@apotech-os/support-kit 10.1.1 → 10.3.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
@@ -24,7 +24,7 @@ var OUTCOMES = [
24
24
  "triaged_only",
25
25
  // tenant/ticket has no draft step to run
26
26
  "no_reply_needed",
27
- // triage read the thread as already closed → NO tag, like 'ready' (whatsapp spec §5.2)
27
+ // the end-of-conversation step judged the thread finished — set on response rows, never returned by runTicket
28
28
  "failed"
29
29
  ];
30
30
  function isOutcome(value) {
@@ -616,6 +616,129 @@ function AutonomyHero({
616
616
  ] }) });
617
617
  }
618
618
 
619
+ // src/domain/reply-timing.ts
620
+ var RESPONDERS = ["ai", "human", "human_ai_assisted", "other", "none"];
621
+ var DELAY_BUCKETS = ["lt_5m", "5_15m", "15_60m", "1_4h", "4_24h", "gt_24h"];
622
+ function foldReplyTimings(rows) {
623
+ return Object.fromEntries(
624
+ RESPONDERS.map((responder) => [
625
+ responder,
626
+ timingOf(rows.filter((row) => row["responder"] === responder))
627
+ ])
628
+ );
629
+ }
630
+ function timingOf(rows) {
631
+ const buckets = emptyBuckets();
632
+ let count = 0;
633
+ let timed = 0;
634
+ let totalSeconds = 0;
635
+ for (const row of rows) {
636
+ const turns = countOf(row);
637
+ count += turns;
638
+ const bucket = row["delayBucket"];
639
+ if (!isDelayBucket(bucket)) continue;
640
+ buckets[bucket] += turns;
641
+ timed += turns;
642
+ totalSeconds += Number(row["totalSeconds"]) || 0;
643
+ }
644
+ return {
645
+ count,
646
+ avgSeconds: timed > 0 ? totalSeconds / timed : null,
647
+ medianBucket: medianBucketOf(buckets, timed),
648
+ buckets
649
+ };
650
+ }
651
+ function medianBucketOf(buckets, timed) {
652
+ let cumulative = 0;
653
+ for (const bucket of DELAY_BUCKETS) {
654
+ cumulative += buckets[bucket];
655
+ if (timed > 0 && cumulative >= timed / 2) return bucket;
656
+ }
657
+ return null;
658
+ }
659
+ function emptyBuckets() {
660
+ return Object.fromEntries(DELAY_BUCKETS.map((bucket) => [bucket, 0]));
661
+ }
662
+ function isDelayBucket(value) {
663
+ return DELAY_BUCKETS.includes(value);
664
+ }
665
+
666
+ // src/domain/dashboard-queries.ts
667
+ var OUTCOME_METRICS = [{ op: "count", as: "count" }];
668
+ var OUTCOME_GROUP_BY = ["status", "autoSendDecision", "outcome"];
669
+ var CATEGORY_OUTCOME_GROUP_BY = ["categoryId", "status", "autoSendDecision", "outcome"];
670
+ var TRIAGE_HANDOFF_GROUP_BY = ["escalated", "status"];
671
+ var CATEGORY_TRIAGE_GROUP_BY = ["categoryId", "escalated", "status"];
672
+ var REPLY_TIMING_GROUP_BY = ["responder", "delayBucket"];
673
+ var REPLY_TIMING_METRICS = [
674
+ { op: "count", as: "count" },
675
+ { op: "sum", field: "delaySeconds", as: "totalSeconds" }
676
+ ];
677
+ var DELAY_BUCKET_LABELS = {
678
+ lt_5m: "moins de 5 min",
679
+ "5_15m": "5 \xE0 15 min",
680
+ "15_60m": "15 \xE0 60 min",
681
+ "1_4h": "1 \xE0 4 h",
682
+ "4_24h": "4 \xE0 24 h",
683
+ gt_24h: "plus de 24 h"
684
+ };
685
+ function formatDuration(seconds) {
686
+ if (Math.round(seconds) < 60) return `${Math.round(seconds)} s`;
687
+ const minutes = Math.round(seconds / 60);
688
+ if (minutes < 60) return `${minutes} min`;
689
+ const hours = Math.floor(minutes / 60);
690
+ if (hours < 24) {
691
+ const rest = minutes % 60;
692
+ return rest === 0 ? `${hours} h` : `${hours} h ${String(rest).padStart(2, "0")}`;
693
+ }
694
+ return `${Math.floor(hours / 24)} j ${hours % 24} h`;
695
+ }
696
+ function Figure({ label, value }) {
697
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
698
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs font-medium uppercase tracking-widest text-muted-foreground", children: label }),
699
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-2xl font-semibold tabular-nums", children: value })
700
+ ] });
701
+ }
702
+ function ReplyTimesSection({ fromIso, toIso }) {
703
+ const { rows, isLoading, error } = useAggregate("reply-timing", {
704
+ filter: { customerMessageAt: { gte: fromIso, lte: toIso } },
705
+ groupBy: REPLY_TIMING_GROUP_BY,
706
+ metrics: REPLY_TIMING_METRICS
707
+ });
708
+ const ai = react.useMemo(() => foldReplyTimings(rows).ai, [rows]);
709
+ const histogram = DELAY_BUCKETS.map((bucket) => ({
710
+ tranche: DELAY_BUCKET_LABELS[bucket],
711
+ ai: ai.buckets[bucket]
712
+ }));
713
+ return /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Card, { "data-testid": "dashboard-reply-times", children: [
714
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardHeader, { children: /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardTitle, { className: "text-sm", children: "D\xE9lais de r\xE9ponse" }) }),
715
+ /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.CardContent, { className: "space-y-4", children: [
716
+ isLoading ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Chargement\u2026" }) : error !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-destructive", children: "Impossible de calculer les d\xE9lais de r\xE9ponse." }) : ai.medianBucket === null || ai.avgSeconds === null ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "Aucune r\xE9ponse de l\u2019IA mesur\xE9e sur cette p\xE9riode." }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
717
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-3 gap-4", children: [
718
+ /* @__PURE__ */ jsxRuntime.jsx(Figure, { label: "D\xE9lai m\xE9dian IA", value: DELAY_BUCKET_LABELS[ai.medianBucket] }),
719
+ /* @__PURE__ */ jsxRuntime.jsx(Figure, { label: "D\xE9lai moyen IA", value: formatDuration(ai.avgSeconds) }),
720
+ /* @__PURE__ */ jsxRuntime.jsx(Figure, { label: "Volume", value: `${ai.count.toLocaleString("fr-FR")} tours` })
721
+ ] }),
722
+ /* @__PURE__ */ jsxRuntime.jsx(
723
+ uiSdk.StackedBarChart,
724
+ {
725
+ data: histogram,
726
+ x: "tranche",
727
+ label: "R\xE9ponses de l\u2019IA par tranche de d\xE9lai",
728
+ series: [{ key: "ai", label: "R\xE9ponse de l\u2019IA", colorIndex: 0 }],
729
+ height: 150
730
+ }
731
+ )
732
+ ] }),
733
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs leading-relaxed text-muted-foreground", children: [
734
+ "Le d\xE9lai court du ",
735
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "premier" }),
736
+ " message du client rest\xE9 sans r\xE9ponse jusqu\u2019\xE0 la premi\xE8re r\xE9ponse qui le suit, en temps r\xE9el (nuits et week-ends compris). La m\xE9diane est une tranche : la moiti\xE9 des r\xE9ponses arrive dans cette tranche ou avant. Deux \xE9carts connus : une r\xE9ponse approuv\xE9e par un humain avant envoi compte comme une r\xE9ponse de l\u2019IA, et les tours reconstitu\xE9s apr\xE8s coup partent du dernier message du client, pas du premier."
737
+ ] })
738
+ ] })
739
+ ] });
740
+ }
741
+
619
742
  // src/domain/period.ts
