import { WebSocket, WebSocketServer } from 'ws'; type EventHandler = (data: any) => void | Promise; declare class PubSub { private channels; private maxListeners; constructor(maxListeners?: number); subscribe(channel: string, handler: EventHandler): () => void; publish(channel: string, data: any): void; hasSubscribers(channel: string): boolean; getSubscriberCount(channel: string): number; getChannels(): string[]; clear(): void; } interface KyroEvent { type: 'create' | 'update' | 'delete'; collection: string; doc?: any; originalDoc?: any; id?: string; tenantId?: string; timestamp: string; user?: any; } declare class KyroPubSub extends PubSub { private registry; constructor(registry: any, maxListeners?: number); publishCollectionEvent(collection: string, event: KyroEvent): void; subscribeToCollection(collection: string, handler: EventHandler): () => void; subscribeToCollectionEvent(collection: string, eventType: 'create' | 'update' | 'delete', handler: EventHandler): () => void; subscribeToTenant(tenantId: string, handler: EventHandler): () => void; subscribeToTenantCollection(tenantId: string, collection: string, handler: EventHandler): () => void; subscribeToAllCollections(handler: EventHandler): () => void; createAfterChangeHook(collection: string): (args: any) => Promise; createAfterDeleteHook(collection: string): (args: any) => Promise; autoRegisterHooks(): void; } interface PresenceUser { id: string; name: string; email?: string; avatar?: string; color?: string; lastSeen: number; } interface CursorState { userId: string; field?: string; position?: number; selection?: { start: number; end: number; }; updatedAt: number; } interface FieldLock { fieldName: string; userId: string; userName: string; lockedAt: number; expiresAt: number; } interface DocComment { id: string; authorId: string; authorName: string; field?: string; text: string; createdAt: string; resolved?: boolean; } interface DocPresenceState { docKey: string; users: Map; cursors: Map; locks: Map; comments: DocComment[]; } declare class PresenceManager { private documents; private defaultLockTtlMs; private getOrCreateDoc; /** * User joins a document room */ join(docKey: string, user: Omit): PresenceUser[]; /** * User leaves a document room */ leave(docKey: string, userId: string): { remainingUsers: PresenceUser[]; releasedLocks: string[]; }; /** * Updates user cursor / focused field in real time */ updateCursor(docKey: string, userId: string, cursor: { field?: string; position?: number; selection?: { start: number; end: number; }; }): CursorState; /** * Attempts to acquire an exclusive lock on a field */ acquireLock(docKey: string, fieldName: string, user: { id: string; name: string; }, ttlMs?: number): { success: boolean; lock?: FieldLock; currentLock?: FieldLock; }; /** * Releases an exclusive lock on a field */ releaseLock(docKey: string, fieldName: string, userId: string): boolean; /** * Adds an editorial review comment */ addComment(docKey: string, comment: { id: string; authorId: string; authorName: string; field?: string; text: string; }): DocComment; /** * Resolves an editorial comment */ resolveComment(docKey: string, commentId: string): boolean; /** * Returns snapshot of entire presence state for a document */ getSnapshot(docKey: string): { users: PresenceUser[]; cursors: CursorState[]; locks: FieldLock[]; comments: DocComment[]; }; /** * Deterministic avatar color generator for users */ private generateUserColor; } interface WSServerOptions { port?: number; pubsub: KyroPubSub; maxConnections?: number; pingInterval?: number; requireAuth?: boolean; verifyToken?: (token: string) => Promise; } interface WSSubscription { channel: string; unsubscribe: () => void; } interface WSClient { id: string; ws: WebSocket; subscriptions: Map; authenticated: boolean; user?: any; tenantId?: string; connectedAt: Date; lastActivity: Date; activeDocKey?: string; } declare class KyroWSServer { private wss; private clients; private pubsub; private options; private pingTimer?; readonly presence: PresenceManager; constructor(options: WSServerOptions); private setupServer; private handleMessage; private handleAuthenticate; private handleSubscribe; private handleUnsubscribe; private handleUnsubscribeAll; private handleList; private handlePresenceJoin; private handlePresenceLeave; private handlePresenceCursor; private handlePresenceLock; private handlePresenceUnlock; private handlePresenceComment; private handlePresenceSnapshot; private handleDisconnect; private sendToClient; private generateClientId; private startPingInterval; broadcast(channel: string, data: any): void; getConnectedClients(): WSClient[]; getClientCount(): number; getSubscriptionCount(): number; close(): Promise; getServer(): WebSocketServer; } declare function createWSServer(options: WSServerOptions): KyroWSServer; export { type CursorState, type DocComment, type DocPresenceState, type EventHandler, type FieldLock, type KyroEvent, KyroPubSub, KyroWSServer, PresenceManager, type PresenceUser, PubSub, type WSClient, type WSServerOptions, createWSServer };