@zenning/ai 5.3.0 → 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 +84 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -34
- 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.mjs
CHANGED
|
@@ -711,7 +711,7 @@ import {
|
|
|
711
711
|
} from "@zenning/provider-utils";
|
|
712
712
|
|
|
713
713
|
// src/version.ts
|
|
714
|
-
var VERSION = true ? "5.3.
|
|
714
|
+
var VERSION = true ? "5.3.2" : "0.0.0-test";
|
|
715
715
|
|
|
716
716
|
// src/util/download/download.ts
|
|
717
717
|
var download = async ({ url }) => {
|
|
@@ -3439,7 +3439,8 @@ function createStreamingUIMessageState({
|
|
|
3439
3439
|
activeReasoningParts: {},
|
|
3440
3440
|
partialToolCalls: {},
|
|
3441
3441
|
isFinalized: false,
|
|
3442
|
-
messageQueue: []
|
|
3442
|
+
messageQueue: [],
|
|
3443
|
+
seenAnnotations: /* @__PURE__ */ new Set()
|
|
3443
3444
|
};
|
|
3444
3445
|
}
|
|
3445
3446
|
function processUIMessageStream({
|
|
@@ -3455,7 +3456,7 @@ function processUIMessageStream({
|
|
|
3455
3456
|
new TransformStream({
|
|
3456
3457
|
async transform(chunk, controller) {
|
|
3457
3458
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
3458
|
-
var _a17, _b
|
|
3459
|
+
var _a17, _b;
|
|
3459
3460
|
function getToolInvocation(toolCallId) {
|
|
3460
3461
|
const toolInvocations = state.message.parts.filter(isToolUIPart);
|
|
3461
3462
|
const toolInvocation = toolInvocations.find(
|
|
@@ -3559,12 +3560,39 @@ function processUIMessageStream({
|
|
|
3559
3560
|
state.message.metadata = mergedMetadata;
|
|
3560
3561
|
}
|
|
3561
3562
|
}
|
|
3563
|
+
function filterDuplicateAnnotations(providerMetadata) {
|
|
3564
|
+
var _a18;
|
|
3565
|
+
if (!((_a18 = providerMetadata == null ? void 0 : providerMetadata.openai) == null ? void 0 : _a18.annotations) || !state.seenAnnotations) {
|
|
3566
|
+
return providerMetadata;
|
|
3567
|
+
}
|
|
3568
|
+
const filtered = { ...providerMetadata };
|
|
3569
|
+
if (filtered.openai) {
|
|
3570
|
+
filtered.openai = { ...filtered.openai };
|
|
3571
|
+
const uniqueAnnotations = filtered.openai.annotations.filter((annotation) => {
|
|
3572
|
+
const key = JSON.stringify(annotation);
|
|
3573
|
+
if (state.seenAnnotations.has(key)) {
|
|
3574
|
+
return false;
|
|
3575
|
+
}
|
|
3576
|
+
state.seenAnnotations.add(key);
|
|
3577
|
+
return true;
|
|
3578
|
+
});
|
|
3579
|
+
if (uniqueAnnotations.length > 0) {
|
|
3580
|
+
filtered.openai.annotations = uniqueAnnotations;
|
|
3581
|
+
} else {
|
|
3582
|
+
delete filtered.openai.annotations;
|
|
3583
|
+
if (Object.keys(filtered.openai).length === 0) {
|
|
3584
|
+
delete filtered.openai;
|
|
3585
|
+
}
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3588
|
+
return Object.keys(filtered).length > 0 ? filtered : void 0;
|
|
3589
|
+
}
|
|
3562
3590
|
switch (chunk.type) {
|
|
3563
3591
|
case "text-start": {
|
|
3564
3592
|
const textPart = {
|
|
3565
3593
|
type: "text",
|
|
3566
3594
|
text: "",
|
|
3567
|
-
providerMetadata: chunk.providerMetadata,
|
|
3595
|
+
providerMetadata: filterDuplicateAnnotations(chunk.providerMetadata),
|
|
3568
3596
|
state: "streaming"
|
|
3569
3597
|
};
|
|
3570
3598
|
state.activeTextParts[chunk.id] = textPart;
|
|
@@ -3575,14 +3603,20 @@ function processUIMessageStream({
|
|
|
3575
3603
|
case "text-delta": {
|
|
3576
3604
|
const textPart = state.activeTextParts[chunk.id];
|
|
3577
3605
|
textPart.text += chunk.delta;
|
|
3578
|
-
|
|
3606
|
+
const filteredMetadata = filterDuplicateAnnotations(chunk.providerMetadata);
|
|
3607
|
+
if (filteredMetadata && !textPart.providerMetadata) {
|
|
3608
|
+
textPart.providerMetadata = filteredMetadata;
|
|
3609
|
+
}
|
|
3579
3610
|
write();
|
|
3580
3611
|
break;
|
|
3581
3612
|
}
|
|
3582
3613
|
case "text-end": {
|
|
3583
3614
|
const textPart = state.activeTextParts[chunk.id];
|
|
3584
3615
|
textPart.state = "done";
|
|
3585
|
-
|
|
3616
|
+
const filteredMetadata = filterDuplicateAnnotations(chunk.providerMetadata);
|
|
3617
|
+
if (filteredMetadata && !textPart.providerMetadata) {
|
|
3618
|
+
textPart.providerMetadata = filteredMetadata;
|
|
3619
|
+
}
|
|
3586
3620
|
delete state.activeTextParts[chunk.id];
|
|
3587
3621
|
write();
|
|
3588
3622
|
break;
|
|
@@ -3602,13 +3636,13 @@ function processUIMessageStream({
|
|
|
3602
3636
|
case "reasoning-delta": {
|
|
3603
3637
|
const reasoningPart = state.activeReasoningParts[chunk.id];
|
|
3604
3638
|
reasoningPart.text += chunk.delta;
|
|
3605
|
-
reasoningPart.providerMetadata = (
|
|
3639
|
+
reasoningPart.providerMetadata = (_a17 = chunk.providerMetadata) != null ? _a17 : reasoningPart.providerMetadata;
|
|
3606
3640
|
write();
|
|
3607
3641
|
break;
|
|
3608
3642
|
}
|
|
3609
3643
|
case "reasoning-end": {
|
|
3610
3644
|
const reasoningPart = state.activeReasoningParts[chunk.id];
|
|
3611
|
-
reasoningPart.providerMetadata = (
|
|
3645
|
+
reasoningPart.providerMetadata = (_b = chunk.providerMetadata) != null ? _b : reasoningPart.providerMetadata;
|
|
3612
3646
|
reasoningPart.state = "done";
|
|
3613
3647
|
delete state.activeReasoningParts[chunk.id];
|
|
3614
3648
|
write();
|
|
@@ -3624,38 +3658,53 @@ function processUIMessageStream({
|
|
|
3624
3658
|
break;
|
|
3625
3659
|
}
|
|
3626
3660
|
case "source-url": {
|
|
3627
|
-
state.message.parts.
|
|
3628
|
-
type
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3661
|
+
const existingSource = state.message.parts.find(
|
|
3662
|
+
(part) => part.type === "source-url" && part.sourceId === chunk.sourceId
|
|
3663
|
+
);
|
|
3664
|
+
if (!existingSource) {
|
|
3665
|
+
state.message.parts.push({
|
|
3666
|
+
type: "source-url",
|
|
3667
|
+
sourceId: chunk.sourceId,
|
|
3668
|
+
url: chunk.url,
|
|
3669
|
+
title: chunk.title,
|
|
3670
|
+
providerMetadata: chunk.providerMetadata
|
|
3671
|
+
});
|
|
3672
|
+
write();
|
|
3673
|
+
}
|
|
3635
3674
|
break;
|
|
3636
3675
|
}
|
|
3637
3676
|
case "source-execution-file": {
|
|
3638
|
-
state.message.parts.
|
|
3639
|
-
type
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3677
|
+
const existingSource = state.message.parts.find(
|
|
3678
|
+
(part) => part.type === "source-execution-file" && part.sourceId === chunk.sourceId
|
|
3679
|
+
);
|
|
3680
|
+
if (!existingSource) {
|
|
3681
|
+
state.message.parts.push({
|
|
3682
|
+
type: "source-execution-file",
|
|
3683
|
+
sourceId: chunk.sourceId,
|
|
3684
|
+
providerMetadata: chunk.providerMetadata
|
|
3685
|
+
});
|
|
3686
|
+
write();
|
|
3687
|
+
}
|
|
3644
3688
|
break;
|
|
3645
3689
|
}
|
|
3646
3690
|
case "source-document": {
|
|
3647
|
-
state.message.parts.
|
|
3648
|
-
type
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3691
|
+
const existingSource = state.message.parts.find(
|
|
3692
|
+
(part) => part.type === "source-document" && part.sourceId === chunk.sourceId
|
|
3693
|
+
);
|
|
3694
|
+
if (!existingSource) {
|
|
3695
|
+
state.message.parts.push({
|
|
3696
|
+
type: "source-document",
|
|
3697
|
+
sourceId: chunk.sourceId,
|
|
3698
|
+
mediaType: chunk.mediaType,
|
|
3699
|
+
title: chunk.title,
|
|
3700
|
+
filename: chunk.filename,
|
|
3701
|
+
fileId: chunk.fileId,
|
|
3702
|
+
startIndex: chunk.startIndex,
|
|
3703
|
+
endIndex: chunk.endIndex,
|
|
3704
|
+
providerMetadata: chunk.providerMetadata
|
|
3705
|
+
});
|
|
3706
|
+
write();
|
|
3707
|
+
}
|
|
3659
3708
|
break;
|
|
3660
3709
|
}
|
|
3661
3710
|
case "tool-input-start": {
|
|
@@ -3841,6 +3890,7 @@ function processUIMessageStream({
|
|
|
3841
3890
|
state.activeReasoningParts = {};
|
|
3842
3891
|
state.partialToolCalls = {};
|
|
3843
3892
|
state.isFinalized = false;
|
|
3893
|
+
state.seenAnnotations = /* @__PURE__ */ new Set();
|
|
3844
3894
|
write();
|
|
3845
3895
|
} else if (!state.message.id) {
|
|
3846
3896
|
state.message.id = chunk.messageId;
|