@ai-sdk/openai 3.0.61 → 3.0.62

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
@@ -4527,7 +4527,21 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema21(
4527
4527
  * When enabled, the SDK applies reasoning-model parameter compatibility rules
4528
4528
  * and defaults `systemMessageMode` to `developer` unless overridden.
4529
4529
  */
4530
- forceReasoning: z23.boolean().optional()
4530
+ forceReasoning: z23.boolean().optional(),
4531
+ /**
4532
+ * Restrict the callable tools to a subset while keeping the full tools
4533
+ * list intact, so prompt caching is preserved across requests with
4534
+ * different allowlists.
4535
+ *
4536
+ * When set, this overrides the request-level `toolChoice` and emits
4537
+ * `tool_choice: { type: "allowed_tools", mode, tools }` on the wire.
4538
+ *
4539
+ * @see https://developers.openai.com/api/reference/resources/responses/methods/create#(resource)%20responses%20%3E%20(model)%20tool_choice_allowed%20%3E%20(schema)
4540
+ */
4541
+ allowedTools: z23.object({
4542
+ toolNames: z23.array(z23.string()).min(1),
4543
+ mode: z23.enum(["auto", "required"]).optional()
4544
+ }).optional()
4531
4545
  })
4532
4546
  )
4533
4547
  );
