@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.
@@ -4424,7 +4424,21 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema17(
4424
4424
  * When enabled, the SDK applies reasoning-model parameter compatibility rules
4425
4425
  * and defaults `systemMessageMode` to `developer` unless overridden.
4426
4426
  */
4427
- forceReasoning: z19.boolean().optional()
4427
+ forceReasoning: z19.boolean().optional(),
4428
+ /**
4429
+ * Restrict the callable tools to a subset while keeping the full tools
4430
+ * list intact, so prompt caching is preserved across requests with
4431
+ * different allowlists.
4432
+ *
4433
+ * When set, this overrides the request-level `toolChoice` and emits
4434
+ * `tool_choice: { type: "allowed_tools", mode, tools }` on the wire.
4435
+ *
4436
+ * @see https://developers.openai.com/api/reference/resources/responses/methods/create#(resource)%20responses%20%3E%20(model)%20tool_choice_allowed%20%3E%20(schema)
4437
+ */
4438
+ allowedTools: z19.object({
4439
+ toolNames: z19.array(z19.string()).min(1),
4440
+ mode: z19.enum(["auto", "required"]).optional()
4441
+ }).optional()
4428
4442
  })
4429
4443
  )
4430
4444
  );
@@ -4784,10 +4798,11 @@ var webSearchPreview = createProviderToolFactoryWithOutputSchema10({
4784
4798
  async function prepareResponsesTools({
4785
4799
  tools,
4786
4800
  toolChoice,
4801
+ allowedTools,
4787
4802
  toolNameMapping,
4788
4803
  customProviderToolNames
4789
4804
  }) {
4790
- var _a, _b;
4805
+ var _a, _b, _c;
4791
4806
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
4792
4807
  const toolWarnings = [];
4793
4808
  if (tools == null) {
@@ -4978,6 +4993,23 @@ async function prepareResponsesTools({
4978
4993
  break;
4979
4994
  }
4980
4995
  }
4996
+ if (allowedTools != null) {
4997
+ return {
4998
+ tools: openaiTools,
4999
+ toolChoice: {
5000
+ type: "allowed_tools",
5001
+ mode: (_b = allowedTools.mode) != null ? _b : "auto",
5002
+ tools: allowedTools.toolNames.map((name) => {
5003
+ var _a2;
5004
+ return {
5005
+ type: "function",
5006
+ name: (_a2 = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(name)) != null ? _a2 : name
5007
+ };
5008
+ })
5009
+ },
5010
+ toolWarnings
5011
+ };
5012
+ }
4981
5013
  if (toolChoice == null) {
4982
5014
  return { tools: openaiTools, toolChoice: void 0, toolWarnings };
4983
5015
  }
@@ -4988,7 +5020,7 @@ async function prepareResponsesTools({
4988
5020
  case "required":
4989
5021
  return { tools: openaiTools, toolChoice: type, toolWarnings };
4990
5022
  case "tool": {
4991
- const resolvedToolName = (_b = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _b : toolChoice.toolName;
5023
+ const resolvedToolName = (_c = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _c : toolChoice.toolName;
4992
5024
  return {
4993
5025
  tools: openaiTools,
4994
5026
  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 },
@@ -5094,7 +5126,7 @@ var OpenAIResponsesLanguageModel = class {
5094
5126
  toolChoice,
5095
5127
  responseFormat
5096
5128
  }) {
5097
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
5129
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
5098
5130
  const warnings = [];
5099
5131
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
5100
5132
  if (topK != null) {
@@ -5157,16 +5189,17 @@ var OpenAIResponsesLanguageModel = class {
5157
5189
  } = await prepareResponsesTools({
5158
5190
  tools,
5159
5191
  toolChoice,
5192
+ allowedTools: (_b = openaiOptions == null ? void 0 : openaiOptions.allowedTools) != null ? _b : void 0,
5160
5193
  toolNameMapping,
5161
5194
  customProviderToolNames
5162
5195
  });
5163
5196
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
5164
5197
  prompt,
5165
5198
  toolNameMapping,
5166
- systemMessageMode: (_b = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _b : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
5199
+ systemMessageMode: (_c = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _c : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
5167
5200
  providerOptionsName,
5168
5201
  fileIdPrefixes: this.config.fileIdPrefixes,
5169
- store: (_c = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _c : true,
5202
+ store: (_d = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _d : true,
5170
5203
  hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
5171
5204
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
5172
5205
  hasShellTool: hasOpenAITool("openai.shell"),
@@ -5174,7 +5207,7 @@ var OpenAIResponsesLanguageModel = class {
5174
5207
  customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
5175
5208
  });
5176
5209
  warnings.push(...inputWarnings);
5177
- const strictJsonSchema = (_d = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _d : true;
5210
+ const strictJsonSchema = (_e = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _e : true;
5178
5211
  let include = openaiOptions == null ? void 0 : openaiOptions.include;
5179
5212
  function addInclude(key) {
5180
5213
  if (include == null) {
@@ -5190,9 +5223,9 @@ var OpenAIResponsesLanguageModel = class {
5190
5223
  if (topLogprobs) {
5191
5224
  addInclude("message.output_text.logprobs");
5192
5225
  }
5193
- const webSearchToolName = (_e = tools == null ? void 0 : tools.find(
5226
+ const webSearchToolName = (_f = tools == null ? void 0 : tools.find(
5194
5227
  (tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
5195
- )) == null ? void 0 : _e.name;
5228
+ )) == null ? void 0 : _f.name;
5196
5229
  if (webSearchToolName) {
5197
5230
  addInclude("web_search_call.action.sources");
5198
5231
  }
@@ -5215,7 +5248,7 @@ var OpenAIResponsesLanguageModel = class {
5215
5248
  format: responseFormat.schema != null ? {
5216
5249
  type: "json_schema",
5217
5250
  strict: strictJsonSchema,
5218
- name: (_f = responseFormat.name) != null ? _f : "response",
5251
+ name: (_g = responseFormat.name) != null ? _g : "response",
5219
5252
  description: responseFormat.description,
5220
5253
  schema: responseFormat.schema
5221
5254
  } : { type: "json_object" }
@@ -5304,9 +5337,9 @@ var OpenAIResponsesLanguageModel = class {
5304
5337
  });
5305
5338
  delete baseArgs.service_tier;
5306
5339
  }
5307
- const shellToolEnvType = (_i = (_h = (_g = tools == null ? void 0 : tools.find(
5340
+ const shellToolEnvType = (_j = (_i = (_h = tools == null ? void 0 : tools.find(
5308
5341
  (tool) => tool.type === "provider" && tool.id === "openai.shell"
5309
- )) == null ? void 0 : _g.args) == null ? void 0 : _h.environment) == null ? void 0 : _i.type;
5342
+ )) == null ? void 0 : _h.args) == null ? void 0 : _i.environment) == null ? void 0 : _j.type;
5310
5343
  const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
5311
5344
  return {
5312
5345
  webSearchToolName,