@apotech-os/support-kit 8.1.0 → 8.2.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.cjs CHANGED
@@ -1197,7 +1197,8 @@ function LangfuseTraceLink({ traceId, observationId, config, label = "Voir la tr
1197
1197
  if (!traceId) {
1198
1198
  return observationId ? /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CopyButton, { value: observationId, label }) : null;
1199
1199
  }
1200
- if (!config?.baseUrl || !config?.projectId) return null;
1200
+ if (!config) return null;
1201
+ if (!config.baseUrl || !config.projectId) return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.CopyButton, { value: traceId, label });
1201
1202
  const origin = parseHttpOrigin(config.baseUrl);
1202
1203
  if (!origin) return null;
1203
1204
  const url = buildTraceUrl(origin, config.projectId, traceId, observationId);
@@ -1280,6 +1281,74 @@ function outcomeLabel(outcome) {
1280
1281
  return outcome ? OUTCOME_LABELS[outcome] : "\u2014";
1281
1282
  }
1282
1283
 
1284
+ // src/ui/tickets/generation-origin.ts
1285
+ var ORIGINS = {
1286
+ first: { kind: "first", label: "1re r\xE9ponse" },
1287
+ followup: { kind: "followup", label: "Message suivant" },
1288
+ test: { kind: "test", label: "Brouillon d'essai" }
1289
+ };
1290
+ function generationOrigin(decision, job) {
1291
+ if (job?.status === "test_draft") return ORIGINS.test;
1292
+ return decision.origin === "followup" ? ORIGINS.followup : ORIGINS.first;
1293
+ }
1294
+ var HISTORY_LIMIT = 100;
1295
+ function useTicketHistory(ticketId) {
1296
+ const { appSlug } = uiSdk.useAppContext();
1297
+ const api = uiSdk.useAppApi();
1298
+ const [entries, setEntries] = react.useState([]);
1299
+ const clientRef = react.useRef(api);
1300
+ clientRef.current = api;
1301
+ const requestIdRef = react.useRef(0);
1302
+ const loadedTicketIdRef = react.useRef(null);
1303
+ const load = react.useCallback(async () => {
1304
+ const requestId = ++requestIdRef.current;
1305
+ if (ticketId === null) {
1306
+ loadedTicketIdRef.current = null;
1307
+ setEntries([]);
1308
+ return;
1309
+ }
1310
+ if (loadedTicketIdRef.current !== ticketId) {
1311
+ loadedTicketIdRef.current = null;
1312
+ setEntries([]);
1313
+ }
1314
+ const byTicket = (sortField) => ({
1315
+ filter: JSON.stringify({ ticketId: { eq: ticketId } }),
1316
+ sort: JSON.stringify([{ field: sortField, direction: "asc" }]),
1317
+ limit: String(HISTORY_LIMIT)
1318
+ });
1319
+ try {
1320
+ const [decisionsPage, jobsPage] = await Promise.all([
1321
+ clientRef.current.get(`/data/apps/${appSlug}/records/triage-decision`, byTicket("decidedAt")),
1322
+ // No sort: these land in a Map keyed by the unique `triageDecisionId`,
1323
+ // so their order is irrelevant (and `generatedAt` is nullable anyway).
1324
+ clientRef.current.get(`/data/apps/${appSlug}/records/generated-response`, {
1325
+ filter: JSON.stringify({ ticketId: { eq: ticketId } }),
1326
+ limit: String(HISTORY_LIMIT)
1327
+ })
1328
+ ]);
1329
+ if (requestId !== requestIdRef.current) return;
1330
+ const jobByDecisionId = /* @__PURE__ */ new Map();
1331
+ for (const record of jobsPage.items) {
1332
+ const job = toGeneratedResponse(record);
1333
+ if (job.triageDecisionId) jobByDecisionId.set(job.triageDecisionId, job);
1334
+ }
1335
+ loadedTicketIdRef.current = ticketId;
1336
+ setEntries(
1337
+ decisionsPage.items.map((record) => toTriageDecision(record)).map((decision) => ({ decision, job: jobByDecisionId.get(decision.id) }))
1338
+ );
1339
+ } catch {
1340
+ if (requestId === requestIdRef.current) setEntries([]);
1341
+ }
1342
+ }, [ticketId, appSlug]);
1343
+ react.useEffect(() => {
1344
+ void load();
1345
+ return () => {
1346
+ requestIdRef.current += 1;
1347
+ };
1348
+ }, [load]);
1349
+ return { entries, refresh: load };
1350
+ }
1351
+
1283
1352
  // src/status/machine.ts
