@ai-sdk/openai 2.0.15 → 2.0.17

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,18 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 2.0.17
4
+
5
+ ### Patch Changes
6
+
7
+ - 70bb696: fix(provider/openai): correct web search tool input
8
+
9
+ ## 2.0.16
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [68751f9]
14
+ - @ai-sdk/provider-utils@3.0.4
15
+
3
16
  ## 2.0.15
4
17
 
5
18
  ### Patch Changes
package/dist/index.js CHANGED
@@ -436,7 +436,23 @@ var webSearchPreviewArgsSchema = import_v44.z.object({
436
436
  var webSearchPreview = (0, import_provider_utils4.createProviderDefinedToolFactory)({
437
437
  id: "openai.web_search_preview",
438
438
  name: "web_search_preview",
439
- inputSchema: import_v44.z.object({})
439
+ inputSchema: import_v44.z.object({
440
+ action: import_v44.z.discriminatedUnion("type", [
441
+ import_v44.z.object({
442
+ type: import_v44.z.literal("search"),
443
+ query: import_v44.z.string()
444
+ }),
445
+ import_v44.z.object({
446
+ type: import_v44.z.literal("open_page"),
447
+ url: import_v44.z.string()
448
+ }),
449
+ import_v44.z.object({
450
+ type: import_v44.z.literal("find"),
451
+ url: import_v44.z.string(),
452
+ pattern: import_v44.z.string()
453
+ })
454
+ ]).nullish()
455
+ })
440
456
  });
441
457
 
442
458
  // src/chat/openai-chat-prepare-tools.ts
@@ -2127,6 +2143,26 @@ function prepareResponsesTools({
2127
2143
  }
2128
2144
 
2129
2145
  // src/responses/openai-responses-language-model.ts
2146
+ var webSearchCallItem = import_v413.z.object({
2147
+ type: import_v413.z.literal("web_search_call"),
2148
+ id: import_v413.z.string(),
2149
+ status: import_v413.z.string(),
2150
+ action: import_v413.z.discriminatedUnion("type", [
2151
+ import_v413.z.object({
2152
+ type: import_v413.z.literal("search"),
2153
+ query: import_v413.z.string()
2154
+ }),
2155
+ import_v413.z.object({
2156
+ type: import_v413.z.literal("open_page"),
2157
+ url: import_v413.z.string()
2158
+ }),
2159
+ import_v413.z.object({
2160
+ type: import_v413.z.literal("find"),
2161
+ url: import_v413.z.string(),
2162
+ pattern: import_v413.z.string()
2163
+ })
2164
+ ]).nullish()
2165
+ });
2130
2166
  var TOP_LOGPROBS_MAX = 20;
2131
2167
  var LOGPROBS_SCHEMA = import_v413.z.array(
2132
2168
  import_v413.z.object({
@@ -2322,7 +2358,7 @@ var OpenAIResponsesLanguageModel = class {
2322
2358
  };
2323
2359
  }
2324
2360
  async doGenerate(options) {
2325
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
2361
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
2326
2362
  const { args: body, warnings } = await this.getArgs(options);
2327
2363
  const url = this.config.url({
2328
2364
  path: "/responses",
@@ -2385,15 +2421,7 @@ var OpenAIResponsesLanguageModel = class {
2385
2421
  arguments: import_v413.z.string(),
2386
2422
  id: import_v413.z.string()
2387
2423
  }),
2388
- import_v413.z.object({
2389
- type: import_v413.z.literal("web_search_call"),
2390
- id: import_v413.z.string(),
2391
- status: import_v413.z.string().optional(),
2392
- action: import_v413.z.object({
2393
- type: import_v413.z.literal("search"),
2394
- query: import_v413.z.string().optional()
2395
- }).nullish()
2396
- }),
2424
+ webSearchCallItem,
2397
2425
  import_v413.z.object({
2398
2426
  type: import_v413.z.literal("computer_call"),
2399
2427
  id: import_v413.z.string(),
@@ -2524,17 +2552,14 @@ var OpenAIResponsesLanguageModel = class {
2524
2552
  type: "tool-call",
2525
2553
  toolCallId: part.id,
2526
2554
  toolName: "web_search_preview",
2527
- input: (_k = (_j = part.action) == null ? void 0 : _j.query) != null ? _k : "",
2555
+ input: JSON.stringify({ action: part.action }),
2528
2556
  providerExecuted: true
2529
2557
  });
2530
2558
  content.push({
2531
2559
  type: "tool-result",
2532
2560
  toolCallId: part.id,
2533
2561
  toolName: "web_search_preview",
2534
- result: {
2535
- status: part.status || "completed",
2536
- ...((_l = part.action) == null ? void 0 : _l.query) && { query: part.action.query }
2537
- },
2562
+ result: { status: part.status },
2538
2563
  providerExecuted: true
2539
2564
  });
2540
2565
  break;
@@ -2592,15 +2617,15 @@ var OpenAIResponsesLanguageModel = class {
2592
2617
  return {
2593
2618
  content,
2594
2619
  finishReason: mapOpenAIResponseFinishReason({
2595
- finishReason: (_m = response.incomplete_details) == null ? void 0 : _m.reason,
2620
+ finishReason: (_j = response.incomplete_details) == null ? void 0 : _j.reason,
2596
2621
  hasToolCalls: content.some((part) => part.type === "tool-call")
2597
2622
  }),
2598
2623
  usage: {
2599
2624
  inputTokens: response.usage.input_tokens,
2600
2625
  outputTokens: response.usage.output_tokens,
2601
2626
  totalTokens: response.usage.input_tokens + response.usage.output_tokens,
2602
- reasoningTokens: (_o = (_n = response.usage.output_tokens_details) == null ? void 0 : _n.reasoning_tokens) != null ? _o : void 0,
2603
- cachedInputTokens: (_q = (_p = response.usage.input_tokens_details) == null ? void 0 : _p.cached_tokens) != null ? _q : void 0
2627
+ reasoningTokens: (_l = (_k = response.usage.output_tokens_details) == null ? void 0 : _k.reasoning_tokens) != null ? _l : void 0,
2628
+ cachedInputTokens: (_n = (_m = response.usage.input_tokens_details) == null ? void 0 : _m.cached_tokens) != null ? _n : void 0
2604
2629
  },
2605
2630
  request: { body },
2606
2631
  response: {
@@ -2652,7 +2677,7 @@ var OpenAIResponsesLanguageModel = class {
2652
2677
  controller.enqueue({ type: "stream-start", warnings });
2653
2678
  },
2654
2679
  transform(chunk, controller) {
2655
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
2680
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
2656
2681
  if (options.includeRawChunks) {
2657
2682
  controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
2658
2683
  }
@@ -2759,20 +2784,14 @@ var OpenAIResponsesLanguageModel = class {
2759
2784
  type: "tool-call",
2760
2785
  toolCallId: value.item.id,
2761
2786
  toolName: "web_search_preview",
2762
- input: (_c = (_b = value.item.action) == null ? void 0 : _b.query) != null ? _c : "",
2787
+ input: JSON.stringify({ action: value.item.action }),
2763
2788
  providerExecuted: true
2764
2789
  });
2765
2790
  controller.enqueue({
2766
2791
  type: "tool-result",
2767
2792
  toolCallId: value.item.id,
2768
2793
  toolName: "web_search_preview",
2769
- result: {
2770
- type: "web_search_tool_result",
2771
- status: value.item.status || "completed",
2772
- ...((_d = value.item.action) == null ? void 0 : _d.query) && {
2773
- query: value.item.action.query
2774
- }
2775
- },
2794
+ result: { status: value.item.status },
2776
2795
  providerExecuted: true
2777
2796
  });
2778
2797
  } else if (value.item.type === "computer_call") {
@@ -2839,7 +2858,7 @@ var OpenAIResponsesLanguageModel = class {
2839
2858
  providerMetadata: {
2840
2859
  openai: {
2841
2860
  itemId: value.item.id,
2842
- reasoningEncryptedContent: (_e = value.item.encrypted_content) != null ? _e : null
2861
+ reasoningEncryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
2843
2862
  }
2844
2863
  }
2845
2864
  });
@@ -2874,7 +2893,7 @@ var OpenAIResponsesLanguageModel = class {
2874
2893
  }
2875
2894
  } else if (isResponseReasoningSummaryPartAddedChunk(value)) {
2876
2895
  if (value.summary_index > 0) {
2877
- (_f = activeReasoning[value.item_id]) == null ? void 0 : _f.summaryParts.push(
2896
+ (_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
2878
2897
  value.summary_index
2879
2898
  );
2880
2899
  controller.enqueue({
@@ -2883,7 +2902,7 @@ var OpenAIResponsesLanguageModel = class {
2883
2902
  providerMetadata: {
2884
2903
  openai: {
2885
2904
  itemId: value.item_id,
2886
- reasoningEncryptedContent: (_h = (_g = activeReasoning[value.item_id]) == null ? void 0 : _g.encryptedContent) != null ? _h : null
2905
+ reasoningEncryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
2887
2906
  }
2888
2907
  }
2889
2908
  });
@@ -2901,20 +2920,20 @@ var OpenAIResponsesLanguageModel = class {
2901
2920
  });
2902
2921
  } else if (isResponseFinishedChunk(value)) {
2903
2922
  finishReason = mapOpenAIResponseFinishReason({
2904
- finishReason: (_i = value.response.incomplete_details) == null ? void 0 : _i.reason,
2923
+ finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
2905
2924
  hasToolCalls
2906
2925
  });
2907
2926
  usage.inputTokens = value.response.usage.input_tokens;
2908
2927
  usage.outputTokens = value.response.usage.output_tokens;
2909
2928
  usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
2910
- usage.reasoningTokens = (_k = (_j = value.response.usage.output_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0;
2911
- usage.cachedInputTokens = (_m = (_l = value.response.usage.input_tokens_details) == null ? void 0 : _l.cached_tokens) != null ? _m : void 0;
2929
+ usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
2930
+ usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
2912
2931
  } else if (isResponseAnnotationAddedChunk(value)) {
2913
2932
  if (value.annotation.type === "url_citation") {
2914
2933
  controller.enqueue({
2915
2934
  type: "source",
2916
2935
  sourceType: "url",
2917
- id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : (0, import_provider_utils12.generateId)(),
2936
+ id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : (0, import_provider_utils12.generateId)(),
2918
2937
  url: value.annotation.url,
2919
2938
  title: value.annotation.title
2920
2939
  });
@@ -2922,7 +2941,7 @@ var OpenAIResponsesLanguageModel = class {
2922
2941
  controller.enqueue({
2923
2942
  type: "source",
2924
2943
  sourceType: "document",
2925
- id: (_s = (_r = (_q = self.config).generateId) == null ? void 0 : _r.call(_q)) != null ? _s : (0, import_provider_utils12.generateId)(),
2944
+ id: (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : (0, import_provider_utils12.generateId)(),
2926
2945
  mediaType: "text/plain",
2927
2946
  title: value.annotation.quote,
2928
2947
  filename: value.annotation.file_id
@@ -3062,15 +3081,7 @@ var responseOutputItemDoneSchema = import_v413.z.object({
3062
3081
  arguments: import_v413.z.string(),
3063
3082
  status: import_v413.z.literal("completed")
3064
3083
  }),
3065
- import_v413.z.object({
3066
- type: import_v413.z.literal("web_search_call"),
3067
- id: import_v413.z.string(),
3068
- status: import_v413.z.literal("completed"),
3069
- action: import_v413.z.object({
3070
- type: import_v413.z.literal("search"),
3071
- query: import_v413.z.string().optional()
3072
- }).nullish()
3073
- }),
3084
+ webSearchCallItem,
3074
3085
  import_v413.z.object({
3075
3086
  type: import_v413.z.literal("computer_call"),
3076
3087
  id: import_v413.z.string(),