@opengeni/db 0.14.3 → 0.16.2

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 (63) hide show
  1. package/dist/{chunk-ELMUCYZF.js → chunk-4RUK5CON.js} +183 -42
  2. package/dist/chunk-4RUK5CON.js.map +1 -0
  3. package/dist/chunk-HZD7KVAR.js +4648 -0
  4. package/dist/chunk-HZD7KVAR.js.map +1 -0
  5. package/dist/{chunk-Y5WZZVQK.js → chunk-SK7YYHBI.js} +5 -2
  6. package/dist/chunk-SK7YYHBI.js.map +1 -0
  7. package/dist/codex-token-resolver.d.ts +64 -0
  8. package/dist/connection-token-resolver.d.ts +90 -0
  9. package/dist/environment-crypto.d.ts +11 -0
  10. package/dist/event-payload-sanitizer.d.ts +32 -0
  11. package/dist/index.d.ts +6217 -10
  12. package/dist/index.js +6930 -2708
  13. package/dist/index.js.map +1 -1
  14. package/dist/insights.d.ts +157 -0
  15. package/dist/memory-domain.d.ts +44 -0
  16. package/dist/migrate.d.ts +5 -7
  17. package/dist/migrate.js +1 -1
  18. package/dist/new-session-drafts.d.ts +49 -0
  19. package/dist/persistence-errors.d.ts +69 -0
  20. package/dist/preference-registry-schema.d.ts +1147 -0
  21. package/dist/preference-registry.d.ts +878 -0
  22. package/dist/provision-roles.d.ts +4 -6489
  23. package/dist/provision-roles.js +1 -1
  24. package/dist/role-relationships.d.ts +35 -0
  25. package/dist/runtime-posture-cli.d.ts +1 -0
  26. package/dist/runtime-posture.d.ts +103 -0
  27. package/dist/schema.d.ts +23533 -3
  28. package/dist/schema.js +17 -1
  29. package/dist/session-control.d.ts +331 -0
  30. package/dist/session-queue-commands.d.ts +186 -0
  31. package/dist/session-tool-call-settlement.d.ts +32 -0
  32. package/dist/turn-initiator.d.ts +28 -0
  33. package/dist/workspace-instruction-policies-schema.d.ts +735 -0
  34. package/dist/workspace-instruction-policies.d.ts +64 -0
  35. package/drizzle/0136_unified_session_tool_policy.sql +1 -1
  36. package/drizzle/0137_preference_registry.sql +1347 -0
  37. package/drizzle/0138_sandbox_checkpoint_artifacts_and_deadlines.sql +1074 -0
  38. package/drizzle/0139_codex_provider_artifact_invalidations.sql +51 -0
  39. package/drizzle/0140_sandbox_restore_and_reaper_fences.sql +276 -0
  40. package/drizzle/0142_sandbox_archive_capture_gate.sql +80 -0
  41. package/drizzle/0143_session_codex_compaction_mode.sql +20 -0
  42. package/drizzle/0144_sandbox_viewer_force_drain_gate.sql +95 -0
  43. package/drizzle/0145_model_call_facts.sql +96 -0
  44. package/drizzle/0146_slack_bot_delete_idempotency.sql +105 -0
  45. package/drizzle/0147_draft_latency_mode.sql +12 -0
  46. package/drizzle/0148_session_turn_latency_mode.sql +12 -0
  47. package/package.json +6 -6
  48. package/src/index.ts +4995 -421
  49. package/src/insights.ts +837 -0
  50. package/src/migrate.ts +9 -1
  51. package/src/new-session-drafts.ts +4 -0
  52. package/src/preference-registry-schema.ts +170 -0
  53. package/src/preference-registry.ts +1220 -0
  54. package/src/provision-roles.ts +95 -22
  55. package/src/role-relationships.ts +132 -0
  56. package/src/runtime-posture.ts +28 -26
  57. package/src/schema.ts +478 -5
  58. package/src/session-queue-commands.ts +39 -6
  59. package/dist/chunk-DW24CKCT.js +0 -4046
  60. package/dist/chunk-DW24CKCT.js.map +0 -1
  61. package/dist/chunk-ELMUCYZF.js.map +0 -1
  62. package/dist/chunk-Y5WZZVQK.js.map +0 -1
  63. package/dist/schema-DhkRhcuQ.d.ts +0 -22666
