@ai-sdk/openai 3.0.105 → 3.0.106
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.js +99 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -39
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +98 -38
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +98 -38
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/responses/convert-to-openai-responses-input.ts +101 -21
package/dist/internal/index.mjs
CHANGED
|
@@ -3056,23 +3056,34 @@ function serializeToolCallArguments2(input) {
|
|
|
3056
3056
|
}
|
|
3057
3057
|
async function convertFunctionToolResultOutput({
|
|
3058
3058
|
output,
|
|
3059
|
+
promptCacheBreakpoint,
|
|
3059
3060
|
providerOptionsName,
|
|
3060
3061
|
warnings
|
|
3061
3062
|
}) {
|
|
3062
3063
|
var _a2;
|
|
3064
|
+
const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
|
|
3065
|
+
{
|
|
3066
|
+
type: "input_text",
|
|
3067
|
+
text: value,
|
|
3068
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3069
|
+
}
|
|
3070
|
+
];
|
|
3063
3071
|
switch (output.type) {
|
|
3064
3072
|
case "text":
|
|
3065
3073
|
case "error-text":
|
|
3066
|
-
return output.value;
|
|
3067
|
-
case "execution-denied":
|
|
3068
|
-
return (
|
|
3074
|
+
return convertScalarOutput(output.value);
|
|
3075
|
+
case "execution-denied": {
|
|
3076
|
+
return convertScalarOutput(
|
|
3077
|
+
(_a2 = output.reason) != null ? _a2 : "Tool call execution denied."
|
|
3078
|
+
);
|
|
3079
|
+
}
|
|
3069
3080
|
case "json":
|
|
3070
3081
|
case "error-json":
|
|
3071
|
-
return JSON.stringify(output.value);
|
|
3082
|
+
return convertScalarOutput(JSON.stringify(output.value));
|
|
3072
3083
|
case "content":
|
|
3073
3084
|
return output.value.map((item) => {
|
|
3074
3085
|
var _a3, _b, _c, _d, _e;
|
|
3075
|
-
const
|
|
3086
|
+
const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
|
|
3076
3087
|
item.providerOptions,
|
|
3077
3088
|
providerOptionsName
|
|
3078
3089
|
);
|
|
@@ -3081,8 +3092,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3081
3092
|
return {
|
|
3082
3093
|
type: "input_text",
|
|
3083
3094
|
text: item.text,
|
|
3084
|
-
...
|
|
3085
|
-
prompt_cache_breakpoint:
|
|
3095
|
+
...promptCacheBreakpoint2 != null && {
|
|
3096
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3086
3097
|
}
|
|
3087
3098
|
};
|
|
3088
3099
|
}
|
|
@@ -3091,8 +3102,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3091
3102
|
type: "input_image",
|
|
3092
3103
|
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3093
3104
|
detail: (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail,
|
|
3094
|
-
...
|
|
3095
|
-
prompt_cache_breakpoint:
|
|
3105
|
+
...promptCacheBreakpoint2 != null && {
|
|
3106
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3096
3107
|
}
|
|
3097
3108
|
};
|
|
3098
3109
|
}
|
|
@@ -3101,8 +3112,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3101
3112
|
type: "input_image",
|
|
3102
3113
|
image_url: item.url,
|
|
3103
3114
|
detail: (_d = (_c = item.providerOptions) == null ? void 0 : _c[providerOptionsName]) == null ? void 0 : _d.imageDetail,
|
|
3104
|
-
...
|
|
3105
|
-
prompt_cache_breakpoint:
|
|
3115
|
+
...promptCacheBreakpoint2 != null && {
|
|
3116
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3106
3117
|
}
|
|
3107
3118
|
};
|
|
3108
3119
|
}
|
|
@@ -3111,8 +3122,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3111
3122
|
type: "input_file",
|
|
3112
3123
|
filename: (_e = item.filename) != null ? _e : "data",
|
|
3113
3124
|
file_data: `data:${item.mediaType};base64,${item.data}`,
|
|
3114
|
-
...
|
|
3115
|
-
prompt_cache_breakpoint:
|
|
3125
|
+
...promptCacheBreakpoint2 != null && {
|
|
3126
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3116
3127
|
}
|
|
3117
3128
|
};
|
|
3118
3129
|
}
|
|
@@ -3120,8 +3131,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3120
3131
|
return {
|
|
3121
3132
|
type: "input_file",
|
|
3122
3133
|
file_url: item.url,
|
|
3123
|
-
...
|
|
3124
|
-
prompt_cache_breakpoint:
|
|
3134
|
+
...promptCacheBreakpoint2 != null && {
|
|
3135
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3125
3136
|
}
|
|
3126
3137
|
};
|
|
3127
3138
|
}
|
|
@@ -3197,6 +3208,17 @@ function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
|
|
|
3197
3208
|
var _a2;
|
|
3198
3209
|
return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
3199
3210
|
}
|
|
3211
|
+
function getScalarToolResultPromptCacheBreakpoint({
|
|
3212
|
+
output,
|
|
3213
|
+
toolResultProviderOptions,
|
|
3214
|
+
providerOptionsName
|
|
3215
|
+
}) {
|
|
3216
|
+
var _a2;
|
|
3217
|
+
return output.type === "content" ? void 0 : (_a2 = getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName)) != null ? _a2 : getPromptCacheBreakpoint2(
|
|
3218
|
+
toolResultProviderOptions,
|
|
3219
|
+
providerOptionsName
|
|
3220
|
+
);
|
|
3221
|
+
}
|
|
3200
3222
|
function isFileId(data, prefixes) {
|
|
3201
3223
|
if (!prefixes) return false;
|
|
3202
3224
|
return prefixes.some((prefix) => data.startsWith(prefix));
|
|
@@ -3697,22 +3719,41 @@ async function convertToOpenAIResponsesInput({
|
|
|
3697
3719
|
parallelToolResultGroup.metadata.toolCallId
|
|
3698
3720
|
);
|
|
3699
3721
|
const toolOutputs = await Promise.all(
|
|
3700
|
-
parallelToolResultGroup.results.map(
|
|
3701
|
-
|
|
3722
|
+
parallelToolResultGroup.results.map(async (result) => {
|
|
3723
|
+
const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
|
|
3702
3724
|
output: result.output,
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
})
|
|
3706
|
-
|
|
3725
|
+
toolResultProviderOptions: result.providerOptions,
|
|
3726
|
+
providerOptionsName
|
|
3727
|
+
});
|
|
3728
|
+
return {
|
|
3729
|
+
output: await convertFunctionToolResultOutput({
|
|
3730
|
+
output: result.output,
|
|
3731
|
+
providerOptionsName,
|
|
3732
|
+
warnings
|
|
3733
|
+
}),
|
|
3734
|
+
promptCacheBreakpoint
|
|
3735
|
+
};
|
|
3736
|
+
})
|
|
3737
|
+
);
|
|
3738
|
+
const serializedToolOutputs = toolOutputs.map(
|
|
3739
|
+
({ output: output2 }) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
|
|
3740
|
+
);
|
|
3741
|
+
const hasPromptCacheBreakpoint = toolOutputs.some(
|
|
3742
|
+
({ promptCacheBreakpoint }) => promptCacheBreakpoint != null
|
|
3707
3743
|
);
|
|
3708
3744
|
input.push({
|
|
3709
3745
|
type: "function_call_output",
|
|
3710
3746
|
call_id: parallelToolResultGroup.metadata.toolCallId,
|
|
3711
3747
|
// The internal wrapper returns one output containing the child
|
|
3712
3748
|
// results in the same order as the original tool_uses array.
|
|
3713
|
-
output:
|
|
3714
|
-
|
|
3715
|
-
|
|
3749
|
+
output: hasPromptCacheBreakpoint ? serializedToolOutputs.map((text, index) => ({
|
|
3750
|
+
type: "input_text",
|
|
3751
|
+
text: index === 0 ? text : `
|
|
3752
|
+
${text}`,
|
|
3753
|
+
...toolOutputs[index].promptCacheBreakpoint != null && {
|
|
3754
|
+
prompt_cache_breakpoint: toolOutputs[index].promptCacheBreakpoint
|
|
3755
|
+
}
|
|
3756
|
+
})) : serializedToolOutputs.join("\n")
|
|
3716
3757
|
});
|
|
3717
3758
|
}
|
|
3718
3759
|
continue;
|
|
@@ -3786,23 +3827,37 @@ async function convertToOpenAIResponsesInput({
|
|
|
3786
3827
|
continue;
|
|
3787
3828
|
}
|
|
3788
3829
|
if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
|
|
3830
|
+
const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
|
|
3831
|
+
output,
|
|
3832
|
+
toolResultProviderOptions: part.providerOptions,
|
|
3833
|
+
providerOptionsName
|
|
3834
|
+
});
|
|
3835
|
+
const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
|
|
3836
|
+
{
|
|
3837
|
+
type: "input_text",
|
|
3838
|
+
text: value,
|
|
3839
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3840
|
+
}
|
|
3841
|
+
];
|
|
3789
3842
|
let outputValue;
|
|
3790
3843
|
switch (output.type) {
|
|
3791
3844
|
case "text":
|
|
3792
3845
|
case "error-text":
|
|
3793
|
-
outputValue = output.value;
|
|
3846
|
+
outputValue = convertScalarOutput(output.value);
|
|
3794
3847
|
break;
|
|
3795
3848
|
case "execution-denied":
|
|
3796
|
-
outputValue = (
|
|
3849
|
+
outputValue = convertScalarOutput(
|
|
3850
|
+
(_y = output.reason) != null ? _y : "Tool call execution denied."
|
|
3851
|
+
);
|
|
3797
3852
|
break;
|
|
3798
3853
|
case "json":
|
|
3799
3854
|
case "error-json":
|
|
3800
|
-
outputValue = JSON.stringify(output.value);
|
|
3855
|
+
outputValue = convertScalarOutput(JSON.stringify(output.value));
|
|
3801
3856
|
break;
|
|
3802
3857
|
case "content":
|
|
3803
3858
|
outputValue = output.value.map((item) => {
|
|
3804
3859
|
var _a3, _b2, _c2, _d2, _e2;
|
|
3805
|
-
const
|
|
3860
|
+
const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
|
|
3806
3861
|
item.providerOptions,
|
|
3807
3862
|
providerOptionsName
|
|
3808
3863
|
);
|
|
@@ -3811,8 +3866,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
3811
3866
|
return {
|
|
3812
3867
|
type: "input_text",
|
|
3813
3868
|
text: item.text,
|
|
3814
|
-
...
|
|
3815
|
-
prompt_cache_breakpoint:
|
|
3869
|
+
...promptCacheBreakpoint2 != null && {
|
|
3870
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3816
3871
|
}
|
|
3817
3872
|
};
|
|
3818
3873
|
case "image-data":
|
|
@@ -3820,8 +3875,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
3820
3875
|
type: "input_image",
|
|
3821
3876
|
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3822
3877
|
detail: (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
3823
|
-
...
|
|
3824
|
-
prompt_cache_breakpoint:
|
|
3878
|
+
...promptCacheBreakpoint2 != null && {
|
|
3879
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3825
3880
|
}
|
|
3826
3881
|
};
|
|
3827
3882
|
case "image-url":
|
|
@@ -3829,8 +3884,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
3829
3884
|
type: "input_image",
|
|
3830
3885
|
image_url: item.url,
|
|
3831
3886
|
detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
|
|
3832
|
-
...
|
|
3833
|
-
prompt_cache_breakpoint:
|
|
3887
|
+
...promptCacheBreakpoint2 != null && {
|
|
3888
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3834
3889
|
}
|
|
3835
3890
|
};
|
|
3836
3891
|
case "file-data":
|
|
@@ -3838,16 +3893,16 @@ async function convertToOpenAIResponsesInput({
|
|
|
3838
3893
|
type: "input_file",
|
|
3839
3894
|
filename: (_e2 = item.filename) != null ? _e2 : "data",
|
|
3840
3895
|
file_data: `data:${item.mediaType};base64,${item.data}`,
|
|
3841
|
-
...
|
|
3842
|
-
prompt_cache_breakpoint:
|
|
3896
|
+
...promptCacheBreakpoint2 != null && {
|
|
3897
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3843
3898
|
}
|
|
3844
3899
|
};
|
|
3845
3900
|
case "file-url":
|
|
3846
3901
|
return {
|
|
3847
3902
|
type: "input_file",
|
|
3848
3903
|
file_url: item.url,
|
|
3849
|
-
...
|
|
3850
|
-
prompt_cache_breakpoint:
|
|
3904
|
+
...promptCacheBreakpoint2 != null && {
|
|
3905
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3851
3906
|
}
|
|
3852
3907
|
};
|
|
3853
3908
|
default:
|
|
@@ -3871,6 +3926,11 @@ async function convertToOpenAIResponsesInput({
|
|
|
3871
3926
|
}
|
|
3872
3927
|
const contentValue = await convertFunctionToolResultOutput({
|
|
3873
3928
|
output,
|
|
3929
|
+
promptCacheBreakpoint: getScalarToolResultPromptCacheBreakpoint({
|
|
3930
|
+
output,
|
|
3931
|
+
toolResultProviderOptions: part.providerOptions,
|
|
3932
|
+
providerOptionsName
|
|
3933
|
+
}),
|
|
3874
3934
|
providerOptionsName,
|
|
3875
3935
|
warnings
|
|
3876
3936
|
});
|