@ai-sdk/openai 2.0.0-alpha.9 → 2.0.0-beta.10

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.
@@ -38,8 +38,8 @@ module.exports = __toCommonJS(internal_exports);
38
38
 
39
39
  // src/openai-chat-language-model.ts
40
40
  var import_provider3 = require("@ai-sdk/provider");
41
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
42
- var import_zod3 = require("zod");
41
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
42
+ var import_v45 = require("zod/v4");
43
43
 
44
44
  // src/convert-to-openai-chat-messages.ts
45
45
  var import_provider = require("@ai-sdk/provider");
@@ -173,7 +173,7 @@ function convertToOpenAIChatMessages({
173
173
  type: "function",
174
174
  function: {
175
175
  name: part.toolName,
176
- arguments: JSON.stringify(part.args)
176
+ arguments: JSON.stringify(part.input)
177
177
  }
178
178
  });
179
179
  break;
@@ -189,10 +189,23 @@ function convertToOpenAIChatMessages({
189
189
  }
190
190
  case "tool": {
191
191
  for (const toolResponse of content) {
192
+ const output = toolResponse.output;
193
+ let contentValue;
194
+ switch (output.type) {
195
+ case "text":
196
+ case "error-text":
197
+ contentValue = output.value;
198
+ break;
199
+ case "content":
200
+ case "json":
201
+ case "error-json":
202
+ contentValue = JSON.stringify(output.value);
203
+ break;
204
+ }
192
205
  messages.push({
193
206
  role: "tool",
194
207
  tool_call_id: toolResponse.toolCallId,
195
- content: JSON.stringify(toolResponse.result)
208
+ content: contentValue
196
209
  });
197
210
  }
198
211
  break;
@@ -237,15 +250,15 @@ function mapOpenAIFinishReason(finishReason) {
237
250
  }
238
251
 
239
252
  // src/openai-chat-options.ts
240
- var import_zod = require("zod");
241
- var openaiProviderOptions = import_zod.z.object({
253
+ var import_v4 = require("zod/v4");
254
+ var openaiProviderOptions = import_v4.z.object({
242
255
  /**
243
256
  * Modify the likelihood of specified tokens appearing in the completion.
244
257
  *
245
258
  * Accepts a JSON object that maps tokens (specified by their token ID in
246
259
  * the GPT tokenizer) to an associated bias value from -100 to 100.
247
260
  */
248
- logitBias: import_zod.z.record(import_zod.z.coerce.number(), import_zod.z.number()).optional(),
261
+ logitBias: import_v4.z.record(import_v4.z.coerce.number(), import_v4.z.number()).optional(),
249
262
  /**
250
263
  * Return the log probabilities of the tokens.
251
264
  *
@@ -255,56 +268,69 @@ var openaiProviderOptions = import_zod.z.object({
255
268
  * Setting to a number will return the log probabilities of the top n
256
269
  * tokens that were generated.
257
270
  */
258
- logprobs: import_zod.z.union([import_zod.z.boolean(), import_zod.z.number()]).optional(),
271
+ logprobs: import_v4.z.union([import_v4.z.boolean(), import_v4.z.number()]).optional(),
259
272
  /**
260
273
  * Whether to enable parallel function calling during tool use. Default to true.
261
274
  */
262
- parallelToolCalls: import_zod.z.boolean().optional(),
275
+ parallelToolCalls: import_v4.z.boolean().optional(),
263
276
  /**
264
277
  * A unique identifier representing your end-user, which can help OpenAI to
265
278
  * monitor and detect abuse.
266
279
  */
267
- user: import_zod.z.string().optional(),
280
+ user: import_v4.z.string().optional(),
268
281
  /**
269
282
  * Reasoning effort for reasoning models. Defaults to `medium`.
270
283
  */
271
- reasoningEffort: import_zod.z.enum(["low", "medium", "high"]).optional(),
284
+ reasoningEffort: import_v4.z.enum(["low", "medium", "high"]).optional(),
272
285
  /**
273
286
  * Maximum number of completion tokens to generate. Useful for reasoning models.
274
287
  */
275
- maxCompletionTokens: import_zod.z.number().optional(),
288
+ maxCompletionTokens: import_v4.z.number().optional(),
276
289
  /**
277
290
  * Whether to enable persistence in responses API.
278
291
  */
279
- store: import_zod.z.boolean().optional(),
292
+ store: import_v4.z.boolean().optional(),
280
293
  /**
281
294
  * Metadata to associate with the request.
282
295
  */
283
- metadata: import_zod.z.record(import_zod.z.string()).optional(),
296
+ metadata: import_v4.z.record(import_v4.z.string().max(64), import_v4.z.string().max(512)).optional(),
284
297
  /**
285
298
  * Parameters for prediction mode.
286
299
  */
287
- prediction: import_zod.z.record(import_zod.z.any()).optional(),
300
+ prediction: import_v4.z.record(import_v4.z.string(), import_v4.z.any()).optional(),
288
301
  /**
289
302
  * Whether to use structured outputs.
290
303
  *
291
304
  * @default true
292
305
  */
293
- structuredOutputs: import_zod.z.boolean().optional()
306
+ structuredOutputs: import_v4.z.boolean().optional(),
307
+ /**
308
+ * Service tier for the request. Set to 'flex' for 50% cheaper processing
309
+ * at the cost of increased latency. Only available for o3 and o4-mini models.
310
+ *
311
+ * @default 'auto'
312
+ */
313
+ serviceTier: import_v4.z.enum(["auto", "flex"]).optional(),
314
+ /**
315
+ * Whether to use strict JSON schema validation.
316
+ *
317
+ * @default false
318
+ */
319
+ strictJsonSchema: import_v4.z.boolean().optional()
294
320
  });
295
321
 
296
322
  // src/openai-error.ts
297
- var import_zod2 = require("zod");
323
+ var import_v42 = require("zod/v4");
298
324
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
299
- var openaiErrorDataSchema = import_zod2.z.object({
300
- error: import_zod2.z.object({
301
- message: import_zod2.z.string(),
325
+ var openaiErrorDataSchema = import_v42.z.object({
326
+ error: import_v42.z.object({
327
+ message: import_v42.z.string(),
302
328
  // The additional information below is handled loosely to support
303
329
  // OpenAI-compatible providers that have slightly different error
304
330
  // responses:
305
- type: import_zod2.z.string().nullish(),
306
- param: import_zod2.z.any().nullish(),
307
- code: import_zod2.z.union([import_zod2.z.string(), import_zod2.z.number()]).nullish()
331
+ type: import_v42.z.string().nullish(),
332
+ param: import_v42.z.any().nullish(),
333
+ code: import_v42.z.union([import_v42.z.string(), import_v42.z.number()]).nullish()
308
334
  })
309
335
  });
310
336
  var openaiFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResponseHandler)({
@@ -314,10 +340,81 @@ var openaiFailedResponseHandler = (0, import_provider_utils2.createJsonErrorResp
314
340
 
315
341
  // src/openai-prepare-tools.ts
316
342
  var import_provider2 = require("@ai-sdk/provider");
343
+
344
+ // src/tool/file-search.ts
345
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
346
+ var import_v43 = require("zod/v4");
347
+ var fileSearchArgsSchema = import_v43.z.object({
348
+ /**
349
+ * List of vector store IDs to search through. If not provided, searches all available vector stores.
350
+ */
351
+ vectorStoreIds: import_v43.z.array(import_v43.z.string()).optional(),
352
+ /**
353
+ * Maximum number of search results to return. Defaults to 10.
354
+ */
355
+ maxResults: import_v43.z.number().optional(),
356
+ /**
357
+ * Type of search to perform. Defaults to 'auto'.
358
+ */
359
+ searchType: import_v43.z.enum(["auto", "keyword", "semantic"]).optional()
360
+ });
361
+ var fileSearch = (0, import_provider_utils3.createProviderDefinedToolFactory)({
362
+ id: "openai.file_search",
363
+ name: "file_search",
364
+ inputSchema: import_v43.z.object({
365
+ query: import_v43.z.string()
366
+ })
367
+ });
368
+
369
+ // src/tool/web-search-preview.ts
370
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
371
+ var import_v44 = require("zod/v4");
372
+ var webSearchPreviewArgsSchema = import_v44.z.object({
373
+ /**
374
+ * Search context size to use for the web search.
375
+ * - high: Most comprehensive context, highest cost, slower response
376
+ * - medium: Balanced context, cost, and latency (default)
377
+ * - low: Least context, lowest cost, fastest response
378
+ */
379
+ searchContextSize: import_v44.z.enum(["low", "medium", "high"]).optional(),
380
+ /**
381
+ * User location information to provide geographically relevant search results.
382
+ */
383
+ userLocation: import_v44.z.object({
384
+ /**
385
+ * Type of location (always 'approximate')
386
+ */
387
+ type: import_v44.z.literal("approximate"),
388
+ /**
389
+ * Two-letter ISO country code (e.g., 'US', 'GB')
390
+ */
391
+ country: import_v44.z.string().optional(),
392
+ /**
393
+ * City name (free text, e.g., 'Minneapolis')
394
+ */
395
+ city: import_v44.z.string().optional(),
396
+ /**
397
+ * Region name (free text, e.g., 'Minnesota')
398
+ */
399
+ region: import_v44.z.string().optional(),
400
+ /**
401
+ * IANA timezone (e.g., 'America/Chicago')
402
+ */
403
+ timezone: import_v44.z.string().optional()
404
+ }).optional()
405
+ });
406
+ var webSearchPreview = (0, import_provider_utils4.createProviderDefinedToolFactory)({
407
+ id: "openai.web_search_preview",
408
+ name: "web_search_preview",
409
+ inputSchema: import_v44.z.object({})
410
+ });
411
+
412
+ // src/openai-prepare-tools.ts
317
413
  function prepareTools({
318
414
  tools,
319
415
  toolChoice,
320
- structuredOutputs
416
+ structuredOutputs,
417
+ strictJsonSchema
321
418
  }) {
322
419
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
323
420
  const toolWarnings = [];
@@ -326,18 +423,47 @@ function prepareTools({
326
423
  }
327
424
  const openaiTools = [];
328
425
  for (const tool of tools) {
329
- if (tool.type === "provider-defined") {
330
- toolWarnings.push({ type: "unsupported-tool", tool });
331
- } else {
332
- openaiTools.push({
333
- type: "function",
334
- function: {
335
- name: tool.name,
336
- description: tool.description,
337
- parameters: tool.parameters,
338
- strict: structuredOutputs ? true : void 0
426
+ switch (tool.type) {
427
+ case "function":
428
+ openaiTools.push({
429
+ type: "function",
430
+ function: {
431
+ name: tool.name,
432
+ description: tool.description,
433
+ parameters: tool.inputSchema,
434
+ strict: structuredOutputs ? strictJsonSchema : void 0
435
+ }
436
+ });
437
+ break;
438
+ case "provider-defined":
439
+ switch (tool.id) {
440
+ case "openai.file_search": {
441
+ const args = fileSearchArgsSchema.parse(tool.args);
442
+ openaiTools.push({
443
+ type: "file_search",
444
+ vector_store_ids: args.vectorStoreIds,
445
+ max_results: args.maxResults,
446
+ search_type: args.searchType
447
+ });
448
+ break;
449
+ }
450
+ case "openai.web_search_preview": {
451
+ const args = webSearchPreviewArgsSchema.parse(tool.args);
452
+ openaiTools.push({
453
+ type: "web_search_preview",
454
+ search_context_size: args.searchContextSize,
455
+ user_location: args.userLocation
456
+ });
457
+ break;
458
+ }
459
+ default:
460
+ toolWarnings.push({ type: "unsupported-tool", tool });
461
+ break;
339
462
  }
340
- });
463
+ break;
464
+ default:
465
+ toolWarnings.push({ type: "unsupported-tool", tool });
466
+ break;
341
467
  }
342
468
  }
343
469
  if (toolChoice == null) {
@@ -397,9 +523,9 @@ var OpenAIChatLanguageModel = class {
397
523
  toolChoice,
398
524
  providerOptions
399
525
  }) {
400
- var _a, _b, _c;
526
+ var _a, _b, _c, _d;
401
527
  const warnings = [];
402
- const openaiOptions = (_a = await (0, import_provider_utils3.parseProviderOptions)({
528
+ const openaiOptions = (_a = await (0, import_provider_utils5.parseProviderOptions)({
403
529
  provider: "openai",
404
530
  providerOptions,
405
531
  schema: openaiProviderOptions
@@ -425,6 +551,7 @@ var OpenAIChatLanguageModel = class {
425
551
  }
426
552
  );
427
553
  warnings.push(...messageWarnings);
554
+ const strictJsonSchema = (_c = openaiOptions.strictJsonSchema) != null ? _c : false;
428
555
  const baseArgs = {
429
556
  // model id:
430
557
  model: this.modelId,
@@ -440,18 +567,15 @@ var OpenAIChatLanguageModel = class {
440
567
  top_p: topP,
441
568
  frequency_penalty: frequencyPenalty,
442
569
  presence_penalty: presencePenalty,
443
- response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? (
444
- // TODO convert into provider option
445
- structuredOutputs && responseFormat.schema != null ? {
446
- type: "json_schema",
447
- json_schema: {
448
- schema: responseFormat.schema,
449
- strict: true,
450
- name: (_c = responseFormat.name) != null ? _c : "response",
451
- description: responseFormat.description
452
- }
453
- } : { type: "json_object" }
454
- ) : void 0,
570
+ response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && responseFormat.schema != null ? {
571
+ type: "json_schema",
572
+ json_schema: {
573
+ schema: responseFormat.schema,
574
+ strict: strictJsonSchema,
575
+ name: (_d = responseFormat.name) != null ? _d : "response",
576
+ description: responseFormat.description
577
+ }
578
+ } : { type: "json_object" } : void 0,
455
579
  stop: stopSequences,
456
580
  seed,
457
581
  // openai specific settings:
@@ -461,6 +585,7 @@ var OpenAIChatLanguageModel = class {
461
585
  metadata: openaiOptions.metadata,
462
586
  prediction: openaiOptions.prediction,
463
587
  reasoning_effort: openaiOptions.reasoningEffort,
588
+ service_tier: openaiOptions.serviceTier,
464
589
  // messages:
465
590
  messages
466
591
  };
@@ -534,6 +659,14 @@ var OpenAIChatLanguageModel = class {
534
659
  });
535
660
  }
536
661
  }
662
+ if (openaiOptions.serviceTier === "flex" && !supportsFlexProcessing(this.modelId)) {
663
+ warnings.push({
664
+ type: "unsupported-setting",
665
+ setting: "serviceTier",
666
+ details: "flex processing is only available for o3 and o4-mini models"
667
+ });
668
+ baseArgs.service_tier = void 0;
669
+ }
537
670
  const {
538
671
  tools: openaiTools,
539
672
  toolChoice: openaiToolChoice,
@@ -541,7 +674,8 @@ var OpenAIChatLanguageModel = class {
541
674
  } = prepareTools({
542
675
  tools,
543
676
  toolChoice,
544
- structuredOutputs
677
+ structuredOutputs,
678
+ strictJsonSchema
545
679
  });
546
680
  return {
547
681
  args: {
@@ -559,15 +693,15 @@ var OpenAIChatLanguageModel = class {
559
693
  responseHeaders,
560
694
  value: response,
561
695
  rawValue: rawResponse
562
- } = await (0, import_provider_utils3.postJsonToApi)({
696
+ } = await (0, import_provider_utils5.postJsonToApi)({
563
697
  url: this.config.url({
564
698
  path: "/chat/completions",
565
699
  modelId: this.modelId
566
700
  }),
567
- headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
701
+ headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), options.headers),
568
702
  body,
569
703
  failedResponseHandler: openaiFailedResponseHandler,
570
- successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
704
+ successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
571
705
  openaiChatResponseSchema
572
706
  ),
573
707
  abortSignal: options.abortSignal,
@@ -582,10 +716,9 @@ var OpenAIChatLanguageModel = class {
582
716
  for (const toolCall of (_a = choice.message.tool_calls) != null ? _a : []) {
583
717
  content.push({
584
718
  type: "tool-call",
585
- toolCallType: "function",
586
- toolCallId: (_b = toolCall.id) != null ? _b : (0, import_provider_utils3.generateId)(),
719
+ toolCallId: (_b = toolCall.id) != null ? _b : (0, import_provider_utils5.generateId)(),
587
720
  toolName: toolCall.function.name,
588
- args: toolCall.function.arguments
721
+ input: toolCall.function.arguments
589
722
  });
590
723
  }
591
724
  const completionTokenDetails = (_c = response.usage) == null ? void 0 : _c.completion_tokens_details;
@@ -629,15 +762,15 @@ var OpenAIChatLanguageModel = class {
629
762
  include_usage: true
630
763
  }
631
764
  };
632
- const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
765
+ const { responseHeaders, value: response } = await (0, import_provider_utils5.postJsonToApi)({
633
766
  url: this.config.url({
634
767
  path: "/chat/completions",
635
768
  modelId: this.modelId
636
769
  }),
637
- headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
770
+ headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), options.headers),
638
771
  body,
639
772
  failedResponseHandler: openaiFailedResponseHandler,
640
- successfulResponseHandler: (0, import_provider_utils3.createEventSourceResponseHandler)(
773
+ successfulResponseHandler: (0, import_provider_utils5.createEventSourceResponseHandler)(
641
774
  openaiChatChunkSchema
642
775
  ),
643
776
  abortSignal: options.abortSignal,
@@ -651,6 +784,7 @@ var OpenAIChatLanguageModel = class {
651
784
  totalTokens: void 0
652
785
  };
653
786
  let isFirstChunk = true;
787
+ let isActiveText = false;
654
788
  const providerMetadata = { openai: {} };
655
789
  return {
656
790
  stream: response.pipeThrough(
@@ -660,6 +794,9 @@ var OpenAIChatLanguageModel = class {
660
794
  },
661
795
  transform(chunk, controller) {
662
796
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
797
+ if (options.includeRawChunks) {
798
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
799
+ }
663
800
  if (!chunk.success) {
664
801
  finishReason = "error";
665
802
  controller.enqueue({ type: "error", error: chunk.error });
@@ -703,9 +840,14 @@ var OpenAIChatLanguageModel = class {
703
840
  }
704
841
  const delta = choice.delta;
705
842
  if (delta.content != null) {
843
+ if (!isActiveText) {
844
+ controller.enqueue({ type: "text-start", id: "0" });
845
+ isActiveText = true;
846
+ }
706
847
  controller.enqueue({
707
- type: "text",
708
- text: delta.content
848
+ type: "text-delta",
849
+ id: "0",
850
+ delta: delta.content
709
851
  });
710
852
  }
711
853
  if (delta.tool_calls != null) {
@@ -730,6 +872,11 @@ var OpenAIChatLanguageModel = class {
730
872
  message: `Expected 'function.name' to be a string.`
731
873
  });
732
874
  }
875
+ controller.enqueue({
876
+ type: "tool-input-start",
877
+ id: toolCallDelta.id,
878
+ toolName: toolCallDelta.function.name
879
+ });
733
880
  toolCalls[index] = {
734
881
  id: toolCallDelta.id,
735
882
  type: "function",
@@ -743,20 +890,21 @@ var OpenAIChatLanguageModel = class {
743
890
  if (((_o = toolCall2.function) == null ? void 0 : _o.name) != null && ((_p = toolCall2.function) == null ? void 0 : _p.arguments) != null) {
744
891
  if (toolCall2.function.arguments.length > 0) {
745
892
  controller.enqueue({
746
- type: "tool-call-delta",
747
- toolCallType: "function",
748
- toolCallId: toolCall2.id,
749
- toolName: toolCall2.function.name,
750
- argsTextDelta: toolCall2.function.arguments
893
+ type: "tool-input-delta",
894
+ id: toolCall2.id,
895
+ delta: toolCall2.function.arguments
751
896
  });
752
897
  }
753
- if ((0, import_provider_utils3.isParsableJson)(toolCall2.function.arguments)) {
898
+ if ((0, import_provider_utils5.isParsableJson)(toolCall2.function.arguments)) {
899
+ controller.enqueue({
900
+ type: "tool-input-end",
901
+ id: toolCall2.id
902
+ });
754
903
  controller.enqueue({
755
904
  type: "tool-call",
756
- toolCallType: "function",
757
- toolCallId: (_q = toolCall2.id) != null ? _q : (0, import_provider_utils3.generateId)(),
905
+ toolCallId: (_q = toolCall2.id) != null ? _q : (0, import_provider_utils5.generateId)(),
758
906
  toolName: toolCall2.function.name,
759
- args: toolCall2.function.arguments
907
+ input: toolCall2.function.arguments
760
908
  });
761
909
  toolCall2.hasFinished = true;
762
910
  }
@@ -771,19 +919,20 @@ var OpenAIChatLanguageModel = class {
771
919
  toolCall.function.arguments += (_t = (_s = toolCallDelta.function) == null ? void 0 : _s.arguments) != null ? _t : "";
772
920
  }
773
921
  controller.enqueue({
774
- type: "tool-call-delta",
775
- toolCallType: "function",
776
- toolCallId: toolCall.id,
777
- toolName: toolCall.function.name,
778
- argsTextDelta: (_u = toolCallDelta.function.arguments) != null ? _u : ""
922
+ type: "tool-input-delta",
923
+ id: toolCall.id,
924
+ delta: (_u = toolCallDelta.function.arguments) != null ? _u : ""
779
925
  });
780
- if (((_v = toolCall.function) == null ? void 0 : _v.name) != null && ((_w = toolCall.function) == null ? void 0 : _w.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments)) {
926
+ if (((_v = toolCall.function) == null ? void 0 : _v.name) != null && ((_w = toolCall.function) == null ? void 0 : _w.arguments) != null && (0, import_provider_utils5.isParsableJson)(toolCall.function.arguments)) {
927
+ controller.enqueue({
928
+ type: "tool-input-end",
929
+ id: toolCall.id
930
+ });
781
931
  controller.enqueue({
782
932
  type: "tool-call",
783
- toolCallType: "function",
784
- toolCallId: (_x = toolCall.id) != null ? _x : (0, import_provider_utils3.generateId)(),
933
+ toolCallId: (_x = toolCall.id) != null ? _x : (0, import_provider_utils5.generateId)(),
785
934
  toolName: toolCall.function.name,
786
- args: toolCall.function.arguments
935
+ input: toolCall.function.arguments
787
936
  });
788
937
  toolCall.hasFinished = true;
789
938
  }
@@ -791,6 +940,9 @@ var OpenAIChatLanguageModel = class {
791
940
  }
792
941
  },
793
942
  flush(controller) {
943
+ if (isActiveText) {
944
+ controller.enqueue({ type: "text-end", id: "0" });
945
+ }
794
946
  controller.enqueue({
795
947
  type: "finish",
796
948
  finishReason,
@@ -805,97 +957,97 @@ var OpenAIChatLanguageModel = class {
805
957
  };
806
958
  }
807
959
  };
808
- var openaiTokenUsageSchema = import_zod3.z.object({
809
- prompt_tokens: import_zod3.z.number().nullish(),
810
- completion_tokens: import_zod3.z.number().nullish(),
811
- total_tokens: import_zod3.z.number().nullish(),
812
- prompt_tokens_details: import_zod3.z.object({
813
- cached_tokens: import_zod3.z.number().nullish()
960
+ var openaiTokenUsageSchema = import_v45.z.object({
961
+ prompt_tokens: import_v45.z.number().nullish(),
962
+ completion_tokens: import_v45.z.number().nullish(),
963
+ total_tokens: import_v45.z.number().nullish(),
964
+ prompt_tokens_details: import_v45.z.object({
965
+ cached_tokens: import_v45.z.number().nullish()
814
966
  }).nullish(),
815
- completion_tokens_details: import_zod3.z.object({
816
- reasoning_tokens: import_zod3.z.number().nullish(),
817
- accepted_prediction_tokens: import_zod3.z.number().nullish(),
818
- rejected_prediction_tokens: import_zod3.z.number().nullish()
967
+ completion_tokens_details: import_v45.z.object({
968
+ reasoning_tokens: import_v45.z.number().nullish(),
969
+ accepted_prediction_tokens: import_v45.z.number().nullish(),
970
+ rejected_prediction_tokens: import_v45.z.number().nullish()
819
971
  }).nullish()
820
972
  }).nullish();
821
- var openaiChatResponseSchema = import_zod3.z.object({
822
- id: import_zod3.z.string().nullish(),
823
- created: import_zod3.z.number().nullish(),
824
- model: import_zod3.z.string().nullish(),
825
- choices: import_zod3.z.array(
826
- import_zod3.z.object({
827
- message: import_zod3.z.object({
828
- role: import_zod3.z.literal("assistant").nullish(),
829
- content: import_zod3.z.string().nullish(),
830
- tool_calls: import_zod3.z.array(
831
- import_zod3.z.object({
832
- id: import_zod3.z.string().nullish(),
833
- type: import_zod3.z.literal("function"),
834
- function: import_zod3.z.object({
835
- name: import_zod3.z.string(),
836
- arguments: import_zod3.z.string()
973
+ var openaiChatResponseSchema = import_v45.z.object({
974
+ id: import_v45.z.string().nullish(),
975
+ created: import_v45.z.number().nullish(),
976
+ model: import_v45.z.string().nullish(),
977
+ choices: import_v45.z.array(
978
+ import_v45.z.object({
979
+ message: import_v45.z.object({
980
+ role: import_v45.z.literal("assistant").nullish(),
981
+ content: import_v45.z.string().nullish(),
982
+ tool_calls: import_v45.z.array(
983
+ import_v45.z.object({
984
+ id: import_v45.z.string().nullish(),
985
+ type: import_v45.z.literal("function"),
986
+ function: import_v45.z.object({
987
+ name: import_v45.z.string(),
988
+ arguments: import_v45.z.string()
837
989
  })
838
990
  })
839
991
  ).nullish()
840
992
  }),
841
- index: import_zod3.z.number(),
842
- logprobs: import_zod3.z.object({
843
- content: import_zod3.z.array(
844
- import_zod3.z.object({
845
- token: import_zod3.z.string(),
846
- logprob: import_zod3.z.number(),
847
- top_logprobs: import_zod3.z.array(
848
- import_zod3.z.object({
849
- token: import_zod3.z.string(),
850
- logprob: import_zod3.z.number()
993
+ index: import_v45.z.number(),
994
+ logprobs: import_v45.z.object({
995
+ content: import_v45.z.array(
996
+ import_v45.z.object({
997
+ token: import_v45.z.string(),
998
+ logprob: import_v45.z.number(),
999
+ top_logprobs: import_v45.z.array(
1000
+ import_v45.z.object({
1001
+ token: import_v45.z.string(),
1002
+ logprob: import_v45.z.number()
851
1003
  })
852
1004
  )
853
1005
  })
854
1006
  ).nullish()
855
1007
  }).nullish(),
856
- finish_reason: import_zod3.z.string().nullish()
1008
+ finish_reason: import_v45.z.string().nullish()
857
1009
  })
858
1010
  ),
859
1011
  usage: openaiTokenUsageSchema
860
1012
  });
861
- var openaiChatChunkSchema = import_zod3.z.union([
862
- import_zod3.z.object({
863
- id: import_zod3.z.string().nullish(),
864
- created: import_zod3.z.number().nullish(),
865
- model: import_zod3.z.string().nullish(),
866
- choices: import_zod3.z.array(
867
- import_zod3.z.object({
868
- delta: import_zod3.z.object({
869
- role: import_zod3.z.enum(["assistant"]).nullish(),
870
- content: import_zod3.z.string().nullish(),
871
- tool_calls: import_zod3.z.array(
872
- import_zod3.z.object({
873
- index: import_zod3.z.number(),
874
- id: import_zod3.z.string().nullish(),
875
- type: import_zod3.z.literal("function").nullish(),
876
- function: import_zod3.z.object({
877
- name: import_zod3.z.string().nullish(),
878
- arguments: import_zod3.z.string().nullish()
1013
+ var openaiChatChunkSchema = import_v45.z.union([
1014
+ import_v45.z.object({
1015
+ id: import_v45.z.string().nullish(),
1016
+ created: import_v45.z.number().nullish(),
1017
+ model: import_v45.z.string().nullish(),
1018
+ choices: import_v45.z.array(
1019
+ import_v45.z.object({
1020
+ delta: import_v45.z.object({
1021
+ role: import_v45.z.enum(["assistant"]).nullish(),
1022
+ content: import_v45.z.string().nullish(),
1023
+ tool_calls: import_v45.z.array(
1024
+ import_v45.z.object({
1025
+ index: import_v45.z.number(),
1026
+ id: import_v45.z.string().nullish(),
1027
+ type: import_v45.z.literal("function").nullish(),
1028
+ function: import_v45.z.object({
1029
+ name: import_v45.z.string().nullish(),
1030
+ arguments: import_v45.z.string().nullish()
879
1031
  })
880
1032
  })
881
1033
  ).nullish()
882
1034
  }).nullish(),
883
- logprobs: import_zod3.z.object({
884
- content: import_zod3.z.array(
885
- import_zod3.z.object({
886
- token: import_zod3.z.string(),
887
- logprob: import_zod3.z.number(),
888
- top_logprobs: import_zod3.z.array(
889
- import_zod3.z.object({
890
- token: import_zod3.z.string(),
891
- logprob: import_zod3.z.number()
1035
+ logprobs: import_v45.z.object({
1036
+ content: import_v45.z.array(
1037
+ import_v45.z.object({
1038
+ token: import_v45.z.string(),
1039
+ logprob: import_v45.z.number(),
1040
+ top_logprobs: import_v45.z.array(
1041
+ import_v45.z.object({
1042
+ token: import_v45.z.string(),
1043
+ logprob: import_v45.z.number()
892
1044
  })
893
1045
  )
894
1046
  })
895
1047
  ).nullish()
896
1048
  }).nullish(),
897
- finish_reason: import_zod3.z.string().nullish(),
898
- index: import_zod3.z.number()
1049
+ finish_reason: import_v45.z.string().nullish(),
1050
+ index: import_v45.z.number()
899
1051
  })
900
1052
  ),
901
1053
  usage: openaiTokenUsageSchema
@@ -905,6 +1057,9 @@ var openaiChatChunkSchema = import_zod3.z.union([
905
1057
  function isReasoningModel(modelId) {
906
1058
  return modelId.startsWith("o");
907
1059
  }
1060
+ function supportsFlexProcessing(modelId) {
1061
+ return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
1062
+ }
908
1063
  function getSystemMessageMode(modelId) {
909
1064
  var _a, _b;
910
1065
  if (!isReasoningModel(modelId)) {
@@ -946,8 +1101,8 @@ var reasoningModels = {
946
1101
  };
947
1102
 
948
1103
  // src/openai-completion-language-model.ts
949
- var import_provider_utils4 = require("@ai-sdk/provider-utils");
950
- var import_zod5 = require("zod");
1104
+ var import_provider_utils6 = require("@ai-sdk/provider-utils");
1105
+ var import_v47 = require("zod/v4");
951
1106
 
952
1107
  // src/convert-to-openai-completion-prompt.ts
953
1108
  var import_provider4 = require("@ai-sdk/provider");
@@ -1025,12 +1180,12 @@ ${user}:`]
1025
1180
  }
1026
1181
 
1027
1182
  // src/openai-completion-options.ts
1028
- var import_zod4 = require("zod");
1029
- var openaiCompletionProviderOptions = import_zod4.z.object({
1183
+ var import_v46 = require("zod/v4");
1184
+ var openaiCompletionProviderOptions = import_v46.z.object({
1030
1185
  /**
1031
1186
  Echo back the prompt in addition to the completion.
1032
1187
  */
1033
- echo: import_zod4.z.boolean().optional(),
1188
+ echo: import_v46.z.boolean().optional(),
1034
1189
  /**
1035
1190
  Modify the likelihood of specified tokens appearing in the completion.
1036
1191
 
@@ -1045,16 +1200,16 @@ var openaiCompletionProviderOptions = import_zod4.z.object({
1045
1200
  As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
1046
1201
  token from being generated.
1047
1202
  */
1048
- logitBias: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.number()).optional(),
1203
+ logitBias: import_v46.z.record(import_v46.z.string(), import_v46.z.number()).optional(),
1049
1204
  /**
1050
1205
  The suffix that comes after a completion of inserted text.
1051
1206
  */
1052
- suffix: import_zod4.z.string().optional(),
1207
+ suffix: import_v46.z.string().optional(),
1053
1208
  /**
1054
1209
  A unique identifier representing your end-user, which can help OpenAI to
1055
1210
  monitor and detect abuse. Learn more.
1056
1211
  */
1057
- user: import_zod4.z.string().optional(),
1212
+ user: import_v46.z.string().optional(),
1058
1213
  /**
1059
1214
  Return the log probabilities of the tokens. Including logprobs will increase
1060
1215
  the response size and can slow down response times. However, it can
@@ -1064,7 +1219,7 @@ var openaiCompletionProviderOptions = import_zod4.z.object({
1064
1219
  Setting to a number will return the log probabilities of the top n
1065
1220
  tokens that were generated.
1066
1221
  */
1067
- logprobs: import_zod4.z.union([import_zod4.z.boolean(), import_zod4.z.number()]).optional()
1222
+ logprobs: import_v46.z.union([import_v46.z.boolean(), import_v46.z.number()]).optional()
1068
1223
  });
1069
1224
 
1070
1225
  // src/openai-completion-language-model.ts
@@ -1100,12 +1255,12 @@ var OpenAICompletionLanguageModel = class {
1100
1255
  }) {
1101
1256
  const warnings = [];
1102
1257
  const openaiOptions = {
1103
- ...await (0, import_provider_utils4.parseProviderOptions)({
1258
+ ...await (0, import_provider_utils6.parseProviderOptions)({
1104
1259
  provider: "openai",
1105
1260
  providerOptions,
1106
1261
  schema: openaiCompletionProviderOptions
1107
1262
  }),
1108
- ...await (0, import_provider_utils4.parseProviderOptions)({
1263
+ ...await (0, import_provider_utils6.parseProviderOptions)({
1109
1264
  provider: this.providerOptionsName,
1110
1265
  providerOptions,
1111
1266
  schema: openaiCompletionProviderOptions
@@ -1161,15 +1316,15 @@ var OpenAICompletionLanguageModel = class {
1161
1316
  responseHeaders,
1162
1317
  value: response,
1163
1318
  rawValue: rawResponse
1164
- } = await (0, import_provider_utils4.postJsonToApi)({
1319
+ } = await (0, import_provider_utils6.postJsonToApi)({
1165
1320
  url: this.config.url({
1166
1321
  path: "/completions",
1167
1322
  modelId: this.modelId
1168
1323
  }),
1169
- headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), options.headers),
1324
+ headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), options.headers),
1170
1325
  body: args,
1171
1326
  failedResponseHandler: openaiFailedResponseHandler,
1172
- successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
1327
+ successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
1173
1328
  openaiCompletionResponseSchema
1174
1329
  ),
1175
1330
  abortSignal: options.abortSignal,
@@ -1207,15 +1362,15 @@ var OpenAICompletionLanguageModel = class {
1207
1362
  include_usage: true
1208
1363
  }
1209
1364
  };
1210
- const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
1365
+ const { responseHeaders, value: response } = await (0, import_provider_utils6.postJsonToApi)({
1211
1366
  url: this.config.url({
1212
1367
  path: "/completions",
1213
1368
  modelId: this.modelId
1214
1369
  }),
1215
- headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), options.headers),
1370
+ headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), options.headers),
1216
1371
  body,
1217
1372
  failedResponseHandler: openaiFailedResponseHandler,
1218
- successfulResponseHandler: (0, import_provider_utils4.createEventSourceResponseHandler)(
1373
+ successfulResponseHandler: (0, import_provider_utils6.createEventSourceResponseHandler)(
1219
1374
  openaiCompletionChunkSchema
1220
1375
  ),
1221
1376
  abortSignal: options.abortSignal,
@@ -1236,6 +1391,9 @@ var OpenAICompletionLanguageModel = class {
1236
1391
  controller.enqueue({ type: "stream-start", warnings });
1237
1392
  },
1238
1393
  transform(chunk, controller) {
1394
+ if (options.includeRawChunks) {
1395
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1396
+ }
1239
1397
  if (!chunk.success) {
1240
1398
  finishReason = "error";
1241
1399
  controller.enqueue({ type: "error", error: chunk.error });
@@ -1253,6 +1411,7 @@ var OpenAICompletionLanguageModel = class {
1253
1411
  type: "response-metadata",
1254
1412
  ...getResponseMetadata(value)
1255
1413
  });
1414
+ controller.enqueue({ type: "text-start", id: "0" });
1256
1415
  }
1257
1416
  if (value.usage != null) {
1258
1417
  usage.inputTokens = value.usage.prompt_tokens;
@@ -1266,14 +1425,18 @@ var OpenAICompletionLanguageModel = class {
1266
1425
  if ((choice == null ? void 0 : choice.logprobs) != null) {
1267
1426
  providerMetadata.openai.logprobs = choice.logprobs;
1268
1427
  }
1269
- if ((choice == null ? void 0 : choice.text) != null) {
1428
+ if ((choice == null ? void 0 : choice.text) != null && choice.text.length > 0) {
1270
1429
  controller.enqueue({
1271
- type: "text",
1272
- text: choice.text
1430
+ type: "text-delta",
1431
+ id: "0",
1432
+ delta: choice.text
1273
1433
  });
1274
1434
  }
1275
1435
  },
1276
1436
  flush(controller) {
1437
+ if (!isFirstChunk) {
1438
+ controller.enqueue({ type: "text-end", id: "0" });
1439
+ }
1277
1440
  controller.enqueue({
1278
1441
  type: "finish",
1279
1442
  finishReason,
@@ -1288,42 +1451,42 @@ var OpenAICompletionLanguageModel = class {
1288
1451
  };
1289
1452
  }
1290
1453
  };
1291
- var usageSchema = import_zod5.z.object({
1292
- prompt_tokens: import_zod5.z.number(),
1293
- completion_tokens: import_zod5.z.number(),
1294
- total_tokens: import_zod5.z.number()
1454
+ var usageSchema = import_v47.z.object({
1455
+ prompt_tokens: import_v47.z.number(),
1456
+ completion_tokens: import_v47.z.number(),
1457
+ total_tokens: import_v47.z.number()
1295
1458
  });
1296
- var openaiCompletionResponseSchema = import_zod5.z.object({
1297
- id: import_zod5.z.string().nullish(),
1298
- created: import_zod5.z.number().nullish(),
1299
- model: import_zod5.z.string().nullish(),
1300
- choices: import_zod5.z.array(
1301
- import_zod5.z.object({
1302
- text: import_zod5.z.string(),
1303
- finish_reason: import_zod5.z.string(),
1304
- logprobs: import_zod5.z.object({
1305
- tokens: import_zod5.z.array(import_zod5.z.string()),
1306
- token_logprobs: import_zod5.z.array(import_zod5.z.number()),
1307
- top_logprobs: import_zod5.z.array(import_zod5.z.record(import_zod5.z.string(), import_zod5.z.number())).nullish()
1459
+ var openaiCompletionResponseSchema = import_v47.z.object({
1460
+ id: import_v47.z.string().nullish(),
1461
+ created: import_v47.z.number().nullish(),
1462
+ model: import_v47.z.string().nullish(),
1463
+ choices: import_v47.z.array(
1464
+ import_v47.z.object({
1465
+ text: import_v47.z.string(),
1466
+ finish_reason: import_v47.z.string(),
1467
+ logprobs: import_v47.z.object({
1468
+ tokens: import_v47.z.array(import_v47.z.string()),
1469
+ token_logprobs: import_v47.z.array(import_v47.z.number()),
1470
+ top_logprobs: import_v47.z.array(import_v47.z.record(import_v47.z.string(), import_v47.z.number())).nullish()
1308
1471
  }).nullish()
1309
1472
  })
1310
1473
  ),
1311
1474
  usage: usageSchema.nullish()
1312
1475
  });
1313
- var openaiCompletionChunkSchema = import_zod5.z.union([
1314
- import_zod5.z.object({
1315
- id: import_zod5.z.string().nullish(),
1316
- created: import_zod5.z.number().nullish(),
1317
- model: import_zod5.z.string().nullish(),
1318
- choices: import_zod5.z.array(
1319
- import_zod5.z.object({
1320
- text: import_zod5.z.string(),
1321
- finish_reason: import_zod5.z.string().nullish(),
1322
- index: import_zod5.z.number(),
1323
- logprobs: import_zod5.z.object({
1324
- tokens: import_zod5.z.array(import_zod5.z.string()),
1325
- token_logprobs: import_zod5.z.array(import_zod5.z.number()),
1326
- top_logprobs: import_zod5.z.array(import_zod5.z.record(import_zod5.z.string(), import_zod5.z.number())).nullish()
1476
+ var openaiCompletionChunkSchema = import_v47.z.union([
1477
+ import_v47.z.object({
1478
+ id: import_v47.z.string().nullish(),
1479
+ created: import_v47.z.number().nullish(),
1480
+ model: import_v47.z.string().nullish(),
1481
+ choices: import_v47.z.array(
1482
+ import_v47.z.object({
1483
+ text: import_v47.z.string(),
1484
+ finish_reason: import_v47.z.string().nullish(),
1485
+ index: import_v47.z.number(),
1486
+ logprobs: import_v47.z.object({
1487
+ tokens: import_v47.z.array(import_v47.z.string()),
1488
+ token_logprobs: import_v47.z.array(import_v47.z.number()),
1489
+ top_logprobs: import_v47.z.array(import_v47.z.record(import_v47.z.string(), import_v47.z.number())).nullish()
1327
1490
  }).nullish()
1328
1491
  })
1329
1492
  ),
@@ -1334,22 +1497,22 @@ var openaiCompletionChunkSchema = import_zod5.z.union([
1334
1497
 
1335
1498
  // src/openai-embedding-model.ts
1336
1499
  var import_provider5 = require("@ai-sdk/provider");
1337
- var import_provider_utils5 = require("@ai-sdk/provider-utils");
1338
- var import_zod7 = require("zod");
1500
+ var import_provider_utils7 = require("@ai-sdk/provider-utils");
1501
+ var import_v49 = require("zod/v4");
1339
1502
 
1340
1503
  // src/openai-embedding-options.ts
1341
- var import_zod6 = require("zod");
1342
- var openaiEmbeddingProviderOptions = import_zod6.z.object({
1504
+ var import_v48 = require("zod/v4");
1505
+ var openaiEmbeddingProviderOptions = import_v48.z.object({
1343
1506
  /**
1344
1507
  The number of dimensions the resulting output embeddings should have.
1345
1508
  Only supported in text-embedding-3 and later models.
1346
1509
  */
1347
- dimensions: import_zod6.z.number().optional(),
1510
+ dimensions: import_v48.z.number().optional(),
1348
1511
  /**
1349
1512
  A unique identifier representing your end-user, which can help OpenAI to
1350
1513
  monitor and detect abuse. Learn more.
1351
1514
  */
1352
- user: import_zod6.z.string().optional()
1515
+ user: import_v48.z.string().optional()
1353
1516
  });
1354
1517
 
1355
1518
  // src/openai-embedding-model.ts
@@ -1379,7 +1542,7 @@ var OpenAIEmbeddingModel = class {
1379
1542
  values
1380
1543
  });
1381
1544
  }
1382
- const openaiOptions = (_a = await (0, import_provider_utils5.parseProviderOptions)({
1545
+ const openaiOptions = (_a = await (0, import_provider_utils7.parseProviderOptions)({
1383
1546
  provider: "openai",
1384
1547
  providerOptions,
1385
1548
  schema: openaiEmbeddingProviderOptions
@@ -1388,12 +1551,12 @@ var OpenAIEmbeddingModel = class {
1388
1551
  responseHeaders,
1389
1552
  value: response,
1390
1553
  rawValue
1391
- } = await (0, import_provider_utils5.postJsonToApi)({
1554
+ } = await (0, import_provider_utils7.postJsonToApi)({
1392
1555
  url: this.config.url({
1393
1556
  path: "/embeddings",
1394
1557
  modelId: this.modelId
1395
1558
  }),
1396
- headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), headers),
1559
+ headers: (0, import_provider_utils7.combineHeaders)(this.config.headers(), headers),
1397
1560
  body: {
1398
1561
  model: this.modelId,
1399
1562
  input: values,
@@ -1402,7 +1565,7 @@ var OpenAIEmbeddingModel = class {
1402
1565
  user: openaiOptions.user
1403
1566
  },
1404
1567
  failedResponseHandler: openaiFailedResponseHandler,
1405
- successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
1568
+ successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
1406
1569
  openaiTextEmbeddingResponseSchema
1407
1570
  ),
1408
1571
  abortSignal,
@@ -1415,14 +1578,14 @@ var OpenAIEmbeddingModel = class {
1415
1578
  };
1416
1579
  }
1417
1580
  };
1418
- var openaiTextEmbeddingResponseSchema = import_zod7.z.object({
1419
- data: import_zod7.z.array(import_zod7.z.object({ embedding: import_zod7.z.array(import_zod7.z.number()) })),
1420
- usage: import_zod7.z.object({ prompt_tokens: import_zod7.z.number() }).nullish()
1581
+ var openaiTextEmbeddingResponseSchema = import_v49.z.object({
1582
+ data: import_v49.z.array(import_v49.z.object({ embedding: import_v49.z.array(import_v49.z.number()) })),
1583
+ usage: import_v49.z.object({ prompt_tokens: import_v49.z.number() }).nullish()
1421
1584
  });
1422
1585
 
1423
1586
  // src/openai-image-model.ts
1424
- var import_provider_utils6 = require("@ai-sdk/provider-utils");
1425
- var import_zod8 = require("zod");
1587
+ var import_provider_utils8 = require("@ai-sdk/provider-utils");
1588
+ var import_v410 = require("zod/v4");
1426
1589
 
1427
1590
  // src/openai-image-settings.ts
1428
1591
  var modelMaxImagesPerCall = {
@@ -1469,12 +1632,12 @@ var OpenAIImageModel = class {
1469
1632
  warnings.push({ type: "unsupported-setting", setting: "seed" });
1470
1633
  }
1471
1634
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1472
- const { value: response, responseHeaders } = await (0, import_provider_utils6.postJsonToApi)({
1635
+ const { value: response, responseHeaders } = await (0, import_provider_utils8.postJsonToApi)({
1473
1636
  url: this.config.url({
1474
1637
  path: "/images/generations",
1475
1638
  modelId: this.modelId
1476
1639
  }),
1477
- headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), headers),
1640
+ headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), headers),
1478
1641
  body: {
1479
1642
  model: this.modelId,
1480
1643
  prompt,
@@ -1484,7 +1647,7 @@ var OpenAIImageModel = class {
1484
1647
  ...!hasDefaultResponseFormat.has(this.modelId) ? { response_format: "b64_json" } : {}
1485
1648
  },
1486
1649
  failedResponseHandler: openaiFailedResponseHandler,
1487
- successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
1650
+ successfulResponseHandler: (0, import_provider_utils8.createJsonResponseHandler)(
1488
1651
  openaiImageResponseSchema
1489
1652
  ),
1490
1653
  abortSignal,
@@ -1510,41 +1673,41 @@ var OpenAIImageModel = class {
1510
1673
  };
1511
1674
  }
1512
1675
  };
1513
- var openaiImageResponseSchema = import_zod8.z.object({
1514
- data: import_zod8.z.array(
1515
- import_zod8.z.object({ b64_json: import_zod8.z.string(), revised_prompt: import_zod8.z.string().optional() })
1676
+ var openaiImageResponseSchema = import_v410.z.object({
1677
+ data: import_v410.z.array(
1678
+ import_v410.z.object({ b64_json: import_v410.z.string(), revised_prompt: import_v410.z.string().optional() })
1516
1679
  )
1517
1680
  });
1518
1681
 
1519
1682
  // src/openai-transcription-model.ts
1520
- var import_provider_utils7 = require("@ai-sdk/provider-utils");
1521
- var import_zod10 = require("zod");
1683
+ var import_provider_utils9 = require("@ai-sdk/provider-utils");
1684
+ var import_v412 = require("zod/v4");
1522
1685
 
1523
1686
  // src/openai-transcription-options.ts
1524
- var import_zod9 = require("zod");
1525
- var openAITranscriptionProviderOptions = import_zod9.z.object({
1687
+ var import_v411 = require("zod/v4");
1688
+ var openAITranscriptionProviderOptions = import_v411.z.object({
1526
1689
  /**
1527
1690
  * Additional information to include in the transcription response.
1528
1691
  */
1529
- include: import_zod9.z.array(import_zod9.z.string()).optional(),
1692
+ include: import_v411.z.array(import_v411.z.string()).optional(),
1530
1693
  /**
1531
1694
  * The language of the input audio in ISO-639-1 format.
1532
1695
  */
1533
- language: import_zod9.z.string().optional(),
1696
+ language: import_v411.z.string().optional(),
1534
1697
  /**
1535
1698
  * An optional text to guide the model's style or continue a previous audio segment.
1536
1699
  */
1537
- prompt: import_zod9.z.string().optional(),
1700
+ prompt: import_v411.z.string().optional(),
1538
1701
  /**
1539
1702
  * The sampling temperature, between 0 and 1.
1540
1703
  * @default 0
1541
1704
  */
1542
- temperature: import_zod9.z.number().min(0).max(1).default(0).optional(),
1705
+ temperature: import_v411.z.number().min(0).max(1).default(0).optional(),
1543
1706
  /**
1544
1707
  * The timestamp granularities to populate for this transcription.
1545
1708
  * @default ['segment']
1546
1709
  */
1547
- timestampGranularities: import_zod9.z.array(import_zod9.z.enum(["word", "segment"])).default(["segment"]).optional()
1710
+ timestampGranularities: import_v411.z.array(import_v411.z.enum(["word", "segment"])).default(["segment"]).optional()
1548
1711
  });
1549
1712
 
1550
1713
  // src/openai-transcription-model.ts
@@ -1611,7 +1774,7 @@ var OpenAITranscriptionModel = class {
1611
1774
  constructor(modelId, config) {
1612
1775
  this.modelId = modelId;
1613
1776
  this.config = config;
1614
- this.specificationVersion = "v1";
1777
+ this.specificationVersion = "v2";
1615
1778
  }
1616
1779
  get provider() {
1617
1780
  return this.config.provider;
@@ -1622,13 +1785,13 @@ var OpenAITranscriptionModel = class {
1622
1785
  providerOptions
1623
1786
  }) {
1624
1787
  const warnings = [];
1625
- const openAIOptions = await (0, import_provider_utils7.parseProviderOptions)({
1788
+ const openAIOptions = await (0, import_provider_utils9.parseProviderOptions)({
1626
1789
  provider: "openai",
1627
1790
  providerOptions,
1628
1791
  schema: openAITranscriptionProviderOptions
1629
1792
  });
1630
1793
  const formData = new FormData();
1631
- const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils7.convertBase64ToUint8Array)(audio)]);
1794
+ const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils9.convertBase64ToUint8Array)(audio)]);
1632
1795
  formData.append("model", this.modelId);
1633
1796
  formData.append("file", new File([blob], "audio", { type: mediaType }));
1634
1797
  if (openAIOptions) {
@@ -1658,15 +1821,15 @@ var OpenAITranscriptionModel = class {
1658
1821
  value: response,
1659
1822
  responseHeaders,
1660
1823
  rawValue: rawResponse
1661
- } = await (0, import_provider_utils7.postFormDataToApi)({
1824
+ } = await (0, import_provider_utils9.postFormDataToApi)({
1662
1825
  url: this.config.url({
1663
1826
  path: "/audio/transcriptions",
1664
1827
  modelId: this.modelId
1665
1828
  }),
1666
- headers: (0, import_provider_utils7.combineHeaders)(this.config.headers(), options.headers),
1829
+ headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
1667
1830
  formData,
1668
1831
  failedResponseHandler: openaiFailedResponseHandler,
1669
- successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
1832
+ successfulResponseHandler: (0, import_provider_utils9.createJsonResponseHandler)(
1670
1833
  openaiTranscriptionResponseSchema
1671
1834
  ),
1672
1835
  abortSignal: options.abortSignal,
@@ -1692,31 +1855,31 @@ var OpenAITranscriptionModel = class {
1692
1855
  };
1693
1856
  }
1694
1857
  };
1695
- var openaiTranscriptionResponseSchema = import_zod10.z.object({
1696
- text: import_zod10.z.string(),
1697
- language: import_zod10.z.string().nullish(),
1698
- duration: import_zod10.z.number().nullish(),
1699
- words: import_zod10.z.array(
1700
- import_zod10.z.object({
1701
- word: import_zod10.z.string(),
1702
- start: import_zod10.z.number(),
1703
- end: import_zod10.z.number()
1858
+ var openaiTranscriptionResponseSchema = import_v412.z.object({
1859
+ text: import_v412.z.string(),
1860
+ language: import_v412.z.string().nullish(),
1861
+ duration: import_v412.z.number().nullish(),
1862
+ words: import_v412.z.array(
1863
+ import_v412.z.object({
1864
+ word: import_v412.z.string(),
1865
+ start: import_v412.z.number(),
1866
+ end: import_v412.z.number()
1704
1867
  })
1705
1868
  ).nullish()
1706
1869
  });
1707
1870
 
1708
1871
  // src/openai-speech-model.ts
1709
- var import_provider_utils8 = require("@ai-sdk/provider-utils");
1710
- var import_zod11 = require("zod");
1711
- var OpenAIProviderOptionsSchema = import_zod11.z.object({
1712
- instructions: import_zod11.z.string().nullish(),
1713
- speed: import_zod11.z.number().min(0.25).max(4).default(1).nullish()
1872
+ var import_provider_utils10 = require("@ai-sdk/provider-utils");
1873
+ var import_v413 = require("zod/v4");
1874
+ var OpenAIProviderOptionsSchema = import_v413.z.object({
1875
+ instructions: import_v413.z.string().nullish(),
1876
+ speed: import_v413.z.number().min(0.25).max(4).default(1).nullish()
1714
1877
  });
1715
1878
  var OpenAISpeechModel = class {
1716
1879
  constructor(modelId, config) {
1717
1880
  this.modelId = modelId;
1718
1881
  this.config = config;
1719
- this.specificationVersion = "v1";
1882
+ this.specificationVersion = "v2";
1720
1883
  }
1721
1884
  get provider() {
1722
1885
  return this.config.provider;
@@ -1727,10 +1890,11 @@ var OpenAISpeechModel = class {
1727
1890
  outputFormat = "mp3",
1728
1891
  speed,
1729
1892
  instructions,
1893
+ language,
1730
1894
  providerOptions
1731
1895
  }) {
1732
1896
  const warnings = [];
1733
- const openAIOptions = await (0, import_provider_utils8.parseProviderOptions)({
1897
+ const openAIOptions = await (0, import_provider_utils10.parseProviderOptions)({
1734
1898
  provider: "openai",
1735
1899
  providerOptions,
1736
1900
  schema: OpenAIProviderOptionsSchema
@@ -1763,6 +1927,13 @@ var OpenAISpeechModel = class {
1763
1927
  }
1764
1928
  }
1765
1929
  }
1930
+ if (language) {
1931
+ warnings.push({
1932
+ type: "unsupported-setting",
1933
+ setting: "language",
1934
+ details: `OpenAI speech models do not support language selection. Language parameter "${language}" was ignored.`
1935
+ });
1936
+ }
1766
1937
  return {
1767
1938
  requestBody,
1768
1939
  warnings
@@ -1776,15 +1947,15 @@ var OpenAISpeechModel = class {
1776
1947
  value: audio,
1777
1948
  responseHeaders,
1778
1949
  rawValue: rawResponse
1779
- } = await (0, import_provider_utils8.postJsonToApi)({
1950
+ } = await (0, import_provider_utils10.postJsonToApi)({
1780
1951
  url: this.config.url({
1781
1952
  path: "/audio/speech",
1782
1953
  modelId: this.modelId
1783
1954
  }),
1784
- headers: (0, import_provider_utils8.combineHeaders)(this.config.headers(), options.headers),
1955
+ headers: (0, import_provider_utils10.combineHeaders)(this.config.headers(), options.headers),
1785
1956
  body: requestBody,
1786
1957
  failedResponseHandler: openaiFailedResponseHandler,
1787
- successfulResponseHandler: (0, import_provider_utils8.createBinaryResponseHandler)(),
1958
+ successfulResponseHandler: (0, import_provider_utils10.createBinaryResponseHandler)(),
1788
1959
  abortSignal: options.abortSignal,
1789
1960
  fetch: this.config.fetch
1790
1961
  });
@@ -1805,15 +1976,19 @@ var OpenAISpeechModel = class {
1805
1976
  };
1806
1977
 
1807
1978
  // src/responses/openai-responses-language-model.ts
1808
- var import_provider_utils9 = require("@ai-sdk/provider-utils");
1809
- var import_zod12 = require("zod");
1979
+ var import_provider8 = require("@ai-sdk/provider");
1980
+ var import_provider_utils12 = require("@ai-sdk/provider-utils");
1981
+ var import_v415 = require("zod/v4");
1810
1982
 
1811
1983
  // src/responses/convert-to-openai-responses-messages.ts
1812
1984
  var import_provider6 = require("@ai-sdk/provider");
1813
- function convertToOpenAIResponsesMessages({
1985
+ var import_provider_utils11 = require("@ai-sdk/provider-utils");
1986
+ var import_v414 = require("zod/v4");
1987
+ async function convertToOpenAIResponsesMessages({
1814
1988
  prompt,
1815
1989
  systemMessageMode
1816
1990
  }) {
1991
+ var _a, _b, _c, _d, _e, _f;
1817
1992
  const messages = [];
1818
1993
  const warnings = [];
1819
1994
  for (const { role, content } of prompt) {
@@ -1848,7 +2023,7 @@ function convertToOpenAIResponsesMessages({
1848
2023
  messages.push({
1849
2024
  role: "user",
1850
2025
  content: content.map((part, index) => {
1851
- var _a, _b, _c;
2026
+ var _a2, _b2, _c2;
1852
2027
  switch (part.type) {
1853
2028
  case "text": {
1854
2029
  return { type: "input_text", text: part.text };
@@ -1860,7 +2035,7 @@ function convertToOpenAIResponsesMessages({
1860
2035
  type: "input_image",
1861
2036
  image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
1862
2037
  // OpenAI specific extension: image detail
1863
- detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
2038
+ detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
1864
2039
  };
1865
2040
  } else if (part.mediaType === "application/pdf") {
1866
2041
  if (part.data instanceof URL) {
@@ -1870,7 +2045,7 @@ function convertToOpenAIResponsesMessages({
1870
2045
  }
1871
2046
  return {
1872
2047
  type: "input_file",
1873
- filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
2048
+ filename: (_c2 = part.filename) != null ? _c2 : `part-${index}.pdf`,
1874
2049
  file_data: `data:application/pdf;base64,${part.data}`
1875
2050
  };
1876
2051
  } else {
@@ -1885,22 +2060,72 @@ function convertToOpenAIResponsesMessages({
1885
2060
  break;
1886
2061
  }
1887
2062
  case "assistant": {
2063
+ const reasoningMessages = {};
1888
2064
  for (const part of content) {
1889
2065
  switch (part.type) {
1890
2066
  case "text": {
1891
2067
  messages.push({
1892
2068
  role: "assistant",
1893
- content: [{ type: "output_text", text: part.text }]
2069
+ content: [{ type: "output_text", text: part.text }],
2070
+ id: (_c = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.itemId) != null ? _c : void 0
1894
2071
  });
1895
2072
  break;
1896
2073
  }
1897
2074
  case "tool-call": {
2075
+ if (part.providerExecuted) {
2076
+ break;
2077
+ }
1898
2078
  messages.push({
1899
2079
  type: "function_call",
1900
2080
  call_id: part.toolCallId,
1901
2081
  name: part.toolName,
1902
- arguments: JSON.stringify(part.args)
2082
+ arguments: JSON.stringify(part.input),
2083
+ id: (_f = (_e = (_d = part.providerOptions) == null ? void 0 : _d.openai) == null ? void 0 : _e.itemId) != null ? _f : void 0
2084
+ });
2085
+ break;
2086
+ }
2087
+ case "tool-result": {
2088
+ warnings.push({
2089
+ type: "other",
2090
+ message: `tool result parts in assistant messages are not supported for OpenAI responses`
2091
+ });
2092
+ break;
2093
+ }
2094
+ case "reasoning": {
2095
+ const providerOptions = await (0, import_provider_utils11.parseProviderOptions)({
2096
+ provider: "openai",
2097
+ providerOptions: part.providerOptions,
2098
+ schema: openaiResponsesReasoningProviderOptionsSchema
1903
2099
  });
2100
+ const reasoningId = providerOptions == null ? void 0 : providerOptions.itemId;
2101
+ if (reasoningId != null) {
2102
+ const existingReasoningMessage = reasoningMessages[reasoningId];
2103
+ const summaryParts = [];
2104
+ if (part.text.length > 0) {
2105
+ summaryParts.push({ type: "summary_text", text: part.text });
2106
+ } else if (existingReasoningMessage !== void 0) {
2107
+ warnings.push({
2108
+ type: "other",
2109
+ message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(part)}.`
2110
+ });
2111
+ }
2112
+ if (existingReasoningMessage === void 0) {
2113
+ reasoningMessages[reasoningId] = {
2114
+ type: "reasoning",
2115
+ id: reasoningId,
2116
+ encrypted_content: providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent,
2117
+ summary: summaryParts
2118
+ };
2119
+ messages.push(reasoningMessages[reasoningId]);
2120
+ } else {
2121
+ existingReasoningMessage.summary.push(...summaryParts);
2122
+ }
2123
+ } else {
2124
+ warnings.push({
2125
+ type: "other",
2126
+ message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
2127
+ });
2128
+ }
1904
2129
  break;
1905
2130
  }
1906
2131
  }
@@ -1909,10 +2134,23 @@ function convertToOpenAIResponsesMessages({
1909
2134
  }
1910
2135
  case "tool": {
1911
2136
  for (const part of content) {
2137
+ const output = part.output;
2138
+ let contentValue;
2139
+ switch (output.type) {
2140
+ case "text":
2141
+ case "error-text":
2142
+ contentValue = output.value;
2143
+ break;
2144
+ case "content":
2145
+ case "json":
2146
+ case "error-json":
2147
+ contentValue = JSON.stringify(output.value);
2148
+ break;
2149
+ }
1912
2150
  messages.push({
1913
2151
  type: "function_call_output",
1914
2152
  call_id: part.toolCallId,
1915
- output: JSON.stringify(part.result)
2153
+ output: contentValue
1916
2154
  });
1917
2155
  }
1918
2156
  break;
@@ -1925,6 +2163,10 @@ function convertToOpenAIResponsesMessages({
1925
2163
  }
1926
2164
  return { messages, warnings };
1927
2165
  }
2166
+ var openaiResponsesReasoningProviderOptionsSchema = import_v414.z.object({
2167
+ itemId: import_v414.z.string().nullish(),
2168
+ reasoningEncryptedContent: import_v414.z.string().nullish()
2169
+ });
1928
2170
 
1929
2171
  // src/responses/map-openai-responses-finish-reason.ts
1930
2172
  function mapOpenAIResponseFinishReason({
@@ -1949,7 +2191,7 @@ var import_provider7 = require("@ai-sdk/provider");
1949
2191
  function prepareResponsesTools({
1950
2192
  tools,
1951
2193
  toolChoice,
1952
- strict
2194
+ strictJsonSchema
1953
2195
  }) {
1954
2196
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
1955
2197
  const toolWarnings = [];
@@ -1964,12 +2206,22 @@ function prepareResponsesTools({
1964
2206
  type: "function",
1965
2207
  name: tool.name,
1966
2208
  description: tool.description,
1967
- parameters: tool.parameters,
1968
- strict: strict ? true : void 0
2209
+ parameters: tool.inputSchema,
2210
+ strict: strictJsonSchema
1969
2211
  });
1970
2212
  break;
1971
2213
  case "provider-defined":
1972
2214
  switch (tool.id) {
2215
+ case "openai.file_search": {
2216
+ const args = fileSearchArgsSchema.parse(tool.args);
2217
+ openaiTools.push({
2218
+ type: "file_search",
2219
+ vector_store_ids: args.vectorStoreIds,
2220
+ max_results: args.maxResults,
2221
+ search_type: args.searchType
2222
+ });
2223
+ break;
2224
+ }
1973
2225
  case "openai.web_search_preview":
1974
2226
  openaiTools.push({
1975
2227
  type: "web_search_preview",
@@ -1999,7 +2251,7 @@ function prepareResponsesTools({
1999
2251
  case "tool":
2000
2252
  return {
2001
2253
  tools: openaiTools,
2002
- toolChoice: toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
2254
+ toolChoice: toolChoice.toolName === "file_search" ? { type: "file_search" } : toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
2003
2255
  toolWarnings
2004
2256
  };
2005
2257
  default: {
@@ -2063,17 +2315,17 @@ var OpenAIResponsesLanguageModel = class {
2063
2315
  if (stopSequences != null) {
2064
2316
  warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
2065
2317
  }
2066
- const { messages, warnings: messageWarnings } = convertToOpenAIResponsesMessages({
2318
+ const { messages, warnings: messageWarnings } = await convertToOpenAIResponsesMessages({
2067
2319
  prompt,
2068
2320
  systemMessageMode: modelConfig.systemMessageMode
2069
2321
  });
2070
2322
  warnings.push(...messageWarnings);
2071
- const openaiOptions = await (0, import_provider_utils9.parseProviderOptions)({
2323
+ const openaiOptions = await (0, import_provider_utils12.parseProviderOptions)({
2072
2324
  provider: "openai",
2073
2325
  providerOptions,
2074
2326
  schema: openaiResponsesProviderOptionsSchema
2075
2327
  });
2076
- const isStrict = (_a = openaiOptions == null ? void 0 : openaiOptions.strictSchemas) != null ? _a : true;
2328
+ const strictJsonSchema = (_a = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _a : false;
2077
2329
  const baseArgs = {
2078
2330
  model: this.modelId,
2079
2331
  input: messages,
@@ -2084,7 +2336,7 @@ var OpenAIResponsesLanguageModel = class {
2084
2336
  text: {
2085
2337
  format: responseFormat.schema != null ? {
2086
2338
  type: "json_schema",
2087
- strict: isStrict,
2339
+ strict: strictJsonSchema,
2088
2340
  name: (_b = responseFormat.name) != null ? _b : "response",
2089
2341
  description: responseFormat.description,
2090
2342
  schema: responseFormat.schema
@@ -2098,6 +2350,8 @@ var OpenAIResponsesLanguageModel = class {
2098
2350
  store: openaiOptions == null ? void 0 : openaiOptions.store,
2099
2351
  user: openaiOptions == null ? void 0 : openaiOptions.user,
2100
2352
  instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
2353
+ service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
2354
+ include: openaiOptions == null ? void 0 : openaiOptions.include,
2101
2355
  // model-specific settings:
2102
2356
  ...modelConfig.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
2103
2357
  reasoning: {
@@ -2130,6 +2384,29 @@ var OpenAIResponsesLanguageModel = class {
2130
2384
  details: "topP is not supported for reasoning models"
2131
2385
  });
2132
2386
  }
2387
+ } else {
2388
+ if ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null) {
2389
+ warnings.push({
2390
+ type: "unsupported-setting",
2391
+ setting: "reasoningEffort",
2392
+ details: "reasoningEffort is not supported for non-reasoning models"
2393
+ });
2394
+ }
2395
+ if ((openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) {
2396
+ warnings.push({
2397
+ type: "unsupported-setting",
2398
+ setting: "reasoningSummary",
2399
+ details: "reasoningSummary is not supported for non-reasoning models"
2400
+ });
2401
+ }
2402
+ }
2403
+ if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !supportsFlexProcessing2(this.modelId)) {
2404
+ warnings.push({
2405
+ type: "unsupported-setting",
2406
+ setting: "serviceTier",
2407
+ details: "flex processing is only available for o3 and o4-mini models"
2408
+ });
2409
+ delete baseArgs.service_tier;
2133
2410
  }
2134
2411
  const {
2135
2412
  tools: openaiTools,
@@ -2138,7 +2415,7 @@ var OpenAIResponsesLanguageModel = class {
2138
2415
  } = prepareResponsesTools({
2139
2416
  tools,
2140
2417
  toolChoice,
2141
- strict: isStrict
2418
+ strictJsonSchema
2142
2419
  });
2143
2420
  return {
2144
2421
  args: {
@@ -2150,97 +2427,137 @@ var OpenAIResponsesLanguageModel = class {
2150
2427
  };
2151
2428
  }
2152
2429
  async doGenerate(options) {
2153
- var _a, _b, _c, _d, _e, _f, _g, _h;
2430
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
2154
2431
  const { args: body, warnings } = await this.getArgs(options);
2432
+ const url = this.config.url({
2433
+ path: "/responses",
2434
+ modelId: this.modelId
2435
+ });
2155
2436
  const {
2156
2437
  responseHeaders,
2157
2438
  value: response,
2158
2439
  rawValue: rawResponse
2159
- } = await (0, import_provider_utils9.postJsonToApi)({
2160
- url: this.config.url({
2161
- path: "/responses",
2162
- modelId: this.modelId
2163
- }),
2164
- headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
2440
+ } = await (0, import_provider_utils12.postJsonToApi)({
2441
+ url,
2442
+ headers: (0, import_provider_utils12.combineHeaders)(this.config.headers(), options.headers),
2165
2443
  body,
2166
2444
  failedResponseHandler: openaiFailedResponseHandler,
2167
- successfulResponseHandler: (0, import_provider_utils9.createJsonResponseHandler)(
2168
- import_zod12.z.object({
2169
- id: import_zod12.z.string(),
2170
- created_at: import_zod12.z.number(),
2171
- model: import_zod12.z.string(),
2172
- output: import_zod12.z.array(
2173
- import_zod12.z.discriminatedUnion("type", [
2174
- import_zod12.z.object({
2175
- type: import_zod12.z.literal("message"),
2176
- role: import_zod12.z.literal("assistant"),
2177
- content: import_zod12.z.array(
2178
- import_zod12.z.object({
2179
- type: import_zod12.z.literal("output_text"),
2180
- text: import_zod12.z.string(),
2181
- annotations: import_zod12.z.array(
2182
- import_zod12.z.object({
2183
- type: import_zod12.z.literal("url_citation"),
2184
- start_index: import_zod12.z.number(),
2185
- end_index: import_zod12.z.number(),
2186
- url: import_zod12.z.string(),
2187
- title: import_zod12.z.string()
2445
+ successfulResponseHandler: (0, import_provider_utils12.createJsonResponseHandler)(
2446
+ import_v415.z.object({
2447
+ id: import_v415.z.string(),
2448
+ created_at: import_v415.z.number(),
2449
+ error: import_v415.z.object({
2450
+ code: import_v415.z.string(),
2451
+ message: import_v415.z.string()
2452
+ }).nullish(),
2453
+ model: import_v415.z.string(),
2454
+ output: import_v415.z.array(
2455
+ import_v415.z.discriminatedUnion("type", [
2456
+ import_v415.z.object({
2457
+ type: import_v415.z.literal("message"),
2458
+ role: import_v415.z.literal("assistant"),
2459
+ id: import_v415.z.string(),
2460
+ content: import_v415.z.array(
2461
+ import_v415.z.object({
2462
+ type: import_v415.z.literal("output_text"),
2463
+ text: import_v415.z.string(),
2464
+ annotations: import_v415.z.array(
2465
+ import_v415.z.object({
2466
+ type: import_v415.z.literal("url_citation"),
2467
+ start_index: import_v415.z.number(),
2468
+ end_index: import_v415.z.number(),
2469
+ url: import_v415.z.string(),
2470
+ title: import_v415.z.string()
2188
2471
  })
2189
2472
  )
2190
2473
  })
2191
2474
  )
2192
2475
  }),
2193
- import_zod12.z.object({
2194
- type: import_zod12.z.literal("function_call"),
2195
- call_id: import_zod12.z.string(),
2196
- name: import_zod12.z.string(),
2197
- arguments: import_zod12.z.string()
2476
+ import_v415.z.object({
2477
+ type: import_v415.z.literal("function_call"),
2478
+ call_id: import_v415.z.string(),
2479
+ name: import_v415.z.string(),
2480
+ arguments: import_v415.z.string(),
2481
+ id: import_v415.z.string()
2198
2482
  }),
2199
- import_zod12.z.object({
2200
- type: import_zod12.z.literal("web_search_call")
2483
+ import_v415.z.object({
2484
+ type: import_v415.z.literal("web_search_call"),
2485
+ id: import_v415.z.string(),
2486
+ status: import_v415.z.string().optional()
2201
2487
  }),
2202
- import_zod12.z.object({
2203
- type: import_zod12.z.literal("computer_call")
2488
+ import_v415.z.object({
2489
+ type: import_v415.z.literal("computer_call"),
2490
+ id: import_v415.z.string(),
2491
+ status: import_v415.z.string().optional()
2204
2492
  }),
2205
- import_zod12.z.object({
2206
- type: import_zod12.z.literal("reasoning"),
2207
- summary: import_zod12.z.array(
2208
- import_zod12.z.object({
2209
- type: import_zod12.z.literal("summary_text"),
2210
- text: import_zod12.z.string()
2493
+ import_v415.z.object({
2494
+ type: import_v415.z.literal("reasoning"),
2495
+ id: import_v415.z.string(),
2496
+ encrypted_content: import_v415.z.string().nullish(),
2497
+ summary: import_v415.z.array(
2498
+ import_v415.z.object({
2499
+ type: import_v415.z.literal("summary_text"),
2500
+ text: import_v415.z.string()
2211
2501
  })
2212
2502
  )
2213
2503
  })
2214
2504
  ])
2215
2505
  ),
2216
- incomplete_details: import_zod12.z.object({ reason: import_zod12.z.string() }).nullable(),
2506
+ incomplete_details: import_v415.z.object({ reason: import_v415.z.string() }).nullable(),
2217
2507
  usage: usageSchema2
2218
2508
  })
2219
2509
  ),
2220
2510
  abortSignal: options.abortSignal,
2221
2511
  fetch: this.config.fetch
2222
2512
  });
2513
+ if (response.error) {
2514
+ throw new import_provider8.APICallError({
2515
+ message: response.error.message,
2516
+ url,
2517
+ requestBodyValues: body,
2518
+ statusCode: 400,
2519
+ responseHeaders,
2520
+ responseBody: rawResponse,
2521
+ isRetryable: false
2522
+ });
2523
+ }
2223
2524
  const content = [];
2224
2525
  for (const part of response.output) {
2225
2526
  switch (part.type) {
2226
2527
  case "reasoning": {
2227
- content.push({
2228
- type: "reasoning",
2229
- text: part.summary.map((summary) => summary.text).join()
2230
- });
2528
+ if (part.summary.length === 0) {
2529
+ part.summary.push({ type: "summary_text", text: "" });
2530
+ }
2531
+ for (const summary of part.summary) {
2532
+ content.push({
2533
+ type: "reasoning",
2534
+ text: summary.text,
2535
+ providerMetadata: {
2536
+ openai: {
2537
+ itemId: part.id,
2538
+ reasoningEncryptedContent: (_a = part.encrypted_content) != null ? _a : null
2539
+ }
2540
+ }
2541
+ });
2542
+ }
2231
2543
  break;
2232
2544
  }
2233
2545
  case "message": {
2234
2546
  for (const contentPart of part.content) {
2235
2547
  content.push({
2236
2548
  type: "text",
2237
- text: contentPart.text
2549
+ text: contentPart.text,
2550
+ providerMetadata: {
2551
+ openai: {
2552
+ itemId: part.id
2553
+ }
2554
+ }
2238
2555
  });
2239
2556
  for (const annotation of contentPart.annotations) {
2240
2557
  content.push({
2241
2558
  type: "source",
2242
2559
  sourceType: "url",
2243
- id: (_c = (_b = (_a = this.config).generateId) == null ? void 0 : _b.call(_a)) != null ? _c : (0, import_provider_utils9.generateId)(),
2560
+ id: (_d = (_c = (_b = this.config).generateId) == null ? void 0 : _c.call(_b)) != null ? _d : (0, import_provider_utils12.generateId)(),
2244
2561
  url: annotation.url,
2245
2562
  title: annotation.title
2246
2563
  });
@@ -2251,10 +2568,51 @@ var OpenAIResponsesLanguageModel = class {
2251
2568
  case "function_call": {
2252
2569
  content.push({
2253
2570
  type: "tool-call",
2254
- toolCallType: "function",
2255
2571
  toolCallId: part.call_id,
2256
2572
  toolName: part.name,
2257
- args: part.arguments
2573
+ input: part.arguments,
2574
+ providerMetadata: {
2575
+ openai: {
2576
+ itemId: part.id
2577
+ }
2578
+ }
2579
+ });
2580
+ break;
2581
+ }
2582
+ case "web_search_call": {
2583
+ content.push({
2584
+ type: "tool-call",
2585
+ toolCallId: part.id,
2586
+ toolName: "web_search_preview",
2587
+ input: "",
2588
+ providerExecuted: true
2589
+ });
2590
+ content.push({
2591
+ type: "tool-result",
2592
+ toolCallId: part.id,
2593
+ toolName: "web_search_preview",
2594
+ result: { status: part.status || "completed" },
2595
+ providerExecuted: true
2596
+ });
2597
+ break;
2598
+ }
2599
+ case "computer_call": {
2600
+ content.push({
2601
+ type: "tool-call",
2602
+ toolCallId: part.id,
2603
+ toolName: "computer_use",
2604
+ input: "",
2605
+ providerExecuted: true
2606
+ });
2607
+ content.push({
2608
+ type: "tool-result",
2609
+ toolCallId: part.id,
2610
+ toolName: "computer_use",
2611
+ result: {
2612
+ type: "computer_use_tool_result",
2613
+ status: part.status || "completed"
2614
+ },
2615
+ providerExecuted: true
2258
2616
  });
2259
2617
  break;
2260
2618
  }
@@ -2263,15 +2621,15 @@ var OpenAIResponsesLanguageModel = class {
2263
2621
  return {
2264
2622
  content,
2265
2623
  finishReason: mapOpenAIResponseFinishReason({
2266
- finishReason: (_d = response.incomplete_details) == null ? void 0 : _d.reason,
2624
+ finishReason: (_e = response.incomplete_details) == null ? void 0 : _e.reason,
2267
2625
  hasToolCalls: content.some((part) => part.type === "tool-call")
2268
2626
  }),
2269
2627
  usage: {
2270
2628
  inputTokens: response.usage.input_tokens,
2271
2629
  outputTokens: response.usage.output_tokens,
2272
2630
  totalTokens: response.usage.input_tokens + response.usage.output_tokens,
2273
- reasoningTokens: (_f = (_e = response.usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : void 0,
2274
- cachedInputTokens: (_h = (_g = response.usage.input_tokens_details) == null ? void 0 : _g.cached_tokens) != null ? _h : void 0
2631
+ reasoningTokens: (_g = (_f = response.usage.output_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : void 0,
2632
+ cachedInputTokens: (_i = (_h = response.usage.input_tokens_details) == null ? void 0 : _h.cached_tokens) != null ? _i : void 0
2275
2633
  },
2276
2634
  request: { body },
2277
2635
  response: {
@@ -2291,18 +2649,18 @@ var OpenAIResponsesLanguageModel = class {
2291
2649
  }
2292
2650
  async doStream(options) {
2293
2651
  const { args: body, warnings } = await this.getArgs(options);
2294
- const { responseHeaders, value: response } = await (0, import_provider_utils9.postJsonToApi)({
2652
+ const { responseHeaders, value: response } = await (0, import_provider_utils12.postJsonToApi)({
2295
2653
  url: this.config.url({
2296
2654
  path: "/responses",
2297
2655
  modelId: this.modelId
2298
2656
  }),
2299
- headers: (0, import_provider_utils9.combineHeaders)(this.config.headers(), options.headers),
2657
+ headers: (0, import_provider_utils12.combineHeaders)(this.config.headers(), options.headers),
2300
2658
  body: {
2301
2659
  ...body,
2302
2660
  stream: true
2303
2661
  },
2304
2662
  failedResponseHandler: openaiFailedResponseHandler,
2305
- successfulResponseHandler: (0, import_provider_utils9.createEventSourceResponseHandler)(
2663
+ successfulResponseHandler: (0, import_provider_utils12.createEventSourceResponseHandler)(
2306
2664
  openaiResponsesChunkSchema
2307
2665
  ),
2308
2666
  abortSignal: options.abortSignal,
@@ -2318,6 +2676,7 @@ var OpenAIResponsesLanguageModel = class {
2318
2676
  let responseId = null;
2319
2677
  const ongoingToolCalls = {};
2320
2678
  let hasToolCalls = false;
2679
+ const activeReasoning = {};
2321
2680
  return {
2322
2681
  stream: response.pipeThrough(
2323
2682
  new TransformStream({
@@ -2325,7 +2684,10 @@ var OpenAIResponsesLanguageModel = class {
2325
2684
  controller.enqueue({ type: "stream-start", warnings });
2326
2685
  },
2327
2686
  transform(chunk, controller) {
2328
- var _a, _b, _c, _d, _e, _f, _g, _h;
2687
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
2688
+ if (options.includeRawChunks) {
2689
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2690
+ }
2329
2691
  if (!chunk.success) {
2330
2692
  finishReason = "error";
2331
2693
  controller.enqueue({ type: "error", error: chunk.error });
@@ -2339,22 +2701,151 @@ var OpenAIResponsesLanguageModel = class {
2339
2701
  toolCallId: value.item.call_id
2340
2702
  };
2341
2703
  controller.enqueue({
2342
- type: "tool-call-delta",
2343
- toolCallType: "function",
2704
+ type: "tool-input-start",
2705
+ id: value.item.call_id,
2706
+ toolName: value.item.name
2707
+ });
2708
+ } else if (value.item.type === "web_search_call") {
2709
+ ongoingToolCalls[value.output_index] = {
2710
+ toolName: "web_search_preview",
2711
+ toolCallId: value.item.id
2712
+ };
2713
+ controller.enqueue({
2714
+ type: "tool-input-start",
2715
+ id: value.item.id,
2716
+ toolName: "web_search_preview"
2717
+ });
2718
+ } else if (value.item.type === "computer_call") {
2719
+ ongoingToolCalls[value.output_index] = {
2720
+ toolName: "computer_use",
2721
+ toolCallId: value.item.id
2722
+ };
2723
+ controller.enqueue({
2724
+ type: "tool-input-start",
2725
+ id: value.item.id,
2726
+ toolName: "computer_use"
2727
+ });
2728
+ } else if (value.item.type === "message") {
2729
+ controller.enqueue({
2730
+ type: "text-start",
2731
+ id: value.item.id,
2732
+ providerMetadata: {
2733
+ openai: {
2734
+ itemId: value.item.id
2735
+ }
2736
+ }
2737
+ });
2738
+ } else if (isResponseOutputItemAddedReasoningChunk(value)) {
2739
+ activeReasoning[value.item.id] = {
2740
+ encryptedContent: value.item.encrypted_content,
2741
+ summaryParts: [0]
2742
+ };
2743
+ controller.enqueue({
2744
+ type: "reasoning-start",
2745
+ id: `${value.item.id}:0`,
2746
+ providerMetadata: {
2747
+ openai: {
2748
+ itemId: value.item.id,
2749
+ reasoningEncryptedContent: (_a = value.item.encrypted_content) != null ? _a : null
2750
+ }
2751
+ }
2752
+ });
2753
+ }
2754
+ } else if (isResponseOutputItemDoneChunk(value)) {
2755
+ if (value.item.type === "function_call") {
2756
+ ongoingToolCalls[value.output_index] = void 0;
2757
+ hasToolCalls = true;
2758
+ controller.enqueue({
2759
+ type: "tool-input-end",
2760
+ id: value.item.call_id
2761
+ });
2762
+ controller.enqueue({
2763
+ type: "tool-call",
2344
2764
  toolCallId: value.item.call_id,
2345
2765
  toolName: value.item.name,
2346
- argsTextDelta: value.item.arguments
2766
+ input: value.item.arguments,
2767
+ providerMetadata: {
2768
+ openai: {
2769
+ itemId: value.item.id
2770
+ }
2771
+ }
2772
+ });
2773
+ } else if (value.item.type === "web_search_call") {
2774
+ ongoingToolCalls[value.output_index] = void 0;
2775
+ hasToolCalls = true;
2776
+ controller.enqueue({
2777
+ type: "tool-input-end",
2778
+ id: value.item.id
2779
+ });
2780
+ controller.enqueue({
2781
+ type: "tool-call",
2782
+ toolCallId: value.item.id,
2783
+ toolName: "web_search_preview",
2784
+ input: "",
2785
+ providerExecuted: true
2786
+ });
2787
+ controller.enqueue({
2788
+ type: "tool-result",
2789
+ toolCallId: value.item.id,
2790
+ toolName: "web_search_preview",
2791
+ result: {
2792
+ type: "web_search_tool_result",
2793
+ status: value.item.status || "completed"
2794
+ },
2795
+ providerExecuted: true
2796
+ });
2797
+ } else if (value.item.type === "computer_call") {
2798
+ ongoingToolCalls[value.output_index] = void 0;
2799
+ hasToolCalls = true;
2800
+ controller.enqueue({
2801
+ type: "tool-input-end",
2802
+ id: value.item.id
2803
+ });
2804
+ controller.enqueue({
2805
+ type: "tool-call",
2806
+ toolCallId: value.item.id,
2807
+ toolName: "computer_use",
2808
+ input: "",
2809
+ providerExecuted: true
2810
+ });
2811
+ controller.enqueue({
2812
+ type: "tool-result",
2813
+ toolCallId: value.item.id,
2814
+ toolName: "computer_use",
2815
+ result: {
2816
+ type: "computer_use_tool_result",
2817
+ status: value.item.status || "completed"
2818
+ },
2819
+ providerExecuted: true
2347
2820
  });
2821
+ } else if (value.item.type === "message") {
2822
+ controller.enqueue({
2823
+ type: "text-end",
2824
+ id: value.item.id
2825
+ });
2826
+ } else if (isResponseOutputItemDoneReasoningChunk(value)) {
2827
+ const activeReasoningPart = activeReasoning[value.item.id];
2828
+ for (const summaryIndex of activeReasoningPart.summaryParts) {
2829
+ controller.enqueue({
2830
+ type: "reasoning-end",
2831
+ id: `${value.item.id}:${summaryIndex}`,
2832
+ providerMetadata: {
2833
+ openai: {
2834
+ itemId: value.item.id,
2835
+ reasoningEncryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
2836
+ }
2837
+ }
2838
+ });
2839
+ }
2840
+ delete activeReasoning[value.item.id];
2348
2841
  }
2349
2842
  } else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
2350
2843
  const toolCall = ongoingToolCalls[value.output_index];
2351
2844
  if (toolCall != null) {
2352
2845
  controller.enqueue({
2353
- type: "tool-call-delta",
2354
- toolCallType: "function",
2355
- toolCallId: toolCall.toolCallId,
2356
- toolName: toolCall.toolName,
2357
- argsTextDelta: value.delta
2846
+ type: "tool-input-delta",
2847
+ id: toolCall.toolCallId,
2848
+ delta: value.delta
2358
2849
  });
2359
2850
  }
2360
2851
  } else if (isResponseCreatedChunk(value)) {
@@ -2367,42 +2858,57 @@ var OpenAIResponsesLanguageModel = class {
2367
2858
  });
2368
2859
  } else if (isTextDeltaChunk(value)) {
2369
2860
  controller.enqueue({
2370
- type: "text",
2371
- text: value.delta
2861
+ type: "text-delta",
2862
+ id: value.item_id,
2863
+ delta: value.delta
2372
2864
  });
2865
+ } else if (isResponseReasoningSummaryPartAddedChunk(value)) {
2866
+ if (value.summary_index > 0) {
2867
+ (_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
2868
+ value.summary_index
2869
+ );
2870
+ controller.enqueue({
2871
+ type: "reasoning-start",
2872
+ id: `${value.item_id}:${value.summary_index}`,
2873
+ providerMetadata: {
2874
+ openai: {
2875
+ itemId: value.item_id,
2876
+ reasoningEncryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
2877
+ }
2878
+ }
2879
+ });
2880
+ }
2373
2881
  } else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
2374
2882
  controller.enqueue({
2375
- type: "reasoning",
2376
- text: value.delta
2377
- });
2378
- } else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
2379
- ongoingToolCalls[value.output_index] = void 0;
2380
- hasToolCalls = true;
2381
- controller.enqueue({
2382
- type: "tool-call",
2383
- toolCallType: "function",
2384
- toolCallId: value.item.call_id,
2385
- toolName: value.item.name,
2386
- args: value.item.arguments
2883
+ type: "reasoning-delta",
2884
+ id: `${value.item_id}:${value.summary_index}`,
2885
+ delta: value.delta,
2886
+ providerMetadata: {
2887
+ openai: {
2888
+ itemId: value.item_id
2889
+ }
2890
+ }
2387
2891
  });
2388
2892
  } else if (isResponseFinishedChunk(value)) {
2389
2893
  finishReason = mapOpenAIResponseFinishReason({
2390
- finishReason: (_a = value.response.incomplete_details) == null ? void 0 : _a.reason,
2894
+ finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
2391
2895
  hasToolCalls
2392
2896
  });
2393
2897
  usage.inputTokens = value.response.usage.input_tokens;
2394
2898
  usage.outputTokens = value.response.usage.output_tokens;
2395
2899
  usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
2396
- usage.reasoningTokens = (_c = (_b = value.response.usage.output_tokens_details) == null ? void 0 : _b.reasoning_tokens) != null ? _c : void 0;
2397
- usage.cachedInputTokens = (_e = (_d = value.response.usage.input_tokens_details) == null ? void 0 : _d.cached_tokens) != null ? _e : void 0;
2900
+ usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
2901
+ usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
2398
2902
  } else if (isResponseAnnotationAddedChunk(value)) {
2399
2903
  controller.enqueue({
2400
2904
  type: "source",
2401
2905
  sourceType: "url",
2402
- id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils9.generateId)(),
2906
+ id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : (0, import_provider_utils12.generateId)(),
2403
2907
  url: value.annotation.url,
2404
2908
  title: value.annotation.title
2405
2909
  });
2910
+ } else if (isErrorChunk(value)) {
2911
+ controller.enqueue({ type: "error", error: value });
2406
2912
  }
2407
2913
  },
2408
2914
  flush(controller) {
@@ -2424,95 +2930,141 @@ var OpenAIResponsesLanguageModel = class {
2424
2930
  };
2425
2931
  }
2426
2932
  };
2427
- var usageSchema2 = import_zod12.z.object({
2428
- input_tokens: import_zod12.z.number(),
2429
- input_tokens_details: import_zod12.z.object({ cached_tokens: import_zod12.z.number().nullish() }).nullish(),
2430
- output_tokens: import_zod12.z.number(),
2431
- output_tokens_details: import_zod12.z.object({ reasoning_tokens: import_zod12.z.number().nullish() }).nullish()
2933
+ var usageSchema2 = import_v415.z.object({
2934
+ input_tokens: import_v415.z.number(),
2935
+ input_tokens_details: import_v415.z.object({ cached_tokens: import_v415.z.number().nullish() }).nullish(),
2936
+ output_tokens: import_v415.z.number(),
2937
+ output_tokens_details: import_v415.z.object({ reasoning_tokens: import_v415.z.number().nullish() }).nullish()
2938
+ });
2939
+ var textDeltaChunkSchema = import_v415.z.object({
2940
+ type: import_v415.z.literal("response.output_text.delta"),
2941
+ item_id: import_v415.z.string(),
2942
+ delta: import_v415.z.string()
2432
2943
  });
2433
- var textDeltaChunkSchema = import_zod12.z.object({
2434
- type: import_zod12.z.literal("response.output_text.delta"),
2435
- delta: import_zod12.z.string()
2944
+ var errorChunkSchema = import_v415.z.object({
2945
+ type: import_v415.z.literal("error"),
2946
+ code: import_v415.z.string(),
2947
+ message: import_v415.z.string(),
2948
+ param: import_v415.z.string().nullish(),
2949
+ sequence_number: import_v415.z.number()
2436
2950
  });
2437
- var responseFinishedChunkSchema = import_zod12.z.object({
2438
- type: import_zod12.z.enum(["response.completed", "response.incomplete"]),
2439
- response: import_zod12.z.object({
2440
- incomplete_details: import_zod12.z.object({ reason: import_zod12.z.string() }).nullish(),
2951
+ var responseFinishedChunkSchema = import_v415.z.object({
2952
+ type: import_v415.z.enum(["response.completed", "response.incomplete"]),
2953
+ response: import_v415.z.object({
2954
+ incomplete_details: import_v415.z.object({ reason: import_v415.z.string() }).nullish(),
2441
2955
  usage: usageSchema2
2442
2956
  })
2443
2957
  });
2444
- var responseCreatedChunkSchema = import_zod12.z.object({
2445
- type: import_zod12.z.literal("response.created"),
2446
- response: import_zod12.z.object({
2447
- id: import_zod12.z.string(),
2448
- created_at: import_zod12.z.number(),
2449
- model: import_zod12.z.string()
2958
+ var responseCreatedChunkSchema = import_v415.z.object({
2959
+ type: import_v415.z.literal("response.created"),
2960
+ response: import_v415.z.object({
2961
+ id: import_v415.z.string(),
2962
+ created_at: import_v415.z.number(),
2963
+ model: import_v415.z.string()
2450
2964
  })
2451
2965
  });
2452
- var responseOutputItemDoneSchema = import_zod12.z.object({
2453
- type: import_zod12.z.literal("response.output_item.done"),
2454
- output_index: import_zod12.z.number(),
2455
- item: import_zod12.z.discriminatedUnion("type", [
2456
- import_zod12.z.object({
2457
- type: import_zod12.z.literal("message")
2966
+ var responseOutputItemAddedSchema = import_v415.z.object({
2967
+ type: import_v415.z.literal("response.output_item.added"),
2968
+ output_index: import_v415.z.number(),
2969
+ item: import_v415.z.discriminatedUnion("type", [
2970
+ import_v415.z.object({
2971
+ type: import_v415.z.literal("message"),
2972
+ id: import_v415.z.string()
2458
2973
  }),
2459
- import_zod12.z.object({
2460
- type: import_zod12.z.literal("function_call"),
2461
- id: import_zod12.z.string(),
2462
- call_id: import_zod12.z.string(),
2463
- name: import_zod12.z.string(),
2464
- arguments: import_zod12.z.string(),
2465
- status: import_zod12.z.literal("completed")
2974
+ import_v415.z.object({
2975
+ type: import_v415.z.literal("reasoning"),
2976
+ id: import_v415.z.string(),
2977
+ encrypted_content: import_v415.z.string().nullish()
2978
+ }),
2979
+ import_v415.z.object({
2980
+ type: import_v415.z.literal("function_call"),
2981
+ id: import_v415.z.string(),
2982
+ call_id: import_v415.z.string(),
2983
+ name: import_v415.z.string(),
2984
+ arguments: import_v415.z.string()
2985
+ }),
2986
+ import_v415.z.object({
2987
+ type: import_v415.z.literal("web_search_call"),
2988
+ id: import_v415.z.string(),
2989
+ status: import_v415.z.string()
2990
+ }),
2991
+ import_v415.z.object({
2992
+ type: import_v415.z.literal("computer_call"),
2993
+ id: import_v415.z.string(),
2994
+ status: import_v415.z.string()
2466
2995
  })
2467
2996
  ])
2468
2997
  });
2469
- var responseFunctionCallArgumentsDeltaSchema = import_zod12.z.object({
2470
- type: import_zod12.z.literal("response.function_call_arguments.delta"),
2471
- item_id: import_zod12.z.string(),
2472
- output_index: import_zod12.z.number(),
2473
- delta: import_zod12.z.string()
2474
- });
2475
- var responseOutputItemAddedSchema = import_zod12.z.object({
2476
- type: import_zod12.z.literal("response.output_item.added"),
2477
- output_index: import_zod12.z.number(),
2478
- item: import_zod12.z.discriminatedUnion("type", [
2479
- import_zod12.z.object({
2480
- type: import_zod12.z.literal("message")
2998
+ var responseOutputItemDoneSchema = import_v415.z.object({
2999
+ type: import_v415.z.literal("response.output_item.done"),
3000
+ output_index: import_v415.z.number(),
3001
+ item: import_v415.z.discriminatedUnion("type", [
3002
+ import_v415.z.object({
3003
+ type: import_v415.z.literal("message"),
3004
+ id: import_v415.z.string()
2481
3005
  }),
2482
- import_zod12.z.object({
2483
- type: import_zod12.z.literal("function_call"),
2484
- id: import_zod12.z.string(),
2485
- call_id: import_zod12.z.string(),
2486
- name: import_zod12.z.string(),
2487
- arguments: import_zod12.z.string()
3006
+ import_v415.z.object({
3007
+ type: import_v415.z.literal("reasoning"),
3008
+ id: import_v415.z.string(),
3009
+ encrypted_content: import_v415.z.string().nullish()
3010
+ }),
3011
+ import_v415.z.object({
3012
+ type: import_v415.z.literal("function_call"),
3013
+ id: import_v415.z.string(),
3014
+ call_id: import_v415.z.string(),
3015
+ name: import_v415.z.string(),
3016
+ arguments: import_v415.z.string(),
3017
+ status: import_v415.z.literal("completed")
3018
+ }),
3019
+ import_v415.z.object({
3020
+ type: import_v415.z.literal("web_search_call"),
3021
+ id: import_v415.z.string(),
3022
+ status: import_v415.z.literal("completed")
3023
+ }),
3024
+ import_v415.z.object({
3025
+ type: import_v415.z.literal("computer_call"),
3026
+ id: import_v415.z.string(),
3027
+ status: import_v415.z.literal("completed")
2488
3028
  })
2489
3029
  ])
2490
3030
  });
2491
- var responseAnnotationAddedSchema = import_zod12.z.object({
2492
- type: import_zod12.z.literal("response.output_text.annotation.added"),
2493
- annotation: import_zod12.z.object({
2494
- type: import_zod12.z.literal("url_citation"),
2495
- url: import_zod12.z.string(),
2496
- title: import_zod12.z.string()
3031
+ var responseFunctionCallArgumentsDeltaSchema = import_v415.z.object({
3032
+ type: import_v415.z.literal("response.function_call_arguments.delta"),
3033
+ item_id: import_v415.z.string(),
3034
+ output_index: import_v415.z.number(),
3035
+ delta: import_v415.z.string()
3036
+ });
3037
+ var responseAnnotationAddedSchema = import_v415.z.object({
3038
+ type: import_v415.z.literal("response.output_text.annotation.added"),
3039
+ annotation: import_v415.z.object({
3040
+ type: import_v415.z.literal("url_citation"),
3041
+ url: import_v415.z.string(),
3042
+ title: import_v415.z.string()
2497
3043
  })
2498
3044
  });
2499
- var responseReasoningSummaryTextDeltaSchema = import_zod12.z.object({
2500
- type: import_zod12.z.literal("response.reasoning_summary_text.delta"),
2501
- item_id: import_zod12.z.string(),
2502
- output_index: import_zod12.z.number(),
2503
- summary_index: import_zod12.z.number(),
2504
- delta: import_zod12.z.string()
3045
+ var responseReasoningSummaryPartAddedSchema = import_v415.z.object({
3046
+ type: import_v415.z.literal("response.reasoning_summary_part.added"),
3047
+ item_id: import_v415.z.string(),
3048
+ summary_index: import_v415.z.number()
2505
3049
  });
2506
- var openaiResponsesChunkSchema = import_zod12.z.union([
3050
+ var responseReasoningSummaryTextDeltaSchema = import_v415.z.object({
3051
+ type: import_v415.z.literal("response.reasoning_summary_text.delta"),
3052
+ item_id: import_v415.z.string(),
3053
+ summary_index: import_v415.z.number(),
3054
+ delta: import_v415.z.string()
3055
+ });
3056
+ var openaiResponsesChunkSchema = import_v415.z.union([
2507
3057
  textDeltaChunkSchema,
2508
3058
  responseFinishedChunkSchema,
2509
3059
  responseCreatedChunkSchema,
3060
+ responseOutputItemAddedSchema,
2510
3061
  responseOutputItemDoneSchema,
2511
3062
  responseFunctionCallArgumentsDeltaSchema,
2512
- responseOutputItemAddedSchema,
2513
3063
  responseAnnotationAddedSchema,
3064
+ responseReasoningSummaryPartAddedSchema,
2514
3065
  responseReasoningSummaryTextDeltaSchema,
2515
- import_zod12.z.object({ type: import_zod12.z.string() }).passthrough()
3066
+ errorChunkSchema,
3067
+ import_v415.z.object({ type: import_v415.z.string() }).loose()
2516
3068
  // fallback for unknown chunks
2517
3069
  ]);
2518
3070
  function isTextDeltaChunk(chunk) {
@@ -2521,6 +3073,9 @@ function isTextDeltaChunk(chunk) {
2521
3073
  function isResponseOutputItemDoneChunk(chunk) {
2522
3074
  return chunk.type === "response.output_item.done";
2523
3075
  }
3076
+ function isResponseOutputItemDoneReasoningChunk(chunk) {
3077
+ return isResponseOutputItemDoneChunk(chunk) && chunk.item.type === "reasoning";
3078
+ }
2524
3079
  function isResponseFinishedChunk(chunk) {
2525
3080
  return chunk.type === "response.completed" || chunk.type === "response.incomplete";
2526
3081
  }
@@ -2533,14 +3088,23 @@ function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
2533
3088
  function isResponseOutputItemAddedChunk(chunk) {
2534
3089
  return chunk.type === "response.output_item.added";
2535
3090
  }
3091
+ function isResponseOutputItemAddedReasoningChunk(chunk) {
3092
+ return isResponseOutputItemAddedChunk(chunk) && chunk.item.type === "reasoning";
3093
+ }
2536
3094
  function isResponseAnnotationAddedChunk(chunk) {
2537
3095
  return chunk.type === "response.output_text.annotation.added";
2538
3096
  }
3097
+ function isResponseReasoningSummaryPartAddedChunk(chunk) {
3098
+ return chunk.type === "response.reasoning_summary_part.added";
3099
+ }
2539
3100
  function isResponseReasoningSummaryTextDeltaChunk(chunk) {
2540
3101
  return chunk.type === "response.reasoning_summary_text.delta";
2541
3102
  }
3103
+ function isErrorChunk(chunk) {
3104
+ return chunk.type === "error";
3105
+ }
2542
3106
  function getResponsesModelConfig(modelId) {
2543
- if (modelId.startsWith("o")) {
3107
+ if (modelId.startsWith("o") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
2544
3108
  if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
2545
3109
  return {
2546
3110
  isReasoningModel: true,
@@ -2560,16 +3124,21 @@ function getResponsesModelConfig(modelId) {
2560
3124
  requiredAutoTruncation: false
2561
3125
  };
2562
3126
  }
2563
- var openaiResponsesProviderOptionsSchema = import_zod12.z.object({
2564
- metadata: import_zod12.z.any().nullish(),
2565
- parallelToolCalls: import_zod12.z.boolean().nullish(),
2566
- previousResponseId: import_zod12.z.string().nullish(),
2567
- store: import_zod12.z.boolean().nullish(),
2568
- user: import_zod12.z.string().nullish(),
2569
- reasoningEffort: import_zod12.z.string().nullish(),
2570
- strictSchemas: import_zod12.z.boolean().nullish(),
2571
- instructions: import_zod12.z.string().nullish(),
2572
- reasoningSummary: import_zod12.z.string().nullish()
3127
+ function supportsFlexProcessing2(modelId) {
3128
+ return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
3129
+ }
3130
+ var openaiResponsesProviderOptionsSchema = import_v415.z.object({
3131
+ metadata: import_v415.z.any().nullish(),
3132
+ parallelToolCalls: import_v415.z.boolean().nullish(),
3133
+ previousResponseId: import_v415.z.string().nullish(),
3134
+ store: import_v415.z.boolean().nullish(),
3135
+ user: import_v415.z.string().nullish(),
3136
+ reasoningEffort: import_v415.z.string().nullish(),
3137
+ strictJsonSchema: import_v415.z.boolean().nullish(),
3138
+ instructions: import_v415.z.string().nullish(),
3139
+ reasoningSummary: import_v415.z.string().nullish(),
3140
+ serviceTier: import_v415.z.enum(["auto", "flex"]).nullish(),
3141
+ include: import_v415.z.array(import_v415.z.enum(["reasoning.encrypted_content"])).nullish()
2573
3142
  });
2574
3143
  // Annotate the CommonJS export names for ESM import in node:
2575
3144
  0 && (module.exports = {