@ai-sdk/openai 2.0.0-beta.5 → 2.0.0-beta.6
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 +8 -0
- package/dist/index.js +73 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -35
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +73 -35
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +73 -35
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/internal/index.js
CHANGED
|
@@ -314,7 +314,7 @@ var openaiProviderOptions = import_v4.z.object({
|
|
|
314
314
|
/**
|
|
315
315
|
* Whether to use strict JSON schema validation.
|
|
316
316
|
*
|
|
317
|
-
* @default
|
|
317
|
+
* @default false
|
|
318
318
|
*/
|
|
319
319
|
strictJsonSchema: import_v4.z.boolean().optional()
|
|
320
320
|
});
|
|
@@ -2656,6 +2656,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2656
2656
|
let responseId = null;
|
|
2657
2657
|
const ongoingToolCalls = {};
|
|
2658
2658
|
let hasToolCalls = false;
|
|
2659
|
+
const activeReasoning = {};
|
|
2659
2660
|
return {
|
|
2660
2661
|
stream: response.pipeThrough(
|
|
2661
2662
|
new TransformStream({
|
|
@@ -2663,7 +2664,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2663
2664
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2664
2665
|
},
|
|
2665
2666
|
transform(chunk, controller) {
|
|
2666
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2667
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2667
2668
|
if (options.includeRawChunks) {
|
|
2668
2669
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2669
2670
|
}
|
|
@@ -2709,10 +2710,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2709
2710
|
type: "text-start",
|
|
2710
2711
|
id: value.item.id
|
|
2711
2712
|
});
|
|
2712
|
-
} else if (value
|
|
2713
|
+
} else if (isResponseOutputItemAddedReasoningChunk(value)) {
|
|
2714
|
+
activeReasoning[value.item.id] = {
|
|
2715
|
+
encryptedContent: value.item.encrypted_content,
|
|
2716
|
+
summaryParts: [0]
|
|
2717
|
+
};
|
|
2713
2718
|
controller.enqueue({
|
|
2714
2719
|
type: "reasoning-start",
|
|
2715
|
-
id: value.item.id
|
|
2720
|
+
id: `${value.item.id}:0`,
|
|
2716
2721
|
providerMetadata: {
|
|
2717
2722
|
openai: {
|
|
2718
2723
|
reasoning: {
|
|
@@ -2790,19 +2795,23 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2790
2795
|
type: "text-end",
|
|
2791
2796
|
id: value.item.id
|
|
2792
2797
|
});
|
|
2793
|
-
} else if (value
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2798
|
+
} else if (isResponseOutputItemDoneReasoningChunk(value)) {
|
|
2799
|
+
const activeReasoningPart = activeReasoning[value.item.id];
|
|
2800
|
+
for (const summaryIndex of activeReasoningPart.summaryParts) {
|
|
2801
|
+
controller.enqueue({
|
|
2802
|
+
type: "reasoning-end",
|
|
2803
|
+
id: `${value.item.id}:${summaryIndex}`,
|
|
2804
|
+
providerMetadata: {
|
|
2805
|
+
openai: {
|
|
2806
|
+
reasoning: {
|
|
2807
|
+
id: value.item.id,
|
|
2808
|
+
encryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
|
|
2809
|
+
}
|
|
2802
2810
|
}
|
|
2803
2811
|
}
|
|
2804
|
-
}
|
|
2805
|
-
}
|
|
2812
|
+
});
|
|
2813
|
+
}
|
|
2814
|
+
delete activeReasoning[value.item.id];
|
|
2806
2815
|
}
|
|
2807
2816
|
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
2808
2817
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
@@ -2827,27 +2836,52 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2827
2836
|
id: value.item_id,
|
|
2828
2837
|
delta: value.delta
|
|
2829
2838
|
});
|
|
2839
|
+
} else if (isResponseReasoningSummaryPartAddedChunk(value)) {
|
|
2840
|
+
if (value.summary_index > 0) {
|
|
2841
|
+
(_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
|
|
2842
|
+
value.summary_index
|
|
2843
|
+
);
|
|
2844
|
+
controller.enqueue({
|
|
2845
|
+
type: "reasoning-start",
|
|
2846
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
2847
|
+
providerMetadata: {
|
|
2848
|
+
openai: {
|
|
2849
|
+
reasoning: {
|
|
2850
|
+
id: value.item_id,
|
|
2851
|
+
encryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2855
|
+
});
|
|
2856
|
+
}
|
|
2830
2857
|
} else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
|
|
2831
2858
|
controller.enqueue({
|
|
2832
2859
|
type: "reasoning-delta",
|
|
2833
|
-
id: value.item_id
|
|
2834
|
-
delta: value.delta
|
|
2860
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
2861
|
+
delta: value.delta,
|
|
2862
|
+
providerMetadata: {
|
|
2863
|
+
openai: {
|
|
2864
|
+
reasoning: {
|
|
2865
|
+
id: value.item_id
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2835
2869
|
});
|
|
2836
2870
|
} else if (isResponseFinishedChunk(value)) {
|
|
2837
2871
|
finishReason = mapOpenAIResponseFinishReason({
|
|
2838
|
-
finishReason: (
|
|
2872
|
+
finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
|
|
2839
2873
|
hasToolCalls
|
|
2840
2874
|
});
|
|
2841
2875
|
usage.inputTokens = value.response.usage.input_tokens;
|
|
2842
2876
|
usage.outputTokens = value.response.usage.output_tokens;
|
|
2843
2877
|
usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
|
|
2844
|
-
usage.reasoningTokens = (
|
|
2845
|
-
usage.cachedInputTokens = (
|
|
2878
|
+
usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
|
|
2879
|
+
usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
|
|
2846
2880
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2847
2881
|
controller.enqueue({
|
|
2848
2882
|
type: "source",
|
|
2849
2883
|
sourceType: "url",
|
|
2850
|
-
id: (
|
|
2884
|
+
id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : (0, import_provider_utils12.generateId)(),
|
|
2851
2885
|
url: value.annotation.url,
|
|
2852
2886
|
title: value.annotation.title
|
|
2853
2887
|
});
|
|
@@ -2918,13 +2952,7 @@ var responseOutputItemAddedSchema = import_v415.z.object({
|
|
|
2918
2952
|
import_v415.z.object({
|
|
2919
2953
|
type: import_v415.z.literal("reasoning"),
|
|
2920
2954
|
id: import_v415.z.string(),
|
|
2921
|
-
encrypted_content: import_v415.z.string().nullish()
|
|
2922
|
-
summary: import_v415.z.array(
|
|
2923
|
-
import_v415.z.object({
|
|
2924
|
-
type: import_v415.z.literal("summary_text"),
|
|
2925
|
-
text: import_v415.z.string()
|
|
2926
|
-
})
|
|
2927
|
-
)
|
|
2955
|
+
encrypted_content: import_v415.z.string().nullish()
|
|
2928
2956
|
}),
|
|
2929
2957
|
import_v415.z.object({
|
|
2930
2958
|
type: import_v415.z.literal("function_call"),
|
|
@@ -2956,13 +2984,7 @@ var responseOutputItemDoneSchema = import_v415.z.object({
|
|
|
2956
2984
|
import_v415.z.object({
|
|
2957
2985
|
type: import_v415.z.literal("reasoning"),
|
|
2958
2986
|
id: import_v415.z.string(),
|
|
2959
|
-
encrypted_content: import_v415.z.string().nullish()
|
|
2960
|
-
summary: import_v415.z.array(
|
|
2961
|
-
import_v415.z.object({
|
|
2962
|
-
type: import_v415.z.literal("summary_text"),
|
|
2963
|
-
text: import_v415.z.string()
|
|
2964
|
-
})
|
|
2965
|
-
)
|
|
2987
|
+
encrypted_content: import_v415.z.string().nullish()
|
|
2966
2988
|
}),
|
|
2967
2989
|
import_v415.z.object({
|
|
2968
2990
|
type: import_v415.z.literal("function_call"),
|
|
@@ -2998,9 +3020,15 @@ var responseAnnotationAddedSchema = import_v415.z.object({
|
|
|
2998
3020
|
title: import_v415.z.string()
|
|
2999
3021
|
})
|
|
3000
3022
|
});
|
|
3023
|
+
var responseReasoningSummaryPartAddedSchema = import_v415.z.object({
|
|
3024
|
+
type: import_v415.z.literal("response.reasoning_summary_part.added"),
|
|
3025
|
+
item_id: import_v415.z.string(),
|
|
3026
|
+
summary_index: import_v415.z.number()
|
|
3027
|
+
});
|
|
3001
3028
|
var responseReasoningSummaryTextDeltaSchema = import_v415.z.object({
|
|
3002
3029
|
type: import_v415.z.literal("response.reasoning_summary_text.delta"),
|
|
3003
3030
|
item_id: import_v415.z.string(),
|
|
3031
|
+
summary_index: import_v415.z.number(),
|
|
3004
3032
|
delta: import_v415.z.string()
|
|
3005
3033
|
});
|
|
3006
3034
|
var openaiResponsesChunkSchema = import_v415.z.union([
|
|
@@ -3011,6 +3039,7 @@ var openaiResponsesChunkSchema = import_v415.z.union([
|
|
|
3011
3039
|
responseOutputItemDoneSchema,
|
|
3012
3040
|
responseFunctionCallArgumentsDeltaSchema,
|
|
3013
3041
|
responseAnnotationAddedSchema,
|
|
3042
|
+
responseReasoningSummaryPartAddedSchema,
|
|
3014
3043
|
responseReasoningSummaryTextDeltaSchema,
|
|
3015
3044
|
errorChunkSchema,
|
|
3016
3045
|
import_v415.z.object({ type: import_v415.z.string() }).loose()
|
|
@@ -3022,6 +3051,9 @@ function isTextDeltaChunk(chunk) {
|
|
|
3022
3051
|
function isResponseOutputItemDoneChunk(chunk) {
|
|
3023
3052
|
return chunk.type === "response.output_item.done";
|
|
3024
3053
|
}
|
|
3054
|
+
function isResponseOutputItemDoneReasoningChunk(chunk) {
|
|
3055
|
+
return isResponseOutputItemDoneChunk(chunk) && chunk.item.type === "reasoning";
|
|
3056
|
+
}
|
|
3025
3057
|
function isResponseFinishedChunk(chunk) {
|
|
3026
3058
|
return chunk.type === "response.completed" || chunk.type === "response.incomplete";
|
|
3027
3059
|
}
|
|
@@ -3034,9 +3066,15 @@ function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
|
|
|
3034
3066
|
function isResponseOutputItemAddedChunk(chunk) {
|
|
3035
3067
|
return chunk.type === "response.output_item.added";
|
|
3036
3068
|
}
|
|
3069
|
+
function isResponseOutputItemAddedReasoningChunk(chunk) {
|
|
3070
|
+
return isResponseOutputItemAddedChunk(chunk) && chunk.item.type === "reasoning";
|
|
3071
|
+
}
|
|
3037
3072
|
function isResponseAnnotationAddedChunk(chunk) {
|
|
3038
3073
|
return chunk.type === "response.output_text.annotation.added";
|
|
3039
3074
|
}
|
|
3075
|
+
function isResponseReasoningSummaryPartAddedChunk(chunk) {
|
|
3076
|
+
return chunk.type === "response.reasoning_summary_part.added";
|
|
3077
|
+
}
|
|
3040
3078
|
function isResponseReasoningSummaryTextDeltaChunk(chunk) {
|
|
3041
3079
|
return chunk.type === "response.reasoning_summary_text.delta";
|
|
3042
3080
|
}
|