620
743
  var WEEKLY_BUCKET_FROM_DAYS = 46;
621
744
  var DAY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
@@ -719,13 +842,6 @@ function StackedLegend({ segments }) {
719
842
  segment.label
720
843
  ] }, segment.key)) });
721
844
  }
722
-
723
- // src/domain/dashboard-queries.ts
724
- var OUTCOME_METRICS = [{ op: "count", as: "count" }];
725
- var OUTCOME_GROUP_BY = ["status", "autoSendDecision", "outcome"];
726
- var CATEGORY_OUTCOME_GROUP_BY = ["categoryId", "status", "autoSendDecision", "outcome"];
727
- var TRIAGE_HANDOFF_GROUP_BY = ["escalated", "status"];
728
- var CATEGORY_TRIAGE_GROUP_BY = ["categoryId", "escalated", "status"];
729
845
  var CATEGORY_COLORS = {
730
846
  auto: "var(--chart-1)",
731
847
  human: "var(--chart-2)",
@@ -880,6 +996,7 @@ function DashboardPage() {
880
996
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-2", children: "Le taux d\u2019autonomie rapporte les r\xE9ponses envoy\xE9es par l\u2019IA \xE0 ces m\xEAmes r\xE9ponses plus celles qu\u2019un humain a reprises \u2014 bloqu\xE9es, escalad\xE9es, invalid\xE9es parce qu\u2019un agent avait d\xE9j\xE0 r\xE9pondu, ou expir\xE9es. \xB7 Une escalade est compt\xE9e UNE fois, du c\xF4t\xE9 humain : c\u2019est un motif de blocage, pas un camp de plus. \xB7 Les demandes encore en cours, celles sans r\xE9ponse n\xE9cessaire et les \xE9checs techniques sont hors du taux \u2014 les compter d\u2019un c\xF4t\xE9 ou de l\u2019autre le fausserait dans les deux sens. \xB7 Le d\xE9nominateur ne couvre que les demandes mises en file : un ticket escalad\xE9 avant toute g\xE9n\xE9ration n\u2019y figure pas." })
881
997
  ] }),
