@apotech-os/support-kit 7.0.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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { EVALUATION_VERDICTS, WHATSAPP_MODES, validateSettings, AGENT_GUARDRAILS, toCategory, DEFAULT_MIN_CONFIDENCE, DEFAULT_ESCALATION_ENABLED, toAuditTags, toAgent, toGeneratedResponse, toResponseComparison, toTriageDecision, isGeneratedResponseStatus, isInvalidatableStatus, toCategoryGroup, NODE_NAMES, settingsToProfile, hasNoDraftNode, outcomeTags, DEFAULT_LLM_PROVIDER, computeWordDiff, requiresFollowup, isSendableVerdict, DEFAULT_MAX_TOOL_CALLS } from '../chunk-CQJJZA4F.js';
1
+ import { EVALUATION_VERDICTS, WHATSAPP_MODES, validateSettings, AGENT_GUARDRAILS, toCategory, DEFAULT_MIN_CONFIDENCE, DEFAULT_ESCALATION_ENABLED, toAuditTags, toAgent, toGeneratedResponse, toResponseComparison, toTriageDecision, isGeneratedResponseStatus, isInvalidatableStatus, toCategoryGroup, NODE_NAMES, settingsToProfile, hasNoDraftNode, outcomeTags, DEFAULT_LLM_PROVIDER, computeWordDiff, requiresFollowup, isSendableVerdict, DEFAULT_MAX_TOOL_CALLS } from '../chunk-QCRCRNYE.js';
2
2
  import { forwardRef, useState, useMemo, useEffect, useRef, useCallback, useId } from 'react';
3
3
  import { Textarea, cn, useAppContext, useAppSettings, DateRangeCompare, Link, Card, CardHeader, CardTitle, CardContent, AreaChart, StackedBarChart, Badge, useAppApi, useToast, Button, Select, DataTable, Spinner, Switch, Input, Checkbox, comparisonRange, SidePanel, Modal, Tooltip, buttonVariants, AppInvokeError, CopyButton, relativeDelta, Table, TableHeader, TableRow, TableHead, TableBody, TableCell, downloadBlob } from '@apotech-os/ui-sdk';
4
4
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
@@ -1362,7 +1362,6 @@ function ticketActions(input) {
1362
1362
  } else if (job) {
1363
1363
  skipped.push(`R\xE9ponse non envoy\xE9e \u2014 ${notSentReason2 ?? "raison inconnue."}`);
1364
1364
  }
1365
- if (job?.outcome === "needs_human") taken.push("Alerte lev\xE9e dans la bo\xEEte de r\xE9ception.");
1366
1365
  if (job?.outcome === "awaiting_approval" && !simulated) taken.push("Demande d'approbation cr\xE9\xE9e.");
1367
1366
  return { tags, taken, skipped, simulated, unrecorded: job !== void 0 && job.outcome === null };
1368
1367
  }
@@ -3316,6 +3315,25 @@ function CategoriesPage() {
3316
3315
  toast({ title: "\xC9chec de la mise \xE0 jour", description: describeApiError(err), variant: "error" });
3317
3316
  }
3318
3317
  }
3318
+ async function toggleFollowupFastResponse(category) {
3319
+ const next = !category.followupFastResponseEnabled;
3320
+ const data = { followupFastResponseEnabled: next };
3321
+ if (!next && category.followupAutoReplyEnabled) data.followupAutoReplyEnabled = false;
3322
+ try {
3323
+ await api.patch(categoryPath(category.id), { data });
3324
+ await refreshCategories();
3325
+ } catch (err) {
3326
+ toast({ title: "\xC9chec de la mise \xE0 jour", description: describeApiError(err), variant: "error" });
3327
+ }
3328
+ }
3329
+ async function toggleFollowupAutoReply(category) {
3330
+ try {
3331
+ await api.patch(categoryPath(category.id), { data: { followupAutoReplyEnabled: !category.followupAutoReplyEnabled } });
3332
+ await refreshCategories();
3333
+ } catch (err) {
3334
+ toast({ title: "\xC9chec de la mise \xE0 jour", description: describeApiError(err), variant: "error" });
3335
+ }
3336
+ }
3319
3337
  async function move(category, direction) {
3320
3338
  const siblings = byGroup.get(category.groupId ?? UNGROUPED_KEY) ?? [];
3321
3339
  const index = siblings.findIndex((c) => c.id === category.id);
@@ -3386,6 +3404,30 @@ function CategoriesPage() {
3386
3404
  }
3387
3405
  )
