@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/index.mjs
CHANGED
|
@@ -294,7 +294,7 @@ var openaiProviderOptions = z.object({
|
|
|
294
294
|
/**
|
|
295
295
|
* Whether to use strict JSON schema validation.
|
|
296
296
|
*
|
|
297
|
-
* @default
|
|
297
|
+
* @default false
|
|
298
298
|
*/
|
|
299
299
|
strictJsonSchema: z.boolean().optional()
|
|
300
300
|
});
|
|
@@ -2576,6 +2576,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2576
2576
|
let responseId = null;
|
|
2577
2577
|
const ongoingToolCalls = {};
|
|
2578
2578
|
let hasToolCalls = false;
|
|
2579
|
+
const activeReasoning = {};
|
|
2579
2580
|
return {
|
|
2580
2581
|
stream: response.pipeThrough(
|
|
2581
2582
|
new TransformStream({
|
|
@@ -2583,7 +2584,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2583
2584
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2584
2585
|
},
|
|
2585
2586
|
transform(chunk, controller) {
|
|
2586
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2587
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2587
2588
|
if (options.includeRawChunks) {
|
|
2588
2589
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2589
2590
|
}
|
|
@@ -2629,10 +2630,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2629
2630
|
type: "text-start",
|
|
2630
2631
|
id: value.item.id
|
|
2631
2632
|
});
|
|
2632
|
-
} else if (value
|
|
2633
|
+
} else if (isResponseOutputItemAddedReasoningChunk(value)) {
|
|
2634
|
+
activeReasoning[value.item.id] = {
|
|
2635
|
+
encryptedContent: value.item.encrypted_content,
|
|
2636
|
+
summaryParts: [0]
|
|
2637
|
+
};
|
|
2633
2638
|
controller.enqueue({
|
|
2634
2639
|
type: "reasoning-start",
|
|
2635
|
-
id: value.item.id
|
|
2640
|
+
id: `${value.item.id}:0`,
|
|
2636
2641
|
providerMetadata: {
|
|
2637
2642
|
openai: {
|
|
2638
2643
|
reasoning: {
|
|
@@ -2710,19 +2715,23 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2710
2715
|
type: "text-end",
|
|
2711
2716
|
id: value.item.id
|
|
2712
2717
|
});
|
|
2713
|
-
} else if (value
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2718
|
+
} else if (isResponseOutputItemDoneReasoningChunk(value)) {
|
|
2719
|
+
const activeReasoningPart = activeReasoning[value.item.id];
|
|
2720
|
+
for (const summaryIndex of activeReasoningPart.summaryParts) {
|
|
2721
|
+
controller.enqueue({
|
|
2722
|
+
type: "reasoning-end",
|
|
2723
|
+
id: `${value.item.id}:${summaryIndex}`,
|
|
2724
|
+
providerMetadata: {
|
|
2725
|
+
openai: {
|
|
2726
|
+
reasoning: {
|
|
2727
|
+
id: value.item.id,
|
|
2728
|
+
encryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
|
|
2729
|
+
}
|
|
2722
2730
|
}
|
|
2723
2731
|
}
|
|
2724
|
-
}
|
|
2725
|
-
}
|
|
2732
|
+
});
|
|
2733
|
+
}
|
|
2734
|
+
delete activeReasoning[value.item.id];
|
|
2726
2735
|
}
|
|
2727
2736
|
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
2728
2737
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
@@ -2747,27 +2756,52 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2747
2756
|
id: value.item_id,
|
|
2748
2757
|
delta: value.delta
|
|
2749
2758
|
});
|
|
2759
|
+
} else if (isResponseReasoningSummaryPartAddedChunk(value)) {
|
|
2760
|
+
if (value.summary_index > 0) {
|
|
2761
|
+
(_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
|
|
2762
|
+
value.summary_index
|
|
2763
|
+
);
|
|
2764
|
+
controller.enqueue({
|
|
2765
|
+
type: "reasoning-start",
|
|
2766
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
2767
|
+
providerMetadata: {
|
|
2768
|
+
openai: {
|
|
2769
|
+
reasoning: {
|
|
2770
|
+
id: value.item_id,
|
|
2771
|
+
encryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
});
|
|
2776
|
+
}
|
|
2750
2777
|
} else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
|
|
2751
2778
|
controller.enqueue({
|
|
2752
2779
|
type: "reasoning-delta",
|
|
2753
|
-
id: value.item_id
|
|
2754
|
-
delta: value.delta
|
|
2780
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
2781
|
+
delta: value.delta,
|
|
2782
|
+
providerMetadata: {
|
|
2783
|
+
openai: {
|
|
2784
|
+
reasoning: {
|
|
2785
|
+
id: value.item_id
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2755
2789
|
});
|
|
2756
2790
|
} else if (isResponseFinishedChunk(value)) {
|
|
2757
2791
|
finishReason = mapOpenAIResponseFinishReason({
|
|
2758
|
-
finishReason: (
|
|
2792
|
+
finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
|
|
2759
2793
|
hasToolCalls
|
|
2760
2794
|
});
|
|
2761
2795
|
usage.inputTokens = value.response.usage.input_tokens;
|
|
2762
2796
|
usage.outputTokens = value.response.usage.output_tokens;
|
|
2763
2797
|
usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
|
|
2764
|
-
usage.reasoningTokens = (
|
|
2765
|
-
usage.cachedInputTokens = (
|
|
2798
|
+
usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
|
|
2799
|
+
usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
|
|
2766
2800
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2767
2801
|
controller.enqueue({
|
|
2768
2802
|
type: "source",
|
|
2769
2803
|
sourceType: "url",
|
|
2770
|
-
id: (
|
|
2804
|
+
id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : generateId2(),
|
|
2771
2805
|
url: value.annotation.url,
|
|
2772
2806
|
title: value.annotation.title
|
|
2773
2807
|
});
|
|
@@ -2838,13 +2872,7 @@ var responseOutputItemAddedSchema = z14.object({
|
|
|
2838
2872
|
z14.object({
|
|
2839
2873
|
type: z14.literal("reasoning"),
|
|
2840
2874
|
id: z14.string(),
|
|
2841
|
-
encrypted_content: z14.string().nullish()
|
|
2842
|
-
summary: z14.array(
|
|
2843
|
-
z14.object({
|
|
2844
|
-
type: z14.literal("summary_text"),
|
|
2845
|
-
text: z14.string()
|
|
2846
|
-
})
|
|
2847
|
-
)
|
|
2875
|
+
encrypted_content: z14.string().nullish()
|
|
2848
2876
|
}),
|
|
2849
2877
|
z14.object({
|
|
2850
2878
|
type: z14.literal("function_call"),
|
|
@@ -2876,13 +2904,7 @@ var responseOutputItemDoneSchema = z14.object({
|
|
|
2876
2904
|
z14.object({
|
|
2877
2905
|
type: z14.literal("reasoning"),
|
|
2878
2906
|
id: z14.string(),
|
|
2879
|
-
encrypted_content: z14.string().nullish()
|
|
2880
|
-
summary: z14.array(
|
|
2881
|
-
z14.object({
|
|
2882
|
-
type: z14.literal("summary_text"),
|
|
2883
|
-
text: z14.string()
|
|
2884
|
-
})
|
|
2885
|
-
)
|
|
2907
|
+
encrypted_content: z14.string().nullish()
|
|
2886
2908
|
}),
|
|
2887
2909
|
z14.object({
|
|
2888
2910
|
type: z14.literal("function_call"),
|
|
@@ -2918,9 +2940,15 @@ var responseAnnotationAddedSchema = z14.object({
|
|
|
2918
2940
|
title: z14.string()
|
|
2919
2941
|
})
|
|
2920
2942
|
});
|
|
2943
|
+
var responseReasoningSummaryPartAddedSchema = z14.object({
|
|
2944
|
+
type: z14.literal("response.reasoning_summary_part.added"),
|
|
2945
|
+
item_id: z14.string(),
|
|
2946
|
+
summary_index: z14.number()
|
|
2947
|
+
});
|
|
2921
2948
|
var responseReasoningSummaryTextDeltaSchema = z14.object({
|
|
2922
2949
|
type: z14.literal("response.reasoning_summary_text.delta"),
|
|
2923
2950
|
item_id: z14.string(),
|
|
2951
|
+
summary_index: z14.number(),
|
|
2924
2952
|
delta: z14.string()
|
|
2925
2953
|
});
|
|
2926
2954
|
var openaiResponsesChunkSchema = z14.union([
|
|
@@ -2931,6 +2959,7 @@ var openaiResponsesChunkSchema = z14.union([
|
|
|
2931
2959
|
responseOutputItemDoneSchema,
|
|
2932
2960
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2933
2961
|
responseAnnotationAddedSchema,
|
|
2962
|
+
responseReasoningSummaryPartAddedSchema,
|
|
2934
2963
|
responseReasoningSummaryTextDeltaSchema,
|
|
2935
2964
|
errorChunkSchema,
|
|
2936
2965
|
z14.object({ type: z14.string() }).loose()
|
|
@@ -2942,6 +2971,9 @@ function isTextDeltaChunk(chunk) {
|
|
|
2942
2971
|
function isResponseOutputItemDoneChunk(chunk) {
|
|
2943
2972
|
return chunk.type === "response.output_item.done";
|
|
2944
2973
|
}
|
|
2974
|
+
function isResponseOutputItemDoneReasoningChunk(chunk) {
|
|
2975
|
+
return isResponseOutputItemDoneChunk(chunk) && chunk.item.type === "reasoning";
|
|
2976
|
+
}
|
|
2945
2977
|
function isResponseFinishedChunk(chunk) {
|
|
2946
2978
|
return chunk.type === "response.completed" || chunk.type === "response.incomplete";
|
|
2947
2979
|
}
|
|
@@ -2954,9 +2986,15 @@ function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
|
|
|
2954
2986
|
function isResponseOutputItemAddedChunk(chunk) {
|
|
2955
2987
|
return chunk.type === "response.output_item.added";
|
|
2956
2988
|
}
|
|
2989
|
+
function isResponseOutputItemAddedReasoningChunk(chunk) {
|
|
2990
|
+
return isResponseOutputItemAddedChunk(chunk) && chunk.item.type === "reasoning";
|
|
2991
|
+
}
|
|
2957
2992
|
function isResponseAnnotationAddedChunk(chunk) {
|
|
2958
2993
|
return chunk.type === "response.output_text.annotation.added";
|
|
2959
2994
|
}
|
|
2995
|
+
function isResponseReasoningSummaryPartAddedChunk(chunk) {
|
|
2996
|
+
return chunk.type === "response.reasoning_summary_part.added";
|
|
2997
|
+
}
|
|
2960
2998
|
function isResponseReasoningSummaryTextDeltaChunk(chunk) {
|
|
2961
2999
|
return chunk.type === "response.reasoning_summary_text.delta";
|
|
2962
3000
|
}
|