@apotech-os/support-kit 3.0.1 → 3.1.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/dist/ui/index.cjs CHANGED
@@ -60,6 +60,7 @@ function toTriageDecision(record) {
60
60
  return {
61
61
  id: record.id,
62
62
  ticketId: data.ticketId ?? "",
63
+ ticketUrl: data.ticketUrl ?? null,
63
64
  decidedAt: data.decidedAt ?? null,
64
65
  categoryId: data.categoryId ?? null,
65
66
  tag: data.tag ?? null,
@@ -504,6 +505,29 @@ function DashboardPage() {
504
505
  ] })
505
506
  ] });
506
507
  }
508
+ function isHttpUrl(url) {
509
+ try {
510
+ const { protocol } = new URL(url);
511
+ return protocol === "http:" || protocol === "https:";
512
+ } catch {
513
+ return false;
514
+ }
515
+ }
516
+ function TicketLink({ ticketId, url, label }) {
517
+ if (!url || !isHttpUrl(url)) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: label ?? ticketId });
518
+ return /* @__PURE__ */ jsxRuntime.jsx(
519
+ uiSdk.Link,
520
+ {
521
+ href: url,
522
+ target: "_blank",
523
+ rel: "noopener noreferrer",
524
+ className: "font-medium",
525
+ title: "Ouvrir le ticket dans Gorgias",
526
+ onClick: (event) => event.stopPropagation(),
527
+ children: label ?? ticketId
528
+ }
529
+ );
530
+ }
507
531
  var UNCONFIGURED = { baseUrl: null, projectId: null };
508
532
  function useLangfuseConfig() {
509
533
  const { appSlug } = uiSdk.useAppContext();
@@ -720,6 +744,7 @@ function DetailPanel({
720
744
  onClose
721
745
  }) {
722
746
  return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.SidePanel, { open: true, onClose, title: `Ticket ${decision.ticketId}`, description: categoryName, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 text-sm", children: [
747
+ decision.ticketUrl && /* @__PURE__ */ jsxRuntime.jsx("p", { children: /* @__PURE__ */ jsxRuntime.jsx(TicketLink, { ticketId: decision.ticketId, url: decision.ticketUrl, label: "Ouvrir le ticket dans Gorgias" }) }),
723
748
  decision.status === "error" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-md bg-destructive/10 p-3 text-destructive", children: [
724
749
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs font-semibold uppercase tracking-wider", children: TRIAGE_DECISION_STATUS_LABELS.error }),
725
750
  decision.error && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-xs", children: decision.error })
@@ -872,7 +897,7 @@ function TicketsPage() {
872
897
  return withOutcome.filter((r) => r.job && responseOutcome(r.job).variant === outcomeFilter);
873
898
  }, [decisions, jobByDecisionId, outcomeFilter]);
874
899
  const columns = [
875
- { key: "ticketId", header: "Ticket", cell: ({ decision }) => decision.ticketId },
900
+ { key: "ticketId", header: "Ticket", cell: ({ decision }) => /* @__PURE__ */ jsxRuntime.jsx(TicketLink, { ticketId: decision.ticketId, url: decision.ticketUrl }) },
876
901
  {
877
902
  key: "category",
878
903
  header: "Cat\xE9gorie",
@@ -1822,6 +1847,16 @@ function applyPreset(value, preset, restore) {
1822
1847
  }
1823
1848
  return next;
1824
1849
  }
1850
+
1851
+ // src/ui/shared/quality-href.ts
1852
+ function qualityHref(appSlug, agent) {
1853
+ const base2 = `/espace/${appSlug}/quality`;
1854
+ if (!agent) return base2;
1855
+ const params = new URLSearchParams({ promptName: agent.promptName });
1856
+ if (agent.promptVersion !== null) params.set("promptVersion", String(agent.promptVersion));
1857
+ params.set("agentId", agent.id);
1858
+ return `${base2}?${params.toString()}`;
1859
+ }
1825
1860
  function usePromptCatalogue() {
1826
1861
  const { appSlug } = uiSdk.useAppContext();
1827
1862
  const api = uiSdk.useAppApi();
@@ -2162,7 +2197,14 @@ function AgentFormModal({
2162
2197
  children: /* @__PURE__ */ jsxRuntime.jsxs("form", { className: "space-y-3", onSubmit: (e) => void submit(e), children: [
2163
2198
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2164
2199
  /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: nameId, className: "mb-1 block text-sm font-medium", children: "Nom" }),
2165
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Input, { id: nameId, value: form.name, onChange: (e) => setForm({ ...form, name: e.target.value }) })
2200
+ /* @__PURE__ */ jsxRuntime.jsx(
2201
+ uiSdk.Input,
2202
+ {
2203
+ id: nameId,
2204
+ value: form.name,
2205
+ onChange: (e) => setForm({ ...form, name: e.target.value })
2206
+ }
2207
+ )
2166
2208
  ] }),
2167
2209
  agent !== "new" && agent.status !== "default" && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2168
2210
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-1 text-sm font-medium", children: "Statut" }),
@@ -2232,7 +2274,12 @@ function AgentFormModal({
2232
2274
  value: showPromptFreeText ? CUSTOM_PROMPT_VALUE : knownPrompt ? form.promptName : agent === "new" ? DERIVED_PROMPT_VALUE : void 0,
2233
2275
  onValueChange: pickPrompt,
2234
2276
  items: [
2235
- ...agent === "new" ? [{ value: DERIVED_PROMPT_VALUE, label: "Nouveau prompt \u2014 agent/<g\xE9n\xE9r\xE9 automatiquement>" }] : [],
2277
+ ...agent === "new" ? [
2278
+ {
2279
+ value: DERIVED_PROMPT_VALUE,
2280
+ label: "Nouveau prompt \u2014 agent/<g\xE9n\xE9r\xE9 automatiquement>"
2281
+ }
2282
+ ] : [],
2236
2283
  ...prompts.map((entry) => ({ value: entry.name, label: entry.name })),
2237
2284
  { value: CUSTOM_PROMPT_VALUE, label: "Autre \u2014 saisir un nom de prompt" }
2238
2285
  ],
@@ -2291,6 +2338,7 @@ function PromptVersionsPanel({
2291
2338
  canWrite,
2292
2339
  onClose
2293
2340
  }) {
2341
+ const { appSlug } = uiSdk.useAppContext();
2294
2342
  const { versions, error, refresh, promote, deleteVersion, createVersion } = usePromptVersions(
2295
2343
  agent.promptName
2296
2344
  );
@@ -2336,7 +2384,11 @@ function PromptVersionsPanel({
2336
2384
  await promote(version);
2337
2385
  toast({ title: `Version ${version} promue en production.`, variant: "success" });
2338
2386
  } catch (err) {
2339
- toast({ title: "\xC9chec de la promotion", description: describeApiError(err), variant: "error" });
2387
+ toast({
2388
+ title: "\xC9chec de la promotion",
2389
+ description: describeApiError(err),
2390
+ variant: "error"
2391
+ });
2340
2392
  }
2341
2393
  }
2342
2394
  async function runCreateVersion() {
@@ -2346,7 +2398,11 @@ function PromptVersionsPanel({
2346
2398
  setNewVersionContent("");
2347
2399
  toast({ title: "Nouvelle version cr\xE9\xE9e.", variant: "success" });
2348
2400
  } catch (err) {
2349
- toast({ title: "\xC9chec de la cr\xE9ation", description: describeApiError(err), variant: "error" });
2401
+ toast({
2402
+ title: "\xC9chec de la cr\xE9ation",
2403
+ description: describeApiError(err),
2404
+ variant: "error"
2405
+ });
2350
2406
  } finally {
2351
2407
  setIsCreatingVersion(false);
2352
2408
  }
@@ -2358,7 +2414,11 @@ function PromptVersionsPanel({
2358
2414
  await deleteVersion(version);
2359
2415
  toast({ title: `Version ${version} supprim\xE9e.`, variant: "success" });
2360
2416
  } catch (err) {
2361
- toast({ title: "\xC9chec de la suppression", description: describeApiError(err), variant: "error" });
2417
+ toast({
2418
+ title: "\xC9chec de la suppression",
2419
+ description: describeApiError(err),
2420
+ variant: "error"
2421
+ });
2362
2422
  } finally {
2363
2423
  setDeletingVersion(null);
2364
2424
  }
@@ -2373,13 +2433,7 @@ function PromptVersionsPanel({
2373
2433
  children: [
2374
2434
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto", children: [
2375
2435
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
2376
- /* @__PURE__ */ jsxRuntime.jsx(
2377
- uiSdk.Link,
2378
- {
2379
- href: `/qualite?promptName=${encodeURIComponent(agent.promptName)}${agent.promptVersion !== null ? `&promptVersion=${agent.promptVersion}` : ""}&agentId=${encodeURIComponent(agent.id)}`,
2380
- children: "Voir dans Qualit\xE9"
2381
- }
2382
- ),
2436
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Link, { href: qualityHref(appSlug, agent), children: "Voir dans Qualit\xE9" }),
2383
2437
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
2384
2438
  versions.length >= 2 && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", onClick: openCompare, children: "Comparer" }),
2385
2439
  canWrite && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", onClick: () => void suggest(), disabled: isSuggesting, children: isSuggesting ? "Suggestion en cours\u2026" : "Sugg\xE9rer une am\xE9lioration" })
@@ -2407,7 +2461,15 @@ function PromptVersionsPanel({
2407
2461
  ] }),
2408
2462
  canWrite && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
2409
2463
  /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", size: "sm", onClick: () => void runPromote(v.version), children: "Promouvoir" }),
2410
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", size: "sm", onClick: () => setDeletingVersion(v.version), children: "Supprimer la version" })
2464
+ /* @__PURE__ */ jsxRuntime.jsx(
2465
+ uiSdk.Button,
2466
+ {
2467
+ variant: "outline",
2468
+ size: "sm",
2469
+ onClick: () => setDeletingVersion(v.version),
2470
+ children: "Supprimer la version"
2471
+ }
2472
+ )
2411
2473
  ] })
2412
2474
  ] }),
2413
2475
  /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "mt-2 whitespace-pre-wrap text-xs text-muted-foreground", children: v.content })
@@ -2474,15 +2536,27 @@ function AgentsPage() {
2474
2536
  await api.patch(recordPath(agent.id), { data: { status } });
2475
2537
  await refresh();
2476
2538
  } catch (err) {
2477
- toast({ title: "\xC9chec de la mise \xE0 jour", description: describeApiError(err), variant: "error" });
2539
+ toast({
2540
+ title: "\xC9chec de la mise \xE0 jour",
2541
+ description: describeApiError(err),
2542
+ variant: "error"
2543
+ });
2478
2544
  }
2479
2545
  }
2480
2546
  async function setDefault(agent) {
2481
2547
  try {
2482
- await api.invoke("set-default-agent", { agentId: agent.id }, { idempotencyKey: crypto.randomUUID() });
2548
+ await api.invoke(
2549
+ "set-default-agent",
2550
+ { agentId: agent.id },
2551
+ { idempotencyKey: crypto.randomUUID() }
2552
+ );
2483
2553
  await refresh();
2484
2554
  } catch (err) {
2485
- toast({ title: "\xC9chec de la promotion par d\xE9faut", description: describeInvokeError(err), variant: "error" });
2555
+ toast({
2556
+ title: "\xC9chec de la promotion par d\xE9faut",
2557
+ description: describeInvokeError(err),
2558
+ variant: "error"
2559
+ });
2486
2560
  }
2487
2561
  }
2488
2562
  async function confirmDelete() {
@@ -2493,7 +2567,11 @@ function AgentsPage() {
2493
2567
  await refresh();
2494
2568
  toast({ title: `Agent \xAB ${agent.name} \xBB supprim\xE9.`, variant: "success" });
2495
2569
  } catch (err) {
2496
- toast({ title: "\xC9chec de la suppression", description: describeApiError(err), variant: "error" });
2570
+ toast({
2571
+ title: "\xC9chec de la suppression",
2572
+ description: describeApiError(err),
2573
+ variant: "error"
2574
+ });
2497
2575
  } finally {
2498
2576
  setDeletingAgent(null);
2499
2577
  }
@@ -2610,7 +2688,14 @@ function AgentsPage() {
2610
2688
  onSave: save
2611
2689
  }
2612
2690
  ),
2613
- versionsAgent && /* @__PURE__ */ jsxRuntime.jsx(PromptVersionsPanel, { agent: versionsAgent, canWrite, onClose: () => setVersionsAgent(null) }),
2691
+ versionsAgent && /* @__PURE__ */ jsxRuntime.jsx(
2692
+ PromptVersionsPanel,
2693
+ {
2694
+ agent: versionsAgent,
2695
+ canWrite,
2696
+ onClose: () => setVersionsAgent(null)
2697
+ }
2698
+ ),
2614
2699
  deletingAgent && /* @__PURE__ */ jsxRuntime.jsx(
2615
2700
  ConfirmModal,
2616
2701
  {
@@ -3096,6 +3181,7 @@ function StatusBadge({ status, error }) {
3096
3181
  }
3097
3182
  function DetailPanel3({ row, categoryName, onClose }) {
3098
3183
  return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.SidePanel, { open: true, onClose, title: `Ticket ${row.ticketId}`, description: categoryName, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 text-sm", children: [
3184
+ row.ticketUrl && /* @__PURE__ */ jsxRuntime.jsx("p", { children: /* @__PURE__ */ jsxRuntime.jsx(TicketLink, { ticketId: row.ticketId, url: row.ticketUrl, label: "Ouvrir le ticket dans Gorgias" }) }),
3099
3185
  row.reasoning && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
3100
3186
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "Raison du triage" }),
3101
3187
  /* @__PURE__ */ jsxRuntime.jsx("p", { children: row.reasoning })
@@ -3153,7 +3239,7 @@ function EscalationsPage() {
3153
3239
  const { rows: categories } = useRecordList("category", { limit: 500 }, toCategory);
3154
3240
  const categoryNames = react.useMemo(() => toNameMap(categories), [categories]);
3155
3241
  const columns = [
3156
- { key: "ticketId", header: "Ticket", cell: (row) => row.ticketId },
3242
+ { key: "ticketId", header: "Ticket", cell: (row) => /* @__PURE__ */ jsxRuntime.jsx(TicketLink, { ticketId: row.ticketId, url: row.ticketUrl }) },
3157
3243
  { key: "category", header: "Cat\xE9gorie", cell: (row) => row.categoryId && categoryNames.get(row.categoryId) || "\u2014" },
3158
3244
  { key: "tag", header: "Tag", cell: (row) => row.tag ? /* @__PURE__ */ jsxRuntime.jsx("code", { className: "text-xs", children: row.tag }) : "\u2014" },
3159
3245
  {
@@ -3303,11 +3389,6 @@ var MATCH_BADGE_CLASS = (pct) => {
3303
3389
  return "border-destructive/25 bg-destructive/10 text-destructive";
3304
3390
  };
3305
3391
  var VERSION_LINE_COLORS = 8;
3306
- function qualityHref(agent) {
3307
- if (!agent) return "/qualite";
3308
- const version = agent.promptVersion !== null ? `&promptVersion=${agent.promptVersion}` : "";
3309
- return `/qualite?promptName=${encodeURIComponent(agent.promptName)}${version}&agentId=${encodeURIComponent(agent.id)}`;
3310
- }
3311
3392
  function tokensFor(row) {
3312
3393
  return row.diff ?? computeWordDiff(row.generatedText, row.sentText);
3313
3394
  }
@@ -3327,39 +3408,80 @@ function DetailPanel4({
3327
3408
  onClose
3328
3409
  }) {
3329
3410
  const tokens = tokensFor(row);
3330
- return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.SidePanel, { open: true, onClose, title: `Ticket ${row.ticketId ?? "\u2014"}`, description: agentName, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 text-sm", children: [
3331
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
3332
- /* @__PURE__ */ jsxRuntime.jsx(MatchBadge, { row }),
3333
- row.ticketUrl && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Link, { href: row.ticketUrl, target: "_blank", rel: "noopener noreferrer", className: "text-xs", children: "Ouvrir le ticket" })
3334
- ] }),
3335
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 gap-3 sm:grid-cols-2", children: [
3336
- /* @__PURE__ */ jsxRuntime.jsx(WordDiffView, { title: "G\xE9n\xE9r\xE9 par l'IA", tokens, keep: "delete", hideEqual: diffOnly }),
3337
- /* @__PURE__ */ jsxRuntime.jsx(WordDiffView, { title: "Envoy\xE9 par l'agent", tokens, keep: "insert", hideEqual: diffOnly })
3338
- ] }),
3339
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground", children: [
3340
- /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
3341
- "Captur\xE9 le ",
3342
- formatDate(row.capturedAt)
3343
- ] }),
3344
- row.promptName && /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
3345
- "Prompt : ",
3346
- /* @__PURE__ */ jsxRuntime.jsx("code", { children: row.promptName }),
3347
- row.promptVersion !== null ? ` v${row.promptVersion}` : ""
3411
+ return /* @__PURE__ */ jsxRuntime.jsx(
3412
+ uiSdk.SidePanel,
3413
+ {
3414
+ open: true,
3415
+ onClose,
3416
+ title: `Ticket ${row.ticketId ?? "\u2014"}`,
3417
+ description: agentName,
3418
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4 text-sm", children: [
3419
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
3420
+ /* @__PURE__ */ jsxRuntime.jsx(MatchBadge, { row }),
3421
+ row.ticketUrl && /* @__PURE__ */ jsxRuntime.jsx(
3422
+ uiSdk.Link,
3423
+ {
3424
+ href: row.ticketUrl,
3425
+ target: "_blank",
3426
+ rel: "noopener noreferrer",
3427
+ className: "text-xs",
3428
+ children: "Ouvrir le ticket"
3429
+ }
3430
+ )
3431
+ ] }),
3432
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 gap-3 sm:grid-cols-2", children: [
3433
+ /* @__PURE__ */ jsxRuntime.jsx(
3434
+ WordDiffView,
3435
+ {
3436
+ title: "G\xE9n\xE9r\xE9 par l'IA",
3437
+ tokens,
3438
+ keep: "delete",
3439
+ hideEqual: diffOnly
3440
+ }
3441
+ ),
3442
+ /* @__PURE__ */ jsxRuntime.jsx(
3443
+ WordDiffView,
3444
+ {
3445
+ title: "Envoy\xE9 par l'agent",
3446
+ tokens,
3447
+ keep: "insert",
3448
+ hideEqual: diffOnly
3449
+ }
3450
+ )
3451
+ ] }),
3452
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground", children: [
3453
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
3454
+ "Captur\xE9 le ",
3455
+ formatDate(row.capturedAt)
3456
+ ] }),
3457
+ row.promptName && /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
3458
+ "Prompt : ",
3459
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: row.promptName }),
3460
+ row.promptVersion !== null ? ` v${row.promptVersion}` : ""
3461
+ ] })
3462
+ ] }),
3463
+ (row.langfuseTraceId || row.langfuseObservationId) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
3464
+ /* @__PURE__ */ jsxRuntime.jsx(
3465
+ LangfuseTraceLink,
3466
+ {
3467
+ traceId: row.langfuseTraceId,
3468
+ config: langfuseConfig,
3469
+ label: "Trace g\xE9n\xE9ration"
3470
+ }
3471
+ ),
3472
+ /* @__PURE__ */ jsxRuntime.jsx(
3473
+ LangfuseTraceLink,
3474
+ {
3475
+ traceId: row.langfuseTraceId,
3476
+ observationId: row.langfuseObservationId,
3477
+ config: langfuseConfig,
3478
+ label: "Trace \xE9valuation"
3479
+ }
3480
+ )
3481
+ ] })
3348
3482
  ] })
