@tangle-network/agent-app 0.60.287 → 0.61.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/app-auth/index.js +2 -2
  2. package/dist/assistant/index.js +5 -6
  3. package/dist/assistant/index.js.map +1 -1
  4. package/dist/chat-react/index.js +1 -1
  5. package/dist/chat-routes/index.js +23 -23
  6. package/dist/{chunk-BI5AZAOO.js → chunk-4P5NFBWX.js} +4 -4
  7. package/dist/{chunk-GDUT72VK.js → chunk-6OSJNJA2.js} +9 -4
  8. package/dist/chunk-6OSJNJA2.js.map +1 -0
  9. package/dist/{chunk-UK7QG5BW.js → chunk-6R73V3Y5.js} +1 -1
  10. package/dist/chunk-6R73V3Y5.js.map +1 -0
  11. package/dist/{chunk-4S6YIDKU.js → chunk-GL44S6S5.js} +15 -4
  12. package/dist/chunk-GL44S6S5.js.map +1 -0
  13. package/dist/{chunk-U77HPL3I.js → chunk-LO6VQ35O.js} +2 -2
  14. package/dist/{chunk-XTMRAE6I.js → chunk-UCCSJX64.js} +3 -5
  15. package/dist/chunk-UCCSJX64.js.map +1 -0
  16. package/dist/{chunk-7D5MHMCP.js → chunk-VJBFCNAU.js} +4 -4
  17. package/dist/design-canvas/index.js +3 -3
  18. package/dist/design-canvas-react/index.js +4 -4
  19. package/dist/launch-invariants/index.js +8 -8
  20. package/dist/openui/index.js +3 -3
  21. package/dist/platform/index.js +12 -12
  22. package/dist/profile/index.js +1 -1
  23. package/dist/public-consultation/index.js +3 -2
  24. package/dist/public-consultation/index.js.map +1 -1
  25. package/dist/rollout/d1.d.ts +1 -0
  26. package/dist/rollout/d1.js +3 -2
  27. package/dist/rollout/d1.js.map +1 -1
  28. package/dist/runtime/index.js +3 -3
  29. package/dist/runtime/router-turn.js +2 -2
  30. package/dist/sequences/index.js +5 -5
  31. package/dist/settings-react/index.js +1 -1
  32. package/dist/skills/index.js +3 -3
  33. package/dist/skills-placement/box.js +1 -1
  34. package/dist/skills-placement/index.js +1 -1
  35. package/dist/stories/chat-controls/fixtures.d.ts +0 -3
  36. package/dist/theme/tokens.css +10 -6
  37. package/dist/trace/index.d.ts +2 -2
  38. package/dist/trace/index.js +4 -2
  39. package/dist/trace/index.js.map +1 -1
  40. package/dist/trace/mission-flow.d.ts +1 -1
  41. package/dist/turn-stream/index.js +3 -3
  42. package/dist/turn-trace/turn-facts.d.ts +2 -0
  43. package/dist/web-react/index.js +10 -16
  44. package/dist/web-react/mission-activity.d.ts +1 -3
  45. package/dist/work-product/index.js +10 -10
  46. package/package.json +2 -7
  47. package/dist/chunk-4S6YIDKU.js.map +0 -1
  48. package/dist/chunk-BLCYKYFV.js +0 -346
  49. package/dist/chunk-BLCYKYFV.js.map +0 -1
  50. package/dist/chunk-GDUT72VK.js.map +0 -1
  51. package/dist/chunk-UK7QG5BW.js.map +0 -1
  52. package/dist/chunk-XTMRAE6I.js.map +0 -1
  53. package/dist/stories/chat-controls/discovery-waterfall-fixture.d.ts +0 -3
  54. package/dist/trace/flow-types.d.ts +0 -32
  55. package/dist/web-react/flow-waterfall-model.d.ts +0 -22
  56. package/dist/web-react/flow-waterfall.css +0 -72
  57. package/dist/web-react/flow-waterfall.d.ts +0 -14
  58. package/dist/web-react/flow-waterfall.js +0 -7
  59. package/dist/web-react/flow-waterfall.js.map +0 -1
  60. /package/dist/{chunk-BI5AZAOO.js.map → chunk-4P5NFBWX.js.map} +0 -0
  61. /package/dist/{chunk-U77HPL3I.js.map → chunk-LO6VQ35O.js.map} +0 -0
  62. /package/dist/{chunk-7D5MHMCP.js.map → chunk-VJBFCNAU.js.map} +0 -0
