@ai-sdk/openai 2.0.0-beta.4 → 2.0.0-beta.5
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.js +36 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -6
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +36 -6
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +38 -6
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/internal/index.js
CHANGED
|
@@ -1976,6 +1976,7 @@ var OpenAISpeechModel = class {
|
|
|
1976
1976
|
};
|
|
1977
1977
|
|
|
1978
1978
|
// src/responses/openai-responses-language-model.ts
|
|
1979
|
+
var import_provider8 = require("@ai-sdk/provider");
|
|
1979
1980
|
var import_provider_utils12 = require("@ai-sdk/provider-utils");
|
|
1980
1981
|
var import_v415 = require("zod/v4");
|
|
1981
1982
|
|
|
@@ -2100,7 +2101,7 @@ async function convertToOpenAIResponsesMessages({
|
|
|
2100
2101
|
const summaryParts = [];
|
|
2101
2102
|
if (part.text.length > 0) {
|
|
2102
2103
|
summaryParts.push({ type: "summary_text", text: part.text });
|
|
2103
|
-
} else {
|
|
2104
|
+
} else if (existingReasoningMessage !== void 0) {
|
|
2104
2105
|
warnings.push({
|
|
2105
2106
|
type: "other",
|
|
2106
2107
|
message: `Cannot append empty reasoning part to existing reasoning sequence. Skipping reasoning part: ${JSON.stringify(part)}.`
|
|
@@ -2418,15 +2419,16 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2418
2419
|
async doGenerate(options) {
|
|
2419
2420
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2420
2421
|
const { args: body, warnings } = await this.getArgs(options);
|
|
2422
|
+
const url = this.config.url({
|
|
2423
|
+
path: "/responses",
|
|
2424
|
+
modelId: this.modelId
|
|
2425
|
+
});
|
|
2421
2426
|
const {
|
|
2422
2427
|
responseHeaders,
|
|
2423
2428
|
value: response,
|
|
2424
2429
|
rawValue: rawResponse
|
|
2425
2430
|
} = await (0, import_provider_utils12.postJsonToApi)({
|
|
2426
|
-
url
|
|
2427
|
-
path: "/responses",
|
|
2428
|
-
modelId: this.modelId
|
|
2429
|
-
}),
|
|
2431
|
+
url,
|
|
2430
2432
|
headers: (0, import_provider_utils12.combineHeaders)(this.config.headers(), options.headers),
|
|
2431
2433
|
body,
|
|
2432
2434
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
@@ -2434,6 +2436,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2434
2436
|
import_v415.z.object({
|
|
2435
2437
|
id: import_v415.z.string(),
|
|
2436
2438
|
created_at: import_v415.z.number(),
|
|
2439
|
+
error: import_v415.z.object({
|
|
2440
|
+
code: import_v415.z.string(),
|
|
2441
|
+
message: import_v415.z.string()
|
|
2442
|
+
}).nullish(),
|
|
2437
2443
|
model: import_v415.z.string(),
|
|
2438
2444
|
output: import_v415.z.array(
|
|
2439
2445
|
import_v415.z.discriminatedUnion("type", [
|
|
@@ -2492,6 +2498,17 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2492
2498
|
abortSignal: options.abortSignal,
|
|
2493
2499
|
fetch: this.config.fetch
|
|
2494
2500
|
});
|
|
2501
|
+
if (response.error) {
|
|
2502
|
+
throw new import_provider8.APICallError({
|
|
2503
|
+
message: response.error.message,
|
|
2504
|
+
url,
|
|
2505
|
+
requestBodyValues: body,
|
|
2506
|
+
statusCode: 400,
|
|
2507
|
+
responseHeaders,
|
|
2508
|
+
responseBody: rawResponse,
|
|
2509
|
+
isRetryable: false
|
|
2510
|
+
});
|
|
2511
|
+
}
|
|
2495
2512
|
const content = [];
|
|
2496
2513
|
for (const part of response.output) {
|
|
2497
2514
|
switch (part.type) {
|
|
@@ -2834,6 +2851,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2834
2851
|
url: value.annotation.url,
|
|
2835
2852
|
title: value.annotation.title
|
|
2836
2853
|
});
|
|
2854
|
+
} else if (isErrorChunk(value)) {
|
|
2855
|
+
controller.enqueue({ type: "error", error: value });
|
|
2837
2856
|
}
|
|
2838
2857
|
},
|
|
2839
2858
|
flush(controller) {
|
|
@@ -2866,6 +2885,13 @@ var textDeltaChunkSchema = import_v415.z.object({
|
|
|
2866
2885
|
item_id: import_v415.z.string(),
|
|
2867
2886
|
delta: import_v415.z.string()
|
|
2868
2887
|
});
|
|
2888
|
+
var errorChunkSchema = import_v415.z.object({
|
|
2889
|
+
type: import_v415.z.literal("error"),
|
|
2890
|
+
code: import_v415.z.string(),
|
|
2891
|
+
message: import_v415.z.string(),
|
|
2892
|
+
param: import_v415.z.string().nullish(),
|
|
2893
|
+
sequence_number: import_v415.z.number()
|
|
2894
|
+
});
|
|
2869
2895
|
var responseFinishedChunkSchema = import_v415.z.object({
|
|
2870
2896
|
type: import_v415.z.enum(["response.completed", "response.incomplete"]),
|
|
2871
2897
|
response: import_v415.z.object({
|
|
@@ -2986,7 +3012,8 @@ var openaiResponsesChunkSchema = import_v415.z.union([
|
|
|
2986
3012
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2987
3013
|
responseAnnotationAddedSchema,
|
|
2988
3014
|
responseReasoningSummaryTextDeltaSchema,
|
|
2989
|
-
|
|
3015
|
+
errorChunkSchema,
|
|
3016
|
+
import_v415.z.object({ type: import_v415.z.string() }).loose()
|
|
2990
3017
|
// fallback for unknown chunks
|
|
2991
3018
|
]);
|
|
2992
3019
|
function isTextDeltaChunk(chunk) {
|
|
@@ -3013,6 +3040,9 @@ function isResponseAnnotationAddedChunk(chunk) {
|
|
|
3013
3040
|
function isResponseReasoningSummaryTextDeltaChunk(chunk) {
|
|
3014
3041
|
return chunk.type === "response.reasoning_summary_text.delta";
|
|
3015
3042
|
}
|
|
3043
|
+
function isErrorChunk(chunk) {
|
|
3044
|
+
return chunk.type === "error";
|
|
3045
|
+
}
|
|
3016
3046
|
function getResponsesModelConfig(modelId) {
|
|
3017
3047
|
if (modelId.startsWith("o") || modelId.startsWith("codex-") || modelId.startsWith("computer-use")) {
|
|
3018
3048
|
if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
|