export type Side = "left" | "right"; export type SerializedMessage = Record; export interface StreamUpdate { text?: string; reasoning?: string; status?: string; } export interface RunRequest { history: SerializedMessage[]; prompt: string; branchId: string; onUpdate?: (update: StreamUpdate) => void; } export interface RunResult { branchId: string; messages: SerializedMessage[]; response: string; reasoning: string; startedAt: string; completedAt: string; model: { provider: string; id: string; checkpoint?: string; }; events: Array>; } export interface BranchBackend { readonly name: string; readonly displayName: string; readonly systemPrompt: string; run(request: RunRequest): Promise; } export interface ForkResult { turnId: string; createdAt: string; prompt: string; parentHistory: SerializedMessage[]; parentHistoryHash: string; left: RunResult; right: RunResult; } export interface CandidateRecord { id: string; source: "left" | "right" | "revision"; response: string; reasoning: string; messages: SerializedMessage[]; model: RunResult["model"]; } export interface PreferenceRecord { schema: "branch-preference/v1"; id: string; createdAt: string; backend: string; systemPrompt: string; systemPromptHash: string; parentHistory: SerializedMessage[]; parentHistoryHash: string; prompt: string; candidates: CandidateRecord[]; preferredCandidateId: string; rejectedCandidateIds: string[]; selection: "left" | "right" | "revise-left" | "revise-right"; correction?: { feedback: string; originalCandidateId: string; revisionPrompt: string; }; }