@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/internal/index.mjs
CHANGED
|
@@ -288,7 +288,7 @@ var openaiProviderOptions = z.object({
|
|
|
288
288
|
/**
|
|
289
289
|
* Whether to use strict JSON schema validation.
|
|
290
290
|
*
|
|
291
|
-
* @default
|
|
291
|
+
* @default false
|
|
292
292
|
*/
|
|
293
293
|
strictJsonSchema: z.boolean().optional()
|
|
294
294
|
});
|
|
@@ -2232,6 +2232,16 @@ function prepareResponsesTools({
|
|
|
2232
2232
|
break;
|
|
2233
2233
|
case "provider-defined":
|
|
2234
2234
|
switch (tool.id) {
|
|
2235
|
+
case "openai.file_search": {
|
|
2236
|
+
const args = fileSearchArgsSchema.parse(tool.args);
|
|
2237
|
+
openaiTools.push({
|
|
2238
|
+
type: "file_search",
|
|
2239
|
+
vector_store_ids: args.vectorStoreIds,
|
|
2240
|
+
max_results: args.maxResults,
|
|
2241
|
+
search_type: args.searchType
|
|
2242
|
+
});
|
|
2243
|
+
break;
|
|
2244
|
+
}
|
|
2235
2245
|
case "openai.web_search_preview":
|
|
2236
2246
|
openaiTools.push({
|
|
2237
2247
|
type: "web_search_preview",
|
|
@@ -2261,7 +2271,7 @@ function prepareResponsesTools({
|
|
|
2261
2271
|
case "tool":
|
|
2262
2272
|
return {
|
|
2263
2273
|
tools: openaiTools,
|
|
2264
|
-
toolChoice: toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
|
|
2274
|
+
toolChoice: toolChoice.toolName === "file_search" ? { type: "file_search" } : toolChoice.toolName === "web_search_preview" ? { type: "web_search_preview" } : { type: "function", name: toolChoice.toolName },
|
|
2265
2275
|
toolWarnings
|
|
2266
2276
|
};
|
|
2267
2277
|
default: {
|
|
@@ -2676,6 +2686,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2676
2686
|
let responseId = null;
|
|
2677
2687
|
const ongoingToolCalls = {};
|
|
2678
2688
|
let hasToolCalls = false;
|
|
2689
|
+
const activeReasoning = {};
|
|
2679
2690
|
return {
|
|
2680
2691
|
stream: response.pipeThrough(
|
|
2681
2692
|
new TransformStream({
|
|
@@ -2683,7 +2694,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2683
2694
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2684
2695
|
},
|
|
2685
2696
|
transform(chunk, controller) {
|
|
2686
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2697
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
2687
2698
|
if (options.includeRawChunks) {
|
|
2688
2699
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2689
2700
|
}
|
|
@@ -2729,10 +2740,14 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2729
2740
|
type: "text-start",
|
|
2730
2741
|
id: value.item.id
|
|
2731
2742
|
});
|
|
2732
|
-
} else if (value
|
|
2743
|
+
} else if (isResponseOutputItemAddedReasoningChunk(value)) {
|
|
2744
|
+
activeReasoning[value.item.id] = {
|
|
2745
|
+
encryptedContent: value.item.encrypted_content,
|
|
2746
|
+
summaryParts: [0]
|
|
2747
|
+
};
|
|
2733
2748
|
controller.enqueue({
|
|
2734
2749
|
type: "reasoning-start",
|
|
2735
|
-
id: value.item.id
|
|
2750
|
+
id: `${value.item.id}:0`,
|
|
2736
2751
|
providerMetadata: {
|
|
2737
2752
|
openai: {
|
|
2738
2753
|
reasoning: {
|
|
@@ -2810,19 +2825,23 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2810
2825
|
type: "text-end",
|
|
2811
2826
|
id: value.item.id
|
|
2812
2827
|
});
|
|
2813
|
-
} else if (value
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2828
|
+
} else if (isResponseOutputItemDoneReasoningChunk(value)) {
|
|
2829
|
+
const activeReasoningPart = activeReasoning[value.item.id];
|
|
2830
|
+
for (const summaryIndex of activeReasoningPart.summaryParts) {
|
|
2831
|
+
controller.enqueue({
|
|
2832
|
+
type: "reasoning-end",
|
|
2833
|
+
id: `${value.item.id}:${summaryIndex}`,
|
|
2834
|
+
providerMetadata: {
|
|
2835
|
+
openai: {
|
|
2836
|
+
reasoning: {
|
|
2837
|
+
id: value.item.id,
|
|
2838
|
+
encryptedContent: (_b = value.item.encrypted_content) != null ? _b : null
|
|
2839
|
+
}
|
|
2822
2840
|
}
|
|
2823
2841
|
}
|
|
2824
|
-
}
|
|
2825
|
-
}
|
|
2842
|
+
});
|
|
2843
|
+
}
|
|
2844
|
+
delete activeReasoning[value.item.id];
|
|
2826
2845
|
}
|
|
2827
2846
|
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
2828
2847
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
@@ -2847,27 +2866,52 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2847
2866
|
id: value.item_id,
|
|
2848
2867
|
delta: value.delta
|
|
2849
2868
|
});
|
|
2869
|
+
} else if (isResponseReasoningSummaryPartAddedChunk(value)) {
|
|
2870
|
+
if (value.summary_index > 0) {
|
|
2871
|
+
(_c = activeReasoning[value.item_id]) == null ? void 0 : _c.summaryParts.push(
|
|
2872
|
+
value.summary_index
|
|
2873
|
+
);
|
|
2874
|
+
controller.enqueue({
|
|
2875
|
+
type: "reasoning-start",
|
|
2876
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
2877
|
+
providerMetadata: {
|
|
2878
|
+
openai: {
|
|
2879
|
+
reasoning: {
|
|
2880
|
+
id: value.item_id,
|
|
2881
|
+
encryptedContent: (_e = (_d = activeReasoning[value.item_id]) == null ? void 0 : _d.encryptedContent) != null ? _e : null
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
});
|
|
2886
|
+
}
|
|
2850
2887
|
} else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
|
|
2851
2888
|
controller.enqueue({
|
|
2852
2889
|
type: "reasoning-delta",
|
|
2853
|
-
id: value.item_id
|
|
2854
|
-
delta: value.delta
|
|
2890
|
+
id: `${value.item_id}:${value.summary_index}`,
|
|
2891
|
+
delta: value.delta,
|
|
2892
|
+
providerMetadata: {
|
|
2893
|
+
openai: {
|
|
2894
|
+
reasoning: {
|
|
2895
|
+
id: value.item_id
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
}
|
|
2855
2899
|
});
|
|
2856
2900
|
} else if (isResponseFinishedChunk(value)) {
|
|
2857
2901
|
finishReason = mapOpenAIResponseFinishReason({
|
|
2858
|
-
finishReason: (
|
|
2902
|
+
finishReason: (_f = value.response.incomplete_details) == null ? void 0 : _f.reason,
|
|
2859
2903
|
hasToolCalls
|
|
2860
2904
|
});
|
|
2861
2905
|
usage.inputTokens = value.response.usage.input_tokens;
|
|
2862
2906
|
usage.outputTokens = value.response.usage.output_tokens;
|
|
2863
2907
|
usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens;
|
|
2864
|
-
usage.reasoningTokens = (
|
|
2865
|
-
usage.cachedInputTokens = (
|
|
2908
|
+
usage.reasoningTokens = (_h = (_g = value.response.usage.output_tokens_details) == null ? void 0 : _g.reasoning_tokens) != null ? _h : void 0;
|
|
2909
|
+
usage.cachedInputTokens = (_j = (_i = value.response.usage.input_tokens_details) == null ? void 0 : _i.cached_tokens) != null ? _j : void 0;
|
|
2866
2910
|
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2867
2911
|
controller.enqueue({
|
|
2868
2912
|
type: "source",
|
|
2869
2913
|
sourceType: "url",
|
|
2870
|
-
id: (
|
|
2914
|
+
id: (_m = (_l = (_k = self.config).generateId) == null ? void 0 : _l.call(_k)) != null ? _m : generateId2(),
|
|
2871
2915
|
url: value.annotation.url,
|
|
2872
2916
|
title: value.annotation.title
|
|
2873
2917
|
});
|
|
@@ -2938,13 +2982,7 @@ var responseOutputItemAddedSchema = z15.object({
|
|
|
2938
2982
|
z15.object({
|
|
2939
2983
|
type: z15.literal("reasoning"),
|
|
2940
2984
|
id: z15.string(),
|
|
2941
|
-
encrypted_content: z15.string().nullish()
|
|
2942
|
-
summary: z15.array(
|
|
2943
|
-
z15.object({
|
|
2944
|
-
type: z15.literal("summary_text"),
|
|
2945
|
-
text: z15.string()
|
|
2946
|
-
})
|
|
2947
|
-
)
|
|
2985
|
+
encrypted_content: z15.string().nullish()
|
|
2948
2986
|
}),
|
|
2949
2987
|
z15.object({
|
|
2950
2988
|
type: z15.literal("function_call"),
|
|
@@ -2976,13 +3014,7 @@ var responseOutputItemDoneSchema = z15.object({
|
|
|
2976
3014
|
z15.object({
|
|
2977
3015
|
type: z15.literal("reasoning"),
|
|
2978
3016
|
id: z15.string(),
|
|
2979
|
-
encrypted_content: z15.string().nullish()
|
|
2980
|
-
summary: z15.array(
|
|
2981
|
-
z15.object({
|
|
2982
|
-
type: z15.literal("summary_text"),
|
|
2983
|
-
text: z15.string()
|
|
2984
|
-
})
|
|
2985
|
-
)
|
|
3017
|
+
encrypted_content: z15.string().nullish()
|
|
2986
3018
|
}),
|
|
2987
3019
|
z15.object({
|
|
2988
3020
|
type: z15.literal("function_call"),
|
|
@@ -3018,9 +3050,15 @@ var responseAnnotationAddedSchema = z15.object({
|
|
|
3018
3050
|
title: z15.string()
|
|
3019
3051
|
})
|
|
3020
3052
|
});
|
|
3053
|
+
var responseReasoningSummaryPartAddedSchema = z15.object({
|
|
3054
|
+
type: z15.literal("response.reasoning_summary_part.added"),
|
|
3055
|
+
item_id: z15.string(),
|
|
3056
|
+
summary_index: z15.number()
|
|
3057
|
+
});
|
|
3021
3058
|
var responseReasoningSummaryTextDeltaSchema = z15.object({
|
|
3022
3059
|
type: z15.literal("response.reasoning_summary_text.delta"),
|
|
3023
3060
|
item_id: z15.string(),
|
|
3061
|
+
summary_index: z15.number(),
|
|
3024
3062
|
delta: z15.string()
|
|
3025
3063
|
});
|
|
3026
3064
|
var openaiResponsesChunkSchema = z15.union([
|
|
@@ -3031,6 +3069,7 @@ var openaiResponsesChunkSchema = z15.union([
|
|
|
3031
3069
|
responseOutputItemDoneSchema,
|
|
3032
3070
|
responseFunctionCallArgumentsDeltaSchema,
|
|
3033
3071
|
responseAnnotationAddedSchema,
|
|
3072
|
+
responseReasoningSummaryPartAddedSchema,
|
|
3034
3073
|
responseReasoningSummaryTextDeltaSchema,
|
|
3035
3074
|
errorChunkSchema,
|
|
3036
3075
|
z15.object({ type: z15.string() }).loose()
|
|
@@ -3042,6 +3081,9 @@ function isTextDeltaChunk(chunk) {
|
|
|
3042
3081
|
function isResponseOutputItemDoneChunk(chunk) {
|
|
3043
3082
|
return chunk.type === "response.output_item.done";
|
|
3044
3083
|
}
|
|
3084
|
+
function isResponseOutputItemDoneReasoningChunk(chunk) {
|
|
3085
|
+
return isResponseOutputItemDoneChunk(chunk) && chunk.item.type === "reasoning";
|
|
3086
|
+
}
|
|
3045
3087
|
function isResponseFinishedChunk(chunk) {
|
|
3046
3088
|
return chunk.type === "response.completed" || chunk.type === "response.incomplete";
|
|
3047
3089
|
}
|
|
@@ -3054,9 +3096,15 @@ function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
|
|
|
3054
3096
|
function isResponseOutputItemAddedChunk(chunk) {
|
|
3055
3097
|
return chunk.type === "response.output_item.added";
|
|
3056
3098
|
}
|
|
3099
|
+
function isResponseOutputItemAddedReasoningChunk(chunk) {
|
|
3100
|
+
return isResponseOutputItemAddedChunk(chunk) && chunk.item.type === "reasoning";
|
|
3101
|
+
}
|
|
3057
3102
|
function isResponseAnnotationAddedChunk(chunk) {
|
|
3058
3103
|
return chunk.type === "response.output_text.annotation.added";
|
|
3059
3104
|
}
|
|
3105
|
+
function isResponseReasoningSummaryPartAddedChunk(chunk) {
|
|
3106
|
+
return chunk.type === "response.reasoning_summary_part.added";
|
|
3107
|
+
}
|
|
3060
3108
|
function isResponseReasoningSummaryTextDeltaChunk(chunk) {
|
|
3061
3109
|
return chunk.type === "response.reasoning_summary_text.delta";
|
|
3062
3110
|
}
|