@opengeni/react 0.36.0 → 0.37.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 (45) hide show
  1. package/README.md +4 -0
  2. package/dist/{chunk-J2RVJ6JX.js → chunk-4IJCL7YO.js} +13 -2
  3. package/dist/chunk-4IJCL7YO.js.map +1 -0
  4. package/dist/{chunk-OKKMZDQF.js → chunk-FSPDND3P.js} +2 -2
  5. package/dist/{chunk-FT2TXNGZ.js → chunk-HJ4OQVGW.js} +174 -14
  6. package/dist/chunk-HJ4OQVGW.js.map +1 -0
  7. package/dist/{chunk-PVW56EVR.js → chunk-IP22SLO6.js} +447 -13
  8. package/dist/chunk-IP22SLO6.js.map +1 -0
  9. package/dist/{chunk-U255M5EZ.js → chunk-SJKT4TKW.js} +39 -6
  10. package/dist/chunk-SJKT4TKW.js.map +1 -0
  11. package/dist/{chunk-XT7JF2EH.js → chunk-UCZPNXV3.js} +96 -17
  12. package/dist/chunk-UCZPNXV3.js.map +1 -0
  13. package/dist/components/chat-composer.d.ts +3 -1
  14. package/dist/components/model-policy-picker.d.ts +78 -0
  15. package/dist/components/session-chrome.d.ts +1 -1
  16. package/dist/composer.d.ts +2 -0
  17. package/dist/composer.js +17 -3
  18. package/dist/hooks/use-composer.d.ts +9 -0
  19. package/dist/index.d.ts +3 -1
  20. package/dist/index.js +30 -9
  21. package/dist/index.js.map +1 -1
  22. package/dist/model-policy.d.ts +12 -4
  23. package/dist/model-policy.js +5 -1
  24. package/dist/session-ui.js +2 -2
  25. package/dist/session.js +3 -3
  26. package/dist/timeline/types.d.ts +5 -0
  27. package/package.json +2 -2
  28. package/src/components/chat-composer.tsx +8 -3
  29. package/src/components/composer.tsx +17 -1
  30. package/src/components/copy-button.tsx +13 -6
  31. package/src/components/model-picker.tsx +2 -2
  32. package/src/components/model-policy-picker.tsx +582 -0
  33. package/src/components/session-chrome.tsx +138 -14
  34. package/src/composer.ts +13 -0
  35. package/src/hooks/use-composer.ts +213 -16
  36. package/src/index.ts +15 -0
  37. package/src/model-policy.ts +69 -14
  38. package/src/timeline/projection.ts +21 -1
  39. package/src/timeline/types.ts +5 -0
  40. package/dist/chunk-FT2TXNGZ.js.map +0 -1
  41. package/dist/chunk-J2RVJ6JX.js.map +0 -1
  42. package/dist/chunk-PVW56EVR.js.map +0 -1
  43. package/dist/chunk-U255M5EZ.js.map +0 -1
  44. package/dist/chunk-XT7JF2EH.js.map +0 -1
  45. /package/dist/{chunk-OKKMZDQF.js.map → chunk-FSPDND3P.js.map} +0 -0
package/README.md CHANGED
@@ -290,6 +290,10 @@ intentional changes should regenerate those snapshots and review the diff.
290
290
  - `FleetTile` — one session in a fleet grid: title, status, model, recency.
291
291
  - `ModelPicker` — a compact model dropdown for a composer slot, grouping the
292
292
  host-exposed models by provider.
293
+ - `ModelPolicyPicker` — the full model policy control used by the OpenGeni web
294
+ app: provider/billing rails, model availability, reasoning effort, and
295
+ runnable latency modes such as Fast. It accepts either `ClientModel[]` or
296
+ catalog-backed `PickerModelRow[]`, and supports host-supplied labels.
293
297
  - `Markdown` — the timeline's markdown renderer (GFM), also usable standalone.
294
298
  - `CommandPalette` — the slash-command palette UI over `useSlashCommands`.
295
299
 
@@ -76,10 +76,12 @@ function buildTimeline(events) {
76
76
  });
77
77
  break;
78
78
  }
