@ai-sdk/openai 2.0.0-canary.1 → 2.0.0-canary.3
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 +24 -0
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +507 -465
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +474 -428
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +67 -2
- package/internal/dist/index.d.ts +67 -2
- package/internal/dist/index.js +498 -462
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +467 -428
- package/internal/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -23,7 +23,6 @@ import { z as z2 } from "zod";
|
|
|
23
23
|
import {
|
|
24
24
|
UnsupportedFunctionalityError
|
|
25
25
|
} from "@ai-sdk/provider";
|
|
26
|
-
import { convertUint8ArrayToBase64 } from "@ai-sdk/provider-utils";
|
|
27
26
|
function convertToOpenAIChatMessages({
|
|
28
27
|
prompt,
|
|
29
28
|
useLegacyFunctionCalling = false,
|
|
@@ -67,55 +66,65 @@ function convertToOpenAIChatMessages({
|
|
|
67
66
|
messages.push({
|
|
68
67
|
role: "user",
|
|
69
68
|
content: content.map((part, index) => {
|
|
70
|
-
var _a, _b, _c
|
|
69
|
+
var _a, _b, _c;
|
|
71
70
|
switch (part.type) {
|
|
72
71
|
case "text": {
|
|
73
72
|
return { type: "text", text: part.text };
|
|
74
73
|
}
|
|
75
|
-
case "image": {
|
|
76
|
-
return {
|
|
77
|
-
type: "image_url",
|
|
78
|
-
image_url: {
|
|
79
|
-
url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${convertUint8ArrayToBase64(part.image)}`,
|
|
80
|
-
// OpenAI specific extension: image detail
|
|
81
|
-
detail: (_c = (_b = part.providerMetadata) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
74
|
case "file": {
|
|
86
|
-
if (part.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
type: "input_audio",
|
|
102
|
-
input_audio: { data: part.data, format: "mp3" }
|
|
103
|
-
};
|
|
75
|
+
if (part.mediaType.startsWith("image/")) {
|
|
76
|
+
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
77
|
+
return {
|
|
78
|
+
type: "image_url",
|
|
79
|
+
image_url: {
|
|
80
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
|
|
81
|
+
// OpenAI specific extension: image detail
|
|
82
|
+
detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
} else if (part.mediaType.startsWith("audio/")) {
|
|
86
|
+
if (part.data instanceof URL) {
|
|
87
|
+
throw new UnsupportedFunctionalityError({
|
|
88
|
+
functionality: "audio file parts with URLs"
|
|
89
|
+
});
|
|
104
90
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
91
|
+
switch (part.mediaType) {
|
|
92
|
+
case "audio/wav": {
|
|
93
|
+
return {
|
|
94
|
+
type: "input_audio",
|
|
95
|
+
input_audio: { data: part.data, format: "wav" }
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
case "audio/mp3":
|
|
99
|
+
case "audio/mpeg": {
|
|
100
|
+
return {
|
|
101
|
+
type: "input_audio",
|
|
102
|
+
input_audio: { data: part.data, format: "mp3" }
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
default: {
|
|
106
|
+
throw new UnsupportedFunctionalityError({
|
|
107
|
+
functionality: `audio content parts with media type ${part.mediaType}`
|
|
108
|
+
});
|
|
109
|
+
}
|
|
113
110
|
}
|
|
114
|
-
|
|
111
|
+
} else if (part.mediaType === "application/pdf") {
|
|
112
|
+
if (part.data instanceof URL) {
|
|
115
113
|
throw new UnsupportedFunctionalityError({
|
|
116
|
-
functionality:
|
|
114
|
+
functionality: "PDF file parts with URLs"
|
|
117
115
|
});
|
|
118
116
|
}
|
|
117
|
+
return {
|
|
118
|
+
type: "file",
|
|
119
|
+
file: {
|
|
120
|
+
filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
|
|
121
|
+
file_data: `data:application/pdf;base64,${part.data}`
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
} else {
|
|
125
|
+
throw new UnsupportedFunctionalityError({
|
|
126
|
+
functionality: `file part media type ${part.mediaType}`
|
|
127
|
+
});
|
|
119
128
|
}
|
|
120
129
|
}
|
|
121
130
|
}
|
|
@@ -259,17 +268,16 @@ import {
|
|
|
259
268
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
|
260
269
|
} from "@ai-sdk/provider";
|
|
261
270
|
function prepareTools({
|
|
262
|
-
|
|
271
|
+
tools,
|
|
272
|
+
toolChoice,
|
|
263
273
|
useLegacyFunctionCalling = false,
|
|
264
274
|
structuredOutputs
|
|
265
275
|
}) {
|
|
266
|
-
|
|
267
|
-
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
|
276
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
268
277
|
const toolWarnings = [];
|
|
269
278
|
if (tools == null) {
|
|
270
|
-
return { tools: void 0,
|
|
279
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
271
280
|
}
|
|
272
|
-
const toolChoice = mode.toolChoice;
|
|
273
281
|
if (useLegacyFunctionCalling) {
|
|
274
282
|
const openaiFunctions = [];
|
|
275
283
|
for (const tool of tools) {
|
|
@@ -329,18 +337,18 @@ function prepareTools({
|
|
|
329
337
|
}
|
|
330
338
|
}
|
|
331
339
|
if (toolChoice == null) {
|
|
332
|
-
return { tools: openaiTools2,
|
|
340
|
+
return { tools: openaiTools2, toolChoice: void 0, toolWarnings };
|
|
333
341
|
}
|
|
334
342
|
const type = toolChoice.type;
|
|
335
343
|
switch (type) {
|
|
336
344
|
case "auto":
|
|
337
345
|
case "none":
|
|
338
346
|
case "required":
|
|
339
|
-
return { tools: openaiTools2,
|
|
347
|
+
return { tools: openaiTools2, toolChoice: type, toolWarnings };
|
|
340
348
|
case "tool":
|
|
341
349
|
return {
|
|
342
350
|
tools: openaiTools2,
|
|
343
|
-
|
|
351
|
+
toolChoice: {
|
|
344
352
|
type: "function",
|
|
345
353
|
function: {
|
|
346
354
|
name: toolChoice.toolName
|
|
@@ -351,7 +359,7 @@ function prepareTools({
|
|
|
351
359
|
default: {
|
|
352
360
|
const _exhaustiveCheck = type;
|
|
353
361
|
throw new UnsupportedFunctionalityError2({
|
|
354
|
-
functionality: `
|
|
362
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
355
363
|
});
|
|
356
364
|
}
|
|
357
365
|
}
|
|
@@ -382,7 +390,6 @@ var OpenAIChatLanguageModel = class {
|
|
|
382
390
|
return !this.settings.downloadImages;
|
|
383
391
|
}
|
|
384
392
|
getArgs({
|
|
385
|
-
mode,
|
|
386
393
|
prompt,
|
|
387
394
|
maxTokens,
|
|
388
395
|
temperature,
|
|
@@ -393,10 +400,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
393
400
|
stopSequences,
|
|
394
401
|
responseFormat,
|
|
395
402
|
seed,
|
|
396
|
-
|
|
403
|
+
tools,
|
|
404
|
+
toolChoice,
|
|
405
|
+
providerOptions
|
|
397
406
|
}) {
|
|
398
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
399
|
-
const type = mode.type;
|
|
407
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
400
408
|
const warnings = [];
|
|
401
409
|
if (topK != null) {
|
|
402
410
|
warnings.push({
|
|
@@ -445,6 +453,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
445
453
|
top_p: topP,
|
|
446
454
|
frequency_penalty: frequencyPenalty,
|
|
447
455
|
presence_penalty: presencePenalty,
|
|
456
|
+
// TODO improve below:
|
|
448
457
|
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? this.supportsStructuredOutputs && responseFormat.schema != null ? {
|
|
449
458
|
type: "json_schema",
|
|
450
459
|
json_schema: {
|
|
@@ -458,11 +467,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
458
467
|
seed,
|
|
459
468
|
// openai specific settings:
|
|
460
469
|
// TODO remove in next major version; we auto-map maxTokens now
|
|
461
|
-
max_completion_tokens: (_b =
|
|
462
|
-
store: (_c =
|
|
463
|
-
metadata: (_d =
|
|
464
|
-
prediction: (_e =
|
|
465
|
-
reasoning_effort: (_g = (_f =
|
|
470
|
+
max_completion_tokens: (_b = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _b.maxCompletionTokens,
|
|
471
|
+
store: (_c = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _c.store,
|
|
472
|
+
metadata: (_d = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _d.metadata,
|
|
473
|
+
prediction: (_e = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _e.prediction,
|
|
474
|
+
reasoning_effort: (_g = (_f = providerOptions == null ? void 0 : providerOptions.openai) == null ? void 0 : _f.reasoningEffort) != null ? _g : this.settings.reasoningEffort,
|
|
466
475
|
// messages:
|
|
467
476
|
messages
|
|
468
477
|
};
|
|
@@ -527,81 +536,28 @@ var OpenAIChatLanguageModel = class {
|
|
|
527
536
|
baseArgs.max_tokens = void 0;
|
|
528
537
|
}
|
|
529
538
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
response_format: this.supportsStructuredOutputs && mode.schema != null ? {
|
|
553
|
-
type: "json_schema",
|
|
554
|
-
json_schema: {
|
|
555
|
-
schema: mode.schema,
|
|
556
|
-
strict: true,
|
|
557
|
-
name: (_h = mode.name) != null ? _h : "response",
|
|
558
|
-
description: mode.description
|
|
559
|
-
}
|
|
560
|
-
} : { type: "json_object" }
|
|
561
|
-
},
|
|
562
|
-
warnings
|
|
563
|
-
};
|
|
564
|
-
}
|
|
565
|
-
case "object-tool": {
|
|
566
|
-
return {
|
|
567
|
-
args: useLegacyFunctionCalling ? {
|
|
568
|
-
...baseArgs,
|
|
569
|
-
function_call: {
|
|
570
|
-
name: mode.tool.name
|
|
571
|
-
},
|
|
572
|
-
functions: [
|
|
573
|
-
{
|
|
574
|
-
name: mode.tool.name,
|
|
575
|
-
description: mode.tool.description,
|
|
576
|
-
parameters: mode.tool.parameters
|
|
577
|
-
}
|
|
578
|
-
]
|
|
579
|
-
} : {
|
|
580
|
-
...baseArgs,
|
|
581
|
-
tool_choice: {
|
|
582
|
-
type: "function",
|
|
583
|
-
function: { name: mode.tool.name }
|
|
584
|
-
},
|
|
585
|
-
tools: [
|
|
586
|
-
{
|
|
587
|
-
type: "function",
|
|
588
|
-
function: {
|
|
589
|
-
name: mode.tool.name,
|
|
590
|
-
description: mode.tool.description,
|
|
591
|
-
parameters: mode.tool.parameters,
|
|
592
|
-
strict: this.supportsStructuredOutputs ? true : void 0
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
]
|
|
596
|
-
},
|
|
597
|
-
warnings
|
|
598
|
-
};
|
|
599
|
-
}
|
|
600
|
-
default: {
|
|
601
|
-
const _exhaustiveCheck = type;
|
|
602
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
539
|
+
const {
|
|
540
|
+
tools: openaiTools2,
|
|
541
|
+
toolChoice: openaiToolChoice,
|
|
542
|
+
functions,
|
|
543
|
+
function_call,
|
|
544
|
+
toolWarnings
|
|
545
|
+
} = prepareTools({
|
|
546
|
+
tools,
|
|
547
|
+
toolChoice,
|
|
548
|
+
useLegacyFunctionCalling,
|
|
549
|
+
structuredOutputs: this.supportsStructuredOutputs
|
|
550
|
+
});
|
|
551
|
+
return {
|
|
552
|
+
args: {
|
|
553
|
+
...baseArgs,
|
|
554
|
+
tools: openaiTools2,
|
|
555
|
+
tool_choice: openaiToolChoice,
|
|
556
|
+
functions,
|
|
557
|
+
function_call
|
|
558
|
+
},
|
|
559
|
+
warnings: [...warnings, ...toolWarnings]
|
|
560
|
+
};
|
|
605
561
|
}
|
|
606
562
|
async doGenerate(options) {
|
|
607
563
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
@@ -1068,9 +1024,6 @@ var reasoningModels = {
|
|
|
1068
1024
|
};
|
|
1069
1025
|
|
|
1070
1026
|
// src/openai-completion-language-model.ts
|
|
1071
|
-
import {
|
|
1072
|
-
UnsupportedFunctionalityError as UnsupportedFunctionalityError5
|
|
1073
|
-
} from "@ai-sdk/provider";
|
|
1074
1027
|
import {
|
|
1075
1028
|
combineHeaders as combineHeaders2,
|
|
1076
1029
|
createEventSourceResponseHandler as createEventSourceResponseHandler2,
|
|
@@ -1114,13 +1067,8 @@ function convertToOpenAICompletionPrompt({
|
|
|
1114
1067
|
case "text": {
|
|
1115
1068
|
return part.text;
|
|
1116
1069
|
}
|
|
1117
|
-
case "image": {
|
|
1118
|
-
throw new UnsupportedFunctionalityError4({
|
|
1119
|
-
functionality: "images"
|
|
1120
|
-
});
|
|
1121
|
-
}
|
|
1122
1070
|
}
|
|
1123
|
-
}).join("");
|
|
1071
|
+
}).filter(Boolean).join("");
|
|
1124
1072
|
text += `${user}:
|
|
1125
1073
|
${userMessage}
|
|
1126
1074
|
|
|
@@ -1193,7 +1141,6 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1193
1141
|
return this.config.provider;
|
|
1194
1142
|
}
|
|
1195
1143
|
getArgs({
|
|
1196
|
-
mode,
|
|
1197
1144
|
inputFormat,
|
|
1198
1145
|
prompt,
|
|
1199
1146
|
maxTokens,
|
|
@@ -1204,16 +1151,19 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1204
1151
|
presencePenalty,
|
|
1205
1152
|
stopSequences: userStopSequences,
|
|
1206
1153
|
responseFormat,
|
|
1154
|
+
tools,
|
|
1155
|
+
toolChoice,
|
|
1207
1156
|
seed
|
|
1208
1157
|
}) {
|
|
1209
|
-
var _a;
|
|
1210
|
-
const type = mode.type;
|
|
1211
1158
|
const warnings = [];
|
|
1212
1159
|
if (topK != null) {
|
|
1213
|
-
warnings.push({
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
});
|
|
1160
|
+
warnings.push({ type: "unsupported-setting", setting: "topK" });
|
|
1161
|
+
}
|
|
1162
|
+
if (tools == null ? void 0 : tools.length) {
|
|
1163
|
+
warnings.push({ type: "unsupported-setting", setting: "tools" });
|
|
1164
|
+
}
|
|
1165
|
+
if (toolChoice != null) {
|
|
1166
|
+
warnings.push({ type: "unsupported-setting", setting: "toolChoice" });
|
|
1217
1167
|
}
|
|
1218
1168
|
if (responseFormat != null && responseFormat.type !== "text") {
|
|
1219
1169
|
warnings.push({
|
|
@@ -1224,56 +1174,30 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1224
1174
|
}
|
|
1225
1175
|
const { prompt: completionPrompt, stopSequences } = convertToOpenAICompletionPrompt({ prompt, inputFormat });
|
|
1226
1176
|
const stop = [...stopSequences != null ? stopSequences : [], ...userStopSequences != null ? userStopSequences : []];
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1177
|
+
return {
|
|
1178
|
+
args: {
|
|
1179
|
+
// model id:
|
|
1180
|
+
model: this.modelId,
|
|
1181
|
+
// model specific settings:
|
|
1182
|
+
echo: this.settings.echo,
|
|
1183
|
+
logit_bias: this.settings.logitBias,
|
|
1184
|
+
logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : void 0 : void 0,
|
|
1185
|
+
suffix: this.settings.suffix,
|
|
1186
|
+
user: this.settings.user,
|
|
1187
|
+
// standardized settings:
|
|
1188
|
+
max_tokens: maxTokens,
|
|
1189
|
+
temperature,
|
|
1190
|
+
top_p: topP,
|
|
1191
|
+
frequency_penalty: frequencyPenalty,
|
|
1192
|
+
presence_penalty: presencePenalty,
|
|
1193
|
+
seed,
|
|
1194
|
+
// prompt:
|
|
1195
|
+
prompt: completionPrompt,
|
|
1196
|
+
// stop sequences:
|
|
1197
|
+
stop: stop.length > 0 ? stop : void 0
|
|
1198
|
+
},
|
|
1199
|
+
warnings
|
|
1247
1200
|
};
|
|
1248
|
-
switch (type) {
|
|
1249
|
-
case "regular": {
|
|
1250
|
-
if ((_a = mode.tools) == null ? void 0 : _a.length) {
|
|
1251
|
-
throw new UnsupportedFunctionalityError5({
|
|
1252
|
-
functionality: "tools"
|
|
1253
|
-
});
|
|
1254
|
-
}
|
|
1255
|
-
if (mode.toolChoice) {
|
|
1256
|
-
throw new UnsupportedFunctionalityError5({
|
|
1257
|
-
functionality: "toolChoice"
|
|
1258
|
-
});
|
|
1259
|
-
}
|
|
1260
|
-
return { args: baseArgs, warnings };
|
|
1261
|
-
}
|
|
1262
|
-
case "object-json": {
|
|
1263
|
-
throw new UnsupportedFunctionalityError5({
|
|
1264
|
-
functionality: "object-json mode"
|
|
1265
|
-
});
|
|
1266
|
-
}
|
|
1267
|
-
case "object-tool": {
|
|
1268
|
-
throw new UnsupportedFunctionalityError5({
|
|
1269
|
-
functionality: "object-tool mode"
|
|
1270
|
-
});
|
|
1271
|
-
}
|
|
1272
|
-
default: {
|
|
1273
|
-
const _exhaustiveCheck = type;
|
|
1274
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
1201
|
}
|
|
1278
1202
|
async doGenerate(options) {
|
|
1279
1203
|
const { args, warnings } = this.getArgs(options);
|
|
@@ -1632,22 +1556,201 @@ var openaiTools = {
|
|
|
1632
1556
|
webSearchPreview: webSearchPreviewTool
|
|
1633
1557
|
};
|
|
1634
1558
|
|
|
1635
|
-
// src/
|
|
1559
|
+
// src/openai-transcription-model.ts
|
|
1636
1560
|
import {
|
|
1637
1561
|
combineHeaders as combineHeaders5,
|
|
1638
|
-
|
|
1562
|
+
convertBase64ToUint8Array,
|
|
1639
1563
|
createJsonResponseHandler as createJsonResponseHandler5,
|
|
1640
|
-
generateId as generateId2,
|
|
1641
1564
|
parseProviderOptions,
|
|
1642
|
-
|
|
1565
|
+
postFormDataToApi
|
|
1643
1566
|
} from "@ai-sdk/provider-utils";
|
|
1644
1567
|
import { z as z7 } from "zod";
|
|
1568
|
+
var OpenAIProviderOptionsSchema = z7.object({
|
|
1569
|
+
include: z7.array(z7.string()).optional().describe(
|
|
1570
|
+
"Additional information to include in the transcription response."
|
|
1571
|
+
),
|
|
1572
|
+
language: z7.string().optional().describe("The language of the input audio in ISO-639-1 format."),
|
|
1573
|
+
prompt: z7.string().optional().describe(
|
|
1574
|
+
"An optional text to guide the model's style or continue a previous audio segment."
|
|
1575
|
+
),
|
|
1576
|
+
temperature: z7.number().min(0).max(1).optional().default(0).describe("The sampling temperature, between 0 and 1."),
|
|
1577
|
+
timestampGranularities: z7.array(z7.enum(["word", "segment"])).optional().default(["segment"]).describe(
|
|
1578
|
+
"The timestamp granularities to populate for this transcription."
|
|
1579
|
+
)
|
|
1580
|
+
});
|
|
1581
|
+
var languageMap = {
|
|
1582
|
+
afrikaans: "af",
|
|
1583
|
+
arabic: "ar",
|
|
1584
|
+
armenian: "hy",
|
|
1585
|
+
azerbaijani: "az",
|
|
1586
|
+
belarusian: "be",
|
|
1587
|
+
bosnian: "bs",
|
|
1588
|
+
bulgarian: "bg",
|
|
1589
|
+
catalan: "ca",
|
|
1590
|
+
chinese: "zh",
|
|
1591
|
+
croatian: "hr",
|
|
1592
|
+
czech: "cs",
|
|
1593
|
+
danish: "da",
|
|
1594
|
+
dutch: "nl",
|
|
1595
|
+
english: "en",
|
|
1596
|
+
estonian: "et",
|
|
1597
|
+
finnish: "fi",
|
|
1598
|
+
french: "fr",
|
|
1599
|
+
galician: "gl",
|
|
1600
|
+
german: "de",
|
|
1601
|
+
greek: "el",
|
|
1602
|
+
hebrew: "he",
|
|
1603
|
+
hindi: "hi",
|
|
1604
|
+
hungarian: "hu",
|
|
1605
|
+
icelandic: "is",
|
|
1606
|
+
indonesian: "id",
|
|
1607
|
+
italian: "it",
|
|
1608
|
+
japanese: "ja",
|
|
1609
|
+
kannada: "kn",
|
|
1610
|
+
kazakh: "kk",
|
|
1611
|
+
korean: "ko",
|
|
1612
|
+
latvian: "lv",
|
|
1613
|
+
lithuanian: "lt",
|
|
1614
|
+
macedonian: "mk",
|
|
1615
|
+
malay: "ms",
|
|
1616
|
+
marathi: "mr",
|
|
1617
|
+
maori: "mi",
|
|
1618
|
+
nepali: "ne",
|
|
1619
|
+
norwegian: "no",
|
|
1620
|
+
persian: "fa",
|
|
1621
|
+
polish: "pl",
|
|
1622
|
+
portuguese: "pt",
|
|
1623
|
+
romanian: "ro",
|
|
1624
|
+
russian: "ru",
|
|
1625
|
+
serbian: "sr",
|
|
1626
|
+
slovak: "sk",
|
|
1627
|
+
slovenian: "sl",
|
|
1628
|
+
spanish: "es",
|
|
1629
|
+
swahili: "sw",
|
|
1630
|
+
swedish: "sv",
|
|
1631
|
+
tagalog: "tl",
|
|
1632
|
+
tamil: "ta",
|
|
1633
|
+
thai: "th",
|
|
1634
|
+
turkish: "tr",
|
|
1635
|
+
ukrainian: "uk",
|
|
1636
|
+
urdu: "ur",
|
|
1637
|
+
vietnamese: "vi",
|
|
1638
|
+
welsh: "cy"
|
|
1639
|
+
};
|
|
1640
|
+
var OpenAITranscriptionModel = class {
|
|
1641
|
+
constructor(modelId, config) {
|
|
1642
|
+
this.modelId = modelId;
|
|
1643
|
+
this.config = config;
|
|
1644
|
+
this.specificationVersion = "v1";
|
|
1645
|
+
}
|
|
1646
|
+
get provider() {
|
|
1647
|
+
return this.config.provider;
|
|
1648
|
+
}
|
|
1649
|
+
getArgs({
|
|
1650
|
+
audio,
|
|
1651
|
+
mediaType,
|
|
1652
|
+
providerOptions
|
|
1653
|
+
}) {
|
|
1654
|
+
const warnings = [];
|
|
1655
|
+
const openAIOptions = parseProviderOptions({
|
|
1656
|
+
provider: "openai",
|
|
1657
|
+
providerOptions,
|
|
1658
|
+
schema: OpenAIProviderOptionsSchema
|
|
1659
|
+
});
|
|
1660
|
+
const formData = new FormData();
|
|
1661
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
1662
|
+
formData.append("model", this.modelId);
|
|
1663
|
+
formData.append("file", new File([blob], "audio", { type: mediaType }));
|
|
1664
|
+
if (openAIOptions) {
|
|
1665
|
+
const transcriptionModelOptions = {
|
|
1666
|
+
include: openAIOptions.include,
|
|
1667
|
+
language: openAIOptions.language,
|
|
1668
|
+
prompt: openAIOptions.prompt,
|
|
1669
|
+
temperature: openAIOptions.temperature,
|
|
1670
|
+
timestamp_granularities: openAIOptions.timestampGranularities
|
|
1671
|
+
};
|
|
1672
|
+
for (const key in transcriptionModelOptions) {
|
|
1673
|
+
const value = transcriptionModelOptions[key];
|
|
1674
|
+
if (value !== void 0) {
|
|
1675
|
+
formData.append(key, value);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
return {
|
|
1680
|
+
formData,
|
|
1681
|
+
warnings
|
|
1682
|
+
};
|
|
1683
|
+
}
|
|
1684
|
+
async doGenerate(options) {
|
|
1685
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1686
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1687
|
+
const { formData, warnings } = this.getArgs(options);
|
|
1688
|
+
const {
|
|
1689
|
+
value: response,
|
|
1690
|
+
responseHeaders,
|
|
1691
|
+
rawValue: rawResponse
|
|
1692
|
+
} = await postFormDataToApi({
|
|
1693
|
+
url: this.config.url({
|
|
1694
|
+
path: "/audio/transcriptions",
|
|
1695
|
+
modelId: this.modelId
|
|
1696
|
+
}),
|
|
1697
|
+
headers: combineHeaders5(this.config.headers(), options.headers),
|
|
1698
|
+
formData,
|
|
1699
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
1700
|
+
successfulResponseHandler: createJsonResponseHandler5(
|
|
1701
|
+
openaiTranscriptionResponseSchema
|
|
1702
|
+
),
|
|
1703
|
+
abortSignal: options.abortSignal,
|
|
1704
|
+
fetch: this.config.fetch
|
|
1705
|
+
});
|
|
1706
|
+
const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
|
|
1707
|
+
return {
|
|
1708
|
+
text: response.text,
|
|
1709
|
+
segments: (_e = (_d = response.words) == null ? void 0 : _d.map((word) => ({
|
|
1710
|
+
text: word.word,
|
|
1711
|
+
startSecond: word.start,
|
|
1712
|
+
endSecond: word.end
|
|
1713
|
+
}))) != null ? _e : [],
|
|
1714
|
+
language,
|
|
1715
|
+
durationInSeconds: (_f = response.duration) != null ? _f : void 0,
|
|
1716
|
+
warnings,
|
|
1717
|
+
response: {
|
|
1718
|
+
timestamp: currentDate,
|
|
1719
|
+
modelId: this.modelId,
|
|
1720
|
+
headers: responseHeaders,
|
|
1721
|
+
body: rawResponse
|
|
1722
|
+
}
|
|
1723
|
+
};
|
|
1724
|
+
}
|
|
1725
|
+
};
|
|
1726
|
+
var openaiTranscriptionResponseSchema = z7.object({
|
|
1727
|
+
text: z7.string(),
|
|
1728
|
+
language: z7.string().nullish(),
|
|
1729
|
+
duration: z7.number().nullish(),
|
|
1730
|
+
words: z7.array(
|
|
1731
|
+
z7.object({
|
|
1732
|
+
word: z7.string(),
|
|
1733
|
+
start: z7.number(),
|
|
1734
|
+
end: z7.number()
|
|
1735
|
+
})
|
|
1736
|
+
).nullish()
|
|
1737
|
+
});
|
|
1738
|
+
|
|
1739
|
+
// src/responses/openai-responses-language-model.ts
|
|
1740
|
+
import {
|
|
1741
|
+
combineHeaders as combineHeaders6,
|
|
1742
|
+
createEventSourceResponseHandler as createEventSourceResponseHandler3,
|
|
1743
|
+
createJsonResponseHandler as createJsonResponseHandler6,
|
|
1744
|
+
generateId as generateId2,
|
|
1745
|
+
parseProviderOptions as parseProviderOptions2,
|
|
1746
|
+
postJsonToApi as postJsonToApi5
|
|
1747
|
+
} from "@ai-sdk/provider-utils";
|
|
1748
|
+
import { z as z8 } from "zod";
|
|
1645
1749
|
|
|
1646
1750
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1647
1751
|
import {
|
|
1648
|
-
UnsupportedFunctionalityError as
|
|
1752
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError5
|
|
1649
1753
|
} from "@ai-sdk/provider";
|
|
1650
|
-
import { convertUint8ArrayToBase64 as convertUint8ArrayToBase642 } from "@ai-sdk/provider-utils";
|
|
1651
1754
|
function convertToOpenAIResponsesMessages({
|
|
1652
1755
|
prompt,
|
|
1653
1756
|
systemMessageMode
|
|
@@ -1686,38 +1789,35 @@ function convertToOpenAIResponsesMessages({
|
|
|
1686
1789
|
messages.push({
|
|
1687
1790
|
role: "user",
|
|
1688
1791
|
content: content.map((part, index) => {
|
|
1689
|
-
var _a, _b, _c
|
|
1792
|
+
var _a, _b, _c;
|
|
1690
1793
|
switch (part.type) {
|
|
1691
1794
|
case "text": {
|
|
1692
1795
|
return { type: "input_text", text: part.text };
|
|
1693
1796
|
}
|
|
1694
|
-
case "image": {
|
|
1695
|
-
return {
|
|
1696
|
-
type: "input_image",
|
|
1697
|
-
image_url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${convertUint8ArrayToBase642(part.image)}`,
|
|
1698
|
-
// OpenAI specific extension: image detail
|
|
1699
|
-
detail: (_c = (_b = part.providerMetadata) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
|
|
1700
|
-
};
|
|
1701
|
-
}
|
|
1702
1797
|
case "file": {
|
|
1703
|
-
if (part.
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
}
|
|
1716
|
-
default: {
|
|
1717
|
-
throw new UnsupportedFunctionalityError6({
|
|
1718
|
-
functionality: "Only PDF files are supported in user messages"
|
|
1798
|
+
if (part.mediaType.startsWith("image/")) {
|
|
1799
|
+
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
1800
|
+
return {
|
|
1801
|
+
type: "input_image",
|
|
1802
|
+
image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
|
|
1803
|
+
// OpenAI specific extension: image detail
|
|
1804
|
+
detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
|
|
1805
|
+
};
|
|
1806
|
+
} else if (part.mediaType === "application/pdf") {
|
|
1807
|
+
if (part.data instanceof URL) {
|
|
1808
|
+
throw new UnsupportedFunctionalityError5({
|
|
1809
|
+
functionality: "PDF file parts with URLs"
|
|
1719
1810
|
});
|
|
1720
1811
|
}
|
|
1812
|
+
return {
|
|
1813
|
+
type: "input_file",
|
|
1814
|
+
filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
|
|
1815
|
+
file_data: `data:application/pdf;base64,${part.data}`
|
|
1816
|
+
};
|
|
1817
|
+
} else {
|
|
1818
|
+
throw new UnsupportedFunctionalityError5({
|
|
1819
|
+
functionality: `file part media type ${part.mediaType}`
|
|
1820
|
+
});
|
|
1721
1821
|
}
|
|
1722
1822
|
}
|
|
1723
1823
|
}
|
|
@@ -1787,19 +1887,18 @@ function mapOpenAIResponseFinishReason({
|
|
|
1787
1887
|
|
|
1788
1888
|
// src/responses/openai-responses-prepare-tools.ts
|
|
1789
1889
|
import {
|
|
1790
|
-
UnsupportedFunctionalityError as
|
|
1890
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError6
|
|
1791
1891
|
} from "@ai-sdk/provider";
|
|
1792
1892
|
function prepareResponsesTools({
|
|
1793
|
-
|
|
1893
|
+
tools,
|
|
1894
|
+
toolChoice,
|
|
1794
1895
|
strict
|
|
1795
1896
|
}) {
|
|
1796
|
-
|
|
1797
|
-
const tools = ((_a = mode.tools) == null ? void 0 : _a.length) ? mode.tools : void 0;
|
|
1897
|
+
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
1798
1898
|
const toolWarnings = [];
|
|
1799
1899
|
if (tools == null) {
|
|
1800
|
-
return { tools: void 0,
|
|
1900
|
+
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
1801
1901
|
}
|
|
1802
|
-
const toolChoice = mode.toolChoice;
|
|
1803
1902
|
const openaiTools2 = [];
|
|
1804
1903
|
for (const tool of tools) {
|
|
1805
1904
|
switch (tool.type) {
|
|
@@ -1832,37 +1931,24 @@ function prepareResponsesTools({
|
|
|
1832
1931
|
}
|
|
1833
1932
|
}
|
|
1834
1933
|
if (toolChoice == null) {
|
|
1835
|
-
return { tools: openaiTools2,
|
|
1934
|
+
return { tools: openaiTools2, toolChoice: void 0, toolWarnings };
|
|
1836
1935
|
}
|
|
1837
1936
|
const type = toolChoice.type;
|
|
1838
1937
|
switch (type) {
|
|
1839
1938
|
case "auto":
|
|
1840
1939
|
case "none":
|
|
1841
1940
|
case "required":
|
|
1842
|
-
return { tools: openaiTools2,
|
|
1843
|
-
case "tool":
|
|
1844
|
-
if (toolChoice.toolName === "web_search_preview") {
|
|
1845
|
-
return {
|
|
1846
|
-
tools: openaiTools2,
|
|
1847
|
-
tool_choice: {
|
|
1848
|
-
type: "web_search_preview"
|
|
1849
|
-
},
|
|
1850
|
-
toolWarnings
|
|
1851
|
-
};
|
|
1852
|
-
}
|
|
1941
|
+
return { tools: openaiTools2, toolChoice: type, toolWarnings };
|
|
1942
|
+
case "tool":
|
|
1853
1943
|
return {
|
|
1854
1944
|
tools: openaiTools2,
|
|
1855
|
-
|
|
1856
|
-
type: "function",
|
|
1857
|
-
name: toolChoice.toolName
|
|
1858
|
-
},
|
|
1945
|
+
toolChoice: toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
|
|
1859
1946
|
toolWarnings
|
|
1860
1947
|
};
|
|
1861
|
-
}
|
|
1862
1948
|
default: {
|
|
1863
1949
|
const _exhaustiveCheck = type;
|
|
1864
|
-
throw new
|
|
1865
|
-
functionality: `
|
|
1950
|
+
throw new UnsupportedFunctionalityError6({
|
|
1951
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
1866
1952
|
});
|
|
1867
1953
|
}
|
|
1868
1954
|
}
|
|
@@ -1880,7 +1966,6 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1880
1966
|
return this.config.provider;
|
|
1881
1967
|
}
|
|
1882
1968
|
getArgs({
|
|
1883
|
-
mode,
|
|
1884
1969
|
maxTokens,
|
|
1885
1970
|
temperature,
|
|
1886
1971
|
stopSequences,
|
|
@@ -1890,24 +1975,19 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1890
1975
|
frequencyPenalty,
|
|
1891
1976
|
seed,
|
|
1892
1977
|
prompt,
|
|
1893
|
-
|
|
1978
|
+
providerOptions,
|
|
1979
|
+
tools,
|
|
1980
|
+
toolChoice,
|
|
1894
1981
|
responseFormat
|
|
1895
1982
|
}) {
|
|
1896
|
-
var _a, _b
|
|
1983
|
+
var _a, _b;
|
|
1897
1984
|
const warnings = [];
|
|
1898
1985
|
const modelConfig = getResponsesModelConfig(this.modelId);
|
|
1899
|
-
const type = mode.type;
|
|
1900
1986
|
if (topK != null) {
|
|
1901
|
-
warnings.push({
|
|
1902
|
-
type: "unsupported-setting",
|
|
1903
|
-
setting: "topK"
|
|
1904
|
-
});
|
|
1987
|
+
warnings.push({ type: "unsupported-setting", setting: "topK" });
|
|
1905
1988
|
}
|
|
1906
1989
|
if (seed != null) {
|
|
1907
|
-
warnings.push({
|
|
1908
|
-
type: "unsupported-setting",
|
|
1909
|
-
setting: "seed"
|
|
1910
|
-
});
|
|
1990
|
+
warnings.push({ type: "unsupported-setting", setting: "seed" });
|
|
1911
1991
|
}
|
|
1912
1992
|
if (presencePenalty != null) {
|
|
1913
1993
|
warnings.push({
|
|
@@ -1922,19 +2002,16 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1922
2002
|
});
|
|
1923
2003
|
}
|
|
1924
2004
|
if (stopSequences != null) {
|
|
1925
|
-
warnings.push({
|
|
1926
|
-
type: "unsupported-setting",
|
|
1927
|
-
setting: "stopSequences"
|
|
1928
|
-
});
|
|
2005
|
+
warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
|
|
1929
2006
|
}
|
|
1930
2007
|
const { messages, warnings: messageWarnings } = convertToOpenAIResponsesMessages({
|
|
1931
2008
|
prompt,
|
|
1932
2009
|
systemMessageMode: modelConfig.systemMessageMode
|
|
1933
2010
|
});
|
|
1934
2011
|
warnings.push(...messageWarnings);
|
|
1935
|
-
const openaiOptions =
|
|
2012
|
+
const openaiOptions = parseProviderOptions2({
|
|
1936
2013
|
provider: "openai",
|
|
1937
|
-
providerOptions
|
|
2014
|
+
providerOptions,
|
|
1938
2015
|
schema: openaiResponsesProviderOptionsSchema
|
|
1939
2016
|
});
|
|
1940
2017
|
const isStrict = (_a = openaiOptions == null ? void 0 : openaiOptions.strictSchemas) != null ? _a : true;
|
|
@@ -1988,62 +2065,23 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1988
2065
|
});
|
|
1989
2066
|
}
|
|
1990
2067
|
}
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
return {
|
|
2009
|
-
args: {
|
|
2010
|
-
...baseArgs,
|
|
2011
|
-
text: {
|
|
2012
|
-
format: mode.schema != null ? {
|
|
2013
|
-
type: "json_schema",
|
|
2014
|
-
strict: isStrict,
|
|
2015
|
-
name: (_c = mode.name) != null ? _c : "response",
|
|
2016
|
-
description: mode.description,
|
|
2017
|
-
schema: mode.schema
|
|
2018
|
-
} : { type: "json_object" }
|
|
2019
|
-
}
|
|
2020
|
-
},
|
|
2021
|
-
warnings
|
|
2022
|
-
};
|
|
2023
|
-
}
|
|
2024
|
-
case "object-tool": {
|
|
2025
|
-
return {
|
|
2026
|
-
args: {
|
|
2027
|
-
...baseArgs,
|
|
2028
|
-
tool_choice: { type: "function", name: mode.tool.name },
|
|
2029
|
-
tools: [
|
|
2030
|
-
{
|
|
2031
|
-
type: "function",
|
|
2032
|
-
name: mode.tool.name,
|
|
2033
|
-
description: mode.tool.description,
|
|
2034
|
-
parameters: mode.tool.parameters,
|
|
2035
|
-
strict: isStrict
|
|
2036
|
-
}
|
|
2037
|
-
]
|
|
2038
|
-
},
|
|
2039
|
-
warnings
|
|
2040
|
-
};
|
|
2041
|
-
}
|
|
2042
|
-
default: {
|
|
2043
|
-
const _exhaustiveCheck = type;
|
|
2044
|
-
throw new Error(`Unsupported type: ${_exhaustiveCheck}`);
|
|
2045
|
-
}
|
|
2046
|
-
}
|
|
2068
|
+
const {
|
|
2069
|
+
tools: openaiTools2,
|
|
2070
|
+
toolChoice: openaiToolChoice,
|
|
2071
|
+
toolWarnings
|
|
2072
|
+
} = prepareResponsesTools({
|
|
2073
|
+
tools,
|
|
2074
|
+
toolChoice,
|
|
2075
|
+
strict: isStrict
|
|
2076
|
+
});
|
|
2077
|
+
return {
|
|
2078
|
+
args: {
|
|
2079
|
+
...baseArgs,
|
|
2080
|
+
tools: openaiTools2,
|
|
2081
|
+
tool_choice: openaiToolChoice
|
|
2082
|
+
},
|
|
2083
|
+
warnings: [...warnings, ...toolWarnings]
|
|
2084
|
+
};
|
|
2047
2085
|
}
|
|
2048
2086
|
async doGenerate(options) {
|
|
2049
2087
|
var _a, _b, _c, _d, _e;
|
|
@@ -2057,53 +2095,53 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2057
2095
|
path: "/responses",
|
|
2058
2096
|
modelId: this.modelId
|
|
2059
2097
|
}),
|
|
2060
|
-
headers:
|
|
2098
|
+
headers: combineHeaders6(this.config.headers(), options.headers),
|
|
2061
2099
|
body,
|
|
2062
2100
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2063
|
-
successfulResponseHandler:
|
|
2064
|
-
|
|
2065
|
-
id:
|
|
2066
|
-
created_at:
|
|
2067
|
-
model:
|
|
2068
|
-
output:
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
type:
|
|
2072
|
-
role:
|
|
2073
|
-
content:
|
|
2074
|
-
|
|
2075
|
-
type:
|
|
2076
|
-
text:
|
|
2077
|
-
annotations:
|
|
2078
|
-
|
|
2079
|
-
type:
|
|
2080
|
-
start_index:
|
|
2081
|
-
end_index:
|
|
2082
|
-
url:
|
|
2083
|
-
title:
|
|
2101
|
+
successfulResponseHandler: createJsonResponseHandler6(
|
|
2102
|
+
z8.object({
|
|
2103
|
+
id: z8.string(),
|
|
2104
|
+
created_at: z8.number(),
|
|
2105
|
+
model: z8.string(),
|
|
2106
|
+
output: z8.array(
|
|
2107
|
+
z8.discriminatedUnion("type", [
|
|
2108
|
+
z8.object({
|
|
2109
|
+
type: z8.literal("message"),
|
|
2110
|
+
role: z8.literal("assistant"),
|
|
2111
|
+
content: z8.array(
|
|
2112
|
+
z8.object({
|
|
2113
|
+
type: z8.literal("output_text"),
|
|
2114
|
+
text: z8.string(),
|
|
2115
|
+
annotations: z8.array(
|
|
2116
|
+
z8.object({
|
|
2117
|
+
type: z8.literal("url_citation"),
|
|
2118
|
+
start_index: z8.number(),
|
|
2119
|
+
end_index: z8.number(),
|
|
2120
|
+
url: z8.string(),
|
|
2121
|
+
title: z8.string()
|
|
2084
2122
|
})
|
|
2085
2123
|
)
|
|
2086
2124
|
})
|
|
2087
2125
|
)
|
|
2088
2126
|
}),
|
|
2089
|
-
|
|
2090
|
-
type:
|
|
2091
|
-
call_id:
|
|
2092
|
-
name:
|
|
2093
|
-
arguments:
|
|
2127
|
+
z8.object({
|
|
2128
|
+
type: z8.literal("function_call"),
|
|
2129
|
+
call_id: z8.string(),
|
|
2130
|
+
name: z8.string(),
|
|
2131
|
+
arguments: z8.string()
|
|
2094
2132
|
}),
|
|
2095
|
-
|
|
2096
|
-
type:
|
|
2133
|
+
z8.object({
|
|
2134
|
+
type: z8.literal("web_search_call")
|
|
2097
2135
|
}),
|
|
2098
|
-
|
|
2099
|
-
type:
|
|
2136
|
+
z8.object({
|
|
2137
|
+
type: z8.literal("computer_call")
|
|
2100
2138
|
}),
|
|
2101
|
-
|
|
2102
|
-
type:
|
|
2139
|
+
z8.object({
|
|
2140
|
+
type: z8.literal("reasoning")
|
|
2103
2141
|
})
|
|
2104
2142
|
])
|
|
2105
2143
|
),
|
|
2106
|
-
incomplete_details:
|
|
2144
|
+
incomplete_details: z8.object({ reason: z8.string() }).nullable(),
|
|
2107
2145
|
usage: usageSchema
|
|
2108
2146
|
})
|
|
2109
2147
|
),
|
|
@@ -2172,7 +2210,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2172
2210
|
path: "/responses",
|
|
2173
2211
|
modelId: this.modelId
|
|
2174
2212
|
}),
|
|
2175
|
-
headers:
|
|
2213
|
+
headers: combineHeaders6(this.config.headers(), options.headers),
|
|
2176
2214
|
body: {
|
|
2177
2215
|
...body,
|
|
2178
2216
|
stream: true
|
|
@@ -2301,79 +2339,79 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2301
2339
|
};
|
|
2302
2340
|
}
|
|
2303
2341
|
};
|
|
2304
|
-
var usageSchema =
|
|
2305
|
-
input_tokens:
|
|
2306
|
-
input_tokens_details:
|
|
2307
|
-
output_tokens:
|
|
2308
|
-
output_tokens_details:
|
|
2342
|
+
var usageSchema = z8.object({
|
|
2343
|
+
input_tokens: z8.number(),
|
|
2344
|
+
input_tokens_details: z8.object({ cached_tokens: z8.number().nullish() }).nullish(),
|
|
2345
|
+
output_tokens: z8.number(),
|
|
2346
|
+
output_tokens_details: z8.object({ reasoning_tokens: z8.number().nullish() }).nullish()
|
|
2309
2347
|
});
|
|
2310
|
-
var textDeltaChunkSchema =
|
|
2311
|
-
type:
|
|
2312
|
-
delta:
|
|
2348
|
+
var textDeltaChunkSchema = z8.object({
|
|
2349
|
+
type: z8.literal("response.output_text.delta"),
|
|
2350
|
+
delta: z8.string()
|
|
2313
2351
|
});
|
|
2314
|
-
var responseFinishedChunkSchema =
|
|
2315
|
-
type:
|
|
2316
|
-
response:
|
|
2317
|
-
incomplete_details:
|
|
2352
|
+
var responseFinishedChunkSchema = z8.object({
|
|
2353
|
+
type: z8.enum(["response.completed", "response.incomplete"]),
|
|
2354
|
+
response: z8.object({
|
|
2355
|
+
incomplete_details: z8.object({ reason: z8.string() }).nullish(),
|
|
2318
2356
|
usage: usageSchema
|
|
2319
2357
|
})
|
|
2320
2358
|
});
|
|
2321
|
-
var responseCreatedChunkSchema =
|
|
2322
|
-
type:
|
|
2323
|
-
response:
|
|
2324
|
-
id:
|
|
2325
|
-
created_at:
|
|
2326
|
-
model:
|
|
2359
|
+
var responseCreatedChunkSchema = z8.object({
|
|
2360
|
+
type: z8.literal("response.created"),
|
|
2361
|
+
response: z8.object({
|
|
2362
|
+
id: z8.string(),
|
|
2363
|
+
created_at: z8.number(),
|
|
2364
|
+
model: z8.string()
|
|
2327
2365
|
})
|
|
2328
2366
|
});
|
|
2329
|
-
var responseOutputItemDoneSchema =
|
|
2330
|
-
type:
|
|
2331
|
-
output_index:
|
|
2332
|
-
item:
|
|
2333
|
-
|
|
2334
|
-
type:
|
|
2367
|
+
var responseOutputItemDoneSchema = z8.object({
|
|
2368
|
+
type: z8.literal("response.output_item.done"),
|
|
2369
|
+
output_index: z8.number(),
|
|
2370
|
+
item: z8.discriminatedUnion("type", [
|
|
2371
|
+
z8.object({
|
|
2372
|
+
type: z8.literal("message")
|
|
2335
2373
|
}),
|
|
2336
|
-
|
|
2337
|
-
type:
|
|
2338
|
-
id:
|
|
2339
|
-
call_id:
|
|
2340
|
-
name:
|
|
2341
|
-
arguments:
|
|
2342
|
-
status:
|
|
2374
|
+
z8.object({
|
|
2375
|
+
type: z8.literal("function_call"),
|
|
2376
|
+
id: z8.string(),
|
|
2377
|
+
call_id: z8.string(),
|
|
2378
|
+
name: z8.string(),
|
|
2379
|
+
arguments: z8.string(),
|
|
2380
|
+
status: z8.literal("completed")
|
|
2343
2381
|
})
|
|
2344
2382
|
])
|
|
2345
2383
|
});
|
|
2346
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
2347
|
-
type:
|
|
2348
|
-
item_id:
|
|
2349
|
-
output_index:
|
|
2350
|
-
delta:
|
|
2384
|
+
var responseFunctionCallArgumentsDeltaSchema = z8.object({
|
|
2385
|
+
type: z8.literal("response.function_call_arguments.delta"),
|
|
2386
|
+
item_id: z8.string(),
|
|
2387
|
+
output_index: z8.number(),
|
|
2388
|
+
delta: z8.string()
|
|
2351
2389
|
});
|
|
2352
|
-
var responseOutputItemAddedSchema =
|
|
2353
|
-
type:
|
|
2354
|
-
output_index:
|
|
2355
|
-
item:
|
|
2356
|
-
|
|
2357
|
-
type:
|
|
2390
|
+
var responseOutputItemAddedSchema = z8.object({
|
|
2391
|
+
type: z8.literal("response.output_item.added"),
|
|
2392
|
+
output_index: z8.number(),
|
|
2393
|
+
item: z8.discriminatedUnion("type", [
|
|
2394
|
+
z8.object({
|
|
2395
|
+
type: z8.literal("message")
|
|
2358
2396
|
}),
|
|
2359
|
-
|
|
2360
|
-
type:
|
|
2361
|
-
id:
|
|
2362
|
-
call_id:
|
|
2363
|
-
name:
|
|
2364
|
-
arguments:
|
|
2397
|
+
z8.object({
|
|
2398
|
+
type: z8.literal("function_call"),
|
|
2399
|
+
id: z8.string(),
|
|
2400
|
+
call_id: z8.string(),
|
|
2401
|
+
name: z8.string(),
|
|
2402
|
+
arguments: z8.string()
|
|
2365
2403
|
})
|
|
2366
2404
|
])
|
|
2367
2405
|
});
|
|
2368
|
-
var responseAnnotationAddedSchema =
|
|
2369
|
-
type:
|
|
2370
|
-
annotation:
|
|
2371
|
-
type:
|
|
2372
|
-
url:
|
|
2373
|
-
title:
|
|
2406
|
+
var responseAnnotationAddedSchema = z8.object({
|
|
2407
|
+
type: z8.literal("response.output_text.annotation.added"),
|
|
2408
|
+
annotation: z8.object({
|
|
2409
|
+
type: z8.literal("url_citation"),
|
|
2410
|
+
url: z8.string(),
|
|
2411
|
+
title: z8.string()
|
|
2374
2412
|
})
|
|
2375
2413
|
});
|
|
2376
|
-
var openaiResponsesChunkSchema =
|
|
2414
|
+
var openaiResponsesChunkSchema = z8.union([
|
|
2377
2415
|
textDeltaChunkSchema,
|
|
2378
2416
|
responseFinishedChunkSchema,
|
|
2379
2417
|
responseCreatedChunkSchema,
|
|
@@ -2381,7 +2419,7 @@ var openaiResponsesChunkSchema = z7.union([
|
|
|
2381
2419
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2382
2420
|
responseOutputItemAddedSchema,
|
|
2383
2421
|
responseAnnotationAddedSchema,
|
|
2384
|
-
|
|
2422
|
+
z8.object({ type: z8.string() }).passthrough()
|
|
2385
2423
|
// fallback for unknown chunks
|
|
2386
2424
|
]);
|
|
2387
2425
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2426,15 +2464,15 @@ function getResponsesModelConfig(modelId) {
|
|
|
2426
2464
|
requiredAutoTruncation: false
|
|
2427
2465
|
};
|
|
2428
2466
|
}
|
|
2429
|
-
var openaiResponsesProviderOptionsSchema =
|
|
2430
|
-
metadata:
|
|
2431
|
-
parallelToolCalls:
|
|
2432
|
-
previousResponseId:
|
|
2433
|
-
store:
|
|
2434
|
-
user:
|
|
2435
|
-
reasoningEffort:
|
|
2436
|
-
strictSchemas:
|
|
2437
|
-
instructions:
|
|
2467
|
+
var openaiResponsesProviderOptionsSchema = z8.object({
|
|
2468
|
+
metadata: z8.any().nullish(),
|
|
2469
|
+
parallelToolCalls: z8.boolean().nullish(),
|
|
2470
|
+
previousResponseId: z8.string().nullish(),
|
|
2471
|
+
store: z8.boolean().nullish(),
|
|
2472
|
+
user: z8.string().nullish(),
|
|
2473
|
+
reasoningEffort: z8.string().nullish(),
|
|
2474
|
+
strictSchemas: z8.boolean().nullish(),
|
|
2475
|
+
instructions: z8.string().nullish()
|
|
2438
2476
|
});
|
|
2439
2477
|
|
|
2440
2478
|
// src/openai-provider.ts
|
|
@@ -2479,6 +2517,12 @@ function createOpenAI(options = {}) {
|
|
|
2479
2517
|
headers: getHeaders,
|
|
2480
2518
|
fetch: options.fetch
|
|
2481
2519
|
});
|
|
2520
|
+
const createTranscriptionModel = (modelId) => new OpenAITranscriptionModel(modelId, {
|
|
2521
|
+
provider: `${providerName}.transcription`,
|
|
2522
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
2523
|
+
headers: getHeaders,
|
|
2524
|
+
fetch: options.fetch
|
|
2525
|
+
});
|
|
2482
2526
|
const createLanguageModel = (modelId, settings) => {
|
|
2483
2527
|
if (new.target) {
|
|
2484
2528
|
throw new Error(
|
|
@@ -2513,6 +2557,8 @@ function createOpenAI(options = {}) {
|
|
|
2513
2557
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
2514
2558
|
provider.image = createImageModel;
|
|
2515
2559
|
provider.imageModel = createImageModel;
|
|
2560
|
+
provider.transcription = createTranscriptionModel;
|
|
2561
|
+
provider.transcriptionModel = createTranscriptionModel;
|
|
2516
2562
|
provider.tools = openaiTools;
|
|
2517
2563
|
return provider;
|
|
2518
2564
|
}
|