mirror of
https://github.com/siop-spelev/siop2.git
synced 2026-08-08 12:41:54 +00:00
feat(r5.3): écrans IA — assistant web, corpus administrable, suggestions OT/mobile
- Contrat (76 opérations) : Document expose inCorpus/indexedAt/chunkCount,
PATCH /documents/{id}/corpus (ASSETS.edit), POST /assistant/reindex
(bilan chiffré) ; ci-contract vérifie désormais aussi le client mobile.
- Web : page /assistant (chat sourcé — extraits exacts cités, Ouvrir vers
PDF authentifié ou fiche OT, avertissement permanent ; refus honnête
chiffré avec action utile) ; Bibliothèque = corpus (bandeau 09-08,
statut d'indexation par document, interrupteur d'exclusion PDF,
Réindexer tout) ; fiche OT : « Décrire pour suggérer » (Appliquer =
geste humain, liseré « suggéré » retiré au choix manuel).
- Mobile : chips de suggestion dans la clôture (un appui = un champ
pré-rempli, « réseau requis » hors-ligne — la file R4 n'en dépend pas).
- apps/ai : seuils AI_SEUIL_* configurables par env (CI + calibrage).
- CI e2e : service siop2-ai (embeddeur déterministe, seuils calibrés sur
mesures : match 0,66 vs bruit 0,11) + parcours R5 Playwright (PDF généré
xref valide → réindexation → réponse sourcée → refus → suggestion).
- Vérifié : 16/16 Playwright, 78 tests API, 23 pytest, 17 jest-expo ;
chaîne réelle au vrai modèle ONNX (web 7/7, mobile Expo web 6/6).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
import { router, useLocalSearchParams } from 'expo-router';
|
||||
import { useState } from 'react';
|
||||
import { ScrollView, Text, View } from 'react-native';
|
||||
import { Pressable, ScrollView, Text, TextInput, View } from 'react-native';
|
||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||
import {
|
||||
BILAN_FIELD_LABELS,
|
||||
BILAN_FIELDS,
|
||||
REQUIRED_BILAN_FIELDS,
|
||||
type BilanField,
|
||||
type BilanSuggestion,
|
||||
type ReportUpsert,
|
||||
} from '@siop/shared';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { useReferenceValues, useWorkOrder } from '@/api/exploitation';
|
||||
import { useReferenceValues, useSuggestionBilan, useWorkOrder } from '@/api/exploitation';
|
||||
import { useHorsLigne } from '@/auth/session';
|
||||
import { BoutonTel, Carte, ChoixTel, EnteteFiche } from '@/composants/ui';
|
||||
import { enfilerBilan, enfilerTransition } from '@/file/actions';
|
||||
@@ -95,6 +96,10 @@ export default function PageCloture() {
|
||||
<SafeAreaView style={{ flex: 1, backgroundColor: t.fond }} edges={['top']}>
|
||||
<ScrollView contentContainerStyle={{ padding: 14, gap: 10 }}>
|
||||
<EnteteFiche titre={`Clôturer ${ot.reference}`} />
|
||||
<CarteSuggestion
|
||||
horsLigne={horsLigne}
|
||||
surApplication={(s) => setChoix((c) => ({ ...c, [s.field]: s.valueId }))}
|
||||
/>
|
||||
<Carte titre="Bilan d'intervention — requis pour clôturer">
|
||||
<View style={{ gap: 10 }}>
|
||||
{[0, 2, 4].map((rang) => (
|
||||
@@ -151,3 +156,118 @@ export default function PageCloture() {
|
||||
</SafeAreaView>
|
||||
);
|
||||
}
|
||||
|
||||
/** Écran 4 des maquettes R5 : décrire au pouce → chips suggérées (D1 — un
|
||||
* appui = un choix humain, les chips ne font que pré-remplir les sélecteurs).
|
||||
* L'IA est un service serveur : hors-ligne, la suggestion attend le réseau
|
||||
* — la clôture en file R4, elle, n'en a pas besoin. */
|
||||
function CarteSuggestion({
|
||||
horsLigne,
|
||||
surApplication,
|
||||
}: {
|
||||
horsLigne: boolean;
|
||||
surApplication: (s: BilanSuggestion) => void;
|
||||
}) {
|
||||
const t = useTokens();
|
||||
const suggerer = useSuggestionBilan();
|
||||
const [description, setDescription] = useState('');
|
||||
const [appliquees, setAppliquees] = useState<Set<BilanField>>(new Set());
|
||||
const suggestions = suggerer.data?.suggestions ?? [];
|
||||
|
||||
return (
|
||||
<Carte titre="Décrire pour suggérer (optionnel)">
|
||||
<TextInput
|
||||
multiline
|
||||
value={description}
|
||||
onChangeText={setDescription}
|
||||
maxLength={2000}
|
||||
placeholder="Décrivez la panne et ce que vous avez fait…"
|
||||
placeholderTextColor={t.encre3}
|
||||
accessibilityLabel="Décrire pour suggérer"
|
||||
style={{
|
||||
minHeight: 64,
|
||||
borderWidth: 1.5,
|
||||
borderColor: t.bordureForte,
|
||||
borderRadius: 9,
|
||||
backgroundColor: t.surface,
|
||||
padding: 9,
|
||||
color: t.encre,
|
||||
fontFamily: 'Manrope_500Medium',
|
||||
fontSize: 13,
|
||||
textAlignVertical: 'top',
|
||||
}}
|
||||
/>
|
||||
<BoutonTel
|
||||
libelle={
|
||||
horsLigne
|
||||
? 'Suggérer — réseau requis'
|
||||
: suggerer.isPending
|
||||
? 'Analyse…'
|
||||
: '✨ Suggérer les codes'
|
||||
}
|
||||
variante="contour"
|
||||
desactive={horsLigne || suggerer.isPending || description.trim().length < 10}
|
||||
surAppui={() => {
|
||||
setAppliquees(new Set());
|
||||
suggerer.mutate(description.trim());
|
||||
}}
|
||||
/>
|
||||
{suggerer.isError ? (
|
||||
<Text style={{ color: t.danger, fontFamily: 'Manrope_600SemiBold', fontSize: 12 }}>
|
||||
{suggerer.error.message}
|
||||
</Text>
|
||||
) : null}
|
||||
{suggerer.isSuccess && suggestions.length === 0 ? (
|
||||
<Text style={{ color: t.encre2, fontFamily: 'Manrope_500Medium', fontSize: 12 }}>
|
||||
Aucun code assez proche — l’IA ne devine pas : choisissez dans les sélecteurs.
|
||||
</Text>
|
||||
) : null}
|
||||
{suggestions.length > 0 ? (
|
||||
<>
|
||||
<View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 6 }}>
|
||||
{suggestions.map((s) => {
|
||||
const faite = appliquees.has(s.field);
|
||||
return (
|
||||
<Pressable
|
||||
key={s.field}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={`Appliquer ${BILAN_FIELD_LABELS[s.field]} : ${s.label}`}
|
||||
disabled={faite}
|
||||
onPress={() => {
|
||||
surApplication(s);
|
||||
setAppliquees((avant) => new Set([...avant, s.field]));
|
||||
}}
|
||||
style={{
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
gap: 5,
|
||||
borderWidth: 1.5,
|
||||
borderColor: t.primaire,
|
||||
backgroundColor: faite ? t.primaire : t.primaireDoux,
|
||||
borderRadius: 999,
|
||||
paddingVertical: 6,
|
||||
paddingHorizontal: 10,
|
||||
}}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
color: faite ? '#fff' : t.primaire,
|
||||
fontFamily: 'Manrope_700Bold',
|
||||
fontSize: 12,
|
||||
}}
|
||||
>
|
||||
{faite ? '✓' : '✨'} {BILAN_FIELD_LABELS[s.field]} : {s.label}
|
||||
</Text>
|
||||
</Pressable>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
<Text style={{ color: t.encre3, fontFamily: 'Manrope_500Medium', fontSize: 11 }}>
|
||||
Rien ne s’enregistre sans votre geste — les chips pré-remplissent les sélecteurs
|
||||
ci-dessous.
|
||||
</Text>
|
||||
</>
|
||||
) : null}
|
||||
</Carte>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user