@apotech-os/support-kit 7.0.1 → 8.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
@@ -340,6 +340,7 @@ var EMPTY_TOTALS = {
340
340
  failed: 0
341
341
  };
342
342
  function outcomeOf(status, autoSendDecision) {
343
+ if (status === "test_draft") return null;
343
344
  if (status === "sent") return "auto";
344
345
  if (status === "no_reply_needed") return "noReplyNeeded";
345
346
  if (status === "failed") return "failed";
@@ -349,7 +350,8 @@ function outcomeOf(status, autoSendDecision) {
349
350
  function foldOutcomes(rows) {
350
351
  const totals = { ...EMPTY_TOTALS };
351
352
  for (const row of rows) {
352
- totals[outcomeOf(row["status"], row["autoSendDecision"])] += Number(row["count"]) || 0;
353
+ const outcome = outcomeOf(row["status"], row["autoSendDecision"]);
354
+ if (outcome !== null) totals[outcome] += Number(row["count"]) || 0;
353
355
  }
354
356
  return totals;
355
357
  }
@@ -363,9 +365,11 @@ function autonomyRate(totals) {
363
365
  function foldDailyOutcomes(rows) {
364
366
  const byDay = /* @__PURE__ */ new Map();
365
367
  for (const row of rows) {
368
+ const outcome = outcomeOf(row["status"], row["autoSendDecision"]);
369
+ if (outcome === null) continue;
366
370
  const day = bucketDay(row);
367
371
  const totals = byDay.get(day) ?? { ...EMPTY_TOTALS };
368
- totals[outcomeOf(row["status"], row["autoSendDecision"])] += Number(row["count"]) || 0;
372
+ totals[outcome] += Number(row["count"]) || 0;
369
373
  byDay.set(day, totals);
370
374
  }
371
375
  return [...byDay.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([day, totals]) => ({
@@ -1118,6 +1122,31 @@ function TicketLink({ ticketId, url, label }) {
1118
1122
  }
1119
1123
  );
1120
1124
  }
1125
+ function readParam(name) {
1126
+ if (typeof window === "undefined") return null;
1127
+ return new URLSearchParams(window.location.search).get(name);
1128
+ }
1129
+ function useQueryParam(name) {
1130
+ const [value, setState] = react.useState(() => readParam(name));
1131
+ react.useEffect(() => {
1132
+ const sync = () => setState(readParam(name));
1133
+ sync();
1134
+ window.addEventListener("popstate", sync);
1135
+ return () => window.removeEventListener("popstate", sync);
1136
+ }, [name]);
1137
+ const setValue = react.useCallback(
1138
+ (next) => {
1139
+ const params = new URLSearchParams(window.location.search);
1140
+ if (next === null) params.delete(name);
1141
+ else params.set(name, next);
1142
+ const query = params.toString();
1143
+ window.history.pushState({}, "", `${window.location.pathname}${query ? `?${query}` : ""}`);
1144
+ setState(next);
1145
+ },
1146
+ [name]
1147
+ );
1148
+ return { value, setValue };
1149
+ }
1121
1150
  var UNCONFIGURED = { baseUrl: null, projectId: null };
1122
1151
  function useLangfuseConfig() {
1123
1152
  const { appSlug } = uiSdk.useAppContext();
@@ -1195,7 +1224,8 @@ var GENERATED_RESPONSE_STATUS_LABELS = {
1195
1224
  failed: "\xC9chec",
1196
1225
  no_reply_needed: "Aucune r\xE9ponse n\xE9cessaire",
1197
1226
  invalidated: "Invalid\xE9e",
1198
- expired: "Expir\xE9e"
1227
+ expired: "Expir\xE9e",
1228
+ test_draft: "Brouillon d'essai \u2014 jamais envoy\xE9"
1199
1229
  };
1200
1230
  var AUTO_SEND_DECISION_LABELS = {
1201
1231
  auto: "Autoris\xE9",
@@ -1259,20 +1289,33 @@ var GENERATED_RESPONSE_STATUSES = [
1259
1289
  "failed",
1260
1290
  "no_reply_needed",
1261
1291
  "invalidated",
1262
- "expired"
1292
+ "expired",
1293
+ // 24/09/2026 — where "générer sans envoyer" rests its draft. It used to
1294
+ // finalize as `invalidated`, which the ticket page and the dashboard both
1295
+ // read as "an agent had already answered": the test artefact was stored,
1296
+ // but disguised as a human intervention. Terminal on purpose — nothing may
1297
+ // serve, send or revive a test draft — and terminal is also what frees the
1298
+ // `openTicketKey` (see `openTicketKeyFor`), so an essay can never hold the
1299
+ // real webhook at G9.
1300
+ "test_draft"
1263
1301
  ];
1264
1302
  function isGeneratedResponseStatus(value) {
1265
1303
  return typeof value === "string" && GENERATED_RESPONSE_STATUSES.includes(value);
1266
1304
  }
1267
1305
  var ALLOWED_TRANSITIONS = {
1268
- pending: ["ready", "failed", "no_reply_needed", "sending", "invalidated"],
1306
+ // `pending -> test_draft` is the ONLY way in: the test pass finalizes the
1307
+ // very `pending` row it opened, and no other status can become a test
1308
+ // draft after the fact — an operator invalidating a real `ready` draft is
1309
+ // expressing "discard this", not "this was an essay".
1310
+ pending: ["ready", "failed", "no_reply_needed", "sending", "invalidated", "test_draft"],
1269
1311
  ready: ["sending", "invalidated", "expired"],
1270
1312
  sending: ["sent", "ready"],
1271
1313
  sent: [],
1272
1314
  failed: [],
1273
1315
  no_reply_needed: [],
1274
1316
  invalidated: [],
1275
- expired: []
1317
+ expired: [],
1318
+ test_draft: []
1276
1319
  };
1277
1320
  function canTransition(from, to) {
1278
1321
  if (!isGeneratedResponseStatus(from) || !isGeneratedResponseStatus(to)) return false;
@@ -1708,6 +1751,8 @@ function deliveryReason(input) {
1708
1751
  }
1709
1752
  case "failed":
1710
1753
  return job.error ?? "La r\xE9ponse a \xE9chou\xE9 avant son envoi.";
1754
+ case "test_draft":
1755
+ return "Brouillon d'essai \u2014 jamais envoy\xE9.";
1711
1756
  default:
1712
1757
  return `La r\xE9ponse n'a pas \xE9t\xE9 envoy\xE9e (statut : ${job.status}).`;
1713
1758
  }
@@ -2245,6 +2290,15 @@ function TicketsPage() {
2245
2290
  return true;
2246
2291
  });
2247
2292
  }, [decisions, jobByDecisionId, comparisonsByTicketId, outcomeFilter, verdictFilter, promptVersionFilter, correctedFilter]);
2293
+ const requestedTicket = useQueryParam("ticket").value;
2294
+ const deepLinkConsumed = react.useRef(false);
2295
+ react.useEffect(() => {
2296
+ if (deepLinkConsumed.current || !requestedTicket) return;
2297
+ const match = rows.find((row) => row.decision.ticketId === requestedTicket);
2298
+ if (!match) return;
2299
+ deepLinkConsumed.current = true;
2300
+ setDetailDecision(match.decision);
2301
+ }, [requestedTicket, rows]);
2248
2302
  const categoryOptions = react.useMemo(
2249
2303
  () => [{ value: "", label: "Toutes cat\xE9gories" }, ...categories.map((category) => ({ value: category.id, label: category.name }))],
2250
2304
  [categories]
@@ -4548,156 +4602,104 @@ function SourceViewField({ views, value, onChange, disabled }) {
4548
4602
  }
4549
4603
  );
4550
4604
  }
4551
- var STATUS_BADGE = {
4552
- passed: { label: "OK", variant: "success" },
4553
- stopped: { label: "Arr\xEAt", variant: "danger" },
4554
- // A pre-gate that could not read its field. Never shown by the diagnostic
4555
- // (it evaluates no payload) but rendered honestly if it ever appears, rather
4556
- // than falling through to a blank badge.
4557
- muted: { label: "Muet", variant: "warning" },
4558
- skipped: { label: "Non \xE9valu\xE9", variant: "neutral" }
4605
+
4606
+ // src/functions/followup-webhook-install.ts
4607
+ var FOLLOWUP_WEBHOOK_ROUTE_PATH = "/gorgias/webhook";
4608
+ var FOLLOWUP_WEBHOOK_FORM = {
4609
+ ticket_id: "{{ticket.id}}",
4610
+ channel: "{{ticket.channel}}",
4611
+ last_message_datetime: "{{ticket.last_message_datetime}}",
4612
+ status: "{{ticket.status}}",
4613
+ tags: "{{ticket.tags}}",
4614
+ last_message_from_agent: "{{ticket.messages[-1].from_agent}}",
4615
+ last_message_public: "{{ticket.messages[-1].public}}"
4559
4616
  };
4617
+ var FOLLOWUP_WEBHOOK_TRIGGER = "ticket-message-created";
4618
+ function followupIntegrationName(slug) {
4619
+ return `Wopilo \u2014 R\xE9ponses aux messages suivants (${slug})`;
4620
+ }
4621
+ function followupWebhookPath(slug) {
4622
+ return `/api/s/${slug}${FOLLOWUP_WEBHOOK_ROUTE_PATH}`;
4623
+ }
4560
4624
  function FollowupWebhookCard({ scopeTag, onScopeTagChange, canWrite }) {
4561
- const api = uiSdk.useAppApi();
4562
- const toast = uiSdk.useToast();
4625
+ const { appSlug } = uiSdk.useAppContext();
4563
4626
  const scopeId = react.useId();
4564
- const ticketId = react.useId();
4565
- const [setup, setSetup] = react.useState(null);
4566
- const [isInstalling, setIsInstalling] = react.useState(false);
4567
- const [ticket, setTicket] = react.useState("");
4568
- const [test, setTest] = react.useState(null);
4569
- const [isTesting, setIsTesting] = react.useState(false);
4570
- const [confirmingRealRun, setConfirmingRealRun] = react.useState(false);
4571
- async function install() {
4572
- setIsInstalling(true);
4573
- try {
4574
- setSetup(await api.invoke("setup-gorgias-webhook", {}));
4575
- toast({ title: "Webhook Gorgias install\xE9.", variant: "success" });
4576
- } catch (err) {
4577
- setSetup(null);
4578
- toast({ title: "\xC9chec de l'installation", description: describeInvokeError(err), variant: "error" });
4579
- } finally {
4580
- setIsInstalling(false);
4581
- }
4582
- }
4583
- async function runTest(mode) {
4584
- setIsTesting(true);
4585
- setTest(null);
4586
- try {
4587
- setTest(await api.invoke("test-gorgias-webhook", { ticketId: ticket.trim(), mode }));
4588
- } catch (err) {
4589
- toast({ title: "\xC9chec du test", description: describeInvokeError(err), variant: "error" });
4590
- } finally {
4591
- setIsTesting(false);
4592
- setConfirmingRealRun(false);
4593
- }
4594
- }
4595
- return /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Card, { id: "webhook-suite", children: [
4596
- /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.CardContent, { className: "space-y-4 p-4", children: [
4597
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4598
- /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "font-medium", children: "R\xE9ponses aux messages suivants" }),
4599
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: "Quand un client r\xE9pond sur un ticket d\xE9j\xE0 trait\xE9, l'agent peut g\xE9n\xE9rer une nouvelle r\xE9ponse. Chaque cat\xE9gorie d\xE9cide si elle suit le fil (page Cat\xE9gories)." })
4600
- ] }),
4601
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4602
- /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: scopeId, className: "mb-1 block text-sm font-medium", children: "Tag de p\xE9rim\xE8tre webhook" }),
4603
- /* @__PURE__ */ jsxRuntime.jsx(
4604
- uiSdk.Input,
4605
- {
4606
- id: scopeId,
4607
- value: scopeTag,
4608
- onChange: (e) => onScopeTagChange(e.target.value),
4609
- placeholder: "wai/triaged",
4610
- disabled: !canWrite
4611
- }
4612
- ),
4613
- /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "mt-1 text-xs text-muted-foreground", children: [
4614
- "Le ticket doit d\xE9j\xE0 porter ce tag pour qu'un message suivant soit trait\xE9 \u2014 typiquement le tag \xAB trait\xE9 \xBB pos\xE9 par le premier passage. ",
4615
- /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "Vide = aucun message suivant trait\xE9" }),
4616
- " (c'est aussi le kill-switch). Deux apps sur le m\xEAme compte Gorgias doivent y mettre des valeurs ",
4617
- /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "distinctes" }),
4618
- ", sinon chacune r\xE9pondrait sur les tickets de l'autre."
4619
- ] })
4627
+ return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Card, { id: "webhook-suite", children: /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.CardContent, { className: "space-y-4 p-4", children: [
4628
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4629
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "font-medium", children: "R\xE9ponses aux messages suivants" }),
4630
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: "Quand un client r\xE9pond sur un ticket d\xE9j\xE0 trait\xE9, l'agent peut g\xE9n\xE9rer une nouvelle r\xE9ponse. Chaque cat\xE9gorie d\xE9cide si elle suit le fil (page Cat\xE9gories)." })
4631
+ ] }),
4632
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4633
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: scopeId, className: "mb-1 block text-sm font-medium", children: "Tag de p\xE9rim\xE8tre webhook" }),
4634
+ /* @__PURE__ */ jsxRuntime.jsx(
4635
+ uiSdk.Input,
4636
+ {
4637
+ id: scopeId,
4638
+ value: scopeTag,
4639
+ onChange: (e) => onScopeTagChange(e.target.value),
4640
+ placeholder: "wai/triaged",
4641
+ disabled: !canWrite
4642
+ }
4643
+ ),
4644
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "mt-1 text-xs text-muted-foreground", children: [
4645
+ "Le ticket doit d\xE9j\xE0 porter ce tag pour qu'un message suivant soit trait\xE9 \u2014 typiquement le tag \xAB trait\xE9 \xBB pos\xE9 par le premier passage. ",
4646
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "Vide = aucun message suivant trait\xE9" }),
4647
+ " (c'est aussi le kill-switch). Deux apps sur le m\xEAme compte Gorgias doivent y mettre des valeurs ",
4648
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "distinctes" }),
4649
+ ", sinon chacune r\xE9pondrait sur les tickets de l'autre."
4650
+ ] })
4651
+ ] }),
4652
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2 border-t pt-4", children: [
4653
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium", children: "Int\xE9gration Gorgias (installation manuelle)" }),
4654
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs text-muted-foreground", children: [
4655
+ "\xC0 cr\xE9er une fois dans Gorgias, sous ",
4656
+ /* @__PURE__ */ jsxRuntime.jsx("em", { children: "Settings \u203A Integrations \u203A HTTP" }),
4657
+ ". Rien n'est install\xE9 depuis cette page : l'app n'\xE9crit rien sur le compte Gorgias."
4620
4658
  ] }),
