@opengeni/db 0.22.2 → 0.26.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.
- package/dist/{chunk-CYGFLLMN.js → chunk-7WTDI7Y3.js} +764 -283
- package/dist/chunk-7WTDI7Y3.js.map +1 -0
- package/dist/{chunk-BNGEN5QZ.js → chunk-KW6U54V2.js} +26 -2
- package/dist/chunk-KW6U54V2.js.map +1 -0
- package/dist/connection-token-resolver.d.ts +24 -2
- package/dist/index.d.ts +107 -5
- package/dist/index.js +7857 -3898
- package/dist/index.js.map +1 -1
- package/dist/preference-registry.d.ts +14 -0
- package/dist/provision-roles.js +1 -1
- package/dist/runtime-posture.d.ts +3 -3
- package/dist/schema.d.ts +1659 -77
- package/dist/schema.js +13 -1
- package/dist/session-control.d.ts +7 -1
- package/dist/session-queue-commands.d.ts +8 -0
- package/dist/session-realtime-context.d.ts +56 -0
- package/dist/session-realtime-ledger.d.ts +188 -0
- package/dist/session-realtime-mirror.d.ts +51 -0
- package/dist/session-realtime-state.d.ts +2 -0
- package/dist/session-realtime-terminal.d.ts +40 -0
- package/dist/session-realtime.d.ts +59 -0
- package/dist/workspace-instruction-policies-schema.d.ts +307 -0
- package/dist/workspace-instruction-policies.d.ts +97 -7
- package/drizzle/0156_slack_reaction_trigger.sql +49 -0
- package/drizzle/0157_session_policy_role_snapshots.sql +1146 -0
- package/drizzle/0158_session_realtime_mode.sql +88 -0
- package/drizzle/0159_session_realtime_ledger.sql +198 -0
- package/drizzle/0160_session_realtime_delegation_terminal.sql +38 -0
- package/drizzle/0161_session_realtime_context_projection.sql +82 -0
- package/drizzle/0162_session_realtime_connection_promotion.sql +53 -0
- package/drizzle/0163_session_realtime_delegation_progress.sql +35 -0
- package/drizzle/0164_session_realtime_models.sql +28 -0
- package/drizzle/0165_document_authority_foundation.sql +259 -0
- package/drizzle/0166_connection_disconnect_idempotency.sql +49 -0
- package/drizzle/0167_document_index_replay_authority.sql +61 -0
- package/drizzle/0168_workspace_instruction_policy_operation_receipts.sql +44 -0
- package/package.json +4 -4
- package/src/connection-token-resolver.ts +79 -16
- package/src/index.ts +1033 -101
- package/src/preference-registry.ts +114 -6
- package/src/provision-roles.ts +12 -0
- package/src/runtime-posture.ts +12 -0
- package/src/schema.ts +486 -43
- package/src/session-control.ts +643 -21
- package/src/session-queue-commands.ts +121 -18
- package/src/session-realtime-context.ts +393 -0
- package/src/session-realtime-ledger.ts +1790 -0
- package/src/session-realtime-mirror.ts +276 -0
- package/src/session-realtime-state.ts +25 -0
- package/src/session-realtime-terminal.ts +306 -0
- package/src/session-realtime.ts +659 -0
- package/src/workspace-instruction-policies-schema.ts +71 -0
- package/src/workspace-instruction-policies.ts +568 -25
- package/dist/chunk-BNGEN5QZ.js.map +0 -1
- package/dist/chunk-CYGFLLMN.js.map +0 -1
package/dist/schema.js
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
codexRotationSettings,
|
|
12
12
|
codexSubscriptionCredentials,
|
|
13
13
|
composerDrafts,
|
|
14
|
+
connectionDisconnectOperations,
|
|
14
15
|
connections,
|
|
15
16
|
connectorActionPolicies,
|
|
16
17
|
connectorActionRequests,
|
|
@@ -95,6 +96,10 @@ import {
|
|
|
95
96
|
sessionMcpServers,
|
|
96
97
|
sessionPendingToolCalls,
|
|
97
98
|
sessionPins,
|
|
99
|
+
sessionRealtimeConnections,
|
|
100
|
+
sessionRealtimeContextProjections,
|
|
101
|
+
sessionRealtimeEntries,
|
|
102
|
+
sessionRealtimeModes,
|
|
98
103
|
sessionRecordingCodecValues,
|
|
99
104
|
sessionRecordingModeValues,
|
|
100
105
|
sessionRecordingStateValues,
|
|
@@ -125,6 +130,7 @@ import {
|
|
|
125
130
|
workspaceInstructionPolicyActivationEvents,
|
|
126
131
|
workspaceInstructionPolicyHeads,
|
|
127
132
|
workspaceInstructionPolicyRevisions,
|
|
133
|
+
workspaceInstructionPolicySnapshots,
|
|
128
134
|
workspaceMemberships,
|
|
129
135
|
workspaceModelPolicies,
|
|
130
136
|
workspacePacks,
|
|
@@ -132,7 +138,7 @@ import {
|
|
|
132
138
|
workspaceVariableSetVariables,
|
|
133
139
|
workspaceVariableSets,
|
|
134
140
|
workspaces
|
|
135
|
-
} from "./chunk-
|
|
141
|
+
} from "./chunk-7WTDI7Y3.js";
|
|
136
142
|
import "./chunk-PZ5AY32C.js";
|
|
137
143
|
export {
|
|
138
144
|
agentRunStates,
|
|
@@ -147,6 +153,7 @@ export {
|
|
|
147
153
|
codexRotationSettings,
|
|
148
154
|
codexSubscriptionCredentials,
|
|
149
155
|
composerDrafts,
|
|
156
|
+
connectionDisconnectOperations,
|
|
150
157
|
connections,
|
|
151
158
|
connectorActionPolicies,
|
|
152
159
|
connectorActionRequests,
|
|
@@ -231,6 +238,10 @@ export {
|
|
|
231
238
|
sessionMcpServers,
|
|
232
239
|
sessionPendingToolCalls,
|
|
233
240
|
sessionPins,
|
|
241
|
+
sessionRealtimeConnections,
|
|
242
|
+
sessionRealtimeContextProjections,
|
|
243
|
+
sessionRealtimeEntries,
|
|
244
|
+
sessionRealtimeModes,
|
|
234
245
|
sessionRecordingCodecValues,
|
|
235
246
|
sessionRecordingModeValues,
|
|
236
247
|
sessionRecordingStateValues,
|
|
@@ -261,6 +272,7 @@ export {
|
|
|
261
272
|
workspaceInstructionPolicyActivationEvents,
|
|
262
273
|
workspaceInstructionPolicyHeads,
|
|
263
274
|
workspaceInstructionPolicyRevisions,
|
|
275
|
+
workspaceInstructionPolicySnapshots,
|
|
264
276
|
workspaceMemberships,
|
|
265
277
|
workspaceModelPolicies,
|
|
266
278
|
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,51 @@
|
|
|
1
|
+
import type { HumanInputQuestion, HumanInputResponse } from "@opengeni/contracts";
|
|
2
|
+
import type { Database } from "./index";
|
|
3
|
+
import * as schema from "./schema";
|
|
4
|
+
export type SessionRealtimeMirrorChannel = "speakable" | "commentary" | null;
|
|
5
|
+
export type MirrorSessionRealtimeContextInput = {
|
|
6
|
+
accountId: string;
|
|
7
|
+
workspaceId: string;
|
|
8
|
+
sessionId: string;
|
|
9
|
+
sourceKind: "human_input" | "human_input_request" | "human_input_response" | "assistant_progress" | "assistant_terminal";
|
|
10
|
+
sourceId: string;
|
|
11
|
+
text: string;
|
|
12
|
+
channel: SessionRealtimeMirrorChannel;
|
|
13
|
+
turnId?: string | null;
|
|
14
|
+
payload?: Record<string, unknown> | undefined;
|
|
15
|
+
now?: Date | undefined;
|
|
16
|
+
};
|
|
17
|
+
export type MirrorSessionRealtimeContextResult = {
|
|
18
|
+
entry: typeof schema.sessionRealtimeEntries.$inferSelect;
|
|
19
|
+
replay: boolean;
|
|
20
|
+
} | null;
|
|
21
|
+
/**
|
|
22
|
+
* Append one canonical same-session fact to the active realtime conversation.
|
|
23
|
+
* The caller already owns the session event-write lock. Locking the active mode
|
|
24
|
+
* serializes sequence allocation with lifecycle end and browser ledger sync.
|
|
25
|
+
*/
|
|
26
|
+
export declare function mirrorSessionRealtimeContextInTransaction(db: Database, input: MirrorSessionRealtimeContextInput): Promise<MirrorSessionRealtimeContextResult>;
|
|
27
|
+
export declare function renderRealtimeHumanInputContext(input: {
|
|
28
|
+
delivery: "send" | "steer";
|
|
29
|
+
routing: "accepted_for_execution" | "queued_for_execution" | "accepted_for_steering";
|
|
30
|
+
text: string;
|
|
31
|
+
}): string;
|
|
32
|
+
export type RealtimeHumanInputRequestContext = {
|
|
33
|
+
id: string;
|
|
34
|
+
questions: HumanInputQuestion[];
|
|
35
|
+
allowSkip: boolean;
|
|
36
|
+
expiresAt?: Date | string | null;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Render the exact durable question contract for the conversational surface.
|
|
40
|
+
* The structured form remains authoritative, while a conversational answer is
|
|
41
|
+
* ordinary new user input that the realtime model delegates once with enough
|
|
42
|
+
* question context for the next underlying turn.
|
|
43
|
+
*/
|
|
44
|
+
export declare function renderRealtimeHumanInputRequestContext(input: {
|
|
45
|
+
requests: RealtimeHumanInputRequestContext[];
|
|
46
|
+
}): string;
|
|
47
|
+
export declare function renderRealtimeHumanInputResponseContext(input: {
|
|
48
|
+
requestId: string;
|
|
49
|
+
questions: HumanInputQuestion[];
|
|
50
|
+
response: HumanInputResponse;
|
|
51
|
+
}): string;
|
|
@@ -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>;
|