@opengeni/db 0.22.2 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/{chunk-CYGFLLMN.js → chunk-3UCHDMKG.js} +656 -282
  2. package/dist/chunk-3UCHDMKG.js.map +1 -0
  3. package/dist/{chunk-BNGEN5QZ.js → chunk-L6ADMZHE.js} +24 -2
  4. package/dist/chunk-L6ADMZHE.js.map +1 -0
  5. package/dist/index.d.ts +39 -3
  6. package/dist/index.js +7009 -3882
  7. package/dist/index.js.map +1 -1
  8. package/dist/provision-roles.js +1 -1
  9. package/dist/runtime-posture.d.ts +3 -3
  10. package/dist/schema.d.ts +1416 -92
  11. package/dist/schema.js +11 -1
  12. package/dist/session-control.d.ts +7 -1
  13. package/dist/session-queue-commands.d.ts +8 -0
  14. package/dist/session-realtime-context.d.ts +56 -0
  15. package/dist/session-realtime-ledger.d.ts +188 -0
  16. package/dist/session-realtime-mirror.d.ts +30 -0
  17. package/dist/session-realtime-state.d.ts +2 -0
  18. package/dist/session-realtime-terminal.d.ts +40 -0
  19. package/dist/session-realtime.d.ts +59 -0
  20. package/dist/workspace-instruction-policies-schema.d.ts +239 -0
  21. package/dist/workspace-instruction-policies.d.ts +44 -0
  22. package/drizzle/0156_slack_reaction_trigger.sql +49 -0
  23. package/drizzle/0157_session_policy_role_snapshots.sql +1146 -0
  24. package/drizzle/0158_session_realtime_mode.sql +88 -0
  25. package/drizzle/0159_session_realtime_ledger.sql +198 -0
  26. package/drizzle/0160_session_realtime_delegation_terminal.sql +38 -0
  27. package/drizzle/0161_session_realtime_context_projection.sql +82 -0
  28. package/drizzle/0162_session_realtime_connection_promotion.sql +53 -0
  29. package/drizzle/0163_session_realtime_delegation_progress.sql +35 -0
  30. package/drizzle/0164_session_realtime_models.sql +28 -0
  31. package/package.json +4 -4
  32. package/src/index.ts +614 -78
  33. package/src/preference-registry.ts +11 -6
  34. package/src/provision-roles.ts +12 -0
  35. package/src/runtime-posture.ts +10 -0
  36. package/src/schema.ts +400 -43
  37. package/src/session-control.ts +596 -21
  38. package/src/session-queue-commands.ts +76 -7
  39. package/src/session-realtime-context.ts +393 -0
  40. package/src/session-realtime-ledger.ts +1790 -0
  41. package/src/session-realtime-mirror.ts +160 -0
  42. package/src/session-realtime-state.ts +25 -0
  43. package/src/session-realtime-terminal.ts +306 -0
  44. package/src/session-realtime.ts +611 -0
  45. package/src/workspace-instruction-policies-schema.ts +41 -0
  46. package/src/workspace-instruction-policies.ts +131 -2
  47. package/dist/chunk-BNGEN5QZ.js.map +0 -1
  48. package/dist/chunk-CYGFLLMN.js.map +0 -1
