@ai-sdk/openai 3.0.105 → 3.0.107
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.d.mts +17 -15
- package/dist/index.d.ts +17 -15
- package/dist/index.js +178 -105
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +178 -105
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +17 -15
- package/dist/internal/index.d.ts +17 -15
- package/dist/internal/index.js +177 -104
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +177 -104
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/openai-stream-error.ts +58 -3
- package/src/responses/convert-openai-responses-usage.ts +17 -12
- package/src/responses/convert-to-openai-responses-input.ts +101 -21
- package/src/responses/openai-responses-api.ts +34 -58
- package/src/responses/openai-responses-language-model.ts +19 -12
|
@@ -298,23 +298,24 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
298
298
|
} | {
|
|
299
299
|
type: "response.completed" | "response.incomplete";
|
|
300
300
|
response: {
|
|
301
|
-
|
|
301
|
+
incomplete_details?: {
|
|
302
|
+
reason: string;
|
|
303
|
+
} | null | undefined;
|
|
304
|
+
usage?: (Record<string, JSONValue | undefined> & {
|
|
302
305
|
input_tokens: number;
|
|
303
306
|
output_tokens: number;
|
|
304
|
-
input_tokens_details?: {
|
|
307
|
+
input_tokens_details?: (Record<string, JSONValue | undefined> & {
|
|
305
308
|
cached_tokens?: number | null | undefined;
|
|
306
309
|
cache_write_tokens?: number | null | undefined;
|
|
307
310
|
orchestration_input_tokens?: number | null | undefined;
|
|
308
311
|
orchestration_input_cached_tokens?: number | null | undefined;
|
|
309
|
-
} | null | undefined;
|
|
310
|
-
output_tokens_details?: {
|
|
312
|
+
}) | null | undefined;
|
|
313
|
+
output_tokens_details?: (Record<string, JSONValue | undefined> & {
|
|
311
314
|
reasoning_tokens?: number | null | undefined;
|
|
312
315
|
orchestration_output_tokens?: number | null | undefined;
|
|
313
|
-
} | null | undefined;
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
reason: string;
|
|
317
|
-
} | null | undefined;
|
|
316
|
+
}) | null | undefined;
|
|
317
|
+
total_tokens?: number | undefined;
|
|
318
|
+
}) | null | undefined;
|
|
318
319
|
reasoning?: {
|
|
319
320
|
context?: string | null | undefined;
|
|
320
321
|
} | null | undefined;
|
|
@@ -331,20 +332,21 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
331
332
|
incomplete_details?: {
|
|
332
333
|
reason: string;
|
|
333
334
|
} | null | undefined;
|
|
334
|
-
usage?: {
|
|
335
|
+
usage?: (Record<string, JSONValue | undefined> & {
|
|
335
336
|
input_tokens: number;
|
|
336
337
|
output_tokens: number;
|
|
337
|
-
input_tokens_details?: {
|
|
338
|
+
input_tokens_details?: (Record<string, JSONValue | undefined> & {
|
|
338
339
|
cached_tokens?: number | null | undefined;
|
|
339
340
|
cache_write_tokens?: number | null | undefined;
|
|
340
341
|
orchestration_input_tokens?: number | null | undefined;
|
|
341
342
|
orchestration_input_cached_tokens?: number | null | undefined;
|
|
342
|
-
} | null | undefined;
|
|
343
|
-
output_tokens_details?: {
|
|
343
|
+
}) | null | undefined;
|
|
344
|
+
output_tokens_details?: (Record<string, JSONValue | undefined> & {
|
|
344
345
|
reasoning_tokens?: number | null | undefined;
|
|
345
346
|
orchestration_output_tokens?: number | null | undefined;
|
|
346
|
-
} | null | undefined;
|
|
347
|
-
|
|
347
|
+
}) | null | undefined;
|
|
348
|
+
total_tokens?: number | undefined;
|
|
349
|
+
}) | null | undefined;
|
|
348
350
|
reasoning?: {
|
|
349
351
|
context?: string | null | undefined;
|
|
350
352
|
} | null | undefined;
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -298,23 +298,24 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
298
298
|
} | {
|
|
299
299
|
type: "response.completed" | "response.incomplete";
|
|
300
300
|
response: {
|
|
301
|
-
|
|
301
|
+
incomplete_details?: {
|
|
302
|
+
reason: string;
|
|
303
|
+
} | null | undefined;
|
|
304
|
+
usage?: (Record<string, JSONValue | undefined> & {
|
|
302
305
|
input_tokens: number;
|
|
303
306
|
output_tokens: number;
|
|
304
|
-
input_tokens_details?: {
|
|
307
|
+
input_tokens_details?: (Record<string, JSONValue | undefined> & {
|
|
305
308
|
cached_tokens?: number | null | undefined;
|
|
306
309
|
cache_write_tokens?: number | null | undefined;
|
|
307
310
|
orchestration_input_tokens?: number | null | undefined;
|
|
308
311
|
orchestration_input_cached_tokens?: number | null | undefined;
|
|
309
|
-
} | null | undefined;
|
|
310
|
-
output_tokens_details?: {
|
|
312
|
+
}) | null | undefined;
|
|
313
|
+
output_tokens_details?: (Record<string, JSONValue | undefined> & {
|
|
311
314
|
reasoning_tokens?: number | null | undefined;
|
|
312
315
|
orchestration_output_tokens?: number | null | undefined;
|
|
313
|
-
} | null | undefined;
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
reason: string;
|
|
317
|
-
} | null | undefined;
|
|
316
|
+
}) | null | undefined;
|
|
317
|
+
total_tokens?: number | undefined;
|
|
318
|
+
}) | null | undefined;
|
|
318
319
|
reasoning?: {
|
|
319
320
|
context?: string | null | undefined;
|
|
320
321
|
} | null | undefined;
|
|
@@ -331,20 +332,21 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
331
332
|
incomplete_details?: {
|
|
332
333
|
reason: string;
|
|
333
334
|
} | null | undefined;
|
|
334
|
-
usage?: {
|
|
335
|
+
usage?: (Record<string, JSONValue | undefined> & {
|
|
335
336
|
input_tokens: number;
|
|
336
337
|
output_tokens: number;
|
|
337
|
-
input_tokens_details?: {
|
|
338
|
+
input_tokens_details?: (Record<string, JSONValue | undefined> & {
|
|
338
339
|
cached_tokens?: number | null | undefined;
|
|
339
340
|
cache_write_tokens?: number | null | undefined;
|
|
340
341
|
orchestration_input_tokens?: number | null | undefined;
|
|
341
342
|
orchestration_input_cached_tokens?: number | null | undefined;
|
|
342
|
-
} | null | undefined;
|
|
343
|
-
output_tokens_details?: {
|
|
343
|
+
}) | null | undefined;
|
|
344
|
+
output_tokens_details?: (Record<string, JSONValue | undefined> & {
|
|
344
345
|
reasoning_tokens?: number | null | undefined;
|
|
345
346
|
orchestration_output_tokens?: number | null | undefined;
|
|
346
|
-
} | null | undefined;
|
|
347
|
-
|
|
347
|
+
}) | null | undefined;
|
|
348
|
+
total_tokens?: number | undefined;
|
|
349
|
+
}) | null | undefined;
|
|
348
350
|
reasoning?: {
|
|
349
351
|
context?: string | null | undefined;
|
|
350
352
|
} | null | undefined;
|
package/dist/internal/index.js
CHANGED
|
@@ -125,6 +125,22 @@ function getGptVersion(modelId) {
|
|
|
125
125
|
|
|
126
126
|
// src/openai-stream-error.ts
|
|
127
127
|
var import_provider = require("@ai-sdk/provider");
|
|
128
|
+
function createOpenAIProviderStreamError(frame) {
|
|
129
|
+
var _a2, _b;
|
|
130
|
+
const streamError = parseStreamError(frame);
|
|
131
|
+
if (streamError == null) {
|
|
132
|
+
return void 0;
|
|
133
|
+
}
|
|
134
|
+
const statusCode = getStatusCode(streamError);
|
|
135
|
+
return {
|
|
136
|
+
message: streamError.message,
|
|
137
|
+
type: (_a2 = streamError.type) != null ? _a2 : void 0,
|
|
138
|
+
code: (_b = streamError.code) != null ? _b : void 0,
|
|
139
|
+
statusCode,
|
|
140
|
+
isRetryable: isRetryableStreamError(streamError, statusCode),
|
|
141
|
+
data: frame
|
|
142
|
+
};
|
|
143
|
+
}
|
|
128
144
|
async function throwIfOpenAIStreamErrorBeforeOutput({
|
|
129
145
|
stream,
|
|
130
146
|
getError,
|
|
@@ -196,16 +212,14 @@ function parseStreamError(frame) {
|
|
|
196
212
|
return typeof (responseError == null ? void 0 : responseError.message) === "string" ? {
|
|
197
213
|
message: responseError.message,
|
|
198
214
|
code: getStringOrNumber(responseError.code),
|
|
199
|
-
type: "response.failed"
|
|
200
|
-
frame
|
|
215
|
+
type: "response.failed"
|
|
201
216
|
} : void 0;
|
|
202
217
|
}
|
|
203
218
|
const error = (_a2 = asRecord(value.error)) != null ? _a2 : value;
|
|
204
219
|
return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
|
|
205
220
|
message: error.message,
|
|
206
221
|
code: getStringOrNumber(error.code),
|
|
207
|
-
type: typeof error.type === "string" ? error.type : void 0
|
|
208
|
-
frame
|
|
222
|
+
type: typeof error.type === "string" ? error.type : void 0
|
|
209
223
|
} : void 0;
|
|
210
224
|
}
|
|
211
225
|
function getStatusCode(error) {
|
|
@@ -245,6 +259,15 @@ function getStringOrNumber(value) {
|
|
|
245
259
|
function isHttpErrorStatusCode(value) {
|
|
246
260
|
return Number.isInteger(value) && value >= 400 && value <= 599;
|
|
247
261
|
}
|
|
262
|
+
function isRetryableStatusCode(statusCode) {
|
|
263
|
+
return statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500;
|
|
264
|
+
}
|
|
265
|
+
function isRetryableStreamError(error, statusCode) {
|
|
266
|
+
if (error.code === "insufficient_quota" || error.type === "insufficient_quota") {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
return isRetryableStatusCode(statusCode);
|
|
270
|
+
}
|
|
248
271
|
|
|
249
272
|
// src/chat/convert-openai-chat-usage.ts
|
|
250
273
|
function convertOpenAIChatUsage(usage) {
|
|
@@ -3011,23 +3034,34 @@ function serializeToolCallArguments2(input) {
|
|
|
3011
3034
|
}
|
|
3012
3035
|
async function convertFunctionToolResultOutput({
|
|
3013
3036
|
output,
|
|
3037
|
+
promptCacheBreakpoint,
|
|
3014
3038
|
providerOptionsName,
|
|
3015
3039
|
warnings
|
|
3016
3040
|
}) {
|
|
3017
3041
|
var _a2;
|
|
3042
|
+
const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
|
|
3043
|
+
{
|
|
3044
|
+
type: "input_text",
|
|
3045
|
+
text: value,
|
|
3046
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3047
|
+
}
|
|
3048
|
+
];
|
|
3018
3049
|
switch (output.type) {
|
|
3019
3050
|
case "text":
|
|
3020
3051
|
case "error-text":
|
|
3021
|
-
return output.value;
|
|
3022
|
-
case "execution-denied":
|
|
3023
|
-
return (
|
|
3052
|
+
return convertScalarOutput(output.value);
|
|
3053
|
+
case "execution-denied": {
|
|
3054
|
+
return convertScalarOutput(
|
|
3055
|
+
(_a2 = output.reason) != null ? _a2 : "Tool call execution denied."
|
|
3056
|
+
);
|
|
3057
|
+
}
|
|
3024
3058
|
case "json":
|
|
3025
3059
|
case "error-json":
|
|
3026
|
-
return JSON.stringify(output.value);
|
|
3060
|
+
return convertScalarOutput(JSON.stringify(output.value));
|
|
3027
3061
|
case "content":
|
|
3028
3062
|
return output.value.map((item) => {
|
|
3029
3063
|
var _a3, _b, _c, _d, _e;
|
|
3030
|
-
const
|
|
3064
|
+
const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
|
|
3031
3065
|
item.providerOptions,
|
|
3032
3066
|
providerOptionsName
|
|
3033
3067
|
);
|
|
@@ -3036,8 +3070,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3036
3070
|
return {
|
|
3037
3071
|
type: "input_text",
|
|
3038
3072
|
text: item.text,
|
|
3039
|
-
...
|
|
3040
|
-
prompt_cache_breakpoint:
|
|
3073
|
+
...promptCacheBreakpoint2 != null && {
|
|
3074
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3041
3075
|
}
|
|
3042
3076
|
};
|
|
3043
3077
|
}
|
|
@@ -3046,8 +3080,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3046
3080
|
type: "input_image",
|
|
3047
3081
|
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3048
3082
|
detail: (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail,
|
|
3049
|
-
...
|
|
3050
|
-
prompt_cache_breakpoint:
|
|
3083
|
+
...promptCacheBreakpoint2 != null && {
|
|
3084
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3051
3085
|
}
|
|
3052
3086
|
};
|
|
3053
3087
|
}
|
|
@@ -3056,8 +3090,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3056
3090
|
type: "input_image",
|
|
3057
3091
|
image_url: item.url,
|
|
3058
3092
|
detail: (_d = (_c = item.providerOptions) == null ? void 0 : _c[providerOptionsName]) == null ? void 0 : _d.imageDetail,
|
|
3059
|
-
...
|
|
3060
|
-
prompt_cache_breakpoint:
|
|
3093
|
+
...promptCacheBreakpoint2 != null && {
|
|
3094
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3061
3095
|
}
|
|
3062
3096
|
};
|
|
3063
3097
|
}
|
|
@@ -3066,8 +3100,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3066
3100
|
type: "input_file",
|
|
3067
3101
|
filename: (_e = item.filename) != null ? _e : "data",
|
|
3068
3102
|
file_data: `data:${item.mediaType};base64,${item.data}`,
|
|
3069
|
-
...
|
|
3070
|
-
prompt_cache_breakpoint:
|
|
3103
|
+
...promptCacheBreakpoint2 != null && {
|
|
3104
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3071
3105
|
}
|
|
3072
3106
|
};
|
|
3073
3107
|
}
|
|
@@ -3075,8 +3109,8 @@ async function convertFunctionToolResultOutput({
|
|
|
3075
3109
|
return {
|
|
3076
3110
|
type: "input_file",
|
|
3077
3111
|
file_url: item.url,
|
|
3078
|
-
...
|
|
3079
|
-
prompt_cache_breakpoint:
|
|
3112
|
+
...promptCacheBreakpoint2 != null && {
|
|
3113
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3080
3114
|
}
|
|
3081
3115
|
};
|
|
3082
3116
|
}
|
|
@@ -3152,6 +3186,17 @@ function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
|
|
|
3152
3186
|
var _a2;
|
|
3153
3187
|
return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
3154
3188
|
}
|
|
3189
|
+
function getScalarToolResultPromptCacheBreakpoint({
|
|
3190
|
+
output,
|
|
3191
|
+
toolResultProviderOptions,
|
|
3192
|
+
providerOptionsName
|
|
3193
|
+
}) {
|
|
3194
|
+
var _a2;
|
|
3195
|
+
return output.type === "content" ? void 0 : (_a2 = getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName)) != null ? _a2 : getPromptCacheBreakpoint2(
|
|
3196
|
+
toolResultProviderOptions,
|
|
3197
|
+
providerOptionsName
|
|
3198
|
+
);
|
|
3199
|
+
}
|
|
3155
3200
|
function isFileId(data, prefixes) {
|
|
3156
3201
|
if (!prefixes) return false;
|
|
3157
3202
|
return prefixes.some((prefix) => data.startsWith(prefix));
|
|
@@ -3652,22 +3697,41 @@ async function convertToOpenAIResponsesInput({
|
|
|
3652
3697
|
parallelToolResultGroup.metadata.toolCallId
|
|
3653
3698
|
);
|
|
3654
3699
|
const toolOutputs = await Promise.all(
|
|
3655
|
-
parallelToolResultGroup.results.map(
|
|
3656
|
-
|
|
3700
|
+
parallelToolResultGroup.results.map(async (result) => {
|
|
3701
|
+
const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
|
|
3657
3702
|
output: result.output,
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
})
|
|
3661
|
-
|
|
3703
|
+
toolResultProviderOptions: result.providerOptions,
|
|
3704
|
+
providerOptionsName
|
|
3705
|
+
});
|
|
3706
|
+
return {
|
|
3707
|
+
output: await convertFunctionToolResultOutput({
|
|
3708
|
+
output: result.output,
|
|
3709
|
+
providerOptionsName,
|
|
3710
|
+
warnings
|
|
3711
|
+
}),
|
|
3712
|
+
promptCacheBreakpoint
|
|
3713
|
+
};
|
|
3714
|
+
})
|
|
3715
|
+
);
|
|
3716
|
+
const serializedToolOutputs = toolOutputs.map(
|
|
3717
|
+
({ output: output2 }) => typeof output2 === "string" ? output2 : JSON.stringify(output2)
|
|
3718
|
+
);
|
|
3719
|
+
const hasPromptCacheBreakpoint = toolOutputs.some(
|
|
3720
|
+
({ promptCacheBreakpoint }) => promptCacheBreakpoint != null
|
|
3662
3721
|
);
|
|
3663
3722
|
input.push({
|
|
3664
3723
|
type: "function_call_output",
|
|
3665
3724
|
call_id: parallelToolResultGroup.metadata.toolCallId,
|
|
3666
3725
|
// The internal wrapper returns one output containing the child
|
|
3667
3726
|
// results in the same order as the original tool_uses array.
|
|
3668
|
-
output:
|
|
3669
|
-
|
|
3670
|
-
|
|
3727
|
+
output: hasPromptCacheBreakpoint ? serializedToolOutputs.map((text, index) => ({
|
|
3728
|
+
type: "input_text",
|
|
3729
|
+
text: index === 0 ? text : `
|
|
3730
|
+
${text}`,
|
|
3731
|
+
...toolOutputs[index].promptCacheBreakpoint != null && {
|
|
3732
|
+
prompt_cache_breakpoint: toolOutputs[index].promptCacheBreakpoint
|
|
3733
|
+
}
|
|
3734
|
+
})) : serializedToolOutputs.join("\n")
|
|
3671
3735
|
});
|
|
3672
3736
|
}
|
|
3673
3737
|
continue;
|
|
@@ -3741,23 +3805,37 @@ async function convertToOpenAIResponsesInput({
|
|
|
3741
3805
|
continue;
|
|
3742
3806
|
}
|
|
3743
3807
|
if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
|
|
3808
|
+
const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
|
|
3809
|
+
output,
|
|
3810
|
+
toolResultProviderOptions: part.providerOptions,
|
|
3811
|
+
providerOptionsName
|
|
3812
|
+
});
|
|
3813
|
+
const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
|
|
3814
|
+
{
|
|
3815
|
+
type: "input_text",
|
|
3816
|
+
text: value,
|
|
3817
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3818
|
+
}
|
|
3819
|
+
];
|
|
3744
3820
|
let outputValue;
|
|
3745
3821
|
switch (output.type) {
|
|
3746
3822
|
case "text":
|
|
3747
3823
|
case "error-text":
|
|
3748
|
-
outputValue = output.value;
|
|
3824
|
+
outputValue = convertScalarOutput(output.value);
|
|
3749
3825
|
break;
|
|
3750
3826
|
case "execution-denied":
|
|
3751
|
-
outputValue = (
|
|
3827
|
+
outputValue = convertScalarOutput(
|
|
3828
|
+
(_y = output.reason) != null ? _y : "Tool call execution denied."
|
|
3829
|
+
);
|
|
3752
3830
|
break;
|
|
3753
3831
|
case "json":
|
|
3754
3832
|
case "error-json":
|
|
3755
|
-
outputValue = JSON.stringify(output.value);
|
|
3833
|
+
outputValue = convertScalarOutput(JSON.stringify(output.value));
|
|
3756
3834
|
break;
|
|
3757
3835
|
case "content":
|
|
3758
3836
|
outputValue = output.value.map((item) => {
|
|
3759
3837
|
var _a3, _b2, _c2, _d2, _e2;
|
|
3760
|
-
const
|
|
3838
|
+
const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
|
|
3761
3839
|
item.providerOptions,
|
|
3762
3840
|
providerOptionsName
|
|
3763
3841
|
);
|
|
@@ -3766,8 +3844,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
3766
3844
|
return {
|
|
3767
3845
|
type: "input_text",
|
|
3768
3846
|
text: item.text,
|
|
3769
|
-
...
|
|
3770
|
-
prompt_cache_breakpoint:
|
|
3847
|
+
...promptCacheBreakpoint2 != null && {
|
|
3848
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3771
3849
|
}
|
|
3772
3850
|
};
|
|
3773
3851
|
case "image-data":
|
|
@@ -3775,8 +3853,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
3775
3853
|
type: "input_image",
|
|
3776
3854
|
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3777
3855
|
detail: (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
3778
|
-
...
|
|
3779
|
-
prompt_cache_breakpoint:
|
|
3856
|
+
...promptCacheBreakpoint2 != null && {
|
|
3857
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3780
3858
|
}
|
|
3781
3859
|
};
|
|
3782
3860
|
case "image-url":
|
|
@@ -3784,8 +3862,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
3784
3862
|
type: "input_image",
|
|
3785
3863
|
image_url: item.url,
|
|
3786
3864
|
detail: (_d2 = (_c2 = item.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail,
|
|
3787
|
-
...
|
|
3788
|
-
prompt_cache_breakpoint:
|
|
3865
|
+
...promptCacheBreakpoint2 != null && {
|
|
3866
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3789
3867
|
}
|
|
3790
3868
|
};
|
|
3791
3869
|
case "file-data":
|
|
@@ -3793,16 +3871,16 @@ async function convertToOpenAIResponsesInput({
|
|
|
3793
3871
|
type: "input_file",
|
|
3794
3872
|
filename: (_e2 = item.filename) != null ? _e2 : "data",
|
|
3795
3873
|
file_data: `data:${item.mediaType};base64,${item.data}`,
|
|
3796
|
-
...
|
|
3797
|
-
prompt_cache_breakpoint:
|
|
3874
|
+
...promptCacheBreakpoint2 != null && {
|
|
3875
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3798
3876
|
}
|
|
3799
3877
|
};
|
|
3800
3878
|
case "file-url":
|
|
3801
3879
|
return {
|
|
3802
3880
|
type: "input_file",
|
|
3803
3881
|
file_url: item.url,
|
|
3804
|
-
...
|
|
3805
|
-
prompt_cache_breakpoint:
|
|
3882
|
+
...promptCacheBreakpoint2 != null && {
|
|
3883
|
+
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
3806
3884
|
}
|
|
3807
3885
|
};
|
|
3808
3886
|
default:
|
|
@@ -3826,6 +3904,11 @@ async function convertToOpenAIResponsesInput({
|
|
|
3826
3904
|
}
|
|
3827
3905
|
const contentValue = await convertFunctionToolResultOutput({
|
|
3828
3906
|
output,
|
|
3907
|
+
promptCacheBreakpoint: getScalarToolResultPromptCacheBreakpoint({
|
|
3908
|
+
output,
|
|
3909
|
+
toolResultProviderOptions: part.providerOptions,
|
|
3910
|
+
providerOptionsName
|
|
3911
|
+
}),
|
|
3829
3912
|
providerOptionsName,
|
|
3830
3913
|
warnings
|
|
3831
3914
|
});
|
|
@@ -3892,6 +3975,31 @@ var jsonValueSchema = import_v418.z.lazy(
|
|
|
3892
3975
|
import_v418.z.record(import_v418.z.string(), jsonValueSchema.optional())
|
|
3893
3976
|
])
|
|
3894
3977
|
);
|
|
3978
|
+
var jsonObjectSchema = import_v418.z.record(import_v418.z.string(), jsonValueSchema.optional());
|
|
3979
|
+
var openaiResponsesUsageSchema = import_v418.z.intersection(
|
|
3980
|
+
jsonObjectSchema,
|
|
3981
|
+
import_v418.z.object({
|
|
3982
|
+
input_tokens: import_v418.z.number(),
|
|
3983
|
+
input_tokens_details: import_v418.z.intersection(
|
|
3984
|
+
jsonObjectSchema,
|
|
3985
|
+
import_v418.z.object({
|
|
3986
|
+
cached_tokens: import_v418.z.number().nullish(),
|
|
3987
|
+
cache_write_tokens: import_v418.z.number().nullish(),
|
|
3988
|
+
orchestration_input_tokens: import_v418.z.number().nullish(),
|
|
3989
|
+
orchestration_input_cached_tokens: import_v418.z.number().nullish()
|
|
3990
|
+
})
|
|
3991
|
+
).nullish(),
|
|
3992
|
+
output_tokens: import_v418.z.number(),
|
|
3993
|
+
output_tokens_details: import_v418.z.intersection(
|
|
3994
|
+
jsonObjectSchema,
|
|
3995
|
+
import_v418.z.object({
|
|
3996
|
+
reasoning_tokens: import_v418.z.number().nullish(),
|
|
3997
|
+
orchestration_output_tokens: import_v418.z.number().nullish()
|
|
3998
|
+
})
|
|
3999
|
+
).nullish(),
|
|
4000
|
+
total_tokens: import_v418.z.number().optional()
|
|
4001
|
+
})
|
|
4002
|
+
);
|
|
3895
4003
|
function isRecord(value) {
|
|
3896
4004
|
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
3897
4005
|
}
|
|
@@ -4003,20 +4111,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils26.lazySchema)(
|
|
|
4003
4111
|
type: import_v418.z.enum(["response.completed", "response.incomplete"]),
|
|
4004
4112
|
response: import_v418.z.object({
|
|
4005
4113
|
incomplete_details: import_v418.z.object({ reason: import_v418.z.string() }).nullish(),
|
|
4006
|
-
usage:
|
|
4007
|
-
input_tokens: import_v418.z.number(),
|
|
4008
|
-
input_tokens_details: import_v418.z.object({
|
|
4009
|
-
cached_tokens: import_v418.z.number().nullish(),
|
|
4010
|
-
cache_write_tokens: import_v418.z.number().nullish(),
|
|
4011
|
-
orchestration_input_tokens: import_v418.z.number().nullish(),
|
|
4012
|
-
orchestration_input_cached_tokens: import_v418.z.number().nullish()
|
|
4013
|
-
}).nullish(),
|
|
4014
|
-
output_tokens: import_v418.z.number(),
|
|
4015
|
-
output_tokens_details: import_v418.z.object({
|
|
4016
|
-
reasoning_tokens: import_v418.z.number().nullish(),
|
|
4017
|
-
orchestration_output_tokens: import_v418.z.number().nullish()
|
|
4018
|
-
}).nullish()
|
|
4019
|
-
}),
|
|
4114
|
+
usage: openaiResponsesUsageSchema.nullish(),
|
|
4020
4115
|
reasoning: import_v418.z.object({
|
|
4021
4116
|
context: import_v418.z.string().nullish()
|
|
4022
4117
|
}).nullish(),
|
|
@@ -4032,20 +4127,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils26.lazySchema)(
|
|
|
4032
4127
|
message: import_v418.z.string()
|
|
4033
4128
|
}).nullish(),
|
|
4034
4129
|
incomplete_details: import_v418.z.object({ reason: import_v418.z.string() }).nullish(),
|
|
4035
|
-
usage:
|
|
4036
|
-
input_tokens: import_v418.z.number(),
|
|
4037
|
-
input_tokens_details: import_v418.z.object({
|
|
4038
|
-
cached_tokens: import_v418.z.number().nullish(),
|
|
4039
|
-
cache_write_tokens: import_v418.z.number().nullish(),
|
|
4040
|
-
orchestration_input_tokens: import_v418.z.number().nullish(),
|
|
4041
|
-
orchestration_input_cached_tokens: import_v418.z.number().nullish()
|
|
4042
|
-
}).nullish(),
|
|
4043
|
-
output_tokens: import_v418.z.number(),
|
|
4044
|
-
output_tokens_details: import_v418.z.object({
|
|
4045
|
-
reasoning_tokens: import_v418.z.number().nullish(),
|
|
4046
|
-
orchestration_output_tokens: import_v418.z.number().nullish()
|
|
4047
|
-
}).nullish()
|
|
4048
|
-
}).nullish(),
|
|
4130
|
+
usage: openaiResponsesUsageSchema.nullish(),
|
|
4049
4131
|
reasoning: import_v418.z.object({
|
|
4050
4132
|
context: import_v418.z.string().nullish()
|
|
4051
4133
|
}).nullish(),
|
|
@@ -4811,20 +4893,7 @@ var openaiResponsesResponseSchema = (0, import_provider_utils26.lazySchema)(
|
|
|
4811
4893
|
context: import_v418.z.string().nullish()
|
|
4812
4894
|
}).nullish(),
|
|
4813
4895
|
incomplete_details: import_v418.z.object({ reason: import_v418.z.string() }).nullish(),
|
|
4814
|
-
usage:
|
|
4815
|
-
input_tokens: import_v418.z.number(),
|
|
4816
|
-
input_tokens_details: import_v418.z.object({
|
|
4817
|
-
cached_tokens: import_v418.z.number().nullish(),
|
|
4818
|
-
cache_write_tokens: import_v418.z.number().nullish(),
|
|
4819
|
-
orchestration_input_tokens: import_v418.z.number().nullish(),
|
|
4820
|
-
orchestration_input_cached_tokens: import_v418.z.number().nullish()
|
|
4821
|
-
}).nullish(),
|
|
4822
|
-
output_tokens: import_v418.z.number(),
|
|
4823
|
-
output_tokens_details: import_v418.z.object({
|
|
4824
|
-
reasoning_tokens: import_v418.z.number().nullish(),
|
|
4825
|
-
orchestration_output_tokens: import_v418.z.number().nullish()
|
|
4826
|
-
}).nullish()
|
|
4827
|
-
}).optional()
|
|
4896
|
+
usage: openaiResponsesUsageSchema.nullish()
|
|
4828
4897
|
})
|
|
4829
4898
|
)
|
|
4830
4899
|
);
|
|
@@ -6735,7 +6804,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6735
6804
|
controller.enqueue({ type: "stream-start", warnings });
|
|
6736
6805
|
},
|
|
6737
6806
|
transform(chunk, controller) {
|
|
6738
|
-
var _a3, _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;
|
|
6807
|
+
var _a3, _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, _Q, _R, _S;
|
|
6739
6808
|
if (options.includeRawChunks) {
|
|
6740
6809
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
6741
6810
|
}
|
|
@@ -7556,15 +7625,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7556
7625
|
raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
|
|
7557
7626
|
};
|
|
7558
7627
|
}
|
|
7559
|
-
usage = value.response.usage;
|
|
7628
|
+
usage = (_A = value.response.usage) != null ? _A : void 0;
|
|
7560
7629
|
if (typeof value.response.service_tier === "string") {
|
|
7561
7630
|
serviceTier = value.response.service_tier;
|
|
7562
7631
|
}
|
|
7563
|
-
if (((
|
|
7632
|
+
if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
|
|
7564
7633
|
reasoningContext = value.response.reasoning.context;
|
|
7565
7634
|
}
|
|
7566
7635
|
} else if (isResponseFailedChunk(value)) {
|
|
7567
|
-
const incompleteReason = (
|
|
7636
|
+
const incompleteReason = (_C = value.response.incomplete_details) == null ? void 0 : _C.reason;
|
|
7568
7637
|
finishReason = {
|
|
7569
7638
|
unified: incompleteReason ? mapOpenAIResponseFinishReason({
|
|
7570
7639
|
finishReason: incompleteReason,
|
|
@@ -7572,23 +7641,24 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7572
7641
|
}) : "error",
|
|
7573
7642
|
raw: incompleteReason != null ? incompleteReason : "error"
|
|
7574
7643
|
};
|
|
7575
|
-
usage = (
|
|
7576
|
-
if (((
|
|
7644
|
+
usage = (_D = value.response.usage) != null ? _D : void 0;
|
|
7645
|
+
if (((_E = value.response.reasoning) == null ? void 0 : _E.context) != null) {
|
|
7577
7646
|
reasoningContext = value.response.reasoning.context;
|
|
7578
7647
|
}
|
|
7579
7648
|
if (!encounteredStreamError && value.response.error != null) {
|
|
7580
7649
|
encounteredStreamError = true;
|
|
7650
|
+
const error = {
|
|
7651
|
+
type: "response.failed",
|
|
7652
|
+
sequence_number: value.sequence_number,
|
|
7653
|
+
response: {
|
|
7654
|
+
error: value.response.error,
|
|
7655
|
+
incomplete_details: value.response.incomplete_details,
|
|
7656
|
+
service_tier: value.response.service_tier
|
|
7657
|
+
}
|
|
7658
|
+
};
|
|
7581
7659
|
controller.enqueue({
|
|
7582
7660
|
type: "error",
|
|
7583
|
-
error:
|
|
7584
|
-
type: "response.failed",
|
|
7585
|
-
sequence_number: value.sequence_number,
|
|
7586
|
-
response: {
|
|
7587
|
-
error: value.response.error,
|
|
7588
|
-
incomplete_details: value.response.incomplete_details,
|
|
7589
|
-
service_tier: value.response.service_tier
|
|
7590
|
-
}
|
|
7591
|
-
}
|
|
7661
|
+
error: (_F = createOpenAIProviderStreamError(error)) != null ? _F : error
|
|
7592
7662
|
});
|
|
7593
7663
|
}
|
|
7594
7664
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
@@ -7597,7 +7667,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7597
7667
|
controller.enqueue({
|
|
7598
7668
|
type: "source",
|
|
7599
7669
|
sourceType: "url",
|
|
7600
|
-
id: (
|
|
7670
|
+
id: (_I = (_H = (_G = self.config).generateId) == null ? void 0 : _H.call(_G)) != null ? _I : (0, import_provider_utils36.generateId)(),
|
|
7601
7671
|
url: value.annotation.url,
|
|
7602
7672
|
title: value.annotation.title
|
|
7603
7673
|
});
|
|
@@ -7605,7 +7675,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7605
7675
|
controller.enqueue({
|
|
7606
7676
|
type: "source",
|
|
7607
7677
|
sourceType: "document",
|
|
7608
|
-
id: (
|
|
7678
|
+
id: (_L = (_K = (_J = self.config).generateId) == null ? void 0 : _K.call(_J)) != null ? _L : (0, import_provider_utils36.generateId)(),
|
|
7609
7679
|
mediaType: "text/plain",
|
|
7610
7680
|
title: value.annotation.filename,
|
|
7611
7681
|
filename: value.annotation.filename,
|
|
@@ -7621,7 +7691,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7621
7691
|
controller.enqueue({
|
|
7622
7692
|
type: "source",
|
|
7623
7693
|
sourceType: "document",
|
|
7624
|
-
id: (
|
|
7694
|
+
id: (_O = (_N = (_M = self.config).generateId) == null ? void 0 : _N.call(_M)) != null ? _O : (0, import_provider_utils36.generateId)(),
|
|
7625
7695
|
mediaType: "text/plain",
|
|
7626
7696
|
title: value.annotation.filename,
|
|
7627
7697
|
filename: value.annotation.filename,
|
|
@@ -7637,7 +7707,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7637
7707
|
controller.enqueue({
|
|
7638
7708
|
type: "source",
|
|
7639
7709
|
sourceType: "document",
|
|
7640
|
-
id: (
|
|
7710
|
+
id: (_R = (_Q = (_P = self.config).generateId) == null ? void 0 : _Q.call(_P)) != null ? _R : (0, import_provider_utils36.generateId)(),
|
|
7641
7711
|
mediaType: "application/octet-stream",
|
|
7642
7712
|
title: value.annotation.file_id,
|
|
7643
7713
|
filename: value.annotation.file_id,
|
|
@@ -7653,7 +7723,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7653
7723
|
} else if (isErrorChunk(value)) {
|
|
7654
7724
|
encounteredStreamError = true;
|
|
7655
7725
|
finishReason = { unified: "error", raw: "error" };
|
|
7656
|
-
controller.enqueue({
|
|
7726
|
+
controller.enqueue({
|
|
7727
|
+
type: "error",
|
|
7728
|
+
error: (_S = createOpenAIProviderStreamError(value)) != null ? _S : value
|
|
7729
|
+
});
|
|
7657
7730
|
}
|
|
7658
7731
|
},
|
|
7659
7732
|
flush(controller) {
|