882
998
  dailyError !== void 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-destructive", children: "Erreur lors du calcul des chiffres cl\xE9s." }),
999
+ /* @__PURE__ */ jsxRuntime.jsx(ReplyTimesSection, { fromIso: bounds.current.fromIso, toIso: bounds.current.toIso }),
883
1000
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 gap-4", children: [
884
1001
  /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.Card, { children: [
885
1002
  /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CardHeader, { children: /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.CardTitle, { className: "text-sm", children: [
@@ -1089,7 +1206,9 @@ var SETTINGS_ISSUE_LABELS = {
1089
1206
  appScopeTag: "Tag des tickets de l'application requis \u2014 c'est lui qui rattache un ticket \xE0 cette app.",
1090
1207
  nodes: "nodes.triage doit \xEAtre configur\xE9 \u2014 une \xE9tape de triage \xE0 null ne triagerait rien.",
1091
1208
  nodePrompt: "Chaque \xE9tape active doit d\xE9signer un prompt Langfuse \u2014 sans prompt, l'\xE9tape n'a rien \xE0 dire au mod\xE8le.",
1092
- senderEmail: "Adresse d'envoi requise quand l'envoi automatique est actif (sauf en mode WhatsApp \xAB auto_reply \xBB)."
1209
+ senderEmail: "Adresse d'envoi requise quand l'envoi automatique est actif (sauf en mode WhatsApp \xAB auto_reply \xBB).",
1210
+ conversationEndTag: "Tag de fin de conversation invalide \u2014 il doit \xEAtre renseign\xE9, et diff\xE9rent des tags de reprise humaine (escalade, \xE0 revoir avant envoi, suivi requis), du tag de prise en charge et du tag de l'application.",
1211
+ conversationEndPrompt: "Prompt \xAB fin de conversation \xBB requis d\xE8s que l'action de fin de conversation est activ\xE9e."
1093
1212
  };
1094
1213
  function settingsIssueLabel(key, fallback) {
1095
1214
  return SETTINGS_ISSUE_LABELS[key] ?? fallback;
@@ -1561,6 +1680,37 @@ var DEFAULT_AUTO_SEND_CHANNELS = [
1561
1680
  "sms",
1562
1681
  "contact-form"
1563
1682
  ];
1683
+
1684
+ // src/settings/conversation-end.ts
1685
+ var CONVERSATION_END_ACTIONS = ["disabled", "tag", "close"];
1686
+ var DEFAULT_CONVERSATION_END_ACTION = "disabled";
1687
+ var DEFAULT_CONVERSATION_END_TAG = "wai/conversation-ended";
1688
+ function readConversationEnd(settings) {
1689
+ const raw = settings;
1690
+ const rawAction = raw.conversationEndAction;
1691
+ const action = CONVERSATION_END_ACTIONS.includes(rawAction) ? rawAction : DEFAULT_CONVERSATION_END_ACTION;
1692
+ const tag = typeof raw.conversationEndTag === "string" ? raw.conversationEndTag.trim() : DEFAULT_CONVERSATION_END_TAG;
1693
+ return { action, tag, prompt: readPrompt(raw.conversationEndPrompt) };
1694
+ }
1695
+ function endConfigOf({
1696
+ action,
1697
+ tag
1698
+ }) {
1699
+ return action === "disabled" ? null : { action, tag };
1700
+ }
1701
+ function toConversationEnd(settings) {
1702
+ return endConfigOf(readConversationEnd(settings));
1703
+ }
1704
+ function conversationEndEffects(end) {
1705
+ if (!end) return { tags: [], close: false };
1706
+ return end.action === "tag" ? { tags: [end.tag], close: false } : { tags: [], close: true };
1707
+ }
1708
+ function readPrompt(raw) {
1709
+ if (typeof raw !== "object" || raw === null) return null;
1710
+ const { name, label } = raw;
1711
+ if (typeof name !== "string" || name === "") return null;
1712
+ return typeof label === "string" && label !== "" ? { name, label } : { name };
1713
+ }
1564
1714
  var AGENT_FIELD_NAME_UID = "e9cfec6f-15c6-4d02-8f79-0667f64b9eb5";
1565
1715
  var AGENT_FIELD_PROVIDER_UID = "e522b809-e8a7-4439-a2df-936158d04389";
1566
1716
  var AGENT_FIELD_MODEL_ID_UID = "d95977ba-362c-44d6-a2f0-24156c76cf8a";
@@ -1799,7 +1949,8 @@ function toDeliveryPolicy(raw) {
1799
1949
  whatsappMode: typeof settings.whatsappMode === "string" ? settings.whatsappMode : null,
1800
1950
  autoSendChannels: Array.isArray(settings.autoSendChannels) ? settings.autoSendChannels : [...DEFAULT_AUTO_SEND_CHANNELS],
1801
1951
  dryRun: settings.dryRun === true,
1802
- audit: toAuditTags(settings)
1952
+ audit: toAuditTags(settings),
1953
+ conversationEnd: toConversationEnd(settings)
1803
1954
  };
1804
1955
  }
1805
1956
 
@@ -2064,6 +2215,8 @@ function deliveryReason(facts) {
2064
2215
  case "test_draft":
2065
2216
  return { code: "test_draft" };
2066
2217
  default:
2218
+ if (job.status === "no_reply_needed" && job.outcome === "no_reply_needed")
2219
+ return { code: "no_reply_needed" };
2067
2220
  return { code: "unexpected_status", status: job.status };
2068
2221
  }
2069
2222
  }
@@ -2211,6 +2364,8 @@ function describeReason(reason2) {
2211
2364
  return "Le client a \xE9crit \xE0 nouveau avant l\u2019envoi : une r\xE9ponse plus r\xE9cente a remplac\xE9 celle-ci.";
2212
2365
  case "test_draft":
2213
2366
  return "Brouillon d'essai \u2014 jamais envoy\xE9.";
2367
+ case "no_reply_needed":
2368
+ return "Aucune r\xE9ponse n\xE9cessaire \u2014 la conversation est finie.";
2214
2369
  case "unexpected_status":
2215
2370
  return `La r\xE9ponse n'a pas \xE9t\xE9 envoy\xE9e (statut : ${reason2.status}).`;
2216
2371
  case "no_correction":
@@ -2327,14 +2482,18 @@ function triageTagNames(input) {
2327
2482
  }
2328
2483
  function wasSimulated(job, policy) {
2329
2484
  if (!job) return false;
2485
+ if (job.status === "test_draft") return true;
2330
2486
  if (job.outcome === "sent" && job.status !== "sent") return true;
2331
2487
  return policy?.dryRun === true;
2332
2488
  }
2333
2489
  function ticketActions(input) {
2334
2490
  const { job, policy, notSentReason: notSentReason2 } = input;
2335
2491
  const simulated = wasSimulated(job, policy);
2492
+ const ended = job?.outcome === "no_reply_needed" && (job.status === "no_reply_needed" || job.status === "test_draft") && input.decision.conversationOver === true;
2493
+ const endEffects = conversationEndEffects(ended ? policy?.conversationEnd ?? null : null);
2336
2494
  const tags = dedupe([
2337
2495
  ...triageTagNames(input),
2496
+ ...endEffects.tags,
2338
2497
  ...policy ? outcomeTags(job?.outcome ?? null, job?.verdict ?? null, policy.audit) : []
2339
2498
  ]);
2340
2499
  const taken = [];
@@ -2345,6 +2504,7 @@ function ticketActions(input) {
2345
2504
  skipped.push(`R\xE9ponse non envoy\xE9e \u2014 ${notSentReason2 ?? "raison inconnue."}`);
2346
2505
  }
2347
2506
  if (job?.outcome === "awaiting_approval" && !simulated) taken.push("Demande d'approbation cr\xE9\xE9e.");
2507
+ if (endEffects.close && !simulated) taken.push("Ticket ferm\xE9 dans Gorgias.");
2348
2508
  return { tags, taken, skipped, simulated, unrecorded: job !== void 0 && job.outcome === null };
2349
2509
  }
2350
2510
  function TimelinePanel(props) {
@@ -4689,8 +4849,35 @@ function validateSettings(settings) {
4689
4849
  message: "senderEmail is required when autoSendEnabled is on, unless whatsappMode is 'auto_reply'."
4690
4850
  });
4691
4851
  }
4852
+ const end = readConversationEnd(settings);
4853
+ if (end.action === "tag" && end.tag === "") {
4854
+ issues.push({
4855
+ key: "conversationEndTag",
4856
+ message: 'conversationEndTag is required when the end-of-conversation action is "tag".'
4857
+ });
4858
+ } else if (end.tag !== "" && reservedTags(settings).includes(end.tag)) {
4859
+ issues.push({
4860
+ key: "conversationEndTag",
4861
+ message: "conversationEndTag must differ from escalationTag, needsReviewTag, followupTag, appScopeTag and handledTag."
4862
+ });
4863
+ }
4864
+ if (end.action !== "disabled" && end.prompt === null) {
4865
+ issues.push({
4866
+ key: "conversationEndPrompt",
4867
+ message: "conversationEndPrompt is required when the end-of-conversation action is on."
4868
+ });
4869
+ }
4692
4870
  return issues;
4693
4871
  }
4872
+ function reservedTags(settings) {
4873
+ return [
4874
+ settings.escalationTag,
4875
+ settings.needsReviewTag,
4876
+ settings.followupTag,
4877
+ settings.appScopeTag,
4878
+ settings.handledTag
4879
+ ].filter(isNonEmptyString).map((tag) => tag.trim());
4880
+ }
4694
4881
  function isNonEmptyString(value) {
4695
4882
  return typeof value === "string" && value.length > 0;
4696
4883
  }
@@ -4768,6 +4955,61 @@ function NumberField({ id, label, value, onChange, disabled, min, max, integer,
4768
4955
  hint && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: hint })
4769
4956
  ] });
