@apotech-os/support-kit 8.3.0 → 8.4.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,4 +1,4 @@
1
- import { EVALUATION_VERDICTS, WHATSAPP_MODES, validateSettings, settingsWarnings, AGENT_GUARDRAILS, toCategory, DEFAULT_MIN_CONFIDENCE, DEFAULT_ESCALATION_ENABLED, toAuditTags, toGeneratedResponse, toTriageDecision, toAgent, toResponseComparison, 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-WVKCRPMV.js';
1
+ import { EVALUATION_VERDICTS, WHATSAPP_MODES, validateSettings, settingsWarnings, AGENT_GUARDRAILS, toCategory, DEFAULT_MIN_CONFIDENCE, DEFAULT_ESCALATION_ENABLED, toAuditTags, toGeneratedResponse, toTriageDecision, toAgent, toResponseComparison, 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-D3QGGJAI.js';
2
2
  import { forwardRef, useState, useMemo, useRef, useCallback, useEffect, 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, 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';
@@ -145,6 +145,9 @@ function toNameMap(rows) {
145
145
  }
146
146
 
147
147
  // src/ui/dashboard/dashboard-stats.ts
148
+ function sumCounts(rows, countField = "count") {
149
+ return rows.reduce((sum, row) => sum + (Number(row[countField]) || 0), 0);
150
+ }
148
151
  function bucketDay(row) {
149
152
  return String(row["bucket"]).slice(0, 10);
150
153
  }
@@ -152,23 +155,38 @@ var EMPTY_TOTALS = {
152
155
  auto: 0,
153
156
  human: 0,
154
157
  inProgress: 0,
155
- noReplyNeeded: 0,
156
- failed: 0
158
+ noReplyNeeded: 0
157
159
  };
158
- function outcomeOf(status, autoSendDecision) {
159
- if (status === "test_draft") return null;
160
+ function countFailed(rows) {
161
+ return sumCounts(rows.filter((row) => row["status"] === "failed"));
162
+ }
163
+ var HUMAN_OUTCOMES = /* @__PURE__ */ new Set(["needs_human", "guardrail_hold", "escalated", "awaiting_approval"]);
164
+ function isUnautomatedTriage(row) {
165
+ return row["escalated"] === "true" || row["status"] === "error";
166
+ }
167
+ function outcomeOf(row) {
168
+ const status = row["status"];
169
+ const autoSendDecision = row["autoSendDecision"];
170
+ if (status === "test_draft" || status === "superseded") return null;
160
171
  if (status === "sent") return "auto";
161
172
  if (status === "no_reply_needed") return "noReplyNeeded";
162
- if (status === "failed") return "failed";
173
+ if (status === "failed") return "human";
163
174
  if (status === "invalidated" || status === "expired") return "human";
175
+ const outcome = row["outcome"];
176
+ if (typeof outcome === "string" && HUMAN_OUTCOMES.has(outcome)) return "human";
177
+ if (outcome === "no_reply_needed") return "noReplyNeeded";
178
+ if (outcome === "triaged_only") return null;
164
179
  return autoSendDecision === "hold" ? "human" : "inProgress";
165
180
  }
166
- function foldOutcomes(rows) {
181
+ function foldOutcomes(rows, triageRows = []) {
167
182
  const totals = { ...EMPTY_TOTALS };
168
183
  for (const row of rows) {
169
- const outcome = outcomeOf(row["status"], row["autoSendDecision"]);
184
+ const outcome = outcomeOf(row);
170
185
  if (outcome !== null) totals[outcome] += Number(row["count"]) || 0;
171
186
  }
187
+ for (const row of triageRows) {
188
+ if (isUnautomatedTriage(row)) totals.human += Number(row["count"]) || 0;
189
+ }
172
190
  return totals;
173
191
  }
174
192
  function settledCount(totals) {
@@ -178,15 +196,22 @@ function autonomyRate(totals) {
178
196
  const settled = settledCount(totals);
179
197
  return settled > 0 ? totals.auto / settled : Number.NaN;
180
198
  }
181
- function foldDailyOutcomes(rows) {
199
+ function foldDailyOutcomes(rows, triageRows = []) {
182
200
  const byDay = /* @__PURE__ */ new Map();
201
+ const totalsFor = (day) => {
202
+ const existing = byDay.get(day);
203
+ if (existing !== void 0) return existing;
204
+ const fresh = { ...EMPTY_TOTALS };
205
+ byDay.set(day, fresh);
206
+ return fresh;
207
+ };
183
208
  for (const row of rows) {
184
- const outcome = outcomeOf(row["status"], row["autoSendDecision"]);
209
+ const outcome = outcomeOf(row);
185
210
  if (outcome === null) continue;
186
- const day = bucketDay(row);
187
- const totals = byDay.get(day) ?? { ...EMPTY_TOTALS };
188
- totals[outcome] += Number(row["count"]) || 0;
189
- byDay.set(day, totals);
211
+ totalsFor(bucketDay(row))[outcome] += Number(row["count"]) || 0;
212
+ }
213
+ for (const row of triageRows) {
214
+ if (isUnautomatedTriage(row)) totalsFor(bucketDay(row)).human += Number(row["count"]) || 0;
190
215
  }
191
216
  return [...byDay.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([day, totals]) => ({
192
217
  day,
@@ -212,7 +237,7 @@ function ratePoints(rate, compareRate) {
212
237
  }
213
238
  var SIGNAL_MIN_VOLUME = 20;
214
239
  var SIGNAL_MIN_POINTS = 3;
215
- function dashboardSignals(totals, compare) {
240
+ function dashboardSignals(totals, compare, failed = 0) {
216
241
  const signals = [];
217
242
  const settled = settledCount(totals);
218
243
  const rate = autonomyRate(totals);
@@ -226,10 +251,10 @@ function dashboardSignals(totals, compare) {
226
251
  });
227
252
  }
228
253
  }
229
- if (totals.failed > 0) {
254
+ if (failed > 0) {
230
255
  signals.push({
231
256
  level: "creuser",
232
- text: `${totals.failed} g\xE9n\xE9ration${totals.failed > 1 ? "s ont" : " a"} \xE9chou\xE9 techniquement : ${totals.failed > 1 ? "ces demandes n\u2019ont" : "cette demande n\u2019a"} jamais eu de brouillon.`
257
+ text: `${failed} g\xE9n\xE9ration${failed > 1 ? "s ont" : " a"} \xE9chou\xE9 techniquement : ${failed > 1 ? "ces demandes n\u2019ont" : "cette demande n\u2019a"} jamais eu de brouillon et ${failed > 1 ? "sont retomb\xE9es" : "est retomb\xE9e"} sur un humain.`
233
258
  });
234
259
  }
235
260
  if (totals.inProgress > 0) {
@@ -252,15 +277,19 @@ function dashboardSignals(totals, compare) {
252
277
  }
253
278
  return signals;
254
279
  }
255
- function foldHumanReasons(rows) {
256
- const reasons = { blocked: 0, invalidated: 0, expired: 0 };
280
+ function foldHumanReasons(rows, triageRows = []) {
281
+ const reasons = { blocked: 0, invalidated: 0, expired: 0, escalatedNoDraft: 0, failed: 0 };
257
282
  for (const row of rows) {
258
- if (outcomeOf(row["status"], row["autoSendDecision"]) !== "human") continue;
283
+ if (outcomeOf(row) !== "human") continue;
259
284
  const count = Number(row["count"]) || 0;
260
285
  if (row["status"] === "invalidated") reasons.invalidated += count;
261
286
  else if (row["status"] === "expired") reasons.expired += count;
287
+ else if (row["status"] === "failed") reasons.failed += count;
262
288
  else reasons.blocked += count;
263
289
  }
290
+ for (const row of triageRows) {
291
+ if (isUnautomatedTriage(row)) reasons.escalatedNoDraft += Number(row["count"]) || 0;
292
+ }
264
293
  return reasons;
265
294
  }
266
295
  var CATEGORY_TOP_N = 10;
@@ -284,12 +313,15 @@ function foldCategoryOutcomes(triageRows, responseRows, categoryNames, topN = CA
284
313
  };
285
314
  for (const row of triageRows) {
286
315
  const bar = barFor(row["categoryId"]);
287
- if (bar !== null) bar.total += Number(row["count"]) || 0;
316
+ if (bar === null) continue;
317
+ const count = Number(row["count"]) || 0;
318
+ bar.total += count;
319
+ if (isUnautomatedTriage(row)) bar.human += count;
288
320
  }
289
321
  for (const row of responseRows) {
290
322
  const bar = barFor(row["categoryId"]);
291
323
  if (bar === null) continue;
292
- const outcome = outcomeOf(row["status"], row["autoSendDecision"]);
324
+ const outcome = outcomeOf(row);
293
325
  const count = Number(row["count"]) || 0;
294
326
  if (outcome === "auto") bar.auto += count;
295
327
  else if (outcome === "human") bar.human += count;
@@ -477,8 +509,10 @@ function StackedLegend({ segments }) {
477
509
  ] }, segment.key)) });
478
510
  }
479
511
  var OUTCOME_METRICS = [{ op: "count", as: "count" }];
480
- var OUTCOME_GROUP_BY = ["status", "autoSendDecision"];
481
- var CATEGORY_OUTCOME_GROUP_BY = ["categoryId", "status", "autoSendDecision"];
512
+ var OUTCOME_GROUP_BY = ["status", "autoSendDecision", "outcome"];
513
+ var CATEGORY_OUTCOME_GROUP_BY = ["categoryId", "status", "autoSendDecision", "outcome"];
514
+ var TRIAGE_HANDOFF_GROUP_BY = ["escalated", "status"];
515
+ var CATEGORY_TRIAGE_GROUP_BY = ["categoryId", "escalated", "status"];
482
516
  var CATEGORY_COLORS = {
483
517
  auto: "var(--chart-1)",
484
518
  human: "var(--chart-2)",
@@ -522,13 +556,27 @@ function DashboardPage() {
522
556
  groupBy: OUTCOME_GROUP_BY,
523
557
  metrics: OUTCOME_METRICS
524
558
  });
559
+ const { rows: dailyTriageRows, isLoading: triageLoading } = useAggregate("triage-decision", {
560
+ filter: { decidedAt: { gte: bounds.current.fromIso, lte: bounds.current.toIso } },
561
+ groupBy: TRIAGE_HANDOFF_GROUP_BY,
562
+ bucket: { field: "decidedAt", interval: bounds.interval, tz: timezone },
563
+ metrics: OUTCOME_METRICS
564
+ });
565
+ const { rows: previousTriageRows, isLoading: previousTriageLoading } = useAggregate(
566
+ "triage-decision",
567
+ {
568
+ filter: { decidedAt: { gte: previousBounds.fromIso, lte: previousBounds.toIso } },
569
+ groupBy: TRIAGE_HANDOFF_GROUP_BY,
570
+ metrics: OUTCOME_METRICS
571
+ }
572
+ );
525
573
  const {
526
574
  rows: categoryCounts,
527
575
  isLoading: categoryLoading,
528
576
  error: categoryError
529
577
  } = useAggregate("triage-decision", {
530
578
  filter: { decidedAt: { gte: bounds.current.fromIso, lte: bounds.current.toIso } },
531
- groupBy: ["categoryId"],
579
+ groupBy: CATEGORY_TRIAGE_GROUP_BY,
532
580
  metrics: OUTCOME_METRICS
533
581
  });
534
582
  const { rows: categoryOutcomes } = useAggregate("generated-response", {
@@ -538,26 +586,36 @@ function DashboardPage() {
538
586
  });
539
587
  const { rows: categories } = useRecordList("category", { limit: 500 }, toCategory);
540
588
  const categoryNames = useMemo(() => toNameMap(categories), [categories]);
541
- const totals = useMemo(() => foldOutcomes(dailyRows), [dailyRows]);
589
+ const totals = useMemo(
590
+ () => foldOutcomes(dailyRows, dailyTriageRows),
591
+ [dailyRows, dailyTriageRows]
592
+ );
542
593
  const compareTotals = useMemo(
543
- () => bounds.previous === null ? null : foldOutcomes(previousRows),
544
- [bounds.previous, previousRows]
594
+ () => bounds.previous === null ? null : foldOutcomes(previousRows, previousTriageRows),
595
+ [bounds.previous, previousRows, previousTriageRows]
545
596
  );
546
597
  const daily = useMemo(() => {
547
- const folded = foldDailyOutcomes(dailyRows);
598
+ const folded = foldDailyOutcomes(dailyRows, dailyTriageRows);
548
599
  return bounds.interval === "day" ? fillMissingDays(folded, bounds.current.fromIso, bounds.current.toIso) : folded;
549
- }, [dailyRows, bounds]);
600
+ }, [dailyRows, dailyTriageRows, bounds]);
550
601
  const rate = autonomyRate(totals);
551
602
  const compareRate = compareTotals === null ? Number.NaN : autonomyRate(compareTotals);
552
603
  const settled = settledCount(totals);
553
- const signals = useMemo(() => dashboardSignals(totals, compareTotals), [totals, compareTotals]);
554
- const reasons = useMemo(() => foldHumanReasons(dailyRows), [dailyRows]);
604
+ const failed = useMemo(() => countFailed(dailyRows), [dailyRows]);
605
+ const signals = useMemo(
606
+ () => dashboardSignals(totals, compareTotals, failed),
607
+ [totals, compareTotals, failed]
608
+ );
609
+ const reasons = useMemo(
610
+ () => foldHumanReasons(dailyRows, dailyTriageRows),
611
+ [dailyRows, dailyTriageRows]
612
+ );
555
613
  const categoryBars = useMemo(
556
614
  () => foldCategoryOutcomes(categoryCounts, categoryOutcomes, categoryNames),
557
615
  [categoryCounts, categoryOutcomes, categoryNames]
558
616
  );
559
617
  const categoryScale = categoryBars.reduce((max, bar) => Math.max(max, bar.total), 0);
560
- const loading = dailyLoading || previousLoading;
618
+ const loading = dailyLoading || previousLoading || triageLoading || previousTriageLoading;
561
619
  const chartData = daily.map((point) => ({ ...point, jour: dayLabel(point.day) }));
562
620
  const bucketWord = bounds.interval === "day" ? "jour" : "semaine";
563
621
  return /* @__PURE__ */ jsxs(PageShell, { children: [
@@ -740,6 +798,18 @@ function DashboardPage() {
740
798
  label: "Brouillon expir\xE9",
741
799
  value: reasons.expired,
742
800
  color: "var(--chart-5)"
801
+ },
802
+ {
803
+ key: "escalatedNoDraft",
804
+ label: "Escalad\xE9 sans brouillon",
805
+ value: reasons.escalatedNoDraft,
806
+ color: "var(--chart-4)"
807
+ },
808
+ {
809
+ key: "failed",
810
+ label: "\xC9chec technique",
811
+ value: reasons.failed,
812
+ color: "var(--destructive)"
743
813
  }
744
814
  ]
745
815
  }
@@ -762,16 +832,26 @@ function DashboardPage() {
762
832
  key: "expired",
763
833
  label: `Brouillon expir\xE9 (${formatCount(reasons.expired)})`,
764
834
  color: "var(--chart-5)"
835
+ },
836
+ {
837
+ key: "escalatedNoDraft",
838
+ label: `Escalad\xE9 sans brouillon (${formatCount(reasons.escalatedNoDraft)})`,
839
+ color: "var(--chart-4)"
840
+ },
841
+ {
842
+ key: "failed",
843
+ label: `\xC9chec technique (${formatCount(reasons.failed)})`,
844
+ color: "var(--destructive)"
765
845
  }
766
846
  ]
767
847
  }
768
848
  ),
769
- /* @__PURE__ */ jsx("p", { className: "text-xs leading-relaxed text-muted-foreground", children: "Les escalades sont dans \xAB\xA0bloqu\xE9\xA0\xBB : un ticket escalad\xE9 voit son brouillon retenu par le garde-fou, c\u2019est un motif de blocage et non un camp de plus. Le d\xE9tail ticket par ticket est sur la page Escalades." })
849
+ /* @__PURE__ */ jsx("p", { className: "text-xs leading-relaxed text-muted-foreground", children: "\xAB\xA0Bloqu\xE9\xA0\xBB veut dire qu\u2019un brouillon existe et qu\u2019on ne l\u2019a pas envoy\xE9 \u2014 chantier de prompt ou de garde-fou. \xAB\xA0Escalad\xE9 sans brouillon\xA0\xBB veut dire qu\u2019on n\u2019a m\xEAme pas essay\xE9 de r\xE9diger\xA0: le tri a pass\xE9 la main. Le d\xE9tail ticket par ticket est sur la page Escalades." })
770
850
  ] }) })
