@ai-sdk/openai 3.0.106 → 3.0.107
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.d.mts +17 -15
- package/dist/index.d.ts +17 -15
- package/dist/index.js +80 -67
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +80 -67
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +17 -15
- package/dist/internal/index.d.ts +17 -15
- package/dist/internal/index.js +79 -66
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +79 -66
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
- 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/dist/index.mjs
CHANGED
|
@@ -76,6 +76,22 @@ function getGptVersion(modelId) {
|
|
|
76
76
|
|
|
77
77
|
// src/openai-stream-error.ts
|
|
78
78
|
import { APICallError } from "@ai-sdk/provider";
|
|
79
|
+
function createOpenAIProviderStreamError(frame) {
|
|
80
|
+
var _a2, _b;
|
|
81
|
+
const streamError = parseStreamError(frame);
|
|
82
|
+
if (streamError == null) {
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
const statusCode = getStatusCode(streamError);
|
|
86
|
+
return {
|
|
87
|
+
message: streamError.message,
|
|
88
|
+
type: (_a2 = streamError.type) != null ? _a2 : void 0,
|
|
89
|
+
code: (_b = streamError.code) != null ? _b : void 0,
|
|
90
|
+
statusCode,
|
|
91
|
+
isRetryable: isRetryableStreamError(streamError, statusCode),
|
|
92
|
+
data: frame
|
|
93
|
+
};
|
|
94
|
+
}
|
|
79
95
|
async function throwIfOpenAIStreamErrorBeforeOutput({
|
|
80
96
|
stream,
|
|
81
97
|
getError,
|
|
@@ -147,16 +163,14 @@ function parseStreamError(frame) {
|
|
|
147
163
|
return typeof (responseError == null ? void 0 : responseError.message) === "string" ? {
|
|
148
164
|
message: responseError.message,
|
|
149
165
|
code: getStringOrNumber(responseError.code),
|
|
150
|
-
type: "response.failed"
|
|
151
|
-
frame
|
|
166
|
+
type: "response.failed"
|
|
152
167
|
} : void 0;
|
|
153
168
|
}
|
|
154
169
|
const error = (_a2 = asRecord(value.error)) != null ? _a2 : value;
|
|
155
170
|
return typeof error.message === "string" && (asRecord(value.error) != null || typeof error.type === "string" || "code" in error || "param" in error) ? {
|
|
156
171
|
message: error.message,
|
|
157
172
|
code: getStringOrNumber(error.code),
|
|
158
|
-
type: typeof error.type === "string" ? error.type : void 0
|
|
159
|
-
frame
|
|
173
|
+
type: typeof error.type === "string" ? error.type : void 0
|
|
160
174
|
} : void 0;
|
|
161
175
|
}
|
|
162
176
|
function getStatusCode(error) {
|
|
@@ -196,6 +210,15 @@ function getStringOrNumber(value) {
|
|
|
196
210
|
function isHttpErrorStatusCode(value) {
|
|
197
211
|
return Number.isInteger(value) && value >= 400 && value <= 599;
|
|
198
212
|
}
|
|
213
|
+
function isRetryableStatusCode(statusCode) {
|
|
214
|
+
return statusCode === 408 || statusCode === 409 || statusCode === 429 || statusCode >= 500;
|
|
215
|
+
}
|
|
216
|
+
function isRetryableStreamError(error, statusCode) {
|
|
217
|
+
if (error.code === "insufficient_quota" || error.type === "insufficient_quota") {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
return isRetryableStatusCode(statusCode);
|
|
221
|
+
}
|
|
199
222
|
|
|
200
223
|
// src/chat/convert-openai-chat-usage.ts
|
|
201
224
|
function convertOpenAIChatUsage(usage) {
|
|
@@ -4109,6 +4132,31 @@ var jsonValueSchema2 = z22.lazy(
|
|
|
4109
4132
|
z22.record(z22.string(), jsonValueSchema2.optional())
|
|
4110
4133
|
])
|
|
4111
4134
|
);
|
|
4135
|
+
var jsonObjectSchema = z22.record(z22.string(), jsonValueSchema2.optional());
|
|
4136
|
+
var openaiResponsesUsageSchema = z22.intersection(
|
|
4137
|
+
jsonObjectSchema,
|
|
4138
|
+
z22.object({
|
|
4139
|
+
input_tokens: z22.number(),
|
|
4140
|
+
input_tokens_details: z22.intersection(
|
|
4141
|
+
jsonObjectSchema,
|
|
4142
|
+
z22.object({
|
|
4143
|
+
cached_tokens: z22.number().nullish(),
|
|
4144
|
+
cache_write_tokens: z22.number().nullish(),
|
|
4145
|
+
orchestration_input_tokens: z22.number().nullish(),
|
|
4146
|
+
orchestration_input_cached_tokens: z22.number().nullish()
|
|
4147
|
+
})
|
|
4148
|
+
).nullish(),
|
|
4149
|
+
output_tokens: z22.number(),
|
|
4150
|
+
output_tokens_details: z22.intersection(
|
|
4151
|
+
jsonObjectSchema,
|
|
4152
|
+
z22.object({
|
|
4153
|
+
reasoning_tokens: z22.number().nullish(),
|
|
4154
|
+
orchestration_output_tokens: z22.number().nullish()
|
|
4155
|
+
})
|
|
4156
|
+
).nullish(),
|
|
4157
|
+
total_tokens: z22.number().optional()
|
|
4158
|
+
})
|
|
4159
|
+
);
|
|
4112
4160
|
function isRecord(value) {
|
|
4113
4161
|
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
4114
4162
|
}
|
|
@@ -4220,20 +4268,7 @@ var openaiResponsesChunkSchema = lazySchema20(
|
|
|
4220
4268
|
type: z22.enum(["response.completed", "response.incomplete"]),
|
|
4221
4269
|
response: z22.object({
|
|
4222
4270
|
incomplete_details: z22.object({ reason: z22.string() }).nullish(),
|
|
4223
|
-
usage:
|
|
4224
|
-
input_tokens: z22.number(),
|
|
4225
|
-
input_tokens_details: z22.object({
|
|
4226
|
-
cached_tokens: z22.number().nullish(),
|
|
4227
|
-
cache_write_tokens: z22.number().nullish(),
|
|
4228
|
-
orchestration_input_tokens: z22.number().nullish(),
|
|
4229
|
-
orchestration_input_cached_tokens: z22.number().nullish()
|
|
4230
|
-
}).nullish(),
|
|
4231
|
-
output_tokens: z22.number(),
|
|
4232
|
-
output_tokens_details: z22.object({
|
|
4233
|
-
reasoning_tokens: z22.number().nullish(),
|
|
4234
|
-
orchestration_output_tokens: z22.number().nullish()
|
|
4235
|
-
}).nullish()
|
|
4236
|
-
}),
|
|
4271
|
+
usage: openaiResponsesUsageSchema.nullish(),
|
|
4237
4272
|
reasoning: z22.object({
|
|
4238
4273
|
context: z22.string().nullish()
|
|
4239
4274
|
}).nullish(),
|
|
@@ -4249,20 +4284,7 @@ var openaiResponsesChunkSchema = lazySchema20(
|
|
|
4249
4284
|
message: z22.string()
|
|
4250
4285
|
}).nullish(),
|
|
4251
4286
|
incomplete_details: z22.object({ reason: z22.string() }).nullish(),
|
|
4252
|
-
usage:
|
|
4253
|
-
input_tokens: z22.number(),
|
|
4254
|
-
input_tokens_details: z22.object({
|
|
4255
|
-
cached_tokens: z22.number().nullish(),
|
|
4256
|
-
cache_write_tokens: z22.number().nullish(),
|
|
4257
|
-
orchestration_input_tokens: z22.number().nullish(),
|
|
4258
|
-
orchestration_input_cached_tokens: z22.number().nullish()
|
|
4259
|
-
}).nullish(),
|
|
4260
|
-
output_tokens: z22.number(),
|
|
4261
|
-
output_tokens_details: z22.object({
|
|
4262
|
-
reasoning_tokens: z22.number().nullish(),
|
|
4263
|
-
orchestration_output_tokens: z22.number().nullish()
|
|
4264
|
-
}).nullish()
|
|
4265
|
-
}).nullish(),
|
|
4287
|
+
usage: openaiResponsesUsageSchema.nullish(),
|
|
4266
4288
|
reasoning: z22.object({
|
|
4267
4289
|
context: z22.string().nullish()
|
|
4268
4290
|
}).nullish(),
|
|
@@ -5028,20 +5050,7 @@ var openaiResponsesResponseSchema = lazySchema20(
|
|
|
5028
5050
|
context: z22.string().nullish()
|
|
5029
5051
|
}).nullish(),
|
|
5030
5052
|
incomplete_details: z22.object({ reason: z22.string() }).nullish(),
|
|
5031
|
-
usage:
|
|
5032
|
-
input_tokens: z22.number(),
|
|
5033
|
-
input_tokens_details: z22.object({
|
|
5034
|
-
cached_tokens: z22.number().nullish(),
|
|
5035
|
-
cache_write_tokens: z22.number().nullish(),
|
|
5036
|
-
orchestration_input_tokens: z22.number().nullish(),
|
|
5037
|
-
orchestration_input_cached_tokens: z22.number().nullish()
|
|
5038
|
-
}).nullish(),
|
|
5039
|
-
output_tokens: z22.number(),
|
|
5040
|
-
output_tokens_details: z22.object({
|
|
5041
|
-
reasoning_tokens: z22.number().nullish(),
|
|
5042
|
-
orchestration_output_tokens: z22.number().nullish()
|
|
5043
|
-
}).nullish()
|
|
5044
|
-
}).optional()
|
|
5053
|
+
usage: openaiResponsesUsageSchema.nullish()
|
|
5045
5054
|
})
|
|
5046
5055
|
)
|
|
5047
5056
|
);
|
|
@@ -6633,7 +6642,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6633
6642
|
controller.enqueue({ type: "stream-start", warnings });
|
|
6634
6643
|
},
|
|
6635
6644
|
transform(chunk, controller) {
|
|
6636
|
-
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;
|
|
6645
|
+
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;
|
|
6637
6646
|
if (options.includeRawChunks) {
|
|
6638
6647
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
6639
6648
|
}
|
|
@@ -7454,15 +7463,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7454
7463
|
raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
|
|
7455
7464
|
};
|
|
7456
7465
|
}
|
|
7457
|
-
usage = value.response.usage;
|
|
7466
|
+
usage = (_A = value.response.usage) != null ? _A : void 0;
|
|
7458
7467
|
if (typeof value.response.service_tier === "string") {
|
|
7459
7468
|
serviceTier = value.response.service_tier;
|
|
7460
7469
|
}
|
|
7461
|
-
if (((
|
|
7470
|
+
if (((_B = value.response.reasoning) == null ? void 0 : _B.context) != null) {
|
|
7462
7471
|
reasoningContext = value.response.reasoning.context;
|
|
7463
7472
|
}
|
|
7464
7473
|
} else if (isResponseFailedChunk(value)) {
|
|
7465
|
-
const incompleteReason = (
|
|
7474
|
+
const incompleteReason = (_C = value.response.incomplete_details) == null ? void 0 : _C.reason;
|
|
7466
7475
|
finishReason = {
|
|
7467
7476
|
unified: incompleteReason ? mapOpenAIResponseFinishReason({
|
|
7468
7477
|
finishReason: incompleteReason,
|
|
@@ -7470,23 +7479,24 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7470
7479
|
}) : "error",
|
|
7471
7480
|
raw: incompleteReason != null ? incompleteReason : "error"
|
|
7472
7481
|
};
|
|
7473
|
-
usage = (
|
|
7474
|
-
if (((
|
|
7482
|
+
usage = (_D = value.response.usage) != null ? _D : void 0;
|
|
7483
|
+
if (((_E = value.response.reasoning) == null ? void 0 : _E.context) != null) {
|
|
7475
7484
|
reasoningContext = value.response.reasoning.context;
|
|
7476
7485
|
}
|
|
7477
7486
|
if (!encounteredStreamError && value.response.error != null) {
|
|
7478
7487
|
encounteredStreamError = true;
|
|
7488
|
+
const error = {
|
|
7489
|
+
type: "response.failed",
|
|
7490
|
+
sequence_number: value.sequence_number,
|
|
7491
|
+
response: {
|
|
7492
|
+
error: value.response.error,
|
|
7493
|
+
incomplete_details: value.response.incomplete_details,
|
|
7494
|
+
service_tier: value.response.service_tier
|
|
7495
|
+
}
|
|
7496
|
+
};
|
|
7479
7497
|
controller.enqueue({
|
|
7480
7498
|
type: "error",
|
|
7481
|
-
error:
|
|
7482
|
-
type: "response.failed",
|
|
7483
|
-
sequence_number: value.sequence_number,
|
|
7484
|
-
response: {
|
|
7485
|
-
error: value.response.error,
|
|
7486
|
-
incomplete_details: value.response.incomplete_details,
|
|
7487
|
-
service_tier: value.response.service_tier
|
|
7488
|
-
}
|
|
7489
|
-
}
|
|
7499
|
+
error: (_F = createOpenAIProviderStreamError(error)) != null ? _F : error
|
|
7490
7500
|
});
|
|
7491
7501
|
}
|
|
7492
7502
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
@@ -7495,7 +7505,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7495
7505
|
controller.enqueue({
|
|
7496
7506
|
type: "source",
|
|
7497
7507
|
sourceType: "url",
|
|
7498
|
-
id: (
|
|
7508
|
+
id: (_I = (_H = (_G = self.config).generateId) == null ? void 0 : _H.call(_G)) != null ? _I : generateId2(),
|
|
7499
7509
|
url: value.annotation.url,
|
|
7500
7510
|
title: value.annotation.title
|
|
7501
7511
|
});
|
|
@@ -7503,7 +7513,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7503
7513
|
controller.enqueue({
|
|
7504
7514
|
type: "source",
|
|
7505
7515
|
sourceType: "document",
|
|
7506
|
-
id: (
|
|
7516
|
+
id: (_L = (_K = (_J = self.config).generateId) == null ? void 0 : _K.call(_J)) != null ? _L : generateId2(),
|
|
7507
7517
|
mediaType: "text/plain",
|
|
7508
7518
|
title: value.annotation.filename,
|
|
7509
7519
|
filename: value.annotation.filename,
|
|
@@ -7519,7 +7529,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7519
7529
|
controller.enqueue({
|
|
7520
7530
|
type: "source",
|
|
7521
7531
|
sourceType: "document",
|
|
7522
|
-
id: (
|
|
7532
|
+
id: (_O = (_N = (_M = self.config).generateId) == null ? void 0 : _N.call(_M)) != null ? _O : generateId2(),
|
|
7523
7533
|
mediaType: "text/plain",
|
|
7524
7534
|
title: value.annotation.filename,
|
|
7525
7535
|
filename: value.annotation.filename,
|
|
@@ -7535,7 +7545,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7535
7545
|
controller.enqueue({
|
|
7536
7546
|
type: "source",
|
|
7537
7547
|
sourceType: "document",
|
|
7538
|
-
id: (
|
|
7548
|
+
id: (_R = (_Q = (_P = self.config).generateId) == null ? void 0 : _Q.call(_P)) != null ? _R : generateId2(),
|
|
7539
7549
|
mediaType: "application/octet-stream",
|
|
7540
7550
|
title: value.annotation.file_id,
|
|
7541
7551
|
filename: value.annotation.file_id,
|
|
@@ -7551,7 +7561,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7551
7561
|
} else if (isErrorChunk(value)) {
|
|
7552
7562
|
encounteredStreamError = true;
|
|
7553
7563
|
finishReason = { unified: "error", raw: "error" };
|
|
7554
|
-
controller.enqueue({
|
|
7564
|
+
controller.enqueue({
|
|
7565
|
+
type: "error",
|
|
7566
|
+
error: (_S = createOpenAIProviderStreamError(value)) != null ? _S : value
|
|
7567
|
+
});
|
|
7555
7568
|
}
|
|
7556
7569
|
},
|
|
7557
7570
|
flush(controller) {
|
|
@@ -8072,7 +8085,7 @@ var OpenAITranscriptionModel = class {
|
|
|
8072
8085
|
};
|
|
8073
8086
|
|
|
8074
8087
|
// src/version.ts
|
|
8075
|
-
var VERSION = true ? "3.0.
|
|
8088
|
+
var VERSION = true ? "3.0.107" : "0.0.0-test";
|
|
8076
8089
|
|
|
8077
8090
|
// src/openai-provider.ts
|
|
8078
8091
|
function createOpenAI(options = {}) {
|