3349
- ] }),
3350
- (row.langfuseTraceId || row.langfuseObservationId) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
3351
- /* @__PURE__ */ jsxRuntime.jsx(LangfuseTraceLink, { traceId: row.langfuseTraceId, config: langfuseConfig, label: "Trace g\xE9n\xE9ration" }),
3352
- /* @__PURE__ */ jsxRuntime.jsx(
3353
- LangfuseTraceLink,
3354
- {
3355
- traceId: row.langfuseTraceId,
3356
- observationId: row.langfuseObservationId,
3357
- config: langfuseConfig,
3358
- label: "Trace \xE9valuation"
3359
- }
3360
- )
3361
- ] })
3362
- ] }) });
3483
+ }
3484
+ );
3363
3485
  }
3364
3486
  function CorrectionsPage() {
3365
3487
  const { role, appSlug } = uiSdk.useAppContext();
@@ -3406,27 +3528,40 @@ function CorrectionsPage() {
3406
3528
  },
3407
3529
  toResponseComparison
3408
3530
  );
3409
- const visibleRows = react.useMemo(() => diffOnly ? comparisons.filter(isTextChanged) : comparisons, [comparisons, diffOnly]);
3531
+ const visibleRows = react.useMemo(
3532
+ () => diffOnly ? comparisons.filter(isTextChanged) : comparisons,
3533
+ [comparisons, diffOnly]
3534
+ );
3410
3535
  const { rows: agents } = useRecordList("agent", { limit: 500 }, toAgent);
3411
3536
  const agentNames = react.useMemo(() => toNameMap(agents), [agents]);
3412
3537
  const selectedAgent = agents.find((a) => a.id === agentFilter);
3413
3538
  const { versions: promptVersions } = usePromptVersions(selectedAgent?.promptName ?? null);
3414
3539
  const versionOptions = [
3415
3540
  { value: "", label: "Toutes les versions" },
3416
- ...promptVersions.map((v) => ({ value: String(v.version), label: `v${v.version}${v.labels.includes("production") ? " (active)" : ""}` }))
3541
+ ...promptVersions.map((v) => ({
3542
+ value: String(v.version),
3543
+ label: `v${v.version}${v.labels.includes("production") ? " (active)" : ""}`
3544
+ }))
3417
3545
  ];
3418
- const {
3419
- rows: diffAnalyses,
3420
- refresh: refreshDiffAnalyses
3421
- } = useRecordList(
3546
+ const { rows: diffAnalyses, refresh: refreshDiffAnalyses } = useRecordList(
3422
3547
  "diff-analysis",
3423
3548
  { filter: agentFilter ? { agentId: { eq: agentFilter } } : void 0, limit: 50 },
3424
3549
  toDiffAnalysis
3425
3550
  );
3426
- const sortedAnalyses = react.useMemo(() => [...diffAnalyses].sort((a, b) => b.promptVersion - a.promptVersion), [diffAnalyses]);
3427
- const rewriteRate = react.useMemo(() => computeRewriteRateByVersion(comparisons, timezone), [comparisons, timezone]);
3551
+ const sortedAnalyses = react.useMemo(
3552
+ () => [...diffAnalyses].sort((a, b) => b.promptVersion - a.promptVersion),
3553
+ [diffAnalyses]
3554
+ );
3555
+ const rewriteRate = react.useMemo(
3556
+ () => computeRewriteRateByVersion(comparisons, timezone),
3557
+ [comparisons, timezone]
3558
+ );
3428
3559
  const rewriteRateSeries = react.useMemo(
3429
- () => rewriteRate.versions.map((version, index) => ({ key: versionSeriesKey(version), label: `v${version}`, colorIndex: index % VERSION_LINE_COLORS })),
3560
+ () => rewriteRate.versions.map((version, index) => ({
3561
+ key: versionSeriesKey(version),
3562
+ label: `v${version}`,
3563
+ colorIndex: index % VERSION_LINE_COLORS
3564
+ })),
3430
3565
  [rewriteRate.versions]
3431
3566
  );
3432
3567
  const agentOptions = [
@@ -3438,11 +3573,17 @@ function CorrectionsPage() {
3438
3573
  setIsAnalyzing(true);
3439
3574
  const payload = { agentId: agentFilter, limit: 50 };
3440
3575
  try {
3441
- await api.invoke("run-diff-analysis", payload, { idempotencyKey: idempotencyKeyFor("run-diff-analysis", payload) });
3576
+ await api.invoke("run-diff-analysis", payload, {
3577
+ idempotencyKey: idempotencyKeyFor("run-diff-analysis", payload)
3578
+ });
3442
3579
  toast({ title: "Analyse lanc\xE9e \u2014 les nouveaux points sont ci-dessous.", variant: "success" });
3443
3580
  await refreshDiffAnalyses();
3444
3581
  } catch (err) {
3445
- toast({ title: "\xC9chec de l'analyse", description: describeInvokeError(err), variant: "error" });
3582
+ toast({
3583
+ title: "\xC9chec de l'analyse",
3584
+ description: describeInvokeError(err),
3585
+ variant: "error"
3586
+ });
3446
3587
  } finally {
3447
3588
  setIsAnalyzing(false);
3448
3589
  }
@@ -3457,7 +3598,11 @@ function CorrectionsPage() {
3457
3598
  await refresh();
3458
3599
  toast({ title: "Comparaison supprim\xE9e.", variant: "success" });
3459
3600
  } catch (err) {
3460
- toast({ title: "\xC9chec de la suppression", description: describeApiError(err), variant: "error" });
3601
+ toast({
3602
+ title: "\xC9chec de la suppression",
3603
+ description: describeApiError(err),
3604
+ variant: "error"
3605
+ });
3461
3606
  } finally {
3462
3607
  setIsDeleting(false);
3463
3608
  setPendingDeleteRow(null);
@@ -3470,7 +3615,11 @@ function CorrectionsPage() {
3470
3615
  await refresh();
3471
3616
  toast({ title: "Comparaisons supprim\xE9es.", variant: "success" });
3472
3617
  } catch (err) {
3473
- toast({ title: "\xC9chec de la suppression", description: describeApiError(err), variant: "error" });
3618
+ toast({
3619
+ title: "\xC9chec de la suppression",
3620
+ description: describeApiError(err),
3621
+ variant: "error"
3622
+ });
3474
3623
  } finally {
3475
3624
  setIsDeleting(false);
3476
3625
  setPendingDeleteAll(false);
@@ -3480,9 +3629,22 @@ function CorrectionsPage() {
3480
3629
  {
3481
3630
  key: "ticketId",
3482
3631
  header: "Ticket",
3483
- cell: (row) => row.ticketUrl ? /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Link, { href: row.ticketUrl, target: "_blank", rel: "noopener noreferrer", onClick: (e) => e.stopPropagation(), children: row.ticketId ?? "\u2014" }) : row.ticketId ?? "\u2014"
3632
+ cell: (row) => row.ticketUrl ? /* @__PURE__ */ jsxRuntime.jsx(
3633
+ uiSdk.Link,
3634
+ {
3635
+ href: row.ticketUrl,
3636
+ target: "_blank",
3637
+ rel: "noopener noreferrer",
3638
+ onClick: (e) => e.stopPropagation(),
3639
+ children: row.ticketId ?? "\u2014"
3640
+ }
3641
+ ) : row.ticketId ?? "\u2014"
3642
+ },
3643
+ {
3644
+ key: "agent",
3645
+ header: "Agent",
3646
+ cell: (row) => row.agentId && agentNames.get(row.agentId) || "\u2014"
3484
3647
  },
3485
- { key: "agent", header: "Agent", cell: (row) => row.agentId && agentNames.get(row.agentId) || "\u2014" },
3486
3648
  {
3487
3649
  key: "changed",
3488
3650
  header: "R\xE9sultat",
@@ -3549,12 +3711,29 @@ function CorrectionsPage() {
3549
3711
  children: diffOnly ? "Afficher toutes les lignes" : "Masquer les lignes identiques"
3550
3712
  }
3551
3713
  ),
3552
- canWrite && agentFilter && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", size: "sm", onClick: () => setPendingDeleteAll(true), disabled: isDeleting, children: "Tout supprimer" })
3714
+ canWrite && agentFilter && /* @__PURE__ */ jsxRuntime.jsx(
3715
+ uiSdk.Button,
3716
+ {
3717
+ variant: "outline",
3718
+ size: "sm",
3719
+ onClick: () => setPendingDeleteAll(true),
3720
+ disabled: isDeleting,
3721
+ children: "Tout supprimer"
3722
+ }
3723
+ )
3553
3724
  ] }),
3554
3725
  /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Card, { children: /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.CardContent, { className: "p-4", children: [
3555
3726
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-1 text-sm font-medium", children: "Taux de r\xE9\xE9criture" }),
3556
3727
  /* @__PURE__ */ jsxRuntime.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." }),
3557
- rewriteRate.points.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Aucune donn\xE9e de r\xE9\xE9criture pour cette s\xE9lection." }) : /* @__PURE__ */ jsxRuntime.jsx(uiSdk.LineChart, { data: rewriteRate.points, x: "day", series: rewriteRateSeries, formatValue: (v) => `${v}%` })
3728
+ rewriteRate.points.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Aucune donn\xE9e de r\xE9\xE9criture pour cette s\xE9lection." }) : /* @__PURE__ */ jsxRuntime.jsx(
3729
+ uiSdk.LineChart,
3730
+ {
3731
+ data: rewriteRate.points,
3732
+ x: "day",
3733
+ series: rewriteRateSeries,
3734
+ formatValue: (v) => `${v}%`
3735
+ }
3736
+ )
3558
3737
  ] }) }),
3559
3738
  agentFilter && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Card, { children: /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.CardContent, { className: "space-y-3 p-4", children: [
3560
3739
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
@@ -3566,7 +3745,7 @@ function CorrectionsPage() {
3566
3745
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: "Patterns r\xE9currents extraits par le LLM \xE0 partir des corrections non identiques." })
3567
3746
  ] }),
3568
3747
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3", children: [
3569
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Link, { href: qualityHref(selectedAgent), children: "Voir dans Qualit\xE9" }),
3748
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Link, { href: qualityHref(appSlug, selectedAgent), children: "Voir dans Qualit\xE9" }),
3570
3749
  canWrite && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { onClick: () => void runAnalysis(), disabled: isAnalyzing, children: isAnalyzing ? "Analyse en cours\u2026" : "Lancer l'analyse" })
3571
3750
  ] })
3572
3751
  ] }),
@@ -4142,6 +4321,84 @@ function useIds(stepKey) {
4142
4321
  minConfidence: `${base2}-${stepKey}-min-confidence`
4143
4322
  };
4144
4323
  }
4324
+ function normalize(text) {
4325
+ return text.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
4326
+ }
4327
+ var MAX_RESULTS = 12;
4328
+ function SearchableSelect({
4329
+ id,
4330
+ options,
4331
+ value,
4332
+ onChange,
4333
+ disabled = false,
4334
+ labels
4335
+ }) {
4336
+ const [search, setSearch] = react.useState("");
4337
+ if (options.length === 0) {
4338
+ return /* @__PURE__ */ jsxRuntime.jsx(
4339
+ uiSdk.Input,
4340
+ {
4341
+ id,
4342
+ "aria-label": labels.fallbackAriaLabel,
4343
+ value,
4344
+ onChange: (e) => onChange(e.target.value),
4345
+ disabled
4346
+ }
4347
+ );
4348
+ }
4349
+ const term = normalize(search.trim());
4350
+ const matches = term === "" ? options : options.filter(
4351
+ (option) => normalize(`${option.label} ${option.keywords ?? ""}`).includes(term)
4352
+ );
4353
+ const shown = matches.slice(0, MAX_RESULTS);
4354
+ const current = options.find((option) => option.value === value);
4355
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
4356
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: current ? labels.current(current.label) : labels.none }),
4357
+ /* @__PURE__ */ jsxRuntime.jsx(
4358
+ uiSdk.Input,
4359
+ {
4360
+ id,
4361
+ "aria-label": labels.searchAriaLabel,
4362
+ placeholder: labels.searchPlaceholder,
4363
+ value: search,
4364
+ onChange: (e) => setSearch(e.target.value),
4365
+ disabled
4366
+ }
4367
+ ),
4368
+ shown.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: labels.noMatch }) : /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "flex flex-wrap gap-2", children: shown.map((option) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsx(
4369
+ uiSdk.Button,
4370
+ {
4371
+ variant: option.value === value ? "default" : "outline",
4372
+ size: "sm",
4373
+ disabled,
4374
+ onClick: () => onChange(option.value),
4375
+ children: option.label
4376
+ }
4377
+ ) }, option.value)) }),
4378
+ matches.length > shown.length && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: labels.truncated(options.length) })
4379
+ ] });
4380
+ }
4381
+ function SourceViewField({ views, value, onChange, disabled }) {
4382
+ return /* @__PURE__ */ jsxRuntime.jsx(
4383
+ SearchableSelect,
4384
+ {
4385
+ id: "sourceViewId",
4386
+ options: views.map((view) => ({ value: view.id, label: view.name, keywords: view.id })),
4387
+ value,
4388
+ onChange,
4389
+ disabled,
4390
+ labels: {
4391
+ fallbackAriaLabel: "Vue Gorgias source",
4392
+ searchAriaLabel: "Chercher une vue Gorgias",
4393
+ searchPlaceholder: "Taper une partie du nom de la vue\u2026",
4394
+ current: (name) => `Vue actuelle : ${name}`,
4395
+ none: "Aucune vue choisie.",
4396
+ noMatch: "Aucune vue ne correspond.",
4397
+ truncated: (total) => `${total} vues au total \u2014 affine la recherche pour voir les autres.`
4398
+ }
4399
+ }
4400
+ );
4401
+ }
4145
4402
  var WHATSAPP_MODE_LABELS = {
4146
4403
  escalate_only: "Escalade uniquement",
4147
4404
  draft_only: "Brouillon uniquement",
@@ -4290,21 +4547,12 @@ function SettingsPage() {
4290
4547
  ] }),
4291
4548
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4292
4549
  /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "sourceViewId", className: "mb-1 block text-sm font-medium", children: "Vue Gorgias source" }),
4293
- views.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
4294
- uiSdk.Select,
4295
- {
4296
- "aria-label": "Vue Gorgias source",
4297
- value: sourceViewId || void 0,
4298
- onValueChange: (v) => set("sourceViewId", v),
4299
- items: views.map((v) => ({ value: v.id, label: v.name })),
4300
- disabled: !canWrite
4301
- }
4302
- ) : /* @__PURE__ */ jsxRuntime.jsx(
4303
- uiSdk.Input,
4550
+ /* @__PURE__ */ jsxRuntime.jsx(
4551
+ SourceViewField,
4304
4552
  {
4305
- id: "sourceViewId",
4553
+ views,
4306
4554
  value: sourceViewId,
4307
- onChange: (e) => set("sourceViewId", e.target.value),
4555
+ onChange: (v) => set("sourceViewId", v),
4308
4556
  disabled: !canWrite
4309
4557
  }
4310
4558
  )
@@ -4438,9 +4686,8 @@ function SettingsPage() {
4438
4686
  ["unknownTag", "Tag inconnu"],
4439
4687
  ["handledTag", "Tag trait\xE9"],
4440
4688
  ["escalationTag", "Tag d'escalade"],
4441
- ["needsHumanTag", "Tag besoin humain"],
4442
4689
  ["autoRepliedTag", "Tag r\xE9pondu automatiquement"],
4443
- ["needsReviewTag", "Tag \xE0 revoir"],
4690
+ ["needsReviewTag", "Tag \xE0 revoir avant envoi"],
4444
4691
  ["followupTag", "Tag suivi requis"]
4445
4692
  ].map(([key, label]) => /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4446
4693
  /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: key, className: "mb-1 block text-sm font-medium", children: label }),
@@ -4600,6 +4847,31 @@ function SettingsPage() {
4600
4847
  ] })
4601
4848
  );
4602
4849
  }
4850
+ function readParam(name) {
4851
+ if (typeof window === "undefined") return null;
4852
+ return new URLSearchParams(window.location.search).get(name);
4853
+ }
4854
+ function useQueryParam(name) {
4855
+ const [value, setState] = react.useState(() => readParam(name));
4856
+ react.useEffect(() => {
4857
+ const sync = () => setState(readParam(name));
4858
+ sync();
4859
+ window.addEventListener("popstate", sync);
4860
+ return () => window.removeEventListener("popstate", sync);
4861
+ }, [name]);
4862
+ const setValue = react.useCallback(
4863
+ (next) => {
4864
+ const params = new URLSearchParams(window.location.search);
4865
+ if (next === null) params.delete(name);
4866
+ else params.set(name, next);
4867
+ const query = params.toString();
4868
+ window.history.pushState({}, "", `${window.location.pathname}${query ? `?${query}` : ""}`);
4869
+ setState(next);
4870
+ },
4871
+ [name]
4872
+ );
4873
+ return { value, setValue };
4874
+ }
4603
4875
 
4604
4876
  // src/graph/state.ts
