@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/internal/index.mjs
CHANGED
|
@@ -647,10 +647,13 @@ function getResponseMetadata({
|
|
|
647
647
|
}
|
|
648
648
|
|
|
649
649
|
// src/chat/map-openai-finish-reason.ts
|
|
650
|
-
function mapOpenAIFinishReason(
|
|
650
|
+
function mapOpenAIFinishReason({
|
|
651
|
+
finishReason,
|
|
652
|
+
hasRefusal = false
|
|
653
|
+
}) {
|
|
651
654
|
switch (finishReason) {
|
|
652
655
|
case "stop":
|
|
653
|
-
return "stop";
|
|
656
|
+
return hasRefusal ? "content-filter" : "stop";
|
|
654
657
|
case "length":
|
|
655
658
|
return "length";
|
|
656
659
|
case "content_filter":
|
|
@@ -680,6 +683,8 @@ var openaiChatResponseSchema = lazySchema2(
|
|
|
680
683
|
message: z2.object({
|
|
681
684
|
role: z2.literal("assistant").nullish(),
|
|
682
685
|
content: z2.string().nullish(),
|
|
686
|
+
// set instead of `content` when the model refuses to answer:
|
|
687
|
+
refusal: z2.string().nullish(),
|
|
683
688
|
audio: z2.object({
|
|
684
689
|
transcript: z2.string().nullish()
|
|
685
690
|
}).nullish(),
|
|
@@ -718,6 +723,20 @@ var openaiChatResponseSchema = lazySchema2(
|
|
|
718
723
|
})
|
|
719
724
|
)
|
|
720
725
|
})
|
|
726
|
+
).nullish(),
|
|
727
|
+
// logprobs of the refusal tokens (set instead of `content` when
|
|
728
|
+
// the model refuses to answer):
|
|
729
|
+
refusal: z2.array(
|
|
730
|
+
z2.object({
|
|
731
|
+
token: z2.string(),
|
|
732
|
+
logprob: z2.number(),
|
|
733
|
+
top_logprobs: z2.array(
|
|
734
|
+
z2.object({
|
|
735
|
+
token: z2.string(),
|
|
736
|
+
logprob: z2.number()
|
|
737
|
+
})
|
|
738
|
+
)
|
|
739
|
+
})
|
|
721
740
|
).nullish()
|
|
722
741
|
}).nullish(),
|
|
723
742
|
finish_reason: z2.string().nullish()
|
|
@@ -752,6 +771,8 @@ var openaiChatChunkSchema = lazySchema2(
|
|
|
752
771
|
delta: z2.object({
|
|
753
772
|
role: z2.enum(["assistant"]).nullish(),
|
|
754
773
|
content: z2.string().nullish(),
|
|
774
|
+
// set instead of `content` when the model refuses to answer:
|
|
775
|
+
refusal: z2.string().nullish(),
|
|
755
776
|
tool_calls: z2.array(
|
|
756
777
|
z2.object({
|
|
757
778
|
index: z2.number(),
|
|
@@ -787,6 +808,20 @@ var openaiChatChunkSchema = lazySchema2(
|
|
|
787
808
|
})
|
|
788
809
|
)
|
|
789
810
|
})
|
|
811
|
+
).nullish(),
|
|
812
|
+
// logprobs of the refusal tokens (set instead of `content` when
|
|
813
|
+
// the model refuses to answer):
|
|
814
|
+
refusal: z2.array(
|
|
815
|
+
z2.object({
|
|
816
|
+
token: z2.string(),
|
|
817
|
+
logprob: z2.number(),
|
|
818
|
+
top_logprobs: z2.array(
|
|
819
|
+
z2.object({
|
|
820
|
+
token: z2.string(),
|
|
821
|
+
logprob: z2.number()
|
|
822
|
+
})
|
|
823
|
+
)
|
|
824
|
+
})
|
|
790
825
|
).nullish()
|
|
791
826
|
}).nullish(),
|
|
792
827
|
finish_reason: z2.string().nullish(),
|
|
@@ -1228,7 +1263,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1228
1263
|
};
|
|
1229
1264
|
}
|
|
1230
1265
|
async doGenerate(options) {
|
|
1231
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h;
|
|
1266
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1232
1267
|
const { args: body, warnings } = await this.getArgs(options);
|
|
1233
1268
|
const {
|
|
1234
1269
|
responseHeaders,
|
|
@@ -1260,6 +1295,11 @@ var OpenAIChatLanguageModel = class {
|
|
|
1260
1295
|
if (text != null && text.length > 0) {
|
|
1261
1296
|
content.push({ type: "text", text });
|
|
1262
1297
|
}
|
|
1298
|
+
const refusal = choice.message.refusal;
|
|
1299
|
+
const hasRefusal = refusal != null && refusal.length > 0;
|
|
1300
|
+
if (hasRefusal) {
|
|
1301
|
+
content.push({ type: "text", text: refusal });
|
|
1302
|
+
}
|
|
1263
1303
|
for (const toolCall of (_b = choice.message.tool_calls) != null ? _b : []) {
|
|
1264
1304
|
content.push({
|
|
1265
1305
|
type: "tool-call",
|
|
@@ -1286,14 +1326,22 @@ var OpenAIChatLanguageModel = class {
|
|
|
1286
1326
|
if ((completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens) != null) {
|
|
1287
1327
|
providerMetadata.openai.rejectedPredictionTokens = completionTokenDetails == null ? void 0 : completionTokenDetails.rejected_prediction_tokens;
|
|
1288
1328
|
}
|
|
1289
|
-
|
|
1290
|
-
|
|
1329
|
+
const contentLogprobs = (_g = choice.logprobs) == null ? void 0 : _g.content;
|
|
1330
|
+
const refusalLogprobs = (_h = choice.logprobs) == null ? void 0 : _h.refusal;
|
|
1331
|
+
if (contentLogprobs != null || refusalLogprobs != null) {
|
|
1332
|
+
providerMetadata.openai.logprobs = [
|
|
1333
|
+
...contentLogprobs != null ? contentLogprobs : [],
|
|
1334
|
+
...refusalLogprobs != null ? refusalLogprobs : []
|
|
1335
|
+
];
|
|
1291
1336
|
}
|
|
1292
1337
|
return {
|
|
1293
1338
|
content,
|
|
1294
1339
|
finishReason: {
|
|
1295
|
-
unified: mapOpenAIFinishReason(
|
|
1296
|
-
|
|
1340
|
+
unified: mapOpenAIFinishReason({
|
|
1341
|
+
finishReason: choice.finish_reason,
|
|
1342
|
+
hasRefusal
|
|
1343
|
+
}),
|
|
1344
|
+
raw: (_i = choice.finish_reason) != null ? _i : void 0
|
|
1297
1345
|
},
|
|
1298
1346
|
usage: convertOpenAIChatUsage(response.usage),
|
|
1299
1347
|
request: { body },
|
|
@@ -1346,6 +1394,10 @@ var OpenAIChatLanguageModel = class {
|
|
|
1346
1394
|
let usage = void 0;
|
|
1347
1395
|
let metadataExtracted = false;
|
|
1348
1396
|
let isActiveText = false;
|
|
1397
|
+
let hasRefusal = false;
|
|
1398
|
+
let rawFinishReason = void 0;
|
|
1399
|
+
let hasLogprobs = false;
|
|
1400
|
+
const streamedLogprobs = [];
|
|
1349
1401
|
const providerMetadata = { openai: {} };
|
|
1350
1402
|
const result = {
|
|
1351
1403
|
stream: checkedResponse.pipeThrough(
|
|
@@ -1358,18 +1410,20 @@ var OpenAIChatLanguageModel = class {
|
|
|
1358
1410
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1359
1411
|
},
|
|
1360
1412
|
transform(chunk, controller) {
|
|
1361
|
-
var _a2, _b, _c, _d
|
|
1413
|
+
var _a2, _b, _c, _d;
|
|
1362
1414
|
if (options.includeRawChunks) {
|
|
1363
1415
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1364
1416
|
}
|
|
1365
1417
|
if (!chunk.success) {
|
|
1366
1418
|
finishReason = { unified: "error", raw: void 0 };
|
|
1419
|
+
rawFinishReason = void 0;
|
|
1367
1420
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
1368
1421
|
return;
|
|
1369
1422
|
}
|
|
1370
1423
|
const value = chunk.value;
|
|
1371
1424
|
if ("error" in value) {
|
|
1372
1425
|
finishReason = { unified: "error", raw: void 0 };
|
|
1426
|
+
rawFinishReason = void 0;
|
|
1373
1427
|
controller.enqueue({ type: "error", error: value.error });
|
|
1374
1428
|
return;
|
|
1375
1429
|
}
|
|
@@ -1394,19 +1448,35 @@ var OpenAIChatLanguageModel = class {
|
|
|
1394
1448
|
}
|
|
1395
1449
|
const choice = value.choices[0];
|
|
1396
1450
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
1397
|
-
|
|
1398
|
-
unified: mapOpenAIFinishReason(choice.finish_reason),
|
|
1399
|
-
raw: choice.finish_reason
|
|
1400
|
-
};
|
|
1451
|
+
rawFinishReason = choice.finish_reason;
|
|
1401
1452
|
}
|
|
1402
|
-
if ((
|
|
1403
|
-
|
|
1453
|
+
if ((choice == null ? void 0 : choice.logprobs) != null) {
|
|
1454
|
+
const contentLogprobs = choice.logprobs.content;
|
|
1455
|
+
const refusalLogprobs = choice.logprobs.refusal;
|
|
1456
|
+
if (contentLogprobs != null || refusalLogprobs != null) {
|
|
1457
|
+
hasLogprobs = true;
|
|
1458
|
+
streamedLogprobs.push(
|
|
1459
|
+
...contentLogprobs != null ? contentLogprobs : [],
|
|
1460
|
+
...refusalLogprobs != null ? refusalLogprobs : []
|
|
1461
|
+
);
|
|
1462
|
+
}
|
|
1404
1463
|
}
|
|
1405
1464
|
if ((choice == null ? void 0 : choice.delta) == null) {
|
|
1406
1465
|
return;
|
|
1407
1466
|
}
|
|
1408
1467
|
const delta = choice.delta;
|
|
1409
|
-
|
|
1468
|
+
const textDeltas = [];
|
|
1469
|
+
if (delta.content != null && delta.content.length > 0) {
|
|
1470
|
+
textDeltas.push(delta.content);
|
|
1471
|
+
}
|
|
1472
|
+
if (delta.refusal != null && delta.refusal.length > 0) {
|
|
1473
|
+
hasRefusal = true;
|
|
1474
|
+
textDeltas.push(delta.refusal);
|
|
1475
|
+
}
|
|
1476
|
+
if (textDeltas.length === 0 && delta.content === "") {
|
|
1477
|
+
textDeltas.push(delta.content);
|
|
1478
|
+
}
|
|
1479
|
+
for (const textDelta of textDeltas) {
|
|
1410
1480
|
if (!isActiveText) {
|
|
1411
1481
|
controller.enqueue({ type: "text-start", id: "0" });
|
|
1412
1482
|
isActiveText = true;
|
|
@@ -1414,7 +1484,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
1414
1484
|
controller.enqueue({
|
|
1415
1485
|
type: "text-delta",
|
|
1416
1486
|
id: "0",
|
|
1417
|
-
delta:
|
|
1487
|
+
delta: textDelta
|
|
1418
1488
|
});
|
|
1419
1489
|
}
|
|
1420
1490
|
if (delta.tool_calls != null) {
|
|
@@ -1439,6 +1509,18 @@ var OpenAIChatLanguageModel = class {
|
|
|
1439
1509
|
controller.enqueue({ type: "text-end", id: "0" });
|
|
1440
1510
|
}
|
|
1441
1511
|
toolCallTracker.flush();
|
|
1512
|
+
if (rawFinishReason != null) {
|
|
1513
|
+
finishReason = {
|
|
1514
|
+
unified: mapOpenAIFinishReason({
|
|
1515
|
+
finishReason: rawFinishReason,
|
|
1516
|
+
hasRefusal
|
|
1517
|
+
}),
|
|
1518
|
+
raw: rawFinishReason
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
if (hasLogprobs) {
|
|
1522
|
+
providerMetadata.openai.logprobs = streamedLogprobs;
|
|
1523
|
+
}
|
|
1442
1524
|
controller.enqueue({
|
|
1443
1525
|
type: "finish",
|
|
1444
1526
|
finishReason,
|
|
@@ -1460,7 +1542,7 @@ function isOpenAIChatOutputChunk(chunk) {
|
|
|
1460
1542
|
}
|
|
1461
1543
|
return chunk.choices.some((choice) => {
|
|
1462
1544
|
const delta = choice.delta;
|
|
1463
|
-
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;
|
|
1545
|
+
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;
|
|
1464
1546
|
});
|
|
1465
1547
|
}
|
|
1466
1548
|
|
|
@@ -2088,6 +2170,9 @@ var OpenAIEmbeddingModel = class {
|
|
|
2088
2170
|
};
|
|
2089
2171
|
|
|
2090
2172
|
// src/image/openai-image-model.ts
|
|
2173
|
+
import {
|
|
2174
|
+
InvalidArgumentError
|
|
2175
|
+
} from "@ai-sdk/provider";
|
|
2091
2176
|
import {
|
|
2092
2177
|
combineHeaders as combineHeaders4,
|
|
2093
2178
|
convertBase64ToUint8Array,
|
|
@@ -2142,6 +2227,8 @@ var modelMaxImagesPerCall = {
|
|
|
2142
2227
|
"gpt-image-1-mini": 10,
|
|
2143
2228
|
"gpt-image-1.5": 10,
|
|
2144
2229
|
"gpt-image-2": 10,
|
|
2230
|
+
"gpt-image-2.6-flare": 10,
|
|
2231
|
+
"gpt-image-2.6-sunburst": 10,
|
|
2145
2232
|
"gpt-image-2.5-flare": 10,
|
|
2146
2233
|
"gpt-image-2.5-flare-2026-09-08": 10,
|
|
2147
2234
|
"gpt-image-2.5-sunburst": 10,
|
|
@@ -2177,6 +2264,11 @@ var baseImageModelOptionsObject = () => z9.object({
|
|
|
2177
2264
|
* Format in which the generated image(s) are returned.
|
|
2178
2265
|
*/
|
|
2179
2266
|
outputFormat: z9.enum(["png", "jpeg", "webp"]).optional(),
|
|
2267
|
+
/**
|
|
2268
|
+
* How much detail the model puts into the image. Supported by GPT Image
|
|
2269
|
+
* 2.6 models. The API defaults to `high`.
|
|
2270
|
+
*/
|
|
2271
|
+
complexity: z9.enum(["low", "medium", "high"]).optional(),
|
|
2180
2272
|
/**
|
|
2181
2273
|
* Compression level (0-100) for the generated image(s). Applies to the
|
|
2182
2274
|
* `jpeg` and `webp` output formats.
|
|
@@ -2186,7 +2278,13 @@ var baseImageModelOptionsObject = () => z9.object({
|
|
|
2186
2278
|
* A unique identifier representing your end-user, which can help OpenAI
|
|
2187
2279
|
* to monitor and detect abuse.
|
|
2188
2280
|
*/
|
|
2189
|
-
user: z9.string().optional()
|
|
2281
|
+
user: z9.string().optional(),
|
|
2282
|
+
/**
|
|
2283
|
+
* A stable identifier used to help detect users of your application that
|
|
2284
|
+
* may be violating OpenAI's usage policies. Should be a hashed username
|
|
2285
|
+
* or email address.
|
|
2286
|
+
*/
|
|
2287
|
+
safetyIdentifier: z9.string().max(128).optional()
|
|
2190
2288
|
});
|
|
2191
2289
|
var openaiImageModelOptions = lazySchema9(
|
|
2192
2290
|
() => zodSchema9(baseImageModelOptionsObject())
|
|
@@ -2200,6 +2298,22 @@ var openaiImageModelGenerationOptions = lazySchema9(
|
|
|
2200
2298
|
* looking images.
|
|
2201
2299
|
*/
|
|
2202
2300
|
style: z9.enum(["vivid", "natural"]).optional(),
|
|
2301
|
+
/**
|
|
2302
|
+
* Format in which the generated image(s) are returned. `gif` produces
|
|
2303
|
+
* an animated GIF and is supported by GPT Image 2.6 models.
|
|
2304
|
+
*/
|
|
2305
|
+
outputFormat: z9.enum(["png", "jpeg", "webp", "gif"]).optional(),
|
|
2306
|
+
/**
|
|
2307
|
+
* Number of frames (2-64) of an animated GIF. Only applies to the `gif`
|
|
2308
|
+
* output format. The API defaults to 9.
|
|
2309
|
+
*/
|
|
2310
|
+
frameCount: z9.number().int().min(2).max(64).optional(),
|
|
2311
|
+
/**
|
|
2312
|
+
* Duration of each frame in milliseconds (20-2000) of an animated GIF.
|
|
2313
|
+
* The API rounds it to the nearest 10 ms. Only applies to the `gif`
|
|
2314
|
+
* output format. The API defaults to 200.
|
|
2315
|
+
*/
|
|
2316
|
+
frameDurationMs: z9.number().int().min(20).max(2e3).optional(),
|
|
2203
2317
|
/**
|
|
2204
2318
|
* Content moderation level for the generated image(s). `low` applies
|
|
2205
2319
|
* less restrictive filtering.
|
|
@@ -2214,7 +2328,14 @@ var openaiImageModelEditOptions = lazySchema9(
|
|
|
2214
2328
|
/**
|
|
2215
2329
|
* Fidelity of the output image(s) to the input image(s).
|
|
2216
2330
|
*/
|
|
2217
|
-
inputFidelity: z9.enum(["high", "low"]).optional()
|
|
2331
|
+
inputFidelity: z9.enum(["high", "low"]).optional(),
|
|
2332
|
+
/**
|
|
2333
|
+
* A transparent PNG overlaid on the first input image to mark up the
|
|
2334
|
+
* regions to change, as an HTTPS URL or a base64 data URL. It must match
|
|
2335
|
+
* the dimensions of the first image. Supported by GPT Image 2.5 and 2.6
|
|
2336
|
+
* models. Cannot be combined with a `mask`.
|
|
2337
|
+
*/
|
|
2338
|
+
markup: z9.string().optional()
|
|
2218
2339
|
})
|
|
2219
2340
|
)
|
|
2220
2341
|
);
|
|
@@ -2263,6 +2384,12 @@ var OpenAIImageModel = class {
|
|
|
2263
2384
|
providerOptions,
|
|
2264
2385
|
schema: openaiImageModelEditOptions
|
|
2265
2386
|
})) != null ? _d : {};
|
|
2387
|
+
if (mask != null && openaiOptions2.markup != null) {
|
|
2388
|
+
throw new InvalidArgumentError({
|
|
2389
|
+
argument: "providerOptions.openai.markup",
|
|
2390
|
+
message: "`markup` cannot be combined with `mask`."
|
|
2391
|
+
});
|
|
2392
|
+
}
|
|
2266
2393
|
const { value: response2, responseHeaders: responseHeaders2 } = await postFormDataToApi({
|
|
2267
2394
|
url: this.config.url({
|
|
2268
2395
|
path: "/images/edits",
|
|
@@ -2287,14 +2414,17 @@ var OpenAIImageModel = class {
|
|
|
2287
2414
|
)
|
|
2288
2415
|
),
|
|
2289
2416
|
mask: mask != null ? await fileToBlob(mask) : void 0,
|
|
2417
|
+
markup: openaiOptions2.markup != null ? await markupToBlob(openaiOptions2.markup) : void 0,
|
|
2290
2418
|
n,
|
|
2291
2419
|
size,
|
|
2292
2420
|
quality: openaiOptions2.quality,
|
|
2293
2421
|
background: openaiOptions2.background,
|
|
2294
2422
|
output_format: openaiOptions2.outputFormat,
|
|
2295
2423
|
output_compression: openaiOptions2.outputCompression,
|
|
2424
|
+
complexity: openaiOptions2.complexity,
|
|
2296
2425
|
input_fidelity: openaiOptions2.inputFidelity,
|
|
2297
|
-
user: openaiOptions2.user
|
|
2426
|
+
user: openaiOptions2.user,
|
|
2427
|
+
safety_identifier: openaiOptions2.safetyIdentifier
|
|
2298
2428
|
}),
|
|
2299
2429
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
2300
2430
|
successfulResponseHandler: createJsonResponseHandler4(
|
|
@@ -2360,7 +2490,11 @@ var OpenAIImageModel = class {
|
|
|
2360
2490
|
moderation: openaiOptions.moderation,
|
|
2361
2491
|
output_format: openaiOptions.outputFormat,
|
|
2362
2492
|
output_compression: openaiOptions.outputCompression,
|
|
2493
|
+
complexity: openaiOptions.complexity,
|
|
2494
|
+
frame_count: openaiOptions.frameCount,
|
|
2495
|
+
frame_duration_ms: openaiOptions.frameDurationMs,
|
|
2363
2496
|
user: openaiOptions.user,
|
|
2497
|
+
safety_identifier: openaiOptions.safetyIdentifier,
|
|
2364
2498
|
...!hasDefaultResponseFormat(this.modelId) ? { response_format: "b64_json" } : {}
|
|
2365
2499
|
},
|
|
2366
2500
|
failedResponseHandler: openaiFailedResponseHandler,
|
|
@@ -2423,6 +2557,21 @@ function distributeTokenDetails(details, index, total) {
|
|
|
2423
2557
|
}
|
|
2424
2558
|
return result;
|
|
2425
2559
|
}
|
|
2560
|
+
async function markupToBlob(markup) {
|
|
2561
|
+
const dataUrl = /^data:([^;,]*)(;base64)?,(.*)$/s.exec(markup);
|
|
2562
|
+
if (dataUrl == null) {
|
|
2563
|
+
return downloadBlob(markup);
|
|
2564
|
+
}
|
|
2565
|
+
if (dataUrl[2] == null) {
|
|
2566
|
+
throw new InvalidArgumentError({
|
|
2567
|
+
argument: "providerOptions.openai.markup",
|
|
2568
|
+
message: "`markup` data URLs must be base64 encoded."
|
|
2569
|
+
});
|
|
2570
|
+
}
|
|
2571
|
+
return new Blob([convertBase64ToUint8Array(dataUrl[3])], {
|
|
2572
|
+
type: dataUrl[1] || "image/png"
|
|
2573
|
+
});
|
|
2574
|
+
}
|
|
2426
2575
|
async function fileToBlob(file) {
|
|
2427
2576
|
if (!file) return void 0;
|
|
2428
2577
|
if (file.type === "url") {
|
|
@@ -4612,12 +4761,14 @@ var openaiResponsesReasoningProviderOptionsSchema = lazySchema19(
|
|
|
4612
4761
|
// src/responses/map-openai-responses-finish-reason.ts
|
|
4613
4762
|
function mapOpenAIResponseFinishReason({
|
|
4614
4763
|
finishReason,
|
|
4615
|
-
hasFunctionCall
|
|
4764
|
+
hasFunctionCall,
|
|
4765
|
+
hasRefusal = false
|
|
4616
4766
|
}) {
|
|
4617
4767
|
switch (finishReason) {
|
|
4618
4768
|
case void 0:
|
|
4619
4769
|
case null:
|
|
4620
|
-
|
|
4770
|
+
if (hasFunctionCall) return "tool-calls";
|
|
4771
|
+
return hasRefusal ? "content-filter" : "stop";
|
|
4621
4772
|
case "max_output_tokens":
|
|
4622
4773
|
return "length";
|
|
4623
4774
|
case "content_filter":
|
|
@@ -4727,6 +4878,8 @@ var openaiResponsesModeledChunkTypes = /* @__PURE__ */ new Set([
|
|
|
4727
4878
|
"response.output_item.done",
|
|
4728
4879
|
"response.output_text.annotation.added",
|
|
4729
4880
|
"response.output_text.delta",
|
|
4881
|
+
"response.refusal.delta",
|
|
4882
|
+
"response.refusal.done",
|
|
4730
4883
|
"response.reasoning_summary_part.added",
|
|
4731
4884
|
"response.reasoning_summary_part.done",
|
|
4732
4885
|
"response.reasoning_summary_text.delta"
|
|
@@ -4783,6 +4936,20 @@ var openaiResponsesChunkSchema = lazySchema20(
|
|
|
4783
4936
|
})
|
|
4784
4937
|
).nullish()
|
|
4785
4938
|
}),
|
|
4939
|
+
z20.object({
|
|
4940
|
+
type: z20.literal("response.refusal.delta"),
|
|
4941
|
+
item_id: z20.string(),
|
|
4942
|
+
output_index: z20.number().nullish(),
|
|
4943
|
+
content_index: z20.number().nullish(),
|
|
4944
|
+
delta: z20.string()
|
|
4945
|
+
}),
|
|
4946
|
+
z20.object({
|
|
4947
|
+
type: z20.literal("response.refusal.done"),
|
|
4948
|
+
item_id: z20.string(),
|
|
4949
|
+
output_index: z20.number().nullish(),
|
|
4950
|
+
content_index: z20.number().nullish(),
|
|
4951
|
+
refusal: z20.string()
|
|
4952
|
+
}),
|
|
4786
4953
|
z20.object({
|
|
4787
4954
|
type: z20.enum(["response.completed", "response.incomplete"]),
|
|
4788
4955
|
response: z20.object({
|
|
@@ -5308,53 +5475,60 @@ var openaiResponsesResponseSchema = lazySchema20(
|
|
|
5308
5475
|
role: z20.literal("assistant"),
|
|
5309
5476
|
id: z20.string(),
|
|
5310
5477
|
phase: z20.enum(["commentary", "final_answer"]).nullish(),
|
|
5478
|
+
// the API returns either text or a refusal as content parts:
|
|
5311
5479
|
content: z20.array(
|
|
5312
|
-
z20.
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
z20.
|
|
5317
|
-
token: z20.string(),
|
|
5318
|
-
logprob: z20.number(),
|
|
5319
|
-
top_logprobs: z20.array(
|
|
5320
|
-
z20.object({
|
|
5321
|
-
token: z20.string(),
|
|
5322
|
-
logprob: z20.number()
|
|
5323
|
-
})
|
|
5324
|
-
)
|
|
5325
|
-
})
|
|
5326
|
-
).nullish(),
|
|
5327
|
-
annotations: z20.array(
|
|
5328
|
-
z20.discriminatedUnion("type", [
|
|
5329
|
-
z20.object({
|
|
5330
|
-
type: z20.literal("url_citation"),
|
|
5331
|
-
start_index: z20.number(),
|
|
5332
|
-
end_index: z20.number(),
|
|
5333
|
-
url: z20.string(),
|
|
5334
|
-
title: z20.string()
|
|
5335
|
-
}),
|
|
5336
|
-
z20.object({
|
|
5337
|
-
type: z20.literal("file_citation"),
|
|
5338
|
-
file_id: z20.string(),
|
|
5339
|
-
filename: z20.string(),
|
|
5340
|
-
index: z20.number()
|
|
5341
|
-
}),
|
|
5342
|
-
z20.object({
|
|
5343
|
-
type: z20.literal("container_file_citation"),
|
|
5344
|
-
container_id: z20.string(),
|
|
5345
|
-
file_id: z20.string(),
|
|
5346
|
-
filename: z20.string(),
|
|
5347
|
-
start_index: z20.number(),
|
|
5348
|
-
end_index: z20.number()
|
|
5349
|
-
}),
|
|
5480
|
+
z20.discriminatedUnion("type", [
|
|
5481
|
+
z20.object({
|
|
5482
|
+
type: z20.literal("output_text"),
|
|
5483
|
+
text: z20.string(),
|
|
5484
|
+
logprobs: z20.array(
|
|
5350
5485
|
z20.object({
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5486
|
+
token: z20.string(),
|
|
5487
|
+
logprob: z20.number(),
|
|
5488
|
+
top_logprobs: z20.array(
|
|
5489
|
+
z20.object({
|
|
5490
|
+
token: z20.string(),
|
|
5491
|
+
logprob: z20.number()
|
|
5492
|
+
})
|
|
5493
|
+
)
|
|
5354
5494
|
})
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5495
|
+
).nullish(),
|
|
5496
|
+
annotations: z20.array(
|
|
5497
|
+
z20.discriminatedUnion("type", [
|
|
5498
|
+
z20.object({
|
|
5499
|
+
type: z20.literal("url_citation"),
|
|
5500
|
+
start_index: z20.number(),
|
|
5501
|
+
end_index: z20.number(),
|
|
5502
|
+
url: z20.string(),
|
|
5503
|
+
title: z20.string()
|
|
5504
|
+
}),
|
|
5505
|
+
z20.object({
|
|
5506
|
+
type: z20.literal("file_citation"),
|
|
5507
|
+
file_id: z20.string(),
|
|
5508
|
+
filename: z20.string(),
|
|
5509
|
+
index: z20.number()
|
|
5510
|
+
}),
|
|
5511
|
+
z20.object({
|
|
5512
|
+
type: z20.literal("container_file_citation"),
|
|
5513
|
+
container_id: z20.string(),
|
|
5514
|
+
file_id: z20.string(),
|
|
5515
|
+
filename: z20.string(),
|
|
5516
|
+
start_index: z20.number(),
|
|
5517
|
+
end_index: z20.number()
|
|
5518
|
+
}),
|
|
5519
|
+
z20.object({
|
|
5520
|
+
type: z20.literal("file_path"),
|
|
5521
|
+
file_id: z20.string(),
|
|
5522
|
+
index: z20.number()
|
|
5523
|
+
})
|
|
5524
|
+
])
|
|
5525
|
+
)
|
|
5526
|
+
}),
|
|
5527
|
+
z20.object({
|
|
5528
|
+
type: z20.literal("refusal"),
|
|
5529
|
+
refusal: z20.string()
|
|
5530
|
+
})
|
|
5531
|
+
])
|
|
5358
5532
|
)
|
|
5359
5533
|
}),
|
|
5360
5534
|
z20.object({
|
|
@@ -6784,6 +6958,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6784
6958
|
)) != null ? _b : [];
|
|
6785
6959
|
let hasFunctionCall = false;
|
|
6786
6960
|
const hostedToolSearchCallIds = [];
|
|
6961
|
+
let hasRefusal = false;
|
|
6787
6962
|
for (const part of response.output) {
|
|
6788
6963
|
switch (part.type) {
|
|
6789
6964
|
case "reasoning": {
|
|
@@ -6917,6 +7092,20 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
6917
7092
|
}
|
|
6918
7093
|
case "message": {
|
|
6919
7094
|
for (const contentPart of part.content) {
|
|
7095
|
+
if (contentPart.type === "refusal") {
|
|
7096
|
+
hasRefusal = true;
|
|
7097
|
+
content.push({
|
|
7098
|
+
type: "text",
|
|
7099
|
+
text: contentPart.refusal,
|
|
7100
|
+
providerMetadata: {
|
|
7101
|
+
[providerOptionsName]: {
|
|
7102
|
+
itemId: part.id,
|
|
7103
|
+
...part.phase != null && { phase: part.phase }
|
|
7104
|
+
}
|
|
7105
|
+
}
|
|
7106
|
+
});
|
|
7107
|
+
continue;
|
|
7108
|
+
}
|
|
6920
7109
|
if (((_h = (_g = options.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.logprobs) && contentPart.logprobs) {
|
|
6921
7110
|
logprobs.push(contentPart.logprobs);
|
|
6922
7111
|
}
|
|
@@ -7216,7 +7405,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7216
7405
|
finishReason: {
|
|
7217
7406
|
unified: mapOpenAIResponseFinishReason({
|
|
7218
7407
|
finishReason: (_C = response.incomplete_details) == null ? void 0 : _C.reason,
|
|
7219
|
-
hasFunctionCall
|
|
7408
|
+
hasFunctionCall,
|
|
7409
|
+
hasRefusal
|
|
7220
7410
|
}),
|
|
7221
7411
|
raw: (_E = (_D = response.incomplete_details) == null ? void 0 : _D.reason) != null ? _E : void 0
|
|
7222
7412
|
},
|
|
@@ -7287,6 +7477,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
7287
7477
|
const ongoingAnnotations = [];
|
|
7288
7478
|
let activeMessagePhase;
|
|
7289
7479
|
let hasFunctionCall = false;
|
|
7480
|
+
let hasRefusal = false;
|
|
7290
7481
|
const activeReasoning = {};
|
|
7291
7482
|
let serviceTier;
|
|
7292
7483
|
let reasoningContext;
|
|
@@ -8060,6 +8251,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
8060
8251
|
if (((_u = (_t = options.providerOptions) == null ? void 0 : _t[providerOptionsName]) == null ? void 0 : _u.logprobs) && value.logprobs) {
|
|
8061
8252
|
logprobs.push(value.logprobs);
|
|
8062
8253
|
}
|
|
8254
|
+
} else if (isRefusalDeltaChunk(value)) {
|
|
8255
|
+
hasRefusal = true;
|
|
8256
|
+
controller.enqueue({
|
|
8257
|
+
type: "text-delta",
|
|
8258
|
+
id: value.item_id,
|
|
8259
|
+
delta: value.delta
|
|
8260
|
+
});
|
|
8261
|
+
} else if (isRefusalDoneChunk(value)) {
|
|
8262
|
+
hasRefusal = true;
|
|
8063
8263
|
} else if (value.type === "response.reasoning_summary_part.added") {
|
|
8064
8264
|
if (value.summary_index > 0) {
|
|
8065
8265
|
const activeReasoningPart = activeReasoning[value.item_id];
|
|
@@ -8122,7 +8322,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
8122
8322
|
finishReason = {
|
|
8123
8323
|
unified: mapOpenAIResponseFinishReason({
|
|
8124
8324
|
finishReason: (_x = value.response.incomplete_details) == null ? void 0 : _x.reason,
|
|
8125
|
-
hasFunctionCall
|
|
8325
|
+
hasFunctionCall,
|
|
8326
|
+
hasRefusal
|
|
8126
8327
|
}),
|
|
8127
8328
|
raw: (_z = (_y = value.response.incomplete_details) == null ? void 0 : _y.reason) != null ? _z : void 0
|
|
8128
8329
|
};
|
|
@@ -8276,6 +8477,12 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
8276
8477
|
function isTextDeltaChunk(chunk) {
|
|
8277
8478
|
return chunk.type === "response.output_text.delta";
|
|
8278
8479
|
}
|
|
8480
|
+
function isRefusalDeltaChunk(chunk) {
|
|
8481
|
+
return chunk.type === "response.refusal.delta";
|
|
8482
|
+
}
|
|
8483
|
+
function isRefusalDoneChunk(chunk) {
|
|
8484
|
+
return chunk.type === "response.refusal.done";
|
|
8485
|
+
}
|
|
8279
8486
|
function isOpenAIChatCompletionChunk(value) {
|
|
8280
8487
|
const chunk = asRecord2(value);
|
|
8281
8488
|
return chunk != null && Array.isArray(chunk.choices) && typeof chunk.type !== "string";
|