771
851
  ] }),
772
852
  /* @__PURE__ */ jsxs(Card, { children: [
773
853
  /* @__PURE__ */ jsx(CardHeader, { children: /* @__PURE__ */ jsx(CardTitle, { className: "text-sm", children: "Signaux \xE0 surveiller" }) }),
774
- /* @__PURE__ */ jsx(CardContent, { children: signals.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Rien de notable sur cette p\xE9riode \u2014 ou pas assez de demandes r\xE9gl\xE9es pour qu\u2019une comparaison veuille dire quelque chose." }) : /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-3", children: signals.map((signal) => /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3", children: [
854
+ /* @__PURE__ */ jsx(CardContent, { "data-testid": "dashboard-signals", children: loading ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Calcul en cours\u2026" }) : signals.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Rien de notable sur cette p\xE9riode \u2014 ou pas assez de demandes r\xE9gl\xE9es pour qu\u2019une comparaison veuille dire quelque chose." }) : /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-3", children: signals.map((signal) => /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3", children: [
775
855
  /* @__PURE__ */ jsx(Badge, { variant: signal.level === "creuser" ? "warning" : "neutral", children: signal.level === "creuser" ? "\xC0 creuser" : "Info" }),
776
856
  /* @__PURE__ */ jsx("span", { className: "text-sm leading-relaxed", children: signal.text })
777
857
  ] }, signal.text)) }) })
