import { type SessionRealtimeMode } from "@opengeni/contracts"; import type { Database, SessionActivityDatabase } from "./database.js"; import { type AssertSessionRealtimeOwnerInput } from "./session-realtime.js"; export declare const SESSION_REALTIME_LEDGER_MAX_BATCH = 64; export declare const SESSION_REALTIME_LEDGER_MAX_TEXT_BYTES = 131072; export declare const SESSION_REALTIME_LEDGER_MAX_PAYLOAD_BYTES = 131072; export declare const SESSION_REALTIME_LEDGER_MAX_OUTBOUND = 100; export declare const SESSION_REALTIME_STARTUP_MAX_ENTRIES = 100; export type SessionRealtimeConnectionState = "negotiating" | "ready" | "active" | "failed" | "closed"; export type SessionRealtimeConnectionPromotionMode = "legacy" | "staged"; export type SessionRealtimeConnection = { id: string; realtimeId: string; operationId: string; connectionEpoch: number; startupFenceSequence: number; promotionMode: SessionRealtimeConnectionPromotionMode; state: SessionRealtimeConnectionState; sdpAnswer: string | null; failureCode: string | null; providerSessionId: string | null; startupEventId: string | null; startupAcknowledgedAt: string | null; negotiatedAt: string | null; closedAt: string | null; createdAt: string; updatedAt: string; }; export type ClaimSessionRealtimeConnectionInput = AssertSessionRealtimeOwnerInput & { operationId: string; expectedConnectionEpoch: number; rotate: boolean; promotionMode?: SessionRealtimeConnectionPromotionMode | undefined; }; export type ClaimSessionRealtimeConnectionResult = { connection: SessionRealtimeConnection; startupEntries: SessionRealtimeLedgerEntry[]; mode: SessionRealtimeMode; modeVersion: number; replay: boolean; }; export type CompleteSessionRealtimeConnectionInput = { workspaceId: string; sessionId: string; realtimeId: string; connectionId: string; operationId: string; connectionEpoch: number; sdpAnswer: string; now?: Date; }; export type CompleteSessionRealtimeConnectionResult = { connection: SessionRealtimeConnection; replay: boolean; }; export type ActivateSessionRealtimeConnectionInput = AssertSessionRealtimeOwnerInput & { operationId: string; connectionId: string; connectionEpoch: number; expectedConnectionEpoch: number; }; export type ActivateSessionRealtimeConnectionResult = { connection: SessionRealtimeConnection; mode: SessionRealtimeMode; replay: boolean; }; export type FailSessionRealtimeConnectionInput = Omit & { failureCode: string; }; export type FailSessionRealtimeConnectionResult = { connection: SessionRealtimeConnection; replay: boolean; }; export type SessionRealtimeLedgerDirection = "provider_in" | "provider_out"; export type SessionRealtimeLedgerKind = "user_transcript" | "assistant_transcript" | "delegation_call" | "delegation_progress" | "delegation_result" | "interruption" | "session_update" | "error"; export type SessionRealtimeLedgerEntry = { id: string; realtimeId: string; operationId: string; connectionEpoch: number; sequence: number; direction: SessionRealtimeLedgerDirection; kind: SessionRealtimeLedgerKind; role: "user" | "assistant" | null; providerEventId: string | null; delegationItemId: string | null; sourceUpdateId: string | null; historyItemId: string | null; turnId: string | null; text: string | null; payload: Record; clientAckedAt: string | null; providerAckedAt: string | null; createdAt: string; updatedAt: string; }; export type SessionRealtimeInboundEntryInput = { operationId: string; kind: Exclude; role?: "user" | "assistant" | null | undefined; providerEventId?: string | null | undefined; delegationItemId?: string | null | undefined; text?: string | null | undefined; payload?: Record | undefined; modelContext?: string | undefined; }; export type SyncSessionRealtimeLedgerInput = AssertSessionRealtimeOwnerInput & { /** Request-scoped callers bound the control prefix wait; lifecycle callers omit it. */ controlLockTimeoutMs?: number; /** The owner's own label (their email), so a voice request names its sender. */ ownerSubjectLabel?: string | null | undefined; connectionId: string; connectionEpoch: number; entries?: SessionRealtimeInboundEntryInput[] | undefined; clientAckThroughSequence?: number | null | undefined; providerAckSequences?: number[] | undefined; providerStarted?: { providerSessionId: string; providerEventId?: string | null | undefined; } | undefined; }; export type SyncSessionRealtimeLedgerResult = { accepted: Array<{ entry: SessionRealtimeLedgerEntry; replay: boolean; }>; outbound: SessionRealtimeLedgerEntry[]; eventIds: string[]; workflowWakeRevision: number | null; }; export type SyncSessionRealtimeLedgerHooks = { /** Test-only failure injection after both durable admission rows exist. */ afterDelegationAdmission?: ((admission: { entryId: string; turnId: string; }) => void | Promise) | undefined; }; export type AppendSessionRealtimeOutboundInput = { workspaceId: string; sessionId: string; realtimeId: string; operationId: string; connectionEpoch: number; kind: Extract; delegationItemId?: string | null; text?: string | null; payload?: Record; now?: Date; }; export type AppendSessionRealtimeOutboundResult = { entry: SessionRealtimeLedgerEntry; replay: boolean; }; export { projectSessionRealtimeDelegationTerminalInTransaction, type ProjectSessionRealtimeDelegationTerminalInput, type ProjectSessionRealtimeDelegationTerminalResult, } from "./session-realtime-terminal.js"; export type ProjectSessionRealtimeDelegationProgressInput = { accountId: string; workspaceId: string; sessionId: string; turnId: string; events: ReadonlyArray<{ id: string; sequence: number; type: string; payload: unknown; }>; now?: Date; }; export type ProjectSessionRealtimeDelegationProgressResult = { entries: SessionRealtimeLedgerEntry[]; }; /** True only for an exact provider-call-linked ordinary turn shape. */ export declare function isSessionRealtimeDelegationTurnMetadata(metadata: Record): boolean; export declare function claimSessionRealtimeConnectionInTransaction(db: Database, input: ClaimSessionRealtimeConnectionInput): Promise; export declare function completeSessionRealtimeConnectionInTransaction(db: Database, input: CompleteSessionRealtimeConnectionInput): Promise; export declare function activateSessionRealtimeConnectionInTransaction(db: Database, input: ActivateSessionRealtimeConnectionInput): Promise; export declare function failSessionRealtimeConnectionInTransaction(db: Database, input: FailSessionRealtimeConnectionInput): Promise; export declare function syncSessionRealtimeLedgerInTransaction(db: SessionActivityDatabase, input: SyncSessionRealtimeLedgerInput, hooks?: SyncSessionRealtimeLedgerHooks): Promise; export declare function appendSessionRealtimeOutboundInTransaction(db: Database, input: AppendSessionRealtimeOutboundInput): Promise; /** * Under the caller's canonical session/turn fence, mirror the agent's * completed working notes into the active delegation's durable provider-out * stream. One append batch becomes one or more bounded progress rows, * preserving the ordinary event order without making the browser's live SSE * authoritative. * * Whole messages, never streaming deltas: every progress row reaches the * voice model as its own context item, so deltas arrived as word fragments * ("You pic", "ked up, so…"). A final answer is not progress either: the * turn's terminal result relays it once. */ export declare function projectSessionRealtimeDelegationProgressInTransaction(db: Database, input: ProjectSessionRealtimeDelegationProgressInput): Promise; /** * Project the authoritative terminal event of an accepted same-session * delegation into exactly one outbound ledger row. The caller already owns the * canonical session/turn settlement locks; this helper deliberately does not * require the original provider connection (or even the mode) to remain * active. A later valid rotation may therefore replay the same durable row, * while the immutable realtime id prevents projection into another mode. */