@ai-sdk/openai 2.0.0-beta.5 → 2.0.0-beta.7
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 +14 -0
- package/dist/index.js +84 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -36
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +84 -36
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +84 -36
- 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
|
});
|
|
@@ -2132,6 +2132,16 @@ function prepareResponsesTools({
|
|
|
2132
2132
|
break;
|
|
2133
2133
|
case "provider-defined":
|
|
2134
2134
|
switch (tool.id) {
|
|
2135
|
+
case "openai.file_search": {
|
|
2136
|
+
const args = fileSearchArgsSchema.parse(tool.args);
|
|
2137
|
+
openaiTools2.push({
|
|
2138
|
+
type: "file_search",
|
|
2139
|
+
vector_store_ids: args.vectorStoreIds,
|
|
2140
|
+
max_results: args.maxResults,
|
|
2141
|
+
search_type: args.searchType
|
|
2142
|
+
});
|
|
2143
|
+
break;
|
|
2144
|
+
}
|
|
2135
2145
|
case "openai.web_search_preview":
|
|
2136
2146
|
openaiTools2.push({
|
|
2137
2147
|
type: "web_search_preview",
|
|
@@ -2161,7 +2171,7 @@ function prepareResponsesTools({
|
|
|
2161
2171
|
case "tool":
|
|
2162
2172
|
return {
|
|
2163
2173
|
tools: openaiTools2,
|
|
2164
|
-
toolChoice: toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
|
|
2174
|
+
toolChoice: toolChoice.toolName === "file_search" ? { type: "file_search" } : toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
|
|
2165
2175
|
toolWarnings
|
|
2166
2176
|
};
|
|
2167
2177
|
default: {
|
|
@@ -2576,6 +2586,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2576
2586
|
let responseId = null;
|
|
2577
2587
|
const ongoingToolCalls = {};
|
|
2578
2588
|
let hasToolCalls = false;
|
|
2589
|
+
const activeReasoning = {};
|
|
2579
2590
|
return {
|
|
2580
2591
|
stream: response.pipeThrough(
|
|
2581
2592
|
new TransformStream({
|
|
@@ -2583,7 +2594,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2583
2594
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2584
2595
|
},
|
|
2585
2596
|
transform(chunk, controller) {
|
|
2586
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2597
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2587
2598
|
if (options.includeRawChunks) {
|
|
2588
2599
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2589
2600
|
}
|
|
@@ -2629,10 +2640,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2629
2640
|
type: "text-start",
|
|
2630
2641
|
id: value.item.id
|
|
2631
2642
|
});
|
|
2632
|
-
} else if (value
|
|
2643
|
+
} else if (isResponseOutputItemAddedReasoningChunk(value)) {
|
|
2644
|
+
activeReasoning[value.item.id] = {
|
|
2645
|
+
encryptedContent: value.item.encrypted_content,
|
|
2646
|
+
summaryParts: [0]
|
|
2647
|
+
};
|
|
2633
2648
|
controller.enqueue({
|
|
2634
2649
|
type: "reasoning-start",
|
|
2635
|
-
id: value.item.id
|
|
2650
|
+
id: `${value.item.id}:0`,
|
|
2636
2651
|
providerMetadata: {
|
|
2637
2652
|
openai: {
|
|
2638
2653
|
reasoning: {
|
|
@@ -2710,19 +2725,23 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2710
2725
|
type: "text-end",
|
|
2711
2726
|
id: value.item.id
|
|
2712
2727
|
});
|
|
2713
|
-
} else if (value
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2728
|
+
} else if (isResponseOutputItemDoneReasoningChunk(value)) {
|
|
2729
|
+
const activeReasoningPart = activeReasoning[value.item.id];
|
|
2730
|
+
for (const summaryIndex of activeReasoningPart.summaryParts) {
|
|
2731
|
+
controller.enqueue({
|
|
2732
|
+
type: "reasoning-end",
|
|
2733
|
+
id: `${value.item.id}:${summaryIndex}`,
|
|
2734
|
+
providerMetadata: {
|
|
2735
|
+
openai: {
|
|
2736
|
+
reasoning: {
|
|
2737
|
+
id: value.item.id,
|
|
2738
|
+
encryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
|
|
2739
|
+
}
|
|
2722
2740
|
}
|
|
2723
2741
|
}
|
|
2724
|
-
}
|
|
2725
|
-
}
|
|
2742
|
+
});
|
|
2743
|
+
}
|
|
2744
|
+
delete activeReasoning[value.item.id];
|
|
2726
2745
|
}
|
|
2727
2746
|
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
2728
2747
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
@@ -2747,27 +2766,52 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2747
2766
|
id: value.item_id,
|
|
2748
2767
|
delta: value.delta
|
|
2749
2768
|
});
|
|
2769
|
+
} else if (isResponseReasoningSummaryPartAddedChunk(value)) {
|
|
2770
|
+
if (value.summary_index > 0) {
|
|
2771
|
+
(_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
|
|
2772
|
+
value.summary_index
|
|
2773
|
+
);
|
|
2774
|
+
controller.enqueue({
|
|
2775
|
+
type: "reasoning-start",
|
|
2776
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
2777
|
+
providerMetadata: {
|
|
2778
|
+
openai: {
|
|
2779
|
+
reasoning: {
|
|
2780
|
+
id: value.item_id,
|
|
2781
|
+
encryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
}
|
|
2785
|
+
});
|
|
2786
|
+
}
|
|
2750
2787
|
} else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
|
|
2751
2788
|
controller.enqueue({
|
|
2752
2789
|
type: "reasoning-delta",
|
|
2753
|
-
id: value.item_id
|
|
2754
|
-
delta: value.delta
|
|
2790
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
2791
|
+
delta: value.delta,
|
|
2792
|
+
providerMetadata: {
|
|
2793
|
+
openai: {
|
|
2794
|
+
reasoning: {
|
|
2795
|
+
id: value.item_id
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2755
2799
|
});
|
|
2756
2800
|
} else if (isResponseFinishedChunk(value)) {
|
|
2757
2801
|
finishReason = mapOpenAIResponseFinishReason({
|
|
2758
|
-
finishReason: (
|
|
2802
|
+
finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
|
|
2759
2803
|
hasToolCalls
|
|
2760
2804
|
});
|
|
2761
2805
|
usage.inputTokens = value.response.usage.input_tokens;
|
|
2762
2806
|
usage.outputTokens = value.response.usage.output_tokens;
|
|
2763
2807
|
usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
|
|
2764
|
-
usage.reasoningTokens = (
|
|
2765
|
-
usage.cachedInputTokens = (
|
|
2808
|
+
usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
|
|
2809
|
+
usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
|
|
2766
2810
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2767
2811
|
controller.enqueue({
|
|
2768
2812
|
type: "source",
|
|
2769
2813
|
sourceType: "url",
|
|
2770
|
-
id: (
|
|
2814
|
+
id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : generateId2(),
|
|
2771
2815
|
url: value.annotation.url,
|
|
2772
2816
|
title: value.annotation.title
|
|
2773
2817
|
});
|
|
@@ -2838,13 +2882,7 @@ var responseOutputItemAddedSchema = z14.object({
|
|
|
2838
2882
|
z14.object({
|
|
2839
2883
|
type: z14.literal("reasoning"),
|
|
2840
2884
|
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
|
-
)
|
|
2885
|
+
encrypted_content: z14.string().nullish()
|
|
2848
2886
|
}),
|
|
2849
2887
|
z14.object({
|
|
2850
2888
|
type: z14.literal("function_call"),
|
|
@@ -2876,13 +2914,7 @@ var responseOutputItemDoneSchema = z14.object({
|
|
|
2876
2914
|
z14.object({
|
|
2877
2915
|
type: z14.literal("reasoning"),
|
|
2878
2916
|
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
|
-
)
|
|
2917
|
+
encrypted_content: z14.string().nullish()
|
|
2886
2918
|
}),
|
|
2887
2919
|
z14.object({
|
|
2888
2920
|
type: z14.literal("function_call"),
|
|
@@ -2918,9 +2950,15 @@ var responseAnnotationAddedSchema = z14.object({
|
|
|
2918
2950
|
title: z14.string()
|
|
2919
2951
|
})
|
|
2920
2952
|
});
|
|
2953
|
+
var responseReasoningSummaryPartAddedSchema = z14.object({
|
|
2954
|
+
type: z14.literal("response.reasoning_summary_part.added"),
|
|
2955
|
+
item_id: z14.string(),
|
|
2956
|
+
summary_index: z14.number()
|
|
2957
|
+
});
|
|
2921
2958
|
var responseReasoningSummaryTextDeltaSchema = z14.object({
|
|
2922
2959
|
type: z14.literal("response.reasoning_summary_text.delta"),
|
|
2923
2960
|
item_id: z14.string(),
|
|
2961
|
+
summary_index: z14.number(),
|
|
2924
2962
|
delta: z14.string()
|
|
2925
2963
|
});
|
|
2926
2964
|
var openaiResponsesChunkSchema = z14.union([
|
|
@@ -2931,6 +2969,7 @@ var openaiResponsesChunkSchema = z14.union([
|
|
|
2931
2969
|
responseOutputItemDoneSchema,
|
|
2932
2970
|
responseFunctionCallArgumentsDeltaSchema,
|
|
2933
2971
|
responseAnnotationAddedSchema,
|
|
2972
|
+
responseReasoningSummaryPartAddedSchema,
|
|
2934
2973
|
responseReasoningSummaryTextDeltaSchema,
|
|
2935
2974
|
errorChunkSchema,
|
|
2936
2975
|
z14.object({ type: z14.string() }).loose()
|
|
@@ -2942,6 +2981,9 @@ function isTextDeltaChunk(chunk) {
|
|
|
2942
2981
|
function isResponseOutputItemDoneChunk(chunk) {
|
|
2943
2982
|
return chunk.type === "response.output_item.done";
|
|
2944
2983
|
}
|
|
2984
|
+
function isResponseOutputItemDoneReasoningChunk(chunk) {
|
|
2985
|
+
return isResponseOutputItemDoneChunk(chunk) && chunk.item.type === "reasoning";
|
|
2986
|
+
}
|
|
2945
2987
|
function isResponseFinishedChunk(chunk) {
|
|
2946
2988
|
return chunk.type === "response.completed" || chunk.type === "response.incomplete";
|
|
2947
2989
|
}
|
|
@@ -2954,9 +2996,15 @@ function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
|
|
|
2954
2996
|
function isResponseOutputItemAddedChunk(chunk) {
|
|
2955
2997
|
return chunk.type === "response.output_item.added";
|
|
2956
2998
|
}
|
|
2999
|
+
function isResponseOutputItemAddedReasoningChunk(chunk) {
|
|
3000
|
+
return isResponseOutputItemAddedChunk(chunk) && chunk.item.type === "reasoning";
|
|
3001
|
+
}
|
|
2957
3002
|
function isResponseAnnotationAddedChunk(chunk) {
|
|
2958
3003
|
return chunk.type === "response.output_text.annotation.added";
|
|
2959
3004
|
}
|
|
3005
|
+
function isResponseReasoningSummaryPartAddedChunk(chunk) {
|
|
3006
|
+
return chunk.type === "response.reasoning_summary_part.added";
|
|
3007
|
+
}
|
|
2960
3008
|
function isResponseReasoningSummaryTextDeltaChunk(chunk) {
|
|
2961
3009
|
return chunk.type === "response.reasoning_summary_text.delta";
|
|
2962
3010
|
}
|