@opencode/ai 2.2.0 → 2.2.2

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 (189) hide show
  1. package/README.md +66 -62
  2. package/dist/effect.d.ts +1 -1
  3. package/dist/effect.js +1 -1
  4. package/dist/image-client.d.ts +45 -0
  5. package/dist/image.d.ts +1 -0
  6. package/dist/index.d.ts +38 -20
  7. package/dist/index.js +14 -2
  8. package/dist/media-client.d.ts +1 -0
  9. package/dist/media-client.js +1 -0
  10. package/dist/protocols/alibaba-chat.d.ts +39 -4
  11. package/dist/protocols/alibaba-responses.d.ts +20 -3
  12. package/dist/protocols/google-images.js +3 -1
  13. package/dist/protocols/meta-responses.d.ts +40 -6
  14. package/dist/protocols/meta-responses.js +1 -1
  15. package/dist/protocols/minimax-images.d.ts +25 -0
  16. package/dist/protocols/minimax-images.js +150 -0
  17. package/dist/protocols/open-responses.d.ts +182 -27
  18. package/dist/protocols/open-responses.js +108 -36
  19. package/dist/protocols/openai-chat.d.ts +438 -46
  20. package/dist/protocols/openai-chat.js +121 -39
  21. package/dist/protocols/openai-compatible-chat.d.ts +35 -4
  22. package/dist/protocols/openai-compatible-responses.d.ts +20 -3
  23. package/dist/protocols/openai-freeform.d.ts +47 -0
  24. package/dist/protocols/openai-freeform.js +54 -0
  25. package/dist/protocols/openai-images.d.ts +16 -1
  26. package/dist/protocols/openai-images.js +49 -17
  27. package/dist/protocols/openai-responses.d.ts +120 -18
  28. package/dist/protocols/openai-responses.js +17 -8
  29. package/dist/protocols/venice-chat.d.ts +39 -4
  30. package/dist/protocols/venice-chat.js +1 -1
  31. package/dist/protocols/xai-images.d.ts +6 -0
  32. package/dist/protocols/xai-images.js +4 -5
  33. package/dist/protocols/xai-responses.d.ts +20 -3
  34. package/dist/protocols/xai-responses.js +2 -1
  35. package/dist/protocols/zai-chat.d.ts +39 -4
  36. package/dist/provider-error.js +5 -4
  37. package/dist/provider-package.d.ts +2 -0
  38. package/dist/providers/alibaba.d.ts +58 -10
  39. package/dist/providers/amazon-bedrock-mantle.d.ts +66 -11
  40. package/dist/providers/amazon-bedrock-mantle.js +1 -1
  41. package/dist/providers/amazon-bedrock.d.ts +1 -1
  42. package/dist/providers/amazon-bedrock.js +1 -1
  43. package/dist/providers/anthropic-compatible.d.ts +1 -1
  44. package/dist/providers/anthropic.d.ts +1 -1
  45. package/dist/providers/anthropic.js +1 -1
  46. package/dist/providers/azure.d.ts +79 -15
  47. package/dist/providers/baseten.d.ts +74 -12
  48. package/dist/providers/baseten.js +1 -1
  49. package/dist/providers/cerebras.d.ts +73 -11
  50. package/dist/providers/cerebras.js +1 -1
  51. package/dist/providers/cloudflare-ai-gateway.d.ts +113 -17
  52. package/dist/providers/cloudflare-workers-ai.d.ts +73 -11
  53. package/dist/providers/cohere/chat.d.ts +1 -1
  54. package/dist/providers/cohere/chat.js +1 -1
  55. package/dist/providers/cohere.d.ts +73 -11
  56. package/dist/providers/cohere.js +1 -1
  57. package/dist/providers/deepinfra.d.ts +73 -11
  58. package/dist/providers/deepinfra.js +1 -1
  59. package/dist/providers/deepseek.d.ts +73 -11
  60. package/dist/providers/deepseek.js +1 -1
  61. package/dist/providers/digitalocean/responses.d.ts +4 -0
  62. package/dist/providers/digitalocean/responses.js +1 -0
  63. package/dist/providers/digitalocean.d.ts +320 -21
  64. package/dist/providers/digitalocean.js +18 -7
  65. package/dist/providers/fireworks.d.ts +73 -11
  66. package/dist/providers/fireworks.js +1 -1
  67. package/dist/providers/google/interactions.d.ts +1 -1
  68. package/dist/providers/google/interactions.js +1 -1
  69. package/dist/providers/google-vertex-chat.d.ts +36 -5
  70. package/dist/providers/google-vertex-chat.js +1 -1
  71. package/dist/providers/google-vertex-interactions.d.ts +1 -1
  72. package/dist/providers/google-vertex-interactions.js +1 -1
  73. package/dist/providers/google-vertex-messages.d.ts +1 -1
  74. package/dist/providers/google-vertex-messages.js +1 -1
  75. package/dist/providers/google-vertex-mistral.d.ts +1 -1
  76. package/dist/providers/google-vertex-mistral.js +1 -1
  77. package/dist/providers/google-vertex-responses.d.ts +21 -4
  78. package/dist/providers/google-vertex-responses.js +1 -1
  79. package/dist/providers/google-vertex.d.ts +2 -2
  80. package/dist/providers/google-vertex.js +1 -1
  81. package/dist/providers/google.d.ts +2 -2
  82. package/dist/providers/google.js +1 -1
  83. package/dist/providers/groq.d.ts +77 -11
  84. package/dist/providers/groq.js +1 -1
  85. package/dist/providers/index.d.ts +0 -4
  86. package/dist/providers/index.js +0 -4
  87. package/dist/providers/meta/images.d.ts +2 -0
  88. package/dist/providers/meta/images.js +1 -0
  89. package/dist/providers/meta.d.ts +61 -12
  90. package/dist/providers/meta.js +2 -1
  91. package/dist/providers/minimax/chat.d.ts +1 -1
  92. package/dist/providers/minimax/chat.js +1 -1
  93. package/dist/providers/minimax/images.d.ts +3 -0
  94. package/dist/providers/minimax/images.js +1 -0
  95. package/dist/providers/minimax/responses.d.ts +1 -1
  96. package/dist/providers/minimax/responses.js +1 -1
  97. package/dist/providers/minimax.d.ts +63 -9
  98. package/dist/providers/minimax.js +22 -9
  99. package/dist/providers/mistral.d.ts +3 -3
  100. package/dist/providers/mistral.js +1 -1
  101. package/dist/providers/moonshot/messages.d.ts +1 -1
  102. package/dist/providers/moonshot/messages.js +1 -1
  103. package/dist/providers/moonshot/responses.d.ts +1 -1
  104. package/dist/providers/moonshot/responses.js +1 -1
  105. package/dist/providers/moonshot.d.ts +56 -8
  106. package/dist/providers/moonshot.js +1 -1
  107. package/dist/providers/openai-compatible-responses.d.ts +21 -4
  108. package/dist/providers/openai-compatible.d.ts +38 -7
  109. package/dist/providers/openai-compatible.js +9 -2
  110. package/dist/providers/openai.d.ts +59 -11
  111. package/dist/providers/openai.js +4 -2
  112. package/dist/providers/opencode.d.ts +3 -3
  113. package/dist/providers/opencode.js +1 -1
  114. package/dist/providers/openrouter/responses.d.ts +4 -0
  115. package/dist/providers/openrouter/responses.js +1 -0
  116. package/dist/providers/openrouter.d.ts +356 -26
  117. package/dist/providers/openrouter.js +42 -13
  118. package/dist/providers/togetherai.d.ts +73 -11
  119. package/dist/providers/togetherai.js +1 -1
  120. package/dist/providers/typesafe-ai.d.ts +3 -3
  121. package/dist/providers/typesafe-ai.js +1 -1
  122. package/dist/providers/venice/responses.d.ts +4 -0
  123. package/dist/providers/venice/responses.js +1 -0
  124. package/dist/providers/venice.d.ts +242 -9
  125. package/dist/providers/venice.js +33 -17
  126. package/dist/providers/vercel-ai-gateway.d.ts +8 -8
  127. package/dist/providers/vercel-ai-gateway.js +12 -2
  128. package/dist/providers/xai.d.ts +39 -8
  129. package/dist/providers/xai.js +1 -1
  130. package/dist/providers/zai-coding-plan/messages.d.ts +1 -1
  131. package/dist/providers/zai-coding-plan/messages.js +1 -1
  132. package/dist/providers/zai-coding-plan/responses.d.ts +1 -1
  133. package/dist/providers/zai-coding-plan/responses.js +1 -1
  134. package/dist/providers/zai-coding-plan.d.ts +56 -8
  135. package/dist/providers/zai-coding-plan.js +1 -1
  136. package/dist/providers/zai.d.ts +37 -6
  137. package/dist/providers/zai.js +1 -1
  138. package/dist/route/auth.d.ts +1 -1
  139. package/dist/route/media-protocol.d.ts +2 -4
  140. package/dist/route/media.d.ts +1 -1
  141. package/dist/route/media.js +2 -4
  142. package/dist/schema/events.d.ts +2 -0
  143. package/dist/schema/messages.d.ts +35 -1
  144. package/dist/schema/messages.js +20 -0
  145. package/dist/speech-client.d.ts +48 -0
  146. package/dist/speech.d.ts +1 -0
  147. package/dist/testing/decision.d.ts +16 -0
  148. package/dist/testing/decision.js +20 -0
  149. package/dist/testing/image.d.ts +14 -0
  150. package/dist/testing/image.js +12 -0
  151. package/dist/testing/media.d.ts +18 -0
  152. package/dist/testing/media.js +36 -0
  153. package/dist/testing/script.d.ts +28 -0
  154. package/dist/testing/script.js +60 -0
  155. package/dist/testing/speech.d.ts +14 -0
  156. package/dist/testing/speech.js +12 -0
  157. package/dist/testing/transcription.d.ts +14 -0
  158. package/dist/testing/transcription.js +12 -0
  159. package/dist/testing/video.d.ts +14 -0
  160. package/dist/testing/video.js +12 -0
  161. package/dist/testing.d.ts +10 -21
  162. package/dist/testing.js +11 -54
  163. package/dist/tool.d.ts +12 -1
  164. package/dist/tool.js +10 -2
  165. package/dist/transcription-client.d.ts +64 -0
  166. package/dist/transcription.d.ts +1 -0
  167. package/dist/video-client.d.ts +41 -0
  168. package/dist/video.d.ts +1 -0
  169. package/package.json +24 -40
  170. package/dist/protocols/bfl-images.d.ts +0 -47
  171. package/dist/protocols/bfl-images.js +0 -155
  172. package/dist/protocols/fal-images.d.ts +0 -34
  173. package/dist/protocols/fal-images.js +0 -95
  174. package/dist/protocols/fal-video.d.ts +0 -29
  175. package/dist/protocols/fal-video.js +0 -73
  176. package/dist/protocols/replicate-images.d.ts +0 -28
  177. package/dist/protocols/replicate-images.js +0 -127
  178. package/dist/protocols/stability-images.d.ts +0 -44
  179. package/dist/protocols/stability-images.js +0 -131
  180. package/dist/protocols/utils/fal-queue.d.ts +0 -26
  181. package/dist/protocols/utils/fal-queue.js +0 -67
  182. package/dist/providers/black-forest-labs.d.ts +0 -21
  183. package/dist/providers/black-forest-labs.js +0 -23
  184. package/dist/providers/fal.d.ts +0 -24
  185. package/dist/providers/fal.js +0 -26
  186. package/dist/providers/replicate.d.ts +0 -21
  187. package/dist/providers/replicate.js +0 -17
  188. package/dist/providers/stability.d.ts +0 -23
  189. package/dist/providers/stability.js +0 -18
