@ai-sdk/openai 3.0.98 → 3.0.100
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 +13 -0
- package/dist/index.js +564 -231
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +488 -153
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +584 -253
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +485 -152
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- 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-language-model.ts +171 -29
package/dist/internal/index.mjs
CHANGED
|
@@ -2966,10 +2966,227 @@ var toolSearchToolFactory = createProviderToolFactoryWithOutputSchema4({
|
|
|
2966
2966
|
outputSchema: toolSearchOutputSchema
|
|
2967
2967
|
});
|
|
2968
2968
|
|
|
2969
|
+
// src/responses/expand-parallel-tool-call.ts
|
|
2970
|
+
import {
|
|
2971
|
+
isJSONObject
|
|
2972
|
+
} from "@ai-sdk/provider";
|
|
2973
|
+
import { safeParseJSON } from "@ai-sdk/provider-utils";
|
|
2974
|
+
var parallelToolName = "parallel";
|
|
2975
|
+
var recipientNamePrefix = "functions.";
|
|
2976
|
+
function getParallelToolCallMetadata({
|
|
2977
|
+
providerOptions,
|
|
2978
|
+
providerOptionsName
|
|
2979
|
+
}) {
|
|
2980
|
+
var _a;
|
|
2981
|
+
const metadata = (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.parallelToolCall;
|
|
2982
|
+
if (!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) {
|
|
2983
|
+
return void 0;
|
|
2984
|
+
}
|
|
2985
|
+
return metadata;
|
|
2986
|
+
}
|
|
2987
|
+
function isUndeclaredParallelToolCall({
|
|
2988
|
+
toolName,
|
|
2989
|
+
tools
|
|
2990
|
+
}) {
|
|
2991
|
+
return toolName === parallelToolName && !tools.some((tool) => tool.name === parallelToolName);
|
|
2992
|
+
}
|
|
2993
|
+
async function expandParallelToolCall({
|
|
2994
|
+
toolCall,
|
|
2995
|
+
tools,
|
|
2996
|
+
providerOptionsName,
|
|
2997
|
+
itemId
|
|
2998
|
+
}) {
|
|
2999
|
+
if (!isUndeclaredParallelToolCall({ toolName: toolCall.toolName, tools })) {
|
|
3000
|
+
return void 0;
|
|
3001
|
+
}
|
|
3002
|
+
const parsedInput = await safeParseJSON({ text: toolCall.input });
|
|
3003
|
+
if (!parsedInput.success || !isJSONObject(parsedInput.value)) {
|
|
3004
|
+
return void 0;
|
|
3005
|
+
}
|
|
3006
|
+
const toolUses = parsedInput.value.tool_uses;
|
|
3007
|
+
if (!Array.isArray(toolUses) || toolUses.length === 0) {
|
|
3008
|
+
return void 0;
|
|
3009
|
+
}
|
|
3010
|
+
const availableToolNames = new Set(tools.map((tool) => tool.name));
|
|
3011
|
+
const expandedToolCalls = [];
|
|
3012
|
+
for (const [index, toolUse] of toolUses.entries()) {
|
|
3013
|
+
if (!isJSONObject(toolUse)) {
|
|
3014
|
+
return void 0;
|
|
3015
|
+
}
|
|
3016
|
+
const recipientName = toolUse.recipient_name;
|
|
3017
|
+
const parameters = toolUse.parameters;
|
|
3018
|
+
if (typeof recipientName !== "string" || !recipientName.startsWith(recipientNamePrefix) || !isJSONObject(parameters)) {
|
|
3019
|
+
return void 0;
|
|
3020
|
+
}
|
|
3021
|
+
const toolName = recipientName.slice(recipientNamePrefix.length);
|
|
3022
|
+
if (toolName.length === 0 || !availableToolNames.has(toolName)) {
|
|
3023
|
+
return void 0;
|
|
3024
|
+
}
|
|
3025
|
+
expandedToolCalls.push({
|
|
3026
|
+
type: "tool-call",
|
|
3027
|
+
toolCallId: `${toolCall.toolCallId}_${index}`,
|
|
3028
|
+
toolName,
|
|
3029
|
+
input: JSON.stringify(parameters),
|
|
3030
|
+
providerMetadata: {
|
|
3031
|
+
[providerOptionsName]: {
|
|
3032
|
+
parallelToolCall: {
|
|
3033
|
+
itemId,
|
|
3034
|
+
toolCallId: toolCall.toolCallId,
|
|
3035
|
+
toolName: toolCall.toolName,
|
|
3036
|
+
input: toolCall.input,
|
|
3037
|
+
index,
|
|
3038
|
+
count: toolUses.length
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
});
|
|
3043
|
+
}
|
|
3044
|
+
return expandedToolCalls;
|
|
3045
|
+
}
|
|
3046
|
+
|
|
2969
3047
|
// src/responses/convert-to-openai-responses-input.ts
|
|
2970
3048
|
function serializeToolCallArguments2(input) {
|
|
2971
3049
|
return JSON.stringify(input === void 0 ? {} : input);
|
|
2972
3050
|
}
|
|
3051
|
+
async function convertFunctionToolResultOutput({
|
|
3052
|
+
output,
|
|
3053
|
+
providerOptionsName,
|
|
3054
|
+
warnings
|
|
3055
|
+
}) {
|
|
3056
|
+
var _a;
|
|
3057
|
+
switch (output.type) {
|
|
3058
|
+
case "text":
|
|
3059
|
+
case "error-text":
|
|
3060
|
+
return output.value;
|
|
3061
|
+
case "execution-denied":
|
|
3062
|
+
return (_a = output.reason) != null ? _a : "Tool call execution denied.";
|
|
3063
|
+
case "json":
|
|
3064
|
+
case "error-json":
|
|
3065
|
+
return JSON.stringify(output.value);
|
|
3066
|
+
case "content":
|
|
3067
|
+
return output.value.map((item) => {
|
|
3068
|
+
var _a2, _b, _c, _d, _e;
|
|
3069
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
3070
|
+
item.providerOptions,
|
|
3071
|
+
providerOptionsName
|
|
3072
|
+
);
|
|
3073
|
+
switch (item.type) {
|
|
3074
|
+
case "text": {
|
|
3075
|
+
return {
|
|
3076
|
+
type: "input_text",
|
|
3077
|
+
text: item.text,
|
|
3078
|
+
...promptCacheBreakpoint != null && {
|
|
3079
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3080
|
+
}
|
|
3081
|
+
};
|
|
3082
|
+
}
|
|
3083
|
+
case "image-data": {
|
|
3084
|
+
return {
|
|
3085
|
+
type: "input_image",
|
|
3086
|
+
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3087
|
+
detail: (_b = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b.imageDetail,
|
|
3088
|
+
...promptCacheBreakpoint != null && {
|
|
3089
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3090
|
+
}
|
|
3091
|
+
};
|
|
3092
|
+
}
|
|
3093
|
+
case "image-url": {
|
|
3094
|
+
return {
|
|
3095
|
+
type: "input_image",
|
|
3096
|
+
image_url: item.url,
|
|
3097
|
+
detail: (_d = (_c = item.providerOptions) == null ? void 0 : _c[providerOptionsName]) == null ? void 0 : _d.imageDetail,
|
|
3098
|
+
...promptCacheBreakpoint != null && {
|
|
3099
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3100
|
+
}
|
|
3101
|
+
};
|
|
3102
|
+
}
|
|
3103
|
+
case "file-data": {
|
|
3104
|
+
return {
|
|
3105
|
+
type: "input_file",
|
|
3106
|
+
filename: (_e = item.filename) != null ? _e : "data",
|
|
3107
|
+
file_data: `data:${item.mediaType};base64,${item.data}`,
|
|
3108
|
+
...promptCacheBreakpoint != null && {
|
|
3109
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3110
|
+
}
|
|
3111
|
+
};
|
|
3112
|
+
}
|
|
3113
|
+
case "file-url": {
|
|
3114
|
+
return {
|
|
3115
|
+
type: "input_file",
|
|
3116
|
+
file_url: item.url,
|
|
3117
|
+
...promptCacheBreakpoint != null && {
|
|
3118
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3119
|
+
}
|
|
3120
|
+
};
|
|
3121
|
+
}
|
|
3122
|
+
default: {
|
|
3123
|
+
warnings.push({
|
|
3124
|
+
type: "other",
|
|
3125
|
+
message: `unsupported tool content part type: ${item.type}`
|
|
3126
|
+
});
|
|
3127
|
+
return void 0;
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
}).filter(isNonNullable);
|
|
3131
|
+
}
|
|
3132
|
+
}
|
|
3133
|
+
function hasSameParallelToolCall(first, second) {
|
|
3134
|
+
return first.itemId === second.itemId && first.toolCallId === second.toolCallId && first.toolName === second.toolName && first.input === second.input && first.count === second.count;
|
|
3135
|
+
}
|
|
3136
|
+
function collectCompleteParallelToolResultGroups({
|
|
3137
|
+
prompt,
|
|
3138
|
+
providerOptionsName
|
|
3139
|
+
}) {
|
|
3140
|
+
const pendingGroups = /* @__PURE__ */ new Map();
|
|
3141
|
+
for (const message of prompt) {
|
|
3142
|
+
if (message.role !== "tool") {
|
|
3143
|
+
continue;
|
|
3144
|
+
}
|
|
3145
|
+
for (const part of message.content) {
|
|
3146
|
+
if (part.type !== "tool-result") {
|
|
3147
|
+
continue;
|
|
3148
|
+
}
|
|
3149
|
+
const metadata = getParallelToolCallMetadata({
|
|
3150
|
+
providerOptions: part.providerOptions,
|
|
3151
|
+
providerOptionsName
|
|
3152
|
+
});
|
|
3153
|
+
if (metadata == null) {
|
|
3154
|
+
continue;
|
|
3155
|
+
}
|
|
3156
|
+
const existing = pendingGroups.get(metadata.toolCallId);
|
|
3157
|
+
if (existing == null) {
|
|
3158
|
+
pendingGroups.set(metadata.toolCallId, {
|
|
3159
|
+
metadata,
|
|
3160
|
+
results: /* @__PURE__ */ new Map([[metadata.index, part]]),
|
|
3161
|
+
invalid: false
|
|
3162
|
+
});
|
|
3163
|
+
continue;
|
|
3164
|
+
}
|
|
3165
|
+
if (!hasSameParallelToolCall(existing.metadata, metadata) || existing.results.has(metadata.index)) {
|
|
3166
|
+
existing.invalid = true;
|
|
3167
|
+
continue;
|
|
3168
|
+
}
|
|
3169
|
+
existing.results.set(metadata.index, part);
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
3172
|
+
const completeGroups = /* @__PURE__ */ new Map();
|
|
3173
|
+
for (const [toolCallId, group] of pendingGroups) {
|
|
3174
|
+
if (group.invalid || group.results.size !== group.metadata.count) {
|
|
3175
|
+
continue;
|
|
3176
|
+
}
|
|
3177
|
+
const results = Array.from(
|
|
3178
|
+
{ length: group.metadata.count },
|
|
3179
|
+
(_, index) => group.results.get(index)
|
|
3180
|
+
);
|
|
3181
|
+
if (results.every(isNonNullable)) {
|
|
3182
|
+
completeGroups.set(toolCallId, {
|
|
3183
|
+
metadata: group.metadata,
|
|
3184
|
+
results
|
|
3185
|
+
});
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
return completeGroups;
|
|
3189
|
+
}
|
|
2973
3190
|
function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
|
|
2974
3191
|
var _a;
|
|
2975
3192
|
return (_a = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a.promptCacheBreakpoint;
|
|
@@ -2993,10 +3210,16 @@ async function convertToOpenAIResponsesInput({
|
|
|
2993
3210
|
hasApplyPatchTool = false,
|
|
2994
3211
|
customProviderToolNames
|
|
2995
3212
|
}) {
|
|
2996
|
-
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
|
|
3213
|
+
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;
|
|
2997
3214
|
let input = [];
|
|
2998
3215
|
const warnings = [];
|
|
2999
3216
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
3217
|
+
const parallelToolResultGroups = hasConversation || hasPreviousResponseId ? collectCompleteParallelToolResultGroups({
|
|
3218
|
+
prompt,
|
|
3219
|
+
providerOptionsName
|
|
3220
|
+
}) : /* @__PURE__ */ new Map();
|
|
3221
|
+
const emittedParallelToolCalls = /* @__PURE__ */ new Set();
|
|
3222
|
+
const emittedParallelToolResults = /* @__PURE__ */ new Set();
|
|
3000
3223
|
for (const { role, content, providerOptions } of prompt) {
|
|
3001
3224
|
switch (role) {
|
|
3002
3225
|
case "system": {
|
|
@@ -3142,6 +3365,34 @@ async function convertToOpenAIResponsesInput({
|
|
|
3142
3365
|
break;
|
|
3143
3366
|
}
|
|
3144
3367
|
case "tool-call": {
|
|
3368
|
+
const parallelToolCallMetadata = getParallelToolCallMetadata({
|
|
3369
|
+
providerOptions: part.providerOptions,
|
|
3370
|
+
providerOptionsName
|
|
3371
|
+
});
|
|
3372
|
+
const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
|
|
3373
|
+
parallelToolCallMetadata.toolCallId
|
|
3374
|
+
);
|
|
3375
|
+
if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
|
|
3376
|
+
parallelToolResultGroup.metadata,
|
|
3377
|
+
parallelToolCallMetadata
|
|
3378
|
+
)) {
|
|
3379
|
+
if (!emittedParallelToolCalls.has(
|
|
3380
|
+
parallelToolResultGroup.metadata.toolCallId
|
|
3381
|
+
)) {
|
|
3382
|
+
emittedParallelToolCalls.add(
|
|
3383
|
+
parallelToolResultGroup.metadata.toolCallId
|
|
3384
|
+
);
|
|
3385
|
+
if (!hasConversation) {
|
|
3386
|
+
input.push({
|
|
3387
|
+
type: "function_call",
|
|
3388
|
+
call_id: parallelToolResultGroup.metadata.toolCallId,
|
|
3389
|
+
name: parallelToolResultGroup.metadata.toolName,
|
|
3390
|
+
arguments: parallelToolResultGroup.metadata.input
|
|
3391
|
+
});
|
|
3392
|
+
}
|
|
3393
|
+
}
|
|
3394
|
+
break;
|
|
3395
|
+
}
|
|
3145
3396
|
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;
|
|
3146
3397
|
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;
|
|
3147
3398
|
if (hasConversation && id != null) {
|
|
@@ -3421,6 +3672,44 @@ async function convertToOpenAIResponsesInput({
|
|
|
3421
3672
|
});
|
|
3422
3673
|
continue;
|
|
3423
3674
|
}
|
|
3675
|
+
const parallelToolCallMetadata = getParallelToolCallMetadata({
|
|
3676
|
+
providerOptions: part.providerOptions,
|
|
3677
|
+
providerOptionsName
|
|
3678
|
+
});
|
|
3679
|
+
const parallelToolResultGroup = parallelToolCallMetadata == null ? void 0 : parallelToolResultGroups.get(
|
|
3680
|
+
parallelToolCallMetadata.toolCallId
|
|
3681
|
+
);
|
|
3682
|
+
if (parallelToolCallMetadata != null && parallelToolResultGroup != null && hasSameParallelToolCall(
|
|
3683
|
+
parallelToolResultGroup.metadata,
|
|
3684
|
+
parallelToolCallMetadata
|
|
3685
|
+
)) {
|
|
3686
|
+
if (!emittedParallelToolResults.has(
|
|
3687
|
+
parallelToolResultGroup.metadata.toolCallId
|
|
3688
|
+
)) {
|
|
3689
|
+
emittedParallelToolResults.add(
|
|
3690
|
+
parallelToolResultGroup.metadata.toolCallId
|
|
3691
|
+
);
|
|
3692
|
+
const toolOutputs = await Promise.all(
|
|
3693
|
+
parallelToolResultGroup.results.map(
|
|
3694
|
+
async (result) => convertFunctionToolResultOutput({
|
|
3695
|
+
output: result.output,
|
|
3696
|
+
providerOptionsName,
|
|
3697
|
+
warnings
|
|
3698
|
+
})
|
|
3699
|
+
)
|
|
3700
|
+
);
|
|
3701
|
+
input.push({
|
|
3702
|
+
type: "function_call_output",
|
|
3703
|
+
call_id: parallelToolResultGroup.metadata.toolCallId,
|
|
3704
|
+
// The internal wrapper returns one output containing the child
|
|
3705
|
+
// results in the same order as the original tool_uses array.
|
|
3706
|
+
output: toolOutputs.map(
|
|
3707
|
+
(output2) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
|
|
3708
|
+
).join("\n")
|
|
3709
|
+
});
|
|
3710
|
+
}
|
|
3711
|
+
continue;
|
|
3712
|
+
}
|
|
3424
3713
|
const output = part.output;
|
|
3425
3714
|
if (output.type === "execution-denied") {
|
|
3426
3715
|
const approvalId = (_x = (_w = output.providerOptions) == null ? void 0 : _w.openai) == null ? void 0 : _x.approvalId;
|
|
@@ -3573,86 +3862,11 @@ async function convertToOpenAIResponsesInput({
|
|
|
3573
3862
|
});
|
|
3574
3863
|
continue;
|
|
3575
3864
|
}
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
break;
|
|
3582
|
-
case "execution-denied":
|
|
3583
|
-
contentValue = (_z = output.reason) != null ? _z : "Tool call execution denied.";
|
|
3584
|
-
break;
|
|
3585
|
-
case "json":
|
|
3586
|
-
case "error-json":
|
|
3587
|
-
contentValue = JSON.stringify(output.value);
|
|
3588
|
-
break;
|
|
3589
|
-
case "content":
|
|
3590
|
-
contentValue = output.value.map((item) => {
|
|
3591
|
-
var _a2, _b2, _c2, _d2, _e2;
|
|
3592
|
-
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
3593
|
-
item.providerOptions,
|
|
3594
|
-
providerOptionsName
|
|
3595
|
-
);
|
|
3596
|
-
switch (item.type) {
|
|
3597
|
-
case "text": {
|
|
3598
|
-
return {
|
|
3599
|
-
type: "input_text",
|
|
3600
|
-
text: item.text,
|
|
3601
|
-
...promptCacheBreakpoint != null && {
|
|
3602
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3603
|
-
}
|
|
3604
|
-
};
|
|
3605
|
-
}
|
|
3606
|
-
case "image-data": {
|
|
3607
|
-
return {
|
|
3608
|
-
type: "input_image",
|
|
3609
|
-
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3610
|
-
detail: (_b2 = (_a2 = item.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
3611
|
-
...promptCacheBreakpoint != null && {
|
|
3612
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3613
|
-
}
|
|
3614
|
-
};
|
|
3615
|
-
}
|
|
3616
|
-
case "image-url": {
|
|
3617
|
-
return {
|
|
3618
|
-
type: "input_image",
|
|
3619
|
-
image_url: item.url,
|
|
3620
|
-
detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
|
|
3621
|
-
...promptCacheBreakpoint != null && {
|
|
3622
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3623
|
-
}
|
|
3624
|
-
};
|
|
3625
|
-
}
|
|
3626
|
-
case "file-data": {
|
|
3627
|
-
return {
|
|
3628
|
-
type: "input_file",
|
|
3629
|
-
filename: (_e2 = item.filename) != null ? _e2 : "data",
|
|
3630
|
-
file_data: `data:${item.mediaType};base64,${item.data}`,
|
|
3631
|
-
...promptCacheBreakpoint != null && {
|
|
3632
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3633
|
-
}
|
|
3634
|
-
};
|
|
3635
|
-
}
|
|
3636
|
-
case "file-url": {
|
|
3637
|
-
return {
|
|
3638
|
-
type: "input_file",
|
|
3639
|
-
file_url: item.url,
|
|
3640
|
-
...promptCacheBreakpoint != null && {
|
|
3641
|
-
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3642
|
-
}
|
|
3643
|
-
};
|
|
3644
|
-
}
|
|
3645
|
-
default: {
|
|
3646
|
-
warnings.push({
|
|
3647
|
-
type: "other",
|
|
3648
|
-
message: `unsupported tool content part type: ${item.type}`
|
|
3649
|
-
});
|
|
3650
|
-
return void 0;
|
|
3651
|
-
}
|
|
3652
|
-
}
|
|
3653
|
-
}).filter(isNonNullable);
|
|
3654
|
-
break;
|
|
3655
|
-
}
|
|
3865
|
+
const contentValue = await convertFunctionToolResultOutput({
|
|
3866
|
+
output,
|
|
3867
|
+
providerOptionsName,
|
|
3868
|
+
warnings
|
|
3869
|
+
});
|
|
3656
3870
|
input.push({
|
|
3657
3871
|
type: "function_call_output",
|
|
3658
3872
|
call_id: part.toolCallId,
|
|
@@ -5974,7 +6188,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5974
6188
|
};
|
|
5975
6189
|
}
|
|
5976
6190
|
async doGenerate(options) {
|
|
5977
|
-
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;
|
|
6191
|
+
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;
|
|
5978
6192
|
const {
|
|
5979
6193
|
args: body,
|
|
5980
6194
|
warnings,
|
|
@@ -6016,6 +6230,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6016
6230
|
}
|
|
6017
6231
|
const content = [];
|
|
6018
6232
|
const logprobs = [];
|
|
6233
|
+
const functionTools = (_b = (_a = options.tools) == null ? void 0 : _a.filter(
|
|
6234
|
+
(tool) => tool.type === "function"
|
|
6235
|
+
)) != null ? _b : [];
|
|
6019
6236
|
let hasFunctionCall = false;
|
|
6020
6237
|
const hostedToolSearchCallIds = [];
|
|
6021
6238
|
for (const part of response.output) {
|
|
@@ -6031,7 +6248,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6031
6248
|
providerMetadata: {
|
|
6032
6249
|
[providerOptionsName]: {
|
|
6033
6250
|
itemId: part.id,
|
|
6034
|
-
reasoningEncryptedContent: (
|
|
6251
|
+
reasoningEncryptedContent: (_c = part.encrypted_content) != null ? _c : null
|
|
6035
6252
|
}
|
|
6036
6253
|
}
|
|
6037
6254
|
});
|
|
@@ -6057,7 +6274,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6057
6274
|
break;
|
|
6058
6275
|
}
|
|
6059
6276
|
case "tool_search_call": {
|
|
6060
|
-
const toolCallId = (
|
|
6277
|
+
const toolCallId = (_d = part.call_id) != null ? _d : part.id;
|
|
6061
6278
|
const isHosted = part.execution === "server";
|
|
6062
6279
|
if (isHosted) {
|
|
6063
6280
|
hostedToolSearchCallIds.push(toolCallId);
|
|
@@ -6080,7 +6297,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6080
6297
|
break;
|
|
6081
6298
|
}
|
|
6082
6299
|
case "tool_search_output": {
|
|
6083
|
-
const toolCallId = (
|
|
6300
|
+
const toolCallId = (_f = (_e = part.call_id) != null ? _e : hostedToolSearchCallIds.shift()) != null ? _f : part.id;
|
|
6084
6301
|
content.push({
|
|
6085
6302
|
type: "tool-result",
|
|
6086
6303
|
toolCallId,
|
|
@@ -6151,7 +6368,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6151
6368
|
}
|
|
6152
6369
|
case "message": {
|
|
6153
6370
|
for (const contentPart of part.content) {
|
|
6154
|
-
if (((
|
|
6371
|
+
if (((_h = (_g = options.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.logprobs) && contentPart.logprobs) {
|
|
6155
6372
|
logprobs.push(contentPart.logprobs);
|
|
6156
6373
|
}
|
|
6157
6374
|
const providerMetadata2 = {
|
|
@@ -6173,7 +6390,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6173
6390
|
content.push({
|
|
6174
6391
|
type: "source",
|
|
6175
6392
|
sourceType: "url",
|
|
6176
|
-
id: (
|
|
6393
|
+
id: (_k = (_j = (_i = this.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : generateId2(),
|
|
6177
6394
|
url: annotation.url,
|
|
6178
6395
|
title: annotation.title
|
|
6179
6396
|
});
|
|
@@ -6181,7 +6398,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6181
6398
|
content.push({
|
|
6182
6399
|
type: "source",
|
|
6183
6400
|
sourceType: "document",
|
|
6184
|
-
id: (
|
|
6401
|
+
id: (_n = (_m = (_l = this.config).generateId) == null ? void 0 : _m.call(_l)) != null ? _n : generateId2(),
|
|
6185
6402
|
mediaType: "text/plain",
|
|
6186
6403
|
title: annotation.filename,
|
|
6187
6404
|
filename: annotation.filename,
|
|
@@ -6197,7 +6414,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6197
6414
|
content.push({
|
|
6198
6415
|
type: "source",
|
|
6199
6416
|
sourceType: "document",
|
|
6200
|
-
id: (
|
|
6417
|
+
id: (_q = (_p = (_o = this.config).generateId) == null ? void 0 : _p.call(_o)) != null ? _q : generateId2(),
|
|
6201
6418
|
mediaType: "text/plain",
|
|
6202
6419
|
title: annotation.filename,
|
|
6203
6420
|
filename: annotation.filename,
|
|
@@ -6213,7 +6430,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6213
6430
|
content.push({
|
|
6214
6431
|
type: "source",
|
|
6215
6432
|
sourceType: "document",
|
|
6216
|
-
id: (
|
|
6433
|
+
id: (_t = (_s = (_r = this.config).generateId) == null ? void 0 : _s.call(_r)) != null ? _t : generateId2(),
|
|
6217
6434
|
mediaType: "application/octet-stream",
|
|
6218
6435
|
title: annotation.file_id,
|
|
6219
6436
|
filename: annotation.file_id,
|
|
@@ -6232,6 +6449,20 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6232
6449
|
}
|
|
6233
6450
|
case "function_call": {
|
|
6234
6451
|
hasFunctionCall = true;
|
|
6452
|
+
const expandedToolCalls = await expandParallelToolCall({
|
|
6453
|
+
toolCall: {
|
|
6454
|
+
toolCallId: part.call_id,
|
|
6455
|
+
toolName: part.name,
|
|
6456
|
+
input: part.arguments
|
|
6457
|
+
},
|
|
6458
|
+
tools: functionTools,
|
|
6459
|
+
providerOptionsName,
|
|
6460
|
+
itemId: part.id
|
|
6461
|
+
});
|
|
6462
|
+
if (expandedToolCalls != null) {
|
|
6463
|
+
content.push(...expandedToolCalls);
|
|
6464
|
+
break;
|
|
6465
|
+
}
|
|
6235
6466
|
content.push({
|
|
6236
6467
|
type: "tool-call",
|
|
6237
6468
|
toolCallId: part.call_id,
|
|
@@ -6283,7 +6514,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6283
6514
|
break;
|
|
6284
6515
|
}
|
|
6285
6516
|
case "mcp_call": {
|
|
6286
|
-
const toolCallId = part.approval_request_id != null ? (
|
|
6517
|
+
const toolCallId = part.approval_request_id != null ? (_u = approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id]) != null ? _u : part.id : part.id;
|
|
6287
6518
|
const toolName = `mcp.${part.name}`;
|
|
6288
6519
|
content.push({
|
|
6289
6520
|
type: "tool-call",
|
|
@@ -6317,8 +6548,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6317
6548
|
break;
|
|
6318
6549
|
}
|
|
6319
6550
|
case "mcp_approval_request": {
|
|
6320
|
-
const approvalRequestId = (
|
|
6321
|
-
const dummyToolCallId = (
|
|
6551
|
+
const approvalRequestId = (_v = part.approval_request_id) != null ? _v : part.id;
|
|
6552
|
+
const dummyToolCallId = (_y = (_x = (_w = this.config).generateId) == null ? void 0 : _x.call(_w)) != null ? _y : generateId2();
|
|
6322
6553
|
const toolName = `mcp.${part.name}`;
|
|
6323
6554
|
content.push({
|
|
6324
6555
|
type: "tool-call",
|
|
@@ -6368,13 +6599,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6368
6599
|
toolName: toolNameMapping.toCustomToolName("file_search"),
|
|
6369
6600
|
result: {
|
|
6370
6601
|
queries: part.queries,
|
|
6371
|
-
results: (
|
|
6602
|
+
results: (_A = (_z = part.results) == null ? void 0 : _z.map((result) => ({
|
|
6372
6603
|
attributes: result.attributes,
|
|
6373
6604
|
fileId: result.file_id,
|
|
6374
6605
|
filename: result.filename,
|
|
6375
6606
|
score: result.score,
|
|
6376
6607
|
text: result.text
|
|
6377
|
-
}))) != null ?
|
|
6608
|
+
}))) != null ? _A : null
|
|
6378
6609
|
}
|
|
6379
6610
|
});
|
|
6380
6611
|
break;
|
|
@@ -6424,7 +6655,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6424
6655
|
responseId: response.id,
|
|
6425
6656
|
...logprobs.length > 0 ? { logprobs } : {},
|
|
6426
6657
|
...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
|
|
6427
|
-
...((
|
|
6658
|
+
...((_B = response.reasoning) == null ? void 0 : _B.context) != null ? { reasoningContext: response.reasoning.context } : {}
|
|
6428
6659
|
}
|
|
6429
6660
|
};
|
|
6430
6661
|
const usage = response.usage;
|
|
@@ -6432,10 +6663,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6432
6663
|
content,
|
|
6433
6664
|
finishReason: {
|
|
6434
6665
|
unified: mapOpenAIResponseFinishReason({
|
|
6435
|
-
finishReason: (
|
|
6666
|
+
finishReason: (_C = response.incomplete_details) == null ? void 0 : _C.reason,
|
|
6436
6667
|
hasFunctionCall
|
|
6437
6668
|
}),
|
|
6438
|
-
raw: (
|
|
6669
|
+
raw: (_E = (_D = response.incomplete_details) == null ? void 0 : _D.reason) != null ? _E : void 0
|
|
6439
6670
|
},
|
|
6440
6671
|
usage: convertOpenAIResponsesUsage(usage),
|
|
6441
6672
|
request: { body },
|
|
@@ -6451,6 +6682,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6451
6682
|
};
|
|
6452
6683
|
}
|
|
6453
6684
|
async doStream(options) {
|
|
6685
|
+
var _a, _b;
|
|
6454
6686
|
const {
|
|
6455
6687
|
args: body,
|
|
6456
6688
|
warnings,
|
|
@@ -6488,6 +6720,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6488
6720
|
});
|
|
6489
6721
|
const self = this;
|
|
6490
6722
|
const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
|
|
6723
|
+
const functionTools = (_b = (_a = options.tools) == null ? void 0 : _a.filter(
|
|
6724
|
+
(tool) => tool.type === "function"
|
|
6725
|
+
)) != null ? _b : [];
|
|
6491
6726
|
const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
|
|
6492
6727
|
let finishReason = {
|
|
6493
6728
|
unified: "other",
|
|
@@ -6512,7 +6747,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6512
6747
|
controller.enqueue({ type: "stream-start", warnings });
|
|
6513
6748
|
},
|
|
6514
6749
|
transform(chunk, controller) {
|
|
6515
|
-
var
|
|
6750
|
+
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;
|
|
6516
6751
|
if (options.includeRawChunks) {
|
|
6517
6752
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
6518
6753
|
}
|
|
@@ -6531,15 +6766,23 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6531
6766
|
const value = chunk.value;
|
|
6532
6767
|
if (isResponseOutputItemAddedChunk(value)) {
|
|
6533
6768
|
if (value.item.type === "function_call") {
|
|
6769
|
+
const suppressInputStreaming = isUndeclaredParallelToolCall({
|
|
6770
|
+
toolName: value.item.name,
|
|
6771
|
+
tools: functionTools
|
|
6772
|
+
});
|
|
6534
6773
|
ongoingToolCalls[value.output_index] = {
|
|
6535
6774
|
toolName: value.item.name,
|
|
6536
|
-
toolCallId: value.item.call_id
|
|
6775
|
+
toolCallId: value.item.call_id,
|
|
6776
|
+
suppressInputStreaming,
|
|
6777
|
+
bufferedInputDeltas: suppressInputStreaming ? [] : void 0
|
|
6537
6778
|
};
|
|
6538
|
-
|
|
6539
|
-
|
|
6540
|
-
|
|
6541
|
-
|
|
6542
|
-
|
|
6779
|
+
if (!suppressInputStreaming) {
|
|
6780
|
+
controller.enqueue({
|
|
6781
|
+
type: "tool-input-start",
|
|
6782
|
+
id: value.item.call_id,
|
|
6783
|
+
toolName: value.item.name
|
|
6784
|
+
});
|
|
6785
|
+
}
|
|
6543
6786
|
} else if (value.item.type === "custom_tool_call") {
|
|
6544
6787
|
const toolName = toolNameMapping.toCustomToolName(
|
|
6545
6788
|
value.item.name
|
|
@@ -6634,7 +6877,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6634
6877
|
ongoingToolCalls[value.output_index] = {
|
|
6635
6878
|
toolName,
|
|
6636
6879
|
toolCallId,
|
|
6637
|
-
toolSearchExecution: (
|
|
6880
|
+
toolSearchExecution: (_a2 = value.item.execution) != null ? _a2 : "server"
|
|
6638
6881
|
};
|
|
6639
6882
|
if (isHosted) {
|
|
6640
6883
|
controller.enqueue({
|
|
@@ -6691,7 +6934,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6691
6934
|
} else if (value.item.type === "shell_call_output") {
|
|
6692
6935
|
} else if (value.item.type === "message") {
|
|
6693
6936
|
ongoingAnnotations.splice(0, ongoingAnnotations.length);
|
|
6694
|
-
activeMessagePhase = (
|
|
6937
|
+
activeMessagePhase = (_b2 = value.item.phase) != null ? _b2 : void 0;
|
|
6695
6938
|
controller.enqueue({
|
|
6696
6939
|
type: "text-start",
|
|
6697
6940
|
id: value.item.id,
|
|
@@ -6738,31 +6981,99 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6738
6981
|
}
|
|
6739
6982
|
});
|
|
6740
6983
|
} else if (value.item.type === "function_call") {
|
|
6984
|
+
const item = value.item;
|
|
6985
|
+
const ongoingToolCall = ongoingToolCalls[value.output_index];
|
|
6741
6986
|
ongoingToolCalls[value.output_index] = void 0;
|
|
6742
6987
|
hasFunctionCall = true;
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
|
|
6749
|
-
|
|
6988
|
+
const suppressInputStreaming = (_e = ongoingToolCall == null ? void 0 : ongoingToolCall.suppressInputStreaming) != null ? _e : isUndeclaredParallelToolCall({
|
|
6989
|
+
toolName: item.name,
|
|
6990
|
+
tools: functionTools
|
|
6991
|
+
});
|
|
6992
|
+
const enqueueUnexpandedToolCall = () => {
|
|
6993
|
+
var _a3;
|
|
6994
|
+
if (suppressInputStreaming) {
|
|
6995
|
+
controller.enqueue({
|
|
6996
|
+
type: "tool-input-start",
|
|
6997
|
+
id: item.call_id,
|
|
6998
|
+
toolName: item.name
|
|
6999
|
+
});
|
|
7000
|
+
const bufferedInputDeltas = (_a3 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a3 : [];
|
|
7001
|
+
if (bufferedInputDeltas.length > 0) {
|
|
7002
|
+
for (const delta of bufferedInputDeltas) {
|
|
7003
|
+
controller.enqueue({
|
|
7004
|
+
type: "tool-input-delta",
|
|
7005
|
+
id: item.call_id,
|
|
7006
|
+
delta
|
|
7007
|
+
});
|
|
6750
7008
|
}
|
|
7009
|
+
} else if (item.arguments.length > 0) {
|
|
7010
|
+
controller.enqueue({
|
|
7011
|
+
type: "tool-input-delta",
|
|
7012
|
+
id: item.call_id,
|
|
7013
|
+
delta: item.arguments
|
|
7014
|
+
});
|
|
6751
7015
|
}
|
|
6752
7016
|
}
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
itemId: value.item.id,
|
|
6762
|
-
...value.item.namespace != null && {
|
|
6763
|
-
namespace: value.item.namespace
|
|
7017
|
+
controller.enqueue({
|
|
7018
|
+
type: "tool-input-end",
|
|
7019
|
+
id: item.call_id,
|
|
7020
|
+
...item.namespace != null && {
|
|
7021
|
+
providerMetadata: {
|
|
7022
|
+
[providerOptionsName]: {
|
|
7023
|
+
namespace: item.namespace
|
|
7024
|
+
}
|
|
6764
7025
|
}
|
|
6765
7026
|
}
|
|
7027
|
+
});
|
|
7028
|
+
controller.enqueue({
|
|
7029
|
+
type: "tool-call",
|
|
7030
|
+
toolCallId: item.call_id,
|
|
7031
|
+
toolName: item.name,
|
|
7032
|
+
input: item.arguments,
|
|
7033
|
+
providerMetadata: {
|
|
7034
|
+
[providerOptionsName]: {
|
|
7035
|
+
itemId: item.id,
|
|
7036
|
+
...item.namespace != null && {
|
|
7037
|
+
namespace: item.namespace
|
|
7038
|
+
}
|
|
7039
|
+
}
|
|
7040
|
+
}
|
|
7041
|
+
});
|
|
7042
|
+
};
|
|
7043
|
+
if (!suppressInputStreaming) {
|
|
7044
|
+
enqueueUnexpandedToolCall();
|
|
7045
|
+
return;
|
|
7046
|
+
}
|
|
7047
|
+
return expandParallelToolCall({
|
|
7048
|
+
toolCall: {
|
|
7049
|
+
toolCallId: item.call_id,
|
|
7050
|
+
toolName: item.name,
|
|
7051
|
+
input: item.arguments
|
|
7052
|
+
},
|
|
7053
|
+
tools: functionTools,
|
|
7054
|
+
providerOptionsName,
|
|
7055
|
+
itemId: item.id
|
|
7056
|
+
}).then((expandedToolCalls) => {
|
|
7057
|
+
if (expandedToolCalls == null) {
|
|
7058
|
+
enqueueUnexpandedToolCall();
|
|
7059
|
+
return;
|
|
7060
|
+
}
|
|
7061
|
+
for (const toolCall of expandedToolCalls) {
|
|
7062
|
+
controller.enqueue({
|
|
7063
|
+
type: "tool-input-start",
|
|
7064
|
+
id: toolCall.toolCallId,
|
|
7065
|
+
toolName: toolCall.toolName
|
|
7066
|
+
});
|
|
7067
|
+
controller.enqueue({
|
|
7068
|
+
type: "tool-input-delta",
|
|
7069
|
+
id: toolCall.toolCallId,
|
|
7070
|
+
delta: toolCall.input
|
|
7071
|
+
});
|
|
7072
|
+
controller.enqueue({
|
|
7073
|
+
type: "tool-input-end",
|
|
7074
|
+
id: toolCall.toolCallId
|
|
7075
|
+
});
|
|
7076
|
+
controller.enqueue(toolCall);
|
|
6766
7077
|
}
|
|
6767
7078
|
});
|
|
6768
7079
|
} else if (value.item.type === "custom_tool_call") {
|
|
@@ -6826,13 +7137,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6826
7137
|
toolName: toolNameMapping.toCustomToolName("file_search"),
|
|
6827
7138
|
result: {
|
|
6828
7139
|
queries: value.item.queries,
|
|
6829
|
-
results: (
|
|
7140
|
+
results: (_g = (_f = value.item.results) == null ? void 0 : _f.map((result2) => ({
|
|
6830
7141
|
attributes: result2.attributes,
|
|
6831
7142
|
fileId: result2.file_id,
|
|
6832
7143
|
filename: result2.filename,
|
|
6833
7144
|
score: result2.score,
|
|
6834
7145
|
text: result2.text
|
|
6835
|
-
}))) != null ?
|
|
7146
|
+
}))) != null ? _g : null
|
|
6836
7147
|
}
|
|
6837
7148
|
});
|
|
6838
7149
|
} else if (value.item.type === "code_interpreter_call") {
|
|
@@ -6858,7 +7169,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6858
7169
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
6859
7170
|
const isHosted = value.item.execution === "server";
|
|
6860
7171
|
if (toolCall != null) {
|
|
6861
|
-
const toolCallId = isHosted ? toolCall.toolCallId : (
|
|
7172
|
+
const toolCallId = isHosted ? toolCall.toolCallId : (_h = value.item.call_id) != null ? _h : value.item.id;
|
|
6862
7173
|
if (isHosted) {
|
|
6863
7174
|
hostedToolSearchCallIds.push(toolCallId);
|
|
6864
7175
|
} else {
|
|
@@ -6890,7 +7201,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6890
7201
|
}
|
|
6891
7202
|
ongoingToolCalls[value.output_index] = void 0;
|
|
6892
7203
|
} else if (value.item.type === "tool_search_output") {
|
|
6893
|
-
const toolCallId = (
|
|
7204
|
+
const toolCallId = (_j = (_i = value.item.call_id) != null ? _i : hostedToolSearchCallIds.shift()) != null ? _j : value.item.id;
|
|
6894
7205
|
controller.enqueue({
|
|
6895
7206
|
type: "tool-result",
|
|
6896
7207
|
toolCallId,
|
|
@@ -6906,10 +7217,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6906
7217
|
});
|
|
6907
7218
|
} else if (value.item.type === "mcp_call") {
|
|
6908
7219
|
ongoingToolCalls[value.output_index] = void 0;
|
|
6909
|
-
const approvalRequestId = (
|
|
6910
|
-
const aliasedToolCallId = approvalRequestId != null ? (
|
|
7220
|
+
const approvalRequestId = (_k = value.item.approval_request_id) != null ? _k : void 0;
|
|
7221
|
+
const aliasedToolCallId = approvalRequestId != null ? (_m = (_l = approvalRequestIdToDummyToolCallIdFromStream.get(
|
|
6911
7222
|
approvalRequestId
|
|
6912
|
-
)) != null ?
|
|
7223
|
+
)) != null ? _l : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _m : value.item.id : value.item.id;
|
|
6913
7224
|
const toolName = `mcp.${value.item.name}`;
|
|
6914
7225
|
controller.enqueue({
|
|
6915
7226
|
type: "tool-call",
|
|
@@ -6979,8 +7290,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6979
7290
|
ongoingToolCalls[value.output_index] = void 0;
|
|
6980
7291
|
} else if (value.item.type === "mcp_approval_request") {
|
|
6981
7292
|
ongoingToolCalls[value.output_index] = void 0;
|
|
6982
|
-
const dummyToolCallId = (
|
|
6983
|
-
const approvalRequestId = (
|
|
7293
|
+
const dummyToolCallId = (_p = (_o = (_n = self.config).generateId) == null ? void 0 : _o.call(_n)) != null ? _p : generateId2();
|
|
7294
|
+
const approvalRequestId = (_q = value.item.approval_request_id) != null ? _q : value.item.id;
|
|
6984
7295
|
approvalRequestIdToDummyToolCallIdFromStream.set(
|
|
6985
7296
|
approvalRequestId,
|
|
6986
7297
|
dummyToolCallId
|
|
@@ -7069,7 +7380,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7069
7380
|
providerMetadata: {
|
|
7070
7381
|
[providerOptionsName]: {
|
|
7071
7382
|
itemId: value.item.id,
|
|
7072
|
-
reasoningEncryptedContent: (
|
|
7383
|
+
reasoningEncryptedContent: (_r = value.item.encrypted_content) != null ? _r : null
|
|
7073
7384
|
}
|
|
7074
7385
|
}
|
|
7075
7386
|
});
|
|
@@ -7079,11 +7390,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7079
7390
|
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
7080
7391
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
7081
7392
|
if (toolCall != null) {
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
|
|
7393
|
+
if (toolCall.suppressInputStreaming) {
|
|
7394
|
+
(_s = toolCall.bufferedInputDeltas) == null ? void 0 : _s.push(value.delta);
|
|
7395
|
+
} else {
|
|
7396
|
+
controller.enqueue({
|
|
7397
|
+
type: "tool-input-delta",
|
|
7398
|
+
id: toolCall.toolCallId,
|
|
7399
|
+
delta: value.delta
|
|
7400
|
+
});
|
|
7401
|
+
}
|
|
7087
7402
|
}
|
|
7088
7403
|
} else if (isResponseCustomToolCallInputDeltaChunk(value)) {
|
|
7089
7404
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
@@ -7182,7 +7497,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7182
7497
|
id: value.item_id,
|
|
7183
7498
|
delta: value.delta
|
|
7184
7499
|
});
|
|
7185
|
-
if (((
|
|
7500
|
+
if (((_u = (_t = options.providerOptions) == null ? void 0 : _t[providerOptionsName]) == null ? void 0 : _u.logprobs) && value.logprobs) {
|
|
7186
7501
|
logprobs.push(value.logprobs);
|
|
7187
7502
|
}
|
|
7188
7503
|
} else if (value.type === "response.reasoning_summary_part.added") {
|
|
@@ -7211,7 +7526,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7211
7526
|
providerMetadata: {
|
|
7212
7527
|
[providerOptionsName]: {
|
|
7213
7528
|
itemId: value.item_id,
|
|
7214
|
-
reasoningEncryptedContent: (
|
|
7529
|
+
reasoningEncryptedContent: (_w = (_v = activeReasoning[value.item_id]) == null ? void 0 : _v.encryptedContent) != null ? _w : null
|
|
7215
7530
|
}
|
|
7216
7531
|
}
|
|
7217
7532
|
});
|
|
@@ -7245,20 +7560,20 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7245
7560
|
} else if (isResponseFinishedChunk(value)) {
|
|
7246
7561
|
finishReason = {
|
|
7247
7562
|
unified: mapOpenAIResponseFinishReason({
|
|
7248
|
-
finishReason: (
|
|
7563
|
+
finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
|
|
7249
7564
|
hasFunctionCall
|
|
7250
7565
|
}),
|
|
7251
|
-
raw: (
|
|
7566
|
+
raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
|
|
7252
7567
|
};
|
|
7253
7568
|
usage = value.response.usage;
|
|
7254
7569
|
if (typeof value.response.service_tier === "string") {
|
|
7255
7570
|
serviceTier = value.response.service_tier;
|
|
7256
7571
|
}
|
|
7257
|
-
if (((
|
|
7572
|
+
if (((_A = value.response.reasoning) == null ? void 0 : _A.context) != null) {
|
|
7258
7573
|
reasoningContext = value.response.reasoning.context;
|
|
7259
7574
|
}
|
|
7260
7575
|
} else if (isResponseFailedChunk(value)) {
|
|
7261
|
-
const incompleteReason = (
|
|
7576
|
+
const incompleteReason = (_B = value.response.incomplete_details) == null ? void 0 : _B.reason;
|
|
7262
7577
|
finishReason = {
|
|
7263
7578
|
unified: incompleteReason ? mapOpenAIResponseFinishReason({
|
|
7264
7579
|
finishReason: incompleteReason,
|
|
@@ -7266,8 +7581,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7266
7581
|
}) : "error",
|
|
7267
7582
|
raw: incompleteReason != null ? incompleteReason : "error"
|
|
7268
7583
|
};
|
|
7269
|
-
usage = (
|
|
7270
|
-
if (((
|
|
7584
|
+
usage = (_C = value.response.usage) != null ? _C : void 0;
|
|
7585
|
+
if (((_D = value.response.reasoning) == null ? void 0 : _D.context) != null) {
|
|
7271
7586
|
reasoningContext = value.response.reasoning.context;
|
|
7272
7587
|
}
|
|
7273
7588
|
if (!encounteredStreamError && value.response.error != null) {
|
|
@@ -7291,7 +7606,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7291
7606
|
controller.enqueue({
|
|
7292
7607
|
type: "source",
|
|
7293
7608
|
sourceType: "url",
|
|
7294
|
-
id: (
|
|
7609
|
+
id: (_G = (_F = (_E = self.config).generateId) == null ? void 0 : _F.call(_E)) != null ? _G : generateId2(),
|
|
7295
7610
|
url: value.annotation.url,
|
|
7296
7611
|
title: value.annotation.title
|
|
7297
7612
|
});
|
|
@@ -7299,7 +7614,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7299
7614
|
controller.enqueue({
|
|
7300
7615
|
type: "source",
|
|
7301
7616
|
sourceType: "document",
|
|
7302
|
-
id: (
|
|
7617
|
+
id: (_J = (_I = (_H = self.config).generateId) == null ? void 0 : _I.call(_H)) != null ? _J : generateId2(),
|
|
7303
7618
|
mediaType: "text/plain",
|
|
7304
7619
|
title: value.annotation.filename,
|
|
7305
7620
|
filename: value.annotation.filename,
|
|
@@ -7315,7 +7630,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7315
7630
|
controller.enqueue({
|
|
7316
7631
|
type: "source",
|
|
7317
7632
|
sourceType: "document",
|
|
7318
|
-
id: (
|
|
7633
|
+
id: (_M = (_L = (_K = self.config).generateId) == null ? void 0 : _L.call(_K)) != null ? _M : generateId2(),
|
|
7319
7634
|
mediaType: "text/plain",
|
|
7320
7635
|
title: value.annotation.filename,
|
|
7321
7636
|
filename: value.annotation.filename,
|
|
@@ -7331,7 +7646,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7331
7646
|
controller.enqueue({
|
|
7332
7647
|
type: "source",
|
|
7333
7648
|
sourceType: "document",
|
|
7334
|
-
id: (
|
|
7649
|
+
id: (_P = (_O = (_N = self.config).generateId) == null ? void 0 : _O.call(_N)) != null ? _P : generateId2(),
|
|
7335
7650
|
mediaType: "application/octet-stream",
|
|
7336
7651
|
title: value.annotation.file_id,
|
|
7337
7652
|
filename: value.annotation.file_id,
|
|
@@ -7351,6 +7666,24 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7351
7666
|
}
|
|
7352
7667
|
},
|
|
7353
7668
|
flush(controller) {
|
|
7669
|
+
var _a2;
|
|
7670
|
+
for (const toolCall of Object.values(ongoingToolCalls)) {
|
|
7671
|
+
if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
|
|
7672
|
+
continue;
|
|
7673
|
+
}
|
|
7674
|
+
controller.enqueue({
|
|
7675
|
+
type: "tool-input-start",
|
|
7676
|
+
id: toolCall.toolCallId,
|
|
7677
|
+
toolName: toolCall.toolName
|
|
7678
|
+
});
|
|
7679
|
+
for (const delta of (_a2 = toolCall.bufferedInputDeltas) != null ? _a2 : []) {
|
|
7680
|
+
controller.enqueue({
|
|
7681
|
+
type: "tool-input-delta",
|
|
7682
|
+
id: toolCall.toolCallId,
|
|
7683
|
+
delta
|
|
7684
|
+
});
|
|
7685
|
+
}
|
|
7686
|
+
}
|
|
7354
7687
|
const providerMetadata = {
|
|
7355
7688
|
[providerOptionsName]: {
|
|
7356
7689
|
responseId,
|