@ai-sdk/openai 3.0.109 → 3.0.110

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.
package/dist/index.mjs CHANGED
@@ -55,6 +55,7 @@ function getOpenAILanguageModelCapabilities(modelId) {
55
55
  supportsFlexProcessing,
56
56
  supportsPriorityProcessing,
57
57
  supportsConfigurationUpdate: isGpt6OrLaterModel,
58
+ supportsAsyncToolCalling: isGpt6OrLaterModel,
58
59
  supportedReasoningEfforts: isGpt6OrLaterModel ? ["low", "medium", "high", "xhigh", "max"] : void 0,
59
60
  isReasoningModel,
60
61
  systemMessageMode,
@@ -2106,9 +2107,10 @@ var baseImageModelOptionsObject = z9.object({
2106
2107
  /**
2107
2108
  * Quality of the generated image(s).
2108
2109
  *
2109
- * Valid values: `standard`, `hd`, `low`, `medium`, `high`, `auto`.
2110
+ * Valid values: `standard`, `hd`, `low`, `medium`, `high`, `xhigh`, `max`, `auto`.
2111
+ * `xhigh` and `max` are supported by GPT Image 2.5 models.
2110
2112
  */
2111
- quality: z9.enum(["standard", "hd", "low", "medium", "high", "auto"]).optional(),
2113
+ quality: z9.enum(["standard", "hd", "low", "medium", "high", "xhigh", "max", "auto"]).optional(),
2112
2114
  /**
2113
2115
  * Background behavior for the generated image(s).
2114
2116
  *
@@ -2481,6 +2483,7 @@ var customArgsSchema = lazySchema11(
2481
2483
  z12.object({
2482
2484
  name: z12.string(),
2483
2485
  description: z12.string().optional(),
2486
+ async: z12.boolean().optional(),
2484
2487
  format: z12.union([
2485
2488
  z12.object({
2486
2489
  type: z12.literal("grammar"),
@@ -2575,7 +2578,7 @@ var imageGenerationArgsSchema = lazySchema13(
2575
2578
  outputCompression: z14.number().int().min(0).max(100).optional(),
2576
2579
  outputFormat: z14.enum(["png", "jpeg", "webp"]).optional(),
2577
2580
  partialImages: z14.number().int().min(0).max(3).optional(),
2578
- quality: z14.enum(["auto", "low", "medium", "high"]).optional(),
2581
+ quality: z14.enum(["auto", "low", "medium", "high", "xhigh", "max"]).optional(),
2579
2582
  size: z14.enum(["1024x1024", "1024x1536", "1536x1024", "auto"]).optional()
2580
2583
  }).strict()
2581
2584
  )
@@ -2959,6 +2962,7 @@ var openaiTools = {
2959
2962
  *
2960
2963
  * @param name - The name of the custom tool.
2961
2964
  * @param description - An optional description of the tool.
2965
+ * @param async - Whether the model can continue without waiting for the tool result.
2962
2966
  * @param format - The output format constraint (grammar type, syntax, and definition).
2963
2967
  */
2964
2968
  customTool,
@@ -2994,7 +2998,7 @@ var openaiTools = {
2994
2998
  * @param outputCompression - Compression level for the output image (0-100).
2995
2999
  * @param outputFormat - The output format of the generated image. One of 'png', 'jpeg', or 'webp'.
2996
3000
  * @param partialImages - Number of partial images to generate in streaming mode (0-3).
2997
- * @param quality - The quality of the generated image. One of 'auto', 'low', 'medium', or 'high'.
3001
+ * @param quality - The quality of the generated image. One of 'auto', 'low', 'medium', 'high', 'xhigh', or 'max'. 'xhigh' and 'max' require a GPT Image 2.5 model.
2998
3002
  * @param size - The size of the generated image. One of 'auto', '1024x1024', '1024x1536', or '1536x1024'.
2999
3003
  */
3000
3004
  imageGeneration,
@@ -3394,7 +3398,7 @@ async function convertToOpenAIResponsesInput({
3394
3398
  toolSearchToolName,
3395
3399
  customProviderToolNames
3396
3400
  }) {
3397
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
3401
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D;
3398
3402
  let input = [];
3399
3403
  const warnings = [];
3400
3404
  const processedApprovalIds = /* @__PURE__ */ new Set();
@@ -3579,6 +3583,7 @@ async function convertToOpenAIResponsesInput({
3579
3583
  }
3580
3584
  const id = (_f = (_c = (_b = part.providerOptions) == null ? void 0 : _b[providerOptionsName]) == null ? void 0 : _c.itemId) != null ? _f : (_e = (_d = part.providerMetadata) == null ? void 0 : _d[providerOptionsName]) == null ? void 0 : _e.itemId;
3581
3585
  const namespace = (_k = (_h = (_g = part.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.namespace) != null ? _k : (_j = (_i = part.providerMetadata) == null ? void 0 : _i[providerOptionsName]) == null ? void 0 : _j.namespace;
3586
+ const isAsync = (_p = (_m = (_l = part.providerOptions) == null ? void 0 : _l[providerOptionsName]) == null ? void 0 : _m.async) != null ? _p : (_o = (_n = part.providerMetadata) == null ? void 0 : _n[providerOptionsName]) == null ? void 0 : _o.async;
3582
3587
  if (hasConversation && id != null) {
3583
3588
  break;
3584
3589
  }
@@ -3602,7 +3607,7 @@ async function convertToOpenAIResponsesInput({
3602
3607
  type: "tool_search_call",
3603
3608
  id: id != null ? id : part.toolCallId,
3604
3609
  execution,
3605
- call_id: (_l = parsedInput.call_id) != null ? _l : null,
3610
+ call_id: (_q = parsedInput.call_id) != null ? _q : null,
3606
3611
  status: "completed",
3607
3612
  arguments: parsedInput.arguments
3608
3613
  });
@@ -3616,7 +3621,7 @@ async function convertToOpenAIResponsesInput({
3616
3621
  break;
3617
3622
  }
3618
3623
  }
3619
- const isProviderDefinedToolCall = hasLocalShellTool && resolvedToolName === "local_shell" || hasShellTool && resolvedToolName === "shell" || hasApplyPatchTool && resolvedToolName === "apply_patch" || ((_m = customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) != null ? _m : false);
3624
+ const isProviderDefinedToolCall = hasLocalShellTool && resolvedToolName === "local_shell" || hasShellTool && resolvedToolName === "shell" || hasApplyPatchTool && resolvedToolName === "apply_patch" || ((_r = customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) != null ? _r : false);
3620
3625
  if (hasPreviousResponseId && store && id != null && isProviderDefinedToolCall) {
3621
3626
  break;
3622
3627
  }
@@ -3682,6 +3687,7 @@ async function convertToOpenAIResponsesInput({
3682
3687
  call_id: part.toolCallId,
3683
3688
  name: resolvedToolName,
3684
3689
  input: typeof part.input === "string" ? part.input : JSON.stringify(part.input),
3690
+ ...isAsync != null && { async: isAsync },
3685
3691
  id
3686
3692
  });
3687
3693
  break;
@@ -3691,6 +3697,7 @@ async function convertToOpenAIResponsesInput({
3691
3697
  call_id: part.toolCallId,
3692
3698
  name: resolvedToolName,
3693
3699
  arguments: serializeToolCallArguments2(part.input),
3700
+ ...isAsync != null && { async: isAsync },
3694
3701
  ...namespace != null && { namespace }
3695
3702
  });
3696
3703
  break;
@@ -3707,7 +3714,7 @@ async function convertToOpenAIResponsesInput({
3707
3714
  part.toolName
3708
3715
  );
3709
3716
  if (part.toolName === toolSearchToolName) {
3710
- const itemId = (_s = (_r = (_o = (_n = part.providerOptions) == null ? void 0 : _n[providerOptionsName]) == null ? void 0 : _o.itemId) != null ? _r : (_q = (_p = part.providerMetadata) == null ? void 0 : _p[providerOptionsName]) == null ? void 0 : _q.itemId) != null ? _s : part.toolCallId;
3717
+ const itemId = (_x = (_w = (_t = (_s = part.providerOptions) == null ? void 0 : _s[providerOptionsName]) == null ? void 0 : _t.itemId) != null ? _w : (_v = (_u = part.providerMetadata) == null ? void 0 : _u[providerOptionsName]) == null ? void 0 : _v.itemId) != null ? _x : part.toolCallId;
3711
3718
  if (store) {
3712
3719
  input.push({ type: "item_reference", id: itemId });
3713
3720
  } else if (part.output.type === "json") {
@@ -3748,7 +3755,7 @@ async function convertToOpenAIResponsesInput({
3748
3755
  break;
3749
3756
  }
3750
3757
  if (store) {
3751
- const itemId = (_v = (_u = (_t = part.providerOptions) == null ? void 0 : _t[providerOptionsName]) == null ? void 0 : _u.itemId) != null ? _v : part.toolCallId;
3758
+ const itemId = (_A = (_z = (_y = part.providerOptions) == null ? void 0 : _y[providerOptionsName]) == null ? void 0 : _z.itemId) != null ? _A : part.toolCallId;
3752
3759
  input.push({ type: "item_reference", id: itemId });
3753
3760
  } else {
3754
3761
  warnings.push({
@@ -3915,7 +3922,7 @@ ${text}`,
3915
3922
  }
3916
3923
  const output = part.output;
3917
3924
  if (output.type === "execution-denied") {
3918
- const approvalId = (_x = (_w = output.providerOptions) == null ? void 0 : _w.openai) == null ? void 0 : _x.approvalId;
3925
+ const approvalId = (_C = (_B = output.providerOptions) == null ? void 0 : _B.openai) == null ? void 0 : _C.approvalId;
3919
3926
  if (approvalId) {
3920
3927
  continue;
3921
3928
  }
@@ -4002,7 +4009,7 @@ ${text}`,
4002
4009
  break;
4003
4010
  case "execution-denied":
4004
4011
  outputValue = convertScalarOutput(
4005
- (_y = output.reason) != null ? _y : "Tool call execution denied."
4012
+ (_D = output.reason) != null ? _D : "Tool call execution denied."
4006
4013
  );
4007
4014
  break;
4008
4015
  case "json":
@@ -4343,6 +4350,7 @@ var openaiResponsesChunkSchema = lazySchema20(
4343
4350
  call_id: z22.string(),
4344
4351
  name: z22.string(),
4345
4352
  arguments: z22.string(),
4353
+ async: z22.boolean().nullish(),
4346
4354
  namespace: z22.string().nullish()
4347
4355
  }),
4348
4356
  z22.object({
@@ -4418,7 +4426,8 @@ var openaiResponsesChunkSchema = lazySchema20(
4418
4426
  id: z22.string(),
4419
4427
  call_id: z22.string(),
4420
4428
  name: z22.string(),
4421
- input: z22.string()
4429
+ input: z22.string(),
4430
+ async: z22.boolean().nullish()
4422
4431
  }),
4423
4432
  z22.object({
4424
4433
  type: z22.literal("shell_call"),
@@ -4486,6 +4495,7 @@ var openaiResponsesChunkSchema = lazySchema20(
4486
4495
  call_id: z22.string(),
4487
4496
  name: z22.string(),
4488
4497
  arguments: z22.string(),
4498
+ async: z22.boolean().nullish(),
4489
4499
  status: z22.literal("completed"),
4490
4500
  namespace: z22.string().nullish()
4491
4501
  }),
@@ -4495,6 +4505,7 @@ var openaiResponsesChunkSchema = lazySchema20(
4495
4505
  call_id: z22.string(),
4496
4506
  name: z22.string(),
4497
4507
  input: z22.string(),
4508
+ async: z22.boolean().nullish(),
4498
4509
  status: z22.literal("completed")
4499
4510
  }),
4500
4511
  z22.object({
@@ -4928,6 +4939,7 @@ var openaiResponsesResponseSchema = lazySchema20(
4928
4939
  name: z22.string(),
4929
4940
  arguments: z22.string(),
4930
4941
  id: z22.string(),
4942
+ async: z22.boolean().nullish(),
4931
4943
  namespace: z22.string().nullish()
4932
4944
  }),
4933
4945
  z22.object({
@@ -4935,7 +4947,8 @@ var openaiResponsesResponseSchema = lazySchema20(
4935
4947
  call_id: z22.string(),
4936
4948
  name: z22.string(),
4937
4949
  input: z22.string(),
4938
- id: z22.string()
4950
+ id: z22.string(),
4951
+ async: z22.boolean().nullish()
4939
4952
  }),
4940
4953
  z22.object({
4941
4954
  type: z22.literal("computer_call"),
@@ -5372,7 +5385,8 @@ async function prepareResponsesTools({
5372
5385
  toolChoice,
5373
5386
  allowedTools,
5374
5387
  toolNameMapping,
5375
- customProviderToolNames
5388
+ customProviderToolNames,
5389
+ supportsAsyncToolCalling = true
5376
5390
  }) {
5377
5391
  var _a2, _b, _c, _d;
5378
5392
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
@@ -5403,7 +5417,13 @@ async function prepareResponsesTools({
5403
5417
  const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
5404
5418
  const openaiFunctionTool = prepareFunctionTool({
5405
5419
  tool,
5406
- options: openaiOptions
5420
+ options: openaiOptions,
5421
+ async: resolveAsyncToolOption({
5422
+ value: openaiOptions == null ? void 0 : openaiOptions.async,
5423
+ supportsAsyncToolCalling,
5424
+ toolName: tool.name,
5425
+ toolWarnings
5426
+ })
5407
5427
  });
5408
5428
  const namespace = openaiOptions == null ? void 0 : openaiOptions.namespace;
5409
5429
  if (namespace == null) {
@@ -5585,6 +5605,12 @@ async function prepareResponsesTools({
5585
5605
  type: "custom",
5586
5606
  name: args.name,
5587
5607
  description: args.description,
5608
+ ...resolveAsyncToolOption({
5609
+ value: args.async,
5610
+ supportsAsyncToolCalling,
5611
+ toolName: args.name,
5612
+ toolWarnings
5613
+ }) != null ? { async: args.async } : {},
5588
5614
  format: args.format
5589
5615
  });
5590
5616
  resolvedCustomProviderToolNames.add(args.name);
@@ -5756,7 +5782,8 @@ function toAllowedToolResolution(tool) {
5756
5782
  }
5757
5783
  function prepareFunctionTool({
5758
5784
  tool,
5759
- options
5785
+ options,
5786
+ async
5760
5787
  }) {
5761
5788
  const deferLoading = options == null ? void 0 : options.deferLoading;
5762
5789
  return {
@@ -5764,10 +5791,27 @@ function prepareFunctionTool({
5764
5791
  name: tool.name,
5765
5792
  description: tool.description,
5766
5793
  parameters: tool.inputSchema,
5794
+ ...async != null ? { async } : {},
5767
5795
  ...tool.strict != null ? { strict: tool.strict } : {},
5768
5796
  ...deferLoading != null ? { defer_loading: deferLoading } : {}
5769
5797
  };
5770
5798
  }
5799
+ function resolveAsyncToolOption({
5800
+ value,
5801
+ supportsAsyncToolCalling,
5802
+ toolName,
5803
+ toolWarnings
5804
+ }) {
5805
+ if (value !== true || supportsAsyncToolCalling) {
5806
+ return value;
5807
+ }
5808
+ toolWarnings.push({
5809
+ type: "unsupported",
5810
+ feature: `async tool calling for "${toolName}"`,
5811
+ details: "Async tool calling is only supported by GPT-6 and later models."
5812
+ });
5813
+ return void 0;
5814
+ }
5771
5815
  function mapShellEnvironment(environment) {
5772
5816
  if (environment.type === "containerReference") {
5773
5817
  const env2 = environment;
@@ -5935,7 +5979,8 @@ var OpenAIResponsesLanguageModel = class {
5935
5979
  toolChoice,
5936
5980
  allowedTools: (_b = openaiOptions == null ? void 0 : openaiOptions.allowedTools) != null ? _b : void 0,
5937
5981
  toolNameMapping,
5938
- customProviderToolNames
5982
+ customProviderToolNames,
5983
+ supportsAsyncToolCalling: modelCapabilities.supportsAsyncToolCalling
5939
5984
  });
5940
5985
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
5941
5986
  prompt,
@@ -6445,6 +6490,7 @@ var OpenAIResponsesLanguageModel = class {
6445
6490
  providerMetadata: {
6446
6491
  [providerOptionsName]: {
6447
6492
  itemId: part.id,
6493
+ ...part.async != null && { async: part.async },
6448
6494
  ...part.namespace != null && { namespace: part.namespace }
6449
6495
  }
6450
6496
  }
@@ -6461,7 +6507,8 @@ var OpenAIResponsesLanguageModel = class {
6461
6507
  input: JSON.stringify(part.input),
6462
6508
  providerMetadata: {
6463
6509
  [providerOptionsName]: {
6464
- itemId: part.id
6510
+ itemId: part.id,
6511
+ ...part.async != null && { async: part.async }
6465
6512
  }
6466
6513
  }
6467
6514
  });
@@ -6749,7 +6796,8 @@ var OpenAIResponsesLanguageModel = class {
6749
6796
  toolName: value.item.name,
6750
6797
  toolCallId: value.item.call_id,
6751
6798
  suppressInputStreaming,
6752
- bufferedInputDeltas: suppressInputStreaming ? [] : void 0
6799
+ bufferedInputDeltas: suppressInputStreaming ? [] : void 0,
6800
+ async: value.item.async
6753
6801
  };
6754
6802
  if (!suppressInputStreaming) {
6755
6803
  controller.enqueue({
@@ -6764,7 +6812,8 @@ var OpenAIResponsesLanguageModel = class {
6764
6812
  );
6765
6813
  ongoingToolCalls[value.output_index] = {
6766
6814
  toolName,
6767
- toolCallId: value.item.call_id
6815
+ toolCallId: value.item.call_id,
6816
+ async: value.item.async
6768
6817
  };
6769
6818
  controller.enqueue({
6770
6819
  type: "tool-input-start",
@@ -7008,6 +7057,7 @@ var OpenAIResponsesLanguageModel = class {
7008
7057
  providerMetadata: {
7009
7058
  [providerOptionsName]: {
7010
7059
  itemId: item.id,
7060
+ ...item.async != null ? { async: item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {},
7011
7061
  ...item.namespace != null && {
7012
7062
  namespace: item.namespace
7013
7063
  }
@@ -7052,6 +7102,7 @@ var OpenAIResponsesLanguageModel = class {
7052
7102
  }
7053
7103
  });
7054
7104
  } else if (value.item.type === "custom_tool_call") {
7105
+ const ongoingToolCall = ongoingToolCalls[value.output_index];
7055
7106
  ongoingToolCalls[value.output_index] = void 0;
7056
7107
  hasFunctionCall = true;
7057
7108
  const toolName = toolNameMapping.toCustomToolName(
@@ -7068,7 +7119,8 @@ var OpenAIResponsesLanguageModel = class {
7068
7119
  input: JSON.stringify(value.item.input),
7069
7120
  providerMetadata: {
7070
7121
  [providerOptionsName]: {
7071
- itemId: value.item.id
7122
+ itemId: value.item.id,
7123
+ ...value.item.async != null ? { async: value.item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {}
7072
7124
  }
7073
7125
  }
7074
7126
  });
@@ -8164,7 +8216,7 @@ var OpenAITranscriptionModel = class {
8164
8216
  };
8165
8217
 
8166
8218
  // src/version.ts
8167
- var VERSION = true ? "3.0.109" : "0.0.0-test";
8219
+ var VERSION = true ? "3.0.110" : "0.0.0-test";
8168
8220
 
8169
8221
  // src/openai-provider.ts
8170
8222
  function createOpenAI(options = {}) {