@leitwerk-dev/protocol 0.2.0 → 0.3.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.
Files changed (128) hide show
  1. package/dist/api-token-contracts.d.ts +20 -0
  2. package/dist/api-token-contracts.d.ts.map +1 -1
  3. package/dist/{chunk-J4VMD5ST.js → chunk-4AKWRRFS.js} +98 -4
  4. package/dist/chunk-4AKWRRFS.js.map +1 -0
  5. package/dist/{chunk-Z4IU6KEN.js → chunk-LTIDCJFK.js} +146 -1
  6. package/dist/chunk-LTIDCJFK.js.map +1 -0
  7. package/dist/{chunk-IWVU76M5.js → chunk-RUPDB3WZ.js} +1 -1
  8. package/dist/chunk-RUPDB3WZ.js.map +1 -0
  9. package/dist/compact-turn-summary.d.ts +21 -3
  10. package/dist/compact-turn-summary.d.ts.map +1 -1
  11. package/dist/config-snapshot-public.d.ts +2 -0
  12. package/dist/config-snapshot-public.d.ts.map +1 -0
  13. package/dist/config-snapshot-public.js +1 -0
  14. package/dist/config-snapshot.d.ts +109 -16
  15. package/dist/config-snapshot.d.ts.map +1 -1
  16. package/dist/config-snapshot.js +0 -1
  17. package/dist/extension-ui-contracts.d.ts +22 -0
  18. package/dist/extension-ui-contracts.d.ts.map +1 -1
  19. package/dist/external-review.d.ts +5 -1
  20. package/dist/external-review.d.ts.map +1 -1
  21. package/dist/form-contract-public.d.ts +2 -0
  22. package/dist/form-contract-public.d.ts.map +1 -0
  23. package/dist/form-contract-public.js +1 -0
  24. package/dist/form-contract.d.ts +29 -5
  25. package/dist/form-contract.d.ts.map +1 -1
  26. package/dist/form-contract.js +0 -1
  27. package/dist/{http-contracts-ht8DDU4J.d.ts → http-contracts-public-rL4HFcxz.d.ts} +971 -45
  28. package/dist/http-contracts-public.d.ts +4 -0
  29. package/dist/http-contracts-public.d.ts.map +1 -0
  30. package/dist/http-contracts-public.js +10 -0
  31. package/dist/http-contracts.d.ts +819 -12
  32. package/dist/http-contracts.d.ts.map +1 -1
  33. package/dist/http-contracts.js +2 -2
  34. package/dist/index.d.ts +30 -25
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +25 -75
  37. package/dist/index.js.map +1 -1
  38. package/dist/initial-prompt.d.ts +6 -0
  39. package/dist/initial-prompt.d.ts.map +1 -1
  40. package/dist/launcher-contract-public.d.ts +2 -0
  41. package/dist/launcher-contract-public.d.ts.map +1 -0
  42. package/dist/launcher-contract-public.js +1 -0
  43. package/dist/launcher-contract-public.js.map +1 -0
  44. package/dist/launcher-contract.d.ts +26 -1
  45. package/dist/launcher-contract.d.ts.map +1 -1
  46. package/dist/launcher-contract.js +0 -1
  47. package/dist/live-turn-projection.d.ts +29 -0
  48. package/dist/live-turn-projection.d.ts.map +1 -1
  49. package/dist/pi-session-message.d.ts +16 -0
  50. package/dist/pi-session-message.d.ts.map +1 -1
  51. package/dist/primary-path-snapshot.d.ts +64 -0
  52. package/dist/primary-path-snapshot.d.ts.map +1 -1
  53. package/dist/protocol.d.ts +387 -1
  54. package/dist/protocol.d.ts.map +1 -1
  55. package/dist/protocol.js +1 -1
  56. package/dist/session-entry-tree.d.ts +12 -0
  57. package/dist/session-entry-tree.d.ts.map +1 -1
  58. package/dist/streamable-events.d.ts +3 -0
  59. package/dist/streamable-events.d.ts.map +1 -1
  60. package/dist/text-preview.d.ts +5 -0
  61. package/dist/text-preview.d.ts.map +1 -1
  62. package/dist/ticket-creation-contracts.d.ts +23 -1
  63. package/dist/ticket-creation-contracts.d.ts.map +1 -1
  64. package/dist/timeline-projection.d.ts +5 -0
  65. package/dist/timeline-projection.d.ts.map +1 -1
  66. package/dist/timestamp-ordering.d.ts +2 -0
  67. package/dist/timestamp-ordering.d.ts.map +1 -1
  68. package/dist/tool-renderer-contract-public.d.ts +3 -0
  69. package/dist/tool-renderer-contract-public.d.ts.map +1 -0
  70. package/dist/tool-renderer-contract-public.js +9 -0
  71. package/dist/tool-renderer-contract-public.js.map +1 -0
  72. package/dist/tool-renderer-contract.d.ts +15 -0
  73. package/dist/tool-renderer-contract.d.ts.map +1 -1
  74. package/dist/tool-renderer-contract.js +1 -1
  75. package/dist/tool-result-truncation.d.ts +4 -0
  76. package/dist/tool-result-truncation.d.ts.map +1 -1
  77. package/dist/turn-continuation.d.ts +28 -0
  78. package/dist/turn-continuation.d.ts.map +1 -1
  79. package/dist/turn-trace-projection.d.ts +1 -1
  80. package/dist/turn-trace-projection.d.ts.map +1 -1
  81. package/dist/usage-by-turn-record.d.ts +2 -0
  82. package/dist/usage-by-turn-record.d.ts.map +1 -1
  83. package/dist/usage-snapshot.d.ts +20 -3
  84. package/dist/usage-snapshot.d.ts.map +1 -1
  85. package/dist/ws-event-payloads.d.ts +14 -0
  86. package/dist/ws-event-payloads.d.ts.map +1 -1
  87. package/package.json +17 -17
  88. package/src/api-token-contracts.ts +20 -0
  89. package/src/compact-turn-summary.ts +26 -4
  90. package/src/config-snapshot-public.ts +12 -0
  91. package/src/config-snapshot.ts +109 -16
  92. package/src/extension-ui-contracts.ts +22 -0
  93. package/src/external-review.ts +5 -1
  94. package/src/form-contract-public.ts +6 -0
  95. package/src/form-contract.ts +29 -5
  96. package/src/http-contracts-public.ts +86 -0
  97. package/src/http-contracts.ts +926 -40
  98. package/src/index.ts +184 -25
  99. package/src/initial-prompt.ts +6 -0
  100. package/src/launcher-contract-public.ts +8 -0
  101. package/src/launcher-contract.ts +26 -1
  102. package/src/live-turn-projection.ts +29 -0
  103. package/src/pi-session-message.ts +21 -3
  104. package/src/primary-path-snapshot.ts +64 -0
  105. package/src/protocol.ts +412 -17
  106. package/src/session-entry-tree.ts +12 -0
  107. package/src/streamable-events.ts +3 -0
  108. package/src/text-preview.ts +5 -0
  109. package/src/ticket-creation-contracts.ts +31 -3
  110. package/src/timeline-projection.ts +5 -0
  111. package/src/timestamp-ordering.ts +2 -0
  112. package/src/tool-renderer-contract-public.ts +10 -0
  113. package/src/tool-renderer-contract.ts +15 -0
  114. package/src/tool-result-truncation.ts +4 -0
  115. package/src/turn-continuation.ts +28 -0
  116. package/src/turn-trace-projection.ts +1 -1
  117. package/src/usage-by-turn-record.ts +2 -0
  118. package/src/usage-snapshot.ts +20 -3
  119. package/src/ws-event-payloads.ts +14 -0
  120. package/dist/chunk-6L4W7WPV.js +0 -1
  121. package/dist/chunk-AAV3AAOF.js +0 -1
  122. package/dist/chunk-IEMT3JG4.js +0 -1
  123. package/dist/chunk-IWVU76M5.js.map +0 -1
  124. package/dist/chunk-J4VMD5ST.js.map +0 -1
  125. package/dist/chunk-Z4IU6KEN.js.map +0 -1
  126. /package/dist/{chunk-6L4W7WPV.js.map → config-snapshot-public.js.map} +0 -0
  127. /package/dist/{chunk-AAV3AAOF.js.map → form-contract-public.js.map} +0 -0
  128. /package/dist/{chunk-IEMT3JG4.js.map → http-contracts-public.js.map} +0 -0
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/usage-snapshot.ts","../src/ws-event-payloads.ts","../src/compact-turn-summary.ts","../src/extension-ui-contracts.ts","../src/initial-prompt.ts","../src/live-turn-projection.ts","../src/timestamp-ordering.ts","../src/pi-session-message.ts","../src/session-entry-tree.ts","../src/streamable-events.ts","../src/text-preview.ts","../src/timeline-projection.ts","../src/tool-result-truncation.ts","../src/turn-continuation.ts","../src/turn-trace-projection.ts","../src/usage-by-turn-record.ts"],"sourcesContent":["import { copiedUnknownRecordSchema as unknownRecordSchema } from \"@leitwerk-dev/domain\";\nimport * as v from \"valibot\";\n\nexport interface UsageCostSnapshot {\n\tinput: number;\n\toutput: number;\n\tcacheRead: number;\n\tcacheWrite: number;\n\ttotal: number;\n}\n\nexport interface UsageTokenCounts {\n\tinput: number;\n\toutput: number;\n\t/** Provider-reported reasoning/thinking tokens. This is a subset of output tokens. */\n\treasoning?: number;\n\tcacheRead: number;\n\tcacheWrite: number;\n\ttotalTokens: number;\n}\n\nexport interface UsageSnapshot extends UsageTokenCounts {\n\tcost: UsageCostSnapshot | null;\n\t/** Number of model requests represented by this aggregate, when known. */\n\trequestCount?: number;\n\t/** Largest input-token count for a single represented model request, when known. */\n\tmaxInputTokens?: number;\n}\n\nfunction readFiniteNumber(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\nfunction normalizeUsageCostSnapshot(value: unknown): UsageCostSnapshot | null {\n\tconst parsedValue = v.safeParse(unknownRecordSchema, value);\n\tif (!parsedValue.success) {\n\t\treturn null;\n\t}\n\tconst record = parsedValue.output;\n\tconst input = readFiniteNumber(record.input) ?? 0;\n\tconst output = readFiniteNumber(record.output) ?? 0;\n\tconst cacheRead = readFiniteNumber(record.cacheRead) ?? 0;\n\tconst cacheWrite = readFiniteNumber(record.cacheWrite) ?? 0;\n\treturn {\n\t\tinput,\n\t\toutput,\n\t\tcacheRead,\n\t\tcacheWrite,\n\t\ttotal: readFiniteNumber(record.total) ?? input + output + cacheRead + cacheWrite,\n\t};\n}\n\nexport function cloneUsageSnapshot(usage: UsageSnapshot | null | undefined): UsageSnapshot | null {\n\tif (!usage) {\n\t\treturn null;\n\t}\n\treturn {\n\t\t...usage,\n\t\tcost: usage.cost ? { ...usage.cost } : null,\n\t};\n}\n\nexport function normalizeUsageSnapshot(value: unknown): UsageSnapshot | null {\n\tconst parsedValue = v.safeParse(unknownRecordSchema, value);\n\tif (!parsedValue.success) {\n\t\treturn null;\n\t}\n\tconst record = parsedValue.output;\n\tconst input = readFiniteNumber(record.input) ?? 0;\n\tconst output = readFiniteNumber(record.output) ?? 0;\n\tconst reasoning = readFiniteNumber(record.reasoning);\n\tconst cacheRead = readFiniteNumber(record.cacheRead) ?? 0;\n\tconst cacheWrite = readFiniteNumber(record.cacheWrite) ?? 0;\n\tconst cost = normalizeUsageCostSnapshot(record.cost);\n\tconst maxInputTokens = readFiniteNumber(record.maxInputTokens);\n\tconst hasExplicitUsageTelemetry =\n\t\t[\"input\", \"output\", \"reasoning\", \"cacheRead\", \"cacheWrite\", \"totalTokens\"].some(\n\t\t\t(key) => readFiniteNumber(record[key]) !== undefined,\n\t\t) || cost !== null;\n\tif (!hasExplicitUsageTelemetry) {\n\t\treturn null;\n\t}\n\treturn {\n\t\tinput,\n\t\toutput,\n\t\t...(reasoning !== undefined ? { reasoning } : {}),\n\t\tcacheRead,\n\t\tcacheWrite,\n\t\ttotalTokens: readFiniteNumber(record.totalTokens) ?? input + output + cacheRead + cacheWrite,\n\t\tcost,\n\t\trequestCount: Math.max(0, Math.floor(readFiniteNumber(record.requestCount) ?? 1)),\n\t\tmaxInputTokens: maxInputTokens !== undefined ? Math.max(0, maxInputTokens) : input,\n\t};\n}\n\nexport function mergeUsageSnapshots(\n\ttotal: UsageSnapshot | null,\n\tusage: UsageSnapshot | null,\n): UsageSnapshot | null {\n\tif (!usage) {\n\t\treturn cloneUsageSnapshot(total);\n\t}\n\tif (!total) {\n\t\treturn cloneUsageSnapshot(usage);\n\t}\n\tconst hasRequestMetrics =\n\t\ttotal.requestCount !== undefined ||\n\t\tusage.requestCount !== undefined ||\n\t\ttotal.maxInputTokens !== undefined ||\n\t\tusage.maxInputTokens !== undefined;\n\treturn {\n\t\tinput: total.input + usage.input,\n\t\toutput: total.output + usage.output,\n\t\t...(total.reasoning !== undefined || usage.reasoning !== undefined\n\t\t\t? { reasoning: (total.reasoning ?? 0) + (usage.reasoning ?? 0) }\n\t\t\t: {}),\n\t\tcacheRead: total.cacheRead + usage.cacheRead,\n\t\tcacheWrite: total.cacheWrite + usage.cacheWrite,\n\t\ttotalTokens: total.totalTokens + usage.totalTokens,\n\t\tcost:\n\t\t\ttotal.cost && usage.cost\n\t\t\t\t? {\n\t\t\t\t\t\tinput: total.cost.input + usage.cost.input,\n\t\t\t\t\t\toutput: total.cost.output + usage.cost.output,\n\t\t\t\t\t\tcacheRead: total.cost.cacheRead + usage.cost.cacheRead,\n\t\t\t\t\t\tcacheWrite: total.cost.cacheWrite + usage.cost.cacheWrite,\n\t\t\t\t\t\ttotal: total.cost.total + usage.cost.total,\n\t\t\t\t\t}\n\t\t\t\t: null,\n\t\t...(hasRequestMetrics\n\t\t\t? {\n\t\t\t\t\trequestCount: (total.requestCount ?? 1) + (usage.requestCount ?? 1),\n\t\t\t\t\tmaxInputTokens: Math.max(\n\t\t\t\t\t\ttotal.maxInputTokens ?? total.input,\n\t\t\t\t\t\tusage.maxInputTokens ?? usage.input,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n}\n","import { asUnknownRecord, trimToNull as readWsEventNonEmptyString } from \"@leitwerk-dev/domain\";\n\nexport interface WsEventPayloadRecord extends Record<string, unknown> {}\n\nexport interface ResolveWsEventToolCallIdOptions {\n\ttimestamp: string;\n\ttoolName?: string;\n\tordinal?: number;\n}\n\nexport function asWsEventPayloadRecord(value: unknown): WsEventPayloadRecord {\n\treturn asUnknownRecord(value) ?? {};\n}\n\nexport { readWsEventNonEmptyString };\n\nexport function readWsEventTimestamp(\n\tdata: WsEventPayloadRecord,\n\tfallbackTimestamp: string,\n): string {\n\treturn readWsEventNonEmptyString(data.timestamp) ?? fallbackTimestamp;\n}\n\nexport function readWsEventTurnRecordId(data: WsEventPayloadRecord): string | null {\n\treturn readWsEventNonEmptyString(data.turnRecordId);\n}\n\nexport function readWsEventPiTurnId(data: WsEventPayloadRecord): string | null {\n\treturn readWsEventNonEmptyString(data.turnId);\n}\n\nexport function readWsEventStreamText(data: WsEventPayloadRecord): string | null {\n\treturn typeof data.text === \"string\"\n\t\t? data.text\n\t\t: typeof data.delta === \"string\"\n\t\t\t? data.delta\n\t\t\t: typeof data.chunk === \"string\"\n\t\t\t\t? data.chunk\n\t\t\t\t: null;\n}\n\nexport function readWsEventToolName(data: WsEventPayloadRecord): string {\n\treturn readWsEventNonEmptyString(data.name) ?? readWsEventNonEmptyString(data.toolName) ?? \"tool\";\n}\n\nexport function readWsEventToolArguments(\n\tdata: WsEventPayloadRecord,\n): Record<string, unknown> | null {\n\treturn asUnknownRecord(data.arguments ?? data.args);\n}\n\nexport function readWsEventToolCallId(data: WsEventPayloadRecord): string | null {\n\treturn readWsEventNonEmptyString(data.toolCallId);\n}\n\nexport function resolveWsEventToolCallId(\n\tdata: WsEventPayloadRecord,\n\toptions: ResolveWsEventToolCallIdOptions,\n): string {\n\treturn (\n\t\treadWsEventToolCallId(data) ??\n\t\t`${options.toolName ?? readWsEventToolName(data)}:${options.timestamp}${options.ordinal ? `:${options.ordinal}` : \"\"}`\n\t);\n}\n","import type {\n\tPrimaryPathActiveTurnSnapshot,\n\tPrimaryPathToolCallSnapshot,\n} from \"./primary-path-snapshot.js\";\nimport {\n\tmergeUsageSnapshots,\n\tnormalizeUsageSnapshot,\n\ttype UsageSnapshot,\n} from \"./usage-snapshot.js\";\nimport {\n\treadWsEventStreamText,\n\treadWsEventTimestamp,\n\treadWsEventToolCallId,\n\treadWsEventToolName,\n} from \"./ws-event-payloads.js\";\n\nexport const REASONING_PREVIEW_MAX_CHARS = 1_024;\n\nexport interface CompactTurnSummary {\n\tassistant: { text: string; thinking: string; lastUpdatedAt: string | null };\n\tcurrentTool: Pick<\n\t\tPrimaryPathToolCallSnapshot,\n\t\t\"toolCallId\" | \"toolName\" | \"status\" | \"isError\"\n\t> | null;\n\tusage: UsageSnapshot | null;\n\ttoolCallCount: number;\n\ttraceItemCount: number;\n\t/** The last persisted event incorporated into this projection. */\n\tthroughEventSequence: number;\n\tlastTraceKind: \"thinking\" | \"tool_call\" | \"operational_event\" | null;\n}\n\n/** Initial-page state. It never contains trace items, tool arguments or results. */\nexport interface CompactActiveTurnSnapshot\n\textends CompactTurnSummary,\n\t\tPick<\n\t\t\tPrimaryPathActiveTurnSnapshot,\n\t\t\t\"turnRecordId\" | \"turnId\" | \"turnType\" | \"pathType\" | \"startedAt\"\n\t\t> {\n\tsummaryPending: boolean;\n}\n\nexport function emptyCompactTurnSummary(): CompactTurnSummary {\n\treturn {\n\t\tassistant: { text: \"\", thinking: \"\", lastUpdatedAt: null },\n\t\tcurrentTool: null,\n\t\tusage: null,\n\t\ttoolCallCount: 0,\n\t\ttraceItemCount: 0,\n\t\tthroughEventSequence: 0,\n\t\tlastTraceKind: null,\n\t};\n}\n\n/** Retain paragraph context; wrapping and blank-line removal belong to the preview viewport. */\nexport function reasoningPreviewTail(text: string): string {\n\tconst normalized = text.replace(/\\r\\n?/g, \"\\n\");\n\tconst lines = normalized.split(\"\\n\").filter((line) => line.trim() !== \"\");\n\tconst separator = /\\n[^\\S\\n]*$/.test(normalized) ? \"\\n\" : \"\";\n\treturn (lines.join(\"\\n\") + separator).slice(-REASONING_PREVIEW_MAX_CHARS);\n}\n\nexport function applyEventToCompactTurnSummary(\n\tprevious: CompactTurnSummary,\n\tevent: {\n\t\teventType: string;\n\t\tdata: Record<string, unknown>;\n\t\tcreatedAt: string;\n\t\teventSequence: number;\n\t},\n): CompactTurnSummary {\n\tif (event.eventSequence <= previous.throughEventSequence) return previous;\n\tconst next = {\n\t\t...previous,\n\t\tassistant: { ...previous.assistant },\n\t\tthroughEventSequence: event.eventSequence,\n\t};\n\tconst { eventType, data } = event;\n\tif (eventType === \"pi.stream.delta\") {\n\t\tconst text = readWsEventStreamText(data);\n\t\tconst key = data.streamType === \"thinking\" ? \"thinking\" : \"text\";\n\t\tnext.assistant[key] = reasoningPreviewTail(next.assistant[key] + text);\n\t\tif (text) next.assistant.lastUpdatedAt = readWsEventTimestamp(data, event.createdAt);\n\t\tif (key === \"thinking\" && text) {\n\t\t\tif (next.lastTraceKind !== \"thinking\") next.traceItemCount++;\n\t\t\tnext.lastTraceKind = \"thinking\";\n\t\t}\n\t} else if (eventType === \"pi.tool.call\" || eventType === \"pi.tool.result\") {\n\t\tconst isResult = eventType === \"pi.tool.result\";\n\t\tconst toolCallId = (readWsEventToolCallId(data) ?? `tool-${event.eventSequence}`).slice(0, 256);\n\t\tif (!isResult) {\n\t\t\tnext.toolCallCount++;\n\t\t\tnext.traceItemCount++;\n\t\t\tnext.lastTraceKind = \"tool_call\";\n\t\t}\n\t\tif (!isResult || !next.currentTool || next.currentTool.toolCallId === toolCallId) {\n\t\t\tnext.currentTool = {\n\t\t\t\ttoolCallId: toolCallId.slice(0, 256),\n\t\t\t\ttoolName: readWsEventToolName(data).slice(0, 256),\n\t\t\t\tstatus: isResult ? \"completed\" : \"running\",\n\t\t\t\tisError: data.isError === true,\n\t\t\t};\n\t\t}\n\t} else if (eventType === \"pi.usage\") {\n\t\tnext.usage = mergeUsageSnapshots(next.usage, normalizeUsageSnapshot(data));\n\t} else if (\n\t\t[\n\t\t\t\"pi.error\",\n\t\t\t\"pi.retry.start\",\n\t\t\t\"pi.retry.end\",\n\t\t\t\"pi.compaction.start\",\n\t\t\t\"pi.compaction.end\",\n\t\t].includes(eventType)\n\t) {\n\t\tnext.traceItemCount++;\n\t\tnext.lastTraceKind = \"operational_event\";\n\t}\n\treturn next;\n}\n","import { isUnknownRecord } from \"@leitwerk-dev/domain\";\nimport * as v from \"valibot\";\n\n// Wire shape only; the catalog validates manifests and hosts check supported versions.\nconst recordSchema = v.custom<Record<string, unknown>>(isUnknownRecord);\nconst versionSchema = v.custom<number>((value) => typeof value === \"number\");\n\nexport const leafOutcomeRendererDescriptorSchema = v.pipe(\n\trecordSchema,\n\tv.object({\n\t\tok: v.literal(true),\n\t\trendererId: v.string(),\n\t\tkind: v.literal(\"custom_element\"),\n\t\ttagName: v.string(),\n\t\tmodulePath: v.string(),\n\t\trendererApiVersion: versionSchema,\n\t\textensionManifestId: v.string(),\n\t\tmoduleUrl: v.string(),\n\t}),\n);\nexport type LeafOutcomeRendererDescriptor = v.InferOutput<\n\ttypeof leafOutcomeRendererDescriptorSchema\n>;\n\nexport const leafOutcomeRendererFailureSchema = v.pipe(\n\trecordSchema,\n\tv.object({\n\t\tok: v.literal(false),\n\t\trendererId: v.string(),\n\t\tcode: v.string(),\n\t\tmessage: v.string(),\n\t}),\n);\nexport type LeafOutcomeRendererFailure = v.InferOutput<typeof leafOutcomeRendererFailureSchema>;\n\nexport const browserUiExtensionDescriptorSchema = v.pipe(\n\trecordSchema,\n\tv.object({\n\t\textensionManifestId: v.string(),\n\t\tmodulePath: v.string(),\n\t\tmoduleUrl: v.string(),\n\t\tbrowserApiVersion: versionSchema,\n\t}),\n);\nexport type BrowserUiExtensionDescriptor = v.InferOutput<typeof browserUiExtensionDescriptorSchema>;\n","import { isUnknownRecord as isRecord } from \"@leitwerk-dev/domain\";\nimport type { FutureExecutionOverviewItem, FutureExecutionSummary } from \"./http-contracts.js\";\n\n// Best-effort extraction of an operator-facing prompt/command from launch params\n// for compact overview and detail read models. Process launchers use several\n// established field names; keep this priority list shared so server and browser\n// projections cannot drift.\nexport const INITIAL_PROMPT_FIELD_PRIORITY = [\n\t\"initialPrompt\",\n\t\"prompt\",\n\t\"taskPrompt\",\n\t\"userPrompt\",\n\t\"instructions\",\n\t\"instruction\",\n\t\"initialCommand\",\n\t\"command\",\n\t\"query\",\n\t\"message\",\n\t\"requestedChange\",\n\t\"request\",\n\t\"description\",\n] as const;\n\nfunction normalizePromptValue(value: string): string | null {\n\tconst normalized = value.replace(/\\s+/g, \" \").trim();\n\treturn normalized.length > 0 ? normalized : null;\n}\n\nexport function truncatePromptPreview(\n\tvalue: string | null | undefined,\n\tmaxLength = 180,\n): string | null {\n\tconst normalized = typeof value === \"string\" ? normalizePromptValue(value) : null;\n\treturn normalized && normalized.length > maxLength\n\t\t? `${normalized.slice(0, maxLength).trimEnd()}…`\n\t\t: normalized;\n}\n\nfunction readStringField(record: Record<string, unknown>, fieldName: string): string | null {\n\tconst exact = record[fieldName];\n\tif (typeof exact === \"string\") {\n\t\treturn exact.trim() ? exact : null;\n\t}\n\n\tconst normalizedFieldName = fieldName.toLowerCase();\n\tfor (const [key, value] of Object.entries(record)) {\n\t\tif (key.toLowerCase() !== normalizedFieldName || typeof value !== \"string\") {\n\t\t\tcontinue;\n\t\t}\n\t\treturn value.trim() ? value : null;\n\t}\n\n\treturn null;\n}\n\nexport function extractInitialPromptFromValue(value: unknown): string | null {\n\tif (!isRecord(value)) {\n\t\treturn null;\n\t}\n\n\tfor (const fieldName of INITIAL_PROMPT_FIELD_PRIORITY) {\n\t\tconst prompt = readStringField(value, fieldName);\n\t\tif (prompt) {\n\t\t\treturn prompt;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function extractInitialPromptFromParamsJson(\n\tparamsJson: string | null | undefined,\n): string | null {\n\tif (!paramsJson) {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\treturn extractInitialPromptFromValue(JSON.parse(paramsJson));\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport function extractInitialPromptPreviewFromParamsJson(\n\tparamsJson: string | null | undefined,\n\tmaxLength = 180,\n): string | null {\n\treturn truncatePromptPreview(extractInitialPromptFromParamsJson(paramsJson), maxLength);\n}\n\nexport function projectFutureExecutionOverview(\n\tsummary: FutureExecutionSummary,\n): FutureExecutionOverviewItem {\n\tconst common = {\n\t\tid: summary.id,\n\t\tscheduleKind: summary.scheduleKind,\n\t\tprocessId: summary.processId,\n\t\tnextRunAt: summary.nextRunAt,\n\t\tcronExpression: summary.cronExpression,\n\t\ttitle: summary.title,\n\t\tstatus: summary.status ?? \"scheduled\",\n\t\tblockedReason: summary.blockedReason ?? null,\n\t\tinitialPromptPreview:\n\t\t\tsummary.kind === \"launch\"\n\t\t\t\t? truncatePromptPreview(extractInitialPromptFromValue(summary.launcherInput))\n\t\t\t\t: null,\n\t};\n\treturn summary.kind === \"action\"\n\t\t? {\n\t\t\t\t...common,\n\t\t\t\tkind: \"action\",\n\t\t\t\tinstanceId: summary.instanceId,\n\t\t\t\tactionId: summary.actionId,\n\t\t\t\tactionLabel: summary.actionLabel,\n\t\t\t}\n\t\t: {\n\t\t\t\t...common,\n\t\t\t\tkind: \"launch\",\n\t\t\t\tinstanceId: null,\n\t\t\t\tlauncherId: summary.launcherId,\n\t\t\t\tlauncherLabel: summary.launcherLabel,\n\t\t\t};\n}\n","import {\n\ttype ProcessEvent,\n\treadFiniteNumber as readNumber,\n\treadNonBlankString as readString,\n} from \"@leitwerk-dev/domain\";\nimport type {\n\tPrimaryPathOperationalTraceItemSnapshot,\n\tPrimaryPathStreamingAssistantSnapshot,\n\tPrimaryPathToolCallSnapshot,\n\tPrimaryPathTraceItemSnapshot,\n} from \"./primary-path-snapshot.js\";\nimport { compareTimestampStrings } from \"./timestamp-ordering.js\";\nimport {\n\tcloneUsageSnapshot,\n\tmergeUsageSnapshots,\n\tnormalizeUsageSnapshot,\n\ttype UsageSnapshot,\n} from \"./usage-snapshot.js\";\nimport {\n\tasWsEventPayloadRecord,\n\treadWsEventNonEmptyString,\n\treadWsEventStreamText,\n\treadWsEventTimestamp,\n\treadWsEventToolArguments,\n\treadWsEventToolCallId,\n\treadWsEventToolName,\n\tresolveWsEventToolCallId,\n\ttype WsEventPayloadRecord,\n} from \"./ws-event-payloads.js\";\n\nexport interface MutableLiveTurnProjection {\n\tassistant: PrimaryPathStreamingAssistantSnapshot;\n\ttoolCalls: PrimaryPathToolCallSnapshot[];\n\ttraceItems: PrimaryPathTraceItemSnapshot[];\n\tusage: UsageSnapshot | null;\n\ttoolCallsById: Map<string, PrimaryPathToolCallSnapshot>;\n\topenToolCallIdsByName: Map<string, string[]>;\n\tnextFallbackOrdinal: number;\n}\n\nexport interface AppliedLiveTurnProjectionEvent {\n\tcanonicalData: WsEventPayloadRecord;\n\ttimestamp: string;\n\ttoolCallId: string | null;\n\ttoolName: string | null;\n}\n\nexport const PRIMARY_PATH_OPERATIONAL_PI_EVENT_TYPES = [\n\t\"pi.error\",\n\t\"pi.retry.start\",\n\t\"pi.retry.end\",\n\t\"pi.compaction.start\",\n\t\"pi.compaction.end\",\n] as const;\n\nconst PRIMARY_PATH_OPERATIONAL_PI_EVENT_TYPE_SET = new Set<string>(\n\tPRIMARY_PATH_OPERATIONAL_PI_EVENT_TYPES,\n);\n\nfunction cloneToolCall(toolCall: PrimaryPathToolCallSnapshot): PrimaryPathToolCallSnapshot {\n\treturn {\n\t\t...toolCall,\n\t\t...(toolCall.arguments ? { arguments: { ...toolCall.arguments } } : {}),\n\t};\n}\n\nfunction formatReason(value: unknown): string | null {\n\tconst reason = readString(value);\n\treturn reason ? reason.replace(/[_-]+/g, \" \") : null;\n}\n\nfunction firstMessage(data: WsEventPayloadRecord, keys: readonly string[]): string | null {\n\tfor (const key of keys) {\n\t\tconst value = readString(data[key]);\n\t\tif (value) {\n\t\t\treturn value;\n\t\t}\n\t}\n\treturn null;\n}\n\nfunction retryStartFallbackMessage(data: WsEventPayloadRecord): string {\n\tconst attempt = readNumber(data.attempt);\n\tconst maxAttempts = readNumber(data.maxAttempts);\n\tconst delayMs = readNumber(data.delayMs);\n\tconst attemptLabel = attempt !== null && maxAttempts !== null ? ` ${attempt}/${maxAttempts}` : \"\";\n\tconst delayLabel = delayMs !== null && delayMs > 0 ? ` in ${delayMs}ms` : \"\";\n\treturn `Retry${attemptLabel} scheduled${delayLabel}.`;\n}\n\nfunction retryEndFallbackMessage(data: WsEventPayloadRecord): string {\n\tconst attempt = readNumber(data.attempt);\n\tif (data.success === true) {\n\t\treturn attempt !== null\n\t\t\t? `Retry sequence succeeded after ${attempt} ${attempt === 1 ? \"retry\" : \"retries\"}.`\n\t\t\t: \"Retry sequence succeeded.\";\n\t}\n\treturn attempt !== null\n\t\t? `Retry sequence ended after ${attempt} ${attempt === 1 ? \"retry\" : \"retries\"}.`\n\t\t: \"Retry sequence ended.\";\n}\n\nexport function buildPrimaryPathOperationalTraceItem(input: {\n\teventType: string;\n\tdata: WsEventPayloadRecord;\n\tfallbackTimestamp: string;\n}): PrimaryPathOperationalTraceItemSnapshot | null {\n\tif (!PRIMARY_PATH_OPERATIONAL_PI_EVENT_TYPE_SET.has(input.eventType)) {\n\t\treturn null;\n\t}\n\tconst timestamp = readWsEventTimestamp(input.data, input.fallbackTimestamp);\n\tif (input.eventType === \"pi.error\") {\n\t\treturn {\n\t\t\tkind: \"operational_event\",\n\t\t\teventType: input.eventType,\n\t\t\tseverity: \"error\",\n\t\t\ttitle: \"Pi request failed\",\n\t\t\tmessage:\n\t\t\t\tfirstMessage(input.data, [\"message\", \"errorMessage\", \"finalError\"]) ??\n\t\t\t\t\"Pi reported an error.\",\n\t\t\ttimestamp,\n\t\t};\n\t}\n\tif (input.eventType === \"pi.retry.start\") {\n\t\treturn {\n\t\t\tkind: \"operational_event\",\n\t\t\teventType: input.eventType,\n\t\t\tseverity: \"warning\",\n\t\t\ttitle: \"Retry scheduled\",\n\t\t\tmessage:\n\t\t\t\tfirstMessage(input.data, [\"message\", \"errorMessage\"]) ??\n\t\t\t\tretryStartFallbackMessage(input.data),\n\t\t\ttimestamp,\n\t\t};\n\t}\n\tif (input.eventType === \"pi.retry.end\") {\n\t\tconst success = input.data.success === true;\n\t\treturn {\n\t\t\tkind: \"operational_event\",\n\t\t\teventType: input.eventType,\n\t\t\tseverity: success ? \"success\" : \"error\",\n\t\t\ttitle: success ? \"Retry succeeded\" : \"Retry exhausted\",\n\t\t\tmessage:\n\t\t\t\tfirstMessage(input.data, [\"message\", \"finalError\", \"errorMessage\"]) ??\n\t\t\t\tretryEndFallbackMessage(input.data),\n\t\t\ttimestamp,\n\t\t};\n\t}\n\tif (input.eventType === \"pi.compaction.start\") {\n\t\tconst reason = formatReason(input.data.reason);\n\t\treturn {\n\t\t\tkind: \"operational_event\",\n\t\t\teventType: input.eventType,\n\t\t\tseverity: \"info\",\n\t\t\ttitle: \"Context compaction started\",\n\t\t\tmessage: reason\n\t\t\t\t? `Pi started compacting context (${reason}).`\n\t\t\t\t: \"Pi started compacting context.\",\n\t\t\ttimestamp,\n\t\t};\n\t}\n\tif (input.eventType === \"pi.compaction.end\") {\n\t\tconst reason = formatReason(input.data.reason);\n\t\tconst errorMessage = firstMessage(input.data, [\"errorMessage\", \"message\"]);\n\t\tconst aborted = input.data.aborted === true;\n\t\tconst willRetry = input.data.willRetry === true;\n\t\tconst statusMessage = errorMessage\n\t\t\t? errorMessage\n\t\t\t: aborted\n\t\t\t\t? \"Context compaction was cancelled.\"\n\t\t\t\t: `Pi compacted context${reason ? ` (${reason})` : \"\"}.${willRetry ? \" Pi will continue automatically.\" : \"\"}`;\n\t\treturn {\n\t\t\tkind: \"operational_event\",\n\t\t\teventType: input.eventType,\n\t\t\tseverity: errorMessage ? \"error\" : aborted ? \"warning\" : \"success\",\n\t\t\ttitle: errorMessage\n\t\t\t\t? \"Context compaction failed\"\n\t\t\t\t: aborted\n\t\t\t\t\t? \"Context compaction cancelled\"\n\t\t\t\t\t: \"Context compacted\",\n\t\t\tmessage: statusMessage,\n\t\t\ttimestamp,\n\t\t};\n\t}\n\treturn null;\n}\n\nfunction addOpenToolCallId(\n\tprojection: MutableLiveTurnProjection,\n\ttoolName: string,\n\ttoolCallId: string,\n) {\n\tconst ids = projection.openToolCallIdsByName.get(toolName) ?? [];\n\tids.push(toolCallId);\n\tprojection.openToolCallIdsByName.set(toolName, ids);\n}\n\nfunction consumeLatestOpenToolCallId(\n\tprojection: MutableLiveTurnProjection,\n\ttoolName: string,\n): string | null {\n\tconst ids = projection.openToolCallIdsByName.get(toolName);\n\tif (!ids || ids.length === 0) {\n\t\treturn null;\n\t}\n\tconst toolCallId = ids.pop() ?? null;\n\tif (ids.length === 0) {\n\t\tprojection.openToolCallIdsByName.delete(toolName);\n\t} else {\n\t\tprojection.openToolCallIdsByName.set(toolName, ids);\n\t}\n\treturn toolCallId;\n}\n\nfunction removeOpenToolCallId(projection: MutableLiveTurnProjection, toolCallId: string) {\n\tfor (const [toolName, ids] of projection.openToolCallIdsByName.entries()) {\n\t\tconst nextIds = ids.filter((candidate) => candidate !== toolCallId);\n\t\tif (nextIds.length === ids.length) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (nextIds.length === 0) {\n\t\t\tprojection.openToolCallIdsByName.delete(toolName);\n\t\t} else {\n\t\t\tprojection.openToolCallIdsByName.set(toolName, nextIds);\n\t\t}\n\t\treturn;\n\t}\n}\n\nfunction canonicalizeToolCallId(input: {\n\tprojection: MutableLiveTurnProjection;\n\tdata: WsEventPayloadRecord;\n\ttimestamp: string;\n\ttoolName: string;\n\tpreferOpenCall: boolean;\n}): string {\n\tconst explicitToolCallId = readWsEventToolCallId(input.data);\n\tif (explicitToolCallId) {\n\t\tif (input.preferOpenCall) {\n\t\t\tremoveOpenToolCallId(input.projection, explicitToolCallId);\n\t\t}\n\t\treturn explicitToolCallId;\n\t}\n\tif (input.preferOpenCall) {\n\t\tconst openToolCallId = consumeLatestOpenToolCallId(input.projection, input.toolName);\n\t\tif (openToolCallId) {\n\t\t\treturn openToolCallId;\n\t\t}\n\t}\n\treturn resolveWsEventToolCallId(input.data, {\n\t\ttimestamp: input.timestamp,\n\t\ttoolName: input.toolName,\n\t\tordinal: input.projection.nextFallbackOrdinal++,\n\t});\n}\n\nfunction appendThinkingTraceText(projection: MutableLiveTurnProjection, text: string): void {\n\tif (text.length === 0) {\n\t\treturn;\n\t}\n\tconst lastTraceItem = projection.traceItems.at(-1);\n\tif (lastTraceItem?.kind === \"thinking\") {\n\t\tlastTraceItem.text += text;\n\t\treturn;\n\t}\n\tprojection.traceItems.push({\n\t\tkind: \"thinking\",\n\t\ttext,\n\t});\n}\n\nfunction ensureToolTraceItem(projection: MutableLiveTurnProjection, toolCallId: string): void {\n\tif (\n\t\tprojection.traceItems.some(\n\t\t\t(traceItem) => traceItem.kind === \"tool_call\" && traceItem.toolCallId === toolCallId,\n\t\t)\n\t) {\n\t\treturn;\n\t}\n\tprojection.traceItems.push({\n\t\tkind: \"tool_call\",\n\t\ttoolCallId,\n\t});\n}\n\nexport function createMutableLiveTurnProjection(): MutableLiveTurnProjection {\n\treturn {\n\t\tassistant: {\n\t\t\ttext: \"\",\n\t\t\tthinking: \"\",\n\t\t\tlastUpdatedAt: null,\n\t\t},\n\t\ttoolCalls: [],\n\t\ttraceItems: [],\n\t\tusage: null,\n\t\ttoolCallsById: new Map<string, PrimaryPathToolCallSnapshot>(),\n\t\topenToolCallIdsByName: new Map<string, string[]>(),\n\t\tnextFallbackOrdinal: 1,\n\t};\n}\n\nexport function snapshotLiveTurnProjection(projection: MutableLiveTurnProjection): {\n\tassistant: PrimaryPathStreamingAssistantSnapshot;\n\ttoolCalls: PrimaryPathToolCallSnapshot[];\n\ttraceItems: PrimaryPathTraceItemSnapshot[];\n\tusage: UsageSnapshot | null;\n} {\n\treturn {\n\t\tassistant: { ...projection.assistant },\n\t\ttoolCalls: projection.toolCalls.map(cloneToolCall),\n\t\ttraceItems: projection.traceItems.map((item) => ({ ...item })),\n\t\tusage: cloneUsageSnapshot(projection.usage),\n\t};\n}\n\nexport function applyPiEventToLiveTurnProjection(\n\tprojection: MutableLiveTurnProjection,\n\tinput: {\n\t\teventType: string;\n\t\tdata: WsEventPayloadRecord;\n\t\tfallbackTimestamp: string;\n\t},\n): AppliedLiveTurnProjectionEvent {\n\tlet timestamp = readWsEventTimestamp(input.data, input.fallbackTimestamp);\n\tif (input.eventType === \"pi.stream.delta\") {\n\t\tconst text = readWsEventStreamText(input.data);\n\t\tif (text) {\n\t\t\tif (readWsEventNonEmptyString(input.data.streamType) === \"thinking\") {\n\t\t\t\tprojection.assistant.thinking += text;\n\t\t\t\tappendThinkingTraceText(projection, text);\n\t\t\t} else {\n\t\t\t\tprojection.assistant.text += text;\n\t\t\t}\n\t\t\tprojection.assistant.lastUpdatedAt = timestamp;\n\t\t}\n\t} else if (input.eventType === \"pi.tool.call\" || input.eventType === \"pi.tool.result\") {\n\t\tconst isResult = input.eventType === \"pi.tool.result\";\n\t\tconst toolName = readWsEventToolName(input.data);\n\t\tconst toolCallId = canonicalizeToolCallId({\n\t\t\tprojection,\n\t\t\tdata: input.data,\n\t\t\ttimestamp,\n\t\t\ttoolName,\n\t\t\tpreferOpenCall: isResult,\n\t\t});\n\t\tconst canonicalData =\n\t\t\treadWsEventToolCallId(input.data) === toolCallId ? input.data : { ...input.data, toolCallId };\n\t\tconst existingToolCall = projection.toolCallsById.get(toolCallId);\n\t\tconst toolCall: PrimaryPathToolCallSnapshot = existingToolCall ?? {\n\t\t\ttoolCallId,\n\t\t\ttoolName,\n\t\t\tstatus: \"running\",\n\t\t\tstartedAt: timestamp,\n\t\t\tcompletedAt: null,\n\t\t\targuments: isResult ? null : readWsEventToolArguments(canonicalData),\n\t\t\tresult: null,\n\t\t\tisError: false,\n\t\t};\n\t\tif (!existingToolCall) {\n\t\t\tprojection.toolCalls.push(toolCall);\n\t\t\tprojection.toolCallsById.set(toolCallId, toolCall);\n\t\t}\n\t\tif (isResult) {\n\t\t\ttoolCall.status = \"completed\";\n\t\t\ttoolCall.completedAt = timestamp;\n\t\t\ttoolCall.result = canonicalData.result ?? null;\n\t\t\ttoolCall.isError = canonicalData.isError === true;\n\t\t\tif (existingToolCall) removeOpenToolCallId(projection, toolCallId);\n\t\t}\n\t\tensureToolTraceItem(projection, toolCallId);\n\t\tif (!isResult) addOpenToolCallId(projection, toolName, toolCallId);\n\t\treturn {\n\t\t\tcanonicalData,\n\t\t\ttimestamp,\n\t\t\ttoolCallId,\n\t\t\ttoolName,\n\t\t};\n\t} else if (input.eventType === \"pi.usage\") {\n\t\tprojection.usage = mergeUsageSnapshots(projection.usage, normalizeUsageSnapshot(input.data));\n\t} else {\n\t\tconst operationalTraceItem = buildPrimaryPathOperationalTraceItem({\n\t\t\teventType: input.eventType,\n\t\t\tdata: input.data,\n\t\t\tfallbackTimestamp: input.fallbackTimestamp,\n\t\t});\n\t\tif (operationalTraceItem) {\n\t\t\tprojection.traceItems.push(operationalTraceItem);\n\t\t\ttimestamp = operationalTraceItem.timestamp;\n\t\t}\n\t}\n\n\treturn {\n\t\tcanonicalData: input.data,\n\t\ttimestamp,\n\t\ttoolCallId: null,\n\t\ttoolName: null,\n\t};\n}\n\nfunction compareProcessEventsChronologically(left: ProcessEvent, right: ProcessEvent): number {\n\tif (left.eventSequence !== undefined && right.eventSequence !== undefined) {\n\t\treturn left.eventSequence - right.eventSequence;\n\t}\n\tconst leftTimestamp = readWsEventTimestamp(asWsEventPayloadRecord(left.data), left.createdAt);\n\tconst rightTimestamp = readWsEventTimestamp(asWsEventPayloadRecord(right.data), right.createdAt);\n\tconst timestampComparison = compareTimestampStrings(leftTimestamp, rightTimestamp);\n\tif (timestampComparison !== 0) {\n\t\treturn timestampComparison;\n\t}\n\tconst createdAtComparison = compareTimestampStrings(left.createdAt, right.createdAt);\n\tif (createdAtComparison !== 0) {\n\t\treturn createdAtComparison;\n\t}\n\treturn left.id.localeCompare(right.id);\n}\n\nexport function buildLiveTurnProjectionFromEvents(\n\tevents: readonly ProcessEvent[],\n): MutableLiveTurnProjection {\n\tconst projection = createMutableLiveTurnProjection();\n\tfor (const event of [...events].sort(compareProcessEventsChronologically)) {\n\t\tapplyPiEventToLiveTurnProjection(projection, {\n\t\t\teventType: event.eventType,\n\t\t\tdata: asWsEventPayloadRecord(event.data),\n\t\t\tfallbackTimestamp: event.createdAt,\n\t\t});\n\t}\n\treturn projection;\n}\n","export function compareTimestampStrings(left: string, right: string): number {\n\tconst leftMs = Date.parse(left);\n\tconst rightMs = Date.parse(right);\n\tif (Number.isFinite(leftMs) && Number.isFinite(rightMs)) {\n\t\treturn leftMs - rightMs;\n\t}\n\treturn left.localeCompare(right);\n}\n\nexport function happenedOnOrAfterStart(entryTimestamp: string, startedAt: string | null): boolean {\n\tif (!startedAt) {\n\t\treturn true;\n\t}\n\treturn compareTimestampStrings(entryTimestamp, startedAt) >= 0;\n}\n","export interface PiSessionMessageLike {\n\trole?: unknown;\n\tcontent?: unknown;\n\tdetails?: unknown;\n\ttoolCallId?: unknown;\n\ttoolName?: unknown;\n\tisError?: unknown;\n\tusage?: unknown;\n}\n\nexport interface PiSessionMessageEntryLike {\n\ttype?: unknown;\n\tmessage?: unknown;\n}\n\nexport function isPiSessionMessageEntryType<TEntry extends { type?: unknown }>(\n\tentry: TEntry | undefined,\n): entry is TEntry & { type: \"message\" } {\n\treturn entry?.type === \"message\";\n}\n\nexport function isPiSessionMessageRecord(value: unknown): value is PiSessionMessageLike {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nexport function isPiSessionMessageEntryWithRecord<TEntry extends PiSessionMessageEntryLike>(\n\tentry: TEntry | undefined,\n): entry is TEntry & { type: \"message\"; message: NonNullable<TEntry[\"message\"]> } {\n\treturn isPiSessionMessageEntryType(entry) && isPiSessionMessageRecord(entry.message);\n}\n\nexport function extractPiSessionMessageText(content: unknown): string {\n\tif (typeof content === \"string\") {\n\t\treturn content;\n\t}\n\tif (!Array.isArray(content)) {\n\t\treturn \"\";\n\t}\n\treturn content\n\t\t.map((block) => {\n\t\t\tif (typeof block !== \"object\" || block === null || Array.isArray(block)) {\n\t\t\t\treturn \"\";\n\t\t\t}\n\t\t\tconst record = block as { type?: unknown; text?: unknown };\n\t\t\treturn record.type === \"text\" && typeof record.text === \"string\" ? record.text : \"\";\n\t\t})\n\t\t.join(\"\");\n}\n","export interface SessionTreeEntryLike {\n\tid: string;\n\tparentId: string | null;\n\ttimestamp: string;\n\ttype: string;\n}\n\nexport interface ReadonlyEntryTree<TEntry extends SessionTreeEntryLike> {\n\tentries: TEntry[];\n\tleafId: string | null;\n\tgetEntry(id: string): TEntry | undefined;\n\tgetChildren(parentId: string): TEntry[];\n\tgetBranch(fromId?: string | null): TEntry[];\n}\n\nexport function createReadonlyEntryTree<TEntry extends SessionTreeEntryLike>(\n\tentries: readonly TEntry[],\n): ReadonlyEntryTree<TEntry> {\n\tconst orderedEntries = [...entries];\n\tconst entriesById = new Map(orderedEntries.map((entry) => [entry.id, entry]));\n\tconst childrenByParentId = new Map<string, TEntry[]>();\n\n\tfor (const entry of orderedEntries) {\n\t\tif (typeof entry.parentId !== \"string\" || entry.parentId.trim() === \"\") {\n\t\t\tcontinue;\n\t\t}\n\t\tconst siblings = childrenByParentId.get(entry.parentId) ?? [];\n\t\tsiblings.push(entry);\n\t\tchildrenByParentId.set(entry.parentId, siblings);\n\t}\n\n\tconst leafId = orderedEntries.at(-1)?.id ?? null;\n\n\tconst getEntry = (id: string): TEntry | undefined => entriesById.get(id);\n\tconst getChildren = (parentId: string): TEntry[] =>\n\t\t(childrenByParentId.get(parentId) ?? []).slice();\n\tconst getBranch = (fromId?: string | null): TEntry[] => {\n\t\tconst resolvedFromId = fromId ?? leafId ?? undefined;\n\t\tif (!resolvedFromId) {\n\t\t\treturn [];\n\t\t}\n\t\tconst branch: TEntry[] = [];\n\t\tconst visited = new Set<string>();\n\t\tlet currentEntry = entriesById.get(resolvedFromId);\n\t\twhile (currentEntry) {\n\t\t\tif (visited.has(currentEntry.id)) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tvisited.add(currentEntry.id);\n\t\t\tbranch.unshift(currentEntry);\n\t\t\tcurrentEntry = currentEntry.parentId ? entriesById.get(currentEntry.parentId) : undefined;\n\t\t}\n\t\treturn branch;\n\t};\n\n\treturn {\n\t\tentries: orderedEntries,\n\t\tleafId,\n\t\tgetEntry,\n\t\tgetChildren,\n\t\tgetBranch,\n\t};\n}\n","export const STREAMABLE_WORKER_EVENT_TYPES = [\n\t\"pi.stream.delta\",\n\t\"pi.turn.start\",\n\t\"pi.turn.end\",\n\t\"pi.tool.call\",\n\t\"pi.tool.result\",\n\t\"pi.label.changed\",\n\t\"pi.error\",\n\t\"pi.retry.start\",\n\t\"pi.retry.end\",\n\t\"pi.usage\",\n\t\"pi.compaction.start\",\n\t\"pi.compaction.end\",\n] as const;\n\nexport type StreamableWorkerEventType = (typeof STREAMABLE_WORKER_EVENT_TYPES)[number];\n\nconst STREAMABLE_EVENT_TYPES = new Set<string>(STREAMABLE_WORKER_EVENT_TYPES);\n\nexport function isStreamableEvent(eventType: string): eventType is StreamableWorkerEventType {\n\treturn STREAMABLE_EVENT_TYPES.has(eventType);\n}\n","export interface TextPreview {\n\ttext: string;\n\ttruncated: boolean;\n}\n\nexport function truncateTextPreview(value: string, maxLength: number): TextPreview {\n\treturn value.length <= maxLength\n\t\t? { text: value, truncated: false }\n\t\t: { text: value.slice(0, maxLength).trimEnd(), truncated: true };\n}\n\nexport function buildTrailingLinePreview(\n\tvalue: string,\n\tlineCount: number,\n\tmaxLength: number,\n): TextPreview {\n\tconst lines = value.replace(/\\r\\n?/g, \"\\n\").split(\"\\n\");\n\tif (lines.length === 1 && lines[0] === \"\") return { text: \"\", truncated: false };\n\n\tlet text = lines.slice(-lineCount).join(\"\\n\");\n\tlet truncated = lines.length > lineCount;\n\tif (text.length > maxLength) {\n\t\ttext = text.slice(-maxLength);\n\t\ttruncated = true;\n\t}\n\tif (truncated) {\n\t\tconst previewLines = text.split(\"\\n\");\n\t\tpreviewLines[0] = previewLines[0] ? `… ${previewLines[0]}` : \"…\";\n\t\ttext = previewLines.join(\"\\n\");\n\t}\n\treturn { text, truncated };\n}\n","import type {\n\tProcessTimelineTurnPresentation,\n\tProcessTimelineTurnSummary,\n} from \"./http-contracts.js\";\nimport type { PrimaryPathActiveTurnSnapshot } from \"./primary-path-snapshot.js\";\n\nexport function timelinePresentationForTurnType(\n\tturnType: ProcessTimelineTurnSummary[\"turnType\"],\n): ProcessTimelineTurnPresentation {\n\tif (turnType === \"external\") return \"external_trigger\";\n\tif (turnType === \"human\") return \"operator_decision\";\n\treturn turnType === \"automatic\" ? \"automatic_turn\" : \"llm_turn\";\n}\n\nexport function buildActiveTimelineTurnSummary(\n\tactiveTurn: Pick<\n\t\tPrimaryPathActiveTurnSnapshot,\n\t\t\"turnRecordId\" | \"turnId\" | \"turnType\" | \"pathType\" | \"startedAt\" | \"assistant\"\n\t>,\n\tinput: {\n\t\tsummary: string;\n\t\toutput: string;\n\t\tactionSource?: ProcessTimelineTurnSummary[\"actionSource\"];\n\t} = { summary: `Current step: ${activeTurn.turnId}`, output: activeTurn.assistant.text.trim() },\n): ProcessTimelineTurnSummary {\n\treturn {\n\t\tid: activeTurn.turnRecordId,\n\t\tturnId: activeTurn.turnId,\n\t\tturnType: activeTurn.turnType,\n\t\tdisplayTurn: activeTurn.turnId,\n\t\toutcome: \"in_progress\",\n\t\tsummary: input.summary,\n\t\toutput: input.output,\n\t\tturnResultMarkdown: \"\",\n\t\tpathType: activeTurn.pathType,\n\t\tcreatedAt: activeTurn.startedAt,\n\t\tpresentation: timelinePresentationForTurnType(activeTurn.turnType),\n\t\tstatus: \"in_progress\",\n\t\tmodelProfileId: null,\n\t\tattemptNumber: 1,\n\t\tparentTurnRecordId: null,\n\t\tstartedAt: activeTurn.startedAt,\n\t\tendedAt: null,\n\t\tactionSource: input.actionSource ?? null,\n\t\tprogress: null,\n\t};\n}\n","import { asUnknownRecord } from \"@leitwerk-dev/domain\";\n\nconst TOOL_TRUNCATION_BOOLEAN_KEYS = [\n\t\"truncated\",\n\t\"isTruncated\",\n\t\"wasTruncated\",\n\t\"outputTruncated\",\n\t\"resultTruncated\",\n] as const;\nconst TOOL_TRUNCATION_TEXT_MARKERS = [\n\t\"output truncated\",\n\t\"result truncated\",\n\t\"response was too big\",\n\t\"too large to display\",\n\t\"truncated after\",\n\t\"truncated to last\",\n\t\"truncated since\",\n] as const;\n\nfunction readTruncationPayload(value: unknown): unknown {\n\tconst record = asUnknownRecord(value);\n\tif (!record) {\n\t\treturn null;\n\t}\n\tif (\"truncation\" in record) {\n\t\treturn record.truncation;\n\t}\n\tfor (const key of TOOL_TRUNCATION_BOOLEAN_KEYS) {\n\t\tif (key in record) {\n\t\t\treturn record[key];\n\t\t}\n\t}\n\treturn null;\n}\n\nfunction isExplicitFalseTruncationString(value: string): boolean {\n\tconst normalized = value.trim().toLowerCase();\n\treturn (\n\t\tnormalized === \"\" ||\n\t\tnormalized === \"false\" ||\n\t\tnormalized === \"none\" ||\n\t\tnormalized === \"null\" ||\n\t\tnormalized === \"no\" ||\n\t\tnormalized === \"0\"\n\t);\n}\n\nfunction isTruthyTruncationValue(value: unknown): boolean {\n\tif (value === null || value === undefined) {\n\t\treturn false;\n\t}\n\tif (typeof value === \"boolean\") {\n\t\treturn value;\n\t}\n\tif (typeof value === \"number\") {\n\t\treturn Number.isFinite(value) && value > 0;\n\t}\n\tif (typeof value === \"string\") {\n\t\treturn !isExplicitFalseTruncationString(value);\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.length > 0;\n\t}\n\tconst record = asUnknownRecord(value);\n\tif (!record) {\n\t\treturn true;\n\t}\n\tfor (const key of TOOL_TRUNCATION_BOOLEAN_KEYS) {\n\t\tif (record[key] === true) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn Object.keys(record).some((key) => {\n\t\tif (\n\t\t\tTOOL_TRUNCATION_BOOLEAN_KEYS.includes(key as (typeof TOOL_TRUNCATION_BOOLEAN_KEYS)[number])\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\treturn isTruthyTruncationValue(record[key]);\n\t});\n}\n\nexport function isToolResultTruncated(input: {\n\tresultText: string | null;\n\tresultDetails: unknown;\n\tresultValue: unknown;\n}): boolean {\n\tconst normalizedText = input.resultText?.toLowerCase() ?? \"\";\n\treturn (\n\t\tTOOL_TRUNCATION_TEXT_MARKERS.some((marker) => normalizedText.includes(marker)) ||\n\t\tisTruthyTruncationValue(readTruncationPayload(input.resultDetails)) ||\n\t\tisTruthyTruncationValue(readTruncationPayload(input.resultValue))\n\t);\n}\n","import { trimToNull } from \"@leitwerk-dev/domain\";\nimport {\n\textractPiSessionMessageText,\n\tisPiSessionMessageEntryType,\n\tisPiSessionMessageEntryWithRecord,\n} from \"./pi-session-message.js\";\nimport type { ReadonlyEntryTree } from \"./session-entry-tree.js\";\nimport { compareTimestampStrings, happenedOnOrAfterStart } from \"./timestamp-ordering.js\";\n\nexport interface ContinuationTreeEntry {\n\tid: string;\n\tparentId: string | null;\n\ttimestamp: string;\n\ttype: string;\n\tmessage?: {\n\t\trole?: string;\n\t\tcontent?: unknown;\n\t};\n}\n\nexport interface ContinuationTurnRecordLike {\n\tforkPiEntryId?: string | null;\n\tresultPiEntryId?: string | null;\n\tstartedAt?: string | null;\n\tstatus?: string | null;\n}\n\nexport interface ContinuationSliceBounds {\n\tendedAt?: string | null;\n}\n\nexport interface TurnContinuationIndex<TEntry extends ContinuationTreeEntry> {\n\tresolveLeafEntryId(\n\t\tturnRecord: ContinuationTurnRecordLike,\n\t\tbounds?: ContinuationSliceBounds,\n\t): string | null;\n\tbuildSlice(turnRecord: ContinuationTurnRecordLike, bounds?: ContinuationSliceBounds): TEntry[];\n}\n\nfunction branchContainsAncestor(\n\tentriesById: ReadonlyMap<string, ContinuationTreeEntry>,\n\tentryId: string,\n\tancestorId: string,\n): boolean {\n\tconst visited = new Set<string>();\n\tlet current = entriesById.get(entryId);\n\twhile (current) {\n\t\tif (visited.has(current.id)) {\n\t\t\treturn false;\n\t\t}\n\t\tvisited.add(current.id);\n\t\tif (current.id === ancestorId) {\n\t\t\treturn true;\n\t\t}\n\t\tcurrent = current.parentId ? entriesById.get(current.parentId) : undefined;\n\t}\n\treturn false;\n}\n\nfunction happenedOnOrBeforeEnd(entryTimestamp: string, endedAt: string | null): boolean {\n\tif (!endedAt) {\n\t\treturn true;\n\t}\n\treturn compareTimestampStrings(entryTimestamp, endedAt) <= 0;\n}\n\nfunction isContinuableEntryWithinBounds(\n\tentry: ContinuationTreeEntry | undefined,\n\tstartedAt: string | null,\n\tendedAt: string | null,\n): entry is ContinuationTreeEntry {\n\treturn (\n\t\t(isPiSessionMessageEntryType(entry) || entry?.type === \"compaction\") &&\n\t\thappenedOnOrAfterStart(entry.timestamp, startedAt) &&\n\t\thappenedOnOrBeforeEnd(entry.timestamp, endedAt)\n\t);\n}\n\nfunction isExplicitLeafUsable(\n\tentriesById: ReadonlyMap<string, ContinuationTreeEntry>,\n\tleafId: string,\n\tforkPiEntryId: string | null,\n\tstartedAt: string | null,\n\tendedAt: string | null,\n): boolean {\n\tconst leafEntry = entriesById.get(leafId);\n\tif (!isContinuableEntryWithinBounds(leafEntry, startedAt, endedAt)) {\n\t\treturn false;\n\t}\n\treturn !forkPiEntryId || branchContainsAncestor(entriesById, leafId, forkPiEntryId);\n}\n\nfunction findLatestContinuableEntryIdOnBranch(\n\tentries: readonly ContinuationTreeEntry[],\n\tentriesById: ReadonlyMap<string, ContinuationTreeEntry>,\n\toptions: { startedAt: string | null; endedAt: string | null; ancestorId: string | null },\n): string | null {\n\tfor (let index = entries.length - 1; index >= 0; index -= 1) {\n\t\tconst entry = entries[index];\n\t\tif (!isContinuableEntryWithinBounds(entry, options.startedAt, options.endedAt)) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (options.ancestorId && !branchContainsAncestor(entriesById, entry.id, options.ancestorId)) {\n\t\t\tcontinue;\n\t\t}\n\t\treturn entry.id;\n\t}\n\treturn null;\n}\n\nfunction resolveTurnContinuationLeafEntryIdFromIndex(\n\tentries: readonly ContinuationTreeEntry[],\n\tentriesById: ReadonlyMap<string, ContinuationTreeEntry>,\n\tturnRecord: ContinuationTurnRecordLike,\n\tbounds: ContinuationSliceBounds = {},\n): string | null {\n\tconst startedAt = trimToNull(turnRecord.startedAt);\n\tconst endedAt = trimToNull(bounds.endedAt);\n\tconst forkPiEntryId = trimToNull(turnRecord.forkPiEntryId);\n\tconst explicitLeafId = trimToNull(turnRecord.resultPiEntryId);\n\tif (\n\t\texplicitLeafId &&\n\t\tisExplicitLeafUsable(entriesById, explicitLeafId, forkPiEntryId, startedAt, endedAt)\n\t) {\n\t\tif (turnRecord.status !== \"failed\") {\n\t\t\treturn explicitLeafId;\n\t\t}\n\t\treturn findLatestContinuableEntryIdOnBranch(entries, entriesById, {\n\t\t\tstartedAt,\n\t\t\tendedAt,\n\t\t\tancestorId: explicitLeafId,\n\t\t});\n\t}\n\n\treturn findLatestContinuableEntryIdOnBranch(entries, entriesById, {\n\t\tstartedAt,\n\t\tendedAt,\n\t\tancestorId: forkPiEntryId,\n\t});\n}\n\nexport function createTurnContinuationIndex<TEntry extends ContinuationTreeEntry>(\n\tentries: readonly TEntry[],\n): TurnContinuationIndex<TEntry> {\n\tconst entriesById = new Map(entries.map((entry) => [entry.id, entry]));\n\n\tconst resolveLeafEntryId = (\n\t\tturnRecord: ContinuationTurnRecordLike,\n\t\tbounds: ContinuationSliceBounds = {},\n\t): string | null =>\n\t\tresolveTurnContinuationLeafEntryIdFromIndex(entries, entriesById, turnRecord, bounds);\n\n\tconst buildSlice = (\n\t\tturnRecord: ContinuationTurnRecordLike,\n\t\tbounds: ContinuationSliceBounds = {},\n\t): TEntry[] => {\n\t\tconst continuationLeafId = resolveLeafEntryId(turnRecord, bounds);\n\t\tif (!continuationLeafId) {\n\t\t\treturn [];\n\t\t}\n\t\tconst forkPiEntryId = trimToNull(turnRecord.forkPiEntryId);\n\t\tconst reversedSlice: TEntry[] = [];\n\t\tconst visited = new Set<string>();\n\t\tlet current = entriesById.get(continuationLeafId);\n\t\tlet foundFork = forkPiEntryId === null;\n\t\twhile (current && !visited.has(current.id)) {\n\t\t\tvisited.add(current.id);\n\t\t\tif (current.id === forkPiEntryId) {\n\t\t\t\tfoundFork = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\treversedSlice.push(current);\n\t\t\tcurrent = current.parentId ? entriesById.get(current.parentId) : undefined;\n\t\t}\n\t\tif (!foundFork) {\n\t\t\treturn [];\n\t\t}\n\t\tconst startedAt = trimToNull(turnRecord.startedAt);\n\t\tconst endedAt = trimToNull(bounds.endedAt);\n\t\treturn reversedSlice\n\t\t\t.reverse()\n\t\t\t.filter(\n\t\t\t\t(entry) =>\n\t\t\t\t\thappenedOnOrAfterStart(entry.timestamp, startedAt) &&\n\t\t\t\t\thappenedOnOrBeforeEnd(entry.timestamp, endedAt),\n\t\t\t);\n\t};\n\n\treturn { resolveLeafEntryId, buildSlice };\n}\n\nexport function resolveTurnContinuationLeafEntryId(\n\tentries: readonly ContinuationTreeEntry[],\n\tturnRecord: ContinuationTurnRecordLike,\n\tbounds: ContinuationSliceBounds = {},\n): string | null {\n\treturn createTurnContinuationIndex(entries).resolveLeafEntryId(turnRecord, bounds);\n}\n\nexport function buildTurnContinuationSliceFromTree<TEntry extends ContinuationTreeEntry>(\n\ttree: ReadonlyEntryTree<TEntry>,\n\tturnRecord: ContinuationTurnRecordLike,\n\tbounds: ContinuationSliceBounds = {},\n): TEntry[] {\n\treturn createTurnContinuationIndex(tree.entries).buildSlice(turnRecord, bounds);\n}\n\nexport function buildTurnContinuationSlice<TEntry extends ContinuationTreeEntry>(\n\tentries: readonly TEntry[],\n\tturnRecord: ContinuationTurnRecordLike,\n\tbounds: ContinuationSliceBounds = {},\n): TEntry[] {\n\treturn createTurnContinuationIndex(entries).buildSlice(turnRecord, bounds);\n}\n\nexport interface BranchUserPromptSnapshot {\n\ttext: string | null;\n\tcreatedAt: string | null;\n}\n\nexport function extractFirstUserPromptOnBranch<TEntry extends ContinuationTreeEntry>(\n\ttree: ReadonlyEntryTree<TEntry>,\n\tleafId: string | null | undefined,\n): BranchUserPromptSnapshot {\n\tconst resolvedLeafId = trimToNull(leafId);\n\tif (!resolvedLeafId) {\n\t\treturn { text: null, createdAt: null };\n\t}\n\tconst branch = tree.getBranch(resolvedLeafId);\n\tfor (const entry of branch) {\n\t\tif (!isPiSessionMessageEntryWithRecord(entry) || entry.message.role !== \"user\") {\n\t\t\tcontinue;\n\t\t}\n\t\tconst text = extractPiSessionMessageText(entry.message.content).trim();\n\t\tif (text === \"\") {\n\t\t\tcontinue;\n\t\t}\n\t\treturn {\n\t\t\ttext,\n\t\t\tcreatedAt: entry.timestamp,\n\t\t};\n\t}\n\treturn { text: null, createdAt: null };\n}\n\nexport function resolveTurnContinuationUserPrompt(\n\tentries: readonly ContinuationTreeEntry[],\n\tturnRecord: ContinuationTurnRecordLike,\n\tbounds: ContinuationSliceBounds = {},\n): string | null {\n\tconst continuationLeafId = resolveTurnContinuationLeafEntryId(entries, turnRecord, bounds);\n\tif (!continuationLeafId) {\n\t\treturn null;\n\t}\n\tconst continuationLeaf = new Map(entries.map((entry) => [entry.id, entry])).get(\n\t\tcontinuationLeafId,\n\t);\n\tif (\n\t\t!isPiSessionMessageEntryWithRecord(continuationLeaf) ||\n\t\tcontinuationLeaf.message.role !== \"user\"\n\t) {\n\t\treturn null;\n\t}\n\tconst promptText = extractPiSessionMessageText(continuationLeaf.message.content).trim();\n\treturn promptText !== \"\" ? promptText : null;\n}\n\nexport function hasTurnContinuationProgress(\n\tentries: readonly ContinuationTreeEntry[],\n\tturnRecord: ContinuationTurnRecordLike,\n\tbounds: ContinuationSliceBounds = {},\n): boolean {\n\treturn resolveTurnContinuationLeafEntryId(entries, turnRecord, bounds) !== null;\n}\n","import type { TurnTraceSnapshot } from \"./http-contracts.js\";\nimport {\n\ttype MutableLiveTurnProjection,\n\tsnapshotLiveTurnProjection,\n} from \"./live-turn-projection.js\";\nimport { extractPiSessionMessageText } from \"./pi-session-message.js\";\nimport { isToolResultTruncated } from \"./tool-result-truncation.js\";\n\n/** Share the recorded tool content presentation between live HTTP history and live frames. */\nexport function snapshotTurnTrace(\n\tprojection: MutableLiveTurnProjection,\n\tpiInput: TurnTraceSnapshot[\"piInput\"] = null,\n): TurnTraceSnapshot {\n\tconst snapshot = snapshotLiveTurnProjection(projection);\n\treturn {\n\t\t...snapshot,\n\t\tpiInput,\n\t\ttoolCalls: snapshot.toolCalls.map(({ result, ...tool }) => {\n\t\t\tconst record =\n\t\t\t\tresult && typeof result === \"object\" ? (result as Record<string, unknown>) : null;\n\t\t\tconst resultText =\n\t\t\t\tresult == null\n\t\t\t\t\t? null\n\t\t\t\t\t: typeof result === \"string\"\n\t\t\t\t\t\t? result\n\t\t\t\t\t\t: record && \"content\" in record\n\t\t\t\t\t\t\t? extractPiSessionMessageText(record.content)\n\t\t\t\t\t\t\t: JSON.stringify(result, null, 2);\n\t\t\treturn {\n\t\t\t\t...tool,\n\t\t\t\tresultText,\n\t\t\t\ttruncated:\n\t\t\t\t\t(\"truncated\" in tool && tool.truncated === true) ||\n\t\t\t\t\tisToolResultTruncated({\n\t\t\t\t\t\tresultText,\n\t\t\t\t\t\tresultDetails: record?.details,\n\t\t\t\t\t\tresultValue: result,\n\t\t\t\t\t}),\n\t\t\t};\n\t\t}),\n\t};\n}\n","import type { ProcessEvent } from \"@leitwerk-dev/domain\";\nimport {\n\tmergeUsageSnapshots,\n\tnormalizeUsageSnapshot,\n\ttype UsageSnapshot,\n} from \"./usage-snapshot.js\";\nimport { asWsEventPayloadRecord, readWsEventTurnRecordId } from \"./ws-event-payloads.js\";\n\nexport type UsageSnapshotByTurnRecordId = Record<string, UsageSnapshot>;\n\nexport function buildUsageSnapshotsByTurnRecordId(\n\tevents: readonly ProcessEvent[],\n): UsageSnapshotByTurnRecordId {\n\tconst snapshots: UsageSnapshotByTurnRecordId = {};\n\tfor (const event of events) {\n\t\tif (event.eventType !== \"pi.usage\") {\n\t\t\tcontinue;\n\t\t}\n\t\tconst payload = asWsEventPayloadRecord(event.data);\n\t\tconst turnRecordId = readWsEventTurnRecordId(payload);\n\t\tif (!turnRecordId) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst usage = normalizeUsageSnapshot(payload);\n\t\tif (!usage) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst merged = mergeUsageSnapshots(snapshots[turnRecordId] ?? null, usage);\n\t\tif (merged) {\n\t\t\tsnapshots[turnRecordId] = merged;\n\t\t}\n\t}\n\treturn snapshots;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,6BAA6BA,4BAA2B;AACjE,YAAY,OAAO;AA4BnB,SAAS,iBAAiB,OAAoC;AAC7D,SAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ;AACtE;AAEA,SAAS,2BAA2B,OAA0C;AAC7E,QAAM,cAAgB,YAAUA,sBAAqB,KAAK;AAC1D,MAAI,CAAC,YAAY,SAAS;AACzB,WAAO;AAAA,EACR;AACA,QAAM,SAAS,YAAY;AAC3B,QAAM,QAAQ,iBAAiB,OAAO,KAAK,KAAK;AAChD,QAAM,SAAS,iBAAiB,OAAO,MAAM,KAAK;AAClD,QAAM,YAAY,iBAAiB,OAAO,SAAS,KAAK;AACxD,QAAM,aAAa,iBAAiB,OAAO,UAAU,KAAK;AAC1D,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAA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AAQ;AAC3B,QAAI,MAAM,cAAc,YAAY;AACnC;AAAA,IACD;AACA,UAAM,UAAU,uBAAuB,MAAM,IAAI;AACjD,UAAM,eAAe,wBAAwB,OAAO;AACpD,QAAI,CAAC,cAAc;AAClB;AAAA,IACD;AACA,UAAM,QAAQ,uBAAuB,OAAO;AAC5C,QAAI,CAAC,OAAO;AACX;AAAA,IACD;AACA,UAAM,SAAS,oBAAoB,UAAU,YAAY,KAAK,MAAM,KAAK;AACzE,QAAI,QAAQ;AACX,gBAAU,YAAY,IAAI;AAAA,IAC3B;AAAA,EACD;AACA,SAAO;AACR;","names":["unknownRecordSchema","v","asUnknownRecord"]}
1
+ {"version":3,"sources":["../src/usage-snapshot.ts","../src/ws-event-payloads.ts","../src/compact-turn-summary.ts","../src/extension-ui-contracts.ts","../src/initial-prompt.ts","../src/live-turn-projection.ts","../src/timestamp-ordering.ts","../src/pi-session-message.ts","../src/session-entry-tree.ts","../src/streamable-events.ts","../src/text-preview.ts","../src/timeline-projection.ts","../src/tool-result-truncation.ts","../src/turn-continuation.ts","../src/turn-trace-projection.ts","../src/usage-by-turn-record.ts"],"sourcesContent":["import { copiedUnknownRecordSchema as unknownRecordSchema } from \"@leitwerk-dev/domain\";\nimport * as v from \"valibot\";\n\n/** @internal */\nexport interface UsageCostSnapshot {\n\t/** @internal */\n\tinput: number;\n\t/** @internal */\n\toutput: number;\n\t/** @internal */\n\tcacheRead: number;\n\t/** @internal */\n\tcacheWrite: number;\n\t/** @internal */\n\ttotal: number;\n}\n\n/** @internal */\nexport interface UsageTokenCounts {\n\t/** @internal */\n\tinput: number;\n\t/** @internal */\n\toutput: number;\n\t/** Provider-reported reasoning/thinking tokens. This is a subset of output tokens. @internal */\n\treasoning?: number;\n\t/** @internal */\n\tcacheRead: number;\n\t/** @internal */\n\tcacheWrite: number;\n\t/** @internal */\n\ttotalTokens: number;\n}\n\n/** @internal */\nexport interface UsageSnapshot extends UsageTokenCounts {\n\t/** @internal */\n\tcost: UsageCostSnapshot | null;\n\t/** Number of model requests represented by this aggregate, when known. @internal */\n\trequestCount?: number;\n\t/** Largest input-token count for a single represented model request, when known. @internal */\n\tmaxInputTokens?: number;\n}\n\nfunction readFiniteNumber(value: unknown): number | undefined {\n\treturn typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\nfunction normalizeUsageCostSnapshot(value: unknown): UsageCostSnapshot | null {\n\tconst parsedValue = v.safeParse(unknownRecordSchema, value);\n\tif (!parsedValue.success) {\n\t\treturn null;\n\t}\n\tconst record = parsedValue.output;\n\tconst input = readFiniteNumber(record.input) ?? 0;\n\tconst output = readFiniteNumber(record.output) ?? 0;\n\tconst cacheRead = readFiniteNumber(record.cacheRead) ?? 0;\n\tconst cacheWrite = readFiniteNumber(record.cacheWrite) ?? 0;\n\treturn {\n\t\tinput,\n\t\toutput,\n\t\tcacheRead,\n\t\tcacheWrite,\n\t\ttotal: readFiniteNumber(record.total) ?? input + output + cacheRead + cacheWrite,\n\t};\n}\n\n/** @internal */\nexport function cloneUsageSnapshot(usage: UsageSnapshot | null | undefined): UsageSnapshot | null {\n\tif (!usage) {\n\t\treturn null;\n\t}\n\treturn {\n\t\t...usage,\n\t\tcost: usage.cost ? { ...usage.cost } : null,\n\t};\n}\n\n/** @internal */\nexport function normalizeUsageSnapshot(value: unknown): UsageSnapshot | null {\n\tconst parsedValue = v.safeParse(unknownRecordSchema, value);\n\tif (!parsedValue.success) {\n\t\treturn null;\n\t}\n\tconst record = parsedValue.output;\n\tconst input = readFiniteNumber(record.input) ?? 0;\n\tconst output = readFiniteNumber(record.output) ?? 0;\n\tconst reasoning = readFiniteNumber(record.reasoning);\n\tconst cacheRead = readFiniteNumber(record.cacheRead) ?? 0;\n\tconst cacheWrite = readFiniteNumber(record.cacheWrite) ?? 0;\n\tconst cost = normalizeUsageCostSnapshot(record.cost);\n\tconst maxInputTokens = readFiniteNumber(record.maxInputTokens);\n\tconst hasExplicitUsageTelemetry =\n\t\t[\"input\", \"output\", \"reasoning\", \"cacheRead\", \"cacheWrite\", \"totalTokens\"].some(\n\t\t\t(key) => readFiniteNumber(record[key]) !== undefined,\n\t\t) || cost !== null;\n\tif (!hasExplicitUsageTelemetry) {\n\t\treturn null;\n\t}\n\treturn {\n\t\tinput,\n\t\toutput,\n\t\t...(reasoning !== undefined ? { reasoning } : {}),\n\t\tcacheRead,\n\t\tcacheWrite,\n\t\ttotalTokens: readFiniteNumber(record.totalTokens) ?? input + output + cacheRead + cacheWrite,\n\t\tcost,\n\t\trequestCount: Math.max(0, Math.floor(readFiniteNumber(record.requestCount) ?? 1)),\n\t\tmaxInputTokens: maxInputTokens !== undefined ? Math.max(0, maxInputTokens) : input,\n\t};\n}\n\n/** @internal */\nexport function mergeUsageSnapshots(\n\ttotal: UsageSnapshot | null,\n\tusage: UsageSnapshot | null,\n): UsageSnapshot | null {\n\tif (!usage) {\n\t\treturn cloneUsageSnapshot(total);\n\t}\n\tif (!total) {\n\t\treturn cloneUsageSnapshot(usage);\n\t}\n\tconst hasRequestMetrics =\n\t\ttotal.requestCount !== undefined ||\n\t\tusage.requestCount !== undefined ||\n\t\ttotal.maxInputTokens !== undefined ||\n\t\tusage.maxInputTokens !== undefined;\n\treturn {\n\t\tinput: total.input + usage.input,\n\t\toutput: total.output + usage.output,\n\t\t...(total.reasoning !== undefined || usage.reasoning !== undefined\n\t\t\t? { reasoning: (total.reasoning ?? 0) + (usage.reasoning ?? 0) }\n\t\t\t: {}),\n\t\tcacheRead: total.cacheRead + usage.cacheRead,\n\t\tcacheWrite: total.cacheWrite + usage.cacheWrite,\n\t\ttotalTokens: total.totalTokens + usage.totalTokens,\n\t\tcost:\n\t\t\ttotal.cost && usage.cost\n\t\t\t\t? {\n\t\t\t\t\t\tinput: total.cost.input + usage.cost.input,\n\t\t\t\t\t\toutput: total.cost.output + usage.cost.output,\n\t\t\t\t\t\tcacheRead: total.cost.cacheRead + usage.cost.cacheRead,\n\t\t\t\t\t\tcacheWrite: total.cost.cacheWrite + usage.cost.cacheWrite,\n\t\t\t\t\t\ttotal: total.cost.total + usage.cost.total,\n\t\t\t\t\t}\n\t\t\t\t: null,\n\t\t...(hasRequestMetrics\n\t\t\t? {\n\t\t\t\t\trequestCount: (total.requestCount ?? 1) + (usage.requestCount ?? 1),\n\t\t\t\t\tmaxInputTokens: Math.max(\n\t\t\t\t\t\ttotal.maxInputTokens ?? total.input,\n\t\t\t\t\t\tusage.maxInputTokens ?? usage.input,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n}\n","import { asUnknownRecord, trimToNull as readWsEventNonEmptyString } from \"@leitwerk-dev/domain\";\n\n/** @internal */\nexport interface WsEventPayloadRecord extends Record<string, unknown> {}\n\n/** @internal */\nexport interface ResolveWsEventToolCallIdOptions {\n\t/** @internal */\n\ttimestamp: string;\n\t/** @internal */\n\ttoolName?: string;\n\t/** @internal */\n\tordinal?: number;\n}\n\n/** @internal */\nexport function asWsEventPayloadRecord(value: unknown): WsEventPayloadRecord {\n\treturn asUnknownRecord(value) ?? {};\n}\n\nexport { readWsEventNonEmptyString };\n\n/** @internal */\nexport function readWsEventTimestamp(\n\tdata: WsEventPayloadRecord,\n\tfallbackTimestamp: string,\n): string {\n\treturn readWsEventNonEmptyString(data.timestamp) ?? fallbackTimestamp;\n}\n\n/** @internal */\nexport function readWsEventTurnRecordId(data: WsEventPayloadRecord): string | null {\n\treturn readWsEventNonEmptyString(data.turnRecordId);\n}\n\n/** @internal */\nexport function readWsEventPiTurnId(data: WsEventPayloadRecord): string | null {\n\treturn readWsEventNonEmptyString(data.turnId);\n}\n\n/** @internal */\nexport function readWsEventStreamText(data: WsEventPayloadRecord): string | null {\n\treturn typeof data.text === \"string\"\n\t\t? data.text\n\t\t: typeof data.delta === \"string\"\n\t\t\t? data.delta\n\t\t\t: typeof data.chunk === \"string\"\n\t\t\t\t? data.chunk\n\t\t\t\t: null;\n}\n\n/** @internal */\nexport function readWsEventToolName(data: WsEventPayloadRecord): string {\n\treturn readWsEventNonEmptyString(data.name) ?? readWsEventNonEmptyString(data.toolName) ?? \"tool\";\n}\n\n/** @internal */\nexport function readWsEventToolArguments(\n\tdata: WsEventPayloadRecord,\n): Record<string, unknown> | null {\n\treturn asUnknownRecord(data.arguments ?? data.args);\n}\n\n/** @internal */\nexport function readWsEventToolCallId(data: WsEventPayloadRecord): string | null {\n\treturn readWsEventNonEmptyString(data.toolCallId);\n}\n\n/** @internal */\nexport function resolveWsEventToolCallId(\n\tdata: WsEventPayloadRecord,\n\toptions: ResolveWsEventToolCallIdOptions,\n): string {\n\treturn (\n\t\treadWsEventToolCallId(data) ??\n\t\t`${options.toolName ?? readWsEventToolName(data)}:${options.timestamp}${options.ordinal ? `:${options.ordinal}` : \"\"}`\n\t);\n}\n","import type {\n\tPrimaryPathActiveTurnSnapshot,\n\tPrimaryPathToolCallSnapshot,\n} from \"./primary-path-snapshot.js\";\nimport {\n\tmergeUsageSnapshots,\n\tnormalizeUsageSnapshot,\n\ttype UsageSnapshot,\n} from \"./usage-snapshot.js\";\nimport {\n\treadWsEventStreamText,\n\treadWsEventTimestamp,\n\treadWsEventToolCallId,\n\treadWsEventToolName,\n} from \"./ws-event-payloads.js\";\n\n/** @internal */\nexport const REASONING_PREVIEW_MAX_CHARS = 1_024;\n\n/** @internal */\nexport interface CompactTurnSummary {\n\t/** @internal */\n\tassistant: {\n\t\t/** @internal */\n\t\ttext: string;\n\t\t/** @internal */\n\t\tthinking: string;\n\t\t/** @internal */\n\t\tlastUpdatedAt: string | null;\n\t};\n\t/** @internal */\n\tcurrentTool: Pick<\n\t\tPrimaryPathToolCallSnapshot,\n\t\t\"toolCallId\" | \"toolName\" | \"status\" | \"isError\"\n\t> | null;\n\t/** @internal */\n\tusage: UsageSnapshot | null;\n\t/** @internal */\n\ttoolCallCount: number;\n\t/** @internal */\n\ttraceItemCount: number;\n\t/** The last persisted event incorporated into this projection. @internal */\n\tthroughEventSequence: number;\n\t/** @internal */\n\tlastTraceKind: \"thinking\" | \"tool_call\" | \"operational_event\" | null;\n}\n\n/** Initial-page state. It never contains trace items, tool arguments or results. @internal */\nexport interface CompactActiveTurnSnapshot\n\textends CompactTurnSummary,\n\t\tPick<\n\t\t\tPrimaryPathActiveTurnSnapshot,\n\t\t\t\"turnRecordId\" | \"turnId\" | \"turnType\" | \"pathType\" | \"startedAt\"\n\t\t> {\n\t/** @internal */\n\tsummaryPending: boolean;\n}\n\n/** @internal */\nexport function emptyCompactTurnSummary(): CompactTurnSummary {\n\treturn {\n\t\tassistant: { text: \"\", thinking: \"\", lastUpdatedAt: null },\n\t\tcurrentTool: null,\n\t\tusage: null,\n\t\ttoolCallCount: 0,\n\t\ttraceItemCount: 0,\n\t\tthroughEventSequence: 0,\n\t\tlastTraceKind: null,\n\t};\n}\n\n/** Retain paragraph context; wrapping and blank-line removal belong to the preview viewport. @internal */\nexport function reasoningPreviewTail(text: string): string {\n\tconst normalized = text.replace(/\\r\\n?/g, \"\\n\");\n\tconst lines = normalized.split(\"\\n\").filter((line) => line.trim() !== \"\");\n\tconst separator = /\\n[^\\S\\n]*$/.test(normalized) ? \"\\n\" : \"\";\n\treturn (lines.join(\"\\n\") + separator).slice(-REASONING_PREVIEW_MAX_CHARS);\n}\n\n/** @internal */\nexport function applyEventToCompactTurnSummary(\n\tprevious: CompactTurnSummary,\n\tevent: {\n\t\t/** @internal */\n\t\teventType: string;\n\t\t/** @internal */\n\t\tdata: Record<string, unknown>;\n\t\t/** @internal */\n\t\tcreatedAt: string;\n\t\t/** @internal */\n\t\teventSequence: number;\n\t},\n): CompactTurnSummary {\n\tif (event.eventSequence <= previous.throughEventSequence) return previous;\n\tconst next = {\n\t\t...previous,\n\t\tassistant: { ...previous.assistant },\n\t\tthroughEventSequence: event.eventSequence,\n\t};\n\tconst { eventType, data } = event;\n\tif (eventType === \"pi.stream.delta\") {\n\t\tconst text = readWsEventStreamText(data);\n\t\tconst key = data.streamType === \"thinking\" ? \"thinking\" : \"text\";\n\t\tnext.assistant[key] = reasoningPreviewTail(next.assistant[key] + text);\n\t\tif (text) next.assistant.lastUpdatedAt = readWsEventTimestamp(data, event.createdAt);\n\t\tif (key === \"thinking\" && text) {\n\t\t\tif (next.lastTraceKind !== \"thinking\") next.traceItemCount++;\n\t\t\tnext.lastTraceKind = \"thinking\";\n\t\t}\n\t} else if (eventType === \"pi.tool.call\" || eventType === \"pi.tool.result\") {\n\t\tconst isResult = eventType === \"pi.tool.result\";\n\t\tconst toolCallId = (readWsEventToolCallId(data) ?? `tool-${event.eventSequence}`).slice(0, 256);\n\t\tif (!isResult) {\n\t\t\tnext.toolCallCount++;\n\t\t\tnext.traceItemCount++;\n\t\t\tnext.lastTraceKind = \"tool_call\";\n\t\t}\n\t\tif (!isResult || !next.currentTool || next.currentTool.toolCallId === toolCallId) {\n\t\t\tnext.currentTool = {\n\t\t\t\ttoolCallId: toolCallId.slice(0, 256),\n\t\t\t\ttoolName: readWsEventToolName(data).slice(0, 256),\n\t\t\t\tstatus: isResult ? \"completed\" : \"running\",\n\t\t\t\tisError: data.isError === true,\n\t\t\t};\n\t\t}\n\t} else if (eventType === \"pi.usage\") {\n\t\tnext.usage = mergeUsageSnapshots(next.usage, normalizeUsageSnapshot(data));\n\t} else if (\n\t\t[\n\t\t\t\"pi.error\",\n\t\t\t\"pi.retry.start\",\n\t\t\t\"pi.retry.end\",\n\t\t\t\"pi.compaction.start\",\n\t\t\t\"pi.compaction.end\",\n\t\t].includes(eventType)\n\t) {\n\t\tnext.traceItemCount++;\n\t\tnext.lastTraceKind = \"operational_event\";\n\t}\n\treturn next;\n}\n","import { isUnknownRecord } from \"@leitwerk-dev/domain\";\nimport * as v from \"valibot\";\n\n// Wire shape only; the catalog validates manifests and hosts check supported versions.\nconst recordSchema = v.custom<Record<string, unknown>>(isUnknownRecord);\nconst versionSchema = v.custom<number>((value) => typeof value === \"number\");\n\n/** @internal */\nexport const leafOutcomeRendererDescriptorSchema = v.pipe(\n\trecordSchema,\n\tv.object({\n\t\t/** @internal */\n\t\tok: v.literal(true),\n\t\t/** @internal */\n\t\trendererId: v.string(),\n\t\t/** @internal */\n\t\tkind: v.literal(\"custom_element\"),\n\t\t/** @internal */\n\t\ttagName: v.string(),\n\t\t/** @internal */\n\t\tmodulePath: v.string(),\n\t\t/** @internal */\n\t\trendererApiVersion: versionSchema,\n\t\t/** @internal */\n\t\textensionManifestId: v.string(),\n\t\t/** @internal */\n\t\tmoduleUrl: v.string(),\n\t}),\n);\n/** @internal */\nexport type LeafOutcomeRendererDescriptor = v.InferOutput<\n\ttypeof leafOutcomeRendererDescriptorSchema\n>;\n\n/** @internal */\nexport const leafOutcomeRendererFailureSchema = v.pipe(\n\trecordSchema,\n\tv.object({\n\t\t/** @internal */\n\t\tok: v.literal(false),\n\t\t/** @internal */\n\t\trendererId: v.string(),\n\t\t/** @internal */\n\t\tcode: v.string(),\n\t\t/** @internal */\n\t\tmessage: v.string(),\n\t}),\n);\n/** @internal */\nexport type LeafOutcomeRendererFailure = v.InferOutput<typeof leafOutcomeRendererFailureSchema>;\n\n/** @internal */\nexport const browserUiExtensionDescriptorSchema = v.pipe(\n\trecordSchema,\n\tv.object({\n\t\t/** @internal */\n\t\textensionManifestId: v.string(),\n\t\t/** @internal */\n\t\tmodulePath: v.string(),\n\t\t/** @internal */\n\t\tmoduleUrl: v.string(),\n\t\t/** @internal */\n\t\tbrowserApiVersion: versionSchema,\n\t}),\n);\n/** @internal */\nexport type BrowserUiExtensionDescriptor = v.InferOutput<typeof browserUiExtensionDescriptorSchema>;\n","import { isUnknownRecord as isRecord } from \"@leitwerk-dev/domain\";\nimport type { FutureExecutionOverviewItem, FutureExecutionSummary } from \"./http-contracts.js\";\n\n// Best-effort extraction of an operator-facing prompt/command from launch params\n// for compact overview and detail read models. Process launchers use several\n// established field names; keep this priority list shared so server and browser\n// projections cannot drift.\n/** @internal */\nexport const INITIAL_PROMPT_FIELD_PRIORITY = [\n\t\"initialPrompt\",\n\t\"prompt\",\n\t\"taskPrompt\",\n\t\"userPrompt\",\n\t\"instructions\",\n\t\"instruction\",\n\t\"initialCommand\",\n\t\"command\",\n\t\"query\",\n\t\"message\",\n\t\"requestedChange\",\n\t\"request\",\n\t\"description\",\n] as const;\n\nfunction normalizePromptValue(value: string): string | null {\n\tconst normalized = value.replace(/\\s+/g, \" \").trim();\n\treturn normalized.length > 0 ? normalized : null;\n}\n\n/** @internal */\nexport function truncatePromptPreview(\n\tvalue: string | null | undefined,\n\tmaxLength = 180,\n): string | null {\n\tconst normalized = typeof value === \"string\" ? normalizePromptValue(value) : null;\n\treturn normalized && normalized.length > maxLength\n\t\t? `${normalized.slice(0, maxLength).trimEnd()}…`\n\t\t: normalized;\n}\n\nfunction readStringField(record: Record<string, unknown>, fieldName: string): string | null {\n\tconst exact = record[fieldName];\n\tif (typeof exact === \"string\") {\n\t\treturn exact.trim() ? exact : null;\n\t}\n\n\tconst normalizedFieldName = fieldName.toLowerCase();\n\tfor (const [key, value] of Object.entries(record)) {\n\t\tif (key.toLowerCase() !== normalizedFieldName || typeof value !== \"string\") {\n\t\t\tcontinue;\n\t\t}\n\t\treturn value.trim() ? value : null;\n\t}\n\n\treturn null;\n}\n\n/** @internal */\nexport function extractInitialPromptFromValue(value: unknown): string | null {\n\tif (!isRecord(value)) {\n\t\treturn null;\n\t}\n\n\tfor (const fieldName of INITIAL_PROMPT_FIELD_PRIORITY) {\n\t\tconst prompt = readStringField(value, fieldName);\n\t\tif (prompt) {\n\t\t\treturn prompt;\n\t\t}\n\t}\n\n\treturn null;\n}\n\n/** @internal */\nexport function extractInitialPromptFromParamsJson(\n\tparamsJson: string | null | undefined,\n): string | null {\n\tif (!paramsJson) {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\treturn extractInitialPromptFromValue(JSON.parse(paramsJson));\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/** @internal */\nexport function extractInitialPromptPreviewFromParamsJson(\n\tparamsJson: string | null | undefined,\n\tmaxLength = 180,\n): string | null {\n\treturn truncatePromptPreview(extractInitialPromptFromParamsJson(paramsJson), maxLength);\n}\n\n/** @internal */\nexport function projectFutureExecutionOverview(\n\tsummary: FutureExecutionSummary,\n): FutureExecutionOverviewItem {\n\tconst common = {\n\t\tid: summary.id,\n\t\tscheduleKind: summary.scheduleKind,\n\t\tprocessId: summary.processId,\n\t\tnextRunAt: summary.nextRunAt,\n\t\tcronExpression: summary.cronExpression,\n\t\ttitle: summary.title,\n\t\tstatus: summary.status ?? \"scheduled\",\n\t\tblockedReason: summary.blockedReason ?? null,\n\t\tinitialPromptPreview:\n\t\t\tsummary.kind === \"launch\"\n\t\t\t\t? truncatePromptPreview(extractInitialPromptFromValue(summary.launcherInput))\n\t\t\t\t: null,\n\t};\n\treturn summary.kind === \"action\"\n\t\t? {\n\t\t\t\t...common,\n\t\t\t\tkind: \"action\",\n\t\t\t\tinstanceId: summary.instanceId,\n\t\t\t\tactionId: summary.actionId,\n\t\t\t\tactionLabel: summary.actionLabel,\n\t\t\t}\n\t\t: {\n\t\t\t\t...common,\n\t\t\t\tkind: \"launch\",\n\t\t\t\tinstanceId: null,\n\t\t\t\tlauncherId: summary.launcherId,\n\t\t\t\tlauncherLabel: summary.launcherLabel,\n\t\t\t};\n}\n","import {\n\ttype ProcessEvent,\n\treadFiniteNumber as readNumber,\n\treadNonBlankString as readString,\n} from \"@leitwerk-dev/domain\";\nimport type {\n\tPrimaryPathOperationalTraceItemSnapshot,\n\tPrimaryPathStreamingAssistantSnapshot,\n\tPrimaryPathToolCallSnapshot,\n\tPrimaryPathTraceItemSnapshot,\n} from \"./primary-path-snapshot.js\";\nimport { compareTimestampStrings } from \"./timestamp-ordering.js\";\nimport {\n\tcloneUsageSnapshot,\n\tmergeUsageSnapshots,\n\tnormalizeUsageSnapshot,\n\ttype UsageSnapshot,\n} from \"./usage-snapshot.js\";\nimport {\n\tasWsEventPayloadRecord,\n\treadWsEventNonEmptyString,\n\treadWsEventStreamText,\n\treadWsEventTimestamp,\n\treadWsEventToolArguments,\n\treadWsEventToolCallId,\n\treadWsEventToolName,\n\tresolveWsEventToolCallId,\n\ttype WsEventPayloadRecord,\n} from \"./ws-event-payloads.js\";\n\n/** @internal */\nexport interface MutableLiveTurnProjection {\n\t/** @internal */\n\tassistant: PrimaryPathStreamingAssistantSnapshot;\n\t/** @internal */\n\ttoolCalls: PrimaryPathToolCallSnapshot[];\n\t/** @internal */\n\ttraceItems: PrimaryPathTraceItemSnapshot[];\n\t/** @internal */\n\tusage: UsageSnapshot | null;\n\t/** @internal */\n\ttoolCallsById: Map<string, PrimaryPathToolCallSnapshot>;\n\t/** @internal */\n\topenToolCallIdsByName: Map<string, string[]>;\n\t/** @internal */\n\tnextFallbackOrdinal: number;\n}\n\n/** @internal */\nexport interface AppliedLiveTurnProjectionEvent {\n\t/** @internal */\n\tcanonicalData: WsEventPayloadRecord;\n\t/** @internal */\n\ttimestamp: string;\n\t/** @internal */\n\ttoolCallId: string | null;\n\t/** @internal */\n\ttoolName: string | null;\n}\n\n/** @internal */\nexport const PRIMARY_PATH_OPERATIONAL_PI_EVENT_TYPES = [\n\t\"pi.error\",\n\t\"pi.retry.start\",\n\t\"pi.retry.end\",\n\t\"pi.compaction.start\",\n\t\"pi.compaction.end\",\n] as const;\n\nconst PRIMARY_PATH_OPERATIONAL_PI_EVENT_TYPE_SET = new Set<string>(\n\tPRIMARY_PATH_OPERATIONAL_PI_EVENT_TYPES,\n);\n\nfunction cloneToolCall(toolCall: PrimaryPathToolCallSnapshot): PrimaryPathToolCallSnapshot {\n\treturn {\n\t\t...toolCall,\n\t\t...(toolCall.arguments ? { arguments: { ...toolCall.arguments } } : {}),\n\t};\n}\n\nfunction formatReason(value: unknown): string | null {\n\tconst reason = readString(value);\n\treturn reason ? reason.replace(/[_-]+/g, \" \") : null;\n}\n\nfunction firstMessage(data: WsEventPayloadRecord, keys: readonly string[]): string | null {\n\tfor (const key of keys) {\n\t\tconst value = readString(data[key]);\n\t\tif (value) {\n\t\t\treturn value;\n\t\t}\n\t}\n\treturn null;\n}\n\nfunction retryStartFallbackMessage(data: WsEventPayloadRecord): string {\n\tconst attempt = readNumber(data.attempt);\n\tconst maxAttempts = readNumber(data.maxAttempts);\n\tconst delayMs = readNumber(data.delayMs);\n\tconst attemptLabel = attempt !== null && maxAttempts !== null ? ` ${attempt}/${maxAttempts}` : \"\";\n\tconst delayLabel = delayMs !== null && delayMs > 0 ? ` in ${delayMs}ms` : \"\";\n\treturn `Retry${attemptLabel} scheduled${delayLabel}.`;\n}\n\nfunction retryEndFallbackMessage(data: WsEventPayloadRecord): string {\n\tconst attempt = readNumber(data.attempt);\n\tif (data.success === true) {\n\t\treturn attempt !== null\n\t\t\t? `Retry sequence succeeded after ${attempt} ${attempt === 1 ? \"retry\" : \"retries\"}.`\n\t\t\t: \"Retry sequence succeeded.\";\n\t}\n\treturn attempt !== null\n\t\t? `Retry sequence ended after ${attempt} ${attempt === 1 ? \"retry\" : \"retries\"}.`\n\t\t: \"Retry sequence ended.\";\n}\n\n/** @internal */\nexport function buildPrimaryPathOperationalTraceItem(input: {\n\t/** @internal */\n\teventType: string;\n\t/** @internal */\n\tdata: WsEventPayloadRecord;\n\t/** @internal */\n\tfallbackTimestamp: string;\n}): PrimaryPathOperationalTraceItemSnapshot | null {\n\tif (!PRIMARY_PATH_OPERATIONAL_PI_EVENT_TYPE_SET.has(input.eventType)) {\n\t\treturn null;\n\t}\n\tconst timestamp = readWsEventTimestamp(input.data, input.fallbackTimestamp);\n\tif (input.eventType === \"pi.error\") {\n\t\treturn {\n\t\t\tkind: \"operational_event\",\n\t\t\teventType: input.eventType,\n\t\t\tseverity: \"error\",\n\t\t\ttitle: \"Pi request failed\",\n\t\t\tmessage:\n\t\t\t\tfirstMessage(input.data, [\"message\", \"errorMessage\", \"finalError\"]) ??\n\t\t\t\t\"Pi reported an error.\",\n\t\t\ttimestamp,\n\t\t};\n\t}\n\tif (input.eventType === \"pi.retry.start\") {\n\t\treturn {\n\t\t\tkind: \"operational_event\",\n\t\t\teventType: input.eventType,\n\t\t\tseverity: \"warning\",\n\t\t\ttitle: \"Retry scheduled\",\n\t\t\tmessage:\n\t\t\t\tfirstMessage(input.data, [\"message\", \"errorMessage\"]) ??\n\t\t\t\tretryStartFallbackMessage(input.data),\n\t\t\ttimestamp,\n\t\t};\n\t}\n\tif (input.eventType === \"pi.retry.end\") {\n\t\tconst success = input.data.success === true;\n\t\treturn {\n\t\t\tkind: \"operational_event\",\n\t\t\teventType: input.eventType,\n\t\t\tseverity: success ? \"success\" : \"error\",\n\t\t\ttitle: success ? \"Retry succeeded\" : \"Retry exhausted\",\n\t\t\tmessage:\n\t\t\t\tfirstMessage(input.data, [\"message\", \"finalError\", \"errorMessage\"]) ??\n\t\t\t\tretryEndFallbackMessage(input.data),\n\t\t\ttimestamp,\n\t\t};\n\t}\n\tif (input.eventType === \"pi.compaction.start\") {\n\t\tconst reason = formatReason(input.data.reason);\n\t\treturn {\n\t\t\tkind: \"operational_event\",\n\t\t\teventType: input.eventType,\n\t\t\tseverity: \"info\",\n\t\t\ttitle: \"Context compaction started\",\n\t\t\tmessage: reason\n\t\t\t\t? `Pi started compacting context (${reason}).`\n\t\t\t\t: \"Pi started compacting context.\",\n\t\t\ttimestamp,\n\t\t};\n\t}\n\tif (input.eventType === \"pi.compaction.end\") {\n\t\tconst reason = formatReason(input.data.reason);\n\t\tconst errorMessage = firstMessage(input.data, [\"errorMessage\", \"message\"]);\n\t\tconst aborted = input.data.aborted === true;\n\t\tconst willRetry = input.data.willRetry === true;\n\t\tconst statusMessage = errorMessage\n\t\t\t? errorMessage\n\t\t\t: aborted\n\t\t\t\t? \"Context compaction was cancelled.\"\n\t\t\t\t: `Pi compacted context${reason ? ` (${reason})` : \"\"}.${willRetry ? \" Pi will continue automatically.\" : \"\"}`;\n\t\treturn {\n\t\t\tkind: \"operational_event\",\n\t\t\teventType: input.eventType,\n\t\t\tseverity: errorMessage ? \"error\" : aborted ? \"warning\" : \"success\",\n\t\t\ttitle: errorMessage\n\t\t\t\t? \"Context compaction failed\"\n\t\t\t\t: aborted\n\t\t\t\t\t? \"Context compaction cancelled\"\n\t\t\t\t\t: \"Context compacted\",\n\t\t\tmessage: statusMessage,\n\t\t\ttimestamp,\n\t\t};\n\t}\n\treturn null;\n}\n\nfunction addOpenToolCallId(\n\tprojection: MutableLiveTurnProjection,\n\ttoolName: string,\n\ttoolCallId: string,\n) {\n\tconst ids = projection.openToolCallIdsByName.get(toolName) ?? [];\n\tids.push(toolCallId);\n\tprojection.openToolCallIdsByName.set(toolName, ids);\n}\n\nfunction consumeLatestOpenToolCallId(\n\tprojection: MutableLiveTurnProjection,\n\ttoolName: string,\n): string | null {\n\tconst ids = projection.openToolCallIdsByName.get(toolName);\n\tif (!ids || ids.length === 0) {\n\t\treturn null;\n\t}\n\tconst toolCallId = ids.pop() ?? null;\n\tif (ids.length === 0) {\n\t\tprojection.openToolCallIdsByName.delete(toolName);\n\t} else {\n\t\tprojection.openToolCallIdsByName.set(toolName, ids);\n\t}\n\treturn toolCallId;\n}\n\nfunction removeOpenToolCallId(projection: MutableLiveTurnProjection, toolCallId: string) {\n\tfor (const [toolName, ids] of projection.openToolCallIdsByName.entries()) {\n\t\tconst nextIds = ids.filter((candidate) => candidate !== toolCallId);\n\t\tif (nextIds.length === ids.length) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (nextIds.length === 0) {\n\t\t\tprojection.openToolCallIdsByName.delete(toolName);\n\t\t} else {\n\t\t\tprojection.openToolCallIdsByName.set(toolName, nextIds);\n\t\t}\n\t\treturn;\n\t}\n}\n\nfunction canonicalizeToolCallId(input: {\n\tprojection: MutableLiveTurnProjection;\n\tdata: WsEventPayloadRecord;\n\ttimestamp: string;\n\ttoolName: string;\n\tpreferOpenCall: boolean;\n}): string {\n\tconst explicitToolCallId = readWsEventToolCallId(input.data);\n\tif (explicitToolCallId) {\n\t\tif (input.preferOpenCall) {\n\t\t\tremoveOpenToolCallId(input.projection, explicitToolCallId);\n\t\t}\n\t\treturn explicitToolCallId;\n\t}\n\tif (input.preferOpenCall) {\n\t\tconst openToolCallId = consumeLatestOpenToolCallId(input.projection, input.toolName);\n\t\tif (openToolCallId) {\n\t\t\treturn openToolCallId;\n\t\t}\n\t}\n\treturn resolveWsEventToolCallId(input.data, {\n\t\ttimestamp: input.timestamp,\n\t\ttoolName: input.toolName,\n\t\tordinal: input.projection.nextFallbackOrdinal++,\n\t});\n}\n\nfunction appendThinkingTraceText(projection: MutableLiveTurnProjection, text: string): void {\n\tif (text.length === 0) {\n\t\treturn;\n\t}\n\tconst lastTraceItem = projection.traceItems.at(-1);\n\tif (lastTraceItem?.kind === \"thinking\") {\n\t\tlastTraceItem.text += text;\n\t\treturn;\n\t}\n\tprojection.traceItems.push({\n\t\tkind: \"thinking\",\n\t\ttext,\n\t});\n}\n\nfunction ensureToolTraceItem(projection: MutableLiveTurnProjection, toolCallId: string): void {\n\tif (\n\t\tprojection.traceItems.some(\n\t\t\t(traceItem) => traceItem.kind === \"tool_call\" && traceItem.toolCallId === toolCallId,\n\t\t)\n\t) {\n\t\treturn;\n\t}\n\tprojection.traceItems.push({\n\t\tkind: \"tool_call\",\n\t\ttoolCallId,\n\t});\n}\n\n/** @internal */\nexport function createMutableLiveTurnProjection(): MutableLiveTurnProjection {\n\treturn {\n\t\tassistant: {\n\t\t\ttext: \"\",\n\t\t\tthinking: \"\",\n\t\t\tlastUpdatedAt: null,\n\t\t},\n\t\ttoolCalls: [],\n\t\ttraceItems: [],\n\t\tusage: null,\n\t\ttoolCallsById: new Map<string, PrimaryPathToolCallSnapshot>(),\n\t\topenToolCallIdsByName: new Map<string, string[]>(),\n\t\tnextFallbackOrdinal: 1,\n\t};\n}\n\n/** @internal */\nexport function snapshotLiveTurnProjection(projection: MutableLiveTurnProjection): {\n\t/** @internal */\n\tassistant: PrimaryPathStreamingAssistantSnapshot;\n\t/** @internal */\n\ttoolCalls: PrimaryPathToolCallSnapshot[];\n\t/** @internal */\n\ttraceItems: PrimaryPathTraceItemSnapshot[];\n\t/** @internal */\n\tusage: UsageSnapshot | null;\n} {\n\treturn {\n\t\tassistant: { ...projection.assistant },\n\t\ttoolCalls: projection.toolCalls.map(cloneToolCall),\n\t\ttraceItems: projection.traceItems.map((item) => ({ ...item })),\n\t\tusage: cloneUsageSnapshot(projection.usage),\n\t};\n}\n\n/** @internal */\nexport function applyPiEventToLiveTurnProjection(\n\tprojection: MutableLiveTurnProjection,\n\tinput: {\n\t\t/** @internal */\n\t\teventType: string;\n\t\t/** @internal */\n\t\tdata: WsEventPayloadRecord;\n\t\t/** @internal */\n\t\tfallbackTimestamp: string;\n\t},\n): AppliedLiveTurnProjectionEvent {\n\tlet timestamp = readWsEventTimestamp(input.data, input.fallbackTimestamp);\n\tif (input.eventType === \"pi.stream.delta\") {\n\t\tconst text = readWsEventStreamText(input.data);\n\t\tif (text) {\n\t\t\tif (readWsEventNonEmptyString(input.data.streamType) === \"thinking\") {\n\t\t\t\tprojection.assistant.thinking += text;\n\t\t\t\tappendThinkingTraceText(projection, text);\n\t\t\t} else {\n\t\t\t\tprojection.assistant.text += text;\n\t\t\t}\n\t\t\tprojection.assistant.lastUpdatedAt = timestamp;\n\t\t}\n\t} else if (input.eventType === \"pi.tool.call\" || input.eventType === \"pi.tool.result\") {\n\t\tconst isResult = input.eventType === \"pi.tool.result\";\n\t\tconst toolName = readWsEventToolName(input.data);\n\t\tconst toolCallId = canonicalizeToolCallId({\n\t\t\tprojection,\n\t\t\tdata: input.data,\n\t\t\ttimestamp,\n\t\t\ttoolName,\n\t\t\tpreferOpenCall: isResult,\n\t\t});\n\t\tconst canonicalData =\n\t\t\treadWsEventToolCallId(input.data) === toolCallId ? input.data : { ...input.data, toolCallId };\n\t\tconst existingToolCall = projection.toolCallsById.get(toolCallId);\n\t\tconst toolCall: PrimaryPathToolCallSnapshot = existingToolCall ?? {\n\t\t\ttoolCallId,\n\t\t\ttoolName,\n\t\t\tstatus: \"running\",\n\t\t\tstartedAt: timestamp,\n\t\t\tcompletedAt: null,\n\t\t\targuments: isResult ? null : readWsEventToolArguments(canonicalData),\n\t\t\tresult: null,\n\t\t\tisError: false,\n\t\t};\n\t\tif (!existingToolCall) {\n\t\t\tprojection.toolCalls.push(toolCall);\n\t\t\tprojection.toolCallsById.set(toolCallId, toolCall);\n\t\t}\n\t\tif (isResult) {\n\t\t\ttoolCall.status = \"completed\";\n\t\t\ttoolCall.completedAt = timestamp;\n\t\t\ttoolCall.result = canonicalData.result ?? null;\n\t\t\ttoolCall.isError = canonicalData.isError === true;\n\t\t\tif (existingToolCall) removeOpenToolCallId(projection, toolCallId);\n\t\t}\n\t\tensureToolTraceItem(projection, toolCallId);\n\t\tif (!isResult) addOpenToolCallId(projection, toolName, toolCallId);\n\t\treturn {\n\t\t\tcanonicalData,\n\t\t\ttimestamp,\n\t\t\ttoolCallId,\n\t\t\ttoolName,\n\t\t};\n\t} else if (input.eventType === \"pi.usage\") {\n\t\tprojection.usage = mergeUsageSnapshots(projection.usage, normalizeUsageSnapshot(input.data));\n\t} else {\n\t\tconst operationalTraceItem = buildPrimaryPathOperationalTraceItem({\n\t\t\teventType: input.eventType,\n\t\t\tdata: input.data,\n\t\t\tfallbackTimestamp: input.fallbackTimestamp,\n\t\t});\n\t\tif (operationalTraceItem) {\n\t\t\tprojection.traceItems.push(operationalTraceItem);\n\t\t\ttimestamp = operationalTraceItem.timestamp;\n\t\t}\n\t}\n\n\treturn {\n\t\tcanonicalData: input.data,\n\t\ttimestamp,\n\t\ttoolCallId: null,\n\t\ttoolName: null,\n\t};\n}\n\nfunction compareProcessEventsChronologically(left: ProcessEvent, right: ProcessEvent): number {\n\tif (left.eventSequence !== undefined && right.eventSequence !== undefined) {\n\t\treturn left.eventSequence - right.eventSequence;\n\t}\n\tconst leftTimestamp = readWsEventTimestamp(asWsEventPayloadRecord(left.data), left.createdAt);\n\tconst rightTimestamp = readWsEventTimestamp(asWsEventPayloadRecord(right.data), right.createdAt);\n\tconst timestampComparison = compareTimestampStrings(leftTimestamp, rightTimestamp);\n\tif (timestampComparison !== 0) {\n\t\treturn timestampComparison;\n\t}\n\tconst createdAtComparison = compareTimestampStrings(left.createdAt, right.createdAt);\n\tif (createdAtComparison !== 0) {\n\t\treturn createdAtComparison;\n\t}\n\treturn left.id.localeCompare(right.id);\n}\n\n/** @internal */\nexport function buildLiveTurnProjectionFromEvents(\n\tevents: readonly ProcessEvent[],\n): MutableLiveTurnProjection {\n\tconst projection = createMutableLiveTurnProjection();\n\tfor (const event of [...events].sort(compareProcessEventsChronologically)) {\n\t\tapplyPiEventToLiveTurnProjection(projection, {\n\t\t\teventType: event.eventType,\n\t\t\tdata: asWsEventPayloadRecord(event.data),\n\t\t\tfallbackTimestamp: event.createdAt,\n\t\t});\n\t}\n\treturn projection;\n}\n","/** @internal */\nexport function compareTimestampStrings(left: string, right: string): number {\n\tconst leftMs = Date.parse(left);\n\tconst rightMs = Date.parse(right);\n\tif (Number.isFinite(leftMs) && Number.isFinite(rightMs)) {\n\t\treturn leftMs - rightMs;\n\t}\n\treturn left.localeCompare(right);\n}\n\n/** @internal */\nexport function happenedOnOrAfterStart(entryTimestamp: string, startedAt: string | null): boolean {\n\tif (!startedAt) {\n\t\treturn true;\n\t}\n\treturn compareTimestampStrings(entryTimestamp, startedAt) >= 0;\n}\n","/** @internal */\nexport interface PiSessionMessageLike {\n\t/** @internal */\n\trole?: unknown;\n\t/** @internal */\n\tcontent?: unknown;\n\t/** @internal */\n\tdetails?: unknown;\n\t/** @internal */\n\ttoolCallId?: unknown;\n\t/** @internal */\n\ttoolName?: unknown;\n\t/** @internal */\n\tisError?: unknown;\n\t/** @internal */\n\tusage?: unknown;\n}\n\n/** @internal */\nexport interface PiSessionMessageEntryLike {\n\t/** @internal */\n\ttype?: unknown;\n\t/** @internal */\n\tmessage?: unknown;\n}\n\n/** @internal */\nexport function isPiSessionMessageEntryType<\n\tTEntry extends {\n\t\t/** @internal */\n\t\ttype?: unknown;\n\t},\n>(entry: TEntry | undefined): entry is TEntry & { type: \"message\" } {\n\treturn entry?.type === \"message\";\n}\n\n/** @internal */\nexport function isPiSessionMessageRecord(value: unknown): value is PiSessionMessageLike {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** @internal */\nexport function isPiSessionMessageEntryWithRecord<TEntry extends PiSessionMessageEntryLike>(\n\tentry: TEntry | undefined,\n): entry is TEntry & { type: \"message\"; message: NonNullable<TEntry[\"message\"]> } {\n\treturn isPiSessionMessageEntryType(entry) && isPiSessionMessageRecord(entry.message);\n}\n\n/** @internal */\nexport function extractPiSessionMessageText(content: unknown): string {\n\tif (typeof content === \"string\") {\n\t\treturn content;\n\t}\n\tif (!Array.isArray(content)) {\n\t\treturn \"\";\n\t}\n\treturn content\n\t\t.map((block) => {\n\t\t\tif (typeof block !== \"object\" || block === null || Array.isArray(block)) {\n\t\t\t\treturn \"\";\n\t\t\t}\n\t\t\tconst record = block as { type?: unknown; text?: unknown };\n\t\t\treturn record.type === \"text\" && typeof record.text === \"string\" ? record.text : \"\";\n\t\t})\n\t\t.join(\"\");\n}\n","/** @internal */\nexport interface SessionTreeEntryLike {\n\t/** @internal */\n\tid: string;\n\t/** @internal */\n\tparentId: string | null;\n\t/** @internal */\n\ttimestamp: string;\n\t/** @internal */\n\ttype: string;\n}\n\n/** @internal */\nexport interface ReadonlyEntryTree<TEntry extends SessionTreeEntryLike> {\n\t/** @internal */\n\tentries: TEntry[];\n\t/** @internal */\n\tleafId: string | null;\n\t/** @internal */\n\tgetEntry(id: string): TEntry | undefined;\n\t/** @internal */\n\tgetChildren(parentId: string): TEntry[];\n\t/** @internal */\n\tgetBranch(fromId?: string | null): TEntry[];\n}\n\n/** @internal */\nexport function createReadonlyEntryTree<TEntry extends SessionTreeEntryLike>(\n\tentries: readonly TEntry[],\n): ReadonlyEntryTree<TEntry> {\n\tconst orderedEntries = [...entries];\n\tconst entriesById = new Map(orderedEntries.map((entry) => [entry.id, entry]));\n\tconst childrenByParentId = new Map<string, TEntry[]>();\n\n\tfor (const entry of orderedEntries) {\n\t\tif (typeof entry.parentId !== \"string\" || entry.parentId.trim() === \"\") {\n\t\t\tcontinue;\n\t\t}\n\t\tconst siblings = childrenByParentId.get(entry.parentId) ?? [];\n\t\tsiblings.push(entry);\n\t\tchildrenByParentId.set(entry.parentId, siblings);\n\t}\n\n\tconst leafId = orderedEntries.at(-1)?.id ?? null;\n\n\tconst getEntry = (id: string): TEntry | undefined => entriesById.get(id);\n\tconst getChildren = (parentId: string): TEntry[] =>\n\t\t(childrenByParentId.get(parentId) ?? []).slice();\n\tconst getBranch = (fromId?: string | null): TEntry[] => {\n\t\tconst resolvedFromId = fromId ?? leafId ?? undefined;\n\t\tif (!resolvedFromId) {\n\t\t\treturn [];\n\t\t}\n\t\tconst branch: TEntry[] = [];\n\t\tconst visited = new Set<string>();\n\t\tlet currentEntry = entriesById.get(resolvedFromId);\n\t\twhile (currentEntry) {\n\t\t\tif (visited.has(currentEntry.id)) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tvisited.add(currentEntry.id);\n\t\t\tbranch.unshift(currentEntry);\n\t\t\tcurrentEntry = currentEntry.parentId ? entriesById.get(currentEntry.parentId) : undefined;\n\t\t}\n\t\treturn branch;\n\t};\n\n\treturn {\n\t\tentries: orderedEntries,\n\t\tleafId,\n\t\tgetEntry,\n\t\tgetChildren,\n\t\tgetBranch,\n\t};\n}\n","/** @internal */\nexport const STREAMABLE_WORKER_EVENT_TYPES = [\n\t\"pi.stream.delta\",\n\t\"pi.turn.start\",\n\t\"pi.turn.end\",\n\t\"pi.tool.call\",\n\t\"pi.tool.result\",\n\t\"pi.label.changed\",\n\t\"pi.error\",\n\t\"pi.retry.start\",\n\t\"pi.retry.end\",\n\t\"pi.usage\",\n\t\"pi.compaction.start\",\n\t\"pi.compaction.end\",\n] as const;\n\n/** @internal */\nexport type StreamableWorkerEventType = (typeof STREAMABLE_WORKER_EVENT_TYPES)[number];\n\nconst STREAMABLE_EVENT_TYPES = new Set<string>(STREAMABLE_WORKER_EVENT_TYPES);\n\n/** @internal */\nexport function isStreamableEvent(eventType: string): eventType is StreamableWorkerEventType {\n\treturn STREAMABLE_EVENT_TYPES.has(eventType);\n}\n","/** @internal */\nexport interface TextPreview {\n\t/** @internal */\n\ttext: string;\n\t/** @internal */\n\ttruncated: boolean;\n}\n\n/** @internal */\nexport function truncateTextPreview(value: string, maxLength: number): TextPreview {\n\treturn value.length <= maxLength\n\t\t? { text: value, truncated: false }\n\t\t: { text: value.slice(0, maxLength).trimEnd(), truncated: true };\n}\n\n/** @internal */\nexport function buildTrailingLinePreview(\n\tvalue: string,\n\tlineCount: number,\n\tmaxLength: number,\n): TextPreview {\n\tconst lines = value.replace(/\\r\\n?/g, \"\\n\").split(\"\\n\");\n\tif (lines.length === 1 && lines[0] === \"\") return { text: \"\", truncated: false };\n\n\tlet text = lines.slice(-lineCount).join(\"\\n\");\n\tlet truncated = lines.length > lineCount;\n\tif (text.length > maxLength) {\n\t\ttext = text.slice(-maxLength);\n\t\ttruncated = true;\n\t}\n\tif (truncated) {\n\t\tconst previewLines = text.split(\"\\n\");\n\t\tpreviewLines[0] = previewLines[0] ? `… ${previewLines[0]}` : \"…\";\n\t\ttext = previewLines.join(\"\\n\");\n\t}\n\treturn { text, truncated };\n}\n","import type {\n\tProcessTimelineTurnPresentation,\n\tProcessTimelineTurnSummary,\n} from \"./http-contracts.js\";\nimport type { PrimaryPathActiveTurnSnapshot } from \"./primary-path-snapshot.js\";\n\n/** @internal */\nexport function timelinePresentationForTurnType(\n\tturnType: ProcessTimelineTurnSummary[\"turnType\"],\n): ProcessTimelineTurnPresentation {\n\tif (turnType === \"external\") return \"external_trigger\";\n\tif (turnType === \"human\") return \"operator_decision\";\n\treturn turnType === \"automatic\" ? \"automatic_turn\" : \"llm_turn\";\n}\n\n/** @internal */\nexport function buildActiveTimelineTurnSummary(\n\tactiveTurn: Pick<\n\t\tPrimaryPathActiveTurnSnapshot,\n\t\t\"turnRecordId\" | \"turnId\" | \"turnType\" | \"pathType\" | \"startedAt\" | \"assistant\"\n\t>,\n\tinput: {\n\t\t/** @internal */\n\t\tsummary: string;\n\t\t/** @internal */\n\t\toutput: string;\n\t\t/** @internal */\n\t\tactionSource?: ProcessTimelineTurnSummary[\"actionSource\"];\n\t} = { summary: `Current step: ${activeTurn.turnId}`, output: activeTurn.assistant.text.trim() },\n): ProcessTimelineTurnSummary {\n\treturn {\n\t\tid: activeTurn.turnRecordId,\n\t\tturnId: activeTurn.turnId,\n\t\tturnType: activeTurn.turnType,\n\t\tdisplayTurn: activeTurn.turnId,\n\t\toutcome: \"in_progress\",\n\t\tsummary: input.summary,\n\t\toutput: input.output,\n\t\tturnResultMarkdown: \"\",\n\t\tpathType: activeTurn.pathType,\n\t\tcreatedAt: activeTurn.startedAt,\n\t\tpresentation: timelinePresentationForTurnType(activeTurn.turnType),\n\t\tstatus: \"in_progress\",\n\t\tmodelProfileId: null,\n\t\tattemptNumber: 1,\n\t\tparentTurnRecordId: null,\n\t\tstartedAt: activeTurn.startedAt,\n\t\tendedAt: null,\n\t\tactionSource: input.actionSource ?? null,\n\t\tprogress: null,\n\t};\n}\n","import { asUnknownRecord } from \"@leitwerk-dev/domain\";\n\nconst TOOL_TRUNCATION_BOOLEAN_KEYS = [\n\t\"truncated\",\n\t\"isTruncated\",\n\t\"wasTruncated\",\n\t\"outputTruncated\",\n\t\"resultTruncated\",\n] as const;\nconst TOOL_TRUNCATION_TEXT_MARKERS = [\n\t\"output truncated\",\n\t\"result truncated\",\n\t\"response was too big\",\n\t\"too large to display\",\n\t\"truncated after\",\n\t\"truncated to last\",\n\t\"truncated since\",\n] as const;\n\nfunction readTruncationPayload(value: unknown): unknown {\n\tconst record = asUnknownRecord(value);\n\tif (!record) {\n\t\treturn null;\n\t}\n\tif (\"truncation\" in record) {\n\t\treturn record.truncation;\n\t}\n\tfor (const key of TOOL_TRUNCATION_BOOLEAN_KEYS) {\n\t\tif (key in record) {\n\t\t\treturn record[key];\n\t\t}\n\t}\n\treturn null;\n}\n\nfunction isExplicitFalseTruncationString(value: string): boolean {\n\tconst normalized = value.trim().toLowerCase();\n\treturn (\n\t\tnormalized === \"\" ||\n\t\tnormalized === \"false\" ||\n\t\tnormalized === \"none\" ||\n\t\tnormalized === \"null\" ||\n\t\tnormalized === \"no\" ||\n\t\tnormalized === \"0\"\n\t);\n}\n\nfunction isTruthyTruncationValue(value: unknown): boolean {\n\tif (value === null || value === undefined) {\n\t\treturn false;\n\t}\n\tif (typeof value === \"boolean\") {\n\t\treturn value;\n\t}\n\tif (typeof value === \"number\") {\n\t\treturn Number.isFinite(value) && value > 0;\n\t}\n\tif (typeof value === \"string\") {\n\t\treturn !isExplicitFalseTruncationString(value);\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.length > 0;\n\t}\n\tconst record = asUnknownRecord(value);\n\tif (!record) {\n\t\treturn true;\n\t}\n\tfor (const key of TOOL_TRUNCATION_BOOLEAN_KEYS) {\n\t\tif (record[key] === true) {\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn Object.keys(record).some((key) => {\n\t\tif (\n\t\t\tTOOL_TRUNCATION_BOOLEAN_KEYS.includes(key as (typeof TOOL_TRUNCATION_BOOLEAN_KEYS)[number])\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\treturn isTruthyTruncationValue(record[key]);\n\t});\n}\n\n/** @internal */\nexport function isToolResultTruncated(input: {\n\t/** @internal */\n\tresultText: string | null;\n\t/** @internal */\n\tresultDetails: unknown;\n\t/** @internal */\n\tresultValue: unknown;\n}): boolean {\n\tconst normalizedText = input.resultText?.toLowerCase() ?? \"\";\n\treturn (\n\t\tTOOL_TRUNCATION_TEXT_MARKERS.some((marker) => normalizedText.includes(marker)) ||\n\t\tisTruthyTruncationValue(readTruncationPayload(input.resultDetails)) ||\n\t\tisTruthyTruncationValue(readTruncationPayload(input.resultValue))\n\t);\n}\n","import { trimToNull } from \"@leitwerk-dev/domain\";\nimport {\n\textractPiSessionMessageText,\n\tisPiSessionMessageEntryType,\n\tisPiSessionMessageEntryWithRecord,\n} from \"./pi-session-message.js\";\nimport type { ReadonlyEntryTree } from \"./session-entry-tree.js\";\nimport { compareTimestampStrings, happenedOnOrAfterStart } from \"./timestamp-ordering.js\";\n\n/** @internal */\nexport interface ContinuationTreeEntry {\n\t/** @internal */\n\tid: string;\n\t/** @internal */\n\tparentId: string | null;\n\t/** @internal */\n\ttimestamp: string;\n\t/** @internal */\n\ttype: string;\n\t/** @internal */\n\tmessage?: {\n\t\t/** @internal */\n\t\trole?: string;\n\t\t/** @internal */\n\t\tcontent?: unknown;\n\t};\n}\n\n/** @internal */\nexport interface ContinuationTurnRecordLike {\n\t/** @internal */\n\tforkPiEntryId?: string | null;\n\t/** @internal */\n\tresultPiEntryId?: string | null;\n\t/** @internal */\n\tstartedAt?: string | null;\n\t/** @internal */\n\tstatus?: string | null;\n}\n\n/** @internal */\nexport interface ContinuationSliceBounds {\n\t/** @internal */\n\tendedAt?: string | null;\n}\n\n/** @internal */\nexport interface TurnContinuationIndex<TEntry extends ContinuationTreeEntry> {\n\t/** @internal */\n\tresolveLeafEntryId(\n\t\tturnRecord: ContinuationTurnRecordLike,\n\t\tbounds?: ContinuationSliceBounds,\n\t): string | null;\n\t/** @internal */\n\tbuildSlice(turnRecord: ContinuationTurnRecordLike, bounds?: ContinuationSliceBounds): TEntry[];\n}\n\nfunction branchContainsAncestor(\n\tentriesById: ReadonlyMap<string, ContinuationTreeEntry>,\n\tentryId: string,\n\tancestorId: string,\n): boolean {\n\tconst visited = new Set<string>();\n\tlet current = entriesById.get(entryId);\n\twhile (current) {\n\t\tif (visited.has(current.id)) {\n\t\t\treturn false;\n\t\t}\n\t\tvisited.add(current.id);\n\t\tif (current.id === ancestorId) {\n\t\t\treturn true;\n\t\t}\n\t\tcurrent = current.parentId ? entriesById.get(current.parentId) : undefined;\n\t}\n\treturn false;\n}\n\nfunction happenedOnOrBeforeEnd(entryTimestamp: string, endedAt: string | null): boolean {\n\tif (!endedAt) {\n\t\treturn true;\n\t}\n\treturn compareTimestampStrings(entryTimestamp, endedAt) <= 0;\n}\n\nfunction isContinuableEntryWithinBounds(\n\tentry: ContinuationTreeEntry | undefined,\n\tstartedAt: string | null,\n\tendedAt: string | null,\n): entry is ContinuationTreeEntry {\n\treturn (\n\t\t(isPiSessionMessageEntryType(entry) || entry?.type === \"compaction\") &&\n\t\thappenedOnOrAfterStart(entry.timestamp, startedAt) &&\n\t\thappenedOnOrBeforeEnd(entry.timestamp, endedAt)\n\t);\n}\n\nfunction isExplicitLeafUsable(\n\tentriesById: ReadonlyMap<string, ContinuationTreeEntry>,\n\tleafId: string,\n\tforkPiEntryId: string | null,\n\tstartedAt: string | null,\n\tendedAt: string | null,\n): boolean {\n\tconst leafEntry = entriesById.get(leafId);\n\tif (!isContinuableEntryWithinBounds(leafEntry, startedAt, endedAt)) {\n\t\treturn false;\n\t}\n\treturn !forkPiEntryId || branchContainsAncestor(entriesById, leafId, forkPiEntryId);\n}\n\nfunction findLatestContinuableEntryIdOnBranch(\n\tentries: readonly ContinuationTreeEntry[],\n\tentriesById: ReadonlyMap<string, ContinuationTreeEntry>,\n\toptions: { startedAt: string | null; endedAt: string | null; ancestorId: string | null },\n): string | null {\n\tfor (let index = entries.length - 1; index >= 0; index -= 1) {\n\t\tconst entry = entries[index];\n\t\tif (!isContinuableEntryWithinBounds(entry, options.startedAt, options.endedAt)) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (options.ancestorId && !branchContainsAncestor(entriesById, entry.id, options.ancestorId)) {\n\t\t\tcontinue;\n\t\t}\n\t\treturn entry.id;\n\t}\n\treturn null;\n}\n\nfunction resolveTurnContinuationLeafEntryIdFromIndex(\n\tentries: readonly ContinuationTreeEntry[],\n\tentriesById: ReadonlyMap<string, ContinuationTreeEntry>,\n\tturnRecord: ContinuationTurnRecordLike,\n\tbounds: ContinuationSliceBounds = {},\n): string | null {\n\tconst startedAt = trimToNull(turnRecord.startedAt);\n\tconst endedAt = trimToNull(bounds.endedAt);\n\tconst forkPiEntryId = trimToNull(turnRecord.forkPiEntryId);\n\tconst explicitLeafId = trimToNull(turnRecord.resultPiEntryId);\n\tif (\n\t\texplicitLeafId &&\n\t\tisExplicitLeafUsable(entriesById, explicitLeafId, forkPiEntryId, startedAt, endedAt)\n\t) {\n\t\tif (turnRecord.status !== \"failed\") {\n\t\t\treturn explicitLeafId;\n\t\t}\n\t\treturn findLatestContinuableEntryIdOnBranch(entries, entriesById, {\n\t\t\tstartedAt,\n\t\t\tendedAt,\n\t\t\tancestorId: explicitLeafId,\n\t\t});\n\t}\n\n\treturn findLatestContinuableEntryIdOnBranch(entries, entriesById, {\n\t\tstartedAt,\n\t\tendedAt,\n\t\tancestorId: forkPiEntryId,\n\t});\n}\n\n/** @internal */\nexport function createTurnContinuationIndex<TEntry extends ContinuationTreeEntry>(\n\tentries: readonly TEntry[],\n): TurnContinuationIndex<TEntry> {\n\tconst entriesById = new Map(entries.map((entry) => [entry.id, entry]));\n\n\tconst resolveLeafEntryId = (\n\t\tturnRecord: ContinuationTurnRecordLike,\n\t\tbounds: ContinuationSliceBounds = {},\n\t): string | null =>\n\t\tresolveTurnContinuationLeafEntryIdFromIndex(entries, entriesById, turnRecord, bounds);\n\n\tconst buildSlice = (\n\t\tturnRecord: ContinuationTurnRecordLike,\n\t\tbounds: ContinuationSliceBounds = {},\n\t): TEntry[] => {\n\t\tconst continuationLeafId = resolveLeafEntryId(turnRecord, bounds);\n\t\tif (!continuationLeafId) {\n\t\t\treturn [];\n\t\t}\n\t\tconst forkPiEntryId = trimToNull(turnRecord.forkPiEntryId);\n\t\tconst reversedSlice: TEntry[] = [];\n\t\tconst visited = new Set<string>();\n\t\tlet current = entriesById.get(continuationLeafId);\n\t\tlet foundFork = forkPiEntryId === null;\n\t\twhile (current && !visited.has(current.id)) {\n\t\t\tvisited.add(current.id);\n\t\t\tif (current.id === forkPiEntryId) {\n\t\t\t\tfoundFork = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\treversedSlice.push(current);\n\t\t\tcurrent = current.parentId ? entriesById.get(current.parentId) : undefined;\n\t\t}\n\t\tif (!foundFork) {\n\t\t\treturn [];\n\t\t}\n\t\tconst startedAt = trimToNull(turnRecord.startedAt);\n\t\tconst endedAt = trimToNull(bounds.endedAt);\n\t\treturn reversedSlice\n\t\t\t.reverse()\n\t\t\t.filter(\n\t\t\t\t(entry) =>\n\t\t\t\t\thappenedOnOrAfterStart(entry.timestamp, startedAt) &&\n\t\t\t\t\thappenedOnOrBeforeEnd(entry.timestamp, endedAt),\n\t\t\t);\n\t};\n\n\treturn { resolveLeafEntryId, buildSlice };\n}\n\n/** @internal */\nexport function resolveTurnContinuationLeafEntryId(\n\tentries: readonly ContinuationTreeEntry[],\n\tturnRecord: ContinuationTurnRecordLike,\n\tbounds: ContinuationSliceBounds = {},\n): string | null {\n\treturn createTurnContinuationIndex(entries).resolveLeafEntryId(turnRecord, bounds);\n}\n\n/** @internal */\nexport function buildTurnContinuationSliceFromTree<TEntry extends ContinuationTreeEntry>(\n\ttree: ReadonlyEntryTree<TEntry>,\n\tturnRecord: ContinuationTurnRecordLike,\n\tbounds: ContinuationSliceBounds = {},\n): TEntry[] {\n\treturn createTurnContinuationIndex(tree.entries).buildSlice(turnRecord, bounds);\n}\n\n/** @internal */\nexport function buildTurnContinuationSlice<TEntry extends ContinuationTreeEntry>(\n\tentries: readonly TEntry[],\n\tturnRecord: ContinuationTurnRecordLike,\n\tbounds: ContinuationSliceBounds = {},\n): TEntry[] {\n\treturn createTurnContinuationIndex(entries).buildSlice(turnRecord, bounds);\n}\n\n/** @internal */\nexport interface BranchUserPromptSnapshot {\n\t/** @internal */\n\ttext: string | null;\n\t/** @internal */\n\tcreatedAt: string | null;\n}\n\n/** @internal */\nexport function extractFirstUserPromptOnBranch<TEntry extends ContinuationTreeEntry>(\n\ttree: ReadonlyEntryTree<TEntry>,\n\tleafId: string | null | undefined,\n): BranchUserPromptSnapshot {\n\tconst resolvedLeafId = trimToNull(leafId);\n\tif (!resolvedLeafId) {\n\t\treturn { text: null, createdAt: null };\n\t}\n\tconst branch = tree.getBranch(resolvedLeafId);\n\tfor (const entry of branch) {\n\t\tif (!isPiSessionMessageEntryWithRecord(entry) || entry.message.role !== \"user\") {\n\t\t\tcontinue;\n\t\t}\n\t\tconst text = extractPiSessionMessageText(entry.message.content).trim();\n\t\tif (text === \"\") {\n\t\t\tcontinue;\n\t\t}\n\t\treturn {\n\t\t\ttext,\n\t\t\tcreatedAt: entry.timestamp,\n\t\t};\n\t}\n\treturn { text: null, createdAt: null };\n}\n\n/** @internal */\nexport function resolveTurnContinuationUserPrompt(\n\tentries: readonly ContinuationTreeEntry[],\n\tturnRecord: ContinuationTurnRecordLike,\n\tbounds: ContinuationSliceBounds = {},\n): string | null {\n\tconst continuationLeafId = resolveTurnContinuationLeafEntryId(entries, turnRecord, bounds);\n\tif (!continuationLeafId) {\n\t\treturn null;\n\t}\n\tconst continuationLeaf = new Map(entries.map((entry) => [entry.id, entry])).get(\n\t\tcontinuationLeafId,\n\t);\n\tif (\n\t\t!isPiSessionMessageEntryWithRecord(continuationLeaf) ||\n\t\tcontinuationLeaf.message.role !== \"user\"\n\t) {\n\t\treturn null;\n\t}\n\tconst promptText = extractPiSessionMessageText(continuationLeaf.message.content).trim();\n\treturn promptText !== \"\" ? promptText : null;\n}\n\n/** @internal */\nexport function hasTurnContinuationProgress(\n\tentries: readonly ContinuationTreeEntry[],\n\tturnRecord: ContinuationTurnRecordLike,\n\tbounds: ContinuationSliceBounds = {},\n): boolean {\n\treturn resolveTurnContinuationLeafEntryId(entries, turnRecord, bounds) !== null;\n}\n","import type { TurnTraceSnapshot } from \"./http-contracts.js\";\nimport {\n\ttype MutableLiveTurnProjection,\n\tsnapshotLiveTurnProjection,\n} from \"./live-turn-projection.js\";\nimport { extractPiSessionMessageText } from \"./pi-session-message.js\";\nimport { isToolResultTruncated } from \"./tool-result-truncation.js\";\n\n/** Share the recorded tool content presentation between live HTTP history and live frames. @internal */\nexport function snapshotTurnTrace(\n\tprojection: MutableLiveTurnProjection,\n\tpiInput: TurnTraceSnapshot[\"piInput\"] = null,\n): TurnTraceSnapshot {\n\tconst snapshot = snapshotLiveTurnProjection(projection);\n\treturn {\n\t\t...snapshot,\n\t\tpiInput,\n\t\ttoolCalls: snapshot.toolCalls.map(({ result, ...tool }) => {\n\t\t\tconst record =\n\t\t\t\tresult && typeof result === \"object\" ? (result as Record<string, unknown>) : null;\n\t\t\tconst resultText =\n\t\t\t\tresult == null\n\t\t\t\t\t? null\n\t\t\t\t\t: typeof result === \"string\"\n\t\t\t\t\t\t? result\n\t\t\t\t\t\t: record && \"content\" in record\n\t\t\t\t\t\t\t? extractPiSessionMessageText(record.content)\n\t\t\t\t\t\t\t: JSON.stringify(result, null, 2);\n\t\t\treturn {\n\t\t\t\t...tool,\n\t\t\t\tresultText,\n\t\t\t\ttruncated:\n\t\t\t\t\t(\"truncated\" in tool && tool.truncated === true) ||\n\t\t\t\t\tisToolResultTruncated({\n\t\t\t\t\t\tresultText,\n\t\t\t\t\t\tresultDetails: record?.details,\n\t\t\t\t\t\tresultValue: result,\n\t\t\t\t\t}),\n\t\t\t};\n\t\t}),\n\t};\n}\n","import type { ProcessEvent } from \"@leitwerk-dev/domain\";\nimport {\n\tmergeUsageSnapshots,\n\tnormalizeUsageSnapshot,\n\ttype UsageSnapshot,\n} from \"./usage-snapshot.js\";\nimport { asWsEventPayloadRecord, readWsEventTurnRecordId } from \"./ws-event-payloads.js\";\n\n/** @internal */\nexport type UsageSnapshotByTurnRecordId = Record<string, UsageSnapshot>;\n\n/** @internal */\nexport function buildUsageSnapshotsByTurnRecordId(\n\tevents: readonly ProcessEvent[],\n): UsageSnapshotByTurnRecordId {\n\tconst snapshots: UsageSnapshotByTurnRecordId = {};\n\tfor (const event of events) {\n\t\tif (event.eventType !== \"pi.usage\") {\n\t\t\tcontinue;\n\t\t}\n\t\tconst payload = asWsEventPayloadRecord(event.data);\n\t\tconst turnRecordId = readWsEventTurnRecordId(payload);\n\t\tif (!turnRecordId) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst usage = normalizeUsageSnapshot(payload);\n\t\tif (!usage) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst merged = mergeUsageSnapshots(snapshots[turnRecordId] ?? null, usage);\n\t\tif (merged) {\n\t\t\tsnapshots[turnRecordId] = merged;\n\t\t}\n\t}\n\treturn snapshots;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,6BAA6B,2BAA2B;AACjE,YAAY,OAAO;AA0CnB,SAAS,iBAAiB,OAAoC;AAC7D,SAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ;AACtE;AAEA,SAAS,2BAA2B,OAA0C;AAC7E,QAAM,cAAgB,YAAU,qBAAqB,KAAK;AAC1D,MAAI,CAAC,YAAY,SAAS;AACzB,WAAO;AAAA,EACR;AACA,QAAM,SAAS,YAAY;AAC3B,QAAM,QAAQ,iBAAiB,OAAO,KAAK,KAAK;AAChD,QAAM,SAAS,iBAAiB,OAAO,MAAM,KAAK;AAClD,QAAM,YAAY,iBAAiB,OAAO,SAAS,KAAK;AACxD,QAAM,aAAa,iBAAiB,OAAO,UAAU,KAAK;AAC1D,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,iBAAiB,OAAO,KAAK,KAAK,QAAQ,SAAS,YAAY;AAAA,EACvE;AACD;AAGO,SAAS,mBAAmB,OAA+D;AACjG,MAAI,CAAC,OAAO;AACX,WAAO;AAAA,EACR;AACA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,MAAM,MAAM,OAAO,EAAE,GAAG,MAAM,KAAK,IAAI;AAAA,EACxC;AACD;AAGO,SAAS,uBAAuB,OAAsC;AAC5E,QAAM,cAAgB,YAAU,qBAAqB,KAAK;AAC1D,MAAI,CAAC,YAAY,SAAS;AACzB,WAAO;AAAA,EACR;AACA,QAAM,SAAS,YAAY;AAC3B,QAAM,QAAQ,iBAAiB,OAAO,KAAK,KAAK;AAChD,QAA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A,IACD,CAAC;AAAA,EACF;AACD;;;AC7BO,SAAS,kCACf,QAC8B;AAC9B,QAAM,YAAyC,CAAC;AAChD,aAAW,SAAS,QAAQ;AAC3B,QAAI,MAAM,cAAc,YAAY;AACnC;AAAA,IACD;AACA,UAAM,UAAU,uBAAuB,MAAM,IAAI;AACjD,UAAM,eAAe,wBAAwB,OAAO;AACpD,QAAI,CAAC,cAAc;AAClB;AAAA,IACD;AACA,UAAM,QAAQ,uBAAuB,OAAO;AAC5C,QAAI,CAAC,OAAO;AACX;AAAA,IACD;AACA,UAAM,SAAS,oBAAoB,UAAU,YAAY,KAAK,MAAM,KAAK;AACzE,QAAI,QAAQ;AACX,gBAAU,YAAY,IAAI;AAAA,IAC3B;AAAA,EACD;AACA,SAAO;AACR;","names":["v","asUnknownRecord"]}
@@ -1,8 +1,14 @@
1
1
  import type { FutureExecutionOverviewItem, FutureExecutionSummary } from "./http-contracts.js";
2
+ /** @internal */
2
3
  export declare const INITIAL_PROMPT_FIELD_PRIORITY: readonly ["initialPrompt", "prompt", "taskPrompt", "userPrompt", "instructions", "instruction", "initialCommand", "command", "query", "message", "requestedChange", "request", "description"];
4
+ /** @internal */
3
5
  export declare function truncatePromptPreview(value: string | null | undefined, maxLength?: number): string | null;
6
+ /** @internal */
4
7
  export declare function extractInitialPromptFromValue(value: unknown): string | null;
8
+ /** @internal */
5
9
  export declare function extractInitialPromptFromParamsJson(paramsJson: string | null | undefined): string | null;
10
+ /** @internal */
6
11
  export declare function extractInitialPromptPreviewFromParamsJson(paramsJson: string | null | undefined, maxLength?: number): string | null;
12
+ /** @internal */
7
13
  export declare function projectFutureExecutionOverview(summary: FutureExecutionSummary): FutureExecutionOverviewItem;
8
14
  //# sourceMappingURL=initial-prompt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"initial-prompt.d.ts","sourceRoot":"","sources":["../src/initial-prompt.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,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gBAAgB;AAChB,wBAAgB,8BAA8B,CAC7C,OAAO,EAAE,sBAAsB,GAC7B,2BAA2B,CA8B7B"}
@@ -0,0 +1,2 @@
1
+ export type { LauncherCardMetadata, LauncherFieldDefinition, LauncherFieldOptionDefinition, LauncherSchemaDefinition, LauncherValidationError, UiLauncherSummaryBase, } from "./launcher-contract.js";
2
+ //# sourceMappingURL=launcher-contract-public.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"launcher-contract-public.d.ts","sourceRoot":"","sources":["../src/launcher-contract-public.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,oBAAoB,EACpB,uBAAuB,EACvB,6BAA6B,EAC7B,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,GACrB,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=launcher-contract-public.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,34 +1,59 @@
1
1
  import type { FormDefinition, FormFieldDefinition, FormFieldOptionDefinition } from "./form-contract.js";
2
+ /** @public */
2
3
  export interface LauncherCardMetadata {
4
+ /** @public */
3
5
  title?: string;
6
+ /** @public */
4
7
  description?: string;
5
8
  }
9
+ /** @public */
6
10
  export type LauncherFieldOptionDefinition = FormFieldOptionDefinition;
11
+ /** @public */
7
12
  export type LauncherFieldDefinition = FormFieldDefinition;
13
+ /** @public */
8
14
  export type LauncherSchemaDefinition = FormDefinition<LauncherFieldDefinition>;
15
+ /** @public */
9
16
  export interface LauncherValidationError {
17
+ /** @public */
10
18
  code: string;
19
+ /** @public */
11
20
  message: string;
21
+ /** @public */
12
22
  fieldId?: string;
13
23
  }
24
+ /** @internal */
14
25
  export interface SkillOptionSummary {
26
+ /** @internal */
15
27
  id: string;
28
+ /** @internal */
16
29
  label: string;
30
+ /** @internal */
17
31
  description: string | null;
18
32
  }
33
+ /** @internal */
19
34
  export interface SkillSelection {
35
+ /** @internal */
20
36
  skillId: string;
37
+ /** @internal */
21
38
  revisionId: string;
22
39
  }
40
+ /** @internal */
23
41
  export interface UiLauncherSummaryBase {
42
+ /** @internal */
24
43
  id: string;
44
+ /** @internal */
25
45
  processId: string;
46
+ /** @internal */
26
47
  displayName: string;
48
+ /** @internal */
27
49
  label: string;
50
+ /** @internal */
28
51
  description: string;
52
+ /** @internal */
29
53
  card: LauncherCardMetadata;
54
+ /** @internal */
30
55
  launchConfigSchema: LauncherSchemaDefinition;
31
- /** Safe summaries of currently available opt-in skills. */
56
+ /** Safe summaries of currently available opt-in skills. @internal */
32
57
  skills?: readonly SkillOptionSummary[];
33
58
  }
34
59
  //# sourceMappingURL=launcher-contract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"launcher-contract.d.ts","sourceRoot":"","sources":["../src/launcher-contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,cAAc,EACd,mBAAmB,EACnB,yBAAyB,EACzB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,oBAAoB;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,6BAA6B,GAAG,yBAAyB,CAAC;AACtE,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,CAAC;AAC1D,MAAM,MAAM,wBAAwB,GAAG,cAAc,CAAC,uBAAuB,CAAC,CAAC;AAE/E,MAAM,WAAW,uBAAuB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,oBAAoB,CAAC;IAC3B,kBAAkB,EAAE,wBAAwB,CAAC;IAC7C,2DAA2D;IAC3D,MAAM,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAC;CACvC"}
1
+ {"version":3,"file":"launcher-contract.d.ts","sourceRoot":"","sources":["../src/launcher-contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,cAAc,EACd,mBAAmB,EACnB,yBAAyB,EACzB,MAAM,oBAAoB,CAAC;AAE5B,cAAc;AACd,MAAM,WAAW,oBAAoB;IACpC,cAAc;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,cAAc;AACd,MAAM,MAAM,6BAA6B,GAAG,yBAAyB,CAAC;AACtE,cAAc;AACd,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,CAAC;AAC1D,cAAc;AACd,MAAM,MAAM,wBAAwB,GAAG,cAAc,CAAC,uBAAuB,CAAC,CAAC;AAE/E,cAAc;AACd,MAAM,WAAW,uBAAuB;IACvC,cAAc;IACd,IAAI,EAAE,MAAM,CAAC;IACb,cAAc;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,gBAAgB;AAChB,MAAM,WAAW,kBAAkB;IAClC,gBAAgB;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB;IAChB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,gBAAgB;AAChB,MAAM,WAAW,cAAc;IAC9B,gBAAgB;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB;IAChB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,gBAAgB;AAChB,MAAM,WAAW,qBAAqB;IACrC,gBAAgB;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB;IAChB,IAAI,EAAE,oBAAoB,CAAC;IAC3B,gBAAgB;IAChB,kBAAkB,EAAE,wBAAwB,CAAC;IAC7C,qEAAqE;IACrE,MAAM,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAC;CACvC"}
@@ -1,2 +1 @@
1
- import "./chunk-IEMT3JG4.js";
2
1
  //# sourceMappingURL=launcher-contract.js.map
@@ -2,38 +2,67 @@ import { type ProcessEvent } from "@leitwerk-dev/domain";
2
2
  import type { PrimaryPathOperationalTraceItemSnapshot, PrimaryPathStreamingAssistantSnapshot, PrimaryPathToolCallSnapshot, PrimaryPathTraceItemSnapshot } from "./primary-path-snapshot.js";
3
3
  import { type UsageSnapshot } from "./usage-snapshot.js";
4
4
  import { type WsEventPayloadRecord } from "./ws-event-payloads.js";
5
+ /** @internal */
5
6
  export interface MutableLiveTurnProjection {
7
+ /** @internal */
6
8
  assistant: PrimaryPathStreamingAssistantSnapshot;
9
+ /** @internal */
7
10
  toolCalls: PrimaryPathToolCallSnapshot[];
11
+ /** @internal */
8
12
  traceItems: PrimaryPathTraceItemSnapshot[];
13
+ /** @internal */
9
14
  usage: UsageSnapshot | null;
15
+ /** @internal */
10
16
  toolCallsById: Map<string, PrimaryPathToolCallSnapshot>;
17
+ /** @internal */
11
18
  openToolCallIdsByName: Map<string, string[]>;
19
+ /** @internal */
12
20
  nextFallbackOrdinal: number;
13
21
  }
22
+ /** @internal */
14
23
  export interface AppliedLiveTurnProjectionEvent {
24
+ /** @internal */
15
25
  canonicalData: WsEventPayloadRecord;
26
+ /** @internal */
16
27
  timestamp: string;
28
+ /** @internal */
17
29
  toolCallId: string | null;
30
+ /** @internal */
18
31
  toolName: string | null;
19
32
  }
33
+ /** @internal */
20
34
  export declare const PRIMARY_PATH_OPERATIONAL_PI_EVENT_TYPES: readonly ["pi.error", "pi.retry.start", "pi.retry.end", "pi.compaction.start", "pi.compaction.end"];
35
+ /** @internal */
21
36
  export declare function buildPrimaryPathOperationalTraceItem(input: {
37
+ /** @internal */
22
38
  eventType: string;
39
+ /** @internal */
23
40
  data: WsEventPayloadRecord;
41
+ /** @internal */
24
42
  fallbackTimestamp: string;
25
43
  }): PrimaryPathOperationalTraceItemSnapshot | null;
44
+ /** @internal */
26
45
  export declare function createMutableLiveTurnProjection(): MutableLiveTurnProjection;
46
+ /** @internal */
27
47
  export declare function snapshotLiveTurnProjection(projection: MutableLiveTurnProjection): {
48
+ /** @internal */
28
49
  assistant: PrimaryPathStreamingAssistantSnapshot;
50
+ /** @internal */
29
51
  toolCalls: PrimaryPathToolCallSnapshot[];
52
+ /** @internal */
30
53
  traceItems: PrimaryPathTraceItemSnapshot[];
54
+ /** @internal */
31
55
  usage: UsageSnapshot | null;
32
56
  };
57
+ /** @internal */
33
58
  export declare function applyPiEventToLiveTurnProjection(projection: MutableLiveTurnProjection, input: {
59
+ /** @internal */
34
60
  eventType: string;
61
+ /** @internal */
35
62
  data: WsEventPayloadRecord;
63
+ /** @internal */
36
64
  fallbackTimestamp: string;
37
65
  }): AppliedLiveTurnProjectionEvent;
66
+ /** @internal */
38
67
  export declare function buildLiveTurnProjectionFromEvents(events: readonly ProcessEvent[]): MutableLiveTurnProjection;
39
68
  //# sourceMappingURL=live-turn-projection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"live-turn-projection.d.ts","sourceRoot":"","sources":["../src/live-turn-projection.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,YAAY,EAGjB,MAAM,sB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+ /** @internal */
3
6
  content?: unknown;
7
+ /** @internal */
4
8
  details?: unknown;
9
+ /** @internal */
5
10
  toolCallId?: unknown;
11
+ /** @internal */
6
12
  toolName?: unknown;
13
+ /** @internal */
7
14
  isError?: unknown;
15
+ /** @internal */
8
16
  usage?: unknown;
9
17
  }
18
+ /** @internal */
10
19
  export interface PiSessionMessageEntryLike {
20
+ /** @internal */
11
21
  type?: unknown;
22
+ /** @internal */
12
23
  message?: unknown;
13
24
  }
25
+ /** @internal */
14
26
  export declare function isPiSessionMessageEntryType<TEntry extends {
27
+ /** @internal */
15
28
  type?: unknown;
16
29
  }>(entry: TEntry | undefined): entry is TEntry & {
17
30
  type: "message";
18
31
  };
32
+ /** @internal */
19
33
  export declare function isPiSessionMessageRecord(value: unknown): value is PiSessionMessageLike;
34
+ /** @internal */
20
35
  export declare function isPiSessionMessageEntryWithRecord<TEntry extends PiSessionMessageEntryLike>(entry: TEntry | undefined): entry is TEntry & {
21
36
  type: "message";
22
37
  message: NonNullable<TEntry["message"]>;
23
38
  };
39
+ /** @internal */
24
40
  export declare function extractPiSessionMessageText(content: unknown): string;
25
41
  //# sourceMappingURL=pi-session-message.d.ts.map