1284
1353
  var GENERATED_RESPONSE_STATUSES = [
1285
1354
  "pending",
@@ -1903,7 +1972,7 @@ function ticketActions(input) {
1903
1972
  return { tags, taken, skipped, simulated, unrecorded: job !== void 0 && job.outcome === null };
1904
1973
  }
1905
1974
  function TimelinePanel(props) {
1906
- const { decision, job, comparisons, conversation, conversationLoading, categoryName, policy, category, onClose, onInvalidate, isInvalidating } = props;
1975
+ const { decision, job, comparisons, conversation, conversationLoading, categoryName, policy, category, onClose, onInvalidate, isInvalidating, history, onSelectGeneration } = props;
1907
1976
  const steps = buildTimeline({ decision, job, comparisons, conversation, conversationLoading, policy, category });
1908
1977
  const notSentReason2 = steps.find((step2) => step2.key === "delivery")?.reason ?? null;
1909
1978
  const actions = ticketActions({ decision, job, policy, category, notSentReason: notSentReason2 });
@@ -1913,10 +1982,41 @@ function TimelinePanel(props) {
1913
1982
  /* @__PURE__ */ jsxRuntime.jsx(TicketLink, { ticketId: decision.ticketId, url: decision.ticketUrl, label: "Ouvrir le ticket dans Gorgias" }),
1914
1983
  onInvalidate && canInvalidate && /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Button, { variant: "outline", size: "sm", onClick: onInvalidate, disabled: isInvalidating, children: isInvalidating ? "Invalidation\u2026" : "Invalider la r\xE9ponse" })
1915
1984
  ] }),
1985
+ history !== void 0 && history.length > 1 && /* @__PURE__ */ jsxRuntime.jsx(ThreadHistory, { history, selectedDecisionId: decision.id, onSelect: onSelectGeneration }),
1916
1986
  steps.map((step2, index) => /* @__PURE__ */ jsxRuntime.jsx(StepBlock, { step: step2, index, last: index === steps.length - 1, children: step2.reached ? renderStep(step2.key, props) : null }, step2.key)),
1917
1987
  /* @__PURE__ */ jsxRuntime.jsx(ActionsBlock, { actions })
1918
1988
  ] }) });
1919
1989
  }
1990
+ function ThreadHistory({
1991
+ history,
1992
+ selectedDecisionId,
1993
+ onSelect
1994
+ }) {
1995
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-1 border-b pb-3", children: [
1996
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs font-medium", children: "Historique du fil" }),
1997
+ /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "space-y-1", children: history.map(({ decision, job }) => {
1998
+ const selected = decision.id === selectedDecisionId;
1999
+ const origin = generationOrigin(decision, job);
2000
+ const outcome = responseOutcome(job);
2001
+ return /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsxs(
2002
+ "button",
2003
+ {
2004
+ type: "button",
2005
+ onClick: onSelect ? () => onSelect(decision) : void 0,
2006
+ "aria-current": selected || void 0,
2007
+ className: `flex w-full items-center justify-between gap-2 rounded border px-2 py-1 text-left text-xs ${selected ? "border-primary/40 bg-primary/5" : "border-border hover:bg-muted/40"}`,
2008
+ children: [
2009
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-2", children: [
2010
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: formatDate(decision.decidedAt) }),
2011
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium", children: origin.label })
2012
+ ] }),
2013
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: outcome.variant, children: outcome.label })
2014
+ ]
2015
+ }
2016
+ ) }, decision.id);
2017
+ }) })
2018
+ ] });
2019
+ }
1920
2020
  function StepBlock({
1921
2021
  step: step2,
1922
2022
  index,
@@ -2157,6 +2257,12 @@ var CORRECTED_OPTIONS = [
2157
2257
  { value: "true", label: "Corrig\xE9s par un humain" },
2158
2258
  { value: "false", label: "Non corrig\xE9s" }
2159
2259
  ];
2260
+ var ORIGIN_FILTER_OPTIONS = [
2261
+ { value: "", label: "Toutes origines" },
2262
+ { value: "first", label: "1res r\xE9ponses" },
2263
+ { value: "followup", label: "Messages suivants" },
2264
+ { value: "test", label: "Brouillons d'essai" }
2265
+ ];
2160
2266
  function OutcomeBadge({ outcome }) {
2161
2267
  return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: OUTCOME_BADGE_VARIANT[outcome.variant], children: outcome.label });
2162
2268
  }
