import type { HappyAgentClient } from "./HappyAgentClient.js"; import type { HappyReducerState } from "./HappyReducerState.js"; import type { Cuid2, EventCursor } from "./protocol/common.js"; import type { HappyAgentUpdate } from "./updates.js"; /** Initial synchronization options for a reducer. */ export interface HappyReducerOptions { /** The last event already reflected in state. */ after?: EventCursor | undefined; } /** Receives an update after it has been reduced into the supplied state. */ export type HappyReducerUpdateListener = (update: HappyAgentUpdate, state: HappyReducerState) => void; /** Receives a new immutable state snapshot and the snapshot it replaced. */ export type HappyReducerStateListener = (state: HappyReducerState, previousState: HappyReducerState) => void; /** Removes one listener registration. Calling it more than once is harmless. */ export type HappyReducerUnsubscribe = () => void; /** * The stateful layer over `HappyAgentClient.updates()`. * * It keeps connection state and visibility-selected agent replicas. The SSE * feed opens before queued agent snapshots, recent events rebase snapshots * that race the stream, and dirty replicas refresh through a bounded queue. * `getState` and `subscribe` form a read-only, React-compatible external store: * a snapshot is replaced only when state changes, and unchanged children keep * their references. Every SSE update is reduced before update listeners see it. */ export declare class HappyReducer { #private; constructor(client: HappyAgentClient, options?: HappyReducerOptions); /** Returns the current immutable snapshot, stable until state changes. */ readonly getState: () => HappyReducerState; /** * Subscribes to state changes using Zustand-style `(state, previousState)` * arguments. Duplicate updates that do not change state do not notify it. */ readonly subscribe: (listener: HappyReducerStateListener) => HappyReducerUnsubscribe; /** Subscribes to every ordered update from the SSE feed without starting the reducer. */ readonly subscribeUpdates: (listener: HappyReducerUpdateListener) => HappyReducerUnsubscribe; /** * Marks an agent visible and queues an authoritative sync at visible priority. * The returned idempotent cleanup lowers it to background priority; the reducer * keeps the agent synchronized while it remains tracked. */ readonly agentVisible: (agentId: Cuid2) => HappyReducerUnsubscribe; /** Starts following updates. Starting an already-running reducer does nothing. */ start(): void; /** Stops synchronously. Any late updates from the old stream are ignored. */ stop(): void; } //# sourceMappingURL=HappyReducer.d.ts.map