import { SessionSummary, WorkspaceSummary } from "../../types/hub.mjs"; import { MentionableSession } from "../lib/sessionMentions.mjs"; import { AttachPhase } from "../lib/sessionSummary.mjs"; import { HubLifecycleSnapshot } from "@agimon-ai/po-core/sessionProtocol"; import { Store } from "@tanstack/store"; //#region src/web/stores/sessionsStore.d.ts /** One rail entry: the hub's summary plus this page's view of its connection. */ export interface SessionMeta { summary: SessionSummary; /** Caller-specific UI rights, never persisted in the shared session summary. */ canInteract?: boolean; /** summary.attach adjusted for sticky refusals and a lost page socket. */ attach: AttachPhase; reason: string; /** Frames replayed into this page's timeline on the last subscribe. */ replayed: number; /** Frames the hub's bounded ring lost before this page subscribed. */ dropped: number; } export interface SessionsState { /** Session ids in rail order: each parent immediately followed by its children. */ order: string[]; byId: Record; activeId: string | null; /** Retained separately because permission and session projections may arrive in either order. */ interactions?: Readonly>; /** Optional startup state, replaced independently of session and transport state. */ lifecycle?: Readonly>; /** URL/tab ownership stays with the parent when a tab focuses another session. */ tabOwnerId?: string | null; /** Destination shown while an autonomous voice handoff changes route and media ownership. */ transferringToId: string | null; /** False until the first snapshot; routing waits for it before redirecting. */ hydrated: boolean; /** The server needs newer client code. Only a reload clears it. */ updateRequired: boolean; updateRequiredHosts?: Readonly>; } /** The one reason every session shows once the server needs newer client code. */ export declare const UPDATE_REQUIRED_REASON = "This app is older than the Po server. Update Po to reconnect."; export declare const sessionsStore: Store; /** * The parent this session nests under, or undefined when it renders at the top * level. * * A parent that has since closed, this session itself, a parent in another * workspace, or a cycle all resolve to undefined. The only safe failure is to * render the row where it can still be seen rather than to hide or duplicate it. */ export declare function resolveParentId(byId: Record, id: string, limit?: number): string | undefined; /** Each nested rail row mapped to the row it renders under, matching `order`. */ export declare function railParentIds(byId: Record, order: readonly string[]): Map; /** True when two rail entries differ at most in `summary.updatedAt`, which the hub bumps on every settled message. */ export declare function sameRailEntry(left: SessionMeta | undefined, right: SessionMeta | undefined): boolean; /** `byId` compared the way the rail reads it: an `updatedAt`-only change is no change. */ export declare function sameRailEntries(left: Record, right: Record): boolean; /** A full caller-specific projection for one host. An absent right is never writable. */ export declare function applySessionInteractions(rights: Readonly>, hostId?: string): void; /** Replaces only this host's lifecycle projection. Empty clears stale startup state. */ export declare function applySessionLifecycleSnapshot(snapshots: Readonly>, hostId?: string): void; export declare function applySessionsSnapshot(frame: Record, hostId?: string): void; export declare function applySessionUpsert(frame: Record, hostId?: string): void; export declare function applySessionRemoved(frame: Record, hostId?: string): void; /** Records what the hub replayed into this page when a subscription started. */ export declare function applySessionBacklog(sessionId: string, replayed: number, dropped: number): void; /** * The page socket died; every session is unreachable until it comes back. * Self-healing: the snapshot on reconnect restores the real states. */ export declare function markSocketClosed(hostId?: string): void; /** * The server needs newer client code; every session is unreachable until the * page reloads with it. Unlike a closed socket nothing here heals on its own, * so later session lists keep the same state and reason. */ export declare function markUpdateRequired(hostId?: string): void; /** * Resolves once the session shows up in the rail, or false on timeout. * * A freshly created session exists on disk before its upsert reaches this * page; navigating to it too early trips the unknown-session fallback and * bounces the user back. Waiting here is what makes "create, then land on it" * one motion. */ export declare function waitForSession(sessionId: string, timeoutMs?: number): Promise; /** * Reads the focused session's rail entry, or null while nothing is focused. Like the rail, it * renders again only when more than `updatedAt` moved, which the hub bumps on unrelated pushes. */ export declare function useActiveSessionMeta(): SessionMeta | null; /** * Every rail entry, rendering again only when more than `updatedAt` moved. A * reader that needs that field fresh, such as a recency sort, reads * `sessionsStore.state` while it renders. */ export declare function useRailEntries(): Record; /** One session's rail entry, rendering again only when more than `updatedAt` moved. */ export declare function useRailEntry(sessionId: string | null): SessionMeta | undefined; /** * True once the hub has answered and reported no sessions at all. * * Several surfaces stand down on this, so the rule is named once rather than * spelled out at each of them. The hydration half is what keeps it honest: an * empty order before the first snapshot only means the hub has not answered * yet, and treating that as "no sessions" would flash an onboarding screen at * someone who has ten. */ export declare function noSessions(state: SessionsState): boolean; export declare function useNoSessions(): boolean; /** * Every session but `excludeId` on the same computer, in rail order and by that computer's own ids, as an `@session:` * mention offers it. The server reads a mention among its own sessions only, so another computer's are left out. */ export declare function mentionableSessions(state: SessionsState, workspaces: Readonly>, excludeId: string | null, now: number): MentionableSession[]; export declare function setActiveSession(sessionId: string | null, tabOwnerId?: string | null): void; export declare function beginSessionTransfer(sessionId: string): void; export declare function completeSessionTransfer(sessionId: string): void; export declare function activeSessionId(): string | null; /** * Runs `run` once the session is attached and its protocol is bound, which only happens after its * page takes focus. Runs once, never retries, so an unacknowledged send cannot repeat; a session that * never gets ready in time skips it. */ export declare function whenSessionReady(sessionId: string, run: () => Promise | void): Promise; export declare function resetSessions(): void; //#endregion //# sourceMappingURL=sessionsStore.d.mts.map