@opencode/ai 2.2.5 → 2.2.6

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 (264) hide show
  1. package/README.md +133 -69
  2. package/dist/cache-policy.d.ts +1 -1
  3. package/dist/cache-policy.js +16 -4
  4. package/dist/decision-client.d.ts +3 -3
  5. package/dist/decision.d.ts +20 -125
  6. package/dist/decision.js +25 -15
  7. package/dist/effect.d.ts +4 -15
  8. package/dist/effect.js +2 -6
  9. package/dist/effort-updates.d.ts +3 -3
  10. package/dist/effort-updates.js +2 -2
  11. package/dist/experimental/cloudflare-run-extraction.d.ts +7 -3
  12. package/dist/experimental/cloudflare-run-extraction.js +4 -1
  13. package/dist/experimental/extraction.d.ts +10 -40
  14. package/dist/experimental/extraction.js +14 -13
  15. package/dist/experimental.d.ts +8 -8
  16. package/dist/experimental.js +4 -4
  17. package/dist/generation.d.ts +0 -2
  18. package/dist/generation.js +2 -2
  19. package/dist/image-client.d.ts +13 -7
  20. package/dist/image-client.js +1 -1
  21. package/dist/image.d.ts +357 -464
  22. package/dist/image.js +17 -15
  23. package/dist/index.d.ts +28 -465
  24. package/dist/index.js +18 -17
  25. package/dist/llm.d.ts +65 -266
  26. package/dist/llm.js +101 -92
  27. package/dist/loop.d.ts +38 -0
  28. package/dist/loop.js +136 -0
  29. package/dist/media-model.d.ts +1 -1
  30. package/dist/media-model.js +8 -6
  31. package/dist/media.d.ts +9 -0
  32. package/dist/media.js +37 -2
  33. package/dist/protocols/alibaba-chat.d.ts +5 -1
  34. package/dist/protocols/alibaba-chat.js +3 -3
  35. package/dist/protocols/alibaba-images.d.ts +2 -2
  36. package/dist/protocols/alibaba-messages.js +3 -3
  37. package/dist/protocols/alibaba-responses.js +8 -20
  38. package/dist/protocols/anthropic-messages.d.ts +1 -1
  39. package/dist/protocols/anthropic-messages.js +54 -173
  40. package/dist/protocols/assemblyai-transcription.d.ts +2 -2
  41. package/dist/protocols/bedrock-converse.js +10 -16
  42. package/dist/protocols/cartesia-speech.d.ts +2 -2
  43. package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
  44. package/dist/protocols/cohere-chat.js +9 -12
  45. package/dist/protocols/deepgram-speech.d.ts +2 -2
  46. package/dist/protocols/deepgram-transcription.d.ts +2 -2
  47. package/dist/protocols/elevenlabs-speech.d.ts +2 -2
  48. package/dist/protocols/elevenlabs-transcription.d.ts +2 -2
  49. package/dist/protocols/gemini.d.ts +3 -0
  50. package/dist/protocols/gemini.js +54 -72
  51. package/dist/protocols/google-images.d.ts +2 -2
  52. package/dist/protocols/google-interactions.d.ts +3 -4
  53. package/dist/protocols/google-interactions.js +44 -30
  54. package/dist/protocols/google-speech.d.ts +2 -2
  55. package/dist/protocols/google-transcription.d.ts +2 -2
  56. package/dist/protocols/google-video.d.ts +2 -2
  57. package/dist/protocols/meta-images.d.ts +2 -2
  58. package/dist/protocols/meta-responses.js +26 -23
  59. package/dist/protocols/minimax-images.d.ts +2 -2
  60. package/dist/protocols/mistral-chat.js +7 -10
  61. package/dist/protocols/open-responses-channel.js +6 -19
  62. package/dist/protocols/open-responses-continuation.d.ts +1 -5
  63. package/dist/protocols/open-responses-continuation.js +1 -3
  64. package/dist/protocols/open-responses.d.ts +1 -21
  65. package/dist/protocols/open-responses.js +10 -15
  66. package/dist/protocols/openai-chat.d.ts +3 -23
  67. package/dist/protocols/openai-chat.js +26 -47
  68. package/dist/protocols/openai-compatible-chat.d.ts +1 -1
  69. package/dist/protocols/openai-compatible-responses.d.ts +2 -2
  70. package/dist/protocols/openai-compatible-responses.js +1 -1
  71. package/dist/protocols/openai-decisions.js +1 -1
  72. package/dist/protocols/openai-images.d.ts +2 -2
  73. package/dist/protocols/openai-responses.js +10 -29
  74. package/dist/protocols/openai-speech.d.ts +2 -2
  75. package/dist/protocols/openai-transcription.d.ts +2 -2
  76. package/dist/protocols/runway-video.d.ts +2 -2
  77. package/dist/protocols/shared.d.ts +1 -4
  78. package/dist/protocols/shared.js +13 -11
  79. package/dist/protocols/system-one.d.ts +4 -4
  80. package/dist/protocols/utils/bedrock-cache.js +2 -5
  81. package/dist/protocols/utils/bedrock-media.d.ts +0 -3
  82. package/dist/protocols/utils/cache.d.ts +3 -0
  83. package/dist/protocols/utils/cache.js +15 -2
  84. package/dist/protocols/utils/image-sizing.d.ts +1 -1
  85. package/dist/protocols/utils/responses-checkpoint.js +1 -1
  86. package/dist/protocols/utils/responses-compaction.d.ts +1 -1
  87. package/dist/protocols/utils/responses-compaction.js +6 -5
  88. package/dist/protocols/utils/responses-hosted-tools.d.ts +97 -1
  89. package/dist/protocols/utils/responses-hosted-tools.js +31 -0
  90. package/dist/protocols/utils/tool-stream.d.ts +5 -271
  91. package/dist/protocols/utils/tool-stream.js +3 -13
  92. package/dist/protocols/venice-chat.d.ts +3 -1
  93. package/dist/protocols/venice-chat.js +4 -4
  94. package/dist/protocols/xai-images.d.ts +2 -2
  95. package/dist/protocols/xai-responses.js +5 -25
  96. package/dist/protocols/xai-video.d.ts +2 -2
  97. package/dist/protocols/zai-chat.d.ts +5 -1
  98. package/dist/protocols/zai-chat.js +1 -1
  99. package/dist/protocols/zai-images.d.ts +2 -2
  100. package/dist/protocols/zai-messages.js +3 -3
  101. package/dist/provider-error.d.ts +0 -1
  102. package/dist/provider-error.js +7 -80
  103. package/dist/providers/alibaba.d.ts +67 -4
  104. package/dist/providers/alibaba.js +6 -1
  105. package/dist/providers/amazon-bedrock-mantle.d.ts +6 -3
  106. package/dist/providers/amazon-bedrock-mantle.js +6 -3
  107. package/dist/providers/amazon-bedrock.d.ts +6 -7
  108. package/dist/providers/amazon-bedrock.js +1 -1
  109. package/dist/providers/anthropic-compatible.d.ts +7 -8
  110. package/dist/providers/anthropic-compatible.js +2 -5
  111. package/dist/providers/anthropic.d.ts +8 -9
  112. package/dist/providers/anthropic.js +2 -7
  113. package/dist/providers/assemblyai.d.ts +2 -2
  114. package/dist/providers/assemblyai.js +2 -7
  115. package/dist/providers/azure/messages.d.ts +2 -0
  116. package/dist/providers/azure/messages.js +1 -0
  117. package/dist/providers/azure.d.ts +322 -7
  118. package/dist/providers/azure.js +25 -9
  119. package/dist/providers/baseten.d.ts +5 -5
  120. package/dist/providers/baseten.js +7 -21
  121. package/dist/providers/cartesia.d.ts +1 -1
  122. package/dist/providers/cerebras.d.ts +5 -5
  123. package/dist/providers/cerebras.js +4 -15
  124. package/dist/providers/cloudflare-ai-gateway.d.ts +21 -13
  125. package/dist/providers/cloudflare-ai-gateway.js +28 -40
  126. package/dist/providers/cloudflare-shared.d.ts +9 -0
  127. package/dist/providers/cloudflare-shared.js +25 -0
  128. package/dist/providers/cloudflare-workers-ai.d.ts +4 -4
  129. package/dist/providers/cloudflare-workers-ai.js +4 -20
  130. package/dist/providers/cohere/chat.js +2 -7
  131. package/dist/providers/cohere.d.ts +6 -5
  132. package/dist/providers/cohere.js +7 -13
  133. package/dist/providers/deepgram.d.ts +2 -2
  134. package/dist/providers/deepgram.js +2 -7
  135. package/dist/providers/deepinfra.d.ts +5 -5
  136. package/dist/providers/deepinfra.js +5 -13
  137. package/dist/providers/deepseek.d.ts +5 -5
  138. package/dist/providers/deepseek.js +3 -14
  139. package/dist/providers/digitalocean.d.ts +8 -5
  140. package/dist/providers/digitalocean.js +13 -14
  141. package/dist/providers/elevenlabs.d.ts +2 -2
  142. package/dist/providers/elevenlabs.js +2 -7
  143. package/dist/providers/fireworks.d.ts +5 -5
  144. package/dist/providers/fireworks.js +4 -15
  145. package/dist/providers/google/interactions.d.ts +1 -1
  146. package/dist/providers/google/interactions.js +2 -7
  147. package/dist/providers/google-vertex-chat.d.ts +3 -3
  148. package/dist/providers/google-vertex-chat.js +3 -29
  149. package/dist/providers/google-vertex-interactions.d.ts +3 -3
  150. package/dist/providers/google-vertex-messages.d.ts +3 -3
  151. package/dist/providers/google-vertex-messages.js +3 -29
  152. package/dist/providers/google-vertex-mistral.d.ts +3 -3
  153. package/dist/providers/google-vertex-mistral.js +3 -29
  154. package/dist/providers/google-vertex-responses.d.ts +3 -3
  155. package/dist/providers/google-vertex-responses.js +4 -30
  156. package/dist/providers/google-vertex-shared.d.ts +31 -0
  157. package/dist/providers/google-vertex-shared.js +25 -0
  158. package/dist/providers/google-vertex.d.ts +3 -3
  159. package/dist/providers/google.d.ts +15 -13
  160. package/dist/providers/google.js +9 -19
  161. package/dist/providers/groq.d.ts +5 -5
  162. package/dist/providers/groq.js +4 -15
  163. package/dist/providers/meta.d.ts +5 -5
  164. package/dist/providers/meta.js +10 -23
  165. package/dist/providers/minimax/chat.js +2 -7
  166. package/dist/providers/minimax/responses.js +2 -7
  167. package/dist/providers/minimax.d.ts +5 -5
  168. package/dist/providers/minimax.js +7 -22
  169. package/dist/providers/mistral.d.ts +10 -11
  170. package/dist/providers/mistral.js +3 -14
  171. package/dist/providers/moonshot/messages.js +2 -7
  172. package/dist/providers/moonshot/responses.js +2 -7
  173. package/dist/providers/moonshot.d.ts +5 -5
  174. package/dist/providers/moonshot.js +4 -16
  175. package/dist/providers/openai-compatible-responses.d.ts +6 -7
  176. package/dist/providers/openai-compatible-responses.js +2 -8
  177. package/dist/providers/openai-compatible.d.ts +6 -7
  178. package/dist/providers/openai-compatible.js +4 -10
  179. package/dist/providers/openai.d.ts +4 -4
  180. package/dist/providers/openai.js +3 -3
  181. package/dist/providers/opencode.d.ts +4 -4
  182. package/dist/providers/opencode.js +6 -2
  183. package/dist/providers/openrouter.d.ts +8 -5
  184. package/dist/providers/openrouter.js +16 -24
  185. package/dist/providers/runway.d.ts +1 -1
  186. package/dist/providers/settings.d.ts +40 -0
  187. package/dist/providers/settings.js +19 -0
  188. package/dist/providers/togetherai.d.ts +5 -5
  189. package/dist/providers/togetherai.js +5 -15
  190. package/dist/providers/typesafe-ai.d.ts +4 -4
  191. package/dist/providers/typesafe-ai.js +6 -2
  192. package/dist/providers/venice.d.ts +4 -4
  193. package/dist/providers/venice.js +6 -2
  194. package/dist/providers/vercel-ai-gateway.d.ts +5 -5
  195. package/dist/providers/vercel-ai-gateway.js +15 -28
  196. package/dist/providers/xai.d.ts +4 -4
  197. package/dist/providers/xai.js +4 -12
  198. package/dist/providers/zai-coding-plan/messages.js +2 -7
  199. package/dist/providers/zai-coding-plan/responses.js +2 -7
  200. package/dist/providers/zai-coding-plan.d.ts +5 -5
  201. package/dist/providers/zai-coding-plan.js +8 -15
  202. package/dist/providers/zai.d.ts +5 -5
  203. package/dist/providers/zai.js +10 -22
  204. package/dist/public.d.ts +12 -0
  205. package/dist/public.js +5 -0
  206. package/dist/route/auth-options.d.ts +9 -5
  207. package/dist/route/auth-options.js +10 -7
  208. package/dist/route/client.d.ts +50 -37
  209. package/dist/route/client.js +42 -53
  210. package/dist/route/decision.d.ts +8 -8
  211. package/dist/route/decision.js +3 -3
  212. package/dist/route/executor.d.ts +5 -0
  213. package/dist/route/executor.js +10 -0
  214. package/dist/route/index.d.ts +5 -7
  215. package/dist/route/index.js +1 -1
  216. package/dist/route/media.d.ts +7 -11
  217. package/dist/route/media.js +22 -26
  218. package/dist/route/transport/http.js +6 -5
  219. package/dist/route/transport/websocket.js +7 -1
  220. package/dist/schema/errors.d.ts +16 -17
  221. package/dist/schema/errors.js +63 -12
  222. package/dist/schema/events.d.ts +2563 -2954
  223. package/dist/schema/events.js +54 -109
  224. package/dist/schema/messages.d.ts +194 -137
  225. package/dist/schema/messages.js +66 -83
  226. package/dist/schema/options.d.ts +112 -65
  227. package/dist/schema/options.js +52 -101
  228. package/dist/speech-client.d.ts +7 -7
  229. package/dist/speech.d.ts +306 -316
  230. package/dist/speech.js +16 -14
  231. package/dist/testing.d.ts +31 -175
  232. package/dist/testing.js +60 -5
  233. package/dist/tool-history.d.ts +1 -1
  234. package/dist/tool-history.js +3 -10
  235. package/dist/tool-runtime.d.ts +9 -2
  236. package/dist/tool-runtime.js +17 -31
  237. package/dist/tool.d.ts +39 -43
  238. package/dist/tool.js +16 -26
  239. package/dist/transcription-client.d.ts +7 -7
  240. package/dist/transcription.d.ts +314 -265
  241. package/dist/transcription.js +16 -14
  242. package/dist/utils/provider-codes.d.ts +3 -0
  243. package/dist/utils/provider-codes.js +41 -0
  244. package/dist/video-client.d.ts +7 -7
  245. package/dist/video-client.js +1 -1
  246. package/dist/video.d.ts +269 -287
  247. package/dist/video.js +16 -14
  248. package/package.json +9 -9
  249. package/dist/experimental/testing.d.ts +0 -3
  250. package/dist/experimental/testing.js +0 -3
  251. package/dist/testing/decision.d.ts +0 -16
  252. package/dist/testing/decision.js +0 -20
  253. package/dist/testing/image.d.ts +0 -14
  254. package/dist/testing/image.js +0 -12
  255. package/dist/testing/media.d.ts +0 -18
  256. package/dist/testing/media.js +0 -36
  257. package/dist/testing/script.d.ts +0 -28
  258. package/dist/testing/script.js +0 -60
  259. package/dist/testing/speech.d.ts +0 -14
  260. package/dist/testing/speech.js +0 -12
  261. package/dist/testing/transcription.d.ts +0 -14
  262. package/dist/testing/transcription.js +0 -12
  263. package/dist/testing/video.d.ts +0 -14
  264. package/dist/testing/video.js +0 -12
