@opencode-ai/ai 0.0.0-beta-17492

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 (194) hide show
  1. package/README.md +392 -0
  2. package/dist/cache-policy.d.ts +2 -0
  3. package/dist/cache-policy.js +121 -0
  4. package/dist/image-client.d.ts +19 -0
  5. package/dist/image-client.js +19 -0
  6. package/dist/image.d.ts +110 -0
  7. package/dist/image.js +102 -0
  8. package/dist/index.d.ts +18 -0
  9. package/dist/index.js +12 -0
  10. package/dist/llm.d.ts +230 -0
  11. package/dist/llm.js +77 -0
  12. package/dist/protocols/anthropic-messages.d.ts +633 -0
  13. package/dist/protocols/anthropic-messages.js +860 -0
  14. package/dist/protocols/bedrock-converse.d.ts +533 -0
  15. package/dist/protocols/bedrock-converse.js +584 -0
  16. package/dist/protocols/bedrock-event-stream.d.ts +9 -0
  17. package/dist/protocols/bedrock-event-stream.js +73 -0
  18. package/dist/protocols/gemini.d.ts +300 -0
  19. package/dist/protocols/gemini.js +512 -0
  20. package/dist/protocols/google-images.d.ts +30 -0
  21. package/dist/protocols/google-images.js +191 -0
  22. package/dist/protocols/index.d.ts +10 -0
  23. package/dist/protocols/index.js +10 -0
  24. package/dist/protocols/open-responses-channel.d.ts +26 -0
  25. package/dist/protocols/open-responses-channel.js +120 -0
  26. package/dist/protocols/open-responses.d.ts +951 -0
  27. package/dist/protocols/open-responses.js +873 -0
  28. package/dist/protocols/openai-chat.d.ts +795 -0
  29. package/dist/protocols/openai-chat.js +718 -0
  30. package/dist/protocols/openai-compatible-chat.d.ts +107 -0
  31. package/dist/protocols/openai-compatible-chat.js +20 -0
  32. package/dist/protocols/openai-compatible-responses.d.ts +96 -0
  33. package/dist/protocols/openai-compatible-responses.js +17 -0
  34. package/dist/protocols/openai-images.d.ts +32 -0
  35. package/dist/protocols/openai-images.js +188 -0
  36. package/dist/protocols/openai-responses-channel.d.ts +12 -0
  37. package/dist/protocols/openai-responses-channel.js +142 -0
  38. package/dist/protocols/openai-responses.d.ts +596 -0
  39. package/dist/protocols/openai-responses.js +208 -0
  40. package/dist/protocols/shared.d.ts +194 -0
  41. package/dist/protocols/shared.js +238 -0
  42. package/dist/protocols/utils/bedrock-auth.d.ts +21 -0
  43. package/dist/protocols/utils/bedrock-auth.js +43 -0
  44. package/dist/protocols/utils/bedrock-cache.d.ts +15 -0
  45. package/dist/protocols/utils/bedrock-cache.js +29 -0
  46. package/dist/protocols/utils/bedrock-media.d.ts +49 -0
  47. package/dist/protocols/utils/bedrock-media.js +70 -0
  48. package/dist/protocols/utils/cache.d.ts +6 -0
  49. package/dist/protocols/utils/cache.js +8 -0
  50. package/dist/protocols/utils/gemini-tool-schema.d.ts +2 -0
  51. package/dist/protocols/utils/gemini-tool-schema.js +103 -0
  52. package/dist/protocols/utils/image-input.d.ts +21 -0
  53. package/dist/protocols/utils/image-input.js +22 -0
  54. package/dist/protocols/utils/lifecycle.d.ts +20 -0
  55. package/dist/protocols/utils/lifecycle.js +68 -0
  56. package/dist/protocols/utils/open-responses-options.d.ts +21 -0
  57. package/dist/protocols/utils/open-responses-options.js +41 -0
  58. package/dist/protocols/utils/openai-image.d.ts +5 -0
  59. package/dist/protocols/utils/openai-image.js +18 -0
  60. package/dist/protocols/utils/openai-options.d.ts +14 -0
  61. package/dist/protocols/utils/openai-options.js +14 -0
  62. package/dist/protocols/utils/tool-schema.d.ts +8 -0
  63. package/dist/protocols/utils/tool-schema.js +81 -0
  64. package/dist/protocols/utils/tool-stream.d.ts +639 -0
  65. package/dist/protocols/utils/tool-stream.js +141 -0
  66. package/dist/protocols/xai-images.d.ts +26 -0
  67. package/dist/protocols/xai-images.js +111 -0
  68. package/dist/protocols/zai-images.d.ts +22 -0
  69. package/dist/protocols/zai-images.js +84 -0
  70. package/dist/protocols.d.ts +1 -0
  71. package/dist/protocols.js +1 -0
  72. package/dist/provider-error.d.ts +14 -0
  73. package/dist/provider-error.js +130 -0
  74. package/dist/provider-package.d.ts +15 -0
  75. package/dist/provider-package.js +1 -0
  76. package/dist/provider.d.ts +23 -0
  77. package/dist/provider.js +2 -0
  78. package/dist/providers/amazon-bedrock/mantle/chat.d.ts +2 -0
  79. package/dist/providers/amazon-bedrock/mantle/chat.js +1 -0
  80. package/dist/providers/amazon-bedrock/mantle/responses.d.ts +2 -0
  81. package/dist/providers/amazon-bedrock/mantle/responses.js +1 -0
  82. package/dist/providers/amazon-bedrock/mantle.d.ts +2 -0
  83. package/dist/providers/amazon-bedrock/mantle.js +1 -0
  84. package/dist/providers/amazon-bedrock-mantle.d.ts +247 -0
  85. package/dist/providers/amazon-bedrock-mantle.js +68 -0
  86. package/dist/providers/amazon-bedrock.d.ts +172 -0
  87. package/dist/providers/amazon-bedrock.js +41 -0
  88. package/dist/providers/anthropic-compatible.d.ts +218 -0
  89. package/dist/providers/anthropic-compatible.js +45 -0
  90. package/dist/providers/anthropic.d.ts +216 -0
  91. package/dist/providers/anthropic.js +40 -0
  92. package/dist/providers/azure/chat.d.ts +2 -0
  93. package/dist/providers/azure/chat.js +1 -0
  94. package/dist/providers/azure/responses.d.ts +2 -0
  95. package/dist/providers/azure/responses.js +1 -0
  96. package/dist/providers/azure.d.ts +248 -0
  97. package/dist/providers/azure.js +90 -0
  98. package/dist/providers/cloudflare.d.ts +338 -0
  99. package/dist/providers/cloudflare.js +87 -0
  100. package/dist/providers/google-vertex/chat.d.ts +2 -0
  101. package/dist/providers/google-vertex/chat.js +1 -0
  102. package/dist/providers/google-vertex/gemini.d.ts +2 -0
  103. package/dist/providers/google-vertex/gemini.js +1 -0
  104. package/dist/providers/google-vertex/messages.d.ts +2 -0
  105. package/dist/providers/google-vertex/messages.js +1 -0
  106. package/dist/providers/google-vertex/responses.d.ts +2 -0
  107. package/dist/providers/google-vertex/responses.js +1 -0
  108. package/dist/providers/google-vertex-chat.d.ts +131 -0
  109. package/dist/providers/google-vertex-chat.js +50 -0
  110. package/dist/providers/google-vertex-messages.d.ts +215 -0
  111. package/dist/providers/google-vertex-messages.js +75 -0
  112. package/dist/providers/google-vertex-responses.d.ts +122 -0
  113. package/dist/providers/google-vertex-responses.js +51 -0
  114. package/dist/providers/google-vertex-shared.d.ts +22 -0
  115. package/dist/providers/google-vertex-shared.js +61 -0
  116. package/dist/providers/google-vertex.d.ts +115 -0
  117. package/dist/providers/google-vertex.js +64 -0
  118. package/dist/providers/google.d.ts +112 -0
  119. package/dist/providers/google.js +43 -0
  120. package/dist/providers/index.d.ts +18 -0
  121. package/dist/providers/index.js +18 -0
  122. package/dist/providers/open-responses-options.d.ts +16 -0
  123. package/dist/providers/open-responses-options.js +1 -0
  124. package/dist/providers/openai/chat.d.ts +2 -0
  125. package/dist/providers/openai/chat.js +1 -0
  126. package/dist/providers/openai/responses.d.ts +2 -0
  127. package/dist/providers/openai/responses.js +1 -0
  128. package/dist/providers/openai-compatible/responses.d.ts +1 -0
  129. package/dist/providers/openai-compatible/responses.js +1 -0
  130. package/dist/providers/openai-compatible-profile.d.ts +43 -0
  131. package/dist/providers/openai-compatible-profile.js +12 -0
  132. package/dist/providers/openai-compatible-responses.d.ts +120 -0
  133. package/dist/providers/openai-compatible-responses.js +33 -0
  134. package/dist/providers/openai-compatible.d.ts +167 -0
  135. package/dist/providers/openai-compatible.js +55 -0
  136. package/dist/providers/openai-options.d.ts +21 -0
  137. package/dist/providers/openai-options.js +41 -0
  138. package/dist/providers/openai.d.ts +264 -0
  139. package/dist/providers/openai.js +83 -0
  140. package/dist/providers/openrouter.d.ts +537 -0
  141. package/dist/providers/openrouter.js +117 -0
  142. package/dist/providers/xai.d.ts +249 -0
  143. package/dist/providers/xai.js +79 -0
  144. package/dist/providers/zai.d.ts +24 -0
  145. package/dist/providers/zai.js +21 -0
  146. package/dist/providers.d.ts +1 -0
  147. package/dist/providers.js +1 -0
  148. package/dist/route/auth-options.d.ts +34 -0
  149. package/dist/route/auth-options.js +14 -0
  150. package/dist/route/auth.d.ts +51 -0
  151. package/dist/route/auth.js +89 -0
  152. package/dist/route/client.d.ts +348 -0
  153. package/dist/route/client.js +214 -0
  154. package/dist/route/endpoint.d.ts +28 -0
  155. package/dist/route/endpoint.js +21 -0
  156. package/dist/route/executor.d.ts +23 -0
  157. package/dist/route/executor.js +227 -0
  158. package/dist/route/framing.d.ts +23 -0
  159. package/dist/route/framing.js +4 -0
  160. package/dist/route/index.d.ts +16 -0
  161. package/dist/route/index.js +9 -0
  162. package/dist/route/protocol.d.ts +77 -0
  163. package/dist/route/protocol.js +17 -0
  164. package/dist/route/transport/http.d.ts +34 -0
  165. package/dist/route/transport/http.js +63 -0
  166. package/dist/route/transport/index.d.ts +39 -0
  167. package/dist/route/transport/index.js +4 -0
  168. package/dist/route/transport/websocket-channel.d.ts +56 -0
  169. package/dist/route/transport/websocket-channel.js +1 -0
  170. package/dist/route/transport/websocket.d.ts +55 -0
  171. package/dist/route/transport/websocket.js +326 -0
  172. package/dist/route.d.ts +1 -0
  173. package/dist/route.js +1 -0
  174. package/dist/schema/errors.d.ts +159 -0
  175. package/dist/schema/errors.js +155 -0
  176. package/dist/schema/events.d.ts +4587 -0
  177. package/dist/schema/events.js +492 -0
  178. package/dist/schema/ids.d.ts +30 -0
  179. package/dist/schema/ids.js +19 -0
  180. package/dist/schema/index.d.ts +5 -0
  181. package/dist/schema/index.js +5 -0
  182. package/dist/schema/messages.d.ts +402 -0
  183. package/dist/schema/messages.js +244 -0
  184. package/dist/schema/options.d.ts +159 -0
  185. package/dist/schema/options.js +202 -0
  186. package/dist/testing.d.ts +1493 -0
  187. package/dist/testing.js +88 -0
  188. package/dist/tool-runtime.d.ts +15 -0
  189. package/dist/tool-runtime.js +54 -0
  190. package/dist/tool.d.ts +135 -0
  191. package/dist/tool.js +66 -0
  192. package/dist/utils/record.d.ts +2 -0
  193. package/dist/utils/record.js +2 -0
  194. package/package.json +47 -0
