@yeaft/webchat-agent 0.1.600 → 0.1.601
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/package.json +1 -1
- package/unify/engine.js +49 -2
package/package.json
CHANGED
package/unify/engine.js
CHANGED
|
@@ -25,6 +25,8 @@ import { shouldConsolidate, consolidate, partitionMessages } from './memory/cons
|
|
|
25
25
|
import { extractMemories } from './memory/extract.js';
|
|
26
26
|
import { runCompact as runCompactOrchestrator } from './compact/orchestrator.js';
|
|
27
27
|
import { evaluateCompactTriggers } from './compact/triggers.js';
|
|
28
|
+
import { archiveTurn } from './archive/turn-archive.js';
|
|
29
|
+
import { archiveToolResults } from './archive/tool-results.js';
|
|
28
30
|
import { buildMemoryInjection } from './memory/layout.js';
|
|
29
31
|
import { buildUserProfile } from './memory/user-memory-store.js';
|
|
30
32
|
import { readSummary as readScopeSummary } from './memory/scope-tree.js';
|
|
@@ -638,7 +640,23 @@ export class Engine {
|
|
|
638
640
|
},
|
|
639
641
|
archive: async (_groupIdx, groupMsgs) => {
|
|
640
642
|
for (const m of groupMsgs) if (m.id) archiveIds.push(m.id);
|
|
641
|
-
|
|
643
|
+
const turnId = groupMsgs[0]?.id || `g_${Date.now()}`;
|
|
644
|
+
// Phase 8 PR-E: persist the cooling turn to
|
|
645
|
+
// <yeaftDir>/memory/archive/<turnId>.md so message_trace can
|
|
646
|
+
// replay it later. Scope is "user/" by default — group/task
|
|
647
|
+
// scoping is a follow-up that will arrive with multi-VP archive
|
|
648
|
+
// routing. Best-effort: archive failure must not abort compact.
|
|
649
|
+
if (this.#yeaftDir) {
|
|
650
|
+
try {
|
|
651
|
+
await archiveTurn({
|
|
652
|
+
root: `${this.#yeaftDir}/memory`,
|
|
653
|
+
scopeDir: 'user',
|
|
654
|
+
turnId,
|
|
655
|
+
messages: groupMsgs,
|
|
656
|
+
});
|
|
657
|
+
} catch { /* best-effort */ }
|
|
658
|
+
}
|
|
659
|
+
return { turnId };
|
|
642
660
|
},
|
|
643
661
|
extract: async (coolingMessages) => {
|
|
644
662
|
try {
|
|
@@ -900,11 +918,40 @@ export class Engine {
|
|
|
900
918
|
}
|
|
901
919
|
}
|
|
902
920
|
|
|
921
|
+
// Phase 8 PR-E: archive bulky tool results before they go on the
|
|
922
|
+
// wire. archiveToolResults walks the messages array and replaces
|
|
923
|
+
// any `role:'tool'` body older than turnAgeMin AND larger than
|
|
924
|
+
// lengthMin with a small stub, persisting the original to
|
|
925
|
+
// <yeaftDir>/memory/<scopeDir>/archive/tool-results/<id>.md so
|
|
926
|
+
// message_trace can fetch it on demand. The stub keeps the
|
|
927
|
+
// OpenAI/Anthropic toolCallId pairing intact.
|
|
928
|
+
let wireMessages = stripMetaForWire([...conversationMessages]);
|
|
929
|
+
if (this.#yeaftDir && (this.#config?.archive?.toolResults !== false)) {
|
|
930
|
+
try {
|
|
931
|
+
const swept = await archiveToolResults({
|
|
932
|
+
root: `${this.#yeaftDir}/memory`,
|
|
933
|
+
scopeDir: 'user',
|
|
934
|
+
messages: wireMessages,
|
|
935
|
+
turnAgeMin: this.#config?.archive?.turnAgeMin,
|
|
936
|
+
lengthMin: this.#config?.archive?.lengthMin,
|
|
937
|
+
});
|
|
938
|
+
wireMessages = swept.nextMessages;
|
|
939
|
+
// Mutate the in-memory conversation array so subsequent turns
|
|
940
|
+
// see the stub too — without this, the next turn re-archives
|
|
941
|
+
// the same body.
|
|
942
|
+
if (swept.archivedCount > 0) {
|
|
943
|
+
for (let i = 0; i < conversationMessages.length; i += 1) {
|
|
944
|
+
conversationMessages[i] = wireMessages[i];
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
} catch { /* best-effort */ }
|
|
948
|
+
}
|
|
949
|
+
|
|
903
950
|
// Stream from adapter
|
|
904
951
|
for await (const event of this.#adapter.stream({
|
|
905
952
|
model: currentModel,
|
|
906
953
|
system: systemPrompt,
|
|
907
|
-
messages:
|
|
954
|
+
messages: wireMessages,
|
|
908
955
|
tools: toolDefs.length > 0 ? toolDefs : undefined,
|
|
909
956
|
maxTokens: this.#config.maxOutputTokens || 16384,
|
|
910
957
|
effort: resolvedEffort,
|