@ai-sdk/openai 2.0.125 → 2.0.127

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,
@@ -933,6 +934,12 @@ var OpenAIChatLanguageModel = class {
933
934
  fetch: this.config.fetch
934
935
  });
935
936
  const choice = response.choices[0];
937
+ if (choice == null) {
938
+ throw new InvalidResponseDataError({
939
+ data: rawResponse,
940
+ message: "Response did not contain any choices."
941
+ });
942
+ }
936
943
  const content = [];
937
944
  const text = choice.message.content;
938
945
  if (text != null && text.length > 0) {
@@ -2463,11 +2470,12 @@ function isFileId(data, prefixes) {
2463
2470
  async function convertToOpenAIResponsesInput({
2464
2471
  prompt,
2465
2472
  systemMessageMode,
2473
+ explicitMessageItemType = false,
2466
2474
  fileIdPrefixes,
2467
2475
  store,
2468
2476
  hasLocalShellTool = false
2469
2477
  }) {
2470
- var _a2, _b, _c, _d, _e, _f;
2478
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
2471
2479
  let input = [];
2472
2480
  const warnings = [];
2473
2481
  for (const { role, content, providerOptions } of prompt) {
@@ -2477,6 +2485,7 @@ async function convertToOpenAIResponsesInput({
2477
2485
  case "system": {
2478
2486
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
2479
2487
  input.push({
2488
+ ...explicitMessageItemType && { type: "message" },
2480
2489
  role: "system",
2481
2490
  content: promptCacheBreakpoint == null ? content : [
2482
2491
  {
@@ -2491,6 +2500,7 @@ async function convertToOpenAIResponsesInput({
2491
2500
  case "developer": {
2492
2501
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
2493
2502
  input.push({
2503
+ ...explicitMessageItemType && { type: "message" },
2494
2504
  role: "developer",
2495
2505
  content: promptCacheBreakpoint == null ? content : [
2496
2506
  {
@@ -2520,6 +2530,7 @@ async function convertToOpenAIResponsesInput({
2520
2530
  }
2521
2531
  case "user": {
2522
2532
  input.push({
2533
+ ...explicitMessageItemType && { type: "message" },
2523
2534
  role: "user",
2524
2535
  content: content.map((part, index) => {
2525
2536
  var _a3, _b2, _c2;
@@ -2596,6 +2607,7 @@ async function convertToOpenAIResponsesInput({
2596
2607
  break;
2597
2608
  }
2598
2609
  input.push({
2610
+ ...explicitMessageItemType && { type: "message" },
2599
2611
  role: "assistant",
2600
2612
  content: [{ type: "output_text", text: part.text }],
2601
2613
  id,
@@ -2609,6 +2621,7 @@ async function convertToOpenAIResponsesInput({
2609
2621
  break;
2610
2622
  }
2611
2623
  const id = (_f = (_e = part.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.itemId;
2624
+ const isAsync = (_h = (_g = part.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.async;
2612
2625
  if (store && id != null) {
2613
2626
  input.push({ type: "item_reference", id });
2614
2627
  break;
@@ -2638,6 +2651,7 @@ async function convertToOpenAIResponsesInput({
2638
2651
  call_id: part.toolCallId,
2639
2652
  name: part.toolName,
2640
2653
  arguments: JSON.stringify(part.input),
2654
+ ...isAsync != null && { async: isAsync },
2641
2655
  id
2642
2656
  });
2643
2657
  break;
@@ -2913,7 +2927,8 @@ var openaiResponsesChunkSchema = lazyValidator12(
2913
2927
  id: z15.string(),
2914
2928
  call_id: z15.string(),
2915
2929
  name: z15.string(),
2916
- arguments: z15.string()
2930
+ arguments: z15.string(),
2931
+ async: z15.boolean().nullish()
2917
2932
  }),
2918
2933
  z15.object({
2919
2934
  type: z15.literal("web_search_call"),
@@ -2968,6 +2983,7 @@ var openaiResponsesChunkSchema = lazyValidator12(
2968
2983
  call_id: z15.string(),
2969
2984
  name: z15.string(),
2970
2985
  arguments: z15.string(),
2986
+ async: z15.boolean().nullish(),
2971
2987
  status: z15.literal("completed")
2972
2988
  }),
2973
2989
  z15.object({
@@ -3279,7 +3295,8 @@ var openaiResponsesResponseSchema = lazyValidator12(
3279
3295
  call_id: z15.string(),
3280
3296
  name: z15.string(),
3281
3297
  arguments: z15.string(),
3282
- id: z15.string()
3298
+ id: z15.string(),
3299
+ async: z15.boolean().nullish()
3283
3300
  }),
3284
3301
  z15.object({
3285
3302
  type: z15.literal("computer_call"),
@@ -3776,8 +3793,10 @@ import { validateTypes as validateTypes2 } from "@ai-sdk/provider-utils";
3776
3793
  async function prepareResponsesTools({
3777
3794
  tools,
3778
3795
  toolChoice,
3779
- strictJsonSchema
3796
+ strictJsonSchema,
3797
+ supportsAsyncToolCalling = true
3780
3798
  }) {
3799
+ var _a2;
3781
3800
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
3782
3801
  const toolWarnings = [];
3783
3802
  if (tools == null) {
@@ -3786,15 +3805,24 @@ async function prepareResponsesTools({
3786
3805
  const openaiTools = [];
3787
3806
  for (const tool of tools) {
3788
3807
  switch (tool.type) {
3789
- case "function":
3808
+ case "function": {
3809
+ const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
3810
+ const async = resolveAsyncToolOption({
3811
+ value: openaiOptions == null ? void 0 : openaiOptions.async,
3812
+ supportsAsyncToolCalling,
3813
+ tool,
3814
+ toolWarnings
3815
+ });
3790
3816
  openaiTools.push({
3791
3817
  type: "function",
3792
3818
  name: tool.name,
3793
3819
  description: tool.description,
3794
3820
  parameters: tool.inputSchema,
3795
- strict: strictJsonSchema
3821
+ strict: strictJsonSchema,
3822
+ ...async != null ? { async } : {}
3796
3823
  });
3797
3824
  break;
3825
+ }
3798
3826
  case "provider-defined": {
3799
3827
  switch (tool.id) {
3800
3828
  case "openai.file_search": {
@@ -3913,6 +3941,22 @@ async function prepareResponsesTools({
3913
3941
  }
3914
3942
  }
3915
3943
  }
3944
+ function resolveAsyncToolOption({
3945
+ value,
3946
+ supportsAsyncToolCalling,
3947
+ tool,
3948
+ toolWarnings
3949
+ }) {
3950
+ if (value !== true || supportsAsyncToolCalling) {
3951
+ return value;
3952
+ }
3953
+ toolWarnings.push({
3954
+ type: "unsupported-tool",
3955
+ tool,
3956
+ details: "Async tool calling is only supported by GPT-6 and later models."
3957
+ });
3958
+ return void 0;
3959
+ }
3916
3960
 
3917
3961
  // src/responses/openai-responses-language-model.ts
3918
3962
  var OpenAIResponsesLanguageModel = class {
@@ -3982,6 +4026,7 @@ var OpenAIResponsesLanguageModel = class {
3982
4026
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
3983
4027
  prompt,
3984
4028
  systemMessageMode: modelCapabilities.systemMessageMode,
4029
+ explicitMessageItemType: this.config.explicitMessageItemType,
3985
4030
  fileIdPrefixes: this.config.fileIdPrefixes,
3986
4031
  store: (_a2 = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _a2 : true,
3987
4032
  hasLocalShellTool: hasOpenAITool("openai.local_shell")
@@ -4192,7 +4237,8 @@ var OpenAIResponsesLanguageModel = class {
4192
4237
  } = await prepareResponsesTools({
4193
4238
  tools,
4194
4239
  toolChoice,
4195
- strictJsonSchema
4240
+ strictJsonSchema,
4241
+ supportsAsyncToolCalling: modelCapabilities.supportsAsyncToolCalling
4196
4242
  });
4197
4243
  return {
4198
4244
  webSearchToolName,
@@ -4386,7 +4432,8 @@ var OpenAIResponsesLanguageModel = class {
4386
4432
  input: part.arguments,
4387
4433
  providerMetadata: {
4388
4434
  [providerKey]: {
4389
- itemId: part.id
4435
+ itemId: part.id,
4436
+ ...part.async != null && { async: part.async }
4390
4437
  }
4391
4438
  }
4392
4439
  });
@@ -4586,7 +4633,8 @@ var OpenAIResponsesLanguageModel = class {
4586
4633
  if (value.item.type === "function_call") {
4587
4634
  ongoingToolCalls[value.output_index] = {
4588
4635
  toolName: value.item.name,
4589
- toolCallId: value.item.call_id
4636
+ toolCallId: value.item.call_id,
4637
+ async: value.item.async
4590
4638
  };
4591
4639
  controller.enqueue({
4592
4640
  type: "tool-input-start",
@@ -4710,6 +4758,7 @@ var OpenAIResponsesLanguageModel = class {
4710
4758
  }
4711
4759
  });
4712
4760
  } else if (value.item.type === "function_call") {
4761
+ const ongoingToolCall = ongoingToolCalls[value.output_index];
4713
4762
  ongoingToolCalls[value.output_index] = void 0;
4714
4763
  hasFunctionCall = true;
4715
4764
  controller.enqueue({
@@ -4723,7 +4772,8 @@ var OpenAIResponsesLanguageModel = class {
4723
4772
  input: value.item.arguments,
4724
4773
  providerMetadata: {
4725
4774
  [providerKey]: {
4726
- itemId: value.item.id
4775
+ itemId: value.item.id,
4776
+ ...value.item.async != null ? { async: value.item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {}
4727
4777
  }
4728
4778
  }
4729
4779
  });