@ai-sdk/openai 4.0.0-beta.40 → 4.0.0-beta.41
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 +12 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +176 -118
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2 -2
- package/dist/internal/index.js +162 -107
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +18 -13
- package/package.json +4 -4
- package/src/chat/convert-openai-chat-usage.ts +1 -1
- package/src/chat/convert-to-openai-chat-messages.ts +85 -72
- package/src/chat/map-openai-finish-reason.ts +1 -1
- package/src/chat/openai-chat-api.ts +6 -2
- package/src/chat/openai-chat-language-model.ts +6 -6
- package/src/chat/openai-chat-options.ts +5 -1
- package/src/chat/openai-chat-prepare-tools.ts +3 -3
- package/src/completion/convert-openai-completion-usage.ts +1 -1
- package/src/completion/convert-to-openai-completion-prompt.ts +1 -2
- package/src/completion/map-openai-finish-reason.ts +1 -1
- package/src/completion/openai-completion-api.ts +5 -2
- package/src/completion/openai-completion-language-model.ts +6 -7
- package/src/completion/openai-completion-options.ts +5 -1
- package/src/embedding/openai-embedding-model.ts +3 -3
- package/src/embedding/openai-embedding-options.ts +5 -1
- package/src/files/openai-files-options.ts +5 -1
- package/src/files/openai-files.ts +5 -7
- package/src/image/openai-image-model.ts +3 -4
- package/src/openai-config.ts +1 -1
- package/src/openai-provider.ts +9 -9
- package/src/responses/convert-openai-responses-usage.ts +1 -1
- package/src/responses/convert-to-openai-responses-input.ts +72 -60
- package/src/responses/map-openai-responses-finish-reason.ts +1 -1
- package/src/responses/openai-responses-api.ts +6 -2
- package/src/responses/openai-responses-language-model.ts +35 -35
- package/src/responses/openai-responses-options.ts +5 -1
- package/src/responses/openai-responses-prepare-tools.ts +5 -5
- package/src/responses/openai-responses-provider-metadata.ts +2 -2
- package/src/skills/openai-skills.ts +4 -8
- package/src/speech/openai-speech-model.ts +4 -5
- package/src/speech/openai-speech-options.ts +5 -1
- package/src/tool/file-search.ts +1 -1
- package/src/tool/mcp.ts +1 -1
- package/src/tool/tool-search.ts +2 -2
- package/src/transcription/openai-transcription-model.ts +4 -5
- package/src/transcription/openai-transcription-options.ts +5 -1
package/dist/internal/index.d.ts
CHANGED
|
@@ -981,7 +981,7 @@ declare const codeInterpreterToolFactory: _ai_sdk_provider_utils.ProviderExecute
|
|
|
981
981
|
url: string;
|
|
982
982
|
}> | null;
|
|
983
983
|
}, CodeInterpreterArgs, {}>;
|
|
984
|
-
declare const codeInterpreter: (args?: CodeInterpreterArgs) => _ai_sdk_provider_utils.
|
|
984
|
+
declare const codeInterpreter: (args?: CodeInterpreterArgs) => _ai_sdk_provider_utils.ProviderExecutedTool<{
|
|
985
985
|
/**
|
|
986
986
|
* The code to run, or null if not available.
|
|
987
987
|
*/
|
|
@@ -1167,7 +1167,7 @@ type ImageGenerationArgs = {
|
|
|
1167
1167
|
*/
|
|
1168
1168
|
size?: 'auto' | '1024x1024' | '1024x1536' | '1536x1024';
|
|
1169
1169
|
};
|
|
1170
|
-
declare const imageGeneration: (args?: ImageGenerationArgs) => _ai_sdk_provider_utils.
|
|
1170
|
+
declare const imageGeneration: (args?: ImageGenerationArgs) => _ai_sdk_provider_utils.ProviderExecutedTool<{}, {
|
|
1171
1171
|
/**
|
|
1172
1172
|
* The generated image encoded in base64.
|
|
1173
1173
|
*/
|
package/dist/internal/index.js
CHANGED
|
@@ -93,7 +93,8 @@ import {
|
|
|
93
93
|
} from "@ai-sdk/provider";
|
|
94
94
|
import {
|
|
95
95
|
convertToBase64,
|
|
96
|
-
|
|
96
|
+
getTopLevelMediaType,
|
|
97
|
+
resolveFullMediaType,
|
|
97
98
|
resolveProviderReference
|
|
98
99
|
} from "@ai-sdk/provider-utils";
|
|
99
100
|
function serializeToolCallArguments(input) {
|
|
@@ -148,75 +149,89 @@ function convertToOpenAIChatMessages({
|
|
|
148
149
|
return { type: "text", text: part.text };
|
|
149
150
|
}
|
|
150
151
|
case "file": {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return {
|
|
165
|
-
type: "image_url",
|
|
166
|
-
image_url: {
|
|
167
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`,
|
|
168
|
-
detail: (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.imageDetail
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
} else if (part.mediaType.startsWith("audio/")) {
|
|
172
|
-
if (part.data instanceof URL) {
|
|
152
|
+
switch (part.data.type) {
|
|
153
|
+
case "reference": {
|
|
154
|
+
return {
|
|
155
|
+
type: "file",
|
|
156
|
+
file: {
|
|
157
|
+
file_id: resolveProviderReference({
|
|
158
|
+
reference: part.data.reference,
|
|
159
|
+
provider: "openai"
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
case "text": {
|
|
173
165
|
throw new UnsupportedFunctionalityError({
|
|
174
|
-
functionality: "
|
|
166
|
+
functionality: "text file parts"
|
|
175
167
|
});
|
|
176
168
|
}
|
|
177
|
-
|
|
178
|
-
|
|
169
|
+
case "url":
|
|
170
|
+
case "data": {
|
|
171
|
+
const topLevel = getTopLevelMediaType(part.mediaType);
|
|
172
|
+
if (topLevel === "image") {
|
|
179
173
|
return {
|
|
180
|
-
type: "
|
|
181
|
-
|
|
182
|
-
data: convertToBase64(part.data),
|
|
183
|
-
|
|
174
|
+
type: "image_url",
|
|
175
|
+
image_url: {
|
|
176
|
+
url: part.data.type === "url" ? part.data.url.toString() : convertToBase64(part.data.data),
|
|
177
|
+
detail: (_b = (_a2 = part.providerOptions) == null ? void 0 : _a2.openai) == null ? void 0 : _b.imageDetail
|
|
184
178
|
}
|
|
185
179
|
};
|
|
180
|
+
} else if (topLevel === "audio") {
|
|
181
|
+
if (part.data.type === "url") {
|
|
182
|
+
throw new UnsupportedFunctionalityError({
|
|
183
|
+
functionality: "audio file parts with URLs"
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
const fullMediaType = resolveFullMediaType({ part });
|
|
187
|
+
switch (fullMediaType) {
|
|
188
|
+
case "audio/wav": {
|
|
189
|
+
return {
|
|
190
|
+
type: "input_audio",
|
|
191
|
+
input_audio: {
|
|
192
|
+
data: convertToBase64(part.data.data),
|
|
193
|
+
format: "wav"
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
case "audio/mp3":
|
|
198
|
+
case "audio/mpeg": {
|
|
199
|
+
return {
|
|
200
|
+
type: "input_audio",
|
|
201
|
+
input_audio: {
|
|
202
|
+
data: convertToBase64(part.data.data),
|
|
203
|
+
format: "mp3"
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
default: {
|
|
208
|
+
throw new UnsupportedFunctionalityError({
|
|
209
|
+
functionality: `audio content parts with media type ${fullMediaType}`
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
186
213
|
}
|
|
187
|
-
|
|
188
|
-
|
|
214
|
+
{
|
|
215
|
+
const fullMediaType = resolveFullMediaType({ part });
|
|
216
|
+
if (fullMediaType !== "application/pdf") {
|
|
217
|
+
throw new UnsupportedFunctionalityError({
|
|
218
|
+
functionality: `file part media type ${fullMediaType}`
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
if (part.data.type === "url") {
|
|
222
|
+
throw new UnsupportedFunctionalityError({
|
|
223
|
+
functionality: "PDF file parts with URLs"
|
|
224
|
+
});
|
|
225
|
+
}
|
|
189
226
|
return {
|
|
190
|
-
type: "
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
227
|
+
type: "file",
|
|
228
|
+
file: {
|
|
229
|
+
filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
|
|
230
|
+
file_data: `data:application/pdf;base64,${convertToBase64(part.data.data)}`
|
|
194
231
|
}
|
|
195
232
|
};
|
|
196
233
|
}
|
|
197
|
-
default: {
|
|
198
|
-
throw new UnsupportedFunctionalityError({
|
|
199
|
-
functionality: `audio content parts with media type ${part.mediaType}`
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
234
|
}
|
|
203
|
-
} else if (part.mediaType === "application/pdf") {
|
|
204
|
-
if (part.data instanceof URL) {
|
|
205
|
-
throw new UnsupportedFunctionalityError({
|
|
206
|
-
functionality: "PDF file parts with URLs"
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
return {
|
|
210
|
-
type: "file",
|
|
211
|
-
file: {
|
|
212
|
-
filename: (_c = part.filename) != null ? _c : `part-${index}.pdf`,
|
|
213
|
-
file_data: `data:application/pdf;base64,${convertToBase64(part.data)}`
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
} else {
|
|
217
|
-
throw new UnsupportedFunctionalityError({
|
|
218
|
-
functionality: `file part media type ${part.mediaType}`
|
|
219
|
-
});
|
|
220
235
|
}
|
|
221
236
|
}
|
|
222
237
|
}
|
|
@@ -322,7 +337,10 @@ function mapOpenAIFinishReason(finishReason) {
|
|
|
322
337
|
}
|
|
323
338
|
|
|
324
339
|
// src/chat/openai-chat-api.ts
|
|
325
|
-
import {
|
|
340
|
+
import {
|
|
341
|
+
lazySchema,
|
|
342
|
+
zodSchema
|
|
343
|
+
} from "@ai-sdk/provider-utils";
|
|
326
344
|
import { z as z2 } from "zod/v4";
|
|
327
345
|
var openaiChatResponseSchema = lazySchema(
|
|
328
346
|
() => zodSchema(
|
|
@@ -464,7 +482,10 @@ var openaiChatChunkSchema = lazySchema(
|
|
|
464
482
|
);
|
|
465
483
|
|
|
466
484
|
// src/chat/openai-chat-options.ts
|
|
467
|
-
import {
|
|
485
|
+
import {
|
|
486
|
+
lazySchema as lazySchema2,
|
|
487
|
+
zodSchema as zodSchema2
|
|
488
|
+
} from "@ai-sdk/provider-utils";
|
|
468
489
|
import { z as z3 } from "zod/v4";
|
|
469
490
|
var openaiLanguageModelChatOptions = lazySchema2(
|
|
470
491
|
() => zodSchema2(
|
|
@@ -1222,7 +1243,10 @@ function mapOpenAIFinishReason2(finishReason) {
|
|
|
1222
1243
|
|
|
1223
1244
|
// src/completion/openai-completion-api.ts
|
|
1224
1245
|
import { z as z4 } from "zod/v4";
|
|
1225
|
-
import {
|
|
1246
|
+
import {
|
|
1247
|
+
lazySchema as lazySchema3,
|
|
1248
|
+
zodSchema as zodSchema3
|
|
1249
|
+
} from "@ai-sdk/provider-utils";
|
|
1226
1250
|
var openaiCompletionResponseSchema = lazySchema3(
|
|
1227
1251
|
() => zodSchema3(
|
|
1228
1252
|
z4.object({
|
|
@@ -1279,7 +1303,10 @@ var openaiCompletionChunkSchema = lazySchema3(
|
|
|
1279
1303
|
);
|
|
1280
1304
|
|
|
1281
1305
|
// src/completion/openai-completion-options.ts
|
|
1282
|
-
import {
|
|
1306
|
+
import {
|
|
1307
|
+
lazySchema as lazySchema4,
|
|
1308
|
+
zodSchema as zodSchema4
|
|
1309
|
+
} from "@ai-sdk/provider-utils";
|
|
1283
1310
|
import { z as z5 } from "zod/v4";
|
|
1284
1311
|
var openaiLanguageModelCompletionOptions = lazySchema4(
|
|
1285
1312
|
() => zodSchema4(
|
|
@@ -1580,7 +1607,10 @@ import {
|
|
|
1580
1607
|
} from "@ai-sdk/provider-utils";
|
|
1581
1608
|
|
|
1582
1609
|
// src/embedding/openai-embedding-options.ts
|
|
1583
|
-
import {
|
|
1610
|
+
import {
|
|
1611
|
+
lazySchema as lazySchema5,
|
|
1612
|
+
zodSchema as zodSchema5
|
|
1613
|
+
} from "@ai-sdk/provider-utils";
|
|
1584
1614
|
import { z as z6 } from "zod/v4";
|
|
1585
1615
|
var openaiEmbeddingModelOptions = lazySchema5(
|
|
1586
1616
|
() => zodSchema5(
|
|
@@ -2002,7 +2032,10 @@ var openaiTranscriptionResponseSchema = lazySchema8(
|
|
|
2002
2032
|
);
|
|
2003
2033
|
|
|
2004
2034
|
// src/transcription/openai-transcription-options.ts
|
|
2005
|
-
import {
|
|
2035
|
+
import {
|
|
2036
|
+
lazySchema as lazySchema9,
|
|
2037
|
+
zodSchema as zodSchema9
|
|
2038
|
+
} from "@ai-sdk/provider-utils";
|
|
2006
2039
|
import { z as z10 } from "zod/v4";
|
|
2007
2040
|
var openAITranscriptionModelOptions = lazySchema9(
|
|
2008
2041
|
() => zodSchema9(
|
|
@@ -2221,7 +2254,10 @@ import {
|
|
|
2221
2254
|
} from "@ai-sdk/provider-utils";
|
|
2222
2255
|
|
|
2223
2256
|
// src/speech/openai-speech-options.ts
|
|
2224
|
-
import {
|
|
2257
|
+
import {
|
|
2258
|
+
lazySchema as lazySchema10,
|
|
2259
|
+
zodSchema as zodSchema10
|
|
2260
|
+
} from "@ai-sdk/provider-utils";
|
|
2225
2261
|
import { z as z11 } from "zod/v4";
|
|
2226
2262
|
var openaiSpeechModelOptionsSchema = lazySchema10(
|
|
2227
2263
|
() => zodSchema10(
|
|
@@ -2405,10 +2441,11 @@ import {
|
|
|
2405
2441
|
} from "@ai-sdk/provider";
|
|
2406
2442
|
import {
|
|
2407
2443
|
convertToBase64 as convertToBase642,
|
|
2444
|
+
getTopLevelMediaType as getTopLevelMediaType2,
|
|
2408
2445
|
isNonNullable,
|
|
2409
|
-
isProviderReference as isProviderReference2,
|
|
2410
2446
|
parseJSON,
|
|
2411
2447
|
parseProviderOptions as parseProviderOptions6,
|
|
2448
|
+
resolveFullMediaType as resolveFullMediaType2,
|
|
2412
2449
|
resolveProviderReference as resolveProviderReference2,
|
|
2413
2450
|
validateTypes
|
|
2414
2451
|
} from "@ai-sdk/provider-utils";
|
|
@@ -2691,50 +2728,62 @@ async function convertToOpenAIResponsesInput({
|
|
|
2691
2728
|
return { type: "input_text", text: part.text };
|
|
2692
2729
|
}
|
|
2693
2730
|
case "file": {
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
type: "input_file",
|
|
2708
|
-
file_id: fileId
|
|
2709
|
-
};
|
|
2710
|
-
}
|
|
2711
|
-
if (part.mediaType.startsWith("image/")) {
|
|
2712
|
-
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
2713
|
-
return {
|
|
2714
|
-
type: "input_image",
|
|
2715
|
-
...part.data instanceof URL ? { image_url: part.data.toString() } : typeof part.data === "string" && isFileId(part.data, fileIdPrefixes) ? { file_id: part.data } : {
|
|
2716
|
-
image_url: `data:${mediaType};base64,${convertToBase642(part.data)}`
|
|
2717
|
-
},
|
|
2718
|
-
detail: (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail
|
|
2719
|
-
};
|
|
2720
|
-
} else if (part.mediaType === "application/pdf") {
|
|
2721
|
-
if (part.data instanceof URL) {
|
|
2731
|
+
switch (part.data.type) {
|
|
2732
|
+
case "reference": {
|
|
2733
|
+
const fileId = resolveProviderReference2({
|
|
2734
|
+
reference: part.data.reference,
|
|
2735
|
+
provider: providerOptionsName
|
|
2736
|
+
});
|
|
2737
|
+
if (getTopLevelMediaType2(part.mediaType) === "image") {
|
|
2738
|
+
return {
|
|
2739
|
+
type: "input_image",
|
|
2740
|
+
file_id: fileId,
|
|
2741
|
+
detail: (_b2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) == null ? void 0 : _b2.imageDetail
|
|
2742
|
+
};
|
|
2743
|
+
}
|
|
2722
2744
|
return {
|
|
2723
2745
|
type: "input_file",
|
|
2724
|
-
|
|
2746
|
+
file_id: fileId
|
|
2725
2747
|
};
|
|
2726
2748
|
}
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2749
|
+
case "text": {
|
|
2750
|
+
throw new UnsupportedFunctionalityError4({
|
|
2751
|
+
functionality: "text file parts"
|
|
2752
|
+
});
|
|
2753
|
+
}
|
|
2754
|
+
case "url":
|
|
2755
|
+
case "data": {
|
|
2756
|
+
const topLevel = getTopLevelMediaType2(part.mediaType);
|
|
2757
|
+
if (topLevel === "image") {
|
|
2758
|
+
return {
|
|
2759
|
+
type: "input_image",
|
|
2760
|
+
...part.data.type === "url" ? { image_url: part.data.url.toString() } : typeof part.data.data === "string" && isFileId(part.data.data, fileIdPrefixes) ? { file_id: part.data.data } : {
|
|
2761
|
+
image_url: `data:${resolveFullMediaType2({ part })};base64,${convertToBase642(part.data.data)}`
|
|
2762
|
+
},
|
|
2763
|
+
detail: (_d2 = (_c2 = part.providerOptions) == null ? void 0 : _c2[providerOptionsName]) == null ? void 0 : _d2.imageDetail
|
|
2764
|
+
};
|
|
2765
|
+
} else {
|
|
2766
|
+
if (part.data.type === "url") {
|
|
2767
|
+
return {
|
|
2768
|
+
type: "input_file",
|
|
2769
|
+
file_url: part.data.url.toString()
|
|
2770
|
+
};
|
|
2771
|
+
}
|
|
2772
|
+
const fullMediaType = resolveFullMediaType2({ part });
|
|
2773
|
+
if (fullMediaType !== "application/pdf") {
|
|
2774
|
+
throw new UnsupportedFunctionalityError4({
|
|
2775
|
+
functionality: `file part media type ${fullMediaType}`
|
|
2776
|
+
});
|
|
2777
|
+
}
|
|
2778
|
+
return {
|
|
2779
|
+
type: "input_file",
|
|
2780
|
+
...typeof part.data.data === "string" && isFileId(part.data.data, fileIdPrefixes) ? { file_id: part.data.data } : {
|
|
2781
|
+
filename: (_e2 = part.filename) != null ? _e2 : `part-${index}.pdf`,
|
|
2782
|
+
file_data: `data:application/pdf;base64,${convertToBase642(part.data.data)}`
|
|
2783
|
+
}
|
|
2784
|
+
};
|
|
2732
2785
|
}
|
|
2733
|
-
}
|
|
2734
|
-
} else {
|
|
2735
|
-
throw new UnsupportedFunctionalityError4({
|
|
2736
|
-
functionality: `file part media type ${part.mediaType}`
|
|
2737
|
-
});
|
|
2786
|
+
}
|
|
2738
2787
|
}
|
|
2739
2788
|
}
|
|
2740
2789
|
}
|
|
@@ -3297,7 +3346,10 @@ function mapOpenAIResponseFinishReason({
|
|
|
3297
3346
|
}
|
|
3298
3347
|
|
|
3299
3348
|
// src/responses/openai-responses-api.ts
|
|
3300
|
-
import {
|
|
3349
|
+
import {
|
|
3350
|
+
lazySchema as lazySchema15,
|
|
3351
|
+
zodSchema as zodSchema15
|
|
3352
|
+
} from "@ai-sdk/provider-utils";
|
|
3301
3353
|
import { z as z17 } from "zod/v4";
|
|
3302
3354
|
var jsonValueSchema = z17.lazy(
|
|
3303
3355
|
() => z17.union([
|
|
@@ -4157,7 +4209,10 @@ var openaiResponsesResponseSchema = lazySchema15(
|
|
|
4157
4209
|
);
|
|
4158
4210
|
|
|
4159
4211
|
// src/responses/openai-responses-options.ts
|
|
4160
|
-
import {
|
|
4212
|
+
import {
|
|
4213
|
+
lazySchema as lazySchema16,
|
|
4214
|
+
zodSchema as zodSchema16
|
|
4215
|
+
} from "@ai-sdk/provider-utils";
|
|
4161
4216
|
import { z as z18 } from "zod/v4";
|
|
4162
4217
|
var TOP_LOGPROBS_MAX = 20;
|
|
4163
4218
|
var openaiResponsesReasoningModelIds = [
|