@apotech-os/support-kit 6.3.0 → 7.0.1

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
@@ -54,6 +54,16 @@ function requiresFollowup(verdict) {
54
54
  return verdict === "send_and_escalate";
55
55
  }
56
56
 
57
+ // src/domain/origin.ts
58
+ var DECISION_ORIGINS = ["triage", "followup"];
59
+ var DEFAULT_DECISION_ORIGIN = "triage";
60
+ function isDecisionOrigin(value) {
61
+ return typeof value === "string" && DECISION_ORIGINS.includes(value);
62
+ }
63
+ function toDecisionOrigin(value) {
64
+ return isDecisionOrigin(value) ? value : DEFAULT_DECISION_ORIGIN;
65
+ }
66
+
57
67
  // src/functions/records.ts
58
68
  function toAgent(record) {
59
69
  const data = record.data;
@@ -82,7 +92,9 @@ function toCategory(record) {
82
92
  description: data.description ?? null,
83
93
  examples: data.examples ?? null,
84
94
  autoReplyEnabled: data.autoReplyEnabled ?? false,
85
- fastResponseEnabled: data.fastResponseEnabled ?? false
95
+ fastResponseEnabled: data.fastResponseEnabled ?? false,
96
+ followupFastResponseEnabled: data.followupFastResponseEnabled ?? false,
97
+ followupAutoReplyEnabled: data.followupAutoReplyEnabled ?? false
86
98
  };
87
99
  }
88
100
  function toCategoryGroup(record) {
@@ -111,7 +123,8 @@ function toTriageDecision(record) {
111
123
  status: data.status ?? null,
112
124
  error: data.error ?? null,
113
125
  runId: data.runId ?? null,
114
- subjectRenamed: data.subjectRenamed ?? false
126
+ subjectRenamed: data.subjectRenamed ?? false,
127
+ origin: toDecisionOrigin(data.origin)
115
128
  };
116
129
  }
117
130
  function toVerdict(raw) {
@@ -152,7 +165,8 @@ function toGeneratedResponse(record) {
152
165
  autoSendDecision: data.autoSendDecision ?? null,
153
166
  sentAt: data.sentAt ?? null,
154
167
  sentMessageId: data.sentMessageId ?? null,
155
- error: data.error ?? null
168
+ error: data.error ?? null,
169
+ origin: toDecisionOrigin(data.origin)
156
170
  };
157
171
  }
158
172
  function toResponseComparison(record) {
@@ -1840,7 +1854,6 @@ function ticketActions(input) {
1840
1854
  } else if (job) {
1841
1855
  skipped.push(`R\xE9ponse non envoy\xE9e \u2014 ${notSentReason2 ?? "raison inconnue."}`);
1842
1856
  }
1843
- if (job?.outcome === "needs_human") taken.push("Alerte lev\xE9e dans la bo\xEEte de r\xE9ception.");
1844
1857
  if (job?.outcome === "awaiting_approval" && !simulated) taken.push("Demande d'approbation cr\xE9\xE9e.");
1845
1858
  return { tags, taken, skipped, simulated, unrecorded: job !== void 0 && job.outcome === null };
1846
1859
  }
@@ -3794,6 +3807,25 @@ function CategoriesPage() {
3794
3807
  toast({ title: "\xC9chec de la mise \xE0 jour", description: describeApiError(err), variant: "error" });
3795
3808
  }
3796
3809
  }
3810
+ async function toggleFollowupFastResponse(category) {
3811
+ const next = !category.followupFastResponseEnabled;
3812
+ const data = { followupFastResponseEnabled: next };
3813
+ if (!next && category.followupAutoReplyEnabled) data.followupAutoReplyEnabled = false;
3814
+ try {
3815
+ await api.patch(categoryPath(category.id), { data });
3816
+ await refreshCategories();
3817
+ } catch (err) {
3818
+ toast({ title: "\xC9chec de la mise \xE0 jour", description: describeApiError(err), variant: "error" });
3819
+ }
3820
+ }
3821
+ async function toggleFollowupAutoReply(category) {
3822
+ try {
3823
+ await api.patch(categoryPath(category.id), { data: { followupAutoReplyEnabled: !category.followupAutoReplyEnabled } });
3824
+ await refreshCategories();
3825
+ } catch (err) {
3826
+ toast({ title: "\xC9chec de la mise \xE0 jour", description: describeApiError(err), variant: "error" });
3827
+ }
3828
+ }
3797
3829
  async function move(category, direction) {
3798
3830
  const siblings = byGroup.get(category.groupId ?? UNGROUPED_KEY) ?? [];
3799
3831
  const index = siblings.findIndex((c) => c.id === category.id);
@@ -3864,6 +3896,30 @@ function CategoriesPage() {
3864
3896
  }
3865
3897
  )
3866
3898
  ] }),
