@ai-sdk/openai 2.0.110 → 2.0.111
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 +7 -0
- package/dist/index.d.mts +13 -3
- package/dist/index.d.ts +13 -3
- package/dist/index.js +306 -78
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +306 -78
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +7 -3
- package/dist/internal/index.d.ts +7 -3
- package/dist/internal/index.js +305 -77
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +305 -77
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -44,7 +44,7 @@ function getOpenAILanguageModelCapabilities(modelId) {
|
|
|
44
44
|
const supportsFlexProcessing = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
45
45
|
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") && !modelId.startsWith("gpt-5.4-nano") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
46
46
|
const isReasoningModel = !(modelId.startsWith("gpt-3") || modelId.startsWith("gpt-4") || modelId.startsWith("chatgpt-4o") || modelId.startsWith("gpt-5-chat"));
|
|
47
|
-
const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1") || modelId.startsWith("gpt-5.2") || modelId.startsWith("gpt-5.3") || modelId.startsWith("gpt-5.4");
|
|
47
|
+
const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1") || modelId.startsWith("gpt-5.2") || modelId.startsWith("gpt-5.3") || modelId.startsWith("gpt-5.4") || modelId.startsWith("gpt-5.6");
|
|
48
48
|
const systemMessageMode = isReasoningModel ? "developer" : "system";
|
|
49
49
|
return {
|
|
50
50
|
supportsFlexProcessing,
|
|
@@ -60,22 +60,46 @@ import {
|
|
|
60
60
|
UnsupportedFunctionalityError
|
|
61
61
|
} from "@ai-sdk/provider";
|
|
62
62
|
import { convertToBase64 } from "@ai-sdk/provider-utils";
|
|
63
|
+
function getPromptCacheBreakpoint(providerOptions) {
|
|
64
|
+
var _a;
|
|
65
|
+
return (_a = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a.promptCacheBreakpoint;
|
|
66
|
+
}
|
|
63
67
|
function convertToOpenAIChatMessages({
|
|
64
68
|
prompt,
|
|
65
69
|
systemMessageMode = "system"
|
|
66
70
|
}) {
|
|
67
71
|
const messages = [];
|
|
68
72
|
const warnings = [];
|
|
69
|
-
for (const { role, content } of prompt) {
|
|
73
|
+
for (const { role, content, providerOptions } of prompt) {
|
|
70
74
|
switch (role) {
|
|
71
75
|
case "system": {
|
|
72
76
|
switch (systemMessageMode) {
|
|
73
77
|
case "system": {
|
|
74
|
-
|
|
78
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint(providerOptions);
|
|
79
|
+
messages.push({
|
|
80
|
+
role: "system",
|
|
81
|
+
content: promptCacheBreakpoint == null ? content : [
|
|
82
|
+
{
|
|
83
|
+
type: "text",
|
|
84
|
+
text: content,
|
|
85
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
});
|
|
75
89
|
break;
|
|
76
90
|
}
|
|
77
91
|
case "developer": {
|
|
78
|
-
|
|
92
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint(providerOptions);
|
|
93
|
+
messages.push({
|
|
94
|
+
role: "developer",
|
|
95
|
+
content: promptCacheBreakpoint == null ? content : [
|
|
96
|
+
{
|
|
97
|
+
type: "text",
|
|
98
|
+
text: content,
|
|
99
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
});
|
|
79
103
|
break;
|
|
80
104
|
}
|
|
81
105
|
case "remove": {
|
|
@@ -95,7 +119,7 @@ function convertToOpenAIChatMessages({
|
|
|
95
119
|
break;
|
|
96
120
|
}
|
|
97
121
|
case "user": {
|
|
98
|
-
if (content.length === 1 && content[0].type === "text") {
|
|
122
|
+
if (content.length === 1 && content[0].type === "text" && getPromptCacheBreakpoint(content[0].providerOptions) == null) {
|
|
99
123
|
messages.push({ role: "user", content: content[0].text });
|
|
100
124
|
break;
|
|
101
125
|
}
|
|
@@ -105,9 +129,21 @@ function convertToOpenAIChatMessages({
|
|
|
105
129
|
var _a, _b, _c;
|
|
106
130
|
switch (part.type) {
|
|
107
131
|
case "text": {
|
|
108
|
-
|
|
132
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint(
|
|
133
|
+
part.providerOptions
|
|
134
|
+
);
|
|
135
|
+
return {
|
|
136
|
+
type: "text",
|
|
137
|
+
text: part.text,
|
|
138
|
+
...promptCacheBreakpoint != null && {
|
|
139
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
140
|
+
}
|
|
141
|
+
};
|
|
109
142
|
}
|
|
110
143
|
case "file": {
|
|
144
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint(
|
|
145
|
+
part.providerOptions
|
|
146
|
+
);
|
|
111
147
|
if (part.mediaType.startsWith("image/")) {
|
|
112
148
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
113
149
|
return {
|
|
@@ -116,6 +152,9 @@ function convertToOpenAIChatMessages({
|
|
|
116
152
|
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`,
|
|
117
153
|
// OpenAI specific extension: image detail
|
|
118
154
|
detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
|
|
155
|
+
},
|
|
156
|
+
...promptCacheBreakpoint != null && {
|
|
157
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
119
158
|
}
|
|
120
159
|
};
|
|
121
160
|
} else if (part.mediaType.startsWith("audio/")) {
|
|
@@ -131,6 +170,9 @@ function convertToOpenAIChatMessages({
|
|
|
131
170
|
input_audio: {
|
|
132
171
|
data: convertToBase64(part.data),
|
|
133
172
|
format: "wav"
|
|
173
|
+
},
|
|
174
|
+
...promptCacheBreakpoint != null && {
|
|
175
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
134
176
|
}
|
|
135
177
|
};
|
|
136
178
|
}
|
|
@@ -141,6 +183,9 @@ function convertToOpenAIChatMessages({
|
|
|
141
183
|
input_audio: {
|
|
142
184
|
data: convertToBase64(part.data),
|
|
143
185
|
format: "mp3"
|
|
186
|
+
},
|
|
187
|
+
...promptCacheBreakpoint != null && {
|
|
188
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
144
189
|
}
|
|
145
190
|
};
|
|
146
191
|
}
|
|
@@ -161,6 +206,9 @@ function convertToOpenAIChatMessages({
|
|
|
161
206
|
file: typeof part.data === "string" && part.data.startsWith("file-") ? { file_id: part.data } : {
|
|
162
207
|
filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
|
|
163
208
|
file_data: `data:application/pdf;base64,${convertToBase64(part.data)}`
|
|
209
|
+
},
|
|
210
|
+
...promptCacheBreakpoint != null && {
|
|
211
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
164
212
|
}
|
|
165
213
|
};
|
|
166
214
|
} else {
|
|
@@ -176,11 +224,24 @@ function convertToOpenAIChatMessages({
|
|
|
176
224
|
}
|
|
177
225
|
case "assistant": {
|
|
178
226
|
let text = "";
|
|
227
|
+
const textParts = [];
|
|
228
|
+
let hasPromptCacheBreakpoint = false;
|
|
179
229
|
const toolCalls = [];
|
|
180
230
|
for (const part of content) {
|
|
181
231
|
switch (part.type) {
|
|
182
232
|
case "text": {
|
|
233
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint(
|
|
234
|
+
part.providerOptions
|
|
235
|
+
);
|
|
183
236
|
text += part.text;
|
|
237
|
+
textParts.push({
|
|
238
|
+
type: "text",
|
|
239
|
+
text: part.text,
|
|
240
|
+
...promptCacheBreakpoint != null && {
|
|
241
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
hasPromptCacheBreakpoint || (hasPromptCacheBreakpoint = promptCacheBreakpoint != null);
|
|
184
245
|
break;
|
|
185
246
|
}
|
|
186
247
|
case "tool-call": {
|
|
@@ -198,7 +259,7 @@ function convertToOpenAIChatMessages({
|
|
|
198
259
|
}
|
|
199
260
|
messages.push({
|
|
200
261
|
role: "assistant",
|
|
201
|
-
content: text,
|
|
262
|
+
content: hasPromptCacheBreakpoint ? textParts : text,
|
|
202
263
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
203
264
|
});
|
|
204
265
|
break;
|
|
@@ -206,6 +267,9 @@ function convertToOpenAIChatMessages({
|
|
|
206
267
|
case "tool": {
|
|
207
268
|
for (const toolResponse of content) {
|
|
208
269
|
const output = toolResponse.output;
|
|
270
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint(
|
|
271
|
+
toolResponse.providerOptions
|
|
272
|
+
);
|
|
209
273
|
let contentValue;
|
|
210
274
|
switch (output.type) {
|
|
211
275
|
case "text":
|
|
@@ -221,7 +285,13 @@ function convertToOpenAIChatMessages({
|
|
|
221
285
|
messages.push({
|
|
222
286
|
role: "tool",
|
|
223
287
|
tool_call_id: toolResponse.toolCallId,
|
|
224
|
-
content: contentValue
|
|
288
|
+
content: promptCacheBreakpoint == null ? contentValue : [
|
|
289
|
+
{
|
|
290
|
+
type: "text",
|
|
291
|
+
text: contentValue,
|
|
292
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
293
|
+
}
|
|
294
|
+
]
|
|
225
295
|
});
|
|
226
296
|
}
|
|
227
297
|
break;
|
|
@@ -327,7 +397,8 @@ var openaiChatResponseSchema = lazyValidator(
|
|
|
327
397
|
completion_tokens: z2.number().nullish(),
|
|
328
398
|
total_tokens: z2.number().nullish(),
|
|
329
399
|
prompt_tokens_details: z2.object({
|
|
330
|
-
cached_tokens: z2.number().nullish()
|
|
400
|
+
cached_tokens: z2.number().nullish(),
|
|
401
|
+
cache_write_tokens: z2.number().nullish()
|
|
331
402
|
}).nullish(),
|
|
332
403
|
completion_tokens_details: z2.object({
|
|
333
404
|
reasoning_tokens: z2.number().nullish(),
|
|
@@ -396,7 +467,8 @@ var openaiChatChunkSchema = lazyValidator(
|
|
|
396
467
|
completion_tokens: z2.number().nullish(),
|
|
397
468
|
total_tokens: z2.number().nullish(),
|
|
398
469
|
prompt_tokens_details: z2.object({
|
|
399
|
-
cached_tokens: z2.number().nullish()
|
|
470
|
+
cached_tokens: z2.number().nullish(),
|
|
471
|
+
cache_write_tokens: z2.number().nullish()
|
|
400
472
|
}).nullish(),
|
|
401
473
|
completion_tokens_details: z2.object({
|
|
402
474
|
reasoning_tokens: z2.number().nullish(),
|
|
@@ -448,7 +520,7 @@ var openaiChatLanguageModelOptions = lazyValidator2(
|
|
|
448
520
|
/**
|
|
449
521
|
* Reasoning effort for reasoning models. Defaults to `medium`.
|
|
450
522
|
*/
|
|
451
|
-
reasoningEffort: z3.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(),
|
|
523
|
+
reasoningEffort: z3.enum(["none", "minimal", "low", "medium", "high", "xhigh", "max"]).optional(),
|
|
452
524
|
/**
|
|
453
525
|
* Maximum number of completion tokens to generate. Useful for reasoning models.
|
|
454
526
|
*/
|
|
@@ -498,11 +570,22 @@ var openaiChatLanguageModelOptions = lazyValidator2(
|
|
|
498
570
|
* Useful for improving cache hit rates and working around automatic caching issues.
|
|
499
571
|
*/
|
|
500
572
|
promptCacheKey: z3.string().optional(),
|
|
573
|
+
/**
|
|
574
|
+
* Prompt cache behavior for GPT-5.6 and later models.
|
|
575
|
+
* `mode` controls whether OpenAI also places an implicit breakpoint.
|
|
576
|
+
* `ttl` sets the minimum cache lifetime and currently only supports 30 minutes.
|
|
577
|
+
*/
|
|
578
|
+
promptCacheOptions: z3.object({
|
|
579
|
+
mode: z3.enum(["implicit", "explicit"]).optional(),
|
|
580
|
+
ttl: z3.literal("30m").optional()
|
|
581
|
+
}).optional(),
|
|
501
582
|
/**
|
|
502
583
|
* The retention policy for the prompt cache.
|
|
503
584
|
* - 'in_memory': Default. Standard prompt caching behavior.
|
|
504
585
|
* - '24h': Extended prompt caching that keeps cached prefixes active for up to 24 hours.
|
|
505
|
-
*
|
|
586
|
+
* Available for models before GPT-5.6 that support extended caching.
|
|
587
|
+
*
|
|
588
|
+
* @deprecated For GPT-5.6 and later models, use `promptCacheOptions.ttl`.
|
|
506
589
|
*
|
|
507
590
|
* @default 'in_memory'
|
|
508
591
|
*/
|
|
@@ -676,6 +759,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
676
759
|
reasoning_effort: openaiOptions.reasoningEffort,
|
|
677
760
|
service_tier: openaiOptions.serviceTier,
|
|
678
761
|
prompt_cache_key: openaiOptions.promptCacheKey,
|
|
762
|
+
prompt_cache_options: openaiOptions.promptCacheOptions,
|
|
679
763
|
prompt_cache_retention: openaiOptions.promptCacheRetention,
|
|
680
764
|
safety_identifier: openaiOptions.safetyIdentifier,
|
|
681
765
|
// messages:
|
|
@@ -841,6 +925,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
841
925
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
|
|
842
926
|
providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
|
|
843
927
|
}
|
|
928
|
+
if ((promptTokenDetails == null ? void 0 : promptTokenDetails.cache_write_tokens) != null) {
|
|
929
|
+
providerMetadata.openai.usage = {
|
|
930
|
+
cacheWriteTokens: promptTokenDetails.cache_write_tokens
|
|
931
|
+
};
|
|
932
|
+
}
|
|
844
933
|
if (((_f = choice.logprobs) == null ? void 0 : _f.content) != null) {
|
|
845
934
|
providerMetadata.openai.logprobs = choice.logprobs.content;
|
|
846
935
|
}
|
|
@@ -904,7 +993,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
904
993
|
controller.enqueue({ type: "stream-start", warnings });
|
|
905
994
|
},
|
|
906
995
|
transform(chunk, controller) {
|
|
907
|
-
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;
|
|
996
|
+
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;
|
|
908
997
|
if (options.includeRawChunks) {
|
|
909
998
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
910
999
|
}
|
|
@@ -935,18 +1024,23 @@ var OpenAIChatLanguageModel = class {
|
|
|
935
1024
|
usage.totalTokens = (_c = value.usage.total_tokens) != null ? _c : void 0;
|
|
936
1025
|
usage.reasoningTokens = (_e = (_d = value.usage.completion_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : void 0;
|
|
937
1026
|
usage.cachedInputTokens = (_g = (_f = value.usage.prompt_tokens_details) == null ? void 0 : _f.cached_tokens) != null ? _g : void 0;
|
|
938
|
-
if (((_h = value.usage.
|
|
939
|
-
providerMetadata.openai.
|
|
1027
|
+
if (((_h = value.usage.prompt_tokens_details) == null ? void 0 : _h.cache_write_tokens) != null) {
|
|
1028
|
+
providerMetadata.openai.usage = {
|
|
1029
|
+
cacheWriteTokens: value.usage.prompt_tokens_details.cache_write_tokens
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
if (((_i = value.usage.completion_tokens_details) == null ? void 0 : _i.accepted_prediction_tokens) != null) {
|
|
1033
|
+
providerMetadata.openai.acceptedPredictionTokens = (_j = value.usage.completion_tokens_details) == null ? void 0 : _j.accepted_prediction_tokens;
|
|
940
1034
|
}
|
|
941
|
-
if (((
|
|
942
|
-
providerMetadata.openai.rejectedPredictionTokens = (
|
|
1035
|
+
if (((_k = value.usage.completion_tokens_details) == null ? void 0 : _k.rejected_prediction_tokens) != null) {
|
|
1036
|
+
providerMetadata.openai.rejectedPredictionTokens = (_l = value.usage.completion_tokens_details) == null ? void 0 : _l.rejected_prediction_tokens;
|
|
943
1037
|
}
|
|
944
1038
|
}
|
|
945
1039
|
const choice = value.choices[0];
|
|
946
1040
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
947
1041
|
finishReason = mapOpenAIFinishReason(choice.finish_reason);
|
|
948
1042
|
}
|
|
949
|
-
if (((
|
|
1043
|
+
if (((_m = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _m.content) != null) {
|
|
950
1044
|
providerMetadata.openai.logprobs = choice.logprobs.content;
|
|
951
1045
|
}
|
|
952
1046
|
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
@@ -980,7 +1074,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
980
1074
|
message: `Expected 'id' to be a string.`
|
|
981
1075
|
});
|
|
982
1076
|
}
|
|
983
|
-
if (((
|
|
1077
|
+
if (((_n = toolCallDelta.function) == null ? void 0 : _n.name) == null) {
|
|
984
1078
|
throw new InvalidResponseDataError({
|
|
985
1079
|
data: toolCallDelta,
|
|
986
1080
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -996,12 +1090,12 @@ var OpenAIChatLanguageModel = class {
|
|
|
996
1090
|
type: "function",
|
|
997
1091
|
function: {
|
|
998
1092
|
name: toolCallDelta.function.name,
|
|
999
|
-
arguments: (
|
|
1093
|
+
arguments: (_o = toolCallDelta.function.arguments) != null ? _o : ""
|
|
1000
1094
|
},
|
|
1001
1095
|
hasFinished: false
|
|
1002
1096
|
};
|
|
1003
1097
|
const toolCall2 = toolCalls[index];
|
|
1004
|
-
if (((
|
|
1098
|
+
if (((_p = toolCall2.function) == null ? void 0 : _p.name) != null && ((_q = toolCall2.function) == null ? void 0 : _q.arguments) != null) {
|
|
1005
1099
|
if (toolCall2.function.arguments.length > 0) {
|
|
1006
1100
|
controller.enqueue({
|
|
1007
1101
|
type: "tool-input-delta",
|
|
@@ -1016,7 +1110,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1016
1110
|
});
|
|
1017
1111
|
controller.enqueue({
|
|
1018
1112
|
type: "tool-call",
|
|
1019
|
-
toolCallId: (
|
|
1113
|
+
toolCallId: (_r = toolCall2.id) != null ? _r : generateId(),
|
|
1020
1114
|
toolName: toolCall2.function.name,
|
|
1021
1115
|
input: toolCall2.function.arguments
|
|
1022
1116
|
});
|
|
@@ -1029,22 +1123,22 @@ var OpenAIChatLanguageModel = class {
|
|
|
1029
1123
|
if (toolCall.hasFinished) {
|
|
1030
1124
|
continue;
|
|
1031
1125
|
}
|
|
1032
|
-
if (((
|
|
1033
|
-
toolCall.function.arguments += (
|
|
1126
|
+
if (((_s = toolCallDelta.function) == null ? void 0 : _s.arguments) != null) {
|
|
1127
|
+
toolCall.function.arguments += (_u = (_t = toolCallDelta.function) == null ? void 0 : _t.arguments) != null ? _u : "";
|
|
1034
1128
|
}
|
|
1035
1129
|
controller.enqueue({
|
|
1036
1130
|
type: "tool-input-delta",
|
|
1037
1131
|
id: toolCall.id,
|
|
1038
|
-
delta: (
|
|
1132
|
+
delta: (_v = toolCallDelta.function.arguments) != null ? _v : ""
|
|
1039
1133
|
});
|
|
1040
|
-
if (((
|
|
1134
|
+
if (((_w = toolCall.function) == null ? void 0 : _w.name) != null && ((_x = toolCall.function) == null ? void 0 : _x.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
1041
1135
|
controller.enqueue({
|
|
1042
1136
|
type: "tool-input-end",
|
|
1043
1137
|
id: toolCall.id
|
|
1044
1138
|
});
|
|
1045
1139
|
controller.enqueue({
|
|
1046
1140
|
type: "tool-call",
|
|
1047
|
-
toolCallId: (
|
|
1141
|
+
toolCallId: (_y = toolCall.id) != null ? _y : generateId(),
|
|
1048
1142
|
toolName: toolCall.function.name,
|
|
1049
1143
|
input: toolCall.function.arguments
|
|
1050
1144
|
});
|
|
@@ -2267,6 +2361,10 @@ import {
|
|
|
2267
2361
|
validateTypes
|
|
2268
2362
|
} from "@ai-sdk/provider-utils";
|
|
2269
2363
|
import { z as z16 } from "zod/v4";
|
|
2364
|
+
function getPromptCacheBreakpoint2(providerOptions) {
|
|
2365
|
+
var _a;
|
|
2366
|
+
return (_a = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a.promptCacheBreakpoint;
|
|
2367
|
+
}
|
|
2270
2368
|
function isFileId(data, prefixes) {
|
|
2271
2369
|
if (!prefixes) return false;
|
|
2272
2370
|
return prefixes.some((prefix) => data.startsWith(prefix));
|
|
@@ -2281,16 +2379,36 @@ async function convertToOpenAIResponsesInput({
|
|
|
2281
2379
|
var _a, _b, _c, _d, _e, _f;
|
|
2282
2380
|
let input = [];
|
|
2283
2381
|
const warnings = [];
|
|
2284
|
-
for (const { role, content } of prompt) {
|
|
2382
|
+
for (const { role, content, providerOptions } of prompt) {
|
|
2285
2383
|
switch (role) {
|
|
2286
2384
|
case "system": {
|
|
2287
2385
|
switch (systemMessageMode) {
|
|
2288
2386
|
case "system": {
|
|
2289
|
-
|
|
2387
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
|
|
2388
|
+
input.push({
|
|
2389
|
+
role: "system",
|
|
2390
|
+
content: promptCacheBreakpoint == null ? content : [
|
|
2391
|
+
{
|
|
2392
|
+
type: "input_text",
|
|
2393
|
+
text: content,
|
|
2394
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2395
|
+
}
|
|
2396
|
+
]
|
|
2397
|
+
});
|
|
2290
2398
|
break;
|
|
2291
2399
|
}
|
|
2292
2400
|
case "developer": {
|
|
2293
|
-
|
|
2401
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
|
|
2402
|
+
input.push({
|
|
2403
|
+
role: "developer",
|
|
2404
|
+
content: promptCacheBreakpoint == null ? content : [
|
|
2405
|
+
{
|
|
2406
|
+
type: "input_text",
|
|
2407
|
+
text: content,
|
|
2408
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2409
|
+
}
|
|
2410
|
+
]
|
|
2411
|
+
});
|
|
2294
2412
|
break;
|
|
2295
2413
|
}
|
|
2296
2414
|
case "remove": {
|
|
@@ -2316,9 +2434,21 @@ async function convertToOpenAIResponsesInput({
|
|
|
2316
2434
|
var _a2, _b2, _c2;
|
|
2317
2435
|
switch (part.type) {
|
|
2318
2436
|
case "text": {
|
|
2319
|
-
|
|
2437
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
2438
|
+
part.providerOptions
|
|
2439
|
+
);
|
|
2440
|
+
return {
|
|
2441
|
+
type: "input_text",
|
|
2442
|
+
text: part.text,
|
|
2443
|
+
...promptCacheBreakpoint != null && {
|
|
2444
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2445
|
+
}
|
|
2446
|
+
};
|
|
2320
2447
|
}
|
|
2321
2448
|
case "file": {
|
|
2449
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
2450
|
+
part.providerOptions
|
|
2451
|
+
);
|
|
2322
2452
|
if (part.mediaType.startsWith("image/")) {
|
|
2323
2453
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
2324
2454
|
return {
|
|
@@ -2326,13 +2456,19 @@ async function convertToOpenAIResponsesInput({
|
|
|
2326
2456
|
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
2327
2457
|
image_url: `data:${mediaType};base64,${convertToBase642(part.data)}`
|
|
2328
2458
|
},
|
|
2329
|
-
detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
|
|
2459
|
+
detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail,
|
|
2460
|
+
...promptCacheBreakpoint != null && {
|
|
2461
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2462
|
+
}
|
|
2330
2463
|
};
|
|
2331
2464
|
} else if (part.mediaType === "application/pdf") {
|
|
2332
2465
|
if (part.data instanceof URL) {
|
|
2333
2466
|
return {
|
|
2334
2467
|
type: "input_file",
|
|
2335
|
-
file_url: part.data.toString()
|
|
2468
|
+
file_url: part.data.toString(),
|
|
2469
|
+
...promptCacheBreakpoint != null && {
|
|
2470
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2471
|
+
}
|
|
2336
2472
|
};
|
|
2337
2473
|
}
|
|
2338
2474
|
return {
|
|
@@ -2340,6 +2476,9 @@ async function convertToOpenAIResponsesInput({
|
|
|
2340
2476
|
...typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
2341
2477
|
filename: (_c2 = part.filename) != null ? _c2 : `part-${index}.pdf`,
|
|
2342
2478
|
file_data: `data:application/pdf;base64,${convertToBase642(part.data)}`
|
|
2479
|
+
},
|
|
2480
|
+
...promptCacheBreakpoint != null && {
|
|
2481
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2343
2482
|
}
|
|
2344
2483
|
};
|
|
2345
2484
|
} else {
|
|
@@ -2425,12 +2564,12 @@ async function convertToOpenAIResponsesInput({
|
|
|
2425
2564
|
break;
|
|
2426
2565
|
}
|
|
2427
2566
|
case "reasoning": {
|
|
2428
|
-
const
|
|
2567
|
+
const providerOptions2 = await parseProviderOptions5({
|
|
2429
2568
|
provider: "openai",
|
|
2430
2569
|
providerOptions: part.providerOptions,
|
|
2431
2570
|
schema: openaiResponsesReasoningProviderOptionsSchema
|
|
2432
2571
|
});
|
|
2433
|
-
const reasoningId =
|
|
2572
|
+
const reasoningId = providerOptions2 == null ? void 0 : providerOptions2.itemId;
|
|
2434
2573
|
if (reasoningId != null) {
|
|
2435
2574
|
const reasoningMessage = reasoningMessages[reasoningId];
|
|
2436
2575
|
if (store) {
|
|
@@ -2459,14 +2598,14 @@ async function convertToOpenAIResponsesInput({
|
|
|
2459
2598
|
reasoningMessages[reasoningId] = {
|
|
2460
2599
|
type: "reasoning",
|
|
2461
2600
|
id: reasoningId,
|
|
2462
|
-
encrypted_content:
|
|
2601
|
+
encrypted_content: providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent,
|
|
2463
2602
|
summary: summaryParts
|
|
2464
2603
|
};
|
|
2465
2604
|
input.push(reasoningMessages[reasoningId]);
|
|
2466
2605
|
} else {
|
|
2467
2606
|
reasoningMessage.summary.push(...summaryParts);
|
|
2468
|
-
if ((
|
|
2469
|
-
reasoningMessage.encrypted_content =
|
|
2607
|
+
if ((providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent) != null) {
|
|
2608
|
+
reasoningMessage.encrypted_content = providerOptions2.reasoningEncryptedContent;
|
|
2470
2609
|
}
|
|
2471
2610
|
}
|
|
2472
2611
|
}
|
|
@@ -2485,6 +2624,9 @@ async function convertToOpenAIResponsesInput({
|
|
|
2485
2624
|
case "tool": {
|
|
2486
2625
|
for (const part of content) {
|
|
2487
2626
|
const output = part.output;
|
|
2627
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
2628
|
+
part.providerOptions
|
|
2629
|
+
);
|
|
2488
2630
|
if (hasLocalShellTool && part.toolName === "local_shell" && output.type === "json") {
|
|
2489
2631
|
const parsedOutput = await validateTypes({
|
|
2490
2632
|
value: output.value,
|
|
@@ -2501,26 +2643,51 @@ async function convertToOpenAIResponsesInput({
|
|
|
2501
2643
|
switch (output.type) {
|
|
2502
2644
|
case "text":
|
|
2503
2645
|
case "error-text":
|
|
2504
|
-
contentValue = output.value
|
|
2646
|
+
contentValue = promptCacheBreakpoint == null ? output.value : [
|
|
2647
|
+
{
|
|
2648
|
+
type: "input_text",
|
|
2649
|
+
text: output.value,
|
|
2650
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2651
|
+
}
|
|
2652
|
+
];
|
|
2505
2653
|
break;
|
|
2506
2654
|
case "json":
|
|
2507
2655
|
case "error-json":
|
|
2508
|
-
contentValue = JSON.stringify(output.value)
|
|
2656
|
+
contentValue = promptCacheBreakpoint == null ? JSON.stringify(output.value) : [
|
|
2657
|
+
{
|
|
2658
|
+
type: "input_text",
|
|
2659
|
+
text: JSON.stringify(output.value),
|
|
2660
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2661
|
+
}
|
|
2662
|
+
];
|
|
2509
2663
|
break;
|
|
2510
2664
|
case "content":
|
|
2511
|
-
contentValue = output.value.map((item) => {
|
|
2665
|
+
contentValue = output.value.map((item, index) => {
|
|
2666
|
+
const isBreakpoint = promptCacheBreakpoint != null && index === output.value.length - 1;
|
|
2512
2667
|
switch (item.type) {
|
|
2513
2668
|
case "text": {
|
|
2514
|
-
return {
|
|
2669
|
+
return {
|
|
2670
|
+
type: "input_text",
|
|
2671
|
+
text: item.text,
|
|
2672
|
+
...isBreakpoint && {
|
|
2673
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2674
|
+
}
|
|
2675
|
+
};
|
|
2515
2676
|
}
|
|
2516
2677
|
case "media": {
|
|
2517
2678
|
return item.mediaType.startsWith("image/") ? {
|
|
2518
2679
|
type: "input_image",
|
|
2519
|
-
image_url: `data:${item.mediaType};base64,${item.data}
|
|
2680
|
+
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
2681
|
+
...isBreakpoint && {
|
|
2682
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2683
|
+
}
|
|
2520
2684
|
} : {
|
|
2521
2685
|
type: "input_file",
|
|
2522
2686
|
filename: "data",
|
|
2523
|
-
file_data: `data:${item.mediaType};base64,${item.data}
|
|
2687
|
+
file_data: `data:${item.mediaType};base64,${item.data}`,
|
|
2688
|
+
...isBreakpoint && {
|
|
2689
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2690
|
+
}
|
|
2524
2691
|
};
|
|
2525
2692
|
}
|
|
2526
2693
|
}
|
|
@@ -2611,6 +2778,7 @@ var openaiResponsesChunkSchema = lazyValidator9(
|
|
|
2611
2778
|
input_tokens: z17.number(),
|
|
2612
2779
|
input_tokens_details: z17.object({
|
|
2613
2780
|
cached_tokens: z17.number().nullish(),
|
|
2781
|
+
cache_write_tokens: z17.number().nullish(),
|
|
2614
2782
|
orchestration_input_tokens: z17.number().nullish(),
|
|
2615
2783
|
orchestration_input_cached_tokens: z17.number().nullish()
|
|
2616
2784
|
}).nullish(),
|
|
@@ -2620,6 +2788,9 @@ var openaiResponsesChunkSchema = lazyValidator9(
|
|
|
2620
2788
|
orchestration_output_tokens: z17.number().nullish()
|
|
2621
2789
|
}).nullish()
|
|
2622
2790
|
}),
|
|
2791
|
+
reasoning: z17.object({
|
|
2792
|
+
context: z17.string().nullish()
|
|
2793
|
+
}).nullish(),
|
|
2623
2794
|
service_tier: z17.string().nullish()
|
|
2624
2795
|
})
|
|
2625
2796
|
}),
|
|
@@ -3038,11 +3209,15 @@ var openaiResponsesResponseSchema = lazyValidator9(
|
|
|
3038
3209
|
])
|
|
3039
3210
|
).optional(),
|
|
3040
3211
|
service_tier: z17.string().nullish(),
|
|
3212
|
+
reasoning: z17.object({
|
|
3213
|
+
context: z17.string().nullish()
|
|
3214
|
+
}).nullish(),
|
|
3041
3215
|
incomplete_details: z17.object({ reason: z17.string() }).nullish(),
|
|
3042
3216
|
usage: z17.object({
|
|
3043
3217
|
input_tokens: z17.number(),
|
|
3044
3218
|
input_tokens_details: z17.object({
|
|
3045
3219
|
cached_tokens: z17.number().nullish(),
|
|
3220
|
+
cache_write_tokens: z17.number().nullish(),
|
|
3046
3221
|
orchestration_input_tokens: z17.number().nullish(),
|
|
3047
3222
|
orchestration_input_cached_tokens: z17.number().nullish()
|
|
3048
3223
|
}).nullish(),
|
|
@@ -3105,7 +3280,11 @@ var openaiResponsesReasoningModelIds = [
|
|
|
3105
3280
|
"gpt-5.4-nano",
|
|
3106
3281
|
"gpt-5.4-nano-2026-03-17",
|
|
3107
3282
|
"gpt-5.4-pro",
|
|
3108
|
-
"gpt-5.4-pro-2026-03-05"
|
|
3283
|
+
"gpt-5.4-pro-2026-03-05",
|
|
3284
|
+
"gpt-5.6",
|
|
3285
|
+
"gpt-5.6-luna",
|
|
3286
|
+
"gpt-5.6-sol",
|
|
3287
|
+
"gpt-5.6-terra"
|
|
3109
3288
|
];
|
|
3110
3289
|
var openaiResponsesModelIds = [
|
|
3111
3290
|
"gpt-4.1",
|
|
@@ -3179,11 +3358,22 @@ var openaiResponsesProviderOptionsSchema = lazyValidator10(
|
|
|
3179
3358
|
parallelToolCalls: z18.boolean().nullish(),
|
|
3180
3359
|
previousResponseId: z18.string().nullish(),
|
|
3181
3360
|
promptCacheKey: z18.string().nullish(),
|
|
3361
|
+
/**
|
|
3362
|
+
* Prompt cache behavior for GPT-5.6 and later models.
|
|
3363
|
+
* `mode` controls whether OpenAI also places an implicit breakpoint.
|
|
3364
|
+
* `ttl` sets the minimum cache lifetime and currently only supports 30 minutes.
|
|
3365
|
+
*/
|
|
3366
|
+
promptCacheOptions: z18.object({
|
|
3367
|
+
mode: z18.enum(["implicit", "explicit"]).optional(),
|
|
3368
|
+
ttl: z18.literal("30m").optional()
|
|
3369
|
+
}).optional(),
|
|
3182
3370
|
/**
|
|
3183
3371
|
* The retention policy for the prompt cache.
|
|
3184
3372
|
* - 'in_memory': Default. Standard prompt caching behavior.
|
|
3185
3373
|
* - '24h': Extended prompt caching that keeps cached prefixes active for up to 24 hours.
|
|
3186
|
-
*
|
|
3374
|
+
* Available for models before GPT-5.6 that support extended caching.
|
|
3375
|
+
*
|
|
3376
|
+
* @deprecated For GPT-5.6 and later models, use `promptCacheOptions.ttl`.
|
|
3187
3377
|
*
|
|
3188
3378
|
* @default 'in_memory'
|
|
3189
3379
|
*/
|
|
@@ -3191,14 +3381,21 @@ var openaiResponsesProviderOptionsSchema = lazyValidator10(
|
|
|
3191
3381
|
/**
|
|
3192
3382
|
* Reasoning effort for reasoning models. Defaults to `medium`. If you use
|
|
3193
3383
|
* `providerOptions` to set the `reasoningEffort` option, this model setting will be ignored.
|
|
3194
|
-
*
|
|
3195
|
-
*
|
|
3196
|
-
* The 'none' type for `reasoningEffort` is only available for OpenAI's GPT-5.1
|
|
3197
|
-
* models. Also, the 'xhigh' type for `reasoningEffort` is only available for
|
|
3198
|
-
* OpenAI's GPT-5.1-Codex-Max model. Setting `reasoningEffort` to 'none' or 'xhigh' with unsupported models will result in
|
|
3199
|
-
* an error.
|
|
3384
|
+
* GPT-5.6 supports 'none' | 'low' | 'medium' | 'high' | 'xhigh' | 'max'.
|
|
3385
|
+
* Supported values vary by model.
|
|
3200
3386
|
*/
|
|
3201
3387
|
reasoningEffort: z18.string().nullish(),
|
|
3388
|
+
/**
|
|
3389
|
+
* Controls how much model work GPT-5.6 performs before returning a final answer.
|
|
3390
|
+
* `standard` is the default. `pro` increases quality, latency, and token usage.
|
|
3391
|
+
*/
|
|
3392
|
+
reasoningMode: z18.enum(["standard", "pro"]).optional(),
|
|
3393
|
+
/**
|
|
3394
|
+
* Controls which available reasoning items GPT-5.6 can use.
|
|
3395
|
+
* `auto` uses the model default, `current_turn` excludes reasoning from earlier
|
|
3396
|
+
* turns, and `all_turns` makes compatible earlier reasoning available.
|
|
3397
|
+
*/
|
|
3398
|
+
reasoningContext: z18.enum(["auto", "current_turn", "all_turns"]).optional(),
|
|
3202
3399
|
reasoningSummary: z18.string().nullish(),
|
|
3203
3400
|
safetyIdentifier: z18.string().nullish(),
|
|
3204
3401
|
serviceTier: z18.enum(["auto", "flex", "priority", "default"]).nullish(),
|
|
@@ -3492,18 +3689,25 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3492
3689
|
service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
|
|
3493
3690
|
include,
|
|
3494
3691
|
prompt_cache_key: openaiOptions == null ? void 0 : openaiOptions.promptCacheKey,
|
|
3692
|
+
prompt_cache_options: openaiOptions == null ? void 0 : openaiOptions.promptCacheOptions,
|
|
3495
3693
|
prompt_cache_retention: openaiOptions == null ? void 0 : openaiOptions.promptCacheRetention,
|
|
3496
3694
|
safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
|
|
3497
3695
|
top_logprobs: topLogprobs,
|
|
3498
3696
|
truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
|
|
3499
3697
|
// model-specific settings:
|
|
3500
|
-
...modelCapabilities.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
|
|
3698
|
+
...modelCapabilities.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null) && {
|
|
3501
3699
|
reasoning: {
|
|
3502
3700
|
...(openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && {
|
|
3503
3701
|
effort: openaiOptions.reasoningEffort
|
|
3504
3702
|
},
|
|
3505
3703
|
...(openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null && {
|
|
3506
3704
|
summary: openaiOptions.reasoningSummary
|
|
3705
|
+
},
|
|
3706
|
+
...(openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null && {
|
|
3707
|
+
mode: openaiOptions.reasoningMode
|
|
3708
|
+
},
|
|
3709
|
+
...(openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null && {
|
|
3710
|
+
context: openaiOptions.reasoningContext
|
|
3507
3711
|
}
|
|
3508
3712
|
}
|
|
3509
3713
|
}
|
|
@@ -3542,6 +3746,20 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3542
3746
|
details: "reasoningSummary is not supported for non-reasoning models"
|
|
3543
3747
|
});
|
|
3544
3748
|
}
|
|
3749
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null) {
|
|
3750
|
+
warnings.push({
|
|
3751
|
+
type: "unsupported-setting",
|
|
3752
|
+
setting: "reasoningMode",
|
|
3753
|
+
details: "reasoningMode is not supported for non-reasoning models"
|
|
3754
|
+
});
|
|
3755
|
+
}
|
|
3756
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null) {
|
|
3757
|
+
warnings.push({
|
|
3758
|
+
type: "unsupported-setting",
|
|
3759
|
+
setting: "reasoningContext",
|
|
3760
|
+
details: "reasoningContext is not supported for non-reasoning models"
|
|
3761
|
+
});
|
|
3762
|
+
}
|
|
3545
3763
|
}
|
|
3546
3764
|
if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !modelCapabilities.supportsFlexProcessing) {
|
|
3547
3765
|
warnings.push({
|
|
@@ -3580,7 +3798,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3580
3798
|
};
|
|
3581
3799
|
}
|
|
3582
3800
|
async doGenerate(options) {
|
|
3583
|
-
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;
|
|
3801
|
+
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;
|
|
3584
3802
|
const {
|
|
3585
3803
|
args: body,
|
|
3586
3804
|
warnings,
|
|
@@ -3864,23 +4082,26 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3864
4082
|
if (typeof response.service_tier === "string") {
|
|
3865
4083
|
providerMetadata[providerKey].serviceTier = response.service_tier;
|
|
3866
4084
|
}
|
|
4085
|
+
if (((_x = response.reasoning) == null ? void 0 : _x.context) != null) {
|
|
4086
|
+
providerMetadata[providerKey].reasoningContext = response.reasoning.context;
|
|
4087
|
+
}
|
|
3867
4088
|
const usage = response.usage;
|
|
3868
|
-
const
|
|
3869
|
-
if (
|
|
3870
|
-
providerMetadata[providerKey].usage =
|
|
4089
|
+
const responsesUsage = getResponsesUsageMetadata(usage);
|
|
4090
|
+
if (responsesUsage != null) {
|
|
4091
|
+
providerMetadata[providerKey].usage = responsesUsage;
|
|
3871
4092
|
}
|
|
3872
4093
|
return {
|
|
3873
4094
|
content,
|
|
3874
4095
|
finishReason: mapOpenAIResponseFinishReason({
|
|
3875
|
-
finishReason: (
|
|
4096
|
+
finishReason: (_y = response.incomplete_details) == null ? void 0 : _y.reason,
|
|
3876
4097
|
hasFunctionCall
|
|
3877
4098
|
}),
|
|
3878
4099
|
usage: {
|
|
3879
4100
|
inputTokens: usage.input_tokens,
|
|
3880
4101
|
outputTokens: usage.output_tokens,
|
|
3881
4102
|
totalTokens: usage.input_tokens + usage.output_tokens,
|
|
3882
|
-
reasoningTokens: (
|
|
3883
|
-
cachedInputTokens: (
|
|
4103
|
+
reasoningTokens: (_A = (_z = usage.output_tokens_details) == null ? void 0 : _z.reasoning_tokens) != null ? _A : void 0,
|
|
4104
|
+
cachedInputTokens: (_C = (_B = usage.input_tokens_details) == null ? void 0 : _B.cached_tokens) != null ? _C : void 0
|
|
3884
4105
|
},
|
|
3885
4106
|
request: { body },
|
|
3886
4107
|
response: {
|
|
@@ -3934,7 +4155,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3934
4155
|
let hasFunctionCall = false;
|
|
3935
4156
|
const activeReasoning = {};
|
|
3936
4157
|
let serviceTier;
|
|
3937
|
-
let
|
|
4158
|
+
let reasoningContext;
|
|
4159
|
+
let responsesUsage;
|
|
3938
4160
|
return {
|
|
3939
4161
|
stream: response.pipeThrough(
|
|
3940
4162
|
new TransformStream({
|
|
@@ -3942,7 +4164,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3942
4164
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3943
4165
|
},
|
|
3944
4166
|
transform(chunk, controller) {
|
|
3945
|
-
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;
|
|
4167
|
+
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;
|
|
3946
4168
|
if (options.includeRawChunks) {
|
|
3947
4169
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3948
4170
|
}
|
|
@@ -4335,16 +4557,17 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4335
4557
|
if (typeof value.response.service_tier === "string") {
|
|
4336
4558
|
serviceTier = value.response.service_tier;
|
|
4337
4559
|
}
|
|
4338
|
-
|
|
4339
|
-
value.response.
|
|
4340
|
-
|
|
4560
|
+
if (((_p = value.response.reasoning) == null ? void 0 : _p.context) != null) {
|
|
4561
|
+
reasoningContext = value.response.reasoning.context;
|
|
4562
|
+
}
|
|
4563
|
+
responsesUsage = getResponsesUsageMetadata(value.response.usage);
|
|
4341
4564
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
4342
4565
|
ongoingAnnotations.push(value.annotation);
|
|
4343
4566
|
if (value.annotation.type === "url_citation") {
|
|
4344
4567
|
controller.enqueue({
|
|
4345
4568
|
type: "source",
|
|
4346
4569
|
sourceType: "url",
|
|
4347
|
-
id: (
|
|
4570
|
+
id: (_s = (_r = (_q = self.config).generateId) == null ? void 0 : _r.call(_q)) != null ? _s : generateId2(),
|
|
4348
4571
|
url: value.annotation.url,
|
|
4349
4572
|
title: value.annotation.title
|
|
4350
4573
|
});
|
|
@@ -4352,10 +4575,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4352
4575
|
controller.enqueue({
|
|
4353
4576
|
type: "source",
|
|
4354
4577
|
sourceType: "document",
|
|
4355
|
-
id: (
|
|
4578
|
+
id: (_v = (_u = (_t = self.config).generateId) == null ? void 0 : _u.call(_t)) != null ? _v : generateId2(),
|
|
4356
4579
|
mediaType: "text/plain",
|
|
4357
|
-
title: (
|
|
4358
|
-
filename: (
|
|
4580
|
+
title: (_x = (_w = value.annotation.quote) != null ? _w : value.annotation.filename) != null ? _x : "Document",
|
|
4581
|
+
filename: (_y = value.annotation.filename) != null ? _y : value.annotation.file_id,
|
|
4359
4582
|
...value.annotation.file_id ? {
|
|
4360
4583
|
providerMetadata: {
|
|
4361
4584
|
[providerKey]: {
|
|
@@ -4381,8 +4604,11 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4381
4604
|
if (serviceTier !== void 0) {
|
|
4382
4605
|
providerMetadata[providerKey].serviceTier = serviceTier;
|
|
4383
4606
|
}
|
|
4384
|
-
if (
|
|
4385
|
-
providerMetadata[providerKey].
|
|
4607
|
+
if (reasoningContext !== void 0) {
|
|
4608
|
+
providerMetadata[providerKey].reasoningContext = reasoningContext;
|
|
4609
|
+
}
|
|
4610
|
+
if (responsesUsage != null) {
|
|
4611
|
+
providerMetadata[providerKey].usage = responsesUsage;
|
|
4386
4612
|
}
|
|
4387
4613
|
controller.enqueue({
|
|
4388
4614
|
type: "finish",
|
|
@@ -4452,15 +4678,17 @@ function mapWebSearchOutput(action) {
|
|
|
4452
4678
|
};
|
|
4453
4679
|
}
|
|
4454
4680
|
}
|
|
4455
|
-
function
|
|
4456
|
-
var _a, _b, _c;
|
|
4457
|
-
const
|
|
4458
|
-
const
|
|
4459
|
-
const
|
|
4460
|
-
|
|
4681
|
+
function getResponsesUsageMetadata(usage) {
|
|
4682
|
+
var _a, _b, _c, _d;
|
|
4683
|
+
const cacheWriteTokens = (_a = usage == null ? void 0 : usage.input_tokens_details) == null ? void 0 : _a.cache_write_tokens;
|
|
4684
|
+
const orchestrationInputTokens = (_b = usage == null ? void 0 : usage.input_tokens_details) == null ? void 0 : _b.orchestration_input_tokens;
|
|
4685
|
+
const orchestrationInputCachedTokens = (_c = usage == null ? void 0 : usage.input_tokens_details) == null ? void 0 : _c.orchestration_input_cached_tokens;
|
|
4686
|
+
const orchestrationOutputTokens = (_d = usage == null ? void 0 : usage.output_tokens_details) == null ? void 0 : _d.orchestration_output_tokens;
|
|
4687
|
+
if (cacheWriteTokens == null && orchestrationInputTokens == null && orchestrationInputCachedTokens == null && orchestrationOutputTokens == null) {
|
|
4461
4688
|
return void 0;
|
|
4462
4689
|
}
|
|
4463
4690
|
return {
|
|
4691
|
+
...cacheWriteTokens != null && { cacheWriteTokens },
|
|
4464
4692
|
...orchestrationInputTokens != null && { orchestrationInputTokens },
|
|
4465
4693
|
...orchestrationInputCachedTokens != null && {
|
|
4466
4694
|
orchestrationInputCachedTokens
|
|
@@ -4840,7 +5068,7 @@ var OpenAITranscriptionModel = class {
|
|
|
4840
5068
|
};
|
|
4841
5069
|
|
|
4842
5070
|
// src/version.ts
|
|
4843
|
-
var VERSION = true ? "2.0.
|
|
5071
|
+
var VERSION = true ? "2.0.111" : "0.0.0-test";
|
|
4844
5072
|
|
|
4845
5073
|
// src/openai-provider.ts
|
|
4846
5074
|
function createOpenAI(options = {}) {
|