4605
4877
  var NODE_NAMES = [
@@ -4620,14 +4892,32 @@ function hasNoDraftNode(profile) {
4620
4892
  }
4621
4893
 
4622
4894
  // src/ui/graph-canvas/reachability.ts
4895
+ var EXIT_TONES = {
4896
+ sent: "delivered",
4897
+ failed: "failure",
4898
+ ready: "held",
4899
+ needs_human: "held",
4900
+ guardrail_hold: "held",
4901
+ awaiting_approval: "held",
4902
+ escalated: "held",
4903
+ triaged_only: "held",
4904
+ no_reply_needed: "held"
4905
+ };
4623
4906
  function stubPrompts() {
4624
4907
  const ref = { name: "", label: "production" };
4625
4908
  return { triage: ref, escalate: ref, draft: ref, evaluate: ref };
4626
4909
  }
4627
4910
  var PROMPT_403_NODES = /* @__PURE__ */ new Set(["triage", "escalate", "draft", "evaluate", "revise"]);
4628
- 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.";
4629
- function reason(kind, message) {
4630
- return { kind, message };
4911
+ var PROMPT_403_NOTE = {
4912
+ id: "prompt-403",
4913
+ message: "Ces \xE9tapes appellent un mod\xE8le via un prompt qui n'est pas d\xE9clar\xE9 : sur un d\xE9ploiement r\xE9el l'appel \xE9choue, m\xEAme l\xE0 o\xF9 cette page affiche \xAB Actif \xBB.",
4914
+ detail: "promptRef est transmis \xE0 ctx.api.llm.complete, qui r\xE9pond 403 PROMPT_NOT_DECLARED tant que manifest.prompts[] reste vide \u2014 d\xE9faut D-LF connu, non corrig\xE9 (journal T24/T25)."
4915
+ };
4916
+ function reason(kind, message, detail) {
4917
+ return detail === void 0 ? { kind, message } : { kind, message, detail };
4918
+ }
4919
+ function note(message, detail) {
4920
+ return detail === void 0 ? { message } : { message, detail };
4631
4921
  }
4632
4922
  function nodeModelOf(node, profile) {
4633
4923
  switch (node) {
@@ -4643,17 +4933,35 @@ function nodeModelOf(node, profile) {
4643
4933
  return null;
4644
4934
  }
4645
4935
  }
4646
- var READY_EXIT = { key: "evaluate-ready", condition: "envoi auto non \xE9ligible", outcome: "ready" };
4936
+ var READY_EXIT = {
4937
+ key: "evaluate-ready",
4938
+ condition: "envoi auto non \xE9ligible",
4939
+ outcome: "ready"
4940
+ };
4647
4941
  var NODE_EXITS = {
4648
- fetchContext: [{ key: "fetchContext-failed", condition: "lecture impossible", outcome: "failed" }],
4942
+ fetchContext: [
4943
+ { key: "fetchContext-failed", condition: "lecture impossible", outcome: "failed" }
4944
+ ],
4649
4945
  triage: [
4650
4946
  { key: "triage-fallback", condition: "classification de repli", outcome: "triaged_only" },
4651
- { key: "triage-closed", condition: "le dernier message client cl\xF4t la conversation", outcome: "no_reply_needed" },
4652
- { key: "triage-whatsapp-gate", condition: "r\xE8gle de canal WhatsApp (STOP ou pas notre tour)", outcome: "guardrail_hold" }
4947
+ {
4948
+ key: "triage-closed",
4949
+ condition: "le dernier message client cl\xF4t la conversation",
4950
+ outcome: "no_reply_needed"
4951
+ },
4952
+ {
4953
+ key: "triage-whatsapp-gate",
4954
+ condition: "r\xE8gle de canal WhatsApp (STOP ou pas notre tour)",
4955
+ outcome: "guardrail_hold"
4956
+ }
4653
4957
  ],
4654
4958
  escalate: [
4655
4959
  { key: "escalate-escalated", condition: "escalade demand\xE9e", outcome: "escalated" },
4656
- { key: "escalate-no-draft", condition: "profil sans n\u0153ud de r\xE9daction", outcome: "triaged_only" }
4960
+ {
4961
+ key: "escalate-no-draft",
4962
+ condition: "profil sans n\u0153ud de r\xE9daction",
4963
+ outcome: "triaged_only"
4964
+ }
4657
4965
  ],
4658
4966
  evaluate: [
4659
4967
  {
@@ -4663,8 +4971,16 @@ var NODE_EXITS = {
4663
4971
  },
4664
4972
  READY_EXIT
4665
4973
  ],
4666
- guardrails: [{ key: "guardrails-content", condition: "garde-fou de contenu", outcome: "guardrail_hold" }],
4667
- authorize: [{ key: "authorize-awaiting", condition: "une action n'est pas \xAB auto \xBB", outcome: "awaiting_approval" }],
4974
+ guardrails: [
4975
+ { key: "guardrails-content", condition: "garde-fou de contenu", outcome: "guardrail_hold" }
4976
+ ],
4977
+ authorize: [
4978
+ {
4979
+ key: "authorize-awaiting",
4980
+ condition: "une action n'est pas \xAB auto \xBB",
4981
+ outcome: "awaiting_approval"
4982
+ }
4983
+ ],
4668
4984
  act: [
4669
4985
  { key: "act-collision", condition: "contr\xF4le anti-collision", outcome: "guardrail_hold" },
4670
4986
  { key: "act-sent-email", condition: "r\xE9ponse email", outcome: "sent" },
@@ -4673,10 +4989,15 @@ var NODE_EXITS = {
4673
4989
  };
4674
4990
  function exitsFor(node, evaluateConfigured) {
4675
4991
  const raw = NODE_EXITS[node] ?? [];
4676
- if (evaluateConfigured) return raw;
4992
+ const withTone = (exits) => exits.map((exit) => ({ ...exit, tone: EXIT_TONES[exit.outcome] }));
4993
+ if (evaluateConfigured) return withTone(raw);
4677
4994
  if (node === "evaluate") return [];
4678
- if (node === "draft") return [READY_EXIT];
4679
- return raw;
4995
+ if (node === "draft") return withTone([READY_EXIT]);
4996
+ return withTone(raw);
4997
+ }
4998
+ function deriveCause(state, reasons) {
4999
+ if (state === "on") return null;
5000
+ return reasons.some((r) => r.kind !== "upstream-disabled") ? "root" : "consequence";
4680
5001
  }
4681
5002
  function deriveState(upstreamOk, blockingReasons, offReasons) {
4682
5003
  if (!upstreamOk) return "unreachable";
@@ -4694,11 +5015,17 @@ function computeGraphReachability(rawSettings, hasCategoryWithAutoReply) {
4694
5015
  nodes: NODE_NAMES.map((node) => ({
4695
5016
  node,
4696
5017
  state: "unreachable",
4697
- reasons: [reason("missing-setting", message)],
5018
+ // Every node reports the SAME single root cause here — none of them
5019
+ // is "blocked by the one before", they are all blocked by the same
5020
+ // absent setting, so none is a mere consequence of another.
5021
+ cause: "root",
5022
+ reasons: [reason("missing-setting", message, "validateSettings: nodes.triage est \xE0 null.")],
4698
5023
  notes: [],
4699
5024
  model: null,
4700
- exits: []
4701
- }))
5025
+ exits: [],
5026
+ promptWarning: false
5027
+ })),
5028
+ globalNotes: []
4702
5029
  };
4703
5030
  }
4704
5031
  const settings = rawSettings;
@@ -4706,20 +5033,23 @@ function computeGraphReachability(rawSettings, hasCategoryWithAutoReply) {
4706
5033
  const evaluateConfigured = profile.nodes.evaluate !== null;
4707
5034
  const byNode = /* @__PURE__ */ new Map();
4708
5035
  function set(node, state, reasons, notes = []) {
4709
- const promptNote = state === "on" && PROMPT_403_NODES.has(node) ? [PROMPT_403_NOTE] : [];
4710
5036
  byNode.set(node, {
4711
5037
  node,
4712
5038
  state,
5039
+ cause: deriveCause(state, reasons),
4713
5040
  reasons,
4714
- notes: [...notes, ...promptNote],
5041
+ notes,
4715
5042
  model: nodeModelOf(node, profile),
4716
- exits: exitsFor(node, evaluateConfigured)
5043
+ exits: exitsFor(node, evaluateConfigured),
5044
+ promptWarning: state === "on" && PROMPT_403_NODES.has(node)
4717
5045
  });
4718
5046
  }
4719
5047
  function getNode(node) {
4720
5048
  const found = byNode.get(node);
4721
5049
  if (!found) {
4722
- 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.`);
5050
+ throw new Error(
5051
+ `computeGraphReachability: no reachability rule was set for node "${node}" \u2014 NODE_NAMES gained an entry this module does not know how to place.`
5052
+ );
4723
5053
  }
4724
5054
  return found;
4725
5055
  }
@@ -4728,121 +5058,329 @@ function computeGraphReachability(rawSettings, hasCategoryWithAutoReply) {
4728
5058
  const fetchBlockingReasons = [];
4729
5059
  const sourceViewIdIssue = issues.find((issue) => issue.key === "sourceViewId");
4730
5060
  if (sourceViewIdIssue) {
4731
- fetchBlockingReasons.push(reason("missing-setting", settingsIssueLabel("sourceViewId", sourceViewIdIssue.message)));
5061
+ fetchBlockingReasons.push(
5062
+ reason(
5063
+ "missing-setting",
5064
+ settingsIssueLabel("sourceViewId", sourceViewIdIssue.message),
5065
+ "validateSettings: sourceViewId est vide."
5066
+ )
5067
+ );
4732
5068
  }
4733
5069
  if (!settings.triageEnabled) {
4734
- fetchOffReasons.push(reason("missing-setting", "triageEnabled est d\xE9sactiv\xE9 \u2014 ce coupe-circuit emp\xEAche toute ex\xE9cution du pipeline."));
5070
+ fetchOffReasons.push(
5071
+ reason(
5072
+ "missing-setting",
5073
+ "Le pipeline est coup\xE9 : aucun ticket n'est lu, donc aucune \xE9tape ne s'ex\xE9cute.",
5074
+ "triageEnabled est d\xE9sactiv\xE9 \u2014 coupe-circuit global (\xA73.5)."
5075
+ )
5076
+ );
4735
5077
  }
4736
- set("fetchContext", deriveState(true, fetchBlockingReasons, fetchOffReasons), [...fetchBlockingReasons, ...fetchOffReasons]);
5078
+ set("fetchContext", deriveState(true, fetchBlockingReasons, fetchOffReasons), [
5079
+ ...fetchBlockingReasons,
5080
+ ...fetchOffReasons
5081
+ ]);
4737
5082
  const fetchNode = getNode("fetchContext");
4738
5083
  const fetchRuns = passesControlOn("fetchContext");
4739
5084
  set(
4740
5085
  "triage",
4741
5086
  fetchRuns ? "on" : "unreachable",
4742
5087
  fetchRuns ? [] : [
4743
- reason(
5088
+ fetchNode.state === "off" ? reason(
4744
5089
  "upstream-disabled",
4745
- 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."
5090
+ "La r\xE9cup\xE9ration du ticket est coup\xE9e \u2014 aucun ticket n'est jamais lu.",
5091
+ "fetchContext est d\xE9sactiv\xE9 (triageEnabled)."
5092
+ ) : reason(
5093
+ "upstream-disabled",
5094
+ "La r\xE9cup\xE9ration du ticket est bloqu\xE9e \u2014 voir sa carte.",
5095
+ "fetchContext est inatteignable (sourceViewId)."
4746
5096
  )
4747
5097
  ]
4748
5098
  );
4749
5099
  const triageRuns = passesControlOn("triage");
4750
5100
  const escalateDisabled = profile.nodes.escalate === null;
5101
+ const escalateOff = reason(
5102
+ "disabled-step",
5103
+ "\xC9tape coup\xE9e dans les r\xE9glages \u2014 aucune escalade automatique n'est d\xE9cid\xE9e.",
5104
+ "nodes.escalate est \xE0 null (\xA73.6)."
5105
+ );
4751
5106
  set(
4752
5107
  "escalate",
4753
- deriveState(triageRuns, [], escalateDisabled ? [reason("disabled-step", "nodes.escalate est \xE0 null dans les r\xE9glages \u2014 \xE9tape d\xE9sactiv\xE9e (\xA73.6).")] : []),
4754
- 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.")]
5108
+ deriveState(triageRuns, [], escalateDisabled ? [escalateOff] : []),
5109
+ triageRuns ? escalateDisabled ? [escalateOff] : [] : [
5110
+ reason(
5111
+ "upstream-disabled",
5112
+ "Le triage n'est jamais atteint.",
5113
+ "triage est inatteignable."
5114
+ )
5115
+ ]
4755
5116
  );
4756
5117
  const draftDisabled = hasNoDraftNode(profile);
5118
+ const draftOff = reason(
5119
+ "disabled-step",
5120
+ "\xC9tape coup\xE9e dans les r\xE9glages \u2014 aucune r\xE9ponse n'est r\xE9dig\xE9e.",
5121
+ "nodes.draft est \xE0 null \u2014 sortie \xAB triaged_only \xBB (run-ticket.ts#hasNoDraftNode)."
5122
+ );
4757
5123
  set(
4758
5124
  "draft",
4759
- 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").')] : []),
4760
- 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.")]
5125
+ deriveState(triageRuns, [], draftDisabled ? [draftOff] : []),
5126
+ triageRuns ? draftDisabled ? [draftOff] : [] : [
5127
+ reason(
5128
+ "upstream-disabled",
5129
+ "Le triage n'est jamais atteint.",
5130
+ "triage est inatteignable."
5131
+ )
5132
+ ]
4761
5133
  );
4762
5134
  const draftRuns = passesControlOn("draft");
4763
5135
  const evaluateDisabled = !evaluateConfigured;
5136
+ const evaluateOff = reason(
5137
+ "disabled-step",
5138
+ "\xC9tape coup\xE9e dans les r\xE9glages \u2014 aucun verdict, la r\xE9ponse reste \xAB Disponible \xBB.",
5139
+ "nodes.evaluate est \xE0 null \u2014 la r\xE9ponse conserve l'issue \xAB ready \xBB."
5140
+ );
4764
5141
  set(
4765
5142
  "evaluate",
4766
- 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".`)] : []),
4767
- 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.")]
5143
+ deriveState(draftRuns, [], evaluateDisabled ? [evaluateOff] : []),
5144
+ draftRuns ? evaluateDisabled ? [evaluateOff] : [] : [
5145
+ getNode("draft").state === "off" ? reason(
5146
+ "upstream-disabled",
5147
+ "La r\xE9daction est coup\xE9e \u2014 aucun ticket n'atteint l'\xE9valuation.",
5148
+ "draft est d\xE9sactiv\xE9."
5149
+ ) : reason(
5150
+ "upstream-disabled",
5151
+ "La r\xE9daction n'est jamais atteinte.",
5152
+ "draft est inatteignable."
5153
+ )
5154
+ ]
4768
5155
  );
4769
5156
  const evaluateRuns = passesControlOn("evaluate");
4770
5157
  const reviseDisabled = profile.nodes.revise === null;
5158
+ const reviseOff = reason(
5159
+ "disabled-step",
5160
+ "\xC9tape coup\xE9e dans les r\xE9glages \u2014 pas de passe de correction.",
5161
+ "nodes.revise est \xE0 null."
5162
+ );
4771
5163
  set(
4772
5164
  "revise",
4773
- deriveState(evaluateRuns, [], reviseDisabled ? [reason("disabled-step", "nodes.revise est \xE0 null dans les r\xE9glages \u2014 pas de passe de correction.")] : []),
4774
- 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.")],
4775
- evaluateRuns && !reviseDisabled ? ["Au plus une passe de r\xE9vision par ticket (\xA73.3)."] : []
5165
+ deriveState(evaluateRuns, [], reviseDisabled ? [reviseOff] : []),
5166
+ evaluateRuns ? reviseDisabled ? [reviseOff] : [] : [
5167
+ getNode("evaluate").state === "off" ? reason(
5168
+ "upstream-disabled",
5169
+ "L'\xE9valuation est coup\xE9e \u2014 aucun ticket n'atteint la r\xE9vision.",
5170
+ "evaluate est d\xE9sactiv\xE9."
5171
+ ) : reason(
5172
+ "upstream-disabled",
5173
+ "L'\xE9valuation n'est jamais atteinte.",
5174
+ "evaluate est inatteignable."
5175
+ )
5176
+ ],
5177
+ evaluateRuns && !reviseDisabled ? [note("Au plus une passe de r\xE9vision par ticket.", "\xA73.3.")] : []
4776
5178
  );
4777
5179
  const autoSendBlockingReasons = [];
4778
5180
  const autoSendOffReasons = [];
4779
5181
  if (!profile.autoSend.enabled) {
4780
- autoSendOffReasons.push(reason("missing-setting", "autoSendEnabled est d\xE9sactiv\xE9 \u2014 ce coupe-circuit emp\xEAche tout envoi automatique."));
5182
+ autoSendOffReasons.push(
5183
+ reason(
5184
+ "missing-setting",
5185
+ "L'envoi automatique est coup\xE9 \u2014 ce coupe-circuit emp\xEAche tout envoi.",
5186
+ "autoSendEnabled est d\xE9sactiv\xE9."
5187
+ )
5188
+ );
4781
5189
  }
4782
5190
  if (!hasCategoryWithAutoReply) {
4783
5191
  autoSendBlockingReasons.push(
4784
- 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.`)
5192
+ reason(
5193
+ "missing-setting",
5194
+ "Aucune cat\xE9gorie n'a \xAB Envoi auto \xBB activ\xE9 \u2014 sans elle, aucune r\xE9ponse n'est \xE9ligible \xE0 un envoi automatique.",
5195
+ "isAutoSendEligible exige category.autoReplyEnabled ; aucune cat\xE9gorie ne le porte aujourd'hui."
5196
+ )
4785
5197
  );
4786
5198
  }
4787
5199
  const senderEmailIssue = issues.find((issue) => issue.key === "senderEmail");
4788
5200
  if (senderEmailIssue) {
4789
- autoSendBlockingReasons.push(reason("missing-setting", settingsIssueLabel("senderEmail", senderEmailIssue.message)));
5201
+ autoSendBlockingReasons.push(
5202
+ reason(
5203
+ "missing-setting",
5204
+ settingsIssueLabel("senderEmail", senderEmailIssue.message),
5205
+ "validateSettings: senderEmail est vide alors que autoSendEnabled est actif."
5206
+ )
5207
+ );
4790
5208
  }
4791
5209
  const guardrailNotes = [];
4792
5210
  if (!profile.autoSend.senderEmail && profile.guardrails.params.whatsappMode === "auto_reply") {
4793
5211
  guardrailNotes.push(
4794
- `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.`
5212
+ note(
5213
+ "Sans adresse d'envoi, seuls les tickets WhatsApp en r\xE9ponse automatique passent ici : un ticket email reste bloqu\xE9 \xE0 \xAB Disponible \xBB.",
5214
+ `senderEmail est vide et whatsappMode="auto_reply" \u2014 hasSenderForMode n'est vrai que pour WhatsApp ; un ticket email n'atteint jamais guardrails/authorize/act.`
5215
+ )
4795
5216
  );
4796
5217
  }
4797
5218
  if (profile.guardrails.params.whatsappMode === "draft_only") {
4798
5219
  guardrailNotes.push(
4799
- '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.'
5220
+ note(
5221
+ "Les tickets WhatsApp ne d\xE9passent jamais \xAB Disponible \xBB (mode brouillon seul) : seuls les tickets email arrivent r\xE9ellement ici.",
5222
+ `whatsappMode="draft_only" \u2014 isAutoSendEligible exclut ce mode ; authorize/act ne s'ex\xE9cutent que pour le canal email.`
5223
+ )
4800
5224
  );
4801
5225
  }
4802
5226
  if (profile.guardrails.params.whatsappMode === "escalate_only") {
4803
5227
  guardrailNotes.push(
4804
- `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.`
5228
+ note(
5229
+ "Un ticket WhatsApp qui arrive ici est syst\xE9matiquement retenu : sur ce canal la r\xE9ponse est gard\xE9e, jamais envoy\xE9e.",
5230
+ `whatsappMode="escalate_only" \u2014 garde-fou \xAB whatsapp \xBB (\xA73.9) ; authorize/act ne s'ex\xE9cutent jamais pour ce canal.`
5231
+ )
4805
5232
  );
4806
5233
  }
4807
5234
  set(
4808
5235
  "guardrails",
4809
5236
  deriveState(evaluateRuns, autoSendBlockingReasons, autoSendOffReasons),
4810
- 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.")],
5237
+ evaluateRuns ? [...autoSendBlockingReasons, ...autoSendOffReasons] : [
5238
+ getNode("evaluate").state === "off" ? reason(
5239
+ "upstream-disabled",
5240
+ "L'\xE9valuation est coup\xE9e \u2014 sans verdict, aucun ticket n'arrive ici.",
5241
+ "evaluate est d\xE9sactiv\xE9."
5242
+ ) : reason(
5243
+ "upstream-disabled",
5244
+ "L'\xE9valuation n'est jamais atteinte \u2014 aucun verdict ne peut donc \xEAtre produit.",
5245
+ "evaluate est inatteignable."
5246
+ )
5247
+ ],
4811
5248
  guardrailNotes
4812
5249
  );
4813
5250
  const guardrailsRuns = passesControlOn("guardrails");
4814
5251
  set(
4815
5252
  "authorize",
4816
5253
  guardrailsRuns ? "on" : "unreachable",
4817
- 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.")],
5254
+ guardrailsRuns ? [] : [
5255
+ getNode("guardrails").state === "off" ? reason(
5256
+ "upstream-disabled",
5257
+ "Les garde-fous sont coup\xE9s \u2014 aucune action n'est jamais autoris\xE9e.",
5258
+ "guardrails est d\xE9sactiv\xE9 (autoSendEnabled)."
5259
+ ) : reason(
5260
+ "upstream-disabled",
5261
+ "Les garde-fous ne sont jamais atteints \u2014 voir leur carte.",
5262
+ "guardrails est inatteignable."
5263
+ )
5264
+ ],
4818
5265
  guardrailsRuns ? guardrailNotes : []
4819
5266
  );
4820
5267
  const authorizeRuns = passesControlOn("authorize");
4821
- 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).`;
5268
+ const approvalNote = note(
5269
+ "Le chemin d'approbation manuelle est inatteignable avec les r\xE9glages actuels : une r\xE9ponse autoris\xE9e part directement, jamais apr\xE8s une approbation.",
5270
+ "authorization.send_reply d\xE9rive du m\xEAme coupe-circuit autoSendEnabled qu'isAutoSendEligible \u2014 l'issue \xAB awaiting_approval \xBB n'est jamais produite (limitation connue, journal T22)."
5271
+ );
4822
5272
  set(
4823
5273
  "act",
4824
5274
  authorizeRuns ? "on" : "unreachable",
4825
- authorizeRuns ? [] : [reason("upstream-disabled", "authorize est inatteignable.")],
5275
+ authorizeRuns ? [] : [
5276
+ reason(
5277
+ "upstream-disabled",
5278
+ "L'autorisation n'est jamais atteinte.",
5279
+ "authorize est inatteignable."
5280
+ )
5281
+ ],
4826
5282
  authorizeRuns ? [...guardrailNotes, approvalNote] : []
4827
5283
  );
4828
- return { blocked: false, nodes: NODE_NAMES.map((node) => getNode(node)) };
5284
+ const nodes = NODE_NAMES.map((node) => getNode(node));
5285
+ const promptWarningNodes = nodes.filter((n) => n.promptWarning).map((n) => n.node);
5286
+ return {
5287
+ blocked: false,
5288
+ nodes,
5289
+ globalNotes: promptWarningNodes.length > 0 ? [{ ...PROMPT_403_NOTE, nodes: promptWarningNodes }] : []
5290
+ };
4829
5291
  }
4830
- var CATEGORY_PAGE_SIZE = 500;
4831
- var REASON_KIND_LABELS = {
5292
+ function windowCutoffIso3(days, now = Date.now()) {
5293
+ return new Date(now - days * 24 * 60 * 60 * 1e3).toISOString();
5294
+ }
5295
+ function totalOf(rows) {
5296
+ if (!Array.isArray(rows)) return null;
5297
+ let total = 0;
5298
+ for (const row of rows) {
5299
+ const value = row?.count;
5300
+ if (typeof value !== "number") return null;
5301
+ total += value;
5302
+ }
5303
+ return total;
5304
+ }
5305
+ function useGraphTraffic(windowDays) {
5306
+ const cutoffIso = react.useMemo(() => windowCutoffIso3(windowDays), [windowDays]);
5307
+ const triaged = useAggregate("triage-decision", {
5308
+ filter: { decidedAt: { gte: cutoffIso } },
5309
+ metrics: [{ op: "count", as: "count" }]
5310
+ });
5311
+ const escalated = useAggregate("triage-decision", {
5312
+ filter: { decidedAt: { gte: cutoffIso }, escalated: { eq: true } },
5313
+ metrics: [{ op: "count", as: "count" }]
5314
+ });
5315
+ const drafted = useAggregate("generated-response", {
5316
+ filter: { generatedAt: { gte: cutoffIso } },
5317
+ metrics: [{ op: "count", as: "count" }]
5318
+ });
5319
+ const sent = useAggregate("generated-response", {
5320
+ filter: { generatedAt: { gte: cutoffIso }, status: { eq: "sent" } },
5321
+ metrics: [{ op: "count", as: "count" }]
5322
+ });
5323
+ const isLoading = triaged.isLoading || escalated.isLoading || drafted.isLoading || sent.isLoading;
5324
+ const failed = [triaged, escalated, drafted, sent].some((q) => q.error !== void 0);
5325
+ const triagedTotal = totalOf(triaged.rows);
5326
+ const escalatedTotal = totalOf(escalated.rows);
5327
+ const draftedTotal = totalOf(drafted.rows);
5328
+ const sentTotal = totalOf(sent.rows);
5329
+ return react.useMemo(() => {
5330
+ const byNode = {};
5331
+ if (triagedTotal !== null) {
5332
+ byNode.fetchContext = {
5333
+ count: triagedTotal,
5334
+ witness: "tickets triag\xE9s (un triage suppose une lecture r\xE9ussie)"
5335
+ };
5336
+ byNode.triage = { count: triagedTotal, witness: "tickets triag\xE9s" };
5337
+ }
5338
+ if (escalatedTotal !== null)
5339
+ byNode.escalate = { count: escalatedTotal, witness: "tickets escalad\xE9s" };
5340
+ if (draftedTotal !== null) byNode.draft = { count: draftedTotal, witness: "r\xE9ponses r\xE9dig\xE9es" };
5341
+ if (sentTotal !== null) byNode.act = { count: sentTotal, witness: "r\xE9ponses envoy\xE9es" };
5342
+ return {
5343
+ byNode: failed ? {} : byNode,
5344
+ isLoading,
5345
+ unavailable: failed
5346
+ };
5347
+ }, [triagedTotal, escalatedTotal, draftedTotal, sentTotal, failed, isLoading]);
5348
+ }
5349
+ var CATEGORY_PAGE_SIZE = 500;
5350
+ var TRAFFIC_WINDOW_DAYS = 7;
5351
+ var REASON_KIND_LABELS = {
4832
5352
  "disabled-step": "\xC9tape d\xE9sactiv\xE9e",
4833
5353
  "upstream-disabled": "Bloqu\xE9 en amont",
4834
5354
  "missing-setting": "R\xE9glage manquant",
4835
5355
  "channel-gate": "Restriction de canal"
4836
5356
  };
4837
- var ACTIVATION_LABELS = {
5357
+ var BADGE_LABELS = {
4838
5358
  on: "Actif",
4839
5359
  off: "D\xE9sactiv\xE9",
4840
- unreachable: "Inatteignable"
5360
+ root: "Bloqu\xE9",
5361
+ consequence: "Hors d\u2019atteinte"
4841
5362
  };
4842
- var ACTIVATION_BADGE_VARIANT = {
5363
+ var BADGE_VARIANTS = {
4843
5364
  on: "success",
4844
5365
  off: "neutral",
4845
- unreachable: "warning"
5366
+ root: "danger",
5367
+ consequence: "warning"
5368
+ };
5369
+ var BADGE_DEFINITIONS = {
5370
+ on: "Au moins un ticket peut atteindre ce n\u0153ud avec les r\xE9glages actuels.",
5371
+ off: "L\u2019op\xE9rateur a coup\xE9 ce n\u0153ud lui-m\xEAme \u2014 un choix, pas un incident.",
5372
+ root: "C\u2019est ici que le parcours s\u2019arr\xEAte : la cause est sur cette carte.",
5373
+ consequence: "Ce n\u0153ud n\u2019a rien de cass\xE9 \u2014 il est simplement priv\xE9 de tickets par un n\u0153ud en amont."
5374
+ };
5375
+ function badgeKindOf(node) {
5376
+ if (node.state === "on") return "on";
5377
+ if (node.state === "off") return "off";
5378
+ return node.cause === "consequence" ? "consequence" : "root";
5379
+ }
5380
+ var EXIT_TONE_CLASSES = {
5381
+ delivered: "border-status-success/30 bg-status-success/10 text-status-success",
5382
+ held: "border-border bg-muted text-muted-foreground",
5383
+ failure: "border-status-blocked/25 bg-status-blocked/10 text-status-blocked"
4846
5384
  };
4847
5385
  var NODE_SETTINGS_SECTION = {
4848
5386
  fetchContext: { id: "source", title: "Source" },
@@ -4854,60 +5392,395 @@ var NODE_SETTINGS_SECTION = {
4854
5392
  guardrails: { id: "guardrails", title: "Guardrails" },
4855
5393
  act: { id: "envoi", title: "Envoi" }
4856
5394
  };
4857
- function NodeCard({ node, appSlug }) {
4858
- const section = NODE_SETTINGS_SECTION[node.node];
5395
+ function settingsHref(appSlug, node) {
5396
+ const section = NODE_SETTINGS_SECTION[node];
5397
+ return section ? `/parametres/espaces/${appSlug}#${section.id}` : null;
5398
+ }
5399
+ function dedupeExits(exits) {
5400
+ const byOutcome = /* @__PURE__ */ new Map();
5401
+ for (const exit of exits) {
5402
+ const existing = byOutcome.get(exit.outcome);
5403
+ if (existing) existing.conditions.push(exit.condition);
5404
+ else
5405
+ byOutcome.set(exit.outcome, {
5406
+ outcome: exit.outcome,
5407
+ tone: exit.tone,
5408
+ conditions: [exit.condition]
5409
+ });
5410
+ }
5411
+ return [...byOutcome.values()];
5412
+ }
5413
+ function computeVerdict(result) {
5414
+ const causes = result.nodes.filter((node) => node.state !== "on" && node.cause === "root");
5415
+ if (result.blocked) {
5416
+ return {
5417
+ tone: "critical",
5418
+ headline: "Le pipeline ne peut pas d\xE9marrer : le triage n\u2019est pas configur\xE9.",
5419
+ causes: causes.slice(0, 1)
5420
+ };
5421
+ }
5422
+ const act = result.nodes.find((node) => node.node === "act");
5423
+ if (act && act.state !== "on") {
5424
+ return {
5425
+ tone: "critical",
5426
+ headline: "Aucune r\xE9ponse ne peut partir automatiquement aujourd\u2019hui.",
5427
+ causes
5428
+ };
5429
+ }
5430
+ return {
5431
+ tone: "ok",
5432
+ headline: "Le parcours va jusqu\u2019\xE0 l\u2019envoi : une r\xE9ponse peut partir automatiquement.",
5433
+ causes
5434
+ };
5435
+ }
5436
+ function VerdictBanner({ verdict, appSlug }) {
5437
+ const critical = verdict.tone === "critical";
5438
+ return /* @__PURE__ */ jsxRuntime.jsx(
5439
+ "section",
5440
+ {
5441
+ "data-testid": "graph-verdict",
5442
+ className: uiSdk.cn(
5443
+ "rounded-lg border p-4",
5444
+ critical ? "border-status-blocked/30 bg-status-blocked/5" : "border-status-success/30 bg-status-success/5"
5445
+ ),
5446
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start gap-3", children: [
5447
+ /* @__PURE__ */ jsxRuntime.jsx(
5448
+ "span",
5449
+ {
5450
+ "aria-hidden": true,
5451
+ className: uiSdk.cn(
5452
+ "mt-0.5 text-lg leading-none",
5453
+ critical ? "text-status-blocked" : "text-status-success"
5454
+ ),
5455
+ children: critical ? "\u26D4" : "\u2713"
5456
+ }
5457
+ ),
5458
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
5459
+ /* @__PURE__ */ jsxRuntime.jsx(
5460
+ "p",
5461
+ {
5462
+ className: uiSdk.cn(
5463
+ "text-sm font-semibold",
5464
+ critical ? "text-status-blocked" : "text-status-success"
5465
+ ),
5466
+ children: verdict.headline
5467
+ }
5468
+ ),
5469
+ verdict.causes.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "space-y-2", children: verdict.causes.map((cause) => {
5470
+ const href = settingsHref(appSlug, cause.node);
5471
+ return /* @__PURE__ */ jsxRuntime.jsxs(
5472
+ "li",
5473
+ {
5474
+ className: "flex flex-wrap items-center gap-x-2 gap-y-1 text-sm",
5475
+ children: [
5476
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium", children: NODE_LABELS[cause.node] }),
5477
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-muted-foreground", children: [
5478
+ "\u2014 ",
5479
+ cause.reasons[0]?.message ?? ""
5480
+ ] }),
5481
+ href && /* @__PURE__ */ jsxRuntime.jsx(
5482
+ uiSdk.Link,
5483
+ {
5484
+ href,
5485
+ className: uiSdk.cn(
5486
+ uiSdk.buttonVariants({ variant: "outline", size: "sm" }),
5487
+ "no-underline"
5488
+ ),
5489
+ children: "Corriger"
5490
+ }
5491
+ )
5492
+ ]
5493
+ },
5494
+ cause.node
5495
+ );
5496
+ }) })
5497
+ ] })
5498
+ ] })
5499
+ }
5500
+ );
5501
+ }
5502
+ function Legend() {
4859
5503
  return /* @__PURE__ */ jsxRuntime.jsx(
4860
- uiSdk.Card,
5504
+ "div",
5505
+ {
5506
+ className: "flex flex-wrap items-center gap-x-4 gap-y-2 text-xs text-muted-foreground",
5507
+ "data-testid": "graph-legend",
5508
+ children: Object.keys(BADGE_LABELS).map((kind) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-1.5", title: BADGE_DEFINITIONS[kind], children: [
5509
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: BADGE_VARIANTS[kind], children: BADGE_LABELS[kind] }),
5510
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "max-w-64", children: BADGE_DEFINITIONS[kind] })
5511
+ ] }, kind))
5512
+ }
5513
+ );
5514
+ }
5515
+ function trafficContradiction(node, traffic) {
5516
+ if (!traffic) return null;
5517
+ if (node.state === "on" && traffic.count === 0) {
5518
+ return `Aucun passage observ\xE9 sur ${TRAFFIC_WINDOW_DAYS} jours, alors que ce n\u0153ud est r\xE9put\xE9 atteignable.`;
5519
+ }
5520
+ if (node.state !== "on" && traffic.count > 0) {
5521
+ return `${traffic.count} passage(s) observ\xE9(s) sur ${TRAFFIC_WINDOW_DAYS} jours, alors que ce n\u0153ud est r\xE9put\xE9 injoignable \u2014 l\u2019analyse ou les r\xE9glages ont chang\xE9 depuis.`;
5522
+ }
5523
+ return null;
5524
+ }
5525
+ function TrafficPill({
5526
+ node,
5527
+ traffic
5528
+ }) {
5529
+ if (!traffic) {
5530
+ return /* @__PURE__ */ jsxRuntime.jsx(
5531
+ "span",
5532
+ {
5533
+ className: "text-xs text-muted-foreground",
5534
+ title: "Aucun enregistrement ne t\xE9moigne du passage par ce n\u0153ud \u2014 cette page pr\xE9f\xE8re ne rien afficher plut\xF4t qu\u2019un chiffre d\xE9duit.",
5535
+ children: "\u2014 trafic non mesur\xE9"
5536
+ }
5537
+ );
5538
+ }
5539
+ const contradiction = trafficContradiction(node, traffic);
5540
+ return /* @__PURE__ */ jsxRuntime.jsxs(
5541
+ "span",
5542
+ {
5543
+ className: uiSdk.cn(
5544
+ "text-xs",
5545
+ contradiction ? "font-medium text-status-blocked" : "text-muted-foreground"
5546
+ ),
5547
+ title: `${traffic.witness}, sur ${TRAFFIC_WINDOW_DAYS} jours.`,
5548
+ children: [
5549
+ traffic.count,
5550
+ " sur ",
5551
+ TRAFFIC_WINDOW_DAYS,
5552
+ " j",
5553
+ contradiction ? " \u26A0" : ""
5554
+ ]
5555
+ }
5556
+ );
5557
+ }
5558
+ function Connector({ into, isBreak }) {
5559
+ const dead = into.state !== "on";
5560
+ return /* @__PURE__ */ jsxRuntime.jsxs(
5561
+ "div",
5562
+ {
5563
+ className: "flex items-center gap-2 pl-[3px]",
5564
+ "data-testid": `graph-edge-${into.node}`,
5565
+ "data-edge-state": dead ? "dead" : "live",
5566
+ children: [
5567
+ /* @__PURE__ */ jsxRuntime.jsx(
5568
+ "span",
5569
+ {
5570
+ "aria-hidden": true,
5571
+ className: uiSdk.cn(
5572
+ "h-6 w-0 border-l-2",
5573
+ dead ? "border-dashed" : "border-solid",
5574
+ into.state === "on" ? "border-status-success/50" : into.cause === "root" ? "border-status-blocked/60" : "border-border"
5575
+ )
5576
+ }
5577
+ ),
5578
+ isBreak && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-xs font-medium text-status-blocked", children: [
5579
+ "\u26D4",
5580
+ " le parcours s",
5581
+ "\u2019",
5582
+ "arr\xEAte ici"
5583
+ ] })
5584
+ ]
5585
+ }
5586
+ );
5587
+ }
5588
+ function NodeRow({
5589
+ node,
5590
+ traffic,
5591
+ technical,
5592
+ globalNotes,
5593
+ onOpen
5594
+ }) {
5595
+ const kind = badgeKindOf(node);
5596
+ const exits = dedupeExits(node.exits);
5597
+ const contradiction = trafficContradiction(node, traffic);
5598
+ const headlineReason = node.reasons[0];
5599
+ const extraCount = Math.max(0, node.reasons.length - 1) + node.notes.length + globalNotes.length;
5600
+ return /* @__PURE__ */ jsxRuntime.jsxs(
5601
+ "div",
4861
5602
  {
5603
+ className: "flex items-start gap-3",
4862
5604
  "data-testid": "graph-node",
4863
5605
  "data-node": node.node,
4864
- className: uiSdk.cn("w-56 shrink-0", node.state !== "on" && "border-dashed opacity-90"),
4865
- children: /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.CardContent, { className: "space-y-2 p-3", "data-testid": `graph-node-${node.node}`, children: [
4866
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-2", children: [
4867
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium", children: NODE_LABELS[node.node] }),
4868
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: ACTIVATION_BADGE_VARIANT[node.state], children: ACTIVATION_LABELS[node.state] })
4869
- ] }),
4870
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs leading-snug text-muted-foreground", children: NODE_ROLE_LABELS[node.node] }),
4871
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "font-mono text-[10px] text-muted-foreground", children: node.node }),
4872
- node.model && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs text-muted-foreground", children: [
4873
- "Mod\xE8le : ",
4874
- /* @__PURE__ */ jsxRuntime.jsx("code", { className: "font-mono", children: node.model })
4875
- ] }),
4876
- node.exits.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "flex flex-wrap gap-1.5 border-t pt-2", children: node.exits.map((exit) => /* @__PURE__ */ jsxRuntime.jsx(
4877
- "li",
5606
+ "data-state": kind,
5607
+ children: [
5608
+ /* @__PURE__ */ jsxRuntime.jsx(
5609
+ "span",
4878
5610
  {
4879
- title: exit.condition,
4880
- className: "rounded-md border px-1.5 py-0.5 text-[11px] leading-tight text-muted-foreground",
4881
- children: outcomeLabel(exit.outcome)
4882
- },
4883
- exit.key
4884
- )) }),
4885
- node.reasons.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "space-y-1", children: node.reasons.map((r, i) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "text-xs text-muted-foreground", children: [
4886
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-medium text-foreground", children: [
4887
- REASON_KIND_LABELS[r.kind],
4888
- " \u2014 "
4889
- ] }),
4890
- r.message
4891
- ] }, i)) }),
4892
- node.notes.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "space-y-1 border-t pt-2", children: node.notes.map((note, i) => /* @__PURE__ */ jsxRuntime.jsx("li", { className: "text-xs text-muted-foreground", children: note }, i)) }),
4893
- section && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "border-t pt-2 text-xs", children: /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Link, { href: `/parametres/espaces/${appSlug}#${section.id}`, children: [
4894
- "Ouvrir \xAB ",
4895
- section.title,
4896
- " \xBB dans Param\xE8tres"
4897
- ] }) })
4898
- ] })
5611
+ "aria-hidden": true,
5612
+ className: uiSdk.cn(
5613
+ "mt-4 size-2 shrink-0 rounded-full",
5614
+ kind === "on" && "bg-status-success",
5615
+ kind === "off" && "bg-muted-foreground/50",
5616
+ kind === "root" && "bg-status-blocked",
5617
+ kind === "consequence" && "bg-status-pending"
5618
+ )
5619
+ }
5620
+ ),
5621
+ /* @__PURE__ */ jsxRuntime.jsx(
5622
+ uiSdk.Card,
5623
+ {
5624
+ className: uiSdk.cn(
5625
+ "w-full max-w-2xl",
5626
+ kind === "root" && "border-status-blocked/40",
5627
+ (kind === "off" || kind === "consequence") && "border-dashed opacity-80"
5628
+ ),
5629
+ children: /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.CardContent, { className: "space-y-2 p-3", "data-testid": `graph-node-${node.node}`, children: [
5630
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-x-2 gap-y-1", children: [
5631
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium", children: NODE_LABELS[node.node] }),
5632
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: BADGE_VARIANTS[kind], title: BADGE_DEFINITIONS[kind], children: BADGE_LABELS[kind] }),
5633
+ node.promptWarning && /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Badge, { variant: "warning", title: "Voir l\u2019avertissement au-dessus du graphe.", children: [
5634
+ "\u26A0",
5635
+ " prompt non d\xE9clar\xE9"
5636
+ ] }),
5637
+ technical && /* @__PURE__ */ jsxRuntime.jsx("code", { className: "font-mono text-[10px] text-muted-foreground", children: node.node }),
5638
+ technical && node.model && /* @__PURE__ */ jsxRuntime.jsx("code", { className: "font-mono text-[10px] text-muted-foreground", children: node.model }),
5639
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "ml-auto flex items-center gap-3", children: [
5640
+ /* @__PURE__ */ jsxRuntime.jsx(TrafficPill, { node, traffic }),
5641
+ /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Button, { variant: "ghost", size: "sm", onClick: onOpen, children: [
5642
+ "D\xE9tails",
5643
+ extraCount > 0 ? ` (${extraCount})` : ""
5644
+ ] })
5645
+ ] })
5646
+ ] }),
5647
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs leading-snug text-muted-foreground", children: NODE_ROLE_LABELS[node.node] }),
5648
+ headlineReason && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs", children: [
5649
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-medium", children: [
5650
+ REASON_KIND_LABELS[headlineReason.kind],
5651
+ " \u2014 "
5652
+ ] }),
5653
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: headlineReason.message }),
5654
+ technical && headlineReason.detail && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ml-1 font-mono text-[10px] text-muted-foreground", children: headlineReason.detail })
5655
+ ] }),
5656
+ contradiction && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs font-medium text-status-blocked", children: contradiction }),
5657
+ exits.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-1.5 border-t pt-2", children: [
5658
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[11px] text-muted-foreground", children: "Issues possibles :" }),
5659
+ exits.map((exit) => /* @__PURE__ */ jsxRuntime.jsx(
5660
+ "span",
5661
+ {
5662
+ title: exit.conditions.join(" \xB7 "),
5663
+ className: uiSdk.cn(
5664
+ "rounded-md border px-1.5 py-0.5 text-[11px] leading-tight",
5665
+ EXIT_TONE_CLASSES[exit.tone]
5666
+ ),
5667
+ children: outcomeLabel(exit.outcome)
5668
+ },
5669
+ exit.outcome
5670
+ ))
5671
+ ] })
5672
+ ] })
5673
+ }
5674
+ )
5675
+ ]
5676
+ }
5677
+ );
5678
+ }
5679
+ function NodeDetailPanel({
5680
+ node,
5681
+ traffic,
5682
+ technical,
5683
+ appSlug,
5684
+ globalNotes,
5685
+ onClose
5686
+ }) {
5687
+ const href = node ? settingsHref(appSlug, node.node) : null;
5688
+ return /* @__PURE__ */ jsxRuntime.jsx(
5689
+ uiSdk.SidePanel,
5690
+ {
5691
+ open: node !== null,
5692
+ onClose,
5693
+ title: node ? NODE_LABELS[node.node] : "",
5694
+ description: node ? NODE_ROLE_LABELS[node.node] : "",
5695
+ children: node && /* @__PURE__ */ jsxRuntime.jsxs(
5696
+ "div",
5697
+ {
5698
+ className: "min-h-0 flex-1 space-y-4 overflow-y-auto text-sm",
5699
+ "data-testid": "graph-node-detail",
5700
+ children: [
5701
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
5702
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: BADGE_VARIANTS[badgeKindOf(node)], children: BADGE_LABELS[badgeKindOf(node)] }),
5703
+ technical && /* @__PURE__ */ jsxRuntime.jsx("code", { className: "font-mono text-xs text-muted-foreground", children: node.node })
5704
+ ] }),
5705
+ node.model && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs text-muted-foreground", children: [
5706
+ "Mod\xE8le : ",
5707
+ /* @__PURE__ */ jsxRuntime.jsx("code", { className: "font-mono", children: node.model })
5708
+ ] }),
5709
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: traffic ? `${traffic.count} ${traffic.witness} sur ${TRAFFIC_WINDOW_DAYS} jours.` : "Aucun enregistrement ne t\xE9moigne du passage par ce n\u0153ud : cette page n\u2019en affiche donc aucun chiffre." }),
5710
+ node.reasons.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "space-y-2", children: [
5711
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-xs font-semibold uppercase tracking-wide text-muted-foreground", children: "Pourquoi" }),
5712
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "space-y-2", children: node.reasons.map((r, i) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "text-xs", children: [
5713
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-medium", children: [
5714
+ REASON_KIND_LABELS[r.kind],
5715
+ " \u2014 "
5716
+ ] }),
5717
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: r.message }),
5718
+ technical && r.detail && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-0.5 font-mono text-[10px] text-muted-foreground", children: r.detail })
5719
+ ] }, i)) })
5720
+ ] }),
5721
+ (node.notes.length > 0 || globalNotes.length > 0) && /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "space-y-2", children: [
5722
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-xs font-semibold uppercase tracking-wide text-muted-foreground", children: "\xC0 savoir" }),
5723
+ /* @__PURE__ */ jsxRuntime.jsxs("ul", { className: "space-y-2", children: [
5724
+ node.notes.map((note2, i) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "text-xs text-muted-foreground", children: [
5725
+ note2.message,
5726
+ technical && note2.detail && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-0.5 font-mono text-[10px]", children: note2.detail })
5727
+ ] }, `note-${i}`)),
5728
+ globalNotes.map((note2) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "text-xs text-muted-foreground", children: [
5729
+ note2.message,
5730
+ technical && note2.detail && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-0.5 font-mono text-[10px]", children: note2.detail })
5731
+ ] }, note2.id))
5732
+ ] })
5733
+ ] }),
5734
+ node.exits.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "space-y-2", children: [
5735
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-xs font-semibold uppercase tracking-wide text-muted-foreground", children: "Issues possibles" }),
5736
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "space-y-1", children: node.exits.map((exit) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "flex items-baseline gap-2 text-xs", children: [
5737
+ /* @__PURE__ */ jsxRuntime.jsx(
5738
+ "span",
5739
+ {
5740
+ className: uiSdk.cn(
5741
+ "rounded-md border px-1.5 py-0.5 leading-tight",
5742
+ EXIT_TONE_CLASSES[exit.tone]
5743
+ ),
5744
+ children: outcomeLabel(exit.outcome)
5745
+ }
5746
+ ),
5747
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: exit.condition })
5748
+ ] }, exit.key)) })
5749
+ ] }),
5750
+ href && /* @__PURE__ */ jsxRuntime.jsx(
5751
+ uiSdk.Link,
5752
+ {
5753
+ href,
5754
+ className: uiSdk.cn(uiSdk.buttonVariants({ variant: "default", size: "sm" }), "no-underline"),
5755
+ children: "Ouvrir le r\xE9glage"
5756
+ }
5757
+ )
5758
+ ]
5759
+ }
5760
+ )
4899
5761
  }
