@zenning/openai 1.4.5 → 1.4.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/dist/index.js +327 -196
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +327 -196
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.js +327 -196
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +327 -196
- package/internal/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/internal/dist/index.js
CHANGED
|
@@ -2700,37 +2700,58 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2700
2700
|
}
|
|
2701
2701
|
}
|
|
2702
2702
|
const reasoningSummary = (_b = (_a15 = response.output.find((item) => item.type === "reasoning")) == null ? void 0 : _a15.summary) != null ? _b : null;
|
|
2703
|
-
|
|
2703
|
+
const allAnnotations = outputTextElements.flatMap((content) => content.annotations);
|
|
2704
|
+
console.log("\u{1F4CB} Processing annotations in doGenerate:", JSON.stringify({
|
|
2704
2705
|
msg: "ai-sdk: content annotations",
|
|
2705
|
-
|
|
2706
|
-
|
|
2706
|
+
count: allAnnotations.length,
|
|
2707
|
+
annotations: allAnnotations
|
|
2708
|
+
}, null, 2));
|
|
2707
2709
|
return {
|
|
2708
2710
|
text: outputTextElements.map((content) => content.text).join("\n"),
|
|
2709
2711
|
sources: outputTextElements.flatMap(
|
|
2710
2712
|
(content) => content.annotations.map((annotation) => {
|
|
2711
|
-
var _a16, _b2, _c2, _d2, _e2, _f2, _g2, _h, _i;
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2713
|
+
var _a16, _b2, _c2, _d2, _e2, _f2, _g2, _h, _i, _j, _k, _l;
|
|
2714
|
+
console.log("\u{1F517} Processing annotation for source:", JSON.stringify(annotation, null, 2));
|
|
2715
|
+
try {
|
|
2716
|
+
if (annotation.type === "url_citation") {
|
|
2717
|
+
const urlSource = {
|
|
2718
|
+
sourceType: "url",
|
|
2719
|
+
id: (_c2 = (_b2 = (_a16 = this.config).generateId) == null ? void 0 : _b2.call(_a16)) != null ? _c2 : (0, import_provider_utils10.generateId)(),
|
|
2720
|
+
url: annotation.url,
|
|
2721
|
+
title: annotation.title
|
|
2722
|
+
};
|
|
2723
|
+
console.log("\u2705 Created URL source:", JSON.stringify(urlSource, null, 2));
|
|
2724
|
+
return urlSource;
|
|
2725
|
+
} else if (annotation.type === "file_citation") {
|
|
2726
|
+
const documentSource = {
|
|
2727
|
+
sourceType: "document",
|
|
2728
|
+
id: (_f2 = (_e2 = (_d2 = this.config).generateId) == null ? void 0 : _e2.call(_d2)) != null ? _f2 : (0, import_provider_utils10.generateId)(),
|
|
2729
|
+
mediaType: "text/plain",
|
|
2730
|
+
title: annotation.quote || annotation.filename || "Document",
|
|
2731
|
+
filename: annotation.filename,
|
|
2732
|
+
quote: annotation.quote
|
|
2733
|
+
};
|
|
2734
|
+
console.log("\u{1F4C4} Created document source:", JSON.stringify(documentSource, null, 2));
|
|
2735
|
+
return documentSource;
|
|
2736
|
+
} else {
|
|
2737
|
+
console.log("\u26A0\uFE0F Unknown annotation type in doGenerate:", annotation.type);
|
|
2738
|
+
return {
|
|
2739
|
+
sourceType: "url",
|
|
2740
|
+
id: (_i = (_h = (_g2 = this.config).generateId) == null ? void 0 : _h.call(_g2)) != null ? _i : (0, import_provider_utils10.generateId)(),
|
|
2741
|
+
url: "",
|
|
2742
|
+
title: "Unknown Source"
|
|
2743
|
+
};
|
|
2744
|
+
}
|
|
2745
|
+
} catch (error) {
|
|
2746
|
+
console.error("\u274C Error creating source in doGenerate:", {
|
|
2747
|
+
annotation,
|
|
2748
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2749
|
+
});
|
|
2729
2750
|
return {
|
|
2730
2751
|
sourceType: "url",
|
|
2731
|
-
id: (
|
|
2752
|
+
id: (_l = (_k = (_j = this.config).generateId) == null ? void 0 : _k.call(_j)) != null ? _l : (0, import_provider_utils10.generateId)(),
|
|
2732
2753
|
url: "",
|
|
2733
|
-
title: "
|
|
2754
|
+
title: "Error Source"
|
|
2734
2755
|
};
|
|
2735
2756
|
}
|
|
2736
2757
|
})
|
|
@@ -2775,24 +2796,40 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2775
2796
|
};
|
|
2776
2797
|
}
|
|
2777
2798
|
async doStream(options) {
|
|
2799
|
+
console.log("\u{1F680} Starting doStream with options:", JSON.stringify({
|
|
2800
|
+
modelId: this.modelId,
|
|
2801
|
+
hasAbortSignal: !!options.abortSignal
|
|
2802
|
+
}, null, 2));
|
|
2778
2803
|
const { args: body, warnings } = this.getArgs(options);
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
})
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2804
|
+
console.log("\u{1F4E4} Request body:", JSON.stringify(body, null, 2));
|
|
2805
|
+
let response;
|
|
2806
|
+
let responseHeaders;
|
|
2807
|
+
try {
|
|
2808
|
+
console.log("\u{1F4E1} Making API request...");
|
|
2809
|
+
const result = await (0, import_provider_utils10.postJsonToApi)({
|
|
2810
|
+
url: this.config.url({
|
|
2811
|
+
path: "/responses",
|
|
2812
|
+
modelId: this.modelId
|
|
2813
|
+
}),
|
|
2814
|
+
headers: (0, import_provider_utils10.combineHeaders)(this.config.headers(), options.headers),
|
|
2815
|
+
body: {
|
|
2816
|
+
...body,
|
|
2817
|
+
stream: true
|
|
2818
|
+
},
|
|
2819
|
+
failedResponseHandler: openaiFailedResponseHandler,
|
|
2820
|
+
successfulResponseHandler: (0, import_provider_utils10.createEventSourceResponseHandler)(
|
|
2821
|
+
openaiResponsesChunkSchema
|
|
2822
|
+
),
|
|
2823
|
+
abortSignal: options.abortSignal,
|
|
2824
|
+
fetch: this.config.fetch
|
|
2825
|
+
});
|
|
2826
|
+
response = result.value;
|
|
2827
|
+
responseHeaders = result.responseHeaders;
|
|
2828
|
+
console.log("\u2705 API request successful, starting stream processing");
|
|
2829
|
+
} catch (error) {
|
|
2830
|
+
console.error("\u274C API request failed:", error);
|
|
2831
|
+
throw error;
|
|
2832
|
+
}
|
|
2796
2833
|
const self = this;
|
|
2797
2834
|
let finishReason = "unknown";
|
|
2798
2835
|
let promptTokens = NaN;
|
|
@@ -2807,173 +2844,221 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
2807
2844
|
new TransformStream({
|
|
2808
2845
|
transform(chunk, controller) {
|
|
2809
2846
|
var _a15, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
};
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2847
|
+
try {
|
|
2848
|
+
console.log("\u{1F4E6} Processing chunk:", JSON.stringify(chunk, null, 2));
|
|
2849
|
+
if (!chunk.success) {
|
|
2850
|
+
console.error("\u274C Chunk parsing failed:", chunk.error);
|
|
2851
|
+
finishReason = "error";
|
|
2852
|
+
controller.enqueue({ type: "error", error: chunk.error });
|
|
2853
|
+
return;
|
|
2854
|
+
}
|
|
2855
|
+
const value = chunk.value;
|
|
2856
|
+
console.log("\u{1F4E5} Chunk value type:", value.type);
|
|
2857
|
+
if (isResponseOutputItemAddedChunk(value)) {
|
|
2858
|
+
console.log("\u{1F4DD} Output item added:", JSON.stringify(value, null, 2));
|
|
2859
|
+
if (value.item.type === "function_call") {
|
|
2860
|
+
ongoingToolCalls[value.output_index] = {
|
|
2861
|
+
toolName: value.item.name,
|
|
2862
|
+
toolCallId: value.item.call_id
|
|
2863
|
+
};
|
|
2864
|
+
controller.enqueue({
|
|
2865
|
+
type: "tool-call-delta",
|
|
2866
|
+
toolCallType: "function",
|
|
2867
|
+
toolCallId: value.item.call_id,
|
|
2868
|
+
toolName: value.item.name,
|
|
2869
|
+
argsTextDelta: value.item.arguments
|
|
2870
|
+
});
|
|
2871
|
+
} else if (value.item.type === "web_search_call") {
|
|
2872
|
+
ongoingToolCalls[value.output_index] = {
|
|
2873
|
+
toolName: "web_search_preview",
|
|
2874
|
+
toolCallId: value.item.id
|
|
2875
|
+
};
|
|
2876
|
+
controller.enqueue({
|
|
2877
|
+
type: "tool-call-delta",
|
|
2878
|
+
toolCallType: "function",
|
|
2879
|
+
toolCallId: value.item.id,
|
|
2880
|
+
toolName: "web_search_preview",
|
|
2881
|
+
argsTextDelta: JSON.stringify({ action: value.item.action })
|
|
2882
|
+
});
|
|
2883
|
+
} else if (value.item.type === "computer_call") {
|
|
2884
|
+
ongoingToolCalls[value.output_index] = {
|
|
2885
|
+
toolName: "computer_use",
|
|
2886
|
+
toolCallId: value.item.id
|
|
2887
|
+
};
|
|
2888
|
+
controller.enqueue({
|
|
2889
|
+
type: "tool-call-delta",
|
|
2890
|
+
toolCallType: "function",
|
|
2891
|
+
toolCallId: value.item.id,
|
|
2892
|
+
toolName: "computer_use",
|
|
2893
|
+
argsTextDelta: ""
|
|
2894
|
+
});
|
|
2895
|
+
} else if (value.item.type === "file_search_call") {
|
|
2896
|
+
ongoingToolCalls[value.output_index] = {
|
|
2897
|
+
toolName: "file_search",
|
|
2898
|
+
toolCallId: value.item.id
|
|
2899
|
+
};
|
|
2900
|
+
controller.enqueue({
|
|
2901
|
+
type: "tool-call-delta",
|
|
2902
|
+
toolCallType: "function",
|
|
2903
|
+
toolCallId: value.item.id,
|
|
2904
|
+
toolName: "file_search",
|
|
2905
|
+
argsTextDelta: ""
|
|
2906
|
+
});
|
|
2907
|
+
}
|
|
2908
|
+
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
2909
|
+
console.log("\u{1F527} Function call arguments delta:", JSON.stringify(value, null, 2));
|
|
2910
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
2911
|
+
if (toolCall != null) {
|
|
2912
|
+
controller.enqueue({
|
|
2913
|
+
type: "tool-call-delta",
|
|
2914
|
+
toolCallType: "function",
|
|
2915
|
+
toolCallId: toolCall.toolCallId,
|
|
2916
|
+
toolName: toolCall.toolName,
|
|
2917
|
+
argsTextDelta: value.delta
|
|
2918
|
+
});
|
|
2919
|
+
}
|
|
2920
|
+
} else if (isResponseCreatedChunk(value)) {
|
|
2921
|
+
console.log("\u{1F680} Response created:", JSON.stringify(value, null, 2));
|
|
2922
|
+
responseId = value.response.id;
|
|
2834
2923
|
controller.enqueue({
|
|
2835
|
-
type: "
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
argsTextDelta: JSON.stringify({ action: value.item.action })
|
|
2924
|
+
type: "response-metadata",
|
|
2925
|
+
id: value.response.id,
|
|
2926
|
+
timestamp: new Date(value.response.created_at * 1e3),
|
|
2927
|
+
modelId: value.response.model
|
|
2840
2928
|
});
|
|
2841
|
-
} else if (value
|
|
2842
|
-
|
|
2843
|
-
toolName: "computer_use",
|
|
2844
|
-
toolCallId: value.item.id
|
|
2845
|
-
};
|
|
2929
|
+
} else if (isTextDeltaChunk(value)) {
|
|
2930
|
+
console.log("\u{1F4DD} Text delta chunk:", JSON.stringify(value, null, 2));
|
|
2846
2931
|
controller.enqueue({
|
|
2847
|
-
type: "
|
|
2848
|
-
|
|
2849
|
-
toolCallId: value.item.id,
|
|
2850
|
-
toolName: "computer_use",
|
|
2851
|
-
argsTextDelta: ""
|
|
2932
|
+
type: "text-delta",
|
|
2933
|
+
textDelta: value.delta
|
|
2852
2934
|
});
|
|
2853
|
-
} else if (value
|
|
2854
|
-
|
|
2855
|
-
toolName: "file_search",
|
|
2856
|
-
toolCallId: value.item.id
|
|
2857
|
-
};
|
|
2935
|
+
} else if (isResponseReasoningSummaryTextDeltaChunk(value)) {
|
|
2936
|
+
console.log("\u{1F9E0} Reasoning summary delta:", JSON.stringify(value, null, 2));
|
|
2858
2937
|
controller.enqueue({
|
|
2859
|
-
type: "
|
|
2860
|
-
|
|
2861
|
-
toolCallId: value.item.id,
|
|
2862
|
-
toolName: "file_search",
|
|
2863
|
-
argsTextDelta: ""
|
|
2938
|
+
type: "reasoning",
|
|
2939
|
+
textDelta: value.delta
|
|
2864
2940
|
});
|
|
2865
|
-
}
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2941
|
+
} else if (isResponseOutputItemDoneChunk(value)) {
|
|
2942
|
+
console.log("\u2705 Output item done:", JSON.stringify(value, null, 2));
|
|
2943
|
+
if (value.item.type === "function_call") {
|
|
2944
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2945
|
+
hasToolCalls = true;
|
|
2946
|
+
controller.enqueue({
|
|
2947
|
+
type: "tool-call",
|
|
2948
|
+
toolCallType: "function",
|
|
2949
|
+
toolCallId: value.item.call_id,
|
|
2950
|
+
toolName: value.item.name,
|
|
2951
|
+
args: value.item.arguments
|
|
2952
|
+
});
|
|
2953
|
+
} else if (value.item.type === "web_search_call") {
|
|
2954
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2955
|
+
hasToolCalls = true;
|
|
2956
|
+
controller.enqueue({
|
|
2957
|
+
type: "tool-call",
|
|
2958
|
+
toolCallType: "function",
|
|
2959
|
+
toolCallId: value.item.id,
|
|
2960
|
+
toolName: "web_search_preview",
|
|
2961
|
+
args: JSON.stringify({ action: value.item.action })
|
|
2962
|
+
});
|
|
2963
|
+
} else if (value.item.type === "computer_call") {
|
|
2964
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2965
|
+
hasToolCalls = true;
|
|
2966
|
+
controller.enqueue({
|
|
2967
|
+
type: "tool-call",
|
|
2968
|
+
toolCallType: "function",
|
|
2969
|
+
toolCallId: value.item.id,
|
|
2970
|
+
toolName: "computer_use",
|
|
2971
|
+
args: ""
|
|
2972
|
+
});
|
|
2973
|
+
} else if (value.item.type === "file_search_call") {
|
|
2974
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
2975
|
+
hasToolCalls = true;
|
|
2976
|
+
controller.enqueue({
|
|
2977
|
+
type: "tool-call",
|
|
2978
|
+
toolCallType: "function",
|
|
2979
|
+
toolCallId: value.item.id,
|
|
2980
|
+
toolName: "file_search",
|
|
2981
|
+
args: JSON.stringify({
|
|
2982
|
+
queries: value.item.queries,
|
|
2983
|
+
results: value.item.results
|
|
2984
|
+
})
|
|
2985
|
+
});
|
|
2986
|
+
}
|
|
2987
|
+
} else if (isResponseFinishedChunk(value)) {
|
|
2988
|
+
console.log("\u{1F3C1} Response finished:", JSON.stringify(value, null, 2));
|
|
2989
|
+
finishReason = mapOpenAIResponseFinishReason({
|
|
2990
|
+
finishReason: (_a15 = value.response.incomplete_details) == null ? void 0 : _a15.reason,
|
|
2991
|
+
hasToolCalls
|
|
2875
2992
|
});
|
|
2993
|
+
promptTokens = value.response.usage.input_tokens;
|
|
2994
|
+
completionTokens = value.response.usage.output_tokens;
|
|
2995
|
+
cachedPromptTokens = (_c = (_b = value.response.usage.input_tokens_details) == null ? void 0 : _b.cached_tokens) != null ? _c : cachedPromptTokens;
|
|
2996
|
+
reasoningTokens = (_e = (_d = value.response.usage.output_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : reasoningTokens;
|
|
2997
|
+
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2998
|
+
console.log("\u{1F50D} Processing annotation chunk:", JSON.stringify({
|
|
2999
|
+
type: value.type,
|
|
3000
|
+
annotation: value.annotation
|
|
3001
|
+
}, null, 2));
|
|
3002
|
+
try {
|
|
3003
|
+
if (value.annotation.type === "url_citation") {
|
|
3004
|
+
const urlSource = {
|
|
3005
|
+
sourceType: "url",
|
|
3006
|
+
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils10.generateId)(),
|
|
3007
|
+
url: value.annotation.url,
|
|
3008
|
+
title: value.annotation.title
|
|
3009
|
+
};
|
|
3010
|
+
console.log("\u2705 Creating URL source:", JSON.stringify(urlSource, null, 2));
|
|
3011
|
+
controller.enqueue({
|
|
3012
|
+
type: "source",
|
|
3013
|
+
source: urlSource
|
|
3014
|
+
});
|
|
3015
|
+
console.log("\u2705 URL source enqueued successfully");
|
|
3016
|
+
} else if (value.annotation.type === "file_citation") {
|
|
3017
|
+
const documentSource = {
|
|
3018
|
+
sourceType: "document",
|
|
3019
|
+
id: (_k = (_j = (_i = self.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : (0, import_provider_utils10.generateId)(),
|
|
3020
|
+
mediaType: "text/plain",
|
|
3021
|
+
title: value.annotation.quote || value.annotation.filename || "Document",
|
|
3022
|
+
filename: value.annotation.filename,
|
|
3023
|
+
quote: value.annotation.quote
|
|
3024
|
+
};
|
|
3025
|
+
console.log("\u{1F4C4} Creating document source:", JSON.stringify(documentSource, null, 2));
|
|
3026
|
+
controller.enqueue({
|
|
3027
|
+
type: "source",
|
|
3028
|
+
source: documentSource
|
|
3029
|
+
});
|
|
3030
|
+
console.log("\u2705 Document source enqueued successfully");
|
|
3031
|
+
} else {
|
|
3032
|
+
console.log("\u26A0\uFE0F Unknown annotation type:", value.annotation.type);
|
|
3033
|
+
}
|
|
3034
|
+
} catch (error) {
|
|
3035
|
+
console.error("\u274C Error processing annotation:", {
|
|
3036
|
+
annotation: value.annotation,
|
|
3037
|
+
error: error instanceof Error ? error.message : String(error),
|
|
3038
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
3039
|
+
});
|
|
3040
|
+
}
|
|
3041
|
+
} else if (isResponseInProgressChunk(value)) {
|
|
3042
|
+
console.log("\u23F3 Response in progress (ignored):", value.type);
|
|
3043
|
+
} else if (isResponseContentPartAddedChunk(value)) {
|
|
3044
|
+
console.log("\u{1F4DD} Content part added (ignored):", value.type);
|
|
3045
|
+
} else if (isResponseOutputTextDoneChunk(value)) {
|
|
3046
|
+
console.log("\u2705 Output text done (ignored):", value.type);
|
|
3047
|
+
} else if (isResponseContentPartDoneChunk(value)) {
|
|
3048
|
+
console.log("\u2705 Content part done (ignored):", value.type);
|
|
3049
|
+
} else {
|
|
3050
|
+
console.log("\u2753 Unhandled chunk type:", value.type, JSON.stringify(value, null, 2));
|
|
2876
3051
|
}
|
|
2877
|
-
}
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
id: value.response.id,
|
|
2882
|
-
timestamp: new Date(value.response.created_at * 1e3),
|
|
2883
|
-
modelId: value.response.model
|
|
2884
|
-
});
|
|
2885
|
-
} else if (isTextDeltaChunk(value)) {
|
|
2886
|
-
controller.enqueue({
|
|
2887
|
-
type: "text-delta",
|
|
2888
|
-
textDelta: value.delta
|
|
3052
|
+
} catch (error) {
|
|
3053
|
+
console.error("\u{1F4A5} FATAL ERROR in chunk processing:", {
|
|
3054
|
+
error: error instanceof Error ? error.message : String(error),
|
|
3055
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
2889
3056
|
});
|
|
2890
|
-
|
|
3057
|
+
finishReason = "error";
|
|
2891
3058
|
controller.enqueue({
|
|
2892
|
-
type: "
|
|
2893
|
-
|
|
2894
|
-
});
|
|
2895
|
-
} else if (isResponseOutputItemDoneChunk(value)) {
|
|
2896
|
-
if (value.item.type === "function_call") {
|
|
2897
|
-
ongoingToolCalls[value.output_index] = void 0;
|
|
2898
|
-
hasToolCalls = true;
|
|
2899
|
-
controller.enqueue({
|
|
2900
|
-
type: "tool-call",
|
|
2901
|
-
toolCallType: "function",
|
|
2902
|
-
toolCallId: value.item.call_id,
|
|
2903
|
-
toolName: value.item.name,
|
|
2904
|
-
args: value.item.arguments
|
|
2905
|
-
});
|
|
2906
|
-
} else if (value.item.type === "web_search_call") {
|
|
2907
|
-
ongoingToolCalls[value.output_index] = void 0;
|
|
2908
|
-
hasToolCalls = true;
|
|
2909
|
-
controller.enqueue({
|
|
2910
|
-
type: "tool-call",
|
|
2911
|
-
toolCallType: "function",
|
|
2912
|
-
toolCallId: value.item.id,
|
|
2913
|
-
toolName: "web_search_preview",
|
|
2914
|
-
args: JSON.stringify({ action: value.item.action })
|
|
2915
|
-
});
|
|
2916
|
-
} else if (value.item.type === "computer_call") {
|
|
2917
|
-
ongoingToolCalls[value.output_index] = void 0;
|
|
2918
|
-
hasToolCalls = true;
|
|
2919
|
-
controller.enqueue({
|
|
2920
|
-
type: "tool-call",
|
|
2921
|
-
toolCallType: "function",
|
|
2922
|
-
toolCallId: value.item.id,
|
|
2923
|
-
toolName: "computer_use",
|
|
2924
|
-
args: ""
|
|
2925
|
-
});
|
|
2926
|
-
} else if (value.item.type === "file_search_call") {
|
|
2927
|
-
ongoingToolCalls[value.output_index] = void 0;
|
|
2928
|
-
hasToolCalls = true;
|
|
2929
|
-
controller.enqueue({
|
|
2930
|
-
type: "tool-call",
|
|
2931
|
-
toolCallType: "function",
|
|
2932
|
-
toolCallId: value.item.id,
|
|
2933
|
-
toolName: "file_search",
|
|
2934
|
-
args: JSON.stringify({
|
|
2935
|
-
queries: value.item.queries,
|
|
2936
|
-
results: value.item.results
|
|
2937
|
-
})
|
|
2938
|
-
});
|
|
2939
|
-
}
|
|
2940
|
-
} else if (isResponseFinishedChunk(value)) {
|
|
2941
|
-
finishReason = mapOpenAIResponseFinishReason({
|
|
2942
|
-
finishReason: (_a15 = value.response.incomplete_details) == null ? void 0 : _a15.reason,
|
|
2943
|
-
hasToolCalls
|
|
3059
|
+
type: "error",
|
|
3060
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
2944
3061
|
});
|
|
2945
|
-
promptTokens = value.response.usage.input_tokens;
|
|
2946
|
-
completionTokens = value.response.usage.output_tokens;
|
|
2947
|
-
cachedPromptTokens = (_c = (_b = value.response.usage.input_tokens_details) == null ? void 0 : _b.cached_tokens) != null ? _c : cachedPromptTokens;
|
|
2948
|
-
reasoningTokens = (_e = (_d = value.response.usage.output_tokens_details) == null ? void 0 : _d.reasoning_tokens) != null ? _e : reasoningTokens;
|
|
2949
|
-
} else if (isResponseAnnotationAddedChunk(value)) {
|
|
2950
|
-
console.log(JSON.stringify({
|
|
2951
|
-
msg: "ai-sdk: source (stream)",
|
|
2952
|
-
source: value.annotation
|
|
2953
|
-
}));
|
|
2954
|
-
if (value.annotation.type === "url_citation") {
|
|
2955
|
-
controller.enqueue({
|
|
2956
|
-
type: "source",
|
|
2957
|
-
source: {
|
|
2958
|
-
sourceType: "url",
|
|
2959
|
-
id: (_h = (_g = (_f = self.config).generateId) == null ? void 0 : _g.call(_f)) != null ? _h : (0, import_provider_utils10.generateId)(),
|
|
2960
|
-
url: value.annotation.url,
|
|
2961
|
-
title: value.annotation.title
|
|
2962
|
-
}
|
|
2963
|
-
});
|
|
2964
|
-
} else if (value.annotation.type === "file_citation") {
|
|
2965
|
-
controller.enqueue({
|
|
2966
|
-
type: "source",
|
|
2967
|
-
source: {
|
|
2968
|
-
sourceType: "document",
|
|
2969
|
-
id: (_k = (_j = (_i = self.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : (0, import_provider_utils10.generateId)(),
|
|
2970
|
-
mediaType: "text/plain",
|
|
2971
|
-
title: value.annotation.quote || value.annotation.filename || "Document",
|
|
2972
|
-
filename: value.annotation.filename,
|
|
2973
|
-
quote: value.annotation.quote
|
|
2974
|
-
}
|
|
2975
|
-
});
|
|
2976
|
-
}
|
|
2977
3062
|
}
|
|
2978
3063
|
},
|
|
2979
3064
|
flush(controller) {
|
|
@@ -3165,6 +3250,36 @@ var responseReasoningSummaryTextDeltaSchema = import_zod12.z.object({
|
|
|
3165
3250
|
summary_index: import_zod12.z.number(),
|
|
3166
3251
|
delta: import_zod12.z.string()
|
|
3167
3252
|
});
|
|
3253
|
+
var responseInProgressChunkSchema = import_zod12.z.object({
|
|
3254
|
+
type: import_zod12.z.literal("response.in_progress"),
|
|
3255
|
+
sequence_number: import_zod12.z.number(),
|
|
3256
|
+
response: import_zod12.z.any()
|
|
3257
|
+
});
|
|
3258
|
+
var responseContentPartAddedChunkSchema = import_zod12.z.object({
|
|
3259
|
+
type: import_zod12.z.literal("response.content_part.added"),
|
|
3260
|
+
sequence_number: import_zod12.z.number(),
|
|
3261
|
+
item_id: import_zod12.z.string(),
|
|
3262
|
+
output_index: import_zod12.z.number(),
|
|
3263
|
+
content_index: import_zod12.z.number(),
|
|
3264
|
+
part: import_zod12.z.any()
|
|
3265
|
+
});
|
|
3266
|
+
var responseOutputTextDoneChunkSchema = import_zod12.z.object({
|
|
3267
|
+
type: import_zod12.z.literal("response.output_text.done"),
|
|
3268
|
+
sequence_number: import_zod12.z.number(),
|
|
3269
|
+
item_id: import_zod12.z.string(),
|
|
3270
|
+
output_index: import_zod12.z.number(),
|
|
3271
|
+
content_index: import_zod12.z.number(),
|
|
3272
|
+
text: import_zod12.z.string(),
|
|
3273
|
+
logprobs: import_zod12.z.array(import_zod12.z.any()).optional()
|
|
3274
|
+
});
|
|
3275
|
+
var responseContentPartDoneChunkSchema = import_zod12.z.object({
|
|
3276
|
+
type: import_zod12.z.literal("response.content_part.done"),
|
|
3277
|
+
sequence_number: import_zod12.z.number(),
|
|
3278
|
+
item_id: import_zod12.z.string(),
|
|
3279
|
+
output_index: import_zod12.z.number(),
|
|
3280
|
+
content_index: import_zod12.z.number(),
|
|
3281
|
+
part: import_zod12.z.any()
|
|
3282
|
+
});
|
|
3168
3283
|
var openaiResponsesChunkSchema = import_zod12.z.union([
|
|
3169
3284
|
textDeltaChunkSchema,
|
|
3170
3285
|
responseFinishedChunkSchema,
|
|
@@ -3174,6 +3289,10 @@ var openaiResponsesChunkSchema = import_zod12.z.union([
|
|
|
3174
3289
|
responseOutputItemAddedSchema,
|
|
3175
3290
|
responseAnnotationAddedSchema,
|
|
3176
3291
|
responseReasoningSummaryTextDeltaSchema,
|
|
3292
|
+
responseInProgressChunkSchema,
|
|
3293
|
+
responseContentPartAddedChunkSchema,
|
|
3294
|
+
responseOutputTextDoneChunkSchema,
|
|
3295
|
+
responseContentPartDoneChunkSchema,
|
|
3177
3296
|
import_zod12.z.object({ type: import_zod12.z.string() }).passthrough()
|
|
3178
3297
|
// fallback for unknown chunks
|
|
3179
3298
|
]);
|
|
@@ -3201,6 +3320,18 @@ function isResponseAnnotationAddedChunk(chunk) {
|
|
|
3201
3320
|
function isResponseReasoningSummaryTextDeltaChunk(chunk) {
|
|
3202
3321
|
return chunk.type === "response.reasoning_summary_text.delta";
|
|
3203
3322
|
}
|
|
3323
|
+
function isResponseInProgressChunk(chunk) {
|
|
3324
|
+
return chunk.type === "response.in_progress";
|
|
3325
|
+
}
|
|
3326
|
+
function isResponseContentPartAddedChunk(chunk) {
|
|
3327
|
+
return chunk.type === "response.content_part.added";
|
|
3328
|
+
}
|
|
3329
|
+
function isResponseOutputTextDoneChunk(chunk) {
|
|
3330
|
+
return chunk.type === "response.output_text.done";
|
|
3331
|
+
}
|
|
3332
|
+
function isResponseContentPartDoneChunk(chunk) {
|
|
3333
|
+
return chunk.type === "response.content_part.done";
|
|
3334
|
+
}
|
|
3204
3335
|
function getResponsesModelConfig(modelId) {
|
|
3205
3336
|
if (modelId.startsWith("o")) {
|
|
3206
3337
|
if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
|