@apotech-os/support-kit 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -0
- package/dist/chunk-KDOL3MLH.js +1766 -0
- package/dist/chunk-KDOL3MLH.js.map +1 -0
- package/dist/index.cjs +5744 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2010 -0
- package/dist/index.d.ts +2010 -0
- package/dist/index.js +3965 -0
- package/dist/index.js.map +1 -0
- package/dist/ui/index.cjs +4946 -0
- package/dist/ui/index.cjs.map +1 -0
- package/dist/ui/index.d.cts +25 -0
- package/dist/ui/index.d.ts +25 -0
- package/dist/ui/index.js +4464 -0
- package/dist/ui/index.js.map +1 -0
- package/package.json +68 -0
package/dist/ui/index.js
ADDED
|
@@ -0,0 +1,4464 @@
|
|
|
1
|
+
import { GENERATED_RESPONSE_STATUSES, EVALUATION_VERDICTS, WHATSAPP_MODES, validateSettings, AGENT_GUARDRAILS, toCategory, toTriageDecision, toAgent, toGeneratedResponse, isGeneratedResponseStatus, toCategoryGroup, toResponseComparison, toDiffAnalysis, NODE_NAMES, settingsToProfile, hasNoDraftNode, guardrailBucket, computeWordDiff, isSendableVerdict } from '../chunk-KDOL3MLH.js';
|
|
2
|
+
import { useState, useMemo, useRef, useEffect, useCallback, useId } from 'react';
|
|
3
|
+
import { useAppContext, useAppSettings, Card, CardContent, Button, Link, KpiCard, BarChart, StackedBarChart, DataTable, Select, useAppApi, useToast, Badge, FunnelChart, Spinner, LineChart, Input, Switch, Checkbox, Textarea, SidePanel, CopyButton, Modal, cn, Tabs, TabsList, TabsTrigger, TabsContent, AppInvokeError } from '@apotech-os/ui-sdk';
|
|
4
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
function useRecordList(objectKey, query, mapper) {
|
|
7
|
+
const { appSlug } = useAppContext();
|
|
8
|
+
const api = useAppApi();
|
|
9
|
+
const path = `/data/apps/${appSlug}/records/${objectKey}`;
|
|
10
|
+
const [rows, setRows] = useState([]);
|
|
11
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
12
|
+
const [error, setError] = useState(void 0);
|
|
13
|
+
const [nextCursor, setNextCursor] = useState(null);
|
|
14
|
+
const [cursorStack, setCursorStack] = useState([null]);
|
|
15
|
+
const clientRef = useRef(api);
|
|
16
|
+
clientRef.current = api;
|
|
17
|
+
const mapperRef = useRef(mapper);
|
|
18
|
+
mapperRef.current = mapper;
|
|
19
|
+
const requestIdRef = useRef(0);
|
|
20
|
+
const isMountedRef = useRef(true);
|
|
21
|
+
const paginate = query.paginate === true;
|
|
22
|
+
const currentCursor = cursorStack[cursorStack.length - 1] ?? null;
|
|
23
|
+
const paramsKey = JSON.stringify({
|
|
24
|
+
filter: query.filter,
|
|
25
|
+
sort: query.sort,
|
|
26
|
+
limit: query.limit,
|
|
27
|
+
cursor: paginate ? currentCursor : void 0
|
|
28
|
+
});
|
|
29
|
+
const filterSortLimitKey = JSON.stringify({ filter: query.filter, sort: query.sort, limit: query.limit });
|
|
30
|
+
const previousFilterSortLimitKeyRef = useRef(filterSortLimitKey);
|
|
31
|
+
if (paginate && previousFilterSortLimitKeyRef.current !== filterSortLimitKey) {
|
|
32
|
+
previousFilterSortLimitKeyRef.current = filterSortLimitKey;
|
|
33
|
+
if (cursorStack.length > 1 || cursorStack[0] !== null) setCursorStack([null]);
|
|
34
|
+
}
|
|
35
|
+
const load = useCallback(async () => {
|
|
36
|
+
const requestId = ++requestIdRef.current;
|
|
37
|
+
setIsLoading(true);
|
|
38
|
+
try {
|
|
39
|
+
const parsed = JSON.parse(paramsKey);
|
|
40
|
+
const params = {};
|
|
41
|
+
if (parsed.filter !== void 0) params.filter = JSON.stringify(parsed.filter);
|
|
42
|
+
if (parsed.sort !== void 0) params.sort = JSON.stringify(parsed.sort);
|
|
43
|
+
if (parsed.limit !== void 0) params.limit = String(parsed.limit);
|
|
44
|
+
if (paginate && parsed.cursor) params.cursor = parsed.cursor;
|
|
45
|
+
const page = await clientRef.current.get(path, params);
|
|
46
|
+
if (requestId !== requestIdRef.current || !isMountedRef.current) return;
|
|
47
|
+
setRows(page.items.map((record) => mapperRef.current(record)));
|
|
48
|
+
setNextCursor(page.nextCursor ?? null);
|
|
49
|
+
setError(void 0);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
if (requestId !== requestIdRef.current || !isMountedRef.current) return;
|
|
52
|
+
setError(err);
|
|
53
|
+
} finally {
|
|
54
|
+
if (requestId === requestIdRef.current) setIsLoading(false);
|
|
55
|
+
}
|
|
56
|
+
}, [path, paramsKey, paginate]);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
isMountedRef.current = true;
|
|
59
|
+
void load();
|
|
60
|
+
return () => {
|
|
61
|
+
isMountedRef.current = false;
|
|
62
|
+
requestIdRef.current += 1;
|
|
63
|
+
};
|
|
64
|
+
}, [load]);
|
|
65
|
+
function goToNextPage() {
|
|
66
|
+
if (!paginate || !nextCursor) return;
|
|
67
|
+
setCursorStack((stack) => [...stack, nextCursor]);
|
|
68
|
+
}
|
|
69
|
+
function goToPreviousPage() {
|
|
70
|
+
if (!paginate || cursorStack.length <= 1) return;
|
|
71
|
+
setCursorStack((stack) => stack.slice(0, -1));
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
rows,
|
|
75
|
+
isLoading,
|
|
76
|
+
error,
|
|
77
|
+
refresh: load,
|
|
78
|
+
hasNextPage: paginate && nextCursor !== null,
|
|
79
|
+
hasPreviousPage: paginate && cursorStack.length > 1,
|
|
80
|
+
goToNextPage,
|
|
81
|
+
goToPreviousPage
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function useAggregate(objectKey, spec) {
|
|
85
|
+
const { appSlug } = useAppContext();
|
|
86
|
+
const api = useAppApi();
|
|
87
|
+
const path = `/data/apps/${appSlug}/aggregate/${objectKey}`;
|
|
88
|
+
const [rows, setRows] = useState([]);
|
|
89
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
90
|
+
const [error, setError] = useState(void 0);
|
|
91
|
+
const clientRef = useRef(api);
|
|
92
|
+
clientRef.current = api;
|
|
93
|
+
const requestIdRef = useRef(0);
|
|
94
|
+
const isMountedRef = useRef(true);
|
|
95
|
+
const specKey = JSON.stringify(spec);
|
|
96
|
+
const load = useCallback(async () => {
|
|
97
|
+
const requestId = ++requestIdRef.current;
|
|
98
|
+
setIsLoading(true);
|
|
99
|
+
try {
|
|
100
|
+
const result = await clientRef.current.post(path, JSON.parse(specKey));
|
|
101
|
+
if (requestId !== requestIdRef.current || !isMountedRef.current) return;
|
|
102
|
+
setRows(result);
|
|
103
|
+
setError(void 0);
|
|
104
|
+
} catch (err) {
|
|
105
|
+
if (requestId !== requestIdRef.current || !isMountedRef.current) return;
|
|
106
|
+
setError(err);
|
|
107
|
+
} finally {
|
|
108
|
+
if (requestId === requestIdRef.current) setIsLoading(false);
|
|
109
|
+
}
|
|
110
|
+
}, [path, specKey]);
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
isMountedRef.current = true;
|
|
113
|
+
void load();
|
|
114
|
+
return () => {
|
|
115
|
+
isMountedRef.current = false;
|
|
116
|
+
requestIdRef.current += 1;
|
|
117
|
+
};
|
|
118
|
+
}, [load]);
|
|
119
|
+
return { rows, isLoading, error, refresh: load };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/ui/shared/format.ts
|
|
123
|
+
function formatDate(iso) {
|
|
124
|
+
if (!iso) return "\u2014";
|
|
125
|
+
return new Date(iso).toLocaleString("fr-FR");
|
|
126
|
+
}
|
|
127
|
+
function toNameMap(rows) {
|
|
128
|
+
return new Map(rows.map((r) => [r.id, r.name]));
|
|
129
|
+
}
|
|
130
|
+
function windowCutoffIso(days) {
|
|
131
|
+
return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/ui/dashboard/dashboard-stats.ts
|
|
135
|
+
function sumCounts(rows, countField = "count") {
|
|
136
|
+
return rows.reduce((sum, row) => sum + (Number(row[countField]) || 0), 0);
|
|
137
|
+
}
|
|
138
|
+
function countFor(rows, groupField, value, countField = "count") {
|
|
139
|
+
const row = rows.find((r) => r[groupField] === value);
|
|
140
|
+
return row ? Number(row[countField]) || 0 : 0;
|
|
141
|
+
}
|
|
142
|
+
function bucketDay(row) {
|
|
143
|
+
return String(row["bucket"]).slice(0, 10);
|
|
144
|
+
}
|
|
145
|
+
function mergeDailySeries(sentRows, heldRows) {
|
|
146
|
+
const byDay = /* @__PURE__ */ new Map();
|
|
147
|
+
for (const row of sentRows) {
|
|
148
|
+
const day = bucketDay(row);
|
|
149
|
+
byDay.set(day, { sent: Number(row["count"]) || 0, held: byDay.get(day)?.held ?? 0 });
|
|
150
|
+
}
|
|
151
|
+
for (const row of heldRows) {
|
|
152
|
+
const day = bucketDay(row);
|
|
153
|
+
const existing = byDay.get(day);
|
|
154
|
+
byDay.set(day, { sent: existing?.sent ?? 0, held: Number(row["count"]) || 0 });
|
|
155
|
+
}
|
|
156
|
+
return [...byDay.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([day, counts]) => ({ day, ...counts }));
|
|
157
|
+
}
|
|
158
|
+
var DEFAULT_TOP_N = 6;
|
|
159
|
+
function foldCategoryBreakdown(rows, categoryNames, topN = DEFAULT_TOP_N) {
|
|
160
|
+
const measured = rows.map((row) => {
|
|
161
|
+
const id = row["categoryId"];
|
|
162
|
+
const name = typeof id === "string" ? categoryNames.get(id) : void 0;
|
|
163
|
+
return name ? { label: name, value: Number(row["count"]) || 0 } : null;
|
|
164
|
+
}).filter((bar) => bar !== null).sort((a, b) => b.value - a.value);
|
|
165
|
+
if (measured.length <= topN + 1) return measured;
|
|
166
|
+
const tail = measured.slice(topN).reduce((sum, bar) => sum + bar.value, 0);
|
|
167
|
+
return [...measured.slice(0, topN), { label: "Autres", value: tail }];
|
|
168
|
+
}
|
|
169
|
+
var WINDOW_OPTIONS = [7, 14, 30];
|
|
170
|
+
var RECENT_ACTIVITY_LIMIT = 8;
|
|
171
|
+
function formatRate(value) {
|
|
172
|
+
return Number.isNaN(value) ? "\u2014" : `${Math.round(value * 100)}%`;
|
|
173
|
+
}
|
|
174
|
+
function rateOrNaN(numerator, denominator) {
|
|
175
|
+
return denominator > 0 ? numerator / denominator : Number.NaN;
|
|
176
|
+
}
|
|
177
|
+
function TriageHealthTone({ enabled }) {
|
|
178
|
+
return /* @__PURE__ */ jsx(Badge, { variant: enabled ? "success" : "danger", children: enabled ? "Actif" : "Coup\xE9" });
|
|
179
|
+
}
|
|
180
|
+
function DashboardPage() {
|
|
181
|
+
const { appSlug } = useAppContext();
|
|
182
|
+
const [windowDays, setWindowDays] = useState(WINDOW_OPTIONS[0]);
|
|
183
|
+
const { settings, error: settingsError } = useAppSettings();
|
|
184
|
+
const timezone = settings?.statsTimezone ?? "UTC";
|
|
185
|
+
const cutoffIso = useMemo(() => windowCutoffIso(windowDays), [windowDays]);
|
|
186
|
+
const { rows: statusCounts, isLoading: statusLoading, error: statusError } = useAggregate("generated-response", {
|
|
187
|
+
filter: { generatedAt: { gte: cutoffIso } },
|
|
188
|
+
groupBy: ["status"],
|
|
189
|
+
metrics: [{ op: "count", as: "count" }]
|
|
190
|
+
});
|
|
191
|
+
const { rows: autoSendCounts, isLoading: autoSendLoading } = useAggregate("generated-response", {
|
|
192
|
+
filter: { generatedAt: { gte: cutoffIso } },
|
|
193
|
+
groupBy: ["autoSendDecision"],
|
|
194
|
+
metrics: [{ op: "count", as: "count" }]
|
|
195
|
+
});
|
|
196
|
+
const { rows: escalatedRows, isLoading: escalatedLoading, error: escalatedError } = useAggregate("triage-decision", {
|
|
197
|
+
filter: { escalated: { eq: true } },
|
|
198
|
+
metrics: [{ op: "count", as: "count" }]
|
|
199
|
+
});
|
|
200
|
+
const { rows: categoryCounts, isLoading: categoryLoading, error: categoryError } = useAggregate("triage-decision", {
|
|
201
|
+
filter: { decidedAt: { gte: cutoffIso } },
|
|
202
|
+
groupBy: ["categoryId"],
|
|
203
|
+
metrics: [{ op: "count", as: "count" }]
|
|
204
|
+
});
|
|
205
|
+
const { rows: dailySent, error: dailySentError } = useAggregate("generated-response", {
|
|
206
|
+
filter: { generatedAt: { gte: cutoffIso }, status: { eq: "sent" } },
|
|
207
|
+
bucket: { field: "generatedAt", interval: "day", tz: timezone },
|
|
208
|
+
metrics: [{ op: "count", as: "count" }]
|
|
209
|
+
});
|
|
210
|
+
const { rows: dailyHeld, error: dailyHeldError } = useAggregate("generated-response", {
|
|
211
|
+
filter: { generatedAt: { gte: cutoffIso }, autoSendDecision: { eq: "hold" } },
|
|
212
|
+
bucket: { field: "generatedAt", interval: "day", tz: timezone },
|
|
213
|
+
metrics: [{ op: "count", as: "count" }]
|
|
214
|
+
});
|
|
215
|
+
const dailySeriesError = dailySentError !== void 0 || dailyHeldError !== void 0;
|
|
216
|
+
const { rows: categories } = useRecordList("category", { limit: 500 }, toCategory);
|
|
217
|
+
const categoryNames = useMemo(() => toNameMap(categories), [categories]);
|
|
218
|
+
const {
|
|
219
|
+
rows: recentActivity,
|
|
220
|
+
isLoading: activityLoading,
|
|
221
|
+
error: activityError
|
|
222
|
+
} = useRecordList(
|
|
223
|
+
"triage-decision",
|
|
224
|
+
{ sort: [{ field: "decidedAt", direction: "desc" }], limit: RECENT_ACTIVITY_LIMIT },
|
|
225
|
+
toTriageDecision
|
|
226
|
+
);
|
|
227
|
+
const totalGenerated = sumCounts(statusCounts);
|
|
228
|
+
const sentCount = countFor(statusCounts, "status", "sent");
|
|
229
|
+
const heldCount = countFor(autoSendCounts, "autoSendDecision", "hold");
|
|
230
|
+
const escalatedTotal = escalatedRows[0] ? Number(escalatedRows[0]["count"]) || 0 : 0;
|
|
231
|
+
const categoryBars = foldCategoryBreakdown(categoryCounts, categoryNames);
|
|
232
|
+
const dailySeries = mergeDailySeries(dailySent, dailyHeld);
|
|
233
|
+
const alarming = settingsError !== void 0 || settings !== void 0 && settings.triageEnabled === false;
|
|
234
|
+
const healthBand = /* @__PURE__ */ jsxs("section", { "data-testid": "dashboard-health", children: [
|
|
235
|
+
/* @__PURE__ */ jsx("h2", { className: "mb-2 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Sant\xE9" }),
|
|
236
|
+
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 gap-3 sm:grid-cols-3", children: settingsError !== void 0 ? /* @__PURE__ */ jsx(Card, { className: "sm:col-span-3", children: /* @__PURE__ */ jsx(CardContent, { className: "p-4 text-sm text-destructive", children: "\xC9tat du triage indisponible." }) }) : settings === void 0 ? /* @__PURE__ */ jsx(Card, { className: "sm:col-span-3", children: /* @__PURE__ */ jsx(CardContent, { className: "p-4 text-sm text-muted-foreground", children: "Chargement de l'\xE9tat du triage\u2026" }) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
237
|
+
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-1 p-4", children: [
|
|
238
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Triage" }),
|
|
239
|
+
/* @__PURE__ */ jsx(TriageHealthTone, { enabled: settings.triageEnabled === true })
|
|
240
|
+
] }) }),
|
|
241
|
+
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-1 p-4", children: [
|
|
242
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Cadence" }),
|
|
243
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: settings.triageIntervalMinutes ? `Toutes les ${settings.triageIntervalMinutes} minutes` : "\u2014" })
|
|
244
|
+
] }) }),
|
|
245
|
+
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-1 p-4", children: [
|
|
246
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Escalades" }),
|
|
247
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: escalatedLoading ? "\u2026" : escalatedError ? "Indisponible" : `${escalatedTotal} au total` })
|
|
248
|
+
] }) })
|
|
249
|
+
] }) })
|
|
250
|
+
] });
|
|
251
|
+
const columns = [
|
|
252
|
+
{ key: "ticketId", header: "Ticket", cell: (row) => row.ticketId },
|
|
253
|
+
{ key: "category", header: "Cat\xE9gorie", cell: (row) => row.categoryId && categoryNames.get(row.categoryId) || "\u2014" },
|
|
254
|
+
{
|
|
255
|
+
key: "escalated",
|
|
256
|
+
header: "Escalade",
|
|
257
|
+
cell: (row) => row.escalated ? /* @__PURE__ */ jsx(Badge, { variant: "warning", children: "Escalad\xE9" }) : /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "Non escalad\xE9" })
|
|
258
|
+
},
|
|
259
|
+
{ key: "decidedAt", header: "Date", cell: (row) => formatDate(row.decidedAt) }
|
|
260
|
+
];
|
|
261
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
262
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-4", children: [
|
|
263
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
264
|
+
/* @__PURE__ */ jsx("h1", { className: "text-lg font-semibold", children: "Tableau de bord" }),
|
|
265
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Les chiffres cl\xE9s et les graphiques couvrent la fen\xEAtre choisie ; la sant\xE9 annonce la sienne." })
|
|
266
|
+
] }),
|
|
267
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
268
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
269
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: "Fen\xEAtre :" }),
|
|
270
|
+
WINDOW_OPTIONS.map((days) => /* @__PURE__ */ jsxs(Button, { size: "sm", variant: windowDays === days ? "default" : "outline", onClick: () => setWindowDays(days), children: [
|
|
271
|
+
days,
|
|
272
|
+
" j"
|
|
273
|
+
] }, days))
|
|
274
|
+
] }),
|
|
275
|
+
/* @__PURE__ */ jsx(Link, { href: `/espace/${appSlug}/pipeline`, children: "Voir le pipeline complet" })
|
|
276
|
+
] })
|
|
277
|
+
] }),
|
|
278
|
+
alarming && healthBand,
|
|
279
|
+
/* @__PURE__ */ jsxs("div", { "data-testid": "dashboard-kpis", className: "grid grid-cols-1 gap-4 sm:grid-cols-3", children: [
|
|
280
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
281
|
+
/* @__PURE__ */ jsx(KpiCard, { label: "G\xE9n\xE9r\xE9", value: statusLoading ? Number.NaN : totalGenerated, formatValue: (v) => Number.isNaN(v) ? "\u2026" : String(v) }),
|
|
282
|
+
/* @__PURE__ */ jsx("p", { className: "mt-1 px-1 text-xs text-muted-foreground", children: "R\xE9ponses g\xE9n\xE9r\xE9es sur la fen\xEAtre choisie, tous statuts confondus (en attente, envoy\xE9es, \xE9chou\xE9es\u2026)." })
|
|
283
|
+
] }),
|
|
284
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
285
|
+
/* @__PURE__ */ jsx(
|
|
286
|
+
KpiCard,
|
|
287
|
+
{
|
|
288
|
+
label: "Taux d'envoi auto",
|
|
289
|
+
value: statusLoading || autoSendLoading ? Number.NaN : rateOrNaN(sentCount, totalGenerated),
|
|
290
|
+
formatValue: formatRate
|
|
291
|
+
}
|
|
292
|
+
),
|
|
293
|
+
/* @__PURE__ */ jsx("p", { className: "mt-1 px-1 text-xs text-muted-foreground", children: "Part des r\xE9ponses g\xE9n\xE9r\xE9es sur la fen\xEAtre dont le statut est \xAB Envoy\xE9e \xBB." })
|
|
294
|
+
] }),
|
|
295
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
296
|
+
/* @__PURE__ */ jsx(
|
|
297
|
+
KpiCard,
|
|
298
|
+
{
|
|
299
|
+
label: "Taux de blocage",
|
|
300
|
+
value: statusLoading || autoSendLoading ? Number.NaN : rateOrNaN(heldCount, totalGenerated),
|
|
301
|
+
formatValue: formatRate,
|
|
302
|
+
lowerIsBetter: true
|
|
303
|
+
}
|
|
304
|
+
),
|
|
305
|
+
/* @__PURE__ */ jsx("p", { className: "mt-1 px-1 text-xs text-muted-foreground", children: "Part des r\xE9ponses g\xE9n\xE9r\xE9es sur la fen\xEAtre que la politique d'envoi a retenues (\xE9tat \xAB Bloqu\xE9 \xBB)." })
|
|
306
|
+
] })
|
|
307
|
+
] }),
|
|
308
|
+
statusError !== void 0 && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: "Erreur lors du calcul des chiffres cl\xE9s." }),
|
|
309
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-4 lg:grid-cols-2", children: [
|
|
310
|
+
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(CardContent, { className: "p-4", children: [
|
|
311
|
+
/* @__PURE__ */ jsx("p", { className: "mb-3 text-sm font-medium", children: "R\xE9partition par cat\xE9gorie" }),
|
|
312
|
+
categoryLoading ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Chargement\u2026" }) : categoryError !== void 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: "Impossible de calculer la r\xE9partition par cat\xE9gorie." }) : categoryBars.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Aucun volume calcul\xE9 pour l'instant sur cette fen\xEAtre." }) : /* @__PURE__ */ jsx(BarChart, { data: categoryBars, x: "label", series: [{ key: "value", label: "Volume", colorIndex: 0 }] })
|
|
313
|
+
] }) }),
|
|
314
|
+
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(CardContent, { className: "p-4", children: [
|
|
315
|
+
/* @__PURE__ */ jsx("p", { className: "mb-3 text-sm font-medium", children: "\xC9volution par jour" }),
|
|
316
|
+
dailySeriesError ? /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: "Impossible de calculer l'\xE9volution par jour." }) : dailySeries.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Aucune journ\xE9e mesur\xE9e sur cette fen\xEAtre." }) : /* @__PURE__ */ jsx(
|
|
317
|
+
StackedBarChart,
|
|
318
|
+
{
|
|
319
|
+
data: dailySeries,
|
|
320
|
+
x: "day",
|
|
321
|
+
label: "\xC9volution par jour",
|
|
322
|
+
series: [
|
|
323
|
+
{ key: "sent", label: "Envoy\xE9es", colorIndex: 0 },
|
|
324
|
+
{ key: "held", label: "Bloqu\xE9es", colorIndex: 1 }
|
|
325
|
+
]
|
|
326
|
+
}
|
|
327
|
+
)
|
|
328
|
+
] }) })
|
|
329
|
+
] }),
|
|
330
|
+
!alarming && healthBand,
|
|
331
|
+
/* @__PURE__ */ jsxs("section", { children: [
|
|
332
|
+
/* @__PURE__ */ jsxs("div", { className: "mb-2 flex items-baseline justify-between gap-4", children: [
|
|
333
|
+
/* @__PURE__ */ jsx("h2", { className: "text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Activit\xE9 r\xE9cente" }),
|
|
334
|
+
/* @__PURE__ */ jsx(Link, { href: `/espace/${appSlug}/tickets`, children: "Ouvrir le suivi des demandes" })
|
|
335
|
+
] }),
|
|
336
|
+
/* @__PURE__ */ jsx(
|
|
337
|
+
DataTable,
|
|
338
|
+
{
|
|
339
|
+
columns,
|
|
340
|
+
rows: recentActivity,
|
|
341
|
+
rowId: (row) => row.id,
|
|
342
|
+
manual: true,
|
|
343
|
+
loading: activityLoading,
|
|
344
|
+
error: activityError ? "Erreur lors du chargement de l\u2019activit\xE9 r\xE9cente." : void 0,
|
|
345
|
+
empty: "Aucune d\xE9cision de triage enregistr\xE9e pour l\u2019instant."
|
|
346
|
+
}
|
|
347
|
+
)
|
|
348
|
+
] })
|
|
349
|
+
] });
|
|
350
|
+
}
|
|
351
|
+
var UNCONFIGURED = { baseUrl: null, projectId: null };
|
|
352
|
+
function useLangfuseConfig() {
|
|
353
|
+
const { appSlug } = useAppContext();
|
|
354
|
+
const api = useAppApi();
|
|
355
|
+
const path = `/data/apps/${appSlug}/langfuse/config`;
|
|
356
|
+
const [config, setConfig] = useState(void 0);
|
|
357
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
358
|
+
const clientRef = useRef(api);
|
|
359
|
+
clientRef.current = api;
|
|
360
|
+
const requestIdRef = useRef(0);
|
|
361
|
+
const isMountedRef = useRef(true);
|
|
362
|
+
useEffect(() => {
|
|
363
|
+
isMountedRef.current = true;
|
|
364
|
+
const requestId = ++requestIdRef.current;
|
|
365
|
+
setIsLoading(true);
|
|
366
|
+
void clientRef.current.get(path).then((loaded) => {
|
|
367
|
+
if (requestId !== requestIdRef.current || !isMountedRef.current) return;
|
|
368
|
+
setConfig(loaded);
|
|
369
|
+
}).catch(() => {
|
|
370
|
+
if (requestId !== requestIdRef.current || !isMountedRef.current) return;
|
|
371
|
+
setConfig(UNCONFIGURED);
|
|
372
|
+
}).finally(() => {
|
|
373
|
+
if (requestId === requestIdRef.current) setIsLoading(false);
|
|
374
|
+
});
|
|
375
|
+
return () => {
|
|
376
|
+
isMountedRef.current = false;
|
|
377
|
+
requestIdRef.current += 1;
|
|
378
|
+
};
|
|
379
|
+
}, [path]);
|
|
380
|
+
return { config, isLoading };
|
|
381
|
+
}
|
|
382
|
+
function parseHttpOrigin(baseUrl) {
|
|
383
|
+
let parsed;
|
|
384
|
+
try {
|
|
385
|
+
parsed = new URL(baseUrl);
|
|
386
|
+
} catch {
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
return parsed.protocol === "http:" || parsed.protocol === "https:" ? parsed : null;
|
|
390
|
+
}
|
|
391
|
+
function buildTraceUrl(base2, projectId, traceId, observationId) {
|
|
392
|
+
const path = `${base2.pathname.replace(/\/$/, "")}/project/${encodeURIComponent(projectId)}/traces/${encodeURIComponent(traceId)}`;
|
|
393
|
+
const url = new URL(`${base2.origin}${path}`);
|
|
394
|
+
if (observationId) url.searchParams.set("observation", observationId);
|
|
395
|
+
return url.toString();
|
|
396
|
+
}
|
|
397
|
+
function LangfuseTraceLink({ traceId, observationId, config, label = "Voir la trace" }) {
|
|
398
|
+
if (!traceId) {
|
|
399
|
+
return observationId ? /* @__PURE__ */ jsx(CopyButton, { value: observationId, label }) : null;
|
|
400
|
+
}
|
|
401
|
+
if (!config?.baseUrl || !config?.projectId) return null;
|
|
402
|
+
const origin = parseHttpOrigin(config.baseUrl);
|
|
403
|
+
if (!origin) return null;
|
|
404
|
+
const url = buildTraceUrl(origin, config.projectId, traceId, observationId);
|
|
405
|
+
return /* @__PURE__ */ jsxs(Link, { href: url, target: "_blank", rel: "noopener noreferrer", className: "inline-flex items-center gap-1 text-xs", children: [
|
|
406
|
+
label,
|
|
407
|
+
/* @__PURE__ */ jsx("svg", { className: "h-3 w-3", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", "aria-hidden": "true", children: /* @__PURE__ */ jsx(
|
|
408
|
+
"path",
|
|
409
|
+
{
|
|
410
|
+
strokeLinecap: "round",
|
|
411
|
+
strokeLinejoin: "round",
|
|
412
|
+
strokeWidth: 2,
|
|
413
|
+
d: "M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"
|
|
414
|
+
}
|
|
415
|
+
) })
|
|
416
|
+
] });
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// src/ui/shared/status-labels.ts
|
|
420
|
+
var GENERATED_RESPONSE_STATUS_LABELS = {
|
|
421
|
+
pending: "En attente",
|
|
422
|
+
ready: "Disponible",
|
|
423
|
+
sending: "Envoi en cours",
|
|
424
|
+
sent: "Envoy\xE9e",
|
|
425
|
+
failed: "\xC9chec",
|
|
426
|
+
no_reply_needed: "Aucune r\xE9ponse n\xE9cessaire",
|
|
427
|
+
invalidated: "Invalid\xE9e",
|
|
428
|
+
expired: "Expir\xE9e"
|
|
429
|
+
};
|
|
430
|
+
var AUTO_SEND_DECISION_LABELS = {
|
|
431
|
+
auto: "Autoris\xE9",
|
|
432
|
+
hold: "Bloqu\xE9"
|
|
433
|
+
};
|
|
434
|
+
var EVALUATION_VERDICT_LABELS = {
|
|
435
|
+
send: "Envoyer",
|
|
436
|
+
send_and_escalate: "Envoyer et escalader",
|
|
437
|
+
hold: "Retenir"
|
|
438
|
+
};
|
|
439
|
+
var TRIAGE_CONFIDENCE_LABELS = {
|
|
440
|
+
high: "\xC9lev\xE9e",
|
|
441
|
+
low: "Faible"
|
|
442
|
+
};
|
|
443
|
+
var TRIAGE_DECISION_STATUS_LABELS = {
|
|
444
|
+
ok: "R\xE9ussi",
|
|
445
|
+
error: "Erreur"
|
|
446
|
+
};
|
|
447
|
+
var NODE_LABELS = {
|
|
448
|
+
fetchContext: "R\xE9cup\xE9ration du ticket",
|
|
449
|
+
triage: "Triage",
|
|
450
|
+
escalate: "Escalade",
|
|
451
|
+
draft: "R\xE9daction",
|
|
452
|
+
evaluate: "\xC9valuation",
|
|
453
|
+
revise: "R\xE9vision",
|
|
454
|
+
guardrails: "Garde-fous",
|
|
455
|
+
authorize: "Autorisation",
|
|
456
|
+
act: "Envoi"
|
|
457
|
+
};
|
|
458
|
+
var NODE_ROLE_LABELS = {
|
|
459
|
+
fetchContext: "Lit la conversation Gorgias",
|
|
460
|
+
triage: "Classe le ticket dans une cat\xE9gorie",
|
|
461
|
+
escalate: "D\xE9cide si un humain doit reprendre la main",
|
|
462
|
+
draft: "\xC9crit la r\xE9ponse, outils compris",
|
|
463
|
+
evaluate: "Juge la r\xE9ponse : send, hold, send_and_escalate",
|
|
464
|
+
revise: "R\xE9\xE9crit une fois contre l'objection du juge",
|
|
465
|
+
guardrails: "Contr\xF4les d\xE9terministes avant envoi",
|
|
466
|
+
authorize: "V\xE9rifie que l'action est permise",
|
|
467
|
+
act: "Anti-collision puis publication de la r\xE9ponse"
|
|
468
|
+
};
|
|
469
|
+
var OUTCOME_LABELS = {
|
|
470
|
+
sent: "Envoy\xE9e",
|
|
471
|
+
ready: "Disponible",
|
|
472
|
+
needs_human: "Revue n\xE9cessaire",
|
|
473
|
+
guardrail_hold: "Retenue par un garde-fou",
|
|
474
|
+
awaiting_approval: "En attente d'approbation",
|
|
475
|
+
escalated: "Escalad\xE9e",
|
|
476
|
+
triaged_only: "Triage seul",
|
|
477
|
+
no_reply_needed: "Aucune r\xE9ponse n\xE9cessaire",
|
|
478
|
+
failed: "\xC9chec"
|
|
479
|
+
};
|
|
480
|
+
function outcomeLabel(outcome) {
|
|
481
|
+
return outcome ? OUTCOME_LABELS[outcome] : "\u2014";
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// src/ui/pipeline/guardrail-labels.ts
|
|
485
|
+
var NO_GUARDRAIL_REASON = "no_guardrail";
|
|
486
|
+
var GUARDRAIL_LABELS = {
|
|
487
|
+
whatsapp: "conversation WhatsApp",
|
|
488
|
+
whatsapp_stop: "le client a demand\xE9 \xE0 ne plus \xEAtre contact\xE9 (STOP)",
|
|
489
|
+
not_customer_turn: "le dernier message du fil est de nous",
|
|
490
|
+
judgeme: "avis Judge.me",
|
|
491
|
+
noreply_sender: "exp\xE9diteur automatique",
|
|
492
|
+
triage_not_high: "triage pas en confiance haute",
|
|
493
|
+
escalated: "ticket d\xE9j\xE0 escalad\xE9",
|
|
494
|
+
blocklist: "terme de la liste de blocage",
|
|
495
|
+
attachment: "pi\xE8ce jointe c\xF4t\xE9 client",
|
|
496
|
+
short_answer: "r\xE9ponse trop courte",
|
|
497
|
+
uncertainty_marker: "marqueur d\u2019incertitude dans la r\xE9ponse",
|
|
498
|
+
evaluation_missing: "aucune \xE9valuation produite"
|
|
499
|
+
};
|
|
500
|
+
function guardrailHitLabel(hit) {
|
|
501
|
+
if (hit === NO_GUARDRAIL_REASON) return "bloqu\xE9e par le verdict ou le seuil, sans garde-fou";
|
|
502
|
+
if (hit.startsWith("blocklist:")) return `terme bloqu\xE9 \xAB ${hit.slice("blocklist:".length)} \xBB`;
|
|
503
|
+
return GUARDRAIL_LABELS[hit] ?? hit;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// src/ui/tickets/ticket-outcome.ts
|
|
507
|
+
var NO_JOB = { label: "Aucune r\xE9ponse g\xE9n\xE9r\xE9e", variant: "neutral" };
|
|
508
|
+
function responseOutcome(job) {
|
|
509
|
+
if (!job) return NO_JOB;
|
|
510
|
+
if (job.autoSendDecision === "hold") return { label: AUTO_SEND_DECISION_LABELS.hold, variant: "warning" };
|
|
511
|
+
if (job.status === "sent") return { label: GENERATED_RESPONSE_STATUS_LABELS.sent, variant: "success" };
|
|
512
|
+
if (job.status === "failed") return { label: GENERATED_RESPONSE_STATUS_LABELS.failed, variant: "danger" };
|
|
513
|
+
if (job.status === "pending" || job.status === "sending") return { label: "En cours", variant: "neutral" };
|
|
514
|
+
const label = isGeneratedResponseStatus(job.status) ? GENERATED_RESPONSE_STATUS_LABELS[job.status] : job.status;
|
|
515
|
+
return { label, variant: "neutral" };
|
|
516
|
+
}
|
|
517
|
+
var DECISIONS_PAGE_SIZE = 50;
|
|
518
|
+
var JOBS_WINDOW_SIZE = 200;
|
|
519
|
+
var OUTCOME_BADGE_VARIANT = {
|
|
520
|
+
neutral: "neutral",
|
|
521
|
+
success: "success",
|
|
522
|
+
warning: "warning",
|
|
523
|
+
danger: "danger"
|
|
524
|
+
};
|
|
525
|
+
var ESCALATED_OPTIONS = [
|
|
526
|
+
{ value: "", label: "Toutes d\xE9cisions" },
|
|
527
|
+
{ value: "true", label: "Escalad\xE9s" },
|
|
528
|
+
{ value: "false", label: "Non escalad\xE9s" }
|
|
529
|
+
];
|
|
530
|
+
var OUTCOME_FILTER_OPTIONS = [
|
|
531
|
+
{ value: "", label: "Tous les r\xE9sultats" },
|
|
532
|
+
{ value: "none", label: "Aucune r\xE9ponse g\xE9n\xE9r\xE9e" },
|
|
533
|
+
{ value: "success", label: "Envoy\xE9es" },
|
|
534
|
+
{ value: "warning", label: "Bloqu\xE9es" },
|
|
535
|
+
{ value: "danger", label: "\xC9checs" }
|
|
536
|
+
];
|
|
537
|
+
function buildFilter(escalated) {
|
|
538
|
+
return escalated ? { escalated: { eq: escalated === "true" } } : void 0;
|
|
539
|
+
}
|
|
540
|
+
function OutcomeBadge({ outcome }) {
|
|
541
|
+
return /* @__PURE__ */ jsx(Badge, { variant: OUTCOME_BADGE_VARIANT[outcome.variant], children: outcome.label });
|
|
542
|
+
}
|
|
543
|
+
function DetailPanel({
|
|
544
|
+
decision,
|
|
545
|
+
categoryName,
|
|
546
|
+
job,
|
|
547
|
+
agentName,
|
|
548
|
+
langfuseConfig,
|
|
549
|
+
onClose
|
|
550
|
+
}) {
|
|
551
|
+
return /* @__PURE__ */ jsx(SidePanel, { open: true, onClose, title: `Ticket ${decision.ticketId}`, description: categoryName, children: /* @__PURE__ */ jsxs("div", { className: "space-y-4 text-sm", children: [
|
|
552
|
+
decision.status === "error" && /* @__PURE__ */ jsxs("div", { className: "rounded-md bg-destructive/10 p-3 text-destructive", children: [
|
|
553
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs font-semibold uppercase tracking-wider", children: TRIAGE_DECISION_STATUS_LABELS.error }),
|
|
554
|
+
decision.error && /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs", children: decision.error })
|
|
555
|
+
] }),
|
|
556
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
557
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Triage" }),
|
|
558
|
+
/* @__PURE__ */ jsx("p", { children: decision.reasoning ?? "\u2014" }),
|
|
559
|
+
decision.tag && /* @__PURE__ */ jsx("code", { className: "mt-1 block text-xs text-muted-foreground", children: decision.tag })
|
|
560
|
+
] }),
|
|
561
|
+
decision.escalated && /* @__PURE__ */ jsxs("div", { children: [
|
|
562
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Escalade" }),
|
|
563
|
+
/* @__PURE__ */ jsxs("p", { children: [
|
|
564
|
+
"Confiance :",
|
|
565
|
+
" ",
|
|
566
|
+
decision.escalationConfidence ? TRIAGE_CONFIDENCE_LABELS[decision.escalationConfidence] : "\u2014"
|
|
567
|
+
] }),
|
|
568
|
+
decision.escalationReasoning && /* @__PURE__ */ jsx("p", { className: "mt-1", children: decision.escalationReasoning })
|
|
569
|
+
] }),
|
|
570
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
571
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "R\xE9ponse" }),
|
|
572
|
+
job ? /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
573
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3 text-xs text-muted-foreground", children: [
|
|
574
|
+
/* @__PURE__ */ jsx(OutcomeBadge, { outcome: responseOutcome(job) }),
|
|
575
|
+
job.agentId && /* @__PURE__ */ jsxs("span", { children: [
|
|
576
|
+
"Agent : ",
|
|
577
|
+
agentName
|
|
578
|
+
] }),
|
|
579
|
+
job.channel && /* @__PURE__ */ jsxs("span", { children: [
|
|
580
|
+
"Canal : ",
|
|
581
|
+
job.channel
|
|
582
|
+
] })
|
|
583
|
+
] }),
|
|
584
|
+
job.verdict && (job.verdict.verdict || job.verdict.confidence !== null) && /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
|
|
585
|
+
job.verdict.verdict && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
586
|
+
"Verdict : ",
|
|
587
|
+
EVALUATION_VERDICT_LABELS[job.verdict.verdict],
|
|
588
|
+
" \xB7 "
|
|
589
|
+
] }),
|
|
590
|
+
job.verdict.confidence !== null && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
591
|
+
"Confiance : ",
|
|
592
|
+
Math.round(job.verdict.confidence * 100),
|
|
593
|
+
" %"
|
|
594
|
+
] })
|
|
595
|
+
] }),
|
|
596
|
+
job.responseText && /* @__PURE__ */ jsxs("div", { children: [
|
|
597
|
+
/* @__PURE__ */ jsx("pre", { className: "whitespace-pre-wrap rounded-md border p-3 text-xs", children: job.responseText }),
|
|
598
|
+
/* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(CopyButton, { value: job.responseText, label: "Copier la r\xE9ponse" }) })
|
|
599
|
+
] }),
|
|
600
|
+
job.verdict?.reason && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: job.verdict.reason }),
|
|
601
|
+
job.guardrailHits.length > 0 && /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1", children: job.guardrailHits.map((hit, index) => /* @__PURE__ */ jsx("code", { className: "rounded bg-status-warning/10 px-1.5 py-0.5 text-xs text-status-warning", children: guardrailHitLabel(hit) }, `${hit}-${index}`)) }),
|
|
602
|
+
job.error && /* @__PURE__ */ jsxs("div", { className: "rounded-md bg-destructive/10 p-3 text-destructive", children: [
|
|
603
|
+
"Erreur : ",
|
|
604
|
+
job.error
|
|
605
|
+
] }),
|
|
606
|
+
job.sentAt && /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
|
|
607
|
+
"Envoy\xE9e le ",
|
|
608
|
+
formatDate(job.sentAt)
|
|
609
|
+
] }),
|
|
610
|
+
(job.promptName || job.sentMessageId) && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground", children: [
|
|
611
|
+
job.promptName && /* @__PURE__ */ jsxs("span", { children: [
|
|
612
|
+
"Prompt : ",
|
|
613
|
+
/* @__PURE__ */ jsx("code", { children: job.promptName }),
|
|
614
|
+
job.promptVersion !== null ? ` v${job.promptVersion}` : ""
|
|
615
|
+
] }),
|
|
616
|
+
job.sentMessageId && /* @__PURE__ */ jsxs("span", { children: [
|
|
617
|
+
"Message Gorgias : ",
|
|
618
|
+
job.sentMessageId
|
|
619
|
+
] })
|
|
620
|
+
] }),
|
|
621
|
+
(job.langfuseTraceId || job.langfuseObservationId) && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
|
|
622
|
+
/* @__PURE__ */ jsx(LangfuseTraceLink, { traceId: job.langfuseTraceId, config: langfuseConfig, label: "Trace g\xE9n\xE9ration" }),
|
|
623
|
+
/* @__PURE__ */ jsx(
|
|
624
|
+
LangfuseTraceLink,
|
|
625
|
+
{
|
|
626
|
+
traceId: job.langfuseTraceId,
|
|
627
|
+
observationId: job.langfuseObservationId,
|
|
628
|
+
config: langfuseConfig,
|
|
629
|
+
label: "Trace \xE9valuation"
|
|
630
|
+
}
|
|
631
|
+
)
|
|
632
|
+
] })
|
|
633
|
+
] }) : /* @__PURE__ */ jsxs("p", { className: "text-muted-foreground", children: [
|
|
634
|
+
"Aucune r\xE9ponse g\xE9n\xE9r\xE9e pour cette d\xE9cision \u2014 le ticket n'\xE9tait pas \xE9ligible, ou la fen\xEAtre lue par cette page (",
|
|
635
|
+
JOBS_WINDOW_SIZE,
|
|
636
|
+
" r\xE9ponses) ne l'atteint pas."
|
|
637
|
+
] })
|
|
638
|
+
] }),
|
|
639
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
640
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs uppercase tracking-wide text-muted-foreground", children: "D\xE9cid\xE9 le" }),
|
|
641
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs font-semibold", children: formatDate(decision.decidedAt) })
|
|
642
|
+
] })
|
|
643
|
+
] }) });
|
|
644
|
+
}
|
|
645
|
+
function TicketsPage() {
|
|
646
|
+
const [escalatedFilter, setEscalatedFilter] = useState("");
|
|
647
|
+
const [outcomeFilter, setOutcomeFilter] = useState("");
|
|
648
|
+
const [detailDecision, setDetailDecision] = useState(null);
|
|
649
|
+
const {
|
|
650
|
+
rows: decisions,
|
|
651
|
+
isLoading: decisionsLoading,
|
|
652
|
+
error: decisionsError,
|
|
653
|
+
refresh: refreshDecisions,
|
|
654
|
+
hasNextPage,
|
|
655
|
+
hasPreviousPage,
|
|
656
|
+
goToNextPage,
|
|
657
|
+
goToPreviousPage
|
|
658
|
+
} = useRecordList(
|
|
659
|
+
"triage-decision",
|
|
660
|
+
{
|
|
661
|
+
filter: buildFilter(escalatedFilter),
|
|
662
|
+
sort: [{ field: "decidedAt", direction: "desc" }],
|
|
663
|
+
limit: DECISIONS_PAGE_SIZE,
|
|
664
|
+
paginate: true
|
|
665
|
+
},
|
|
666
|
+
toTriageDecision
|
|
667
|
+
);
|
|
668
|
+
const {
|
|
669
|
+
rows: jobs,
|
|
670
|
+
isLoading: jobsLoading,
|
|
671
|
+
error: jobsError,
|
|
672
|
+
refresh: refreshJobs
|
|
673
|
+
} = useRecordList(
|
|
674
|
+
"generated-response",
|
|
675
|
+
{ sort: [{ field: "generatedAt", direction: "desc" }], limit: JOBS_WINDOW_SIZE },
|
|
676
|
+
toGeneratedResponse
|
|
677
|
+
);
|
|
678
|
+
const { rows: agents } = useRecordList("agent", { limit: 500 }, toAgent);
|
|
679
|
+
const agentNames = useMemo(() => toNameMap(agents), [agents]);
|
|
680
|
+
function refreshBoth() {
|
|
681
|
+
return Promise.all([refreshDecisions(), refreshJobs()]).then(() => void 0);
|
|
682
|
+
}
|
|
683
|
+
const { rows: categories } = useRecordList("category", { limit: 500 }, toCategory);
|
|
684
|
+
const categoryNames = useMemo(() => toNameMap(categories), [categories]);
|
|
685
|
+
const { config: langfuseConfig } = useLangfuseConfig();
|
|
686
|
+
const jobByDecisionId = useMemo(() => {
|
|
687
|
+
const map = /* @__PURE__ */ new Map();
|
|
688
|
+
for (const job of jobs) {
|
|
689
|
+
if (job.triageDecisionId) map.set(job.triageDecisionId, job);
|
|
690
|
+
}
|
|
691
|
+
return map;
|
|
692
|
+
}, [jobs]);
|
|
693
|
+
const joinWindowMayBeIncomplete = jobs.length >= JOBS_WINDOW_SIZE;
|
|
694
|
+
const rows = useMemo(() => {
|
|
695
|
+
const withOutcome = decisions.map((decision) => ({
|
|
696
|
+
decision,
|
|
697
|
+
job: jobByDecisionId.get(decision.id)
|
|
698
|
+
}));
|
|
699
|
+
if (!outcomeFilter) return withOutcome;
|
|
700
|
+
if (outcomeFilter === "none") return withOutcome.filter((r) => !r.job);
|
|
701
|
+
return withOutcome.filter((r) => r.job && responseOutcome(r.job).variant === outcomeFilter);
|
|
702
|
+
}, [decisions, jobByDecisionId, outcomeFilter]);
|
|
703
|
+
const columns = [
|
|
704
|
+
{ key: "ticketId", header: "Ticket", cell: ({ decision }) => decision.ticketId },
|
|
705
|
+
{
|
|
706
|
+
key: "category",
|
|
707
|
+
header: "Cat\xE9gorie",
|
|
708
|
+
cell: ({ decision }) => decision.categoryId && categoryNames.get(decision.categoryId) || "\u2014"
|
|
709
|
+
},
|
|
710
|
+
{ key: "tag", header: "Tag", cell: ({ decision }) => decision.tag ? /* @__PURE__ */ jsx("code", { className: "text-xs", children: decision.tag }) : "\u2014" },
|
|
711
|
+
{
|
|
712
|
+
key: "status",
|
|
713
|
+
header: "Statut",
|
|
714
|
+
// §3.4 freezes `decision.status`/`decision.error` — dropped from every
|
|
715
|
+
// surface of this page in pass 1 (T27 rework, pass 2 of 2), so an
|
|
716
|
+
// errored triage was indistinguishable from a clean one at a glance.
|
|
717
|
+
cell: ({ decision }) => decision.status === "error" ? /* @__PURE__ */ jsx(Badge, { variant: "danger", children: TRIAGE_DECISION_STATUS_LABELS.error }) : /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "\u2014" })
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
key: "escalated",
|
|
721
|
+
header: "Escalade",
|
|
722
|
+
cell: ({ decision }) => decision.escalated ? /* @__PURE__ */ jsx(Badge, { variant: "warning", children: "Escalad\xE9" }) : /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "Non escalad\xE9" })
|
|
723
|
+
},
|
|
724
|
+
{ key: "outcome", header: "R\xE9ponse", cell: ({ job }) => /* @__PURE__ */ jsx(OutcomeBadge, { outcome: responseOutcome(job) }) },
|
|
725
|
+
{ key: "decidedAt", header: "D\xE9cid\xE9 le", cell: ({ decision }) => formatDate(decision.decidedAt) }
|
|
726
|
+
];
|
|
727
|
+
const isLoading = decisionsLoading || jobsLoading;
|
|
728
|
+
const combinedError = decisionsError ?? jobsError;
|
|
729
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
730
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
731
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
732
|
+
/* @__PURE__ */ jsx("h1", { className: "text-lg font-semibold", children: "Demandes" }),
|
|
733
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Les tickets trait\xE9s par le graphe, et le parcours de chacun." })
|
|
734
|
+
] }),
|
|
735
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", onClick: () => void refreshBoth(), children: "Actualiser" })
|
|
736
|
+
] }),
|
|
737
|
+
joinWindowMayBeIncomplete && /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
|
|
738
|
+
"La jointure ne lit que les ",
|
|
739
|
+
JOBS_WINDOW_SIZE,
|
|
740
|
+
" derni\xE8res r\xE9ponses g\xE9n\xE9r\xE9es \u2014 au-del\xE0, l'absence de r\xE9ponse affich\xE9e ici peut \xEAtre un simple effet de fen\xEAtre, pas un fait."
|
|
741
|
+
] }),
|
|
742
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
|
|
743
|
+
/* @__PURE__ */ jsx(
|
|
744
|
+
Select,
|
|
745
|
+
{
|
|
746
|
+
items: ESCALATED_OPTIONS,
|
|
747
|
+
value: escalatedFilter,
|
|
748
|
+
onValueChange: setEscalatedFilter,
|
|
749
|
+
placeholder: "Toutes d\xE9cisions",
|
|
750
|
+
"aria-label": "Filtrer par d\xE9cision"
|
|
751
|
+
}
|
|
752
|
+
),
|
|
753
|
+
/* @__PURE__ */ jsx(
|
|
754
|
+
Select,
|
|
755
|
+
{
|
|
756
|
+
items: OUTCOME_FILTER_OPTIONS,
|
|
757
|
+
value: outcomeFilter,
|
|
758
|
+
onValueChange: setOutcomeFilter,
|
|
759
|
+
placeholder: "Tous les r\xE9sultats",
|
|
760
|
+
"aria-label": "Filtrer par r\xE9sultat de r\xE9ponse"
|
|
761
|
+
}
|
|
762
|
+
),
|
|
763
|
+
rows.length > 0 && /* @__PURE__ */ jsxs("span", { className: "ml-auto text-sm text-muted-foreground", children: [
|
|
764
|
+
rows.length,
|
|
765
|
+
" r\xE9sultat",
|
|
766
|
+
rows.length > 1 ? "s" : "",
|
|
767
|
+
" sur cette page"
|
|
768
|
+
] })
|
|
769
|
+
] }),
|
|
770
|
+
/* @__PURE__ */ jsx(
|
|
771
|
+
DataTable,
|
|
772
|
+
{
|
|
773
|
+
columns,
|
|
774
|
+
rows,
|
|
775
|
+
rowId: (row) => row.decision.id,
|
|
776
|
+
manual: true,
|
|
777
|
+
loading: isLoading,
|
|
778
|
+
onRowClick: (row) => setDetailDecision(row.decision),
|
|
779
|
+
pagination: {
|
|
780
|
+
hasNext: hasNextPage,
|
|
781
|
+
hasPrevious: hasPreviousPage,
|
|
782
|
+
onNext: goToNextPage,
|
|
783
|
+
onPrevious: goToPreviousPage
|
|
784
|
+
},
|
|
785
|
+
error: combinedError !== void 0 ? /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-3", children: [
|
|
786
|
+
"Erreur lors du chargement des demandes.",
|
|
787
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => void refreshBoth(), children: "R\xE9essayer" })
|
|
788
|
+
] }) : void 0,
|
|
789
|
+
empty: "Aucune d\xE9cision de triage pour l'instant."
|
|
790
|
+
}
|
|
791
|
+
),
|
|
792
|
+
detailDecision && /* @__PURE__ */ jsx(
|
|
793
|
+
DetailPanel,
|
|
794
|
+
{
|
|
795
|
+
decision: detailDecision,
|
|
796
|
+
categoryName: detailDecision.categoryId && categoryNames.get(detailDecision.categoryId) || "\u2014",
|
|
797
|
+
job: jobByDecisionId.get(detailDecision.id),
|
|
798
|
+
agentName: jobByDecisionId.get(detailDecision.id)?.agentId && agentNames.get(jobByDecisionId.get(detailDecision.id).agentId) || "\u2014",
|
|
799
|
+
langfuseConfig,
|
|
800
|
+
onClose: () => setDetailDecision(null)
|
|
801
|
+
}
|
|
802
|
+
)
|
|
803
|
+
] });
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// src/ui/shared/idempotency-key.ts
|
|
807
|
+
function idempotencyKeyFor(operation, payload) {
|
|
808
|
+
const seed = `${operation}:${JSON.stringify(payload)}`;
|
|
809
|
+
let hash = 2166136261;
|
|
810
|
+
for (let i = 0; i < seed.length; i++) {
|
|
811
|
+
hash ^= seed.charCodeAt(i);
|
|
812
|
+
hash = Math.imul(hash, 16777619);
|
|
813
|
+
}
|
|
814
|
+
return (hash >>> 0).toString(16);
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
// src/ui/shared/settings-issue-labels.ts
|
|
818
|
+
var SETTINGS_ISSUE_LABELS = {
|
|
819
|
+
sourceViewId: "Vue Gorgias source requise \u2014 choisissez la vue que cette app poss\xE8de.",
|
|
820
|
+
nodes: "nodes.triage doit \xEAtre configur\xE9 \u2014 une \xE9tape de triage \xE0 null ne triagerait rien.",
|
|
821
|
+
senderEmail: "Adresse d'envoi requise quand l'envoi automatique est actif (sauf en mode WhatsApp \xAB auto_reply \xBB)."
|
|
822
|
+
};
|
|
823
|
+
function settingsIssueLabel(key, fallback) {
|
|
824
|
+
return SETTINGS_ISSUE_LABELS[key] ?? fallback;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
// src/ui/shared/function-error-labels.ts
|
|
828
|
+
var EXACT_MESSAGE_LABELS = {
|
|
829
|
+
"name is required": "Le nom est requis.",
|
|
830
|
+
"content is required": "Le contenu est requis.",
|
|
831
|
+
"agentId is required": "L'agent est requis.",
|
|
832
|
+
"ticketId is required": "Le ticket est requis.",
|
|
833
|
+
"No non-identical comparison found for this agent": "Aucune comparaison diff\xE9rente de l'original n'a \xE9t\xE9 trouv\xE9e pour cet agent.",
|
|
834
|
+
"The model returned an invalid JSON response": "Le mod\xE8le a renvoy\xE9 une r\xE9ponse JSON invalide.",
|
|
835
|
+
"Either viewId or ticketIds is required": "Une vue ou une liste de tickets est requise."
|
|
836
|
+
};
|
|
837
|
+
var SETTINGS_VALIDATION_MESSAGE_LABELS = {
|
|
838
|
+
"sourceViewId is required \u2014 pick the Gorgias view this app owns.": SETTINGS_ISSUE_LABELS.sourceViewId,
|
|
839
|
+
"nodes.triage must be configured \u2014 a null triage step would triage nothing.": SETTINGS_ISSUE_LABELS.nodes,
|
|
840
|
+
"senderEmail is required when autoSendEnabled is on, unless whatsappMode is 'auto_reply'.": SETTINGS_ISSUE_LABELS.senderEmail
|
|
841
|
+
};
|
|
842
|
+
var DYNAMIC_MESSAGE_PATTERNS = [
|
|
843
|
+
{
|
|
844
|
+
// create-shared-prompt-version.ts
|
|
845
|
+
pattern: /^"(.+)" is not a shared\/\* prompt — create-shared-prompt-version only writes the shared\/\* library\.$/,
|
|
846
|
+
build: ([, name]) => `\xAB ${name} \xBB n'est pas un prompt shared/* \u2014 seule la biblioth\xE8que shared/* peut \xEAtre \xE9crite ici.`
|
|
847
|
+
},
|
|
848
|
+
{
|
|
849
|
+
// run-diff-analysis.ts / suggest-prompt.ts
|
|
850
|
+
pattern: /^Agent "(.+)" has no promptName configured$/,
|
|
851
|
+
build: ([, agentId]) => `L'agent \xAB ${agentId} \xBB n'a pas de promptName configur\xE9.`
|
|
852
|
+
},
|
|
853
|
+
{
|
|
854
|
+
// graph-dry-run.ts
|
|
855
|
+
pattern: /^Category "(.+)" not found$/,
|
|
856
|
+
build: ([, categoryId]) => `Cat\xE9gorie \xAB ${categoryId} \xBB introuvable.`
|
|
857
|
+
},
|
|
858
|
+
{
|
|
859
|
+
// validate-references.ts, via create-shared-prompt-version.ts's "Invalid reference tags: …"
|
|
860
|
+
pattern: /^Malformed reference tag near "(.*)": it will be saved as literal text instead of being resolved\.$/,
|
|
861
|
+
build: ([, snippet]) => `Balise de r\xE9f\xE9rence malform\xE9e pr\xE8s de \xAB ${snippet} \xBB : elle sera enregistr\xE9e telle quelle au lieu d'\xEAtre r\xE9solue.`
|
|
862
|
+
},
|
|
863
|
+
{
|
|
864
|
+
pattern: /^Reference "(.+)" points to this same prompt \("(.+)"\) — a prompt cannot reference itself\.$/,
|
|
865
|
+
build: ([, raw, self]) => `La r\xE9f\xE9rence \xAB ${raw} \xBB pointe vers ce m\xEAme prompt (\xAB ${self} \xBB) \u2014 un prompt ne peut pas se r\xE9f\xE9rencer lui-m\xEAme.`
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
pattern: /^Reference "(.+)" points to prompt "(.+)", which exists but is outside this app's prompts allowlist \(role\.prompts\) — it cannot be composed here even though it can be read elsewhere\.$/,
|
|
869
|
+
build: ([, raw, name]) => `La r\xE9f\xE9rence \xAB ${raw} \xBB pointe vers le prompt \xAB ${name} \xBB, qui existe mais est hors de la liste autoris\xE9e de cette app (role.prompts) \u2014 il ne peut pas \xEAtre compos\xE9 ici, m\xEAme s'il reste lisible ailleurs.`
|
|
870
|
+
},
|
|
871
|
+
{
|
|
872
|
+
pattern: /^Reference "(.+)" could not be resolved: prompt "(.+)" with (.+) was not found, or the prompt store could not be reached to verify it\.$/,
|
|
873
|
+
build: ([, raw, name, locator]) => `La r\xE9f\xE9rence \xAB ${raw} \xBB n'a pas pu \xEAtre r\xE9solue : le prompt \xAB ${name} \xBB avec ${locator} est introuvable, ou le magasin de prompts \xE9tait injoignable pour le v\xE9rifier.`
|
|
874
|
+
},
|
|
875
|
+
{
|
|
876
|
+
pattern: /^Reference "(.+)" creates a cycle: prompt "(.+)" \(transitively\) references this prompt \("(.+)"\)\.$/,
|
|
877
|
+
build: ([, raw, name, self]) => `La r\xE9f\xE9rence \xAB ${raw} \xBB cr\xE9e un cycle : le prompt \xAB ${name} \xBB r\xE9f\xE9rence (de fa\xE7on transitive) ce m\xEAme prompt (\xAB ${self} \xBB).`
|
|
878
|
+
},
|
|
879
|
+
{
|
|
880
|
+
pattern: /^Reference chain exceeds the runtime composition cap \((\d+) levels\): the segment past that depth would be silently stripped when this prompt is resolved\.$/,
|
|
881
|
+
build: ([, levels]) => `La cha\xEEne de r\xE9f\xE9rences d\xE9passe la limite de composition (${levels} niveaux) : le segment au-del\xE0 de cette profondeur serait silencieusement supprim\xE9 lors de la r\xE9solution du prompt.`
|
|
882
|
+
}
|
|
883
|
+
];
|
|
884
|
+
function translateSettingsInvalidMessage(message) {
|
|
885
|
+
const prefix = "Settings are invalid: ";
|
|
886
|
+
if (!message.startsWith(prefix)) return null;
|
|
887
|
+
const rest = message.slice(prefix.length);
|
|
888
|
+
const translatedRest = Object.entries(SETTINGS_VALIDATION_MESSAGE_LABELS).reduce(
|
|
889
|
+
(acc, [en, fr]) => acc.split(en).join(fr),
|
|
890
|
+
rest
|
|
891
|
+
);
|
|
892
|
+
return `R\xE9glages invalides : ${translatedRest}`;
|
|
893
|
+
}
|
|
894
|
+
function translateReferenceTagsMessage(message) {
|
|
895
|
+
const prefix = "Invalid reference tags: ";
|
|
896
|
+
if (!message.startsWith(prefix)) return null;
|
|
897
|
+
const rest = message.slice(prefix.length);
|
|
898
|
+
const translatedRest = translateFunctionErrorMessage(rest);
|
|
899
|
+
return `Balises de r\xE9f\xE9rence invalides : ${translatedRest}`;
|
|
900
|
+
}
|
|
901
|
+
function translateDynamicMessage(message) {
|
|
902
|
+
for (const { pattern, build } of DYNAMIC_MESSAGE_PATTERNS) {
|
|
903
|
+
const match = message.match(pattern);
|
|
904
|
+
if (match) return build(match);
|
|
905
|
+
}
|
|
906
|
+
return null;
|
|
907
|
+
}
|
|
908
|
+
function translateFunctionErrorMessage(message) {
|
|
909
|
+
if (message in EXACT_MESSAGE_LABELS) return EXACT_MESSAGE_LABELS[message];
|
|
910
|
+
const settingsTranslated = translateSettingsInvalidMessage(message);
|
|
911
|
+
if (settingsTranslated !== null) return settingsTranslated;
|
|
912
|
+
const referenceTagsTranslated = translateReferenceTagsMessage(message);
|
|
913
|
+
if (referenceTagsTranslated !== null) return referenceTagsTranslated;
|
|
914
|
+
const dynamicTranslated = translateDynamicMessage(message);
|
|
915
|
+
if (dynamicTranslated !== null) return dynamicTranslated;
|
|
916
|
+
return message;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
// src/ui/shared/invoke-error.ts
|
|
920
|
+
var GENERIC_MESSAGE = "Une erreur est survenue. R\xE9essayez, ou contactez un administrateur si le probl\xE8me persiste.";
|
|
921
|
+
function describeInvokeError(err) {
|
|
922
|
+
if (err instanceof AppInvokeError && err.code === "FUNCTION_REJECTED") {
|
|
923
|
+
return translateFunctionErrorMessage(err.message);
|
|
924
|
+
}
|
|
925
|
+
return GENERIC_MESSAGE;
|
|
926
|
+
}
|
|
927
|
+
function describeApiError(err) {
|
|
928
|
+
const shape = err;
|
|
929
|
+
const status = shape?.response?.status ?? shape?.status;
|
|
930
|
+
const message = shape?.response?.data?.message ?? shape?.message;
|
|
931
|
+
if (typeof status === "number" && status >= 400 && status < 500 && message) {
|
|
932
|
+
return message;
|
|
933
|
+
}
|
|
934
|
+
return GENERIC_MESSAGE;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
// src/ui/shared/roles.ts
|
|
938
|
+
function canWriteForRole(role) {
|
|
939
|
+
return role === "EDITOR" || role === "ADMIN";
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// src/ui/pipeline/stats.ts
|
|
943
|
+
var TREATED_STATUSES = /* @__PURE__ */ new Set(["ready", "sending", "sent"]);
|
|
944
|
+
var REACHED_READY_STATUSES = /* @__PURE__ */ new Set(["ready", "sent", "expired", "invalidated"]);
|
|
945
|
+
var GENERATION_ATTEMPT_STATUSES = /* @__PURE__ */ new Set(["ready", "sent", "expired", "invalidated", "failed"]);
|
|
946
|
+
function toCalendarDay(iso, timezone) {
|
|
947
|
+
return new Intl.DateTimeFormat("en-CA", { timeZone: timezone, year: "numeric", month: "2-digit", day: "2-digit" }).format(
|
|
948
|
+
new Date(iso)
|
|
949
|
+
);
|
|
950
|
+
}
|
|
951
|
+
function holdReasonsFor(row) {
|
|
952
|
+
if (row.guardrailHits.length === 0) return [NO_GUARDRAIL_REASON];
|
|
953
|
+
return row.guardrailHits.map(guardrailBucket);
|
|
954
|
+
}
|
|
955
|
+
function computePipelineStats(rows, timezone = "UTC") {
|
|
956
|
+
const totalGenerated = rows.length;
|
|
957
|
+
const sent = rows.filter((r) => r.status === "sent").length;
|
|
958
|
+
const held = rows.filter((r) => r.autoSendDecision === "hold").length;
|
|
959
|
+
const treated = rows.filter((r) => isGeneratedResponseStatus(r.status) && TREATED_STATUSES.has(r.status)).length;
|
|
960
|
+
const reachedReady = rows.filter((r) => isGeneratedResponseStatus(r.status) && REACHED_READY_STATUSES.has(r.status));
|
|
961
|
+
const servedAtLeastOnce = reachedReady.filter((r) => r.servedCount > 0).length;
|
|
962
|
+
const attempts = rows.filter((r) => isGeneratedResponseStatus(r.status) && GENERATION_ATTEMPT_STATUSES.has(r.status));
|
|
963
|
+
const failedAttempts = attempts.filter((r) => r.status === "failed").length;
|
|
964
|
+
const servedTotal = rows.reduce((sum, r) => sum + r.servedCount, 0);
|
|
965
|
+
const holdReasonCounts = /* @__PURE__ */ new Map();
|
|
966
|
+
for (const row of rows) {
|
|
967
|
+
if (row.autoSendDecision !== "hold") continue;
|
|
968
|
+
for (const reason2 of holdReasonsFor(row)) {
|
|
969
|
+
holdReasonCounts.set(reason2, (holdReasonCounts.get(reason2) ?? 0) + 1);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
const dailyCounts = /* @__PURE__ */ new Map();
|
|
973
|
+
for (const row of rows) {
|
|
974
|
+
if (!row.generatedAt) continue;
|
|
975
|
+
const day = toCalendarDay(row.generatedAt, timezone);
|
|
976
|
+
const bucket = dailyCounts.get(day) ?? { sent: 0, held: 0 };
|
|
977
|
+
if (row.status === "sent") bucket.sent += 1;
|
|
978
|
+
if (row.autoSendDecision === "hold") bucket.held += 1;
|
|
979
|
+
dailyCounts.set(day, bucket);
|
|
980
|
+
}
|
|
981
|
+
return {
|
|
982
|
+
totalGenerated,
|
|
983
|
+
sent,
|
|
984
|
+
held,
|
|
985
|
+
reuseRate: reachedReady.length === 0 ? null : servedAtLeastOnce / reachedReady.length,
|
|
986
|
+
generationSuccessRate: attempts.length === 0 ? null : (attempts.length - failedAttempts) / attempts.length,
|
|
987
|
+
servedTotal,
|
|
988
|
+
funnel: [
|
|
989
|
+
{ label: "G\xE9n\xE9r\xE9", value: totalGenerated },
|
|
990
|
+
{ label: "Trait\xE9", value: treated },
|
|
991
|
+
{ label: "Envoy\xE9", value: sent }
|
|
992
|
+
],
|
|
993
|
+
holdReasons: [...holdReasonCounts.entries()].map(([reason2, count]) => ({ reason: reason2, count })),
|
|
994
|
+
daily: [...dailyCounts.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([day, counts]) => ({ day, ...counts }))
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
var STATS_PAGE_SIZE = 200;
|
|
998
|
+
var TABLE_PAGE_SIZE = 200;
|
|
999
|
+
var WINDOW_OPTIONS2 = [7, 14, 30];
|
|
1000
|
+
var DECISION_OPTIONS = [
|
|
1001
|
+
{ value: "", label: "Tous" },
|
|
1002
|
+
{ value: "sent", label: "Envoy\xE9s auto" },
|
|
1003
|
+
{ value: "held", label: "Bloqu\xE9s" },
|
|
1004
|
+
{ value: "error", label: "Erreurs" }
|
|
1005
|
+
];
|
|
1006
|
+
var STATUS_FILTER_OPTIONS = [
|
|
1007
|
+
{ value: "", label: "Tous les statuts" },
|
|
1008
|
+
...GENERATED_RESPONSE_STATUSES.map((status) => ({ value: status, label: GENERATED_RESPONSE_STATUS_LABELS[status] }))
|
|
1009
|
+
];
|
|
1010
|
+
var VERDICT_FILTER_OPTIONS = [
|
|
1011
|
+
{ value: "", label: "Tous les verdicts" },
|
|
1012
|
+
...EVALUATION_VERDICTS.map((verdict) => ({ value: verdict, label: EVALUATION_VERDICT_LABELS[verdict] }))
|
|
1013
|
+
];
|
|
1014
|
+
function statusLabel(status) {
|
|
1015
|
+
return isGeneratedResponseStatus(status) ? GENERATED_RESPONSE_STATUS_LABELS[status] : status;
|
|
1016
|
+
}
|
|
1017
|
+
function buildTableFilter(decision, status) {
|
|
1018
|
+
if (decision === "sent") return { status: { eq: "sent" } };
|
|
1019
|
+
if (decision === "held") return { autoSendDecision: { eq: "hold" } };
|
|
1020
|
+
if (decision === "error") return { error: { nempty: true } };
|
|
1021
|
+
if (status) return { status: { eq: status } };
|
|
1022
|
+
return void 0;
|
|
1023
|
+
}
|
|
1024
|
+
function countOrEllipsis(value) {
|
|
1025
|
+
return Number.isNaN(value) ? "\u2026" : String(value);
|
|
1026
|
+
}
|
|
1027
|
+
function windowCutoffIso2(days) {
|
|
1028
|
+
return new Date(Date.now() - days * 24 * 60 * 60 * 1e3).toISOString();
|
|
1029
|
+
}
|
|
1030
|
+
function ConfidenceCell({ confidence }) {
|
|
1031
|
+
if (confidence === null) return /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "\u2014" });
|
|
1032
|
+
return /* @__PURE__ */ jsxs("span", { className: "tabular-nums", children: [
|
|
1033
|
+
Math.round(confidence * 100),
|
|
1034
|
+
"%"
|
|
1035
|
+
] });
|
|
1036
|
+
}
|
|
1037
|
+
function DetailPanel2({
|
|
1038
|
+
row,
|
|
1039
|
+
categoryName,
|
|
1040
|
+
agentName,
|
|
1041
|
+
langfuseConfig,
|
|
1042
|
+
onClose
|
|
1043
|
+
}) {
|
|
1044
|
+
return /* @__PURE__ */ jsx(SidePanel, { open: true, onClose, title: `Ticket ${row.ticketId}`, description: `${categoryName} \u2014 ${agentName}`, children: /* @__PURE__ */ jsxs("div", { className: "space-y-4 text-sm", children: [
|
|
1045
|
+
row.responseText && /* @__PURE__ */ jsxs("div", { children: [
|
|
1046
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "R\xE9ponse g\xE9n\xE9r\xE9e" }),
|
|
1047
|
+
/* @__PURE__ */ jsx("pre", { className: "whitespace-pre-wrap rounded-md border p-3 text-xs", children: row.responseText })
|
|
1048
|
+
] }),
|
|
1049
|
+
row.verdict?.reason && /* @__PURE__ */ jsxs("div", { children: [
|
|
1050
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Raison \xE9valuation" }),
|
|
1051
|
+
/* @__PURE__ */ jsx("p", { children: row.verdict.reason })
|
|
1052
|
+
] }),
|
|
1053
|
+
row.guardrailHits.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
|
|
1054
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Garde-fous d\xE9clench\xE9s" }),
|
|
1055
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1", children: row.guardrailHits.map((hit, index) => /* @__PURE__ */ jsx("code", { className: "rounded bg-status-warning/10 px-1.5 py-0.5 text-xs text-status-warning", children: guardrailHitLabel(hit) }, `${hit}-${index}`)) })
|
|
1056
|
+
] }),
|
|
1057
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4 sm:grid-cols-3", children: [
|
|
1058
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1059
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs uppercase tracking-wide text-muted-foreground", children: "Msg. lors g\xE9n\xE9ration" }),
|
|
1060
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs font-semibold", children: row.generatedMessageCount })
|
|
1061
|
+
] }),
|
|
1062
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1063
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs uppercase tracking-wide text-muted-foreground", children: "Expire" }),
|
|
1064
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs font-semibold", children: formatDate(row.expiresAt) })
|
|
1065
|
+
] }),
|
|
1066
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1067
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs uppercase tracking-wide text-muted-foreground", children: "Envoy\xE9 le" }),
|
|
1068
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs font-semibold", children: formatDate(row.sentAt) })
|
|
1069
|
+
] })
|
|
1070
|
+
] }),
|
|
1071
|
+
row.sentMessageId && /* @__PURE__ */ jsxs("div", { children: [
|
|
1072
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs uppercase tracking-wide text-muted-foreground", children: "Message Gorgias" }),
|
|
1073
|
+
/* @__PURE__ */ jsx("code", { className: "text-xs", children: row.sentMessageId })
|
|
1074
|
+
] }),
|
|
1075
|
+
row.error && /* @__PURE__ */ jsxs("div", { className: "rounded-md bg-destructive/10 p-3 text-destructive", children: [
|
|
1076
|
+
"Erreur : ",
|
|
1077
|
+
row.error
|
|
1078
|
+
] }),
|
|
1079
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground", children: [
|
|
1080
|
+
/* @__PURE__ */ jsx("span", { children: "Valeurs brutes" }),
|
|
1081
|
+
/* @__PURE__ */ jsxs("code", { children: [
|
|
1082
|
+
"status=",
|
|
1083
|
+
row.status
|
|
1084
|
+
] }),
|
|
1085
|
+
/* @__PURE__ */ jsxs("code", { children: [
|
|
1086
|
+
"autoSendDecision=",
|
|
1087
|
+
row.autoSendDecision ?? "\u2014"
|
|
1088
|
+
] }),
|
|
1089
|
+
/* @__PURE__ */ jsxs("code", { children: [
|
|
1090
|
+
"verdict=",
|
|
1091
|
+
row.verdict?.verdict ?? "\u2014"
|
|
1092
|
+
] })
|
|
1093
|
+
] }),
|
|
1094
|
+
(row.langfuseTraceId || row.langfuseObservationId) && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
|
|
1095
|
+
/* @__PURE__ */ jsx(LangfuseTraceLink, { traceId: row.langfuseTraceId, config: langfuseConfig, label: "Trace g\xE9n\xE9ration" }),
|
|
1096
|
+
/* @__PURE__ */ jsx(
|
|
1097
|
+
LangfuseTraceLink,
|
|
1098
|
+
{
|
|
1099
|
+
traceId: row.langfuseTraceId,
|
|
1100
|
+
observationId: row.langfuseObservationId,
|
|
1101
|
+
config: langfuseConfig,
|
|
1102
|
+
label: "Trace \xE9valuation"
|
|
1103
|
+
}
|
|
1104
|
+
)
|
|
1105
|
+
] })
|
|
1106
|
+
] }) });
|
|
1107
|
+
}
|
|
1108
|
+
function PipelinePage() {
|
|
1109
|
+
const { role } = useAppContext();
|
|
1110
|
+
const canWrite = canWriteForRole(role);
|
|
1111
|
+
const api = useAppApi();
|
|
1112
|
+
const toast = useToast();
|
|
1113
|
+
const [isTriaging, setIsTriaging] = useState(false);
|
|
1114
|
+
const isTriagingRef = useRef(false);
|
|
1115
|
+
const [windowDays, setWindowDays] = useState(WINDOW_OPTIONS2[0]);
|
|
1116
|
+
const [decisionFilter, setDecisionFilter] = useState("");
|
|
1117
|
+
const [statusFilter, setStatusFilter] = useState("");
|
|
1118
|
+
const [verdictFilter, setVerdictFilter] = useState("");
|
|
1119
|
+
const [detailRow, setDetailRow] = useState(null);
|
|
1120
|
+
const { settings } = useAppSettings();
|
|
1121
|
+
const {
|
|
1122
|
+
rows: statsRows,
|
|
1123
|
+
isLoading: statsLoading,
|
|
1124
|
+
refresh: refreshStats
|
|
1125
|
+
} = useRecordList(
|
|
1126
|
+
"generated-response",
|
|
1127
|
+
{ sort: [{ field: "generatedAt", direction: "desc" }], limit: STATS_PAGE_SIZE },
|
|
1128
|
+
toGeneratedResponse
|
|
1129
|
+
);
|
|
1130
|
+
const {
|
|
1131
|
+
rows: tableRows,
|
|
1132
|
+
isLoading: tableLoading,
|
|
1133
|
+
error: tableError,
|
|
1134
|
+
refresh: refreshTable
|
|
1135
|
+
} = useRecordList(
|
|
1136
|
+
"generated-response",
|
|
1137
|
+
{
|
|
1138
|
+
filter: buildTableFilter(decisionFilter, statusFilter),
|
|
1139
|
+
sort: [{ field: "generatedAt", direction: "desc" }],
|
|
1140
|
+
limit: TABLE_PAGE_SIZE
|
|
1141
|
+
},
|
|
1142
|
+
toGeneratedResponse
|
|
1143
|
+
);
|
|
1144
|
+
const { rows: categories } = useRecordList("category", { limit: 500 }, toCategory);
|
|
1145
|
+
const { rows: agents } = useRecordList("agent", { limit: 500 }, toAgent);
|
|
1146
|
+
const { config: langfuseConfig } = useLangfuseConfig();
|
|
1147
|
+
const categoryNames = useMemo(() => toNameMap(categories), [categories]);
|
|
1148
|
+
const agentNames = useMemo(() => toNameMap(agents), [agents]);
|
|
1149
|
+
const windowedStatsRows = useMemo(() => {
|
|
1150
|
+
const cutoff = windowCutoffIso2(windowDays);
|
|
1151
|
+
return statsRows.filter((row) => row.generatedAt !== null && row.generatedAt >= cutoff);
|
|
1152
|
+
}, [statsRows, windowDays]);
|
|
1153
|
+
const stats = useMemo(
|
|
1154
|
+
() => computePipelineStats(windowedStatsRows, settings?.statsTimezone ?? "UTC"),
|
|
1155
|
+
[windowedStatsRows, settings?.statsTimezone]
|
|
1156
|
+
);
|
|
1157
|
+
const visibleRows = useMemo(
|
|
1158
|
+
() => verdictFilter ? tableRows.filter((row) => row.verdict?.verdict === verdictFilter) : tableRows,
|
|
1159
|
+
[tableRows, verdictFilter]
|
|
1160
|
+
);
|
|
1161
|
+
async function refreshAll() {
|
|
1162
|
+
await Promise.all([refreshStats(), refreshTable()]);
|
|
1163
|
+
}
|
|
1164
|
+
async function runTriageNow() {
|
|
1165
|
+
if (isTriagingRef.current) return;
|
|
1166
|
+
isTriagingRef.current = true;
|
|
1167
|
+
setIsTriaging(true);
|
|
1168
|
+
try {
|
|
1169
|
+
const result = await api.invoke(
|
|
1170
|
+
"run-triage-now",
|
|
1171
|
+
{},
|
|
1172
|
+
{ idempotencyKey: idempotencyKeyFor("run-triage-now", {}) }
|
|
1173
|
+
);
|
|
1174
|
+
toast(
|
|
1175
|
+
result.status === "already-running" ? { title: "Un triage est d\xE9j\xE0 en cours \u2014 aucun second lot n\u2019a \xE9t\xE9 lanc\xE9.", variant: "info" } : { title: "Triage lanc\xE9 \u2014 suivez le run pour son avancement.", variant: "success" }
|
|
1176
|
+
);
|
|
1177
|
+
await refreshAll();
|
|
1178
|
+
} catch (err) {
|
|
1179
|
+
toast({ title: "\xC9chec du lancement du triage", description: describeInvokeError(err), variant: "error" });
|
|
1180
|
+
} finally {
|
|
1181
|
+
isTriagingRef.current = false;
|
|
1182
|
+
setIsTriaging(false);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
function selectDecision(decision) {
|
|
1186
|
+
setDecisionFilter(decision);
|
|
1187
|
+
if (decision) setStatusFilter("");
|
|
1188
|
+
}
|
|
1189
|
+
const columns = [
|
|
1190
|
+
{ key: "ticketId", header: "Ticket", cell: (row) => row.ticketId },
|
|
1191
|
+
{ key: "category", header: "Cat\xE9gorie", cell: (row) => row.categoryId && categoryNames.get(row.categoryId) || "\u2014" },
|
|
1192
|
+
{ key: "agent", header: "Agent", cell: (row) => row.agentId && agentNames.get(row.agentId) || "\u2014" },
|
|
1193
|
+
{ key: "status", header: "Statut", cell: (row) => /* @__PURE__ */ jsx(Badge, { children: statusLabel(row.status) }) },
|
|
1194
|
+
{ key: "confidence", header: "Confiance", cell: (row) => /* @__PURE__ */ jsx(ConfidenceCell, { confidence: row.verdict?.confidence ?? null }) },
|
|
1195
|
+
{
|
|
1196
|
+
key: "verdict",
|
|
1197
|
+
header: "Verdict",
|
|
1198
|
+
cell: (row) => row.verdict?.verdict ? /* @__PURE__ */ jsx(Badge, { variant: row.verdict.verdict === "hold" ? "warning" : "success", children: EVALUATION_VERDICT_LABELS[row.verdict.verdict] }) : "\u2014"
|
|
1199
|
+
},
|
|
1200
|
+
{
|
|
1201
|
+
key: "autoSendDecision",
|
|
1202
|
+
header: "Envoi auto",
|
|
1203
|
+
cell: (row) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
|
|
1204
|
+
row.autoSendDecision ? /* @__PURE__ */ jsx(Badge, { variant: row.autoSendDecision === "auto" ? "success" : "warning", children: AUTO_SEND_DECISION_LABELS[row.autoSendDecision] }) : "\u2014",
|
|
1205
|
+
row.status === "sent" && row.verdict?.verdict === "send_and_escalate" && /* @__PURE__ */ jsx(Badge, { variant: "warning", className: "w-fit text-[10px]", children: "\xE0 escalader" }),
|
|
1206
|
+
row.sentAt && /* @__PURE__ */ jsx("span", { className: "whitespace-nowrap text-xs text-muted-foreground", children: formatDate(row.sentAt) })
|
|
1207
|
+
] })
|
|
1208
|
+
},
|
|
1209
|
+
{ key: "servedCount", header: "Servi", align: "right", cell: (row) => String(row.servedCount) },
|
|
1210
|
+
{ key: "generatedAt", header: "G\xE9n\xE9r\xE9 le", cell: (row) => formatDate(row.generatedAt) },
|
|
1211
|
+
{
|
|
1212
|
+
key: "langfuse",
|
|
1213
|
+
header: "Langfuse",
|
|
1214
|
+
cell: (row) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", onClick: (e) => e.stopPropagation(), children: [
|
|
1215
|
+
/* @__PURE__ */ jsx(LangfuseTraceLink, { traceId: row.langfuseTraceId, config: langfuseConfig, label: "G\xE9n\xE9ration" }),
|
|
1216
|
+
/* @__PURE__ */ jsx(
|
|
1217
|
+
LangfuseTraceLink,
|
|
1218
|
+
{
|
|
1219
|
+
traceId: row.langfuseTraceId,
|
|
1220
|
+
observationId: row.langfuseObservationId,
|
|
1221
|
+
config: langfuseConfig,
|
|
1222
|
+
label: "\xC9valuation"
|
|
1223
|
+
}
|
|
1224
|
+
)
|
|
1225
|
+
] })
|
|
1226
|
+
}
|
|
1227
|
+
];
|
|
1228
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
1229
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1230
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1231
|
+
/* @__PURE__ */ jsx("h1", { className: "text-lg font-semibold", children: "Pipeline" }),
|
|
1232
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Cycle de vie des r\xE9ponses g\xE9n\xE9r\xE9es automatiquement." })
|
|
1233
|
+
] }),
|
|
1234
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
1235
|
+
settings && /* @__PURE__ */ jsxs(Badge, { variant: settings.autoSendEnabled ? "success" : "neutral", children: [
|
|
1236
|
+
"Envoi auto : ",
|
|
1237
|
+
settings.autoSendEnabled ? "ACTIF" : "INACTIF"
|
|
1238
|
+
] }),
|
|
1239
|
+
canWrite && /* @__PURE__ */ jsx(Button, { onClick: () => void runTriageNow(), disabled: isTriaging, children: isTriaging ? "Triage en cours\u2026" : "Lancer le triage maintenant" })
|
|
1240
|
+
] })
|
|
1241
|
+
] }),
|
|
1242
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1243
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: "Fen\xEAtre :" }),
|
|
1244
|
+
WINDOW_OPTIONS2.map((days) => /* @__PURE__ */ jsxs(Button, { size: "sm", variant: windowDays === days ? "default" : "outline", onClick: () => setWindowDays(days), children: [
|
|
1245
|
+
days,
|
|
1246
|
+
" j"
|
|
1247
|
+
] }, days))
|
|
1248
|
+
] }),
|
|
1249
|
+
/* @__PURE__ */ jsxs("div", { "data-testid": "pipeline-kpis", className: "grid grid-cols-1 gap-4 sm:grid-cols-3", children: [
|
|
1250
|
+
/* @__PURE__ */ jsx(KpiCard, { label: "G\xE9n\xE9r\xE9", value: statsLoading ? Number.NaN : stats.totalGenerated, formatValue: countOrEllipsis }),
|
|
1251
|
+
/* @__PURE__ */ jsx(KpiCard, { label: "Envoy\xE9", value: statsLoading ? Number.NaN : stats.sent, formatValue: countOrEllipsis }),
|
|
1252
|
+
/* @__PURE__ */ jsx(
|
|
1253
|
+
KpiCard,
|
|
1254
|
+
{
|
|
1255
|
+
label: "Bloqu\xE9s",
|
|
1256
|
+
value: statsLoading ? Number.NaN : stats.held,
|
|
1257
|
+
formatValue: countOrEllipsis,
|
|
1258
|
+
lowerIsBetter: true
|
|
1259
|
+
}
|
|
1260
|
+
)
|
|
1261
|
+
] }),
|
|
1262
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-x-8 gap-y-1 text-xs text-muted-foreground", children: [
|
|
1263
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
1264
|
+
"Taux de r\xE9utilisation",
|
|
1265
|
+
" ",
|
|
1266
|
+
/* @__PURE__ */ jsx("span", { className: "font-semibold tabular-nums text-foreground", children: stats.reuseRate === null ? "\u2014" : `${Math.round(stats.reuseRate * 100)}%` })
|
|
1267
|
+
] }),
|
|
1268
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
1269
|
+
"Succ\xE8s g\xE9n\xE9ration",
|
|
1270
|
+
" ",
|
|
1271
|
+
/* @__PURE__ */ jsx("span", { className: "font-semibold tabular-nums text-foreground", children: stats.generationSuccessRate === null ? "\u2014" : `${Math.round(stats.generationSuccessRate * 100)}%` })
|
|
1272
|
+
] }),
|
|
1273
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
1274
|
+
"Servis ",
|
|
1275
|
+
/* @__PURE__ */ jsx("span", { className: "font-semibold tabular-nums text-foreground", children: stats.servedTotal })
|
|
1276
|
+
] })
|
|
1277
|
+
] }),
|
|
1278
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-4 lg:grid-cols-2", children: [
|
|
1279
|
+
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(CardContent, { className: "p-4", children: /* @__PURE__ */ jsx(FunnelChart, { data: stats.funnel, label: "Entonnoir du pipeline" }) }) }),
|
|
1280
|
+
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-2 p-4", children: [
|
|
1281
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: "Raisons de blocage" }),
|
|
1282
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "Une r\xE9ponse bloqu\xE9e peut d\xE9clencher plusieurs garde-fous : le total peut d\xE9passer le nombre de r\xE9ponses bloqu\xE9es." }),
|
|
1283
|
+
stats.holdReasons.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Aucun garde-fou n\u2019a bloqu\xE9 de r\xE9ponse sur cette fen\xEAtre." }) : /* @__PURE__ */ jsx("ul", { className: "space-y-1 text-sm", children: [...stats.holdReasons].sort((a, b) => b.count - a.count).map((r) => /* @__PURE__ */ jsxs("li", { className: "flex items-center justify-between gap-3", children: [
|
|
1284
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: guardrailHitLabel(r.reason) }),
|
|
1285
|
+
/* @__PURE__ */ jsx("span", { className: "tabular-nums text-muted-foreground", children: r.count })
|
|
1286
|
+
] }, r.reason)) })
|
|
1287
|
+
] }) })
|
|
1288
|
+
] }),
|
|
1289
|
+
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(CardContent, { className: "p-4", children: stats.daily.length === 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1290
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: "\xC9volution par jour" }),
|
|
1291
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Aucune journ\xE9e mesur\xE9e sur cette fen\xEAtre." })
|
|
1292
|
+
] }) : /* @__PURE__ */ jsx(
|
|
1293
|
+
StackedBarChart,
|
|
1294
|
+
{
|
|
1295
|
+
data: stats.daily,
|
|
1296
|
+
x: "day",
|
|
1297
|
+
label: "\xC9volution par jour",
|
|
1298
|
+
series: [
|
|
1299
|
+
{ key: "sent", label: "Envoy\xE9es", colorIndex: 0 },
|
|
1300
|
+
{ key: "held", label: "Bloqu\xE9es", colorIndex: 1 }
|
|
1301
|
+
]
|
|
1302
|
+
}
|
|
1303
|
+
) }) }),
|
|
1304
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
|
|
1305
|
+
DECISION_OPTIONS.map((option) => /* @__PURE__ */ jsx(
|
|
1306
|
+
Button,
|
|
1307
|
+
{
|
|
1308
|
+
size: "sm",
|
|
1309
|
+
variant: decisionFilter === option.value ? "default" : "outline",
|
|
1310
|
+
onClick: () => selectDecision(option.value),
|
|
1311
|
+
children: option.label
|
|
1312
|
+
},
|
|
1313
|
+
option.value
|
|
1314
|
+
)),
|
|
1315
|
+
/* @__PURE__ */ jsx(
|
|
1316
|
+
Select,
|
|
1317
|
+
{
|
|
1318
|
+
items: STATUS_FILTER_OPTIONS,
|
|
1319
|
+
value: statusFilter,
|
|
1320
|
+
onValueChange: setStatusFilter,
|
|
1321
|
+
disabled: decisionFilter !== "",
|
|
1322
|
+
placeholder: "Tous les statuts",
|
|
1323
|
+
"aria-label": "Filtrer par statut"
|
|
1324
|
+
}
|
|
1325
|
+
),
|
|
1326
|
+
/* @__PURE__ */ jsx(
|
|
1327
|
+
Select,
|
|
1328
|
+
{
|
|
1329
|
+
items: VERDICT_FILTER_OPTIONS,
|
|
1330
|
+
value: verdictFilter,
|
|
1331
|
+
onValueChange: setVerdictFilter,
|
|
1332
|
+
placeholder: "Tous les verdicts",
|
|
1333
|
+
"aria-label": "Filtrer par verdict"
|
|
1334
|
+
}
|
|
1335
|
+
),
|
|
1336
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => void refreshTable(), children: "Actualiser" }),
|
|
1337
|
+
visibleRows.length > 0 && /* @__PURE__ */ jsxs("span", { className: "ml-auto text-sm text-muted-foreground", children: [
|
|
1338
|
+
visibleRows.length,
|
|
1339
|
+
" r\xE9sultat",
|
|
1340
|
+
visibleRows.length > 1 ? "s" : ""
|
|
1341
|
+
] })
|
|
1342
|
+
] }),
|
|
1343
|
+
tableLoading || statsLoading ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center py-12", children: [
|
|
1344
|
+
/* @__PURE__ */ jsx(Spinner, {}),
|
|
1345
|
+
" ",
|
|
1346
|
+
/* @__PURE__ */ jsx("span", { className: "ml-2 text-sm text-muted-foreground", children: "Chargement de la file\u2026" })
|
|
1347
|
+
] }) : /* @__PURE__ */ jsx(
|
|
1348
|
+
DataTable,
|
|
1349
|
+
{
|
|
1350
|
+
columns,
|
|
1351
|
+
rows: visibleRows,
|
|
1352
|
+
rowId: (row) => row.id,
|
|
1353
|
+
manual: true,
|
|
1354
|
+
onRowClick: (row) => setDetailRow(row),
|
|
1355
|
+
error: tableError ? /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-3", children: [
|
|
1356
|
+
"Erreur lors du chargement de la file.",
|
|
1357
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => void refreshTable(), children: "R\xE9essayer" })
|
|
1358
|
+
] }) : void 0,
|
|
1359
|
+
empty: "Aucune r\xE9ponse g\xE9n\xE9r\xE9e pour l'instant."
|
|
1360
|
+
}
|
|
1361
|
+
),
|
|
1362
|
+
detailRow && /* @__PURE__ */ jsx(
|
|
1363
|
+
DetailPanel2,
|
|
1364
|
+
{
|
|
1365
|
+
row: detailRow,
|
|
1366
|
+
categoryName: detailRow.categoryId && categoryNames.get(detailRow.categoryId) || "\u2014",
|
|
1367
|
+
agentName: detailRow.agentId && agentNames.get(detailRow.agentId) || "\u2014",
|
|
1368
|
+
langfuseConfig,
|
|
1369
|
+
onClose: () => setDetailRow(null)
|
|
1370
|
+
}
|
|
1371
|
+
)
|
|
1372
|
+
] });
|
|
1373
|
+
}
|
|
1374
|
+
function ConfirmModal({
|
|
1375
|
+
title,
|
|
1376
|
+
description,
|
|
1377
|
+
confirmLabel,
|
|
1378
|
+
busyLabel = "Suppression\u2026",
|
|
1379
|
+
onConfirm,
|
|
1380
|
+
onCancel
|
|
1381
|
+
}) {
|
|
1382
|
+
const [isConfirming, setIsConfirming] = useState(false);
|
|
1383
|
+
async function confirm() {
|
|
1384
|
+
setIsConfirming(true);
|
|
1385
|
+
try {
|
|
1386
|
+
await onConfirm();
|
|
1387
|
+
} finally {
|
|
1388
|
+
setIsConfirming(false);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
return /* @__PURE__ */ jsx(Modal, { open: true, onClose: onCancel, title, children: /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
1392
|
+
/* @__PURE__ */ jsx("div", { className: "text-sm text-muted-foreground", children: description }),
|
|
1393
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
1394
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", onClick: onCancel, disabled: isConfirming, children: "Annuler" }),
|
|
1395
|
+
/* @__PURE__ */ jsx(Button, { variant: "destructive", onClick: () => void confirm(), disabled: isConfirming, children: isConfirming ? busyLabel : confirmLabel })
|
|
1396
|
+
] })
|
|
1397
|
+
] }) });
|
|
1398
|
+
}
|
|
1399
|
+
function usePromptVersions(promptName) {
|
|
1400
|
+
const { appSlug } = useAppContext();
|
|
1401
|
+
const api = useAppApi();
|
|
1402
|
+
const [versions, setVersions] = useState([]);
|
|
1403
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
1404
|
+
const [error, setError] = useState(void 0);
|
|
1405
|
+
const clientRef = useRef(api);
|
|
1406
|
+
clientRef.current = api;
|
|
1407
|
+
const requestIdRef = useRef(0);
|
|
1408
|
+
const isMountedRef = useRef(true);
|
|
1409
|
+
const load = useCallback(async () => {
|
|
1410
|
+
const requestId = ++requestIdRef.current;
|
|
1411
|
+
if (!promptName) {
|
|
1412
|
+
if (requestId === requestIdRef.current && isMountedRef.current) setVersions([]);
|
|
1413
|
+
return;
|
|
1414
|
+
}
|
|
1415
|
+
setIsLoading(true);
|
|
1416
|
+
try {
|
|
1417
|
+
const result = await clientRef.current.get(
|
|
1418
|
+
`/data/apps/${appSlug}/prompts/versions`,
|
|
1419
|
+
{ name: promptName }
|
|
1420
|
+
);
|
|
1421
|
+
if (requestId !== requestIdRef.current || !isMountedRef.current) return;
|
|
1422
|
+
setVersions(result);
|
|
1423
|
+
setError(void 0);
|
|
1424
|
+
} catch (err) {
|
|
1425
|
+
if (requestId !== requestIdRef.current || !isMountedRef.current) return;
|
|
1426
|
+
setError(err);
|
|
1427
|
+
} finally {
|
|
1428
|
+
if (requestId === requestIdRef.current) setIsLoading(false);
|
|
1429
|
+
}
|
|
1430
|
+
}, [appSlug, promptName]);
|
|
1431
|
+
useEffect(() => {
|
|
1432
|
+
isMountedRef.current = true;
|
|
1433
|
+
void load();
|
|
1434
|
+
return () => {
|
|
1435
|
+
isMountedRef.current = false;
|
|
1436
|
+
requestIdRef.current += 1;
|
|
1437
|
+
};
|
|
1438
|
+
}, [load]);
|
|
1439
|
+
const runWrite = useCallback(
|
|
1440
|
+
async (write) => {
|
|
1441
|
+
try {
|
|
1442
|
+
await write();
|
|
1443
|
+
await load();
|
|
1444
|
+
} catch (err) {
|
|
1445
|
+
if (isMountedRef.current) setError(err);
|
|
1446
|
+
throw err;
|
|
1447
|
+
}
|
|
1448
|
+
},
|
|
1449
|
+
[load]
|
|
1450
|
+
);
|
|
1451
|
+
const refreshAgentSnapshot = useCallback(async () => {
|
|
1452
|
+
if (!promptName) return;
|
|
1453
|
+
try {
|
|
1454
|
+
await clientRef.current.invoke("sync-agent-prompt-snapshot", { promptName });
|
|
1455
|
+
} catch {
|
|
1456
|
+
}
|
|
1457
|
+
}, [promptName]);
|
|
1458
|
+
const promote = useCallback(
|
|
1459
|
+
async (version) => {
|
|
1460
|
+
if (!promptName) return;
|
|
1461
|
+
await runWrite(
|
|
1462
|
+
() => clientRef.current.post(`/data/apps/${appSlug}/prompts/promote`, {
|
|
1463
|
+
name: promptName,
|
|
1464
|
+
version,
|
|
1465
|
+
label: "production"
|
|
1466
|
+
})
|
|
1467
|
+
);
|
|
1468
|
+
await refreshAgentSnapshot();
|
|
1469
|
+
},
|
|
1470
|
+
[appSlug, promptName, refreshAgentSnapshot, runWrite]
|
|
1471
|
+
);
|
|
1472
|
+
const deleteVersion = useCallback(
|
|
1473
|
+
async (version) => {
|
|
1474
|
+
if (!promptName) return;
|
|
1475
|
+
const params = new URLSearchParams({ name: promptName, version: String(version) });
|
|
1476
|
+
await runWrite(
|
|
1477
|
+
() => clientRef.current.delete(`/data/apps/${appSlug}/prompts/versions?${params.toString()}`)
|
|
1478
|
+
);
|
|
1479
|
+
},
|
|
1480
|
+
[appSlug, promptName, runWrite]
|
|
1481
|
+
);
|
|
1482
|
+
const createVersion = useCallback(
|
|
1483
|
+
async (content) => {
|
|
1484
|
+
if (!promptName) return;
|
|
1485
|
+
await runWrite(
|
|
1486
|
+
() => clientRef.current.post(`/data/apps/${appSlug}/prompts/versions`, { name: promptName, content })
|
|
1487
|
+
);
|
|
1488
|
+
await refreshAgentSnapshot();
|
|
1489
|
+
},
|
|
1490
|
+
[appSlug, promptName, refreshAgentSnapshot, runWrite]
|
|
1491
|
+
);
|
|
1492
|
+
return { versions, isLoading, error, refresh: load, promote, deleteVersion, createVersion };
|
|
1493
|
+
}
|
|
1494
|
+
function WordDiffView({ title, tokens, keep, hideEqual = false }) {
|
|
1495
|
+
const highlightCls = keep === "delete" ? "bg-destructive/10 text-destructive" : "bg-status-success/10 text-status-success";
|
|
1496
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col overflow-hidden rounded-md border", children: [
|
|
1497
|
+
/* @__PURE__ */ jsx("div", { className: "border-b bg-muted px-3 py-1.5 text-xs font-semibold text-muted-foreground", children: title }),
|
|
1498
|
+
/* @__PURE__ */ jsx("pre", { className: "max-h-96 overflow-y-auto whitespace-pre-wrap p-3 text-xs", children: tokens.map((op, index) => {
|
|
1499
|
+
if (op.op === "equal") return hideEqual ? null : /* @__PURE__ */ jsx("span", { children: op.text }, index);
|
|
1500
|
+
if (op.op !== keep) return null;
|
|
1501
|
+
return /* @__PURE__ */ jsx("span", { className: `rounded px-0.5 ${highlightCls}`, children: op.text }, index);
|
|
1502
|
+
}) })
|
|
1503
|
+
] });
|
|
1504
|
+
}
|
|
1505
|
+
function versionLabel(version) {
|
|
1506
|
+
return version.label ? `v${version.version} \u2014 ${version.label}` : `v${version.version}`;
|
|
1507
|
+
}
|
|
1508
|
+
function VersionCompareView({
|
|
1509
|
+
versions,
|
|
1510
|
+
leftVersion,
|
|
1511
|
+
rightVersion,
|
|
1512
|
+
onSelectLeft,
|
|
1513
|
+
onSelectRight
|
|
1514
|
+
}) {
|
|
1515
|
+
const options = versions.map((v) => ({ value: String(v.version), label: versionLabel(v) }));
|
|
1516
|
+
const left = versions.find((v) => v.version === leftVersion);
|
|
1517
|
+
const right = versions.find((v) => v.version === rightVersion);
|
|
1518
|
+
const ops = useMemo(() => computeWordDiff(left?.content, right?.content), [left?.content, right?.content]);
|
|
1519
|
+
if (!left || !right) return null;
|
|
1520
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-3 rounded-md border p-3", children: [
|
|
1521
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
1522
|
+
/* @__PURE__ */ jsx(Select, { items: options, value: String(leftVersion), onValueChange: (v) => onSelectLeft(Number(v)), "aria-label": "Version de gauche" }),
|
|
1523
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: "vs" }),
|
|
1524
|
+
/* @__PURE__ */ jsx(Select, { items: options, value: String(rightVersion), onValueChange: (v) => onSelectRight(Number(v)), "aria-label": "Version de droite" })
|
|
1525
|
+
] }),
|
|
1526
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3", children: [
|
|
1527
|
+
/* @__PURE__ */ jsx(WordDiffView, { title: versionLabel(left), tokens: ops, keep: "delete" }),
|
|
1528
|
+
/* @__PURE__ */ jsx(WordDiffView, { title: versionLabel(right), tokens: ops, keep: "insert" })
|
|
1529
|
+
] })
|
|
1530
|
+
] });
|
|
1531
|
+
}
|
|
1532
|
+
var STATUS_LABELS = {
|
|
1533
|
+
default: "Par d\xE9faut",
|
|
1534
|
+
available: "Disponible",
|
|
1535
|
+
archived: "Archiv\xE9"
|
|
1536
|
+
};
|
|
1537
|
+
var STATUS_VARIANT = {
|
|
1538
|
+
default: "brand",
|
|
1539
|
+
available: "neutral",
|
|
1540
|
+
archived: "outline"
|
|
1541
|
+
};
|
|
1542
|
+
function emptyForm() {
|
|
1543
|
+
return { name: "", modelId: "", provider: "openai", systemPromptSnapshot: "" };
|
|
1544
|
+
}
|
|
1545
|
+
function formFromAgent(agent) {
|
|
1546
|
+
return {
|
|
1547
|
+
name: agent.name,
|
|
1548
|
+
modelId: agent.modelId,
|
|
1549
|
+
provider: agent.provider,
|
|
1550
|
+
systemPromptSnapshot: agent.systemPromptSnapshot ?? ""
|
|
1551
|
+
};
|
|
1552
|
+
}
|
|
1553
|
+
function AgentFormModal({
|
|
1554
|
+
agent,
|
|
1555
|
+
onClose,
|
|
1556
|
+
onSave
|
|
1557
|
+
}) {
|
|
1558
|
+
const [form, setForm] = useState(
|
|
1559
|
+
agent === "new" ? emptyForm() : formFromAgent(agent)
|
|
1560
|
+
);
|
|
1561
|
+
const [isSaving, setIsSaving] = useState(false);
|
|
1562
|
+
const nameId = useId();
|
|
1563
|
+
const modelId = useId();
|
|
1564
|
+
const snapshotId = useId();
|
|
1565
|
+
const isValid = form.name.trim() !== "" && form.modelId.trim() !== "";
|
|
1566
|
+
async function submit(event) {
|
|
1567
|
+
event.preventDefault();
|
|
1568
|
+
if (isSaving || !isValid) return;
|
|
1569
|
+
setIsSaving(true);
|
|
1570
|
+
try {
|
|
1571
|
+
await onSave(form);
|
|
1572
|
+
} finally {
|
|
1573
|
+
setIsSaving(false);
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
return /* @__PURE__ */ jsx(
|
|
1577
|
+
Modal,
|
|
1578
|
+
{
|
|
1579
|
+
open: true,
|
|
1580
|
+
onClose,
|
|
1581
|
+
title: agent === "new" ? "Nouvel agent" : `Modifier ${form.name}`,
|
|
1582
|
+
children: /* @__PURE__ */ jsxs("form", { className: "space-y-3", onSubmit: (e) => void submit(e), children: [
|
|
1583
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1584
|
+
/* @__PURE__ */ jsx("label", { htmlFor: nameId, className: "mb-1 block text-sm font-medium", children: "Nom" }),
|
|
1585
|
+
/* @__PURE__ */ jsx(Input, { id: nameId, value: form.name, onChange: (e) => setForm({ ...form, name: e.target.value }) })
|
|
1586
|
+
] }),
|
|
1587
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1588
|
+
/* @__PURE__ */ jsx("label", { htmlFor: modelId, className: "mb-1 block text-sm font-medium", children: "Mod\xE8le" }),
|
|
1589
|
+
/* @__PURE__ */ jsx(
|
|
1590
|
+
Input,
|
|
1591
|
+
{
|
|
1592
|
+
id: modelId,
|
|
1593
|
+
value: form.modelId,
|
|
1594
|
+
onChange: (e) => setForm({ ...form, modelId: e.target.value })
|
|
1595
|
+
}
|
|
1596
|
+
)
|
|
1597
|
+
] }),
|
|
1598
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1599
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-sm font-medium", children: "Fournisseur" }),
|
|
1600
|
+
/* @__PURE__ */ jsxs("p", { className: "text-sm text-muted-foreground", children: [
|
|
1601
|
+
form.provider,
|
|
1602
|
+
" \u2014 non modifiable ici ; le fournisseur r\xE9ellement appel\xE9 est celui des Param\xE8tres."
|
|
1603
|
+
] })
|
|
1604
|
+
] }),
|
|
1605
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1606
|
+
/* @__PURE__ */ jsx("label", { htmlFor: snapshotId, className: "mb-1 block text-sm font-medium", children: "Prompt de secours (niveau 3)" }),
|
|
1607
|
+
/* @__PURE__ */ jsx(
|
|
1608
|
+
Textarea,
|
|
1609
|
+
{
|
|
1610
|
+
id: snapshotId,
|
|
1611
|
+
value: form.systemPromptSnapshot,
|
|
1612
|
+
onChange: (e) => setForm({ ...form, systemPromptSnapshot: e.target.value })
|
|
1613
|
+
}
|
|
1614
|
+
)
|
|
1615
|
+
] }),
|
|
1616
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2 pt-2", children: [
|
|
1617
|
+
/* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: onClose, children: "Annuler" }),
|
|
1618
|
+
/* @__PURE__ */ jsx(Button, { type: "submit", disabled: isSaving || !isValid, children: isSaving ? "Enregistrement\u2026" : "Enregistrer" })
|
|
1619
|
+
] })
|
|
1620
|
+
] })
|
|
1621
|
+
}
|
|
1622
|
+
);
|
|
1623
|
+
}
|
|
1624
|
+
function PromptVersionsPanel({
|
|
1625
|
+
agent,
|
|
1626
|
+
canWrite,
|
|
1627
|
+
onClose
|
|
1628
|
+
}) {
|
|
1629
|
+
const { versions, error, refresh, promote, deleteVersion, createVersion } = usePromptVersions(
|
|
1630
|
+
agent.promptName
|
|
1631
|
+
);
|
|
1632
|
+
const [suggestMessage, setSuggestMessage] = useState(null);
|
|
1633
|
+
const [isSuggesting, setIsSuggesting] = useState(false);
|
|
1634
|
+
const isSuggestingRef = useRef(false);
|
|
1635
|
+
const [newVersionContent, setNewVersionContent] = useState("");
|
|
1636
|
+
const [isCreatingVersion, setIsCreatingVersion] = useState(false);
|
|
1637
|
+
const [deletingVersion, setDeletingVersion] = useState(null);
|
|
1638
|
+
const [isComparing, setIsComparing] = useState(false);
|
|
1639
|
+
const [compareLeft, setCompareLeft] = useState(null);
|
|
1640
|
+
const [compareRight, setCompareRight] = useState(null);
|
|
1641
|
+
const newVersionId = useId();
|
|
1642
|
+
const api = useAppApi();
|
|
1643
|
+
const toast = useToast();
|
|
1644
|
+
function openCompare() {
|
|
1645
|
+
const sorted = [...versions].sort((a, b) => a.version - b.version);
|
|
1646
|
+
setCompareLeft(sorted[0]?.version ?? null);
|
|
1647
|
+
setCompareRight(sorted[sorted.length - 1]?.version ?? null);
|
|
1648
|
+
setIsComparing(true);
|
|
1649
|
+
}
|
|
1650
|
+
async function suggest() {
|
|
1651
|
+
if (isSuggestingRef.current) return;
|
|
1652
|
+
isSuggestingRef.current = true;
|
|
1653
|
+
setIsSuggesting(true);
|
|
1654
|
+
setSuggestMessage(null);
|
|
1655
|
+
const payload = { agentId: agent.id };
|
|
1656
|
+
try {
|
|
1657
|
+
await api.invoke("suggest-prompt", payload, {
|
|
1658
|
+
idempotencyKey: idempotencyKeyFor("suggest-prompt", payload)
|
|
1659
|
+
});
|
|
1660
|
+
await refresh();
|
|
1661
|
+
setSuggestMessage("Suggestion cr\xE9\xE9e \u2014 une nouvelle version a \xE9t\xE9 ajout\xE9e.");
|
|
1662
|
+
} catch (err) {
|
|
1663
|
+
setSuggestMessage(describeInvokeError(err));
|
|
1664
|
+
} finally {
|
|
1665
|
+
isSuggestingRef.current = false;
|
|
1666
|
+
setIsSuggesting(false);
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
async function runPromote(version) {
|
|
1670
|
+
try {
|
|
1671
|
+
await promote(version);
|
|
1672
|
+
toast({ title: `Version ${version} promue en production.`, variant: "success" });
|
|
1673
|
+
} catch (err) {
|
|
1674
|
+
toast({ title: "\xC9chec de la promotion", description: describeApiError(err), variant: "error" });
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
async function runCreateVersion() {
|
|
1678
|
+
setIsCreatingVersion(true);
|
|
1679
|
+
try {
|
|
1680
|
+
await createVersion(newVersionContent);
|
|
1681
|
+
setNewVersionContent("");
|
|
1682
|
+
toast({ title: "Nouvelle version cr\xE9\xE9e.", variant: "success" });
|
|
1683
|
+
} catch (err) {
|
|
1684
|
+
toast({ title: "\xC9chec de la cr\xE9ation", description: describeApiError(err), variant: "error" });
|
|
1685
|
+
} finally {
|
|
1686
|
+
setIsCreatingVersion(false);
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
async function confirmDeleteVersion() {
|
|
1690
|
+
if (deletingVersion === null) return;
|
|
1691
|
+
const version = deletingVersion;
|
|
1692
|
+
try {
|
|
1693
|
+
await deleteVersion(version);
|
|
1694
|
+
toast({ title: `Version ${version} supprim\xE9e.`, variant: "success" });
|
|
1695
|
+
} catch (err) {
|
|
1696
|
+
toast({ title: "\xC9chec de la suppression", description: describeApiError(err), variant: "error" });
|
|
1697
|
+
} finally {
|
|
1698
|
+
setDeletingVersion(null);
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
return /* @__PURE__ */ jsxs(
|
|
1702
|
+
SidePanel,
|
|
1703
|
+
{
|
|
1704
|
+
open: true,
|
|
1705
|
+
onClose,
|
|
1706
|
+
title: `Versions du prompt \u2014 ${agent.name}`,
|
|
1707
|
+
description: agent.promptName,
|
|
1708
|
+
children: [
|
|
1709
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto", children: [
|
|
1710
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1711
|
+
/* @__PURE__ */ jsx(
|
|
1712
|
+
Link,
|
|
1713
|
+
{
|
|
1714
|
+
href: `/qualite?promptName=${encodeURIComponent(agent.promptName)}${agent.promptVersion !== null ? `&promptVersion=${agent.promptVersion}` : ""}&agentId=${encodeURIComponent(agent.id)}`,
|
|
1715
|
+
children: "Voir dans Qualit\xE9"
|
|
1716
|
+
}
|
|
1717
|
+
),
|
|
1718
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
1719
|
+
versions.length >= 2 && /* @__PURE__ */ jsx(Button, { variant: "outline", onClick: openCompare, children: "Comparer" }),
|
|
1720
|
+
canWrite && /* @__PURE__ */ jsx(Button, { variant: "outline", onClick: () => void suggest(), disabled: isSuggesting, children: isSuggesting ? "Suggestion en cours\u2026" : "Sugg\xE9rer une am\xE9lioration" })
|
|
1721
|
+
] })
|
|
1722
|
+
] }),
|
|
1723
|
+
suggestMessage && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: suggestMessage }),
|
|
1724
|
+
error !== void 0 && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: "Erreur lors du chargement des versions." }),
|
|
1725
|
+
isComparing && compareLeft !== null && compareRight !== null && /* @__PURE__ */ jsx(
|
|
1726
|
+
VersionCompareView,
|
|
1727
|
+
{
|
|
1728
|
+
versions,
|
|
1729
|
+
leftVersion: compareLeft,
|
|
1730
|
+
rightVersion: compareRight,
|
|
1731
|
+
onSelectLeft: setCompareLeft,
|
|
1732
|
+
onSelectRight: setCompareRight
|
|
1733
|
+
}
|
|
1734
|
+
),
|
|
1735
|
+
/* @__PURE__ */ jsx("div", { className: "space-y-3", children: versions.map((v) => /* @__PURE__ */ jsxs("div", { className: "rounded-md border p-3", children: [
|
|
1736
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1737
|
+
/* @__PURE__ */ jsxs("div", { className: "text-sm font-medium", children: [
|
|
1738
|
+
"v",
|
|
1739
|
+
v.version,
|
|
1740
|
+
" ",
|
|
1741
|
+
v.label && /* @__PURE__ */ jsx(Badge, { variant: "brand", children: v.label })
|
|
1742
|
+
] }),
|
|
1743
|
+
canWrite && /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
1744
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => void runPromote(v.version), children: "Promouvoir" }),
|
|
1745
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => setDeletingVersion(v.version), children: "Supprimer la version" })
|
|
1746
|
+
] })
|
|
1747
|
+
] }),
|
|
1748
|
+
/* @__PURE__ */ jsx("pre", { className: "mt-2 whitespace-pre-wrap text-xs text-muted-foreground", children: v.content })
|
|
1749
|
+
] }, v.version)) }),
|
|
1750
|
+
canWrite && /* @__PURE__ */ jsxs("div", { className: "space-y-2 border-t pt-3", children: [
|
|
1751
|
+
/* @__PURE__ */ jsx("label", { htmlFor: newVersionId, className: "block text-sm font-medium", children: "Nouvelle version" }),
|
|
1752
|
+
/* @__PURE__ */ jsx(
|
|
1753
|
+
Textarea,
|
|
1754
|
+
{
|
|
1755
|
+
id: newVersionId,
|
|
1756
|
+
value: newVersionContent,
|
|
1757
|
+
onChange: (e) => setNewVersionContent(e.target.value)
|
|
1758
|
+
}
|
|
1759
|
+
),
|
|
1760
|
+
/* @__PURE__ */ jsx(
|
|
1761
|
+
Button,
|
|
1762
|
+
{
|
|
1763
|
+
onClick: () => void runCreateVersion(),
|
|
1764
|
+
disabled: newVersionContent.trim() === "" || isCreatingVersion,
|
|
1765
|
+
children: isCreatingVersion ? "Cr\xE9ation\u2026" : "Cr\xE9er la version"
|
|
1766
|
+
}
|
|
1767
|
+
)
|
|
1768
|
+
] })
|
|
1769
|
+
] }),
|
|
1770
|
+
deletingVersion !== null && /* @__PURE__ */ jsx(
|
|
1771
|
+
ConfirmModal,
|
|
1772
|
+
{
|
|
1773
|
+
title: "Supprimer la version ?",
|
|
1774
|
+
description: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1775
|
+
"La version ",
|
|
1776
|
+
deletingVersion,
|
|
1777
|
+
" de ",
|
|
1778
|
+
/* @__PURE__ */ jsx("code", { children: agent.promptName }),
|
|
1779
|
+
" sera supprim\xE9e d\xE9finitivement. Impossible si elle porte le label \xAB production \xBB ou s'il s'agit de la derni\xE8re version restante."
|
|
1780
|
+
] }),
|
|
1781
|
+
confirmLabel: "Supprimer la version",
|
|
1782
|
+
onConfirm: confirmDeleteVersion,
|
|
1783
|
+
onCancel: () => setDeletingVersion(null)
|
|
1784
|
+
}
|
|
1785
|
+
)
|
|
1786
|
+
]
|
|
1787
|
+
}
|
|
1788
|
+
);
|
|
1789
|
+
}
|
|
1790
|
+
function AgentsPage() {
|
|
1791
|
+
const { appSlug, role } = useAppContext();
|
|
1792
|
+
const canWrite = canWriteForRole(role);
|
|
1793
|
+
const api = useAppApi();
|
|
1794
|
+
const toast = useToast();
|
|
1795
|
+
const {
|
|
1796
|
+
rows: agents,
|
|
1797
|
+
isLoading,
|
|
1798
|
+
error,
|
|
1799
|
+
refresh
|
|
1800
|
+
} = useRecordList("agent", { limit: 500 }, toAgent);
|
|
1801
|
+
const [formAgent, setFormAgent] = useState(null);
|
|
1802
|
+
const [versionsAgent, setVersionsAgent] = useState(null);
|
|
1803
|
+
const [deletingAgent, setDeletingAgent] = useState(null);
|
|
1804
|
+
const recordPath = (id) => `/data/apps/${appSlug}/records/agent/${id}`;
|
|
1805
|
+
async function patchStatus(agent, status) {
|
|
1806
|
+
try {
|
|
1807
|
+
await api.patch(recordPath(agent.id), { data: { status } });
|
|
1808
|
+
await refresh();
|
|
1809
|
+
} catch (err) {
|
|
1810
|
+
toast({ title: "\xC9chec de la mise \xE0 jour", description: describeApiError(err), variant: "error" });
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
async function setDefault(agent) {
|
|
1814
|
+
try {
|
|
1815
|
+
await api.invoke("set-default-agent", { agentId: agent.id }, { idempotencyKey: crypto.randomUUID() });
|
|
1816
|
+
await refresh();
|
|
1817
|
+
} catch (err) {
|
|
1818
|
+
toast({ title: "\xC9chec de la promotion par d\xE9faut", description: describeInvokeError(err), variant: "error" });
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
async function confirmDelete() {
|
|
1822
|
+
if (!deletingAgent) return;
|
|
1823
|
+
const agent = deletingAgent;
|
|
1824
|
+
try {
|
|
1825
|
+
await api.delete(recordPath(agent.id));
|
|
1826
|
+
await refresh();
|
|
1827
|
+
toast({ title: `Agent \xAB ${agent.name} \xBB supprim\xE9.`, variant: "success" });
|
|
1828
|
+
} catch (err) {
|
|
1829
|
+
toast({ title: "\xC9chec de la suppression", description: describeApiError(err), variant: "error" });
|
|
1830
|
+
} finally {
|
|
1831
|
+
setDeletingAgent(null);
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
async function save(form) {
|
|
1835
|
+
try {
|
|
1836
|
+
if (formAgent === "new") {
|
|
1837
|
+
await api.invoke(
|
|
1838
|
+
"create-agent",
|
|
1839
|
+
{ name: form.name, modelId: form.modelId, provider: form.provider, systemPromptSnapshot: form.systemPromptSnapshot },
|
|
1840
|
+
{ idempotencyKey: crypto.randomUUID() }
|
|
1841
|
+
);
|
|
1842
|
+
} else if (formAgent) {
|
|
1843
|
+
await api.patch(recordPath(formAgent.id), {
|
|
1844
|
+
data: { name: form.name, modelId: form.modelId, systemPromptSnapshot: form.systemPromptSnapshot }
|
|
1845
|
+
});
|
|
1846
|
+
}
|
|
1847
|
+
setFormAgent(null);
|
|
1848
|
+
await refresh();
|
|
1849
|
+
} catch (err) {
|
|
1850
|
+
toast({
|
|
1851
|
+
title: formAgent === "new" ? "\xC9chec de la cr\xE9ation de l'agent" : "\xC9chec de l'enregistrement",
|
|
1852
|
+
description: formAgent === "new" ? describeInvokeError(err) : describeApiError(err),
|
|
1853
|
+
variant: "error"
|
|
1854
|
+
});
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
const columns = [
|
|
1858
|
+
{ key: "name", header: "Nom", cell: (row) => row.name },
|
|
1859
|
+
{ key: "model", header: "Mod\xE8le", cell: (row) => `${row.provider} / ${row.modelId}` },
|
|
1860
|
+
{
|
|
1861
|
+
key: "status",
|
|
1862
|
+
header: "Statut",
|
|
1863
|
+
cell: (row) => /* @__PURE__ */ jsx(Badge, { variant: STATUS_VARIANT[row.status] ?? "neutral", children: STATUS_LABELS[row.status] ?? row.status })
|
|
1864
|
+
},
|
|
1865
|
+
{ key: "promptName", header: "Prompt", cell: (row) => row.promptName },
|
|
1866
|
+
{
|
|
1867
|
+
key: "actions",
|
|
1868
|
+
header: "",
|
|
1869
|
+
cell: (row) => /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
1870
|
+
canWrite && row.status !== "default" && /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => void setDefault(row), children: "D\xE9finir par d\xE9faut" }),
|
|
1871
|
+
canWrite && row.status !== "archived" && /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => void patchStatus(row, "archived"), children: "Archiver" }),
|
|
1872
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => setVersionsAgent(row), children: "Versions" }),
|
|
1873
|
+
canWrite && /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => setFormAgent(row), children: "Modifier" }),
|
|
1874
|
+
canWrite && /* @__PURE__ */ jsx(
|
|
1875
|
+
Button,
|
|
1876
|
+
{
|
|
1877
|
+
variant: "outline",
|
|
1878
|
+
size: "sm",
|
|
1879
|
+
"aria-label": `Supprimer \u2014 ${row.name}`,
|
|
1880
|
+
onClick: () => setDeletingAgent(row),
|
|
1881
|
+
children: "Supprimer"
|
|
1882
|
+
}
|
|
1883
|
+
)
|
|
1884
|
+
] })
|
|
1885
|
+
}
|
|
1886
|
+
];
|
|
1887
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
1888
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1889
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1890
|
+
/* @__PURE__ */ jsx("h1", { className: "text-lg font-semibold", children: "Agents" }),
|
|
1891
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Agents de r\xE9daction et leurs prompts." })
|
|
1892
|
+
] }),
|
|
1893
|
+
canWrite && /* @__PURE__ */ jsx(Button, { onClick: () => setFormAgent("new"), children: "Nouvel agent" })
|
|
1894
|
+
] }),
|
|
1895
|
+
/* @__PURE__ */ jsx(
|
|
1896
|
+
DataTable,
|
|
1897
|
+
{
|
|
1898
|
+
columns,
|
|
1899
|
+
rows: agents,
|
|
1900
|
+
rowId: (row) => row.id,
|
|
1901
|
+
manual: true,
|
|
1902
|
+
loading: isLoading,
|
|
1903
|
+
error: error ? /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-3", children: [
|
|
1904
|
+
"Erreur lors du chargement des agents.",
|
|
1905
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => void refresh(), children: "R\xE9essayer" })
|
|
1906
|
+
] }) : void 0,
|
|
1907
|
+
empty: "Aucun agent configur\xE9."
|
|
1908
|
+
}
|
|
1909
|
+
),
|
|
1910
|
+
formAgent && /* @__PURE__ */ jsx(AgentFormModal, { agent: formAgent, onClose: () => setFormAgent(null), onSave: save }),
|
|
1911
|
+
versionsAgent && /* @__PURE__ */ jsx(PromptVersionsPanel, { agent: versionsAgent, canWrite, onClose: () => setVersionsAgent(null) }),
|
|
1912
|
+
deletingAgent && /* @__PURE__ */ jsx(
|
|
1913
|
+
ConfirmModal,
|
|
1914
|
+
{
|
|
1915
|
+
title: "Supprimer l'agent ?",
|
|
1916
|
+
description: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1917
|
+
"L'agent \xAB ",
|
|
1918
|
+
deletingAgent.name,
|
|
1919
|
+
" \xBB sera supprim\xE9, avec tout son historique d'\xE9valuations et de comparaisons. Toute cat\xE9gorie qui lui est li\xE9e retombera sur l'agent par d\xE9faut et se remettra \xE0 r\xE9diger avec un prompt diff\xE9rent."
|
|
1920
|
+
] }),
|
|
1921
|
+
confirmLabel: "Supprimer l'agent",
|
|
1922
|
+
onConfirm: confirmDelete,
|
|
1923
|
+
onCancel: () => setDeletingAgent(null)
|
|
1924
|
+
}
|
|
1925
|
+
)
|
|
1926
|
+
] });
|
|
1927
|
+
}
|
|
1928
|
+
var UNGROUPED_KEY = "";
|
|
1929
|
+
function GroupFormModal({ onClose, onSave }) {
|
|
1930
|
+
const [name, setName] = useState("");
|
|
1931
|
+
const [isSaving, setIsSaving] = useState(false);
|
|
1932
|
+
const nameId = useId();
|
|
1933
|
+
async function submit(event) {
|
|
1934
|
+
event.preventDefault();
|
|
1935
|
+
if (isSaving || name.trim() === "") return;
|
|
1936
|
+
setIsSaving(true);
|
|
1937
|
+
try {
|
|
1938
|
+
await onSave(name);
|
|
1939
|
+
} finally {
|
|
1940
|
+
setIsSaving(false);
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
return /* @__PURE__ */ jsx(Modal, { open: true, onClose, title: "Nouveau groupe", children: /* @__PURE__ */ jsxs("form", { className: "space-y-3", onSubmit: (e) => void submit(e), children: [
|
|
1944
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1945
|
+
/* @__PURE__ */ jsx("label", { htmlFor: nameId, className: "mb-1 block text-sm font-medium", children: "Nom du groupe" }),
|
|
1946
|
+
/* @__PURE__ */ jsx(Input, { id: nameId, value: name, onChange: (e) => setName(e.target.value) })
|
|
1947
|
+
] }),
|
|
1948
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
1949
|
+
/* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: onClose, children: "Annuler" }),
|
|
1950
|
+
/* @__PURE__ */ jsx(Button, { type: "submit", disabled: isSaving || name.trim() === "", children: isSaving ? "Cr\xE9ation\u2026" : "Cr\xE9er" })
|
|
1951
|
+
] })
|
|
1952
|
+
] }) });
|
|
1953
|
+
}
|
|
1954
|
+
function CategoryFormModal({
|
|
1955
|
+
groupId,
|
|
1956
|
+
category,
|
|
1957
|
+
agents,
|
|
1958
|
+
onClose,
|
|
1959
|
+
onSave
|
|
1960
|
+
}) {
|
|
1961
|
+
const [isSaving, setIsSaving] = useState(false);
|
|
1962
|
+
const [form, setForm] = useState({
|
|
1963
|
+
name: category?.name ?? "",
|
|
1964
|
+
tagName: category?.tagName ?? "",
|
|
1965
|
+
groupId,
|
|
1966
|
+
agentId: category?.agentId ?? "",
|
|
1967
|
+
extraTags: category?.extraTags.join(", ") ?? "",
|
|
1968
|
+
examples: category?.examples ?? ""
|
|
1969
|
+
});
|
|
1970
|
+
const nameId = useId();
|
|
1971
|
+
const tagId = useId();
|
|
1972
|
+
const agentSelectId = useId();
|
|
1973
|
+
const extraTagsId = useId();
|
|
1974
|
+
const examplesId = useId();
|
|
1975
|
+
const isValid = form.name.trim() !== "" && form.tagName.trim() !== "";
|
|
1976
|
+
async function submit(event) {
|
|
1977
|
+
event.preventDefault();
|
|
1978
|
+
if (isSaving || !isValid) return;
|
|
1979
|
+
setIsSaving(true);
|
|
1980
|
+
try {
|
|
1981
|
+
await onSave(form);
|
|
1982
|
+
} finally {
|
|
1983
|
+
setIsSaving(false);
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
const agentItems = [
|
|
1987
|
+
{ value: "", label: "Aucun agent" },
|
|
1988
|
+
...agents.map((a) => ({ value: a.id, label: a.name }))
|
|
1989
|
+
];
|
|
1990
|
+
return /* @__PURE__ */ jsx(Modal, { open: true, onClose, title: category ? `Modifier ${category.name}` : "Nouvelle cat\xE9gorie", children: /* @__PURE__ */ jsxs("form", { className: "space-y-3", onSubmit: (e) => void submit(e), children: [
|
|
1991
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1992
|
+
/* @__PURE__ */ jsx("label", { htmlFor: nameId, className: "mb-1 block text-sm font-medium", children: "Nom" }),
|
|
1993
|
+
/* @__PURE__ */ jsx(Input, { id: nameId, value: form.name, onChange: (e) => setForm({ ...form, name: e.target.value }) })
|
|
1994
|
+
] }),
|
|
1995
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
1996
|
+
/* @__PURE__ */ jsx("label", { htmlFor: tagId, className: "mb-1 block text-sm font-medium", children: "Tag Gorgias (exact, sensible \xE0 la casse)" }),
|
|
1997
|
+
/* @__PURE__ */ jsx(Input, { id: tagId, value: form.tagName, onChange: (e) => setForm({ ...form, tagName: e.target.value }) })
|
|
1998
|
+
] }),
|
|
1999
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2000
|
+
/* @__PURE__ */ jsx("label", { htmlFor: agentSelectId, className: "mb-1 block text-sm font-medium", children: "Agent IA" }),
|
|
2001
|
+
/* @__PURE__ */ jsx(
|
|
2002
|
+
Select,
|
|
2003
|
+
{
|
|
2004
|
+
"aria-label": "Agent IA",
|
|
2005
|
+
value: form.agentId,
|
|
2006
|
+
onValueChange: (v) => setForm({ ...form, agentId: v }),
|
|
2007
|
+
items: agentItems
|
|
2008
|
+
}
|
|
2009
|
+
),
|
|
2010
|
+
/* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: "Requis pour activer \xAB R\xE9ponse rapide \xBB et \xAB Envoi auto \xBB sur cette cat\xE9gorie." })
|
|
2011
|
+
] }),
|
|
2012
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2013
|
+
/* @__PURE__ */ jsx("label", { htmlFor: extraTagsId, className: "mb-1 block text-sm font-medium", children: "Tags additionnels (s\xE9par\xE9s par des virgules)" }),
|
|
2014
|
+
/* @__PURE__ */ jsx(
|
|
2015
|
+
Input,
|
|
2016
|
+
{
|
|
2017
|
+
id: extraTagsId,
|
|
2018
|
+
value: form.extraTags,
|
|
2019
|
+
onChange: (e) => setForm({ ...form, extraTags: e.target.value })
|
|
2020
|
+
}
|
|
2021
|
+
)
|
|
2022
|
+
] }),
|
|
2023
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2024
|
+
/* @__PURE__ */ jsx("label", { htmlFor: examplesId, className: "mb-1 block text-sm font-medium", children: "Exemples" }),
|
|
2025
|
+
/* @__PURE__ */ jsx(
|
|
2026
|
+
Textarea,
|
|
2027
|
+
{
|
|
2028
|
+
id: examplesId,
|
|
2029
|
+
value: form.examples,
|
|
2030
|
+
onChange: (e) => setForm({ ...form, examples: e.target.value })
|
|
2031
|
+
}
|
|
2032
|
+
)
|
|
2033
|
+
] }),
|
|
2034
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2 pt-2", children: [
|
|
2035
|
+
/* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: onClose, children: "Annuler" }),
|
|
2036
|
+
/* @__PURE__ */ jsx(Button, { type: "submit", disabled: isSaving || !isValid, children: isSaving ? "Enregistrement\u2026" : "Enregistrer" })
|
|
2037
|
+
] })
|
|
2038
|
+
] }) });
|
|
2039
|
+
}
|
|
2040
|
+
function CategoriesPage() {
|
|
2041
|
+
const { appSlug, role } = useAppContext();
|
|
2042
|
+
const canWrite = canWriteForRole(role);
|
|
2043
|
+
const api = useAppApi();
|
|
2044
|
+
const toast = useToast();
|
|
2045
|
+
const {
|
|
2046
|
+
rows: groups,
|
|
2047
|
+
isLoading: groupsLoading,
|
|
2048
|
+
error: groupsError,
|
|
2049
|
+
refresh: refreshGroups
|
|
2050
|
+
} = useRecordList("category-group", { limit: 200 }, toCategoryGroup);
|
|
2051
|
+
const {
|
|
2052
|
+
rows: categories,
|
|
2053
|
+
isLoading: categoriesLoading,
|
|
2054
|
+
error: categoriesError,
|
|
2055
|
+
refresh: refreshCategories
|
|
2056
|
+
} = useRecordList("category", { limit: 500 }, toCategory);
|
|
2057
|
+
const { rows: agents } = useRecordList("agent", { limit: 500 }, toAgent);
|
|
2058
|
+
const [newGroup, setNewGroup] = useState(false);
|
|
2059
|
+
const [categoryForm, setCategoryForm] = useState(null);
|
|
2060
|
+
const [deletingGroup, setDeletingGroup] = useState(null);
|
|
2061
|
+
const [deletingCategory, setDeletingCategory] = useState(null);
|
|
2062
|
+
const byGroup = useMemo(() => {
|
|
2063
|
+
const map = /* @__PURE__ */ new Map();
|
|
2064
|
+
for (const category of categories) {
|
|
2065
|
+
const key = category.groupId ?? UNGROUPED_KEY;
|
|
2066
|
+
const list2 = map.get(key) ?? [];
|
|
2067
|
+
list2.push(category);
|
|
2068
|
+
map.set(key, list2);
|
|
2069
|
+
}
|
|
2070
|
+
for (const list2 of map.values()) list2.sort((a, b) => a.order - b.order);
|
|
2071
|
+
return map;
|
|
2072
|
+
}, [categories]);
|
|
2073
|
+
const categoryPath = (id) => `/data/apps/${appSlug}/records/category/${id}`;
|
|
2074
|
+
const groupPath = (id) => `/data/apps/${appSlug}/records/category-group/${id}`;
|
|
2075
|
+
async function createGroup(name) {
|
|
2076
|
+
try {
|
|
2077
|
+
await api.post(`/data/apps/${appSlug}/records/category-group`, { data: { name, order: groups.length } });
|
|
2078
|
+
setNewGroup(false);
|
|
2079
|
+
await refreshGroups();
|
|
2080
|
+
} catch (err) {
|
|
2081
|
+
toast({ title: "\xC9chec de la cr\xE9ation du groupe", description: describeApiError(err), variant: "error" });
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
async function confirmDeleteGroup() {
|
|
2085
|
+
if (!deletingGroup) return;
|
|
2086
|
+
const group = deletingGroup;
|
|
2087
|
+
try {
|
|
2088
|
+
await api.delete(groupPath(group.id));
|
|
2089
|
+
await Promise.all([refreshGroups(), refreshCategories()]);
|
|
2090
|
+
toast({ title: `Groupe \xAB ${group.name} \xBB supprim\xE9.`, variant: "success" });
|
|
2091
|
+
} catch (err) {
|
|
2092
|
+
toast({ title: "\xC9chec de la suppression du groupe", description: describeApiError(err), variant: "error" });
|
|
2093
|
+
} finally {
|
|
2094
|
+
setDeletingGroup(null);
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
async function saveCategory(form) {
|
|
2098
|
+
const data = {
|
|
2099
|
+
name: form.name,
|
|
2100
|
+
tagName: form.tagName,
|
|
2101
|
+
groupId: form.groupId || null,
|
|
2102
|
+
agentId: form.agentId || null,
|
|
2103
|
+
extraTags: form.extraTags.split(",").map((t) => t.trim()).filter(Boolean),
|
|
2104
|
+
examples: form.examples
|
|
2105
|
+
};
|
|
2106
|
+
try {
|
|
2107
|
+
if (categoryForm?.category) {
|
|
2108
|
+
await api.patch(categoryPath(categoryForm.category.id), { data });
|
|
2109
|
+
} else {
|
|
2110
|
+
const order = (byGroup.get(form.groupId || UNGROUPED_KEY) ?? []).length;
|
|
2111
|
+
await api.post(`/data/apps/${appSlug}/records/category`, { data: { ...data, order } });
|
|
2112
|
+
}
|
|
2113
|
+
setCategoryForm(null);
|
|
2114
|
+
await refreshCategories();
|
|
2115
|
+
} catch (err) {
|
|
2116
|
+
toast({ title: "\xC9chec de l'enregistrement de la cat\xE9gorie", description: describeApiError(err), variant: "error" });
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
async function confirmDeleteCategory() {
|
|
2120
|
+
if (!deletingCategory) return;
|
|
2121
|
+
const category = deletingCategory;
|
|
2122
|
+
try {
|
|
2123
|
+
await api.delete(categoryPath(category.id));
|
|
2124
|
+
await refreshCategories();
|
|
2125
|
+
toast({ title: `Cat\xE9gorie \xAB ${category.name} \xBB supprim\xE9e.`, variant: "success" });
|
|
2126
|
+
} catch (err) {
|
|
2127
|
+
toast({ title: "\xC9chec de la suppression", description: describeApiError(err), variant: "error" });
|
|
2128
|
+
} finally {
|
|
2129
|
+
setDeletingCategory(null);
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
async function toggleFastResponse(category) {
|
|
2133
|
+
const next = !category.fastResponseEnabled;
|
|
2134
|
+
const data = { fastResponseEnabled: next };
|
|
2135
|
+
if (!next && category.autoReplyEnabled) data.autoReplyEnabled = false;
|
|
2136
|
+
try {
|
|
2137
|
+
await api.patch(categoryPath(category.id), { data });
|
|
2138
|
+
await refreshCategories();
|
|
2139
|
+
} catch (err) {
|
|
2140
|
+
toast({ title: "\xC9chec de la mise \xE0 jour", description: describeApiError(err), variant: "error" });
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
async function toggleAutoReply(category) {
|
|
2144
|
+
try {
|
|
2145
|
+
await api.patch(categoryPath(category.id), { data: { autoReplyEnabled: !category.autoReplyEnabled } });
|
|
2146
|
+
await refreshCategories();
|
|
2147
|
+
} catch (err) {
|
|
2148
|
+
toast({ title: "\xC9chec de la mise \xE0 jour", description: describeApiError(err), variant: "error" });
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
async function move(category, direction) {
|
|
2152
|
+
const siblings = byGroup.get(category.groupId ?? UNGROUPED_KEY) ?? [];
|
|
2153
|
+
const index = siblings.findIndex((c) => c.id === category.id);
|
|
2154
|
+
const swapWith = siblings[index + direction];
|
|
2155
|
+
if (!swapWith) return;
|
|
2156
|
+
try {
|
|
2157
|
+
await api.patch(categoryPath(category.id), { data: { order: swapWith.order } });
|
|
2158
|
+
await api.patch(categoryPath(swapWith.id), { data: { order: category.order } });
|
|
2159
|
+
await refreshCategories();
|
|
2160
|
+
} catch (err) {
|
|
2161
|
+
toast({ title: "\xC9chec du r\xE9ordonnancement", description: describeApiError(err), variant: "error" });
|
|
2162
|
+
await refreshCategories();
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
function renderCategoryList(groupCategories) {
|
|
2166
|
+
return /* @__PURE__ */ jsx("div", { className: "space-y-2", children: groupCategories.map((category, index) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 rounded-md border p-2", children: [
|
|
2167
|
+
canWrite && /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
2168
|
+
/* @__PURE__ */ jsx(
|
|
2169
|
+
Button,
|
|
2170
|
+
{
|
|
2171
|
+
type: "button",
|
|
2172
|
+
variant: "ghost",
|
|
2173
|
+
"aria-label": `Monter \u2014 ${category.name}`,
|
|
2174
|
+
disabled: index === 0,
|
|
2175
|
+
onClick: () => void move(category, -1),
|
|
2176
|
+
className: "h-4 min-w-0 p-0 text-xs leading-none",
|
|
2177
|
+
children: "\u25B2"
|
|
2178
|
+
}
|
|
2179
|
+
),
|
|
2180
|
+
/* @__PURE__ */ jsx(
|
|
2181
|
+
Button,
|
|
2182
|
+
{
|
|
2183
|
+
type: "button",
|
|
2184
|
+
variant: "ghost",
|
|
2185
|
+
"aria-label": `Descendre \u2014 ${category.name}`,
|
|
2186
|
+
disabled: index === groupCategories.length - 1,
|
|
2187
|
+
onClick: () => void move(category, 1),
|
|
2188
|
+
className: "h-4 min-w-0 p-0 text-xs leading-none",
|
|
2189
|
+
children: "\u25BC"
|
|
2190
|
+
}
|
|
2191
|
+
)
|
|
2192
|
+
] }),
|
|
2193
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1", children: [
|
|
2194
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: category.name }),
|
|
2195
|
+
/* @__PURE__ */ jsx("code", { className: "text-xs text-muted-foreground", children: category.tagName })
|
|
2196
|
+
] }),
|
|
2197
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2198
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: "R\xE9ponse rapide" }),
|
|
2199
|
+
/* @__PURE__ */ jsx(
|
|
2200
|
+
Switch,
|
|
2201
|
+
{
|
|
2202
|
+
"aria-label": `R\xE9ponse rapide \u2014 ${category.name}`,
|
|
2203
|
+
checked: category.fastResponseEnabled,
|
|
2204
|
+
onCheckedChange: () => void toggleFastResponse(category),
|
|
2205
|
+
disabled: !canWrite || !category.agentId
|
|
2206
|
+
}
|
|
2207
|
+
)
|
|
2208
|
+
] }),
|
|
2209
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2210
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: "Envoi auto" }),
|
|
2211
|
+
/* @__PURE__ */ jsx(
|
|
2212
|
+
Switch,
|
|
2213
|
+
{
|
|
2214
|
+
"aria-label": `Envoi auto \u2014 ${category.name}`,
|
|
2215
|
+
checked: category.autoReplyEnabled,
|
|
2216
|
+
onCheckedChange: () => void toggleAutoReply(category),
|
|
2217
|
+
disabled: !canWrite || !category.fastResponseEnabled || !category.agentId
|
|
2218
|
+
}
|
|
2219
|
+
)
|
|
2220
|
+
] }),
|
|
2221
|
+
category.extraTags.length > 0 && /* @__PURE__ */ jsx("div", { className: "flex gap-1", children: category.extraTags.map((tag) => /* @__PURE__ */ jsx(Badge, { variant: "outline", children: tag }, tag)) }),
|
|
2222
|
+
canWrite && /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
2223
|
+
/* @__PURE__ */ jsx(
|
|
2224
|
+
Button,
|
|
2225
|
+
{
|
|
2226
|
+
variant: "outline",
|
|
2227
|
+
size: "sm",
|
|
2228
|
+
onClick: () => setCategoryForm({ groupId: category.groupId ?? UNGROUPED_KEY, category }),
|
|
2229
|
+
children: "Modifier"
|
|
2230
|
+
}
|
|
2231
|
+
),
|
|
2232
|
+
/* @__PURE__ */ jsx(
|
|
2233
|
+
Button,
|
|
2234
|
+
{
|
|
2235
|
+
variant: "outline",
|
|
2236
|
+
size: "sm",
|
|
2237
|
+
"aria-label": `Supprimer \u2014 ${category.name}`,
|
|
2238
|
+
onClick: () => setDeletingCategory(category),
|
|
2239
|
+
children: "Supprimer"
|
|
2240
|
+
}
|
|
2241
|
+
)
|
|
2242
|
+
] })
|
|
2243
|
+
] }, category.id)) });
|
|
2244
|
+
}
|
|
2245
|
+
const isLoading = groupsLoading || categoriesLoading;
|
|
2246
|
+
const loadError = groupsError ?? categoriesError;
|
|
2247
|
+
const ungrouped = byGroup.get(UNGROUPED_KEY) ?? [];
|
|
2248
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
2249
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2250
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2251
|
+
/* @__PURE__ */ jsx("h1", { className: "text-lg font-semibold", children: "Cat\xE9gories" }),
|
|
2252
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "R\xE9f\xE9rentiel de cat\xE9gorisation des tickets." })
|
|
2253
|
+
] }),
|
|
2254
|
+
canWrite && /* @__PURE__ */ jsx(Button, { onClick: () => setNewGroup(true), children: "Nouveau groupe" })
|
|
2255
|
+
] }),
|
|
2256
|
+
loadError ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-3 py-12", children: [
|
|
2257
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: "Erreur lors du chargement des cat\xE9gories." }),
|
|
2258
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", onClick: () => void Promise.all([refreshGroups(), refreshCategories()]), children: "R\xE9essayer" })
|
|
2259
|
+
] }) : isLoading ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center py-12", children: [
|
|
2260
|
+
/* @__PURE__ */ jsx(Spinner, {}),
|
|
2261
|
+
" ",
|
|
2262
|
+
/* @__PURE__ */ jsx("span", { className: "ml-2 text-sm text-muted-foreground", children: "Chargement\u2026" })
|
|
2263
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2264
|
+
groups.slice().sort((a, b) => a.order - b.order).map((group) => {
|
|
2265
|
+
const groupCategories = byGroup.get(group.id) ?? [];
|
|
2266
|
+
return /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-2 p-4", children: [
|
|
2267
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2268
|
+
/* @__PURE__ */ jsx("h2", { className: "font-medium", children: group.name }),
|
|
2269
|
+
canWrite && /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
2270
|
+
/* @__PURE__ */ jsx(
|
|
2271
|
+
Button,
|
|
2272
|
+
{
|
|
2273
|
+
variant: "outline",
|
|
2274
|
+
size: "sm",
|
|
2275
|
+
onClick: () => setCategoryForm({ groupId: group.id, category: null }),
|
|
2276
|
+
children: "Ajouter une cat\xE9gorie"
|
|
2277
|
+
}
|
|
2278
|
+
),
|
|
2279
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => setDeletingGroup(group), children: "Supprimer le groupe" })
|
|
2280
|
+
] })
|
|
2281
|
+
] }),
|
|
2282
|
+
renderCategoryList(groupCategories)
|
|
2283
|
+
] }) }, group.id);
|
|
2284
|
+
}),
|
|
2285
|
+
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-2 p-4", children: [
|
|
2286
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2287
|
+
/* @__PURE__ */ jsx("h2", { className: "font-medium", children: "Sans groupe" }),
|
|
2288
|
+
canWrite && /* @__PURE__ */ jsx(
|
|
2289
|
+
Button,
|
|
2290
|
+
{
|
|
2291
|
+
variant: "outline",
|
|
2292
|
+
size: "sm",
|
|
2293
|
+
onClick: () => setCategoryForm({ groupId: UNGROUPED_KEY, category: null }),
|
|
2294
|
+
children: "Ajouter une cat\xE9gorie"
|
|
2295
|
+
}
|
|
2296
|
+
)
|
|
2297
|
+
] }),
|
|
2298
|
+
ungrouped.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Aucune cat\xE9gorie sans groupe." }) : renderCategoryList(ungrouped)
|
|
2299
|
+
] }) })
|
|
2300
|
+
] }),
|
|
2301
|
+
newGroup && /* @__PURE__ */ jsx(GroupFormModal, { onClose: () => setNewGroup(false), onSave: createGroup }),
|
|
2302
|
+
categoryForm && /* @__PURE__ */ jsx(
|
|
2303
|
+
CategoryFormModal,
|
|
2304
|
+
{
|
|
2305
|
+
groupId: categoryForm.groupId,
|
|
2306
|
+
category: categoryForm.category,
|
|
2307
|
+
agents,
|
|
2308
|
+
onClose: () => setCategoryForm(null),
|
|
2309
|
+
onSave: saveCategory
|
|
2310
|
+
}
|
|
2311
|
+
),
|
|
2312
|
+
deletingGroup && /* @__PURE__ */ jsx(
|
|
2313
|
+
ConfirmModal,
|
|
2314
|
+
{
|
|
2315
|
+
title: "Supprimer le groupe ?",
|
|
2316
|
+
description: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2317
|
+
"Le groupe \xAB ",
|
|
2318
|
+
deletingGroup.name,
|
|
2319
|
+
" \xBB sera supprim\xE9. Ses cat\xE9gories ne seront PAS supprim\xE9es \u2014 elles passeront dans \xAB Sans groupe \xBB."
|
|
2320
|
+
] }),
|
|
2321
|
+
confirmLabel: "Supprimer le groupe",
|
|
2322
|
+
onConfirm: confirmDeleteGroup,
|
|
2323
|
+
onCancel: () => setDeletingGroup(null)
|
|
2324
|
+
}
|
|
2325
|
+
),
|
|
2326
|
+
deletingCategory && /* @__PURE__ */ jsx(
|
|
2327
|
+
ConfirmModal,
|
|
2328
|
+
{
|
|
2329
|
+
title: "Supprimer la cat\xE9gorie ?",
|
|
2330
|
+
description: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2331
|
+
"La cat\xE9gorie \xAB ",
|
|
2332
|
+
deletingCategory.name,
|
|
2333
|
+
" \xBB sera supprim\xE9e. Les tickets d\xE9j\xE0 tagu\xE9s",
|
|
2334
|
+
" ",
|
|
2335
|
+
/* @__PURE__ */ jsx("code", { children: deletingCategory.tagName }),
|
|
2336
|
+
" ne seront plus reconnus par le triage."
|
|
2337
|
+
] }),
|
|
2338
|
+
confirmLabel: "Supprimer la cat\xE9gorie",
|
|
2339
|
+
onConfirm: confirmDeleteCategory,
|
|
2340
|
+
onCancel: () => setDeletingCategory(null)
|
|
2341
|
+
}
|
|
2342
|
+
)
|
|
2343
|
+
] });
|
|
2344
|
+
}
|
|
2345
|
+
var ESCALATIONS_PAGE_SIZE = 200;
|
|
2346
|
+
var ESCALATED_OPTIONS2 = [
|
|
2347
|
+
{ value: "", label: "Toutes d\xE9cisions" },
|
|
2348
|
+
{ value: "true", label: "Escalad\xE9s" },
|
|
2349
|
+
{ value: "false", label: "Non escalad\xE9s" }
|
|
2350
|
+
];
|
|
2351
|
+
var CONFIDENCE_OPTIONS = [
|
|
2352
|
+
{ value: "", label: "Toutes confiances" },
|
|
2353
|
+
{ value: "high", label: TRIAGE_CONFIDENCE_LABELS.high },
|
|
2354
|
+
{ value: "low", label: TRIAGE_CONFIDENCE_LABELS.low }
|
|
2355
|
+
];
|
|
2356
|
+
var STATUS_OPTIONS = [
|
|
2357
|
+
{ value: "", label: "Tous les statuts" },
|
|
2358
|
+
{ value: "ok", label: TRIAGE_DECISION_STATUS_LABELS.ok },
|
|
2359
|
+
{ value: "error", label: TRIAGE_DECISION_STATUS_LABELS.error }
|
|
2360
|
+
];
|
|
2361
|
+
function buildFilter2(escalated, confidence, status) {
|
|
2362
|
+
const filter = {};
|
|
2363
|
+
if (escalated) filter.escalated = { eq: escalated === "true" };
|
|
2364
|
+
if (confidence) filter.escalationConfidence = { eq: confidence };
|
|
2365
|
+
if (status) filter.status = { eq: status };
|
|
2366
|
+
return Object.keys(filter).length > 0 ? filter : void 0;
|
|
2367
|
+
}
|
|
2368
|
+
function ConfidenceBadge({ confidence }) {
|
|
2369
|
+
if (!confidence) return /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "\u2014" });
|
|
2370
|
+
return /* @__PURE__ */ jsx(Badge, { variant: confidence === "high" ? "success" : "warning", children: TRIAGE_CONFIDENCE_LABELS[confidence] });
|
|
2371
|
+
}
|
|
2372
|
+
function StatusBadge({ status, error }) {
|
|
2373
|
+
if (!status) return /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "\u2014" });
|
|
2374
|
+
return /* @__PURE__ */ jsx(Badge, { variant: status === "error" ? "danger" : "neutral", title: status === "error" ? error ?? void 0 : void 0, children: TRIAGE_DECISION_STATUS_LABELS[status] });
|
|
2375
|
+
}
|
|
2376
|
+
function DetailPanel3({ row, categoryName, onClose }) {
|
|
2377
|
+
return /* @__PURE__ */ jsx(SidePanel, { open: true, onClose, title: `Ticket ${row.ticketId}`, description: categoryName, children: /* @__PURE__ */ jsxs("div", { className: "space-y-4 text-sm", children: [
|
|
2378
|
+
row.reasoning && /* @__PURE__ */ jsxs("div", { children: [
|
|
2379
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Raison du triage" }),
|
|
2380
|
+
/* @__PURE__ */ jsx("p", { children: row.reasoning })
|
|
2381
|
+
] }),
|
|
2382
|
+
row.escalationReasoning && /* @__PURE__ */ jsxs("div", { children: [
|
|
2383
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Raison de l\u2019escalade" }),
|
|
2384
|
+
/* @__PURE__ */ jsx("p", { children: row.escalationReasoning })
|
|
2385
|
+
] }),
|
|
2386
|
+
row.error && /* @__PURE__ */ jsxs("div", { className: "rounded-md bg-destructive/10 p-3 text-destructive", children: [
|
|
2387
|
+
"Erreur : ",
|
|
2388
|
+
row.error
|
|
2389
|
+
] }),
|
|
2390
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
2391
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2392
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs uppercase tracking-wide text-muted-foreground", children: "Run parent" }),
|
|
2393
|
+
/* @__PURE__ */ jsx("code", { className: "text-xs", children: row.runId ?? "\u2014" })
|
|
2394
|
+
] }),
|
|
2395
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2396
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs uppercase tracking-wide text-muted-foreground", children: "D\xE9cid\xE9 le" }),
|
|
2397
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs font-semibold", children: formatDate(row.decidedAt) })
|
|
2398
|
+
] })
|
|
2399
|
+
] }),
|
|
2400
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground", children: [
|
|
2401
|
+
/* @__PURE__ */ jsx("span", { children: "Valeurs brutes" }),
|
|
2402
|
+
/* @__PURE__ */ jsxs("code", { children: [
|
|
2403
|
+
"status=",
|
|
2404
|
+
row.status ?? "\u2014"
|
|
2405
|
+
] }),
|
|
2406
|
+
/* @__PURE__ */ jsxs("code", { children: [
|
|
2407
|
+
"escalationConfidence=",
|
|
2408
|
+
row.escalationConfidence ?? "\u2014"
|
|
2409
|
+
] })
|
|
2410
|
+
] })
|
|
2411
|
+
] }) });
|
|
2412
|
+
}
|
|
2413
|
+
function EscalationsPage() {
|
|
2414
|
+
const [escalatedFilter, setEscalatedFilter] = useState("");
|
|
2415
|
+
const [confidenceFilter, setConfidenceFilter] = useState("");
|
|
2416
|
+
const [statusFilter, setStatusFilter] = useState("");
|
|
2417
|
+
const [detailRow, setDetailRow] = useState(null);
|
|
2418
|
+
const {
|
|
2419
|
+
rows: escalations,
|
|
2420
|
+
isLoading,
|
|
2421
|
+
error,
|
|
2422
|
+
refresh
|
|
2423
|
+
} = useRecordList(
|
|
2424
|
+
"triage-decision",
|
|
2425
|
+
{
|
|
2426
|
+
filter: buildFilter2(escalatedFilter, confidenceFilter, statusFilter),
|
|
2427
|
+
sort: [{ field: "decidedAt", direction: "desc" }],
|
|
2428
|
+
limit: ESCALATIONS_PAGE_SIZE
|
|
2429
|
+
},
|
|
2430
|
+
toTriageDecision
|
|
2431
|
+
);
|
|
2432
|
+
const { rows: categories } = useRecordList("category", { limit: 500 }, toCategory);
|
|
2433
|
+
const categoryNames = useMemo(() => toNameMap(categories), [categories]);
|
|
2434
|
+
const columns = [
|
|
2435
|
+
{ key: "ticketId", header: "Ticket", cell: (row) => row.ticketId },
|
|
2436
|
+
{ key: "category", header: "Cat\xE9gorie", cell: (row) => row.categoryId && categoryNames.get(row.categoryId) || "\u2014" },
|
|
2437
|
+
{ key: "tag", header: "Tag", cell: (row) => row.tag ? /* @__PURE__ */ jsx("code", { className: "text-xs", children: row.tag }) : "\u2014" },
|
|
2438
|
+
{
|
|
2439
|
+
key: "escalationConfidence",
|
|
2440
|
+
header: "Confiance",
|
|
2441
|
+
cell: (row) => /* @__PURE__ */ jsx(ConfidenceBadge, { confidence: row.escalationConfidence })
|
|
2442
|
+
},
|
|
2443
|
+
// Header is plain "Raison", not "Raison de l'escalade": the cell falls
|
|
2444
|
+
// back to `reasoning` (the TRIAGE reason) for a row the escalation step
|
|
2445
|
+
// left empty, and labelling that as the escalation's own reason is a
|
|
2446
|
+
// lie. Marking the fallback per row would need a second badge in an
|
|
2447
|
+
// already dense table — the detail panel labels the two apart
|
|
2448
|
+
// ("Raison du triage" / "Raison de l’escalade") for whoever needs it.
|
|
2449
|
+
{ key: "escalationReasoning", header: "Raison", cell: (row) => row.escalationReasoning ?? row.reasoning ?? "\u2014" },
|
|
2450
|
+
{
|
|
2451
|
+
key: "status",
|
|
2452
|
+
header: "Statut",
|
|
2453
|
+
cell: (row) => /* @__PURE__ */ jsx(StatusBadge, { status: row.status, error: row.error })
|
|
2454
|
+
},
|
|
2455
|
+
{ key: "decidedAt", header: "D\xE9cid\xE9 le", cell: (row) => formatDate(row.decidedAt) }
|
|
2456
|
+
];
|
|
2457
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
2458
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2459
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2460
|
+
/* @__PURE__ */ jsx("h1", { className: "text-lg font-semibold", children: "Escalades" }),
|
|
2461
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "D\xE9cisions d\u2019escalade humaine \xE9valu\xE9es lors des runs de triage." })
|
|
2462
|
+
] }),
|
|
2463
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", onClick: () => void refresh(), children: "Actualiser" })
|
|
2464
|
+
] }),
|
|
2465
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
|
|
2466
|
+
/* @__PURE__ */ jsx(
|
|
2467
|
+
Select,
|
|
2468
|
+
{
|
|
2469
|
+
items: ESCALATED_OPTIONS2,
|
|
2470
|
+
value: escalatedFilter,
|
|
2471
|
+
onValueChange: setEscalatedFilter,
|
|
2472
|
+
placeholder: "Toutes d\xE9cisions",
|
|
2473
|
+
"aria-label": "Filtrer par d\xE9cision"
|
|
2474
|
+
}
|
|
2475
|
+
),
|
|
2476
|
+
/* @__PURE__ */ jsx(
|
|
2477
|
+
Select,
|
|
2478
|
+
{
|
|
2479
|
+
items: CONFIDENCE_OPTIONS,
|
|
2480
|
+
value: confidenceFilter,
|
|
2481
|
+
onValueChange: setConfidenceFilter,
|
|
2482
|
+
placeholder: "Toutes confiances",
|
|
2483
|
+
"aria-label": "Filtrer par confiance"
|
|
2484
|
+
}
|
|
2485
|
+
),
|
|
2486
|
+
/* @__PURE__ */ jsx(
|
|
2487
|
+
Select,
|
|
2488
|
+
{
|
|
2489
|
+
items: STATUS_OPTIONS,
|
|
2490
|
+
value: statusFilter,
|
|
2491
|
+
onValueChange: setStatusFilter,
|
|
2492
|
+
placeholder: "Tous les statuts",
|
|
2493
|
+
"aria-label": "Filtrer par statut"
|
|
2494
|
+
}
|
|
2495
|
+
),
|
|
2496
|
+
escalations.length > 0 && /* @__PURE__ */ jsxs("span", { className: "ml-auto text-sm text-muted-foreground", children: [
|
|
2497
|
+
escalations.length,
|
|
2498
|
+
" r\xE9sultat",
|
|
2499
|
+
escalations.length > 1 ? "s" : ""
|
|
2500
|
+
] })
|
|
2501
|
+
] }),
|
|
2502
|
+
/* @__PURE__ */ jsx(
|
|
2503
|
+
DataTable,
|
|
2504
|
+
{
|
|
2505
|
+
columns,
|
|
2506
|
+
rows: escalations,
|
|
2507
|
+
rowId: (row) => row.id,
|
|
2508
|
+
manual: true,
|
|
2509
|
+
loading: isLoading,
|
|
2510
|
+
onRowClick: (row) => setDetailRow(row),
|
|
2511
|
+
error: error ? /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-3", children: [
|
|
2512
|
+
"Erreur lors du chargement des escalades.",
|
|
2513
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => void refresh(), children: "R\xE9essayer" })
|
|
2514
|
+
] }) : void 0,
|
|
2515
|
+
empty: "Aucune d\xE9cision d'escalade pour l'instant."
|
|
2516
|
+
}
|
|
2517
|
+
),
|
|
2518
|
+
detailRow && /* @__PURE__ */ jsx(
|
|
2519
|
+
DetailPanel3,
|
|
2520
|
+
{
|
|
2521
|
+
row: detailRow,
|
|
2522
|
+
categoryName: detailRow.categoryId && categoryNames.get(detailRow.categoryId) || "\u2014",
|
|
2523
|
+
onClose: () => setDetailRow(null)
|
|
2524
|
+
}
|
|
2525
|
+
)
|
|
2526
|
+
] });
|
|
2527
|
+
}
|
|
2528
|
+
|
|
2529
|
+
// src/ui/corrections/corrections-stats.ts
|
|
2530
|
+
function isTextChanged(row) {
|
|
2531
|
+
return Boolean(row.generatedText) && row.generatedText.trim() !== row.sentText.trim();
|
|
2532
|
+
}
|
|
2533
|
+
function toCalendarDay2(iso, timezone) {
|
|
2534
|
+
return new Intl.DateTimeFormat("en-CA", { timeZone: timezone, year: "numeric", month: "2-digit", day: "2-digit" }).format(
|
|
2535
|
+
new Date(iso)
|
|
2536
|
+
);
|
|
2537
|
+
}
|
|
2538
|
+
function wordChangeRatio(row) {
|
|
2539
|
+
if (!row.generatedText) return null;
|
|
2540
|
+
const tokens = row.diff ?? computeWordDiff(row.generatedText, row.sentText);
|
|
2541
|
+
if (tokens.length === 0) return null;
|
|
2542
|
+
const changed = tokens.filter((token) => token.op !== "equal").length;
|
|
2543
|
+
return changed / tokens.length * 100;
|
|
2544
|
+
}
|
|
2545
|
+
function matchPercentage(row) {
|
|
2546
|
+
const changeRatio = wordChangeRatio(row);
|
|
2547
|
+
return changeRatio === null ? null : Math.round(100 - changeRatio);
|
|
2548
|
+
}
|
|
2549
|
+
function versionSeriesKey(promptVersion) {
|
|
2550
|
+
return `v${promptVersion}`;
|
|
2551
|
+
}
|
|
2552
|
+
function computeRewriteRateByVersion(rows, timezone = "UTC") {
|
|
2553
|
+
const byDay = /* @__PURE__ */ new Map();
|
|
2554
|
+
const versions = /* @__PURE__ */ new Set();
|
|
2555
|
+
for (const row of rows) {
|
|
2556
|
+
if (!row.capturedAt || row.promptVersion === null) continue;
|
|
2557
|
+
const ratio = wordChangeRatio(row);
|
|
2558
|
+
if (ratio === null) continue;
|
|
2559
|
+
const day = toCalendarDay2(row.capturedAt, timezone);
|
|
2560
|
+
const byVersion = byDay.get(day) ?? /* @__PURE__ */ new Map();
|
|
2561
|
+
const bucket = byVersion.get(row.promptVersion) ?? { sum: 0, count: 0 };
|
|
2562
|
+
bucket.sum += ratio;
|
|
2563
|
+
bucket.count += 1;
|
|
2564
|
+
byVersion.set(row.promptVersion, bucket);
|
|
2565
|
+
byDay.set(day, byVersion);
|
|
2566
|
+
versions.add(row.promptVersion);
|
|
2567
|
+
}
|
|
2568
|
+
const points = [...byDay.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([day, byVersion]) => {
|
|
2569
|
+
const point = { day };
|
|
2570
|
+
for (const [version, { sum, count }] of byVersion) {
|
|
2571
|
+
point[versionSeriesKey(version)] = Math.round(sum / count);
|
|
2572
|
+
}
|
|
2573
|
+
return point;
|
|
2574
|
+
});
|
|
2575
|
+
return { points, versions: [...versions].sort((a, b) => a - b) };
|
|
2576
|
+
}
|
|
2577
|
+
var PAGE_SIZE = 50;
|
|
2578
|
+
var MATCH_BADGE_CLASS = (pct) => {
|
|
2579
|
+
if (pct >= 80) return "border-status-success/25 bg-status-success/10 text-status-success";
|
|
2580
|
+
if (pct >= 50) return "border-status-warning/25 bg-status-warning/10 text-status-warning";
|
|
2581
|
+
return "border-destructive/25 bg-destructive/10 text-destructive";
|
|
2582
|
+
};
|
|
2583
|
+
var VERSION_LINE_COLORS = 8;
|
|
2584
|
+
function qualityHref(agent) {
|
|
2585
|
+
if (!agent) return "/qualite";
|
|
2586
|
+
const version = agent.promptVersion !== null ? `&promptVersion=${agent.promptVersion}` : "";
|
|
2587
|
+
return `/qualite?promptName=${encodeURIComponent(agent.promptName)}${version}&agentId=${encodeURIComponent(agent.id)}`;
|
|
2588
|
+
}
|
|
2589
|
+
function tokensFor(row) {
|
|
2590
|
+
return row.diff ?? computeWordDiff(row.generatedText, row.sentText);
|
|
2591
|
+
}
|
|
2592
|
+
function MatchBadge({ row }) {
|
|
2593
|
+
const pct = matchPercentage(row);
|
|
2594
|
+
if (pct === null) return null;
|
|
2595
|
+
return /* @__PURE__ */ jsxs(Badge, { className: MATCH_BADGE_CLASS(pct), children: [
|
|
2596
|
+
pct,
|
|
2597
|
+
" % de correspondance"
|
|
2598
|
+
] });
|
|
2599
|
+
}
|
|
2600
|
+
function DetailPanel4({
|
|
2601
|
+
row,
|
|
2602
|
+
agentName,
|
|
2603
|
+
langfuseConfig,
|
|
2604
|
+
diffOnly,
|
|
2605
|
+
onClose
|
|
2606
|
+
}) {
|
|
2607
|
+
const tokens = tokensFor(row);
|
|
2608
|
+
return /* @__PURE__ */ jsx(SidePanel, { open: true, onClose, title: `Ticket ${row.ticketId ?? "\u2014"}`, description: agentName, children: /* @__PURE__ */ jsxs("div", { className: "space-y-4 text-sm", children: [
|
|
2609
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
|
|
2610
|
+
/* @__PURE__ */ jsx(MatchBadge, { row }),
|
|
2611
|
+
row.ticketUrl && /* @__PURE__ */ jsx(Link, { href: row.ticketUrl, target: "_blank", rel: "noopener noreferrer", className: "text-xs", children: "Ouvrir le ticket" })
|
|
2612
|
+
] }),
|
|
2613
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-3 sm:grid-cols-2", children: [
|
|
2614
|
+
/* @__PURE__ */ jsx(WordDiffView, { title: "G\xE9n\xE9r\xE9 par l'IA", tokens, keep: "delete", hideEqual: diffOnly }),
|
|
2615
|
+
/* @__PURE__ */ jsx(WordDiffView, { title: "Envoy\xE9 par l'agent", tokens, keep: "insert", hideEqual: diffOnly })
|
|
2616
|
+
] }),
|
|
2617
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground", children: [
|
|
2618
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
2619
|
+
"Captur\xE9 le ",
|
|
2620
|
+
formatDate(row.capturedAt)
|
|
2621
|
+
] }),
|
|
2622
|
+
row.promptName && /* @__PURE__ */ jsxs("span", { children: [
|
|
2623
|
+
"Prompt : ",
|
|
2624
|
+
/* @__PURE__ */ jsx("code", { children: row.promptName }),
|
|
2625
|
+
row.promptVersion !== null ? ` v${row.promptVersion}` : ""
|
|
2626
|
+
] })
|
|
2627
|
+
] }),
|
|
2628
|
+
(row.langfuseTraceId || row.langfuseObservationId) && /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
|
|
2629
|
+
/* @__PURE__ */ jsx(LangfuseTraceLink, { traceId: row.langfuseTraceId, config: langfuseConfig, label: "Trace g\xE9n\xE9ration" }),
|
|
2630
|
+
/* @__PURE__ */ jsx(
|
|
2631
|
+
LangfuseTraceLink,
|
|
2632
|
+
{
|
|
2633
|
+
traceId: row.langfuseTraceId,
|
|
2634
|
+
observationId: row.langfuseObservationId,
|
|
2635
|
+
config: langfuseConfig,
|
|
2636
|
+
label: "Trace \xE9valuation"
|
|
2637
|
+
}
|
|
2638
|
+
)
|
|
2639
|
+
] })
|
|
2640
|
+
] }) });
|
|
2641
|
+
}
|
|
2642
|
+
function CorrectionsPage() {
|
|
2643
|
+
const { role, appSlug } = useAppContext();
|
|
2644
|
+
const canWrite = canWriteForRole(role);
|
|
2645
|
+
const api = useAppApi();
|
|
2646
|
+
const toast = useToast();
|
|
2647
|
+
const { config: langfuseConfig } = useLangfuseConfig();
|
|
2648
|
+
const { settings } = useAppSettings();
|
|
2649
|
+
const timezone = settings?.statsTimezone ?? "UTC";
|
|
2650
|
+
const [agentFilter, setAgentFilter] = useState("");
|
|
2651
|
+
const [versionFilter, setVersionFilter] = useState("");
|
|
2652
|
+
const [diffOnly, setDiffOnly] = useState(false);
|
|
2653
|
+
const [detailRow, setDetailRow] = useState(null);
|
|
2654
|
+
const [isAnalyzing, setIsAnalyzing] = useState(false);
|
|
2655
|
+
const [pendingDeleteRow, setPendingDeleteRow] = useState(null);
|
|
2656
|
+
const [pendingDeleteAll, setPendingDeleteAll] = useState(false);
|
|
2657
|
+
const [isDeleting, setIsDeleting] = useState(false);
|
|
2658
|
+
function handleAgentFilterChange(value) {
|
|
2659
|
+
setAgentFilter(value);
|
|
2660
|
+
setVersionFilter("");
|
|
2661
|
+
}
|
|
2662
|
+
const comparisonFilter = useMemo(() => {
|
|
2663
|
+
if (!agentFilter) return void 0;
|
|
2664
|
+
const filter = { agentId: { eq: agentFilter } };
|
|
2665
|
+
if (versionFilter !== "") filter.promptVersion = { eq: Number(versionFilter) };
|
|
2666
|
+
return filter;
|
|
2667
|
+
}, [agentFilter, versionFilter]);
|
|
2668
|
+
const {
|
|
2669
|
+
rows: comparisons,
|
|
2670
|
+
isLoading,
|
|
2671
|
+
error,
|
|
2672
|
+
refresh,
|
|
2673
|
+
hasNextPage,
|
|
2674
|
+
hasPreviousPage,
|
|
2675
|
+
goToNextPage,
|
|
2676
|
+
goToPreviousPage
|
|
2677
|
+
} = useRecordList(
|
|
2678
|
+
"response-comparison",
|
|
2679
|
+
{
|
|
2680
|
+
filter: comparisonFilter,
|
|
2681
|
+
sort: [{ field: "capturedAt", direction: "desc" }],
|
|
2682
|
+
limit: PAGE_SIZE,
|
|
2683
|
+
paginate: true
|
|
2684
|
+
},
|
|
2685
|
+
toResponseComparison
|
|
2686
|
+
);
|
|
2687
|
+
const visibleRows = useMemo(() => diffOnly ? comparisons.filter(isTextChanged) : comparisons, [comparisons, diffOnly]);
|
|
2688
|
+
const { rows: agents } = useRecordList("agent", { limit: 500 }, toAgent);
|
|
2689
|
+
const agentNames = useMemo(() => toNameMap(agents), [agents]);
|
|
2690
|
+
const selectedAgent = agents.find((a) => a.id === agentFilter);
|
|
2691
|
+
const { versions: promptVersions } = usePromptVersions(selectedAgent?.promptName ?? null);
|
|
2692
|
+
const versionOptions = [
|
|
2693
|
+
{ value: "", label: "Toutes les versions" },
|
|
2694
|
+
...promptVersions.map((v) => ({ value: String(v.version), label: `v${v.version}${v.labels.includes("production") ? " (active)" : ""}` }))
|
|
2695
|
+
];
|
|
2696
|
+
const {
|
|
2697
|
+
rows: diffAnalyses,
|
|
2698
|
+
refresh: refreshDiffAnalyses
|
|
2699
|
+
} = useRecordList(
|
|
2700
|
+
"diff-analysis",
|
|
2701
|
+
{ filter: agentFilter ? { agentId: { eq: agentFilter } } : void 0, limit: 50 },
|
|
2702
|
+
toDiffAnalysis
|
|
2703
|
+
);
|
|
2704
|
+
const sortedAnalyses = useMemo(() => [...diffAnalyses].sort((a, b) => b.promptVersion - a.promptVersion), [diffAnalyses]);
|
|
2705
|
+
const rewriteRate = useMemo(() => computeRewriteRateByVersion(comparisons, timezone), [comparisons, timezone]);
|
|
2706
|
+
const rewriteRateSeries = useMemo(
|
|
2707
|
+
() => rewriteRate.versions.map((version, index) => ({ key: versionSeriesKey(version), label: `v${version}`, colorIndex: index % VERSION_LINE_COLORS })),
|
|
2708
|
+
[rewriteRate.versions]
|
|
2709
|
+
);
|
|
2710
|
+
const agentOptions = [
|
|
2711
|
+
{ value: "", label: "Tous les agents" },
|
|
2712
|
+
...agents.map((a) => ({ value: a.id, label: a.name }))
|
|
2713
|
+
];
|
|
2714
|
+
async function runAnalysis() {
|
|
2715
|
+
if (!agentFilter) return;
|
|
2716
|
+
setIsAnalyzing(true);
|
|
2717
|
+
const payload = { agentId: agentFilter, limit: 50 };
|
|
2718
|
+
try {
|
|
2719
|
+
await api.invoke("run-diff-analysis", payload, { idempotencyKey: idempotencyKeyFor("run-diff-analysis", payload) });
|
|
2720
|
+
toast({ title: "Analyse lanc\xE9e \u2014 les nouveaux points sont ci-dessous.", variant: "success" });
|
|
2721
|
+
await refreshDiffAnalyses();
|
|
2722
|
+
} catch (err) {
|
|
2723
|
+
toast({ title: "\xC9chec de l'analyse", description: describeInvokeError(err), variant: "error" });
|
|
2724
|
+
} finally {
|
|
2725
|
+
setIsAnalyzing(false);
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
const recordPath = (id) => `/data/apps/${appSlug}/records/response-comparison/${id}`;
|
|
2729
|
+
async function confirmDeleteRow() {
|
|
2730
|
+
if (!pendingDeleteRow) return;
|
|
2731
|
+
const row = pendingDeleteRow;
|
|
2732
|
+
setIsDeleting(true);
|
|
2733
|
+
try {
|
|
2734
|
+
await api.delete(recordPath(row.id));
|
|
2735
|
+
await refresh();
|
|
2736
|
+
toast({ title: "Comparaison supprim\xE9e.", variant: "success" });
|
|
2737
|
+
} catch (err) {
|
|
2738
|
+
toast({ title: "\xC9chec de la suppression", description: describeApiError(err), variant: "error" });
|
|
2739
|
+
} finally {
|
|
2740
|
+
setIsDeleting(false);
|
|
2741
|
+
setPendingDeleteRow(null);
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
async function confirmDeleteAll() {
|
|
2745
|
+
setIsDeleting(true);
|
|
2746
|
+
try {
|
|
2747
|
+
await Promise.all(comparisons.map((row) => api.delete(recordPath(row.id))));
|
|
2748
|
+
await refresh();
|
|
2749
|
+
toast({ title: "Comparaisons supprim\xE9es.", variant: "success" });
|
|
2750
|
+
} catch (err) {
|
|
2751
|
+
toast({ title: "\xC9chec de la suppression", description: describeApiError(err), variant: "error" });
|
|
2752
|
+
} finally {
|
|
2753
|
+
setIsDeleting(false);
|
|
2754
|
+
setPendingDeleteAll(false);
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
const columns = [
|
|
2758
|
+
{
|
|
2759
|
+
key: "ticketId",
|
|
2760
|
+
header: "Ticket",
|
|
2761
|
+
cell: (row) => row.ticketUrl ? /* @__PURE__ */ jsx(Link, { href: row.ticketUrl, target: "_blank", rel: "noopener noreferrer", onClick: (e) => e.stopPropagation(), children: row.ticketId ?? "\u2014" }) : row.ticketId ?? "\u2014"
|
|
2762
|
+
},
|
|
2763
|
+
{ key: "agent", header: "Agent", cell: (row) => row.agentId && agentNames.get(row.agentId) || "\u2014" },
|
|
2764
|
+
{
|
|
2765
|
+
key: "changed",
|
|
2766
|
+
header: "R\xE9sultat",
|
|
2767
|
+
cell: (row) => isTextChanged(row) ? /* @__PURE__ */ jsx(Badge, { variant: "warning", children: "Modifi\xE9" }) : /* @__PURE__ */ jsx(Badge, { variant: "neutral", children: "Identique" })
|
|
2768
|
+
},
|
|
2769
|
+
{ key: "match", header: "Correspondance", cell: (row) => /* @__PURE__ */ jsx(MatchBadge, { row }) },
|
|
2770
|
+
{ key: "capturedAt", header: "Captur\xE9 le", cell: (row) => formatDate(row.capturedAt) },
|
|
2771
|
+
...canWrite ? [
|
|
2772
|
+
{
|
|
2773
|
+
key: "actions",
|
|
2774
|
+
header: "",
|
|
2775
|
+
cell: (row) => /* @__PURE__ */ jsx(
|
|
2776
|
+
Button,
|
|
2777
|
+
{
|
|
2778
|
+
variant: "ghost",
|
|
2779
|
+
size: "sm",
|
|
2780
|
+
onClick: (e) => {
|
|
2781
|
+
e.stopPropagation();
|
|
2782
|
+
setPendingDeleteRow(row);
|
|
2783
|
+
},
|
|
2784
|
+
children: "Supprimer"
|
|
2785
|
+
}
|
|
2786
|
+
)
|
|
2787
|
+
}
|
|
2788
|
+
] : []
|
|
2789
|
+
];
|
|
2790
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
2791
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2792
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2793
|
+
/* @__PURE__ */ jsx("h1", { className: "text-lg font-semibold", children: "Corrections" }),
|
|
2794
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Ce que l'IA a propos\xE9, compar\xE9 \xE0 ce que l'agent a r\xE9ellement envoy\xE9." })
|
|
2795
|
+
] }),
|
|
2796
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", onClick: () => void refresh(), children: "Actualiser" })
|
|
2797
|
+
] }),
|
|
2798
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
|
|
2799
|
+
/* @__PURE__ */ jsx(
|
|
2800
|
+
Select,
|
|
2801
|
+
{
|
|
2802
|
+
items: agentOptions,
|
|
2803
|
+
value: agentFilter,
|
|
2804
|
+
onValueChange: handleAgentFilterChange,
|
|
2805
|
+
placeholder: "Tous les agents",
|
|
2806
|
+
"aria-label": "Filtrer par agent"
|
|
2807
|
+
}
|
|
2808
|
+
),
|
|
2809
|
+
/* @__PURE__ */ jsx(
|
|
2810
|
+
Select,
|
|
2811
|
+
{
|
|
2812
|
+
items: versionOptions,
|
|
2813
|
+
value: versionFilter,
|
|
2814
|
+
onValueChange: setVersionFilter,
|
|
2815
|
+
placeholder: "Toutes les versions",
|
|
2816
|
+
"aria-label": "Filtrer par version de prompt",
|
|
2817
|
+
disabled: !agentFilter
|
|
2818
|
+
}
|
|
2819
|
+
),
|
|
2820
|
+
/* @__PURE__ */ jsx(
|
|
2821
|
+
Button,
|
|
2822
|
+
{
|
|
2823
|
+
variant: diffOnly ? "default" : "outline",
|
|
2824
|
+
size: "sm",
|
|
2825
|
+
onClick: () => setDiffOnly((v) => !v),
|
|
2826
|
+
children: diffOnly ? "Afficher toutes les lignes" : "Masquer les lignes identiques"
|
|
2827
|
+
}
|
|
2828
|
+
),
|
|
2829
|
+
canWrite && agentFilter && /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => setPendingDeleteAll(true), disabled: isDeleting, children: "Tout supprimer" })
|
|
2830
|
+
] }),
|
|
2831
|
+
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(CardContent, { className: "p-4", children: [
|
|
2832
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-sm font-medium", children: "Taux de r\xE9\xE9criture" }),
|
|
2833
|
+
/* @__PURE__ */ jsx("p", { className: "mb-3 text-xs text-muted-foreground", children: "Part moyenne de la r\xE9ponse IA modifi\xE9e avant envoi, par version de prompt \u2014 plus le taux est bas, mieux c'est." }),
|
|
2834
|
+
rewriteRate.points.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Aucune donn\xE9e de r\xE9\xE9criture pour cette s\xE9lection." }) : /* @__PURE__ */ jsx(LineChart, { data: rewriteRate.points, x: "day", series: rewriteRateSeries, formatValue: (v) => `${v}%` })
|
|
2835
|
+
] }) }),
|
|
2836
|
+
agentFilter && /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-3 p-4", children: [
|
|
2837
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2838
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
2839
|
+
/* @__PURE__ */ jsxs("p", { className: "text-sm font-medium", children: [
|
|
2840
|
+
"Analyse des corrections \u2014 ",
|
|
2841
|
+
selectedAgent?.name ?? agentFilter
|
|
2842
|
+
] }),
|
|
2843
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "Patterns r\xE9currents extraits par le LLM \xE0 partir des corrections non identiques." })
|
|
2844
|
+
] }),
|
|
2845
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
2846
|
+
/* @__PURE__ */ jsx(Link, { href: qualityHref(selectedAgent), children: "Voir dans Qualit\xE9" }),
|
|
2847
|
+
canWrite && /* @__PURE__ */ jsx(Button, { onClick: () => void runAnalysis(), disabled: isAnalyzing, children: isAnalyzing ? "Analyse en cours\u2026" : "Lancer l'analyse" })
|
|
2848
|
+
] })
|
|
2849
|
+
] }),
|
|
2850
|
+
sortedAnalyses.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Aucune analyse pour cet agent pour l'instant." }) : /* @__PURE__ */ jsx("div", { className: "space-y-2", children: sortedAnalyses.map((analysis) => /* @__PURE__ */ jsxs("div", { className: "rounded-md border p-3", children: [
|
|
2851
|
+
/* @__PURE__ */ jsxs("p", { className: "mb-1 text-xs font-semibold text-muted-foreground", children: [
|
|
2852
|
+
analysis.promptName,
|
|
2853
|
+
" v",
|
|
2854
|
+
analysis.promptVersion
|
|
2855
|
+
] }),
|
|
2856
|
+
/* @__PURE__ */ jsx("ul", { className: "list-inside list-disc text-sm", children: analysis.points.map((point, index) => /* @__PURE__ */ jsx("li", { children: point }, index)) })
|
|
2857
|
+
] }, analysis.id)) })
|
|
2858
|
+
] }) }),
|
|
2859
|
+
/* @__PURE__ */ jsx(
|
|
2860
|
+
DataTable,
|
|
2861
|
+
{
|
|
2862
|
+
columns,
|
|
2863
|
+
rows: visibleRows,
|
|
2864
|
+
rowId: (row) => row.id,
|
|
2865
|
+
manual: true,
|
|
2866
|
+
loading: isLoading,
|
|
2867
|
+
onRowClick: (row) => setDetailRow(row),
|
|
2868
|
+
pagination: {
|
|
2869
|
+
hasNext: hasNextPage,
|
|
2870
|
+
hasPrevious: hasPreviousPage,
|
|
2871
|
+
onNext: goToNextPage,
|
|
2872
|
+
onPrevious: goToPreviousPage
|
|
2873
|
+
},
|
|
2874
|
+
error: error !== void 0 ? /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-3", children: [
|
|
2875
|
+
"Erreur lors du chargement des corrections.",
|
|
2876
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => void refresh(), children: "R\xE9essayer" })
|
|
2877
|
+
] }) : void 0,
|
|
2878
|
+
empty: "Aucune correction enregistr\xE9e pour l'instant."
|
|
2879
|
+
}
|
|
2880
|
+
),
|
|
2881
|
+
detailRow && /* @__PURE__ */ jsx(
|
|
2882
|
+
DetailPanel4,
|
|
2883
|
+
{
|
|
2884
|
+
row: detailRow,
|
|
2885
|
+
agentName: detailRow.agentId && agentNames.get(detailRow.agentId) || "\u2014",
|
|
2886
|
+
langfuseConfig,
|
|
2887
|
+
diffOnly,
|
|
2888
|
+
onClose: () => setDetailRow(null)
|
|
2889
|
+
}
|
|
2890
|
+
),
|
|
2891
|
+
pendingDeleteRow && /* @__PURE__ */ jsx(
|
|
2892
|
+
ConfirmModal,
|
|
2893
|
+
{
|
|
2894
|
+
title: "Supprimer cette comparaison ?",
|
|
2895
|
+
description: `Ticket ${pendingDeleteRow.ticketId ?? "\u2014"} \u2014 captur\xE9e le ${formatDate(pendingDeleteRow.capturedAt)}. Cette action est irr\xE9versible.`,
|
|
2896
|
+
confirmLabel: "Supprimer la comparaison",
|
|
2897
|
+
onConfirm: confirmDeleteRow,
|
|
2898
|
+
onCancel: () => setPendingDeleteRow(null)
|
|
2899
|
+
}
|
|
2900
|
+
),
|
|
2901
|
+
pendingDeleteAll && /* @__PURE__ */ jsx(
|
|
2902
|
+
ConfirmModal,
|
|
2903
|
+
{
|
|
2904
|
+
title: "Supprimer toutes les comparaisons de cet agent ?",
|
|
2905
|
+
description: `Toutes les comparaisons de \xAB ${selectedAgent?.name ?? agentFilter} \xBB sur cette page seront supprim\xE9es. Cette action est irr\xE9versible.`,
|
|
2906
|
+
confirmLabel: "Tout supprimer",
|
|
2907
|
+
onConfirm: confirmDeleteAll,
|
|
2908
|
+
onCancel: () => setPendingDeleteAll(false)
|
|
2909
|
+
}
|
|
2910
|
+
)
|
|
2911
|
+
] });
|
|
2912
|
+
}
|
|
2913
|
+
var WHATSAPP_MODE_LABELS = {
|
|
2914
|
+
escalate_only: "Escalade uniquement",
|
|
2915
|
+
draft_only: "Brouillon uniquement",
|
|
2916
|
+
auto_reply: "R\xE9ponse automatique"
|
|
2917
|
+
};
|
|
2918
|
+
var WHATSAPP_MODE_OPTIONS = WHATSAPP_MODES.map((value) => ({ value, label: WHATSAPP_MODE_LABELS[value] }));
|
|
2919
|
+
function field(value) {
|
|
2920
|
+
return typeof value === "string" ? value : "";
|
|
2921
|
+
}
|
|
2922
|
+
function bool(value) {
|
|
2923
|
+
return value === true;
|
|
2924
|
+
}
|
|
2925
|
+
function num(value) {
|
|
2926
|
+
return typeof value === "number" ? value : 0;
|
|
2927
|
+
}
|
|
2928
|
+
function list(value) {
|
|
2929
|
+
return Array.isArray(value) ? value.join(", ") : "";
|
|
2930
|
+
}
|
|
2931
|
+
function parseList(value) {
|
|
2932
|
+
return value.split(",").map((v) => v.trim()).filter(Boolean);
|
|
2933
|
+
}
|
|
2934
|
+
function NodesField({ value, onChange }) {
|
|
2935
|
+
const id = useId();
|
|
2936
|
+
const [text, setText] = useState(() => JSON.stringify(value ?? null, null, 2));
|
|
2937
|
+
const [parseError, setParseError] = useState(null);
|
|
2938
|
+
function handleChange(next) {
|
|
2939
|
+
setText(next);
|
|
2940
|
+
try {
|
|
2941
|
+
onChange(JSON.parse(next));
|
|
2942
|
+
setParseError(null);
|
|
2943
|
+
} catch {
|
|
2944
|
+
setParseError("JSON invalide \u2014 la derni\xE8re valeur valide est conserv\xE9e tant que ce texte ne parse pas.");
|
|
2945
|
+
}
|
|
2946
|
+
}
|
|
2947
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
2948
|
+
/* @__PURE__ */ jsx("label", { htmlFor: id, className: "mb-1 block text-sm font-medium", children: "\xC9tapes du graphe (JSON)" }),
|
|
2949
|
+
/* @__PURE__ */ jsx(
|
|
2950
|
+
Textarea,
|
|
2951
|
+
{
|
|
2952
|
+
id,
|
|
2953
|
+
className: "font-mono text-xs",
|
|
2954
|
+
rows: 10,
|
|
2955
|
+
value: text,
|
|
2956
|
+
onChange: (e) => handleChange(e.target.value)
|
|
2957
|
+
}
|
|
2958
|
+
),
|
|
2959
|
+
parseError && /* @__PURE__ */ jsx("p", { className: "mt-1 text-sm text-destructive", children: parseError }),
|
|
2960
|
+
/* @__PURE__ */ jsxs("p", { className: "mt-1 text-xs text-muted-foreground", children: [
|
|
2961
|
+
"Chaque cl\xE9 optionnelle (",
|
|
2962
|
+
/* @__PURE__ */ jsx("code", { children: "escalate" }),
|
|
2963
|
+
", ",
|
|
2964
|
+
/* @__PURE__ */ jsx("code", { children: "draft" }),
|
|
2965
|
+
", ",
|
|
2966
|
+
/* @__PURE__ */ jsx("code", { children: "evaluate" }),
|
|
2967
|
+
",",
|
|
2968
|
+
" ",
|
|
2969
|
+
/* @__PURE__ */ jsx("code", { children: "revise" }),
|
|
2970
|
+
") accepte ",
|
|
2971
|
+
/* @__PURE__ */ jsx("code", { children: "null" }),
|
|
2972
|
+
" pour d\xE9sactiver l'\xE9tape (\xA73.6).",
|
|
2973
|
+
" ",
|
|
2974
|
+
/* @__PURE__ */ jsx("code", { children: "triage" }),
|
|
2975
|
+
" est obligatoire."
|
|
2976
|
+
] })
|
|
2977
|
+
] });
|
|
2978
|
+
}
|
|
2979
|
+
function NumberField({
|
|
2980
|
+
id,
|
|
2981
|
+
label,
|
|
2982
|
+
value,
|
|
2983
|
+
onChange
|
|
2984
|
+
}) {
|
|
2985
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
2986
|
+
/* @__PURE__ */ jsx("label", { htmlFor: id, className: "mb-1 block text-sm font-medium", children: label }),
|
|
2987
|
+
/* @__PURE__ */ jsx(
|
|
2988
|
+
Input,
|
|
2989
|
+
{
|
|
2990
|
+
id,
|
|
2991
|
+
type: "number",
|
|
2992
|
+
value,
|
|
2993
|
+
onChange: (e) => {
|
|
2994
|
+
const parsed = Number(e.target.value);
|
|
2995
|
+
if (e.target.value.trim() !== "" && Number.isFinite(parsed)) onChange(parsed);
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
)
|
|
2999
|
+
] });
|
|
3000
|
+
}
|
|
3001
|
+
function SettingsPage() {
|
|
3002
|
+
const { appSlug, role } = useAppContext();
|
|
3003
|
+
const canWrite = canWriteForRole(role);
|
|
3004
|
+
const api = useAppApi();
|
|
3005
|
+
const toast = useToast();
|
|
3006
|
+
const { settings, isLoading, save, isSaving, saveError } = useAppSettings();
|
|
3007
|
+
const [form, setForm] = useState({});
|
|
3008
|
+
const [views, setViews] = useState([]);
|
|
3009
|
+
const [uncheckedAppSlugs, setUncheckedAppSlugs] = useState([]);
|
|
3010
|
+
const [installedAppsUnavailable, setInstalledAppsUnavailable] = useState(false);
|
|
3011
|
+
const formInitializedRef = useRef(false);
|
|
3012
|
+
useEffect(() => {
|
|
3013
|
+
if (settings && !formInitializedRef.current) {
|
|
3014
|
+
setForm(settings);
|
|
3015
|
+
formInitializedRef.current = true;
|
|
3016
|
+
}
|
|
3017
|
+
}, [settings]);
|
|
3018
|
+
const wasSavingRef = useRef(false);
|
|
3019
|
+
useEffect(() => {
|
|
3020
|
+
if (wasSavingRef.current && !isSaving) {
|
|
3021
|
+
if (saveError === void 0) toast({ title: "R\xE9glages enregistr\xE9s.", variant: "success" });
|
|
3022
|
+
else toast({ title: "\xC9chec de l'enregistrement", description: describeApiError(saveError), variant: "error" });
|
|
3023
|
+
}
|
|
3024
|
+
wasSavingRef.current = isSaving;
|
|
3025
|
+
}, [isSaving, saveError, toast]);
|
|
3026
|
+
const apiRef = useRef(api);
|
|
3027
|
+
apiRef.current = api;
|
|
3028
|
+
useEffect(() => {
|
|
3029
|
+
let cancelled = false;
|
|
3030
|
+
(async () => {
|
|
3031
|
+
let checkAppSlugs = [];
|
|
3032
|
+
try {
|
|
3033
|
+
const installed = await apiRef.current.get("/platform/apps/installed");
|
|
3034
|
+
checkAppSlugs = installed.apps.map((a) => a.slug).filter((slug) => slug !== appSlug);
|
|
3035
|
+
if (!cancelled) setInstalledAppsUnavailable(false);
|
|
3036
|
+
} catch {
|
|
3037
|
+
checkAppSlugs = [];
|
|
3038
|
+
if (!cancelled) setInstalledAppsUnavailable(true);
|
|
3039
|
+
}
|
|
3040
|
+
try {
|
|
3041
|
+
const result = await apiRef.current.invoke("list-gorgias-views", { checkAppSlugs });
|
|
3042
|
+
if (!cancelled) {
|
|
3043
|
+
setViews(result.views);
|
|
3044
|
+
setUncheckedAppSlugs(result.uncheckedAppSlugs);
|
|
3045
|
+
}
|
|
3046
|
+
} catch {
|
|
3047
|
+
}
|
|
3048
|
+
})();
|
|
3049
|
+
return () => {
|
|
3050
|
+
cancelled = true;
|
|
3051
|
+
};
|
|
3052
|
+
}, [appSlug]);
|
|
3053
|
+
function set(key, value) {
|
|
3054
|
+
setForm((prev) => ({ ...prev, [key]: value }));
|
|
3055
|
+
}
|
|
3056
|
+
if (isLoading) {
|
|
3057
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center py-12", children: [
|
|
3058
|
+
/* @__PURE__ */ jsx(Spinner, {}),
|
|
3059
|
+
" ",
|
|
3060
|
+
/* @__PURE__ */ jsx("span", { className: "ml-2 text-sm text-muted-foreground", children: "Chargement\u2026" })
|
|
3061
|
+
] });
|
|
3062
|
+
}
|
|
3063
|
+
const sourceViewId = field(form.sourceViewId);
|
|
3064
|
+
const claimedView = views.find((v) => v.id === sourceViewId);
|
|
3065
|
+
const claimUnverifiable = installedAppsUnavailable || uncheckedAppSlugs.length > 0;
|
|
3066
|
+
const issues = validateSettings(form);
|
|
3067
|
+
const guardrailsActive = Array.isArray(form.guardrailsActive) ? form.guardrailsActive : [];
|
|
3068
|
+
function toggleGuardrail(id, checked) {
|
|
3069
|
+
set(
|
|
3070
|
+
"guardrailsActive",
|
|
3071
|
+
checked ? [.../* @__PURE__ */ new Set([...guardrailsActive, id])] : guardrailsActive.filter((g) => g !== id)
|
|
3072
|
+
);
|
|
3073
|
+
}
|
|
3074
|
+
return /* @__PURE__ */ jsxs("div", { className: "max-w-3xl space-y-6", children: [
|
|
3075
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3076
|
+
/* @__PURE__ */ jsx("h1", { className: "text-lg font-semibold", children: "Param\xE8tres" }),
|
|
3077
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Configuration du pipeline de support." })
|
|
3078
|
+
] }),
|
|
3079
|
+
/* @__PURE__ */ jsx(Card, { id: "source", children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-3 p-4", children: [
|
|
3080
|
+
/* @__PURE__ */ jsx("h2", { className: "font-medium", children: "Source" }),
|
|
3081
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3082
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "gorgiasConnectionId", className: "mb-1 block text-sm font-medium", children: "Connexion Gorgias" }),
|
|
3083
|
+
/* @__PURE__ */ jsx(
|
|
3084
|
+
Input,
|
|
3085
|
+
{
|
|
3086
|
+
id: "gorgiasConnectionId",
|
|
3087
|
+
value: field(form.gorgiasConnectionId),
|
|
3088
|
+
onChange: (e) => set("gorgiasConnectionId", e.target.value),
|
|
3089
|
+
disabled: !canWrite
|
|
3090
|
+
}
|
|
3091
|
+
)
|
|
3092
|
+
] }),
|
|
3093
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3094
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "sourceViewId", className: "mb-1 block text-sm font-medium", children: "Vue Gorgias source" }),
|
|
3095
|
+
views.length > 0 ? /* @__PURE__ */ jsx(
|
|
3096
|
+
Select,
|
|
3097
|
+
{
|
|
3098
|
+
"aria-label": "Vue Gorgias source",
|
|
3099
|
+
value: sourceViewId || void 0,
|
|
3100
|
+
onValueChange: (v) => set("sourceViewId", v),
|
|
3101
|
+
items: views.map((v) => ({ value: v.id, label: v.name })),
|
|
3102
|
+
disabled: !canWrite
|
|
3103
|
+
}
|
|
3104
|
+
) : /* @__PURE__ */ jsx(
|
|
3105
|
+
Input,
|
|
3106
|
+
{
|
|
3107
|
+
id: "sourceViewId",
|
|
3108
|
+
value: sourceViewId,
|
|
3109
|
+
onChange: (e) => set("sourceViewId", e.target.value),
|
|
3110
|
+
disabled: !canWrite
|
|
3111
|
+
}
|
|
3112
|
+
)
|
|
3113
|
+
] }),
|
|
3114
|
+
claimedView && claimedView.claimedByAppSlugs.length > 0 && /* @__PURE__ */ jsxs("p", { className: "text-sm text-status-pending", children: [
|
|
3115
|
+
"Cette vue est d\xE9j\xE0 utilis\xE9e par : ",
|
|
3116
|
+
claimedView.claimedByAppSlugs.join(", ")
|
|
3117
|
+
] }),
|
|
3118
|
+
claimUnverifiable && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Conflit avec une autre application : inv\xE9rifiable (droits administrateur plateforme requis pour lister les applications install\xE9es). Ce contr\xF4le est informatif \u2014 il ne bloque rien, mais ne peut pas garantir l'absence de conflit." }),
|
|
3119
|
+
sourceViewId === "" && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: "Aucune vue Gorgias configur\xE9e \u2014 le triage ne peut pas d\xE9marrer tant que ce champ n'est pas renseign\xE9." })
|
|
3120
|
+
] }) }),
|
|
3121
|
+
sourceViewId === "" ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3122
|
+
/* @__PURE__ */ jsx(Card, { id: "cadence", children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-3 p-4", children: [
|
|
3123
|
+
/* @__PURE__ */ jsx("h2", { className: "font-medium", children: "Cadence" }),
|
|
3124
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-sm", children: [
|
|
3125
|
+
/* @__PURE__ */ jsx(
|
|
3126
|
+
Switch,
|
|
3127
|
+
{
|
|
3128
|
+
"aria-label": "Triage activ\xE9",
|
|
3129
|
+
checked: bool(form.triageEnabled),
|
|
3130
|
+
onCheckedChange: (v) => set("triageEnabled", v),
|
|
3131
|
+
disabled: !canWrite
|
|
3132
|
+
}
|
|
3133
|
+
),
|
|
3134
|
+
"Triage activ\xE9"
|
|
3135
|
+
] }),
|
|
3136
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-sm", children: [
|
|
3137
|
+
/* @__PURE__ */ jsx(
|
|
3138
|
+
Switch,
|
|
3139
|
+
{
|
|
3140
|
+
"aria-label": "Mode d'essai",
|
|
3141
|
+
checked: bool(form.dryRun),
|
|
3142
|
+
onCheckedChange: (v) => set("dryRun", v),
|
|
3143
|
+
disabled: !canWrite
|
|
3144
|
+
}
|
|
3145
|
+
),
|
|
3146
|
+
"Mode d'essai \u2014 le triage tourne en entier, sans aucune \xE9criture Gorgias (ni r\xE9ponse, ni tag)"
|
|
3147
|
+
] }),
|
|
3148
|
+
/* @__PURE__ */ jsx(
|
|
3149
|
+
NumberField,
|
|
3150
|
+
{
|
|
3151
|
+
id: "batchLimit",
|
|
3152
|
+
label: "Taille de lot",
|
|
3153
|
+
value: num(form.batchLimit),
|
|
3154
|
+
onChange: (v) => set("batchLimit", v)
|
|
3155
|
+
}
|
|
3156
|
+
),
|
|
3157
|
+
/* @__PURE__ */ jsx(
|
|
3158
|
+
NumberField,
|
|
3159
|
+
{
|
|
3160
|
+
id: "triageIntervalMinutes",
|
|
3161
|
+
label: "Intervalle de triage (minutes)",
|
|
3162
|
+
value: num(form.triageIntervalMinutes),
|
|
3163
|
+
onChange: (v) => set("triageIntervalMinutes", v)
|
|
3164
|
+
}
|
|
3165
|
+
),
|
|
3166
|
+
/* @__PURE__ */ jsx(
|
|
3167
|
+
NumberField,
|
|
3168
|
+
{
|
|
3169
|
+
id: "responseTtlMinutes",
|
|
3170
|
+
label: "Dur\xE9e de vie des r\xE9ponses (minutes)",
|
|
3171
|
+
value: num(form.responseTtlMinutes),
|
|
3172
|
+
onChange: (v) => set("responseTtlMinutes", v)
|
|
3173
|
+
}
|
|
3174
|
+
)
|
|
3175
|
+
] }) }),
|
|
3176
|
+
/* @__PURE__ */ jsx(Card, { id: "envoi", children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-3 p-4", children: [
|
|
3177
|
+
/* @__PURE__ */ jsx("h2", { className: "font-medium", children: "Envoi" }),
|
|
3178
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-sm", children: [
|
|
3179
|
+
/* @__PURE__ */ jsx(
|
|
3180
|
+
Switch,
|
|
3181
|
+
{
|
|
3182
|
+
"aria-label": "Envoi automatique",
|
|
3183
|
+
checked: bool(form.autoSendEnabled),
|
|
3184
|
+
onCheckedChange: (v) => set("autoSendEnabled", v),
|
|
3185
|
+
disabled: !canWrite
|
|
3186
|
+
}
|
|
3187
|
+
),
|
|
3188
|
+
"Envoi automatique"
|
|
3189
|
+
] }),
|
|
3190
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3191
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "senderEmail", className: "mb-1 block text-sm font-medium", children: "Adresse d'envoi" }),
|
|
3192
|
+
/* @__PURE__ */ jsx(
|
|
3193
|
+
Input,
|
|
3194
|
+
{
|
|
3195
|
+
id: "senderEmail",
|
|
3196
|
+
value: field(form.senderEmail),
|
|
3197
|
+
onChange: (e) => set("senderEmail", e.target.value),
|
|
3198
|
+
disabled: !canWrite
|
|
3199
|
+
}
|
|
3200
|
+
)
|
|
3201
|
+
] }),
|
|
3202
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-sm", children: [
|
|
3203
|
+
/* @__PURE__ */ jsx(
|
|
3204
|
+
Switch,
|
|
3205
|
+
{
|
|
3206
|
+
"aria-label": "Exiger une confiance de triage \xE9lev\xE9e",
|
|
3207
|
+
checked: bool(form.requireHighTriageConfidence),
|
|
3208
|
+
onCheckedChange: (v) => set("requireHighTriageConfidence", v),
|
|
3209
|
+
disabled: !canWrite
|
|
3210
|
+
}
|
|
3211
|
+
),
|
|
3212
|
+
"Exiger une confiance de triage \xE9lev\xE9e avant tout envoi automatique"
|
|
3213
|
+
] }),
|
|
3214
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3215
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "whatsappMode", className: "mb-1 block text-sm font-medium", children: "Mode WhatsApp" }),
|
|
3216
|
+
/* @__PURE__ */ jsx(
|
|
3217
|
+
Select,
|
|
3218
|
+
{
|
|
3219
|
+
"aria-label": "Mode WhatsApp",
|
|
3220
|
+
value: field(form.whatsappMode) || void 0,
|
|
3221
|
+
onValueChange: (v) => set("whatsappMode", v),
|
|
3222
|
+
items: WHATSAPP_MODE_OPTIONS,
|
|
3223
|
+
disabled: !canWrite
|
|
3224
|
+
}
|
|
3225
|
+
)
|
|
3226
|
+
] })
|
|
3227
|
+
] }) }),
|
|
3228
|
+
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-3 p-4", children: [
|
|
3229
|
+
/* @__PURE__ */ jsx("h2", { className: "font-medium", children: "Tags d'audit" }),
|
|
3230
|
+
[
|
|
3231
|
+
["unknownTag", "Tag inconnu"],
|
|
3232
|
+
["handledTag", "Tag trait\xE9"],
|
|
3233
|
+
["escalationTag", "Tag d'escalade"],
|
|
3234
|
+
["needsHumanTag", "Tag besoin humain"],
|
|
3235
|
+
["autoRepliedTag", "Tag r\xE9pondu automatiquement"],
|
|
3236
|
+
["needsReviewTag", "Tag \xE0 revoir"],
|
|
3237
|
+
["followupTag", "Tag suivi requis"]
|
|
3238
|
+
].map(([key, label]) => /* @__PURE__ */ jsxs("div", { children: [
|
|
3239
|
+
/* @__PURE__ */ jsx("label", { htmlFor: key, className: "mb-1 block text-sm font-medium", children: label }),
|
|
3240
|
+
/* @__PURE__ */ jsx(Input, { id: key, value: field(form[key]), onChange: (e) => set(key, e.target.value), disabled: !canWrite })
|
|
3241
|
+
] }, key))
|
|
3242
|
+
] }) }),
|
|
3243
|
+
/* @__PURE__ */ jsx(Card, { id: "guardrails", children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-3 p-4", children: [
|
|
3244
|
+
/* @__PURE__ */ jsx("h2", { className: "font-medium", children: "Garde-fous" }),
|
|
3245
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3246
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-sm font-medium", children: "Garde-fous actifs" }),
|
|
3247
|
+
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 gap-1", children: AGENT_GUARDRAILS.map((id) => /* @__PURE__ */ jsx(
|
|
3248
|
+
Checkbox,
|
|
3249
|
+
{
|
|
3250
|
+
label: guardrailHitLabel(id),
|
|
3251
|
+
checked: guardrailsActive.includes(id),
|
|
3252
|
+
onCheckedChange: (checked) => toggleGuardrail(id, checked),
|
|
3253
|
+
disabled: !canWrite
|
|
3254
|
+
},
|
|
3255
|
+
id
|
|
3256
|
+
)) })
|
|
3257
|
+
] }),
|
|
3258
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3259
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "blocklist", className: "mb-1 block text-sm font-medium", children: "Liste de blocage" }),
|
|
3260
|
+
/* @__PURE__ */ jsx(
|
|
3261
|
+
Textarea,
|
|
3262
|
+
{
|
|
3263
|
+
id: "blocklist",
|
|
3264
|
+
value: list(form.blocklist),
|
|
3265
|
+
onChange: (e) => set("blocklist", parseList(e.target.value)),
|
|
3266
|
+
disabled: !canWrite
|
|
3267
|
+
}
|
|
3268
|
+
)
|
|
3269
|
+
] }),
|
|
3270
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3271
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "noreplySenders", className: "mb-1 block text-sm font-medium", children: "Exp\xE9diteurs no-reply (s\xE9par\xE9s par des virgules)" }),
|
|
3272
|
+
/* @__PURE__ */ jsx(
|
|
3273
|
+
Textarea,
|
|
3274
|
+
{
|
|
3275
|
+
id: "noreplySenders",
|
|
3276
|
+
value: list(form.noreplySenders),
|
|
3277
|
+
onChange: (e) => set("noreplySenders", parseList(e.target.value)),
|
|
3278
|
+
disabled: !canWrite
|
|
3279
|
+
}
|
|
3280
|
+
)
|
|
3281
|
+
] })
|
|
3282
|
+
] }) }),
|
|
3283
|
+
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-3 p-4", children: [
|
|
3284
|
+
/* @__PURE__ */ jsx("h2", { className: "font-medium", children: "Prompts de style par canal" }),
|
|
3285
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3286
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "channelPromptEmail", className: "mb-1 block text-sm font-medium", children: "Prompt de style \u2014 email" }),
|
|
3287
|
+
/* @__PURE__ */ jsx(
|
|
3288
|
+
Input,
|
|
3289
|
+
{
|
|
3290
|
+
id: "channelPromptEmail",
|
|
3291
|
+
value: field(form.channelPromptEmail),
|
|
3292
|
+
onChange: (e) => set("channelPromptEmail", e.target.value),
|
|
3293
|
+
disabled: !canWrite
|
|
3294
|
+
}
|
|
3295
|
+
)
|
|
3296
|
+
] }),
|
|
3297
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3298
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "channelPromptWhatsapp", className: "mb-1 block text-sm font-medium", children: "Prompt de style \u2014 WhatsApp" }),
|
|
3299
|
+
/* @__PURE__ */ jsx(
|
|
3300
|
+
Input,
|
|
3301
|
+
{
|
|
3302
|
+
id: "channelPromptWhatsapp",
|
|
3303
|
+
value: field(form.channelPromptWhatsapp),
|
|
3304
|
+
onChange: (e) => set("channelPromptWhatsapp", e.target.value),
|
|
3305
|
+
disabled: !canWrite
|
|
3306
|
+
}
|
|
3307
|
+
)
|
|
3308
|
+
] })
|
|
3309
|
+
] }) }),
|
|
3310
|
+
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-3 p-4", children: [
|
|
3311
|
+
/* @__PURE__ */ jsx("h2", { className: "font-medium", children: "Divers" }),
|
|
3312
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-sm", children: [
|
|
3313
|
+
/* @__PURE__ */ jsx(
|
|
3314
|
+
Checkbox,
|
|
3315
|
+
{
|
|
3316
|
+
checked: bool(form.renameEnabled),
|
|
3317
|
+
onCheckedChange: (v) => set("renameEnabled", v === true),
|
|
3318
|
+
disabled: !canWrite
|
|
3319
|
+
}
|
|
3320
|
+
),
|
|
3321
|
+
"Renommage de sujet activ\xE9"
|
|
3322
|
+
] }),
|
|
3323
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3324
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "renameFrom", className: "mb-1 block text-sm font-medium", children: "Renommage \u2014 motif \xE0 rep\xE9rer dans le sujet" }),
|
|
3325
|
+
/* @__PURE__ */ jsx(
|
|
3326
|
+
Input,
|
|
3327
|
+
{
|
|
3328
|
+
id: "renameFrom",
|
|
3329
|
+
value: field(form.renameFrom),
|
|
3330
|
+
onChange: (e) => set("renameFrom", e.target.value),
|
|
3331
|
+
disabled: !canWrite
|
|
3332
|
+
}
|
|
3333
|
+
)
|
|
3334
|
+
] }),
|
|
3335
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3336
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "renameTo", className: "mb-1 block text-sm font-medium", children: "Renommage \u2014 sujet de remplacement" }),
|
|
3337
|
+
/* @__PURE__ */ jsx(
|
|
3338
|
+
Input,
|
|
3339
|
+
{
|
|
3340
|
+
id: "renameTo",
|
|
3341
|
+
value: field(form.renameTo),
|
|
3342
|
+
onChange: (e) => set("renameTo", e.target.value),
|
|
3343
|
+
disabled: !canWrite
|
|
3344
|
+
}
|
|
3345
|
+
)
|
|
3346
|
+
] }),
|
|
3347
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3348
|
+
/* @__PURE__ */ jsx("label", { htmlFor: "statsTimezone", className: "mb-1 block text-sm font-medium", children: "Fuseau horaire des statistiques" }),
|
|
3349
|
+
/* @__PURE__ */ jsx(
|
|
3350
|
+
Input,
|
|
3351
|
+
{
|
|
3352
|
+
id: "statsTimezone",
|
|
3353
|
+
value: field(form.statsTimezone),
|
|
3354
|
+
onChange: (e) => set("statsTimezone", e.target.value),
|
|
3355
|
+
disabled: !canWrite
|
|
3356
|
+
}
|
|
3357
|
+
)
|
|
3358
|
+
] })
|
|
3359
|
+
] }) }),
|
|
3360
|
+
/* @__PURE__ */ jsx(Card, { id: "pipeline-avance", children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-3 p-4", children: [
|
|
3361
|
+
/* @__PURE__ */ jsx("h2", { className: "font-medium", children: "Pipeline (avanc\xE9)" }),
|
|
3362
|
+
/* @__PURE__ */ jsx(NodesField, { value: form.nodes, onChange: (v) => set("nodes", v) }),
|
|
3363
|
+
/* @__PURE__ */ jsx(Link, { href: `/espace/${appSlug}/graph-canvas`, children: "Visualiser dans Graphe" })
|
|
3364
|
+
] }) }),
|
|
3365
|
+
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-3 p-4", children: [
|
|
3366
|
+
/* @__PURE__ */ jsx("h2", { className: "font-medium", children: "Agents support" }),
|
|
3367
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Les agents support sont des utilisateurs plateforme \u2014 donnez-leur acc\xE8s \xE0 cette application depuis la gestion des membres." }),
|
|
3368
|
+
/* @__PURE__ */ jsx(Link, { href: "/parametres/membres", children: "G\xE9rer les acc\xE8s" })
|
|
3369
|
+
] }) }),
|
|
3370
|
+
issues.length > 0 && /* @__PURE__ */ jsx("div", { className: "rounded-md border border-status-pending bg-status-pending/10 p-3 text-sm", children: issues.map((issue) => /* @__PURE__ */ jsx("p", { children: settingsIssueLabel(issue.key, issue.message) }, issue.key)) }),
|
|
3371
|
+
canWrite && /* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx(Button, { onClick: () => void save(form), disabled: isSaving || issues.length > 0, children: isSaving ? "Enregistrement\u2026" : "Enregistrer" }) })
|
|
3372
|
+
] })
|
|
3373
|
+
] });
|
|
3374
|
+
}
|
|
3375
|
+
|
|
3376
|
+
// src/ui/graph-canvas/reachability.ts
|
|
3377
|
+
function stubPrompts() {
|
|
3378
|
+
const ref = { name: "", label: "production" };
|
|
3379
|
+
return { triage: ref, escalate: ref, draft: ref, evaluate: ref, revise: ref };
|
|
3380
|
+
}
|
|
3381
|
+
var PROMPT_403_NODES = /* @__PURE__ */ new Set(["triage", "escalate", "draft", "evaluate", "revise"]);
|
|
3382
|
+
var PROMPT_403_NOTE = "promptRef est transmis \xE0 ctx.api.llm.complete, qui r\xE9pond 403 en production tant que manifest.prompts[] reste vide (d\xE9faut D-LF connu, non corrig\xE9 \u2014 voir le journal T24/T25) : ce n\u0153ud peut renvoyer PROMPT_NOT_DECLARED sur un d\xE9ploiement r\xE9el malgr\xE9 un r\xE9glage \xAB Actif \xBB ici.";
|
|
3383
|
+
function reason(kind, message) {
|
|
3384
|
+
return { kind, message };
|
|
3385
|
+
}
|
|
3386
|
+
function nodeModelOf(node, profile) {
|
|
3387
|
+
switch (node) {
|
|
3388
|
+
case "triage":
|
|
3389
|
+
return profile.nodes.triage.model;
|
|
3390
|
+
case "escalate":
|
|
3391
|
+
return profile.nodes.escalate?.model ?? null;
|
|
3392
|
+
case "evaluate":
|
|
3393
|
+
return profile.nodes.evaluate?.model ?? null;
|
|
3394
|
+
case "revise":
|
|
3395
|
+
return profile.nodes.revise?.model ?? null;
|
|
3396
|
+
default:
|
|
3397
|
+
return null;
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
var READY_EXIT = { key: "evaluate-ready", condition: "envoi auto non \xE9ligible", outcome: "ready" };
|
|
3401
|
+
var NODE_EXITS = {
|
|
3402
|
+
fetchContext: [{ key: "fetchContext-failed", condition: "lecture impossible", outcome: "failed" }],
|
|
3403
|
+
triage: [
|
|
3404
|
+
{ key: "triage-fallback", condition: "classification de repli", outcome: "triaged_only" },
|
|
3405
|
+
{ key: "triage-closed", condition: "le dernier message client cl\xF4t la conversation", outcome: "no_reply_needed" },
|
|
3406
|
+
{ key: "triage-whatsapp-gate", condition: "r\xE8gle de canal WhatsApp (STOP ou pas notre tour)", outcome: "guardrail_hold" }
|
|
3407
|
+
],
|
|
3408
|
+
escalate: [
|
|
3409
|
+
{ key: "escalate-escalated", condition: "escalade demand\xE9e", outcome: "escalated" },
|
|
3410
|
+
{ key: "escalate-no-draft", condition: "profil sans n\u0153ud de r\xE9daction", outcome: "triaged_only" }
|
|
3411
|
+
],
|
|
3412
|
+
evaluate: [
|
|
3413
|
+
{
|
|
3414
|
+
key: "evaluate-needs-human",
|
|
3415
|
+
condition: "verdict non envoyable, confiance sous le seuil, ou suivi requis sans escalade",
|
|
3416
|
+
outcome: "needs_human"
|
|
3417
|
+
},
|
|
3418
|
+
READY_EXIT
|
|
3419
|
+
],
|
|
3420
|
+
guardrails: [{ key: "guardrails-content", condition: "garde-fou de contenu", outcome: "guardrail_hold" }],
|
|
3421
|
+
authorize: [{ key: "authorize-awaiting", condition: "une action n'est pas \xAB auto \xBB", outcome: "awaiting_approval" }],
|
|
3422
|
+
act: [
|
|
3423
|
+
{ key: "act-collision", condition: "contr\xF4le anti-collision", outcome: "guardrail_hold" },
|
|
3424
|
+
{ key: "act-sent-email", condition: "r\xE9ponse email", outcome: "sent" },
|
|
3425
|
+
{ key: "act-sent-whatsapp", condition: "note WhatsApp", outcome: "sent" }
|
|
3426
|
+
]
|
|
3427
|
+
};
|
|
3428
|
+
function exitsFor(node, evaluateConfigured) {
|
|
3429
|
+
const raw = NODE_EXITS[node] ?? [];
|
|
3430
|
+
if (evaluateConfigured) return raw;
|
|
3431
|
+
if (node === "evaluate") return [];
|
|
3432
|
+
if (node === "draft") return [READY_EXIT];
|
|
3433
|
+
return raw;
|
|
3434
|
+
}
|
|
3435
|
+
function deriveState(upstreamOk, blockingReasons, offReasons) {
|
|
3436
|
+
if (!upstreamOk) return "unreachable";
|
|
3437
|
+
if (blockingReasons.length > 0) return "unreachable";
|
|
3438
|
+
if (offReasons.length > 0) return "off";
|
|
3439
|
+
return "on";
|
|
3440
|
+
}
|
|
3441
|
+
function computeGraphReachability(rawSettings, hasCategoryWithAutoReply) {
|
|
3442
|
+
const issues = validateSettings(rawSettings);
|
|
3443
|
+
const nodesIssue = issues.find((issue) => issue.key === "nodes");
|
|
3444
|
+
if (nodesIssue) {
|
|
3445
|
+
const message = settingsIssueLabel("nodes", nodesIssue.message);
|
|
3446
|
+
return {
|
|
3447
|
+
blocked: true,
|
|
3448
|
+
nodes: NODE_NAMES.map((node) => ({
|
|
3449
|
+
node,
|
|
3450
|
+
state: "unreachable",
|
|
3451
|
+
reasons: [reason("missing-setting", message)],
|
|
3452
|
+
notes: [],
|
|
3453
|
+
model: null,
|
|
3454
|
+
exits: []
|
|
3455
|
+
}))
|
|
3456
|
+
};
|
|
3457
|
+
}
|
|
3458
|
+
const settings = rawSettings;
|
|
3459
|
+
const profile = settingsToProfile(settings, stubPrompts());
|
|
3460
|
+
const evaluateConfigured = profile.nodes.evaluate !== null;
|
|
3461
|
+
const byNode = /* @__PURE__ */ new Map();
|
|
3462
|
+
function set(node, state, reasons, notes = []) {
|
|
3463
|
+
const promptNote = state === "on" && PROMPT_403_NODES.has(node) ? [PROMPT_403_NOTE] : [];
|
|
3464
|
+
byNode.set(node, {
|
|
3465
|
+
node,
|
|
3466
|
+
state,
|
|
3467
|
+
reasons,
|
|
3468
|
+
notes: [...notes, ...promptNote],
|
|
3469
|
+
model: nodeModelOf(node, profile),
|
|
3470
|
+
exits: exitsFor(node, evaluateConfigured)
|
|
3471
|
+
});
|
|
3472
|
+
}
|
|
3473
|
+
function getNode(node) {
|
|
3474
|
+
const found = byNode.get(node);
|
|
3475
|
+
if (!found) {
|
|
3476
|
+
throw new Error(`computeGraphReachability: no reachability rule was set for node "${node}" \u2014 NODE_NAMES gained an entry this module does not know how to place.`);
|
|
3477
|
+
}
|
|
3478
|
+
return found;
|
|
3479
|
+
}
|
|
3480
|
+
const passesControlOn = (node) => getNode(node).state === "on";
|
|
3481
|
+
const fetchOffReasons = [];
|
|
3482
|
+
const fetchBlockingReasons = [];
|
|
3483
|
+
const sourceViewIdIssue = issues.find((issue) => issue.key === "sourceViewId");
|
|
3484
|
+
if (sourceViewIdIssue) {
|
|
3485
|
+
fetchBlockingReasons.push(reason("missing-setting", settingsIssueLabel("sourceViewId", sourceViewIdIssue.message)));
|
|
3486
|
+
}
|
|
3487
|
+
if (!settings.triageEnabled) {
|
|
3488
|
+
fetchOffReasons.push(reason("missing-setting", "triageEnabled est d\xE9sactiv\xE9 \u2014 ce coupe-circuit emp\xEAche toute ex\xE9cution du pipeline."));
|
|
3489
|
+
}
|
|
3490
|
+
set("fetchContext", deriveState(true, fetchBlockingReasons, fetchOffReasons), [...fetchBlockingReasons, ...fetchOffReasons]);
|
|
3491
|
+
const fetchNode = getNode("fetchContext");
|
|
3492
|
+
const fetchRuns = passesControlOn("fetchContext");
|
|
3493
|
+
set(
|
|
3494
|
+
"triage",
|
|
3495
|
+
fetchRuns ? "on" : "unreachable",
|
|
3496
|
+
fetchRuns ? [] : [
|
|
3497
|
+
reason(
|
|
3498
|
+
"upstream-disabled",
|
|
3499
|
+
fetchNode.state === "off" ? "fetchContext est d\xE9sactiv\xE9 (triageEnabled) \u2014 aucun ticket n'est jamais lu." : "fetchContext est inatteignable \u2014 voir les raisons ci-dessus."
|
|
3500
|
+
)
|
|
3501
|
+
]
|
|
3502
|
+
);
|
|
3503
|
+
const triageRuns = passesControlOn("triage");
|
|
3504
|
+
const escalateDisabled = profile.nodes.escalate === null;
|
|
3505
|
+
set(
|
|
3506
|
+
"escalate",
|
|
3507
|
+
deriveState(triageRuns, [], escalateDisabled ? [reason("disabled-step", "nodes.escalate est \xE0 null dans les r\xE9glages \u2014 \xE9tape d\xE9sactiv\xE9e (\xA73.6).")] : []),
|
|
3508
|
+
triageRuns ? escalateDisabled ? [reason("disabled-step", "nodes.escalate est \xE0 null dans les r\xE9glages \u2014 \xE9tape d\xE9sactiv\xE9e (\xA73.6).")] : [] : [reason("upstream-disabled", "triage est inatteignable.")]
|
|
3509
|
+
);
|
|
3510
|
+
const draftDisabled = hasNoDraftNode(profile);
|
|
3511
|
+
set(
|
|
3512
|
+
"draft",
|
|
3513
|
+
deriveState(triageRuns, [], draftDisabled ? [reason("disabled-step", 'nodes.draft est \xE0 null dans les r\xE9glages \u2014 aucune r\xE9ponse ne sera r\xE9dig\xE9e (sortie "triaged_only").')] : []),
|
|
3514
|
+
triageRuns ? draftDisabled ? [reason("disabled-step", 'nodes.draft est \xE0 null dans les r\xE9glages \u2014 aucune r\xE9ponse ne sera r\xE9dig\xE9e (sortie "triaged_only").')] : [] : [reason("upstream-disabled", "triage est inatteignable.")]
|
|
3515
|
+
);
|
|
3516
|
+
const draftRuns = passesControlOn("draft");
|
|
3517
|
+
const evaluateDisabled = !evaluateConfigured;
|
|
3518
|
+
set(
|
|
3519
|
+
"evaluate",
|
|
3520
|
+
deriveState(draftRuns, [], evaluateDisabled ? [reason("disabled-step", `nodes.evaluate est \xE0 null dans les r\xE9glages \u2014 aucun verdict n'est jamais produit, la r\xE9ponse reste "ready".`)] : []),
|
|
3521
|
+
draftRuns ? evaluateDisabled ? [reason("disabled-step", `nodes.evaluate est \xE0 null dans les r\xE9glages \u2014 aucun verdict n'est jamais produit, la r\xE9ponse reste "ready".`)] : [] : [reason("upstream-disabled", getNode("draft").state === "off" ? "draft est d\xE9sactiv\xE9 \u2014 aucun ticket n'atteint jamais \xE9valuate." : "draft est inatteignable.")]
|
|
3522
|
+
);
|
|
3523
|
+
const evaluateRuns = passesControlOn("evaluate");
|
|
3524
|
+
const reviseDisabled = profile.nodes.revise === null;
|
|
3525
|
+
set(
|
|
3526
|
+
"revise",
|
|
3527
|
+
deriveState(evaluateRuns, [], reviseDisabled ? [reason("disabled-step", "nodes.revise est \xE0 null dans les r\xE9glages \u2014 pas de passe de correction.")] : []),
|
|
3528
|
+
evaluateRuns ? reviseDisabled ? [reason("disabled-step", "nodes.revise est \xE0 null dans les r\xE9glages \u2014 pas de passe de correction.")] : [] : [reason("upstream-disabled", getNode("evaluate").state === "off" ? "evaluate est d\xE9sactiv\xE9 \u2014 aucun ticket n'atteint jamais revise." : "evaluate est inatteignable.")],
|
|
3529
|
+
evaluateRuns && !reviseDisabled ? ["Au plus une passe de r\xE9vision par ticket (\xA73.3)."] : []
|
|
3530
|
+
);
|
|
3531
|
+
const autoSendBlockingReasons = [];
|
|
3532
|
+
const autoSendOffReasons = [];
|
|
3533
|
+
if (!profile.autoSend.enabled) {
|
|
3534
|
+
autoSendOffReasons.push(reason("missing-setting", "autoSendEnabled est d\xE9sactiv\xE9 \u2014 ce coupe-circuit emp\xEAche tout envoi automatique."));
|
|
3535
|
+
}
|
|
3536
|
+
if (!hasCategoryWithAutoReply) {
|
|
3537
|
+
autoSendBlockingReasons.push(
|
|
3538
|
+
reason("missing-setting", `Aucune cat\xE9gorie n'a "Envoi auto" activ\xE9 \u2014 isAutoSendEligible exige category.autoReplyEnabled, qu'aucune cat\xE9gorie ne porte aujourd'hui.`)
|
|
3539
|
+
);
|
|
3540
|
+
}
|
|
3541
|
+
const senderEmailIssue = issues.find((issue) => issue.key === "senderEmail");
|
|
3542
|
+
if (senderEmailIssue) {
|
|
3543
|
+
autoSendBlockingReasons.push(reason("missing-setting", settingsIssueLabel("senderEmail", senderEmailIssue.message)));
|
|
3544
|
+
}
|
|
3545
|
+
const guardrailNotes = [];
|
|
3546
|
+
if (!profile.autoSend.senderEmail && profile.guardrails.params.whatsappMode === "auto_reply") {
|
|
3547
|
+
guardrailNotes.push(
|
|
3548
|
+
`senderEmail est vide : seuls les tickets WhatsApp en mode "auto_reply" peuvent atteindre ce n\u0153ud sans adresse d'envoi \u2014 un ticket email reste bloqu\xE9 \xE0 "ready", sans jamais atteindre guardrails/authorize/act.`
|
|
3549
|
+
);
|
|
3550
|
+
}
|
|
3551
|
+
if (profile.guardrails.params.whatsappMode === "draft_only") {
|
|
3552
|
+
guardrailNotes.push(
|
|
3553
|
+
'whatsappMode="draft_only" : un ticket WhatsApp ne d\xE9passera jamais "ready" (isAutoSendEligible exclut ce mode) \u2014 seuls les tickets email atteignent r\xE9ellement ce n\u0153ud, et donc authorize/act ci-apr\xE8s.'
|
|
3554
|
+
);
|
|
3555
|
+
}
|
|
3556
|
+
if (profile.guardrails.params.whatsappMode === "escalate_only") {
|
|
3557
|
+
guardrailNotes.push(
|
|
3558
|
+
`whatsappMode="escalate_only" : un ticket WhatsApp qui atteint ce n\u0153ud sera syst\xE9matiquement bloqu\xE9 par le garde-fou "whatsapp" (\xA73.9) \u2014 la r\xE9ponse est retenue, pas envoy\xE9e, et authorize/act ci-apr\xE8s ne s'ex\xE9cutent jamais pour ce canal.`
|
|
3559
|
+
);
|
|
3560
|
+
}
|
|
3561
|
+
set(
|
|
3562
|
+
"guardrails",
|
|
3563
|
+
deriveState(evaluateRuns, autoSendBlockingReasons, autoSendOffReasons),
|
|
3564
|
+
evaluateRuns ? [...autoSendBlockingReasons, ...autoSendOffReasons] : [reason("upstream-disabled", getNode("evaluate").state === "off" ? "evaluate est d\xE9sactiv\xE9 \u2014 sans verdict, aucun ticket n'atteint jamais ce n\u0153ud." : "evaluate est inatteignable \u2014 aucun verdict ne peut donc jamais \xEAtre produit.")],
|
|
3565
|
+
guardrailNotes
|
|
3566
|
+
);
|
|
3567
|
+
const guardrailsRuns = passesControlOn("guardrails");
|
|
3568
|
+
set(
|
|
3569
|
+
"authorize",
|
|
3570
|
+
guardrailsRuns ? "on" : "unreachable",
|
|
3571
|
+
guardrailsRuns ? [] : [reason("upstream-disabled", getNode("guardrails").state === "off" ? "guardrails est d\xE9sactiv\xE9 (autoSendEnabled) \u2014 aucune action n'est jamais autoris\xE9e." : "guardrails est inatteignable \u2014 voir les raisons ci-dessus.")],
|
|
3572
|
+
guardrailsRuns ? guardrailNotes : []
|
|
3573
|
+
);
|
|
3574
|
+
const authorizeRuns = passesControlOn("authorize");
|
|
3575
|
+
const approvalNote = `Le chemin d'approbation manuelle ("awaiting_approval") est inatteignable avec les r\xE9glages actuels : authorization.send_reply d\xE9rive du m\xEAme coupe-circuit autoSendEnabled qu'isAutoSendEligible, donc "act" est toujours atteint en direct, jamais via une approbation (limitation connue, voir le journal T22).`;
|
|
3576
|
+
set(
|
|
3577
|
+
"act",
|
|
3578
|
+
authorizeRuns ? "on" : "unreachable",
|
|
3579
|
+
authorizeRuns ? [] : [reason("upstream-disabled", "authorize est inatteignable.")],
|
|
3580
|
+
authorizeRuns ? [...guardrailNotes, approvalNote] : []
|
|
3581
|
+
);
|
|
3582
|
+
return { blocked: false, nodes: NODE_NAMES.map((node) => getNode(node)) };
|
|
3583
|
+
}
|
|
3584
|
+
var CATEGORY_PAGE_SIZE = 500;
|
|
3585
|
+
var REASON_KIND_LABELS = {
|
|
3586
|
+
"disabled-step": "\xC9tape d\xE9sactiv\xE9e",
|
|
3587
|
+
"upstream-disabled": "Bloqu\xE9 en amont",
|
|
3588
|
+
"missing-setting": "R\xE9glage manquant",
|
|
3589
|
+
"channel-gate": "Restriction de canal"
|
|
3590
|
+
};
|
|
3591
|
+
var ACTIVATION_LABELS = {
|
|
3592
|
+
on: "Actif",
|
|
3593
|
+
off: "D\xE9sactiv\xE9",
|
|
3594
|
+
unreachable: "Inatteignable"
|
|
3595
|
+
};
|
|
3596
|
+
var ACTIVATION_BADGE_VARIANT = {
|
|
3597
|
+
on: "success",
|
|
3598
|
+
off: "neutral",
|
|
3599
|
+
unreachable: "warning"
|
|
3600
|
+
};
|
|
3601
|
+
var NODE_SETTINGS_SECTION = {
|
|
3602
|
+
fetchContext: { id: "source", title: "Source" },
|
|
3603
|
+
triage: { id: "pipeline-avance", title: "Pipeline (avanc\xE9)" },
|
|
3604
|
+
escalate: { id: "pipeline-avance", title: "Pipeline (avanc\xE9)" },
|
|
3605
|
+
draft: { id: "pipeline-avance", title: "Pipeline (avanc\xE9)" },
|
|
3606
|
+
evaluate: { id: "pipeline-avance", title: "Pipeline (avanc\xE9)" },
|
|
3607
|
+
revise: { id: "pipeline-avance", title: "Pipeline (avanc\xE9)" },
|
|
3608
|
+
guardrails: { id: "guardrails", title: "Guardrails" },
|
|
3609
|
+
act: { id: "envoi", title: "Envoi" }
|
|
3610
|
+
};
|
|
3611
|
+
function NodeCard({ node, appSlug }) {
|
|
3612
|
+
const section = NODE_SETTINGS_SECTION[node.node];
|
|
3613
|
+
return /* @__PURE__ */ jsx(
|
|
3614
|
+
Card,
|
|
3615
|
+
{
|
|
3616
|
+
"data-testid": "graph-node",
|
|
3617
|
+
"data-node": node.node,
|
|
3618
|
+
className: cn("w-56 shrink-0", node.state !== "on" && "border-dashed opacity-90"),
|
|
3619
|
+
children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-2 p-3", "data-testid": `graph-node-${node.node}`, children: [
|
|
3620
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
|
|
3621
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: NODE_LABELS[node.node] }),
|
|
3622
|
+
/* @__PURE__ */ jsx(Badge, { variant: ACTIVATION_BADGE_VARIANT[node.state], children: ACTIVATION_LABELS[node.state] })
|
|
3623
|
+
] }),
|
|
3624
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs leading-snug text-muted-foreground", children: NODE_ROLE_LABELS[node.node] }),
|
|
3625
|
+
/* @__PURE__ */ jsx("p", { className: "font-mono text-[10px] text-muted-foreground", children: node.node }),
|
|
3626
|
+
node.model && /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
|
|
3627
|
+
"Mod\xE8le : ",
|
|
3628
|
+
/* @__PURE__ */ jsx("code", { className: "font-mono", children: node.model })
|
|
3629
|
+
] }),
|
|
3630
|
+
node.exits.length > 0 && /* @__PURE__ */ jsx("ul", { className: "flex flex-wrap gap-1.5 border-t pt-2", children: node.exits.map((exit) => /* @__PURE__ */ jsx(
|
|
3631
|
+
"li",
|
|
3632
|
+
{
|
|
3633
|
+
title: exit.condition,
|
|
3634
|
+
className: "rounded-md border px-1.5 py-0.5 text-[11px] leading-tight text-muted-foreground",
|
|
3635
|
+
children: outcomeLabel(exit.outcome)
|
|
3636
|
+
},
|
|
3637
|
+
exit.key
|
|
3638
|
+
)) }),
|
|
3639
|
+
node.reasons.length > 0 && /* @__PURE__ */ jsx("ul", { className: "space-y-1", children: node.reasons.map((r, i) => /* @__PURE__ */ jsxs("li", { className: "text-xs text-muted-foreground", children: [
|
|
3640
|
+
/* @__PURE__ */ jsxs("span", { className: "font-medium text-foreground", children: [
|
|
3641
|
+
REASON_KIND_LABELS[r.kind],
|
|
3642
|
+
" \u2014 "
|
|
3643
|
+
] }),
|
|
3644
|
+
r.message
|
|
3645
|
+
] }, i)) }),
|
|
3646
|
+
node.notes.length > 0 && /* @__PURE__ */ jsx("ul", { className: "space-y-1 border-t pt-2", children: node.notes.map((note, i) => /* @__PURE__ */ jsx("li", { className: "text-xs text-muted-foreground", children: note }, i)) }),
|
|
3647
|
+
section && /* @__PURE__ */ jsx("p", { className: "border-t pt-2 text-xs", children: /* @__PURE__ */ jsxs(Link, { href: `/parametres/espaces/${appSlug}#${section.id}`, children: [
|
|
3648
|
+
"Ouvrir \xAB ",
|
|
3649
|
+
section.title,
|
|
3650
|
+
" \xBB dans Param\xE8tres"
|
|
3651
|
+
] }) })
|
|
3652
|
+
] })
|
|
3653
|
+
}
|
|
3654
|
+
);
|
|
3655
|
+
}
|
|
3656
|
+
function GraphCanvasPage() {
|
|
3657
|
+
const { appSlug } = useAppContext();
|
|
3658
|
+
const { settings, isLoading: settingsLoading, error: settingsError } = useAppSettings();
|
|
3659
|
+
const {
|
|
3660
|
+
rows: categories,
|
|
3661
|
+
isLoading: categoriesLoading,
|
|
3662
|
+
error: categoriesError
|
|
3663
|
+
} = useRecordList("category", { limit: CATEGORY_PAGE_SIZE }, toCategory);
|
|
3664
|
+
const hasCategoryWithAutoReply = useMemo(() => categories.some((c) => c.autoReplyEnabled), [categories]);
|
|
3665
|
+
const categoriesMayBeTruncated = categories.length >= CATEGORY_PAGE_SIZE;
|
|
3666
|
+
const result = useMemo(
|
|
3667
|
+
() => settings ? computeGraphReachability(settings, hasCategoryWithAutoReply) : null,
|
|
3668
|
+
[settings, hasCategoryWithAutoReply]
|
|
3669
|
+
);
|
|
3670
|
+
const isLoading = settingsLoading || categoriesLoading;
|
|
3671
|
+
const isUnavailable = !isLoading && (settingsError !== void 0 || categoriesError !== void 0 || !result);
|
|
3672
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
3673
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3674
|
+
/* @__PURE__ */ jsx("h1", { className: "text-lg font-semibold", children: "Graphe" }),
|
|
3675
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Le parcours d'un ticket \xE0 travers les 9 n\u0153uds du pipeline, et ce qui, dans les r\xE9glages actuels, rend chaque n\u0153ud atteignable ou non." })
|
|
3676
|
+
] }),
|
|
3677
|
+
isLoading ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center py-12", children: [
|
|
3678
|
+
/* @__PURE__ */ jsx(Spinner, {}),
|
|
3679
|
+
" ",
|
|
3680
|
+
/* @__PURE__ */ jsx("span", { className: "ml-2 text-sm text-muted-foreground", children: "Chargement\u2026" })
|
|
3681
|
+
] }) : isUnavailable ? /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: "Impossible de calculer le graphe : les r\xE9glages ou les cat\xE9gories n'ont pas pu \xEAtre charg\xE9s." }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3682
|
+
result.blocked && /* @__PURE__ */ jsxs("div", { className: "rounded-md border border-status-warning/40 bg-status-warning/10 p-3 text-sm text-status-warning", children: [
|
|
3683
|
+
"Le graphe ne peut d\xE9marrer avec les r\xE9glages actuels : ",
|
|
3684
|
+
result.nodes[0].reasons[0]?.message ?? ""
|
|
3685
|
+
] }),
|
|
3686
|
+
!hasCategoryWithAutoReply && categoriesMayBeTruncated && /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
|
|
3687
|
+
"La lecture des cat\xE9gories est born\xE9e aux ",
|
|
3688
|
+
CATEGORY_PAGE_SIZE,
|
|
3689
|
+
" premi\xE8res \u2014 au-del\xE0, l'absence de cat\xE9gorie avec \xAB Envoi auto \xBB activ\xE9 ci-dessous peut \xEAtre un simple effet de fen\xEAtre, pas un fait."
|
|
3690
|
+
] }),
|
|
3691
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap items-center gap-2", children: result.nodes.map((node, i) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
3692
|
+
/* @__PURE__ */ jsx(NodeCard, { node, appSlug }),
|
|
3693
|
+
i < result.nodes.length - 1 && /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "text-muted-foreground", children: "\u2192" })
|
|
3694
|
+
] }, node.node)) }),
|
|
3695
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "\u21BA \xAB R\xE9vision \xBB rejoue \xAB \xC9valuation \xBB une fois avant de continuer (au plus une passe par ticket, \xA73.3) \u2014 la fl\xE8che lin\xE9aire ci-dessus ne montre pas ce retour en arri\xE8re pour garder la s\xE9quence lisible." }),
|
|
3696
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-4 text-xs text-muted-foreground", children: [
|
|
3697
|
+
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5", children: [
|
|
3698
|
+
/* @__PURE__ */ jsx(Badge, { variant: "success", children: "Actif" }),
|
|
3699
|
+
" le n\u0153ud peut \xEAtre atteint par au moins un ticket avec les r\xE9glages actuels."
|
|
3700
|
+
] }),
|
|
3701
|
+
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5", children: [
|
|
3702
|
+
/* @__PURE__ */ jsx(Badge, { variant: "neutral", children: "D\xE9sactiv\xE9" }),
|
|
3703
|
+
" l'op\xE9rateur a coup\xE9 ce n\u0153ud lui-m\xEAme \u2014 un choix, pas un incident."
|
|
3704
|
+
] }),
|
|
3705
|
+
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5", children: [
|
|
3706
|
+
/* @__PURE__ */ jsx(Badge, { variant: "warning", children: "Inatteignable" }),
|
|
3707
|
+
" aucun ticket ne peut atteindre ce n\u0153ud aujourd'hui \u2014 voir les raisons sur sa carte."
|
|
3708
|
+
] })
|
|
3709
|
+
] })
|
|
3710
|
+
] })
|
|
3711
|
+
] });
|
|
3712
|
+
}
|
|
3713
|
+
var SHARED_PREFIX = "shared/";
|
|
3714
|
+
function useSharedPrompts() {
|
|
3715
|
+
const { appSlug } = useAppContext();
|
|
3716
|
+
const api = useAppApi();
|
|
3717
|
+
const [prompts, setPrompts] = useState([]);
|
|
3718
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
3719
|
+
const [error, setError] = useState(void 0);
|
|
3720
|
+
const clientRef = useRef(api);
|
|
3721
|
+
clientRef.current = api;
|
|
3722
|
+
const requestIdRef = useRef(0);
|
|
3723
|
+
const isMountedRef = useRef(true);
|
|
3724
|
+
const load = useCallback(async () => {
|
|
3725
|
+
const requestId = ++requestIdRef.current;
|
|
3726
|
+
setIsLoading(true);
|
|
3727
|
+
try {
|
|
3728
|
+
const catalogue = await clientRef.current.get(`/data/apps/${appSlug}/prompts`);
|
|
3729
|
+
if (requestId !== requestIdRef.current || !isMountedRef.current) return;
|
|
3730
|
+
setPrompts(catalogue.filter((entry) => entry.name.startsWith(SHARED_PREFIX)));
|
|
3731
|
+
setError(void 0);
|
|
3732
|
+
} catch (err) {
|
|
3733
|
+
if (requestId !== requestIdRef.current || !isMountedRef.current) return;
|
|
3734
|
+
setError(err);
|
|
3735
|
+
} finally {
|
|
3736
|
+
if (requestId === requestIdRef.current) setIsLoading(false);
|
|
3737
|
+
}
|
|
3738
|
+
}, [appSlug]);
|
|
3739
|
+
useEffect(() => {
|
|
3740
|
+
isMountedRef.current = true;
|
|
3741
|
+
void load();
|
|
3742
|
+
return () => {
|
|
3743
|
+
isMountedRef.current = false;
|
|
3744
|
+
requestIdRef.current += 1;
|
|
3745
|
+
};
|
|
3746
|
+
}, [load]);
|
|
3747
|
+
return { prompts, isLoading, error, refresh: load };
|
|
3748
|
+
}
|
|
3749
|
+
var PRODUCTION_LABEL = "production";
|
|
3750
|
+
var SHARED_PREFIX2 = "shared/";
|
|
3751
|
+
var SLUG_RE = /^[a-z0-9-]{1,64}$/;
|
|
3752
|
+
var SLUG_ERROR = "Le nom doit contenir 1 \xE0 64 minuscules, chiffres ou tirets.";
|
|
3753
|
+
function VersionsPanel({ name, canWrite, onClose }) {
|
|
3754
|
+
const { versions, error, promote, deleteVersion, refresh } = usePromptVersions(name);
|
|
3755
|
+
const [newContent, setNewContent] = useState("");
|
|
3756
|
+
const [isCreating, setIsCreating] = useState(false);
|
|
3757
|
+
const [createError, setCreateError] = useState(null);
|
|
3758
|
+
const [deletingVersion, setDeletingVersion] = useState(null);
|
|
3759
|
+
const [promotingVersion, setPromotingVersion] = useState(null);
|
|
3760
|
+
const [isComparing, setIsComparing] = useState(false);
|
|
3761
|
+
const [compareLeft, setCompareLeft] = useState(null);
|
|
3762
|
+
const [compareRight, setCompareRight] = useState(null);
|
|
3763
|
+
const newVersionId = useId();
|
|
3764
|
+
const api = useAppApi();
|
|
3765
|
+
const toast = useToast();
|
|
3766
|
+
const sorted = [...versions].sort((a, b) => b.version - a.version);
|
|
3767
|
+
const hasActiveVersion = versions.some((v) => v.labels.includes(PRODUCTION_LABEL));
|
|
3768
|
+
function openCompare() {
|
|
3769
|
+
const byVersionAsc = [...versions].sort((a, b) => a.version - b.version);
|
|
3770
|
+
setCompareLeft(byVersionAsc[0]?.version ?? null);
|
|
3771
|
+
setCompareRight(byVersionAsc[byVersionAsc.length - 1]?.version ?? null);
|
|
3772
|
+
setIsComparing(true);
|
|
3773
|
+
}
|
|
3774
|
+
const isPromotingRef = useRef(false);
|
|
3775
|
+
async function confirmPromote() {
|
|
3776
|
+
if (promotingVersion === null || isPromotingRef.current) return;
|
|
3777
|
+
isPromotingRef.current = true;
|
|
3778
|
+
const version = promotingVersion;
|
|
3779
|
+
try {
|
|
3780
|
+
await promote(version);
|
|
3781
|
+
toast({ title: `Version ${version} promue en production.`, variant: "success" });
|
|
3782
|
+
} catch (err) {
|
|
3783
|
+
toast({ title: "\xC9chec de la promotion", description: describeApiError(err), variant: "error" });
|
|
3784
|
+
} finally {
|
|
3785
|
+
isPromotingRef.current = false;
|
|
3786
|
+
setPromotingVersion(null);
|
|
3787
|
+
}
|
|
3788
|
+
}
|
|
3789
|
+
async function confirmDelete() {
|
|
3790
|
+
if (deletingVersion === null) return;
|
|
3791
|
+
const version = deletingVersion;
|
|
3792
|
+
try {
|
|
3793
|
+
await deleteVersion(version);
|
|
3794
|
+
toast({ title: `Version ${version} supprim\xE9e.`, variant: "success" });
|
|
3795
|
+
} catch (err) {
|
|
3796
|
+
toast({ title: "\xC9chec de la suppression", description: describeApiError(err), variant: "error" });
|
|
3797
|
+
} finally {
|
|
3798
|
+
setDeletingVersion(null);
|
|
3799
|
+
}
|
|
3800
|
+
}
|
|
3801
|
+
async function runCreateVersion() {
|
|
3802
|
+
setIsCreating(true);
|
|
3803
|
+
setCreateError(null);
|
|
3804
|
+
const payload = { name, content: newContent };
|
|
3805
|
+
try {
|
|
3806
|
+
await api.invoke(
|
|
3807
|
+
"create-shared-prompt-version",
|
|
3808
|
+
payload,
|
|
3809
|
+
{ idempotencyKey: idempotencyKeyFor("create-shared-prompt-version", payload) }
|
|
3810
|
+
);
|
|
3811
|
+
setNewContent("");
|
|
3812
|
+
await refresh();
|
|
3813
|
+
} catch (err) {
|
|
3814
|
+
setCreateError(describeInvokeError(err));
|
|
3815
|
+
} finally {
|
|
3816
|
+
setIsCreating(false);
|
|
3817
|
+
}
|
|
3818
|
+
}
|
|
3819
|
+
return /* @__PURE__ */ jsxs(SidePanel, { open: true, onClose, title: name, description: "Ressource commune \xE0 l'entreprise \u2014 toute nouvelle version s'applique \xE0 toutes les apps qui utilisent ce prompt.", children: [
|
|
3820
|
+
/* @__PURE__ */ jsxs("div", { "data-testid": "shared-prompt-versions", className: "flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto", children: [
|
|
3821
|
+
error !== void 0 && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: "Erreur lors du chargement des versions." }),
|
|
3822
|
+
versions.length > 0 && !hasActiveVersion && /* @__PURE__ */ jsx("p", { className: "rounded-md border border-status-warning/40 bg-status-warning/10 p-2 text-sm text-status-warning", children: "Aucune version active \u2014 aucune version ne porte le label \xAB production \xBB." }),
|
|
3823
|
+
versions.length >= 2 && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: openCompare, children: "Comparer" }) }),
|
|
3824
|
+
isComparing && compareLeft !== null && compareRight !== null && /* @__PURE__ */ jsx(
|
|
3825
|
+
VersionCompareView,
|
|
3826
|
+
{
|
|
3827
|
+
versions,
|
|
3828
|
+
leftVersion: compareLeft,
|
|
3829
|
+
rightVersion: compareRight,
|
|
3830
|
+
onSelectLeft: setCompareLeft,
|
|
3831
|
+
onSelectRight: setCompareRight
|
|
3832
|
+
}
|
|
3833
|
+
),
|
|
3834
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
3835
|
+
sorted.map((v) => /* @__PURE__ */ jsxs("div", { className: "rounded-md border p-3", children: [
|
|
3836
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
3837
|
+
/* @__PURE__ */ jsxs("div", { className: "text-sm font-medium", children: [
|
|
3838
|
+
"v",
|
|
3839
|
+
v.version,
|
|
3840
|
+
" ",
|
|
3841
|
+
v.label && /* @__PURE__ */ jsx(Badge, { variant: "brand", children: v.label })
|
|
3842
|
+
] }),
|
|
3843
|
+
canWrite && /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
|
|
3844
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => setPromotingVersion(v.version), children: "Promouvoir" }),
|
|
3845
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => setDeletingVersion(v.version), children: "Supprimer la version" })
|
|
3846
|
+
] })
|
|
3847
|
+
] }),
|
|
3848
|
+
/* @__PURE__ */ jsxs("p", { className: "mt-1 text-xs text-muted-foreground", children: [
|
|
3849
|
+
"Cr\xE9\xE9e le ",
|
|
3850
|
+
formatDate(v.createdAt)
|
|
3851
|
+
] }),
|
|
3852
|
+
/* @__PURE__ */ jsx("pre", { className: "mt-2 whitespace-pre-wrap text-xs text-muted-foreground", children: v.content })
|
|
3853
|
+
] }, v.version)),
|
|
3854
|
+
sorted.length === 0 && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Aucune version pour l'instant." })
|
|
3855
|
+
] }),
|
|
3856
|
+
canWrite && /* @__PURE__ */ jsxs("div", { className: "space-y-2 border-t pt-3", children: [
|
|
3857
|
+
/* @__PURE__ */ jsx("label", { htmlFor: newVersionId, className: "block text-sm font-medium", children: "Nouvelle version" }),
|
|
3858
|
+
/* @__PURE__ */ jsx(Textarea, { id: newVersionId, value: newContent, onChange: (e) => setNewContent(e.target.value), rows: 8 }),
|
|
3859
|
+
createError && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: createError }),
|
|
3860
|
+
/* @__PURE__ */ jsx(Button, { onClick: () => void runCreateVersion(), disabled: newContent.trim() === "" || isCreating, children: isCreating ? "Cr\xE9ation\u2026" : "Cr\xE9er la version" })
|
|
3861
|
+
] })
|
|
3862
|
+
] }),
|
|
3863
|
+
promotingVersion !== null && /* @__PURE__ */ jsx(
|
|
3864
|
+
ConfirmModal,
|
|
3865
|
+
{
|
|
3866
|
+
title: "Promouvoir cette version ?",
|
|
3867
|
+
description: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3868
|
+
"La v",
|
|
3869
|
+
promotingVersion,
|
|
3870
|
+
" de ",
|
|
3871
|
+
/* @__PURE__ */ jsx("code", { children: name }),
|
|
3872
|
+
" devient imm\xE9diatement le contenu actif en production \u2014 pour TOUTES les apps qui utilisent ce prompt commun, pas seulement celle-ci."
|
|
3873
|
+
] }),
|
|
3874
|
+
confirmLabel: "Promouvoir",
|
|
3875
|
+
busyLabel: "Promotion\u2026",
|
|
3876
|
+
onConfirm: confirmPromote,
|
|
3877
|
+
onCancel: () => setPromotingVersion(null)
|
|
3878
|
+
}
|
|
3879
|
+
),
|
|
3880
|
+
deletingVersion !== null && /* @__PURE__ */ jsx(
|
|
3881
|
+
ConfirmModal,
|
|
3882
|
+
{
|
|
3883
|
+
title: "Supprimer la version ?",
|
|
3884
|
+
description: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3885
|
+
"La version ",
|
|
3886
|
+
deletingVersion,
|
|
3887
|
+
" de ",
|
|
3888
|
+
/* @__PURE__ */ jsx("code", { children: name }),
|
|
3889
|
+
" sera supprim\xE9e d\xE9finitivement pour TOUTES les apps qui utilisent ce prompt commun. Impossible si elle porte le label \xAB production \xBB ou s'il s'agit de la derni\xE8re version restante."
|
|
3890
|
+
] }),
|
|
3891
|
+
confirmLabel: "Supprimer la version",
|
|
3892
|
+
onConfirm: confirmDelete,
|
|
3893
|
+
onCancel: () => setDeletingVersion(null)
|
|
3894
|
+
}
|
|
3895
|
+
)
|
|
3896
|
+
] });
|
|
3897
|
+
}
|
|
3898
|
+
function NewSharedPromptModal({ onClose, onCreated }) {
|
|
3899
|
+
const { appSlug } = useAppContext();
|
|
3900
|
+
const api = useAppApi();
|
|
3901
|
+
const [slug, setSlug] = useState("");
|
|
3902
|
+
const [content, setContent] = useState("");
|
|
3903
|
+
const [slugError, setSlugError] = useState("");
|
|
3904
|
+
const [error, setError] = useState(null);
|
|
3905
|
+
const [isCreating, setIsCreating] = useState(false);
|
|
3906
|
+
const nameId = useId();
|
|
3907
|
+
const contentId = useId();
|
|
3908
|
+
const name = `${SHARED_PREFIX2}${slug}`;
|
|
3909
|
+
function handleSlugChange(value) {
|
|
3910
|
+
setSlug(value);
|
|
3911
|
+
setSlugError(value && !SLUG_RE.test(value) ? SLUG_ERROR : "");
|
|
3912
|
+
}
|
|
3913
|
+
async function handleSubmit(event) {
|
|
3914
|
+
event.preventDefault();
|
|
3915
|
+
if (!SLUG_RE.test(slug)) {
|
|
3916
|
+
setSlugError(SLUG_ERROR);
|
|
3917
|
+
return;
|
|
3918
|
+
}
|
|
3919
|
+
if (!content.trim()) {
|
|
3920
|
+
setError("Le contenu est requis.");
|
|
3921
|
+
return;
|
|
3922
|
+
}
|
|
3923
|
+
setError(null);
|
|
3924
|
+
setIsCreating(true);
|
|
3925
|
+
const payload = { name, content };
|
|
3926
|
+
try {
|
|
3927
|
+
const result = await api.invoke(
|
|
3928
|
+
"create-shared-prompt-version",
|
|
3929
|
+
payload,
|
|
3930
|
+
{ idempotencyKey: idempotencyKeyFor("create-shared-prompt-version", payload) }
|
|
3931
|
+
);
|
|
3932
|
+
try {
|
|
3933
|
+
await api.post(`/data/apps/${appSlug}/prompts/promote`, {
|
|
3934
|
+
name,
|
|
3935
|
+
version: result.version,
|
|
3936
|
+
label: "production"
|
|
3937
|
+
});
|
|
3938
|
+
} catch {
|
|
3939
|
+
}
|
|
3940
|
+
onCreated(name);
|
|
3941
|
+
} catch (err) {
|
|
3942
|
+
setError(describeInvokeError(err));
|
|
3943
|
+
} finally {
|
|
3944
|
+
setIsCreating(false);
|
|
3945
|
+
}
|
|
3946
|
+
}
|
|
3947
|
+
return /* @__PURE__ */ jsx(Modal, { open: true, onClose, title: "Nouveau prompt partag\xE9", children: /* @__PURE__ */ jsxs("form", { className: "space-y-3", onSubmit: (e) => void handleSubmit(e), children: [
|
|
3948
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3949
|
+
/* @__PURE__ */ jsx("label", { htmlFor: nameId, className: "mb-1 block text-sm font-medium", children: "Nom" }),
|
|
3950
|
+
/* @__PURE__ */ jsx(Input, { id: nameId, value: slug, onChange: (e) => handleSlugChange(e.target.value), placeholder: "tone-of-voice" }),
|
|
3951
|
+
/* @__PURE__ */ jsxs("p", { className: "mt-1 text-xs text-muted-foreground", children: [
|
|
3952
|
+
"Nom final : ",
|
|
3953
|
+
/* @__PURE__ */ jsx("code", { children: slug ? name : `${SHARED_PREFIX2}<nom>` })
|
|
3954
|
+
] }),
|
|
3955
|
+
slugError && /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-destructive", children: slugError })
|
|
3956
|
+
] }),
|
|
3957
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3958
|
+
/* @__PURE__ */ jsx("label", { htmlFor: contentId, className: "mb-1 block text-sm font-medium", children: "Contenu" }),
|
|
3959
|
+
/* @__PURE__ */ jsx(Textarea, { id: contentId, value: content, onChange: (e) => setContent(e.target.value), rows: 8 })
|
|
3960
|
+
] }),
|
|
3961
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "La premi\xE8re version est activ\xE9e imm\xE9diatement (production)." }),
|
|
3962
|
+
error && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: error }),
|
|
3963
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
3964
|
+
/* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: onClose, disabled: isCreating, children: "Annuler" }),
|
|
3965
|
+
/* @__PURE__ */ jsx(Button, { type: "submit", disabled: isCreating, children: isCreating ? "Cr\xE9ation\u2026" : "Cr\xE9er" })
|
|
3966
|
+
] })
|
|
3967
|
+
] }) });
|
|
3968
|
+
}
|
|
3969
|
+
function SharedPromptsPage() {
|
|
3970
|
+
const { role } = useAppContext();
|
|
3971
|
+
const canWrite = canWriteForRole(role);
|
|
3972
|
+
const { prompts, isLoading, error, refresh } = useSharedPrompts();
|
|
3973
|
+
const [selected, setSelected] = useState(null);
|
|
3974
|
+
const [isCreateOpen, setIsCreateOpen] = useState(false);
|
|
3975
|
+
const columns = [
|
|
3976
|
+
{ key: "name", header: "Nom", cell: (row) => row.name },
|
|
3977
|
+
{
|
|
3978
|
+
key: "labels",
|
|
3979
|
+
header: "Labels",
|
|
3980
|
+
cell: (row) => row.labels.length > 0 ? row.labels.map((l) => /* @__PURE__ */ jsx(Badge, { children: l }, l)) : "\u2014"
|
|
3981
|
+
},
|
|
3982
|
+
{ key: "latestVersion", header: "Derni\xE8re version", align: "right", cell: (row) => `v${row.latestVersion}` }
|
|
3983
|
+
];
|
|
3984
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
3985
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-4", children: [
|
|
3986
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
3987
|
+
/* @__PURE__ */ jsx("h1", { className: "text-lg font-semibold", children: "Prompts partag\xE9s" }),
|
|
3988
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "La biblioth\xE8que des prompts \xAB shared/* \xBB et leur composition." })
|
|
3989
|
+
] }),
|
|
3990
|
+
canWrite && /* @__PURE__ */ jsx(Button, { onClick: () => setIsCreateOpen(true), children: "+ Nouveau prompt partag\xE9" })
|
|
3991
|
+
] }),
|
|
3992
|
+
/* @__PURE__ */ jsx("div", { className: "rounded-md border border-status-warning/40 bg-status-warning/10 p-3 text-sm text-status-warning", children: "Ressource commune \xE0 toute l'entreprise : sous D-LF il n'existe qu'un seul prompt Langfuse par nom \xAB shared/* \xBB, partag\xE9 par toutes les apps support. Modifier ou promouvoir une version ici change ce que TOUTES les apps utilisant ce prompt envoient \u2014 pas seulement celle-ci." }),
|
|
3993
|
+
/* @__PURE__ */ jsx(
|
|
3994
|
+
DataTable,
|
|
3995
|
+
{
|
|
3996
|
+
columns,
|
|
3997
|
+
rows: prompts,
|
|
3998
|
+
rowId: (row) => row.name,
|
|
3999
|
+
manual: true,
|
|
4000
|
+
loading: isLoading,
|
|
4001
|
+
onRowClick: (row) => setSelected(row.name),
|
|
4002
|
+
error: error ? /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-3", children: [
|
|
4003
|
+
"Erreur lors du chargement des prompts.",
|
|
4004
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => void refresh(), children: "R\xE9essayer" })
|
|
4005
|
+
] }) : void 0,
|
|
4006
|
+
empty: "Aucun prompt \xAB shared/* \xBB accessible depuis cette app."
|
|
4007
|
+
}
|
|
4008
|
+
),
|
|
4009
|
+
selected && /* @__PURE__ */ jsx(VersionsPanel, { name: selected, canWrite, onClose: () => setSelected(null) }),
|
|
4010
|
+
isCreateOpen && /* @__PURE__ */ jsx(
|
|
4011
|
+
NewSharedPromptModal,
|
|
4012
|
+
{
|
|
4013
|
+
onClose: () => setIsCreateOpen(false),
|
|
4014
|
+
onCreated: (name) => {
|
|
4015
|
+
setIsCreateOpen(false);
|
|
4016
|
+
void refresh();
|
|
4017
|
+
setSelected(name);
|
|
4018
|
+
}
|
|
4019
|
+
}
|
|
4020
|
+
)
|
|
4021
|
+
] });
|
|
4022
|
+
}
|
|
4023
|
+
|
|
4024
|
+
// src/ui/test/tag-origin.ts
|
|
4025
|
+
function str(value) {
|
|
4026
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
4027
|
+
}
|
|
4028
|
+
function tagOrigin(tag, settings) {
|
|
4029
|
+
if (!settings) return "classification";
|
|
4030
|
+
if (tag === str(settings.autoRepliedTag)) return "tag d'envoi";
|
|
4031
|
+
if (tag === str(settings.needsReviewTag)) return "tag de relecture";
|
|
4032
|
+
if (tag === str(settings.followupTag)) return "tag de suivi";
|
|
4033
|
+
if (tag === str(settings.escalationTag)) return "tag d'escalade";
|
|
4034
|
+
if (tag === str(settings.handledTag)) return "tag de traitement";
|
|
4035
|
+
if (tag === str(settings.unknownTag)) return "classification de repli";
|
|
4036
|
+
return "classification";
|
|
4037
|
+
}
|
|
4038
|
+
|
|
4039
|
+
// src/ui/test/verdict-summary.ts
|
|
4040
|
+
var COLLISION_GUARDRAILS = ["ticket_closed", "agent_replied", "diverged", "customer_email_missing", "run_deadline"];
|
|
4041
|
+
function base(result) {
|
|
4042
|
+
return { label: outcomeLabel(result.outcome), collisionHits: [], contentHits: [] };
|
|
4043
|
+
}
|
|
4044
|
+
function needsHumanSentence(result) {
|
|
4045
|
+
const verdict = result.verdict;
|
|
4046
|
+
if (!verdict || verdict.status !== "success") {
|
|
4047
|
+
const reason2 = verdict?.reason ? ` (${verdict.reason})` : "";
|
|
4048
|
+
return `L'\xE9valuation n'a pas abouti${reason2} : sans verdict exploitable, le graphe passe la main.`;
|
|
4049
|
+
}
|
|
4050
|
+
if (!isSendableVerdict(verdict.verdict)) {
|
|
4051
|
+
return `Le juge a r\xE9pondu \xAB ${verdict.verdict ?? "aucun verdict"} \xBB : ce verdict n'est pas envoyable, quelle que soit la confiance.`;
|
|
4052
|
+
}
|
|
4053
|
+
const confidencePct = verdict.confidence !== null ? `${Math.round(verdict.confidence * 100)} %` : "une confiance inconnue";
|
|
4054
|
+
return `Le juge a r\xE9pondu \xAB ${verdict.verdict} \xBB avec ${confidencePct} de confiance${verdict.reason ? ` : ${verdict.reason}` : "."}`;
|
|
4055
|
+
}
|
|
4056
|
+
function guardrailHoldSummary(result) {
|
|
4057
|
+
const collisionHits = result.guardrailHits.filter((hit) => COLLISION_GUARDRAILS.includes(hit));
|
|
4058
|
+
const contentHits = result.guardrailHits.filter((hit) => !COLLISION_GUARDRAILS.includes(hit));
|
|
4059
|
+
const sentence = collisionHits.length > 0 ? "Le contr\xF4le anti-collision, juste avant de poster, a bloqu\xE9 la r\xE9ponse : la conversation avait boug\xE9." : `${contentHits.length} garde-fou${contentHits.length > 1 ? "s" : ""} de contenu ${contentHits.length > 1 ? "ont" : "a"} bloqu\xE9 la r\xE9ponse avant l'envoi.`;
|
|
4060
|
+
return { sentence, collisionHits, contentHits };
|
|
4061
|
+
}
|
|
4062
|
+
function readySentence(result) {
|
|
4063
|
+
if (!result.verdict) {
|
|
4064
|
+
return "La r\xE9ponse est pr\xEAte pour l'extension. L'envoi n'a pas \xE9t\xE9 tent\xE9 : sans \xE9valuation, aucun verdict n'a \xE9t\xE9 produit, et l'envoi auto est impossible par construction.";
|
|
4065
|
+
}
|
|
4066
|
+
return "La r\xE9ponse est pr\xEAte pour l'extension. L'envoi automatique n'\xE9tait pas \xE9ligible.";
|
|
4067
|
+
}
|
|
4068
|
+
function describeVerdict(result) {
|
|
4069
|
+
if (result.error) {
|
|
4070
|
+
const failing = result.steps.find((step) => step.error);
|
|
4071
|
+
return {
|
|
4072
|
+
label: "Erreur technique",
|
|
4073
|
+
tone: "danger",
|
|
4074
|
+
sentence: failing ? `Le n\u0153ud \xAB ${NODE_LABELS[failing.node]} \xBB a lev\xE9 une erreur : ${result.error}` : `Le run a lev\xE9 une erreur : ${result.error}`,
|
|
4075
|
+
collisionHits: [],
|
|
4076
|
+
contentHits: []
|
|
4077
|
+
};
|
|
4078
|
+
}
|
|
4079
|
+
switch (result.outcome) {
|
|
4080
|
+
case "sent":
|
|
4081
|
+
return {
|
|
4082
|
+
...base(result),
|
|
4083
|
+
tone: "success",
|
|
4084
|
+
sentence: "La r\xE9ponse a pass\xE9 les garde-fous, l'autorisation et le contr\xF4le anti-collision : elle serait partie au client."
|
|
4085
|
+
};
|
|
4086
|
+
case "needs_human":
|
|
4087
|
+
return { ...base(result), tone: "warning", sentence: needsHumanSentence(result) };
|
|
4088
|
+
case "guardrail_hold":
|
|
4089
|
+
return { ...base(result), tone: "warning", ...guardrailHoldSummary(result) };
|
|
4090
|
+
case "ready":
|
|
4091
|
+
return { ...base(result), tone: "success", sentence: readySentence(result) };
|
|
4092
|
+
case "escalated":
|
|
4093
|
+
return { ...base(result), tone: "warning", sentence: "Le n\u0153ud d'escalade a pass\xE9 la main \xE0 un humain \u2014 aucune r\xE9ponse n'a \xE9t\xE9 r\xE9dig\xE9e." };
|
|
4094
|
+
case "triaged_only":
|
|
4095
|
+
return {
|
|
4096
|
+
...base(result),
|
|
4097
|
+
tone: "warning",
|
|
4098
|
+
sentence: "Ce profil n'a pas de n\u0153ud de r\xE9daction, ou le triage a pos\xE9 une classification de repli : le ticket est class\xE9, aucune r\xE9ponse n'est \xE9crite."
|
|
4099
|
+
};
|
|
4100
|
+
case "no_reply_needed":
|
|
4101
|
+
return {
|
|
4102
|
+
...base(result),
|
|
4103
|
+
tone: "success",
|
|
4104
|
+
sentence: "Le triage a lu le dernier message client comme une cl\xF4ture de la conversation : aucune r\xE9ponse n'est n\xE9cessaire, la r\xE9daction n'a pas \xE9t\xE9 appel\xE9e."
|
|
4105
|
+
};
|
|
4106
|
+
case "awaiting_approval":
|
|
4107
|
+
return { ...base(result), tone: "warning", sentence: "Une action propos\xE9e n'est pas autoris\xE9e en automatique : le run attend une validation humaine." };
|
|
4108
|
+
case "failed":
|
|
4109
|
+
return { ...base(result), tone: "danger", sentence: "La lecture de la conversation Gorgias a \xE9chou\xE9 : le graphe n'a rien pu faire de ce ticket." };
|
|
4110
|
+
default:
|
|
4111
|
+
return { ...base(result), tone: "neutral", sentence: "Le run s'est termin\xE9 sans issue d\xE9clar\xE9e." };
|
|
4112
|
+
}
|
|
4113
|
+
}
|
|
4114
|
+
function totalDurationMs(result) {
|
|
4115
|
+
return result.steps.reduce((total, step) => total + step.durationMs, 0);
|
|
4116
|
+
}
|
|
4117
|
+
var VERDICT_BADGE_VARIANT = {
|
|
4118
|
+
success: "success",
|
|
4119
|
+
warning: "warning",
|
|
4120
|
+
danger: "danger",
|
|
4121
|
+
neutral: "neutral"
|
|
4122
|
+
};
|
|
4123
|
+
function DryRunResultView({ result, langfuseConfig, knownTags, tagSettings }) {
|
|
4124
|
+
const verdict = describeVerdict(result);
|
|
4125
|
+
const triageStep = result.steps.find((step) => step.node === "triage");
|
|
4126
|
+
const triageTag = triageStep?.patch.classification?.category;
|
|
4127
|
+
const isFallbackClassification = triageStep?.patch.classification?.isFallback === true;
|
|
4128
|
+
const unknownTag = Boolean(triageTag) && !isFallbackClassification && knownTags !== void 0 && !knownTags.includes(triageTag);
|
|
4129
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-4 text-sm", children: [
|
|
4130
|
+
/* @__PURE__ */ jsxs("div", { className: "rounded-md border p-4", "data-testid": "verdict-banner", children: [
|
|
4131
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-baseline gap-x-3 gap-y-1", children: [
|
|
4132
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs uppercase tracking-wide text-muted-foreground", children: "Issue du run" }),
|
|
4133
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
|
|
4134
|
+
totalDurationMs(result),
|
|
4135
|
+
" ms"
|
|
4136
|
+
] })
|
|
4137
|
+
] }),
|
|
4138
|
+
/* @__PURE__ */ jsxs("div", { className: "mt-1 flex flex-wrap items-center gap-3", children: [
|
|
4139
|
+
/* @__PURE__ */ jsx(Badge, { variant: VERDICT_BADGE_VARIANT[verdict.tone], children: verdict.label }),
|
|
4140
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs uppercase tracking-wide text-muted-foreground", children: "Chemin d'envoi exerc\xE9" }),
|
|
4141
|
+
/* @__PURE__ */ jsx(Badge, { variant: result.sendSeamExercised ? "success" : "neutral", children: result.sendSeamExercised ? "oui" : "non" })
|
|
4142
|
+
] }),
|
|
4143
|
+
/* @__PURE__ */ jsx("p", { className: "mt-1.5", children: verdict.sentence }),
|
|
4144
|
+
verdict.collisionHits.length > 0 && /* @__PURE__ */ jsxs("div", { className: "mt-2", children: [
|
|
4145
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs font-medium text-muted-foreground", children: "Contr\xF4les anti-collision d\xE9clench\xE9s" }),
|
|
4146
|
+
/* @__PURE__ */ jsx("div", { className: "mt-1 flex flex-wrap gap-1", children: verdict.collisionHits.map((hit) => /* @__PURE__ */ jsx(Badge, { variant: "warning", children: hit }, hit)) })
|
|
4147
|
+
] }),
|
|
4148
|
+
verdict.contentHits.length > 0 && /* @__PURE__ */ jsxs("div", { className: "mt-2", children: [
|
|
4149
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs font-medium text-muted-foreground", children: "R\xE8gles de contenu d\xE9clench\xE9es" }),
|
|
4150
|
+
/* @__PURE__ */ jsx("div", { className: "mt-1 flex flex-wrap gap-1", children: verdict.contentHits.map((hit) => /* @__PURE__ */ jsx(Badge, { variant: "warning", children: hit }, hit)) })
|
|
4151
|
+
] })
|
|
4152
|
+
] }),
|
|
4153
|
+
result.error && /* @__PURE__ */ jsxs("div", { className: "rounded-md bg-destructive/10 p-3 text-destructive", children: [
|
|
4154
|
+
"Erreur d'ex\xE9cution : ",
|
|
4155
|
+
result.error
|
|
4156
|
+
] }),
|
|
4157
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
4158
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "N\u0153uds ex\xE9cut\xE9s" }),
|
|
4159
|
+
/* @__PURE__ */ jsx("ul", { className: "space-y-1", children: result.steps.map((step, i) => /* @__PURE__ */ jsxs("li", { className: "flex items-center justify-between gap-3", children: [
|
|
4160
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
4161
|
+
NODE_LABELS[step.node],
|
|
4162
|
+
" (",
|
|
4163
|
+
step.node,
|
|
4164
|
+
")",
|
|
4165
|
+
step.node === "triage" && unknownTag && /* @__PURE__ */ jsx("span", { className: "ml-2 text-xs text-status-warning", children: "\u2014 ce tag ne correspond \xE0 aucune cat\xE9gorie configur\xE9e" })
|
|
4166
|
+
] }),
|
|
4167
|
+
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2 text-xs text-muted-foreground", children: [
|
|
4168
|
+
step.durationMs,
|
|
4169
|
+
" ms",
|
|
4170
|
+
step.error && /* @__PURE__ */ jsx(Badge, { variant: "danger", children: step.error })
|
|
4171
|
+
] })
|
|
4172
|
+
] }, i)) })
|
|
4173
|
+
] }),
|
|
4174
|
+
result.skipped.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
|
|
4175
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "N\u0153uds non atteints" }),
|
|
4176
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1", children: result.skipped.map((node) => /* @__PURE__ */ jsx(Badge, { variant: "outline", children: NODE_LABELS[node] }, node)) })
|
|
4177
|
+
] }),
|
|
4178
|
+
result.completions.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
|
|
4179
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Appels LLM" }),
|
|
4180
|
+
/* @__PURE__ */ jsx("div", { className: "space-y-2", children: result.completions.map((c, i) => /* @__PURE__ */ jsxs("div", { className: "rounded-md border p-3", children: [
|
|
4181
|
+
/* @__PURE__ */ jsxs("div", { className: "mb-1 flex flex-wrap items-center gap-2", children: [
|
|
4182
|
+
/* @__PURE__ */ jsx(Badge, { children: c.label }),
|
|
4183
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: c.model }),
|
|
4184
|
+
/* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground", children: [
|
|
4185
|
+
c.durationMs,
|
|
4186
|
+
" ms"
|
|
4187
|
+
] }),
|
|
4188
|
+
c.traceId && /* @__PURE__ */ jsx(LangfuseTraceLink, { traceId: c.traceId, config: langfuseConfig, label: "Trace" })
|
|
4189
|
+
] }),
|
|
4190
|
+
c.error ? /* @__PURE__ */ jsx("p", { className: "text-destructive", children: c.error }) : /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap", children: c.text })
|
|
4191
|
+
] }, i)) })
|
|
4192
|
+
] }),
|
|
4193
|
+
result.draft?.text && /* @__PURE__ */ jsxs("div", { children: [
|
|
4194
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Brouillon" }),
|
|
4195
|
+
/* @__PURE__ */ jsx("pre", { className: "whitespace-pre-wrap rounded-md border p-3 text-xs", children: result.draft.text })
|
|
4196
|
+
] }),
|
|
4197
|
+
result.verdict && /* @__PURE__ */ jsxs("div", { children: [
|
|
4198
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Verdict" }),
|
|
4199
|
+
/* @__PURE__ */ jsxs("p", { children: [
|
|
4200
|
+
result.verdict.verdict ?? "\u2014",
|
|
4201
|
+
" (",
|
|
4202
|
+
result.verdict.status,
|
|
4203
|
+
") \u2014 ",
|
|
4204
|
+
result.verdict.reason
|
|
4205
|
+
] })
|
|
4206
|
+
] }),
|
|
4207
|
+
result.guardrailHits.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
|
|
4208
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Garde-fous d\xE9clench\xE9s" }),
|
|
4209
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1", children: result.guardrailHits.map((hit, i) => /* @__PURE__ */ jsx(Badge, { variant: "warning", children: hit }, `${hit}-${i}`)) })
|
|
4210
|
+
] }),
|
|
4211
|
+
/* @__PURE__ */ jsxs("div", { className: "rounded-md border border-dashed p-4", children: [
|
|
4212
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Ce qui n'a pas eu lieu" }),
|
|
4213
|
+
/* @__PURE__ */ jsxs("p", { className: "mt-1.5 text-sm", children: [
|
|
4214
|
+
"Ce run n'a rien \xE9crit : aucun tag pos\xE9, aucune r\xE9ponse publi\xE9e, aucun job cr\xE9\xE9.",
|
|
4215
|
+
result.wouldHaveTagged.length > 0 || result.wouldHaveReplied ? " Voici ce qu'il aurait appliqu\xE9." : " Il n'aurait rien appliqu\xE9 non plus."
|
|
4216
|
+
] }),
|
|
4217
|
+
result.wouldHaveTagged.length > 0 && /* @__PURE__ */ jsx("ul", { className: "mt-3 space-y-1", children: result.wouldHaveTagged.map((tag) => /* @__PURE__ */ jsxs("li", { className: "flex flex-wrap items-baseline gap-x-2 gap-y-0.5", children: [
|
|
4218
|
+
/* @__PURE__ */ jsx("code", { className: "rounded bg-muted px-1.5 py-0.5 text-xs", children: tag }),
|
|
4219
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: tagOrigin(tag, tagSettings) })
|
|
4220
|
+
] }, tag)) }),
|
|
4221
|
+
result.wouldHaveReplied && /* @__PURE__ */ jsxs("div", { className: "mt-3", children: [
|
|
4222
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs font-medium text-muted-foreground", children: "Et cette r\xE9ponse serait partie au client" }),
|
|
4223
|
+
result.wouldHaveReplied.subject && /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
|
|
4224
|
+
"Objet : ",
|
|
4225
|
+
result.wouldHaveReplied.subject
|
|
4226
|
+
] }),
|
|
4227
|
+
/* @__PURE__ */ jsx("pre", { className: "mt-1 whitespace-pre-wrap rounded-md border p-3 text-xs", children: result.wouldHaveReplied.body })
|
|
4228
|
+
] })
|
|
4229
|
+
] })
|
|
4230
|
+
] });
|
|
4231
|
+
}
|
|
4232
|
+
var TRI_STATE_OPTIONS = [
|
|
4233
|
+
{ value: "", label: "R\xE9glages actuels" },
|
|
4234
|
+
{ value: "on", label: "Forcer actif" },
|
|
4235
|
+
{ value: "off", label: "Forcer inactif" }
|
|
4236
|
+
];
|
|
4237
|
+
function triStateToOverride(value) {
|
|
4238
|
+
if (value === "on") return true;
|
|
4239
|
+
if (value === "off") return false;
|
|
4240
|
+
return void 0;
|
|
4241
|
+
}
|
|
4242
|
+
function OverrideSelect({ label, value, onChange }) {
|
|
4243
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
4244
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 block text-xs font-medium text-muted-foreground", children: label }),
|
|
4245
|
+
/* @__PURE__ */ jsx(
|
|
4246
|
+
Select,
|
|
4247
|
+
{
|
|
4248
|
+
"aria-label": label,
|
|
4249
|
+
items: TRI_STATE_OPTIONS,
|
|
4250
|
+
value,
|
|
4251
|
+
onValueChange: (next) => onChange(next)
|
|
4252
|
+
}
|
|
4253
|
+
)
|
|
4254
|
+
] });
|
|
4255
|
+
}
|
|
4256
|
+
function describeOverrides(overrides) {
|
|
4257
|
+
const parts = [];
|
|
4258
|
+
if (overrides.evaluate !== void 0) parts.push(`n\u0153ud \xE9valuation forc\xE9 ${overrides.evaluate ? "actif" : "inactif"}`);
|
|
4259
|
+
if (overrides.revise !== void 0) parts.push(`n\u0153ud r\xE9vision forc\xE9 ${overrides.revise ? "actif" : "inactif"}`);
|
|
4260
|
+
if (overrides.guardrails !== void 0) parts.push(`garde-fous forc\xE9s ${overrides.guardrails ? "actifs" : "inactifs"}`);
|
|
4261
|
+
if (overrides.autoSend) parts.push("envoi automatique forc\xE9");
|
|
4262
|
+
return parts.length > 0 ? `R\xE9sultat obtenu avec : ${parts.join(", ")}.` : "R\xE9sultat obtenu avec les r\xE9glages actuels (aucun for\xE7age).";
|
|
4263
|
+
}
|
|
4264
|
+
function SingleTicketTab({ langfuseConfig, agents, categories, knownTags, tagSettings }) {
|
|
4265
|
+
const api = useAppApi();
|
|
4266
|
+
const [ticketId, setTicketId] = useState("");
|
|
4267
|
+
const [agentId, setAgentId] = useState("");
|
|
4268
|
+
const [categoryId, setCategoryId] = useState("");
|
|
4269
|
+
const [evaluateOverride, setEvaluateOverride] = useState("");
|
|
4270
|
+
const [reviseOverride, setReviseOverride] = useState("");
|
|
4271
|
+
const [guardrailsOverride, setGuardrailsOverride] = useState("");
|
|
4272
|
+
const [autoSendOverride, setAutoSendOverride] = useState(false);
|
|
4273
|
+
const [isRunning, setIsRunning] = useState(false);
|
|
4274
|
+
const [error, setError] = useState(null);
|
|
4275
|
+
const [result, setResult] = useState(null);
|
|
4276
|
+
const [resultOverrides, setResultOverrides] = useState(null);
|
|
4277
|
+
const ticketIdInputId = useId();
|
|
4278
|
+
const agentOptions = [{ value: "", label: "Agent du profil (d\xE9faut)" }, ...agents.map((a) => ({ value: a.id, label: a.name }))];
|
|
4279
|
+
const categoryOptions = [{ value: "", label: "Cat\xE9gorie du triage (d\xE9faut)" }, ...categories.map((c) => ({ value: c.id, label: c.name }))];
|
|
4280
|
+
async function run() {
|
|
4281
|
+
setIsRunning(true);
|
|
4282
|
+
setError(null);
|
|
4283
|
+
setResult(null);
|
|
4284
|
+
setResultOverrides(null);
|
|
4285
|
+
const overrides = {
|
|
4286
|
+
...triStateToOverride(evaluateOverride) !== void 0 ? { evaluate: triStateToOverride(evaluateOverride) } : {},
|
|
4287
|
+
...triStateToOverride(reviseOverride) !== void 0 ? { revise: triStateToOverride(reviseOverride) } : {},
|
|
4288
|
+
...triStateToOverride(guardrailsOverride) !== void 0 ? { guardrails: triStateToOverride(guardrailsOverride) } : {},
|
|
4289
|
+
...autoSendOverride ? { autoSend: true } : {}
|
|
4290
|
+
};
|
|
4291
|
+
const payload = {
|
|
4292
|
+
ticketId: ticketId.trim(),
|
|
4293
|
+
...agentId.trim() ? { agentId: agentId.trim() } : {},
|
|
4294
|
+
...categoryId.trim() ? { categoryId: categoryId.trim() } : {},
|
|
4295
|
+
...Object.keys(overrides).length > 0 ? { overrides } : {}
|
|
4296
|
+
};
|
|
4297
|
+
try {
|
|
4298
|
+
const response = await api.invoke(
|
|
4299
|
+
"graph-dry-run",
|
|
4300
|
+
payload,
|
|
4301
|
+
{ idempotencyKey: idempotencyKeyFor("graph-dry-run", payload) }
|
|
4302
|
+
);
|
|
4303
|
+
setResult(response);
|
|
4304
|
+
setResultOverrides(overrides);
|
|
4305
|
+
} catch (err) {
|
|
4306
|
+
setError(describeInvokeError(err));
|
|
4307
|
+
} finally {
|
|
4308
|
+
setIsRunning(false);
|
|
4309
|
+
}
|
|
4310
|
+
}
|
|
4311
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
4312
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Rejoue le graphe complet pour UN ticket, sans jamais r\xE9pondre, taguer ni \xE9crire de record (\xA70). Les n\u0153uds forc\xE9s \xAB inactif \xBB ou \xAB actif \xBB ne s'appliquent qu'\xE0 cette ex\xE9cution \u2014 les r\xE9glages de l'app ne changent pas." }),
|
|
4313
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-3 sm:grid-cols-3", children: [
|
|
4314
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
4315
|
+
/* @__PURE__ */ jsx("label", { htmlFor: ticketIdInputId, className: "mb-1 block text-sm font-medium", children: "ID du ticket" }),
|
|
4316
|
+
/* @__PURE__ */ jsx(Input, { id: ticketIdInputId, value: ticketId, onChange: (e) => setTicketId(e.target.value), placeholder: "12345" })
|
|
4317
|
+
] }),
|
|
4318
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
4319
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 block text-sm font-medium", children: "Agent (optionnel)" }),
|
|
4320
|
+
/* @__PURE__ */ jsx(Select, { "aria-label": "Agent (optionnel)", items: agentOptions, value: agentId, onValueChange: setAgentId, placeholder: "Agent du profil (d\xE9faut)" })
|
|
4321
|
+
] }),
|
|
4322
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
4323
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 block text-sm font-medium", children: "Cat\xE9gorie forc\xE9e (optionnel)" }),
|
|
4324
|
+
/* @__PURE__ */ jsx(Select, { "aria-label": "Cat\xE9gorie forc\xE9e (optionnel)", items: categoryOptions, value: categoryId, onValueChange: setCategoryId, placeholder: "Cat\xE9gorie du triage (d\xE9faut)" })
|
|
4325
|
+
] })
|
|
4326
|
+
] }),
|
|
4327
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-3 sm:grid-cols-4", children: [
|
|
4328
|
+
/* @__PURE__ */ jsx(OverrideSelect, { label: "N\u0153ud \xE9valuation", value: evaluateOverride, onChange: setEvaluateOverride }),
|
|
4329
|
+
/* @__PURE__ */ jsx(OverrideSelect, { label: "N\u0153ud r\xE9vision", value: reviseOverride, onChange: setReviseOverride }),
|
|
4330
|
+
/* @__PURE__ */ jsx(OverrideSelect, { label: "Garde-fous", value: guardrailsOverride, onChange: setGuardrailsOverride }),
|
|
4331
|
+
/* @__PURE__ */ jsx("div", { className: "mb-1 text-xs font-medium text-muted-foreground", children: /* @__PURE__ */ jsx(
|
|
4332
|
+
Checkbox,
|
|
4333
|
+
{
|
|
4334
|
+
label: "Forcer l'envoi automatique (n\xE9cessite senderEmail)",
|
|
4335
|
+
checked: autoSendOverride,
|
|
4336
|
+
onCheckedChange: setAutoSendOverride
|
|
4337
|
+
}
|
|
4338
|
+
) })
|
|
4339
|
+
] }),
|
|
4340
|
+
/* @__PURE__ */ jsx(Button, { onClick: () => void run(), disabled: ticketId.trim() === "" || isRunning, children: isRunning ? "Test en cours\u2026" : "Lancer le test" }),
|
|
4341
|
+
error && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: error }),
|
|
4342
|
+
result && /* @__PURE__ */ jsxs("div", { className: "rounded-md border p-4", children: [
|
|
4343
|
+
/* @__PURE__ */ jsx("p", { className: "mb-3 text-xs font-medium text-muted-foreground", "data-testid": "single-ticket-result-overrides", children: describeOverrides(resultOverrides ?? {}) }),
|
|
4344
|
+
/* @__PURE__ */ jsx(DryRunResultView, { result, langfuseConfig, knownTags, tagSettings })
|
|
4345
|
+
] })
|
|
4346
|
+
] });
|
|
4347
|
+
}
|
|
4348
|
+
function BenchTab({ langfuseConfig, agents, knownTags, tagSettings }) {
|
|
4349
|
+
const api = useAppApi();
|
|
4350
|
+
const [viewId, setViewId] = useState("");
|
|
4351
|
+
const [ticketIds, setTicketIds] = useState("");
|
|
4352
|
+
const [agentId, setAgentId] = useState("");
|
|
4353
|
+
const [limit, setLimit] = useState("");
|
|
4354
|
+
const [isRunning, setIsRunning] = useState(false);
|
|
4355
|
+
const [error, setError] = useState(null);
|
|
4356
|
+
const [response, setResponse] = useState(null);
|
|
4357
|
+
const [selected, setSelected] = useState(null);
|
|
4358
|
+
const viewIdInputId = useId();
|
|
4359
|
+
const ticketIdsInputId = useId();
|
|
4360
|
+
const limitInputId = useId();
|
|
4361
|
+
const agentOptions = [{ value: "", label: "Chaque ticket, agent r\xE9el de sa cat\xE9gorie" }, ...agents.map((a) => ({ value: a.id, label: a.name }))];
|
|
4362
|
+
async function run() {
|
|
4363
|
+
setIsRunning(true);
|
|
4364
|
+
setError(null);
|
|
4365
|
+
setResponse(null);
|
|
4366
|
+
const parsedIds = ticketIds.split(",").map((id) => id.trim()).filter(Boolean);
|
|
4367
|
+
const parsedLimit = Number(limit);
|
|
4368
|
+
const payload = {
|
|
4369
|
+
...viewId.trim() ? { viewId: viewId.trim() } : {},
|
|
4370
|
+
...parsedIds.length > 0 ? { ticketIds: parsedIds } : {},
|
|
4371
|
+
...agentId.trim() ? { agentId: agentId.trim() } : {},
|
|
4372
|
+
...limit.trim() !== "" && Number.isFinite(parsedLimit) ? { limit: parsedLimit } : {}
|
|
4373
|
+
};
|
|
4374
|
+
try {
|
|
4375
|
+
const result = await api.invoke(
|
|
4376
|
+
"test-agents",
|
|
4377
|
+
payload,
|
|
4378
|
+
{ idempotencyKey: idempotencyKeyFor("test-agents", payload) }
|
|
4379
|
+
);
|
|
4380
|
+
setResponse(result);
|
|
4381
|
+
} catch (err) {
|
|
4382
|
+
setError(describeInvokeError(err));
|
|
4383
|
+
} finally {
|
|
4384
|
+
setIsRunning(false);
|
|
4385
|
+
}
|
|
4386
|
+
}
|
|
4387
|
+
const columns = [
|
|
4388
|
+
{ key: "ticketId", header: "Ticket", cell: (row) => row.ticketId },
|
|
4389
|
+
{ key: "outcome", header: "Issue", cell: (row) => /* @__PURE__ */ jsx(Badge, { variant: row.outcome === "sent" ? "success" : "neutral", children: outcomeLabel(row.outcome) }) },
|
|
4390
|
+
{ key: "guardrails", header: "Garde-fous", cell: (row) => row.guardrailHits.length > 0 ? row.guardrailHits.map(guardrailHitLabel).join(", ") : "\u2014" },
|
|
4391
|
+
{ key: "completions", header: "Appels LLM", align: "right", cell: (row) => String(row.completions.length) },
|
|
4392
|
+
{ key: "error", header: "Erreur", cell: (row) => row.error ? /* @__PURE__ */ jsx(Badge, { variant: "danger", children: row.error }) : "\u2014" }
|
|
4393
|
+
];
|
|
4394
|
+
const canSubmit = (viewId.trim() !== "" || ticketIds.trim() !== "") && !isRunning;
|
|
4395
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
|
|
4396
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Rejoue le graphe complet, sans \xE9criture, sur plusieurs tickets d'une vue Gorgias ou d'une liste d'ids \u2014 aucune de leurs cat\xE9gories n'est r\xE9ellement lue pour l'envoi automatique : le banc force \xAB Envoi auto \xBB actif pour chaque ticket afin d'observer le chemin complet (voir le bandeau ci-dessous)." }),
|
|
4397
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-3 sm:grid-cols-4", children: [
|
|
4398
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
4399
|
+
/* @__PURE__ */ jsx("label", { htmlFor: viewIdInputId, className: "mb-1 block text-sm font-medium", children: "Vue Gorgias (id)" }),
|
|
4400
|
+
/* @__PURE__ */ jsx(Input, { id: viewIdInputId, value: viewId, onChange: (e) => setViewId(e.target.value) })
|
|
4401
|
+
] }),
|
|
4402
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
4403
|
+
/* @__PURE__ */ jsx("label", { htmlFor: ticketIdsInputId, className: "mb-1 block text-sm font-medium", children: "Ou ids de tickets (s\xE9par\xE9s par une virgule)" }),
|
|
4404
|
+
/* @__PURE__ */ jsx(Input, { id: ticketIdsInputId, value: ticketIds, onChange: (e) => setTicketIds(e.target.value) })
|
|
4405
|
+
] }),
|
|
4406
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
4407
|
+
/* @__PURE__ */ jsx("p", { className: "mb-1 block text-sm font-medium", children: "Agent (optionnel)" }),
|
|
4408
|
+
/* @__PURE__ */ jsx(Select, { "aria-label": "Agent (optionnel)", items: agentOptions, value: agentId, onValueChange: setAgentId, placeholder: "Chaque ticket, agent r\xE9el de sa cat\xE9gorie" })
|
|
4409
|
+
] }),
|
|
4410
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
4411
|
+
/* @__PURE__ */ jsx("label", { htmlFor: limitInputId, className: "mb-1 block text-sm font-medium", children: "Limite (d\xE9faut 20, max 100)" }),
|
|
4412
|
+
/* @__PURE__ */ jsx(Input, { id: limitInputId, type: "number", value: limit, onChange: (e) => setLimit(e.target.value) })
|
|
4413
|
+
] })
|
|
4414
|
+
] }),
|
|
4415
|
+
/* @__PURE__ */ jsx(Button, { onClick: () => void run(), disabled: !canSubmit, children: isRunning ? "Banc en cours\u2026" : "Lancer le banc" }),
|
|
4416
|
+
error && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: error }),
|
|
4417
|
+
response && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4418
|
+
/* @__PURE__ */ jsx("div", { className: "rounded-md border border-status-warning/40 bg-status-warning/10 p-3 text-sm text-status-warning", children: "Envoi automatique forc\xE9 pour ce banc : chaque ticket est \xE9valu\xE9 comme si sa cat\xE9gorie avait \xAB Envoi auto \xBB activ\xE9, quel que soit son r\xE9glage r\xE9el \u2014 voir la colonne Issue pour ce que le graphe aurait fait dans ce cas." }),
|
|
4419
|
+
/* @__PURE__ */ jsx(
|
|
4420
|
+
DataTable,
|
|
4421
|
+
{
|
|
4422
|
+
columns,
|
|
4423
|
+
rows: response.results,
|
|
4424
|
+
rowId: (row) => row.ticketId,
|
|
4425
|
+
manual: true,
|
|
4426
|
+
onRowClick: (row) => setSelected(row),
|
|
4427
|
+
empty: "Aucun ticket dans cette fen\xEAtre."
|
|
4428
|
+
}
|
|
4429
|
+
)
|
|
4430
|
+
] }),
|
|
4431
|
+
selected && /* @__PURE__ */ jsx(SidePanel, { open: true, onClose: () => setSelected(null), title: `Ticket ${selected.ticketId}`, children: /* @__PURE__ */ jsx("div", { "data-testid": "dry-run-detail", children: /* @__PURE__ */ jsx(DryRunResultView, { result: selected, langfuseConfig, knownTags, tagSettings }) }) })
|
|
4432
|
+
] });
|
|
4433
|
+
}
|
|
4434
|
+
function TestTabs() {
|
|
4435
|
+
const { config: langfuseConfig } = useLangfuseConfig();
|
|
4436
|
+
const { settings } = useAppSettings();
|
|
4437
|
+
const { rows: allAgents } = useRecordList("agent", { limit: 500 }, toAgent);
|
|
4438
|
+
const { rows: categories } = useRecordList("category", { limit: 500 }, toCategory);
|
|
4439
|
+
const agents = useMemo(() => allAgents.filter((agent) => agent.status !== "archived"), [allAgents]);
|
|
4440
|
+
const knownTags = useMemo(() => categories.map((category) => category.tagName), [categories]);
|
|
4441
|
+
return /* @__PURE__ */ jsxs(Tabs, { defaultValue: "single", children: [
|
|
4442
|
+
/* @__PURE__ */ jsxs(TabsList, { children: [
|
|
4443
|
+
/* @__PURE__ */ jsx(TabsTrigger, { value: "single", children: "Test unitaire" }),
|
|
4444
|
+
/* @__PURE__ */ jsx(TabsTrigger, { value: "bench", children: "Banc d'essai" })
|
|
4445
|
+
] }),
|
|
4446
|
+
/* @__PURE__ */ jsx(TabsContent, { value: "single", children: /* @__PURE__ */ jsx(SingleTicketTab, { langfuseConfig, agents, categories, knownTags, tagSettings: settings }) }),
|
|
4447
|
+
/* @__PURE__ */ jsx(TabsContent, { value: "bench", children: /* @__PURE__ */ jsx(BenchTab, { langfuseConfig, agents, knownTags, tagSettings: settings }) })
|
|
4448
|
+
] });
|
|
4449
|
+
}
|
|
4450
|
+
function TestPage() {
|
|
4451
|
+
const { role } = useAppContext();
|
|
4452
|
+
const canRun = canWriteForRole(role);
|
|
4453
|
+
return /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
|
|
4454
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
4455
|
+
/* @__PURE__ */ jsx("h1", { className: "text-lg font-semibold", children: "Banc de test" }),
|
|
4456
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Rejoue le graphe sans jamais agir sur un vrai ticket (\xA70)." })
|
|
4457
|
+
] }),
|
|
4458
|
+
!canRun ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Acc\xE8s en lecture seule \u2014 lancer un test n\xE9cessite le r\xF4le EDITOR (chaque ex\xE9cution consomme du budget LLM)." }) : /* @__PURE__ */ jsx(TestTabs, {})
|
|
4459
|
+
] });
|
|
4460
|
+
}
|
|
4461
|
+
|
|
4462
|
+
export { AgentsPage, CategoriesPage, CorrectionsPage, DashboardPage, EscalationsPage, GraphCanvasPage, PipelinePage, SettingsPage, SharedPromptsPage, TestPage, TicketsPage };
|
|
4463
|
+
//# sourceMappingURL=index.js.map
|
|
4464
|
+
//# sourceMappingURL=index.js.map
|