@ai-sdk/openai 3.0.0-beta.54 → 3.0.0-beta.55
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 +6 -0
- package/dist/index.d.mts +51 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +845 -474
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +803 -428
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +377 -23
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +359 -1
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/internal/index.mjs
CHANGED
|
@@ -2559,6 +2559,19 @@ var openaiResponsesChunkSchema = lazySchema12(
|
|
|
2559
2559
|
])
|
|
2560
2560
|
).nullable(),
|
|
2561
2561
|
status: z14.string()
|
|
2562
|
+
}),
|
|
2563
|
+
z14.object({
|
|
2564
|
+
type: z14.literal("mcp_call"),
|
|
2565
|
+
id: z14.string(),
|
|
2566
|
+
status: z14.string()
|
|
2567
|
+
}),
|
|
2568
|
+
z14.object({
|
|
2569
|
+
type: z14.literal("mcp_list_tools"),
|
|
2570
|
+
id: z14.string()
|
|
2571
|
+
}),
|
|
2572
|
+
z14.object({
|
|
2573
|
+
type: z14.literal("mcp_approval_request"),
|
|
2574
|
+
id: z14.string()
|
|
2562
2575
|
})
|
|
2563
2576
|
])
|
|
2564
2577
|
}),
|
|
@@ -2660,6 +2673,52 @@ var openaiResponsesChunkSchema = lazySchema12(
|
|
|
2660
2673
|
type: z14.literal("computer_call"),
|
|
2661
2674
|
id: z14.string(),
|
|
2662
2675
|
status: z14.literal("completed")
|
|
2676
|
+
}),
|
|
2677
|
+
z14.object({
|
|
2678
|
+
type: z14.literal("mcp_call"),
|
|
2679
|
+
id: z14.string(),
|
|
2680
|
+
status: z14.string(),
|
|
2681
|
+
arguments: z14.string(),
|
|
2682
|
+
name: z14.string(),
|
|
2683
|
+
server_label: z14.string(),
|
|
2684
|
+
output: z14.string().nullish(),
|
|
2685
|
+
error: z14.union([
|
|
2686
|
+
z14.string(),
|
|
2687
|
+
z14.object({
|
|
2688
|
+
type: z14.string().optional(),
|
|
2689
|
+
code: z14.union([z14.number(), z14.string()]).optional(),
|
|
2690
|
+
message: z14.string().optional()
|
|
2691
|
+
}).loose()
|
|
2692
|
+
]).nullish()
|
|
2693
|
+
}),
|
|
2694
|
+
z14.object({
|
|
2695
|
+
type: z14.literal("mcp_list_tools"),
|
|
2696
|
+
id: z14.string(),
|
|
2697
|
+
server_label: z14.string(),
|
|
2698
|
+
tools: z14.array(
|
|
2699
|
+
z14.object({
|
|
2700
|
+
name: z14.string(),
|
|
2701
|
+
description: z14.string().optional(),
|
|
2702
|
+
input_schema: z14.any(),
|
|
2703
|
+
annotations: z14.record(z14.string(), z14.unknown()).optional()
|
|
2704
|
+
})
|
|
2705
|
+
),
|
|
2706
|
+
error: z14.union([
|
|
2707
|
+
z14.string(),
|
|
2708
|
+
z14.object({
|
|
2709
|
+
type: z14.string().optional(),
|
|
2710
|
+
code: z14.union([z14.number(), z14.string()]).optional(),
|
|
2711
|
+
message: z14.string().optional()
|
|
2712
|
+
}).loose()
|
|
2713
|
+
]).optional()
|
|
2714
|
+
}),
|
|
2715
|
+
z14.object({
|
|
2716
|
+
type: z14.literal("mcp_approval_request"),
|
|
2717
|
+
id: z14.string(),
|
|
2718
|
+
server_label: z14.string(),
|
|
2719
|
+
name: z14.string(),
|
|
2720
|
+
arguments: z14.string(),
|
|
2721
|
+
approval_request_id: z14.string()
|
|
2663
2722
|
})
|
|
2664
2723
|
])
|
|
2665
2724
|
}),
|
|
@@ -2915,6 +2974,52 @@ var openaiResponsesResponseSchema = lazySchema12(
|
|
|
2915
2974
|
text: z14.string()
|
|
2916
2975
|
})
|
|
2917
2976
|
)
|
|
2977
|
+
}),
|
|
2978
|
+
z14.object({
|
|
2979
|
+
type: z14.literal("mcp_call"),
|
|
2980
|
+
id: z14.string(),
|
|
2981
|
+
status: z14.string(),
|
|
2982
|
+
arguments: z14.string(),
|
|
2983
|
+
name: z14.string(),
|
|
2984
|
+
server_label: z14.string(),
|
|
2985
|
+
output: z14.string().nullish(),
|
|
2986
|
+
error: z14.union([
|
|
2987
|
+
z14.string(),
|
|
2988
|
+
z14.object({
|
|
2989
|
+
type: z14.string().optional(),
|
|
2990
|
+
code: z14.union([z14.number(), z14.string()]).optional(),
|
|
2991
|
+
message: z14.string().optional()
|
|
2992
|
+
}).loose()
|
|
2993
|
+
]).nullish()
|
|
2994
|
+
}),
|
|
2995
|
+
z14.object({
|
|
2996
|
+
type: z14.literal("mcp_list_tools"),
|
|
2997
|
+
id: z14.string(),
|
|
2998
|
+
server_label: z14.string(),
|
|
2999
|
+
tools: z14.array(
|
|
3000
|
+
z14.object({
|
|
3001
|
+
name: z14.string(),
|
|
3002
|
+
description: z14.string().optional(),
|
|
3003
|
+
input_schema: z14.any(),
|
|
3004
|
+
annotations: z14.record(z14.string(), z14.unknown()).optional()
|
|
3005
|
+
})
|
|
3006
|
+
),
|
|
3007
|
+
error: z14.union([
|
|
3008
|
+
z14.string(),
|
|
3009
|
+
z14.object({
|
|
3010
|
+
type: z14.string().optional(),
|
|
3011
|
+
code: z14.union([z14.number(), z14.string()]).optional(),
|
|
3012
|
+
message: z14.string().optional()
|
|
3013
|
+
}).loose()
|
|
3014
|
+
]).optional()
|
|
3015
|
+
}),
|
|
3016
|
+
z14.object({
|
|
3017
|
+
type: z14.literal("mcp_approval_request"),
|
|
3018
|
+
id: z14.string(),
|
|
3019
|
+
server_label: z14.string(),
|
|
3020
|
+
name: z14.string(),
|
|
3021
|
+
arguments: z14.string(),
|
|
3022
|
+
approval_request_id: z14.string()
|
|
2918
3023
|
})
|
|
2919
3024
|
])
|
|
2920
3025
|
),
|
|
@@ -3300,6 +3405,97 @@ var imageGeneration = (args = {}) => {
|
|
|
3300
3405
|
return imageGenerationToolFactory(args);
|
|
3301
3406
|
};
|
|
3302
3407
|
|
|
3408
|
+
// src/tool/mcp.ts
|
|
3409
|
+
import {
|
|
3410
|
+
createProviderDefinedToolFactoryWithOutputSchema as createProviderDefinedToolFactoryWithOutputSchema7,
|
|
3411
|
+
lazySchema as lazySchema19,
|
|
3412
|
+
zodSchema as zodSchema19
|
|
3413
|
+
} from "@ai-sdk/provider-utils";
|
|
3414
|
+
import { z as z21 } from "zod/v4";
|
|
3415
|
+
var jsonValueSchema = z21.lazy(
|
|
3416
|
+
() => z21.union([
|
|
3417
|
+
z21.string(),
|
|
3418
|
+
z21.number(),
|
|
3419
|
+
z21.boolean(),
|
|
3420
|
+
z21.null(),
|
|
3421
|
+
z21.array(jsonValueSchema),
|
|
3422
|
+
z21.record(z21.string(), jsonValueSchema)
|
|
3423
|
+
])
|
|
3424
|
+
);
|
|
3425
|
+
var mcpArgsSchema = lazySchema19(
|
|
3426
|
+
() => zodSchema19(
|
|
3427
|
+
z21.object({
|
|
3428
|
+
serverLabel: z21.string(),
|
|
3429
|
+
allowedTools: z21.union([
|
|
3430
|
+
z21.array(z21.string()),
|
|
3431
|
+
z21.object({
|
|
3432
|
+
readOnly: z21.boolean().optional(),
|
|
3433
|
+
toolNames: z21.array(z21.string()).optional()
|
|
3434
|
+
})
|
|
3435
|
+
]).optional(),
|
|
3436
|
+
authorization: z21.string().optional(),
|
|
3437
|
+
connectorId: z21.string().optional(),
|
|
3438
|
+
headers: z21.record(z21.string(), z21.string()).optional(),
|
|
3439
|
+
// TODO: Integrate this MCP tool approval with our SDK's existing tool approval architecture
|
|
3440
|
+
// requireApproval: z
|
|
3441
|
+
// .union([
|
|
3442
|
+
// z.enum(['always', 'never']),
|
|
3443
|
+
// z.object({
|
|
3444
|
+
// readOnly: z.boolean().optional(),
|
|
3445
|
+
// toolNames: z.array(z.string()).optional(),
|
|
3446
|
+
// }),
|
|
3447
|
+
// ])
|
|
3448
|
+
// .optional(),
|
|
3449
|
+
serverDescription: z21.string().optional(),
|
|
3450
|
+
serverUrl: z21.string().optional()
|
|
3451
|
+
}).refine(
|
|
3452
|
+
(v) => v.serverUrl != null || v.connectorId != null,
|
|
3453
|
+
"One of serverUrl or connectorId must be provided."
|
|
3454
|
+
)
|
|
3455
|
+
)
|
|
3456
|
+
);
|
|
3457
|
+
var mcpInputSchema = lazySchema19(() => zodSchema19(z21.object({})));
|
|
3458
|
+
var mcpOutputSchema = lazySchema19(
|
|
3459
|
+
() => zodSchema19(
|
|
3460
|
+
z21.discriminatedUnion("type", [
|
|
3461
|
+
z21.object({
|
|
3462
|
+
type: z21.literal("call"),
|
|
3463
|
+
serverLabel: z21.string(),
|
|
3464
|
+
name: z21.string(),
|
|
3465
|
+
arguments: z21.string(),
|
|
3466
|
+
output: z21.string().nullable().optional(),
|
|
3467
|
+
error: z21.union([z21.string(), jsonValueSchema]).optional()
|
|
3468
|
+
}),
|
|
3469
|
+
z21.object({
|
|
3470
|
+
type: z21.literal("listTools"),
|
|
3471
|
+
serverLabel: z21.string(),
|
|
3472
|
+
tools: z21.array(
|
|
3473
|
+
z21.object({
|
|
3474
|
+
name: z21.string(),
|
|
3475
|
+
description: z21.string().optional(),
|
|
3476
|
+
inputSchema: jsonValueSchema,
|
|
3477
|
+
annotations: z21.record(z21.string(), jsonValueSchema).optional()
|
|
3478
|
+
})
|
|
3479
|
+
),
|
|
3480
|
+
error: z21.union([z21.string(), jsonValueSchema]).optional()
|
|
3481
|
+
}),
|
|
3482
|
+
z21.object({
|
|
3483
|
+
type: z21.literal("approvalRequest"),
|
|
3484
|
+
serverLabel: z21.string(),
|
|
3485
|
+
name: z21.string(),
|
|
3486
|
+
arguments: z21.string(),
|
|
3487
|
+
approvalRequestId: z21.string()
|
|
3488
|
+
})
|
|
3489
|
+
])
|
|
3490
|
+
)
|
|
3491
|
+
);
|
|
3492
|
+
var mcpToolFactory = createProviderDefinedToolFactoryWithOutputSchema7({
|
|
3493
|
+
id: "openai.mcp",
|
|
3494
|
+
name: "mcp",
|
|
3495
|
+
inputSchema: mcpInputSchema,
|
|
3496
|
+
outputSchema: mcpOutputSchema
|
|
3497
|
+
});
|
|
3498
|
+
|
|
3303
3499
|
// src/responses/openai-responses-prepare-tools.ts
|
|
3304
3500
|
import { validateTypes as validateTypes2 } from "@ai-sdk/provider-utils";
|
|
3305
3501
|
async function prepareResponsesTools({
|
|
@@ -3408,6 +3604,36 @@ async function prepareResponsesTools({
|
|
|
3408
3604
|
});
|
|
3409
3605
|
break;
|
|
3410
3606
|
}
|
|
3607
|
+
case "openai.mcp": {
|
|
3608
|
+
const args = await validateTypes2({
|
|
3609
|
+
value: tool.args,
|
|
3610
|
+
schema: mcpArgsSchema
|
|
3611
|
+
});
|
|
3612
|
+
openaiTools.push({
|
|
3613
|
+
type: "mcp",
|
|
3614
|
+
server_label: args.serverLabel,
|
|
3615
|
+
allowed_tools: Array.isArray(args.allowedTools) ? args.allowedTools : args.allowedTools ? {
|
|
3616
|
+
read_only: args.allowedTools.readOnly,
|
|
3617
|
+
tool_names: args.allowedTools.toolNames
|
|
3618
|
+
} : void 0,
|
|
3619
|
+
authorization: args.authorization,
|
|
3620
|
+
connector_id: args.connectorId,
|
|
3621
|
+
headers: args.headers,
|
|
3622
|
+
// require_approval:
|
|
3623
|
+
// typeof args.requireApproval === 'string'
|
|
3624
|
+
// ? args.requireApproval
|
|
3625
|
+
// : args.requireApproval
|
|
3626
|
+
// ? {
|
|
3627
|
+
// read_only: args.requireApproval.readOnly,
|
|
3628
|
+
// tool_names: args.requireApproval.toolNames,
|
|
3629
|
+
// }
|
|
3630
|
+
// : undefined,
|
|
3631
|
+
require_approval: "never",
|
|
3632
|
+
server_description: args.serverDescription,
|
|
3633
|
+
server_url: args.serverUrl
|
|
3634
|
+
});
|
|
3635
|
+
break;
|
|
3636
|
+
}
|
|
3411
3637
|
}
|
|
3412
3638
|
break;
|
|
3413
3639
|
}
|
|
@@ -3428,7 +3654,7 @@ async function prepareResponsesTools({
|
|
|
3428
3654
|
case "tool":
|
|
3429
3655
|
return {
|
|
3430
3656
|
tools: openaiTools,
|
|
3431
|
-
toolChoice: toolChoice.toolName === "code_interpreter" || toolChoice.toolName === "file_search" || toolChoice.toolName === "image_generation" || toolChoice.toolName === "web_search_preview" || toolChoice.toolName === "web_search" ? { type: toolChoice.toolName } : { type: "function", name: toolChoice.toolName },
|
|
3657
|
+
toolChoice: toolChoice.toolName === "code_interpreter" || toolChoice.toolName === "file_search" || toolChoice.toolName === "image_generation" || toolChoice.toolName === "web_search_preview" || toolChoice.toolName === "web_search" || toolChoice.toolName === "mcp" ? { type: toolChoice.toolName } : { type: "function", name: toolChoice.toolName },
|
|
3432
3658
|
toolWarnings
|
|
3433
3659
|
};
|
|
3434
3660
|
default: {
|
|
@@ -3858,6 +4084,80 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3858
4084
|
});
|
|
3859
4085
|
break;
|
|
3860
4086
|
}
|
|
4087
|
+
case "mcp_call": {
|
|
4088
|
+
content.push({
|
|
4089
|
+
type: "tool-call",
|
|
4090
|
+
toolCallId: part.id,
|
|
4091
|
+
toolName: "mcp",
|
|
4092
|
+
input: JSON.stringify({}),
|
|
4093
|
+
providerExecuted: true
|
|
4094
|
+
});
|
|
4095
|
+
content.push({
|
|
4096
|
+
type: "tool-result",
|
|
4097
|
+
toolCallId: part.id,
|
|
4098
|
+
toolName: "mcp",
|
|
4099
|
+
result: {
|
|
4100
|
+
type: "call",
|
|
4101
|
+
serverLabel: part.server_label,
|
|
4102
|
+
name: part.name,
|
|
4103
|
+
arguments: part.arguments,
|
|
4104
|
+
...part.output != null ? { output: part.output } : {},
|
|
4105
|
+
...part.error != null ? { error: part.error } : {}
|
|
4106
|
+
}
|
|
4107
|
+
});
|
|
4108
|
+
break;
|
|
4109
|
+
}
|
|
4110
|
+
case "mcp_list_tools": {
|
|
4111
|
+
content.push({
|
|
4112
|
+
type: "tool-call",
|
|
4113
|
+
toolCallId: part.id,
|
|
4114
|
+
toolName: "mcp",
|
|
4115
|
+
input: JSON.stringify({}),
|
|
4116
|
+
providerExecuted: true
|
|
4117
|
+
});
|
|
4118
|
+
content.push({
|
|
4119
|
+
type: "tool-result",
|
|
4120
|
+
toolCallId: part.id,
|
|
4121
|
+
toolName: "mcp",
|
|
4122
|
+
result: {
|
|
4123
|
+
type: "listTools",
|
|
4124
|
+
serverLabel: part.server_label,
|
|
4125
|
+
tools: part.tools.map((t) => {
|
|
4126
|
+
var _a2, _b2;
|
|
4127
|
+
return {
|
|
4128
|
+
name: t.name,
|
|
4129
|
+
description: (_a2 = t.description) != null ? _a2 : void 0,
|
|
4130
|
+
inputSchema: t.input_schema,
|
|
4131
|
+
annotations: (_b2 = t.annotations) != null ? _b2 : void 0
|
|
4132
|
+
};
|
|
4133
|
+
}),
|
|
4134
|
+
...part.error != null ? { error: part.error } : {}
|
|
4135
|
+
}
|
|
4136
|
+
});
|
|
4137
|
+
break;
|
|
4138
|
+
}
|
|
4139
|
+
case "mcp_approval_request": {
|
|
4140
|
+
content.push({
|
|
4141
|
+
type: "tool-call",
|
|
4142
|
+
toolCallId: part.id,
|
|
4143
|
+
toolName: "mcp",
|
|
4144
|
+
input: JSON.stringify({}),
|
|
4145
|
+
providerExecuted: true
|
|
4146
|
+
});
|
|
4147
|
+
content.push({
|
|
4148
|
+
type: "tool-result",
|
|
4149
|
+
toolCallId: part.id,
|
|
4150
|
+
toolName: "mcp",
|
|
4151
|
+
result: {
|
|
4152
|
+
type: "approvalRequest",
|
|
4153
|
+
serverLabel: part.server_label,
|
|
4154
|
+
name: part.name,
|
|
4155
|
+
arguments: part.arguments,
|
|
4156
|
+
approvalRequestId: part.approval_request_id
|
|
4157
|
+
}
|
|
4158
|
+
});
|
|
4159
|
+
break;
|
|
4160
|
+
}
|
|
3861
4161
|
case "computer_call": {
|
|
3862
4162
|
content.push({
|
|
3863
4163
|
type: "tool-call",
|
|
@@ -4092,6 +4392,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4092
4392
|
input: "{}",
|
|
4093
4393
|
providerExecuted: true
|
|
4094
4394
|
});
|
|
4395
|
+
} else if (value.item.type === "mcp_call" || value.item.type === "mcp_list_tools" || value.item.type === "mcp_approval_request") {
|
|
4396
|
+
controller.enqueue({
|
|
4397
|
+
type: "tool-call",
|
|
4398
|
+
toolCallId: value.item.id,
|
|
4399
|
+
toolName: "mcp",
|
|
4400
|
+
input: "{}",
|
|
4401
|
+
providerExecuted: true
|
|
4402
|
+
});
|
|
4095
4403
|
} else if (value.item.type === "message") {
|
|
4096
4404
|
controller.enqueue({
|
|
4097
4405
|
type: "text-start",
|
|
@@ -4203,6 +4511,56 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4203
4511
|
result: value.item.result
|
|
4204
4512
|
}
|
|
4205
4513
|
});
|
|
4514
|
+
} else if (value.item.type === "mcp_call") {
|
|
4515
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
4516
|
+
controller.enqueue({
|
|
4517
|
+
type: "tool-result",
|
|
4518
|
+
toolCallId: value.item.id,
|
|
4519
|
+
toolName: "mcp",
|
|
4520
|
+
result: {
|
|
4521
|
+
type: "call",
|
|
4522
|
+
serverLabel: value.item.server_label,
|
|
4523
|
+
name: value.item.name,
|
|
4524
|
+
arguments: value.item.arguments,
|
|
4525
|
+
...value.item.output != null ? { output: value.item.output } : {},
|
|
4526
|
+
...value.item.error != null ? { error: value.item.error } : {}
|
|
4527
|
+
}
|
|
4528
|
+
});
|
|
4529
|
+
} else if (value.item.type === "mcp_list_tools") {
|
|
4530
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
4531
|
+
controller.enqueue({
|
|
4532
|
+
type: "tool-result",
|
|
4533
|
+
toolCallId: value.item.id,
|
|
4534
|
+
toolName: "mcp",
|
|
4535
|
+
result: {
|
|
4536
|
+
type: "listTools",
|
|
4537
|
+
serverLabel: value.item.server_label,
|
|
4538
|
+
tools: value.item.tools.map((t) => {
|
|
4539
|
+
var _a2, _b2;
|
|
4540
|
+
return {
|
|
4541
|
+
name: t.name,
|
|
4542
|
+
description: (_a2 = t.description) != null ? _a2 : void 0,
|
|
4543
|
+
inputSchema: t.input_schema,
|
|
4544
|
+
annotations: (_b2 = t.annotations) != null ? _b2 : void 0
|
|
4545
|
+
};
|
|
4546
|
+
}),
|
|
4547
|
+
...value.item.error != null ? { error: value.item.error } : {}
|
|
4548
|
+
}
|
|
4549
|
+
});
|
|
4550
|
+
} else if (value.item.type === "mcp_approval_request") {
|
|
4551
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
4552
|
+
controller.enqueue({
|
|
4553
|
+
type: "tool-result",
|
|
4554
|
+
toolCallId: value.item.id,
|
|
4555
|
+
toolName: "mcp",
|
|
4556
|
+
result: {
|
|
4557
|
+
type: "approvalRequest",
|
|
4558
|
+
serverLabel: value.item.server_label,
|
|
4559
|
+
name: value.item.name,
|
|
4560
|
+
arguments: value.item.arguments,
|
|
4561
|
+
approvalRequestId: value.item.approval_request_id
|
|
4562
|
+
}
|
|
4563
|
+
});
|
|
4206
4564
|
} else if (value.item.type === "local_shell_call") {
|
|
4207
4565
|
ongoingToolCalls[value.output_index] = void 0;
|
|
4208
4566
|
controller.enqueue({
|