import type { ConnectionAccountIntent, McpConnectionAccountBinding, McpPersonalConnectionDelegation, SessionRealtimeEndReason, SessionRealtimeMode, SessionRealtimeModel } from "@opengeni/contracts"; import type { Database, SessionActivityDatabase } from "./database.js"; import * as schema from "./schema.js"; export { sessionRealtimeIsActiveInTransaction } from "./session-realtime-state.js"; export declare const SESSION_REALTIME_LEASE_MS = 30000; export type SessionRealtimeConflictCode = "SESSION_CANCELLED" | "CONTROL_NOT_ACTIVE" | "REALTIME_ACTIVE" | "REALTIME_NOT_FOUND" | "REALTIME_NOT_ACTIVE" | "REALTIME_OWNER_MISMATCH" | "REALTIME_VERSION_CHANGED" | "REALTIME_CONNECTION_CHANGED" | "REALTIME_CONNECTION_ACTIVE" | "REALTIME_CONNECTION_NOT_FOUND" | "REALTIME_CONNECTION_STATE_CHANGED" | "REALTIME_PROVIDER_NOT_STARTED" | "REALTIME_DELEGATION_CHANGED" | "REALTIME_ENTRY_CHANGED" | "REALTIME_ACK_INVALID"; export declare class SessionRealtimeConflictError extends Error { readonly code: SessionRealtimeConflictCode; readonly name = "SessionRealtimeConflictError"; constructor(code: SessionRealtimeConflictCode, message: string); } type SessionRow = typeof schema.sessions.$inferSelect; export type BeginSessionRealtimeInput = { accountId: string; workspaceId: string; sessionId: string; operationId: string; ownerSubjectId: string; browserInstanceId: string; ownerKey: string; model: SessionRealtimeModel; incomingCall?: { callId: string; device: string; answered?: boolean | undefined; } | undefined; personalConnectionDelegations?: McpPersonalConnectionDelegation[]; mcpAccountBindings?: McpConnectionAccountBinding[] | null; /** The voice owner's account intent, carried by the turns this lease admits. */ connectionAccountIntent?: ConnectionAccountIntent | null; now?: Date; leaseMs?: number; }; export type RenewSessionRealtimeInput = { workspaceId: string; sessionId: string; realtimeId: string; ownerSubjectId: string; browserInstanceId: string; ownerKey: string; expectedVersion: number; now?: Date; leaseMs?: number; /** * False keeps the current lease unchanged (owner still proven). Used when a * deployment-funded call ran out of credits: the client drains and ends * inside the remaining lease, and an ignoring client lapses on its own. */ extendLease?: boolean; }; export type EndSessionRealtimeInput = Omit & { reason: Extract; /** The ending person's own label (their email), so the flushed tail names its sender. */ ownerSubjectLabel?: string | null | undefined; }; export type AssertSessionRealtimeOwnerInput = Omit; export type SessionRealtimeMutationResult = { mode: SessionRealtimeMode; replay: boolean; eventIds: string[]; workflowWakeRevision: number | null; }; export type RenewSessionRealtimeResult = SessionRealtimeMutationResult & { expired: boolean; }; export declare function beginSessionRealtimeInTransaction(db: SessionActivityDatabase, input: BeginSessionRealtimeInput): Promise; /** * Fence a provider connection to the exact active authenticated browser owner. * The caller must finish this transaction before contacting the provider; owner * proof is authorization material and must never cross that boundary. */ export declare function assertSessionRealtimeOwnerInTransaction(db: Database, input: AssertSessionRealtimeOwnerInput): Promise; export declare function renewSessionRealtimeInTransaction(db: SessionActivityDatabase, input: RenewSessionRealtimeInput): Promise; export declare function endSessionRealtimeInTransaction(db: SessionActivityDatabase, input: EndSessionRealtimeInput): Promise; /** Lazily settle an expired voice lease under the canonical session lock. */ export declare function settleExpiredSessionRealtimeInTransaction(db: SessionActivityDatabase, session: SessionRow, now?: Date): Promise; /** * End the chat's voice session because the chat became Only me: whoever * started it, its delegations and account bindings stop applying. An * already-expired lease ends as `lease_expired`, exactly as it would lazily. * Callers hold the session-event write locks. */ export declare function endSessionRealtimeForPrivateTransitionInTransaction(db: SessionActivityDatabase, session: SessionRow, now?: Date): Promise<{ eventId: string; workflowWakeRevision: number; } | null>;