4770
4957
  }
4958
+ function PromptRefPicker({
4959
+ id,
4960
+ subject,
4961
+ name,
4962
+ label,
4963
+ prompts,
4964
+ promptsLoading,
4965
+ disabled,
4966
+ onChange
4967
+ }) {
4968
+ const known = prompts.find((entry) => entry.name === name);
4969
+ const unlisted = name !== "" && !known;
4970
+ const orphaned = unlisted && !promptsLoading;
4971
+ const labels = known?.labels.length ? known.labels : [DEFAULT_PROMPT_LABEL];
4972
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4973
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: id, className: "mb-1 block text-sm font-medium", children: "Prompt Langfuse" }),
4974
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-2 sm:grid-cols-2", children: [
4975
+ /* @__PURE__ */ jsxRuntime.jsx(
4976
+ uiSdk.Select,
4977
+ {
4978
+ "aria-label": `Prompt \u2014 ${subject}`,
4979
+ value: name,
4980
+ onValueChange: (next) => onChange(next, DEFAULT_PROMPT_LABEL),
4981
+ items: [
4982
+ ...unlisted ? [{ value: name, label: orphaned ? `${name} \u2014 introuvable dans Langfuse` : name }] : [],
4983
+ ...prompts.map((entry) => ({ value: entry.name, label: entry.name }))
4984
+ ],
4985
+ disabled: disabled || promptsLoading
4986
+ }
4987
+ ),
4988
+ /* @__PURE__ */ jsxRuntime.jsx(
4989
+ uiSdk.Select,
4990
+ {
4991
+ "aria-label": `Version du prompt \u2014 ${subject}`,
4992
+ value: labels.includes(label) ? label : "",
4993
+ onValueChange: (next) => onChange(name, next),
4994
+ items: labels.map((entry) => ({ value: entry, label: entry })),
4995
+ disabled: disabled || promptsLoading || name === ""
4996
+ }
4997
+ )
4998
+ ] }),
4999
+ name === "" && !promptsLoading && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-sm text-destructive", children: "Aucun prompt choisi \u2014 cette \xE9tape ne peut pas s'ex\xE9cuter tant qu'elle n'en d\xE9signe pas un." }),
5000
+ orphaned && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "mt-1 text-sm text-destructive", children: [
5001
+ "\xAB ",
5002
+ name,
5003
+ " \xBB n'est pas dans le catalogue de cette app \u2014 le prochain traitement \xE9chouera tant que ce prompt n'est pas r\xE9tabli ou remplac\xE9."
5004
+ ] }),
5005
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "mt-1 text-xs text-muted-foreground", children: [
5006
+ "Le label suit les promotions faites dans Langfuse : promouvoir une nouvelle version sous \xAB",
5007
+ " ",
5008
+ label,
5009
+ " \xBB la met en service sans repasser ici."
5010
+ ] })
5011
+ ] });
5012
+ }
4771
5013
  var PERCENT = 100;
