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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -91,6 +91,15 @@ export function useCocheChecklist(otId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
/** Suggestion R5 (D1) : l'IA est un service SERVEUR — la suggestion demande le
|
||||
* réseau, la clôture en file R4 fonctionne sans elle. */
|
||||
export function useSuggestionBilan() {
|
||||
return useMutation({
|
||||
mutationFn: async (description: string) =>
|
||||
unwrap(await api.POST('/assistant/suggest-bilan', { body: { description } })),
|
||||
});
|
||||
}
|
||||
|
||||
export function useBilan(otId: string) {
|
||||
const invalide = useInvalideOT(otId);
|
||||
return useMutation({
|
||||
|
||||
109
apps/mobile/src/api/schema.d.ts
vendored
109
apps/mobile/src/api/schema.d.ts
vendored
@@ -407,6 +407,23 @@ export interface paths {
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/documents/{id}/corpus": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
get?: never;
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
/** Inclure/exclure du corpus IA (D3 — réversible, effectif à la prochaine réindexation) */
|
||||
patch: operations["updateDocumentCorpus"];
|
||||
trace?: never;
|
||||
};
|
||||
"/documents/{id}": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
@@ -475,6 +492,23 @@ export interface paths {
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/assistant/reindex": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
get?: never;
|
||||
put?: never;
|
||||
/** Réindexer le corpus (bibliothèque PDF + bilans clôturés, anonymisés à l’ingestion — D4) */
|
||||
post: operations["reindexAssistant"];
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/search": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
@@ -1437,6 +1471,9 @@ export interface components {
|
||||
uploadedByName: string | null;
|
||||
/** Format: date-time */
|
||||
createdAt: string;
|
||||
inCorpus: boolean;
|
||||
indexedAt: string | null;
|
||||
chunkCount: number;
|
||||
}[];
|
||||
};
|
||||
Document: {
|
||||
@@ -1452,6 +1489,12 @@ export interface components {
|
||||
uploadedByName: string | null;
|
||||
/** Format: date-time */
|
||||
createdAt: string;
|
||||
inCorpus: boolean;
|
||||
indexedAt: string | null;
|
||||
chunkCount: number;
|
||||
};
|
||||
DocumentCorpusUpdate: {
|
||||
inCorpus: boolean;
|
||||
};
|
||||
AnalyticsSummary: {
|
||||
months: number;
|
||||
@@ -1518,6 +1561,12 @@ export interface components {
|
||||
SuggestBilan: {
|
||||
description: string;
|
||||
};
|
||||
ReindexResult: {
|
||||
documentsIndexed: number;
|
||||
documentsSkipped: number;
|
||||
reportsIndexed: number;
|
||||
chunks: number;
|
||||
};
|
||||
SearchResponse: {
|
||||
workOrders: {
|
||||
/** Format: uuid */
|
||||
@@ -2990,6 +3039,39 @@ export interface operations {
|
||||
};
|
||||
};
|
||||
};
|
||||
updateDocumentCorpus: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
id: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": components["schemas"]["DocumentCorpusUpdate"];
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description Document mis à jour */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Document"];
|
||||
};
|
||||
};
|
||||
/** @description Inconnu */
|
||||
404: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content?: never;
|
||||
};
|
||||
};
|
||||
};
|
||||
deleteDocument: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
@@ -3101,6 +3183,33 @@ export interface operations {
|
||||
};
|
||||
};
|
||||
};
|
||||
reindexAssistant: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description Bilan d’indexation */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["ReindexResult"];
|
||||
};
|
||||
};
|
||||
/** @description Service IA indisponible */
|
||||
503: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content?: never;
|
||||
};
|
||||
};
|
||||
};
|
||||
globalSearch: {
|
||||
parameters: {
|
||||
query: {
|
||||
|
||||
Reference in New Issue
Block a user