@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.
package/dist/index.js CHANGED
@@ -69,6 +69,7 @@ function getOpenAILanguageModelCapabilities(modelId) {
69
69
  supportsFlexProcessing,
70
70
  supportsPriorityProcessing,
71
71
  supportsConfigurationUpdate: isGpt6OrLaterModel,
72
+ supportsAsyncToolCalling: isGpt6OrLaterModel,
72
73
  supportedReasoningEfforts: isGpt6OrLaterModel ? ["low", "medium", "high", "xhigh", "max"] : void 0,
73
74
  isReasoningModel,
74
75
  systemMessageMode,
@@ -944,6 +945,12 @@ var OpenAIChatLanguageModel = class {
944
945
  fetch: this.config.fetch
945
946
  });
946
947
  const choice = response.choices[0];
948
+ if (choice == null) {
949
+ throw new import_provider3.InvalidResponseDataError({
950
+ data: rawResponse,
951
+ message: "Response did not contain any choices."
952
+ });
953
+ }
947
954
  const content = [];
948
955
  const text = choice.message.content;
949
956
  if (text != null && text.length > 0) {
@@ -2359,11 +2366,12 @@ function isFileId(data, prefixes) {
2359
2366
  async function convertToOpenAIResponsesInput({
2360
2367
  prompt,
2361
2368
  systemMessageMode,
2369
+ explicitMessageItemType = false,
2362
2370
  fileIdPrefixes,
2363
2371
  store,
2364
2372
  hasLocalShellTool = false
2365
2373
  }) {
2366
- var _a2, _b, _c, _d, _e, _f;
2374
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
2367
2375
  let input = [];
2368
2376
  const warnings = [];
2369
2377
  for (const { role, content, providerOptions } of prompt) {
@@ -2373,6 +2381,7 @@ async function convertToOpenAIResponsesInput({
2373
2381
  case "system": {
2374
2382
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
2375
2383
  input.push({
2384
+ ...explicitMessageItemType && { type: "message" },
2376
2385
  role: "system",
2377
2386
  content: promptCacheBreakpoint == null ? content : [
2378
2387
  {
@@ -2387,6 +2396,7 @@ async function convertToOpenAIResponsesInput({
2387
2396
  case "developer": {
2388
2397
  const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
2389
2398
  input.push({
2399
+ ...explicitMessageItemType && { type: "message" },
2390
2400
  role: "developer",
2391
2401
  content: promptCacheBreakpoint == null ? content : [
2392
2402
  {
@@ -2416,6 +2426,7 @@ async function convertToOpenAIResponsesInput({
2416
2426
  }
2417
2427
  case "user": {
2418
2428
  input.push({
2429
+ ...explicitMessageItemType && { type: "message" },
2419
2430
  role: "user",
2420
2431
  content: content.map((part, index) => {
2421
2432
  var _a3, _b2, _c2;
@@ -2492,6 +2503,7 @@ async function convertToOpenAIResponsesInput({
2492
2503
  break;
2493
2504
  }
2494
2505
  input.push({
2506
+ ...explicitMessageItemType && { type: "message" },
2495
2507
  role: "assistant",
2496
2508
  content: [{ type: "output_text", text: part.text }],
2497
2509
  id,
@@ -2505,6 +2517,7 @@ async function convertToOpenAIResponsesInput({
2505
2517
  break;
2506
2518
  }
2507
2519
  const id = (_f = (_e = part.providerOptions) == null ? void 0 : _e.openai) == null ? void 0 : _f.itemId;
2520
+ const isAsync = (_h = (_g = part.providerOptions) == null ? void 0 : _g.openai) == null ? void 0 : _h.async;
2508
2521
  if (store && id != null) {
2509
2522
  input.push({ type: "item_reference", id });
2510
2523
  break;
@@ -2534,6 +2547,7 @@ async function convertToOpenAIResponsesInput({
2534
2547
  call_id: part.toolCallId,
2535
2548
  name: part.toolName,
2536
2549
  arguments: JSON.stringify(part.input),
2550
+ ...isAsync != null && { async: isAsync },
2537
2551
  id
2538
2552
  });
2539
2553
  break;
@@ -2806,7 +2820,8 @@ var openaiResponsesChunkSchema = (0, import_provider_utils22.lazyValidator)(
2806
2820
  id: import_v417.z.string(),
2807
2821
  call_id: import_v417.z.string(),
2808
2822
  name: import_v417.z.string(),
2809
- arguments: import_v417.z.string()
2823
+ arguments: import_v417.z.string(),
2824
+ async: import_v417.z.boolean().nullish()
2810
2825
  }),
2811
2826
  import_v417.z.object({
2812
2827
  type: import_v417.z.literal("web_search_call"),
@@ -2861,6 +2876,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils22.lazyValidator)(
2861
2876
  call_id: import_v417.z.string(),
2862
2877
  name: import_v417.z.string(),
2863
2878
  arguments: import_v417.z.string(),
2879
+ async: import_v417.z.boolean().nullish(),
2864
2880
  status: import_v417.z.literal("completed")
2865
2881
  }),
2866
2882
  import_v417.z.object({
@@ -3172,7 +3188,8 @@ var openaiResponsesResponseSchema = (0, import_provider_utils22.lazyValidator)(
3172
3188
  call_id: import_v417.z.string(),
3173
3189
  name: import_v417.z.string(),
3174
3190
  arguments: import_v417.z.string(),
3175
- id: import_v417.z.string()
3191
+ id: import_v417.z.string(),
3192
+ async: import_v417.z.boolean().nullish()
3176
3193
  }),
3177
3194
  import_v417.z.object({
3178
3195
  type: import_v417.z.literal("computer_call"),
@@ -3405,8 +3422,10 @@ var import_provider_utils24 = require("@ai-sdk/provider-utils");
3405
3422
  async function prepareResponsesTools({
3406
3423
  tools,
3407
3424
  toolChoice,
3408
- strictJsonSchema
3425
+ strictJsonSchema,
3426
+ supportsAsyncToolCalling = true
3409
3427
  }) {
3428
+ var _a2;
3410
3429
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
3411
3430
  const toolWarnings = [];
3412
3431
  if (tools == null) {
@@ -3415,15 +3434,24 @@ async function prepareResponsesTools({
3415
3434
  const openaiTools2 = [];
3416
3435
  for (const tool of tools) {
3417
3436
  switch (tool.type) {
3418
- case "function":
3437
+ case "function": {
3438
+ const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
3439
+ const async = resolveAsyncToolOption({
3440
+ value: openaiOptions == null ? void 0 : openaiOptions.async,
3441
+ supportsAsyncToolCalling,
3442
+ tool,
3443
+ toolWarnings
3444
+ });
3419
3445
  openaiTools2.push({
3420
3446
  type: "function",
3421
3447
  name: tool.name,
3422
3448
  description: tool.description,
3423
3449
  parameters: tool.inputSchema,
3424
- strict: strictJsonSchema
3450
+ strict: strictJsonSchema,
3451
+ ...async != null ? { async } : {}
3425
3452
  });
3426
3453
  break;
3454
+ }
3427
3455
  case "provider-defined": {
3428
3456
  switch (tool.id) {
3429
3457
  case "openai.file_search": {
@@ -3542,6 +3570,22 @@ async function prepareResponsesTools({
3542
3570
  }
3543
3571
  }
3544
3572
  }
3573
+ function resolveAsyncToolOption({
3574
+ value,
3575
+ supportsAsyncToolCalling,
3576
+ tool,
3577
+ toolWarnings
3578
+ }) {
3579
+ if (value !== true || supportsAsyncToolCalling) {
3580
+ return value;
3581
+ }
3582
+ toolWarnings.push({
3583
+ type: "unsupported-tool",
3584
+ tool,
3585
+ details: "Async tool calling is only supported by GPT-6 and later models."
3586
+ });
3587
+ return void 0;
3588
+ }
3545
3589
 
3546
3590
  // src/responses/openai-responses-language-model.ts
3547
3591
  var OpenAIResponsesLanguageModel = class {
@@ -3611,6 +3655,7 @@ var OpenAIResponsesLanguageModel = class {
3611
3655
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
3612
3656
  prompt,
3613
3657
  systemMessageMode: modelCapabilities.systemMessageMode,
3658
+ explicitMessageItemType: this.config.explicitMessageItemType,
3614
3659
  fileIdPrefixes: this.config.fileIdPrefixes,
3615
3660
  store: (_a2 = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _a2 : true,
3616
3661
  hasLocalShellTool: hasOpenAITool("openai.local_shell")
@@ -3821,7 +3866,8 @@ var OpenAIResponsesLanguageModel = class {
3821
3866
  } = await prepareResponsesTools({
3822
3867
  tools,
3823
3868
  toolChoice,
3824
- strictJsonSchema
3869
+ strictJsonSchema,
3870
+ supportsAsyncToolCalling: modelCapabilities.supportsAsyncToolCalling
3825
3871
  });
3826
3872
  return {
3827
3873
  webSearchToolName,
@@ -4015,7 +4061,8 @@ var OpenAIResponsesLanguageModel = class {
4015
4061
  input: part.arguments,
4016
4062
  providerMetadata: {
4017
4063
  [providerKey]: {
4018
- itemId: part.id
4064
+ itemId: part.id,
4065
+ ...part.async != null && { async: part.async }
4019
4066
  }
4020
4067
  }
4021
4068
  });
@@ -4215,7 +4262,8 @@ var OpenAIResponsesLanguageModel = class {
4215
4262
  if (value.item.type === "function_call") {
4216
4263
  ongoingToolCalls[value.output_index] = {
4217
4264
  toolName: value.item.name,
4218
- toolCallId: value.item.call_id
4265
+ toolCallId: value.item.call_id,
4266
+ async: value.item.async
4219
4267
  };
4220
4268
  controller.enqueue({
4221
4269
  type: "tool-input-start",
@@ -4339,6 +4387,7 @@ var OpenAIResponsesLanguageModel = class {
4339
4387
  }
4340
4388
  });
4341
4389
  } else if (value.item.type === "function_call") {
4390
+ const ongoingToolCall = ongoingToolCalls[value.output_index];
4342
4391
  ongoingToolCalls[value.output_index] = void 0;
4343
4392
  hasFunctionCall = true;
4344
4393
  controller.enqueue({
@@ -4352,7 +4401,8 @@ var OpenAIResponsesLanguageModel = class {
4352
4401
  input: value.item.arguments,
4353
4402
  providerMetadata: {
4354
4403
  [providerKey]: {
4355
- itemId: value.item.id
4404
+ itemId: value.item.id,
4405
+ ...value.item.async != null ? { async: value.item.async } : (ongoingToolCall == null ? void 0 : ongoingToolCall.async) != null ? { async: ongoingToolCall.async } : {}
4356
4406
  }
4357
4407
  }
4358
4408
  });
@@ -5087,7 +5137,7 @@ var OpenAITranscriptionModel = class {
5087
5137
  };
5088
5138
 
5089
5139
  // src/version.ts
5090
- var VERSION = true ? "2.0.125" : "0.0.0-test";
5140
+ var VERSION = true ? "2.0.127" : "0.0.0-test";
5091
5141
 
5092
5142
  // src/openai-provider.ts
5093
5143
  function createOpenAI(options = {}) {