4772
5014
  function PipelineNodesForm({
4773
5015
  value,
@@ -5036,51 +5278,19 @@ function StepPromptField({
5036
5278
  if (stepUsesAgentPrompt(step2.key)) {
5037
5279
  return /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: step2.key === "revise" ? "Cette \xE9tape relance l'agent qui r\xE9dige avec l'objection du relecteur \u2014 elle n'a pas de prompt \xE0 choisir." : "Le prompt de cette \xE9tape est celui de l'agent qui r\xE9dige \u2014 il se choisit sur la page Agents." });
5038
5280
  }
5039
- const name = stepPromptName(settings);
5040
- const label = stepPromptLabel(settings);
5041
- const known = prompts.find((entry) => entry.name === name);
5042
- const unlisted = name !== "" && !known;
5043
- const orphaned = unlisted && !promptsLoading;
5044
- const labels = known?.labels.length ? known.labels : [DEFAULT_PROMPT_LABEL];
5045
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5046
- /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: id, className: "mb-1 block text-sm font-medium", children: "Prompt Langfuse" }),
5047
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-2 sm:grid-cols-2", children: [
5048
- /* @__PURE__ */ jsxRuntime.jsx(
5049
- uiSdk.Select,
5050
- {
5051
- "aria-label": `Prompt \u2014 ${step2.label}`,
5052
- value: name,
5053
- onValueChange: (next) => onPatch(promptPatch(next, DEFAULT_PROMPT_LABEL)),
5054
- items: [
5055
- ...unlisted ? [{ value: name, label: orphaned ? `${name} \u2014 introuvable dans Langfuse` : name }] : [],
5056
- ...prompts.map((entry) => ({ value: entry.name, label: entry.name }))
5057
- ],
5058
- disabled: disabled || promptsLoading
5059
- }
5060
- ),
5061
- /* @__PURE__ */ jsxRuntime.jsx(
5062
- uiSdk.Select,
5063
- {
5064
- "aria-label": `Version du prompt \u2014 ${step2.label}`,
5065
- value: labels.includes(label) ? label : "",
5066
- onValueChange: (next) => onPatch(promptPatch(name, next)),
5067
- items: labels.map((entry) => ({ value: entry, label: entry })),
5068
- disabled: disabled || promptsLoading || name === ""
5069
- }
5070
- )
5071
- ] }),
5072
- name === "" && !promptsLoading && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-sm text-destructive", children: "Aucun prompt choisi \u2014 cette \xE9tape ne peut pas s'ex\xE9cuter tant qu'elle n'en d\xE9signe pas un." }),
5073
- orphaned && /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "mt-1 text-sm text-destructive", children: [
5074
- "\xAB ",
5075
- name,
5076
- " \xBB n'est pas dans le catalogue de cette app \u2014 le prochain traitement \xE9chouera tant que ce prompt n'est pas r\xE9tabli ou remplac\xE9."
5077
- ] }),
5078
- /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "mt-1 text-xs text-muted-foreground", children: [
5079
- "Le label suit les promotions faites dans Langfuse : promouvoir une nouvelle version sous \xAB ",
5080
- label,
5081
- " \xBB la met en service sans repasser ici."
5082
- ] })
5083
- ] });
5281
+ return /* @__PURE__ */ jsxRuntime.jsx(
5282
+ PromptRefPicker,
5283
+ {
5284
+ id,
5285
+ subject: step2.label,
5286
+ name: stepPromptName(settings),
5287
+ label: stepPromptLabel(settings),
5288
+ prompts,
5289
+ promptsLoading,
5290
+ disabled,
5291
+ onChange: (name, label) => onPatch(promptPatch(name, label))
5292
+ }
5293
+ );
5084
5294
  }
