fix(server): refuse memory writes for a workspace that does not exist (UF-039)
POST /api/memory/frames, /api/quick-capture and the Memory Center's POST /api/memory saved a memory meant for an unknown workspace into personal memory, which every workspace reads. They now answer 404 workspace_not_found and write nothing; a request without a workspace still goes to personal memory.
This commit is contained in:
@@ -26,6 +26,17 @@ export type MemoryLifecycle = 'active' | 'unreviewed' | 'archived';
|
||||
/** The origin background fact extraction writes with (see memory-extraction.ts). */
|
||||
const EXTRACTION_ORIGIN = 'extraction';
|
||||
|
||||
/**
|
||||
* Where a write goes: personal memory when no workspace is named, the
|
||||
* workspace's memory when it exists, and null for a workspace that does not
|
||||
* exist. Callers refuse that write instead of saving into personal memory,
|
||||
* which every workspace reads (UF-039).
|
||||
*/
|
||||
export function writeScopeForWorkspace(server: FastifyInstance, workspaceId: string | undefined): MemoryScope | null {
|
||||
if (!workspaceId) return PERSONAL_SCOPE;
|
||||
return server.workspaceManager.get(workspaceId) ? workspaceScope(workspaceId) : null;
|
||||
}
|
||||
|
||||
/** The workspace's scope when the workspace exists, else personal memory. */
|
||||
export function scopeForWorkspace(server: FastifyInstance, workspaceId: string | undefined): MemoryScope {
|
||||
return workspaceId && server.workspaceManager.get(workspaceId)
|
||||
|
||||
Reference in New Issue
Block a user