@@ -1042,7 +1122,8 @@ var GENERATED_RESPONSE_STATUS_LABELS = {
1042
1122
  no_reply_needed: "Aucune r\xE9ponse n\xE9cessaire",
1043
1123
  invalidated: "Invalid\xE9e",
1044
1124
  expired: "Expir\xE9e",
1045
- test_draft: "Brouillon d'essai \u2014 jamais envoy\xE9"
1125
+ test_draft: "Brouillon d'essai \u2014 jamais envoy\xE9",
1126
+ superseded: "Remplac\xE9e par une r\xE9ponse plus r\xE9cente"
1046
1127
  };
1047
1128
  var AUTO_SEND_DECISION_LABELS = {
1048
1129
  auto: "Autoris\xE9",
@@ -1340,6 +1421,8 @@ function deliveryReason(input) {
1340
1421
  }
1341
1422
  case "failed":
1342
1423
  return job.error ?? "La r\xE9ponse a \xE9chou\xE9 avant son envoi.";
1424
+ case "superseded":
1425
+ return "Le client a \xE9crit \xE0 nouveau avant l\u2019envoi : une r\xE9ponse plus r\xE9cente a remplac\xE9 celle-ci.";
1343
1426
  case "test_draft":
1344
1427
  return "Brouillon d'essai \u2014 jamais envoy\xE9.";
1345
1428
  default: