@ai-sdk/openai 3.0.124 → 3.0.125

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 3.0.125
4
+
5
+ ### Patch Changes
6
+
7
+ - ce4202b: fix(openai): replay web search results when response storage is disabled
8
+ - fde0b6c: fix(openai): classify Responses stream errors with null codes
9
+
3
10
  ## 3.0.124
4
11
 
5
12
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -220,21 +220,6 @@ type OpenAIResponsesFileSearchToolCompoundFilter = {
220
220
  declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
221
221
  type: "unknown_chunk";
222
222
  message: string;
223
- } | {
224
- type: "error";
225
- sequence_number: number;
226
- error: {
227
- type: string;
228
- code: string;
229
- message: string;
230
- param?: string | null | undefined;
231
- };
232
- } | {
233
- type: "error";
234
- sequence_number: number;
235
- message: string;
236
- code?: string | null | undefined;
237
- param?: string | null | undefined;
238
223
  } | {
239
224
  type: "response.output_text.delta";
240
225
  item_id: string;
@@ -709,6 +694,21 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
709
694
  item_id: string;
710
695
  output_index: number;
711
696
  diff: string;
697
+ } | {
698
+ type: "error";
699
+ sequence_number: number;
700
+ error: {
701
+ type: string;
702
+ message: string;
703
+ code?: string | null | undefined;
704
+ param?: string | null | undefined;
705
+ };
706
+ } | {
707
+ type: "error";
708
+ sequence_number: number;
709
+ message: string;
710
+ code?: string | null | undefined;
711
+ param?: string | null | undefined;
712
712
  }>;
713
713
  type OpenAIResponsesChunk = InferSchema<typeof openaiResponsesChunkSchema>;
