@apotech-os/support-kit 8.0.0 → 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.js CHANGED
@@ -1,6 +1,6 @@
1
- import { EVALUATION_VERDICTS, WHATSAPP_MODES, validateSettings, AGENT_GUARDRAILS, toCategory, DEFAULT_MIN_CONFIDENCE, DEFAULT_ESCALATION_ENABLED, toAuditTags, toAgent, toGeneratedResponse, toResponseComparison, toTriageDecision, isGeneratedResponseStatus, isInvalidatableStatus, toCategoryGroup, followupIntegrationName, FOLLOWUP_WEBHOOK_TRIGGER, followupWebhookPath, FOLLOWUP_WEBHOOK_FORM, NODE_NAMES, settingsToProfile, hasNoDraftNode, outcomeTags, DEFAULT_LLM_PROVIDER, computeWordDiff, requiresFollowup, isSendableVerdict, DEFAULT_MAX_TOOL_CALLS } from '../chunk-2UHFKGMI.js';
2
- import { forwardRef, useState, useMemo, useEffect, useRef, useCallback, useId } from 'react';
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';
1
+ import { EVALUATION_VERDICTS, WHATSAPP_MODES, validateSettings, AGENT_GUARDRAILS, toCategory, DEFAULT_MIN_CONFIDENCE, DEFAULT_ESCALATION_ENABLED, toAuditTags, toAgent, toGeneratedResponse, toResponseComparison, toTriageDecision, isGeneratedResponseStatus, isInvalidatableStatus, toCategoryGroup, followupIntegrationName, FOLLOWUP_WEBHOOK_TRIGGER, followupWebhookPath, FOLLOWUP_WEBHOOK_FORM, NODE_NAMES, settingsToProfile, hasNoDraftNode, outcomeTags, DEFAULT_LLM_PROVIDER, computeWordDiff, requiresFollowup, isSendableVerdict, DEFAULT_MAX_TOOL_CALLS } from '../chunk-LXHPPWPM.js';
2
+ import { forwardRef, useState, useMemo, useRef, useEffect, useCallback, useId } from 'react';
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, useAppRun, 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';
5
5
 
