// Transport-agnostic sync vocabulary. Every peer conversation - the HTTP // server, a LAN device, a file pack - reduces to exchanging these messages; // Loro import is idempotent (ops dedup by peer + counter), so any message may // be re-sent or replayed safely. interface DocAnnouncement { doc_id: string; // base64 of the doc's binary oplog version vector vv: string; } export type SyncMsg = | { t: 'hello'; protocol: 1; device_id: string; docs: DocAnnouncement[] } | { t: 'doc-update'; doc_id: string; mode: 'update' | 'snapshot'; payload: string } | { t: 'doc-request'; doc_id: string; have_vv: string } | { t: 'blob-have'; hashes: string[] } | { t: 'blob-want'; hashes: string[] } | { t: 'blob-data'; hash: string; mime: string; bytes: string } | { t: 'bye' }; // What the engine needs from a peer. The HTTP transport maps this onto the // REST endpoints (cursor-based); a P2P transport speaks SyncMsg directly. export interface SyncPeer { name: string; manifest(): Promise<{ doc_id: string; latest_seq: number }[]>; pull(docId: string, afterSeq: number): Promise<{ updates: Uint8Array[]; latestSeq: number }>; push(docId: string, updates: Uint8Array[]): Promise; // Fire-and-forget push for a closing page (no awaiting possible there). beacon?(docId: string, updates: Uint8Array[]): void; }