@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.js
CHANGED
|
@@ -3011,23 +3011,34 @@ function serializeToolCallArguments2(input) {
|
|
|
3011
3011
|
}
|
|
3012
3012
|
async function convertFunctionToolResultOutput({
|
|
3013
3013
|
output,
|
|
3014
|
+
promptCacheBreakpoint,
|
|
3014
3015
|
providerOptionsName,
|
|
3015
3016
|
warnings
|
|
3016
3017
|
}) {
|
|
3017
3018
|
var _a2;
|
|
3019
|
+
const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
|
|
3020
|
+
{
|
|
3021
|
+
type: "input_text",
|
|
3022
|
+
text: value,
|
|
3023
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3024
|
+
}
|
|
3025
|
+
];
|
|
3018
3026
|
switch (output.type) {
|
|
3019
3027
|
case "text":
|
|
3020
3028
|
case "error-text":
|
|
3021
|
-
return output.value;
|
|
3022
|
-
case "execution-denied":
|
|
3023
|
-
return (
|
|
3029
|
+
return convertScalarOutput(output.value);
|
|
3030
|
+
case "execution-denied": {
|
|
3031
|
+
return convertScalarOutput(
|
|
3032
|
+
(_a2 = output.reason) != null ? _a2 : "Tool call execution denied."
|
|
3033
|
+
);
|
|
3034
|
+
}
|
|
3024
3035
|
case "json":
|
|
3025
3036
|
case "error-json":
|
|
3026
|
-
return JSON.stringify(output.value);
|
|
3037
|
+
return convertScalarOutput(JSON.stringify(output.value));
|
|
3027
3038
|
case "content":
|
|
3028
3039
|
return output.value.map((item) => {
|
|
3029
3040
|
var _a3, _b, _c, _d, _e;
|
|
3030
|
-
const
|
|
3041
|
+
const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
|
|
3031
3042
|
item.providerOptions,
|
|
3032
3043
|
providerOptionsName
|
|
3033
3044
|
);
|
|
@@ -3036,8 +3047,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3036
3047
|
return {
|
|
3037
3048
|
type: "input_text",
|
|
3038
3049
|
text: item.text,
|
|
3039
|
-
...
|
|
3040
|
-
prompt_cache_breakpoint:
|
|
3050
|
+
...promptCacheBreakpoint2 != null && {
|
|
3051
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3041
3052
|
}
|
|
3042
3053
|
};
|
|
3043
3054
|
}
|
|
@@ -3046,8 +3057,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3046
3057
|
type: "input_image",
|
|
3047
3058
|
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3048
3059
|
detail: (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail,
|
|
3049
|
-
...
|
|
3050
|
-
prompt_cache_breakpoint:
|
|
3060
|
+
...promptCacheBreakpoint2 != null && {
|
|
3061
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3051
3062
|
}
|
|
3052
3063
|
};
|
|
3053
3064
|
}
|
|
@@ -3056,8 +3067,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3056
3067
|
type: "input_image",
|
|
3057
3068
|
image_url: item.url,
|
|
3058
3069
|
detail: (_d = (_c = item.providerOptions) == null ? void 0 : _c[providerOptionsName]) == null ? void 0 : _d.imageDetail,
|
|
3059
|
-
...
|
|
3060
|
-
prompt_cache_breakpoint:
|
|
3070
|
+
...promptCacheBreakpoint2 != null && {
|
|
3071
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3061
3072
|
}
|
|
3062
3073
|
};
|
|
3063
3074
|
}
|
|
@@ -3066,8 +3077,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3066
3077
|
type: "input_file",
|
|
3067
3078
|
filename: (_e = item.filename) != null ? _e : "data",
|
|
3068
3079
|
file_data: `data:${item.mediaType};base64,${item.data}`,
|
|
3069
|
-
...
|
|
3070
|
-
prompt_cache_breakpoint:
|
|
3080
|
+
...promptCacheBreakpoint2 != null && {
|
|
3081
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3071
3082
|
}
|
|
3072
3083
|
};
|
|
3073
3084
|
}
|
|
@@ -3075,8 +3086,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3075
3086
|
return {
|
|
3076
3087
|
type: "input_file",
|
|
3077
3088
|
file_url: item.url,
|
|
3078
|
-
...
|
|
3079
|
-
prompt_cache_breakpoint:
|
|
3089
|
+
...promptCacheBreakpoint2 != null && {
|
|
3090
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3080
3091
|
}
|
|
3081
3092
|
};
|
|
3082
3093
|
}
|
|
@@ -3152,6 +3163,17 @@ function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
|
|
|
3152
3163
|
var _a2;
|
|
3153
3164
|
return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
3154
3165
|
}
|
|
3166
|
+
function getScalarToolResultPromptCacheBreakpoint({
|
|
3167
|
+
output,
|
|
3168
|
+
toolResultProviderOptions,
|
|
3169
|
+
providerOptionsName
|
|
3170
|
+
}) {
|
|
3171
|
+
var _a2;
|
|
3172
|
+
return output.type === "content" ? void 0 : (_a2 = getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName)) != null ? _a2 : getPromptCacheBreakpoint2(
|
|
3173
|
+
toolResultProviderOptions,
|
|
3174
|
+
providerOptionsName
|
|
3175
|
+
);
|
|
3176
|
+
}
|
|
3155
3177
|
function isFileId(data, prefixes) {
|
|
3156
3178
|
if (!prefixes) return false;
|
|
3157
3179
|
return prefixes.some((prefix) => data.startsWith(prefix));
|
|
@@ -3652,22 +3674,41 @@ async function convertToOpenAIResponsesInput({
|
|
|
3652
3674
|
parallelToolResultGroup.metadata.toolCallId
|
|
3653
3675
|
);
|
|
3654
3676
|
const toolOutputs = await Promise.all(
|
|
3655
|
-
parallelToolResultGroup.results.map(
|
|
3656
|
-
|
|
3677
|
+
parallelToolResultGroup.results.map(async (result) => {
|
|
3678
|
+
const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
|
|
3657
3679
|
output: result.output,
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
})
|
|
3661
|
-
|
|
3680
|
+
toolResultProviderOptions: result.providerOptions,
|
|
3681
|
+
providerOptionsName
|
|
3682
|
+
});
|
|
3683
|
+
return {
|
|
3684
|
+
output: await convertFunctionToolResultOutput({
|
|
3685
|
+
output: result.output,
|
|
3686
|
+
providerOptionsName,
|
|
3687
|
+
warnings
|
|
3688
|
+
}),
|
|
3689
|
+
promptCacheBreakpoint
|
|
3690
|
+
};
|
|
3691
|
+
})
|
|
3692
|
+
);
|
|
3693
|
+
const serializedToolOutputs = toolOutputs.map(
|
|
3694
|
+
({ output: output2 }) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
|
|
3695
|
+
);
|
|
3696
|
+
const hasPromptCacheBreakpoint = toolOutputs.some(
|
|
3697
|
+
({ promptCacheBreakpoint }) => promptCacheBreakpoint != null
|
|
3662
3698
|
);
|
|
3663
3699
|
input.push({
|
|
3664
3700
|
type: "function_call_output",
|
|
3665
3701
|
call_id: parallelToolResultGroup.metadata.toolCallId,
|
|
3666
3702
|
// The internal wrapper returns one output containing the child
|
|
3667
3703
|
// results in the same order as the original tool_uses array.
|
|
3668
|
-
output:
|
|
3669
|
-
|
|
3670
|
-
|
|
3704
|
+
output: hasPromptCacheBreakpoint ? serializedToolOutputs.map((text, index) => ({
|
|
3705
|
+
type: "input_text",
|
|
3706
|
+
text: index === 0 ? text : `
|
|
3707
|
+
${text}`,
|
|
3708
|
+
...toolOutputs[index].promptCacheBreakpoint != null && {
|
|
3709
|
+
prompt_cache_breakpoint: toolOutputs[index].promptCacheBreakpoint
|
|
3710
|
+
}
|
|
3711
|
+
})) : serializedToolOutputs.join("\n")
|
|
3671
3712
|
});
|
|
3672
3713
|
}
|
|
3673
3714
|
continue;
|
|
@@ -3741,23 +3782,37 @@ async function convertToOpenAIResponsesInput({
|
|
|
3741
3782
|
continue;
|
|
3742
3783
|
}
|
|
3743
3784
|
if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
|
|
3785
|
+
const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
|
|
3786
|
+
output,
|
|
3787
|
+
toolResultProviderOptions: part.providerOptions,
|
|
3788
|
+
providerOptionsName
|
|
3789
|
+
});
|
|
3790
|
+
const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
|
|
3791
|
+
{
|
|
3792
|
+
type: "input_text",
|
|
3793
|
+
text: value,
|
|
3794
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3795
|
+
}
|
|
3796
|
+
];
|
|
3744
3797
|
let outputValue;
|
|
3745
3798
|
switch (output.type) {
|
|
3746
3799
|
case "text":
|
|
3747
3800
|
case "error-text":
|
|
3748
|
-
outputValue = output.value;
|
|
3801
|
+
outputValue = convertScalarOutput(output.value);
|
|
3749
3802
|
break;
|
|
3750
3803
|
case "execution-denied":
|
|
3751
|
-
outputValue = (
|
|
3804
|
+
outputValue = convertScalarOutput(
|
|
3805
|
+
(_y = output.reason) != null ? _y : "Tool call execution denied."
|
|
3806
|
+
);
|
|
3752
3807
|
break;
|
|
3753
3808
|
case "json":
|
|
3754
3809
|
case "error-json":
|
|
3755
|
-
outputValue = JSON.stringify(output.value);
|
|
3810
|
+
outputValue = convertScalarOutput(JSON.stringify(output.value));
|
|
3756
3811
|
break;
|
|
3757
3812
|
case "content":
|
|
3758
3813
|
outputValue = output.value.map((item) => {
|
|
3759
3814
|
var _a3, _b2, _c2, _d2, _e2;
|
|
3760
|
-
const
|
|
3815
|
+
const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
|
|
3761
3816
|
item.providerOptions,
|
|
3762
3817
|
providerOptionsName
|
|
3763
3818
|
);
|
|
@@ -3766,8 +3821,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
3766
3821
|
return {
|
|
3767
3822
|
type: "input_text",
|
|
3768
3823
|
text: item.text,
|
|
3769
|
-
...
|
|
3770
|
-
prompt_cache_breakpoint:
|
|
3824
|
+
...promptCacheBreakpoint2 != null && {
|
|
3825
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3771
3826
|
}
|
|
3772
3827
|
};
|
|
3773
3828
|
case "image-data":
|
|
@@ -3775,8 +3830,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
3775
3830
|
type: "input_image",
|
|
3776
3831
|
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3777
3832
|
detail: (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
3778
|
-
...
|
|
3779
|
-
prompt_cache_breakpoint:
|
|
3833
|
+
...promptCacheBreakpoint2 != null && {
|
|
3834
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3780
3835
|
}
|
|
3781
3836
|
};
|
|
3782
3837
|
case "image-url":
|
|
@@ -3784,8 +3839,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
3784
3839
|
type: "input_image",
|
|
3785
3840
|
image_url: item.url,
|
|
3786
3841
|
detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
|
|
3787
|
-
...
|
|
3788
|
-
prompt_cache_breakpoint:
|
|
3842
|
+
...promptCacheBreakpoint2 != null && {
|
|
3843
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3789
3844
|
}
|
|
3790
3845
|
};
|
|
3791
3846
|
case "file-data":
|
|
@@ -3793,16 +3848,16 @@ async function convertToOpenAIResponsesInput({
|
|
|
3793
3848
|
type: "input_file",
|
|
3794
3849
|
filename: (_e2 = item.filename) != null ? _e2 : "data",
|
|
3795
3850
|
file_data: `data:${item.mediaType};base64,${item.data}`,
|
|
3796
|
-
...
|
|
3797
|
-
prompt_cache_breakpoint:
|
|
3851
|
+
...promptCacheBreakpoint2 != null && {
|
|
3852
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3798
3853
|
}
|
|
3799
3854
|
};
|
|
3800
3855
|
case "file-url":
|
|
3801
3856
|
return {
|
|
3802
3857
|
type: "input_file",
|
|
3803
3858
|
file_url: item.url,
|
|
3804
|
-
...
|
|
3805
|
-
prompt_cache_breakpoint:
|
|
3859
|
+
...promptCacheBreakpoint2 != null && {
|
|
3860
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3806
3861
|
}
|
|
3807
3862
|
};
|
|
3808
3863
|
default:
|
|
@@ -3826,6 +3881,11 @@ async function convertToOpenAIResponsesInput({
|
|
|
3826
3881
|
}
|
|
3827
3882
|
const contentValue = await convertFunctionToolResultOutput({
|
|
3828
3883
|
output,
|
|
3884
|
+
promptCacheBreakpoint: getScalarToolResultPromptCacheBreakpoint({
|
|
3885
|
+
output,
|
|
3886
|
+
toolResultProviderOptions: part.providerOptions,
|
|
3887
|
+
providerOptionsName
|
|
3888
|
+
}),
|
|
3829
3889
|
providerOptionsName,
|
|
3830
3890
|
warnings
|
|
3831
3891
|
});
|