feat: add supplier AI context modal and bulk product AI analysis component

This commit is contained in:
Michael committed 2026-02-26 15:40:24 +01:00
1 parent 9d8ef0e4db
commit 174b7fa36c
3 files changed
+32 -2

No files matched your search

@@ -25,7 +25,7 @@ export function AiInsightBlock({ row }: AiInsightBlockProps) {
const status = insight?.status ?? "idle";
const handleAnalyze = () => {
const handleAnalyze = async () => {
if (status === "loading") return;
// Reset Visuel Immédiat
@@ -35,6 +35,20 @@ export function AiInsightBlock({ row }: AiInsightBlockProps) {
const allRows = useGridStore.getState().rows;
const rayonRows = allRows.filter(r => r.libelleNiveau2 === row.libelleNiveau2);
// Fetch local context if needed
let supplierContext = "";
if (row.codeFournisseur) {
try {
const ctxRes = await fetch(`/api/ai/context?fournisseur=${row.codeFournisseur}`);
if (ctxRes.ok) {
const data = await ctxRes.json();
supplierContext = data.context || "";
}
} catch (err) {
console.error("Failed to load supplier context for AI", err);
}
}
// Préparation du ScoringEngine
const regScore = Object.values(row.sales12m || {}).filter((v: any) => v > 0).length;
const weight = (row.workingStores?.length || 1) === 1 ? 2 : 1;
@@ -94,6 +108,7 @@ export function AiInsightBlock({ row }: AiInsightBlockProps) {
totalFournisseurCa: row.totalFournisseurCa,
codeFournisseur: row.codeFournisseur,
totalMagasins: 2,
supplierContext: supplierContext,
scoring: {
compositeScore: scoringResult.compositeScore,
decision: scoringResult.decision.recommendation,