4621
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2 border-t pt-4", children: [
4622
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium", children: "Int\xE9gration Gorgias" }),
4623
- /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs text-muted-foreground", children: [
4624
- "Renseignez d'abord la variable serveur ",
4625
- /* @__PURE__ */ jsxRuntime.jsx("code", { children: "GORGIAS_CALLBACK_APP_KEY" }),
4626
- " (une cl\xE9 d'application",
4627
- " ",
4628
- /* @__PURE__ */ jsxRuntime.jsx("code", { children: "wopilo_app_\u2026" }),
4629
- "), puis installez l'int\xE9gration. L'op\xE9ration est idempotente : re-cliquer la met \xE0 jour."
4659
+ /* @__PURE__ */ jsxRuntime.jsxs("dl", { className: "space-y-1 text-xs", children: [
4660
+ /* @__PURE__ */ jsxRuntime.jsx(RecipeRow, { label: "Nom", children: followupIntegrationName(appSlug) }),
4661
+ /* @__PURE__ */ jsxRuntime.jsx(RecipeRow, { label: "D\xE9clencheur", children: FOLLOWUP_WEBHOOK_TRIGGER }),
4662
+ /* @__PURE__ */ jsxRuntime.jsx(RecipeRow, { label: "M\xE9thode", children: "POST" }),
4663
+ /* @__PURE__ */ jsxRuntime.jsxs(RecipeRow, { label: "URL", children: [
4664
+ "<PUBLIC_BASE_URL>",
4665
+ followupWebhookPath(appSlug)
4630
4666
  ] }),
4631
- canWrite && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { type: "button", variant: "outline", onClick: () => void install(), disabled: isInstalling, children: isInstalling ? "Installation\u2026" : "Installer le webhook Gorgias" }),
4632
- setup && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs text-muted-foreground", children: [
4633
- setup.created ? "Int\xE9gration cr\xE9\xE9e" : "Int\xE9gration mise \xE0 jour",
4634
- " \u2014 Gorgias appellera",
4635
- " ",
4636
- /* @__PURE__ */ jsxRuntime.jsx("code", { children: setup.url }),
4637
- "."
4667
+ /* @__PURE__ */ jsxRuntime.jsxs(RecipeRow, { label: "En-t\xEAte", children: [
4668
+ "Authorization: Bearer <cl\xE9 d'application ",
4669
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: "wopilo_app_\u2026" }),
4670
+ ">"
4638
4671
  ] })
