@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.
@@ -48,6 +48,7 @@ function getOpenAILanguageModelCapabilities(modelId) {
48
48
  supportsFlexProcessing,
49
49
  supportsPriorityProcessing,
50
50
  supportsConfigurationUpdate: isGpt6OrLaterModel,
51
+ supportsAsyncToolCalling: isGpt6OrLaterModel,
51
52
  supportedReasoningEfforts: isGpt6OrLaterModel ? ["low", "medium", "high", "xhigh", "max"] : void 0,
52
53
  isReasoningModel,
53
54
  systemMessageMode,
@@ -2463,11 +2464,12 @@ function isFileId(data, prefixes) {
2463
2464
  async function convertToOpenAIResponsesInput({
2464
2465
  prompt,
2465
2466
  systemMessageMode,
2467
+ explicitMessageItemType = false,
2466
2468
  fileIdPrefixes,
2467
2469
  store,
2468
2470
  hasLocalShellTool = false
2469
2471
  }) {
2470
- var _a2, _b, _c, _d, _e, _f;
2472
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
2471
2473
  let input = [];
2472
2474
  const warnings = [];
2473
2475
  for (const { role, content, providerOptions } of prompt) {
@@ -2477,6 +2479,7 @@ async function convertToOpenAIResponsesInput({
2477
2479
  case "system": {
2478
2480
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
2479
2481
  input.push({
2482
+ ...explicitMessageItemType && { type: "message" },
2480
2483
  role: "system",
2481
2484
  content: promptCacheBreakpoint == null ? content : [
2482
2485
  {
@@ -2491,6 +2494,7 @@ async function convertToOpenAIResponsesInput({
2491
2494
  case "developer": {
2492
2495
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
2493
2496
  input.push({
2497
+ ...explicitMessageItemType && { type: "message" },
2494
2498
  role: "developer",
2495
2499
  content: promptCacheBreakpoint == null ? content : [
2496
2500
  {
@@ -2520,6 +2524,7 @@ async function convertToOpenAIResponsesInput({
2520
2524
  }
2521
2525
  case "user": {
2522
2526
  input.push({
2527
+ ...explicitMessageItemType && { type: "message" },
2523
2528
  role: "user",
2524
2529
  content: content.map((part, index) => {
2525
2530
  var _a3, _b2, _c2;
@@ -2596,6 +2601,7 @@ async function convertToOpenAIResponsesInput({
2596
2601
  break;
2597
2602
  }
2598
2603
  input.push({
2604
+ ...explicitMessageItemType && { type: "message" },
2599
2605
  role: "assistant",
2600
2606
  content: [{ type: "output_text", text: part.text }],
2601
2607
  id,
@@ -2609,6 +2615,7 @@ async function convertToOpenAIResponsesInput({
2609
2615
  break;
2610
2616
  }
2611
2617
  const id = (_f = (_e = part.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.itemId;
2618
+ const isAsync = (_h = (_g = part.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.async;
2612
2619
  if (store && id != null) {
2613
2620
  input.push({ type: "item_reference", id });
2614
2621
  break;
@@ -2638,6 +2645,7 @@ async function convertToOpenAIResponsesInput({
2638
2645
  call_id: part.toolCallId,
2639
2646
  name: part.toolName,
2640
2647
  arguments: JSON.stringify(part.input),
2648
+ ...isAsync != null && { async: isAsync },
2641
2649
  id
2642
2650
  });
2643
2651
  break;
@@ -2913,7 +2921,8 @@ var openaiResponsesChunkSchema = lazyValidator12(
2913
2921
  id: z15.string(),
2914
2922
  call_id: z15.string(),
2915
2923
  name: z15.string(),
2916
- arguments: z15.string()
2924
+ arguments: z15.string(),
2925
+ async: z15.boolean().nullish()
2917
2926
  }),
2918
2927
  z15.object({
2919
2928
  type: z15.literal("web_search_call"),
@@ -2968,6 +2977,7 @@ var openaiResponsesChunkSchema = lazyValidator12(
2968
2977
  call_id: z15.string(),
2969
2978
  name: z15.string(),
2970
2979
  arguments: z15.string(),
2980
+ async: z15.boolean().nullish(),
2971
2981
  status: z15.literal("completed")
2972
2982
  }),
2973
2983
  z15.object({
@@ -3279,7 +3289,8 @@ var openaiResponsesResponseSchema = lazyValidator12(
3279
3289
  call_id: z15.string(),
3280
3290
  name: z15.string(),
3281
3291
  arguments: z15.string(),
3282
- id: z15.string()
3292
+ id: z15.string(),
3293
+ async: z15.boolean().nullish()
3283
3294
  }),
3284
3295
  z15.object({
3285
3296
  type: z15.literal("computer_call"),
@@ -3776,8 +3787,10 @@ import { validateTypes as validateTypes2 } from "@ai-sdk/provider-utils";
3776
3787
  async function prepareResponsesTools({
3777
3788
  tools,
3778
3789
  toolChoice,
3779
- strictJsonSchema
3790
+ strictJsonSchema,
3791
+ supportsAsyncToolCalling = true
3780
3792
  }) {
3793
+ var _a2;
3781
3794
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
3782
3795
  const toolWarnings = [];
3783
3796
  if (tools == null) {
@@ -3786,15 +3799,24 @@ async function prepareResponsesTools({
3786
3799
  const openaiTools = [];
3787
3800
  for (const tool of tools) {
3788
3801
  switch (tool.type) {
3789
- case "function":
3802
+ case "function": {
3803
+ const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
3804
+ const async = resolveAsyncToolOption({
3805
+ value: openaiOptions == null ? void 0 : openaiOptions.async,
3806
+ supportsAsyncToolCalling,
3807
+ tool,
3808
+ toolWarnings
3809
+ });
3790
3810
  openaiTools.push({
3791
3811
  type: "function",
3792
3812
  name: tool.name,
3793
3813
  description: tool.description,
3794
3814
  parameters: tool.inputSchema,
3795
- strict: strictJsonSchema
3815
+ strict: strictJsonSchema,
3816
+ ...async != null ? { async } : {}
3796
3817
  });
3797
3818
  break;
3819
+ }
3798
3820
  case "provider-defined": {
3799
3821
  switch (tool.id) {
3800
3822
  case "openai.file_search": {
@@ -3913,6 +3935,22 @@ async function prepareResponsesTools({
3913
3935
  }
3914
3936
  }
3915
3937
  }
3938
+ function resolveAsyncToolOption({
3939
+ value,
3940
+ supportsAsyncToolCalling,
3941
+ tool,
3942
+ toolWarnings
3943
+ }) {
3944
+ if (value !== true || supportsAsyncToolCalling) {
3945
+ return value;
3946
+ }
3947
+ toolWarnings.push({
3948
+ type: "unsupported-tool",
3949
+ tool,
3950
+ details: "Async tool calling is only supported by GPT-6 and later models."
3951
+ });
3952
+ return void 0;
3953
+ }
3916
3954
 
3917
3955
  // src/responses/openai-responses-language-model.ts
3918
3956
  var OpenAIResponsesLanguageModel = class {
@@ -3982,6 +4020,7 @@ var OpenAIResponsesLanguageModel = class {
3982
4020
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
3983
4021
  prompt,
3984
4022
  systemMessageMode: modelCapabilities.systemMessageMode,
4023
+ explicitMessageItemType: this.config.explicitMessageItemType,
3985
4024
  fileIdPrefixes: this.config.fileIdPrefixes,
3986
4025
  store: (_a2 = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _a2 : true,
3987
4026
  hasLocalShellTool: hasOpenAITool("openai.local_shell")
@@ -4192,7 +4231,8 @@ var OpenAIResponsesLanguageModel = class {
4192
4231
  } = await prepareResponsesTools({
4193
4232
  tools,
4194
4233
  toolChoice,
4195
- strictJsonSchema
4234
+ strictJsonSchema,
4235
+ supportsAsyncToolCalling: modelCapabilities.supportsAsyncToolCalling
4196
4236
  });
4197
4237
  return {
4198
4238
  webSearchToolName,
@@ -4386,7 +4426,8 @@ var OpenAIResponsesLanguageModel = class {
4386
4426
  input: part.arguments,
4387
4427
  providerMetadata: {
4388
4428
  [providerKey]: {
4389
- itemId: part.id
4429
+ itemId: part.id,
4430
+ ...part.async != null && { async: part.async }
4390
4431
  }
4391
4432
  }
4392
4433
  });
@@ -4586,7 +4627,8 @@ var OpenAIResponsesLanguageModel = class {
4586
4627
  if (value.item.type === "function_call") {
4587
4628
  ongoingToolCalls[value.output_index] = {
4588
4629
  toolName: value.item.name,
4589
- toolCallId: value.item.call_id
4630
+ toolCallId: value.item.call_id,
4631
+ async: value.item.async
4590
4632
  };
4591
4633
  controller.enqueue({
4592
4634
  type: "tool-input-start",
@@ -4710,6 +4752,7 @@ var OpenAIResponsesLanguageModel = class {
4710
4752
  }
4711
4753
  });
4712
4754
  } else if (value.item.type === "function_call") {
4755
+ const ongoingToolCall = ongoingToolCalls[value.output_index];
4713
4756
  ongoingToolCalls[value.output_index] = void 0;
4714
4757
  hasFunctionCall = true;
4715
4758
  controller.enqueue({
@@ -4723,7 +4766,8 @@ var OpenAIResponsesLanguageModel = class {
4723
4766
  input: value.item.arguments,
4724
4767
  providerMetadata: {
4725
4768
  [providerKey]: {
4726
- itemId: value.item.id
4769
+ itemId: value.item.id,
4770
+ ...value.item.async != null ? { async: value.item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {}
4727
4771
  }
4728
4772
  }
4729
4773
  });