@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.
package/dist/index.mjs CHANGED
@@ -3300,24 +3300,26 @@ async function convertToOpenAIResponsesInput({
3300
3300
  break;
3301
3301
  case "content":
3302
3302
  outputValue = output.value.map((item) => {
3303
- var _a2;
3303
+ var _a2, _b2, _c2, _d2, _e2;
3304
3304
  switch (item.type) {
3305
3305
  case "text":
3306
3306
  return { type: "input_text", text: item.text };
3307
3307
  case "image-data":
3308
3308
  return {
3309
3309
  type: "input_image",
3310
- image_url: `data:${item.mediaType};base64,${item.data}`
3310
+ image_url: `data:${item.mediaType};base64,${item.data}`,
3311
+ detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail
3311
3312
  };
3312
3313
  case "image-url":
3313
3314
  return {
3314
3315
  type: "input_image",
3315
- image_url: item.url
3316
+ image_url: item.url,
3317
+ detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail
3316
3318
  };
3317
3319
  case "file-data":
3318
3320
  return {
3319
3321
  type: "input_file",
3320
- filename: (_a2 = item.filename) != null ? _a2 : "data",
3322
+ filename: (_e2 = item.filename) != null ? _e2 : "data",
3321
3323
  file_data: `data:${item.mediaType};base64,${item.data}`
3322
3324
  };
3323
3325
  case "file-url":
@@ -3359,7 +3361,7 @@ async function convertToOpenAIResponsesInput({
3359
3361
  break;
3360
3362
  case "content":
3361
3363
  contentValue = output.value.map((item) => {
3362
- var _a2;
3364
+ var _a2, _b2, _c2, _d2, _e2;
3363
3365
  switch (item.type) {
3364
3366
  case "text": {
3365
3367
  return { type: "input_text", text: item.text };
@@ -3367,19 +3369,21 @@ async function convertToOpenAIResponsesInput({
3367
3369
  case "image-data": {
3368
3370
  return {
3369
3371
  type: "input_image",
3370
- image_url: `data:${item.mediaType};base64,${item.data}`
3372
+ image_url: `data:${item.mediaType};base64,${item.data}`,
3373
+ detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail
3371
3374
  };
3372
3375
  }
3373
3376
  case "image-url": {
3374
3377
  return {
3375
3378
  type: "input_image",
3376
- image_url: item.url
3379
+ image_url: item.url,
3380
+ detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail
3377
3381
  };
3378
3382
  }
3379
3383
  case "file-data": {
3380
3384
  return {
3381
3385
  type: "input_file",
3382
- filename: (_a2 = item.filename) != null ? _a2 : "data",
3386
+ filename: (_e2 = item.filename) != null ? _e2 : "data",
3383
3387
  file_data: `data:${item.mediaType};base64,${item.data}`
3384
3388
  };
3385
3389
  }
@@ -4523,7 +4527,21 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema21(
4523
4527
  * When enabled, the SDK applies reasoning-model parameter compatibility rules
4524
4528
  * and defaults `systemMessageMode` to `developer` unless overridden.
4525
4529
  */
4526
- 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()
4527
4545
  })
4528
4546
  )
4529
4547
  );
@@ -4536,10 +4554,11 @@ import { validateTypes as validateTypes2 } from "@ai-sdk/provider-utils";
4536
4554
  async function prepareResponsesTools({
4537
4555
  tools,
4538
4556
  toolChoice,
4557
+ allowedTools,
4539
4558
  toolNameMapping,
4540
4559
  customProviderToolNames
4541
4560
  }) {
4542
- var _a, _b;
4561
+ var _a, _b, _c;
4543
4562
  tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
4544
4563
  const toolWarnings = [];
4545
4564
  if (tools == null) {
@@ -4730,6 +4749,23 @@ async function prepareResponsesTools({
4730
4749
  break;
4731
4750
  }
4732
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
+ }
4733
4769
  if (toolChoice == null) {
4734
4770
  return { tools: openaiTools2, toolChoice: void 0, toolWarnings };
4735
4771
  }
@@ -4740,7 +4776,7 @@ async function prepareResponsesTools({
4740
4776
  case "required":
4741
4777
  return { tools: openaiTools2, toolChoice: type, toolWarnings };
4742
4778
  case "tool": {
4743
- 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;
4744
4780
  return {
4745
4781
  tools: openaiTools2,
4746
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 },
@@ -4846,7 +4882,7 @@ var OpenAIResponsesLanguageModel = class {
4846
4882
  toolChoice,
4847
4883
  responseFormat
4848
4884
  }) {
4849
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4885
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
4850
4886
  const warnings = [];
4851
4887
  const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
4852
4888
  if (topK != null) {
@@ -4909,16 +4945,17 @@ var OpenAIResponsesLanguageModel = class {
4909
4945
  } = await prepareResponsesTools({
4910
4946
  tools,
4911
4947
  toolChoice,
4948
+ allowedTools: (_b = openaiOptions == null ? void 0 : openaiOptions.allowedTools) != null ? _b : void 0,
4912
4949
  toolNameMapping,
4913
4950
  customProviderToolNames
4914
4951
  });
4915
4952
  const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
4916
4953
  prompt,
4917
4954
  toolNameMapping,
4918
- 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,
4919
4956
  providerOptionsName,
4920
4957
  fileIdPrefixes: this.config.fileIdPrefixes,
4921
- store: (_c = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _c : true,
4958
+ store: (_d = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _d : true,
4922
4959
  hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
4923
4960
  hasLocalShellTool: hasOpenAITool("openai.local_shell"),
4924
4961
  hasShellTool: hasOpenAITool("openai.shell"),
@@ -4926,7 +4963,7 @@ var OpenAIResponsesLanguageModel = class {
4926
4963
  customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
4927
4964
  });
4928
4965
  warnings.push(...inputWarnings);
4929
- 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;
4930
4967
  let include = openaiOptions == null ? void 0 : openaiOptions.include;
4931
4968
  function addInclude(key) {
4932
4969
  if (include == null) {
@@ -4942,9 +4979,9 @@ var OpenAIResponsesLanguageModel = class {
4942
4979
  if (topLogprobs) {
4943
4980
  addInclude("message.output_text.logprobs");
4944
4981
  }
4945
- const webSearchToolName = (_e = tools == null ? void 0 : tools.find(
4982
+ const webSearchToolName = (_f = tools == null ? void 0 : tools.find(
4946
4983
  (tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
4947
- )) == null ? void 0 : _e.name;
4984
+ )) == null ? void 0 : _f.name;
4948
4985
  if (webSearchToolName) {
4949
4986
  addInclude("web_search_call.action.sources");
4950
4987
  }
@@ -4967,7 +5004,7 @@ var OpenAIResponsesLanguageModel = class {
4967
5004
  format: responseFormat.schema != null ? {
4968
5005
  type: "json_schema",
4969
5006
  strict: strictJsonSchema,
4970
- name: (_f = responseFormat.name) != null ? _f : "response",
5007
+ name: (_g = responseFormat.name) != null ? _g : "response",
4971
5008
  description: responseFormat.description,
4972
5009
  schema: responseFormat.schema
4973
5010
  } : { type: "json_object" }
@@ -5056,9 +5093,9 @@ var OpenAIResponsesLanguageModel = class {
5056
5093
  });
5057
5094
  delete baseArgs.service_tier;
5058
5095
  }
5059
- const shellToolEnvType = (_i = (_h = (_g = tools == null ? void 0 : tools.find(
5096
+ const shellToolEnvType = (_j = (_i = (_h = tools == null ? void 0 : tools.find(
5060
5097
  (tool) => tool.type === "provider" && tool.id === "openai.shell"
5061
- )) == 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;
5062
5099
  const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
5063
5100
  return {
5064
5101
  webSearchToolName,
@@ -6875,7 +6912,7 @@ var OpenAITranscriptionModel = class {
6875
6912
  };
6876
6913
 
6877
6914
  // src/version.ts
6878
- var VERSION = true ? "3.0.60" : "0.0.0-test";
6915
+ var VERSION = true ? "3.0.62" : "0.0.0-test";
6879
6916
 
6880
6917
  // src/openai-provider.ts
6881
6918
  function createOpenAI(options = {}) {