3388
3406
  ] }),
3407
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
3408
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: "Fast response (suite)" }),
3409
+ /* @__PURE__ */ jsx(
3410
+ Switch,
3411
+ {
3412
+ "aria-label": `Fast response (suite) \u2014 ${category.name}`,
3413
+ checked: category.followupFastResponseEnabled,
3414
+ onCheckedChange: () => void toggleFollowupFastResponse(category),
3415
+ disabled: !canWrite || !category.agentId
3416
+ }
3417
+ )
3418
+ ] }),
3419
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
3420
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: "R\xE9ponse auto (suite)" }),
3421
+ /* @__PURE__ */ jsx(
3422
+ Switch,
3423
+ {
3424
+ "aria-label": `R\xE9ponse auto (suite) \u2014 ${category.name}`,
3425
+ checked: category.followupAutoReplyEnabled,
3426
+ onCheckedChange: () => void toggleFollowupAutoReply(category),
3427
+ disabled: !canWrite || !category.followupFastResponseEnabled || !category.agentId
3428
+ }
3429
+ )
3430
+ ] }),
3389
3431
  category.extraTags.length > 0 && /* @__PURE__ */ jsx("div", { className: "flex gap-1", children: category.extraTags.map((tag) => /* @__PURE__ */ jsx(Badge, { variant: "outline", children: tag }, tag)) }),
3390
3432
  canWrite && /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
3391
3433
  /* @__PURE__ */ jsx(
@@ -3959,6 +4001,158 @@ function SourceViewField({ views, value, onChange, disabled }) {
3959
4001
  }
3960
4002
  );
3961
4003
  }
