@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/internal/index.mjs
CHANGED
|
@@ -264,7 +264,14 @@ var openaiProviderOptions = z.object({
|
|
|
264
264
|
*
|
|
265
265
|
* @default true
|
|
266
266
|
*/
|
|
267
|
-
structuredOutputs: z.boolean().optional()
|
|
267
|
+
structuredOutputs: z.boolean().optional(),
|
|
268
|
+
/**
|
|
269
|
+
* Service tier for the request. Set to 'flex' for 50% cheaper processing
|
|
270
|
+
* at the cost of increased latency. Only available for o3 and o4-mini models.
|
|
271
|
+
*
|
|
272
|
+
* @default 'auto'
|
|
273
|
+
*/
|
|
274
|
+
serviceTier: z.enum(["auto", "flex"]).optional()
|
|
268
275
|
});
|
|
269
276
|
|
|
270
277
|
// src/openai-error.ts
|
|
@@ -437,6 +444,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
437
444
|
metadata: openaiOptions.metadata,
|
|
438
445
|
prediction: openaiOptions.prediction,
|
|
439
446
|
reasoning_effort: openaiOptions.reasoningEffort,
|
|
447
|
+
service_tier: openaiOptions.serviceTier,
|
|
440
448
|
// messages:
|
|
441
449
|
messages
|
|
442
450
|
};
|
|
@@ -510,6 +518,14 @@ var OpenAIChatLanguageModel = class {
|
|
|
510
518
|
});
|
|
511
519
|
}
|
|
512
520
|
}
|
|
521
|
+
if (openaiOptions.serviceTier === "flex" && !supportsFlexProcessing(this.modelId)) {
|
|
522
|
+
warnings.push({
|
|
523
|
+
type: "unsupported-setting",
|
|
524
|
+
setting: "serviceTier",
|
|
525
|
+
details: "flex processing is only available for o3 and o4-mini models"
|
|
526
|
+
});
|
|
527
|
+
baseArgs.service_tier = void 0;
|
|
528
|
+
}
|
|
513
529
|
const {
|
|
514
530
|
tools: openaiTools,
|
|
515
531
|
toolChoice: openaiToolChoice,
|
|
@@ -636,6 +652,9 @@ var OpenAIChatLanguageModel = class {
|
|
|
636
652
|
},
|
|
637
653
|
transform(chunk, controller) {
|
|
638
654
|
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;
|
|
655
|
+
if (options.includeRawChunks) {
|
|
656
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
657
|
+
}
|
|
639
658
|
if (!chunk.success) {
|
|
640
659
|
finishReason = "error";
|
|
641
660
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -881,6 +900,9 @@ var openaiChatChunkSchema = z3.union([
|
|
|
881
900
|
function isReasoningModel(modelId) {
|
|
882
901
|
return modelId.startsWith("o");
|
|
883
902
|
}
|
|
903
|
+
function supportsFlexProcessing(modelId) {
|
|
904
|
+
return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
905
|
+
}
|
|
884
906
|
function getSystemMessageMode(modelId) {
|
|
885
907
|
var _a, _b;
|
|
886
908
|
if (!isReasoningModel(modelId)) {
|
|
@@ -1221,6 +1243,9 @@ var OpenAICompletionLanguageModel = class {
|
|
|
1221
1243
|
controller.enqueue({ type: "stream-start", warnings });
|
|
1222
1244
|
},
|
|
1223
1245
|
transform(chunk, controller) {
|
|
1246
|
+
if (options.includeRawChunks) {
|
|
1247
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
1248
|
+
}
|
|
1224
1249
|
if (!chunk.success) {
|
|
1225
1250
|
finishReason = "error";
|
|
1226
1251
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -2116,6 +2141,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2116
2141
|
store: openaiOptions == null ? void 0 : openaiOptions.store,
|
|
2117
2142
|
user: openaiOptions == null ? void 0 : openaiOptions.user,
|
|
2118
2143
|
instructions: openaiOptions == null ? void 0 : openaiOptions.instructions,
|
|
2144
|
+
service_tier: openaiOptions == null ? void 0 : openaiOptions.serviceTier,
|
|
2119
2145
|
// model-specific settings:
|
|
2120
2146
|
...modelConfig.isReasoningModel && ((openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
|
|
2121
2147
|
reasoning: {
|
|
@@ -2149,6 +2175,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2149
2175
|
});
|
|
2150
2176
|
}
|
|
2151
2177
|
}
|
|
2178
|
+
if ((openaiOptions == null ? void 0 : openaiOptions.serviceTier) === "flex" && !supportsFlexProcessing2(this.modelId)) {
|
|
2179
|
+
warnings.push({
|
|
2180
|
+
type: "unsupported-setting",
|
|
2181
|
+
setting: "serviceTier",
|
|
2182
|
+
details: "flex processing is only available for o3 and o4-mini models"
|
|
2183
|
+
});
|
|
2184
|
+
delete baseArgs.service_tier;
|
|
2185
|
+
}
|
|
2152
2186
|
const {
|
|
2153
2187
|
tools: openaiTools,
|
|
2154
2188
|
toolChoice: openaiToolChoice,
|
|
@@ -2336,6 +2370,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2336
2370
|
let responseId = null;
|
|
2337
2371
|
const ongoingToolCalls = {};
|
|
2338
2372
|
let hasToolCalls = false;
|
|
2373
|
+
let lastReasoningSummaryIndex = null;
|
|
2339
2374
|
return {
|
|
2340
2375
|
stream: response.pipeThrough(
|
|
2341
2376
|
new TransformStream({
|
|
@@ -2344,6 +2379,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2344
2379
|
},
|
|
2345
2380
|
transform(chunk, controller) {
|
|
2346
2381
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2382
|
+
if (options.includeRawChunks) {
|
|
2383
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2384
|
+
}
|
|
2347
2385
|
if (!chunk.success) {
|
|
2348
2386
|
finishReason = "error";
|
|
2349
2387
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -2389,10 +2427,16 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2389
2427
|
text: value.delta
|
|
2390
2428
|
});
|
|
2391
2429
|
} else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
|
|
2430
|
+
if (lastReasoningSummaryIndex !== null && value.summary_index !== lastReasoningSummaryIndex) {
|
|
2431
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
|
2432
|
+
}
|
|
2433
|
+
lastReasoningSummaryIndex = value.summary_index;
|
|
2392
2434
|
controller.enqueue({
|
|
2393
2435
|
type: "reasoning",
|
|
2394
2436
|
text: value.delta
|
|
2395
2437
|
});
|
|
2438
|
+
} else if (isResponseReasoningSummaryPartDoneChunk(value)) {
|
|
2439
|
+
controller.enqueue({ type: "reasoning-part-finish" });
|
|
2396
2440
|
} else if (isResponseOutputItemDoneChunk(value) && value.item.type === "function_call") {
|
|
2397
2441
|
ongoingToolCalls[value.output_index] = void 0;
|
|
2398
2442
|
hasToolCalls = true;
|
|
@@ -2521,6 +2565,13 @@ var responseReasoningSummaryTextDeltaSchema = z12.object({
|
|
|
2521
2565
|
summary_index: z12.number(),
|
|
2522
2566
|
delta: z12.string()
|
|
2523
2567
|
});
|
|
2568
|
+
var responseReasoningSummaryPartDoneSchema = z12.object({
|
|
2569
|
+
type: z12.literal("response.reasoning_summary_part.done"),
|
|
2570
|
+
item_id: z12.string(),
|
|
2571
|
+
output_index: z12.number(),
|
|
2572
|
+
summary_index: z12.number(),
|
|
2573
|
+
part: z12.unknown().nullish()
|
|
2574
|
+
});
|
|
2524
2575
|
var openaiResponsesChunkSchema = z12.union([
|
|
2525
2576
|
textDeltaChunkSchema,
|
|
2526
2577
|
responseFinishedChunkSchema,
|
|
@@ -2530,6 +2581,7 @@ var openaiResponsesChunkSchema = z12.union([
|
|
|
2530
2581
|
responseOutputItemAddedSchema,
|
|
2531
2582
|
responseAnnotationAddedSchema,
|
|
2532
2583
|
responseReasoningSummaryTextDeltaSchema,
|
|
2584
|
+
responseReasoningSummaryPartDoneSchema,
|
|
2533
2585
|
z12.object({ type: z12.string() }).passthrough()
|
|
2534
2586
|
// fallback for unknown chunks
|
|
2535
2587
|
]);
|
|
@@ -2557,6 +2609,9 @@ function isResponseAnnotationAddedChunk(chunk) {
|
|
|
2557
2609
|
function isResponseReasoningSummaryTextDeltaChunk(chunk) {
|
|
2558
2610
|
return chunk.type === "response.reasoning_summary_text.delta";
|
|
2559
2611
|
}
|
|
2612
|
+
function isResponseReasoningSummaryPartDoneChunk(chunk) {
|
|
2613
|
+
return chunk.type === "response.reasoning_summary_part.done";
|
|
2614
|
+
}
|
|
2560
2615
|
function getResponsesModelConfig(modelId) {
|
|
2561
2616
|
if (modelId.startsWith("o")) {
|
|
2562
2617
|
if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
|
|
@@ -2578,6 +2633,9 @@ function getResponsesModelConfig(modelId) {
|
|
|
2578
2633
|
requiredAutoTruncation: false
|
|
2579
2634
|
};
|
|
2580
2635
|
}
|
|
2636
|
+
function supportsFlexProcessing2(modelId) {
|
|
2637
|
+
return modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
2638
|
+
}
|
|
2581
2639
|
var openaiResponsesProviderOptionsSchema = z12.object({
|
|
2582
2640
|
metadata: z12.any().nullish(),
|
|
2583
2641
|
parallelToolCalls: z12.boolean().nullish(),
|
|
@@ -2587,7 +2645,8 @@ var openaiResponsesProviderOptionsSchema = z12.object({
|
|
|
2587
2645
|
reasoningEffort: z12.string().nullish(),
|
|
2588
2646
|
strictSchemas: z12.boolean().nullish(),
|
|
2589
2647
|
instructions: z12.string().nullish(),
|
|
2590
|
-
reasoningSummary: z12.string().nullish()
|
|
2648
|
+
reasoningSummary: z12.string().nullish(),
|
|
2649
|
+
serviceTier: z12.enum(["auto", "flex"]).nullish()
|
|
2591
2650
|
});
|
|
2592
2651
|
export {
|
|
2593
2652
|
OpenAIChatLanguageModel,
|