@@ -70,238 +70,12 @@ export declare const appendExisting: <K extends StreamKey>(route: string, tools:
70
70
  * from state, and reject malformed local arguments without repairing them.
71
71
  * Missing keys are a no-op because some providers emit stop events for
72
72
  * non-tool content blocks.
73
- */
74
- export declare const finish: <K extends StreamKey>(route: string, tools: State<K>, key: K) => Effect.Effect<{
75
- tools: Partial<Record<K, PendingTool>>;
76
- events?: undefined;
77
- } | {
78
- tools: Partial<Record<K, PendingTool>>;
79
- events: readonly ({
80
- readonly type: "step-start";
81
- readonly index: number;
82
- } | {
83
- readonly type: "raw";
84
- readonly data: unknown;
85
- } | {
86
- readonly type: "text-start";
87
- readonly id: string;
88
- readonly providerMetadata?: {
89
- readonly [x: string]: {
90
- readonly [x: string]: unknown;
91
- };
92
- } | undefined;
93
- } | {
94
- readonly type: "text-delta";
95
- readonly id: string;
96
- readonly text: string;
97
- readonly providerMetadata?: {
98
- readonly [x: string]: {
99
- readonly [x: string]: unknown;
100
- };
101
- } | undefined;
102
- } | {
103
- readonly type: "text-end";
104
- readonly id: string;
105
- readonly text?: string | undefined;
106
- readonly providerMetadata?: {
107
- readonly [x: string]: {
108
- readonly [x: string]: unknown;
109
- };
110
- } | undefined;
111
- } | {
112
- readonly type: "reasoning-start";
113
- readonly id: string;
114
- readonly providerMetadata?: {
115
- readonly [x: string]: {
116
- readonly [x: string]: unknown;
117
- };
118
- } | undefined;
119
- } | {
120
- readonly type: "reasoning-delta";
121
- readonly id: string;
122
- readonly text: string;
123
- readonly providerMetadata?: {
124
- readonly [x: string]: {
125
- readonly [x: string]: unknown;
126
- };
127
- } | undefined;
128
- } | {
129
- readonly type: "reasoning-end";
130
- readonly id: string;
131
- readonly text?: string | undefined;
132
- readonly providerMetadata?: {
133
- readonly [x: string]: {
134
- readonly [x: string]: unknown;
135
- };
136
- } | undefined;
137
- } | {
138
- readonly type: "tool-input-start";
139
- readonly id: string;
140
- readonly name: string;
141
- readonly namespace?: string | undefined;
142
- readonly providerExecuted?: boolean | undefined;
143
- readonly providerMetadata?: {
144
- readonly [x: string]: {
145
- readonly [x: string]: unknown;
146
- };
147
- } | undefined;
148
- } | {
149
- readonly type: "tool-input-delta";
150
- readonly id: string;
151
- readonly name: string;
152
- readonly namespace?: string | undefined;
153
- readonly text: string;
154
- readonly input?: unknown;
155
- } | {
156
- readonly type: "tool-input-end";
157
- readonly id: string;
158
- readonly name: string;
159
- readonly namespace?: string | undefined;
160
- readonly providerMetadata?: {
161
- readonly [x: string]: {
162
- readonly [x: string]: unknown;
163
- };
164
- } | undefined;
165
- } | {
166
- readonly type: "tool-input-error";
167
- readonly id: string;
168
- readonly name: string;
169
- readonly namespace?: string | undefined;
170
- readonly raw: string;
171
- } | {
172
- readonly type: "tool-call";
173
- readonly id: string;
174
- readonly name: string;
175
- readonly namespace?: string | undefined;
176
- readonly input: unknown;
177
- readonly providerExecuted?: boolean | undefined;
178
- readonly providerMetadata?: {
179
- readonly [x: string]: {
180
- readonly [x: string]: unknown;
181
- };
182
- } | undefined;
183
- } | {
184
- readonly type: "tool-result";
185
- readonly id: string;
186
- readonly name: string;
187
- readonly namespace?: string | undefined;
188
- readonly result: {
189
- readonly type: "json";
190
- readonly value: unknown;
191
- } | {
192
- readonly type: "text";
193
- readonly value: unknown;
194
- } | {
195
- readonly type: "error";
196
- readonly value: unknown;
197
- } | {
198
- readonly type: "content";
199
- readonly value: readonly ({
200
- readonly type: "text";
201
- readonly text: string;
202
- } | {
203
- readonly type: "file";
204
- readonly uri: string;
205
- readonly mime: string;
206
- readonly name?: string | undefined;
207
- })[];
208
- };
209
- readonly output?: {
210
- readonly structured: unknown;
211
- readonly content: readonly ({
212
- readonly type: "text";
213
- readonly text: string;
214
- } | {
215
- readonly type: "file";
216
- readonly uri: string;
217
- readonly mime: string;
218
- readonly name?: string | undefined;
219
- })[];
220
- } | undefined;
221
- readonly providerExecuted?: boolean | undefined;
222
- readonly providerMetadata?: {
223
- readonly [x: string]: {
224
- readonly [x: string]: unknown;
225
- };
226
- } | undefined;
227
- } | {
228
- readonly type: "tool-error";
229
- readonly id: string;
230
- readonly name: string;
231
- readonly namespace?: string | undefined;
232
- readonly message: string;
233
- readonly error?: unknown;
234
- readonly providerMetadata?: {
235
- readonly [x: string]: {
236
- readonly [x: string]: unknown;
237
- };
238
- } | undefined;
239
- } | {
240
- readonly type: "step-finish";
241
- readonly index: number;
242
- readonly reason: {
243
- readonly normalized: "content-filter" | "error" | "length" | "stop" | "tool-calls" | "unknown";
244
- readonly raw?: string | undefined;
245
- readonly category?: string | undefined;
246
- readonly explanation?: string | undefined;
247
- };
248
- readonly usage?: import("../../schema/events.js").Usage | undefined;
249
- readonly providerMetadata?: {
250
- readonly [x: string]: {
251
- readonly [x: string]: unknown;
252
- };
253
- } | undefined;
254
- } | {
255
- readonly type: "finish";
256
- readonly reason: {
257
- readonly normalized: "content-filter" | "error" | "length" | "stop" | "tool-calls" | "unknown";
258
- readonly raw?: string | undefined;
259
- readonly category?: string | undefined;
260
- readonly explanation?: string | undefined;
261
- };
262
- readonly usage?: import("../../schema/events.js").Usage | undefined;
263
- readonly providerMetadata?: {
264
- readonly [x: string]: {
265
- readonly [x: string]: unknown;
266
- };
267
- } | undefined;
268
- } | {
269
- readonly type: "media";
270
- readonly media: import("../../media.js").Asset;
271
- readonly providerMetadata?: {
272
- readonly [x: string]: {
273
- readonly [x: string]: unknown;
274
- };
275
- } | undefined;
276
- } | {
277
- readonly type: "provider-error";
278
- readonly message: string;
279
- readonly classification?: "context-overflow" | "payload-too-large" | undefined;
280
- readonly providerMetadata?: {
281
- readonly [x: string]: {
282
- readonly [x: string]: unknown;
283
- };
284
- } | undefined;
285
- } | ({
286
- readonly type: "compaction";
287
- readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
288
- readonly id?: string | undefined;
289
- readonly encrypted?: string | undefined;
290
- readonly text?: string | null | undefined;
291
- } & ({
292
- readonly encrypted: string;
293
- readonly text?: never;
294
- } | {
295
- readonly text: string | null;
296
- readonly encrypted?: never;
297
- })))[];
298
- }, AIError, never>;
299
- /**
300
- * Finalize one pending tool call with an authoritative final input string.
73
+ *
74
+ * Pass `input` when the provider sends an authoritative final input string.
301
75
  * OpenAI Responses can send accumulated deltas and then repeat the completed
302
76
  * arguments on `response.output_item.done`; the final value wins.
303
77
  */
304
- export declare const finishWithInput: <K extends StreamKey>(route: string, tools: State<K>, key: K, input: string) => Effect.Effect<{
78
+ export declare const finish: <K extends StreamKey>(route: string, tools: State<K>, key: K, input?: string) => Effect.Effect<{
305
79
  tools: Partial<Record<K, PendingTool>>;
306
80
  events?: undefined;
307
81
  } | {
@@ -454,18 +228,6 @@ export declare const finishWithInput: <K extends StreamKey>(route: string, tools
454
228
  readonly [x: string]: unknown;
455
229
  };
456
230
  } | undefined;
457
- } | {
458
- readonly type: "tool-error";
459
- readonly id: string;
460
- readonly name: string;
461
- readonly namespace?: string | undefined;
462
- readonly message: string;
463
- readonly error?: unknown;
464
- readonly providerMetadata?: {
465
- readonly [x: string]: {
466
- readonly [x: string]: unknown;
467
- };
468
- } | undefined;
469
231
  } | {
470
232
  readonly type: "step-finish";
471
233
  readonly index: number;
@@ -490,6 +252,7 @@ export declare const finishWithInput: <K extends StreamKey>(route: string, tools
490
252
  readonly explanation?: string | undefined;
491
253
  };
492
254
  readonly usage?: import("../../schema/events.js").Usage | undefined;
255
+ readonly message?: import("../../schema/messages.js").AssistantMessage | undefined;
493
256
  readonly providerMetadata?: {
494
257
  readonly [x: string]: {
495
258
  readonly [x: string]: unknown;
@@ -503,15 +266,6 @@ export declare const finishWithInput: <K extends StreamKey>(route: string, tools
503
266
  readonly [x: string]: unknown;
504
267
  };
505
268
  } | undefined;
506
- } | {
507
- readonly type: "provider-error";
508
- readonly message: string;
509
- readonly classification?: "context-overflow" | "payload-too-large" | undefined;
510
- readonly providerMetadata?: {
511
- readonly [x: string]: {
512
- readonly [x: string]: unknown;
513
- };
514
- } | undefined;
515
269
  } | ({
516
270
  readonly type: "compaction";
517
271
  readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -681,18 +435,6 @@ export declare const finishAll: <K extends StreamKey>(route: string, tools: Stat
681
435
  readonly [x: string]: unknown;
682
436
  };
683
437
  } | undefined;
684
- } | {
685
- readonly type: "tool-error";
686
- readonly id: string;
687
- readonly name: string;
688
- readonly namespace?: string | undefined;
689
- readonly message: string;
690
- readonly error?: unknown;
691
- readonly providerMetadata?: {
692
- readonly [x: string]: {
693
- readonly [x: string]: unknown;
694
- };
695
- } | undefined;
696
438
  } | {
697
439
  readonly type: "step-finish";
698
440
  readonly index: number;
@@ -717,6 +459,7 @@ export declare const finishAll: <K extends StreamKey>(route: string, tools: Stat
717
459
  readonly explanation?: string | undefined;
718
460
  };
719
461
  readonly usage?: import("../../schema/events.js").Usage | undefined;
462
+ readonly message?: import("../../schema/messages.js").AssistantMessage | undefined;
720
463
  readonly providerMetadata?: {
721
464
  readonly [x: string]: {
722
465
  readonly [x: string]: unknown;
@@ -730,15 +473,6 @@ export declare const finishAll: <K extends StreamKey>(route: string, tools: Stat
730
473
  readonly [x: string]: unknown;
731
474
  };
732
475
  } | undefined;
733
- } | {
734
- readonly type: "provider-error";
735
- readonly message: string;
736
- readonly classification?: "context-overflow" | "payload-too-large" | undefined;
737
- readonly providerMetadata?: {
738
- readonly [x: string]: {
739
- readonly [x: string]: unknown;
740
- };
741
- } | undefined;
742
476
  } | ({
743
477
  readonly type: "compaction";
744
478
  readonly provider: string & import("effect/Brand").Brand<"AI.ProviderID">;
@@ -124,22 +124,12 @@ export const appendExisting = (route, tools, key, text, missingToolMessage) => a
124
124
  * from state, and reject malformed local arguments without repairing them.
125
125
  * Missing keys are a no-op because some providers emit stop events for
126
126
  * non-tool content blocks.
127
- */
128
- export const finish = (route, tools, key) => Effect.gen(function* () {
129
- const tool = tools[key];
130
- if (!tool)
131
- return { tools };
132
- return {
133
- tools: withoutTool(tools, key),
134
- events: finishEvents(tool, yield* toolCall(route, tool)),
135
- };
136
- });
137
- /**
138
- * Finalize one pending tool call with an authoritative final input string.
127
+ *
128
+ * Pass `input` when the provider sends an authoritative final input string.
139
129
  * OpenAI Responses can send accumulated deltas and then repeat the completed
140
130
  * arguments on `response.output_item.done`; the final value wins.
141
131
  */
142
- export const finishWithInput = (route, tools, key, input) => Effect.gen(function* () {
132
+ export const finish = (route, tools, key, input) => Effect.gen(function* () {
143
133
  const tool = tools[key];
144
134
  if (!tool)
145
135
  return { tools };
@@ -48,7 +48,9 @@ interface State {
48
48
  }
49
49
  export declare const compatibility: {
50
50
  maxTokensField: "max_completion_tokens";
51
- supportsPromptCacheKey: true;
51
+ };
52
+ export declare const capabilities: {
53
+ promptCacheKey: true;
52
54
  };
53
55
  export declare const protocol: Protocol<{
54
56
  readonly model: string;
@@ -1,6 +1,6 @@
1
1
  import { Effect, Schema } from "effect";
2
2
  import { Protocol } from "../route/protocol.js";
3
- import { AIError, LLMEvent } from "../schema/index.js";
3
+ import { AIError, LLMEvent, } from "../schema/index.js";
4
4
  import { classifyProviderFailure } from "../provider-error.js";
5
5
  import { OpenAIChat } from "./openai-chat.js";
6
6
  import { JsonObject, optionalArray, optionalNull, ProviderShared } from "./shared.js";
@@ -138,7 +138,7 @@ const fromRequest = Effect.fn("VeniceChat.fromRequest")(function* (request) {
138
138
  });
139
139
  return {
140
140
  ...body,
141
- max_completion_tokens: options.maxCompletionTokens ?? options.maxTokens ?? request.generation?.maxTokens,
141
+ max_completion_tokens: options.maxCompletionTokens ?? options.maxTokens ?? request.maxTokens,
142
142
  reasoning_effort: undefined,
143
143
  reasoning: options.reasoningEffort === undefined
144
144
  ? options.reasoning
@@ -153,7 +153,7 @@ const fromRequest = Effect.fn("VeniceChat.fromRequest")(function* (request) {
153
153
  prompt_cache_retention: options.promptCacheRetention ?? body.prompt_cache_retention,
154
154
  parallel_tool_calls: options.parallelToolCalls,
155
155
  min_p: options.minP,
156
- top_k: request.generation?.topK,
156
+ top_k: request.topK,
157
157
  repetition_penalty: options.repetitionPenalty,
158
158
  stop_token_ids: options.stopTokenIds,
159
159
  logprobs: options.logprobs,
@@ -261,8 +261,8 @@ const onHalt = Effect.fn("VeniceChat.onHalt")(function* (state) {
261
261
  });
262
262
  export const compatibility = {
263
263
  maxTokensField: "max_completion_tokens",
264
- supportsPromptCacheKey: true,
265
264
  };
265
+ export const capabilities = { promptCacheKey: true };
266
266
  export const protocol = Protocol.make({
267
267
  id: "venice-chat",
268
268
  body: { schema: Body, from: fromRequest },
@@ -1,4 +1,4 @@
1
- import { ImageModel, ImageResponse, type ImageRequestFor } from "../image.js";
1
+ import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
2
2
  import { MediaProtocol } from "../route/media-protocol.js";
3
3
  import { MediaRoute } from "../route/media.js";
4
4
  import { type OpenString } from "../schema/index.js";
@@ -11,7 +11,7 @@ export type XAIImageOptions = {
11
11
  readonly responseFormat?: OpenString<"url" | "b64_json">;
12
12
  readonly response_format?: OpenString<"url" | "b64_json">;
13
13
  } & Record<string, unknown>;
14
- export type Request = ImageRequestFor<XAIImageOptions>;
14
+ export type Request = ImageRequest<ImageModel<XAIImageOptions>>;
15
15
  /** xAI renders `1k` or `2k`; other tiers use the nearest one. */
16
16
  export declare const resolution: (request: {
17
17
  readonly resolution?: string;
@@ -59,31 +59,16 @@ const fromRequest = Effect.fn("XAIResponses.fromRequest")(function* (request) {
59
59
  ...body,
60
60
  presence_penalty: undefined,
61
61
  frequency_penalty: undefined,
62
- top_k: request.generation?.topK,
62
+ top_k: request.topK,
63
63
  min_p: options.minP,
64
64
  };
65
65
  });
66
+ // Grok speaks the standard Responses reasoning dialect (`reasoning_summary_text.*`,
67
+ // handled by the baseline); only its hosted tool vocabulary differs.
66
68
  const HOSTED_TOOLS = {
67
- web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
69
+ ...ResponsesHostedTools.common,
68
70
  x_search_call: { name: "x_search", input: (item) => item.action ?? {} },
69
- file_search_call: { name: "file_search", input: (item) => ({ queries: item.queries ?? [] }) },
70
- code_interpreter_call: {
71
- name: "code_interpreter",
72
- input: (item) => ({ code: item.code, container_id: item.container_id }),
73
- },
74
71
  image_generation_call: { name: "image_generation", input: () => ({}) },
75
- mcp_call: {
76
- name: "mcp",
77
- input: (item) => ({ server_label: item.server_label, name: item.name, arguments: item.arguments }),
78
- },
79
- };
80
- // Grok speaks the standard Responses reasoning dialect (`reasoning_summary_text.*`,
81
- // handled by the baseline); only its hosted tool vocabulary differs.
82
- const step = (state, input) => {
83
- const event = OpenResponses.normalize(state, input);
84
- if (event.type === "response.output_item.done" && event.item && ResponsesHostedTools.isItem(event.item, HOSTED_TOOLS))
85
- return ResponsesHostedTools.onDone(state, event.item, HOSTED_TOOLS);
86
- return OpenResponses.step(state, event);
87
72
  };
88
73
  export const protocol = Protocol.make({
89
74
  id: ADAPTER,
@@ -91,12 +76,7 @@ export const protocol = Protocol.make({
91
76
  schema: Body,
92
77
  from: fromRequest,
93
78
  },
94
- stream: {
95
- event: OpenResponses.protocol.stream.event,
96
- initial: (request) => OpenResponses.initial(request, adapter),
97
- step,
98
- terminal: OpenResponses.terminal,
99
- },
79
+ stream: ResponsesHostedTools.stream(adapter, HOSTED_TOOLS),
100
80
  });
101
81
  export const compact = ResponsesCompaction.make(adapter, (request) => OpenResponses.lowerTools(ProviderShared.flattenTools(request.tools), adapter, OpenAIFreeform.tools(request)));
102
82
  export * as XAIResponses from "./xai-responses.js";
@@ -1,7 +1,7 @@
1
1
  import { Schema } from "effect";
2
2
  import { MediaProtocol } from "../route/media-protocol.js";
3
3
  import { MediaRoute } from "../route/media.js";
4
- import { VideoModel, VideoResponse, type VideoRequestFor } from "../video.js";
4
+ import { VideoModel, VideoResponse, type VideoRequest } from "../video.js";
5
5
  export declare const DEFAULT_BASE_URL = "https://api.x.ai/v1";
6
6
  export declare const PATH = "/videos/generations";
7
7
  export declare const EDIT_PATH = "/videos/edits";
@@ -17,7 +17,7 @@ export type XAIVideoOptions = {
17
17
  readonly voice_id: string;
18
18
  }>;
19
19
  } & Record<string, unknown>;
20
- export type Request = VideoRequestFor<XAIVideoOptions>;
20
+ export type Request = VideoRequest<VideoModel<XAIVideoOptions>>;
21
21
  export declare const Token: Schema.Struct<{
22
22
  readonly requestID: Schema.String;
23
23
  }>;
@@ -21,10 +21,14 @@ declare const Options: Schema.Struct<{
21
21
  export type OptionsInput = typeof Options.Type;
22
22
  export declare const compatibility: {
23
23
  maxTokensField: "max_tokens";
24
- supportsStrictMode: false;
25
24
  reasoningField: string;
26
25
  zaiToolStream: false;
27
26
  };
27
+ export declare const capabilities: {
28
+ tools: {
29
+ strict: false;
30
+ };
31
+ };
28
32
  export declare const protocol: Protocol<{
29
33
  readonly model: string;
30
34
  readonly messages: readonly ({
@@ -44,10 +44,10 @@ const fromRequest = Effect.fn("ZAIChat.fromRequest")(function* (request) {
44
44
  });
45
45
  export const compatibility = {
46
46
  maxTokensField: "max_tokens",
47
- supportsStrictMode: false,
48
47
  reasoningField: "reasoning_content",
49
48
  zaiToolStream: false,
50
49
  };
50
+ export const capabilities = { tools: { strict: false } };
51
51
  export const protocol = Protocol.make({
52
52
  id: "zai-chat",
53
53
  body: { schema: Body, from: fromRequest },
@@ -1,4 +1,4 @@
1
- import { ImageModel, ImageResponse, type ImageRequestFor } from "../image.js";
1
+ import { ImageModel, ImageResponse, type ImageRequest } from "../image.js";
2
2
  import { MediaProtocol } from "../route/media-protocol.js";
3
3
  import { MediaRoute } from "../route/media.js";
4
4
  import { type OpenString } from "../schema/index.js";
@@ -11,7 +11,7 @@ export type ZAIImageOptions = {
11
11
  readonly quality?: OpenString<"hd" | "standard">;
12
12
  readonly userID?: string;
13
13
  } & Record<string, unknown>;
14
- export type Request = ImageRequestFor<ZAIImageOptions>;
14
+ export type Request = ImageRequest<ImageModel<ZAIImageOptions>>;
15
15
  export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
16
16
  export declare const model: (input: MediaRoute.ModelInput) => ImageModel<ZAIImageOptions>;
17
17
  export declare const ZAIImages: {
@@ -1,6 +1,5 @@
1
1
  import { Effect, Schema } from "effect";
2
2
  import { Protocol } from "../route/protocol.js";
3
- import { LLMRequest } from "../schema/index.js";
4
3
  import { AnthropicMessages } from "./anthropic-messages.js";
5
4
  import { ProviderShared } from "./shared.js";
6
5
  import { OpenResponsesOptions } from "./utils/open-responses-options.js";
@@ -15,9 +14,10 @@ const Body = Schema.Struct({
15
14
  const fromRequest = Effect.fn("ZAIMessages.fromRequest")(function* (request) {
16
15
  const options = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(request.providerOptions ?? {});
17
16
  // Z.AI accepts enabled thinking without Anthropic's mandatory token budget.
18
- const body = yield* AnthropicMessages.protocol.body.from(LLMRequest.update(request, {
17
+ const body = yield* AnthropicMessages.protocol.body.from({
18
+ ...request,
19
19
  providerOptions: { ...request.providerOptions, thinking: undefined },
20
- }));
20
+ });
21
21
  return { ...body, thinking: options.thinking };
22
22
  });
23
23
  export const protocol = Protocol.make({
@@ -1,6 +1,5 @@
1
1
  import { AIError, type HttpContext, type HttpRateLimitDetails } from "./schema/index.js";
2
2
  export declare const isContextOverflow: (message: string) => boolean;
3
- export declare const isPayloadTooLarge: (message: string) => boolean;
4
3
  export declare const isContextOverflowFailure: (failure: unknown) => boolean;
5
4
  /**
6
5
  * Whether a failed call may succeed when sent again: rate limits, provider-side failures, transport failures that did
@@ -1,7 +1,6 @@
1
1
  import { Option, Schema, SchemaGetter } from "effect";
2
- import { AuthenticationError, ContentPolicyError, InvalidRequestError, AIError, ProviderErrorEvent, ProviderInternalError, QuotaExceededError, RateLimitError, UnknownProviderError, } from "./schema/index.js";
3
- import { Json } from "./utils/json.js";
4
- import { isRecord } from "./utils/record.js";
2
+ import { AuthenticationError, ContentPolicyError, InvalidRequestError, AIError, ProviderInternalError, QuotaExceededError, RateLimitError, UnknownProviderError, } from "./schema/index.js";
3
+ import { awsErrorType, providerCodes } from "./utils/provider-codes.js";
5
4
  const patterns = [
6
5
  /prompt is too long/i,
7
6
  /input is too long for (?:the )?(?:requested|selected) model/i,
@@ -57,51 +56,15 @@ const exclusions = [
57
56
  ];
58
57
  export const isContextOverflow = (message) => !exclusions.some((pattern) => pattern.test(message)) &&
59
58
  (patterns.some((pattern) => pattern.test(message)) || /^4(?:00|13)\s*(status code)?\s*\(no body\)/i.test(message));
60
- export const isPayloadTooLarge = (message) => payloadPatterns.some((pattern) => pattern.test(message));
61
- export const isContextOverflowFailure = (failure) => failure instanceof AIError
62
- ? failure.reason._tag === "InvalidRequest" && failure.reason.classification === "context-overflow"
63
- : Schema.is(ProviderErrorEvent)(failure) && failure.classification === "context-overflow";
59
+ const isPayloadTooLarge = (message) => payloadPatterns.some((pattern) => pattern.test(message));
60
+ export const isContextOverflowFailure = (failure) => failure instanceof AIError &&
61
+ failure.reason._tag === "InvalidRequest" &&
62
+ failure.reason.classification === "context-overflow";
64
63
  /**
65
64
  * Whether a failed call may succeed when sent again: rate limits, provider-side failures, transport failures that did
66
65
  * not deliver an accepted write, and unrecognized failures. Callers decide which calls are safe to repeat.
67
66
  */
68
- export const isRetryable = (error) => {
69
- const override = error.reason.http?.headers["x-should-retry"];
70
- if (override === "true")
71
- return true;
72
- if (override === "false")
73
- return false;
74
- switch (error.reason._tag) {
75
- case "RateLimit":
76
- case "ProviderInternal":
77
- return true;
78
- // A WebSocket acknowledgment marks delivery accepted before model output may exist.
79
- // Read failures can still recover; the caller chooses retry versus continuation from durable output.
80
- case "Transport":
81
- return (error.reason.delivery !== "rejected" &&
82
- (error.reason.delivery !== "accepted" || error.reason.operation === "read"));
83
- case "InvalidProviderOutput":
84
- return error.reason.classification === "incomplete-stream";
85
- // Unrecognized failures retry: classification records affirmative
86
- // deterministic evidence, and transient failures are exactly the ones
87
- // that arrive in shapes no classifier anticipates.
88
- case "UnknownProvider":
89
- return true;
90
- case "Authentication":
91
- case "QuotaExceeded":
92
- case "ContentPolicy":
93
- case "InvalidRequest":
94
- case "UnsupportedOperation":
95
- case "NoRoute":
96
- case "Timeout":
97
- return false;
98
- default: {
99
- const exhaustive = error.reason;
100
- return exhaustive;
101
- }
102
- }
103
- };
104
- const decodeJson = Schema.decodeUnknownOption(Json);
67
+ export const isRetryable = (error) => error.isRetryable;
105
68
  // OpenCode Zen reports account caps as typed 429/402 errors that are not throttles.
106
69
  const QUOTA_CODES = new Set([
107
70
  "insufficient_quota",
@@ -251,39 +214,3 @@ export function classifyProviderFailure(input) {
251
214
  return new InvalidRequestError(details);
252
215
  return new UnknownProviderError(details);
253
216
  }
254
- function providerCodes(value) {
255
- const decoded = typeof value === "string" ? Option.getOrUndefined(decodeJson(value)) : value;
256
- if (!isRecord(decoded))
257
- return [];
258
- const error = isRecord(decoded.error) ? decoded.error : undefined;
259
- const inner = error && isRecord(error.innererror) ? error.innererror : undefined;
260
- const metadata = error && isRecord(error.metadata) ? error.metadata : undefined;
261
- const response = isRecord(decoded.response) ? decoded.response : undefined;
262
- const responseError = response && isRecord(response.error) ? response.error : undefined;
263
- const exception = isRecord(decoded.exception) ? decoded.exception : undefined;
264
- return [
265
- decoded.code,
266
- ...awsErrorType(decoded.__type),
267
- ...awsErrorType(decoded.code),
268
- decoded.error_type,
269
- error?.code,
270
- error?.type,
271
- error?.status,
272
- error?.error_type,
273
- // Google `google.rpc.ErrorInfo` details carry the specific reason.
274
- ...(Array.isArray(error?.details)
275
- ? error.details.map((detail) => (isRecord(detail) ? detail.reason : undefined))
276
- : []),
277
- inner?.code,
278
- metadata?.error_type,
279
- responseError?.code,
280
- response?.error_type,
281
- exception?.type,
282
- ].filter((value) => typeof value === "string");
283
- }
284
- // AWS restJson1 reports the modeled error in `X-Amzn-Errortype`, `__type` or `code`, possibly
285
- // namespaced (`ns#Name`) or suffixed (`Name:uri`). Keep the shape name only.
286
- // https://smithy.io/2.0/aws/protocols/aws-restjson1-protocol.html#operation-error-serialization
287
- function awsErrorType(value) {
288
- return typeof value === "string" ? [value.replace(/:.*/s, "").replace(/^[^#]*#/, "")] : [];
289
- }