@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/index.mjs
CHANGED
|
@@ -40,10 +40,10 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
40
40
|
|
|
41
41
|
// src/openai-language-model-capabilities.ts
|
|
42
42
|
function getOpenAILanguageModelCapabilities(modelId) {
|
|
43
|
-
var
|
|
43
|
+
var _a2, _b, _c, _d, _e;
|
|
44
44
|
const oSeriesVersion = getOSeriesVersion(modelId);
|
|
45
45
|
const gptVersion = getGptVersion(modelId);
|
|
46
|
-
const isGptChatModel = (gptVersion == null ? void 0 : gptVersion.minor) == null && ((_b = (
|
|
46
|
+
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);
|
|
47
47
|
const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
|
|
48
48
|
const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
|
|
49
49
|
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
|
|
@@ -123,10 +123,10 @@ function createOpenAIStreamError({
|
|
|
123
123
|
requestBodyValues,
|
|
124
124
|
responseHeaders
|
|
125
125
|
}) {
|
|
126
|
-
var
|
|
126
|
+
var _a2;
|
|
127
127
|
const streamError = parseStreamError(frame);
|
|
128
128
|
return new APICallError({
|
|
129
|
-
message: (
|
|
129
|
+
message: (_a2 = streamError == null ? void 0 : streamError.message) != null ? _a2 : "OpenAI stream failed before any output was generated",
|
|
130
130
|
url,
|
|
131
131
|
requestBodyValues,
|
|
132
132
|
statusCode: streamError == null ? 500 : getStatusCode(streamError),
|
|
@@ -136,7 +136,7 @@ function createOpenAIStreamError({
|
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
function parseStreamError(frame) {
|
|
139
|
-
var
|
|
139
|
+
var _a2;
|
|
140
140
|
const value = asRecord(frame);
|
|
141
141
|
if (value == null) {
|
|
142
142
|
return void 0;
|
|
@@ -151,7 +151,7 @@ function parseStreamError(frame) {
|
|
|
151
151
|
frame
|
|
152
152
|
} : void 0;
|
|
153
153
|
}
|
|
154
|
-
const error = (
|
|
154
|
+
const error = (_a2 = asRecord(value.error)) != null ? _a2 : value;
|
|
155
155
|
return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
|
|
156
156
|
message: error.message,
|
|
157
157
|
code: getStringOrNumber(error.code),
|
|
@@ -199,7 +199,7 @@ function isHttpErrorStatusCode(value) {
|
|
|
199
199
|
|
|
200
200
|
// src/chat/convert-openai-chat-usage.ts
|
|
201
201
|
function convertOpenAIChatUsage(usage) {
|
|
202
|
-
var
|
|
202
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
203
203
|
if (usage == null) {
|
|
204
204
|
return {
|
|
205
205
|
inputTokens: {
|
|
@@ -216,7 +216,7 @@ function convertOpenAIChatUsage(usage) {
|
|
|
216
216
|
raw: void 0
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
|
-
const promptTokens = (
|
|
219
|
+
const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
|
|
220
220
|
const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
|
|
221
221
|
const cachedTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
|
|
222
222
|
const cacheWriteTokens = (_f = (_e = usage.prompt_tokens_details) == null ? void 0 : _e.cache_write_tokens) != null ? _f : void 0;
|
|
@@ -243,17 +243,19 @@ import {
|
|
|
243
243
|
} from "@ai-sdk/provider";
|
|
244
244
|
import { convertToBase64 } from "@ai-sdk/provider-utils";
|
|
245
245
|
function serializeToolCallArguments(input) {
|
|
246
|
-
return JSON.stringify(
|
|
246
|
+
return JSON.stringify(
|
|
247
|
+
typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
|
|
248
|
+
);
|
|
247
249
|
}
|
|
248
250
|
function getPromptCacheBreakpoint(providerOptions) {
|
|
249
|
-
var
|
|
250
|
-
return (
|
|
251
|
+
var _a2;
|
|
252
|
+
return (_a2 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
251
253
|
}
|
|
252
254
|
function convertToOpenAIChatMessages({
|
|
253
255
|
prompt,
|
|
254
256
|
systemMessageMode = "system"
|
|
255
257
|
}) {
|
|
256
|
-
var
|
|
258
|
+
var _a2, _b;
|
|
257
259
|
const messages = [];
|
|
258
260
|
const warnings = [];
|
|
259
261
|
for (const { role, content, providerOptions } of prompt) {
|
|
@@ -312,7 +314,7 @@ function convertToOpenAIChatMessages({
|
|
|
312
314
|
messages.push({
|
|
313
315
|
role: "user",
|
|
314
316
|
content: content.map((part, index) => {
|
|
315
|
-
var
|
|
317
|
+
var _a3, _b2, _c;
|
|
316
318
|
switch (part.type) {
|
|
317
319
|
case "text": {
|
|
318
320
|
const promptCacheBreakpoint = getPromptCacheBreakpoint(
|
|
@@ -337,7 +339,7 @@ function convertToOpenAIChatMessages({
|
|
|
337
339
|
image_url: {
|
|
338
340
|
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`,
|
|
339
341
|
// OpenAI specific extension: image detail
|
|
340
|
-
detail: (_b2 = (
|
|
342
|
+
detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3.openai) == null ? void 0 : _b2.imageDetail
|
|
341
343
|
},
|
|
342
344
|
...promptCacheBreakpoint != null && {
|
|
343
345
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
@@ -456,7 +458,7 @@ function convertToOpenAIChatMessages({
|
|
|
456
458
|
continue;
|
|
457
459
|
}
|
|
458
460
|
const output = toolResponse.output;
|
|
459
|
-
const promptCacheBreakpoint = (
|
|
461
|
+
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);
|
|
460
462
|
let contentValue;
|
|
461
463
|
switch (output.type) {
|
|
462
464
|
case "text":
|
|
@@ -898,13 +900,13 @@ var OpenAIChatLanguageModel = class {
|
|
|
898
900
|
toolChoice,
|
|
899
901
|
providerOptions
|
|
900
902
|
}) {
|
|
901
|
-
var
|
|
903
|
+
var _a2, _b, _c, _d, _e;
|
|
902
904
|
const warnings = [];
|
|
903
|
-
const openaiOptions = (
|
|
905
|
+
const openaiOptions = (_a2 = await parseProviderOptions({
|
|
904
906
|
provider: "openai",
|
|
905
907
|
providerOptions,
|
|
906
908
|
schema: openaiLanguageModelChatOptions
|
|
907
|
-
})) != null ?
|
|
909
|
+
})) != null ? _a2 : {};
|
|
908
910
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
909
911
|
const isReasoningModel = (_b = openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
|
|
910
912
|
if (topK != null) {
|
|
@@ -1066,7 +1068,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1066
1068
|
};
|
|
1067
1069
|
}
|
|
1068
1070
|
async doGenerate(options) {
|
|
1069
|
-
var
|
|
1071
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1070
1072
|
const { args: body, warnings } = await this.getArgs(options);
|
|
1071
1073
|
const {
|
|
1072
1074
|
responseHeaders,
|
|
@@ -1092,7 +1094,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1092
1094
|
if (text != null && text.length > 0) {
|
|
1093
1095
|
content.push({ type: "text", text });
|
|
1094
1096
|
}
|
|
1095
|
-
for (const toolCall of (
|
|
1097
|
+
for (const toolCall of (_a2 = choice.message.tool_calls) != null ? _a2 : []) {
|
|
1096
1098
|
content.push({
|
|
1097
1099
|
type: "tool-call",
|
|
1098
1100
|
toolCallId: (_b = toolCall.id) != null ? _b : generateId(),
|
|
@@ -1186,7 +1188,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1186
1188
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1187
1189
|
},
|
|
1188
1190
|
transform(chunk, controller) {
|
|
1189
|
-
var
|
|
1191
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1190
1192
|
if (options.includeRawChunks) {
|
|
1191
1193
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1192
1194
|
}
|
|
@@ -1213,7 +1215,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1213
1215
|
}
|
|
1214
1216
|
if (value.usage != null) {
|
|
1215
1217
|
usage = value.usage;
|
|
1216
|
-
if (((
|
|
1218
|
+
if (((_a2 = value.usage.completion_tokens_details) == null ? void 0 : _a2.accepted_prediction_tokens) != null) {
|
|
1217
1219
|
providerMetadata.openai.acceptedPredictionTokens = (_b = value.usage.completion_tokens_details) == null ? void 0 : _b.accepted_prediction_tokens;
|
|
1218
1220
|
}
|
|
1219
1221
|
if (((_c = value.usage.completion_tokens_details) == null ? void 0 : _c.rejected_prediction_tokens) != null) {
|
|
@@ -1320,7 +1322,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1320
1322
|
}
|
|
1321
1323
|
},
|
|
1322
1324
|
flush(controller) {
|
|
1323
|
-
var
|
|
1325
|
+
var _a2;
|
|
1324
1326
|
if (isActiveText) {
|
|
1325
1327
|
controller.enqueue({ type: "text-end", id: "0" });
|
|
1326
1328
|
}
|
|
@@ -1332,7 +1334,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1332
1334
|
});
|
|
1333
1335
|
controller.enqueue({
|
|
1334
1336
|
type: "tool-call",
|
|
1335
|
-
toolCallId: (
|
|
1337
|
+
toolCallId: (_a2 = toolCall.id) != null ? _a2 : generateId(),
|
|
1336
1338
|
toolName: toolCall.function.name,
|
|
1337
1339
|
input: toolCall.function.arguments
|
|
1338
1340
|
});
|
|
@@ -1375,7 +1377,7 @@ import {
|
|
|
1375
1377
|
|
|
1376
1378
|
// src/completion/convert-openai-completion-usage.ts
|
|
1377
1379
|
function convertOpenAICompletionUsage(usage) {
|
|
1378
|
-
var
|
|
1380
|
+
var _a2, _b, _c, _d;
|
|
1379
1381
|
if (usage == null) {
|
|
1380
1382
|
return {
|
|
1381
1383
|
inputTokens: {
|
|
@@ -1392,7 +1394,7 @@ function convertOpenAICompletionUsage(usage) {
|
|
|
1392
1394
|
raw: void 0
|
|
1393
1395
|
};
|
|
1394
1396
|
}
|
|
1395
|
-
const promptTokens = (
|
|
1397
|
+
const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
|
|
1396
1398
|
const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
|
|
1397
1399
|
return {
|
|
1398
1400
|
inputTokens: {
|
|
@@ -1718,7 +1720,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1718
1720
|
};
|
|
1719
1721
|
}
|
|
1720
1722
|
async doGenerate(options) {
|
|
1721
|
-
var
|
|
1723
|
+
var _a2;
|
|
1722
1724
|
const { args, warnings } = await this.getArgs(options);
|
|
1723
1725
|
const {
|
|
1724
1726
|
responseHeaders,
|
|
@@ -1748,7 +1750,7 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1748
1750
|
usage: convertOpenAICompletionUsage(response.usage),
|
|
1749
1751
|
finishReason: {
|
|
1750
1752
|
unified: mapOpenAIFinishReason2(choice.finish_reason),
|
|
1751
|
-
raw: (
|
|
1753
|
+
raw: (_a2 = choice.finish_reason) != null ? _a2 : void 0
|
|
1752
1754
|
},
|
|
1753
1755
|
request: { body: args },
|
|
1754
1756
|
response: {
|
|
@@ -1879,6 +1881,7 @@ import {
|
|
|
1879
1881
|
import {
|
|
1880
1882
|
combineHeaders as combineHeaders3,
|
|
1881
1883
|
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1884
|
+
EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL,
|
|
1882
1885
|
parseProviderOptions as parseProviderOptions3,
|
|
1883
1886
|
postJsonToApi as postJsonToApi3
|
|
1884
1887
|
} from "@ai-sdk/provider-utils";
|
|
@@ -1919,10 +1922,13 @@ var openaiTextEmbeddingResponseSchema = lazySchema6(
|
|
|
1919
1922
|
);
|
|
1920
1923
|
|
|
1921
1924
|
// src/embedding/openai-embedding-model.ts
|
|
1925
|
+
var _a;
|
|
1926
|
+
_a = EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL;
|
|
1922
1927
|
var OpenAIEmbeddingModel = class {
|
|
1923
1928
|
constructor(modelId, config) {
|
|
1924
1929
|
this.specificationVersion = "v3";
|
|
1925
1930
|
this.maxEmbeddingsPerCall = 2048;
|
|
1931
|
+
this[_a] = 3e5;
|
|
1926
1932
|
this.supportsParallelCalls = true;
|
|
1927
1933
|
this.modelId = modelId;
|
|
1928
1934
|
this.config = config;
|
|
@@ -1936,7 +1942,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1936
1942
|
abortSignal,
|
|
1937
1943
|
providerOptions
|
|
1938
1944
|
}) {
|
|
1939
|
-
var
|
|
1945
|
+
var _a2;
|
|
1940
1946
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1941
1947
|
throw new TooManyEmbeddingValuesForCallError({
|
|
1942
1948
|
provider: this.provider,
|
|
@@ -1945,11 +1951,11 @@ var OpenAIEmbeddingModel = class {
|
|
|
1945
1951
|
values
|
|
1946
1952
|
});
|
|
1947
1953
|
}
|
|
1948
|
-
const openaiOptions = (
|
|
1954
|
+
const openaiOptions = (_a2 = await parseProviderOptions3({
|
|
1949
1955
|
provider: "openai",
|
|
1950
1956
|
providerOptions,
|
|
1951
1957
|
schema: openaiEmbeddingModelOptions
|
|
1952
|
-
})) != null ?
|
|
1958
|
+
})) != null ? _a2 : {};
|
|
1953
1959
|
const {
|
|
1954
1960
|
responseHeaders,
|
|
1955
1961
|
value: response,
|
|
@@ -2047,8 +2053,8 @@ function hasDefaultResponseFormat(modelId) {
|
|
|
2047
2053
|
);
|
|
2048
2054
|
}
|
|
2049
2055
|
function getMaxImagesPerCall(modelId) {
|
|
2050
|
-
var
|
|
2051
|
-
return (
|
|
2056
|
+
var _a2;
|
|
2057
|
+
return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
|
|
2052
2058
|
}
|
|
2053
2059
|
var baseImageModelOptionsObject = z9.object({
|
|
2054
2060
|
/**
|
|
@@ -2135,7 +2141,7 @@ var OpenAIImageModel = class {
|
|
|
2135
2141
|
headers,
|
|
2136
2142
|
abortSignal
|
|
2137
2143
|
}) {
|
|
2138
|
-
var
|
|
2144
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2139
2145
|
const warnings = [];
|
|
2140
2146
|
if (aspectRatio != null) {
|
|
2141
2147
|
warnings.push({
|
|
@@ -2147,7 +2153,7 @@ var OpenAIImageModel = class {
|
|
|
2147
2153
|
if (seed != null) {
|
|
2148
2154
|
warnings.push({ type: "unsupported", feature: "seed" });
|
|
2149
2155
|
}
|
|
2150
|
-
const currentDate = (_c = (_b = (
|
|
2156
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2151
2157
|
if (files != null) {
|
|
2152
2158
|
const openaiOptions2 = (_d = await parseProviderOptions4({
|
|
2153
2159
|
provider: "openai",
|
|
@@ -2210,10 +2216,10 @@ var OpenAIImageModel = class {
|
|
|
2210
2216
|
providerMetadata: {
|
|
2211
2217
|
openai: {
|
|
2212
2218
|
images: response2.data.map((item, index) => {
|
|
2213
|
-
var
|
|
2219
|
+
var _a3, _b2, _c2, _d2, _e2, _f2;
|
|
2214
2220
|
return {
|
|
2215
2221
|
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
|
|
2216
|
-
created: (
|
|
2222
|
+
created: (_a3 = response2.created) != null ? _a3 : void 0,
|
|
2217
2223
|
size: (_b2 = response2.size) != null ? _b2 : void 0,
|
|
2218
2224
|
quality: (_c2 = response2.quality) != null ? _c2 : void 0,
|
|
2219
2225
|
background: (_d2 = response2.background) != null ? _d2 : void 0,
|
|
@@ -2277,10 +2283,10 @@ var OpenAIImageModel = class {
|
|
|
2277
2283
|
providerMetadata: {
|
|
2278
2284
|
openai: {
|
|
2279
2285
|
images: response.data.map((item, index) => {
|
|
2280
|
-
var
|
|
2286
|
+
var _a3, _b2, _c2, _d2, _e2, _f2;
|
|
2281
2287
|
return {
|
|
2282
2288
|
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
|
|
2283
|
-
created: (
|
|
2289
|
+
created: (_a3 = response.created) != null ? _a3 : void 0,
|
|
2284
2290
|
size: (_b2 = response.size) != null ? _b2 : void 0,
|
|
2285
2291
|
quality: (_c2 = response.quality) != null ? _c2 : void 0,
|
|
2286
2292
|
background: (_d2 = response.background) != null ? _d2 : void 0,
|
|
@@ -3024,7 +3030,7 @@ import {
|
|
|
3024
3030
|
|
|
3025
3031
|
// src/responses/convert-openai-responses-usage.ts
|
|
3026
3032
|
function convertOpenAIResponsesUsage(usage) {
|
|
3027
|
-
var
|
|
3033
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
3028
3034
|
if (usage == null) {
|
|
3029
3035
|
return {
|
|
3030
3036
|
inputTokens: {
|
|
@@ -3043,7 +3049,7 @@ function convertOpenAIResponsesUsage(usage) {
|
|
|
3043
3049
|
}
|
|
3044
3050
|
const inputTokens = usage.input_tokens;
|
|
3045
3051
|
const outputTokens = usage.output_tokens;
|
|
3046
|
-
const cachedTokens = (_b = (
|
|
3052
|
+
const cachedTokens = (_b = (_a2 = usage.input_tokens_details) == null ? void 0 : _a2.cached_tokens) != null ? _b : 0;
|
|
3047
3053
|
const cacheWriteTokens = (_d = (_c = usage.input_tokens_details) == null ? void 0 : _c.cache_write_tokens) != null ? _d : void 0;
|
|
3048
3054
|
const reasoningTokens = (_f = (_e = usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
|
|
3049
3055
|
return {
|
|
@@ -3086,8 +3092,8 @@ function getParallelToolCallMetadata({
|
|
|
3086
3092
|
providerOptions,
|
|
3087
3093
|
providerOptionsName
|
|
3088
3094
|
}) {
|
|
3089
|
-
var
|
|
3090
|
-
const metadata = (
|
|
3095
|
+
var _a2;
|
|
3096
|
+
const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
|
|
3091
3097
|
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) {
|
|
3092
3098
|
return void 0;
|
|
3093
3099
|
}
|
|
@@ -3162,19 +3168,19 @@ async function convertFunctionToolResultOutput({
|
|
|
3162
3168
|
providerOptionsName,
|
|
3163
3169
|
warnings
|
|
3164
3170
|
}) {
|
|
3165
|
-
var
|
|
3171
|
+
var _a2;
|
|
3166
3172
|
switch (output.type) {
|
|
3167
3173
|
case "text":
|
|
3168
3174
|
case "error-text":
|
|
3169
3175
|
return output.value;
|
|
3170
3176
|
case "execution-denied":
|
|
3171
|
-
return (
|
|
3177
|
+
return (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
|
|
3172
3178
|
case "json":
|
|
3173
3179
|
case "error-json":
|
|
3174
3180
|
return JSON.stringify(output.value);
|
|
3175
3181
|
case "content":
|
|
3176
3182
|
return output.value.map((item) => {
|
|
3177
|
-
var
|
|
3183
|
+
var _a3, _b, _c, _d, _e;
|
|
3178
3184
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
3179
3185
|
item.providerOptions,
|
|
3180
3186
|
providerOptionsName
|
|
@@ -3193,7 +3199,7 @@ async function convertFunctionToolResultOutput({
|
|
|
3193
3199
|
return {
|
|
3194
3200
|
type: "input_image",
|
|
3195
3201
|
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3196
|
-
detail: (_b = (
|
|
3202
|
+
detail: (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail,
|
|
3197
3203
|
...promptCacheBreakpoint != null && {
|
|
3198
3204
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3199
3205
|
}
|
|
@@ -3297,8 +3303,8 @@ function collectCompleteParallelToolResultGroups({
|
|
|
3297
3303
|
return completeGroups;
|
|
3298
3304
|
}
|
|
3299
3305
|
function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
|
|
3300
|
-
var
|
|
3301
|
-
return (
|
|
3306
|
+
var _a2;
|
|
3307
|
+
return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
3302
3308
|
}
|
|
3303
3309
|
function isFileId(data, prefixes) {
|
|
3304
3310
|
if (!prefixes) return false;
|
|
@@ -3317,9 +3323,10 @@ async function convertToOpenAIResponsesInput({
|
|
|
3317
3323
|
hasLocalShellTool = false,
|
|
3318
3324
|
hasShellTool = false,
|
|
3319
3325
|
hasApplyPatchTool = false,
|
|
3326
|
+
toolSearchToolName,
|
|
3320
3327
|
customProviderToolNames
|
|
3321
3328
|
}) {
|
|
3322
|
-
var
|
|
3329
|
+
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;
|
|
3323
3330
|
let input = [];
|
|
3324
3331
|
const warnings = [];
|
|
3325
3332
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
@@ -3387,7 +3394,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3387
3394
|
input.push({
|
|
3388
3395
|
role: "user",
|
|
3389
3396
|
content: content.map((part, index) => {
|
|
3390
|
-
var
|
|
3397
|
+
var _a3, _b2, _c2;
|
|
3391
3398
|
switch (part.type) {
|
|
3392
3399
|
case "text": {
|
|
3393
3400
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
@@ -3414,7 +3421,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3414
3421
|
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
3415
3422
|
image_url: `data:${mediaType};base64,${convertToBase642(part.data)}`
|
|
3416
3423
|
},
|
|
3417
|
-
detail: (_b2 = (
|
|
3424
|
+
detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
3418
3425
|
...promptCacheBreakpoint != null && {
|
|
3419
3426
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3420
3427
|
}
|
|
@@ -3455,7 +3462,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3455
3462
|
for (const part of content) {
|
|
3456
3463
|
switch (part.type) {
|
|
3457
3464
|
case "text": {
|
|
3458
|
-
const providerOpts = (
|
|
3465
|
+
const providerOpts = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName];
|
|
3459
3466
|
const id = providerOpts == null ? void 0 : providerOpts.itemId;
|
|
3460
3467
|
const phase = providerOpts == null ? void 0 : providerOpts.phase;
|
|
3461
3468
|
if (hasConversation && id != null) {
|
|
@@ -3510,7 +3517,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3510
3517
|
const resolvedToolName = toolNameMapping.toProviderToolName(
|
|
3511
3518
|
part.toolName
|
|
3512
3519
|
);
|
|
3513
|
-
if (
|
|
3520
|
+
if (part.toolName === toolSearchToolName) {
|
|
3514
3521
|
if (store && id != null) {
|
|
3515
3522
|
input.push({ type: "item_reference", id });
|
|
3516
3523
|
break;
|
|
@@ -3631,7 +3638,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3631
3638
|
const resolvedResultToolName = toolNameMapping.toProviderToolName(
|
|
3632
3639
|
part.toolName
|
|
3633
3640
|
);
|
|
3634
|
-
if (
|
|
3641
|
+
if (part.toolName === toolSearchToolName) {
|
|
3635
3642
|
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;
|
|
3636
3643
|
if (store) {
|
|
3637
3644
|
input.push({ type: "item_reference", id: itemId });
|
|
@@ -3829,7 +3836,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3829
3836
|
const resolvedToolName = toolNameMapping.toProviderToolName(
|
|
3830
3837
|
part.toolName
|
|
3831
3838
|
);
|
|
3832
|
-
if (
|
|
3839
|
+
if (part.toolName === toolSearchToolName && output.type === "json") {
|
|
3833
3840
|
const parsedOutput = await validateTypes({
|
|
3834
3841
|
value: output.value,
|
|
3835
3842
|
schema: toolSearchOutputSchema
|
|
@@ -3903,7 +3910,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3903
3910
|
break;
|
|
3904
3911
|
case "content":
|
|
3905
3912
|
outputValue = output.value.map((item) => {
|
|
3906
|
-
var
|
|
3913
|
+
var _a3, _b2, _c2, _d2, _e2;
|
|
3907
3914
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
3908
3915
|
item.providerOptions,
|
|
3909
3916
|
providerOptionsName
|
|
@@ -3921,7 +3928,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3921
3928
|
return {
|
|
3922
3929
|
type: "input_image",
|
|
3923
3930
|
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
3924
|
-
detail: (_b2 = (
|
|
3931
|
+
detail: (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
3925
3932
|
...promptCacheBreakpoint != null && {
|
|
3926
3933
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
3927
3934
|
}
|
|
@@ -4042,6 +4049,22 @@ var jsonValueSchema2 = z22.lazy(
|
|
|
4042
4049
|
z22.record(z22.string(), jsonValueSchema2.optional())
|
|
4043
4050
|
])
|
|
4044
4051
|
);
|
|
4052
|
+
function isRecord(value) {
|
|
4053
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
4054
|
+
}
|
|
4055
|
+
var openaiResponsesLocalShellCallSchema = z22.object({
|
|
4056
|
+
type: z22.literal("local_shell_call"),
|
|
4057
|
+
id: z22.string(),
|
|
4058
|
+
call_id: z22.string(),
|
|
4059
|
+
action: z22.object({
|
|
4060
|
+
type: z22.literal("exec"),
|
|
4061
|
+
command: z22.array(z22.string()),
|
|
4062
|
+
timeout_ms: z22.number().optional(),
|
|
4063
|
+
user: z22.string().optional(),
|
|
4064
|
+
working_directory: z22.string().optional(),
|
|
4065
|
+
env: z22.record(z22.string(), z22.string()).optional()
|
|
4066
|
+
})
|
|
4067
|
+
});
|
|
4045
4068
|
var openaiResponsesNestedErrorChunkSchema = z22.object({
|
|
4046
4069
|
type: z22.literal("error"),
|
|
4047
4070
|
sequence_number: z22.number(),
|
|
@@ -4059,6 +4082,60 @@ var openaiResponsesErrorChunkSchema = z22.object({
|
|
|
4059
4082
|
message: z22.string(),
|
|
4060
4083
|
param: z22.string().nullish()
|
|
4061
4084
|
});
|
|
4085
|
+
var openaiResponsesModeledChunkTypes = /* @__PURE__ */ new Set([
|
|
4086
|
+
"error",
|
|
4087
|
+
"response.apply_patch_call_operation_diff.delta",
|
|
4088
|
+
"response.apply_patch_call_operation_diff.done",
|
|
4089
|
+
"response.code_interpreter_call_code.delta",
|
|
4090
|
+
"response.code_interpreter_call_code.done",
|
|
4091
|
+
"response.completed",
|
|
4092
|
+
"response.created",
|
|
4093
|
+
"response.custom_tool_call_input.delta",
|
|
4094
|
+
"response.failed",
|
|
4095
|
+
"response.function_call_arguments.delta",
|
|
4096
|
+
"response.function_call_arguments.done",
|
|
4097
|
+
"response.image_generation_call.partial_image",
|
|
4098
|
+
"response.incomplete",
|
|
4099
|
+
"response.output_item.added",
|
|
4100
|
+
"response.output_item.done",
|
|
4101
|
+
"response.output_text.annotation.added",
|
|
4102
|
+
"response.output_text.delta",
|
|
4103
|
+
"response.reasoning_summary_part.added",
|
|
4104
|
+
"response.reasoning_summary_part.done",
|
|
4105
|
+
"response.reasoning_summary_text.delta"
|
|
4106
|
+
]);
|
|
4107
|
+
var openaiResponsesModeledOutputItemTypes = /* @__PURE__ */ new Set([
|
|
4108
|
+
"apply_patch_call",
|
|
4109
|
+
"code_interpreter_call",
|
|
4110
|
+
"computer_call",
|
|
4111
|
+
"custom_tool_call",
|
|
4112
|
+
"file_search_call",
|
|
4113
|
+
"function_call",
|
|
4114
|
+
"image_generation_call",
|
|
4115
|
+
"local_shell_call",
|
|
4116
|
+
"mcp_approval_request",
|
|
4117
|
+
"mcp_call",
|
|
4118
|
+
"mcp_list_tools",
|
|
4119
|
+
"message",
|
|
4120
|
+
"reasoning",
|
|
4121
|
+
"shell_call",
|
|
4122
|
+
"shell_call_output",
|
|
4123
|
+
"tool_search_call",
|
|
4124
|
+
"tool_search_output",
|
|
4125
|
+
"web_search_call"
|
|
4126
|
+
]);
|
|
4127
|
+
function isModeledOpenAIResponsesChunk(value) {
|
|
4128
|
+
if (typeof value.type !== "string" || !openaiResponsesModeledChunkTypes.has(value.type)) {
|
|
4129
|
+
return false;
|
|
4130
|
+
}
|
|
4131
|
+
if (value.type !== "response.output_item.added" && value.type !== "response.output_item.done") {
|
|
4132
|
+
return true;
|
|
4133
|
+
}
|
|
4134
|
+
if (!isRecord(value.item) || typeof value.item.type !== "string") {
|
|
4135
|
+
return true;
|
|
4136
|
+
}
|
|
4137
|
+
return openaiResponsesModeledOutputItemTypes.has(value.item.type);
|
|
4138
|
+
}
|
|
4062
4139
|
var openaiResponsesChunkSchema = lazySchema20(
|
|
4063
4140
|
() => zodSchema20(
|
|
4064
4141
|
z22.union([
|
|
@@ -4177,6 +4254,7 @@ var openaiResponsesChunkSchema = lazySchema20(
|
|
|
4177
4254
|
type: z22.literal("file_search_call"),
|
|
4178
4255
|
id: z22.string()
|
|
4179
4256
|
}),
|
|
4257
|
+
openaiResponsesLocalShellCallSchema,
|
|
4180
4258
|
z22.object({
|
|
4181
4259
|
type: z22.literal("image_generation_call"),
|
|
4182
4260
|
id: z22.string()
|
|
@@ -4375,19 +4453,7 @@ var openaiResponsesChunkSchema = lazySchema20(
|
|
|
4375
4453
|
})
|
|
4376
4454
|
).nullish()
|
|
4377
4455
|
}),
|
|
4378
|
-
|
|
4379
|
-
type: z22.literal("local_shell_call"),
|
|
4380
|
-
id: z22.string(),
|
|
4381
|
-
call_id: z22.string(),
|
|
4382
|
-
action: z22.object({
|
|
4383
|
-
type: z22.literal("exec"),
|
|
4384
|
-
command: z22.array(z22.string()),
|
|
4385
|
-
timeout_ms: z22.number().optional(),
|
|
4386
|
-
user: z22.string().optional(),
|
|
4387
|
-
working_directory: z22.string().optional(),
|
|
4388
|
-
env: z22.record(z22.string(), z22.string()).optional()
|
|
4389
|
-
})
|
|
4390
|
-
}),
|
|
4456
|
+
openaiResponsesLocalShellCallSchema,
|
|
4391
4457
|
z22.object({
|
|
4392
4458
|
type: z22.literal("computer_call"),
|
|
4393
4459
|
id: z22.string(),
|
|
@@ -4514,6 +4580,14 @@ var openaiResponsesChunkSchema = lazySchema20(
|
|
|
4514
4580
|
output_index: z22.number(),
|
|
4515
4581
|
delta: z22.string()
|
|
4516
4582
|
}),
|
|
4583
|
+
z22.object({
|
|
4584
|
+
// `name` is documented as required but omitted from live API events:
|
|
4585
|
+
// https://github.com/openai/openai-openapi/issues/545
|
|
4586
|
+
type: z22.literal("response.function_call_arguments.done"),
|
|
4587
|
+
item_id: z22.string(),
|
|
4588
|
+
output_index: z22.number(),
|
|
4589
|
+
arguments: z22.string()
|
|
4590
|
+
}),
|
|
4517
4591
|
z22.object({
|
|
4518
4592
|
type: z22.literal("response.custom_tool_call_input.delta"),
|
|
4519
4593
|
item_id: z22.string(),
|
|
@@ -4600,7 +4674,9 @@ var openaiResponsesChunkSchema = lazySchema20(
|
|
|
4600
4674
|
}),
|
|
4601
4675
|
openaiResponsesNestedErrorChunkSchema,
|
|
4602
4676
|
openaiResponsesErrorChunkSchema,
|
|
4603
|
-
z22.object({ type: z22.string() }).loose().
|
|
4677
|
+
z22.object({ type: z22.string() }).loose().refine((value) => !isModeledOpenAIResponsesChunk(value), {
|
|
4678
|
+
message: "Known response chunk failed schema validation"
|
|
4679
|
+
}).transform((value) => ({
|
|
4604
4680
|
type: "unknown_chunk",
|
|
4605
4681
|
message: value.type
|
|
4606
4682
|
}))
|
|
@@ -4740,19 +4816,7 @@ var openaiResponsesResponseSchema = lazySchema20(
|
|
|
4740
4816
|
id: z22.string(),
|
|
4741
4817
|
result: z22.string()
|
|
4742
4818
|
}),
|
|
4743
|
-
|
|
4744
|
-
type: z22.literal("local_shell_call"),
|
|
4745
|
-
id: z22.string(),
|
|
4746
|
-
call_id: z22.string(),
|
|
4747
|
-
action: z22.object({
|
|
4748
|
-
type: z22.literal("exec"),
|
|
4749
|
-
command: z22.array(z22.string()),
|
|
4750
|
-
timeout_ms: z22.number().optional(),
|
|
4751
|
-
user: z22.string().optional(),
|
|
4752
|
-
working_directory: z22.string().optional(),
|
|
4753
|
-
env: z22.record(z22.string(), z22.string()).optional()
|
|
4754
|
-
})
|
|
4755
|
-
}),
|
|
4819
|
+
openaiResponsesLocalShellCallSchema,
|
|
4756
4820
|
z22.object({
|
|
4757
4821
|
type: z22.literal("function_call"),
|
|
4758
4822
|
call_id: z22.string(),
|
|
@@ -5207,7 +5271,7 @@ async function prepareResponsesTools({
|
|
|
5207
5271
|
toolNameMapping,
|
|
5208
5272
|
customProviderToolNames
|
|
5209
5273
|
}) {
|
|
5210
|
-
var
|
|
5274
|
+
var _a2, _b, _c, _d;
|
|
5211
5275
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
5212
5276
|
const toolWarnings = [];
|
|
5213
5277
|
if (tools == null) {
|
|
@@ -5233,7 +5297,7 @@ async function prepareResponsesTools({
|
|
|
5233
5297
|
for (const tool of tools) {
|
|
5234
5298
|
switch (tool.type) {
|
|
5235
5299
|
case "function": {
|
|
5236
|
-
const openaiOptions = (
|
|
5300
|
+
const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
|
|
5237
5301
|
const openaiFunctionTool = prepareFunctionTool({
|
|
5238
5302
|
tool,
|
|
5239
5303
|
options: openaiOptions
|
|
@@ -5650,13 +5714,13 @@ function mapShellSkills(skills) {
|
|
|
5650
5714
|
|
|
5651
5715
|
// src/responses/openai-responses-language-model.ts
|
|
5652
5716
|
function extractApprovalRequestIdToToolCallIdMapping(prompt) {
|
|
5653
|
-
var
|
|
5717
|
+
var _a2, _b;
|
|
5654
5718
|
const mapping = {};
|
|
5655
5719
|
for (const message of prompt) {
|
|
5656
5720
|
if (message.role !== "assistant") continue;
|
|
5657
5721
|
for (const part of message.content) {
|
|
5658
5722
|
if (part.type !== "tool-call") continue;
|
|
5659
|
-
const approvalRequestId = (_b = (
|
|
5723
|
+
const approvalRequestId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.approvalRequestId;
|
|
5660
5724
|
if (approvalRequestId != null) {
|
|
5661
5725
|
mapping[approvalRequestId] = part.toolCallId;
|
|
5662
5726
|
}
|
|
@@ -5692,7 +5756,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5692
5756
|
toolChoice,
|
|
5693
5757
|
responseFormat
|
|
5694
5758
|
}) {
|
|
5695
|
-
var
|
|
5759
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
5696
5760
|
const warnings = [];
|
|
5697
5761
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
5698
5762
|
if (topK != null) {
|
|
@@ -5723,7 +5787,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5723
5787
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
5724
5788
|
});
|
|
5725
5789
|
}
|
|
5726
|
-
const isReasoningModel = (
|
|
5790
|
+
const isReasoningModel = (_a2 = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _a2 : modelCapabilities.isReasoningModel;
|
|
5727
5791
|
if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
|
|
5728
5792
|
warnings.push({
|
|
5729
5793
|
type: "unsupported",
|
|
@@ -5772,6 +5836,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5772
5836
|
hasLocalShellTool: hasOpenAITool("openai.local_shell"),
|
|
5773
5837
|
hasShellTool: hasOpenAITool("openai.shell"),
|
|
5774
5838
|
hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
|
|
5839
|
+
toolSearchToolName: getOpenAIToolName("openai.tool_search"),
|
|
5775
5840
|
customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
|
|
5776
5841
|
});
|
|
5777
5842
|
warnings.push(...inputWarnings);
|
|
@@ -5784,8 +5849,12 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5784
5849
|
include = [...include, key];
|
|
5785
5850
|
}
|
|
5786
5851
|
}
|
|
5852
|
+
function getOpenAIToolName(id) {
|
|
5853
|
+
var _a3;
|
|
5854
|
+
return (_a3 = tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && tool.id === id)) == null ? void 0 : _a3.name;
|
|
5855
|
+
}
|
|
5787
5856
|
function hasOpenAITool(id) {
|
|
5788
|
-
return (
|
|
5857
|
+
return getOpenAIToolName(id) != null;
|
|
5789
5858
|
}
|
|
5790
5859
|
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;
|
|
5791
5860
|
if (topLogprobs) {
|
|
@@ -5945,7 +6014,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5945
6014
|
};
|
|
5946
6015
|
}
|
|
5947
6016
|
async doGenerate(options) {
|
|
5948
|
-
var
|
|
6017
|
+
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;
|
|
5949
6018
|
const {
|
|
5950
6019
|
args: body,
|
|
5951
6020
|
warnings,
|
|
@@ -5987,7 +6056,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5987
6056
|
}
|
|
5988
6057
|
const content = [];
|
|
5989
6058
|
const logprobs = [];
|
|
5990
|
-
const functionTools = (_b = (
|
|
6059
|
+
const functionTools = (_b = (_a2 = options.tools) == null ? void 0 : _a2.filter(
|
|
5991
6060
|
(tool) => tool.type === "function"
|
|
5992
6061
|
)) != null ? _b : [];
|
|
5993
6062
|
let hasFunctionCall = false;
|
|
@@ -6439,7 +6508,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6439
6508
|
};
|
|
6440
6509
|
}
|
|
6441
6510
|
async doStream(options) {
|
|
6442
|
-
var
|
|
6511
|
+
var _a2, _b;
|
|
6443
6512
|
const {
|
|
6444
6513
|
args: body,
|
|
6445
6514
|
warnings,
|
|
@@ -6477,7 +6546,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6477
6546
|
});
|
|
6478
6547
|
const self = this;
|
|
6479
6548
|
const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
|
|
6480
|
-
const functionTools = (_b = (
|
|
6549
|
+
const functionTools = (_b = (_a2 = options.tools) == null ? void 0 : _a2.filter(
|
|
6481
6550
|
(tool) => tool.type === "function"
|
|
6482
6551
|
)) != null ? _b : [];
|
|
6483
6552
|
const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
|
|
@@ -6504,7 +6573,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6504
6573
|
controller.enqueue({ type: "stream-start", warnings });
|
|
6505
6574
|
},
|
|
6506
6575
|
transform(chunk, controller) {
|
|
6507
|
-
var
|
|
6576
|
+
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;
|
|
6508
6577
|
if (options.includeRawChunks) {
|
|
6509
6578
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
6510
6579
|
}
|
|
@@ -6516,6 +6585,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6516
6585
|
requestBodyValues: body,
|
|
6517
6586
|
responseHeaders
|
|
6518
6587
|
}) : chunk.error;
|
|
6588
|
+
encounteredStreamError = true;
|
|
6519
6589
|
finishReason = { unified: "error", raw: void 0 };
|
|
6520
6590
|
controller.enqueue({ type: "error", error });
|
|
6521
6591
|
return;
|
|
@@ -6634,7 +6704,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6634
6704
|
ongoingToolCalls[value.output_index] = {
|
|
6635
6705
|
toolName,
|
|
6636
6706
|
toolCallId,
|
|
6637
|
-
toolSearchExecution: (
|
|
6707
|
+
toolSearchExecution: (_a3 = value.item.execution) != null ? _a3 : "server"
|
|
6638
6708
|
};
|
|
6639
6709
|
if (isHosted) {
|
|
6640
6710
|
controller.enqueue({
|
|
@@ -6747,14 +6817,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6747
6817
|
tools: functionTools
|
|
6748
6818
|
});
|
|
6749
6819
|
const enqueueUnexpandedToolCall = () => {
|
|
6750
|
-
var
|
|
6820
|
+
var _a4;
|
|
6751
6821
|
if (suppressInputStreaming) {
|
|
6752
6822
|
controller.enqueue({
|
|
6753
6823
|
type: "tool-input-start",
|
|
6754
6824
|
id: item.call_id,
|
|
6755
6825
|
toolName: item.name
|
|
6756
6826
|
});
|
|
6757
|
-
const bufferedInputDeltas = (
|
|
6827
|
+
const bufferedInputDeltas = (_a4 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a4 : [];
|
|
6758
6828
|
if (bufferedInputDeltas.length > 0) {
|
|
6759
6829
|
for (const delta of bufferedInputDeltas) {
|
|
6760
6830
|
controller.enqueue({
|
|
@@ -7315,13 +7385,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7315
7385
|
activeReasoning[value.item_id].summaryParts[value.summary_index] = "can-conclude";
|
|
7316
7386
|
}
|
|
7317
7387
|
} else if (isResponseFinishedChunk(value)) {
|
|
7318
|
-
|
|
7319
|
-
|
|
7320
|
-
|
|
7321
|
-
|
|
7322
|
-
|
|
7323
|
-
|
|
7324
|
-
|
|
7388
|
+
if (!encounteredStreamError) {
|
|
7389
|
+
finishReason = {
|
|
7390
|
+
unified: mapOpenAIResponseFinishReason({
|
|
7391
|
+
finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
|
|
7392
|
+
hasFunctionCall
|
|
7393
|
+
}),
|
|
7394
|
+
raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
|
|
7395
|
+
};
|
|
7396
|
+
}
|
|
7325
7397
|
usage = value.response.usage;
|
|
7326
7398
|
if (typeof value.response.service_tier === "string") {
|
|
7327
7399
|
serviceTier = value.response.service_tier;
|
|
@@ -7423,7 +7495,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7423
7495
|
}
|
|
7424
7496
|
},
|
|
7425
7497
|
flush(controller) {
|
|
7426
|
-
var
|
|
7498
|
+
var _a3;
|
|
7427
7499
|
for (const toolCall of Object.values(ongoingToolCalls)) {
|
|
7428
7500
|
if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
|
|
7429
7501
|
continue;
|
|
@@ -7433,7 +7505,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7433
7505
|
id: toolCall.toolCallId,
|
|
7434
7506
|
toolName: toolCall.toolName
|
|
7435
7507
|
});
|
|
7436
|
-
for (const delta of (
|
|
7508
|
+
for (const delta of (_a3 = toolCall.bufferedInputDeltas) != null ? _a3 : []) {
|
|
7437
7509
|
controller.enqueue({
|
|
7438
7510
|
type: "tool-input-delta",
|
|
7439
7511
|
id: toolCall.toolCallId,
|
|
@@ -7538,7 +7610,7 @@ function isResponseOutputChunk(chunk) {
|
|
|
7538
7610
|
return !(chunk.type === "response.created" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
|
|
7539
7611
|
}
|
|
7540
7612
|
function mapWebSearchOutput(action) {
|
|
7541
|
-
var
|
|
7613
|
+
var _a2;
|
|
7542
7614
|
if (action == null) {
|
|
7543
7615
|
return {};
|
|
7544
7616
|
}
|
|
@@ -7547,7 +7619,7 @@ function mapWebSearchOutput(action) {
|
|
|
7547
7619
|
return {
|
|
7548
7620
|
action: {
|
|
7549
7621
|
type: "search",
|
|
7550
|
-
query: (
|
|
7622
|
+
query: (_a2 = action.query) != null ? _a2 : void 0,
|
|
7551
7623
|
...action.queries != null && { queries: action.queries }
|
|
7552
7624
|
},
|
|
7553
7625
|
// include sources when provided by the Responses API (behind include flag)
|
|
@@ -7658,8 +7730,8 @@ var OpenAISpeechModel = class {
|
|
|
7658
7730
|
};
|
|
7659
7731
|
}
|
|
7660
7732
|
async doGenerate(options) {
|
|
7661
|
-
var
|
|
7662
|
-
const currentDate = (_c = (_b = (
|
|
7733
|
+
var _a2, _b, _c;
|
|
7734
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
7663
7735
|
const { requestBody, warnings } = await this.getArgs(options);
|
|
7664
7736
|
const {
|
|
7665
7737
|
value: audio,
|
|
@@ -7893,8 +7965,8 @@ var OpenAITranscriptionModel = class {
|
|
|
7893
7965
|
};
|
|
7894
7966
|
}
|
|
7895
7967
|
async doGenerate(options) {
|
|
7896
|
-
var
|
|
7897
|
-
const currentDate = (_c = (_b = (
|
|
7968
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
7969
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
7898
7970
|
const { formData, warnings } = await this.getArgs(options);
|
|
7899
7971
|
const {
|
|
7900
7972
|
value: response,
|
|
@@ -7940,17 +8012,17 @@ var OpenAITranscriptionModel = class {
|
|
|
7940
8012
|
};
|
|
7941
8013
|
|
|
7942
8014
|
// src/version.ts
|
|
7943
|
-
var VERSION = true ? "3.0.
|
|
8015
|
+
var VERSION = true ? "3.0.104" : "0.0.0-test";
|
|
7944
8016
|
|
|
7945
8017
|
// src/openai-provider.ts
|
|
7946
8018
|
function createOpenAI(options = {}) {
|
|
7947
|
-
var
|
|
7948
|
-
const baseURL = (
|
|
8019
|
+
var _a2, _b;
|
|
8020
|
+
const baseURL = (_a2 = withoutTrailingSlash(
|
|
7949
8021
|
loadOptionalSetting({
|
|
7950
8022
|
settingValue: options.baseURL,
|
|
7951
8023
|
environmentVariableName: "OPENAI_BASE_URL"
|
|
7952
8024
|
})
|
|
7953
|
-
)) != null ?
|
|
8025
|
+
)) != null ? _a2 : "https://api.openai.com/v1";
|
|
7954
8026
|
const providerName = (_b = options.name) != null ? _b : "openai";
|
|
7955
8027
|
const getHeaders = () => withUserAgentSuffix(
|
|
7956
8028
|
{
|