veryfront 0.1.1142 → 0.1.1144
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/esm/deno.js +8 -8
- package/esm/src/agent/hosted/chat-request-parser.d.ts.map +1 -1
- package/esm/src/agent/hosted/chat-request-parser.js +101 -1
- package/esm/src/agent/hosted/chat-request-tool-part.d.ts +11 -0
- package/esm/src/agent/hosted/chat-request-tool-part.d.ts.map +1 -0
- package/esm/src/agent/hosted/chat-request-tool-part.js +19 -0
- package/esm/src/agent/hosted/chat-request.d.ts +24 -0
- package/esm/src/agent/hosted/chat-request.d.ts.map +1 -1
- package/esm/src/agent/hosted/chat-request.js +298 -2
- package/esm/src/chat/conversation.d.ts +35 -2
- package/esm/src/chat/conversation.d.ts.map +1 -1
- package/esm/src/chat/conversation.js +323 -44
- package/esm/src/chat/message-prep.d.ts.map +1 -1
- package/esm/src/chat/message-prep.js +24 -6
- package/esm/src/middleware/core/pipeline/pipeline.d.ts +21 -0
- package/esm/src/middleware/core/pipeline/pipeline.d.ts.map +1 -1
- package/esm/src/middleware/core/pipeline/pipeline.js +150 -4
- package/esm/src/react/compat/ssr-adapter/stream-renderer.d.ts.map +1 -1
- package/esm/src/react/compat/ssr-adapter/stream-renderer.js +14 -2
- package/esm/src/react/compat/ssr-adapter/types.d.ts +1 -0
- package/esm/src/react/compat/ssr-adapter/types.d.ts.map +1 -1
- package/esm/src/rendering/orchestrator/module-loader/module-transform-cache.d.ts +3 -2
- package/esm/src/rendering/orchestrator/module-loader/module-transform-cache.d.ts.map +1 -1
- package/esm/src/rendering/orchestrator/module-loader/module-transform-cache.js +32 -21
- package/esm/src/rendering/orchestrator/ssr-orchestrator.d.ts +1 -1
- package/esm/src/rendering/orchestrator/ssr-orchestrator.d.ts.map +1 -1
- package/esm/src/rendering/orchestrator/ssr-orchestrator.js +8 -1
- package/esm/src/rendering/ssr-globals/dom-stubs.d.ts +2 -9
- package/esm/src/rendering/ssr-globals/dom-stubs.d.ts.map +1 -1
- package/esm/src/rendering/ssr-globals/dom-stubs.js +5 -7
- package/esm/src/rendering/ssr-renderer.d.ts.map +1 -1
- package/esm/src/rendering/ssr-renderer.js +8 -2
- package/esm/src/server/services/rendering/ssr.service.d.ts.map +1 -1
- package/esm/src/server/services/rendering/ssr.service.js +102 -18
- package/esm/src/transforms/esm/transform-cache.d.ts +3 -1
- package/esm/src/transforms/esm/transform-cache.d.ts.map +1 -1
- package/esm/src/transforms/esm/transform-cache.js +26 -4
- package/esm/src/transforms/pipeline/index.d.ts.map +1 -1
- package/esm/src/transforms/pipeline/index.js +6 -17
- package/esm/src/transforms/pipeline/stages/ssr-vf-modules/transform.d.ts.map +1 -1
- package/esm/src/transforms/pipeline/stages/ssr-vf-modules/transform.js +18 -3
- package/esm/src/transforms/shared/framework-bundle-paths.d.ts +7 -0
- package/esm/src/transforms/shared/framework-bundle-paths.d.ts.map +1 -1
- package/esm/src/transforms/shared/framework-bundle-paths.js +14 -0
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../src/src/chat/conversation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAEV,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAEpB,QAAA,MAAM,gCAAgC,eAAuD,CAAC;AAE9F,8DAA8D;AAC9D,MAAM,MAAM,gCAAgC,GAAG,oBAAoB,GAAG;IACpE,CAAC,gCAAgC,CAAC,CAAC,EAAE,MAAM,CAAC;CAC7C,CAAC;AAEF,oFAAoF;AACpF,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,GAAG,SAAS,CAEjG;AAED,6EAA6E;AAC7E,wBAAgB,gCAAgC,C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oB,GAAG,MAAM,CAoB5E;AAmbD,yEAAyE;AACzE,MAAM,MAAM,gCAAgC,GAAG;IAC7C,2BAA2B,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,oBAAoB,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACtC,sBAAsB,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,sBAAsB,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChD,6BAA6B,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/C,uBAAuB,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACzC,yBAAyB,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;CAC5C,CAAC;AAEF,+EAA+E;AAC/E,wBAAgB,oCAAoC,CAClD,QAAQ,EAAE,SAAS,6BAA6B,EAAE,GACjD,gCAAgC,CAwGlC;AAgTD,sDAAsD;AACtD,wBAAgB,wCAAwC,CACtD,QAAQ,EAAE,SAAS,6BAA6B,EAAE,GACjD,oBAAoB,EAAE,CA2CxB"}
|
|
@@ -422,6 +422,12 @@ export function isReasoningPart(value) {
|
|
|
422
422
|
typeof value.signature === "string" ||
|
|
423
423
|
typeof value.redactedData === "string");
|
|
424
424
|
}
|
|
425
|
+
function isProviderVisibleReasoningPart(value) {
|
|
426
|
+
return isReasoningPart(value) &&
|
|
427
|
+
(getNonEmptyStringField(value, "text") !== undefined ||
|
|
428
|
+
getNonEmptyStringField(value, "signature") !== undefined ||
|
|
429
|
+
getNonEmptyStringField(value, "redactedData") !== undefined);
|
|
430
|
+
}
|
|
425
431
|
/** Message shape for extract text from. */
|
|
426
432
|
export function extractTextFromMessage(message) {
|
|
427
433
|
if (!message || !message.content)
|
|
@@ -525,6 +531,9 @@ function getRawToolCallPart(part) {
|
|
|
525
531
|
toolCallId,
|
|
526
532
|
toolName,
|
|
527
533
|
input: toRecord(part.input),
|
|
534
|
+
...(typeof part.state === "string" ? { state: part.state } : {}),
|
|
535
|
+
...(Object.hasOwn(part, "output") ? { output: part.output } : {}),
|
|
536
|
+
...(typeof part.errorText === "string" ? { errorText: part.errorText } : {}),
|
|
528
537
|
};
|
|
529
538
|
}
|
|
530
539
|
function getRawToolResultPart(part) {
|
|
@@ -556,9 +565,14 @@ function getRawToolResultPart(part) {
|
|
|
556
565
|
output,
|
|
557
566
|
};
|
|
558
567
|
}
|
|
559
|
-
function
|
|
568
|
+
function buildToolNameMap(parts) {
|
|
560
569
|
const toolNames = new Map();
|
|
561
570
|
for (const part of parts) {
|
|
571
|
+
const toolPart = getToolPart(part);
|
|
572
|
+
if (toolPart) {
|
|
573
|
+
toolNames.set(toolPart.toolCallId, toolPart.toolName);
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
562
576
|
const rawToolCall = getRawToolCallPart(part);
|
|
563
577
|
if (!rawToolCall) {
|
|
564
578
|
continue;
|
|
@@ -567,6 +581,20 @@ function buildRawToolNameMap(parts) {
|
|
|
567
581
|
}
|
|
568
582
|
return toolNames;
|
|
569
583
|
}
|
|
584
|
+
function resolveRawToolResultPart(rawResult, toolNamesById, knownToolNamesById, matchedToolName) {
|
|
585
|
+
const toolName = matchedToolName ?? rawResult.toolName ??
|
|
586
|
+
toolNamesById.get(rawResult.toolCallId) ??
|
|
587
|
+
knownToolNamesById.get(rawResult.toolCallId);
|
|
588
|
+
if (!toolName) {
|
|
589
|
+
return null;
|
|
590
|
+
}
|
|
591
|
+
return {
|
|
592
|
+
type: "tool-result",
|
|
593
|
+
toolCallId: rawResult.toolCallId,
|
|
594
|
+
toolName,
|
|
595
|
+
output: rawResult.output,
|
|
596
|
+
};
|
|
597
|
+
}
|
|
570
598
|
function buildToolResultOutput(toolPart) {
|
|
571
599
|
if (toolPart.state === "output-available") {
|
|
572
600
|
return {
|
|
@@ -583,6 +611,216 @@ function buildToolResultOutput(toolPart) {
|
|
|
583
611
|
}
|
|
584
612
|
return null;
|
|
585
613
|
}
|
|
614
|
+
function isTransientToolState(state) {
|
|
615
|
+
return state === "pending" || state === "input-available" || state === "input-streaming" ||
|
|
616
|
+
state === "streaming" || state === "approval-requested" || state === "approval-responded";
|
|
617
|
+
}
|
|
618
|
+
function buildRawToolCallResultOutput(rawToolCall) {
|
|
619
|
+
if (!rawToolCall.state) {
|
|
620
|
+
return null;
|
|
621
|
+
}
|
|
622
|
+
return buildToolResultOutput({
|
|
623
|
+
state: rawToolCall.state,
|
|
624
|
+
...(rawToolCall.output !== undefined ? { output: rawToolCall.output } : {}),
|
|
625
|
+
...(rawToolCall.errorText !== undefined ? { errorText: rawToolCall.errorText } : {}),
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
function hasSelfContainedRawToolCallResult(rawToolCall) {
|
|
629
|
+
if (rawToolCall.state === "error" && rawToolCall.output === undefined &&
|
|
630
|
+
rawToolCall.errorText === undefined) {
|
|
631
|
+
return false;
|
|
632
|
+
}
|
|
633
|
+
return buildRawToolCallResultOutput(rawToolCall) !== null;
|
|
634
|
+
}
|
|
635
|
+
function shouldSkipTransientToolCall(part, state, replayMatches) {
|
|
636
|
+
return isTransientToolState(state) &&
|
|
637
|
+
(!isRecord(part) || !replayMatches.preservedTransientToolParts.has(part));
|
|
638
|
+
}
|
|
639
|
+
function getReplayToolCallPart(part, role) {
|
|
640
|
+
if (role !== "assistant") {
|
|
641
|
+
return null;
|
|
642
|
+
}
|
|
643
|
+
if (!isRecord(part)) {
|
|
644
|
+
return null;
|
|
645
|
+
}
|
|
646
|
+
const toolPart = getToolPart(part);
|
|
647
|
+
if (toolPart) {
|
|
648
|
+
return {
|
|
649
|
+
part,
|
|
650
|
+
toolCallId: toolPart.toolCallId,
|
|
651
|
+
toolName: toolPart.toolName,
|
|
652
|
+
transient: isTransientToolState(toolPart.state),
|
|
653
|
+
selfContainedResult: buildToolResultOutput(toolPart) !== null,
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
const rawToolCall = getRawToolCallPart(part);
|
|
657
|
+
if (!rawToolCall) {
|
|
658
|
+
return null;
|
|
659
|
+
}
|
|
660
|
+
return {
|
|
661
|
+
part,
|
|
662
|
+
toolCallId: rawToolCall.toolCallId,
|
|
663
|
+
toolName: rawToolCall.toolName,
|
|
664
|
+
transient: isTransientToolState(rawToolCall.state),
|
|
665
|
+
selfContainedResult: hasSelfContainedRawToolCallResult(rawToolCall),
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
function getReplayToolResultPart(part, role) {
|
|
669
|
+
if (role !== "assistant" && role !== "tool") {
|
|
670
|
+
return null;
|
|
671
|
+
}
|
|
672
|
+
if (!isRecord(part)) {
|
|
673
|
+
return null;
|
|
674
|
+
}
|
|
675
|
+
const rawToolResult = getRawToolResultPart(part);
|
|
676
|
+
if (rawToolResult) {
|
|
677
|
+
return {
|
|
678
|
+
part,
|
|
679
|
+
toolCallId: rawToolResult.toolCallId,
|
|
680
|
+
...(rawToolResult.toolName ? { toolName: rawToolResult.toolName } : {}),
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
const toolPart = getToolPart(part);
|
|
684
|
+
if (role === "tool" && toolPart && buildToolResultOutput(toolPart)) {
|
|
685
|
+
return {
|
|
686
|
+
part,
|
|
687
|
+
toolCallId: toolPart.toolCallId,
|
|
688
|
+
toolName: toolPart.toolName,
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
return null;
|
|
692
|
+
}
|
|
693
|
+
function isProviderVisibleNonToolPart(role, part) {
|
|
694
|
+
if (role === "system") {
|
|
695
|
+
return isTextPart(part) && part.text.length > 0;
|
|
696
|
+
}
|
|
697
|
+
if (role === "user") {
|
|
698
|
+
return isTextPart(part) && part.text.length > 0 || getFilePart(part) !== null;
|
|
699
|
+
}
|
|
700
|
+
if (role === "assistant") {
|
|
701
|
+
return isTextPart(part) && part.text.length > 0 || isProviderVisibleReasoningPart(part) ||
|
|
702
|
+
getFilePart(part) !== null;
|
|
703
|
+
}
|
|
704
|
+
return false;
|
|
705
|
+
}
|
|
706
|
+
function isCompatibleToolResultName(call, result) {
|
|
707
|
+
return !result.toolName || result.toolName === call.toolName;
|
|
708
|
+
}
|
|
709
|
+
function removePendingCallsThroughMatchedResult(pendingCalls, matchedIndex, toolCallId) {
|
|
710
|
+
const priorUnmatchedCalls = pendingCalls.slice(0, matchedIndex).filter((pendingCall) => pendingCall.toolCallId !== toolCallId);
|
|
711
|
+
pendingCalls.splice(0, matchedIndex + 1, ...priorUnmatchedCalls);
|
|
712
|
+
}
|
|
713
|
+
function removePendingCallsWithId(pendingCalls, toolCallId) {
|
|
714
|
+
for (let index = pendingCalls.length - 1; index >= 0; index--) {
|
|
715
|
+
if (pendingCalls[index]?.toolCallId === toolCallId) {
|
|
716
|
+
pendingCalls.splice(index, 1);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
function removePendingCallsFromEarlierMessages(pendingCalls, messageIndex) {
|
|
721
|
+
for (let index = pendingCalls.length - 1; index >= 0; index--) {
|
|
722
|
+
if ((pendingCalls[index]?.originMessageIndex ?? messageIndex) < messageIndex) {
|
|
723
|
+
pendingCalls.splice(index, 1);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
function hasPendingCallsFromEarlierMessages(pendingCalls, messageIndex) {
|
|
728
|
+
return pendingCalls.some((pendingCall) => pendingCall.originMessageIndex < messageIndex);
|
|
729
|
+
}
|
|
730
|
+
/** Find adjacent replay call/result occurrences using part object identity. */
|
|
731
|
+
export function findProviderVisibleToolReplayMatches(messages) {
|
|
732
|
+
const preservedTransientToolParts = new WeakSet();
|
|
733
|
+
const matchedToolCallParts = new WeakSet();
|
|
734
|
+
const matchedToolResultParts = new WeakSet();
|
|
735
|
+
const matchedToolResultNames = new WeakMap();
|
|
736
|
+
const toolCallPartsStartingNewBatch = new WeakSet();
|
|
737
|
+
const supersededToolCallParts = new WeakSet();
|
|
738
|
+
const supersededToolResultParts = new WeakSet();
|
|
739
|
+
const matchedResultPartByCallPart = new WeakMap();
|
|
740
|
+
const toolCallsById = new Map();
|
|
741
|
+
const pendingCalls = [];
|
|
742
|
+
for (const [messageIndex, message] of messages.entries()) {
|
|
743
|
+
let pendingCountBeforeSameMessageVisibleContent = null;
|
|
744
|
+
for (const part of message.parts) {
|
|
745
|
+
const call = getReplayToolCallPart(part, message.role);
|
|
746
|
+
if (call) {
|
|
747
|
+
const callsWithId = toolCallsById.get(call.toolCallId) ?? [];
|
|
748
|
+
callsWithId.push(call);
|
|
749
|
+
toolCallsById.set(call.toolCallId, callsWithId);
|
|
750
|
+
if (hasPendingCallsFromEarlierMessages(pendingCalls, messageIndex)) {
|
|
751
|
+
toolCallPartsStartingNewBatch.add(call.part);
|
|
752
|
+
}
|
|
753
|
+
removePendingCallsFromEarlierMessages(pendingCalls, messageIndex);
|
|
754
|
+
if (pendingCountBeforeSameMessageVisibleContent !== null) {
|
|
755
|
+
pendingCalls.splice(0, pendingCountBeforeSameMessageVisibleContent);
|
|
756
|
+
pendingCountBeforeSameMessageVisibleContent = null;
|
|
757
|
+
}
|
|
758
|
+
removePendingCallsWithId(pendingCalls, call.toolCallId);
|
|
759
|
+
if (call.selfContainedResult) {
|
|
760
|
+
for (const priorCall of callsWithId) {
|
|
761
|
+
if (priorCall.part === call.part) {
|
|
762
|
+
continue;
|
|
763
|
+
}
|
|
764
|
+
supersededToolCallParts.add(priorCall.part);
|
|
765
|
+
const priorResultPart = matchedResultPartByCallPart.get(priorCall.part);
|
|
766
|
+
if (priorResultPart) {
|
|
767
|
+
supersededToolResultParts.add(priorResultPart);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
772
|
+
pendingCalls.push({ ...call, originMessageIndex: messageIndex });
|
|
773
|
+
continue;
|
|
774
|
+
}
|
|
775
|
+
const result = getReplayToolResultPart(part, message.role);
|
|
776
|
+
if (result) {
|
|
777
|
+
const matchedIndex = pendingCalls.findLastIndex((pendingCall) => pendingCall.toolCallId === result.toolCallId &&
|
|
778
|
+
isCompatibleToolResultName(pendingCall, result));
|
|
779
|
+
if (matchedIndex >= 0) {
|
|
780
|
+
const matchedCall = pendingCalls[matchedIndex];
|
|
781
|
+
if (!matchedCall) {
|
|
782
|
+
continue;
|
|
783
|
+
}
|
|
784
|
+
if (matchedCall.transient) {
|
|
785
|
+
preservedTransientToolParts.add(matchedCall.part);
|
|
786
|
+
}
|
|
787
|
+
for (const priorCall of toolCallsById.get(matchedCall.toolCallId) ?? []) {
|
|
788
|
+
if (priorCall.part === matchedCall.part) {
|
|
789
|
+
continue;
|
|
790
|
+
}
|
|
791
|
+
supersededToolCallParts.add(priorCall.part);
|
|
792
|
+
const priorResultPart = matchedResultPartByCallPart.get(priorCall.part);
|
|
793
|
+
if (priorResultPart) {
|
|
794
|
+
supersededToolResultParts.add(priorResultPart);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
matchedToolCallParts.add(matchedCall.part);
|
|
798
|
+
matchedToolResultParts.add(result.part);
|
|
799
|
+
matchedToolResultNames.set(result.part, matchedCall.toolName);
|
|
800
|
+
matchedResultPartByCallPart.set(matchedCall.part, result.part);
|
|
801
|
+
removePendingCallsThroughMatchedResult(pendingCalls, matchedIndex, result.toolCallId);
|
|
802
|
+
}
|
|
803
|
+
continue;
|
|
804
|
+
}
|
|
805
|
+
if (isProviderVisibleNonToolPart(message.role, part)) {
|
|
806
|
+
removePendingCallsFromEarlierMessages(pendingCalls, messageIndex);
|
|
807
|
+
pendingCountBeforeSameMessageVisibleContent ??= pendingCalls.length;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
if (pendingCountBeforeSameMessageVisibleContent !== null) {
|
|
811
|
+
pendingCalls.splice(0, pendingCountBeforeSameMessageVisibleContent);
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
return {
|
|
815
|
+
preservedTransientToolParts,
|
|
816
|
+
matchedToolCallParts,
|
|
817
|
+
matchedToolResultParts,
|
|
818
|
+
matchedToolResultNames,
|
|
819
|
+
toolCallPartsStartingNewBatch,
|
|
820
|
+
supersededToolCallParts,
|
|
821
|
+
supersededToolResultParts,
|
|
822
|
+
};
|
|
823
|
+
}
|
|
586
824
|
function convertSystemMessage(message) {
|
|
587
825
|
const content = message.parts.flatMap((part) => (isTextPart(part) ? [part.text] : [])).join("");
|
|
588
826
|
if (content.length === 0) {
|
|
@@ -599,7 +837,9 @@ function convertUserMessage(message) {
|
|
|
599
837
|
const content = [];
|
|
600
838
|
for (const part of message.parts) {
|
|
601
839
|
if (isTextPart(part)) {
|
|
602
|
-
|
|
840
|
+
if (part.text.length > 0) {
|
|
841
|
+
content.push({ type: "text", text: part.text });
|
|
842
|
+
}
|
|
603
843
|
continue;
|
|
604
844
|
}
|
|
605
845
|
const filePart = getFilePart(part);
|
|
@@ -617,8 +857,8 @@ function convertUserMessage(message) {
|
|
|
617
857
|
},
|
|
618
858
|
];
|
|
619
859
|
}
|
|
620
|
-
function convertAssistantMessage(message) {
|
|
621
|
-
const
|
|
860
|
+
function convertAssistantMessage(message, knownToolNamesById, replayMatches) {
|
|
861
|
+
const toolNamesById = buildToolNameMap(message.parts);
|
|
622
862
|
const assistantContent = [];
|
|
623
863
|
const deferredAssistantContent = [];
|
|
624
864
|
const toolResults = [];
|
|
@@ -670,12 +910,41 @@ function convertAssistantMessage(message) {
|
|
|
670
910
|
toolResults.push(part);
|
|
671
911
|
pendingToolCallIds.delete(part.toolCallId);
|
|
672
912
|
};
|
|
913
|
+
const pushToolCall = (part, toolCall, resultOutput) => {
|
|
914
|
+
if (shouldSkipTransientToolCall(part, toolCall.state, replayMatches)) {
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
if (isRecord(part) && replayMatches.supersededToolCallParts.has(part)) {
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
if (isRecord(part) && replayMatches.toolCallPartsStartingNewBatch.has(part)) {
|
|
921
|
+
flushAssistantMessage(assistantContent);
|
|
922
|
+
flushToolMessage();
|
|
923
|
+
flushAssistantMessage(deferredAssistantContent);
|
|
924
|
+
}
|
|
925
|
+
pushAssistantPart({
|
|
926
|
+
type: "tool-call",
|
|
927
|
+
toolCallId: toolCall.toolCallId,
|
|
928
|
+
toolName: toolCall.toolName,
|
|
929
|
+
input: toolCall.input,
|
|
930
|
+
});
|
|
931
|
+
if (resultOutput) {
|
|
932
|
+
pushToolResult({
|
|
933
|
+
type: "tool-result",
|
|
934
|
+
toolCallId: toolCall.toolCallId,
|
|
935
|
+
toolName: toolCall.toolName,
|
|
936
|
+
output: resultOutput,
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
};
|
|
673
940
|
for (const part of message.parts) {
|
|
674
941
|
if (isTextPart(part)) {
|
|
675
|
-
|
|
942
|
+
if (part.text.length > 0) {
|
|
943
|
+
pushAssistantPart({ type: "text", text: part.text });
|
|
944
|
+
}
|
|
676
945
|
continue;
|
|
677
946
|
}
|
|
678
|
-
if (
|
|
947
|
+
if (isProviderVisibleReasoningPart(part)) {
|
|
679
948
|
pushAssistantPart({
|
|
680
949
|
type: "reasoning",
|
|
681
950
|
text: part.text,
|
|
@@ -691,42 +960,26 @@ function convertAssistantMessage(message) {
|
|
|
691
960
|
}
|
|
692
961
|
const toolPart = getToolPart(part);
|
|
693
962
|
if (toolPart) {
|
|
694
|
-
|
|
695
|
-
type: "tool-call",
|
|
696
|
-
toolCallId: toolPart.toolCallId,
|
|
697
|
-
toolName: toolPart.toolName,
|
|
698
|
-
input: toolPart.input,
|
|
699
|
-
});
|
|
700
|
-
const resultOutput = buildToolResultOutput(toolPart);
|
|
701
|
-
if (resultOutput) {
|
|
702
|
-
pushToolResult({
|
|
703
|
-
type: "tool-result",
|
|
704
|
-
toolCallId: toolPart.toolCallId,
|
|
705
|
-
toolName: toolPart.toolName,
|
|
706
|
-
output: resultOutput,
|
|
707
|
-
});
|
|
708
|
-
}
|
|
963
|
+
pushToolCall(part, toolPart, buildToolResultOutput(toolPart));
|
|
709
964
|
continue;
|
|
710
965
|
}
|
|
711
966
|
const rawToolCall = getRawToolCallPart(part);
|
|
712
967
|
if (rawToolCall) {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
toolName: rawToolCall.toolName,
|
|
717
|
-
input: rawToolCall.input,
|
|
718
|
-
});
|
|
968
|
+
const authoritativeResultFollows = isRecord(part) &&
|
|
969
|
+
replayMatches.matchedToolCallParts.has(part);
|
|
970
|
+
pushToolCall(part, rawToolCall, authoritativeResultFollows ? null : buildRawToolCallResultOutput(rawToolCall));
|
|
719
971
|
continue;
|
|
720
972
|
}
|
|
721
973
|
const rawToolResult = getRawToolResultPart(part);
|
|
722
974
|
if (rawToolResult) {
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
975
|
+
if (!isRecord(part) || !replayMatches.matchedToolResultParts.has(part) ||
|
|
976
|
+
replayMatches.supersededToolResultParts.has(part)) {
|
|
977
|
+
continue;
|
|
978
|
+
}
|
|
979
|
+
const toolResult = resolveRawToolResultPart(rawToolResult, toolNamesById, knownToolNamesById, replayMatches.matchedToolResultNames.get(part));
|
|
980
|
+
if (toolResult) {
|
|
981
|
+
pushToolResult(toolResult);
|
|
982
|
+
}
|
|
730
983
|
}
|
|
731
984
|
}
|
|
732
985
|
flushAssistantMessage(assistantContent);
|
|
@@ -734,20 +987,39 @@ function convertAssistantMessage(message) {
|
|
|
734
987
|
flushAssistantMessage(deferredAssistantContent);
|
|
735
988
|
return messages;
|
|
736
989
|
}
|
|
737
|
-
function convertToolMessage(message) {
|
|
738
|
-
const
|
|
990
|
+
function convertToolMessage(message, knownToolNamesById, replayMatches) {
|
|
991
|
+
const toolNamesById = buildToolNameMap(message.parts);
|
|
739
992
|
const toolResults = [];
|
|
740
993
|
for (const part of message.parts) {
|
|
994
|
+
const toolPart = getToolPart(part);
|
|
995
|
+
if (toolPart) {
|
|
996
|
+
const output = buildToolResultOutput(toolPart);
|
|
997
|
+
if (output) {
|
|
998
|
+
if (!isRecord(part) || !replayMatches.matchedToolResultParts.has(part) ||
|
|
999
|
+
replayMatches.supersededToolResultParts.has(part)) {
|
|
1000
|
+
continue;
|
|
1001
|
+
}
|
|
1002
|
+
toolResults.push({
|
|
1003
|
+
type: "tool-result",
|
|
1004
|
+
toolCallId: toolPart.toolCallId,
|
|
1005
|
+
toolName: toolPart.toolName,
|
|
1006
|
+
output,
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
741
1011
|
const rawResult = getRawToolResultPart(part);
|
|
742
1012
|
if (!rawResult) {
|
|
743
1013
|
continue;
|
|
744
1014
|
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
1015
|
+
if (!isRecord(part) || !replayMatches.matchedToolResultParts.has(part) ||
|
|
1016
|
+
replayMatches.supersededToolResultParts.has(part)) {
|
|
1017
|
+
continue;
|
|
1018
|
+
}
|
|
1019
|
+
const toolResult = resolveRawToolResultPart(rawResult, toolNamesById, knownToolNamesById, replayMatches.matchedToolResultNames.get(part));
|
|
1020
|
+
if (toolResult) {
|
|
1021
|
+
toolResults.push(toolResult);
|
|
1022
|
+
}
|
|
751
1023
|
}
|
|
752
1024
|
if (toolResults.length === 0) {
|
|
753
1025
|
return [];
|
|
@@ -757,7 +1029,14 @@ function convertToolMessage(message) {
|
|
|
757
1029
|
/** Convert UI messages to provider model messages. */
|
|
758
1030
|
export function convertUiMessagesToProviderModelMessages(messages) {
|
|
759
1031
|
const providerMessages = [];
|
|
1032
|
+
const knownToolNamesById = new Map();
|
|
1033
|
+
const replayMatches = findProviderVisibleToolReplayMatches(messages);
|
|
760
1034
|
for (const message of messages) {
|
|
1035
|
+
if (message.role === "assistant") {
|
|
1036
|
+
for (const [toolCallId, toolName] of buildToolNameMap(message.parts)) {
|
|
1037
|
+
knownToolNamesById.set(toolCallId, toolName);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
761
1040
|
const converted = (() => {
|
|
762
1041
|
switch (message.role) {
|
|
763
1042
|
case "system":
|
|
@@ -765,9 +1044,9 @@ export function convertUiMessagesToProviderModelMessages(messages) {
|
|
|
765
1044
|
case "user":
|
|
766
1045
|
return convertUserMessage(message);
|
|
767
1046
|
case "assistant":
|
|
768
|
-
return convertAssistantMessage(message);
|
|
1047
|
+
return convertAssistantMessage(message, knownToolNamesById, replayMatches);
|
|
769
1048
|
case "tool":
|
|
770
|
-
return convertToolMessage(message);
|
|
1049
|
+
return convertToolMessage(message, knownToolNamesById, replayMatches);
|
|
771
1050
|
default:
|
|
772
1051
|
return [];
|
|
773
1052
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-prep.d.ts","sourceRoot":"","sources":["../../../src/src/chat/message-prep.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"message-prep.d.ts","sourceRoot":"","sources":["../../../src/src/chat/message-prep.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAUjC,OAAO,EAKL,KAAK,aAAa,EAGlB,KAAK,oBAAoB,EAE1B,MAAM,YAAY,CAAC;AAKpB,0EAA0E;AAC1E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,6BAA6B,EAAE,MAAM,CAAC;IACtC,4BAA4B,EAAE,MAAM,CAAC;IACrC,8BAA8B,EAAE,MAAM,CAAC;IACvC,6BAA6B,EAAE,MAAM,CAAC;IACtC,gCAAgC,EAAE,MAAM,CAAC;CAC1C,CAAC;AAEF,mDAAmD;AACnD,eAAO,MAAM,2BAA2B,EAAE,iBAOzC,CAAC;AAIF,kEAAkE;AAClE,MAAM,MAAM,gCAAgC,GACxC,MAAM,GACN;IACA,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACC;IACA,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9B,UA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isToolCallPart, isToolResultPart, } from "./conversation.js";
|
|
1
|
+
import { convertUiMessagesToProviderModelMessages, copyProviderModelMessageSourceId, findProviderVisibleToolReplayMatches, getStringField, isReasoningPart, isToolCallPart, isToolResultPart, } from "./conversation.js";
|
|
2
2
|
import { buildDataFileAnnotation, normalizeInlineAttachmentMediaType, } from "./types.js";
|
|
3
3
|
import { historicalToolSummaries } from "../integrations/_tool_summaries.js";
|
|
4
4
|
import { safeJsonParse } from "../utils/json.js";
|
|
@@ -533,7 +533,8 @@ function isPendingToolPart(part) {
|
|
|
533
533
|
}
|
|
534
534
|
const state = typeof part.state === "string" ? part.state : null;
|
|
535
535
|
const isPendingState = state === "pending" || state === "input-available" ||
|
|
536
|
-
state === "input-streaming"
|
|
536
|
+
state === "input-streaming" || state === "streaming" ||
|
|
537
|
+
state === "approval-requested" || state === "approval-responded";
|
|
537
538
|
if (!isPendingState) {
|
|
538
539
|
return false;
|
|
539
540
|
}
|
|
@@ -543,8 +544,8 @@ function getToolPartCallId(part) {
|
|
|
543
544
|
if (!isRecord(part)) {
|
|
544
545
|
return null;
|
|
545
546
|
}
|
|
546
|
-
const toolCallId = part
|
|
547
|
-
return
|
|
547
|
+
const toolCallId = getStringField(part, "toolCallId", "");
|
|
548
|
+
return toolCallId.length > 0 ? toolCallId : null;
|
|
548
549
|
}
|
|
549
550
|
function isToolLikePart(part) {
|
|
550
551
|
return isRecord(part) && typeof part.type === "string" &&
|
|
@@ -563,11 +564,28 @@ function isToolErrorState(part) {
|
|
|
563
564
|
}
|
|
564
565
|
/** Strip pending tool parts. */
|
|
565
566
|
export function stripPendingToolParts(messages) {
|
|
567
|
+
const replayMatches = findProviderVisibleToolReplayMatches(messages);
|
|
566
568
|
return messages.flatMap((message) => {
|
|
567
|
-
if (message.
|
|
569
|
+
if (message.parts.length === 0) {
|
|
568
570
|
return [message];
|
|
569
571
|
}
|
|
570
|
-
const parts = message.parts.filter((part) =>
|
|
572
|
+
const parts = message.parts.filter((part) => {
|
|
573
|
+
if (isRecord(part) &&
|
|
574
|
+
(replayMatches.supersededToolCallParts.has(part) ||
|
|
575
|
+
replayMatches.supersededToolResultParts.has(part))) {
|
|
576
|
+
return false;
|
|
577
|
+
}
|
|
578
|
+
if (message.role !== "assistant") {
|
|
579
|
+
return true;
|
|
580
|
+
}
|
|
581
|
+
if (!isPendingToolPart(part)) {
|
|
582
|
+
return true;
|
|
583
|
+
}
|
|
584
|
+
const toolCallId = getMessagePartToolCallId(part);
|
|
585
|
+
return toolCallId && isRecord(part)
|
|
586
|
+
? replayMatches.preservedTransientToolParts.has(part)
|
|
587
|
+
: false;
|
|
588
|
+
});
|
|
571
589
|
if (parts.length === message.parts.length) {
|
|
572
590
|
return [message];
|
|
573
591
|
}
|
|
@@ -28,6 +28,27 @@ export declare class MiddlewarePipeline {
|
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
30
|
handle(req: Request, handler: (req: Request) => Response | Promise<Response>): Promise<Response>;
|
|
31
|
+
/**
|
|
32
|
+
* Run every registered teardown callback once, in registration order,
|
|
33
|
+
* without discarding them, so a module-scoped route pipeline fires them
|
|
34
|
+
* again on the next request. Called by {@link execute} and {@link handle}:
|
|
35
|
+
* after response bodies close, are canceled, or error; immediately for
|
|
36
|
+
* bodyless, locked, or already-read responses and handler/middleware
|
|
37
|
+
* exceptions. Callback errors are logged and swallowed so cleanup failures
|
|
38
|
+
* never surface to the client. Locked or already-read response bodies cannot
|
|
39
|
+
* be wrapped by the Fetch API, so immediate cleanup is the unavoidable
|
|
40
|
+
* fallback for those invalid response states.
|
|
41
|
+
*/
|
|
42
|
+
private runTeardownCallbacks;
|
|
43
|
+
private withResponseTeardown;
|
|
44
|
+
private copyResponseMetadata;
|
|
45
|
+
private wrapBodyWithTeardown;
|
|
46
|
+
/**
|
|
47
|
+
* Drain and discard all registered teardown callbacks. Unlike the
|
|
48
|
+
* per-request cleanup run by {@link execute} / {@link handle}, this clears
|
|
49
|
+
* the callbacks so they never run again. Use it for one-shot lifecycle
|
|
50
|
+
* cleanup, e.g. draining a long-lived pipeline on server shutdown.
|
|
51
|
+
*/
|
|
31
52
|
teardown(): Promise<void>;
|
|
32
53
|
getMiddleware(): Array<{
|
|
33
54
|
name?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../../../../src/src/middleware/core/pipeline/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAG5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAGzE,qCAAqC;AACrC,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,iBAAiB,CAAyC;IAClE,OAAO,CAAC,QAAQ,CAA4D;gBAEhE,QAAQ,GAAE,yBAA8B;IAEpD,GAAG,CAAC,UAAU,EAAE,iBAAiB,GAAG,IAAI;IAKxC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,iBAAiB,EAAE,GAAG,IAAI;IAK/D,UAAU,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAKhD,OAAO,IAAI,iBAAiB;
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../../../../src/src/middleware/core/pipeline/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAG5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAGzE,qCAAqC;AACrC,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,WAAW,CAA2B;IAC9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