4900
5762
  );
4901
5763
  }
4902
5764
  function GraphCanvasPage() {
4903
5765
  const { appSlug } = uiSdk.useAppContext();
4904
- const { settings, isLoading: settingsLoading, error: settingsError } = uiSdk.useAppSettings();
5766
+ const { value: viewParam, setValue: setViewParam } = useQueryParam("vue");
5767
+ const technical = viewParam === "technique";
5768
+ const [openNode, setOpenNode] = react.useState(null);
5769
+ const {
5770
+ settings,
5771
+ isLoading: settingsLoading,
5772
+ error: settingsError
5773
+ } = uiSdk.useAppSettings();
4905
5774
  const {
4906
5775
  rows: categories,
4907
5776
  isLoading: categoriesLoading,
4908
5777
  error: categoriesError
4909
5778
  } = useRecordList("category", { limit: CATEGORY_PAGE_SIZE }, toCategory);
4910
- const hasCategoryWithAutoReply = react.useMemo(() => categories.some((c) => c.autoReplyEnabled), [categories]);
5779
+ const traffic = useGraphTraffic(TRAFFIC_WINDOW_DAYS);
5780
+ const hasCategoryWithAutoReply = react.useMemo(
5781
+ () => categories.some((c) => c.autoReplyEnabled),
5782
+ [categories]
5783
+ );
4911
5784
  const categoriesMayBeTruncated = categories.length >= CATEGORY_PAGE_SIZE;
4912
5785
  const result = react.useMemo(
4913
5786
  () => settings ? computeGraphReachability(settings, hasCategoryWithAutoReply) : null,
@@ -4915,41 +5788,134 @@ function GraphCanvasPage() {
4915
5788
  );
4916
5789
  const isLoading = settingsLoading || categoriesLoading;
4917
5790
  const isUnavailable = !isLoading && (settingsError !== void 0 || categoriesError !== void 0 || !result);
5791
+ const verdict = react.useMemo(() => result ? computeVerdict(result) : null, [result]);
5792
+ const selected = result?.nodes.find((node) => node.node === openNode) ?? null;
5793
+ const notesFor = (node) => result ? result.globalNotes.filter((note2) => note2.nodes.includes(node)) : [];
5794
+ const breakNode = result?.nodes.find((node) => node.state === "unreachable" && node.cause === "root")?.node ?? null;
5795
+ const rail = react.useMemo(() => {
5796
+ if (!result) return null;
5797
+ const rows = result.nodes.map((node, i) => /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
5798
+ i > 0 && /* @__PURE__ */ jsxRuntime.jsx(Connector, { into: node, isBreak: node.node === breakNode }),
5799
+ /* @__PURE__ */ jsxRuntime.jsx(
5800
+ NodeRow,
5801
+ {
5802
+ node,
5803
+ traffic: traffic.byNode[node.node],
5804
+ technical,
5805
+ globalNotes: result.globalNotes.filter((note2) => note2.nodes.includes(node.node)),
5806
+ onOpen: () => setOpenNode(node.node)
5807
+ }
5808
+ )
5809
+ ] }, node.node));
5810
+ const from = result.nodes.findIndex((node) => node.node === "evaluate");
5811
+ const to = result.nodes.findIndex((node) => node.node === "revise");
5812
+ if (from < 0 || to <= from) return rows;
5813
+ return [
5814
+ ...rows.slice(0, from),
5815
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
5816
+ /* @__PURE__ */ jsxRuntime.jsx(
5817
+ "div",
5818
+ {
5819
+ "aria-hidden": true,
5820
+ "data-testid": "graph-back-edge",
5821
+ className: "pointer-events-none absolute inset-y-6 -left-9 w-6 rounded-l-md border-y-2 border-l-2 border-dashed border-muted-foreground/40"
5822
+ }
5823
+ ),
5824
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "pointer-events-none absolute -left-9 top-1/2 w-6 -translate-y-1/2 text-center text-[10px] leading-none text-muted-foreground", children: "\u21BA" }),
5825
+ rows.slice(from, to + 1)
5826
+ ] }, "back-edge"),
5827
+ ...rows.slice(to + 1)
5828
+ ];
5829
+ }, [result, breakNode, traffic.byNode, technical]);
4918
5830
  return /* @__PURE__ */ jsxRuntime.jsxs(PageShell, { children: [
4919
- /* @__PURE__ */ jsxRuntime.jsx(PageHeader, { title: "Graphe", description: "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." }),
5831
+ /* @__PURE__ */ jsxRuntime.jsx(
5832
+ PageHeader,
5833
+ {
5834
+ title: "Graphe",
5835
+ description: "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.",
5836
+ actions: /* @__PURE__ */ jsxRuntime.jsxs(
5837
+ "div",
5838
+ {
5839
+ className: "flex items-center rounded-md border p-0.5",
5840
+ role: "group",
5841
+ "aria-label": "Registre d'affichage",
5842
+ children: [
5843
+ /* @__PURE__ */ jsxRuntime.jsx(
5844
+ uiSdk.Button,
5845
+ {
5846
+ variant: technical ? "ghost" : "secondary",
5847
+ size: "sm",
5848
+ "aria-pressed": !technical,
5849
+ onClick: () => setViewParam(null),
5850
+ children: "Op\xE9rateur"
5851
+ }
5852
+ ),
5853
+ /* @__PURE__ */ jsxRuntime.jsx(
5854
+ uiSdk.Button,
5855
+ {
5856
+ variant: technical ? "secondary" : "ghost",
5857
+ size: "sm",
5858
+ "aria-pressed": technical,
5859
+ onClick: () => setViewParam("technique"),
5860
+ children: "Technique"
5861
+ }
5862
+ )
5863
+ ]
5864
+ }
5865
+ )
5866
+ }
5867
+ ),
4920
5868
  isLoading ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center py-12", children: [
4921
5869
  /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Spinner, {}),
4922
5870
  " ",
4923
5871
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ml-2 text-sm text-muted-foreground", children: "Chargement\u2026" })
4924
5872
  ] }) : isUnavailable ? /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4925