5085
5295
  function useIds(stepKey) {
5086
5296
  const base2 = react.useId();
@@ -5270,6 +5480,64 @@ function RecipeRow({ label, children }) {
5270
5480
  /* @__PURE__ */ jsxRuntime.jsx("dd", { className: "break-all font-mono", children })
5271
5481
  ] });
5272
5482
  }
5483
+ var ACTION_OPTIONS = [
5484
+ { value: "disabled", label: "D\xE9sactiv\xE9 \u2014 r\xE9pondre \xE0 tous les messages" },
5485
+ { value: "tag", label: "Poser un tag \u2014 un humain repasse via une vue Gorgias" },
5486
+ { value: "close", label: "Fermer le ticket dans Gorgias, sans tag" }
5487
+ ];
5488
+ function ConversationEndCard({
5489
+ form,
5490
+ set,
5491
+ canWrite,
5492
+ prompts,
5493
+ promptsLoading
5494
+ }) {
5495
+ const end = readConversationEnd(form);
5496
+ const tag = typeof form.conversationEndTag === "string" ? form.conversationEndTag : DEFAULT_CONVERSATION_END_TAG;
5497
+ return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Card, { id: "conversation-end", children: /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.CardContent, { className: "space-y-3 p-4", children: [
5498
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "font-medium", children: "Fin de conversation" }),
5499
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground", children: "Sur un message qui n\u2019appelle aucune r\xE9ponse (\xAB merci \xBB, \xE9moji seul, \xAB c\u2019est r\xE9gl\xE9 \xBB), premier message compris, l\u2019app n\u2019envoie jamais de r\xE9ponse : elle pose le tag ou ferme le ticket, et annule un brouillon rest\xE9 ouvert. Dans le doute l\u2019app r\xE9pond. Un ticket repris par un humain n\u2019est jamais touch\xE9." }),
5500
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
5501
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "conversationEndAction", className: "mb-1 block text-sm font-medium", children: "Action de fin de conversation" }),
5502
+ /* @__PURE__ */ jsxRuntime.jsx(
5503
+ uiSdk.Select,
5504
+ {
5505
+ "aria-label": "Action de fin de conversation",
5506
+ value: end.action,
5507
+ onValueChange: (value) => set("conversationEndAction", value),
5508
+ items: ACTION_OPTIONS,
5509
+ disabled: !canWrite
5510
+ }
5511
+ )
5512
+ ] }),
5513
+ end.action === "tag" && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
5514
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "conversationEndTag", className: "mb-1 block text-sm font-medium", children: "Tag de fin de conversation" }),
5515
+ /* @__PURE__ */ jsxRuntime.jsx(
5516
+ uiSdk.Input,
5517
+ {
5518
+ id: "conversationEndTag",
5519
+ value: tag,
5520
+ onChange: (e) => set("conversationEndTag", e.target.value),
5521
+ disabled: !canWrite
5522
+ }
5523
+ ),
5524
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: "Retir\xE9 automatiquement quand le client r\xE9\xE9crit avec une demande. Cr\xE9ez une vue Gorgias sur ce tag pour repasser sur ces tickets." })
5525
+ ] }),
5526
+ end.action !== "disabled" && /* @__PURE__ */ jsxRuntime.jsx(
5527
+ PromptRefPicker,
5528
+ {
5529
+ id: "conversationEndPrompt",
5530
+ subject: "Fin de conversation",
5531
+ name: end.prompt?.name ?? "",
5532
+ label: end.prompt?.label ?? DEFAULT_PROMPT_LABEL,
5533
+ prompts,
5534
+ promptsLoading,
5535
+ disabled: !canWrite,
5536
+ onChange: (name, label) => set("conversationEndPrompt", { name, label })
5537
+ }
5538
+ )
5539
+ ] }) });
5540
+ }
5273
5541
  var WHATSAPP_MODE_LABELS = {
5274
5542
  escalate_only: "Escalade uniquement",
5275
5543
  draft_only: "Brouillon uniquement",
@@ -5596,6 +5864,16 @@ function SettingsPage() {
5596
5864
  /* @__PURE__ */ jsxRuntime.jsx(SettingsWarnings, { warnings: tagWarnings })
5597
5865
  ] }) }),