package/dist/schema.js CHANGED
@@ -95,6 +95,10 @@ import {
95
95
  sessionMcpServers,
96
96
  sessionPendingToolCalls,
97
97
  sessionPins,
98
+ sessionRealtimeConnections,
99
+ sessionRealtimeContextProjections,
100
+ sessionRealtimeEntries,
101
+ sessionRealtimeModes,
98
102
  sessionRecordingCodecValues,
99
103
  sessionRecordingModeValues,
100
104
  sessionRecordingStateValues,
@@ -125,6 +129,7 @@ import {
125
129
  workspaceInstructionPolicyActivationEvents,
126
130
  workspaceInstructionPolicyHeads,
127
131
  workspaceInstructionPolicyRevisions,
132
+ workspaceInstructionPolicySnapshots,
128
133
  workspaceMemberships,
129
134
  workspaceModelPolicies,
130
135
  workspacePacks,
@@ -132,7 +137,7 @@ import {
132
137
  workspaceVariableSetVariables,
133
138
  workspaceVariableSets,
134
139
  workspaces
135
- } from "./chunk-CYGFLLMN.js";
140
+ } from "./chunk-3UCHDMKG.js";
136
141
  import "./chunk-PZ5AY32C.js";
137
142
  export {
138
143
  agentRunStates,
@@ -231,6 +236,10 @@ export {
231
236
  sessionMcpServers,
232
237
  sessionPendingToolCalls,
233
238
  sessionPins,
239
+ sessionRealtimeConnections,
240
+ sessionRealtimeContextProjections,
241
+ sessionRealtimeEntries,
242
+ sessionRealtimeModes,
234
243
  sessionRecordingCodecValues,
235
244
  sessionRecordingModeValues,
236
245
  sessionRecordingStateValues,
@@ -261,6 +270,7 @@ export {
261
270
  workspaceInstructionPolicyActivationEvents,
262
271
  workspaceInstructionPolicyHeads,
263
272
  workspaceInstructionPolicyRevisions,
273
+ workspaceInstructionPolicySnapshots,
264
274
  workspaceMemberships,
265
275
  workspaceModelPolicies,
266
276
  workspacePacks,
@@ -288,6 +288,12 @@ export type SessionControlMutationResult = {
288
288
  workspaceControlEventId: string;
289
289
  interruptionCount: number;
290
290
  wakeCount: number;
291
+ cancelledSessionCount: number;
292
+ cancelledTurnCount: number;
293
+ affectedSessionEvents: Array<{
294
+ sessionId: string;
295
+ eventIds: string[];
296
+ }>;
291
297
  replay: boolean;
292
298
  };
293
299
  export declare function mutateSessionControlInTransaction(db: Database, input: {
@@ -296,7 +302,7 @@ export declare function mutateSessionControlInTransaction(db: Database, input: {
296
302
  sessionId: string;
297
303
  actor: SessionCommandActor;
298
304
  operationKey: string;
299
- action: "pause" | "resume";
305
+ action: "pause" | "resume" | "cancel";
300
306
  reason?: string | null;
301
307
  expectedControlEtag?: string | null;
302
308
  }): Promise<SessionControlMutationResult>;
@@ -157,6 +157,14 @@ export declare function submitHumanPromptInTransaction(db: Database, input: {
157
157
  reasoningEffortFallback: ReasoningEffort;
158
158
  /** Trusted API/core admission snapshot. Omitted only by legacy low-level callers. */
159
159
  turnExecutionPolicy?: TurnExecutionPolicyV1;
160
+ /** Trusted core-only metadata attached to the admitted turn. */
161
+ turnMetadata?: Record<string, unknown>;
162
+ /** Trusted display projection; the durable turn still receives `text`. */
163
+ messagePresentation?: {
164
+ kind: "realtime_voice" | "realtime_voice_handoff";
165
+ text: string;
166
+ context: string;
167
+ };
160
168
  source: "user" | "api";
161
169
  personalConnectionDelegations?: McpPersonalConnectionDelegation[];
162
170
  mcpCredentialUpdates?: Array<{
@@ -0,0 +1,56 @@
1
+ import type { Database } from "./index";
2
+ export declare const SESSION_REALTIME_CONTEXT_MAX_BYTES = 65536;
3
+ export declare const SESSION_REALTIME_TAIL_SOURCE = "transcript_tail_flush";
4
+ export declare const SESSION_REALTIME_TAIL_INSTRUCTION = "The user just ended their realtime session. Here is the remaining handoff/transcript tail. You probably do not have to do anything; acknowledge the handoff unless the transcript itself asks for something.";
5
+ export type SessionRealtimeContextProjection = {
6
+ id: string;
7
+ workspaceId: string;
8
+ sessionId: string;
9
+ turnId: string;
10
+ context: string | null;
11
+ sourceModeCount: number;
12
+ sourceEntryCount: number;
13
+ includedEntryCount: number;
14
+ omittedEntryCount: number;
15
+ createdAt: string;
16
+ };
17
+ export type SessionRealtimeContextSourceEntry = {
18
+ id: string;
19
+ realtimeId: string;
20
+ sequence: number;
21
+ role: string | null;
22
+ text: string | null;
23
+ payload: Record<string, unknown>;
24
+ };
25
+ export type SessionRealtimeContinuityEntry = {
26
+ realtimeId: string;
27
+ sequence: number;
28
+ role: "user" | "assistant";
29
+ text: string;
30
+ turnId: string;
31
+ createdAt: string;
32
+ };
33
+ /** Render the exact finalized tail after the latest provider delegation fence. */
34
+ export declare function renderSessionRealtimeTail(entries: readonly SessionRealtimeContextSourceEntry[]): {
35
+ context: string | null;
36
+ includedEntryCount: number;
37
+ omittedEntryCount: number;
38
+ };
39
+ /**
40
+ * Codex-style end fence: route only finalized voice transcript after the last
41
+ * delegation into the same canonical Steer-or-start path used by a human.
42
+ */
43
+ export declare function flushSessionRealtimeTranscriptTailInTransaction(db: Database, input: {
44
+ accountId: string;
45
+ workspaceId: string;
46
+ sessionId: string;
47
+ realtimeId: string;
48
+ ownerSubjectId: string;
49
+ now?: Date;
50
+ }): Promise<SessionRealtimeContextProjection | null>;
51
+ export declare function listSessionRealtimeContinuityEntriesInTransaction(db: Database, input: {
52
+ accountId: string;
53
+ workspaceId: string;
54
+ sessionId: string;
55
+ maximumEntries?: number;
56
+ }): Promise<SessionRealtimeContinuityEntry[]>;
@@ -0,0 +1,188 @@
1
+ import { type SessionRealtimeMode } from "@opengeni/contracts";
2
+ import type { Database } from "./index";
3
+ import { type AssertSessionRealtimeOwnerInput } from "./session-realtime";
4
+ export declare const SESSION_REALTIME_LEDGER_MAX_BATCH = 64;
5
+ export declare const SESSION_REALTIME_LEDGER_MAX_TEXT_BYTES = 131072;
6
+ export declare const SESSION_REALTIME_LEDGER_MAX_PAYLOAD_BYTES = 131072;
7
+ export declare const SESSION_REALTIME_LEDGER_MAX_OUTBOUND = 100;
8
+ export declare const SESSION_REALTIME_STARTUP_MAX_ENTRIES = 100;
9
+ export type SessionRealtimeConnectionState = "negotiating" | "ready" | "active" | "failed" | "closed";
10
+ export type SessionRealtimeConnectionPromotionMode = "legacy" | "staged";
11
+ export type SessionRealtimeConnection = {
12
+ id: string;
13
+ realtimeId: string;
14
+ operationId: string;
15
+ connectionEpoch: number;
16
+ startupFenceSequence: number;
17
+ promotionMode: SessionRealtimeConnectionPromotionMode;
18
+ state: SessionRealtimeConnectionState;
19
+ sdpAnswer: string | null;
20
+ failureCode: string | null;
21
+ providerSessionId: string | null;
22
+ startupEventId: string | null;
23
+ startupAcknowledgedAt: string | null;
24
+ negotiatedAt: string | null;
25
+ closedAt: string | null;
26
+ createdAt: string;
27
+ updatedAt: string;
28
+ };
29
+ export type ClaimSessionRealtimeConnectionInput = AssertSessionRealtimeOwnerInput & {
30
+ operationId: string;
31
+ expectedConnectionEpoch: number;
32
+ rotate: boolean;
33
+ promotionMode?: SessionRealtimeConnectionPromotionMode | undefined;
34
+ };
35
+ export type ClaimSessionRealtimeConnectionResult = {
36
+ connection: SessionRealtimeConnection;
37
+ startupEntries: SessionRealtimeLedgerEntry[];
38
+ mode: SessionRealtimeMode;
39
+ modeVersion: number;
40
+ replay: boolean;
41
+ };
42
+ export type CompleteSessionRealtimeConnectionInput = {
43
+ workspaceId: string;
44
+ sessionId: string;
45
+ realtimeId: string;
46
+ connectionId: string;
47
+ operationId: string;
48
+ connectionEpoch: number;
49
+ sdpAnswer: string;
50
+ now?: Date;
51
+ };
52
+ export type CompleteSessionRealtimeConnectionResult = {
53
+ connection: SessionRealtimeConnection;
54
+ replay: boolean;
55
+ };
56
+ export type ActivateSessionRealtimeConnectionInput = AssertSessionRealtimeOwnerInput & {
57
+ operationId: string;
58
+ connectionId: string;
59
+ connectionEpoch: number;
60
+ expectedConnectionEpoch: number;
61
+ };
62
+ export type ActivateSessionRealtimeConnectionResult = {
63
+ connection: SessionRealtimeConnection;
64
+ mode: SessionRealtimeMode;
65
+ replay: boolean;
66
+ };
67
+ export type FailSessionRealtimeConnectionInput = Omit<CompleteSessionRealtimeConnectionInput, "sdpAnswer"> & {
68
+ failureCode: string;
69
+ };
70
+ export type FailSessionRealtimeConnectionResult = {
71
+ connection: SessionRealtimeConnection;
72
+ replay: boolean;
73
+ };
74
+ export type SessionRealtimeLedgerDirection = "provider_in" | "provider_out";
75
+ export type SessionRealtimeLedgerKind = "user_transcript" | "assistant_transcript" | "delegation_call" | "delegation_progress" | "delegation_result" | "interruption" | "session_update" | "error";
76
+ export type SessionRealtimeLedgerEntry = {
77
+ id: string;
78
+ realtimeId: string;
79
+ operationId: string;
80
+ connectionEpoch: number;
81
+ sequence: number;
82
+ direction: SessionRealtimeLedgerDirection;
83
+ kind: SessionRealtimeLedgerKind;
84
+ role: "user" | "assistant" | null;
85
+ providerEventId: string | null;
86
+ delegationItemId: string | null;
87
+ sourceUpdateId: string | null;
88
+ historyItemId: string | null;
89
+ turnId: string | null;
90
+ text: string | null;
91
+ payload: Record<string, unknown>;
92
+ clientAckedAt: string | null;
93
+ providerAckedAt: string | null;
94
+ createdAt: string;
95
+ updatedAt: string;
96
+ };
97
+ export type SessionRealtimeInboundEntryInput = {
98
+ operationId: string;
99
+ kind: Exclude<SessionRealtimeLedgerKind, "delegation_progress" | "delegation_result" | "session_update">;
100
+ role?: "user" | "assistant" | null | undefined;
101
+ providerEventId?: string | null | undefined;
102
+ delegationItemId?: string | null | undefined;
103
+ text?: string | null | undefined;
104
+ payload?: Record<string, unknown> | undefined;
105
+ };
106
+ export type SyncSessionRealtimeLedgerInput = AssertSessionRealtimeOwnerInput & {
107
+ connectionId: string;
108
+ connectionEpoch: number;
109
+ entries?: SessionRealtimeInboundEntryInput[] | undefined;
110
+ clientAckThroughSequence?: number | null | undefined;
111
+ providerAckSequences?: number[] | undefined;
112
+ providerStarted?: {
113
+ providerSessionId: string;
114
+ providerEventId?: string | null | undefined;
115
+ } | undefined;
116
+ };
117
+ export type SyncSessionRealtimeLedgerResult = {
118
+ accepted: Array<{
119
+ entry: SessionRealtimeLedgerEntry;
120
+ replay: boolean;
121
+ }>;
122
+ outbound: SessionRealtimeLedgerEntry[];
123
+ eventIds: string[];
124
+ workflowWakeRevision: number | null;
125
+ };
126
+ export type SyncSessionRealtimeLedgerHooks = {
127
+ /** Test-only failure injection after both durable admission rows exist. */
128
+ afterDelegationAdmission?: ((admission: {
129
+ entryId: string;
130
+ turnId: string;
131
+ }) => void | Promise<void>) | undefined;
132
+ };
133
+ export type AppendSessionRealtimeOutboundInput = {
134
+ workspaceId: string;
135
+ sessionId: string;
136
+ realtimeId: string;
137
+ operationId: string;
138
+ connectionEpoch: number;
139
+ kind: Extract<SessionRealtimeLedgerKind, "delegation_result" | "error">;
140
+ delegationItemId?: string | null;
141
+ text?: string | null;
142
+ payload?: Record<string, unknown>;
143
+ now?: Date;
144
+ };
145
+ export type AppendSessionRealtimeOutboundResult = {
146
+ entry: SessionRealtimeLedgerEntry;
147
+ replay: boolean;
148
+ };
149
+ export { projectSessionRealtimeDelegationTerminalInTransaction, type ProjectSessionRealtimeDelegationTerminalInput, type ProjectSessionRealtimeDelegationTerminalResult, } from "./session-realtime-terminal";
150
+ export type ProjectSessionRealtimeDelegationProgressInput = {
151
+ accountId: string;
152
+ workspaceId: string;
153
+ sessionId: string;
154
+ turnId: string;
155
+ events: ReadonlyArray<{
156
+ id: string;
157
+ sequence: number;
158
+ type: string;
159
+ payload: unknown;
160
+ }>;
161
+ now?: Date;
162
+ };
163
+ export type ProjectSessionRealtimeDelegationProgressResult = {
164
+ entries: SessionRealtimeLedgerEntry[];
165
+ };
166
+ /** True only for an exact provider-call-linked ordinary turn shape. */
167
+ export declare function isSessionRealtimeDelegationTurnMetadata(metadata: Record<string, unknown>): boolean;
168
+ export declare function claimSessionRealtimeConnectionInTransaction(db: Database, input: ClaimSessionRealtimeConnectionInput): Promise<ClaimSessionRealtimeConnectionResult>;
169
+ export declare function completeSessionRealtimeConnectionInTransaction(db: Database, input: CompleteSessionRealtimeConnectionInput): Promise<CompleteSessionRealtimeConnectionResult>;
170
+ export declare function activateSessionRealtimeConnectionInTransaction(db: Database, input: ActivateSessionRealtimeConnectionInput): Promise<ActivateSessionRealtimeConnectionResult>;
171
+ export declare function failSessionRealtimeConnectionInTransaction(db: Database, input: FailSessionRealtimeConnectionInput): Promise<FailSessionRealtimeConnectionResult>;
172
+ export declare function syncSessionRealtimeLedgerInTransaction(db: Database, input: SyncSessionRealtimeLedgerInput, hooks?: SyncSessionRealtimeLedgerHooks): Promise<SyncSessionRealtimeLedgerResult>;
173
+ export declare function appendSessionRealtimeOutboundInTransaction(db: Database, input: AppendSessionRealtimeOutboundInput): Promise<AppendSessionRealtimeOutboundResult>;
174
+ /**
175
+ * Under the caller's canonical session/turn fence, mirror accepted assistant
176
+ * text deltas into the active delegation's durable provider-out stream. One
177
+ * append batch becomes one or more bounded progress rows, preserving the
178
+ * ordinary event order without making the browser's live SSE authoritative.
179
+ */
180
+ export declare function projectSessionRealtimeDelegationProgressInTransaction(db: Database, input: ProjectSessionRealtimeDelegationProgressInput): Promise<ProjectSessionRealtimeDelegationProgressResult>;
181
+ /**
182
+ * Project the authoritative terminal event of an accepted same-session
183
+ * delegation into exactly one outbound ledger row. The caller already owns the
184
+ * canonical session/turn settlement locks; this helper deliberately does not
185
+ * require the original provider connection (or even the mode) to remain
186
+ * active. A later valid rotation may therefore replay the same durable row,
187
+ * while the immutable realtime id prevents projection into another mode.
188
+ */
@@ -0,0 +1,30 @@
1
+ import type { Database } from "./index";
2
+ import * as schema from "./schema";
3
+ export type SessionRealtimeMirrorChannel = "speakable" | "commentary" | null;
4
+ export type MirrorSessionRealtimeContextInput = {
5
+ accountId: string;
6
+ workspaceId: string;
7
+ sessionId: string;
8
+ sourceKind: "human_input" | "assistant_progress" | "assistant_terminal";
9
+ sourceId: string;
10
+ text: string;
11
+ channel: SessionRealtimeMirrorChannel;
12
+ turnId?: string | null;
13
+ payload?: Record<string, unknown> | undefined;
14
+ now?: Date | undefined;
15
+ };
16
+ export type MirrorSessionRealtimeContextResult = {
17
+ entry: typeof schema.sessionRealtimeEntries.$inferSelect;
18
+ replay: boolean;
19
+ } | null;
20
+ /**
21
+ * Append one canonical same-session fact to the active realtime conversation.
22
+ * The caller already owns the session event-write lock. Locking the active mode
23
+ * serializes sequence allocation with lifecycle end and browser ledger sync.
24
+ */
25
+ export declare function mirrorSessionRealtimeContextInTransaction(db: Database, input: MirrorSessionRealtimeContextInput): Promise<MirrorSessionRealtimeContextResult>;
26
+ export declare function renderRealtimeHumanInputContext(input: {
27
+ delivery: "send" | "steer";
28
+ routing: "accepted_for_execution" | "queued_for_execution" | "accepted_for_steering";
29
+ text: string;
30
+ }): string;
@@ -0,0 +1,2 @@
1
+ import type { Database } from "./index";
2
+ export declare function sessionRealtimeIsActiveInTransaction(db: Database, workspaceId: string, sessionId: string, now?: Date): Promise<boolean>;
@@ -0,0 +1,40 @@
1
+ import type { Database } from "./index";
2
+ export type ProjectSessionRealtimeDelegationTerminalInput = {
3
+ accountId: string;
4
+ workspaceId: string;
5
+ sessionId: string;
6
+ turnId: string;
7
+ turnStatus: "completed" | "failed" | "cancelled" | "superseded";
8
+ terminalEvent: {
9
+ type: "turn.completed" | "turn.failed" | "turn.cancelled" | "turn.superseded";
10
+ payload: Record<string, unknown>;
11
+ };
12
+ now?: Date;
13
+ };
14
+ export type SessionRealtimeTerminalEntry = {
15
+ id: string;
16
+ realtimeId: string;
17
+ operationId: string;
18
+ connectionEpoch: number;
19
+ sequence: number;
20
+ direction: "provider_in" | "provider_out";
21
+ kind: "user_transcript" | "assistant_transcript" | "delegation_call" | "delegation_progress" | "delegation_result" | "interruption" | "session_update" | "error";
22
+ role: "user" | "assistant" | null;
23
+ providerEventId: string | null;
24
+ delegationItemId: string | null;
25
+ sourceUpdateId: string | null;
26
+ historyItemId: string | null;
27
+ turnId: string | null;
28
+ text: string | null;
29
+ payload: Record<string, unknown>;
30
+ clientAckedAt: string | null;
31
+ providerAckedAt: string | null;
32
+ createdAt: string;
33
+ updatedAt: string;
34
+ };
35
+ export type ProjectSessionRealtimeDelegationTerminalResult = {
36
+ entry: SessionRealtimeTerminalEntry;
37
+ replay: boolean;
38
+ } | null;
39
+ /** One terminal projection for every realtime-delegated durable turn. */
40
+ export declare function projectSessionRealtimeDelegationTerminalInTransaction(db: Database, input: ProjectSessionRealtimeDelegationTerminalInput): Promise<ProjectSessionRealtimeDelegationTerminalResult>;
@@ -0,0 +1,59 @@
1
+ import type { SessionRealtimeEndReason, SessionRealtimeMode, SessionRealtimeModel } from "@opengeni/contracts";
2
+ import type { Database } from "./index";
3
+ import * as schema from "./schema";
4
+ export { sessionRealtimeIsActiveInTransaction } from "./session-realtime-state";
5
+ export declare const SESSION_REALTIME_LEASE_MS = 30000;
6
+ 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";
7
+ export declare class SessionRealtimeConflictError extends Error {
8
+ readonly code: SessionRealtimeConflictCode;
9
+ readonly name = "SessionRealtimeConflictError";
10
+ constructor(code: SessionRealtimeConflictCode, message: string);
11
+ }
12
+ type SessionRow = typeof schema.sessions.$inferSelect;
13
+ export type BeginSessionRealtimeInput = {
14
+ accountId: string;
15
+ workspaceId: string;
16
+ sessionId: string;
17
+ operationId: string;
18
+ ownerSubjectId: string;
19
+ browserInstanceId: string;
20
+ ownerKey: string;
21
+ model: SessionRealtimeModel;
22
+ now?: Date;
23
+ leaseMs?: number;
24
+ };
25
+ export type RenewSessionRealtimeInput = {
26
+ workspaceId: string;
27
+ sessionId: string;
28
+ realtimeId: string;
29
+ ownerSubjectId: string;
30
+ browserInstanceId: string;
31
+ ownerKey: string;
32
+ expectedVersion: number;
33
+ now?: Date;
34
+ leaseMs?: number;
35
+ };
36
+ export type EndSessionRealtimeInput = Omit<RenewSessionRealtimeInput, "leaseMs"> & {
37
+ reason: Extract<SessionRealtimeEndReason, "user_stop" | "browser_unload">;
38
+ };
39
+ export type AssertSessionRealtimeOwnerInput = Omit<RenewSessionRealtimeInput, "leaseMs">;
40
+ export type SessionRealtimeMutationResult = {
41
+ mode: SessionRealtimeMode;
42
+ replay: boolean;
43
+ eventIds: string[];
44
+ workflowWakeRevision: number | null;
45
+ };
46
+ export type RenewSessionRealtimeResult = SessionRealtimeMutationResult & {
47
+ expired: boolean;
48
+ };
49
+ export declare function beginSessionRealtimeInTransaction(db: Database, input: BeginSessionRealtimeInput): Promise<SessionRealtimeMutationResult>;
50
+ /**
51
+ * Fence a provider connection to the exact active authenticated browser owner.
52
+ * The caller must finish this transaction before contacting the provider; owner
53
+ * proof is authorization material and must never cross that boundary.
54
+ */
55
+ export declare function assertSessionRealtimeOwnerInTransaction(db: Database, input: AssertSessionRealtimeOwnerInput): Promise<SessionRealtimeMode>;
56
+ export declare function renewSessionRealtimeInTransaction(db: Database, input: RenewSessionRealtimeInput): Promise<RenewSessionRealtimeResult>;
57
+ export declare function endSessionRealtimeInTransaction(db: Database, input: EndSessionRealtimeInput): Promise<SessionRealtimeMutationResult>;
58
+ /** Lazily settle an expired voice lease under the canonical session lock. */
59
+ export declare function settleExpiredSessionRealtimeInTransaction(db: Database, session: SessionRow, now?: Date): Promise<SessionRow>;