@ai-sdk/openai 2.0.29 → 2.0.30
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 +7 -0
- package/dist/index.js +45 -44
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -16
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +34 -33
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +17 -16
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ __export(src_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(src_exports);
|
|
27
27
|
|
|
28
28
|
// src/openai-provider.ts
|
|
29
|
-
var
|
|
29
|
+
var import_provider_utils15 = require("@ai-sdk/provider-utils");
|
|
30
30
|
|
|
31
31
|
// src/chat/openai-chat-language-model.ts
|
|
32
32
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -1922,36 +1922,35 @@ var openaiTools = {
|
|
|
1922
1922
|
|
|
1923
1923
|
// src/responses/openai-responses-language-model.ts
|
|
1924
1924
|
var import_provider8 = require("@ai-sdk/provider");
|
|
1925
|
-
var
|
|
1925
|
+
var import_provider_utils12 = require("@ai-sdk/provider-utils");
|
|
1926
1926
|
var import_v414 = require("zod/v4");
|
|
1927
1927
|
|
|
1928
|
-
// src/responses/convert-to-openai-responses-
|
|
1928
|
+
// src/responses/convert-to-openai-responses-input.ts
|
|
1929
1929
|
var import_provider6 = require("@ai-sdk/provider");
|
|
1930
1930
|
var import_provider_utils11 = require("@ai-sdk/provider-utils");
|
|
1931
1931
|
var import_v413 = require("zod/v4");
|
|
1932
|
-
var import_provider_utils12 = require("@ai-sdk/provider-utils");
|
|
1933
1932
|
function isFileId(data, prefixes) {
|
|
1934
1933
|
if (!prefixes) return false;
|
|
1935
1934
|
return prefixes.some((prefix) => data.startsWith(prefix));
|
|
1936
1935
|
}
|
|
1937
|
-
async function
|
|
1936
|
+
async function convertToOpenAIResponsesInput({
|
|
1938
1937
|
prompt,
|
|
1939
1938
|
systemMessageMode,
|
|
1940
1939
|
fileIdPrefixes
|
|
1941
1940
|
}) {
|
|
1942
1941
|
var _a, _b, _c, _d, _e, _f;
|
|
1943
|
-
const
|
|
1942
|
+
const input = [];
|
|
1944
1943
|
const warnings = [];
|
|
1945
1944
|
for (const { role, content } of prompt) {
|
|
1946
1945
|
switch (role) {
|
|
1947
1946
|
case "system": {
|
|
1948
1947
|
switch (systemMessageMode) {
|
|
1949
1948
|
case "system": {
|
|
1950
|
-
|
|
1949
|
+
input.push({ role: "system", content });
|
|
1951
1950
|
break;
|
|
1952
1951
|
}
|
|
1953
1952
|
case "developer": {
|
|
1954
|
-
|
|
1953
|
+
input.push({ role: "developer", content });
|
|
1955
1954
|
break;
|
|
1956
1955
|
}
|
|
1957
1956
|
case "remove": {
|
|
@@ -1971,7 +1970,7 @@ async function convertToOpenAIResponsesMessages({
|
|
|
1971
1970
|
break;
|
|
1972
1971
|
}
|
|
1973
1972
|
case "user": {
|
|
1974
|
-
|
|
1973
|
+
input.push({
|
|
1975
1974
|
role: "user",
|
|
1976
1975
|
content: content.map((part, index) => {
|
|
1977
1976
|
var _a2, _b2, _c2;
|
|
@@ -1985,7 +1984,7 @@ async function convertToOpenAIResponsesMessages({
|
|
|
1985
1984
|
return {
|
|
1986
1985
|
type: "input_image",
|
|
1987
1986
|
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
1988
|
-
image_url: `data:${mediaType};base64,${(0,
|
|
1987
|
+
image_url: `data:${mediaType};base64,${(0, import_provider_utils11.convertToBase64)(part.data)}`
|
|
1989
1988
|
},
|
|
1990
1989
|
detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b2.imageDetail
|
|
1991
1990
|
};
|
|
@@ -2000,7 +1999,7 @@ async function convertToOpenAIResponsesMessages({
|
|
|
2000
1999
|
type: "input_file",
|
|
2001
2000
|
...typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
2002
2001
|
filename: (_c2 = part.filename) != null ? _c2 : `part-${index}.pdf`,
|
|
2003
|
-
file_data: `data:application/pdf;base64,${(0,
|
|
2002
|
+
file_data: `data:application/pdf;base64,${(0, import_provider_utils11.convertToBase64)(part.data)}`
|
|
2004
2003
|
}
|
|
2005
2004
|
};
|
|
2006
2005
|
} else {
|
|
@@ -2016,10 +2015,11 @@ async function convertToOpenAIResponsesMessages({
|
|
|
2016
2015
|
}
|
|
2017
2016
|
case "assistant": {
|
|
2018
2017
|
const reasoningMessages = {};
|
|
2018
|
+
const toolCallParts = {};
|
|
2019
2019
|
for (const part of content) {
|
|
2020
2020
|
switch (part.type) {
|
|
2021
2021
|
case "text": {
|
|
2022
|
-
|
|
2022
|
+
input.push({
|
|
2023
2023
|
role: "assistant",
|
|
2024
2024
|
content: [{ type: "output_text", text: part.text }],
|
|
2025
2025
|
id: (_c = (_b = (_a = part.providerOptions) == null ? void 0 : _a.openai) == null ? void 0 : _b.itemId) != null ? _c : void 0
|
|
@@ -2027,10 +2027,11 @@ async function convertToOpenAIResponsesMessages({
|
|
|
2027
2027
|
break;
|
|
2028
2028
|
}
|
|
2029
2029
|
case "tool-call": {
|
|
2030
|
+
toolCallParts[part.toolCallId] = part;
|
|
2030
2031
|
if (part.providerExecuted) {
|
|
2031
2032
|
break;
|
|
2032
2033
|
}
|
|
2033
|
-
|
|
2034
|
+
input.push({
|
|
2034
2035
|
type: "function_call",
|
|
2035
2036
|
call_id: part.toolCallId,
|
|
2036
2037
|
name: part.toolName,
|
|
@@ -2071,7 +2072,7 @@ async function convertToOpenAIResponsesMessages({
|
|
|
2071
2072
|
encrypted_content: providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent,
|
|
2072
2073
|
summary: summaryParts
|
|
2073
2074
|
};
|
|
2074
|
-
|
|
2075
|
+
input.push(reasoningMessages[reasoningId]);
|
|
2075
2076
|
} else {
|
|
2076
2077
|
existingReasoningMessage.summary.push(...summaryParts);
|
|
2077
2078
|
}
|
|
@@ -2102,7 +2103,7 @@ async function convertToOpenAIResponsesMessages({
|
|
|
2102
2103
|
contentValue = JSON.stringify(output.value);
|
|
2103
2104
|
break;
|
|
2104
2105
|
}
|
|
2105
|
-
|
|
2106
|
+
input.push({
|
|
2106
2107
|
type: "function_call_output",
|
|
2107
2108
|
call_id: part.toolCallId,
|
|
2108
2109
|
output: contentValue
|
|
@@ -2116,7 +2117,7 @@ async function convertToOpenAIResponsesMessages({
|
|
|
2116
2117
|
}
|
|
2117
2118
|
}
|
|
2118
2119
|
}
|
|
2119
|
-
return {
|
|
2120
|
+
return { input, warnings };
|
|
2120
2121
|
}
|
|
2121
2122
|
var openaiResponsesReasoningProviderOptionsSchema = import_v413.z.object({
|
|
2122
2123
|
itemId: import_v413.z.string().nullish(),
|
|
@@ -2339,13 +2340,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2339
2340
|
if (stopSequences != null) {
|
|
2340
2341
|
warnings.push({ type: "unsupported-setting", setting: "stopSequences" });
|
|
2341
2342
|
}
|
|
2342
|
-
const {
|
|
2343
|
+
const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
|
|
2343
2344
|
prompt,
|
|
2344
2345
|
systemMessageMode: modelConfig.systemMessageMode,
|
|
2345
2346
|
fileIdPrefixes: this.config.fileIdPrefixes
|
|
2346
2347
|
});
|
|
2347
|
-
warnings.push(...
|
|
2348
|
-
const openaiOptions = await (0,
|
|
2348
|
+
warnings.push(...inputWarnings);
|
|
2349
|
+
const openaiOptions = await (0, import_provider_utils12.parseProviderOptions)({
|
|
2349
2350
|
provider: "openai",
|
|
2350
2351
|
providerOptions,
|
|
2351
2352
|
schema: openaiResponsesProviderOptionsSchema
|
|
@@ -2364,7 +2365,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2364
2365
|
include = codeInterpreterToolName ? Array.isArray(include) ? [...include, "code_interpreter_call.outputs"] : ["code_interpreter_call.outputs"] : include;
|
|
2365
2366
|
const baseArgs = {
|
|
2366
2367
|
model: this.modelId,
|
|
2367
|
-
input
|
|
2368
|
+
input,
|
|
2368
2369
|
temperature,
|
|
2369
2370
|
top_p: topP,
|
|
2370
2371
|
max_output_tokens: maxOutputTokens,
|
|
@@ -2494,12 +2495,12 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2494
2495
|
responseHeaders,
|
|
2495
2496
|
value: response,
|
|
2496
2497
|
rawValue: rawResponse
|
|
2497
|
-
} = await (0,
|
|
2498
|
+
} = await (0, import_provider_utils12.postJsonToApi)({
|
|
2498
2499
|
url,
|
|
2499
|
-
headers: (0,
|
|
2500
|
+
headers: (0, import_provider_utils12.combineHeaders)(this.config.headers(), options.headers),
|
|
2500
2501
|
body,
|
|
2501
2502
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2502
|
-
successfulResponseHandler: (0,
|
|
2503
|
+
successfulResponseHandler: (0, import_provider_utils12.createJsonResponseHandler)(
|
|
2503
2504
|
import_v414.z.object({
|
|
2504
2505
|
id: import_v414.z.string(),
|
|
2505
2506
|
created_at: import_v414.z.number(),
|
|
@@ -2649,7 +2650,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2649
2650
|
content.push({
|
|
2650
2651
|
type: "source",
|
|
2651
2652
|
sourceType: "url",
|
|
2652
|
-
id: (_f = (_e = (_d = this.config).generateId) == null ? void 0 : _e.call(_d)) != null ? _f : (0,
|
|
2653
|
+
id: (_f = (_e = (_d = this.config).generateId) == null ? void 0 : _e.call(_d)) != null ? _f : (0, import_provider_utils12.generateId)(),
|
|
2653
2654
|
url: annotation.url,
|
|
2654
2655
|
title: annotation.title
|
|
2655
2656
|
});
|
|
@@ -2657,7 +2658,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2657
2658
|
content.push({
|
|
2658
2659
|
type: "source",
|
|
2659
2660
|
sourceType: "document",
|
|
2660
|
-
id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : (0,
|
|
2661
|
+
id: (_i = (_h = (_g = this.config).generateId) == null ? void 0 : _h.call(_g)) != null ? _i : (0, import_provider_utils12.generateId)(),
|
|
2661
2662
|
mediaType: "text/plain",
|
|
2662
2663
|
title: (_k = (_j = annotation.quote) != null ? _j : annotation.filename) != null ? _k : "Document",
|
|
2663
2664
|
filename: (_l = annotation.filename) != null ? _l : annotation.file_id
|
|
@@ -2805,18 +2806,18 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2805
2806
|
warnings,
|
|
2806
2807
|
webSearchToolName
|
|
2807
2808
|
} = await this.getArgs(options);
|
|
2808
|
-
const { responseHeaders, value: response } = await (0,
|
|
2809
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils12.postJsonToApi)({
|
|
2809
2810
|
url: this.config.url({
|
|
2810
2811
|
path: "/responses",
|
|
2811
2812
|
modelId: this.modelId
|
|
2812
2813
|
}),
|
|
2813
|
-
headers: (0,
|
|
2814
|
+
headers: (0, import_provider_utils12.combineHeaders)(this.config.headers(), options.headers),
|
|
2814
2815
|
body: {
|
|
2815
2816
|
...body,
|
|
2816
2817
|
stream: true
|
|
2817
2818
|
},
|
|
2818
2819
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2819
|
-
successfulResponseHandler: (0,
|
|
2820
|
+
successfulResponseHandler: (0, import_provider_utils12.createEventSourceResponseHandler)(
|
|
2820
2821
|
openaiResponsesChunkSchema
|
|
2821
2822
|
),
|
|
2822
2823
|
abortSignal: options.abortSignal,
|
|
@@ -3118,7 +3119,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3118
3119
|
controller.enqueue({
|
|
3119
3120
|
type: "source",
|
|
3120
3121
|
sourceType: "url",
|
|
3121
|
-
id: (_o = (_n = (_m = self.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : (0,
|
|
3122
|
+
id: (_o = (_n = (_m = self.config).generateId) == null ? void 0 : _n.call(_m)) != null ? _o : (0, import_provider_utils12.generateId)(),
|
|
3122
3123
|
url: value.annotation.url,
|
|
3123
3124
|
title: value.annotation.title
|
|
3124
3125
|
});
|
|
@@ -3126,7 +3127,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
3126
3127
|
controller.enqueue({
|
|
3127
3128
|
type: "source",
|
|
3128
3129
|
sourceType: "document",
|
|
3129
|
-
id: (_r = (_q = (_p = self.config).generateId) == null ? void 0 : _q.call(_p)) != null ? _r : (0,
|
|
3130
|
+
id: (_r = (_q = (_p = self.config).generateId) == null ? void 0 : _q.call(_p)) != null ? _r : (0, import_provider_utils12.generateId)(),
|
|
3130
3131
|
mediaType: "text/plain",
|
|
3131
3132
|
title: (_t = (_s = value.annotation.quote) != null ? _s : value.annotation.filename) != null ? _t : "Document",
|
|
3132
3133
|
filename: (_u = value.annotation.filename) != null ? _u : value.annotation.file_id
|
|
@@ -3453,7 +3454,7 @@ var openaiResponsesProviderOptionsSchema = import_v414.z.object({
|
|
|
3453
3454
|
});
|
|
3454
3455
|
|
|
3455
3456
|
// src/speech/openai-speech-model.ts
|
|
3456
|
-
var
|
|
3457
|
+
var import_provider_utils13 = require("@ai-sdk/provider-utils");
|
|
3457
3458
|
var import_v415 = require("zod/v4");
|
|
3458
3459
|
var OpenAIProviderOptionsSchema = import_v415.z.object({
|
|
3459
3460
|
instructions: import_v415.z.string().nullish(),
|
|
@@ -3478,7 +3479,7 @@ var OpenAISpeechModel = class {
|
|
|
3478
3479
|
providerOptions
|
|
3479
3480
|
}) {
|
|
3480
3481
|
const warnings = [];
|
|
3481
|
-
const openAIOptions = await (0,
|
|
3482
|
+
const openAIOptions = await (0, import_provider_utils13.parseProviderOptions)({
|
|
3482
3483
|
provider: "openai",
|
|
3483
3484
|
providerOptions,
|
|
3484
3485
|
schema: OpenAIProviderOptionsSchema
|
|
@@ -3531,15 +3532,15 @@ var OpenAISpeechModel = class {
|
|
|
3531
3532
|
value: audio,
|
|
3532
3533
|
responseHeaders,
|
|
3533
3534
|
rawValue: rawResponse
|
|
3534
|
-
} = await (0,
|
|
3535
|
+
} = await (0, import_provider_utils13.postJsonToApi)({
|
|
3535
3536
|
url: this.config.url({
|
|
3536
3537
|
path: "/audio/speech",
|
|
3537
3538
|
modelId: this.modelId
|
|
3538
3539
|
}),
|
|
3539
|
-
headers: (0,
|
|
3540
|
+
headers: (0, import_provider_utils13.combineHeaders)(this.config.headers(), options.headers),
|
|
3540
3541
|
body: requestBody,
|
|
3541
3542
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
3542
|
-
successfulResponseHandler: (0,
|
|
3543
|
+
successfulResponseHandler: (0, import_provider_utils13.createBinaryResponseHandler)(),
|
|
3543
3544
|
abortSignal: options.abortSignal,
|
|
3544
3545
|
fetch: this.config.fetch
|
|
3545
3546
|
});
|
|
@@ -3560,7 +3561,7 @@ var OpenAISpeechModel = class {
|
|
|
3560
3561
|
};
|
|
3561
3562
|
|
|
3562
3563
|
// src/transcription/openai-transcription-model.ts
|
|
3563
|
-
var
|
|
3564
|
+
var import_provider_utils14 = require("@ai-sdk/provider-utils");
|
|
3564
3565
|
var import_v417 = require("zod/v4");
|
|
3565
3566
|
|
|
3566
3567
|
// src/transcription/openai-transcription-options.ts
|
|
@@ -3665,15 +3666,15 @@ var OpenAITranscriptionModel = class {
|
|
|
3665
3666
|
providerOptions
|
|
3666
3667
|
}) {
|
|
3667
3668
|
const warnings = [];
|
|
3668
|
-
const openAIOptions = await (0,
|
|
3669
|
+
const openAIOptions = await (0, import_provider_utils14.parseProviderOptions)({
|
|
3669
3670
|
provider: "openai",
|
|
3670
3671
|
providerOptions,
|
|
3671
3672
|
schema: openAITranscriptionProviderOptions
|
|
3672
3673
|
});
|
|
3673
3674
|
const formData = new FormData();
|
|
3674
|
-
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0,
|
|
3675
|
+
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils14.convertBase64ToUint8Array)(audio)]);
|
|
3675
3676
|
formData.append("model", this.modelId);
|
|
3676
|
-
const fileExtension = (0,
|
|
3677
|
+
const fileExtension = (0, import_provider_utils14.mediaTypeToExtension)(mediaType);
|
|
3677
3678
|
formData.append(
|
|
3678
3679
|
"file",
|
|
3679
3680
|
new File([blob], "audio", { type: mediaType }),
|
|
@@ -3718,15 +3719,15 @@ var OpenAITranscriptionModel = class {
|
|
|
3718
3719
|
value: response,
|
|
3719
3720
|
responseHeaders,
|
|
3720
3721
|
rawValue: rawResponse
|
|
3721
|
-
} = await (0,
|
|
3722
|
+
} = await (0, import_provider_utils14.postFormDataToApi)({
|
|
3722
3723
|
url: this.config.url({
|
|
3723
3724
|
path: "/audio/transcriptions",
|
|
3724
3725
|
modelId: this.modelId
|
|
3725
3726
|
}),
|
|
3726
|
-
headers: (0,
|
|
3727
|
+
headers: (0, import_provider_utils14.combineHeaders)(this.config.headers(), options.headers),
|
|
3727
3728
|
formData,
|
|
3728
3729
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
3729
|
-
successfulResponseHandler: (0,
|
|
3730
|
+
successfulResponseHandler: (0, import_provider_utils14.createJsonResponseHandler)(
|
|
3730
3731
|
openaiTranscriptionResponseSchema
|
|
3731
3732
|
),
|
|
3732
3733
|
abortSignal: options.abortSignal,
|
|
@@ -3786,10 +3787,10 @@ var openaiTranscriptionResponseSchema = import_v417.z.object({
|
|
|
3786
3787
|
// src/openai-provider.ts
|
|
3787
3788
|
function createOpenAI(options = {}) {
|
|
3788
3789
|
var _a, _b;
|
|
3789
|
-
const baseURL = (_a = (0,
|
|
3790
|
+
const baseURL = (_a = (0, import_provider_utils15.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://api.openai.com/v1";
|
|
3790
3791
|
const providerName = (_b = options.name) != null ? _b : "openai";
|
|
3791
3792
|
const getHeaders = () => ({
|
|
3792
|
-
Authorization: `Bearer ${(0,
|
|
3793
|
+
Authorization: `Bearer ${(0, import_provider_utils15.loadApiKey)({
|
|
3793
3794
|
apiKey: options.apiKey,
|
|
3794
3795
|
environmentVariableName: "OPENAI_API_KEY",
|
|
3795
3796
|
description: "OpenAI"
|