/** * SessionRegistry — in-memory store of agent sessions. * * Kept deliberately simple: a Map keyed by sessionId with lazy TTL eviction. * Persistence is out of scope; sessions are by definition ephemeral context * windows for an agent working on a task right now. */ import type { AgentSession } from "../types.js"; import { type WorkingMemoryBufferConfig } from "../buffer/working-memory-buffer.js"; import type { SessionStore } from "./session-store.js"; export interface CreateSessionInput { sessionId: string; agentId: string; workspaceId?: string; taskContext?: string; taskEmbedding?: Float32Array | number[]; ttlMs?: number; /** Provide a buffer config to attach a WorkingMemoryBuffer to this session. */ bufferConfig?: WorkingMemoryBufferConfig; /** * Maximum entries in accessHistory before LRU eviction kicks in (IMP-11). * Defaults to 1000 — large enough for any single agent run, small enough * to keep memory predictable. */ accessHistoryMaxEntries?: number; } export declare class SessionRegistry { private sessions; private defaultTtlMs; private readonly store?; constructor(defaultTtlMs?: number, store?: SessionStore); create(input: CreateSessionInput, now?: number): AgentSession; /** * Await backend readiness before a read (hydration race fix, #18). * * Sync backends (PostgreSQL, Memory) resolve immediately. The PG backend awaits * its in-memory mirror hydration so a session resume immediately after a * process restart observes PG-persisted sessions. Call this before the first * `get()` of a resume flow; the sync `get()` used by the modulation pipeline * stays synchronous. */ ensureReady(): Promise; /** * Async resume path: await backend hydration, then return the session via the * sync `get()`. Use this for session-resume entry points (REST/MCP) where a * caller must observe a persisted session immediately after a process * restart. The hot-path `process()` pipeline continues to use the sync * `get()`. Project search uses this path before session-aware modulation. */ getAsync(sessionId: string, now?: number): Promise; /** * Retrieve a live session. IMP-10: an active `get()` slides the TTL * forward so a session in use does not silently expire mid-task. * The slide is bounded to defaultTtlMs from `now` — accessing a session * never extends it beyond what a fresh `create()` would give. * * NOTE: this is the sync hot path. For backends with an async-warmed read * mirror (PG), the very first call after a process restart may return null * until hydration settles (<100ms). Resume entry points should use * `getAsync()` / `ensureReady()` first. */ get(sessionId: string, now?: number): AgentSession | null; /** * Update the task context for an existing session and refresh its TTL. */ updateTaskContext(sessionId: string, taskContext: string, taskEmbedding?: Float32Array | number[], now?: number): AgentSession | null; /** * Record that the agent accessed a memory inside this session. * Used by agent-affinity scoring. * * IMP-11: the Map is bounded by `accessHistoryLimit`. Re-recording an * existing key refreshes its recency (delete-then-set), keeping the LRU * intuition exact even with the small overhead. */ recordAccess(sessionId: string, memoryId: string, now?: number): void; delete(sessionId: string): boolean; /** Evict expired sessions. Called opportunistically. */ evictExpired(now?: number): number; size(): number; /** Test hook. */ clear(): void; } export declare function getSessionRegistry(): SessionRegistry; export declare function resetSessionRegistry(): void; //# sourceMappingURL=session-registry.d.ts.map