feat: amélioration de l'assistant IA logisticien et de la gestion des containers
- **Backend (Cloud Functions)** :
- Mise à jour de `firebase-functions` vers la version `7.2.5`.
- Amélioration de la sécurité et de la flexibilité des clés API Gemini (support des variables d'environnement `.env` et `.env.local`).
- Optimisation de la recherche d'équipements avec une stratégie multi-passes (exacte, par tokens, puis catégorielle/fuzzy).
- Ajout de nouveaux outils pour l'IA : `check_container_availability` et `check_container_availability_batch` pour vérifier la disponibilité des flight-cases.
- Implémentation d'un post-traitement automatique suggérant des containers complets si tous leurs équipements internes sont requis par l'événement.
- Amélioration de la résilience aux erreurs 429/503 de Gemini avec une stratégie d'exponential backoff.
- **Frontend (Flutter)** :
- Mise à jour du service `AiEquipmentAssistantService` pour gérer les métadonnées détaillées des containers (rationale, items manquants/matchings, disponibilité).
- Refonte de l'interface `AiEquipmentAssistantDialog` :
- Affichage enrichi des containers dans le récapitulatif.
- Ajout de la possibilité de sélectionner/désélectionner manuellement les containers (notamment ceux marqués comme "partiels").
- Amélioration visuelle (ombres, bordures, icônes de statut de disponibilité).
- Marquage de l'assistant en mode "BETA".
- **Général** :
- Mise à jour du `.gitignore` pour inclure `functions/.env.local`.
- Correction de typos et amélioration du logging de debug dans le backend.
This commit is contained in:
@@ -52,6 +52,7 @@ class _AiEquipmentAssistantDialogState
|
||||
late List<EventEquipment> _workingEquipment;
|
||||
AiEquipmentDocument? _selectedDocument;
|
||||
List<String> _sessionLogs = [];
|
||||
Set<String> _selectedContainerIds = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -134,6 +135,11 @@ class _AiEquipmentAssistantDialogState
|
||||
_workingEquipment = List<EventEquipment>.from(
|
||||
response.proposal!.asEventEquipment,
|
||||
);
|
||||
// Préselectionner les containers non partiels
|
||||
_selectedContainerIds = {
|
||||
for (final c in response.proposal!.containers)
|
||||
if (!c.partial) c.containerId
|
||||
};
|
||||
}
|
||||
_sessionLogs.addAll(response.debugLogs);
|
||||
_isLoading = false;
|
||||
@@ -267,7 +273,7 @@ class _AiEquipmentAssistantDialogState
|
||||
children: [
|
||||
AppBar(
|
||||
automaticallyImplyLeading: false,
|
||||
title: const Text('Assistant IA Logisticien'),
|
||||
title: const Text('(BETA) Assistant IA Logisticien'),
|
||||
actions: [
|
||||
if (_sessionLogs.isNotEmpty)
|
||||
IconButton(
|
||||
@@ -422,13 +428,13 @@ class _AiEquipmentAssistantDialogState
|
||||
bottomLeft: Radius.circular(message.isUser ? 16 : 4),
|
||||
bottomRight: Radius.circular(message.isUser ? 4 : 16),
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.05),
|
||||
blurRadius: 4,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.05),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
border:
|
||||
message.isUser ? null : Border.all(color: Colors.grey.shade200),
|
||||
),
|
||||
@@ -488,11 +494,11 @@ class _AiEquipmentAssistantDialogState
|
||||
width: double.infinity,
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: bgColor,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: color.withValues(alpha: 0.3)),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: bgColor,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: color.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -500,11 +506,13 @@ class _AiEquipmentAssistantDialogState
|
||||
children: [
|
||||
Icon(icon, size: 18, color: color),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
title.replaceAll(':', '').trim(),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
Expanded(
|
||||
child: Text(
|
||||
title.replaceAll(':', '').trim(),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -525,7 +533,10 @@ class _AiEquipmentAssistantDialogState
|
||||
if (_latestProposal == null) return;
|
||||
|
||||
List<EventEquipment> equipment = List.from(_latestProposal!.asEventEquipment);
|
||||
List<String> containerIds = List.from(_latestProposal!.containerIds);
|
||||
// Ne renvoyer que les containerIds sélectionnés (par défaut les containers complets)
|
||||
final List<String> containerIds = _selectedContainerIds.isNotEmpty
|
||||
? _selectedContainerIds.toList()
|
||||
: List.from(_latestProposal!.containerIds);
|
||||
|
||||
if (excludeAlternatives) {
|
||||
// On utilise la liste des items d'origine pour savoir lesquels exclure
|
||||
@@ -558,9 +569,9 @@ class _AiEquipmentAssistantDialogState
|
||||
padding: const EdgeInsets.all(16),
|
||||
constraints: const BoxConstraints(maxHeight: 280),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.indigo.shade50,
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: Colors.indigo.shade200),
|
||||
border: Border.all(color: Colors.grey.shade300),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.05),
|
||||
@@ -576,12 +587,14 @@ class _AiEquipmentAssistantDialogState
|
||||
children: [
|
||||
const Icon(Icons.assignment_turned_in, color: Colors.indigo),
|
||||
const SizedBox(width: 12),
|
||||
const Text(
|
||||
'Récapitulatif de la proposition IA',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
color: Colors.indigo,
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'Récapitulatif de la proposition IA',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
color: Colors.indigo,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -633,21 +646,58 @@ class _AiEquipmentAssistantDialogState
|
||||
);
|
||||
}),
|
||||
],
|
||||
if (proposal.containerIds.isNotEmpty) ...[
|
||||
if (proposal.containers.isNotEmpty) ...[
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'Fly-cases & Boîtes :',
|
||||
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 13),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
...proposal.containerIds.map((id) {
|
||||
...proposal.containers.map((c) {
|
||||
final isPartial = c.partial;
|
||||
final isSelected = _selectedContainerIds.contains(c.containerId);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 6, left: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.inventory_2_outlined, size: 14, color: Colors.indigo),
|
||||
Icon(
|
||||
Icons.inventory_2_outlined,
|
||||
size: 14,
|
||||
color: c.available == false ? Colors.red : Colors.indigo,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(id, style: const TextStyle(fontWeight: FontWeight.w500)),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: Text('${c.containerId} ${c.rationale.isNotEmpty ? "- ${c.rationale}" : ""}', style: const TextStyle(fontWeight: FontWeight.w500))),
|
||||
if (c.available == false)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: Icon(Icons.block, color: Colors.red.shade700, size: 14),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (isPartial) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text('Contenu partiel : ${c.matchingEquipmentIds.length}/${c.equipmentIds.length} items utilisés.', style: TextStyle(fontSize: 12, color: Colors.grey.shade700)),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
if (isPartial)
|
||||
Checkbox(
|
||||
value: isSelected,
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
if (v == true) _selectedContainerIds.add(c.containerId);
|
||||
else _selectedContainerIds.remove(c.containerId);
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user