@ai-sdk/openai 4.0.0-beta.20 → 4.0.0-beta.21
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 +9 -0
- package/dist/index.d.mts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +1299 -1162
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1270 -1121
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +5 -5
- package/dist/internal/index.d.ts +5 -5
- package/dist/internal/index.js +32 -5
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +39 -6
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/chat/convert-to-openai-chat-messages.ts +21 -10
- package/src/files/openai-files-api.ts +17 -0
- package/src/files/openai-files-options.ts +18 -0
- package/src/files/openai-files.ts +102 -0
- package/src/index.ts +1 -0
- package/src/openai-config.ts +5 -5
- package/src/openai-provider.ts +18 -0
- package/src/responses/convert-to-openai-responses-input.ts +29 -2
|
@@ -89,12 +89,12 @@ type OpenAIConfig = {
|
|
|
89
89
|
fetch?: FetchFunction;
|
|
90
90
|
generateId?: () => string;
|
|
91
91
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
92
|
+
* This is soft-deprecated. Use provider references (e.g. `{ openai: 'file-abc123' }`)
|
|
93
|
+
* in file part data instead. File ID prefixes used to identify file IDs
|
|
94
|
+
* in Responses API. When undefined, all string file data is treated as
|
|
95
|
+
* base64 content.
|
|
94
96
|
*
|
|
95
|
-
*
|
|
96
|
-
* - OpenAI: ['file-'] for IDs like 'file-abc123'
|
|
97
|
-
* - Azure OpenAI: ['assistant-'] for IDs like 'assistant-abc123'
|
|
97
|
+
* TODO: remove in v8
|
|
98
98
|
*/
|
|
99
99
|
fileIdPrefixes?: readonly string[];
|
|
100
100
|
};
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -89,12 +89,12 @@ type OpenAIConfig = {
|
|
|
89
89
|
fetch?: FetchFunction;
|
|
90
90
|
generateId?: () => string;
|
|
91
91
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
92
|
+
* This is soft-deprecated. Use provider references (e.g. `{ openai: 'file-abc123' }`)
|
|
93
|
+
* in file part data instead. File ID prefixes used to identify file IDs
|
|
94
|
+
* in Responses API. When undefined, all string file data is treated as
|
|
95
|
+
* base64 content.
|
|
94
96
|
*
|
|
95
|
-
*
|
|
96
|
-
* - OpenAI: ['file-'] for IDs like 'file-abc123'
|
|
97
|
-
* - Azure OpenAI: ['assistant-'] for IDs like 'assistant-abc123'
|
|
97
|
+
* TODO: remove in v8
|
|
98
98
|
*/
|
|
99
99
|
fileIdPrefixes?: readonly string[];
|
|
100
100
|
};
|
package/dist/internal/index.js
CHANGED
|
@@ -186,13 +186,23 @@ function convertToOpenAIChatMessages({
|
|
|
186
186
|
return { type: "text", text: part.text };
|
|
187
187
|
}
|
|
188
188
|
case "file": {
|
|
189
|
+
if ((0, import_provider_utils2.isProviderReference)(part.data)) {
|
|
190
|
+
return {
|
|
191
|
+
type: "file",
|
|
192
|
+
file: {
|
|
193
|
+
file_id: (0, import_provider_utils2.resolveProviderReference)({
|
|
194
|
+
reference: part.data,
|
|
195
|
+
provider: "openai"
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
189
200
|
if (part.mediaType.startsWith("image/")) {
|
|
190
201
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
191
202
|
return {
|
|
192
203
|
type: "image_url",
|
|
193
204
|
image_url: {
|
|
194
205
|
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${(0, import_provider_utils2.convertToBase64)(part.data)}`,
|
|
195
|
-
// OpenAI specific extension: image detail
|
|
196
206
|
detail: (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.imageDetail
|
|
197
207
|
}
|
|
198
208
|
};
|
|
@@ -236,7 +246,7 @@ function convertToOpenAIChatMessages({
|
|
|
236
246
|
}
|
|
237
247
|
return {
|
|
238
248
|
type: "file",
|
|
239
|
-
file:
|
|
249
|
+
file: {
|
|
240
250
|
filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
|
|
241
251
|
file_data: `data:application/pdf;base64,${(0, import_provider_utils2.convertToBase64)(part.data)}`
|
|
242
252
|
}
|
|
@@ -2638,12 +2648,29 @@ async function convertToOpenAIResponsesInput({
|
|
|
2638
2648
|
input.push({
|
|
2639
2649
|
role: "user",
|
|
2640
2650
|
content: content.map((part, index) => {
|
|
2641
|
-
var _a2, _b2, _c2;
|
|
2651
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
2642
2652
|
switch (part.type) {
|
|
2643
2653
|
case "text": {
|
|
2644
2654
|
return { type: "input_text", text: part.text };
|
|
2645
2655
|
}
|
|
2646
2656
|
case "file": {
|
|
2657
|
+
if ((0, import_provider_utils23.isProviderReference)(part.data)) {
|
|
2658
|
+
const fileId = (0, import_provider_utils23.resolveProviderReference)({
|
|
2659
|
+
reference: part.data,
|
|
2660
|
+
provider: providerOptionsName
|
|
2661
|
+
});
|
|
2662
|
+
if (part.mediaType.startsWith("image/")) {
|
|
2663
|
+
return {
|
|
2664
|
+
type: "input_image",
|
|
2665
|
+
file_id: fileId,
|
|
2666
|
+
detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail
|
|
2667
|
+
};
|
|
2668
|
+
}
|
|
2669
|
+
return {
|
|
2670
|
+
type: "input_file",
|
|
2671
|
+
file_id: fileId
|
|
2672
|
+
};
|
|
2673
|
+
}
|
|
2647
2674
|
if (part.mediaType.startsWith("image/")) {
|
|
2648
2675
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
2649
2676
|
return {
|
|
@@ -2651,7 +2678,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2651
2678
|
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
2652
2679
|
image_url: `data:${mediaType};base64,${(0, import_provider_utils23.convertToBase64)(part.data)}`
|
|
2653
2680
|
},
|
|
2654
|
-
detail: (
|
|
2681
|
+
detail: (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail
|
|
2655
2682
|
};
|
|
2656
2683
|
} else if (part.mediaType === "application/pdf") {
|
|
2657
2684
|
if (part.data instanceof URL) {
|
|
@@ -2663,7 +2690,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2663
2690
|
return {
|
|
2664
2691
|
type: "input_file",
|
|
2665
2692
|
...typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
2666
|
-
filename: (
|
|
2693
|
+
filename: (_e2 = part.filename) != null ? _e2 : `part-${index}.pdf`,
|
|
2667
2694
|
file_data: `data:application/pdf;base64,${(0, import_provider_utils23.convertToBase64)(part.data)}`
|
|
2668
2695
|
}
|
|
2669
2696
|
};
|