@ai-sdk/openai 4.0.17 → 4.0.19
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.js +39 -22
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2 -1
- package/dist/internal/index.js +39 -21
- package/dist/internal/index.js.map +1 -1
- package/package.json +1 -1
- package/src/image/openai-image-model-options.ts +8 -7
- package/src/image/openai-image-model.ts +2 -2
- package/src/openai-language-model-capabilities.ts +47 -22
- package/src/responses/convert-to-openai-responses-input.ts +9 -5
package/dist/internal/index.d.ts
CHANGED
|
@@ -150,6 +150,7 @@ declare class OpenAIEmbeddingModel implements EmbeddingModelV4 {
|
|
|
150
150
|
type OpenAIImageModelId = 'dall-e-3' | 'dall-e-2' | 'gpt-image-1' | 'gpt-image-1-mini' | 'gpt-image-1.5' | 'gpt-image-2' | 'chatgpt-image-latest' | (string & {});
|
|
151
151
|
declare const modelMaxImagesPerCall: Record<OpenAIImageModelId, number>;
|
|
152
152
|
declare function hasDefaultResponseFormat(modelId: string): boolean;
|
|
153
|
+
declare function getMaxImagesPerCall(modelId: OpenAIImageModelId): number;
|
|
153
154
|
declare const openaiImageModelOptions: _ai_sdk_provider_utils.LazySchema<{
|
|
154
155
|
quality?: "auto" | "low" | "medium" | "high" | "standard" | "hd" | undefined;
|
|
155
156
|
background?: "auto" | "transparent" | "opaque" | undefined;
|
|
@@ -1694,4 +1695,4 @@ declare const webSearchPreview: _ai_sdk_provider_utils.ProviderExecutedToolFacto
|
|
|
1694
1695
|
};
|
|
1695
1696
|
}, {}>;
|
|
1696
1697
|
|
|
1697
|
-
export { type ApplyPatchOperation, OpenAIChatLanguageModel, type OpenAIChatModelId, OpenAICompletionLanguageModel, type OpenAICompletionModelId, OpenAIEmbeddingModel, type OpenAIEmbeddingModelId, type OpenAIEmbeddingModelOptions, OpenAIImageModel, type OpenAIImageModelEditOptions, type OpenAIImageModelGenerationOptions, type OpenAIImageModelId, type OpenAIImageModelOptions, type OpenAILanguageModelChatOptions, type OpenAILanguageModelCompletionOptions, OpenAIResponsesLanguageModel, OpenAISpeechModel, type OpenAISpeechModelId, type OpenAISpeechModelOptions, type OpenAITranscriptionCallOptions, OpenAITranscriptionModel, type OpenAITranscriptionModelId, type OpenAITranscriptionModelOptions, type OpenAITranscriptionStreamOptions, type OpenaiResponsesCompactionProviderMetadata, type OpenaiResponsesProviderMetadata, type OpenaiResponsesReasoningProviderMetadata, type OpenaiResponsesSourceDocumentProviderMetadata, type OpenaiResponsesTextProviderMetadata, type ResponsesCompactionProviderMetadata, type ResponsesProviderMetadata, type ResponsesReasoningProviderMetadata, type ResponsesSourceDocumentProviderMetadata, type ResponsesTextProviderMetadata, applyPatch, applyPatchArgsSchema, applyPatchInputSchema, applyPatchOutputSchema, applyPatchToolFactory, codeInterpreter, codeInterpreterArgsSchema, codeInterpreterInputSchema, codeInterpreterOutputSchema, codeInterpreterToolFactory, fileSearch, fileSearchArgsSchema, fileSearchOutputSchema, hasDefaultResponseFormat, imageGeneration, imageGenerationArgsSchema, imageGenerationOutputSchema, modelMaxImagesPerCall, openAITranscriptionModelOptions, openaiEmbeddingModelOptions, openaiImageModelEditOptions, openaiImageModelGenerationOptions, openaiImageModelOptions, openaiLanguageModelChatOptions, openaiLanguageModelCompletionOptions, openaiSpeechModelOptionsSchema, webSearch, webSearchArgsSchema, webSearchOutputSchema, webSearchPreview, webSearchPreviewArgsSchema, webSearchPreviewInputSchema, webSearchToolFactory };
|
|
1698
|
+
export { type ApplyPatchOperation, OpenAIChatLanguageModel, type OpenAIChatModelId, OpenAICompletionLanguageModel, type OpenAICompletionModelId, OpenAIEmbeddingModel, type OpenAIEmbeddingModelId, type OpenAIEmbeddingModelOptions, OpenAIImageModel, type OpenAIImageModelEditOptions, type OpenAIImageModelGenerationOptions, type OpenAIImageModelId, type OpenAIImageModelOptions, type OpenAILanguageModelChatOptions, type OpenAILanguageModelCompletionOptions, OpenAIResponsesLanguageModel, OpenAISpeechModel, type OpenAISpeechModelId, type OpenAISpeechModelOptions, type OpenAITranscriptionCallOptions, OpenAITranscriptionModel, type OpenAITranscriptionModelId, type OpenAITranscriptionModelOptions, type OpenAITranscriptionStreamOptions, type OpenaiResponsesCompactionProviderMetadata, type OpenaiResponsesProviderMetadata, type OpenaiResponsesReasoningProviderMetadata, type OpenaiResponsesSourceDocumentProviderMetadata, type OpenaiResponsesTextProviderMetadata, type ResponsesCompactionProviderMetadata, type ResponsesProviderMetadata, type ResponsesReasoningProviderMetadata, type ResponsesSourceDocumentProviderMetadata, type ResponsesTextProviderMetadata, applyPatch, applyPatchArgsSchema, applyPatchInputSchema, applyPatchOutputSchema, applyPatchToolFactory, codeInterpreter, codeInterpreterArgsSchema, codeInterpreterInputSchema, codeInterpreterOutputSchema, codeInterpreterToolFactory, fileSearch, fileSearchArgsSchema, fileSearchOutputSchema, getMaxImagesPerCall, hasDefaultResponseFormat, imageGeneration, imageGenerationArgsSchema, imageGenerationOutputSchema, modelMaxImagesPerCall, openAITranscriptionModelOptions, openaiEmbeddingModelOptions, openaiImageModelEditOptions, openaiImageModelGenerationOptions, openaiImageModelOptions, openaiLanguageModelChatOptions, openaiLanguageModelCompletionOptions, openaiSpeechModelOptionsSchema, webSearch, webSearchArgsSchema, webSearchOutputSchema, webSearchPreview, webSearchPreviewArgsSchema, webSearchPreviewInputSchema, webSearchToolFactory };
|
package/dist/internal/index.js
CHANGED
|
@@ -34,10 +34,15 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
34
34
|
|
|
35
35
|
// src/openai-language-model-capabilities.ts
|
|
36
36
|
function getOpenAILanguageModelCapabilities(modelId) {
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
37
|
+
var _a, _b, _c, _d, _e;
|
|
38
|
+
const oSeriesVersion = getOSeriesVersion(modelId);
|
|
39
|
+
const gptVersion = getGptVersion(modelId);
|
|
40
|
+
const isGptChatModel = (gptVersion == null ? void 0 : gptVersion.minor) == null && ((_b = (_a = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _a.startsWith("chat")) != null ? _b : false);
|
|
41
|
+
const isGptNanoModel = (_d = (_c = gptVersion == null ? void 0 : gptVersion.variant) == null ? void 0 : _c.startsWith("nano")) != null ? _d : false;
|
|
42
|
+
const supportsFlexProcessing = oSeriesVersion != null && oSeriesVersion >= 3 || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
|
|
43
|
+
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || gptVersion != null && gptVersion.major >= 5 && !isGptNanoModel && !isGptChatModel || oSeriesVersion != null && oSeriesVersion >= 3;
|
|
44
|
+
const isReasoningModel = oSeriesVersion != null || gptVersion != null && gptVersion.major >= 5 && !isGptChatModel;
|
|
45
|
+
const supportsNonReasoningParameters = gptVersion != null && (gptVersion.major > 5 || gptVersion.major === 5 && ((_e = gptVersion.minor) != null ? _e : 0) >= 1);
|
|
41
46
|
const systemMessageMode = isReasoningModel ? "developer" : "system";
|
|
42
47
|
return {
|
|
43
48
|
supportsFlexProcessing,
|
|
@@ -47,6 +52,21 @@ function getOpenAILanguageModelCapabilities(modelId) {
|
|
|
47
52
|
supportsNonReasoningParameters
|
|
48
53
|
};
|
|
49
54
|
}
|
|
55
|
+
function getOSeriesVersion(modelId) {
|
|
56
|
+
const match = /^o(\d+)(?:-|$)/.exec(modelId);
|
|
57
|
+
return match == null ? void 0 : Number(match[1]);
|
|
58
|
+
}
|
|
59
|
+
function getGptVersion(modelId) {
|
|
60
|
+
const match = /^gpt-(\d+)(?:\.(\d+))?(?:-(.+))?$/.exec(modelId);
|
|
61
|
+
if (match == null) {
|
|
62
|
+
return void 0;
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
major: Number(match[1]),
|
|
66
|
+
minor: match[2] == null ? void 0 : Number(match[2]),
|
|
67
|
+
variant: match[3]
|
|
68
|
+
};
|
|
69
|
+
}
|
|
50
70
|
|
|
51
71
|
// src/openai-stream-error.ts
|
|
52
72
|
import { APICallError } from "@ai-sdk/provider";
|
|
@@ -2016,18 +2036,16 @@ var modelMaxImagesPerCall = {
|
|
|
2016
2036
|
"gpt-image-2": 10,
|
|
2017
2037
|
"chatgpt-image-latest": 10
|
|
2018
2038
|
};
|
|
2019
|
-
var defaultResponseFormatPrefixes = [
|
|
2020
|
-
"chatgpt-image-",
|
|
2021
|
-
"gpt-image-1-mini",
|
|
2022
|
-
"gpt-image-1.5",
|
|
2023
|
-
"gpt-image-1",
|
|
2024
|
-
"gpt-image-2"
|
|
2025
|
-
];
|
|
2039
|
+
var defaultResponseFormatPrefixes = ["chatgpt-image-", "gpt-image-"];
|
|
2026
2040
|
function hasDefaultResponseFormat(modelId) {
|
|
2027
2041
|
return defaultResponseFormatPrefixes.some(
|
|
2028
2042
|
(prefix) => modelId.startsWith(prefix)
|
|
2029
2043
|
);
|
|
2030
2044
|
}
|
|
2045
|
+
function getMaxImagesPerCall(modelId) {
|
|
2046
|
+
var _a;
|
|
2047
|
+
return (_a = modelMaxImagesPerCall[modelId]) != null ? _a : modelId.startsWith("gpt-image-") ? 10 : 1;
|
|
2048
|
+
}
|
|
2031
2049
|
var baseImageModelOptionsObject = z9.object({
|
|
2032
2050
|
/**
|
|
2033
2051
|
* Quality of the generated image(s).
|
|
@@ -2105,8 +2123,7 @@ var OpenAIImageModel = class _OpenAIImageModel {
|
|
|
2105
2123
|
return new _OpenAIImageModel(options.modelId, options.config);
|
|
2106
2124
|
}
|
|
2107
2125
|
get maxImagesPerCall() {
|
|
2108
|
-
|
|
2109
|
-
return (_a = modelMaxImagesPerCall[this.modelId]) != null ? _a : 1;
|
|
2126
|
+
return getMaxImagesPerCall(this.modelId);
|
|
2110
2127
|
}
|
|
2111
2128
|
get provider() {
|
|
2112
2129
|
return this.config.provider;
|
|
@@ -3392,7 +3409,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3392
3409
|
hasComputerTool = false,
|
|
3393
3410
|
customProviderToolNames
|
|
3394
3411
|
}) {
|
|
3395
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
3412
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
|
|
3396
3413
|
let input = [];
|
|
3397
3414
|
const warnings = [];
|
|
3398
3415
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
@@ -3751,7 +3768,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3751
3768
|
part.toolName
|
|
3752
3769
|
);
|
|
3753
3770
|
if (resolvedResultToolName === "tool_search") {
|
|
3754
|
-
const itemId = (
|
|
3771
|
+
const itemId = (_s = (_r = (_o = (_n = part.providerOptions) == null ? void 0 : _n[providerOptionsName]) == null ? void 0 : _o.itemId) != null ? _r : (_q = (_p = part.providerMetadata) == null ? void 0 : _p[providerOptionsName]) == null ? void 0 : _q.itemId) != null ? _s : part.toolCallId;
|
|
3755
3772
|
if (store) {
|
|
3756
3773
|
input.push({ type: "item_reference", id: itemId });
|
|
3757
3774
|
} else if (part.output.type === "json") {
|
|
@@ -3792,7 +3809,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3792
3809
|
break;
|
|
3793
3810
|
}
|
|
3794
3811
|
if (store) {
|
|
3795
|
-
const itemId = (
|
|
3812
|
+
const itemId = (_v = (_u = (_t = part.providerOptions) == null ? void 0 : _t[providerOptionsName]) == null ? void 0 : _u.itemId) != null ? _v : part.toolCallId;
|
|
3796
3813
|
input.push({ type: "item_reference", id: itemId });
|
|
3797
3814
|
} else {
|
|
3798
3815
|
warnings.push({
|
|
@@ -3877,7 +3894,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3877
3894
|
}
|
|
3878
3895
|
case "custom": {
|
|
3879
3896
|
if (part.kind === "openai.compaction") {
|
|
3880
|
-
const providerOptions2 = (
|
|
3897
|
+
const providerOptions2 = (_w = part.providerOptions) == null ? void 0 : _w[providerOptionsName];
|
|
3881
3898
|
const id = providerOptions2 == null ? void 0 : providerOptions2.itemId;
|
|
3882
3899
|
if (hasConversation && id != null) {
|
|
3883
3900
|
break;
|
|
@@ -3924,7 +3941,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3924
3941
|
}
|
|
3925
3942
|
const output = part.output;
|
|
3926
3943
|
if (output.type === "execution-denied") {
|
|
3927
|
-
const approvalId = (
|
|
3944
|
+
const approvalId = (_y = (_x = output.providerOptions) == null ? void 0 : _x.openai) == null ? void 0 : _y.approvalId;
|
|
3928
3945
|
if (approvalId) {
|
|
3929
3946
|
continue;
|
|
3930
3947
|
}
|
|
@@ -4004,7 +4021,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4004
4021
|
file_id: parsedOutput.output.fileId,
|
|
4005
4022
|
detail: parsedOutput.output.detail
|
|
4006
4023
|
},
|
|
4007
|
-
acknowledged_safety_checks: (
|
|
4024
|
+
acknowledged_safety_checks: (_z = parsedOutput.acknowledgedSafetyChecks) == null ? void 0 : _z.map((safetyCheck) => ({
|
|
4008
4025
|
id: safetyCheck.id,
|
|
4009
4026
|
code: safetyCheck.code,
|
|
4010
4027
|
message: safetyCheck.message
|
|
@@ -4020,7 +4037,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4020
4037
|
outputValue = output.value;
|
|
4021
4038
|
break;
|
|
4022
4039
|
case "execution-denied":
|
|
4023
|
-
outputValue = (
|
|
4040
|
+
outputValue = (_A = output.reason) != null ? _A : "Tool call execution denied.";
|
|
4024
4041
|
break;
|
|
4025
4042
|
case "json":
|
|
4026
4043
|
case "error-json":
|
|
@@ -4119,7 +4136,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
4119
4136
|
contentValue = output.value;
|
|
4120
4137
|
break;
|
|
4121
4138
|
case "execution-denied":
|
|
4122
|
-
contentValue = (
|
|
4139
|
+
contentValue = (_B = output.reason) != null ? _B : "Tool call execution denied.";
|
|
4123
4140
|
break;
|
|
4124
4141
|
case "json":
|
|
4125
4142
|
case "error-json":
|
|
@@ -8173,6 +8190,7 @@ export {
|
|
|
8173
8190
|
fileSearch,
|
|
8174
8191
|
fileSearchArgsSchema,
|
|
8175
8192
|
fileSearchOutputSchema,
|
|
8193
|
+
getMaxImagesPerCall,
|
|
8176
8194
|
hasDefaultResponseFormat,
|
|
8177
8195
|
imageGeneration,
|
|
8178
8196
|
imageGenerationArgsSchema,
|