@opencode/ai 2.2.5 → 2.2.7

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 (306) hide show
  1. package/README.md +228 -72
  2. package/dist/ai-client.d.ts +2 -2
  3. package/dist/ai-client.js +2 -1
  4. package/dist/cache-policy.d.ts +1 -1
  5. package/dist/cache-policy.js +16 -4
  6. package/dist/decision-client.d.ts +3 -3
  7. package/dist/decision.d.ts +30 -125
  8. package/dist/decision.js +27 -15
  9. package/dist/effect.d.ts +10 -15
  10. package/dist/effect.js +6 -6
  11. package/dist/effort-updates.d.ts +3 -3
  12. package/dist/effort-updates.js +2 -2
  13. package/dist/embedding-client.d.ts +21 -0
  14. package/dist/embedding-client.js +30 -0
  15. package/dist/embedding.d.ts +111 -0
  16. package/dist/embedding.js +75 -0
  17. package/dist/experimental/cloudflare-run-extraction.d.ts +7 -3
  18. package/dist/experimental/cloudflare-run-extraction.js +4 -1
  19. package/dist/experimental/extraction.d.ts +10 -40
  20. package/dist/experimental/extraction.js +14 -13
  21. package/dist/experimental.d.ts +8 -8
  22. package/dist/experimental.js +4 -4
  23. package/dist/generation.d.ts +0 -2
  24. package/dist/generation.js +2 -2
  25. package/dist/image-client.d.ts +13 -7
  26. package/dist/image-client.js +1 -1
  27. package/dist/image.d.ts +357 -465
  28. package/dist/image.js +17 -18
  29. package/dist/index.d.ts +35 -467
  30. package/dist/index.js +23 -17
  31. package/dist/llm.d.ts +65 -266
  32. package/dist/llm.js +101 -92
  33. package/dist/loop.d.ts +38 -0
  34. package/dist/loop.js +136 -0
  35. package/dist/media-model.d.ts +1 -1
  36. package/dist/media-model.js +8 -6
  37. package/dist/media.d.ts +9 -0
  38. package/dist/media.js +37 -2
  39. package/dist/protocols/alibaba-chat.d.ts +9 -1
  40. package/dist/protocols/alibaba-chat.js +3 -3
  41. package/dist/protocols/alibaba-images.d.ts +2 -2
  42. package/dist/protocols/alibaba-messages.js +3 -3
  43. package/dist/protocols/alibaba-responses.js +8 -20
  44. package/dist/protocols/anthropic-messages.d.ts +1 -1
  45. package/dist/protocols/anthropic-messages.js +57 -176
  46. package/dist/protocols/assemblyai-transcription.d.ts +2 -2
  47. package/dist/protocols/bedrock-converse.js +10 -16
  48. package/dist/protocols/cartesia-speech.d.ts +2 -2
  49. package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
  50. package/dist/protocols/cohere-chat.js +9 -12
  51. package/dist/protocols/deepgram-speech.d.ts +2 -2
  52. package/dist/protocols/deepgram-transcription.d.ts +2 -2
  53. package/dist/protocols/elevenlabs-speech.d.ts +2 -2
  54. package/dist/protocols/elevenlabs-transcription.d.ts +2 -2
  55. package/dist/protocols/gemini.d.ts +3 -0
  56. package/dist/protocols/gemini.js +54 -72
  57. package/dist/protocols/google-embed-content.d.ts +34 -0
  58. package/dist/protocols/google-embed-content.js +110 -0
  59. package/dist/protocols/google-images.d.ts +2 -2
  60. package/dist/protocols/google-interactions.d.ts +3 -4
  61. package/dist/protocols/google-interactions.js +44 -30
  62. package/dist/protocols/google-speech.d.ts +2 -2
  63. package/dist/protocols/google-transcription.d.ts +2 -2
  64. package/dist/protocols/google-vertex-predict-embeddings.d.ts +18 -0
  65. package/dist/protocols/google-vertex-predict-embeddings.js +74 -0
  66. package/dist/protocols/google-video.d.ts +2 -2
  67. package/dist/protocols/index.d.ts +3 -0
  68. package/dist/protocols/index.js +3 -0
  69. package/dist/protocols/meta-images.d.ts +2 -2
  70. package/dist/protocols/meta-responses.js +26 -23
  71. package/dist/protocols/minimax-images.d.ts +2 -2
  72. package/dist/protocols/mistral-chat.js +7 -10
  73. package/dist/protocols/open-responses-channel.js +6 -19
  74. package/dist/protocols/open-responses-continuation.d.ts +1 -5
  75. package/dist/protocols/open-responses-continuation.js +1 -3
  76. package/dist/protocols/open-responses.d.ts +2 -22
  77. package/dist/protocols/open-responses.js +41 -23
  78. package/dist/protocols/openai-chat.d.ts +27 -23
  79. package/dist/protocols/openai-chat.js +62 -57
  80. package/dist/protocols/openai-compatible-chat.d.ts +2 -1
  81. package/dist/protocols/openai-compatible-responses.d.ts +2 -2
  82. package/dist/protocols/openai-compatible-responses.js +1 -1
  83. package/dist/protocols/openai-decisions.js +15 -2
  84. package/dist/protocols/openai-embeddings.d.ts +16 -0
  85. package/dist/protocols/openai-embeddings.js +76 -0
  86. package/dist/protocols/openai-images.d.ts +2 -2
  87. package/dist/protocols/openai-responses.js +10 -29
  88. package/dist/protocols/openai-speech.d.ts +2 -2
  89. package/dist/protocols/openai-transcription.d.ts +2 -2
  90. package/dist/protocols/runway-video.d.ts +2 -2
  91. package/dist/protocols/shared.d.ts +14 -7
  92. package/dist/protocols/shared.js +40 -15
  93. package/dist/protocols/system-one.d.ts +4 -4
  94. package/dist/protocols/system-one.js +8 -1
  95. package/dist/protocols/utils/bedrock-cache.js +2 -5
  96. package/dist/protocols/utils/bedrock-media.d.ts +0 -3
  97. package/dist/protocols/utils/cache.d.ts +3 -0
  98. package/dist/protocols/utils/cache.js +15 -2
  99. package/dist/protocols/utils/image-sizing.d.ts +1 -1
  100. package/dist/protocols/utils/responses-checkpoint.js +1 -1
  101. package/dist/protocols/utils/responses-compaction.d.ts +1 -1
  102. package/dist/protocols/utils/responses-compaction.js +6 -5
  103. package/dist/protocols/utils/responses-hosted-tools.d.ts +97 -1
  104. package/dist/protocols/utils/responses-hosted-tools.js +31 -0
  105. package/dist/protocols/utils/tool-stream.d.ts +5 -271
  106. package/dist/protocols/utils/tool-stream.js +3 -13
  107. package/dist/protocols/venice-chat.d.ts +7 -1
  108. package/dist/protocols/venice-chat.js +4 -4
  109. package/dist/protocols/xai-images.d.ts +2 -2
  110. package/dist/protocols/xai-responses.js +5 -25
  111. package/dist/protocols/xai-video.d.ts +2 -2
  112. package/dist/protocols/zai-chat.d.ts +9 -1
  113. package/dist/protocols/zai-chat.js +1 -1
  114. package/dist/protocols/zai-images.d.ts +2 -2
  115. package/dist/protocols/zai-messages.js +3 -3
  116. package/dist/provider-error.d.ts +0 -1
  117. package/dist/provider-error.js +7 -80
  118. package/dist/providers/alibaba/embeddings.d.ts +2 -0
  119. package/dist/providers/alibaba/embeddings.js +1 -0
  120. package/dist/providers/alibaba.d.ts +70 -4
  121. package/dist/providers/alibaba.js +20 -2
  122. package/dist/providers/amazon-bedrock-mantle.d.ts +7 -3
  123. package/dist/providers/amazon-bedrock-mantle.js +6 -3
  124. package/dist/providers/amazon-bedrock.d.ts +6 -7
  125. package/dist/providers/amazon-bedrock.js +1 -1
  126. package/dist/providers/anthropic-compatible.d.ts +7 -8
  127. package/dist/providers/anthropic-compatible.js +2 -5
  128. package/dist/providers/anthropic.d.ts +8 -9
  129. package/dist/providers/anthropic.js +2 -7
  130. package/dist/providers/assemblyai.d.ts +2 -2
  131. package/dist/providers/assemblyai.js +2 -7
  132. package/dist/providers/azure/embeddings.d.ts +2 -0
  133. package/dist/providers/azure/embeddings.js +1 -0
  134. package/dist/providers/azure/messages.d.ts +2 -0
  135. package/dist/providers/azure/messages.js +1 -0
  136. package/dist/providers/azure.d.ts +325 -7
  137. package/dist/providers/azure.js +40 -9
  138. package/dist/providers/baseten.d.ts +7 -5
  139. package/dist/providers/baseten.js +7 -21
  140. package/dist/providers/cartesia.d.ts +1 -1
  141. package/dist/providers/cerebras.d.ts +7 -5
  142. package/dist/providers/cerebras.js +4 -15
  143. package/dist/providers/cloudflare-ai-gateway.d.ts +23 -13
  144. package/dist/providers/cloudflare-ai-gateway.js +28 -40
  145. package/dist/providers/cloudflare-shared.d.ts +9 -0
  146. package/dist/providers/cloudflare-shared.js +25 -0
  147. package/dist/providers/cloudflare-workers-ai.d.ts +6 -4
  148. package/dist/providers/cloudflare-workers-ai.js +4 -20
  149. package/dist/providers/cohere/chat.js +2 -7
  150. package/dist/providers/cohere/embeddings.d.ts +2 -0
  151. package/dist/providers/cohere/embeddings.js +1 -0
  152. package/dist/providers/cohere.d.ts +14 -5
  153. package/dist/providers/cohere.js +23 -13
  154. package/dist/providers/deepgram.d.ts +2 -2
  155. package/dist/providers/deepgram.js +2 -7
  156. package/dist/providers/deepinfra/embeddings.d.ts +2 -0
  157. package/dist/providers/deepinfra/embeddings.js +1 -0
  158. package/dist/providers/deepinfra.d.ts +10 -5
  159. package/dist/providers/deepinfra.js +20 -14
  160. package/dist/providers/deepseek.d.ts +7 -5
  161. package/dist/providers/deepseek.js +3 -14
  162. package/dist/providers/digitalocean/embeddings.d.ts +2 -0
  163. package/dist/providers/digitalocean/embeddings.js +1 -0
  164. package/dist/providers/digitalocean.d.ts +18 -5
  165. package/dist/providers/digitalocean.js +28 -14
  166. package/dist/providers/elevenlabs.d.ts +2 -2
  167. package/dist/providers/elevenlabs.js +2 -7
  168. package/dist/providers/fireworks/embeddings.d.ts +2 -0
  169. package/dist/providers/fireworks/embeddings.js +1 -0
  170. package/dist/providers/fireworks.d.ts +10 -5
  171. package/dist/providers/fireworks.js +17 -14
  172. package/dist/providers/google/embeddings.d.ts +2 -0
  173. package/dist/providers/google/embeddings.js +1 -0
  174. package/dist/providers/google/interactions.d.ts +1 -1
  175. package/dist/providers/google/interactions.js +2 -7
  176. package/dist/providers/google-vertex/embeddings.d.ts +2 -0
  177. package/dist/providers/google-vertex/embeddings.js +1 -0
  178. package/dist/providers/google-vertex-chat.d.ts +4 -3
  179. package/dist/providers/google-vertex-chat.js +3 -29
  180. package/dist/providers/google-vertex-interactions.d.ts +3 -3
  181. package/dist/providers/google-vertex-messages.d.ts +3 -3
  182. package/dist/providers/google-vertex-messages.js +3 -29
  183. package/dist/providers/google-vertex-mistral.d.ts +3 -3
  184. package/dist/providers/google-vertex-mistral.js +3 -29
  185. package/dist/providers/google-vertex-responses.d.ts +3 -3
  186. package/dist/providers/google-vertex-responses.js +4 -30
  187. package/dist/providers/google-vertex-shared.d.ts +31 -0
  188. package/dist/providers/google-vertex-shared.js +25 -0
  189. package/dist/providers/google-vertex.d.ts +10 -3
  190. package/dist/providers/google-vertex.js +52 -0
  191. package/dist/providers/google.d.ts +21 -13
  192. package/dist/providers/google.js +23 -19
  193. package/dist/providers/groq.d.ts +10 -5
  194. package/dist/providers/groq.js +4 -15
  195. package/dist/providers/meta.d.ts +6 -5
  196. package/dist/providers/meta.js +10 -23
  197. package/dist/providers/minimax/chat.js +2 -7
  198. package/dist/providers/minimax/responses.js +2 -7
  199. package/dist/providers/minimax.d.ts +6 -5
  200. package/dist/providers/minimax.js +7 -22
  201. package/dist/providers/mistral.d.ts +10 -11
  202. package/dist/providers/mistral.js +3 -14
  203. package/dist/providers/moonshot/messages.js +2 -7
  204. package/dist/providers/moonshot/responses.js +2 -7
  205. package/dist/providers/moonshot.d.ts +6 -5
  206. package/dist/providers/moonshot.js +4 -16
  207. package/dist/providers/openai/embeddings.d.ts +2 -0
  208. package/dist/providers/openai/embeddings.js +1 -0
  209. package/dist/providers/openai-compatible/embeddings.d.ts +2 -0
  210. package/dist/providers/openai-compatible/embeddings.js +1 -0
  211. package/dist/providers/openai-compatible-responses.d.ts +6 -7
  212. package/dist/providers/openai-compatible-responses.js +2 -8
  213. package/dist/providers/openai-compatible.d.ts +10 -7
  214. package/dist/providers/openai-compatible.js +17 -10
  215. package/dist/providers/openai.d.ts +11 -4
  216. package/dist/providers/openai.js +17 -3
  217. package/dist/providers/opencode.d.ts +4 -4
  218. package/dist/providers/opencode.js +6 -2
  219. package/dist/providers/openrouter/embeddings.d.ts +2 -0
  220. package/dist/providers/openrouter/embeddings.js +1 -0
  221. package/dist/providers/openrouter.d.ts +24 -5
  222. package/dist/providers/openrouter.js +31 -24
  223. package/dist/providers/runway.d.ts +1 -1
  224. package/dist/providers/settings.d.ts +40 -0
  225. package/dist/providers/settings.js +19 -0
  226. package/dist/providers/togetherai.d.ts +7 -5
  227. package/dist/providers/togetherai.js +5 -15
  228. package/dist/providers/typesafe-ai.d.ts +4 -4
  229. package/dist/providers/typesafe-ai.js +6 -2
  230. package/dist/providers/venice.d.ts +5 -4
  231. package/dist/providers/venice.js +6 -2
  232. package/dist/providers/vercel-ai-gateway/embeddings.d.ts +2 -0
  233. package/dist/providers/vercel-ai-gateway/embeddings.js +1 -0
  234. package/dist/providers/vercel-ai-gateway.d.ts +9 -5
  235. package/dist/providers/vercel-ai-gateway.js +30 -29
  236. package/dist/providers/xai.d.ts +5 -4
  237. package/dist/providers/xai.js +4 -12
  238. package/dist/providers/zai-coding-plan/messages.js +2 -7
  239. package/dist/providers/zai-coding-plan/responses.js +2 -7
  240. package/dist/providers/zai-coding-plan.d.ts +6 -5
  241. package/dist/providers/zai-coding-plan.js +8 -15
  242. package/dist/providers/zai.d.ts +6 -5
  243. package/dist/providers/zai.js +10 -22
  244. package/dist/public.d.ts +14 -0
  245. package/dist/public.js +6 -0
  246. package/dist/route/auth-options.d.ts +9 -5
  247. package/dist/route/auth-options.js +10 -7
  248. package/dist/route/client.d.ts +50 -37
  249. package/dist/route/client.js +42 -53
  250. package/dist/route/decision.d.ts +8 -8
  251. package/dist/route/decision.js +3 -3
  252. package/dist/route/embedding.d.ts +61 -0
  253. package/dist/route/embedding.js +88 -0
  254. package/dist/route/executor.d.ts +5 -0
  255. package/dist/route/executor.js +10 -0
  256. package/dist/route/index.d.ts +5 -7
  257. package/dist/route/index.js +1 -1
  258. package/dist/route/media.d.ts +7 -11
  259. package/dist/route/media.js +22 -26
  260. package/dist/route/transport/http.js +6 -5
  261. package/dist/route/transport/websocket.js +7 -1
  262. package/dist/schema/errors.d.ts +16 -17
  263. package/dist/schema/errors.js +63 -12
  264. package/dist/schema/events.d.ts +2563 -2954
  265. package/dist/schema/events.js +54 -109
  266. package/dist/schema/messages.d.ts +194 -137
  267. package/dist/schema/messages.js +66 -83
  268. package/dist/schema/options.d.ts +112 -65
  269. package/dist/schema/options.js +52 -101
  270. package/dist/speech-client.d.ts +7 -7
  271. package/dist/speech.d.ts +306 -316
  272. package/dist/speech.js +16 -14
  273. package/dist/testing.d.ts +31 -175
  274. package/dist/testing.js +60 -5
  275. package/dist/tool-history.d.ts +1 -1
  276. package/dist/tool-history.js +3 -10
  277. package/dist/tool-runtime.d.ts +9 -2
  278. package/dist/tool-runtime.js +17 -31
  279. package/dist/tool.d.ts +39 -43
  280. package/dist/tool.js +16 -26
  281. package/dist/transcription-client.d.ts +7 -7
  282. package/dist/transcription.d.ts +314 -265
  283. package/dist/transcription.js +16 -14
  284. package/dist/utils/provider-codes.d.ts +3 -0
  285. package/dist/utils/provider-codes.js +41 -0
  286. package/dist/video-client.d.ts +7 -7
  287. package/dist/video-client.js +1 -1
  288. package/dist/video.d.ts +269 -287
  289. package/dist/video.js +16 -14
  290. package/package.json +309 -257
  291. package/dist/experimental/testing.d.ts +0 -3
  292. package/dist/experimental/testing.js +0 -3
  293. package/dist/testing/decision.d.ts +0 -16
  294. package/dist/testing/decision.js +0 -20
  295. package/dist/testing/image.d.ts +0 -14
  296. package/dist/testing/image.js +0 -12
  297. package/dist/testing/media.d.ts +0 -18
  298. package/dist/testing/media.js +0 -36
  299. package/dist/testing/script.d.ts +0 -28
  300. package/dist/testing/script.js +0 -60
  301. package/dist/testing/speech.d.ts +0 -14
  302. package/dist/testing/speech.js +0 -12
  303. package/dist/testing/transcription.d.ts +0 -14
  304. package/dist/testing/transcription.js +0 -12
  305. package/dist/testing/video.d.ts +0 -14
  306. package/dist/testing/video.js +0 -12
