@ai-sdk/openai 3.0.101 → 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 +21 -0
- package/dist/index.d.mts +29 -12
- package/dist/index.d.ts +29 -12
- package/dist/index.js +190 -119
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +191 -119
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +31 -13
- package/dist/internal/index.d.ts +31 -13
- package/dist/internal/index.js +186 -115
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +187 -115
- 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-api.ts +113 -40
- package/src/responses/openai-responses-language-model.ts +17 -10
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
|
}
|
|
@@ -3886,6 +3892,22 @@ var jsonValueSchema = import_v418.z.lazy(
|
|
|
3886
3892
|
import_v418.z.record(import_v418.z.string(), jsonValueSchema.optional())
|
|
3887
3893
|
])
|
|
3888
3894
|
);
|
|
3895
|
+
function isRecord(value) {
|
|
3896
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
3897
|
+
}
|
|
3898
|
+
var openaiResponsesLocalShellCallSchema = import_v418.z.object({
|
|
3899
|
+
type: import_v418.z.literal("local_shell_call"),
|
|
3900
|
+
id: import_v418.z.string(),
|
|
3901
|
+
call_id: import_v418.z.string(),
|
|
3902
|
+
action: import_v418.z.object({
|
|
3903
|
+
type: import_v418.z.literal("exec"),
|
|
3904
|
+
command: import_v418.z.array(import_v418.z.string()),
|
|
3905
|
+
timeout_ms: import_v418.z.number().optional(),
|
|
3906
|
+
user: import_v418.z.string().optional(),
|
|
3907
|
+
working_directory: import_v418.z.string().optional(),
|
|
3908
|
+
env: import_v418.z.record(import_v418.z.string(), import_v418.z.string()).optional()
|
|
3909
|
+
})
|
|
3910
|
+
});
|
|
3889
3911
|
var openaiResponsesNestedErrorChunkSchema = import_v418.z.object({
|
|
3890
3912
|
type: import_v418.z.literal("error"),
|
|
3891
3913
|
sequence_number: import_v418.z.number(),
|
|
@@ -3903,6 +3925,60 @@ var openaiResponsesErrorChunkSchema = import_v418.z.object({
|
|
|
3903
3925
|
message: import_v418.z.string(),
|
|
3904
3926
|
param: import_v418.z.string().nullish()
|
|
3905
3927
|
});
|
|
3928
|
+
var openaiResponsesModeledChunkTypes = /* @__PURE__ */ new Set([
|
|
3929
|
+
"error",
|
|
3930
|
+
"response.apply_patch_call_operation_diff.delta",
|
|
3931
|
+
"response.apply_patch_call_operation_diff.done",
|
|
3932
|
+
"response.code_interpreter_call_code.delta",
|
|
3933
|
+
"response.code_interpreter_call_code.done",
|
|
3934
|
+
"response.completed",
|
|
3935
|
+
"response.created",
|
|
3936
|
+
"response.custom_tool_call_input.delta",
|
|
3937
|
+
"response.failed",
|
|
3938
|
+
"response.function_call_arguments.delta",
|
|
3939
|
+
"response.function_call_arguments.done",
|
|
3940
|
+
"response.image_generation_call.partial_image",
|
|
3941
|
+
"response.incomplete",
|
|
3942
|
+
"response.output_item.added",
|
|
3943
|
+
"response.output_item.done",
|
|
3944
|
+
"response.output_text.annotation.added",
|
|
3945
|
+
"response.output_text.delta",
|
|
3946
|
+
"response.reasoning_summary_part.added",
|
|
3947
|
+
"response.reasoning_summary_part.done",
|
|
3948
|
+
"response.reasoning_summary_text.delta"
|
|
3949
|
+
]);
|
|
3950
|
+
var openaiResponsesModeledOutputItemTypes = /* @__PURE__ */ new Set([
|
|
3951
|
+
"apply_patch_call",
|
|
3952
|
+
"code_interpreter_call",
|
|
3953
|
+
"computer_call",
|
|
3954
|
+
"custom_tool_call",
|
|
3955
|
+
"file_search_call",
|
|
3956
|
+
"function_call",
|
|
3957
|
+
"image_generation_call",
|
|
3958
|
+
"local_shell_call",
|
|
3959
|
+
"mcp_approval_request",
|
|
3960
|
+
"mcp_call",
|
|
3961
|
+
"mcp_list_tools",
|
|
3962
|
+
"message",
|
|
3963
|
+
"reasoning",
|
|
3964
|
+
"shell_call",
|
|
3965
|
+
"shell_call_output",
|
|
3966
|
+
"tool_search_call",
|
|
3967
|
+
"tool_search_output",
|
|
3968
|
+
"web_search_call"
|
|
3969
|
+
]);
|
|
3970
|
+
function isModeledOpenAIResponsesChunk(value) {
|
|
3971
|
+
if (typeof value.type !== "string" || !openaiResponsesModeledChunkTypes.has(value.type)) {
|
|
3972
|
+
return false;
|
|
3973
|
+
}
|
|
3974
|
+
if (value.type !== "response.output_item.added" && value.type !== "response.output_item.done") {
|
|
3975
|
+
return true;
|
|
3976
|
+
}
|
|
3977
|
+
if (!isRecord(value.item) || typeof value.item.type !== "string") {
|
|
3978
|
+
return true;
|
|
3979
|
+
}
|
|
3980
|
+
return openaiResponsesModeledOutputItemTypes.has(value.item.type);
|
|
3981
|
+
}
|
|
3906
3982
|
var openaiResponsesChunkSchema = (0, import_provider_utils26.lazySchema)(
|
|
3907
3983
|
() => (0, import_provider_utils26.zodSchema)(
|
|
3908
3984
|
import_v418.z.union([
|
|
@@ -4021,6 +4097,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils26.lazySchema)(
|
|
|
4021
4097
|
type: import_v418.z.literal("file_search_call"),
|
|
4022
4098
|
id: import_v418.z.string()
|
|
4023
4099
|
}),
|
|
4100
|
+
openaiResponsesLocalShellCallSchema,
|
|
4024
4101
|
import_v418.z.object({
|
|
4025
4102
|
type: import_v418.z.literal("image_generation_call"),
|
|
4026
4103
|
id: import_v418.z.string()
|
|
@@ -4219,19 +4296,7 @@ var openaiResponsesChunkSchema = (0, import_provider_utils26.lazySchema)(
|
|
|
4219
4296
|
})
|
|
4220
4297
|
).nullish()
|
|
4221
4298
|
}),
|
|
4222
|
-
|
|
4223
|
-
type: import_v418.z.literal("local_shell_call"),
|
|
4224
|
-
id: import_v418.z.string(),
|
|
4225
|
-
call_id: import_v418.z.string(),
|
|
4226
|
-
action: import_v418.z.object({
|
|
4227
|
-
type: import_v418.z.literal("exec"),
|
|
4228
|
-
command: import_v418.z.array(import_v418.z.string()),
|
|
4229
|
-
timeout_ms: import_v418.z.number().optional(),
|
|
4230
|
-
user: import_v418.z.string().optional(),
|
|
4231
|
-
working_directory: import_v418.z.string().optional(),
|
|
4232
|
-
env: import_v418.z.record(import_v418.z.string(), import_v418.z.string()).optional()
|
|
4233
|
-
})
|
|
4234
|
-
}),
|
|
4299
|
+
openaiResponsesLocalShellCallSchema,
|
|
4235
4300
|
import_v418.z.object({
|
|
4236
4301
|
type: import_v418.z.literal("computer_call"),
|
|
4237
4302
|
id: import_v418.z.string(),
|
|
@@ -4358,6 +4423,14 @@ var openaiResponsesChunkSchema = (0, import_provider_utils26.lazySchema)(
|
|
|
4358
4423
|
output_index: import_v418.z.number(),
|
|
4359
4424
|
delta: import_v418.z.string()
|
|
4360
4425
|
}),
|
|
4426
|
+
import_v418.z.object({
|
|
4427
|
+
// `name` is documented as required but omitted from live API events:
|
|
4428
|
+
// https://github.com/openai/openai-openapi/issues/545
|
|
4429
|
+
type: import_v418.z.literal("response.function_call_arguments.done"),
|
|
4430
|
+
item_id: import_v418.z.string(),
|
|
4431
|
+
output_index: import_v418.z.number(),
|
|
4432
|
+
arguments: import_v418.z.string()
|
|
4433
|
+
}),
|
|
4361
4434
|
import_v418.z.object({
|
|
4362
4435
|
type: import_v418.z.literal("response.custom_tool_call_input.delta"),
|
|
4363
4436
|
item_id: import_v418.z.string(),
|
|
@@ -4444,7 +4517,9 @@ var openaiResponsesChunkSchema = (0, import_provider_utils26.lazySchema)(
|
|
|
4444
4517
|
}),
|
|
4445
4518
|
openaiResponsesNestedErrorChunkSchema,
|
|
4446
4519
|
openaiResponsesErrorChunkSchema,
|
|
4447
|
-
import_v418.z.object({ type: import_v418.z.string() }).loose().
|
|
4520
|
+
import_v418.z.object({ type: import_v418.z.string() }).loose().refine((value) => !isModeledOpenAIResponsesChunk(value), {
|
|
4521
|
+
message: "Known response chunk failed schema validation"
|
|
4522
|
+
}).transform((value) => ({
|
|
4448
4523
|
type: "unknown_chunk",
|
|
4449
4524
|
message: value.type
|
|
4450
4525
|
}))
|
|
@@ -4584,19 +4659,7 @@ var openaiResponsesResponseSchema = (0, import_provider_utils26.lazySchema)(
|
|
|
4584
4659
|
id: import_v418.z.string(),
|
|
4585
4660
|
result: import_v418.z.string()
|
|
4586
4661
|
}),
|
|
4587
|
-
|
|
4588
|
-
type: import_v418.z.literal("local_shell_call"),
|
|
4589
|
-
id: import_v418.z.string(),
|
|
4590
|
-
call_id: import_v418.z.string(),
|
|
4591
|
-
action: import_v418.z.object({
|
|
4592
|
-
type: import_v418.z.literal("exec"),
|
|
4593
|
-
command: import_v418.z.array(import_v418.z.string()),
|
|
4594
|
-
timeout_ms: import_v418.z.number().optional(),
|
|
4595
|
-
user: import_v418.z.string().optional(),
|
|
4596
|
-
working_directory: import_v418.z.string().optional(),
|
|
4597
|
-
env: import_v418.z.record(import_v418.z.string(), import_v418.z.string()).optional()
|
|
4598
|
-
})
|
|
4599
|
-
}),
|
|
4662
|
+
openaiResponsesLocalShellCallSchema,
|
|
4600
4663
|
import_v418.z.object({
|
|
4601
4664
|
type: import_v418.z.literal("function_call"),
|
|
4602
4665
|
call_id: import_v418.z.string(),
|
|
@@ -5370,7 +5433,7 @@ async function prepareResponsesTools({
|
|
|
5370
5433
|
toolNameMapping,
|
|
5371
5434
|
customProviderToolNames
|
|
5372
5435
|
}) {
|
|
5373
|
-
var
|
|
5436
|
+
var _a2, _b, _c, _d;
|
|
5374
5437
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
5375
5438
|
const toolWarnings = [];
|
|
5376
5439
|
if (tools == null) {
|
|
@@ -5396,7 +5459,7 @@ async function prepareResponsesTools({
|
|
|
5396
5459
|
for (const tool of tools) {
|
|
5397
5460
|
switch (tool.type) {
|
|
5398
5461
|
case "function": {
|
|
5399
|
-
const openaiOptions = (
|
|
5462
|
+
const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
|
|
5400
5463
|
const openaiFunctionTool = prepareFunctionTool({
|
|
5401
5464
|
tool,
|
|
5402
5465
|
options: openaiOptions
|
|
@@ -5813,13 +5876,13 @@ function mapShellSkills(skills) {
|
|
|
5813
5876
|
|
|
5814
5877
|
// src/responses/openai-responses-language-model.ts
|
|
5815
5878
|
function extractApprovalRequestIdToToolCallIdMapping(prompt) {
|
|
5816
|
-
var
|
|
5879
|
+
var _a2, _b;
|
|
5817
5880
|
const mapping = {};
|
|
5818
5881
|
for (const message of prompt) {
|
|
5819
5882
|
if (message.role !== "assistant") continue;
|
|
5820
5883
|
for (const part of message.content) {
|
|
5821
5884
|
if (part.type !== "tool-call") continue;
|
|
5822
|
-
const approvalRequestId = (_b = (
|
|
5885
|
+
const approvalRequestId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.approvalRequestId;
|
|
5823
5886
|
if (approvalRequestId != null) {
|
|
5824
5887
|
mapping[approvalRequestId] = part.toolCallId;
|
|
5825
5888
|
}
|
|
@@ -5855,7 +5918,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5855
5918
|
toolChoice,
|
|
5856
5919
|
responseFormat
|
|
5857
5920
|
}) {
|
|
5858
|
-
var
|
|
5921
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
5859
5922
|
const warnings = [];
|
|
5860
5923
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
5861
5924
|
if (topK != null) {
|
|
@@ -5886,7 +5949,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5886
5949
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
5887
5950
|
});
|
|
5888
5951
|
}
|
|
5889
|
-
const isReasoningModel = (
|
|
5952
|
+
const isReasoningModel = (_a2 = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _a2 : modelCapabilities.isReasoningModel;
|
|
5890
5953
|
if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
|
|
5891
5954
|
warnings.push({
|
|
5892
5955
|
type: "unsupported",
|
|
@@ -5935,6 +5998,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5935
5998
|
hasLocalShellTool: hasOpenAITool("openai.local_shell"),
|
|
5936
5999
|
hasShellTool: hasOpenAITool("openai.shell"),
|
|
5937
6000
|
hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
|
|
6001
|
+
toolSearchToolName: getOpenAIToolName("openai.tool_search"),
|
|
5938
6002
|
customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
|
|
5939
6003
|
});
|
|
5940
6004
|
warnings.push(...inputWarnings);
|
|
@@ -5947,8 +6011,12 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5947
6011
|
include = [...include, key];
|
|
5948
6012
|
}
|
|
5949
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
|
+
}
|
|
5950
6018
|
function hasOpenAITool(id) {
|
|
5951
|
-
return (
|
|
6019
|
+
return getOpenAIToolName(id) != null;
|
|
5952
6020
|
}
|
|
5953
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;
|
|
5954
6022
|
if (topLogprobs) {
|
|
@@ -6108,7 +6176,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6108
6176
|
};
|
|
6109
6177
|
}
|
|
6110
6178
|
async doGenerate(options) {
|
|
6111
|
-
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;
|
|
6112
6180
|
const {
|
|
6113
6181
|
args: body,
|
|
6114
6182
|
warnings,
|
|
@@ -6150,7 +6218,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6150
6218
|
}
|
|
6151
6219
|
const content = [];
|
|
6152
6220
|
const logprobs = [];
|
|
6153
|
-
const functionTools = (_b = (
|
|
6221
|
+
const functionTools = (_b = (_a2 = options.tools) == null ? void 0 : _a2.filter(
|
|
6154
6222
|
(tool) => tool.type === "function"
|
|
6155
6223
|
)) != null ? _b : [];
|
|
6156
6224
|
let hasFunctionCall = false;
|
|
@@ -6602,7 +6670,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6602
6670
|
};
|
|
6603
6671
|
}
|
|
6604
6672
|
async doStream(options) {
|
|
6605
|
-
var
|
|
6673
|
+
var _a2, _b;
|
|
6606
6674
|
const {
|
|
6607
6675
|
args: body,
|
|
6608
6676
|
warnings,
|
|
@@ -6640,7 +6708,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6640
6708
|
});
|
|
6641
6709
|
const self = this;
|
|
6642
6710
|
const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
|
|
6643
|
-
const functionTools = (_b = (
|
|
6711
|
+
const functionTools = (_b = (_a2 = options.tools) == null ? void 0 : _a2.filter(
|
|
6644
6712
|
(tool) => tool.type === "function"
|
|
6645
6713
|
)) != null ? _b : [];
|
|
6646
6714
|
const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
|
|
@@ -6667,7 +6735,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6667
6735
|
controller.enqueue({ type: "stream-start", warnings });
|
|
6668
6736
|
},
|
|
6669
6737
|
transform(chunk, controller) {
|
|
6670
|
-
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;
|
|
6671
6739
|
if (options.includeRawChunks) {
|
|
6672
6740
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
6673
6741
|
}
|
|
@@ -6679,6 +6747,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6679
6747
|
requestBodyValues: body,
|
|
6680
6748
|
responseHeaders
|
|
6681
6749
|
}) : chunk.error;
|
|
6750
|
+
encounteredStreamError = true;
|
|
6682
6751
|
finishReason = { unified: "error", raw: void 0 };
|
|
6683
6752
|
controller.enqueue({ type: "error", error });
|
|
6684
6753
|
return;
|
|
@@ -6797,7 +6866,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6797
6866
|
ongoingToolCalls[value.output_index] = {
|
|
6798
6867
|
toolName,
|
|
6799
6868
|
toolCallId,
|
|
6800
|
-
toolSearchExecution: (
|
|
6869
|
+
toolSearchExecution: (_a3 = value.item.execution) != null ? _a3 : "server"
|
|
6801
6870
|
};
|
|
6802
6871
|
if (isHosted) {
|
|
6803
6872
|
controller.enqueue({
|
|
@@ -6910,14 +6979,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6910
6979
|
tools: functionTools
|
|
6911
6980
|
});
|
|
6912
6981
|
const enqueueUnexpandedToolCall = () => {
|
|
6913
|
-
var
|
|
6982
|
+
var _a4;
|
|
6914
6983
|
if (suppressInputStreaming) {
|
|
6915
6984
|
controller.enqueue({
|
|
6916
6985
|
type: "tool-input-start",
|
|
6917
6986
|
id: item.call_id,
|
|
6918
6987
|
toolName: item.name
|
|
6919
6988
|
});
|
|
6920
|
-
const bufferedInputDeltas = (
|
|
6989
|
+
const bufferedInputDeltas = (_a4 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a4 : [];
|
|
6921
6990
|
if (bufferedInputDeltas.length > 0) {
|
|
6922
6991
|
for (const delta of bufferedInputDeltas) {
|
|
6923
6992
|
controller.enqueue({
|
|
@@ -7478,13 +7547,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7478
7547
|
activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
|
|
7479
7548
|
}
|
|
7480
7549
|
} else if (isResponseFinishedChunk(value)) {
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7550
|
+
if (!encounteredStreamError) {
|
|
7551
|
+
finishReason = {
|
|
7552
|
+
unified: mapOpenAIResponseFinishReason({
|
|
7553
|
+
finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
|
|
7554
|
+
hasFunctionCall
|
|
7555
|
+
}),
|
|
7556
|
+
raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
|
|
7557
|
+
};
|
|
7558
|
+
}
|
|
7488
7559
|
usage = value.response.usage;
|
|
7489
7560
|
if (typeof value.response.service_tier === "string") {
|
|
7490
7561
|
serviceTier = value.response.service_tier;
|
|
@@ -7586,7 +7657,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7586
7657
|
}
|
|
7587
7658
|
},
|
|
7588
7659
|
flush(controller) {
|
|
7589
|
-
var
|
|
7660
|
+
var _a3;
|
|
7590
7661
|
for (const toolCall of Object.values(ongoingToolCalls)) {
|
|
7591
7662
|
if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
|
|
7592
7663
|
continue;
|
|
@@ -7596,7 +7667,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7596
7667
|
id: toolCall.toolCallId,
|
|
7597
7668
|
toolName: toolCall.toolName
|
|
7598
7669
|
});
|
|
7599
|
-
for (const delta of (
|
|
7670
|
+
for (const delta of (_a3 = toolCall.bufferedInputDeltas) != null ? _a3 : []) {
|
|
7600
7671
|
controller.enqueue({
|
|
7601
7672
|
type: "tool-input-delta",
|
|
7602
7673
|
id: toolCall.toolCallId,
|
|
@@ -7701,7 +7772,7 @@ function isResponseOutputChunk(chunk) {
|
|
|
7701
7772
|
return !(chunk.type === "response.created" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
|
|
7702
7773
|
}
|
|
7703
7774
|
function mapWebSearchOutput(action) {
|
|
7704
|
-
var
|
|
7775
|
+
var _a2;
|
|
7705
7776
|
if (action == null) {
|
|
7706
7777
|
return {};
|
|
7707
7778
|
}
|
|
@@ -7710,7 +7781,7 @@ function mapWebSearchOutput(action) {
|
|
|
7710
7781
|
return {
|
|
7711
7782
|
action: {
|
|
7712
7783
|
type: "search",
|
|
7713
|
-
query: (
|
|
7784
|
+
query: (_a2 = action.query) != null ? _a2 : void 0,
|
|
7714
7785
|
...action.queries != null && { queries: action.queries }
|
|
7715
7786
|
},
|
|
7716
7787
|
// include sources when provided by the Responses API (behind include flag)
|