@ai-sdk/openai 4.0.46 → 4.0.49
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 +31 -0
- package/dist/index.d.ts +29 -12
- package/dist/index.js +384 -276
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +45 -26
- package/dist/internal/index.js +271 -167
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +31 -11
- package/package.json +6 -6
- package/src/chat/convert-openai-chat-usage.ts +1 -1
- 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 +103 -103
- package/src/openai-stream-error.ts +68 -15
- package/src/responses/openai-responses-api.ts +114 -40
- package/src/responses/openai-responses-language-model.ts +28 -18
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;
|
|
@@ -270,7 +296,7 @@ function convertOpenAIChatUsage(usage) {
|
|
|
270
296
|
},
|
|
271
297
|
outputTokens: {
|
|
272
298
|
total: completionTokens,
|
|
273
|
-
text: completionTokens - reasoningTokens,
|
|
299
|
+
text: Math.max(0, completionTokens - reasoningTokens),
|
|
274
300
|
reasoning: reasoningTokens
|
|
275
301
|
},
|
|
276
302
|
raw: usage
|
|
@@ -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;
|
|
@@ -4685,7 +4782,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4685
4782
|
customProviderToolNames,
|
|
4686
4783
|
outputSchemaToolNames
|
|
4687
4784
|
}) {
|
|
4688
|
-
var
|
|
4785
|
+
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
4786
|
let input = [];
|
|
4690
4787
|
const warnings = [];
|
|
4691
4788
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
@@ -4753,7 +4850,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4753
4850
|
input.push({
|
|
4754
4851
|
role: "user",
|
|
4755
4852
|
content: content.map((part, index) => {
|
|
4756
|
-
var
|
|
4853
|
+
var _a3, _b2, _c2, _d2, _e2;
|
|
4757
4854
|
switch (part.type) {
|
|
4758
4855
|
case "text": {
|
|
4759
4856
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
@@ -4783,7 +4880,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4783
4880
|
return {
|
|
4784
4881
|
type: "input_image",
|
|
4785
4882
|
file_id: fileId,
|
|
4786
|
-
detail: (_b2 = (
|
|
4883
|
+
detail: (_b2 = (_a3 = part.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail,
|
|
4787
4884
|
...promptCacheBreakpoint != null && {
|
|
4788
4885
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
4789
4886
|
}
|
|
@@ -4856,7 +4953,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4856
4953
|
for (const part of content) {
|
|
4857
4954
|
switch (part.type) {
|
|
4858
4955
|
case "text": {
|
|
4859
|
-
const providerOptions2 = (
|
|
4956
|
+
const providerOptions2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName];
|
|
4860
4957
|
const id = providerOptions2 == null ? void 0 : providerOptions2.itemId;
|
|
4861
4958
|
const phase = providerOptions2 == null ? void 0 : providerOptions2.phase;
|
|
4862
4959
|
if (hasConversation && id != null) {
|
|
@@ -5438,7 +5535,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
5438
5535
|
break;
|
|
5439
5536
|
case "content":
|
|
5440
5537
|
outputValue = output.value.map((item) => {
|
|
5441
|
-
var
|
|
5538
|
+
var _a3, _b2, _c2;
|
|
5442
5539
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
5443
5540
|
item.providerOptions,
|
|
5444
5541
|
providerOptionsName
|
|
@@ -5454,7 +5551,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
5454
5551
|
};
|
|
5455
5552
|
case "file": {
|
|
5456
5553
|
const topLevel = getTopLevelMediaType2(item.mediaType);
|
|
5457
|
-
const imageDetail = (_b2 = (
|
|
5554
|
+
const imageDetail = (_b2 = (_a3 = item.providerOptions) == null ? void 0 : _a3[providerOptionsName]) == null ? void 0 : _b2.imageDetail;
|
|
5458
5555
|
if (item.data.type === "data") {
|
|
5459
5556
|
const fullMediaType = resolveFullMediaType2({
|
|
5460
5557
|
part: item
|
|
@@ -5868,7 +5965,7 @@ async function prepareResponsesTools({
|
|
|
5868
5965
|
customProviderToolNames,
|
|
5869
5966
|
outputSchemaToolNames
|
|
5870
5967
|
}) {
|
|
5871
|
-
var
|
|
5968
|
+
var _a2, _b, _c, _d;
|
|
5872
5969
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
5873
5970
|
const toolWarnings = [];
|
|
5874
5971
|
if (tools == null) {
|
|
@@ -5894,7 +5991,7 @@ async function prepareResponsesTools({
|
|
|
5894
5991
|
for (const tool of tools) {
|
|
5895
5992
|
switch (tool.type) {
|
|
5896
5993
|
case "function": {
|
|
5897
|
-
const openaiOptions = (
|
|
5994
|
+
const openaiOptions = (_a2 = tool.providerOptions) == null ? void 0 : _a2.openai;
|
|
5898
5995
|
if ((openaiOptions == null ? void 0 : openaiOptions.outputSchema) != null) {
|
|
5899
5996
|
outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.add(tool.name);
|
|
5900
5997
|
}
|
|
@@ -6312,11 +6409,11 @@ function mapShellEnvironment(environment) {
|
|
|
6312
6409
|
function mapShellSkills(skills) {
|
|
6313
6410
|
return skills == null ? void 0 : skills.map(
|
|
6314
6411
|
(skill) => {
|
|
6315
|
-
var
|
|
6412
|
+
var _a2, _b;
|
|
6316
6413
|
return skill.type === "skillReference" ? {
|
|
6317
6414
|
type: "skill_reference",
|
|
6318
6415
|
skill_id: resolveProviderReference3({
|
|
6319
|
-
reference: (
|
|
6416
|
+
reference: (_a2 = skill.providerReference) != null ? _a2 : {},
|
|
6320
6417
|
provider: "openai"
|
|
6321
6418
|
}),
|
|
6322
6419
|
version: (_b = skill.version) != null ? _b : "latest"
|
|
@@ -6336,13 +6433,13 @@ function mapShellSkills(skills) {
|
|
|
6336
6433
|
|
|
6337
6434
|
// src/responses/openai-responses-language-model.ts
|
|
6338
6435
|
function extractApprovalRequestIdToToolCallIdMapping(prompt) {
|
|
6339
|
-
var
|
|
6436
|
+
var _a2, _b;
|
|
6340
6437
|
const mapping = {};
|
|
6341
6438
|
for (const message of prompt) {
|
|
6342
6439
|
if (message.role !== "assistant") continue;
|
|
6343
6440
|
for (const part of message.content) {
|
|
6344
6441
|
if (part.type !== "tool-call") continue;
|
|
6345
|
-
const approvalRequestId = (_b = (
|
|
6442
|
+
const approvalRequestId = (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.approvalRequestId;
|
|
6346
6443
|
if (approvalRequestId != null) {
|
|
6347
6444
|
mapping[approvalRequestId] = part.toolCallId;
|
|
6348
6445
|
}
|
|
@@ -6405,16 +6502,16 @@ function mapComputerCallInput({
|
|
|
6405
6502
|
pending_safety_checks,
|
|
6406
6503
|
status
|
|
6407
6504
|
}) {
|
|
6408
|
-
var
|
|
6505
|
+
var _a2;
|
|
6409
6506
|
return {
|
|
6410
6507
|
actions: (actions != null ? actions : action != null ? [action] : []).map(
|
|
6411
6508
|
mapComputerAction
|
|
6412
6509
|
),
|
|
6413
|
-
pendingSafetyChecks: (
|
|
6510
|
+
pendingSafetyChecks: (_a2 = pending_safety_checks == null ? void 0 : pending_safety_checks.map((safetyCheck) => ({
|
|
6414
6511
|
id: safetyCheck.id,
|
|
6415
6512
|
...safetyCheck.code != null && { code: safetyCheck.code },
|
|
6416
6513
|
...safetyCheck.message != null && { message: safetyCheck.message }
|
|
6417
|
-
}))) != null ?
|
|
6514
|
+
}))) != null ? _a2 : [],
|
|
6418
6515
|
status
|
|
6419
6516
|
};
|
|
6420
6517
|
}
|
|
@@ -6456,7 +6553,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
6456
6553
|
toolChoice,
|
|
6457
6554
|
responseFormat
|
|
6458
6555
|
}) {
|
|
6459
|
-
var
|
|
6556
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
6460
6557
|
const warnings = [];
|
|
6461
6558
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
6462
6559
|
if (topK != null) {
|
|
@@ -6487,7 +6584,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
6487
6584
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
6488
6585
|
});
|
|
6489
6586
|
}
|
|
6490
|
-
const resolvedReasoningEffort = (
|
|
6587
|
+
const resolvedReasoningEffort = (_a2 = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null ? _a2 : isCustomReasoning2(reasoning) ? reasoning : void 0;
|
|
6491
6588
|
const resolvedReasoningSummary = (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) !== void 0 ? openaiOptions.reasoningSummary : resolvedReasoningEffort != null && resolvedReasoningEffort !== "none" ? "detailed" : void 0;
|
|
6492
6589
|
const isReasoningModel = (_b = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
|
|
6493
6590
|
if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
|
|
@@ -6726,7 +6823,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
6726
6823
|
};
|
|
6727
6824
|
}
|
|
6728
6825
|
async doGenerate(options) {
|
|
6729
|
-
var
|
|
6826
|
+
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
6827
|
const {
|
|
6731
6828
|
args: body,
|
|
6732
6829
|
warnings,
|
|
@@ -6746,7 +6843,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
6746
6843
|
rawValue: rawResponse
|
|
6747
6844
|
} = await postJsonToApi5({
|
|
6748
6845
|
url,
|
|
6749
|
-
headers: combineHeaders6((_b = (
|
|
6846
|
+
headers: combineHeaders6((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
6750
6847
|
body,
|
|
6751
6848
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
6752
6849
|
successfulResponseHandler: createJsonResponseHandler6(
|
|
@@ -7307,7 +7404,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7307
7404
|
};
|
|
7308
7405
|
}
|
|
7309
7406
|
async doStream(options) {
|
|
7310
|
-
var
|
|
7407
|
+
var _a2, _b, _c, _d;
|
|
7311
7408
|
const {
|
|
7312
7409
|
args: body,
|
|
7313
7410
|
warnings,
|
|
@@ -7323,7 +7420,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7323
7420
|
});
|
|
7324
7421
|
const { responseHeaders, value: response } = await postJsonToApi5({
|
|
7325
7422
|
url,
|
|
7326
|
-
headers: combineHeaders6((_b = (
|
|
7423
|
+
headers: combineHeaders6((_b = (_a2 = this.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
7327
7424
|
body: {
|
|
7328
7425
|
...body,
|
|
7329
7426
|
stream: true
|
|
@@ -7367,8 +7464,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7367
7464
|
itemId,
|
|
7368
7465
|
outputIndex
|
|
7369
7466
|
}) => {
|
|
7370
|
-
var
|
|
7371
|
-
return outputIndex == null ? itemId : (
|
|
7467
|
+
var _a3;
|
|
7468
|
+
return outputIndex == null ? itemId : (_a3 = activeOutputItemIds[outputIndex]) != null ? _a3 : itemId;
|
|
7372
7469
|
};
|
|
7373
7470
|
let serviceTier;
|
|
7374
7471
|
let reasoningContext;
|
|
@@ -7381,7 +7478,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7381
7478
|
controller.enqueue({ type: "stream-start", warnings });
|
|
7382
7479
|
},
|
|
7383
7480
|
transform(chunk, controller) {
|
|
7384
|
-
var
|
|
7481
|
+
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
7482
|
if (options.includeRawChunks) {
|
|
7386
7483
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
7387
7484
|
}
|
|
@@ -7393,6 +7490,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7393
7490
|
requestBodyValues: body,
|
|
7394
7491
|
responseHeaders
|
|
7395
7492
|
}) : chunk.error;
|
|
7493
|
+
encounteredStreamError = true;
|
|
7396
7494
|
finishReason = { unified: "error", raw: void 0 };
|
|
7397
7495
|
controller.enqueue({ type: "error", error });
|
|
7398
7496
|
return;
|
|
@@ -7459,7 +7557,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7459
7557
|
providerExecuted: true
|
|
7460
7558
|
});
|
|
7461
7559
|
} else if (value.item.type === "computer_call") {
|
|
7462
|
-
const toolCallId = (
|
|
7560
|
+
const toolCallId = (_a3 = value.item.call_id) != null ? _a3 : value.item.id;
|
|
7463
7561
|
ongoingToolCalls[value.output_index] = {
|
|
7464
7562
|
toolName: toolNameMapping.toCustomToolName("computer"),
|
|
7465
7563
|
toolCallId
|
|
@@ -7631,14 +7729,14 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7631
7729
|
tools: functionTools
|
|
7632
7730
|
});
|
|
7633
7731
|
const enqueueUnexpandedToolCall = () => {
|
|
7634
|
-
var
|
|
7732
|
+
var _a4;
|
|
7635
7733
|
if (suppressInputStreaming) {
|
|
7636
7734
|
controller.enqueue({
|
|
7637
7735
|
type: "tool-input-start",
|
|
7638
7736
|
id: item.call_id,
|
|
7639
7737
|
toolName: item.name
|
|
7640
7738
|
});
|
|
7641
|
-
const bufferedInputDeltas = (
|
|
7739
|
+
const bufferedInputDeltas = (_a4 = ongoingToolCall == null ? void 0 : ongoingToolCall.bufferedInputDeltas) != null ? _a4 : [];
|
|
7642
7740
|
if (bufferedInputDeltas.length > 0) {
|
|
7643
7741
|
for (const delta of bufferedInputDeltas) {
|
|
7644
7742
|
controller.enqueue({
|
|
@@ -8306,13 +8404,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8306
8404
|
}
|
|
8307
8405
|
}
|
|
8308
8406
|
} else if (isResponseFinishedChunk(value)) {
|
|
8309
|
-
|
|
8310
|
-
|
|
8311
|
-
|
|
8312
|
-
|
|
8313
|
-
|
|
8314
|
-
|
|
8315
|
-
|
|
8407
|
+
if (!encounteredStreamError) {
|
|
8408
|
+
finishReason = {
|
|
8409
|
+
unified: mapOpenAIResponseFinishReason({
|
|
8410
|
+
finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
|
|
8411
|
+
hasFunctionCall
|
|
8412
|
+
}),
|
|
8413
|
+
raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
|
|
8414
|
+
};
|
|
8415
|
+
}
|
|
8316
8416
|
usage = value.response.usage;
|
|
8317
8417
|
if (typeof value.response.service_tier === "string") {
|
|
8318
8418
|
serviceTier = value.response.service_tier;
|
|
@@ -8335,17 +8435,18 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8335
8435
|
}
|
|
8336
8436
|
if (!encounteredStreamError && value.response.error != null) {
|
|
8337
8437
|
encounteredStreamError = true;
|
|
8438
|
+
const error = {
|
|
8439
|
+
type: "response.failed",
|
|
8440
|
+
sequence_number: value.sequence_number,
|
|
8441
|
+
response: {
|
|
8442
|
+
error: value.response.error,
|
|
8443
|
+
incomplete_details: value.response.incomplete_details,
|
|
8444
|
+
service_tier: value.response.service_tier
|
|
8445
|
+
}
|
|
8446
|
+
};
|
|
8338
8447
|
controller.enqueue({
|
|
8339
8448
|
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
|
-
}
|
|
8449
|
+
error: (_E = createOpenAIProviderStreamError(error)) != null ? _E : error
|
|
8349
8450
|
});
|
|
8350
8451
|
}
|
|
8351
8452
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
@@ -8354,7 +8455,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8354
8455
|
controller.enqueue({
|
|
8355
8456
|
type: "source",
|
|
8356
8457
|
sourceType: "url",
|
|
8357
|
-
id: (
|
|
8458
|
+
id: (_H = (_G = (_F = self.config).generateId) == null ? void 0 : _G.call(_F)) != null ? _H : generateId2(),
|
|
8358
8459
|
url: value.annotation.url,
|
|
8359
8460
|
title: value.annotation.title
|
|
8360
8461
|
});
|
|
@@ -8362,7 +8463,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8362
8463
|
controller.enqueue({
|
|
8363
8464
|
type: "source",
|
|
8364
8465
|
sourceType: "document",
|
|
8365
|
-
id: (
|
|
8466
|
+
id: (_K = (_J = (_I = self.config).generateId) == null ? void 0 : _J.call(_I)) != null ? _K : generateId2(),
|
|
8366
8467
|
mediaType: "text/plain",
|
|
8367
8468
|
title: value.annotation.filename,
|
|
8368
8469
|
filename: value.annotation.filename,
|
|
@@ -8378,7 +8479,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8378
8479
|
controller.enqueue({
|
|
8379
8480
|
type: "source",
|
|
8380
8481
|
sourceType: "document",
|
|
8381
|
-
id: (
|
|
8482
|
+
id: (_N = (_M = (_L = self.config).generateId) == null ? void 0 : _M.call(_L)) != null ? _N : generateId2(),
|
|
8382
8483
|
mediaType: "text/plain",
|
|
8383
8484
|
title: value.annotation.filename,
|
|
8384
8485
|
filename: value.annotation.filename,
|
|
@@ -8394,7 +8495,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8394
8495
|
controller.enqueue({
|
|
8395
8496
|
type: "source",
|
|
8396
8497
|
sourceType: "document",
|
|
8397
|
-
id: (
|
|
8498
|
+
id: (_Q = (_P = (_O = self.config).generateId) == null ? void 0 : _P.call(_O)) != null ? _Q : generateId2(),
|
|
8398
8499
|
mediaType: "application/octet-stream",
|
|
8399
8500
|
title: value.annotation.file_id,
|
|
8400
8501
|
filename: value.annotation.file_id,
|
|
@@ -8410,11 +8511,14 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8410
8511
|
} else if (isErrorChunk(value)) {
|
|
8411
8512
|
encounteredStreamError = true;
|
|
8412
8513
|
finishReason = { unified: "error", raw: "error" };
|
|
8413
|
-
controller.enqueue({
|
|
8514
|
+
controller.enqueue({
|
|
8515
|
+
type: "error",
|
|
8516
|
+
error: (_R = createOpenAIProviderStreamError(value)) != null ? _R : value
|
|
8517
|
+
});
|
|
8414
8518
|
}
|
|
8415
8519
|
},
|
|
8416
8520
|
flush(controller) {
|
|
8417
|
-
var
|
|
8521
|
+
var _a3;
|
|
8418
8522
|
for (const toolCall of Object.values(ongoingToolCalls)) {
|
|
8419
8523
|
if (!(toolCall == null ? void 0 : toolCall.suppressInputStreaming)) {
|
|
8420
8524
|
continue;
|
|
@@ -8424,7 +8528,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8424
8528
|
id: toolCall.toolCallId,
|
|
8425
8529
|
toolName: toolCall.toolName
|
|
8426
8530
|
});
|
|
8427
|
-
for (const delta of (
|
|
8531
|
+
for (const delta of (_a3 = toolCall.bufferedInputDeltas) != null ? _a3 : []) {
|
|
8428
8532
|
controller.enqueue({
|
|
8429
8533
|
type: "tool-input-delta",
|
|
8430
8534
|
id: toolCall.toolCallId,
|
|
@@ -8532,7 +8636,7 @@ function isResponseOutputChunk(chunk) {
|
|
|
8532
8636
|
return !(chunk.type === "response.created" || chunk.type === "response.in_progress" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
|
|
8533
8637
|
}
|
|
8534
8638
|
function mapWebSearchOutput(action) {
|
|
8535
|
-
var
|
|
8639
|
+
var _a2;
|
|
8536
8640
|
if (action == null) {
|
|
8537
8641
|
return {};
|
|
8538
8642
|
}
|
|
@@ -8541,7 +8645,7 @@ function mapWebSearchOutput(action) {
|
|
|
8541
8645
|
return {
|
|
8542
8646
|
action: {
|
|
8543
8647
|
type: "search",
|
|
8544
|
-
query: (
|
|
8648
|
+
query: (_a2 = action.query) != null ? _a2 : void 0,
|
|
8545
8649
|
...action.queries != null && { queries: action.queries }
|
|
8546
8650
|
},
|
|
8547
8651
|
// include sources when provided by the Responses API (behind include flag)
|
|
@@ -8612,9 +8716,17 @@ var OpenAIResponsesBatch = class {
|
|
|
8612
8716
|
this.options = options;
|
|
8613
8717
|
}
|
|
8614
8718
|
async startBatch(options) {
|
|
8615
|
-
var
|
|
8719
|
+
var _a2, _b, _c, _d;
|
|
8616
8720
|
const fileParts = [];
|
|
8617
|
-
const warnings = []
|
|
8721
|
+
const warnings = options.webhookUrl == null ? [] : [
|
|
8722
|
+
{
|
|
8723
|
+
warning: {
|
|
8724
|
+
type: "unsupported",
|
|
8725
|
+
feature: "webhookUrl",
|
|
8726
|
+
details: "The OpenAI Batch API does not support per-batch webhook URLs."
|
|
8727
|
+
}
|
|
8728
|
+
}
|
|
8729
|
+
];
|
|
8618
8730
|
for (const request of options.requests) {
|
|
8619
8731
|
const preparedRequest = await this.options.prepareRequest(request);
|
|
8620
8732
|
fileParts.push(
|
|
@@ -8645,7 +8757,7 @@ var OpenAIResponsesBatch = class {
|
|
|
8645
8757
|
);
|
|
8646
8758
|
const { value: uploadedFile } = await postToApi({
|
|
8647
8759
|
url: this.getUrl("/files"),
|
|
8648
|
-
headers: combineHeaders7((_b = (
|
|
8760
|
+
headers: combineHeaders7((_b = (_a2 = this.options.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
8649
8761
|
body: {
|
|
8650
8762
|
content: formData,
|
|
8651
8763
|
values: {
|
|
@@ -8695,7 +8807,8 @@ var OpenAIResponsesBatch = class {
|
|
|
8695
8807
|
}
|
|
8696
8808
|
async getBatchResults(options) {
|
|
8697
8809
|
const batch = await this.retrieveBatch(options);
|
|
8698
|
-
|
|
8810
|
+
const batchStatus = convertOpenAIBatchStatus(batch);
|
|
8811
|
+
if (batchStatus.status === "pending") {
|
|
8699
8812
|
throw new InvalidArgumentError({
|
|
8700
8813
|
argument: "batchId",
|
|
8701
8814
|
message: `OpenAI batch "${options.batchId}" is not complete.`
|
|
@@ -8704,14 +8817,20 @@ var OpenAIResponsesBatch = class {
|
|
|
8704
8817
|
const fileIds = [batch.output_file_id, batch.error_file_id].filter(
|
|
8705
8818
|
(fileId) => fileId != null
|
|
8706
8819
|
);
|
|
8820
|
+
if (batchStatus.status === "completed" && fileIds.length === 0) {
|
|
8821
|
+
throw new InvalidResponseDataError({
|
|
8822
|
+
data: batch,
|
|
8823
|
+
message: `OpenAI batch "${options.batchId}" completed without batch output.`
|
|
8824
|
+
});
|
|
8825
|
+
}
|
|
8707
8826
|
const iterator = this.iterateBatchResults({ fileIds, options });
|
|
8708
8827
|
return convertAsyncIteratorToReadableStream(iterator);
|
|
8709
8828
|
}
|
|
8710
8829
|
async retrieveBatch(options) {
|
|
8711
|
-
var
|
|
8830
|
+
var _a2, _b;
|
|
8712
8831
|
const { value: batch } = await getFromApi({
|
|
8713
8832
|
url: this.getUrl(`/batches/${encodeURIComponent(options.batchId)}`),
|
|
8714
|
-
headers: combineHeaders7((_b = (
|
|
8833
|
+
headers: combineHeaders7((_b = (_a2 = this.options.config).headers) == null ? void 0 : _b.call(_a2), options.headers),
|
|
8715
8834
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
8716
8835
|
successfulResponseHandler: createJsonResponseHandler7(
|
|
8717
8836
|
openaiBatchResponseSchema
|
|
@@ -8726,21 +8845,23 @@ var OpenAIResponsesBatch = class {
|
|
|
8726
8845
|
fileIds,
|
|
8727
8846
|
options
|
|
8728
8847
|
}) {
|
|
8729
|
-
var
|
|
8848
|
+
var _a2, _b;
|
|
8730
8849
|
for (const fileId of fileIds) {
|
|
8731
|
-
const { value:
|
|
8850
|
+
const { value: lines } = await getFromApi({
|
|
8732
8851
|
url: this.getUrl(`/files/${encodeURIComponent(fileId)}/content`),
|
|
8733
8852
|
headers: combineHeaders7(
|
|
8734
|
-
(_b = (
|
|
8853
|
+
(_b = (_a2 = this.options.config).headers) == null ? void 0 : _b.call(_a2),
|
|
8735
8854
|
options.headers
|
|
8736
8855
|
),
|
|
8737
8856
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
8738
|
-
successfulResponseHandler:
|
|
8857
|
+
successfulResponseHandler: createJsonLinesResponseHandler(
|
|
8858
|
+
openaiBatchResultLineSchema
|
|
8859
|
+
),
|
|
8739
8860
|
abortSignal: options.abortSignal,
|
|
8740
8861
|
fetch: this.options.config.fetch,
|
|
8741
8862
|
validateUrl: false
|
|
8742
8863
|
});
|
|
8743
|
-
for await (const line of
|
|
8864
|
+
for await (const line of lines) {
|
|
8744
8865
|
yield await this.convertResultLine(line);
|
|
8745
8866
|
}
|
|
8746
8867
|
}
|
|
@@ -8834,9 +8955,9 @@ var OpenAIResponsesBatchLanguageModel = class _OpenAIResponsesBatchLanguageModel
|
|
|
8834
8955
|
}
|
|
8835
8956
|
};
|
|
8836
8957
|
function convertOpenAIBatchStatus(batch) {
|
|
8837
|
-
var
|
|
8958
|
+
var _a2, _b, _c;
|
|
8838
8959
|
const status = mapOpenAIBatchStatus(batch.status);
|
|
8839
|
-
const firstError = (_b = (
|
|
8960
|
+
const firstError = (_b = (_a2 = batch.errors) == null ? void 0 : _a2.data) == null ? void 0 : _b[0];
|
|
8840
8961
|
const requestCounts = convertOpenAIRequestCounts(batch.request_counts);
|
|
8841
8962
|
const createdAt = convertUnixTimestamp(batch.created_at);
|
|
8842
8963
|
const expiresAt = convertUnixTimestamp(batch.expires_at);
|
|
@@ -8874,15 +8995,12 @@ function convertOpenAIRequestCounts(counts) {
|
|
|
8874
8995
|
const total = counts == null ? void 0 : counts.total;
|
|
8875
8996
|
const completed = counts == null ? void 0 : counts.completed;
|
|
8876
8997
|
const failed = counts == null ? void 0 : counts.failed;
|
|
8877
|
-
|
|
8878
|
-
return void 0;
|
|
8879
|
-
}
|
|
8880
|
-
return {
|
|
8998
|
+
return normalizeBatchRequestCounts({
|
|
8881
8999
|
total,
|
|
8882
|
-
pending: total - completed - failed,
|
|
9000
|
+
pending: total != null && completed != null && failed != null ? total - completed - failed : void 0,
|
|
8883
9001
|
completed,
|
|
8884
9002
|
failed
|
|
8885
|
-
};
|
|
9003
|
+
});
|
|
8886
9004
|
}
|
|
8887
9005
|
function convertUnixTimestamp(value) {
|
|
8888
9006
|
if (value == null || !Number.isFinite(value)) {
|
|
@@ -8895,7 +9013,7 @@ async function convertOpenAIErrorResponse({
|
|
|
8895
9013
|
body,
|
|
8896
9014
|
statusCode
|
|
8897
9015
|
}) {
|
|
8898
|
-
var
|
|
9016
|
+
var _a2;
|
|
8899
9017
|
const result = await safeValidateTypes({
|
|
8900
9018
|
value: body,
|
|
8901
9019
|
schema: openaiErrorDataSchema
|
|
@@ -8908,17 +9026,27 @@ async function convertOpenAIErrorResponse({
|
|
|
8908
9026
|
}
|
|
8909
9027
|
return {
|
|
8910
9028
|
message: result.value.error.message,
|
|
8911
|
-
type: (
|
|
9029
|
+
type: (_a2 = result.value.error.type) != null ? _a2 : void 0,
|
|
8912
9030
|
code: result.value.error.code != null ? String(result.value.error.code) : void 0,
|
|
8913
9031
|
statusCode
|
|
8914
9032
|
};
|
|
8915
9033
|
}
|
|
8916
9034
|
async function convertOpenAIResponsesBatchResponse(body) {
|
|
8917
|
-
var
|
|
8918
|
-
const
|
|
9035
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
9036
|
+
const validation = await safeValidateTypes({
|
|
8919
9037
|
value: body,
|
|
8920
9038
|
schema: openaiResponsesResponseSchema
|
|
8921
9039
|
});
|
|
9040
|
+
if (!validation.success) {
|
|
9041
|
+
return {
|
|
9042
|
+
success: false,
|
|
9043
|
+
error: {
|
|
9044
|
+
message: "OpenAI returned an invalid Responses batch result.",
|
|
9045
|
+
code: "invalid_response"
|
|
9046
|
+
}
|
|
9047
|
+
};
|
|
9048
|
+
}
|
|
9049
|
+
const response = validation.value;
|
|
8922
9050
|
if (response.error != null) {
|
|
8923
9051
|
return {
|
|
8924
9052
|
success: false,
|
|
@@ -8930,7 +9058,7 @@ async function convertOpenAIResponsesBatchResponse(body) {
|
|
|
8930
9058
|
};
|
|
8931
9059
|
}
|
|
8932
9060
|
if (response.output == null) {
|
|
8933
|
-
const detail = (
|
|
9061
|
+
const detail = (_a2 = response.incomplete_details) == null ? void 0 : _a2.reason;
|
|
8934
9062
|
return {
|
|
8935
9063
|
success: false,
|
|
8936
9064
|
error: {
|
|
@@ -8942,21 +9070,49 @@ async function convertOpenAIResponsesBatchResponse(body) {
|
|
|
8942
9070
|
const content = [];
|
|
8943
9071
|
const logprobs = [];
|
|
8944
9072
|
for (const part of response.output) {
|
|
8945
|
-
|
|
8946
|
-
|
|
8947
|
-
|
|
8948
|
-
|
|
8949
|
-
|
|
9073
|
+
switch (part.type) {
|
|
9074
|
+
case "reasoning": {
|
|
9075
|
+
const summaries = part.summary.length > 0 ? part.summary : [{ type: "summary_text", text: "" }];
|
|
9076
|
+
for (const summary of summaries) {
|
|
9077
|
+
content.push({
|
|
9078
|
+
type: "reasoning",
|
|
9079
|
+
text: summary.text,
|
|
9080
|
+
providerMetadata: {
|
|
9081
|
+
openai: {
|
|
9082
|
+
itemId: part.id,
|
|
9083
|
+
reasoningEncryptedContent: (_b = part.encrypted_content) != null ? _b : null
|
|
9084
|
+
}
|
|
9085
|
+
}
|
|
9086
|
+
});
|
|
8950
9087
|
}
|
|
9088
|
+
break;
|
|
8951
9089
|
}
|
|
8952
|
-
|
|
8953
|
-
|
|
8954
|
-
|
|
8955
|
-
|
|
8956
|
-
|
|
8957
|
-
|
|
9090
|
+
case "message": {
|
|
9091
|
+
for (const contentPart of part.content) {
|
|
9092
|
+
content.push({ type: "text", text: contentPart.text });
|
|
9093
|
+
if (contentPart.logprobs != null) {
|
|
9094
|
+
logprobs.push(contentPart.logprobs);
|
|
9095
|
+
}
|
|
8958
9096
|
}
|
|
8959
|
-
|
|
9097
|
+
break;
|
|
9098
|
+
}
|
|
9099
|
+
case "function_call":
|
|
9100
|
+
case "custom_tool_call":
|
|
9101
|
+
return {
|
|
9102
|
+
success: false,
|
|
9103
|
+
error: {
|
|
9104
|
+
message: "OpenAI returned a tool call, but tool calls are not supported in AI SDK text batches.",
|
|
9105
|
+
code: "unsupported_content"
|
|
9106
|
+
}
|
|
9107
|
+
};
|
|
9108
|
+
default:
|
|
9109
|
+
return {
|
|
9110
|
+
success: false,
|
|
9111
|
+
error: {
|
|
9112
|
+
message: `OpenAI returned an unsupported "${part.type}" output item in an AI SDK text batch.`,
|
|
9113
|
+
code: "unsupported_content"
|
|
9114
|
+
}
|
|
9115
|
+
};
|
|
8960
9116
|
}
|
|
8961
9117
|
}
|
|
8962
9118
|
const providerMetadata = {
|
|
@@ -8964,7 +9120,7 @@ async function convertOpenAIResponsesBatchResponse(body) {
|
|
|
8964
9120
|
responseId: response.id,
|
|
8965
9121
|
...logprobs.length > 0 ? { logprobs } : {},
|
|
8966
9122
|
...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
|
|
8967
|
-
...((
|
|
9123
|
+
...((_c = response.reasoning) == null ? void 0 : _c.context) != null ? { reasoningContext: response.reasoning.context } : {}
|
|
8968
9124
|
}
|
|
8969
9125
|
};
|
|
8970
9126
|
return {
|
|
@@ -8973,10 +9129,10 @@ async function convertOpenAIResponsesBatchResponse(body) {
|
|
|
8973
9129
|
content,
|
|
8974
9130
|
finishReason: {
|
|
8975
9131
|
unified: mapOpenAIResponseFinishReason({
|
|
8976
|
-
finishReason: (
|
|
9132
|
+
finishReason: (_d = response.incomplete_details) == null ? void 0 : _d.reason,
|
|
8977
9133
|
hasFunctionCall: false
|
|
8978
9134
|
}),
|
|
8979
|
-
raw: (
|
|
9135
|
+
raw: (_f = (_e = response.incomplete_details) == null ? void 0 : _e.reason) != null ? _f : void 0
|
|
8980
9136
|
},
|
|
8981
9137
|
usage: convertOpenAIResponsesUsage(response.usage),
|
|
8982
9138
|
response: {
|
|
@@ -8989,58 +9145,10 @@ async function convertOpenAIResponsesBatchResponse(body) {
|
|
|
8989
9145
|
}
|
|
8990
9146
|
};
|
|
8991
9147
|
}
|
|
8992
|
-
var rawStreamResponseHandler = async ({ response }) => {
|
|
8993
|
-
if (response.body == null) {
|
|
8994
|
-
throw new EmptyResponseBodyError();
|
|
8995
|
-
}
|
|
8996
|
-
return { value: response.body };
|
|
8997
|
-
};
|
|
8998
|
-
async function* parseJsonLines(stream) {
|
|
8999
|
-
const reader = stream.getReader();
|
|
9000
|
-
const decoder = new TextDecoder();
|
|
9001
|
-
let buffer = "";
|
|
9002
|
-
let finished = false;
|
|
9003
|
-
try {
|
|
9004
|
-
while (true) {
|
|
9005
|
-
const { done, value } = await reader.read();
|
|
9006
|
-
if (done) {
|
|
9007
|
-
finished = true;
|
|
9008
|
-
buffer += decoder.decode();
|
|
9009
|
-
break;
|
|
9010
|
-
}
|
|
9011
|
-
buffer += decoder.decode(value, { stream: true });
|
|
9012
|
-
let lineEnd = buffer.indexOf("\n");
|
|
9013
|
-
while (lineEnd !== -1) {
|
|
9014
|
-
const line = buffer.slice(0, lineEnd).replace(/\r$/, "");
|
|
9015
|
-
buffer = buffer.slice(lineEnd + 1);
|
|
9016
|
-
if (line.trim().length > 0) {
|
|
9017
|
-
yield await parseJSON2({
|
|
9018
|
-
text: line,
|
|
9019
|
-
schema: openaiBatchResultLineSchema
|
|
9020
|
-
});
|
|
9021
|
-
}
|
|
9022
|
-
lineEnd = buffer.indexOf("\n");
|
|
9023
|
-
}
|
|
9024
|
-
}
|
|
9025
|
-
const finalLine = buffer.replace(/\r$/, "");
|
|
9026
|
-
if (finalLine.trim().length > 0) {
|
|
9027
|
-
yield await parseJSON2({
|
|
9028
|
-
text: finalLine,
|
|
9029
|
-
schema: openaiBatchResultLineSchema
|
|
9030
|
-
});
|
|
9031
|
-
}
|
|
9032
|
-
} finally {
|
|
9033
|
-
if (!finished) {
|
|
9034
|
-
await reader.cancel().catch(() => {
|
|
9035
|
-
});
|
|
9036
|
-
}
|
|
9037
|
-
reader.releaseLock();
|
|
9038
|
-
}
|
|
9039
|
-
}
|
|
9040
9148
|
|
|
9041
9149
|
// src/realtime/openai-realtime-event-mapper.ts
|
|
9042
9150
|
function parseOpenAIRealtimeServerEvent(raw) {
|
|
9043
|
-
var
|
|
9151
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
|
|
9044
9152
|
const event = raw;
|
|
9045
9153
|
const type = event.type;
|
|
9046
9154
|
switch (type) {
|
|
@@ -9048,7 +9156,7 @@ function parseOpenAIRealtimeServerEvent(raw) {
|
|
|
9048
9156
|
case "session.created":
|
|
9049
9157
|
return {
|
|
9050
9158
|
type: "session-created",
|
|
9051
|
-
sessionId: (
|
|
9159
|
+
sessionId: (_a2 = event.session) == null ? void 0 : _a2.id,
|
|
9052
9160
|
raw
|
|
9053
9161
|
};
|
|
9054
9162
|
case "session.updated":
|
|
@@ -9286,7 +9394,7 @@ function serializeOpenAIRealtimeClientEvent(event, modelId) {
|
|
|
9286
9394
|
}
|
|
9287
9395
|
}
|
|
9288
9396
|
function buildOpenAISessionConfig(config, modelId) {
|
|
9289
|
-
var
|
|
9397
|
+
var _a2;
|
|
9290
9398
|
const session = {
|
|
9291
9399
|
type: "realtime",
|
|
9292
9400
|
model: modelId
|
|
@@ -9327,7 +9435,7 @@ function buildOpenAISessionConfig(config, modelId) {
|
|
|
9327
9435
|
}
|
|
9328
9436
|
if (config.inputAudioTranscription != null) {
|
|
9329
9437
|
input.transcription = {
|
|
9330
|
-
model: (
|
|
9438
|
+
model: (_a2 = config.inputAudioTranscription.model) != null ? _a2 : "gpt-realtime-whisper",
|
|
9331
9439
|
...config.inputAudioTranscription.language != null ? { language: config.inputAudioTranscription.language } : {},
|
|
9332
9440
|
...config.inputAudioTranscription.prompt != null ? { prompt: config.inputAudioTranscription.prompt } : {}
|
|
9333
9441
|
};
|
|
@@ -9374,8 +9482,8 @@ var OpenAIRealtimeModel = class {
|
|
|
9374
9482
|
this.config = config;
|
|
9375
9483
|
}
|
|
9376
9484
|
async doCreateClientSecret(options) {
|
|
9377
|
-
var
|
|
9378
|
-
const fetchFn = (
|
|
9485
|
+
var _a2;
|
|
9486
|
+
const fetchFn = (_a2 = this.config.fetch) != null ? _a2 : fetch;
|
|
9379
9487
|
const url = `${this.config.baseURL}/realtime/client_secrets`;
|
|
9380
9488
|
const session = options.sessionConfig != null ? buildOpenAISessionConfig(options.sessionConfig, this.modelId) : { type: "realtime", model: this.modelId };
|
|
9381
9489
|
const response = await fetchFn(url, {
|
|
@@ -9528,8 +9636,8 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
|
|
|
9528
9636
|
};
|
|
9529
9637
|
}
|
|
9530
9638
|
async doGenerate(options) {
|
|
9531
|
-
var
|
|
9532
|
-
const currentDate = (_c = (_b = (
|
|
9639
|
+
var _a2, _b, _c, _d, _e;
|
|
9640
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
9533
9641
|
const { requestBody, warnings } = await this.getArgs(options);
|
|
9534
9642
|
const {
|
|
9535
9643
|
value: audio,
|
|
@@ -9805,13 +9913,13 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
9805
9913
|
};
|
|
9806
9914
|
}
|
|
9807
9915
|
async doGenerate(options) {
|
|
9808
|
-
var
|
|
9916
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
9809
9917
|
if (isRealtimeTranscriptionModelId(this.modelId)) {
|
|
9810
9918
|
throw new UnsupportedFunctionalityError6({
|
|
9811
9919
|
functionality: `non-streaming transcription with ${this.modelId}`
|
|
9812
9920
|
});
|
|
9813
9921
|
}
|
|
9814
|
-
const currentDate = (_c = (_b = (
|
|
9922
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
9815
9923
|
const { formData, warnings } = await this.getArgs(options);
|
|
9816
9924
|
const {
|
|
9817
9925
|
value: response,
|
|
@@ -9855,13 +9963,13 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
9855
9963
|
};
|
|
9856
9964
|
}
|
|
9857
9965
|
async doStream(options) {
|
|
9858
|
-
var
|
|
9966
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
9859
9967
|
if (!isRealtimeTranscriptionModelId(this.modelId)) {
|
|
9860
9968
|
throw new UnsupportedFunctionalityError6({
|
|
9861
9969
|
functionality: `streaming transcription with ${this.modelId}`
|
|
9862
9970
|
});
|
|
9863
9971
|
}
|
|
9864
|
-
const currentDate = (_c = (_b = (
|
|
9972
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
9865
9973
|
const openAIOptions = await parseProviderOptions9({
|
|
9866
9974
|
provider: "openai",
|
|
9867
9975
|
providerOptions: options.providerOptions,
|
|
@@ -10000,7 +10108,7 @@ function createOpenAIRealtimeTranscriptionStream({
|
|
|
10000
10108
|
void sendAudio(socket).catch(finishWithError);
|
|
10001
10109
|
},
|
|
10002
10110
|
onMessageText: async (text) => {
|
|
10003
|
-
var
|
|
10111
|
+
var _a2, _b, _c, _d;
|
|
10004
10112
|
const parsed = await safeParseJSON2({ text });
|
|
10005
10113
|
if (!parsed.success) return;
|
|
10006
10114
|
const raw = parsed.value;
|
|
@@ -10012,7 +10120,7 @@ function createOpenAIRealtimeTranscriptionStream({
|
|
|
10012
10120
|
controller.enqueue({
|
|
10013
10121
|
type: "transcript-delta",
|
|
10014
10122
|
id: raw.item_id,
|
|
10015
|
-
delta: (
|
|
10123
|
+
delta: (_a2 = raw.delta) != null ? _a2 : ""
|
|
10016
10124
|
});
|
|
10017
10125
|
break;
|
|
10018
10126
|
}
|
|
@@ -10051,7 +10159,7 @@ function buildOpenAIRealtimeTranscriptionSession({
|
|
|
10051
10159
|
inputAudioFormat,
|
|
10052
10160
|
providerOptions
|
|
10053
10161
|
}) {
|
|
10054
|
-
var
|
|
10162
|
+
var _a2, _b;
|
|
10055
10163
|
return {
|
|
10056
10164
|
type: "session.update",
|
|
10057
10165
|
session: {
|
|
@@ -10065,7 +10173,7 @@ function buildOpenAIRealtimeTranscriptionSession({
|
|
|
10065
10173
|
transcription: {
|
|
10066
10174
|
model: modelId,
|
|
10067
10175
|
...(providerOptions == null ? void 0 : providerOptions.language) != null ? { language: providerOptions.language } : {},
|
|
10068
|
-
...((
|
|
10176
|
+
...((_a2 = providerOptions == null ? void 0 : providerOptions.streaming) == null ? void 0 : _a2.delay) != null ? { delay: providerOptions.streaming.delay } : {}
|
|
10069
10177
|
},
|
|
10070
10178
|
turn_detection: null
|
|
10071
10179
|
}
|
|
@@ -10075,14 +10183,14 @@ function buildOpenAIRealtimeTranscriptionSession({
|
|
|
10075
10183
|
};
|
|
10076
10184
|
}
|
|
10077
10185
|
function getOpenAIRealtimeConnection(headers) {
|
|
10078
|
-
var
|
|
10186
|
+
var _a2;
|
|
10079
10187
|
let authorization;
|
|
10080
10188
|
for (const [key, value] of Object.entries(headers)) {
|
|
10081
10189
|
if (key.toLowerCase() === "authorization" && value != null) {
|
|
10082
10190
|
authorization = value;
|
|
10083
10191
|
}
|
|
10084
10192
|
}
|
|
10085
|
-
const token = (
|
|
10193
|
+
const token = (_a2 = authorization == null ? void 0 : authorization.match(/^bearer\s+(.+)$/i)) == null ? void 0 : _a2[1];
|
|
10086
10194
|
if (token == null) {
|
|
10087
10195
|
return { protocols: ["realtime"], headers };
|
|
10088
10196
|
}
|
|
@@ -10143,14 +10251,14 @@ var OpenAISpeechTranslationModel = class _OpenAISpeechTranslationModel {
|
|
|
10143
10251
|
return this.config.provider;
|
|
10144
10252
|
}
|
|
10145
10253
|
async doStream(options) {
|
|
10146
|
-
var
|
|
10254
|
+
var _a2, _b, _c, _d, _e;
|
|
10147
10255
|
if (options.targetLanguage == null) {
|
|
10148
10256
|
throw new InvalidArgumentError2({
|
|
10149
10257
|
argument: "targetLanguage",
|
|
10150
10258
|
message: `targetLanguage is required for translation model '${this.modelId}'.`
|
|
10151
10259
|
});
|
|
10152
10260
|
}
|
|
10153
|
-
const currentDate = (_c = (_b = (
|
|
10261
|
+
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
10154
10262
|
await parseProviderOptions10({
|
|
10155
10263
|
provider: "openai",
|
|
10156
10264
|
providerOptions: options.providerOptions,
|
|
@@ -10296,7 +10404,7 @@ function createOpenAIRealtimeSpeechTranslationStream({
|
|
|
10296
10404
|
void sendAudio(socket).catch(finishWithError);
|
|
10297
10405
|
},
|
|
10298
10406
|
onMessageText: async (text) => {
|
|
10299
|
-
var
|
|
10407
|
+
var _a2, _b, _c, _d, _e, _f;
|
|
10300
10408
|
if (finished) return;
|
|
10301
10409
|
const parsed = await safeParseJSON3({ text });
|
|
10302
10410
|
if (!parsed.success) return;
|
|
@@ -10315,7 +10423,7 @@ function createOpenAIRealtimeSpeechTranslationStream({
|
|
|
10315
10423
|
break;
|
|
10316
10424
|
}
|
|
10317
10425
|
case "session.output_transcript.delta": {
|
|
10318
|
-
translationText += (
|
|
10426
|
+
translationText += (_a2 = raw.delta) != null ? _a2 : "";
|
|
10319
10427
|
controller.enqueue({
|
|
10320
10428
|
type: "output-text-delta",
|
|
10321
10429
|
delta: (_b = raw.delta) != null ? _b : ""
|
|
@@ -10392,14 +10500,14 @@ function validateOpenAISpeechTranslationInputAudioFormat(inputAudioFormat) {
|
|
|
10392
10500
|
}
|
|
10393
10501
|
}
|
|
10394
10502
|
function getOpenAIRealtimeConnection2(headers) {
|
|
10395
|
-
var
|
|
10503
|
+
var _a2;
|
|
10396
10504
|
let authorization;
|
|
10397
10505
|
for (const [key, value] of Object.entries(headers)) {
|
|
10398
10506
|
if (key.toLowerCase() === "authorization" && value != null) {
|
|
10399
10507
|
authorization = value;
|
|
10400
10508
|
}
|
|
10401
10509
|
}
|
|
10402
|
-
const token = (
|
|
10510
|
+
const token = (_a2 = authorization == null ? void 0 : authorization.match(/^bearer\s+(.+)$/i)) == null ? void 0 : _a2[1];
|
|
10403
10511
|
if (token == null) {
|
|
10404
10512
|
return { protocols: ["realtime"], headers };
|
|
10405
10513
|
}
|
|
@@ -10498,19 +10606,19 @@ var OpenAISkills = class {
|
|
|
10498
10606
|
};
|
|
10499
10607
|
|
|
10500
10608
|
// src/version.ts
|
|
10501
|
-
var VERSION = true ? "4.0.
|
|
10609
|
+
var VERSION = true ? "4.0.49" : "0.0.0-test";
|
|
10502
10610
|
|
|
10503
10611
|
// src/openai-provider.ts
|
|
10504
10612
|
function createOpenAI(options = {}) {
|
|
10505
|
-
var
|
|
10506
|
-
const baseURL = (
|
|
10613
|
+
var _a2, _b;
|
|
10614
|
+
const baseURL = (_a2 = withoutTrailingSlash(
|
|
10507
10615
|
validateBaseURL(
|
|
10508
10616
|
loadOptionalSetting({
|
|
10509
10617
|
settingValue: options.baseURL,
|
|
10510
10618
|
environmentVariableName: "OPENAI_BASE_URL"
|
|
10511
10619
|
})
|
|
10512
10620
|
)
|
|
10513
|
-
)) != null ?
|
|
10621
|
+
)) != null ? _a2 : "https://api.openai.com/v1";
|
|
10514
10622
|
const providerName = (_b = options.name) != null ? _b : "openai";
|
|
10515
10623
|
const getHeaders = () => withUserAgentSuffix(
|
|
10516
10624
|
{
|