@ai-sdk/openai 3.0.36 → 3.0.38
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 +14 -0
- package/README.md +1 -1
- package/dist/index.d.mts +53 -3
- package/dist/index.d.ts +53 -3
- package/dist/index.js +1168 -966
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1118 -912
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +20 -2
- package/dist/internal/index.d.ts +20 -2
- package/dist/internal/index.js +349 -158
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +327 -132
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-openai.mdx +79 -1
- package/package.json +2 -2
- package/src/chat/openai-chat-options.ts +0 -5
- package/src/openai-language-model-capabilities.ts +0 -2
- package/src/openai-tools.ts +13 -1
- package/src/responses/convert-to-openai-responses-input.ts +74 -0
- package/src/responses/openai-responses-api.ts +58 -0
- package/src/responses/openai-responses-language-model.ts +94 -9
- package/src/responses/openai-responses-options.ts +0 -22
- package/src/responses/openai-responses-prepare-tools.ts +41 -11
- package/src/tool/custom.ts +64 -0
package/dist/internal/index.mjs
CHANGED
|
@@ -35,7 +35,7 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
35
35
|
function getOpenAILanguageModelCapabilities(modelId) {
|
|
36
36
|
const supportsFlexProcessing = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
37
37
|
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
38
|
-
const isReasoningModel = modelId.startsWith("o1") || modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("
|
|
38
|
+
const isReasoningModel = modelId.startsWith("o1") || modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
39
39
|
const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1") || modelId.startsWith("gpt-5.2");
|
|
40
40
|
const systemMessageMode = isReasoningModel ? "developer" : "system";
|
|
41
41
|
return {
|
|
@@ -2585,9 +2585,10 @@ async function convertToOpenAIResponsesInput({
|
|
|
2585
2585
|
hasConversation = false,
|
|
2586
2586
|
hasLocalShellTool = false,
|
|
2587
2587
|
hasShellTool = false,
|
|
2588
|
-
hasApplyPatchTool = false
|
|
2588
|
+
hasApplyPatchTool = false,
|
|
2589
|
+
customProviderToolNames
|
|
2589
2590
|
}) {
|
|
2590
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
2591
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2591
2592
|
const input = [];
|
|
2592
2593
|
const warnings = [];
|
|
2593
2594
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
@@ -2756,6 +2757,16 @@ async function convertToOpenAIResponsesInput({
|
|
|
2756
2757
|
});
|
|
2757
2758
|
break;
|
|
2758
2759
|
}
|
|
2760
|
+
if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
|
|
2761
|
+
input.push({
|
|
2762
|
+
type: "custom_tool_call",
|
|
2763
|
+
call_id: part.toolCallId,
|
|
2764
|
+
name: resolvedToolName,
|
|
2765
|
+
input: typeof part.input === "string" ? part.input : JSON.stringify(part.input),
|
|
2766
|
+
id
|
|
2767
|
+
});
|
|
2768
|
+
break;
|
|
2769
|
+
}
|
|
2759
2770
|
input.push({
|
|
2760
2771
|
type: "function_call",
|
|
2761
2772
|
call_id: part.toolCallId,
|
|
@@ -2960,6 +2971,61 @@ async function convertToOpenAIResponsesInput({
|
|
|
2960
2971
|
});
|
|
2961
2972
|
continue;
|
|
2962
2973
|
}
|
|
2974
|
+
if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
|
|
2975
|
+
let outputValue;
|
|
2976
|
+
switch (output.type) {
|
|
2977
|
+
case "text":
|
|
2978
|
+
case "error-text":
|
|
2979
|
+
outputValue = output.value;
|
|
2980
|
+
break;
|
|
2981
|
+
case "execution-denied":
|
|
2982
|
+
outputValue = (_l = output.reason) != null ? _l : "Tool execution denied.";
|
|
2983
|
+
break;
|
|
2984
|
+
case "json":
|
|
2985
|
+
case "error-json":
|
|
2986
|
+
outputValue = JSON.stringify(output.value);
|
|
2987
|
+
break;
|
|
2988
|
+
case "content":
|
|
2989
|
+
outputValue = output.value.map((item) => {
|
|
2990
|
+
var _a2;
|
|
2991
|
+
switch (item.type) {
|
|
2992
|
+
case "text":
|
|
2993
|
+
return { type: "input_text", text: item.text };
|
|
2994
|
+
case "image-data":
|
|
2995
|
+
return {
|
|
2996
|
+
type: "input_image",
|
|
2997
|
+
image_url: `data:${item.mediaType};base64,${item.data}`
|
|
2998
|
+
};
|
|
2999
|
+
case "image-url":
|
|
3000
|
+
return {
|
|
3001
|
+
type: "input_image",
|
|
3002
|
+
image_url: item.url
|
|
3003
|
+
};
|
|
3004
|
+
case "file-data":
|
|
3005
|
+
return {
|
|
3006
|
+
type: "input_file",
|
|
3007
|
+
filename: (_a2 = item.filename) != null ? _a2 : "data",
|
|
3008
|
+
file_data: `data:${item.mediaType};base64,${item.data}`
|
|
3009
|
+
};
|
|
3010
|
+
default:
|
|
3011
|
+
warnings.push({
|
|
3012
|
+
type: "other",
|
|
3013
|
+
message: `unsupported custom tool content part type: ${item.type}`
|
|
3014
|
+
});
|
|
3015
|
+
return void 0;
|
|
3016
|
+
}
|
|
3017
|
+
}).filter(isNonNullable);
|
|
3018
|
+
break;
|
|
3019
|
+
default:
|
|
3020
|
+
outputValue = "";
|
|
3021
|
+
}
|
|
3022
|
+
input.push({
|
|
3023
|
+
type: "custom_tool_call_output",
|
|
3024
|
+
call_id: part.toolCallId,
|
|
3025
|
+
output: outputValue
|
|
3026
|
+
});
|
|
3027
|
+
continue;
|
|
3028
|
+
}
|
|
2963
3029
|
let contentValue;
|
|
2964
3030
|
switch (output.type) {
|
|
2965
3031
|
case "text":
|
|
@@ -2967,7 +3033,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2967
3033
|
contentValue = output.value;
|
|
2968
3034
|
break;
|
|
2969
3035
|
case "execution-denied":
|
|
2970
|
-
contentValue = (
|
|
3036
|
+
contentValue = (_m = output.reason) != null ? _m : "Tool execution denied.";
|
|
2971
3037
|
break;
|
|
2972
3038
|
case "json":
|
|
2973
3039
|
case "error-json":
|
|
@@ -3182,6 +3248,13 @@ var openaiResponsesChunkSchema = lazySchema14(
|
|
|
3182
3248
|
})
|
|
3183
3249
|
])
|
|
3184
3250
|
}),
|
|
3251
|
+
z16.object({
|
|
3252
|
+
type: z16.literal("custom_tool_call"),
|
|
3253
|
+
id: z16.string(),
|
|
3254
|
+
call_id: z16.string(),
|
|
3255
|
+
name: z16.string(),
|
|
3256
|
+
input: z16.string()
|
|
3257
|
+
}),
|
|
3185
3258
|
z16.object({
|
|
3186
3259
|
type: z16.literal("shell_call"),
|
|
3187
3260
|
id: z16.string(),
|
|
@@ -3234,6 +3307,14 @@ var openaiResponsesChunkSchema = lazySchema14(
|
|
|
3234
3307
|
arguments: z16.string(),
|
|
3235
3308
|
status: z16.literal("completed")
|
|
3236
3309
|
}),
|
|
3310
|
+
z16.object({
|
|
3311
|
+
type: z16.literal("custom_tool_call"),
|
|
3312
|
+
id: z16.string(),
|
|
3313
|
+
call_id: z16.string(),
|
|
3314
|
+
name: z16.string(),
|
|
3315
|
+
input: z16.string(),
|
|
3316
|
+
status: z16.literal("completed")
|
|
3317
|
+
}),
|
|
3237
3318
|
z16.object({
|
|
3238
3319
|
type: z16.literal("code_interpreter_call"),
|
|
3239
3320
|
id: z16.string(),
|
|
@@ -3417,6 +3498,12 @@ var openaiResponsesChunkSchema = lazySchema14(
|
|
|
3417
3498
|
output_index: z16.number(),
|
|
3418
3499
|
delta: z16.string()
|
|
3419
3500
|
}),
|
|
3501
|
+
z16.object({
|
|
3502
|
+
type: z16.literal("response.custom_tool_call_input.delta"),
|
|
3503
|
+
item_id: z16.string(),
|
|
3504
|
+
output_index: z16.number(),
|
|
3505
|
+
delta: z16.string()
|
|
3506
|
+
}),
|
|
3420
3507
|
z16.object({
|
|
3421
3508
|
type: z16.literal("response.image_generation_call.partial_image"),
|
|
3422
3509
|
item_id: z16.string(),
|
|
@@ -3664,6 +3751,13 @@ var openaiResponsesResponseSchema = lazySchema14(
|
|
|
3664
3751
|
arguments: z16.string(),
|
|
3665
3752
|
id: z16.string()
|
|
3666
3753
|
}),
|
|
3754
|
+
z16.object({
|
|
3755
|
+
type: z16.literal("custom_tool_call"),
|
|
3756
|
+
call_id: z16.string(),
|
|
3757
|
+
name: z16.string(),
|
|
3758
|
+
input: z16.string(),
|
|
3759
|
+
id: z16.string()
|
|
3760
|
+
}),
|
|
3667
3761
|
z16.object({
|
|
3668
3762
|
type: z16.literal("computer_call"),
|
|
3669
3763
|
id: z16.string(),
|
|
@@ -3800,16 +3894,10 @@ var openaiResponsesReasoningModelIds = [
|
|
|
3800
3894
|
"o1-2024-12-17",
|
|
3801
3895
|
"o3",
|
|
3802
3896
|
"o3-2025-04-16",
|
|
3803
|
-
"o3-deep-research",
|
|
3804
|
-
"o3-deep-research-2025-06-26",
|
|
3805
3897
|
"o3-mini",
|
|
3806
3898
|
"o3-mini-2025-01-31",
|
|
3807
3899
|
"o4-mini",
|
|
3808
3900
|
"o4-mini-2025-04-16",
|
|
3809
|
-
"o4-mini-deep-research",
|
|
3810
|
-
"o4-mini-deep-research-2025-06-26",
|
|
3811
|
-
"codex-mini-latest",
|
|
3812
|
-
"computer-use-preview",
|
|
3813
3901
|
"gpt-5",
|
|
3814
3902
|
"gpt-5-2025-08-07",
|
|
3815
3903
|
"gpt-5-codex",
|
|
@@ -3842,7 +3930,6 @@ var openaiResponsesModelIds = [
|
|
|
3842
3930
|
"gpt-4o-2024-08-06",
|
|
3843
3931
|
"gpt-4o-2024-11-20",
|
|
3844
3932
|
"gpt-4o-audio-preview",
|
|
3845
|
-
"gpt-4o-audio-preview-2024-10-01",
|
|
3846
3933
|
"gpt-4o-audio-preview-2024-12-17",
|
|
3847
3934
|
"gpt-4o-search-preview",
|
|
3848
3935
|
"gpt-4o-search-preview-2025-03-11",
|
|
@@ -3850,19 +3937,9 @@ var openaiResponsesModelIds = [
|
|
|
3850
3937
|
"gpt-4o-mini-search-preview-2025-03-11",
|
|
3851
3938
|
"gpt-4o-mini",
|
|
3852
3939
|
"gpt-4o-mini-2024-07-18",
|
|
3853
|
-
"gpt-4-turbo",
|
|
3854
|
-
"gpt-4-turbo-2024-04-09",
|
|
3855
|
-
"gpt-4-turbo-preview",
|
|
3856
|
-
"gpt-4-0125-preview",
|
|
3857
|
-
"gpt-4-1106-preview",
|
|
3858
|
-
"gpt-4",
|
|
3859
|
-
"gpt-4-0613",
|
|
3860
|
-
"gpt-4.5-preview",
|
|
3861
|
-
"gpt-4.5-preview-2025-02-27",
|
|
3862
3940
|
"gpt-3.5-turbo-0125",
|
|
3863
3941
|
"gpt-3.5-turbo",
|
|
3864
3942
|
"gpt-3.5-turbo-1106",
|
|
3865
|
-
"chatgpt-4o-latest",
|
|
3866
3943
|
"gpt-5-chat-latest",
|
|
3867
3944
|
...openaiResponsesReasoningModelIds
|
|
3868
3945
|
];
|
|
@@ -4167,139 +4244,115 @@ var imageGeneration = (args = {}) => {
|
|
|
4167
4244
|
return imageGenerationToolFactory(args);
|
|
4168
4245
|
};
|
|
4169
4246
|
|
|
4170
|
-
// src/tool/
|
|
4247
|
+
// src/tool/custom.ts
|
|
4171
4248
|
import {
|
|
4172
|
-
|
|
4249
|
+
createProviderToolFactory,
|
|
4173
4250
|
lazySchema as lazySchema19,
|
|
4174
4251
|
zodSchema as zodSchema19
|
|
4175
4252
|
} from "@ai-sdk/provider-utils";
|
|
4176
4253
|
import { z as z21 } from "zod/v4";
|
|
4177
|
-
var
|
|
4178
|
-
() => z21.union([
|
|
4179
|
-
z21.string(),
|
|
4180
|
-
z21.number(),
|
|
4181
|
-
z21.boolean(),
|
|
4182
|
-
z21.null(),
|
|
4183
|
-
z21.array(jsonValueSchema),
|
|
4184
|
-
z21.record(z21.string(), jsonValueSchema)
|
|
4185
|
-
])
|
|
4186
|
-
);
|
|
4187
|
-
var mcpArgsSchema = lazySchema19(
|
|
4254
|
+
var customArgsSchema = lazySchema19(
|
|
4188
4255
|
() => zodSchema19(
|
|
4189
4256
|
z21.object({
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4257
|
+
name: z21.string(),
|
|
4258
|
+
description: z21.string().optional(),
|
|
4259
|
+
format: z21.union([
|
|
4193
4260
|
z21.object({
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
authorization: z21.string().optional(),
|
|
4199
|
-
connectorId: z21.string().optional(),
|
|
4200
|
-
headers: z21.record(z21.string(), z21.string()).optional(),
|
|
4201
|
-
requireApproval: z21.union([
|
|
4202
|
-
z21.enum(["always", "never"]),
|
|
4261
|
+
type: z21.literal("grammar"),
|
|
4262
|
+
syntax: z21.enum(["regex", "lark"]),
|
|
4263
|
+
definition: z21.string()
|
|
4264
|
+
}),
|
|
4203
4265
|
z21.object({
|
|
4204
|
-
|
|
4205
|
-
toolNames: z21.array(z21.string()).optional()
|
|
4206
|
-
}).optional()
|
|
4266
|
+
type: z21.literal("text")
|
|
4207
4267
|
})
|
|
4208
|
-
]).optional()
|
|
4209
|
-
serverDescription: z21.string().optional(),
|
|
4210
|
-
serverUrl: z21.string().optional()
|
|
4211
|
-
}).refine(
|
|
4212
|
-
(v) => v.serverUrl != null || v.connectorId != null,
|
|
4213
|
-
"One of serverUrl or connectorId must be provided."
|
|
4214
|
-
)
|
|
4215
|
-
)
|
|
4216
|
-
);
|
|
4217
|
-
var mcpInputSchema = lazySchema19(() => zodSchema19(z21.object({})));
|
|
4218
|
-
var mcpOutputSchema = lazySchema19(
|
|
4219
|
-
() => zodSchema19(
|
|
4220
|
-
z21.object({
|
|
4221
|
-
type: z21.literal("call"),
|
|
4222
|
-
serverLabel: z21.string(),
|
|
4223
|
-
name: z21.string(),
|
|
4224
|
-
arguments: z21.string(),
|
|
4225
|
-
output: z21.string().nullish(),
|
|
4226
|
-
error: z21.union([z21.string(), jsonValueSchema]).optional()
|
|
4268
|
+
]).optional()
|
|
4227
4269
|
})
|
|
4228
4270
|
)
|
|
4229
4271
|
);
|
|
4230
|
-
var
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4272
|
+
var customInputSchema = lazySchema19(() => zodSchema19(z21.string()));
|
|
4273
|
+
var customToolFactory = createProviderToolFactory({
|
|
4274
|
+
id: "openai.custom",
|
|
4275
|
+
inputSchema: customInputSchema
|
|
4234
4276
|
});
|
|
4235
4277
|
|
|
4236
|
-
// src/tool/
|
|
4278
|
+
// src/tool/mcp.ts
|
|
4237
4279
|
import {
|
|
4238
|
-
createProviderToolFactoryWithOutputSchema as
|
|
4280
|
+
createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema7,
|
|
4239
4281
|
lazySchema as lazySchema20,
|
|
4240
4282
|
zodSchema as zodSchema20
|
|
4241
4283
|
} from "@ai-sdk/provider-utils";
|
|
4242
4284
|
import { z as z22 } from "zod/v4";
|
|
4243
|
-
var
|
|
4244
|
-
() =>
|
|
4245
|
-
z22.
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
city: z22.string().optional(),
|
|
4253
|
-
region: z22.string().optional(),
|
|
4254
|
-
timezone: z22.string().optional()
|
|
4255
|
-
}).optional()
|
|
4256
|
-
})
|
|
4257
|
-
)
|
|
4285
|
+
var jsonValueSchema = z22.lazy(
|
|
4286
|
+
() => z22.union([
|
|
4287
|
+
z22.string(),
|
|
4288
|
+
z22.number(),
|
|
4289
|
+
z22.boolean(),
|
|
4290
|
+
z22.null(),
|
|
4291
|
+
z22.array(jsonValueSchema),
|
|
4292
|
+
z22.record(z22.string(), jsonValueSchema)
|
|
4293
|
+
])
|
|
4258
4294
|
);
|
|
4259
|
-
var
|
|
4260
|
-
var webSearchOutputSchema = lazySchema20(
|
|
4295
|
+
var mcpArgsSchema = lazySchema20(
|
|
4261
4296
|
() => zodSchema20(
|
|
4262
4297
|
z22.object({
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
query: z22.string().optional()
|
|
4267
|
-
}),
|
|
4298
|
+
serverLabel: z22.string(),
|
|
4299
|
+
allowedTools: z22.union([
|
|
4300
|
+
z22.array(z22.string()),
|
|
4268
4301
|
z22.object({
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
})
|
|
4302
|
+
readOnly: z22.boolean().optional(),
|
|
4303
|
+
toolNames: z22.array(z22.string()).optional()
|
|
4304
|
+
})
|
|
4305
|
+
]).optional(),
|
|
4306
|
+
authorization: z22.string().optional(),
|
|
4307
|
+
connectorId: z22.string().optional(),
|
|
4308
|
+
headers: z22.record(z22.string(), z22.string()).optional(),
|
|
4309
|
+
requireApproval: z22.union([
|
|
4310
|
+
z22.enum(["always", "never"]),
|
|
4272
4311
|
z22.object({
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4312
|
+
never: z22.object({
|
|
4313
|
+
toolNames: z22.array(z22.string()).optional()
|
|
4314
|
+
}).optional()
|
|
4276
4315
|
})
|
|
4277
4316
|
]).optional(),
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4317
|
+
serverDescription: z22.string().optional(),
|
|
4318
|
+
serverUrl: z22.string().optional()
|
|
4319
|
+
}).refine(
|
|
4320
|
+
(v) => v.serverUrl != null || v.connectorId != null,
|
|
4321
|
+
"One of serverUrl or connectorId must be provided."
|
|
4322
|
+
)
|
|
4323
|
+
)
|
|
4324
|
+
);
|
|
4325
|
+
var mcpInputSchema = lazySchema20(() => zodSchema20(z22.object({})));
|
|
4326
|
+
var mcpOutputSchema = lazySchema20(
|
|
4327
|
+
() => zodSchema20(
|
|
4328
|
+
z22.object({
|
|
4329
|
+
type: z22.literal("call"),
|
|
4330
|
+
serverLabel: z22.string(),
|
|
4331
|
+
name: z22.string(),
|
|
4332
|
+
arguments: z22.string(),
|
|
4333
|
+
output: z22.string().nullish(),
|
|
4334
|
+
error: z22.union([z22.string(), jsonValueSchema]).optional()
|
|
4284
4335
|
})
|
|
4285
4336
|
)
|
|
4286
4337
|
);
|
|
4287
|
-
var
|
|
4288
|
-
id: "openai.
|
|
4289
|
-
inputSchema:
|
|
4290
|
-
outputSchema:
|
|
4338
|
+
var mcpToolFactory = createProviderToolFactoryWithOutputSchema7({
|
|
4339
|
+
id: "openai.mcp",
|
|
4340
|
+
inputSchema: mcpInputSchema,
|
|
4341
|
+
outputSchema: mcpOutputSchema
|
|
4291
4342
|
});
|
|
4292
4343
|
|
|
4293
|
-
// src/tool/web-search
|
|
4344
|
+
// src/tool/web-search.ts
|
|
4294
4345
|
import {
|
|
4295
|
-
createProviderToolFactoryWithOutputSchema as
|
|
4346
|
+
createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema8,
|
|
4296
4347
|
lazySchema as lazySchema21,
|
|
4297
4348
|
zodSchema as zodSchema21
|
|
4298
4349
|
} from "@ai-sdk/provider-utils";
|
|
4299
4350
|
import { z as z23 } from "zod/v4";
|
|
4300
|
-
var
|
|
4351
|
+
var webSearchArgsSchema = lazySchema21(
|
|
4301
4352
|
() => zodSchema21(
|
|
4302
4353
|
z23.object({
|
|
4354
|
+
externalWebAccess: z23.boolean().optional(),
|
|
4355
|
+
filters: z23.object({ allowedDomains: z23.array(z23.string()).optional() }).optional(),
|
|
4303
4356
|
searchContextSize: z23.enum(["low", "medium", "high"]).optional(),
|
|
4304
4357
|
userLocation: z23.object({
|
|
4305
4358
|
type: z23.literal("approximate"),
|
|
@@ -4311,10 +4364,8 @@ var webSearchPreviewArgsSchema = lazySchema21(
|
|
|
4311
4364
|
})
|
|
4312
4365
|
)
|
|
4313
4366
|
);
|
|
4314
|
-
var
|
|
4315
|
-
|
|
4316
|
-
);
|
|
4317
|
-
var webSearchPreviewOutputSchema = lazySchema21(
|
|
4367
|
+
var webSearchInputSchema = lazySchema21(() => zodSchema21(z23.object({})));
|
|
4368
|
+
var webSearchOutputSchema = lazySchema21(
|
|
4318
4369
|
() => zodSchema21(
|
|
4319
4370
|
z23.object({
|
|
4320
4371
|
action: z23.discriminatedUnion("type", [
|
|
@@ -4331,6 +4382,63 @@ var webSearchPreviewOutputSchema = lazySchema21(
|
|
|
4331
4382
|
url: z23.string().nullish(),
|
|
4332
4383
|
pattern: z23.string().nullish()
|
|
4333
4384
|
})
|
|
4385
|
+
]).optional(),
|
|
4386
|
+
sources: z23.array(
|
|
4387
|
+
z23.discriminatedUnion("type", [
|
|
4388
|
+
z23.object({ type: z23.literal("url"), url: z23.string() }),
|
|
4389
|
+
z23.object({ type: z23.literal("api"), name: z23.string() })
|
|
4390
|
+
])
|
|
4391
|
+
).optional()
|
|
4392
|
+
})
|
|
4393
|
+
)
|
|
4394
|
+
);
|
|
4395
|
+
var webSearchToolFactory = createProviderToolFactoryWithOutputSchema8({
|
|
4396
|
+
id: "openai.web_search",
|
|
4397
|
+
inputSchema: webSearchInputSchema,
|
|
4398
|
+
outputSchema: webSearchOutputSchema
|
|
4399
|
+
});
|
|
4400
|
+
|
|
4401
|
+
// src/tool/web-search-preview.ts
|
|
4402
|
+
import {
|
|
4403
|
+
createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema9,
|
|
4404
|
+
lazySchema as lazySchema22,
|
|
4405
|
+
zodSchema as zodSchema22
|
|
4406
|
+
} from "@ai-sdk/provider-utils";
|
|
4407
|
+
import { z as z24 } from "zod/v4";
|
|
4408
|
+
var webSearchPreviewArgsSchema = lazySchema22(
|
|
4409
|
+
() => zodSchema22(
|
|
4410
|
+
z24.object({
|
|
4411
|
+
searchContextSize: z24.enum(["low", "medium", "high"]).optional(),
|
|
4412
|
+
userLocation: z24.object({
|
|
4413
|
+
type: z24.literal("approximate"),
|
|
4414
|
+
country: z24.string().optional(),
|
|
4415
|
+
city: z24.string().optional(),
|
|
4416
|
+
region: z24.string().optional(),
|
|
4417
|
+
timezone: z24.string().optional()
|
|
4418
|
+
}).optional()
|
|
4419
|
+
})
|
|
4420
|
+
)
|
|
4421
|
+
);
|
|
4422
|
+
var webSearchPreviewInputSchema = lazySchema22(
|
|
4423
|
+
() => zodSchema22(z24.object({}))
|
|
4424
|
+
);
|
|
4425
|
+
var webSearchPreviewOutputSchema = lazySchema22(
|
|
4426
|
+
() => zodSchema22(
|
|
4427
|
+
z24.object({
|
|
4428
|
+
action: z24.discriminatedUnion("type", [
|
|
4429
|
+
z24.object({
|
|
4430
|
+
type: z24.literal("search"),
|
|
4431
|
+
query: z24.string().optional()
|
|
4432
|
+
}),
|
|
4433
|
+
z24.object({
|
|
4434
|
+
type: z24.literal("openPage"),
|
|
4435
|
+
url: z24.string().nullish()
|
|
4436
|
+
}),
|
|
4437
|
+
z24.object({
|
|
4438
|
+
type: z24.literal("findInPage"),
|
|
4439
|
+
url: z24.string().nullish(),
|
|
4440
|
+
pattern: z24.string().nullish()
|
|
4441
|
+
})
|
|
4334
4442
|
]).optional()
|
|
4335
4443
|
})
|
|
4336
4444
|
)
|
|
@@ -4344,14 +4452,18 @@ var webSearchPreview = createProviderToolFactoryWithOutputSchema9({
|
|
|
4344
4452
|
// src/responses/openai-responses-prepare-tools.ts
|
|
4345
4453
|
async function prepareResponsesTools({
|
|
4346
4454
|
tools,
|
|
4347
|
-
toolChoice
|
|
4455
|
+
toolChoice,
|
|
4456
|
+
toolNameMapping,
|
|
4457
|
+
customProviderToolNames
|
|
4348
4458
|
}) {
|
|
4459
|
+
var _a;
|
|
4349
4460
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
4350
4461
|
const toolWarnings = [];
|
|
4351
4462
|
if (tools == null) {
|
|
4352
4463
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
4353
4464
|
}
|
|
4354
4465
|
const openaiTools = [];
|
|
4466
|
+
const resolvedCustomProviderToolNames = customProviderToolNames != null ? customProviderToolNames : /* @__PURE__ */ new Set();
|
|
4355
4467
|
for (const tool of tools) {
|
|
4356
4468
|
switch (tool.type) {
|
|
4357
4469
|
case "function":
|
|
@@ -4493,6 +4605,20 @@ async function prepareResponsesTools({
|
|
|
4493
4605
|
});
|
|
4494
4606
|
break;
|
|
4495
4607
|
}
|
|
4608
|
+
case "openai.custom": {
|
|
4609
|
+
const args = await validateTypes2({
|
|
4610
|
+
value: tool.args,
|
|
4611
|
+
schema: customArgsSchema
|
|
4612
|
+
});
|
|
4613
|
+
openaiTools.push({
|
|
4614
|
+
type: "custom",
|
|
4615
|
+
name: args.name,
|
|
4616
|
+
description: args.description,
|
|
4617
|
+
format: args.format
|
|
4618
|
+
});
|
|
4619
|
+
resolvedCustomProviderToolNames.add(args.name);
|
|
4620
|
+
break;
|
|
4621
|
+
}
|
|
4496
4622
|
}
|
|
4497
4623
|
break;
|
|
4498
4624
|
}
|
|
@@ -4513,12 +4639,14 @@ async function prepareResponsesTools({
|
|
|
4513
4639
|
case "none":
|
|
4514
4640
|
case "required":
|
|
4515
4641
|
return { tools: openaiTools, toolChoice: type, toolWarnings };
|
|
4516
|
-
case "tool":
|
|
4642
|
+
case "tool": {
|
|
4643
|
+
const resolvedToolName = (_a = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _a : toolChoice.toolName;
|
|
4517
4644
|
return {
|
|
4518
4645
|
tools: openaiTools,
|
|
4519
|
-
toolChoice:
|
|
4646
|
+
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 },
|
|
4520
4647
|
toolWarnings
|
|
4521
4648
|
};
|
|
4649
|
+
}
|
|
4522
4650
|
default: {
|
|
4523
4651
|
const _exhaustiveCheck = type;
|
|
4524
4652
|
throw new UnsupportedFunctionalityError5({
|
|
@@ -4669,7 +4797,19 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4669
4797
|
"openai.web_search_preview": "web_search_preview",
|
|
4670
4798
|
"openai.mcp": "mcp",
|
|
4671
4799
|
"openai.apply_patch": "apply_patch"
|
|
4672
|
-
}
|
|
4800
|
+
},
|
|
4801
|
+
resolveProviderToolName: (tool) => tool.id === "openai.custom" ? tool.args.name : void 0
|
|
4802
|
+
});
|
|
4803
|
+
const customProviderToolNames = /* @__PURE__ */ new Set();
|
|
4804
|
+
const {
|
|
4805
|
+
tools: openaiTools,
|
|
4806
|
+
toolChoice: openaiToolChoice,
|
|
4807
|
+
toolWarnings
|
|
4808
|
+
} = await prepareResponsesTools({
|
|
4809
|
+
tools,
|
|
4810
|
+
toolChoice,
|
|
4811
|
+
toolNameMapping,
|
|
4812
|
+
customProviderToolNames
|
|
4673
4813
|
});
|
|
4674
4814
|
const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
|
|
4675
4815
|
prompt,
|
|
@@ -4681,7 +4821,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4681
4821
|
hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
|
|
4682
4822
|
hasLocalShellTool: hasOpenAITool("openai.local_shell"),
|
|
4683
4823
|
hasShellTool: hasOpenAITool("openai.shell"),
|
|
4684
|
-
hasApplyPatchTool: hasOpenAITool("openai.apply_patch")
|
|
4824
|
+
hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
|
|
4825
|
+
customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
|
|
4685
4826
|
});
|
|
4686
4827
|
warnings.push(...inputWarnings);
|
|
4687
4828
|
const strictJsonSchema = (_d = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _d : true;
|
|
@@ -4814,14 +4955,6 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4814
4955
|
});
|
|
4815
4956
|
delete baseArgs.service_tier;
|
|
4816
4957
|
}
|
|
4817
|
-
const {
|
|
4818
|
-
tools: openaiTools,
|
|
4819
|
-
toolChoice: openaiToolChoice,
|
|
4820
|
-
toolWarnings
|
|
4821
|
-
} = await prepareResponsesTools({
|
|
4822
|
-
tools,
|
|
4823
|
-
toolChoice
|
|
4824
|
-
});
|
|
4825
4958
|
const shellToolEnvType = (_i = (_h = (_g = tools == null ? void 0 : tools.find(
|
|
4826
4959
|
(tool) => tool.type === "provider" && tool.id === "openai.shell"
|
|
4827
4960
|
)) == null ? void 0 : _g.args) == null ? void 0 : _h.environment) == null ? void 0 : _i.type;
|
|
@@ -5071,6 +5204,22 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5071
5204
|
});
|
|
5072
5205
|
break;
|
|
5073
5206
|
}
|
|
5207
|
+
case "custom_tool_call": {
|
|
5208
|
+
hasFunctionCall = true;
|
|
5209
|
+
const toolName = toolNameMapping.toCustomToolName(part.name);
|
|
5210
|
+
content.push({
|
|
5211
|
+
type: "tool-call",
|
|
5212
|
+
toolCallId: part.call_id,
|
|
5213
|
+
toolName,
|
|
5214
|
+
input: JSON.stringify(part.input),
|
|
5215
|
+
providerMetadata: {
|
|
5216
|
+
[providerOptionsName]: {
|
|
5217
|
+
itemId: part.id
|
|
5218
|
+
}
|
|
5219
|
+
}
|
|
5220
|
+
});
|
|
5221
|
+
break;
|
|
5222
|
+
}
|
|
5074
5223
|
case "web_search_call": {
|
|
5075
5224
|
content.push({
|
|
5076
5225
|
type: "tool-call",
|
|
@@ -5329,6 +5478,19 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5329
5478
|
id: value.item.call_id,
|
|
5330
5479
|
toolName: value.item.name
|
|
5331
5480
|
});
|
|
5481
|
+
} else if (value.item.type === "custom_tool_call") {
|
|
5482
|
+
const toolName = toolNameMapping.toCustomToolName(
|
|
5483
|
+
value.item.name
|
|
5484
|
+
);
|
|
5485
|
+
ongoingToolCalls[value.output_index] = {
|
|
5486
|
+
toolName,
|
|
5487
|
+
toolCallId: value.item.call_id
|
|
5488
|
+
};
|
|
5489
|
+
controller.enqueue({
|
|
5490
|
+
type: "tool-input-start",
|
|
5491
|
+
id: value.item.call_id,
|
|
5492
|
+
toolName
|
|
5493
|
+
});
|
|
5332
5494
|
} else if (value.item.type === "web_search_call") {
|
|
5333
5495
|
ongoingToolCalls[value.output_index] = {
|
|
5334
5496
|
toolName: toolNameMapping.toCustomToolName(
|
|
@@ -5513,6 +5675,27 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5513
5675
|
}
|
|
5514
5676
|
}
|
|
5515
5677
|
});
|
|
5678
|
+
} else if (value.item.type === "custom_tool_call") {
|
|
5679
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
5680
|
+
hasFunctionCall = true;
|
|
5681
|
+
const toolName = toolNameMapping.toCustomToolName(
|
|
5682
|
+
value.item.name
|
|
5683
|
+
);
|
|
5684
|
+
controller.enqueue({
|
|
5685
|
+
type: "tool-input-end",
|
|
5686
|
+
id: value.item.call_id
|
|
5687
|
+
});
|
|
5688
|
+
controller.enqueue({
|
|
5689
|
+
type: "tool-call",
|
|
5690
|
+
toolCallId: value.item.call_id,
|
|
5691
|
+
toolName,
|
|
5692
|
+
input: JSON.stringify(value.item.input),
|
|
5693
|
+
providerMetadata: {
|
|
5694
|
+
[providerOptionsName]: {
|
|
5695
|
+
itemId: value.item.id
|
|
5696
|
+
}
|
|
5697
|
+
}
|
|
5698
|
+
});
|
|
5516
5699
|
} else if (value.item.type === "web_search_call") {
|
|
5517
5700
|
ongoingToolCalls[value.output_index] = void 0;
|
|
5518
5701
|
controller.enqueue({
|
|
@@ -5762,6 +5945,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5762
5945
|
delta: value.delta
|
|
5763
5946
|
});
|
|
5764
5947
|
}
|
|
5948
|
+
} else if (isResponseCustomToolCallInputDeltaChunk(value)) {
|
|
5949
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
5950
|
+
if (toolCall != null) {
|
|
5951
|
+
controller.enqueue({
|
|
5952
|
+
type: "tool-input-delta",
|
|
5953
|
+
id: toolCall.toolCallId,
|
|
5954
|
+
delta: value.delta
|
|
5955
|
+
});
|
|
5956
|
+
}
|
|
5765
5957
|
} else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
|
|
5766
5958
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
5767
5959
|
if (toolCall == null ? void 0 : toolCall.applyPatch) {
|
|
@@ -6022,6 +6214,9 @@ function isResponseCreatedChunk(chunk) {
|
|
|
6022
6214
|
function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
|
|
6023
6215
|
return chunk.type === "response.function_call_arguments.delta";
|
|
6024
6216
|
}
|
|
6217
|
+
function isResponseCustomToolCallInputDeltaChunk(chunk) {
|
|
6218
|
+
return chunk.type === "response.custom_tool_call_input.delta";
|
|
6219
|
+
}
|
|
6025
6220
|
function isResponseImageGenerationCallPartialImageChunk(chunk) {
|
|
6026
6221
|
return chunk.type === "response.image_generation_call.partial_image";
|
|
6027
6222
|
}
|