@opengeni/db 3.7.4 → 4.0.0-canary.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 (113) hide show
  1. package/dist/automations.d.ts +4 -0
  2. package/dist/canonical-human-identities.js +3 -3
  3. package/dist/capability-integrations.d.ts +2 -0
  4. package/dist/{chunk-6DPJA36C.js → chunk-2XEZK4LF.js} +7 -1
  5. package/dist/chunk-2XEZK4LF.js.map +1 -0
  6. package/dist/{chunk-4NAR7FBA.js → chunk-3RI33YQN.js} +67 -1
  7. package/dist/chunk-3RI33YQN.js.map +1 -0
  8. package/dist/{chunk-SZAWDXQC.js → chunk-CJROYHSC.js} +3 -3
  9. package/dist/{chunk-DZCYW2WT.js → chunk-MX6V5F65.js} +2 -2
  10. package/dist/{chunk-S3TDDCS2.js → chunk-N5VXJ4I2.js} +151 -78
  11. package/dist/chunk-N5VXJ4I2.js.map +1 -0
  12. package/dist/{chunk-U4WPPEBH.js → chunk-NLFHMPUB.js} +2 -2
  13. package/dist/{chunk-5NNCGFQY.js → chunk-P6NSEG2S.js} +2 -2
  14. package/dist/{chunk-O56DM5GZ.js → chunk-QM6YOWHZ.js} +624 -57
  15. package/dist/chunk-QM6YOWHZ.js.map +1 -0
  16. package/dist/{chunk-US4IS6IV.js → chunk-RZNOSEMC.js} +2 -2
  17. package/dist/{chunk-F6PBS6WE.js → chunk-UFAMOUWL.js} +2 -2
  18. package/dist/codemode-operations.d.ts +5 -0
  19. package/dist/codex-token-resolver.d.ts +6 -2
  20. package/dist/connection-token-resolver.d.ts +8 -0
  21. package/dist/editable-artifact-durable-export.js +2 -2
  22. package/dist/editable-artifacts.js +3 -3
  23. package/dist/generated-images.d.ts +15 -0
  24. package/dist/index.d.ts +393 -91
  25. package/dist/index.js +9992 -6069
  26. package/dist/index.js.map +1 -1
  27. package/dist/insights.d.ts +9 -0
  28. package/dist/managed-auth-session-sets.js +3 -3
  29. package/dist/managed-user-setup.d.ts +3 -0
  30. package/dist/mcp-oauth.d.ts +80 -0
  31. package/dist/migrate.d.ts +1 -0
  32. package/dist/migrate.js +3 -1
  33. package/dist/model-catalog.d.ts +153 -0
  34. package/dist/model-context-snapshots.d.ts +20 -0
  35. package/dist/new-session-drafts.d.ts +12 -0
  36. package/dist/organization-membership-lifecycle.d.ts +8 -1
  37. package/dist/organization-model-providers.d.ts +101 -0
  38. package/dist/pack-components.d.ts +1 -0
  39. package/dist/pr-review.d.ts +9 -0
  40. package/dist/provision-roles.js +1 -1
  41. package/dist/runtime-posture.d.ts +8 -8
  42. package/dist/schema.d.ts +7708 -5050
  43. package/dist/schema.js +25 -1
  44. package/dist/session-background-commands.d.ts +18 -6
  45. package/dist/session-background-commands.js +15 -9
  46. package/dist/session-control.d.ts +37 -2
  47. package/dist/session-goal-pacing.d.ts +3 -6
  48. package/dist/session-queue-commands.d.ts +17 -0
  49. package/dist/session-tenancy.js +3 -3
  50. package/dist/tool-gateway-approvals.d.ts +31 -0
  51. package/dist/video-generation.js +3 -3
  52. package/dist/workspace-artifacts.d.ts +17 -3
  53. package/dist/xai-subscription.d.ts +8 -0
  54. package/drizzle/0387_bound_host_export_session_payloads.sql +165 -0
  55. package/drizzle/0388_sandbox_provider_deadline_interactions.sql +491 -0
  56. package/drizzle/0389_model_catalog_and_gateway_custom_models.sql +241 -0
  57. package/drizzle/0390_organization_model_provider_connections.sql +197 -0
  58. package/drizzle/0391_sandbox_provider_deadline_interaction_followup.sql +295 -0
  59. package/drizzle/0392_context_compaction_pending_observability.sql +198 -0
  60. package/drizzle/0393_workspace_memory_and_learning_defaults.sql +102 -0
  61. package/drizzle/0394_session_selected_skill_activation.sql +20 -0
  62. package/drizzle/0395_scheduled_task_unclaimed_occurrence_invalidation.sql +154 -0
  63. package/drizzle/0396_model_call_equivalent_credit_cost.sql +28 -0
  64. package/drizzle/0397_sandbox_deadline_rotation_preemption.sql +113 -0
  65. package/drizzle/0398_organization_workspace_management_entry.sql +206 -0
  66. package/drizzle/0399_additional_managed_organization_creation.sql +691 -0
  67. package/drizzle/0400_session_attempt_model_context_snapshots.sql +65 -0
  68. package/drizzle/0401_organization_user_setup_token_transport.sql +178 -0
  69. package/drizzle/0402_session_input_wait_and_background_command_results.sql +1023 -0
  70. package/drizzle/0403_codex_unconditional_credential_leasing.sql +181 -0
  71. package/drizzle/0404_mcp_oauth_authorization_server.sql +471 -0
  72. package/drizzle/0405_tool_gateway_approval_capabilities.sql +184 -0
  73. package/drizzle/0406_workspace_html_site_sources.sql +71 -0
  74. package/package.json +6 -6
  75. package/src/automations.ts +9 -1
  76. package/src/capability-integrations.ts +8 -0
  77. package/src/codemode-operations.ts +31 -21
  78. package/src/codex-token-resolver.ts +16 -6
  79. package/src/connection-token-resolver.ts +52 -3
  80. package/src/generated-images.ts +70 -6
  81. package/src/index.ts +3894 -994
  82. package/src/insights-model-bundle.ts +54 -5
  83. package/src/insights.ts +53 -7
  84. package/src/managed-user-setup.ts +14 -3
  85. package/src/mcp-oauth.ts +488 -0
  86. package/src/migrate.ts +9 -1
  87. package/src/model-catalog.ts +682 -0
  88. package/src/model-context-snapshots.ts +151 -0
  89. package/src/new-session-drafts.ts +66 -21
  90. package/src/organization-membership-lifecycle.ts +47 -5
  91. package/src/organization-model-providers.ts +614 -0
  92. package/src/pack-components.ts +15 -2
  93. package/src/pr-review.ts +19 -0
  94. package/src/provision-roles.ts +4 -0
  95. package/src/runtime-posture.ts +64 -0
  96. package/src/schema.ts +666 -61
  97. package/src/session-background-commands.ts +180 -78
  98. package/src/session-control.ts +181 -12
  99. package/src/session-goal-pacing.ts +4 -8
  100. package/src/session-queue-commands.ts +157 -82
  101. package/src/tool-gateway-approvals.ts +168 -0
  102. package/src/workspace-artifacts.ts +633 -178
  103. package/src/xai-subscription.ts +66 -14
  104. package/dist/chunk-4NAR7FBA.js.map +0 -1
  105. package/dist/chunk-6DPJA36C.js.map +0 -1
  106. package/dist/chunk-O56DM5GZ.js.map +0 -1
  107. package/dist/chunk-S3TDDCS2.js.map +0 -1
  108. /package/dist/{chunk-SZAWDXQC.js.map → chunk-CJROYHSC.js.map} +0 -0
  109. /package/dist/{chunk-DZCYW2WT.js.map → chunk-MX6V5F65.js.map} +0 -0
  110. /package/dist/{chunk-U4WPPEBH.js.map → chunk-NLFHMPUB.js.map} +0 -0
  111. /package/dist/{chunk-5NNCGFQY.js.map → chunk-P6NSEG2S.js.map} +0 -0
  112. /package/dist/{chunk-US4IS6IV.js.map → chunk-RZNOSEMC.js.map} +0 -0
  113. /package/dist/{chunk-F6PBS6WE.js.map → chunk-UFAMOUWL.js.map} +0 -0