@@ -2175,19 +2281,35 @@ function TicketsPage() {
2175
2281
  const [verdictFilter, setVerdictFilter] = react.useState("");
2176
2282
  const [promptVersionFilter, setPromptVersionFilter] = react.useState("");
2177
2283
  const [correctedFilter, setCorrectedFilter] = react.useState("");
2284
+ const [originFilter, setOriginFilter] = react.useState("");
2178
2285
  const [detailDecision, setDetailDecision] = react.useState(null);
2179
2286
  const [isTriaging, setIsTriaging] = react.useState(false);
2180
2287
  const [isInvalidating, setIsInvalidating] = react.useState(false);
2288
+ const requestedTicket = useQueryParam("ticket").value;
2289
+ const [ticketSearch, setTicketSearch] = react.useState(() => requestedTicket?.trim() ?? "");
2290
+ const searchDebounce = react.useRef(null);
2291
+ const onTableStateChange = react.useCallback((tableState) => {
2292
+ if (searchDebounce.current) clearTimeout(searchDebounce.current);
2293
+ searchDebounce.current = setTimeout(() => setTicketSearch(tableState.search.trim()), 300);
2294
+ }, []);
2295
+ react.useEffect(
2296
+ () => () => {
2297
+ if (searchDebounce.current) clearTimeout(searchDebounce.current);
2298
+ },
2299
+ []
2300
+ );
2301
+ const history = useTicketHistory(detailDecision?.ticketId ?? null);
2181
2302
  const [triageInFlight] = react.useState(() => ({ current: false }));
2182
2303
  const periodKey = JSON.stringify(period);
2183
2304
  const bounds = react.useMemo(() => periodBoundsOf(JSON.parse(periodKey)).current, [periodKey]);
2184
2305
  const decisionFilter = react.useMemo(() => {
2306
+ if (ticketSearch) return { ticketId: { eq: ticketSearch } };
2185
2307
  const filter = { decidedAt: { gte: bounds.fromIso, lte: bounds.toIso } };
2186
2308
  if (categoryFilter) filter.categoryId = { eq: categoryFilter };
2187
2309
  if (escalatedFilter) filter.escalated = { eq: escalatedFilter === "true" };
2188
2310
  if (confidenceFilter) filter.confidence = { eq: confidenceFilter };
2189
2311
  return filter;
2190
- }, [bounds.fromIso, bounds.toIso, categoryFilter, escalatedFilter, confidenceFilter]);
2312
+ }, [ticketSearch, bounds.fromIso, bounds.toIso, categoryFilter, escalatedFilter, confidenceFilter]);
2191
2313
  const {
2192
2314
  rows: decisions,
2193
2315
  isLoading: decisionsLoading,
@@ -2240,7 +2362,7 @@ function TicketsPage() {
2240
2362
  const agentNames = react.useMemo(() => toNameMap(agents), [agents]);
2241
2363
  const { config: langfuseConfig } = useLangfuseConfig();
2242
2364
  function refreshAll() {
2243
- return Promise.all([refreshDecisions(), refreshJobs(), refreshComparisons()]).then(() => void 0);
2365
+ return Promise.all([refreshDecisions(), refreshJobs(), refreshComparisons(), history.refresh()]).then(() => void 0);
2244
2366
  }
2245
2367
  const jobByDecisionId = react.useMemo(() => {
2246
2368
  const map = /* @__PURE__ */ new Map();
@@ -2287,10 +2409,10 @@ function TicketsPage() {
2287
2409
  if (promptVersionFilter && String(row.job?.promptVersion ?? "") !== promptVersionFilter) return false;
2288
2410
  if (correctedFilter === "true" && row.comparisons.length === 0) return false;
2289
2411
  if (correctedFilter === "false" && row.comparisons.length > 0) return false;
2412
+ if (originFilter && generationOrigin(row.decision, row.job).kind !== originFilter) return false;
2290
2413
  return true;
2291
2414
  });
2292
- }, [decisions, jobByDecisionId, comparisonsByTicketId, outcomeFilter, verdictFilter, promptVersionFilter, correctedFilter]);
2293
- const requestedTicket = useQueryParam("ticket").value;
2415
+ }, [decisions, jobByDecisionId, comparisonsByTicketId, outcomeFilter, verdictFilter, promptVersionFilter, correctedFilter, originFilter]);
2294
2416
  const deepLinkConsumed = react.useRef(false);