4639
4672
  ] }),
4640
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2 border-t pt-4", children: [
4641
- /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: ticketId, className: "block text-sm font-medium", children: "Ticket \xE0 tester" }),
4642
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
4643
- /* @__PURE__ */ jsxRuntime.jsx(
4644
- uiSdk.Input,
4645
- {
4646
- id: ticketId,
4647
- value: ticket,
4648
- onChange: (e) => setTicket(e.target.value),
4649
- placeholder: "1534712154",
4650
- className: "max-w-48"
4651
- }
4652
- ),
4653
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { type: "button", variant: "outline", onClick: () => void runTest("diagnostic"), disabled: !ticket.trim() || isTesting, children: "Diagnostic" }),
4654
- canWrite && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { type: "button", variant: "outline", onClick: () => setConfirmingRealRun(true), disabled: !ticket.trim() || isTesting, children: "Ex\xE9cution r\xE9elle" })
4655
- ] }),
4656
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: "Le diagnostic \xE9value les m\xEAmes conditions que le webhook, sans aucun effet de bord. L'ex\xE9cution r\xE9elle d\xE9clenche le vrai traitement." }),
4657
- isTesting && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-sm text-muted-foreground", children: [
4658
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Spinner, {}),
4659
- " Test en cours\u2026"
4660
- ] }),
4661
- test?.mode === "run" && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm", children: [
4662
- "Traitement d\xE9clench\xE9. Run \xE0 suivre : ",
4663
- /* @__PURE__ */ jsxRuntime.jsx("code", { children: test.runId }),
4664
- "."
4665
- ] }),
4666
- test?.mode === "diagnostic" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
4667
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium", children: test.stoppedAt === null ? `Ticket ${test.ticketId} : il aurait re\xE7u une r\xE9ponse de suite.` : `Ticket ${test.ticketId} : arr\xEAt en ${test.stoppedAt}.` }),
4668
- /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "space-y-1", children: test.gates.map((gate) => /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "flex items-start gap-2 text-xs", children: [
4669
- /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: STATUS_BADGE[gate.status].variant, children: STATUS_BADGE[gate.status].label }),
4670
- /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
4671
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-medium", children: [
4672
- gate.gate,
4673
- " \u2014 ",
4674
- gate.label
4675
- ] }),
4676
- /* @__PURE__ */ jsxRuntime.jsx("br", {}),
4677
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: gate.detail })
4678
- ] })
4679
- ] }, gate.gate)) })
4680
- ] })
4673
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs text-muted-foreground", children: [
4674
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: "PUBLIC_BASE_URL" }),
4675
+ " est l'origine publique de l'",
4676
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "API" }),
4677
+ " \u2014 pas forc\xE9ment celle de cette interface, que l'instance peut servir depuis un autre domaine (",
4678
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: "WEB_APP_URL" }),
4679
+ "). En cas de doute, c'est la valeur r\xE9gl\xE9e c\xF4t\xE9 instance qui fait foi : une URL construite sur la mauvaise origine renvoie 404 \xE0 chaque appel Gorgias, sans message d'erreur nulle part."
4680
+ ] }),
4681
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs text-muted-foreground", children: [
4682
+ "La cl\xE9 est une cl\xE9 d'application de cette app, cr\xE9\xE9e dans la plateforme puis coll\xE9e telle quelle dans l'en-t\xEAte. Elle porte le r\xF4le manifeste complet de l'app (voir",
4683
+ " ",
4684
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: "docs/app-platform/gorgias-callback-authentication.md" }),
4685
+ " \xA75)."
4686
+ ] }),
4687
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4688
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-1 text-xs font-medium", children: "Champs du corps (onglet \xAB Body \xBB, un par ligne)" }),
4689
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "space-y-0.5 font-mono text-xs text-muted-foreground", children: Object.entries(FOLLOWUP_WEBHOOK_FORM).map(([key, value]) => /* @__PURE__ */ jsxRuntime.jsxs("li", { children: [
4690
+ key,
4691
+ " = ",
4692
+ value
4693
+ ] }, key)) }),
4694
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: "Les quatre derniers champs ne sont pas document\xE9s par Gorgias : s'ils ne se r\xE9solvent pas, le traitement relit simplement le ticket et continue. Rien ne casse s'ils manquent." })
4681
4695
  ] })
