import type { DocWithId } from "@vibes.diy/vibe-runtime/indexeddb-store.js"; import type { MirrorOp, MirrorWriteOp, MirrorWriteSettle } from "@vibes.diy/vibe-types"; export type BusMsg = { readonly kind: "delta"; readonly dbName: string; readonly era: string; readonly seq: number; readonly ops: MirrorOp[]; readonly originRuntimeId?: string; } | { readonly kind: "era-reset"; readonly dbName: string; readonly era: string; readonly seq: number; readonly docs: DocWithId[]; } | { readonly kind: "settled"; readonly dbName: string; readonly era: string; readonly settled: boolean; readonly confirmed?: boolean; } | { readonly kind: "refused"; readonly dbName: string; readonly era: string; readonly docId: string; readonly message?: string; readonly code: "access-denied" | "unreadable"; readonly opIds?: readonly string[]; } | { readonly kind: "write-settled"; readonly dbName: string; readonly era: string; readonly settles: readonly MirrorWriteSettle[]; } | { readonly kind: "snapshot-req"; readonly corrId: string; readonly dbName: string; readonly fromSeq?: number; } | { readonly kind: "snapshot-res"; readonly corrId: string; readonly dbName: string; readonly ok: boolean; readonly era?: string; readonly mode?: "snapshot" | "resume"; readonly seq?: number; readonly docs?: DocWithId[]; readonly ops?: MirrorOp[]; readonly message?: string; readonly settled?: boolean; readonly confirmed?: boolean; } | { readonly kind: "write-req"; readonly corrId: string; readonly dbName: string; readonly originRuntimeId: string; readonly writes: MirrorWriteOp[]; } | { readonly kind: "interest"; readonly dbName: string; readonly sourceId: string; readonly interests: string[]; } | { readonly kind: "write-res"; readonly corrId: string; readonly dbName: string; readonly results: { id: string; ok: boolean; message?: string; receipts?: true; }[]; }; export interface TabBus { post(msg: BusMsg): void; onMessage(fn: (msg: BusMsg) => void): () => void; close(): void; } export type MakeBus = (channelName: string) => TabBus; export declare class TabMirrorBus implements TabBus { private readonly ch; constructor(channelName: string); post(msg: BusMsg): void; onMessage(fn: (msg: BusMsg) => void): () => void; close(): void; } export declare const defaultMakeBus: MakeBus; export type LeaderRole = "leader" | "follower"; export interface LockManagerLike { request(name: string, options: { mode?: "exclusive" | "shared"; ifAvailable?: boolean; signal?: AbortSignal; }, callback: (lock: unknown) => Promise | unknown): Promise; } export interface TabLeadershipOptions { readonly lockName: string; readonly locks?: LockManagerLike; readonly onMissingLocks?: LeaderRole; } export declare class TabLeadership { private _role; private readonly decided; private settle; private settled; private onPromoteCb?; private readonly abort; private releaseHeld?; private stopped; constructor(opts: TabLeadershipOptions); whenDecided(): Promise; get role(): LeaderRole; onPromote(cb: () => void): void; stop(): void; }