/** * PTYSyncStore — session discovery over truffle's SyncedStore primitive. * * Each device publishes its current list of shareable local PTY sessions * to a shared `'avocado-pty-sessions'` store. Peers observe the store via * `onChange` and reconcile their proxy sessions accordingly. * * RFC 022: SyncedStore slices remain keyed by durable ULID (`deviceId`). * Local `getLocalInfo().deviceId` is always a real ULID. Remote slice * events carry the peer's ULID once identity is known. Live PTY *routing* * uses Peer handles / `peer.ref` in `PTYMeshBridge` — this store only does * discovery, not message routing. * * Wire shape stored per device: * * { * sessions: RemoteSessionAnnounce[] * updatedAt: number // unix-ms, set by the writer * } * * On receive we defensively coerce unknown slice shapes to an empty * session list (a peer running a different schema shouldn't crash us). */ import { EventEmitter } from 'events'; import type { MeshNode, NapiSlice } from '@vibecook/truffle'; import type { RemoteSessionAnnounce } from '#types'; /** Default store id — one namespace per mesh for PTY session discovery. */ export declare const DEFAULT_PTY_STORE_ID = "avocado-pty-sessions"; /** Shape of each device's slice in the PTY sync store. */ export interface PTYSessionsSlice { sessions: RemoteSessionAnnounce[]; updatedAt: number; } export interface PTYSyncStoreOptions { /** Truffle mesh node (from `createMeshNode`). */ node: MeshNode; /** Override the default store id (useful for tests or isolated meshes). */ storeId?: string; } /** * Callback fired when a remote device updates or removes its slice. * * `deviceId` is the durable ULID of the peer (SyncedStore attribution), * not a Tailscale id and not a process-local peer ref. */ export type RemoteSessionsChangeCallback = (deviceId: string, sessions: RemoteSessionAnnounce[] | null) => void; /** * Thin wrapper around `NapiSyncedStore` for PTY session discovery. * * Inherits from EventEmitter purely for consumer convenience — the primary * API is `onRemoteChange(cb)` and the store's imperative methods. */ export declare class PTYSyncStore extends EventEmitter { private readonly node; private readonly storeId; private store; private disposed; private readonly localDeviceId; constructor(options: PTYSyncStoreOptions); /** Store identifier in use (for logs/debugging). */ getStoreId(): string; /** This node's durable ULID (SyncedStore owner key for local slice). */ getLocalDeviceId(): string; /** * Publish this device's shareable sessions. * * Pass an empty array to signal "I have nothing to share" — peers will * see an empty slice rather than a stale one. */ setLocalSessions(sessions: RemoteSessionAnnounce[]): Promise; /** Get the local slice that we published most recently (if any). */ getLocalSessions(): Promise; /** * Snapshot of all remote peers' session lists. * * Keyed by durable deviceId (ULID). Excludes the local device. * Use `PTYMeshBridge.getTransportByDeviceId` to resolve live routing. */ getRemoteSessions(): Promise>; /** Raw slices from truffle — useful for debugging or advanced consumers. */ getAllSlices(): Promise; /** * Subscribe to remote slice changes. * * The callback fires for `peer_updated` (with decoded sessions) and * `peer_removed` (with `null` to signal deletion). `local_changed` * events are ignored — the caller is the one who wrote those. * * Multiple subscribers are supported — `NapiSyncedStore.onChange` is * additive, and we also re-emit a `'remoteChange'` event for convenience. */ onRemoteChange(callback: RemoteSessionsChangeCallback): void; dispose(): Promise; } export declare function createPTYSyncStore(options: PTYSyncStoreOptions): PTYSyncStore; //# sourceMappingURL=pty-sync-store.d.ts.map