- result.blocked && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-md border border-status-warning/40 bg-status-warning/10 p-3 text-sm text-status-warning", children: [
4926
- "Le graphe ne peut d\xE9marrer avec les r\xE9glages actuels : ",
4927
- result.nodes[0].reasons[0]?.message ?? ""
4928
- ] }),
5873
+ /* @__PURE__ */ jsxRuntime.jsx(VerdictBanner, { verdict, appSlug }),
5874
+ result.globalNotes.map((note2) => /* @__PURE__ */ jsxRuntime.jsxs(
5875
+ "div",
5876
+ {
5877
+ "data-testid": `graph-global-note-${note2.id}`,
5878
+ className: "rounded-md border border-status-warning/40 bg-status-warning/10 p-3 text-sm text-status-warning",
5879
+ children: [
5880
+ /* @__PURE__ */ jsxRuntime.jsx("p", { children: note2.message }),
5881
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "mt-1 text-xs", children: [
5882
+ "N\u0153uds concern\xE9s (",
5883
+ note2.nodes.length,
5884
+ ") :",
5885
+ " ",
5886
+ note2.nodes.map((n) => NODE_LABELS[n]).join(", "),
5887
+ "."
5888
+ ] }),
5889
+ technical && note2.detail && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 font-mono text-[10px]", children: note2.detail })
5890
+ ]
5891
+ },
5892
+ note2.id
5893
+ )),
4929
5894
  !hasCategoryWithAutoReply && categoriesMayBeTruncated && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs text-muted-foreground", children: [