package/dist/schema.js CHANGED
@@ -38,12 +38,19 @@ import {
38
38
  machineMetricsLatest,
39
39
  machineMetricsSeries,
40
40
  managedAccounts,
41
+ modelCallFacts,
41
42
  nestedAgentDepthConfiguration,
42
43
  newSessionDrafts,
43
44
  packInstallations,
45
+ preferenceRegistryEvents,
46
+ preferenceRegistryPreferences,
47
+ preferenceRegistryRevisions,
48
+ preferenceRegistrySnapshots,
44
49
  rigChanges,
45
50
  rigVersions,
46
51
  rigs,
52
+ sandboxCheckpointArtifactStateValues,
53
+ sandboxCheckpointArtifacts,
47
54
  sandboxKindValues,
48
55
  sandboxLeaseHolders,
49
56
  sandboxLeaseLivenessValues,
@@ -79,6 +86,7 @@ import {
79
86
  sessionTurns,
80
87
  sessionWorkflowWakeOutbox,
81
88
  sessions,
89
+ slackBotDeleteOperations,
82
90
  slackBotPostOperations,
83
91
  socialConnections,
84
92
  socialPosts,
@@ -97,7 +105,7 @@ import {
97
105
  workspaceVariableSetVariables,
98
106
  workspaceVariableSets,
99
107
  workspaces
100
- } from "./chunk-DW24CKCT.js";
108
+ } from "./chunk-HZD7KVAR.js";
101
109
  import "./chunk-PZ5AY32C.js";
102
110
  export {
103
111
  agentRunStates,
@@ -139,12 +147,19 @@ export {
139
147
  machineMetricsLatest,
140
148
  machineMetricsSeries,
141
149
  managedAccounts,
150
+ modelCallFacts,
142
151
  nestedAgentDepthConfiguration,
143
152
  newSessionDrafts,
144
153
  packInstallations,
154
+ preferenceRegistryEvents,
155
+ preferenceRegistryPreferences,
156
+ preferenceRegistryRevisions,
157
+ preferenceRegistrySnapshots,
145
158
  rigChanges,
146
159
  rigVersions,
147
160
  rigs,
161
+ sandboxCheckpointArtifactStateValues,
162
+ sandboxCheckpointArtifacts,
148
163
  sandboxKindValues,
149
164
  sandboxLeaseHolders,
150
165
  sandboxLeaseLivenessValues,
@@ -180,6 +195,7 @@ export {
180
195
  sessionTurns,
181
196
  sessionWorkflowWakeOutbox,
182
197
  sessions,
198
+ slackBotDeleteOperations,
183
199
  slackBotPostOperations,
184
200
  socialConnections,
185
201
  socialPosts,
@@ -0,0 +1,331 @@
1
+ import { type SessionMcpApprovalPolicy, type TurnInitiatorContext } from "@opengeni/contracts";
2
+ import type { Database } from "./index";
3
+ import * as schema from "./schema";
4
+ export declare const SESSION_ANCESTRY_LIMIT = 10000;
5
+ export type WorkspaceControlLockMode = "none" | "share" | "update";
6
+ export type EffectiveControlState = "active" | "paused";
7
+ export type SessionCommandActor = {
8
+ type: "human" | "operator";
9
+ subjectId: string;
10
+ } | {
11
+ type: "service";
12
+ subjectId: string;
13
+ subjectLabel?: string;
14
+ context?: TurnInitiatorContext;
15
+ } | {
16
+ type: "agent_attempt";
17
+ attemptId: string;
18
+ sessionId: string;
19
+ turnId: string;
20
+ executionGeneration: number;
21
+ };
22
+ export type SessionTurnAttemptOutcome = "completed" | "failed" | "cancelled" | "superseded" | "requires_action" | "waiting_capacity" | "interrupted_recoverable" | "lease_lost_recoverable" | "pre_cutover_closed";
23
+ export type EffectiveControlBlocker = {
24
+ kind: "session" | "workspace";
25
+ sessionId?: string;
26
+ displayName: string;
27
+ actor: string | null;
28
+ reason: string | null;
29
+ changedAt: Date | null;
30
+ revision: number;
31
+ };
32
+ export type EffectiveControlResumeOption = {
33
+ scope: "selected" | "session" | "workspace";
34
+ targetId?: string;
35
+ selectedStateAfter: EffectiveControlState;
36
+ remainingPrimaryBlocker?: EffectiveControlBlocker;
37
+ impactCopy: string;
38
+ };
39
+ export type EffectiveSessionControl = {
40
+ state: EffectiveControlState;
41
+ controlVersion: number;
42
+ controlEtag: string;
43
+ directState: EffectiveControlState;
44
+ primaryBlocker: EffectiveControlBlocker | null;
45
+ additionalBlockerCount: number;
46
+ blockers: EffectiveControlBlocker[];
47
+ resumeOptions: EffectiveControlResumeOption[];
48
+ override: {
49
+ rootSessionId: string;
50
+ revision: number;
51
+ } | null;
52
+ settlement: {
53
+ state: "stopping";
54
+ attemptCount: number;
55
+ interruptionPendingCount: number;
56
+ quiescencePendingCount: number;
57
+ } | null;
58
+ };
59
+ export declare const SESSION_DISCOVERY_CONTROL_TITLE_MAX_CHARS = 200;
60
+ export declare const SESSION_DISCOVERY_CONTROL_TARGET_LIMIT = 100;
61
+ /**
62
+ * Purpose-built control projection for session discovery. Full blocker evidence,
63
+ * actors/reasons, resume options, etags, and settlement state remain available
64
+ * from the ordinary session detail APIs; this shape is intentionally only what
65
+ * `sessions_list` renders.
66
+ */
67
+ export type SessionDiscoveryControl = {
68
+ state: EffectiveControlState;
69
+ primaryBlocker: {
70
+ kind: "session" | "workspace";
71
+ sessionId?: string;
72
+ displayName: string;
73
+ displayNameOriginalChars: number;
74
+ } | null;
75
+ additionalBlockerCount: number;
76
+ };
77
+ export declare function serializeEffectiveSessionControl(control: EffectiveSessionControl): {
78
+ state: EffectiveControlState;
79
+ controlVersion: number;
80
+ controlEtag: string;
81
+ directState: EffectiveControlState;
82
+ additionalBlockerCount: number;
83
+ override: {
84
+ rootSessionId: string;
85
+ revision: number;
86
+ } | null;
87
+ settlement: {
88
+ state: "stopping";
89
+ attemptCount: number;
90
+ interruptionPendingCount: number;
91
+ quiescencePendingCount: number;
92
+ } | null;
93
+ primaryBlocker: (Omit<EffectiveControlBlocker, "changedAt"> & {
94
+ changedAt: string | null;
95
+ }) | null;
96
+ blockers: (Omit<EffectiveControlBlocker, "changedAt"> & {
97
+ changedAt: string | null;
98
+ })[];
99
+ resumeOptions: {
100
+ scope: "selected" | "session" | "workspace";
101
+ targetId?: string;
102
+ selectedStateAfter: EffectiveControlState;
103
+ impactCopy: string;
104
+ remainingPrimaryBlocker?: Omit<EffectiveControlBlocker, "changedAt"> & {
105
+ changedAt: string | null;
106
+ };
107
+ }[];
108
+ };
109
+ export type WorkspaceControlRow = {
110
+ workspaceId: string;
111
+ accountId: string;
112
+ revision: number | string;
113
+ workspaceState: string;
114
+ workspacePauseRevision: number | string | null;
115
+ reason: string | null;
116
+ changedBy: string | null;
117
+ changedAt: Date | string | null;
118
+ };
119
+ export type SessionCommandReceiptRow = typeof schema.sessionCommandReceipts.$inferSelect;
120
+ export declare class SessionControlInvariantError extends Error {
121
+ readonly code = "SESSION_CONTROL_INVARIANT";
122
+ constructor(message: string);
123
+ }
124
+ export declare class SessionControlConflictError extends Error {
125
+ readonly code = "CONTROL_CHANGED";
126
+ constructor(message?: string);
127
+ }
128
+ export declare class SessionCommandIdempotencyError extends Error {
129
+ readonly code = "IDEMPOTENCY_KEY_REUSED";
130
+ constructor();
131
+ }
132
+ export declare class AgentCommandAuthorityError extends Error {
133
+ readonly code: "CALLER_STALE" | "CALLER_INTERRUPTED" | "SELF_OR_ANCESTOR_PAUSE" | "SELF_STEER";
134
+ constructor(code: "CALLER_STALE" | "CALLER_INTERRUPTED" | "SELF_OR_ANCESTOR_PAUSE" | "SELF_STEER", message: string);
135
+ }
136
+ export declare function assertAgentCommandAuthorityInTransaction(db: Database, input: {
137
+ workspaceId: string;
138
+ actor: Extract<SessionCommandActor, {
139
+ type: "agent_attempt";
140
+ }>;
141
+ targetSessionId: string;
142
+ action: "pause" | "resume" | "steer" | "message" | "goal";
143
+ }): Promise<void>;
144
+ export declare function canonicalSessionCommandHash(value: unknown): string;
145
+ export declare function lockWorkspaceInferenceControl(db: Database, workspaceId: string, mode: WorkspaceControlLockMode): Promise<WorkspaceControlRow>;
146
+ export type SessionEventWriteLockInput = {
147
+ workspaceId: string;
148
+ /**
149
+ * Control-aware writes take this lock first. Callers that already hold the
150
+ * workspace control row (for example a Pause mutation under FOR UPDATE) say
151
+ * `already_locked`; ordinary audit/title appends explicitly use `none`.
152
+ */
153
+ controlLock: WorkspaceControlLockMode | "already_locked" | "none";
154
+ /** Used only when a staged caller already established the workspace prefix. */
155
+ workspaceLock?: "key_share" | "already_locked";
156
+ sessionIds?: string[];
157
+ turnIds?: string[];
158
+ attemptIds?: string[];
159
+ };
160
+ export type SessionEventWriteLocks = {
161
+ control: WorkspaceControlRow | null;
162
+ workspace: typeof schema.workspaces.$inferSelect | null;
163
+ sessions: Array<typeof schema.sessions.$inferSelect>;
164
+ turns: Array<typeof schema.sessionTurns.$inferSelect>;
165
+ attempts: Array<typeof schema.sessionTurnAttempts.$inferSelect>;
166
+ };
167
+ /**
168
+ * Establish the one canonical lock prefix for every `session_events` writer:
169
+ *
170
+ * workspace_inference_controls (when control-aware)
171
+ * -> actual workspaces row FOR KEY SHARE
172
+ * -> session rows FOR UPDATE, UUID ordered
173
+ * -> exact turn rows FOR UPDATE, UUID ordered
174
+ * -> exact attempt rows FOR UPDATE, UUID ordered
175
+ *
176
+ * `FOR KEY SHARE` is deliberate. Event inserts need the workspace key to remain
177
+ * stable for their FK, but they do not mutate the workspace. The old generic
178
+ * `FOR UPDATE` lock serialized unrelated sessions and inverted the activity
179
+ * path's session -> implicit workspace-FK edge.
180
+ *
181
+ * Complex lifecycle transactions may acquire allocator/control locks before
182
+ * this helper and may discover exact turn IDs only after locking the session.
183
+ * They use the explicit `already_locked` stages, while retaining the same
184
+ * monotonic table order. New event writers should prefer one complete call.
185
+ */
186
+ export declare function lockSessionEventWriteRows(db: Database, input: SessionEventWriteLockInput): Promise<SessionEventWriteLocks>;
187
+ export declare function registerSessionTurnAttemptClaim(db: Database, input: {
188
+ id: string;
189
+ accountId: string;
190
+ workspaceId: string;
191
+ sessionId: string;
192
+ turnId: string;
193
+ executionGeneration: number;
194
+ temporalWorkflowId: string;
195
+ temporalWorkflowRunId: string;
196
+ temporalActivityId: string;
197
+ verifiedControlRevision: number;
198
+ mcpApprovalPolicies: Record<string, SessionMcpApprovalPolicy>;
199
+ }): Promise<typeof schema.sessionTurnAttempts.$inferSelect>;
200
+ /**
201
+ * Close the exact first-class owner while the caller still holds the owning
202
+ * session/turn locks. Every path that clears `session_turns.active_attempt_id`
203
+ * must call this in the same transaction; otherwise a later claim would either
204
+ * collide with a zombie live owner or have to weaken the ownership fence.
205
+ */
206
+ export declare function closeSessionTurnAttemptInTransaction(db: Database, input: {
207
+ id: string;
208
+ accountId: string;
209
+ workspaceId: string;
210
+ sessionId: string;
211
+ turnId: string;
212
+ executionGeneration: number;
213
+ outcome: SessionTurnAttemptOutcome;
214
+ closedAt?: Date;
215
+ }): Promise<{
216
+ action: "closed" | "already_closed";
217
+ }>;
218
+ export declare function evaluateSessionControls(db: Database, workspaceId: string, sessionIds: string[], options?: {
219
+ lock?: WorkspaceControlLockMode;
220
+ /** Reuse a control row already locked before workspace/session/turn rows. */
221
+ workspaceControl?: WorkspaceControlRow | undefined;
222
+ }): Promise<Map<string, EffectiveSessionControl>>;
223
+ /**
224
+ * Return one compact aggregate row per target for `sessions_list`.
225
+ *
226
+ * Unlike `evaluateSessionControls`, the database boundary never returns a row
227
+ * per blocker/ancestor, nor does application code construct blocker or resume
228
+ * option arrays. The recursive walk carries no growing visited-path array: a
229
+ * missing ancestor stops below the limit, while a cycle cannot reach a root and
230
+ * therefore runs into the hard `SESSION_ANCESTRY_LIMIT`. The externally
231
+ * supplied target set is capped by `SESSION_DISCOVERY_CONTROL_TARGET_LIMIT`.
232
+ */
233
+ export declare function evaluateSessionDiscoveryControls(db: Database, workspaceId: string, sessionIds: string[]): Promise<Map<string, SessionDiscoveryControl>>;
234
+ export declare function evaluateSessionControl(db: Database, workspaceId: string, sessionId: string, options?: {
235
+ lock?: WorkspaceControlLockMode;
236
+ workspaceControl?: WorkspaceControlRow | undefined;
237
+ }): Promise<EffectiveSessionControl>;
238
+ export declare function reserveSessionCommandReceipt(db: Database, input: {
239
+ accountId: string;
240
+ workspaceId: string;
241
+ actor: SessionCommandActor;
242
+ action: string;
243
+ targetSessionId: string | null;
244
+ targetTurnId: string | null;
245
+ operationKey: string;
246
+ canonicalRequestHash: string;
247
+ identityScope?: "actor" | "goal_operation";
248
+ }): Promise<{
249
+ receipt: SessionCommandReceiptRow;
250
+ replay: boolean;
251
+ }>;
252
+ /** Register one exact post-commit Temporal nudge without encoding eligibility in
253
+ * the transport. The workflow re-reads canonical Postgres state; coalescing is
254
+ * revisioned so a lost or stale delivery cannot hide a later mutation. */
255
+ export declare function registerSessionWorkflowWakeInTransaction(db: Database, input: {
256
+ accountId: string;
257
+ workspaceId: string;
258
+ sessionId: string;
259
+ temporalWorkflowId: string;
260
+ reason: string;
261
+ }): Promise<number>;
262
+ /**
263
+ * Internal producers share one outstanding session-level receipt. While a wake
264
+ * remains undelivered, another update makes that same batch richer instead of
265
+ * manufacturing another transport revision or sequential model turn.
266
+ */
267
+ export declare function registerInternalUpdateWakeInTransaction(db: Database, input: {
268
+ accountId: string;
269
+ workspaceId: string;
270
+ sessionId: string;
271
+ temporalWorkflowId: string;
272
+ }): Promise<{
273
+ wakeRevision: number;
274
+ shouldSignal: boolean;
275
+ }>;
276
+ export declare function updateSessionCommandReceiptResult(db: Database, receiptId: string, input: {
277
+ controlRevision?: number | null;
278
+ queueVersion?: number | null;
279
+ turnVersion?: number | null;
280
+ draftRevision?: number | null;
281
+ result: Record<string, unknown>;
282
+ }): Promise<SessionCommandReceiptRow>;
283
+ export type SessionControlMutationResult = {
284
+ receipt: SessionCommandReceiptRow;
285
+ control: EffectiveSessionControl;
286
+ sessionControlEventId: string;
287
+ workspaceControlEventId: string;
288
+ interruptionCount: number;
289
+ wakeCount: number;
290
+ replay: boolean;
291
+ };
292
+ export declare function mutateSessionControlInTransaction(db: Database, input: {
293
+ accountId: string;
294
+ workspaceId: string;
295
+ sessionId: string;
296
+ actor: SessionCommandActor;
297
+ operationKey: string;
298
+ action: "pause" | "resume";
299
+ reason?: string | null;
300
+ expectedControlEtag?: string | null;
301
+ }): Promise<SessionControlMutationResult>;
302
+ export declare function autoResumeSessionBranchInTransaction(db: Database, input: {
303
+ workspaceId: string;
304
+ sessionId: string;
305
+ actor: string;
306
+ reason: "human_send" | "human_steer" | "service_send" | "service_steer" | "agent_steer";
307
+ observedControlEtag?: string | null;
308
+ }): Promise<{
309
+ revision: number;
310
+ control: EffectiveSessionControl;
311
+ changed: boolean;
312
+ workspaceControlEventId: string | null;
313
+ }>;
314
+ export type WorkspaceControlMutationResult = {
315
+ receipt: SessionCommandReceiptRow;
316
+ revision: number;
317
+ workspaceControlEventId: string;
318
+ workspaceState: EffectiveControlState;
319
+ interruptionCount: number;
320
+ wakeCount: number;
321
+ replay: boolean;
322
+ };
323
+ export declare function mutateWorkspaceControlInTransaction(db: Database, input: {
324
+ accountId: string;
325
+ workspaceId: string;
326
+ actor: SessionCommandActor;
327
+ operationKey: string;
328
+ action: "pause" | "resume";
329
+ reason?: string | null;
330
+ expectedRevision?: number | null;
331
+ }): Promise<WorkspaceControlMutationResult>;
@@ -0,0 +1,186 @@
1
+ import { ResourceRef, type LatencyMode, type ReasoningEffort, type TurnExecutionPolicyV1 } from "@opengeni/contracts";
2
+ import type { Database } from "./index";
3
+ import { type SessionCommandActor, type SessionCommandReceiptRow } from "./session-control";
4
+ import * as schema from "./schema";
5
+ export type QueueCommandConflictCode = "QUEUE_VERSION_CHANGED" | "QUEUE_PROMPT_STARTED" | "QUEUE_ANCHOR_CHANGED" | "PROMPT_CHANGED" | "DRAFT_CHANGED" | "DRAFT_NOT_EMPTY" | "EDIT_SOURCE_CHANGED";
6
+ export declare class QueueCommandConflictError extends Error {
7
+ readonly code: QueueCommandConflictCode;
8
+ readonly current: {
9
+ queueVersion: number;
10
+ turnVersion?: number;
11
+ draftRevision?: number;
12
+ };
13
+ readonly name = "QueueCommandConflictError";
14
+ constructor(code: QueueCommandConflictCode, message: string, current: {
15
+ queueVersion: number;
16
+ turnVersion?: number;
17
+ draftRevision?: number;
18
+ });
19
+ }
20
+ export type ComposerDraftRow = typeof schema.composerDrafts.$inferSelect;
21
+ export type QueuedTurnRow = typeof schema.sessionTurns.$inferSelect;
22
+ export type QueueCommandResult = {
23
+ receipt: SessionCommandReceiptRow;
24
+ queueVersion: number;
25
+ items: QueuedTurnRow[];
26
+ eventIds: string[];
27
+ replay: boolean;
28
+ };
29
+ export type EditQueueCommandResult = QueueCommandResult & {
30
+ draft: ComposerDraftRow;
31
+ };
32
+ export type SteerQueueCommandResult = QueueCommandResult & {
33
+ interruptionCount: number;
34
+ workspaceControlEventId: string | null;
35
+ };
36
+ export type SubmitHumanPromptResult = {
37
+ receipt: SessionCommandReceiptRow;
38
+ queueVersion: number;
39
+ acceptedEventId: string;
40
+ eventIds: string[];
41
+ turnId: string;
42
+ wakeRevision: number;
43
+ interruptionCount: number;
44
+ workspaceControlEventId: string | null;
45
+ replay: boolean;
46
+ };
47
+ export type AgentInternalUpdateCommandResult = {
48
+ receipt: SessionCommandReceiptRow;
49
+ updateId: string;
50
+ eventIds: string[];
51
+ wakeRevision: number | null;
52
+ shouldSignal: boolean;
53
+ workflowId: string;
54
+ effectiveState: "active" | "paused";
55
+ interruptionCount: number;
56
+ workspaceControlEventId: string | null;
57
+ replay: boolean;
58
+ };
59
+ type SteerSupersessionResult = {
60
+ interruptionCount: number;
61
+ replacedTurn: typeof schema.sessionTurns.$inferSelect | null;
62
+ liveCurrentTurnId: string | null;
63
+ lastSequence: number;
64
+ };
65
+ /**
66
+ * One canonical replacement transition shared by human row/new-prompt Steer
67
+ * and Agent Steer. A live owner is interrupted and remains current until exact
68
+ * settlement; an ownerless approval/recovery/capacity turn is superseded now.
69
+ */
70
+ export declare function supersedeSessionCurrentDirectionInTransaction(db: Database, input: {
71
+ accountId: string;
72
+ workspaceId: string;
73
+ sessionId: string;
74
+ activeTurnId: string | null;
75
+ actor: SessionCommandActor;
76
+ operationId: string;
77
+ controlRevision: number;
78
+ lastSequence: number;
79
+ }): Promise<SteerSupersessionResult>;
80
+ export declare function getComposerDraftInTransaction(db: Database, input: {
81
+ workspaceId: string;
82
+ sessionId: string;
83
+ subjectId: string;
84
+ lock?: boolean;
85
+ }): Promise<ComposerDraftRow | null>;
86
+ export declare function saveComposerDraftInTransaction(db: Database, input: {
87
+ accountId: string;
88
+ workspaceId: string;
89
+ sessionId: string;
90
+ subjectId: string;
91
+ expectedRevision: number;
92
+ text: string;
93
+ resources: ResourceRef[];
94
+ model: string;
95
+ reasoningEffort: ReasoningEffort;
96
+ latencyMode?: LatencyMode;
97
+ }): Promise<ComposerDraftRow>;
98
+ export declare function moveQueuedTurnInTransaction(db: Database, input: {
99
+ accountId: string;
100
+ workspaceId: string;
101
+ sessionId: string;
102
+ turnId: string;
103
+ beforeTurnId: string | null;
104
+ expectedQueueVersion: number;
105
+ actor: SessionCommandActor;
106
+ operationKey: string;
107
+ }): Promise<QueueCommandResult>;
108
+ export declare function deleteSessionQueueItemInTransaction(db: Database, input: {
109
+ accountId: string;
110
+ workspaceId: string;
111
+ sessionId: string;
112
+ turnId: string;
113
+ expectedTurnVersion: number;
114
+ actor: SessionCommandActor;
115
+ operationKey: string;
116
+ reason?: string | null;
117
+ }): Promise<QueueCommandResult>;
118
+ export declare function editQueuedTurnInTransaction(db: Database, input: {
119
+ accountId: string;
120
+ workspaceId: string;
121
+ sessionId: string;
122
+ turnId: string;
123
+ subjectId: string;
124
+ expectedTurnVersion: number;
125
+ expectedDraftRevision: number;
126
+ replaceDraft: boolean;
127
+ actor: SessionCommandActor;
128
+ operationKey: string;
129
+ }): Promise<EditQueueCommandResult>;
130
+ export declare function steerQueuedTurnInTransaction(db: Database, input: {
131
+ accountId: string;
132
+ workspaceId: string;
133
+ sessionId: string;
134
+ turnId: string;
135
+ expectedTurnVersion: number;
136
+ controlEtag?: string | null;
137
+ actor: SessionCommandActor;
138
+ operationKey: string;
139
+ }): Promise<SteerQueueCommandResult>;
140
+ export declare function submitHumanPromptInTransaction(db: Database, input: {
141
+ accountId: string;
142
+ workspaceId: string;
143
+ sessionId: string;
144
+ subjectId: string;
145
+ subjectLabel?: string;
146
+ actor: SessionCommandActor;
147
+ operationKey: string;
148
+ delivery: "send" | "steer";
149
+ controlEtag?: string | null;
150
+ expectedDraftRevision?: number | null;
151
+ text: string;
152
+ turnInstructions?: string | null;
153
+ resources: ResourceRef[];
154
+ model?: string | null;
155
+ reasoningEffort?: ReasoningEffort | null;
156
+ latencyMode?: LatencyMode | null;
157
+ reasoningEffortFallback: ReasoningEffort;
158
+ /** Trusted API/core admission snapshot. Omitted only by legacy low-level callers. */
159
+ turnExecutionPolicy?: TurnExecutionPolicyV1;
160
+ source: "user" | "api";
161
+ mcpCredentialUpdates?: Array<{
162
+ id: string;
163
+ headersEncrypted: Record<string, string>;
164
+ }>;
165
+ }): Promise<SubmitHumanPromptResult>;
166
+ export declare function sendAgentMessageInTransaction(db: Database, input: {
167
+ accountId: string;
168
+ workspaceId: string;
169
+ targetSessionId: string;
170
+ actor: Extract<SessionCommandActor, {
171
+ type: "agent_attempt";
172
+ }>;
173
+ operationKey: string;
174
+ text: string;
175
+ }): Promise<AgentInternalUpdateCommandResult>;
176
+ export declare function steerAgentSessionInTransaction(db: Database, input: {
177
+ accountId: string;
178
+ workspaceId: string;
179
+ targetSessionId: string;
180
+ actor: Extract<SessionCommandActor, {
181
+ type: "agent_attempt";
182
+ }>;
183
+ operationKey: string;
184
+ instruction: string;
185
+ }): Promise<AgentInternalUpdateCommandResult>;
186
+ export {};
@@ -0,0 +1,32 @@
1
+ import type { SessionEvent } from "@opengeni/contracts";
2
+ import type { Database } from "./index";
3
+ export declare const TOOL_RESULT_TYPE_BY_CALL_TYPE: Readonly<Record<string, string>>;
4
+ export declare function historyCallId(item: Record<string, unknown>): string | null;
5
+ export declare function historyItemType(item: Record<string, unknown>): string | null;
6
+ /** Provider-valid result for a started call whose durable outcome is unknown. */
7
+ export declare function interruptedToolCallResult(input: {
8
+ callType: string;
9
+ callId: string;
10
+ callItem: Record<string, unknown>;
11
+ reason: string;
12
+ }): Record<string, unknown> | null;
13
+ export type ClosePendingSessionToolCallsInput = {
14
+ accountId: string;
15
+ workspaceId: string;
16
+ sessionId: string;
17
+ turnId: string;
18
+ reason: string;
19
+ sequence: number;
20
+ now: Date;
21
+ };
22
+ /**
23
+ * Close every unresolved raw tool call for a logical turn while its owning
24
+ * session/turn locks are held. Durable results win; otherwise the model gets an
25
+ * explicit interrupted/outcome-unknown result for protocols that can represent
26
+ * one. Repeated settlement is an exact no-op after ledger deletion.
27
+ */
28
+ export declare function closePendingSessionToolCallsInTransaction(tx: Database, input: ClosePendingSessionToolCallsInput): Promise<{
29
+ sequence: number;
30
+ events: SessionEvent[];
31
+ closed: number;
32
+ }>;
@@ -0,0 +1,28 @@
1
+ import { type TurnInitiator, type TurnInitiatorContext } from "@opengeni/contracts";
2
+ import type { Database } from "./index";
3
+ import type { SessionCommandActor } from "./session-control";
4
+ export declare const UNATTRIBUTED_LEGACY_INITIATOR: TurnInitiator;
5
+ export type FrozenTurnInitiator = {
6
+ initiator: TurnInitiator;
7
+ context: TurnInitiatorContext;
8
+ };
9
+ /**
10
+ * Bound agent provenance without discarding its causal authority. Once the
11
+ * chain exceeds the cap, retain the first hop and the newest hops in order;
12
+ * consumers can still identify the root attempt while recent diagnostics stay
13
+ * useful. The omitted middle is signalled separately by `viaTruncated`.
14
+ */
15
+ export declare function clipAgentProvenanceHops(hops: Array<Record<string, unknown>>): Array<Record<string, unknown>>;
16
+ export declare function initiatorContextForStorage(initiator: TurnInitiator, context?: TurnInitiatorContext): TurnInitiatorContext;
17
+ export declare function initiatorFromStorage(kind: string, subjectId: string, context: TurnInitiatorContext): TurnInitiator;
18
+ export declare function initiatorColumns(value: FrozenTurnInitiator): {
19
+ initiatorKind: TurnInitiator["kind"];
20
+ initiatorSubjectId: string;
21
+ initiatorContext: TurnInitiatorContext;
22
+ };
23
+ export declare function creatorColumns(value: FrozenTurnInitiator): {
24
+ createdByKind: TurnInitiator["kind"];
25
+ createdBySubjectId: string;
26
+ createdByContext: TurnInitiatorContext;
27
+ };
28
+ export declare function frozenInitiatorForCommandActor(db: Database, workspaceId: string, actor: SessionCommandActor, subjectLabel?: string): Promise<FrozenTurnInitiator>;