import { type SessionEvent } from "@opengeni/sdk"; import type { EmbeddedSessionEventClientLike } from "../client.js"; /** * Keep live browser work active while the page is visible, then suspend it * after a short hidden-tab grace period. Returning to the page re-enables the * caller, which must reconcile durable state before resuming live delivery. */ export declare function usePageLiveActivity(hiddenGraceMs?: number): boolean; export type AsyncListState = { data: T | null; loading: boolean; error: Error | null; refresh: () => Promise; }; /** * How a read hook rides out transient failures (a transport error or a * 502/503/504, as during an API rolling deploy). While the failures last less * than `quietWindowMs`, the hook keeps its loading state or its last data and * retries with backoff; after that it surfaces the error but keeps retrying * every `backgroundDelayMs`, and clears the error when a read succeeds. * Definitive errors (401, 403, 404, other statuses) surface immediately. */ export type TransientReadRetryOptions = { quietWindowMs?: number | undefined; initialDelayMs?: number | undefined; maxDelayMs?: number | undefined; backgroundDelayMs?: number | undefined; }; export type TransientReadRetryPolicy = { quietWindowMs: number; initialDelayMs: number; maxDelayMs: number; backgroundDelayMs: number; }; export declare const DEFAULT_TRANSIENT_READ_RETRY: Readonly; type TransientReadStreak = { since: number; attempts: number; surfaced: boolean; }; /** * The decision for one transient read failure: stay quiet and retry soon, or * surface the error (once per streak) and keep retrying in the background. */ export declare function transientReadRetryStep(streak: TransientReadStreak, now: number, policy: TransientReadRetryPolicy): { quiet: boolean; delayMs: number; }; /** * Shared fetch + optional polling loop for the list/read hooks. Stale * responses (superseded by a newer load or an unmount) are dropped. * Transient failures are retried quietly (see {@link TransientReadRetryOptions}). */ export declare function usePolledValue(load: (signal?: AbortSignal) => Promise, options?: { pollIntervalMs?: number | undefined; enabled?: boolean | undefined; /** Quiet retry of transient failures; on by default, `false` surfaces them at once. */ transientRetry?: TransientReadRetryOptions | false | undefined; }): AsyncListState; export type MutationState = { mutating: boolean; mutationError: Error | null; clearMutationError: () => void; }; /** * Shared async mutation runner for the write hooks. `run` resolves with the * operation's value, or `null` after capturing the error in `mutationError` * (callers then roll back optimistic state). */ export declare function useMutationRunner(identity?: unknown): MutationState & { run: (operation: () => Promise) => Promise; }; export type SessionEventFeedOptions = { /** * Share an existing event log (from `useSessionEvents`) instead of opening * a second stream. When omitted the hook tails the session's event stream * itself, starting at the current `lastSequence`. */ events?: SessionEvent[] | undefined; enabled?: boolean | undefined; }; /** * What a read hook's authoritative value reflects, for {@link useSessionEventTrigger}: * * - a number: every session event at or below this sequence (the session * detail's `lastSequence`, or a projection's `observedSessionSequence`); * - `"reading"`: the first read for this conversation is still in flight; * - `null` (or omitted): unknown, so every matching event refreshes. */ export type SessionReadThrough = number | "reading" | null; /** The sequence a projection read reflects, as {@link SessionReadThrough}. */ export declare function projectionReadThrough(value: unknown, firstReadInFlight: boolean): SessionReadThrough; export type SessionEventTriggerOptions = SessionEventFeedOptions & { /** * Shared-feed mode: deliver an event only when the hook's own read does not * already reflect it. While the first read is in flight, matching events * wait for it and the newest is delivered once if the read predates it. */ readThrough?: SessionReadThrough | undefined; /** * Re-read the hook's projection. Called instead of delivering an event when * the feed's window starts after the sequence the read reflects, so events * between them (which could have changed the projection) were never seen. */ refresh?: (() => void) | undefined; }; /** * Invoke `onEvent` for every session event matching `match` — the live-update * primitive behind `useTurnQueue` and `useGoal`. Either watches a shared * `events` log or tails the stream directly (reconnect handled by the SDK). */ export declare function useSessionEventTrigger(client: EmbeddedSessionEventClientLike, workspaceId: string, sessionId: string | null | undefined, match: (event: SessionEvent) => boolean, onEvent: (event: SessionEvent) => void, options?: SessionEventTriggerOptions, reconcileBeforeLive?: (() => void | Promise) | undefined): void; /** Debounce rapid event bursts into one trailing call (default 150ms). */ export declare function useDebouncedCallback(callback: () => void, delayMs?: number): () => void; export {};