6
6
  function useRecordList(objectKey, query, mapper) {
@@ -156,6 +156,7 @@ var EMPTY_TOTALS = {
156
156
  failed: 0
157
157
  };
158
158
  function outcomeOf(status, autoSendDecision) {
159
+ if (status === "test_draft") return null;
159
160
  if (status === "sent") return "auto";
160
161
  if (status === "no_reply_needed") return "noReplyNeeded";
161
162
  if (status === "failed") return "failed";
@@ -165,7 +166,8 @@ function outcomeOf(status, autoSendDecision) {
165
166
  function foldOutcomes(rows) {
166
167
  const totals = { ...EMPTY_TOTALS };
167
168
  for (const row of rows) {
168
- totals[outcomeOf(row["status"], row["autoSendDecision"])] += Number(row["count"]) || 0;
169
+ const outcome = outcomeOf(row["status"], row["autoSendDecision"]);
170
+ if (outcome !== null) totals[outcome] += Number(row["count"]) || 0;
169
171
  }
170
172
  return totals;
171
173
  }
@@ -179,9 +181,11 @@ function autonomyRate(totals) {
179
181
  function foldDailyOutcomes(rows) {
180
182
  const byDay = /* @__PURE__ */ new Map();
181
183
  for (const row of rows) {
184
+ const outcome = outcomeOf(row["status"], row["autoSendDecision"]);
185
+ if (outcome === null) continue;
182
186
  const day = bucketDay(row);
183
187
  const totals = byDay.get(day) ?? { ...EMPTY_TOTALS };
184
- totals[outcomeOf(row["status"], row["autoSendDecision"])] += Number(row["count"]) || 0;
188
+ totals[outcome] += Number(row["count"]) || 0;
185
189
  byDay.set(day, totals);
186
190
  }
187
191
  return [...byDay.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([day, totals]) => ({
@@ -934,6 +938,31 @@ function TicketLink({ ticketId, url, label }) {
934
938
  }
935
939
  );
936
940
  }
941
+ function readParam(name) {
942
+ if (typeof window === "undefined") return null;
943
+ return new URLSearchParams(window.location.search).get(name);
944
+ }
945
+ function useQueryParam(name) {
946
+ const [value, setState] = useState(() => readParam(name));
947
+ useEffect(() => {
948
+ const sync = () => setState(readParam(name));
949
+ sync();
950
+ window.addEventListener("popstate", sync);
951
+ return () => window.removeEventListener("popstate", sync);
952
+ }, [name]);
953
+ const setValue = useCallback(
954
+ (next) => {
955
+ const params = new URLSearchParams(window.location.search);
956
+ if (next === null) params.delete(name);
957
+ else params.set(name, next);
958
+ const query = params.toString();
959
+ window.history.pushState({}, "", `${window.location.pathname}${query ? `?${query}` : ""}`);
960
+ setState(next);
961
+ },
962
+ [name]
963
+ );
964
+ return { value, setValue };
965
+ }
937
966
  var UNCONFIGURED = { baseUrl: null, projectId: null };
938
967
  function useLangfuseConfig() {
939
968
  const { appSlug } = useAppContext();
@@ -1011,7 +1040,8 @@ var GENERATED_RESPONSE_STATUS_LABELS = {
1011
1040
  failed: "\xC9chec",
1012
1041
  no_reply_needed: "Aucune r\xE9ponse n\xE9cessaire",
1013
1042
  invalidated: "Invalid\xE9e",
1014
- expired: "Expir\xE9e"
1043
+ expired: "Expir\xE9e",
1044
+ test_draft: "Brouillon d'essai \u2014 jamais envoy\xE9"
1015
1045
  };
1016
1046
  var AUTO_SEND_DECISION_LABELS = {
1017
1047
  auto: "Autoris\xE9",
@@ -1241,6 +1271,8 @@ function deliveryReason(input) {
1241
1271
  }
1242
1272
  case "failed":
1243
1273
  return job.error ?? "La r\xE9ponse a \xE9chou\xE9 avant son envoi.";
1274
+ case "test_draft":
1275
+ return "Brouillon d'essai \u2014 jamais envoy\xE9.";
1244
1276
  default:
1245
1277
  return `La r\xE9ponse n'a pas \xE9t\xE9 envoy\xE9e (statut : ${job.status}).`;
1246
1278
  }
@@ -1753,6 +1785,15 @@ function TicketsPage() {
1753
1785
  return true;
1754
1786
  });
1755
1787
  }, [decisions, jobByDecisionId, comparisonsByTicketId, outcomeFilter, verdictFilter, promptVersionFilter, correctedFilter]);
1788
+ const requestedTicket = useQueryParam("ticket").value;
1789
+ const deepLinkConsumed = useRef(false);
1790
+ useEffect(() => {
1791
+ if (deepLinkConsumed.current || !requestedTicket) return;
1792
+ const match = rows.find((row) => row.decision.ticketId === requestedTicket);
1793
+ if (!match) return;
1794
+ deepLinkConsumed.current = true;
1795
+ setDetailDecision(match.decision);
1796
+ }, [requestedTicket, rows]);
1756
1797
  const categoryOptions = useMemo(
1757
1798
  () => [{ value: "", label: "Toutes cat\xE9gories" }, ...categories.map((category) => ({ value: category.id, label: category.name }))],
1758
1799
  [categories]
@@ -4539,31 +4580,6 @@ function SettingsPage() {
4539
4580
  );
4540
4581
  }
4541
4582
  var ReglagesPage = SettingsPage;
4542
- function readParam(name) {
4543
- if (typeof window === "undefined") return null;
4544
- return new URLSearchParams(window.location.search).get(name);
4545
- }
4546
- function useQueryParam(name) {
4547
- const [value, setState] = useState(() => readParam(name));
4548
- useEffect(() => {
4549
- const sync = () => setState(readParam(name));
4550
- sync();
4551
- window.addEventListener("popstate", sync);
4552
- return () => window.removeEventListener("popstate", sync);
4553
- }, [name]);
4554
- const setValue = useCallback(
4555
- (next) => {
4556
- const params = new URLSearchParams(window.location.search);
4557
- if (next === null) params.delete(name);
4558
- else params.set(name, next);
4559
- const query = params.toString();
4560
- window.history.pushState({}, "", `${window.location.pathname}${query ? `?${query}` : ""}`);
4561
- setState(next);
4562
- },
4563
- [name]
4564
- );
4565
- return { value, setValue };
4566
- }
4567
4583
 
4568
4584
  // src/ui/graph-canvas/reachability.ts
4569
4585
  var EXIT_TONES = {
@@ -6140,20 +6156,80 @@ function DryRunResultView({ result, langfuseConfig, knownTags, tagSettings }) {
6140
6156
  var STATUS_BADGE = {
6141
6157
  passed: { label: "OK", variant: "success" },
6142
6158
  stopped: { label: "Arr\xEAt", variant: "danger" },
6143
- // A pre-gate that could not read its field. Never shown by the diagnostic
6144
- // (it evaluates no payload) but rendered honestly if it ever appears, rather
6145
- // than falling through to a blank badge.
6159
+ // A pre-gate that could not read its field. The diagnostic never produces
6160
+ // one (it evaluates no payload), but a run stopped on a pre-gate does —
6161
+ // rendered honestly rather than falling through to a blank badge.
6146
6162
  muted: { label: "Muet", variant: "warning" },
6147
6163
  skipped: { label: "Non \xE9valu\xE9", variant: "neutral" }
6148
6164
  };
6165
+ function GatesTable({ gates }) {
6166
+ return /* @__PURE__ */ jsx("ul", { className: "space-y-1", children: gates.map((gate) => {
6167
+ const badge = STATUS_BADGE[gate.status] ?? STATUS_BADGE.skipped;
6168
+ return /* @__PURE__ */ jsxs("li", { className: "flex items-start gap-2 text-xs", children: [
6169
+ /* @__PURE__ */ jsx(Badge, { variant: badge.variant, children: badge.label }),
6170
+ /* @__PURE__ */ jsxs("span", { children: [
6171
+ /* @__PURE__ */ jsxs("span", { className: "font-medium", children: [
6172
+ gate.gate,
6173
+ " \u2014 ",
6174
+ gate.label
6175
+ ] }),
6176
+ /* @__PURE__ */ jsx("br", {}),
6177
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: gate.detail })
6178
+ ] })
6179
+ ] }, gate.gate);
6180
+ }) });
6181
+ }
6182
+ function parseRunResult(result) {
6183
+ if (typeof result !== "object" || result === null) return null;
6184
+ const raw = result;
6185
+ if (!Array.isArray(raw.gates)) return null;
6186
+ return {
6187
+ ticketId: typeof raw.ticketId === "string" ? raw.ticketId : null,
6188
+ stoppedAt: typeof raw.stoppedAt === "string" ? raw.stoppedAt : null,
6189
+ reason: typeof raw.reason === "string" ? raw.reason : null,
6190
+ gates: raw.gates,
6191
+ categoryName: typeof raw.categoryName === "string" ? raw.categoryName : null,
6192
+ outcome: typeof raw.outcome === "string" ? raw.outcome : null,
6193
+ responseId: typeof raw.responseId === "string" ? raw.responseId : null
6194
+ };
6195
+ }
6196
+ function describeRunDecision(result, mode) {
6197
+ if (result.stoppedAt !== null) return `Arr\xEAt en ${result.stoppedAt}.`;
6198
+ const category = result.categoryName ? ` (cat\xE9gorie \xAB ${result.categoryName} \xBB)` : "";
6199
+ if (result.outcome === "sent") {
6200
+ 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}.`;
6201
+ }
6202
+ const label = result.outcome !== null && result.outcome in OUTCOME_LABELS ? OUTCOME_LABELS[result.outcome] : null;
6203
+ return label ? `${label}${category}.` : `Traitement termin\xE9${category}.`;
6204
+ }
6149
6205
  function FollowupWebhookCard2() {
6150
6206
  const api = useAppApi();
6207
+ const { appSlug } = useAppContext();
6151
6208
  const toast = useToast();
6152
6209
  const ticketId = useId();
6153
6210
  const [ticket, setTicket] = useState("");
6154
6211
  const [test, setTest] = useState(null);
6155
6212
  const [isTesting, setIsTesting] = useState(false);
6156
6213
  const [confirmingRealRun, setConfirmingRealRun] = useState(false);
6214
+ const followedRunId = test !== null && test.mode !== "diagnostic" ? test.runId : null;
6215
+ const { run, isPolling } = useAppRun(followedRunId);
6216
+ const runResult = run && run.status === "succeeded" ? parseRunResult(run.result) : null;
6217
+ const [draftText, setDraftText] = useState(null);
6218
+ useEffect(() => {
6219
+ setDraftText(null);
6220
+ const responseId = runResult?.responseId;
6221
+ if (!responseId) return;
6222
+ let cancelled = false;
6223
+ void api.get(
6224
+ `/data/apps/${appSlug}/records/generated-response/${encodeURIComponent(responseId)}`
6225
+ ).then((record) => {
6226
+ if (!cancelled) setDraftText(record?.data?.responseText ?? null);
6227
+ }).catch(() => {
6228
+ });
6229
+ return () => {
6230
+ cancelled = true;
6231
+ };
6232
+ }, [runResult?.responseId, appSlug]);
6157
6233
  async function runTest(mode) {
6158
6234
  setIsTesting(true);
6159
6235
  setTest(null);
@@ -6210,20 +6286,29 @@ function FollowupWebhookCard2() {
6210
6286
  /* @__PURE__ */ jsx("code", { children: test.runId }),
6211
6287
  "."
6212
6288
  ] }),
6289
+ test !== null && test.mode !== "diagnostic" && /* @__PURE__ */ jsxs(Fragment, { children: [
6290
+ isPolling && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-sm text-muted-foreground", children: [
6291
+ /* @__PURE__ */ jsx(Spinner, {}),
6292
+ " Ex\xE9cution en cours\u2026"
6293
+ ] }),
6294
+ run?.status === "failed" && /* @__PURE__ */ jsxs("p", { className: "text-sm text-destructive", children: [
6295
+ "L'ex\xE9cution a \xE9chou\xE9 : ",
6296
+ run.error?.message ?? "erreur inconnue."
6297
+ ] }),
6298
+ runResult && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
6299
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: describeRunDecision(runResult, test.mode) }),
6300
+ runResult.stoppedAt !== null && runResult.reason !== null && !runResult.gates.some((gate) => gate.status === "stopped") && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: runResult.reason }),
6301
+ /* @__PURE__ */ jsx(GatesTable, { gates: runResult.gates }),
6302
+ draftText !== null && /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
6303
+ /* @__PURE__ */ jsx("p", { className: "text-xs font-medium", children: "Brouillon g\xE9n\xE9r\xE9" }),
6304
+ /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap rounded border bg-muted/30 p-2 text-xs", children: draftText })
6305
+ ] }),
6306
+ /* @__PURE__ */ jsx("p", { className: "text-xs", children: /* @__PURE__ */ jsx(Link, { href: `/espace/${appSlug}/tickets?ticket=${encodeURIComponent(runResult.ticketId ?? test.ticketId)}`, children: "Ouvrir la fiche du ticket" }) })
6307
+ ] })
6308
+ ] }),
6213
6309
  test?.mode === "diagnostic" && /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
6214
6310
  /* @__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}.` }),
6215
- /* @__PURE__ */ jsx("ul", { className: "space-y-1", children: test.gates.map((gate) => /* @__PURE__ */ jsxs("li", { className: "flex items-start gap-2 text-xs", children: [
6216
- /* @__PURE__ */ jsx(Badge, { variant: STATUS_BADGE[gate.status].variant, children: STATUS_BADGE[gate.status].label }),
6217
- /* @__PURE__ */ jsxs("span", { children: [
6218
- /* @__PURE__ */ jsxs("span", { className: "font-medium", children: [
6219
- gate.gate,
6220
- " \u2014 ",
6221
- gate.label
6222
- ] }),
6223
- /* @__PURE__ */ jsx("br", {}),
6224
- /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: gate.detail })
6225
- ] })
6226
- ] }, gate.gate)) })
6311
+ /* @__PURE__ */ jsx(GatesTable, { gates: test.gates })
6227
6312
  ] })
6228
6313
  ] })
6229
6314
  ] }),