/** * Memory tool-context wiring for the daemon's `ChatMemoryManager`. * * Extracted from `runDaemonInner` so the production glue between the chat * memory layer and the DKG agent — the exact query/createAssertion/ * writeAssertion surface, the memory-graph-changed emission, and the legacy * chat-WM migration (#2149) — is unit-testable without booting a daemon. * `resolveMemoryAgentAddress` in `lifecycle.ts` is the sibling contract for * WHICH agentAddress this context is driven with. * * The legacy migration lives HERE, not in `ChatMemoryManager`: the manager * describes the assertion it wants (`createAssertion` has ensure semantics), * while this daemon boundary owns publisher storage-upgrade concerns. * * Which assertion may migrate is DATA, not a hard-coded product branch: the * caller passes the same `{ contextGraphId, assertionName }` it constructs * `ChatMemoryManager` with, and only that exact pair migrates. Every other * legacy KA stays read-only, exactly as the publisher guarantees. Keeping the * pair a parameter is what makes an overridden chat-memory configuration * migrate its OWN assertion rather than silently migrating the package * defaults (or nothing at all). */ import { ChatMemoryManager, type LlmConfig, type MemoryToolContext } from "@origintrail-official/dkg-node-ui"; import type { MemoryGraphChangedEvent } from "./routes/context.js"; /** * The one assertion this tool context is allowed to storage-upgrade before * creating. Mirrors the chat-memory identifiers the manager is built with. */ export interface LegacyMigrationPolicy { contextGraphId: string; assertionName: string; } /** The minimal agent surface the memory tool context drives. */ export interface MemoryToolContextAgent { query(sparql: string, opts?: { contextGraphId?: string; graphSuffix?: "_shared_memory"; includeSharedMemory?: boolean; view?: "working-memory" | "shared-working-memory" | "verifiable-memory"; agentAddress?: string; assertionName?: string; subGraphName?: string; }): Promise; assertion: { create(contextGraphId: string, name: string, opts?: { subGraphName?: string; agentAddress?: string; }): Promise; write(contextGraphId: string, name: string, quads: any[], opts?: { subGraphName?: string; agentAddress?: string; }): Promise; migrateLegacyRootScopedWorkingMemory(contextGraphId: string, name: string, opts?: { subGraphName?: string; agentAddress?: string; }): Promise; }; createContextGraph(opts: { id: string; name: string; description?: string; private?: boolean; }): Promise; listContextGraphs(): Promise; } export declare function buildMemoryToolContext(agent: MemoryToolContextAgent, emitMemoryGraphChanged: (event: MemoryGraphChangedEvent) => void, legacyMigration: LegacyMigrationPolicy): MemoryToolContext; /** * Build the chat-memory stack as ONE unit. * * The safety property this exists to hold: the assertion the migration * policy may storage-upgrade is by construction the assertion * `ChatMemoryManager` writes to. Wiring them separately in `runDaemonInner` * left a gap where a future edit could hand one pair to the manager and * another to the policy — the manager would then write assertion A while * migration was permitted for assertion B, silently reinstating the #2149 * failure with every test still green. * * Declaring the identifiers here and returning them alongside both objects * makes that invariant testable without booting a daemon, in the same * spirit as `resolveMemoryAgentAddress`. */ export declare function buildChatMemoryStack(input: { agent: MemoryToolContextAgent; emitMemoryGraphChanged: (event: MemoryGraphChangedEvent) => void; llmConfig: LlmConfig; agentAddress: string; }): { chatMemoryIds: LegacyMigrationPolicy; toolContext: MemoryToolContext; manager: ChatMemoryManager; }; //# sourceMappingURL=memory-tool-context.d.ts.map