@@ -31,7 +31,7 @@ const Settings = {
31
31
  background: Schema.optional(Schema.String),
32
32
  };
33
33
  const OpenAIImageResponse = Schema.Struct({
34
- // `response_format` picks `b64_json` or `url`; DALL·E and many compatible hosts default to `url`.
34
+ // GPT Image models always return `b64_json`; compatible hosts that default to `url` can return either.
35
35
  data: Schema.Array(Schema.Struct({ b64_json: optionalNull(Schema.String), url: optionalNull(Schema.String) })),
36
36
  ...Settings,
37
37
  usage: Schema.optional(Usage),
@@ -85,7 +85,13 @@ const nativeOptions = (options) => {
85
85
  if (!options)
86
86
  return undefined;
87
87
  const { outputCompression, outputFormat, partialImages: _, mask: __, ...native } = options;
88
- return { output_compression: outputCompression, output_format: outputFormat, ...native };
88
+ // `response_format: null` drops a provider's default, for hosts that reject the field.
89
+ return {
90
+ output_compression: outputCompression,
91
+ output_format: outputFormat,
92
+ ...native,
93
+ response_format: native.response_format ?? undefined,
94
+ };
89
95
  };
90
96
  /**
91
97
  * `gpt-image-1`, `chatgpt-image` and DALL·E take a fixed list, `gpt-image-2` and later any size within limits. Other
@@ -111,11 +117,12 @@ const sizes = (model) => {
111
117
  return { multiple: 16, maxEdge: 3840, minPixels: 655_360, maxPixels: 8_294_400, maxRatio: 3 };
112
118
  return { multiple: 16 };
113
119
  };
114
- const size = (request) => {
120
+ const pixelSize = (request) => {
115
121
  if (!ImageSizing.isRequested(request))
116
122
  return undefined;
117
123
  const options = sizes(request.model.id);
118
- return "multiple" in options ? ImageSizing.fit(request, options) : ImageSizing.nearest(request, options);
124
+ const size = "multiple" in options ? ImageSizing.fit(request, options) : ImageSizing.nearest(request, options);
125
+ return { size: `${size.width}x${size.height}` };
119
126
  };
120
127
  const streamOptions = (request) => {
121
128
  if (request.mode !== "stream")
@@ -127,21 +134,35 @@ const streamOptions = (request) => {
127
134
  const isEdit = (request) => (request.images?.length ?? 0) > 0;
128
135
  const isInline = (asset) => asset.source.type === "bytes" || asset.source.type === "base64";
129
136
  const reference = (asset, provider) => ProviderShared.mediaReference(asset, provider, route.name).pipe(Effect.map((item) => (item.type === "ref" ? { file_id: item.value } : { image_url: item.value })));
130
- const fromRequest = Effect.fn("OpenAIImages.fromRequest")(function* (request) {
137
+ const fromRequest = Effect.fn("OpenAIImages.fromRequest")(function* (request, options) {
131
138
  const images = request.images ?? [];
132
139
  const mask = request.providerOptions?.mask;
140
+ if (options.imageInput === "references" && mask !== undefined)
141
+ return yield* route.unsupported("media.mask", `${request.model.provider} image edits take no mask`);
133
142
  if (mask !== undefined && images.length === 0)
134
143
  return yield* ProviderShared.invalidRequest("An OpenAI image mask requires at least one input image");
135
144
  if (request.providerOptions?.size !== undefined && ImageSizing.isRequested(request))
136
145
  return yield* ProviderShared.invalidRequest("OpenAI providerOptions.size replaces aspect and resolution; set one or the other");
137
- const chosen = size(request);
138
146
  const fields = mergeJsonRecords({
139
147
  n: request.n,
140
- size: chosen === undefined ? undefined : `${chosen.width}x${chosen.height}`,
148
+ ...options.sizing(request),
141
149
  ...(yield* streamOptions(request)),
142
150
  }, nativeOptions(request.providerOptions), request.http?.body);
143
- // Owned bytes go through multipart edits; remote URLs and file IDs use the JSON edits body instead.
144
- if (images.length > 0 && images.every(isInline) && (mask === undefined || isInline(mask))) {
151
+ if (options.imageInput === "references") {
152
+ const references = yield* Effect.forEach(images, (image) => ProviderShared.mediaReference(image, undefined, route.name));
153
+ return MediaProtocol.json(mergeJsonRecords({
154
+ model: request.model.id,
155
+ prompt: request.prompt,
156
+ input_references: references.length === 0
157
+ ? undefined
158
+ : references.map((item) => ({ type: "image_url", image_url: { url: item.value } })),
159
+ }, fields) ?? {});
160
+ }
161
+ // Owned bytes go through multipart edits; remote URLs, file IDs and `json-edits` hosts use the JSON edits body.
162
+ if (options.imageInput === "edits" &&
163
+ images.length > 0 &&
164
+ images.every(isInline) &&
165
+ (mask === undefined || isInline(mask))) {
145
166
  const form = new FormData();
146
167
  MediaInput.appendFields(form, { model: request.model.id, prompt: request.prompt }, { overlay: fields, reserved: RESERVED_FORM_FIELDS });
147
168
  const uploads = yield* Effect.forEach(images, (image) => MediaInput.inlineBytes(route.id, image));
@@ -250,8 +271,8 @@ const finish = (state, context) => {
250
271
  // ---------------------------------------------------------------------------
251
272
  // 7. Protocol and route
252
273
  // ---------------------------------------------------------------------------
253
- export const protocol = MediaProtocol.stream(route, {
254
- body: { from: fromRequest },
274
+ const makeProtocol = (options) => MediaProtocol.stream(route, {
275
+ body: { from: (request) => fromRequest(request, options) },
255
276
  frames: (bytes, context) => context.request.mode === "stream"
256
277
  ? Framing.sse.frame(bytes)
257
278
  : Framing.document.frame(bytes).pipe(Stream.map((document) => ({ document }))),
@@ -259,13 +280,24 @@ export const protocol = MediaProtocol.stream(route, {
259
280
  step,
260
281
  finish,
261
282
  });
262
- /** `provider` attributes models, refs, and metadata to an OpenAI-compatible host; it defaults to `openai`. */
263
- export const model = (input) => ImageModel.fromRoute({
264
- protocol: input.provider === undefined ? protocol : { ...protocol, provider: ProviderID.make(input.provider) },
265
- baseURL: DEFAULT_BASE_URL,
266
- path: ({ request }) => (isEdit(request) ? EDIT_PATH : PATH),
267
- }, input);
283
+ export const protocol = makeProtocol({ sizing: pixelSize, imageInput: "edits" });
284
+ /**
285
+ * `provider` attributes models, refs, and metadata to an OpenAI-compatible host; it defaults to `openai`. `sizing`
286
+ * replaces the `size` that `aspect` and `resolution` lower to, and `imageInput` how input images are sent.
287
+ */
288
+ export const model = (input) => {
289
+ const imageInput = input.imageInput ?? "edits";
290
+ const base = input.sizing === undefined && imageInput === "edits"
291
+ ? protocol
292
+ : makeProtocol({ sizing: input.sizing ?? pixelSize, imageInput });
293
+ return ImageModel.fromRoute({
294
+ protocol: input.provider === undefined ? base : { ...base, provider: ProviderID.make(input.provider) },
295
+ baseURL: DEFAULT_BASE_URL,
296
+ path: ({ request }) => (imageInput !== "references" && isEdit(request) ? EDIT_PATH : PATH),
297
+ }, input);
298
+ };
268
299
  export const OpenAIImages = {
269
300
  protocol,
270
301
  model,
302
+ pixelSize,
271
303
  };
@@ -82,7 +82,7 @@ declare const OpenAIResponsesBody: Schema.Struct<{
82
82
  readonly namespace: Schema.optional<Schema.String>;
83
83
  readonly arguments: Schema.String;
84
84
  }>, Schema.Struct<{
85
- readonly type: Schema.tag<"function_call_output">;
85
+ readonly type: Schema.Literals<readonly ["function_call_output", "custom_tool_call_output"]>;
86
86
  readonly call_id: Schema.String;
87
87
  readonly output: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.Union<readonly [Schema.Struct<{
88
88
  readonly type: Schema.tag<"input_text">;
@@ -101,6 +101,12 @@ declare const OpenAIResponsesBody: Schema.Struct<{
101
101
  readonly type: Schema.tag<"input_video">;
102
102
  readonly video_url: Schema.String;
103
103
  }>]>>]>;
104
+ }>, Schema.Struct<{
105
+ readonly type: Schema.tag<"custom_tool_call">;
106
+ readonly id: Schema.optionalKey<Schema.String>;
107
+ readonly call_id: Schema.String;
108
+ readonly name: Schema.String;
109
+ readonly input: Schema.String;
104
110
  }>, Schema.Union<readonly [Schema.StructWithRest<Schema.Struct<{
105
111
  readonly type: Schema.tag<"web_search_call">;
106
112
  readonly id: Schema.String;
@@ -164,6 +170,17 @@ declare const OpenAIResponsesBody: Schema.Struct<{
164
170
  readonly description: Schema.String;
165
171
  readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
166
172
  readonly strict: Schema.optional<Schema.Boolean>;
173
+ }>, Schema.Struct<{
174
+ readonly type: Schema.tag<"custom">;
175
+ readonly name: Schema.String;
176
+ readonly description: Schema.String;
177
+ readonly format: Schema.Union<readonly [Schema.Struct<{
178
+ readonly type: Schema.tag<"text">;
179
+ }>, Schema.Struct<{
180
+ readonly type: Schema.tag<"grammar">;
181
+ readonly syntax: Schema.Literals<readonly ["lark", "regex"]>;
182
+ readonly definition: Schema.String;
183
+ }>]>;
167
184
  }>, Schema.Struct<{
168
185
  readonly type: Schema.tag<"namespace">;
169
186
  readonly name: Schema.String;
@@ -187,13 +204,13 @@ declare const OpenAIResponsesBody: Schema.Struct<{
187
204
  readonly size: Schema.optional<Schema.String>;
188
205
  }>]>>>;
189
206
  readonly tool_choice: Schema.optional<Schema.Union<readonly [Schema.Union<readonly [Schema.Literals<readonly ["auto", "none", "required"]>, Schema.Struct<{
190
- readonly type: Schema.tag<"function">;
207
+ readonly type: Schema.Literals<readonly ["function", "custom"]>;
191
208
  readonly name: Schema.String;
192
209
  }>, Schema.Struct<{
193
210
  readonly type: Schema.tag<"allowed_tools">;
194
211
  readonly mode: Schema.Literals<readonly ["auto", "none", "required"]>;
195
212
  readonly tools: Schema.$Array<Schema.Struct<{
196
- readonly type: Schema.tag<"function">;
213
+ readonly type: Schema.Literals<readonly ["function", "custom"]>;
197
214
  readonly name: Schema.String;
198
215
  }>>;
199
216
  }>]>, Schema.Struct<{
@@ -232,7 +249,7 @@ export declare const protocol: Protocol<{
232
249
  readonly role: "developer";
233
250
  readonly content: string;
234
251
  } | {
235
- readonly type: "function_call_output";
252
+ readonly type: "custom_tool_call_output" | "function_call_output";
236
253
  readonly call_id: string;
237
254
  readonly output: string | readonly ({
238
255
  readonly type: "input_text";
@@ -302,6 +319,12 @@ export declare const protocol: Protocol<{
302
319
  readonly name: string;
303
320
  readonly namespace?: string | undefined;
304
321
  readonly arguments: string;
322
+ } | {
323
+ readonly type: "custom_tool_call";
324
+ readonly id?: string | undefined;
325
+ readonly call_id: string;
326
+ readonly name: string;
327
+ readonly input: string;
305
328
  } | {
306
329
  readonly [x: string]: unknown;
307
330
  readonly type: "web_search_call";
@@ -373,6 +396,17 @@ export declare const protocol: Protocol<{
373
396
  readonly ttl?: string | undefined;
374
397
  } | undefined;
375
398
  readonly tools?: readonly ({
399
+ readonly type: "custom";
400
+ readonly name: string;
401
+ readonly description: string;
402
+ readonly format: {
403
+ readonly type: "text";
404
+ } | {
405
+ readonly type: "grammar";
406
+ readonly syntax: "lark" | "regex";
407
+ readonly definition: string;
408
+ };
409
+ } | {
376
410
  readonly type: "namespace";
377
411
  readonly name: string;
378
412
  readonly description: string;
@@ -405,13 +439,13 @@ export declare const protocol: Protocol<{
405
439
  readonly size?: string | undefined;
406
440
  })[] | undefined;
407
441
  readonly tool_choice?: "auto" | "none" | "required" | {
408
- readonly type: "function";
442
+ readonly type: "custom" | "function";
409
443
  readonly name: string;
410
444
  } | {
411
445
  readonly type: "allowed_tools";
412
446
  readonly mode: "auto" | "none" | "required";
413
447
  readonly tools: readonly {
414
- readonly type: "function";
448
+ readonly type: "custom" | "function";
415
449
  readonly name: string;
416
450
  }[];
417
451
  } | {
@@ -503,7 +537,7 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
503
537
  readonly role: "developer";
504
538
  readonly content: string;
505
539
  } | {
506
- readonly type: "function_call_output";
540
+ readonly type: "custom_tool_call_output" | "function_call_output";
507
541
  readonly call_id: string;
508
542
  readonly output: string | readonly ({
509
543
  readonly type: "input_text";
@@ -573,6 +607,12 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
573
607
  readonly name: string;
574
608
  readonly namespace?: string | undefined;
575
609
  readonly arguments: string;
610
+ } | {
611
+ readonly type: "custom_tool_call";
612
+ readonly id?: string | undefined;
613
+ readonly call_id: string;
614
+ readonly name: string;
615
+ readonly input: string;
576
616
  } | {
577
617
  readonly [x: string]: unknown;
578
618
  readonly type: "web_search_call";
@@ -644,6 +684,17 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
644
684
  readonly ttl?: string | undefined;
645
685
  } | undefined;
646
686
  readonly tools?: readonly ({
687
+ readonly type: "custom";
688
+ readonly name: string;
689
+ readonly description: string;
690
+ readonly format: {
691
+ readonly type: "text";
692
+ } | {
693
+ readonly type: "grammar";
694
+ readonly syntax: "lark" | "regex";
695
+ readonly definition: string;
696
+ };
697
+ } | {
647
698
  readonly type: "namespace";
648
699
  readonly name: string;
649
700
  readonly description: string;
@@ -676,13 +727,13 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
676
727
  readonly size?: string | undefined;
677
728
  })[] | undefined;
678
729
  readonly tool_choice?: "auto" | "none" | "required" | {
679
- readonly type: "function";
730
+ readonly type: "custom" | "function";
680
731
  readonly name: string;
681
732
  } | {
682
733
  readonly type: "allowed_tools";
683
734
  readonly mode: "auto" | "none" | "required";
684
735
  readonly tools: readonly {
685
- readonly type: "function";
736
+ readonly type: "custom" | "function";
686
737
  readonly name: string;
687
738
  }[];
688
739
  } | {
@@ -716,7 +767,7 @@ export declare const channelTransport: (options: import("./open-responses-channe
716
767
  readonly role: "developer";
717
768
  readonly content: string;
718
769
  } | {
719
- readonly type: "function_call_output";
770
+ readonly type: "custom_tool_call_output" | "function_call_output";
720
771
  readonly call_id: string;
721
772
  readonly output: string | readonly ({
722
773
  readonly type: "input_text";
@@ -786,6 +837,12 @@ export declare const channelTransport: (options: import("./open-responses-channe
786
837
  readonly name: string;
787
838
  readonly namespace?: string | undefined;
788
839
  readonly arguments: string;
840
+ } | {
841
+ readonly type: "custom_tool_call";
842
+ readonly id?: string | undefined;
843
+ readonly call_id: string;
844
+ readonly name: string;
845
+ readonly input: string;
789
846
  } | {
790
847
  readonly [x: string]: unknown;
791
848
  readonly type: "web_search_call";
@@ -857,6 +914,17 @@ export declare const channelTransport: (options: import("./open-responses-channe
857
914
  readonly ttl?: string | undefined;
858
915
  } | undefined;
859
916
  readonly tools?: readonly ({
917
+ readonly type: "custom";
918
+ readonly name: string;
919
+ readonly description: string;
920
+ readonly format: {
921
+ readonly type: "text";
922
+ } | {
923
+ readonly type: "grammar";
924
+ readonly syntax: "lark" | "regex";
925
+ readonly definition: string;
926
+ };
927
+ } | {
860
928
  readonly type: "namespace";
861
929
  readonly name: string;
862
930
  readonly description: string;
@@ -889,13 +957,13 @@ export declare const channelTransport: (options: import("./open-responses-channe
889
957
  readonly size?: string | undefined;
890
958
  })[] | undefined;
891
959
  readonly tool_choice?: "auto" | "none" | "required" | {
892
- readonly type: "function";
960
+ readonly type: "custom" | "function";
893
961
  readonly name: string;
894
962
  } | {
895
963
  readonly type: "allowed_tools";
896
964
  readonly mode: "auto" | "none" | "required";
897
965
  readonly tools: readonly {
898
- readonly type: "function";
966
+ readonly type: "custom" | "function";
899
967
  readonly name: string;
900
968
  }[];
901
969
  } | {
@@ -929,7 +997,7 @@ export declare const transport: import("../route/transport/index.js").Transport<
929
997
  readonly role: "developer";
930
998
  readonly content: string;
931
999
  } | {
932
- readonly type: "function_call_output";
1000
+ readonly type: "custom_tool_call_output" | "function_call_output";
933
1001
  readonly call_id: string;
934
1002
  readonly output: string | readonly ({
935
1003
  readonly type: "input_text";
@@ -999,6 +1067,12 @@ export declare const transport: import("../route/transport/index.js").Transport<
999
1067
  readonly name: string;
1000
1068
  readonly namespace?: string | undefined;
1001
1069
  readonly arguments: string;
1070
+ } | {
1071
+ readonly type: "custom_tool_call";
1072
+ readonly id?: string | undefined;
1073
+ readonly call_id: string;
1074
+ readonly name: string;
1075
+ readonly input: string;
1002
1076
  } | {
1003
1077
  readonly [x: string]: unknown;
1004
1078
  readonly type: "web_search_call";
@@ -1070,6 +1144,17 @@ export declare const transport: import("../route/transport/index.js").Transport<
1070
1144
  readonly ttl?: string | undefined;
1071
1145
  } | undefined;
1072
1146
  readonly tools?: readonly ({
1147
+ readonly type: "custom";
1148
+ readonly name: string;
1149
+ readonly description: string;
1150
+ readonly format: {
1151
+ readonly type: "text";
1152
+ } | {
1153
+ readonly type: "grammar";
1154
+ readonly syntax: "lark" | "regex";
1155
+ readonly definition: string;
1156
+ };
1157
+ } | {
1073
1158
  readonly type: "namespace";
1074
1159
  readonly name: string;
1075
1160
  readonly description: string;
@@ -1102,13 +1187,13 @@ export declare const transport: import("../route/transport/index.js").Transport<
1102
1187
  readonly size?: string | undefined;
1103
1188
  })[] | undefined;
1104
1189
  readonly tool_choice?: "auto" | "none" | "required" | {
1105
- readonly type: "function";
1190
+ readonly type: "custom" | "function";
1106
1191
  readonly name: string;
1107
1192
  } | {
1108
1193
  readonly type: "allowed_tools";
1109
1194
  readonly mode: "auto" | "none" | "required";
1110
1195
  readonly tools: readonly {
1111
- readonly type: "function";
1196
+ readonly type: "custom" | "function";
1112
1197
  readonly name: string;
1113
1198
  }[];
1114
1199
  } | {
@@ -1142,7 +1227,7 @@ export declare const route: Route<{
1142
1227
  readonly role: "developer";
1143
1228
  readonly content: string;
1144
1229
  } | {
1145
- readonly type: "function_call_output";
1230
+ readonly type: "custom_tool_call_output" | "function_call_output";
1146
1231
  readonly call_id: string;
1147
1232
  readonly output: string | readonly ({
1148
1233
  readonly type: "input_text";
@@ -1212,6 +1297,12 @@ export declare const route: Route<{
1212
1297
  readonly name: string;
1213
1298
  readonly namespace?: string | undefined;
1214
1299
  readonly arguments: string;
1300
+ } | {
1301
+ readonly type: "custom_tool_call";
1302
+ readonly id?: string | undefined;
1303
+ readonly call_id: string;
1304
+ readonly name: string;
1305
+ readonly input: string;
1215
1306
  } | {
1216
1307
  readonly [x: string]: unknown;
1217
1308
  readonly type: "web_search_call";
@@ -1283,6 +1374,17 @@ export declare const route: Route<{
1283
1374
  readonly ttl?: string | undefined;
1284
1375
  } | undefined;
1285
1376
  readonly tools?: readonly ({
1377
+ readonly type: "custom";
1378
+ readonly name: string;
1379
+ readonly description: string;
1380
+ readonly format: {
1381
+ readonly type: "text";
1382
+ } | {
1383
+ readonly type: "grammar";
1384
+ readonly syntax: "lark" | "regex";
1385
+ readonly definition: string;
1386
+ };
1387
+ } | {
1286
1388
  readonly type: "namespace";
1287
1389
  readonly name: string;
1288
1390
  readonly description: string;
@@ -1315,13 +1417,13 @@ export declare const route: Route<{
1315
1417
  readonly size?: string | undefined;
1316
1418
  })[] | undefined;
1317
1419
  readonly tool_choice?: "auto" | "none" | "required" | {
1318
- readonly type: "function";
1420
+ readonly type: "custom" | "function";
1319
1421
  readonly name: string;
1320
1422
  } | {
1321
1423
  readonly type: "allowed_tools";
1322
1424
  readonly mode: "auto" | "none" | "required";
1323
1425
  readonly tools: readonly {
1324
- readonly type: "function";
1426
+ readonly type: "custom" | "function";
1325
1427
  readonly name: string;
1326
1428
  }[];
1327
1429
  } | {
@@ -17,6 +17,7 @@ import { OpenResponsesChannel } from "./open-responses-channel.js";
17
17
  import { ResponsesCompaction } from "./utils/responses-compaction.js";
18
18
  import { ResponsesCheckpoint } from "./utils/responses-checkpoint.js";
19
19
  import * as Cache from "./utils/cache.js";
20
+ import { OpenAIFreeform } from "./openai-freeform.js";
20
21
  const ADAPTER = "openai-responses";
21
22
  const NAME = "OpenAI Responses";
22
23
  const WEBSOCKET_PROTOCOL_HEADER = "responses_websockets=2026-02-06";
@@ -83,6 +84,7 @@ const OpenAIResponsesNamespace = Schema.Struct({
83
84
  });
84
85
  const OpenAIResponsesTools = Schema.Union([
85
86
  OpenResponses.Tool,
87
+ OpenResponses.CustomTool,
86
88
  OpenAIResponsesNamespace,
87
89
  OpenAIResponsesImageGenerationTool,
88
90
  ]);
@@ -145,20 +147,23 @@ const nativeImageTool = (tool) => {
145
147
  const native = nativeImageToolInput(tool);
146
148
  return Schema.is(OpenAIResponsesImageGenerationTool)(native) ? native : undefined;
147
149
  };
148
- const lowerTool = Effect.fnUntraced(function* (tool) {
150
+ const lowerTool = Effect.fnUntraced(function* (tool, custom) {
149
151
  const native = nativeImageToolInput(tool);
150
152
  if (native !== undefined) {
151
153
  if (Schema.is(OpenAIResponsesImageGenerationTool)(native))
152
154
  return native;
153
155
  return yield* ProviderShared.invalidRequest("OpenAI Responses image generation tool options are invalid");
154
156
  }
157
+ const definition = custom.get(tool.name);
158
+ if (definition)
159
+ return OpenResponses.lowerCustomTool(tool, definition);
155
160
  return yield* OpenResponses.lowerTool(NAME, tool);
156
161
  });
157
162
  // Native namespaces hold only function tools, so deeper levels flatten into
158
163
  // the leaf names the same way non-native protocols flatten the whole tree.
159
- const lowerToolEntry = Effect.fnUntraced(function* (tool) {
164
+ const lowerToolEntry = Effect.fnUntraced(function* (tool, custom) {
160
165
  if (tool.type === "tool")
161
- return yield* lowerTool(tool);
166
+ return yield* lowerTool(tool, custom);
162
167
  // OpenAI requires a namespace description; fall back to a generic one so a
163
168
  // missing description never blocks the request.
164
169
  return {
@@ -168,14 +173,17 @@ const lowerToolEntry = Effect.fnUntraced(function* (tool) {
168
173
  tools: yield* Effect.forEach(ProviderShared.flattenTools(tool.tools), (leaf) => OpenResponses.lowerTool(NAME, leaf)),
169
174
  };
170
175
  });
171
- const lowerTools = (request) => Effect.forEach(request.tools, lowerToolEntry);
172
- const lowerToolChoice = (toolChoice, tools) => ProviderShared.matchToolChoice(NAME, toolChoice, {
176
+ const lowerTools = (request) => {
177
+ const custom = OpenAIFreeform.tools(request);
178
+ return Effect.forEach(request.tools, (tool) => lowerToolEntry(tool, custom));
179
+ };
180
+ const lowerToolChoice = (toolChoice, tools, custom) => ProviderShared.matchToolChoice(NAME, toolChoice, {
173
181
  auto: () => "auto",
174
182
  none: () => "none",
175
183
  required: () => "required",
176
184
  tool: (name) => tools.some((tool) => tool.type === "tool" && tool.name === name && nativeImageTool(tool) !== undefined)
177
185
  ? { type: "image_generation" }
178
- : { type: "function", name },
186
+ : OpenResponses.namedTool(name, custom),
179
187
  });
180
188
  const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request) {
181
189
  const management = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Schema.UndefinedOr(ContextManagement)))(request.providerOptions?.contextManagement);
@@ -183,6 +191,7 @@ const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request)
183
191
  const reasoning = Schema.decodeUnknownSync(ReasoningOptions)(request.providerOptions ?? {});
184
192
  const updates = resolveEffortUpdates(request, options.reasoningEffort);
185
193
  const generation = OpenResponses.lowerGeneration(request, { ...options, reasoningEffort: updates.effort });
194
+ const custom = OpenAIFreeform.tools(request);
186
195
  return {
187
196
  ...(yield* OpenResponses.lowerConversation(updates.request, adapter)),
188
197
  ...generation,
@@ -200,8 +209,8 @@ const fromRequest = Effect.fn("OpenAIResponses.fromRequest")(function* (request)
200
209
  tools: request.tools.length === 0 ? undefined : yield* lowerTools(request),
201
210
  tool_choice: request.tools.length === 0
202
211
  ? undefined
203
- : (OpenResponses.allowedToolChoice(request, options) ??
204
- (request.toolChoice ? yield* lowerToolChoice(request.toolChoice, request.tools) : undefined)),
212
+ : (OpenResponses.allowedToolChoice(options, custom) ??
213
+ (request.toolChoice ? yield* lowerToolChoice(request.toolChoice, request.tools, custom) : undefined)),
205
214
  };
206
215
  });
207
216
  const checkpointBody = {
@@ -52,7 +52,7 @@ export declare const compatibility: {
52
52
  };
53
53
  export declare const protocol: Protocol<{
54
54
  readonly model: string;
55
- readonly tools?: readonly {
55
+ readonly tools?: readonly ({
56
56
  readonly type: "function";
57
57
  readonly function: {
58
58
  readonly name: string;
@@ -66,12 +66,36 @@ export declare const protocol: Protocol<{
66
66
  readonly type: "ephemeral";
67
67
  readonly ttl?: string | undefined;
68
68
  } | undefined;
69
- }[] | undefined;
69
+ } | {
70
+ readonly type: "custom";
71
+ readonly custom: {
72
+ readonly name: string;
73
+ readonly description: string;
74
+ readonly format: {
75
+ readonly type: "text";
76
+ } | {
77
+ readonly type: "grammar";
78
+ readonly grammar: {
79
+ readonly syntax: "lark" | "regex";
80
+ readonly definition: string;
81
+ };
82
+ };
83
+ };
84
+ readonly cache_control?: {
85
+ readonly type: "ephemeral";
86
+ readonly ttl?: string | undefined;
87
+ } | undefined;
88
+ })[] | undefined;
70
89
  readonly tool_choice?: "auto" | "none" | "required" | {
71
90
  readonly type: "function";
72
91
  readonly function: {
73
92
  readonly name: string;
74
93
  };
94
+ } | {
95
+ readonly type: "custom";
96
+ readonly custom: {
97
+ readonly name: string;
98
+ };
75
99
  } | undefined;
76
100
  readonly stream: true;
77
101
  readonly stream_options?: {
@@ -176,7 +200,14 @@ export declare const protocol: Protocol<{
176
200
  readonly reasoning?: string | undefined;
177
201
  readonly reasoning_text?: string | undefined;
178
202
  readonly reasoning_details?: unknown;
179
- readonly tool_calls?: readonly {
203
+ readonly tool_calls?: readonly ({
204
+ readonly id: string;
205
+ readonly type: "custom";
206
+ readonly custom: {
207
+ readonly name: string;
208
+ readonly input: string;
209
+ };
210
+ } | {
180
211
  readonly id: string;
181
212
  readonly type: "function";
182
213
  readonly function: {
@@ -189,7 +220,7 @@ export declare const protocol: Protocol<{
189
220
  };
190
221
  } | undefined;
191
222
  readonly thought_signature?: string | undefined;
192
- }[] | undefined;
223
+ })[] | undefined;
193
224
  readonly thought_signature?: string | undefined;
194
225
  })[];
195
226
  readonly reasoning?: {
@@ -256,6 +287,10 @@ export declare const protocol: Protocol<{
256
287
  readonly name?: string | null | undefined;
257
288
  readonly arguments?: string | null | undefined;
258
289
  } | null | undefined;
290
+ readonly custom?: {
291
+ readonly name?: string | null | undefined;
292
+ readonly input?: string | null | undefined;
293
+ } | null | undefined;
259
294
  readonly extra_content?: unknown;
260
295
  readonly thought_signature?: string | null | undefined;
261
296
  }[] | null | undefined;
@@ -48,7 +48,7 @@ const ToolCall = Schema.Struct({
48
48
  });
49
49
  const Assistant = Schema.StructWithRest(Schema.Struct({
50
50
  ...OpenAIChat.OpenAIChatMessage.cases.assistant.schema.fields,
51
- tool_calls: optionalArray(ToolCall),
51
+ tool_calls: optionalArray(Schema.Union([ToolCall, OpenAIChat.OpenAIChatAssistantCustomToolCall])),
52
52
  thought_signature: Schema.optional(Schema.String),
53
53
  }), [JsonObject]);
54
54
  const Messages = Schema.Array(Schema.Union([
@@ -7,13 +7,19 @@ export declare const PATH = "/images/generations";
7
7
  export declare const EDIT_PATH = "/images/edits";
8
8
  /** Provider-native options. Common fields (`n`, `aspect`, `resolution`, `images`) live on the request. */
9
9
  export type XAIImageOptions = {
10
+ /** Defaults to `b64_json`; `url` returns a short-lived hosted URL instead. */
10
11
  readonly responseFormat?: OpenString<"url" | "b64_json">;
11
12
  readonly response_format?: OpenString<"url" | "b64_json">;
12
13
  } & Record<string, unknown>;
13
14
  export type Request = ImageRequestFor<XAIImageOptions>;
15
+ /** xAI renders `1k` or `2k`; other tiers use the nearest one. */
16
+ export declare const resolution: (request: {
17
+ readonly resolution?: string;
18
+ }) => "1k" | "2k" | undefined;
14
19
  export declare const protocol: MediaProtocol.Inline<Request, ImageResponse>;
15
20
  export declare const model: (input: MediaRoute.ModelInput) => ImageModel<XAIImageOptions>;
16
21
  export declare const XAIImages: {
17
22
  readonly protocol: MediaProtocol.Inline<Request, ImageResponse>;
18
23
  readonly model: typeof model;
24
+ readonly resolution: typeof resolution;
19
25
  };
@@ -27,13 +27,11 @@ const XAIImageResponse = Schema.Struct({
27
27
  // 5. Request body construction
28
28
  // ---------------------------------------------------------------------------
29
29
  const nativeOptions = (options) => {
30
- if (!options)
31
- return undefined;
32
- const { responseFormat, ...native } = options;
33
- return { response_format: responseFormat, ...native };
30
+ const { responseFormat, ...native } = options ?? {};
31
+ return { response_format: responseFormat ?? "b64_json", ...native };
34
32
  };
35
33
  /** xAI renders `1k` or `2k`; other tiers use the nearest one. */
36
- const resolution = (request) => {
34
+ export const resolution = (request) => {
37
35
  if (request.resolution === undefined)
38
36
  return undefined;
39
37
  return (ImageSizing.tier(request.resolution) ?? 1) < 1.5 ? "1k" : "2k";
@@ -85,4 +83,5 @@ export const model = (input) => ImageModel.fromRoute({ protocol, baseURL: DEFAUL
85
83
  export const XAIImages = {
86
84
  protocol,
87
85
  model,
86
+ resolution,
88
87
  };