@@ -4540,10 +4554,11 @@ import { validateTypes as validateTypes2 } from "@ai-sdk/provider-utils";
4540
4554
  async function prepareResponsesTools({
4541
4555
  tools,
4542
4556
  toolChoice,
4557
+ allowedTools,
4543
4558
  toolNameMapping,
4544
4559
  customProviderToolNames
4545
4560
  }) {
4546
- var _a, _b;
4561
+ var _a, _b, _c;
4547
4562
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
4548
4563
  const toolWarnings = [];
4549
4564
  if (tools == null) {
@@ -4734,6 +4749,23 @@ async function prepareResponsesTools({
4734
4749
  break;
4735
4750
  }
4736
4751
  }
4752
+ if (allowedTools != null) {
4753
+ return {
4754
+ tools: openaiTools2,
4755
+ toolChoice: {
4756
+ type: "allowed_tools",
4757
+ mode: (_b = allowedTools.mode) != null ? _b : "auto",
4758
+ tools: allowedTools.toolNames.map((name) => {
4759
+ var _a2;
4760
+ return {
4761
+ type: "function",
4762
+ name: (_a2 = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(name)) != null ? _a2 : name
4763
+ };
4764
+ })
4765
+ },
4766
+ toolWarnings
4767
+ };
4768
+ }
4737
4769
  if (toolChoice == null) {
4738
4770
  return { tools: openaiTools2, toolChoice: void 0, toolWarnings };
4739
4771
  }
@@ -4744,7 +4776,7 @@ async function prepareResponsesTools({
4744
4776
  case "required":
4745
4777
  return { tools: openaiTools2, toolChoice: type, toolWarnings };
4746
4778
  case "tool": {
4747
- const resolvedToolName = (_b = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _b : toolChoice.toolName;
4779
+ const resolvedToolName = (_c = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _c : toolChoice.toolName;
4748
4780
  return {
4749
4781
  tools: openaiTools2,
4750
4782
  toolChoice: resolvedToolName === "code_interpreter" || resolvedToolName === "file_search" || resolvedToolName === "image_generation" || resolvedToolName === "web_search_preview" || resolvedToolName === "web_search" || resolvedToolName === "mcp" || resolvedToolName === "apply_patch" ? { type: resolvedToolName } : resolvedCustomProviderToolNames.has(resolvedToolName) ? { type: "custom", name: resolvedToolName } : { type: "function", name: resolvedToolName },
@@ -4850,7 +4882,7 @@ var OpenAIResponsesLanguageModel = class {
4850
4882
  toolChoice,
4851
4883
  responseFormat
4852
4884
  }) {
4853
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4885
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
4854
4886
  const warnings = [];
4855
4887
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
4856
4888
  if (topK != null) {
@@ -4913,16 +4945,17 @@ var OpenAIResponsesLanguageModel = class {
4913
4945
  } = await prepareResponsesTools({
4914
4946
  tools,
4915
4947
  toolChoice,
4948
+ allowedTools: (_b = openaiOptions == null ? void 0 : openaiOptions.allowedTools) != null ? _b : void 0,
4916
4949
  toolNameMapping,
4917
4950
  customProviderToolNames
4918
4951
  });
4919
4952
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
4920
4953
  prompt,
4921
4954
  toolNameMapping,
4922
- systemMessageMode: (_b = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _b : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
4955
+ systemMessageMode: (_c = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _c : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
4923
4956
  providerOptionsName,
4924
4957
  fileIdPrefixes: this.config.fileIdPrefixes,
4925
- store: (_c = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _c : true,
4958
+ store: (_d = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _d : true,
4926
4959
  hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
4927
4960
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
4928
4961
  hasShellTool: hasOpenAITool("openai.shell"),
@@ -4930,7 +4963,7 @@ var OpenAIResponsesLanguageModel = class {
4930
4963
  customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
4931
4964
  });
4932
4965
  warnings.push(...inputWarnings);
4933
- const strictJsonSchema = (_d = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _d : true;
4966
+ const strictJsonSchema = (_e = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _e : true;
4934
4967
  let include = openaiOptions == null ? void 0 : openaiOptions.include;
4935
4968
  function addInclude(key) {
4936
4969
  if (include == null) {
@@ -4946,9 +4979,9 @@ var OpenAIResponsesLanguageModel = class {
4946
4979
  if (topLogprobs) {
4947
4980
  addInclude("message.output_text.logprobs");
4948
4981
  }
4949
- const webSearchToolName = (_e = tools == null ? void 0 : tools.find(
4982
+ const webSearchToolName = (_f = tools == null ? void 0 : tools.find(
4950
4983
  (tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
4951
- )) == null ? void 0 : _e.name;
4984
+ )) == null ? void 0 : _f.name;
4952
4985
  if (webSearchToolName) {
4953
4986
  addInclude("web_search_call.action.sources");
4954
4987
  }
@@ -4971,7 +5004,7 @@ var OpenAIResponsesLanguageModel = class {
4971
5004
  format: responseFormat.schema != null ? {
4972
5005
  type: "json_schema",
4973
5006
  strict: strictJsonSchema,
4974
- name: (_f = responseFormat.name) != null ? _f : "response",
5007
+ name: (_g = responseFormat.name) != null ? _g : "response",
4975
5008
  description: responseFormat.description,
4976
5009
  schema: responseFormat.schema
4977
5010
  } : { type: "json_object" }
@@ -5060,9 +5093,9 @@ var OpenAIResponsesLanguageModel = class {
5060
5093
  });
5061
5094
  delete baseArgs.service_tier;
5062
5095
  }
5063
- const shellToolEnvType = (_i = (_h = (_g = tools == null ? void 0 : tools.find(
5096
+ const shellToolEnvType = (_j = (_i = (_h = tools == null ? void 0 : tools.find(
5064
5097
  (tool) => tool.type === "provider" && tool.id === "openai.shell"
5065
- )) == null ? void 0 : _g.args) == null ? void 0 : _h.environment) == null ? void 0 : _i.type;
5098
+ )) == null ? void 0 : _h.args) == null ? void 0 : _i.environment) == null ? void 0 : _j.type;
5066
5099
  const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
5067
5100
  return {
5068
5101
  webSearchToolName,
@@ -6879,7 +6912,7 @@ var OpenAITranscriptionModel = class {
6879
6912
  };
6880
6913
 
6881
6914
  // src/version.ts
6882
- var VERSION = true ? "3.0.61" : "0.0.0-test";
6915
+ var VERSION = true ? "3.0.62" : "0.0.0-test";
6883
6916
 
6884
6917
  // src/openai-provider.ts
6885
6918
  function createOpenAI(options = {}) {