@ai-sdk/openai 3.0.97 → 3.0.99
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 +26 -0
- package/dist/index.js +700 -240
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +625 -163
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +720 -262
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +622 -162
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-openai.mdx +57 -0
- package/package.json +1 -1
- package/src/responses/convert-to-openai-responses-input.ts +309 -90
- package/src/responses/expand-parallel-tool-call.ts +142 -0
- package/src/responses/openai-responses-api.ts +15 -0
- package/src/responses/openai-responses-language-model.ts +171 -29
- package/src/responses/openai-responses-prepare-tools.ts +186 -5
package/dist/internal/index.js
CHANGED
|
@@ -2678,8 +2678,8 @@ var OpenAISpeechModel = class {
|
|
|
2678
2678
|
};
|
|
2679
2679
|
|
|
2680
2680
|
// src/responses/openai-responses-language-model.ts
|
|
2681
|
-
var
|
|
2682
|
-
var
|
|
2681
|
+
var import_provider10 = require("@ai-sdk/provider");
|
|
2682
|
+
var import_provider_utils36 = require("@ai-sdk/provider-utils");
|
|
2683
2683
|
|
|
2684
2684
|
// src/responses/convert-openai-responses-usage.ts
|
|
2685
2685
|
function convertOpenAIResponsesUsage(usage) {
|
|
@@ -2722,8 +2722,8 @@ function convertOpenAIResponsesUsage(usage) {
|
|
|
2722
2722
|
}
|
|
2723
2723
|
|
|
2724
2724
|
// src/responses/convert-to-openai-responses-input.ts
|
|
2725
|
-
var
|
|
2726
|
-
var
|
|
2725
|
+
var import_provider8 = require("@ai-sdk/provider");
|
|
2726
|
+
var import_provider_utils25 = require("@ai-sdk/provider-utils");
|
|
2727
2727
|
var import_v417 = require("zod/v4");
|
|
2728
2728
|
|
|
2729
2729
|
// src/tool/apply-patch.ts
|
|
@@ -2924,10 +2924,225 @@ var toolSearchToolFactory = (0, import_provider_utils23.createProviderToolFactor
|
|
|
2924
2924
|
outputSchema: toolSearchOutputSchema
|
|
2925
2925
|
});
|
|
2926
2926
|
|
|
2927
|
+
// src/responses/expand-parallel-tool-call.ts
|
|
2928
|
+
var import_provider7 = require("@ai-sdk/provider");
|
|
2929
|
+
var import_provider_utils24 = require("@ai-sdk/provider-utils");
|
|
2930
|
+
var parallelToolName = "parallel";
|
|
2931
|
+
var recipientNamePrefix = "functions.";
|
|
2932
|
+
function getParallelToolCallMetadata({
|
|
2933
|
+
providerOptions,
|
|
2934
|
+
providerOptionsName
|
|
2935
|
+
}) {
|
|
2936
|
+
var _a;
|
|
2937
|
+
const metadata = (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.parallelToolCall;
|
|
2938
|
+
if (!(0, import_provider7.isJSONObject)(metadata) || typeof metadata.itemId !== "string" || typeof metadata.toolCallId !== "string" || typeof metadata.toolName !== "string" || typeof metadata.input !== "string" || typeof metadata.index !== "number" || !Number.isInteger(metadata.index) || typeof metadata.count !== "number" || !Number.isInteger(metadata.count) || metadata.index < 0 || metadata.count <= metadata.index) {
|
|
2939
|
+
return void 0;
|
|
2940
|
+
}
|
|
2941
|
+
return metadata;
|
|
2942
|
+
}
|
|
2943
|
+
function isUndeclaredParallelToolCall({
|
|
2944
|
+
toolName,
|
|
2945
|
+
tools
|
|
2946
|
+
}) {
|
|
2947
|
+
return toolName === parallelToolName && !tools.some((tool) => tool.name === parallelToolName);
|
|
2948
|
+
}
|
|
2949
|
+
async function expandParallelToolCall({
|
|
2950
|
+
toolCall,
|
|
2951
|
+
tools,
|
|
2952
|
+
providerOptionsName,
|
|
2953
|
+
itemId
|
|
2954
|
+
}) {
|
|
2955
|
+
if (!isUndeclaredParallelToolCall({ toolName: toolCall.toolName, tools })) {
|
|
2956
|
+
return void 0;
|
|
2957
|
+
}
|
|
2958
|
+
const parsedInput = await (0, import_provider_utils24.safeParseJSON)({ text: toolCall.input });
|
|
2959
|
+
if (!parsedInput.success || !(0, import_provider7.isJSONObject)(parsedInput.value)) {
|
|
2960
|
+
return void 0;
|
|
2961
|
+
}
|
|
2962
|
+
const toolUses = parsedInput.value.tool_uses;
|
|
2963
|
+
if (!Array.isArray(toolUses) || toolUses.length === 0) {
|
|
2964
|
+
return void 0;
|
|
2965
|
+
}
|
|
2966
|
+
const availableToolNames = new Set(tools.map((tool) => tool.name));
|
|
2967
|
+
const expandedToolCalls = [];
|
|
2968
|
+
for (const [index, toolUse] of toolUses.entries()) {
|
|
2969
|
+
if (!(0, import_provider7.isJSONObject)(toolUse)) {
|
|
2970
|
+
return void 0;
|
|
2971
|
+
}
|
|
2972
|
+
const recipientName = toolUse.recipient_name;
|
|
2973
|
+
const parameters = toolUse.parameters;
|
|
2974
|
+
if (typeof recipientName !== "string" || !recipientName.startsWith(recipientNamePrefix) || !(0, import_provider7.isJSONObject)(parameters)) {
|
|
2975
|
+
return void 0;
|
|
2976
|
+
}
|
|
2977
|
+
const toolName = recipientName.slice(recipientNamePrefix.length);
|
|
2978
|
+
if (toolName.length === 0 || !availableToolNames.has(toolName)) {
|
|
2979
|
+
return void 0;
|
|
2980
|
+
}
|
|
2981
|
+
expandedToolCalls.push({
|
|
2982
|
+
type: "tool-call",
|
|
2983
|
+
toolCallId: `${toolCall.toolCallId}_${index}`,
|
|
2984
|
+
toolName,
|
|
2985
|
+
input: JSON.stringify(parameters),
|
|
2986
|
+
providerMetadata: {
|
|
2987
|
+
[providerOptionsName]: {
|
|
2988
|
+
parallelToolCall: {
|
|
2989
|
+
itemId,
|
|
2990
|
+
toolCallId: toolCall.toolCallId,
|
|
2991
|
+
toolName: toolCall.toolName,
|
|
2992
|
+
input: toolCall.input,
|
|
2993
|
+
index,
|
|
2994
|
+
count: toolUses.length
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
});
|
|
2999
|
+
}
|
|
3000
|
+
return expandedToolCalls;
|
|
3001
|
+
}
|
|
3002
|
+
|
|
2927
3003
|
// src/responses/convert-to-openai-responses-input.ts
|
|
2928
3004
|
function serializeToolCallArguments2(input) {
|
|
2929
3005
|
return JSON.stringify(input === void 0 ? {} : input);
|
|
2930
3006
|
}
|
|
3007
|
+
async function convertFunctionToolResultOutput({
|
|
3008
|
+
output,
|
|
3009
|
+
providerOptionsName,
|
|
3010
|
+
warnings
|
|
3011
|
+
}) {
|
|
3012
|
+
var _a;
|
|
3013
|
+
switch (output.type) {
|
|
3014
|
+
case "text":
|
|
3015
|
+
case "error-text":
|
|
3016
|
+
return output.value;
|
|
3017
|
+
case "execution-denied":
|
|
3018
|
+
return (_a = output.reason) != null ? _a : "Tool call execution denied.";
|
|
3019
|
+
case "json":
|
|
3020
|
+
case "error-json":
|
|
3021
|
+
return JSON.stringify(output.value);
|
|
3022
|
+
case "content":
|
|
3023
|
+
return output.value.map((item) => {
|
|
3024
|
+
var _a2, _b, _c, _d, _e;
|
|
3025
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
3026
|
+
item.providerOptions,
|
|
3027
|
+
providerOptionsName
|
|
3028
|
+
);
|
|
3029
|
+
switch (item.type) {
|
|
3030
|
+
case "text": {
|
|
3031
|
+
return {
|
|
3032
|
+
type: "input_text",
|
|
3033
|
+
text: item.text,
|
|
3034
|
+
...promptCacheBreakpoint != null && {
|
|
3035
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3036
|
+
}
|
|
3037
|
+
};
|
|
3038
|
+
}
|
|
3039
|
+
case "image-data": {
|
|
3040
|
+
return {
|
|
3041
|
+
type: "input_image",
|
|
3042
|
+
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3043
|
+
detail: (_b = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b.imageDetail,
|
|
3044
|
+
...promptCacheBreakpoint != null && {
|
|
3045
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3046
|
+
}
|
|
3047
|
+
};
|
|
3048
|
+
}
|
|
3049
|
+
case "image-url": {
|
|
3050
|
+
return {
|
|
3051
|
+
type: "input_image",
|
|
3052
|
+
image_url: item.url,
|
|
3053
|
+
detail: (_d = (_c = item.providerOptions) == null ? void 0 : _c[providerOptionsName]) == null ? void 0 : _d.imageDetail,
|
|
3054
|
+
...promptCacheBreakpoint != null && {
|
|
3055
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3056
|
+
}
|
|
3057
|
+
};
|
|
3058
|
+
}
|
|
3059
|
+
case "file-data": {
|
|
3060
|
+
return {
|
|
3061
|
+
type: "input_file",
|
|
3062
|
+
filename: (_e = item.filename) != null ? _e : "data",
|
|
3063
|
+
file_data: `data:${item.mediaType};base64,${item.data}`,
|
|
3064
|
+
...promptCacheBreakpoint != null && {
|
|
3065
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3066
|
+
}
|
|
3067
|
+
};
|
|
3068
|
+
}
|
|
3069
|
+
case "file-url": {
|
|
3070
|
+
return {
|
|
3071
|
+
type: "input_file",
|
|
3072
|
+
file_url: item.url,
|
|
3073
|
+
...promptCacheBreakpoint != null && {
|
|
3074
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3075
|
+
}
|
|
3076
|
+
};
|
|
3077
|
+
}
|
|
3078
|
+
default: {
|
|
3079
|
+
warnings.push({
|
|
3080
|
+
type: "other",
|
|
3081
|
+
message: `unsupported tool content part type: ${item.type}`
|
|
3082
|
+
});
|
|
3083
|
+
return void 0;
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
}).filter(import_provider_utils25.isNonNullable);
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3089
|
+
function hasSameParallelToolCall(first, second) {
|
|
3090
|
+
return first.itemId === second.itemId && first.toolCallId === second.toolCallId && first.toolName === second.toolName && first.input === second.input && first.count === second.count;
|
|
3091
|
+
}
|
|
3092
|
+
function collectCompleteParallelToolResultGroups({
|
|
3093
|
+
prompt,
|
|
3094
|
+
providerOptionsName
|
|
3095
|
+
}) {
|
|
3096
|
+
const pendingGroups = /* @__PURE__ */ new Map();
|
|
3097
|
+
for (const message of prompt) {
|
|
3098
|
+
if (message.role !== "tool") {
|
|
3099
|
+
continue;
|
|
3100
|
+
}
|
|
3101
|
+
for (const part of message.content) {
|
|
3102
|
+
if (part.type !== "tool-result") {
|
|
3103
|
+
continue;
|
|
3104
|
+
}
|
|
3105
|
+
const metadata = getParallelToolCallMetadata({
|
|
3106
|
+
providerOptions: part.providerOptions,
|
|
3107
|
+
providerOptionsName
|
|
3108
|
+
});
|
|
3109
|
+
if (metadata == null) {
|
|
3110
|
+
continue;
|
|
3111
|
+
}
|
|
3112
|
+
const existing = pendingGroups.get(metadata.toolCallId);
|
|
3113
|
+
if (existing == null) {
|
|
3114
|
+
pendingGroups.set(metadata.toolCallId, {
|
|
3115
|
+
metadata,
|
|
3116
|
+
results: /* @__PURE__ */ new Map([[metadata.index, part]]),
|
|
3117
|
+
invalid: false
|
|
3118
|
+
});
|
|
3119
|
+
continue;
|
|
3120
|
+
}
|
|
3121
|
+
if (!hasSameParallelToolCall(existing.metadata, metadata) || existing.results.has(metadata.index)) {
|
|
3122
|
+
existing.invalid = true;
|
|
3123
|
+
continue;
|
|
3124
|
+
}
|
|
3125
|
+
existing.results.set(metadata.index, part);
|
|
3126
|
+
}
|
|
3127
|
+
}
|
|
3128
|
+
const completeGroups = /* @__PURE__ */ new Map();
|
|
3129
|
+
for (const [toolCallId, group] of pendingGroups) {
|
|
3130
|
+
if (group.invalid || group.results.size !== group.metadata.count) {
|
|
3131
|
+
continue;
|
|
3132
|
+
}
|
|
3133
|
+
const results = Array.from(
|
|
3134
|
+
{ length: group.metadata.count },
|
|
3135
|
+
(_, index) => group.results.get(index)
|
|
3136
|
+
);
|
|
3137
|
+
if (results.every(import_provider_utils25.isNonNullable)) {
|
|
3138
|
+
completeGroups.set(toolCallId, {
|
|
3139
|
+
metadata: group.metadata,
|
|
3140
|
+
results
|
|
3141
|
+
});
|
|
3142
|
+
}
|
|
3143
|
+
}
|
|
3144
|
+
return completeGroups;
|
|
3145
|
+
}
|
|
2931
3146
|
function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
|
|
2932
3147
|
var _a;
|
|
2933
3148
|
return (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.promptCacheBreakpoint;
|
|
@@ -2951,10 +3166,16 @@ async function convertToOpenAIResponsesInput({
|
|
|
2951
3166
|
hasApplyPatchTool = false,
|
|
2952
3167
|
customProviderToolNames
|
|
2953
3168
|
}) {
|
|
2954
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y
|
|
3169
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
2955
3170
|
let input = [];
|
|
2956
3171
|
const warnings = [];
|
|
2957
3172
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
3173
|
+
const parallelToolResultGroups = hasConversation || hasPreviousResponseId ? collectCompleteParallelToolResultGroups({
|
|
3174
|
+
prompt,
|
|
3175
|
+
providerOptionsName
|
|
3176
|
+
}) : /* @__PURE__ */ new Map();
|
|
3177
|
+
const emittedParallelToolCalls = /* @__PURE__ */ new Set();
|
|
3178
|
+
const emittedParallelToolResults = /* @__PURE__ */ new Set();
|
|
2958
3179
|
for (const { role, content, providerOptions } of prompt) {
|
|
2959
3180
|
switch (role) {
|
|
2960
3181
|
case "system": {
|
|
@@ -3038,7 +3259,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3038
3259
|
return {
|
|
3039
3260
|
type: "input_image",
|
|
3040
3261
|
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
3041
|
-
image_url: `data:${mediaType};base64,${(0,
|
|
3262
|
+
image_url: `data:${mediaType};base64,${(0, import_provider_utils25.convertToBase64)(part.data)}`
|
|
3042
3263
|
},
|
|
3043
3264
|
detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
3044
3265
|
...promptCacheBreakpoint != null && {
|
|
@@ -3056,7 +3277,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3056
3277
|
};
|
|
3057
3278
|
}
|
|
3058
3279
|
if (mediaType !== "application/pdf" && !passThroughUnsupportedFiles) {
|
|
3059
|
-
throw new
|
|
3280
|
+
throw new import_provider8.UnsupportedFunctionalityError({
|
|
3060
3281
|
functionality: `file part media type ${mediaType}`
|
|
3061
3282
|
});
|
|
3062
3283
|
}
|
|
@@ -3064,7 +3285,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3064
3285
|
type: "input_file",
|
|
3065
3286
|
...typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
3066
3287
|
filename: (_c2 = part.filename) != null ? _c2 : mediaType === "application/pdf" ? `part-${index}.pdf` : `part-${index}`,
|
|
3067
|
-
file_data: `data:${mediaType};base64,${(0,
|
|
3288
|
+
file_data: `data:${mediaType};base64,${(0, import_provider_utils25.convertToBase64)(part.data)}`
|
|
3068
3289
|
},
|
|
3069
3290
|
...promptCacheBreakpoint != null && {
|
|
3070
3291
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
@@ -3100,6 +3321,34 @@ async function convertToOpenAIResponsesInput({
|
|
|
3100
3321
|
break;
|
|
3101
3322
|
}
|
|
3102
3323
|
case "tool-call": {
|
|
3324
|
+
const parallelToolCallMetadata = getParallelToolCallMetadata({
|
|
3325
|
+
providerOptions: part.providerOptions,
|
|
3326
|
+
providerOptionsName
|
|
3327
|
+
});
|
|
3328
|
+
const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
|
|
3329
|
+
parallelToolCallMetadata.toolCallId
|
|
3330
|
+
);
|
|
3331
|
+
if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
|
|
3332
|
+
parallelToolResultGroup.metadata,
|
|
3333
|
+
parallelToolCallMetadata
|
|
3334
|
+
)) {
|
|
3335
|
+
if (!emittedParallelToolCalls.has(
|
|
3336
|
+
parallelToolResultGroup.metadata.toolCallId
|
|
3337
|
+
)) {
|
|
3338
|
+
emittedParallelToolCalls.add(
|
|
3339
|
+
parallelToolResultGroup.metadata.toolCallId
|
|
3340
|
+
);
|
|
3341
|
+
if (!hasConversation) {
|
|
3342
|
+
input.push({
|
|
3343
|
+
type: "function_call",
|
|
3344
|
+
call_id: parallelToolResultGroup.metadata.toolCallId,
|
|
3345
|
+
name: parallelToolResultGroup.metadata.toolName,
|
|
3346
|
+
arguments: parallelToolResultGroup.metadata.input
|
|
3347
|
+
});
|
|
3348
|
+
}
|
|
3349
|
+
}
|
|
3350
|
+
break;
|
|
3351
|
+
}
|
|
3103
3352
|
const id = (_f = (_c = (_b = part.providerOptions) == null ? void 0 : _b[providerOptionsName]) == null ? void 0 : _c.itemId) != null ? _f : (_e = (_d = part.providerMetadata) == null ? void 0 : _d[providerOptionsName]) == null ? void 0 : _e.itemId;
|
|
3104
3353
|
const namespace = (_k = (_h = (_g = part.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.namespace) != null ? _k : (_j = (_i = part.providerMetadata) == null ? void 0 : _i[providerOptionsName]) == null ? void 0 : _j.namespace;
|
|
3105
3354
|
if (hasConversation && id != null) {
|
|
@@ -3113,10 +3362,10 @@ async function convertToOpenAIResponsesInput({
|
|
|
3113
3362
|
input.push({ type: "item_reference", id });
|
|
3114
3363
|
break;
|
|
3115
3364
|
}
|
|
3116
|
-
const parsedInput = typeof part.input === "string" ? await (0,
|
|
3365
|
+
const parsedInput = typeof part.input === "string" ? await (0, import_provider_utils25.parseJSON)({
|
|
3117
3366
|
text: part.input,
|
|
3118
3367
|
schema: toolSearchInputSchema
|
|
3119
|
-
}) : await (0,
|
|
3368
|
+
}) : await (0, import_provider_utils25.validateTypes)({
|
|
3120
3369
|
value: part.input,
|
|
3121
3370
|
schema: toolSearchInputSchema
|
|
3122
3371
|
});
|
|
@@ -3148,7 +3397,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3148
3397
|
break;
|
|
3149
3398
|
}
|
|
3150
3399
|
if (hasLocalShellTool && resolvedToolName === "local_shell") {
|
|
3151
|
-
const parsedInput = await (0,
|
|
3400
|
+
const parsedInput = await (0, import_provider_utils25.validateTypes)({
|
|
3152
3401
|
value: part.input,
|
|
3153
3402
|
schema: localShellInputSchema
|
|
3154
3403
|
});
|
|
@@ -3168,7 +3417,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3168
3417
|
break;
|
|
3169
3418
|
}
|
|
3170
3419
|
if (hasShellTool && resolvedToolName === "shell") {
|
|
3171
|
-
const parsedInput = await (0,
|
|
3420
|
+
const parsedInput = await (0, import_provider_utils25.validateTypes)({
|
|
3172
3421
|
value: part.input,
|
|
3173
3422
|
schema: shellInputSchema
|
|
3174
3423
|
});
|
|
@@ -3186,7 +3435,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3186
3435
|
break;
|
|
3187
3436
|
}
|
|
3188
3437
|
if (hasApplyPatchTool && resolvedToolName === "apply_patch") {
|
|
3189
|
-
const parsedInput = await (0,
|
|
3438
|
+
const parsedInput = await (0, import_provider_utils25.validateTypes)({
|
|
3190
3439
|
value: part.input,
|
|
3191
3440
|
schema: applyPatchInputSchema
|
|
3192
3441
|
});
|
|
@@ -3234,7 +3483,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3234
3483
|
if (store) {
|
|
3235
3484
|
input.push({ type: "item_reference", id: itemId });
|
|
3236
3485
|
} else if (part.output.type === "json") {
|
|
3237
|
-
const parsedOutput = await (0,
|
|
3486
|
+
const parsedOutput = await (0, import_provider_utils25.validateTypes)({
|
|
3238
3487
|
value: part.output.value,
|
|
3239
3488
|
schema: toolSearchOutputSchema
|
|
3240
3489
|
});
|
|
@@ -3251,7 +3500,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3251
3500
|
}
|
|
3252
3501
|
if (hasShellTool && resolvedResultToolName === "shell") {
|
|
3253
3502
|
if (part.output.type === "json") {
|
|
3254
|
-
const parsedOutput = await (0,
|
|
3503
|
+
const parsedOutput = await (0, import_provider_utils25.validateTypes)({
|
|
3255
3504
|
value: part.output.value,
|
|
3256
3505
|
schema: shellOutputSchema
|
|
3257
3506
|
});
|
|
@@ -3282,7 +3531,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3282
3531
|
break;
|
|
3283
3532
|
}
|
|
3284
3533
|
case "reasoning": {
|
|
3285
|
-
const providerOptions2 = await (0,
|
|
3534
|
+
const providerOptions2 = await (0, import_provider_utils25.parseProviderOptions)({
|
|
3286
3535
|
provider: providerOptionsName,
|
|
3287
3536
|
providerOptions: part.providerOptions,
|
|
3288
3537
|
schema: openaiResponsesReasoningProviderOptionsSchema
|
|
@@ -3379,6 +3628,44 @@ async function convertToOpenAIResponsesInput({
|
|
|
3379
3628
|
});
|
|
3380
3629
|
continue;
|
|
3381
3630
|
}
|
|
3631
|
+
const parallelToolCallMetadata = getParallelToolCallMetadata({
|
|
3632
|
+
providerOptions: part.providerOptions,
|
|
3633
|
+
providerOptionsName
|
|
3634
|
+
});
|
|
3635
|
+
const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
|
|
3636
|
+
parallelToolCallMetadata.toolCallId
|
|
3637
|
+
);
|
|
3638
|
+
if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
|
|
3639
|
+
parallelToolResultGroup.metadata,
|
|
3640
|
+
parallelToolCallMetadata
|
|
3641
|
+
)) {
|
|
3642
|
+
if (!emittedParallelToolResults.has(
|
|
3643
|
+
parallelToolResultGroup.metadata.toolCallId
|
|
3644
|
+
)) {
|
|
3645
|
+
emittedParallelToolResults.add(
|
|
3646
|
+
parallelToolResultGroup.metadata.toolCallId
|
|
3647
|
+
);
|
|
3648
|
+
const toolOutputs = await Promise.all(
|
|
3649
|
+
parallelToolResultGroup.results.map(
|
|
3650
|
+
async (result) => convertFunctionToolResultOutput({
|
|
3651
|
+
output: result.output,
|
|
3652
|
+
providerOptionsName,
|
|
3653
|
+
warnings
|
|
3654
|
+
})
|
|
3655
|
+
)
|
|
3656
|
+
);
|
|
3657
|
+
input.push({
|
|
3658
|
+
type: "function_call_output",
|
|
3659
|
+
call_id: parallelToolResultGroup.metadata.toolCallId,
|
|
3660
|
+
// The internal wrapper returns one output containing the child
|
|
3661
|
+
// results in the same order as the original tool_uses array.
|
|
3662
|
+
output: toolOutputs.map(
|
|
3663
|
+
(output2) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
|
|
3664
|
+
).join("\n")
|
|
3665
|
+
});
|
|
3666
|
+
}
|
|
3667
|
+
continue;
|
|
3668
|
+
}
|
|
3382
3669
|
const output = part.output;
|
|
3383
3670
|
if (output.type === "execution-denied") {
|
|
3384
3671
|
const approvalId = (_x = (_w = output.providerOptions) == null ? void 0 : _w.openai) == null ? void 0 : _x.approvalId;
|
|
@@ -3390,7 +3677,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3390
3677
|
part.toolName
|
|
3391
3678
|
);
|
|
3392
3679
|
if (resolvedToolName === "tool_search" && output.type === "json") {
|
|
3393
|
-
const parsedOutput = await (0,
|
|
3680
|
+
const parsedOutput = await (0, import_provider_utils25.validateTypes)({
|
|
3394
3681
|
value: output.value,
|
|
3395
3682
|
schema: toolSearchOutputSchema
|
|
3396
3683
|
});
|
|
@@ -3404,7 +3691,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3404
3691
|
continue;
|
|
3405
3692
|
}
|
|
3406
3693
|
if (hasLocalShellTool && resolvedToolName === "local_shell" && output.type === "json") {
|
|
3407
|
-
const parsedOutput = await (0,
|
|
3694
|
+
const parsedOutput = await (0, import_provider_utils25.validateTypes)({
|
|
3408
3695
|
value: output.value,
|
|
3409
3696
|
schema: localShellOutputSchema
|
|
3410
3697
|
});
|
|
@@ -3416,7 +3703,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3416
3703
|
continue;
|
|
3417
3704
|
}
|
|
3418
3705
|
if (hasShellTool && resolvedToolName === "shell" && output.type === "json") {
|
|
3419
|
-
const parsedOutput = await (0,
|
|
3706
|
+
const parsedOutput = await (0, import_provider_utils25.validateTypes)({
|
|
3420
3707
|
value: output.value,
|
|
3421
3708
|
schema: shellOutputSchema
|
|
3422
3709
|
});
|
|
@@ -3435,7 +3722,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3435
3722
|
continue;
|
|
3436
3723
|
}
|
|
3437
3724
|
if (hasApplyPatchTool && part.toolName === "apply_patch" && output.type === "json") {
|
|
3438
|
-
const parsedOutput = await (0,
|
|
3725
|
+
const parsedOutput = await (0, import_provider_utils25.validateTypes)({
|
|
3439
3726
|
value: output.value,
|
|
3440
3727
|
schema: applyPatchOutputSchema
|
|
3441
3728
|
});
|
|
@@ -3519,7 +3806,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3519
3806
|
});
|
|
3520
3807
|
return void 0;
|
|
3521
3808
|
}
|
|
3522
|
-
}).filter(
|
|
3809
|
+
}).filter(import_provider_utils25.isNonNullable);
|
|
3523
3810
|
break;
|
|
3524
3811
|
default:
|
|
3525
3812
|
outputValue = "";
|
|
@@ -3531,86 +3818,11 @@ async function convertToOpenAIResponsesInput({
|
|
|
3531
3818
|
});
|
|
3532
3819
|
continue;
|
|
3533
3820
|
}
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
break;
|
|
3540
|
-
case "execution-denied":
|
|
3541
|
-
contentValue = (_z = output.reason) != null ? _z : "Tool call execution denied.";
|
|
3542
|
-
break;
|
|
3543
|
-
case "json":
|
|
3544
|
-
case "error-json":
|
|
3545
|
-
contentValue = JSON.stringify(output.value);
|
|
3546
|
-
break;
|
|
3547
|
-
case "content":
|
|
3548
|
-
contentValue = output.value.map((item) => {
|
|
3549
|
-
var _a2, _b2, _c2, _d2, _e2;
|
|
3550
|
-
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
3551
|
-
item.providerOptions,
|
|
3552
|
-
providerOptionsName
|
|
3553
|
-
);
|
|
3554
|
-
switch (item.type) {
|
|
3555
|
-
case "text": {
|
|
3556
|
-
return {
|
|
3557
|
-
type: "input_text",
|
|
3558
|
-
text: item.text,
|
|
3559
|
-
...promptCacheBreakpoint != null && {
|
|
3560
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3561
|
-
}
|
|
3562
|
-
};
|
|
3563
|
-
}
|
|
3564
|
-
case "image-data": {
|
|
3565
|
-
return {
|
|
3566
|
-
type: "input_image",
|
|
3567
|
-
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3568
|
-
detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
3569
|
-
...promptCacheBreakpoint != null && {
|
|
3570
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3571
|
-
}
|
|
3572
|
-
};
|
|
3573
|
-
}
|
|
3574
|
-
case "image-url": {
|
|
3575
|
-
return {
|
|
3576
|
-
type: "input_image",
|
|
3577
|
-
image_url: item.url,
|
|
3578
|
-
detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
|
|
3579
|
-
...promptCacheBreakpoint != null && {
|
|
3580
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3581
|
-
}
|
|
3582
|
-
};
|
|
3583
|
-
}
|
|
3584
|
-
case "file-data": {
|
|
3585
|
-
return {
|
|
3586
|
-
type: "input_file",
|
|
3587
|
-
filename: (_e2 = item.filename) != null ? _e2 : "data",
|
|
3588
|
-
file_data: `data:${item.mediaType};base64,${item.data}`,
|
|
3589
|
-
...promptCacheBreakpoint != null && {
|
|
3590
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3591
|
-
}
|
|
3592
|
-
};
|
|
3593
|
-
}
|
|
3594
|
-
case "file-url": {
|
|
3595
|
-
return {
|
|
3596
|
-
type: "input_file",
|
|
3597
|
-
file_url: item.url,
|
|
3598
|
-
...promptCacheBreakpoint != null && {
|
|
3599
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3600
|
-
}
|
|
3601
|
-
};
|
|
3602
|
-
}
|
|
3603
|
-
default: {
|
|
3604
|
-
warnings.push({
|
|
3605
|
-
type: "other",
|
|
3606
|
-
message: `unsupported tool content part type: ${item.type}`
|
|
3607
|
-
});
|
|
3608
|
-
return void 0;
|
|
3609
|
-
}
|
|
3610
|
-
}
|
|
3611
|
-
}).filter(import_provider_utils24.isNonNullable);
|
|
3612
|
-
break;
|
|
3613
|
-
}
|
|
3821
|
+
const contentValue = await convertFunctionToolResultOutput({
|
|
3822
|
+
output,
|
|
3823
|
+
providerOptionsName,
|
|
3824
|
+
warnings
|
|
3825
|
+
});
|
|
3614
3826
|
input.push({
|
|
3615
3827
|
type: "function_call_output",
|
|
3616
3828
|
call_id: part.toolCallId,
|
|
@@ -3662,7 +3874,7 @@ function mapOpenAIResponseFinishReason({
|
|
|
3662
3874
|
}
|
|
3663
3875
|
|
|
3664
3876
|
// src/responses/openai-responses-api.ts
|
|
3665
|
-
var
|
|
3877
|
+
var import_provider_utils26 = require("@ai-sdk/provider-utils");
|
|
3666
3878
|
var import_v418 = require("zod/v4");
|
|
3667
3879
|
var jsonValueSchema = import_v418.z.lazy(
|
|
3668
3880
|
() => import_v418.z.union([
|
|
@@ -3691,8 +3903,8 @@ var openaiResponsesErrorChunkSchema = import_v418.z.object({
|
|
|
3691
3903
|
message: import_v418.z.string(),
|
|
3692
3904
|
param: import_v418.z.string().nullish()
|
|
3693
3905
|
});
|
|
3694
|
-
var openaiResponsesChunkSchema = (0,
|
|
3695
|
-
() => (0,
|
|
3906
|
+
var openaiResponsesChunkSchema = (0, import_provider_utils26.lazySchema)(
|
|
3907
|
+
() => (0, import_provider_utils26.zodSchema)(
|
|
3696
3908
|
import_v418.z.union([
|
|
3697
3909
|
import_v418.z.object({
|
|
3698
3910
|
type: import_v418.z.literal("response.output_text.delta"),
|
|
@@ -4240,8 +4452,8 @@ var openaiResponsesChunkSchema = (0, import_provider_utils25.lazySchema)(
|
|
|
4240
4452
|
])
|
|
4241
4453
|
)
|
|
4242
4454
|
);
|
|
4243
|
-
var openaiResponsesResponseSchema = (0,
|
|
4244
|
-
() => (0,
|
|
4455
|
+
var openaiResponsesResponseSchema = (0, import_provider_utils26.lazySchema)(
|
|
4456
|
+
() => (0, import_provider_utils26.zodSchema)(
|
|
4245
4457
|
import_v418.z.object({
|
|
4246
4458
|
id: import_v418.z.string().optional(),
|
|
4247
4459
|
created_at: import_v418.z.number().optional(),
|
|
@@ -4555,7 +4767,7 @@ var openaiResponsesResponseSchema = (0, import_provider_utils25.lazySchema)(
|
|
|
4555
4767
|
);
|
|
4556
4768
|
|
|
4557
4769
|
// src/responses/openai-responses-options.ts
|
|
4558
|
-
var
|
|
4770
|
+
var import_provider_utils27 = require("@ai-sdk/provider-utils");
|
|
4559
4771
|
var import_v419 = require("zod/v4");
|
|
4560
4772
|
var TOP_LOGPROBS_MAX = 20;
|
|
4561
4773
|
var openaiResponsesReasoningModelIds = [
|
|
@@ -4627,8 +4839,8 @@ var openaiResponsesModelIds = [
|
|
|
4627
4839
|
"gpt-5-chat-latest",
|
|
4628
4840
|
...openaiResponsesReasoningModelIds
|
|
4629
4841
|
];
|
|
4630
|
-
var openaiLanguageModelResponsesOptionsSchema = (0,
|
|
4631
|
-
() => (0,
|
|
4842
|
+
var openaiLanguageModelResponsesOptionsSchema = (0, import_provider_utils27.lazySchema)(
|
|
4843
|
+
() => (0, import_provider_utils27.zodSchema)(
|
|
4632
4844
|
import_v419.z.object({
|
|
4633
4845
|
/**
|
|
4634
4846
|
* The ID of the OpenAI Conversation to continue.
|
|
@@ -4825,22 +5037,22 @@ var openaiLanguageModelResponsesOptionsSchema = (0, import_provider_utils26.lazy
|
|
|
4825
5037
|
);
|
|
4826
5038
|
|
|
4827
5039
|
// src/responses/openai-responses-prepare-tools.ts
|
|
4828
|
-
var
|
|
4829
|
-
var
|
|
5040
|
+
var import_provider9 = require("@ai-sdk/provider");
|
|
5041
|
+
var import_provider_utils35 = require("@ai-sdk/provider-utils");
|
|
4830
5042
|
|
|
4831
5043
|
// src/tool/code-interpreter.ts
|
|
4832
|
-
var
|
|
5044
|
+
var import_provider_utils28 = require("@ai-sdk/provider-utils");
|
|
4833
5045
|
var import_v420 = require("zod/v4");
|
|
4834
|
-
var codeInterpreterInputSchema = (0,
|
|
4835
|
-
() => (0,
|
|
5046
|
+
var codeInterpreterInputSchema = (0, import_provider_utils28.lazySchema)(
|
|
5047
|
+
() => (0, import_provider_utils28.zodSchema)(
|
|
4836
5048
|
import_v420.z.object({
|
|
4837
5049
|
code: import_v420.z.string().nullish(),
|
|
4838
5050
|
containerId: import_v420.z.string()
|
|
4839
5051
|
})
|
|
4840
5052
|
)
|
|
4841
5053
|
);
|
|
4842
|
-
var codeInterpreterOutputSchema = (0,
|
|
4843
|
-
() => (0,
|
|
5054
|
+
var codeInterpreterOutputSchema = (0, import_provider_utils28.lazySchema)(
|
|
5055
|
+
() => (0, import_provider_utils28.zodSchema)(
|
|
4844
5056
|
import_v420.z.object({
|
|
4845
5057
|
outputs: import_v420.z.array(
|
|
4846
5058
|
import_v420.z.discriminatedUnion("type", [
|
|
@@ -4851,8 +5063,8 @@ var codeInterpreterOutputSchema = (0, import_provider_utils27.lazySchema)(
|
|
|
4851
5063
|
})
|
|
4852
5064
|
)
|
|
4853
5065
|
);
|
|
4854
|
-
var codeInterpreterArgsSchema = (0,
|
|
4855
|
-
() => (0,
|
|
5066
|
+
var codeInterpreterArgsSchema = (0, import_provider_utils28.lazySchema)(
|
|
5067
|
+
() => (0, import_provider_utils28.zodSchema)(
|
|
4856
5068
|
import_v420.z.object({
|
|
4857
5069
|
container: import_v420.z.union([
|
|
4858
5070
|
import_v420.z.string(),
|
|
@@ -4863,7 +5075,7 @@ var codeInterpreterArgsSchema = (0, import_provider_utils27.lazySchema)(
|
|
|
4863
5075
|
})
|
|
4864
5076
|
)
|
|
4865
5077
|
);
|
|
4866
|
-
var codeInterpreterToolFactory = (0,
|
|
5078
|
+
var codeInterpreterToolFactory = (0, import_provider_utils28.createProviderToolFactoryWithOutputSchema)({
|
|
4867
5079
|
id: "openai.code_interpreter",
|
|
4868
5080
|
inputSchema: codeInterpreterInputSchema,
|
|
4869
5081
|
outputSchema: codeInterpreterOutputSchema
|
|
@@ -4873,7 +5085,7 @@ var codeInterpreter = (args = {}) => {
|
|
|
4873
5085
|
};
|
|
4874
5086
|
|
|
4875
5087
|
// src/tool/file-search.ts
|
|
4876
|
-
var
|
|
5088
|
+
var import_provider_utils29 = require("@ai-sdk/provider-utils");
|
|
4877
5089
|
var import_v421 = require("zod/v4");
|
|
4878
5090
|
var comparisonFilterSchema = import_v421.z.object({
|
|
4879
5091
|
key: import_v421.z.string(),
|
|
@@ -4886,8 +5098,8 @@ var compoundFilterSchema = import_v421.z.object({
|
|
|
4886
5098
|
import_v421.z.union([comparisonFilterSchema, import_v421.z.lazy(() => compoundFilterSchema)])
|
|
4887
5099
|
)
|
|
4888
5100
|
});
|
|
4889
|
-
var fileSearchArgsSchema = (0,
|
|
4890
|
-
() => (0,
|
|
5101
|
+
var fileSearchArgsSchema = (0, import_provider_utils29.lazySchema)(
|
|
5102
|
+
() => (0, import_provider_utils29.zodSchema)(
|
|
4891
5103
|
import_v421.z.object({
|
|
4892
5104
|
vectorStoreIds: import_v421.z.array(import_v421.z.string()),
|
|
4893
5105
|
maxNumResults: import_v421.z.number().optional(),
|
|
@@ -4899,8 +5111,8 @@ var fileSearchArgsSchema = (0, import_provider_utils28.lazySchema)(
|
|
|
4899
5111
|
})
|
|
4900
5112
|
)
|
|
4901
5113
|
);
|
|
4902
|
-
var fileSearchOutputSchema = (0,
|
|
4903
|
-
() => (0,
|
|
5114
|
+
var fileSearchOutputSchema = (0, import_provider_utils29.lazySchema)(
|
|
5115
|
+
() => (0, import_provider_utils29.zodSchema)(
|
|
4904
5116
|
import_v421.z.object({
|
|
4905
5117
|
queries: import_v421.z.array(import_v421.z.string()),
|
|
4906
5118
|
results: import_v421.z.array(
|
|
@@ -4915,17 +5127,17 @@ var fileSearchOutputSchema = (0, import_provider_utils28.lazySchema)(
|
|
|
4915
5127
|
})
|
|
4916
5128
|
)
|
|
4917
5129
|
);
|
|
4918
|
-
var fileSearch = (0,
|
|
5130
|
+
var fileSearch = (0, import_provider_utils29.createProviderToolFactoryWithOutputSchema)({
|
|
4919
5131
|
id: "openai.file_search",
|
|
4920
5132
|
inputSchema: import_v421.z.object({}),
|
|
4921
5133
|
outputSchema: fileSearchOutputSchema
|
|
4922
5134
|
});
|
|
4923
5135
|
|
|
4924
5136
|
// src/tool/image-generation.ts
|
|
4925
|
-
var
|
|
5137
|
+
var import_provider_utils30 = require("@ai-sdk/provider-utils");
|
|
4926
5138
|
var import_v422 = require("zod/v4");
|
|
4927
|
-
var imageGenerationArgsSchema = (0,
|
|
4928
|
-
() => (0,
|
|
5139
|
+
var imageGenerationArgsSchema = (0, import_provider_utils30.lazySchema)(
|
|
5140
|
+
() => (0, import_provider_utils30.zodSchema)(
|
|
4929
5141
|
import_v422.z.object({
|
|
4930
5142
|
background: import_v422.z.enum(["auto", "opaque", "transparent"]).optional(),
|
|
4931
5143
|
inputFidelity: import_v422.z.enum(["low", "high"]).optional(),
|
|
@@ -4943,11 +5155,11 @@ var imageGenerationArgsSchema = (0, import_provider_utils29.lazySchema)(
|
|
|
4943
5155
|
}).strict()
|
|
4944
5156
|
)
|
|
4945
5157
|
);
|
|
4946
|
-
var imageGenerationInputSchema = (0,
|
|
4947
|
-
var imageGenerationOutputSchema = (0,
|
|
4948
|
-
() => (0,
|
|
5158
|
+
var imageGenerationInputSchema = (0, import_provider_utils30.lazySchema)(() => (0, import_provider_utils30.zodSchema)(import_v422.z.object({})));
|
|
5159
|
+
var imageGenerationOutputSchema = (0, import_provider_utils30.lazySchema)(
|
|
5160
|
+
() => (0, import_provider_utils30.zodSchema)(import_v422.z.object({ result: import_v422.z.string() }))
|
|
4949
5161
|
);
|
|
4950
|
-
var imageGenerationToolFactory = (0,
|
|
5162
|
+
var imageGenerationToolFactory = (0, import_provider_utils30.createProviderToolFactoryWithOutputSchema)({
|
|
4951
5163
|
id: "openai.image_generation",
|
|
4952
5164
|
inputSchema: imageGenerationInputSchema,
|
|
4953
5165
|
outputSchema: imageGenerationOutputSchema
|
|
@@ -4957,10 +5169,10 @@ var imageGeneration = (args = {}) => {
|
|
|
4957
5169
|
};
|
|
4958
5170
|
|
|
4959
5171
|
// src/tool/custom.ts
|
|
4960
|
-
var
|
|
5172
|
+
var import_provider_utils31 = require("@ai-sdk/provider-utils");
|
|
4961
5173
|
var import_v423 = require("zod/v4");
|
|
4962
|
-
var customArgsSchema = (0,
|
|
4963
|
-
() => (0,
|
|
5174
|
+
var customArgsSchema = (0, import_provider_utils31.lazySchema)(
|
|
5175
|
+
() => (0, import_provider_utils31.zodSchema)(
|
|
4964
5176
|
import_v423.z.object({
|
|
4965
5177
|
name: import_v423.z.string(),
|
|
4966
5178
|
description: import_v423.z.string().optional(),
|
|
@@ -4977,14 +5189,14 @@ var customArgsSchema = (0, import_provider_utils30.lazySchema)(
|
|
|
4977
5189
|
})
|
|
4978
5190
|
)
|
|
4979
5191
|
);
|
|
4980
|
-
var customInputSchema = (0,
|
|
4981
|
-
var customToolFactory = (0,
|
|
5192
|
+
var customInputSchema = (0, import_provider_utils31.lazySchema)(() => (0, import_provider_utils31.zodSchema)(import_v423.z.string()));
|
|
5193
|
+
var customToolFactory = (0, import_provider_utils31.createProviderToolFactory)({
|
|
4982
5194
|
id: "openai.custom",
|
|
4983
5195
|
inputSchema: customInputSchema
|
|
4984
5196
|
});
|
|
4985
5197
|
|
|
4986
5198
|
// src/tool/mcp.ts
|
|
4987
|
-
var
|
|
5199
|
+
var import_provider_utils32 = require("@ai-sdk/provider-utils");
|
|
4988
5200
|
var import_v424 = require("zod/v4");
|
|
4989
5201
|
var jsonValueSchema2 = import_v424.z.lazy(
|
|
4990
5202
|
() => import_v424.z.union([
|
|
@@ -4996,8 +5208,8 @@ var jsonValueSchema2 = import_v424.z.lazy(
|
|
|
4996
5208
|
import_v424.z.record(import_v424.z.string(), jsonValueSchema2)
|
|
4997
5209
|
])
|
|
4998
5210
|
);
|
|
4999
|
-
var mcpArgsSchema = (0,
|
|
5000
|
-
() => (0,
|
|
5211
|
+
var mcpArgsSchema = (0, import_provider_utils32.lazySchema)(
|
|
5212
|
+
() => (0, import_provider_utils32.zodSchema)(
|
|
5001
5213
|
import_v424.z.object({
|
|
5002
5214
|
serverLabel: import_v424.z.string(),
|
|
5003
5215
|
allowedTools: import_v424.z.union([
|
|
@@ -5026,9 +5238,9 @@ var mcpArgsSchema = (0, import_provider_utils31.lazySchema)(
|
|
|
5026
5238
|
)
|
|
5027
5239
|
)
|
|
5028
5240
|
);
|
|
5029
|
-
var mcpInputSchema = (0,
|
|
5030
|
-
var mcpOutputSchema = (0,
|
|
5031
|
-
() => (0,
|
|
5241
|
+
var mcpInputSchema = (0, import_provider_utils32.lazySchema)(() => (0, import_provider_utils32.zodSchema)(import_v424.z.object({})));
|
|
5242
|
+
var mcpOutputSchema = (0, import_provider_utils32.lazySchema)(
|
|
5243
|
+
() => (0, import_provider_utils32.zodSchema)(
|
|
5032
5244
|
import_v424.z.object({
|
|
5033
5245
|
type: import_v424.z.literal("call"),
|
|
5034
5246
|
serverLabel: import_v424.z.string(),
|
|
@@ -5039,17 +5251,17 @@ var mcpOutputSchema = (0, import_provider_utils31.lazySchema)(
|
|
|
5039
5251
|
})
|
|
5040
5252
|
)
|
|
5041
5253
|
);
|
|
5042
|
-
var mcpToolFactory = (0,
|
|
5254
|
+
var mcpToolFactory = (0, import_provider_utils32.createProviderToolFactoryWithOutputSchema)({
|
|
5043
5255
|
id: "openai.mcp",
|
|
5044
5256
|
inputSchema: mcpInputSchema,
|
|
5045
5257
|
outputSchema: mcpOutputSchema
|
|
5046
5258
|
});
|
|
5047
5259
|
|
|
5048
5260
|
// src/tool/web-search.ts
|
|
5049
|
-
var
|
|
5261
|
+
var import_provider_utils33 = require("@ai-sdk/provider-utils");
|
|
5050
5262
|
var import_v425 = require("zod/v4");
|
|
5051
|
-
var webSearchArgsSchema = (0,
|
|
5052
|
-
() => (0,
|
|
5263
|
+
var webSearchArgsSchema = (0, import_provider_utils33.lazySchema)(
|
|
5264
|
+
() => (0, import_provider_utils33.zodSchema)(
|
|
5053
5265
|
import_v425.z.object({
|
|
5054
5266
|
externalWebAccess: import_v425.z.boolean().optional(),
|
|
5055
5267
|
filters: import_v425.z.object({
|
|
@@ -5067,9 +5279,9 @@ var webSearchArgsSchema = (0, import_provider_utils32.lazySchema)(
|
|
|
5067
5279
|
})
|
|
5068
5280
|
)
|
|
5069
5281
|
);
|
|
5070
|
-
var webSearchInputSchema = (0,
|
|
5071
|
-
var webSearchOutputSchema = (0,
|
|
5072
|
-
() => (0,
|
|
5282
|
+
var webSearchInputSchema = (0, import_provider_utils33.lazySchema)(() => (0, import_provider_utils33.zodSchema)(import_v425.z.object({})));
|
|
5283
|
+
var webSearchOutputSchema = (0, import_provider_utils33.lazySchema)(
|
|
5284
|
+
() => (0, import_provider_utils33.zodSchema)(
|
|
5073
5285
|
import_v425.z.object({
|
|
5074
5286
|
action: import_v425.z.discriminatedUnion("type", [
|
|
5075
5287
|
import_v425.z.object({
|
|
@@ -5096,7 +5308,7 @@ var webSearchOutputSchema = (0, import_provider_utils32.lazySchema)(
|
|
|
5096
5308
|
})
|
|
5097
5309
|
)
|
|
5098
5310
|
);
|
|
5099
|
-
var webSearchToolFactory = (0,
|
|
5311
|
+
var webSearchToolFactory = (0, import_provider_utils33.createProviderToolFactoryWithOutputSchema)({
|
|
5100
5312
|
id: "openai.web_search",
|
|
5101
5313
|
inputSchema: webSearchInputSchema,
|
|
5102
5314
|
outputSchema: webSearchOutputSchema
|
|
@@ -5104,10 +5316,10 @@ var webSearchToolFactory = (0, import_provider_utils32.createProviderToolFactory
|
|
|
5104
5316
|
var webSearch = (args = {}) => webSearchToolFactory(args);
|
|
5105
5317
|
|
|
5106
5318
|
// src/tool/web-search-preview.ts
|
|
5107
|
-
var
|
|
5319
|
+
var import_provider_utils34 = require("@ai-sdk/provider-utils");
|
|
5108
5320
|
var import_v426 = require("zod/v4");
|
|
5109
|
-
var webSearchPreviewArgsSchema = (0,
|
|
5110
|
-
() => (0,
|
|
5321
|
+
var webSearchPreviewArgsSchema = (0, import_provider_utils34.lazySchema)(
|
|
5322
|
+
() => (0, import_provider_utils34.zodSchema)(
|
|
5111
5323
|
import_v426.z.object({
|
|
5112
5324
|
searchContextSize: import_v426.z.enum(["low", "medium", "high"]).optional(),
|
|
5113
5325
|
userLocation: import_v426.z.object({
|
|
@@ -5120,11 +5332,11 @@ var webSearchPreviewArgsSchema = (0, import_provider_utils33.lazySchema)(
|
|
|
5120
5332
|
})
|
|
5121
5333
|
)
|
|
5122
5334
|
);
|
|
5123
|
-
var webSearchPreviewInputSchema = (0,
|
|
5124
|
-
() => (0,
|
|
5335
|
+
var webSearchPreviewInputSchema = (0, import_provider_utils34.lazySchema)(
|
|
5336
|
+
() => (0, import_provider_utils34.zodSchema)(import_v426.z.object({}))
|
|
5125
5337
|
);
|
|
5126
|
-
var webSearchPreviewOutputSchema = (0,
|
|
5127
|
-
() => (0,
|
|
5338
|
+
var webSearchPreviewOutputSchema = (0, import_provider_utils34.lazySchema)(
|
|
5339
|
+
() => (0, import_provider_utils34.zodSchema)(
|
|
5128
5340
|
import_v426.z.object({
|
|
5129
5341
|
action: import_v426.z.discriminatedUnion("type", [
|
|
5130
5342
|
import_v426.z.object({
|
|
@@ -5144,7 +5356,7 @@ var webSearchPreviewOutputSchema = (0, import_provider_utils33.lazySchema)(
|
|
|
5144
5356
|
})
|
|
5145
5357
|
)
|
|
5146
5358
|
);
|
|
5147
|
-
var webSearchPreview = (0,
|
|
5359
|
+
var webSearchPreview = (0, import_provider_utils34.createProviderToolFactoryWithOutputSchema)({
|
|
5148
5360
|
id: "openai.web_search_preview",
|
|
5149
5361
|
inputSchema: webSearchPreviewInputSchema,
|
|
5150
5362
|
outputSchema: webSearchPreviewOutputSchema
|
|
@@ -5158,7 +5370,7 @@ async function prepareResponsesTools({
|
|
|
5158
5370
|
toolNameMapping,
|
|
5159
5371
|
customProviderToolNames
|
|
5160
5372
|
}) {
|
|
5161
|
-
var _a, _b, _c;
|
|
5373
|
+
var _a, _b, _c, _d;
|
|
5162
5374
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
5163
5375
|
const toolWarnings = [];
|
|
5164
5376
|
if (tools == null) {
|
|
@@ -5167,6 +5379,20 @@ async function prepareResponsesTools({
|
|
|
5167
5379
|
const openaiTools = [];
|
|
5168
5380
|
const namespaceTools = /* @__PURE__ */ new Map();
|
|
5169
5381
|
const resolvedCustomProviderToolNames = customProviderToolNames != null ? customProviderToolNames : /* @__PURE__ */ new Set();
|
|
5382
|
+
const allowedToolResolutions = /* @__PURE__ */ new Map();
|
|
5383
|
+
const allowedToolAliases = /* @__PURE__ */ new Map();
|
|
5384
|
+
const recordAllowedTool = (toolName, resolution, canonicalName) => {
|
|
5385
|
+
allowedToolResolutions.set(toolName, resolution);
|
|
5386
|
+
if (canonicalName == null || canonicalName === toolName) {
|
|
5387
|
+
return;
|
|
5388
|
+
}
|
|
5389
|
+
const existingAlias = allowedToolAliases.get(canonicalName);
|
|
5390
|
+
if (existingAlias == null) {
|
|
5391
|
+
allowedToolAliases.set(canonicalName, resolution);
|
|
5392
|
+
} else if (existingAlias !== "ambiguous" && !isSameAllowedTool(existingAlias, resolution)) {
|
|
5393
|
+
allowedToolAliases.set(canonicalName, "ambiguous");
|
|
5394
|
+
}
|
|
5395
|
+
};
|
|
5170
5396
|
for (const tool of tools) {
|
|
5171
5397
|
switch (tool.type) {
|
|
5172
5398
|
case "function": {
|
|
@@ -5190,18 +5416,33 @@ async function prepareResponsesTools({
|
|
|
5190
5416
|
namespaceTools.set(namespace.name, namespaceTool);
|
|
5191
5417
|
openaiTools.push(namespaceTool);
|
|
5192
5418
|
} else if (namespaceTool.description !== namespace.description) {
|
|
5193
|
-
throw new
|
|
5419
|
+
throw new import_provider9.UnsupportedFunctionalityError({
|
|
5194
5420
|
functionality: `conflicting descriptions for OpenAI tool namespace "${namespace.name}"`
|
|
5195
5421
|
});
|
|
5196
5422
|
}
|
|
5197
5423
|
namespaceTool.tools.push(openaiFunctionTool);
|
|
5198
5424
|
}
|
|
5425
|
+
recordAllowedTool(
|
|
5426
|
+
tool.name,
|
|
5427
|
+
namespace != null ? {
|
|
5428
|
+
supported: false,
|
|
5429
|
+
reason: "tools inside an OpenAI tool namespace are not visible to tool_choice.allowed_tools"
|
|
5430
|
+
} : (openaiOptions == null ? void 0 : openaiOptions.deferLoading) === true ? {
|
|
5431
|
+
supported: false,
|
|
5432
|
+
reason: "deferred tools are not visible to tool_choice.allowed_tools"
|
|
5433
|
+
} : {
|
|
5434
|
+
supported: true,
|
|
5435
|
+
entry: { type: "function", name: tool.name }
|
|
5436
|
+
},
|
|
5437
|
+
void 0
|
|
5438
|
+
);
|
|
5199
5439
|
break;
|
|
5200
5440
|
}
|
|
5201
5441
|
case "provider": {
|
|
5442
|
+
const openaiToolCountBefore = openaiTools.length;
|
|
5202
5443
|
switch (tool.id) {
|
|
5203
5444
|
case "openai.file_search": {
|
|
5204
|
-
const args = await (0,
|
|
5445
|
+
const args = await (0, import_provider_utils35.validateTypes)({
|
|
5205
5446
|
value: tool.args,
|
|
5206
5447
|
schema: fileSearchArgsSchema
|
|
5207
5448
|
});
|
|
@@ -5224,7 +5465,7 @@ async function prepareResponsesTools({
|
|
|
5224
5465
|
break;
|
|
5225
5466
|
}
|
|
5226
5467
|
case "openai.shell": {
|
|
5227
|
-
const args = await (0,
|
|
5468
|
+
const args = await (0, import_provider_utils35.validateTypes)({
|
|
5228
5469
|
value: tool.args,
|
|
5229
5470
|
schema: shellArgsSchema
|
|
5230
5471
|
});
|
|
@@ -5243,7 +5484,7 @@ async function prepareResponsesTools({
|
|
|
5243
5484
|
break;
|
|
5244
5485
|
}
|
|
5245
5486
|
case "openai.web_search_preview": {
|
|
5246
|
-
const args = await (0,
|
|
5487
|
+
const args = await (0, import_provider_utils35.validateTypes)({
|
|
5247
5488
|
value: tool.args,
|
|
5248
5489
|
schema: webSearchPreviewArgsSchema
|
|
5249
5490
|
});
|
|
@@ -5255,7 +5496,7 @@ async function prepareResponsesTools({
|
|
|
5255
5496
|
break;
|
|
5256
5497
|
}
|
|
5257
5498
|
case "openai.web_search": {
|
|
5258
|
-
const args = await (0,
|
|
5499
|
+
const args = await (0, import_provider_utils35.validateTypes)({
|
|
5259
5500
|
value: tool.args,
|
|
5260
5501
|
schema: webSearchArgsSchema
|
|
5261
5502
|
});
|
|
@@ -5272,7 +5513,7 @@ async function prepareResponsesTools({
|
|
|
5272
5513
|
break;
|
|
5273
5514
|
}
|
|
5274
5515
|
case "openai.code_interpreter": {
|
|
5275
|
-
const args = await (0,
|
|
5516
|
+
const args = await (0, import_provider_utils35.validateTypes)({
|
|
5276
5517
|
value: tool.args,
|
|
5277
5518
|
schema: codeInterpreterArgsSchema
|
|
5278
5519
|
});
|
|
@@ -5283,7 +5524,7 @@ async function prepareResponsesTools({
|
|
|
5283
5524
|
break;
|
|
5284
5525
|
}
|
|
5285
5526
|
case "openai.image_generation": {
|
|
5286
|
-
const args = await (0,
|
|
5527
|
+
const args = await (0, import_provider_utils35.validateTypes)({
|
|
5287
5528
|
value: tool.args,
|
|
5288
5529
|
schema: imageGenerationArgsSchema
|
|
5289
5530
|
});
|
|
@@ -5306,7 +5547,7 @@ async function prepareResponsesTools({
|
|
|
5306
5547
|
break;
|
|
5307
5548
|
}
|
|
5308
5549
|
case "openai.mcp": {
|
|
5309
|
-
const args = await (0,
|
|
5550
|
+
const args = await (0, import_provider_utils35.validateTypes)({
|
|
5310
5551
|
value: tool.args,
|
|
5311
5552
|
schema: mcpArgsSchema
|
|
5312
5553
|
});
|
|
@@ -5332,7 +5573,7 @@ async function prepareResponsesTools({
|
|
|
5332
5573
|
break;
|
|
5333
5574
|
}
|
|
5334
5575
|
case "openai.custom": {
|
|
5335
|
-
const args = await (0,
|
|
5576
|
+
const args = await (0, import_provider_utils35.validateTypes)({
|
|
5336
5577
|
value: tool.args,
|
|
5337
5578
|
schema: customArgsSchema
|
|
5338
5579
|
});
|
|
@@ -5346,7 +5587,7 @@ async function prepareResponsesTools({
|
|
|
5346
5587
|
break;
|
|
5347
5588
|
}
|
|
5348
5589
|
case "openai.tool_search": {
|
|
5349
|
-
const args = await (0,
|
|
5590
|
+
const args = await (0, import_provider_utils35.validateTypes)({
|
|
5350
5591
|
value: tool.args,
|
|
5351
5592
|
schema: toolSearchArgsSchema
|
|
5352
5593
|
});
|
|
@@ -5359,6 +5600,14 @@ async function prepareResponsesTools({
|
|
|
5359
5600
|
break;
|
|
5360
5601
|
}
|
|
5361
5602
|
}
|
|
5603
|
+
if (openaiTools.length > openaiToolCountBefore) {
|
|
5604
|
+
const openaiTool = openaiTools[openaiToolCountBefore];
|
|
5605
|
+
recordAllowedTool(
|
|
5606
|
+
tool.name,
|
|
5607
|
+
toAllowedToolResolution(openaiTool),
|
|
5608
|
+
toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(tool.name)
|
|
5609
|
+
);
|
|
5610
|
+
}
|
|
5362
5611
|
break;
|
|
5363
5612
|
}
|
|
5364
5613
|
default:
|
|
@@ -5370,18 +5619,63 @@ async function prepareResponsesTools({
|
|
|
5370
5619
|
}
|
|
5371
5620
|
}
|
|
5372
5621
|
if (allowedTools != null) {
|
|
5622
|
+
const allowedToolEntries = [];
|
|
5623
|
+
const droppedToolNames = [];
|
|
5624
|
+
for (const name of allowedTools.toolNames) {
|
|
5625
|
+
const directResolution = allowedToolResolutions.get(name);
|
|
5626
|
+
const resolution = directResolution != null ? directResolution : allowedToolAliases.get(name);
|
|
5627
|
+
if (directResolution != null && allowedToolAliases.has(name)) {
|
|
5628
|
+
toolWarnings.push({
|
|
5629
|
+
type: "unsupported",
|
|
5630
|
+
feature: `allowedTools entry "${name}"`,
|
|
5631
|
+
details: "this name is both a tool name and the provider tool name of another tool in this request; the tool with this name is allowed"
|
|
5632
|
+
});
|
|
5633
|
+
}
|
|
5634
|
+
if (resolution === "ambiguous") {
|
|
5635
|
+
toolWarnings.push({
|
|
5636
|
+
type: "unsupported",
|
|
5637
|
+
feature: `allowedTools entry "${name}"`,
|
|
5638
|
+
details: "several tools in this request share this provider tool name; use the tool name from the tools for this request instead"
|
|
5639
|
+
});
|
|
5640
|
+
droppedToolNames.push(name);
|
|
5641
|
+
continue;
|
|
5642
|
+
}
|
|
5643
|
+
if (resolution == null) {
|
|
5644
|
+
toolWarnings.push({
|
|
5645
|
+
type: "unsupported",
|
|
5646
|
+
feature: `allowedTools entry "${name}"`,
|
|
5647
|
+
details: "the tool is not part of the tools for this request and is sent as a function tool"
|
|
5648
|
+
});
|
|
5649
|
+
allowedToolEntries.push({
|
|
5650
|
+
type: "function",
|
|
5651
|
+
name: (_b = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(name)) != null ? _b : name
|
|
5652
|
+
});
|
|
5653
|
+
continue;
|
|
5654
|
+
}
|
|
5655
|
+
if (!resolution.supported) {
|
|
5656
|
+
toolWarnings.push({
|
|
5657
|
+
type: "unsupported",
|
|
5658
|
+
feature: `allowedTools entry "${name}"`,
|
|
5659
|
+
details: `${resolution.reason}; the tool is removed from the allowed tools`
|
|
5660
|
+
});
|
|
5661
|
+
droppedToolNames.push(name);
|
|
5662
|
+
continue;
|
|
5663
|
+
}
|
|
5664
|
+
allowedToolEntries.push(resolution.entry);
|
|
5665
|
+
}
|
|
5666
|
+
if (allowedToolEntries.length === 0) {
|
|
5667
|
+
throw new import_provider9.UnsupportedFunctionalityError({
|
|
5668
|
+
functionality: `allowedTools with only tools that cannot be allow-listed (${droppedToolNames.join(
|
|
5669
|
+
", "
|
|
5670
|
+
)})`
|
|
5671
|
+
});
|
|
5672
|
+
}
|
|
5373
5673
|
return {
|
|
5374
5674
|
tools: openaiTools,
|
|
5375
5675
|
toolChoice: {
|
|
5376
5676
|
type: "allowed_tools",
|
|
5377
|
-
mode: (
|
|
5378
|
-
tools:
|
|
5379
|
-
var _a2;
|
|
5380
|
-
return {
|
|
5381
|
-
type: "function",
|
|
5382
|
-
name: (_a2 = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(name)) != null ? _a2 : name
|
|
5383
|
-
};
|
|
5384
|
-
})
|
|
5677
|
+
mode: (_c = allowedTools.mode) != null ? _c : "auto",
|
|
5678
|
+
tools: allowedToolEntries
|
|
5385
5679
|
},
|
|
5386
5680
|
toolWarnings
|
|
5387
5681
|
};
|
|
@@ -5396,7 +5690,7 @@ async function prepareResponsesTools({
|
|
|
5396
5690
|
case "required":
|
|
5397
5691
|
return { tools: openaiTools, toolChoice: type, toolWarnings };
|
|
5398
5692
|
case "tool": {
|
|
5399
|
-
const resolvedToolName = (
|
|
5693
|
+
const resolvedToolName = (_d = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _d : toolChoice.toolName;
|
|
5400
5694
|
return {
|
|
5401
5695
|
tools: openaiTools,
|
|
5402
5696
|
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 },
|
|
@@ -5405,12 +5699,57 @@ async function prepareResponsesTools({
|
|
|
5405
5699
|
}
|
|
5406
5700
|
default: {
|
|
5407
5701
|
const _exhaustiveCheck = type;
|
|
5408
|
-
throw new
|
|
5702
|
+
throw new import_provider9.UnsupportedFunctionalityError({
|
|
5409
5703
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
5410
5704
|
});
|
|
5411
5705
|
}
|
|
5412
5706
|
}
|
|
5413
5707
|
}
|
|
5708
|
+
function allowedToolKey(entry) {
|
|
5709
|
+
switch (entry.type) {
|
|
5710
|
+
case "mcp":
|
|
5711
|
+
return `mcp:${entry.server_label}`;
|
|
5712
|
+
case "function":
|
|
5713
|
+
case "custom":
|
|
5714
|
+
return `${entry.type}:${entry.name}`;
|
|
5715
|
+
default:
|
|
5716
|
+
return entry.type;
|
|
5717
|
+
}
|
|
5718
|
+
}
|
|
5719
|
+
function isSameAllowedTool(a, b) {
|
|
5720
|
+
if (a.supported && b.supported) {
|
|
5721
|
+
return allowedToolKey(a.entry) === allowedToolKey(b.entry);
|
|
5722
|
+
}
|
|
5723
|
+
if (!a.supported && !b.supported) {
|
|
5724
|
+
return a.reason === b.reason;
|
|
5725
|
+
}
|
|
5726
|
+
return false;
|
|
5727
|
+
}
|
|
5728
|
+
function toAllowedToolResolution(tool) {
|
|
5729
|
+
switch (tool.type) {
|
|
5730
|
+
case "custom":
|
|
5731
|
+
return { supported: true, entry: { type: "custom", name: tool.name } };
|
|
5732
|
+
case "mcp":
|
|
5733
|
+
return {
|
|
5734
|
+
supported: true,
|
|
5735
|
+
entry: { type: "mcp", server_label: tool.server_label }
|
|
5736
|
+
};
|
|
5737
|
+
case "file_search":
|
|
5738
|
+
case "web_search":
|
|
5739
|
+
case "web_search_preview":
|
|
5740
|
+
case "image_generation":
|
|
5741
|
+
case "code_interpreter":
|
|
5742
|
+
case "apply_patch":
|
|
5743
|
+
case "shell":
|
|
5744
|
+
case "local_shell":
|
|
5745
|
+
return { supported: true, entry: { type: tool.type } };
|
|
5746
|
+
default:
|
|
5747
|
+
return {
|
|
5748
|
+
supported: false,
|
|
5749
|
+
reason: `OpenAI does not support ${tool.type} tools in tool_choice.allowed_tools`
|
|
5750
|
+
};
|
|
5751
|
+
}
|
|
5752
|
+
}
|
|
5414
5753
|
function prepareFunctionTool({
|
|
5415
5754
|
tool,
|
|
5416
5755
|
options
|
|
@@ -5535,13 +5874,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5535
5874
|
warnings.push({ type: "unsupported", feature: "stopSequences" });
|
|
5536
5875
|
}
|
|
5537
5876
|
const providerOptionsName = this.config.provider.includes("azure") ? "azure" : "openai";
|
|
5538
|
-
let openaiOptions = await (0,
|
|
5877
|
+
let openaiOptions = await (0, import_provider_utils36.parseProviderOptions)({
|
|
5539
5878
|
provider: providerOptionsName,
|
|
5540
5879
|
providerOptions,
|
|
5541
5880
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
5542
5881
|
});
|
|
5543
5882
|
if (openaiOptions == null && providerOptionsName !== "openai") {
|
|
5544
|
-
openaiOptions = await (0,
|
|
5883
|
+
openaiOptions = await (0, import_provider_utils36.parseProviderOptions)({
|
|
5545
5884
|
provider: "openai",
|
|
5546
5885
|
providerOptions,
|
|
5547
5886
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
@@ -5555,7 +5894,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5555
5894
|
details: "conversation and previousResponseId cannot be used together"
|
|
5556
5895
|
});
|
|
5557
5896
|
}
|
|
5558
|
-
const toolNameMapping = (0,
|
|
5897
|
+
const toolNameMapping = (0, import_provider_utils36.createToolNameMapping)({
|
|
5559
5898
|
tools,
|
|
5560
5899
|
providerToolNames: {
|
|
5561
5900
|
"openai.code_interpreter": "code_interpreter",
|
|
@@ -5769,7 +6108,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5769
6108
|
};
|
|
5770
6109
|
}
|
|
5771
6110
|
async doGenerate(options) {
|
|
5772
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C;
|
|
6111
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E;
|
|
5773
6112
|
const {
|
|
5774
6113
|
args: body,
|
|
5775
6114
|
warnings,
|
|
@@ -5787,19 +6126,19 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5787
6126
|
responseHeaders,
|
|
5788
6127
|
value: response,
|
|
5789
6128
|
rawValue: rawResponse
|
|
5790
|
-
} = await (0,
|
|
6129
|
+
} = await (0, import_provider_utils36.postJsonToApi)({
|
|
5791
6130
|
url,
|
|
5792
|
-
headers: (0,
|
|
6131
|
+
headers: (0, import_provider_utils36.combineHeaders)(this.config.headers(), options.headers),
|
|
5793
6132
|
body,
|
|
5794
6133
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
5795
|
-
successfulResponseHandler: (0,
|
|
6134
|
+
successfulResponseHandler: (0, import_provider_utils36.createJsonResponseHandler)(
|
|
5796
6135
|
openaiResponsesResponseSchema
|
|
5797
6136
|
),
|
|
5798
6137
|
abortSignal: options.abortSignal,
|
|
5799
6138
|
fetch: this.config.fetch
|
|
5800
6139
|
});
|
|
5801
6140
|
if (response.error) {
|
|
5802
|
-
throw new
|
|
6141
|
+
throw new import_provider10.APICallError({
|
|
5803
6142
|
message: response.error.message,
|
|
5804
6143
|
url,
|
|
5805
6144
|
requestBodyValues: body,
|
|
@@ -5811,6 +6150,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5811
6150
|
}
|
|
5812
6151
|
const content = [];
|
|
5813
6152
|
const logprobs = [];
|
|
6153
|
+
const functionTools = (_b = (_a = options.tools) == null ? void 0 : _a.filter(
|
|
6154
|
+
(tool) => tool.type === "function"
|
|
6155
|
+
)) != null ? _b : [];
|
|
5814
6156
|
let hasFunctionCall = false;
|
|
5815
6157
|
const hostedToolSearchCallIds = [];
|
|
5816
6158
|
for (const part of response.output) {
|
|
@@ -5826,7 +6168,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5826
6168
|
providerMetadata: {
|
|
5827
6169
|
[providerOptionsName]: {
|
|
5828
6170
|
itemId: part.id,
|
|
5829
|
-
reasoningEncryptedContent: (
|
|
6171
|
+
reasoningEncryptedContent: (_c = part.encrypted_content) != null ? _c : null
|
|
5830
6172
|
}
|
|
5831
6173
|
}
|
|
5832
6174
|
});
|
|
@@ -5852,7 +6194,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5852
6194
|
break;
|
|
5853
6195
|
}
|
|
5854
6196
|
case "tool_search_call": {
|
|
5855
|
-
const toolCallId = (
|
|
6197
|
+
const toolCallId = (_d = part.call_id) != null ? _d : part.id;
|
|
5856
6198
|
const isHosted = part.execution === "server";
|
|
5857
6199
|
if (isHosted) {
|
|
5858
6200
|
hostedToolSearchCallIds.push(toolCallId);
|
|
@@ -5875,7 +6217,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5875
6217
|
break;
|
|
5876
6218
|
}
|
|
5877
6219
|
case "tool_search_output": {
|
|
5878
|
-
const toolCallId = (
|
|
6220
|
+
const toolCallId = (_f = (_e = part.call_id) != null ? _e : hostedToolSearchCallIds.shift()) != null ? _f : part.id;
|
|
5879
6221
|
content.push({
|
|
5880
6222
|
type: "tool-result",
|
|
5881
6223
|
toolCallId,
|
|
@@ -5946,7 +6288,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5946
6288
|
}
|
|
5947
6289
|
case "message": {
|
|
5948
6290
|
for (const contentPart of part.content) {
|
|
5949
|
-
if (((
|
|
6291
|
+
if (((_h = (_g = options.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.logprobs) && contentPart.logprobs) {
|
|
5950
6292
|
logprobs.push(contentPart.logprobs);
|
|
5951
6293
|
}
|
|
5952
6294
|
const providerMetadata2 = {
|
|
@@ -5968,7 +6310,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5968
6310
|
content.push({
|
|
5969
6311
|
type: "source",
|
|
5970
6312
|
sourceType: "url",
|
|
5971
|
-
id: (
|
|
6313
|
+
id: (_k = (_j = (_i = this.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : (0, import_provider_utils36.generateId)(),
|
|
5972
6314
|
url: annotation.url,
|
|
5973
6315
|
title: annotation.title
|
|
5974
6316
|
});
|
|
@@ -5976,7 +6318,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5976
6318
|
content.push({
|
|
5977
6319
|
type: "source",
|
|
5978
6320
|
sourceType: "document",
|
|
5979
|
-
id: (
|
|
6321
|
+
id: (_n = (_m = (_l = this.config).generateId) == null ? void 0 : _m.call(_l)) != null ? _n : (0, import_provider_utils36.generateId)(),
|
|
5980
6322
|
mediaType: "text/plain",
|
|
5981
6323
|
title: annotation.filename,
|
|
5982
6324
|
filename: annotation.filename,
|
|
@@ -5992,7 +6334,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5992
6334
|
content.push({
|
|
5993
6335
|
type: "source",
|
|
5994
6336
|
sourceType: "document",
|
|
5995
|
-
id: (
|
|
6337
|
+
id: (_q = (_p = (_o = this.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : (0, import_provider_utils36.generateId)(),
|
|
5996
6338
|
mediaType: "text/plain",
|
|
5997
6339
|
title: annotation.filename,
|
|
5998
6340
|
filename: annotation.filename,
|
|
@@ -6008,7 +6350,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6008
6350
|
content.push({
|
|
6009
6351
|
type: "source",
|
|
6010
6352
|
sourceType: "document",
|
|
6011
|
-
id: (
|
|
6353
|
+
id: (_t = (_s = (_r = this.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : (0, import_provider_utils36.generateId)(),
|
|
6012
6354
|
mediaType: "application/octet-stream",
|
|
6013
6355
|
title: annotation.file_id,
|
|
6014
6356
|
filename: annotation.file_id,
|
|
@@ -6027,6 +6369,20 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6027
6369
|
}
|
|
6028
6370
|
case "function_call": {
|
|
6029
6371
|
hasFunctionCall = true;
|
|
6372
|
+
const expandedToolCalls = await expandParallelToolCall({
|
|
6373
|
+
toolCall: {
|
|
6374
|
+
toolCallId: part.call_id,
|
|
6375
|
+
toolName: part.name,
|
|
6376
|
+
input: part.arguments
|
|
6377
|
+
},
|
|
6378
|
+
tools: functionTools,
|
|
6379
|
+
providerOptionsName,
|
|
6380
|
+
itemId: part.id
|
|
6381
|
+
});
|
|
6382
|
+
if (expandedToolCalls != null) {
|
|
6383
|
+
content.push(...expandedToolCalls);
|
|
6384
|
+
break;
|
|
6385
|
+
}
|
|
6030
6386
|
content.push({
|
|
6031
6387
|
type: "tool-call",
|
|
6032
6388
|
toolCallId: part.call_id,
|
|
@@ -6078,7 +6434,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6078
6434
|
break;
|
|
6079
6435
|
}
|
|
6080
6436
|
case "mcp_call": {
|
|
6081
|
-
const toolCallId = part.approval_request_id != null ? (
|
|
6437
|
+
const toolCallId = part.approval_request_id != null ? (_u = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _u : part.id : part.id;
|
|
6082
6438
|
const toolName = `mcp.${part.name}`;
|
|
6083
6439
|
content.push({
|
|
6084
6440
|
type: "tool-call",
|
|
@@ -6112,8 +6468,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6112
6468
|
break;
|
|
6113
6469
|
}
|
|
6114
6470
|
case "mcp_approval_request": {
|
|
6115
|
-
const approvalRequestId = (
|
|
6116
|
-
const dummyToolCallId = (
|
|
6471
|
+
const approvalRequestId = (_v = part.approval_request_id) != null ? _v : part.id;
|
|
6472
|
+
const dummyToolCallId = (_y = (_x = (_w = this.config).generateId) == null ? void 0 : _x.call(_w)) != null ? _y : (0, import_provider_utils36.generateId)();
|
|
6117
6473
|
const toolName = `mcp.${part.name}`;
|
|
6118
6474
|
content.push({
|
|
6119
6475
|
type: "tool-call",
|
|
@@ -6163,13 +6519,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6163
6519
|
toolName: toolNameMapping.toCustomToolName("file_search"),
|
|
6164
6520
|
result: {
|
|
6165
6521
|
queries: part.queries,
|
|
6166
|
-
results: (
|
|
6522
|
+
results: (_A = (_z = part.results) == null ? void 0 : _z.map((result) => ({
|
|
6167
6523
|
attributes: result.attributes,
|
|
6168
6524
|
fileId: result.file_id,
|
|
6169
6525
|
filename: result.filename,
|
|
6170
6526
|
score: result.score,
|
|
6171
6527
|
text: result.text
|
|
6172
|
-
}))) != null ?
|
|
6528
|
+
}))) != null ? _A : null
|
|
6173
6529
|
}
|
|
6174
6530
|
});
|
|
6175
6531
|
break;
|
|
@@ -6219,7 +6575,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6219
6575
|
responseId: response.id,
|
|
6220
6576
|
...logprobs.length > 0 ? { logprobs } : {},
|
|
6221
6577
|
...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
|
|
6222
|
-
...((
|
|
6578
|
+
...((_B = response.reasoning) == null ? void 0 : _B.context) != null ? { reasoningContext: response.reasoning.context } : {}
|
|
6223
6579
|
}
|
|
6224
6580
|
};
|
|
6225
6581
|
const usage = response.usage;
|
|
@@ -6227,10 +6583,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6227
6583
|
content,
|
|
6228
6584
|
finishReason: {
|
|
6229
6585
|
unified: mapOpenAIResponseFinishReason({
|
|
6230
|
-
finishReason: (
|
|
6586
|
+
finishReason: (_C = response.incomplete_details) == null ? void 0 : _C.reason,
|
|
6231
6587
|
hasFunctionCall
|
|
6232
6588
|
}),
|
|
6233
|
-
raw: (
|
|
6589
|
+
raw: (_E = (_D = response.incomplete_details) == null ? void 0 : _D.reason) != null ? _E : void 0
|
|
6234
6590
|
},
|
|
6235
6591
|
usage: convertOpenAIResponsesUsage(usage),
|
|
6236
6592
|
request: { body },
|
|
@@ -6246,6 +6602,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6246
6602
|
};
|
|
6247
6603
|
}
|
|
6248
6604
|
async doStream(options) {
|
|
6605
|
+
var _a, _b;
|
|
6249
6606
|
const {
|
|
6250
6607
|
args: body,
|
|
6251
6608
|
warnings,
|
|
@@ -6259,15 +6616,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6259
6616
|
path: "/responses",
|
|
6260
6617
|
modelId: this.modelId
|
|
6261
6618
|
});
|
|
6262
|
-
const { responseHeaders, value: response } = await (0,
|
|
6619
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils36.postJsonToApi)({
|
|
6263
6620
|
url,
|
|
6264
|
-
headers: (0,
|
|
6621
|
+
headers: (0, import_provider_utils36.combineHeaders)(this.config.headers(), options.headers),
|
|
6265
6622
|
body: {
|
|
6266
6623
|
...body,
|
|
6267
6624
|
stream: true
|
|
6268
6625
|
},
|
|
6269
6626
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
6270
|
-
successfulResponseHandler: (0,
|
|
6627
|
+
successfulResponseHandler: (0, import_provider_utils36.createEventSourceResponseHandler)(
|
|
6271
6628
|
openaiResponsesChunkSchema
|
|
6272
6629
|
),
|
|
6273
6630
|
abortSignal: options.abortSignal,
|
|
@@ -6283,6 +6640,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6283
6640
|
});
|
|
6284
6641
|
const self = this;
|
|
6285
6642
|
const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
|
|
6643
|
+
const functionTools = (_b = (_a = options.tools) == null ? void 0 : _a.filter(
|
|
6644
|
+
(tool) => tool.type === "function"
|
|
6645
|
+
)) != null ? _b : [];
|
|
6286
6646
|
const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
|
|
6287
6647
|
let finishReason = {
|
|
6288
6648
|
unified: "other",
|
|
@@ -6307,7 +6667,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6307
6667
|
controller.enqueue({ type: "stream-start", warnings });
|
|
6308
6668
|
},
|
|
6309
6669
|
transform(chunk, controller) {
|
|
6310
|
-
var
|
|
6670
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P;
|
|
6311
6671
|
if (options.includeRawChunks) {
|
|
6312
6672
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
6313
6673
|
}
|
|
@@ -6326,15 +6686,23 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6326
6686
|
const value = chunk.value;
|
|
6327
6687
|
if (isResponseOutputItemAddedChunk(value)) {
|
|
6328
6688
|
if (value.item.type === "function_call") {
|
|
6689
|
+
const suppressInputStreaming = isUndeclaredParallelToolCall({
|
|
6690
|
+
toolName: value.item.name,
|
|
6691
|
+
tools: functionTools
|
|
6692
|
+
});
|
|
6329
6693
|
ongoingToolCalls[value.output_index] = {
|
|
6330
6694
|
toolName: value.item.name,
|
|
6331
|
-
toolCallId: value.item.call_id
|
|
6695
|
+
toolCallId: value.item.call_id,
|
|
6696
|
+
suppressInputStreaming,
|
|
6697
|
+
bufferedInputDeltas: suppressInputStreaming ? [] : void 0
|
|
6332
6698
|
};
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
|
|
6699
|
+
if (!suppressInputStreaming) {
|
|
6700
|
+
controller.enqueue({
|
|
6701
|
+
type: "tool-input-start",
|
|
6702
|
+
id: value.item.call_id,
|
|
6703
|
+
toolName: value.item.name
|
|
6704
|
+
});
|
|
6705
|
+
}
|
|
6338
6706
|
} else if (value.item.type === "custom_tool_call") {
|
|
6339
6707
|
const toolName = toolNameMapping.toCustomToolName(
|
|
6340
6708
|
value.item.name
|
|
@@ -6429,7 +6797,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6429
6797
|
ongoingToolCalls[value.output_index] = {
|
|
6430
6798
|
toolName,
|
|
6431
6799
|
toolCallId,
|
|
6432
|
-
toolSearchExecution: (
|
|
6800
|
+
toolSearchExecution: (_a2 = value.item.execution) != null ? _a2 : "server"
|
|
6433
6801
|
};
|
|
6434
6802
|
if (isHosted) {
|
|
6435
6803
|
controller.enqueue({
|
|
@@ -6486,7 +6854,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6486
6854
|
} else if (value.item.type === "shell_call_output") {
|
|
6487
6855
|
} else if (value.item.type === "message") {
|
|
6488
6856
|
ongoingAnnotations.splice(0, ongoingAnnotations.length);
|
|
6489
|
-
activeMessagePhase = (
|
|
6857
|
+
activeMessagePhase = (_b2 = value.item.phase) != null ? _b2 : void 0;
|
|
6490
6858
|
controller.enqueue({
|
|
6491
6859
|
type: "text-start",
|
|
6492
6860
|
id: value.item.id,
|
|
@@ -6533,31 +6901,99 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6533
6901
|
}
|
|
6534
6902
|
});
|
|
6535
6903
|
} else if (value.item.type === "function_call") {
|
|
6904
|
+
const item = value.item;
|
|
6905
|
+
const ongoingToolCall = ongoingToolCalls[value.output_index];
|
|
6536
6906
|
ongoingToolCalls[value.output_index] = void 0;
|
|
6537
6907
|
hasFunctionCall = true;
|
|
6538
|
-
|
|
6539
|
-
|
|
6540
|
-
|
|
6541
|
-
|
|
6542
|
-
|
|
6543
|
-
|
|
6544
|
-
|
|
6908
|
+
const suppressInputStreaming = (_e = ongoingToolCall == null ? void 0 : ongoingToolCall.suppressInputStreaming) != null ? _e : isUndeclaredParallelToolCall({
|
|
6909
|
+
toolName: item.name,
|
|
6910
|
+
tools: functionTools
|
|
6911
|
+
});
|
|
6912
|
+
const enqueueUnexpandedToolCall = () => {
|
|
6913
|
+
var _a3;
|
|
6914
|
+
if (suppressInputStreaming) {
|
|
6915
|
+
controller.enqueue({
|
|
6916
|
+
type: "tool-input-start",
|
|
6917
|
+
id: item.call_id,
|
|
6918
|
+
toolName: item.name
|
|
6919
|
+
});
|
|
6920
|
+
const bufferedInputDeltas = (_a3 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a3 : [];
|
|
6921
|
+
if (bufferedInputDeltas.length > 0) {
|
|
6922
|
+
for (const delta of bufferedInputDeltas) {
|
|
6923
|
+
controller.enqueue({
|
|
6924
|
+
type: "tool-input-delta",
|
|
6925
|
+
id: item.call_id,
|
|
6926
|
+
delta
|
|
6927
|
+
});
|
|
6545
6928
|
}
|
|
6929
|
+
} else if (item.arguments.length > 0) {
|
|
6930
|
+
controller.enqueue({
|
|
6931
|
+
type: "tool-input-delta",
|
|
6932
|
+
id: item.call_id,
|
|
6933
|
+
delta: item.arguments
|
|
6934
|
+
});
|
|
6546
6935
|
}
|
|
6547
6936
|
}
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
|
|
6551
|
-
|
|
6552
|
-
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6937
|
+
controller.enqueue({
|
|
6938
|
+
type: "tool-input-end",
|
|
6939
|
+
id: item.call_id,
|
|
6940
|
+
...item.namespace != null && {
|
|
6941
|
+
providerMetadata: {
|
|
6942
|
+
[providerOptionsName]: {
|
|
6943
|
+
namespace: item.namespace
|
|
6944
|
+
}
|
|
6945
|
+
}
|
|
6946
|
+
}
|
|
6947
|
+
});
|
|
6948
|
+
controller.enqueue({
|
|
6949
|
+
type: "tool-call",
|
|
6950
|
+
toolCallId: item.call_id,
|
|
6951
|
+
toolName: item.name,
|
|
6952
|
+
input: item.arguments,
|
|
6953
|
+
providerMetadata: {
|
|
6954
|
+
[providerOptionsName]: {
|
|
6955
|
+
itemId: item.id,
|
|
6956
|
+
...item.namespace != null && {
|
|
6957
|
+
namespace: item.namespace
|
|
6958
|
+
}
|
|
6559
6959
|
}
|
|
6560
6960
|
}
|
|
6961
|
+
});
|
|
6962
|
+
};
|
|
6963
|
+
if (!suppressInputStreaming) {
|
|
6964
|
+
enqueueUnexpandedToolCall();
|
|
6965
|
+
return;
|
|
6966
|
+
}
|
|
6967
|
+
return expandParallelToolCall({
|
|
6968
|
+
toolCall: {
|
|
6969
|
+
toolCallId: item.call_id,
|
|
6970
|
+
toolName: item.name,
|
|
6971
|
+
input: item.arguments
|
|
6972
|
+
},
|
|
6973
|
+
tools: functionTools,
|
|
6974
|
+
providerOptionsName,
|
|
6975
|
+
itemId: item.id
|
|
6976
|
+
}).then((expandedToolCalls) => {
|
|
6977
|
+
if (expandedToolCalls == null) {
|
|
6978
|
+
enqueueUnexpandedToolCall();
|
|
6979
|
+
return;
|
|
6980
|
+
}
|
|
6981
|
+
for (const toolCall of expandedToolCalls) {
|
|
6982
|
+
controller.enqueue({
|
|
6983
|
+
type: "tool-input-start",
|
|
6984
|
+
id: toolCall.toolCallId,
|
|
6985
|
+
toolName: toolCall.toolName
|
|
6986
|
+
});
|
|
6987
|
+
controller.enqueue({
|
|
6988
|
+
type: "tool-input-delta",
|
|
6989
|
+
id: toolCall.toolCallId,
|
|
6990
|
+
delta: toolCall.input
|
|
6991
|
+
});
|
|
6992
|
+
controller.enqueue({
|
|
6993
|
+
type: "tool-input-end",
|
|
6994
|
+
id: toolCall.toolCallId
|
|
6995
|
+
});
|
|
6996
|
+
controller.enqueue(toolCall);
|
|
6561
6997
|
}
|
|
6562
6998
|
});
|
|
6563
6999
|
} else if (value.item.type === "custom_tool_call") {
|
|
@@ -6621,13 +7057,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6621
7057
|
toolName: toolNameMapping.toCustomToolName("file_search"),
|
|
6622
7058
|
result: {
|
|
6623
7059
|
queries: value.item.queries,
|
|
6624
|
-
results: (
|
|
7060
|
+
results: (_g = (_f = value.item.results) == null ? void 0 : _f.map((result2) => ({
|
|
6625
7061
|
attributes: result2.attributes,
|
|
6626
7062
|
fileId: result2.file_id,
|
|
6627
7063
|
filename: result2.filename,
|
|
6628
7064
|
score: result2.score,
|
|
6629
7065
|
text: result2.text
|
|
6630
|
-
}))) != null ?
|
|
7066
|
+
}))) != null ? _g : null
|
|
6631
7067
|
}
|
|
6632
7068
|
});
|
|
6633
7069
|
} else if (value.item.type === "code_interpreter_call") {
|
|
@@ -6653,7 +7089,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6653
7089
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
6654
7090
|
const isHosted = value.item.execution === "server";
|
|
6655
7091
|
if (toolCall != null) {
|
|
6656
|
-
const toolCallId = isHosted ? toolCall.toolCallId : (
|
|
7092
|
+
const toolCallId = isHosted ? toolCall.toolCallId : (_h = value.item.call_id) != null ? _h : value.item.id;
|
|
6657
7093
|
if (isHosted) {
|
|
6658
7094
|
hostedToolSearchCallIds.push(toolCallId);
|
|
6659
7095
|
} else {
|
|
@@ -6685,7 +7121,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6685
7121
|
}
|
|
6686
7122
|
ongoingToolCalls[value.output_index] = void 0;
|
|
6687
7123
|
} else if (value.item.type === "tool_search_output") {
|
|
6688
|
-
const toolCallId = (
|
|
7124
|
+
const toolCallId = (_j = (_i = value.item.call_id) != null ? _i : hostedToolSearchCallIds.shift()) != null ? _j : value.item.id;
|
|
6689
7125
|
controller.enqueue({
|
|
6690
7126
|
type: "tool-result",
|
|
6691
7127
|
toolCallId,
|
|
@@ -6701,10 +7137,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6701
7137
|
});
|
|
6702
7138
|
} else if (value.item.type === "mcp_call") {
|
|
6703
7139
|
ongoingToolCalls[value.output_index] = void 0;
|
|
6704
|
-
const approvalRequestId = (
|
|
6705
|
-
const aliasedToolCallId = approvalRequestId != null ? (
|
|
7140
|
+
const approvalRequestId = (_k = value.item.approval_request_id) != null ? _k : void 0;
|
|
7141
|
+
const aliasedToolCallId = approvalRequestId != null ? (_m = (_l = approvalRequestIdToDummyToolCallIdFromStream.get(
|
|
6706
7142
|
approvalRequestId
|
|
6707
|
-
)) != null ?
|
|
7143
|
+
)) != null ? _l : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _m : value.item.id : value.item.id;
|
|
6708
7144
|
const toolName = `mcp.${value.item.name}`;
|
|
6709
7145
|
controller.enqueue({
|
|
6710
7146
|
type: "tool-call",
|
|
@@ -6774,8 +7210,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6774
7210
|
ongoingToolCalls[value.output_index] = void 0;
|
|
6775
7211
|
} else if (value.item.type === "mcp_approval_request") {
|
|
6776
7212
|
ongoingToolCalls[value.output_index] = void 0;
|
|
6777
|
-
const dummyToolCallId = (
|
|
6778
|
-
const approvalRequestId = (
|
|
7213
|
+
const dummyToolCallId = (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : (0, import_provider_utils36.generateId)();
|
|
7214
|
+
const approvalRequestId = (_q = value.item.approval_request_id) != null ? _q : value.item.id;
|
|
6779
7215
|
approvalRequestIdToDummyToolCallIdFromStream.set(
|
|
6780
7216
|
approvalRequestId,
|
|
6781
7217
|
dummyToolCallId
|
|
@@ -6864,7 +7300,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6864
7300
|
providerMetadata: {
|
|
6865
7301
|
[providerOptionsName]: {
|
|
6866
7302
|
itemId: value.item.id,
|
|
6867
|
-
reasoningEncryptedContent: (
|
|
7303
|
+
reasoningEncryptedContent: (_r = value.item.encrypted_content) != null ? _r : null
|
|
6868
7304
|
}
|
|
6869
7305
|
}
|
|
6870
7306
|
});
|
|
@@ -6874,11 +7310,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6874
7310
|
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
6875
7311
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
6876
7312
|
if (toolCall != null) {
|
|
6877
|
-
|
|
6878
|
-
|
|
6879
|
-
|
|
6880
|
-
|
|
6881
|
-
|
|
7313
|
+
if (toolCall.suppressInputStreaming) {
|
|
7314
|
+
(_s = toolCall.bufferedInputDeltas) == null ? void 0 : _s.push(value.delta);
|
|
7315
|
+
} else {
|
|
7316
|
+
controller.enqueue({
|
|
7317
|
+
type: "tool-input-delta",
|
|
7318
|
+
id: toolCall.toolCallId,
|
|
7319
|
+
delta: value.delta
|
|
7320
|
+
});
|
|
7321
|
+
}
|
|
6882
7322
|
}
|
|
6883
7323
|
} else if (isResponseCustomToolCallInputDeltaChunk(value)) {
|
|
6884
7324
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
@@ -6977,7 +7417,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6977
7417
|
id: value.item_id,
|
|
6978
7418
|
delta: value.delta
|
|
6979
7419
|
});
|
|
6980
|
-
if (((
|
|
7420
|
+
if (((_u = (_t = options.providerOptions) == null ? void 0 : _t[providerOptionsName]) == null ? void 0 : _u.logprobs) && value.logprobs) {
|
|
6981
7421
|
logprobs.push(value.logprobs);
|
|
6982
7422
|
}
|
|
6983
7423
|
} else if (value.type === "response.reasoning_summary_part.added") {
|
|
@@ -7006,7 +7446,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7006
7446
|
providerMetadata: {
|
|
7007
7447
|
[providerOptionsName]: {
|
|
7008
7448
|
itemId: value.item_id,
|
|
7009
|
-
reasoningEncryptedContent: (
|
|
7449
|
+
reasoningEncryptedContent: (_w = (_v = activeReasoning[value.item_id]) == null ? void 0 : _v.encryptedContent) != null ? _w : null
|
|
7010
7450
|
}
|
|
7011
7451
|
}
|
|
7012
7452
|
});
|
|
@@ -7040,20 +7480,20 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7040
7480
|
} else if (isResponseFinishedChunk(value)) {
|
|
7041
7481
|
finishReason = {
|
|
7042
7482
|
unified: mapOpenAIResponseFinishReason({
|
|
7043
|
-
finishReason: (
|
|
7483
|
+
finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
|
|
7044
7484
|
hasFunctionCall
|
|
7045
7485
|
}),
|
|
7046
|
-
raw: (
|
|
7486
|
+
raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
|
|
7047
7487
|
};
|
|
7048
7488
|
usage = value.response.usage;
|
|
7049
7489
|
if (typeof value.response.service_tier === "string") {
|
|
7050
7490
|
serviceTier = value.response.service_tier;
|
|
7051
7491
|
}
|
|
7052
|
-
if (((
|
|
7492
|
+
if (((_A = value.response.reasoning) == null ? void 0 : _A.context) != null) {
|
|
7053
7493
|
reasoningContext = value.response.reasoning.context;
|
|
7054
7494
|
}
|
|
7055
7495
|
} else if (isResponseFailedChunk(value)) {
|
|
7056
|
-
const incompleteReason = (
|
|
7496
|
+
const incompleteReason = (_B = value.response.incomplete_details) == null ? void 0 : _B.reason;
|
|
7057
7497
|
finishReason = {
|
|
7058
7498
|
unified: incompleteReason ? mapOpenAIResponseFinishReason({
|
|
7059
7499
|
finishReason: incompleteReason,
|
|
@@ -7061,8 +7501,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7061
7501
|
}) : "error",
|
|
7062
7502
|
raw: incompleteReason != null ? incompleteReason : "error"
|
|
7063
7503
|
};
|
|
7064
|
-
usage = (
|
|
7065
|
-
if (((
|
|
7504
|
+
usage = (_C = value.response.usage) != null ? _C : void 0;
|
|
7505
|
+
if (((_D = value.response.reasoning) == null ? void 0 : _D.context) != null) {
|
|
7066
7506
|
reasoningContext = value.response.reasoning.context;
|
|
7067
7507
|
}
|
|
7068
7508
|
if (!encounteredStreamError && value.response.error != null) {
|
|
@@ -7086,7 +7526,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7086
7526
|
controller.enqueue({
|
|
7087
7527
|
type: "source",
|
|
7088
7528
|
sourceType: "url",
|
|
7089
|
-
id: (
|
|
7529
|
+
id: (_G = (_F = (_E = self.config).generateId) == null ? void 0 : _F.call(_E)) != null ? _G : (0, import_provider_utils36.generateId)(),
|
|
7090
7530
|
url: value.annotation.url,
|
|
7091
7531
|
title: value.annotation.title
|
|
7092
7532
|
});
|
|
@@ -7094,7 +7534,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7094
7534
|
controller.enqueue({
|
|
7095
7535
|
type: "source",
|
|
7096
7536
|
sourceType: "document",
|
|
7097
|
-
id: (
|
|
7537
|
+
id: (_J = (_I = (_H = self.config).generateId) == null ? void 0 : _I.call(_H)) != null ? _J : (0, import_provider_utils36.generateId)(),
|
|
7098
7538
|
mediaType: "text/plain",
|
|
7099
7539
|
title: value.annotation.filename,
|
|
7100
7540
|
filename: value.annotation.filename,
|
|
@@ -7110,7 +7550,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7110
7550
|
controller.enqueue({
|
|
7111
7551
|
type: "source",
|
|
7112
7552
|
sourceType: "document",
|
|
7113
|
-
id: (
|
|
7553
|
+
id: (_M = (_L = (_K = self.config).generateId) == null ? void 0 : _L.call(_K)) != null ? _M : (0, import_provider_utils36.generateId)(),
|
|
7114
7554
|
mediaType: "text/plain",
|
|
7115
7555
|
title: value.annotation.filename,
|
|
7116
7556
|
filename: value.annotation.filename,
|
|
@@ -7126,7 +7566,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7126
7566
|
controller.enqueue({
|
|
7127
7567
|
type: "source",
|
|
7128
7568
|
sourceType: "document",
|
|
7129
|
-
id: (
|
|
7569
|
+
id: (_P = (_O = (_N = self.config).generateId) == null ? void 0 : _O.call(_N)) != null ? _P : (0, import_provider_utils36.generateId)(),
|
|
7130
7570
|
mediaType: "application/octet-stream",
|
|
7131
7571
|
title: value.annotation.file_id,
|
|
7132
7572
|
filename: value.annotation.file_id,
|
|
@@ -7146,6 +7586,24 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7146
7586
|
}
|
|
7147
7587
|
},
|
|
7148
7588
|
flush(controller) {
|
|
7589
|
+
var _a2;
|
|
7590
|
+
for (const toolCall of Object.values(ongoingToolCalls)) {
|
|
7591
|
+
if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
|
|
7592
|
+
continue;
|
|
7593
|
+
}
|
|
7594
|
+
controller.enqueue({
|
|
7595
|
+
type: "tool-input-start",
|
|
7596
|
+
id: toolCall.toolCallId,
|
|
7597
|
+
toolName: toolCall.toolName
|
|
7598
|
+
});
|
|
7599
|
+
for (const delta of (_a2 = toolCall.bufferedInputDeltas) != null ? _a2 : []) {
|
|
7600
|
+
controller.enqueue({
|
|
7601
|
+
type: "tool-input-delta",
|
|
7602
|
+
id: toolCall.toolCallId,
|
|
7603
|
+
delta
|
|
7604
|
+
});
|
|
7605
|
+
}
|
|
7606
|
+
}
|
|
7149
7607
|
const providerMetadata = {
|
|
7150
7608
|
[providerOptionsName]: {
|
|
7151
7609
|
responseId,
|
|
@@ -7183,7 +7641,7 @@ function createOpenAIResponsesChatCompletionsMismatchError({
|
|
|
7183
7641
|
requestBodyValues,
|
|
7184
7642
|
responseHeaders
|
|
7185
7643
|
}) {
|
|
7186
|
-
return new
|
|
7644
|
+
return new import_provider10.APICallError({
|
|
7187
7645
|
message: "Received a Chat Completions stream while using the OpenAI Responses API. The default OpenAI provider model uses the Responses API. If your custom baseURL targets a Chat Completions-compatible endpoint, use openai.chat('model-id') or createOpenAI(...).chat('model-id') instead. You can also use @ai-sdk/openai-compatible for OpenAI-compatible providers.",
|
|
7188
7646
|
url,
|
|
7189
7647
|
requestBodyValues,
|