@ai-sdk/openai 2.0.125 → 2.0.126

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.
@@ -91,6 +91,11 @@ type OpenAIConfig = {
91
91
  headers: () => Record<string, string | undefined>;
92
92
  fetch?: FetchFunction;
93
93
  generateId?: () => string;
94
+ /**
95
+ * Whether Responses API message input items must include an explicit
96
+ * `type: 'message'` discriminator.
97
+ */
98
+ explicitMessageItemType?: boolean;
94
99
  /**
95
100
  * File ID prefixes used to identify file IDs in Responses API.
96
101
  * When undefined, all file data is treated as base64 content.
@@ -91,6 +91,11 @@ type OpenAIConfig = {
91
91
  headers: () => Record<string, string | undefined>;
92
92
  fetch?: FetchFunction;
93
93
  generateId?: () => string;
94
+ /**
95
+ * Whether Responses API message input items must include an explicit
96
+ * `type: 'message'` discriminator.
97
+ */
98
+ explicitMessageItemType?: boolean;
94
99
  /**
95
100
  * File ID prefixes used to identify file IDs in Responses API.
96
101
  * When undefined, all file data is treated as base64 content.
@@ -98,6 +98,7 @@ function getOpenAILanguageModelCapabilities(modelId) {
98
98
  supportsFlexProcessing,
99
99
  supportsPriorityProcessing,
100
100
  supportsConfigurationUpdate: isGpt6OrLaterModel,
101
+ supportsAsyncToolCalling: isGpt6OrLaterModel,
101
102
  supportedReasoningEfforts: isGpt6OrLaterModel ? ["low", "medium", "high", "xhigh", "max"] : void 0,
102
103
  isReasoningModel,
103
104
  systemMessageMode,
@@ -2432,11 +2433,12 @@ function isFileId(data, prefixes) {
2432
2433
  async function convertToOpenAIResponsesInput({
2433
2434
  prompt,
2434
2435
  systemMessageMode,
2436
+ explicitMessageItemType = false,
2435
2437
  fileIdPrefixes,
2436
2438
  store,
2437
2439
  hasLocalShellTool = false
2438
2440
  }) {
2439
- var _a2, _b, _c, _d, _e, _f;
2441
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
2440
2442
  let input = [];
2441
2443
  const warnings = [];
2442
2444
  for (const { role, content, providerOptions } of prompt) {
@@ -2446,6 +2448,7 @@ async function convertToOpenAIResponsesInput({
2446
2448
  case "system": {
2447
2449
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
2448
2450
  input.push({
2451
+ ...explicitMessageItemType && { type: "message" },
2449
2452
  role: "system",
2450
2453
  content: promptCacheBreakpoint == null ? content : [
2451
2454
  {
@@ -2460,6 +2463,7 @@ async function convertToOpenAIResponsesInput({
2460
2463
  case "developer": {
2461
2464
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
2462
2465
  input.push({
2466
+ ...explicitMessageItemType && { type: "message" },
2463
2467
  role: "developer",
2464
2468
  content: promptCacheBreakpoint == null ? content : [
2465
2469
  {
@@ -2489,6 +2493,7 @@ async function convertToOpenAIResponsesInput({
2489
2493
  }
2490
2494
  case "user": {
2491
2495
  input.push({
2496
+ ...explicitMessageItemType && { type: "message" },
2492
2497
  role: "user",
2493
2498
  content: content.map((part, index) => {
2494
2499
  var _a3, _b2, _c2;
@@ -2565,6 +2570,7 @@ async function convertToOpenAIResponsesInput({
2565
2570
  break;
2566
2571
  }
2567
2572
  input.push({
2573
+ ...explicitMessageItemType && { type: "message" },
2568
2574
  role: "assistant",
2569
2575
  content: [{ type: "output_text", text: part.text }],
2570
2576
  id,
@@ -2578,6 +2584,7 @@ async function convertToOpenAIResponsesInput({
2578
2584
  break;
2579
2585
  }
2580
2586
  const id = (_f = (_e = part.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.itemId;
2587
+ const isAsync = (_h = (_g = part.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.async;
2581
2588
  if (store && id != null) {
2582
2589
  input.push({ type: "item_reference", id });
2583
2590
  break;
@@ -2607,6 +2614,7 @@ async function convertToOpenAIResponsesInput({
2607
2614
  call_id: part.toolCallId,
2608
2615
  name: part.toolName,
2609
2616
  arguments: JSON.stringify(part.input),
2617
+ ...isAsync != null && { async: isAsync },
2610
2618
  id
2611
2619
  });
2612
2620
  break;
@@ -2879,7 +2887,8 @@ var openaiResponsesChunkSchema = (0, import_provider_utils22.lazyValidator)(
2879
2887
  id: import_v415.z.string(),
2880
2888
  call_id: import_v415.z.string(),
2881
2889
  name: import_v415.z.string(),
2882
- arguments: import_v415.z.string()
2890
+ arguments: import_v415.z.string(),
2891
+ async: import_v415.z.boolean().nullish()
2883
2892
  }),
2884
2893
  import_v415.z.object({
2885
2894
  type: import_v415.z.literal("web_search_call"),
@@ -2934,6 +2943,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils22.lazyValidator)(
2934
2943
  call_id: import_v415.z.string(),
2935
2944
  name: import_v415.z.string(),
2936
2945
  arguments: import_v415.z.string(),
2946
+ async: import_v415.z.boolean().nullish(),
2937
2947
  status: import_v415.z.literal("completed")
2938
2948
  }),
2939
2949
  import_v415.z.object({
@@ -3245,7 +3255,8 @@ var openaiResponsesResponseSchema = (0, import_provider_utils22.lazyValidator)(
3245
3255
  call_id: import_v415.z.string(),
3246
3256
  name: import_v415.z.string(),
3247
3257
  arguments: import_v415.z.string(),
3248
- id: import_v415.z.string()
3258
+ id: import_v415.z.string(),
3259
+ async: import_v415.z.boolean().nullish()
3249
3260
  }),
3250
3261
  import_v415.z.object({
3251
3262
  type: import_v415.z.literal("computer_call"),
@@ -3717,8 +3728,10 @@ var import_provider_utils29 = require("@ai-sdk/provider-utils");
3717
3728
  async function prepareResponsesTools({
3718
3729
  tools,
3719
3730
  toolChoice,
3720
- strictJsonSchema
3731
+ strictJsonSchema,
3732
+ supportsAsyncToolCalling = true
3721
3733
  }) {
3734
+ var _a2;
3722
3735
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
3723
3736
  const toolWarnings = [];
3724
3737
  if (tools == null) {
@@ -3727,15 +3740,24 @@ async function prepareResponsesTools({
3727
3740
  const openaiTools = [];
3728
3741
  for (const tool of tools) {
3729
3742
  switch (tool.type) {
3730
- case "function":
3743
+ case "function": {
3744
+ const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
3745
+ const async = resolveAsyncToolOption({
3746
+ value: openaiOptions == null ? void 0 : openaiOptions.async,
3747
+ supportsAsyncToolCalling,
3748
+ tool,
3749
+ toolWarnings
3750
+ });
3731
3751
  openaiTools.push({
3732
3752
  type: "function",
3733
3753
  name: tool.name,
3734
3754
  description: tool.description,
3735
3755
  parameters: tool.inputSchema,
3736
- strict: strictJsonSchema
3756
+ strict: strictJsonSchema,
3757
+ ...async != null ? { async } : {}
3737
3758
  });
3738
3759
  break;
3760
+ }
3739
3761
  case "provider-defined": {
3740
3762
  switch (tool.id) {
3741
3763
  case "openai.file_search": {
@@ -3854,6 +3876,22 @@ async function prepareResponsesTools({
3854
3876
  }
3855
3877
  }
3856
3878
  }
3879
+ function resolveAsyncToolOption({
3880
+ value,
3881
+ supportsAsyncToolCalling,
3882
+ tool,
3883
+ toolWarnings
3884
+ }) {
3885
+ if (value !== true || supportsAsyncToolCalling) {
3886
+ return value;
3887
+ }
3888
+ toolWarnings.push({
3889
+ type: "unsupported-tool",
3890
+ tool,
3891
+ details: "Async tool calling is only supported by GPT-6 and later models."
3892
+ });
3893
+ return void 0;
3894
+ }
3857
3895
 
3858
3896
  // src/responses/openai-responses-language-model.ts
3859
3897
  var OpenAIResponsesLanguageModel = class {
@@ -3923,6 +3961,7 @@ var OpenAIResponsesLanguageModel = class {
3923
3961
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
3924
3962
  prompt,
3925
3963
  systemMessageMode: modelCapabilities.systemMessageMode,
3964
+ explicitMessageItemType: this.config.explicitMessageItemType,
3926
3965
  fileIdPrefixes: this.config.fileIdPrefixes,
3927
3966
  store: (_a2 = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _a2 : true,
3928
3967
  hasLocalShellTool: hasOpenAITool("openai.local_shell")
@@ -4133,7 +4172,8 @@ var OpenAIResponsesLanguageModel = class {
4133
4172
  } = await prepareResponsesTools({
4134
4173
  tools,
4135
4174
  toolChoice,
4136
- strictJsonSchema
4175
+ strictJsonSchema,
4176
+ supportsAsyncToolCalling: modelCapabilities.supportsAsyncToolCalling
4137
4177
  });
4138
4178
  return {
4139
4179
  webSearchToolName,
@@ -4327,7 +4367,8 @@ var OpenAIResponsesLanguageModel = class {
4327
4367
  input: part.arguments,
4328
4368
  providerMetadata: {
4329
4369
  [providerKey]: {
4330
- itemId: part.id
4370
+ itemId: part.id,
4371
+ ...part.async != null && { async: part.async }
4331
4372
  }
4332
4373
  }
4333
4374
  });
@@ -4527,7 +4568,8 @@ var OpenAIResponsesLanguageModel = class {
4527
4568
  if (value.item.type === "function_call") {
4528
4569
  ongoingToolCalls[value.output_index] = {
4529
4570
  toolName: value.item.name,
4530
- toolCallId: value.item.call_id
4571
+ toolCallId: value.item.call_id,
4572
+ async: value.item.async
4531
4573
  };
4532
4574
  controller.enqueue({
4533
4575
  type: "tool-input-start",
@@ -4651,6 +4693,7 @@ var OpenAIResponsesLanguageModel = class {
4651
4693
  }
4652
4694
  });
4653
4695
  } else if (value.item.type === "function_call") {
4696
+ const ongoingToolCall = ongoingToolCalls[value.output_index];
4654
4697
  ongoingToolCalls[value.output_index] = void 0;
4655
4698
  hasFunctionCall = true;
4656
4699
  controller.enqueue({
@@ -4664,7 +4707,8 @@ var OpenAIResponsesLanguageModel = class {
4664
4707
  input: value.item.arguments,
4665
4708
  providerMetadata: {
4666
4709
  [providerKey]: {
4667
- itemId: value.item.id
4710
+ itemId: value.item.id,
4711
+ ...value.item.async != null ? { async: value.item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {}
4668
4712
  }
4669
4713
  }
4670
4714
  });