@ai-sdk/openai 3.0.35 → 3.0.37
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 +21 -0
- package/dist/index.d.mts +50 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +1167 -948
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1117 -894
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +18 -0
- package/dist/internal/index.d.ts +18 -0
- package/dist/internal/index.js +349 -141
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +327 -115
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-openai.mdx +78 -0
- package/package.json +2 -2
- package/src/chat/openai-chat-language-model.ts +4 -1
- package/src/openai-tools.ts +12 -0
- 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-prepare-tools.ts +41 -11
- package/src/tool/custom.ts +64 -0
package/dist/internal/index.mjs
CHANGED
|
@@ -997,7 +997,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
997
997
|
for (const toolCallDelta of delta.tool_calls) {
|
|
998
998
|
const index = toolCallDelta.index;
|
|
999
999
|
if (toolCalls[index] == null) {
|
|
1000
|
-
if (toolCallDelta.type !== "function") {
|
|
1000
|
+
if (toolCallDelta.type != null && toolCallDelta.type !== "function") {
|
|
1001
1001
|
throw new InvalidResponseDataError({
|
|
1002
1002
|
data: toolCallDelta,
|
|
1003
1003
|
message: `Expected 'function' type.`
|
|
@@ -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(),
|
|
@@ -4167,139 +4261,115 @@ var imageGeneration = (args = {}) => {
|
|
|
4167
4261
|
return imageGenerationToolFactory(args);
|
|
4168
4262
|
};
|
|
4169
4263
|
|
|
4170
|
-
// src/tool/
|
|
4264
|
+
// src/tool/custom.ts
|
|
4171
4265
|
import {
|
|
4172
|
-
|
|
4266
|
+
createProviderToolFactory,
|
|
4173
4267
|
lazySchema as lazySchema19,
|
|
4174
4268
|
zodSchema as zodSchema19
|
|
4175
4269
|
} from "@ai-sdk/provider-utils";
|
|
4176
4270
|
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(
|
|
4271
|
+
var customArgsSchema = lazySchema19(
|
|
4188
4272
|
() => zodSchema19(
|
|
4189
4273
|
z21.object({
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4274
|
+
name: z21.string(),
|
|
4275
|
+
description: z21.string().optional(),
|
|
4276
|
+
format: z21.union([
|
|
4193
4277
|
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"]),
|
|
4278
|
+
type: z21.literal("grammar"),
|
|
4279
|
+
syntax: z21.enum(["regex", "lark"]),
|
|
4280
|
+
definition: z21.string()
|
|
4281
|
+
}),
|
|
4203
4282
|
z21.object({
|
|
4204
|
-
|
|
4205
|
-
toolNames: z21.array(z21.string()).optional()
|
|
4206
|
-
}).optional()
|
|
4283
|
+
type: z21.literal("text")
|
|
4207
4284
|
})
|
|
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()
|
|
4285
|
+
]).optional()
|
|
4227
4286
|
})
|
|
4228
4287
|
)
|
|
4229
4288
|
);
|
|
4230
|
-
var
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4289
|
+
var customInputSchema = lazySchema19(() => zodSchema19(z21.string()));
|
|
4290
|
+
var customToolFactory = createProviderToolFactory({
|
|
4291
|
+
id: "openai.custom",
|
|
4292
|
+
inputSchema: customInputSchema
|
|
4234
4293
|
});
|
|
4235
4294
|
|
|
4236
|
-
// src/tool/
|
|
4295
|
+
// src/tool/mcp.ts
|
|
4237
4296
|
import {
|
|
4238
|
-
createProviderToolFactoryWithOutputSchema as
|
|
4297
|
+
createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema7,
|
|
4239
4298
|
lazySchema as lazySchema20,
|
|
4240
4299
|
zodSchema as zodSchema20
|
|
4241
4300
|
} from "@ai-sdk/provider-utils";
|
|
4242
4301
|
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
|
-
)
|
|
4302
|
+
var jsonValueSchema = z22.lazy(
|
|
4303
|
+
() => z22.union([
|
|
4304
|
+
z22.string(),
|
|
4305
|
+
z22.number(),
|
|
4306
|
+
z22.boolean(),
|
|
4307
|
+
z22.null(),
|
|
4308
|
+
z22.array(jsonValueSchema),
|
|
4309
|
+
z22.record(z22.string(), jsonValueSchema)
|
|
4310
|
+
])
|
|
4258
4311
|
);
|
|
4259
|
-
var
|
|
4260
|
-
var webSearchOutputSchema = lazySchema20(
|
|
4312
|
+
var mcpArgsSchema = lazySchema20(
|
|
4261
4313
|
() => zodSchema20(
|
|
4262
4314
|
z22.object({
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
query: z22.string().optional()
|
|
4267
|
-
}),
|
|
4315
|
+
serverLabel: z22.string(),
|
|
4316
|
+
allowedTools: z22.union([
|
|
4317
|
+
z22.array(z22.string()),
|
|
4268
4318
|
z22.object({
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
})
|
|
4319
|
+
readOnly: z22.boolean().optional(),
|
|
4320
|
+
toolNames: z22.array(z22.string()).optional()
|
|
4321
|
+
})
|
|
4322
|
+
]).optional(),
|
|
4323
|
+
authorization: z22.string().optional(),
|
|
4324
|
+
connectorId: z22.string().optional(),
|
|
4325
|
+
headers: z22.record(z22.string(), z22.string()).optional(),
|
|
4326
|
+
requireApproval: z22.union([
|
|
4327
|
+
z22.enum(["always", "never"]),
|
|
4272
4328
|
z22.object({
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4329
|
+
never: z22.object({
|
|
4330
|
+
toolNames: z22.array(z22.string()).optional()
|
|
4331
|
+
}).optional()
|
|
4276
4332
|
})
|
|
4277
4333
|
]).optional(),
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4334
|
+
serverDescription: z22.string().optional(),
|
|
4335
|
+
serverUrl: z22.string().optional()
|
|
4336
|
+
}).refine(
|
|
4337
|
+
(v) => v.serverUrl != null || v.connectorId != null,
|
|
4338
|
+
"One of serverUrl or connectorId must be provided."
|
|
4339
|
+
)
|
|
4340
|
+
)
|
|
4341
|
+
);
|
|
4342
|
+
var mcpInputSchema = lazySchema20(() => zodSchema20(z22.object({})));
|
|
4343
|
+
var mcpOutputSchema = lazySchema20(
|
|
4344
|
+
() => zodSchema20(
|
|
4345
|
+
z22.object({
|
|
4346
|
+
type: z22.literal("call"),
|
|
4347
|
+
serverLabel: z22.string(),
|
|
4348
|
+
name: z22.string(),
|
|
4349
|
+
arguments: z22.string(),
|
|
4350
|
+
output: z22.string().nullish(),
|
|
4351
|
+
error: z22.union([z22.string(), jsonValueSchema]).optional()
|
|
4284
4352
|
})
|
|
4285
4353
|
)
|
|
4286
4354
|
);
|
|
4287
|
-
var
|
|
4288
|
-
id: "openai.
|
|
4289
|
-
inputSchema:
|
|
4290
|
-
outputSchema:
|
|
4355
|
+
var mcpToolFactory = createProviderToolFactoryWithOutputSchema7({
|
|
4356
|
+
id: "openai.mcp",
|
|
4357
|
+
inputSchema: mcpInputSchema,
|
|
4358
|
+
outputSchema: mcpOutputSchema
|
|
4291
4359
|
});
|
|
4292
4360
|
|
|
4293
|
-
// src/tool/web-search
|
|
4361
|
+
// src/tool/web-search.ts
|
|
4294
4362
|
import {
|
|
4295
|
-
createProviderToolFactoryWithOutputSchema as
|
|
4363
|
+
createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema8,
|
|
4296
4364
|
lazySchema as lazySchema21,
|
|
4297
4365
|
zodSchema as zodSchema21
|
|
4298
4366
|
} from "@ai-sdk/provider-utils";
|
|
4299
4367
|
import { z as z23 } from "zod/v4";
|
|
4300
|
-
var
|
|
4368
|
+
var webSearchArgsSchema = lazySchema21(
|
|
4301
4369
|
() => zodSchema21(
|
|
4302
4370
|
z23.object({
|
|
4371
|
+
externalWebAccess: z23.boolean().optional(),
|
|
4372
|
+
filters: z23.object({ allowedDomains: z23.array(z23.string()).optional() }).optional(),
|
|
4303
4373
|
searchContextSize: z23.enum(["low", "medium", "high"]).optional(),
|
|
4304
4374
|
userLocation: z23.object({
|
|
4305
4375
|
type: z23.literal("approximate"),
|
|
@@ -4311,10 +4381,8 @@ var webSearchPreviewArgsSchema = lazySchema21(
|
|
|
4311
4381
|
})
|
|
4312
4382
|
)
|
|
4313
4383
|
);
|
|
4314
|
-
var
|
|
4315
|
-
|
|
4316
|
-
);
|
|
4317
|
-
var webSearchPreviewOutputSchema = lazySchema21(
|
|
4384
|
+
var webSearchInputSchema = lazySchema21(() => zodSchema21(z23.object({})));
|
|
4385
|
+
var webSearchOutputSchema = lazySchema21(
|
|
4318
4386
|
() => zodSchema21(
|
|
4319
4387
|
z23.object({
|
|
4320
4388
|
action: z23.discriminatedUnion("type", [
|
|
@@ -4331,6 +4399,63 @@ var webSearchPreviewOutputSchema = lazySchema21(
|
|
|
4331
4399
|
url: z23.string().nullish(),
|
|
4332
4400
|
pattern: z23.string().nullish()
|
|
4333
4401
|
})
|
|
4402
|
+
]).optional(),
|
|
4403
|
+
sources: z23.array(
|
|
4404
|
+
z23.discriminatedUnion("type", [
|
|
4405
|
+
z23.object({ type: z23.literal("url"), url: z23.string() }),
|
|
4406
|
+
z23.object({ type: z23.literal("api"), name: z23.string() })
|
|
4407
|
+
])
|
|
4408
|
+
).optional()
|
|
4409
|
+
})
|
|
4410
|
+
)
|
|
4411
|
+
);
|
|
4412
|
+
var webSearchToolFactory = createProviderToolFactoryWithOutputSchema8({
|
|
4413
|
+
id: "openai.web_search",
|
|
4414
|
+
inputSchema: webSearchInputSchema,
|
|
4415
|
+
outputSchema: webSearchOutputSchema
|
|
4416
|
+
});
|
|
4417
|
+
|
|
4418
|
+
// src/tool/web-search-preview.ts
|
|
4419
|
+
import {
|
|
4420
|
+
createProviderToolFactoryWithOutputSchema as createProviderToolFactoryWithOutputSchema9,
|
|
4421
|
+
lazySchema as lazySchema22,
|
|
4422
|
+
zodSchema as zodSchema22
|
|
4423
|
+
} from "@ai-sdk/provider-utils";
|
|
4424
|
+
import { z as z24 } from "zod/v4";
|
|
4425
|
+
var webSearchPreviewArgsSchema = lazySchema22(
|
|
4426
|
+
() => zodSchema22(
|
|
4427
|
+
z24.object({
|
|
4428
|
+
searchContextSize: z24.enum(["low", "medium", "high"]).optional(),
|
|
4429
|
+
userLocation: z24.object({
|
|
4430
|
+
type: z24.literal("approximate"),
|
|
4431
|
+
country: z24.string().optional(),
|
|
4432
|
+
city: z24.string().optional(),
|
|
4433
|
+
region: z24.string().optional(),
|
|
4434
|
+
timezone: z24.string().optional()
|
|
4435
|
+
}).optional()
|
|
4436
|
+
})
|
|
4437
|
+
)
|
|
4438
|
+
);
|
|
4439
|
+
var webSearchPreviewInputSchema = lazySchema22(
|
|
4440
|
+
() => zodSchema22(z24.object({}))
|
|
4441
|
+
);
|
|
4442
|
+
var webSearchPreviewOutputSchema = lazySchema22(
|
|
4443
|
+
() => zodSchema22(
|
|
4444
|
+
z24.object({
|
|
4445
|
+
action: z24.discriminatedUnion("type", [
|
|
4446
|
+
z24.object({
|
|
4447
|
+
type: z24.literal("search"),
|
|
4448
|
+
query: z24.string().optional()
|
|
4449
|
+
}),
|
|
4450
|
+
z24.object({
|
|
4451
|
+
type: z24.literal("openPage"),
|
|
4452
|
+
url: z24.string().nullish()
|
|
4453
|
+
}),
|
|
4454
|
+
z24.object({
|
|
4455
|
+
type: z24.literal("findInPage"),
|
|
4456
|
+
url: z24.string().nullish(),
|
|
4457
|
+
pattern: z24.string().nullish()
|
|
4458
|
+
})
|
|
4334
4459
|
]).optional()
|
|
4335
4460
|
})
|
|
4336
4461
|
)
|
|
@@ -4344,14 +4469,18 @@ var webSearchPreview = createProviderToolFactoryWithOutputSchema9({
|
|
|
4344
4469
|
// src/responses/openai-responses-prepare-tools.ts
|
|
4345
4470
|
async function prepareResponsesTools({
|
|
4346
4471
|
tools,
|
|
4347
|
-
toolChoice
|
|
4472
|
+
toolChoice,
|
|
4473
|
+
toolNameMapping,
|
|
4474
|
+
customProviderToolNames
|
|
4348
4475
|
}) {
|
|
4476
|
+
var _a;
|
|
4349
4477
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
4350
4478
|
const toolWarnings = [];
|
|
4351
4479
|
if (tools == null) {
|
|
4352
4480
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
4353
4481
|
}
|
|
4354
4482
|
const openaiTools = [];
|
|
4483
|
+
const resolvedCustomProviderToolNames = customProviderToolNames != null ? customProviderToolNames : /* @__PURE__ */ new Set();
|
|
4355
4484
|
for (const tool of tools) {
|
|
4356
4485
|
switch (tool.type) {
|
|
4357
4486
|
case "function":
|
|
@@ -4493,6 +4622,20 @@ async function prepareResponsesTools({
|
|
|
4493
4622
|
});
|
|
4494
4623
|
break;
|
|
4495
4624
|
}
|
|
4625
|
+
case "openai.custom": {
|
|
4626
|
+
const args = await validateTypes2({
|
|
4627
|
+
value: tool.args,
|
|
4628
|
+
schema: customArgsSchema
|
|
4629
|
+
});
|
|
4630
|
+
openaiTools.push({
|
|
4631
|
+
type: "custom",
|
|
4632
|
+
name: args.name,
|
|
4633
|
+
description: args.description,
|
|
4634
|
+
format: args.format
|
|
4635
|
+
});
|
|
4636
|
+
resolvedCustomProviderToolNames.add(args.name);
|
|
4637
|
+
break;
|
|
4638
|
+
}
|
|
4496
4639
|
}
|
|
4497
4640
|
break;
|
|
4498
4641
|
}
|
|
@@ -4513,12 +4656,14 @@ async function prepareResponsesTools({
|
|
|
4513
4656
|
case "none":
|
|
4514
4657
|
case "required":
|
|
4515
4658
|
return { tools: openaiTools, toolChoice: type, toolWarnings };
|
|
4516
|
-
case "tool":
|
|
4659
|
+
case "tool": {
|
|
4660
|
+
const resolvedToolName = (_a = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _a : toolChoice.toolName;
|
|
4517
4661
|
return {
|
|
4518
4662
|
tools: openaiTools,
|
|
4519
|
-
toolChoice:
|
|
4663
|
+
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
4664
|
toolWarnings
|
|
4521
4665
|
};
|
|
4666
|
+
}
|
|
4522
4667
|
default: {
|
|
4523
4668
|
const _exhaustiveCheck = type;
|
|
4524
4669
|
throw new UnsupportedFunctionalityError5({
|
|
@@ -4669,7 +4814,19 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4669
4814
|
"openai.web_search_preview": "web_search_preview",
|
|
4670
4815
|
"openai.mcp": "mcp",
|
|
4671
4816
|
"openai.apply_patch": "apply_patch"
|
|
4672
|
-
}
|
|
4817
|
+
},
|
|
4818
|
+
resolveProviderToolName: (tool) => tool.id === "openai.custom" ? tool.args.name : void 0
|
|
4819
|
+
});
|
|
4820
|
+
const customProviderToolNames = /* @__PURE__ */ new Set();
|
|
4821
|
+
const {
|
|
4822
|
+
tools: openaiTools,
|
|
4823
|
+
toolChoice: openaiToolChoice,
|
|
4824
|
+
toolWarnings
|
|
4825
|
+
} = await prepareResponsesTools({
|
|
4826
|
+
tools,
|
|
4827
|
+
toolChoice,
|
|
4828
|
+
toolNameMapping,
|
|
4829
|
+
customProviderToolNames
|
|
4673
4830
|
});
|
|
4674
4831
|
const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
|
|
4675
4832
|
prompt,
|
|
@@ -4681,7 +4838,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4681
4838
|
hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
|
|
4682
4839
|
hasLocalShellTool: hasOpenAITool("openai.local_shell"),
|
|
4683
4840
|
hasShellTool: hasOpenAITool("openai.shell"),
|
|
4684
|
-
hasApplyPatchTool: hasOpenAITool("openai.apply_patch")
|
|
4841
|
+
hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
|
|
4842
|
+
customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
|
|
4685
4843
|
});
|
|
4686
4844
|
warnings.push(...inputWarnings);
|
|
4687
4845
|
const strictJsonSchema = (_d = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _d : true;
|
|
@@ -4814,14 +4972,6 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4814
4972
|
});
|
|
4815
4973
|
delete baseArgs.service_tier;
|
|
4816
4974
|
}
|
|
4817
|
-
const {
|
|
4818
|
-
tools: openaiTools,
|
|
4819
|
-
toolChoice: openaiToolChoice,
|
|
4820
|
-
toolWarnings
|
|
4821
|
-
} = await prepareResponsesTools({
|
|
4822
|
-
tools,
|
|
4823
|
-
toolChoice
|
|
4824
|
-
});
|
|
4825
4975
|
const shellToolEnvType = (_i = (_h = (_g = tools == null ? void 0 : tools.find(
|
|
4826
4976
|
(tool) => tool.type === "provider" && tool.id === "openai.shell"
|
|
4827
4977
|
)) == null ? void 0 : _g.args) == null ? void 0 : _h.environment) == null ? void 0 : _i.type;
|
|
@@ -5071,6 +5221,22 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5071
5221
|
});
|
|
5072
5222
|
break;
|
|
5073
5223
|
}
|
|
5224
|
+
case "custom_tool_call": {
|
|
5225
|
+
hasFunctionCall = true;
|
|
5226
|
+
const toolName = toolNameMapping.toCustomToolName(part.name);
|
|
5227
|
+
content.push({
|
|
5228
|
+
type: "tool-call",
|
|
5229
|
+
toolCallId: part.call_id,
|
|
5230
|
+
toolName,
|
|
5231
|
+
input: JSON.stringify(part.input),
|
|
5232
|
+
providerMetadata: {
|
|
5233
|
+
[providerOptionsName]: {
|
|
5234
|
+
itemId: part.id
|
|
5235
|
+
}
|
|
5236
|
+
}
|
|
5237
|
+
});
|
|
5238
|
+
break;
|
|
5239
|
+
}
|
|
5074
5240
|
case "web_search_call": {
|
|
5075
5241
|
content.push({
|
|
5076
5242
|
type: "tool-call",
|
|
@@ -5329,6 +5495,19 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5329
5495
|
id: value.item.call_id,
|
|
5330
5496
|
toolName: value.item.name
|
|
5331
5497
|
});
|
|
5498
|
+
} else if (value.item.type === "custom_tool_call") {
|
|
5499
|
+
const toolName = toolNameMapping.toCustomToolName(
|
|
5500
|
+
value.item.name
|
|
5501
|
+
);
|
|
5502
|
+
ongoingToolCalls[value.output_index] = {
|
|
5503
|
+
toolName,
|
|
5504
|
+
toolCallId: value.item.call_id
|
|
5505
|
+
};
|
|
5506
|
+
controller.enqueue({
|
|
5507
|
+
type: "tool-input-start",
|
|
5508
|
+
id: value.item.call_id,
|
|
5509
|
+
toolName
|
|
5510
|
+
});
|
|
5332
5511
|
} else if (value.item.type === "web_search_call") {
|
|
5333
5512
|
ongoingToolCalls[value.output_index] = {
|
|
5334
5513
|
toolName: toolNameMapping.toCustomToolName(
|
|
@@ -5513,6 +5692,27 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5513
5692
|
}
|
|
5514
5693
|
}
|
|
5515
5694
|
});
|
|
5695
|
+
} else if (value.item.type === "custom_tool_call") {
|
|
5696
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
5697
|
+
hasFunctionCall = true;
|
|
5698
|
+
const toolName = toolNameMapping.toCustomToolName(
|
|
5699
|
+
value.item.name
|
|
5700
|
+
);
|
|
5701
|
+
controller.enqueue({
|
|
5702
|
+
type: "tool-input-end",
|
|
5703
|
+
id: value.item.call_id
|
|
5704
|
+
});
|
|
5705
|
+
controller.enqueue({
|
|
5706
|
+
type: "tool-call",
|
|
5707
|
+
toolCallId: value.item.call_id,
|
|
5708
|
+
toolName,
|
|
5709
|
+
input: JSON.stringify(value.item.input),
|
|
5710
|
+
providerMetadata: {
|
|
5711
|
+
[providerOptionsName]: {
|
|
5712
|
+
itemId: value.item.id
|
|
5713
|
+
}
|
|
5714
|
+
}
|
|
5715
|
+
});
|
|
5516
5716
|
} else if (value.item.type === "web_search_call") {
|
|
5517
5717
|
ongoingToolCalls[value.output_index] = void 0;
|
|
5518
5718
|
controller.enqueue({
|
|
@@ -5762,6 +5962,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5762
5962
|
delta: value.delta
|
|
5763
5963
|
});
|
|
5764
5964
|
}
|
|
5965
|
+
} else if (isResponseCustomToolCallInputDeltaChunk(value)) {
|
|
5966
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
5967
|
+
if (toolCall != null) {
|
|
5968
|
+
controller.enqueue({
|
|
5969
|
+
type: "tool-input-delta",
|
|
5970
|
+
id: toolCall.toolCallId,
|
|
5971
|
+
delta: value.delta
|
|
5972
|
+
});
|
|
5973
|
+
}
|
|
5765
5974
|
} else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
|
|
5766
5975
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
5767
5976
|
if (toolCall == null ? void 0 : toolCall.applyPatch) {
|
|
@@ -6022,6 +6231,9 @@ function isResponseCreatedChunk(chunk) {
|
|
|
6022
6231
|
function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
|
|
6023
6232
|
return chunk.type === "response.function_call_arguments.delta";
|
|
6024
6233
|
}
|
|
6234
|
+
function isResponseCustomToolCallInputDeltaChunk(chunk) {
|
|
6235
|
+
return chunk.type === "response.custom_tool_call_input.delta";
|
|
6236
|
+
}
|
|
6025
6237
|
function isResponseImageGenerationCallPartialImageChunk(chunk) {
|
|
6026
6238
|
return chunk.type === "response.image_generation_call.partial_image";
|
|
6027
6239
|
}
|