import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import type { StateFile, Mail, ThreadSummary } from "../core/types"; export type ThreadingFlagKey = `thread-storage-${TParam}`; export type AdapterOptionKey = TFlag extends ThreadingFlagKey ? B : never; export type AdapterFlags = Record, string | boolean>; export type PiFlagParam = { type: "string" | "boolean"; description: string; default?: string; }; export type AdapterOptions> = { [K in keyof TFlags]: TFlags[K] extends PiFlagParam ? TFlags[K]["type"] extends "string" ? string : boolean : never; }; export interface StorageAdapter { configure(): Promise; loadState(threadId: string): Promise; saveState(threadId: string, state: StateFile): Promise; listThreads(): Promise; threadExists(threadId: string): Promise; sendMail(mail: Mail): Promise; receiveMail(threadId: string): Promise; watchMail(threadId: string, cb: () => void): () => void; } export interface JournalAdapter { appendJournal(threadId: string, entry: string): Promise; readJournal(threadId: string): Promise; } export type ThreadAdapter = StorageAdapter & Partial; export interface AdapterDefinition< TFlags extends Record = Record, > { options: TFlags; build(pi: ExtensionAPI): ThreadAdapter; }