refactor: keep runtime context in memory
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
import { join } from "node:path";
|
||||
|
||||
import { config } from "../config.js";
|
||||
import {
|
||||
atomicWriteJson,
|
||||
ensureDirectory,
|
||||
readJsonFile,
|
||||
removeFileIfExists,
|
||||
} from "../utils/fileStore.js";
|
||||
|
||||
export type SessionRuntimeContext = {
|
||||
accessToken?: string;
|
||||
actorKey: string;
|
||||
allowLearningWrite?: boolean;
|
||||
clientSessionId: string;
|
||||
learningMode?: "interactive" | "review";
|
||||
memoryListReadScopes?: Partial<Record<"user" | "workspace", boolean>>;
|
||||
projectId?: string;
|
||||
projectKey: string;
|
||||
sessionId: string;
|
||||
traceId: string;
|
||||
};
|
||||
|
||||
export class SessionRuntimeContextStore {
|
||||
constructor(private readonly baseDir = config.SESSION_RUNTIME_CONTEXT_STORAGE_DIR) {}
|
||||
|
||||
async initialize() {
|
||||
await ensureDirectory(this.baseDir);
|
||||
}
|
||||
|
||||
async write(context: SessionRuntimeContext) {
|
||||
await atomicWriteJson(this.filePath(context.sessionId), context);
|
||||
}
|
||||
|
||||
async read(sessionId: string) {
|
||||
return await readJsonFile<SessionRuntimeContext>(this.filePath(sessionId));
|
||||
}
|
||||
|
||||
async remove(sessionId: string) {
|
||||
await removeFileIfExists(this.filePath(sessionId));
|
||||
}
|
||||
|
||||
private filePath(sessionId: string) {
|
||||
return join(this.baseDir, `${sessionId}.json`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user