@ai-sdk/openai 3.0.102 → 3.0.104
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 +15 -0
- package/dist/index.js +96 -85
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +97 -85
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -1
- package/dist/internal/index.d.ts +2 -1
- package/dist/internal/index.js +92 -81
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +93 -81
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/chat/convert-to-openai-chat-messages.ts +5 -1
- package/src/embedding/openai-embedding-model.ts +2 -0
- package/src/responses/convert-to-openai-responses-input.ts +5 -3
- package/src/responses/openai-responses-language-model.ts +7 -3
package/dist/internal/index.js
CHANGED
|
@@ -89,10 +89,10 @@ var openaiFailedResponseHandler = (0, import_provider_utils.createJsonErrorRespo
|
|
|
89
89
|
|
|
90
90
|
// src/openai-language-model-capabilities.ts
|
|
91
91
|
function getOpenAILanguageModelCapabilities(modelId) {
|
|
92
|
-
var
|
|
92
|
+
var _a2, _b, _c, _d, _e;
|
|
93
93
|
const oSeriesVersion = getOSeriesVersion(modelId);
|
|
94
94
|
const gptVersion = getGptVersion(modelId);
|
|
95
|
-
const isGptChatModel = (gptVersion == null ? void 0 : gptVersion.minor) == null && ((_b = (
|
|
95
|
+
const isGptChatModel = (gptVersion == null ? void 0 : gptVersion.minor) == null && ((_b = (_a2 = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _a2.startsWith("chat")) != null ? _b : false);
|
|
96
96
|
const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
|
|
97
97
|
const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
|
|
98
98
|
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
|
|
@@ -172,10 +172,10 @@ function createOpenAIStreamError({
|
|
|
172
172
|
requestBodyValues,
|
|
173
173
|
responseHeaders
|
|
174
174
|
}) {
|
|
175
|
-
var
|
|
175
|
+
var _a2;
|
|
176
176
|
const streamError = parseStreamError(frame);
|
|
177
177
|
return new import_provider.APICallError({
|
|
178
|
-
message: (
|
|
178
|
+
message: (_a2 = streamError == null ? void 0 : streamError.message) != null ? _a2 : "OpenAI stream failed before any output was generated",
|
|
179
179
|
url,
|
|
180
180
|
requestBodyValues,
|
|
181
181
|
statusCode: streamError == null ? 500 : getStatusCode(streamError),
|
|
@@ -185,7 +185,7 @@ function createOpenAIStreamError({
|
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
187
|
function parseStreamError(frame) {
|
|
188
|
-
var
|
|
188
|
+
var _a2;
|
|
189
189
|
const value = asRecord(frame);
|
|
190
190
|
if (value == null) {
|
|
191
191
|
return void 0;
|
|
@@ -200,7 +200,7 @@ function parseStreamError(frame) {
|
|
|
200
200
|
frame
|
|
201
201
|
} : void 0;
|
|
202
202
|
}
|
|
203
|
-
const error = (
|
|
203
|
+
const error = (_a2 = asRecord(value.error)) != null ? _a2 : value;
|
|
204
204
|
return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
|
|
205
205
|
message: error.message,
|
|
206
206
|
code: getStringOrNumber(error.code),
|
|
@@ -248,7 +248,7 @@ function isHttpErrorStatusCode(value) {
|
|
|
248
248
|
|
|
249
249
|
// src/chat/convert-openai-chat-usage.ts
|
|
250
250
|
function convertOpenAIChatUsage(usage) {
|
|
251
|
-
var
|
|
251
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
252
252
|
if (usage == null) {
|
|
253
253
|
return {
|
|
254
254
|
inputTokens: {
|
|
@@ -265,7 +265,7 @@ function convertOpenAIChatUsage(usage) {
|
|
|
265
265
|
raw: void 0
|
|
266
266
|
};
|
|
267
267
|
}
|
|
268
|
-
const promptTokens = (
|
|
268
|
+
const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
|
|
269
269
|
const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
|
|
270
270
|
const cachedTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
|
|
271
271
|
const cacheWriteTokens = (_f = (_e = usage.prompt_tokens_details) == null ? void 0 : _e.cache_write_tokens) != null ? _f : void 0;
|
|
@@ -290,17 +290,19 @@ function convertOpenAIChatUsage(usage) {
|
|
|
290
290
|
var import_provider2 = require("@ai-sdk/provider");
|
|
291
291
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
292
292
|
function serializeToolCallArguments(input) {
|
|
293
|
-
return JSON.stringify(
|
|
293
|
+
return JSON.stringify(
|
|
294
|
+
typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
|
|
295
|
+
);
|
|
294
296
|
}
|
|
295
297
|
function getPromptCacheBreakpoint(providerOptions) {
|
|
296
|
-
var
|
|
297
|
-
return (
|
|
298
|
+
var _a2;
|
|
299
|
+
return (_a2 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
298
300
|
}
|
|
299
301
|
function convertToOpenAIChatMessages({
|
|
300
302
|
prompt,
|
|
301
303
|
systemMessageMode = "system"
|
|
302
304
|
}) {
|
|
303
|
-
var
|
|
305
|
+
var _a2, _b;
|
|
304
306
|
const messages = [];
|
|
305
307
|
const warnings = [];
|
|
306
308
|
for (const { role, content, providerOptions } of prompt) {
|
|
@@ -359,7 +361,7 @@ function convertToOpenAIChatMessages({
|
|
|
359
361
|
messages.push({
|
|
360
362
|
role: "user",
|
|
361
363
|
content: content.map((part, index) => {
|
|
362
|
-
var
|
|
364
|
+
var _a3, _b2, _c;
|
|
363
365
|
switch (part.type) {
|
|
364
366
|
case "text": {
|
|
365
367
|
const promptCacheBreakpoint = getPromptCacheBreakpoint(
|
|
@@ -384,7 +386,7 @@ function convertToOpenAIChatMessages({
|
|
|
384
386
|
image_url: {
|
|
385
387
|
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils2.convertToBase64)(part.data)}`,
|
|
386
388
|
// OpenAI specific extension: image detail
|
|
387
|
-
detail: (_b2 = (
|
|
389
|
+
detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3.openai) == null ? void 0 : _b2.imageDetail
|
|
388
390
|
},
|
|
389
391
|
...promptCacheBreakpoint != null && {
|
|
390
392
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
@@ -503,7 +505,7 @@ function convertToOpenAIChatMessages({
|
|
|
503
505
|
continue;
|
|
504
506
|
}
|
|
505
507
|
const output = toolResponse.output;
|
|
506
|
-
const promptCacheBreakpoint = (
|
|
508
|
+
const promptCacheBreakpoint = (_a2 = output.type === "content" ? output.value.map((part) => getPromptCacheBreakpoint(part.providerOptions)).find((breakpoint) => breakpoint != null) : getPromptCacheBreakpoint(output.providerOptions)) != null ? _a2 : getPromptCacheBreakpoint(toolResponse.providerOptions);
|
|
507
509
|
let contentValue;
|
|
508
510
|
switch (output.type) {
|
|
509
511
|
case "text":
|
|
@@ -937,13 +939,13 @@ var OpenAIChatLanguageModel = class {
|
|
|
937
939
|
toolChoice,
|
|
938
940
|
providerOptions
|
|
939
941
|
}) {
|
|
940
|
-
var
|
|
942
|
+
var _a2, _b, _c, _d, _e;
|
|
941
943
|
const warnings = [];
|
|
942
|
-
const openaiOptions = (
|
|
944
|
+
const openaiOptions = (_a2 = await (0, import_provider_utils5.parseProviderOptions)({
|
|
943
945
|
provider: "openai",
|
|
944
946
|
providerOptions,
|
|
945
947
|
schema: openaiLanguageModelChatOptions
|
|
946
|
-
})) != null ?
|
|
948
|
+
})) != null ? _a2 : {};
|
|
947
949
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
948
950
|
const isReasoningModel = (_b = openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
|
|
949
951
|
if (topK != null) {
|
|
@@ -1105,7 +1107,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1105
1107
|
};
|
|
1106
1108
|
}
|
|
1107
1109
|
async doGenerate(options) {
|
|
1108
|
-
var
|
|
1110
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1109
1111
|
const { args: body, warnings } = await this.getArgs(options);
|
|
1110
1112
|
const {
|
|
1111
1113
|
responseHeaders,
|
|
@@ -1131,7 +1133,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1131
1133
|
if (text != null && text.length > 0) {
|
|
1132
1134
|
content.push({ type: "text", text });
|
|
1133
1135
|
}
|
|
1134
|
-
for (const toolCall of (
|
|
1136
|
+
for (const toolCall of (_a2 = choice.message.tool_calls) != null ? _a2 : []) {
|
|
1135
1137
|
content.push({
|
|
1136
1138
|
type: "tool-call",
|
|
1137
1139
|
toolCallId: (_b = toolCall.id) != null ? _b : (0, import_provider_utils5.generateId)(),
|
|
@@ -1225,7 +1227,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1225
1227
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1226
1228
|
},
|
|
1227
1229
|
transform(chunk, controller) {
|
|
1228
|
-
var
|
|
1230
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1229
1231
|
if (options.includeRawChunks) {
|
|
1230
1232
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1231
1233
|
}
|
|
@@ -1252,7 +1254,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1252
1254
|
}
|
|
1253
1255
|
if (value.usage != null) {
|
|
1254
1256
|
usage = value.usage;
|
|
1255
|
-
if (((
|
|
1257
|
+
if (((_a2 = value.usage.completion_tokens_details) == null ? void 0 : _a2.accepted_prediction_tokens) != null) {
|
|
1256
1258
|
providerMetadata.openai.acceptedPredictionTokens = (_b = value.usage.completion_tokens_details) == null ? void 0 : _b.accepted_prediction_tokens;
|
|
1257
1259
|
}
|
|
1258
1260
|
if (((_c = value.usage.completion_tokens_details) == null ? void 0 : _c.rejected_prediction_tokens) != null) {
|
|
@@ -1359,7 +1361,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1359
1361
|
}
|
|
1360
1362
|
},
|
|
1361
1363
|
flush(controller) {
|
|
1362
|
-
var
|
|
1364
|
+
var _a2;
|
|
1363
1365
|
if (isActiveText) {
|
|
1364
1366
|
controller.enqueue({ type: "text-end", id: "0" });
|
|
1365
1367
|
}
|
|
@@ -1371,7 +1373,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1371
1373
|
});
|
|
1372
1374
|
controller.enqueue({
|
|
1373
1375
|
type: "tool-call",
|
|
1374
|
-
toolCallId: (
|
|
1376
|
+
toolCallId: (_a2 = toolCall.id) != null ? _a2 : (0, import_provider_utils5.generateId)(),
|
|
1375
1377
|
toolName: toolCall.function.name,
|
|
1376
1378
|
input: toolCall.function.arguments
|
|
1377
1379
|
});
|
|
@@ -1408,7 +1410,7 @@ var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
|
1408
1410
|
|
|
1409
1411
|
// src/completion/convert-openai-completion-usage.ts
|
|
1410
1412
|
function convertOpenAICompletionUsage(usage) {
|
|
1411
|
-
var
|
|
1413
|
+
var _a2, _b, _c, _d;
|
|
1412
1414
|
if (usage == null) {
|
|
1413
1415
|
return {
|
|
1414
1416
|
inputTokens: {
|
|
@@ -1425,7 +1427,7 @@ function convertOpenAICompletionUsage(usage) {
|
|
|
1425
1427
|
raw: void 0
|
|
1426
1428
|
};
|
|
1427
1429
|
}
|
|
1428
|
-
const promptTokens = (
|
|
1430
|
+
const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
|
|
1429
1431
|
const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
|
|
1430
1432
|
return {
|
|
1431
1433
|
inputTokens: {
|
|
@@ -1742,7 +1744,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1742
1744
|
};
|
|
1743
1745
|
}
|
|
1744
1746
|
async doGenerate(options) {
|
|
1745
|
-
var
|
|
1747
|
+
var _a2;
|
|
1746
1748
|
const { args, warnings } = await this.getArgs(options);
|
|
1747
1749
|
const {
|
|
1748
1750
|
responseHeaders,
|
|
@@ -1772,7 +1774,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1772
1774
|
usage: convertOpenAICompletionUsage(response.usage),
|
|
1773
1775
|
finishReason: {
|
|
1774
1776
|
unified: mapOpenAIFinishReason2(choice.finish_reason),
|
|
1775
|
-
raw: (
|
|
1777
|
+
raw: (_a2 = choice.finish_reason) != null ? _a2 : void 0
|
|
1776
1778
|
},
|
|
1777
1779
|
request: { body: args },
|
|
1778
1780
|
response: {
|
|
@@ -1933,10 +1935,13 @@ var openaiTextEmbeddingResponseSchema = (0, import_provider_utils10.lazySchema)(
|
|
|
1933
1935
|
);
|
|
1934
1936
|
|
|
1935
1937
|
// src/embedding/openai-embedding-model.ts
|
|
1938
|
+
var _a;
|
|
1939
|
+
_a = import_provider_utils11.EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL;
|
|
1936
1940
|
var OpenAIEmbeddingModel = class {
|
|
1937
1941
|
constructor(modelId, config) {
|
|
1938
1942
|
this.specificationVersion = "v3";
|
|
1939
1943
|
this.maxEmbeddingsPerCall = 2048;
|
|
1944
|
+
this[_a] = 3e5;
|
|
1940
1945
|
this.supportsParallelCalls = true;
|
|
1941
1946
|
this.modelId = modelId;
|
|
1942
1947
|
this.config = config;
|
|
@@ -1950,7 +1955,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1950
1955
|
abortSignal,
|
|
1951
1956
|
providerOptions
|
|
1952
1957
|
}) {
|
|
1953
|
-
var
|
|
1958
|
+
var _a2;
|
|
1954
1959
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1955
1960
|
throw new import_provider6.TooManyEmbeddingValuesForCallError({
|
|
1956
1961
|
provider: this.provider,
|
|
@@ -1959,11 +1964,11 @@ var OpenAIEmbeddingModel = class {
|
|
|
1959
1964
|
values
|
|
1960
1965
|
});
|
|
1961
1966
|
}
|
|
1962
|
-
const openaiOptions = (
|
|
1967
|
+
const openaiOptions = (_a2 = await (0, import_provider_utils11.parseProviderOptions)({
|
|
1963
1968
|
provider: "openai",
|
|
1964
1969
|
providerOptions,
|
|
1965
1970
|
schema: openaiEmbeddingModelOptions
|
|
1966
|
-
})) != null ?
|
|
1971
|
+
})) != null ? _a2 : {};
|
|
1967
1972
|
const {
|
|
1968
1973
|
responseHeaders,
|
|
1969
1974
|
value: response,
|
|
@@ -2049,8 +2054,8 @@ function hasDefaultResponseFormat(modelId) {
|
|
|
2049
2054
|
);
|
|
2050
2055
|
}
|
|
2051
2056
|
function getMaxImagesPerCall(modelId) {
|
|
2052
|
-
var
|
|
2053
|
-
return (
|
|
2057
|
+
var _a2;
|
|
2058
|
+
return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
|
|
2054
2059
|
}
|
|
2055
2060
|
var baseImageModelOptionsObject = import_v49.z.object({
|
|
2056
2061
|
/**
|
|
@@ -2137,7 +2142,7 @@ var OpenAIImageModel = class {
|
|
|
2137
2142
|
headers,
|
|
2138
2143
|
abortSignal
|
|
2139
2144
|
}) {
|
|
2140
|
-
var
|
|
2145
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2141
2146
|
const warnings = [];
|
|
2142
2147
|
if (aspectRatio != null) {
|
|
2143
2148
|
warnings.push({
|
|
@@ -2149,7 +2154,7 @@ var OpenAIImageModel = class {
|
|
|
2149
2154
|
if (seed != null) {
|
|
2150
2155
|
warnings.push({ type: "unsupported", feature: "seed" });
|
|
2151
2156
|
}
|
|
2152
|
-
const currentDate = (_c = (_b = (
|
|
2157
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2153
2158
|
if (files != null) {
|
|
2154
2159
|
const openaiOptions2 = (_d = await (0, import_provider_utils14.parseProviderOptions)({
|
|
2155
2160
|
provider: "openai",
|
|
@@ -2212,10 +2217,10 @@ var OpenAIImageModel = class {
|
|
|
2212
2217
|
providerMetadata: {
|
|
2213
2218
|
openai: {
|
|
2214
2219
|
images: response2.data.map((item, index) => {
|
|
2215
|
-
var
|
|
2220
|
+
var _a3, _b2, _c2, _d2, _e2, _f2;
|
|
2216
2221
|
return {
|
|
2217
2222
|
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
|
|
2218
|
-
created: (
|
|
2223
|
+
created: (_a3 = response2.created) != null ? _a3 : void 0,
|
|
2219
2224
|
size: (_b2 = response2.size) != null ? _b2 : void 0,
|
|
2220
2225
|
quality: (_c2 = response2.quality) != null ? _c2 : void 0,
|
|
2221
2226
|
background: (_d2 = response2.background) != null ? _d2 : void 0,
|
|
@@ -2279,10 +2284,10 @@ var OpenAIImageModel = class {
|
|
|
2279
2284
|
providerMetadata: {
|
|
2280
2285
|
openai: {
|
|
2281
2286
|
images: response.data.map((item, index) => {
|
|
2282
|
-
var
|
|
2287
|
+
var _a3, _b2, _c2, _d2, _e2, _f2;
|
|
2283
2288
|
return {
|
|
2284
2289
|
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
|
|
2285
|
-
created: (
|
|
2290
|
+
created: (_a3 = response.created) != null ? _a3 : void 0,
|
|
2286
2291
|
size: (_b2 = response.size) != null ? _b2 : void 0,
|
|
2287
2292
|
quality: (_c2 = response.quality) != null ? _c2 : void 0,
|
|
2288
2293
|
background: (_d2 = response.background) != null ? _d2 : void 0,
|
|
@@ -2515,8 +2520,8 @@ var OpenAITranscriptionModel = class {
|
|
|
2515
2520
|
};
|
|
2516
2521
|
}
|
|
2517
2522
|
async doGenerate(options) {
|
|
2518
|
-
var
|
|
2519
|
-
const currentDate = (_c = (_b = (
|
|
2523
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
2524
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2520
2525
|
const { formData, warnings } = await this.getArgs(options);
|
|
2521
2526
|
const {
|
|
2522
2527
|
value: response,
|
|
@@ -2642,8 +2647,8 @@ var OpenAISpeechModel = class {
|
|
|
2642
2647
|
};
|
|
2643
2648
|
}
|
|
2644
2649
|
async doGenerate(options) {
|
|
2645
|
-
var
|
|
2646
|
-
const currentDate = (_c = (_b = (
|
|
2650
|
+
var _a2, _b, _c;
|
|
2651
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2647
2652
|
const { requestBody, warnings } = await this.getArgs(options);
|
|
2648
2653
|
const {
|
|
2649
2654
|
value: audio,
|
|
@@ -2683,7 +2688,7 @@ var import_provider_utils36 = require("@ai-sdk/provider-utils");
|
|
|
2683
2688
|
|
|
2684
2689
|
// src/responses/convert-openai-responses-usage.ts
|
|
2685
2690
|
function convertOpenAIResponsesUsage(usage) {
|
|
2686
|
-
var
|
|
2691
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
2687
2692
|
if (usage == null) {
|
|
2688
2693
|
return {
|
|
2689
2694
|
inputTokens: {
|
|
@@ -2702,7 +2707,7 @@ function convertOpenAIResponsesUsage(usage) {
|
|
|
2702
2707
|
}
|
|
2703
2708
|
const inputTokens = usage.input_tokens;
|
|
2704
2709
|
const outputTokens = usage.output_tokens;
|
|
2705
|
-
const cachedTokens = (_b = (
|
|
2710
|
+
const cachedTokens = (_b = (_a2 = usage.input_tokens_details) == null ? void 0 : _a2.cached_tokens) != null ? _b : 0;
|
|
2706
2711
|
const cacheWriteTokens = (_d = (_c = usage.input_tokens_details) == null ? void 0 : _c.cache_write_tokens) != null ? _d : void 0;
|
|
2707
2712
|
const reasoningTokens = (_f = (_e = usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
|
|
2708
2713
|
return {
|
|
@@ -2933,8 +2938,8 @@ function getParallelToolCallMetadata({
|
|
|
2933
2938
|
providerOptions,
|
|
2934
2939
|
providerOptionsName
|
|
2935
2940
|
}) {
|
|
2936
|
-
var
|
|
2937
|
-
const metadata = (
|
|
2941
|
+
var _a2;
|
|
2942
|
+
const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
|
|
2938
2943
|
if (!(0, import_provider7.isJSONObject)(metadata) || typeof metadata.itemId !== "string" || typeof metadata.toolCallId !== "string" || typeof metadata.toolName !== "string" || typeof metadata.input !== "string" || typeof metadata.index !== "number" || !Number.isInteger(metadata.index) || typeof metadata.count !== "number" || !Number.isInteger(metadata.count) || metadata.index < 0 || metadata.count <= metadata.index) {
|
|
2939
2944
|
return void 0;
|
|
2940
2945
|
}
|
|
@@ -3009,19 +3014,19 @@ async function convertFunctionToolResultOutput({
|
|
|
3009
3014
|
providerOptionsName,
|
|
3010
3015
|
warnings
|
|
3011
3016
|
}) {
|
|
3012
|
-
var
|
|
3017
|
+
var _a2;
|
|
3013
3018
|
switch (output.type) {
|
|
3014
3019
|
case "text":
|
|
3015
3020
|
case "error-text":
|
|
3016
3021
|
return output.value;
|
|
3017
3022
|
case "execution-denied":
|
|
3018
|
-
return (
|
|
3023
|
+
return (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
|
|
3019
3024
|
case "json":
|
|
3020
3025
|
case "error-json":
|
|
3021
3026
|
return JSON.stringify(output.value);
|
|
3022
3027
|
case "content":
|
|
3023
3028
|
return output.value.map((item) => {
|
|
3024
|
-
var
|
|
3029
|
+
var _a3, _b, _c, _d, _e;
|
|
3025
3030
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
3026
3031
|
item.providerOptions,
|
|
3027
3032
|
providerOptionsName
|
|
@@ -3040,7 +3045,7 @@ async function convertFunctionToolResultOutput({
|
|
|
3040
3045
|
return {
|
|
3041
3046
|
type: "input_image",
|
|
3042
3047
|
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3043
|
-
detail: (_b = (
|
|
3048
|
+
detail: (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail,
|
|
3044
3049
|
...promptCacheBreakpoint != null && {
|
|
3045
3050
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3046
3051
|
}
|
|
@@ -3144,8 +3149,8 @@ function collectCompleteParallelToolResultGroups({
|
|
|
3144
3149
|
return completeGroups;
|
|
3145
3150
|
}
|
|
3146
3151
|
function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
|
|
3147
|
-
var
|
|
3148
|
-
return (
|
|
3152
|
+
var _a2;
|
|
3153
|
+
return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
3149
3154
|
}
|
|
3150
3155
|
function isFileId(data, prefixes) {
|
|
3151
3156
|
if (!prefixes) return false;
|
|
@@ -3164,9 +3169,10 @@ async function convertToOpenAIResponsesInput({
|
|
|
3164
3169
|
hasLocalShellTool = false,
|
|
3165
3170
|
hasShellTool = false,
|
|
3166
3171
|
hasApplyPatchTool = false,
|
|
3172
|
+
toolSearchToolName,
|
|
3167
3173
|
customProviderToolNames
|
|
3168
3174
|
}) {
|
|
3169
|
-
var
|
|
3175
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
3170
3176
|
let input = [];
|
|
3171
3177
|
const warnings = [];
|
|
3172
3178
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
@@ -3234,7 +3240,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3234
3240
|
input.push({
|
|
3235
3241
|
role: "user",
|
|
3236
3242
|
content: content.map((part, index) => {
|
|
3237
|
-
var
|
|
3243
|
+
var _a3, _b2, _c2;
|
|
3238
3244
|
switch (part.type) {
|
|
3239
3245
|
case "text": {
|
|
3240
3246
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
@@ -3261,7 +3267,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3261
3267
|
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
3262
3268
|
image_url: `data:${mediaType};base64,${(0, import_provider_utils25.convertToBase64)(part.data)}`
|
|
3263
3269
|
},
|
|
3264
|
-
detail: (_b2 = (
|
|
3270
|
+
detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
3265
3271
|
...promptCacheBreakpoint != null && {
|
|
3266
3272
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3267
3273
|
}
|
|
@@ -3302,7 +3308,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3302
3308
|
for (const part of content) {
|
|
3303
3309
|
switch (part.type) {
|
|
3304
3310
|
case "text": {
|
|
3305
|
-
const providerOpts = (
|
|
3311
|
+
const providerOpts = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName];
|
|
3306
3312
|
const id = providerOpts == null ? void 0 : providerOpts.itemId;
|
|
3307
3313
|
const phase = providerOpts == null ? void 0 : providerOpts.phase;
|
|
3308
3314
|
if (hasConversation && id != null) {
|
|
@@ -3357,7 +3363,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3357
3363
|
const resolvedToolName = toolNameMapping.toProviderToolName(
|
|
3358
3364
|
part.toolName
|
|
3359
3365
|
);
|
|
3360
|
-
if (
|
|
3366
|
+
if (part.toolName === toolSearchToolName) {
|
|
3361
3367
|
if (store && id != null) {
|
|
3362
3368
|
input.push({ type: "item_reference", id });
|
|
3363
3369
|
break;
|
|
@@ -3478,7 +3484,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3478
3484
|
const resolvedResultToolName = toolNameMapping.toProviderToolName(
|
|
3479
3485
|
part.toolName
|
|
3480
3486
|
);
|
|
3481
|
-
if (
|
|
3487
|
+
if (part.toolName === toolSearchToolName) {
|
|
3482
3488
|
const itemId = (_s = (_r = (_o = (_n = part.providerOptions) == null ? void 0 : _n[providerOptionsName]) == null ? void 0 : _o.itemId) != null ? _r : (_q = (_p = part.providerMetadata) == null ? void 0 : _p[providerOptionsName]) == null ? void 0 : _q.itemId) != null ? _s : part.toolCallId;
|
|
3483
3489
|
if (store) {
|
|
3484
3490
|
input.push({ type: "item_reference", id: itemId });
|
|
@@ -3676,7 +3682,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3676
3682
|
const resolvedToolName = toolNameMapping.toProviderToolName(
|
|
3677
3683
|
part.toolName
|
|
3678
3684
|
);
|
|
3679
|
-
if (
|
|
3685
|
+
if (part.toolName === toolSearchToolName && output.type === "json") {
|
|
3680
3686
|
const parsedOutput = await (0, import_provider_utils25.validateTypes)({
|
|
3681
3687
|
value: output.value,
|
|
3682
3688
|
schema: toolSearchOutputSchema
|
|
@@ -3750,7 +3756,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3750
3756
|
break;
|
|
3751
3757
|
case "content":
|
|
3752
3758
|
outputValue = output.value.map((item) => {
|
|
3753
|
-
var
|
|
3759
|
+
var _a3, _b2, _c2, _d2, _e2;
|
|
3754
3760
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
3755
3761
|
item.providerOptions,
|
|
3756
3762
|
providerOptionsName
|
|
@@ -3768,7 +3774,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3768
3774
|
return {
|
|
3769
3775
|
type: "input_image",
|
|
3770
3776
|
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3771
|
-
detail: (_b2 = (
|
|
3777
|
+
detail: (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
3772
3778
|
...promptCacheBreakpoint != null && {
|
|
3773
3779
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3774
3780
|
}
|
|
@@ -5427,7 +5433,7 @@ async function prepareResponsesTools({
|
|
|
5427
5433
|
toolNameMapping,
|
|
5428
5434
|
customProviderToolNames
|
|
5429
5435
|
}) {
|
|
5430
|
-
var
|
|
5436
|
+
var _a2, _b, _c, _d;
|
|
5431
5437
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
5432
5438
|
const toolWarnings = [];
|
|
5433
5439
|
if (tools == null) {
|
|
@@ -5453,7 +5459,7 @@ async function prepareResponsesTools({
|
|
|
5453
5459
|
for (const tool of tools) {
|
|
5454
5460
|
switch (tool.type) {
|
|
5455
5461
|
case "function": {
|
|
5456
|
-
const openaiOptions = (
|
|
5462
|
+
const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
|
|
5457
5463
|
const openaiFunctionTool = prepareFunctionTool({
|
|
5458
5464
|
tool,
|
|
5459
5465
|
options: openaiOptions
|
|
@@ -5870,13 +5876,13 @@ function mapShellSkills(skills) {
|
|
|
5870
5876
|
|
|
5871
5877
|
// src/responses/openai-responses-language-model.ts
|
|
5872
5878
|
function extractApprovalRequestIdToToolCallIdMapping(prompt) {
|
|
5873
|
-
var
|
|
5879
|
+
var _a2, _b;
|
|
5874
5880
|
const mapping = {};
|
|
5875
5881
|
for (const message of prompt) {
|
|
5876
5882
|
if (message.role !== "assistant") continue;
|
|
5877
5883
|
for (const part of message.content) {
|
|
5878
5884
|
if (part.type !== "tool-call") continue;
|
|
5879
|
-
const approvalRequestId = (_b = (
|
|
5885
|
+
const approvalRequestId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.approvalRequestId;
|
|
5880
5886
|
if (approvalRequestId != null) {
|
|
5881
5887
|
mapping[approvalRequestId] = part.toolCallId;
|
|
5882
5888
|
}
|
|
@@ -5912,7 +5918,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5912
5918
|
toolChoice,
|
|
5913
5919
|
responseFormat
|
|
5914
5920
|
}) {
|
|
5915
|
-
var
|
|
5921
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
5916
5922
|
const warnings = [];
|
|
5917
5923
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
5918
5924
|
if (topK != null) {
|
|
@@ -5943,7 +5949,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5943
5949
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
5944
5950
|
});
|
|
5945
5951
|
}
|
|
5946
|
-
const isReasoningModel = (
|
|
5952
|
+
const isReasoningModel = (_a2 = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _a2 : modelCapabilities.isReasoningModel;
|
|
5947
5953
|
if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
|
|
5948
5954
|
warnings.push({
|
|
5949
5955
|
type: "unsupported",
|
|
@@ -5992,6 +5998,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5992
5998
|
hasLocalShellTool: hasOpenAITool("openai.local_shell"),
|
|
5993
5999
|
hasShellTool: hasOpenAITool("openai.shell"),
|
|
5994
6000
|
hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
|
|
6001
|
+
toolSearchToolName: getOpenAIToolName("openai.tool_search"),
|
|
5995
6002
|
customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
|
|
5996
6003
|
});
|
|
5997
6004
|
warnings.push(...inputWarnings);
|
|
@@ -6004,8 +6011,12 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6004
6011
|
include = [...include, key];
|
|
6005
6012
|
}
|
|
6006
6013
|
}
|
|
6014
|
+
function getOpenAIToolName(id) {
|
|
6015
|
+
var _a3;
|
|
6016
|
+
return (_a3 = tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && tool.id === id)) == null ? void 0 : _a3.name;
|
|
6017
|
+
}
|
|
6007
6018
|
function hasOpenAITool(id) {
|
|
6008
|
-
return (
|
|
6019
|
+
return getOpenAIToolName(id) != null;
|
|
6009
6020
|
}
|
|
6010
6021
|
const topLogprobs = typeof (openaiOptions == null ? void 0 : openaiOptions.logprobs) === "number" ? openaiOptions == null ? void 0 : openaiOptions.logprobs : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? TOP_LOGPROBS_MAX : void 0;
|
|
6011
6022
|
if (topLogprobs) {
|
|
@@ -6165,7 +6176,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6165
6176
|
};
|
|
6166
6177
|
}
|
|
6167
6178
|
async doGenerate(options) {
|
|
6168
|
-
var
|
|
6179
|
+
var _a2, _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, _D, _E;
|
|
6169
6180
|
const {
|
|
6170
6181
|
args: body,
|
|
6171
6182
|
warnings,
|
|
@@ -6207,7 +6218,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6207
6218
|
}
|
|
6208
6219
|
const content = [];
|
|
6209
6220
|
const logprobs = [];
|
|
6210
|
-
const functionTools = (_b = (
|
|
6221
|
+
const functionTools = (_b = (_a2 = options.tools) == null ? void 0 : _a2.filter(
|
|
6211
6222
|
(tool) => tool.type === "function"
|
|
6212
6223
|
)) != null ? _b : [];
|
|
6213
6224
|
let hasFunctionCall = false;
|
|
@@ -6659,7 +6670,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6659
6670
|
};
|
|
6660
6671
|
}
|
|
6661
6672
|
async doStream(options) {
|
|
6662
|
-
var
|
|
6673
|
+
var _a2, _b;
|
|
6663
6674
|
const {
|
|
6664
6675
|
args: body,
|
|
6665
6676
|
warnings,
|
|
@@ -6697,7 +6708,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6697
6708
|
});
|
|
6698
6709
|
const self = this;
|
|
6699
6710
|
const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
|
|
6700
|
-
const functionTools = (_b = (
|
|
6711
|
+
const functionTools = (_b = (_a2 = options.tools) == null ? void 0 : _a2.filter(
|
|
6701
6712
|
(tool) => tool.type === "function"
|
|
6702
6713
|
)) != null ? _b : [];
|
|
6703
6714
|
const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
|
|
@@ -6724,7 +6735,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6724
6735
|
controller.enqueue({ type: "stream-start", warnings });
|
|
6725
6736
|
},
|
|
6726
6737
|
transform(chunk, controller) {
|
|
6727
|
-
var
|
|
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;
|
|
6728
6739
|
if (options.includeRawChunks) {
|
|
6729
6740
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
6730
6741
|
}
|
|
@@ -6855,7 +6866,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6855
6866
|
ongoingToolCalls[value.output_index] = {
|
|
6856
6867
|
toolName,
|
|
6857
6868
|
toolCallId,
|
|
6858
|
-
toolSearchExecution: (
|
|
6869
|
+
toolSearchExecution: (_a3 = value.item.execution) != null ? _a3 : "server"
|
|
6859
6870
|
};
|
|
6860
6871
|
if (isHosted) {
|
|
6861
6872
|
controller.enqueue({
|
|
@@ -6968,14 +6979,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6968
6979
|
tools: functionTools
|
|
6969
6980
|
});
|
|
6970
6981
|
const enqueueUnexpandedToolCall = () => {
|
|
6971
|
-
var
|
|
6982
|
+
var _a4;
|
|
6972
6983
|
if (suppressInputStreaming) {
|
|
6973
6984
|
controller.enqueue({
|
|
6974
6985
|
type: "tool-input-start",
|
|
6975
6986
|
id: item.call_id,
|
|
6976
6987
|
toolName: item.name
|
|
6977
6988
|
});
|
|
6978
|
-
const bufferedInputDeltas = (
|
|
6989
|
+
const bufferedInputDeltas = (_a4 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a4 : [];
|
|
6979
6990
|
if (bufferedInputDeltas.length > 0) {
|
|
6980
6991
|
for (const delta of bufferedInputDeltas) {
|
|
6981
6992
|
controller.enqueue({
|
|
@@ -7646,7 +7657,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7646
7657
|
}
|
|
7647
7658
|
},
|
|
7648
7659
|
flush(controller) {
|
|
7649
|
-
var
|
|
7660
|
+
var _a3;
|
|
7650
7661
|
for (const toolCall of Object.values(ongoingToolCalls)) {
|
|
7651
7662
|
if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
|
|
7652
7663
|
continue;
|
|
@@ -7656,7 +7667,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7656
7667
|
id: toolCall.toolCallId,
|
|
7657
7668
|
toolName: toolCall.toolName
|
|
7658
7669
|
});
|
|
7659
|
-
for (const delta of (
|
|
7670
|
+
for (const delta of (_a3 = toolCall.bufferedInputDeltas) != null ? _a3 : []) {
|
|
7660
7671
|
controller.enqueue({
|
|
7661
7672
|
type: "tool-input-delta",
|
|
7662
7673
|
id: toolCall.toolCallId,
|
|
@@ -7761,7 +7772,7 @@ function isResponseOutputChunk(chunk) {
|
|
|
7761
7772
|
return !(chunk.type === "response.created" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
|
|
7762
7773
|
}
|
|
7763
7774
|
function mapWebSearchOutput(action) {
|
|
7764
|
-
var
|
|
7775
|
+
var _a2;
|
|
7765
7776
|
if (action == null) {
|
|
7766
7777
|
return {};
|
|
7767
7778
|
}
|
|
@@ -7770,7 +7781,7 @@ function mapWebSearchOutput(action) {
|
|
|
7770
7781
|
return {
|
|
7771
7782
|
action: {
|
|
7772
7783
|
type: "search",
|
|
7773
|
-
query: (
|
|
7784
|
+
query: (_a2 = action.query) != null ? _a2 : void 0,
|
|
7774
7785
|
...action.queries != null && { queries: action.queries }
|
|
7775
7786
|
},
|
|
7776
7787
|
// include sources when provided by the Responses API (behind include flag)
|