@ai-sdk/openai 3.0.104 → 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 +13 -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 +2 -2
- package/src/responses/convert-to-openai-responses-input.ts +101 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 3.0.106
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 85ba0b0: Preserve explicit prompt cache breakpoints on scalar Responses tool results.
|
|
8
|
+
|
|
9
|
+
## 3.0.105
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [cc23556]
|
|
14
|
+
- @ai-sdk/provider-utils@4.0.50
|
|
15
|
+
|
|
3
16
|
## 3.0.104
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -3067,23 +3067,34 @@ function serializeToolCallArguments2(input) {
|
|
|
3067
3067
|
}
|
|
3068
3068
|
async function convertFunctionToolResultOutput({
|
|
3069
3069
|
output,
|
|
3070
|
+
promptCacheBreakpoint,
|
|
3070
3071
|
providerOptionsName,
|
|
3071
3072
|
warnings
|
|
3072
3073
|
}) {
|
|
3073
3074
|
var _a2;
|
|
3075
|
+
const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
|
|
3076
|
+
{
|
|
3077
|
+
type: "input_text",
|
|
3078
|
+
text: value,
|
|
3079
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3080
|
+
}
|
|
3081
|
+
];
|
|
3074
3082
|
switch (output.type) {
|
|
3075
3083
|
case "text":
|
|
3076
3084
|
case "error-text":
|
|
3077
|
-
return output.value;
|
|
3078
|
-
case "execution-denied":
|
|
3079
|
-
return (
|
|
3085
|
+
return convertScalarOutput(output.value);
|
|
3086
|
+
case "execution-denied": {
|
|
3087
|
+
return convertScalarOutput(
|
|
3088
|
+
(_a2 = output.reason) != null ? _a2 : "Tool call execution denied."
|
|
3089
|
+
);
|
|
3090
|
+
}
|
|
3080
3091
|
case "json":
|
|
3081
3092
|
case "error-json":
|
|
3082
|
-
return JSON.stringify(output.value);
|
|
3093
|
+
return convertScalarOutput(JSON.stringify(output.value));
|
|
3083
3094
|
case "content":
|
|
3084
3095
|
return output.value.map((item) => {
|
|
3085
3096
|
var _a3, _b, _c, _d, _e;
|
|
3086
|
-
const
|
|
3097
|
+
const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
|
|
3087
3098
|
item.providerOptions,
|
|
3088
3099
|
providerOptionsName
|
|
3089
3100
|
);
|
|
@@ -3092,8 +3103,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3092
3103
|
return {
|
|
3093
3104
|
type: "input_text",
|
|
3094
3105
|
text: item.text,
|
|
3095
|
-
...
|
|
3096
|
-
prompt_cache_breakpoint:
|
|
3106
|
+
...promptCacheBreakpoint2 != null && {
|
|
3107
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3097
3108
|
}
|
|
3098
3109
|
};
|
|
3099
3110
|
}
|
|
@@ -3102,8 +3113,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3102
3113
|
type: "input_image",
|
|
3103
3114
|
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3104
3115
|
detail: (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail,
|
|
3105
|
-
...
|
|
3106
|
-
prompt_cache_breakpoint:
|
|
3116
|
+
...promptCacheBreakpoint2 != null && {
|
|
3117
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3107
3118
|
}
|
|
3108
3119
|
};
|
|
3109
3120
|
}
|
|
@@ -3112,8 +3123,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3112
3123
|
type: "input_image",
|
|
3113
3124
|
image_url: item.url,
|
|
3114
3125
|
detail: (_d = (_c = item.providerOptions) == null ? void 0 : _c[providerOptionsName]) == null ? void 0 : _d.imageDetail,
|
|
3115
|
-
...
|
|
3116
|
-
prompt_cache_breakpoint:
|
|
3126
|
+
...promptCacheBreakpoint2 != null && {
|
|
3127
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3117
3128
|
}
|
|
3118
3129
|
};
|
|
3119
3130
|
}
|
|
@@ -3122,8 +3133,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3122
3133
|
type: "input_file",
|
|
3123
3134
|
filename: (_e = item.filename) != null ? _e : "data",
|
|
3124
3135
|
file_data: `data:${item.mediaType};base64,${item.data}`,
|
|
3125
|
-
...
|
|
3126
|
-
prompt_cache_breakpoint:
|
|
3136
|
+
...promptCacheBreakpoint2 != null && {
|
|
3137
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3127
3138
|
}
|
|
3128
3139
|
};
|
|
3129
3140
|
}
|
|
@@ -3131,8 +3142,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3131
3142
|
return {
|
|
3132
3143
|
type: "input_file",
|
|
3133
3144
|
file_url: item.url,
|
|
3134
|
-
...
|
|
3135
|
-
prompt_cache_breakpoint:
|
|
3145
|
+
...promptCacheBreakpoint2 != null && {
|
|
3146
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3136
3147
|
}
|
|
3137
3148
|
};
|
|
3138
3149
|
}
|
|
@@ -3208,6 +3219,17 @@ function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
|
|
|
3208
3219
|
var _a2;
|
|
3209
3220
|
return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
3210
3221
|
}
|
|
3222
|
+
function getScalarToolResultPromptCacheBreakpoint({
|
|
3223
|
+
output,
|
|
3224
|
+
toolResultProviderOptions,
|
|
3225
|
+
providerOptionsName
|
|
3226
|
+
}) {
|
|
3227
|
+
var _a2;
|
|
3228
|
+
return output.type === "content" ? void 0 : (_a2 = getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName)) != null ? _a2 : getPromptCacheBreakpoint2(
|
|
3229
|
+
toolResultProviderOptions,
|
|
3230
|
+
providerOptionsName
|
|
3231
|
+
);
|
|
3232
|
+
}
|
|
3211
3233
|
function isFileId(data, prefixes) {
|
|
3212
3234
|
if (!prefixes) return false;
|
|
3213
3235
|
return prefixes.some((prefix) => data.startsWith(prefix));
|
|
@@ -3708,22 +3730,41 @@ async function convertToOpenAIResponsesInput({
|
|
|
3708
3730
|
parallelToolResultGroup.metadata.toolCallId
|
|
3709
3731
|
);
|
|
3710
3732
|
const toolOutputs = await Promise.all(
|
|
3711
|
-
parallelToolResultGroup.results.map(
|
|
3712
|
-
|
|
3733
|
+
parallelToolResultGroup.results.map(async (result) => {
|
|
3734
|
+
const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
|
|
3713
3735
|
output: result.output,
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
})
|
|
3717
|
-
|
|
3736
|
+
toolResultProviderOptions: result.providerOptions,
|
|
3737
|
+
providerOptionsName
|
|
3738
|
+
});
|
|
3739
|
+
return {
|
|
3740
|
+
output: await convertFunctionToolResultOutput({
|
|
3741
|
+
output: result.output,
|
|
3742
|
+
providerOptionsName,
|
|
3743
|
+
warnings
|
|
3744
|
+
}),
|
|
3745
|
+
promptCacheBreakpoint
|
|
3746
|
+
};
|
|
3747
|
+
})
|
|
3748
|
+
);
|
|
3749
|
+
const serializedToolOutputs = toolOutputs.map(
|
|
3750
|
+
({ output: output2 }) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
|
|
3751
|
+
);
|
|
3752
|
+
const hasPromptCacheBreakpoint = toolOutputs.some(
|
|
3753
|
+
({ promptCacheBreakpoint }) => promptCacheBreakpoint != null
|
|
3718
3754
|
);
|
|
3719
3755
|
input.push({
|
|
3720
3756
|
type: "function_call_output",
|
|
3721
3757
|
call_id: parallelToolResultGroup.metadata.toolCallId,
|
|
3722
3758
|
// The internal wrapper returns one output containing the child
|
|
3723
3759
|
// results in the same order as the original tool_uses array.
|
|
3724
|
-
output:
|
|
3725
|
-
|
|
3726
|
-
|
|
3760
|
+
output: hasPromptCacheBreakpoint ? serializedToolOutputs.map((text, index) => ({
|
|
3761
|
+
type: "input_text",
|
|
3762
|
+
text: index === 0 ? text : `
|
|
3763
|
+
${text}`,
|
|
3764
|
+
...toolOutputs[index].promptCacheBreakpoint != null && {
|
|
3765
|
+
prompt_cache_breakpoint: toolOutputs[index].promptCacheBreakpoint
|
|
3766
|
+
}
|
|
3767
|
+
})) : serializedToolOutputs.join("\n")
|
|
3727
3768
|
});
|
|
3728
3769
|
}
|
|
3729
3770
|
continue;
|
|
@@ -3797,23 +3838,37 @@ async function convertToOpenAIResponsesInput({
|
|
|
3797
3838
|
continue;
|
|
3798
3839
|
}
|
|
3799
3840
|
if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
|
|
3841
|
+
const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
|
|
3842
|
+
output,
|
|
3843
|
+
toolResultProviderOptions: part.providerOptions,
|
|
3844
|
+
providerOptionsName
|
|
3845
|
+
});
|
|
3846
|
+
const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
|
|
3847
|
+
{
|
|
3848
|
+
type: "input_text",
|
|
3849
|
+
text: value,
|
|
3850
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3851
|
+
}
|
|
3852
|
+
];
|
|
3800
3853
|
let outputValue;
|
|
3801
3854
|
switch (output.type) {
|
|
3802
3855
|
case "text":
|
|
3803
3856
|
case "error-text":
|
|
3804
|
-
outputValue = output.value;
|
|
3857
|
+
outputValue = convertScalarOutput(output.value);
|
|
3805
3858
|
break;
|
|
3806
3859
|
case "execution-denied":
|
|
3807
|
-
outputValue = (
|
|
3860
|
+
outputValue = convertScalarOutput(
|
|
3861
|
+
(_y = output.reason) != null ? _y : "Tool call execution denied."
|
|
3862
|
+
);
|
|
3808
3863
|
break;
|
|
3809
3864
|
case "json":
|
|
3810
3865
|
case "error-json":
|
|
3811
|
-
outputValue = JSON.stringify(output.value);
|
|
3866
|
+
outputValue = convertScalarOutput(JSON.stringify(output.value));
|
|
3812
3867
|
break;
|
|
3813
3868
|
case "content":
|
|
3814
3869
|
outputValue = output.value.map((item) => {
|
|
3815
3870
|
var _a3, _b2, _c2, _d2, _e2;
|
|
3816
|
-
const
|
|
3871
|
+
const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
|
|
3817
3872
|
item.providerOptions,
|
|
3818
3873
|
providerOptionsName
|
|
3819
3874
|
);
|
|
@@ -3822,8 +3877,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
3822
3877
|
return {
|
|
3823
3878
|
type: "input_text",
|
|
3824
3879
|
text: item.text,
|
|
3825
|
-
...
|
|
3826
|
-
prompt_cache_breakpoint:
|
|
3880
|
+
...promptCacheBreakpoint2 != null && {
|
|
3881
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3827
3882
|
}
|
|
3828
3883
|
};
|
|
3829
3884
|
case "image-data":
|
|
@@ -3831,8 +3886,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
3831
3886
|
type: "input_image",
|
|
3832
3887
|
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3833
3888
|
detail: (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
3834
|
-
...
|
|
3835
|
-
prompt_cache_breakpoint:
|
|
3889
|
+
...promptCacheBreakpoint2 != null && {
|
|
3890
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3836
3891
|
}
|
|
3837
3892
|
};
|
|
3838
3893
|
case "image-url":
|
|
@@ -3840,8 +3895,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
3840
3895
|
type: "input_image",
|
|
3841
3896
|
image_url: item.url,
|
|
3842
3897
|
detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
|
|
3843
|
-
...
|
|
3844
|
-
prompt_cache_breakpoint:
|
|
3898
|
+
...promptCacheBreakpoint2 != null && {
|
|
3899
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3845
3900
|
}
|
|
3846
3901
|
};
|
|
3847
3902
|
case "file-data":
|
|
@@ -3849,16 +3904,16 @@ async function convertToOpenAIResponsesInput({
|
|
|
3849
3904
|
type: "input_file",
|
|
3850
3905
|
filename: (_e2 = item.filename) != null ? _e2 : "data",
|
|
3851
3906
|
file_data: `data:${item.mediaType};base64,${item.data}`,
|
|
3852
|
-
...
|
|
3853
|
-
prompt_cache_breakpoint:
|
|
3907
|
+
...promptCacheBreakpoint2 != null && {
|
|
3908
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3854
3909
|
}
|
|
3855
3910
|
};
|
|
3856
3911
|
case "file-url":
|
|
3857
3912
|
return {
|
|
3858
3913
|
type: "input_file",
|
|
3859
3914
|
file_url: item.url,
|
|
3860
|
-
...
|
|
3861
|
-
prompt_cache_breakpoint:
|
|
3915
|
+
...promptCacheBreakpoint2 != null && {
|
|
3916
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3862
3917
|
}
|
|
3863
3918
|
};
|
|
3864
3919
|
default:
|
|
@@ -3882,6 +3937,11 @@ async function convertToOpenAIResponsesInput({
|
|
|
3882
3937
|
}
|
|
3883
3938
|
const contentValue = await convertFunctionToolResultOutput({
|
|
3884
3939
|
output,
|
|
3940
|
+
promptCacheBreakpoint: getScalarToolResultPromptCacheBreakpoint({
|
|
3941
|
+
output,
|
|
3942
|
+
toolResultProviderOptions: part.providerOptions,
|
|
3943
|
+
providerOptionsName
|
|
3944
|
+
}),
|
|
3885
3945
|
providerOptionsName,
|
|
3886
3946
|
warnings
|
|
3887
3947
|
});
|
|
@@ -7888,7 +7948,7 @@ var OpenAITranscriptionModel = class {
|
|
|
7888
7948
|
};
|
|
7889
7949
|
|
|
7890
7950
|
// src/version.ts
|
|
7891
|
-
var VERSION = true ? "3.0.
|
|
7951
|
+
var VERSION = true ? "3.0.106" : "0.0.0-test";
|
|
7892
7952
|
|
|
7893
7953
|
// src/openai-provider.ts
|
|
7894
7954
|
function createOpenAI(options = {}) {
|