@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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +58 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -21
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +57 -20
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +57 -20
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/responses/convert-to-openai-responses-input.ts +12 -0
- package/src/responses/openai-responses-language-model.ts +1 -0
- package/src/responses/openai-responses-options.ts +17 -0
- package/src/responses/openai-responses-prepare-tools.ts +26 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 3.0.62
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 65edcca: feat: add allowedTools provider option for OpenAI Responses
|
|
8
|
+
|
|
9
|
+
## 3.0.61
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- b93f9b4: feat(provider/openai): forward imageDetail providerOptions on tool-result image content
|
|
14
|
+
|
|
3
15
|
## 3.0.60
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1058,6 +1058,10 @@ declare const openaiLanguageModelResponsesOptionsSchema: _ai_sdk_provider_utils.
|
|
|
1058
1058
|
user?: string | null | undefined;
|
|
1059
1059
|
systemMessageMode?: "remove" | "system" | "developer" | undefined;
|
|
1060
1060
|
forceReasoning?: boolean | undefined;
|
|
1061
|
+
allowedTools?: {
|
|
1062
|
+
toolNames: string[];
|
|
1063
|
+
mode?: "auto" | "required" | undefined;
|
|
1064
|
+
} | undefined;
|
|
1061
1065
|
}>;
|
|
1062
1066
|
type OpenAILanguageModelResponsesOptions = InferSchema<typeof openaiLanguageModelResponsesOptionsSchema>;
|
|
1063
1067
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1058,6 +1058,10 @@ declare const openaiLanguageModelResponsesOptionsSchema: _ai_sdk_provider_utils.
|
|
|
1058
1058
|
user?: string | null | undefined;
|
|
1059
1059
|
systemMessageMode?: "remove" | "system" | "developer" | undefined;
|
|
1060
1060
|
forceReasoning?: boolean | undefined;
|
|
1061
|
+
allowedTools?: {
|
|
1062
|
+
toolNames: string[];
|
|
1063
|
+
mode?: "auto" | "required" | undefined;
|
|
1064
|
+
} | undefined;
|
|
1061
1065
|
}>;
|
|
1062
1066
|
type OpenAILanguageModelResponsesOptions = InferSchema<typeof openaiLanguageModelResponsesOptionsSchema>;
|
|
1063
1067
|
|
package/dist/index.js
CHANGED
|
@@ -3204,24 +3204,26 @@ async function convertToOpenAIResponsesInput({
|
|
|
3204
3204
|
break;
|
|
3205
3205
|
case "content":
|
|
3206
3206
|
outputValue = output.value.map((item) => {
|
|
3207
|
-
var _a2;
|
|
3207
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
3208
3208
|
switch (item.type) {
|
|
3209
3209
|
case "text":
|
|
3210
3210
|
return { type: "input_text", text: item.text };
|
|
3211
3211
|
case "image-data":
|
|
3212
3212
|
return {
|
|
3213
3213
|
type: "input_image",
|
|
3214
|
-
image_url: `data:${item.mediaType};base64,${item.data}
|
|
3214
|
+
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3215
|
+
detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail
|
|
3215
3216
|
};
|
|
3216
3217
|
case "image-url":
|
|
3217
3218
|
return {
|
|
3218
3219
|
type: "input_image",
|
|
3219
|
-
image_url: item.url
|
|
3220
|
+
image_url: item.url,
|
|
3221
|
+
detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail
|
|
3220
3222
|
};
|
|
3221
3223
|
case "file-data":
|
|
3222
3224
|
return {
|
|
3223
3225
|
type: "input_file",
|
|
3224
|
-
filename: (
|
|
3226
|
+
filename: (_e2 = item.filename) != null ? _e2 : "data",
|
|
3225
3227
|
file_data: `data:${item.mediaType};base64,${item.data}`
|
|
3226
3228
|
};
|
|
3227
3229
|
case "file-url":
|
|
@@ -3263,7 +3265,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3263
3265
|
break;
|
|
3264
3266
|
case "content":
|
|
3265
3267
|
contentValue = output.value.map((item) => {
|
|
3266
|
-
var _a2;
|
|
3268
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
3267
3269
|
switch (item.type) {
|
|
3268
3270
|
case "text": {
|
|
3269
3271
|
return { type: "input_text", text: item.text };
|
|
@@ -3271,19 +3273,21 @@ async function convertToOpenAIResponsesInput({
|
|
|
3271
3273
|
case "image-data": {
|
|
3272
3274
|
return {
|
|
3273
3275
|
type: "input_image",
|
|
3274
|
-
image_url: `data:${item.mediaType};base64,${item.data}
|
|
3276
|
+
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3277
|
+
detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail
|
|
3275
3278
|
};
|
|
3276
3279
|
}
|
|
3277
3280
|
case "image-url": {
|
|
3278
3281
|
return {
|
|
3279
3282
|
type: "input_image",
|
|
3280
|
-
image_url: item.url
|
|
3283
|
+
image_url: item.url,
|
|
3284
|
+
detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail
|
|
3281
3285
|
};
|
|
3282
3286
|
}
|
|
3283
3287
|
case "file-data": {
|
|
3284
3288
|
return {
|
|
3285
3289
|
type: "input_file",
|
|
3286
|
-
filename: (
|
|
3290
|
+
filename: (_e2 = item.filename) != null ? _e2 : "data",
|
|
3287
3291
|
file_data: `data:${item.mediaType};base64,${item.data}`
|
|
3288
3292
|
};
|
|
3289
3293
|
}
|
|
@@ -4421,7 +4425,21 @@ var openaiLanguageModelResponsesOptionsSchema = (0, import_provider_utils28.lazy
|
|
|
4421
4425
|
* When enabled, the SDK applies reasoning-model parameter compatibility rules
|
|
4422
4426
|
* and defaults `systemMessageMode` to `developer` unless overridden.
|
|
4423
4427
|
*/
|
|
4424
|
-
forceReasoning: import_v423.z.boolean().optional()
|
|
4428
|
+
forceReasoning: import_v423.z.boolean().optional(),
|
|
4429
|
+
/**
|
|
4430
|
+
* Restrict the callable tools to a subset while keeping the full tools
|
|
4431
|
+
* list intact, so prompt caching is preserved across requests with
|
|
4432
|
+
* different allowlists.
|
|
4433
|
+
*
|
|
4434
|
+
* When set, this overrides the request-level `toolChoice` and emits
|
|
4435
|
+
* `tool_choice: { type: "allowed_tools", mode, tools }` on the wire.
|
|
4436
|
+
*
|
|
4437
|
+
* @see https://developers.openai.com/api/reference/resources/responses/methods/create#(resource)%20responses%20%3E%20(model)%20tool_choice_allowed%20%3E%20(schema)
|
|
4438
|
+
*/
|
|
4439
|
+
allowedTools: import_v423.z.object({
|
|
4440
|
+
toolNames: import_v423.z.array(import_v423.z.string()).min(1),
|
|
4441
|
+
mode: import_v423.z.enum(["auto", "required"]).optional()
|
|
4442
|
+
}).optional()
|
|
4425
4443
|
})
|
|
4426
4444
|
)
|
|
4427
4445
|
);
|
|
@@ -4432,10 +4450,11 @@ var import_provider_utils29 = require("@ai-sdk/provider-utils");
|
|
|
4432
4450
|
async function prepareResponsesTools({
|
|
4433
4451
|
tools,
|
|
4434
4452
|
toolChoice,
|
|
4453
|
+
allowedTools,
|
|
4435
4454
|
toolNameMapping,
|
|
4436
4455
|
customProviderToolNames
|
|
4437
4456
|
}) {
|
|
4438
|
-
var _a, _b;
|
|
4457
|
+
var _a, _b, _c;
|
|
4439
4458
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
4440
4459
|
const toolWarnings = [];
|
|
4441
4460
|
if (tools == null) {
|
|
@@ -4626,6 +4645,23 @@ async function prepareResponsesTools({
|
|
|
4626
4645
|
break;
|
|
4627
4646
|
}
|
|
4628
4647
|
}
|
|
4648
|
+
if (allowedTools != null) {
|
|
4649
|
+
return {
|
|
4650
|
+
tools: openaiTools2,
|
|
4651
|
+
toolChoice: {
|
|
4652
|
+
type: "allowed_tools",
|
|
4653
|
+
mode: (_b = allowedTools.mode) != null ? _b : "auto",
|
|
4654
|
+
tools: allowedTools.toolNames.map((name) => {
|
|
4655
|
+
var _a2;
|
|
4656
|
+
return {
|
|
4657
|
+
type: "function",
|
|
4658
|
+
name: (_a2 = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(name)) != null ? _a2 : name
|
|
4659
|
+
};
|
|
4660
|
+
})
|
|
4661
|
+
},
|
|
4662
|
+
toolWarnings
|
|
4663
|
+
};
|
|
4664
|
+
}
|
|
4629
4665
|
if (toolChoice == null) {
|
|
4630
4666
|
return { tools: openaiTools2, toolChoice: void 0, toolWarnings };
|
|
4631
4667
|
}
|
|
@@ -4636,7 +4672,7 @@ async function prepareResponsesTools({
|
|
|
4636
4672
|
case "required":
|
|
4637
4673
|
return { tools: openaiTools2, toolChoice: type, toolWarnings };
|
|
4638
4674
|
case "tool": {
|
|
4639
|
-
const resolvedToolName = (
|
|
4675
|
+
const resolvedToolName = (_c = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _c : toolChoice.toolName;
|
|
4640
4676
|
return {
|
|
4641
4677
|
tools: openaiTools2,
|
|
4642
4678
|
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 },
|
|
@@ -4742,7 +4778,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4742
4778
|
toolChoice,
|
|
4743
4779
|
responseFormat
|
|
4744
4780
|
}) {
|
|
4745
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
4781
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
4746
4782
|
const warnings = [];
|
|
4747
4783
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
4748
4784
|
if (topK != null) {
|
|
@@ -4805,16 +4841,17 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4805
4841
|
} = await prepareResponsesTools({
|
|
4806
4842
|
tools,
|
|
4807
4843
|
toolChoice,
|
|
4844
|
+
allowedTools: (_b = openaiOptions == null ? void 0 : openaiOptions.allowedTools) != null ? _b : void 0,
|
|
4808
4845
|
toolNameMapping,
|
|
4809
4846
|
customProviderToolNames
|
|
4810
4847
|
});
|
|
4811
4848
|
const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
|
|
4812
4849
|
prompt,
|
|
4813
4850
|
toolNameMapping,
|
|
4814
|
-
systemMessageMode: (
|
|
4851
|
+
systemMessageMode: (_c = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _c : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
|
|
4815
4852
|
providerOptionsName,
|
|
4816
4853
|
fileIdPrefixes: this.config.fileIdPrefixes,
|
|
4817
|
-
store: (
|
|
4854
|
+
store: (_d = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _d : true,
|
|
4818
4855
|
hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
|
|
4819
4856
|
hasLocalShellTool: hasOpenAITool("openai.local_shell"),
|
|
4820
4857
|
hasShellTool: hasOpenAITool("openai.shell"),
|
|
@@ -4822,7 +4859,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4822
4859
|
customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
|
|
4823
4860
|
});
|
|
4824
4861
|
warnings.push(...inputWarnings);
|
|
4825
|
-
const strictJsonSchema = (
|
|
4862
|
+
const strictJsonSchema = (_e = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _e : true;
|
|
4826
4863
|
let include = openaiOptions == null ? void 0 : openaiOptions.include;
|
|
4827
4864
|
function addInclude(key) {
|
|
4828
4865
|
if (include == null) {
|
|
@@ -4838,9 +4875,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4838
4875
|
if (topLogprobs) {
|
|
4839
4876
|
addInclude("message.output_text.logprobs");
|
|
4840
4877
|
}
|
|
4841
|
-
const webSearchToolName = (
|
|
4878
|
+
const webSearchToolName = (_f = tools == null ? void 0 : tools.find(
|
|
4842
4879
|
(tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
|
|
4843
|
-
)) == null ? void 0 :
|
|
4880
|
+
)) == null ? void 0 : _f.name;
|
|
4844
4881
|
if (webSearchToolName) {
|
|
4845
4882
|
addInclude("web_search_call.action.sources");
|
|
4846
4883
|
}
|
|
@@ -4863,7 +4900,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4863
4900
|
format: responseFormat.schema != null ? {
|
|
4864
4901
|
type: "json_schema",
|
|
4865
4902
|
strict: strictJsonSchema,
|
|
4866
|
-
name: (
|
|
4903
|
+
name: (_g = responseFormat.name) != null ? _g : "response",
|
|
4867
4904
|
description: responseFormat.description,
|
|
4868
4905
|
schema: responseFormat.schema
|
|
4869
4906
|
} : { type: "json_object" }
|
|
@@ -4952,9 +4989,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4952
4989
|
});
|
|
4953
4990
|
delete baseArgs.service_tier;
|
|
4954
4991
|
}
|
|
4955
|
-
const shellToolEnvType = (
|
|
4992
|
+
const shellToolEnvType = (_j = (_i = (_h = tools == null ? void 0 : tools.find(
|
|
4956
4993
|
(tool) => tool.type === "provider" && tool.id === "openai.shell"
|
|
4957
|
-
)) == null ? void 0 :
|
|
4994
|
+
)) == null ? void 0 : _h.args) == null ? void 0 : _i.environment) == null ? void 0 : _j.type;
|
|
4958
4995
|
const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
|
|
4959
4996
|
return {
|
|
4960
4997
|
webSearchToolName,
|
|
@@ -6753,7 +6790,7 @@ var OpenAITranscriptionModel = class {
|
|
|
6753
6790
|
};
|
|
6754
6791
|
|
|
6755
6792
|
// src/version.ts
|
|
6756
|
-
var VERSION = true ? "3.0.
|
|
6793
|
+
var VERSION = true ? "3.0.62" : "0.0.0-test";
|
|
6757
6794
|
|
|
6758
6795
|
// src/openai-provider.ts
|
|
6759
6796
|
function createOpenAI(options = {}) {
|