@ai-sdk/openai 2.0.133 → 2.0.134

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
@@ -2349,6 +2349,7 @@ import {
2349
2349
  import {
2350
2350
  convertToBase64 as convertToBase642,
2351
2351
  parseProviderOptions as parseProviderOptions5,
2352
+ safeValidateTypes,
2352
2353
  validateTypes
2353
2354
  } from "@ai-sdk/provider-utils";
2354
2355
  import { z as z17 } from "zod/v4";
@@ -2559,6 +2560,56 @@ var openaiResponsesSystemMessageOptionsSchema = lazyValidator9(
2559
2560
  );
2560
2561
 
2561
2562
  // src/responses/convert-to-openai-responses-input.ts
2563
+ async function convertWebSearchToolResultOutput({
2564
+ output,
2565
+ id
2566
+ }) {
2567
+ if (output.type !== "json") {
2568
+ return void 0;
2569
+ }
2570
+ const validation = await safeValidateTypes({
2571
+ value: output.value,
2572
+ schema: webSearchOutputSchema
2573
+ });
2574
+ if (!validation.success || validation.value.action == null) {
2575
+ return void 0;
2576
+ }
2577
+ const { action, sources } = validation.value;
2578
+ switch (action.type) {
2579
+ case "search":
2580
+ return {
2581
+ type: "web_search_call",
2582
+ id,
2583
+ status: "completed",
2584
+ action: {
2585
+ type: "search",
2586
+ ...action.query != null && { query: action.query },
2587
+ ...sources != null && { sources }
2588
+ }
2589
+ };
2590
+ case "openPage":
2591
+ return {
2592
+ type: "web_search_call",
2593
+ id,
2594
+ status: "completed",
2595
+ action: {
2596
+ type: "open_page",
2597
+ url: action.url
2598
+ }
2599
+ };
2600
+ case "findInPage":
2601
+ return {
2602
+ type: "web_search_call",
2603
+ id,
2604
+ status: "completed",
2605
+ action: {
2606
+ type: "find_in_page",
2607
+ url: action.url,
2608
+ pattern: action.pattern
2609
+ }
2610
+ };
2611
+ }
2612
+ }
2562
2613
  function getPromptCacheBreakpoint2(providerOptions) {
2563
2614
  var _a2;
2564
2615
  return (_a2 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a2.promptCacheBreakpoint;
@@ -2575,9 +2626,10 @@ async function convertToOpenAIResponsesInput({
2575
2626
  fileIdPrefixes,
2576
2627
  store,
2577
2628
  configurationUpdateUnsupportedReason,
2578
- hasLocalShellTool = false
2629
+ hasLocalShellTool = false,
2630
+ webSearchToolName
2579
2631
  }) {
2580
- var _a2, _b, _c, _d, _e, _f, _g, _h;
2632
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2581
2633
  let input = [];
2582
2634
  const warnings = [];
2583
2635
  for (const { role, content, providerOptions } of prompt) {
@@ -2787,6 +2839,21 @@ async function convertToOpenAIResponsesInput({
2787
2839
  }
2788
2840
  // assistant tool result parts are from provider-executed tools:
2789
2841
  case "tool-result": {
2842
+ if (part.toolName === "web_search" || part.toolName === "web_search_preview" || part.toolName === webSearchToolName) {
2843
+ const itemId = (_k = (_j = (_i = part.providerOptions) == null ? void 0 : _i[providerOptionsName]) == null ? void 0 : _j.itemId) != null ? _k : part.toolCallId;
2844
+ if (store) {
2845
+ input.push({ type: "item_reference", id: itemId });
2846
+ break;
2847
+ }
2848
+ const webSearchCall = await convertWebSearchToolResultOutput({
2849
+ output: part.output,
2850
+ id: itemId
2851
+ });
2852
+ if (webSearchCall != null) {
2853
+ input.push(webSearchCall);
2854
+ break;
2855
+ }
2856
+ }
2790
2857
  if (store) {
2791
2858
  input.push({ type: "item_reference", id: part.toolCallId });
2792
2859
  } else {
@@ -3722,6 +3789,9 @@ var OpenAIResponsesLanguageModel = class {
3722
3789
  modelCapabilities,
3723
3790
  options: openaiOptions
3724
3791
  });
3792
+ const webSearchToolName = (_a2 = tools == null ? void 0 : tools.find(
3793
+ (tool) => tool.type === "provider-defined" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
3794
+ )) == null ? void 0 : _a2.name;
3725
3795
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
3726
3796
  prompt,
3727
3797
  configurationUpdateUnsupportedReason,
@@ -3729,8 +3799,9 @@ var OpenAIResponsesLanguageModel = class {
3729
3799
  systemMessageMode: modelCapabilities.systemMessageMode,
3730
3800
  explicitMessageItemType: this.config.explicitMessageItemType,
3731
3801
  fileIdPrefixes: this.config.fileIdPrefixes,
3732
- store: (_a2 = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _a2 : true,
3733
- hasLocalShellTool: hasOpenAITool("openai.local_shell")
3802
+ store: (_b = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _b : true,
3803
+ hasLocalShellTool: hasOpenAITool("openai.local_shell"),
3804
+ webSearchToolName
3734
3805
  });
3735
3806
  warnings.push(...inputWarnings);
3736
3807
  let resolvedReasoningEffort = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort;
@@ -3767,7 +3838,7 @@ var OpenAIResponsesLanguageModel = class {
3767
3838
  });
3768
3839
  }
3769
3840
  }
3770
- const strictJsonSchema = (_b = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _b : false;
3841
+ const strictJsonSchema = (_c = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _c : false;
3771
3842
  let include = openaiOptions == null ? void 0 : openaiOptions.include;
3772
3843
  function addInclude(key) {
3773
3844
  if (include == null) {
@@ -3785,9 +3856,6 @@ var OpenAIResponsesLanguageModel = class {
3785
3856
  if (topLogprobs) {
3786
3857
  addInclude("message.output_text.logprobs");
3787
3858
  }
3788
- const webSearchToolName = (_c = tools == null ? void 0 : tools.find(
3789
- (tool) => tool.type === "provider-defined" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
3790
- )) == null ? void 0 : _c.name;
3791
3859
  if (webSearchToolName) {
3792
3860
  addInclude("web_search_call.action.sources");
3793
3861
  }
@@ -5236,7 +5304,7 @@ var OpenAITranscriptionModel = class {
5236
5304
  };
5237
5305
 
5238
5306
  // src/version.ts
5239
- var VERSION = true ? "2.0.133" : "0.0.0-test";
5307
+ var VERSION = true ? "2.0.134" : "0.0.0-test";
5240
5308
 
5241
5309
  // src/openai-provider.ts
5242
5310
  function createOpenAI(options = {}) {