@ai-sdk/openai 2.0.0-alpha.10 → 2.0.0-alpha.12
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 +19 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +61 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -2
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +12 -0
- package/dist/internal/index.d.ts +12 -0
- package/dist/internal/index.js +61 -2
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +61 -2
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -270,7 +270,14 @@ var openaiProviderOptions = z.object({
|
|
|
270
270
|
*
|
|
271
271
|
* @default true
|
|
272
272
|
*/
|
|
273
|
-
structuredOutputs: z.boolean().optional()
|
|
273
|
+
structuredOutputs: z.boolean().optional(),
|
|
274
|
+
/**
|
|
275
|
+
* Service tier for the request. Set to 'flex' for 50% cheaper processing
|
|
276
|
+
* at the cost of increased latency. Only available for o3 and o4-mini models.
|
|
277
|
+
*
|
|
278
|
+
* @default 'auto'
|
|
279
|
+
*/
|
|
280
|
+
serviceTier: z.enum(["auto", "flex"]).optional()
|
|
274
281
|
});
|
|
275
282
|
|
|
276
283
|
// src/openai-error.ts
|
|
@@ -443,6 +450,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
443
450
|
metadata: openaiOptions.metadata,
|
|
444
451
|
prediction: openaiOptions.prediction,
|
|
445
452
|
reasoning_effort: openaiOptions.reasoningEffort,
|
|
453
|
+
service_tier: openaiOptions.serviceTier,
|
|
446
454
|
// messages:
|
|
447
455
|
messages
|
|
448
456
|
};
|
|
@@ -516,6 +524,14 @@ var OpenAIChatLanguageModel = class {
|
|
|
516
524
|
});
|
|
517
525
|
}
|
|
518
526
|
}
|
|
527
|
+
if (openaiOptions.serviceTier === "flex" && !supportsFlexProcessing(this.modelId)) {
|
|
528
|
+
warnings.push({
|
|
529
|
+
type: "unsupported-setting",
|
|
530
|
+
setting: "serviceTier",
|
|
531
|
+
details: "flex processing is only available for o3 and o4-mini models"
|
|
532
|
+
});
|
|
533
|
+
baseArgs.service_tier = void 0;
|
|
534
|
+
}
|
|
519
535
|
const {
|
|
520
536
|
tools: openaiTools2,
|
|
521
537
|
toolChoice: openaiToolChoice,
|
|
@@ -642,6 +658,9 @@ var OpenAIChatLanguageModel = class {
|
|
|
642
658
|
},
|
|
643
659
|
transform(chunk, controller) {
|
|
644
660
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
661
|
+
if (options.includeRawChunks) {
|
|
662
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
663
|
+
}
|
|
645
664
|
if (!chunk.success) {
|
|
646
665
|
finishReason = "error";
|
|
647
666
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -887,6 +906,9 @@ var openaiChatChunkSchema = z3.union([
|
|
|
887
906
|
function isReasoningModel(modelId) {
|
|
888
907
|
return modelId.startsWith("o");
|
|
889
908
|
}
|
|
909
|
+
function supportsFlexProcessing(modelId) {
|
|
910
|
+
return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
911
|
+
}
|
|
890
912
|
function getSystemMessageMode(modelId) {
|
|
891
913
|
var _a, _b;
|
|
892
914
|
if (!isReasoningModel(modelId)) {
|
|
@@ -1227,6 +1249,9 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1227
1249
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1228
1250
|
},
|
|
1229
1251
|
transform(chunk, controller) {
|
|
1252
|
+
if (options.includeRawChunks) {
|
|
1253
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1254
|
+
}
|
|
1230
1255
|
if (!chunk.success) {
|
|
1231
1256
|
finishReason = "error";
|
|
1232
1257
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -2039,6 +2064,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2039
2064
|
store: openaiOptions == null ? void 0 : openaiOptions.store,
|
|
2040
2065
|
user: openaiOptions == null ? void 0 : openaiOptions.user,
|
|
2041
2066
|
instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
|
|
2067
|
+
service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
|
|
2042
2068
|
// model-specific settings:
|
|
2043
2069
|
...modelConfig.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
|
|
2044
2070
|
reasoning: {
|
|
@@ -2072,6 +2098,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2072
2098
|
});
|
|
2073
2099
|
}
|
|
2074
2100
|
}
|
|
2101
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !supportsFlexProcessing2(this.modelId)) {
|
|
2102
|
+
warnings.push({
|
|
2103
|
+
type: "unsupported-setting",
|
|
2104
|
+
setting: "serviceTier",
|
|
2105
|
+
details: "flex processing is only available for o3 and o4-mini models"
|
|
2106
|
+
});
|
|
2107
|
+
delete baseArgs.service_tier;
|
|
2108
|
+
}
|
|
2075
2109
|
const {
|
|
2076
2110
|
tools: openaiTools2,
|
|
2077
2111
|
toolChoice: openaiToolChoice,
|
|
@@ -2259,6 +2293,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2259
2293
|
let responseId = null;
|
|
2260
2294
|
const ongoingToolCalls = {};
|
|
2261
2295
|
let hasToolCalls = false;
|
|
2296
|
+
let lastReasoningSummaryIndex = null;
|
|
2262
2297
|
return {
|
|
2263
2298
|
stream: response.pipeThrough(
|
|
2264
2299
|
new TransformStream({
|
|
@@ -2267,6 +2302,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2267
2302
|
},
|
|
2268
2303
|
transform(chunk, controller) {
|
|
2269
2304
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2305
|
+
if (options.includeRawChunks) {
|
|
2306
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2307
|
+
}
|
|
2270
2308
|
if (!chunk.success) {
|
|
2271
2309
|
finishReason = "error";
|
|
2272
2310
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -2312,10 +2350,16 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2312
2350
|
text: value.delta
|
|
2313
2351
|
});
|
|
2314
2352
|
} else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
|
|
2353
|
+
if (lastReasoningSummaryIndex !== null && value.summary_index !== lastReasoningSummaryIndex) {
|
|
2354
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
|
2355
|
+
}
|
|
2356
|
+
lastReasoningSummaryIndex = value.summary_index;
|
|
2315
2357
|
controller.enqueue({
|
|
2316
2358
|
type: "reasoning",
|
|
2317
2359
|
text: value.delta
|
|
2318
2360
|
});
|
|
2361
|
+
} else if (isResponseReasoningSummaryPartDoneChunk(value)) {
|
|
2362
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
|
2319
2363
|
} else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
|
|
2320
2364
|
ongoingToolCalls[value.output_index] = void 0;
|
|
2321
2365
|
hasToolCalls = true;
|
|
@@ -2444,6 +2488,13 @@ var responseReasoningSummaryTextDeltaSchema = z12.object({
|
|
|
2444
2488
|
summary_index: z12.number(),
|
|
2445
2489
|
delta: z12.string()
|
|
2446
2490
|
});
|
|
2491
|
+
var responseReasoningSummaryPartDoneSchema = z12.object({
|
|
2492
|
+
type: z12.literal("response.reasoning_summary_part.done"),
|
|
2493
|
+
item_id: z12.string(),
|
|
2494
|
+
output_index: z12.number(),
|
|
2495
|
+
summary_index: z12.number(),
|
|
2496
|
+
part: z12.unknown().nullish()
|
|
2497
|
+
});
|
|
2447
2498
|
var openaiResponsesChunkSchema = z12.union([
|
|
2448
2499
|
textDeltaChunkSchema,
|
|
2449
2500
|
responseFinishedChunkSchema,
|
|
@@ -2453,6 +2504,7 @@ var openaiResponsesChunkSchema = z12.union([
|
|
|
2453
2504
|
responseOutputItemAddedSchema,
|
|
2454
2505
|
responseAnnotationAddedSchema,
|
|
2455
2506
|
responseReasoningSummaryTextDeltaSchema,
|
|
2507
|
+
responseReasoningSummaryPartDoneSchema,
|
|
2456
2508
|
z12.object({ type: z12.string() }).passthrough()
|
|
2457
2509
|
// fallback for unknown chunks
|
|
2458
2510
|
]);
|
|
@@ -2480,6 +2532,9 @@ function isResponseAnnotationAddedChunk(chunk) {
|
|
|
2480
2532
|
function isResponseReasoningSummaryTextDeltaChunk(chunk) {
|
|
2481
2533
|
return chunk.type === "response.reasoning_summary_text.delta";
|
|
2482
2534
|
}
|
|
2535
|
+
function isResponseReasoningSummaryPartDoneChunk(chunk) {
|
|
2536
|
+
return chunk.type === "response.reasoning_summary_part.done";
|
|
2537
|
+
}
|
|
2483
2538
|
function getResponsesModelConfig(modelId) {
|
|
2484
2539
|
if (modelId.startsWith("o")) {
|
|
2485
2540
|
if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
|
|
@@ -2501,6 +2556,9 @@ function getResponsesModelConfig(modelId) {
|
|
|
2501
2556
|
requiredAutoTruncation: false
|
|
2502
2557
|
};
|
|
2503
2558
|
}
|
|
2559
|
+
function supportsFlexProcessing2(modelId) {
|
|
2560
|
+
return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
2561
|
+
}
|
|
2504
2562
|
var openaiResponsesProviderOptionsSchema = z12.object({
|
|
2505
2563
|
metadata: z12.any().nullish(),
|
|
2506
2564
|
parallelToolCalls: z12.boolean().nullish(),
|
|
@@ -2510,7 +2568,8 @@ var openaiResponsesProviderOptionsSchema = z12.object({
|
|
|
2510
2568
|
reasoningEffort: z12.string().nullish(),
|
|
2511
2569
|
strictSchemas: z12.boolean().nullish(),
|
|
2512
2570
|
instructions: z12.string().nullish(),
|
|
2513
|
-
reasoningSummary: z12.string().nullish()
|
|
2571
|
+
reasoningSummary: z12.string().nullish(),
|
|
2572
|
+
serviceTier: z12.enum(["auto", "flex"]).nullish()
|
|
2514
2573
|
});
|
|
2515
2574
|
|
|
2516
2575
|
// src/openai-speech-model.ts
|