4004
+ var STATUS_BADGE = {
4005
+ passed: { label: "OK", variant: "success" },
4006
+ stopped: { label: "Arr\xEAt", variant: "danger" },
4007
+ // A pre-gate that could not read its field. Never shown by the diagnostic
4008
+ // (it evaluates no payload) but rendered honestly if it ever appears, rather
4009
+ // than falling through to a blank badge.
4010
+ muted: { label: "Muet", variant: "warning" },
4011
+ skipped: { label: "Non \xE9valu\xE9", variant: "neutral" }
4012
+ };
4013
+ function FollowupWebhookCard({ scopeTag, onScopeTagChange, canWrite }) {
4014
+ const api = useAppApi();
4015
+ const toast = useToast();
4016
+ const scopeId = useId();
4017
+ const ticketId = useId();
4018
+ const [setup, setSetup] = useState(null);
4019
+ const [isInstalling, setIsInstalling] = useState(false);
4020
+ const [ticket, setTicket] = useState("");
4021
+ const [test, setTest] = useState(null);
4022
+ const [isTesting, setIsTesting] = useState(false);
4023
+ const [confirmingRealRun, setConfirmingRealRun] = useState(false);
4024
+ async function install() {
4025
+ setIsInstalling(true);
4026
+ try {
4027
+ setSetup(await api.invoke("setup-gorgias-webhook", {}));
4028
+ toast({ title: "Webhook Gorgias install\xE9.", variant: "success" });
4029
+ } catch (err) {
4030
+ setSetup(null);
4031
+ toast({ title: "\xC9chec de l'installation", description: describeInvokeError(err), variant: "error" });
4032
+ } finally {
4033
+ setIsInstalling(false);
4034
+ }
4035
+ }
4036
+ async function runTest(mode) {
4037
+ setIsTesting(true);
4038
+ setTest(null);
4039
+ try {
4040
+ setTest(await api.invoke("test-gorgias-webhook", { ticketId: ticket.trim(), mode }));
4041
+ } catch (err) {
4042
+ toast({ title: "\xC9chec du test", description: describeInvokeError(err), variant: "error" });
4043
+ } finally {
4044
+ setIsTesting(false);
4045
+ setConfirmingRealRun(false);
4046
+ }
4047
+ }
4048
+ return /* @__PURE__ */ jsxs(Card, { id: "webhook-suite", children: [
4049
+ /* @__PURE__ */ jsxs(CardContent, { className: "space-y-4 p-4", children: [
4050
+ /* @__PURE__ */ jsxs("div", { children: [
4051
+ /* @__PURE__ */ jsx("h2", { className: "font-medium", children: "R\xE9ponses aux messages suivants" }),
4052
+ /* @__PURE__ */ 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)." })
4053
+ ] }),
4054
+ /* @__PURE__ */ jsxs("div", { children: [
4055
+ /* @__PURE__ */ jsx("label", { htmlFor: scopeId, className: "mb-1 block text-sm font-medium", children: "Tag de p\xE9rim\xE8tre webhook" }),
4056
+ /* @__PURE__ */ jsx(
4057
+ Input,
4058
+ {
4059
+ id: scopeId,
4060
+ value: scopeTag,
4061
+ onChange: (e) => onScopeTagChange(e.target.value),
4062
+ placeholder: "wai/triaged",
4063
+ disabled: !canWrite
4064
+ }
4065
+ ),
4066
+ /* @__PURE__ */ jsxs("p", { className: "mt-1 text-xs text-muted-foreground", children: [
4067
+ "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. ",
4068
+ /* @__PURE__ */ jsx("strong", { children: "Vide = aucun message suivant trait\xE9" }),
4069
+ " (c'est aussi le kill-switch). Deux apps sur le m\xEAme compte Gorgias doivent y mettre des valeurs ",
4070
+ /* @__PURE__ */ jsx("strong", { children: "distinctes" }),
4071
+ ", sinon chacune r\xE9pondrait sur les tickets de l'autre."
4072
+ ] })
4073
+ ] }),
4074
+ /* @__PURE__ */ jsxs("div", { className: "space-y-2 border-t pt-4", children: [
4075
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: "Int\xE9gration Gorgias" }),
4076
+ /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
4077
+ "Renseignez d'abord la variable serveur ",
4078
+ /* @__PURE__ */ jsx("code", { children: "GORGIAS_CALLBACK_APP_KEY" }),
4079
+ " (une cl\xE9 d'application",
4080
+ " ",
4081
+ /* @__PURE__ */ jsx("code", { children: "wopilo_app_\u2026" }),
4082
+ "), puis installez l'int\xE9gration. L'op\xE9ration est idempotente : re-cliquer la met \xE0 jour."
4083
+ ] }),
4084
+ canWrite && /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: () => void install(), disabled: isInstalling, children: isInstalling ? "Installation\u2026" : "Installer le webhook Gorgias" }),
4085
+ setup && /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
4086
+ setup.created ? "Int\xE9gration cr\xE9\xE9e" : "Int\xE9gration mise \xE0 jour",
4087
+ " \u2014 Gorgias appellera",
4088
+ " ",
4089
+ /* @__PURE__ */ jsx("code", { children: setup.url }),
4090
+ "."
4091
+ ] })
4092
+ ] }),
4093
+ /* @__PURE__ */ jsxs("div", { className: "space-y-2 border-t pt-4", children: [
4094
+ /* @__PURE__ */ jsx("label", { htmlFor: ticketId, className: "block text-sm font-medium", children: "Ticket \xE0 tester" }),
4095
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
4096
+ /* @__PURE__ */ jsx(
4097
+ Input,
4098
+ {
4099
+ id: ticketId,
4100
+ value: ticket,
4101
+ onChange: (e) => setTicket(e.target.value),
4102
+ placeholder: "1534712154",
4103
+ className: "max-w-48"
4104
+ }
4105
+ ),
4106
+ /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: () => void runTest("diagnostic"), disabled: !ticket.trim() || isTesting, children: "Diagnostic" }),
4107
+ canWrite && /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: () => setConfirmingRealRun(true), disabled: !ticket.trim() || isTesting, children: "Ex\xE9cution r\xE9elle" })
4108
+ ] }),
4109
+ /* @__PURE__ */ 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." }),
4110
+ isTesting && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-sm text-muted-foreground", children: [
4111
+ /* @__PURE__ */ jsx(Spinner, {}),
4112
+ " Test en cours\u2026"
4113
+ ] }),
4114
+ test?.mode === "run" && /* @__PURE__ */ jsxs("p", { className: "text-sm", children: [
4115
+ "Traitement d\xE9clench\xE9. Run \xE0 suivre : ",
4116
+ /* @__PURE__ */ jsx("code", { children: test.runId }),
4117
+ "."
4118
+ ] }),
4119
+ test?.mode === "diagnostic" && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
4120
+ /* @__PURE__ */ 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}.` }),
4121
+ /* @__PURE__ */ jsx("ul", { className: "space-y-1", children: test.gates.map((gate) => /* @__PURE__ */ jsxs("li", { className: "flex items-start gap-2 text-xs", children: [
4122
+ /* @__PURE__ */ jsx(Badge, { variant: STATUS_BADGE[gate.status].variant, children: STATUS_BADGE[gate.status].label }),
4123
+ /* @__PURE__ */ jsxs("span", { children: [
4124
+ /* @__PURE__ */ jsxs("span", { className: "font-medium", children: [
4125
+ gate.gate,
4126
+ " \u2014 ",
4127
+ gate.label
4128
+ ] }),
4129
+ /* @__PURE__ */ jsx("br", {}),
4130
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: gate.detail })
4131
+ ] })
4132
+ ] }, gate.gate)) })
4133
+ ] })
4134
+ ] })
4135
+ ] }),
4136
+ confirmingRealRun && /* @__PURE__ */ jsx(
4137
+ ConfirmModal,
4138
+ {
4139
+ title: "Lancer le traitement r\xE9el ?",
4140
+ description: /* @__PURE__ */ jsxs(Fragment, { children: [
4141
+ "Le ticket ",
4142
+ ticket.trim(),
4143
+ " va \xEAtre trait\xE9 comme un vrai message suivant : g\xE9n\xE9ration, garde-fous, et",
4144
+ " ",
4145
+ /* @__PURE__ */ jsx("strong", { children: "envoi r\xE9el au client" }),
4146
+ " si sa cat\xE9gorie est en r\xE9ponse automatique. \xC0 r\xE9server \xE0 un ticket de test."
4147
+ ] }),
4148
+ confirmLabel: "Lancer",
4149
+ busyLabel: "D\xE9clenchement\u2026",
4150
+ onConfirm: () => runTest("run"),
4151
+ onCancel: () => setConfirmingRealRun(false)
4152
+ }
4153
+ )
4154
+ ] });
4155
+ }
3962
4156
  var WHATSAPP_MODE_LABELS = {
3963
4157
  escalate_only: "Escalade uniquement",
3964
4158
  draft_only: "Brouillon uniquement",
@@ -3978,7 +4172,7 @@ function list(value) {
3978
4172
  return Array.isArray(value) ? value.join(", ") : "";
3979
4173
  }
3980
4174
  function parseList(value) {
3981
- return value.split(",").map((v) => v.trim()).filter(Boolean);
4175
+ return value.split(/[\n,]/).map((v) => v.trim()).filter(Boolean);
3982
4176
  }
3983
4177
  function describeConnection(connections) {
3984
4178
  if (connections === void 0) return { text: "Chargement\u2026", tone: "muted" };
@@ -4254,6 +4448,14 @@ function SettingsPage() {
4254
4448
  /* @__PURE__ */ jsx(Input, { id: key, value: field(form[key]), onChange: (e) => set(key, e.target.value), disabled: !canWrite })
4255
4449
  ] }, key))
4256
4450
  ] }) }),
4451
+ /* @__PURE__ */ jsx(
4452
+ FollowupWebhookCard,
4453
+ {
4454
+ scopeTag: field(form.webhookScopeTag),
4455
+ onScopeTagChange: (value) => set("webhookScopeTag", value),
4456
+ canWrite
4457
+ }
4458
+ ),
4257
4459
  /* @__PURE__ */ jsx(Card, { id: "guardrails", children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-3 p-4", children: [
4258
4460
  /* @__PURE__ */ jsx("h2", { className: "font-medium", children: "Garde-fous" }),
4259
4461
  /* @__PURE__ */ jsxs("div", { children: [
@@ -4270,7 +4472,7 @@ function SettingsPage() {
4270
4472
  )) })
4271
4473
  ] }),
4272
4474
  /* @__PURE__ */ jsxs("div", { children: [
4273
- /* @__PURE__ */ jsx("label", { htmlFor: "blocklist", className: "mb-1 block text-sm font-medium", children: "Liste de blocage" }),
4475
+ /* @__PURE__ */ 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)" }),
4274
4476
  /* @__PURE__ */ jsx(
4275
4477
  Textarea,
4276
4478
  {
@@ -4282,7 +4484,7 @@ function SettingsPage() {
4282
4484
  )
4283
4485
  ] }),
4284
4486
  /* @__PURE__ */ jsxs("div", { children: [
4285
- /* @__PURE__ */ jsx("label", { htmlFor: "noreplySenders", className: "mb-1 block text-sm font-medium", children: "Exp\xE9diteurs no-reply (s\xE9par\xE9s par des virgules)" }),
4487
+ /* @__PURE__ */ 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)" }),
4286
4488
  /* @__PURE__ */ jsx(
4287
4489
  Textarea,
4288
4490
  {