2295
2417
  react.useEffect(() => {
2296
2418
  if (deepLinkConsumed.current || !requestedTicket) return;
@@ -2338,6 +2460,15 @@ function TicketsPage() {
2338
2460
  }
2339
2461
  const columns = [
2340
2462
  { key: "ticketId", header: "Ticket", cell: ({ decision }) => /* @__PURE__ */ jsxRuntime.jsx(TicketLink, { ticketId: decision.ticketId, url: decision.ticketUrl }) },
2463
+ {
2464
+ key: "origin",
2465
+ header: "Origine",
2466
+ cell: ({ decision, job }) => {
2467
+ const origin = generationOrigin(decision, job);
2468
+ if (origin.kind === "first") return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: origin.label });
2469
+ return /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Badge, { variant: origin.kind === "test" ? "warning" : "info", children: origin.label });
2470
+ }
2471
+ },
2341
2472
  { key: "category", header: "Cat\xE9gorie", cell: ({ decision }) => decision.categoryId && categoryNames.get(decision.categoryId) || "\u2014" },
2342
2473
  { key: "tag", header: "Tag", cell: ({ decision }) => decision.tag ? /* @__PURE__ */ jsxRuntime.jsx("code", { className: "text-xs", children: decision.tag }) : "\u2014" },
2343
2474
  {
@@ -2394,7 +2525,12 @@ function TicketsPage() {
2394
2525
  },
2395
2526
  { key: "decidedAt", header: "D\xE9cid\xE9 le", cell: ({ decision }) => formatDate(decision.decidedAt) }
2396
2527
  ];
2397
- const detailRow = detailDecision ? rows.find((row) => row.decision.id === detailDecision.id) : void 0;
2528
+ const historyEntry = detailDecision ? history.entries.find((entry) => entry.decision.id === detailDecision.id) : void 0;
2529
+ const pageRow = detailDecision ? rows.find((row) => row.decision.id === detailDecision.id) : void 0;
2530
+ const detailRow = detailDecision ? {
2531
+ job: historyEntry?.job ?? pageRow?.job,
2532
+ comparisons: comparisonsByTicketId.get(detailDecision.ticketId) ?? []
2533
+ } : void 0;
2398
2534
  const liveConversation = useLiveConversation(detailDecision, detailRow);
2399
2535
  const isLoading = decisionsLoading || jobsLoading;
2400
2536
  const combinedError = decisionsError ?? jobsError ?? comparisonsError;
@@ -2428,6 +2564,7 @@ function TicketsPage() {
2428
2564
  /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Select, { items: VERDICT_OPTIONS, value: verdictFilter, onValueChange: setVerdictFilter, placeholder: "Tous les verdicts", "aria-label": "Filtrer par verdict" }),
