@ai-sdk/openai 2.0.0-canary.2 → 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 +15 -0
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +397 -215
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +366 -178
- 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 +388 -212
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +359 -178
- package/internal/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -26,16 +26,15 @@ __export(src_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(src_exports);
|
|
27
27
|
|
|
28
28
|
// src/openai-provider.ts
|
|
29
|
-
var
|
|
29
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
|
30
30
|
|
|
31
31
|
// src/openai-chat-language-model.ts
|
|
32
32
|
var import_provider3 = require("@ai-sdk/provider");
|
|
33
|
-
var
|
|
33
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
34
34
|
var import_zod2 = require("zod");
|
|
35
35
|
|
|
36
36
|
// src/convert-to-openai-chat-messages.ts
|
|
37
37
|
var import_provider = require("@ai-sdk/provider");
|
|
38
|
-
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
39
38
|
function convertToOpenAIChatMessages({
|
|
40
39
|
prompt,
|
|
41
40
|
useLegacyFunctionCalling = false,
|
|
@@ -79,55 +78,65 @@ function convertToOpenAIChatMessages({
|
|
|
79
78
|
messages.push({
|
|
80
79
|
role: "user",
|
|
81
80
|
content: content.map((part, index) => {
|
|
82
|
-
var _a, _b, _c
|
|
81
|
+
var _a, _b, _c;
|
|
83
82
|
switch (part.type) {
|
|
84
83
|
case "text": {
|
|
85
84
|
return { type: "text", text: part.text };
|
|
86
85
|
}
|
|
87
|
-
case "image": {
|
|
88
|
-
return {
|
|
89
|
-
type: "image_url",
|
|
90
|
-
image_url: {
|
|
91
|
-
url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${(0, import_provider_utils.convertUint8ArrayToBase64)(part.image)}`,
|
|
92
|
-
// OpenAI specific extension: image detail
|
|
93
|
-
detail: (_c = (_b = part.providerOptions) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
86
|
case "file": {
|
|
98
|
-
if (part.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
type: "input_audio",
|
|
114
|
-
input_audio: { data: part.data, format: "mp3" }
|
|
115
|
-
};
|
|
87
|
+
if (part.mediaType.startsWith("image/")) {
|
|
88
|
+
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
89
|
+
return {
|
|
90
|
+
type: "image_url",
|
|
91
|
+
image_url: {
|
|
92
|
+
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
|
|
93
|
+
// OpenAI specific extension: image detail
|
|
94
|
+
detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
} else if (part.mediaType.startsWith("audio/")) {
|
|
98
|
+
if (part.data instanceof URL) {
|
|
99
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
100
|
+
functionality: "audio file parts with URLs"
|
|
101
|
+
});
|
|
116
102
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
103
|
+
switch (part.mediaType) {
|
|
104
|
+
case "audio/wav": {
|
|
105
|
+
return {
|
|
106
|
+
type: "input_audio",
|
|
107
|
+
input_audio: { data: part.data, format: "wav" }
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
case "audio/mp3":
|
|
111
|
+
case "audio/mpeg": {
|
|
112
|
+
return {
|
|
113
|
+
type: "input_audio",
|
|
114
|
+
input_audio: { data: part.data, format: "mp3" }
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
default: {
|
|
118
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
119
|
+
functionality: `audio content parts with media type ${part.mediaType}`
|
|
120
|
+
});
|
|
121
|
+
}
|
|
125
122
|
}
|
|
126
|
-
|
|
123
|
+
} else if (part.mediaType === "application/pdf") {
|
|
124
|
+
if (part.data instanceof URL) {
|
|
127
125
|
throw new import_provider.UnsupportedFunctionalityError({
|
|
128
|
-
functionality:
|
|
126
|
+
functionality: "PDF file parts with URLs"
|
|
129
127
|
});
|
|
130
128
|
}
|
|
129
|
+
return {
|
|
130
|
+
type: "file",
|
|
131
|
+
file: {
|
|
132
|
+
filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
|
|
133
|
+
file_data: `data:application/pdf;base64,${part.data}`
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
} else {
|
|
137
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
138
|
+
functionality: `file part media type ${part.mediaType}`
|
|
139
|
+
});
|
|
131
140
|
}
|
|
132
141
|
}
|
|
133
142
|
}
|
|
@@ -236,7 +245,7 @@ function mapOpenAIFinishReason(finishReason) {
|
|
|
236
245
|
|
|
237
246
|
// src/openai-error.ts
|
|
238
247
|
var import_zod = require("zod");
|
|
239
|
-
var
|
|
248
|
+
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
240
249
|
var openaiErrorDataSchema = import_zod.z.object({
|
|
241
250
|
error: import_zod.z.object({
|
|
242
251
|
message: import_zod.z.string(),
|
|
@@ -248,7 +257,7 @@ var openaiErrorDataSchema = import_zod.z.object({
|
|
|
248
257
|
code: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]).nullish()
|
|
249
258
|
})
|
|
250
259
|
});
|
|
251
|
-
var openaiFailedResponseHandler = (0,
|
|
260
|
+
var openaiFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
|
|
252
261
|
errorSchema: openaiErrorDataSchema,
|
|
253
262
|
errorToMessage: (data) => data.error.message
|
|
254
263
|
});
|
|
@@ -360,7 +369,7 @@ function prepareTools({
|
|
|
360
369
|
default: {
|
|
361
370
|
const _exhaustiveCheck = type;
|
|
362
371
|
throw new import_provider2.UnsupportedFunctionalityError({
|
|
363
|
-
functionality: `
|
|
372
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
364
373
|
});
|
|
365
374
|
}
|
|
366
375
|
}
|
|
@@ -567,15 +576,15 @@ var OpenAIChatLanguageModel = class {
|
|
|
567
576
|
responseHeaders,
|
|
568
577
|
value: response,
|
|
569
578
|
rawValue: rawResponse
|
|
570
|
-
} = await (0,
|
|
579
|
+
} = await (0, import_provider_utils2.postJsonToApi)({
|
|
571
580
|
url: this.config.url({
|
|
572
581
|
path: "/chat/completions",
|
|
573
582
|
modelId: this.modelId
|
|
574
583
|
}),
|
|
575
|
-
headers: (0,
|
|
584
|
+
headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
|
|
576
585
|
body,
|
|
577
586
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
578
|
-
successfulResponseHandler: (0,
|
|
587
|
+
successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
|
|
579
588
|
openaiChatResponseSchema
|
|
580
589
|
),
|
|
581
590
|
abortSignal: options.abortSignal,
|
|
@@ -603,7 +612,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
603
612
|
toolCalls: this.settings.useLegacyFunctionCalling && choice.message.function_call ? [
|
|
604
613
|
{
|
|
605
614
|
toolCallType: "function",
|
|
606
|
-
toolCallId: (0,
|
|
615
|
+
toolCallId: (0, import_provider_utils2.generateId)(),
|
|
607
616
|
toolName: choice.message.function_call.name,
|
|
608
617
|
args: choice.message.function_call.arguments
|
|
609
618
|
}
|
|
@@ -611,7 +620,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
611
620
|
var _a2;
|
|
612
621
|
return {
|
|
613
622
|
toolCallType: "function",
|
|
614
|
-
toolCallId: (_a2 = toolCall.id) != null ? _a2 : (0,
|
|
623
|
+
toolCallId: (_a2 = toolCall.id) != null ? _a2 : (0, import_provider_utils2.generateId)(),
|
|
615
624
|
toolName: toolCall.function.name,
|
|
616
625
|
args: toolCall.function.arguments
|
|
617
626
|
};
|
|
@@ -681,15 +690,15 @@ var OpenAIChatLanguageModel = class {
|
|
|
681
690
|
// only include stream_options when in strict compatibility mode:
|
|
682
691
|
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
683
692
|
};
|
|
684
|
-
const { responseHeaders, value: response } = await (0,
|
|
693
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils2.postJsonToApi)({
|
|
685
694
|
url: this.config.url({
|
|
686
695
|
path: "/chat/completions",
|
|
687
696
|
modelId: this.modelId
|
|
688
697
|
}),
|
|
689
|
-
headers: (0,
|
|
698
|
+
headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
|
|
690
699
|
body,
|
|
691
700
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
692
|
-
successfulResponseHandler: (0,
|
|
701
|
+
successfulResponseHandler: (0, import_provider_utils2.createEventSourceResponseHandler)(
|
|
693
702
|
openaiChatChunkSchema
|
|
694
703
|
),
|
|
695
704
|
abortSignal: options.abortSignal,
|
|
@@ -777,7 +786,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
777
786
|
const mappedToolCalls = useLegacyFunctionCalling && delta.function_call != null ? [
|
|
778
787
|
{
|
|
779
788
|
type: "function",
|
|
780
|
-
id: (0,
|
|
789
|
+
id: (0, import_provider_utils2.generateId)(),
|
|
781
790
|
function: delta.function_call,
|
|
782
791
|
index: 0
|
|
783
792
|
}
|
|
@@ -824,11 +833,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
824
833
|
argsTextDelta: toolCall2.function.arguments
|
|
825
834
|
});
|
|
826
835
|
}
|
|
827
|
-
if ((0,
|
|
836
|
+
if ((0, import_provider_utils2.isParsableJson)(toolCall2.function.arguments)) {
|
|
828
837
|
controller.enqueue({
|
|
829
838
|
type: "tool-call",
|
|
830
839
|
toolCallType: "function",
|
|
831
|
-
toolCallId: (_e = toolCall2.id) != null ? _e : (0,
|
|
840
|
+
toolCallId: (_e = toolCall2.id) != null ? _e : (0, import_provider_utils2.generateId)(),
|
|
832
841
|
toolName: toolCall2.function.name,
|
|
833
842
|
args: toolCall2.function.arguments
|
|
834
843
|
});
|
|
@@ -851,11 +860,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
851
860
|
toolName: toolCall.function.name,
|
|
852
861
|
argsTextDelta: (_i = toolCallDelta.function.arguments) != null ? _i : ""
|
|
853
862
|
});
|
|
854
|
-
if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && (0,
|
|
863
|
+
if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && (0, import_provider_utils2.isParsableJson)(toolCall.function.arguments)) {
|
|
855
864
|
controller.enqueue({
|
|
856
865
|
type: "tool-call",
|
|
857
866
|
toolCallType: "function",
|
|
858
|
-
toolCallId: (_l = toolCall.id) != null ? _l : (0,
|
|
867
|
+
toolCallId: (_l = toolCall.id) != null ? _l : (0, import_provider_utils2.generateId)(),
|
|
859
868
|
toolName: toolCall.function.name,
|
|
860
869
|
args: toolCall.function.arguments
|
|
861
870
|
});
|
|
@@ -1025,7 +1034,7 @@ var reasoningModels = {
|
|
|
1025
1034
|
};
|
|
1026
1035
|
|
|
1027
1036
|
// src/openai-completion-language-model.ts
|
|
1028
|
-
var
|
|
1037
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
1029
1038
|
var import_zod3 = require("zod");
|
|
1030
1039
|
|
|
1031
1040
|
// src/convert-to-openai-completion-prompt.ts
|
|
@@ -1060,13 +1069,8 @@ function convertToOpenAICompletionPrompt({
|
|
|
1060
1069
|
case "text": {
|
|
1061
1070
|
return part.text;
|
|
1062
1071
|
}
|
|
1063
|
-
case "image": {
|
|
1064
|
-
throw new import_provider4.UnsupportedFunctionalityError({
|
|
1065
|
-
functionality: "images"
|
|
1066
|
-
});
|
|
1067
|
-
}
|
|
1068
1072
|
}
|
|
1069
|
-
}).join("");
|
|
1073
|
+
}).filter(Boolean).join("");
|
|
1070
1074
|
text += `${user}:
|
|
1071
1075
|
${userMessage}
|
|
1072
1076
|
|
|
@@ -1203,15 +1207,15 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1203
1207
|
responseHeaders,
|
|
1204
1208
|
value: response,
|
|
1205
1209
|
rawValue: rawResponse
|
|
1206
|
-
} = await (0,
|
|
1210
|
+
} = await (0, import_provider_utils3.postJsonToApi)({
|
|
1207
1211
|
url: this.config.url({
|
|
1208
1212
|
path: "/completions",
|
|
1209
1213
|
modelId: this.modelId
|
|
1210
1214
|
}),
|
|
1211
|
-
headers: (0,
|
|
1215
|
+
headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
|
|
1212
1216
|
body: args,
|
|
1213
1217
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1214
|
-
successfulResponseHandler: (0,
|
|
1218
|
+
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)(
|
|
1215
1219
|
openaiCompletionResponseSchema
|
|
1216
1220
|
),
|
|
1217
1221
|
abortSignal: options.abortSignal,
|
|
@@ -1242,15 +1246,15 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1242
1246
|
// only include stream_options when in strict compatibility mode:
|
|
1243
1247
|
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : void 0
|
|
1244
1248
|
};
|
|
1245
|
-
const { responseHeaders, value: response } = await (0,
|
|
1249
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({
|
|
1246
1250
|
url: this.config.url({
|
|
1247
1251
|
path: "/completions",
|
|
1248
1252
|
modelId: this.modelId
|
|
1249
1253
|
}),
|
|
1250
|
-
headers: (0,
|
|
1254
|
+
headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
|
|
1251
1255
|
body,
|
|
1252
1256
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1253
|
-
successfulResponseHandler: (0,
|
|
1257
|
+
successfulResponseHandler: (0, import_provider_utils3.createEventSourceResponseHandler)(
|
|
1254
1258
|
openaiCompletionChunkSchema
|
|
1255
1259
|
),
|
|
1256
1260
|
abortSignal: options.abortSignal,
|
|
@@ -1374,7 +1378,7 @@ var openaiCompletionChunkSchema = import_zod3.z.union([
|
|
|
1374
1378
|
|
|
1375
1379
|
// src/openai-embedding-model.ts
|
|
1376
1380
|
var import_provider5 = require("@ai-sdk/provider");
|
|
1377
|
-
var
|
|
1381
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
1378
1382
|
var import_zod4 = require("zod");
|
|
1379
1383
|
var OpenAIEmbeddingModel = class {
|
|
1380
1384
|
constructor(modelId, settings, config) {
|
|
@@ -1407,12 +1411,12 @@ var OpenAIEmbeddingModel = class {
|
|
|
1407
1411
|
values
|
|
1408
1412
|
});
|
|
1409
1413
|
}
|
|
1410
|
-
const { responseHeaders, value: response } = await (0,
|
|
1414
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
|
|
1411
1415
|
url: this.config.url({
|
|
1412
1416
|
path: "/embeddings",
|
|
1413
1417
|
modelId: this.modelId
|
|
1414
1418
|
}),
|
|
1415
|
-
headers: (0,
|
|
1419
|
+
headers: (0, import_provider_utils4.combineHeaders)(this.config.headers(), headers),
|
|
1416
1420
|
body: {
|
|
1417
1421
|
model: this.modelId,
|
|
1418
1422
|
input: values,
|
|
@@ -1421,7 +1425,7 @@ var OpenAIEmbeddingModel = class {
|
|
|
1421
1425
|
user: this.settings.user
|
|
1422
1426
|
},
|
|
1423
1427
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1424
|
-
successfulResponseHandler: (0,
|
|
1428
|
+
successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(
|
|
1425
1429
|
openaiTextEmbeddingResponseSchema
|
|
1426
1430
|
),
|
|
1427
1431
|
abortSignal,
|
|
@@ -1440,7 +1444,7 @@ var openaiTextEmbeddingResponseSchema = import_zod4.z.object({
|
|
|
1440
1444
|
});
|
|
1441
1445
|
|
|
1442
1446
|
// src/openai-image-model.ts
|
|
1443
|
-
var
|
|
1447
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
1444
1448
|
var import_zod5 = require("zod");
|
|
1445
1449
|
|
|
1446
1450
|
// src/openai-image-settings.ts
|
|
@@ -1487,12 +1491,12 @@ var OpenAIImageModel = class {
|
|
|
1487
1491
|
warnings.push({ type: "unsupported-setting", setting: "seed" });
|
|
1488
1492
|
}
|
|
1489
1493
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1490
|
-
const { value: response, responseHeaders } = await (0,
|
|
1494
|
+
const { value: response, responseHeaders } = await (0, import_provider_utils5.postJsonToApi)({
|
|
1491
1495
|
url: this.config.url({
|
|
1492
1496
|
path: "/images/generations",
|
|
1493
1497
|
modelId: this.modelId
|
|
1494
1498
|
}),
|
|
1495
|
-
headers: (0,
|
|
1499
|
+
headers: (0, import_provider_utils5.combineHeaders)(this.config.headers(), headers),
|
|
1496
1500
|
body: {
|
|
1497
1501
|
model: this.modelId,
|
|
1498
1502
|
prompt,
|
|
@@ -1502,7 +1506,7 @@ var OpenAIImageModel = class {
|
|
|
1502
1506
|
response_format: "b64_json"
|
|
1503
1507
|
},
|
|
1504
1508
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1505
|
-
successfulResponseHandler: (0,
|
|
1509
|
+
successfulResponseHandler: (0, import_provider_utils5.createJsonResponseHandler)(
|
|
1506
1510
|
openaiImageResponseSchema
|
|
1507
1511
|
),
|
|
1508
1512
|
abortSignal,
|
|
@@ -1544,13 +1548,186 @@ var openaiTools = {
|
|
|
1544
1548
|
webSearchPreview: webSearchPreviewTool
|
|
1545
1549
|
};
|
|
1546
1550
|
|
|
1547
|
-
// src/
|
|
1548
|
-
var
|
|
1551
|
+
// src/openai-transcription-model.ts
|
|
1552
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
|
1549
1553
|
var import_zod7 = require("zod");
|
|
1554
|
+
var OpenAIProviderOptionsSchema = import_zod7.z.object({
|
|
1555
|
+
include: import_zod7.z.array(import_zod7.z.string()).optional().describe(
|
|
1556
|
+
"Additional information to include in the transcription response."
|
|
1557
|
+
),
|
|
1558
|
+
language: import_zod7.z.string().optional().describe("The language of the input audio in ISO-639-1 format."),
|
|
1559
|
+
prompt: import_zod7.z.string().optional().describe(
|
|
1560
|
+
"An optional text to guide the model's style or continue a previous audio segment."
|
|
1561
|
+
),
|
|
1562
|
+
temperature: import_zod7.z.number().min(0).max(1).optional().default(0).describe("The sampling temperature, between 0 and 1."),
|
|
1563
|
+
timestampGranularities: import_zod7.z.array(import_zod7.z.enum(["word", "segment"])).optional().default(["segment"]).describe(
|
|
1564
|
+
"The timestamp granularities to populate for this transcription."
|
|
1565
|
+
)
|
|
1566
|
+
});
|
|
1567
|
+
var languageMap = {
|
|
1568
|
+
afrikaans: "af",
|
|
1569
|
+
arabic: "ar",
|
|
1570
|
+
armenian: "hy",
|
|
1571
|
+
azerbaijani: "az",
|
|
1572
|
+
belarusian: "be",
|
|
1573
|
+
bosnian: "bs",
|
|
1574
|
+
bulgarian: "bg",
|
|
1575
|
+
catalan: "ca",
|
|
1576
|
+
chinese: "zh",
|
|
1577
|
+
croatian: "hr",
|
|
1578
|
+
czech: "cs",
|
|
1579
|
+
danish: "da",
|
|
1580
|
+
dutch: "nl",
|
|
1581
|
+
english: "en",
|
|
1582
|
+
estonian: "et",
|
|
1583
|
+
finnish: "fi",
|
|
1584
|
+
french: "fr",
|
|
1585
|
+
galician: "gl",
|
|
1586
|
+
german: "de",
|
|
1587
|
+
greek: "el",
|
|
1588
|
+
hebrew: "he",
|
|
1589
|
+
hindi: "hi",
|
|
1590
|
+
hungarian: "hu",
|
|
1591
|
+
icelandic: "is",
|
|
1592
|
+
indonesian: "id",
|
|
1593
|
+
italian: "it",
|
|
1594
|
+
japanese: "ja",
|
|
1595
|
+
kannada: "kn",
|
|
1596
|
+
kazakh: "kk",
|
|
1597
|
+
korean: "ko",
|
|
1598
|
+
latvian: "lv",
|
|
1599
|
+
lithuanian: "lt",
|
|
1600
|
+
macedonian: "mk",
|
|
1601
|
+
malay: "ms",
|
|
1602
|
+
marathi: "mr",
|
|
1603
|
+
maori: "mi",
|
|
1604
|
+
nepali: "ne",
|
|
1605
|
+
norwegian: "no",
|
|
1606
|
+
persian: "fa",
|
|
1607
|
+
polish: "pl",
|
|
1608
|
+
portuguese: "pt",
|
|
1609
|
+
romanian: "ro",
|
|
1610
|
+
russian: "ru",
|
|
1611
|
+
serbian: "sr",
|
|
1612
|
+
slovak: "sk",
|
|
1613
|
+
slovenian: "sl",
|
|
1614
|
+
spanish: "es",
|
|
1615
|
+
swahili: "sw",
|
|
1616
|
+
swedish: "sv",
|
|
1617
|
+
tagalog: "tl",
|
|
1618
|
+
tamil: "ta",
|
|
1619
|
+
thai: "th",
|
|
1620
|
+
turkish: "tr",
|
|
1621
|
+
ukrainian: "uk",
|
|
1622
|
+
urdu: "ur",
|
|
1623
|
+
vietnamese: "vi",
|
|
1624
|
+
welsh: "cy"
|
|
1625
|
+
};
|
|
1626
|
+
var OpenAITranscriptionModel = class {
|
|
1627
|
+
constructor(modelId, config) {
|
|
1628
|
+
this.modelId = modelId;
|
|
1629
|
+
this.config = config;
|
|
1630
|
+
this.specificationVersion = "v1";
|
|
1631
|
+
}
|
|
1632
|
+
get provider() {
|
|
1633
|
+
return this.config.provider;
|
|
1634
|
+
}
|
|
1635
|
+
getArgs({
|
|
1636
|
+
audio,
|
|
1637
|
+
mediaType,
|
|
1638
|
+
providerOptions
|
|
1639
|
+
}) {
|
|
1640
|
+
const warnings = [];
|
|
1641
|
+
const openAIOptions = (0, import_provider_utils6.parseProviderOptions)({
|
|
1642
|
+
provider: "openai",
|
|
1643
|
+
providerOptions,
|
|
1644
|
+
schema: OpenAIProviderOptionsSchema
|
|
1645
|
+
});
|
|
1646
|
+
const formData = new FormData();
|
|
1647
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils6.convertBase64ToUint8Array)(audio)]);
|
|
1648
|
+
formData.append("model", this.modelId);
|
|
1649
|
+
formData.append("file", new File([blob], "audio", { type: mediaType }));
|
|
1650
|
+
if (openAIOptions) {
|
|
1651
|
+
const transcriptionModelOptions = {
|
|
1652
|
+
include: openAIOptions.include,
|
|
1653
|
+
language: openAIOptions.language,
|
|
1654
|
+
prompt: openAIOptions.prompt,
|
|
1655
|
+
temperature: openAIOptions.temperature,
|
|
1656
|
+
timestamp_granularities: openAIOptions.timestampGranularities
|
|
1657
|
+
};
|
|
1658
|
+
for (const key in transcriptionModelOptions) {
|
|
1659
|
+
const value = transcriptionModelOptions[key];
|
|
1660
|
+
if (value !== void 0) {
|
|
1661
|
+
formData.append(key, value);
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
return {
|
|
1666
|
+
formData,
|
|
1667
|
+
warnings
|
|
1668
|
+
};
|
|
1669
|
+
}
|
|
1670
|
+
async doGenerate(options) {
|
|
1671
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1672
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1673
|
+
const { formData, warnings } = this.getArgs(options);
|
|
1674
|
+
const {
|
|
1675
|
+
value: response,
|
|
1676
|
+
responseHeaders,
|
|
1677
|
+
rawValue: rawResponse
|
|
1678
|
+
} = await (0, import_provider_utils6.postFormDataToApi)({
|
|
1679
|
+
url: this.config.url({
|
|
1680
|
+
path: "/audio/transcriptions",
|
|
1681
|
+
modelId: this.modelId
|
|
1682
|
+
}),
|
|
1683
|
+
headers: (0, import_provider_utils6.combineHeaders)(this.config.headers(), options.headers),
|
|
1684
|
+
formData,
|
|
1685
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
1686
|
+
successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(
|
|
1687
|
+
openaiTranscriptionResponseSchema
|
|
1688
|
+
),
|
|
1689
|
+
abortSignal: options.abortSignal,
|
|
1690
|
+
fetch: this.config.fetch
|
|
1691
|
+
});
|
|
1692
|
+
const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
|
|
1693
|
+
return {
|
|
1694
|
+
text: response.text,
|
|
1695
|
+
segments: (_e = (_d = response.words) == null ? void 0 : _d.map((word) => ({
|
|
1696
|
+
text: word.word,
|
|
1697
|
+
startSecond: word.start,
|
|
1698
|
+
endSecond: word.end
|
|
1699
|
+
}))) != null ? _e : [],
|
|
1700
|
+
language,
|
|
1701
|
+
durationInSeconds: (_f = response.duration) != null ? _f : void 0,
|
|
1702
|
+
warnings,
|
|
1703
|
+
response: {
|
|
1704
|
+
timestamp: currentDate,
|
|
1705
|
+
modelId: this.modelId,
|
|
1706
|
+
headers: responseHeaders,
|
|
1707
|
+
body: rawResponse
|
|
1708
|
+
}
|
|
1709
|
+
};
|
|
1710
|
+
}
|
|
1711
|
+
};
|
|
1712
|
+
var openaiTranscriptionResponseSchema = import_zod7.z.object({
|
|
1713
|
+
text: import_zod7.z.string(),
|
|
1714
|
+
language: import_zod7.z.string().nullish(),
|
|
1715
|
+
duration: import_zod7.z.number().nullish(),
|
|
1716
|
+
words: import_zod7.z.array(
|
|
1717
|
+
import_zod7.z.object({
|
|
1718
|
+
word: import_zod7.z.string(),
|
|
1719
|
+
start: import_zod7.z.number(),
|
|
1720
|
+
end: import_zod7.z.number()
|
|
1721
|
+
})
|
|
1722
|
+
).nullish()
|
|
1723
|
+
});
|
|
1724
|
+
|
|
1725
|
+
// src/responses/openai-responses-language-model.ts
|
|
1726
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1727
|
+
var import_zod8 = require("zod");
|
|
1550
1728
|
|
|
1551
1729
|
// src/responses/convert-to-openai-responses-messages.ts
|
|
1552
1730
|
var import_provider6 = require("@ai-sdk/provider");
|
|
1553
|
-
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
|
1554
1731
|
function convertToOpenAIResponsesMessages({
|
|
1555
1732
|
prompt,
|
|
1556
1733
|
systemMessageMode
|
|
@@ -1589,38 +1766,35 @@ function convertToOpenAIResponsesMessages({
|
|
|
1589
1766
|
messages.push({
|
|
1590
1767
|
role: "user",
|
|
1591
1768
|
content: content.map((part, index) => {
|
|
1592
|
-
var _a, _b, _c
|
|
1769
|
+
var _a, _b, _c;
|
|
1593
1770
|
switch (part.type) {
|
|
1594
1771
|
case "text": {
|
|
1595
1772
|
return { type: "input_text", text: part.text };
|
|
1596
1773
|
}
|
|
1597
|
-
case "image": {
|
|
1598
|
-
return {
|
|
1599
|
-
type: "input_image",
|
|
1600
|
-
image_url: part.image instanceof URL ? part.image.toString() : `data:${(_a = part.mimeType) != null ? _a : "image/jpeg"};base64,${(0, import_provider_utils7.convertUint8ArrayToBase64)(part.image)}`,
|
|
1601
|
-
// OpenAI specific extension: image detail
|
|
1602
|
-
detail: (_c = (_b = part.providerOptions) == null ? void 0 : _b.openai) == null ? void 0 : _c.imageDetail
|
|
1603
|
-
};
|
|
1604
|
-
}
|
|
1605
1774
|
case "file": {
|
|
1606
|
-
if (part.
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
file_data: `data:application/pdf;base64,${part.data}`
|
|
1617
|
-
};
|
|
1618
|
-
}
|
|
1619
|
-
default: {
|
|
1775
|
+
if (part.mediaType.startsWith("image/")) {
|
|
1776
|
+
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
1777
|
+
return {
|
|
1778
|
+
type: "input_image",
|
|
1779
|
+
image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`,
|
|
1780
|
+
// OpenAI specific extension: image detail
|
|
1781
|
+
detail: (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.imageDetail
|
|
1782
|
+
};
|
|
1783
|
+
} else if (part.mediaType === "application/pdf") {
|
|
1784
|
+
if (part.data instanceof URL) {
|
|
1620
1785
|
throw new import_provider6.UnsupportedFunctionalityError({
|
|
1621
|
-
functionality: "
|
|
1786
|
+
functionality: "PDF file parts with URLs"
|
|
1622
1787
|
});
|
|
1623
1788
|
}
|
|
1789
|
+
return {
|
|
1790
|
+
type: "input_file",
|
|
1791
|
+
filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
|
|
1792
|
+
file_data: `data:application/pdf;base64,${part.data}`
|
|
1793
|
+
};
|
|
1794
|
+
} else {
|
|
1795
|
+
throw new import_provider6.UnsupportedFunctionalityError({
|
|
1796
|
+
functionality: `file part media type ${part.mediaType}`
|
|
1797
|
+
});
|
|
1624
1798
|
}
|
|
1625
1799
|
}
|
|
1626
1800
|
}
|
|
@@ -1749,7 +1923,7 @@ function prepareResponsesTools({
|
|
|
1749
1923
|
default: {
|
|
1750
1924
|
const _exhaustiveCheck = type;
|
|
1751
1925
|
throw new import_provider7.UnsupportedFunctionalityError({
|
|
1752
|
-
functionality: `
|
|
1926
|
+
functionality: `tool choice type: ${_exhaustiveCheck}`
|
|
1753
1927
|
});
|
|
1754
1928
|
}
|
|
1755
1929
|
}
|
|
@@ -1810,7 +1984,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1810
1984
|
systemMessageMode: modelConfig.systemMessageMode
|
|
1811
1985
|
});
|
|
1812
1986
|
warnings.push(...messageWarnings);
|
|
1813
|
-
const openaiOptions = (0,
|
|
1987
|
+
const openaiOptions = (0, import_provider_utils7.parseProviderOptions)({
|
|
1814
1988
|
provider: "openai",
|
|
1815
1989
|
providerOptions,
|
|
1816
1990
|
schema: openaiResponsesProviderOptionsSchema
|
|
@@ -1891,58 +2065,58 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1891
2065
|
responseHeaders,
|
|
1892
2066
|
value: response,
|
|
1893
2067
|
rawValue: rawResponse
|
|
1894
|
-
} = await (0,
|
|
2068
|
+
} = await (0, import_provider_utils7.postJsonToApi)({
|
|
1895
2069
|
url: this.config.url({
|
|
1896
2070
|
path: "/responses",
|
|
1897
2071
|
modelId: this.modelId
|
|
1898
2072
|
}),
|
|
1899
|
-
headers: (0,
|
|
2073
|
+
headers: (0, import_provider_utils7.combineHeaders)(this.config.headers(), options.headers),
|
|
1900
2074
|
body,
|
|
1901
2075
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
1902
|
-
successfulResponseHandler: (0,
|
|
1903
|
-
|
|
1904
|
-
id:
|
|
1905
|
-
created_at:
|
|
1906
|
-
model:
|
|
1907
|
-
output:
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
type:
|
|
1911
|
-
role:
|
|
1912
|
-
content:
|
|
1913
|
-
|
|
1914
|
-
type:
|
|
1915
|
-
text:
|
|
1916
|
-
annotations:
|
|
1917
|
-
|
|
1918
|
-
type:
|
|
1919
|
-
start_index:
|
|
1920
|
-
end_index:
|
|
1921
|
-
url:
|
|
1922
|
-
title:
|
|
2076
|
+
successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
|
|
2077
|
+
import_zod8.z.object({
|
|
2078
|
+
id: import_zod8.z.string(),
|
|
2079
|
+
created_at: import_zod8.z.number(),
|
|
2080
|
+
model: import_zod8.z.string(),
|
|
2081
|
+
output: import_zod8.z.array(
|
|
2082
|
+
import_zod8.z.discriminatedUnion("type", [
|
|
2083
|
+
import_zod8.z.object({
|
|
2084
|
+
type: import_zod8.z.literal("message"),
|
|
2085
|
+
role: import_zod8.z.literal("assistant"),
|
|
2086
|
+
content: import_zod8.z.array(
|
|
2087
|
+
import_zod8.z.object({
|
|
2088
|
+
type: import_zod8.z.literal("output_text"),
|
|
2089
|
+
text: import_zod8.z.string(),
|
|
2090
|
+
annotations: import_zod8.z.array(
|
|
2091
|
+
import_zod8.z.object({
|
|
2092
|
+
type: import_zod8.z.literal("url_citation"),
|
|
2093
|
+
start_index: import_zod8.z.number(),
|
|
2094
|
+
end_index: import_zod8.z.number(),
|
|
2095
|
+
url: import_zod8.z.string(),
|
|
2096
|
+
title: import_zod8.z.string()
|
|
1923
2097
|
})
|
|
1924
2098
|
)
|
|
1925
2099
|
})
|
|
1926
2100
|
)
|
|
1927
2101
|
}),
|
|
1928
|
-
|
|
1929
|
-
type:
|
|
1930
|
-
call_id:
|
|
1931
|
-
name:
|
|
1932
|
-
arguments:
|
|
2102
|
+
import_zod8.z.object({
|
|
2103
|
+
type: import_zod8.z.literal("function_call"),
|
|
2104
|
+
call_id: import_zod8.z.string(),
|
|
2105
|
+
name: import_zod8.z.string(),
|
|
2106
|
+
arguments: import_zod8.z.string()
|
|
1933
2107
|
}),
|
|
1934
|
-
|
|
1935
|
-
type:
|
|
2108
|
+
import_zod8.z.object({
|
|
2109
|
+
type: import_zod8.z.literal("web_search_call")
|
|
1936
2110
|
}),
|
|
1937
|
-
|
|
1938
|
-
type:
|
|
2111
|
+
import_zod8.z.object({
|
|
2112
|
+
type: import_zod8.z.literal("computer_call")
|
|
1939
2113
|
}),
|
|
1940
|
-
|
|
1941
|
-
type:
|
|
2114
|
+
import_zod8.z.object({
|
|
2115
|
+
type: import_zod8.z.literal("reasoning")
|
|
1942
2116
|
})
|
|
1943
2117
|
])
|
|
1944
2118
|
),
|
|
1945
|
-
incomplete_details:
|
|
2119
|
+
incomplete_details: import_zod8.z.object({ reason: import_zod8.z.string() }).nullable(),
|
|
1946
2120
|
usage: usageSchema
|
|
1947
2121
|
})
|
|
1948
2122
|
),
|
|
@@ -1963,7 +2137,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
1963
2137
|
var _a2, _b2, _c2;
|
|
1964
2138
|
return {
|
|
1965
2139
|
sourceType: "url",
|
|
1966
|
-
id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : (0,
|
|
2140
|
+
id: (_c2 = (_b2 = (_a2 = this.config).generateId) == null ? void 0 : _b2.call(_a2)) != null ? _c2 : (0, import_provider_utils7.generateId)(),
|
|
1967
2141
|
url: annotation.url,
|
|
1968
2142
|
title: annotation.title
|
|
1969
2143
|
};
|
|
@@ -2006,18 +2180,18 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2006
2180
|
}
|
|
2007
2181
|
async doStream(options) {
|
|
2008
2182
|
const { args: body, warnings } = this.getArgs(options);
|
|
2009
|
-
const { responseHeaders, value: response } = await (0,
|
|
2183
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils7.postJsonToApi)({
|
|
2010
2184
|
url: this.config.url({
|
|
2011
2185
|
path: "/responses",
|
|
2012
2186
|
modelId: this.modelId
|
|
2013
2187
|
}),
|
|
2014
|
-
headers: (0,
|
|
2188
|
+
headers: (0, import_provider_utils7.combineHeaders)(this.config.headers(), options.headers),
|
|
2015
2189
|
body: {
|
|
2016
2190
|
...body,
|
|
2017
2191
|
stream: true
|
|
2018
2192
|
},
|
|
2019
2193
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2020
|
-
successfulResponseHandler: (0,
|
|
2194
|
+
successfulResponseHandler: (0, import_provider_utils7.createEventSourceResponseHandler)(
|
|
2021
2195
|
openaiResponsesChunkSchema
|
|
2022
2196
|
),
|
|
2023
2197
|
abortSignal: options.abortSignal,
|
|
@@ -2105,7 +2279,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2105
2279
|
type: "source",
|
|
2106
2280
|
source: {
|
|
2107
2281
|
sourceType: "url",
|
|
2108
|
-
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0,
|
|
2282
|
+
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils7.generateId)(),
|
|
2109
2283
|
url: value.annotation.url,
|
|
2110
2284
|
title: value.annotation.title
|
|
2111
2285
|
}
|
|
@@ -2140,79 +2314,79 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2140
2314
|
};
|
|
2141
2315
|
}
|
|
2142
2316
|
};
|
|
2143
|
-
var usageSchema =
|
|
2144
|
-
input_tokens:
|
|
2145
|
-
input_tokens_details:
|
|
2146
|
-
output_tokens:
|
|
2147
|
-
output_tokens_details:
|
|
2317
|
+
var usageSchema = import_zod8.z.object({
|
|
2318
|
+
input_tokens: import_zod8.z.number(),
|
|
2319
|
+
input_tokens_details: import_zod8.z.object({ cached_tokens: import_zod8.z.number().nullish() }).nullish(),
|
|
2320
|
+
output_tokens: import_zod8.z.number(),
|
|
2321
|
+
output_tokens_details: import_zod8.z.object({ reasoning_tokens: import_zod8.z.number().nullish() }).nullish()
|
|
2148
2322
|
});
|
|
2149
|
-
var textDeltaChunkSchema =
|
|
2150
|
-
type:
|
|
2151
|
-
delta:
|
|
2323
|
+
var textDeltaChunkSchema = import_zod8.z.object({
|
|
2324
|
+
type: import_zod8.z.literal("response.output_text.delta"),
|
|
2325
|
+
delta: import_zod8.z.string()
|
|
2152
2326
|
});
|
|
2153
|
-
var responseFinishedChunkSchema =
|
|
2154
|
-
type:
|
|
2155
|
-
response:
|
|
2156
|
-
incomplete_details:
|
|
2327
|
+
var responseFinishedChunkSchema = import_zod8.z.object({
|
|
2328
|
+
type: import_zod8.z.enum(["response.completed", "response.incomplete"]),
|
|
2329
|
+
response: import_zod8.z.object({
|
|
2330
|
+
incomplete_details: import_zod8.z.object({ reason: import_zod8.z.string() }).nullish(),
|
|
2157
2331
|
usage: usageSchema
|
|
2158
2332
|
})
|
|
2159
2333
|
});
|
|
2160
|
-
var responseCreatedChunkSchema =
|
|
2161
|
-
type:
|
|
2162
|
-
response:
|
|
2163
|
-
id:
|
|
2164
|
-
created_at:
|
|
2165
|
-
model:
|
|
2334
|
+
var responseCreatedChunkSchema = import_zod8.z.object({
|
|
2335
|
+
type: import_zod8.z.literal("response.created"),
|
|
2336
|
+
response: import_zod8.z.object({
|
|
2337
|
+
id: import_zod8.z.string(),
|
|
2338
|
+
created_at: import_zod8.z.number(),
|
|
2339
|
+
model: import_zod8.z.string()
|
|
2166
2340
|
})
|
|
2167
2341
|
});
|
|
2168
|
-
var responseOutputItemDoneSchema =
|
|
2169
|
-
type:
|
|
2170
|
-
output_index:
|
|
2171
|
-
item:
|
|
2172
|
-
|
|
2173
|
-
type:
|
|
2342
|
+
var responseOutputItemDoneSchema = import_zod8.z.object({
|
|
2343
|
+
type: import_zod8.z.literal("response.output_item.done"),
|
|
2344
|
+
output_index: import_zod8.z.number(),
|
|
2345
|
+
item: import_zod8.z.discriminatedUnion("type", [
|
|
2346
|
+
import_zod8.z.object({
|
|
2347
|
+
type: import_zod8.z.literal("message")
|
|
2174
2348
|
}),
|
|
2175
|
-
|
|
2176
|
-
type:
|
|
2177
|
-
id:
|
|
2178
|
-
call_id:
|
|
2179
|
-
name:
|
|
2180
|
-
arguments:
|
|
2181
|
-
status:
|
|
2349
|
+
import_zod8.z.object({
|
|
2350
|
+
type: import_zod8.z.literal("function_call"),
|
|
2351
|
+
id: import_zod8.z.string(),
|
|
2352
|
+
call_id: import_zod8.z.string(),
|
|
2353
|
+
name: import_zod8.z.string(),
|
|
2354
|
+
arguments: import_zod8.z.string(),
|
|
2355
|
+
status: import_zod8.z.literal("completed")
|
|
2182
2356
|
})
|
|
2183
2357
|
])
|
|
2184
2358
|
});
|
|
2185
|
-
var responseFunctionCallArgumentsDeltaSchema =
|
|
2186
|
-
type:
|
|
2187
|
-
item_id:
|
|
2188
|
-
output_index:
|
|
2189
|
-
delta:
|
|
2359
|
+
var responseFunctionCallArgumentsDeltaSchema = import_zod8.z.object({
|
|
2360
|
+
type: import_zod8.z.literal("response.function_call_arguments.delta"),
|
|
2361
|
+
item_id: import_zod8.z.string(),
|
|
2362
|
+
output_index: import_zod8.z.number(),
|
|
2363
|
+
delta: import_zod8.z.string()
|
|
2190
2364
|
});
|
|
2191
|
-
var responseOutputItemAddedSchema =
|
|
2192
|
-
type:
|
|
2193
|
-
output_index:
|
|
2194
|
-
item:
|
|
2195
|
-
|
|
2196
|
-
type:
|
|
2365
|
+
var responseOutputItemAddedSchema = import_zod8.z.object({
|
|
2366
|
+
type: import_zod8.z.literal("response.output_item.added"),
|
|
2367
|
+
output_index: import_zod8.z.number(),
|
|
2368
|
+
item: import_zod8.z.discriminatedUnion("type", [
|
|
2369
|
+
import_zod8.z.object({
|
|
2370
|
+
type: import_zod8.z.literal("message")
|
|
2197
2371
|
}),
|
|
2198
|
-
|
|
2199
|
-
type:
|
|
2200
|
-
id:
|
|
2201
|
-
call_id:
|
|
2202
|
-
name:
|
|
2203
|
-
arguments:
|
|
2372
|
+
import_zod8.z.object({
|
|
2373
|
+
type: import_zod8.z.literal("function_call"),
|
|
2374
|
+
id: import_zod8.z.string(),
|
|
2375
|
+
call_id: import_zod8.z.string(),
|
|
2376
|
+
name: import_zod8.z.string(),
|
|
2377
|
+
arguments: import_zod8.z.string()
|
|
2204
2378
|
})
|
|
2205
2379
|
])
|
|
2206
2380
|
});
|
|
2207
|
-
var responseAnnotationAddedSchema =
|
|
2208
|
-
type:
|
|
2209
|
-
annotation:
|
|
2210
|
-
type:
|
|
2211
|
-
url:
|
|
2212
|
-
title:
|
|
2381
|
+
var responseAnnotationAddedSchema = import_zod8.z.object({
|
|
2382
|
+
type: import_zod8.z.literal("response.output_text.annotation.added"),
|
|
2383
|
+
annotation: import_zod8.z.object({
|
|
2384
|
+
type: import_zod8.z.literal("url_citation"),
|
|
2385
|
+
url: import_zod8.z.string(),
|
|
2386
|
+
title: import_zod8.z.string()
|
|
2213
2387
|
})
|
|
2214
2388
|
});
|
|
2215
|
-
var openaiResponsesChunkSchema =
|
|
2389
|
+
var openaiResponsesChunkSchema = import_zod8.z.union([
|
|
2216
2390
|
textDeltaChunkSchema,
|
|
2217
2391
|
responseFinishedChunkSchema,
|
|
2218
2392
|
responseCreatedChunkSchema,
|
|
@@ -2220,7 +2394,7 @@ var openaiResponsesChunkSchema = import_zod7.z.union([
|
|
|
2220
2394
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2221
2395
|
responseOutputItemAddedSchema,
|
|
2222
2396
|
responseAnnotationAddedSchema,
|
|
2223
|
-
|
|
2397
|
+
import_zod8.z.object({ type: import_zod8.z.string() }).passthrough()
|
|
2224
2398
|
// fallback for unknown chunks
|
|
2225
2399
|
]);
|
|
2226
2400
|
function isTextDeltaChunk(chunk) {
|
|
@@ -2265,25 +2439,25 @@ function getResponsesModelConfig(modelId) {
|
|
|
2265
2439
|
requiredAutoTruncation: false
|
|
2266
2440
|
};
|
|
2267
2441
|
}
|
|
2268
|
-
var openaiResponsesProviderOptionsSchema =
|
|
2269
|
-
metadata:
|
|
2270
|
-
parallelToolCalls:
|
|
2271
|
-
previousResponseId:
|
|
2272
|
-
store:
|
|
2273
|
-
user:
|
|
2274
|
-
reasoningEffort:
|
|
2275
|
-
strictSchemas:
|
|
2276
|
-
instructions:
|
|
2442
|
+
var openaiResponsesProviderOptionsSchema = import_zod8.z.object({
|
|
2443
|
+
metadata: import_zod8.z.any().nullish(),
|
|
2444
|
+
parallelToolCalls: import_zod8.z.boolean().nullish(),
|
|
2445
|
+
previousResponseId: import_zod8.z.string().nullish(),
|
|
2446
|
+
store: import_zod8.z.boolean().nullish(),
|
|
2447
|
+
user: import_zod8.z.string().nullish(),
|
|
2448
|
+
reasoningEffort: import_zod8.z.string().nullish(),
|
|
2449
|
+
strictSchemas: import_zod8.z.boolean().nullish(),
|
|
2450
|
+
instructions: import_zod8.z.string().nullish()
|
|
2277
2451
|
});
|
|
2278
2452
|
|
|
2279
2453
|
// src/openai-provider.ts
|
|
2280
2454
|
function createOpenAI(options = {}) {
|
|
2281
2455
|
var _a, _b, _c;
|
|
2282
|
-
const baseURL = (_a = (0,
|
|
2456
|
+
const baseURL = (_a = (0, import_provider_utils8.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.openai.com/v1";
|
|
2283
2457
|
const compatibility = (_b = options.compatibility) != null ? _b : "compatible";
|
|
2284
2458
|
const providerName = (_c = options.name) != null ? _c : "openai";
|
|
2285
2459
|
const getHeaders = () => ({
|
|
2286
|
-
Authorization: `Bearer ${(0,
|
|
2460
|
+
Authorization: `Bearer ${(0, import_provider_utils8.loadApiKey)({
|
|
2287
2461
|
apiKey: options.apiKey,
|
|
2288
2462
|
environmentVariableName: "OPENAI_API_KEY",
|
|
2289
2463
|
description: "OpenAI"
|
|
@@ -2318,6 +2492,12 @@ function createOpenAI(options = {}) {
|
|
|
2318
2492
|
headers: getHeaders,
|
|
2319
2493
|
fetch: options.fetch
|
|
2320
2494
|
});
|
|
2495
|
+
const createTranscriptionModel = (modelId) => new OpenAITranscriptionModel(modelId, {
|
|
2496
|
+
provider: `${providerName}.transcription`,
|
|
2497
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
2498
|
+
headers: getHeaders,
|
|
2499
|
+
fetch: options.fetch
|
|
2500
|
+
});
|
|
2321
2501
|
const createLanguageModel = (modelId, settings) => {
|
|
2322
2502
|
if (new.target) {
|
|
2323
2503
|
throw new Error(
|
|
@@ -2352,6 +2532,8 @@ function createOpenAI(options = {}) {
|
|
|
2352
2532
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
2353
2533
|
provider.image = createImageModel;
|
|
2354
2534
|
provider.imageModel = createImageModel;
|
|
2535
|
+
provider.transcription = createTranscriptionModel;
|
|
2536
|
+
provider.transcriptionModel = createTranscriptionModel;
|
|
2355
2537
|
provider.tools = openaiTools;
|
|
2356
2538
|
return provider;
|
|
2357
2539
|
}
|