@ai-sdk/openai 4.0.75 → 4.0.77
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 +16 -0
- package/dist/index.js +423 -505
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +353 -414
- package/dist/internal/index.js.map +1 -1
- package/package.json +3 -3
- package/src/responses/openai-responses-prepare-tools.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -47,17 +47,16 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
47
47
|
|
|
48
48
|
// src/openai-language-model-capabilities.ts
|
|
49
49
|
function getOpenAILanguageModelCapabilities(modelId) {
|
|
50
|
-
var _a2, _b, _c, _d, _e;
|
|
51
50
|
const oSeriesVersion = getOSeriesVersion(modelId);
|
|
52
51
|
const gptVersion = getGptVersion(modelId);
|
|
53
|
-
const isGptChatModel =
|
|
54
|
-
const isGptNanoModel =
|
|
52
|
+
const isGptChatModel = gptVersion?.minor == null && (gptVersion?.variant?.startsWith("chat") ?? false);
|
|
53
|
+
const isGptNanoModel = gptVersion?.variant?.startsWith("nano") ?? false;
|
|
55
54
|
const isGpt6OrLaterModel = gptVersion != null && gptVersion.major >= 6;
|
|
56
55
|
const isGpt6SolOrLuna = modelId === "gpt-6-sol" || modelId === "gpt-6-luna";
|
|
57
56
|
const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
|
|
58
57
|
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
|
|
59
58
|
const isReasoningModel = oSeriesVersion != null || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
|
|
60
|
-
const supportsNonReasoningParameters = !isGpt6OrLaterModel && gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && (
|
|
59
|
+
const supportsNonReasoningParameters = !isGpt6OrLaterModel && gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && (gptVersion.minor ?? 0) >= 1);
|
|
61
60
|
const systemMessageMode = isReasoningModel ? "developer" : "system";
|
|
62
61
|
return {
|
|
63
62
|
supportsFlexProcessing,
|
|
@@ -92,7 +91,6 @@ import {
|
|
|
92
91
|
createProviderStreamError
|
|
93
92
|
} from "@ai-sdk/provider-utils";
|
|
94
93
|
function createOpenAIProviderStreamError(frame) {
|
|
95
|
-
var _a2, _b;
|
|
96
94
|
const streamError = parseStreamError(frame);
|
|
97
95
|
if (streamError == null) {
|
|
98
96
|
return void 0;
|
|
@@ -100,8 +98,8 @@ function createOpenAIProviderStreamError(frame) {
|
|
|
100
98
|
const statusCode = getStatusCode(streamError);
|
|
101
99
|
return createProviderStreamError({
|
|
102
100
|
message: streamError.message,
|
|
103
|
-
type:
|
|
104
|
-
code:
|
|
101
|
+
type: streamError.type ?? void 0,
|
|
102
|
+
code: streamError.code ?? void 0,
|
|
105
103
|
statusCode,
|
|
106
104
|
isRetryable: isRetryableStreamError(streamError, statusCode),
|
|
107
105
|
data: frame
|
|
@@ -157,7 +155,7 @@ async function throwIfOpenAIStreamErrorBeforeOutput({
|
|
|
157
155
|
if (isOutputChunk(chunk.value)) {
|
|
158
156
|
return streamForConsumer;
|
|
159
157
|
}
|
|
160
|
-
if (!accepted &&
|
|
158
|
+
if (!accepted && isAcceptedChunk?.(chunk.value) === true) {
|
|
161
159
|
accepted = true;
|
|
162
160
|
}
|
|
163
161
|
}
|
|
@@ -173,7 +171,7 @@ async function drainReader(reader) {
|
|
|
173
171
|
try {
|
|
174
172
|
while (!(await reader.read()).done) {
|
|
175
173
|
}
|
|
176
|
-
} catch
|
|
174
|
+
} catch {
|
|
177
175
|
} finally {
|
|
178
176
|
reader.releaseLock();
|
|
179
177
|
}
|
|
@@ -203,35 +201,33 @@ function createOpenAIStreamError({
|
|
|
203
201
|
requestBodyValues,
|
|
204
202
|
responseHeaders
|
|
205
203
|
}) {
|
|
206
|
-
var _a2, _b;
|
|
207
204
|
const streamError = createOpenAIProviderStreamError(frame);
|
|
208
205
|
return new APICallError({
|
|
209
|
-
message:
|
|
206
|
+
message: streamError?.message ?? "OpenAI stream failed before any output was generated",
|
|
210
207
|
url,
|
|
211
208
|
requestBodyValues,
|
|
212
|
-
statusCode:
|
|
209
|
+
statusCode: streamError?.statusCode ?? 500,
|
|
213
210
|
responseHeaders,
|
|
214
211
|
responseBody: JSON.stringify(frame),
|
|
215
212
|
data: frame,
|
|
216
|
-
isRetryable: streamError
|
|
213
|
+
isRetryable: streamError?.isRetryable
|
|
217
214
|
});
|
|
218
215
|
}
|
|
219
216
|
function parseStreamError(frame) {
|
|
220
|
-
var _a2;
|
|
221
217
|
const value = asRecord(frame);
|
|
222
218
|
if (value == null) {
|
|
223
219
|
return void 0;
|
|
224
220
|
}
|
|
225
221
|
if (value.type === "response.failed") {
|
|
226
222
|
const response = asRecord(value.response);
|
|
227
|
-
const responseError = asRecord(response
|
|
228
|
-
return typeof
|
|
223
|
+
const responseError = asRecord(response?.error);
|
|
224
|
+
return typeof responseError?.message === "string" ? {
|
|
229
225
|
message: responseError.message,
|
|
230
226
|
code: getStringOrNumber(responseError.code),
|
|
231
227
|
type: "response.failed"
|
|
232
228
|
} : void 0;
|
|
233
229
|
}
|
|
234
|
-
const error =
|
|
230
|
+
const error = asRecord(value.error) ?? value;
|
|
235
231
|
return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
|
|
236
232
|
message: error.message,
|
|
237
233
|
code: getStringOrNumber(error.code),
|
|
@@ -287,19 +283,18 @@ function isRetryableStreamError(error, statusCode) {
|
|
|
287
283
|
// src/chat/convert-openai-chat-usage.ts
|
|
288
284
|
import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
|
|
289
285
|
function convertOpenAIChatUsage(usage) {
|
|
290
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
291
286
|
if (usage == null) {
|
|
292
287
|
return createNullLanguageModelUsage();
|
|
293
288
|
}
|
|
294
|
-
const promptTokens =
|
|
295
|
-
const completionTokens =
|
|
296
|
-
const cachedTokens =
|
|
297
|
-
const cacheWriteTokens =
|
|
298
|
-
const reasoningTokens =
|
|
289
|
+
const promptTokens = usage.prompt_tokens ?? 0;
|
|
290
|
+
const completionTokens = usage.completion_tokens ?? 0;
|
|
291
|
+
const cachedTokens = usage.prompt_tokens_details?.cached_tokens ?? 0;
|
|
292
|
+
const cacheWriteTokens = usage.prompt_tokens_details?.cache_write_tokens ?? void 0;
|
|
293
|
+
const reasoningTokens = usage.completion_tokens_details?.reasoning_tokens ?? 0;
|
|
299
294
|
return {
|
|
300
295
|
inputTokens: {
|
|
301
296
|
total: promptTokens,
|
|
302
|
-
noCache: promptTokens - cachedTokens - (cacheWriteTokens
|
|
297
|
+
noCache: promptTokens - cachedTokens - (cacheWriteTokens ?? 0),
|
|
303
298
|
cacheRead: cachedTokens,
|
|
304
299
|
cacheWrite: cacheWriteTokens
|
|
305
300
|
},
|
|
@@ -328,14 +323,12 @@ function serializeToolCallArguments(input) {
|
|
|
328
323
|
);
|
|
329
324
|
}
|
|
330
325
|
function getPromptCacheBreakpoint(providerOptions) {
|
|
331
|
-
|
|
332
|
-
return (_a2 = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
326
|
+
return providerOptions?.openai?.promptCacheBreakpoint;
|
|
333
327
|
}
|
|
334
328
|
function convertToOpenAIChatMessages({
|
|
335
329
|
prompt,
|
|
336
330
|
systemMessageMode = "system"
|
|
337
331
|
}) {
|
|
338
|
-
var _a2, _b;
|
|
339
332
|
const messages = [];
|
|
340
333
|
const warnings = [];
|
|
341
334
|
for (const { role, content, providerOptions } of prompt) {
|
|
@@ -394,7 +387,6 @@ function convertToOpenAIChatMessages({
|
|
|
394
387
|
messages.push({
|
|
395
388
|
role: "user",
|
|
396
389
|
content: content.map((part, index) => {
|
|
397
|
-
var _a3, _b2, _c;
|
|
398
390
|
switch (part.type) {
|
|
399
391
|
case "text": {
|
|
400
392
|
const promptCacheBreakpoint = getPromptCacheBreakpoint(
|
|
@@ -440,7 +432,7 @@ function convertToOpenAIChatMessages({
|
|
|
440
432
|
type: "image_url",
|
|
441
433
|
image_url: {
|
|
442
434
|
url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`,
|
|
443
|
-
detail:
|
|
435
|
+
detail: part.providerOptions?.openai?.imageDetail
|
|
444
436
|
},
|
|
445
437
|
...promptCacheBreakpoint != null && {
|
|
446
438
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
@@ -501,7 +493,7 @@ function convertToOpenAIChatMessages({
|
|
|
501
493
|
return {
|
|
502
494
|
type: "file",
|
|
503
495
|
file: {
|
|
504
|
-
filename:
|
|
496
|
+
filename: part.filename ?? `part-${index}.pdf`,
|
|
505
497
|
file_data: `data:application/pdf;base64,${convertToBase64(part.data.data)}`
|
|
506
498
|
},
|
|
507
499
|
...promptCacheBreakpoint != null && {
|
|
@@ -536,7 +528,7 @@ function convertToOpenAIChatMessages({
|
|
|
536
528
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
537
529
|
}
|
|
538
530
|
});
|
|
539
|
-
hasPromptCacheBreakpoint
|
|
531
|
+
hasPromptCacheBreakpoint ||= promptCacheBreakpoint != null;
|
|
540
532
|
break;
|
|
541
533
|
}
|
|
542
534
|
case "tool-call": {
|
|
@@ -565,7 +557,7 @@ function convertToOpenAIChatMessages({
|
|
|
565
557
|
continue;
|
|
566
558
|
}
|
|
567
559
|
const output = toolResponse.output;
|
|
568
|
-
const promptCacheBreakpoint = (
|
|
560
|
+
const promptCacheBreakpoint = (output.type === "content" ? output.value.map((part) => getPromptCacheBreakpoint(part.providerOptions)).find((breakpoint) => breakpoint != null) : getPromptCacheBreakpoint(output.providerOptions)) ?? getPromptCacheBreakpoint(toolResponse.providerOptions);
|
|
569
561
|
let contentValue;
|
|
570
562
|
switch (output.type) {
|
|
571
563
|
case "text":
|
|
@@ -573,7 +565,7 @@ function convertToOpenAIChatMessages({
|
|
|
573
565
|
contentValue = output.value;
|
|
574
566
|
break;
|
|
575
567
|
case "execution-denied":
|
|
576
|
-
contentValue =
|
|
568
|
+
contentValue = output.reason ?? "Tool call execution denied.";
|
|
577
569
|
break;
|
|
578
570
|
case "content":
|
|
579
571
|
case "json":
|
|
@@ -1087,7 +1079,7 @@ function prepareChatTools({
|
|
|
1087
1079
|
tools,
|
|
1088
1080
|
toolChoice
|
|
1089
1081
|
}) {
|
|
1090
|
-
tools =
|
|
1082
|
+
tools = tools?.length ? tools : void 0;
|
|
1091
1083
|
const toolWarnings = [];
|
|
1092
1084
|
if (tools == null) {
|
|
1093
1085
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
@@ -1186,15 +1178,14 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1186
1178
|
reasoning,
|
|
1187
1179
|
providerOptions
|
|
1188
1180
|
}) {
|
|
1189
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
1190
1181
|
const warnings = [];
|
|
1191
|
-
const openaiOptions =
|
|
1182
|
+
const openaiOptions = await parseProviderOptions({
|
|
1192
1183
|
provider: "openai",
|
|
1193
1184
|
providerOptions,
|
|
1194
1185
|
schema: openaiLanguageModelChatOptions
|
|
1195
|
-
})
|
|
1186
|
+
}) ?? {};
|
|
1196
1187
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
1197
|
-
let resolvedReasoningEffort =
|
|
1188
|
+
let resolvedReasoningEffort = openaiOptions.reasoningEffort ?? (isCustomReasoning(reasoning) ? reasoning : void 0);
|
|
1198
1189
|
if (resolvedReasoningEffort != null && modelCapabilities.supportedReasoningEfforts != null && !modelCapabilities.supportedReasoningEfforts.includes(
|
|
1199
1190
|
resolvedReasoningEffort
|
|
1200
1191
|
)) {
|
|
@@ -1205,19 +1196,19 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1205
1196
|
});
|
|
1206
1197
|
resolvedReasoningEffort = void 0;
|
|
1207
1198
|
}
|
|
1208
|
-
const isReasoningModel =
|
|
1199
|
+
const isReasoningModel = openaiOptions.forceReasoning ?? modelCapabilities.isReasoningModel;
|
|
1209
1200
|
if (topK != null) {
|
|
1210
1201
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
1211
1202
|
}
|
|
1212
1203
|
const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages(
|
|
1213
1204
|
{
|
|
1214
1205
|
prompt,
|
|
1215
|
-
systemMessageMode:
|
|
1206
|
+
systemMessageMode: openaiOptions.systemMessageMode ?? (isReasoningModel ? "developer" : modelCapabilities.systemMessageMode)
|
|
1216
1207
|
}
|
|
1217
1208
|
);
|
|
1218
1209
|
warnings.push(...messageWarnings);
|
|
1219
|
-
const strictJsonSchema =
|
|
1220
|
-
const normalizedResponseFormatSchema =
|
|
1210
|
+
const strictJsonSchema = openaiOptions.strictJsonSchema ?? true;
|
|
1211
|
+
const normalizedResponseFormatSchema = responseFormat?.type === "json" && responseFormat.schema != null ? normalizeOpenAIJsonSchema(responseFormat.schema) : void 0;
|
|
1221
1212
|
if (normalizedResponseFormatSchema != null) {
|
|
1222
1213
|
warnings.push(...normalizedResponseFormatSchema.warnings);
|
|
1223
1214
|
}
|
|
@@ -1236,12 +1227,12 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1236
1227
|
top_p: topP,
|
|
1237
1228
|
frequency_penalty: frequencyPenalty,
|
|
1238
1229
|
presence_penalty: presencePenalty,
|
|
1239
|
-
response_format:
|
|
1230
|
+
response_format: responseFormat?.type === "json" ? normalizedResponseFormatSchema != null ? {
|
|
1240
1231
|
type: "json_schema",
|
|
1241
1232
|
json_schema: {
|
|
1242
1233
|
schema: normalizedResponseFormatSchema.schema,
|
|
1243
1234
|
strict: strictJsonSchema,
|
|
1244
|
-
name:
|
|
1235
|
+
name: responseFormat.name ?? "response",
|
|
1245
1236
|
description: responseFormat.description
|
|
1246
1237
|
}
|
|
1247
1238
|
} : { type: "json_object" } : void 0,
|
|
@@ -1377,7 +1368,6 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1377
1368
|
};
|
|
1378
1369
|
}
|
|
1379
1370
|
async doGenerate(options) {
|
|
1380
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
1381
1371
|
const { args: body, warnings } = await this.getArgs(options);
|
|
1382
1372
|
const {
|
|
1383
1373
|
responseHeaders,
|
|
@@ -1388,7 +1378,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1388
1378
|
path: "/chat/completions",
|
|
1389
1379
|
modelId: this.modelId
|
|
1390
1380
|
}),
|
|
1391
|
-
headers: combineHeaders(
|
|
1381
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
1392
1382
|
body,
|
|
1393
1383
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1394
1384
|
successfulResponseHandler: createJsonResponseHandler(
|
|
@@ -1405,11 +1395,11 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1405
1395
|
});
|
|
1406
1396
|
}
|
|
1407
1397
|
const content = [];
|
|
1408
|
-
const text = choice.message.content != null && choice.message.content.length > 0 ? choice.message.content :
|
|
1398
|
+
const text = choice.message.content != null && choice.message.content.length > 0 ? choice.message.content : choice.message.audio?.transcript;
|
|
1409
1399
|
if (text != null && text.length > 0) {
|
|
1410
1400
|
content.push({ type: "text", text });
|
|
1411
1401
|
}
|
|
1412
|
-
for (const toolCall of
|
|
1402
|
+
for (const toolCall of choice.message.tool_calls ?? []) {
|
|
1413
1403
|
content.push({
|
|
1414
1404
|
type: "tool-call",
|
|
1415
1405
|
toolCallId: toolCall.id || generateId(),
|
|
@@ -1417,7 +1407,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1417
1407
|
input: toolCall.function.arguments
|
|
1418
1408
|
});
|
|
1419
1409
|
}
|
|
1420
|
-
for (const annotation of
|
|
1410
|
+
for (const annotation of choice.message.annotations ?? []) {
|
|
1421
1411
|
content.push({
|
|
1422
1412
|
type: "source",
|
|
1423
1413
|
sourceType: "url",
|
|
@@ -1426,22 +1416,22 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1426
1416
|
title: annotation.url_citation.title
|
|
1427
1417
|
});
|
|
1428
1418
|
}
|
|
1429
|
-
const completionTokenDetails =
|
|
1419
|
+
const completionTokenDetails = response.usage?.completion_tokens_details;
|
|
1430
1420
|
const providerMetadata = { openai: {} };
|
|
1431
|
-
if (
|
|
1432
|
-
providerMetadata.openai.acceptedPredictionTokens = completionTokenDetails
|
|
1421
|
+
if (completionTokenDetails?.accepted_prediction_tokens != null) {
|
|
1422
|
+
providerMetadata.openai.acceptedPredictionTokens = completionTokenDetails?.accepted_prediction_tokens;
|
|
1433
1423
|
}
|
|
1434
|
-
if (
|
|
1435
|
-
providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails
|
|
1424
|
+
if (completionTokenDetails?.rejected_prediction_tokens != null) {
|
|
1425
|
+
providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails?.rejected_prediction_tokens;
|
|
1436
1426
|
}
|
|
1437
|
-
if (
|
|
1427
|
+
if (choice.logprobs?.content != null) {
|
|
1438
1428
|
providerMetadata.openai.logprobs = choice.logprobs.content;
|
|
1439
1429
|
}
|
|
1440
1430
|
return {
|
|
1441
1431
|
content,
|
|
1442
1432
|
finishReason: {
|
|
1443
1433
|
unified: mapOpenAIFinishReason(choice.finish_reason),
|
|
1444
|
-
raw:
|
|
1434
|
+
raw: choice.finish_reason ?? void 0
|
|
1445
1435
|
},
|
|
1446
1436
|
usage: convertOpenAIChatUsage(response.usage),
|
|
1447
1437
|
request: { body },
|
|
@@ -1455,7 +1445,6 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1455
1445
|
};
|
|
1456
1446
|
}
|
|
1457
1447
|
async doStream(options) {
|
|
1458
|
-
var _a2, _b;
|
|
1459
1448
|
const { args, warnings } = await this.getArgs(options);
|
|
1460
1449
|
const body = {
|
|
1461
1450
|
...args,
|
|
@@ -1470,7 +1459,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1470
1459
|
});
|
|
1471
1460
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
1472
1461
|
url,
|
|
1473
|
-
headers: combineHeaders(
|
|
1462
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
1474
1463
|
body,
|
|
1475
1464
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1476
1465
|
successfulResponseHandler: createEventSourceResponseHandler(
|
|
@@ -1507,7 +1496,6 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1507
1496
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1508
1497
|
},
|
|
1509
1498
|
transform(chunk, controller) {
|
|
1510
|
-
var _a3, _b2, _c, _d, _e, _f;
|
|
1511
1499
|
if (options.includeRawChunks) {
|
|
1512
1500
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1513
1501
|
}
|
|
@@ -1521,7 +1509,7 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1521
1509
|
finishReason = { unified: "error", raw: void 0 };
|
|
1522
1510
|
controller.enqueue({
|
|
1523
1511
|
type: "error",
|
|
1524
|
-
error:
|
|
1512
|
+
error: createOpenAIProviderStreamError(value.error) ?? value.error
|
|
1525
1513
|
});
|
|
1526
1514
|
return;
|
|
1527
1515
|
}
|
|
@@ -1537,24 +1525,24 @@ var OpenAIChatLanguageModel = class _OpenAIChatLanguageModel {
|
|
|
1537
1525
|
}
|
|
1538
1526
|
if (value.usage != null) {
|
|
1539
1527
|
usage = value.usage;
|
|
1540
|
-
if (
|
|
1541
|
-
providerMetadata.openai.acceptedPredictionTokens =
|
|
1528
|
+
if (value.usage.completion_tokens_details?.accepted_prediction_tokens != null) {
|
|
1529
|
+
providerMetadata.openai.acceptedPredictionTokens = value.usage.completion_tokens_details?.accepted_prediction_tokens;
|
|
1542
1530
|
}
|
|
1543
|
-
if (
|
|
1544
|
-
providerMetadata.openai.rejectedPredictionTokens =
|
|
1531
|
+
if (value.usage.completion_tokens_details?.rejected_prediction_tokens != null) {
|
|
1532
|
+
providerMetadata.openai.rejectedPredictionTokens = value.usage.completion_tokens_details?.rejected_prediction_tokens;
|
|
1545
1533
|
}
|
|
1546
1534
|
}
|
|
1547
1535
|
const choice = value.choices[0];
|
|
1548
|
-
if (
|
|
1536
|
+
if (choice?.finish_reason != null) {
|
|
1549
1537
|
finishReason = {
|
|
1550
1538
|
unified: mapOpenAIFinishReason(choice.finish_reason),
|
|
1551
1539
|
raw: choice.finish_reason
|
|
1552
1540
|
};
|
|
1553
1541
|
}
|
|
1554
|
-
if (
|
|
1542
|
+
if (choice?.logprobs?.content != null) {
|
|
1555
1543
|
providerMetadata.openai.logprobs = choice.logprobs.content;
|
|
1556
1544
|
}
|
|
1557
|
-
if (
|
|
1545
|
+
if (choice?.delta == null) {
|
|
1558
1546
|
return;
|
|
1559
1547
|
}
|
|
1560
1548
|
const delta = choice.delta;
|
|
@@ -1612,7 +1600,7 @@ function isOpenAIChatOutputChunk(chunk) {
|
|
|
1612
1600
|
}
|
|
1613
1601
|
return chunk.choices.some((choice) => {
|
|
1614
1602
|
const delta = choice.delta;
|
|
1615
|
-
return
|
|
1603
|
+
return delta?.content != null && delta.content.length > 0 || delta?.tool_calls != null && delta.tool_calls.length > 0 || delta?.annotations != null && delta.annotations.length > 0;
|
|
1616
1604
|
});
|
|
1617
1605
|
}
|
|
1618
1606
|
|
|
@@ -1631,21 +1619,20 @@ import {
|
|
|
1631
1619
|
// src/completion/convert-openai-completion-usage.ts
|
|
1632
1620
|
import { createNullLanguageModelUsage as createNullLanguageModelUsage2 } from "@ai-sdk/provider-utils";
|
|
1633
1621
|
function convertOpenAICompletionUsage(usage) {
|
|
1634
|
-
var _a2, _b, _c, _d;
|
|
1635
1622
|
if (usage == null) {
|
|
1636
1623
|
return createNullLanguageModelUsage2();
|
|
1637
1624
|
}
|
|
1638
|
-
const promptTokens =
|
|
1639
|
-
const completionTokens =
|
|
1625
|
+
const promptTokens = usage.prompt_tokens ?? 0;
|
|
1626
|
+
const completionTokens = usage.completion_tokens ?? 0;
|
|
1640
1627
|
return {
|
|
1641
1628
|
inputTokens: {
|
|
1642
|
-
total:
|
|
1629
|
+
total: usage.prompt_tokens ?? void 0,
|
|
1643
1630
|
noCache: promptTokens,
|
|
1644
1631
|
cacheRead: void 0,
|
|
1645
1632
|
cacheWrite: void 0
|
|
1646
1633
|
},
|
|
1647
1634
|
outputTokens: {
|
|
1648
|
-
total:
|
|
1635
|
+
total: usage.completion_tokens ?? void 0,
|
|
1649
1636
|
text: completionTokens,
|
|
1650
1637
|
reasoning: void 0
|
|
1651
1638
|
},
|
|
@@ -1919,7 +1906,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1919
1906
|
if (topK != null) {
|
|
1920
1907
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
1921
1908
|
}
|
|
1922
|
-
if (tools
|
|
1909
|
+
if (tools?.length) {
|
|
1923
1910
|
warnings.push({ type: "unsupported", feature: "tools" });
|
|
1924
1911
|
}
|
|
1925
1912
|
if (toolChoice != null) {
|
|
@@ -1933,7 +1920,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1933
1920
|
});
|
|
1934
1921
|
}
|
|
1935
1922
|
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt });
|
|
1936
|
-
const stop = [...stopSequences
|
|
1923
|
+
const stop = [...stopSequences ?? [], ...userStopSequences ?? []];
|
|
1937
1924
|
return {
|
|
1938
1925
|
args: {
|
|
1939
1926
|
// model id:
|
|
@@ -1941,7 +1928,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1941
1928
|
// model specific settings:
|
|
1942
1929
|
echo: openaiOptions.echo,
|
|
1943
1930
|
logit_bias: openaiOptions.logitBias,
|
|
1944
|
-
logprobs:
|
|
1931
|
+
logprobs: openaiOptions?.logprobs === true ? 0 : openaiOptions?.logprobs === false ? void 0 : openaiOptions?.logprobs,
|
|
1945
1932
|
suffix: openaiOptions.suffix,
|
|
1946
1933
|
user: openaiOptions.user,
|
|
1947
1934
|
// standardized settings:
|
|
@@ -1960,7 +1947,6 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1960
1947
|
};
|
|
1961
1948
|
}
|
|
1962
1949
|
async doGenerate(options) {
|
|
1963
|
-
var _a2, _b, _c;
|
|
1964
1950
|
const { args, warnings } = await this.getArgs(options);
|
|
1965
1951
|
const {
|
|
1966
1952
|
responseHeaders,
|
|
@@ -1971,7 +1957,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1971
1957
|
path: "/completions",
|
|
1972
1958
|
modelId: this.modelId
|
|
1973
1959
|
}),
|
|
1974
|
-
headers: combineHeaders2(
|
|
1960
|
+
headers: combineHeaders2(this.config.headers?.(), options.headers),
|
|
1975
1961
|
body: args,
|
|
1976
1962
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1977
1963
|
successfulResponseHandler: createJsonResponseHandler2(
|
|
@@ -1990,7 +1976,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
1990
1976
|
usage: convertOpenAICompletionUsage(response.usage),
|
|
1991
1977
|
finishReason: {
|
|
1992
1978
|
unified: mapOpenAIFinishReason2(choice.finish_reason),
|
|
1993
|
-
raw:
|
|
1979
|
+
raw: choice.finish_reason ?? void 0
|
|
1994
1980
|
},
|
|
1995
1981
|
request: { body: args },
|
|
1996
1982
|
response: {
|
|
@@ -2003,7 +1989,6 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
2003
1989
|
};
|
|
2004
1990
|
}
|
|
2005
1991
|
async doStream(options) {
|
|
2006
|
-
var _a2, _b;
|
|
2007
1992
|
const { args, warnings } = await this.getArgs(options);
|
|
2008
1993
|
const body = {
|
|
2009
1994
|
...args,
|
|
@@ -2018,7 +2003,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
2018
2003
|
});
|
|
2019
2004
|
const { responseHeaders, value: response } = await postJsonToApi2({
|
|
2020
2005
|
url,
|
|
2021
|
-
headers: combineHeaders2(
|
|
2006
|
+
headers: combineHeaders2(this.config.headers?.(), options.headers),
|
|
2022
2007
|
body,
|
|
2023
2008
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2024
2009
|
successfulResponseHandler: createEventSourceResponseHandler2(
|
|
@@ -2049,7 +2034,6 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
2049
2034
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2050
2035
|
},
|
|
2051
2036
|
transform(chunk, controller) {
|
|
2052
|
-
var _a3;
|
|
2053
2037
|
if (options.includeRawChunks) {
|
|
2054
2038
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2055
2039
|
}
|
|
@@ -2063,7 +2047,7 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
2063
2047
|
finishReason = { unified: "error", raw: void 0 };
|
|
2064
2048
|
controller.enqueue({
|
|
2065
2049
|
type: "error",
|
|
2066
|
-
error:
|
|
2050
|
+
error: createOpenAIProviderStreamError(value.error) ?? value.error
|
|
2067
2051
|
});
|
|
2068
2052
|
return;
|
|
2069
2053
|
}
|
|
@@ -2079,16 +2063,16 @@ var OpenAICompletionLanguageModel = class _OpenAICompletionLanguageModel {
|
|
|
2079
2063
|
usage = value.usage;
|
|
2080
2064
|
}
|
|
2081
2065
|
const choice = value.choices[0];
|
|
2082
|
-
if (
|
|
2066
|
+
if (choice?.finish_reason != null) {
|
|
2083
2067
|
finishReason = {
|
|
2084
2068
|
unified: mapOpenAIFinishReason2(choice.finish_reason),
|
|
2085
2069
|
raw: choice.finish_reason
|
|
2086
2070
|
};
|
|
2087
2071
|
}
|
|
2088
|
-
if (
|
|
2072
|
+
if (choice?.logprobs != null) {
|
|
2089
2073
|
providerMetadata.openai.logprobs = choice.logprobs;
|
|
2090
2074
|
}
|
|
2091
|
-
if (
|
|
2075
|
+
if (choice?.text != null && choice.text.length > 0) {
|
|
2092
2076
|
controller.enqueue({
|
|
2093
2077
|
type: "text-delta",
|
|
2094
2078
|
id: "0",
|
|
@@ -2198,7 +2182,6 @@ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
|
|
|
2198
2182
|
abortSignal,
|
|
2199
2183
|
providerOptions
|
|
2200
2184
|
}) {
|
|
2201
|
-
var _a2, _b, _c;
|
|
2202
2185
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
2203
2186
|
throw new TooManyEmbeddingValuesForCallError({
|
|
2204
2187
|
provider: this.provider,
|
|
@@ -2207,11 +2190,11 @@ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
|
|
|
2207
2190
|
values
|
|
2208
2191
|
});
|
|
2209
2192
|
}
|
|
2210
|
-
const openaiOptions =
|
|
2193
|
+
const openaiOptions = await parseProviderOptions3({
|
|
2211
2194
|
provider: "openai",
|
|
2212
2195
|
providerOptions,
|
|
2213
2196
|
schema: openaiEmbeddingModelOptions
|
|
2214
|
-
})
|
|
2197
|
+
}) ?? {};
|
|
2215
2198
|
const {
|
|
2216
2199
|
responseHeaders,
|
|
2217
2200
|
value: response,
|
|
@@ -2221,7 +2204,7 @@ var OpenAIEmbeddingModel = class _OpenAIEmbeddingModel {
|
|
|
2221
2204
|
path: "/embeddings",
|
|
2222
2205
|
modelId: this.modelId
|
|
2223
2206
|
}),
|
|
2224
|
-
headers: combineHeaders3(
|
|
2207
|
+
headers: combineHeaders3(this.config.headers?.(), headers),
|
|
2225
2208
|
body: {
|
|
2226
2209
|
model: this.modelId,
|
|
2227
2210
|
input: values,
|
|
@@ -2342,7 +2325,6 @@ var OpenAIFiles = class {
|
|
|
2342
2325
|
headers,
|
|
2343
2326
|
providerOptions
|
|
2344
2327
|
}) {
|
|
2345
|
-
var _a2, _b, _c;
|
|
2346
2328
|
let openaiOptions;
|
|
2347
2329
|
try {
|
|
2348
2330
|
openaiOptions = await parseProviderOptions4({
|
|
@@ -2357,7 +2339,7 @@ var OpenAIFiles = class {
|
|
|
2357
2339
|
}
|
|
2358
2340
|
throw error;
|
|
2359
2341
|
}
|
|
2360
|
-
const purpose =
|
|
2342
|
+
const purpose = openaiOptions?.purpose ?? "assistants";
|
|
2361
2343
|
const requestHeaders = this.getHeaders(headers);
|
|
2362
2344
|
const url = `${this.config.baseURL}/files`;
|
|
2363
2345
|
let response;
|
|
@@ -2365,7 +2347,7 @@ var OpenAIFiles = class {
|
|
|
2365
2347
|
const parts = [
|
|
2366
2348
|
{ type: "field", name: "purpose", value: purpose }
|
|
2367
2349
|
];
|
|
2368
|
-
if (
|
|
2350
|
+
if (openaiOptions?.expiresAfter != null) {
|
|
2369
2351
|
parts.push(
|
|
2370
2352
|
{ type: "field", name: "expires_after[anchor]", value: "created_at" },
|
|
2371
2353
|
{
|
|
@@ -2405,7 +2387,7 @@ var OpenAIFiles = class {
|
|
|
2405
2387
|
formData.append("file", blob);
|
|
2406
2388
|
}
|
|
2407
2389
|
formData.append("purpose", purpose);
|
|
2408
|
-
if (
|
|
2390
|
+
if (openaiOptions?.expiresAfter != null) {
|
|
2409
2391
|
formData.append("expires_after[anchor]", "created_at");
|
|
2410
2392
|
formData.append(
|
|
2411
2393
|
"expires_after[seconds]",
|
|
@@ -2427,7 +2409,7 @@ var OpenAIFiles = class {
|
|
|
2427
2409
|
return {
|
|
2428
2410
|
warnings: [],
|
|
2429
2411
|
providerReference: { openai: response.id },
|
|
2430
|
-
...
|
|
2412
|
+
...response.filename ?? filename ? { filename: response.filename ?? filename } : {},
|
|
2431
2413
|
...mediaType != null ? { mediaType } : {},
|
|
2432
2414
|
...response.bytes != null ? { byteSize: response.bytes } : {},
|
|
2433
2415
|
...response.created_at != null ? { createdAt: new Date(response.created_at * 1e3) } : {},
|
|
@@ -2471,7 +2453,6 @@ var OpenAIFiles = class {
|
|
|
2471
2453
|
abortSignal,
|
|
2472
2454
|
headers
|
|
2473
2455
|
}) {
|
|
2474
|
-
var _a2;
|
|
2475
2456
|
const fileId = this.getFileId(file);
|
|
2476
2457
|
const { value: content, responseHeaders } = await getFromApi({
|
|
2477
2458
|
url: `${this.config.baseURL}/files/${encodePathSegment(fileId)}/content`,
|
|
@@ -2482,7 +2463,7 @@ var OpenAIFiles = class {
|
|
|
2482
2463
|
fetch: this.config.fetch,
|
|
2483
2464
|
validateUrl: false
|
|
2484
2465
|
});
|
|
2485
|
-
const mediaType =
|
|
2466
|
+
const mediaType = responseHeaders?.["content-type"]?.split(";")[0].trim();
|
|
2486
2467
|
return {
|
|
2487
2468
|
warnings: [],
|
|
2488
2469
|
content,
|
|
@@ -2594,8 +2575,7 @@ function hasDefaultResponseFormat(modelId) {
|
|
|
2594
2575
|
);
|
|
2595
2576
|
}
|
|
2596
2577
|
function getMaxImagesPerCall(modelId) {
|
|
2597
|
-
|
|
2598
|
-
return (_a2 = modelMaxImagesPerCall[modelId]) != null ? _a2 : modelId.startsWith("gpt-image-") ? 10 : 1;
|
|
2578
|
+
return modelMaxImagesPerCall[modelId] ?? (modelId.startsWith("gpt-image-") ? 10 : 1);
|
|
2599
2579
|
}
|
|
2600
2580
|
var baseImageModelOptionsObject = z11.object({
|
|
2601
2581
|
/**
|
|
@@ -2692,7 +2672,6 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2692
2672
|
headers,
|
|
2693
2673
|
abortSignal
|
|
2694
2674
|
}) {
|
|
2695
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
2696
2675
|
const warnings = [];
|
|
2697
2676
|
if (aspectRatio != null) {
|
|
2698
2677
|
warnings.push({
|
|
@@ -2704,19 +2683,19 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2704
2683
|
if (seed != null) {
|
|
2705
2684
|
warnings.push({ type: "unsupported", feature: "seed" });
|
|
2706
2685
|
}
|
|
2707
|
-
const currentDate =
|
|
2686
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
2708
2687
|
if (files != null) {
|
|
2709
|
-
const openaiOptions2 =
|
|
2688
|
+
const openaiOptions2 = await parseProviderOptions5({
|
|
2710
2689
|
provider: "openai",
|
|
2711
2690
|
providerOptions,
|
|
2712
2691
|
schema: openaiImageModelEditOptions
|
|
2713
|
-
})
|
|
2692
|
+
}) ?? {};
|
|
2714
2693
|
const { value: response2, responseHeaders: responseHeaders2 } = await postFormDataToApi2({
|
|
2715
2694
|
url: this.config.url({
|
|
2716
2695
|
path: "/images/edits",
|
|
2717
2696
|
modelId: this.modelId
|
|
2718
2697
|
}),
|
|
2719
|
-
headers: combineHeaders5(
|
|
2698
|
+
headers: combineHeaders5(this.config.headers?.(), headers),
|
|
2720
2699
|
formData: convertToFormData({
|
|
2721
2700
|
model: this.modelId,
|
|
2722
2701
|
prompt,
|
|
@@ -2755,9 +2734,9 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2755
2734
|
images: response2.data.map((item) => item.b64_json),
|
|
2756
2735
|
warnings,
|
|
2757
2736
|
usage: response2.usage != null ? {
|
|
2758
|
-
inputTokens:
|
|
2759
|
-
outputTokens:
|
|
2760
|
-
totalTokens:
|
|
2737
|
+
inputTokens: response2.usage.input_tokens ?? void 0,
|
|
2738
|
+
outputTokens: response2.usage.output_tokens ?? void 0,
|
|
2739
|
+
totalTokens: response2.usage.total_tokens ?? void 0
|
|
2761
2740
|
} : void 0,
|
|
2762
2741
|
response: {
|
|
2763
2742
|
timestamp: currentDate,
|
|
@@ -2766,37 +2745,34 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2766
2745
|
},
|
|
2767
2746
|
providerMetadata: {
|
|
2768
2747
|
openai: {
|
|
2769
|
-
images: response2.data.map((item, index) => {
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
)
|
|
2783
|
-
};
|
|
2784
|
-
})
|
|
2748
|
+
images: response2.data.map((item, index) => ({
|
|
2749
|
+
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
|
|
2750
|
+
created: response2.created ?? void 0,
|
|
2751
|
+
size: response2.size ?? void 0,
|
|
2752
|
+
quality: response2.quality ?? void 0,
|
|
2753
|
+
background: response2.background ?? void 0,
|
|
2754
|
+
outputFormat: response2.output_format ?? void 0,
|
|
2755
|
+
...distributeTokenDetails(
|
|
2756
|
+
response2.usage?.input_tokens_details,
|
|
2757
|
+
index,
|
|
2758
|
+
response2.data.length
|
|
2759
|
+
)
|
|
2760
|
+
}))
|
|
2785
2761
|
}
|
|
2786
2762
|
}
|
|
2787
2763
|
};
|
|
2788
2764
|
}
|
|
2789
|
-
const openaiOptions =
|
|
2765
|
+
const openaiOptions = await parseProviderOptions5({
|
|
2790
2766
|
provider: "openai",
|
|
2791
2767
|
providerOptions,
|
|
2792
2768
|
schema: openaiImageModelGenerationOptions
|
|
2793
|
-
})
|
|
2769
|
+
}) ?? {};
|
|
2794
2770
|
const { value: response, responseHeaders } = await postJsonToApi4({
|
|
2795
2771
|
url: this.config.url({
|
|
2796
2772
|
path: "/images/generations",
|
|
2797
2773
|
modelId: this.modelId
|
|
2798
2774
|
}),
|
|
2799
|
-
headers: combineHeaders5(
|
|
2775
|
+
headers: combineHeaders5(this.config.headers?.(), headers),
|
|
2800
2776
|
body: {
|
|
2801
2777
|
model: this.modelId,
|
|
2802
2778
|
prompt,
|
|
@@ -2822,9 +2798,9 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2822
2798
|
images: response.data.map((item) => item.b64_json),
|
|
2823
2799
|
warnings,
|
|
2824
2800
|
usage: response.usage != null ? {
|
|
2825
|
-
inputTokens:
|
|
2826
|
-
outputTokens:
|
|
2827
|
-
totalTokens:
|
|
2801
|
+
inputTokens: response.usage.input_tokens ?? void 0,
|
|
2802
|
+
outputTokens: response.usage.output_tokens ?? void 0,
|
|
2803
|
+
totalTokens: response.usage.total_tokens ?? void 0
|
|
2828
2804
|
} : void 0,
|
|
2829
2805
|
response: {
|
|
2830
2806
|
timestamp: currentDate,
|
|
@@ -2833,22 +2809,19 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2833
2809
|
},
|
|
2834
2810
|
providerMetadata: {
|
|
2835
2811
|
openai: {
|
|
2836
|
-
images: response.data.map((item, index) => {
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
)
|
|
2850
|
-
};
|
|
2851
|
-
})
|
|
2812
|
+
images: response.data.map((item, index) => ({
|
|
2813
|
+
...item.revised_prompt ? { revisedPrompt: item.revised_prompt } : {},
|
|
2814
|
+
created: response.created ?? void 0,
|
|
2815
|
+
size: response.size ?? void 0,
|
|
2816
|
+
quality: response.quality ?? void 0,
|
|
2817
|
+
background: response.background ?? void 0,
|
|
2818
|
+
outputFormat: response.output_format ?? void 0,
|
|
2819
|
+
...distributeTokenDetails(
|
|
2820
|
+
response.usage?.input_tokens_details,
|
|
2821
|
+
index,
|
|
2822
|
+
response.data.length
|
|
2823
|
+
)
|
|
2824
|
+
}))
|
|
2852
2825
|
}
|
|
2853
2826
|
}
|
|
2854
2827
|
};
|
|
@@ -3581,15 +3554,14 @@ var programmaticToolCallingFactory = createProviderExecutedToolFactory7({
|
|
|
3581
3554
|
var programmaticToolCalling = () => experimental_toolCaller(programmaticToolCallingFactory({}), {
|
|
3582
3555
|
type: "provider",
|
|
3583
3556
|
prepareProviderOptions: (providerOptions) => {
|
|
3584
|
-
|
|
3585
|
-
const openaiOptions = providerOptions == null ? void 0 : providerOptions.openai;
|
|
3557
|
+
const openaiOptions = providerOptions?.openai;
|
|
3586
3558
|
return {
|
|
3587
3559
|
...providerOptions,
|
|
3588
3560
|
openai: {
|
|
3589
3561
|
...openaiOptions,
|
|
3590
3562
|
allowedCallers: [
|
|
3591
3563
|
.../* @__PURE__ */ new Set([
|
|
3592
|
-
...
|
|
3564
|
+
...openaiOptions?.allowedCallers ?? [],
|
|
3593
3565
|
"programmatic"
|
|
3594
3566
|
])
|
|
3595
3567
|
]
|
|
@@ -3755,19 +3727,18 @@ import { z as z28 } from "zod/v4";
|
|
|
3755
3727
|
// src/responses/convert-openai-responses-usage.ts
|
|
3756
3728
|
import { createNullLanguageModelUsage as createNullLanguageModelUsage3 } from "@ai-sdk/provider-utils";
|
|
3757
3729
|
function convertOpenAIResponsesUsage(usage) {
|
|
3758
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
3759
3730
|
if (usage == null) {
|
|
3760
3731
|
return createNullLanguageModelUsage3();
|
|
3761
3732
|
}
|
|
3762
3733
|
const inputTokens = usage.input_tokens;
|
|
3763
3734
|
const outputTokens = usage.output_tokens;
|
|
3764
|
-
const cachedTokens =
|
|
3765
|
-
const cacheWriteTokens =
|
|
3766
|
-
const reasoningTokens =
|
|
3735
|
+
const cachedTokens = usage.input_tokens_details?.cached_tokens ?? 0;
|
|
3736
|
+
const cacheWriteTokens = usage.input_tokens_details?.cache_write_tokens ?? void 0;
|
|
3737
|
+
const reasoningTokens = usage.output_tokens_details?.reasoning_tokens ?? 0;
|
|
3767
3738
|
return {
|
|
3768
3739
|
inputTokens: {
|
|
3769
3740
|
total: inputTokens,
|
|
3770
|
-
noCache: inputTokens - cachedTokens - (cacheWriteTokens
|
|
3741
|
+
noCache: inputTokens - cachedTokens - (cacheWriteTokens ?? 0),
|
|
3771
3742
|
cacheRead: cachedTokens,
|
|
3772
3743
|
cacheWrite: cacheWriteTokens
|
|
3773
3744
|
},
|
|
@@ -5244,8 +5215,7 @@ function getParallelToolCallMetadata({
|
|
|
5244
5215
|
providerOptions,
|
|
5245
5216
|
providerOptionsName
|
|
5246
5217
|
}) {
|
|
5247
|
-
|
|
5248
|
-
const metadata = (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.parallelToolCall;
|
|
5218
|
+
const metadata = providerOptions?.[providerOptionsName]?.parallelToolCall;
|
|
5249
5219
|
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) {
|
|
5250
5220
|
return void 0;
|
|
5251
5221
|
}
|
|
@@ -5326,8 +5296,7 @@ async function convertFunctionToolResultOutput({
|
|
|
5326
5296
|
providerOptionsName,
|
|
5327
5297
|
warnings
|
|
5328
5298
|
}) {
|
|
5329
|
-
|
|
5330
|
-
const hasOutputSchema = outputSchemaToolNames == null ? void 0 : outputSchemaToolNames.has(toolName);
|
|
5299
|
+
const hasOutputSchema = outputSchemaToolNames?.has(toolName);
|
|
5331
5300
|
const convertScalarOutput = (value) => promptCacheBreakpoint == null ? value : [
|
|
5332
5301
|
{
|
|
5333
5302
|
type: "input_text",
|
|
@@ -5342,7 +5311,7 @@ async function convertFunctionToolResultOutput({
|
|
|
5342
5311
|
hasOutputSchema ? JSON.stringify(output.value) : output.value
|
|
5343
5312
|
);
|
|
5344
5313
|
case "execution-denied": {
|
|
5345
|
-
const reason =
|
|
5314
|
+
const reason = output.reason ?? "Tool call execution denied.";
|
|
5346
5315
|
return convertScalarOutput(
|
|
5347
5316
|
hasOutputSchema ? JSON.stringify(reason) : reason
|
|
5348
5317
|
);
|
|
@@ -5352,7 +5321,6 @@ async function convertFunctionToolResultOutput({
|
|
|
5352
5321
|
return convertScalarOutput(JSON.stringify(output.value));
|
|
5353
5322
|
case "content":
|
|
5354
5323
|
return output.value.map((item) => {
|
|
5355
|
-
var _a3, _b, _c;
|
|
5356
5324
|
const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
|
|
5357
5325
|
item.providerOptions,
|
|
5358
5326
|
providerOptionsName
|
|
@@ -5369,7 +5337,7 @@ async function convertFunctionToolResultOutput({
|
|
|
5369
5337
|
}
|
|
5370
5338
|
case "file": {
|
|
5371
5339
|
const topLevel = getTopLevelMediaType2(item.mediaType);
|
|
5372
|
-
const imageDetail =
|
|
5340
|
+
const imageDetail = item.providerOptions?.[providerOptionsName]?.imageDetail;
|
|
5373
5341
|
if (item.data.type === "reference") {
|
|
5374
5342
|
const fileId = resolveProviderReference2({
|
|
5375
5343
|
reference: item.data.reference,
|
|
@@ -5407,7 +5375,7 @@ async function convertFunctionToolResultOutput({
|
|
|
5407
5375
|
}
|
|
5408
5376
|
return {
|
|
5409
5377
|
type: "input_file",
|
|
5410
|
-
filename:
|
|
5378
|
+
filename: item.filename ?? "data",
|
|
5411
5379
|
file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
|
|
5412
5380
|
...promptCacheBreakpoint2 != null && {
|
|
5413
5381
|
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
@@ -5508,16 +5476,14 @@ function collectCompleteParallelToolResultGroups({
|
|
|
5508
5476
|
return completeGroups;
|
|
5509
5477
|
}
|
|
5510
5478
|
function getPromptCacheBreakpoint2(providerOptions, providerOptionsName) {
|
|
5511
|
-
|
|
5512
|
-
return (_a2 = providerOptions == null ? void 0 : providerOptions[providerOptionsName]) == null ? void 0 : _a2.promptCacheBreakpoint;
|
|
5479
|
+
return providerOptions?.[providerOptionsName]?.promptCacheBreakpoint;
|
|
5513
5480
|
}
|
|
5514
5481
|
function getScalarToolResultPromptCacheBreakpoint({
|
|
5515
5482
|
output,
|
|
5516
5483
|
toolResultProviderOptions,
|
|
5517
5484
|
providerOptionsName
|
|
5518
5485
|
}) {
|
|
5519
|
-
|
|
5520
|
-
return output.type === "content" ? void 0 : (_a2 = getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName)) != null ? _a2 : getPromptCacheBreakpoint2(
|
|
5486
|
+
return output.type === "content" ? void 0 : getPromptCacheBreakpoint2(output.providerOptions, providerOptionsName) ?? getPromptCacheBreakpoint2(
|
|
5521
5487
|
toolResultProviderOptions,
|
|
5522
5488
|
providerOptionsName
|
|
5523
5489
|
);
|
|
@@ -5546,7 +5512,6 @@ async function convertToOpenAIResponsesInput({
|
|
|
5546
5512
|
outputSchemaToolNames,
|
|
5547
5513
|
configurationUpdateUnsupportedReason
|
|
5548
5514
|
}) {
|
|
5549
|
-
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, _L, _M, _N, _O, _P;
|
|
5550
5515
|
let input = [];
|
|
5551
5516
|
const warnings = [];
|
|
5552
5517
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
@@ -5572,7 +5537,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
5572
5537
|
schema: openaiResponsesSystemMessageOptionsSchema
|
|
5573
5538
|
});
|
|
5574
5539
|
}
|
|
5575
|
-
const effort = options
|
|
5540
|
+
const effort = options?.reasoningEffortUpdate;
|
|
5576
5541
|
if (effort != null) {
|
|
5577
5542
|
const unsupportedReason = content !== "" ? "Message-level reasoningEffortUpdate requires empty system message content." : configurationUpdateUnsupportedReason;
|
|
5578
5543
|
if (unsupportedReason != null) {
|
|
@@ -5645,7 +5610,6 @@ async function convertToOpenAIResponsesInput({
|
|
|
5645
5610
|
...explicitMessageItemType && { type: "message" },
|
|
5646
5611
|
role: "user",
|
|
5647
5612
|
content: content.map((part, index) => {
|
|
5648
|
-
var _a3, _b2, _c2, _d2, _e2;
|
|
5649
5613
|
switch (part.type) {
|
|
5650
5614
|
case "text": {
|
|
5651
5615
|
const promptCacheBreakpoint = getPromptCacheBreakpoint2(
|
|
@@ -5675,7 +5639,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
5675
5639
|
return {
|
|
5676
5640
|
type: "input_image",
|
|
5677
5641
|
file_id: fileId,
|
|
5678
|
-
detail:
|
|
5642
|
+
detail: part.providerOptions?.[providerOptionsName]?.imageDetail,
|
|
5679
5643
|
...promptCacheBreakpoint != null && {
|
|
5680
5644
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
5681
5645
|
}
|
|
@@ -5703,7 +5667,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
5703
5667
|
...part.data.type === "url" ? { image_url: part.data.url.toString() } : typeof part.data.data === "string" && isFileId(part.data.data, fileIdPrefixes) ? { file_id: part.data.data } : {
|
|
5704
5668
|
image_url: `data:${resolveFullMediaType2({ part })};base64,${convertToBase642(part.data.data)}`
|
|
5705
5669
|
},
|
|
5706
|
-
detail:
|
|
5670
|
+
detail: part.providerOptions?.[providerOptionsName]?.imageDetail,
|
|
5707
5671
|
...promptCacheBreakpoint != null && {
|
|
5708
5672
|
prompt_cache_breakpoint: promptCacheBreakpoint
|
|
5709
5673
|
}
|
|
@@ -5727,7 +5691,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
5727
5691
|
return {
|
|
5728
5692
|
type: "input_file",
|
|
5729
5693
|
...typeof part.data.data === "string" && isFileId(part.data.data, fileIdPrefixes) ? { file_id: part.data.data } : {
|
|
5730
|
-
filename:
|
|
5694
|
+
filename: part.filename ?? (fullMediaType === "application/pdf" ? `part-${index}.pdf` : `part-${index}`),
|
|
5731
5695
|
file_data: `data:${fullMediaType};base64,${convertToBase642(part.data.data)}`
|
|
5732
5696
|
},
|
|
5733
5697
|
...promptCacheBreakpoint != null && {
|
|
@@ -5748,9 +5712,9 @@ async function convertToOpenAIResponsesInput({
|
|
|
5748
5712
|
for (const part of content) {
|
|
5749
5713
|
switch (part.type) {
|
|
5750
5714
|
case "text": {
|
|
5751
|
-
const providerOptions2 =
|
|
5752
|
-
const id = providerOptions2
|
|
5753
|
-
const phase = providerOptions2
|
|
5715
|
+
const providerOptions2 = part.providerOptions?.[providerOptionsName];
|
|
5716
|
+
const id = providerOptions2?.itemId;
|
|
5717
|
+
const phase = providerOptions2?.phase;
|
|
5754
5718
|
if (hasConversation && id != null) {
|
|
5755
5719
|
break;
|
|
5756
5720
|
}
|
|
@@ -5795,11 +5759,11 @@ async function convertToOpenAIResponsesInput({
|
|
|
5795
5759
|
}
|
|
5796
5760
|
break;
|
|
5797
5761
|
}
|
|
5798
|
-
const id =
|
|
5799
|
-
const namespace =
|
|
5800
|
-
const isAsync =
|
|
5801
|
-
const caller =
|
|
5802
|
-
if (
|
|
5762
|
+
const id = part.providerOptions?.[providerOptionsName]?.itemId ?? part.providerMetadata?.[providerOptionsName]?.itemId;
|
|
5763
|
+
const namespace = part.providerOptions?.[providerOptionsName]?.namespace ?? part.providerMetadata?.[providerOptionsName]?.namespace;
|
|
5764
|
+
const isAsync = part.providerOptions?.[providerOptionsName]?.async ?? part.providerMetadata?.[providerOptionsName]?.async;
|
|
5765
|
+
const caller = part.providerOptions?.[providerOptionsName]?.caller;
|
|
5766
|
+
if (caller?.type === "program") {
|
|
5803
5767
|
programmaticToolCallIds.add(part.toolCallId);
|
|
5804
5768
|
}
|
|
5805
5769
|
if (hasConversation && id != null) {
|
|
@@ -5823,9 +5787,9 @@ async function convertToOpenAIResponsesInput({
|
|
|
5823
5787
|
const execution = parsedInput.call_id != null ? "client" : "server";
|
|
5824
5788
|
input.push({
|
|
5825
5789
|
type: "tool_search_call",
|
|
5826
|
-
id: id
|
|
5790
|
+
id: id ?? part.toolCallId,
|
|
5827
5791
|
execution,
|
|
5828
|
-
call_id:
|
|
5792
|
+
call_id: parsedInput.call_id ?? null,
|
|
5829
5793
|
status: "completed",
|
|
5830
5794
|
arguments: parsedInput.arguments
|
|
5831
5795
|
});
|
|
@@ -5842,7 +5806,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
5842
5806
|
});
|
|
5843
5807
|
input.push({
|
|
5844
5808
|
type: "program",
|
|
5845
|
-
id: id
|
|
5809
|
+
id: id ?? part.toolCallId,
|
|
5846
5810
|
call_id: part.toolCallId,
|
|
5847
5811
|
code: parsedInput.code,
|
|
5848
5812
|
fingerprint: parsedInput.fingerprint
|
|
@@ -5857,7 +5821,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
5857
5821
|
break;
|
|
5858
5822
|
}
|
|
5859
5823
|
}
|
|
5860
|
-
const isProviderDefinedToolCall = hasLocalShellTool && resolvedToolName === "local_shell" || hasShellTool && resolvedToolName === "shell" || hasApplyPatchTool && resolvedToolName === "apply_patch" || hasComputerTool && resolvedToolName === "computer" || (
|
|
5824
|
+
const isProviderDefinedToolCall = hasLocalShellTool && resolvedToolName === "local_shell" || hasShellTool && resolvedToolName === "shell" || hasApplyPatchTool && resolvedToolName === "apply_patch" || hasComputerTool && resolvedToolName === "computer" || (customProviderToolNames?.has(resolvedToolName) ?? false);
|
|
5861
5825
|
if (hasPreviousResponseId && store && id != null && isProviderDefinedToolCall) {
|
|
5862
5826
|
break;
|
|
5863
5827
|
}
|
|
@@ -5964,7 +5928,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
5964
5928
|
});
|
|
5965
5929
|
break;
|
|
5966
5930
|
}
|
|
5967
|
-
if (customProviderToolNames
|
|
5931
|
+
if (customProviderToolNames?.has(resolvedToolName)) {
|
|
5968
5932
|
input.push({
|
|
5969
5933
|
type: "custom_tool_call",
|
|
5970
5934
|
call_id: part.toolCallId,
|
|
@@ -6000,7 +5964,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
6000
5964
|
part.toolName
|
|
6001
5965
|
);
|
|
6002
5966
|
if (part.toolName === toolSearchToolName) {
|
|
6003
|
-
const itemId =
|
|
5967
|
+
const itemId = part.providerOptions?.[providerOptionsName]?.itemId ?? part.providerMetadata?.[providerOptionsName]?.itemId ?? part.toolCallId;
|
|
6004
5968
|
if (store) {
|
|
6005
5969
|
input.push({ type: "item_reference", id: itemId });
|
|
6006
5970
|
} else if (part.output.type === "json") {
|
|
@@ -6020,7 +5984,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
6020
5984
|
break;
|
|
6021
5985
|
}
|
|
6022
5986
|
if (resolvedResultToolName === "programmatic_tool_calling") {
|
|
6023
|
-
const itemId =
|
|
5987
|
+
const itemId = part.providerOptions?.[providerOptionsName]?.itemId ?? part.providerMetadata?.[providerOptionsName]?.itemId ?? part.toolCallId;
|
|
6024
5988
|
if (store) {
|
|
6025
5989
|
input.push({ type: "item_reference", id: itemId });
|
|
6026
5990
|
} else if (part.output.type === "json") {
|
|
@@ -6060,7 +6024,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
6060
6024
|
break;
|
|
6061
6025
|
}
|
|
6062
6026
|
if (store) {
|
|
6063
|
-
const itemId =
|
|
6027
|
+
const itemId = part.providerOptions?.[providerOptionsName]?.itemId ?? part.toolCallId;
|
|
6064
6028
|
input.push({ type: "item_reference", id: itemId });
|
|
6065
6029
|
} else {
|
|
6066
6030
|
warnings.push({
|
|
@@ -6076,7 +6040,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
6076
6040
|
providerOptions: part.providerOptions,
|
|
6077
6041
|
schema: openaiResponsesReasoningProviderOptionsSchema
|
|
6078
6042
|
});
|
|
6079
|
-
const reasoningId = providerOptions2
|
|
6043
|
+
const reasoningId = providerOptions2?.itemId;
|
|
6080
6044
|
if ((hasConversation || hasPreviousResponseId) && reasoningId != null) {
|
|
6081
6045
|
break;
|
|
6082
6046
|
}
|
|
@@ -6108,19 +6072,19 @@ async function convertToOpenAIResponsesInput({
|
|
|
6108
6072
|
reasoningMessages[reasoningId] = {
|
|
6109
6073
|
type: "reasoning",
|
|
6110
6074
|
id: reasoningId,
|
|
6111
|
-
encrypted_content: providerOptions2
|
|
6075
|
+
encrypted_content: providerOptions2?.reasoningEncryptedContent,
|
|
6112
6076
|
summary: summaryParts
|
|
6113
6077
|
};
|
|
6114
6078
|
input.push(reasoningMessages[reasoningId]);
|
|
6115
6079
|
} else {
|
|
6116
6080
|
reasoningMessage.summary.push(...summaryParts);
|
|
6117
|
-
if (
|
|
6081
|
+
if (providerOptions2?.reasoningEncryptedContent != null) {
|
|
6118
6082
|
reasoningMessage.encrypted_content = providerOptions2.reasoningEncryptedContent;
|
|
6119
6083
|
}
|
|
6120
6084
|
}
|
|
6121
6085
|
}
|
|
6122
6086
|
} else {
|
|
6123
|
-
const encryptedContent = providerOptions2
|
|
6087
|
+
const encryptedContent = providerOptions2?.reasoningEncryptedContent;
|
|
6124
6088
|
if (encryptedContent != null) {
|
|
6125
6089
|
const summaryParts = [];
|
|
6126
6090
|
if (part.text.length > 0) {
|
|
@@ -6145,8 +6109,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
6145
6109
|
}
|
|
6146
6110
|
case "custom": {
|
|
6147
6111
|
if (part.kind === "openai.compaction") {
|
|
6148
|
-
const providerOptions2 =
|
|
6149
|
-
const id = providerOptions2
|
|
6112
|
+
const providerOptions2 = part.providerOptions?.[providerOptionsName];
|
|
6113
|
+
const id = providerOptions2?.itemId;
|
|
6150
6114
|
if (hasConversation && id != null) {
|
|
6151
6115
|
break;
|
|
6152
6116
|
}
|
|
@@ -6154,7 +6118,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
6154
6118
|
input.push({ type: "item_reference", id });
|
|
6155
6119
|
break;
|
|
6156
6120
|
}
|
|
6157
|
-
const encryptedContent = providerOptions2
|
|
6121
|
+
const encryptedContent = providerOptions2?.encryptedContent;
|
|
6158
6122
|
if (id != null) {
|
|
6159
6123
|
input.push({
|
|
6160
6124
|
type: "compaction",
|
|
@@ -6251,7 +6215,7 @@ ${text}`,
|
|
|
6251
6215
|
}
|
|
6252
6216
|
const output = part.output;
|
|
6253
6217
|
if (output.type === "execution-denied") {
|
|
6254
|
-
const approvalId =
|
|
6218
|
+
const approvalId = output.providerOptions?.openai?.approvalId;
|
|
6255
6219
|
if (approvalId) {
|
|
6256
6220
|
continue;
|
|
6257
6221
|
}
|
|
@@ -6331,7 +6295,7 @@ ${text}`,
|
|
|
6331
6295
|
file_id: parsedOutput.output.fileId,
|
|
6332
6296
|
detail: parsedOutput.output.detail
|
|
6333
6297
|
},
|
|
6334
|
-
acknowledged_safety_checks:
|
|
6298
|
+
acknowledged_safety_checks: parsedOutput.acknowledgedSafetyChecks?.map((safetyCheck) => ({
|
|
6335
6299
|
id: safetyCheck.id,
|
|
6336
6300
|
code: safetyCheck.code,
|
|
6337
6301
|
message: safetyCheck.message
|
|
@@ -6339,7 +6303,7 @@ ${text}`,
|
|
|
6339
6303
|
});
|
|
6340
6304
|
continue;
|
|
6341
6305
|
}
|
|
6342
|
-
if (customProviderToolNames
|
|
6306
|
+
if (customProviderToolNames?.has(resolvedToolName)) {
|
|
6343
6307
|
const promptCacheBreakpoint = getScalarToolResultPromptCacheBreakpoint({
|
|
6344
6308
|
output,
|
|
6345
6309
|
toolResultProviderOptions: part.providerOptions,
|
|
@@ -6360,7 +6324,7 @@ ${text}`,
|
|
|
6360
6324
|
break;
|
|
6361
6325
|
case "execution-denied":
|
|
6362
6326
|
outputValue = convertScalarOutput(
|
|
6363
|
-
|
|
6327
|
+
output.reason ?? "Tool call execution denied."
|
|
6364
6328
|
);
|
|
6365
6329
|
break;
|
|
6366
6330
|
case "json":
|
|
@@ -6369,7 +6333,6 @@ ${text}`,
|
|
|
6369
6333
|
break;
|
|
6370
6334
|
case "content":
|
|
6371
6335
|
outputValue = output.value.map((item) => {
|
|
6372
|
-
var _a3, _b2, _c2;
|
|
6373
6336
|
const promptCacheBreakpoint2 = getPromptCacheBreakpoint2(
|
|
6374
6337
|
item.providerOptions,
|
|
6375
6338
|
providerOptionsName
|
|
@@ -6385,7 +6348,7 @@ ${text}`,
|
|
|
6385
6348
|
};
|
|
6386
6349
|
case "file": {
|
|
6387
6350
|
const topLevel = getTopLevelMediaType2(item.mediaType);
|
|
6388
|
-
const imageDetail =
|
|
6351
|
+
const imageDetail = item.providerOptions?.[providerOptionsName]?.imageDetail;
|
|
6389
6352
|
if (item.data.type === "data") {
|
|
6390
6353
|
const fullMediaType = resolveFullMediaType2({
|
|
6391
6354
|
part: item
|
|
@@ -6402,7 +6365,7 @@ ${text}`,
|
|
|
6402
6365
|
}
|
|
6403
6366
|
return {
|
|
6404
6367
|
type: "input_file",
|
|
6405
|
-
filename:
|
|
6368
|
+
filename: item.filename ?? "data",
|
|
6406
6369
|
file_data: `data:${fullMediaType};base64,${convertToBase642(item.data.data)}`,
|
|
6407
6370
|
...promptCacheBreakpoint2 != null && {
|
|
6408
6371
|
prompt_cache_breakpoint: promptCacheBreakpoint2
|
|
@@ -6453,8 +6416,8 @@ ${text}`,
|
|
|
6453
6416
|
});
|
|
6454
6417
|
continue;
|
|
6455
6418
|
}
|
|
6456
|
-
const resultCaller =
|
|
6457
|
-
if (output.type === "execution-denied" && (
|
|
6419
|
+
const resultCaller = part.providerOptions?.[providerOptionsName]?.caller;
|
|
6420
|
+
if (output.type === "execution-denied" && (resultCaller?.type === "program" || programmaticToolCallIds.has(part.toolCallId))) {
|
|
6458
6421
|
throw new UnsupportedFunctionalityError5({
|
|
6459
6422
|
functionality: "execution-denied results for programmatic tool calls"
|
|
6460
6423
|
});
|
|
@@ -6522,15 +6485,14 @@ async function prepareResponsesTools({
|
|
|
6522
6485
|
outputSchemaToolNames,
|
|
6523
6486
|
supportsAsyncToolCalling = true
|
|
6524
6487
|
}) {
|
|
6525
|
-
|
|
6526
|
-
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
6488
|
+
tools = tools?.length ? tools : void 0;
|
|
6527
6489
|
const toolWarnings = [];
|
|
6528
6490
|
if (tools == null) {
|
|
6529
6491
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
6530
6492
|
}
|
|
6531
6493
|
const openaiTools2 = [];
|
|
6532
6494
|
const namespaceTools = /* @__PURE__ */ new Map();
|
|
6533
|
-
const resolvedCustomProviderToolNames = customProviderToolNames
|
|
6495
|
+
const resolvedCustomProviderToolNames = customProviderToolNames ?? /* @__PURE__ */ new Set();
|
|
6534
6496
|
const allowedToolResolutions = /* @__PURE__ */ new Map();
|
|
6535
6497
|
const allowedToolAliases = /* @__PURE__ */ new Map();
|
|
6536
6498
|
const recordAllowedTool = (toolName, resolution, canonicalName) => {
|
|
@@ -6548,22 +6510,22 @@ async function prepareResponsesTools({
|
|
|
6548
6510
|
for (const tool of tools) {
|
|
6549
6511
|
switch (tool.type) {
|
|
6550
6512
|
case "function": {
|
|
6551
|
-
const openaiOptions =
|
|
6552
|
-
if (
|
|
6553
|
-
outputSchemaToolNames
|
|
6513
|
+
const openaiOptions = tool.providerOptions?.openai;
|
|
6514
|
+
if (openaiOptions?.outputSchema != null) {
|
|
6515
|
+
outputSchemaToolNames?.add(tool.name);
|
|
6554
6516
|
}
|
|
6555
6517
|
const openaiFunctionTool = prepareFunctionTool({
|
|
6556
6518
|
tool,
|
|
6557
6519
|
options: openaiOptions,
|
|
6558
6520
|
toolWarnings,
|
|
6559
6521
|
async: resolveAsyncToolOption({
|
|
6560
|
-
value: openaiOptions
|
|
6522
|
+
value: openaiOptions?.async,
|
|
6561
6523
|
supportsAsyncToolCalling,
|
|
6562
6524
|
toolName: tool.name,
|
|
6563
6525
|
toolWarnings
|
|
6564
6526
|
})
|
|
6565
6527
|
});
|
|
6566
|
-
const namespace = openaiOptions
|
|
6528
|
+
const namespace = openaiOptions?.namespace;
|
|
6567
6529
|
if (namespace == null) {
|
|
6568
6530
|
openaiTools2.push(openaiFunctionTool);
|
|
6569
6531
|
} else {
|
|
@@ -6589,7 +6551,7 @@ async function prepareResponsesTools({
|
|
|
6589
6551
|
namespace != null ? {
|
|
6590
6552
|
supported: false,
|
|
6591
6553
|
reason: "tools inside an OpenAI tool namespace are not visible to tool_choice.allowed_tools"
|
|
6592
|
-
} :
|
|
6554
|
+
} : openaiOptions?.deferLoading === true ? {
|
|
6593
6555
|
supported: false,
|
|
6594
6556
|
reason: "deferred tools are not visible to tool_choice.allowed_tools"
|
|
6595
6557
|
} : {
|
|
@@ -6735,7 +6697,7 @@ async function prepareResponsesTools({
|
|
|
6735
6697
|
authorization: args.authorization,
|
|
6736
6698
|
connector_id: args.connectorId,
|
|
6737
6699
|
headers: args.headers,
|
|
6738
|
-
require_approval: requireApprovalParam
|
|
6700
|
+
require_approval: requireApprovalParam ?? "never",
|
|
6739
6701
|
server_description: args.serverDescription,
|
|
6740
6702
|
server_url: args.serverUrl
|
|
6741
6703
|
});
|
|
@@ -6786,7 +6748,7 @@ async function prepareResponsesTools({
|
|
|
6786
6748
|
recordAllowedTool(
|
|
6787
6749
|
tool.name,
|
|
6788
6750
|
toAllowedToolResolution(openaiTool),
|
|
6789
|
-
toolNameMapping
|
|
6751
|
+
toolNameMapping?.toProviderToolName(tool.name)
|
|
6790
6752
|
);
|
|
6791
6753
|
}
|
|
6792
6754
|
break;
|
|
@@ -6804,7 +6766,7 @@ async function prepareResponsesTools({
|
|
|
6804
6766
|
const droppedToolNames = [];
|
|
6805
6767
|
for (const name of allowedTools.toolNames) {
|
|
6806
6768
|
const directResolution = allowedToolResolutions.get(name);
|
|
6807
|
-
const resolution = directResolution
|
|
6769
|
+
const resolution = directResolution ?? allowedToolAliases.get(name);
|
|
6808
6770
|
if (directResolution != null && allowedToolAliases.has(name)) {
|
|
6809
6771
|
toolWarnings.push({
|
|
6810
6772
|
type: "unsupported",
|
|
@@ -6829,7 +6791,7 @@ async function prepareResponsesTools({
|
|
|
6829
6791
|
});
|
|
6830
6792
|
allowedToolEntries.push({
|
|
6831
6793
|
type: "function",
|
|
6832
|
-
name:
|
|
6794
|
+
name: toolNameMapping?.toProviderToolName(name) ?? name
|
|
6833
6795
|
});
|
|
6834
6796
|
continue;
|
|
6835
6797
|
}
|
|
@@ -6855,7 +6817,7 @@ async function prepareResponsesTools({
|
|
|
6855
6817
|
tools: openaiTools2,
|
|
6856
6818
|
toolChoice: {
|
|
6857
6819
|
type: "allowed_tools",
|
|
6858
|
-
mode:
|
|
6820
|
+
mode: allowedTools.mode ?? "auto",
|
|
6859
6821
|
tools: allowedToolEntries
|
|
6860
6822
|
},
|
|
6861
6823
|
toolWarnings
|
|
@@ -6871,7 +6833,7 @@ async function prepareResponsesTools({
|
|
|
6871
6833
|
case "required":
|
|
6872
6834
|
return { tools: openaiTools2, toolChoice: type, toolWarnings };
|
|
6873
6835
|
case "tool": {
|
|
6874
|
-
const resolvedToolName =
|
|
6836
|
+
const resolvedToolName = toolNameMapping?.toProviderToolName(toolChoice.toolName) ?? toolChoice.toolName;
|
|
6875
6837
|
return {
|
|
6876
6838
|
tools: openaiTools2,
|
|
6877
6839
|
toolChoice: resolvedToolName === "code_interpreter" || resolvedToolName === "file_search" || resolvedToolName === "image_generation" || resolvedToolName === "web_search_preview" || resolvedToolName === "web_search" || resolvedToolName === "mcp" || resolvedToolName === "apply_patch" || resolvedToolName === "computer" || resolvedToolName === "programmatic_tool_calling" ? { type: resolvedToolName } : resolvedCustomProviderToolNames.has(resolvedToolName) ? { type: "custom", name: resolvedToolName } : { type: "function", name: resolvedToolName },
|
|
@@ -6939,13 +6901,12 @@ function prepareFunctionTool({
|
|
|
6939
6901
|
toolWarnings,
|
|
6940
6902
|
async
|
|
6941
6903
|
}) {
|
|
6942
|
-
|
|
6943
|
-
const deferLoading = options == null ? void 0 : options.deferLoading;
|
|
6904
|
+
const deferLoading = options?.deferLoading;
|
|
6944
6905
|
const normalizedInputSchema = normalizeOpenAIJsonSchema(tool.inputSchema);
|
|
6945
|
-
const normalizedOutputSchema =
|
|
6906
|
+
const normalizedOutputSchema = options?.outputSchema != null ? normalizeOpenAIJsonSchema(options.outputSchema) : void 0;
|
|
6946
6907
|
toolWarnings.push(
|
|
6947
6908
|
...normalizedInputSchema.warnings,
|
|
6948
|
-
...
|
|
6909
|
+
...normalizedOutputSchema?.warnings ?? []
|
|
6949
6910
|
);
|
|
6950
6911
|
return {
|
|
6951
6912
|
type: "function",
|
|
@@ -6953,10 +6914,10 @@ function prepareFunctionTool({
|
|
|
6953
6914
|
description: tool.description,
|
|
6954
6915
|
parameters: normalizedInputSchema.schema,
|
|
6955
6916
|
...async != null ? { async } : {},
|
|
6956
|
-
|
|
6917
|
+
strict: tool.strict ?? false,
|
|
6957
6918
|
...deferLoading != null ? { defer_loading: deferLoading } : {},
|
|
6958
|
-
...
|
|
6959
|
-
...
|
|
6919
|
+
...options?.allowedCallers != null ? { allowed_callers: options.allowedCallers } : {},
|
|
6920
|
+
...options?.outputSchema != null ? { output_schema: normalizedOutputSchema?.schema } : {}
|
|
6960
6921
|
};
|
|
6961
6922
|
}
|
|
6962
6923
|
function resolveAsyncToolOption({
|
|
@@ -7003,39 +6964,35 @@ function mapShellEnvironment(environment) {
|
|
|
7003
6964
|
};
|
|
7004
6965
|
}
|
|
7005
6966
|
function mapShellSkills(skills) {
|
|
7006
|
-
return skills
|
|
7007
|
-
(skill) => {
|
|
7008
|
-
|
|
7009
|
-
|
|
7010
|
-
|
|
7011
|
-
|
|
7012
|
-
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
data: skill.source.data
|
|
7024
|
-
}
|
|
7025
|
-
};
|
|
6967
|
+
return skills?.map(
|
|
6968
|
+
(skill) => skill.type === "skillReference" ? {
|
|
6969
|
+
type: "skill_reference",
|
|
6970
|
+
skill_id: resolveProviderReference3({
|
|
6971
|
+
reference: skill.providerReference ?? {},
|
|
6972
|
+
provider: "openai"
|
|
6973
|
+
}),
|
|
6974
|
+
version: skill.version ?? "latest"
|
|
6975
|
+
} : {
|
|
6976
|
+
type: "inline",
|
|
6977
|
+
name: skill.name,
|
|
6978
|
+
description: skill.description,
|
|
6979
|
+
source: {
|
|
6980
|
+
type: "base64",
|
|
6981
|
+
media_type: skill.source.mediaType,
|
|
6982
|
+
data: skill.source.data
|
|
6983
|
+
}
|
|
7026
6984
|
}
|
|
7027
6985
|
);
|
|
7028
6986
|
}
|
|
7029
6987
|
|
|
7030
6988
|
// src/responses/openai-responses-language-model.ts
|
|
7031
6989
|
function extractApprovalRequestIdToToolCallIdMapping(prompt) {
|
|
7032
|
-
var _a2, _b;
|
|
7033
6990
|
const mapping = {};
|
|
7034
6991
|
for (const message of prompt) {
|
|
7035
6992
|
if (message.role !== "assistant") continue;
|
|
7036
6993
|
for (const part of message.content) {
|
|
7037
6994
|
if (part.type !== "tool-call") continue;
|
|
7038
|
-
const approvalRequestId =
|
|
6995
|
+
const approvalRequestId = part.providerOptions?.openai?.approvalRequestId;
|
|
7039
6996
|
if (approvalRequestId != null) {
|
|
7040
6997
|
mapping[approvalRequestId] = part.toolCallId;
|
|
7041
6998
|
}
|
|
@@ -7098,16 +7055,15 @@ function mapComputerCallInput({
|
|
|
7098
7055
|
pending_safety_checks,
|
|
7099
7056
|
status
|
|
7100
7057
|
}) {
|
|
7101
|
-
var _a2;
|
|
7102
7058
|
return {
|
|
7103
|
-
actions: (actions
|
|
7059
|
+
actions: (actions ?? (action != null ? [action] : [])).map(
|
|
7104
7060
|
mapComputerAction
|
|
7105
7061
|
),
|
|
7106
|
-
pendingSafetyChecks:
|
|
7062
|
+
pendingSafetyChecks: pending_safety_checks?.map((safetyCheck) => ({
|
|
7107
7063
|
id: safetyCheck.id,
|
|
7108
7064
|
...safetyCheck.code != null && { code: safetyCheck.code },
|
|
7109
7065
|
...safetyCheck.message != null && { message: safetyCheck.message }
|
|
7110
|
-
}))
|
|
7066
|
+
})) ?? [],
|
|
7111
7067
|
status
|
|
7112
7068
|
};
|
|
7113
7069
|
}
|
|
@@ -7122,7 +7078,7 @@ function getConfigurationUpdateUnsupportedReason({
|
|
|
7122
7078
|
if (!modelCapabilities.supportsConfigurationUpdate) {
|
|
7123
7079
|
return "reasoningEffortUpdate is only supported by GPT-6 and later models";
|
|
7124
7080
|
}
|
|
7125
|
-
if (
|
|
7081
|
+
if (options?.reasoningMode === "pro" || options?.contextManagement != null || options?.truncation === "auto") {
|
|
7126
7082
|
return "reasoningEffortUpdate requires standard reasoning mode without automatic compaction or automatic truncation";
|
|
7127
7083
|
}
|
|
7128
7084
|
return void 0;
|
|
@@ -7169,7 +7125,6 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7169
7125
|
responseFormat
|
|
7170
7126
|
}
|
|
7171
7127
|
}) {
|
|
7172
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
7173
7128
|
const warnings = [];
|
|
7174
7129
|
const modelCapabilities = getOpenAILanguageModelCapabilities(modelId);
|
|
7175
7130
|
if (topK != null) {
|
|
@@ -7200,7 +7155,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7200
7155
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
7201
7156
|
});
|
|
7202
7157
|
}
|
|
7203
|
-
let resolvedReasoningEffort =
|
|
7158
|
+
let resolvedReasoningEffort = openaiOptions?.reasoningEffort ?? (isCustomReasoning2(reasoning) ? reasoning : void 0);
|
|
7204
7159
|
if (resolvedReasoningEffort != null && modelCapabilities.supportedReasoningEfforts != null && !modelCapabilities.supportedReasoningEfforts.includes(
|
|
7205
7160
|
resolvedReasoningEffort
|
|
7206
7161
|
)) {
|
|
@@ -7211,9 +7166,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7211
7166
|
});
|
|
7212
7167
|
resolvedReasoningEffort = void 0;
|
|
7213
7168
|
}
|
|
7214
|
-
const resolvedReasoningSummary =
|
|
7215
|
-
const isReasoningModel =
|
|
7216
|
-
if (
|
|
7169
|
+
const resolvedReasoningSummary = openaiOptions?.reasoningSummary !== void 0 ? openaiOptions.reasoningSummary : resolvedReasoningEffort != null && resolvedReasoningEffort !== "none" ? "detailed" : void 0;
|
|
7170
|
+
const isReasoningModel = openaiOptions?.forceReasoning ?? modelCapabilities.isReasoningModel;
|
|
7171
|
+
if (openaiOptions?.conversation && openaiOptions?.previousResponseId) {
|
|
7217
7172
|
warnings.push({
|
|
7218
7173
|
type: "unsupported",
|
|
7219
7174
|
feature: "conversation",
|
|
@@ -7246,7 +7201,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7246
7201
|
} = await prepareResponsesTools({
|
|
7247
7202
|
tools,
|
|
7248
7203
|
toolChoice,
|
|
7249
|
-
allowedTools:
|
|
7204
|
+
allowedTools: openaiOptions?.allowedTools ?? void 0,
|
|
7250
7205
|
toolNameMapping,
|
|
7251
7206
|
customProviderToolNames,
|
|
7252
7207
|
outputSchemaToolNames,
|
|
@@ -7259,15 +7214,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7259
7214
|
const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
|
|
7260
7215
|
prompt,
|
|
7261
7216
|
toolNameMapping,
|
|
7262
|
-
systemMessageMode:
|
|
7217
|
+
systemMessageMode: openaiOptions?.systemMessageMode ?? (isReasoningModel ? "developer" : modelCapabilities.systemMessageMode),
|
|
7263
7218
|
providerOptionsName,
|
|
7264
7219
|
configurationUpdateUnsupportedReason,
|
|
7265
7220
|
explicitMessageItemType: config.explicitMessageItemType,
|
|
7266
7221
|
fileIdPrefixes: config.fileIdPrefixes,
|
|
7267
|
-
passThroughUnsupportedFiles:
|
|
7268
|
-
store:
|
|
7269
|
-
hasConversation:
|
|
7270
|
-
hasPreviousResponseId:
|
|
7222
|
+
passThroughUnsupportedFiles: openaiOptions?.passThroughUnsupportedFiles ?? false,
|
|
7223
|
+
store: openaiOptions?.store ?? true,
|
|
7224
|
+
hasConversation: openaiOptions?.conversation != null,
|
|
7225
|
+
hasPreviousResponseId: openaiOptions?.previousResponseId != null,
|
|
7271
7226
|
hasLocalShellTool: hasOpenAITool("openai.local_shell"),
|
|
7272
7227
|
hasShellTool: hasOpenAITool("openai.shell"),
|
|
7273
7228
|
hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
|
|
@@ -7277,7 +7232,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7277
7232
|
outputSchemaToolNames: outputSchemaToolNames.size > 0 ? outputSchemaToolNames : void 0
|
|
7278
7233
|
});
|
|
7279
7234
|
warnings.push(...inputWarnings);
|
|
7280
|
-
const reasoningEffortUpdate = openaiOptions
|
|
7235
|
+
const reasoningEffortUpdate = openaiOptions?.reasoningEffortUpdate;
|
|
7281
7236
|
if (reasoningEffortUpdate != null && configurationUpdateUnsupportedReason != null) {
|
|
7282
7237
|
warnings.push({
|
|
7283
7238
|
type: "unsupported",
|
|
@@ -7286,7 +7241,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7286
7241
|
});
|
|
7287
7242
|
} else if (reasoningEffortUpdate != null) {
|
|
7288
7243
|
const firstItem = input[0];
|
|
7289
|
-
if (
|
|
7244
|
+
if (firstItem?.type !== "configuration_update" || firstItem.reasoning.effort !== reasoningEffortUpdate) {
|
|
7290
7245
|
input.unshift({
|
|
7291
7246
|
type: "configuration_update",
|
|
7292
7247
|
reasoning: { effort: reasoningEffortUpdate }
|
|
@@ -7300,15 +7255,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7300
7255
|
});
|
|
7301
7256
|
}
|
|
7302
7257
|
}
|
|
7303
|
-
if (openaiOptions
|
|
7258
|
+
if (openaiOptions?.compactionTrigger) {
|
|
7304
7259
|
input.push({ type: "compaction_trigger" });
|
|
7305
7260
|
}
|
|
7306
|
-
const strictJsonSchema =
|
|
7307
|
-
const normalizedResponseFormatSchema =
|
|
7261
|
+
const strictJsonSchema = openaiOptions?.strictJsonSchema ?? true;
|
|
7262
|
+
const normalizedResponseFormatSchema = responseFormat?.type === "json" && responseFormat.schema != null ? normalizeOpenAIJsonSchema(responseFormat.schema) : void 0;
|
|
7308
7263
|
if (normalizedResponseFormatSchema != null) {
|
|
7309
7264
|
warnings.push(...normalizedResponseFormatSchema.warnings);
|
|
7310
7265
|
}
|
|
7311
|
-
let include = openaiOptions
|
|
7266
|
+
let include = openaiOptions?.include;
|
|
7312
7267
|
function addInclude(key) {
|
|
7313
7268
|
if (include == null) {
|
|
7314
7269
|
include = [key];
|
|
@@ -7317,26 +7272,25 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7317
7272
|
}
|
|
7318
7273
|
}
|
|
7319
7274
|
function getOpenAIToolName(id) {
|
|
7320
|
-
|
|
7321
|
-
return (_a3 = tools == null ? void 0 : tools.find((tool) => tool.type === "provider" && tool.id === id)) == null ? void 0 : _a3.name;
|
|
7275
|
+
return tools?.find((tool) => tool.type === "provider" && tool.id === id)?.name;
|
|
7322
7276
|
}
|
|
7323
7277
|
function hasOpenAITool(id) {
|
|
7324
7278
|
return getOpenAIToolName(id) != null;
|
|
7325
7279
|
}
|
|
7326
|
-
const topLogprobs = typeof
|
|
7280
|
+
const topLogprobs = typeof openaiOptions?.logprobs === "number" ? openaiOptions?.logprobs : openaiOptions?.logprobs === true ? TOP_LOGPROBS_MAX : void 0;
|
|
7327
7281
|
if (topLogprobs) {
|
|
7328
7282
|
addInclude("message.output_text.logprobs");
|
|
7329
7283
|
}
|
|
7330
|
-
const webSearchToolName =
|
|
7284
|
+
const webSearchToolName = tools?.find(
|
|
7331
7285
|
(tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
|
|
7332
|
-
)
|
|
7333
|
-
if (webSearchToolName && config.supportsWebSearchSourcesInclude !== false &&
|
|
7286
|
+
)?.name;
|
|
7287
|
+
if (webSearchToolName && config.supportsWebSearchSourcesInclude !== false && openaiOptions?.includeWebSearchSources !== false) {
|
|
7334
7288
|
addInclude("web_search_call.action.sources");
|
|
7335
7289
|
}
|
|
7336
7290
|
if (hasOpenAITool("openai.code_interpreter")) {
|
|
7337
7291
|
addInclude("code_interpreter_call.outputs");
|
|
7338
7292
|
}
|
|
7339
|
-
const store = openaiOptions
|
|
7293
|
+
const store = openaiOptions?.store;
|
|
7340
7294
|
if (store === false && isReasoningModel) {
|
|
7341
7295
|
addInclude("reasoning.encrypted_content");
|
|
7342
7296
|
}
|
|
@@ -7346,48 +7300,48 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7346
7300
|
temperature,
|
|
7347
7301
|
top_p: topP,
|
|
7348
7302
|
max_output_tokens: maxOutputTokens,
|
|
7349
|
-
...(
|
|
7303
|
+
...(responseFormat?.type === "json" || openaiOptions?.textVerbosity) && {
|
|
7350
7304
|
text: {
|
|
7351
|
-
...
|
|
7305
|
+
...responseFormat?.type === "json" && {
|
|
7352
7306
|
format: normalizedResponseFormatSchema != null ? {
|
|
7353
7307
|
type: "json_schema",
|
|
7354
7308
|
strict: strictJsonSchema,
|
|
7355
|
-
name:
|
|
7309
|
+
name: responseFormat.name ?? "response",
|
|
7356
7310
|
description: responseFormat.description,
|
|
7357
7311
|
schema: normalizedResponseFormatSchema.schema
|
|
7358
7312
|
} : { type: "json_object" }
|
|
7359
7313
|
},
|
|
7360
|
-
...
|
|
7314
|
+
...openaiOptions?.textVerbosity && {
|
|
7361
7315
|
verbosity: openaiOptions.textVerbosity
|
|
7362
7316
|
}
|
|
7363
7317
|
}
|
|
7364
7318
|
},
|
|
7365
7319
|
// provider options:
|
|
7366
|
-
conversation: openaiOptions
|
|
7367
|
-
max_tool_calls: openaiOptions
|
|
7368
|
-
metadata: openaiOptions
|
|
7369
|
-
parallel_tool_calls: openaiOptions
|
|
7370
|
-
previous_response_id: openaiOptions
|
|
7320
|
+
conversation: openaiOptions?.conversation,
|
|
7321
|
+
max_tool_calls: openaiOptions?.maxToolCalls,
|
|
7322
|
+
metadata: openaiOptions?.metadata,
|
|
7323
|
+
parallel_tool_calls: openaiOptions?.parallelToolCalls,
|
|
7324
|
+
previous_response_id: openaiOptions?.previousResponseId,
|
|
7371
7325
|
store,
|
|
7372
|
-
user: openaiOptions
|
|
7373
|
-
instructions: openaiOptions
|
|
7374
|
-
service_tier: openaiOptions
|
|
7326
|
+
user: openaiOptions?.user,
|
|
7327
|
+
instructions: openaiOptions?.instructions,
|
|
7328
|
+
service_tier: openaiOptions?.serviceTier,
|
|
7375
7329
|
include,
|
|
7376
|
-
prompt_cache_key: openaiOptions
|
|
7377
|
-
prompt_cache_options: openaiOptions
|
|
7378
|
-
prompt_cache_retention: openaiOptions
|
|
7379
|
-
safety_identifier: openaiOptions
|
|
7330
|
+
prompt_cache_key: openaiOptions?.promptCacheKey,
|
|
7331
|
+
prompt_cache_options: openaiOptions?.promptCacheOptions,
|
|
7332
|
+
prompt_cache_retention: openaiOptions?.promptCacheRetention,
|
|
7333
|
+
safety_identifier: openaiOptions?.safetyIdentifier,
|
|
7380
7334
|
top_logprobs: topLogprobs,
|
|
7381
|
-
truncation: openaiOptions
|
|
7335
|
+
truncation: openaiOptions?.truncation,
|
|
7382
7336
|
// context management (server-side compaction):
|
|
7383
|
-
...
|
|
7337
|
+
...openaiOptions?.contextManagement && {
|
|
7384
7338
|
context_management: openaiOptions.contextManagement.map((cm) => ({
|
|
7385
7339
|
type: cm.type,
|
|
7386
7340
|
compact_threshold: cm.compactThreshold
|
|
7387
7341
|
}))
|
|
7388
7342
|
},
|
|
7389
7343
|
// model-specific settings:
|
|
7390
|
-
...isReasoningModel && (resolvedReasoningEffort != null || resolvedReasoningSummary != null ||
|
|
7344
|
+
...isReasoningModel && (resolvedReasoningEffort != null || resolvedReasoningSummary != null || openaiOptions?.reasoningMode != null || openaiOptions?.reasoningContext != null) && {
|
|
7391
7345
|
reasoning: {
|
|
7392
7346
|
...resolvedReasoningEffort != null && {
|
|
7393
7347
|
effort: resolvedReasoningEffort
|
|
@@ -7395,10 +7349,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7395
7349
|
...resolvedReasoningSummary != null && {
|
|
7396
7350
|
summary: resolvedReasoningSummary
|
|
7397
7351
|
},
|
|
7398
|
-
...
|
|
7352
|
+
...openaiOptions?.reasoningMode != null && {
|
|
7399
7353
|
mode: openaiOptions.reasoningMode
|
|
7400
7354
|
},
|
|
7401
|
-
...
|
|
7355
|
+
...openaiOptions?.reasoningContext != null && {
|
|
7402
7356
|
context: openaiOptions.reasoningContext
|
|
7403
7357
|
}
|
|
7404
7358
|
}
|
|
@@ -7430,9 +7384,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7430
7384
|
details: "topP is not supported for reasoning models"
|
|
7431
7385
|
});
|
|
7432
7386
|
}
|
|
7433
|
-
if (modelCapabilities.supportedReasoningEfforts != null && (baseArgs.top_logprobs != null ||
|
|
7387
|
+
if (modelCapabilities.supportedReasoningEfforts != null && (baseArgs.top_logprobs != null || baseArgs.include?.includes("message.output_text.logprobs"))) {
|
|
7434
7388
|
baseArgs.top_logprobs = void 0;
|
|
7435
|
-
const filteredInclude =
|
|
7389
|
+
const filteredInclude = baseArgs.include?.filter(
|
|
7436
7390
|
(value) => value !== "message.output_text.logprobs"
|
|
7437
7391
|
);
|
|
7438
7392
|
baseArgs.include = filteredInclude != null && filteredInclude.length > 0 ? filteredInclude : void 0;
|
|
@@ -7444,28 +7398,28 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7444
7398
|
}
|
|
7445
7399
|
}
|
|
7446
7400
|
} else {
|
|
7447
|
-
if (
|
|
7401
|
+
if (openaiOptions?.reasoningEffort != null) {
|
|
7448
7402
|
warnings.push({
|
|
7449
7403
|
type: "unsupported",
|
|
7450
7404
|
feature: "reasoningEffort",
|
|
7451
7405
|
details: "reasoningEffort is not supported for non-reasoning models"
|
|
7452
7406
|
});
|
|
7453
7407
|
}
|
|
7454
|
-
if (
|
|
7408
|
+
if (openaiOptions?.reasoningSummary != null) {
|
|
7455
7409
|
warnings.push({
|
|
7456
7410
|
type: "unsupported",
|
|
7457
7411
|
feature: "reasoningSummary",
|
|
7458
7412
|
details: "reasoningSummary is not supported for non-reasoning models"
|
|
7459
7413
|
});
|
|
7460
7414
|
}
|
|
7461
|
-
if (
|
|
7415
|
+
if (openaiOptions?.reasoningMode != null) {
|
|
7462
7416
|
warnings.push({
|
|
7463
7417
|
type: "unsupported",
|
|
7464
7418
|
feature: "reasoningMode",
|
|
7465
7419
|
details: "reasoningMode is not supported for non-reasoning models"
|
|
7466
7420
|
});
|
|
7467
7421
|
}
|
|
7468
|
-
if (
|
|
7422
|
+
if (openaiOptions?.reasoningContext != null) {
|
|
7469
7423
|
warnings.push({
|
|
7470
7424
|
type: "unsupported",
|
|
7471
7425
|
feature: "reasoningContext",
|
|
@@ -7473,7 +7427,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7473
7427
|
});
|
|
7474
7428
|
}
|
|
7475
7429
|
}
|
|
7476
|
-
if (
|
|
7430
|
+
if (openaiOptions?.serviceTier === "flex" && !modelCapabilities.supportsFlexProcessing) {
|
|
7477
7431
|
warnings.push({
|
|
7478
7432
|
type: "unsupported",
|
|
7479
7433
|
feature: "serviceTier",
|
|
@@ -7481,7 +7435,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7481
7435
|
});
|
|
7482
7436
|
delete baseArgs.service_tier;
|
|
7483
7437
|
}
|
|
7484
|
-
if ((
|
|
7438
|
+
if ((openaiOptions?.serviceTier === "priority" || openaiOptions?.serviceTier === "fast") && !modelCapabilities.supportsPriorityProcessing) {
|
|
7485
7439
|
warnings.push({
|
|
7486
7440
|
type: "unsupported",
|
|
7487
7441
|
feature: "serviceTier",
|
|
@@ -7489,9 +7443,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7489
7443
|
});
|
|
7490
7444
|
delete baseArgs.service_tier;
|
|
7491
7445
|
}
|
|
7492
|
-
const shellToolEnvType =
|
|
7446
|
+
const shellToolEnvType = tools?.find(
|
|
7493
7447
|
(tool) => tool.type === "provider" && tool.id === "openai.shell"
|
|
7494
|
-
)
|
|
7448
|
+
)?.args?.environment?.type;
|
|
7495
7449
|
const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
|
|
7496
7450
|
return {
|
|
7497
7451
|
webSearchToolName,
|
|
@@ -7515,7 +7469,6 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7515
7469
|
});
|
|
7516
7470
|
}
|
|
7517
7471
|
async doGenerate(options) {
|
|
7518
|
-
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;
|
|
7519
7472
|
const {
|
|
7520
7473
|
args: body,
|
|
7521
7474
|
warnings,
|
|
@@ -7535,7 +7488,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7535
7488
|
rawValue: rawResponse
|
|
7536
7489
|
} = await postJsonToApi5({
|
|
7537
7490
|
url,
|
|
7538
|
-
headers: combineHeaders6(
|
|
7491
|
+
headers: combineHeaders6(this.config.headers?.(), options.headers),
|
|
7539
7492
|
body,
|
|
7540
7493
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
7541
7494
|
successfulResponseHandler: createJsonResponseHandler6(
|
|
@@ -7556,7 +7509,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7556
7509
|
});
|
|
7557
7510
|
}
|
|
7558
7511
|
if (response.output == null) {
|
|
7559
|
-
const detail =
|
|
7512
|
+
const detail = response.incomplete_details?.reason;
|
|
7560
7513
|
throw new APICallError2({
|
|
7561
7514
|
message: detail ? `Responses API returned no output (${detail})` : "Responses API returned no output",
|
|
7562
7515
|
url,
|
|
@@ -7569,9 +7522,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7569
7522
|
}
|
|
7570
7523
|
const content = [];
|
|
7571
7524
|
const logprobs = [];
|
|
7572
|
-
const functionTools =
|
|
7525
|
+
const functionTools = options.tools?.filter(
|
|
7573
7526
|
(tool) => tool.type === "function"
|
|
7574
|
-
)
|
|
7527
|
+
) ?? [];
|
|
7575
7528
|
let hasFunctionCall = false;
|
|
7576
7529
|
const hostedToolSearchCallIds = [];
|
|
7577
7530
|
for (const part of response.output) {
|
|
@@ -7587,7 +7540,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7587
7540
|
providerMetadata: {
|
|
7588
7541
|
[providerOptionsName]: {
|
|
7589
7542
|
itemId: part.id,
|
|
7590
|
-
reasoningEncryptedContent:
|
|
7543
|
+
reasoningEncryptedContent: part.encrypted_content ?? null
|
|
7591
7544
|
}
|
|
7592
7545
|
}
|
|
7593
7546
|
});
|
|
@@ -7613,7 +7566,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7613
7566
|
break;
|
|
7614
7567
|
}
|
|
7615
7568
|
case "tool_search_call": {
|
|
7616
|
-
const toolCallId =
|
|
7569
|
+
const toolCallId = part.call_id ?? part.id;
|
|
7617
7570
|
const isHosted = part.execution === "server";
|
|
7618
7571
|
if (isHosted) {
|
|
7619
7572
|
hostedToolSearchCallIds.push(toolCallId);
|
|
@@ -7636,7 +7589,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7636
7589
|
break;
|
|
7637
7590
|
}
|
|
7638
7591
|
case "tool_search_output": {
|
|
7639
|
-
const toolCallId =
|
|
7592
|
+
const toolCallId = part.call_id ?? hostedToolSearchCallIds.shift() ?? part.id;
|
|
7640
7593
|
content.push({
|
|
7641
7594
|
type: "tool-result",
|
|
7642
7595
|
toolCallId,
|
|
@@ -7707,7 +7660,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7707
7660
|
}
|
|
7708
7661
|
case "message": {
|
|
7709
7662
|
for (const contentPart of part.content) {
|
|
7710
|
-
if (
|
|
7663
|
+
if (options.providerOptions?.[providerOptionsName]?.logprobs && contentPart.logprobs) {
|
|
7711
7664
|
logprobs.push(contentPart.logprobs);
|
|
7712
7665
|
}
|
|
7713
7666
|
const providerMetadata2 = {
|
|
@@ -7729,7 +7682,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7729
7682
|
content.push({
|
|
7730
7683
|
type: "source",
|
|
7731
7684
|
sourceType: "url",
|
|
7732
|
-
id:
|
|
7685
|
+
id: this.config.generateId?.() ?? generateId2(),
|
|
7733
7686
|
url: annotation.url,
|
|
7734
7687
|
title: annotation.title
|
|
7735
7688
|
});
|
|
@@ -7737,7 +7690,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7737
7690
|
content.push({
|
|
7738
7691
|
type: "source",
|
|
7739
7692
|
sourceType: "document",
|
|
7740
|
-
id:
|
|
7693
|
+
id: this.config.generateId?.() ?? generateId2(),
|
|
7741
7694
|
mediaType: "text/plain",
|
|
7742
7695
|
title: annotation.filename,
|
|
7743
7696
|
filename: annotation.filename,
|
|
@@ -7753,7 +7706,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7753
7706
|
content.push({
|
|
7754
7707
|
type: "source",
|
|
7755
7708
|
sourceType: "document",
|
|
7756
|
-
id:
|
|
7709
|
+
id: this.config.generateId?.() ?? generateId2(),
|
|
7757
7710
|
mediaType: "text/plain",
|
|
7758
7711
|
title: annotation.filename,
|
|
7759
7712
|
filename: annotation.filename,
|
|
@@ -7769,7 +7722,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7769
7722
|
content.push({
|
|
7770
7723
|
type: "source",
|
|
7771
7724
|
sourceType: "document",
|
|
7772
|
-
id:
|
|
7725
|
+
id: this.config.generateId?.() ?? generateId2(),
|
|
7773
7726
|
mediaType: "application/octet-stream",
|
|
7774
7727
|
title: annotation.file_id,
|
|
7775
7728
|
filename: annotation.file_id,
|
|
@@ -7884,7 +7837,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7884
7837
|
type: "tool-call",
|
|
7885
7838
|
toolCallId: part.id,
|
|
7886
7839
|
toolName: toolNameMapping.toCustomToolName(
|
|
7887
|
-
webSearchToolName
|
|
7840
|
+
webSearchToolName ?? "web_search"
|
|
7888
7841
|
),
|
|
7889
7842
|
input: JSON.stringify({}),
|
|
7890
7843
|
providerExecuted: true
|
|
@@ -7893,14 +7846,14 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7893
7846
|
type: "tool-result",
|
|
7894
7847
|
toolCallId: part.id,
|
|
7895
7848
|
toolName: toolNameMapping.toCustomToolName(
|
|
7896
|
-
webSearchToolName
|
|
7849
|
+
webSearchToolName ?? "web_search"
|
|
7897
7850
|
),
|
|
7898
7851
|
result: mapWebSearchOutput(part.action)
|
|
7899
7852
|
});
|
|
7900
7853
|
break;
|
|
7901
7854
|
}
|
|
7902
7855
|
case "mcp_call": {
|
|
7903
|
-
const toolCallId = part.approval_request_id != null ?
|
|
7856
|
+
const toolCallId = part.approval_request_id != null ? approvalRequestIdToDummyToolCallIdFromPrompt[part.approval_request_id] ?? part.id : part.id;
|
|
7904
7857
|
const toolName = `mcp.${part.name}`;
|
|
7905
7858
|
content.push({
|
|
7906
7859
|
type: "tool-call",
|
|
@@ -7934,8 +7887,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7934
7887
|
break;
|
|
7935
7888
|
}
|
|
7936
7889
|
case "mcp_approval_request": {
|
|
7937
|
-
const approvalRequestId =
|
|
7938
|
-
const dummyToolCallId =
|
|
7890
|
+
const approvalRequestId = part.approval_request_id ?? part.id;
|
|
7891
|
+
const dummyToolCallId = this.config.generateId?.() ?? generateId2();
|
|
7939
7892
|
const toolName = `mcp.${part.name}`;
|
|
7940
7893
|
content.push({
|
|
7941
7894
|
type: "tool-call",
|
|
@@ -8001,13 +7954,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8001
7954
|
toolName: toolNameMapping.toCustomToolName("file_search"),
|
|
8002
7955
|
result: {
|
|
8003
7956
|
queries: part.queries,
|
|
8004
|
-
results:
|
|
7957
|
+
results: part.results?.map((result) => ({
|
|
8005
7958
|
attributes: result.attributes,
|
|
8006
7959
|
fileId: result.file_id,
|
|
8007
7960
|
filename: result.filename,
|
|
8008
7961
|
score: result.score,
|
|
8009
7962
|
text: result.text
|
|
8010
|
-
}))
|
|
7963
|
+
})) ?? null
|
|
8011
7964
|
}
|
|
8012
7965
|
});
|
|
8013
7966
|
break;
|
|
@@ -8072,7 +8025,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8072
8025
|
responseId: response.id,
|
|
8073
8026
|
...logprobs.length > 0 ? { logprobs } : {},
|
|
8074
8027
|
...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
|
|
8075
|
-
...
|
|
8028
|
+
...response.reasoning?.context != null ? { reasoningContext: response.reasoning.context } : {}
|
|
8076
8029
|
}
|
|
8077
8030
|
};
|
|
8078
8031
|
const usage = response.usage;
|
|
@@ -8080,10 +8033,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8080
8033
|
content,
|
|
8081
8034
|
finishReason: {
|
|
8082
8035
|
unified: mapOpenAIResponseFinishReason({
|
|
8083
|
-
finishReason:
|
|
8036
|
+
finishReason: response.incomplete_details?.reason,
|
|
8084
8037
|
hasFunctionCall
|
|
8085
8038
|
}),
|
|
8086
|
-
raw:
|
|
8039
|
+
raw: response.incomplete_details?.reason ?? void 0
|
|
8087
8040
|
},
|
|
8088
8041
|
usage: convertOpenAIResponsesUsage(usage),
|
|
8089
8042
|
request: { body },
|
|
@@ -8099,7 +8052,6 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8099
8052
|
};
|
|
8100
8053
|
}
|
|
8101
8054
|
async doStream(options) {
|
|
8102
|
-
var _a2, _b, _c, _d;
|
|
8103
8055
|
const {
|
|
8104
8056
|
args: body,
|
|
8105
8057
|
warnings,
|
|
@@ -8115,7 +8067,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8115
8067
|
});
|
|
8116
8068
|
const { responseHeaders, value: response } = await postJsonToApi5({
|
|
8117
8069
|
url,
|
|
8118
|
-
headers: combineHeaders6(
|
|
8070
|
+
headers: combineHeaders6(this.config.headers?.(), options.headers),
|
|
8119
8071
|
body: {
|
|
8120
8072
|
...body,
|
|
8121
8073
|
stream: true
|
|
@@ -8138,9 +8090,9 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8138
8090
|
});
|
|
8139
8091
|
const self = this;
|
|
8140
8092
|
const approvalRequestIdToDummyToolCallIdFromPrompt = extractApprovalRequestIdToToolCallIdMapping(options.prompt);
|
|
8141
|
-
const functionTools =
|
|
8093
|
+
const functionTools = options.tools?.filter(
|
|
8142
8094
|
(tool) => tool.type === "function"
|
|
8143
|
-
)
|
|
8095
|
+
) ?? [];
|
|
8144
8096
|
const approvalRequestIdToDummyToolCallIdFromStream = /* @__PURE__ */ new Map();
|
|
8145
8097
|
let finishReason = {
|
|
8146
8098
|
unified: "other",
|
|
@@ -8158,10 +8110,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8158
8110
|
const resolveOutputItemId = ({
|
|
8159
8111
|
itemId,
|
|
8160
8112
|
outputIndex
|
|
8161
|
-
}) =>
|
|
8162
|
-
var _a3;
|
|
8163
|
-
return outputIndex == null ? itemId : (_a3 = activeOutputItemIds[outputIndex]) != null ? _a3 : itemId;
|
|
8164
|
-
};
|
|
8113
|
+
}) => outputIndex == null ? itemId : activeOutputItemIds[outputIndex] ?? itemId;
|
|
8165
8114
|
let serviceTier;
|
|
8166
8115
|
let reasoningContext;
|
|
8167
8116
|
const hostedToolSearchCallIds = [];
|
|
@@ -8173,7 +8122,6 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8173
8122
|
controller.enqueue({ type: "stream-start", warnings });
|
|
8174
8123
|
},
|
|
8175
8124
|
transform(chunk, controller) {
|
|
8176
|
-
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, _S;
|
|
8177
8125
|
if (options.includeRawChunks) {
|
|
8178
8126
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
8179
8127
|
}
|
|
@@ -8228,7 +8176,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8228
8176
|
} else if (value.item.type === "web_search_call") {
|
|
8229
8177
|
ongoingToolCalls[value.output_index] = {
|
|
8230
8178
|
toolName: toolNameMapping.toCustomToolName(
|
|
8231
|
-
webSearchToolName
|
|
8179
|
+
webSearchToolName ?? "web_search"
|
|
8232
8180
|
),
|
|
8233
8181
|
toolCallId: value.item.id
|
|
8234
8182
|
};
|
|
@@ -8236,7 +8184,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8236
8184
|
type: "tool-input-start",
|
|
8237
8185
|
id: value.item.id,
|
|
8238
8186
|
toolName: toolNameMapping.toCustomToolName(
|
|
8239
|
-
webSearchToolName
|
|
8187
|
+
webSearchToolName ?? "web_search"
|
|
8240
8188
|
),
|
|
8241
8189
|
providerExecuted: true
|
|
8242
8190
|
});
|
|
@@ -8248,13 +8196,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8248
8196
|
type: "tool-call",
|
|
8249
8197
|
toolCallId: value.item.id,
|
|
8250
8198
|
toolName: toolNameMapping.toCustomToolName(
|
|
8251
|
-
webSearchToolName
|
|
8199
|
+
webSearchToolName ?? "web_search"
|
|
8252
8200
|
),
|
|
8253
8201
|
input: JSON.stringify({}),
|
|
8254
8202
|
providerExecuted: true
|
|
8255
8203
|
});
|
|
8256
8204
|
} else if (value.item.type === "computer_call") {
|
|
8257
|
-
const toolCallId =
|
|
8205
|
+
const toolCallId = value.item.call_id ?? value.item.id;
|
|
8258
8206
|
ongoingToolCalls[value.output_index] = {
|
|
8259
8207
|
toolName: toolNameMapping.toCustomToolName("computer"),
|
|
8260
8208
|
toolCallId
|
|
@@ -8306,7 +8254,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8306
8254
|
ongoingToolCalls[value.output_index] = {
|
|
8307
8255
|
toolName,
|
|
8308
8256
|
toolCallId,
|
|
8309
|
-
toolSearchExecution:
|
|
8257
|
+
toolSearchExecution: value.item.execution ?? "server"
|
|
8310
8258
|
};
|
|
8311
8259
|
if (isHosted) {
|
|
8312
8260
|
controller.enqueue({
|
|
@@ -8364,7 +8312,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8364
8312
|
} else if (value.item.type === "message") {
|
|
8365
8313
|
activeOutputItemIds[value.output_index] = value.item.id;
|
|
8366
8314
|
ongoingAnnotations.splice(0);
|
|
8367
|
-
activeMessagePhase =
|
|
8315
|
+
activeMessagePhase = value.item.phase ?? void 0;
|
|
8368
8316
|
controller.enqueue({
|
|
8369
8317
|
type: "text-start",
|
|
8370
8318
|
id: value.item.id,
|
|
@@ -8389,7 +8337,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8389
8337
|
providerMetadata: {
|
|
8390
8338
|
[providerOptionsName]: {
|
|
8391
8339
|
itemId: value.item.id,
|
|
8392
|
-
reasoningEncryptedContent:
|
|
8340
|
+
reasoningEncryptedContent: value.item.encrypted_content ?? null
|
|
8393
8341
|
}
|
|
8394
8342
|
}
|
|
8395
8343
|
});
|
|
@@ -8400,7 +8348,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8400
8348
|
itemId: value.item.id,
|
|
8401
8349
|
outputIndex: value.output_index
|
|
8402
8350
|
});
|
|
8403
|
-
const phase =
|
|
8351
|
+
const phase = value.item.phase ?? activeMessagePhase;
|
|
8404
8352
|
activeMessagePhase = void 0;
|
|
8405
8353
|
controller.enqueue({
|
|
8406
8354
|
type: "text-end",
|
|
@@ -8421,19 +8369,18 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8421
8369
|
const ongoingToolCall = ongoingToolCalls[value.output_index];
|
|
8422
8370
|
ongoingToolCalls[value.output_index] = void 0;
|
|
8423
8371
|
hasFunctionCall = true;
|
|
8424
|
-
const suppressInputStreaming =
|
|
8372
|
+
const suppressInputStreaming = ongoingToolCall?.suppressInputStreaming ?? isUndeclaredParallelToolCall({
|
|
8425
8373
|
toolName: item.name,
|
|
8426
8374
|
tools: functionTools
|
|
8427
8375
|
});
|
|
8428
8376
|
const enqueueUnexpandedToolCall = () => {
|
|
8429
|
-
var _a4;
|
|
8430
8377
|
if (suppressInputStreaming) {
|
|
8431
8378
|
controller.enqueue({
|
|
8432
8379
|
type: "tool-input-start",
|
|
8433
8380
|
id: item.call_id,
|
|
8434
8381
|
toolName: item.name
|
|
8435
8382
|
});
|
|
8436
|
-
const bufferedInputDeltas =
|
|
8383
|
+
const bufferedInputDeltas = ongoingToolCall?.bufferedInputDeltas ?? [];
|
|
8437
8384
|
if (bufferedInputDeltas.length > 0) {
|
|
8438
8385
|
for (const delta of bufferedInputDeltas) {
|
|
8439
8386
|
controller.enqueue({
|
|
@@ -8469,7 +8416,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8469
8416
|
providerMetadata: {
|
|
8470
8417
|
[providerOptionsName]: {
|
|
8471
8418
|
itemId: item.id,
|
|
8472
|
-
...item.async != null ? { async: item.async } :
|
|
8419
|
+
...item.async != null ? { async: item.async } : ongoingToolCall?.async != null ? { async: ongoingToolCall.async } : {},
|
|
8473
8420
|
...item.namespace != null && {
|
|
8474
8421
|
namespace: item.namespace
|
|
8475
8422
|
},
|
|
@@ -8573,7 +8520,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8573
8520
|
providerMetadata: {
|
|
8574
8521
|
[providerOptionsName]: {
|
|
8575
8522
|
itemId: value.item.id,
|
|
8576
|
-
...value.item.async != null ? { async: value.item.async } :
|
|
8523
|
+
...value.item.async != null ? { async: value.item.async } : ongoingToolCall?.async != null ? { async: ongoingToolCall.async } : {}
|
|
8577
8524
|
}
|
|
8578
8525
|
}
|
|
8579
8526
|
});
|
|
@@ -8583,7 +8530,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8583
8530
|
type: "tool-result",
|
|
8584
8531
|
toolCallId: value.item.id,
|
|
8585
8532
|
toolName: toolNameMapping.toCustomToolName(
|
|
8586
|
-
webSearchToolName
|
|
8533
|
+
webSearchToolName ?? "web_search"
|
|
8587
8534
|
),
|
|
8588
8535
|
result: mapWebSearchOutput(value.item.action)
|
|
8589
8536
|
});
|
|
@@ -8643,13 +8590,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8643
8590
|
toolName: toolNameMapping.toCustomToolName("file_search"),
|
|
8644
8591
|
result: {
|
|
8645
8592
|
queries: value.item.queries,
|
|
8646
|
-
results:
|
|
8593
|
+
results: value.item.results?.map((result2) => ({
|
|
8647
8594
|
attributes: result2.attributes,
|
|
8648
8595
|
fileId: result2.file_id,
|
|
8649
8596
|
filename: result2.filename,
|
|
8650
8597
|
score: result2.score,
|
|
8651
8598
|
text: result2.text
|
|
8652
|
-
}))
|
|
8599
|
+
})) ?? null
|
|
8653
8600
|
}
|
|
8654
8601
|
});
|
|
8655
8602
|
} else if (value.item.type === "code_interpreter_call") {
|
|
@@ -8675,7 +8622,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8675
8622
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
8676
8623
|
const isHosted = value.item.execution === "server";
|
|
8677
8624
|
if (toolCall != null) {
|
|
8678
|
-
const toolCallId = isHosted ? toolCall.toolCallId :
|
|
8625
|
+
const toolCallId = isHosted ? toolCall.toolCallId : value.item.call_id ?? value.item.id;
|
|
8679
8626
|
if (isHosted) {
|
|
8680
8627
|
hostedToolSearchCallIds.push(toolCallId);
|
|
8681
8628
|
} else {
|
|
@@ -8707,7 +8654,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8707
8654
|
}
|
|
8708
8655
|
ongoingToolCalls[value.output_index] = void 0;
|
|
8709
8656
|
} else if (value.item.type === "tool_search_output") {
|
|
8710
|
-
const toolCallId =
|
|
8657
|
+
const toolCallId = value.item.call_id ?? hostedToolSearchCallIds.shift() ?? value.item.id;
|
|
8711
8658
|
controller.enqueue({
|
|
8712
8659
|
type: "tool-result",
|
|
8713
8660
|
toolCallId,
|
|
@@ -8723,10 +8670,10 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8723
8670
|
});
|
|
8724
8671
|
} else if (value.item.type === "mcp_call") {
|
|
8725
8672
|
ongoingToolCalls[value.output_index] = void 0;
|
|
8726
|
-
const approvalRequestId =
|
|
8727
|
-
const aliasedToolCallId = approvalRequestId != null ?
|
|
8673
|
+
const approvalRequestId = value.item.approval_request_id ?? void 0;
|
|
8674
|
+
const aliasedToolCallId = approvalRequestId != null ? approvalRequestIdToDummyToolCallIdFromStream.get(
|
|
8728
8675
|
approvalRequestId
|
|
8729
|
-
)
|
|
8676
|
+
) ?? approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId] ?? value.item.id : value.item.id;
|
|
8730
8677
|
const toolName = `mcp.${value.item.name}`;
|
|
8731
8678
|
controller.enqueue({
|
|
8732
8679
|
type: "tool-call",
|
|
@@ -8758,7 +8705,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8758
8705
|
ongoingToolCalls[value.output_index] = void 0;
|
|
8759
8706
|
} else if (value.item.type === "apply_patch_call") {
|
|
8760
8707
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
8761
|
-
if (
|
|
8708
|
+
if (toolCall?.applyPatch && !toolCall.applyPatch.endEmitted && value.item.operation.type !== "delete_file") {
|
|
8762
8709
|
if (!toolCall.applyPatch.hasDiff) {
|
|
8763
8710
|
controller.enqueue({
|
|
8764
8711
|
type: "tool-input-delta",
|
|
@@ -8797,8 +8744,8 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8797
8744
|
ongoingToolCalls[value.output_index] = void 0;
|
|
8798
8745
|
} else if (value.item.type === "mcp_approval_request") {
|
|
8799
8746
|
ongoingToolCalls[value.output_index] = void 0;
|
|
8800
|
-
const dummyToolCallId =
|
|
8801
|
-
const approvalRequestId =
|
|
8747
|
+
const dummyToolCallId = self.config.generateId?.() ?? generateId2();
|
|
8748
|
+
const approvalRequestId = value.item.approval_request_id ?? value.item.id;
|
|
8802
8749
|
approvalRequestIdToDummyToolCallIdFromStream.set(
|
|
8803
8750
|
approvalRequestId,
|
|
8804
8751
|
dummyToolCallId
|
|
@@ -8892,7 +8839,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8892
8839
|
providerMetadata: {
|
|
8893
8840
|
[providerOptionsName]: {
|
|
8894
8841
|
itemId,
|
|
8895
|
-
reasoningEncryptedContent:
|
|
8842
|
+
reasoningEncryptedContent: value.item.encrypted_content ?? null
|
|
8896
8843
|
}
|
|
8897
8844
|
}
|
|
8898
8845
|
});
|
|
@@ -8917,7 +8864,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8917
8864
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
8918
8865
|
if (toolCall != null) {
|
|
8919
8866
|
if (toolCall.suppressInputStreaming) {
|
|
8920
|
-
|
|
8867
|
+
toolCall.bufferedInputDeltas?.push(value.delta);
|
|
8921
8868
|
} else {
|
|
8922
8869
|
controller.enqueue({
|
|
8923
8870
|
type: "tool-input-delta",
|
|
@@ -8937,7 +8884,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8937
8884
|
}
|
|
8938
8885
|
} else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
|
|
8939
8886
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
8940
|
-
if (toolCall
|
|
8887
|
+
if (toolCall?.applyPatch) {
|
|
8941
8888
|
controller.enqueue({
|
|
8942
8889
|
type: "tool-input-delta",
|
|
8943
8890
|
id: toolCall.toolCallId,
|
|
@@ -8947,7 +8894,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
8947
8894
|
}
|
|
8948
8895
|
} else if (isResponseApplyPatchCallOperationDiffDoneChunk(value)) {
|
|
8949
8896
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
8950
|
-
if (
|
|
8897
|
+
if (toolCall?.applyPatch && !toolCall.applyPatch.endEmitted) {
|
|
8951
8898
|
if (!toolCall.applyPatch.hasDiff) {
|
|
8952
8899
|
controller.enqueue({
|
|
8953
8900
|
type: "tool-input-delta",
|
|
@@ -9027,7 +8974,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
9027
8974
|
id: itemId,
|
|
9028
8975
|
delta: value.delta
|
|
9029
8976
|
});
|
|
9030
|
-
if (
|
|
8977
|
+
if (options.providerOptions?.[providerOptionsName]?.logprobs && value.logprobs) {
|
|
9031
8978
|
logprobs.push(value.logprobs);
|
|
9032
8979
|
}
|
|
9033
8980
|
} else if (value.type === "response.reasoning_summary_part.added") {
|
|
@@ -9061,7 +9008,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
9061
9008
|
providerMetadata: {
|
|
9062
9009
|
[providerOptionsName]: {
|
|
9063
9010
|
itemId,
|
|
9064
|
-
reasoningEncryptedContent:
|
|
9011
|
+
reasoningEncryptedContent: activeReasoningPart.encryptedContent ?? null
|
|
9065
9012
|
}
|
|
9066
9013
|
}
|
|
9067
9014
|
});
|
|
@@ -9108,30 +9055,30 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
9108
9055
|
if (!encounteredStreamError) {
|
|
9109
9056
|
finishReason = {
|
|
9110
9057
|
unified: mapOpenAIResponseFinishReason({
|
|
9111
|
-
finishReason:
|
|
9058
|
+
finishReason: value.response.incomplete_details?.reason,
|
|
9112
9059
|
hasFunctionCall
|
|
9113
9060
|
}),
|
|
9114
|
-
raw:
|
|
9061
|
+
raw: value.response.incomplete_details?.reason ?? void 0
|
|
9115
9062
|
};
|
|
9116
9063
|
}
|
|
9117
|
-
usage =
|
|
9064
|
+
usage = value.response.usage ?? void 0;
|
|
9118
9065
|
if (typeof value.response.service_tier === "string") {
|
|
9119
9066
|
serviceTier = value.response.service_tier;
|
|
9120
9067
|
}
|
|
9121
|
-
if (
|
|
9068
|
+
if (value.response.reasoning?.context != null) {
|
|
9122
9069
|
reasoningContext = value.response.reasoning.context;
|
|
9123
9070
|
}
|
|
9124
9071
|
} else if (isResponseFailedChunk(value)) {
|
|
9125
|
-
const incompleteReason =
|
|
9072
|
+
const incompleteReason = value.response.incomplete_details?.reason;
|
|
9126
9073
|
finishReason = {
|
|
9127
9074
|
unified: incompleteReason ? mapOpenAIResponseFinishReason({
|
|
9128
9075
|
finishReason: incompleteReason,
|
|
9129
9076
|
hasFunctionCall
|
|
9130
9077
|
}) : "error",
|
|
9131
|
-
raw: incompleteReason
|
|
9078
|
+
raw: incompleteReason ?? "error"
|
|
9132
9079
|
};
|
|
9133
|
-
usage =
|
|
9134
|
-
if (
|
|
9080
|
+
usage = value.response.usage ?? void 0;
|
|
9081
|
+
if (value.response.reasoning?.context != null) {
|
|
9135
9082
|
reasoningContext = value.response.reasoning.context;
|
|
9136
9083
|
}
|
|
9137
9084
|
if (!encounteredStreamError && value.response.error != null) {
|
|
@@ -9147,7 +9094,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
9147
9094
|
};
|
|
9148
9095
|
controller.enqueue({
|
|
9149
9096
|
type: "error",
|
|
9150
|
-
error:
|
|
9097
|
+
error: createOpenAIProviderStreamError(error) ?? error
|
|
9151
9098
|
});
|
|
9152
9099
|
}
|
|
9153
9100
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
@@ -9156,7 +9103,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
9156
9103
|
controller.enqueue({
|
|
9157
9104
|
type: "source",
|
|
9158
9105
|
sourceType: "url",
|
|
9159
|
-
id:
|
|
9106
|
+
id: self.config.generateId?.() ?? generateId2(),
|
|
9160
9107
|
url: value.annotation.url,
|
|
9161
9108
|
title: value.annotation.title
|
|
9162
9109
|
});
|
|
@@ -9164,7 +9111,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
9164
9111
|
controller.enqueue({
|
|
9165
9112
|
type: "source",
|
|
9166
9113
|
sourceType: "document",
|
|
9167
|
-
id:
|
|
9114
|
+
id: self.config.generateId?.() ?? generateId2(),
|
|
9168
9115
|
mediaType: "text/plain",
|
|
9169
9116
|
title: value.annotation.filename,
|
|
9170
9117
|
filename: value.annotation.filename,
|
|
@@ -9180,7 +9127,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
9180
9127
|
controller.enqueue({
|
|
9181
9128
|
type: "source",
|
|
9182
9129
|
sourceType: "document",
|
|
9183
|
-
id:
|
|
9130
|
+
id: self.config.generateId?.() ?? generateId2(),
|
|
9184
9131
|
mediaType: "text/plain",
|
|
9185
9132
|
title: value.annotation.filename,
|
|
9186
9133
|
filename: value.annotation.filename,
|
|
@@ -9196,7 +9143,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
9196
9143
|
controller.enqueue({
|
|
9197
9144
|
type: "source",
|
|
9198
9145
|
sourceType: "document",
|
|
9199
|
-
id:
|
|
9146
|
+
id: self.config.generateId?.() ?? generateId2(),
|
|
9200
9147
|
mediaType: "application/octet-stream",
|
|
9201
9148
|
title: value.annotation.file_id,
|
|
9202
9149
|
filename: value.annotation.file_id,
|
|
@@ -9214,14 +9161,13 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
9214
9161
|
finishReason = { unified: "error", raw: "error" };
|
|
9215
9162
|
controller.enqueue({
|
|
9216
9163
|
type: "error",
|
|
9217
|
-
error:
|
|
9164
|
+
error: createOpenAIProviderStreamError(value) ?? value
|
|
9218
9165
|
});
|
|
9219
9166
|
}
|
|
9220
9167
|
},
|
|
9221
9168
|
flush(controller) {
|
|
9222
|
-
var _a3;
|
|
9223
9169
|
for (const toolCall of Object.values(ongoingToolCalls)) {
|
|
9224
|
-
if (!
|
|
9170
|
+
if (!toolCall?.suppressInputStreaming) {
|
|
9225
9171
|
continue;
|
|
9226
9172
|
}
|
|
9227
9173
|
controller.enqueue({
|
|
@@ -9229,7 +9175,7 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
9229
9175
|
id: toolCall.toolCallId,
|
|
9230
9176
|
toolName: toolCall.toolName
|
|
9231
9177
|
});
|
|
9232
|
-
for (const delta of
|
|
9178
|
+
for (const delta of toolCall.bufferedInputDeltas ?? []) {
|
|
9233
9179
|
controller.enqueue({
|
|
9234
9180
|
type: "tool-input-delta",
|
|
9235
9181
|
id: toolCall.toolCallId,
|
|
@@ -9337,7 +9283,6 @@ function isResponseOutputChunk(chunk) {
|
|
|
9337
9283
|
return !(chunk.type === "response.created" || chunk.type === "response.in_progress" || chunk.type === "response.failed" || chunk.type === "error" || chunk.type === "unknown_chunk");
|
|
9338
9284
|
}
|
|
9339
9285
|
function mapWebSearchOutput(action) {
|
|
9340
|
-
var _a2;
|
|
9341
9286
|
if (action == null) {
|
|
9342
9287
|
return {};
|
|
9343
9288
|
}
|
|
@@ -9346,7 +9291,7 @@ function mapWebSearchOutput(action) {
|
|
|
9346
9291
|
return {
|
|
9347
9292
|
action: {
|
|
9348
9293
|
type: "search",
|
|
9349
|
-
query:
|
|
9294
|
+
query: action.query ?? void 0,
|
|
9350
9295
|
...action.queries != null && { queries: action.queries }
|
|
9351
9296
|
},
|
|
9352
9297
|
// include sources when provided by the Responses API (behind include flag)
|
|
@@ -9451,7 +9396,6 @@ var OpenAIBatch = class {
|
|
|
9451
9396
|
this.provider = options.provider;
|
|
9452
9397
|
}
|
|
9453
9398
|
async doStartBatch(options) {
|
|
9454
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
9455
9399
|
assertTextBatchRequests(options.requests);
|
|
9456
9400
|
validateSingleModel(options.requests);
|
|
9457
9401
|
const fileParts = [];
|
|
@@ -9467,7 +9411,7 @@ var OpenAIBatch = class {
|
|
|
9467
9411
|
const batchOptions = await this.parseBatchProviderOptions(
|
|
9468
9412
|
options.providerOptions
|
|
9469
9413
|
);
|
|
9470
|
-
const inputFileExpiresAfterSeconds =
|
|
9414
|
+
const inputFileExpiresAfterSeconds = batchOptions?.inputFileExpiresAfter ?? openaiBatchInputFileDefaultExpiresAfterSeconds;
|
|
9471
9415
|
for (const request of options.requests) {
|
|
9472
9416
|
const preparedRequest = await this.prepareRequest(request);
|
|
9473
9417
|
fileParts.push(
|
|
@@ -9482,7 +9426,7 @@ var OpenAIBatch = class {
|
|
|
9482
9426
|
for (const warning of preparedRequest.warnings) {
|
|
9483
9427
|
warnings.push({ requestId: request.id, warning });
|
|
9484
9428
|
}
|
|
9485
|
-
for (const tool of
|
|
9429
|
+
for (const tool of request.options.tools ?? []) {
|
|
9486
9430
|
if (tool.type === "provider" && !openAIBatchConvertibleProviderToolIds.has(tool.id)) {
|
|
9487
9431
|
warnings.push({
|
|
9488
9432
|
requestId: request.id,
|
|
@@ -9510,7 +9454,7 @@ var OpenAIBatch = class {
|
|
|
9510
9454
|
);
|
|
9511
9455
|
const { value: uploadedFile } = await postToApi({
|
|
9512
9456
|
url: this.getUrl("/files"),
|
|
9513
|
-
headers: combineHeaders7(
|
|
9457
|
+
headers: combineHeaders7(this.options.config.headers?.(), options.headers),
|
|
9514
9458
|
body: {
|
|
9515
9459
|
content: formData,
|
|
9516
9460
|
values: {
|
|
@@ -9533,7 +9477,7 @@ var OpenAIBatch = class {
|
|
|
9533
9477
|
});
|
|
9534
9478
|
const { value: batch } = await postJsonToApi6({
|
|
9535
9479
|
url: this.getUrl("/batches"),
|
|
9536
|
-
headers: combineHeaders7(
|
|
9480
|
+
headers: combineHeaders7(this.options.config.headers?.(), options.headers),
|
|
9537
9481
|
body: {
|
|
9538
9482
|
input_file_id: uploadedFile.id,
|
|
9539
9483
|
endpoint: openaiBatchEndpoint,
|
|
@@ -9580,12 +9524,11 @@ var OpenAIBatch = class {
|
|
|
9580
9524
|
return convertOpenAIBatchStatus(batch);
|
|
9581
9525
|
}
|
|
9582
9526
|
async doCancelBatch(options) {
|
|
9583
|
-
var _a2, _b;
|
|
9584
9527
|
await postJsonToApi6({
|
|
9585
9528
|
url: this.getUrl(
|
|
9586
9529
|
`/batches/${encodeURIComponent(options.batchId)}/cancel`
|
|
9587
9530
|
),
|
|
9588
|
-
headers: combineHeaders7(
|
|
9531
|
+
headers: combineHeaders7(this.options.config.headers?.(), options.headers),
|
|
9589
9532
|
body: {},
|
|
9590
9533
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
9591
9534
|
successfulResponseHandler: createJsonResponseHandler7(
|
|
@@ -9597,7 +9540,6 @@ var OpenAIBatch = class {
|
|
|
9597
9540
|
return {};
|
|
9598
9541
|
}
|
|
9599
9542
|
async doListBatches(options) {
|
|
9600
|
-
var _a2, _b;
|
|
9601
9543
|
const url = new URL(this.getUrl("/batches"));
|
|
9602
9544
|
if (options.limit != null) {
|
|
9603
9545
|
url.searchParams.set("limit", String(options.limit));
|
|
@@ -9607,7 +9549,7 @@ var OpenAIBatch = class {
|
|
|
9607
9549
|
}
|
|
9608
9550
|
const { value: page } = await getFromApi2({
|
|
9609
9551
|
url: url.toString(),
|
|
9610
|
-
headers: combineHeaders7(
|
|
9552
|
+
headers: combineHeaders7(this.options.config.headers?.(), options.headers),
|
|
9611
9553
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
9612
9554
|
successfulResponseHandler: createJsonResponseHandler7(
|
|
9613
9555
|
openaiBatchListResponseSchema
|
|
@@ -9646,10 +9588,9 @@ var OpenAIBatch = class {
|
|
|
9646
9588
|
return convertAsyncIteratorToReadableStream(iterator);
|
|
9647
9589
|
}
|
|
9648
9590
|
async retrieveBatch(options) {
|
|
9649
|
-
var _a2, _b;
|
|
9650
9591
|
const { value: batch } = await getFromApi2({
|
|
9651
9592
|
url: this.getUrl(`/batches/${encodeURIComponent(options.batchId)}`),
|
|
9652
|
-
headers: combineHeaders7(
|
|
9593
|
+
headers: combineHeaders7(this.options.config.headers?.(), options.headers),
|
|
9653
9594
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
9654
9595
|
successfulResponseHandler: createJsonResponseHandler7(
|
|
9655
9596
|
openaiBatchResponseSchema
|
|
@@ -9664,12 +9605,11 @@ var OpenAIBatch = class {
|
|
|
9664
9605
|
fileIds,
|
|
9665
9606
|
options
|
|
9666
9607
|
}) {
|
|
9667
|
-
var _a2, _b;
|
|
9668
9608
|
for (const fileId of fileIds) {
|
|
9669
9609
|
const { value: lines } = await getFromApi2({
|
|
9670
9610
|
url: this.getUrl(`/files/${encodeURIComponent(fileId)}/content`),
|
|
9671
9611
|
headers: combineHeaders7(
|
|
9672
|
-
|
|
9612
|
+
this.options.config.headers?.(),
|
|
9673
9613
|
options.headers
|
|
9674
9614
|
),
|
|
9675
9615
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
@@ -9750,8 +9690,7 @@ var OpenAIBatch = class {
|
|
|
9750
9690
|
}
|
|
9751
9691
|
};
|
|
9752
9692
|
function validateSingleModel(requests) {
|
|
9753
|
-
|
|
9754
|
-
const modelId = (_a2 = requests[0]) == null ? void 0 : _a2.modelId;
|
|
9693
|
+
const modelId = requests[0]?.modelId;
|
|
9755
9694
|
for (const request of requests) {
|
|
9756
9695
|
if (request.modelId !== modelId) {
|
|
9757
9696
|
throw new InvalidArgumentError2({
|
|
@@ -9769,9 +9708,8 @@ var openAIBatchConvertibleProviderToolIds = /* @__PURE__ */ new Set([
|
|
|
9769
9708
|
"openai.web_search_preview"
|
|
9770
9709
|
]);
|
|
9771
9710
|
function convertOpenAIBatchStatus(batch) {
|
|
9772
|
-
var _a2, _b, _c;
|
|
9773
9711
|
const status = mapOpenAIBatchStatus(batch.status);
|
|
9774
|
-
const firstError =
|
|
9712
|
+
const firstError = batch.errors?.data?.[0];
|
|
9775
9713
|
const requestCounts = convertOpenAIRequestCounts(batch.request_counts);
|
|
9776
9714
|
const createdAt = convertUnixTimestamp(batch.created_at);
|
|
9777
9715
|
const expiresAt = convertUnixTimestamp(batch.expires_at);
|
|
@@ -9781,7 +9719,7 @@ function convertOpenAIBatchStatus(batch) {
|
|
|
9781
9719
|
...requestCounts != null ? { requestCounts } : {},
|
|
9782
9720
|
...firstError != null ? {
|
|
9783
9721
|
error: {
|
|
9784
|
-
message:
|
|
9722
|
+
message: firstError.message ?? "OpenAI batch failed.",
|
|
9785
9723
|
...firstError.code != null ? { code: firstError.code } : {}
|
|
9786
9724
|
}
|
|
9787
9725
|
} : {},
|
|
@@ -9806,9 +9744,9 @@ function mapOpenAIBatchStatus(rawStatus) {
|
|
|
9806
9744
|
}
|
|
9807
9745
|
}
|
|
9808
9746
|
function convertOpenAIRequestCounts(counts) {
|
|
9809
|
-
const total = counts
|
|
9810
|
-
const completed = counts
|
|
9811
|
-
const failed = counts
|
|
9747
|
+
const total = counts?.total;
|
|
9748
|
+
const completed = counts?.completed;
|
|
9749
|
+
const failed = counts?.failed;
|
|
9812
9750
|
return normalizeBatchRequestCounts({
|
|
9813
9751
|
total,
|
|
9814
9752
|
pending: total != null && completed != null && failed != null ? total - completed - failed : void 0,
|
|
@@ -9827,7 +9765,6 @@ async function convertOpenAIErrorResponse({
|
|
|
9827
9765
|
body,
|
|
9828
9766
|
statusCode
|
|
9829
9767
|
}) {
|
|
9830
|
-
var _a2;
|
|
9831
9768
|
const result = await safeValidateTypes({
|
|
9832
9769
|
value: body,
|
|
9833
9770
|
schema: openaiErrorDataSchema
|
|
@@ -9840,13 +9777,12 @@ async function convertOpenAIErrorResponse({
|
|
|
9840
9777
|
}
|
|
9841
9778
|
return {
|
|
9842
9779
|
message: result.value.error.message,
|
|
9843
|
-
type:
|
|
9780
|
+
type: result.value.error.type ?? void 0,
|
|
9844
9781
|
code: result.value.error.code != null ? String(result.value.error.code) : void 0,
|
|
9845
9782
|
statusCode
|
|
9846
9783
|
};
|
|
9847
9784
|
}
|
|
9848
9785
|
async function convertOpenAIBatchResult(body) {
|
|
9849
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
9850
9786
|
const validation = await safeValidateTypes({
|
|
9851
9787
|
value: body,
|
|
9852
9788
|
schema: openaiResponsesResponseSchema
|
|
@@ -9872,7 +9808,7 @@ async function convertOpenAIBatchResult(body) {
|
|
|
9872
9808
|
};
|
|
9873
9809
|
}
|
|
9874
9810
|
if (response.output == null) {
|
|
9875
|
-
const detail =
|
|
9811
|
+
const detail = response.incomplete_details?.reason;
|
|
9876
9812
|
return {
|
|
9877
9813
|
success: false,
|
|
9878
9814
|
error: {
|
|
@@ -9895,7 +9831,7 @@ async function convertOpenAIBatchResult(body) {
|
|
|
9895
9831
|
providerMetadata: {
|
|
9896
9832
|
openai: {
|
|
9897
9833
|
itemId: part.id,
|
|
9898
|
-
reasoningEncryptedContent:
|
|
9834
|
+
reasoningEncryptedContent: part.encrypted_content ?? null
|
|
9899
9835
|
}
|
|
9900
9836
|
}
|
|
9901
9837
|
});
|
|
@@ -9971,13 +9907,13 @@ async function convertOpenAIBatchResult(body) {
|
|
|
9971
9907
|
toolName: "file_search",
|
|
9972
9908
|
result: {
|
|
9973
9909
|
queries: part.queries,
|
|
9974
|
-
results:
|
|
9910
|
+
results: part.results?.map((result) => ({
|
|
9975
9911
|
attributes: result.attributes,
|
|
9976
9912
|
fileId: result.file_id,
|
|
9977
9913
|
filename: result.filename,
|
|
9978
9914
|
score: result.score,
|
|
9979
9915
|
text: result.text
|
|
9980
|
-
}))
|
|
9916
|
+
})) ?? null
|
|
9981
9917
|
},
|
|
9982
9918
|
dynamic: true
|
|
9983
9919
|
});
|
|
@@ -10017,7 +9953,7 @@ async function convertOpenAIBatchResult(body) {
|
|
|
10017
9953
|
responseId: response.id,
|
|
10018
9954
|
...logprobs.length > 0 ? { logprobs } : {},
|
|
10019
9955
|
...typeof response.service_tier === "string" ? { serviceTier: response.service_tier } : {},
|
|
10020
|
-
...
|
|
9956
|
+
...response.reasoning?.context != null ? { reasoningContext: response.reasoning.context } : {}
|
|
10021
9957
|
}
|
|
10022
9958
|
};
|
|
10023
9959
|
return {
|
|
@@ -10026,10 +9962,10 @@ async function convertOpenAIBatchResult(body) {
|
|
|
10026
9962
|
content,
|
|
10027
9963
|
finishReason: {
|
|
10028
9964
|
unified: mapOpenAIResponseFinishReason({
|
|
10029
|
-
finishReason:
|
|
9965
|
+
finishReason: response.incomplete_details?.reason,
|
|
10030
9966
|
hasFunctionCall
|
|
10031
9967
|
}),
|
|
10032
|
-
raw:
|
|
9968
|
+
raw: response.incomplete_details?.reason ?? void 0
|
|
10033
9969
|
},
|
|
10034
9970
|
usage: convertOpenAIResponsesUsage(response.usage),
|
|
10035
9971
|
response: {
|
|
@@ -10123,7 +10059,6 @@ var audioFormatSchema = z30.union([
|
|
|
10123
10059
|
})
|
|
10124
10060
|
]);
|
|
10125
10061
|
function buildOpenAILiveSessionConfig(config, modelId, transport = "websocket") {
|
|
10126
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
10127
10062
|
for (const key of Object.keys(config)) {
|
|
10128
10063
|
if (![
|
|
10129
10064
|
"instructions",
|
|
@@ -10137,13 +10072,13 @@ function buildOpenAILiveSessionConfig(config, modelId, transport = "websocket")
|
|
|
10137
10072
|
});
|
|
10138
10073
|
}
|
|
10139
10074
|
}
|
|
10140
|
-
if (z30.object({ delegation: z30.object({ type: z30.literal("responses") }) }).safeParse(
|
|
10075
|
+
if (z30.object({ delegation: z30.object({ type: z30.literal("responses") }) }).safeParse(config.providerOptions?.openai).success) {
|
|
10141
10076
|
throw new UnsupportedFunctionalityError9({
|
|
10142
10077
|
functionality: "OpenAI Live Responses delegation; only client delegation is supported"
|
|
10143
10078
|
});
|
|
10144
10079
|
}
|
|
10145
10080
|
const options = openaiRealtimeModelLiveOptionsSchema.parse(
|
|
10146
|
-
|
|
10081
|
+
config.providerOptions?.openai ?? {}
|
|
10147
10082
|
);
|
|
10148
10083
|
if (options.client !== void 0 && transport !== "webrtc") {
|
|
10149
10084
|
throw new UnsupportedFunctionalityError9({
|
|
@@ -10174,9 +10109,9 @@ function buildOpenAILiveSessionConfig(config, modelId, transport = "websocket")
|
|
|
10174
10109
|
...config.instructions !== void 0 ? { instructions: config.instructions } : {},
|
|
10175
10110
|
audio: {
|
|
10176
10111
|
...transport === "websocket" ? {
|
|
10177
|
-
format:
|
|
10112
|
+
format: inputFormat ?? outputFormat ?? { type: "audio/pcm", rate: 24e3 }
|
|
10178
10113
|
} : {},
|
|
10179
|
-
output: { voice:
|
|
10114
|
+
output: { voice: options.voice ?? config.voice ?? "marin" }
|
|
10180
10115
|
},
|
|
10181
10116
|
...options.delegation !== void 0 ? { delegation: options.delegation } : {},
|
|
10182
10117
|
...options.client !== void 0 ? {
|
|
@@ -10300,7 +10235,6 @@ function parseOpenAILiveServerEvent(raw) {
|
|
|
10300
10235
|
return [parseServerEvent(raw)];
|
|
10301
10236
|
}
|
|
10302
10237
|
function parseServerEvent(raw) {
|
|
10303
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
10304
10238
|
const envelope = envelopeSchema.safeParse(raw);
|
|
10305
10239
|
if (envelope.success && !knownTypes.has(envelope.data.type)) {
|
|
10306
10240
|
return { type: "custom", rawType: envelope.data.type, raw };
|
|
@@ -10328,13 +10262,13 @@ function parseServerEvent(raw) {
|
|
|
10328
10262
|
return {
|
|
10329
10263
|
type: "session-started",
|
|
10330
10264
|
sessionId: event.session.id,
|
|
10331
|
-
delegationMode:
|
|
10265
|
+
delegationMode: event.session.delegation?.type === "responses" ? "provider" : "client",
|
|
10332
10266
|
raw
|
|
10333
10267
|
};
|
|
10334
10268
|
case "session.closed":
|
|
10335
10269
|
return {
|
|
10336
10270
|
type: "session-closed",
|
|
10337
|
-
sessionId:
|
|
10271
|
+
sessionId: event.session?.id,
|
|
10338
10272
|
usage: event.usage,
|
|
10339
10273
|
reason: event.reason,
|
|
10340
10274
|
raw
|
|
@@ -10343,7 +10277,7 @@ function parseServerEvent(raw) {
|
|
|
10343
10277
|
return {
|
|
10344
10278
|
type: "session-usage",
|
|
10345
10279
|
usage: event.usage,
|
|
10346
|
-
contextWindowUsageRatio:
|
|
10280
|
+
contextWindowUsageRatio: event.context_window?.usage_ratio,
|
|
10347
10281
|
raw
|
|
10348
10282
|
};
|
|
10349
10283
|
case "session.output_audio.delta":
|
|
@@ -10362,8 +10296,8 @@ function parseServerEvent(raw) {
|
|
|
10362
10296
|
return {
|
|
10363
10297
|
type: "delegation-created",
|
|
10364
10298
|
delegationId: event.delegation.id,
|
|
10365
|
-
target: event.delegation.target === "responses" ? "provider" :
|
|
10366
|
-
offsetMs:
|
|
10299
|
+
target: event.delegation.target === "responses" ? "provider" : event.delegation.target ?? void 0,
|
|
10300
|
+
offsetMs: event.offset_ms ?? void 0,
|
|
10367
10301
|
...event.delegation.response_id != null ? { responseId: event.delegation.response_id } : {},
|
|
10368
10302
|
raw
|
|
10369
10303
|
};
|
|
@@ -10371,15 +10305,15 @@ function parseServerEvent(raw) {
|
|
|
10371
10305
|
return {
|
|
10372
10306
|
type: "error",
|
|
10373
10307
|
message: event.error.message,
|
|
10374
|
-
code:
|
|
10375
|
-
clientEventId:
|
|
10308
|
+
code: event.error.code ?? void 0,
|
|
10309
|
+
clientEventId: event.error.client_event_id ?? void 0,
|
|
10376
10310
|
raw
|
|
10377
10311
|
};
|
|
10378
10312
|
case "session.updated":
|
|
10379
10313
|
return {
|
|
10380
10314
|
type: "command-acknowledged",
|
|
10381
10315
|
command: "session.update",
|
|
10382
|
-
clientEventId:
|
|
10316
|
+
clientEventId: event.client_event_id ?? void 0,
|
|
10383
10317
|
raw
|
|
10384
10318
|
};
|
|
10385
10319
|
case "session.input_audio.muted":
|
|
@@ -10387,7 +10321,7 @@ function parseServerEvent(raw) {
|
|
|
10387
10321
|
return {
|
|
10388
10322
|
type: "command-acknowledged",
|
|
10389
10323
|
command: event.type.slice(0, -1),
|
|
10390
|
-
clientEventId:
|
|
10324
|
+
clientEventId: event.client_event_id ?? void 0,
|
|
10391
10325
|
raw
|
|
10392
10326
|
};
|
|
10393
10327
|
case "session.instructions.appended":
|
|
@@ -10396,13 +10330,12 @@ function parseServerEvent(raw) {
|
|
|
10396
10330
|
return {
|
|
10397
10331
|
type: "command-acknowledged",
|
|
10398
10332
|
command: event.type.slice(0, -2),
|
|
10399
|
-
clientEventId:
|
|
10333
|
+
clientEventId: event.client_event_id ?? void 0,
|
|
10400
10334
|
raw
|
|
10401
10335
|
};
|
|
10402
10336
|
}
|
|
10403
10337
|
}
|
|
10404
10338
|
function serializeOpenAILiveClientEvent(event, modelId) {
|
|
10405
|
-
var _a2, _b, _c;
|
|
10406
10339
|
const eventId = "eventId" in event && event.eventId !== void 0 ? { event_id: event.eventId } : {};
|
|
10407
10340
|
switch (event.type) {
|
|
10408
10341
|
case "session-start":
|
|
@@ -10434,9 +10367,9 @@ function serializeOpenAILiveClientEvent(event, modelId) {
|
|
|
10434
10367
|
}).parse(event);
|
|
10435
10368
|
const options = z31.strictObject({
|
|
10436
10369
|
channel: z31.enum(["instructions", "thinking", "commentary"]).optional()
|
|
10437
|
-
}).parse(
|
|
10370
|
+
}).parse(event.providerOptions?.openai ?? {});
|
|
10438
10371
|
return {
|
|
10439
|
-
type: `session.${
|
|
10372
|
+
type: `session.${options.channel ?? "thinking"}.append`,
|
|
10440
10373
|
content: context.content,
|
|
10441
10374
|
delegation_id: context.delegationId,
|
|
10442
10375
|
...eventId
|
|
@@ -10522,7 +10455,6 @@ var OpenAIRealtimeModelLive = class {
|
|
|
10522
10455
|
|
|
10523
10456
|
// src/realtime/openai-realtime-event-mapper.ts
|
|
10524
10457
|
function parseOpenAIRealtimeServerEvent(raw) {
|
|
10525
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
10526
10458
|
const event = raw;
|
|
10527
10459
|
const type = event.type;
|
|
10528
10460
|
switch (type) {
|
|
@@ -10530,7 +10462,7 @@ function parseOpenAIRealtimeServerEvent(raw) {
|
|
|
10530
10462
|
case "session.created":
|
|
10531
10463
|
return {
|
|
10532
10464
|
type: "session-created",
|
|
10533
|
-
sessionId:
|
|
10465
|
+
sessionId: event.session?.id,
|
|
10534
10466
|
raw
|
|
10535
10467
|
};
|
|
10536
10468
|
case "session.updated":
|
|
@@ -10559,7 +10491,7 @@ function parseOpenAIRealtimeServerEvent(raw) {
|
|
|
10559
10491
|
case "conversation.item.added":
|
|
10560
10492
|
return {
|
|
10561
10493
|
type: "conversation-item-added",
|
|
10562
|
-
itemId:
|
|
10494
|
+
itemId: event.item?.id ?? event.item_id,
|
|
10563
10495
|
item: event.item,
|
|
10564
10496
|
raw
|
|
10565
10497
|
};
|
|
@@ -10567,21 +10499,21 @@ function parseOpenAIRealtimeServerEvent(raw) {
|
|
|
10567
10499
|
return {
|
|
10568
10500
|
type: "input-transcription-completed",
|
|
10569
10501
|
itemId: event.item_id,
|
|
10570
|
-
transcript:
|
|
10502
|
+
transcript: event.transcript ?? "",
|
|
10571
10503
|
raw
|
|
10572
10504
|
};
|
|
10573
10505
|
// ── Response lifecycle ──────────────────────────────────────────
|
|
10574
10506
|
case "response.created":
|
|
10575
10507
|
return {
|
|
10576
10508
|
type: "response-created",
|
|
10577
|
-
responseId:
|
|
10509
|
+
responseId: event.response?.id ?? event.response_id,
|
|
10578
10510
|
raw
|
|
10579
10511
|
};
|
|
10580
10512
|
case "response.done":
|
|
10581
10513
|
return {
|
|
10582
10514
|
type: "response-done",
|
|
10583
|
-
responseId:
|
|
10584
|
-
status:
|
|
10515
|
+
responseId: event.response?.id ?? event.response_id,
|
|
10516
|
+
status: event.response?.status ?? "completed",
|
|
10585
10517
|
raw
|
|
10586
10518
|
};
|
|
10587
10519
|
// ── Output item lifecycle ───────────────────────────────────────
|
|
@@ -10589,14 +10521,14 @@ function parseOpenAIRealtimeServerEvent(raw) {
|
|
|
10589
10521
|
return {
|
|
10590
10522
|
type: "output-item-added",
|
|
10591
10523
|
responseId: event.response_id,
|
|
10592
|
-
itemId:
|
|
10524
|
+
itemId: event.item?.id ?? event.item_id,
|
|
10593
10525
|
raw
|
|
10594
10526
|
};
|
|
10595
10527
|
case "response.output_item.done":
|
|
10596
10528
|
return {
|
|
10597
10529
|
type: "output-item-done",
|
|
10598
10530
|
responseId: event.response_id,
|
|
10599
|
-
itemId:
|
|
10531
|
+
itemId: event.item?.id ?? event.item_id,
|
|
10600
10532
|
raw
|
|
10601
10533
|
};
|
|
10602
10534
|
case "response.content_part.added":
|
|
@@ -10687,9 +10619,9 @@ function parseOpenAIRealtimeServerEvent(raw) {
|
|
|
10687
10619
|
case "error":
|
|
10688
10620
|
return {
|
|
10689
10621
|
type: "error",
|
|
10690
|
-
message:
|
|
10691
|
-
code:
|
|
10692
|
-
clientEventId:
|
|
10622
|
+
message: event.error?.message ?? event.message ?? "Unknown error",
|
|
10623
|
+
code: event.error?.code ?? event.code,
|
|
10624
|
+
clientEventId: event.error?.event_id ?? void 0,
|
|
10693
10625
|
raw
|
|
10694
10626
|
};
|
|
10695
10627
|
// ── Pass-through ────────────────────────────────────────────────
|
|
@@ -10771,7 +10703,6 @@ function serializeOpenAIRealtimeClientEvent(event, modelId) {
|
|
|
10771
10703
|
}
|
|
10772
10704
|
}
|
|
10773
10705
|
function buildOpenAISessionConfig(config, modelId) {
|
|
10774
|
-
var _a2;
|
|
10775
10706
|
const session = {
|
|
10776
10707
|
type: "realtime",
|
|
10777
10708
|
model: modelId
|
|
@@ -10812,7 +10743,7 @@ function buildOpenAISessionConfig(config, modelId) {
|
|
|
10812
10743
|
}
|
|
10813
10744
|
if (config.inputAudioTranscription != null) {
|
|
10814
10745
|
input.transcription = {
|
|
10815
|
-
model:
|
|
10746
|
+
model: config.inputAudioTranscription.model ?? "gpt-realtime-whisper",
|
|
10816
10747
|
...config.inputAudioTranscription.language != null ? { language: config.inputAudioTranscription.language } : {},
|
|
10817
10748
|
...config.inputAudioTranscription.prompt != null ? { prompt: config.inputAudioTranscription.prompt } : {}
|
|
10818
10749
|
};
|
|
@@ -10859,8 +10790,7 @@ var OpenAIRealtimeModel = class {
|
|
|
10859
10790
|
this.config = config;
|
|
10860
10791
|
}
|
|
10861
10792
|
async doCreateClientSecret(options) {
|
|
10862
|
-
|
|
10863
|
-
const fetchFn = (_a2 = this.config.fetch) != null ? _a2 : fetch;
|
|
10793
|
+
const fetchFn = this.config.fetch ?? fetch;
|
|
10864
10794
|
const url = `${this.config.baseURL}/realtime/client_secrets`;
|
|
10865
10795
|
const session = options.sessionConfig != null ? buildOpenAISessionConfig(options.sessionConfig, this.modelId) : { type: "realtime", model: this.modelId };
|
|
10866
10796
|
const response = await fetchFn(url, {
|
|
@@ -11007,7 +10937,6 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
|
|
|
11007
10937
|
language,
|
|
11008
10938
|
providerOptions
|
|
11009
10939
|
}) {
|
|
11010
|
-
var _a2, _b;
|
|
11011
10940
|
const warnings = [];
|
|
11012
10941
|
const openAIOptions = await parseProviderOptions9({
|
|
11013
10942
|
provider: "openai",
|
|
@@ -11035,8 +10964,8 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
|
|
|
11035
10964
|
}
|
|
11036
10965
|
if (openAIOptions) {
|
|
11037
10966
|
const speechModelOptions = {
|
|
11038
|
-
speed:
|
|
11039
|
-
instructions:
|
|
10967
|
+
speed: openAIOptions.speed ?? void 0,
|
|
10968
|
+
instructions: openAIOptions.instructions ?? void 0
|
|
11040
10969
|
};
|
|
11041
10970
|
for (const key in speechModelOptions) {
|
|
11042
10971
|
const value = speechModelOptions[key];
|
|
@@ -11058,8 +10987,7 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
|
|
|
11058
10987
|
};
|
|
11059
10988
|
}
|
|
11060
10989
|
async doGenerate(options) {
|
|
11061
|
-
|
|
11062
|
-
const currentDate = (_c = (_b = (_a2 = this.config._internal) == null ? void 0 : _a2.currentDate) == null ? void 0 : _b.call(_a2)) != null ? _c : /* @__PURE__ */ new Date();
|
|
10990
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
11063
10991
|
const { requestBody, warnings } = await this.getArgs(options);
|
|
11064
10992
|
const {
|
|
11065
10993
|
value: audio,
|
|
@@ -11070,7 +10998,7 @@ var OpenAISpeechModel = class _OpenAISpeechModel {
|
|
|
11070
10998
|
path: "/audio/speech",
|
|
11071
10999
|
modelId: this.modelId
|
|
11072
11000
|
}),
|
|
11073
|
-
headers: combineHeaders8(
|
|
11001
|
+
headers: combineHeaders8(this.config.headers?.(), options.headers),
|
|
11074
11002
|
body: requestBody,
|
|
11075
11003
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
11076
11004
|
successfulResponseHandler: createBinaryResponseHandler(),
|
|
@@ -11308,7 +11236,6 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
11308
11236
|
mediaType,
|
|
11309
11237
|
providerOptions
|
|
11310
11238
|
}) {
|
|
11311
|
-
var _a2, _b;
|
|
11312
11239
|
const warnings = [];
|
|
11313
11240
|
const openAIOptions = await parseProviderOptions10({
|
|
11314
11241
|
provider: "openai",
|
|
@@ -11328,7 +11255,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
11328
11255
|
formData.append("response_format", "verbose_json");
|
|
11329
11256
|
}
|
|
11330
11257
|
const isDiarizationModel = this.modelId === "gpt-4o-transcribe-diarize";
|
|
11331
|
-
const chunkingStrategy =
|
|
11258
|
+
const chunkingStrategy = openAIOptions?.chunkingStrategy ?? (isDiarizationModel ? "auto" : void 0);
|
|
11332
11259
|
if (openAIOptions) {
|
|
11333
11260
|
const isGpt4oTranscribeModel = [
|
|
11334
11261
|
"gpt-4o-transcribe",
|
|
@@ -11341,7 +11268,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
11341
11268
|
// https://platform.openai.com/docs/api-reference/audio/createTranscription#audio_createtranscription-response_format
|
|
11342
11269
|
// prefer verbose_json to get segments for models that support it
|
|
11343
11270
|
...this.modelId !== "whisper-1" && {
|
|
11344
|
-
response_format:
|
|
11271
|
+
response_format: openAIOptions.responseFormat ?? (isDiarizationModel ? "diarized_json" : isGpt4oTranscribeModel ? "json" : "verbose_json")
|
|
11345
11272
|
},
|
|
11346
11273
|
temperature: openAIOptions.temperature,
|
|
11347
11274
|
timestamp_granularities: openAIOptions.timestampGranularities
|
|
@@ -11383,13 +11310,12 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
11383
11310
|
};
|
|
11384
11311
|
}
|
|
11385
11312
|
async doGenerate(options) {
|
|
11386
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
11387
11313
|
if (isRealtimeTranscriptionModelId(this.modelId)) {
|
|
11388
11314
|
throw new UnsupportedFunctionalityError12({
|
|
11389
11315
|
functionality: `non-streaming transcription with ${this.modelId}`
|
|
11390
11316
|
});
|
|
11391
11317
|
}
|
|
11392
|
-
const currentDate =
|
|
11318
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
11393
11319
|
const { formData, warnings } = await this.getArgs(options);
|
|
11394
11320
|
const {
|
|
11395
11321
|
value: response,
|
|
@@ -11400,7 +11326,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
11400
11326
|
path: "/audio/transcriptions",
|
|
11401
11327
|
modelId: this.modelId
|
|
11402
11328
|
}),
|
|
11403
|
-
headers: combineHeaders9(
|
|
11329
|
+
headers: combineHeaders9(this.config.headers?.(), options.headers),
|
|
11404
11330
|
formData,
|
|
11405
11331
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
11406
11332
|
successfulResponseHandler: createJsonResponseHandler9(
|
|
@@ -11410,7 +11336,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
11410
11336
|
fetch: this.config.fetch
|
|
11411
11337
|
});
|
|
11412
11338
|
const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
|
|
11413
|
-
const diarizedSegments =
|
|
11339
|
+
const diarizedSegments = response.segments?.flatMap(
|
|
11414
11340
|
(segment) => "speaker" in segment ? [
|
|
11415
11341
|
{
|
|
11416
11342
|
text: segment.text,
|
|
@@ -11422,17 +11348,17 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
11422
11348
|
);
|
|
11423
11349
|
return {
|
|
11424
11350
|
text: response.text,
|
|
11425
|
-
segments:
|
|
11351
|
+
segments: response.segments?.map((segment) => ({
|
|
11426
11352
|
text: segment.text,
|
|
11427
11353
|
startSecond: segment.start,
|
|
11428
11354
|
endSecond: segment.end
|
|
11429
|
-
}))
|
|
11355
|
+
})) ?? response.words?.map((word) => ({
|
|
11430
11356
|
text: word.word,
|
|
11431
11357
|
startSecond: word.start,
|
|
11432
11358
|
endSecond: word.end
|
|
11433
|
-
}))
|
|
11359
|
+
})) ?? [],
|
|
11434
11360
|
language,
|
|
11435
|
-
durationInSeconds:
|
|
11361
|
+
durationInSeconds: response.duration ?? void 0,
|
|
11436
11362
|
warnings,
|
|
11437
11363
|
response: {
|
|
11438
11364
|
timestamp: currentDate,
|
|
@@ -11450,20 +11376,19 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
11450
11376
|
};
|
|
11451
11377
|
}
|
|
11452
11378
|
async doStream(options) {
|
|
11453
|
-
var _a2, _b, _c, _d, _e, _f, _g;
|
|
11454
11379
|
if (!isRealtimeTranscriptionModelId(this.modelId)) {
|
|
11455
11380
|
throw new UnsupportedFunctionalityError12({
|
|
11456
11381
|
functionality: `streaming transcription with ${this.modelId}`
|
|
11457
11382
|
});
|
|
11458
11383
|
}
|
|
11459
|
-
const currentDate =
|
|
11384
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
11460
11385
|
const openAIOptions = await parseProviderOptions10({
|
|
11461
11386
|
provider: "openai",
|
|
11462
11387
|
providerOptions: options.providerOptions,
|
|
11463
11388
|
schema: openAITranscriptionModelOptions
|
|
11464
11389
|
});
|
|
11465
11390
|
const warnings = [];
|
|
11466
|
-
const rawOpenAIOptions =
|
|
11391
|
+
const rawOpenAIOptions = options.providerOptions?.openai ?? {};
|
|
11467
11392
|
for (const option of [
|
|
11468
11393
|
"include",
|
|
11469
11394
|
"prompt",
|
|
@@ -11478,7 +11403,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
11478
11403
|
});
|
|
11479
11404
|
}
|
|
11480
11405
|
}
|
|
11481
|
-
const headers = combineHeaders9(
|
|
11406
|
+
const headers = combineHeaders9(this.config.headers?.(), options.headers);
|
|
11482
11407
|
const sessionUpdate = buildOpenAIRealtimeTranscriptionSession({
|
|
11483
11408
|
modelId: this.modelId,
|
|
11484
11409
|
inputAudioFormat: options.inputAudioFormat,
|
|
@@ -11500,7 +11425,7 @@ var OpenAITranscriptionModel = class _OpenAITranscriptionModel {
|
|
|
11500
11425
|
),
|
|
11501
11426
|
headers,
|
|
11502
11427
|
sessionUpdate,
|
|
11503
|
-
language: openAIOptions
|
|
11428
|
+
language: openAIOptions?.language,
|
|
11504
11429
|
warnings,
|
|
11505
11430
|
audio: options.audio,
|
|
11506
11431
|
abortSignal: options.abortSignal,
|
|
@@ -11536,7 +11461,7 @@ function createOpenAIRealtimeTranscriptionStream({
|
|
|
11536
11461
|
void audio.cancel().catch(() => {
|
|
11537
11462
|
});
|
|
11538
11463
|
}
|
|
11539
|
-
connection
|
|
11464
|
+
connection?.close(closeCode);
|
|
11540
11465
|
};
|
|
11541
11466
|
const finishWithError = (error) => {
|
|
11542
11467
|
if (finished) return;
|
|
@@ -11595,7 +11520,6 @@ function createOpenAIRealtimeTranscriptionStream({
|
|
|
11595
11520
|
void sendAudio(socket).catch(finishWithError);
|
|
11596
11521
|
},
|
|
11597
11522
|
onMessageText: async (text) => {
|
|
11598
|
-
var _a2, _b, _c, _d;
|
|
11599
11523
|
const parsed = await safeParseJSON2({ text });
|
|
11600
11524
|
if (!parsed.success) return;
|
|
11601
11525
|
const raw = parsed.value;
|
|
@@ -11607,17 +11531,17 @@ function createOpenAIRealtimeTranscriptionStream({
|
|
|
11607
11531
|
controller.enqueue({
|
|
11608
11532
|
type: "transcript-delta",
|
|
11609
11533
|
id: raw.item_id,
|
|
11610
|
-
delta:
|
|
11534
|
+
delta: raw.delta ?? ""
|
|
11611
11535
|
});
|
|
11612
11536
|
break;
|
|
11613
11537
|
}
|
|
11614
11538
|
case "conversation.item.input_audio_transcription.completed": {
|
|
11615
|
-
finish(
|
|
11539
|
+
finish(raw.transcript ?? "", raw.item_id);
|
|
11616
11540
|
break;
|
|
11617
11541
|
}
|
|
11618
11542
|
case "error": {
|
|
11619
11543
|
finishWithError(
|
|
11620
|
-
new Error(
|
|
11544
|
+
new Error(raw.error?.message ?? "OpenAI realtime error")
|
|
11621
11545
|
);
|
|
11622
11546
|
break;
|
|
11623
11547
|
}
|
|
@@ -11646,7 +11570,6 @@ function buildOpenAIRealtimeTranscriptionSession({
|
|
|
11646
11570
|
inputAudioFormat,
|
|
11647
11571
|
providerOptions
|
|
11648
11572
|
}) {
|
|
11649
|
-
var _a2, _b;
|
|
11650
11573
|
return {
|
|
11651
11574
|
type: "session.update",
|
|
11652
11575
|
session: {
|
|
@@ -11659,25 +11582,24 @@ function buildOpenAIRealtimeTranscriptionSession({
|
|
|
11659
11582
|
},
|
|
11660
11583
|
transcription: {
|
|
11661
11584
|
model: modelId,
|
|
11662
|
-
...
|
|
11663
|
-
...
|
|
11585
|
+
...providerOptions?.language != null ? { language: providerOptions.language } : {},
|
|
11586
|
+
...providerOptions?.streaming?.delay != null ? { delay: providerOptions.streaming.delay } : {}
|
|
11664
11587
|
},
|
|
11665
11588
|
turn_detection: null
|
|
11666
11589
|
}
|
|
11667
11590
|
},
|
|
11668
|
-
...
|
|
11591
|
+
...providerOptions?.streaming?.include != null ? { include: providerOptions.streaming.include } : {}
|
|
11669
11592
|
}
|
|
11670
11593
|
};
|
|
11671
11594
|
}
|
|
11672
11595
|
function getOpenAIRealtimeConnection(headers) {
|
|
11673
|
-
var _a2;
|
|
11674
11596
|
let authorization;
|
|
11675
11597
|
for (const [key, value] of Object.entries(headers)) {
|
|
11676
11598
|
if (key.toLowerCase() === "authorization" && value != null) {
|
|
11677
11599
|
authorization = value;
|
|
11678
11600
|
}
|
|
11679
11601
|
}
|
|
11680
|
-
const token =
|
|
11602
|
+
const token = authorization?.match(/^bearer\s+(.+)$/i)?.[1];
|
|
11681
11603
|
if (token == null) {
|
|
11682
11604
|
return { protocols: ["realtime"], headers };
|
|
11683
11605
|
}
|
|
@@ -11738,14 +11660,13 @@ var OpenAISpeechTranslationModel = class _OpenAISpeechTranslationModel {
|
|
|
11738
11660
|
return this.config.provider;
|
|
11739
11661
|
}
|
|
11740
11662
|
async doStream(options) {
|
|
11741
|
-
var _a2, _b, _c, _d, _e;
|
|
11742
11663
|
if (options.targetLanguage == null) {
|
|
11743
11664
|
throw new InvalidArgumentError5({
|
|
11744
11665
|
argument: "targetLanguage",
|
|
11745
11666
|
message: `targetLanguage is required for translation model '${this.modelId}'.`
|
|
11746
11667
|
});
|
|
11747
11668
|
}
|
|
11748
|
-
const currentDate =
|
|
11669
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
11749
11670
|
await parseProviderOptions11({
|
|
11750
11671
|
provider: "openai",
|
|
11751
11672
|
providerOptions: options.providerOptions,
|
|
@@ -11767,7 +11688,7 @@ var OpenAISpeechTranslationModel = class _OpenAISpeechTranslationModel {
|
|
|
11767
11688
|
details: "The OpenAI Realtime translation API always outputs 24kHz 16-bit PCM audio and does not accept an output audio format."
|
|
11768
11689
|
});
|
|
11769
11690
|
}
|
|
11770
|
-
const headers = combineHeaders10(
|
|
11691
|
+
const headers = combineHeaders10(this.config.headers?.(), options.headers);
|
|
11771
11692
|
const sessionUpdate = buildOpenAIRealtimeSpeechTranslationSession({
|
|
11772
11693
|
targetLanguage: options.targetLanguage
|
|
11773
11694
|
});
|
|
@@ -11823,7 +11744,7 @@ function createOpenAIRealtimeSpeechTranslationStream({
|
|
|
11823
11744
|
void audio.cancel().catch(() => {
|
|
11824
11745
|
});
|
|
11825
11746
|
}
|
|
11826
|
-
connection
|
|
11747
|
+
connection?.close(closeCode);
|
|
11827
11748
|
};
|
|
11828
11749
|
const finishWithError = (error) => {
|
|
11829
11750
|
if (finished) return;
|
|
@@ -11891,7 +11812,6 @@ function createOpenAIRealtimeSpeechTranslationStream({
|
|
|
11891
11812
|
void sendAudio(socket).catch(finishWithError);
|
|
11892
11813
|
},
|
|
11893
11814
|
onMessageText: async (text) => {
|
|
11894
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
11895
11815
|
if (finished) return;
|
|
11896
11816
|
const parsed = await safeParseJSON3({ text });
|
|
11897
11817
|
if (!parsed.success) return;
|
|
@@ -11910,18 +11830,18 @@ function createOpenAIRealtimeSpeechTranslationStream({
|
|
|
11910
11830
|
break;
|
|
11911
11831
|
}
|
|
11912
11832
|
case "session.output_transcript.delta": {
|
|
11913
|
-
translationText +=
|
|
11833
|
+
translationText += raw.delta ?? "";
|
|
11914
11834
|
controller.enqueue({
|
|
11915
11835
|
type: "output-text-delta",
|
|
11916
|
-
delta:
|
|
11836
|
+
delta: raw.delta ?? ""
|
|
11917
11837
|
});
|
|
11918
11838
|
break;
|
|
11919
11839
|
}
|
|
11920
11840
|
case "session.input_transcript.delta": {
|
|
11921
|
-
sourceText +=
|
|
11841
|
+
sourceText += raw.delta ?? "";
|
|
11922
11842
|
controller.enqueue({
|
|
11923
11843
|
type: "source-transcript-delta",
|
|
11924
|
-
delta:
|
|
11844
|
+
delta: raw.delta ?? ""
|
|
11925
11845
|
});
|
|
11926
11846
|
break;
|
|
11927
11847
|
}
|
|
@@ -11932,7 +11852,7 @@ function createOpenAIRealtimeSpeechTranslationStream({
|
|
|
11932
11852
|
case "error": {
|
|
11933
11853
|
controller.enqueue({
|
|
11934
11854
|
type: "error",
|
|
11935
|
-
error: new Error(
|
|
11855
|
+
error: new Error(raw.error?.message ?? "OpenAI realtime error")
|
|
11936
11856
|
});
|
|
11937
11857
|
break;
|
|
11938
11858
|
}
|
|
@@ -11945,7 +11865,7 @@ function createOpenAIRealtimeSpeechTranslationStream({
|
|
|
11945
11865
|
if (finished) return;
|
|
11946
11866
|
finishWithError(
|
|
11947
11867
|
new Error(
|
|
11948
|
-
`OpenAI realtime translation WebSocket closed unexpectedly before finishing (code ${code
|
|
11868
|
+
`OpenAI realtime translation WebSocket closed unexpectedly before finishing (code ${code ?? "unknown"}${reason ? `, reason: ${reason}` : ""}).`
|
|
11949
11869
|
)
|
|
11950
11870
|
);
|
|
11951
11871
|
}
|
|
@@ -11987,14 +11907,13 @@ function validateOpenAISpeechTranslationInputAudioFormat(inputAudioFormat) {
|
|
|
11987
11907
|
}
|
|
11988
11908
|
}
|
|
11989
11909
|
function getOpenAIRealtimeConnection2(headers) {
|
|
11990
|
-
var _a2;
|
|
11991
11910
|
let authorization;
|
|
11992
11911
|
for (const [key, value] of Object.entries(headers)) {
|
|
11993
11912
|
if (key.toLowerCase() === "authorization" && value != null) {
|
|
11994
11913
|
authorization = value;
|
|
11995
11914
|
}
|
|
11996
11915
|
}
|
|
11997
|
-
const token =
|
|
11916
|
+
const token = authorization?.match(/^bearer\s+(.+)$/i)?.[1];
|
|
11998
11917
|
if (token == null) {
|
|
11999
11918
|
return { protocols: ["realtime"], headers };
|
|
12000
11919
|
}
|
|
@@ -12093,20 +12012,19 @@ var OpenAISkills = class {
|
|
|
12093
12012
|
};
|
|
12094
12013
|
|
|
12095
12014
|
// src/version.ts
|
|
12096
|
-
var VERSION = true ? "4.0.
|
|
12015
|
+
var VERSION = true ? "4.0.77" : "0.0.0-test";
|
|
12097
12016
|
|
|
12098
12017
|
// src/openai-provider.ts
|
|
12099
12018
|
function createOpenAI(options = {}) {
|
|
12100
|
-
|
|
12101
|
-
const baseURL = (_a2 = withoutTrailingSlash(
|
|
12019
|
+
const baseURL = withoutTrailingSlash(
|
|
12102
12020
|
validateBaseURL(
|
|
12103
12021
|
loadOptionalSetting({
|
|
12104
12022
|
settingValue: options.baseURL,
|
|
12105
12023
|
environmentVariableName: "OPENAI_BASE_URL"
|
|
12106
12024
|
})
|
|
12107
12025
|
)
|
|
12108
|
-
)
|
|
12109
|
-
const providerName =
|
|
12026
|
+
) ?? "https://api.openai.com/v1";
|
|
12027
|
+
const providerName = options.name ?? "openai";
|
|
12110
12028
|
const getHeaders = () => withUserAgentSuffix(
|
|
12111
12029
|
{
|
|
12112
12030
|
Authorization: `Bearer ${loadApiKey({
|