2429
2565
  /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Select, { items: promptVersionOptions, value: promptVersionFilter, onValueChange: setPromptVersionFilter, placeholder: "Toutes versions de prompt", "aria-label": "Filtrer par version de prompt" }),
2430
2566
  /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Select, { items: CORRECTED_OPTIONS, value: correctedFilter, onValueChange: setCorrectedFilter, placeholder: "Corrig\xE9s ou non", "aria-label": "Filtrer par correction humaine" }),
2567
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Select, { items: ORIGIN_FILTER_OPTIONS, value: originFilter, onValueChange: setOriginFilter, placeholder: "Toutes origines", "aria-label": "Filtrer par origine" }),
2431
2568
  rows.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "ml-auto text-sm text-muted-foreground", children: [
2432
2569
  rows.length,
2433
2570
  " ticket",
@@ -2442,6 +2579,9 @@ function TicketsPage() {
2442
2579
  rows,
2443
2580
  rowId: (row) => row.decision.id,
2444
2581
  manual: true,
2582
+ defaultState: { search: requestedTicket?.trim() ?? "" },
2583
+ onStateChange: onTableStateChange,
2584
+ searchPlaceholder: "ID de ticket\u2026",
2445
2585
  loading: isLoading,
2446
2586
  onRowClick: (row) => setDetailDecision(row.decision),
2447
2587
  pagination: {
@@ -2474,6 +2614,8 @@ function TicketsPage() {
2474
2614
  category: categories.find((entry) => entry.id === detailDecision.categoryId) ?? null,
2475
2615
  agentName: detailRow?.job?.agentId && agentNames.get(detailRow.job.agentId) || "\u2014",
2476
2616
  langfuseConfig,
2617
+ history: history.entries,
2618
+ onSelectGeneration: (selected) => setDetailDecision(selected),
2477
2619
  onClose: () => setDetailDecision(null),
2478
2620
  onInvalidate: canWrite && detailRow?.job ? () => void invalidateResponse(detailRow.job.id) : void 0,
2479
2621
  isInvalidating
@@ -6769,7 +6911,8 @@ function parseRunResult(result) {
6769
6911
  gates: raw.gates,
6770
6912
  categoryName: typeof raw.categoryName === "string" ? raw.categoryName : null,
6771
6913
  outcome: typeof raw.outcome === "string" ? raw.outcome : null,
6772
- responseId: typeof raw.responseId === "string" ? raw.responseId : null
6914
+ responseId: typeof raw.responseId === "string" ? raw.responseId : null,
6915
+ ticketUrl: typeof raw.ticketUrl === "string" ? raw.ticketUrl : null
6773
6916
  };
6774
6917
  }
6775
6918
  function describeRunDecision(result, mode) {
@@ -6882,7 +7025,13 @@ function FollowupWebhookCard2() {
6882
7025
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs font-medium", children: "Brouillon g\xE9n\xE9r\xE9" }),
6883
7026
  /* @__PURE__ */ jsxRuntime.jsx("p", { className: "whitespace-pre-wrap rounded border bg-muted/30 p-2 text-xs", children: draftText })
6884
7027
  ] }),
6885
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs", children: /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Link, { href: `/espace/${appSlug}/tickets?ticket=${encodeURIComponent(runResult.ticketId ?? test.ticketId)}`, children: "Ouvrir la fiche du ticket" }) })
7028
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-xs", children: [
7029
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Link, { href: `/espace/${appSlug}/tickets?ticket=${encodeURIComponent(runResult.ticketId ?? test.ticketId)}`, children: "Ouvrir la fiche du ticket" }),
7030
+ runResult.ticketUrl !== null && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
7031
+ " \xB7 ",
7032
+ /* @__PURE__ */ jsxRuntime.jsx(uiSdk.Link, { href: runResult.ticketUrl, target: "_blank", rel: "noopener noreferrer", children: "Ouvrir dans Gorgias" })
7033
+ ] })
7034
+ ] })
6886
7035
  ] })
6887
7036
  ] }),
6888
7037
  test?.mode === "diagnostic" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [