@ai-sdk/openai 3.0.60 → 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.
@@ -3149,24 +3149,26 @@ async function convertToOpenAIResponsesInput({
3149
3149
  break;
3150
3150
  case "content":
3151
3151
  outputValue = output.value.map((item) => {
3152
- var _a2;
3152
+ var _a2, _b2, _c2, _d2, _e2;
3153
3153
  switch (item.type) {
3154
3154
  case "text":
3155
3155
  return { type: "input_text", text: item.text };
3156
3156
  case "image-data":
3157
3157
  return {
3158
3158
  type: "input_image",
3159
- image_url: `data:${item.mediaType};base64,${item.data}`
3159
+ image_url: `data:${item.mediaType};base64,${item.data}`,
3160
+ detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail
3160
3161
  };
3161
3162
  case "image-url":
3162
3163
  return {
3163
3164
  type: "input_image",
3164
- image_url: item.url
3165
+ image_url: item.url,
3166
+ detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail
3165
3167
  };
3166
3168
  case "file-data":
3167
3169
  return {
3168
3170
  type: "input_file",
3169
- filename: (_a2 = item.filename) != null ? _a2 : "data",
3171
+ filename: (_e2 = item.filename) != null ? _e2 : "data",
3170
3172
  file_data: `data:${item.mediaType};base64,${item.data}`
3171
3173
  };
3172
3174
  case "file-url":
@@ -3208,7 +3210,7 @@ async function convertToOpenAIResponsesInput({
3208
3210
  break;
3209
3211
  case "content":
3210
3212
  contentValue = output.value.map((item) => {
3211
- var _a2;
3213
+ var _a2, _b2, _c2, _d2, _e2;
3212
3214
  switch (item.type) {
3213
3215
  case "text": {
3214
3216
  return { type: "input_text", text: item.text };
@@ -3216,19 +3218,21 @@ async function convertToOpenAIResponsesInput({
3216
3218
  case "image-data": {
3217
3219
  return {
3218
3220
  type: "input_image",
3219
- image_url: `data:${item.mediaType};base64,${item.data}`
3221
+ image_url: `data:${item.mediaType};base64,${item.data}`,
3222
+ detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail
3220
3223
  };
3221
3224
  }
3222
3225
  case "image-url": {
3223
3226
  return {
3224
3227
  type: "input_image",
3225
- image_url: item.url
3228
+ image_url: item.url,
3229
+ detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail
3226
3230
  };
3227
3231
  }
3228
3232
  case "file-data": {
3229
3233
  return {
3230
3234
  type: "input_file",
3231
- filename: (_a2 = item.filename) != null ? _a2 : "data",
3235
+ filename: (_e2 = item.filename) != null ? _e2 : "data",
3232
3236
  file_data: `data:${item.mediaType};base64,${item.data}`
3233
3237
  };
3234
3238
  }
@@ -4366,7 +4370,21 @@ var openaiLanguageModelResponsesOptionsSchema = (0, import_provider_utils26.lazy
4366
4370
  * When enabled, the SDK applies reasoning-model parameter compatibility rules
4367
4371
  * and defaults `systemMessageMode` to `developer` unless overridden.
4368
4372
  */
4369
- forceReasoning: import_v419.z.boolean().optional()
4373
+ forceReasoning: import_v419.z.boolean().optional(),
4374
+ /**
4375
+ * Restrict the callable tools to a subset while keeping the full tools
4376
+ * list intact, so prompt caching is preserved across requests with
4377
+ * different allowlists.
4378
+ *
4379
+ * When set, this overrides the request-level `toolChoice` and emits
4380
+ * `tool_choice: { type: "allowed_tools", mode, tools }` on the wire.
4381
+ *
4382
+ * @see https://developers.openai.com/api/reference/resources/responses/methods/create#(resource)%20responses%20%3E%20(model)%20tool_choice_allowed%20%3E%20(schema)
4383
+ */
4384
+ allowedTools: import_v419.z.object({
4385
+ toolNames: import_v419.z.array(import_v419.z.string()).min(1),
4386
+ mode: import_v419.z.enum(["auto", "required"]).optional()
4387
+ }).optional()
4370
4388
  })
4371
4389
  )
4372
4390
  );
@@ -4696,10 +4714,11 @@ var webSearchPreview = (0, import_provider_utils33.createProviderToolFactoryWith
4696
4714
  async function prepareResponsesTools({
4697
4715
  tools,
4698
4716
  toolChoice,
4717
+ allowedTools,
4699
4718
  toolNameMapping,
4700
4719
  customProviderToolNames
4701
4720
  }) {
4702
- var _a, _b;
4721
+ var _a, _b, _c;
4703
4722
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
4704
4723
  const toolWarnings = [];
4705
4724
  if (tools == null) {
@@ -4890,6 +4909,23 @@ async function prepareResponsesTools({
4890
4909
  break;
4891
4910
  }
4892
4911
  }
4912
+ if (allowedTools != null) {
4913
+ return {
4914
+ tools: openaiTools,
4915
+ toolChoice: {
4916
+ type: "allowed_tools",
4917
+ mode: (_b = allowedTools.mode) != null ? _b : "auto",
4918
+ tools: allowedTools.toolNames.map((name) => {
4919
+ var _a2;
4920
+ return {
4921
+ type: "function",
4922
+ name: (_a2 = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(name)) != null ? _a2 : name
4923
+ };
4924
+ })
4925
+ },
4926
+ toolWarnings
4927
+ };
4928
+ }
4893
4929
  if (toolChoice == null) {
4894
4930
  return { tools: openaiTools, toolChoice: void 0, toolWarnings };
4895
4931
  }
@@ -4900,7 +4936,7 @@ async function prepareResponsesTools({
4900
4936
  case "required":
4901
4937
  return { tools: openaiTools, toolChoice: type, toolWarnings };
4902
4938
  case "tool": {
4903
- const resolvedToolName = (_b = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _b : toolChoice.toolName;
4939
+ const resolvedToolName = (_c = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _c : toolChoice.toolName;
4904
4940
  return {
4905
4941
  tools: openaiTools,
4906
4942
  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 },
@@ -5006,7 +5042,7 @@ var OpenAIResponsesLanguageModel = class {
5006
5042
  toolChoice,
5007
5043
  responseFormat
5008
5044
  }) {
5009
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
5045
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
5010
5046
  const warnings = [];
5011
5047
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
5012
5048
  if (topK != null) {
@@ -5069,16 +5105,17 @@ var OpenAIResponsesLanguageModel = class {
5069
5105
  } = await prepareResponsesTools({
5070
5106
  tools,
5071
5107
  toolChoice,
5108
+ allowedTools: (_b = openaiOptions == null ? void 0 : openaiOptions.allowedTools) != null ? _b : void 0,
5072
5109
  toolNameMapping,
5073
5110
  customProviderToolNames
5074
5111
  });
5075
5112
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
5076
5113
  prompt,
5077
5114
  toolNameMapping,
5078
- systemMessageMode: (_b = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _b : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
5115
+ systemMessageMode: (_c = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _c : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
5079
5116
  providerOptionsName,
5080
5117
  fileIdPrefixes: this.config.fileIdPrefixes,
5081
- store: (_c = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _c : true,
5118
+ store: (_d = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _d : true,
5082
5119
  hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
5083
5120
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
5084
5121
  hasShellTool: hasOpenAITool("openai.shell"),
@@ -5086,7 +5123,7 @@ var OpenAIResponsesLanguageModel = class {
5086
5123
  customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
5087
5124
  });
5088
5125
  warnings.push(...inputWarnings);
5089
- const strictJsonSchema = (_d = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _d : true;
5126
+ const strictJsonSchema = (_e = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _e : true;
5090
5127
  let include = openaiOptions == null ? void 0 : openaiOptions.include;
5091
5128
  function addInclude(key) {
5092
5129
  if (include == null) {
@@ -5102,9 +5139,9 @@ var OpenAIResponsesLanguageModel = class {
5102
5139
  if (topLogprobs) {
5103
5140
  addInclude("message.output_text.logprobs");
5104
5141
  }
5105
- const webSearchToolName = (_e = tools == null ? void 0 : tools.find(
5142
+ const webSearchToolName = (_f = tools == null ? void 0 : tools.find(
5106
5143
  (tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
5107
- )) == null ? void 0 : _e.name;
5144
+ )) == null ? void 0 : _f.name;
5108
5145
  if (webSearchToolName) {
5109
5146
  addInclude("web_search_call.action.sources");
5110
5147
  }
@@ -5127,7 +5164,7 @@ var OpenAIResponsesLanguageModel = class {
5127
5164
  format: responseFormat.schema != null ? {
5128
5165
  type: "json_schema",
5129
5166
  strict: strictJsonSchema,
5130
- name: (_f = responseFormat.name) != null ? _f : "response",
5167
+ name: (_g = responseFormat.name) != null ? _g : "response",
5131
5168
  description: responseFormat.description,
5132
5169
  schema: responseFormat.schema
5133
5170
  } : { type: "json_object" }
@@ -5216,9 +5253,9 @@ var OpenAIResponsesLanguageModel = class {
5216
5253
  });
5217
5254
  delete baseArgs.service_tier;
5218
5255
  }
5219
- const shellToolEnvType = (_i = (_h = (_g = tools == null ? void 0 : tools.find(
5256
+ const shellToolEnvType = (_j = (_i = (_h = tools == null ? void 0 : tools.find(
5220
5257
  (tool) => tool.type === "provider" && tool.id === "openai.shell"
5221
- )) == null ? void 0 : _g.args) == null ? void 0 : _h.environment) == null ? void 0 : _i.type;
5258
+ )) == null ? void 0 : _h.args) == null ? void 0 : _i.environment) == null ? void 0 : _j.type;
5222
5259
  const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
5223
5260
  return {
5224
5261
  webSearchToolName,