import { type Database, type SessionActivityDatabase } from "./database.js"; import * as schema from "./schema.js"; /** The cancellation reason shared with membership revocation. */ export declare const VISIBILITY_WORK_CANCEL_REASON = "authority_changed"; export type SessionVisibilityWork = { /** Responses running or parked mid-turn (approval, question, capacity, recovery). */ runningTurnCount: number; /** Messages waiting behind the current response. */ queuedTurnCount: number; activeGoal: boolean; /** A voice session is live in the chat. */ liveVoice: boolean; /** Pending updates that carry another member's authority. */ otherPeoplePendingUpdateCount: number; /** Subscription account choices for the chat that the owner cannot use. */ otherPeopleAccountChoiceCount: number; }; export type SessionVisibilityWorkInventory = { work: SessionVisibilityWork; liveAttempts: Array<{ id: string; turnId: string; }>; pendingTurnIds: string[]; leftoverTurnCount: number; sessionShowsWork: boolean; }; export declare function sessionVisibilityWorkIsEmpty(work: SessionVisibilityWork): boolean; export declare const EMPTY_SESSION_VISIBILITY_WORK: SessionVisibilityWork; /** * Read-only classification; callers that act on it must hold the tenancy * fence. The other-people counts come from an owner-only routine, so the * caller's RLS subject must be the session owner. */ export declare function readSessionVisibilityWork(db: Database, input: { accountId: string; workspaceId: string; sessionId: string; sessionStatus: string; }): Promise; export type SessionVisibilityWorkLock = { session: typeof schema.sessions.$inferSelect; }; /** * Canonical prefix for a visibility change that may write session events. The * caller already holds the organization-membership and exclusive * session-tenancy advisory fences. The workspace row is taken FOR UPDATE here, * exactly as the visibility transition function takes it next, so the definer never * upgrades a weaker workspace lock while holding session rows. */ export declare function lockSessionForVisibilityWork(db: Database, input: { workspaceId: string; sessionId: string; }): Promise; export type SessionVisibilityWorkSettlement = { eventIds: string[]; cancelledTurnCount: number; pausedGoal: boolean; workflowWake: { accountId: string; workspaceId: string; sessionId: string; temporalWorkflowId: string; wakeRevision: number; } | null; }; /** * Cancel the exact non-live turns, optionally pause the active goal, retire * interruptions left on already closed attempts, and settle the public * projection. Live attempts are never touched here. Callers hold * {@link lockSessionForVisibilityWork}. */ export declare function settleSessionVisibilityWorkInTransaction(db: SessionActivityDatabase, input: { session: typeof schema.sessions.$inferSelect; actorSubjectId: string; cancelTurnIds: string[]; pauseGoal: boolean; /** The session still has a live attempt whose settlement owns the projection. */ liveTurnId: string | null; }): Promise; /** * Request a terminal stop of each live attempt. The interruption kind * `authority_change` makes the worker cancel the turn (not pause it) when it * settles, exactly like a revoked membership. The receipt row is the * interruption's operation identity. */ export declare function interruptSessionAttemptsForVisibilityChangeInTransaction(db: Database, input: { session: typeof schema.sessions.$inferSelect; actorSubjectId: string; operationKey: string; attemptIds: string[]; }): Promise;