@ai-sdk/openai 2.0.109 → 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 +14 -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 +3 -3
package/dist/index.js
CHANGED
|
@@ -57,7 +57,7 @@ function getOpenAILanguageModelCapabilities(modelId) {
|
|
|
57
57
|
const supportsFlexProcessing = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
58
58
|
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");
|
|
59
59
|
const isReasoningModel = !(modelId.startsWith("gpt-3") || modelId.startsWith("gpt-4") || modelId.startsWith("chatgpt-4o") || modelId.startsWith("gpt-5-chat"));
|
|
60
|
-
const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1") || modelId.startsWith("gpt-5.2") || modelId.startsWith("gpt-5.3") || modelId.startsWith("gpt-5.4");
|
|
60
|
+
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");
|
|
61
61
|
const systemMessageMode = isReasoningModel ? "developer" : "system";
|
|
62
62
|
return {
|
|
63
63
|
supportsFlexProcessing,
|
|
@@ -71,22 +71,46 @@ function getOpenAILanguageModelCapabilities(modelId) {
|
|
|
71
71
|
// src/chat/convert-to-openai-chat-messages.ts
|
|
72
72
|
var import_provider = require("@ai-sdk/provider");
|
|
73
73
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
74
|
+
function getPromptCacheBreakpoint(providerOptions) {
|
|
75
|
+
var _a;
|
|
76
|
+
return (_a = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a.promptCacheBreakpoint;
|
|
77
|
+
}
|
|
74
78
|
function convertToOpenAIChatMessages({
|
|
75
79
|
prompt,
|
|
76
80
|
systemMessageMode = "system"
|
|
77
81
|
}) {
|
|
78
82
|
const messages = [];
|
|
79
83
|
const warnings = [];
|
|
80
|
-
for (const { role, content } of prompt) {
|
|
84
|
+
for (const { role, content, providerOptions } of prompt) {
|
|
81
85
|
switch (role) {
|
|
82
86
|
case "system": {
|
|
83
87
|
switch (systemMessageMode) {
|
|
84
88
|
case "system": {
|
|
85
|
-
|
|
89
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint(providerOptions);
|
|
90
|
+
messages.push({
|
|
91
|
+
role: "system",
|
|
92
|
+
content: promptCacheBreakpoint == null ? content : [
|
|
93
|
+
{
|
|
94
|
+
type: "text",
|
|
95
|
+
text: content,
|
|
96
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
});
|
|
86
100
|
break;
|
|
87
101
|
}
|
|
88
102
|
case "developer": {
|
|
89
|
-
|
|
103
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint(providerOptions);
|
|
104
|
+
messages.push({
|
|
105
|
+
role: "developer",
|
|
106
|
+
content: promptCacheBreakpoint == null ? content : [
|
|
107
|
+
{
|
|
108
|
+
type: "text",
|
|
109
|
+
text: content,
|
|
110
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
});
|
|
90
114
|
break;
|
|
91
115
|
}
|
|
92
116
|
case "remove": {
|
|
@@ -106,7 +130,7 @@ function convertToOpenAIChatMessages({
|
|
|
106
130
|
break;
|
|
107
131
|
}
|
|
108
132
|
case "user": {
|
|
109
|
-
if (content.length === 1 && content[0].type === "text") {
|
|
133
|
+
if (content.length === 1 && content[0].type === "text" && getPromptCacheBreakpoint(content[0].providerOptions) == null) {
|
|
110
134
|
messages.push({ role: "user", content: content[0].text });
|
|
111
135
|
break;
|
|
112
136
|
}
|
|
@@ -116,9 +140,21 @@ function convertToOpenAIChatMessages({
|
|
|
116
140
|
var _a, _b, _c;
|
|
117
141
|
switch (part.type) {
|
|
118
142
|
case "text": {
|
|
119
|
-
|
|
143
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint(
|
|
144
|
+
part.providerOptions
|
|
145
|
+
);
|
|
146
|
+
return {
|
|
147
|
+
type: "text",
|
|
148
|
+
text: part.text,
|
|
149
|
+
...promptCacheBreakpoint != null && {
|
|
150
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
151
|
+
}
|
|
152
|
+
};
|
|
120
153
|
}
|
|
121
154
|
case "file": {
|
|
155
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint(
|
|
156
|
+
part.providerOptions
|
|
157
|
+
);
|
|
122
158
|
if (part.mediaType.startsWith("image/")) {
|
|
123
159
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
124
160
|
return {
|
|
@@ -127,6 +163,9 @@ function convertToOpenAIChatMessages({
|
|
|
127
163
|
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils2.convertToBase64)(part.data)}`,
|
|
128
164
|
// OpenAI specific extension: image detail
|
|
129
165
|
detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
|
|
166
|
+
},
|
|
167
|
+
...promptCacheBreakpoint != null && {
|
|
168
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
130
169
|
}
|
|
131
170
|
};
|
|
132
171
|
} else if (part.mediaType.startsWith("audio/")) {
|
|
@@ -142,6 +181,9 @@ function convertToOpenAIChatMessages({
|
|
|
142
181
|
input_audio: {
|
|
143
182
|
data: (0, import_provider_utils2.convertToBase64)(part.data),
|
|
144
183
|
format: "wav"
|
|
184
|
+
},
|
|
185
|
+
...promptCacheBreakpoint != null && {
|
|
186
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
145
187
|
}
|
|
146
188
|
};
|
|
147
189
|
}
|
|
@@ -152,6 +194,9 @@ function convertToOpenAIChatMessages({
|
|
|
152
194
|
input_audio: {
|
|
153
195
|
data: (0, import_provider_utils2.convertToBase64)(part.data),
|
|
154
196
|
format: "mp3"
|
|
197
|
+
},
|
|
198
|
+
...promptCacheBreakpoint != null && {
|
|
199
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
155
200
|
}
|
|
156
201
|
};
|
|
157
202
|
}
|
|
@@ -172,6 +217,9 @@ function convertToOpenAIChatMessages({
|
|
|
172
217
|
file: typeof part.data === "string" && part.data.startsWith("file-") ? { file_id: part.data } : {
|
|
173
218
|
filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
|
|
174
219
|
file_data: `data:application/pdf;base64,${(0, import_provider_utils2.convertToBase64)(part.data)}`
|
|
220
|
+
},
|
|
221
|
+
...promptCacheBreakpoint != null && {
|
|
222
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
175
223
|
}
|
|
176
224
|
};
|
|
177
225
|
} else {
|
|
@@ -187,11 +235,24 @@ function convertToOpenAIChatMessages({
|
|
|
187
235
|
}
|
|
188
236
|
case "assistant": {
|
|
189
237
|
let text = "";
|
|
238
|
+
const textParts = [];
|
|
239
|
+
let hasPromptCacheBreakpoint = false;
|
|
190
240
|
const toolCalls = [];
|
|
191
241
|
for (const part of content) {
|
|
192
242
|
switch (part.type) {
|
|
193
243
|
case "text": {
|
|
244
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint(
|
|
245
|
+
part.providerOptions
|
|
246
|
+
);
|
|
194
247
|
text += part.text;
|
|
248
|
+
textParts.push({
|
|
249
|
+
type: "text",
|
|
250
|
+
text: part.text,
|
|
251
|
+
...promptCacheBreakpoint != null && {
|
|
252
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
hasPromptCacheBreakpoint || (hasPromptCacheBreakpoint = promptCacheBreakpoint != null);
|
|
195
256
|
break;
|
|
196
257
|
}
|
|
197
258
|
case "tool-call": {
|
|
@@ -209,7 +270,7 @@ function convertToOpenAIChatMessages({
|
|
|
209
270
|
}
|
|
210
271
|
messages.push({
|
|
211
272
|
role: "assistant",
|
|
212
|
-
content: text,
|
|
273
|
+
content: hasPromptCacheBreakpoint ? textParts : text,
|
|
213
274
|
tool_calls: toolCalls.length > 0 ? toolCalls : void 0
|
|
214
275
|
});
|
|
215
276
|
break;
|
|
@@ -217,6 +278,9 @@ function convertToOpenAIChatMessages({
|
|
|
217
278
|
case "tool": {
|
|
218
279
|
for (const toolResponse of content) {
|
|
219
280
|
const output = toolResponse.output;
|
|
281
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint(
|
|
282
|
+
toolResponse.providerOptions
|
|
283
|
+
);
|
|
220
284
|
let contentValue;
|
|
221
285
|
switch (output.type) {
|
|
222
286
|
case "text":
|
|
@@ -232,7 +296,13 @@ function convertToOpenAIChatMessages({
|
|
|
232
296
|
messages.push({
|
|
233
297
|
role: "tool",
|
|
234
298
|
tool_call_id: toolResponse.toolCallId,
|
|
235
|
-
content: contentValue
|
|
299
|
+
content: promptCacheBreakpoint == null ? contentValue : [
|
|
300
|
+
{
|
|
301
|
+
type: "text",
|
|
302
|
+
text: contentValue,
|
|
303
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
304
|
+
}
|
|
305
|
+
]
|
|
236
306
|
});
|
|
237
307
|
}
|
|
238
308
|
break;
|
|
@@ -335,7 +405,8 @@ var openaiChatResponseSchema = (0, import_provider_utils3.lazyValidator)(
|
|
|
335
405
|
completion_tokens: import_v42.z.number().nullish(),
|
|
336
406
|
total_tokens: import_v42.z.number().nullish(),
|
|
337
407
|
prompt_tokens_details: import_v42.z.object({
|
|
338
|
-
cached_tokens: import_v42.z.number().nullish()
|
|
408
|
+
cached_tokens: import_v42.z.number().nullish(),
|
|
409
|
+
cache_write_tokens: import_v42.z.number().nullish()
|
|
339
410
|
}).nullish(),
|
|
340
411
|
completion_tokens_details: import_v42.z.object({
|
|
341
412
|
reasoning_tokens: import_v42.z.number().nullish(),
|
|
@@ -404,7 +475,8 @@ var openaiChatChunkSchema = (0, import_provider_utils3.lazyValidator)(
|
|
|
404
475
|
completion_tokens: import_v42.z.number().nullish(),
|
|
405
476
|
total_tokens: import_v42.z.number().nullish(),
|
|
406
477
|
prompt_tokens_details: import_v42.z.object({
|
|
407
|
-
cached_tokens: import_v42.z.number().nullish()
|
|
478
|
+
cached_tokens: import_v42.z.number().nullish(),
|
|
479
|
+
cache_write_tokens: import_v42.z.number().nullish()
|
|
408
480
|
}).nullish(),
|
|
409
481
|
completion_tokens_details: import_v42.z.object({
|
|
410
482
|
reasoning_tokens: import_v42.z.number().nullish(),
|
|
@@ -453,7 +525,7 @@ var openaiChatLanguageModelOptions = (0, import_provider_utils4.lazyValidator)(
|
|
|
453
525
|
/**
|
|
454
526
|
* Reasoning effort for reasoning models. Defaults to `medium`.
|
|
455
527
|
*/
|
|
456
|
-
reasoningEffort: import_v43.z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]).optional(),
|
|
528
|
+
reasoningEffort: import_v43.z.enum(["none", "minimal", "low", "medium", "high", "xhigh", "max"]).optional(),
|
|
457
529
|
/**
|
|
458
530
|
* Maximum number of completion tokens to generate. Useful for reasoning models.
|
|
459
531
|
*/
|
|
@@ -503,11 +575,22 @@ var openaiChatLanguageModelOptions = (0, import_provider_utils4.lazyValidator)(
|
|
|
503
575
|
* Useful for improving cache hit rates and working around automatic caching issues.
|
|
504
576
|
*/
|
|
505
577
|
promptCacheKey: import_v43.z.string().optional(),
|
|
578
|
+
/**
|
|
579
|
+
* Prompt cache behavior for GPT-5.6 and later models.
|
|
580
|
+
* `mode` controls whether OpenAI also places an implicit breakpoint.
|
|
581
|
+
* `ttl` sets the minimum cache lifetime and currently only supports 30 minutes.
|
|
582
|
+
*/
|
|
583
|
+
promptCacheOptions: import_v43.z.object({
|
|
584
|
+
mode: import_v43.z.enum(["implicit", "explicit"]).optional(),
|
|
585
|
+
ttl: import_v43.z.literal("30m").optional()
|
|
586
|
+
}).optional(),
|
|
506
587
|
/**
|
|
507
588
|
* The retention policy for the prompt cache.
|
|
508
589
|
* - 'in_memory': Default. Standard prompt caching behavior.
|
|
509
590
|
* - '24h': Extended prompt caching that keeps cached prefixes active for up to 24 hours.
|
|
510
|
-
*
|
|
591
|
+
* Available for models before GPT-5.6 that support extended caching.
|
|
592
|
+
*
|
|
593
|
+
* @deprecated For GPT-5.6 and later models, use `promptCacheOptions.ttl`.
|
|
511
594
|
*
|
|
512
595
|
* @default 'in_memory'
|
|
513
596
|
*/
|
|
@@ -679,6 +762,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
679
762
|
reasoning_effort: openaiOptions.reasoningEffort,
|
|
680
763
|
service_tier: openaiOptions.serviceTier,
|
|
681
764
|
prompt_cache_key: openaiOptions.promptCacheKey,
|
|
765
|
+
prompt_cache_options: openaiOptions.promptCacheOptions,
|
|
682
766
|
prompt_cache_retention: openaiOptions.promptCacheRetention,
|
|
683
767
|
safety_identifier: openaiOptions.safetyIdentifier,
|
|
684
768
|
// messages:
|
|
@@ -844,6 +928,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
844
928
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
|
|
845
929
|
providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
|
|
846
930
|
}
|
|
931
|
+
if ((promptTokenDetails == null ? void 0 : promptTokenDetails.cache_write_tokens) != null) {
|
|
932
|
+
providerMetadata.openai.usage = {
|
|
933
|
+
cacheWriteTokens: promptTokenDetails.cache_write_tokens
|
|
934
|
+
};
|
|
935
|
+
}
|
|
847
936
|
if (((_f = choice.logprobs) == null ? void 0 : _f.content) != null) {
|
|
848
937
|
providerMetadata.openai.logprobs = choice.logprobs.content;
|
|
849
938
|
}
|
|
@@ -907,7 +996,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
907
996
|
controller.enqueue({ type: "stream-start", warnings });
|
|
908
997
|
},
|
|
909
998
|
transform(chunk, controller) {
|
|
910
|
-
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;
|
|
999
|
+
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;
|
|
911
1000
|
if (options.includeRawChunks) {
|
|
912
1001
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
913
1002
|
}
|
|
@@ -938,18 +1027,23 @@ var OpenAIChatLanguageModel = class {
|
|
|
938
1027
|
usage.totalTokens = (_c = value.usage.total_tokens) != null ? _c : void 0;
|
|
939
1028
|
usage.reasoningTokens = (_e = (_d = value.usage.completion_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : void 0;
|
|
940
1029
|
usage.cachedInputTokens = (_g = (_f = value.usage.prompt_tokens_details) == null ? void 0 : _f.cached_tokens) != null ? _g : void 0;
|
|
941
|
-
if (((_h = value.usage.
|
|
942
|
-
providerMetadata.openai.
|
|
1030
|
+
if (((_h = value.usage.prompt_tokens_details) == null ? void 0 : _h.cache_write_tokens) != null) {
|
|
1031
|
+
providerMetadata.openai.usage = {
|
|
1032
|
+
cacheWriteTokens: value.usage.prompt_tokens_details.cache_write_tokens
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
if (((_i = value.usage.completion_tokens_details) == null ? void 0 : _i.accepted_prediction_tokens) != null) {
|
|
1036
|
+
providerMetadata.openai.acceptedPredictionTokens = (_j = value.usage.completion_tokens_details) == null ? void 0 : _j.accepted_prediction_tokens;
|
|
943
1037
|
}
|
|
944
|
-
if (((
|
|
945
|
-
providerMetadata.openai.rejectedPredictionTokens = (
|
|
1038
|
+
if (((_k = value.usage.completion_tokens_details) == null ? void 0 : _k.rejected_prediction_tokens) != null) {
|
|
1039
|
+
providerMetadata.openai.rejectedPredictionTokens = (_l = value.usage.completion_tokens_details) == null ? void 0 : _l.rejected_prediction_tokens;
|
|
946
1040
|
}
|
|
947
1041
|
}
|
|
948
1042
|
const choice = value.choices[0];
|
|
949
1043
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
950
1044
|
finishReason = mapOpenAIFinishReason(choice.finish_reason);
|
|
951
1045
|
}
|
|
952
|
-
if (((
|
|
1046
|
+
if (((_m = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _m.content) != null) {
|
|
953
1047
|
providerMetadata.openai.logprobs = choice.logprobs.content;
|
|
954
1048
|
}
|
|
955
1049
|
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
@@ -983,7 +1077,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
983
1077
|
message: `Expected 'id' to be a string.`
|
|
984
1078
|
});
|
|
985
1079
|
}
|
|
986
|
-
if (((
|
|
1080
|
+
if (((_n = toolCallDelta.function) == null ? void 0 : _n.name) == null) {
|
|
987
1081
|
throw new import_provider3.InvalidResponseDataError({
|
|
988
1082
|
data: toolCallDelta,
|
|
989
1083
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -999,12 +1093,12 @@ var OpenAIChatLanguageModel = class {
|
|
|
999
1093
|
type: "function",
|
|
1000
1094
|
function: {
|
|
1001
1095
|
name: toolCallDelta.function.name,
|
|
1002
|
-
arguments: (
|
|
1096
|
+
arguments: (_o = toolCallDelta.function.arguments) != null ? _o : ""
|
|
1003
1097
|
},
|
|
1004
1098
|
hasFinished: false
|
|
1005
1099
|
};
|
|
1006
1100
|
const toolCall2 = toolCalls[index];
|
|
1007
|
-
if (((
|
|
1101
|
+
if (((_p = toolCall2.function) == null ? void 0 : _p.name) != null && ((_q = toolCall2.function) == null ? void 0 : _q.arguments) != null) {
|
|
1008
1102
|
if (toolCall2.function.arguments.length > 0) {
|
|
1009
1103
|
controller.enqueue({
|
|
1010
1104
|
type: "tool-input-delta",
|
|
@@ -1019,7 +1113,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1019
1113
|
});
|
|
1020
1114
|
controller.enqueue({
|
|
1021
1115
|
type: "tool-call",
|
|
1022
|
-
toolCallId: (
|
|
1116
|
+
toolCallId: (_r = toolCall2.id) != null ? _r : (0, import_provider_utils5.generateId)(),
|
|
1023
1117
|
toolName: toolCall2.function.name,
|
|
1024
1118
|
input: toolCall2.function.arguments
|
|
1025
1119
|
});
|
|
@@ -1032,22 +1126,22 @@ var OpenAIChatLanguageModel = class {
|
|
|
1032
1126
|
if (toolCall.hasFinished) {
|
|
1033
1127
|
continue;
|
|
1034
1128
|
}
|
|
1035
|
-
if (((
|
|
1036
|
-
toolCall.function.arguments += (
|
|
1129
|
+
if (((_s = toolCallDelta.function) == null ? void 0 : _s.arguments) != null) {
|
|
1130
|
+
toolCall.function.arguments += (_u = (_t = toolCallDelta.function) == null ? void 0 : _t.arguments) != null ? _u : "";
|
|
1037
1131
|
}
|
|
1038
1132
|
controller.enqueue({
|
|
1039
1133
|
type: "tool-input-delta",
|
|
1040
1134
|
id: toolCall.id,
|
|
1041
|
-
delta: (
|
|
1135
|
+
delta: (_v = toolCallDelta.function.arguments) != null ? _v : ""
|
|
1042
1136
|
});
|
|
1043
|
-
if (((
|
|
1137
|
+
if (((_w = toolCall.function) == null ? void 0 : _w.name) != null && ((_x = toolCall.function) == null ? void 0 : _x.arguments) != null && (0, import_provider_utils5.isParsableJson)(toolCall.function.arguments)) {
|
|
1044
1138
|
controller.enqueue({
|
|
1045
1139
|
type: "tool-input-end",
|
|
1046
1140
|
id: toolCall.id
|
|
1047
1141
|
});
|
|
1048
1142
|
controller.enqueue({
|
|
1049
1143
|
type: "tool-call",
|
|
1050
|
-
toolCallId: (
|
|
1144
|
+
toolCallId: (_y = toolCall.id) != null ? _y : (0, import_provider_utils5.generateId)(),
|
|
1051
1145
|
toolName: toolCall.function.name,
|
|
1052
1146
|
input: toolCall.function.arguments
|
|
1053
1147
|
});
|
|
@@ -2198,6 +2292,10 @@ var import_provider_utils25 = require("@ai-sdk/provider-utils");
|
|
|
2198
2292
|
var import_provider6 = require("@ai-sdk/provider");
|
|
2199
2293
|
var import_provider_utils21 = require("@ai-sdk/provider-utils");
|
|
2200
2294
|
var import_v416 = require("zod/v4");
|
|
2295
|
+
function getPromptCacheBreakpoint2(providerOptions) {
|
|
2296
|
+
var _a;
|
|
2297
|
+
return (_a = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a.promptCacheBreakpoint;
|
|
2298
|
+
}
|
|
2201
2299
|
function isFileId(data, prefixes) {
|
|
2202
2300
|
if (!prefixes) return false;
|
|
2203
2301
|
return prefixes.some((prefix) => data.startsWith(prefix));
|
|
@@ -2212,16 +2310,36 @@ async function convertToOpenAIResponsesInput({
|
|
|
2212
2310
|
var _a, _b, _c, _d, _e, _f;
|
|
2213
2311
|
let input = [];
|
|
2214
2312
|
const warnings = [];
|
|
2215
|
-
for (const { role, content } of prompt) {
|
|
2313
|
+
for (const { role, content, providerOptions } of prompt) {
|
|
2216
2314
|
switch (role) {
|
|
2217
2315
|
case "system": {
|
|
2218
2316
|
switch (systemMessageMode) {
|
|
2219
2317
|
case "system": {
|
|
2220
|
-
|
|
2318
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
|
|
2319
|
+
input.push({
|
|
2320
|
+
role: "system",
|
|
2321
|
+
content: promptCacheBreakpoint == null ? content : [
|
|
2322
|
+
{
|
|
2323
|
+
type: "input_text",
|
|
2324
|
+
text: content,
|
|
2325
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2326
|
+
}
|
|
2327
|
+
]
|
|
2328
|
+
});
|
|
2221
2329
|
break;
|
|
2222
2330
|
}
|
|
2223
2331
|
case "developer": {
|
|
2224
|
-
|
|
2332
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint2(providerOptions);
|
|
2333
|
+
input.push({
|
|
2334
|
+
role: "developer",
|
|
2335
|
+
content: promptCacheBreakpoint == null ? content : [
|
|
2336
|
+
{
|
|
2337
|
+
type: "input_text",
|
|
2338
|
+
text: content,
|
|
2339
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2340
|
+
}
|
|
2341
|
+
]
|
|
2342
|
+
});
|
|
2225
2343
|
break;
|
|
2226
2344
|
}
|
|
2227
2345
|
case "remove": {
|
|
@@ -2247,9 +2365,21 @@ async function convertToOpenAIResponsesInput({
|
|
|
2247
2365
|
var _a2, _b2, _c2;
|
|
2248
2366
|
switch (part.type) {
|
|
2249
2367
|
case "text": {
|
|
2250
|
-
|
|
2368
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
2369
|
+
part.providerOptions
|
|
2370
|
+
);
|
|
2371
|
+
return {
|
|
2372
|
+
type: "input_text",
|
|
2373
|
+
text: part.text,
|
|
2374
|
+
...promptCacheBreakpoint != null && {
|
|
2375
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2376
|
+
}
|
|
2377
|
+
};
|
|
2251
2378
|
}
|
|
2252
2379
|
case "file": {
|
|
2380
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
2381
|
+
part.providerOptions
|
|
2382
|
+
);
|
|
2253
2383
|
if (part.mediaType.startsWith("image/")) {
|
|
2254
2384
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
2255
2385
|
return {
|
|
@@ -2257,13 +2387,19 @@ async function convertToOpenAIResponsesInput({
|
|
|
2257
2387
|
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
2258
2388
|
image_url: `data:${mediaType};base64,${(0, import_provider_utils21.convertToBase64)(part.data)}`
|
|
2259
2389
|
},
|
|
2260
|
-
detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
|
|
2390
|
+
detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail,
|
|
2391
|
+
...promptCacheBreakpoint != null && {
|
|
2392
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2393
|
+
}
|
|
2261
2394
|
};
|
|
2262
2395
|
} else if (part.mediaType === "application/pdf") {
|
|
2263
2396
|
if (part.data instanceof URL) {
|
|
2264
2397
|
return {
|
|
2265
2398
|
type: "input_file",
|
|
2266
|
-
file_url: part.data.toString()
|
|
2399
|
+
file_url: part.data.toString(),
|
|
2400
|
+
...promptCacheBreakpoint != null && {
|
|
2401
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2402
|
+
}
|
|
2267
2403
|
};
|
|
2268
2404
|
}
|
|
2269
2405
|
return {
|
|
@@ -2271,6 +2407,9 @@ async function convertToOpenAIResponsesInput({
|
|
|
2271
2407
|
...typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
2272
2408
|
filename: (_c2 = part.filename) != null ? _c2 : `part-${index}.pdf`,
|
|
2273
2409
|
file_data: `data:application/pdf;base64,${(0, import_provider_utils21.convertToBase64)(part.data)}`
|
|
2410
|
+
},
|
|
2411
|
+
...promptCacheBreakpoint != null && {
|
|
2412
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2274
2413
|
}
|
|
2275
2414
|
};
|
|
2276
2415
|
} else {
|
|
@@ -2356,12 +2495,12 @@ async function convertToOpenAIResponsesInput({
|
|
|
2356
2495
|
break;
|
|
2357
2496
|
}
|
|
2358
2497
|
case "reasoning": {
|
|
2359
|
-
const
|
|
2498
|
+
const providerOptions2 = await (0, import_provider_utils21.parseProviderOptions)({
|
|
2360
2499
|
provider: "openai",
|
|
2361
2500
|
providerOptions: part.providerOptions,
|
|
2362
2501
|
schema: openaiResponsesReasoningProviderOptionsSchema
|
|
2363
2502
|
});
|
|
2364
|
-
const reasoningId =
|
|
2503
|
+
const reasoningId = providerOptions2 == null ? void 0 : providerOptions2.itemId;
|
|
2365
2504
|
if (reasoningId != null) {
|
|
2366
2505
|
const reasoningMessage = reasoningMessages[reasoningId];
|
|
2367
2506
|
if (store) {
|
|
@@ -2390,14 +2529,14 @@ async function convertToOpenAIResponsesInput({
|
|
|
2390
2529
|
reasoningMessages[reasoningId] = {
|
|
2391
2530
|
type: "reasoning",
|
|
2392
2531
|
id: reasoningId,
|
|
2393
|
-
encrypted_content:
|
|
2532
|
+
encrypted_content: providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent,
|
|
2394
2533
|
summary: summaryParts
|
|
2395
2534
|
};
|
|
2396
2535
|
input.push(reasoningMessages[reasoningId]);
|
|
2397
2536
|
} else {
|
|
2398
2537
|
reasoningMessage.summary.push(...summaryParts);
|
|
2399
|
-
if ((
|
|
2400
|
-
reasoningMessage.encrypted_content =
|
|
2538
|
+
if ((providerOptions2 == null ? void 0 : providerOptions2.reasoningEncryptedContent) != null) {
|
|
2539
|
+
reasoningMessage.encrypted_content = providerOptions2.reasoningEncryptedContent;
|
|
2401
2540
|
}
|
|
2402
2541
|
}
|
|
2403
2542
|
}
|
|
@@ -2416,6 +2555,9 @@ async function convertToOpenAIResponsesInput({
|
|
|
2416
2555
|
case "tool": {
|
|
2417
2556
|
for (const part of content) {
|
|
2418
2557
|
const output = part.output;
|
|
2558
|
+
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
2559
|
+
part.providerOptions
|
|
2560
|
+
);
|
|
2419
2561
|
if (hasLocalShellTool && part.toolName === "local_shell" && output.type === "json") {
|
|
2420
2562
|
const parsedOutput = await (0, import_provider_utils21.validateTypes)({
|
|
2421
2563
|
value: output.value,
|
|
@@ -2432,26 +2574,51 @@ async function convertToOpenAIResponsesInput({
|
|
|
2432
2574
|
switch (output.type) {
|
|
2433
2575
|
case "text":
|
|
2434
2576
|
case "error-text":
|
|
2435
|
-
contentValue = output.value
|
|
2577
|
+
contentValue = promptCacheBreakpoint == null ? output.value : [
|
|
2578
|
+
{
|
|
2579
|
+
type: "input_text",
|
|
2580
|
+
text: output.value,
|
|
2581
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2582
|
+
}
|
|
2583
|
+
];
|
|
2436
2584
|
break;
|
|
2437
2585
|
case "json":
|
|
2438
2586
|
case "error-json":
|
|
2439
|
-
contentValue = JSON.stringify(output.value)
|
|
2587
|
+
contentValue = promptCacheBreakpoint == null ? JSON.stringify(output.value) : [
|
|
2588
|
+
{
|
|
2589
|
+
type: "input_text",
|
|
2590
|
+
text: JSON.stringify(output.value),
|
|
2591
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2592
|
+
}
|
|
2593
|
+
];
|
|
2440
2594
|
break;
|
|
2441
2595
|
case "content":
|
|
2442
|
-
contentValue = output.value.map((item) => {
|
|
2596
|
+
contentValue = output.value.map((item, index) => {
|
|
2597
|
+
const isBreakpoint = promptCacheBreakpoint != null && index === output.value.length - 1;
|
|
2443
2598
|
switch (item.type) {
|
|
2444
2599
|
case "text": {
|
|
2445
|
-
return {
|
|
2600
|
+
return {
|
|
2601
|
+
type: "input_text",
|
|
2602
|
+
text: item.text,
|
|
2603
|
+
...isBreakpoint && {
|
|
2604
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2605
|
+
}
|
|
2606
|
+
};
|
|
2446
2607
|
}
|
|
2447
2608
|
case "media": {
|
|
2448
2609
|
return item.mediaType.startsWith("image/") ? {
|
|
2449
2610
|
type: "input_image",
|
|
2450
|
-
image_url: `data:${item.mediaType};base64,${item.data}
|
|
2611
|
+
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
2612
|
+
...isBreakpoint && {
|
|
2613
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2614
|
+
}
|
|
2451
2615
|
} : {
|
|
2452
2616
|
type: "input_file",
|
|
2453
2617
|
filename: "data",
|
|
2454
|
-
file_data: `data:${item.mediaType};base64,${item.data}
|
|
2618
|
+
file_data: `data:${item.mediaType};base64,${item.data}`,
|
|
2619
|
+
...isBreakpoint && {
|
|
2620
|
+
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
2621
|
+
}
|
|
2455
2622
|
};
|
|
2456
2623
|
}
|
|
2457
2624
|
}
|
|
@@ -2539,6 +2706,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils22.lazyValidator)(
|
|
|
2539
2706
|
input_tokens: import_v417.z.number(),
|
|
2540
2707
|
input_tokens_details: import_v417.z.object({
|
|
2541
2708
|
cached_tokens: import_v417.z.number().nullish(),
|
|
2709
|
+
cache_write_tokens: import_v417.z.number().nullish(),
|
|
2542
2710
|
orchestration_input_tokens: import_v417.z.number().nullish(),
|
|
2543
2711
|
orchestration_input_cached_tokens: import_v417.z.number().nullish()
|
|
2544
2712
|
}).nullish(),
|
|
@@ -2548,6 +2716,9 @@ var openaiResponsesChunkSchema = (0, import_provider_utils22.lazyValidator)(
|
|
|
2548
2716
|
orchestration_output_tokens: import_v417.z.number().nullish()
|
|
2549
2717
|
}).nullish()
|
|
2550
2718
|
}),
|
|
2719
|
+
reasoning: import_v417.z.object({
|
|
2720
|
+
context: import_v417.z.string().nullish()
|
|
2721
|
+
}).nullish(),
|
|
2551
2722
|
service_tier: import_v417.z.string().nullish()
|
|
2552
2723
|
})
|
|
2553
2724
|
}),
|
|
@@ -2966,11 +3137,15 @@ var openaiResponsesResponseSchema = (0, import_provider_utils22.lazyValidator)(
|
|
|
2966
3137
|
])
|
|
2967
3138
|
).optional(),
|
|
2968
3139
|
service_tier: import_v417.z.string().nullish(),
|
|
3140
|
+
reasoning: import_v417.z.object({
|
|
3141
|
+
context: import_v417.z.string().nullish()
|
|
3142
|
+
}).nullish(),
|
|
2969
3143
|
incomplete_details: import_v417.z.object({ reason: import_v417.z.string() }).nullish(),
|
|
2970
3144
|
usage: import_v417.z.object({
|
|
2971
3145
|
input_tokens: import_v417.z.number(),
|
|
2972
3146
|
input_tokens_details: import_v417.z.object({
|
|
2973
3147
|
cached_tokens: import_v417.z.number().nullish(),
|
|
3148
|
+
cache_write_tokens: import_v417.z.number().nullish(),
|
|
2974
3149
|
orchestration_input_tokens: import_v417.z.number().nullish(),
|
|
2975
3150
|
orchestration_input_cached_tokens: import_v417.z.number().nullish()
|
|
2976
3151
|
}).nullish(),
|
|
@@ -3030,7 +3205,11 @@ var openaiResponsesReasoningModelIds = [
|
|
|
3030
3205
|
"gpt-5.4-nano",
|
|
3031
3206
|
"gpt-5.4-nano-2026-03-17",
|
|
3032
3207
|
"gpt-5.4-pro",
|
|
3033
|
-
"gpt-5.4-pro-2026-03-05"
|
|
3208
|
+
"gpt-5.4-pro-2026-03-05",
|
|
3209
|
+
"gpt-5.6",
|
|
3210
|
+
"gpt-5.6-luna",
|
|
3211
|
+
"gpt-5.6-sol",
|
|
3212
|
+
"gpt-5.6-terra"
|
|
3034
3213
|
];
|
|
3035
3214
|
var openaiResponsesModelIds = [
|
|
3036
3215
|
"gpt-4.1",
|
|
@@ -3104,11 +3283,22 @@ var openaiResponsesProviderOptionsSchema = (0, import_provider_utils23.lazyValid
|
|
|
3104
3283
|
parallelToolCalls: import_v418.z.boolean().nullish(),
|
|
3105
3284
|
previousResponseId: import_v418.z.string().nullish(),
|
|
3106
3285
|
promptCacheKey: import_v418.z.string().nullish(),
|
|
3286
|
+
/**
|
|
3287
|
+
* Prompt cache behavior for GPT-5.6 and later models.
|
|
3288
|
+
* `mode` controls whether OpenAI also places an implicit breakpoint.
|
|
3289
|
+
* `ttl` sets the minimum cache lifetime and currently only supports 30 minutes.
|
|
3290
|
+
*/
|
|
3291
|
+
promptCacheOptions: import_v418.z.object({
|
|
3292
|
+
mode: import_v418.z.enum(["implicit", "explicit"]).optional(),
|
|
3293
|
+
ttl: import_v418.z.literal("30m").optional()
|
|
3294
|
+
}).optional(),
|
|
3107
3295
|
/**
|
|
3108
3296
|
* The retention policy for the prompt cache.
|
|
3109
3297
|
* - 'in_memory': Default. Standard prompt caching behavior.
|
|
3110
3298
|
* - '24h': Extended prompt caching that keeps cached prefixes active for up to 24 hours.
|
|
3111
|
-
*
|
|
3299
|
+
* Available for models before GPT-5.6 that support extended caching.
|
|
3300
|
+
*
|
|
3301
|
+
* @deprecated For GPT-5.6 and later models, use `promptCacheOptions.ttl`.
|
|
3112
3302
|
*
|
|
3113
3303
|
* @default 'in_memory'
|
|
3114
3304
|
*/
|
|
@@ -3116,14 +3306,21 @@ var openaiResponsesProviderOptionsSchema = (0, import_provider_utils23.lazyValid
|
|
|
3116
3306
|
/**
|
|
3117
3307
|
* Reasoning effort for reasoning models. Defaults to `medium`. If you use
|
|
3118
3308
|
* `providerOptions` to set the `reasoningEffort` option, this model setting will be ignored.
|
|
3119
|
-
*
|
|
3120
|
-
*
|
|
3121
|
-
* The 'none' type for `reasoningEffort` is only available for OpenAI's GPT-5.1
|
|
3122
|
-
* models. Also, the 'xhigh' type for `reasoningEffort` is only available for
|
|
3123
|
-
* OpenAI's GPT-5.1-Codex-Max model. Setting `reasoningEffort` to 'none' or 'xhigh' with unsupported models will result in
|
|
3124
|
-
* an error.
|
|
3309
|
+
* GPT-5.6 supports 'none' | 'low' | 'medium' | 'high' | 'xhigh' | 'max'.
|
|
3310
|
+
* Supported values vary by model.
|
|
3125
3311
|
*/
|
|
3126
3312
|
reasoningEffort: import_v418.z.string().nullish(),
|
|
3313
|
+
/**
|
|
3314
|
+
* Controls how much model work GPT-5.6 performs before returning a final answer.
|
|
3315
|
+
* `standard` is the default. `pro` increases quality, latency, and token usage.
|
|
3316
|
+
*/
|
|
3317
|
+
reasoningMode: import_v418.z.enum(["standard", "pro"]).optional(),
|
|
3318
|
+
/**
|
|
3319
|
+
* Controls which available reasoning items GPT-5.6 can use.
|
|
3320
|
+
* `auto` uses the model default, `current_turn` excludes reasoning from earlier
|
|
3321
|
+
* turns, and `all_turns` makes compatible earlier reasoning available.
|
|
3322
|
+
*/
|
|
3323
|
+
reasoningContext: import_v418.z.enum(["auto", "current_turn", "all_turns"]).optional(),
|
|
3127
3324
|
reasoningSummary: import_v418.z.string().nullish(),
|
|
3128
3325
|
safetyIdentifier: import_v418.z.string().nullish(),
|
|
3129
3326
|
serviceTier: import_v418.z.enum(["auto", "flex", "priority", "default"]).nullish(),
|
|
@@ -3415,18 +3612,25 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3415
3612
|
service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
|
|
3416
3613
|
include,
|
|
3417
3614
|
prompt_cache_key: openaiOptions == null ? void 0 : openaiOptions.promptCacheKey,
|
|
3615
|
+
prompt_cache_options: openaiOptions == null ? void 0 : openaiOptions.promptCacheOptions,
|
|
3418
3616
|
prompt_cache_retention: openaiOptions == null ? void 0 : openaiOptions.promptCacheRetention,
|
|
3419
3617
|
safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
|
|
3420
3618
|
top_logprobs: topLogprobs,
|
|
3421
3619
|
truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
|
|
3422
3620
|
// model-specific settings:
|
|
3423
|
-
...modelCapabilities.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
|
|
3621
|
+
...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) && {
|
|
3424
3622
|
reasoning: {
|
|
3425
3623
|
...(openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null && {
|
|
3426
3624
|
effort: openaiOptions.reasoningEffort
|
|
3427
3625
|
},
|
|
3428
3626
|
...(openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null && {
|
|
3429
3627
|
summary: openaiOptions.reasoningSummary
|
|
3628
|
+
},
|
|
3629
|
+
...(openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null && {
|
|
3630
|
+
mode: openaiOptions.reasoningMode
|
|
3631
|
+
},
|
|
3632
|
+
...(openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null && {
|
|
3633
|
+
context: openaiOptions.reasoningContext
|
|
3430
3634
|
}
|
|
3431
3635
|
}
|
|
3432
3636
|
}
|
|
@@ -3465,6 +3669,20 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3465
3669
|
details: "reasoningSummary is not supported for non-reasoning models"
|
|
3466
3670
|
});
|
|
3467
3671
|
}
|
|
3672
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.reasoningMode) != null) {
|
|
3673
|
+
warnings.push({
|
|
3674
|
+
type: "unsupported-setting",
|
|
3675
|
+
setting: "reasoningMode",
|
|
3676
|
+
details: "reasoningMode is not supported for non-reasoning models"
|
|
3677
|
+
});
|
|
3678
|
+
}
|
|
3679
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.reasoningContext) != null) {
|
|
3680
|
+
warnings.push({
|
|
3681
|
+
type: "unsupported-setting",
|
|
3682
|
+
setting: "reasoningContext",
|
|
3683
|
+
details: "reasoningContext is not supported for non-reasoning models"
|
|
3684
|
+
});
|
|
3685
|
+
}
|
|
3468
3686
|
}
|
|
3469
3687
|
if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !modelCapabilities.supportsFlexProcessing) {
|
|
3470
3688
|
warnings.push({
|
|
@@ -3503,7 +3721,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3503
3721
|
};
|
|
3504
3722
|
}
|
|
3505
3723
|
async doGenerate(options) {
|
|
3506
|
-
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;
|
|
3724
|
+
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;
|
|
3507
3725
|
const {
|
|
3508
3726
|
args: body,
|
|
3509
3727
|
warnings,
|
|
@@ -3787,23 +4005,26 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3787
4005
|
if (typeof response.service_tier === "string") {
|
|
3788
4006
|
providerMetadata[providerKey].serviceTier = response.service_tier;
|
|
3789
4007
|
}
|
|
4008
|
+
if (((_x = response.reasoning) == null ? void 0 : _x.context) != null) {
|
|
4009
|
+
providerMetadata[providerKey].reasoningContext = response.reasoning.context;
|
|
4010
|
+
}
|
|
3790
4011
|
const usage = response.usage;
|
|
3791
|
-
const
|
|
3792
|
-
if (
|
|
3793
|
-
providerMetadata[providerKey].usage =
|
|
4012
|
+
const responsesUsage = getResponsesUsageMetadata(usage);
|
|
4013
|
+
if (responsesUsage != null) {
|
|
4014
|
+
providerMetadata[providerKey].usage = responsesUsage;
|
|
3794
4015
|
}
|
|
3795
4016
|
return {
|
|
3796
4017
|
content,
|
|
3797
4018
|
finishReason: mapOpenAIResponseFinishReason({
|
|
3798
|
-
finishReason: (
|
|
4019
|
+
finishReason: (_y = response.incomplete_details) == null ? void 0 : _y.reason,
|
|
3799
4020
|
hasFunctionCall
|
|
3800
4021
|
}),
|
|
3801
4022
|
usage: {
|
|
3802
4023
|
inputTokens: usage.input_tokens,
|
|
3803
4024
|
outputTokens: usage.output_tokens,
|
|
3804
4025
|
totalTokens: usage.input_tokens + usage.output_tokens,
|
|
3805
|
-
reasoningTokens: (
|
|
3806
|
-
cachedInputTokens: (
|
|
4026
|
+
reasoningTokens: (_A = (_z = usage.output_tokens_details) == null ? void 0 : _z.reasoning_tokens) != null ? _A : void 0,
|
|
4027
|
+
cachedInputTokens: (_C = (_B = usage.input_tokens_details) == null ? void 0 : _B.cached_tokens) != null ? _C : void 0
|
|
3807
4028
|
},
|
|
3808
4029
|
request: { body },
|
|
3809
4030
|
response: {
|
|
@@ -3857,7 +4078,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3857
4078
|
let hasFunctionCall = false;
|
|
3858
4079
|
const activeReasoning = {};
|
|
3859
4080
|
let serviceTier;
|
|
3860
|
-
let
|
|
4081
|
+
let reasoningContext;
|
|
4082
|
+
let responsesUsage;
|
|
3861
4083
|
return {
|
|
3862
4084
|
stream: response.pipeThrough(
|
|
3863
4085
|
new TransformStream({
|
|
@@ -3865,7 +4087,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3865
4087
|
controller.enqueue({ type: "stream-start", warnings });
|
|
3866
4088
|
},
|
|
3867
4089
|
transform(chunk, controller) {
|
|
3868
|
-
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;
|
|
4090
|
+
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;
|
|
3869
4091
|
if (options.includeRawChunks) {
|
|
3870
4092
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
3871
4093
|
}
|
|
@@ -4258,16 +4480,17 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4258
4480
|
if (typeof value.response.service_tier === "string") {
|
|
4259
4481
|
serviceTier = value.response.service_tier;
|
|
4260
4482
|
}
|
|
4261
|
-
|
|
4262
|
-
value.response.
|
|
4263
|
-
|
|
4483
|
+
if (((_p = value.response.reasoning) == null ? void 0 : _p.context) != null) {
|
|
4484
|
+
reasoningContext = value.response.reasoning.context;
|
|
4485
|
+
}
|
|
4486
|
+
responsesUsage = getResponsesUsageMetadata(value.response.usage);
|
|
4264
4487
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
4265
4488
|
ongoingAnnotations.push(value.annotation);
|
|
4266
4489
|
if (value.annotation.type === "url_citation") {
|
|
4267
4490
|
controller.enqueue({
|
|
4268
4491
|
type: "source",
|
|
4269
4492
|
sourceType: "url",
|
|
4270
|
-
id: (
|
|
4493
|
+
id: (_s = (_r = (_q = self.config).generateId) == null ? void 0 : _r.call(_q)) != null ? _s : (0, import_provider_utils25.generateId)(),
|
|
4271
4494
|
url: value.annotation.url,
|
|
4272
4495
|
title: value.annotation.title
|
|
4273
4496
|
});
|
|
@@ -4275,10 +4498,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4275
4498
|
controller.enqueue({
|
|
4276
4499
|
type: "source",
|
|
4277
4500
|
sourceType: "document",
|
|
4278
|
-
id: (
|
|
4501
|
+
id: (_v = (_u = (_t = self.config).generateId) == null ? void 0 : _u.call(_t)) != null ? _v : (0, import_provider_utils25.generateId)(),
|
|
4279
4502
|
mediaType: "text/plain",
|
|
4280
|
-
title: (
|
|
4281
|
-
filename: (
|
|
4503
|
+
title: (_x = (_w = value.annotation.quote) != null ? _w : value.annotation.filename) != null ? _x : "Document",
|
|
4504
|
+
filename: (_y = value.annotation.filename) != null ? _y : value.annotation.file_id,
|
|
4282
4505
|
...value.annotation.file_id ? {
|
|
4283
4506
|
providerMetadata: {
|
|
4284
4507
|
[providerKey]: {
|
|
@@ -4304,8 +4527,11 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4304
4527
|
if (serviceTier !== void 0) {
|
|
4305
4528
|
providerMetadata[providerKey].serviceTier = serviceTier;
|
|
4306
4529
|
}
|
|
4307
|
-
if (
|
|
4308
|
-
providerMetadata[providerKey].
|
|
4530
|
+
if (reasoningContext !== void 0) {
|
|
4531
|
+
providerMetadata[providerKey].reasoningContext = reasoningContext;
|
|
4532
|
+
}
|
|
4533
|
+
if (responsesUsage != null) {
|
|
4534
|
+
providerMetadata[providerKey].usage = responsesUsage;
|
|
4309
4535
|
}
|
|
4310
4536
|
controller.enqueue({
|
|
4311
4537
|
type: "finish",
|
|
@@ -4375,15 +4601,17 @@ function mapWebSearchOutput(action) {
|
|
|
4375
4601
|
};
|
|
4376
4602
|
}
|
|
4377
4603
|
}
|
|
4378
|
-
function
|
|
4379
|
-
var _a, _b, _c;
|
|
4380
|
-
const
|
|
4381
|
-
const
|
|
4382
|
-
const
|
|
4383
|
-
|
|
4604
|
+
function getResponsesUsageMetadata(usage) {
|
|
4605
|
+
var _a, _b, _c, _d;
|
|
4606
|
+
const cacheWriteTokens = (_a = usage == null ? void 0 : usage.input_tokens_details) == null ? void 0 : _a.cache_write_tokens;
|
|
4607
|
+
const orchestrationInputTokens = (_b = usage == null ? void 0 : usage.input_tokens_details) == null ? void 0 : _b.orchestration_input_tokens;
|
|
4608
|
+
const orchestrationInputCachedTokens = (_c = usage == null ? void 0 : usage.input_tokens_details) == null ? void 0 : _c.orchestration_input_cached_tokens;
|
|
4609
|
+
const orchestrationOutputTokens = (_d = usage == null ? void 0 : usage.output_tokens_details) == null ? void 0 : _d.orchestration_output_tokens;
|
|
4610
|
+
if (cacheWriteTokens == null && orchestrationInputTokens == null && orchestrationInputCachedTokens == null && orchestrationOutputTokens == null) {
|
|
4384
4611
|
return void 0;
|
|
4385
4612
|
}
|
|
4386
4613
|
return {
|
|
4614
|
+
...cacheWriteTokens != null && { cacheWriteTokens },
|
|
4387
4615
|
...orchestrationInputTokens != null && { orchestrationInputTokens },
|
|
4388
4616
|
...orchestrationInputCachedTokens != null && {
|
|
4389
4617
|
orchestrationInputCachedTokens
|
|
@@ -4745,7 +4973,7 @@ var OpenAITranscriptionModel = class {
|
|
|
4745
4973
|
};
|
|
4746
4974
|
|
|
4747
4975
|
// src/version.ts
|
|
4748
|
-
var VERSION = true ? "2.0.
|
|
4976
|
+
var VERSION = true ? "2.0.111" : "0.0.0-test";
|
|
4749
4977
|
|
|
4750
4978
|
// src/openai-provider.ts
|
|
4751
4979
|
function createOpenAI(options = {}) {
|