@slopus/happy-providers 0.0.1 → 0.0.5

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 (152) hide show
  1. package/EXAMPLES.md +42 -74
  2. package/README.md +176 -100
  3. package/dist/core/BaseSession.d.ts +3 -2
  4. package/dist/core/BaseSession.d.ts.map +1 -1
  5. package/dist/core/BaseSession.js.map +1 -1
  6. package/dist/core/EmptyResponseError.d.ts +3 -3
  7. package/dist/core/EmptyResponseError.d.ts.map +1 -1
  8. package/dist/core/EmptyResponseError.js.map +1 -1
  9. package/dist/core/SessionAssistantMessageAccumulator.d.ts +17 -0
  10. package/dist/core/SessionAssistantMessageAccumulator.d.ts.map +1 -0
  11. package/dist/core/SessionAssistantMessageAccumulator.js +154 -0
  12. package/dist/core/SessionAssistantMessageAccumulator.js.map +1 -0
  13. package/dist/core/SessionCompaction.d.ts +4 -11
  14. package/dist/core/SessionCompaction.d.ts.map +1 -1
  15. package/dist/core/SessionContext.d.ts +35 -33
  16. package/dist/core/SessionContext.d.ts.map +1 -1
  17. package/dist/core/SessionEvent.d.ts +23 -8
  18. package/dist/core/SessionEvent.d.ts.map +1 -1
  19. package/dist/core/SessionEvent.js.map +1 -1
  20. package/dist/core/SessionRunRequest.d.ts +2 -5
  21. package/dist/core/SessionRunRequest.d.ts.map +1 -1
  22. package/dist/core/SessionTool.d.ts +1 -3
  23. package/dist/core/SessionTool.d.ts.map +1 -1
  24. package/dist/core/SessionUsage.d.ts +14 -0
  25. package/dist/core/SessionUsage.d.ts.map +1 -0
  26. package/dist/core/{SessionCacheUsage.js → SessionUsage.js} +2 -2
  27. package/dist/core/SessionUsage.js.map +1 -0
  28. package/dist/core/addSessionUsage.d.ts +3 -0
  29. package/dist/core/addSessionUsage.d.ts.map +1 -0
  30. package/dist/core/{addSessionCacheUsage.js → addSessionUsage.js} +3 -3
  31. package/dist/core/addSessionUsage.js.map +1 -0
  32. package/dist/core/emitToolCallResult.d.ts +1 -0
  33. package/dist/core/emitToolCallResult.d.ts.map +1 -1
  34. package/dist/core/emitToolCallResult.js +6 -2
  35. package/dist/core/emitToolCallResult.js.map +1 -1
  36. package/dist/core/toSessionReminderMessage.d.ts.map +1 -1
  37. package/dist/core/toSessionReminderMessage.js +6 -2
  38. package/dist/core/toSessionReminderMessage.js.map +1 -1
  39. package/dist/index.d.ts +6 -5
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +2 -1
  42. package/dist/index.js.map +1 -1
  43. package/dist/protocol/anthropic/collectAnthropicCompaction.d.ts +2 -2
  44. package/dist/protocol/anthropic/collectAnthropicCompaction.d.ts.map +1 -1
  45. package/dist/protocol/anthropic/collectAnthropicCompaction.js +14 -9
  46. package/dist/protocol/anthropic/collectAnthropicCompaction.js.map +1 -1
  47. package/dist/protocol/anthropic/mapAnthropicStream.d.ts.map +1 -1
  48. package/dist/protocol/anthropic/mapAnthropicStream.js +52 -30
  49. package/dist/protocol/anthropic/mapAnthropicStream.js.map +1 -1
  50. package/dist/protocol/anthropic/toAnthropicMessages.d.ts +1 -2
  51. package/dist/protocol/anthropic/toAnthropicMessages.d.ts.map +1 -1
  52. package/dist/protocol/anthropic/toAnthropicMessages.js +46 -108
  53. package/dist/protocol/anthropic/toAnthropicMessages.js.map +1 -1
  54. package/dist/protocol/responses/ResponsesSession.d.ts +3 -2
  55. package/dist/protocol/responses/ResponsesSession.d.ts.map +1 -1
  56. package/dist/protocol/responses/ResponsesSession.js +19 -48
  57. package/dist/protocol/responses/ResponsesSession.js.map +1 -1
  58. package/dist/protocol/responses/mapOpenAIResponseStream.d.ts +9 -6
  59. package/dist/protocol/responses/mapOpenAIResponseStream.d.ts.map +1 -1
  60. package/dist/protocol/responses/mapOpenAIResponseStream.js +191 -59
  61. package/dist/protocol/responses/mapOpenAIResponseStream.js.map +1 -1
  62. package/dist/protocol/responses/toOpenAIInputContent.d.ts +2 -2
  63. package/dist/protocol/responses/toOpenAIInputContent.d.ts.map +1 -1
  64. package/dist/protocol/responses/toOpenAIInputContent.js +4 -4
  65. package/dist/protocol/responses/toOpenAIInputContent.js.map +1 -1
  66. package/dist/protocol/responses/toOpenAIResponseInput.d.ts.map +1 -1
  67. package/dist/protocol/responses/toOpenAIResponseInput.js +74 -68
  68. package/dist/protocol/responses/toOpenAIResponseInput.js.map +1 -1
  69. package/dist/protocol/responses/toSessionUsage.d.ts +4 -0
  70. package/dist/protocol/responses/toSessionUsage.d.ts.map +1 -0
  71. package/dist/protocol/responses/{toSessionCacheUsage.js → toSessionUsage.js} +4 -4
  72. package/dist/protocol/responses/toSessionUsage.js.map +1 -0
  73. package/dist/vendors/bedrock/AnthropicBedrockSession.d.ts +3 -2
  74. package/dist/vendors/bedrock/AnthropicBedrockSession.d.ts.map +1 -1
  75. package/dist/vendors/bedrock/AnthropicBedrockSession.js +34 -73
  76. package/dist/vendors/bedrock/AnthropicBedrockSession.js.map +1 -1
  77. package/dist/vendors/claude/ClaudeSession.d.ts +3 -2
  78. package/dist/vendors/claude/ClaudeSession.d.ts.map +1 -1
  79. package/dist/vendors/claude/ClaudeSession.js +180 -82
  80. package/dist/vendors/claude/ClaudeSession.js.map +1 -1
  81. package/dist/vendors/claude/impl/ClaudeToolBridge.js +1 -7
  82. package/dist/vendors/claude/impl/ClaudeToolBridge.js.map +1 -1
  83. package/dist/vendors/claude/impl/claudeMessageIdentity.d.ts +3 -4
  84. package/dist/vendors/claude/impl/claudeMessageIdentity.d.ts.map +1 -1
  85. package/dist/vendors/claude/impl/claudeMessageIdentity.js +9 -12
  86. package/dist/vendors/claude/impl/claudeMessageIdentity.js.map +1 -1
  87. package/dist/vendors/claude/impl/createClaudeSessionReplay.js +36 -30
  88. package/dist/vendors/claude/impl/createClaudeSessionReplay.js.map +1 -1
  89. package/dist/vendors/claude/impl/toClaudeSdkOptions.d.ts.map +1 -1
  90. package/dist/vendors/claude/impl/toClaudeSdkOptions.js +2 -2
  91. package/dist/vendors/claude/impl/toClaudeSdkOptions.js.map +1 -1
  92. package/dist/vendors/codex/CodexSession.d.ts +3 -2
  93. package/dist/vendors/codex/CodexSession.d.ts.map +1 -1
  94. package/dist/vendors/codex/CodexSession.js +45 -65
  95. package/dist/vendors/codex/CodexSession.js.map +1 -1
  96. package/dist/vendors/codex/CodexToolVendor.d.ts +2 -1
  97. package/dist/vendors/codex/CodexToolVendor.d.ts.map +1 -1
  98. package/dist/vendors/codex/impl/codexCompaction.d.ts +2 -2
  99. package/dist/vendors/codex/impl/codexCompaction.d.ts.map +1 -1
  100. package/dist/vendors/codex/impl/codexCompaction.js +15 -7
  101. package/dist/vendors/codex/impl/codexCompaction.js.map +1 -1
  102. package/dist/vendors/codex/impl/createCodexModelSwitchMessage.d.ts.map +1 -1
  103. package/dist/vendors/codex/impl/createCodexModelSwitchMessage.js +11 -8
  104. package/dist/vendors/codex/impl/createCodexModelSwitchMessage.js.map +1 -1
  105. package/dist/vendors/codex/impl/getCodexContextSuffix.js +13 -15
  106. package/dist/vendors/codex/impl/getCodexContextSuffix.js.map +1 -1
  107. package/dist/vendors/codex/impl/getCodexIncrementalInput.d.ts +2 -2
  108. package/dist/vendors/codex/impl/getCodexIncrementalInput.d.ts.map +1 -1
  109. package/dist/vendors/codex/impl/getCodexIncrementalInput.js +15 -4
  110. package/dist/vendors/codex/impl/getCodexIncrementalInput.js.map +1 -1
  111. package/dist/vendors/codex/impl/getCodexTurnKey.js +1 -1
  112. package/dist/vendors/codex/impl/getCodexTurnKey.js.map +1 -1
  113. package/dist/vendors/codex/impl/settleCodexToolSearch.d.ts +4 -3
  114. package/dist/vendors/codex/impl/settleCodexToolSearch.d.ts.map +1 -1
  115. package/dist/vendors/codex/impl/settleCodexToolSearch.js +14 -2
  116. package/dist/vendors/codex/impl/settleCodexToolSearch.js.map +1 -1
  117. package/dist/vendors/codex/impl/toCodexToolDefinitions.d.ts.map +1 -1
  118. package/dist/vendors/codex/impl/toCodexToolDefinitions.js +6 -27
  119. package/dist/vendors/codex/impl/toCodexToolDefinitions.js.map +1 -1
  120. package/dist/vendors/codex/impl/withCodexSkills.d.ts.map +1 -1
  121. package/dist/vendors/codex/impl/withCodexSkills.js +8 -12
  122. package/dist/vendors/codex/impl/withCodexSkills.js.map +1 -1
  123. package/dist/vendors/codex/tools/tool_search.d.ts +9 -5
  124. package/dist/vendors/codex/tools/tool_search.d.ts.map +1 -1
  125. package/dist/vendors/codex/tools/tool_search.js +8 -10
  126. package/dist/vendors/codex/tools/tool_search.js.map +1 -1
  127. package/dist/vendors/grok/GrokSession.d.ts +3 -2
  128. package/dist/vendors/grok/GrokSession.d.ts.map +1 -1
  129. package/dist/vendors/grok/GrokSession.js +26 -48
  130. package/dist/vendors/grok/GrokSession.js.map +1 -1
  131. package/dist/vendors/grok/impl/grokMessages.js +11 -5
  132. package/dist/vendors/grok/impl/grokMessages.js.map +1 -1
  133. package/dist/vendors/grok/impl/stripGrokContextImages.d.ts.map +1 -1
  134. package/dist/vendors/grok/impl/stripGrokContextImages.js +3 -3
  135. package/dist/vendors/grok/impl/stripGrokContextImages.js.map +1 -1
  136. package/dist/vendors/grok/impl/toGrokInputContent.d.ts +2 -2
  137. package/dist/vendors/grok/impl/toGrokInputContent.d.ts.map +1 -1
  138. package/dist/vendors/grok/impl/toGrokInputContent.js +4 -4
  139. package/dist/vendors/grok/impl/toGrokInputContent.js.map +1 -1
  140. package/dist/vendors/grok/impl/toGrokResponseInput.d.ts.map +1 -1
  141. package/dist/vendors/grok/impl/toGrokResponseInput.js +78 -70
  142. package/dist/vendors/grok/impl/toGrokResponseInput.js.map +1 -1
  143. package/package.json +2 -1
  144. package/dist/core/SessionCacheUsage.d.ts +0 -9
  145. package/dist/core/SessionCacheUsage.d.ts.map +0 -1
  146. package/dist/core/SessionCacheUsage.js.map +0 -1
  147. package/dist/core/addSessionCacheUsage.d.ts +0 -3
  148. package/dist/core/addSessionCacheUsage.d.ts.map +0 -1
  149. package/dist/core/addSessionCacheUsage.js.map +0 -1
  150. package/dist/protocol/responses/toSessionCacheUsage.d.ts +0 -4
  151. package/dist/protocol/responses/toSessionCacheUsage.d.ts.map +0 -1
  152. package/dist/protocol/responses/toSessionCacheUsage.js.map +0 -1