4682
- ] }),
4683
- confirmingRealRun && /* @__PURE__ */ jsxRuntime.jsx(
4684
- ConfirmModal,
4685
- {
4686
- title: "Lancer le traitement r\xE9el ?",
4687
- description: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4688
- "Le ticket ",
4689
- ticket.trim(),
4690
- " va \xEAtre trait\xE9 comme un vrai message suivant : g\xE9n\xE9ration, garde-fous, et",
4691
- " ",
4692
- /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "envoi r\xE9el au client" }),
4693
- " si sa cat\xE9gorie est en r\xE9ponse automatique. \xC0 r\xE9server \xE0 un ticket de test."
4694
- ] }),
4695
- confirmLabel: "Lancer",
4696
- busyLabel: "D\xE9clenchement\u2026",
4697
- onConfirm: () => runTest("run"),
4698
- onCancel: () => setConfirmingRealRun(false)
4699
- }
4700
- )
4696
+ ] })
4697
+ ] }) });
4698
+ }
4699
+ function RecipeRow({ label, children }) {
4700
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
4701
+ /* @__PURE__ */ jsxRuntime.jsx("dt", { className: "w-24 shrink-0 text-muted-foreground", children: label }),
4702
+ /* @__PURE__ */ jsxRuntime.jsx("dd", { className: "break-all font-mono", children })
4701
4703
  ] });
