@ai-sdk/openai 3.0.106 → 3.0.108
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 +13 -0
- package/dist/index.d.mts +19 -17
- package/dist/index.d.ts +19 -17
- package/dist/index.js +82 -68
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +82 -68
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +19 -17
- package/dist/internal/index.d.ts +19 -17
- package/dist/internal/index.js +81 -67
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +81 -67
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-openai.mdx +1 -0
- package/package.json +1 -1
- package/src/chat/openai-chat-options.ts +1 -0
- package/src/openai-stream-error.ts +58 -3
- package/src/responses/convert-openai-responses-usage.ts +17 -12
- package/src/responses/openai-responses-api.ts +34 -58
- package/src/responses/openai-responses-language-model.ts +19 -12
- package/src/responses/openai-responses-options.ts +2 -0
package/dist/internal/index.mjs
CHANGED
|
@@ -68,6 +68,22 @@ function getGptVersion(modelId) {
|
|
|
68
68
|
|
|
69
69
|
// src/openai-stream-error.ts
|
|
70
70
|
import { APICallError } from "@ai-sdk/provider";
|
|
71
|
+
function createOpenAIProviderStreamError(frame) {
|
|
72
|
+
var _a2, _b;
|
|
73
|
+
const streamError = parseStreamError(frame);
|
|
74
|
+
if (streamError == null) {
|
|
75
|
+
return void 0;
|
|
76
|
+
}
|
|
77
|
+
const statusCode = getStatusCode(streamError);
|
|
78
|
+
return {
|
|
79
|
+
message: streamError.message,
|
|
80
|
+
type: (_a2 = streamError.type) != null ? _a2 : void 0,
|
|
81
|
+
code: (_b = streamError.code) != null ? _b : void 0,
|
|
82
|
+
statusCode,
|
|
83
|
+
isRetryable: isRetryableStreamError(streamError, statusCode),
|
|
84
|
+
data: frame
|
|
85
|
+
};
|
|
86
|
+
}
|
|
71
87
|
async function throwIfOpenAIStreamErrorBeforeOutput({
|
|
72
88
|
stream,
|
|
73
89
|
getError,
|
|
@@ -139,16 +155,14 @@ function parseStreamError(frame) {
|
|
|
139
155
|
return typeof (responseError == null ? void 0 : responseError.message) === "string" ? {
|
|
140
156
|
message: responseError.message,
|
|
141
157
|
code: getStringOrNumber(responseError.code),
|
|
142
|
-
type: "response.failed"
|
|
143
|
-
frame
|
|
158
|
+
type: "response.failed"
|
|
144
159
|
} : void 0;
|
|
145
160
|
}
|
|
146
161
|
const error = (_a2 = asRecord(value.error)) != null ? _a2 : value;
|
|
147
162
|
return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
|
|
148
163
|
message: error.message,
|
|
149
164
|
code: getStringOrNumber(error.code),
|
|
150
|
-
type: typeof error.type === "string" ? error.type : void 0
|
|
151
|
-
frame
|
|
165
|
+
type: typeof error.type === "string" ? error.type : void 0
|
|
152
166
|
} : void 0;
|
|
153
167
|
}
|
|
154
168
|
function getStatusCode(error) {
|
|
@@ -188,6 +202,15 @@ function getStringOrNumber(value) {
|
|
|
188
202
|
function isHttpErrorStatusCode(value) {
|
|
189
203
|
return Number.isInteger(value) && value >= 400 && value <= 599;
|
|
190
204
|
}
|
|
205
|
+
function isRetryableStatusCode(statusCode) {
|
|
206
|
+
return statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500;
|
|
207
|
+
}
|
|
208
|
+
function isRetryableStreamError(error, statusCode) {
|
|
209
|
+
if (error.code === "insufficient_quota" || error.type === "insufficient_quota") {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
return isRetryableStatusCode(statusCode);
|
|
213
|
+
}
|
|
191
214
|
|
|
192
215
|
// src/chat/convert-openai-chat-usage.ts
|
|
193
216
|
function convertOpenAIChatUsage(usage) {
|
|
@@ -4000,6 +4023,31 @@ var jsonValueSchema = z18.lazy(
|
|
|
4000
4023
|
z18.record(z18.string(), jsonValueSchema.optional())
|
|
4001
4024
|
])
|
|
4002
4025
|
);
|
|
4026
|
+
var jsonObjectSchema = z18.record(z18.string(), jsonValueSchema.optional());
|
|
4027
|
+
var openaiResponsesUsageSchema = z18.intersection(
|
|
4028
|
+
jsonObjectSchema,
|
|
4029
|
+
z18.object({
|
|
4030
|
+
input_tokens: z18.number(),
|
|
4031
|
+
input_tokens_details: z18.intersection(
|
|
4032
|
+
jsonObjectSchema,
|
|
4033
|
+
z18.object({
|
|
4034
|
+
cached_tokens: z18.number().nullish(),
|
|
4035
|
+
cache_write_tokens: z18.number().nullish(),
|
|
4036
|
+
orchestration_input_tokens: z18.number().nullish(),
|
|
4037
|
+
orchestration_input_cached_tokens: z18.number().nullish()
|
|
4038
|
+
})
|
|
4039
|
+
).nullish(),
|
|
4040
|
+
output_tokens: z18.number(),
|
|
4041
|
+
output_tokens_details: z18.intersection(
|
|
4042
|
+
jsonObjectSchema,
|
|
4043
|
+
z18.object({
|
|
4044
|
+
reasoning_tokens: z18.number().nullish(),
|
|
4045
|
+
orchestration_output_tokens: z18.number().nullish()
|
|
4046
|
+
})
|
|
4047
|
+
).nullish(),
|
|
4048
|
+
total_tokens: z18.number().optional()
|
|
4049
|
+
})
|
|
4050
|
+
);
|
|
4003
4051
|
function isRecord(value) {
|
|
4004
4052
|
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
4005
4053
|
}
|
|
@@ -4111,20 +4159,7 @@ var openaiResponsesChunkSchema = lazySchema16(
|
|
|
4111
4159
|
type: z18.enum(["response.completed", "response.incomplete"]),
|
|
4112
4160
|
response: z18.object({
|
|
4113
4161
|
incomplete_details: z18.object({ reason: z18.string() }).nullish(),
|
|
4114
|
-
usage:
|
|
4115
|
-
input_tokens: z18.number(),
|
|
4116
|
-
input_tokens_details: z18.object({
|
|
4117
|
-
cached_tokens: z18.number().nullish(),
|
|
4118
|
-
cache_write_tokens: z18.number().nullish(),
|
|
4119
|
-
orchestration_input_tokens: z18.number().nullish(),
|
|
4120
|
-
orchestration_input_cached_tokens: z18.number().nullish()
|
|
4121
|
-
}).nullish(),
|
|
4122
|
-
output_tokens: z18.number(),
|
|
4123
|
-
output_tokens_details: z18.object({
|
|
4124
|
-
reasoning_tokens: z18.number().nullish(),
|
|
4125
|
-
orchestration_output_tokens: z18.number().nullish()
|
|
4126
|
-
}).nullish()
|
|
4127
|
-
}),
|
|
4162
|
+
usage: openaiResponsesUsageSchema.nullish(),
|
|
4128
4163
|
reasoning: z18.object({
|
|
4129
4164
|
context: z18.string().nullish()
|
|
4130
4165
|
}).nullish(),
|
|
@@ -4140,20 +4175,7 @@ var openaiResponsesChunkSchema = lazySchema16(
|
|
|
4140
4175
|
message: z18.string()
|
|
4141
4176
|
}).nullish(),
|
|
4142
4177
|
incomplete_details: z18.object({ reason: z18.string() }).nullish(),
|
|
4143
|
-
usage:
|
|
4144
|
-
input_tokens: z18.number(),
|
|
4145
|
-
input_tokens_details: z18.object({
|
|
4146
|
-
cached_tokens: z18.number().nullish(),
|
|
4147
|
-
cache_write_tokens: z18.number().nullish(),
|
|
4148
|
-
orchestration_input_tokens: z18.number().nullish(),
|
|
4149
|
-
orchestration_input_cached_tokens: z18.number().nullish()
|
|
4150
|
-
}).nullish(),
|
|
4151
|
-
output_tokens: z18.number(),
|
|
4152
|
-
output_tokens_details: z18.object({
|
|
4153
|
-
reasoning_tokens: z18.number().nullish(),
|
|
4154
|
-
orchestration_output_tokens: z18.number().nullish()
|
|
4155
|
-
}).nullish()
|
|
4156
|
-
}).nullish(),
|
|
4178
|
+
usage: openaiResponsesUsageSchema.nullish(),
|
|
4157
4179
|
reasoning: z18.object({
|
|
4158
4180
|
context: z18.string().nullish()
|
|
4159
4181
|
}).nullish(),
|
|
@@ -4919,20 +4941,7 @@ var openaiResponsesResponseSchema = lazySchema16(
|
|
|
4919
4941
|
context: z18.string().nullish()
|
|
4920
4942
|
}).nullish(),
|
|
4921
4943
|
incomplete_details: z18.object({ reason: z18.string() }).nullish(),
|
|
4922
|
-
usage:
|
|
4923
|
-
input_tokens: z18.number(),
|
|
4924
|
-
input_tokens_details: z18.object({
|
|
4925
|
-
cached_tokens: z18.number().nullish(),
|
|
4926
|
-
cache_write_tokens: z18.number().nullish(),
|
|
4927
|
-
orchestration_input_tokens: z18.number().nullish(),
|
|
4928
|
-
orchestration_input_cached_tokens: z18.number().nullish()
|
|
4929
|
-
}).nullish(),
|
|
4930
|
-
output_tokens: z18.number(),
|
|
4931
|
-
output_tokens_details: z18.object({
|
|
4932
|
-
reasoning_tokens: z18.number().nullish(),
|
|
4933
|
-
orchestration_output_tokens: z18.number().nullish()
|
|
4934
|
-
}).nullish()
|
|
4935
|
-
}).optional()
|
|
4944
|
+
usage: openaiResponsesUsageSchema.nullish()
|
|
4936
4945
|
})
|
|
4937
4946
|
)
|
|
4938
4947
|
);
|
|
@@ -4986,7 +4995,8 @@ var openaiResponsesReasoningModelIds = [
|
|
|
4986
4995
|
"gpt-5.6",
|
|
4987
4996
|
"gpt-5.6-luna",
|
|
4988
4997
|
"gpt-5.6-sol",
|
|
4989
|
-
"gpt-5.6-terra"
|
|
4998
|
+
"gpt-5.6-terra",
|
|
4999
|
+
"gpt-6-astra"
|
|
4990
5000
|
];
|
|
4991
5001
|
var openaiResponsesModelIds = [
|
|
4992
5002
|
"gpt-4.1",
|
|
@@ -6876,7 +6886,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6876
6886
|
controller.enqueue({ type: "stream-start", warnings });
|
|
6877
6887
|
},
|
|
6878
6888
|
transform(chunk, controller) {
|
|
6879
|
-
var _a3, _b2, _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, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P;
|
|
6889
|
+
var _a3, _b2, _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, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S;
|
|
6880
6890
|
if (options.includeRawChunks) {
|
|
6881
6891
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
6882
6892
|
}
|
|
@@ -7697,15 +7707,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7697
7707
|
raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
|
|
7698
7708
|
};
|
|
7699
7709
|
}
|
|
7700
|
-
usage = value.response.usage;
|
|
7710
|
+
usage = (_A = value.response.usage) != null ? _A : void 0;
|
|
7701
7711
|
if (typeof value.response.service_tier === "string") {
|
|
7702
7712
|
serviceTier = value.response.service_tier;
|
|
7703
7713
|
}
|
|
7704
|
-
if (((
|
|
7714
|
+
if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
|
|
7705
7715
|
reasoningContext = value.response.reasoning.context;
|
|
7706
7716
|
}
|
|
7707
7717
|
} else if (isResponseFailedChunk(value)) {
|
|
7708
|
-
const incompleteReason = (
|
|
7718
|
+
const incompleteReason = (_C = value.response.incomplete_details) == null ? void 0 : _C.reason;
|
|
7709
7719
|
finishReason = {
|
|
7710
7720
|
unified: incompleteReason ? mapOpenAIResponseFinishReason({
|
|
7711
7721
|
finishReason: incompleteReason,
|
|
@@ -7713,23 +7723,24 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7713
7723
|
}) : "error",
|
|
7714
7724
|
raw: incompleteReason != null ? incompleteReason : "error"
|
|
7715
7725
|
};
|
|
7716
|
-
usage = (
|
|
7717
|
-
if (((
|
|
7726
|
+
usage = (_D = value.response.usage) != null ? _D : void 0;
|
|
7727
|
+
if (((_E = value.response.reasoning) == null ? void 0 : _E.context) != null) {
|
|
7718
7728
|
reasoningContext = value.response.reasoning.context;
|
|
7719
7729
|
}
|
|
7720
7730
|
if (!encounteredStreamError && value.response.error != null) {
|
|
7721
7731
|
encounteredStreamError = true;
|
|
7732
|
+
const error = {
|
|
7733
|
+
type: "response.failed",
|
|
7734
|
+
sequence_number: value.sequence_number,
|
|
7735
|
+
response: {
|
|
7736
|
+
error: value.response.error,
|
|
7737
|
+
incomplete_details: value.response.incomplete_details,
|
|
7738
|
+
service_tier: value.response.service_tier
|
|
7739
|
+
}
|
|
7740
|
+
};
|
|
7722
7741
|
controller.enqueue({
|
|
7723
7742
|
type: "error",
|
|
7724
|
-
error:
|
|
7725
|
-
type: "response.failed",
|
|
7726
|
-
sequence_number: value.sequence_number,
|
|
7727
|
-
response: {
|
|
7728
|
-
error: value.response.error,
|
|
7729
|
-
incomplete_details: value.response.incomplete_details,
|
|
7730
|
-
service_tier: value.response.service_tier
|
|
7731
|
-
}
|
|
7732
|
-
}
|
|
7743
|
+
error: (_F = createOpenAIProviderStreamError(error)) != null ? _F : error
|
|
7733
7744
|
});
|
|
7734
7745
|
}
|
|
7735
7746
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
@@ -7738,7 +7749,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7738
7749
|
controller.enqueue({
|
|
7739
7750
|
type: "source",
|
|
7740
7751
|
sourceType: "url",
|
|
7741
|
-
id: (
|
|
7752
|
+
id: (_I = (_H = (_G = self.config).generateId) == null ? void 0 : _H.call(_G)) != null ? _I : generateId2(),
|
|
7742
7753
|
url: value.annotation.url,
|
|
7743
7754
|
title: value.annotation.title
|
|
7744
7755
|
});
|
|
@@ -7746,7 +7757,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7746
7757
|
controller.enqueue({
|
|
7747
7758
|
type: "source",
|
|
7748
7759
|
sourceType: "document",
|
|
7749
|
-
id: (
|
|
7760
|
+
id: (_L = (_K = (_J = self.config).generateId) == null ? void 0 : _K.call(_J)) != null ? _L : generateId2(),
|
|
7750
7761
|
mediaType: "text/plain",
|
|
7751
7762
|
title: value.annotation.filename,
|
|
7752
7763
|
filename: value.annotation.filename,
|
|
@@ -7762,7 +7773,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7762
7773
|
controller.enqueue({
|
|
7763
7774
|
type: "source",
|
|
7764
7775
|
sourceType: "document",
|
|
7765
|
-
id: (
|
|
7776
|
+
id: (_O = (_N = (_M = self.config).generateId) == null ? void 0 : _N.call(_M)) != null ? _O : generateId2(),
|
|
7766
7777
|
mediaType: "text/plain",
|
|
7767
7778
|
title: value.annotation.filename,
|
|
7768
7779
|
filename: value.annotation.filename,
|
|
@@ -7778,7 +7789,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7778
7789
|
controller.enqueue({
|
|
7779
7790
|
type: "source",
|
|
7780
7791
|
sourceType: "document",
|
|
7781
|
-
id: (
|
|
7792
|
+
id: (_R = (_Q = (_P = self.config).generateId) == null ? void 0 : _Q.call(_P)) != null ? _R : generateId2(),
|
|
7782
7793
|
mediaType: "application/octet-stream",
|
|
7783
7794
|
title: value.annotation.file_id,
|
|
7784
7795
|
filename: value.annotation.file_id,
|
|
@@ -7794,7 +7805,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7794
7805
|
} else if (isErrorChunk(value)) {
|
|
7795
7806
|
encounteredStreamError = true;
|
|
7796
7807
|
finishReason = { unified: "error", raw: "error" };
|
|
7797
|
-
controller.enqueue({
|
|
7808
|
+
controller.enqueue({
|
|
7809
|
+
type: "error",
|
|
7810
|
+
error: (_S = createOpenAIProviderStreamError(value)) != null ? _S : value
|
|
7811
|
+
});
|
|
7798
7812
|
}
|
|
7799
7813
|
},
|
|
7800
7814
|
flush(controller) {
|