@@ -10,8 +10,8 @@ import "../chunk-R4X5474U.js";
10
10
  import "../chunk-SJWIZT7B.js";
11
11
  import "../chunk-RASGKEAL.js";
12
12
  import "../chunk-IUVDR3KJ.js";
13
- import "../chunk-G7M2C72Q.js";
14
13
  import "../chunk-AMUXRAUO.js";
14
+ import "../chunk-G7M2C72Q.js";
15
15
  import "../chunk-FPNZMIAW.js";
16
16
  import "../chunk-TXD5HXLE.js";
17
17
  export {
@@ -1,6 +1,3 @@
1
- import {
2
- redactErrorMessage
3
- } from "../chunk-MH74DY2I.js";
4
1
  import {
5
2
  createSandboxFileIndexRoute
6
3
  } from "../chunk-FQYAJYPW.js";
@@ -52,6 +49,24 @@ import {
52
49
  } from "../chunk-DJIN3YUJ.js";
53
50
  import "../chunk-F4TUZYMX.js";
54
51
  import "../chunk-4LBCTFBP.js";
52
+ import "../chunk-DSMGS4IV.js";
53
+ import "../chunk-5BJHKQ33.js";
54
+ import "../chunk-6A7MYOUI.js";
55
+ import "../chunk-O7UX55EU.js";
56
+ import "../chunk-XEAZWJ3W.js";
57
+ import "../chunk-S5SRJJQG.js";
58
+ import "../chunk-7TZA2TAM.js";
59
+ import "../chunk-UGWQLQDS.js";
60
+ import "../chunk-WSQFNMIA.js";
61
+ import {
62
+ runProtectedRouterTurn
63
+ } from "../chunk-LO6VQ35O.js";
64
+ import {
65
+ runRouterTurn
66
+ } from "../chunk-VJBFCNAU.js";
67
+ import "../chunk-UFQM46NV.js";
68
+ import "../chunk-D6UJEOZQ.js";
69
+ import "../chunk-AMUXRAUO.js";
55
70
  import {
56
71
  INTENT_LINE_HISTORY_MESSAGES,
57
72
  INTENT_LINE_MAX_CHARS,
@@ -63,14 +78,17 @@ import {
63
78
  rowIdOf,
64
79
  storeSupportsDraftPersistence,
65
80
  streamChatRouteAsSandboxEvents
66
- } from "../chunk-4S6YIDKU.js";
81
+ } from "../chunk-GL44S6S5.js";
82
+ import {
83
+ redactErrorMessage
84
+ } from "../chunk-MH74DY2I.js";
67
85
  import "../chunk-KH4QSBNI.js";
68
86
  import {
69
87
  sniffMimeFromName
70
88
  } from "../chunk-CQGEGPY7.js";
71
89
  import "../chunk-RN4WPTBH.js";
72
90
  import "../chunk-WP2GYFZ4.js";
73
- import "../chunk-UK7QG5BW.js";
91
+ import "../chunk-6R73V3Y5.js";
74
92
  import {
75
93
  attachmentInputToPart,
76
94
  attachmentKindForMime,
@@ -142,25 +160,7 @@ import {
142
160
  } from "../chunk-ISP6ZH3G.js";
143
161
  import "../chunk-MM6RLOXF.js";
144
162
  import "../chunk-XELWWXJJ.js";
145
- import "../chunk-DSMGS4IV.js";
146
- import "../chunk-5BJHKQ33.js";
147
- import "../chunk-6A7MYOUI.js";
148
- import "../chunk-O7UX55EU.js";
149
- import "../chunk-XEAZWJ3W.js";
150
- import "../chunk-S5SRJJQG.js";
151
- import "../chunk-7TZA2TAM.js";
152
- import "../chunk-UGWQLQDS.js";
153
- import "../chunk-WSQFNMIA.js";
154
- import {
155
- runProtectedRouterTurn
156
- } from "../chunk-U77HPL3I.js";
157
- import {
158
- runRouterTurn
159
- } from "../chunk-7D5MHMCP.js";
160
- import "../chunk-UFQM46NV.js";
161
- import "../chunk-D6UJEOZQ.js";
162
163
  import "../chunk-ORQD4AUO.js";
163
- import "../chunk-AMUXRAUO.js";
164
164
  import {
165
165
  readSandboxBinaryBytes,
166
166
  statSandboxFileSize
@@ -1,11 +1,11 @@
1
+ import {
2
+ isTangleBillingEnforcementDisabled
3
+ } from "./chunk-D6UJEOZQ.js";
1
4
  import {
2
5
  clearCookieHeader,
3
6
  readCookieValue,
4
7
  serializeCookie
5
8
  } from "./chunk-WP2GYFZ4.js";
6
- import {
7
- isTangleBillingEnforcementDisabled
8
- } from "./chunk-D6UJEOZQ.js";
9
9
 
10
10
  // src/platform/sso.ts
11
11
  var DEFAULT_STATE_TTL_SECONDS = 600;
@@ -516,4 +516,4 @@ export {
516
516
  createAdminGuard,
517
517
  assertBillableBalance
518
518
  };
519
- //# sourceMappingURL=chunk-BI5AZAOO.js.map
519
+ //# sourceMappingURL=chunk-4P5NFBWX.js.map
@@ -4,17 +4,22 @@ var str = (v) => typeof v === "string" && v.length > 0 ? v : void 0;
4
4
  var rec = (v) => v && typeof v === "object" ? v : {};
5
5
  var LIVE_DELEGATION_STATUSES = /* @__PURE__ */ new Set(["pending", "running"]);
6
6
  var ERROR_STATUSES = /* @__PURE__ */ new Set(["failed", "error", "cancelled", "aborted", "down"]);
7
+ function flowStatus(status) {
8
+ const normalized = String(status ?? "").toLowerCase();
9
+ return ERROR_STATUSES.has(normalized) ? "failed" : LIVE_DELEGATION_STATUSES.has(normalized) ? "running" : "done";
10
+ }
7
11
  function delegationActivityToFlowSpans(activity, turnStartMs, opts) {
8
12
  const spans = [];
9
13
  for (const run of activity) {
10
14
  const startedAt = Date.parse(run.startedAt);
11
15
  if (!Number.isFinite(startedAt)) continue;
12
16
  const startMs = startedAt - turnStartMs;
13
- const live = LIVE_DELEGATION_STATUSES.has(run.status);
17
+ const status = flowStatus(run.status);
18
+ const live = status === "running";
14
19
  const endMs = run.durationMs !== void 0 ? startMs + run.durationMs : live && opts?.nowMs !== void 0 ? opts.nowMs - turnStartMs : startMs;
15
20
  spans.push({
16
21
  id: run.taskId,
17
- status: live ? "running" : ERROR_STATUSES.has(run.status) ? "failed" : "done",
22
+ status,
18
23
  kind: "tool",
19
24
  name: `${run.tool} \u2014 ${run.detail}`,
20
25
  startMs,
@@ -212,7 +217,7 @@ function composeMissionFlowTrace(input) {
212
217
  spans.push({
213
218
  kind: "pipeline",
214
219
  id: `step-${step.id}`,
215
- ...step.status && LIVE_DELEGATION_STATUSES.has(step.status) ? { status: "running" } : {},
220
+ status: flowStatus(step.status),
216
221
  name: step.intent,
217
222
  startMs,
218
223
  endMs,
@@ -243,4 +248,4 @@ export {
243
248
  stepActivityFlowTrace,
244
249
  composeMissionFlowTrace
245
250
  };
246
- //# sourceMappingURL=chunk-GDUT72VK.js.map
251
+ //# sourceMappingURL=chunk-6OSJNJA2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/trace/mission-flow.ts"],"sourcesContent":["/**\n * Delegation → FlowSpan converters — render what a mission's delegated agent\n * runs actually did as ONE FlowTrace, drawable by the existing\n * `renderWaterfall` (or any viewer that consumes FlowSpans).\n *\n * Two fidelities, one tree:\n * - COARSE: `delegationActivityToFlowSpans` draws one 'tool' span per\n * delegation from the StepAgentActivity snapshot (startedAt/durationMs) —\n * available live, from the step's journaled lane.\n * - FINE: `loopTraceEventsToFlowSpans` reconstructs agent-runtime's\n * loop → round → iteration hierarchy from the LoopTraceEvent journal a\n * delegation persists. Stable ids carry the hierarchy; descriptive names\n * retain context in the ASCII waterfall as well.\n *\n * `composeMissionFlowTrace` lays a whole mission out: one 'pipeline' span per\n * step, each step's delegations beneath it. Pure data transforms — the\n * structural `LoopTraceEventLike` keeps this module free of the optional\n * agent-runtime peer.\n */\n\nimport type { StepAgentActivity } from '../missions/agent-activity'\nimport type { FlowSpan, FlowTrace } from '@tangle-network/charts'\n\n/** Structural mirror of agent-runtime's `LoopTraceEvent` — same fields, no\n * import, so journals parsed from JSON feed straight in. */\nexport interface LoopTraceEventLike {\n kind: string\n runId: string\n /** Epoch ms. */\n timestamp: number\n payload: object\n}\n\nconst num = (v: unknown): number | undefined =>\n typeof v === 'number' && Number.isFinite(v) ? v : undefined\nconst str = (v: unknown): string | undefined =>\n typeof v === 'string' && v.length > 0 ? v : undefined\nconst rec = (v: unknown): Record<string, unknown> =>\n v && typeof v === 'object' ? (v as Record<string, unknown>) : {}\n\n/** Statuses that mean the delegation is still producing wall time. */\nconst LIVE_DELEGATION_STATUSES = new Set(['pending', 'running'])\nconst ERROR_STATUSES = new Set(['failed', 'error', 'cancelled', 'aborted', 'down'])\n\n/** Interpret domain wire status at the producer boundary, never in the chart. */\nfunction flowStatus(status?: string): NonNullable<FlowSpan['status']> {\n const normalized = String(status ?? '').toLowerCase()\n return ERROR_STATUSES.has(normalized) ? 'failed'\n : LIVE_DELEGATION_STATUSES.has(normalized) ? 'running' : 'done'\n}\n\n/**\n * One 'tool' FlowSpan per delegation, positioned relative to `turnStartMs`\n * (the epoch-ms origin of the trace — usually the step or mission start).\n * A row whose `startedAt` does not parse cannot be placed on a timeline and\n * is omitted from the WATERFALL (it stays in the lane itself). A run without\n * `durationMs` is still in flight: its span extends to `opts.nowMs` when\n * given, else renders as a point — `approx` flags both.\n */\nexport function delegationActivityToFlowSpans(\n activity: StepAgentActivity[],\n turnStartMs: number,\n opts?: { nowMs?: number },\n): FlowSpan[] {\n const spans: FlowSpan[] = []\n for (const run of activity) {\n const startedAt = Date.parse(run.startedAt)\n if (!Number.isFinite(startedAt)) continue\n const startMs = startedAt - turnStartMs\n const status = flowStatus(run.status)\n const live = status === 'running'\n const endMs =\n run.durationMs !== undefined\n ? startMs + run.durationMs\n : live && opts?.nowMs !== undefined\n ? opts.nowMs - turnStartMs\n : startMs\n spans.push({\n id: run.taskId,\n status,\n kind: 'tool',\n name: `${run.tool} — ${run.detail}`,\n startMs,\n endMs: Math.max(endMs, startMs),\n ...(run.durationMs === undefined ? { approx: true } : {}),\n meta: {\n taskId: run.taskId,\n status: run.status,\n ...(run.costUsd !== undefined ? { costUsd: run.costUsd } : {}),\n ...(run.iteration !== undefined ? { iteration: run.iteration } : {}),\n ...(run.phase !== undefined ? { phase: run.phase } : {}),\n ...(run.traceId !== undefined ? { traceId: run.traceId } : {}),\n ...(run.spanId !== undefined ? { spanId: run.spanId } : {}),\n },\n })\n }\n return spans\n}\n\n/**\n * Reconstruct one delegation's loop → round → iteration tree from its\n * journaled LoopTraceEvents, as FlowSpans relative to `loop.started` (or the\n * first event). Mirrors agent-runtime's `buildLoopOtelSpans` topology:\n * rounds open on `loop.plan` and flush on the next plan / `loop.decision` /\n * `loop.ended`; iterations span `loop.iteration.started` → `.ended`.\n */\nexport function loopTraceEventsToFlowSpans(events: LoopTraceEventLike[]): FlowSpan[] {\n if (events.length === 0) return []\n const ordered = [...events].sort((a, b) => a.timestamp - b.timestamp)\n const started = ordered.find((e) => e.kind === 'loop.started')\n const ended = ordered.find((e) => e.kind === 'loop.ended')\n const origin = started?.timestamp ?? ordered[0]!.timestamp\n const rootEnd = ended?.timestamp ?? ordered[ordered.length - 1]!.timestamp\n const t = (epochMs: number) => epochMs - origin\n const rootId = `loop:${ordered[0]!.runId}`\n\n const spans: FlowSpan[] = []\n const sp = rec(started?.payload)\n const ep = rec(ended?.payload)\n spans.push({\n kind: 'pipeline',\n id: rootId,\n status: ended ? 'done' : 'running',\n name: 'loop',\n startMs: 0,\n endMs: t(rootEnd),\n meta: {\n runId: ordered[0]!.runId,\n ...(str(sp.driver) !== undefined ? { driver: str(sp.driver) } : {}),\n ...(num(ep.totalCostUsd) !== undefined ? { costUsd: num(ep.totalCostUsd) } : {}),\n ...(num(ep.winnerIterationIndex) !== undefined\n ? { winnerIterationIndex: num(ep.winnerIterationIndex) }\n : {}),\n ...(num(ep.iterations) !== undefined ? { iterations: num(ep.iterations) } : {}),\n },\n })\n\n const iterStart = new Map<number, { timestamp: number; parentId: string }>()\n let round: { index: number; startMs: number; meta: Record<string, unknown>; moveKind: string } | undefined\n const flushRound = (endEpochMs: number, running = false) => {\n if (!round) return\n spans.push({\n kind: 'pipeline',\n id: `${rootId}:round-${round.index}`,\n parentId: rootId,\n status: running ? 'running' : 'done',\n name: `loop ▸ round ${round.index} (${round.moveKind})`,\n startMs: round.startMs,\n endMs: t(endEpochMs),\n meta: round.meta,\n })\n round = undefined\n }\n\n for (const e of ordered) {\n const p = rec(e.payload)\n switch (e.kind) {\n case 'loop.plan': {\n flushRound(e.timestamp)\n const index = num(p.roundIndex) ?? 0\n round = {\n index,\n startMs: t(e.timestamp),\n moveKind: str(p.moveKind) ?? 'unknown',\n meta: {\n roundIndex: index,\n moveKind: str(p.moveKind) ?? 'unknown',\n width: num(p.plannedCount) ?? 0,\n ...(str(p.rationale) !== undefined ? { rationale: str(p.rationale) } : {}),\n ...(num(p.parentIndex) !== undefined ? { parentIndex: num(p.parentIndex) } : {}),\n },\n }\n break\n }\n case 'loop.iteration.started': {\n const idx = num(p.iterationIndex)\n if (idx !== undefined) iterStart.set(idx, { timestamp: e.timestamp, parentId: round ? `${rootId}:round-${round.index}` : rootId })\n break\n }\n case 'loop.iteration.ended': {\n const idx = num(p.iterationIndex) ?? 0\n const open = iterStart.get(idx)\n const startEpoch = open?.timestamp ?? e.timestamp\n iterStart.delete(idx)\n const error = str(p.error)\n const verdict = rec(p.verdict)\n const tokens = rec(p.tokenUsage)\n const roundLabel = round ? `round ${round.index} ▸ ` : ''\n spans.push({\n kind: 'model',\n id: `${rootId}:iteration-${idx}`,\n parentId: open?.parentId ?? rootId,\n status: error ? 'failed' : 'done',\n name: `loop ▸ ${roundLabel}iter ${idx} (${str(p.agentRunName) ?? 'agent'})`,\n startMs: t(startEpoch),\n endMs: t(e.timestamp),\n meta: {\n iterationIndex: idx,\n ok: error === undefined,\n ...(error !== undefined ? { error } : {}),\n ...(num(p.costUsd) !== undefined ? { costUsd: num(p.costUsd) } : {}),\n ...(typeof verdict.valid === 'boolean' ? { verdictValid: verdict.valid } : {}),\n ...(num(verdict.score) !== undefined ? { verdictScore: num(verdict.score) } : {}),\n ...(num(tokens.input) !== undefined ? { inputTokens: num(tokens.input) } : {}),\n ...(num(tokens.output) !== undefined ? { outputTokens: num(tokens.output) } : {}),\n },\n })\n break\n }\n case 'loop.decision': {\n if (round) {\n const decision = str(p.decision)\n if (decision !== undefined) round.meta.decision = decision\n flushRound(e.timestamp)\n }\n break\n }\n }\n }\n flushRound(rootEnd, !ended)\n for (const [idx, open] of iterStart) {\n spans.push({ kind: 'model', id: `${rootId}:iteration-${idx}`, parentId: open.parentId,\n name: `loop ▸ iter ${idx}`, startMs: t(open.timestamp), endMs: t(rootEnd),\n status: ended ? 'failed' : 'running', approx: true })\n }\n return spans\n}\n\n/**\n * A single step's activity lane as its own FlowTrace — what a per-step\n * drill-in renders. Origin defaults to the earliest delegation start so the\n * waterfall begins at the lane's first run.\n */\nexport function stepActivityFlowTrace(\n activity: StepAgentActivity[],\n opts?: { startedAt?: number; nowMs?: number },\n): FlowTrace {\n let origin = opts?.startedAt\n if (origin === undefined) {\n for (const run of activity) {\n const parsed = Date.parse(run.startedAt)\n if (Number.isFinite(parsed) && (origin === undefined || parsed < origin)) origin = parsed\n }\n }\n const spans = delegationActivityToFlowSpans(\n activity,\n origin ?? 0,\n opts?.nowMs !== undefined ? { nowMs: opts.nowMs } : undefined,\n )\n let costUsd: number | undefined\n for (const span of spans) {\n const c = num(rec(span.meta).costUsd)\n if (c !== undefined) costUsd = (costUsd ?? 0) + c\n }\n return {\n spans,\n totalMs: spans.reduce((max, s) => Math.max(max, s.endMs), 0),\n promptTokens: 0,\n completionTokens: 0,\n ...(costUsd !== undefined ? { costUsd } : {}),\n toolCalls: spans.length,\n }\n}\n\n/** Define a step in a mission flow with id, intent, optional status, start time, and duration */\nexport interface MissionFlowStep {\n id: string\n intent: string\n status?: string\n /** Epoch ms the step attempt started. Absent → laid out sequentially after\n * the previous step (missions run steps in order), `approx` flagged. */\n startedAt?: number\n durationMs?: number\n}\n\n/**\n * Compose a mission-wide FlowTrace: one 'pipeline' span per step, the step's\n * delegated runs ('tool' spans, from `activity[stepId]`) beneath it. A step\n * span always covers its delegations' extent. Cost is the sum of delegation\n * `costUsd`; token counts are not knowable from the activity lane and stay 0.\n */\nexport function composeMissionFlowTrace(input: {\n steps: MissionFlowStep[]\n /** Delegated-run snapshots keyed by step id (the step's `agentActivity`). */\n activity?: Record<string, StepAgentActivity[]>\n /** Epoch-ms origin. Default: the earliest known step/delegation start. */\n startedAt?: number\n}): FlowTrace {\n const activity = input.activity ?? {}\n\n const startCandidates: number[] = []\n if (input.startedAt !== undefined) startCandidates.push(input.startedAt)\n else {\n for (const step of input.steps) {\n if (step.startedAt !== undefined) startCandidates.push(step.startedAt)\n }\n for (const runs of Object.values(activity)) {\n for (const run of runs) {\n const parsed = Date.parse(run.startedAt)\n if (Number.isFinite(parsed)) startCandidates.push(parsed)\n }\n }\n }\n const origin = startCandidates.length > 0 ? Math.min(...startCandidates) : 0\n\n const spans: FlowSpan[] = []\n let costUsd: number | undefined\n let toolCalls = 0\n let cursorMs = 0\n\n for (const step of input.steps) {\n const inferred = step.startedAt === undefined\n const startMs = inferred ? cursorMs : step.startedAt! - origin\n const runSpans = delegationActivityToFlowSpans(activity[step.id] ?? [], origin)\n const runExtent = runSpans.reduce((max, s) => Math.max(max, s.endMs), startMs)\n const endMs = Math.max(step.durationMs !== undefined ? startMs + step.durationMs : startMs, runExtent)\n\n spans.push({\n kind: 'pipeline',\n id: `step-${step.id}`,\n status: flowStatus(step.status),\n name: step.intent,\n startMs,\n endMs,\n ...(inferred || step.durationMs === undefined ? { approx: true } : {}),\n meta: { stepId: step.id, ...(step.status !== undefined ? { status: step.status } : {}) },\n })\n for (const span of runSpans) {\n spans.push({ ...span, id: `step-${step.id}:${span.id}`, parentId: `step-${step.id}`, name: `${step.intent} ▸ ${span.name}` })\n toolCalls++\n const c = num(rec(span.meta).costUsd)\n if (c !== undefined) costUsd = (costUsd ?? 0) + c\n }\n cursorMs = endMs\n }\n\n return {\n spans,\n totalMs: spans.reduce((max, s) => Math.max(max, s.endMs), 0),\n promptTokens: 0,\n completionTokens: 0,\n ...(costUsd !== undefined ? { costUsd } : {}),\n toolCalls,\n }\n}\n"],"mappings":";AAiCA,IAAM,MAAM,CAAC,MACX,OAAO,MAAM,YAAY,OAAO,SAAS,CAAC,IAAI,IAAI;AACpD,IAAM,MAAM,CAAC,MACX,OAAO,MAAM,YAAY,EAAE,SAAS,IAAI,IAAI;AAC9C,IAAM,MAAM,CAAC,MACX,KAAK,OAAO,MAAM,WAAY,IAAgC,CAAC;AAGjE,IAAM,2BAA2B,oBAAI,IAAI,CAAC,WAAW,SAAS,CAAC;AAC/D,IAAM,iBAAiB,oBAAI,IAAI,CAAC,UAAU,SAAS,aAAa,WAAW,MAAM,CAAC;AAGlF,SAAS,WAAW,QAAkD;AACpE,QAAM,aAAa,OAAO,UAAU,EAAE,EAAE,YAAY;AACpD,SAAO,eAAe,IAAI,UAAU,IAAI,WACpC,yBAAyB,IAAI,UAAU,IAAI,YAAY;AAC7D;AAUO,SAAS,8BACd,UACA,aACA,MACY;AACZ,QAAM,QAAoB,CAAC;AAC3B,aAAW,OAAO,UAAU;AAC1B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MAAM,IAAI,QAAQ,KAAK,EAAE,IAAI,KAAK,EAAE,IAAI,UAAU,QAAQ,KAAK,EAAE,IAAI,MAAM,GAAG,KAAK,MAAM,WAAM,KAAK,IAAI,GAAG,CAAC;AAC5H;AACA,YAAM,IAAI,IAAI,IAAI,KAAK,IAAI,EAAE,OAAO;AACpC,UAAI,MAAM,OAAW,YAAW,WAAW,KAAK;AAAA,IAClD;AACA,eAAW;AAAA,EACb;AAEA,SAAO;AAAA,IACL;AAAA,IACA,SAAS,MAAM,OAAO,CAAC,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,KAAK,GAAG,CAAC;AAAA,IAC3D,cAAc;AAAA,IACd,kBAAkB;AAAA,IAClB,GAAI,YAAY,SAAY,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC3C;AAAA,EACF;AACF;","names":[]}
@@ -14,4 +14,4 @@ export {
14
14
  noteMeasuredTurnFacts,
15
15
  measuredTurnFacts
16
16
  };
17
- //# sourceMappingURL=chunk-UK7QG5BW.js.map
17
+ //# sourceMappingURL=chunk-6R73V3Y5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/turn-trace/turn-facts.ts"],"sourcesContent":["/**\n * What `createChatTurnRoutes` measured for a settled turn, kept in this isolate\n * under the turn's stream id so the rollout timing store can fill the row the\n * product writes from its lifecycle hook. A product's writer that forgot\n * `firstVisibleMs` or `admissionMs` (Legal never wrote first_visible_ms) still\n * records them after a version bump, on every lane.\n *\n * Internal: not exported from a subpath. Values the product passes always win.\n */\nexport interface MeasuredTurnFacts {\n admissionMs?: number\n firstVisibleMs?: number\n firstTextMs?: number\n /** The model that served the turn. */\n model?: string\n /** The terminal event's readable code and explanation, before product serialization. */\n failureCode?: string\n}\n\n/** Turns kept; a lifecycle hook reads its turn's facts within the same request, so a small window is enough. */\nconst KEEP = 512\nconst facts = new Map<string, MeasuredTurnFacts>()\n\nexport function noteMeasuredTurnFacts(turnStreamId: string, measured: MeasuredTurnFacts): void {\n facts.delete(turnStreamId)\n facts.set(turnStreamId, measured)\n if (facts.size > KEEP) facts.delete(facts.keys().next().value!)\n}\n\nexport function measuredTurnFacts(turnStreamId: string): MeasuredTurnFacts | undefined {\n return facts.get(turnStreamId)\n}\n"],"mappings":";AAoBA,IAAM,OAAO;AACb,IAAM,QAAQ,oBAAI,IAA+B;AAE1C,SAAS,sBAAsB,cAAsB,UAAmC;AAC7F,QAAM,OAAO,YAAY;AACzB,QAAM,IAAI,cAAc,QAAQ;AAChC,MAAI,MAAM,OAAO,KAAM,OAAM,OAAO,MAAM,KAAK,EAAE,KAAK,EAAE,KAAM;AAChE;AAEO,SAAS,kBAAkB,cAAqD;AACrF,SAAO,MAAM,IAAI,YAAY;AAC/B;","names":[]}
@@ -1,3 +1,6 @@
1
+ import {
2
+ redactErrorMessage
3
+ } from "./chunk-MH74DY2I.js";
1
4
  import {
2
5
  createInteractionAnswerRoute
3
6
  } from "./chunk-KH4QSBNI.js";
@@ -6,7 +9,7 @@ import {
6
9
  } from "./chunk-WP2GYFZ4.js";
7
10
  import {
8
11
  noteMeasuredTurnFacts
9
- } from "./chunk-UK7QG5BW.js";
12
+ } from "./chunk-6R73V3Y5.js";
10
13
  import {
11
14
  mentionInputToPart,
12
15
  toChatMessageParts
@@ -628,7 +631,14 @@ function settledTurnTiming(turnStreamId, at, trace) {
628
631
  ...at.firstVisibleAt === void 0 ? {} : { firstVisibleMs: at.firstVisibleAt - at.startedAt },
629
632
  ...at.firstTextAt === void 0 ? {} : { firstTextMs: at.firstTextAt - at.startedAt }
630
633
  };
631
- noteMeasuredTurnFacts(turnStreamId, { ...measured, ...at.model ? { model: at.model } : {} });
634
+ const reason = at.failure ? failureReasonOf(at.failure.data) ?? redactErrorMessage(at.failure.error, "chat turn failed") : void 0;
635
+ const code = at.failure ? failureCodeOf(at.failure.data) : void 0;
636
+ const failureCode = reason ? redactErrorMessage(code && !reason.startsWith(code) ? `${code}: ${reason}` : reason) : void 0;
637
+ noteMeasuredTurnFacts(turnStreamId, {
638
+ ...measured,
639
+ ...at.model ? { model: at.model } : {},
640
+ ...failureCode ? { failureCode } : {}
641
+ });
632
642
  return { ...measured, trace };
633
643
  }
634
644
  function createAdmittedTurnRunner({
@@ -827,7 +837,8 @@ function createAdmittedTurnRunner({
827
837
  startedAt: turnStartedAtMs,
828
838
  firstVisibleAt: firstVisibleAtMs,
829
839
  firstTextAt: firstTextAtMs,
830
- model: producer?.model
840
+ model: producer?.model,
841
+ failure: failed ? { data: lastFailureData, error: terminalError } : void 0
831
842
  }, snapshot.summary);
832
843
  try {
833
844
  if (!lifecycle) {
@@ -1703,4 +1714,4 @@ export {
1703
1714
  createChatTurnRoutes,
1704
1715
  streamChatRouteAsSandboxEvents
1705
1716
  };
1706
- //# sourceMappingURL=chunk-4S6YIDKU.js.map
1717
+ //# sourceMappingURL=chunk-GL44S6S5.js.map