No JSDoc comment in source yet.
API
@Component()
export class MemoryService implements Memory {
@Use() private readonly paths!: AgentPaths;
@Use() private readonly agentConfigService!: AgentConfig;
async overview(projectId: string, agentId: string): Promise<MemoryOverviewResponse>;
async insertTemplatePlaceholder(projectId: string, agentId: string): Promise<MemoryOverviewResponse>;
async listScopes(projectId: string, agentId: string): Promise<MemoryScopeInfo[]>;
async listFiles(projectId: string, agentId: string, scopeKey: string): Promise<MemoryFilesResponse>;
async readFile(projectId: string, agentId: string, scopeKey: string, filePath: string): Promise<MemoryFileResponse>;
async exportScope(projectId: string, agentId: string, scopeKey: string): Promise<Uint8Array>;
async importScope(projectId: string, agentId: string, scopeKey: string, request: { mode: MemoryImportMode; confirm: boolean; payload?: unknown; dataBase64?: string }): Promise<MemoryImportResponse>;
async deleteFile(projectId: string, agentId: string, scopeKey: string, filePath: string): Promise<void>;
}Dependencies & Wiring
Extracted from class decoratorsMethods (8)
overview
async overview(projectId: string, agentId: string): Promise<MemoryOverviewResponse>The tab's landing payload: the Agent-level switch and one entry per scope directory.
stringstringPromise<MemoryOverviewResponse>insertTemplatePlaceholder
async insertTemplatePlaceholder(projectId: string, agentId: string): Promise<MemoryOverviewResponse>Inserts the {{MEMORY}} placeholder into the Agent's prompt template — the explicit
adoption path for an Agent created before Memory shipped; nothing inserts automatically.
Idempotent: a template that already carries it is left as it is (the refreshed overview
reports templateHasMemory either way).
stringstringPromise<MemoryOverviewResponse>listScopes
async listScopes(projectId: string, agentId: string): Promise<MemoryScopeInfo[]>The scope directories under memory/: the User scope first — always listed, even before it
exists on disk, so a memory can be filed there without waiting for a Session to create it —
then the Workspaces, newest activity first (one with no memory yet sorts last, by key).
stringstringPromise<MemoryScopeInfo[]>listFiles
async listFiles(projectId: string, agentId: string, scopeKey: string): Promise<MemoryFilesResponse>One scope's topic files with their frontmatter and the files each keeps, then the files that belong to no topic.
stringstringstringPromise<MemoryFilesResponse>readFile
async readFile(projectId: string, agentId: string, scopeKey: string, filePath: string): Promise<MemoryFileResponse>One memory file's content, by its path in the scope: a topic (one segment) with the files it
keeps, or a kept file (<folder>/<path>). A kept file is handed out only as text and only up
to the per-file bound: past it the answer is 413, and a file that is not UTF-8 text is 415,
each saying why — the listing still shows the file, so its owner can see it is there.
stringstringstringstringPromise<MemoryFileResponse>exportScope
async exportScope(projectId: string, agentId: string, scopeKey: string): Promise<Uint8Array>The whole scope as a zip of its folder (memory-archive.ts): MEMORY.md, every topic file,
and every folder's files — a topic's scripts and a folder no topic keeps alike — each as the
file it is on disk, binary or not. Dot entries (the .workspace marker, a temporary write)
and links stay out, as everywhere else in this service, and so does a file that vanished
between the listing and the read. Past the import's caps the answer is 413, so every export
imports.
stringstringstringPromise<Uint8Array>importScope
async importScope(projectId: string, agentId: string, scopeKey: string, request: { mode: MemoryImportMode; confirm: boolean; payload?: unknown; dataBase64?: string }): Promise<MemoryImportResponse>Writes an import into one scope: a zip of a scope folder (dataBase64), or a version 1 JSON
document (payload, from before the zip; see memory-transfer-document.ts).
A memory is a topic file and the folder of its name, so every decision below is made per
memory; a folder with no topic beside it is a memory of its own, named <folder>/. The
default mode keeps every memory already on disk and writes only memories the scope does not
have, so an import can never cost the user a memory they did not agree to lose. overwrite
replaces a memory the import carries — topic and folder, since the topic's text describes
that folder's files — and replace additionally deletes every memory the import does not
carry. Both destructive modes are refused with 409 unless confirm is set — but only when
they would actually destroy something, since a confirmation that names nothing is just a
click. The refusal's details name what is at stake, so a client can ask about exactly that.
The index follows the files. A scope with no index takes the import's; replace takes it
too (the whole scope is being replaced); a merge keeps the index that is there and appends
the import's lines for the topics it wrote, because only the indexes enter the model's
context and an unindexed memory is one the Agent never reads. Only topic lines are ever
added or pruned: a topic's files are listed in its own text, never in MEMORY.md.
A non-directory standing at a memory's folder — a planted symlink, a file — or on the way to one of its files refuses the import with 409 before anything is written, rather than writing through it.
stringstringstring{ mode: MemoryImportMode; confirm: boolean; payload?: unknown; dataBase64?: string }Promise<MemoryImportResponse>deleteFile
async deleteFile(projectId: string, agentId: string, scopeKey: string, filePath: string): Promise<void>Deletes a memory file by its path in the scope. A topic goes with its folder, and its lines
are mechanically dropped from the scope's MEMORY.md: any line whose Markdown link target is
exactly this file (](<file>)) goes; a mention of the name in ordinary prose, or a link to a
different file, survives. A kept file (<folder>/<path>) goes alone, with every folder above
it that this left empty up to the scope — so deleting a topic's last file leaves no empty
folder behind; the topic's text and the index are the model's and stay as they are. Besides
an import, these are the only writes the API performs on Memory content — everything else is
the model's, through a chat Session.
stringstringstringstringPromise<void>