package/dist/schema.js CHANGED
@@ -62,6 +62,7 @@ import {
62
62
  connectorActionPolicies,
63
63
  connectorActionRequests,
64
64
  creditLedgerEntries,
65
+ deploymentModelCatalog,
65
66
  deviceEnrollmentRequests,
66
67
  deviceEnrollmentStatusValues,
67
68
  documentBases,
@@ -154,6 +155,11 @@ import {
154
155
  managedAuthLoginTransactions,
155
156
  managedAuthSessionSetOperations,
156
157
  managedAuthSessionSets,
158
+ mcpOauthAccessTokens,
159
+ mcpOauthAuthorizationCodes,
160
+ mcpOauthAuthorizationRequests,
161
+ mcpOauthClients,
162
+ mcpOauthRefreshTokens,
157
163
  memorySlackPublicationConfigurations,
158
164
  memorySlackPublicationReceipts,
159
165
  memorySlackPublications,
@@ -169,6 +175,9 @@ import {
169
175
  organizationMembershipLifecycleEvents,
170
176
  organizationMembershipOperationReceipts,
171
177
  organizationMemberships,
178
+ organizationModelProviderConnectionOperations,
179
+ organizationModelProviderConnections,
180
+ organizationModelProviderCustomModels,
172
181
  organizationPrivateSessionSettingEvents,
173
182
  organizationPrivateSessionSettings,
174
183
  organizationProfileEvents,
@@ -225,6 +234,7 @@ import {
225
234
  scheduledTasks,
226
235
  sessionAttemptCodemodeCalls,
227
236
  sessionAttemptInterruptions,
237
+ sessionAttemptModelContextSnapshots,
228
238
  sessionAttemptToolCatalogs,
229
239
  sessionBackgroundCommands,
230
240
  sessionCommandReceipts,
@@ -289,6 +299,7 @@ import {
289
299
  taskNoteWriteCapabilities,
290
300
  taskNotes,
291
301
  temporalScheduleCleanupOutbox,
302
+ toolGatewayApprovalCapabilities,
292
303
  transcriptionRecordingChunkStateValues,
293
304
  transcriptionRecordingChunks,
294
305
  transcriptionRecordingObjectKindValues,
@@ -310,6 +321,7 @@ import {
310
321
  workspaceCaptures,
311
322
  workspaceCodexSubscriptionPreferences,
312
323
  workspaceControlEvents,
324
+ workspaceGatewayCustomModels,
313
325
  workspaceInferenceControls,
314
326
  workspaceInstructionPolicyActivationEvents,
315
327
  workspaceInstructionPolicyDeactivationEvents,
@@ -337,7 +349,7 @@ import {
337
349
  xaiRotationSettings,
338
350
  xaiSessionAccountPins,
339
351
  xaiSubscriptionCredentials
340
- } from "./chunk-O56DM5GZ.js";
352
+ } from "./chunk-QM6YOWHZ.js";
341
353
  import "./chunk-PZ5AY32C.js";
342
354
  export {
343
355
  agentRunStates,
@@ -403,6 +415,7 @@ export {
403
415
  connectorActionPolicies,
404
416
  connectorActionRequests,
405
417
  creditLedgerEntries,
418
+ deploymentModelCatalog,
406
419
  deviceEnrollmentRequests,
407
420
  deviceEnrollmentStatusValues,
408
421
  documentBases,
@@ -495,6 +508,11 @@ export {
495
508
  managedAuthLoginTransactions,
496
509
  managedAuthSessionSetOperations,
497
510
  managedAuthSessionSets,
511
+ mcpOauthAccessTokens,
512
+ mcpOauthAuthorizationCodes,
513
+ mcpOauthAuthorizationRequests,
514
+ mcpOauthClients,
515
+ mcpOauthRefreshTokens,
498
516
  memorySlackPublicationConfigurations,
499
517
  memorySlackPublicationReceipts,
500
518
  memorySlackPublications,
@@ -510,6 +528,9 @@ export {
510
528
  organizationMembershipLifecycleEvents,
511
529
  organizationMembershipOperationReceipts,
512
530
  organizationMemberships,
531
+ organizationModelProviderConnectionOperations,
532
+ organizationModelProviderConnections,
533
+ organizationModelProviderCustomModels,
513
534
  organizationPrivateSessionSettingEvents,
514
535
  organizationPrivateSessionSettings,
515
536
  organizationProfileEvents,
@@ -566,6 +587,7 @@ export {
566
587
  scheduledTasks,
567
588
  sessionAttemptCodemodeCalls,
568
589
  sessionAttemptInterruptions,
590
+ sessionAttemptModelContextSnapshots,
569
591
  sessionAttemptToolCatalogs,
570
592
  sessionBackgroundCommands,
571
593
  sessionCommandReceipts,
@@ -630,6 +652,7 @@ export {
630
652
  taskNoteWriteCapabilities,
631
653
  taskNotes,
632
654
  temporalScheduleCleanupOutbox,
655
+ toolGatewayApprovalCapabilities,
633
656
  transcriptionRecordingChunkStateValues,
634
657
  transcriptionRecordingChunks,
635
658
  transcriptionRecordingObjectKindValues,
@@ -651,6 +674,7 @@ export {
651
674
  workspaceCaptures,
652
675
  workspaceCodexSubscriptionPreferences,
653
676
  workspaceControlEvents,
677
+ workspaceGatewayCustomModels,
654
678
  workspaceInferenceControls,
655
679
  workspaceInstructionPolicyActivationEvents,
656
680
  workspaceInstructionPolicyDeactivationEvents,
@@ -1,11 +1,17 @@
1
1
  import type { SessionBackgroundCommand, SessionBackgroundCommandActivity } from "@opengeni/contracts";
2
- import type { Database } from "./database.js";
2
+ import type { Database, SessionActivityDatabase } from "./database.js";
3
3
  export type ConnectedMachineBackgroundCommandProof = {
4
4
  outcome: "exited" | "lost";
5
5
  exitCode: number | null;
6
6
  reason: string;
7
7
  observedAt: Date;
8
8
  };
9
+ export declare const SESSION_BACKGROUND_COMMAND_REASON_MAX_BYTES = 512;
10
+ export declare function boundedSessionBackgroundCommandReason(value: string, label: string): string;
11
+ export type SessionBackgroundCommandTerminalMutation = {
12
+ prepare: (tx: SessionActivityDatabase) => Promise<void>;
13
+ commit: (tx: SessionActivityDatabase, command: SessionBackgroundCommand) => Promise<void>;
14
+ };
9
15
  export type ConnectedMachineBackgroundCommandClaim = {
10
16
  commandId: string;
11
17
  accountId: string;
@@ -71,9 +77,9 @@ export declare function deferConnectedMachineBackgroundCommandReconciliation(db:
71
77
  retryAfterMs: number;
72
78
  }): Promise<boolean>;
73
79
  /** Settle only from the proof already checkpointed under this exact claim. */
74
- export declare function settleClaimedConnectedMachineBackgroundCommand(db: Database, input: {
80
+ export declare function settleClaimedConnectedMachineBackgroundCommandWithMutation(db: Database, input: {
75
81
  claim: ConnectedMachineBackgroundCommandClaim;
76
- }): Promise<boolean>;
82
+ }, mutateTerminal: SessionBackgroundCommandTerminalMutation): Promise<boolean>;
77
83
  export declare function requestSessionBackgroundCommandCancellation(db: Database, input: {
78
84
  accountId: string;
79
85
  workspaceId: string;
@@ -101,7 +107,7 @@ export declare function requestWorkspaceBackgroundCommandCancellationsInTransact
101
107
  workspaceId: string;
102
108
  subjectId: string;
103
109
  }): Promise<number>;
104
- export declare function settleSessionBackgroundCommandForRetainedProcess(db: Database, input: {
110
+ export declare function settleSessionBackgroundCommandForRetainedProcessInTransaction(tx: SessionActivityDatabase, input: {
105
111
  accountId: string;
106
112
  workspaceId: string;
107
113
  sessionId: string;
@@ -109,8 +115,8 @@ export declare function settleSessionBackgroundCommandForRetainedProcess(db: Dat
109
115
  outcome: "exited" | "lost";
110
116
  exitCode: number | null;
111
117
  reason: string;
112
- }): Promise<SessionBackgroundCommand | null>;
113
- export declare function settleConnectedMachineSessionBackgroundCommand(db: Database, input: {
118
+ }, mutateTerminal: SessionBackgroundCommandTerminalMutation): Promise<SessionBackgroundCommand | null>;
119
+ export declare function settleConnectedMachineSessionBackgroundCommandWithMutation(db: Database, input: {
114
120
  accountId: string;
115
121
  workspaceId: string;
116
122
  sessionId: string;
@@ -122,4 +128,10 @@ export declare function settleConnectedMachineSessionBackgroundCommand(db: Datab
122
128
  outcome: "exited" | "lost";
123
129
  exitCode: number | null;
124
130
  reason: string;
131
+ }, mutateTerminal: SessionBackgroundCommandTerminalMutation): Promise<SessionBackgroundCommand | null>;
132
+ export declare function getSessionBackgroundCommand(db: Database, input: {
133
+ accountId: string;
134
+ workspaceId: string;
135
+ sessionId: string;
136
+ commandId: string;
125
137
  }): Promise<SessionBackgroundCommand | null>;
@@ -1,7 +1,10 @@
1
1
  import {
2
+ SESSION_BACKGROUND_COMMAND_REASON_MAX_BYTES,
2
3
  backgroundCommandActivityForSessions,
4
+ boundedSessionBackgroundCommandReason,
3
5
  claimConnectedMachineSessionBackgroundCommands,
4
6
  deferConnectedMachineBackgroundCommandReconciliation,
7
+ getSessionBackgroundCommand,
5
8
  insertConnectedMachineSessionBackgroundCommandInTransaction,
6
9
  insertManagedSessionBackgroundCommandInTransaction,
7
10
  listSessionBackgroundCommands,
@@ -9,17 +12,20 @@ import {
9
12
  requestSessionBackgroundCommandCancellation,
10
13
  requestSessionBackgroundCommandCancellationsInTransaction,
11
14
  requestWorkspaceBackgroundCommandCancellationsInTransaction,
12
- settleClaimedConnectedMachineBackgroundCommand,
13
- settleConnectedMachineSessionBackgroundCommand,
14
- settleSessionBackgroundCommandForRetainedProcess
15
- } from "./chunk-S3TDDCS2.js";
16
- import "./chunk-F6PBS6WE.js";
17
- import "./chunk-O56DM5GZ.js";
15
+ settleClaimedConnectedMachineBackgroundCommandWithMutation,
16
+ settleConnectedMachineSessionBackgroundCommandWithMutation,
17
+ settleSessionBackgroundCommandForRetainedProcessInTransaction
18
+ } from "./chunk-N5VXJ4I2.js";
19
+ import "./chunk-UFAMOUWL.js";
20
+ import "./chunk-QM6YOWHZ.js";
18
21
  import "./chunk-PZ5AY32C.js";
19
22
  export {
23
+ SESSION_BACKGROUND_COMMAND_REASON_MAX_BYTES,
20
24
  backgroundCommandActivityForSessions,
25
+ boundedSessionBackgroundCommandReason,
21
26
  claimConnectedMachineSessionBackgroundCommands,
22
27
  deferConnectedMachineBackgroundCommandReconciliation,
28
+ getSessionBackgroundCommand,
23
29
  insertConnectedMachineSessionBackgroundCommandInTransaction,
24
30
  insertManagedSessionBackgroundCommandInTransaction,
25
31
  listSessionBackgroundCommands,
@@ -27,8 +33,8 @@ export {
27
33
  requestSessionBackgroundCommandCancellation,
28
34
  requestSessionBackgroundCommandCancellationsInTransaction,
29
35
  requestWorkspaceBackgroundCommandCancellationsInTransaction,
30
- settleClaimedConnectedMachineBackgroundCommand,
31
- settleConnectedMachineSessionBackgroundCommand,
32
- settleSessionBackgroundCommandForRetainedProcess
36
+ settleClaimedConnectedMachineBackgroundCommandWithMutation,
37
+ settleConnectedMachineSessionBackgroundCommandWithMutation,
38
+ settleSessionBackgroundCommandForRetainedProcessInTransaction
33
39
  };
34
40
  //# sourceMappingURL=session-background-commands.js.map
@@ -158,7 +158,7 @@ export declare function assertAgentCommandAuthorityInTransaction(db: Database, i
158
158
  type: "agent_attempt";
159
159
  }>;
160
160
  targetSessionId: string;
161
- action: "pause" | "resume" | "steer" | "message" | "goal";
161
+ action: "pause" | "resume" | "steer" | "message" | "goal" | "wait";
162
162
  }): Promise<void>;
163
163
  export declare function canonicalSessionCommandHash(value: unknown): string;
164
164
  /**
@@ -429,6 +429,40 @@ export declare function evaluateSessionControl(db: Database, workspaceId: string
429
429
  lock?: WorkspaceControlLockMode;
430
430
  workspaceControl?: WorkspaceControlRow | undefined;
431
431
  }): Promise<EffectiveSessionControl>;
432
+ export type SessionPromptCommandAction = "prompt.send" | "prompt.steer";
433
+ /**
434
+ * Prompt operation keys are actor-scoped across target sessions and across the
435
+ * Send/Steer action pair. The advisory lock closes the gap left by the legacy
436
+ * action/target-specific unique index without changing old receipt identities.
437
+ */
438
+ export declare function reserveSessionPromptCommandReceipt(db: Database, input: {
439
+ accountId: string;
440
+ workspaceId: string;
441
+ actor: SessionCommandActor;
442
+ action: SessionPromptCommandAction;
443
+ targetSessionId: string;
444
+ operationKey: string;
445
+ canonicalRequestHash: string;
446
+ boundaryRequestHash: string;
447
+ }): Promise<{
448
+ receipt: SessionCommandReceiptRow;
449
+ replay: boolean;
450
+ }>;
451
+ /** Serialize one actor-scoped prompt operation before replay or reservation. */
452
+ export declare function lockSessionPromptCommandOperation(db: Database, input: {
453
+ workspaceId: string;
454
+ actor: SessionCommandActor;
455
+ operationKey: string;
456
+ }): Promise<void>;
457
+ /** Return only a fully committed exact prompt receipt with the new boundary fingerprint. */
458
+ export declare function getCompletedSessionPromptCommandReceipt(db: Database, input: {
459
+ workspaceId: string;
460
+ actor: SessionCommandActor;
461
+ action: SessionPromptCommandAction;
462
+ targetSessionId: string;
463
+ operationKey: string;
464
+ boundaryRequestHash: string;
465
+ }): Promise<SessionCommandReceiptRow | null>;
432
466
  export declare function reserveSessionCommandReceipt(db: Database, input: {
433
467
  accountId: string;
434
468
  workspaceId: string;
@@ -438,7 +472,8 @@ export declare function reserveSessionCommandReceipt(db: Database, input: {
438
472
  targetTurnId: string | null;
439
473
  operationKey: string;
440
474
  canonicalRequestHash: string;
441
- identityScope?: "actor" | "goal_operation";
475
+ identityScope?: "actor" | "target_operation";
476
+ initialResult?: Record<string, unknown>;
442
477
  }): Promise<{
443
478
  receipt: SessionCommandReceiptRow;
444
479
  replay: boolean;
@@ -1,11 +1,8 @@
1
1
  import type { Database } from "./database.js";
2
2
  import * as schema from "./schema.js";
3
- /** Column reset shared by every goal head mutation that retires a `goal_wait` hold. */
4
- export declare const SESSION_GOAL_HOLD_CLEARED: {
5
- readonly continuationHoldTurnId: null;
6
- readonly continuationHoldUntil: null;
7
- readonly continuationHoldReason: null;
8
- readonly continuationHoldSetAt: null;
3
+ /** Clear a terminal unchanged-input continuation fence after newer goal truth. */
4
+ export declare const SESSION_GOAL_SUPPRESSION_CLEARED: {
5
+ readonly continuationSuppressedTurnId: null;
9
6
  };
10
7
  /** The pause reason written when a per-goal or deployment continuation ceiling is reached. */
11
8
  export declare const SESSION_GOAL_CAP_PAUSED_REASON = "max_auto_continuations";
@@ -53,6 +53,18 @@ export type SubmitHumanPromptResult = {
53
53
  workspaceControlEventId: string | null;
54
54
  replay: boolean;
55
55
  };
56
+ export declare function replaySubmittedHumanPromptFromBoundaryReceipt(db: Database, input: {
57
+ workspaceId: string;
58
+ sessionId: string;
59
+ subjectId: string;
60
+ actor: SessionCommandActor;
61
+ operationKey: string;
62
+ delivery: "send" | "steer";
63
+ boundaryRequestHash: string;
64
+ expectedDraftRevision?: number | null;
65
+ /** Wait for an overlapping same-key transaction before checking committed replay truth. */
66
+ serializeOperation?: boolean;
67
+ }): Promise<SubmitHumanPromptResult | null>;
56
68
  export type AgentInternalUpdateCommandResult = {
57
69
  receipt: SessionCommandReceiptRow;
58
70
  updateId: string;
@@ -179,6 +191,8 @@ export declare function submitHumanPromptInTransaction(db: SessionActivityDataba
179
191
  subjectLabel?: string;
180
192
  actor: SessionCommandActor;
181
193
  operationKey: string;
194
+ /** Stable parsed boundary-request identity used before mutable enrichment. */
195
+ boundaryRequestHash?: string;
182
196
  delivery: "send" | "steer";
183
197
  controlEtag?: string | null;
184
198
  expectedDraftRevision?: number | null;
@@ -213,6 +227,9 @@ export declare function submitHumanPromptInTransaction(db: SessionActivityDataba
213
227
  id: string;
214
228
  headersEncrypted: Record<string, string>;
215
229
  }>;
230
+ /** Trusted database-only admission seam. It runs only after a completed
231
+ * operation replay has been ruled out; throwing rolls the prompt back. */
232
+ beforeFreshPromptCommit?: (tx: Database) => Promise<void>;
216
233
  /** Request-scoped callers bound the control prefix wait; lifecycle callers omit it. */
217
234
  controlLockTimeoutMs?: number;
218
235
  }): Promise<SubmitHumanPromptResult>;
@@ -14,9 +14,9 @@ import {
14
14
  replayAppliedSessionFork,
15
15
  sessionTenancyProductActivated,
16
16
  transitionSessionVisibility
17
- } from "./chunk-5NNCGFQY.js";
18
- import "./chunk-F6PBS6WE.js";
19
- import "./chunk-O56DM5GZ.js";
17
+ } from "./chunk-P6NSEG2S.js";
18
+ import "./chunk-UFAMOUWL.js";
19
+ import "./chunk-QM6YOWHZ.js";
20
20
  import "./chunk-PZ5AY32C.js";
21
21
  export {
22
22
  SessionTenancyAccessError,
@@ -0,0 +1,31 @@
1
+ import type { ToolGatewayIdentity } from "@opengeni/contracts";
2
+ import type { Database } from "./database.js";
3
+ export declare class ToolGatewayApprovalRateLimitError extends Error {
4
+ readonly name = "ToolGatewayApprovalRateLimitError";
5
+ }
6
+ export declare class ToolGatewayApprovalOperationStartedError extends Error {
7
+ readonly name = "ToolGatewayApprovalOperationStartedError";
8
+ }
9
+ export declare function issueToolGatewayApproval(db: Database, input: {
10
+ tokenHash: string;
11
+ accountId: string;
12
+ workspaceId: string;
13
+ subjectId: string;
14
+ operationId: string;
15
+ catalogDigest: string;
16
+ identity: ToolGatewayIdentity;
17
+ argumentsDigest: string;
18
+ approvalAuthorityDigest: string;
19
+ expiresAt: Date;
20
+ }): Promise<void>;
21
+ export declare function consumeToolGatewayApproval(db: Database, input: {
22
+ tokenHash: string;
23
+ accountId: string;
24
+ workspaceId: string;
25
+ subjectId: string;
26
+ operationId: string;
27
+ catalogDigest: string;
28
+ identity: ToolGatewayIdentity;
29
+ argumentsDigest: string;
30
+ approvalAuthorityDigest: string;
31
+ }): Promise<boolean>;
@@ -29,9 +29,9 @@ import {
29
29
  settleVideoGenerationFailure,
30
30
  settleVideoGenerationReady,
31
31
  updateWorkspaceVideoGenerationPolicy
32
- } from "./chunk-SZAWDXQC.js";
33
- import "./chunk-F6PBS6WE.js";
34
- import "./chunk-O56DM5GZ.js";
32
+ } from "./chunk-CJROYHSC.js";
33
+ import "./chunk-UFAMOUWL.js";
34
+ import "./chunk-QM6YOWHZ.js";
35
35
  import "./chunk-PZ5AY32C.js";
36
36
  export {
37
37
  ACTIVE_VIDEO_GENERATION_STATUSES,
@@ -1,6 +1,6 @@
1
- import type { WorkspaceArtifact, WorkspaceArtifactDetailResponse, WorkspaceArtifactMutationResponse, WorkspaceArtifactVersion } from "@opengeni/contracts";
1
+ import { type ToolGatewayIdentity, type WorkspaceArtifact, type WorkspaceArtifactDetailResponse, type WorkspaceArtifactMutationResponse, type WorkspaceArtifactVersion } from "@opengeni/contracts";
2
2
  import type { Database } from "./database.js";
3
- type ArtifactMutationToolName = "artifacts_create" | "artifacts_publish" | "artifacts_rollback";
3
+ type ArtifactMutationToolName = "artifacts_create" | "artifacts_publish" | "artifacts_rollback" | "artifacts_archive" | "artifacts_restore";
4
4
  export declare class WorkspaceArtifactNotFoundError extends Error {
5
5
  readonly name = "WorkspaceArtifactNotFoundError";
6
6
  }
@@ -15,6 +15,7 @@ export declare class WorkspaceArtifactOperationError extends Error {
15
15
  export declare function listWorkspaceArtifacts(db: Database, workspaceId: string, options?: {
16
16
  limit?: number;
17
17
  cursor?: string;
18
+ status?: "active" | "archived";
18
19
  }): Promise<{
19
20
  artifacts: WorkspaceArtifact[];
20
21
  nextCursor: string | null;
@@ -25,6 +26,7 @@ export declare function getWorkspaceArtifactContentRef(db: Database, workspaceId
25
26
  artifactId: string;
26
27
  version: WorkspaceArtifactVersion;
27
28
  contentKey: string;
29
+ sourceKey: string | null;
28
30
  }>;
29
31
  type PublishMetadata = {
30
32
  accountId: string;
@@ -32,6 +34,10 @@ type PublishMetadata = {
32
34
  contentKey: string;
33
35
  contentSha256: string;
34
36
  sizeBytes: number;
37
+ sourceKey: string;
38
+ sourceSha256: string;
39
+ sourceSizeBytes: number;
40
+ requestedTools?: ToolGatewayIdentity[];
35
41
  operationKey: string;
36
42
  actorSubjectId: string;
37
43
  sourceSessionId: string | null;
@@ -40,12 +46,14 @@ type PublishMetadata = {
40
46
  sourceExecutionGeneration: number | null;
41
47
  sourceToolName: ArtifactMutationToolName | null;
42
48
  persistContent: () => Promise<void>;
49
+ discardContent: () => Promise<void>;
43
50
  };
44
51
  export declare function createWorkspaceArtifact(db: Database, input: PublishMetadata & {
45
52
  artifactId: string;
46
53
  slug: string;
47
54
  title: string;
48
55
  description: string | null;
56
+ requestedSlug?: string | null;
49
57
  }): Promise<WorkspaceArtifactMutationResponse>;
50
58
  export declare function publishWorkspaceArtifactVersion(db: Database, input: PublishMetadata & {
51
59
  artifactId: string;
@@ -53,10 +61,16 @@ export declare function publishWorkspaceArtifactVersion(db: Database, input: Pub
53
61
  title?: string;
54
62
  description?: string | null;
55
63
  }): Promise<WorkspaceArtifactMutationResponse>;
56
- export declare function rollbackWorkspaceArtifact(db: Database, input: Omit<PublishMetadata, "contentKey" | "contentSha256" | "sizeBytes" | "persistContent"> & {
64
+ export declare function rollbackWorkspaceArtifact(db: Database, input: Omit<PublishMetadata, "contentKey" | "contentSha256" | "sizeBytes" | "sourceKey" | "sourceSha256" | "sourceSizeBytes" | "requestedTools" | "persistContent" | "discardContent"> & {
57
65
  artifactId: string;
58
66
  versionId: string;
59
67
  expectedCurrentVersionId: string;
60
68
  reason: string;
61
69
  }): Promise<WorkspaceArtifactMutationResponse>;
70
+ export declare function setWorkspaceArtifactStatus(db: Database, input: Omit<PublishMetadata, "contentKey" | "contentSha256" | "sizeBytes" | "sourceKey" | "sourceSha256" | "sourceSizeBytes" | "requestedTools" | "persistContent" | "discardContent"> & {
71
+ artifactId: string;
72
+ status: "active" | "archived";
73
+ expectedCurrentVersionId: string;
74
+ reason: string;
75
+ }): Promise<WorkspaceArtifactMutationResponse>;
62
76
  export {};
@@ -97,6 +97,14 @@ export declare function listXaiSubscriptionAccountsMetadata(db: Database, input:
97
97
  export declare function workspaceXaiSubscriptionActive(db: Database, settings: {
98
98
  readonly supergrokSubscriptionEnabled: boolean;
99
99
  }, workspaceId: string, subjectId: string): Promise<boolean>;
100
+ /** Metadata-only readiness for the exact provider-account authority frozen on a turn. */
101
+ export declare function workspaceXaiSubscriptionActiveForAuthority(db: Database, settings: {
102
+ readonly supergrokSubscriptionEnabled: boolean;
103
+ }, input: {
104
+ workspaceId: string;
105
+ subjectId: string;
106
+ authoritySnapshot: XaiAuthoritySnapshot;
107
+ }): Promise<boolean>;
100
108
  export declare function getXaiSubscriptionAccountMetadata(db: Database, input: {
101
109
  workspaceId: string;
102
110
  subjectId: string;
@@ -0,0 +1,165 @@
1
+ -- deployment-mode: rolling
2
+ -- Host export is an optional bounded projection. Canonical session_events keeps
3
+ -- the complete lossless payload; an oversized projection must never roll back
4
+ -- the source event or a later lifecycle transaction that closes pending work.
5
+
6
+ SET lock_timeout = '5s';
7
+ SET statement_timeout = '10min';
8
+
9
+ DO $migration$
10
+ DECLARE target_schema text := current_schema();
11
+ BEGIN
12
+ EXECUTE format($create$
13
+ CREATE OR REPLACE FUNCTION opengeni_private.enqueue_host_session_event_export()
14
+ RETURNS trigger
15
+ LANGUAGE plpgsql
16
+ SECURITY DEFINER
17
+ SET search_path = pg_catalog
18
+ AS $function$
19
+ DECLARE
20
+ v_enabled boolean;
21
+ v_initiator jsonb;
22
+ v_context jsonb := '{}'::jsonb;
23
+ v_origin text;
24
+ v_source_payload_bytes integer;
25
+ v_export_payload jsonb;
26
+ v_export_payload_codec_version smallint;
27
+ v_payload_bytes integer;
28
+ BEGIN
29
+ IF NEW.type IN (
30
+ 'agent.message.delta', 'agent.reasoning.delta',
31
+ 'sandbox.command.output.delta', 'terminal.pty.output.delta'
32
+ ) THEN
33
+ RETURN NEW;
34
+ END IF;
35
+
36
+ SELECT c.session_events_enabled INTO v_enabled
37
+ FROM %1$I.host_export_config c WHERE c.id = 1
38
+ FOR SHARE;
39
+ IF coalesce(v_enabled, false) = false THEN
40
+ RETURN NEW;
41
+ END IF;
42
+
43
+ IF NEW.turn_id IS NOT NULL THEN
44
+ SELECT
45
+ CASE WHEN octet_length(t.initiator_subject_id) <= 1024 THEN
46
+ jsonb_strip_nulls(jsonb_build_object(
47
+ 'kind', t.initiator_kind,
48
+ 'subjectId', t.initiator_subject_id,
49
+ 'label', CASE
50
+ WHEN jsonb_typeof(t.initiator_context -> 'label') = 'string'
51
+ THEN left(t.initiator_context ->> 'label', 256)
52
+ ELSE NULL
53
+ END
54
+ ))
55
+ ELSE NULL END,
56
+ jsonb_strip_nulls(jsonb_build_object(
57
+ 'label', CASE
58
+ WHEN jsonb_typeof(t.initiator_context -> 'label') = 'string'
59
+ THEN left(t.initiator_context ->> 'label', 256)
60
+ ELSE NULL
61
+ END,
62
+ 'backfill', CASE
63
+ WHEN jsonb_typeof(t.initiator_context -> 'backfill') = 'boolean'
64
+ THEN t.initiator_context -> 'backfill'
65
+ ELSE NULL
66
+ END,
67
+ 'attributionOmitted', CASE
68
+ WHEN octet_length(t.initiator_subject_id) > 1024 THEN 'subject_id_too_large'
69
+ ELSE NULL
70
+ END
71
+ )),
72
+ t.source
73
+ INTO v_initiator, v_context, v_origin
74
+ FROM %1$I.session_turns t
75
+ WHERE t.workspace_id = NEW.workspace_id AND t.id = NEW.turn_id;
76
+ ELSIF NEW.type = 'session.created' THEN
77
+ SELECT
78
+ CASE WHEN octet_length(s.created_by_subject_id) <= 1024 THEN
79
+ jsonb_strip_nulls(jsonb_build_object(
80
+ 'kind', s.created_by_kind,
81
+ 'subjectId', s.created_by_subject_id,
82
+ 'label', CASE
83
+ WHEN jsonb_typeof(s.created_by_context -> 'label') = 'string'
84
+ THEN left(s.created_by_context ->> 'label', 256)
85
+ ELSE NULL
86
+ END
87
+ ))
88
+ ELSE NULL END,
89
+ jsonb_strip_nulls(jsonb_build_object(
90
+ 'label', CASE
91
+ WHEN jsonb_typeof(s.created_by_context -> 'label') = 'string'
92
+ THEN left(s.created_by_context ->> 'label', 256)
93
+ ELSE NULL
94
+ END,
95
+ 'backfill', CASE
96
+ WHEN jsonb_typeof(s.created_by_context -> 'backfill') = 'boolean'
97
+ THEN s.created_by_context -> 'backfill'
98
+ ELSE NULL
99
+ END,
100
+ 'attributionOmitted', CASE
101
+ WHEN octet_length(s.created_by_subject_id) > 1024 THEN 'subject_id_too_large'
102
+ ELSE NULL
103
+ END
104
+ )),
105
+ NULL
106
+ INTO v_initiator, v_context, v_origin
107
+ FROM %1$I.sessions s
108
+ WHERE s.workspace_id = NEW.workspace_id AND s.id = NEW.session_id;
109
+ END IF;
110
+
111
+ v_source_payload_bytes := octet_length(NEW.payload::text);
112
+ v_export_payload := NEW.payload;
113
+ v_export_payload_codec_version := NEW.payload_codec_version;
114
+ IF v_source_payload_bytes > 65536 THEN
115
+ v_export_payload := jsonb_build_object(
116
+ '_hostExport', jsonb_build_object(
117
+ 'payloadMode', 'summary',
118
+ 'payloadTruncated', true,
119
+ 'originalBytes', v_source_payload_bytes,
120
+ 'sourceEventId', NEW.id,
121
+ 'fullPayload', 'retained in canonical session event'
122
+ ),
123
+ 'preview', '[host-export payload omitted at bounded projection boundary]'
124
+ );
125
+ -- The projection is literal PostgreSQL JSON, not an application-codec
126
+ -- envelope. Preserve codec truth only when the original payload is kept.
127
+ v_export_payload_codec_version := NULL;
128
+ END IF;
129
+
130
+ v_payload_bytes := octet_length(v_export_payload::text)
131
+ + octet_length(NEW.type)
132
+ + coalesce(octet_length(NEW.client_event_id), 0)
133
+ + coalesce(octet_length(NEW.turn_association), 0)
134
+ + coalesce(octet_length(NEW.duplicate_reason), 0)
135
+ + octet_length(coalesce(v_initiator, 'null'::jsonb)::text)
136
+ + octet_length(v_context::text)
137
+ + 768;
138
+ INSERT INTO %1$I.host_export_outbox (
139
+ export_kind, source_id, account_id, workspace_id, session_id,
140
+ turn_id, turn_generation, turn_attempt_id, session_sequence,
141
+ client_event_id, turn_association, duplicate_of_event_id, duplicate_reason,
142
+ event_type, idempotency_key, initiator, initiator_context, origin,
143
+ payload, payload_codec_version, envelope_bytes, occurred_at,
144
+ source_recorded_at, enqueued_at
145
+ ) VALUES (
146
+ 'session_event', NEW.id, NEW.account_id, NEW.workspace_id, NEW.session_id,
147
+ NEW.turn_id, NEW.turn_generation, NEW.turn_attempt_id, NEW.sequence,
148
+ NEW.client_event_id, NEW.turn_association, NEW.duplicate_of_event_id,
149
+ NEW.duplicate_reason,
150
+ NEW.type, 'session_event:' || NEW.id::text, v_initiator,
151
+ coalesce(v_context, '{}'::jsonb), v_origin, v_export_payload,
152
+ v_export_payload_codec_version, greatest(1, v_payload_bytes), NEW.occurred_at,
153
+ NEW.created_at, clock_timestamp()
154
+ )
155
+ ON CONFLICT (export_kind, source_id) DO NOTHING;
156
+ RETURN NEW;
157
+ END $function$;
158
+ $create$, target_schema);
159
+ END
160
+ $migration$;
161
+
162
+ COMMENT ON COLUMN host_export_outbox.payload IS
163
+ 'Immutable bounded host projection. Canonical session_events retains the complete payload; oversized host projections carry an explicit content-free truncation receipt.';
164
+ COMMENT ON COLUMN host_export_outbox.payload_codec_version IS
165
+ 'Codec truth for the stored host projection. NULL means literal SQL JSON, including oversized-payload projections; 1 means the original application-coded payload was retained exactly.';