@@ -0,0 +1,639 @@
1
+ import { Effect } from "effect";
2
+ import { AIError, LLMEvent, type ProviderMetadata } from "../../schema/index.js";
3
+ import { type ToolAccumulator } from "../shared.js";
4
+ type StreamKey = string | number;
5
+ /**
6
+ * One pending streamed tool call. Providers emit the tool identity and JSON
7
+ * argument text across separate chunks; `input` is the raw JSON string collected
8
+ * so far, not the parsed object.
9
+ */
10
+ export interface PendingTool extends ToolAccumulator {
11
+ readonly providerExecuted?: boolean;
12
+ readonly providerMetadata?: ProviderMetadata;
13
+ }
14
+ /**
15
+ * Sparse parser state keyed by the provider's stream-local tool identifier.
16
+ *
17
+ * This key is not the final tool-call id (`call_...`). It is the id/index the
18
+ * provider uses while streaming a partial call: OpenAI Chat / Anthropic /
19
+ * Bedrock use numeric content indexes, while OpenAI Responses uses string
20
+ * `item_id`s. The generic keeps each protocol internally consistent.
21
+ */
22
+ export type State<K extends StreamKey> = Partial<Record<K, PendingTool>>;
23
+ /**
24
+ * Result of adding argument text to one pending tool call. It returns both the
25
+ * next `tools` state and the updated `tool` because parsers often need the
26
+ * current id/name immediately. `events` contains lifecycle and delta events
27
+ * produced by the append; metadata-only deltas update identity without output.
28
+ */
29
+ export interface AppendOutcome<K extends StreamKey> {
30
+ readonly tools: State<K>;
31
+ readonly tool: PendingTool;
32
+ readonly events: ReadonlyArray<LLMEvent>;
33
+ }
34
+ /** Create empty accumulator state for one provider stream. */
35
+ export declare const empty: <K extends StreamKey>() => State<K>;
36
+ export declare const isError: <K extends StreamKey>(result: AppendOutcome<K> | AIError) => result is AIError;
37
+ /**
38
+ * Register a tool call whose start event arrived before any argument deltas.
39
+ * Used by Anthropic `content_block_start`, Bedrock `contentBlockStart`, and
40
+ * OpenAI Responses `response.output_item.added`.
41
+ */
42
+ export declare const start: <K extends StreamKey>(tools: State<K>, key: K, tool: Omit<PendingTool, "input"> & {
43
+ readonly input?: string;
44
+ }) => Partial<Record<K, PendingTool>>;
45
+ /**
46
+ * Append a streamed argument delta, starting the tool if this provider encodes
47
+ * identity on the first delta instead of a separate start event. OpenAI Chat has
48
+ * this shape: `tool_calls[].index` is the stream key, and `id` / `name` may only
49
+ * appear on the first delta for that index.
50
+ */
51
+ export declare const appendOrStart: <K extends StreamKey>(route: string, tools: State<K>, key: K, delta: {
52
+ readonly id?: string;
53
+ readonly name?: string;
54
+ readonly text: string;
55
+ }, missingToolMessage: string) => AppendOutcome<K> | AIError;
56
+ /**
57
+ * Append argument text to a tool that must already have been started. This keeps
58
+ * protocols honest when their stream grammar promises a start event before any
59
+ * argument delta.
60
+ */
61
+ export declare const appendExisting: <K extends StreamKey>(route: string, tools: State<K>, key: K, text: string, missingToolMessage: string) => AppendOutcome<K> | AIError;
62
+ /**
63
+ * Finalize one pending tool call: parse the accumulated raw JSON, remove it
64
+ * from state, and return either a call or a non-executable local input error.
65
+ * Missing keys are a no-op because some providers emit stop events for
66
+ * non-tool content blocks.
67
+ */
68
+ export declare const finish: <K extends StreamKey>(route: string, tools: State<K>, key: K) => Effect.Effect<{
69
+ tools: Partial<Record<K, PendingTool>>;
70
+ events?: undefined;
71
+ } | {
72
+ tools: Partial<Record<K, PendingTool>>;
73
+ events: readonly ({
74
+ readonly type: "step-start";
75
+ readonly index: number;
76
+ } | {
77
+ readonly id: string;
78
+ readonly type: "text-start";
79
+ readonly providerMetadata?: {
80
+ readonly [x: string]: {
81
+ readonly [x: string]: unknown;
82
+ };
83
+ } | undefined;
84
+ } | {
85
+ readonly id: string;
86
+ readonly type: "text-delta";
87
+ readonly text: string;
88
+ readonly providerMetadata?: {
89
+ readonly [x: string]: {
90
+ readonly [x: string]: unknown;
91
+ };
92
+ } | undefined;
93
+ } | {
94
+ readonly id: string;
95
+ readonly type: "text-end";
96
+ readonly providerMetadata?: {
97
+ readonly [x: string]: {
98
+ readonly [x: string]: unknown;
99
+ };
100
+ } | undefined;
101
+ } | {
102
+ readonly id: string;
103
+ readonly type: "reasoning-start";
104
+ readonly providerMetadata?: {
105
+ readonly [x: string]: {
106
+ readonly [x: string]: unknown;
107
+ };
108
+ } | undefined;
109
+ } | {
110
+ readonly id: string;
111
+ readonly type: "reasoning-delta";
112
+ readonly text: string;
113
+ readonly providerMetadata?: {
114
+ readonly [x: string]: {
115
+ readonly [x: string]: unknown;
116
+ };
117
+ } | undefined;
118
+ } | {
119
+ readonly id: string;
120
+ readonly type: "reasoning-end";
121
+ readonly providerMetadata?: {
122
+ readonly [x: string]: {
123
+ readonly [x: string]: unknown;
124
+ };
125
+ } | undefined;
126
+ } | {
127
+ readonly id: string;
128
+ readonly type: "tool-input-start";
129
+ readonly name: string;
130
+ readonly providerMetadata?: {
131
+ readonly [x: string]: {
132
+ readonly [x: string]: unknown;
133
+ };
134
+ } | undefined;
135
+ readonly providerExecuted?: boolean | undefined;
136
+ } | {
137
+ readonly type: "tool-input-delta";
138
+ readonly id: string;
139
+ readonly name: string;
140
+ readonly text: string;
141
+ } | {
142
+ readonly id: string;
143
+ readonly type: "tool-input-end";
144
+ readonly name: string;
145
+ readonly providerMetadata?: {
146
+ readonly [x: string]: {
147
+ readonly [x: string]: unknown;
148
+ };
149
+ } | undefined;
150
+ } | {
151
+ readonly type: "tool-input-error";
152
+ readonly id: string;
153
+ readonly name: string;
154
+ readonly raw: string;
155
+ } | {
156
+ readonly id: string;
157
+ readonly type: "tool-call";
158
+ readonly name: string;
159
+ readonly input: unknown;
160
+ readonly providerMetadata?: {
161
+ readonly [x: string]: {
162
+ readonly [x: string]: unknown;
163
+ };
164
+ } | undefined;
165
+ readonly providerExecuted?: boolean | undefined;
166
+ } | {
167
+ readonly id: string;
168
+ readonly type: "tool-result";
169
+ readonly name: string;
170
+ readonly result: {
171
+ readonly type: "json";
172
+ readonly value: unknown;
173
+ } | {
174
+ readonly type: "text";
175
+ readonly value: unknown;
176
+ } | {
177
+ readonly type: "error";
178
+ readonly value: unknown;
179
+ } | {
180
+ readonly type: "content";
181
+ readonly value: readonly ({
182
+ readonly type: "text";
183
+ readonly text: string;
184
+ } | {
185
+ readonly type: "file";
186
+ readonly uri: string;
187
+ readonly mime: string;
188
+ readonly name?: string | undefined;
189
+ })[];
190
+ };
191
+ readonly output?: {
192
+ readonly structured: unknown;
193
+ readonly content: readonly ({
194
+ readonly type: "text";
195
+ readonly text: string;
196
+ } | {
197
+ readonly type: "file";
198
+ readonly uri: string;
199
+ readonly mime: string;
200
+ readonly name?: string | undefined;
201
+ })[];
202
+ } | undefined;
203
+ readonly providerMetadata?: {
204
+ readonly [x: string]: {
205
+ readonly [x: string]: unknown;
206
+ };
207
+ } | undefined;
208
+ readonly providerExecuted?: boolean | undefined;
209
+ } | {
210
+ readonly id: string;
211
+ readonly type: "tool-error";
212
+ readonly name: string;
213
+ readonly message: string;
214
+ readonly error?: unknown;
215
+ readonly providerMetadata?: {
216
+ readonly [x: string]: {
217
+ readonly [x: string]: unknown;
218
+ };
219
+ } | undefined;
220
+ } | {
221
+ readonly type: "step-finish";
222
+ readonly reason: {
223
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
224
+ readonly raw?: string | undefined;
225
+ };
226
+ readonly index: number;
227
+ readonly providerMetadata?: {
228
+ readonly [x: string]: {
229
+ readonly [x: string]: unknown;
230
+ };
231
+ } | undefined;
232
+ readonly usage?: import("../../schema/events.js").Usage | undefined;
233
+ } | {
234
+ readonly type: "finish";
235
+ readonly reason: {
236
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
237
+ readonly raw?: string | undefined;
238
+ };
239
+ readonly providerMetadata?: {
240
+ readonly [x: string]: {
241
+ readonly [x: string]: unknown;
242
+ };
243
+ } | undefined;
244
+ readonly usage?: import("../../schema/events.js").Usage | undefined;
245
+ } | {
246
+ readonly type: "provider-error";
247
+ readonly message: string;
248
+ readonly providerMetadata?: {
249
+ readonly [x: string]: {
250
+ readonly [x: string]: unknown;
251
+ };
252
+ } | undefined;
253
+ readonly classification?: "context-overflow" | "payload-too-large" | undefined;
254
+ })[];
255
+ }, AIError, never>;
256
+ /**
257
+ * Finalize one pending tool call with an authoritative final input string.
258
+ * OpenAI Responses can send accumulated deltas and then repeat the completed
259
+ * arguments on `response.output_item.done`; the final value wins.
260
+ */
261
+ export declare const finishWithInput: <K extends StreamKey>(route: string, tools: State<K>, key: K, input: string) => Effect.Effect<{
262
+ tools: Partial<Record<K, PendingTool>>;
263
+ events?: undefined;
264
+ } | {
265
+ tools: Partial<Record<K, PendingTool>>;
266
+ events: readonly ({
267
+ readonly type: "step-start";
268
+ readonly index: number;
269
+ } | {
270
+ readonly id: string;
271
+ readonly type: "text-start";
272
+ readonly providerMetadata?: {
273
+ readonly [x: string]: {
274
+ readonly [x: string]: unknown;
275
+ };
276
+ } | undefined;
277
+ } | {
278
+ readonly id: string;
279
+ readonly type: "text-delta";
280
+ readonly text: string;
281
+ readonly providerMetadata?: {
282
+ readonly [x: string]: {
283
+ readonly [x: string]: unknown;
284
+ };
285
+ } | undefined;
286
+ } | {
287
+ readonly id: string;
288
+ readonly type: "text-end";
289
+ readonly providerMetadata?: {
290
+ readonly [x: string]: {
291
+ readonly [x: string]: unknown;
292
+ };
293
+ } | undefined;
294
+ } | {
295
+ readonly id: string;
296
+ readonly type: "reasoning-start";
297
+ readonly providerMetadata?: {
298
+ readonly [x: string]: {
299
+ readonly [x: string]: unknown;
300
+ };
301
+ } | undefined;
302
+ } | {
303
+ readonly id: string;
304
+ readonly type: "reasoning-delta";
305
+ readonly text: string;
306
+ readonly providerMetadata?: {
307
+ readonly [x: string]: {
308
+ readonly [x: string]: unknown;
309
+ };
310
+ } | undefined;
311
+ } | {
312
+ readonly id: string;
313
+ readonly type: "reasoning-end";
314
+ readonly providerMetadata?: {
315
+ readonly [x: string]: {
316
+ readonly [x: string]: unknown;
317
+ };
318
+ } | undefined;
319
+ } | {
320
+ readonly id: string;
321
+ readonly type: "tool-input-start";
322
+ readonly name: string;
323
+ readonly providerMetadata?: {
324
+ readonly [x: string]: {
325
+ readonly [x: string]: unknown;
326
+ };
327
+ } | undefined;
328
+ readonly providerExecuted?: boolean | undefined;
329
+ } | {
330
+ readonly type: "tool-input-delta";
331
+ readonly id: string;
332
+ readonly name: string;
333
+ readonly text: string;
334
+ } | {
335
+ readonly id: string;
336
+ readonly type: "tool-input-end";
337
+ readonly name: string;
338
+ readonly providerMetadata?: {
339
+ readonly [x: string]: {
340
+ readonly [x: string]: unknown;
341
+ };
342
+ } | undefined;
343
+ } | {
344
+ readonly type: "tool-input-error";
345
+ readonly id: string;
346
+ readonly name: string;
347
+ readonly raw: string;
348
+ } | {
349
+ readonly id: string;
350
+ readonly type: "tool-call";
351
+ readonly name: string;
352
+ readonly input: unknown;
353
+ readonly providerMetadata?: {
354
+ readonly [x: string]: {
355
+ readonly [x: string]: unknown;
356
+ };
357
+ } | undefined;
358
+ readonly providerExecuted?: boolean | undefined;
359
+ } | {
360
+ readonly id: string;
361
+ readonly type: "tool-result";
362
+ readonly name: string;
363
+ readonly result: {
364
+ readonly type: "json";
365
+ readonly value: unknown;
366
+ } | {
367
+ readonly type: "text";
368
+ readonly value: unknown;
369
+ } | {
370
+ readonly type: "error";
371
+ readonly value: unknown;
372
+ } | {
373
+ readonly type: "content";
374
+ readonly value: readonly ({
375
+ readonly type: "text";
376
+ readonly text: string;
377
+ } | {
378
+ readonly type: "file";
379
+ readonly uri: string;
380
+ readonly mime: string;
381
+ readonly name?: string | undefined;
382
+ })[];
383
+ };
384
+ readonly output?: {
385
+ readonly structured: unknown;
386
+ readonly content: readonly ({
387
+ readonly type: "text";
388
+ readonly text: string;
389
+ } | {
390
+ readonly type: "file";
391
+ readonly uri: string;
392
+ readonly mime: string;
393
+ readonly name?: string | undefined;
394
+ })[];
395
+ } | undefined;
396
+ readonly providerMetadata?: {
397
+ readonly [x: string]: {
398
+ readonly [x: string]: unknown;
399
+ };
400
+ } | undefined;
401
+ readonly providerExecuted?: boolean | undefined;
402
+ } | {
403
+ readonly id: string;
404
+ readonly type: "tool-error";
405
+ readonly name: string;
406
+ readonly message: string;
407
+ readonly error?: unknown;
408
+ readonly providerMetadata?: {
409
+ readonly [x: string]: {
410
+ readonly [x: string]: unknown;
411
+ };
412
+ } | undefined;
413
+ } | {
414
+ readonly type: "step-finish";
415
+ readonly reason: {
416
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
417
+ readonly raw?: string | undefined;
418
+ };
419
+ readonly index: number;
420
+ readonly providerMetadata?: {
421
+ readonly [x: string]: {
422
+ readonly [x: string]: unknown;
423
+ };
424
+ } | undefined;
425
+ readonly usage?: import("../../schema/events.js").Usage | undefined;
426
+ } | {
427
+ readonly type: "finish";
428
+ readonly reason: {
429
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
430
+ readonly raw?: string | undefined;
431
+ };
432
+ readonly providerMetadata?: {
433
+ readonly [x: string]: {
434
+ readonly [x: string]: unknown;
435
+ };
436
+ } | undefined;
437
+ readonly usage?: import("../../schema/events.js").Usage | undefined;
438
+ } | {
439
+ readonly type: "provider-error";
440
+ readonly message: string;
441
+ readonly providerMetadata?: {
442
+ readonly [x: string]: {
443
+ readonly [x: string]: unknown;
444
+ };
445
+ } | undefined;
446
+ readonly classification?: "context-overflow" | "payload-too-large" | undefined;
447
+ })[];
448
+ }, AIError, never>;
449
+ /**
450
+ * Finalize every pending tool call at once. OpenAI Chat has this shape: it does
451
+ * not emit per-tool stop events, so all accumulated calls finish independently
452
+ * when the choice receives a terminal `finish_reason`.
453
+ */
454
+ export declare const finishAll: <K extends StreamKey>(route: string, tools: State<K>) => Effect.Effect<{
455
+ tools: Partial<Record<K, PendingTool>>;
456
+ events: ({
457
+ readonly type: "step-start";
458
+ readonly index: number;
459
+ } | {
460
+ readonly id: string;
461
+ readonly type: "text-start";
462
+ readonly providerMetadata?: {
463
+ readonly [x: string]: {
464
+ readonly [x: string]: unknown;
465
+ };
466
+ } | undefined;
467
+ } | {
468
+ readonly id: string;
469
+ readonly type: "text-delta";
470
+ readonly text: string;
471
+ readonly providerMetadata?: {
472
+ readonly [x: string]: {
473
+ readonly [x: string]: unknown;
474
+ };
475
+ } | undefined;
476
+ } | {
477
+ readonly id: string;
478
+ readonly type: "text-end";
479
+ readonly providerMetadata?: {
480
+ readonly [x: string]: {
481
+ readonly [x: string]: unknown;
482
+ };
483
+ } | undefined;
484
+ } | {
485
+ readonly id: string;
486
+ readonly type: "reasoning-start";
487
+ readonly providerMetadata?: {
488
+ readonly [x: string]: {
489
+ readonly [x: string]: unknown;
490
+ };
491
+ } | undefined;
492
+ } | {
493
+ readonly id: string;
494
+ readonly type: "reasoning-delta";
495
+ readonly text: string;
496
+ readonly providerMetadata?: {
497
+ readonly [x: string]: {
498
+ readonly [x: string]: unknown;
499
+ };
500
+ } | undefined;
501
+ } | {
502
+ readonly id: string;
503
+ readonly type: "reasoning-end";
504
+ readonly providerMetadata?: {
505
+ readonly [x: string]: {
506
+ readonly [x: string]: unknown;
507
+ };
508
+ } | undefined;
509
+ } | {
510
+ readonly id: string;
511
+ readonly type: "tool-input-start";
512
+ readonly name: string;
513
+ readonly providerMetadata?: {
514
+ readonly [x: string]: {
515
+ readonly [x: string]: unknown;
516
+ };
517
+ } | undefined;
518
+ readonly providerExecuted?: boolean | undefined;
519
+ } | {
520
+ readonly type: "tool-input-delta";
521
+ readonly id: string;
522
+ readonly name: string;
523
+ readonly text: string;
524
+ } | {
525
+ readonly id: string;
526
+ readonly type: "tool-input-end";
527
+ readonly name: string;
528
+ readonly providerMetadata?: {
529
+ readonly [x: string]: {
530
+ readonly [x: string]: unknown;
531
+ };
532
+ } | undefined;
533
+ } | {
534
+ readonly type: "tool-input-error";
535
+ readonly id: string;
536
+ readonly name: string;
537
+ readonly raw: string;
538
+ } | {
539
+ readonly id: string;
540
+ readonly type: "tool-call";
541
+ readonly name: string;
542
+ readonly input: unknown;
543
+ readonly providerMetadata?: {
544
+ readonly [x: string]: {
545
+ readonly [x: string]: unknown;
546
+ };
547
+ } | undefined;
548
+ readonly providerExecuted?: boolean | undefined;
549
+ } | {
550
+ readonly id: string;
551
+ readonly type: "tool-result";
552
+ readonly name: string;
553
+ readonly result: {
554
+ readonly type: "json";
555
+ readonly value: unknown;
556
+ } | {
557
+ readonly type: "text";
558
+ readonly value: unknown;
559
+ } | {
560
+ readonly type: "error";
561
+ readonly value: unknown;
562
+ } | {
563
+ readonly type: "content";
564
+ readonly value: readonly ({
565
+ readonly type: "text";
566
+ readonly text: string;
567
+ } | {
568
+ readonly type: "file";
569
+ readonly uri: string;
570
+ readonly mime: string;
571
+ readonly name?: string | undefined;
572
+ })[];
573
+ };
574
+ readonly output?: {
575
+ readonly structured: unknown;
576
+ readonly content: readonly ({
577
+ readonly type: "text";
578
+ readonly text: string;
579
+ } | {
580
+ readonly type: "file";
581
+ readonly uri: string;
582
+ readonly mime: string;
583
+ readonly name?: string | undefined;
584
+ })[];
585
+ } | undefined;
586
+ readonly providerMetadata?: {
587
+ readonly [x: string]: {
588
+ readonly [x: string]: unknown;
589
+ };
590
+ } | undefined;
591
+ readonly providerExecuted?: boolean | undefined;
592
+ } | {
593
+ readonly id: string;
594
+ readonly type: "tool-error";
595
+ readonly name: string;
596
+ readonly message: string;
597
+ readonly error?: unknown;
598
+ readonly providerMetadata?: {
599
+ readonly [x: string]: {
600
+ readonly [x: string]: unknown;
601
+ };
602
+ } | undefined;
603
+ } | {
604
+ readonly type: "step-finish";
605
+ readonly reason: {
606
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
607
+ readonly raw?: string | undefined;
608
+ };
609
+ readonly index: number;
610
+ readonly providerMetadata?: {
611
+ readonly [x: string]: {
612
+ readonly [x: string]: unknown;
613
+ };
614
+ } | undefined;
615
+ readonly usage?: import("../../schema/events.js").Usage | undefined;
616
+ } | {
617
+ readonly type: "finish";
618
+ readonly reason: {
619
+ readonly normalized: "length" | "stop" | "tool-calls" | "content-filter" | "error" | "unknown";
620
+ readonly raw?: string | undefined;
621
+ };
622
+ readonly providerMetadata?: {
623
+ readonly [x: string]: {
624
+ readonly [x: string]: unknown;
625
+ };
626
+ } | undefined;
627
+ readonly usage?: import("../../schema/events.js").Usage | undefined;
628
+ } | {
629
+ readonly type: "provider-error";
630
+ readonly message: string;
631
+ readonly providerMetadata?: {
632
+ readonly [x: string]: {
633
+ readonly [x: string]: unknown;
634
+ };
635
+ } | undefined;
636
+ readonly classification?: "context-overflow" | "payload-too-large" | undefined;
637
+ })[];
638
+ }, AIError, never>;
639
+ export * as ToolStream from "./tool-stream.js";