4930
5895
  "La lecture des cat\xE9gories est born\xE9e aux ",
4931
5896
  CATEGORY_PAGE_SIZE,
4932
5897
  " 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."
4933
5898
  ] }),
4934
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap items-center gap-2", children: result.nodes.map((node, i) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
4935
- /* @__PURE__ */ jsxRuntime.jsx(NodeCard, { node, appSlug }),
4936
- i < result.nodes.length - 1 && /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": true, className: "text-muted-foreground", children: "\u2192" })
4937
- ] }, node.node)) }),
4938
- /* @__PURE__ */ jsxRuntime.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." }),
4939
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-4 text-xs text-muted-foreground", children: [
4940
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-1.5", children: [
4941
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "success", children: "Actif" }),
4942
- " le n\u0153ud peut \xEAtre atteint par au moins un ticket avec les r\xE9glages actuels."
4943
- ] }),
4944
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-1.5", children: [
4945
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "neutral", children: "D\xE9sactiv\xE9" }),
4946
- " l'op\xE9rateur a coup\xE9 ce n\u0153ud lui-m\xEAme \u2014 un choix, pas un incident."
4947
- ] }),
4948
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-1.5", children: [
4949
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "warning", children: "Inatteignable" }),
4950
- " aucun ticket ne peut atteindre ce n\u0153ud aujourd'hui \u2014 voir les raisons sur sa carte."
4951
- ] })
4952
- ] })
5899
+ /* @__PURE__ */ jsxRuntime.jsx(Legend, {}),
5900
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: traffic.unavailable ? "Trafic observ\xE9 indisponible : le verdict ci-dessous reste calcul\xE9 sur les r\xE9glages seuls." : `Chiffres observ\xE9s sur les ${TRAFFIC_WINDOW_DAYS} derniers jours \u2014 seuls les n\u0153uds dont un enregistrement t\xE9moigne du passage en portent un.` }),
5901
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-0 pl-10", children: rail }),
5902
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs text-muted-foreground", children: [
5903
+ "\u21BA",
5904
+ " \xAB R\xE9vision \xBB rejoue \xAB \xC9valuation \xBB \u2014 au plus une passe par ticket",
5905
+ technical ? " (\xA73.3)" : "",
5906
+ "."
5907
+ ] }),
5908
+ /* @__PURE__ */ jsxRuntime.jsx(
5909
+ NodeDetailPanel,
5910
+ {
5911
+ node: selected,
5912
+ traffic: selected ? traffic.byNode[selected.node] : void 0,
5913
+ technical,
5914
+ appSlug,
5915
+ globalNotes: selected ? notesFor(selected.node) : [],
5916
+ onClose: () => setOpenNode(null)
5917
+ }
5918
+ )
4953
5919
  ] })
4954
5920
  ] });
4955
5921
  }
@@ -5665,6 +6631,1130 @@ function TestPage() {
5665
6631
  !canRun ? /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsx(TestControls, {})
5666
6632
  ] });
5667
6633
  }
