@ai-sdk/openai 4.0.47 → 4.0.50
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 +27 -0
- package/dist/index.d.ts +29 -12
- package/dist/index.js +384 -278
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +45 -26
- package/dist/internal/index.js +280 -170
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +31 -11
- package/package.json +2 -2
- package/src/chat/convert-to-openai-chat-messages.ts +5 -1
- package/src/chat/openai-chat-language-model.ts +9 -2
- package/src/completion/openai-completion-language-model.ts +9 -2
- package/src/embedding/openai-embedding-model.ts +2 -0
- package/src/openai-responses-batch.ts +90 -102
- package/src/openai-stream-error.ts +68 -15
- package/src/responses/convert-to-openai-responses-input.ts +5 -3
- package/src/responses/openai-responses-api.ts +114 -40
- package/src/responses/openai-responses-language-model.ts +35 -21
package/dist/index.js
CHANGED
|
@@ -43,10 +43,10 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
43
43
|
|
|
44
44
|
// src/openai-language-model-capabilities.ts
|
|
45
45
|
function getOpenAILanguageModelCapabilities(modelId) {
|
|
46
|
-
var
|
|
46
|
+
var _a2, _b, _c, _d, _e;
|
|
47
47
|
const oSeriesVersion = getOSeriesVersion(modelId);
|
|
48
48
|
const gptVersion = getGptVersion(modelId);
|
|
49
|
-
const isGptChatModel = (gptVersion == null ? void 0 : gptVersion.minor) == null && ((_b = (
|
|
49
|
+
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);
|
|
50
50
|
const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
|
|
51
51
|
const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
|
|
52
52
|
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
|
|
@@ -79,6 +79,25 @@ function getGptVersion(modelId) {
|
|
|
79
79
|
|
|
80
80
|
// src/openai-stream-error.ts
|
|
81
81
|
import { APICallError } from "@ai-sdk/provider";
|
|
82
|
+
import {
|
|
83
|
+
createProviderStreamError
|
|
84
|
+
} from "@ai-sdk/provider-utils";
|
|
85
|
+
function createOpenAIProviderStreamError(frame) {
|
|
86
|
+
var _a2, _b;
|
|
87
|
+
const streamError = parseStreamError(frame);
|
|
88
|
+
if (streamError == null) {
|
|
89
|
+
return void 0;
|
|
90
|
+
}
|
|
91
|
+
const statusCode = getStatusCode(streamError);
|
|
92
|
+
return createProviderStreamError({
|
|
93
|
+
message: streamError.message,
|
|
94
|
+
type: (_a2 = streamError.type) != null ? _a2 : void 0,
|
|
95
|
+
code: (_b = streamError.code) != null ? _b : void 0,
|
|
96
|
+
statusCode,
|
|
97
|
+
isRetryable: isRetryableStreamError(streamError, statusCode),
|
|
98
|
+
data: frame
|
|
99
|
+
});
|
|
100
|
+
}
|
|
82
101
|
async function throwIfOpenAIStreamErrorBeforeOutput({
|
|
83
102
|
stream,
|
|
84
103
|
getError,
|
|
@@ -175,20 +194,21 @@ function createOpenAIStreamError({
|
|
|
175
194
|
requestBodyValues,
|
|
176
195
|
responseHeaders
|
|
177
196
|
}) {
|
|
178
|
-
var
|
|
179
|
-
const streamError =
|
|
197
|
+
var _a2, _b;
|
|
198
|
+
const streamError = createOpenAIProviderStreamError(frame);
|
|
180
199
|
return new APICallError({
|
|
181
|
-
message: (
|
|
200
|
+
message: (_a2 = streamError == null ? void 0 : streamError.message) != null ? _a2 : "OpenAI stream failed before any output was generated",
|
|
182
201
|
url,
|
|
183
202
|
requestBodyValues,
|
|
184
|
-
statusCode: streamError == null ?
|
|
203
|
+
statusCode: (_b = streamError == null ? void 0 : streamError.statusCode) != null ? _b : 500,
|
|
185
204
|
responseHeaders,
|
|
186
205
|
responseBody: JSON.stringify(frame),
|
|
187
|
-
data: frame
|
|
206
|
+
data: frame,
|
|
207
|
+
isRetryable: streamError == null ? void 0 : streamError.isRetryable
|
|
188
208
|
});
|
|
189
209
|
}
|
|
190
210
|
function parseStreamError(frame) {
|
|
191
|
-
var
|
|
211
|
+
var _a2;
|
|
192
212
|
const value = asRecord(frame);
|
|
193
213
|
if (value == null) {
|
|
194
214
|
return void 0;
|
|
@@ -199,27 +219,20 @@ function parseStreamError(frame) {
|
|
|
199
219
|
return typeof (responseError == null ? void 0 : responseError.message) === "string" ? {
|
|
200
220
|
message: responseError.message,
|
|
201
221
|
code: getStringOrNumber(responseError.code),
|
|
202
|
-
type: "response.failed"
|
|
203
|
-
frame
|
|
222
|
+
type: "response.failed"
|
|
204
223
|
} : void 0;
|
|
205
224
|
}
|
|
206
|
-
const error = (
|
|
225
|
+
const error = (_a2 = asRecord(value.error)) != null ? _a2 : value;
|
|
207
226
|
return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
|
|
208
227
|
message: error.message,
|
|
209
228
|
code: getStringOrNumber(error.code),
|
|
210
|
-
type: typeof error.type === "string" ? error.type : void 0
|
|
211
|
-
frame
|
|
229
|
+
type: typeof error.type === "string" ? error.type : void 0
|
|
212
230
|
} : void 0;
|
|
213
231
|
}
|
|
214
232
|
function getStatusCode(error) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (typeof error.code === "string" && /^\d{3}$/.test(error.code)) {
|
|
219
|
-
const numericCode = Number(error.code);
|
|
220
|
-
if (isHttpErrorStatusCode(numericCode)) {
|
|
221
|
-
return numericCode;
|
|
222
|
-
}
|
|
233
|
+
const explicitStatusCode = getHttpStatusCode(error.code);
|
|
234
|
+
if (explicitStatusCode != null) {
|
|
235
|
+
return explicitStatusCode;
|
|
223
236
|
}
|
|
224
237
|
const discriminator = [error.code, error.type].filter((value) => typeof value === "string" || typeof value === "number").join(" ").toLowerCase();
|
|
225
238
|
if (["insufficient_quota", "rate_limit"].some(
|
|
@@ -248,15 +261,28 @@ function getStringOrNumber(value) {
|
|
|
248
261
|
function isHttpErrorStatusCode(value) {
|
|
249
262
|
return Number.isInteger(value) && value >= 400 && value <= 599;
|
|
250
263
|
}
|
|
264
|
+
function getHttpStatusCode(value) {
|
|
265
|
+
const statusCode = typeof value === "string" && /^\d{3}$/.test(value) ? Number(value) : value;
|
|
266
|
+
return typeof statusCode === "number" && isHttpErrorStatusCode(statusCode) ? statusCode : void 0;
|
|
267
|
+
}
|
|
268
|
+
function isRetryableStatusCode(statusCode) {
|
|
269
|
+
return statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500;
|
|
270
|
+
}
|
|
271
|
+
function isRetryableStreamError(error, statusCode) {
|
|
272
|
+
if (error.code === "insufficient_quota" || error.type === "insufficient_quota") {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
return isRetryableStatusCode(statusCode);
|
|
276
|
+
}
|
|
251
277
|
|
|
252
278
|
// src/chat/convert-openai-chat-usage.ts
|
|
253
279
|
import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
|
|
254
280
|
function convertOpenAIChatUsage(usage) {
|
|
255
|
-
var
|
|
281
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
256
282
|
if (usage == null) {
|
|
257
283
|
return createNullLanguageModelUsage();
|
|
258
284
|
}
|
|
259
|
-
const promptTokens = (
|
|
285
|
+
const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
|
|
260
286
|
const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
|
|
261
287
|
const cachedTokens = (_d = (_c = usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : 0;
|
|
262
288
|
const cacheWriteTokens = (_f = (_e = usage.prompt_tokens_details) == null ? void 0 : _e.cache_write_tokens) != null ? _f : void 0;
|
|
@@ -288,17 +314,19 @@ import {
|
|
|
288
314
|
resolveProviderReference
|
|
289
315
|
} from "@ai-sdk/provider-utils";
|
|
290
316
|
function serializeToolCallArguments(input) {
|
|
291
|
-
return JSON.stringify(
|
|
317
|
+
return JSON.stringify(
|
|
318
|
+
typeof input === "object" && input !== null && !Array.isArray(input) ? input : {}
|
|
319
|
+
);
|
|
292
320
|
}
|
|
293
321
|
function getPromptCacheBreakpoint(providerOptions) {
|
|
294
|
-
var
|
|
295
|
-
return (
|
|
322
|
+
var _a2;
|
|
323
|
+
return (_a2 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
296
324
|
}
|
|
297
325
|
function convertToOpenAIChatMessages({
|
|
298
326
|
prompt,
|
|
299
327
|
systemMessageMode = "system"
|
|
300
328
|
}) {
|
|
301
|
-
var
|
|
329
|
+
var _a2, _b;
|
|
302
330
|
const messages = [];
|
|
303
331
|
const warnings = [];
|
|
304
332
|
for (const { role, content, providerOptions } of prompt) {
|
|
@@ -357,7 +385,7 @@ function convertToOpenAIChatMessages({
|
|
|
357
385
|
messages.push({
|
|
358
386
|
role: "user",
|
|
359
387
|
content: content.map((part, index) => {
|
|
360
|
-
var
|
|
388
|
+
var _a3, _b2, _c;
|
|
361
389
|
switch (part.type) {
|
|
362
390
|
case "text": {
|
|
363
391
|
const promptCacheBreakpoint = getPromptCacheBreakpoint(
|
|
@@ -403,7 +431,7 @@ function convertToOpenAIChatMessages({
|
|
|
403
431
|
type: "image_url",
|
|
404
432
|
image_url: {
|
|
405
433
|
url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`,
|
|
406
|
-
detail: (_b2 = (
|
|
434
|
+
detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3.openai) == null ? void 0 : _b2.imageDetail
|
|
407
435
|
},
|
|
408
436
|
...promptCacheBreakpoint != null && {
|
|
409
437
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
@@ -528,7 +556,7 @@ function convertToOpenAIChatMessages({
|
|
|
528
556
|
continue;
|
|
529
557
|
}
|
|
530
558
|
const output = toolResponse.output;
|
|
531
|
-
const promptCacheBreakpoint = (
|
|
559
|
+
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);
|
|
532
560
|
let contentValue;
|
|
533
561
|
switch (output.type) {
|
|
534
562
|
case "text":
|
|
@@ -983,13 +1011,13 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
983
1011
|
reasoning,
|
|
984
1012
|
providerOptions
|
|
985
1013
|
}) {
|
|
986
|
-
var
|
|
1014
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
987
1015
|
const warnings = [];
|
|
988
|
-
const openaiOptions = (
|
|
1016
|
+
const openaiOptions = (_a2 = await parseProviderOptions({
|
|
989
1017
|
provider: "openai",
|
|
990
1018
|
providerOptions,
|
|
991
1019
|
schema: openaiLanguageModelChatOptions
|
|
992
|
-
})) != null ?
|
|
1020
|
+
})) != null ? _a2 : {};
|
|
993
1021
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
994
1022
|
const resolvedReasoningEffort = (_b = openaiOptions.reasoningEffort) != null ? _b : isCustomReasoning(reasoning) ? reasoning : void 0;
|
|
995
1023
|
const isReasoningModel = (_c = openaiOptions.forceReasoning) != null ? _c : modelCapabilities.isReasoningModel;
|
|
@@ -1152,7 +1180,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1152
1180
|
};
|
|
1153
1181
|
}
|
|
1154
1182
|
async doGenerate(options) {
|
|
1155
|
-
var
|
|
1183
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
1156
1184
|
const { args: body, warnings } = await this.getArgs(options);
|
|
1157
1185
|
const {
|
|
1158
1186
|
responseHeaders,
|
|
@@ -1163,7 +1191,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1163
1191
|
path: "/chat/completions",
|
|
1164
1192
|
modelId: this.modelId
|
|
1165
1193
|
}),
|
|
1166
|
-
headers: combineHeaders((_b = (
|
|
1194
|
+
headers: combineHeaders((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
1167
1195
|
body,
|
|
1168
1196
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1169
1197
|
successfulResponseHandler: createJsonResponseHandler(
|
|
@@ -1224,7 +1252,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1224
1252
|
};
|
|
1225
1253
|
}
|
|
1226
1254
|
async doStream(options) {
|
|
1227
|
-
var
|
|
1255
|
+
var _a2, _b;
|
|
1228
1256
|
const { args, warnings } = await this.getArgs(options);
|
|
1229
1257
|
const body = {
|
|
1230
1258
|
...args,
|
|
@@ -1239,7 +1267,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1239
1267
|
});
|
|
1240
1268
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
1241
1269
|
url,
|
|
1242
|
-
headers: combineHeaders((_b = (
|
|
1270
|
+
headers: combineHeaders((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
1243
1271
|
body,
|
|
1244
1272
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1245
1273
|
successfulResponseHandler: createEventSourceResponseHandler(
|
|
@@ -1276,7 +1304,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1276
1304
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1277
1305
|
},
|
|
1278
1306
|
transform(chunk, controller) {
|
|
1279
|
-
var
|
|
1307
|
+
var _a3, _b2, _c, _d, _e, _f;
|
|
1280
1308
|
if (options.includeRawChunks) {
|
|
1281
1309
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1282
1310
|
}
|
|
@@ -1288,7 +1316,10 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1288
1316
|
const value = chunk.value;
|
|
1289
1317
|
if ("error" in value) {
|
|
1290
1318
|
finishReason = { unified: "error", raw: void 0 };
|
|
1291
|
-
controller.enqueue({
|
|
1319
|
+
controller.enqueue({
|
|
1320
|
+
type: "error",
|
|
1321
|
+
error: (_a3 = createOpenAIProviderStreamError(value.error)) != null ? _a3 : value.error
|
|
1322
|
+
});
|
|
1292
1323
|
return;
|
|
1293
1324
|
}
|
|
1294
1325
|
if (!metadataExtracted) {
|
|
@@ -1303,11 +1334,11 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1303
1334
|
}
|
|
1304
1335
|
if (value.usage != null) {
|
|
1305
1336
|
usage = value.usage;
|
|
1306
|
-
if (((
|
|
1307
|
-
providerMetadata.openai.acceptedPredictionTokens = (
|
|
1337
|
+
if (((_b2 = value.usage.completion_tokens_details) == null ? void 0 : _b2.accepted_prediction_tokens) != null) {
|
|
1338
|
+
providerMetadata.openai.acceptedPredictionTokens = (_c = value.usage.completion_tokens_details) == null ? void 0 : _c.accepted_prediction_tokens;
|
|
1308
1339
|
}
|
|
1309
|
-
if (((
|
|
1310
|
-
providerMetadata.openai.rejectedPredictionTokens = (
|
|
1340
|
+
if (((_d = value.usage.completion_tokens_details) == null ? void 0 : _d.rejected_prediction_tokens) != null) {
|
|
1341
|
+
providerMetadata.openai.rejectedPredictionTokens = (_e = value.usage.completion_tokens_details) == null ? void 0 : _e.rejected_prediction_tokens;
|
|
1311
1342
|
}
|
|
1312
1343
|
}
|
|
1313
1344
|
const choice = value.choices[0];
|
|
@@ -1317,7 +1348,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1317
1348
|
raw: choice.finish_reason
|
|
1318
1349
|
};
|
|
1319
1350
|
}
|
|
1320
|
-
if (((
|
|
1351
|
+
if (((_f = choice == null ? void 0 : choice.logprobs) == null ? void 0 : _f.content) != null) {
|
|
1321
1352
|
providerMetadata.openai.logprobs = choice.logprobs.content;
|
|
1322
1353
|
}
|
|
1323
1354
|
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
@@ -1397,11 +1428,11 @@ import {
|
|
|
1397
1428
|
// src/completion/convert-openai-completion-usage.ts
|
|
1398
1429
|
import { createNullLanguageModelUsage as createNullLanguageModelUsage2 } from "@ai-sdk/provider-utils";
|
|
1399
1430
|
function convertOpenAICompletionUsage(usage) {
|
|
1400
|
-
var
|
|
1431
|
+
var _a2, _b, _c, _d;
|
|
1401
1432
|
if (usage == null) {
|
|
1402
1433
|
return createNullLanguageModelUsage2();
|
|
1403
1434
|
}
|
|
1404
|
-
const promptTokens = (
|
|
1435
|
+
const promptTokens = (_a2 = usage.prompt_tokens) != null ? _a2 : 0;
|
|
1405
1436
|
const completionTokens = (_b = usage.completion_tokens) != null ? _b : 0;
|
|
1406
1437
|
return {
|
|
1407
1438
|
inputTokens: {
|
|
@@ -1726,7 +1757,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1726
1757
|
};
|
|
1727
1758
|
}
|
|
1728
1759
|
async doGenerate(options) {
|
|
1729
|
-
var
|
|
1760
|
+
var _a2, _b, _c;
|
|
1730
1761
|
const { args, warnings } = await this.getArgs(options);
|
|
1731
1762
|
const {
|
|
1732
1763
|
responseHeaders,
|
|
@@ -1737,7 +1768,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1737
1768
|
path: "/completions",
|
|
1738
1769
|
modelId: this.modelId
|
|
1739
1770
|
}),
|
|
1740
|
-
headers: combineHeaders2((_b = (
|
|
1771
|
+
headers: combineHeaders2((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
1741
1772
|
body: args,
|
|
1742
1773
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1743
1774
|
successfulResponseHandler: createJsonResponseHandler2(
|
|
@@ -1769,7 +1800,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1769
1800
|
};
|
|
1770
1801
|
}
|
|
1771
1802
|
async doStream(options) {
|
|
1772
|
-
var
|
|
1803
|
+
var _a2, _b;
|
|
1773
1804
|
const { args, warnings } = await this.getArgs(options);
|
|
1774
1805
|
const body = {
|
|
1775
1806
|
...args,
|
|
@@ -1784,7 +1815,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1784
1815
|
});
|
|
1785
1816
|
const { responseHeaders, value: response } = await postJsonToApi2({
|
|
1786
1817
|
url,
|
|
1787
|
-
headers: combineHeaders2((_b = (
|
|
1818
|
+
headers: combineHeaders2((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
1788
1819
|
body,
|
|
1789
1820
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1790
1821
|
successfulResponseHandler: createEventSourceResponseHandler2(
|
|
@@ -1815,6 +1846,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1815
1846
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1816
1847
|
},
|
|
1817
1848
|
transform(chunk, controller) {
|
|
1849
|
+
var _a3;
|
|
1818
1850
|
if (options.includeRawChunks) {
|
|
1819
1851
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1820
1852
|
}
|
|
@@ -1826,7 +1858,10 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1826
1858
|
const value = chunk.value;
|
|
1827
1859
|
if ("error" in value) {
|
|
1828
1860
|
finishReason = { unified: "error", raw: void 0 };
|
|
1829
|
-
controller.enqueue({
|
|
1861
|
+
controller.enqueue({
|
|
1862
|
+
type: "error",
|
|
1863
|
+
error: (_a3 = createOpenAIProviderStreamError(value.error)) != null ? _a3 : value.error
|
|
1864
|
+
});
|
|
1830
1865
|
return;
|
|
1831
1866
|
}
|
|
1832
1867
|
if (isFirstChunk) {
|
|
@@ -1888,6 +1923,7 @@ import {
|
|
|
1888
1923
|
import {
|
|
1889
1924
|
combineHeaders as combineHeaders3,
|
|
1890
1925
|
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1926
|
+
EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL,
|
|
1891
1927
|
parseProviderOptions as parseProviderOptions3,
|
|
1892
1928
|
postJsonToApi as postJsonToApi3,
|
|
1893
1929
|
serializeModelOptions as serializeModelOptions3,
|
|
@@ -1931,15 +1967,17 @@ var openaiTextEmbeddingResponseSchema = lazySchema6(
|
|
|
1931
1967
|
);
|
|
1932
1968
|
|
|
1933
1969
|
// src/embedding/openai-embedding-model.ts
|
|
1970
|
+
var _a;
|
|
1934
1971
|
var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
|
|
1935
1972
|
constructor(modelId, config) {
|
|
1936
1973
|
this.specificationVersion = "v4";
|
|
1937
1974
|
this.maxEmbeddingsPerCall = 2048;
|
|
1975
|
+
this[_a] = 3e5;
|
|
1938
1976
|
this.supportsParallelCalls = true;
|
|
1939
1977
|
this.modelId = modelId;
|
|
1940
1978
|
this.config = config;
|
|
1941
1979
|
}
|
|
1942
|
-
static [WORKFLOW_SERIALIZE3](model) {
|
|
1980
|
+
static [(_a = EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, WORKFLOW_SERIALIZE3)](model) {
|
|
1943
1981
|
return serializeModelOptions3({
|
|
1944
1982
|
modelId: model.modelId,
|
|
1945
1983
|
config: model.config
|
|
@@ -1957,7 +1995,7 @@ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
|
|
|
1957
1995
|
abortSignal,
|
|
1958
1996
|
providerOptions
|
|
1959
1997
|
}) {
|
|
1960
|
-
var
|
|
1998
|
+
var _a2, _b, _c;
|
|
1961
1999
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
1962
2000
|
throw new TooManyEmbeddingValuesForCallError({
|
|
1963
2001
|
provider: this.provider,
|
|
@@ -1966,11 +2004,11 @@ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
|
|
|
1966
2004
|
values
|
|
1967
2005
|
});
|
|
1968
2006
|
}
|
|
1969
|
-
const openaiOptions = (
|
|
2007
|
+
const openaiOptions = (_a2 = await parseProviderOptions3({
|
|
1970
2008
|
provider: "openai",
|
|
1971
2009
|
providerOptions,
|
|
1972
2010
|
schema: openaiEmbeddingModelOptions
|
|
1973
|
-
})) != null ?
|
|
2011
|
+
})) != null ? _a2 : {};
|
|
1974
2012
|
const {
|
|
1975
2013
|
responseHeaders,
|
|
1976
2014
|
value: response,
|
|
@@ -2066,7 +2104,7 @@ var OpenAIFiles = class {
|
|
|
2066
2104
|
filename,
|
|
2067
2105
|
providerOptions
|
|
2068
2106
|
}) {
|
|
2069
|
-
var
|
|
2107
|
+
var _a2, _b, _c;
|
|
2070
2108
|
const openaiOptions = await parseProviderOptions4({
|
|
2071
2109
|
provider: "openai",
|
|
2072
2110
|
providerOptions,
|
|
@@ -2082,7 +2120,7 @@ var OpenAIFiles = class {
|
|
|
2082
2120
|
} else {
|
|
2083
2121
|
formData.append("file", blob);
|
|
2084
2122
|
}
|
|
2085
|
-
formData.append("purpose", (
|
|
2123
|
+
formData.append("purpose", (_a2 = openaiOptions == null ? void 0 : openaiOptions.purpose) != null ? _a2 : "assistants");
|
|
2086
2124
|
if ((openaiOptions == null ? void 0 : openaiOptions.expiresAfter) != null) {
|
|
2087
2125
|
formData.append("expires_after[anchor]", "created_at");
|
|
2088
2126
|
formData.append(
|
|
@@ -2186,8 +2224,8 @@ function hasDefaultResponseFormat(modelId) {
|
|
|
2186
2224
|
);
|
|
2187
2225
|
}
|
|
2188
2226
|
function getMaxImagesPerCall(modelId) {
|
|
2189
|
-
var
|
|
2190
|
-
return (
|
|
2227
|
+
var _a2;
|
|
2228
|
+
return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
|
|
2191
2229
|
}
|
|
2192
2230
|
var baseImageModelOptionsObject = z11.object({
|
|
2193
2231
|
/**
|
|
@@ -2283,7 +2321,7 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2283
2321
|
headers,
|
|
2284
2322
|
abortSignal
|
|
2285
2323
|
}) {
|
|
2286
|
-
var
|
|
2324
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
2287
2325
|
const warnings = [];
|
|
2288
2326
|
if (aspectRatio != null) {
|
|
2289
2327
|
warnings.push({
|
|
@@ -2295,7 +2333,7 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2295
2333
|
if (seed != null) {
|
|
2296
2334
|
warnings.push({ type: "unsupported", feature: "seed" });
|
|
2297
2335
|
}
|
|
2298
|
-
const currentDate = (_c = (_b = (
|
|
2336
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
2299
2337
|
if (files != null) {
|
|
2300
2338
|
const openaiOptions2 = (_d = await parseProviderOptions5({
|
|
2301
2339
|
provider: "openai",
|
|
@@ -2358,10 +2396,10 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2358
2396
|
providerMetadata: {
|
|
2359
2397
|
openai: {
|
|
2360
2398
|
images: response2.data.map((item, index) => {
|
|
2361
|
-
var
|
|
2399
|
+
var _a3, _b2, _c2, _d2, _e2, _f2;
|
|
2362
2400
|
return {
|
|
2363
2401
|
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
|
|
2364
|
-
created: (
|
|
2402
|
+
created: (_a3 = response2.created) != null ? _a3 : void 0,
|
|
2365
2403
|
size: (_b2 = response2.size) != null ? _b2 : void 0,
|
|
2366
2404
|
quality: (_c2 = response2.quality) != null ? _c2 : void 0,
|
|
2367
2405
|
background: (_d2 = response2.background) != null ? _d2 : void 0,
|
|
@@ -2425,10 +2463,10 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2425
2463
|
providerMetadata: {
|
|
2426
2464
|
openai: {
|
|
2427
2465
|
images: response.data.map((item, index) => {
|
|
2428
|
-
var
|
|
2466
|
+
var _a3, _b2, _c2, _d2, _e2, _f2;
|
|
2429
2467
|
return {
|
|
2430
2468
|
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
|
|
2431
|
-
created: (
|
|
2469
|
+
created: (_a3 = response.created) != null ? _a3 : void 0,
|
|
2432
2470
|
size: (_b2 = response.size) != null ? _b2 : void 0,
|
|
2433
2471
|
quality: (_c2 = response.quality) != null ? _c2 : void 0,
|
|
2434
2472
|
background: (_d2 = response.background) != null ? _d2 : void 0,
|
|
@@ -3167,7 +3205,7 @@ var programmaticToolCallingFactory = createProviderExecutedToolFactory7({
|
|
|
3167
3205
|
var programmaticToolCalling = () => experimental_toolCaller(programmaticToolCallingFactory({}), {
|
|
3168
3206
|
type: "provider",
|
|
3169
3207
|
prepareProviderOptions: (providerOptions) => {
|
|
3170
|
-
var
|
|
3208
|
+
var _a2;
|
|
3171
3209
|
const openaiOptions = providerOptions == null ? void 0 : providerOptions.openai;
|
|
3172
3210
|
return {
|
|
3173
3211
|
...providerOptions,
|
|
@@ -3175,7 +3213,7 @@ var programmaticToolCalling = () => experimental_toolCaller(programmaticToolCall
|
|
|
3175
3213
|
...openaiOptions,
|
|
3176
3214
|
allowedCallers: [
|
|
3177
3215
|
.../* @__PURE__ */ new Set([
|
|
3178
|
-
...(
|
|
3216
|
+
...(_a2 = openaiOptions == null ? void 0 : openaiOptions.allowedCallers) != null ? _a2 : [],
|
|
3179
3217
|
"programmatic"
|
|
3180
3218
|
])
|
|
3181
3219
|
]
|
|
@@ -3317,20 +3355,20 @@ var openaiTools = {
|
|
|
3317
3355
|
|
|
3318
3356
|
// src/openai-responses-batch.ts
|
|
3319
3357
|
import {
|
|
3320
|
-
|
|
3321
|
-
|
|
3358
|
+
InvalidArgumentError,
|
|
3359
|
+
InvalidResponseDataError
|
|
3322
3360
|
} from "@ai-sdk/provider";
|
|
3323
3361
|
import {
|
|
3324
3362
|
combineHeaders as combineHeaders7,
|
|
3325
3363
|
convertAsyncIteratorToReadableStream,
|
|
3364
|
+
createJsonLinesResponseHandler,
|
|
3326
3365
|
createJsonResponseHandler as createJsonResponseHandler7,
|
|
3327
3366
|
getFromApi,
|
|
3328
3367
|
lazySchema as lazySchema26,
|
|
3329
|
-
|
|
3368
|
+
normalizeBatchRequestCounts,
|
|
3330
3369
|
postJsonToApi as postJsonToApi6,
|
|
3331
3370
|
postToApi,
|
|
3332
3371
|
safeValidateTypes,
|
|
3333
|
-
validateTypes as validateTypes3,
|
|
3334
3372
|
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE6,
|
|
3335
3373
|
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE6,
|
|
3336
3374
|
zodSchema as zodSchema26
|
|
@@ -3340,13 +3378,13 @@ import { z as z28 } from "zod/v4";
|
|
|
3340
3378
|
// src/responses/convert-openai-responses-usage.ts
|
|
3341
3379
|
import { createNullLanguageModelUsage as createNullLanguageModelUsage3 } from "@ai-sdk/provider-utils";
|
|
3342
3380
|
function convertOpenAIResponsesUsage(usage) {
|
|
3343
|
-
var
|
|
3381
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
3344
3382
|
if (usage == null) {
|
|
3345
3383
|
return createNullLanguageModelUsage3();
|
|
3346
3384
|
}
|
|
3347
3385
|
const inputTokens = usage.input_tokens;
|
|
3348
3386
|
const outputTokens = usage.output_tokens;
|
|
3349
|
-
const cachedTokens = (_b = (
|
|
3387
|
+
const cachedTokens = (_b = (_a2 = usage.input_tokens_details) == null ? void 0 : _a2.cached_tokens) != null ? _b : 0;
|
|
3350
3388
|
const cacheWriteTokens = (_d = (_c = usage.input_tokens_details) == null ? void 0 : _c.cache_write_tokens) != null ? _d : void 0;
|
|
3351
3389
|
const reasoningTokens = (_f = (_e = usage.output_tokens_details) == null ? void 0 : _e.reasoning_tokens) != null ? _f : 0;
|
|
3352
3390
|
return {
|
|
@@ -3385,6 +3423,7 @@ function mapOpenAIResponseFinishReason({
|
|
|
3385
3423
|
|
|
3386
3424
|
// src/responses/openai-responses-api.ts
|
|
3387
3425
|
import {
|
|
3426
|
+
isRecord,
|
|
3388
3427
|
lazySchema as lazySchema24,
|
|
3389
3428
|
zodSchema as zodSchema24
|
|
3390
3429
|
} from "@ai-sdk/provider-utils";
|
|
@@ -3482,6 +3521,19 @@ var openaiResponsesProgramOutputSchema = z25.object({
|
|
|
3482
3521
|
result: z25.string(),
|
|
3483
3522
|
status: z25.enum(["completed", "incomplete"])
|
|
3484
3523
|
});
|
|
3524
|
+
var openaiResponsesLocalShellCallSchema = z25.object({
|
|
3525
|
+
type: z25.literal("local_shell_call"),
|
|
3526
|
+
id: z25.string(),
|
|
3527
|
+
call_id: z25.string(),
|
|
3528
|
+
action: z25.object({
|
|
3529
|
+
type: z25.literal("exec"),
|
|
3530
|
+
command: z25.array(z25.string()),
|
|
3531
|
+
timeout_ms: z25.number().optional(),
|
|
3532
|
+
user: z25.string().optional(),
|
|
3533
|
+
working_directory: z25.string().optional(),
|
|
3534
|
+
env: z25.record(z25.string(), z25.string()).optional()
|
|
3535
|
+
})
|
|
3536
|
+
});
|
|
3485
3537
|
var openaiResponsesNestedErrorChunkSchema = z25.object({
|
|
3486
3538
|
type: z25.literal("error"),
|
|
3487
3539
|
sequence_number: z25.number(),
|
|
@@ -3499,6 +3551,64 @@ var openaiResponsesErrorChunkSchema = z25.object({
|
|
|
3499
3551
|
message: z25.string(),
|
|
3500
3552
|
param: z25.string().nullish()
|
|
3501
3553
|
});
|
|
3554
|
+
var openaiResponsesModeledChunkTypes = /* @__PURE__ */ new Set([
|
|
3555
|
+
"error",
|
|
3556
|
+
"response.apply_patch_call_operation_diff.delta",
|
|
3557
|
+
"response.apply_patch_call_operation_diff.done",
|
|
3558
|
+
"response.code_interpreter_call_code.delta",
|
|
3559
|
+
"response.code_interpreter_call_code.done",
|
|
3560
|
+
"response.completed",
|
|
3561
|
+
"response.created",
|
|
3562
|
+
"response.custom_tool_call_input.delta",
|
|
3563
|
+
"response.failed",
|
|
3564
|
+
"response.function_call_arguments.delta",
|
|
3565
|
+
"response.function_call_arguments.done",
|
|
3566
|
+
"response.image_generation_call.partial_image",
|
|
3567
|
+
"response.in_progress",
|
|
3568
|
+
"response.incomplete",
|
|
3569
|
+
"response.output_item.added",
|
|
3570
|
+
"response.output_item.done",
|
|
3571
|
+
"response.output_text.annotation.added",
|
|
3572
|
+
"response.output_text.delta",
|
|
3573
|
+
"response.reasoning_summary_part.added",
|
|
3574
|
+
"response.reasoning_summary_part.done",
|
|
3575
|
+
"response.reasoning_summary_text.delta"
|
|
3576
|
+
]);
|
|
3577
|
+
var openaiResponsesModeledOutputItemTypes = /* @__PURE__ */ new Set([
|
|
3578
|
+
"apply_patch_call",
|
|
3579
|
+
"code_interpreter_call",
|
|
3580
|
+
"compaction",
|
|
3581
|
+
"computer_call",
|
|
3582
|
+
"custom_tool_call",
|
|
3583
|
+
"file_search_call",
|
|
3584
|
+
"function_call",
|
|
3585
|
+
"image_generation_call",
|
|
3586
|
+
"local_shell_call",
|
|
3587
|
+
"mcp_approval_request",
|
|
3588
|
+
"mcp_call",
|
|
3589
|
+
"mcp_list_tools",
|
|
3590
|
+
"message",
|
|
3591
|
+
"program",
|
|
3592
|
+
"program_output",
|
|
3593
|
+
"reasoning",
|
|
3594
|
+
"shell_call",
|
|
3595
|
+
"shell_call_output",
|
|
3596
|
+
"tool_search_call",
|
|
3597
|
+
"tool_search_output",
|
|
3598
|
+
"web_search_call"
|
|
3599
|
+
]);
|
|
3600
|
+
function isModeledOpenAIResponsesChunk(value) {
|
|
3601
|
+
if (typeof value.type !== "string" || !openaiResponsesModeledChunkTypes.has(value.type)) {
|
|
3602
|
+
return false;
|
|
3603
|
+
}
|
|
3604
|
+
if (value.type !== "response.output_item.added" && value.type !== "response.output_item.done") {
|
|
3605
|
+
return true;
|
|
3606
|
+
}
|
|
3607
|
+
if (!isRecord(value.item) || typeof value.item.type !== "string") {
|
|
3608
|
+
return true;
|
|
3609
|
+
}
|
|
3610
|
+
return openaiResponsesModeledOutputItemTypes.has(value.item.type);
|
|
3611
|
+
}
|
|
3502
3612
|
var openaiResponsesChunkSchema = lazySchema24(
|
|
3503
3613
|
() => zodSchema24(
|
|
3504
3614
|
z25.union([
|
|
@@ -3626,6 +3736,7 @@ var openaiResponsesChunkSchema = lazySchema24(
|
|
|
3626
3736
|
type: z25.literal("file_search_call"),
|
|
3627
3737
|
id: z25.string()
|
|
3628
3738
|
}),
|
|
3739
|
+
openaiResponsesLocalShellCallSchema,
|
|
3629
3740
|
z25.object({
|
|
3630
3741
|
type: z25.literal("image_generation_call"),
|
|
3631
3742
|
id: z25.string()
|
|
@@ -3832,19 +3943,7 @@ var openaiResponsesChunkSchema = lazySchema24(
|
|
|
3832
3943
|
})
|
|
3833
3944
|
).nullish()
|
|
3834
3945
|
}),
|
|
3835
|
-
|
|
3836
|
-
type: z25.literal("local_shell_call"),
|
|
3837
|
-
id: z25.string(),
|
|
3838
|
-
call_id: z25.string(),
|
|
3839
|
-
action: z25.object({
|
|
3840
|
-
type: z25.literal("exec"),
|
|
3841
|
-
command: z25.array(z25.string()),
|
|
3842
|
-
timeout_ms: z25.number().optional(),
|
|
3843
|
-
user: z25.string().optional(),
|
|
3844
|
-
working_directory: z25.string().optional(),
|
|
3845
|
-
env: z25.record(z25.string(), z25.string()).optional()
|
|
3846
|
-
})
|
|
3847
|
-
}),
|
|
3946
|
+
openaiResponsesLocalShellCallSchema,
|
|
3848
3947
|
openaiResponsesComputerCallSchema,
|
|
3849
3948
|
z25.object({
|
|
3850
3949
|
type: z25.literal("mcp_call"),
|
|
@@ -3972,6 +4071,14 @@ var openaiResponsesChunkSchema = lazySchema24(
|
|
|
3972
4071
|
output_index: z25.number(),
|
|
3973
4072
|
delta: z25.string()
|
|
3974
4073
|
}),
|
|
4074
|
+
z25.object({
|
|
4075
|
+
// `name` is documented as required but omitted from live API events:
|
|
4076
|
+
// https://github.com/openai/openai-openapi/issues/545
|
|
4077
|
+
type: z25.literal("response.function_call_arguments.done"),
|
|
4078
|
+
item_id: z25.string(),
|
|
4079
|
+
output_index: z25.number(),
|
|
4080
|
+
arguments: z25.string()
|
|
4081
|
+
}),
|
|
3975
4082
|
z25.object({
|
|
3976
4083
|
type: z25.literal("response.custom_tool_call_input.delta"),
|
|
3977
4084
|
item_id: z25.string(),
|
|
@@ -4061,7 +4168,9 @@ var openaiResponsesChunkSchema = lazySchema24(
|
|
|
4061
4168
|
}),
|
|
4062
4169
|
openaiResponsesNestedErrorChunkSchema,
|
|
4063
4170
|
openaiResponsesErrorChunkSchema,
|
|
4064
|
-
z25.object({ type: z25.string() }).loose().
|
|
4171
|
+
z25.object({ type: z25.string() }).loose().refine((value) => !isModeledOpenAIResponsesChunk(value), {
|
|
4172
|
+
message: "Known response chunk failed schema validation"
|
|
4173
|
+
}).transform((value) => ({
|
|
4065
4174
|
type: "unknown_chunk",
|
|
4066
4175
|
message: value.type
|
|
4067
4176
|
}))
|
|
@@ -4201,19 +4310,7 @@ var openaiResponsesResponseSchema = lazySchema24(
|
|
|
4201
4310
|
id: z25.string(),
|
|
4202
4311
|
result: z25.string()
|
|
4203
4312
|
}),
|
|
4204
|
-
|
|
4205
|
-
type: z25.literal("local_shell_call"),
|
|
4206
|
-
id: z25.string(),
|
|
4207
|
-
call_id: z25.string(),
|
|
4208
|
-
action: z25.object({
|
|
4209
|
-
type: z25.literal("exec"),
|
|
4210
|
-
command: z25.array(z25.string()),
|
|
4211
|
-
timeout_ms: z25.number().optional(),
|
|
4212
|
-
user: z25.string().optional(),
|
|
4213
|
-
working_directory: z25.string().optional(),
|
|
4214
|
-
env: z25.record(z25.string(), z25.string()).optional()
|
|
4215
|
-
})
|
|
4216
|
-
}),
|
|
4313
|
+
openaiResponsesLocalShellCallSchema,
|
|
4217
4314
|
z25.object({
|
|
4218
4315
|
type: z25.literal("function_call"),
|
|
4219
4316
|
call_id: z25.string(),
|
|
@@ -4432,8 +4529,8 @@ function getParallelToolCallMetadata({
|
|
|
4432
4529
|
providerOptions,
|
|
4433
4530
|
providerOptionsName
|
|
4434
4531
|
}) {
|
|
4435
|
-
var
|
|
4436
|
-
const metadata = (
|
|
4532
|
+
var _a2;
|
|
4533
|
+
const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
|
|
4437
4534
|
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) {
|
|
4438
4535
|
return void 0;
|
|
4439
4536
|
}
|
|
@@ -4513,14 +4610,14 @@ async function convertFunctionToolResultOutput({
|
|
|
4513
4610
|
providerOptionsName,
|
|
4514
4611
|
warnings
|
|
4515
4612
|
}) {
|
|
4516
|
-
var
|
|
4613
|
+
var _a2;
|
|
4517
4614
|
const hasOutputSchema = outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.has(toolName);
|
|
4518
4615
|
switch (output.type) {
|
|
4519
4616
|
case "text":
|
|
4520
4617
|
case "error-text":
|
|
4521
4618
|
return hasOutputSchema ? JSON.stringify(output.value) : output.value;
|
|
4522
4619
|
case "execution-denied": {
|
|
4523
|
-
const reason = (
|
|
4620
|
+
const reason = (_a2 = output.reason) != null ? _a2 : "Tool call execution denied.";
|
|
4524
4621
|
return hasOutputSchema ? JSON.stringify(reason) : reason;
|
|
4525
4622
|
}
|
|
4526
4623
|
case "json":
|
|
@@ -4528,7 +4625,7 @@ async function convertFunctionToolResultOutput({
|
|
|
4528
4625
|
return JSON.stringify(output.value);
|
|
4529
4626
|
case "content":
|
|
4530
4627
|
return output.value.map((item) => {
|
|
4531
|
-
var
|
|
4628
|
+
var _a3, _b, _c;
|
|
4532
4629
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
4533
4630
|
item.providerOptions,
|
|
4534
4631
|
providerOptionsName
|
|
@@ -4545,7 +4642,7 @@ async function convertFunctionToolResultOutput({
|
|
|
4545
4642
|
}
|
|
4546
4643
|
case "file": {
|
|
4547
4644
|
const topLevel = getTopLevelMediaType2(item.mediaType);
|
|
4548
|
-
const imageDetail = (_b = (
|
|
4645
|
+
const imageDetail = (_b = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b.imageDetail;
|
|
4549
4646
|
if (item.data.type === "data") {
|
|
4550
4647
|
const fullMediaType = resolveFullMediaType2({ part: item });
|
|
4551
4648
|
if (topLevel === "image") {
|
|
@@ -4661,8 +4758,8 @@ function collectCompleteParallelToolResultGroups({
|
|
|
4661
4758
|
return completeGroups;
|
|
4662
4759
|
}
|
|
4663
4760
|
function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
|
|
4664
|
-
var
|
|
4665
|
-
return (
|
|
4761
|
+
var _a2;
|
|
4762
|
+
return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
4666
4763
|
}
|
|
4667
4764
|
function isFileId(data, prefixes) {
|
|
4668
4765
|
if (!prefixes) return false;
|
|
@@ -4682,10 +4779,11 @@ async function convertToOpenAIResponsesInput({
|
|
|
4682
4779
|
hasShellTool = false,
|
|
4683
4780
|
hasApplyPatchTool = false,
|
|
4684
4781
|
hasComputerTool = false,
|
|
4782
|
+
toolSearchToolName,
|
|
4685
4783
|
customProviderToolNames,
|
|
4686
4784
|
outputSchemaToolNames
|
|
4687
4785
|
}) {
|
|
4688
|
-
var
|
|
4786
|
+
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, _F, _G, _H, _I, _J, _K;
|
|
4689
4787
|
let input = [];
|
|
4690
4788
|
const warnings = [];
|
|
4691
4789
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
@@ -4753,7 +4851,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4753
4851
|
input.push({
|
|
4754
4852
|
role: "user",
|
|
4755
4853
|
content: content.map((part, index) => {
|
|
4756
|
-
var
|
|
4854
|
+
var _a3, _b2, _c2, _d2, _e2;
|
|
4757
4855
|
switch (part.type) {
|
|
4758
4856
|
case "text": {
|
|
4759
4857
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
@@ -4783,7 +4881,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4783
4881
|
return {
|
|
4784
4882
|
type: "input_image",
|
|
4785
4883
|
file_id: fileId,
|
|
4786
|
-
detail: (_b2 = (
|
|
4884
|
+
detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
4787
4885
|
...promptCacheBreakpoint != null && {
|
|
4788
4886
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
4789
4887
|
}
|
|
@@ -4856,7 +4954,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4856
4954
|
for (const part of content) {
|
|
4857
4955
|
switch (part.type) {
|
|
4858
4956
|
case "text": {
|
|
4859
|
-
const providerOptions2 = (
|
|
4957
|
+
const providerOptions2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName];
|
|
4860
4958
|
const id = providerOptions2 == null ? void 0 : providerOptions2.itemId;
|
|
4861
4959
|
const phase = providerOptions2 == null ? void 0 : providerOptions2.phase;
|
|
4862
4960
|
if (hasConversation && id != null) {
|
|
@@ -4912,7 +5010,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4912
5010
|
const resolvedToolName = toolNameMapping.toProviderToolName(
|
|
4913
5011
|
part.toolName
|
|
4914
5012
|
);
|
|
4915
|
-
if (
|
|
5013
|
+
if (part.toolName === toolSearchToolName) {
|
|
4916
5014
|
if (store && id != null) {
|
|
4917
5015
|
input.push({ type: "item_reference", id });
|
|
4918
5016
|
break;
|
|
@@ -5101,7 +5199,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
5101
5199
|
const resolvedResultToolName = toolNameMapping.toProviderToolName(
|
|
5102
5200
|
part.toolName
|
|
5103
5201
|
);
|
|
5104
|
-
if (
|
|
5202
|
+
if (part.toolName === toolSearchToolName) {
|
|
5105
5203
|
const itemId = (_u = (_t = (_q = (_p = part.providerOptions) == null ? void 0 : _p[providerOptionsName]) == null ? void 0 : _q.itemId) != null ? _t : (_s = (_r = part.providerMetadata) == null ? void 0 : _r[providerOptionsName]) == null ? void 0 : _s.itemId) != null ? _u : part.toolCallId;
|
|
5106
5204
|
if (store) {
|
|
5107
5205
|
input.push({ type: "item_reference", id: itemId });
|
|
@@ -5342,7 +5440,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
5342
5440
|
const resolvedToolName = toolNameMapping.toProviderToolName(
|
|
5343
5441
|
part.toolName
|
|
5344
5442
|
);
|
|
5345
|
-
if (
|
|
5443
|
+
if (part.toolName === toolSearchToolName && output.type === "json") {
|
|
5346
5444
|
const parsedOutput = await validateTypes({
|
|
5347
5445
|
value: output.value,
|
|
5348
5446
|
schema: toolSearchOutputSchema
|
|
@@ -5438,7 +5536,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
5438
5536
|
break;
|
|
5439
5537
|
case "content":
|
|
5440
5538
|
outputValue = output.value.map((item) => {
|
|
5441
|
-
var
|
|
5539
|
+
var _a3, _b2, _c2;
|
|
5442
5540
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
5443
5541
|
item.providerOptions,
|
|
5444
5542
|
providerOptionsName
|
|
@@ -5454,7 +5552,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
5454
5552
|
};
|
|
5455
5553
|
case "file": {
|
|
5456
5554
|
const topLevel = getTopLevelMediaType2(item.mediaType);
|
|
5457
|
-
const imageDetail = (_b2 = (
|
|
5555
|
+
const imageDetail = (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail;
|
|
5458
5556
|
if (item.data.type === "data") {
|
|
5459
5557
|
const fullMediaType = resolveFullMediaType2({
|
|
5460
5558
|
part: item
|
|
@@ -5868,7 +5966,7 @@ async function prepareResponsesTools({
|
|
|
5868
5966
|
customProviderToolNames,
|
|
5869
5967
|
outputSchemaToolNames
|
|
5870
5968
|
}) {
|
|
5871
|
-
var
|
|
5969
|
+
var _a2, _b, _c, _d;
|
|
5872
5970
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
5873
5971
|
const toolWarnings = [];
|
|
5874
5972
|
if (tools == null) {
|
|
@@ -5894,7 +5992,7 @@ async function prepareResponsesTools({
|
|
|
5894
5992
|
for (const tool of tools) {
|
|
5895
5993
|
switch (tool.type) {
|
|
5896
5994
|
case "function": {
|
|
5897
|
-
const openaiOptions = (
|
|
5995
|
+
const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
|
|
5898
5996
|
if ((openaiOptions == null ? void 0 : openaiOptions.outputSchema) != null) {
|
|
5899
5997
|
outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.add(tool.name);
|
|
5900
5998
|
}
|
|
@@ -6312,11 +6410,11 @@ function mapShellEnvironment(environment) {
|
|
|
6312
6410
|
function mapShellSkills(skills) {
|
|
6313
6411
|
return skills == null ? void 0 : skills.map(
|
|
6314
6412
|
(skill) => {
|
|
6315
|
-
var
|
|
6413
|
+
var _a2, _b;
|
|
6316
6414
|
return skill.type === "skillReference" ? {
|
|
6317
6415
|
type: "skill_reference",
|
|
6318
6416
|
skill_id: resolveProviderReference3({
|
|
6319
|
-
reference: (
|
|
6417
|
+
reference: (_a2 = skill.providerReference) != null ? _a2 : {},
|
|
6320
6418
|
provider: "openai"
|
|
6321
6419
|
}),
|
|
6322
6420
|
version: (_b = skill.version) != null ? _b : "latest"
|
|
@@ -6336,13 +6434,13 @@ function mapShellSkills(skills) {
|
|
|
6336
6434
|
|
|
6337
6435
|
// src/responses/openai-responses-language-model.ts
|
|
6338
6436
|
function extractApprovalRequestIdToToolCallIdMapping(prompt) {
|
|
6339
|
-
var
|
|
6437
|
+
var _a2, _b;
|
|
6340
6438
|
const mapping = {};
|
|
6341
6439
|
for (const message of prompt) {
|
|
6342
6440
|
if (message.role !== "assistant") continue;
|
|
6343
6441
|
for (const part of message.content) {
|
|
6344
6442
|
if (part.type !== "tool-call") continue;
|
|
6345
|
-
const approvalRequestId = (_b = (
|
|
6443
|
+
const approvalRequestId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.approvalRequestId;
|
|
6346
6444
|
if (approvalRequestId != null) {
|
|
6347
6445
|
mapping[approvalRequestId] = part.toolCallId;
|
|
6348
6446
|
}
|
|
@@ -6405,16 +6503,16 @@ function mapComputerCallInput({
|
|
|
6405
6503
|
pending_safety_checks,
|
|
6406
6504
|
status
|
|
6407
6505
|
}) {
|
|
6408
|
-
var
|
|
6506
|
+
var _a2;
|
|
6409
6507
|
return {
|
|
6410
6508
|
actions: (actions != null ? actions : action != null ? [action] : []).map(
|
|
6411
6509
|
mapComputerAction
|
|
6412
6510
|
),
|
|
6413
|
-
pendingSafetyChecks: (
|
|
6511
|
+
pendingSafetyChecks: (_a2 = pending_safety_checks == null ? void 0 : pending_safety_checks.map((safetyCheck) => ({
|
|
6414
6512
|
id: safetyCheck.id,
|
|
6415
6513
|
...safetyCheck.code != null && { code: safetyCheck.code },
|
|
6416
6514
|
...safetyCheck.message != null && { message: safetyCheck.message }
|
|
6417
|
-
}))) != null ?
|
|
6515
|
+
}))) != null ? _a2 : [],
|
|
6418
6516
|
status
|
|
6419
6517
|
};
|
|
6420
6518
|
}
|
|
@@ -6456,7 +6554,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
6456
6554
|
toolChoice,
|
|
6457
6555
|
responseFormat
|
|
6458
6556
|
}) {
|
|
6459
|
-
var
|
|
6557
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
6460
6558
|
const warnings = [];
|
|
6461
6559
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
6462
6560
|
if (topK != null) {
|
|
@@ -6487,7 +6585,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
6487
6585
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
6488
6586
|
});
|
|
6489
6587
|
}
|
|
6490
|
-
const resolvedReasoningEffort = (
|
|
6588
|
+
const resolvedReasoningEffort = (_a2 = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null ? _a2 : isCustomReasoning2(reasoning) ? reasoning : void 0;
|
|
6491
6589
|
const resolvedReasoningSummary = (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) !== void 0 ? openaiOptions.reasoningSummary : resolvedReasoningEffort != null && resolvedReasoningEffort !== "none" ? "detailed" : void 0;
|
|
6492
6590
|
const isReasoningModel = (_b = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
|
|
6493
6591
|
if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
|
|
@@ -6542,6 +6640,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
6542
6640
|
hasShellTool: hasOpenAITool("openai.shell"),
|
|
6543
6641
|
hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
|
|
6544
6642
|
hasComputerTool: hasOpenAITool("openai.computer"),
|
|
6643
|
+
toolSearchToolName: getOpenAIToolName("openai.tool_search"),
|
|
6545
6644
|
customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0,
|
|
6546
6645
|
outputSchemaToolNames: outputSchemaToolNames.size > 0 ? outputSchemaToolNames : void 0
|
|
6547
6646
|
});
|
|
@@ -6558,8 +6657,12 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
6558
6657
|
include = [...include, key];
|
|
6559
6658
|
}
|
|
6560
6659
|
}
|
|
6660
|
+
function getOpenAIToolName(id) {
|
|
6661
|
+
var _a3;
|
|
6662
|
+
return (_a3 = tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && tool.id === id)) == null ? void 0 : _a3.name;
|
|
6663
|
+
}
|
|
6561
6664
|
function hasOpenAITool(id) {
|
|
6562
|
-
return (
|
|
6665
|
+
return getOpenAIToolName(id) != null;
|
|
6563
6666
|
}
|
|
6564
6667
|
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;
|
|
6565
6668
|
if (topLogprobs) {
|
|
@@ -6726,7 +6829,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
6726
6829
|
};
|
|
6727
6830
|
}
|
|
6728
6831
|
async doGenerate(options) {
|
|
6729
|
-
var
|
|
6832
|
+
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, _F, _G, _H;
|
|
6730
6833
|
const {
|
|
6731
6834
|
args: body,
|
|
6732
6835
|
warnings,
|
|
@@ -6746,7 +6849,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
6746
6849
|
rawValue: rawResponse
|
|
6747
6850
|
} = await postJsonToApi5({
|
|
6748
6851
|
url,
|
|
6749
|
-
headers: combineHeaders6((_b = (
|
|
6852
|
+
headers: combineHeaders6((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
6750
6853
|
body,
|
|
6751
6854
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
6752
6855
|
successfulResponseHandler: createJsonResponseHandler6(
|
|
@@ -7307,7 +7410,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7307
7410
|
};
|
|
7308
7411
|
}
|
|
7309
7412
|
async doStream(options) {
|
|
7310
|
-
var
|
|
7413
|
+
var _a2, _b, _c, _d;
|
|
7311
7414
|
const {
|
|
7312
7415
|
args: body,
|
|
7313
7416
|
warnings,
|
|
@@ -7323,7 +7426,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7323
7426
|
});
|
|
7324
7427
|
const { responseHeaders, value: response } = await postJsonToApi5({
|
|
7325
7428
|
url,
|
|
7326
|
-
headers: combineHeaders6((_b = (
|
|
7429
|
+
headers: combineHeaders6((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
7327
7430
|
body: {
|
|
7328
7431
|
...body,
|
|
7329
7432
|
stream: true
|
|
@@ -7367,8 +7470,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7367
7470
|
itemId,
|
|
7368
7471
|
outputIndex
|
|
7369
7472
|
}) => {
|
|
7370
|
-
var
|
|
7371
|
-
return outputIndex == null ? itemId : (
|
|
7473
|
+
var _a3;
|
|
7474
|
+
return outputIndex == null ? itemId : (_a3 = activeOutputItemIds[outputIndex]) != null ? _a3 : itemId;
|
|
7372
7475
|
};
|
|
7373
7476
|
let serviceTier;
|
|
7374
7477
|
let reasoningContext;
|
|
@@ -7381,7 +7484,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7381
7484
|
controller.enqueue({ type: "stream-start", warnings });
|
|
7382
7485
|
},
|
|
7383
7486
|
transform(chunk, controller) {
|
|
7384
|
-
var
|
|
7487
|
+
var _a3, _b2, _c2, _d2, _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, _Q, _R;
|
|
7385
7488
|
if (options.includeRawChunks) {
|
|
7386
7489
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
7387
7490
|
}
|
|
@@ -7393,6 +7496,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7393
7496
|
requestBodyValues: body,
|
|
7394
7497
|
responseHeaders
|
|
7395
7498
|
}) : chunk.error;
|
|
7499
|
+
encounteredStreamError = true;
|
|
7396
7500
|
finishReason = { unified: "error", raw: void 0 };
|
|
7397
7501
|
controller.enqueue({ type: "error", error });
|
|
7398
7502
|
return;
|
|
@@ -7459,7 +7563,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7459
7563
|
providerExecuted: true
|
|
7460
7564
|
});
|
|
7461
7565
|
} else if (value.item.type === "computer_call") {
|
|
7462
|
-
const toolCallId = (
|
|
7566
|
+
const toolCallId = (_a3 = value.item.call_id) != null ? _a3 : value.item.id;
|
|
7463
7567
|
ongoingToolCalls[value.output_index] = {
|
|
7464
7568
|
toolName: toolNameMapping.toCustomToolName("computer"),
|
|
7465
7569
|
toolCallId
|
|
@@ -7631,14 +7735,14 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7631
7735
|
tools: functionTools
|
|
7632
7736
|
});
|
|
7633
7737
|
const enqueueUnexpandedToolCall = () => {
|
|
7634
|
-
var
|
|
7738
|
+
var _a4;
|
|
7635
7739
|
if (suppressInputStreaming) {
|
|
7636
7740
|
controller.enqueue({
|
|
7637
7741
|
type: "tool-input-start",
|
|
7638
7742
|
id: item.call_id,
|
|
7639
7743
|
toolName: item.name
|
|
7640
7744
|
});
|
|
7641
|
-
const bufferedInputDeltas = (
|
|
7745
|
+
const bufferedInputDeltas = (_a4 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a4 : [];
|
|
7642
7746
|
if (bufferedInputDeltas.length > 0) {
|
|
7643
7747
|
for (const delta of bufferedInputDeltas) {
|
|
7644
7748
|
controller.enqueue({
|
|
@@ -8306,13 +8410,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8306
8410
|
}
|
|
8307
8411
|
}
|
|
8308
8412
|
} else if (isResponseFinishedChunk(value)) {
|
|
8309
|
-
|
|
8310
|
-
|
|
8311
|
-
|
|
8312
|
-
|
|
8313
|
-
|
|
8314
|
-
|
|
8315
|
-
|
|
8413
|
+
if (!encounteredStreamError) {
|
|
8414
|
+
finishReason = {
|
|
8415
|
+
unified: mapOpenAIResponseFinishReason({
|
|
8416
|
+
finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
|
|
8417
|
+
hasFunctionCall
|
|
8418
|
+
}),
|
|
8419
|
+
raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
|
|
8420
|
+
};
|
|
8421
|
+
}
|
|
8316
8422
|
usage = value.response.usage;
|
|
8317
8423
|
if (typeof value.response.service_tier === "string") {
|
|
8318
8424
|
serviceTier = value.response.service_tier;
|
|
@@ -8335,17 +8441,18 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8335
8441
|
}
|
|
8336
8442
|
if (!encounteredStreamError && value.response.error != null) {
|
|
8337
8443
|
encounteredStreamError = true;
|
|
8444
|
+
const error = {
|
|
8445
|
+
type: "response.failed",
|
|
8446
|
+
sequence_number: value.sequence_number,
|
|
8447
|
+
response: {
|
|
8448
|
+
error: value.response.error,
|
|
8449
|
+
incomplete_details: value.response.incomplete_details,
|
|
8450
|
+
service_tier: value.response.service_tier
|
|
8451
|
+
}
|
|
8452
|
+
};
|
|
8338
8453
|
controller.enqueue({
|
|
8339
8454
|
type: "error",
|
|
8340
|
-
error:
|
|
8341
|
-
type: "response.failed",
|
|
8342
|
-
sequence_number: value.sequence_number,
|
|
8343
|
-
response: {
|
|
8344
|
-
error: value.response.error,
|
|
8345
|
-
incomplete_details: value.response.incomplete_details,
|
|
8346
|
-
service_tier: value.response.service_tier
|
|
8347
|
-
}
|
|
8348
|
-
}
|
|
8455
|
+
error: (_E = createOpenAIProviderStreamError(error)) != null ? _E : error
|
|
8349
8456
|
});
|
|
8350
8457
|
}
|
|
8351
8458
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
@@ -8354,7 +8461,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8354
8461
|
controller.enqueue({
|
|
8355
8462
|
type: "source",
|
|
8356
8463
|
sourceType: "url",
|
|
8357
|
-
id: (
|
|
8464
|
+
id: (_H = (_G = (_F = self.config).generateId) == null ? void 0 : _G.call(_F)) != null ? _H : generateId2(),
|
|
8358
8465
|
url: value.annotation.url,
|
|
8359
8466
|
title: value.annotation.title
|
|
8360
8467
|
});
|
|
@@ -8362,7 +8469,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8362
8469
|
controller.enqueue({
|
|
8363
8470
|
type: "source",
|
|
8364
8471
|
sourceType: "document",
|
|
8365
|
-
id: (
|
|
8472
|
+
id: (_K = (_J = (_I = self.config).generateId) == null ? void 0 : _J.call(_I)) != null ? _K : generateId2(),
|
|
8366
8473
|
mediaType: "text/plain",
|
|
8367
8474
|
title: value.annotation.filename,
|
|
8368
8475
|
filename: value.annotation.filename,
|
|
@@ -8378,7 +8485,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8378
8485
|
controller.enqueue({
|
|
8379
8486
|
type: "source",
|
|
8380
8487
|
sourceType: "document",
|
|
8381
|
-
id: (
|
|
8488
|
+
id: (_N = (_M = (_L = self.config).generateId) == null ? void 0 : _M.call(_L)) != null ? _N : generateId2(),
|
|
8382
8489
|
mediaType: "text/plain",
|
|
8383
8490
|
title: value.annotation.filename,
|
|
8384
8491
|
filename: value.annotation.filename,
|
|
@@ -8394,7 +8501,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8394
8501
|
controller.enqueue({
|
|
8395
8502
|
type: "source",
|
|
8396
8503
|
sourceType: "document",
|
|
8397
|
-
id: (
|
|
8504
|
+
id: (_Q = (_P = (_O = self.config).generateId) == null ? void 0 : _P.call(_O)) != null ? _Q : generateId2(),
|
|
8398
8505
|
mediaType: "application/octet-stream",
|
|
8399
8506
|
title: value.annotation.file_id,
|
|
8400
8507
|
filename: value.annotation.file_id,
|
|
@@ -8410,11 +8517,14 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8410
8517
|
} else if (isErrorChunk(value)) {
|
|
8411
8518
|
encounteredStreamError = true;
|
|
8412
8519
|
finishReason = { unified: "error", raw: "error" };
|
|
8413
|
-
controller.enqueue({
|
|
8520
|
+
controller.enqueue({
|
|
8521
|
+
type: "error",
|
|
8522
|
+
error: (_R = createOpenAIProviderStreamError(value)) != null ? _R : value
|
|
8523
|
+
});
|
|
8414
8524
|
}
|
|
8415
8525
|
},
|
|
8416
8526
|
flush(controller) {
|
|
8417
|
-
var
|
|
8527
|
+
var _a3;
|
|
8418
8528
|
for (const toolCall of Object.values(ongoingToolCalls)) {
|
|
8419
8529
|
if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
|
|
8420
8530
|
continue;
|
|
@@ -8424,7 +8534,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8424
8534
|
id: toolCall.toolCallId,
|
|
8425
8535
|
toolName: toolCall.toolName
|
|
8426
8536
|
});
|
|
8427
|
-
for (const delta of (
|
|
8537
|
+
for (const delta of (_a3 = toolCall.bufferedInputDeltas) != null ? _a3 : []) {
|
|
8428
8538
|
controller.enqueue({
|
|
8429
8539
|
type: "tool-input-delta",
|
|
8430
8540
|
id: toolCall.toolCallId,
|
|
@@ -8532,7 +8642,7 @@ function isResponseOutputChunk(chunk) {
|
|
|
8532
8642
|
return !(chunk.type === "response.created" || chunk.type === "response.in_progress" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
|
|
8533
8643
|
}
|
|
8534
8644
|
function mapWebSearchOutput(action) {
|
|
8535
|
-
var
|
|
8645
|
+
var _a2;
|
|
8536
8646
|
if (action == null) {
|
|
8537
8647
|
return {};
|
|
8538
8648
|
}
|
|
@@ -8541,7 +8651,7 @@ function mapWebSearchOutput(action) {
|
|
|
8541
8651
|
return {
|
|
8542
8652
|
action: {
|
|
8543
8653
|
type: "search",
|
|
8544
|
-
query: (
|
|
8654
|
+
query: (_a2 = action.query) != null ? _a2 : void 0,
|
|
8545
8655
|
...action.queries != null && { queries: action.queries }
|
|
8546
8656
|
},
|
|
8547
8657
|
// include sources when provided by the Responses API (behind include flag)
|
|
@@ -8612,7 +8722,7 @@ var OpenAIResponsesBatch = class {
|
|
|
8612
8722
|
this.options = options;
|
|
8613
8723
|
}
|
|
8614
8724
|
async startBatch(options) {
|
|
8615
|
-
var
|
|
8725
|
+
var _a2, _b, _c, _d;
|
|
8616
8726
|
const fileParts = [];
|
|
8617
8727
|
const warnings = options.webhookUrl == null ? [] : [
|
|
8618
8728
|
{
|
|
@@ -8653,7 +8763,7 @@ var OpenAIResponsesBatch = class {
|
|
|
8653
8763
|
);
|
|
8654
8764
|
const { value: uploadedFile } = await postToApi({
|
|
8655
8765
|
url: this.getUrl("/files"),
|
|
8656
|
-
headers: combineHeaders7((_b = (
|
|
8766
|
+
headers: combineHeaders7((_b = (_a2 = this.options.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
8657
8767
|
body: {
|
|
8658
8768
|
content: formData,
|
|
8659
8769
|
values: {
|
|
@@ -8703,7 +8813,8 @@ var OpenAIResponsesBatch = class {
|
|
|
8703
8813
|
}
|
|
8704
8814
|
async getBatchResults(options) {
|
|
8705
8815
|
const batch = await this.retrieveBatch(options);
|
|
8706
|
-
|
|
8816
|
+
const batchStatus = convertOpenAIBatchStatus(batch);
|
|
8817
|
+
if (batchStatus.status === "pending") {
|
|
8707
8818
|
throw new InvalidArgumentError({
|
|
8708
8819
|
argument: "batchId",
|
|
8709
8820
|
message: `OpenAI batch "${options.batchId}" is not complete.`
|
|
@@ -8712,14 +8823,20 @@ var OpenAIResponsesBatch = class {
|
|
|
8712
8823
|
const fileIds = [batch.output_file_id, batch.error_file_id].filter(
|
|
8713
8824
|
(fileId) => fileId != null
|
|
8714
8825
|
);
|
|
8826
|
+
if (batchStatus.status === "completed" && fileIds.length === 0) {
|
|
8827
|
+
throw new InvalidResponseDataError({
|
|
8828
|
+
data: batch,
|
|
8829
|
+
message: `OpenAI batch "${options.batchId}" completed without batch output.`
|
|
8830
|
+
});
|
|
8831
|
+
}
|
|
8715
8832
|
const iterator = this.iterateBatchResults({ fileIds, options });
|
|
8716
8833
|
return convertAsyncIteratorToReadableStream(iterator);
|
|
8717
8834
|
}
|
|
8718
8835
|
async retrieveBatch(options) {
|
|
8719
|
-
var
|
|
8836
|
+
var _a2, _b;
|
|
8720
8837
|
const { value: batch } = await getFromApi({
|
|
8721
8838
|
url: this.getUrl(`/batches/${encodeURIComponent(options.batchId)}`),
|
|
8722
|
-
headers: combineHeaders7((_b = (
|
|
8839
|
+
headers: combineHeaders7((_b = (_a2 = this.options.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
8723
8840
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
8724
8841
|
successfulResponseHandler: createJsonResponseHandler7(
|
|
8725
8842
|
openaiBatchResponseSchema
|
|
@@ -8734,21 +8851,23 @@ var OpenAIResponsesBatch = class {
|
|
|
8734
8851
|
fileIds,
|
|
8735
8852
|
options
|
|
8736
8853
|
}) {
|
|
8737
|
-
var
|
|
8854
|
+
var _a2, _b;
|
|
8738
8855
|
for (const fileId of fileIds) {
|
|
8739
|
-
const { value:
|
|
8856
|
+
const { value: lines } = await getFromApi({
|
|
8740
8857
|
url: this.getUrl(`/files/${encodeURIComponent(fileId)}/content`),
|
|
8741
8858
|
headers: combineHeaders7(
|
|
8742
|
-
(_b = (
|
|
8859
|
+
(_b = (_a2 = this.options.config).headers) == null ? void 0 : _b.call(_a2),
|
|
8743
8860
|
options.headers
|
|
8744
8861
|
),
|
|
8745
8862
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
8746
|
-
successfulResponseHandler:
|
|
8863
|
+
successfulResponseHandler: createJsonLinesResponseHandler(
|
|
8864
|
+
openaiBatchResultLineSchema
|
|
8865
|
+
),
|
|
8747
8866
|
abortSignal: options.abortSignal,
|
|
8748
8867
|
fetch: this.options.config.fetch,
|
|
8749
8868
|
validateUrl: false
|
|
8750
8869
|
});
|
|
8751
|
-
for await (const line of
|
|
8870
|
+
for await (const line of lines) {
|
|
8752
8871
|
yield await this.convertResultLine(line);
|
|
8753
8872
|
}
|
|
8754
8873
|
}
|
|
@@ -8842,9 +8961,9 @@ var OpenAIResponsesBatchLanguageModel = class _OpenAIResponsesBatchLanguageModel
|
|
|
8842
8961
|
}
|
|
8843
8962
|
};
|
|
8844
8963
|
function convertOpenAIBatchStatus(batch) {
|
|
8845
|
-
var
|
|
8964
|
+
var _a2, _b, _c;
|
|
8846
8965
|
const status = mapOpenAIBatchStatus(batch.status);
|
|
8847
|
-
const firstError = (_b = (
|
|
8966
|
+
const firstError = (_b = (_a2 = batch.errors) == null ? void 0 : _a2.data) == null ? void 0 : _b[0];
|
|
8848
8967
|
const requestCounts = convertOpenAIRequestCounts(batch.request_counts);
|
|
8849
8968
|
const createdAt = convertUnixTimestamp(batch.created_at);
|
|
8850
8969
|
const expiresAt = convertUnixTimestamp(batch.expires_at);
|
|
@@ -8882,15 +9001,12 @@ function convertOpenAIRequestCounts(counts) {
|
|
|
8882
9001
|
const total = counts == null ? void 0 : counts.total;
|
|
8883
9002
|
const completed = counts == null ? void 0 : counts.completed;
|
|
8884
9003
|
const failed = counts == null ? void 0 : counts.failed;
|
|
8885
|
-
|
|
8886
|
-
return void 0;
|
|
8887
|
-
}
|
|
8888
|
-
return {
|
|
9004
|
+
return normalizeBatchRequestCounts({
|
|
8889
9005
|
total,
|
|
8890
|
-
pending: total - completed - failed,
|
|
9006
|
+
pending: total != null && completed != null && failed != null ? total - completed - failed : void 0,
|
|
8891
9007
|
completed,
|
|
8892
9008
|
failed
|
|
8893
|
-
};
|
|
9009
|
+
});
|
|
8894
9010
|
}
|
|
8895
9011
|
function convertUnixTimestamp(value) {
|
|
8896
9012
|
if (value == null || !Number.isFinite(value)) {
|
|
@@ -8903,7 +9019,7 @@ async function convertOpenAIErrorResponse({
|
|
|
8903
9019
|
body,
|
|
8904
9020
|
statusCode
|
|
8905
9021
|
}) {
|
|
8906
|
-
var
|
|
9022
|
+
var _a2;
|
|
8907
9023
|
const result = await safeValidateTypes({
|
|
8908
9024
|
value: body,
|
|
8909
9025
|
schema: openaiErrorDataSchema
|
|
@@ -8916,17 +9032,27 @@ async function convertOpenAIErrorResponse({
|
|
|
8916
9032
|
}
|
|
8917
9033
|
return {
|
|
8918
9034
|
message: result.value.error.message,
|
|
8919
|
-
type: (
|
|
9035
|
+
type: (_a2 = result.value.error.type) != null ? _a2 : void 0,
|
|
8920
9036
|
code: result.value.error.code != null ? String(result.value.error.code) : void 0,
|
|
8921
9037
|
statusCode
|
|
8922
9038
|
};
|
|
8923
9039
|
}
|
|
8924
9040
|
async function convertOpenAIResponsesBatchResponse(body) {
|
|
8925
|
-
var
|
|
8926
|
-
const
|
|
9041
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
9042
|
+
const validation = await safeValidateTypes({
|
|
8927
9043
|
value: body,
|
|
8928
9044
|
schema: openaiResponsesResponseSchema
|
|
8929
9045
|
});
|
|
9046
|
+
if (!validation.success) {
|
|
9047
|
+
return {
|
|
9048
|
+
success: false,
|
|
9049
|
+
error: {
|
|
9050
|
+
message: "OpenAI returned an invalid Responses batch result.",
|
|
9051
|
+
code: "invalid_response"
|
|
9052
|
+
}
|
|
9053
|
+
};
|
|
9054
|
+
}
|
|
9055
|
+
const response = validation.value;
|
|
8930
9056
|
if (response.error != null) {
|
|
8931
9057
|
return {
|
|
8932
9058
|
success: false,
|
|
@@ -8938,7 +9064,7 @@ async function convertOpenAIResponsesBatchResponse(body) {
|
|
|
8938
9064
|
};
|
|
8939
9065
|
}
|
|
8940
9066
|
if (response.output == null) {
|
|
8941
|
-
const detail = (
|
|
9067
|
+
const detail = (_a2 = response.incomplete_details) == null ? void 0 : _a2.reason;
|
|
8942
9068
|
return {
|
|
8943
9069
|
success: false,
|
|
8944
9070
|
error: {
|
|
@@ -8950,21 +9076,49 @@ async function convertOpenAIResponsesBatchResponse(body) {
|
|
|
8950
9076
|
const content = [];
|
|
8951
9077
|
const logprobs = [];
|
|
8952
9078
|
for (const part of response.output) {
|
|
8953
|
-
|
|
8954
|
-
|
|
8955
|
-
|
|
8956
|
-
|
|
8957
|
-
|
|
9079
|
+
switch (part.type) {
|
|
9080
|
+
case "reasoning": {
|
|
9081
|
+
const summaries = part.summary.length > 0 ? part.summary : [{ type: "summary_text", text: "" }];
|
|
9082
|
+
for (const summary of summaries) {
|
|
9083
|
+
content.push({
|
|
9084
|
+
type: "reasoning",
|
|
9085
|
+
text: summary.text,
|
|
9086
|
+
providerMetadata: {
|
|
9087
|
+
openai: {
|
|
9088
|
+
itemId: part.id,
|
|
9089
|
+
reasoningEncryptedContent: (_b = part.encrypted_content) != null ? _b : null
|
|
9090
|
+
}
|
|
9091
|
+
}
|
|
9092
|
+
});
|
|
8958
9093
|
}
|
|
9094
|
+
break;
|
|
8959
9095
|
}
|
|
8960
|
-
|
|
8961
|
-
|
|
8962
|
-
|
|
8963
|
-
|
|
8964
|
-
|
|
8965
|
-
|
|
9096
|
+
case "message": {
|
|
9097
|
+
for (const contentPart of part.content) {
|
|
9098
|
+
content.push({ type: "text", text: contentPart.text });
|
|
9099
|
+
if (contentPart.logprobs != null) {
|
|
9100
|
+
logprobs.push(contentPart.logprobs);
|
|
9101
|
+
}
|
|
8966
9102
|
}
|
|
8967
|
-
|
|
9103
|
+
break;
|
|
9104
|
+
}
|
|
9105
|
+
case "function_call":
|
|
9106
|
+
case "custom_tool_call":
|
|
9107
|
+
return {
|
|
9108
|
+
success: false,
|
|
9109
|
+
error: {
|
|
9110
|
+
message: "OpenAI returned a tool call, but tool calls are not supported in AI SDK text batches.",
|
|
9111
|
+
code: "unsupported_content"
|
|
9112
|
+
}
|
|
9113
|
+
};
|
|
9114
|
+
default:
|
|
9115
|
+
return {
|
|
9116
|
+
success: false,
|
|
9117
|
+
error: {
|
|
9118
|
+
message: `OpenAI returned an unsupported "${part.type}" output item in an AI SDK text batch.`,
|
|
9119
|
+
code: "unsupported_content"
|
|
9120
|
+
}
|
|
9121
|
+
};
|
|
8968
9122
|
}
|
|
8969
9123
|
}
|
|
8970
9124
|
const providerMetadata = {
|
|
@@ -8972,7 +9126,7 @@ async function convertOpenAIResponsesBatchResponse(body) {
|
|
|
8972
9126
|
responseId: response.id,
|
|
8973
9127
|
...logprobs.length > 0 ? { logprobs } : {},
|
|
8974
9128
|
...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
|
|
8975
|
-
...((
|
|
9129
|
+
...((_c = response.reasoning) == null ? void 0 : _c.context) != null ? { reasoningContext: response.reasoning.context } : {}
|
|
8976
9130
|
}
|
|
8977
9131
|
};
|
|
8978
9132
|
return {
|
|
@@ -8981,10 +9135,10 @@ async function convertOpenAIResponsesBatchResponse(body) {
|
|
|
8981
9135
|
content,
|
|
8982
9136
|
finishReason: {
|
|
8983
9137
|
unified: mapOpenAIResponseFinishReason({
|
|
8984
|
-
finishReason: (
|
|
9138
|
+
finishReason: (_d = response.incomplete_details) == null ? void 0 : _d.reason,
|
|
8985
9139
|
hasFunctionCall: false
|
|
8986
9140
|
}),
|
|
8987
|
-
raw: (
|
|
9141
|
+
raw: (_f = (_e = response.incomplete_details) == null ? void 0 : _e.reason) != null ? _f : void 0
|
|
8988
9142
|
},
|
|
8989
9143
|
usage: convertOpenAIResponsesUsage(response.usage),
|
|
8990
9144
|
response: {
|
|
@@ -8997,58 +9151,10 @@ async function convertOpenAIResponsesBatchResponse(body) {
|
|
|
8997
9151
|
}
|
|
8998
9152
|
};
|
|
8999
9153
|
}
|
|
9000
|
-
var rawStreamResponseHandler = async ({ response }) => {
|
|
9001
|
-
if (response.body == null) {
|
|
9002
|
-
throw new EmptyResponseBodyError();
|
|
9003
|
-
}
|
|
9004
|
-
return { value: response.body };
|
|
9005
|
-
};
|
|
9006
|
-
async function* parseJsonLines(stream) {
|
|
9007
|
-
const reader = stream.getReader();
|
|
9008
|
-
const decoder = new TextDecoder();
|
|
9009
|
-
let buffer = "";
|
|
9010
|
-
let finished = false;
|
|
9011
|
-
try {
|
|
9012
|
-
while (true) {
|
|
9013
|
-
const { done, value } = await reader.read();
|
|
9014
|
-
if (done) {
|
|
9015
|
-
finished = true;
|
|
9016
|
-
buffer += decoder.decode();
|
|
9017
|
-
break;
|
|
9018
|
-
}
|
|
9019
|
-
buffer += decoder.decode(value, { stream: true });
|
|
9020
|
-
let lineEnd = buffer.indexOf("\n");
|
|
9021
|
-
while (lineEnd !== -1) {
|
|
9022
|
-
const line = buffer.slice(0, lineEnd).replace(/\r$/, "");
|
|
9023
|
-
buffer = buffer.slice(lineEnd + 1);
|
|
9024
|
-
if (line.trim().length > 0) {
|
|
9025
|
-
yield await parseJSON2({
|
|
9026
|
-
text: line,
|
|
9027
|
-
schema: openaiBatchResultLineSchema
|
|
9028
|
-
});
|
|
9029
|
-
}
|
|
9030
|
-
lineEnd = buffer.indexOf("\n");
|
|
9031
|
-
}
|
|
9032
|
-
}
|
|
9033
|
-
const finalLine = buffer.replace(/\r$/, "");
|
|
9034
|
-
if (finalLine.trim().length > 0) {
|
|
9035
|
-
yield await parseJSON2({
|
|
9036
|
-
text: finalLine,
|
|
9037
|
-
schema: openaiBatchResultLineSchema
|
|
9038
|
-
});
|
|
9039
|
-
}
|
|
9040
|
-
} finally {
|
|
9041
|
-
if (!finished) {
|
|
9042
|
-
await reader.cancel().catch(() => {
|
|
9043
|
-
});
|
|
9044
|
-
}
|
|
9045
|
-
reader.releaseLock();
|
|
9046
|
-
}
|
|
9047
|
-
}
|
|
9048
9154
|
|
|
9049
9155
|
// src/realtime/openai-realtime-event-mapper.ts
|
|
9050
9156
|
function parseOpenAIRealtimeServerEvent(raw) {
|
|
9051
|
-
var
|
|
9157
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
9052
9158
|
const event = raw;
|
|
9053
9159
|
const type = event.type;
|
|
9054
9160
|
switch (type) {
|
|
@@ -9056,7 +9162,7 @@ function parseOpenAIRealtimeServerEvent(raw) {
|
|
|
9056
9162
|
case "session.created":
|
|
9057
9163
|
return {
|
|
9058
9164
|
type: "session-created",
|
|
9059
|
-
sessionId: (
|
|
9165
|
+
sessionId: (_a2 = event.session) == null ? void 0 : _a2.id,
|
|
9060
9166
|
raw
|
|
9061
9167
|
};
|
|
9062
9168
|
case "session.updated":
|
|
@@ -9294,7 +9400,7 @@ function serializeOpenAIRealtimeClientEvent(event, modelId) {
|
|
|
9294
9400
|
}
|
|
9295
9401
|
}
|
|
9296
9402
|
function buildOpenAISessionConfig(config, modelId) {
|
|
9297
|
-
var
|
|
9403
|
+
var _a2;
|
|
9298
9404
|
const session = {
|
|
9299
9405
|
type: "realtime",
|
|
9300
9406
|
model: modelId
|
|
@@ -9335,7 +9441,7 @@ function buildOpenAISessionConfig(config, modelId) {
|
|
|
9335
9441
|
}
|
|
9336
9442
|
if (config.inputAudioTranscription != null) {
|
|
9337
9443
|
input.transcription = {
|
|
9338
|
-
model: (
|
|
9444
|
+
model: (_a2 = config.inputAudioTranscription.model) != null ? _a2 : "gpt-realtime-whisper",
|
|
9339
9445
|
...config.inputAudioTranscription.language != null ? { language: config.inputAudioTranscription.language } : {},
|
|
9340
9446
|
...config.inputAudioTranscription.prompt != null ? { prompt: config.inputAudioTranscription.prompt } : {}
|
|
9341
9447
|
};
|
|
@@ -9382,8 +9488,8 @@ var OpenAIRealtimeModel = class {
|
|
|
9382
9488
|
this.config = config;
|
|
9383
9489
|
}
|
|
9384
9490
|
async doCreateClientSecret(options) {
|
|
9385
|
-
var
|
|
9386
|
-
const fetchFn = (
|
|
9491
|
+
var _a2;
|
|
9492
|
+
const fetchFn = (_a2 = this.config.fetch) != null ? _a2 : fetch;
|
|
9387
9493
|
const url = `${this.config.baseURL}/realtime/client_secrets`;
|
|
9388
9494
|
const session = options.sessionConfig != null ? buildOpenAISessionConfig(options.sessionConfig, this.modelId) : { type: "realtime", model: this.modelId };
|
|
9389
9495
|
const response = await fetchFn(url, {
|
|
@@ -9536,8 +9642,8 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
|
|
|
9536
9642
|
};
|
|
9537
9643
|
}
|
|
9538
9644
|
async doGenerate(options) {
|
|
9539
|
-
var
|
|
9540
|
-
const currentDate = (_c = (_b = (
|
|
9645
|
+
var _a2, _b, _c, _d, _e;
|
|
9646
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
9541
9647
|
const { requestBody, warnings } = await this.getArgs(options);
|
|
9542
9648
|
const {
|
|
9543
9649
|
value: audio,
|
|
@@ -9813,13 +9919,13 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
9813
9919
|
};
|
|
9814
9920
|
}
|
|
9815
9921
|
async doGenerate(options) {
|
|
9816
|
-
var
|
|
9922
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
9817
9923
|
if (isRealtimeTranscriptionModelId(this.modelId)) {
|
|
9818
9924
|
throw new UnsupportedFunctionalityError6({
|
|
9819
9925
|
functionality: `non-streaming transcription with ${this.modelId}`
|
|
9820
9926
|
});
|
|
9821
9927
|
}
|
|
9822
|
-
const currentDate = (_c = (_b = (
|
|
9928
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
9823
9929
|
const { formData, warnings } = await this.getArgs(options);
|
|
9824
9930
|
const {
|
|
9825
9931
|
value: response,
|
|
@@ -9863,13 +9969,13 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
9863
9969
|
};
|
|
9864
9970
|
}
|
|
9865
9971
|
async doStream(options) {
|
|
9866
|
-
var
|
|
9972
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
9867
9973
|
if (!isRealtimeTranscriptionModelId(this.modelId)) {
|
|
9868
9974
|
throw new UnsupportedFunctionalityError6({
|
|
9869
9975
|
functionality: `streaming transcription with ${this.modelId}`
|
|
9870
9976
|
});
|
|
9871
9977
|
}
|
|
9872
|
-
const currentDate = (_c = (_b = (
|
|
9978
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
9873
9979
|
const openAIOptions = await parseProviderOptions9({
|
|
9874
9980
|
provider: "openai",
|
|
9875
9981
|
providerOptions: options.providerOptions,
|
|
@@ -10008,7 +10114,7 @@ function createOpenAIRealtimeTranscriptionStream({
|
|
|
10008
10114
|
void sendAudio(socket).catch(finishWithError);
|
|
10009
10115
|
},
|
|
10010
10116
|
onMessageText: async (text) => {
|
|
10011
|
-
var
|
|
10117
|
+
var _a2, _b, _c, _d;
|
|
10012
10118
|
const parsed = await safeParseJSON2({ text });
|
|
10013
10119
|
if (!parsed.success) return;
|
|
10014
10120
|
const raw = parsed.value;
|
|
@@ -10020,7 +10126,7 @@ function createOpenAIRealtimeTranscriptionStream({
|
|
|
10020
10126
|
controller.enqueue({
|
|
10021
10127
|
type: "transcript-delta",
|
|
10022
10128
|
id: raw.item_id,
|
|
10023
|
-
delta: (
|
|
10129
|
+
delta: (_a2 = raw.delta) != null ? _a2 : ""
|
|
10024
10130
|
});
|
|
10025
10131
|
break;
|
|
10026
10132
|
}
|
|
@@ -10059,7 +10165,7 @@ function buildOpenAIRealtimeTranscriptionSession({
|
|
|
10059
10165
|
inputAudioFormat,
|
|
10060
10166
|
providerOptions
|
|
10061
10167
|
}) {
|
|
10062
|
-
var
|
|
10168
|
+
var _a2, _b;
|
|
10063
10169
|
return {
|
|
10064
10170
|
type: "session.update",
|
|
10065
10171
|
session: {
|
|
@@ -10073,7 +10179,7 @@ function buildOpenAIRealtimeTranscriptionSession({
|
|
|
10073
10179
|
transcription: {
|
|
10074
10180
|
model: modelId,
|
|
10075
10181
|
...(providerOptions == null ? void 0 : providerOptions.language) != null ? { language: providerOptions.language } : {},
|
|
10076
|
-
...((
|
|
10182
|
+
...((_a2 = providerOptions == null ? void 0 : providerOptions.streaming) == null ? void 0 : _a2.delay) != null ? { delay: providerOptions.streaming.delay } : {}
|
|
10077
10183
|
},
|
|
10078
10184
|
turn_detection: null
|
|
10079
10185
|
}
|
|
@@ -10083,14 +10189,14 @@ function buildOpenAIRealtimeTranscriptionSession({
|
|
|
10083
10189
|
};
|
|
10084
10190
|
}
|
|
10085
10191
|
function getOpenAIRealtimeConnection(headers) {
|
|
10086
|
-
var
|
|
10192
|
+
var _a2;
|
|
10087
10193
|
let authorization;
|
|
10088
10194
|
for (const [key, value] of Object.entries(headers)) {
|
|
10089
10195
|
if (key.toLowerCase() === "authorization" && value != null) {
|
|
10090
10196
|
authorization = value;
|
|
10091
10197
|
}
|
|
10092
10198
|
}
|
|
10093
|
-
const token = (
|
|
10199
|
+
const token = (_a2 = authorization == null ? void 0 : authorization.match(/^bearer\s+(.+)$/i)) == null ? void 0 : _a2[1];
|
|
10094
10200
|
if (token == null) {
|
|
10095
10201
|
return { protocols: ["realtime"], headers };
|
|
10096
10202
|
}
|
|
@@ -10151,14 +10257,14 @@ var OpenAISpeechTranslationModel = class _OpenAISpeechTranslationModel {
|
|
|
10151
10257
|
return this.config.provider;
|
|
10152
10258
|
}
|
|
10153
10259
|
async doStream(options) {
|
|
10154
|
-
var
|
|
10260
|
+
var _a2, _b, _c, _d, _e;
|
|
10155
10261
|
if (options.targetLanguage == null) {
|
|
10156
10262
|
throw new InvalidArgumentError2({
|
|
10157
10263
|
argument: "targetLanguage",
|
|
10158
10264
|
message: `targetLanguage is required for translation model '${this.modelId}'.`
|
|
10159
10265
|
});
|
|
10160
10266
|
}
|
|
10161
|
-
const currentDate = (_c = (_b = (
|
|
10267
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
10162
10268
|
await parseProviderOptions10({
|
|
10163
10269
|
provider: "openai",
|
|
10164
10270
|
providerOptions: options.providerOptions,
|
|
@@ -10304,7 +10410,7 @@ function createOpenAIRealtimeSpeechTranslationStream({
|
|
|
10304
10410
|
void sendAudio(socket).catch(finishWithError);
|
|
10305
10411
|
},
|
|
10306
10412
|
onMessageText: async (text) => {
|
|
10307
|
-
var
|
|
10413
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
10308
10414
|
if (finished) return;
|
|
10309
10415
|
const parsed = await safeParseJSON3({ text });
|
|
10310
10416
|
if (!parsed.success) return;
|
|
@@ -10323,7 +10429,7 @@ function createOpenAIRealtimeSpeechTranslationStream({
|
|
|
10323
10429
|
break;
|
|
10324
10430
|
}
|
|
10325
10431
|
case "session.output_transcript.delta": {
|
|
10326
|
-
translationText += (
|
|
10432
|
+
translationText += (_a2 = raw.delta) != null ? _a2 : "";
|
|
10327
10433
|
controller.enqueue({
|
|
10328
10434
|
type: "output-text-delta",
|
|
10329
10435
|
delta: (_b = raw.delta) != null ? _b : ""
|
|
@@ -10400,14 +10506,14 @@ function validateOpenAISpeechTranslationInputAudioFormat(inputAudioFormat) {
|
|
|
10400
10506
|
}
|
|
10401
10507
|
}
|
|
10402
10508
|
function getOpenAIRealtimeConnection2(headers) {
|
|
10403
|
-
var
|
|
10509
|
+
var _a2;
|
|
10404
10510
|
let authorization;
|
|
10405
10511
|
for (const [key, value] of Object.entries(headers)) {
|
|
10406
10512
|
if (key.toLowerCase() === "authorization" && value != null) {
|
|
10407
10513
|
authorization = value;
|
|
10408
10514
|
}
|
|
10409
10515
|
}
|
|
10410
|
-
const token = (
|
|
10516
|
+
const token = (_a2 = authorization == null ? void 0 : authorization.match(/^bearer\s+(.+)$/i)) == null ? void 0 : _a2[1];
|
|
10411
10517
|
if (token == null) {
|
|
10412
10518
|
return { protocols: ["realtime"], headers };
|
|
10413
10519
|
}
|
|
@@ -10506,19 +10612,19 @@ var OpenAISkills = class {
|
|
|
10506
10612
|
};
|
|
10507
10613
|
|
|
10508
10614
|
// src/version.ts
|
|
10509
|
-
var VERSION = true ? "4.0.
|
|
10615
|
+
var VERSION = true ? "4.0.50" : "0.0.0-test";
|
|
10510
10616
|
|
|
10511
10617
|
// src/openai-provider.ts
|
|
10512
10618
|
function createOpenAI(options = {}) {
|
|
10513
|
-
var
|
|
10514
|
-
const baseURL = (
|
|
10619
|
+
var _a2, _b;
|
|
10620
|
+
const baseURL = (_a2 = withoutTrailingSlash(
|
|
10515
10621
|
validateBaseURL(
|
|
10516
10622
|
loadOptionalSetting({
|
|
10517
10623
|
settingValue: options.baseURL,
|
|
10518
10624
|
environmentVariableName: "OPENAI_BASE_URL"
|
|
10519
10625
|
})
|
|
10520
10626
|
)
|
|
10521
|
-
)) != null ?
|
|
10627
|
+
)) != null ? _a2 : "https://api.openai.com/v1";
|
|
10522
10628
|
const providerName = (_b = options.name) != null ? _b : "openai";
|
|
10523
10629
|
const getHeaders = () => withUserAgentSuffix(
|
|
10524
10630
|
{
|