@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.
Files changed (55) hide show
  1. package/dist/{chunk-CYGFLLMN.js → chunk-7WTDI7Y3.js} +764 -283
  2. package/dist/chunk-7WTDI7Y3.js.map +1 -0
  3. package/dist/{chunk-BNGEN5QZ.js → chunk-KW6U54V2.js} +26 -2
  4. package/dist/chunk-KW6U54V2.js.map +1 -0
  5. package/dist/connection-token-resolver.d.ts +24 -2
  6. package/dist/index.d.ts +107 -5
  7. package/dist/index.js +7857 -3898
  8. package/dist/index.js.map +1 -1
  9. package/dist/preference-registry.d.ts +14 -0
  10. package/dist/provision-roles.js +1 -1
  11. package/dist/runtime-posture.d.ts +3 -3
  12. package/dist/schema.d.ts +1659 -77
  13. package/dist/schema.js +13 -1
  14. package/dist/session-control.d.ts +7 -1
  15. package/dist/session-queue-commands.d.ts +8 -0
  16. package/dist/session-realtime-context.d.ts +56 -0
  17. package/dist/session-realtime-ledger.d.ts +188 -0
  18. package/dist/session-realtime-mirror.d.ts +51 -0
  19. package/dist/session-realtime-state.d.ts +2 -0
  20. package/dist/session-realtime-terminal.d.ts +40 -0
  21. package/dist/session-realtime.d.ts +59 -0
  22. package/dist/workspace-instruction-policies-schema.d.ts +307 -0
  23. package/dist/workspace-instruction-policies.d.ts +97 -7
  24. package/drizzle/0156_slack_reaction_trigger.sql +49 -0
  25. package/drizzle/0157_session_policy_role_snapshots.sql +1146 -0
  26. package/drizzle/0158_session_realtime_mode.sql +88 -0
  27. package/drizzle/0159_session_realtime_ledger.sql +198 -0
  28. package/drizzle/0160_session_realtime_delegation_terminal.sql +38 -0
  29. package/drizzle/0161_session_realtime_context_projection.sql +82 -0
  30. package/drizzle/0162_session_realtime_connection_promotion.sql +53 -0
  31. package/drizzle/0163_session_realtime_delegation_progress.sql +35 -0
  32. package/drizzle/0164_session_realtime_models.sql +28 -0
  33. package/drizzle/0165_document_authority_foundation.sql +259 -0
  34. package/drizzle/0166_connection_disconnect_idempotency.sql +49 -0
  35. package/drizzle/0167_document_index_replay_authority.sql +61 -0
  36. package/drizzle/0168_workspace_instruction_policy_operation_receipts.sql +44 -0
  37. package/package.json +4 -4
  38. package/src/connection-token-resolver.ts +79 -16
  39. package/src/index.ts +1033 -101
  40. package/src/preference-registry.ts +114 -6
  41. package/src/provision-roles.ts +12 -0
  42. package/src/runtime-posture.ts +12 -0
  43. package/src/schema.ts +486 -43
  44. package/src/session-control.ts +643 -21
  45. package/src/session-queue-commands.ts +121 -18
  46. package/src/session-realtime-context.ts +393 -0
  47. package/src/session-realtime-ledger.ts +1790 -0
  48. package/src/session-realtime-mirror.ts +276 -0
  49. package/src/session-realtime-state.ts +25 -0
  50. package/src/session-realtime-terminal.ts +306 -0
  51. package/src/session-realtime.ts +659 -0
  52. package/src/workspace-instruction-policies-schema.ts +71 -0
  53. package/src/workspace-instruction-policies.ts +568 -25
  54. package/dist/chunk-BNGEN5QZ.js.map +0 -1
  55. package/dist/chunk-CYGFLLMN.js.map +0 -1