6634
+ function ExperimentStatusBadge({ experiment }) {
6635
+ if (experiment.status === "done" && experiment.succeeded) {
6636
+ return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "success", children: "Termin\xE9" });
6637
+ }
6638
+ if (experiment.status === "done" && !experiment.succeeded) {
6639
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-0.5", children: [
6640
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "warning", children: "Termin\xE9 partiellement" }),
6641
+ experiment.note && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-status-pending", children: experiment.note })
6642
+ ] });
6643
+ }
6644
+ if (experiment.status === "failed") {
6645
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-0.5", children: [
6646
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "danger", children: "\xC9chec" }),
6647
+ experiment.error && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-status-blocked", children: experiment.error })
6648
+ ] });
6649
+ }
6650
+ if (experiment.status === "running") return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "info", children: "En cours" });
6651
+ return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "outline", children: "En attente" });
6652
+ }
6653
+
6654
+ // src/ui/quality/quality-error.ts
6655
+ var QUALITY_ERROR_MESSAGES = {
6656
+ LANGFUSE_UNCONFIGURED: "Langfuse est injoignable ou mal configur\xE9 \u2014 r\xE9essayez plus tard.",
6657
+ DATASET_NOT_FOUND: "Ce dataset n'existe pas dans Langfuse \u2014 v\xE9rifiez son nom.",
6658
+ DATASET_STORE_REQUEST_REJECTED: "Langfuse a rejet\xE9 la requ\xEAte sur ce dataset (identifiants ou quota) \u2014 le nom du dataset n'est pas forc\xE9ment en cause.",
6659
+ PROMPT_VERSION_NOT_FOUND: "Cette version de prompt n'existe pas dans Langfuse.",
6660
+ PROMPT_VERSION_STORE_REQUEST_REJECTED: "Langfuse a rejet\xE9 la requ\xEAte sur ce prompt (identifiants ou quota) \u2014 le nom ou la version ne sont pas forc\xE9ment en cause.",
6661
+ EXPERIMENT_NOT_FOUND: "Une ou plusieurs exp\xE9riences s\xE9lectionn\xE9es sont introuvables.",
6662
+ INVALID_REVIEW_SELECTION: "S\xE9lection invalide pour cr\xE9er une revue.",
6663
+ REVIEW_NOT_FOUND: "Cette revue est introuvable.",
6664
+ UNKNOWN_RUN_NAME: "Ce run ne fait pas partie de la revue.",
6665
+ UNKNOWN_DATASET_ITEM: "Cet item ne fait pas partie de la revue.",
6666
+ RUN_RESULTS_MISSING: "Un des runs s\xE9lectionn\xE9s n'a pas de r\xE9sultats persist\xE9s.",
6667
+ PROMPT_NOT_FOUND: "Ce prompt est introuvable dans Langfuse.",
6668
+ PROMPT_STORE_REQUEST_REJECTED: "Langfuse a rejet\xE9 la promotion (identifiants ou quota).",
6669
+ PROMPT_STORE_UNAVAILABLE: "Langfuse est injoignable \u2014 r\xE9essayez plus tard."
6670
+ };
6671
+ function apiErrorBody(err) {
6672
+ return err?.response?.data;
6673
+ }
6674
+ function qualityErrorMessage(err) {
6675
+ const body = apiErrorBody(err);
6676
+ if (body?.code && body.code in QUALITY_ERROR_MESSAGES) {
6677
+ return QUALITY_ERROR_MESSAGES[body.code];
6678
+ }
6679
+ return body?.message ?? "Une erreur inattendue est survenue.";
6680
+ }
6681
+ function isSelectable(experiment) {
6682
+ return experiment.status === "done";
6683
+ }
6684
+ function ExperimentsTable({
6685
+ experiments,
6686
+ isPending,
6687
+ isError,
6688
+ error,
6689
+ canSelect,
6690
+ selectedIds,
6691
+ /** Once true, every checkbox NOT already selected is disabled — the 2-3 cap must reject a 4th pick visibly, not silently no-op it. */
6692
+ atSelectionCap,
6693
+ onToggleSelect
6694
+ }) {
6695
+ if (isPending) return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Chargement\u2026" });
6696
+ if (isError) return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-destructive", children: qualityErrorMessage(error) });
6697
+ if (experiments.length === 0) {
6698
+ return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Aucune exp\xE9rience pour ce dataset." });
6699
+ }
6700
+ return /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Table, { children: [
6701
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.TableHeader, { children: /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.TableRow, { children: [
6702
+ canSelect && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.TableHead, {}),
6703
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.TableHead, { children: "Nom" }),
6704
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.TableHead, { children: "Prompt" }),
6705
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.TableHead, { children: "Statut" }),
6706
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.TableHead, { children: "Progression" })
6707
+ ] }) }),
6708
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.TableBody, { children: experiments.map((experiment) => /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.TableRow, { children: [
6709
+ canSelect && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.TableCell, { children: /* @__PURE__ */ jsxRuntime.jsx(
6710
+ uiSdk.Checkbox,
6711
+ {
6712
+ "aria-label": `S\xE9lectionner ${experiment.name}`,
6713
+ checked: selectedIds.includes(experiment.id),
6714
+ disabled: !isSelectable(experiment) || atSelectionCap && !selectedIds.includes(experiment.id),
6715
+ onCheckedChange: () => onToggleSelect(experiment.id)
6716
+ }
6717
+ ) }),
6718
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.TableCell, { children: experiment.name }),
6719
+ /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.TableCell, { children: [
6720
+ experiment.promptName,
6721
+ " v",
6722
+ experiment.promptVersion
6723
+ ] }),
6724
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.TableCell, { children: /* @__PURE__ */ jsxRuntime.jsx(ExperimentStatusBadge, { experiment }) }),
6725
+ /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.TableCell, { children: [
6726
+ experiment.progress.done,
6727
+ "/",
6728
+ experiment.progress.total
6729
+ ] })
6730
+ ] }, experiment.id)) })
6731
+ ] });
6732
+ }
6733
+ function useAsyncData(load, fallback) {
6734
+ const [data, setData] = react.useState(fallback);
6735
+ const [isLoading, setIsLoading] = react.useState(true);
6736
+ const [error, setError] = react.useState(void 0);
6737
+ const requestIdRef = react.useRef(0);
6738
+ const isMountedRef = react.useRef(true);
6739
+ const run = react.useCallback(async () => {
6740
+ const requestId = ++requestIdRef.current;
6741
+ const isCurrent = () => requestId === requestIdRef.current && isMountedRef.current;
6742
+ setIsLoading(true);
6743
+ try {
6744
+ const result = await load();
6745
+ if (!isCurrent()) return;
6746
+ setData(result);
6747
+ setError(void 0);
6748
+ } catch (err) {
6749
+ if (!isCurrent()) return;
6750
+ setError(err);
6751
+ } finally {
6752
+ if (requestId === requestIdRef.current) setIsLoading(false);
6753
+ }
6754
+ }, [load]);
6755
+ react.useEffect(() => {
6756
+ isMountedRef.current = true;
6757
+ void run();
6758
+ return () => {
6759
+ isMountedRef.current = false;
6760
+ requestIdRef.current += 1;
6761
+ };
6762
+ }, [run]);
6763
+ return { data, isLoading, error, refresh: run };
6764
+ }
6765
+ function useDatasetCatalogue() {
6766
+ const { appSlug } = uiSdk.useAppContext();
6767
+ const api = uiSdk.useAppApi();
6768
+ const apiRef = react.useRef(api);
6769
+ apiRef.current = api;
6770
+ const load = react.useCallback(
6771
+ () => apiRef.current.get(`/data/apps/${appSlug}/langfuse/datasets`),
6772
+ [appSlug]
6773
+ );
6774
+ return useAsyncData(load, []);
6775
+ }
6776
+ function useExperiments(datasetName) {
6777
+ const { appSlug } = uiSdk.useAppContext();
6778
+ const api = uiSdk.useAppApi();
6779
+ const apiRef = react.useRef(api);
6780
+ apiRef.current = api;
6781
+ const trimmed = datasetName.trim();
6782
+ const load = react.useCallback(async () => {
6783
+ if (trimmed.length === 0) return [];
6784
+ const params = new URLSearchParams({ datasetName: trimmed });
6785
+ return apiRef.current.get(
6786
+ `/data/apps/${appSlug}/quality/experiments?${params.toString()}`
6787
+ );
6788
+ }, [appSlug, trimmed]);
6789
+ return useAsyncData(load, []);
6790
+ }
6791
+ function useReview(reviewId) {
6792
+ const { appSlug } = uiSdk.useAppContext();
6793
+ const api = uiSdk.useAppApi();
6794
+ const apiRef = react.useRef(api);
6795
+ apiRef.current = api;
6796
+ const load = react.useCallback(async () => {
6797
+ if (!reviewId) return null;
6798
+ return apiRef.current.get(`/data/apps/${appSlug}/quality/reviews/${reviewId}`);
6799
+ }, [appSlug, reviewId]);
6800
+ return useAsyncData(load, null);
6801
+ }
6802
+ function useQualityActions() {
6803
+ const { appSlug } = uiSdk.useAppContext();
6804
+ const api = uiSdk.useAppApi();
6805
+ const apiRef = react.useRef(api);
6806
+ apiRef.current = api;
6807
+ return react.useMemo(() => {
6808
+ const base2 = `/data/apps/${appSlug}/quality`;
6809
+ return {
6810
+ launchExperiment: (input) => apiRef.current.post(`${base2}/experiments`, input),
6811
+ createReview: (input) => apiRef.current.post(`${base2}/reviews`, input),
6812
+ putItemReview: (reviewId, datasetItemId, patch) => apiRef.current.put(
6813
+ `${base2}/reviews/${reviewId}/items/${datasetItemId}`,
6814
+ patch
6815
+ ),
6816
+ generateSummary: (reviewId) => apiRef.current.post(`${base2}/reviews/${reviewId}/summary`),
6817
+ exportReview: (reviewId) => apiRef.current.get(`${base2}/reviews/${reviewId}/export`),
6818
+ /** Which version currently holds `label` — `{ version: null }` when none does, which is not an error. */
6819
+ promptLabelVersion: (name, label) => {
6820
+ const params = new URLSearchParams({ name, label });
6821
+ return apiRef.current.get(
6822
+ `${base2}/prompts/label?${params.toString()}`
6823
+ );
6824
+ },
6825
+ /**
6826
+ * Promotion goes through the PROMPTS primitive, not the quality one:
6827
+ * `/quality/prompts/promote` was a second door onto the same
6828
+ * company-wide write and was removed with the platform section.
6829
+ */
6830
+ promotePrompt: (name, version, label) => apiRef.current.post(`/data/apps/${appSlug}/prompts/promote`, {
6831
+ name,
6832
+ version,
6833
+ label
6834
+ })
6835
+ };
6836
+ }, [appSlug]);
6837
+ }
6838
+ function parsePositiveInteger(value) {
6839
+ const n = Number(value);
6840
+ return Number.isInteger(n) && n > 0 ? n : null;
6841
+ }
6842
+ function LaunchExperimentForm({
6843
+ datasetName,
6844
+ initialPromptName,
6845
+ initialPromptVersion,
6846
+ initialAgentId,
6847
+ onLaunched
6848
+ }) {
6849
+ const toast = uiSdk.useToast();
6850
+ const actions = useQualityActions();
6851
+ const [isLaunching, setIsLaunching] = react.useState(false);
6852
+ const [name, setName] = react.useState("");
6853
+ const [agentId, setAgentId] = react.useState(initialAgentId ?? "");
6854
+ const [promptName, setPromptName] = react.useState(initialPromptName ?? "");
6855
+ const initialPromptVersionParsed = initialPromptVersion ? parsePositiveInteger(initialPromptVersion) : null;
6856
+ const [promptVersion, setPromptVersion] = react.useState(
6857
+ initialPromptVersionParsed !== null ? String(initialPromptVersionParsed) : ""
6858
+ );
6859
+ const parsedPromptVersion = parsePositiveInteger(promptVersion);
6860
+ const canSubmit = datasetName.trim().length > 0 && name.trim().length > 0 && agentId.trim().length > 0 && promptName.trim().length > 0 && parsedPromptVersion !== null;
6861
+ const onSubmit = async (event) => {
6862
+ event.preventDefault();
6863
+ if (!canSubmit || parsedPromptVersion === null) return;
6864
+ setIsLaunching(true);
6865
+ try {
6866
+ const experiment = await actions.launchExperiment({
6867
+ datasetName: datasetName.trim(),
6868
+ name: name.trim(),
6869
+ agentId: agentId.trim(),
6870
+ promptName: promptName.trim(),
6871
+ promptVersion: parsedPromptVersion
6872
+ });
6873
+ toast({ title: "Exp\xE9rience lanc\xE9e", description: experiment.name });
6874
+ setName("");
6875
+ onLaunched(experiment);
6876
+ } catch (err) {
6877
+ toast({
6878
+ title: "Lancement impossible",
6879
+ description: qualityErrorMessage(err),
6880
+ variant: "error"
6881
+ });
6882
+ } finally {
6883
+ setIsLaunching(false);
6884
+ }
6885
+ };
6886
+ return /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Card, { children: [
6887
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardTitle, { children: "Lancer une exp\xE9rience" }) }),
6888
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardContent, { children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: (e) => void onSubmit(e), className: "grid gap-3 sm:grid-cols-2", children: [
6889
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs text-muted-foreground sm:col-span-2", children: [
6890
+ "Dataset : ",
6891
+ /* @__PURE__ */ jsxRuntime.jsx("code", { className: "font-mono", children: datasetName.trim() || "\u2014" })
6892
+ ] }),
6893
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
6894
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "quality-launch-name", className: "block text-sm font-medium", children: "Nom" }),
6895
+ /* @__PURE__ */ jsxRuntime.jsx(
6896
+ uiSdk.Input,
6897
+ {
6898
+ id: "quality-launch-name",
6899
+ value: name,
6900
+ onChange: (e) => setName(e.target.value),
6901
+ placeholder: "ex. triage v3 vs v4"
6902
+ }
6903
+ )
6904
+ ] }),
6905
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
6906
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "quality-launch-agent", className: "block text-sm font-medium", children: "Identifiant de l'agent" }),
6907
+ /* @__PURE__ */ jsxRuntime.jsx(
6908
+ uiSdk.Input,
6909
+ {
6910
+ id: "quality-launch-agent",
6911
+ value: agentId,
6912
+ onChange: (e) => setAgentId(e.target.value),
6913
+ "aria-describedby": "quality-launch-agent-help",
6914
+ placeholder: "ex. 7f3c1a2e-\u2026"
6915
+ }
6916
+ ),
6917
+ /* @__PURE__ */ jsxRuntime.jsx("p", { id: "quality-launch-agent-help", className: "text-xs text-muted-foreground", children: "Visible sur la page Agents de l'app \u2014 le lien \xAB Qualit\xE9 \xBB de cette page le pr\xE9-remplit." })
6918
+ ] }),
6919
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
6920
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "quality-launch-prompt", className: "block text-sm font-medium", children: "Prompt" }),
6921
+ /* @__PURE__ */ jsxRuntime.jsx(
6922
+ uiSdk.Input,
6923
+ {
6924
+ id: "quality-launch-prompt",
6925
+ value: promptName,
6926
+ onChange: (e) => setPromptName(e.target.value),
6927
+ placeholder: "ex. triage"
6928
+ }
6929
+ )
6930
+ ] }),
6931
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
6932
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "quality-launch-version", className: "block text-sm font-medium", children: "Version" }),
6933
+ /* @__PURE__ */ jsxRuntime.jsx(
6934
+ uiSdk.Input,
6935
+ {
6936
+ id: "quality-launch-version",
6937
+ type: "number",
6938
+ min: 1,
6939
+ value: promptVersion,
6940
+ onChange: (e) => setPromptVersion(e.target.value)
6941
+ }
6942
+ )
6943
+ ] }),
6944
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "sm:col-span-2", children: /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { type: "submit", disabled: !canSubmit || isLaunching, children: isLaunching ? "Lancement\u2026" : "Lancer" }) })
6945
+ ] }) })
6946
+ ] });
6947
+ }
6948
+ var MAX_REVIEW_EXPERIMENTS = 3;
6949
+ function toggleSelection(selected, id) {
6950
+ if (selected.includes(id)) return selected.filter((existing) => existing !== id);
6951
+ if (selected.length >= MAX_REVIEW_EXPERIMENTS) return selected;
6952
+ return [...selected, id];
6953
+ }
6954
+ function ExperimentsView({
6955
+ canEdit,
6956
+ onReviewCreated
6957
+ }) {
6958
+ const toast = uiSdk.useToast();
6959
+ const actions = useQualityActions();
6960
+ const promptName = useQueryParam("promptName").value;
6961
+ const promptVersion = useQueryParam("promptVersion").value;
6962
+ const agentId = useQueryParam("agentId").value;
6963
+ const [datasetName, setDatasetName] = react.useState("");
6964
+ const [selectedIds, setSelectedIds] = react.useState([]);
6965
+ const [reviewName, setReviewName] = react.useState("");
6966
+ const [isCreating, setIsCreating] = react.useState(false);
6967
+ const datasets = useDatasetCatalogue();
6968
+ const experiments = useExperiments(datasetName);
6969
+ const canCreateReview = canEdit && selectedIds.length >= 2 && selectedIds.length <= MAX_REVIEW_EXPERIMENTS && reviewName.trim().length > 0;
6970
+ const onCreateReview = async () => {
6971
+ setIsCreating(true);
6972
+ try {
6973
+ const review = await actions.createReview({
6974
+ name: reviewName.trim(),
6975
+ experimentIds: selectedIds
6976
+ });
6977
+ onReviewCreated(review.id);
6978
+ } catch (err) {
6979
+ toast({
6980
+ title: "Cr\xE9ation de la revue impossible",
6981
+ description: qualityErrorMessage(err),
6982
+ variant: "error"
6983
+ });
6984
+ } finally {
6985
+ setIsCreating(false);
6986
+ }
6987
+ };
6988
+ return /* @__PURE__ */ jsxRuntime.jsxs(PageShell, { children: [
6989
+ /* @__PURE__ */ jsxRuntime.jsx(PageHeader, { title: "Qualit\xE9" }),
6990
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "max-w-md space-y-1.5", children: [
6991
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "quality-dataset", className: "block text-sm font-medium", children: "Dataset" }),
6992
+ /* @__PURE__ */ jsxRuntime.jsx(
6993
+ SearchableSelect,
6994
+ {
6995
+ id: "quality-dataset",
6996
+ options: datasets.data.map((dataset) => ({
6997
+ value: dataset.name,
6998
+ label: dataset.name,
6999
+ keywords: dataset.description ?? ""
7000
+ })),
7001
+ value: datasetName,
7002
+ onChange: (next) => {
7003
+ setDatasetName(next);
7004
+ setSelectedIds([]);
7005
+ },
7006
+ disabled: datasets.isLoading,
7007
+ labels: {
7008
+ fallbackAriaLabel: "Dataset",
7009
+ searchAriaLabel: "Chercher un dataset",
7010
+ searchPlaceholder: "Taper une partie du nom du dataset\u2026",
7011
+ current: (name) => `Dataset actuel : ${name}`,
7012
+ none: "Aucun dataset choisi.",
7013
+ noMatch: "Aucun dataset ne correspond.",
7014
+ truncated: (total) => `${total} datasets au total \u2014 affine la recherche pour voir les autres.`
7015
+ }
7016
+ }
7017
+ ),
7018
+ datasets.error !== void 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: "Catalogue Langfuse indisponible \u2014 saisissez le nom du dataset \xE0 la main." })
7019
+ ] }),
7020
+ canEdit && /* @__PURE__ */ jsxRuntime.jsx(
7021
+ LaunchExperimentForm,
7022
+ {
7023
+ datasetName,
7024
+ initialPromptName: promptName ?? void 0,
7025
+ initialPromptVersion: promptVersion ?? void 0,
7026
+ initialAgentId: agentId ?? void 0,
7027
+ onLaunched: () => void experiments.refresh()
7028
+ }
7029
+ ),
7030
+ /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Card, { children: [
7031
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardTitle, { children: "Runs" }) }),
7032
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardContent, { className: "space-y-4", children: datasetName.trim().length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Choisissez un dataset pour voir ses runs." }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
7033
+ canEdit && experiments.data.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: "S\xE9lectionnez 2 \xE0 3 runs termin\xE9s pour cr\xE9er une revue." }),
7034
+ /* @__PURE__ */ jsxRuntime.jsx(
7035
+ ExperimentsTable,
7036
+ {
7037
+ experiments: experiments.data,
7038
+ isPending: experiments.isLoading,
7039
+ isError: experiments.error !== void 0,
7040
+ error: experiments.error,
7041
+ canSelect: canEdit,
7042
+ selectedIds,
7043
+ atSelectionCap: selectedIds.length >= MAX_REVIEW_EXPERIMENTS,
7044
+ onToggleSelect: (id) => setSelectedIds((prev) => toggleSelection(prev, id))
7045
+ }
7046
+ ),
7047
+ canEdit && experiments.data.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-end gap-2", children: [
7048
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
7049
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "quality-review-name", className: "block text-sm font-medium", children: "Nom de la revue" }),
7050
+ /* @__PURE__ */ jsxRuntime.jsx(
7051
+ uiSdk.Input,
7052
+ {
7053
+ id: "quality-review-name",
7054
+ value: reviewName,
7055
+ onChange: (e) => setReviewName(e.target.value),
7056
+ placeholder: "ex. triage v3 vs v4"
7057
+ }
7058
+ )
7059
+ ] }),
7060
+ /* @__PURE__ */ jsxRuntime.jsx(
7061
+ uiSdk.Button,
7062
+ {
7063
+ disabled: !canCreateReview || isCreating,
7064
+ onClick: () => void onCreateReview(),
7065
+ children: isCreating ? "Cr\xE9ation\u2026" : "Cr\xE9er la revue"
7066
+ }
7067
+ )
7068
+ ] })
7069
+ ] }) })
7070
+ ] })
7071
+ ] });
7072
+ }
7073
+
7074
+ // src/ui/quality/quality-role.ts
7075
+ function canEditQuality(platformRole) {
7076
+ return platformRole === "EDITOR" || platformRole === "ADMIN";
7077
+ }
7078
+ function ExportReviewButton({ reviewId }) {
7079
+ const toast = uiSdk.useToast();
7080
+ const actions = useQualityActions();
7081
+ const [busy, setBusy] = react.useState(false);
7082
+ const onExport = async () => {
7083
+ setBusy(true);
7084
+ try {
7085
+ const payload = await actions.exportReview(reviewId);
7086
+ uiSdk.downloadBlob(
7087
+ new Blob([JSON.stringify(payload, null, 2)], { type: "application/json" }),
7088
+ `revue-${reviewId}.json`
7089
+ );
7090
+ } catch (err) {
7091
+ toast({
7092
+ title: "Export impossible",
7093
+ description: qualityErrorMessage(err),
7094
+ variant: "error"
7095
+ });
7096
+ } finally {
7097
+ setBusy(false);
7098
+ }
7099
+ };
7100
+ return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", size: "sm", onClick: onExport, disabled: busy, children: busy ? "Export\u2026" : "Exporter" });
7101
+ }
7102
+
7103
+ // src/ui/quality/quality-format.ts
7104
+ function formatScore(value) {
7105
+ return value.toFixed(2);
7106
+ }
7107
+ var CHART_COLOR_CLASSES = [
7108
+ { stroke: "stroke-chart-1", fill: "fill-chart-1" },
7109
+ { stroke: "stroke-chart-2", fill: "fill-chart-2" },
7110
+ { stroke: "stroke-chart-3", fill: "fill-chart-3" },
7111
+ { stroke: "stroke-chart-4", fill: "fill-chart-4" },
7112
+ { stroke: "stroke-chart-5", fill: "fill-chart-5" }
7113
+ ];
7114
+ function colorClassesAt(index) {
7115
+ return CHART_COLOR_CLASSES[index % CHART_COLOR_CLASSES.length];
7116
+ }
7117
+ function axisPoint(index, count, radius, cx, cy) {
7118
+ const angle = -Math.PI / 2 + index * 2 * Math.PI / count;
7119
+ return { x: cx + radius * Math.cos(angle), y: cy + radius * Math.sin(angle) };
7120
+ }
7121
+ function polygonPoints(values, maxValue, radius, cx, cy) {
7122
+ return values.map((value, index) => {
7123
+ const clamped = Math.max(0, Math.min(value / maxValue, 1));
7124
+ const point = axisPoint(index, values.length, radius * clamped, cx, cy);
7125
+ return `${point.x},${point.y}`;
7126
+ }).join(" ");
7127
+ }
7128
+ function seriesPoints(values, maxValue, radius, cx, cy) {
7129
+ return values.map((value, index) => {
7130
+ if (value === null) return null;
7131
+ const clamped = Math.max(0, Math.min(value / maxValue, 1));
7132
+ return axisPoint(index, values.length, radius * clamped, cx, cy);
7133
+ });
7134
+ }
7135
+ function seriesPathD(points) {
7136
+ const n = points.length;
7137
+ if (n === 0) return "";
7138
+ const commands = [];
7139
+ let drawing = false;
7140
+ for (let i = 0; i <= n; i++) {
7141
+ const point = points[i % n];
7142
+ if (!point) {
7143
+ drawing = false;
7144
+ continue;
7145
+ }
7146
+ commands.push(`${drawing ? "L" : "M"}${point.x},${point.y}`);
7147
+ drawing = true;
7148
+ }
7149
+ return commands.join(" ");
7150
+ }
7151
+ var GRID_RINGS = [0.25, 0.5, 0.75, 1];
7152
+ function ScoreRadarChart({
7153
+ axes,
7154
+ series,
7155
+ maxValue = 1,
7156
+ size = 260,
7157
+ className
7158
+ }) {
7159
+ const cx = size / 2;
7160
+ const cy = size / 2;
7161
+ const radius = size / 2 - 32;
7162
+ const label = series.map((s) => s.label).join(", ") || "Aucun run s\xE9lectionn\xE9";
7163
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: uiSdk.cn("w-full max-w-80", className), children: [
7164
+ /* @__PURE__ */ jsxRuntime.jsxs(
7165
+ "svg",
7166
+ {
7167
+ role: "img",
7168
+ "aria-label": `Radar de scores \u2014 ${label}`,
7169
+ viewBox: `0 0 ${size} ${size}`,
7170
+ className: "w-full",
7171
+ children: [
7172
+ axes.length > 0 && GRID_RINGS.map((ring) => /* @__PURE__ */ jsxRuntime.jsx(
7173
+ "polygon",
7174
+ {
7175
+ points: polygonPoints(
7176
+ axes.map(() => maxValue),
7177
+ maxValue * ring,
7178
+ radius,
7179
+ cx,
7180
+ cy
7181
+ ),
7182
+ className: "fill-none stroke-border",
7183
+ strokeWidth: 1
7184
+ },
7185
+ ring
7186
+ )),
7187
+ axes.map((axis, index) => {
7188
+ const tip = axisPoint(index, axes.length, radius, cx, cy);
7189
+ const labelPoint = axisPoint(index, axes.length, radius + 18, cx, cy);
7190
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
7191
+ /* @__PURE__ */ jsxRuntime.jsx(
7192
+ "line",
7193
+ {
7194
+ x1: cx,
7195
+ y1: cy,
7196
+ x2: tip.x,
7197
+ y2: tip.y,
7198
+ className: "stroke-border",
7199
+ strokeWidth: 1
7200
+ }
7201
+ ),
7202
+ /* @__PURE__ */ jsxRuntime.jsx(
7203
+ "text",
7204
+ {
7205
+ x: labelPoint.x,
7206
+ y: labelPoint.y,
7207
+ textAnchor: "middle",
7208
+ dominantBaseline: "middle",
7209
+ className: "fill-muted-foreground text-[9px]",
7210
+ children: axis
7211
+ }
7212
+ )
7213
+ ] }, axis);
7214
+ }),
7215
+ series.map((entry) => {
7216
+ const colors = colorClassesAt(entry.colorIndex);
7217
+ const isComplete = entry.values.every((value) => value !== null);
7218
+ const points = seriesPoints(entry.values, maxValue, radius, cx, cy);
7219
+ return /* @__PURE__ */ jsxRuntime.jsx(
7220
+ "path",
7221
+ {
7222
+ "data-series": entry.key,
7223
+ d: seriesPathD(points),
7224
+ className: uiSdk.cn(
7225
+ colors.stroke,
7226
+ isComplete ? uiSdk.cn(colors.fill, "fill-opacity-15") : "fill-none"
7227
+ ),
7228
+ strokeWidth: 2
7229
+ },
7230
+ entry.key
7231
+ );
7232
+ })
7233
+ ]
7234
+ }
7235
+ ),
7236
+ series.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "mt-2 flex flex-wrap gap-x-4 gap-y-1", children: series.map((entry) => {
7237
+ const colors = colorClassesAt(entry.colorIndex);
7238
+ return /* @__PURE__ */ jsxRuntime.jsxs(
7239
+ "li",
7240
+ {
7241
+ className: "flex items-center gap-1.5 text-xs text-muted-foreground",
7242
+ children: [
7243
+ /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": true, className: uiSdk.cn("size-2.5 rounded-sm", colors.fill) }),
7244
+ entry.label
7245
+ ]
7246
+ },
7247
+ entry.key
7248
+ );
7249
+ }) })
7250
+ ] });
7251
+ }
7252
+ function formatScoreWithDenominator(value, scoredCount, itemCount) {
7253
+ return `${formatScore(value)} (${scoredCount}/${itemCount})`;
7254
+ }
7255
+ function coverageLabel(run) {
7256
+ const worstCoverage = run.scores.length > 0 ? Math.min(...run.scores.map((s) => s.scoredCount)) : 0;
7257
+ return `${run.label} (${worstCoverage}/${run.itemCount})`;
7258
+ }
7259
+ function collectCriteria(histogram) {
7260
+ const seen = /* @__PURE__ */ new Set();
7261
+ for (const run of histogram) {
7262
+ for (const score of run.scores) seen.add(score.criterion);
7263
+ }
7264
+ return [...seen];
7265
+ }
7266
+ function toRadarSeries(histogram, axes) {
7267
+ return histogram.map((run, index) => ({
7268
+ key: run.runName,
7269
+ label: coverageLabel(run),
7270
+ colorIndex: index,
7271
+ values: axes.map((axis) => run.scores.find((score) => score.criterion === axis)?.value ?? null)
7272
+ }));
7273
+ }
7274
+ function ReviewHistogram({
7275
+ histogram,
7276
+ runs
7277
+ }) {
7278
+ if (histogram.length === 0) {
7279
+ return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Pas encore de scores." });
7280
+ }
7281
+ const axes = collectCriteria(histogram);
7282
+ const succeededByRunName = new Map(runs.map((run) => [run.runName, run.succeeded]));
7283
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
7284
+ /* @__PURE__ */ jsxRuntime.jsx(ScoreRadarChart, { axes, series: toRadarSeries(histogram, axes) }),
7285
+ /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "w-full text-sm", children: [
7286
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: "text-xs text-muted-foreground", children: [
7287
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "py-1 pr-2 text-left font-medium", children: "Crit\xE8re" }),
7288
+ histogram.map((run) => /* @__PURE__ */ jsxRuntime.jsxs("th", { className: "px-2 py-1 text-left font-medium", children: [
7289
+ run.label,
7290
+ succeededByRunName.get(run.runName) === false && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-0.5 font-normal", children: /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "warning", children: "Termin\xE9 partiellement" }) })
7291
+ ] }, run.runName))
7292
+ ] }) }),
7293
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: axes.map((axis) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: "border-t", children: [
7294
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "py-1.5 pr-2 font-mono text-xs text-muted-foreground", children: axis }),
7295
+ histogram.map((run) => {
7296
+ const score = run.scores.find((s) => s.criterion === axis);
7297
+ return /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-2 py-1.5 tabular-nums", children: score ? formatScoreWithDenominator(score.value, score.scoredCount, run.itemCount) : "\u2014" }, run.runName);
7298
+ })
7299
+ ] }, axis)) })
7300
+ ] })
7301
+ ] });
7302
+ }
7303
+ function ItemListEntry({
7304
+ item,
7305
+ isSelected,
7306
+ onSelect
7307
+ }) {
7308
+ return /* @__PURE__ */ jsxRuntime.jsxs(
7309
+ "button",
7310
+ {
7311
+ type: "button",
7312
+ onClick: onSelect,
7313
+ className: uiSdk.cn(
7314
+ "flex w-full items-center justify-between gap-2 rounded-md px-3 py-1.5 text-left text-sm",
7315
+ isSelected ? "bg-muted font-medium text-foreground" : "text-muted-foreground hover:bg-muted/60"
7316
+ ),
7317
+ children: [
7318
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate font-mono text-xs", children: item.datasetItemId }),
7319
+ item.review.bestRunName && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "brand", children: item.review.bestRunName })
7320
+ ]
7321
+ }
7322
+ );
7323
+ }
7324
+ function OutputCard({
7325
+ output,
7326
+ isBest,
7327
+ canEdit,
7328
+ onPickBest
7329
+ }) {
7330
+ return /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Card, { children: [
7331
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardTitle, { className: "text-sm", children: output.label }) }),
7332
+ /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.CardContent, { className: "space-y-2", children: [
7333
+ output.hasResult ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
7334
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "whitespace-pre-wrap text-sm", children: output.output ?? "\u2014" }),
7335
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-1.5", children: output.scores.map((score) => /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Badge, { variant: "outline", children: [
7336
+ score.criterion,
7337
+ ": ",
7338
+ formatScore(score.value)
7339
+ ] }, score.criterion)) })
7340
+ ] }) : (
7341
+ // D1 — a run that crashed on this item or never saw it (dataset
7342
+ // grew after this run launched) must never read as "this run
7343
+ // answered with nothing", which is a model-quality signal. It also
7344
+ // must never be offered as the best answer: the best-run
7345
+ // distribution feeding the synthesis would then be polled on a run
7346
+ // that produced no output at all.
7347
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm italic text-muted-foreground", children: "Aucun r\xE9sultat pour ce run." })
7348
+ ),
7349
+ canEdit && output.hasResult && /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Button, { size: "sm", variant: isBest ? "default" : "outline", onClick: onPickBest, children: [
7350
+ "Meilleure r\xE9ponse \u2014 ",
7351
+ output.label
7352
+ ] })
7353
+ ] })
7354
+ ] });
7355
+ }
7356
+ function ItemDetail({
7357
+ reviewId,
7358
+ item,
7359
+ canEdit,
7360
+ onSaved
7361
+ }) {
7362
+ const toast = uiSdk.useToast();
7363
+ const actions = useQualityActions();
7364
+ const [isSaving, setIsSaving] = react.useState(false);
7365
+ const [bestRunName, setBestRunName] = react.useState(item.review.bestRunName);
7366
+ const [comment, setComment] = react.useState(item.review.comment);
7367
+ react.useEffect(() => {
7368
+ setBestRunName(item.review.bestRunName);
7369
+ setComment(item.review.comment);
7370
+ }, [item.datasetItemId, item.review.bestRunName, item.review.comment]);
7371
+ const onSave = async () => {
7372
+ setIsSaving(true);
7373
+ try {
7374
+ const saved = await actions.putItemReview(reviewId, item.datasetItemId, {
7375
+ bestRunName,
7376
+ comment
7377
+ });
7378
+ onSaved(item.datasetItemId, saved);
7379
+ toast({ title: "Revue enregistr\xE9e" });
7380
+ } catch (err) {
7381
+ toast({
7382
+ title: "Enregistrement impossible",
7383
+ description: qualityErrorMessage(err),
7384
+ variant: "error"
7385
+ });
7386
+ } finally {
7387
+ setIsSaving(false);
7388
+ }
7389
+ };
7390
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4", children: [
7391
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid gap-3 sm:grid-cols-2", children: item.outputs.map((output) => /* @__PURE__ */ jsxRuntime.jsx(
7392
+ OutputCard,
7393
+ {
7394
+ output,
7395
+ isBest: bestRunName === output.runName,
7396
+ canEdit,
7397
+ onPickBest: () => setBestRunName(output.runName)
7398
+ },
7399
+ output.runName
7400
+ )) }),
7401
+ item.review.judgeVerdicts.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-1.5", children: item.review.judgeVerdicts.map((verdict) => /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Badge, { variant: "outline", children: [
7402
+ verdict.runName,
7403
+ " : ",
7404
+ verdict.verdict
7405
+ ] }, verdict.runName)) }),
7406
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
7407
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "quality-item-comment", className: "block text-sm font-medium", children: "Commentaire" }),
7408
+ /* @__PURE__ */ jsxRuntime.jsx(
7409
+ uiSdk.Textarea,
7410
+ {
7411
+ id: "quality-item-comment",
7412
+ value: comment,
7413
+ disabled: !canEdit,
7414
+ onChange: (e) => setComment(e.target.value)
7415
+ }
7416
+ )
7417
+ ] }),
7418
+ canEdit && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { onClick: () => void onSave(), disabled: isSaving, children: isSaving ? "Enregistrement\u2026" : "Enregistrer" })
7419
+ ] });
7420
+ }
7421
+ function ReviewItemsPanel({
7422
+ reviewId,
7423
+ items,
7424
+ canEdit,
7425
+ onItemSaved
7426
+ }) {
7427
+ const [selectedId, setSelectedId] = react.useState(items[0]?.datasetItemId);
7428
+ const selected = items.find((item) => item.datasetItemId === selectedId) ?? items[0];
7429
+ if (items.length === 0) {
7430
+ return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Aucun item \xE0 revoir." });
7431
+ }
7432
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-4 md:grid-cols-[220px_1fr]", children: [
7433
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-0.5", children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
7434
+ ItemListEntry,
7435
+ {
7436
+ item,
7437
+ isSelected: item.datasetItemId === selected?.datasetItemId,
7438
+ onSelect: () => setSelectedId(item.datasetItemId)
7439
+ },
7440
+ item.datasetItemId
7441
+ )) }),
7442
+ selected && /* @__PURE__ */ jsxRuntime.jsx(ItemDetail, { reviewId, item: selected, canEdit, onSaved: onItemSaved })
7443
+ ] });
7444
+ }
7445
+ function useCurrentLabelHolder(promptName, label) {
7446
+ const actions = useQualityActions();
7447
+ const [version, setVersion] = react.useState(null);
7448
+ const [isLoading, setIsLoading] = react.useState(false);
7449
+ react.useEffect(() => {
7450
+ if (!label) {
7451
+ setVersion(null);
7452
+ return;
7453
+ }
7454
+ let cancelled = false;
7455
+ setIsLoading(true);
7456
+ actions.promptLabelVersion(promptName, label).then((result) => {
7457
+ if (!cancelled) setVersion(result.version);
7458
+ }).catch(() => {
7459
+ if (!cancelled) setVersion(null);
7460
+ }).finally(() => {
7461
+ if (!cancelled) setIsLoading(false);
7462
+ });
7463
+ return () => {
7464
+ cancelled = true;
7465
+ };
7466
+ }, [actions, promptName, label]);
7467
+ return { version, isLoading };
7468
+ }
7469
+ var KNOWN_PROMPT_LABELS = ["production", "staging"];
7470
+ var CUSTOM_LABEL_OPTION = "__custom__";
7471
+ function PromoteRunDialog({
7472
+ run,
7473
+ open,
7474
+ onClose
7475
+ }) {
7476
+ const toast = uiSdk.useToast();
7477
+ const actions = useQualityActions();
7478
+ const [selectedOption, setSelectedOption] = react.useState(KNOWN_PROMPT_LABELS[0]);
7479
+ const [customLabel, setCustomLabel] = react.useState("");
7480
+ const [isPromoting, setIsPromoting] = react.useState(false);
7481
+ const label = selectedOption === CUSTOM_LABEL_OPTION ? customLabel.trim() : selectedOption;
7482
+ const currentHolder = useCurrentLabelHolder(run.promptName, label);
7483
+ const onConfirm = async () => {
7484
+ if (!label) return;
7485
+ setIsPromoting(true);
7486
+ try {
7487
+ await actions.promotePrompt(run.promptName, run.promptVersion, label);
7488
+ toast({
7489
+ title: "Version promue",
7490
+ description: `${run.promptName} v${run.promptVersion} \u2192 ${label}`
7491
+ });
7492
+ onClose();
7493
+ } catch (err) {
7494
+ toast({
7495
+ title: "Promotion impossible",
7496
+ description: qualityErrorMessage(err),
7497
+ variant: "error"
7498
+ });
7499
+ } finally {
7500
+ setIsPromoting(false);
7501
+ }
7502
+ };
7503
+ return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Modal, { open, onClose, title: `Promouvoir ${run.label}`, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
7504
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm text-muted-foreground", children: [
7505
+ run.promptName,
7506
+ " v",
7507
+ run.promptVersion
7508
+ ] }),
7509
+ !run.succeeded && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-0.5", children: [
7510
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "warning", children: "Termin\xE9 partiellement" }),
7511
+ run.note && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-status-pending", children: run.note })
7512
+ ] }),
7513
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm text-muted-foreground", children: [
7514
+ "Cette action est ",
7515
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium text-foreground", children: "irr\xE9versible" }),
7516
+ " et s'applique imm\xE9diatement \xE0",
7517
+ " ",
7518
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium text-foreground", children: "toutes les apps" }),
7519
+ " qui r\xE9solvent",
7520
+ " ",
7521
+ /* @__PURE__ */ jsxRuntime.jsxs("code", { className: "font-mono", children: [
7522
+ run.promptName,
7523
+ "@",
7524
+ label || "\u2026"
7525
+ ] }),
7526
+ " ",
7527
+ "\u2014 les noms de prompts ne sont pas cloisonn\xE9s par app."
7528
+ ] }),
7529
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1.5", children: [
7530
+ /* @__PURE__ */ jsxRuntime.jsx("label", { id: "quality-promote-label-group", className: "block text-sm font-medium", children: "Label" }),
7531
+ /* @__PURE__ */ jsxRuntime.jsxs(
7532
+ "div",
7533
+ {
7534
+ role: "radiogroup",
7535
+ "aria-labelledby": "quality-promote-label-group",
7536
+ className: "space-y-1.5",
7537
+ children: [
7538
+ KNOWN_PROMPT_LABELS.map((known) => /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "flex items-center gap-2 text-sm", children: [
7539
+ /* @__PURE__ */ jsxRuntime.jsx(
7540
+ "input",
7541
+ {
7542
+ type: "radio",
7543
+ name: "quality-promote-label",
7544
+ value: known,
7545
+ checked: selectedOption === known,
7546
+ onChange: () => setSelectedOption(known)
7547
+ }
7548
+ ),
7549
+ known
7550
+ ] }, known)),
7551
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "flex items-center gap-2 text-sm", children: [
7552
+ /* @__PURE__ */ jsxRuntime.jsx(
7553
+ "input",
7554
+ {
7555
+ type: "radio",
7556
+ name: "quality-promote-label",
7557
+ value: CUSTOM_LABEL_OPTION,
7558
+ checked: selectedOption === CUSTOM_LABEL_OPTION,
7559
+ onChange: () => setSelectedOption(CUSTOM_LABEL_OPTION)
7560
+ }
7561
+ ),
7562
+ "Autre"
7563
+ ] }),
7564
+ selectedOption === CUSTOM_LABEL_OPTION && /* @__PURE__ */ jsxRuntime.jsx(
7565
+ uiSdk.Input,
7566
+ {
7567
+ "aria-label": "Label personnalis\xE9",
7568
+ value: customLabel,
7569
+ onChange: (e) => setCustomLabel(e.target.value),
7570
+ className: "ml-6 w-auto"
7571
+ }
7572
+ )
7573
+ ]
7574
+ }
7575
+ )
7576
+ ] }),
7577
+ label && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: currentHolder.isLoading ? "V\xE9rification de la version actuelle\u2026" : currentHolder.version != null ? `Actuellement : ${run.promptName} v${currentHolder.version} porte le label \xAB ${label} \xBB.` : `Aucune version ne porte actuellement le label \xAB ${label} \xBB.` }),
7578
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
7579
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", size: "sm", onClick: onClose, children: "Annuler" }),
7580
+ /* @__PURE__ */ jsxRuntime.jsx(
7581
+ uiSdk.Button,
7582
+ {
7583
+ variant: "destructive",
7584
+ size: "sm",
7585
+ onClick: () => void onConfirm(),
7586
+ disabled: isPromoting || !label,
7587
+ children: isPromoting ? "Promotion\u2026" : "Promouvoir d\xE9finitivement"
7588
+ }
7589
+ )
7590
+ ] })
7591
+ ] }) });
7592
+ }
7593
+ function ReviewRunsSummary({ runs, canEdit }) {
7594
+ const [promoting, setPromoting] = react.useState(null);
7595
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-3", children: [
7596
+ runs.map((run) => /* @__PURE__ */ jsxRuntime.jsxs(
7597
+ "div",
7598
+ {
7599
+ "data-testid": `review-run-${run.runName}`,
7600
+ className: "flex items-center gap-3 rounded-md border px-3 py-2",
7601
+ children: [
7602
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7603
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium", children: run.label }),
7604
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs text-muted-foreground", children: [
7605
+ run.promptName,
7606
+ " v",
7607
+ run.promptVersion
7608
+ ] })
7609
+ ] }),
7610
+ run.succeeded ? /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "success", children: "Termin\xE9" }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-0.5", children: [
7611
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "warning", children: "Termin\xE9 partiellement" }),
7612
+ run.note && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-status-pending", children: run.note })
7613
+ ] }),
7614
+ canEdit && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { size: "sm", variant: "outline", onClick: () => setPromoting(run), children: "Promouvoir" })
7615
+ ]
7616
+ },
7617
+ run.runName
7618
+ )),
7619
+ promoting && /* @__PURE__ */ jsxRuntime.jsx(PromoteRunDialog, { run: promoting, open: true, onClose: () => setPromoting(null) })
7620
+ ] });
7621
+ }
7622
+ function formatGeneratedAt(iso) {
7623
+ const date = new Date(iso);
7624
+ return Number.isNaN(date.getTime()) ? iso : date.toLocaleString("fr-FR");
7625
+ }
7626
+ function ReviewSummaryCard({
7627
+ reviewId,
7628
+ summary,
7629
+ canEdit,
7630
+ onGenerated
7631
+ }) {
7632
+ const toast = uiSdk.useToast();
7633
+ const actions = useQualityActions();
7634
+ const [isGenerating, setIsGenerating] = react.useState(false);
7635
+ const onGenerate = async () => {
7636
+ setIsGenerating(true);
7637
+ try {
7638
+ onGenerated(await actions.generateSummary(reviewId));
7639
+ } catch (err) {
7640
+ toast({
7641
+ title: "Synth\xE8se impossible",
7642
+ description: qualityErrorMessage(err),
7643
+ variant: "error"
7644
+ });
7645
+ } finally {
7646
+ setIsGenerating(false);
7647
+ }
7648
+ };
7649
+ return /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Card, { children: [
7650
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardTitle, { children: "Synth\xE8se" }) }),
7651
+ /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.CardContent, { className: "space-y-3", children: [
7652
+ summary ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7653
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "whitespace-pre-wrap text-sm", children: summary.text }),
7654
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "mt-2 text-xs text-muted-foreground", children: [
7655
+ summary.modelId,
7656
+ " \u2014 ",
7657
+ formatGeneratedAt(summary.generatedAt)
7658
+ ] })
7659
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Aucune synth\xE8se pour le moment." }),
7660
+ canEdit && /* @__PURE__ */ jsxRuntime.jsx(
7661
+ uiSdk.Button,
7662
+ {
7663
+ variant: "outline",
7664
+ size: "sm",
7665
+ disabled: isGenerating,
7666
+ onClick: () => void onGenerate(),
7667
+ children: isGenerating ? "G\xE9n\xE9ration\u2026" : "G\xE9n\xE9rer la synth\xE8se"
7668
+ }
7669
+ )
7670
+ ] })
7671
+ ] });
7672
+ }
7673
+ function ReviewView({
7674
+ reviewId,
7675
+ canEdit,
7676
+ onBack
7677
+ }) {
7678
+ const loaded = useReview(reviewId);
7679
+ const [review, setReview] = react.useState(loaded.data);
7680
+ react.useEffect(() => {
7681
+ setReview(loaded.data);
7682
+ }, [loaded.data]);
7683
+ const back = /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "ghost", size: "sm", className: "w-fit px-0 text-muted-foreground", onClick: onBack, children: "\u2190 Qualit\xE9" });
7684
+ if (loaded.isLoading) {
7685
+ return /* @__PURE__ */ jsxRuntime.jsxs(PageShell, { children: [
7686
+ back,
7687
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Chargement\u2026" })
7688
+ ] });
7689
+ }
7690
+ if (loaded.error !== void 0) {
7691
+ return /* @__PURE__ */ jsxRuntime.jsxs(PageShell, { children: [
7692
+ back,
7693
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: qualityErrorMessage(loaded.error) })
7694
+ ] });
7695
+ }
7696
+ if (!review) {
7697
+ return /* @__PURE__ */ jsxRuntime.jsxs(PageShell, { children: [
7698
+ back,
7699
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Revue introuvable." })
7700
+ ] });
7701
+ }
7702
+ return /* @__PURE__ */ jsxRuntime.jsxs(PageShell, { children: [
7703
+ back,
7704
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-4", children: [
7705
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
7706
+ /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-2xl font-semibold", children: review.name }),
7707
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm text-muted-foreground", children: [
7708
+ "Dataset : ",
7709
+ review.datasetName
7710
+ ] })
7711
+ ] }),
7712
+ /* @__PURE__ */ jsxRuntime.jsx(ExportReviewButton, { reviewId: review.id })
7713
+ ] }),
7714
+ /* @__PURE__ */ jsxRuntime.jsx(ReviewRunsSummary, { runs: review.runs, canEdit }),
7715
+ /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Card, { children: [
7716
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardTitle, { children: "Scores" }) }),
7717
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardContent, { children: /* @__PURE__ */ jsxRuntime.jsx(ReviewHistogram, { histogram: review.histogram, runs: review.runs }) })
7718
+ ] }),
7719
+ /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Card, { children: [
7720
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardTitle, { children: "Revue item par item" }) }),
7721
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardContent, { children: /* @__PURE__ */ jsxRuntime.jsx(
7722
+ ReviewItemsPanel,
7723
+ {
7724
+ reviewId: review.id,
7725
+ items: review.items,
7726
+ canEdit,
7727
+ onItemSaved: (datasetItemId, saved) => setReview(
7728
+ (current) => current ? {
7729
+ ...current,
7730
+ items: current.items.map(
7731
+ (item) => item.datasetItemId === datasetItemId ? { ...item, review: saved } : item
7732
+ )
7733
+ } : current
7734
+ )
7735
+ }
7736
+ ) })
7737
+ ] }),
7738
+ /* @__PURE__ */ jsxRuntime.jsx(
7739
+ ReviewSummaryCard,
7740
+ {
7741
+ reviewId: review.id,
7742
+ summary: review.summary,
7743
+ canEdit,
7744
+ onGenerated: (summary) => setReview((current) => current ? { ...current, summary } : current)
7745
+ }
7746
+ )
7747
+ ] });
7748
+ }
7749
+ function QualityPage() {
7750
+ const { platformRole } = uiSdk.useAppContext();
7751
+ const canEdit = canEditQuality(platformRole);
7752
+ const { value: reviewId, setValue: setReviewId } = useQueryParam("revue");
7753
+ if (reviewId) {
7754
+ return /* @__PURE__ */ jsxRuntime.jsx(ReviewView, { reviewId, canEdit, onBack: () => setReviewId(null) });
7755
+ }
7756
+ return /* @__PURE__ */ jsxRuntime.jsx(ExperimentsView, { canEdit, onReviewCreated: setReviewId });
7757
+ }
5668
7758
 
5669
7759
  exports.AgentsPage = AgentsPage;
5670
7760
  exports.CategoriesPage = CategoriesPage;
@@ -5673,6 +7763,7 @@ exports.DashboardPage = DashboardPage;
5673
7763
  exports.EscalationsPage = EscalationsPage;
5674
7764
  exports.GraphCanvasPage = GraphCanvasPage;
5675
7765
  exports.PipelinePage = PipelinePage;
7766
+ exports.QualityPage = QualityPage;
5676
7767
  exports.SettingsPage = SettingsPage;
5677
7768
  exports.SharedPromptsPage = SharedPromptsPage;
5678
7769
  exports.TestPage = TestPage;