@ai-sdk/openai 3.0.136 → 3.0.138
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 +28 -0
- package/dist/index.d.mts +23 -2
- package/dist/index.d.ts +23 -2
- package/dist/index.js +290 -85
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +276 -69
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +23 -2
- package/dist/internal/index.d.ts +23 -2
- package/dist/internal/index.js +289 -84
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +275 -68
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-openai.mdx +92 -0
- package/package.json +3 -3
- package/src/chat/map-openai-finish-reason.ts +11 -4
- package/src/chat/openai-chat-api.ts +36 -0
- package/src/chat/openai-chat-language-model.ts +101 -12
- package/src/image/openai-image-model-options.ts +44 -0
- package/src/image/openai-image-model.ts +44 -4
- package/src/responses/map-openai-responses-finish-reason.ts +7 -1
- package/src/responses/openai-responses-api.ts +71 -48
- package/src/responses/openai-responses-language-model.ts +47 -0
package/dist/index.mjs
CHANGED
|
@@ -655,10 +655,13 @@ function getResponseMetadata({
|
|
|
655
655
|
}
|
|
656
656
|
|
|
657
657
|
// src/chat/map-openai-finish-reason.ts
|
|
658
|
-
function mapOpenAIFinishReason(
|
|
658
|
+
function mapOpenAIFinishReason({
|
|
659
|
+
finishReason,
|
|
660
|
+
hasRefusal = false
|
|
661
|
+
}) {
|
|
659
662
|
switch (finishReason) {
|
|
660
663
|
case "stop":
|
|
661
|
-
return "stop";
|
|
664
|
+
return hasRefusal ? "content-filter" : "stop";
|
|
662
665
|
case "length":
|
|
663
666
|
return "length";
|
|
664
667
|
case "content_filter":
|
|
@@ -688,6 +691,8 @@ var openaiChatResponseSchema = lazySchema2(
|
|
|
688
691
|
message: z2.object({
|
|
689
692
|
role: z2.literal("assistant").nullish(),
|
|
690
693
|
content: z2.string().nullish(),
|
|
694
|
+
// set instead of `content` when the model refuses to answer:
|
|
695
|
+
refusal: z2.string().nullish(),
|
|
691
696
|
audio: z2.object({
|
|
692
697
|
transcript: z2.string().nullish()
|
|
693
698
|
}).nullish(),
|
|
@@ -726,6 +731,20 @@ var openaiChatResponseSchema = lazySchema2(
|
|
|
726
731
|
})
|
|
727
732
|
)
|
|
728
733
|
})
|
|
734
|
+
).nullish(),
|
|
735
|
+
// logprobs of the refusal tokens (set instead of `content` when
|
|
736
|
+
// the model refuses to answer):
|
|
737
|
+
refusal: z2.array(
|
|
738
|
+
z2.object({
|
|
739
|
+
token: z2.string(),
|
|
740
|
+
logprob: z2.number(),
|
|
741
|
+
top_logprobs: z2.array(
|
|
742
|
+
z2.object({
|
|
743
|
+
token: z2.string(),
|
|
744
|
+
logprob: z2.number()
|
|
745
|
+
})
|
|
746
|
+
)
|
|
747
|
+
})
|
|
729
748
|
).nullish()
|
|
730
749
|
}).nullish(),
|
|
731
750
|
finish_reason: z2.string().nullish()
|
|
@@ -760,6 +779,8 @@ var openaiChatChunkSchema = lazySchema2(
|
|
|
760
779
|
delta: z2.object({
|
|
761
780
|
role: z2.enum(["assistant"]).nullish(),
|
|
762
781
|
content: z2.string().nullish(),
|
|
782
|
+
// set instead of `content` when the model refuses to answer:
|
|
783
|
+
refusal: z2.string().nullish(),
|
|
763
784
|
tool_calls: z2.array(
|
|
764
785
|
z2.object({
|
|
765
786
|
index: z2.number(),
|
|
@@ -795,6 +816,20 @@ var openaiChatChunkSchema = lazySchema2(
|
|
|
795
816
|
})
|
|
796
817
|
)
|
|
797
818
|
})
|
|
819
|
+
).nullish(),
|
|
820
|
+
// logprobs of the refusal tokens (set instead of `content` when
|
|
821
|
+
// the model refuses to answer):
|
|
822
|
+
refusal: z2.array(
|
|
823
|
+
z2.object({
|
|
824
|
+
token: z2.string(),
|
|
825
|
+
logprob: z2.number(),
|
|
826
|
+
top_logprobs: z2.array(
|
|
827
|
+
z2.object({
|
|
828
|
+
token: z2.string(),
|
|
829
|
+
logprob: z2.number()
|
|
830
|
+
})
|
|
831
|
+
)
|
|
832
|
+
})
|
|
798
833
|
).nullish()
|
|
799
834
|
}).nullish(),
|
|
800
835
|
finish_reason: z2.string().nullish(),
|
|
@@ -1236,7 +1271,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1236
1271
|
};
|
|
1237
1272
|
}
|
|
1238
1273
|
async doGenerate(options) {
|
|
1239
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
1274
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1240
1275
|
const { args: body, warnings } = await this.getArgs(options);
|
|
1241
1276
|
const {
|
|
1242
1277
|
responseHeaders,
|
|
@@ -1268,6 +1303,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
1268
1303
|
if (text != null && text.length > 0) {
|
|
1269
1304
|
content.push({ type: "text", text });
|
|
1270
1305
|
}
|
|
1306
|
+
const refusal = choice.message.refusal;
|
|
1307
|
+
const hasRefusal = refusal != null && refusal.length > 0;
|
|
1308
|
+
if (hasRefusal) {
|
|
1309
|
+
content.push({ type: "text", text: refusal });
|
|
1310
|
+
}
|
|
1271
1311
|
for (const toolCall of (_b = choice.message.tool_calls) != null ? _b : []) {
|
|
1272
1312
|
content.push({
|
|
1273
1313
|
type: "tool-call",
|
|
@@ -1294,14 +1334,22 @@ var OpenAIChatLanguageModel = class {
|
|
|
1294
1334
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
|
|
1295
1335
|
providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
|
|
1296
1336
|
}
|
|
1297
|
-
|
|
1298
|
-
|
|
1337
|
+
const contentLogprobs = (_g = choice.logprobs) == null ? void 0 : _g.content;
|
|
1338
|
+
const refusalLogprobs = (_h = choice.logprobs) == null ? void 0 : _h.refusal;
|
|
1339
|
+
if (contentLogprobs != null || refusalLogprobs != null) {
|
|
1340
|
+
providerMetadata.openai.logprobs = [
|
|
1341
|
+
...contentLogprobs != null ? contentLogprobs : [],
|
|
1342
|
+
...refusalLogprobs != null ? refusalLogprobs : []
|
|
1343
|
+
];
|
|
1299
1344
|
}
|
|
1300
1345
|
return {
|
|
1301
1346
|
content,
|
|
1302
1347
|
finishReason: {
|
|
1303
|
-
unified: mapOpenAIFinishReason(
|
|
1304
|
-
|
|
1348
|
+
unified: mapOpenAIFinishReason({
|
|
1349
|
+
finishReason: choice.finish_reason,
|
|
1350
|
+
hasRefusal
|
|
1351
|
+
}),
|
|
1352
|
+
raw: (_i = choice.finish_reason) != null ? _i : void 0
|
|
1305
1353
|
},
|
|
1306
1354
|
usage: convertOpenAIChatUsage(response.usage),
|
|
1307
1355
|
request: { body },
|
|
@@ -1354,6 +1402,10 @@ var OpenAIChatLanguageModel = class {
|
|
|
1354
1402
|
let usage = void 0;
|
|
1355
1403
|
let metadataExtracted = false;
|
|
1356
1404
|
let isActiveText = false;
|
|
1405
|
+
let hasRefusal = false;
|
|
1406
|
+
let rawFinishReason = void 0;
|
|
1407
|
+
let hasLogprobs = false;
|
|
1408
|
+
const streamedLogprobs = [];
|
|
1357
1409
|
const providerMetadata = { openai: {} };
|
|
1358
1410
|
const result = {
|
|
1359
1411
|
stream: checkedResponse.pipeThrough(
|
|
@@ -1366,18 +1418,20 @@ var OpenAIChatLanguageModel = class {
|
|
|
1366
1418
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1367
1419
|
},
|
|
1368
1420
|
transform(chunk, controller) {
|
|
1369
|
-
var _a2, _b, _c, _d
|
|
1421
|
+
var _a2, _b, _c, _d;
|
|
1370
1422
|
if (options.includeRawChunks) {
|
|
1371
1423
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1372
1424
|
}
|
|
1373
1425
|
if (!chunk.success) {
|
|
1374
1426
|
finishReason = { unified: "error", raw: void 0 };
|
|
1427
|
+
rawFinishReason = void 0;
|
|
1375
1428
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
1376
1429
|
return;
|
|
1377
1430
|
}
|
|
1378
1431
|
const value = chunk.value;
|
|
1379
1432
|
if ("error" in value) {
|
|
1380
1433
|
finishReason = { unified: "error", raw: void 0 };
|
|
1434
|
+
rawFinishReason = void 0;
|
|
1381
1435
|
controller.enqueue({ type: "error", error: value.error });
|
|
1382
1436
|
return;
|
|
1383
1437
|
}
|
|
@@ -1402,19 +1456,35 @@ var OpenAIChatLanguageModel = class {
|
|
|
1402
1456
|
}
|
|
1403
1457
|
const choice = value.choices[0];
|
|
1404
1458
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
1405
|
-
|
|
1406
|
-
unified: mapOpenAIFinishReason(choice.finish_reason),
|
|
1407
|
-
raw: choice.finish_reason
|
|
1408
|
-
};
|
|
1459
|
+
rawFinishReason = choice.finish_reason;
|
|
1409
1460
|
}
|
|
1410
|
-
if ((
|
|
1411
|
-
|
|
1461
|
+
if ((choice == null ? void 0 : choice.logprobs) != null) {
|
|
1462
|
+
const contentLogprobs = choice.logprobs.content;
|
|
1463
|
+
const refusalLogprobs = choice.logprobs.refusal;
|
|
1464
|
+
if (contentLogprobs != null || refusalLogprobs != null) {
|
|
1465
|
+
hasLogprobs = true;
|
|
1466
|
+
streamedLogprobs.push(
|
|
1467
|
+
...contentLogprobs != null ? contentLogprobs : [],
|
|
1468
|
+
...refusalLogprobs != null ? refusalLogprobs : []
|
|
1469
|
+
);
|
|
1470
|
+
}
|
|
1412
1471
|
}
|
|
1413
1472
|
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
1414
1473
|
return;
|
|
1415
1474
|
}
|
|
1416
1475
|
const delta = choice.delta;
|
|
1417
|
-
|
|
1476
|
+
const textDeltas = [];
|
|
1477
|
+
if (delta.content != null && delta.content.length > 0) {
|
|
1478
|
+
textDeltas.push(delta.content);
|
|
1479
|
+
}
|
|
1480
|
+
if (delta.refusal != null && delta.refusal.length > 0) {
|
|
1481
|
+
hasRefusal = true;
|
|
1482
|
+
textDeltas.push(delta.refusal);
|
|
1483
|
+
}
|
|
1484
|
+
if (textDeltas.length === 0 && delta.content === "") {
|
|
1485
|
+
textDeltas.push(delta.content);
|
|
1486
|
+
}
|
|
1487
|
+
for (const textDelta of textDeltas) {
|
|
1418
1488
|
if (!isActiveText) {
|
|
1419
1489
|
controller.enqueue({ type: "text-start", id: "0" });
|
|
1420
1490
|
isActiveText = true;
|
|
@@ -1422,7 +1492,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1422
1492
|
controller.enqueue({
|
|
1423
1493
|
type: "text-delta",
|
|
1424
1494
|
id: "0",
|
|
1425
|
-
delta:
|
|
1495
|
+
delta: textDelta
|
|
1426
1496
|
});
|
|
1427
1497
|
}
|
|
1428
1498
|
if (delta.tool_calls != null) {
|
|
@@ -1447,6 +1517,18 @@ var OpenAIChatLanguageModel = class {
|
|
|
1447
1517
|
controller.enqueue({ type: "text-end", id: "0" });
|
|
1448
1518
|
}
|
|
1449
1519
|
toolCallTracker.flush();
|
|
1520
|
+
if (rawFinishReason != null) {
|
|
1521
|
+
finishReason = {
|
|
1522
|
+
unified: mapOpenAIFinishReason({
|
|
1523
|
+
finishReason: rawFinishReason,
|
|
1524
|
+
hasRefusal
|
|
1525
|
+
}),
|
|
1526
|
+
raw: rawFinishReason
|
|
1527
|
+
};
|
|
1528
|
+
}
|
|
1529
|
+
if (hasLogprobs) {
|
|
1530
|
+
providerMetadata.openai.logprobs = streamedLogprobs;
|
|
1531
|
+
}
|
|
1450
1532
|
controller.enqueue({
|
|
1451
1533
|
type: "finish",
|
|
1452
1534
|
finishReason,
|
|
@@ -1468,7 +1550,7 @@ function isOpenAIChatOutputChunk(chunk) {
|
|
|
1468
1550
|
}
|
|
1469
1551
|
return chunk.choices.some((choice) => {
|
|
1470
1552
|
const delta = choice.delta;
|
|
1471
|
-
return (delta == null ? void 0 : delta.content) != null && delta.content.length > 0 || (delta == null ? void 0 : delta.tool_calls) != null && delta.tool_calls.length > 0 || (delta == null ? void 0 : delta.annotations) != null && delta.annotations.length > 0;
|
|
1553
|
+
return (delta == null ? void 0 : delta.content) != null && delta.content.length > 0 || (delta == null ? void 0 : delta.refusal) != null && delta.refusal.length > 0 || (delta == null ? void 0 : delta.tool_calls) != null && delta.tool_calls.length > 0 || (delta == null ? void 0 : delta.annotations) != null && delta.annotations.length > 0;
|
|
1472
1554
|
});
|
|
1473
1555
|
}
|
|
1474
1556
|
|
|
@@ -2096,6 +2178,9 @@ var OpenAIEmbeddingModel = class {
|
|
|
2096
2178
|
};
|
|
2097
2179
|
|
|
2098
2180
|
// src/image/openai-image-model.ts
|
|
2181
|
+
import {
|
|
2182
|
+
InvalidArgumentError
|
|
2183
|
+
} from "@ai-sdk/provider";
|
|
2099
2184
|
import {
|
|
2100
2185
|
combineHeaders as combineHeaders4,
|
|
2101
2186
|
convertBase64ToUint8Array,
|
|
@@ -2150,6 +2235,8 @@ var modelMaxImagesPerCall = {
|
|
|
2150
2235
|
"gpt-image-1-mini": 10,
|
|
2151
2236
|
"gpt-image-1.5": 10,
|
|
2152
2237
|
"gpt-image-2": 10,
|
|
2238
|
+
"gpt-image-2.6-flare": 10,
|
|
2239
|
+
"gpt-image-2.6-sunburst": 10,
|
|
2153
2240
|
"gpt-image-2.5-flare": 10,
|
|
2154
2241
|
"gpt-image-2.5-flare-2026-09-08": 10,
|
|
2155
2242
|
"gpt-image-2.5-sunburst": 10,
|
|
@@ -2185,6 +2272,11 @@ var baseImageModelOptionsObject = () => z9.object({
|
|
|
2185
2272
|
* Format in which the generated image(s) are returned.
|
|
2186
2273
|
*/
|
|
2187
2274
|
outputFormat: z9.enum(["png", "jpeg", "webp"]).optional(),
|
|
2275
|
+
/**
|
|
2276
|
+
* How much detail the model puts into the image. Supported by GPT Image
|
|
2277
|
+
* 2.6 models. The API defaults to `high`.
|
|
2278
|
+
*/
|
|
2279
|
+
complexity: z9.enum(["low", "medium", "high"]).optional(),
|
|
2188
2280
|
/**
|
|
2189
2281
|
* Compression level (0-100) for the generated image(s). Applies to the
|
|
2190
2282
|
* `jpeg` and `webp` output formats.
|
|
@@ -2194,7 +2286,13 @@ var baseImageModelOptionsObject = () => z9.object({
|
|
|
2194
2286
|
* A unique identifier representing your end-user, which can help OpenAI
|
|
2195
2287
|
* to monitor and detect abuse.
|
|
2196
2288
|
*/
|
|
2197
|
-
user: z9.string().optional()
|
|
2289
|
+
user: z9.string().optional(),
|
|
2290
|
+
/**
|
|
2291
|
+
* A stable identifier used to help detect users of your application that
|
|
2292
|
+
* may be violating OpenAI's usage policies. Should be a hashed username
|
|
2293
|
+
* or email address.
|
|
2294
|
+
*/
|
|
2295
|
+
safetyIdentifier: z9.string().max(128).optional()
|
|
2198
2296
|
});
|
|
2199
2297
|
var openaiImageModelOptions = lazySchema9(
|
|
2200
2298
|
() => zodSchema9(baseImageModelOptionsObject())
|
|
@@ -2208,6 +2306,22 @@ var openaiImageModelGenerationOptions = lazySchema9(
|
|
|
2208
2306
|
* looking images.
|
|
2209
2307
|
*/
|
|
2210
2308
|
style: z9.enum(["vivid", "natural"]).optional(),
|
|
2309
|
+
/**
|
|
2310
|
+
* Format in which the generated image(s) are returned. `gif` produces
|
|
2311
|
+
* an animated GIF and is supported by GPT Image 2.6 models.
|
|
2312
|
+
*/
|
|
2313
|
+
outputFormat: z9.enum(["png", "jpeg", "webp", "gif"]).optional(),
|
|
2314
|
+
/**
|
|
2315
|
+
* Number of frames (2-64) of an animated GIF. Only applies to the `gif`
|
|
2316
|
+
* output format. The API defaults to 9.
|
|
2317
|
+
*/
|
|
2318
|
+
frameCount: z9.number().int().min(2).max(64).optional(),
|
|
2319
|
+
/**
|
|
2320
|
+
* Duration of each frame in milliseconds (20-2000) of an animated GIF.
|
|
2321
|
+
* The API rounds it to the nearest 10 ms. Only applies to the `gif`
|
|
2322
|
+
* output format. The API defaults to 200.
|
|
2323
|
+
*/
|
|
2324
|
+
frameDurationMs: z9.number().int().min(20).max(2e3).optional(),
|
|
2211
2325
|
/**
|
|
2212
2326
|
* Content moderation level for the generated image(s). `low` applies
|
|
2213
2327
|
* less restrictive filtering.
|
|
@@ -2222,7 +2336,14 @@ var openaiImageModelEditOptions = lazySchema9(
|
|
|
2222
2336
|
/**
|
|
2223
2337
|
* Fidelity of the output image(s) to the input image(s).
|
|
2224
2338
|
*/
|
|
2225
|
-
inputFidelity: z9.enum(["high", "low"]).optional()
|
|
2339
|
+
inputFidelity: z9.enum(["high", "low"]).optional(),
|
|
2340
|
+
/**
|
|
2341
|
+
* A transparent PNG overlaid on the first input image to mark up the
|
|
2342
|
+
* regions to change, as an HTTPS URL or a base64 data URL. It must match
|
|
2343
|
+
* the dimensions of the first image. Supported by GPT Image 2.5 and 2.6
|
|
2344
|
+
* models. Cannot be combined with a `mask`.
|
|
2345
|
+
*/
|
|
2346
|
+
markup: z9.string().optional()
|
|
2226
2347
|
})
|
|
2227
2348
|
)
|
|
2228
2349
|
);
|
|
@@ -2271,6 +2392,12 @@ var OpenAIImageModel = class {
|
|
|
2271
2392
|
providerOptions,
|
|
2272
2393
|
schema: openaiImageModelEditOptions
|
|
2273
2394
|
})) != null ? _d : {};
|
|
2395
|
+
if (mask != null && openaiOptions2.markup != null) {
|
|
2396
|
+
throw new InvalidArgumentError({
|
|
2397
|
+
argument: "providerOptions.openai.markup",
|
|
2398
|
+
message: "`markup` cannot be combined with `mask`."
|
|
2399
|
+
});
|
|
2400
|
+
}
|
|
2274
2401
|
const { value: response2, responseHeaders: responseHeaders2 } = await postFormDataToApi({
|
|
2275
2402
|
url: this.config.url({
|
|
2276
2403
|
path: "/images/edits",
|
|
@@ -2295,14 +2422,17 @@ var OpenAIImageModel = class {
|
|
|
2295
2422
|
)
|
|
2296
2423
|
),
|
|
2297
2424
|
mask: mask != null ? await fileToBlob(mask) : void 0,
|
|
2425
|
+
markup: openaiOptions2.markup != null ? await markupToBlob(openaiOptions2.markup) : void 0,
|
|
2298
2426
|
n,
|
|
2299
2427
|
size,
|
|
2300
2428
|
quality: openaiOptions2.quality,
|
|
2301
2429
|
background: openaiOptions2.background,
|
|
2302
2430
|
output_format: openaiOptions2.outputFormat,
|
|
2303
2431
|
output_compression: openaiOptions2.outputCompression,
|
|
2432
|
+
complexity: openaiOptions2.complexity,
|
|
2304
2433
|
input_fidelity: openaiOptions2.inputFidelity,
|
|
2305
|
-
user: openaiOptions2.user
|
|
2434
|
+
user: openaiOptions2.user,
|
|
2435
|
+
safety_identifier: openaiOptions2.safetyIdentifier
|
|
2306
2436
|
}),
|
|
2307
2437
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2308
2438
|
successfulResponseHandler: createJsonResponseHandler4(
|
|
@@ -2368,7 +2498,11 @@ var OpenAIImageModel = class {
|
|
|
2368
2498
|
moderation: openaiOptions.moderation,
|
|
2369
2499
|
output_format: openaiOptions.outputFormat,
|
|
2370
2500
|
output_compression: openaiOptions.outputCompression,
|
|
2501
|
+
complexity: openaiOptions.complexity,
|
|
2502
|
+
frame_count: openaiOptions.frameCount,
|
|
2503
|
+
frame_duration_ms: openaiOptions.frameDurationMs,
|
|
2371
2504
|
user: openaiOptions.user,
|
|
2505
|
+
safety_identifier: openaiOptions.safetyIdentifier,
|
|
2372
2506
|
...!hasDefaultResponseFormat(this.modelId) ? { response_format: "b64_json" } : {}
|
|
2373
2507
|
},
|
|
2374
2508
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
@@ -2431,6 +2565,21 @@ function distributeTokenDetails(details, index, total) {
|
|
|
2431
2565
|
}
|
|
2432
2566
|
return result;
|
|
2433
2567
|
}
|
|
2568
|
+
async function markupToBlob(markup) {
|
|
2569
|
+
const dataUrl = /^data:([^;,]*)(;base64)?,(.*)$/s.exec(markup);
|
|
2570
|
+
if (dataUrl == null) {
|
|
2571
|
+
return downloadBlob(markup);
|
|
2572
|
+
}
|
|
2573
|
+
if (dataUrl[2] == null) {
|
|
2574
|
+
throw new InvalidArgumentError({
|
|
2575
|
+
argument: "providerOptions.openai.markup",
|
|
2576
|
+
message: "`markup` data URLs must be base64 encoded."
|
|
2577
|
+
});
|
|
2578
|
+
}
|
|
2579
|
+
return new Blob([convertBase64ToUint8Array(dataUrl[3])], {
|
|
2580
|
+
type: dataUrl[1] || "image/png"
|
|
2581
|
+
});
|
|
2582
|
+
}
|
|
2434
2583
|
async function fileToBlob(file) {
|
|
2435
2584
|
if (!file) return void 0;
|
|
2436
2585
|
if (file.type === "url") {
|
|
@@ -4644,12 +4793,14 @@ var openaiResponsesReasoningProviderOptionsSchema = lazySchema22(
|
|
|
4644
4793
|
// src/responses/map-openai-responses-finish-reason.ts
|
|
4645
4794
|
function mapOpenAIResponseFinishReason({
|
|
4646
4795
|
finishReason,
|
|
4647
|
-
hasFunctionCall
|
|
4796
|
+
hasFunctionCall,
|
|
4797
|
+
hasRefusal = false
|
|
4648
4798
|
}) {
|
|
4649
4799
|
switch (finishReason) {
|
|
4650
4800
|
case void 0:
|
|
4651
4801
|
case null:
|
|
4652
|
-
|
|
4802
|
+
if (hasFunctionCall) return "tool-calls";
|
|
4803
|
+
return hasRefusal ? "content-filter" : "stop";
|
|
4653
4804
|
case "max_output_tokens":
|
|
4654
4805
|
return "length";
|
|
4655
4806
|
case "content_filter":
|
|
@@ -4759,6 +4910,8 @@ var openaiResponsesModeledChunkTypes = /* @__PURE__ */ new Set([
|
|
|
4759
4910
|
"response.output_item.done",
|
|
4760
4911
|
"response.output_text.annotation.added",
|
|
4761
4912
|
"response.output_text.delta",
|
|
4913
|
+
"response.refusal.delta",
|
|
4914
|
+
"response.refusal.done",
|
|
4762
4915
|
"response.reasoning_summary_part.added",
|
|
4763
4916
|
"response.reasoning_summary_part.done",
|
|
4764
4917
|
"response.reasoning_summary_text.delta"
|
|
@@ -4815,6 +4968,20 @@ var openaiResponsesChunkSchema = lazySchema23(
|
|
|
4815
4968
|
})
|
|
4816
4969
|
).nullish()
|
|
4817
4970
|
}),
|
|
4971
|
+
z23.object({
|
|
4972
|
+
type: z23.literal("response.refusal.delta"),
|
|
4973
|
+
item_id: z23.string(),
|
|
4974
|
+
output_index: z23.number().nullish(),
|
|
4975
|
+
content_index: z23.number().nullish(),
|
|
4976
|
+
delta: z23.string()
|
|
4977
|
+
}),
|
|
4978
|
+
z23.object({
|
|
4979
|
+
type: z23.literal("response.refusal.done"),
|
|
4980
|
+
item_id: z23.string(),
|
|
4981
|
+
output_index: z23.number().nullish(),
|
|
4982
|
+
content_index: z23.number().nullish(),
|
|
4983
|
+
refusal: z23.string()
|
|
4984
|
+
}),
|
|
4818
4985
|
z23.object({
|
|
4819
4986
|
type: z23.enum(["response.completed", "response.incomplete"]),
|
|
4820
4987
|
response: z23.object({
|
|
@@ -5340,53 +5507,60 @@ var openaiResponsesResponseSchema = lazySchema23(
|
|
|
5340
5507
|
role: z23.literal("assistant"),
|
|
5341
5508
|
id: z23.string(),
|
|
5342
5509
|
phase: z23.enum(["commentary", "final_answer"]).nullish(),
|
|
5510
|
+
// the API returns either text or a refusal as content parts:
|
|
5343
5511
|
content: z23.array(
|
|
5344
|
-
z23.
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5348
|
-
z23.
|
|
5349
|
-
token: z23.string(),
|
|
5350
|
-
logprob: z23.number(),
|
|
5351
|
-
top_logprobs: z23.array(
|
|
5352
|
-
z23.object({
|
|
5353
|
-
token: z23.string(),
|
|
5354
|
-
logprob: z23.number()
|
|
5355
|
-
})
|
|
5356
|
-
)
|
|
5357
|
-
})
|
|
5358
|
-
).nullish(),
|
|
5359
|
-
annotations: z23.array(
|
|
5360
|
-
z23.discriminatedUnion("type", [
|
|
5361
|
-
z23.object({
|
|
5362
|
-
type: z23.literal("url_citation"),
|
|
5363
|
-
start_index: z23.number(),
|
|
5364
|
-
end_index: z23.number(),
|
|
5365
|
-
url: z23.string(),
|
|
5366
|
-
title: z23.string()
|
|
5367
|
-
}),
|
|
5368
|
-
z23.object({
|
|
5369
|
-
type: z23.literal("file_citation"),
|
|
5370
|
-
file_id: z23.string(),
|
|
5371
|
-
filename: z23.string(),
|
|
5372
|
-
index: z23.number()
|
|
5373
|
-
}),
|
|
5374
|
-
z23.object({
|
|
5375
|
-
type: z23.literal("container_file_citation"),
|
|
5376
|
-
container_id: z23.string(),
|
|
5377
|
-
file_id: z23.string(),
|
|
5378
|
-
filename: z23.string(),
|
|
5379
|
-
start_index: z23.number(),
|
|
5380
|
-
end_index: z23.number()
|
|
5381
|
-
}),
|
|
5512
|
+
z23.discriminatedUnion("type", [
|
|
5513
|
+
z23.object({
|
|
5514
|
+
type: z23.literal("output_text"),
|
|
5515
|
+
text: z23.string(),
|
|
5516
|
+
logprobs: z23.array(
|
|
5382
5517
|
z23.object({
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5518
|
+
token: z23.string(),
|
|
5519
|
+
logprob: z23.number(),
|
|
5520
|
+
top_logprobs: z23.array(
|
|
5521
|
+
z23.object({
|
|
5522
|
+
token: z23.string(),
|
|
5523
|
+
logprob: z23.number()
|
|
5524
|
+
})
|
|
5525
|
+
)
|
|
5386
5526
|
})
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5527
|
+
).nullish(),
|
|
5528
|
+
annotations: z23.array(
|
|
5529
|
+
z23.discriminatedUnion("type", [
|
|
5530
|
+
z23.object({
|
|
5531
|
+
type: z23.literal("url_citation"),
|
|
5532
|
+
start_index: z23.number(),
|
|
5533
|
+
end_index: z23.number(),
|
|
5534
|
+
url: z23.string(),
|
|
5535
|
+
title: z23.string()
|
|
5536
|
+
}),
|
|
5537
|
+
z23.object({
|
|
5538
|
+
type: z23.literal("file_citation"),
|
|
5539
|
+
file_id: z23.string(),
|
|
5540
|
+
filename: z23.string(),
|
|
5541
|
+
index: z23.number()
|
|
5542
|
+
}),
|
|
5543
|
+
z23.object({
|
|
5544
|
+
type: z23.literal("container_file_citation"),
|
|
5545
|
+
container_id: z23.string(),
|
|
5546
|
+
file_id: z23.string(),
|
|
5547
|
+
filename: z23.string(),
|
|
5548
|
+
start_index: z23.number(),
|
|
5549
|
+
end_index: z23.number()
|
|
5550
|
+
}),
|
|
5551
|
+
z23.object({
|
|
5552
|
+
type: z23.literal("file_path"),
|
|
5553
|
+
file_id: z23.string(),
|
|
5554
|
+
index: z23.number()
|
|
5555
|
+
})
|
|
5556
|
+
])
|
|
5557
|
+
)
|
|
5558
|
+
}),
|
|
5559
|
+
z23.object({
|
|
5560
|
+
type: z23.literal("refusal"),
|
|
5561
|
+
refusal: z23.string()
|
|
5562
|
+
})
|
|
5563
|
+
])
|
|
5390
5564
|
)
|
|
5391
5565
|
}),
|
|
5392
5566
|
z23.object({
|
|
@@ -6523,6 +6697,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6523
6697
|
)) != null ? _b : [];
|
|
6524
6698
|
let hasFunctionCall = false;
|
|
6525
6699
|
const hostedToolSearchCallIds = [];
|
|
6700
|
+
let hasRefusal = false;
|
|
6526
6701
|
for (const part of response.output) {
|
|
6527
6702
|
switch (part.type) {
|
|
6528
6703
|
case "reasoning": {
|
|
@@ -6656,6 +6831,20 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6656
6831
|
}
|
|
6657
6832
|
case "message": {
|
|
6658
6833
|
for (const contentPart of part.content) {
|
|
6834
|
+
if (contentPart.type === "refusal") {
|
|
6835
|
+
hasRefusal = true;
|
|
6836
|
+
content.push({
|
|
6837
|
+
type: "text",
|
|
6838
|
+
text: contentPart.refusal,
|
|
6839
|
+
providerMetadata: {
|
|
6840
|
+
[providerOptionsName]: {
|
|
6841
|
+
itemId: part.id,
|
|
6842
|
+
...part.phase != null && { phase: part.phase }
|
|
6843
|
+
}
|
|
6844
|
+
}
|
|
6845
|
+
});
|
|
6846
|
+
continue;
|
|
6847
|
+
}
|
|
6659
6848
|
if (((_h = (_g = options.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.logprobs) && contentPart.logprobs) {
|
|
6660
6849
|
logprobs.push(contentPart.logprobs);
|
|
6661
6850
|
}
|
|
@@ -6955,7 +7144,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6955
7144
|
finishReason: {
|
|
6956
7145
|
unified: mapOpenAIResponseFinishReason({
|
|
6957
7146
|
finishReason: (_C = response.incomplete_details) == null ? void 0 : _C.reason,
|
|
6958
|
-
hasFunctionCall
|
|
7147
|
+
hasFunctionCall,
|
|
7148
|
+
hasRefusal
|
|
6959
7149
|
}),
|
|
6960
7150
|
raw: (_E = (_D = response.incomplete_details) == null ? void 0 : _D.reason) != null ? _E : void 0
|
|
6961
7151
|
},
|
|
@@ -7026,6 +7216,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7026
7216
|
const ongoingAnnotations = [];
|
|
7027
7217
|
let activeMessagePhase;
|
|
7028
7218
|
let hasFunctionCall = false;
|
|
7219
|
+
let hasRefusal = false;
|
|
7029
7220
|
const activeReasoning = {};
|
|
7030
7221
|
let serviceTier;
|
|
7031
7222
|
let reasoningContext;
|
|
@@ -7799,6 +7990,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7799
7990
|
if (((_u = (_t = options.providerOptions) == null ? void 0 : _t[providerOptionsName]) == null ? void 0 : _u.logprobs) && value.logprobs) {
|
|
7800
7991
|
logprobs.push(value.logprobs);
|
|
7801
7992
|
}
|
|
7993
|
+
} else if (isRefusalDeltaChunk(value)) {
|
|
7994
|
+
hasRefusal = true;
|
|
7995
|
+
controller.enqueue({
|
|
7996
|
+
type: "text-delta",
|
|
7997
|
+
id: value.item_id,
|
|
7998
|
+
delta: value.delta
|
|
7999
|
+
});
|
|
8000
|
+
} else if (isRefusalDoneChunk(value)) {
|
|
8001
|
+
hasRefusal = true;
|
|
7802
8002
|
} else if (value.type === "response.reasoning_summary_part.added") {
|
|
7803
8003
|
if (value.summary_index > 0) {
|
|
7804
8004
|
const activeReasoningPart = activeReasoning[value.item_id];
|
|
@@ -7861,7 +8061,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7861
8061
|
finishReason = {
|
|
7862
8062
|
unified: mapOpenAIResponseFinishReason({
|
|
7863
8063
|
finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
|
|
7864
|
-
hasFunctionCall
|
|
8064
|
+
hasFunctionCall,
|
|
8065
|
+
hasRefusal
|
|
7865
8066
|
}),
|
|
7866
8067
|
raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
|
|
7867
8068
|
};
|
|
@@ -8015,6 +8216,12 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
8015
8216
|
function isTextDeltaChunk(chunk) {
|
|
8016
8217
|
return chunk.type === "response.output_text.delta";
|
|
8017
8218
|
}
|
|
8219
|
+
function isRefusalDeltaChunk(chunk) {
|
|
8220
|
+
return chunk.type === "response.refusal.delta";
|
|
8221
|
+
}
|
|
8222
|
+
function isRefusalDoneChunk(chunk) {
|
|
8223
|
+
return chunk.type === "response.refusal.done";
|
|
8224
|
+
}
|
|
8018
8225
|
function isOpenAIChatCompletionChunk(value) {
|
|
8019
8226
|
const chunk = asRecord2(value);
|
|
8020
8227
|
return chunk != null && Array.isArray(chunk.choices) && typeof chunk.type !== "string";
|
|
@@ -8512,7 +8719,7 @@ var OpenAITranscriptionModel = class {
|
|
|
8512
8719
|
};
|
|
8513
8720
|
|
|
8514
8721
|
// src/version.ts
|
|
8515
|
-
var VERSION = true ? "3.0.
|
|
8722
|
+
var VERSION = true ? "3.0.138" : "0.0.0-test";
|
|
8516
8723
|
|
|
8517
8724
|
// src/openai-provider.ts
|
|
8518
8725
|
function createOpenAI(options = {}) {
|