79
+ const voiceMessage = realtimeVoiceMessage(payload);
79
80
  items.push({
80
81
  kind: "user-message",
81
82
  id: event.id,
82
- text: stringValue(payload.text),
83
+ text: voiceMessage?.text ?? stringValue(payload.text),
84
+ ...voiceMessage ? { presentation: voiceMessage.presentation } : {},
83
85
  resources: resourceRefs(payload.resources),
84
86
  tools: toolRefs(payload.tools),
85
87
  occurredAt: event.occurredAt
@@ -498,6 +500,15 @@ ${message}` : message;
498
500
  }
499
501
  return items;
500
502
  }
503
+ function realtimeVoiceMessage(payload) {
504
+ const presentation = asRecord(payload.presentation);
505
+ const visibleText = stringValue(payload.text);
506
+ if (presentation.kind === "realtime_voice" || presentation.kind === "realtime_voice_handoff") {
507
+ const context = stringValue(presentation.context);
508
+ return visibleText && context ? { text: visibleText, presentation: { kind: presentation.kind, context } } : null;
509
+ }
510
+ return null;
511
+ }
501
512
  function providerNativeToolStatus(rawValue) {
502
513
  const raw = asRecord(rawValue);
503
514
  if (raw.type !== "hosted_tool_call") {
@@ -1158,4 +1169,4 @@ export {
1158
1169
  groupTimeline,
1159
1170
  extractSessionRef
1160
1171
  };
1161
- //# sourceMappingURL=chunk-J2RVJ6JX.js.map
1172
+ //# sourceMappingURL=chunk-4IJCL7YO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/timeline/tool-display-name.ts","../src/timeline/projection.ts"],"sourcesContent":["/**\n * MCP / first-party tool naming helpers.\n *\n * Wire names are often `<serverId>__<toolName>` (see prefixedMcpToolName).\n * Matching and titles must use the leaf tool name so `opengeni__session_create`\n * and bare `session_create` resolve the same UI — without inventing previews\n * from argument JSON.\n */\n\n/** Leaf tool name after the first `__` server boundary (or the whole name). */\nexport function mcpToolLeaf(name: string): string {\n const boundary = name.indexOf(\"__\");\n return boundary >= 0 ? name.slice(boundary + 2) : name;\n}\n\n/**\n * True when `wireName` is exactly `leaf` or ends with `__${leaf}` (MCP prefix).\n * Does not treat arbitrary suffixes as matches — the leaf must be the full\n * right-hand side after `__`.\n */\nexport function toolMatchesLeaf(wireName: string, leaf: string): boolean {\n return wireName === leaf || wireName.endsWith(`__${leaf}`);\n}\n\n/**\n * Readable label for a tool call (\"session_create\" / \"opengeni__session_create\"\n * → \"Session create\"). Title-cases the first character of the leaf phrase.\n */\nexport function toolDisplayName(name: string): string {\n const phrase = mcpToolLeaf(name).replace(/[_-]+/g, \" \").trim();\n if (!phrase) {\n return name;\n }\n return phrase.charAt(0).toUpperCase() + phrase.slice(1);\n}\n","import type { SessionEvent, SessionStatus } from \"@opengeni/sdk\";\nconst { default: fleetDecisionItem } = await import(\"./fleet-decision-projection\");\nimport {\n CREDIT_EXHAUSTION_MESSAGE,\n humanizeFailureReason,\n isCreditExhaustion,\n tryParseJson,\n} from \"../lib/format\";\nimport { mcpToolLeaf, toolMatchesLeaf } from \"./tool-display-name\";\nimport type {\n AgentMessageItem,\n ActivityItem,\n AuthNeededItem,\n ContextCompactionItem,\n GoalItem,\n MachineInputBatchItem,\n MemoryItem,\n SandboxItem,\n SessionStatusItem,\n TimelineGroup,\n TimelineItem,\n TurnEndItem,\n ToolCallItem,\n WorkerItem,\n} from \"./types\";\n\nexport { toolDisplayName, mcpToolLeaf, toolMatchesLeaf } from \"./tool-display-name\";\n\n/* ----------------------------------------------------------------------------\n Timeline projection\n\n `buildTimeline` folds a session's raw event log (replayed + live, ordered by\n sequence) into renderable items: chat messages with accumulated streaming\n deltas, reasoning summaries, tool calls matched to their outputs, sandbox\n operations with command output, spawned-worker status (the manager's\n `session_create` / `session_send_message` orchestration calls), goal\n markers, status changes, and turn failures.\n\n It is a pure function — same events in, same items out — so it can be\n memoized, unit-tested, and re-run incrementally as new events stream in.\n -------------------------------------------------------------------------- */\n\n/** Tool leaves on the first-party OpenGeni MCP server that operate on sessions. */\nconst WORKER_SPAWN_TOOL = \"session_create\";\nconst WORKER_MESSAGE_TOOL = \"session_send_message\";\n\n/**\n * Tools whose durable side-effect events already own the timeline (MemoryRow).\n * Emitting a generic tool-call too is double chrome — skip the call.\n *\n * Goal tools are intentionally NOT landmark-only: an agent `goal_set` /\n * `goal_update` / `goal_complete` / `goal_pause` stays an in-cluster tool row,\n * and the matching `goal.*` session event is suppressed below when `actor` is\n * `\"agent\"`. That keeps mid-turn goal tools from splitting the step rail with\n * a breakaway GoalRow pill. Non-agent goal events (API, create-session,\n * system auto-pause, continuations) still render as landmarks.\n */\nconst LANDMARK_ONLY_TOOL_LEAVES = new Set([\"memory_save\", \"memory_correct\"]);\n\nexport function buildTimeline(events: SessionEvent[]): TimelineItem[] {\n const items: TimelineItem[] = [];\n const prescan = prescanTurnAnchors(events);\n const ordered = orderTimelineEvents(events, prescan);\n\n const last = (): TimelineItem | undefined => items[items.length - 1];\n\n /** A new item of a different kind ends whatever was streaming at the tail. */\n const closeStreamingTail = (): void => {\n const open = last();\n if ((open?.kind === \"agent-message\" || open?.kind === \"reasoning\") && open.streaming) {\n open.streaming = false;\n }\n };\n\n const finalizeOpen = (\n turnId?: string | null,\n disposition: \"complete\" | \"failed\" | \"cancelled\" = \"complete\",\n ): void => {\n for (const item of items) {\n if (\n turnId !== undefined &&\n \"turnId\" in item &&\n item.turnId &&\n turnId &&\n item.turnId !== turnId\n ) {\n continue;\n }\n if ((item.kind === \"agent-message\" || item.kind === \"reasoning\") && item.streaming) {\n item.streaming = false;\n }\n if ((item.kind === \"tool-call\" || item.kind === \"worker\") && item.status === \"running\") {\n item.status = disposition;\n }\n if (item.kind === \"sandbox\" && item.status === \"running\") {\n item.status = disposition;\n }\n }\n };\n\n for (const event of ordered) {\n const payload = asRecord(event.payload);\n const turnId = event.turnId ?? null;\n\n switch (event.type) {\n case \"user.message\": {\n // A steering message must not mark in-flight tools complete; it only\n // ends whatever text was streaming. Turn lifecycle events finalize.\n closeStreamingTail();\n const childCompletion = workerCompletionPayload(payload.childCompletion);\n if (childCompletion) {\n items.push({\n kind: \"worker-completion\",\n id: event.id,\n turnId,\n occurredAt: event.occurredAt,\n childSessionId: childCompletion.childSessionId,\n childStatus: childCompletion.childStatus,\n goalStatus: childCompletion.goalStatus,\n goalText: childCompletion.goalText,\n evidence: childCompletion.evidence,\n pausedReason: childCompletion.pausedReason,\n text: stringValue(payload.text),\n });\n break;\n }\n const voiceMessage = realtimeVoiceMessage(payload);\n items.push({\n kind: \"user-message\",\n id: event.id,\n text: voiceMessage?.text ?? stringValue(payload.text),\n ...(voiceMessage ? { presentation: voiceMessage.presentation } : {}),\n resources: resourceRefs(payload.resources),\n tools: toolRefs(payload.tools),\n occurredAt: event.occurredAt,\n });\n break;\n }\n\n case \"system.update.delivered\": {\n const inputs = machineInputMembers(payload.members);\n if (inputs.length === 0) break;\n closeStreamingTail();\n items.push({\n kind: \"machine-input-batch\",\n id: event.id,\n turnId,\n members: inputs,\n occurredAt: event.occurredAt,\n });\n break;\n }\n\n case \"agent.message.delta\": {\n const text = stringValue(payload.text);\n if (!text) {\n break;\n }\n const open = last();\n if (open?.kind === \"agent-message\" && open.streaming && open.turnId === turnId) {\n open.text += text;\n break;\n }\n closeStreamingTail();\n items.push({\n kind: \"agent-message\",\n id: event.id,\n turnId,\n text,\n streaming: true,\n occurredAt: event.occurredAt,\n });\n break;\n }\n\n case \"agent.message.completed\": {\n const text = stringValue(payload.text);\n // Reconcile the most recent same-turn agent message — even when\n // activity (tool calls, reasoning) landed after its deltas — so the\n // completed text never duplicates the streamed one.\n let openIndex = -1;\n for (let index = items.length - 1; index >= 0; index -= 1) {\n const candidate = items[index];\n if (candidate?.kind === \"agent-message\" && candidate.turnId === turnId) {\n openIndex = index;\n break;\n }\n }\n const candidate = openIndex >= 0 ? items[openIndex] : undefined;\n const open: AgentMessageItem | undefined =\n candidate?.kind === \"agent-message\" ? candidate : undefined;\n if (\n open &&\n (open.streaming || !open.text || text === open.text || text.startsWith(open.text))\n ) {\n // The completed text is authoritative when it extends what streamed.\n if (!open.text || (text && text.startsWith(open.text))) {\n open.text = text || open.text;\n }\n open.streaming = false;\n // Completion time is what the footer shows (\"finished at\"); keep the\n // first-delta stamp only until this event arrives.\n open.occurredAt = event.occurredAt;\n // The SDK can emit a hosted-tool item only after its provider-native\n // operation has completed, even though answer deltas were already\n // streamed. The completed message event is the durable ordering\n // authority, so move the reconciled row after any intervening tool\n // activity instead of leaving completed web searches below the answer.\n if (openIndex < items.length - 1) {\n items.splice(openIndex, 1);\n items.push(open);\n }\n break;\n }\n if (text) {\n items.push({\n kind: \"agent-message\",\n id: event.id,\n turnId,\n text,\n streaming: false,\n occurredAt: event.occurredAt,\n });\n }\n break;\n }\n\n case \"agent.reasoning.delta\": {\n const text = reasoningText(event.payload);\n if (!text) {\n break;\n }\n const open = last();\n if (open?.kind === \"reasoning\" && open.streaming && open.turnId === turnId) {\n open.text += text;\n break;\n }\n closeStreamingTail();\n items.push({\n kind: \"reasoning\",\n id: event.id,\n turnId,\n text,\n streaming: true,\n occurredAt: event.occurredAt,\n });\n break;\n }\n\n case \"agent.toolCall.created\": {\n const name = typeof payload.name === \"string\" ? payload.name : \"tool\";\n const callId = typeof payload.id === \"string\" ? payload.id : null;\n const args = payload.arguments ?? null;\n closeStreamingTail();\n if (\n toolMatchesLeaf(name, WORKER_SPAWN_TOOL) ||\n toolMatchesLeaf(name, WORKER_MESSAGE_TOOL)\n ) {\n items.push({\n kind: \"worker\",\n id: event.id,\n turnId,\n callId,\n action: toolMatchesLeaf(name, WORKER_SPAWN_TOOL) ? \"spawn\" : \"message\",\n prompt: workerPrompt(args),\n workerSessionId: extractSessionRef(args),\n status: \"running\",\n occurredAt: event.occurredAt,\n });\n break;\n }\n if (LANDMARK_ONLY_TOOL_LEAVES.has(mcpToolLeaf(name))) {\n // Goal/memory landmarks arrive as goal.* / memory.* events.\n break;\n }\n // Live Responses `web_search_call` events and the later SDK\n // `RunToolCallItem` share the same item id. Merge so mid-stream cards\n // do not duplicate when the step finally materializes.\n if (callId) {\n const existing = [...items]\n .reverse()\n .find(\n (item): item is ToolCallItem => item.kind === \"tool-call\" && item.callId === callId,\n );\n if (existing) {\n if (args != null) {\n existing.arguments = args;\n }\n if (payload.raw !== undefined) {\n existing.raw = mergeToolCallRaw(existing.raw, payload.raw);\n }\n existing.status = providerNativeToolStatus(existing.raw);\n break;\n }\n }\n items.push({\n kind: \"tool-call\",\n id: event.id,\n turnId,\n callId,\n name,\n arguments: args,\n output: undefined,\n // The provider-native item drives the per-tool renderers (apply_patch\n // operation, computer_call action, web_search providerData, …).\n raw: payload.raw,\n status: providerNativeToolStatus(payload.raw),\n occurredAt: event.occurredAt,\n });\n break;\n }\n\n case \"agent.toolCall.output\": {\n const callId = typeof payload.id === \"string\" ? payload.id : null;\n const target = findOpenCall(items, callId);\n if (!target) {\n break;\n }\n if (target.kind === \"worker\") {\n // A worker spawn/message that returns an error flag (or an MCP\n // isError result) settles to \"failed\" too, so WorkerRow surfaces it.\n target.status = isErrorOutput(payload) ? \"failed\" : \"complete\";\n target.workerSessionId = target.workerSessionId ?? extractSessionRef(payload.output);\n break;\n }\n // An output carrying an explicit error flag (or an MCP isError result)\n // settles the tool to \"failed\" so the renderer can surface it loudly.\n target.status = isErrorOutput(payload) ? \"failed\" : \"complete\";\n target.output = payload.output;\n break;\n }\n\n case \"sandbox.operation.started\":\n case \"sandbox.operation.completed\":\n case \"sandbox.operation.failed\": {\n const name = typeof payload.name === \"string\" ? payload.name : \"sandbox\";\n const status = event.type.endsWith(\".failed\")\n ? \"failed\"\n : event.type.endsWith(\".completed\")\n ? \"complete\"\n : \"running\";\n // Routine per-turn platform plumbing that runs before EVERY turn to\n // guarantee box contents survive a re-warm — NOT the agent redoing work:\n // - repository-clone: idempotent clone check + off-manifest token re-seed;\n // - file-resource-download: idempotent `if [ ! -f ] then curl` (skips\n // when the attached file is already on the box — see\n // sandboxFileDownloadCommand), so an uploaded image is not re-fetched;\n // the operation still emits every turn even when it does nothing.\n // Rendering either every turn reads as churn. Only FAILURES surface, and\n // they surface loudly — the failed event below creates its own item even\n // without a started row.\n if (\n (name === \"repository-clone\" || name === \"file-resource-download\") &&\n status !== \"failed\"\n ) {\n break;\n }\n const existing = findOpenSandbox(items, name);\n if (existing && status !== \"running\") {\n existing.status = status;\n if (\n payload.origin === \"created\" ||\n payload.origin === \"restored\" ||\n payload.origin === \"resumed\"\n ) {\n existing.origin = payload.origin;\n }\n const message = failureMessage(payload);\n if (message) {\n existing.output = existing.output ? `${existing.output}\\n${message}` : message;\n }\n break;\n }\n if (!existing) {\n closeStreamingTail();\n items.push({\n kind: \"sandbox\",\n id: event.id,\n turnId,\n name,\n command: typeof payload.command === \"string\" ? payload.command : null,\n output: failureMessage(payload) ?? \"\",\n origin:\n payload.origin === \"created\" ||\n payload.origin === \"restored\" ||\n payload.origin === \"resumed\"\n ? payload.origin\n : null,\n status,\n occurredAt: event.occurredAt,\n });\n }\n break;\n }\n\n case \"sandbox.command.output.delta\": {\n // `chunk` is the canonical wire field; text/output are legacy shapes.\n const text =\n typeof payload.chunk === \"string\"\n ? payload.chunk\n : typeof payload.text === \"string\"\n ? payload.text\n : typeof payload.output === \"string\"\n ? payload.output\n : \"\";\n if (!text) {\n break;\n }\n // Attach to the named operation when the payload carries one;\n // otherwise the latest running operation is the best available owner.\n const open =\n (typeof payload.name === \"string\" ? findOpenSandbox(items, payload.name) : undefined) ??\n [...items]\n .reverse()\n .find(\n (item): item is SandboxItem => item.kind === \"sandbox\" && item.status === \"running\",\n );\n if (open) {\n open.output += text;\n }\n break;\n }\n\n case \"session.status.changed\": {\n const status = payload.status;\n if (!isSessionStatus(status)) {\n break;\n }\n // Only attention-worthy statuses earn a timeline divider. queued /\n // running / idle are machinery telemetry: the header pill carries the\n // live status, the shimmer says \"running\", and the turn chip's duration\n // facet says how long — a stale \"idle · 27s\" row is pure noise,\n // especially in historical traces.\n if (!ATTENTION_STATUSES.has(status)) {\n break;\n }\n const previous = [...items]\n .reverse()\n .find((item): item is SessionStatusItem => item.kind === \"session-status\");\n if (previous?.status === status) {\n break;\n }\n items.push({\n kind: \"session-status\",\n id: event.id,\n status,\n occurredAt: event.occurredAt,\n });\n break;\n }\n\n case \"session.requiresAction\": {\n finalizeOpen(turnId);\n items.push({\n kind: \"notice\",\n id: event.id,\n tone: \"waiting\",\n text: \"Approval needed — the turn is paused until someone decides.\",\n occurredAt: event.occurredAt,\n });\n break;\n }\n\n case \"session.context.compaction.requested\":\n case \"session.context.compaction.started\": {\n closeStreamingTail();\n settleOrPushContextCompaction(items, {\n id: event.id,\n turnId,\n phase: \"started\",\n trigger: compactionTrigger(payload),\n estimatedTokensBefore: numberOrNull(payload.estimatedTokensBefore),\n estimatedTokensAfter: null,\n skipReason: null,\n implementation:\n typeof payload.implementation === \"string\" ? payload.implementation : null,\n occurredAt: event.occurredAt,\n });\n break;\n }\n\n case \"session.context.compacted\": {\n closeStreamingTail();\n settleOrPushContextCompaction(items, {\n id: event.id,\n turnId,\n phase: \"compacted\",\n trigger: compactionTrigger(payload),\n estimatedTokensBefore: numberOrNull(payload.estimatedTokensBefore),\n estimatedTokensAfter: numberOrNull(payload.estimatedTokensAfter),\n skipReason: null,\n implementation:\n typeof payload.implementation === \"string\" ? payload.implementation : null,\n occurredAt: event.occurredAt,\n });\n break;\n }\n\n case \"session.context.compaction.skipped\": {\n closeStreamingTail();\n settleOrPushContextCompaction(items, {\n id: event.id,\n turnId,\n phase: \"skipped\",\n trigger: compactionTrigger(payload),\n estimatedTokensBefore: numberOrNull(payload.estimatedTokensBefore),\n estimatedTokensAfter: null,\n skipReason: typeof payload.reason === \"string\" ? payload.reason : null,\n implementation:\n typeof payload.implementation === \"string\" ? payload.implementation : null,\n occurredAt: event.occurredAt,\n });\n break;\n }\n\n case \"turn.recovery.requested\": {\n // Recovery requests are durable control-plane evidence, not a user\n // message or proof that recovery succeeded. Live state already exposes\n // a genuinely recovering session; keep the raw event in Debug/audit.\n break;\n }\n\n case \"turn.event.rejected_late\": {\n // Attempt-fence rejections prove stale callbacks did not alter current\n // truth. They are useful diagnostics but never actionable chat content,\n // regardless of the rejected event type. Debug/audit retains the event.\n break;\n }\n\n case \"tool.auth_needed\":\n case \"credential.auth_needed\": {\n // Keep the whole structured payload — the renderer turns it into a clean\n // inline reconnect card, and the app starts the recovery flow off the\n // connectionId/resource. Losing it to a plain-text notice was the ugly\n // \"linear.app needs to be reconnected.\" line users complained about.\n closeStreamingTail();\n items.push({\n kind: \"auth-needed\",\n id: event.id,\n turnId,\n providerDomain: stringValue(payload.providerDomain),\n connectionId: typeof payload.connectionId === \"string\" ? payload.connectionId : null,\n reason: authNeededReason(payload.reason),\n scopes: stringList(payload.scopes),\n resource: typeof payload.resource === \"string\" ? payload.resource : null,\n toolName: typeof payload.toolName === \"string\" ? payload.toolName : null,\n authorizationUrl:\n typeof payload.authorizationUrl === \"string\" ? payload.authorizationUrl : null,\n occurredAt: event.occurredAt,\n });\n break;\n }\n\n case \"turn.completed\": {\n // A standalone manual compaction uses the turn ledger for fencing and\n // recovery, but it is maintenance rather than a conversational turn.\n // The dedicated context-compaction landmark is the complete UI truth;\n // adding a generic turn chip would falsely make it look like an\n // extra agent response.\n if (payload.maintenance === \"context_compaction\") {\n finalizeOpen(turnId);\n break;\n }\n // Credit exhaustion arrives as a NOMINALLY completed turn (`detail:\n // \"insufficient OpenGeni credits\"`, `segmentLimit: \"budget_exhausted\"`)\n // — the engine ended the segment early, it did not finish the work.\n // Rendering it as a clean \"complete\" turn is a lie that leaves the\n // session looking healthy while every future turn silently dies, so it\n // projects exactly like a failed turn plus an explicit notice.\n if (isCreditExhaustionPayload(payload)) {\n finalizeOpen(turnId);\n items.push(turnEndItem(event, \"failed\", CREDIT_EXHAUSTION_MESSAGE));\n items.push({\n kind: \"notice\",\n id: event.id,\n tone: \"failed\",\n text: CREDIT_EXHAUSTION_MESSAGE,\n occurredAt: event.occurredAt,\n });\n break;\n }\n finalizeOpen(turnId);\n items.push(turnEndItem(event, \"complete\", null));\n break;\n }\n\n case \"turn.failed\": {\n const hadActivity = hasTurnActivity(items, turnId);\n // Credit death can hide behind fields `failureMessage` doesn't read\n // (detail/segmentLimit), so classify the whole payload before falling\n // back to the generic error/message extraction.\n const failureText = isCreditExhaustionPayload(payload)\n ? CREDIT_EXHAUSTION_MESSAGE\n : failureMessage(payload);\n // The TURN failed — the in-flight items did not. Chip doctrine: red is\n // spent once, on the turn-level outcome. Items caught mid-flight read\n // as calm \"interrupted\" (same as turn.cancelled); an item that itself\n // failed keeps its own failed status from its output event.\n finalizeOpen(turnId, \"cancelled\");\n items.push(turnEndItem(event, \"failed\", failureText));\n if (!hadActivity) {\n items.push({\n kind: \"notice\",\n id: event.id,\n tone: \"failed\",\n text: failureText ?? \"The turn failed.\",\n occurredAt: event.occurredAt,\n });\n }\n break;\n }\n\n case \"turn.cancelled\": {\n // A retraction of a never-started queued turn is not a turn ending —\n // the message was withdrawn before any work happened; show nothing.\n // A null turnId proves nothing, so it keeps the legacy finalize path.\n if (turnId && !prescan.startedTurnIds.has(turnId)) {\n break;\n }\n const hadActivity = hasTurnActivity(items, turnId);\n finalizeOpen(turnId, \"cancelled\");\n items.push(turnEndItem(event, \"cancelled\", null));\n if (!hadActivity) {\n items.push({\n kind: \"notice\",\n id: event.id,\n tone: \"cancelled\",\n text: \"Interrupted.\",\n occurredAt: event.occurredAt,\n });\n }\n break;\n }\n\n case \"memory.saved\":\n case \"memory.corrected\": {\n // A first-party memory write is a discrete step, not streamed text, so it\n // ends whatever was streaming (mirrors tool/sandbox pushes). A payload\n // missing the memory id is malformed and dropped rather than shown blank.\n const memory = memoryItem(event.id, event.type, turnId, payload, event.occurredAt);\n if (memory) {\n closeStreamingTail();\n items.push(memory);\n }\n break;\n }\n\n case \"codex.fleet.decision\": {\n const decision = fleetDecisionItem(event, payload);\n if (decision) {\n closeStreamingTail();\n items.push(decision);\n }\n break;\n }\n\n case \"goal.set\":\n case \"goal.updated\":\n case \"goal.completed\":\n case \"goal.paused\":\n case \"goal.resumed\":\n case \"goal.cleared\":\n case \"goal.continuation\": {\n // Agent tool mutations already appear as tool-call rows in the activity\n // cluster. Re-emitting them as GoalRow landmarks splits \"N steps\" mid-turn.\n if (shouldSuppressAgentGoalLandmark(event.type, payload)) {\n break;\n }\n items.push({\n kind: \"goal\",\n id: event.id,\n action: event.type.slice(\"goal.\".length) as GoalItem[\"action\"],\n text: goalText(payload),\n occurredAt: event.occurredAt,\n });\n break;\n }\n\n default:\n break;\n }\n }\n\n for (const item of items) {\n if (item.kind === \"agent-message\") {\n item.text = stripOpaqueCitationTokens(item.text);\n }\n }\n return items;\n}\n\nfunction realtimeVoiceMessage(payload: Record<string, unknown>): {\n text: string;\n presentation: {\n kind: \"realtime_voice\" | \"realtime_voice_handoff\";\n context: string;\n };\n} | null {\n const presentation = asRecord(payload.presentation);\n const visibleText = stringValue(payload.text);\n if (presentation.kind === \"realtime_voice\" || presentation.kind === \"realtime_voice_handoff\") {\n const context = stringValue(presentation.context);\n return visibleText && context\n ? { text: visibleText, presentation: { kind: presentation.kind, context } }\n : null;\n }\n return null;\n}\n\nfunction providerNativeToolStatus(rawValue: unknown): ToolCallItem[\"status\"] {\n const raw = asRecord(rawValue);\n if (raw.type !== \"hosted_tool_call\") {\n return \"running\";\n }\n switch (raw.status) {\n case \"completed\":\n return \"complete\";\n case \"failed\":\n case \"incomplete\":\n return \"failed\";\n case \"cancelled\":\n return \"cancelled\";\n default:\n return \"running\";\n }\n}\n\n/**\n * Prefer newer status/fields, but keep earlier providerData.action when a\n * progress-only Responses event arrives without the search query payload.\n */\nfunction mergeToolCallRaw(existingValue: unknown, nextValue: unknown): unknown {\n const existing = asRecord(existingValue);\n const next = asRecord(nextValue);\n if (Object.keys(next).length === 0) {\n return existingValue;\n }\n const existingProvider = asRecord(existing.providerData);\n const nextProvider = asRecord(next.providerData);\n const providerData = {\n ...existingProvider,\n ...nextProvider,\n };\n if (\n existingProvider.action != null &&\n (nextProvider.action == null ||\n (typeof nextProvider.action === \"object\" &&\n nextProvider.action !== null &&\n Object.keys(nextProvider.action as object).length === 0))\n ) {\n providerData.action = existingProvider.action;\n }\n return {\n ...existing,\n ...next,\n ...(Object.keys(providerData).length > 0 ? { providerData } : {}),\n };\n}\n\n/**\n * Codex subscription web search can return private citation handles without\n * the URL annotation table that would make them resolvable. Keep the canonical\n * model-history item untouched, but never expose those unusable handles in the\n * human timeline. Ordinary markdown links and structured URL citations remain.\n */\nexport function stripOpaqueCitationTokens(text: string): string {\n return text.replace(/\\s*cite(?:[^]+)+/gu, \"\");\n}\n\n/** The turn-end payload shape, as `isCreditExhaustion` wants it. */\nfunction isCreditExhaustionPayload(payload: Record<string, unknown>): boolean {\n return isCreditExhaustion({\n error: typeof payload.error === \"string\" ? payload.error : null,\n detail: typeof payload.detail === \"string\" ? payload.detail : null,\n segmentLimit: typeof payload.segmentLimit === \"string\" ? payload.segmentLimit : null,\n });\n}\n\n/**\n * Whether the session's most recent turn ended in credit exhaustion — the\n * terminal credit state apps key their \"add credits\" affordances on. Derived\n * from the LAST turn-end event (completed/failed/cancelled): a later turn that\n * settles any other way (someone topped up and kept working) clears it.\n */\nexport function creditExhaustedFromEvents(events: SessionEvent[]): boolean {\n const ordered = [...events].sort((a, b) => a.sequence - b.sequence);\n for (let index = ordered.length - 1; index >= 0; index -= 1) {\n const event = ordered[index];\n if (\n event?.type !== \"turn.completed\" &&\n event?.type !== \"turn.failed\" &&\n event?.type !== \"turn.cancelled\"\n ) {\n continue;\n }\n return isCreditExhaustionPayload(asRecord(event.payload));\n }\n return false;\n}\n\n/** The latest session status carried in the event log, if any. */\nexport function sessionStatusFromEvents(events: SessionEvent[]): SessionStatus | null {\n for (let index = events.length - 1; index >= 0; index -= 1) {\n const event = events[index];\n if (event?.type !== \"session.status.changed\") {\n continue;\n }\n const status = asRecord(event.payload).status;\n if (isSessionStatus(status)) {\n return status;\n }\n }\n return null;\n}\n\n/* ----------------------------------------------------------------------------\n Visual grouping: consecutive activity items (reasoning / tools / workers /\n sandbox) cluster into collapsible blocks. Once a turn settles, the full\n non-user span folds behind a turn group, with activity blocks nested inside.\n -------------------------------------------------------------------------- */\n\n/**\n * Whether an item clusters into an activity block. A `switch` (not a stringly-\n * typed set) so adding an {@link ActivityItem} kind is a compile-time prompt to\n * decide its grouping — and it narrows `item` to `ActivityItem` with no cast.\n */\nfunction isActivityItem(item: TimelineItem): item is ActivityItem {\n switch (item.kind) {\n case \"reasoning\":\n case \"tool-call\":\n case \"worker\":\n case \"sandbox\":\n case \"memory\":\n case \"fleet-decision\":\n return true;\n default:\n return false;\n }\n}\n\nexport function groupTimeline(items: TimelineItem[]): TimelineGroup[] {\n const groups: TimelineGroup[] = [];\n for (const item of items) {\n if (isActivityItem(item)) {\n const open = groups[groups.length - 1];\n if (open?.kind === \"activity\" && open.outcome === undefined) {\n open.items.push(item);\n } else {\n groups.push({\n kind: \"activity\",\n id: `activity-${item.id}`,\n items: [item],\n });\n }\n continue;\n }\n if (item.kind === \"turn-end\") {\n stampTurnOutcome(groups, item);\n foldSettledTurn(groups, item);\n continue;\n }\n groups.push({ kind: \"item\", item });\n }\n return groups;\n}\n\n/* --- helpers ---------------------------------------------------------------- */\n\ntype TurnAnchorPrescan = {\n queuedTurnByTrigger: Map<string, string>;\n startSeqByTrigger: Map<string, number>;\n cancelledBeforeStartTriggers: Set<string>;\n startedTurnIds: Set<string>;\n};\n\nfunction prescanTurnAnchors(events: SessionEvent[]): TurnAnchorPrescan {\n const ordered = [...events].sort((a, b) => a.sequence - b.sequence);\n const queuedTurnByTrigger = new Map<string, string>();\n const startSeqByTrigger = new Map<string, number>();\n const cancelledTurnIds = new Set<string>();\n const fallbackSeqByTurn = new Map<string, number>();\n const startedTurnIds = new Set<string>();\n\n for (const event of ordered) {\n const payload = asRecord(event.payload);\n const turnId = event.turnId ?? null;\n if (event.type === \"turn.queued\") {\n const triggerEventId =\n typeof payload.triggerEventId === \"string\" ? payload.triggerEventId : null;\n const queuedTurnId = typeof payload.turnId === \"string\" ? payload.turnId : turnId;\n if (triggerEventId && queuedTurnId) {\n queuedTurnByTrigger.set(triggerEventId, queuedTurnId);\n }\n continue;\n }\n if (event.type === \"turn.started\") {\n const triggerEventId =\n typeof payload.triggerEventId === \"string\" ? payload.triggerEventId : null;\n if (triggerEventId && !startSeqByTrigger.has(triggerEventId)) {\n startSeqByTrigger.set(triggerEventId, event.sequence);\n }\n if (turnId) {\n startedTurnIds.add(turnId);\n }\n } else if (event.type === \"turn.cancelled\" && turnId) {\n cancelledTurnIds.add(turnId);\n }\n\n if (turnId && isTurnExecutionEvidence(event.type)) {\n const previous = fallbackSeqByTurn.get(turnId);\n if (previous === undefined || event.sequence < previous) {\n fallbackSeqByTurn.set(turnId, event.sequence);\n }\n }\n if (turnId && isTurnExecutionEvidence(event.type)) {\n startedTurnIds.add(turnId);\n }\n }\n\n for (const [triggerEventId, turnId] of queuedTurnByTrigger) {\n if (!startSeqByTrigger.has(triggerEventId)) {\n const fallbackSeq = fallbackSeqByTurn.get(turnId);\n if (fallbackSeq !== undefined) {\n startSeqByTrigger.set(triggerEventId, fallbackSeq);\n }\n }\n }\n\n const cancelledBeforeStartTriggers = new Set<string>();\n for (const [triggerEventId, turnId] of queuedTurnByTrigger) {\n if (\n cancelledTurnIds.has(turnId) &&\n !startSeqByTrigger.has(triggerEventId) &&\n !fallbackSeqByTurn.has(turnId)\n ) {\n cancelledBeforeStartTriggers.add(triggerEventId);\n }\n }\n\n return {\n queuedTurnByTrigger,\n startSeqByTrigger,\n cancelledBeforeStartTriggers,\n startedTurnIds,\n };\n}\n\nfunction orderTimelineEvents(events: SessionEvent[], prescan: TurnAnchorPrescan): SessionEvent[] {\n const ordered = [...events].sort((a, b) => a.sequence - b.sequence);\n const insertions = new Map<number, SessionEvent[]>();\n\n for (const event of ordered) {\n if (event.type !== \"user.message\") {\n continue;\n }\n const queuedTurnId = prescan.queuedTurnByTrigger.get(event.id);\n if (!queuedTurnId) {\n pushInsertion(insertions, event.sequence, event);\n continue;\n }\n if (prescan.cancelledBeforeStartTriggers.has(event.id)) {\n continue;\n }\n const startSeq = prescan.startSeqByTrigger.get(event.id);\n if (startSeq !== undefined) {\n pushInsertion(insertions, startSeq, event);\n continue;\n }\n // A waiting prompt belongs only in the prompt queue. It enters the\n // timeline at turn.started (or the first same-turn activity fallback),\n // never as a second queued representation.\n }\n\n const projected: SessionEvent[] = [];\n for (const event of ordered) {\n const before = insertions.get(event.sequence);\n if (before) {\n projected.push(...before);\n }\n if (event.type !== \"user.message\") {\n projected.push(event);\n }\n }\n return projected;\n}\n\nfunction pushInsertion(\n insertions: Map<number, SessionEvent[]>,\n sequence: number,\n event: SessionEvent,\n): void {\n const bucket = insertions.get(sequence);\n if (bucket) {\n bucket.push(event);\n } else {\n insertions.set(sequence, [event]);\n }\n}\n\nfunction isAgentActivityEvent(type: string): boolean {\n return type.startsWith(\"agent.\") || type.startsWith(\"sandbox.\");\n}\n\n/**\n * Evidence that a queued prompt crossed the execution boundary when an older\n * or partially recovered ledger is missing its canonical `turn.started`.\n * Queue/control bookkeeping intentionally does not qualify: moving, editing,\n * steering, or deleting a waiting row must never make its prompt appear in the\n * transcript as though inference had begun.\n */\nfunction isTurnExecutionEvidence(type: string): boolean {\n return (\n isAgentActivityEvent(type) ||\n type === \"turn.completed\" ||\n type === \"turn.failed\" ||\n type === \"turn.recovery.requested\" ||\n type === \"turn.capacity_waiting\" ||\n type === \"session.requiresAction\" ||\n type === \"tool.auth_needed\" ||\n type === \"credential.auth_needed\" ||\n type.startsWith(\"rig.setup.\") ||\n type === \"codex.capacity.waiting\" ||\n type === \"codex.capacity.resumed\" ||\n type === \"codex.fleet.decision\"\n );\n}\n\nfunction turnEndItem(\n event: SessionEvent,\n outcome: TurnEndItem[\"outcome\"],\n failureText: string | null,\n): TurnEndItem {\n return {\n kind: \"turn-end\",\n id: `${event.id}-turn-end`,\n turnId: event.turnId ?? null,\n outcome,\n failureText,\n occurredAt: event.occurredAt,\n };\n}\n\nfunction hasTurnActivity(items: TimelineItem[], turnId: string | null): boolean {\n if (turnId) {\n return items.some((item) => isActivityItem(item) && item.turnId === turnId);\n }\n for (let index = items.length - 1; index >= 0; index -= 1) {\n const item = items[index];\n if (!item || item.kind === \"turn-end\" || item.kind === \"user-message\") {\n return false;\n }\n if (isActivityItem(item)) {\n return true;\n }\n }\n return false;\n}\n\nfunction stampTurnOutcome(groups: TimelineGroup[], turnEnd: TurnEndItem): void {\n if (turnEnd.turnId === null) {\n const trailing = groups[groups.length - 1];\n if (trailing?.kind === \"activity\" && trailing.outcome === undefined) {\n applyTurnOutcome(trailing, turnEnd);\n }\n return;\n }\n for (const group of groups) {\n if (group.kind !== \"activity\" || group.outcome !== undefined) {\n continue;\n }\n if (group.items.some((activity) => activity.turnId === turnEnd.turnId)) {\n applyTurnOutcome(group, turnEnd);\n }\n }\n}\n\nfunction applyTurnOutcome(\n group: Extract<TimelineGroup, { kind: \"activity\" }>,\n turnEnd: TurnEndItem,\n): void {\n // A sub-cluster reports ITS OWN outcome, not the turn's. When a turn fails\n // at step 7, clusters 1–6 completed — painting them all red says \"everything\n // broke\" when one thing did. The turn-level fold carries the turn outcome;\n // a cluster goes red only if an item inside it actually failed, and reads\n // \"cancelled\" (interrupted) only when it holds the items cut off mid-flight.\n if (turnEnd.outcome === \"complete\") {\n group.outcome = \"complete\";\n return;\n }\n const hasFailed = group.items.some((item) => \"status\" in item && item.status === \"failed\");\n const hasInterrupted = group.items.some(\n (item) => \"status\" in item && item.status === \"cancelled\",\n );\n group.outcome = hasFailed ? \"failed\" : hasInterrupted ? \"cancelled\" : \"complete\";\n if (turnEnd.failureText && hasFailed) {\n group.failureText = turnEnd.failureText;\n }\n}\n\nfunction foldSettledTurn(groups: TimelineGroup[], turnEnd: TurnEndItem): void {\n let startIndex = groups.length;\n let stoppedAtForeignTurn = false;\n while (startIndex > 0) {\n const previous = groups[startIndex - 1];\n if (isTurnBoundary(previous)) {\n break;\n }\n if (belongsToDifferentTurn(previous, turnEnd.turnId)) {\n stoppedAtForeignTurn = true;\n break;\n }\n startIndex -= 1;\n }\n if (stoppedAtForeignTurn) {\n while (startIndex < groups.length && isBetweenTurnDivider(groups[startIndex])) {\n startIndex += 1;\n }\n }\n\n const collected = groups.slice(startIndex);\n if (collected.length === 0) {\n return;\n }\n\n const finalMessage = extractFinalAgentMessage(collected, turnEnd);\n const body = finalMessage ? collected.slice(0, -1) : collected;\n if (body.length === 0) {\n return;\n }\n\n const firstOccurredAt = groupStartedAt(body[0]) ?? turnEnd.occurredAt;\n const prior = startIndex > 0 ? groups[startIndex - 1] : undefined;\n const contextCompactionCount =\n prior?.kind === \"item\" &&\n prior.item.kind === \"context-compaction\" &&\n prior.item.phase === \"compacted\"\n ? 1\n : 0;\n const turnGroup: TimelineGroup = {\n kind: \"turn\",\n id: `turn-${turnEnd.turnId ?? turnEnd.id}`,\n outcome: turnEnd.outcome,\n startedAt: firstOccurredAt,\n endedAt: turnEnd.occurredAt,\n groups: body,\n ...(contextCompactionCount > 0 ? { contextCompactionCount } : {}),\n };\n if (turnEnd.failureText) {\n turnGroup.failureText = turnEnd.failureText;\n }\n\n groups.splice(\n startIndex,\n collected.length,\n ...(finalMessage ? [turnGroup, finalMessage] : [turnGroup]),\n );\n}\n\nfunction isTurnBoundary(group: TimelineGroup | undefined): boolean {\n return (\n group?.kind === \"turn\" ||\n (group?.kind === \"item\" &&\n (group.item.kind === \"user-message\" ||\n group.item.kind === \"context-compaction\" ||\n (group.item.kind === \"notice\" && group.item.tone === \"input\")))\n );\n}\n\nfunction belongsToDifferentTurn(group: TimelineGroup | undefined, turnId: string | null): boolean {\n if (!group || !turnId) {\n return false;\n }\n if (group.kind === \"activity\") {\n return (\n group.items.length > 0 &&\n group.items.every((item) => item.turnId !== null && item.turnId !== turnId)\n );\n }\n return (\n group.kind === \"item\" &&\n group.item.kind === \"agent-message\" &&\n group.item.turnId !== null &&\n group.item.turnId !== turnId\n );\n}\n\nfunction isBetweenTurnDivider(group: TimelineGroup | undefined): boolean {\n return (\n group?.kind === \"item\" &&\n group.item.kind === \"session-status\" &&\n group.item.status !== \"running\"\n );\n}\n\nfunction extractFinalAgentMessage(\n groups: TimelineGroup[],\n turnEnd: TurnEndItem,\n): Extract<TimelineGroup, { kind: \"item\" }> | null {\n const tail = groups[groups.length - 1];\n if (tail?.kind !== \"item\" || tail.item.kind !== \"agent-message\" || tail.item.streaming) {\n return null;\n }\n if (tail.item.turnId && turnEnd.turnId && tail.item.turnId !== turnEnd.turnId) {\n return null;\n }\n return tail;\n}\n\nfunction groupStartedAt(group: TimelineGroup | undefined): string | undefined {\n if (!group) {\n return undefined;\n }\n switch (group.kind) {\n case \"item\":\n return group.item.occurredAt;\n case \"activity\":\n return group.items[0]?.occurredAt;\n case \"turn\":\n return group.startedAt;\n }\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> {\n return value !== null && typeof value === \"object\" ? (value as Record<string, unknown>) : {};\n}\n\nfunction stringValue(value: unknown): string {\n return typeof value === \"string\" ? value : \"\";\n}\n\nfunction numberOrNull(value: unknown): number | null {\n return typeof value === \"number\" && Number.isFinite(value) ? value : null;\n}\n\nfunction compactionTrigger(payload: Record<string, unknown>): ContextCompactionItem[\"trigger\"] {\n const trigger = payload.trigger;\n return trigger === \"auto\" ||\n trigger === \"operator\" ||\n trigger === \"proactive\" ||\n trigger === \"overflow\"\n ? trigger\n : null;\n}\n\n/**\n * Keep one landmark per turn: a later started/compacted/skipped settles the\n * open started row instead of stacking notices.\n */\nfunction settleOrPushContextCompaction(\n items: TimelineItem[],\n next: Omit<ContextCompactionItem, \"kind\">,\n): void {\n const openIndex = findOpenContextCompactionIndex(items, next.turnId);\n if (openIndex >= 0) {\n const open = items[openIndex];\n if (open?.kind === \"context-compaction\") {\n items[openIndex] = {\n ...open,\n ...next,\n // Prefer the settled event id so keys stay stable with the finish row.\n id: next.phase === \"started\" ? open.id : next.id,\n trigger: next.trigger ?? open.trigger,\n estimatedTokensBefore: next.estimatedTokensBefore ?? open.estimatedTokensBefore,\n implementation: next.implementation ?? open.implementation,\n };\n return;\n }\n }\n items.push({ kind: \"context-compaction\", ...next });\n}\n\nfunction findOpenContextCompactionIndex(items: TimelineItem[], turnId: string | null): number {\n for (let index = items.length - 1; index >= 0; index -= 1) {\n const item = items[index];\n if (item?.kind !== \"context-compaction\" || item.phase !== \"started\") {\n continue;\n }\n if (turnId && item.turnId && item.turnId !== turnId) {\n continue;\n }\n return index;\n }\n return -1;\n}\n\nfunction machineInputMembers(value: unknown): MachineInputBatchItem[\"members\"] {\n const kinds = new Set<MachineInputBatchItem[\"members\"][number][\"kind\"]>([\n \"scheduled_occurrence\",\n \"goal_continuation\",\n \"agent_message\",\n \"agent_steer_instruction\",\n \"child_terminal_result\",\n ]);\n const classifications = new Set<MachineInputBatchItem[\"members\"][number][\"classification\"]>([\n \"success\",\n \"failure\",\n \"action_required\",\n \"info\",\n ]);\n return Array.isArray(value)\n ? value.flatMap((candidate) => {\n const member = asRecord(candidate);\n return typeof member.id === \"string\" &&\n typeof member.kind === \"string\" &&\n kinds.has(member.kind as MachineInputBatchItem[\"members\"][number][\"kind\"]) &&\n typeof member.classification === \"string\" &&\n classifications.has(\n member.classification as MachineInputBatchItem[\"members\"][number][\"classification\"],\n ) &&\n typeof member.sourceId === \"string\"\n ? [\n {\n id: member.id,\n kind: member.kind as MachineInputBatchItem[\"members\"][number][\"kind\"],\n classification:\n member.classification as MachineInputBatchItem[\"members\"][number][\"classification\"],\n sourceId: member.sourceId,\n summary: stringValue(member.summary),\n },\n ]\n : [];\n })\n : [];\n}\n\nconst SESSION_STATUSES: readonly SessionStatus[] = [\n \"queued\",\n \"running\",\n \"idle\",\n \"requires_action\",\n \"failed\",\n \"cancelled\",\n];\n\n/** Statuses that demand the reader's attention and so earn a timeline divider. */\nconst ATTENTION_STATUSES: ReadonlySet<SessionStatus> = new Set([\n \"requires_action\",\n \"failed\",\n \"cancelled\",\n]);\n\n/** Keep only entries that match the wire shapes; user payloads are untyped. */\nfunction resourceRefs(value: unknown): import(\"@opengeni/sdk\").ResourceRef[] {\n if (!Array.isArray(value)) {\n return [];\n }\n return value.filter((entry): entry is import(\"@opengeni/sdk\").ResourceRef => {\n const record = asRecord(entry);\n if (record.kind === \"repository\") {\n return typeof record.uri === \"string\" && typeof record.ref === \"string\";\n }\n return record.kind === \"file\" && typeof record.fileId === \"string\";\n });\n}\n\nfunction toolRefs(value: unknown): import(\"@opengeni/sdk\").ToolRef[] {\n if (!Array.isArray(value)) {\n return [];\n }\n return value.filter((entry): entry is import(\"@opengeni/sdk\").ToolRef => {\n const record = asRecord(entry);\n return record.kind === \"mcp\" && typeof record.id === \"string\";\n });\n}\n\nfunction workerCompletionPayload(value: unknown): {\n childSessionId: string;\n childStatus: string;\n goalStatus: string | null;\n goalText: string | null;\n evidence: string | null;\n pausedReason: string | null;\n} | null {\n const payload = asRecord(value);\n const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n if (\n typeof payload.childSessionId !== \"string\" ||\n !uuidPattern.test(payload.childSessionId) ||\n typeof payload.status !== \"string\" ||\n payload.status.trim() === \"\"\n ) {\n return null;\n }\n const goal = asRecord(payload.goal);\n return {\n childSessionId: payload.childSessionId,\n childStatus: payload.status,\n goalStatus: typeof goal.status === \"string\" ? goal.status : null,\n goalText: typeof goal.text === \"string\" ? goal.text : null,\n evidence: typeof goal.evidence === \"string\" ? goal.evidence : null,\n // Console pauses and several server paths put the human explanation on\n // `rationale`, not `pausedReason` — same fallback the goal pill uses, so a\n // paused worker card never shows \"Worker paused\" with the reason missing.\n pausedReason:\n typeof goal.pausedReason === \"string\"\n ? goal.pausedReason\n : typeof goal.rationale === \"string\"\n ? goal.rationale\n : null,\n };\n}\n\nfunction isSessionStatus(value: unknown): value is SessionStatus {\n return typeof value === \"string\" && (SESSION_STATUSES as readonly string[]).includes(value);\n}\n\n/** Does this tool output represent an error (explicit flag or MCP `isError`)? */\nfunction isErrorOutput(payload: Record<string, unknown>): boolean {\n if (payload.error === true || payload.failed === true) {\n return true;\n }\n const output = payload.output;\n return (\n !!output && typeof output === \"object\" && (output as { isError?: unknown }).isError === true\n );\n}\n\nfunction findOpenCall(\n items: TimelineItem[],\n callId: string | null,\n): ToolCallItem | WorkerItem | undefined {\n const reversed = [...items].reverse();\n const isCall = (item: TimelineItem): item is ToolCallItem | WorkerItem =>\n item.kind === \"tool-call\" || item.kind === \"worker\";\n if (callId) {\n const byId = reversed.find((item) => isCall(item) && item.callId === callId);\n if (byId) {\n return byId as ToolCallItem | WorkerItem;\n }\n }\n return reversed.find(\n (item): item is ToolCallItem | WorkerItem => isCall(item) && item.status === \"running\",\n );\n}\n\nfunction findOpenSandbox(items: TimelineItem[], name: string): SandboxItem | undefined {\n return [...items]\n .reverse()\n .find(\n (item): item is SandboxItem =>\n item.kind === \"sandbox\" && item.name === name && item.status === \"running\",\n );\n}\n\nfunction failureMessage(payload: Record<string, unknown>): string | null {\n for (const key of [\"error\", \"message\"] as const) {\n const value = payload[key];\n if (typeof value === \"string\" && value.trim().length > 0) {\n // Auth/quota provider errors are rewritten for the right audience\n // (raw text remains in the event payload for debug surfaces).\n return humanizeFailureReason(value);\n }\n }\n return null;\n}\n\nfunction goalText(payload: Record<string, unknown>): string | null {\n if (typeof payload.text === \"string\" && payload.text) {\n return payload.text;\n }\n const goal = asRecord(payload.goal);\n if (typeof goal.text === \"string\" && goal.text) {\n return goal.text;\n }\n if (typeof payload.prompt === \"string\" && payload.prompt) {\n return payload.prompt;\n }\n return null;\n}\n\n/**\n * Agent-owned goal mutations already have an in-cluster tool row. Suppress the\n * breakaway landmark for those only. `goal.completed` has no actor field today\n * and is only emitted by the agent tool, so it is always suppressed. API /\n * system / create-session / continuation landmarks stay visible.\n */\nfunction shouldSuppressAgentGoalLandmark(type: string, payload: Record<string, unknown>): boolean {\n if (type === \"goal.completed\") {\n return true;\n }\n if (type === \"goal.set\" || type === \"goal.updated\" || type === \"goal.paused\") {\n return payload.actor === \"agent\";\n }\n return false;\n}\n\n/**\n * Fold a `memory.saved` / `memory.corrected` event into a {@link MemoryItem}.\n * Reads DEFENSIVELY (the payload is untyped `unknown`, no Zod schema): a missing\n * memory id means a malformed event, so we return null and the case drops it.\n */\nfunction memoryItem(\n id: string,\n type: string,\n turnId: string | null,\n payload: Record<string, unknown>,\n occurredAt: string,\n): MemoryItem | null {\n const memoryId =\n typeof payload.memoryId === \"string\" && payload.memoryId ? payload.memoryId : null;\n if (!memoryId) {\n return null;\n }\n const replacementPreview =\n typeof payload.replacementPreview === \"string\" ? payload.replacementPreview : undefined;\n const replacementMemoryId =\n typeof payload.replacementMemoryId === \"string\" ? payload.replacementMemoryId : undefined;\n const action = typeof payload.action === \"string\" ? payload.action : undefined;\n return {\n kind: \"memory\",\n id,\n turnId,\n variant: type === \"memory.corrected\" ? \"corrected\" : \"saved\",\n memoryKind: stringValue(payload.kind),\n preview: stringValue(payload.preview),\n ...(payload.deduped === true ? { deduped: true } : {}),\n ...(replacementPreview ? { replacementPreview } : {}),\n ...(action ? { action } : {}),\n memoryId,\n ...(replacementMemoryId ? { replacementMemoryId } : {}),\n occurredAt,\n };\n}\n\nconst AUTH_NEEDED_REASONS: ReadonlySet<string> = new Set([\n \"missing_connection\",\n \"expired\",\n \"insufficient_scope\",\n \"refresh_failed\",\n \"personal_authority_unavailable\",\n \"unsupported_auth\",\n \"resource_scope_unavailable\",\n]);\n\nfunction authNeededReason(value: unknown): AuthNeededItem[\"reason\"] {\n return typeof value === \"string\" && AUTH_NEEDED_REASONS.has(value)\n ? (value as AuthNeededItem[\"reason\"])\n : null;\n}\n\nfunction stringList(value: unknown): string[] {\n return Array.isArray(value)\n ? value.filter((entry): entry is string => typeof entry === \"string\" && entry.trim().length > 0)\n : [];\n}\n\nfunction reasoningText(payload: unknown): string {\n const record = asRecord(payload);\n if (typeof record.text === \"string\") {\n return record.text;\n }\n const content = asRecord(asRecord(record.item).rawItem).content;\n if (!Array.isArray(content)) {\n return \"\";\n }\n return content\n .map((part) => {\n const text = asRecord(part).text;\n return stringValue(text);\n })\n .join(\"\");\n}\n\n/** The worker's initial/sent message from `session_create`/`session_send_message` args. */\nfunction workerPrompt(args: unknown): string | null {\n const record = asRecord(typeof args === \"string\" ? tryParseJson(args) : args);\n for (const key of [\"initialMessage\", \"message\", \"text\", \"prompt\"] as const) {\n const value = record[key];\n if (typeof value === \"string\" && value.trim().length > 0) {\n return value;\n }\n }\n return null;\n}\n\n/**\n * Find a session id in orchestration tool arguments or output. Handles raw\n * objects, JSON strings, and MCP tool results (`{ content: [{ type: \"text\",\n * text: \"{...}\" }], structuredContent? }`).\n */\nexport function extractSessionRef(value: unknown, depth = 0): string | null {\n if (depth > 6 || value === null || value === undefined) {\n return null;\n }\n if (typeof value === \"string\") {\n return extractSessionRef(tryParseJson(value), depth + 1);\n }\n if (Array.isArray(value)) {\n for (const entry of value) {\n const found = extractSessionRef(entry, depth + 1);\n if (found) {\n return found;\n }\n }\n return null;\n }\n if (typeof value !== \"object\") {\n return null;\n }\n const record = value as Record<string, unknown>;\n if (typeof record.sessionId === \"string\" && looksLikeId(record.sessionId)) {\n return record.sessionId;\n }\n if (\n typeof record.id === \"string\" &&\n looksLikeId(record.id) &&\n (\"status\" in record || \"workspaceId\" in record || \"initialMessage\" in record)\n ) {\n return record.id;\n }\n for (const key of [\"structuredContent\", \"session\", \"result\", \"content\"] as const) {\n if (key in record) {\n const found = extractSessionRef(record[key], depth + 1);\n if (found) {\n return found;\n }\n }\n }\n if (typeof record.text === \"string\") {\n return extractSessionRef(tryParseJson(record.text), depth + 1);\n }\n return null;\n}\n\nfunction looksLikeId(value: string): boolean {\n return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);\n}\n"],"mappings":";;;;;;;;AAUO,SAAS,YAAY,MAAsB;AAChD,QAAM,WAAW,KAAK,QAAQ,IAAI;AAClC,SAAO,YAAY,IAAI,KAAK,MAAM,WAAW,CAAC,IAAI;AACpD;AAOO,SAAS,gBAAgB,UAAkB,MAAuB;AACvE,SAAO,aAAa,QAAQ,SAAS,SAAS,KAAK,IAAI,EAAE;AAC3D;AAMO,SAAS,gBAAgB,MAAsB;AACpD,QAAM,SAAS,YAAY,IAAI,EAAE,QAAQ,UAAU,GAAG,EAAE,KAAK;AAC7D,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AACA,SAAO,OAAO,OAAO,CAAC,EAAE,YAAY,IAAI,OAAO,MAAM,CAAC;AACxD;;;ACjCA,IAAM,EAAE,SAAS,kBAAkB,IAAI,MAAM,OAAO,yCAA6B;AA0CjF,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAa5B,IAAM,4BAA4B,oBAAI,IAAI,CAAC,eAAe,gBAAgB,CAAC;AAEpE,SAAS,cAAc,QAAwC;AACpE,QAAM,Q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AAW,UAAU,SAAS,GAAY;AAChF,QAAI,OAAO,QAAQ;AACjB,YAAM,QAAQ,kBAAkB,OAAO,GAAG,GAAG,QAAQ,CAAC;AACtD,UAAI,OAAO;AACT,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACA,MAAI,OAAO,OAAO,SAAS,UAAU;AACnC,WAAO,kBAAkB,aAAa,OAAO,IAAI,GAAG,QAAQ,CAAC;AAAA,EAC/D;AACA,SAAO;AACT;AAEA,SAAS,YAAY,OAAwB;AAC3C,SAAO,kEAAkE,KAAK,KAAK;AACrF;","names":["candidate"]}
@@ -2,7 +2,7 @@ import {
2
2
  buildTimeline,
3
3
  groupTimeline,
4
4
  sessionStatusFromEvents
5
- } from "./chunk-J2RVJ6JX.js";
5
+ } from "./chunk-4IJCL7YO.js";
6
6
  import {
7
7
  useDebouncedCallback,
8
8
  useEmbeddedFileAttachments,
@@ -2100,4 +2100,4 @@ export {
2100
2100
  isHumanInputEvent,
2101
2101
  useHumanInputRequests
2102
2102
  };
2103
- //# sourceMappingURL=chunk-OKKMZDQF.js.map
2103
+ //# sourceMappingURL=chunk-FSPDND3P.js.map
@@ -103,6 +103,32 @@ function updatePendingComposerShadow(key, operation, shadow) {
103
103
  rememberPendingComposerOperation(key, next);
104
104
  return next;
105
105
  }
106
+ var STEERING_SETTLEMENT_EVENT_TYPES = /* @__PURE__ */ new Set([
107
+ "turn.started",
108
+ "turn.completed",
109
+ "turn.failed",
110
+ "turn.cancelled",
111
+ "turn.superseded"
112
+ ]);
113
+ function isSteeringSettlementEvent(event) {
114
+ return STEERING_SETTLEMENT_EVENT_TYPES.has(event.type);
115
+ }
116
+ function steeringAcceptedEvent(steering, events) {
117
+ return events.find(
118
+ (event) => event.type === "user.message" && steering.clientEventId !== null && event.clientEventId === steering.clientEventId
119
+ );
120
+ }
121
+ function steeringSettledByEvents(steering, events) {
122
+ const acceptedEventId = steering.triggerEventId ?? steeringAcceptedEvent(steering, events)?.id ?? null;
123
+ return events.some((event) => {
124
+ if (steering.turnId && event.turnId === steering.turnId && isSteeringSettlementEvent(event)) {
125
+ return true;
126
+ }
127
+ if (event.type !== "turn.started" || !acceptedEventId) return false;
128
+ const payload = event.payload;
129
+ return typeof payload === "object" && payload !== null && "triggerEventId" in payload && payload.triggerEventId === acceptedEventId;
130
+ });
131
+ }
106
132
  function useComposer(sessionId, options = {}) {
107
133
  const { client, workspaceId, registerSessionReconciler } = useEmbeddedSession(options);
108
134
  const durableDrafts = options.draftPersistence !== "disabled";
@@ -113,6 +139,15 @@ function useComposer(sessionId, options = {}) {
113
139
  const [value, setValue] = useState(() => initialShadow?.text ?? "");
114
140
  const [stateTargetKey, setStateTargetKey] = useState(targetKey);
115
141
  const [sending, setSending] = useState(false);
142
+ const [steering, setSteering] = useState(
143
+ () => initialPendingOperation?.delivery === "steer" ? {
144
+ phase: "submitting",
145
+ text: initialPendingOperation.input.text,
146
+ clientEventId: initialPendingOperation.input.clientEventId ?? null,
147
+ triggerEventId: null,
148
+ turnId: null
149
+ } : null
150
+ );
116
151
  const [pausing, setPausing] = useState(false);
117
152
  const [resuming, setResuming] = useState(false);
118
153
  const [error, setError] = useState(null);
@@ -124,6 +159,8 @@ function useComposer(sessionId, options = {}) {
124
159
  () => initialShadow?.resources ?? []
125
160
  );
126
161
  const pendingOperationRef = useRef(initialPendingOperation);
162
+ const steeringSettlementEventsRef = useRef([]);
163
+ const steeringRef = useRef(steering);
127
164
  const pendingClientEventId = useRef(
128
165
  initialPendingOperation?.input.clientEventId ?? null
129
166
  );
@@ -141,6 +178,9 @@ function useComposer(sessionId, options = {}) {
141
178
  useLayoutEffect(() => {
142
179
  onDraftAppliedRef.current = onDraftApplied;
143
180
  }, [onDraftApplied]);
181
+ useLayoutEffect(() => {
182
+ steeringRef.current = steering;
183
+ }, [steering]);
144
184
  const sendExtrasRef = useRef(options.sendExtras);
145
185
  sendExtrasRef.current = options.sendExtras;
146
186
  const sendBlockedRef = useRef(options.sendBlocked);
@@ -153,6 +193,7 @@ function useComposer(sessionId, options = {}) {
153
193
  targetGeneration.current += 1;
154
194
  draftReadGeneration.current += 1;
155
195
  pendingOperationRef.current = restorePendingComposerOperation(pendingOperationKey);
196
+ steeringSettlementEventsRef.current = [];
156
197
  pendingClientEventId.current = pendingOperationRef.current?.input.clientEventId ?? null;
157
198
  const shadow = pendingOperationRef.current?.newerShadow;
158
199
  localEditRevision.current = shadow ? 1 : 0;
@@ -164,6 +205,15 @@ function useComposer(sessionId, options = {}) {
164
205
  setStateTargetKey(targetKey);
165
206
  setValue(shadow?.text ?? "");
166
207
  setSending(false);
208
+ setSteering(
209
+ pendingOperationRef.current?.delivery === "steer" ? {
210
+ phase: "submitting",
211
+ text: pendingOperationRef.current.input.text,
212
+ clientEventId: pendingOperationRef.current.input.clientEventId ?? null,
213
+ triggerEventId: null,
214
+ turnId: null
215
+ } : null
216
+ );
167
217
  setPausing(false);
168
218
  setResuming(false);
169
219
  setError(null);
@@ -301,17 +351,73 @@ function useComposer(sessionId, options = {}) {
301
351
  if (!sessionId || !durableDrafts) return;
302
352
  return registerSessionReconciler(sessionId, "composer", async () => await loadDraft(false));
303
353
  }, [durableDrafts, loadDraft, registerSessionReconciler, sessionId]);
354
+ const reconcileSteering = useCallback(async () => {
355
+ if (!sessionId || !steeringRef.current) return;
356
+ const ownedTargetKey = targetKey;
357
+ let events;
358
+ try {
359
+ events = await client.listEvents(workspaceId, sessionId, {
360
+ includeTypes: [
361
+ "user.message",
362
+ "turn.started",
363
+ "turn.completed",
364
+ "turn.failed",
365
+ "turn.cancelled",
366
+ "turn.superseded"
367
+ ],
368
+ limit: 250,
369
+ payloadMode: "full"
370
+ });
371
+ } catch {
372
+ return;
373
+ }
374
+ if (targetKeyRef.current !== ownedTargetKey) return;
375
+ setSteering((current) => {
376
+ if (!current) return current;
377
+ if (steeringSettledByEvents(current, events)) {
378
+ steeringSettlementEventsRef.current = [];
379
+ return null;
380
+ }
381
+ const accepted = steeringAcceptedEvent(current, events);
382
+ if (!accepted || current.triggerEventId) return current;
383
+ return {
384
+ ...current,
385
+ phase: "accepted",
386
+ triggerEventId: accepted.id
387
+ };
388
+ });
389
+ }, [client, sessionId, targetKey, workspaceId]);
304
390
  useSessionEventTrigger(
305
391
  client,
306
392
  workspaceId,
307
393
  sessionId,
308
- isComposerDraftEvent,
309
- () => void loadDraft(false),
394
+ (event) => isComposerDraftEvent(event) || isSteeringSettlementEvent(event),
395
+ (event) => {
396
+ if (isComposerDraftEvent(event)) void loadDraft(false);
397
+ if (!isSteeringSettlementEvent(event)) return;
398
+ steeringSettlementEventsRef.current = [
399
+ ...steeringSettlementEventsRef.current.slice(-15),
400
+ event
401
+ ];
402
+ setSteering((current) => {
403
+ if (!current || !steeringSettledByEvents(current, [event])) return current;
404
+ steeringSettlementEventsRef.current = [];
405
+ return null;
406
+ });
407
+ },
310
408
  {
311
- enabled: Boolean(sessionId) && durableDrafts,
409
+ enabled: Boolean(sessionId) && (durableDrafts || steering !== null),
312
410
  ...options.events !== void 0 ? { events: options.events } : {}
313
- }
411
+ },
412
+ reconcileSteering
314
413
  );
414
+ useEffect(() => {
415
+ if (!steering) return;
416
+ const observed = [...options.events ?? [], ...steeringSettlementEventsRef.current];
417
+ if (!steeringSettledByEvents(steering, observed)) return;
418
+ steeringSettlementEventsRef.current = [];
419
+ setSteering(null);
420
+ }, [options.events, steering]);
315
421
  const currentDraftPayload = useCallback(() => {
316
422
  if (!durableDrafts || targetKeyRef.current !== targetKey) return null;
317
423
  const base = draftRef.current;
@@ -427,6 +533,7 @@ function useComposer(sessionId, options = {}) {
427
533
  pendingClientEventId.current = null;
428
534
  forgetPendingComposerOperation(operationKey);
429
535
  };
536
+ let keepSteering = pending?.delivery === "steer";
430
537
  const settleAccepted = (operation) => {
431
538
  clearPending();
432
539
  const draftWasUnchanged = valueRef.current === operation.draftAtSend;
@@ -458,25 +565,34 @@ function useComposer(sessionId, options = {}) {
458
565
  };
459
566
  const deliver = async (operation) => {
460
567
  if (operation.delivery === "steer") {
461
- await client.steerMessage(workspaceId, sessionId, operation.input);
462
- } else {
463
- await client.sendMessage(workspaceId, sessionId, operation.input);
568
+ return await client.steerMessage(workspaceId, sessionId, operation.input);
464
569
  }
570
+ await client.sendMessage(workspaceId, sessionId, operation.input);
571
+ return null;
465
572
  };
573
+ if (delivery === "steer") {
574
+ setSteering({
575
+ phase: "submitting",
576
+ text: rawText,
577
+ clientEventId: pending?.input.clientEventId ?? pendingClientEventId.current,
578
+ triggerEventId: null,
579
+ turnId: null
580
+ });
581
+ }
466
582
  setSending(true);
467
583
  setError(null);
468
584
  try {
469
585
  if (pending) {
470
- let accepted = false;
586
+ let acceptedEvent = null;
471
587
  try {
472
588
  const events = await client.listEvents(workspaceId, sessionId, {
473
589
  includeTypes: ["user.message"],
474
590
  limit: 100,
475
591
  payloadMode: "none"
476
592
  });
477
- accepted = events.some(
593
+ acceptedEvent = events.find(
478
594
  (event) => event.type === "user.message" && event.clientEventId === pending.input.clientEventId
479
- );
595
+ ) ?? null;
480
596
  } catch (cause) {
481
597
  if (targetKeyRef.current === ownedTargetKey && targetGeneration.current === ownedGeneration) {
482
598
  setError(asError(cause));
@@ -486,7 +602,17 @@ function useComposer(sessionId, options = {}) {
486
602
  if (targetKeyRef.current !== ownedTargetKey || targetGeneration.current !== ownedGeneration) {
487
603
  return false;
488
604
  }
489
- if (accepted) {
605
+ if (acceptedEvent) {
606
+ if (pending.delivery === "steer") {
607
+ keepSteering = true;
608
+ setSteering({
609
+ phase: "accepted",
610
+ text: pending.input.text,
611
+ clientEventId: pending.input.clientEventId ?? null,
612
+ triggerEventId: acceptedEvent.id,
613
+ turnId: null
614
+ });
615
+ }
490
616
  settleAccepted(pending);
491
617
  return true;
492
618
  }
@@ -499,8 +625,19 @@ function useComposer(sessionId, options = {}) {
499
625
  return false;
500
626
  }
501
627
  try {
502
- await deliver(pending);
628
+ const result = await deliver(pending);
629
+ if (pending.delivery === "steer" && result) {
630
+ keepSteering = true;
631
+ setSteering({
632
+ phase: "accepted",
633
+ text: pending.input.text,
634
+ clientEventId: pending.input.clientEventId ?? null,
635
+ triggerEventId: result.accepted.id,
636
+ turnId: result.turn.id
637
+ });
638
+ }
503
639
  } catch (cause) {
640
+ if (pending.delivery === "steer") keepSteering = true;
504
641
  if (targetKeyRef.current === ownedTargetKey && targetGeneration.current === ownedGeneration) {
505
642
  setError(asError(cause));
506
643
  }
@@ -539,11 +676,32 @@ function useComposer(sessionId, options = {}) {
539
676
  };
540
677
  pendingOperationRef.current = operation;
541
678
  rememberPendingComposerOperation(operationKey, operation);
679
+ if (delivery === "steer") {
680
+ setSteering({
681
+ phase: "submitting",
682
+ text: sendText,
683
+ clientEventId: input.clientEventId ?? null,
684
+ triggerEventId: null,
685
+ turnId: null
686
+ });
687
+ }
542
688
  try {
543
- await deliver(operation);
689
+ const result = await deliver(operation);
690
+ if (delivery === "steer" && result) {
691
+ keepSteering = true;
692
+ setSteering({
693
+ phase: "accepted",
694
+ text: sendText,
695
+ clientEventId: input.clientEventId ?? null,
696
+ triggerEventId: result.accepted.id,
697
+ turnId: result.turn.id
698
+ });
699
+ }
544
700
  } catch (cause) {
545
701
  if (!isOutcomeUnknownError(cause)) {
546
702
  clearPending();
703
+ } else if (delivery === "steer") {
704
+ keepSteering = true;
547
705
  }
548
706
  if (targetKeyRef.current === ownedTargetKey && targetGeneration.current === ownedGeneration) {
549
707
  setError(asError(cause));
@@ -558,6 +716,7 @@ function useComposer(sessionId, options = {}) {
558
716
  } finally {
559
717
  if (targetKeyRef.current === ownedTargetKey && targetGeneration.current === ownedGeneration) {
560
718
  setSending(false);
719
+ if (delivery === "steer" && !keepSteering) setSteering(null);
561
720
  }
562
721
  }
563
722
  },
@@ -763,6 +922,7 @@ function useComposer(sessionId, options = {}) {
763
922
  hasDraftContent,
764
923
  send,
765
924
  steer,
925
+ steering: identityMatches ? steering : null,
766
926
  sending: identityMatches ? sending : false,
767
927
  canSend: identityMatches && Boolean(sessionId) && !sending && sendBlockedRef.current?.() !== true && (hasPendingOperation || value.trim().length > 0 || hasReadyResources),
768
928
  pause,
@@ -858,4 +1018,4 @@ export {
858
1018
  shouldSubmitOnKey,
859
1019
  shouldSteerOnKey
860
1020
  };
861
- //# sourceMappingURL=chunk-FT2TXNGZ.js.map
1021
+ //# sourceMappingURL=chunk-HJ4OQVGW.js.map