4702
4704
  }
4703
4705
  var WHATSAPP_MODE_LABELS = {
@@ -5157,31 +5159,6 @@ function SettingsPage() {
5157
5159
  );
5158
5160
  }
5159
5161
  var ReglagesPage = SettingsPage;
5160
- function readParam(name) {
5161
- if (typeof window === "undefined") return null;
5162
- return new URLSearchParams(window.location.search).get(name);
5163
- }
5164
- function useQueryParam(name) {
5165
- const [value, setState] = react.useState(() => readParam(name));
5166
- react.useEffect(() => {
5167
- const sync = () => setState(readParam(name));
5168
- sync();
5169
- window.addEventListener("popstate", sync);
5170
- return () => window.removeEventListener("popstate", sync);
5171
- }, [name]);
5172
- const setValue = react.useCallback(
5173
- (next) => {
5174
- const params = new URLSearchParams(window.location.search);
5175
- if (next === null) params.delete(name);
5176
- else params.set(name, next);
5177
- const query = params.toString();
5178
- window.history.pushState({}, "", `${window.location.pathname}${query ? `?${query}` : ""}`);
5179
- setState(next);
5180
- },
5181
- [name]
5182
- );
5183
- return { value, setValue };
5184
- }
5185
5162
 
5186
5163
  // src/ui/graph-canvas/reachability.ts