@@ -1,5 +1,5 @@
1
1
  import { Effect } from "effect";
2
- import { type AIError, type ToolResultPart } from "../../schema/index.js";
2
+ import { type AIError, type LLMRequest, type ToolResultPart } from "../../schema/index.js";
3
3
  import { OpenResponses } from "../open-responses.js";
4
4
  export type Item = OpenResponses.OutputItem & {
5
5
  readonly status?: string;
@@ -21,6 +21,102 @@ export interface Definition {
21
21
  readonly result?: (item: Item) => Effect.Effect<ToolResultPart["result"], AIError>;
22
22
  }
23
23
  export type Definitions = Readonly<Record<string, Definition>>;
24
+ /** Hosted tools that several Responses providers report with the same item shape. */
25
+ export declare const common: {
26
+ readonly web_search_call: {
27
+ readonly name: "web_search";
28
+ readonly input: (item: Item) => {};
29
+ };
30
+ readonly file_search_call: {
31
+ readonly name: "file_search";
32
+ readonly input: (item: Item) => {
33
+ queries: {};
34
+ };
35
+ };
36
+ readonly code_interpreter_call: {
37
+ readonly name: "code_interpreter";
38
+ readonly input: (item: Item) => {
39
+ code: string | undefined;
40
+ container_id: string | undefined;
41
+ };
42
+ };
43
+ readonly mcp_call: {
44
+ readonly name: "mcp";
45
+ readonly input: (item: Item) => {
46
+ server_label: string | undefined;
47
+ name: string | undefined;
48
+ arguments: string | undefined;
49
+ };
50
+ };
51
+ };
24
52
  export declare const isItem: <Tools extends Definitions>(item: OpenResponses.OutputItem, tools: Tools) => item is Item;
53
+ /**
54
+ * Responses stream that turns completed hosted tool items into a provider-executed
55
+ * tool call and result. `override` sees each normalized event first and may handle it.
56
+ */
57
+ export declare const stream: (adapter: OpenResponses.ProviderAdapter, tools: Definitions, override?: (state: OpenResponses.ParserState, event: OpenResponses.NormalizedEvent) => Effect.Effect<OpenResponses.StepResult, AIError> | undefined) => {
58
+ event: import("effect/Schema").Codec<{
59
+ readonly [x: string]: unknown;
60
+ readonly type: string;
61
+ readonly delta?: string | undefined;
62
+ readonly arguments?: string | undefined;
63
+ readonly text?: string | undefined;
64
+ readonly item_id?: string | undefined;
65
+ readonly output_index?: number | undefined;
66
+ readonly summary_index?: number | undefined;
67
+ readonly item?: {
68
+ readonly [x: string]: unknown;
69
+ readonly type: string;
70
+ readonly id?: string | undefined;
71
+ readonly call_id?: string | undefined;
72
+ readonly name?: string | undefined;
73
+ readonly namespace?: string | undefined;
74
+ readonly arguments?: string | undefined;
75
+ readonly encrypted_content?: string | null | undefined;
76
+ } | null | undefined;
77
+ readonly response?: {
78
+ readonly [x: string]: unknown;
79
+ readonly id?: string | undefined;
80
+ readonly service_tier?: string | null | undefined;
81
+ readonly incomplete_details?: {
82
+ readonly reason?: string | undefined;
83
+ } | null | undefined;
84
+ readonly output?: readonly {
85
+ readonly [x: string]: unknown;
86
+ readonly type: string;
87
+ readonly id?: string | undefined;
88
+ readonly call_id?: string | undefined;
89
+ readonly name?: string | undefined;
90
+ readonly namespace?: string | undefined;
91
+ readonly arguments?: string | undefined;
92
+ readonly encrypted_content?: string | null | undefined;
93
+ }[] | undefined;
94
+ readonly usage?: {
95
+ readonly [x: string]: unknown;
96
+ readonly input_tokens?: number | undefined;
97
+ readonly input_tokens_details?: {
98
+ readonly [x: string]: unknown;
99
+ readonly cached_tokens?: number | undefined;
100
+ readonly cache_write_tokens?: number | undefined;
101
+ } | null | undefined;
102
+ readonly output_tokens?: number | undefined;
103
+ readonly output_tokens_details?: {
104
+ readonly [x: string]: unknown;
105
+ readonly reasoning_tokens?: number | undefined;
106
+ } | null | undefined;
107
+ readonly total_tokens?: number | undefined;
108
+ } | null | undefined;
109
+ readonly error?: unknown;
110
+ } | undefined;
111
+ readonly code?: unknown;
112
+ readonly message?: unknown;
113
+ readonly error?: unknown;
114
+ readonly status?: unknown;
115
+ readonly status_code?: unknown;
116
+ }, string, never, never>;
117
+ initial: (request: LLMRequest) => OpenResponses.ParserState;
118
+ step: (state: OpenResponses.ParserState, input: OpenResponses.Event) => AIError | Effect.Effect<OpenResponses.StepResult, AIError, never>;
119
+ terminal: typeof OpenResponses.terminal;
120
+ };
25
121
  export declare const onDone: (state: OpenResponses.ParserState, item: Item, tools: Definitions) => Effect.Effect<OpenResponses.StepResult, AIError>;
26
122
  export * as ResponsesHostedTools from "./responses-hosted-tools.js";
@@ -2,7 +2,38 @@ import { Effect } from "effect";
2
2
  import { LLMEvent } from "../../schema/index.js";
3
3
  import { OpenResponses } from "../open-responses.js";
4
4
  import { Lifecycle } from "./lifecycle.js";
5
+ /** Hosted tools that several Responses providers report with the same item shape. */
6
+ export const common = {
7
+ web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
8
+ file_search_call: { name: "file_search", input: (item) => ({ queries: item.queries ?? [] }) },
9
+ code_interpreter_call: {
10
+ name: "code_interpreter",
11
+ input: (item) => ({ code: item.code, container_id: item.container_id }),
12
+ },
13
+ mcp_call: {
14
+ name: "mcp",
15
+ input: (item) => ({ server_label: item.server_label, name: item.name, arguments: item.arguments }),
16
+ },
17
+ };
5
18
  export const isItem = (item, tools) => item.type in tools;
19
+ /**
20
+ * Responses stream that turns completed hosted tool items into a provider-executed
21
+ * tool call and result. `override` sees each normalized event first and may handle it.
22
+ */
23
+ export const stream = (adapter, tools, override) => ({
24
+ event: OpenResponses.protocol.stream.event,
25
+ initial: (request) => OpenResponses.initial(request, adapter),
26
+ step: (state, input) => {
27
+ const event = OpenResponses.normalize(state, input);
28
+ const handled = override?.(state, event);
29
+ if (handled)
30
+ return handled;
31
+ if (event.type === "response.output_item.done" && event.item && isItem(event.item, tools))
32
+ return onDone(state, event.item, tools);
33
+ return OpenResponses.step(state, event);
34
+ },
35
+ terminal: OpenResponses.terminal,
36
+ });
6
37
  export const onDone = Effect.fnUntraced(function* (state, item, tools) {
7
38
  const tool = tools[item.type];
8
39
  if (!tool)
@@ -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;
@@ -200,6 +202,7 @@ export declare const protocol: Protocol<{
200
202
  readonly reasoning?: string | undefined;
201
203
  readonly reasoning_text?: string | undefined;
202
204
  readonly reasoning_details?: unknown;
205
+ readonly reasoning_opaque?: string | undefined;
203
206
  readonly tool_calls?: readonly ({
204
207
  readonly id: string;
205
208
  readonly type: "custom";
@@ -260,6 +263,7 @@ export declare const protocol: Protocol<{
260
263
  readonly prompt_cache_hit_tokens?: number | null | undefined;
261
264
  readonly cache_read_input_tokens?: number | null | undefined;
262
265
  readonly cache_created_input_tokens?: number | null | undefined;
266
+ readonly reasoning_tokens?: number | null | undefined;
263
267
  readonly prompt_tokens_details?: {
264
268
  readonly [x: string]: unknown;
265
269
  readonly cached_tokens?: number | null | undefined;
@@ -280,6 +284,7 @@ export declare const protocol: Protocol<{
280
284
  readonly reasoning?: string | null | undefined;
281
285
  readonly reasoning_text?: string | null | undefined;
282
286
  readonly reasoning_details?: unknown;
287
+ readonly reasoning_opaque?: string | null | undefined;
283
288
  readonly tool_calls?: readonly {
284
289
  readonly index?: number | null | undefined;
285
290
  readonly id?: string | null | undefined;
@@ -306,6 +311,7 @@ export declare const protocol: Protocol<{
306
311
  readonly prompt_cache_hit_tokens?: number | null | undefined;
307
312
  readonly cache_read_input_tokens?: number | null | undefined;
308
313
  readonly cache_created_input_tokens?: number | null | undefined;
314
+ readonly reasoning_tokens?: number | null | undefined;
309
315
  readonly completion_tokens_details?: {
310
316
  readonly [x: string]: unknown;
311
317
  readonly reasoning_tokens?: number | null | undefined;
@@ -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
  }>;