package/README.md CHANGED
@@ -60,7 +60,7 @@ filesystem, and networking APIs, so it won't run in browsers, bundlers targeting
60
60
  runtimes, or React Native. The package manifest sets `browser` to `false` on purpose.
61
61
 
62
62
  ```sh
63
- pnpm add @slopus/happy-providers
63
+ pnpm add @slopus/happy-providers @steve.kite/stdlib
64
64
  ```
65
65
 
66
66
  If your application defines tools, add TypeBox as a direct dependency too — tool parameters are
@@ -81,9 +81,13 @@ warm, but you own the transcript.
81
81
  import {
82
82
  CodexProvider,
83
83
  CodexSessionCredential,
84
+ SessionAssistantMessageAccumulator,
85
+ type SessionAssistantMessage,
84
86
  type SessionMessage,
85
87
  } from "@slopus/happy-providers";
88
+ import { createRootContext, withLifetime } from "@steve.kite/stdlib";
86
89
 
90
+ const ctx = createRootContext().named("provider-session");
87
91
  const credential = await CodexSessionCredential.tryLoad();
88
92
  if (credential === null) {
89
93
  throw new Error("Sign in with Codex before starting a session.");
@@ -94,25 +98,30 @@ const provider = new CodexProvider({
94
98
  model: "gpt-5.6-sol",
95
99
  transport: "auto",
96
100
  });
101
+ const instructions = "You are a concise coding assistant.";
97
102
  const session = await provider.session("conversation-1", {
98
- instructions: "You are a concise coding assistant.",
103
+ instructions,
99
104
  tools: [],
100
105
  });
101
106
 
102
107
  const messages: SessionMessage[] = [];
103
108
 
104
109
  async function ask(content: string): Promise<string> {
105
- messages.push({ role: "user", content });
110
+ messages.push({ role: "user", content: [{ type: "text", text: content }] });
106
111
 
107
112
  let response = "";
108
- for await (const event of session.run({ context: { messages } })) {
113
+ const assistant = new SessionAssistantMessageAccumulator();
114
+ for await (const event of session.run(ctx, { context: { instructions, messages } })) {
115
+ assistant.add(event);
109
116
  if (event.type === "text_delta") response += event.delta;
110
117
  if (event.type === "done" && event.state === "error") {
111
118
  throw new Error(event.message);
112
119
  }
113
120
  }
114
121
 
115
- messages.push({ role: "assistant", content: response });
122
+ const message = assistant.message();
123
+ if (message === undefined) throw new Error("The provider returned no assistant message.");
124
+ messages.push(message);
116
125
  return response;
117
126
  }
118
127
 
@@ -124,8 +133,10 @@ try {
124
133
  }
125
134
  ```
126
135
 
127
- A production caller should persist more than plain text — reasoning, response items, tool calls,
128
- tool results, and their opaque `vendor` fields all belong in your durable transcript.
136
+ A production caller reconstructs and persists the assistant message from the ordered block events.
137
+ `SessionAssistantMessageAccumulator` does that directly, including retry rewinds. Its result
138
+ contains the text, reasoning, tool calls, provider-owned tool results, and opaque replay metadata
139
+ needed for the next turn.
129
140
  [EXAMPLES.md](EXAMPLES.md) walks through a complete event collector and a tool-call continuation.
130
141
 
131
142
  ## Providers and credentials
@@ -175,15 +186,15 @@ You supply the instructions and tools yourself. The vendor prompts and tool desc
175
186
  find reproduced in this source tree are reference data for protocol tests, and they are
176
187
  intentionally not exported.
177
188
 
178
- Each `run()` then takes the complete transcript plus anything you want to vary per turn: model,
179
- reasoning effort, priority service tier, structured output schema, and an abort signal:
189
+ Each `run()` takes a stdlib context first, then the complete transcript plus anything you want to
190
+ vary per turn: model, reasoning effort, priority service tier, and structured output schema.
191
+ Cancellation travels through `ctx.lifetime`; use `withLifetime` to attach an operation signal:
180
192
 
181
193
  ```ts
182
- const stream = session.run({
183
- context: { messages },
194
+ const stream = session.run(withLifetime(ctx, abortController.signal), {
195
+ context: { instructions, messages },
184
196
  model: "gpt-5.6-sol",
185
197
  effort: "high",
186
- abort: abortController.signal,
187
198
  });
188
199
  ```
189
200
 
@@ -216,22 +227,23 @@ continuing the same conversation; mint a new one for a new conversation or an in
216
227
  ## Messages and events
217
228
 
218
229
  `SessionMessage` covers user, assistant, tool-result, system-notice, agent, and compaction
219
- messages. Multimodal content uses ordered text/image parts in `input`.
230
+ messages. User, system, assistant, and tool-result content is always an ordered block array.
220
231
 
221
232
  Some fields exist purely so the provider can continue a conversation faithfully, and their
222
233
  contents are intentionally opaque. Whenever these appear, store them byte-for-byte and send them
223
234
  back unchanged:
224
235
 
225
- - assistant `encryptedReasoning` and `responseItems`;
226
- - tool-call and tool-result `vendor` metadata;
227
- - signed reasoning blocks;
236
+ - reasoning block `reasoning` payloads;
237
+ - tool-call and tool-result block `vendor` metadata;
228
238
  - compaction `encryptedContent` and `vendor` metadata.
229
239
 
230
240
  `SessionStream` is an `AsyncIterable<SessionEvent>`. You'll see text and reasoning deltas,
231
241
  tool-call boundaries, provider-owned tool results, token usage, retry notices, and block rollback
232
- boundaries. Every started stream ends with exactly one `done` event. When collecting a stream, use
233
- `committedSessionEvents()` so output invalidated by `block_reset` is discarded correctly — more on
234
- that in the [retries section](#retries-happen-inside-the-session) below.
242
+ boundaries. Content-block start order is the exact order of `SessionAssistantMessage.content`;
243
+ indexes are neither exposed nor needed. Every started stream ends with exactly one `done` event.
244
+ Use `SessionAssistantMessageAccumulator` to build the message while streaming, or
245
+ `assistantMessageFromEvents()` after collecting a run. Both discard output invalidated by
246
+ `block_reset` correctly.
235
247
 
236
248
  ## Tools: you run them, not the library
237
249
 
@@ -276,10 +288,9 @@ context using its native compaction protocol. Compaction is explicit — the lib
276
288
  behind your back:
277
289
 
278
290
  ```ts
279
- const compacted = await session.compact({
280
- context: { messages },
281
- inputTokens,
282
- signal: abortController.signal,
291
+ const compacted = await session.compact(withLifetime(ctx, abortController.signal), {
292
+ context: { instructions, messages },
293
+ instructions: "Preserve decisions, unfinished work, and exact identifiers.",
283
294
  });
284
295
 
285
296
  if (compacted.status === "completed") {
@@ -290,6 +301,11 @@ if (compacted.status === "completed") {
290
301
  On success, adopt and persist the complete returned `context` as your new transcript. On
291
302
  cancellation or failure, keep the original — nothing was changed out from under you.
292
303
 
304
+ The `context` is the complete caller-selected input to compact: root instructions and messages
305
+ travel together exactly as they do for inference. The separate `instructions` field tells the
306
+ provider what the compacted replacement should retain. Compaction does not accept a caller token
307
+ count; providers report their own usage.
308
+
293
309
  ## The most important part: sessions are stateful and managed
294
310
 
295
311
  Everything above is mechanics. This is the mental model.
@@ -346,11 +362,11 @@ next operation.
346
362
 
347
363
  ```ts
348
364
  // Correct: turns on one session are sequential.
349
- for await (const event of session.run({ context: { messages } })) {
365
+ for await (const event of session.run(ctx, { context: { instructions, messages } })) {
350
366
  // Consume every event.
351
367
  }
352
368
 
353
- const compacted = await session.compact({ context: { messages } });
369
+ const compacted = await session.compact(ctx, { context: { instructions, messages } });
354
370
  ```
355
371
 
356
372
  Independent sessions run concurrently just fine — use one session per conversation or branch:
@@ -360,12 +376,16 @@ const first = await provider.session("conversation-1", firstOptions);
360
376
  const second = await provider.session("conversation-2", secondOptions);
361
377
 
362
378
  const runFirst = async () => {
363
- for await (const event of first.run({ context: { messages: firstMessages } })) {
379
+ for await (const event of first.run(ctx, {
380
+ context: { instructions: firstInstructions, messages: firstMessages },
381
+ })) {
364
382
  // Consume the first conversation's events.
365
383
  }
366
384
  };
367
385
  const runSecond = async () => {
368
- for await (const event of second.run({ context: { messages: secondMessages } })) {
386
+ for await (const event of second.run(ctx, {
387
+ context: { instructions: secondInstructions, messages: secondMessages },
388
+ })) {
369
389
  // Consume the second conversation's events.
370
390
  }
371
391
  };
@@ -384,7 +404,7 @@ the next inference begins.
384
404
  or by creating two session objects with the same ID.
385
405
 
386
406
  To branch today, copy your transcript and open a new session with its own ID. Include all opaque
387
- reasoning, response items, tool metadata, and compaction messages in the copy:
407
+ reasoning, tool metadata, and compaction messages in the copy:
388
408
 
389
409
  ```ts
390
410
  const branchMessages = structuredClone(messages);
@@ -394,8 +414,8 @@ const branch = await provider.session("conversation-1-branch-1", {
394
414
  modelConfigurations,
395
415
  });
396
416
 
397
- for await (const event of branch.run({
398
- context: { messages: branchMessages },
417
+ for await (const event of branch.run(ctx, {
418
+ context: { instructions, messages: branchMessages },
399
419
  model,
400
420
  effort,
401
421
  })) {
@@ -450,7 +470,7 @@ out the rewound output:
450
470
  import { committedSessionEvents, type SessionEvent } from "@slopus/happy-providers";
451
471
 
452
472
  const streamed: SessionEvent[] = [];
453
- for await (const event of session.run({ context: { messages } })) {
473
+ for await (const event of session.run(ctx, { context: { instructions, messages } })) {
454
474
  streamed.push(event);
455
475
  }
456
476
 
@@ -597,8 +617,8 @@ What `provider.session(id, options)` returns:
597
617
  abstract class BaseSession {
598
618
  readonly id: string;
599
619
 
600
- abstract run(request: SessionRunRequest): SessionStream;
601
- abstract compact(options?: SessionCompactionOptions): Promise<SessionCompaction>;
620
+ abstract run(ctx: Context, request: SessionRunRequest): SessionStream;
621
+ abstract compact(ctx: Context, options: SessionCompactionOptions): Promise<SessionCompaction>;
602
622
  abstract destroy(): void | Promise<void>;
603
623
  }
604
624
  ```
@@ -635,11 +655,8 @@ What one `run()` takes:
635
655
 
636
656
  ```ts
637
657
  interface SessionRunRequest {
638
- /** Complete rebuilt conversation history for this inference turn. */
639
- context: {
640
- readonly messages: readonly SessionMessage[];
641
- };
642
- abort?: AbortSignal;
658
+ /** Complete rebuilt conversation context for this inference turn. */
659
+ context: SessionContext;
643
660
  model?: string;
644
661
  effort?: SessionReasoningEffort;
645
662
  serviceTier?: SessionServiceTier;
@@ -673,58 +690,54 @@ type SessionMessage =
673
690
  | SessionCompactionMessage;
674
691
  ```
675
692
 
676
- A user turn. `input`, when present, replaces `content` with ordered multimodal parts:
693
+ A user turn contains ordered multimodal blocks:
677
694
 
678
695
  ```ts
679
696
  interface SessionUserMessage {
680
697
  readonly role: "user";
681
- readonly content: string;
682
- /** Background context that does not establish a provider turn boundary. */
683
- readonly contextOnly?: true;
684
- readonly input?: SessionInputContent;
698
+ readonly content: readonly SessionInputBlock[];
685
699
  }
686
700
 
687
- type SessionInputContent = readonly (SessionTextContent | SessionImageContent)[];
701
+ type SessionInputBlock = SessionTextBlock | SessionImageBlock;
688
702
 
689
- interface SessionTextContent {
703
+ interface SessionTextBlock {
690
704
  readonly type: "text";
691
705
  readonly text: string;
692
706
  }
693
707
 
694
- interface SessionImageContent {
708
+ interface SessionImageBlock {
695
709
  readonly type: "image";
696
710
  readonly data: string;
697
711
  readonly mimeType: string;
698
712
  }
699
713
  ```
700
714
 
701
- A model turn — the shape with the most to preserve. Anthropic signs the text of its thinking
702
- blocks, so a signature replayed beside different text is rejected: keep each reasoning block and
703
- its signature together, untouched. `encryptedReasoning` and `responseItems` are opaque; store
704
- them byte-for-byte:
715
+ A model turn is one ordered block array. Do not flatten or reorder it: provider replay state lives
716
+ on the block it belongs to, so text, reasoning, client tool calls, and provider-owned tool results
717
+ retain their original sequence:
705
718
 
706
719
  ```ts
707
720
  interface SessionAssistantMessage {
708
721
  readonly role: "assistant";
709
- readonly content: string;
710
- /** Opaque encrypted reasoning from a Responses-compatible backend. */
711
- readonly encryptedReasoning?: string;
712
- /** Ordered reasoning blocks retained as caller-owned history. */
713
- readonly reasoning?: readonly SessionReasoning[];
714
- /** Completed client tool calls emitted alongside this message. */
715
- readonly toolCalls?: readonly SessionToolCall[];
716
- /** Ordered, opaque Responses output items, replayed without flattening or reordering. */
717
- readonly responseItems?: readonly string[];
722
+ readonly content: readonly SessionAssistantBlock[];
718
723
  }
719
724
 
720
- interface SessionReasoning {
721
- readonly text: string;
722
- readonly signature?: string;
723
- /** Reasoning the vendor withheld, where the signature is the whole payload. */
724
- readonly redacted?: boolean;
725
+ type SessionAssistantBlock =
726
+ | SessionTextBlock
727
+ | SessionReasoningBlock
728
+ | SessionToolCallBlock
729
+ | SessionToolResultBlock;
730
+
731
+ interface SessionReasoningBlock {
732
+ readonly type: "reasoning";
733
+ /** Human-readable reasoning, when exposed. */
734
+ readonly text?: string;
735
+ /** Opaque signed or encrypted replay state, when required. */
736
+ readonly reasoning?: string;
725
737
  }
726
738
 
727
- interface SessionToolCall {
739
+ interface SessionToolCallBlock {
740
+ readonly type: "tool_call";
728
741
  readonly callId: string;
729
742
  readonly name: string;
730
743
  readonly namespace?: string;
@@ -743,11 +756,9 @@ Your answer to a tool call, tied back by `callId`:
743
756
  interface SessionToolResultMessage {
744
757
  readonly role: "tool";
745
758
  readonly callId: string;
746
- readonly content: string;
759
+ readonly content: readonly SessionOutputBlock[];
747
760
  /** Whether the caller reported that the tool invocation failed. */
748
761
  readonly isError?: boolean;
749
- /** Ordered multimodal content. When present, providers use this instead of content. */
750
- readonly input?: SessionInputContent;
751
762
  /** The opaque metadata that arrived with the call, echoed back. */
752
763
  readonly vendor?: any;
753
764
  }
@@ -760,7 +771,7 @@ edit it):
760
771
  ```ts
761
772
  interface SessionSystemMessage {
762
773
  readonly role: "system";
763
- readonly content: string | readonly string[];
774
+ readonly content: readonly SessionTextBlock[];
764
775
  }
765
776
 
766
777
  interface SessionAgentMessage {
@@ -784,6 +795,11 @@ interface SessionCompactionMessage {
784
795
  }
785
796
  ```
786
797
 
798
+ `SessionAgentMessage` is specifically Codex cross-agent replay state. It represents encrypted
799
+ messages exchanged by Codex collaborators and preserves their author, recipient, display header,
800
+ and turn boundary. Persist and replay values emitted by Codex; do not construct it as a generic
801
+ application message. Non-Codex providers ignore it.
802
+
787
803
  ### `SessionTool`
788
804
 
789
805
  A tool definition, as covered in the [Tools section](#tools-you-run-them-not-the-library):
@@ -802,9 +818,7 @@ interface SessionTool {
802
818
  readonly description?: string;
803
819
  readonly parameters?: TSchema; // a TypeBox schema
804
820
  /** Provider-neutral request to expose this tool through native tool discovery. */
805
- readonly deferLoading?: boolean;
806
- /** Opaque provider metadata persisted with this tool definition. */
807
- readonly vendor?: any;
821
+ readonly defer?: boolean;
808
822
  /** OpenAI-style Lark grammar; ignored by providers that do not support grammar tools. */
809
823
  readonly grammar?: SessionToolLarkGrammar;
810
824
  }
@@ -821,35 +835,62 @@ interface SessionToolLarkGrammar {
821
835
 
822
836
  ```ts
823
837
  type SessionEvent =
824
- // Blocks bracket tentative output so provider-owned retries can rewind it.
838
+ // Attempt blocks bracket tentative output so provider-owned retries can rewind it.
825
839
  | { type: "block_start" }
826
840
  | { type: "block_stop" }
827
841
  | { type: "block_reset" }
828
- // Content.
842
+ // Text and reasoning blocks are sequential. Start order is message-content order.
843
+ | { type: "text_start" }
829
844
  | { type: "text_delta"; delta: string }
845
+ | { type: "text_end" }
846
+ | { type: "reasoning_start" }
830
847
  | { type: "reasoning_delta"; delta: string }
831
- | { type: "encrypted_reasoning"; content: string }
832
- | { type: "response_items"; items: readonly string[] }
848
+ | { type: "reasoning_end"; reasoning?: string }
833
849
  // Tool calls. `server: true` marks a provider-owned call the client never executes.
834
- | { type: "toolcall_start"; callId: string; name: string; namespace?: string; server?: true; vendor?: any }
850
+ | {
851
+ type: "toolcall_start";
852
+ callId: string;
853
+ name: string;
854
+ namespace?: string;
855
+ server?: true;
856
+ vendor?: any;
857
+ }
835
858
  | { type: "toolcall_delta"; callId: string; delta: string }
836
859
  | { type: "toolcall_end"; callId: string; arguments: string; incomplete?: boolean }
837
860
  // Server-tool results settle inside the same response, streamed beside the call.
838
- | { type: "toolcall_result_start"; callId: string }
861
+ | { type: "toolcall_result_start"; callId: string; vendor?: any }
839
862
  | { type: "toolcall_result_delta"; callId: string; delta: string }
840
- | { type: "toolcall_result_end"; callId: string; result: string; incomplete?: boolean }
863
+ | {
864
+ type: "toolcall_result_end";
865
+ callId: string;
866
+ content: readonly SessionOutputBlock[];
867
+ isError?: boolean;
868
+ incomplete?: boolean;
869
+ }
841
870
  // Progress.
842
871
  | { type: "retrying"; attempt: number; reason: string }
843
- | { type: "token_usage"; usage: SessionCacheUsage }
872
+ | { type: "token_usage"; usage: SessionUsage }
844
873
  // Exactly one done event ends every started stream.
845
874
  | { type: "done"; state: "cancelled" }
846
- | { type: "done"; state: "normal"; endTurn?: boolean }
847
- | { type: "done"; state: "tool_call" }
848
- | { type: "done"; state: "length" }
849
- | { type: "done"; state: "error"; kind: SessionErrorKind; message: string; providerError?: SessionProviderError };
875
+ | { type: "done"; state: "normal"; tokens: SessionTokens; endTurn?: boolean }
876
+ | { type: "done"; state: "tool_call"; tokens: SessionTokens }
877
+ | { type: "done"; state: "length"; tokens: SessionTokens }
878
+ | {
879
+ type: "done";
880
+ state: "error";
881
+ kind: SessionErrorKind;
882
+ message: string;
883
+ providerError?: SessionProviderError;
884
+ };
850
885
 
851
886
  type SessionErrorKind = "internal_error" | "context_overflow" | "billing_error" | "unknown";
852
887
 
888
+ interface SessionTokens {
889
+ /** Full input context size, including cached input. */
890
+ readonly input: number;
891
+ readonly output: number;
892
+ }
893
+
853
894
  type SessionStream = AsyncIterable<SessionEvent>;
854
895
  ```
855
896
 
@@ -859,15 +900,37 @@ response hit a length limit, `"cancelled"` means the run was aborted, and `"erro
859
900
  Ordinary tools never emit `toolcall_result_*` events — you answer those with a `role: "tool"`
860
901
  message; only server tools stream their results here.
861
902
 
903
+ No content index is exposed. A `text_start`, `reasoning_start`, `toolcall_start`, or
904
+ `toolcall_result_start` appends that block to the assistant message. Text and reasoning are
905
+ sequential; parallel tool calls are updated by `callId`. The corresponding end event closes the
906
+ block and supplies final opaque state or normalized content when needed.
907
+
908
+ The exported accumulator implements those rules and the outer retry rollback boundaries:
909
+
910
+ ```ts
911
+ const assistant = new SessionAssistantMessageAccumulator();
912
+
913
+ for await (const event of session.run(ctx, { context: { instructions, messages } })) {
914
+ assistant.add(event);
915
+ }
916
+
917
+ const message = assistant.message();
918
+ if (message !== undefined) messages.push(message);
919
+ ```
920
+
921
+ If you already collected the complete run, `assistantMessageFromEvents(events)` returns the same
922
+ result. There is no terminal `assistant_message` event and no provider-specific `response_items`
923
+ event; the ordered lifecycle is the message.
924
+
862
925
  The helpers `isSessionDoneEvent()` and `isSessionErrorDone()` narrow events, and
863
926
  `committedSessionEvents()` filters a collected stream down to what survived block rewinds.
864
927
 
865
- ### `SessionCacheUsage`
928
+ ### `SessionUsage`
866
929
 
867
930
  Token accounting for one attempt:
868
931
 
869
932
  ```ts
870
- interface SessionCacheUsage {
933
+ interface SessionUsage {
871
934
  readonly input: number;
872
935
  readonly output: number;
873
936
  readonly cacheRead: number;
@@ -876,12 +939,31 @@ interface SessionCacheUsage {
876
939
  }
877
940
  ```
878
941
 
879
- Cache reads are the payoff of prompt-cache continuity — a healthy continuation shows most of its
880
- input arriving as `cacheRead`.
942
+ The fields are normalized the same way for every provider: `input` is the complete input context,
943
+ including cached tokens; `cacheRead` and `cacheWrite` describe subsets of that input; and
944
+ `totalTokens` is `input + output`. Cache reads are the payoff of prompt-cache continuity — a
945
+ healthy continuation shows much of its input also reported as `cacheRead`.
946
+
947
+ **Getting the last turn's context size.** The size of the context the model actually saw on a
948
+ turn is `input`; cache columns are already included:
949
+
950
+ ```ts
951
+ let lastUsage: SessionUsage | undefined;
952
+ for await (const event of session.run(ctx, { context: { instructions, messages } })) {
953
+ if (event.type === "token_usage") lastUsage = event.usage;
954
+ }
955
+
956
+ const contextSize = lastUsage?.input ?? 0;
957
+ ```
958
+
959
+ Keep the _last_ `token_usage` event of the run — a retried run reports usage per attempt, and the
960
+ final event describes the attempt that produced the committed response. This is the right value
961
+ for a context-window meter in your UI. Compaction itself does not accept a caller-supplied token
962
+ count; its returned usage comes from the provider.
881
963
 
882
964
  ### `SessionCompaction`
883
965
 
884
- What `compact(options)` takes and resolves to:
966
+ What `compact(ctx, options)` takes and resolves to:
885
967
 
886
968
  ```ts
887
969
  interface SessionCompactionOptions {
@@ -889,13 +971,8 @@ interface SessionCompactionOptions {
889
971
  readonly model?: string;
890
972
  /** Provider-native instructions describing what the compaction should retain. */
891
973
  readonly instructions?: string;
892
- /** Rebuilt conversation prefix selected by the caller for this compaction. */
893
- readonly context?: {
894
- readonly messages: readonly SessionMessage[];
895
- };
896
- /** Best available count of input tokens in the selected context. */
897
- readonly inputTokens?: number;
898
- readonly signal?: AbortSignal;
974
+ /** Complete context to compact, including its root instructions and messages. */
975
+ readonly context: SessionContext;
899
976
  }
900
977
 
901
978
  type SessionCompaction =
@@ -913,7 +990,7 @@ interface CompletedSessionCompaction {
913
990
  readonly encryptedReasoning?: string;
914
991
  /** Original messages intentionally retained alongside the summary. */
915
992
  readonly preservedMessages: readonly SessionMessage[];
916
- readonly usage: SessionCacheUsage;
993
+ readonly usage: SessionUsage;
917
994
  /** Complete replacement context — adopt this as your new transcript. */
918
995
  readonly context: SessionContext;
919
996
  }
@@ -928,8 +1005,6 @@ interface FailedSessionCompaction {
928
1005
  readonly status: "failed";
929
1006
  readonly kind: "inference_error" | "invalid_summary" | "tool_call";
930
1007
  readonly message: string;
931
- /** Original context left active because compaction did not complete. */
932
- readonly context: SessionContext;
933
1008
  }
934
1009
 
935
1010
  interface SessionContext {
@@ -938,7 +1013,8 @@ interface SessionContext {
938
1013
  }
939
1014
  ```
940
1015
 
941
- On `"cancelled"` and `"failed"` nothing changed — the original context is still active.
1016
+ On `"cancelled"` and `"failed"` nothing changed. Cancellation echoes the selected context;
1017
+ failure only describes the error because the caller already owns the unchanged input context.
942
1018
 
943
1019
  ### `SessionProviderError`
944
1020
 
@@ -2,11 +2,12 @@ import type { SessionContext } from "../core/SessionContext.js";
2
2
  import type { SessionCompaction, SessionCompactionOptions } from "../core/SessionCompaction.js";
3
3
  import type { SessionEvent, SessionStream } from "../core/SessionEvent.js";
4
4
  import type { SessionRunRequest } from "../core/SessionRunRequest.js";
5
+ import type { Context } from "@steve.kite/stdlib";
5
6
  export declare abstract class BaseSession {
6
7
  readonly id: string;
7
8
  protected constructor(id: string);
8
- abstract run(request: SessionRunRequest): SessionStream;
9
- abstract compact(options?: SessionCompactionOptions): Promise<SessionCompaction>;
9
+ abstract run(ctx: Context, request: SessionRunRequest): SessionStream;
10
+ abstract compact(ctx: Context, options: SessionCompactionOptions): Promise<SessionCompaction>;
10
11
  abstract destroy(): void | Promise<void>;
11
12
  }
12
13
  export type { SessionCompaction, SessionContext, SessionEvent, SessionRunRequest, SessionStream };
@@ -1 +1 @@
1
- {"version":3,"file":"BaseSession.d.ts","sourceRoot":"","sources":["../../sources/core/BaseSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAC/F,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE,8BAAsB,WAAW;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,SAAS,aAAa,EAAE,EAAE,MAAM,EAE/B;IAED,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,iBAAiB,GAAG,aAAa,CAAC;IAExD,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAEjF,QAAQ,CAAC,OAAO,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5C;AAED,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,CAAC"}
1
+ {"version":3,"file":"BaseSession.d.ts","sourceRoot":"","sources":["../../sources/core/BaseSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAC/F,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,8BAAsB,WAAW;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,SAAS,aAAa,EAAE,EAAE,MAAM,EAE/B;IAED,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,iBAAiB,GAAG,aAAa,CAAC;IAEtE,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE9F,QAAQ,CAAC,OAAO,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5C;AAED,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"BaseSession.js","sourceRoot":"","sources":["../../sources/core/BaseSession.ts"],"names":[],"mappings":"AAKA,MAAM,OAAgB,WAAW;IACpB,EAAE,CAAS;IACpB,YAAsB,EAAU;QAC5B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACjB,CAAC;CAOJ"}
1
+ {"version":3,"file":"BaseSession.js","sourceRoot":"","sources":["../../sources/core/BaseSession.ts"],"names":[],"mappings":"AAMA,MAAM,OAAgB,WAAW;IACpB,EAAE,CAAS;IACpB,YAAsB,EAAU;QAC5B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACjB,CAAC;CAOJ"}
@@ -1,4 +1,4 @@
1
- import type { SessionCacheUsage } from "../core/SessionCacheUsage.js";
1
+ import type { SessionUsage } from "../core/SessionUsage.js";
2
2
  import type { SessionEvent } from "../core/SessionEvent.js";
3
3
  type ErrorDoneEvent = Extract<SessionEvent, {
4
4
  type: "done";
@@ -7,8 +7,8 @@ type ErrorDoneEvent = Extract<SessionEvent, {
7
7
  export declare class EmptyResponseError extends Error {
8
8
  readonly code = "empty_response";
9
9
  readonly errorType = "empty_response";
10
- readonly usage: SessionCacheUsage | undefined;
11
- constructor(provider: string, usage?: SessionCacheUsage);
10
+ readonly usage: SessionUsage | undefined;
11
+ constructor(provider: string, usage?: SessionUsage);
12
12
  }
13
13
  export declare function isEmptyResponseError(error: unknown): error is EmptyResponseError;
14
14
  export declare function emptyResponseDoneEvent(error: EmptyResponseError, attempts: number): ErrorDoneEvent;
@@ -1 +1 @@
1
- {"version":3,"file":"EmptyResponseError.d.ts","sourceRoot":"","sources":["../../sources/core/EmptyResponseError.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,KAAK,cAAc,GAAG,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAE9E,qBAAa,kBAAmB,SAAQ,KAAK;IACzC,QAAQ,CAAC,IAAI,oBAAoB;IACjC,QAAQ,CAAC,SAAS,oBAAoB;IACtC,QAAQ,CAAC,KAAK,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAE9C,YAAY,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,iBAAiB,EAItD;CACJ;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB,CAEhF;AAED,wBAAgB,sBAAsB,CAClC,KAAK,EAAE,kBAAkB,EACzB,QAAQ,EAAE,MAAM,GACjB,cAAc,CAehB"}
1
+ {"version":3,"file":"EmptyResponseError.d.ts","sourceRoot":"","sources":["../../sources/core/EmptyResponseError.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,KAAK,cAAc,GAAG,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAE9E,qBAAa,kBAAmB,SAAQ,KAAK;IACzC,QAAQ,CAAC,IAAI,oBAAoB;IACjC,QAAQ,CAAC,SAAS,oBAAoB;IACtC,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,SAAS,CAAC;IAEzC,YAAY,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,YAAY,EAIjD;CACJ;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB,CAEhF;AAED,wBAAgB,sBAAsB,CAClC,KAAK,EAAE,kBAAkB,EACzB,QAAQ,EAAE,MAAM,GACjB,cAAc,CAehB"}
@@ -1 +1 @@
1
- {"version":3,"file":"EmptyResponseError.js","sourceRoot":"","sources":["../../sources/core/EmptyResponseError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,2CAA2C,CAAC;AAM5F,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAChC,IAAI,GAAG,gBAAgB,CAAC;IACxB,SAAS,GAAG,gBAAgB,CAAC;IAC7B,KAAK,CAAgC;IAE9C,YAAY,QAAgB,EAAE,KAAyB;QACnD,KAAK,CAAC,GAAG,QAAQ,+CAA+C,CAAC,CAAC;QAClE,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAc;IAC/C,OAAO,KAAK,YAAY,kBAAkB,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,sBAAsB,CAClC,KAAyB,EACzB,QAAgB;IAEhB,MAAM,WAAW,GAAG,+BAA+B,CAAC,KAAK,EAAE;QACvD,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC;QAC/B,eAAe,EAAE,KAAK,CAAC,OAAO;KACjC,CAAC,CAAC;IACH,OAAO;QACH,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,OAAO;QACd,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,aAAa,EAAE;YACX,IAAI,EAAE,gBAAgB;YACtB,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;SACxD;KACJ,CAAC;AACN,CAAC"}
1
+ {"version":3,"file":"EmptyResponseError.js","sourceRoot":"","sources":["../../sources/core/EmptyResponseError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,2CAA2C,CAAC;AAM5F,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAChC,IAAI,GAAG,gBAAgB,CAAC;IACxB,SAAS,GAAG,gBAAgB,CAAC;IAC7B,KAAK,CAA2B;IAEzC,YAAY,QAAgB,EAAE,KAAoB;QAC9C,KAAK,CAAC,GAAG,QAAQ,+CAA+C,CAAC,CAAC;QAClE,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAc;IAC/C,OAAO,KAAK,YAAY,kBAAkB,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,sBAAsB,CAClC,KAAyB,EACzB,QAAgB;IAEhB,MAAM,WAAW,GAAG,+BAA+B,CAAC,KAAK,EAAE;QACvD,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC;QAC/B,eAAe,EAAE,KAAK,CAAC,OAAO;KACjC,CAAC,CAAC;IACH,OAAO;QACH,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,OAAO;QACd,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,aAAa,EAAE;YACX,IAAI,EAAE,gBAAgB;YACtB,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;SACxD;KACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { SessionAssistantMessage } from "../core/SessionContext.js";
2
+ import type { SessionEvent } from "../core/SessionEvent.js";
3
+ /** Reconstructs one ordered assistant message from a session run's block events. */
4
+ export declare class SessionAssistantMessageAccumulator {
5
+ private readonly content;
6
+ private checkpoint;
7
+ private text;
8
+ private reasoning;
9
+ private readonly toolCalls;
10
+ private readonly toolResults;
11
+ add(event: SessionEvent): void;
12
+ message(): SessionAssistantMessage | undefined;
13
+ private clearActiveBlocks;
14
+ }
15
+ /** Reconstructs one assistant message after consuming a complete run. */
16
+ export declare function assistantMessageFromEvents(events: readonly SessionEvent[]): SessionAssistantMessage | undefined;
17
+ //# sourceMappingURL=SessionAssistantMessageAccumulator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionAssistantMessageAccumulator.d.ts","sourceRoot":"","sources":["../../sources/core/SessionAssistantMessageAccumulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAER,uBAAuB,EAE1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AA4B3D,oFAAoF;AACpF,qBAAa,kCAAkC;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA+B;IACvD,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,IAAI,CAA+B;IAC3C,OAAO,CAAC,SAAS,CAAoC;IACrD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA2C;IACrE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA6C;IAEzE,GAAG,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CA8G7B;IAED,OAAO,IAAI,uBAAuB,GAAG,SAAS,CAM7C;IAED,OAAO,CAAC,iBAAiB;CAM5B;AAED,yEAAyE;AACzE,wBAAgB,0BAA0B,CACtC,MAAM,EAAE,SAAS,YAAY,EAAE,GAChC,uBAAuB,GAAG,SAAS,CAIrC"}