@opengeni/react 0.36.1 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -2
- package/dist/{chunk-J2RVJ6JX.js → chunk-4IJCL7YO.js} +13 -2
- package/dist/chunk-4IJCL7YO.js.map +1 -0
- package/dist/{chunk-7CJOAW3V.js → chunk-EB67J347.js} +1 -135
- package/dist/chunk-EB67J347.js.map +1 -0
- package/dist/chunk-EKZH6IDG.js +141 -0
- package/dist/chunk-EKZH6IDG.js.map +1 -0
- package/dist/{chunk-OKKMZDQF.js → chunk-JALF5FI3.js} +9 -7
- package/dist/{chunk-OKKMZDQF.js.map → chunk-JALF5FI3.js.map} +1 -1
- package/dist/{chunk-Z5FV355Z.js → chunk-KR2SK5GJ.js} +1382 -724
- package/dist/chunk-KR2SK5GJ.js.map +1 -0
- package/dist/{chunk-N4XEBE23.js → chunk-OMCFRWHL.js} +22 -13
- package/dist/{chunk-N4XEBE23.js.map → chunk-OMCFRWHL.js.map} +1 -1
- package/dist/{chunk-FT2TXNGZ.js → chunk-Q2NCKWTK.js} +183 -18
- package/dist/chunk-Q2NCKWTK.js.map +1 -0
- package/dist/{chunk-22RM4GMO.js → chunk-SJKT4TKW.js} +26 -2
- package/dist/chunk-SJKT4TKW.js.map +1 -0
- package/dist/{chunk-ALA3UGWB.js → chunk-SXIQK54Z.js} +8 -6
- package/dist/{chunk-ALA3UGWB.js.map → chunk-SXIQK54Z.js.map} +1 -1
- package/dist/chunk-WZT5G5OR.js +433 -0
- package/dist/chunk-WZT5G5OR.js.map +1 -0
- package/dist/client.d.ts +2 -0
- package/dist/components/chat-composer.d.ts +7 -1
- package/dist/components/human-input-form.d.ts +16 -6
- package/dist/components/human-input-surface.d.ts +19 -0
- package/dist/components/machine-input-display.d.ts +12 -0
- package/dist/components/message-timeline.d.ts +6 -1
- package/dist/components/model-policy-picker.d.ts +78 -0
- package/dist/components/session-chrome.d.ts +2 -1
- package/dist/components/tip-follow.d.ts +30 -0
- package/dist/composer.d.ts +2 -0
- package/dist/composer.js +22 -5
- package/dist/hooks/use-composer.d.ts +10 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +2261 -2230
- package/dist/index.js.map +1 -1
- package/dist/machines.js +4 -3
- package/dist/model-policy.d.ts +12 -4
- package/dist/model-policy.js +5 -1
- package/dist/realtime/dropdown-menu.d.ts +16 -0
- package/dist/realtime/realtime-control.d.ts +126 -0
- package/dist/realtime.d.ts +11 -0
- package/dist/realtime.js +1023 -0
- package/dist/realtime.js.map +1 -0
- package/dist/session-context.d.ts +7 -1
- package/dist/session-ui.d.ts +2 -0
- package/dist/session-ui.js +6 -4
- package/dist/session.js +5 -4
- package/dist/timeline/compute-label.d.ts +2 -0
- package/dist/timeline/index.d.ts +1 -0
- package/dist/timeline/types.d.ts +5 -0
- package/package.json +7 -2
- package/src/client.ts +13 -0
- package/src/components/chat-composer.tsx +19 -5
- package/src/components/composer-transcription-control.tsx +2 -2
- package/src/components/composer.tsx +14 -5
- package/src/components/human-input-form.tsx +506 -186
- package/src/components/human-input-surface.tsx +80 -0
- package/src/components/machine-input-display.ts +83 -0
- package/src/components/message-timeline.tsx +348 -308
- package/src/components/model-policy-picker.tsx +587 -0
- package/src/components/sandbox-files.tsx +1 -1
- package/src/components/session-chrome.tsx +141 -15
- package/src/components/tip-follow.ts +127 -6
- package/src/composer.ts +13 -0
- package/src/hooks/use-composer.ts +229 -29
- package/src/index.ts +19 -0
- package/src/model-policy.ts +51 -7
- package/src/realtime/dropdown-menu.tsx +123 -0
- package/src/realtime/realtime-control.tsx +1178 -0
- package/src/realtime.ts +27 -0
- package/src/session-context.ts +16 -0
- package/src/session-ui.ts +2 -0
- package/src/timeline/compute-label.tsx +18 -0
- package/src/timeline/index.ts +3 -0
- package/src/timeline/projection.ts +21 -1
- package/src/timeline/tool-renderers.tsx +232 -43
- package/src/timeline/types.ts +5 -0
- package/styles/index.css +61 -0
- package/styles/tokens.css +2 -0
- package/dist/chunk-22RM4GMO.js.map +0 -1
- package/dist/chunk-7CJOAW3V.js.map +0 -1
- package/dist/chunk-FT2TXNGZ.js.map +0 -1
- package/dist/chunk-J2RVJ6JX.js.map +0 -1
- package/dist/chunk-Z5FV355Z.js.map +0 -1
package/README.md
CHANGED
|
@@ -13,7 +13,8 @@ The default root import (`@opengeni/react`) is the clean sandbox-agnostic
|
|
|
13
13
|
surface — the chat/timeline hooks and components plus the sandbox workspace
|
|
14
14
|
suite. Advanced chat-composer composition lives under
|
|
15
15
|
`@opengeni/react/composer`; Connected-Machine UI lives under
|
|
16
|
-
`@opengeni/react/machines
|
|
16
|
+
`@opengeni/react/machines`; realtime voice controls live under the lazily
|
|
17
|
+
loadable `@opengeni/react/realtime` subpath. (The root barrel still re-exports the machines
|
|
17
18
|
island for back-compat, deprecated per #144.)
|
|
18
19
|
|
|
19
20
|
Design-system-first: every visual decision routes through CSS-variable tokens
|
|
@@ -118,6 +119,89 @@ export function App() {
|
|
|
118
119
|
}
|
|
119
120
|
```
|
|
120
121
|
|
|
122
|
+
## Realtime composer controls (`@opengeni/react/realtime`)
|
|
123
|
+
|
|
124
|
+
The realtime subpath is the exact OpenGeni composer experience: model catalog
|
|
125
|
+
and selection, split-button motion, start/stop/retry states, microphone and
|
|
126
|
+
audio mute controls, diagnostics, recovery, and the same copy, ARIA, classes,
|
|
127
|
+
and styling used by the web console. It is deliberately separate from the root
|
|
128
|
+
entry so SSR and non-realtime consumers do not eagerly load browser media or
|
|
129
|
+
transport code.
|
|
130
|
+
|
|
131
|
+
For an existing session, place one public component in the composer's action
|
|
132
|
+
slot. It resolves `client` and `workspaceId` from `OpenGeniProvider` and reuses
|
|
133
|
+
the host's existing session/event projection rather than opening a duplicate
|
|
134
|
+
stream:
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
import { ChatComposer } from "@opengeni/react";
|
|
138
|
+
import { SessionRealtimeControl } from "@opengeni/react/realtime";
|
|
139
|
+
|
|
140
|
+
<ChatComposer
|
|
141
|
+
composer={composer}
|
|
142
|
+
effectiveControl={effectiveControl}
|
|
143
|
+
actionsStart={
|
|
144
|
+
<SessionRealtimeControl
|
|
145
|
+
sessionId={sessionId}
|
|
146
|
+
sessionStatus={sessionStatus}
|
|
147
|
+
effectiveControl={effectiveControl}
|
|
148
|
+
events={events}
|
|
149
|
+
eventsReady={!initialLoading}
|
|
150
|
+
codexConnected={codexConnected}
|
|
151
|
+
/>
|
|
152
|
+
}
|
|
153
|
+
/>;
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
For a new-session composer, create the session with `startMode: "realtime"`,
|
|
157
|
+
navigate to it, and pass the selected model to the same existing-session
|
|
158
|
+
control's `realtimeAutostartModel` prop:
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
import { NewSessionRealtimeControl } from "@opengeni/react/realtime";
|
|
162
|
+
|
|
163
|
+
<NewSessionRealtimeControl
|
|
164
|
+
codexConnected={codexConnected}
|
|
165
|
+
onStart={async (model) => {
|
|
166
|
+
const session = await client.createSession(workspaceId, {
|
|
167
|
+
requestedSessionId: crypto.randomUUID(),
|
|
168
|
+
startMode: "realtime",
|
|
169
|
+
idempotencyKey: crypto.randomUUID(),
|
|
170
|
+
});
|
|
171
|
+
navigateToSession(session.id, { realtimeAutostartModel: model });
|
|
172
|
+
return true;
|
|
173
|
+
}}
|
|
174
|
+
/>;
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Proxy-backed hosts can pass explicit `client` and `workspaceId` overrides. The
|
|
178
|
+
exported `EmbeddedRealtimeSessionClientLike` requires only catalog, begin,
|
|
179
|
+
Codex/Gateway negotiation, activation, heartbeat, ledger sync, and end. For
|
|
180
|
+
custom layouts, use `useSessionRealtime`, `useRealtimeModelSelection`,
|
|
181
|
+
`RealtimeVoiceControl`, and `RealtimeModelPickerMenu`; the batteries-included
|
|
182
|
+
wrappers remain the recommended path.
|
|
183
|
+
|
|
184
|
+
The reference consumer is `demo/realtime.html`. Run `bun run demo` from
|
|
185
|
+
`packages/react`, then open `http://localhost:3100/realtime.html?mode=mock` for
|
|
186
|
+
deterministic selection/start/mute/stop/reconnect/error testing. Use
|
|
187
|
+
`?mode=live&workspaceId=…&sessionId=…` against the web server's same-origin
|
|
188
|
+
`/demo-api` proxy for a real local OpenGeni environment. Configure
|
|
189
|
+
`OPENGENI_DEMO_API_URL` and, only on the server, optional demo API/access
|
|
190
|
+
credentials; the browser receives neither credential. Prefer the deployment's
|
|
191
|
+
normal browser authentication. If the proxy needs a server credential, create a
|
|
192
|
+
dedicated tenant-scoped, least-privilege key for the reference demo and never
|
|
193
|
+
reuse a deployment-wide runtime secret. Helm deployments can mount a Secret
|
|
194
|
+
containing only `api-key` and/or `access-key` with
|
|
195
|
+
`web.demoApiCredentialsSecret`; those values are mounted read-only rather than
|
|
196
|
+
exposed as container environment variables. Local non-Kubernetes servers may
|
|
197
|
+
instead use `OPENGENI_DEMO_API_KEY` and/or `OPENGENI_DEMO_ACCESS_KEY`.
|
|
198
|
+
|
|
199
|
+
Microphone capture works on `localhost` or a secure HTTPS origin. A remote HTTP
|
|
200
|
+
deployment cannot request microphone access. The live page exercises catalog
|
|
201
|
+
loading, realtime-first creation, Codex Live, Gateway models, mute, recovery,
|
|
202
|
+
delegation/context timeline updates, structured questions, and stop/restart
|
|
203
|
+
through published package APIs only.
|
|
204
|
+
|
|
121
205
|
## Composer customization (`@opengeni/react/composer`)
|
|
122
206
|
|
|
123
207
|
Use `ChatComposer` for the standard layout and its `controlsStart`, `header`,
|
|
@@ -290,6 +374,10 @@ intentional changes should regenerate those snapshots and review the diff.
|
|
|
290
374
|
- `FleetTile` — one session in a fleet grid: title, status, model, recency.
|
|
291
375
|
- `ModelPicker` — a compact model dropdown for a composer slot, grouping the
|
|
292
376
|
host-exposed models by provider.
|
|
377
|
+
- `ModelPolicyPicker` — the full model policy control used by the OpenGeni web
|
|
378
|
+
app: provider/billing rails, model availability, reasoning effort, and
|
|
379
|
+
runnable latency modes such as Fast. It accepts either `ClientModel[]` or
|
|
380
|
+
catalog-backed `PickerModelRow[]`, and supports host-supplied labels.
|
|
293
381
|
- `Markdown` — the timeline's markdown renderer (GFM), also usable standalone.
|
|
294
382
|
- `CommandPalette` — the slash-command palette UI over `useSlashCommands`.
|
|
295
383
|
|
|
@@ -414,4 +502,6 @@ what the surfaces you mount need:
|
|
|
414
502
|
`bun run demo` (from this package) serves a harness that drives the real hooks
|
|
415
503
|
and components against a scripted mock client — a manager ops-channel narrative
|
|
416
504
|
with streaming, tool calls, and a worker spawn, plus fleet and scheduled-task
|
|
417
|
-
views and a dark/light toggle. `
|
|
505
|
+
views and a dark/light toggle. `realtime.html` is the public-package reference
|
|
506
|
+
consumer described above, with deterministic mock and same-origin live modes.
|
|
507
|
+
`bun run demo:build` is part of the repo gate.
|
|
@@ -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-
|
|
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,QAAwB,CAAC;AAC/B,QAAM,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ChF,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"]}
|
|
@@ -1,127 +1,3 @@
|
|
|
1
|
-
// src/session-context.ts
|
|
2
|
-
import { createContext, useContext } from "react";
|
|
3
|
-
var OpenGeniContext = createContext(null);
|
|
4
|
-
var NOOP_REGISTER_RECONCILER = () => () => void 0;
|
|
5
|
-
var NOOP_RECONCILE_SESSION = async () => void 0;
|
|
6
|
-
function useEmbeddedClientRefinement(override, requiredMethods, hookName) {
|
|
7
|
-
const context = useContext(OpenGeniContext);
|
|
8
|
-
const candidate = override.client ?? context?.client;
|
|
9
|
-
const workspaceId = override.workspaceId ?? context?.workspaceId;
|
|
10
|
-
if (!candidate || !workspaceId) {
|
|
11
|
-
throw new Error(
|
|
12
|
-
"@opengeni/react: no OpenGeni client/workspace available. Wrap the tree in <OpenGeniProvider> or pass { client, workspaceId } to the hook."
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
const methods = candidate;
|
|
16
|
-
const missing = requiredMethods.filter((method) => typeof methods[method] !== "function");
|
|
17
|
-
if (missing.length > 0) {
|
|
18
|
-
throw new Error(
|
|
19
|
-
`@opengeni/react: ${hookName} requires client method${missing.length === 1 ? "" : "s"} ${missing.join(", ")}.`
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
client: candidate,
|
|
24
|
-
workspaceId,
|
|
25
|
-
workspaceControlEvent: context?.workspaceControlEvent ?? null,
|
|
26
|
-
workspaceControlConnectionState: context?.workspaceControlConnectionState ?? "idle",
|
|
27
|
-
registerSessionReconciler: context?.registerSessionReconciler ?? NOOP_REGISTER_RECONCILER,
|
|
28
|
-
reconcileSession: context?.reconcileSession ?? NOOP_RECONCILE_SESSION
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function eventClientMethods(override, directMethods) {
|
|
32
|
-
const hasSharedEventFeed = "events" in override && override.events !== void 0;
|
|
33
|
-
return hasSharedEventFeed ? directMethods : ["getSession", "streamEvents", ...directMethods];
|
|
34
|
-
}
|
|
35
|
-
function useOpenGeni(override = {}) {
|
|
36
|
-
const context = useContext(OpenGeniContext);
|
|
37
|
-
const client = override.client ?? context?.client;
|
|
38
|
-
const workspaceId = override.workspaceId ?? context?.workspaceId;
|
|
39
|
-
if (!client || !workspaceId) {
|
|
40
|
-
throw new Error(
|
|
41
|
-
"@opengeni/react: no OpenGeni client/workspace available. Wrap the tree in <OpenGeniProvider> or pass { client, workspaceId } to the hook."
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
client,
|
|
46
|
-
workspaceId,
|
|
47
|
-
workspaceControlEvent: context?.workspaceControlEvent ?? null,
|
|
48
|
-
workspaceControlConnectionState: context?.workspaceControlConnectionState ?? "idle",
|
|
49
|
-
registerSessionReconciler: context?.registerSessionReconciler ?? NOOP_REGISTER_RECONCILER,
|
|
50
|
-
reconcileSession: context?.reconcileSession ?? NOOP_RECONCILE_SESSION
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function useEmbeddedSession(override = {}) {
|
|
54
|
-
return useEmbeddedClientRefinement(
|
|
55
|
-
override,
|
|
56
|
-
[
|
|
57
|
-
"getSession",
|
|
58
|
-
"listEvents",
|
|
59
|
-
"streamEvents",
|
|
60
|
-
"getComposerDraft",
|
|
61
|
-
"saveComposerDraft",
|
|
62
|
-
"sendMessage",
|
|
63
|
-
"steerMessage",
|
|
64
|
-
"getQueue",
|
|
65
|
-
"moveQueueItem",
|
|
66
|
-
"editQueueItem",
|
|
67
|
-
"steerQueueItem",
|
|
68
|
-
"deleteQueueItem",
|
|
69
|
-
"pauseSession",
|
|
70
|
-
"resumeSession",
|
|
71
|
-
"sendApprovalDecision"
|
|
72
|
-
],
|
|
73
|
-
"session hooks"
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
function useEmbeddedSessionRead(override = {}) {
|
|
77
|
-
return useEmbeddedClientRefinement(
|
|
78
|
-
override,
|
|
79
|
-
eventClientMethods(override, ["getSession", "updateSession"]),
|
|
80
|
-
"useSession"
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
function useEmbeddedGoal(override = {}) {
|
|
84
|
-
return useEmbeddedClientRefinement(
|
|
85
|
-
override,
|
|
86
|
-
eventClientMethods(override, ["getGoal", "updateGoal", "deleteGoal"]),
|
|
87
|
-
"useGoal"
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
function useEmbeddedSessionLineage(override = {}) {
|
|
91
|
-
return useEmbeddedClientRefinement(
|
|
92
|
-
override,
|
|
93
|
-
eventClientMethods(override, ["getSessionLineage"]),
|
|
94
|
-
"useSessionLineage"
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
function useEmbeddedFileAttachments(override = {}) {
|
|
98
|
-
return useEmbeddedClientRefinement(override, ["uploadFile"], "useFileAttachments");
|
|
99
|
-
}
|
|
100
|
-
function useEmbeddedHumanInputSession(override = {}) {
|
|
101
|
-
return useEmbeddedClientRefinement(
|
|
102
|
-
override,
|
|
103
|
-
eventClientMethods(override, ["listHumanInputRequests", "submitHumanInputResponse"]),
|
|
104
|
-
"useHumanInputRequests"
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
function useEmbeddedSessionMcpApprovalPolicy(override = {}) {
|
|
108
|
-
return useEmbeddedClientRefinement(
|
|
109
|
-
override,
|
|
110
|
-
eventClientMethods(override, ["getSession", "updateSessionMcpApprovalPolicy"]),
|
|
111
|
-
"useSessionMcpApprovalPolicy"
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
function useOpenGeniClient(override = {}) {
|
|
115
|
-
const context = useContext(OpenGeniContext);
|
|
116
|
-
const client = override.client ?? context?.client;
|
|
117
|
-
if (!client) {
|
|
118
|
-
throw new Error(
|
|
119
|
-
"@opengeni/react: no OpenGeni client available. Wrap the tree in <OpenGeniProvider> or pass { client } to the hook."
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
return client;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
1
|
// src/hooks/internal.ts
|
|
126
2
|
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
127
3
|
function usePolledValue(load, options = {}) {
|
|
@@ -374,19 +250,9 @@ function useDebouncedCallback(callback, delayMs = 150) {
|
|
|
374
250
|
}
|
|
375
251
|
|
|
376
252
|
export {
|
|
377
|
-
OpenGeniContext,
|
|
378
|
-
useOpenGeni,
|
|
379
|
-
useEmbeddedSession,
|
|
380
|
-
useEmbeddedSessionRead,
|
|
381
|
-
useEmbeddedGoal,
|
|
382
|
-
useEmbeddedSessionLineage,
|
|
383
|
-
useEmbeddedFileAttachments,
|
|
384
|
-
useEmbeddedHumanInputSession,
|
|
385
|
-
useEmbeddedSessionMcpApprovalPolicy,
|
|
386
|
-
useOpenGeniClient,
|
|
387
253
|
usePolledValue,
|
|
388
254
|
useMutationRunner,
|
|
389
255
|
useSessionEventTrigger,
|
|
390
256
|
useDebouncedCallback
|
|
391
257
|
};
|
|
392
|
-
//# sourceMappingURL=chunk-
|
|
258
|
+
//# sourceMappingURL=chunk-EB67J347.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/internal.ts"],"sourcesContent":["import type { SessionEvent } from \"@opengeni/sdk\";\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from \"react\";\nimport type { EmbeddedSessionEventClientLike } from \"../client\";\n\nexport type AsyncListState<T> = {\n data: T | null;\n loading: boolean;\n error: Error | null;\n refresh: () => Promise<void>;\n};\n\n/**\n * Shared fetch + optional polling loop for the list/read hooks. Stale\n * responses (superseded by a newer load or an unmount) are dropped.\n */\nexport function usePolledValue<T>(\n load: (signal?: AbortSignal) => Promise<T>,\n options: { pollIntervalMs?: number | undefined; enabled?: boolean | undefined } = {},\n): AsyncListState<T> {\n const enabled = options.enabled ?? true;\n const pollIntervalMs = options.pollIntervalMs;\n const [data, setData] = useState<T | null>(null);\n const [loading, setLoading] = useState(enabled);\n const [error, setError] = useState<Error | null>(null);\n const generation = useRef(0);\n const activeLoadRef = useRef(load);\n useLayoutEffect(() => {\n activeLoadRef.current = load;\n }, [load]);\n const requestAbortRef = useRef<AbortController | null>(null);\n const [stateIdentity, setStateIdentity] = useState<{ load: typeof load }>(() => ({ load }));\n\n // A new loader identity means a new query (different session/workspace/...):\n // drop the previous result instead of showing it as the new query's data.\n useEffect(() => {\n if (stateIdentity.load !== load) {\n setStateIdentity({ load });\n setData(null);\n setError(null);\n }\n }, [load, stateIdentity.load]);\n\n const run = useCallback(async () => {\n // A callback retained by a completed mutation from the previous query must\n // not supersede or settle the current query's request.\n if (activeLoadRef.current !== load) return;\n const ticket = ++generation.current;\n requestAbortRef.current?.abort();\n const requestAbort = new AbortController();\n requestAbortRef.current = requestAbort;\n try {\n const result = await load(requestAbort.signal);\n if (\n ticket === generation.current &&\n activeLoadRef.current === load &&\n !requestAbort.signal.aborted\n ) {\n setData(result);\n setError(null);\n setLoading(false);\n }\n } catch (cause) {\n if (\n ticket === generation.current &&\n activeLoadRef.current === load &&\n !requestAbort.signal.aborted\n ) {\n setError(cause instanceof Error ? cause : new Error(String(cause)));\n setLoading(false);\n }\n } finally {\n if (requestAbortRef.current === requestAbort) {\n requestAbortRef.current = null;\n }\n }\n }, [load]);\n\n useEffect(() => {\n if (!enabled) {\n setLoading(false);\n return;\n }\n setLoading(true);\n void run();\n if (pollIntervalMs === undefined || pollIntervalMs <= 0) {\n return () => {\n generation.current += 1;\n requestAbortRef.current?.abort();\n };\n }\n const timer = setInterval(() => void run(), pollIntervalMs);\n return () => {\n clearInterval(timer);\n generation.current += 1;\n requestAbortRef.current?.abort();\n };\n }, [run, enabled, pollIntervalMs]);\n\n const identityMatches = stateIdentity.load === load;\n return {\n data: identityMatches ? data : null,\n loading: identityMatches ? loading : enabled,\n error: identityMatches ? error : null,\n refresh: run,\n };\n}\n\nexport type MutationState = {\n mutating: boolean;\n mutationError: Error | null;\n clearMutationError: () => void;\n};\n\n/**\n * Shared async mutation runner for the write hooks. `run` resolves with the\n * operation's value, or `null` after capturing the error in `mutationError`\n * (callers then roll back optimistic state).\n */\nexport function useMutationRunner(identity: unknown = undefined): MutationState & {\n run: <T>(operation: () => Promise<T>) => Promise<T | null>;\n} {\n const [mutating, setMutating] = useState(false);\n const [mutationError, setMutationError] = useState<Error | null>(null);\n const [stateIdentity, setStateIdentity] = useState<unknown>(() => identity);\n const inFlight = useRef(0);\n const generation = useRef(0);\n const identityRef = useRef(identity);\n useLayoutEffect(() => {\n if (Object.is(identityRef.current, identity)) return;\n identityRef.current = identity;\n generation.current += 1;\n inFlight.current = 0;\n }, [identity]);\n const mounted = useRef(true);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n useEffect(() => {\n if (!Object.is(stateIdentity, identity)) {\n setStateIdentity(() => identity);\n setMutating(false);\n setMutationError(null);\n }\n }, [identity, stateIdentity]);\n const run = useCallback(\n async <T>(operation: () => Promise<T>): Promise<T | null> => {\n const ownedIdentity = identity;\n const ownedGeneration = generation.current;\n if (!Object.is(identityRef.current, ownedIdentity)) return null;\n inFlight.current += 1;\n if (mounted.current) {\n setMutating(true);\n setMutationError(null);\n }\n try {\n const result = await operation();\n if (\n !mounted.current ||\n generation.current !== ownedGeneration ||\n !Object.is(identityRef.current, ownedIdentity)\n ) {\n return null;\n }\n return result;\n } catch (cause) {\n if (\n mounted.current &&\n generation.current === ownedGeneration &&\n Object.is(identityRef.current, ownedIdentity)\n ) {\n setMutationError(cause instanceof Error ? cause : new Error(String(cause)));\n }\n return null;\n } finally {\n if (\n generation.current === ownedGeneration &&\n Object.is(identityRef.current, ownedIdentity)\n ) {\n inFlight.current -= 1;\n if (mounted.current && inFlight.current === 0) {\n setMutating(false);\n }\n }\n }\n },\n [identity],\n );\n const identityMatches = Object.is(stateIdentity, identity);\n return {\n mutating: identityMatches && mutating,\n mutationError: identityMatches ? mutationError : null,\n clearMutationError: useCallback(() => {\n if (Object.is(identityRef.current, identity)) setMutationError(null);\n }, [identity]),\n run,\n };\n}\n\nexport type SessionEventFeedOptions = {\n /**\n * Share an existing event log (from `useSessionEvents`) instead of opening\n * a second stream. When omitted the hook tails the session's event stream\n * itself, starting at the current `lastSequence`.\n */\n events?: SessionEvent[] | undefined;\n enabled?: boolean | undefined;\n};\n\n/**\n * Invoke `onEvent` for every session event matching `match` — the live-update\n * primitive behind `useTurnQueue` and `useGoal`. Either watches a shared\n * `events` log or tails the stream directly (reconnect handled by the SDK).\n */\nexport function useSessionEventTrigger(\n client: EmbeddedSessionEventClientLike,\n workspaceId: string,\n sessionId: string | null | undefined,\n match: (event: SessionEvent) => boolean,\n onEvent: (event: SessionEvent) => void,\n options: SessionEventFeedOptions = {},\n reconcileBeforeLive?: (() => void | Promise<void>) | undefined,\n): void {\n const enabled = options.enabled ?? true;\n const events = options.events;\n const sharedFeed = events !== undefined;\n const matchRef = useRef(match);\n const onEventRef = useRef(onEvent);\n const reconcileBeforeLiveRef = useRef(reconcileBeforeLive);\n useLayoutEffect(() => {\n matchRef.current = match;\n onEventRef.current = onEvent;\n reconcileBeforeLiveRef.current = reconcileBeforeLive;\n }, [match, onEvent, reconcileBeforeLive]);\n const consumedRef = useRef(0);\n const feedKeyRef = useRef<string | null>(null);\n const sharedFeedHasEventsRef = useRef(false);\n\n // Shared-log mode: scan only the unseen tail on every append.\n useEffect(() => {\n if (!sharedFeed || !enabled || !sessionId) {\n return;\n }\n const feedKey = `${workspaceId}\\u0000${sessionId}`;\n const firstSequence = events[0]?.sequence ?? 0;\n if (feedKeyRef.current !== feedKey) {\n feedKeyRef.current = feedKey;\n sharedFeedHasEventsRef.current = events.length > 0;\n // The caller has already loaded its authoritative initial projection.\n // Seed from the shared log's current tail so mounting a large historical\n // session cannot replay every old event as a new live trigger.\n consumedRef.current = events.at(-1)?.sequence ?? 0;\n return;\n }\n const firstNonEmptyBatch = !sharedFeedHasEventsRef.current && events.length > 0;\n if (firstNonEmptyBatch || firstSequence > consumedRef.current + 1) {\n // The usual shared feed mounts empty, then receives a historical tail.\n // A later discontinuity can likewise replace the retained browser\n // window. In either case, reconcile once from the latest relevant event\n // instead of replaying the whole retained window as live traffic.\n sharedFeedHasEventsRef.current = events.length > 0;\n consumedRef.current = events.at(-1)?.sequence ?? consumedRef.current;\n let latestMatch: SessionEvent | undefined;\n for (let index = events.length - 1; index >= 0; index -= 1) {\n const event = events[index];\n if (event && matchRef.current(event)) {\n latestMatch = event;\n break;\n }\n }\n if (latestMatch) {\n onEventRef.current(latestMatch);\n }\n return;\n }\n sharedFeedHasEventsRef.current ||= events.length > 0;\n for (const event of events) {\n if (event.sequence <= consumedRef.current) {\n continue;\n }\n consumedRef.current = event.sequence;\n if (matchRef.current(event)) {\n onEventRef.current(event);\n }\n }\n }, [sharedFeed, enabled, events, workspaceId, sessionId]);\n\n // Self-stream mode: tail from the session's current lastSequence.\n useEffect(() => {\n if (sharedFeed || !enabled || !sessionId) {\n return;\n }\n const controller = new AbortController();\n void (async () => {\n try {\n const session = await client.getSession(workspaceId, sessionId);\n if (controller.signal.aborted) {\n return;\n }\n const stream = client.streamEvents(workspaceId, sessionId, {\n after: session.lastSequence,\n signal: controller.signal,\n beforeLive: async () => await reconcileBeforeLiveRef.current?.(),\n });\n for await (const event of stream) {\n if (matchRef.current(event)) {\n onEventRef.current(event);\n }\n }\n } catch {\n // Live updates are best-effort: the read hooks still expose refresh()\n // and the initial load already populated state.\n }\n })();\n return () => {\n controller.abort();\n };\n }, [sharedFeed, enabled, client, workspaceId, sessionId]);\n}\n\n/** Debounce rapid event bursts into one trailing call (default 150ms). */\nexport function useDebouncedCallback(callback: () => void, delayMs = 150): () => void {\n const callbackRef = useRef(callback);\n useLayoutEffect(() => {\n callbackRef.current = callback;\n }, [callback]);\n const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n useEffect(() => {\n return () => {\n if (timerRef.current !== null) {\n clearTimeout(timerRef.current);\n }\n };\n }, []);\n return useCallback(() => {\n if (timerRef.current !== null) {\n clearTimeout(timerRef.current);\n }\n timerRef.current = setTimeout(() => {\n timerRef.current = null;\n callbackRef.current();\n }, delayMs);\n }, [delayMs]);\n}\n"],"mappings":";AACA,SAAS,aAAa,WAAW,iBAAiB,QAAQ,gBAAgB;AAcnE,SAAS,eACd,MACA,UAAkF,CAAC,GAChE;AACnB,QAAM,UAAU,QAAQ,WAAW;AACnC,QAAM,iBAAiB,QAAQ;AAC/B,QAAM,CAAC,MAAM,OAAO,IAAI,SAAmB,IAAI;AAC/C,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,OAAO;AAC9C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAuB,IAAI;AACrD,QAAM,aAAa,OAAO,CAAC;AAC3B,QAAM,gBAAgB,OAAO,IAAI;AACjC,kBAAgB,MAAM;AACpB,kBAAc,UAAU;AAAA,EAC1B,GAAG,CAAC,IAAI,CAAC;AACT,QAAM,kBAAkB,OAA+B,IAAI;AAC3D,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAgC,OAAO,EAAE,KAAK,EAAE;AAI1F,YAAU,MAAM;AACd,QAAI,cAAc,SAAS,MAAM;AAC/B,uBAAiB,EAAE,KAAK,CAAC;AACzB,cAAQ,IAAI;AACZ,eAAS,IAAI;AAAA,IACf;AAAA,EACF,GAAG,CAAC,MAAM,cAAc,IAAI,CAAC;AAE7B,QAAM,MAAM,YAAY,YAAY;AAGlC,QAAI,cAAc,YAAY,KAAM;AACpC,UAAM,SAAS,EAAE,WAAW;AAC5B,oBAAgB,SAAS,MAAM;AAC/B,UA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