@@ -17,6 +17,7 @@ __export(schema_exports, {
17
17
  codexRotationSettings: () => codexRotationSettings,
18
18
  codexSubscriptionCredentials: () => codexSubscriptionCredentials,
19
19
  composerDrafts: () => composerDrafts,
20
+ connectionDisconnectOperations: () => connectionDisconnectOperations,
20
21
  connections: () => connections,
21
22
  connectorActionPolicies: () => connectorActionPolicies,
22
23
  connectorActionRequests: () => connectorActionRequests,
@@ -101,6 +102,10 @@ __export(schema_exports, {
101
102
  sessionMcpServers: () => sessionMcpServers,
102
103
  sessionPendingToolCalls: () => sessionPendingToolCalls,
103
104
  sessionPins: () => sessionPins,
105
+ sessionRealtimeConnections: () => sessionRealtimeConnections,
106
+ sessionRealtimeContextProjections: () => sessionRealtimeContextProjections,
107
+ sessionRealtimeEntries: () => sessionRealtimeEntries,
108
+ sessionRealtimeModes: () => sessionRealtimeModes,
104
109
  sessionRecordingCodecValues: () => sessionRecordingCodecValues,
105
110
  sessionRecordingModeValues: () => sessionRecordingModeValues,
106
111
  sessionRecordingStateValues: () => sessionRecordingStateValues,
@@ -131,6 +136,7 @@ __export(schema_exports, {
131
136
  workspaceInstructionPolicyActivationEvents: () => workspaceInstructionPolicyActivationEvents,
132
137
  workspaceInstructionPolicyHeads: () => workspaceInstructionPolicyHeads,
133
138
  workspaceInstructionPolicyRevisions: () => workspaceInstructionPolicyRevisions,
139
+ workspaceInstructionPolicySnapshots: () => workspaceInstructionPolicySnapshots,
134
140
  workspaceMemberships: () => workspaceMemberships,
135
141
  workspaceModelPolicies: () => workspaceModelPolicies,
136
142
  workspacePacks: () => workspacePacks,
@@ -146,8 +152,8 @@ import {
146
152
  check as check4,
147
153
  foreignKey,
148
154
  index as index5,
149
- integer as integer4,
150
- jsonb as jsonb4,
155
+ integer as integer5,
156
+ jsonb as jsonb5,
151
157
  numeric,
152
158
  pgTable as pgTable5,
153
159
  text as text5,
@@ -163,6 +169,8 @@ import {
163
169
  bigint,
164
170
  check,
165
171
  index,
172
+ integer,
173
+ jsonb,
166
174
  pgTable,
167
175
  text,
168
176
  timestamp,
@@ -173,6 +181,8 @@ var workspaceInstructionPolicyRevisions = pgTable(
173
181
  "workspace_instruction_policy_revisions",
174
182
  {
175
183
  id: uuid("id").primaryKey().defaultRandom(),
184
+ operationId: uuid("operation_id"),
185
+ requestFingerprint: text("request_fingerprint"),
176
186
  accountId: uuid("account_id").notNull(),
177
187
  workspaceId: uuid("workspace_id").notNull(),
178
188
  revision: bigint("revision", { mode: "number" }).notNull().default(sql`nextval('workspace_instruction_policy_revision_seq')`),
@@ -188,6 +198,17 @@ var workspaceInstructionPolicyRevisions = pgTable(
188
198
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
189
199
  },
190
200
  (table) => ({
201
+ workspaceOperation: uniqueIndex("workspace_instruction_policy_revisions_workspace_operation_uq").on(table.workspaceId, table.operationId).where(sql`${table.operationId} is not null`),
202
+ operationReceipt: check(
203
+ "workspace_instruction_policy_revisions_operation_receipt_chk",
204
+ sql`(
205
+ (${table.operationId} is null and ${table.requestFingerprint} is null)
206
+ or (
207
+ ${table.operationId} is not null
208
+ and ${table.requestFingerprint} ~ '^[0-9a-f]{64}$'
209
+ )
210
+ )`
211
+ ),
191
212
  workspaceRevision: uniqueIndex(
192
213
  "workspace_instruction_policy_revisions_workspace_revision_uq"
193
214
  ).on(table.workspaceId, table.revision),
@@ -241,6 +262,8 @@ var workspaceInstructionPolicyActivationEvents = pgTable(
241
262
  "workspace_instruction_policy_activation_events",
242
263
  {
243
264
  id: uuid("id").primaryKey().defaultRandom(),
265
+ operationId: uuid("operation_id"),
266
+ requestFingerprint: text("request_fingerprint"),
244
267
  accountId: uuid("account_id").notNull(),
245
268
  workspaceId: uuid("workspace_id").notNull(),
246
269
  kind: text("kind").notNull(),
@@ -259,6 +282,17 @@ var workspaceInstructionPolicyActivationEvents = pgTable(
259
282
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
260
283
  },
261
284
  (table) => ({
285
+ workspaceOperation: uniqueIndex("workspace_instruction_policy_events_workspace_operation_uq").on(table.workspaceId, table.operationId).where(sql`${table.operationId} is not null`),
286
+ operationReceipt: check(
287
+ "workspace_instruction_policy_events_operation_receipt_chk",
288
+ sql`(
289
+ (${table.operationId} is null and ${table.requestFingerprint} is null)
290
+ or (
291
+ ${table.operationId} is not null
292
+ and ${table.requestFingerprint} ~ '^[0-9a-f]{64}$'
293
+ )
294
+ )`
295
+ ),
262
296
  workspaceActivationVersion: uniqueIndex(
263
297
  "workspace_instruction_policy_events_target_version_uq"
264
298
  ).on(
@@ -283,6 +317,43 @@ var workspaceInstructionPolicyActivationEvents = pgTable(
283
317
  )
284
318
  })
285
319
  );
320
+ var workspaceInstructionPolicySnapshots = pgTable(
321
+ "workspace_instruction_policy_snapshots",
322
+ {
323
+ id: uuid("id").primaryKey().defaultRandom(),
324
+ accountId: uuid("account_id").notNull(),
325
+ workspaceId: uuid("workspace_id").notNull(),
326
+ sessionId: uuid("session_id").notNull(),
327
+ turnId: uuid("turn_id").notNull(),
328
+ attemptId: uuid("attempt_id").notNull(),
329
+ executionGeneration: integer("execution_generation").notNull(),
330
+ policyRole: text("policy_role"),
331
+ roleSource: text("role_source").notNull(),
332
+ entries: jsonb("entries").$type().notNull(),
333
+ entryHash: text("entry_hash").notNull(),
334
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
335
+ },
336
+ (table) => ({
337
+ attempt: uniqueIndex("workspace_instruction_policy_snapshots_attempt_uq").on(
338
+ table.accountId,
339
+ table.workspaceId,
340
+ table.attemptId
341
+ ),
342
+ workspaceTimeline: index("workspace_instruction_policy_snapshots_workspace_time_idx").on(
343
+ table.workspaceId,
344
+ table.createdAt,
345
+ table.id
346
+ ),
347
+ entriesShape: check(
348
+ "workspace_instruction_policy_snapshots_entries_chk",
349
+ sql`jsonb_typeof(${table.entries}) = 'array' and jsonb_array_length(${table.entries}) <= 3`
350
+ ),
351
+ roleSourceValid: check(
352
+ "workspace_instruction_policy_snapshots_role_source_chk",
353
+ sql`${table.roleSource} in ('session_binding', 'metadata_fallback', 'none', 'invalid_metadata_fallback')`
354
+ )
355
+ })
356
+ );
286
357
 
287
358
  // src/preference-registry-schema.ts
288
359
  import { sql as sql2 } from "drizzle-orm";
@@ -291,8 +362,8 @@ import {
291
362
  boolean,
292
363
  check as check2,
293
364
  index as index2,
294
- integer,
295
- jsonb,
365
+ integer as integer2,
366
+ jsonb as jsonb2,
296
367
  pgTable as pgTable2,
297
368
  text as text2,
298
369
  timestamp as timestamp2,
@@ -309,8 +380,8 @@ var preferenceRegistryPreferences = pgTable2(
309
380
  scopeWorkspaceId: uuid2("scope_workspace_id"),
310
381
  scopeSubjectId: text2("scope_subject_id"),
311
382
  status: text2("status").notNull().default("proposed"),
312
- scopeVersion: integer("scope_version").notNull().default(1),
313
- activationVersion: integer("activation_version").notNull().default(0),
383
+ scopeVersion: integer2("scope_version").notNull().default(1),
384
+ activationVersion: integer2("activation_version").notNull().default(0),
314
385
  activeRevisionId: uuid2("active_revision_id"),
315
386
  activeRevision: bigint2("active_revision", { mode: "number" }),
316
387
  activeContentHash: text2("active_content_hash"),
@@ -352,9 +423,9 @@ var preferenceRegistryRevisions = pgTable2(
352
423
  description: text2("description").notNull(),
353
424
  content: text2("content").notNull(),
354
425
  contentHash: text2("content_hash").notNull(),
355
- precedenceRank: integer("precedence_rank").notNull().default(0),
426
+ precedenceRank: integer2("precedence_rank").notNull().default(0),
356
427
  conflictStrategy: text2("conflict_strategy").notNull(),
357
- conflictsWith: jsonb("conflicts_with").$type().notNull().default([]),
428
+ conflictsWith: jsonb2("conflicts_with").$type().notNull().default([]),
358
429
  provenanceSource: text2("provenance_source").notNull(),
359
430
  provenanceSourceId: text2("provenance_source_id"),
360
431
  trust: text2("trust").notNull(),
@@ -381,7 +452,7 @@ var preferenceRegistryEvents = pgTable2(
381
452
  accountId: uuid2("account_id").notNull(),
382
453
  preferenceId: uuid2("preference_id").notNull(),
383
454
  type: text2("type").notNull(),
384
- version: integer("version").notNull(),
455
+ version: integer2("version").notNull(),
385
456
  oldRevisionId: uuid2("old_revision_id"),
386
457
  newRevisionId: uuid2("new_revision_id"),
387
458
  oldScope: text2("old_scope"),
@@ -416,9 +487,9 @@ var preferenceRegistrySnapshots = pgTable2(
416
487
  sessionId: uuid2("session_id").notNull(),
417
488
  turnId: uuid2("turn_id").notNull(),
418
489
  attemptId: uuid2("attempt_id").notNull(),
419
- executionGeneration: integer("execution_generation").notNull(),
490
+ executionGeneration: integer2("execution_generation").notNull(),
420
491
  initiatingHumanSubjectId: text2("initiating_human_subject_id").notNull(),
421
- descriptors: jsonb("descriptors").$type().notNull(),
492
+ descriptors: jsonb2("descriptors").$type().notNull(),
422
493
  descriptorHash: text2("descriptor_hash").notNull(),
423
494
  truncated: boolean("truncated").notNull().default(false),
424
495
  createdAt: timestamp2("created_at", { withTimezone: true }).notNull().defaultNow()
@@ -446,8 +517,8 @@ import { sql as sql3 } from "drizzle-orm";
446
517
  import {
447
518
  check as check3,
448
519
  index as index3,
449
- integer as integer2,
450
- jsonb as jsonb2,
520
+ integer as integer3,
521
+ jsonb as jsonb3,
451
522
  pgTable as pgTable3,
452
523
  text as text3,
453
524
  timestamp as timestamp3,
@@ -463,7 +534,7 @@ var knowledgeMemoryRelationships = pgTable3(
463
534
  sourceMemoryId: uuid3("source_memory_id").notNull(),
464
535
  targetMemoryId: uuid3("target_memory_id").notNull(),
465
536
  relationshipType: text3("relationship_type").notNull(),
466
- version: integer2("version").notNull().default(1),
537
+ version: integer3("version").notNull().default(1),
467
538
  createdByEventId: uuid3("created_by_event_id").notNull(),
468
539
  removedByEventId: uuid3("removed_by_event_id"),
469
540
  createdAt: timestamp3("created_at", { withTimezone: true }).notNull().defaultNow(),
@@ -528,10 +599,10 @@ var knowledgeMemoryLifecycleEvents = pgTable3(
528
599
  actorSessionId: uuid3("actor_session_id"),
529
600
  actorTurnId: uuid3("actor_turn_id"),
530
601
  actorAttemptId: uuid3("actor_attempt_id"),
531
- actorExecutionGeneration: integer2("actor_execution_generation"),
602
+ actorExecutionGeneration: integer3("actor_execution_generation"),
532
603
  planHash: text3("plan_hash").notNull(),
533
- beforeState: jsonb2("before_state").$type().notNull(),
534
- afterState: jsonb2("after_state").$type().notNull(),
604
+ beforeState: jsonb3("before_state").$type().notNull(),
605
+ afterState: jsonb3("after_state").$type().notNull(),
535
606
  revertsEventId: uuid3("reverts_event_id"),
536
607
  createdAt: timestamp3("created_at", { withTimezone: true }).notNull().defaultNow()
537
608
  },
@@ -600,8 +671,8 @@ import {
600
671
  bigint as bigint3,
601
672
  boolean as boolean2,
602
673
  index as index4,
603
- integer as integer3,
604
- jsonb as jsonb3,
674
+ integer as integer4,
675
+ jsonb as jsonb4,
605
676
  pgTable as pgTable4,
606
677
  text as text4,
607
678
  timestamp as timestamp4,
@@ -772,7 +843,7 @@ var knowledgeSyncRuns = pgTable4(
772
843
  state: text4("state").notNull().default("started"),
773
844
  outputCursor: text4("output_cursor"),
774
845
  watermark: timestamp4("watermark", { withTimezone: true }),
775
- metadata: jsonb3("metadata").$type().notNull().default({}),
846
+ metadata: jsonb4("metadata").$type().notNull().default({}),
776
847
  errorCode: text4("error_code"),
777
848
  completionHash: text4("completion_hash"),
778
849
  ...actorColumns(),
@@ -848,7 +919,7 @@ var knowledgeDocumentVersions = pgTable4(
848
919
  contentSha256: text4("content_sha256").notNull(),
849
920
  ingestionKey: text4("ingestion_key").notNull(),
850
921
  sourceCursor: text4("source_cursor"),
851
- sourceMetadata: jsonb3("source_metadata").$type().notNull().default({}),
922
+ sourceMetadata: jsonb4("source_metadata").$type().notNull().default({}),
852
923
  sourceCreatedAt: timestamp4("source_created_at", { withTimezone: true }),
853
924
  sourceUpdatedAt: timestamp4("source_updated_at", { withTimezone: true }),
854
925
  observedAt: timestamp4("observed_at", { withTimezone: true }).notNull().defaultNow(),
@@ -856,7 +927,7 @@ var knowledgeDocumentVersions = pgTable4(
856
927
  aclGeneration: bigint3("acl_generation", { mode: "number" }).notNull(),
857
928
  documentId: uuid4("document_id"),
858
929
  fileId: uuid4("file_id"),
859
- locationMetadata: jsonb3("location_metadata").$type().notNull().default({}),
930
+ locationMetadata: jsonb4("location_metadata").$type().notNull().default({}),
860
931
  operationId: text4("operation_id").notNull(),
861
932
  inputHash: text4("input_hash").notNull(),
862
933
  ...actorColumns(),
@@ -990,7 +1061,7 @@ var knowledgeFacts = pgTable4(
990
1061
  predicateKey: text4("predicate_key").notNull(),
991
1062
  objectKind: text4("object_kind").notNull(),
992
1063
  objectEntityId: uuid4("object_entity_id"),
993
- objectValue: jsonb3("object_value").$type(),
1064
+ objectValue: jsonb4("object_value").$type(),
994
1065
  objectHash: text4("object_hash").notNull(),
995
1066
  operationId: text4("operation_id").notNull(),
996
1067
  inputHash: text4("input_hash").notNull(),
@@ -1020,11 +1091,11 @@ var knowledgeClaims = pgTable4(
1020
1091
  ...tenantScopeColumns(),
1021
1092
  factId: uuid4("fact_id").notNull(),
1022
1093
  origin: text4("origin").notNull(),
1023
- confidenceBps: integer3("confidence_bps").notNull(),
1094
+ confidenceBps: integer4("confidence_bps").notNull(),
1024
1095
  effectiveAt: timestamp4("effective_at", { withTimezone: true }).notNull(),
1025
1096
  expiresAt: timestamp4("expires_at", { withTimezone: true }),
1026
1097
  extractionMethod: text4("extraction_method").notNull(),
1027
- extractionMetadata: jsonb3("extraction_metadata").$type().notNull().default({}),
1098
+ extractionMetadata: jsonb4("extraction_metadata").$type().notNull().default({}),
1028
1099
  modelProvider: text4("model_provider"),
1029
1100
  modelName: text4("model_name"),
1030
1101
  modelVersion: text4("model_version"),
@@ -1081,7 +1152,7 @@ var knowledgeClaimEvidence = pgTable4(
1081
1152
  documentVersionId: uuid4("document_version_id").notNull(),
1082
1153
  polarity: text4("polarity").notNull(),
1083
1154
  documentChunkId: uuid4("document_chunk_id"),
1084
- chunkIndex: integer3("chunk_index"),
1155
+ chunkIndex: integer4("chunk_index"),
1085
1156
  locator: text4("locator"),
1086
1157
  quoteHash: text4("quote_hash"),
1087
1158
  contentHash: text4("content_hash").notNull(),
@@ -1208,7 +1279,7 @@ var workspaces = pgTable5(
1208
1279
  agentInstructions: text5("agent_instructions"),
1209
1280
  // Growth-ready per-workspace settings bag (migration 0045). Holds memoryEnabled
1210
1281
  // and future workspace-level toggles; validated/merged via WorkspaceSettingsSchema.
1211
- settings: jsonb4("settings").$type().notNull().default({}),
1282
+ settings: jsonb5("settings").$type().notNull().default({}),
1212
1283
  // The workspace's default rig (migration 0047). NULL ⇒ no default; sessions
1213
1284
  // created without an explicit rig ride no rig (today's behavior exactly). FK
1214
1285
  // (-> rigs(id) ON DELETE SET NULL) lives in migration 0047, not a Drizzle
@@ -1284,16 +1355,16 @@ var workspaceArtifactVersions = pgTable5(
1284
1355
  accountId: uuid5("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
1285
1356
  workspaceId: uuid5("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
1286
1357
  artifactId: uuid5("artifact_id").notNull(),
1287
- revision: integer4("revision").notNull(),
1358
+ revision: integer5("revision").notNull(),
1288
1359
  contentKey: text5("content_key").notNull(),
1289
1360
  contentType: text5("content_type").$type().notNull().default("text/html"),
1290
1361
  contentSha256: text5("content_sha256").notNull(),
1291
- sizeBytes: integer4("size_bytes").notNull(),
1362
+ sizeBytes: integer5("size_bytes").notNull(),
1292
1363
  operationKey: text5("operation_key").notNull(),
1293
1364
  sourceSessionId: uuid5("source_session_id"),
1294
1365
  sourceTurnId: uuid5("source_turn_id"),
1295
1366
  sourceAttemptId: uuid5("source_attempt_id"),
1296
- sourceExecutionGeneration: integer4("source_execution_generation"),
1367
+ sourceExecutionGeneration: integer5("source_execution_generation"),
1297
1368
  createdBySubjectId: text5("created_by_subject_id").notNull(),
1298
1369
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
1299
1370
  },
@@ -1351,7 +1422,7 @@ var workspaceArtifactEvents = pgTable5(
1351
1422
  sourceSessionId: uuid5("source_session_id"),
1352
1423
  sourceTurnId: uuid5("source_turn_id"),
1353
1424
  sourceAttemptId: uuid5("source_attempt_id"),
1354
- sourceExecutionGeneration: integer4("source_execution_generation"),
1425
+ sourceExecutionGeneration: integer5("source_execution_generation"),
1355
1426
  actorSubjectId: text5("actor_subject_id").notNull(),
1356
1427
  reason: text5("reason").notNull(),
1357
1428
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
@@ -1396,7 +1467,7 @@ var nestedAgentDepthConfiguration = pgTable5(
1396
1467
  "nested_agent_depth_configuration",
1397
1468
  {
1398
1469
  singleton: boolean3("singleton").primaryKey().notNull().default(true),
1399
- maxNestedAgentDepth: integer4("max_nested_agent_depth").notNull(),
1470
+ maxNestedAgentDepth: integer5("max_nested_agent_depth").notNull(),
1400
1471
  policySource: text5("policy_source").$type().notNull(),
1401
1472
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
1402
1473
  },
@@ -1484,7 +1555,7 @@ var workspaceMemberships = pgTable5(
1484
1555
  subjectId: text5("subject_id").notNull(),
1485
1556
  subjectLabel: text5("subject_label"),
1486
1557
  role: text5("role").notNull().default("member"),
1487
- permissions: jsonb4("permissions").$type().notNull().default([]),
1558
+ permissions: jsonb5("permissions").$type().notNull().default([]),
1488
1559
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
1489
1560
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
1490
1561
  },
@@ -1508,7 +1579,7 @@ var apiKeys = pgTable5(
1508
1579
  name: text5("name").notNull(),
1509
1580
  prefix: text5("prefix").notNull(),
1510
1581
  keyHash: text5("key_hash").notNull(),
1511
- permissions: jsonb4("permissions").$type().notNull().default([]),
1582
+ permissions: jsonb5("permissions").$type().notNull().default([]),
1512
1583
  expiresAt: timestamp5("expires_at", { withTimezone: true }),
1513
1584
  revokedAt: timestamp5("revoked_at", { withTimezone: true }),
1514
1585
  lastUsedAt: timestamp5("last_used_at", { withTimezone: true }),
@@ -1554,7 +1625,7 @@ var workspaceVariableSetVariables = pgTable5(
1554
1625
  name: text5("name").notNull(),
1555
1626
  // Format: v1:<base64 iv>:<base64 ciphertext||gcm-tag>. Never returned by any API.
1556
1627
  valueEncrypted: text5("value_encrypted").notNull(),
1557
- version: integer4("version").notNull().default(1),
1628
+ version: integer5("version").notNull().default(1),
1558
1629
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
1559
1630
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
1560
1631
  },
@@ -1590,7 +1661,7 @@ var codexSubscriptionCredentials = pgTable5(
1590
1661
  status: text5("status").notNull().default("active"),
1591
1662
  // active | needs_relogin | error
1592
1663
  lastError: text5("last_error"),
1593
- version: integer4("version").notNull().default(1),
1664
+ version: integer5("version").notNull().default(1),
1594
1665
  label: text5("label"),
1595
1666
  // user-chosen nickname; null ⇒ derive from email/plan/account
1596
1667
  accountEmail: text5("account_email"),
@@ -1598,9 +1669,9 @@ var codexSubscriptionCredentials = pgTable5(
1598
1669
  // P2 usage cache (plaintext metadata; NEVER a token). Snapshotted from
1599
1670
  // GET /wham/usage; drives the quota bars + the cache TTL. primary = 5h window
1600
1671
  // (limit_window_seconds 18000), secondary = weekly (604800).
1601
- primaryUsedPercent: integer4("primary_used_percent"),
1672
+ primaryUsedPercent: integer5("primary_used_percent"),
1602
1673
  primaryResetAt: timestamp5("primary_reset_at", { withTimezone: true }),
1603
- secondaryUsedPercent: integer4("secondary_used_percent"),
1674
+ secondaryUsedPercent: integer5("secondary_used_percent"),
1604
1675
  secondaryResetAt: timestamp5("secondary_reset_at", { withTimezone: true }),
1605
1676
  usageCheckedAt: timestamp5("usage_checked_at", { withTimezone: true }),
1606
1677
  // snapshot freshness → cache TTL clock
@@ -1627,22 +1698,18 @@ var codexSubscriptionCredentials = pgTable5(
1627
1698
  allocatorEnabled: boolean3("allocator_enabled").notNull().default(true),
1628
1699
  // Independent OCC/audit sequence for the allocator toggle. Token refresh
1629
1700
  // continues to own `version`; quota/cache writes own neither counter.
1630
- allocatorVersion: integer4("allocator_version").notNull().default(1),
1701
+ allocatorVersion: integer5("allocator_version").notNull().default(1),
1631
1702
  allocatorUpdatedBySubjectId: text5("allocator_updated_by_subject_id"),
1632
- allocatorUpdatedAt: timestamp5("allocator_updated_at", {
1633
- withTimezone: true
1634
- }),
1703
+ allocatorUpdatedAt: timestamp5("allocator_updated_at", { withTimezone: true }),
1635
1704
  // Authoritative count-only summary cached from /wham/usage. Detailed rows
1636
1705
  // are never persisted as redemption authority; every first POST preflights
1637
1706
  // the provider's fresh detail endpoint.
1638
- resetCreditAvailableCount: integer4("reset_credit_available_count"),
1639
- resetCreditsCheckedAt: timestamp5("reset_credits_checked_at", {
1640
- withTimezone: true
1641
- }),
1707
+ resetCreditAvailableCount: integer5("reset_credit_available_count"),
1708
+ resetCreditsCheckedAt: timestamp5("reset_credits_checked_at", { withTimezone: true }),
1642
1709
  // Set only by a direct Better Auth cookie connection/reconnection. Legacy,
1643
1710
  // configured, delegated, API-key, and agent-created rows remain view-only.
1644
1711
  connectedBySubjectId: text5("connected_by_subject_id"),
1645
- selectionCount: integer4("selection_count").notNull().default(0),
1712
+ selectionCount: integer5("selection_count").notNull().default(0),
1646
1713
  lastSelectedAt: timestamp5("last_selected_at", { withTimezone: true }),
1647
1714
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
1648
1715
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
@@ -1677,13 +1744,11 @@ var codexResetRedemptionAttempts = pgTable5(
1677
1744
  outcome: text5("outcome"),
1678
1745
  claimHolderId: uuid5("claim_holder_id"),
1679
1746
  claimExpiresAt: timestamp5("claim_expires_at", { withTimezone: true }),
1680
- confirmationExpiresAt: timestamp5("confirmation_expires_at", {
1681
- withTimezone: true
1682
- }).notNull(),
1747
+ confirmationExpiresAt: timestamp5("confirmation_expires_at", { withTimezone: true }).notNull(),
1683
1748
  providerStartedAt: timestamp5("provider_started_at", { withTimezone: true }),
1684
1749
  completedAt: timestamp5("completed_at", { withTimezone: true }),
1685
1750
  lastFailureKind: text5("last_failure_kind"),
1686
- retryCount: integer4("retry_count").notNull().default(0),
1751
+ retryCount: integer5("retry_count").notNull().default(0),
1687
1752
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
1688
1753
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
1689
1754
  },
@@ -1738,19 +1803,19 @@ var connections = pgTable5(
1738
1803
  kind: text5("kind").notNull(),
1739
1804
  status: text5("status").notNull().default("active"),
1740
1805
  credentialEncrypted: text5("credential_encrypted").notNull(),
1741
- grantedScopes: jsonb4("granted_scopes").$type().notNull().default([]),
1806
+ grantedScopes: jsonb5("granted_scopes").$type().notNull().default([]),
1742
1807
  expiresAt: timestamp5("expires_at", { withTimezone: true }),
1743
1808
  lastRefreshAt: timestamp5("last_refresh_at", { withTimezone: true }),
1744
1809
  lastUsedAt: timestamp5("last_used_at", { withTimezone: true }),
1745
1810
  lastError: text5("last_error"),
1746
- version: integer4("version").notNull().default(1),
1811
+ version: integer5("version").notNull().default(1),
1747
1812
  // Server-owned proof that the dedicated install route verified the exact
1748
1813
  // credential at this connection version. Generic/legacy writers cannot set
1749
1814
  // these columns, and migration 0131 clears them when protected fields change
1750
1815
  // without a fresh verification in the same statement.
1751
1816
  verifiedInstallAt: timestamp5("verified_install_at", { withTimezone: true }),
1752
- verifiedInstallVersion: integer4("verified_install_version"),
1753
- metadata: jsonb4("metadata").$type().notNull().default({}),
1817
+ verifiedInstallVersion: integer5("verified_install_version"),
1818
+ metadata: jsonb5("metadata").$type().notNull().default({}),
1754
1819
  createdBySubjectId: text5("created_by_subject_id"),
1755
1820
  updatedBySubjectId: text5("updated_by_subject_id"),
1756
1821
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
@@ -1774,6 +1839,38 @@ var connections = pgTable5(
1774
1839
  )
1775
1840
  })
1776
1841
  );
1842
+ var connectionDisconnectOperations = pgTable5(
1843
+ "connection_disconnect_operations",
1844
+ {
1845
+ id: uuid5("id").primaryKey().defaultRandom(),
1846
+ accountId: uuid5("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
1847
+ workspaceId: uuid5("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
1848
+ connectionId: uuid5("connection_id").notNull().references(() => connections.id, { onDelete: "cascade" }),
1849
+ subjectId: text5("subject_id").notNull(),
1850
+ idempotencyKey: text5("idempotency_key").notNull(),
1851
+ expectedVersion: integer5("expected_version").notNull(),
1852
+ resultVersion: integer5("result_version").notNull(),
1853
+ createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
1854
+ },
1855
+ (table) => ({
1856
+ workspaceSubjectKey: uniqueIndex5("connection_disconnect_operations_subject_key_uq").on(
1857
+ table.workspaceId,
1858
+ table.subjectId,
1859
+ table.idempotencyKey
1860
+ ),
1861
+ connectionGeneration: uniqueIndex5(
1862
+ "connection_disconnect_operations_connection_generation_uq"
1863
+ ).on(table.workspaceId, table.connectionId, table.expectedVersion),
1864
+ identityValid: check4(
1865
+ "connection_disconnect_operations_identity_check",
1866
+ sql5`length(${table.subjectId}) between 1 and 512
1867
+ and length(${table.idempotencyKey}) between 1 and 200
1868
+ and ${table.idempotencyKey} = btrim(${table.idempotencyKey})
1869
+ and ${table.expectedVersion} > 0
1870
+ and ${table.resultVersion} = ${table.expectedVersion} + 1`
1871
+ )
1872
+ })
1873
+ );
1777
1874
  var connectorActionPolicies = pgTable5(
1778
1875
  "connector_action_policies",
1779
1876
  {
@@ -1785,7 +1882,7 @@ var connectorActionPolicies = pgTable5(
1785
1882
  toolName: text5("tool_name").notNull(),
1786
1883
  actionName: text5("action_name").notNull(),
1787
1884
  policy: text5("policy").$type().notNull(),
1788
- version: integer4("version").notNull().default(1),
1885
+ version: integer5("version").notNull().default(1),
1789
1886
  createdBySubjectId: text5("created_by_subject_id").notNull(),
1790
1887
  updatedBySubjectId: text5("updated_by_subject_id").notNull(),
1791
1888
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
@@ -1860,9 +1957,10 @@ var slackInteractionInbox = pgTable5(
1860
1957
  status: text5("status").$type().notNull().default("pending"),
1861
1958
  claimHolderId: uuid5("claim_holder_id"),
1862
1959
  claimExpiresAt: timestamp5("claim_expires_at", { withTimezone: true }),
1863
- attemptCount: integer4("attempt_count").notNull().default(0),
1960
+ attemptCount: integer5("attempt_count").notNull().default(0),
1864
1961
  retryAt: timestamp5("retry_at", { withTimezone: true }),
1865
1962
  lastErrorCode: text5("last_error_code"),
1963
+ reactionContextCheckpoint: jsonb5("reaction_context_checkpoint").$type(),
1866
1964
  processedAt: timestamp5("processed_at", { withTimezone: true }),
1867
1965
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
1868
1966
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
@@ -1902,16 +2000,16 @@ var slackInteractions = pgTable5(
1902
2000
  sessionId: uuid5("session_id").references(() => sessions.id, {
1903
2001
  onDelete: "cascade"
1904
2002
  }),
1905
- lastDeliveredSessionEventSequence: integer4("last_delivered_session_event_sequence").notNull().default(0),
2003
+ lastDeliveredSessionEventSequence: integer5("last_delivered_session_event_sequence").notNull().default(0),
1906
2004
  deliveryClaimHolderId: uuid5("delivery_claim_holder_id"),
1907
2005
  deliveryClaimExpiresAt: timestamp5("delivery_claim_expires_at", {
1908
2006
  withTimezone: true
1909
2007
  }),
1910
- deliveryAttemptCount: integer4("delivery_attempt_count").notNull().default(0),
2008
+ deliveryAttemptCount: integer5("delivery_attempt_count").notNull().default(0),
1911
2009
  deliveryRetryAt: timestamp5("delivery_retry_at", { withTimezone: true }),
1912
2010
  deliveryLastErrorCode: text5("delivery_last_error_code"),
1913
2011
  ackSlackMessageTs: text5("ack_slack_message_ts"),
1914
- progressCount: integer4("progress_count").notNull().default(0),
2012
+ progressCount: integer5("progress_count").notNull().default(0),
1915
2013
  terminalDeliveryState: text5("terminal_delivery_state").$type().notNull().default("open"),
1916
2014
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
1917
2015
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
@@ -1943,8 +2041,8 @@ var slackInteractionProgressDeliveries = pgTable5(
1943
2041
  accountId: uuid5("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
1944
2042
  workspaceId: uuid5("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
1945
2043
  interactionId: uuid5("interaction_id").notNull(),
1946
- sessionEventSequence: integer4("session_event_sequence").notNull(),
1947
- slot: integer4("slot").notNull(),
2044
+ sessionEventSequence: integer5("session_event_sequence").notNull(),
2045
+ slot: integer5("slot").notNull(),
1948
2046
  operationId: uuid5("operation_id").notNull(),
1949
2047
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
1950
2048
  },
@@ -1987,7 +2085,7 @@ var slackBotPostOperations = pgTable5(
1987
2085
  status: text5("status").$type().notNull(),
1988
2086
  claimHolderId: uuid5("claim_holder_id"),
1989
2087
  claimExpiresAt: timestamp5("claim_expires_at", { withTimezone: true }),
1990
- attemptCount: integer4("attempt_count").notNull().default(0),
2088
+ attemptCount: integer5("attempt_count").notNull().default(0),
1991
2089
  lastFailureCode: text5("last_failure_code"),
1992
2090
  slackChannelId: text5("slack_channel_id"),
1993
2091
  slackMessageTimestamp: text5("slack_message_timestamp"),
@@ -2057,7 +2155,7 @@ var slackBotDeleteOperations = pgTable5(
2057
2155
  status: text5("status").$type().notNull(),
2058
2156
  claimHolderId: uuid5("claim_holder_id"),
2059
2157
  claimExpiresAt: timestamp5("claim_expires_at", { withTimezone: true }),
2060
- attemptCount: integer4("attempt_count").notNull().default(0),
2158
+ attemptCount: integer5("attempt_count").notNull().default(0),
2061
2159
  lastFailureCode: text5("last_failure_code"),
2062
2160
  slackChannelId: text5("slack_channel_id"),
2063
2161
  slackMessageTimestamp: text5("slack_message_timestamp"),
@@ -2120,7 +2218,7 @@ var integrationOauthClients = pgTable5(
2120
2218
  clientId: text5("client_id").notNull(),
2121
2219
  clientSecretEncrypted: text5("client_secret_encrypted"),
2122
2220
  tokenEndpointAuthMethod: text5("token_endpoint_auth_method").notNull().default("none"),
2123
- metadata: jsonb4("metadata").$type().notNull().default({}),
2221
+ metadata: jsonb5("metadata").$type().notNull().default({}),
2124
2222
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
2125
2223
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
2126
2224
  },
@@ -2196,7 +2294,7 @@ var codexCredentialLeases = pgTable5(
2196
2294
  // durable turn replaces holderId and increments generation atomically;
2197
2295
  // stale/zombie heartbeats and releases must match both values.
2198
2296
  holderId: text5("holder_id").notNull(),
2199
- generation: integer4("generation").notNull().default(1),
2297
+ generation: integer5("generation").notNull().default(1),
2200
2298
  leasedUntil: timestamp5("leased_until", { withTimezone: true }).notNull(),
2201
2299
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
2202
2300
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
@@ -2235,15 +2333,20 @@ var sessions = pgTable5(
2235
2333
  // Composed system-level AFTER the workspace agentInstructions; never emitted
2236
2334
  // as a timeline event.
2237
2335
  instructions: text5("instructions"),
2238
- resources: jsonb4("resources").$type().notNull().default([]),
2239
- skills: jsonb4("skills").$type().notNull().default([]),
2240
- tools: jsonb4("tools").$type().notNull().default([]),
2241
- metadata: jsonb4("metadata").$type().notNull().default({}),
2336
+ // Immutable normalized prompt-policy role. This is deliberately separate
2337
+ // from workspace membership roles and memory selectors. Existing rows keep
2338
+ // NULL and use the bounded metadata.role compatibility fallback at the
2339
+ // attempt-snapshot boundary.
2340
+ policyRole: text5("policy_role"),
2341
+ resources: jsonb5("resources").$type().notNull().default([]),
2342
+ skills: jsonb5("skills").$type().notNull().default([]),
2343
+ tools: jsonb5("tools").$type().notNull().default([]),
2344
+ metadata: jsonb5("metadata").$type().notNull().default({}),
2242
2345
  // Frozen creator fact. This is used for creation attribution and for the
2243
2346
  // idempotent first-turn repair only; later turns capture their own actor.
2244
2347
  createdByKind: text5("created_by_kind").notNull().default("service"),
2245
2348
  createdBySubjectId: text5("created_by_subject_id").notNull().default("unattributed-legacy"),
2246
- createdByContext: jsonb4("created_by_context").$type().notNull().default({ backfill: true }),
2349
+ createdByContext: jsonb5("created_by_context").$type().notNull().default({ backfill: true }),
2247
2350
  model: text5("model").notNull(),
2248
2351
  sandboxBackend: text5("sandbox_backend").notNull(),
2249
2352
  // The OS this session's box runs. Defaults to 'linux' (today's only OS, so
@@ -2273,7 +2376,7 @@ var sessions = pgTable5(
2273
2376
  // in-flight op fenced by a stale active_epoch retries against the new active
2274
2377
  // sandbox. integer (NOT bigint) — the lease-epoch spike: int8 reads back as a
2275
2378
  // JS string and breaks the strict fence; int4 returns a number.
2276
- activeEpoch: integer4("active_epoch").notNull().default(0),
2379
+ activeEpoch: integer5("active_epoch").notNull().default(0),
2277
2380
  // The session's WORKING DIRECTORY — the path/cwd base the (selfhosted) box's
2278
2381
  // agent/terminal/file-dock operate under. A launch-workspace_root-relative
2279
2382
  // subdir or an absolute machine path; surfaced alongside the active-sandbox
@@ -2294,20 +2397,20 @@ var sessions = pgTable5(
2294
2397
  rigVersionId: uuid5("rig_version_id"),
2295
2398
  // Non-default first-party MCP token permissions (manager-style sessions);
2296
2399
  // null means the fixed worker default set in @opengeni/runtime.
2297
- firstPartyMcpPermissions: jsonb4("first_party_mcp_permissions").$type(),
2400
+ firstPartyMcpPermissions: jsonb5("first_party_mcp_permissions").$type(),
2298
2401
  // Exact model-visible first-party tool selection. All catalogued tools are
2299
2402
  // selected by default; [] intentionally selects no broad-server tools.
2300
- firstPartyMcpTools: jsonb4("first_party_mcp_tools").$type().notNull(),
2403
+ firstPartyMcpTools: jsonb5("first_party_mcp_tools").$type().notNull(),
2301
2404
  // Initial-command staging only. initializeSessionStartAtomically copies
2302
2405
  // this immutable snapshot onto the first turn so create repair survives a
2303
2406
  // crash between the session insert and first-turn transaction. Runtime
2304
2407
  // credential authority must never read this session field.
2305
- initialPersonalConnectionDelegations: jsonb4("initial_personal_connection_delegations").$type().notNull().default([]),
2408
+ initialPersonalConnectionDelegations: jsonb5("initial_personal_connection_delegations").$type().notNull().default([]),
2306
2409
  // Durable tool-policy origin. Migration 0136 removes the old null/legacy
2307
2410
  // representation so every session has one explicit policy mode.
2308
- toolPolicy: jsonb4("tool_policy").$type().notNull(),
2411
+ toolPolicy: jsonb5("tool_policy").$type().notNull(),
2309
2412
  // Optimistic-concurrency fence for durable session tool-policy writes.
2310
- toolPolicyVersion: integer4("tool_policy_version").notNull().default(1),
2413
+ toolPolicyVersion: integer5("tool_policy_version").notNull().default(1),
2311
2414
  // The manager session that spawned this one via session_create. Set only
2312
2415
  // when the creating grant carried a worker-signed sessionId claim (a session
2313
2416
  // spawning a worker); null for direct API creates and scheduled-task runs.
@@ -2331,9 +2434,9 @@ var sessions = pgTable5(
2331
2434
  // populated by the database admission boundary and never re-derived from
2332
2435
  // a live workspace setting for an existing session.
2333
2436
  rootSessionId: uuid5("root_session_id").notNull(),
2334
- nestedAgentDepth: integer4("nested_agent_depth").notNull(),
2335
- maxNestedAgentDepthOverride: integer4("max_nested_agent_depth_override"),
2336
- effectiveMaxNestedAgentDepth: integer4("effective_max_nested_agent_depth").notNull(),
2437
+ nestedAgentDepth: integer5("nested_agent_depth").notNull(),
2438
+ maxNestedAgentDepthOverride: integer5("max_nested_agent_depth_override"),
2439
+ effectiveMaxNestedAgentDepth: integer5("effective_max_nested_agent_depth").notNull(),
2337
2440
  nestedAgentDepthPolicySource: text5("nested_agent_depth_policy_source").notNull(),
2338
2441
  nestedAgentDepthPolicySessionId: uuid5("nested_agent_depth_policy_session_id"),
2339
2442
  temporalWorkflowId: text5("temporal_workflow_id"),
@@ -2342,13 +2445,13 @@ var sessions = pgTable5(
2342
2445
  // turn. The pre-turn portable compaction trigger reads this as its budget
2343
2446
  // signal (char/4 estimate is the same-turn fallback). Null until a turn with
2344
2447
  // usage has completed.
2345
- lastInputTokens: integer4("last_input_tokens"),
2448
+ lastInputTokens: integer5("last_input_tokens"),
2346
2449
  // Operator /compact request flag. The API sets
2347
2450
  // it true; the worker honors it BEFORE the next turn's model call by forcing
2348
2451
  // a compaction, then clears it. A durable flag (not a transient signal) so
2349
2452
  // the trigger survives a worker restart and converges before the next turn.
2350
2453
  compactRequested: boolean3("compact_requested").notNull().default(false),
2351
- queueVersion: integer4("queue_version").notNull().default(0),
2454
+ queueVersion: integer5("queue_version").notNull().default(0),
2352
2455
  queueHeadPosition: bigint4("queue_head_position", { mode: "number" }).notNull().default(0),
2353
2456
  queueTailPosition: bigint4("queue_tail_position", { mode: "number" }).notNull().default(0),
2354
2457
  directControlState: text5("direct_control_state").notNull().default("active"),
@@ -2362,7 +2465,7 @@ var sessions = pgTable5(
2362
2465
  directControlChangedAt: timestamp5("direct_control_changed_at", {
2363
2466
  withTimezone: true
2364
2467
  }),
2365
- lastSequence: integer4("last_sequence").notNull().default(0),
2468
+ lastSequence: integer5("last_sequence").notNull().default(0),
2366
2469
  // The session's PINNED Codex account (manual override from the in-session
2367
2470
  // switcher). NULL ⇒ follow the workspace active pointer. FK declared in the
2368
2471
  // migration with ON DELETE SET NULL (a disconnected pin degrades to "follow
@@ -2433,6 +2536,296 @@ var sessions = pgTable5(
2433
2536
  )
2434
2537
  })
2435
2538
  );
2539
+ var sessionRealtimeModes = pgTable5(
2540
+ "session_realtime_modes",
2541
+ {
2542
+ id: uuid5("id").primaryKey().defaultRandom(),
2543
+ accountId: uuid5("account_id").notNull(),
2544
+ workspaceId: uuid5("workspace_id").notNull(),
2545
+ sessionId: uuid5("session_id").notNull(),
2546
+ operationId: uuid5("operation_id").notNull(),
2547
+ ownerSubjectId: text5("owner_subject_id").notNull(),
2548
+ browserInstanceId: text5("browser_instance_id").notNull(),
2549
+ ownerKeyHash: text5("owner_key_hash").notNull(),
2550
+ model: text5("model").notNull(),
2551
+ state: text5("state").notNull().default("active"),
2552
+ version: integer5("version").notNull().default(1),
2553
+ connectionEpoch: integer5("connection_epoch").notNull().default(1),
2554
+ leaseExpiresAt: timestamp5("lease_expires_at", { withTimezone: true }).notNull(),
2555
+ lastHeartbeatAt: timestamp5("last_heartbeat_at", { withTimezone: true }).notNull(),
2556
+ startedAt: timestamp5("started_at", { withTimezone: true }).notNull().defaultNow(),
2557
+ endedAt: timestamp5("ended_at", { withTimezone: true }),
2558
+ endReason: text5("end_reason"),
2559
+ // The rolling migration owns this forward reference. End commits at most
2560
+ // one canonical transcript-tail Steer and binds its audit projection here.
2561
+ contextProjectionId: uuid5("context_projection_id"),
2562
+ contextProjectedAt: timestamp5("context_projected_at", { withTimezone: true }),
2563
+ createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
2564
+ updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
2565
+ },
2566
+ (table) => ({
2567
+ workspaceAccount: foreignKey({
2568
+ name: "session_realtime_modes_workspace_account_fk",
2569
+ columns: [table.workspaceId, table.accountId],
2570
+ foreignColumns: [workspaces.id, workspaces.accountId]
2571
+ }).onDelete("cascade"),
2572
+ workspaceSession: foreignKey({
2573
+ name: "session_realtime_modes_workspace_session_fk",
2574
+ columns: [table.workspaceId, table.sessionId],
2575
+ foreignColumns: [sessions.workspaceId, sessions.id]
2576
+ }).onDelete("cascade"),
2577
+ operation: uniqueIndex5("session_realtime_modes_operation_uq").on(
2578
+ table.workspaceId,
2579
+ table.sessionId,
2580
+ table.operationId
2581
+ ),
2582
+ oneActive: uniqueIndex5("session_realtime_modes_one_active_uq").on(table.workspaceId, table.sessionId).where(sql5`${table.state} = 'active'`),
2583
+ activeLease: index5("session_realtime_modes_active_lease_idx").on(table.leaseExpiresAt, table.workspaceId, table.sessionId).where(sql5`${table.state} = 'active'`),
2584
+ stateValid: check4(
2585
+ "session_realtime_modes_state_check",
2586
+ sql5`${table.state} in ('active', 'ended')`
2587
+ ),
2588
+ modelValid: check4(
2589
+ "session_realtime_modes_model_check",
2590
+ sql5`${table.model} in (
2591
+ 'gpt-live-1-boulder-alpha',
2592
+ 'opengeni-gateway/openai/gpt-realtime-2.1',
2593
+ 'opengeni-gateway/openai/gpt-realtime-mini',
2594
+ 'opengeni-gateway/xai/grok-voice-think-fast-2.0',
2595
+ 'workspace-gateway/openai/gpt-realtime-2.1',
2596
+ 'workspace-gateway/openai/gpt-realtime-mini',
2597
+ 'workspace-gateway/xai/grok-voice-think-fast-2.0'
2598
+ )`
2599
+ ),
2600
+ endReasonValid: check4(
2601
+ "session_realtime_modes_end_reason_check",
2602
+ sql5`${table.endReason} is null or ${table.endReason} in ('user_stop', 'browser_unload', 'lease_expired')`
2603
+ ),
2604
+ versionValid: check4("session_realtime_modes_version_check", sql5`${table.version} >= 1`),
2605
+ epochValid: check4("session_realtime_modes_epoch_check", sql5`${table.connectionEpoch} >= 1`),
2606
+ ownerSubjectValid: check4(
2607
+ "session_realtime_modes_owner_subject_check",
2608
+ sql5`octet_length(${table.ownerSubjectId}) between 1 and 1024`
2609
+ ),
2610
+ browserInstanceValid: check4(
2611
+ "session_realtime_modes_browser_instance_check",
2612
+ sql5`octet_length(${table.browserInstanceId}) between 1 and 256`
2613
+ ),
2614
+ ownerKeyHashValid: check4(
2615
+ "session_realtime_modes_owner_key_hash_check",
2616
+ sql5`${table.ownerKeyHash} ~ '^[0-9a-f]{64}$'`
2617
+ ),
2618
+ leaseValid: check4(
2619
+ "session_realtime_modes_lease_check",
2620
+ sql5`${table.leaseExpiresAt} > ${table.lastHeartbeatAt}`
2621
+ ),
2622
+ terminalValid: check4(
2623
+ "session_realtime_modes_terminal_check",
2624
+ sql5`(${table.state} = 'active' and ${table.endedAt} is null and ${table.endReason} is null)
2625
+ or (${table.state} = 'ended' and ${table.endedAt} is not null and ${table.endReason} is not null)`
2626
+ )
2627
+ })
2628
+ );
2629
+ var sessionRealtimeConnections = pgTable5(
2630
+ "session_realtime_connections",
2631
+ {
2632
+ id: uuid5("id").primaryKey().defaultRandom(),
2633
+ accountId: uuid5("account_id").notNull(),
2634
+ workspaceId: uuid5("workspace_id").notNull(),
2635
+ sessionId: uuid5("session_id").notNull(),
2636
+ realtimeId: uuid5("realtime_id").notNull().references(() => sessionRealtimeModes.id, { onDelete: "cascade" }),
2637
+ operationId: uuid5("operation_id").notNull(),
2638
+ connectionEpoch: integer5("connection_epoch").notNull(),
2639
+ startupFenceSequence: integer5("startup_fence_sequence").notNull().default(0),
2640
+ promotionMode: text5("promotion_mode").notNull().default("legacy"),
2641
+ state: text5("state").notNull().default("negotiating"),
2642
+ sdpAnswer: text5("sdp_answer"),
2643
+ failureCode: text5("failure_code"),
2644
+ providerSessionId: text5("provider_session_id"),
2645
+ startupEventId: text5("startup_event_id"),
2646
+ startupAcknowledgedAt: timestamp5("startup_acknowledged_at", { withTimezone: true }),
2647
+ negotiatedAt: timestamp5("negotiated_at", { withTimezone: true }),
2648
+ closedAt: timestamp5("closed_at", { withTimezone: true }),
2649
+ createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
2650
+ updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
2651
+ },
2652
+ (table) => ({
2653
+ workspaceAccount: foreignKey({
2654
+ name: "session_realtime_connections_workspace_account_fk",
2655
+ columns: [table.workspaceId, table.accountId],
2656
+ foreignColumns: [workspaces.id, workspaces.accountId]
2657
+ }).onDelete("cascade"),
2658
+ workspaceSession: foreignKey({
2659
+ name: "session_realtime_connections_workspace_session_fk",
2660
+ columns: [table.workspaceId, table.sessionId],
2661
+ foreignColumns: [sessions.workspaceId, sessions.id]
2662
+ }).onDelete("cascade"),
2663
+ operation: uniqueIndex5("session_realtime_connections_operation_uq").on(
2664
+ table.realtimeId,
2665
+ table.operationId
2666
+ ),
2667
+ epoch: uniqueIndex5("session_realtime_connections_epoch_uq").on(
2668
+ table.realtimeId,
2669
+ table.connectionEpoch
2670
+ ),
2671
+ oneActive: uniqueIndex5("session_realtime_connections_one_active_uq").on(table.realtimeId).where(
2672
+ sql5`(${table.promotionMode} = 'legacy' and ${table.state} in ('negotiating', 'ready', 'active'))
2673
+ or (${table.promotionMode} = 'staged' and ${table.state} = 'active')`
2674
+ ),
2675
+ onePreparing: uniqueIndex5("session_realtime_connections_one_preparing_uq").on(table.realtimeId).where(
2676
+ sql5`(${table.promotionMode} = 'legacy' and ${table.state} in ('negotiating', 'ready', 'active'))
2677
+ or (${table.promotionMode} = 'staged' and ${table.state} in ('negotiating', 'ready'))`
2678
+ ),
2679
+ epochValid: check4(
2680
+ "session_realtime_connections_epoch_check",
2681
+ sql5`${table.connectionEpoch} >= 1`
2682
+ ),
2683
+ startupFenceValid: check4(
2684
+ "session_realtime_connections_startup_fence_check",
2685
+ sql5`${table.startupFenceSequence} >= 0`
2686
+ ),
2687
+ promotionModeValid: check4(
2688
+ "session_realtime_connections_promotion_mode_check",
2689
+ sql5`${table.promotionMode} in ('legacy', 'staged')`
2690
+ ),
2691
+ stateValid: check4(
2692
+ "session_realtime_connections_state_check",
2693
+ sql5`${table.state} in ('negotiating', 'ready', 'active', 'failed', 'closed')`
2694
+ ),
2695
+ sdpValid: check4(
2696
+ "session_realtime_connections_sdp_check",
2697
+ sql5`${table.sdpAnswer} is null or octet_length(${table.sdpAnswer}) between 1 and 1048576`
2698
+ ),
2699
+ failureValid: check4(
2700
+ "session_realtime_connections_failure_check",
2701
+ sql5`${table.failureCode} is null or octet_length(${table.failureCode}) between 1 and 128`
2702
+ ),
2703
+ providerSessionValid: check4(
2704
+ "session_realtime_connections_provider_session_check",
2705
+ sql5`${table.providerSessionId} is null or octet_length(${table.providerSessionId}) between 1 and 1024`
2706
+ ),
2707
+ startupEventValid: check4(
2708
+ "session_realtime_connections_startup_event_check",
2709
+ sql5`${table.startupEventId} is null or octet_length(${table.startupEventId}) between 1 and 1024`
2710
+ ),
2711
+ startupAckValid: check4(
2712
+ "session_realtime_connections_startup_ack_check",
2713
+ sql5`(${table.startupAcknowledgedAt} is null and ${table.providerSessionId} is null and ${table.startupEventId} is null)
2714
+ or (${table.startupAcknowledgedAt} is not null and ${table.providerSessionId} is not null)`
2715
+ ),
2716
+ terminalValid: check4(
2717
+ "session_realtime_connections_terminal_check",
2718
+ sql5`(${table.state} = 'negotiating' and ${table.sdpAnswer} is null and ${table.failureCode} is null and ${table.negotiatedAt} is null and ${table.closedAt} is null)
2719
+ or (${table.state} = 'ready' and ${table.sdpAnswer} is not null and ${table.failureCode} is null and ${table.negotiatedAt} is not null and ${table.closedAt} is null)
2720
+ or (${table.state} = 'active' and ${table.sdpAnswer} is not null and ${table.failureCode} is null and ${table.negotiatedAt} is not null and ${table.closedAt} is null)
2721
+ or (${table.state} = 'failed' and ${table.sdpAnswer} is null and ${table.failureCode} is not null and ${table.closedAt} is not null)
2722
+ or (${table.state} = 'closed' and ${table.closedAt} is not null)`
2723
+ )
2724
+ })
2725
+ );
2726
+ var sessionRealtimeEntries = pgTable5(
2727
+ "session_realtime_entries",
2728
+ {
2729
+ id: uuid5("id").primaryKey().defaultRandom(),
2730
+ accountId: uuid5("account_id").notNull(),
2731
+ workspaceId: uuid5("workspace_id").notNull(),
2732
+ sessionId: uuid5("session_id").notNull(),
2733
+ realtimeId: uuid5("realtime_id").notNull().references(() => sessionRealtimeModes.id, { onDelete: "cascade" }),
2734
+ operationId: uuid5("operation_id").notNull(),
2735
+ connectionEpoch: integer5("connection_epoch").notNull(),
2736
+ sequence: integer5("sequence").notNull(),
2737
+ direction: text5("direction").notNull(),
2738
+ kind: text5("kind").notNull(),
2739
+ role: text5("role"),
2740
+ providerEventId: text5("provider_event_id"),
2741
+ delegationItemId: text5("delegation_item_id"),
2742
+ // The referenced tables are declared later in this schema module; the
2743
+ // rolling migration owns all three ON DELETE SET NULL foreign keys.
2744
+ sourceUpdateId: uuid5("source_update_id"),
2745
+ historyItemId: uuid5("history_item_id"),
2746
+ // The rolling migration owns this ON DELETE SET NULL foreign key because
2747
+ // sessionTurns is declared later in this schema module. A non-null value
2748
+ // links the accepted provider call and its one terminal outbound
2749
+ // result/error to the same ordinary turn. It never denotes a child/fork
2750
+ // session.
2751
+ turnId: uuid5("turn_id"),
2752
+ text: text5("text"),
2753
+ payload: jsonb5("payload").$type().notNull().default({}),
2754
+ clientAckedAt: timestamp5("client_acked_at", { withTimezone: true }),
2755
+ providerAckedAt: timestamp5("provider_acked_at", { withTimezone: true }),
2756
+ createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
2757
+ updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
2758
+ },
2759
+ (table) => ({
2760
+ workspaceAccount: foreignKey({
2761
+ name: "session_realtime_entries_workspace_account_fk",
2762
+ columns: [table.workspaceId, table.accountId],
2763
+ foreignColumns: [workspaces.id, workspaces.accountId]
2764
+ }).onDelete("cascade"),
2765
+ workspaceSession: foreignKey({
2766
+ name: "session_realtime_entries_workspace_session_fk",
2767
+ columns: [table.workspaceId, table.sessionId],
2768
+ foreignColumns: [sessions.workspaceId, sessions.id]
2769
+ }).onDelete("cascade"),
2770
+ operation: uniqueIndex5("session_realtime_entries_operation_uq").on(
2771
+ table.realtimeId,
2772
+ table.operationId
2773
+ ),
2774
+ sequence: uniqueIndex5("session_realtime_entries_sequence_uq").on(
2775
+ table.realtimeId,
2776
+ table.sequence
2777
+ ),
2778
+ sourceUpdate: uniqueIndex5("session_realtime_entries_source_update_uq").on(table.realtimeId, table.sourceUpdateId).where(sql5`${table.sourceUpdateId} is not null`),
2779
+ delegationTurn: uniqueIndex5("session_realtime_entries_delegation_turn_uq").on(table.turnId).where(sql5`${table.kind} = 'delegation_call' and ${table.turnId} is not null`),
2780
+ delegationTerminal: uniqueIndex5("session_realtime_entries_delegation_terminal_uq").on(table.turnId).where(
2781
+ sql5`${table.direction} = 'provider_out' and ${table.kind} in ('delegation_result', 'error') and ${table.turnId} is not null`
2782
+ ),
2783
+ delegationCall: uniqueIndex5("session_realtime_entries_delegation_call_uq").on(table.realtimeId, table.delegationItemId).where(sql5`${table.kind} = 'delegation_call' and ${table.delegationItemId} is not null`),
2784
+ outboundPending: index5("session_realtime_entries_outbound_pending_idx").on(table.realtimeId, table.sequence).where(sql5`${table.direction} = 'provider_out' and ${table.providerAckedAt} is null`),
2785
+ epochValid: check4("session_realtime_entries_epoch_check", sql5`${table.connectionEpoch} >= 1`),
2786
+ sequenceValid: check4("session_realtime_entries_sequence_check", sql5`${table.sequence} >= 1`),
2787
+ directionValid: check4(
2788
+ "session_realtime_entries_direction_check",
2789
+ sql5`${table.direction} in ('provider_in', 'provider_out')`
2790
+ ),
2791
+ kindValid: check4(
2792
+ "session_realtime_entries_kind_check",
2793
+ sql5`${table.kind} in ('user_transcript', 'assistant_transcript', 'delegation_call', 'delegation_progress', 'delegation_result', 'interruption', 'session_update', 'error')`
2794
+ ),
2795
+ roleValid: check4(
2796
+ "session_realtime_entries_role_check",
2797
+ sql5`${table.role} is null or ${table.role} in ('user', 'assistant')`
2798
+ ),
2799
+ providerEventValid: check4(
2800
+ "session_realtime_entries_provider_event_check",
2801
+ sql5`${table.providerEventId} is null or octet_length(${table.providerEventId}) between 1 and 1024`
2802
+ ),
2803
+ delegationItemValid: check4(
2804
+ "session_realtime_entries_delegation_item_check",
2805
+ sql5`${table.delegationItemId} is null or octet_length(${table.delegationItemId}) between 1 and 1024`
2806
+ ),
2807
+ textValid: check4(
2808
+ "session_realtime_entries_text_check",
2809
+ sql5`${table.text} is null or octet_length(${table.text}) <= 131072`
2810
+ ),
2811
+ payloadValid: check4(
2812
+ "session_realtime_entries_payload_check",
2813
+ sql5`octet_length(${table.payload}::text) <= 131072`
2814
+ ),
2815
+ turnValid: check4(
2816
+ "session_realtime_entries_turn_check",
2817
+ sql5`${table.turnId} is null
2818
+ or (${table.kind} = 'delegation_call' and ${table.direction} = 'provider_in')
2819
+ or (${table.kind} in ('delegation_progress', 'delegation_result', 'error') and ${table.direction} = 'provider_out')`
2820
+ ),
2821
+ transcriptValid: check4(
2822
+ "session_realtime_entries_transcript_check",
2823
+ sql5`(${table.kind} = 'user_transcript' and ${table.role} = 'user' and ${table.text} is not null)
2824
+ or (${table.kind} = 'assistant_transcript' and ${table.role} = 'assistant' and ${table.text} is not null)
2825
+ or (${table.kind} not in ('user_transcript', 'assistant_transcript') and ${table.role} is null)`
2826
+ )
2827
+ })
2828
+ );
2436
2829
  var sessionSpawnDenials = pgTable5(
2437
2830
  "session_spawn_denials",
2438
2831
  {
@@ -2441,10 +2834,10 @@ var sessionSpawnDenials = pgTable5(
2441
2834
  workspaceId: uuid5("workspace_id").notNull(),
2442
2835
  parentSessionId: uuid5("parent_session_id"),
2443
2836
  rootSessionId: uuid5("root_session_id"),
2444
- currentDepth: integer4("current_depth").notNull(),
2837
+ currentDepth: integer5("current_depth").notNull(),
2445
2838
  attemptedDepth: bigint4("attempted_depth", { mode: "number" }).notNull(),
2446
- effectiveMaxNestedAgentDepth: integer4("effective_max_nested_agent_depth").notNull(),
2447
- requestedMaxNestedAgentDepthOverride: integer4("requested_max_nested_agent_depth_override"),
2839
+ effectiveMaxNestedAgentDepth: integer5("effective_max_nested_agent_depth").notNull(),
2840
+ requestedMaxNestedAgentDepthOverride: integer5("requested_max_nested_agent_depth_override"),
2448
2841
  policySource: text5("policy_source").notNull(),
2449
2842
  policySessionId: uuid5("policy_session_id"),
2450
2843
  subjectId: text5("subject_id"),
@@ -2488,7 +2881,7 @@ var sessionPins = pgTable5(
2488
2881
  // unpin+re-pin that would otherwise recreate version 1.
2489
2882
  pinned: boolean3("pinned").notNull().default(true),
2490
2883
  pinnedAt: timestamp5("pinned_at", { withTimezone: true }).defaultNow(),
2491
- version: integer4("version").notNull().default(1)
2884
+ version: integer5("version").notNull().default(1)
2492
2885
  },
2493
2886
  (table) => ({
2494
2887
  subjectNonempty: check4(
@@ -2573,19 +2966,19 @@ var sessionMcpServers = pgTable5(
2573
2966
  serverId: text5("server_id").notNull(),
2574
2967
  name: text5("name"),
2575
2968
  url: text5("url").notNull(),
2576
- allowedTools: jsonb4("allowed_tools").$type(),
2577
- timeoutMs: integer4("timeout_ms"),
2969
+ allowedTools: jsonb5("allowed_tools").$type(),
2970
+ timeoutMs: integer5("timeout_ms"),
2578
2971
  cacheToolsList: boolean3("cache_tools_list").notNull().default(false),
2579
2972
  // Human-approval policy: `true` = every tool requires approval, a string[] of
2580
2973
  // UNPREFIXED tool names = only those require it, null/absent = auto-run.
2581
- requireApproval: jsonb4("require_approval").$type(),
2974
+ requireApproval: jsonb5("require_approval").$type(),
2582
2975
  // Non-secret pointer resolved at request time by the standalone broker or
2583
2976
  // an embedding host. Unlike headersEncrypted, this is safe to project.
2584
- connectionRef: jsonb4("connection_ref").$type(),
2977
+ connectionRef: jsonb5("connection_ref").$type(),
2585
2978
  // Map of header name -> AES-GCM ciphertext. Values are decrypted only by the
2586
2979
  // worker's run-preparation path and never returned by API helpers.
2587
- headersEncrypted: jsonb4("headers_encrypted").$type().notNull().default({}),
2588
- credentialVersion: integer4("credential_version").notNull().default(1),
2980
+ headersEncrypted: jsonb5("headers_encrypted").$type().notNull().default({}),
2981
+ credentialVersion: integer5("credential_version").notNull().default(1),
2589
2982
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
2590
2983
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
2591
2984
  },
@@ -2670,7 +3063,7 @@ var documents = pgTable5(
2670
3063
  status: text5("status").notNull().default("queued"),
2671
3064
  title: text5("title").notNull(),
2672
3065
  parser: text5("parser").notNull().default("liteparse"),
2673
- chunkCount: integer4("chunk_count").notNull().default(0),
3066
+ chunkCount: integer5("chunk_count").notNull().default(0),
2674
3067
  error: text5("error"),
2675
3068
  sourceKind: text5("source_kind").notNull().default("manual_upload"),
2676
3069
  sourceUri: text5("source_uri"),
@@ -2680,7 +3073,12 @@ var documents = pgTable5(
2680
3073
  sourceCreatedAt: timestamp5("source_created_at", { withTimezone: true }),
2681
3074
  sourceUpdatedAt: timestamp5("source_updated_at", { withTimezone: true }),
2682
3075
  sourceVersion: text5("source_version"),
2683
- aclTags: jsonb4("acl_tags").$type().notNull().default([]),
3076
+ aclTags: jsonb5("acl_tags").$type().notNull().default([]),
3077
+ // Durable authorization tuple. The workspace_id above remains ingestion
3078
+ // provenance; organization authority deliberately has no workspace owner.
3079
+ authorityKind: text5("authority_kind").notNull().default("workspace"),
3080
+ authorityWorkspaceId: uuid5("authority_workspace_id"),
3081
+ authoritySubjectId: text5("authority_subject_id"),
2684
3082
  // Per-document access controls. visibility 'private' restricts human reads to
2685
3083
  // created_by (a grant subject id, not a uuid); agent_access=false hides the
2686
3084
  // document from agent retrieval surfaces (docs MCP) while humans keep REST.
@@ -2689,9 +3087,9 @@ var documents = pgTable5(
2689
3087
  agentAccess: boolean3("agent_access").notNull().default(true),
2690
3088
  // Auto-curation output (knowledge drops).
2691
3089
  summary: text5("summary"),
2692
- topics: jsonb4("topics").$type().notNull().default([]),
3090
+ topics: jsonb5("topics").$type().notNull().default([]),
2693
3091
  curationStatus: text5("curation_status").notNull().default("none"),
2694
- curation: jsonb4("curation").$type(),
3092
+ curation: jsonb5("curation").$type(),
2695
3093
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
2696
3094
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
2697
3095
  },
@@ -2718,6 +3116,28 @@ var documents = pgTable5(
2718
3116
  table.workspaceId,
2719
3117
  table.curationStatus
2720
3118
  ),
3119
+ authority: index5("documents_authority_idx").on(
3120
+ table.accountId,
3121
+ table.authorityKind,
3122
+ table.authorityWorkspaceId,
3123
+ table.authoritySubjectId,
3124
+ table.status
3125
+ ),
3126
+ authorityWorkspaceAccount: foreignKey({
3127
+ name: "documents_authority_workspace_fk",
3128
+ columns: [table.authorityWorkspaceId, table.accountId],
3129
+ foreignColumns: [workspaces.id, workspaces.accountId]
3130
+ }).onDelete("restrict"),
3131
+ authorityState: check4(
3132
+ "documents_authority_chk",
3133
+ sql5`(${table.authorityKind} = 'organization' and ${table.authorityWorkspaceId} is null and ${table.authoritySubjectId} is null)
3134
+ or (${table.authorityKind} = 'workspace' and ${table.authorityWorkspaceId} = ${table.workspaceId} and ${table.authoritySubjectId} is null)
3135
+ or (${table.authorityKind} = 'personal' and ${table.authorityWorkspaceId} = ${table.workspaceId} and nullif(btrim(${table.authoritySubjectId}), '') is not null and octet_length(convert_to(${table.authoritySubjectId}, 'UTF8')) <= 1024 and ${table.authoritySubjectId} = ${table.createdBy})`
3136
+ ),
3137
+ authorityVisibility: check4(
3138
+ "documents_authority_visibility_chk",
3139
+ sql5`(${table.authorityKind} = 'personal') = (${table.visibility} = 'private')`
3140
+ ),
2721
3141
  visibilityState: check4(
2722
3142
  "documents_visibility_chk",
2723
3143
  sql5`${table.visibility} in ('workspace', 'private')`
@@ -2746,9 +3166,12 @@ var documentChunks = pgTable5(
2746
3166
  documentId: uuid5("document_id").notNull().references(() => documents.id, { onDelete: "cascade" }),
2747
3167
  baseId: uuid5("base_id").notNull().references(() => documentBases.id, { onDelete: "cascade" }),
2748
3168
  fileId: uuid5("file_id").notNull().references(() => files.id, { onDelete: "restrict" }),
2749
- chunkIndex: integer4("chunk_index").notNull(),
3169
+ chunkIndex: integer5("chunk_index").notNull(),
2750
3170
  text: text5("text").notNull(),
2751
- metadata: jsonb4("metadata").$type().notNull().default({}),
3171
+ metadata: jsonb5("metadata").$type().notNull().default({}),
3172
+ authorityKind: text5("authority_kind").notNull().default("workspace"),
3173
+ authorityWorkspaceId: uuid5("authority_workspace_id"),
3174
+ authoritySubjectId: text5("authority_subject_id"),
2752
3175
  embedding: vector("embedding").notNull(),
2753
3176
  embeddingModel: text5("embedding_model").notNull(),
2754
3177
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
@@ -2759,7 +3182,24 @@ var documentChunks = pgTable5(
2759
3182
  table.documentId,
2760
3183
  table.chunkIndex
2761
3184
  ),
2762
- base: index5("document_chunks_workspace_base_idx").on(table.workspaceId, table.baseId)
3185
+ base: index5("document_chunks_workspace_base_idx").on(table.workspaceId, table.baseId),
3186
+ authority: index5("document_chunks_authority_idx").on(
3187
+ table.accountId,
3188
+ table.authorityKind,
3189
+ table.authorityWorkspaceId,
3190
+ table.authoritySubjectId
3191
+ ),
3192
+ authorityWorkspaceAccount: foreignKey({
3193
+ name: "document_chunks_authority_workspace_fk",
3194
+ columns: [table.authorityWorkspaceId, table.accountId],
3195
+ foreignColumns: [workspaces.id, workspaces.accountId]
3196
+ }).onDelete("restrict"),
3197
+ authorityState: check4(
3198
+ "document_chunks_authority_chk",
3199
+ sql5`(${table.authorityKind} = 'organization' and ${table.authorityWorkspaceId} is null and ${table.authoritySubjectId} is null)
3200
+ or (${table.authorityKind} = 'workspace' and ${table.authorityWorkspaceId} = ${table.workspaceId} and ${table.authoritySubjectId} is null)
3201
+ or (${table.authorityKind} = 'personal' and ${table.authorityWorkspaceId} = ${table.workspaceId} and nullif(btrim(${table.authoritySubjectId}), '') is not null and octet_length(convert_to(${table.authoritySubjectId}, 'UTF8')) <= 1024)`
3202
+ )
2763
3203
  })
2764
3204
  );
2765
3205
  var knowledgeMemories = pgTable5(
@@ -2772,9 +3212,9 @@ var knowledgeMemories = pgTable5(
2772
3212
  kind: text5("kind").notNull().default("semantic"),
2773
3213
  scope: text5("scope").notNull().default("workspace"),
2774
3214
  text: text5("text").notNull(),
2775
- sourceRefs: jsonb4("source_refs").$type().notNull().default([]),
2776
- confidence: integer4("confidence").notNull().default(50),
2777
- metadata: jsonb4("metadata").$type().notNull().default({}),
3215
+ sourceRefs: jsonb5("source_refs").$type().notNull().default([]),
3216
+ confidence: integer5("confidence").notNull().default(50),
3217
+ metadata: jsonb5("metadata").$type().notNull().default({}),
2778
3218
  createdBySessionId: uuid5("created_by_session_id").references(() => sessions.id, {
2779
3219
  onDelete: "set null"
2780
3220
  }),
@@ -2785,7 +3225,7 @@ var knowledgeMemories = pgTable5(
2785
3225
  embedding: vector("embedding"),
2786
3226
  embeddingModel: text5("embedding_model"),
2787
3227
  pinned: boolean3("pinned").notNull().default(false),
2788
- usageCount: integer4("usage_count").notNull().default(0),
3228
+ usageCount: integer5("usage_count").notNull().default(0),
2789
3229
  lastUsedAt: timestamp5("last_used_at", { withTimezone: true }),
2790
3230
  // Self-referential supersession chain. FKs live in migration 0045 (ON DELETE SET
2791
3231
  // NULL); declared here as plain columns like the migration-only composite FK.
@@ -2801,10 +3241,10 @@ var knowledgeMemories = pgTable5(
2801
3241
  scopeSessionId: uuid5("scope_session_id"),
2802
3242
  namespace: text5("namespace_key").notNull().default("general"),
2803
3243
  labels: text5("labels").array().notNull().default([]),
2804
- memoryVersion: integer4("memory_version").notNull().default(1),
3244
+ memoryVersion: integer5("memory_version").notNull().default(1),
2805
3245
  createdByKind: text5("created_by_kind").notNull().default("service"),
2806
3246
  createdBySubjectId: text5("created_by_subject_id").notNull().default("unattributed-legacy"),
2807
- createdByContext: jsonb4("created_by_context").$type().notNull().default({ backfill: true }),
3247
+ createdByContext: jsonb5("created_by_context").$type().notNull().default({ backfill: true }),
2808
3248
  // sha256(normalizeMemoryText(text)) — exact-dedup key; see memory-domain.
2809
3249
  textHash: text5("text_hash"),
2810
3250
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
@@ -2872,8 +3312,8 @@ var sessionTurns = pgTable5(
2872
3312
  // Host context for this exact turn. System-level at runtime and deliberately
2873
3313
  // separate from the visible prompt/event payload.
2874
3314
  turnInstructions: text5("turn_instructions"),
2875
- resources: jsonb4("resources").$type().notNull().default([]),
2876
- tools: jsonb4("tools").$type().notNull().default([]),
3315
+ resources: jsonb5("resources").$type().notNull().default([]),
3316
+ tools: jsonb5("tools").$type().notNull().default([]),
2877
3317
  // false = inherit the durable session policy; true = this turn explicitly
2878
3318
  // replaces it with `tools` after the core subset fence.
2879
3319
  toolsProvided: boolean3("tools_provided").notNull().default(false),
@@ -2885,30 +3325,35 @@ var sessionTurns = pgTable5(
2885
3325
  // Per-turn OS override. NULL = inherit the session's sandbox_os. CHECK-
2886
3326
  // constrained to the SandboxOs enum (or NULL) in migration 0018.
2887
3327
  sandboxOs: text5("sandbox_os"),
2888
- metadata: jsonb4("metadata").$type().notNull().default({}),
2889
- version: integer4("version").notNull().default(1),
2890
- executionGeneration: integer4("execution_generation").notNull().default(0),
3328
+ metadata: jsonb5("metadata").$type().notNull().default({}),
3329
+ version: integer5("version").notNull().default(1),
3330
+ executionGeneration: integer5("execution_generation").notNull().default(0),
2891
3331
  // Composite FK to session_turn_attempts is installed by migration 0063.
2892
3332
  // It lives in SQL because attempts carry the reciprocal turn FK and because
2893
3333
  // the claim transaction preallocates this ID before inserting the attempt;
2894
3334
  // the SQL constraint is therefore DEFERRABLE INITIALLY DEFERRED.
2895
3335
  activeAttemptId: uuid5("active_attempt_id"),
2896
- lineage: jsonb4("lineage").$type().notNull().default({}),
3336
+ lineage: jsonb5("lineage").$type().notNull().default({}),
2897
3337
  // Required immutable authority captured when the turn is accepted. These
2898
3338
  // columns are deliberately outside mutable metadata/lineage.
2899
3339
  initiatorKind: text5("initiator_kind").notNull().default("service"),
2900
3340
  initiatorSubjectId: text5("initiator_subject_id").notNull().default("unattributed-legacy"),
2901
- initiatorContext: jsonb4("initiator_context").$type().notNull().default({ backfill: true }),
3341
+ initiatorContext: jsonb5("initiator_context").$type().notNull().default({ backfill: true }),
3342
+ // Immutable human authority for exact-attempt governance. Human turns bind
3343
+ // their own subject; trusted continuations/compactions may inherit the
3344
+ // causal turn's value while retaining a service initiator. Null means the
3345
+ // turn has no human preference authority.
3346
+ initiatingHumanSubjectId: text5("initiating_human_subject_id"),
2902
3347
  // Immutable exact personal MCP authority for this logical turn. Recovery,
2903
3348
  // approval, retries, and Toolspace reuse this row; no runtime may infer
2904
3349
  // broader authority from the session creator or mutable session state.
2905
- personalConnectionDelegations: jsonb4("personal_connection_delegations").$type().notNull().default([]),
3350
+ personalConnectionDelegations: jsonb5("personal_connection_delegations").$type().notNull().default([]),
2906
3351
  cancelledBy: text5("cancelled_by"),
2907
3352
  cancelReason: text5("cancel_reason"),
2908
3353
  // Atomic per-turn toolspace call budget counter (migration 0043). Incremented
2909
3354
  // by a single conditional UPDATE at tools/call time; the row lock serializes
2910
3355
  // concurrent reservations so exactly `toolspaceMaxCallsPerTurn` succeed.
2911
- toolspaceCallCount: integer4("toolspace_call_count").notNull().default(0),
3356
+ toolspaceCallCount: integer5("toolspace_call_count").notNull().default(0),
2912
3357
  startedAt: timestamp5("started_at", { withTimezone: true }),
2913
3358
  finishedAt: timestamp5("finished_at", { withTimezone: true }),
2914
3359
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
@@ -2932,6 +3377,58 @@ var sessionTurns = pgTable5(
2932
3377
  )
2933
3378
  })
2934
3379
  );
3380
+ var sessionRealtimeContextProjections = pgTable5(
3381
+ "session_realtime_context_projections",
3382
+ {
3383
+ id: uuid5("id").primaryKey().defaultRandom(),
3384
+ accountId: uuid5("account_id").notNull(),
3385
+ workspaceId: uuid5("workspace_id").notNull(),
3386
+ sessionId: uuid5("session_id").notNull(),
3387
+ turnId: uuid5("turn_id").notNull(),
3388
+ context: text5("context"),
3389
+ sourceModeCount: integer5("source_mode_count").notNull(),
3390
+ sourceEntryCount: integer5("source_entry_count").notNull(),
3391
+ includedEntryCount: integer5("included_entry_count").notNull(),
3392
+ omittedEntryCount: integer5("omitted_entry_count").notNull(),
3393
+ createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
3394
+ },
3395
+ (table) => ({
3396
+ workspaceAccount: foreignKey({
3397
+ name: "session_realtime_context_projections_workspace_account_fk",
3398
+ columns: [table.workspaceId, table.accountId],
3399
+ foreignColumns: [workspaces.id, workspaces.accountId]
3400
+ }).onDelete("cascade"),
3401
+ workspaceSession: foreignKey({
3402
+ name: "session_realtime_context_projections_workspace_session_fk",
3403
+ columns: [table.workspaceId, table.sessionId],
3404
+ foreignColumns: [sessions.workspaceId, sessions.id]
3405
+ }).onDelete("cascade"),
3406
+ workspaceTurn: foreignKey({
3407
+ name: "session_realtime_context_projections_workspace_turn_fk",
3408
+ columns: [table.workspaceId, table.turnId],
3409
+ foreignColumns: [sessionTurns.workspaceId, sessionTurns.id]
3410
+ }).onDelete("cascade"),
3411
+ turn: uniqueIndex5("session_realtime_context_projections_turn_uq").on(
3412
+ table.workspaceId,
3413
+ table.sessionId,
3414
+ table.turnId
3415
+ ),
3416
+ contextValid: check4(
3417
+ "session_realtime_context_projections_context_check",
3418
+ sql5`${table.context} is null or octet_length(${table.context}) between 1 and 65536`
3419
+ ),
3420
+ countsValid: check4(
3421
+ "session_realtime_context_projections_counts_check",
3422
+ sql5`${table.sourceModeCount} >= 1
3423
+ and ${table.sourceEntryCount} >= 0
3424
+ and ${table.includedEntryCount} >= 0
3425
+ and ${table.omittedEntryCount} >= 0
3426
+ and ${table.includedEntryCount} + ${table.omittedEntryCount} = ${table.sourceEntryCount}
3427
+ and ((${table.sourceEntryCount} = 0 and ${table.context} is null)
3428
+ or (${table.sourceEntryCount} > 0 and ${table.context} is not null))`
3429
+ )
3430
+ })
3431
+ );
2935
3432
  var sessionTurnAttempts = pgTable5(
2936
3433
  "session_turn_attempts",
2937
3434
  {
@@ -2940,7 +3437,7 @@ var sessionTurnAttempts = pgTable5(
2940
3437
  workspaceId: uuid5("workspace_id").notNull(),
2941
3438
  sessionId: uuid5("session_id").notNull(),
2942
3439
  turnId: uuid5("turn_id").notNull(),
2943
- executionGeneration: integer4("execution_generation").notNull(),
3440
+ executionGeneration: integer5("execution_generation").notNull(),
2944
3441
  state: text5("state").notNull().default("claimed"),
2945
3442
  outcome: text5("outcome"),
2946
3443
  temporalWorkflowId: text5("temporal_workflow_id").notNull(),
@@ -2953,8 +3450,8 @@ var sessionTurnAttempts = pgTable5(
2953
3450
  mode: "number"
2954
3451
  }).notNull(),
2955
3452
  // Immutable policy snapshot captured under the session lock at claim.
2956
- mcpApprovalPolicies: jsonb4("mcp_approval_policies").$type().notNull(),
2957
- connectorActionPolicies: jsonb4("connector_action_policies").$type().notNull().default([]),
3453
+ mcpApprovalPolicies: jsonb5("mcp_approval_policies").$type().notNull(),
3454
+ connectorActionPolicies: jsonb5("connector_action_policies").$type().notNull().default([]),
2958
3455
  startedAt: timestamp5("started_at", { withTimezone: true }).notNull().defaultNow(),
2959
3456
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow(),
2960
3457
  closedAt: timestamp5("closed_at", { withTimezone: true }),
@@ -3034,20 +3531,20 @@ var connectorActionRequests = pgTable5(
3034
3531
  sessionId: uuid5("session_id").notNull(),
3035
3532
  turnId: uuid5("turn_id").notNull(),
3036
3533
  creationAttemptId: uuid5("creation_attempt_id").notNull(),
3037
- creationExecutionGeneration: integer4("creation_execution_generation").notNull(),
3534
+ creationExecutionGeneration: integer5("creation_execution_generation").notNull(),
3038
3535
  executionAttemptId: uuid5("execution_attempt_id"),
3039
- executionAttemptGeneration: integer4("execution_attempt_generation"),
3536
+ executionAttemptGeneration: integer5("execution_attempt_generation"),
3040
3537
  approvalId: text5("approval_id").notNull(),
3041
3538
  initiatorKind: text5("initiator_kind").$type().notNull(),
3042
3539
  initiatorSubjectId: text5("initiator_subject_id").notNull(),
3043
3540
  connectionId: text5("connection_id").notNull(),
3044
- connectionVersion: integer4("connection_version"),
3541
+ connectionVersion: integer5("connection_version"),
3045
3542
  serverId: text5("server_id").notNull(),
3046
3543
  toolName: text5("tool_name").notNull(),
3047
3544
  actionName: text5("action_name").notNull(),
3048
3545
  // Attempt-frozen provenance intentionally survives policy deletion.
3049
3546
  policyId: uuid5("policy_id"),
3050
- policyVersion: integer4("policy_version"),
3547
+ policyVersion: integer5("policy_version"),
3051
3548
  policySource: text5("policy_source").$type().notNull(),
3052
3549
  policyDecision: text5("policy_decision").$type().notNull(),
3053
3550
  actionFingerprint: text5("action_fingerprint").notNull(),
@@ -3144,10 +3641,10 @@ var sessionCommandReceipts = pgTable5(
3144
3641
  appliedControlRevision: bigint4("applied_control_revision", {
3145
3642
  mode: "number"
3146
3643
  }),
3147
- appliedQueueVersion: integer4("applied_queue_version"),
3148
- appliedTurnVersion: integer4("applied_turn_version"),
3644
+ appliedQueueVersion: integer5("applied_queue_version"),
3645
+ appliedTurnVersion: integer5("applied_turn_version"),
3149
3646
  appliedDraftRevision: bigint4("applied_draft_revision", { mode: "number" }),
3150
- result: jsonb4("result").$type().notNull().default({}),
3647
+ result: jsonb5("result").$type().notNull().default({}),
3151
3648
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
3152
3649
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
3153
3650
  },
@@ -3208,11 +3705,11 @@ var workspaceControlEvents = pgTable5(
3208
3705
  action: text5("action").notNull(),
3209
3706
  automatic: boolean3("automatic").notNull().default(false),
3210
3707
  reason: text5("reason"),
3211
- reasonOriginalBytes: integer4("reason_original_bytes"),
3708
+ reasonOriginalBytes: integer5("reason_original_bytes"),
3212
3709
  actor: text5("actor").notNull(),
3213
3710
  // Null is the rolling-upgrade shape for untouched, already-bounded legacy
3214
3711
  // rows. New writes and rewritten poison rows carry exact source byte facts.
3215
- actorOriginalBytes: integer4("actor_original_bytes"),
3712
+ actorOriginalBytes: integer5("actor_original_bytes"),
3216
3713
  occurredAt: timestamp5("occurred_at", { withTimezone: true }).notNull().defaultNow()
3217
3714
  },
3218
3715
  (table) => ({
@@ -3305,14 +3802,14 @@ var composerDrafts = pgTable5(
3305
3802
  subjectId: text5("subject_id").notNull(),
3306
3803
  revision: bigint4("revision", { mode: "number" }).notNull().default(1),
3307
3804
  text: text5("text").notNull().default(""),
3308
- resources: jsonb4("resources").$type().notNull().default([]),
3309
- tools: jsonb4("tools").$type().notNull().default([]),
3805
+ resources: jsonb5("resources").$type().notNull().default([]),
3806
+ tools: jsonb5("tools").$type().notNull().default([]),
3310
3807
  toolsProvided: boolean3("tools_provided").notNull().default(false),
3311
3808
  model: text5("model").notNull(),
3312
3809
  reasoningEffort: text5("reasoning_effort").notNull(),
3313
3810
  latencyMode: text5("latency_mode").notNull().default("standard"),
3314
3811
  sourceTurnId: uuid5("source_turn_id"),
3315
- sourceTurnVersion: integer4("source_turn_version"),
3812
+ sourceTurnVersion: integer5("source_turn_version"),
3316
3813
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
3317
3814
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
3318
3815
  },
@@ -3357,12 +3854,12 @@ var newSessionDrafts = pgTable5(
3357
3854
  subjectId: text5("subject_id").notNull(),
3358
3855
  revision: bigint4("revision", { mode: "number" }).notNull().default(1),
3359
3856
  text: text5("text").notNull().default(""),
3360
- resources: jsonb4("resources").$type().notNull().default([]),
3361
- tools: jsonb4("tools").$type().notNull().default([]),
3857
+ resources: jsonb5("resources").$type().notNull().default([]),
3858
+ tools: jsonb5("tools").$type().notNull().default([]),
3362
3859
  model: text5("model").notNull(),
3363
3860
  reasoningEffort: text5("reasoning_effort").notNull(),
3364
3861
  latencyMode: text5("latency_mode").notNull().default("standard"),
3365
- sessionOptions: jsonb4("session_options").$type().notNull().default({}),
3862
+ sessionOptions: jsonb5("session_options").$type().notNull().default({}),
3366
3863
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
3367
3864
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
3368
3865
  },
@@ -3399,11 +3896,11 @@ var sessionSystemUpdates = pgTable5(
3399
3896
  sourceId: text5("source_id").notNull(),
3400
3897
  dedupeKey: text5("dedupe_key").notNull(),
3401
3898
  summary: text5("summary").notNull(),
3402
- payload: jsonb4("payload").$type().notNull().default({}),
3403
- lineage: jsonb4("lineage").$type().notNull().default({}),
3899
+ payload: jsonb5("payload").$type().notNull().default({}),
3900
+ lineage: jsonb5("lineage").$type().notNull().default({}),
3404
3901
  // Private immutable authority frozen when this machine input is accepted.
3405
3902
  // Public projections intentionally omit connection ids and owner subjects.
3406
- personalConnectionDelegations: jsonb4("personal_connection_delegations").$type().notNull().default([]),
3903
+ personalConnectionDelegations: jsonb5("personal_connection_delegations").$type().notNull().default([]),
3407
3904
  // pending is visible queue truth; delivered means its exact model-memory
3408
3905
  // batch was durably claimed. Terminal cancellation/supersession is explicit.
3409
3906
  state: text5("state").notNull().default("pending"),
@@ -3464,13 +3961,13 @@ var sessionSystemUpdateOutbox = pgTable5(
3464
3961
  classification: text5("classification").notNull(),
3465
3962
  sourceId: text5("source_id").notNull(),
3466
3963
  summary: text5("summary").notNull(),
3467
- payload: jsonb4("payload").$type().notNull().default({}),
3468
- lineage: jsonb4("lineage").$type().notNull().default({}),
3964
+ payload: jsonb5("payload").$type().notNull().default({}),
3965
+ lineage: jsonb5("lineage").$type().notNull().default({}),
3469
3966
  // Exact private authority copied from the causal parent turn in the source
3470
3967
  // terminal transaction. Delivery retries cannot replace this snapshot.
3471
- personalConnectionDelegations: jsonb4("personal_connection_delegations").$type().notNull().default([]),
3968
+ personalConnectionDelegations: jsonb5("personal_connection_delegations").$type().notNull().default([]),
3472
3969
  status: text5("status").notNull().default("pending"),
3473
- attempts: integer4("attempts").notNull().default(0),
3970
+ attempts: integer5("attempts").notNull().default(0),
3474
3971
  updateId: uuid5("update_id"),
3475
3972
  lastError: text5("last_error"),
3476
3973
  deliveredAt: timestamp5("delivered_at", { withTimezone: true }),
@@ -3503,7 +4000,7 @@ var sessionWorkflowWakeOutbox = pgTable5(
3503
4000
  wakeRevision: bigint4("wake_revision", { mode: "number" }).notNull().default(1),
3504
4001
  deliveredRevision: bigint4("delivered_revision", { mode: "number" }).notNull().default(0),
3505
4002
  reason: text5("reason").notNull(),
3506
- attempts: integer4("attempts").notNull().default(0),
4003
+ attempts: integer5("attempts").notNull().default(0),
3507
4004
  nextAttemptAt: timestamp5("next_attempt_at", { withTimezone: true }).notNull().defaultNow(),
3508
4005
  lastError: text5("last_error"),
3509
4006
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
@@ -3554,27 +4051,23 @@ var sessionGoals = pgTable5(
3554
4051
  // agent | user_pause | api | no_progress | max_auto_continuations | limits
3555
4052
  createdBy: text5("created_by").notNull().default("api"),
3556
4053
  // api | agent | scheduled_task
3557
- version: integer4("version").notNull().default(1),
4054
+ version: integer5("version").notNull().default(1),
3558
4055
  // bumped on every set/update; progress signal
3559
- autoContinuations: integer4("auto_continuations").notNull().default(0),
3560
- noProgressStreak: integer4("no_progress_streak").notNull().default(0),
3561
- maxAutoContinuations: integer4("max_auto_continuations"),
4056
+ autoContinuations: integer5("auto_continuations").notNull().default(0),
4057
+ noProgressStreak: integer5("no_progress_streak").notNull().default(0),
4058
+ maxAutoContinuations: integer5("max_auto_continuations"),
3562
4059
  // per-goal override; a configured settings cap (if any) remains the hard ceiling
3563
4060
  lastContinuationTurnId: uuid5("last_continuation_turn_id"),
3564
- versionAtLastContinuation: integer4("version_at_last_continuation"),
4061
+ versionAtLastContinuation: integer5("version_at_last_continuation"),
3565
4062
  // Postgres owns the continuation obligation. Terminal settlement advances
3566
4063
  // wakeRevision in the same transaction that makes the session idle;
3567
4064
  // materialization advances observedRevision only alongside the one typed
3568
4065
  // update, timeline events, usage row, and workflow-wake outbox row.
3569
4066
  // Temporal signals and workflow history are replaceable nudges over these
3570
4067
  // monotonic revisions.
3571
- continuationWakeRevision: bigint4("continuation_wake_revision", {
3572
- mode: "number"
3573
- }).notNull().default(0),
3574
- continuationObservedRevision: bigint4("continuation_observed_revision", {
3575
- mode: "number"
3576
- }).notNull().default(0),
3577
- metadata: jsonb4("metadata").$type().notNull().default({}),
4068
+ continuationWakeRevision: bigint4("continuation_wake_revision", { mode: "number" }).notNull().default(0),
4069
+ continuationObservedRevision: bigint4("continuation_observed_revision", { mode: "number" }).notNull().default(0),
4070
+ metadata: jsonb5("metadata").$type().notNull().default({}),
3578
4071
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
3579
4072
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
3580
4073
  },
@@ -3603,23 +4096,23 @@ var codexCapacityWaiters = pgTable5(
3603
4096
  sessionId: uuid5("session_id").notNull(),
3604
4097
  goalId: uuid5("goal_id"),
3605
4098
  blockedTurnId: uuid5("blocked_turn_id").notNull(),
3606
- blockedTurnGeneration: integer4("blocked_turn_generation").notNull(),
4099
+ blockedTurnGeneration: integer5("blocked_turn_generation").notNull(),
3607
4100
  workflowId: text5("workflow_id").notNull(),
3608
- generation: integer4("generation").notNull().default(1),
4101
+ generation: integer5("generation").notNull().default(1),
3609
4102
  status: text5("status").notNull().default("waiting"),
3610
4103
  // waiting | resumed | superseded
3611
- goalVersion: integer4("goal_version"),
4104
+ goalVersion: integer5("goal_version"),
3612
4105
  policyHash: text5("policy_hash"),
3613
4106
  earliestResetAt: timestamp5("earliest_reset_at", { withTimezone: true }),
3614
4107
  nextCheckAt: timestamp5("next_check_at", { withTimezone: true }).notNull(),
3615
4108
  resetKind: text5("reset_kind").notNull(),
3616
4109
  // authoritative | bounded_refresh
3617
- refreshAttempt: integer4("refresh_attempt").notNull().default(0),
4110
+ refreshAttempt: integer5("refresh_attempt").notNull().default(0),
3618
4111
  // Coalescing outbox generation. Every eligibility-affecting mutation bumps
3619
4112
  // wakeRevision. Duplicate/lost Temporal signals are harmless because only
3620
4113
  // the row-locked evaluator moves observedWakeRevision and may enqueue work.
3621
- wakeRevision: integer4("wake_revision").notNull().default(1),
3622
- observedWakeRevision: integer4("observed_wake_revision").notNull().default(0),
4114
+ wakeRevision: integer5("wake_revision").notNull().default(1),
4115
+ observedWakeRevision: integer5("observed_wake_revision").notNull().default(0),
3623
4116
  lastWakeReason: text5("last_wake_reason").notNull().default("capacity_wait_armed"),
3624
4117
  resumedUpdateId: uuid5("resumed_update_id"),
3625
4118
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
@@ -3654,17 +4147,17 @@ var sessionEvents = pgTable5(
3654
4147
  workspaceId: uuid5("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
3655
4148
  sessionId: uuid5("session_id").notNull().references(() => sessions.id, { onDelete: "cascade" }),
3656
4149
  turnId: uuid5("turn_id"),
3657
- turnGeneration: integer4("turn_generation"),
4150
+ turnGeneration: integer5("turn_generation"),
3658
4151
  turnAttemptId: uuid5("turn_attempt_id"),
3659
4152
  turnAssociation: text5("turn_association"),
3660
4153
  duplicateOfEventId: uuid5("duplicate_of_event_id"),
3661
4154
  duplicateReason: text5("duplicate_reason"),
3662
- sequence: integer4("sequence").notNull(),
4155
+ sequence: integer5("sequence").notNull(),
3663
4156
  type: text5("type").notNull(),
3664
- payload: jsonb4("payload").$type().notNull().default({}),
4157
+ payload: jsonb5("payload").$type().notNull().default({}),
3665
4158
  clientEventId: text5("client_event_id"),
3666
4159
  producerId: text5("producer_id"),
3667
- producerSeq: integer4("producer_seq"),
4160
+ producerSeq: integer5("producer_seq"),
3668
4161
  occurredAt: timestamp5("occurred_at", { withTimezone: true }).notNull().defaultNow(),
3669
4162
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
3670
4163
  },
@@ -3730,9 +4223,9 @@ var agentRunStates = pgTable5("agent_run_states", {
3730
4223
  turnId: uuid5("turn_id").references(() => sessionTurns.id, {
3731
4224
  onDelete: "set null"
3732
4225
  }),
3733
- stateVersion: integer4("state_version").notNull(),
4226
+ stateVersion: integer5("state_version").notNull(),
3734
4227
  serializedRunState: text5("serialized_run_state").notNull(),
3735
- pendingApprovals: jsonb4("pending_approvals").$type().notNull().default([]),
4228
+ pendingApprovals: jsonb5("pending_approvals").$type().notNull().default([]),
3736
4229
  // The Codex account that FROZE this run state: the turn's resolved codex
3737
4230
  // credential id (pin > workspace-active), or NULL when frozen on the
3738
4231
  // non-codex / Azure path (or before this column existed). The serialized
@@ -3767,13 +4260,13 @@ var sessionHumanInputRequests = pgTable5(
3767
4260
  workspaceId: uuid5("workspace_id").notNull(),
3768
4261
  sessionId: uuid5("session_id").notNull(),
3769
4262
  turnId: uuid5("turn_id").notNull(),
3770
- turnGeneration: integer4("turn_generation").notNull(),
4263
+ turnGeneration: integer5("turn_generation").notNull(),
3771
4264
  creationAttemptId: uuid5("creation_attempt_id").notNull(),
3772
4265
  toolCallId: text5("tool_call_id").notNull(),
3773
4266
  status: text5("status").notNull().default("pending"),
3774
- questions: jsonb4("questions").$type().notNull(),
4267
+ questions: jsonb5("questions").$type().notNull(),
3775
4268
  allowSkip: boolean3("allow_skip").notNull().default(false),
3776
- response: jsonb4("response").$type(),
4269
+ response: jsonb5("response").$type(),
3777
4270
  respondedBy: text5("responded_by"),
3778
4271
  respondedAt: timestamp5("responded_at", { withTimezone: true }),
3779
4272
  expiresAt: timestamp5("expires_at", { withTimezone: true }),
@@ -3849,7 +4342,7 @@ var sessionHistoryItems = pgTable5(
3849
4342
  // positions; only the summary uses the half-step. `mode: "number"` maps the
3850
4343
  // postgres.js string back to a JS number so every reader stays numeric.
3851
4344
  position: numeric("position", { mode: "number" }).notNull(),
3852
- item: jsonb4("item").$type().notNull(),
4345
+ item: jsonb5("item").$type().notNull(),
3853
4346
  // Live-row flag for client-side context compaction. The read path selects
3854
4347
  // only active rows; a compaction supersedes the summarized prefix (sets this
3855
4348
  // false — never deletes, so the full transcript stays as an audit trail) and
@@ -3895,13 +4388,13 @@ var sessionPendingToolCalls = pgTable5(
3895
4388
  workspaceId: uuid5("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
3896
4389
  sessionId: uuid5("session_id").notNull().references(() => sessions.id, { onDelete: "cascade" }),
3897
4390
  turnId: uuid5("turn_id").notNull().references(() => sessionTurns.id, { onDelete: "cascade" }),
3898
- executionGeneration: integer4("execution_generation").notNull(),
4391
+ executionGeneration: integer5("execution_generation").notNull(),
3899
4392
  attemptId: uuid5("attempt_id").notNull(),
3900
4393
  callId: text5("call_id").notNull(),
3901
4394
  callType: text5("call_type").notNull(),
3902
- callItem: jsonb4("call_item").$type().notNull(),
3903
- modelToolOutputTruncationTokens: integer4("model_tool_output_truncation_tokens"),
3904
- resultItem: jsonb4("result_item").$type(),
4395
+ callItem: jsonb5("call_item").$type().notNull(),
4396
+ modelToolOutputTruncationTokens: integer5("model_tool_output_truncation_tokens"),
4397
+ resultItem: jsonb5("result_item").$type(),
3905
4398
  resultRecordedAt: timestamp5("result_recorded_at", { withTimezone: true }),
3906
4399
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
3907
4400
  },
@@ -3930,7 +4423,7 @@ var sandboxSessionEnvelopes = pgTable5(
3930
4423
  accountId: uuid5("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
3931
4424
  workspaceId: uuid5("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
3932
4425
  sessionId: uuid5("session_id").notNull().references(() => sessions.id, { onDelete: "cascade" }),
3933
- envelope: jsonb4("envelope").$type().notNull(),
4426
+ envelope: jsonb5("envelope").$type().notNull(),
3934
4427
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
3935
4428
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
3936
4429
  },
@@ -3958,27 +4451,27 @@ var sandboxCheckpointArtifacts = pgTable5(
3958
4451
  workspaceId: uuid5("workspace_id").notNull(),
3959
4452
  sandboxGroupId: uuid5("sandbox_group_id").notNull(),
3960
4453
  sourceLeaseId: uuid5("source_lease_id").notNull(),
3961
- sourceLeaseEpoch: integer4("source_lease_epoch").notNull(),
4454
+ sourceLeaseEpoch: integer5("source_lease_epoch").notNull(),
3962
4455
  sourceInstanceId: text5("source_instance_id"),
3963
- sourceWorkspaceGeneration: integer4("source_workspace_generation"),
4456
+ sourceWorkspaceGeneration: integer5("source_workspace_generation"),
3964
4457
  provenance: text5("provenance", {
3965
4458
  enum: ["native_capture", "legacy_provider_adopted"]
3966
4459
  }).notNull(),
3967
4460
  providerBackend: text5("provider_backend").notNull(),
3968
4461
  providerBindingKey: text5("provider_binding_key").notNull(),
3969
- providerBinding: jsonb4("provider_binding").$type().notNull(),
4462
+ providerBinding: jsonb5("provider_binding").$type().notNull(),
3970
4463
  objectKind: text5("object_kind", {
3971
4464
  enum: ["modal_filesystem_snapshot", "modal_directory_snapshot"]
3972
4465
  }).notNull(),
3973
4466
  objectId: text5("object_id").notNull(),
3974
4467
  archiveBase64: text5("archive_base64").notNull(),
3975
4468
  archiveSha256: text5("archive_sha256").notNull(),
3976
- archiveBytes: integer4("archive_bytes").notNull(),
3977
- descriptor: jsonb4("descriptor").$type().notNull(),
4469
+ archiveBytes: integer5("archive_bytes").notNull(),
4470
+ descriptor: jsonb5("descriptor").$type().notNull(),
3978
4471
  descriptorRevision: text5("descriptor_revision").notNull(),
3979
4472
  state: text5("state", { enum: sandboxCheckpointArtifactStateValues }).notNull().default("candidate"),
3980
4473
  deleteAfter: timestamp5("delete_after", { withTimezone: true }),
3981
- deleteAttempts: integer4("delete_attempts").notNull().default(0),
4474
+ deleteAttempts: integer5("delete_attempts").notNull().default(0),
3982
4475
  deleteClaimId: uuid5("delete_claim_id"),
3983
4476
  deleteClaimedAt: timestamp5("delete_claimed_at", { withTimezone: true }),
3984
4477
  lastDeleteError: text5("last_delete_error"),
@@ -4066,9 +4559,9 @@ var sandboxLeases = pgTable5(
4066
4559
  workspaceId: uuid5("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
4067
4560
  sandboxGroupId: uuid5("sandbox_group_id").notNull(),
4068
4561
  liveness: text5("liveness", { enum: sandboxLeaseLivenessValues }).notNull().default("cold"),
4069
- refcount: integer4("refcount").notNull().default(0),
4070
- turnHolders: integer4("turn_holders").notNull().default(0),
4071
- viewerHolders: integer4("viewer_holders").notNull().default(0),
4562
+ refcount: integer5("refcount").notNull().default(0),
4563
+ turnHolders: integer5("turn_holders").notNull().default(0),
4564
+ viewerHolders: integer5("viewer_holders").notNull().default(0),
4072
4565
  instanceId: text5("instance_id"),
4073
4566
  backend: text5("backend").notNull(),
4074
4567
  os: text5("os").notNull().default("linux"),
@@ -4098,21 +4591,21 @@ var sandboxLeases = pgTable5(
4098
4591
  // JS STRING from postgres-js, breaking the strict epoch-fence comparison (it
4099
4592
  // was always-true → every turn fenced); int4 returns a JS number, the fix.
4100
4593
  // Epochs never approach 2^31, so the narrower type loses nothing.
4101
- leaseEpoch: integer4("lease_epoch").notNull().default(0),
4594
+ leaseEpoch: integer5("lease_epoch").notNull().default(0),
4102
4595
  // Monotonic mutation intent for the live workspace. Every acknowledged
4103
4596
  // filesystem-writing operation advances this under the exact lease epoch +
4104
4597
  // provider-instance fence BEFORE it reaches the provider. A verified
4105
4598
  // archive fold copies the exact captured value into archive_generation in
4106
4599
  // the same row update; equality is the only durable completeness proof.
4107
- workspaceGeneration: integer4("workspace_generation").notNull().default(0),
4108
- archiveGeneration: integer4("archive_generation"),
4600
+ workspaceGeneration: integer5("workspace_generation").notNull().default(0),
4601
+ archiveGeneration: integer5("archive_generation"),
4109
4602
  // Provider-native capture may pause the live box. The exact claim is
4110
4603
  // acquired before provider I/O and cleared only after that capture settles;
4111
4604
  // new holders and workspace mutations fence on it. The SQL constraint also
4112
4605
  // requires the claimed generation to remain current, so an unaware writer
4113
4606
  // cannot advance generation through an active capture.
4114
4607
  archiveCaptureId: uuid5("archive_capture_id"),
4115
- archiveCaptureGeneration: integer4("archive_capture_generation"),
4608
+ archiveCaptureGeneration: integer5("archive_capture_generation"),
4116
4609
  archiveCaptureStartedAt: timestamp5("archive_capture_started_at", {
4117
4610
  withTimezone: true
4118
4611
  }),
@@ -4122,12 +4615,12 @@ var sandboxLeases = pgTable5(
4122
4615
  // The group box-envelope (the "envelope split" Critical): the small recovery
4123
4616
  // descriptor to resume()-by-id the group's box without a per-session join.
4124
4617
  resumeBackendId: text5("resume_backend_id"),
4125
- resumeState: jsonb4("resume_state").$type(),
4618
+ resumeState: jsonb5("resume_state").$type(),
4126
4619
  // Warm-time billing cursor: last_meter_at = accrual cursor; last_meter_tick =
4127
4620
  // idempotency tick (warm_seconds accrued idempotent on
4128
4621
  // (sandbox_group_id, lease_epoch, last_meter_tick) in P2.1).
4129
4622
  lastMeterAt: timestamp5("last_meter_at", { withTimezone: true }),
4130
- lastMeterTick: integer4("last_meter_tick").notNull().default(0),
4623
+ lastMeterTick: integer5("last_meter_tick").notNull().default(0),
4131
4624
  providerCreatedAt: timestamp5("provider_created_at", { withTimezone: true }),
4132
4625
  providerDeadlineAt: timestamp5("provider_deadline_at", {
4133
4626
  withTimezone: true
@@ -4221,9 +4714,7 @@ var sandboxLeaseHolders = pgTable5(
4221
4714
  accountId: uuid5("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
4222
4715
  workspaceId: uuid5("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
4223
4716
  leaseId: uuid5("lease_id").notNull().references(() => sandboxLeases.id, { onDelete: "cascade" }),
4224
- kind: text5("kind", {
4225
- enum: ["turn", "viewer", "direct", "process"]
4226
- }).notNull(),
4717
+ kind: text5("kind", { enum: ["turn", "viewer", "direct", "process"] }).notNull(),
4227
4718
  holderId: text5("holder_id").notNull(),
4228
4719
  // The attributing session within the (possibly shared) group.
4229
4720
  subjectId: uuid5("subject_id"),
@@ -4256,20 +4747,18 @@ var sandboxWorkspaceMutationAdmissions = pgTable5(
4256
4747
  leaseId: uuid5("lease_id").notNull().references(() => sandboxLeases.id, { onDelete: "cascade" }),
4257
4748
  sandboxGroupId: uuid5("sandbox_group_id").notNull(),
4258
4749
  sessionId: uuid5("session_id").notNull(),
4259
- actorKind: text5("actor_kind", {
4260
- enum: sandboxWorkspaceMutationActorKindValues
4261
- }).notNull(),
4750
+ actorKind: text5("actor_kind", { enum: sandboxWorkspaceMutationActorKindValues }).notNull(),
4262
4751
  actorId: uuid5("actor_id").notNull(),
4263
4752
  // Exact turn authority is present only for actor_kind='turn'. Direct HTTP
4264
4753
  // requests and retained processes never invent a turn or quiescence owner.
4265
4754
  turnId: uuid5("turn_id"),
4266
4755
  attemptId: uuid5("attempt_id"),
4267
- executionGeneration: integer4("execution_generation"),
4756
+ executionGeneration: integer5("execution_generation"),
4268
4757
  holderKind: text5("holder_kind", {
4269
4758
  enum: sandboxWorkspaceMutationHolderKindValues
4270
4759
  }).notNull(),
4271
4760
  holderId: text5("holder_id").notNull(),
4272
- leaseEpoch: integer4("lease_epoch").notNull(),
4761
+ leaseEpoch: integer5("lease_epoch").notNull(),
4273
4762
  providerBackend: text5("provider_backend").notNull(),
4274
4763
  providerInstanceId: text5("provider_instance_id").notNull(),
4275
4764
  routeKind: text5("route_kind", { enum: ["home", "active"] }).notNull(),
@@ -4277,8 +4766,8 @@ var sandboxWorkspaceMutationAdmissions = pgTable5(
4277
4766
  // target is pinned together with the active pointer epoch observed when the
4278
4767
  // operation was admitted.
4279
4768
  routeTargetId: uuid5("route_target_id"),
4280
- routeEpoch: integer4("route_epoch").notNull(),
4281
- workspaceGeneration: integer4("workspace_generation").notNull(),
4769
+ routeEpoch: integer5("route_epoch").notNull(),
4770
+ workspaceGeneration: integer5("workspace_generation").notNull(),
4282
4771
  operation: text5("operation").notNull(),
4283
4772
  providerOutcome: text5("provider_outcome", {
4284
4773
  enum: ["resolved", "rejected", "retained"]
@@ -4396,27 +4885,25 @@ var sandboxRetainedProcesses = pgTable5(
4396
4885
  sandboxGroupId: uuid5("sandbox_group_id").notNull(),
4397
4886
  parentAdmissionId: uuid5("parent_admission_id").notNull(),
4398
4887
  holderId: text5("holder_id").notNull(),
4399
- ownerActorKind: text5("owner_actor_kind", {
4400
- enum: ["turn", "direct"]
4401
- }).notNull(),
4888
+ ownerActorKind: text5("owner_actor_kind", { enum: ["turn", "direct"] }).notNull(),
4402
4889
  ownerActorId: uuid5("owner_actor_id").notNull(),
4403
4890
  ownerTurnId: uuid5("owner_turn_id"),
4404
4891
  ownerAttemptId: uuid5("owner_attempt_id"),
4405
- ownerExecutionGeneration: integer4("owner_execution_generation"),
4406
- leaseEpoch: integer4("lease_epoch").notNull(),
4892
+ ownerExecutionGeneration: integer5("owner_execution_generation"),
4893
+ leaseEpoch: integer5("lease_epoch").notNull(),
4407
4894
  providerBackend: text5("provider_backend").notNull(),
4408
4895
  providerInstanceId: text5("provider_instance_id").notNull(),
4409
4896
  // Provider object ids are namespace-scoped. New Modal processes bind the
4410
4897
  // exact authenticated workspace before execution; legacy rows remain null
4411
4898
  // until a positive lookup proves which namespace owns the historical box.
4412
4899
  providerBindingKey: text5("provider_binding_key"),
4413
- providerBinding: jsonb4("provider_binding").$type(),
4900
+ providerBinding: jsonb5("provider_binding").$type(),
4414
4901
  routeKind: text5("route_kind", { enum: ["home", "active"] }).notNull(),
4415
4902
  routeTargetId: uuid5("route_target_id"),
4416
- routeEpoch: integer4("route_epoch").notNull(),
4417
- providerSessionId: integer4("provider_session_id").notNull(),
4903
+ routeEpoch: integer5("route_epoch").notNull(),
4904
+ providerSessionId: integer5("provider_session_id").notNull(),
4418
4905
  state: text5("state", { enum: sandboxRetainedProcessStateValues }).notNull().default("active"),
4419
- exitCode: integer4("exit_code"),
4906
+ exitCode: integer5("exit_code"),
4420
4907
  settlementReason: text5("settlement_reason"),
4421
4908
  startedAt: timestamp5("started_at", { withTimezone: true }).notNull().defaultNow(),
4422
4909
  settledAt: timestamp5("settled_at", { withTimezone: true }),
@@ -4426,19 +4913,13 @@ var sandboxRetainedProcesses = pgTable5(
4426
4913
  // never exit/loss proof.
4427
4914
  reconcileAfter: timestamp5("reconcile_after", { withTimezone: true }).notNull().defaultNow(),
4428
4915
  reconcileClaimId: uuid5("reconcile_claim_id"),
4429
- reconcileClaimedAt: timestamp5("reconcile_claimed_at", {
4430
- withTimezone: true
4431
- }),
4432
- reconcileAttempts: integer4("reconcile_attempts").notNull().default(0),
4916
+ reconcileClaimedAt: timestamp5("reconcile_claimed_at", { withTimezone: true }),
4917
+ reconcileAttempts: integer5("reconcile_attempts").notNull().default(0),
4433
4918
  lastReconcileOutcome: text5("last_reconcile_outcome"),
4434
- reconcileProofOutcome: text5("reconcile_proof_outcome", {
4435
- enum: ["exited", "lost"]
4436
- }),
4437
- reconcileProofExitCode: integer4("reconcile_proof_exit_code"),
4919
+ reconcileProofOutcome: text5("reconcile_proof_outcome", { enum: ["exited", "lost"] }),
4920
+ reconcileProofExitCode: integer5("reconcile_proof_exit_code"),
4438
4921
  reconcileProofReason: text5("reconcile_proof_reason"),
4439
- reconcileProofObservedAt: timestamp5("reconcile_proof_observed_at", {
4440
- withTimezone: true
4441
- })
4922
+ reconcileProofObservedAt: timestamp5("reconcile_proof_observed_at", { withTimezone: true })
4442
4923
  },
4443
4924
  (table) => ({
4444
4925
  workspaceAccount: foreignKey({
@@ -4614,8 +5095,8 @@ var sessionRecordings = pgTable5(
4614
5095
  storageKey: text5("storage_key"),
4615
5096
  sizeBytes: bigint4("size_bytes", { mode: "number" }),
4616
5097
  durationSeconds: numeric("duration_seconds").$type(),
4617
- width: integer4("width").notNull(),
4618
- height: integer4("height").notNull(),
5098
+ width: integer5("width").notNull(),
5099
+ height: integer5("height").notNull(),
4619
5100
  reason: text5("reason"),
4620
5101
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
4621
5102
  finalizedAt: timestamp5("finalized_at", { withTimezone: true })
@@ -4639,7 +5120,7 @@ var workspaceCaptures = pgTable5(
4639
5120
  onDelete: "set null"
4640
5121
  }),
4641
5122
  revision: bigint4("revision", { mode: "number" }).notNull(),
4642
- leaseEpoch: integer4("lease_epoch").notNull(),
5123
+ leaseEpoch: integer5("lease_epoch").notNull(),
4643
5124
  // 'available' on a committed capture. 'failed' reserved for a future two-phase
4644
5125
  // write; the current synchronous capture only ever inserts 'available'.
4645
5126
  state: text5("state", { enum: ["available", "failed"] }).notNull().default("available"),
@@ -4649,9 +5130,9 @@ var workspaceCaptures = pgTable5(
4649
5130
  // or sign it independently of the (usually small) manifest metadata.
4650
5131
  treeIndexKey: text5("tree_index_key"),
4651
5132
  // Content-addressed after-image blob keys this revision references (GC input).
4652
- blobKeys: jsonb4("blob_keys").$type().notNull().default([]),
5133
+ blobKeys: jsonb5("blob_keys").$type().notNull().default([]),
4653
5134
  sizeBytes: bigint4("size_bytes", { mode: "number" }),
4654
- stats: jsonb4("stats").$type().notNull().default({}),
5135
+ stats: jsonb5("stats").$type().notNull().default({}),
4655
5136
  capturedAt: timestamp5("captured_at", { withTimezone: true }).notNull().defaultNow()
4656
5137
  },
4657
5138
  (table) => ({
@@ -4679,15 +5160,15 @@ var sandboxPtySessions = pgTable5(
4679
5160
  retainedProcessId: uuid5("retained_process_id"),
4680
5161
  openAdmissionId: uuid5("open_admission_id"),
4681
5162
  // Copied provider locator for the adopted retained process.
4682
- execSessionId: integer4("exec_session_id"),
4683
- leaseEpoch: integer4("lease_epoch").notNull(),
5163
+ execSessionId: integer5("exec_session_id"),
5164
+ leaseEpoch: integer5("lease_epoch").notNull(),
4684
5165
  providerBackend: text5("provider_backend"),
4685
5166
  providerInstanceId: text5("provider_instance_id"),
4686
5167
  routeKind: text5("route_kind", { enum: ["home", "active"] }),
4687
5168
  routeTargetId: uuid5("route_target_id"),
4688
- routeEpoch: integer4("route_epoch"),
4689
- cols: integer4("cols").notNull(),
4690
- rows: integer4("rows").notNull(),
5169
+ routeEpoch: integer5("route_epoch"),
5170
+ cols: integer5("cols").notNull(),
5171
+ rows: integer5("rows").notNull(),
4691
5172
  shell: text5("shell").notNull(),
4692
5173
  cwd: text5("cwd").notNull(),
4693
5174
  status: text5("status").notNull().default("open"),
@@ -4943,15 +5424,15 @@ var scheduledTasks = pgTable5(
4943
5424
  workspaceId: uuid5("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
4944
5425
  name: text5("name").notNull(),
4945
5426
  status: text5("status").notNull().default("active"),
4946
- schedule: jsonb4("schedule").$type().notNull(),
5427
+ schedule: jsonb5("schedule").$type().notNull(),
4947
5428
  temporalScheduleId: text5("temporal_schedule_id").notNull(),
4948
5429
  runMode: text5("run_mode").notNull().default("new_session_per_run"),
4949
5430
  overlapPolicy: text5("overlap_policy").notNull().default("allow_concurrent"),
4950
- agentConfig: jsonb4("agent_config").$type().notNull(),
5431
+ agentConfig: jsonb5("agent_config").$type().notNull(),
4951
5432
  createdByKind: text5("created_by_kind").notNull().default("service"),
4952
5433
  createdBySubjectId: text5("created_by_subject_id").notNull().default("unattributed-legacy"),
4953
- createdByContext: jsonb4("created_by_context").$type().notNull().default({ backfill: true }),
4954
- personalConnectionDelegations: jsonb4("personal_connection_delegations").$type().notNull().default([]),
5434
+ createdByContext: jsonb5("created_by_context").$type().notNull().default({ backfill: true }),
5435
+ personalConnectionDelegations: jsonb5("personal_connection_delegations").$type().notNull().default([]),
4955
5436
  reusableSessionId: uuid5("reusable_session_id").references(() => sessions.id, {
4956
5437
  onDelete: "set null"
4957
5438
  }),
@@ -4962,7 +5443,7 @@ var scheduledTasks = pgTable5(
4962
5443
  // (migration 0047). NULL ⇒ no rig. FK (-> rigs(id) ON DELETE SET NULL) lives
4963
5444
  // in migration 0047 (forward-reference pattern). Consumed in M3.
4964
5445
  rigId: uuid5("rig_id"),
4965
- metadata: jsonb4("metadata").$type().notNull().default({}),
5446
+ metadata: jsonb5("metadata").$type().notNull().default({}),
4966
5447
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
4967
5448
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
4968
5449
  },
@@ -5019,7 +5500,7 @@ var githubInstallations = pgTable5(
5019
5500
  id: uuid5("id").primaryKey().defaultRandom(),
5020
5501
  accountId: uuid5("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
5021
5502
  workspaceId: uuid5("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
5022
- installationId: integer4("installation_id").notNull(),
5503
+ installationId: integer5("installation_id").notNull(),
5023
5504
  githubAccountId: bigint4("github_account_id", { mode: "number" }),
5024
5505
  accountLogin: text5("account_login"),
5025
5506
  accountType: text5("account_type"),
@@ -5028,12 +5509,8 @@ var githubInstallations = pgTable5(
5028
5509
  githubActorId: bigint4("github_actor_id", { mode: "number" }),
5029
5510
  githubActorLogin: text5("github_actor_login"),
5030
5511
  authorityKind: text5("authority_kind"),
5031
- authorityCheckedAt: timestamp5("authority_checked_at", {
5032
- withTimezone: true
5033
- }),
5034
- authorityExpiresAt: timestamp5("authority_expires_at", {
5035
- withTimezone: true
5036
- }),
5512
+ authorityCheckedAt: timestamp5("authority_checked_at", { withTimezone: true }),
5513
+ authorityExpiresAt: timestamp5("authority_expires_at", { withTimezone: true }),
5037
5514
  authorityNonce: text5("authority_nonce"),
5038
5515
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
5039
5516
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
@@ -5104,7 +5581,7 @@ var githubInstallationRepositories = pgTable5(
5104
5581
  id: uuid5("id").primaryKey().defaultRandom(),
5105
5582
  accountId: uuid5("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
5106
5583
  workspaceId: uuid5("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
5107
- installationId: integer4("installation_id").notNull(),
5584
+ installationId: integer5("installation_id").notNull(),
5108
5585
  repositoryId: bigint4("repository_id", { mode: "number" }).notNull(),
5109
5586
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
5110
5587
  },
@@ -5151,7 +5628,7 @@ var usageEvents = pgTable5(
5151
5628
  turnAttemptId: uuid5("turn_attempt_id"),
5152
5629
  initiatorKind: text5("initiator_kind"),
5153
5630
  initiatorSubjectId: text5("initiator_subject_id"),
5154
- initiatorContext: jsonb4("initiator_context").$type().notNull().default({}),
5631
+ initiatorContext: jsonb5("initiator_context").$type().notNull().default({}),
5155
5632
  origin: text5("origin"),
5156
5633
  idempotencyKey: text5("idempotency_key").notNull(),
5157
5634
  occurredAt: timestamp5("occurred_at", { withTimezone: true }).notNull(),
@@ -5290,7 +5767,7 @@ var modelCallFacts = pgTable5(
5290
5767
  var hostExportConfig = pgTable5(
5291
5768
  "host_export_config",
5292
5769
  {
5293
- id: integer4("id").primaryKey().default(1),
5770
+ id: integer5("id").primaryKey().default(1),
5294
5771
  sessionEventsEnabled: boolean3("session_events_enabled").notNull().default(false),
5295
5772
  usageEventsEnabled: boolean3("usage_events_enabled").notNull().default(false),
5296
5773
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
@@ -5311,24 +5788,22 @@ var hostExportOutbox = pgTable5(
5311
5788
  sessionId: uuid5("session_id"),
5312
5789
  rootSessionId: uuid5("root_session_id"),
5313
5790
  turnId: uuid5("turn_id"),
5314
- turnGeneration: integer4("turn_generation"),
5791
+ turnGeneration: integer5("turn_generation"),
5315
5792
  turnAttemptId: uuid5("turn_attempt_id"),
5316
- sessionSequence: integer4("session_sequence"),
5793
+ sessionSequence: integer5("session_sequence"),
5317
5794
  clientEventId: text5("client_event_id"),
5318
5795
  turnAssociation: text5("turn_association"),
5319
5796
  duplicateOfEventId: uuid5("duplicate_of_event_id"),
5320
5797
  duplicateReason: text5("duplicate_reason"),
5321
5798
  eventType: text5("event_type").notNull(),
5322
5799
  idempotencyKey: text5("idempotency_key").notNull(),
5323
- initiator: jsonb4("initiator").$type(),
5324
- initiatorContext: jsonb4("initiator_context").$type().notNull().default({}),
5800
+ initiator: jsonb5("initiator").$type(),
5801
+ initiatorContext: jsonb5("initiator_context").$type().notNull().default({}),
5325
5802
  origin: text5("origin"),
5326
- payload: jsonb4("payload").$type().notNull(),
5327
- envelopeBytes: integer4("envelope_bytes").notNull(),
5803
+ payload: jsonb5("payload").$type().notNull(),
5804
+ envelopeBytes: integer5("envelope_bytes").notNull(),
5328
5805
  occurredAt: timestamp5("occurred_at", { withTimezone: true }).notNull(),
5329
- sourceRecordedAt: timestamp5("source_recorded_at", {
5330
- withTimezone: true
5331
- }).notNull(),
5806
+ sourceRecordedAt: timestamp5("source_recorded_at", { withTimezone: true }).notNull(),
5332
5807
  enqueuedAt: timestamp5("enqueued_at", { withTimezone: true }).notNull()
5333
5808
  },
5334
5809
  (table) => ({
@@ -5389,7 +5864,7 @@ var hostExportConsumers = pgTable5(
5389
5864
  leaseExpiresAt: timestamp5("lease_expires_at", { withTimezone: true }),
5390
5865
  leaseFrom: bigint4("lease_from", { mode: "bigint" }),
5391
5866
  leaseThrough: bigint4("lease_through", { mode: "bigint" }),
5392
- consecutiveFailures: integer4("consecutive_failures").notNull().default(0),
5867
+ consecutiveFailures: integer5("consecutive_failures").notNull().default(0),
5393
5868
  nextAttemptAt: timestamp5("next_attempt_at", { withTimezone: true }).notNull().defaultNow(),
5394
5869
  lastError: text5("last_error"),
5395
5870
  lastErrorAt: timestamp5("last_error_at", { withTimezone: true }),
@@ -5423,7 +5898,7 @@ var hostExportDeadLetters = pgTable5(
5423
5898
  exportCursor: bigint4("export_cursor", { mode: "bigint" }).notNull(),
5424
5899
  sourceId: uuid5("source_id").notNull(),
5425
5900
  reason: text5("reason").notNull(),
5426
- envelope: jsonb4("envelope").$type().notNull(),
5901
+ envelope: jsonb5("envelope").$type().notNull(),
5427
5902
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
5428
5903
  },
5429
5904
  (table) => ({
@@ -5460,7 +5935,7 @@ var creditLedgerEntries = pgTable5(
5460
5935
  sourceType: text5("source_type"),
5461
5936
  sourceId: text5("source_id"),
5462
5937
  idempotencyKey: text5("idempotency_key").notNull(),
5463
- metadata: jsonb4("metadata").$type().notNull().default({}),
5938
+ metadata: jsonb5("metadata").$type().notNull().default({}),
5464
5939
  occurredAt: timestamp5("occurred_at", { withTimezone: true }).notNull().defaultNow(),
5465
5940
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
5466
5941
  },
@@ -5498,7 +5973,7 @@ var stripeWebhookEvents = pgTable5("stripe_webhook_events", {
5498
5973
  id: text5("id").primaryKey(),
5499
5974
  type: text5("type").notNull(),
5500
5975
  livemode: text5("livemode").notNull().default("false"),
5501
- payload: jsonb4("payload").$type().notNull(),
5976
+ payload: jsonb5("payload").$type().notNull(),
5502
5977
  processedAt: timestamp5("processed_at", { withTimezone: true }),
5503
5978
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
5504
5979
  });
@@ -5516,7 +5991,7 @@ var auditEvents = pgTable5(
5516
5991
  action: text5("action").notNull(),
5517
5992
  targetType: text5("target_type"),
5518
5993
  targetId: text5("target_id"),
5519
- metadata: jsonb4("metadata").$type().notNull().default({}),
5994
+ metadata: jsonb5("metadata").$type().notNull().default({}),
5520
5995
  occurredAt: timestamp5("occurred_at", { withTimezone: true }).notNull().defaultNow()
5521
5996
  },
5522
5997
  (table) => ({
@@ -5535,7 +6010,7 @@ var packInstallations = pgTable5(
5535
6010
  workspaceId: uuid5("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
5536
6011
  packId: text5("pack_id").notNull(),
5537
6012
  status: text5("status").notNull().default("active"),
5538
- metadata: jsonb4("metadata").$type().notNull().default({}),
6013
+ metadata: jsonb5("metadata").$type().notNull().default({}),
5539
6014
  enabledAt: timestamp5("enabled_at", { withTimezone: true }).notNull().defaultNow(),
5540
6015
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
5541
6016
  },
@@ -5554,7 +6029,7 @@ var workspacePacks = pgTable5(
5554
6029
  accountId: uuid5("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
5555
6030
  workspaceId: uuid5("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
5556
6031
  packId: text5("pack_id").notNull(),
5557
- manifest: jsonb4("manifest").$type().notNull(),
6032
+ manifest: jsonb5("manifest").$type().notNull(),
5558
6033
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
5559
6034
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
5560
6035
  },
@@ -5573,12 +6048,12 @@ var importBatches = pgTable5(
5573
6048
  snapshotDate: timestamp5("snapshot_date", { withTimezone: true }).notNull(),
5574
6049
  snapshotRef: text5("snapshot_ref"),
5575
6050
  attributionNote: text5("attribution_note").notNull(),
5576
- importedCount: integer4("imported_count").notNull().default(0),
5577
- skippedCount: integer4("skipped_count").notNull().default(0),
5578
- quarantinedCount: integer4("quarantined_count").notNull().default(0),
5579
- logoFailureCount: integer4("logo_failure_count").notNull().default(0),
5580
- staleCount: integer4("stale_count").notNull().default(0),
5581
- details: jsonb4("details").$type().notNull().default({}),
6051
+ importedCount: integer5("imported_count").notNull().default(0),
6052
+ skippedCount: integer5("skipped_count").notNull().default(0),
6053
+ quarantinedCount: integer5("quarantined_count").notNull().default(0),
6054
+ logoFailureCount: integer5("logo_failure_count").notNull().default(0),
6055
+ staleCount: integer5("stale_count").notNull().default(0),
6056
+ details: jsonb5("details").$type().notNull().default({}),
5582
6057
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
5583
6058
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
5584
6059
  },
@@ -5605,7 +6080,7 @@ var capabilityCatalogItems = pgTable5(
5605
6080
  name: text5("name").notNull(),
5606
6081
  description: text5("description"),
5607
6082
  category: text5("category").notNull().default("custom"),
5608
- tags: jsonb4("tags").$type().notNull().default([]),
6083
+ tags: jsonb5("tags").$type().notNull().default([]),
5609
6084
  homepageUrl: text5("homepage_url"),
5610
6085
  endpointUrl: text5("endpoint_url"),
5611
6086
  installUrl: text5("install_url"),
@@ -5615,7 +6090,7 @@ var capabilityCatalogItems = pgTable5(
5615
6090
  transport: text5("transport"),
5616
6091
  mcpUrl: text5("mcp_url"),
5617
6092
  authKind: text5("auth_kind"),
5618
- credentialFacts: jsonb4("credential_facts").$type().notNull().default([]),
6093
+ credentialFacts: jsonb5("credential_facts").$type().notNull().default([]),
5619
6094
  tier: text5("tier"),
5620
6095
  provenance: text5("provenance"),
5621
6096
  logoAssetPath: text5("logo_asset_path"),
@@ -5624,7 +6099,7 @@ var capabilityCatalogItems = pgTable5(
5624
6099
  }),
5625
6100
  stale: boolean3("stale").notNull().default(false),
5626
6101
  staleAt: timestamp5("stale_at", { withTimezone: true }),
5627
- metadata: jsonb4("metadata").$type().notNull().default({}),
6102
+ metadata: jsonb5("metadata").$type().notNull().default({}),
5628
6103
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
5629
6104
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
5630
6105
  },
@@ -5662,8 +6137,8 @@ var capabilityInstallations = pgTable5(
5662
6137
  capabilityId: text5("capability_id").notNull(),
5663
6138
  kind: text5("kind").notNull(),
5664
6139
  status: text5("status").notNull().default("active"),
5665
- config: jsonb4("config").$type().notNull().default({}),
5666
- metadata: jsonb4("metadata").$type().notNull().default({}),
6140
+ config: jsonb5("config").$type().notNull().default({}),
6141
+ metadata: jsonb5("metadata").$type().notNull().default({}),
5667
6142
  enabledAt: timestamp5("enabled_at", { withTimezone: true }).notNull().defaultNow(),
5668
6143
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
5669
6144
  },
@@ -5690,14 +6165,14 @@ var socialConnections = pgTable5(
5690
6165
  accountName: text5("account_name"),
5691
6166
  externalAccountId: text5("external_account_id"),
5692
6167
  status: text5("status").notNull().default("connected"),
5693
- scopes: jsonb4("scopes").$type().notNull().default([]),
6168
+ scopes: jsonb5("scopes").$type().notNull().default([]),
5694
6169
  credentialRef: text5("credential_ref"),
5695
6170
  // AES-256-GCM envelope (environment-crypto v1 format) holding the OAuth
5696
6171
  // token bundle. Never exposed through contracts or MCP tools; only the
5697
6172
  // host-side social API client decrypts it.
5698
6173
  credentialEncrypted: text5("credential_encrypted"),
5699
- tokenMetadata: jsonb4("token_metadata").$type().notNull().default({}),
5700
- metadata: jsonb4("metadata").$type().notNull().default({}),
6174
+ tokenMetadata: jsonb5("token_metadata").$type().notNull().default({}),
6175
+ metadata: jsonb5("metadata").$type().notNull().default({}),
5701
6176
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow(),
5702
6177
  updatedAt: timestamp5("updated_at", { withTimezone: true }).notNull().defaultNow()
5703
6178
  },
@@ -5727,8 +6202,8 @@ var socialPosts = pgTable5(
5727
6202
  authorHandle: text5("author_handle"),
5728
6203
  text: text5("text").notNull(),
5729
6204
  publishedAt: timestamp5("published_at", { withTimezone: true }).notNull(),
5730
- metrics: jsonb4("metrics").$type().notNull().default({}),
5731
- raw: jsonb4("raw").$type().notNull().default({}),
6205
+ metrics: jsonb5("metrics").$type().notNull().default({}),
6206
+ raw: jsonb5("raw").$type().notNull().default({}),
5732
6207
  createdAt: timestamp5("created_at", { withTimezone: true }).notNull().defaultNow()
5733
6208
  },
5734
6209
  (table) => ({
@@ -5774,15 +6249,15 @@ var rigVersions = pgTable5(
5774
6249
  accountId: uuid5("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
5775
6250
  workspaceId: uuid5("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
5776
6251
  rigId: uuid5("rig_id").notNull().references(() => rigs.id, { onDelete: "cascade" }),
5777
- version: integer4("version").notNull(),
6252
+ version: integer5("version").notNull(),
5778
6253
  image: text5("image"),
5779
6254
  setupScript: text5("setup_script"),
5780
6255
  // Self-declared health checks: [{ name, command }].
5781
- checks: jsonb4("checks").$type().notNull().default([]),
6256
+ checks: jsonb5("checks").$type().notNull().default([]),
5782
6257
  // Registered credential-hook names (resolved to hook implementations in M3).
5783
- credentialHooks: jsonb4("credential_hooks").$type().notNull().default([]),
6258
+ credentialHooks: jsonb5("credential_hooks").$type().notNull().default([]),
5784
6259
  // Variable-set ids layered below the session's variable set at run time (M3).
5785
- defaultVariableSetIds: jsonb4("default_variable_set_ids").$type().notNull().default([]),
6260
+ defaultVariableSetIds: jsonb5("default_variable_set_ids").$type().notNull().default([]),
5786
6261
  changelog: text5("changelog"),
5787
6262
  createdBy: text5("created_by"),
5788
6263
  active: boolean3("active").notNull().default(false),
@@ -5811,11 +6286,11 @@ var rigChanges = pgTable5(
5811
6286
  }),
5812
6287
  // 'setup_append' | 'definition_edit' (CHECK in migration 0047).
5813
6288
  kind: text5("kind").notNull(),
5814
- payload: jsonb4("payload").$type().notNull(),
6289
+ payload: jsonb5("payload").$type().notNull(),
5815
6290
  // 'proposed' | 'verifying' | 'merged' | 'rejected' | 'failed' (CHECK in 0047).
5816
6291
  status: text5("status").notNull().default("proposed"),
5817
6292
  proposedBy: text5("proposed_by"),
5818
- verification: jsonb4("verification").$type(),
6293
+ verification: jsonb5("verification").$type(),
5819
6294
  resultVersionId: uuid5("result_version_id").references(() => rigVersions.id, {
5820
6295
  onDelete: "set null"
5821
6296
  }),
@@ -5836,6 +6311,7 @@ export {
5836
6311
  workspaceInstructionPolicyRevisions,
5837
6312
  workspaceInstructionPolicyHeads,
5838
6313
  workspaceInstructionPolicyActivationEvents,
6314
+ workspaceInstructionPolicySnapshots,
5839
6315
  preferenceRegistryPreferences,
5840
6316
  preferenceRegistryRevisions,
5841
6317
  preferenceRegistryEvents,
@@ -5873,6 +6349,7 @@ export {
5873
6349
  codexSubscriptionCredentials,
5874
6350
  codexResetRedemptionAttempts,
5875
6351
  connections,
6352
+ connectionDisconnectOperations,
5876
6353
  connectorActionPolicies,
5877
6354
  slackBotUserLinks,
5878
6355
  slackInteractionInbox,
@@ -5886,6 +6363,9 @@ export {
5886
6363
  workspaceModelPolicies,
5887
6364
  codexCredentialLeases,
5888
6365
  sessions,
6366
+ sessionRealtimeModes,
6367
+ sessionRealtimeConnections,
6368
+ sessionRealtimeEntries,
5889
6369
  sessionSpawnDenials,
5890
6370
  sessionPins,
5891
6371
  sessionListSnapshots,
@@ -5897,6 +6377,7 @@ export {
5897
6377
  documentChunks,
5898
6378
  knowledgeMemories,
5899
6379
  sessionTurns,
6380
+ sessionRealtimeContextProjections,
5900
6381
  sessionTurnAttempts,
5901
6382
  connectorActionRequests,
5902
6383
  sessionCommandReceipts,
@@ -5968,4 +6449,4 @@ export {
5968
6449
  rigChanges,
5969
6450
  schema_exports
5970
6451
  };
5971
- //# sourceMappingURL=chunk-CYGFLLMN.js.map
6452
+ //# sourceMappingURL=chunk-7WTDI7Y3.js.map