@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.
package/dist/index.mjs CHANGED
@@ -56,6 +56,7 @@ function getOpenAILanguageModelCapabilities(modelId) {
56
56
  supportsFlexProcessing,
57
57
  supportsPriorityProcessing,
58
58
  supportsConfigurationUpdate: isGpt6OrLaterModel,
59
+ supportsAsyncToolCalling: isGpt6OrLaterModel,
59
60
  supportedReasoningEfforts: isGpt6OrLaterModel ? ["low", "medium", "high", "xhigh", "max"] : void 0,
60
61
  isReasoningModel,
61
62
  systemMessageMode,
@@ -2429,11 +2430,12 @@ function isFileId(data, prefixes) {
2429
2430
  async function convertToOpenAIResponsesInput({
2430
2431
  prompt,
2431
2432
  systemMessageMode,
2433
+ explicitMessageItemType = false,
2432
2434
  fileIdPrefixes,
2433
2435
  store,
2434
2436
  hasLocalShellTool = false
2435
2437
  }) {
2436
- var _a2, _b, _c, _d, _e, _f;
2438
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
2437
2439
  let input = [];
2438
2440
  const warnings = [];
2439
2441
  for (const { role, content, providerOptions } of prompt) {
@@ -2443,6 +2445,7 @@ async function convertToOpenAIResponsesInput({
2443
2445
  case "system": {
2444
2446
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
2445
2447
  input.push({
2448
+ ...explicitMessageItemType && { type: "message" },
2446
2449
  role: "system",
2447
2450
  content: promptCacheBreakpoint == null ? content : [
2448
2451
  {
@@ -2457,6 +2460,7 @@ async function convertToOpenAIResponsesInput({
2457
2460
  case "developer": {
2458
2461
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
2459
2462
  input.push({
2463
+ ...explicitMessageItemType && { type: "message" },
2460
2464
  role: "developer",
2461
2465
  content: promptCacheBreakpoint == null ? content : [
2462
2466
  {
@@ -2486,6 +2490,7 @@ async function convertToOpenAIResponsesInput({
2486
2490
  }
2487
2491
  case "user": {
2488
2492
  input.push({
2493
+ ...explicitMessageItemType && { type: "message" },
2489
2494
  role: "user",
2490
2495
  content: content.map((part, index) => {
2491
2496
  var _a3, _b2, _c2;
@@ -2562,6 +2567,7 @@ async function convertToOpenAIResponsesInput({
2562
2567
  break;
2563
2568
  }
2564
2569
  input.push({
2570
+ ...explicitMessageItemType && { type: "message" },
2565
2571
  role: "assistant",
2566
2572
  content: [{ type: "output_text", text: part.text }],
2567
2573
  id,
@@ -2575,6 +2581,7 @@ async function convertToOpenAIResponsesInput({
2575
2581
  break;
2576
2582
  }
2577
2583
  const id = (_f = (_e = part.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.itemId;
2584
+ const isAsync = (_h = (_g = part.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.async;
2578
2585
  if (store && id != null) {
2579
2586
  input.push({ type: "item_reference", id });
2580
2587
  break;
@@ -2604,6 +2611,7 @@ async function convertToOpenAIResponsesInput({
2604
2611
  call_id: part.toolCallId,
2605
2612
  name: part.toolName,
2606
2613
  arguments: JSON.stringify(part.input),
2614
+ ...isAsync != null && { async: isAsync },
2607
2615
  id
2608
2616
  });
2609
2617
  break;
@@ -2879,7 +2887,8 @@ var openaiResponsesChunkSchema = lazyValidator9(
2879
2887
  id: z17.string(),
2880
2888
  call_id: z17.string(),
2881
2889
  name: z17.string(),
2882
- arguments: z17.string()
2890
+ arguments: z17.string(),
2891
+ async: z17.boolean().nullish()
2883
2892
  }),
2884
2893
  z17.object({
2885
2894
  type: z17.literal("web_search_call"),
@@ -2934,6 +2943,7 @@ var openaiResponsesChunkSchema = lazyValidator9(
2934
2943
  call_id: z17.string(),
2935
2944
  name: z17.string(),
2936
2945
  arguments: z17.string(),
2946
+ async: z17.boolean().nullish(),
2937
2947
  status: z17.literal("completed")
2938
2948
  }),
2939
2949
  z17.object({
@@ -3245,7 +3255,8 @@ var openaiResponsesResponseSchema = lazyValidator9(
3245
3255
  call_id: z17.string(),
3246
3256
  name: z17.string(),
3247
3257
  arguments: z17.string(),
3248
- id: z17.string()
3258
+ id: z17.string(),
3259
+ async: z17.boolean().nullish()
3249
3260
  }),
3250
3261
  z17.object({
3251
3262
  type: z17.literal("computer_call"),
@@ -3483,8 +3494,10 @@ import { validateTypes as validateTypes2 } from "@ai-sdk/provider-utils";
3483
3494
  async function prepareResponsesTools({
3484
3495
  tools,
3485
3496
  toolChoice,
3486
- strictJsonSchema
3497
+ strictJsonSchema,
3498
+ supportsAsyncToolCalling = true
3487
3499
  }) {
3500
+ var _a2;
3488
3501
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
3489
3502
  const toolWarnings = [];
3490
3503
  if (tools == null) {
@@ -3493,15 +3506,24 @@ async function prepareResponsesTools({
3493
3506
  const openaiTools2 = [];
3494
3507
  for (const tool of tools) {
3495
3508
  switch (tool.type) {
3496
- case "function":
3509
+ case "function": {
3510
+ const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
3511
+ const async = resolveAsyncToolOption({
3512
+ value: openaiOptions == null ? void 0 : openaiOptions.async,
3513
+ supportsAsyncToolCalling,
3514
+ tool,
3515
+ toolWarnings
3516
+ });
3497
3517
  openaiTools2.push({
3498
3518
  type: "function",
3499
3519
  name: tool.name,
3500
3520
  description: tool.description,
3501
3521
  parameters: tool.inputSchema,
3502
- strict: strictJsonSchema
3522
+ strict: strictJsonSchema,
3523
+ ...async != null ? { async } : {}
3503
3524
  });
3504
3525
  break;
3526
+ }
3505
3527
  case "provider-defined": {
3506
3528
  switch (tool.id) {
3507
3529
  case "openai.file_search": {
@@ -3620,6 +3642,22 @@ async function prepareResponsesTools({
3620
3642
  }
3621
3643
  }
3622
3644
  }
3645
+ function resolveAsyncToolOption({
3646
+ value,
3647
+ supportsAsyncToolCalling,
3648
+ tool,
3649
+ toolWarnings
3650
+ }) {
3651
+ if (value !== true || supportsAsyncToolCalling) {
3652
+ return value;
3653
+ }
3654
+ toolWarnings.push({
3655
+ type: "unsupported-tool",
3656
+ tool,
3657
+ details: "Async tool calling is only supported by GPT-6 and later models."
3658
+ });
3659
+ return void 0;
3660
+ }
3623
3661
 
3624
3662
  // src/responses/openai-responses-language-model.ts
3625
3663
  var OpenAIResponsesLanguageModel = class {
@@ -3689,6 +3727,7 @@ var OpenAIResponsesLanguageModel = class {
3689
3727
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
3690
3728
  prompt,
3691
3729
  systemMessageMode: modelCapabilities.systemMessageMode,
3730
+ explicitMessageItemType: this.config.explicitMessageItemType,
3692
3731
  fileIdPrefixes: this.config.fileIdPrefixes,
3693
3732
  store: (_a2 = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _a2 : true,
3694
3733
  hasLocalShellTool: hasOpenAITool("openai.local_shell")
@@ -3899,7 +3938,8 @@ var OpenAIResponsesLanguageModel = class {
3899
3938
  } = await prepareResponsesTools({
3900
3939
  tools,
3901
3940
  toolChoice,
3902
- strictJsonSchema
3941
+ strictJsonSchema,
3942
+ supportsAsyncToolCalling: modelCapabilities.supportsAsyncToolCalling
3903
3943
  });
3904
3944
  return {
3905
3945
  webSearchToolName,
@@ -4093,7 +4133,8 @@ var OpenAIResponsesLanguageModel = class {
4093
4133
  input: part.arguments,
4094
4134
  providerMetadata: {
4095
4135
  [providerKey]: {
4096
- itemId: part.id
4136
+ itemId: part.id,
4137
+ ...part.async != null && { async: part.async }
4097
4138
  }
4098
4139
  }
4099
4140
  });
@@ -4293,7 +4334,8 @@ var OpenAIResponsesLanguageModel = class {
4293
4334
  if (value.item.type === "function_call") {
4294
4335
  ongoingToolCalls[value.output_index] = {
4295
4336
  toolName: value.item.name,
4296
- toolCallId: value.item.call_id
4337
+ toolCallId: value.item.call_id,
4338
+ async: value.item.async
4297
4339
  };
4298
4340
  controller.enqueue({
4299
4341
  type: "tool-input-start",
@@ -4417,6 +4459,7 @@ var OpenAIResponsesLanguageModel = class {
4417
4459
  }
4418
4460
  });
4419
4461
  } else if (value.item.type === "function_call") {
4462
+ const ongoingToolCall = ongoingToolCalls[value.output_index];
4420
4463
  ongoingToolCalls[value.output_index] = void 0;
4421
4464
  hasFunctionCall = true;
4422
4465
  controller.enqueue({
@@ -4430,7 +4473,8 @@ var OpenAIResponsesLanguageModel = class {
4430
4473
  input: value.item.arguments,
4431
4474
  providerMetadata: {
4432
4475
  [providerKey]: {
4433
- itemId: value.item.id
4476
+ itemId: value.item.id,
4477
+ ...value.item.async != null ? { async: value.item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {}
4434
4478
  }
4435
4479
  }
4436
4480
  });
@@ -5183,7 +5227,7 @@ var OpenAITranscriptionModel = class {
5183
5227
  };
5184
5228
 
5185
5229
  // src/version.ts
5186
- var VERSION = true ? "2.0.125" : "0.0.0-test";
5230
+ var VERSION = true ? "2.0.126" : "0.0.0-test";
5187
5231
 
5188
5232
  // src/openai-provider.ts
5189
5233
  function createOpenAI(options = {}) {