/** Maps projects to dedicated worlds for memory isolation. All project reads and writes use the resolved world ID. */ import type { UUID } from "../types/primitives.js"; /** * Prefix for the project→world derivation. Kept distinct so a project id can * never collide with an entity/room base used elsewhere in `createUniqueUuid`. */ export declare const PROJECT_WORLD_PREFIX = "project:"; /** * Deterministic, per-agent worldId for a project. * * Derivation matches `createUniqueUuid(runtime, "project:" + projectId)`: * `stringToUuid("project::")`. Per-agent because Worlds are * agent-scoped (`World.agentId`); two agents referencing the same project each * get their own project world, exactly like every other `createUniqueUuid` * value. * * @param agentId the runtime's agentId (worlds are agent-scoped) * @param projectId the ProjectRecord id * @returns stable worldId UUID for (agent, project) */ export declare function projectWorldId(agentId: UUID, projectId: string): UUID; /** Options shared by the scoping helpers. */ export interface ProjectScopeOptions { /** The runtime agentId (worlds are agent-scoped). Required to derive a world. */ agentId: UUID; /** Active project ID. Omission or an empty value disables project scoping. */ projectId?: string; } /** * A minimal read/search filter shape carrying an optional `worldId`. Matches the * relevant subset of the `getMemories`/`searchMemories` param objects so this * helper can wrap either without importing the full DB interface. */ export interface WorldScopedFilter { worldId?: UUID; [key: string]: unknown; } /** * Inject the project worldId into a memory read/search filter. * * - No `projectId` ⇒ returns the filter **unchanged** (unscoped/global read). * - `projectId` set ⇒ returns a copy with `worldId` set to the project world. * - If the caller already set a `worldId` that DISAGREES with the project world * while a projectId is in effect, that is a fail-closed error (a caller trying * to read one project's memories under another project's scope). A matching * worldId is a no-op. */ export declare function scopeMemoryFilterToProject(filter: T, opts: ProjectScopeOptions): T; /** * A minimal memory shape carrying an optional `worldId`. Matches the subset of * `Memory` needed here without importing the full type (avoids a cycle for * store-layer callers). */ export interface WorldScopedMemory { worldId?: UUID | null; [key: string]: unknown; } /** * Stamp the project worldId on a memory at write time. * * - No `projectId` ⇒ returns the memory **unchanged** (global write). * - `projectId` set ⇒ returns a copy with `worldId` set to the project world. * - A pre-existing conflicting `worldId` on the memory (while a project is in * effect) is a fail-closed error: writing a memory tagged for project B while * scoped to project A would poison isolation. A matching worldId is a no-op. */ export declare function scopeMemoryToProject(memory: T, opts: ProjectScopeOptions): T; /** Rejects retrieved memories belonging to a different project world. Unscoped memories are allowed; without projectId, the input passes through unchanged. */ export declare function assertMemoriesInProject(memories: readonly T[], opts: ProjectScopeOptions): readonly T[];