5187
5164
  var EXIT_TONES = {
@@ -6755,6 +6732,185 @@ function DryRunResultView({ result, langfuseConfig, knownTags, tagSettings }) {
6755
6732
  ] })
6756
6733
  ] });
6757
6734
  }
6735
+ var STATUS_BADGE = {
6736
+ passed: { label: "OK", variant: "success" },
6737
+ stopped: { label: "Arr\xEAt", variant: "danger" },
6738
+ // A pre-gate that could not read its field. The diagnostic never produces
6739
+ // one (it evaluates no payload), but a run stopped on a pre-gate does —
6740
+ // rendered honestly rather than falling through to a blank badge.
6741
+ muted: { label: "Muet", variant: "warning" },
6742
+ skipped: { label: "Non \xE9valu\xE9", variant: "neutral" }
6743
+ };
6744
+ function GatesTable({ gates }) {
6745
+ return /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "space-y-1", children: gates.map((gate) => {
6746
+ const badge = STATUS_BADGE[gate.status] ?? STATUS_BADGE.skipped;
6747
+ return /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "flex items-start gap-2 text-xs", children: [
6748
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: badge.variant, children: badge.label }),
6749
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
6750
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-medium", children: [
6751
+ gate.gate,
6752
+ " \u2014 ",
6753
+ gate.label
6754
+ ] }),
6755
+ /* @__PURE__ */ jsxRuntime.jsx("br", {}),
6756
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: gate.detail })
6757
+ ] })
6758
+ ] }, gate.gate);
6759
+ }) });
6760
+ }
6761
+ function parseRunResult(result) {
6762
+ if (typeof result !== "object" || result === null) return null;
6763
+ const raw = result;
6764
+ if (!Array.isArray(raw.gates)) return null;
6765
+ return {
6766
+ ticketId: typeof raw.ticketId === "string" ? raw.ticketId : null,
6767
+ stoppedAt: typeof raw.stoppedAt === "string" ? raw.stoppedAt : null,
6768
+ reason: typeof raw.reason === "string" ? raw.reason : null,
6769
+ gates: raw.gates,
6770
+ categoryName: typeof raw.categoryName === "string" ? raw.categoryName : null,
6771
+ outcome: typeof raw.outcome === "string" ? raw.outcome : null,
6772
+ responseId: typeof raw.responseId === "string" ? raw.responseId : null
6773
+ };
6774
+ }
6775
+ function describeRunDecision(result, mode) {
6776
+ if (result.stoppedAt !== null) return `Arr\xEAt en ${result.stoppedAt}.`;
6777
+ const category = result.categoryName ? ` (cat\xE9gorie \xAB ${result.categoryName} \xBB)` : "";
6778
+ if (result.outcome === "sent") {
6779
+ return mode === "generate" ? `La r\xE9ponse aurait \xE9t\xE9 envoy\xE9e au client${category} \u2014 g\xE9n\xE9r\xE9e sans envoi.` : `La r\xE9ponse a \xE9t\xE9 envoy\xE9e au client${category}.`;
6780
+ }
6781
+ const label = result.outcome !== null && result.outcome in OUTCOME_LABELS ? OUTCOME_LABELS[result.outcome] : null;
6782
+ return label ? `${label}${category}.` : `Traitement termin\xE9${category}.`;
6783
+ }
6784
+ function FollowupWebhookCard2() {
6785
+ const api = uiSdk.useAppApi();
6786
+ const { appSlug } = uiSdk.useAppContext();
6787
+ const toast = uiSdk.useToast();
6788
+ const ticketId = react.useId();
6789
+ const [ticket, setTicket] = react.useState("");
6790
+ const [test, setTest] = react.useState(null);
6791
+ const [isTesting, setIsTesting] = react.useState(false);
6792
+ const [confirmingRealRun, setConfirmingRealRun] = react.useState(false);
6793
+ const followedRunId = test !== null && test.mode !== "diagnostic" ? test.runId : null;
6794
+ const { run, isPolling } = uiSdk.useAppRun(followedRunId);
6795
+ const runResult = run && run.status === "succeeded" ? parseRunResult(run.result) : null;
6796
+ const [draftText, setDraftText] = react.useState(null);
6797
+ react.useEffect(() => {
6798
+ setDraftText(null);
6799
+ const responseId = runResult?.responseId;
6800
+ if (!responseId) return;
6801
+ let cancelled = false;
6802
+ void api.get(
6803
+ `/data/apps/${appSlug}/records/generated-response/${encodeURIComponent(responseId)}`
6804
+ ).then((record) => {
6805
+ if (!cancelled) setDraftText(record?.data?.responseText ?? null);
6806
+ }).catch(() => {
6807
+ });
6808
+ return () => {
6809
+ cancelled = true;
6810
+ };
6811
+ }, [runResult?.responseId, appSlug]);
6812
+ async function runTest(mode) {
6813
+ setIsTesting(true);
6814
+ setTest(null);
6815
+ try {
6816
+ setTest(await api.invoke("test-gorgias-webhook", { ticketId: ticket.trim(), mode }));
6817
+ } catch (err) {
6818
+ toast({ title: "\xC9chec du test", description: describeInvokeError(err), variant: "error" });
6819
+ } finally {
6820
+ setIsTesting(false);
6821
+ setConfirmingRealRun(false);
6822
+ }
6823
+ }
6824
+ const disabled = !ticket.trim() || isTesting;
6825
+ return /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Card, { id: "webhook-suite", children: [
6826
+ /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.CardContent, { className: "space-y-3 p-4", children: [
6827
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
6828
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "font-medium", children: "R\xE9ponses aux messages suivants" }),
6829
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: "Rejoue sur un ticket r\xE9el ce que ferait le webhook Gorgias quand un client r\xE9pond sur un ticket d\xE9j\xE0 trait\xE9. Le tag de p\xE9rim\xE8tre et les cat\xE9gories se r\xE8glent dans Param\xE8tres." })
6830
+ ] }),
6831
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2 border-t pt-3", children: [
6832
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: ticketId, className: "block text-sm font-medium", children: "Ticket \xE0 tester" }),
6833
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
6834
+ /* @__PURE__ */ jsxRuntime.jsx(
6835
+ uiSdk.Input,
6836
+ {
6837
+ id: ticketId,
6838
+ value: ticket,
6839
+ onChange: (e) => setTicket(e.target.value),
6840
+ placeholder: "1534712154",
6841
+ className: "max-w-48"
6842
+ }
6843
+ ),
6844
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { type: "button", variant: "outline", onClick: () => void runTest("diagnostic"), disabled, children: "Diagnostic" }),
6845
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { type: "button", variant: "outline", onClick: () => void runTest("generate"), disabled, children: "G\xE9n\xE9rer sans envoyer" }),
6846
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { type: "button", variant: "outline", onClick: () => setConfirmingRealRun(true), disabled, children: "Ex\xE9cution r\xE9elle" })
6847
+ ] }),
6848
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs text-muted-foreground", children: [
6849
+ "Le diagnostic \xE9value les m\xEAmes conditions que le webhook, sans aucun effet de bord.",
6850
+ " ",
6851
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "G\xE9n\xE9rer sans envoyer" }),
6852
+ " produit la r\xE9ponse compl\xE8te \u2014 m\xEAme si la cat\xE9gorie n'a pas activ\xE9 les r\xE9ponses aux messages suivants \u2014 et ne l'envoie jamais ; elle se lit dans la fiche du ticket. L'ex\xE9cution r\xE9elle d\xE9clenche le vrai traitement."
6853
+ ] }),
6854
+ isTesting && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-sm text-muted-foreground", children: [
6855
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Spinner, {}),
6856
+ " Test en cours\u2026"
6857
+ ] }),
6858
+ test?.mode === "generate" && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm", children: [
6859
+ "G\xE9n\xE9ration d\xE9clench\xE9e, sans envoi. Run \xE0 suivre : ",
6860
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: test.runId }),
6861
+ "."
6862
+ ] }),
6863
+ test?.mode === "run" && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm", children: [
6864
+ "Traitement d\xE9clench\xE9. Run \xE0 suivre : ",
6865
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: test.runId }),
6866
+ "."
6867
+ ] }),
6868
+ test !== null && test.mode !== "diagnostic" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6869
+ isPolling && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-sm text-muted-foreground", children: [
6870
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Spinner, {}),
6871
+ " Ex\xE9cution en cours\u2026"
6872
+ ] }),
6873
+ run?.status === "failed" && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm text-destructive", children: [
6874
+ "L'ex\xE9cution a \xE9chou\xE9 : ",
6875
+ run.error?.message ?? "erreur inconnue."
6876
+ ] }),
6877
+ runResult && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
6878
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium", children: describeRunDecision(runResult, test.mode) }),
6879
+ runResult.stoppedAt !== null && runResult.reason !== null && !runResult.gates.some((gate) => gate.status === "stopped") && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: runResult.reason }),
6880
+ /* @__PURE__ */ jsxRuntime.jsx(GatesTable, { gates: runResult.gates }),
6881
+ draftText !== null && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1", children: [
6882
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs font-medium", children: "Brouillon g\xE9n\xE9r\xE9" }),
6883
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "whitespace-pre-wrap rounded border bg-muted/30 p-2 text-xs", children: draftText })
6884
+ ] }),
6885
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs", children: /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Link, { href: `/espace/${appSlug}/tickets?ticket=${encodeURIComponent(runResult.ticketId ?? test.ticketId)}`, children: "Ouvrir la fiche du ticket" }) })
6886
+ ] })
6887
+ ] }),
6888
+ test?.mode === "diagnostic" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
6889
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium", children: test.stoppedAt === null ? `Ticket ${test.ticketId} : il aurait re\xE7u une r\xE9ponse de suite.` : `Ticket ${test.ticketId} : arr\xEAt en ${test.stoppedAt}.` }),
6890
+ /* @__PURE__ */ jsxRuntime.jsx(GatesTable, { gates: test.gates })
6891
+ ] })
6892
+ ] })
6893
+ ] }),
6894
+ confirmingRealRun && /* @__PURE__ */ jsxRuntime.jsx(
6895
+ ConfirmModal,
6896
+ {
6897
+ title: "Lancer le traitement r\xE9el ?",
6898
+ description: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6899
+ "Le ticket ",
6900
+ ticket.trim(),
6901
+ " va \xEAtre trait\xE9 comme un vrai message suivant : g\xE9n\xE9ration, garde-fous, et",
6902
+ " ",
6903
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "envoi r\xE9el au client" }),
6904
+ " si sa cat\xE9gorie est en r\xE9ponse automatique. Pour tout voir sans rien envoyer, utilisez \xAB G\xE9n\xE9rer sans envoyer \xBB."
6905
+ ] }),
6906
+ confirmLabel: "Lancer",
6907
+ busyLabel: "D\xE9clenchement\u2026",
6908
+ onConfirm: () => runTest("run"),
6909
+ onCancel: () => setConfirmingRealRun(false)
6910
+ }
6911
+ )
6912
+ ] });
6913
+ }
6758
6914
  var TRI_STATE_OPTIONS = [
6759
6915
  { value: "", label: "R\xE9glages actuels" },
6760
6916
  { value: "on", label: "Forcer actif" },
@@ -6942,9 +7098,11 @@ function TestControls() {
6942
7098
  function TestPage() {
6943
7099
  const { role } = uiSdk.useAppContext();
6944
7100
  const canRun = canWriteForRole(role);
7101
+ const canTestFollowup = role === "ADMIN";
6945
7102
  return /* @__PURE__ */ jsxRuntime.jsxs(PageShell, { children: [
6946
7103
  /* @__PURE__ */ jsxRuntime.jsx(PageHeader, { title: "Banc de test", description: "Rejoue le graphe sans jamais agir sur un vrai ticket (\xA70)." }),
6947
- !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, {})
7104
+ !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, {}),
7105
+ canTestFollowup && /* @__PURE__ */ jsxRuntime.jsx(FollowupWebhookCard2, {})
6948
7106
  ] });
6949
7107
  }
6950
7108
  function ExperimentStatusBadge({ experiment }) {