@yeaft/webchat-agent 0.1.542 → 0.1.543
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 +39 -21
package/package.json
CHANGED
package/unify/engine.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
import { randomUUID } from 'crypto';
|
|
21
21
|
import { buildSystemPrompt } from './prompts.js';
|
|
22
22
|
import { LLMContextError, LLMAbortError } from './llm/adapter.js';
|
|
23
|
-
import {
|
|
23
|
+
import { recallR6, formatForInjection } from './memory/recall-r6.js';
|
|
24
24
|
import { shouldConsolidate, consolidate } from './memory/consolidate.js';
|
|
25
25
|
import { buildMemoryInjection } from './memory/layout.js';
|
|
26
26
|
import { runStopHooks } from './stop-hooks.js';
|
|
@@ -350,29 +350,34 @@ export class Engine {
|
|
|
350
350
|
|
|
351
351
|
/**
|
|
352
352
|
* Perform memory recall for a given prompt.
|
|
353
|
+
* Uses recallR6 (R6 shard-based recall) when memoryShardStore is available,
|
|
354
|
+
* falling back to empty results if not.
|
|
353
355
|
*
|
|
354
356
|
* @param {string} prompt
|
|
355
|
-
* @returns {Promise<{ profile: string, entries: object[] }|null>}
|
|
357
|
+
* @returns {Promise<{ profile: string, entries: object[], formatted: string }|null>}
|
|
356
358
|
*/
|
|
357
359
|
async #recallMemory(prompt) {
|
|
358
|
-
|
|
360
|
+
const memory = { profile: '', entries: [], formatted: '' };
|
|
359
361
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
362
|
+
// Read user profile from legacy store if available
|
|
363
|
+
if (this.#memoryStore) {
|
|
364
|
+
memory.profile = this.#memoryStore.readProfile();
|
|
365
|
+
}
|
|
364
366
|
|
|
365
|
-
//
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
367
|
+
// R6 shard-based recall (preferred path)
|
|
368
|
+
if (this.#memoryShardStore) {
|
|
369
|
+
try {
|
|
370
|
+
const result = await recallR6({
|
|
371
|
+
prompt,
|
|
372
|
+
memoryShardStore: this.#memoryShardStore,
|
|
373
|
+
adapter: this.#adapter,
|
|
374
|
+
fastModel: this.#fastConfig?.model,
|
|
375
|
+
});
|
|
376
|
+
memory.entries = result.entries;
|
|
377
|
+
memory.formatted = formatForInjection(result.entries);
|
|
378
|
+
} catch {
|
|
379
|
+
// Recall failure is non-critical
|
|
380
|
+
}
|
|
376
381
|
}
|
|
377
382
|
|
|
378
383
|
return memory;
|
|
@@ -563,10 +568,13 @@ export class Engine {
|
|
|
563
568
|
async *#runQuery({ prompt, messages, signal, userEffort = null, scenario = 'chat' }) {
|
|
564
569
|
|
|
565
570
|
// ─── Pre-query: Memory Injection (task-287) + Compact Summary ──
|
|
566
|
-
//
|
|
567
|
-
//
|
|
571
|
+
// Two-layer recall:
|
|
572
|
+
// 1. Static memory index injection (buildMemoryInjection — always)
|
|
573
|
+
// 2. R6 shard-based recall (recallR6 — when memoryShardStore is wired)
|
|
574
|
+
// No per-turn fuzzy recall via old recall.js — LLM calls memory_load /
|
|
568
575
|
// memory_query on demand (memory_search still works as a deprecated alias).
|
|
569
576
|
let memoryInjection = '';
|
|
577
|
+
let recallEntryCount = 0;
|
|
570
578
|
if (this.#yeaftDir) {
|
|
571
579
|
try {
|
|
572
580
|
const entryCount = this.#memoryStore?.stats?.().entryCount ?? 0;
|
|
@@ -580,8 +588,18 @@ export class Engine {
|
|
|
580
588
|
// Injection failure is non-critical — fall back to empty.
|
|
581
589
|
}
|
|
582
590
|
}
|
|
591
|
+
|
|
592
|
+
// R6 recall: append shard-based recall results to memory injection
|
|
593
|
+
const recallResult = await this.#recallMemory(prompt);
|
|
594
|
+
if (recallResult && recallResult.formatted) {
|
|
595
|
+
memoryInjection = memoryInjection
|
|
596
|
+
? memoryInjection + '\n\n' + recallResult.formatted
|
|
597
|
+
: recallResult.formatted;
|
|
598
|
+
recallEntryCount = recallResult.entries.length;
|
|
599
|
+
}
|
|
600
|
+
|
|
583
601
|
if (memoryInjection) {
|
|
584
|
-
yield { type: 'recall', entryCount:
|
|
602
|
+
yield { type: 'recall', entryCount: recallEntryCount, cached: false };
|
|
585
603
|
}
|
|
586
604
|
|
|
587
605
|
const compactSummary = this.#getCompactSummary();
|