@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.mjs
CHANGED
|
@@ -32,10 +32,10 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
32
32
|
|
|
33
33
|
// src/openai-language-model-capabilities.ts
|
|
34
34
|
function getOpenAILanguageModelCapabilities(modelId) {
|
|
35
|
-
var
|
|
35
|
+
var _a2, _b, _c, _d, _e;
|
|
36
36
|
const oSeriesVersion = getOSeriesVersion(modelId);
|
|
37
37
|
const gptVersion = getGptVersion(modelId);
|
|
38
|
-
const isGptChatModel = (gptVersion == null ? void 0 : gptVersion.minor) == null && ((_b = (
|
|
38
|
+
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);
|
|
39
39
|
const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
|
|
40
40
|
const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
|
|
41
41
|
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
|
|
@@ -115,10 +115,10 @@ function createOpenAIStreamError({
|
|
|
115
115
|
requestBodyValues,
|
|
116
116
|
responseHeaders
|
|
117
117
|
}) {
|
|
118
|
-
var
|
|
118
|
+
var _a2;
|
|
119
119
|
const streamError = parseStreamError(frame);
|
|
120
120
|
return new APICallError({
|
|
121
|
-
message: (
|
|
121
|
+
message: (_a2 = streamError == null ? void 0 : streamError.message) != null ? _a2 : "OpenAI stream failed before any output was generated",
|
|
122
122
|
url,
|
|
123
123
|
requestBodyValues,
|
|
124
124
|
statusCode: streamError == null ? 500 : getStatusCode(streamError),
|
|
@@ -128,7 +128,7 @@ function createOpenAIStreamError({
|
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
function parseStreamError(frame) {
|
|
131
|
-
var
|
|
131
|
+
var _a2;
|
|
132
132
|
const value = asRecord(frame);
|
|
133
133
|
if (value == null) {
|
|
134
134
|
return void 0;
|
|
@@ -143,7 +143,7 @@ function parseStreamError(frame) {
|
|
|
143
143
|
frame
|
|
144
144
|
} : void 0;
|
|
145
145
|
}
|
|
146
|
-
const error = (
|
|
146
|
+
const error = (_a2 = asRecord(value.error)) != null ? _a2 : value;
|
|
147
147
|
return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
|
|
148
148
|
message: error.message,
|
|
149
149
|
code: getStringOrNumber(error.code),
|
|
@@ -191,7 +191,7 @@ function isHttpErrorStatusCode(value) {
|
|
|
191
191
|
|
|
192
192
|
// src/chat/convert-openai-chat-usage.ts
|
|
193
193
|
function convertOpenAIChatUsage(usage) {
|
|
194
|
-
var
|
|
194
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
195
195
|
if (usage == null) {
|
|
196
196
|
return {
|
|
197
197
|
inputTokens: {
|
|
@@ -208,7 +208,7 @@ function convertOpenAIChatUsage(usage) {
|
|
|
208
208
|
raw: void 0
|
|
209
209
|
};
|
|
210
210
|
}
|
|
211
|
-
const promptTokens = (
|
|
211
|
+
const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
|
|
212
212
|
const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
|
|
213
213
|
const cachedTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
|
|
214
214
|
const cacheWriteTokens = (_f = (_e = usage.prompt_tokens_details) == null ? void 0 : _e.cache_write_tokens) != null ? _f : void 0;
|
|
@@ -235,17 +235,19 @@ import {
|
|
|
235
235
|
} from "@ai-sdk/provider";
|
|
236
236
|
import { convertToBase64 } from "@ai-sdk/provider-utils";
|
|
237
237
|
function serializeToolCallArguments(input) {
|
|
238
|
-
return JSON.stringify(
|
|
238
|
+
return JSON.stringify(
|
|
239
|
+
typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
|
|
240
|
+
);
|
|
239
241
|
}
|
|
240
242
|
function getPromptCacheBreakpoint(providerOptions) {
|
|
241
|
-
var
|
|
242
|
-
return (
|
|
243
|
+
var _a2;
|
|
244
|
+
return (_a2 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
243
245
|
}
|
|
244
246
|
function convertToOpenAIChatMessages({
|
|
245
247
|
prompt,
|
|
246
248
|
systemMessageMode = "system"
|
|
247
249
|
}) {
|
|
248
|
-
var
|
|
250
|
+
var _a2, _b;
|
|
249
251
|
const messages = [];
|
|
250
252
|
const warnings = [];
|
|
251
253
|
for (const { role, content, providerOptions } of prompt) {
|
|
@@ -304,7 +306,7 @@ function convertToOpenAIChatMessages({
|
|
|
304
306
|
messages.push({
|
|
305
307
|
role: "user",
|
|
306
308
|
content: content.map((part, index) => {
|
|
307
|
-
var
|
|
309
|
+
var _a3, _b2, _c;
|
|
308
310
|
switch (part.type) {
|
|
309
311
|
case "text": {
|
|
310
312
|
const promptCacheBreakpoint = getPromptCacheBreakpoint(
|
|
@@ -329,7 +331,7 @@ function convertToOpenAIChatMessages({
|
|
|
329
331
|
image_url: {
|
|
330
332
|
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`,
|
|
331
333
|
// OpenAI specific extension: image detail
|
|
332
|
-
detail: (_b2 = (
|
|
334
|
+
detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3.openai) == null ? void 0 : _b2.imageDetail
|
|
333
335
|
},
|
|
334
336
|
...promptCacheBreakpoint != null && {
|
|
335
337
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
@@ -448,7 +450,7 @@ function convertToOpenAIChatMessages({
|
|
|
448
450
|
continue;
|
|
449
451
|
}
|
|
450
452
|
const output = toolResponse.output;
|
|
451
|
-
const promptCacheBreakpoint = (
|
|
453
|
+
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);
|
|
452
454
|
let contentValue;
|
|
453
455
|
switch (output.type) {
|
|
454
456
|
case "text":
|
|
@@ -890,13 +892,13 @@ var OpenAIChatLanguageModel = class {
|
|
|
890
892
|
toolChoice,
|
|
891
893
|
providerOptions
|
|
892
894
|
}) {
|
|
893
|
-
var
|
|
895
|
+
var _a2, _b, _c, _d, _e;
|
|
894
896
|
const warnings = [];
|
|
895
|
-
const openaiOptions = (
|
|
897
|
+
const openaiOptions = (_a2 = await parseProviderOptions({
|
|
896
898
|
provider: "openai",
|
|
897
899
|
providerOptions,
|
|
898
900
|
schema: openaiLanguageModelChatOptions
|
|
899
|
-
})) != null ?
|
|
901
|
+
})) != null ? _a2 : {};
|
|
900
902
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
901
903
|
const isReasoningModel = (_b = openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
|
|
902
904
|
if (topK != null) {
|
|
@@ -1058,7 +1060,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1058
1060
|
};
|
|
1059
1061
|
}
|
|
1060
1062
|
async doGenerate(options) {
|
|
1061
|
-
var
|
|
1063
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1062
1064
|
const { args: body, warnings } = await this.getArgs(options);
|
|
1063
1065
|
const {
|
|
1064
1066
|
responseHeaders,
|
|
@@ -1084,7 +1086,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1084
1086
|
if (text != null && text.length > 0) {
|
|
1085
1087
|
content.push({ type: "text", text });
|
|
1086
1088
|
}
|
|
1087
|
-
for (const toolCall of (
|
|
1089
|
+
for (const toolCall of (_a2 = choice.message.tool_calls) != null ? _a2 : []) {
|
|
1088
1090
|
content.push({
|
|
1089
1091
|
type: "tool-call",
|
|
1090
1092
|
toolCallId: (_b = toolCall.id) != null ? _b : generateId(),
|
|
@@ -1178,7 +1180,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1178
1180
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1179
1181
|
},
|
|
1180
1182
|
transform(chunk, controller) {
|
|
1181
|
-
var
|
|
1183
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1182
1184
|
if (options.includeRawChunks) {
|
|
1183
1185
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1184
1186
|
}
|
|
@@ -1205,7 +1207,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1205
1207
|
}
|
|
1206
1208
|
if (value.usage != null) {
|
|
1207
1209
|
usage = value.usage;
|
|
1208
|
-
if (((
|
|
1210
|
+
if (((_a2 = value.usage.completion_tokens_details) == null ? void 0 : _a2.accepted_prediction_tokens) != null) {
|
|
1209
1211
|
providerMetadata.openai.acceptedPredictionTokens = (_b = value.usage.completion_tokens_details) == null ? void 0 : _b.accepted_prediction_tokens;
|
|
1210
1212
|
}
|
|
1211
1213
|
if (((_c = value.usage.completion_tokens_details) == null ? void 0 : _c.rejected_prediction_tokens) != null) {
|
|
@@ -1312,7 +1314,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1312
1314
|
}
|
|
1313
1315
|
},
|
|
1314
1316
|
flush(controller) {
|
|
1315
|
-
var
|
|
1317
|
+
var _a2;
|
|
1316
1318
|
if (isActiveText) {
|
|
1317
1319
|
controller.enqueue({ type: "text-end", id: "0" });
|
|
1318
1320
|
}
|
|
@@ -1324,7 +1326,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1324
1326
|
});
|
|
1325
1327
|
controller.enqueue({
|
|
1326
1328
|
type: "tool-call",
|
|
1327
|
-
toolCallId: (
|
|
1329
|
+
toolCallId: (_a2 = toolCall.id) != null ? _a2 : generateId(),
|
|
1328
1330
|
toolName: toolCall.function.name,
|
|
1329
1331
|
input: toolCall.function.arguments
|
|
1330
1332
|
});
|
|
@@ -1367,7 +1369,7 @@ import {
|
|
|
1367
1369
|
|
|
1368
1370
|
// src/completion/convert-openai-completion-usage.ts
|
|
1369
1371
|
function convertOpenAICompletionUsage(usage) {
|
|
1370
|
-
var
|
|
1372
|
+
var _a2, _b, _c, _d;
|
|
1371
1373
|
if (usage == null) {
|
|
1372
1374
|
return {
|
|
1373
1375
|
inputTokens: {
|
|
@@ -1384,7 +1386,7 @@ function convertOpenAICompletionUsage(usage) {
|
|
|
1384
1386
|
raw: void 0
|
|
1385
1387
|
};
|
|
1386
1388
|
}
|
|
1387
|
-
const promptTokens = (
|
|
1389
|
+
const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
|
|
1388
1390
|
const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
|
|
1389
1391
|
return {
|
|
1390
1392
|
inputTokens: {
|
|
@@ -1710,7 +1712,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1710
1712
|
};
|
|
1711
1713
|
}
|
|
1712
1714
|
async doGenerate(options) {
|
|
1713
|
-
var
|
|
1715
|
+
var _a2;
|
|
1714
1716
|
const { args, warnings } = await this.getArgs(options);
|
|
1715
1717
|
const {
|
|
1716
1718
|
responseHeaders,
|
|
@@ -1740,7 +1742,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1740
1742
|
usage: convertOpenAICompletionUsage(response.usage),
|
|
1741
1743
|
finishReason: {
|
|
1742
1744
|
unified: mapOpenAIFinishReason2(choice.finish_reason),
|
|
1743
|
-
raw: (
|
|
1745
|
+
raw: (_a2 = choice.finish_reason) != null ? _a2 : void 0
|
|
1744
1746
|
},
|
|
1745
1747
|
request: { body: args },
|
|
1746
1748
|
response: {
|
|
@@ -1871,6 +1873,7 @@ import {
|
|
|
1871
1873
|
import {
|
|
1872
1874
|
combineHeaders as combineHeaders3,
|
|
1873
1875
|
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1876
|
+
EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL,
|
|
1874
1877
|
parseProviderOptions as parseProviderOptions3,
|
|
1875
1878
|
postJsonToApi as postJsonToApi3
|
|
1876
1879
|
} from "@ai-sdk/provider-utils";
|
|
@@ -1911,10 +1914,13 @@ var openaiTextEmbeddingResponseSchema = lazySchema6(
|
|
|
1911
1914
|
);
|
|
1912
1915
|
|
|
1913
1916
|
// src/embedding/openai-embedding-model.ts
|
|
1917
|
+
var _a;
|
|
1918
|
+
_a = EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL;
|
|
1914
1919
|
var OpenAIEmbeddingModel = class {
|
|
1915
1920
|
constructor(modelId, config) {
|
|
1916
1921
|
this.specificationVersion = "v3";
|
|
1917
1922
|
this.maxEmbeddingsPerCall = 2048;
|
|
1923
|
+
this[_a] = 3e5;
|
|
1918
1924
|
this.supportsParallelCalls = true;
|
|
1919
1925
|
this.modelId = modelId;
|
|
1920
1926
|
this.config = config;
|
|
@@ -1928,7 +1934,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1928
1934
|
abortSignal,
|
|
1929
1935
|
providerOptions
|
|
1930
1936
|
}) {
|
|
1931
|
-
var
|
|
1937
|
+
var _a2;
|
|
1932
1938
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1933
1939
|
throw new TooManyEmbeddingValuesForCallError({
|
|
1934
1940
|
provider: this.provider,
|
|
@@ -1937,11 +1943,11 @@ var OpenAIEmbeddingModel = class {
|
|
|
1937
1943
|
values
|
|
1938
1944
|
});
|
|
1939
1945
|
}
|
|
1940
|
-
const openaiOptions = (
|
|
1946
|
+
const openaiOptions = (_a2 = await parseProviderOptions3({
|
|
1941
1947
|
provider: "openai",
|
|
1942
1948
|
providerOptions,
|
|
1943
1949
|
schema: openaiEmbeddingModelOptions
|
|
1944
|
-
})) != null ?
|
|
1950
|
+
})) != null ? _a2 : {};
|
|
1945
1951
|
const {
|
|
1946
1952
|
responseHeaders,
|
|
1947
1953
|
value: response,
|
|
@@ -2039,8 +2045,8 @@ function hasDefaultResponseFormat(modelId) {
|
|
|
2039
2045
|
);
|
|
2040
2046
|
}
|
|
2041
2047
|
function getMaxImagesPerCall(modelId) {
|
|
2042
|
-
var
|
|
2043
|
-
return (
|
|
2048
|
+
var _a2;
|
|
2049
|
+
return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
|
|
2044
2050
|
}
|
|
2045
2051
|
var baseImageModelOptionsObject = z9.object({
|
|
2046
2052
|
/**
|
|
@@ -2127,7 +2133,7 @@ var OpenAIImageModel = class {
|
|
|
2127
2133
|
headers,
|
|
2128
2134
|
abortSignal
|
|
2129
2135
|
}) {
|
|
2130
|
-
var
|
|
2136
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2131
2137
|
const warnings = [];
|
|
2132
2138
|
if (aspectRatio != null) {
|
|
2133
2139
|
warnings.push({
|
|
@@ -2139,7 +2145,7 @@ var OpenAIImageModel = class {
|
|
|
2139
2145
|
if (seed != null) {
|
|
2140
2146
|
warnings.push({ type: "unsupported", feature: "seed" });
|
|
2141
2147
|
}
|
|
2142
|
-
const currentDate = (_c = (_b = (
|
|
2148
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2143
2149
|
if (files != null) {
|
|
2144
2150
|
const openaiOptions2 = (_d = await parseProviderOptions4({
|
|
2145
2151
|
provider: "openai",
|
|
@@ -2202,10 +2208,10 @@ var OpenAIImageModel = class {
|
|
|
2202
2208
|
providerMetadata: {
|
|
2203
2209
|
openai: {
|
|
2204
2210
|
images: response2.data.map((item, index) => {
|
|
2205
|
-
var
|
|
2211
|
+
var _a3, _b2, _c2, _d2, _e2, _f2;
|
|
2206
2212
|
return {
|
|
2207
2213
|
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
|
|
2208
|
-
created: (
|
|
2214
|
+
created: (_a3 = response2.created) != null ? _a3 : void 0,
|
|
2209
2215
|
size: (_b2 = response2.size) != null ? _b2 : void 0,
|
|
2210
2216
|
quality: (_c2 = response2.quality) != null ? _c2 : void 0,
|
|
2211
2217
|
background: (_d2 = response2.background) != null ? _d2 : void 0,
|
|
@@ -2269,10 +2275,10 @@ var OpenAIImageModel = class {
|
|
|
2269
2275
|
providerMetadata: {
|
|
2270
2276
|
openai: {
|
|
2271
2277
|
images: response.data.map((item, index) => {
|
|
2272
|
-
var
|
|
2278
|
+
var _a3, _b2, _c2, _d2, _e2, _f2;
|
|
2273
2279
|
return {
|
|
2274
2280
|
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
|
|
2275
|
-
created: (
|
|
2281
|
+
created: (_a3 = response.created) != null ? _a3 : void 0,
|
|
2276
2282
|
size: (_b2 = response.size) != null ? _b2 : void 0,
|
|
2277
2283
|
quality: (_c2 = response.quality) != null ? _c2 : void 0,
|
|
2278
2284
|
background: (_d2 = response.background) != null ? _d2 : void 0,
|
|
@@ -2515,8 +2521,8 @@ var OpenAITranscriptionModel = class {
|
|
|
2515
2521
|
};
|
|
2516
2522
|
}
|
|
2517
2523
|
async doGenerate(options) {
|
|
2518
|
-
var
|
|
2519
|
-
const currentDate = (_c = (_b = (
|
|
2524
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
2525
|
+
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
2526
|
const { formData, warnings } = await this.getArgs(options);
|
|
2521
2527
|
const {
|
|
2522
2528
|
value: response,
|
|
@@ -2650,8 +2656,8 @@ var OpenAISpeechModel = class {
|
|
|
2650
2656
|
};
|
|
2651
2657
|
}
|
|
2652
2658
|
async doGenerate(options) {
|
|
2653
|
-
var
|
|
2654
|
-
const currentDate = (_c = (_b = (
|
|
2659
|
+
var _a2, _b, _c;
|
|
2660
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2655
2661
|
const { requestBody, warnings } = await this.getArgs(options);
|
|
2656
2662
|
const {
|
|
2657
2663
|
value: audio,
|
|
@@ -2701,7 +2707,7 @@ import {
|
|
|
2701
2707
|
|
|
2702
2708
|
// src/responses/convert-openai-responses-usage.ts
|
|
2703
2709
|
function convertOpenAIResponsesUsage(usage) {
|
|
2704
|
-
var
|
|
2710
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
2705
2711
|
if (usage == null) {
|
|
2706
2712
|
return {
|
|
2707
2713
|
inputTokens: {
|
|
@@ -2720,7 +2726,7 @@ function convertOpenAIResponsesUsage(usage) {
|
|
|
2720
2726
|
}
|
|
2721
2727
|
const inputTokens = usage.input_tokens;
|
|
2722
2728
|
const outputTokens = usage.output_tokens;
|
|
2723
|
-
const cachedTokens = (_b = (
|
|
2729
|
+
const cachedTokens = (_b = (_a2 = usage.input_tokens_details) == null ? void 0 : _a2.cached_tokens) != null ? _b : 0;
|
|
2724
2730
|
const cacheWriteTokens = (_d = (_c = usage.input_tokens_details) == null ? void 0 : _c.cache_write_tokens) != null ? _d : void 0;
|
|
2725
2731
|
const reasoningTokens = (_f = (_e = usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
|
|
2726
2732
|
return {
|
|
@@ -2977,8 +2983,8 @@ function getParallelToolCallMetadata({
|
|
|
2977
2983
|
providerOptions,
|
|
2978
2984
|
providerOptionsName
|
|
2979
2985
|
}) {
|
|
2980
|
-
var
|
|
2981
|
-
const metadata = (
|
|
2986
|
+
var _a2;
|
|
2987
|
+
const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
|
|
2982
2988
|
if (!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) {
|
|
2983
2989
|
return void 0;
|
|
2984
2990
|
}
|
|
@@ -3053,19 +3059,19 @@ async function convertFunctionToolResultOutput({
|
|
|
3053
3059
|
providerOptionsName,
|
|
3054
3060
|
warnings
|
|
3055
3061
|
}) {
|
|
3056
|
-
var
|
|
3062
|
+
var _a2;
|
|
3057
3063
|
switch (output.type) {
|
|
3058
3064
|
case "text":
|
|
3059
3065
|
case "error-text":
|
|
3060
3066
|
return output.value;
|
|
3061
3067
|
case "execution-denied":
|
|
3062
|
-
return (
|
|
3068
|
+
return (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
|
|
3063
3069
|
case "json":
|
|
3064
3070
|
case "error-json":
|
|
3065
3071
|
return JSON.stringify(output.value);
|
|
3066
3072
|
case "content":
|
|
3067
3073
|
return output.value.map((item) => {
|
|
3068
|
-
var
|
|
3074
|
+
var _a3, _b, _c, _d, _e;
|
|
3069
3075
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
3070
3076
|
item.providerOptions,
|
|
3071
3077
|
providerOptionsName
|
|
@@ -3084,7 +3090,7 @@ async function convertFunctionToolResultOutput({
|
|
|
3084
3090
|
return {
|
|
3085
3091
|
type: "input_image",
|
|
3086
3092
|
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3087
|
-
detail: (_b = (
|
|
3093
|
+
detail: (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail,
|
|
3088
3094
|
...promptCacheBreakpoint != null && {
|
|
3089
3095
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3090
3096
|
}
|
|
@@ -3188,8 +3194,8 @@ function collectCompleteParallelToolResultGroups({
|
|
|
3188
3194
|
return completeGroups;
|
|
3189
3195
|
}
|
|
3190
3196
|
function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
|
|
3191
|
-
var
|
|
3192
|
-
return (
|
|
3197
|
+
var _a2;
|
|
3198
|
+
return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
3193
3199
|
}
|
|
3194
3200
|
function isFileId(data, prefixes) {
|
|
3195
3201
|
if (!prefixes) return false;
|
|
@@ -3208,9 +3214,10 @@ async function convertToOpenAIResponsesInput({
|
|
|
3208
3214
|
hasLocalShellTool = false,
|
|
3209
3215
|
hasShellTool = false,
|
|
3210
3216
|
hasApplyPatchTool = false,
|
|
3217
|
+
toolSearchToolName,
|
|
3211
3218
|
customProviderToolNames
|
|
3212
3219
|
}) {
|
|
3213
|
-
var
|
|
3220
|
+
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;
|
|
3214
3221
|
let input = [];
|
|
3215
3222
|
const warnings = [];
|
|
3216
3223
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
@@ -3278,7 +3285,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3278
3285
|
input.push({
|
|
3279
3286
|
role: "user",
|
|
3280
3287
|
content: content.map((part, index) => {
|
|
3281
|
-
var
|
|
3288
|
+
var _a3, _b2, _c2;
|
|
3282
3289
|
switch (part.type) {
|
|
3283
3290
|
case "text": {
|
|
3284
3291
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
@@ -3305,7 +3312,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3305
3312
|
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
3306
3313
|
image_url: `data:${mediaType};base64,${convertToBase642(part.data)}`
|
|
3307
3314
|
},
|
|
3308
|
-
detail: (_b2 = (
|
|
3315
|
+
detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
3309
3316
|
...promptCacheBreakpoint != null && {
|
|
3310
3317
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3311
3318
|
}
|
|
@@ -3346,7 +3353,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3346
3353
|
for (const part of content) {
|
|
3347
3354
|
switch (part.type) {
|
|
3348
3355
|
case "text": {
|
|
3349
|
-
const providerOpts = (
|
|
3356
|
+
const providerOpts = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName];
|
|
3350
3357
|
const id = providerOpts == null ? void 0 : providerOpts.itemId;
|
|
3351
3358
|
const phase = providerOpts == null ? void 0 : providerOpts.phase;
|
|
3352
3359
|
if (hasConversation && id != null) {
|
|
@@ -3401,7 +3408,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3401
3408
|
const resolvedToolName = toolNameMapping.toProviderToolName(
|
|
3402
3409
|
part.toolName
|
|
3403
3410
|
);
|
|
3404
|
-
if (
|
|
3411
|
+
if (part.toolName === toolSearchToolName) {
|
|
3405
3412
|
if (store && id != null) {
|
|
3406
3413
|
input.push({ type: "item_reference", id });
|
|
3407
3414
|
break;
|
|
@@ -3522,7 +3529,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3522
3529
|
const resolvedResultToolName = toolNameMapping.toProviderToolName(
|
|
3523
3530
|
part.toolName
|
|
3524
3531
|
);
|
|
3525
|
-
if (
|
|
3532
|
+
if (part.toolName === toolSearchToolName) {
|
|
3526
3533
|
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;
|
|
3527
3534
|
if (store) {
|
|
3528
3535
|
input.push({ type: "item_reference", id: itemId });
|
|
@@ -3720,7 +3727,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3720
3727
|
const resolvedToolName = toolNameMapping.toProviderToolName(
|
|
3721
3728
|
part.toolName
|
|
3722
3729
|
);
|
|
3723
|
-
if (
|
|
3730
|
+
if (part.toolName === toolSearchToolName && output.type === "json") {
|
|
3724
3731
|
const parsedOutput = await validateTypes({
|
|
3725
3732
|
value: output.value,
|
|
3726
3733
|
schema: toolSearchOutputSchema
|
|
@@ -3794,7 +3801,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3794
3801
|
break;
|
|
3795
3802
|
case "content":
|
|
3796
3803
|
outputValue = output.value.map((item) => {
|
|
3797
|
-
var
|
|
3804
|
+
var _a3, _b2, _c2, _d2, _e2;
|
|
3798
3805
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
3799
3806
|
item.providerOptions,
|
|
3800
3807
|
providerOptionsName
|
|
@@ -3812,7 +3819,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3812
3819
|
return {
|
|
3813
3820
|
type: "input_image",
|
|
3814
3821
|
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3815
|
-
detail: (_b2 = (
|
|
3822
|
+
detail: (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
3816
3823
|
...promptCacheBreakpoint != null && {
|
|
3817
3824
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3818
3825
|
}
|
|
@@ -5507,7 +5514,7 @@ async function prepareResponsesTools({
|
|
|
5507
5514
|
toolNameMapping,
|
|
5508
5515
|
customProviderToolNames
|
|
5509
5516
|
}) {
|
|
5510
|
-
var
|
|
5517
|
+
var _a2, _b, _c, _d;
|
|
5511
5518
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
5512
5519
|
const toolWarnings = [];
|
|
5513
5520
|
if (tools == null) {
|
|
@@ -5533,7 +5540,7 @@ async function prepareResponsesTools({
|
|
|
5533
5540
|
for (const tool of tools) {
|
|
5534
5541
|
switch (tool.type) {
|
|
5535
5542
|
case "function": {
|
|
5536
|
-
const openaiOptions = (
|
|
5543
|
+
const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
|
|
5537
5544
|
const openaiFunctionTool = prepareFunctionTool({
|
|
5538
5545
|
tool,
|
|
5539
5546
|
options: openaiOptions
|
|
@@ -5950,13 +5957,13 @@ function mapShellSkills(skills) {
|
|
|
5950
5957
|
|
|
5951
5958
|
// src/responses/openai-responses-language-model.ts
|
|
5952
5959
|
function extractApprovalRequestIdToToolCallIdMapping(prompt) {
|
|
5953
|
-
var
|
|
5960
|
+
var _a2, _b;
|
|
5954
5961
|
const mapping = {};
|
|
5955
5962
|
for (const message of prompt) {
|
|
5956
5963
|
if (message.role !== "assistant") continue;
|
|
5957
5964
|
for (const part of message.content) {
|
|
5958
5965
|
if (part.type !== "tool-call") continue;
|
|
5959
|
-
const approvalRequestId = (_b = (
|
|
5966
|
+
const approvalRequestId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.approvalRequestId;
|
|
5960
5967
|
if (approvalRequestId != null) {
|
|
5961
5968
|
mapping[approvalRequestId] = part.toolCallId;
|
|
5962
5969
|
}
|
|
@@ -5992,7 +5999,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5992
5999
|
toolChoice,
|
|
5993
6000
|
responseFormat
|
|
5994
6001
|
}) {
|
|
5995
|
-
var
|
|
6002
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
5996
6003
|
const warnings = [];
|
|
5997
6004
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
5998
6005
|
if (topK != null) {
|
|
@@ -6023,7 +6030,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6023
6030
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
6024
6031
|
});
|
|
6025
6032
|
}
|
|
6026
|
-
const isReasoningModel = (
|
|
6033
|
+
const isReasoningModel = (_a2 = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _a2 : modelCapabilities.isReasoningModel;
|
|
6027
6034
|
if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
|
|
6028
6035
|
warnings.push({
|
|
6029
6036
|
type: "unsupported",
|
|
@@ -6072,6 +6079,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6072
6079
|
hasLocalShellTool: hasOpenAITool("openai.local_shell"),
|
|
6073
6080
|
hasShellTool: hasOpenAITool("openai.shell"),
|
|
6074
6081
|
hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
|
|
6082
|
+
toolSearchToolName: getOpenAIToolName("openai.tool_search"),
|
|
6075
6083
|
customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
|
|
6076
6084
|
});
|
|
6077
6085
|
warnings.push(...inputWarnings);
|
|
@@ -6084,8 +6092,12 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6084
6092
|
include = [...include, key];
|
|
6085
6093
|
}
|
|
6086
6094
|
}
|
|
6095
|
+
function getOpenAIToolName(id) {
|
|
6096
|
+
var _a3;
|
|
6097
|
+
return (_a3 = tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && tool.id === id)) == null ? void 0 : _a3.name;
|
|
6098
|
+
}
|
|
6087
6099
|
function hasOpenAITool(id) {
|
|
6088
|
-
return (
|
|
6100
|
+
return getOpenAIToolName(id) != null;
|
|
6089
6101
|
}
|
|
6090
6102
|
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;
|
|
6091
6103
|
if (topLogprobs) {
|
|
@@ -6245,7 +6257,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6245
6257
|
};
|
|
6246
6258
|
}
|
|
6247
6259
|
async doGenerate(options) {
|
|
6248
|
-
var
|
|
6260
|
+
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;
|
|
6249
6261
|
const {
|
|
6250
6262
|
args: body,
|
|
6251
6263
|
warnings,
|
|
@@ -6287,7 +6299,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6287
6299
|
}
|
|
6288
6300
|
const content = [];
|
|
6289
6301
|
const logprobs = [];
|
|
6290
|
-
const functionTools = (_b = (
|
|
6302
|
+
const functionTools = (_b = (_a2 = options.tools) == null ? void 0 : _a2.filter(
|
|
6291
6303
|
(tool) => tool.type === "function"
|
|
6292
6304
|
)) != null ? _b : [];
|
|
6293
6305
|
let hasFunctionCall = false;
|
|
@@ -6739,7 +6751,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6739
6751
|
};
|
|
6740
6752
|
}
|
|
6741
6753
|
async doStream(options) {
|
|
6742
|
-
var
|
|
6754
|
+
var _a2, _b;
|
|
6743
6755
|
const {
|
|
6744
6756
|
args: body,
|
|
6745
6757
|
warnings,
|
|
@@ -6777,7 +6789,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6777
6789
|
});
|
|
6778
6790
|
const self = this;
|
|
6779
6791
|
const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
|
|
6780
|
-
const functionTools = (_b = (
|
|
6792
|
+
const functionTools = (_b = (_a2 = options.tools) == null ? void 0 : _a2.filter(
|
|
6781
6793
|
(tool) => tool.type === "function"
|
|
6782
6794
|
)) != null ? _b : [];
|
|
6783
6795
|
const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
|
|
@@ -6804,7 +6816,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6804
6816
|
controller.enqueue({ type: "stream-start", warnings });
|
|
6805
6817
|
},
|
|
6806
6818
|
transform(chunk, controller) {
|
|
6807
|
-
var
|
|
6819
|
+
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;
|
|
6808
6820
|
if (options.includeRawChunks) {
|
|
6809
6821
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
6810
6822
|
}
|
|
@@ -6935,7 +6947,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6935
6947
|
ongoingToolCalls[value.output_index] = {
|
|
6936
6948
|
toolName,
|
|
6937
6949
|
toolCallId,
|
|
6938
|
-
toolSearchExecution: (
|
|
6950
|
+
toolSearchExecution: (_a3 = value.item.execution) != null ? _a3 : "server"
|
|
6939
6951
|
};
|
|
6940
6952
|
if (isHosted) {
|
|
6941
6953
|
controller.enqueue({
|
|
@@ -7048,14 +7060,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7048
7060
|
tools: functionTools
|
|
7049
7061
|
});
|
|
7050
7062
|
const enqueueUnexpandedToolCall = () => {
|
|
7051
|
-
var
|
|
7063
|
+
var _a4;
|
|
7052
7064
|
if (suppressInputStreaming) {
|
|
7053
7065
|
controller.enqueue({
|
|
7054
7066
|
type: "tool-input-start",
|
|
7055
7067
|
id: item.call_id,
|
|
7056
7068
|
toolName: item.name
|
|
7057
7069
|
});
|
|
7058
|
-
const bufferedInputDeltas = (
|
|
7070
|
+
const bufferedInputDeltas = (_a4 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a4 : [];
|
|
7059
7071
|
if (bufferedInputDeltas.length > 0) {
|
|
7060
7072
|
for (const delta of bufferedInputDeltas) {
|
|
7061
7073
|
controller.enqueue({
|
|
@@ -7726,7 +7738,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7726
7738
|
}
|
|
7727
7739
|
},
|
|
7728
7740
|
flush(controller) {
|
|
7729
|
-
var
|
|
7741
|
+
var _a3;
|
|
7730
7742
|
for (const toolCall of Object.values(ongoingToolCalls)) {
|
|
7731
7743
|
if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
|
|
7732
7744
|
continue;
|
|
@@ -7736,7 +7748,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7736
7748
|
id: toolCall.toolCallId,
|
|
7737
7749
|
toolName: toolCall.toolName
|
|
7738
7750
|
});
|
|
7739
|
-
for (const delta of (
|
|
7751
|
+
for (const delta of (_a3 = toolCall.bufferedInputDeltas) != null ? _a3 : []) {
|
|
7740
7752
|
controller.enqueue({
|
|
7741
7753
|
type: "tool-input-delta",
|
|
7742
7754
|
id: toolCall.toolCallId,
|
|
@@ -7841,7 +7853,7 @@ function isResponseOutputChunk(chunk) {
|
|
|
7841
7853
|
return !(chunk.type === "response.created" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
|
|
7842
7854
|
}
|
|
7843
7855
|
function mapWebSearchOutput(action) {
|
|
7844
|
-
var
|
|
7856
|
+
var _a2;
|
|
7845
7857
|
if (action == null) {
|
|
7846
7858
|
return {};
|
|
7847
7859
|
}
|
|
@@ -7850,7 +7862,7 @@ function mapWebSearchOutput(action) {
|
|
|
7850
7862
|
return {
|
|
7851
7863
|
action: {
|
|
7852
7864
|
type: "search",
|
|
7853
|
-
query: (
|
|
7865
|
+
query: (_a2 = action.query) != null ? _a2 : void 0,
|
|
7854
7866
|
...action.queries != null && { queries: action.queries }
|
|
7855
7867
|
},
|
|
7856
7868
|
// include sources when provided by the Responses API (behind include flag)
|