import type { Conversation, ConversationCreateInit, ConversationStatusSnapshot, ConversationSummary, PendingSubagentResult, } from "../state.js"; import type { ConversationEntry, NewConversationEntry } from "./entries.js"; import type { MainMemory } from "../memory.js"; import type { TodoItem } from "../todo-tools.js"; import type { Reminder, ReminderCreateInput, ReminderStatus } from "../reminder-store.js"; // --------------------------------------------------------------------------- // VFS types // --------------------------------------------------------------------------- export interface VfsStat { type: "file" | "directory" | "symlink"; size: number; mode: number; mimeType?: string; symlinkTarget?: string; createdAt: number; updatedAt: number; } export interface VfsDirEntry { name: string; type: "file" | "directory" | "symlink"; } // --------------------------------------------------------------------------- // StorageEngine – single interface replacing all KV stores // --------------------------------------------------------------------------- export interface StorageEngine { /** Partition key: every read/write is scoped to this agent id. */ readonly agentId: string; /** Run migrations and prepare the storage backend. */ initialize(): Promise; /** Gracefully release resources. */ close(): Promise; // --- Conversations (replaces ConversationStore) --- conversations: { list(ownerId?: string, tenantId?: string | null): Promise; /** * Load a conversation WITHOUT the tool_result_archive blob. Use this on * read paths (UI loads, existence checks, etc.) — the archive can grow * unboundedly as tool calls accumulate, and most callers never touch it. */ get(conversationId: string): Promise; /** * Load a conversation WITH the tool_result_archive. Only use this when * starting/resuming a harness run — the archive needs to be reseeded so * the agent can retrieve previously-archived tool results by id. */ getWithArchive(conversationId: string): Promise; /** * Cheap column-level snapshot — no data blob, no heavy columns. For hot * polling paths. Returns undefined if the conversation doesn't exist. */ getStatusSnapshot(conversationId: string): Promise; create( ownerId?: string, title?: string, tenantId?: string | null, init?: ConversationCreateInit, ): Promise; update(conversation: Conversation): Promise; rename(conversationId: string, title: string): Promise; delete(conversationId: string): Promise; search(query: string, tenantId?: string | null): Promise; appendSubagentResult( conversationId: string, result: PendingSubagentResult, ): Promise; clearCallbackLock(conversationId: string): Promise; /** List thread conversations anchored under `parentConversationId`. */ listThreads(parentConversationId: string): Promise; /** * Append entries to a conversation's append-only log (Phase 3 substrate). * Assigns a per-conversation monotonic `seq` and `createdAt` to each entry, * persists them in order, and returns the stored entries. Additive — no * read path consumes these yet. */ appendEntries( conversationId: string, agentId: string, tenantId: string | null, entries: NewConversationEntry[], ): Promise; /** Read a conversation's entries ordered by `seq` ascending. */ readEntries( conversationId: string, opts?: { types?: string[]; afterSeq?: number; limit?: number }, ): Promise; }; // --- Memory (replaces MemoryStore) --- memory: { get(tenantId?: string | null): Promise; update(content: string, tenantId?: string | null): Promise; }; // --- Todos (replaces TodoStore) --- todos: { get(conversationId: string): Promise; set(conversationId: string, todos: TodoItem[]): Promise; }; // --- Reminders (replaces ReminderStore) --- reminders: { list(tenantId?: string | null): Promise; create(input: ReminderCreateInput): Promise; update(id: string, fields: { scheduledAt?: number; occurrenceCount?: number; status?: ReminderStatus }): Promise; cancel(id: string): Promise; delete(id: string): Promise; }; // --- Virtual Filesystem (replaces UploadStore + new VFS) --- vfs: { readFile(tenantId: string, path: string): Promise; writeFile( tenantId: string, path: string, content: Uint8Array, mimeType?: string, ): Promise; appendFile(tenantId: string, path: string, content: Uint8Array): Promise; deleteFile(tenantId: string, path: string): Promise; deleteDir(tenantId: string, path: string, recursive?: boolean): Promise; stat(tenantId: string, path: string): Promise; readdir(tenantId: string, path: string): Promise; mkdir(tenantId: string, path: string, recursive?: boolean): Promise; rename(tenantId: string, oldPath: string, newPath: string): Promise; chmod(tenantId: string, path: string, mode: number): Promise; utimes(tenantId: string, path: string, mtime: Date): Promise; symlink(tenantId: string, target: string, linkPath: string): Promise; readlink(tenantId: string, path: string): Promise; lstat(tenantId: string, path: string): Promise; listAllPaths(tenantId: string): string[]; getUsage(tenantId: string): Promise<{ fileCount: number; totalBytes: number }>; }; }