@zenning/ai 5.3.1 → 5.3.2
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 +43 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -8
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -802,7 +802,7 @@ function detectMediaType({
|
|
|
802
802
|
var import_provider_utils2 = require("@zenning/provider-utils");
|
|
803
803
|
|
|
804
804
|
// src/version.ts
|
|
805
|
-
var VERSION = true ? "5.3.
|
|
805
|
+
var VERSION = true ? "5.3.2" : "0.0.0-test";
|
|
806
806
|
|
|
807
807
|
// src/util/download/download.ts
|
|
808
808
|
var download = async ({ url }) => {
|
|
@@ -3508,7 +3508,8 @@ function createStreamingUIMessageState({
|
|
|
3508
3508
|
activeReasoningParts: {},
|
|
3509
3509
|
partialToolCalls: {},
|
|
3510
3510
|
isFinalized: false,
|
|
3511
|
-
messageQueue: []
|
|
3511
|
+
messageQueue: [],
|
|
3512
|
+
seenAnnotations: /* @__PURE__ */ new Set()
|
|
3512
3513
|
};
|
|
3513
3514
|
}
|
|
3514
3515
|
function processUIMessageStream({
|
|
@@ -3524,7 +3525,7 @@ function processUIMessageStream({
|
|
|
3524
3525
|
new TransformStream({
|
|
3525
3526
|
async transform(chunk, controller) {
|
|
3526
3527
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
3527
|
-
var _a17, _b
|
|
3528
|
+
var _a17, _b;
|
|
3528
3529
|
function getToolInvocation(toolCallId) {
|
|
3529
3530
|
const toolInvocations = state.message.parts.filter(isToolUIPart);
|
|
3530
3531
|
const toolInvocation = toolInvocations.find(
|
|
@@ -3628,12 +3629,39 @@ function processUIMessageStream({
|
|
|
3628
3629
|
state.message.metadata = mergedMetadata;
|
|
3629
3630
|
}
|
|
3630
3631
|
}
|
|
3632
|
+
function filterDuplicateAnnotations(providerMetadata) {
|
|
3633
|
+
var _a18;
|
|
3634
|
+
if (!((_a18 = providerMetadata == null ? void 0 : providerMetadata.openai) == null ? void 0 : _a18.annotations) || !state.seenAnnotations) {
|
|
3635
|
+
return providerMetadata;
|
|
3636
|
+
}
|
|
3637
|
+
const filtered = { ...providerMetadata };
|
|
3638
|
+
if (filtered.openai) {
|
|
3639
|
+
filtered.openai = { ...filtered.openai };
|
|
3640
|
+
const uniqueAnnotations = filtered.openai.annotations.filter((annotation) => {
|
|
3641
|
+
const key = JSON.stringify(annotation);
|
|
3642
|
+
if (state.seenAnnotations.has(key)) {
|
|
3643
|
+
return false;
|
|
3644
|
+
}
|
|
3645
|
+
state.seenAnnotations.add(key);
|
|
3646
|
+
return true;
|
|
3647
|
+
});
|
|
3648
|
+
if (uniqueAnnotations.length > 0) {
|
|
3649
|
+
filtered.openai.annotations = uniqueAnnotations;
|
|
3650
|
+
} else {
|
|
3651
|
+
delete filtered.openai.annotations;
|
|
3652
|
+
if (Object.keys(filtered.openai).length === 0) {
|
|
3653
|
+
delete filtered.openai;
|
|
3654
|
+
}
|
|
3655
|
+
}
|
|
3656
|
+
}
|
|
3657
|
+
return Object.keys(filtered).length > 0 ? filtered : void 0;
|
|
3658
|
+
}
|
|
3631
3659
|
switch (chunk.type) {
|
|
3632
3660
|
case "text-start": {
|
|
3633
3661
|
const textPart = {
|
|
3634
3662
|
type: "text",
|
|
3635
3663
|
text: "",
|
|
3636
|
-
providerMetadata: chunk.providerMetadata,
|
|
3664
|
+
providerMetadata: filterDuplicateAnnotations(chunk.providerMetadata),
|
|
3637
3665
|
state: "streaming"
|
|
3638
3666
|
};
|
|
3639
3667
|
state.activeTextParts[chunk.id] = textPart;
|
|
@@ -3644,14 +3672,20 @@ function processUIMessageStream({
|
|
|
3644
3672
|
case "text-delta": {
|
|
3645
3673
|
const textPart = state.activeTextParts[chunk.id];
|
|
3646
3674
|
textPart.text += chunk.delta;
|
|
3647
|
-
|
|
3675
|
+
const filteredMetadata = filterDuplicateAnnotations(chunk.providerMetadata);
|
|
3676
|
+
if (filteredMetadata && !textPart.providerMetadata) {
|
|
3677
|
+
textPart.providerMetadata = filteredMetadata;
|
|
3678
|
+
}
|
|
3648
3679
|
write();
|
|
3649
3680
|
break;
|
|
3650
3681
|
}
|
|
3651
3682
|
case "text-end": {
|
|
3652
3683
|
const textPart = state.activeTextParts[chunk.id];
|
|
3653
3684
|
textPart.state = "done";
|
|
3654
|
-
|
|
3685
|
+
const filteredMetadata = filterDuplicateAnnotations(chunk.providerMetadata);
|
|
3686
|
+
if (filteredMetadata && !textPart.providerMetadata) {
|
|
3687
|
+
textPart.providerMetadata = filteredMetadata;
|
|
3688
|
+
}
|
|
3655
3689
|
delete state.activeTextParts[chunk.id];
|
|
3656
3690
|
write();
|
|
3657
3691
|
break;
|
|
@@ -3671,13 +3705,13 @@ function processUIMessageStream({
|
|
|
3671
3705
|
case "reasoning-delta": {
|
|
3672
3706
|
const reasoningPart = state.activeReasoningParts[chunk.id];
|
|
3673
3707
|
reasoningPart.text += chunk.delta;
|
|
3674
|
-
reasoningPart.providerMetadata = (
|
|
3708
|
+
reasoningPart.providerMetadata = (_a17 = chunk.providerMetadata) != null ? _a17 : reasoningPart.providerMetadata;
|
|
3675
3709
|
write();
|
|
3676
3710
|
break;
|
|
3677
3711
|
}
|
|
3678
3712
|
case "reasoning-end": {
|
|
3679
3713
|
const reasoningPart = state.activeReasoningParts[chunk.id];
|
|
3680
|
-
reasoningPart.providerMetadata = (
|
|
3714
|
+
reasoningPart.providerMetadata = (_b = chunk.providerMetadata) != null ? _b : reasoningPart.providerMetadata;
|
|
3681
3715
|
reasoningPart.state = "done";
|
|
3682
3716
|
delete state.activeReasoningParts[chunk.id];
|
|
3683
3717
|
write();
|
|
@@ -3925,6 +3959,7 @@ function processUIMessageStream({
|
|
|
3925
3959
|
state.activeReasoningParts = {};
|
|
3926
3960
|
state.partialToolCalls = {};
|
|
3927
3961
|
state.isFinalized = false;
|
|
3962
|
+
state.seenAnnotations = /* @__PURE__ */ new Set();
|
|
3928
3963
|
write();
|
|
3929
3964
|
} else if (!state.message.id) {
|
|
3930
3965
|
state.message.id = chunk.messageId;
|