@apotech-os/support-kit 8.4.0 → 10.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, 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';
1
+ import { EVALUATION_VERDICTS, WHATSAPP_MODES, foldOutcomes, foldDailyOutcomes, fillMissingDays, autonomyRate, settledCount, countFailed, dashboardSignals, foldHumanReasons, foldCategoryOutcomes, toDeliveryPolicy, validateSettings, settingsWarnings, SUPPORT_CHANNELS, AGENT_GUARDRAILS, periodBoundsOf, toCategory, OUTCOME_METRICS, OUTCOME_GROUP_BY, TRIAGE_HANDOFF_GROUP_BY, CATEGORY_TRIAGE_GROUP_BY, CATEGORY_OUTCOME_GROUP_BY, ratePoints, toGeneratedResponse, toTriageDecision, toAgent, toResponseComparison, isGeneratedResponseStatus, isInvalidatableStatus, toCategoryGroup, followupIntegrationName, FOLLOWUP_WEBHOOK_TRIGGER, followupWebhookPath, FOLLOWUP_WEBHOOK_FORM, NODE_NAMES, settingsToProfile, hasNoDraftNode, buildTimelineSteps, outcomeTags, DEFAULT_LLM_PROVIDER, computeWordDiff, isSendableVerdict, COLLISION_GUARDRAILS, DEFAULT_MAX_TOOL_CALLS, DEFAULT_MIN_CONFIDENCE, DEFAULT_ESCALATION_ENABLED } from '../chunk-KEPXRZ7R.js';
2
2
  import { forwardRef, useState, useMemo, useRef, useCallback, useEffect, 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';
3
+ import { Textarea, cn, useAppContext, useAppSettings, DateRangeCompare, Link, Card, CardHeader, CardTitle, CardContent, AreaChart, StackedBarChart, Badge, useAppApi, useToast, Button, Select, DataTable, Spinner, Switch, Checkbox, Input, 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) {
@@ -143,212 +143,6 @@ function formatDate(iso) {
143
143
  function toNameMap(rows) {
144
144
  return new Map(rows.map((r) => [r.id, r.name]));
145
145
  }
146
-
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
- }
151
- function bucketDay(row) {
152
- return String(row["bucket"]).slice(0, 10);
153
- }
154
- var EMPTY_TOTALS = {
155
- auto: 0,
156
- human: 0,
157
- inProgress: 0,
158
- noReplyNeeded: 0
159
- };
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;
171
- if (status === "sent") return "auto";
172
- if (status === "no_reply_needed") return "noReplyNeeded";
173
- if (status === "failed") return "human";
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;
179
- return autoSendDecision === "hold" ? "human" : "inProgress";
180
- }
181
- function foldOutcomes(rows, triageRows = []) {
182
- const totals = { ...EMPTY_TOTALS };
183
- for (const row of rows) {
184
- const outcome = outcomeOf(row);
185
- if (outcome !== null) totals[outcome] += Number(row["count"]) || 0;
186
- }
187
- for (const row of triageRows) {
188
- if (isUnautomatedTriage(row)) totals.human += Number(row["count"]) || 0;
189
- }
190
- return totals;
191
- }
192
- function settledCount(totals) {
193
- return totals.auto + totals.human;
194
- }
195
- function autonomyRate(totals) {
196
- const settled = settledCount(totals);
197
- return settled > 0 ? totals.auto / settled : Number.NaN;
198
- }
199
- function foldDailyOutcomes(rows, triageRows = []) {
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
- };
208
- for (const row of rows) {
209
- const outcome = outcomeOf(row);
210
- if (outcome === null) continue;
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;
215
- }
216
- return [...byDay.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([day, totals]) => ({
217
- day,
218
- auto: totals.auto,
219
- human: totals.human,
220
- rate: settledCount(totals) > 0 ? autonomyRate(totals) : null
221
- }));
222
- }
223
- function fillMissingDays(series, fromIso, toIso) {
224
- const from = Date.parse(fromIso.slice(0, 10));
225
- const to = Date.parse(toIso.slice(0, 10));
226
- if (Number.isNaN(from) || Number.isNaN(to) || to < from) return series;
227
- const measured = new Map(series.map((point) => [point.day, point]));
228
- const filled = [];
229
- for (let t = from; t <= to; t += 864e5) {
230
- const day = new Date(t).toISOString().slice(0, 10);
231
- filled.push(measured.get(day) ?? { day, auto: 0, human: 0, rate: null });
232
- }
233
- return filled;
234
- }
235
- function ratePoints(rate, compareRate) {
236
- return Number.isNaN(rate) || Number.isNaN(compareRate) ? null : (rate - compareRate) * 100;
237
- }
238
- var SIGNAL_MIN_VOLUME = 20;
239
- var SIGNAL_MIN_POINTS = 3;
240
- function dashboardSignals(totals, compare, failed = 0) {
241
- const signals = [];
242
- const settled = settledCount(totals);
243
- const rate = autonomyRate(totals);
244
- if (compare !== null && settled >= SIGNAL_MIN_VOLUME && settledCount(compare) >= SIGNAL_MIN_VOLUME) {
245
- const points = ratePoints(rate, autonomyRate(compare));
246
- if (points !== null && Math.abs(points) >= SIGNAL_MIN_POINTS) {
247
- const move = points < 0 ? "recule" : "progresse";
248
- signals.push({
249
- level: points < 0 ? "creuser" : "info",
250
- text: `Le taux d\u2019autonomie ${move} de ${Math.abs(Math.round(points))} points par rapport \xE0 la p\xE9riode pr\xE9c\xE9dente.`
251
- });
252
- }
253
- }
254
- if (failed > 0) {
255
- signals.push({
256
- level: "creuser",
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.`
258
- });
259
- }
260
- if (totals.inProgress > 0) {
261
- signals.push({
262
- level: "info",
263
- text: `${totals.inProgress} r\xE9ponse${totals.inProgress > 1 ? "s sont" : " est"} encore en cours : ${totals.inProgress > 1 ? "elles ne comptent" : "elle ne compte"} dans aucun des deux camps.`
264
- });
265
- }
266
- if (totals.noReplyNeeded > 0) {
267
- signals.push({
268
- level: "info",
269
- text: `${totals.noReplyNeeded} demande${totals.noReplyNeeded > 1 ? "s" : ""} ne n\xE9cessitai${totals.noReplyNeeded > 1 ? "ent" : "t"} aucune r\xE9ponse : hors du taux d\u2019autonomie.`
270
- });
271
- }
272
- if (compare !== null && settled > 0 && settledCount(compare) < SIGNAL_MIN_VOLUME) {
273
- signals.push({
274
- level: "info",
275
- text: "La p\xE9riode pr\xE9c\xE9dente compte trop peu de demandes r\xE9gl\xE9es pour que la comparaison veuille dire quelque chose."
276
- });
277
- }
278
- return signals;
279
- }
280
- function foldHumanReasons(rows, triageRows = []) {
281
- const reasons = { blocked: 0, invalidated: 0, expired: 0, escalatedNoDraft: 0, failed: 0 };
282
- for (const row of rows) {
283
- if (outcomeOf(row) !== "human") continue;
284
- const count = Number(row["count"]) || 0;
285
- if (row["status"] === "invalidated") reasons.invalidated += count;
286
- else if (row["status"] === "expired") reasons.expired += count;
287
- else if (row["status"] === "failed") reasons.failed += count;
288
- else reasons.blocked += count;
289
- }
290
- for (const row of triageRows) {
291
- if (isUnautomatedTriage(row)) reasons.escalatedNoDraft += Number(row["count"]) || 0;
292
- }
293
- return reasons;
294
- }
295
- var CATEGORY_TOP_N = 10;
296
- function foldCategoryOutcomes(triageRows, responseRows, categoryNames, topN = CATEGORY_TOP_N) {
297
- const byId = /* @__PURE__ */ new Map();
298
- const barFor = (id) => {
299
- const name = typeof id === "string" ? categoryNames.get(id) : void 0;
300
- if (name === void 0) return null;
301
- const existing = byId.get(id);
302
- if (existing !== void 0) return existing;
303
- const bar = {
304
- label: name,
305
- total: 0,
306
- auto: 0,
307
- human: 0,
308
- noReply: 0,
309
- undrafted: 0
310
- };
311
- byId.set(id, bar);
312
- return bar;
313
- };
314
- for (const row of triageRows) {
315
- const bar = barFor(row["categoryId"]);
316
- if (bar === null) continue;
317
- const count = Number(row["count"]) || 0;
318
- bar.total += count;
319
- if (isUnautomatedTriage(row)) bar.human += count;
320
- }
321
- for (const row of responseRows) {
322
- const bar = barFor(row["categoryId"]);
323
- if (bar === null) continue;
324
- const outcome = outcomeOf(row);
325
- const count = Number(row["count"]) || 0;
326
- if (outcome === "auto") bar.auto += count;
327
- else if (outcome === "human") bar.human += count;
328
- else if (outcome === "noReplyNeeded") bar.noReply += count;
329
- }
330
- const bars = [...byId.values()].map((bar) => {
331
- const accounted = bar.auto + bar.human + bar.noReply;
332
- return {
333
- ...bar,
334
- total: Math.max(bar.total, accounted),
335
- undrafted: Math.max(0, bar.total - accounted)
336
- };
337
- }).filter((bar) => bar.total > 0).sort((a, b) => b.total - a.total);
338
- if (bars.length <= topN + 1) return bars;
339
- const tail = bars.slice(topN).reduce(
340
- (sum, bar) => ({
341
- label: "Autres",
342
- total: sum.total + bar.total,
343
- auto: sum.auto + bar.auto,
344
- human: sum.human + bar.human,
345
- noReply: sum.noReply + bar.noReply,
346
- undrafted: sum.undrafted + bar.undrafted
347
- }),
348
- { label: "Autres", total: 0, auto: 0, human: 0, noReply: 0, undrafted: 0 }
349
- );
350
- return [...bars.slice(0, topN), tail];
351
- }
352
146
  var POINTS_FORMAT = new Intl.NumberFormat("fr-FR", {
353
147
  maximumFractionDigits: 1,
354
148
  signDisplay: "exceptZero"
@@ -419,34 +213,12 @@ var DASHBOARD_PRESETS = [
419
213
  { key: "last7", label: "7 derniers jours" },
420
214
  { key: "last30", label: "30 derniers jours" }
421
215
  ];
422
- var WEEKLY_BUCKET_FROM_DAYS = 46;
423
- var DAY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
424
- var EPOCH_ISO = "1970-01-01T00:00:00.000Z";
425
- function startOfDayIso(day) {
426
- return day !== void 0 && DAY_PATTERN.test(day) ? `${day}T00:00:00.000Z` : EPOCH_ISO;
427
- }
428
- function endOfDayIso(day) {
429
- return DAY_PATTERN.test(day) ? `${day}T23:59:59.999Z` : (/* @__PURE__ */ new Date()).toISOString();
430
- }
431
- function dayCount(bounds) {
432
- const from = Date.parse(bounds.fromIso);
433
- const to = Date.parse(bounds.toIso);
434
- if (Number.isNaN(from) || Number.isNaN(to)) return 0;
435
- return Math.max(1, Math.round((to - from) / 864e5));
436
- }
437
- function periodBoundsOf(value) {
438
- const current = {
439
- fromIso: startOfDayIso(value.range.from),
440
- toIso: endOfDayIso(value.range.to)
441
- };
442
- const compare = value.compare === "none" ? void 0 : value.compareRange ?? comparisonRange(value.preset, value.range, value.compare);
443
- const days = dayCount(current);
444
- return {
445
- current,
446
- previous: compare === void 0 ? null : { fromIso: startOfDayIso(compare.from), toIso: endOfDayIso(compare.to) },
447
- days,
448
- interval: days >= WEEKLY_BUCKET_FROM_DAYS ? "week" : "day"
449
- };
216
+ function periodBoundsOf2(value) {
217
+ const compareRange = value.compare === "none" ? void 0 : value.compareRange ?? comparisonRange(value.preset, value.range, value.compare);
218
+ return periodBoundsOf({
219
+ range: value.range,
220
+ ...compareRange === void 0 ? {} : { compareRange }
221
+ });
450
222
  }
451
223
  function defaultPeriod(today = /* @__PURE__ */ new Date()) {
452
224
  const to = today.toISOString().slice(0, 10);
@@ -508,11 +280,6 @@ function StackedLegend({ segments }) {
508
280
  segment.label
509
281
  ] }, segment.key)) });
510
282
  }
511
- var OUTCOME_METRICS = [{ op: "count", as: "count" }];
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"];
516
283
  var CATEGORY_COLORS = {
517
284
  auto: "var(--chart-1)",
518
285
  human: "var(--chart-2)",
@@ -538,7 +305,7 @@ function DashboardPage() {
538
305
  const { settings } = useAppSettings();
539
306
  const timezone = settings?.statsTimezone ?? "UTC";
540
307
  const periodKey = JSON.stringify(period);
541
- const bounds = useMemo(() => periodBoundsOf(JSON.parse(periodKey)), [periodKey]);
308
+ const bounds = useMemo(() => periodBoundsOf2(JSON.parse(periodKey)), [periodKey]);
542
309
  const currentFilter = { generatedAt: { gte: bounds.current.fromIso, lte: bounds.current.toIso } };
543
310
  const previousBounds = bounds.previous ?? bounds.current;
544
311
  const {
@@ -873,6 +640,7 @@ function idempotencyKeyFor(operation, payload) {
873
640
  // src/ui/shared/settings-issue-labels.ts
874
641
  var SETTINGS_ISSUE_LABELS = {
875
642
  sourceViewId: "Vue Gorgias source requise \u2014 choisissez la vue que cette app poss\xE8de.",
643
+ appScopeTag: "Tag des tickets de l'application requis \u2014 c'est lui qui rattache un ticket \xE0 cette app.",
876
644
  nodes: "nodes.triage doit \xEAtre configur\xE9 \u2014 une \xE9tape de triage \xE0 null ne triagerait rien.",
877
645
  nodePrompt: "Chaque \xE9tape active doit d\xE9signer un prompt Langfuse \u2014 sans prompt, l'\xE9tape n'a rien \xE0 dire au mod\xE8le.",
878
646
  senderEmail: "Adresse d'envoi requise quand l'envoi automatique est actif (sauf en mode WhatsApp \xAB auto_reply \xBB)."
@@ -893,6 +661,7 @@ var EXACT_MESSAGE_LABELS = {
893
661
  };
894
662
  var SETTINGS_VALIDATION_MESSAGE_LABELS = {
895
663
  "sourceViewId is required \u2014 pick the Gorgias view this app owns.": SETTINGS_ISSUE_LABELS.sourceViewId,
664
+ "appScopeTag is required \u2014 set the tag that marks this app's tickets.": SETTINGS_ISSUE_LABELS.appScopeTag,
896
665
  "nodes.triage must be configured \u2014 a null triage step would triage nothing.": SETTINGS_ISSUE_LABELS.nodes,
897
666
  "senderEmail is required when autoSendEnabled is on, unless whatsappMode is 'auto_reply'.": SETTINGS_ISSUE_LABELS.senderEmail
898
667
  };
@@ -1258,28 +1027,6 @@ function responseOutcome(job) {
1258
1027
  return { label, variant: "neutral" };
1259
1028
  }
1260
1029
 
1261
- // src/ui/tickets/delivery-policy.ts
1262
- function evaluateNode(settings) {
1263
- const node = settings.nodes?.evaluate;
1264
- return node && typeof node === "object" ? node : null;
1265
- }
1266
- function toDeliveryPolicy(raw) {
1267
- if (!raw || typeof raw !== "object") return null;
1268
- const settings = raw;
1269
- const evaluate = evaluateNode(settings);
1270
- const senderEmail = typeof settings.senderEmail === "string" ? settings.senderEmail : "";
1271
- return {
1272
- followupSendable: typeof evaluate?.escalationEnabled === "boolean" ? evaluate.escalationEnabled : DEFAULT_ESCALATION_ENABLED,
1273
- minConfidence: typeof evaluate?.minConfidence === "number" ? evaluate.minConfidence : DEFAULT_MIN_CONFIDENCE,
1274
- evaluateConfigured: evaluate !== null,
1275
- autoSendEnabled: settings.autoSendEnabled === true,
1276
- senderEmail: senderEmail === "" ? null : senderEmail,
1277
- whatsappMode: typeof settings.whatsappMode === "string" ? settings.whatsappMode : null,
1278
- dryRun: settings.dryRun === true,
1279
- audit: toAuditTags(settings)
1280
- };
1281
- }
1282
-
1283
1030
  // src/ui/tickets/match.ts
1284
1031
  function tokensFor(row) {
1285
1032
  return row.diff ?? computeWordDiff(row.generatedText, row.sentText);
@@ -1333,24 +1080,113 @@ function WordDiffView({ title, tokens, keep, hideEqual = false }) {
1333
1080
 
1334
1081
  // src/ui/tickets/guardrail-labels.ts
1335
1082
  var NO_GUARDRAIL_REASON = "no_guardrail";
1336
- var GUARDRAIL_LABELS = {
1337
- whatsapp: "conversation WhatsApp",
1338
- whatsapp_stop: "le client a demand\xE9 \xE0 ne plus \xEAtre contact\xE9 (STOP)",
1339
- not_customer_turn: "le dernier message du fil est de nous",
1340
- judgeme: "avis Judge.me",
1341
- noreply_sender: "exp\xE9diteur automatique",
1342
- triage_not_high: "triage pas en confiance haute",
1343
- escalated: "ticket d\xE9j\xE0 escalad\xE9",
1344
- blocklist: "terme de la liste de blocage",
1345
- attachment: "pi\xE8ce jointe c\xF4t\xE9 client",
1346
- short_answer: "r\xE9ponse trop courte",
1347
- uncertainty_marker: "marqueur d\u2019incertitude dans la r\xE9ponse",
1348
- evaluation_missing: "aucune \xE9valuation produite"
1083
+ var GUARDRAIL_COPY = {
1084
+ whatsapp: {
1085
+ label: "conversation WhatsApp",
1086
+ explanation: "Le mode WhatsApp est r\xE9gl\xE9 sur \xAB escalade seule \xBB : sur ce canal la r\xE9ponse est r\xE9dig\xE9e puis confi\xE9e \xE0 un humain, jamais envoy\xE9e automatiquement."
1087
+ },
1088
+ whatsapp_stop: {
1089
+ label: "le client a demand\xE9 \xE0 ne plus \xEAtre contact\xE9 (STOP)",
1090
+ explanation: "Le client a \xE9crit \xAB STOP \xBB : il demande \xE0 ne plus \xEAtre contact\xE9. Rien ne part automatiquement, et le ticket est escalad\xE9 pour qu\u2019un humain acte la demande."
1091
+ },
1092
+ not_customer_turn: {
1093
+ label: "le dernier message du fil est de nous",
1094
+ explanation: "Le dernier message du fil vient de nous, pas du client : envoyer reviendrait \xE0 nous r\xE9pondre \xE0 nous-m\xEAmes."
1095
+ },
1096
+ judgeme: {
1097
+ label: "avis Judge.me",
1098
+ explanation: "Ce ticket est une notification d\u2019avis Judge.me, pas un message de client : il n\u2019appelle aucune r\xE9ponse automatique."
1099
+ },
1100
+ noreply_sender: {
1101
+ label: "exp\xE9diteur automatique",
1102
+ explanation: "L\u2019adresse de l\u2019exp\xE9diteur figure dans la liste des exp\xE9diteurs automatiques : la r\xE9ponse n\u2019atteindrait aucun humain."
1103
+ },
1104
+ triage_not_high: {
1105
+ label: "triage pas en confiance haute",
1106
+ explanation: "Le triage n\u2019a pas class\xE9 ce ticket avec une confiance haute, et les r\xE9glages exigent une confiance haute avant tout envoi automatique."
1107
+ },
1108
+ escalated: {
1109
+ label: "ticket d\xE9j\xE0 escalad\xE9",
1110
+ explanation: "Le ticket \xE9tait d\xE9j\xE0 escalad\xE9 vers un humain : l\u2019envoi automatique n\u2019a pas lieu d\u2019\xEAtre."
1111
+ },
1112
+ blocklist: {
1113
+ label: "terme de la liste de blocage",
1114
+ explanation: "Le premier message du client contient un terme de la liste de blocage : ces sujets passent obligatoirement par un humain."
1115
+ },
1116
+ attachment: {
1117
+ label: "pi\xE8ce jointe c\xF4t\xE9 client",
1118
+ explanation: "Le client a joint un ou plusieurs fichiers, que l\u2019agent ne sait pas lire : la r\xE9ponse part en revue humaine plut\xF4t que de r\xE9pondre \xE0 c\xF4t\xE9."
1119
+ },
1120
+ short_answer: {
1121
+ label: "r\xE9ponse trop courte",
1122
+ explanation: "Le brouillon fait moins de 20 caract\xE8res : trop court pour \xEAtre une vraie r\xE9ponse, il est retenu."
1123
+ },
1124
+ uncertainty_marker: {
1125
+ label: "marqueur d\u2019incertitude dans la r\xE9ponse",
1126
+ explanation: "Le brouillon contient une formule d\u2019incertitude (\xAB je ne suis pas s\xFBr \xBB, \xAB je ne peux pas \xBB\u2026) : une r\xE9ponse qui doute ne part pas seule."
1127
+ },
1128
+ evaluation_missing: {
1129
+ label: "aucune \xE9valuation produite",
1130
+ explanation: "Aucun verdict d\u2019\xE9valuation n\u2019a \xE9t\xE9 produit : sans jugement sur la r\xE9ponse, l\u2019envoi automatique est impossible."
1131
+ },
1132
+ customer_email_missing: {
1133
+ label: "client sans adresse e-mail",
1134
+ explanation: "Ce ticket n\u2019est pas un ticket WhatsApp, l\u2019envoi se ferait donc par e-mail \u2014 mais le client n\u2019a pas d\u2019adresse, ce qui est le cas des messages Instagram, Facebook ou SMS. Il n\u2019y a nulle part o\xF9 envoyer la r\xE9ponse."
1135
+ },
1136
+ ticket_closed: {
1137
+ label: "ticket ferm\xE9 entre-temps",
1138
+ explanation: "Le ticket a \xE9t\xE9 ferm\xE9 pendant que la r\xE9ponse se r\xE9digeait : l\u2019envoyer rouvrirait une conversation que quelqu\u2019un a close."
1139
+ },
1140
+ agent_replied: {
1141
+ label: "r\xE9ponse d\u2019un agent en cours de route",
1142
+ explanation: "Un agent a r\xE9pondu au client entre le lancement du run et l\u2019envoi : la r\xE9ponse automatique a \xE9t\xE9 annul\xE9e pour ne pas doubler la r\xE9ponse humaine."
1143
+ },
1144
+ diverged: {
1145
+ label: "la conversation a boug\xE9",
1146
+ explanation: "Le fil a chang\xE9 depuis la r\xE9daction \u2014 nouveau message, ou message modifi\xE9 : la r\xE9ponse pr\xE9par\xE9e ne correspond plus \xE0 ce que le client a \xE9crit."
1147
+ },
1148
+ run_deadline: {
1149
+ label: "d\xE9lai du run d\xE9pass\xE9",
1150
+ explanation: "Le run a d\xE9pass\xE9 son temps imparti avant de poster : la r\xE9ponse n\u2019est plus sous la responsabilit\xE9 de ce passage, elle n\u2019est pas envoy\xE9e."
1151
+ }
1349
1152
  };
1153
+ var NO_GUARDRAIL_COPY = {
1154
+ label: "bloqu\xE9e par le verdict ou le seuil, sans garde-fou",
1155
+ explanation: "Aucun garde-fou n\u2019a \xE9t\xE9 d\xE9clench\xE9 : c\u2019est le verdict du juge ou le seuil de confiance qui a retenu la r\xE9ponse."
1156
+ };
1157
+ function blockedTerm(hit) {
1158
+ return hit.startsWith("blocklist:") ? hit.slice("blocklist:".length) : null;
1159
+ }
1350
1160
  function guardrailHitLabel(hit) {
1351
- if (hit === NO_GUARDRAIL_REASON) return "bloqu\xE9e par le verdict ou le seuil, sans garde-fou";
1352
- if (hit.startsWith("blocklist:")) return `terme bloqu\xE9 \xAB ${hit.slice("blocklist:".length)} \xBB`;
1353
- return GUARDRAIL_LABELS[hit] ?? hit;
1161
+ if (hit === NO_GUARDRAIL_REASON) return NO_GUARDRAIL_COPY.label;
1162
+ const term = blockedTerm(hit);
1163
+ if (term !== null) return `terme bloqu\xE9 \xAB ${term} \xBB`;
1164
+ return GUARDRAIL_COPY[hit]?.label ?? hit;
1165
+ }
1166
+ function guardrailExplanation(hit) {
1167
+ if (hit === NO_GUARDRAIL_REASON) return NO_GUARDRAIL_COPY.explanation;
1168
+ const term = blockedTerm(hit);
1169
+ if (term !== null) {
1170
+ return `Le premier message du client contient \xAB ${term} \xBB, inscrit dans la liste de blocage : ces sujets passent obligatoirement par un humain.`;
1171
+ }
1172
+ return GUARDRAIL_COPY[hit]?.explanation ?? null;
1173
+ }
1174
+ var CHANNEL_LABELS = {
1175
+ email: "E-mail",
1176
+ whatsapp: "WhatsApp",
1177
+ chat: "Chat",
1178
+ phone: "T\xE9l\xE9phone",
1179
+ "contact-form": "Formulaire de contact",
1180
+ sms: "SMS",
1181
+ "instagram-direct-message": "Instagram (message priv\xE9)",
1182
+ "instagram-comment": "Instagram (commentaire)",
1183
+ "instagram-mention": "Instagram (mention)",
1184
+ "instagram-ad-comment": "Instagram (commentaire sous publicit\xE9)",
1185
+ facebook: "Facebook",
1186
+ "facebook-messenger": "Facebook Messenger"
1187
+ };
1188
+ function channelLabel(channel) {
1189
+ return CHANNEL_LABELS[channel] ?? channel;
1354
1190
  }
1355
1191
 
1356
1192
  // src/ui/tickets/timeline.ts
@@ -1364,152 +1200,116 @@ var TITLES = {
1364
1200
  correction: "Corrig\xE9 par un humain"
1365
1201
  };
1366
1202
  function buildTimeline(input) {
1367
- return [
1368
- step("received", receivedReason(input)),
1369
- step("prompt", promptReason(input)),
1370
- step("triage", triageReason(input)),
1371
- step("draft", draftReason(input)),
1372
- step("evaluation", evaluationReason(input)),
1373
- step("delivery", deliveryReason(input)),
1374
- step("correction", correctionReason(input))
1375
- ];
1376
- }
1377
- function step(key, reason2) {
1378
- return reason2 === null ? { key, title: TITLES[key], reached: true } : { key, title: TITLES[key], reached: false, reason: reason2 };
1379
- }
1380
- function receivedReason({ conversation, conversationLoading }) {
1381
- if (conversation) return null;
1382
- if (conversationLoading) return "Lecture de la conversation en cours\u2026";
1383
- return "Aucune conversation disponible : rien n'a \xE9t\xE9 captur\xE9 au moment du run, et le fil n'a pas pu \xEAtre relu chez Gorgias.";
1384
- }
1385
- function promptReason({ conversation, job, decision }) {
1386
- if (!job) return noResponseCause(decision);
1387
- if (conversation?.systemPrompt) return null;
1388
- return "Le prompt rendu n'a pas \xE9t\xE9 captur\xE9 sur cette r\xE9ponse \u2014 les r\xE9ponses \xE9crites avant cette capture n'en gardent que le nom et la version.";
1389
- }
1390
- function triageReason({ decision }) {
1391
- if (decision.status === "error" && !decision.tag) {
1392
- return decision.error ?? "Le triage a \xE9chou\xE9 sans produire de classification.";
1393
- }
1394
- return null;
1203
+ return buildTimelineSteps(input).map(
1204
+ (state) => state.reached ? { key: state.key, title: TITLES[state.key], reached: true } : {
1205
+ key: state.key,
1206
+ title: TITLES[state.key],
1207
+ reached: false,
1208
+ reason: describeReason(state.reason)
1209
+ }
1210
+ );
1395
1211
  }
1396
- function draftReason({ job, decision }) {
1397
- if (!job) return noResponseCause(decision);
1398
- if (job.responseText) return null;
1399
- if (job.status === "pending") return "La r\xE9daction n'a pas encore tourn\xE9.";
1400
- return job.error ?? "La r\xE9daction n'a produit aucun texte.";
1401
- }
1402
- function evaluationReason({ job, decision }) {
1403
- if (!job) return noResponseCause(decision);
1404
- if (job.verdict) return null;
1405
- if (job.status === "pending") return "L'\xE9valuation n'a pas encore tourn\xE9.";
1406
- return "Aucun verdict : l'\xE9valuation n'a pas \xE9t\xE9 atteinte.";
1407
- }
1408
- function deliveryReason(input) {
1409
- const { job, decision } = input;
1410
- if (!job) return noResponseCause(decision);
1411
- switch (job.status) {
1412
- case "sent":
1413
- return null;
1414
- case "pending":
1212
+ function describeReason(reason2) {
1213
+ switch (reason2.code) {
1214
+ case "conversation_loading":
1215
+ return "Lecture de la conversation en cours\u2026";
1216
+ case "conversation_unavailable":
1217
+ return "Aucune conversation disponible : rien n'a \xE9t\xE9 captur\xE9 au moment du run, et le fil n'a pas pu \xEAtre relu chez Gorgias.";
1218
+ case "ticket_escalated":
1219
+ return "Ticket escalad\xE9 \xE0 un humain \u2014 le graphe ne r\xE9dige pas.";
1220
+ case "conversation_over":
1221
+ return "Conversation consid\xE9r\xE9e close \u2014 rien \xE0 r\xE9pondre.";
1222
+ case "triage_error":
1223
+ return reason2.error ?? "Le triage a \xE9chou\xE9.";
1224
+ case "category_not_drafting":
1225
+ return "La cat\xE9gorie n'a pas la r\xE9ponse rapide activ\xE9e, ou n'a pas d'agent r\xE9dacteur.";
1226
+ case "triage_failed":
1227
+ return reason2.error ?? "Le triage a \xE9chou\xE9 sans produire de classification.";
1228
+ case "prompt_not_captured":
1229
+ return "Le prompt rendu n'a pas \xE9t\xE9 captur\xE9 sur cette r\xE9ponse \u2014 les r\xE9ponses \xE9crites avant cette capture n'en gardent que le nom et la version.";
1230
+ case "draft_pending":
1231
+ return "La r\xE9daction n'a pas encore tourn\xE9.";
1232
+ case "draft_empty":
1233
+ return reason2.error ?? "La r\xE9daction n'a produit aucun texte.";
1234
+ case "evaluation_pending":
1235
+ return "L'\xE9valuation n'a pas encore tourn\xE9.";
1236
+ case "evaluation_missing":
1237
+ return "Aucun verdict : l'\xE9valuation n'a pas \xE9t\xE9 atteinte.";
1238
+ case "reply_queued":
1415
1239
  return "La r\xE9ponse est encore en file.";
1416
- case "ready":
1417
- return notSentReason(input);
1418
- case "expired": {
1419
- const why = notSentReason(input);
1420
- return why === GENERIC_NOT_SENT ? "La r\xE9ponse a expir\xE9 avant son envoi." : `La r\xE9ponse a expir\xE9 avant son envoi. ${why}`;
1421
- }
1422
- case "failed":
1423
- return job.error ?? "La r\xE9ponse a \xE9chou\xE9 avant son envoi.";
1240
+ case "expired":
1241
+ return reason2.detail === null ? "La r\xE9ponse a expir\xE9 avant son envoi." : `La r\xE9ponse a expir\xE9 avant son envoi. ${describeNotSent(reason2.detail)}`;
1242
+ case "delivery_failed":
1243
+ return reason2.error ?? "La r\xE9ponse a \xE9chou\xE9 avant son envoi.";
1424
1244
  case "superseded":
1425
1245
  return "Le client a \xE9crit \xE0 nouveau avant l\u2019envoi : une r\xE9ponse plus r\xE9cente a remplac\xE9 celle-ci.";
1426
1246
  case "test_draft":
1427
1247
  return "Brouillon d'essai \u2014 jamais envoy\xE9.";
1248
+ case "unexpected_status":
1249
+ return `La r\xE9ponse n'a pas \xE9t\xE9 envoy\xE9e (statut : ${reason2.status}).`;
1250
+ case "no_correction":
1251
+ return "Aucune correction captur\xE9e : l'agent n'a pas r\xE9\xE9crit de r\xE9ponse sur ce ticket.";
1428
1252
  default:
1429
- return `La r\xE9ponse n'a pas \xE9t\xE9 envoy\xE9e (statut : ${job.status}).`;
1430
- }
1431
- }
1432
- var GENERIC_NOT_SENT = "R\xE9dig\xE9e, en attente d'un envoi.";
1433
- function notSentReason({ job, policy, category }) {
1434
- if (!job) return GENERIC_NOT_SENT;
1435
- if (job.autoSendDecision === "hold") {
1436
- return "Mise en attente d\xE9finitive : cette r\xE9ponse ne repartira pas toute seule (refus d\u2019approbation, contr\xF4le de derni\xE8re minute, ou envoi interrompu puis repris).";
1437
- }
1438
- switch (job.outcome) {
1439
- case "needs_human":
1440
- return notSendableReason(job, policy);
1441
- case "guardrail_hold":
1442
- return guardrailReason(job);
1253
+ return describeNotSent(reason2);
1254
+ }
1255
+ }
1256
+ function describeNotSent(reason2) {
1257
+ switch (reason2.code) {
1258
+ case "generic_not_sent":
1259
+ return "R\xE9dig\xE9e, en attente d'un envoi.";
1260
+ case "held_permanently":
1261
+ return "Mise en attente d\xE9finitive : cette r\xE9ponse ne repartira pas toute seule (refus d\u2019approbation, contr\xF4le de derni\xE8re minute, ou envoi interrompu puis repris).";
1262
+ case "guardrail_unrecorded":
1263
+ return "Un garde-fou a bloqu\xE9 l\u2019envoi (r\xE9ponse ant\xE9rieure \xE0 l\u2019enregistrement du motif).";
1264
+ case "guardrail":
1265
+ return describeGuardrail(reason2.hits, reason2.reconstructed);
1443
1266
  case "awaiting_approval":
1444
1267
  return "En attente d'une approbation humaine avant envoi.";
1445
- case "ready":
1446
- return notEligibleReason(job, policy, category);
1447
- case "sent":
1268
+ case "trial_mode":
1448
1269
  return "Mode essai : la r\xE9ponse aurait \xE9t\xE9 envoy\xE9e, mais rien n'a \xE9t\xE9 transmis au client.";
1449
- case null:
1450
- return legacyNotSentReason(job, policy, category);
1451
- default:
1452
- return GENERIC_NOT_SENT;
1453
- }
1454
- }
1455
- function notSendableReason(job, policy) {
1456
- const verdict = job.verdict;
1457
- if (!verdict) return "L'\xE9valuation n'a produit aucun verdict \u2014 par s\xE9curit\xE9, la r\xE9ponse part en revue humaine.";
1458
- if (verdict.status === "error") return "L'\xE9valuation a \xE9chou\xE9 \u2014 par s\xE9curit\xE9, la r\xE9ponse part en revue humaine.";
1459
- if (verdict.verdict === "hold") return "Le juge a retenu la r\xE9ponse (verdict \xAB Retenir \xBB) \u2014 elle demande une relecture.";
1460
- if (!policy) return "Le juge n'a pas autoris\xE9 l'envoi automatique.";
1461
- if ((verdict.confidence ?? 0) < policy.minConfidence) {
1462
- return `Confiance de ${asPercent(verdict.confidence ?? 0)} %, sous le seuil de ${asPercent(policy.minConfidence)} % fix\xE9 sur l'\xE9tape \xC9valuation.`;
1463
- }
1464
- if (requiresFollowup(verdict.verdict) && !policy.followupSendable) {
1465
- return "Le juge a valid\xE9 la r\xE9ponse mais demand\xE9 un suivi humain (verdict \xAB Envoyer et escalader \xBB). L'option \xAB Envoyer les r\xE9ponses qui demandent un suivi humain \xBB est d\xE9sactiv\xE9e sur l'\xE9tape \xC9valuation : la r\xE9ponse n'est donc pas envoy\xE9e.";
1466
- }
1467
- return "Le juge n'a pas autoris\xE9 l'envoi automatique.";
1468
- }
1469
- function notEligibleReason(job, policy, category) {
1470
- if (!policy) return GENERIC_NOT_SENT;
1471
- if (!policy.evaluateConfigured) {
1472
- return "L'\xE9tape \xC9valuation est coup\xE9e : sans verdict, l'envoi automatique est impossible.";
1473
- }
1474
- if (!policy.autoSendEnabled) return "L'envoi automatique est d\xE9sactiv\xE9 dans les r\xE9glages.";
1475
- if (category && !category.autoReplyEnabled) {
1476
- return `La cat\xE9gorie \xAB ${category.name} \xBB n'a pas l'auto-r\xE9ponse activ\xE9e.`;
1477
- }
1478
- const isWhatsapp = job.channel === "whatsapp";
1479
- if (isWhatsapp && policy.whatsappMode === "draft_only") {
1480
- return "Mode WhatsApp \xAB brouillon seul \xBB : la r\xE9ponse est r\xE9dig\xE9e, jamais envoy\xE9e automatiquement.";
1481
- }
1482
- if (!policy.senderEmail && !(isWhatsapp && policy.whatsappMode === "auto_reply")) {
1483
- return "Aucune adresse d'exp\xE9dition n'est configur\xE9e dans les r\xE9glages.";
1270
+ case "no_verdict":
1271
+ return "L'\xE9valuation n'a produit aucun verdict \u2014 par s\xE9curit\xE9, la r\xE9ponse part en revue humaine.";
1272
+ case "evaluation_failed":
1273
+ return "L'\xE9valuation a \xE9chou\xE9 \u2014 par s\xE9curit\xE9, la r\xE9ponse part en revue humaine.";
1274
+ case "judge_held":
1275
+ return "Le juge a retenu la r\xE9ponse (verdict \xAB Retenir \xBB) \u2014 elle demande une relecture.";
1276
+ case "judge_not_authorized":
1277
+ return "Le juge n'a pas autoris\xE9 l'envoi automatique.";
1278
+ case "below_confidence":
1279
+ return `Confiance de ${asPercent(reason2.confidence)} %, sous le seuil de ${asPercent(reason2.minConfidence)} % fix\xE9 sur l'\xE9tape \xC9valuation.`;
1280
+ case "followup_not_sendable":
1281
+ return "Le juge a valid\xE9 la r\xE9ponse mais demand\xE9 un suivi humain (verdict \xAB Envoyer et escalader \xBB). L'option \xAB Envoyer les r\xE9ponses qui demandent un suivi humain \xBB est d\xE9sactiv\xE9e sur l'\xE9tape \xC9valuation : la r\xE9ponse n'est donc pas envoy\xE9e.";
1282
+ case "legacy_followup_probable":
1283
+ return "Probablement : le juge a valid\xE9 la r\xE9ponse en demandant un suivi humain, et l'option \xAB Envoyer les r\xE9ponses qui demandent un suivi humain \xBB est d\xE9sactiv\xE9e sur l'\xE9tape \xC9valuation. (R\xE9ponse ant\xE9rieure \xE0 l'enregistrement des sorties de run \u2014 lecture faite avec les r\xE9glages actuels.)";
1284
+ case "evaluation_disabled":
1285
+ return "L'\xE9tape \xC9valuation est coup\xE9e : sans verdict, l'envoi automatique est impossible.";
1286
+ case "auto_send_disabled":
1287
+ return "L'envoi automatique est d\xE9sactiv\xE9 dans les r\xE9glages.";
1288
+ case "category_auto_reply_off":
1289
+ return `La cat\xE9gorie \xAB ${reason2.categoryName} \xBB n'a pas l'auto-r\xE9ponse activ\xE9e.`;
1290
+ case "whatsapp_draft_only":
1291
+ return "Mode WhatsApp \xAB brouillon seul \xBB : la r\xE9ponse est r\xE9dig\xE9e, jamais envoy\xE9e automatiquement.";
1292
+ case "no_publication_path": {
1293
+ const channel = reason2.channel ? ` ${channelLabel(reason2.channel)}` : "";
1294
+ return `Aucun moyen de publier une r\xE9ponse sur ce ticket : Gorgias ne d\xE9clare pas le canal${channel} r\xE9pondable, ou le contact n'a pas l'adresse que ce canal exige. Le brouillon reste disponible pour un agent.`;
1295
+ }
1296
+ case "channel_not_enabled":
1297
+ return `L'envoi automatique n'est pas activ\xE9 pour le canal ${channelLabel(reason2.channel ?? "")}. Le brouillon reste disponible pour un agent.`;
1298
+ case "no_sender_address":
1299
+ return "Aucune adresse d'exp\xE9dition n'est configur\xE9e dans les r\xE9glages.";
1484
1300
  }
1485
- return GENERIC_NOT_SENT;
1486
1301
  }
1487
- function guardrailReason(job) {
1488
- if (job.guardrailHits.length === 0) return "Un garde-fou a bloqu\xE9 l'envoi.";
1489
- return `Garde-fou d\xE9clench\xE9 : ${job.guardrailHits.map(guardrailHitLabel).join(", ")}.`;
1490
- }
1491
- function legacyNotSentReason(job, policy, category) {
1492
- if (job.guardrailHits.length > 0) return guardrailReason(job);
1493
- const verdict = job.verdict;
1494
- if (policy && verdict && verdict.status === "success" && requiresFollowup(verdict.verdict) && !policy.followupSendable) {
1495
- return "Probablement : le juge a valid\xE9 la r\xE9ponse en demandant un suivi humain, et l'option \xAB Envoyer les r\xE9ponses qui demandent un suivi humain \xBB est d\xE9sactiv\xE9e sur l'\xE9tape \xC9valuation. (R\xE9ponse ant\xE9rieure \xE0 l'enregistrement des sorties de run \u2014 lecture faite avec les r\xE9glages actuels.)";
1496
- }
1497
- if (verdict && (verdict.status === "error" || verdict.verdict === "hold")) return notSendableReason(job, policy);
1498
- return notEligibleReason(job, policy, category);
1302
+ function describeGuardrail(hits, reconstructed) {
1303
+ const [first = "", ...rest] = hits;
1304
+ const explanation = guardrailExplanation(first);
1305
+ const head = `Garde-fou d\xE9clench\xE9 : ${guardrailHitLabel(first)}.`;
1306
+ const others = rest.length > 0 ? ` \xC9galement d\xE9clench\xE9 : ${rest.map(guardrailHitLabel).join(", ")}.` : "";
1307
+ const caveat = reconstructed ? " (Motif reconstitu\xE9 a posteriori depuis Gorgias \u2014 lecture faite avec les r\xE9glages actuels.)" : "";
1308
+ return `${head}${explanation ? ` ${explanation}` : ""}${others}${caveat}`;
1499
1309
  }
1500
1310
  function asPercent(ratio) {
1501
1311
  return Math.round(ratio * 100);
1502
1312
  }
1503
- function correctionReason({ comparisons }) {
1504
- if (comparisons.length > 0) return null;
1505
- return "Aucune correction captur\xE9e : l'agent n'a pas r\xE9\xE9crit de r\xE9ponse sur ce ticket.";
1506
- }
1507
- function noResponseCause(decision) {
1508
- if (decision.escalated) return "Ticket escalad\xE9 \xE0 un humain \u2014 le graphe ne r\xE9dige pas.";
1509
- if (decision.conversationOver) return "Conversation consid\xE9r\xE9e close \u2014 rien \xE0 r\xE9pondre.";
1510
- if (decision.status === "error") return decision.error ?? "Le triage a \xE9chou\xE9.";
1511
- return "La cat\xE9gorie n'a pas la r\xE9ponse rapide activ\xE9e, ou n'a pas d'agent r\xE9dacteur.";
1512
- }
1513
1313
 
1514
1314
  // src/ui/tickets/ticket-actions.ts
1515
1315
  function dedupe(names) {
@@ -1533,7 +1333,7 @@ function wasSimulated(job, policy) {
1533
1333
  return policy?.dryRun === true;
1534
1334
  }
1535
1335
  function ticketActions(input) {
1536
- const { job, policy, notSentReason: notSentReason2 } = input;
1336
+ const { job, policy, notSentReason } = input;
1537
1337
  const simulated = wasSimulated(job, policy);
1538
1338
  const tags = dedupe([
1539
1339
  ...triageTagNames(input),
@@ -1544,7 +1344,7 @@ function ticketActions(input) {
1544
1344
  if (job?.status === "sent") {
1545
1345
  taken.push("R\xE9ponse envoy\xE9e au client.");
1546
1346
  } else if (job) {
1547
- skipped.push(`R\xE9ponse non envoy\xE9e \u2014 ${notSentReason2 ?? "raison inconnue."}`);
1347
+ skipped.push(`R\xE9ponse non envoy\xE9e \u2014 ${notSentReason ?? "raison inconnue."}`);
1548
1348
  }
1549
1349
  if (job?.outcome === "awaiting_approval" && !simulated) taken.push("Demande d'approbation cr\xE9\xE9e.");
1550
1350
  return { tags, taken, skipped, simulated, unrecorded: job !== void 0 && job.outcome === null };
@@ -1552,8 +1352,8 @@ function ticketActions(input) {
1552
1352
  function TimelinePanel(props) {
1553
1353
  const { decision, job, comparisons, conversation, conversationLoading, categoryName, policy, category, onClose, onInvalidate, isInvalidating, history, onSelectGeneration } = props;
1554
1354
  const steps = buildTimeline({ decision, job, comparisons, conversation, conversationLoading, policy, category });
1555
- const notSentReason2 = steps.find((step2) => step2.key === "delivery")?.reason ?? null;
1556
- const actions = ticketActions({ decision, job, policy, category, notSentReason: notSentReason2 });
1355
+ const notSentReason = steps.find((step) => step.key === "delivery")?.reason ?? null;
1356
+ const actions = ticketActions({ decision, job, policy, category, notSentReason });
1557
1357
  const canInvalidate = job !== void 0 && isGeneratedResponseStatus(job.status) && isInvalidatableStatus(job.status);
1558
1358
  return /* @__PURE__ */ jsx(SidePanel, { open: true, onClose, title: `Ticket ${decision.ticketId}`, description: categoryName, children: /* @__PURE__ */ jsxs("div", { className: "min-h-0 flex-1 space-y-1 overflow-y-auto text-sm", children: [
1559
1359
  /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3 pb-3", children: [
@@ -1561,7 +1361,7 @@ function TimelinePanel(props) {
1561
1361
  onInvalidate && canInvalidate && /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: onInvalidate, disabled: isInvalidating, children: isInvalidating ? "Invalidation\u2026" : "Invalider la r\xE9ponse" })
1562
1362
  ] }),
1563
1363
  history !== void 0 && history.length > 1 && /* @__PURE__ */ jsx(ThreadHistory, { history, selectedDecisionId: decision.id, onSelect: onSelectGeneration }),
1564
- steps.map((step2, index) => /* @__PURE__ */ jsx(StepBlock, { step: step2, index, last: index === steps.length - 1, children: step2.reached ? renderStep(step2.key, props) : null }, step2.key)),
1364
+ steps.map((step, index) => /* @__PURE__ */ jsx(StepBlock, { step, index, last: index === steps.length - 1, children: step.reached ? renderStep(step.key, props) : null }, step.key)),
1565
1365
  /* @__PURE__ */ jsx(ActionsBlock, { actions })
1566
1366
  ] }) });
1567
1367
  }
@@ -1596,7 +1396,7 @@ function ThreadHistory({
1596
1396
  ] });
1597
1397
  }
1598
1398
  function StepBlock({
1599
- step: step2,
1399
+ step,
1600
1400
  index,
1601
1401
  last,
1602
1402
  children
@@ -1606,16 +1406,16 @@ function StepBlock({
1606
1406
  /* @__PURE__ */ jsx(
1607
1407
  "span",
1608
1408
  {
1609
- className: `flex h-6 w-6 shrink-0 items-center justify-center rounded-full border text-xs font-semibold ${step2.reached ? "border-primary/30 bg-primary/10 text-primary" : "border-muted bg-muted text-muted-foreground"}`,
1409
+ className: `flex h-6 w-6 shrink-0 items-center justify-center rounded-full border text-xs font-semibold ${step.reached ? "border-primary/30 bg-primary/10 text-primary" : "border-muted bg-muted text-muted-foreground"}`,
1610
1410
  "aria-hidden": true,
1611
1411
  children: index + 1
1612
1412
  }
1613
1413
  ),
1614
1414
  !last && /* @__PURE__ */ jsx("span", { className: "w-px flex-1 bg-border", "aria-hidden": true })
1615
1415
  ] }),
1616
- /* @__PURE__ */ jsxs("div", { className: `min-w-0 flex-1 pb-5 ${step2.reached ? "" : "text-muted-foreground"}`, children: [
1617
- /* @__PURE__ */ jsx("p", { className: "text-xs font-semibold uppercase tracking-wider", children: step2.title }),
1618
- step2.reached ? /* @__PURE__ */ jsx("div", { className: "mt-2 space-y-2", children }) : /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs", children: step2.reason })
1416
+ /* @__PURE__ */ jsxs("div", { className: `min-w-0 flex-1 pb-5 ${step.reached ? "" : "text-muted-foreground"}`, children: [
1417
+ /* @__PURE__ */ jsx("p", { className: "text-xs font-semibold uppercase tracking-wider", children: step.title }),
1418
+ step.reached ? /* @__PURE__ */ jsx("div", { className: "mt-2 space-y-2", children }) : /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs", children: step.reason })
1619
1419
  ] })
1620
1420
  ] });
1621
1421
  }
@@ -1884,7 +1684,7 @@ function TicketsPage() {
1884
1684
  const history = useTicketHistory(detailDecision?.ticketId ?? null);
1885
1685
  const [triageInFlight] = useState(() => ({ current: false }));
1886
1686
  const periodKey = JSON.stringify(period);
1887
- const bounds = useMemo(() => periodBoundsOf(JSON.parse(periodKey)).current, [periodKey]);
1687
+ const bounds = useMemo(() => periodBoundsOf2(JSON.parse(periodKey)).current, [periodKey]);
1888
1688
  const decisionFilter = useMemo(() => {
1889
1689
  if (ticketSearch) return { ticketId: { eq: ticketSearch } };
1890
1690
  const filter = { decidedAt: { gte: bounds.fromIso, lte: bounds.toIso } };
@@ -2302,20 +2102,20 @@ var PIPELINE_STEPS = [
2302
2102
  }
2303
2103
  ];
2304
2104
  var TRIAGE_LOCK_REASON = "Sans triage l'app ne traite rien.";
2305
- var STEP_BY_KEY = new Map(PIPELINE_STEPS.map((step2) => [step2.key, step2]));
2105
+ var STEP_BY_KEY = new Map(PIPELINE_STEPS.map((step) => [step.key, step]));
2306
2106
  function pipelineStep(key) {
2307
- const step2 = STEP_BY_KEY.get(key);
2308
- if (!step2) throw new Error(`unknown pipeline step: ${key}`);
2309
- return step2;
2107
+ const step = STEP_BY_KEY.get(key);
2108
+ if (!step) throw new Error(`unknown pipeline step: ${key}`);
2109
+ return step;
2310
2110
  }
2311
2111
  function readNodes(value) {
2312
2112
  if (typeof value !== "object" || value === null || Array.isArray(value)) return {};
2313
2113
  return value;
2314
2114
  }
2315
2115
  function readStep(value, key) {
2316
- const step2 = readNodes(value)[key];
2317
- if (typeof step2 !== "object" || step2 === null || Array.isArray(step2)) return null;
2318
- return step2;
2116
+ const step = readNodes(value)[key];
2117
+ if (typeof step !== "object" || step === null || Array.isArray(step)) return null;
2118
+ return step;
2319
2119
  }
2320
2120
  function isStepEnabled(value, key) {
2321
2121
  return readStep(value, key) !== null;
@@ -2328,43 +2128,43 @@ function stepBlockedReason(value, key) {
2328
2128
  function isStepActive(value, key) {
2329
2129
  return isStepEnabled(value, key) && stepBlockedReason(value, key) === null;
2330
2130
  }
2331
- function withStep(value, key, step2) {
2332
- return { ...readNodes(value), [key]: step2 };
2131
+ function withStep(value, key, step) {
2132
+ return { ...readNodes(value), [key]: step };
2333
2133
  }
2334
2134
  function withStepFields(value, key, patch) {
2335
- const step2 = readStep(value, key);
2336
- if (!step2) return readNodes(value);
2337
- const next = { ...step2 };
2135
+ const step = readStep(value, key);
2136
+ if (!step) return readNodes(value);
2137
+ const next = { ...step };
2338
2138
  for (const [field2, fieldValue] of Object.entries(patch)) {
2339
2139
  if (fieldValue === void 0) delete next[field2];
2340
2140
  else next[field2] = fieldValue;
2341
2141
  }
2342
2142
  return withStep(value, key, next);
2343
2143
  }
2344
- function stepString(step2, field2) {
2345
- const value = step2?.[field2];
2144
+ function stepString(step, field2) {
2145
+ const value = step?.[field2];
2346
2146
  return typeof value === "string" ? value : "";
2347
2147
  }
2348
- function stepNumber(step2, field2, fallback) {
2349
- const value = step2?.[field2];
2148
+ function stepNumber(step, field2, fallback) {
2149
+ const value = step?.[field2];
2350
2150
  return typeof value === "number" && Number.isFinite(value) ? value : fallback;
2351
2151
  }
2352
- function stepBoolean(step2, field2, fallback) {
2353
- const value = step2?.[field2];
2152
+ function stepBoolean(step, field2, fallback) {
2153
+ const value = step?.[field2];
2354
2154
  return typeof value === "boolean" ? value : fallback;
2355
2155
  }
2356
2156
  function stepUsesAgentPrompt(key) {
2357
2157
  return key === "draft" || key === "revise";
2358
2158
  }
2359
2159
  var DEFAULT_PROMPT_LABEL = "production";
2360
- function stepPromptName(step2) {
2361
- return readPromptField(step2, "name");
2160
+ function stepPromptName(step) {
2161
+ return readPromptField(step, "name");
2362
2162
  }
2363
- function stepPromptLabel(step2) {
2364
- return readPromptField(step2, "label") || DEFAULT_PROMPT_LABEL;
2163
+ function stepPromptLabel(step) {
2164
+ return readPromptField(step, "label") || DEFAULT_PROMPT_LABEL;
2365
2165
  }
2366
- function readPromptField(step2, field2) {
2367
- const prompt = step2?.prompt;
2166
+ function readPromptField(step, field2) {
2167
+ const prompt = step?.prompt;
2368
2168
  if (typeof prompt !== "object" || prompt === null) return "";
2369
2169
  const value = prompt[field2];
2370
2170
  return typeof value === "string" ? value : "";
@@ -2372,8 +2172,8 @@ function readPromptField(step2, field2) {
2372
2172
  function promptPatch(name, label) {
2373
2173
  return { prompt: { name, label } };
2374
2174
  }
2375
- function stepReasoning(step2) {
2376
- const value = step2?.reasoning;
2175
+ function stepReasoning(step) {
2176
+ const value = step?.reasoning;
2377
2177
  return REASONING_EFFORTS.some((effort) => effort.value === value) ? value : "off";
2378
2178
  }
2379
2179
  var REASONING_EFFORTS = [
@@ -3896,9 +3696,9 @@ function PipelineNodesForm({
3896
3696
  let changed = false;
3897
3697
  const next = { ...prev };
3898
3698
  for (const key of PIPELINE_STEP_KEYS) {
3899
- const step2 = readStep(value, key);
3900
- if (step2 && JSON.stringify(step2) !== JSON.stringify(prev[key])) {
3901
- next[key] = step2;
3699
+ const step = readStep(value, key);
3700
+ if (step && JSON.stringify(step) !== JSON.stringify(prev[key])) {
3701
+ next[key] = step;
3902
3702
  changed = true;
3903
3703
  }
3904
3704
  }
@@ -3927,26 +3727,26 @@ function PipelineNodesForm({
3927
3727
  ) }, preset.id))
3928
3728
  ] }),
3929
3729
  /* @__PURE__ */ jsx("p", { className: "-mt-2 text-xs text-muted-foreground", children: "Un pr\xE9r\xE9glage remplit ce formulaire \u2014 il n'enregistre rien tant que vous n'avez pas cliqu\xE9 sur Enregistrer." }),
3930
- /* @__PURE__ */ jsx("div", { className: "divide-y rounded-md border", children: PIPELINE_STEPS.map((step2) => /* @__PURE__ */ jsx(
3730
+ /* @__PURE__ */ jsx("div", { className: "divide-y rounded-md border", children: PIPELINE_STEPS.map((step) => /* @__PURE__ */ jsx(
3931
3731
  StepRow,
3932
3732
  {
3933
- step: step2,
3733
+ step,
3934
3734
  value,
3935
3735
  canWrite,
3936
- issueMessage: step2.key === "triage" ? issueMessage : null,
3736
+ issueMessage: step.key === "triage" ? issueMessage : null,
3937
3737
  prompts,
3938
3738
  promptsLoading,
3939
3739
  models,
3940
3740
  modelsLoading,
3941
- onToggle: (on) => toggleStep(step2.key, on),
3942
- onPatch: (patch) => onChange(withStepFields(value, step2.key, patch))
3741
+ onToggle: (on) => toggleStep(step.key, on),
3742
+ onPatch: (patch) => onChange(withStepFields(value, step.key, patch))
3943
3743
  },
3944
- step2.key
3744
+ step.key
3945
3745
  )) })
3946
3746
  ] });
3947
3747
  }
3948
3748
  function StepRow({
3949
- step: step2,
3749
+ step,
3950
3750
  value,
3951
3751
  canWrite,
3952
3752
  issueMessage,
@@ -3957,15 +3757,15 @@ function StepRow({
3957
3757
  onToggle,
3958
3758
  onPatch
3959
3759
  }) {
3960
- const enabled = isStepEnabled(value, step2.key);
3961
- const blockedReason = stepBlockedReason(value, step2.key);
3760
+ const enabled = isStepEnabled(value, step.key);
3761
+ const blockedReason = stepBlockedReason(value, step.key);
3962
3762
  const promptFieldId = useId();
3963
- const triageLocked = step2.key === "triage" && enabled;
3763
+ const triageLocked = step.key === "triage" && enabled;
3964
3764
  const editable = canWrite && !blockedReason && !triageLocked;
3965
3765
  const toggle = /* @__PURE__ */ jsx(
3966
3766
  Switch,
3967
3767
  {
3968
- "aria-label": `${step2.label} \u2014 activer l'\xE9tape`,
3768
+ "aria-label": `${step.label} \u2014 activer l'\xE9tape`,
3969
3769
  checked: enabled,
3970
3770
  onCheckedChange: onToggle,
3971
3771
  disabled: !editable
@@ -3974,8 +3774,8 @@ function StepRow({
3974
3774
  return /* @__PURE__ */ jsxs("div", { className: blockedReason ? "space-y-2 p-4 opacity-60" : "space-y-2 p-4", children: [
3975
3775
  /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-3", children: [
3976
3776
  /* @__PURE__ */ jsxs("div", { children: [
3977
- /* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: step2.label }),
3978
- /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: step2.description })
3777
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: step.label }),
3778
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: step.description })
3979
3779
  ] }),
3980
3780
  /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-2 text-sm", children: [
3981
3781
  triageLocked ? /* @__PURE__ */ jsx(Tooltip, { label: TRIAGE_LOCK_REASON, children: toggle }) : toggle,
@@ -3990,8 +3790,8 @@ function StepRow({
3990
3790
  /* @__PURE__ */ jsx("div", { className: "rounded-md bg-muted/40 p-3", children: /* @__PURE__ */ jsx(
3991
3791
  StepPromptField,
3992
3792
  {
3993
- step: step2,
3994
- settings: readStep(value, step2.key),
3793
+ step,
3794
+ settings: readStep(value, step.key),
3995
3795
  disabled: !canWrite || blockedReason !== null,
3996
3796
  prompts,
3997
3797
  promptsLoading,
@@ -4004,8 +3804,8 @@ function StepRow({
4004
3804
  /* @__PURE__ */ jsx("div", { className: "mt-3 grid gap-4 rounded-md bg-muted/40 p-3 sm:grid-cols-2", children: /* @__PURE__ */ jsx(
4005
3805
  StepOptions,
4006
3806
  {
4007
- step: step2,
4008
- settings: readStep(value, step2.key),
3807
+ step,
3808
+ settings: readStep(value, step.key),
4009
3809
  disabled: !canWrite || blockedReason !== null,
4010
3810
  models,
4011
3811
  modelsLoading,
@@ -4016,7 +3816,7 @@ function StepRow({
4016
3816
  ] });
4017
3817
  }
4018
3818
  function StepOptions({
4019
- step: step2,
3819
+ step,
4020
3820
  settings,
4021
3821
  disabled,
4022
3822
  models,
@@ -4027,14 +3827,14 @@ function StepOptions({
4027
3827
  const known = models.includes(model);
4028
3828
  const [freeText, setFreeText] = useState(false);
4029
3829
  const showFreeText = freeText || model !== "" && !known && !modelsLoading;
4030
- const ids = useIds(step2.key);
3830
+ const ids = useIds(step.key);
4031
3831
  return /* @__PURE__ */ jsxs(Fragment, { children: [
4032
3832
  /* @__PURE__ */ jsxs("div", { children: [
4033
3833
  /* @__PURE__ */ jsx("label", { htmlFor: ids.model, className: "mb-1 block text-sm font-medium", children: "Mod\xE8le" }),
4034
3834
  /* @__PURE__ */ jsx(
4035
3835
  Select,
4036
3836
  {
4037
- "aria-label": `Mod\xE8le \u2014 ${step2.label}`,
3837
+ "aria-label": `Mod\xE8le \u2014 ${step.label}`,
4038
3838
  value: showFreeText ? CUSTOM_MODEL_VALUE : model,
4039
3839
  onValueChange: (next) => {
4040
3840
  if (next === CUSTOM_MODEL_VALUE) {
@@ -4064,7 +3864,7 @@ function StepOptions({
4064
3864
  Input,
4065
3865
  {
4066
3866
  id: ids.model,
4067
- "aria-label": `Identifiant de mod\xE8le \u2014 ${step2.label}`,
3867
+ "aria-label": `Identifiant de mod\xE8le \u2014 ${step.label}`,
4068
3868
  value: model,
4069
3869
  disabled,
4070
3870
  onChange: (e) => onPatch({ model: e.target.value })
@@ -4074,7 +3874,7 @@ function StepOptions({
4074
3874
  Input,
4075
3875
  {
4076
3876
  id: ids.provider,
4077
- "aria-label": `Fournisseur \u2014 ${step2.label}`,
3877
+ "aria-label": `Fournisseur \u2014 ${step.label}`,
4078
3878
  value: stepString(settings, "provider") || DEFAULT_LLM_PROVIDER,
4079
3879
  disabled,
4080
3880
  onChange: (e) => onPatch({ provider: e.target.value })
@@ -4088,7 +3888,7 @@ function StepOptions({
4088
3888
  /* @__PURE__ */ jsx(
4089
3889
  Select,
4090
3890
  {
4091
- "aria-label": `Effort de raisonnement \u2014 ${step2.label}`,
3891
+ "aria-label": `Effort de raisonnement \u2014 ${step.label}`,
4092
3892
  value: stepReasoning(settings),
4093
3893
  onValueChange: (next) => onPatch({ reasoning: next }),
4094
3894
  items: REASONING_EFFORTS.map((effort) => ({ value: effort.value, label: effort.label })),
@@ -4096,7 +3896,7 @@ function StepOptions({
4096
3896
  }
4097
3897
  )
4098
3898
  ] }),
4099
- step2.key === "draft" && /* @__PURE__ */ jsx(
3899
+ step.key === "draft" && /* @__PURE__ */ jsx(
4100
3900
  NumberField,
4101
3901
  {
4102
3902
  id: ids.maxToolCalls,
@@ -4109,7 +3909,7 @@ function StepOptions({
4109
3909
  hint: "Chaque consultation (commande, livraison\u2026) co\xFBte un appel suppl\xE9mentaire."
4110
3910
  }
4111
3911
  ),
4112
- step2.key === "evaluate" && /* @__PURE__ */ jsxs(Fragment, { children: [
3912
+ step.key === "evaluate" && /* @__PURE__ */ jsxs(Fragment, { children: [
4113
3913
  /* @__PURE__ */ jsx(
4114
3914
  NumberField,
4115
3915
  {
@@ -4136,7 +3936,7 @@ function StepOptions({
4136
3936
  ] });
4137
3937
  }
4138
3938
  function StepPromptField({
4139
- step: step2,
3939
+ step,
4140
3940
  settings,
4141
3941
  disabled,
4142
3942
  prompts,
@@ -4144,8 +3944,8 @@ function StepPromptField({
4144
3944
  id,
4145
3945
  onPatch
4146
3946
  }) {
4147
- if (stepUsesAgentPrompt(step2.key)) {
4148
- return /* @__PURE__ */ 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." });
3947
+ if (stepUsesAgentPrompt(step.key)) {
3948
+ return /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: step.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." });
4149
3949
  }
4150
3950
  const name = stepPromptName(settings);
4151
3951
  const label = stepPromptLabel(settings);
@@ -4159,7 +3959,7 @@ function StepPromptField({
4159
3959
  /* @__PURE__ */ jsx(
4160
3960
  Select,
4161
3961
  {
4162
- "aria-label": `Prompt \u2014 ${step2.label}`,
3962
+ "aria-label": `Prompt \u2014 ${step.label}`,
4163
3963
  value: name,
4164
3964
  onValueChange: (next) => onPatch(promptPatch(next, DEFAULT_PROMPT_LABEL)),
4165
3965
  items: [
@@ -4172,7 +3972,7 @@ function StepPromptField({
4172
3972
  /* @__PURE__ */ jsx(
4173
3973
  Select,
4174
3974
  {
4175
- "aria-label": `Version du prompt \u2014 ${step2.label}`,
3975
+ "aria-label": `Version du prompt \u2014 ${step.label}`,
4176
3976
  value: labels.includes(label) ? label : "",
4177
3977
  onValueChange: (next) => onPatch(promptPatch(name, next)),
4178
3978
  items: labels.map((entry) => ({ value: entry, label: entry })),
@@ -4302,33 +4102,12 @@ function SourceViewField({ views, value, onChange, disabled }) {
4302
4102
  }
4303
4103
  );
4304
4104
  }
4305
- function FollowupWebhookCard({ scopeTag, onScopeTagChange, canWrite }) {
4105
+ function FollowupWebhookCard() {
4306
4106
  const { appSlug } = useAppContext();
4307
- const scopeId = useId();
4308
4107
  return /* @__PURE__ */ jsx(Card, { id: "webhook-suite", children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-4 p-4", children: [
4309
4108
  /* @__PURE__ */ jsxs("div", { children: [
4310
4109
  /* @__PURE__ */ jsx("h2", { className: "font-medium", children: "R\xE9ponses aux messages suivants" }),
4311
- /* @__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)." })
4312
- ] }),
4313
- /* @__PURE__ */ jsxs("div", { children: [
4314
- /* @__PURE__ */ jsx("label", { htmlFor: scopeId, className: "mb-1 block text-sm font-medium", children: "Tag de p\xE9rim\xE8tre webhook" }),
4315
- /* @__PURE__ */ jsx(
4316
- Input,
4317
- {
4318
- id: scopeId,
4319
- value: scopeTag,
4320
- onChange: (e) => onScopeTagChange(e.target.value),
4321
- placeholder: "wai/triaged",
4322
- disabled: !canWrite
4323
- }
4324
- ),
4325
- /* @__PURE__ */ jsxs("p", { className: "mt-1 text-xs text-muted-foreground", children: [
4326
- "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. ",
4327
- /* @__PURE__ */ jsx("strong", { children: "Vide = aucun message suivant trait\xE9" }),
4328
- " (c'est aussi le kill-switch). Deux apps sur le m\xEAme compte Gorgias doivent y mettre des valeurs ",
4329
- /* @__PURE__ */ jsx("strong", { children: "distinctes" }),
4330
- ", sinon chacune r\xE9pondrait sur les tickets de l'autre."
4331
- ] })
4110
+ /* @__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). Seuls les tickets qui portent le tag des tickets de l'application sont concern\xE9s." })
4332
4111
  ] }),
4333
4112
  /* @__PURE__ */ jsxs("div", { className: "space-y-2 border-t pt-4", children: [
4334
4113
  /* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: "Int\xE9gration Gorgias (installation manuelle)" }),
@@ -4426,6 +4205,9 @@ function describeConnection(connections) {
4426
4205
  }
4427
4206
  return { text: `${fallback.label} (par d\xE9faut, parmi ${connections.length} connexions)`, tone: "normal" };
4428
4207
  }
4208
+ function SettingsWarnings({ warnings }) {
4209
+ return /* @__PURE__ */ jsx(Fragment, { children: warnings.map((warning) => /* @__PURE__ */ jsx("p", { className: "text-sm text-status-pending", children: warning.message }, warning.key)) });
4210
+ }
4429
4211
  function SettingsPage() {
4430
4212
  const { appSlug, role } = useAppContext();
4431
4213
  const canWrite = canWriteForRole(role);
@@ -4499,9 +4281,18 @@ function SettingsPage() {
4499
4281
  const claimUnverifiable = installedAppsUnavailable || uncheckedAppSlugs.length > 0;
4500
4282
  const issues = validateSettings(form);
4501
4283
  const warnings = settingsWarnings(form);
4284
+ const sendWarnings = warnings.filter((warning) => warning.key === "noAutoSendChannels");
4285
+ const tagWarnings = warnings.filter((warning) => warning.key !== "noAutoSendChannels");
4502
4286
  const nodesIssue = issues.find((issue) => issue.key === "nodes");
4503
4287
  const summaryIssues = issues.filter((issue) => issue !== nodesIssue);
4504
4288
  const guardrailsActive = Array.isArray(form.guardrailsActive) ? form.guardrailsActive : [];
4289
+ const autoSendChannels = Array.isArray(form.autoSendChannels) ? form.autoSendChannels : [];
4290
+ function toggleAutoSendChannel(channel, checked) {
4291
+ set(
4292
+ "autoSendChannels",
4293
+ checked ? [.../* @__PURE__ */ new Set([...autoSendChannels, channel])] : autoSendChannels.filter((c) => c !== channel)
4294
+ );
4295
+ }
4505
4296
  function toggleGuardrail(id, checked) {
4506
4297
  set(
4507
4298
  "guardrailsActive",
@@ -4627,6 +4418,20 @@ function SettingsPage() {
4627
4418
  ),
4628
4419
  "Envoi automatique"
4629
4420
  ] }),
4421
+ /* @__PURE__ */ jsxs("div", { children: [
4422
+ /* @__PURE__ */ jsx("p", { className: "mb-1 text-sm font-medium", children: "Canaux o\xF9 l'envoi automatique s'applique" }),
4423
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 gap-1", children: SUPPORT_CHANNELS.map((channel) => /* @__PURE__ */ jsx(
4424
+ Checkbox,
4425
+ {
4426
+ label: channelLabel(channel),
4427
+ checked: autoSendChannels.includes(channel),
4428
+ onCheckedChange: (checked) => toggleAutoSendChannel(channel, checked),
4429
+ disabled: !canWrite
4430
+ },
4431
+ channel
4432
+ )) }),
4433
+ /* @__PURE__ */ jsx(SettingsWarnings, { warnings: sendWarnings })
4434
+ ] }),
4630
4435
  /* @__PURE__ */ jsxs("div", { children: [
4631
4436
  /* @__PURE__ */ jsx("label", { htmlFor: "senderEmail", className: "mb-1 block text-sm font-medium", children: "Adresse d'envoi" }),
4632
4437
  /* @__PURE__ */ jsx(
@@ -4674,22 +4479,15 @@ function SettingsPage() {
4674
4479
  ["autoRepliedTag", "Tag r\xE9pondu automatiquement"],
4675
4480
  ["needsReviewTag", "Tag \xE0 revoir avant envoi"],
4676
4481
  ["followupTag", "Tag suivi requis"],
4677
- ["appScopeTag", "Tag d'appartenance"]
4482
+ ["appScopeTag", "Tag des tickets de l'application"]
4678
4483
  ].map(([key, label]) => /* @__PURE__ */ jsxs("div", { children: [
4679
4484
  /* @__PURE__ */ jsx("label", { htmlFor: key, className: "mb-1 block text-sm font-medium", children: label }),
4680
4485
  /* @__PURE__ */ jsx(Input, { id: key, value: field(form[key]), onChange: (e) => set(key, e.target.value), disabled: !canWrite })
4681
4486
  ] }, key)),
4682
- /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "Le tag d\u2019appartenance est pos\xE9 sur chaque ticket que le triage examine, dans le m\xEAme appel que les tags ci-dessus. Il doit \xEAtre propre \xE0 cette app : c\u2019est lui qui distingue ses tickets de ceux d\u2019une autre app install\xE9e sur le m\xEAme compte Gorgias." }),
4683
- warnings.map((warning) => /* @__PURE__ */ jsx("p", { className: "text-sm text-status-pending", children: warning.message }, warning.key))
4487
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "Le tag des tickets de l\u2019application est obligatoire. Il est pos\xE9 sur chaque ticket que le triage examine, et c\u2019est lui qui dit qu\u2019un ticket appartient \xE0 cette app : les r\xE9ponses aux messages suivants et l\u2019agent par d\xE9faut propos\xE9 dans l\u2019extension Gorgias s\u2019appuient dessus. Il doit \xEAtre propre \xE0 cette app, distinct de celui d\u2019une autre app install\xE9e sur le m\xEAme compte Gorgias." }),
4488
+ /* @__PURE__ */ jsx(SettingsWarnings, { warnings: tagWarnings })
4684
4489
  ] }) }),
4685
- /* @__PURE__ */ jsx(
4686
- FollowupWebhookCard,
4687
- {
4688
- scopeTag: field(form.webhookScopeTag),
4689
- onScopeTagChange: (value) => set("webhookScopeTag", value),
4690
- canWrite
4691
- }
4692
- ),
4490
+ /* @__PURE__ */ jsx(FollowupWebhookCard, {}),
4693
4491
  /* @__PURE__ */ jsx(Card, { id: "guardrails", children: /* @__PURE__ */ jsxs(CardContent, { className: "space-y-3 p-4", children: [
4694
4492
  /* @__PURE__ */ jsx("h2", { className: "font-medium", children: "Garde-fous" }),
4695
4493
  /* @__PURE__ */ jsxs("div", { children: [
@@ -6226,7 +6024,6 @@ function tagOrigin(tag, settings) {
6226
6024
  }
6227
6025
 
6228
6026
  // src/ui/test/verdict-summary.ts
6229
- var COLLISION_GUARDRAILS = ["ticket_closed", "agent_replied", "diverged", "customer_email_missing", "run_deadline"];
6230
6027
  function base(result) {
6231
6028
  return { label: outcomeLabel(result.outcome), collisionHits: [], contentHits: [] };
6232
6029
  }
@@ -6242,21 +6039,33 @@ function needsHumanSentence(result) {
6242
6039
  const confidencePct = verdict.confidence !== null ? `${Math.round(verdict.confidence * 100)} %` : "une confiance inconnue";
6243
6040
  return `Le juge a r\xE9pondu \xAB ${verdict.verdict} \xBB avec ${confidencePct} de confiance${verdict.reason ? ` : ${verdict.reason}` : "."}`;
6244
6041
  }
6042
+ function isCollisionHit(hit) {
6043
+ return COLLISION_GUARDRAILS.includes(hit);
6044
+ }
6245
6045
  function guardrailHoldSummary(result) {
6246
- const collisionHits = result.guardrailHits.filter((hit) => COLLISION_GUARDRAILS.includes(hit));
6247
- const contentHits = result.guardrailHits.filter((hit) => !COLLISION_GUARDRAILS.includes(hit));
6046
+ const collisionHits = result.guardrailHits.filter((hit) => isCollisionHit(hit));
6047
+ const contentHits = result.guardrailHits.filter((hit) => !isCollisionHit(hit));
6248
6048
  const sentence = collisionHits.length > 0 ? "Le contr\xF4le anti-collision, juste avant de poster, a bloqu\xE9 la r\xE9ponse : la conversation avait boug\xE9." : `${contentHits.length} garde-fou${contentHits.length > 1 ? "s" : ""} de contenu ${contentHits.length > 1 ? "ont" : "a"} bloqu\xE9 la r\xE9ponse avant l'envoi.`;
6249
6049
  return { sentence, collisionHits, contentHits };
6250
6050
  }
6251
- function readySentence(result) {
6051
+ function readySummary(result) {
6052
+ if (result.ineligibleReason === "no_publication_path") {
6053
+ return {
6054
+ tone: "warning",
6055
+ sentence: "La r\xE9ponse est pr\xEAte pour l'extension, mais rien ne permet de la publier : Gorgias ne d\xE9clare pas ce canal r\xE9pondable, ou le contact n'a pas l'adresse que ce canal exige."
6056
+ };
6057
+ }
6252
6058
  if (!result.verdict) {
6253
- return "La r\xE9ponse est pr\xEAte pour l'extension. L'envoi n'a pas \xE9t\xE9 tent\xE9 : sans \xE9valuation, aucun verdict n'a \xE9t\xE9 produit, et l'envoi auto est impossible par construction.";
6059
+ return {
6060
+ tone: "success",
6061
+ sentence: "La r\xE9ponse est pr\xEAte pour l'extension. L'envoi n'a pas \xE9t\xE9 tent\xE9 : sans \xE9valuation, aucun verdict n'a \xE9t\xE9 produit, et l'envoi auto est impossible par construction."
6062
+ };
6254
6063
  }
6255
- return "La r\xE9ponse est pr\xEAte pour l'extension. L'envoi automatique n'\xE9tait pas \xE9ligible.";
6064
+ return { tone: "success", sentence: "La r\xE9ponse est pr\xEAte pour l'extension. L'envoi automatique n'\xE9tait pas \xE9ligible." };
6256
6065
  }
6257
6066
  function describeVerdict(result) {
6258
6067
  if (result.error) {
6259
- const failing = result.steps.find((step2) => step2.error);
6068
+ const failing = result.steps.find((step) => step.error);
6260
6069
  return {
6261
6070
  label: "Erreur technique",
6262
6071
  tone: "danger",
@@ -6277,7 +6086,7 @@ function describeVerdict(result) {
6277
6086
  case "guardrail_hold":
6278
6087
  return { ...base(result), tone: "warning", ...guardrailHoldSummary(result) };
6279
6088
  case "ready":
6280
- return { ...base(result), tone: "success", sentence: readySentence(result) };
6089
+ return { ...base(result), ...readySummary(result) };
6281
6090
  case "escalated":
6282
6091
  return { ...base(result), tone: "warning", sentence: "Le n\u0153ud d'escalade a pass\xE9 la main \xE0 un humain \u2014 aucune r\xE9ponse n'a \xE9t\xE9 r\xE9dig\xE9e." };
6283
6092
  case "triaged_only":
@@ -6301,7 +6110,7 @@ function describeVerdict(result) {
6301
6110
  }
6302
6111
  }
6303
6112
  function totalDurationMs(result) {
6304
- return result.steps.reduce((total, step2) => total + step2.durationMs, 0);
6113
+ return result.steps.reduce((total, step) => total + step.durationMs, 0);
6305
6114
  }
6306
6115
  var VERDICT_BADGE_VARIANT = {
6307
6116
  success: "success",
@@ -6311,7 +6120,7 @@ var VERDICT_BADGE_VARIANT = {
6311
6120
  };
6312
6121
  function DryRunResultView({ result, langfuseConfig, knownTags, tagSettings }) {
6313
6122
  const verdict = describeVerdict(result);
6314
- const triageStep = result.steps.find((step2) => step2.node === "triage");
6123
+ const triageStep = result.steps.find((step) => step.node === "triage");
6315
6124
  const triageTag = triageStep?.patch.classification?.category;
6316
6125
  const isFallbackClassification = triageStep?.patch.classification?.isFallback === true;
6317
6126
  const unknownTag = Boolean(triageTag) && !isFallbackClassification && knownTags !== void 0 && !knownTags.includes(triageTag);
@@ -6345,18 +6154,18 @@ function DryRunResultView({ result, langfuseConfig, knownTags, tagSettings }) {
6345
6154
  ] }),
6346
6155
  /* @__PURE__ */ jsxs("div", { children: [
6347
6156
  /* @__PURE__ */ jsx("p", { className: "mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: "N\u0153uds ex\xE9cut\xE9s" }),
6348
- /* @__PURE__ */ jsx("ul", { className: "space-y-1", children: result.steps.map((step2, i) => /* @__PURE__ */ jsxs("li", { className: "flex items-center justify-between gap-3", children: [
6157
+ /* @__PURE__ */ jsx("ul", { className: "space-y-1", children: result.steps.map((step, i) => /* @__PURE__ */ jsxs("li", { className: "flex items-center justify-between gap-3", children: [
6349
6158
  /* @__PURE__ */ jsxs("span", { children: [
6350
- NODE_LABELS[step2.node],
6159
+ NODE_LABELS[step.node],
6351
6160
  " (",
6352
- step2.node,
6161
+ step.node,
6353
6162
  ")",
6354
- step2.node === "triage" && unknownTag && /* @__PURE__ */ jsx("span", { className: "ml-2 text-xs text-status-warning", children: "\u2014 ce tag ne correspond \xE0 aucune cat\xE9gorie configur\xE9e" })
6163
+ step.node === "triage" && unknownTag && /* @__PURE__ */ jsx("span", { className: "ml-2 text-xs text-status-warning", children: "\u2014 ce tag ne correspond \xE0 aucune cat\xE9gorie configur\xE9e" })
6355
6164
  ] }),
6356
6165
  /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2 text-xs text-muted-foreground", children: [
6357
- step2.durationMs,
6166
+ step.durationMs,
6358
6167
  " ms",
6359
- step2.error && /* @__PURE__ */ jsx(Badge, { variant: "danger", children: step2.error })
6168
+ step.error && /* @__PURE__ */ jsx(Badge, { variant: "danger", children: step.error })
6360
6169
  ] })
6361
6170
  ] }, i)) })
6362
6171
  ] }),
@@ -6513,7 +6322,7 @@ function FollowupWebhookCard2() {
6513
6322
  /* @__PURE__ */ jsxs(CardContent, { className: "space-y-3 p-4", children: [
6514
6323
  /* @__PURE__ */ jsxs("div", { children: [
6515
6324
  /* @__PURE__ */ jsx("h2", { className: "font-medium", children: "R\xE9ponses aux messages suivants" }),
6516
- /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "Rejoue sur un ticket r\xE9el ce que ferait le webhook Gorgias quand un client r\xE9pond sur un ticket d\xE9j\xE0 trait\xE9. Le tag de p\xE9rim\xE8tre et les cat\xE9gories se r\xE8glent dans Param\xE8tres." })
6325
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: "Rejoue sur un ticket r\xE9el ce que ferait le webhook Gorgias quand un client r\xE9pond sur un ticket d\xE9j\xE0 trait\xE9. Le tag des tickets de l\u2019application et les cat\xE9gories se r\xE8glent dans Param\xE8tres." })
6517
6326
  ] }),
6518
6327
  /* @__PURE__ */ jsxs("div", { className: "space-y-2 border-t pt-3", children: [
6519
6328
  /* @__PURE__ */ jsx("label", { htmlFor: ticketId, className: "block text-sm font-medium", children: "Ticket \xE0 tester" }),