5598
5866
  /* @__PURE__ */ jsxRuntime.jsx(FollowupWebhookCard, {}),
5867
+ /* @__PURE__ */ jsxRuntime.jsx(
5868
+ ConversationEndCard,
5869
+ {
5870
+ form,
5871
+ set,
5872
+ canWrite,
5873
+ prompts: promptCatalogue.prompts,
5874
+ promptsLoading: promptCatalogue.isLoading
5875
+ }
5876
+ ),
5599
5877
  /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Card, { id: "guardrails", children: /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.CardContent, { className: "space-y-3 p-4", children: [
5600
5878
  /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "font-medium", children: "Garde-fous" }),
5601
5879
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
@@ -5804,11 +6082,6 @@ var NODE_EXITS = {
5804
6082
  ],
5805
6083
  triage: [
5806
6084
  { key: "triage-fallback", condition: "classification de repli", outcome: "triaged_only" },
5807
- {
5808
- key: "triage-closed",
5809
- condition: "le dernier message client cl\xF4t la conversation",
5810
- outcome: "no_reply_needed"
5811
- },
5812
6085
  {
5813
6086
  key: "triage-whatsapp-gate",
5814
6087
  condition: "r\xE8gle de canal WhatsApp (STOP ou pas notre tour)",
@@ -7377,6 +7650,7 @@ function parseRunResult(result) {
7377
7650
  };
7378
7651
  }
7379
7652
  function describeRunDecision(result, mode) {
7653
+ if (result.stoppedAt === "FC" && result.outcome === "no_reply_needed") return "Conversation finie \u2014 aucune r\xE9ponse.";
7380
7654
  if (result.stoppedAt !== null) return `Arr\xEAt en ${result.stoppedAt}.`;
7381
7655
  const category = result.categoryName ? ` (cat\xE9gorie \xAB ${result.categoryName} \xBB)` : "";
7382
7656
  if (result.outcome === "sent") {