@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/index.js
CHANGED
|
@@ -27,7 +27,7 @@ __export(index_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
|
|
29
29
|
// src/openai-provider.ts
|
|
30
|
-
var
|
|
30
|
+
var import_provider_utils37 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/chat/openai-chat-language-model.ts
|
|
33
33
|
var import_provider4 = require("@ai-sdk/provider");
|
|
@@ -2932,8 +2932,8 @@ var openaiTools = {
|
|
|
2932
2932
|
};
|
|
2933
2933
|
|
|
2934
2934
|
// src/responses/openai-responses-language-model.ts
|
|
2935
|
-
var
|
|
2936
|
-
var
|
|
2935
|
+
var import_provider10 = require("@ai-sdk/provider");
|
|
2936
|
+
var import_provider_utils31 = require("@ai-sdk/provider-utils");
|
|
2937
2937
|
|
|
2938
2938
|
// src/responses/convert-openai-responses-usage.ts
|
|
2939
2939
|
function convertOpenAIResponsesUsage(usage) {
|
|
@@ -2976,12 +2976,229 @@ function convertOpenAIResponsesUsage(usage) {
|
|
|
2976
2976
|
}
|
|
2977
2977
|
|
|
2978
2978
|
// src/responses/convert-to-openai-responses-input.ts
|
|
2979
|
+
var import_provider8 = require("@ai-sdk/provider");
|
|
2980
|
+
var import_provider_utils27 = require("@ai-sdk/provider-utils");
|
|
2981
|
+
var import_v421 = require("zod/v4");
|
|
2982
|
+
|
|
2983
|
+
// src/responses/expand-parallel-tool-call.ts
|
|
2979
2984
|
var import_provider7 = require("@ai-sdk/provider");
|
|
2980
2985
|
var import_provider_utils26 = require("@ai-sdk/provider-utils");
|
|
2981
|
-
var
|
|
2986
|
+
var parallelToolName = "parallel";
|
|
2987
|
+
var recipientNamePrefix = "functions.";
|
|
2988
|
+
function getParallelToolCallMetadata({
|
|
2989
|
+
providerOptions,
|
|
2990
|
+
providerOptionsName
|
|
2991
|
+
}) {
|
|
2992
|
+
var _a;
|
|
2993
|
+
const metadata = (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.parallelToolCall;
|
|
2994
|
+
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) {
|
|
2995
|
+
return void 0;
|
|
2996
|
+
}
|
|
2997
|
+
return metadata;
|
|
2998
|
+
}
|
|
2999
|
+
function isUndeclaredParallelToolCall({
|
|
3000
|
+
toolName,
|
|
3001
|
+
tools
|
|
3002
|
+
}) {
|
|
3003
|
+
return toolName === parallelToolName && !tools.some((tool) => tool.name === parallelToolName);
|
|
3004
|
+
}
|
|
3005
|
+
async function expandParallelToolCall({
|
|
3006
|
+
toolCall,
|
|
3007
|
+
tools,
|
|
3008
|
+
providerOptionsName,
|
|
3009
|
+
itemId
|
|
3010
|
+
}) {
|
|
3011
|
+
if (!isUndeclaredParallelToolCall({ toolName: toolCall.toolName, tools })) {
|
|
3012
|
+
return void 0;
|
|
3013
|
+
}
|
|
3014
|
+
const parsedInput = await (0, import_provider_utils26.safeParseJSON)({ text: toolCall.input });
|
|
3015
|
+
if (!parsedInput.success || !(0, import_provider7.isJSONObject)(parsedInput.value)) {
|
|
3016
|
+
return void 0;
|
|
3017
|
+
}
|
|
3018
|
+
const toolUses = parsedInput.value.tool_uses;
|
|
3019
|
+
if (!Array.isArray(toolUses) || toolUses.length === 0) {
|
|
3020
|
+
return void 0;
|
|
3021
|
+
}
|
|
3022
|
+
const availableToolNames = new Set(tools.map((tool) => tool.name));
|
|
3023
|
+
const expandedToolCalls = [];
|
|
3024
|
+
for (const [index, toolUse] of toolUses.entries()) {
|
|
3025
|
+
if (!(0, import_provider7.isJSONObject)(toolUse)) {
|
|
3026
|
+
return void 0;
|
|
3027
|
+
}
|
|
3028
|
+
const recipientName = toolUse.recipient_name;
|
|
3029
|
+
const parameters = toolUse.parameters;
|
|
3030
|
+
if (typeof recipientName !== "string" || !recipientName.startsWith(recipientNamePrefix) || !(0, import_provider7.isJSONObject)(parameters)) {
|
|
3031
|
+
return void 0;
|
|
3032
|
+
}
|
|
3033
|
+
const toolName = recipientName.slice(recipientNamePrefix.length);
|
|
3034
|
+
if (toolName.length === 0 || !availableToolNames.has(toolName)) {
|
|
3035
|
+
return void 0;
|
|
3036
|
+
}
|
|
3037
|
+
expandedToolCalls.push({
|
|
3038
|
+
type: "tool-call",
|
|
3039
|
+
toolCallId: `${toolCall.toolCallId}_${index}`,
|
|
3040
|
+
toolName,
|
|
3041
|
+
input: JSON.stringify(parameters),
|
|
3042
|
+
providerMetadata: {
|
|
3043
|
+
[providerOptionsName]: {
|
|
3044
|
+
parallelToolCall: {
|
|
3045
|
+
itemId,
|
|
3046
|
+
toolCallId: toolCall.toolCallId,
|
|
3047
|
+
toolName: toolCall.toolName,
|
|
3048
|
+
input: toolCall.input,
|
|
3049
|
+
index,
|
|
3050
|
+
count: toolUses.length
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
});
|
|
3055
|
+
}
|
|
3056
|
+
return expandedToolCalls;
|
|
3057
|
+
}
|
|
3058
|
+
|
|
3059
|
+
// src/responses/convert-to-openai-responses-input.ts
|
|
2982
3060
|
function serializeToolCallArguments2(input) {
|
|
2983
3061
|
return JSON.stringify(input === void 0 ? {} : input);
|
|
2984
3062
|
}
|
|
3063
|
+
async function convertFunctionToolResultOutput({
|
|
3064
|
+
output,
|
|
3065
|
+
providerOptionsName,
|
|
3066
|
+
warnings
|
|
3067
|
+
}) {
|
|
3068
|
+
var _a;
|
|
3069
|
+
switch (output.type) {
|
|
3070
|
+
case "text":
|
|
3071
|
+
case "error-text":
|
|
3072
|
+
return output.value;
|
|
3073
|
+
case "execution-denied":
|
|
3074
|
+
return (_a = output.reason) != null ? _a : "Tool call execution denied.";
|
|
3075
|
+
case "json":
|
|
3076
|
+
case "error-json":
|
|
3077
|
+
return JSON.stringify(output.value);
|
|
3078
|
+
case "content":
|
|
3079
|
+
return output.value.map((item) => {
|
|
3080
|
+
var _a2, _b, _c, _d, _e;
|
|
3081
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
3082
|
+
item.providerOptions,
|
|
3083
|
+
providerOptionsName
|
|
3084
|
+
);
|
|
3085
|
+
switch (item.type) {
|
|
3086
|
+
case "text": {
|
|
3087
|
+
return {
|
|
3088
|
+
type: "input_text",
|
|
3089
|
+
text: item.text,
|
|
3090
|
+
...promptCacheBreakpoint != null && {
|
|
3091
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3092
|
+
}
|
|
3093
|
+
};
|
|
3094
|
+
}
|
|
3095
|
+
case "image-data": {
|
|
3096
|
+
return {
|
|
3097
|
+
type: "input_image",
|
|
3098
|
+
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3099
|
+
detail: (_b = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b.imageDetail,
|
|
3100
|
+
...promptCacheBreakpoint != null && {
|
|
3101
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3102
|
+
}
|
|
3103
|
+
};
|
|
3104
|
+
}
|
|
3105
|
+
case "image-url": {
|
|
3106
|
+
return {
|
|
3107
|
+
type: "input_image",
|
|
3108
|
+
image_url: item.url,
|
|
3109
|
+
detail: (_d = (_c = item.providerOptions) == null ? void 0 : _c[providerOptionsName]) == null ? void 0 : _d.imageDetail,
|
|
3110
|
+
...promptCacheBreakpoint != null && {
|
|
3111
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3112
|
+
}
|
|
3113
|
+
};
|
|
3114
|
+
}
|
|
3115
|
+
case "file-data": {
|
|
3116
|
+
return {
|
|
3117
|
+
type: "input_file",
|
|
3118
|
+
filename: (_e = item.filename) != null ? _e : "data",
|
|
3119
|
+
file_data: `data:${item.mediaType};base64,${item.data}`,
|
|
3120
|
+
...promptCacheBreakpoint != null && {
|
|
3121
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3122
|
+
}
|
|
3123
|
+
};
|
|
3124
|
+
}
|
|
3125
|
+
case "file-url": {
|
|
3126
|
+
return {
|
|
3127
|
+
type: "input_file",
|
|
3128
|
+
file_url: item.url,
|
|
3129
|
+
...promptCacheBreakpoint != null && {
|
|
3130
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3131
|
+
}
|
|
3132
|
+
};
|
|
3133
|
+
}
|
|
3134
|
+
default: {
|
|
3135
|
+
warnings.push({
|
|
3136
|
+
type: "other",
|
|
3137
|
+
message: `unsupported tool content part type: ${item.type}`
|
|
3138
|
+
});
|
|
3139
|
+
return void 0;
|
|
3140
|
+
}
|
|
3141
|
+
}
|
|
3142
|
+
}).filter(import_provider_utils27.isNonNullable);
|
|
3143
|
+
}
|
|
3144
|
+
}
|
|
3145
|
+
function hasSameParallelToolCall(first, second) {
|
|
3146
|
+
return first.itemId === second.itemId && first.toolCallId === second.toolCallId && first.toolName === second.toolName && first.input === second.input && first.count === second.count;
|
|
3147
|
+
}
|
|
3148
|
+
function collectCompleteParallelToolResultGroups({
|
|
3149
|
+
prompt,
|
|
3150
|
+
providerOptionsName
|
|
3151
|
+
}) {
|
|
3152
|
+
const pendingGroups = /* @__PURE__ */ new Map();
|
|
3153
|
+
for (const message of prompt) {
|
|
3154
|
+
if (message.role !== "tool") {
|
|
3155
|
+
continue;
|
|
3156
|
+
}
|
|
3157
|
+
for (const part of message.content) {
|
|
3158
|
+
if (part.type !== "tool-result") {
|
|
3159
|
+
continue;
|
|
3160
|
+
}
|
|
3161
|
+
const metadata = getParallelToolCallMetadata({
|
|
3162
|
+
providerOptions: part.providerOptions,
|
|
3163
|
+
providerOptionsName
|
|
3164
|
+
});
|
|
3165
|
+
if (metadata == null) {
|
|
3166
|
+
continue;
|
|
3167
|
+
}
|
|
3168
|
+
const existing = pendingGroups.get(metadata.toolCallId);
|
|
3169
|
+
if (existing == null) {
|
|
3170
|
+
pendingGroups.set(metadata.toolCallId, {
|
|
3171
|
+
metadata,
|
|
3172
|
+
results: /* @__PURE__ */ new Map([[metadata.index, part]]),
|
|
3173
|
+
invalid: false
|
|
3174
|
+
});
|
|
3175
|
+
continue;
|
|
3176
|
+
}
|
|
3177
|
+
if (!hasSameParallelToolCall(existing.metadata, metadata) || existing.results.has(metadata.index)) {
|
|
3178
|
+
existing.invalid = true;
|
|
3179
|
+
continue;
|
|
3180
|
+
}
|
|
3181
|
+
existing.results.set(metadata.index, part);
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
const completeGroups = /* @__PURE__ */ new Map();
|
|
3185
|
+
for (const [toolCallId, group] of pendingGroups) {
|
|
3186
|
+
if (group.invalid || group.results.size !== group.metadata.count) {
|
|
3187
|
+
continue;
|
|
3188
|
+
}
|
|
3189
|
+
const results = Array.from(
|
|
3190
|
+
{ length: group.metadata.count },
|
|
3191
|
+
(_, index) => group.results.get(index)
|
|
3192
|
+
);
|
|
3193
|
+
if (results.every(import_provider_utils27.isNonNullable)) {
|
|
3194
|
+
completeGroups.set(toolCallId, {
|
|
3195
|
+
metadata: group.metadata,
|
|
3196
|
+
results
|
|
3197
|
+
});
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
return completeGroups;
|
|
3201
|
+
}
|
|
2985
3202
|
function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
|
|
2986
3203
|
var _a;
|
|
2987
3204
|
return (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.promptCacheBreakpoint;
|
|
@@ -3005,10 +3222,16 @@ async function convertToOpenAIResponsesInput({
|
|
|
3005
3222
|
hasApplyPatchTool = false,
|
|
3006
3223
|
customProviderToolNames
|
|
3007
3224
|
}) {
|
|
3008
|
-
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
|
|
3225
|
+
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;
|
|
3009
3226
|
let input = [];
|
|
3010
3227
|
const warnings = [];
|
|
3011
3228
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
3229
|
+
const parallelToolResultGroups = hasConversation || hasPreviousResponseId ? collectCompleteParallelToolResultGroups({
|
|
3230
|
+
prompt,
|
|
3231
|
+
providerOptionsName
|
|
3232
|
+
}) : /* @__PURE__ */ new Map();
|
|
3233
|
+
const emittedParallelToolCalls = /* @__PURE__ */ new Set();
|
|
3234
|
+
const emittedParallelToolResults = /* @__PURE__ */ new Set();
|
|
3012
3235
|
for (const { role, content, providerOptions } of prompt) {
|
|
3013
3236
|
switch (role) {
|
|
3014
3237
|
case "system": {
|
|
@@ -3092,7 +3315,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3092
3315
|
return {
|
|
3093
3316
|
type: "input_image",
|
|
3094
3317
|
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
3095
|
-
image_url: `data:${mediaType};base64,${(0,
|
|
3318
|
+
image_url: `data:${mediaType};base64,${(0, import_provider_utils27.convertToBase64)(part.data)}`
|
|
3096
3319
|
},
|
|
3097
3320
|
detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
3098
3321
|
...promptCacheBreakpoint != null && {
|
|
@@ -3110,7 +3333,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3110
3333
|
};
|
|
3111
3334
|
}
|
|
3112
3335
|
if (mediaType !== "application/pdf" && !passThroughUnsupportedFiles) {
|
|
3113
|
-
throw new
|
|
3336
|
+
throw new import_provider8.UnsupportedFunctionalityError({
|
|
3114
3337
|
functionality: `file part media type ${mediaType}`
|
|
3115
3338
|
});
|
|
3116
3339
|
}
|
|
@@ -3118,7 +3341,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3118
3341
|
type: "input_file",
|
|
3119
3342
|
...typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
3120
3343
|
filename: (_c2 = part.filename) != null ? _c2 : mediaType === "application/pdf" ? `part-${index}.pdf` : `part-${index}`,
|
|
3121
|
-
file_data: `data:${mediaType};base64,${(0,
|
|
3344
|
+
file_data: `data:${mediaType};base64,${(0, import_provider_utils27.convertToBase64)(part.data)}`
|
|
3122
3345
|
},
|
|
3123
3346
|
...promptCacheBreakpoint != null && {
|
|
3124
3347
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
@@ -3154,6 +3377,34 @@ async function convertToOpenAIResponsesInput({
|
|
|
3154
3377
|
break;
|
|
3155
3378
|
}
|
|
3156
3379
|
case "tool-call": {
|
|
3380
|
+
const parallelToolCallMetadata = getParallelToolCallMetadata({
|
|
3381
|
+
providerOptions: part.providerOptions,
|
|
3382
|
+
providerOptionsName
|
|
3383
|
+
});
|
|
3384
|
+
const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
|
|
3385
|
+
parallelToolCallMetadata.toolCallId
|
|
3386
|
+
);
|
|
3387
|
+
if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
|
|
3388
|
+
parallelToolResultGroup.metadata,
|
|
3389
|
+
parallelToolCallMetadata
|
|
3390
|
+
)) {
|
|
3391
|
+
if (!emittedParallelToolCalls.has(
|
|
3392
|
+
parallelToolResultGroup.metadata.toolCallId
|
|
3393
|
+
)) {
|
|
3394
|
+
emittedParallelToolCalls.add(
|
|
3395
|
+
parallelToolResultGroup.metadata.toolCallId
|
|
3396
|
+
);
|
|
3397
|
+
if (!hasConversation) {
|
|
3398
|
+
input.push({
|
|
3399
|
+
type: "function_call",
|
|
3400
|
+
call_id: parallelToolResultGroup.metadata.toolCallId,
|
|
3401
|
+
name: parallelToolResultGroup.metadata.toolName,
|
|
3402
|
+
arguments: parallelToolResultGroup.metadata.input
|
|
3403
|
+
});
|
|
3404
|
+
}
|
|
3405
|
+
}
|
|
3406
|
+
break;
|
|
3407
|
+
}
|
|
3157
3408
|
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;
|
|
3158
3409
|
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;
|
|
3159
3410
|
if (hasConversation && id != null) {
|
|
@@ -3167,10 +3418,10 @@ async function convertToOpenAIResponsesInput({
|
|
|
3167
3418
|
input.push({ type: "item_reference", id });
|
|
3168
3419
|
break;
|
|
3169
3420
|
}
|
|
3170
|
-
const parsedInput = typeof part.input === "string" ? await (0,
|
|
3421
|
+
const parsedInput = typeof part.input === "string" ? await (0, import_provider_utils27.parseJSON)({
|
|
3171
3422
|
text: part.input,
|
|
3172
3423
|
schema: toolSearchInputSchema
|
|
3173
|
-
}) : await (0,
|
|
3424
|
+
}) : await (0, import_provider_utils27.validateTypes)({
|
|
3174
3425
|
value: part.input,
|
|
3175
3426
|
schema: toolSearchInputSchema
|
|
3176
3427
|
});
|
|
@@ -3202,7 +3453,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3202
3453
|
break;
|
|
3203
3454
|
}
|
|
3204
3455
|
if (hasLocalShellTool && resolvedToolName === "local_shell") {
|
|
3205
|
-
const parsedInput = await (0,
|
|
3456
|
+
const parsedInput = await (0, import_provider_utils27.validateTypes)({
|
|
3206
3457
|
value: part.input,
|
|
3207
3458
|
schema: localShellInputSchema
|
|
3208
3459
|
});
|
|
@@ -3222,7 +3473,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3222
3473
|
break;
|
|
3223
3474
|
}
|
|
3224
3475
|
if (hasShellTool && resolvedToolName === "shell") {
|
|
3225
|
-
const parsedInput = await (0,
|
|
3476
|
+
const parsedInput = await (0, import_provider_utils27.validateTypes)({
|
|
3226
3477
|
value: part.input,
|
|
3227
3478
|
schema: shellInputSchema
|
|
3228
3479
|
});
|
|
@@ -3240,7 +3491,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3240
3491
|
break;
|
|
3241
3492
|
}
|
|
3242
3493
|
if (hasApplyPatchTool && resolvedToolName === "apply_patch") {
|
|
3243
|
-
const parsedInput = await (0,
|
|
3494
|
+
const parsedInput = await (0, import_provider_utils27.validateTypes)({
|
|
3244
3495
|
value: part.input,
|
|
3245
3496
|
schema: applyPatchInputSchema
|
|
3246
3497
|
});
|
|
@@ -3288,7 +3539,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3288
3539
|
if (store) {
|
|
3289
3540
|
input.push({ type: "item_reference", id: itemId });
|
|
3290
3541
|
} else if (part.output.type === "json") {
|
|
3291
|
-
const parsedOutput = await (0,
|
|
3542
|
+
const parsedOutput = await (0, import_provider_utils27.validateTypes)({
|
|
3292
3543
|
value: part.output.value,
|
|
3293
3544
|
schema: toolSearchOutputSchema
|
|
3294
3545
|
});
|
|
@@ -3305,7 +3556,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3305
3556
|
}
|
|
3306
3557
|
if (hasShellTool && resolvedResultToolName === "shell") {
|
|
3307
3558
|
if (part.output.type === "json") {
|
|
3308
|
-
const parsedOutput = await (0,
|
|
3559
|
+
const parsedOutput = await (0, import_provider_utils27.validateTypes)({
|
|
3309
3560
|
value: part.output.value,
|
|
3310
3561
|
schema: shellOutputSchema
|
|
3311
3562
|
});
|
|
@@ -3336,7 +3587,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3336
3587
|
break;
|
|
3337
3588
|
}
|
|
3338
3589
|
case "reasoning": {
|
|
3339
|
-
const providerOptions2 = await (0,
|
|
3590
|
+
const providerOptions2 = await (0, import_provider_utils27.parseProviderOptions)({
|
|
3340
3591
|
provider: providerOptionsName,
|
|
3341
3592
|
providerOptions: part.providerOptions,
|
|
3342
3593
|
schema: openaiResponsesReasoningProviderOptionsSchema
|
|
@@ -3433,6 +3684,44 @@ async function convertToOpenAIResponsesInput({
|
|
|
3433
3684
|
});
|
|
3434
3685
|
continue;
|
|
3435
3686
|
}
|
|
3687
|
+
const parallelToolCallMetadata = getParallelToolCallMetadata({
|
|
3688
|
+
providerOptions: part.providerOptions,
|
|
3689
|
+
providerOptionsName
|
|
3690
|
+
});
|
|
3691
|
+
const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
|
|
3692
|
+
parallelToolCallMetadata.toolCallId
|
|
3693
|
+
);
|
|
3694
|
+
if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
|
|
3695
|
+
parallelToolResultGroup.metadata,
|
|
3696
|
+
parallelToolCallMetadata
|
|
3697
|
+
)) {
|
|
3698
|
+
if (!emittedParallelToolResults.has(
|
|
3699
|
+
parallelToolResultGroup.metadata.toolCallId
|
|
3700
|
+
)) {
|
|
3701
|
+
emittedParallelToolResults.add(
|
|
3702
|
+
parallelToolResultGroup.metadata.toolCallId
|
|
3703
|
+
);
|
|
3704
|
+
const toolOutputs = await Promise.all(
|
|
3705
|
+
parallelToolResultGroup.results.map(
|
|
3706
|
+
async (result) => convertFunctionToolResultOutput({
|
|
3707
|
+
output: result.output,
|
|
3708
|
+
providerOptionsName,
|
|
3709
|
+
warnings
|
|
3710
|
+
})
|
|
3711
|
+
)
|
|
3712
|
+
);
|
|
3713
|
+
input.push({
|
|
3714
|
+
type: "function_call_output",
|
|
3715
|
+
call_id: parallelToolResultGroup.metadata.toolCallId,
|
|
3716
|
+
// The internal wrapper returns one output containing the child
|
|
3717
|
+
// results in the same order as the original tool_uses array.
|
|
3718
|
+
output: toolOutputs.map(
|
|
3719
|
+
(output2) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
|
|
3720
|
+
).join("\n")
|
|
3721
|
+
});
|
|
3722
|
+
}
|
|
3723
|
+
continue;
|
|
3724
|
+
}
|
|
3436
3725
|
const output = part.output;
|
|
3437
3726
|
if (output.type === "execution-denied") {
|
|
3438
3727
|
const approvalId = (_x = (_w = output.providerOptions) == null ? void 0 : _w.openai) == null ? void 0 : _x.approvalId;
|
|
@@ -3444,7 +3733,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3444
3733
|
part.toolName
|
|
3445
3734
|
);
|
|
3446
3735
|
if (resolvedToolName === "tool_search" && output.type === "json") {
|
|
3447
|
-
const parsedOutput = await (0,
|
|
3736
|
+
const parsedOutput = await (0, import_provider_utils27.validateTypes)({
|
|
3448
3737
|
value: output.value,
|
|
3449
3738
|
schema: toolSearchOutputSchema
|
|
3450
3739
|
});
|
|
@@ -3458,7 +3747,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3458
3747
|
continue;
|
|
3459
3748
|
}
|
|
3460
3749
|
if (hasLocalShellTool && resolvedToolName === "local_shell" && output.type === "json") {
|
|
3461
|
-
const parsedOutput = await (0,
|
|
3750
|
+
const parsedOutput = await (0, import_provider_utils27.validateTypes)({
|
|
3462
3751
|
value: output.value,
|
|
3463
3752
|
schema: localShellOutputSchema
|
|
3464
3753
|
});
|
|
@@ -3470,7 +3759,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3470
3759
|
continue;
|
|
3471
3760
|
}
|
|
3472
3761
|
if (hasShellTool && resolvedToolName === "shell" && output.type === "json") {
|
|
3473
|
-
const parsedOutput = await (0,
|
|
3762
|
+
const parsedOutput = await (0, import_provider_utils27.validateTypes)({
|
|
3474
3763
|
value: output.value,
|
|
3475
3764
|
schema: shellOutputSchema
|
|
3476
3765
|
});
|
|
@@ -3489,7 +3778,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3489
3778
|
continue;
|
|
3490
3779
|
}
|
|
3491
3780
|
if (hasApplyPatchTool && part.toolName === "apply_patch" && output.type === "json") {
|
|
3492
|
-
const parsedOutput = await (0,
|
|
3781
|
+
const parsedOutput = await (0, import_provider_utils27.validateTypes)({
|
|
3493
3782
|
value: output.value,
|
|
3494
3783
|
schema: applyPatchOutputSchema
|
|
3495
3784
|
});
|
|
@@ -3573,7 +3862,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3573
3862
|
});
|
|
3574
3863
|
return void 0;
|
|
3575
3864
|
}
|
|
3576
|
-
}).filter(
|
|
3865
|
+
}).filter(import_provider_utils27.isNonNullable);
|
|
3577
3866
|
break;
|
|
3578
3867
|
default:
|
|
3579
3868
|
outputValue = "";
|
|
@@ -3585,86 +3874,11 @@ async function convertToOpenAIResponsesInput({
|
|
|
3585
3874
|
});
|
|
3586
3875
|
continue;
|
|
3587
3876
|
}
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
break;
|
|
3594
|
-
case "execution-denied":
|
|
3595
|
-
contentValue = (_z = output.reason) != null ? _z : "Tool call execution denied.";
|
|
3596
|
-
break;
|
|
3597
|
-
case "json":
|
|
3598
|
-
case "error-json":
|
|
3599
|
-
contentValue = JSON.stringify(output.value);
|
|
3600
|
-
break;
|
|
3601
|
-
case "content":
|
|
3602
|
-
contentValue = output.value.map((item) => {
|
|
3603
|
-
var _a2, _b2, _c2, _d2, _e2;
|
|
3604
|
-
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
3605
|
-
item.providerOptions,
|
|
3606
|
-
providerOptionsName
|
|
3607
|
-
);
|
|
3608
|
-
switch (item.type) {
|
|
3609
|
-
case "text": {
|
|
3610
|
-
return {
|
|
3611
|
-
type: "input_text",
|
|
3612
|
-
text: item.text,
|
|
3613
|
-
...promptCacheBreakpoint != null && {
|
|
3614
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3615
|
-
}
|
|
3616
|
-
};
|
|
3617
|
-
}
|
|
3618
|
-
case "image-data": {
|
|
3619
|
-
return {
|
|
3620
|
-
type: "input_image",
|
|
3621
|
-
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3622
|
-
detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
3623
|
-
...promptCacheBreakpoint != null && {
|
|
3624
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3625
|
-
}
|
|
3626
|
-
};
|
|
3627
|
-
}
|
|
3628
|
-
case "image-url": {
|
|
3629
|
-
return {
|
|
3630
|
-
type: "input_image",
|
|
3631
|
-
image_url: item.url,
|
|
3632
|
-
detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
|
|
3633
|
-
...promptCacheBreakpoint != null && {
|
|
3634
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3635
|
-
}
|
|
3636
|
-
};
|
|
3637
|
-
}
|
|
3638
|
-
case "file-data": {
|
|
3639
|
-
return {
|
|
3640
|
-
type: "input_file",
|
|
3641
|
-
filename: (_e2 = item.filename) != null ? _e2 : "data",
|
|
3642
|
-
file_data: `data:${item.mediaType};base64,${item.data}`,
|
|
3643
|
-
...promptCacheBreakpoint != null && {
|
|
3644
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3645
|
-
}
|
|
3646
|
-
};
|
|
3647
|
-
}
|
|
3648
|
-
case "file-url": {
|
|
3649
|
-
return {
|
|
3650
|
-
type: "input_file",
|
|
3651
|
-
file_url: item.url,
|
|
3652
|
-
...promptCacheBreakpoint != null && {
|
|
3653
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3654
|
-
}
|
|
3655
|
-
};
|
|
3656
|
-
}
|
|
3657
|
-
default: {
|
|
3658
|
-
warnings.push({
|
|
3659
|
-
type: "other",
|
|
3660
|
-
message: `unsupported tool content part type: ${item.type}`
|
|
3661
|
-
});
|
|
3662
|
-
return void 0;
|
|
3663
|
-
}
|
|
3664
|
-
}
|
|
3665
|
-
}).filter(import_provider_utils26.isNonNullable);
|
|
3666
|
-
break;
|
|
3667
|
-
}
|
|
3877
|
+
const contentValue = await convertFunctionToolResultOutput({
|
|
3878
|
+
output,
|
|
3879
|
+
providerOptionsName,
|
|
3880
|
+
warnings
|
|
3881
|
+
});
|
|
3668
3882
|
input.push({
|
|
3669
3883
|
type: "function_call_output",
|
|
3670
3884
|
call_id: part.toolCallId,
|
|
@@ -3716,7 +3930,7 @@ function mapOpenAIResponseFinishReason({
|
|
|
3716
3930
|
}
|
|
3717
3931
|
|
|
3718
3932
|
// src/responses/openai-responses-api.ts
|
|
3719
|
-
var
|
|
3933
|
+
var import_provider_utils28 = require("@ai-sdk/provider-utils");
|
|
3720
3934
|
var import_v422 = require("zod/v4");
|
|
3721
3935
|
var jsonValueSchema2 = import_v422.z.lazy(
|
|
3722
3936
|
() => import_v422.z.union([
|
|
@@ -3745,8 +3959,8 @@ var openaiResponsesErrorChunkSchema = import_v422.z.object({
|
|
|
3745
3959
|
message: import_v422.z.string(),
|
|
3746
3960
|
param: import_v422.z.string().nullish()
|
|
3747
3961
|
});
|
|
3748
|
-
var openaiResponsesChunkSchema = (0,
|
|
3749
|
-
() => (0,
|
|
3962
|
+
var openaiResponsesChunkSchema = (0, import_provider_utils28.lazySchema)(
|
|
3963
|
+
() => (0, import_provider_utils28.zodSchema)(
|
|
3750
3964
|
import_v422.z.union([
|
|
3751
3965
|
import_v422.z.object({
|
|
3752
3966
|
type: import_v422.z.literal("response.output_text.delta"),
|
|
@@ -4294,8 +4508,8 @@ var openaiResponsesChunkSchema = (0, import_provider_utils27.lazySchema)(
|
|
|
4294
4508
|
])
|
|
4295
4509
|
)
|
|
4296
4510
|
);
|
|
4297
|
-
var openaiResponsesResponseSchema = (0,
|
|
4298
|
-
() => (0,
|
|
4511
|
+
var openaiResponsesResponseSchema = (0, import_provider_utils28.lazySchema)(
|
|
4512
|
+
() => (0, import_provider_utils28.zodSchema)(
|
|
4299
4513
|
import_v422.z.object({
|
|
4300
4514
|
id: import_v422.z.string().optional(),
|
|
4301
4515
|
created_at: import_v422.z.number().optional(),
|
|
@@ -4609,7 +4823,7 @@ var openaiResponsesResponseSchema = (0, import_provider_utils27.lazySchema)(
|
|
|
4609
4823
|
);
|
|
4610
4824
|
|
|
4611
4825
|
// src/responses/openai-responses-options.ts
|
|
4612
|
-
var
|
|
4826
|
+
var import_provider_utils29 = require("@ai-sdk/provider-utils");
|
|
4613
4827
|
var import_v423 = require("zod/v4");
|
|
4614
4828
|
var TOP_LOGPROBS_MAX = 20;
|
|
4615
4829
|
var openaiResponsesReasoningModelIds = [
|
|
@@ -4681,8 +4895,8 @@ var openaiResponsesModelIds = [
|
|
|
4681
4895
|
"gpt-5-chat-latest",
|
|
4682
4896
|
...openaiResponsesReasoningModelIds
|
|
4683
4897
|
];
|
|
4684
|
-
var openaiLanguageModelResponsesOptionsSchema = (0,
|
|
4685
|
-
() => (0,
|
|
4898
|
+
var openaiLanguageModelResponsesOptionsSchema = (0, import_provider_utils29.lazySchema)(
|
|
4899
|
+
() => (0, import_provider_utils29.zodSchema)(
|
|
4686
4900
|
import_v423.z.object({
|
|
4687
4901
|
/**
|
|
4688
4902
|
* The ID of the OpenAI Conversation to continue.
|
|
@@ -4879,8 +5093,8 @@ var openaiLanguageModelResponsesOptionsSchema = (0, import_provider_utils28.lazy
|
|
|
4879
5093
|
);
|
|
4880
5094
|
|
|
4881
5095
|
// src/responses/openai-responses-prepare-tools.ts
|
|
4882
|
-
var
|
|
4883
|
-
var
|
|
5096
|
+
var import_provider9 = require("@ai-sdk/provider");
|
|
5097
|
+
var import_provider_utils30 = require("@ai-sdk/provider-utils");
|
|
4884
5098
|
async function prepareResponsesTools({
|
|
4885
5099
|
tools,
|
|
4886
5100
|
toolChoice,
|
|
@@ -4888,7 +5102,7 @@ async function prepareResponsesTools({
|
|
|
4888
5102
|
toolNameMapping,
|
|
4889
5103
|
customProviderToolNames
|
|
4890
5104
|
}) {
|
|
4891
|
-
var _a, _b, _c;
|
|
5105
|
+
var _a, _b, _c, _d;
|
|
4892
5106
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
4893
5107
|
const toolWarnings = [];
|
|
4894
5108
|
if (tools == null) {
|
|
@@ -4897,6 +5111,20 @@ async function prepareResponsesTools({
|
|
|
4897
5111
|
const openaiTools2 = [];
|
|
4898
5112
|
const namespaceTools = /* @__PURE__ */ new Map();
|
|
4899
5113
|
const resolvedCustomProviderToolNames = customProviderToolNames != null ? customProviderToolNames : /* @__PURE__ */ new Set();
|
|
5114
|
+
const allowedToolResolutions = /* @__PURE__ */ new Map();
|
|
5115
|
+
const allowedToolAliases = /* @__PURE__ */ new Map();
|
|
5116
|
+
const recordAllowedTool = (toolName, resolution, canonicalName) => {
|
|
5117
|
+
allowedToolResolutions.set(toolName, resolution);
|
|
5118
|
+
if (canonicalName == null || canonicalName === toolName) {
|
|
5119
|
+
return;
|
|
5120
|
+
}
|
|
5121
|
+
const existingAlias = allowedToolAliases.get(canonicalName);
|
|
5122
|
+
if (existingAlias == null) {
|
|
5123
|
+
allowedToolAliases.set(canonicalName, resolution);
|
|
5124
|
+
} else if (existingAlias !== "ambiguous" && !isSameAllowedTool(existingAlias, resolution)) {
|
|
5125
|
+
allowedToolAliases.set(canonicalName, "ambiguous");
|
|
5126
|
+
}
|
|
5127
|
+
};
|
|
4900
5128
|
for (const tool of tools) {
|
|
4901
5129
|
switch (tool.type) {
|
|
4902
5130
|
case "function": {
|
|
@@ -4920,18 +5148,33 @@ async function prepareResponsesTools({
|
|
|
4920
5148
|
namespaceTools.set(namespace.name, namespaceTool);
|
|
4921
5149
|
openaiTools2.push(namespaceTool);
|
|
4922
5150
|
} else if (namespaceTool.description !== namespace.description) {
|
|
4923
|
-
throw new
|
|
5151
|
+
throw new import_provider9.UnsupportedFunctionalityError({
|
|
4924
5152
|
functionality: `conflicting descriptions for OpenAI tool namespace "${namespace.name}"`
|
|
4925
5153
|
});
|
|
4926
5154
|
}
|
|
4927
5155
|
namespaceTool.tools.push(openaiFunctionTool);
|
|
4928
5156
|
}
|
|
5157
|
+
recordAllowedTool(
|
|
5158
|
+
tool.name,
|
|
5159
|
+
namespace != null ? {
|
|
5160
|
+
supported: false,
|
|
5161
|
+
reason: "tools inside an OpenAI tool namespace are not visible to tool_choice.allowed_tools"
|
|
5162
|
+
} : (openaiOptions == null ? void 0 : openaiOptions.deferLoading) === true ? {
|
|
5163
|
+
supported: false,
|
|
5164
|
+
reason: "deferred tools are not visible to tool_choice.allowed_tools"
|
|
5165
|
+
} : {
|
|
5166
|
+
supported: true,
|
|
5167
|
+
entry: { type: "function", name: tool.name }
|
|
5168
|
+
},
|
|
5169
|
+
void 0
|
|
5170
|
+
);
|
|
4929
5171
|
break;
|
|
4930
5172
|
}
|
|
4931
5173
|
case "provider": {
|
|
5174
|
+
const openaiToolCountBefore = openaiTools2.length;
|
|
4932
5175
|
switch (tool.id) {
|
|
4933
5176
|
case "openai.file_search": {
|
|
4934
|
-
const args = await (0,
|
|
5177
|
+
const args = await (0, import_provider_utils30.validateTypes)({
|
|
4935
5178
|
value: tool.args,
|
|
4936
5179
|
schema: fileSearchArgsSchema
|
|
4937
5180
|
});
|
|
@@ -4954,7 +5197,7 @@ async function prepareResponsesTools({
|
|
|
4954
5197
|
break;
|
|
4955
5198
|
}
|
|
4956
5199
|
case "openai.shell": {
|
|
4957
|
-
const args = await (0,
|
|
5200
|
+
const args = await (0, import_provider_utils30.validateTypes)({
|
|
4958
5201
|
value: tool.args,
|
|
4959
5202
|
schema: shellArgsSchema
|
|
4960
5203
|
});
|
|
@@ -4973,7 +5216,7 @@ async function prepareResponsesTools({
|
|
|
4973
5216
|
break;
|
|
4974
5217
|
}
|
|
4975
5218
|
case "openai.web_search_preview": {
|
|
4976
|
-
const args = await (0,
|
|
5219
|
+
const args = await (0, import_provider_utils30.validateTypes)({
|
|
4977
5220
|
value: tool.args,
|
|
4978
5221
|
schema: webSearchPreviewArgsSchema
|
|
4979
5222
|
});
|
|
@@ -4985,7 +5228,7 @@ async function prepareResponsesTools({
|
|
|
4985
5228
|
break;
|
|
4986
5229
|
}
|
|
4987
5230
|
case "openai.web_search": {
|
|
4988
|
-
const args = await (0,
|
|
5231
|
+
const args = await (0, import_provider_utils30.validateTypes)({
|
|
4989
5232
|
value: tool.args,
|
|
4990
5233
|
schema: webSearchArgsSchema
|
|
4991
5234
|
});
|
|
@@ -5002,7 +5245,7 @@ async function prepareResponsesTools({
|
|
|
5002
5245
|
break;
|
|
5003
5246
|
}
|
|
5004
5247
|
case "openai.code_interpreter": {
|
|
5005
|
-
const args = await (0,
|
|
5248
|
+
const args = await (0, import_provider_utils30.validateTypes)({
|
|
5006
5249
|
value: tool.args,
|
|
5007
5250
|
schema: codeInterpreterArgsSchema
|
|
5008
5251
|
});
|
|
@@ -5013,7 +5256,7 @@ async function prepareResponsesTools({
|
|
|
5013
5256
|
break;
|
|
5014
5257
|
}
|
|
5015
5258
|
case "openai.image_generation": {
|
|
5016
|
-
const args = await (0,
|
|
5259
|
+
const args = await (0, import_provider_utils30.validateTypes)({
|
|
5017
5260
|
value: tool.args,
|
|
5018
5261
|
schema: imageGenerationArgsSchema
|
|
5019
5262
|
});
|
|
@@ -5036,7 +5279,7 @@ async function prepareResponsesTools({
|
|
|
5036
5279
|
break;
|
|
5037
5280
|
}
|
|
5038
5281
|
case "openai.mcp": {
|
|
5039
|
-
const args = await (0,
|
|
5282
|
+
const args = await (0, import_provider_utils30.validateTypes)({
|
|
5040
5283
|
value: tool.args,
|
|
5041
5284
|
schema: mcpArgsSchema
|
|
5042
5285
|
});
|
|
@@ -5062,7 +5305,7 @@ async function prepareResponsesTools({
|
|
|
5062
5305
|
break;
|
|
5063
5306
|
}
|
|
5064
5307
|
case "openai.custom": {
|
|
5065
|
-
const args = await (0,
|
|
5308
|
+
const args = await (0, import_provider_utils30.validateTypes)({
|
|
5066
5309
|
value: tool.args,
|
|
5067
5310
|
schema: customArgsSchema
|
|
5068
5311
|
});
|
|
@@ -5076,7 +5319,7 @@ async function prepareResponsesTools({
|
|
|
5076
5319
|
break;
|
|
5077
5320
|
}
|
|
5078
5321
|
case "openai.tool_search": {
|
|
5079
|
-
const args = await (0,
|
|
5322
|
+
const args = await (0, import_provider_utils30.validateTypes)({
|
|
5080
5323
|
value: tool.args,
|
|
5081
5324
|
schema: toolSearchArgsSchema
|
|
5082
5325
|
});
|
|
@@ -5089,6 +5332,14 @@ async function prepareResponsesTools({
|
|
|
5089
5332
|
break;
|
|
5090
5333
|
}
|
|
5091
5334
|
}
|
|
5335
|
+
if (openaiTools2.length > openaiToolCountBefore) {
|
|
5336
|
+
const openaiTool = openaiTools2[openaiToolCountBefore];
|
|
5337
|
+
recordAllowedTool(
|
|
5338
|
+
tool.name,
|
|
5339
|
+
toAllowedToolResolution(openaiTool),
|
|
5340
|
+
toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(tool.name)
|
|
5341
|
+
);
|
|
5342
|
+
}
|
|
5092
5343
|
break;
|
|
5093
5344
|
}
|
|
5094
5345
|
default:
|
|
@@ -5100,18 +5351,63 @@ async function prepareResponsesTools({
|
|
|
5100
5351
|
}
|
|
5101
5352
|
}
|
|
5102
5353
|
if (allowedTools != null) {
|
|
5354
|
+
const allowedToolEntries = [];
|
|
5355
|
+
const droppedToolNames = [];
|
|
5356
|
+
for (const name of allowedTools.toolNames) {
|
|
5357
|
+
const directResolution = allowedToolResolutions.get(name);
|
|
5358
|
+
const resolution = directResolution != null ? directResolution : allowedToolAliases.get(name);
|
|
5359
|
+
if (directResolution != null && allowedToolAliases.has(name)) {
|
|
5360
|
+
toolWarnings.push({
|
|
5361
|
+
type: "unsupported",
|
|
5362
|
+
feature: `allowedTools entry "${name}"`,
|
|
5363
|
+
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"
|
|
5364
|
+
});
|
|
5365
|
+
}
|
|
5366
|
+
if (resolution === "ambiguous") {
|
|
5367
|
+
toolWarnings.push({
|
|
5368
|
+
type: "unsupported",
|
|
5369
|
+
feature: `allowedTools entry "${name}"`,
|
|
5370
|
+
details: "several tools in this request share this provider tool name; use the tool name from the tools for this request instead"
|
|
5371
|
+
});
|
|
5372
|
+
droppedToolNames.push(name);
|
|
5373
|
+
continue;
|
|
5374
|
+
}
|
|
5375
|
+
if (resolution == null) {
|
|
5376
|
+
toolWarnings.push({
|
|
5377
|
+
type: "unsupported",
|
|
5378
|
+
feature: `allowedTools entry "${name}"`,
|
|
5379
|
+
details: "the tool is not part of the tools for this request and is sent as a function tool"
|
|
5380
|
+
});
|
|
5381
|
+
allowedToolEntries.push({
|
|
5382
|
+
type: "function",
|
|
5383
|
+
name: (_b = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(name)) != null ? _b : name
|
|
5384
|
+
});
|
|
5385
|
+
continue;
|
|
5386
|
+
}
|
|
5387
|
+
if (!resolution.supported) {
|
|
5388
|
+
toolWarnings.push({
|
|
5389
|
+
type: "unsupported",
|
|
5390
|
+
feature: `allowedTools entry "${name}"`,
|
|
5391
|
+
details: `${resolution.reason}; the tool is removed from the allowed tools`
|
|
5392
|
+
});
|
|
5393
|
+
droppedToolNames.push(name);
|
|
5394
|
+
continue;
|
|
5395
|
+
}
|
|
5396
|
+
allowedToolEntries.push(resolution.entry);
|
|
5397
|
+
}
|
|
5398
|
+
if (allowedToolEntries.length === 0) {
|
|
5399
|
+
throw new import_provider9.UnsupportedFunctionalityError({
|
|
5400
|
+
functionality: `allowedTools with only tools that cannot be allow-listed (${droppedToolNames.join(
|
|
5401
|
+
", "
|
|
5402
|
+
)})`
|
|
5403
|
+
});
|
|
5404
|
+
}
|
|
5103
5405
|
return {
|
|
5104
5406
|
tools: openaiTools2,
|
|
5105
5407
|
toolChoice: {
|
|
5106
5408
|
type: "allowed_tools",
|
|
5107
|
-
mode: (
|
|
5108
|
-
tools:
|
|
5109
|
-
var _a2;
|
|
5110
|
-
return {
|
|
5111
|
-
type: "function",
|
|
5112
|
-
name: (_a2 = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(name)) != null ? _a2 : name
|
|
5113
|
-
};
|
|
5114
|
-
})
|
|
5409
|
+
mode: (_c = allowedTools.mode) != null ? _c : "auto",
|
|
5410
|
+
tools: allowedToolEntries
|
|
5115
5411
|
},
|
|
5116
5412
|
toolWarnings
|
|
5117
5413
|
};
|
|
@@ -5126,7 +5422,7 @@ async function prepareResponsesTools({
|
|
|
5126
5422
|
case "required":
|
|
5127
5423
|
return { tools: openaiTools2, toolChoice: type, toolWarnings };
|
|
5128
5424
|
case "tool": {
|
|
5129
|
-
const resolvedToolName = (
|
|
5425
|
+
const resolvedToolName = (_d = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _d : toolChoice.toolName;
|
|
5130
5426
|
return {
|
|
5131
5427
|
tools: openaiTools2,
|
|
5132
5428
|
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 },
|
|
@@ -5135,12 +5431,57 @@ async function prepareResponsesTools({
|
|
|
5135
5431
|
}
|
|
5136
5432
|
default: {
|
|
5137
5433
|
const _exhaustiveCheck = type;
|
|
5138
|
-
throw new
|
|
5434
|
+
throw new import_provider9.UnsupportedFunctionalityError({
|
|
5139
5435
|
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
5140
5436
|
});
|
|
5141
5437
|
}
|
|
5142
5438
|
}
|
|
5143
5439
|
}
|
|
5440
|
+
function allowedToolKey(entry) {
|
|
5441
|
+
switch (entry.type) {
|
|
5442
|
+
case "mcp":
|
|
5443
|
+
return `mcp:${entry.server_label}`;
|
|
5444
|
+
case "function":
|
|
5445
|
+
case "custom":
|
|
5446
|
+
return `${entry.type}:${entry.name}`;
|
|
5447
|
+
default:
|
|
5448
|
+
return entry.type;
|
|
5449
|
+
}
|
|
5450
|
+
}
|
|
5451
|
+
function isSameAllowedTool(a, b) {
|
|
5452
|
+
if (a.supported && b.supported) {
|
|
5453
|
+
return allowedToolKey(a.entry) === allowedToolKey(b.entry);
|
|
5454
|
+
}
|
|
5455
|
+
if (!a.supported && !b.supported) {
|
|
5456
|
+
return a.reason === b.reason;
|
|
5457
|
+
}
|
|
5458
|
+
return false;
|
|
5459
|
+
}
|
|
5460
|
+
function toAllowedToolResolution(tool) {
|
|
5461
|
+
switch (tool.type) {
|
|
5462
|
+
case "custom":
|
|
5463
|
+
return { supported: true, entry: { type: "custom", name: tool.name } };
|
|
5464
|
+
case "mcp":
|
|
5465
|
+
return {
|
|
5466
|
+
supported: true,
|
|
5467
|
+
entry: { type: "mcp", server_label: tool.server_label }
|
|
5468
|
+
};
|
|
5469
|
+
case "file_search":
|
|
5470
|
+
case "web_search":
|
|
5471
|
+
case "web_search_preview":
|
|
5472
|
+
case "image_generation":
|
|
5473
|
+
case "code_interpreter":
|
|
5474
|
+
case "apply_patch":
|
|
5475
|
+
case "shell":
|
|
5476
|
+
case "local_shell":
|
|
5477
|
+
return { supported: true, entry: { type: tool.type } };
|
|
5478
|
+
default:
|
|
5479
|
+
return {
|
|
5480
|
+
supported: false,
|
|
5481
|
+
reason: `OpenAI does not support ${tool.type} tools in tool_choice.allowed_tools`
|
|
5482
|
+
};
|
|
5483
|
+
}
|
|
5484
|
+
}
|
|
5144
5485
|
function prepareFunctionTool({
|
|
5145
5486
|
tool,
|
|
5146
5487
|
options
|
|
@@ -5265,13 +5606,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5265
5606
|
warnings.push({ type: "unsupported", feature: "stopSequences" });
|
|
5266
5607
|
}
|
|
5267
5608
|
const providerOptionsName = this.config.provider.includes("azure") ? "azure" : "openai";
|
|
5268
|
-
let openaiOptions = await (0,
|
|
5609
|
+
let openaiOptions = await (0, import_provider_utils31.parseProviderOptions)({
|
|
5269
5610
|
provider: providerOptionsName,
|
|
5270
5611
|
providerOptions,
|
|
5271
5612
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
5272
5613
|
});
|
|
5273
5614
|
if (openaiOptions == null && providerOptionsName !== "openai") {
|
|
5274
|
-
openaiOptions = await (0,
|
|
5615
|
+
openaiOptions = await (0, import_provider_utils31.parseProviderOptions)({
|
|
5275
5616
|
provider: "openai",
|
|
5276
5617
|
providerOptions,
|
|
5277
5618
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
@@ -5285,7 +5626,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5285
5626
|
details: "conversation and previousResponseId cannot be used together"
|
|
5286
5627
|
});
|
|
5287
5628
|
}
|
|
5288
|
-
const toolNameMapping = (0,
|
|
5629
|
+
const toolNameMapping = (0, import_provider_utils31.createToolNameMapping)({
|
|
5289
5630
|
tools,
|
|
5290
5631
|
providerToolNames: {
|
|
5291
5632
|
"openai.code_interpreter": "code_interpreter",
|
|
@@ -5499,7 +5840,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5499
5840
|
};
|
|
5500
5841
|
}
|
|
5501
5842
|
async doGenerate(options) {
|
|
5502
|
-
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;
|
|
5843
|
+
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;
|
|
5503
5844
|
const {
|
|
5504
5845
|
args: body,
|
|
5505
5846
|
warnings,
|
|
@@ -5517,19 +5858,19 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5517
5858
|
responseHeaders,
|
|
5518
5859
|
value: response,
|
|
5519
5860
|
rawValue: rawResponse
|
|
5520
|
-
} = await (0,
|
|
5861
|
+
} = await (0, import_provider_utils31.postJsonToApi)({
|
|
5521
5862
|
url,
|
|
5522
|
-
headers: (0,
|
|
5863
|
+
headers: (0, import_provider_utils31.combineHeaders)(this.config.headers(), options.headers),
|
|
5523
5864
|
body,
|
|
5524
5865
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
5525
|
-
successfulResponseHandler: (0,
|
|
5866
|
+
successfulResponseHandler: (0, import_provider_utils31.createJsonResponseHandler)(
|
|
5526
5867
|
openaiResponsesResponseSchema
|
|
5527
5868
|
),
|
|
5528
5869
|
abortSignal: options.abortSignal,
|
|
5529
5870
|
fetch: this.config.fetch
|
|
5530
5871
|
});
|
|
5531
5872
|
if (response.error) {
|
|
5532
|
-
throw new
|
|
5873
|
+
throw new import_provider10.APICallError({
|
|
5533
5874
|
message: response.error.message,
|
|
5534
5875
|
url,
|
|
5535
5876
|
requestBodyValues: body,
|
|
@@ -5541,6 +5882,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5541
5882
|
}
|
|
5542
5883
|
const content = [];
|
|
5543
5884
|
const logprobs = [];
|
|
5885
|
+
const functionTools = (_b = (_a = options.tools) == null ? void 0 : _a.filter(
|
|
5886
|
+
(tool) => tool.type === "function"
|
|
5887
|
+
)) != null ? _b : [];
|
|
5544
5888
|
let hasFunctionCall = false;
|
|
5545
5889
|
const hostedToolSearchCallIds = [];
|
|
5546
5890
|
for (const part of response.output) {
|
|
@@ -5556,7 +5900,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5556
5900
|
providerMetadata: {
|
|
5557
5901
|
[providerOptionsName]: {
|
|
5558
5902
|
itemId: part.id,
|
|
5559
|
-
reasoningEncryptedContent: (
|
|
5903
|
+
reasoningEncryptedContent: (_c = part.encrypted_content) != null ? _c : null
|
|
5560
5904
|
}
|
|
5561
5905
|
}
|
|
5562
5906
|
});
|
|
@@ -5582,7 +5926,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5582
5926
|
break;
|
|
5583
5927
|
}
|
|
5584
5928
|
case "tool_search_call": {
|
|
5585
|
-
const toolCallId = (
|
|
5929
|
+
const toolCallId = (_d = part.call_id) != null ? _d : part.id;
|
|
5586
5930
|
const isHosted = part.execution === "server";
|
|
5587
5931
|
if (isHosted) {
|
|
5588
5932
|
hostedToolSearchCallIds.push(toolCallId);
|
|
@@ -5605,7 +5949,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5605
5949
|
break;
|
|
5606
5950
|
}
|
|
5607
5951
|
case "tool_search_output": {
|
|
5608
|
-
const toolCallId = (
|
|
5952
|
+
const toolCallId = (_f = (_e = part.call_id) != null ? _e : hostedToolSearchCallIds.shift()) != null ? _f : part.id;
|
|
5609
5953
|
content.push({
|
|
5610
5954
|
type: "tool-result",
|
|
5611
5955
|
toolCallId,
|
|
@@ -5676,7 +6020,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5676
6020
|
}
|
|
5677
6021
|
case "message": {
|
|
5678
6022
|
for (const contentPart of part.content) {
|
|
5679
|
-
if (((
|
|
6023
|
+
if (((_h = (_g = options.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.logprobs) && contentPart.logprobs) {
|
|
5680
6024
|
logprobs.push(contentPart.logprobs);
|
|
5681
6025
|
}
|
|
5682
6026
|
const providerMetadata2 = {
|
|
@@ -5698,7 +6042,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5698
6042
|
content.push({
|
|
5699
6043
|
type: "source",
|
|
5700
6044
|
sourceType: "url",
|
|
5701
|
-
id: (
|
|
6045
|
+
id: (_k = (_j = (_i = this.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : (0, import_provider_utils31.generateId)(),
|
|
5702
6046
|
url: annotation.url,
|
|
5703
6047
|
title: annotation.title
|
|
5704
6048
|
});
|
|
@@ -5706,7 +6050,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5706
6050
|
content.push({
|
|
5707
6051
|
type: "source",
|
|
5708
6052
|
sourceType: "document",
|
|
5709
|
-
id: (
|
|
6053
|
+
id: (_n = (_m = (_l = this.config).generateId) == null ? void 0 : _m.call(_l)) != null ? _n : (0, import_provider_utils31.generateId)(),
|
|
5710
6054
|
mediaType: "text/plain",
|
|
5711
6055
|
title: annotation.filename,
|
|
5712
6056
|
filename: annotation.filename,
|
|
@@ -5722,7 +6066,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5722
6066
|
content.push({
|
|
5723
6067
|
type: "source",
|
|
5724
6068
|
sourceType: "document",
|
|
5725
|
-
id: (
|
|
6069
|
+
id: (_q = (_p = (_o = this.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : (0, import_provider_utils31.generateId)(),
|
|
5726
6070
|
mediaType: "text/plain",
|
|
5727
6071
|
title: annotation.filename,
|
|
5728
6072
|
filename: annotation.filename,
|
|
@@ -5738,7 +6082,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5738
6082
|
content.push({
|
|
5739
6083
|
type: "source",
|
|
5740
6084
|
sourceType: "document",
|
|
5741
|
-
id: (
|
|
6085
|
+
id: (_t = (_s = (_r = this.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : (0, import_provider_utils31.generateId)(),
|
|
5742
6086
|
mediaType: "application/octet-stream",
|
|
5743
6087
|
title: annotation.file_id,
|
|
5744
6088
|
filename: annotation.file_id,
|
|
@@ -5757,6 +6101,20 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5757
6101
|
}
|
|
5758
6102
|
case "function_call": {
|
|
5759
6103
|
hasFunctionCall = true;
|
|
6104
|
+
const expandedToolCalls = await expandParallelToolCall({
|
|
6105
|
+
toolCall: {
|
|
6106
|
+
toolCallId: part.call_id,
|
|
6107
|
+
toolName: part.name,
|
|
6108
|
+
input: part.arguments
|
|
6109
|
+
},
|
|
6110
|
+
tools: functionTools,
|
|
6111
|
+
providerOptionsName,
|
|
6112
|
+
itemId: part.id
|
|
6113
|
+
});
|
|
6114
|
+
if (expandedToolCalls != null) {
|
|
6115
|
+
content.push(...expandedToolCalls);
|
|
6116
|
+
break;
|
|
6117
|
+
}
|
|
5760
6118
|
content.push({
|
|
5761
6119
|
type: "tool-call",
|
|
5762
6120
|
toolCallId: part.call_id,
|
|
@@ -5808,7 +6166,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5808
6166
|
break;
|
|
5809
6167
|
}
|
|
5810
6168
|
case "mcp_call": {
|
|
5811
|
-
const toolCallId = part.approval_request_id != null ? (
|
|
6169
|
+
const toolCallId = part.approval_request_id != null ? (_u = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _u : part.id : part.id;
|
|
5812
6170
|
const toolName = `mcp.${part.name}`;
|
|
5813
6171
|
content.push({
|
|
5814
6172
|
type: "tool-call",
|
|
@@ -5842,8 +6200,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5842
6200
|
break;
|
|
5843
6201
|
}
|
|
5844
6202
|
case "mcp_approval_request": {
|
|
5845
|
-
const approvalRequestId = (
|
|
5846
|
-
const dummyToolCallId = (
|
|
6203
|
+
const approvalRequestId = (_v = part.approval_request_id) != null ? _v : part.id;
|
|
6204
|
+
const dummyToolCallId = (_y = (_x = (_w = this.config).generateId) == null ? void 0 : _x.call(_w)) != null ? _y : (0, import_provider_utils31.generateId)();
|
|
5847
6205
|
const toolName = `mcp.${part.name}`;
|
|
5848
6206
|
content.push({
|
|
5849
6207
|
type: "tool-call",
|
|
@@ -5893,13 +6251,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5893
6251
|
toolName: toolNameMapping.toCustomToolName("file_search"),
|
|
5894
6252
|
result: {
|
|
5895
6253
|
queries: part.queries,
|
|
5896
|
-
results: (
|
|
6254
|
+
results: (_A = (_z = part.results) == null ? void 0 : _z.map((result) => ({
|
|
5897
6255
|
attributes: result.attributes,
|
|
5898
6256
|
fileId: result.file_id,
|
|
5899
6257
|
filename: result.filename,
|
|
5900
6258
|
score: result.score,
|
|
5901
6259
|
text: result.text
|
|
5902
|
-
}))) != null ?
|
|
6260
|
+
}))) != null ? _A : null
|
|
5903
6261
|
}
|
|
5904
6262
|
});
|
|
5905
6263
|
break;
|
|
@@ -5949,7 +6307,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5949
6307
|
responseId: response.id,
|
|
5950
6308
|
...logprobs.length > 0 ? { logprobs } : {},
|
|
5951
6309
|
...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
|
|
5952
|
-
...((
|
|
6310
|
+
...((_B = response.reasoning) == null ? void 0 : _B.context) != null ? { reasoningContext: response.reasoning.context } : {}
|
|
5953
6311
|
}
|
|
5954
6312
|
};
|
|
5955
6313
|
const usage = response.usage;
|
|
@@ -5957,10 +6315,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5957
6315
|
content,
|
|
5958
6316
|
finishReason: {
|
|
5959
6317
|
unified: mapOpenAIResponseFinishReason({
|
|
5960
|
-
finishReason: (
|
|
6318
|
+
finishReason: (_C = response.incomplete_details) == null ? void 0 : _C.reason,
|
|
5961
6319
|
hasFunctionCall
|
|
5962
6320
|
}),
|
|
5963
|
-
raw: (
|
|
6321
|
+
raw: (_E = (_D = response.incomplete_details) == null ? void 0 : _D.reason) != null ? _E : void 0
|
|
5964
6322
|
},
|
|
5965
6323
|
usage: convertOpenAIResponsesUsage(usage),
|
|
5966
6324
|
request: { body },
|
|
@@ -5976,6 +6334,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5976
6334
|
};
|
|
5977
6335
|
}
|
|
5978
6336
|
async doStream(options) {
|
|
6337
|
+
var _a, _b;
|
|
5979
6338
|
const {
|
|
5980
6339
|
args: body,
|
|
5981
6340
|
warnings,
|
|
@@ -5989,15 +6348,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5989
6348
|
path: "/responses",
|
|
5990
6349
|
modelId: this.modelId
|
|
5991
6350
|
});
|
|
5992
|
-
const { responseHeaders, value: response } = await (0,
|
|
6351
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils31.postJsonToApi)({
|
|
5993
6352
|
url,
|
|
5994
|
-
headers: (0,
|
|
6353
|
+
headers: (0, import_provider_utils31.combineHeaders)(this.config.headers(), options.headers),
|
|
5995
6354
|
body: {
|
|
5996
6355
|
...body,
|
|
5997
6356
|
stream: true
|
|
5998
6357
|
},
|
|
5999
6358
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
6000
|
-
successfulResponseHandler: (0,
|
|
6359
|
+
successfulResponseHandler: (0, import_provider_utils31.createEventSourceResponseHandler)(
|
|
6001
6360
|
openaiResponsesChunkSchema
|
|
6002
6361
|
),
|
|
6003
6362
|
abortSignal: options.abortSignal,
|
|
@@ -6013,6 +6372,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6013
6372
|
});
|
|
6014
6373
|
const self = this;
|
|
6015
6374
|
const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
|
|
6375
|
+
const functionTools = (_b = (_a = options.tools) == null ? void 0 : _a.filter(
|
|
6376
|
+
(tool) => tool.type === "function"
|
|
6377
|
+
)) != null ? _b : [];
|
|
6016
6378
|
const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
|
|
6017
6379
|
let finishReason = {
|
|
6018
6380
|
unified: "other",
|
|
@@ -6037,7 +6399,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6037
6399
|
controller.enqueue({ type: "stream-start", warnings });
|
|
6038
6400
|
},
|
|
6039
6401
|
transform(chunk, controller) {
|
|
6040
|
-
var
|
|
6402
|
+
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;
|
|
6041
6403
|
if (options.includeRawChunks) {
|
|
6042
6404
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
6043
6405
|
}
|
|
@@ -6056,15 +6418,23 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6056
6418
|
const value = chunk.value;
|
|
6057
6419
|
if (isResponseOutputItemAddedChunk(value)) {
|
|
6058
6420
|
if (value.item.type === "function_call") {
|
|
6421
|
+
const suppressInputStreaming = isUndeclaredParallelToolCall({
|
|
6422
|
+
toolName: value.item.name,
|
|
6423
|
+
tools: functionTools
|
|
6424
|
+
});
|
|
6059
6425
|
ongoingToolCalls[value.output_index] = {
|
|
6060
6426
|
toolName: value.item.name,
|
|
6061
|
-
toolCallId: value.item.call_id
|
|
6427
|
+
toolCallId: value.item.call_id,
|
|
6428
|
+
suppressInputStreaming,
|
|
6429
|
+
bufferedInputDeltas: suppressInputStreaming ? [] : void 0
|
|
6062
6430
|
};
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6431
|
+
if (!suppressInputStreaming) {
|
|
6432
|
+
controller.enqueue({
|
|
6433
|
+
type: "tool-input-start",
|
|
6434
|
+
id: value.item.call_id,
|
|
6435
|
+
toolName: value.item.name
|
|
6436
|
+
});
|
|
6437
|
+
}
|
|
6068
6438
|
} else if (value.item.type === "custom_tool_call") {
|
|
6069
6439
|
const toolName = toolNameMapping.toCustomToolName(
|
|
6070
6440
|
value.item.name
|
|
@@ -6159,7 +6529,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6159
6529
|
ongoingToolCalls[value.output_index] = {
|
|
6160
6530
|
toolName,
|
|
6161
6531
|
toolCallId,
|
|
6162
|
-
toolSearchExecution: (
|
|
6532
|
+
toolSearchExecution: (_a2 = value.item.execution) != null ? _a2 : "server"
|
|
6163
6533
|
};
|
|
6164
6534
|
if (isHosted) {
|
|
6165
6535
|
controller.enqueue({
|
|
@@ -6216,7 +6586,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6216
6586
|
} else if (value.item.type === "shell_call_output") {
|
|
6217
6587
|
} else if (value.item.type === "message") {
|
|
6218
6588
|
ongoingAnnotations.splice(0, ongoingAnnotations.length);
|
|
6219
|
-
activeMessagePhase = (
|
|
6589
|
+
activeMessagePhase = (_b2 = value.item.phase) != null ? _b2 : void 0;
|
|
6220
6590
|
controller.enqueue({
|
|
6221
6591
|
type: "text-start",
|
|
6222
6592
|
id: value.item.id,
|
|
@@ -6263,31 +6633,99 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6263
6633
|
}
|
|
6264
6634
|
});
|
|
6265
6635
|
} else if (value.item.type === "function_call") {
|
|
6636
|
+
const item = value.item;
|
|
6637
|
+
const ongoingToolCall = ongoingToolCalls[value.output_index];
|
|
6266
6638
|
ongoingToolCalls[value.output_index] = void 0;
|
|
6267
6639
|
hasFunctionCall = true;
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6640
|
+
const suppressInputStreaming = (_e = ongoingToolCall == null ? void 0 : ongoingToolCall.suppressInputStreaming) != null ? _e : isUndeclaredParallelToolCall({
|
|
6641
|
+
toolName: item.name,
|
|
6642
|
+
tools: functionTools
|
|
6643
|
+
});
|
|
6644
|
+
const enqueueUnexpandedToolCall = () => {
|
|
6645
|
+
var _a3;
|
|
6646
|
+
if (suppressInputStreaming) {
|
|
6647
|
+
controller.enqueue({
|
|
6648
|
+
type: "tool-input-start",
|
|
6649
|
+
id: item.call_id,
|
|
6650
|
+
toolName: item.name
|
|
6651
|
+
});
|
|
6652
|
+
const bufferedInputDeltas = (_a3 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a3 : [];
|
|
6653
|
+
if (bufferedInputDeltas.length > 0) {
|
|
6654
|
+
for (const delta of bufferedInputDeltas) {
|
|
6655
|
+
controller.enqueue({
|
|
6656
|
+
type: "tool-input-delta",
|
|
6657
|
+
id: item.call_id,
|
|
6658
|
+
delta
|
|
6659
|
+
});
|
|
6275
6660
|
}
|
|
6661
|
+
} else if (item.arguments.length > 0) {
|
|
6662
|
+
controller.enqueue({
|
|
6663
|
+
type: "tool-input-delta",
|
|
6664
|
+
id: item.call_id,
|
|
6665
|
+
delta: item.arguments
|
|
6666
|
+
});
|
|
6276
6667
|
}
|
|
6277
6668
|
}
|
|
6278
|
-
|
|
6279
|
-
|
|
6280
|
-
|
|
6281
|
-
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
|
|
6669
|
+
controller.enqueue({
|
|
6670
|
+
type: "tool-input-end",
|
|
6671
|
+
id: item.call_id,
|
|
6672
|
+
...item.namespace != null && {
|
|
6673
|
+
providerMetadata: {
|
|
6674
|
+
[providerOptionsName]: {
|
|
6675
|
+
namespace: item.namespace
|
|
6676
|
+
}
|
|
6677
|
+
}
|
|
6678
|
+
}
|
|
6679
|
+
});
|
|
6680
|
+
controller.enqueue({
|
|
6681
|
+
type: "tool-call",
|
|
6682
|
+
toolCallId: item.call_id,
|
|
6683
|
+
toolName: item.name,
|
|
6684
|
+
input: item.arguments,
|
|
6685
|
+
providerMetadata: {
|
|
6686
|
+
[providerOptionsName]: {
|
|
6687
|
+
itemId: item.id,
|
|
6688
|
+
...item.namespace != null && {
|
|
6689
|
+
namespace: item.namespace
|
|
6690
|
+
}
|
|
6289
6691
|
}
|
|
6290
6692
|
}
|
|
6693
|
+
});
|
|
6694
|
+
};
|
|
6695
|
+
if (!suppressInputStreaming) {
|
|
6696
|
+
enqueueUnexpandedToolCall();
|
|
6697
|
+
return;
|
|
6698
|
+
}
|
|
6699
|
+
return expandParallelToolCall({
|
|
6700
|
+
toolCall: {
|
|
6701
|
+
toolCallId: item.call_id,
|
|
6702
|
+
toolName: item.name,
|
|
6703
|
+
input: item.arguments
|
|
6704
|
+
},
|
|
6705
|
+
tools: functionTools,
|
|
6706
|
+
providerOptionsName,
|
|
6707
|
+
itemId: item.id
|
|
6708
|
+
}).then((expandedToolCalls) => {
|
|
6709
|
+
if (expandedToolCalls == null) {
|
|
6710
|
+
enqueueUnexpandedToolCall();
|
|
6711
|
+
return;
|
|
6712
|
+
}
|
|
6713
|
+
for (const toolCall of expandedToolCalls) {
|
|
6714
|
+
controller.enqueue({
|
|
6715
|
+
type: "tool-input-start",
|
|
6716
|
+
id: toolCall.toolCallId,
|
|
6717
|
+
toolName: toolCall.toolName
|
|
6718
|
+
});
|
|
6719
|
+
controller.enqueue({
|
|
6720
|
+
type: "tool-input-delta",
|
|
6721
|
+
id: toolCall.toolCallId,
|
|
6722
|
+
delta: toolCall.input
|
|
6723
|
+
});
|
|
6724
|
+
controller.enqueue({
|
|
6725
|
+
type: "tool-input-end",
|
|
6726
|
+
id: toolCall.toolCallId
|
|
6727
|
+
});
|
|
6728
|
+
controller.enqueue(toolCall);
|
|
6291
6729
|
}
|
|
6292
6730
|
});
|
|
6293
6731
|
} else if (value.item.type === "custom_tool_call") {
|
|
@@ -6351,13 +6789,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6351
6789
|
toolName: toolNameMapping.toCustomToolName("file_search"),
|
|
6352
6790
|
result: {
|
|
6353
6791
|
queries: value.item.queries,
|
|
6354
|
-
results: (
|
|
6792
|
+
results: (_g = (_f = value.item.results) == null ? void 0 : _f.map((result2) => ({
|
|
6355
6793
|
attributes: result2.attributes,
|
|
6356
6794
|
fileId: result2.file_id,
|
|
6357
6795
|
filename: result2.filename,
|
|
6358
6796
|
score: result2.score,
|
|
6359
6797
|
text: result2.text
|
|
6360
|
-
}))) != null ?
|
|
6798
|
+
}))) != null ? _g : null
|
|
6361
6799
|
}
|
|
6362
6800
|
});
|
|
6363
6801
|
} else if (value.item.type === "code_interpreter_call") {
|
|
@@ -6383,7 +6821,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6383
6821
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
6384
6822
|
const isHosted = value.item.execution === "server";
|
|
6385
6823
|
if (toolCall != null) {
|
|
6386
|
-
const toolCallId = isHosted ? toolCall.toolCallId : (
|
|
6824
|
+
const toolCallId = isHosted ? toolCall.toolCallId : (_h = value.item.call_id) != null ? _h : value.item.id;
|
|
6387
6825
|
if (isHosted) {
|
|
6388
6826
|
hostedToolSearchCallIds.push(toolCallId);
|
|
6389
6827
|
} else {
|
|
@@ -6415,7 +6853,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6415
6853
|
}
|
|
6416
6854
|
ongoingToolCalls[value.output_index] = void 0;
|
|
6417
6855
|
} else if (value.item.type === "tool_search_output") {
|
|
6418
|
-
const toolCallId = (
|
|
6856
|
+
const toolCallId = (_j = (_i = value.item.call_id) != null ? _i : hostedToolSearchCallIds.shift()) != null ? _j : value.item.id;
|
|
6419
6857
|
controller.enqueue({
|
|
6420
6858
|
type: "tool-result",
|
|
6421
6859
|
toolCallId,
|
|
@@ -6431,10 +6869,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6431
6869
|
});
|
|
6432
6870
|
} else if (value.item.type === "mcp_call") {
|
|
6433
6871
|
ongoingToolCalls[value.output_index] = void 0;
|
|
6434
|
-
const approvalRequestId = (
|
|
6435
|
-
const aliasedToolCallId = approvalRequestId != null ? (
|
|
6872
|
+
const approvalRequestId = (_k = value.item.approval_request_id) != null ? _k : void 0;
|
|
6873
|
+
const aliasedToolCallId = approvalRequestId != null ? (_m = (_l = approvalRequestIdToDummyToolCallIdFromStream.get(
|
|
6436
6874
|
approvalRequestId
|
|
6437
|
-
)) != null ?
|
|
6875
|
+
)) != null ? _l : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _m : value.item.id : value.item.id;
|
|
6438
6876
|
const toolName = `mcp.${value.item.name}`;
|
|
6439
6877
|
controller.enqueue({
|
|
6440
6878
|
type: "tool-call",
|
|
@@ -6504,8 +6942,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6504
6942
|
ongoingToolCalls[value.output_index] = void 0;
|
|
6505
6943
|
} else if (value.item.type === "mcp_approval_request") {
|
|
6506
6944
|
ongoingToolCalls[value.output_index] = void 0;
|
|
6507
|
-
const dummyToolCallId = (
|
|
6508
|
-
const approvalRequestId = (
|
|
6945
|
+
const dummyToolCallId = (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : (0, import_provider_utils31.generateId)();
|
|
6946
|
+
const approvalRequestId = (_q = value.item.approval_request_id) != null ? _q : value.item.id;
|
|
6509
6947
|
approvalRequestIdToDummyToolCallIdFromStream.set(
|
|
6510
6948
|
approvalRequestId,
|
|
6511
6949
|
dummyToolCallId
|
|
@@ -6594,7 +7032,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6594
7032
|
providerMetadata: {
|
|
6595
7033
|
[providerOptionsName]: {
|
|
6596
7034
|
itemId: value.item.id,
|
|
6597
|
-
reasoningEncryptedContent: (
|
|
7035
|
+
reasoningEncryptedContent: (_r = value.item.encrypted_content) != null ? _r : null
|
|
6598
7036
|
}
|
|
6599
7037
|
}
|
|
6600
7038
|
});
|
|
@@ -6604,11 +7042,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6604
7042
|
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
6605
7043
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
6606
7044
|
if (toolCall != null) {
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
|
|
6611
|
-
|
|
7045
|
+
if (toolCall.suppressInputStreaming) {
|
|
7046
|
+
(_s = toolCall.bufferedInputDeltas) == null ? void 0 : _s.push(value.delta);
|
|
7047
|
+
} else {
|
|
7048
|
+
controller.enqueue({
|
|
7049
|
+
type: "tool-input-delta",
|
|
7050
|
+
id: toolCall.toolCallId,
|
|
7051
|
+
delta: value.delta
|
|
7052
|
+
});
|
|
7053
|
+
}
|
|
6612
7054
|
}
|
|
6613
7055
|
} else if (isResponseCustomToolCallInputDeltaChunk(value)) {
|
|
6614
7056
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
@@ -6707,7 +7149,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6707
7149
|
id: value.item_id,
|
|
6708
7150
|
delta: value.delta
|
|
6709
7151
|
});
|
|
6710
|
-
if (((
|
|
7152
|
+
if (((_u = (_t = options.providerOptions) == null ? void 0 : _t[providerOptionsName]) == null ? void 0 : _u.logprobs) && value.logprobs) {
|
|
6711
7153
|
logprobs.push(value.logprobs);
|
|
6712
7154
|
}
|
|
6713
7155
|
} else if (value.type === "response.reasoning_summary_part.added") {
|
|
@@ -6736,7 +7178,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6736
7178
|
providerMetadata: {
|
|
6737
7179
|
[providerOptionsName]: {
|
|
6738
7180
|
itemId: value.item_id,
|
|
6739
|
-
reasoningEncryptedContent: (
|
|
7181
|
+
reasoningEncryptedContent: (_w = (_v = activeReasoning[value.item_id]) == null ? void 0 : _v.encryptedContent) != null ? _w : null
|
|
6740
7182
|
}
|
|
6741
7183
|
}
|
|
6742
7184
|
});
|
|
@@ -6770,20 +7212,20 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6770
7212
|
} else if (isResponseFinishedChunk(value)) {
|
|
6771
7213
|
finishReason = {
|
|
6772
7214
|
unified: mapOpenAIResponseFinishReason({
|
|
6773
|
-
finishReason: (
|
|
7215
|
+
finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
|
|
6774
7216
|
hasFunctionCall
|
|
6775
7217
|
}),
|
|
6776
|
-
raw: (
|
|
7218
|
+
raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
|
|
6777
7219
|
};
|
|
6778
7220
|
usage = value.response.usage;
|
|
6779
7221
|
if (typeof value.response.service_tier === "string") {
|
|
6780
7222
|
serviceTier = value.response.service_tier;
|
|
6781
7223
|
}
|
|
6782
|
-
if (((
|
|
7224
|
+
if (((_A = value.response.reasoning) == null ? void 0 : _A.context) != null) {
|
|
6783
7225
|
reasoningContext = value.response.reasoning.context;
|
|
6784
7226
|
}
|
|
6785
7227
|
} else if (isResponseFailedChunk(value)) {
|
|
6786
|
-
const incompleteReason = (
|
|
7228
|
+
const incompleteReason = (_B = value.response.incomplete_details) == null ? void 0 : _B.reason;
|
|
6787
7229
|
finishReason = {
|
|
6788
7230
|
unified: incompleteReason ? mapOpenAIResponseFinishReason({
|
|
6789
7231
|
finishReason: incompleteReason,
|
|
@@ -6791,8 +7233,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6791
7233
|
}) : "error",
|
|
6792
7234
|
raw: incompleteReason != null ? incompleteReason : "error"
|
|
6793
7235
|
};
|
|
6794
|
-
usage = (
|
|
6795
|
-
if (((
|
|
7236
|
+
usage = (_C = value.response.usage) != null ? _C : void 0;
|
|
7237
|
+
if (((_D = value.response.reasoning) == null ? void 0 : _D.context) != null) {
|
|
6796
7238
|
reasoningContext = value.response.reasoning.context;
|
|
6797
7239
|
}
|
|
6798
7240
|
if (!encounteredStreamError && value.response.error != null) {
|
|
@@ -6816,7 +7258,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6816
7258
|
controller.enqueue({
|
|
6817
7259
|
type: "source",
|
|
6818
7260
|
sourceType: "url",
|
|
6819
|
-
id: (
|
|
7261
|
+
id: (_G = (_F = (_E = self.config).generateId) == null ? void 0 : _F.call(_E)) != null ? _G : (0, import_provider_utils31.generateId)(),
|
|
6820
7262
|
url: value.annotation.url,
|
|
6821
7263
|
title: value.annotation.title
|
|
6822
7264
|
});
|
|
@@ -6824,7 +7266,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6824
7266
|
controller.enqueue({
|
|
6825
7267
|
type: "source",
|
|
6826
7268
|
sourceType: "document",
|
|
6827
|
-
id: (
|
|
7269
|
+
id: (_J = (_I = (_H = self.config).generateId) == null ? void 0 : _I.call(_H)) != null ? _J : (0, import_provider_utils31.generateId)(),
|
|
6828
7270
|
mediaType: "text/plain",
|
|
6829
7271
|
title: value.annotation.filename,
|
|
6830
7272
|
filename: value.annotation.filename,
|
|
@@ -6840,7 +7282,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6840
7282
|
controller.enqueue({
|
|
6841
7283
|
type: "source",
|
|
6842
7284
|
sourceType: "document",
|
|
6843
|
-
id: (
|
|
7285
|
+
id: (_M = (_L = (_K = self.config).generateId) == null ? void 0 : _L.call(_K)) != null ? _M : (0, import_provider_utils31.generateId)(),
|
|
6844
7286
|
mediaType: "text/plain",
|
|
6845
7287
|
title: value.annotation.filename,
|
|
6846
7288
|
filename: value.annotation.filename,
|
|
@@ -6856,7 +7298,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6856
7298
|
controller.enqueue({
|
|
6857
7299
|
type: "source",
|
|
6858
7300
|
sourceType: "document",
|
|
6859
|
-
id: (
|
|
7301
|
+
id: (_P = (_O = (_N = self.config).generateId) == null ? void 0 : _O.call(_N)) != null ? _P : (0, import_provider_utils31.generateId)(),
|
|
6860
7302
|
mediaType: "application/octet-stream",
|
|
6861
7303
|
title: value.annotation.file_id,
|
|
6862
7304
|
filename: value.annotation.file_id,
|
|
@@ -6876,6 +7318,24 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6876
7318
|
}
|
|
6877
7319
|
},
|
|
6878
7320
|
flush(controller) {
|
|
7321
|
+
var _a2;
|
|
7322
|
+
for (const toolCall of Object.values(ongoingToolCalls)) {
|
|
7323
|
+
if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
|
|
7324
|
+
continue;
|
|
7325
|
+
}
|
|
7326
|
+
controller.enqueue({
|
|
7327
|
+
type: "tool-input-start",
|
|
7328
|
+
id: toolCall.toolCallId,
|
|
7329
|
+
toolName: toolCall.toolName
|
|
7330
|
+
});
|
|
7331
|
+
for (const delta of (_a2 = toolCall.bufferedInputDeltas) != null ? _a2 : []) {
|
|
7332
|
+
controller.enqueue({
|
|
7333
|
+
type: "tool-input-delta",
|
|
7334
|
+
id: toolCall.toolCallId,
|
|
7335
|
+
delta
|
|
7336
|
+
});
|
|
7337
|
+
}
|
|
7338
|
+
}
|
|
6879
7339
|
const providerMetadata = {
|
|
6880
7340
|
[providerOptionsName]: {
|
|
6881
7341
|
responseId,
|
|
@@ -6913,7 +7373,7 @@ function createOpenAIResponsesChatCompletionsMismatchError({
|
|
|
6913
7373
|
requestBodyValues,
|
|
6914
7374
|
responseHeaders
|
|
6915
7375
|
}) {
|
|
6916
|
-
return new
|
|
7376
|
+
return new import_provider10.APICallError({
|
|
6917
7377
|
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.",
|
|
6918
7378
|
url,
|
|
6919
7379
|
requestBodyValues,
|
|
@@ -7005,13 +7465,13 @@ function escapeJSONDelta(delta) {
|
|
|
7005
7465
|
}
|
|
7006
7466
|
|
|
7007
7467
|
// src/speech/openai-speech-model.ts
|
|
7008
|
-
var
|
|
7468
|
+
var import_provider_utils33 = require("@ai-sdk/provider-utils");
|
|
7009
7469
|
|
|
7010
7470
|
// src/speech/openai-speech-options.ts
|
|
7011
|
-
var
|
|
7471
|
+
var import_provider_utils32 = require("@ai-sdk/provider-utils");
|
|
7012
7472
|
var import_v424 = require("zod/v4");
|
|
7013
|
-
var openaiSpeechModelOptionsSchema = (0,
|
|
7014
|
-
() => (0,
|
|
7473
|
+
var openaiSpeechModelOptionsSchema = (0, import_provider_utils32.lazySchema)(
|
|
7474
|
+
() => (0, import_provider_utils32.zodSchema)(
|
|
7015
7475
|
import_v424.z.object({
|
|
7016
7476
|
instructions: import_v424.z.string().nullish(),
|
|
7017
7477
|
speed: import_v424.z.number().min(0.25).max(4).default(1).nullish()
|
|
@@ -7039,7 +7499,7 @@ var OpenAISpeechModel = class {
|
|
|
7039
7499
|
providerOptions
|
|
7040
7500
|
}) {
|
|
7041
7501
|
const warnings = [];
|
|
7042
|
-
const openAIOptions = await (0,
|
|
7502
|
+
const openAIOptions = await (0, import_provider_utils33.parseProviderOptions)({
|
|
7043
7503
|
provider: "openai",
|
|
7044
7504
|
providerOptions,
|
|
7045
7505
|
schema: openaiSpeechModelOptionsSchema
|
|
@@ -7092,15 +7552,15 @@ var OpenAISpeechModel = class {
|
|
|
7092
7552
|
value: audio,
|
|
7093
7553
|
responseHeaders,
|
|
7094
7554
|
rawValue: rawResponse
|
|
7095
|
-
} = await (0,
|
|
7555
|
+
} = await (0, import_provider_utils33.postJsonToApi)({
|
|
7096
7556
|
url: this.config.url({
|
|
7097
7557
|
path: "/audio/speech",
|
|
7098
7558
|
modelId: this.modelId
|
|
7099
7559
|
}),
|
|
7100
|
-
headers: (0,
|
|
7560
|
+
headers: (0, import_provider_utils33.combineHeaders)(this.config.headers(), options.headers),
|
|
7101
7561
|
body: requestBody,
|
|
7102
7562
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
7103
|
-
successfulResponseHandler: (0,
|
|
7563
|
+
successfulResponseHandler: (0, import_provider_utils33.createBinaryResponseHandler)(),
|
|
7104
7564
|
abortSignal: options.abortSignal,
|
|
7105
7565
|
fetch: this.config.fetch
|
|
7106
7566
|
});
|
|
@@ -7121,13 +7581,13 @@ var OpenAISpeechModel = class {
|
|
|
7121
7581
|
};
|
|
7122
7582
|
|
|
7123
7583
|
// src/transcription/openai-transcription-model.ts
|
|
7124
|
-
var
|
|
7584
|
+
var import_provider_utils36 = require("@ai-sdk/provider-utils");
|
|
7125
7585
|
|
|
7126
7586
|
// src/transcription/openai-transcription-api.ts
|
|
7127
|
-
var
|
|
7587
|
+
var import_provider_utils34 = require("@ai-sdk/provider-utils");
|
|
7128
7588
|
var import_v425 = require("zod/v4");
|
|
7129
|
-
var openaiTranscriptionResponseSchema = (0,
|
|
7130
|
-
() => (0,
|
|
7589
|
+
var openaiTranscriptionResponseSchema = (0, import_provider_utils34.lazySchema)(
|
|
7590
|
+
() => (0, import_provider_utils34.zodSchema)(
|
|
7131
7591
|
import_v425.z.object({
|
|
7132
7592
|
text: import_v425.z.string(),
|
|
7133
7593
|
language: import_v425.z.string().nullish(),
|
|
@@ -7158,10 +7618,10 @@ var openaiTranscriptionResponseSchema = (0, import_provider_utils33.lazySchema)(
|
|
|
7158
7618
|
);
|
|
7159
7619
|
|
|
7160
7620
|
// src/transcription/openai-transcription-options.ts
|
|
7161
|
-
var
|
|
7621
|
+
var import_provider_utils35 = require("@ai-sdk/provider-utils");
|
|
7162
7622
|
var import_v426 = require("zod/v4");
|
|
7163
|
-
var openAITranscriptionModelOptions = (0,
|
|
7164
|
-
() => (0,
|
|
7623
|
+
var openAITranscriptionModelOptions = (0, import_provider_utils35.lazySchema)(
|
|
7624
|
+
() => (0, import_provider_utils35.zodSchema)(
|
|
7165
7625
|
import_v426.z.object({
|
|
7166
7626
|
/**
|
|
7167
7627
|
* Additional information to include in the transcription response.
|
|
@@ -7264,15 +7724,15 @@ var OpenAITranscriptionModel = class {
|
|
|
7264
7724
|
providerOptions
|
|
7265
7725
|
}) {
|
|
7266
7726
|
const warnings = [];
|
|
7267
|
-
const openAIOptions = await (0,
|
|
7727
|
+
const openAIOptions = await (0, import_provider_utils36.parseProviderOptions)({
|
|
7268
7728
|
provider: "openai",
|
|
7269
7729
|
providerOptions,
|
|
7270
7730
|
schema: openAITranscriptionModelOptions
|
|
7271
7731
|
});
|
|
7272
7732
|
const formData = new FormData();
|
|
7273
|
-
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0,
|
|
7733
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils36.convertBase64ToUint8Array)(audio)]);
|
|
7274
7734
|
formData.append("model", this.modelId);
|
|
7275
|
-
const fileExtension = (0,
|
|
7735
|
+
const fileExtension = (0, import_provider_utils36.mediaTypeToExtension)(mediaType);
|
|
7276
7736
|
formData.append(
|
|
7277
7737
|
"file",
|
|
7278
7738
|
new File([blob], "audio", { type: mediaType }),
|
|
@@ -7317,15 +7777,15 @@ var OpenAITranscriptionModel = class {
|
|
|
7317
7777
|
value: response,
|
|
7318
7778
|
responseHeaders,
|
|
7319
7779
|
rawValue: rawResponse
|
|
7320
|
-
} = await (0,
|
|
7780
|
+
} = await (0, import_provider_utils36.postFormDataToApi)({
|
|
7321
7781
|
url: this.config.url({
|
|
7322
7782
|
path: "/audio/transcriptions",
|
|
7323
7783
|
modelId: this.modelId
|
|
7324
7784
|
}),
|
|
7325
|
-
headers: (0,
|
|
7785
|
+
headers: (0, import_provider_utils36.combineHeaders)(this.config.headers(), options.headers),
|
|
7326
7786
|
formData,
|
|
7327
7787
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
7328
|
-
successfulResponseHandler: (0,
|
|
7788
|
+
successfulResponseHandler: (0, import_provider_utils36.createJsonResponseHandler)(
|
|
7329
7789
|
openaiTranscriptionResponseSchema
|
|
7330
7790
|
),
|
|
7331
7791
|
abortSignal: options.abortSignal,
|
|
@@ -7357,21 +7817,21 @@ var OpenAITranscriptionModel = class {
|
|
|
7357
7817
|
};
|
|
7358
7818
|
|
|
7359
7819
|
// src/version.ts
|
|
7360
|
-
var VERSION = true ? "3.0.
|
|
7820
|
+
var VERSION = true ? "3.0.99" : "0.0.0-test";
|
|
7361
7821
|
|
|
7362
7822
|
// src/openai-provider.ts
|
|
7363
7823
|
function createOpenAI(options = {}) {
|
|
7364
7824
|
var _a, _b;
|
|
7365
|
-
const baseURL = (_a = (0,
|
|
7366
|
-
(0,
|
|
7825
|
+
const baseURL = (_a = (0, import_provider_utils37.withoutTrailingSlash)(
|
|
7826
|
+
(0, import_provider_utils37.loadOptionalSetting)({
|
|
7367
7827
|
settingValue: options.baseURL,
|
|
7368
7828
|
environmentVariableName: "OPENAI_BASE_URL"
|
|
7369
7829
|
})
|
|
7370
7830
|
)) != null ? _a : "https://api.openai.com/v1";
|
|
7371
7831
|
const providerName = (_b = options.name) != null ? _b : "openai";
|
|
7372
|
-
const getHeaders = () => (0,
|
|
7832
|
+
const getHeaders = () => (0, import_provider_utils37.withUserAgentSuffix)(
|
|
7373
7833
|
{
|
|
7374
|
-
Authorization: `Bearer ${(0,
|
|
7834
|
+
Authorization: `Bearer ${(0, import_provider_utils37.loadApiKey)({
|
|
7375
7835
|
apiKey: options.apiKey,
|
|
7376
7836
|
environmentVariableName: "OPENAI_API_KEY",
|
|
7377
7837
|
description: "OpenAI"
|