3899
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
3900
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-muted-foreground", children: "Fast response (suite)" }),
3901
+ /* @__PURE__ */ jsxRuntime.jsx(
3902
+ uiSdk.Switch,
3903
+ {
3904
+ "aria-label": `Fast response (suite) \u2014 ${category.name}`,
3905
+ checked: category.followupFastResponseEnabled,
3906
+ onCheckedChange: () => void toggleFollowupFastResponse(category),
3907
+ disabled: !canWrite || !category.agentId
3908
+ }
3909
+ )
3910
+ ] }),
3911
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
3912
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-muted-foreground", children: "R\xE9ponse auto (suite)" }),
3913
+ /* @__PURE__ */ jsxRuntime.jsx(
3914
+ uiSdk.Switch,
3915
+ {
3916
+ "aria-label": `R\xE9ponse auto (suite) \u2014 ${category.name}`,
3917
+ checked: category.followupAutoReplyEnabled,
3918
+ onCheckedChange: () => void toggleFollowupAutoReply(category),
3919
+ disabled: !canWrite || !category.followupFastResponseEnabled || !category.agentId
3920
+ }
3921
+ )
3922
+ ] }),
3867
3923
  category.extraTags.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-1", children: category.extraTags.map((tag) => /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: "outline", children: tag }, tag)) }),
3868
3924
  canWrite && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
3869
3925
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -4492,6 +4548,158 @@ function SourceViewField({ views, value, onChange, disabled }) {
4492
4548
  }
4493
4549
  );
4494
4550
  }
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" }
4559
+ };
4560
+ function FollowupWebhookCard({ scopeTag, onScopeTagChange, canWrite }) {
4561
+ const api = uiSdk.useAppApi();
4562
+ const toast = uiSdk.useToast();
4563
+ 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
+ ] })
4620
+ ] }),
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."
4630
+ ] }),
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
+ "."
4638
+ ] })
4639
+ ] }),
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
+ ] })
4681
+ ] })
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
+ )
4701
+ ] });
4702
+ }
4495
4703
  var WHATSAPP_MODE_LABELS = {
4496
4704
  escalate_only: "Escalade uniquement",
4497
4705
  draft_only: "Brouillon uniquement",
@@ -4511,7 +4719,7 @@ function list(value) {
4511
4719
  return Array.isArray(value) ? value.join(", ") : "";
4512
4720
  }
4513
4721
  function parseList(value) {
4514
- return value.split(",").map((v) => v.trim()).filter(Boolean);
4722
+ return value.split(/[\n,]/).map((v) => v.trim()).filter(Boolean);
4515
4723
  }
4516
4724
  function describeConnection(connections) {
4517
4725
  if (connections === void 0) return { text: "Chargement\u2026", tone: "muted" };
@@ -4787,6 +4995,14 @@ function SettingsPage() {
4787
4995
  /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Input, { id: key, value: field(form[key]), onChange: (e) => set(key, e.target.value), disabled: !canWrite })
4788
4996
  ] }, key))
4789
4997
  ] }) }),
4998
+ /* @__PURE__ */ jsxRuntime.jsx(
4999
+ FollowupWebhookCard,
5000
+ {
5001
+ scopeTag: field(form.webhookScopeTag),
5002
+ onScopeTagChange: (value) => set("webhookScopeTag", value),
5003
+ canWrite
5004
+ }
5005
+ ),
4790
5006
  /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Card, { id: "guardrails", children: /* @__PURE__ */ jsxRuntime.jsxs(uiSdk.CardContent, { className: "space-y-3 p-4", children: [
4791
5007
  /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "font-medium", children: "Garde-fous" }),
4792
5008
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
@@ -4803,7 +5019,7 @@ function SettingsPage() {
4803
5019
  )) })
4804
5020
  ] }),
4805
5021
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4806
- /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "blocklist", className: "mb-1 block text-sm font-medium", children: "Liste de blocage" }),
5022
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "blocklist", className: "mb-1 block text-sm font-medium", children: "Liste de blocage (un par ligne ou s\xE9par\xE9s par des virgules)" }),
4807
5023
  /* @__PURE__ */ jsxRuntime.jsx(
4808
5024
  uiSdk.Textarea,
4809
5025
  {
@@ -4815,7 +5031,7 @@ function SettingsPage() {
4815
5031
  )
4816
5032
  ] }),
4817
5033
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4818
- /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "noreplySenders", className: "mb-1 block text-sm font-medium", children: "Exp\xE9diteurs no-reply (s\xE9par\xE9s par des virgules)" }),
5034
+ /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: "noreplySenders", className: "mb-1 block text-sm font-medium", children: "Exp\xE9diteurs no-reply (un par ligne ou s\xE9par\xE9s par des virgules)" }),
4819
5035
  /* @__PURE__ */ jsxRuntime.jsx(
4820
5036
  uiSdk.Textarea,
4821
5037
  {