714
714
  type OpenAIResponsesLogprobs = NonNullable<(OpenAIResponsesChunk & {
package/dist/index.d.ts CHANGED
@@ -220,21 +220,6 @@ type OpenAIResponsesFileSearchToolCompoundFilter = {
220
220
  declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
221
221
  type: "unknown_chunk";
222
222
  message: string;
223
- } | {
224
- type: "error";
225
- sequence_number: number;
226
- error: {
227
- type: string;
228
- code: string;
229
- message: string;
230
- param?: string | null | undefined;
231
- };
232
- } | {
233
- type: "error";
234
- sequence_number: number;
235
- message: string;
236
- code?: string | null | undefined;
237
- param?: string | null | undefined;
238
223
  } | {
239
224
  type: "response.output_text.delta";
240
225
  item_id: string;
@@ -709,6 +694,21 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
709
694
  item_id: string;
710
695
  output_index: number;
711
696
  diff: string;
697
+ } | {
698
+ type: "error";
699
+ sequence_number: number;
700
+ error: {
701
+ type: string;
702
+ message: string;
703
+ code?: string | null | undefined;
704
+ param?: string | null | undefined;
705
+ };
706
+ } | {
707
+ type: "error";
708
+ sequence_number: number;
709
+ message: string;
710
+ code?: string | null | undefined;
711
+ param?: string | null | undefined;
712
712
  }>;
713
713
  type OpenAIResponsesChunk = InferSchema<typeof openaiResponsesChunkSchema>;
714
714
  type OpenAIResponsesLogprobs = NonNullable<(OpenAIResponsesChunk & {
package/dist/index.js CHANGED
@@ -3455,6 +3455,57 @@ async function expandParallelToolCall({
3455
3455
  function serializeToolCallArguments2(input) {
3456
3456
  return JSON.stringify(input === void 0 ? {} : input);
3457
3457
  }
3458
+ async function convertWebSearchToolResultOutput({
3459
+ output,
3460
+ id
3461
+ }) {
3462
+ if (output.type !== "json") {
3463
+ return void 0;
3464
+ }
3465
+ const validation = await (0, import_provider_utils28.safeValidateTypes)({
3466
+ value: output.value,
3467
+ schema: webSearchOutputSchema
3468
+ });
3469
+ if (!validation.success || validation.value.action == null) {
3470
+ return void 0;
3471
+ }
3472
+ const { action, sources } = validation.value;
3473
+ switch (action.type) {
3474
+ case "search":
3475
+ return {
3476
+ type: "web_search_call",
3477
+ id,
3478
+ status: "completed",
3479
+ action: {
3480
+ type: "search",
3481
+ ...action.query != null && { query: action.query },
3482
+ ...action.queries != null && { queries: action.queries },
3483
+ ...sources != null && { sources }
3484
+ }
3485
+ };
3486
+ case "openPage":
3487
+ return {
3488
+ type: "web_search_call",
3489
+ id,
3490
+ status: "completed",
3491
+ action: {
3492
+ type: "open_page",
3493
+ url: action.url
3494
+ }
3495
+ };
3496
+ case "findInPage":
3497
+ return {
3498
+ type: "web_search_call",
3499
+ id,
3500
+ status: "completed",
3501
+ action: {
3502
+ type: "find_in_page",
3503
+ url: action.url,
3504
+ pattern: action.pattern
3505
+ }
3506
+ };
3507
+ }
3508
+ }
3458
3509
  async function convertFunctionToolResultOutput({
3459
3510
  output,
3460
3511
  promptCacheBreakpoint,
@@ -3661,7 +3712,7 @@ async function convertToOpenAIResponsesInput({
3661
3712
  toolSearchToolName,
3662
3713
  customProviderToolNames
3663
3714
  }) {
3664
- 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;
3715
+ 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, _E, _F, _G;
3665
3716
  let input = [];
3666
3717
  const warnings = [];
3667
3718
  const processedApprovalIds = /* @__PURE__ */ new Set();
@@ -4007,8 +4058,23 @@ async function convertToOpenAIResponsesInput({
4007
4058
  const resolvedResultToolName = toolNameMapping.toProviderToolName(
4008
4059
  part.toolName
4009
4060
  );
4061
+ if (resolvedResultToolName === "web_search" || resolvedResultToolName === "web_search_preview") {
4062
+ const itemId = (_u = (_t = (_s = part.providerOptions) == null ? void 0 : _s[providerOptionsName]) == null ? void 0 : _t.itemId) != null ? _u : part.toolCallId;
4063
+ if (store) {
4064
+ input.push({ type: "item_reference", id: itemId });
4065
+ break;
4066
+ }
4067
+ const webSearchCall = await convertWebSearchToolResultOutput({
4068
+ output: part.output,
4069
+ id: itemId
4070
+ });
4071
+ if (webSearchCall != null) {
4072
+ input.push(webSearchCall);
4073
+ break;
4074
+ }
4075
+ }
4010
4076
  if (part.toolName === toolSearchToolName) {
4011
- 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;
4077
+ const itemId = (_A = (_z = (_w = (_v = part.providerOptions) == null ? void 0 : _v[providerOptionsName]) == null ? void 0 : _w.itemId) != null ? _z : (_y = (_x = part.providerMetadata) == null ? void 0 : _x[providerOptionsName]) == null ? void 0 : _y.itemId) != null ? _A : part.toolCallId;
4012
4078
  if (store) {
4013
4079
  input.push({ type: "item_reference", id: itemId });
4014
4080
  } else if (part.output.type === "json") {
@@ -4049,7 +4115,7 @@ async function convertToOpenAIResponsesInput({
4049
4115
  break;
4050
4116
  }
4051
4117
  if (store) {
4052
- const itemId = (_A = (_z = (_y = part.providerOptions) == null ? void 0 : _y[providerOptionsName]) == null ? void 0 : _z.itemId) != null ? _A : part.toolCallId;
4118
+ const itemId = (_D = (_C = (_B = part.providerOptions) == null ? void 0 : _B[providerOptionsName]) == null ? void 0 : _C.itemId) != null ? _D : part.toolCallId;
4053
4119
  input.push({ type: "item_reference", id: itemId });
4054
4120
  } else {
4055
4121
  warnings.push({
@@ -4216,7 +4282,7 @@ ${text}`,
4216
4282
  }
4217
4283
  const output = part.output;
4218
4284
  if (output.type === "execution-denied") {
4219
- const approvalId = (_C = (_B = output.providerOptions) == null ? void 0 : _B.openai) == null ? void 0 : _C.approvalId;
4285
+ const approvalId = (_F = (_E = output.providerOptions) == null ? void 0 : _E.openai) == null ? void 0 : _F.approvalId;
4220
4286
  if (approvalId) {
4221
4287
  continue;
4222
4288
  }
@@ -4303,7 +4369,7 @@ ${text}`,
4303
4369
  break;
4304
4370
  case "execution-denied":
4305
4371
  outputValue = convertScalarOutput(
4306
- (_D = output.reason) != null ? _D : "Tool call execution denied."
4372
+ (_G = output.reason) != null ? _G : "Tool call execution denied."
4307
4373
  );
4308
4374
  break;
4309
4375
  case "json":
@@ -4499,7 +4565,7 @@ var openaiResponsesNestedErrorChunkSchema = import_v423.z.object({
4499
4565
  sequence_number: import_v423.z.number(),
4500
4566
  error: import_v423.z.object({
4501
4567
  type: import_v423.z.string(),
4502
- code: import_v423.z.string(),
4568
+ code: import_v423.z.string().nullish(),
4503
4569
  message: import_v423.z.string(),
4504
4570
  param: import_v423.z.string().nullish()
4505
4571
  })
@@ -8232,7 +8298,7 @@ var OpenAITranscriptionModel = class {
8232
8298
  };
8233
8299
 
8234
8300
  // src/version.ts
8235
- var VERSION = true ? "3.0.124" : "0.0.0-test";
8301
+ var VERSION = true ? "3.0.125" : "0.0.0-test";
8236
8302
 
8237
8303
  // src/openai-provider.ts
8238
8304
  function createOpenAI(options = {}) {