@opengeni/db 0.7.2 → 0.9.3

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 (59) hide show
  1. package/dist/{chunk-B22X3IEZ.js → chunk-4LG5NBTC.js} +512 -32
  2. package/dist/chunk-4LG5NBTC.js.map +1 -0
  3. package/dist/{chunk-YFQ7SGE4.js → chunk-BMFDXFPA.js} +23 -1
  4. package/dist/chunk-BMFDXFPA.js.map +1 -0
  5. package/dist/chunk-KW526IJA.js +127 -0
  6. package/dist/chunk-KW526IJA.js.map +1 -0
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.js +6092 -2080
  9. package/dist/index.js.map +1 -1
  10. package/dist/migrate.d.ts +29 -4
  11. package/dist/migrate.js +3 -1
  12. package/dist/provision-roles.d.ts +732 -47
  13. package/dist/provision-roles.js +1 -1
  14. package/dist/{schema-BN5mB9xZ.d.ts → schema-CdPGTHlD.d.ts} +2118 -119
  15. package/dist/schema.d.ts +1 -1
  16. package/dist/schema.js +17 -1
  17. package/drizzle/0064_rotation_strategy_sharded_backfill.sql +15 -0
  18. package/drizzle/0065_session_attempt_quiescence.sql +26 -0
  19. package/drizzle/0066_session_interruption_attempt_lookup.sql +4 -0
  20. package/drizzle/0067_session_event_payload_bounds.sql +209 -0
  21. package/drizzle/0068_workspace_control_event_bounds.sql +134 -0
  22. package/drizzle/0069_session_event_history_backfill.sql +32 -0
  23. package/drizzle/0070_session_event_type_sequence_lookup.sql +4 -0
  24. package/drizzle/0071_session_event_monitoring_tail.sql +10 -0
  25. package/drizzle/0072_sessions_workspace_created_id_idx.sql +4 -0
  26. package/drizzle/0073_sessions_workspace_updated_id_idx.sql +4 -0
  27. package/drizzle/0074_session_activity_revisions.sql +72 -0
  28. package/drizzle/0075_sessions_workspace_activity_revision_idx.sql +4 -0
  29. package/drizzle/0076_session_workflow_wake_acl.sql +13 -0
  30. package/drizzle/0077_session_attempt_latest_lookup.sql +4 -0
  31. package/drizzle/0094_quarantine_credential_bearing_catalog_urls.sql +51 -0
  32. package/drizzle/0095_github_existing_installations.sql +84 -0
  33. package/drizzle/0096_session_turn_initiators.sql +97 -0
  34. package/drizzle/0097_host_export_outbox.sql +1220 -0
  35. package/drizzle/0098_usage_events_workspace_session_idx.sql +4 -0
  36. package/drizzle/0099_session_human_input_attempt_owner_index.sql +6 -0
  37. package/drizzle/0100_session_human_input_requests.sql +89 -0
  38. package/drizzle/0101_session_mcp_connection_refs.sql +30 -0
  39. package/drizzle/0102_session_command_receipt_service_actor.sql +16 -0
  40. package/drizzle/0103_host_export_root_session.sql +166 -0
  41. package/drizzle/0104_host_export_root_session_backfill.sql +27 -0
  42. package/drizzle/0105_session_turn_instructions.sql +9 -0
  43. package/package.json +4 -4
  44. package/src/connection-token-resolver.ts +287 -1
  45. package/src/event-payload-sanitizer.ts +57 -19
  46. package/src/index.ts +5429 -1131
  47. package/src/memory-domain.ts +1 -1
  48. package/src/migrate.ts +86 -23
  49. package/src/persistence-errors.ts +252 -0
  50. package/src/provision-roles.ts +42 -0
  51. package/src/schema.ts +552 -34
  52. package/src/session-control.ts +518 -38
  53. package/src/session-queue-commands.ts +308 -57
  54. package/src/session-tool-call-settlement.ts +58 -7
  55. package/src/turn-initiator.ts +155 -0
  56. package/dist/chunk-7LDU7F5P.js +0 -80
  57. package/dist/chunk-7LDU7F5P.js.map +0 -1
  58. package/dist/chunk-B22X3IEZ.js.map +0 -1
  59. package/dist/chunk-YFQ7SGE4.js.map +0 -1
@@ -29,7 +29,13 @@ __export(schema_exports, {
29
29
  enrollments: () => enrollments,
30
30
  fileUploads: () => fileUploads,
31
31
  files: () => files,
32
+ githubInstallationRepositories: () => githubInstallationRepositories,
32
33
  githubInstallations: () => githubInstallations,
34
+ hostExportConfig: () => hostExportConfig,
35
+ hostExportConsumers: () => hostExportConsumers,
36
+ hostExportCursorState: () => hostExportCursorState,
37
+ hostExportDeadLetters: () => hostExportDeadLetters,
38
+ hostExportOutbox: () => hostExportOutbox,
33
39
  importBatches: () => importBatches,
34
40
  integrationOauthClients: () => integrationOauthClients,
35
41
  integrationOauthStateNonces: () => integrationOauthStateNonces,
@@ -55,6 +61,7 @@ __export(schema_exports, {
55
61
  sessionEvents: () => sessionEvents,
56
62
  sessionGoals: () => sessionGoals,
57
63
  sessionHistoryItems: () => sessionHistoryItems,
64
+ sessionHumanInputRequests: () => sessionHumanInputRequests,
58
65
  sessionListSnapshots: () => sessionListSnapshots,
59
66
  sessionMcpServers: () => sessionMcpServers,
60
67
  sessionPendingToolCalls: () => sessionPendingToolCalls,
@@ -79,6 +86,7 @@ __export(schema_exports, {
79
86
  workspaceMemberships: () => workspaceMemberships,
80
87
  workspaceModelPolicies: () => workspaceModelPolicies,
81
88
  workspacePacks: () => workspacePacks,
89
+ workspaceSessionActivityRevisions: () => workspaceSessionActivityRevisions,
82
90
  workspaceVariableSetVariables: () => workspaceVariableSetVariables,
83
91
  workspaceVariableSets: () => workspaceVariableSets,
84
92
  workspaces: () => workspaces
@@ -162,7 +170,9 @@ var workspaceInferenceControls = pgTable(
162
170
  accountId: uuid("account_id").notNull(),
163
171
  revision: bigint("revision", { mode: "number" }).notNull().default(0),
164
172
  workspaceState: text("workspace_state").notNull().default("active"),
165
- workspacePauseRevision: bigint("workspace_pause_revision", { mode: "number" }),
173
+ workspacePauseRevision: bigint("workspace_pause_revision", {
174
+ mode: "number"
175
+ }),
166
176
  reason: text("reason"),
167
177
  changedBy: text("changed_by"),
168
178
  changedAt: timestamp("changed_at", { withTimezone: true }),
@@ -194,6 +204,25 @@ var workspaceInferenceControls = pgTable(
194
204
  )
195
205
  })
196
206
  );
207
+ var workspaceSessionActivityRevisions = pgTable(
208
+ "workspace_session_activity_revisions",
209
+ {
210
+ workspaceId: uuid("workspace_id").primaryKey(),
211
+ accountId: uuid("account_id").notNull(),
212
+ revision: bigint("revision", { mode: "number" }).notNull().default(0)
213
+ },
214
+ (table) => ({
215
+ workspaceAccount: foreignKey({
216
+ name: "workspace_session_activity_revisions_workspace_account_fk",
217
+ columns: [table.workspaceId, table.accountId],
218
+ foreignColumns: [workspaces.id, workspaces.accountId]
219
+ }).onDelete("cascade"),
220
+ revisionValid: check(
221
+ "workspace_session_activity_revisions_revision_check",
222
+ sql`${table.revision} >= 0`
223
+ )
224
+ })
225
+ );
197
226
  var workspaceMemberships = pgTable(
198
227
  "workspace_memberships",
199
228
  {
@@ -221,7 +250,9 @@ var apiKeys = pgTable(
221
250
  {
222
251
  id: uuid("id").primaryKey().defaultRandom(),
223
252
  accountId: uuid("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
224
- workspaceId: uuid("workspace_id").references(() => workspaces.id, { onDelete: "cascade" }),
253
+ workspaceId: uuid("workspace_id").references(() => workspaces.id, {
254
+ onDelete: "cascade"
255
+ }),
225
256
  name: text("name").notNull(),
226
257
  prefix: text("prefix").notNull(),
227
258
  keyHash: text("key_hash").notNull(),
@@ -332,13 +363,15 @@ var codexSubscriptionCredentials = pgTable(
332
363
  // excluded). The writer only ever sets a NON-empty set, so a flaky empty turn
333
364
  // can't false-drop coverage. connectorsCheckedAt is the freshness clock.
334
365
  connectorNamespaces: text("connector_namespaces").array(),
335
- connectorsCheckedAt: timestamp("connectors_checked_at", { withTimezone: true }),
366
+ connectorsCheckedAt: timestamp("connectors_checked_at", {
367
+ withTimezone: true
368
+ }),
336
369
  // Workspace-local, server-held fairness cursor. Provider usage headers are
337
370
  // capacity hints, never the sole allocator: live lease count is ranked first
338
371
  // and this cursor deterministically breaks equal-load/equal-capacity ties.
339
372
  // This flag controls NEW automatic allocations only. Credential health,
340
373
  // refresh, encrypted material, and already-frozen/in-flight turns are
341
- // intentionally independent. OPE-24 owns toggle OCC/audit and product UI.
374
+ // intentionally independent. account eligibility policy owns toggle OCC/audit and product UI.
342
375
  allocatorEnabled: boolean("allocator_enabled").notNull().default(true),
343
376
  selectionCount: integer("selection_count").notNull().default(0),
344
377
  lastSelectedAt: timestamp("last_selected_at", { withTimezone: true }),
@@ -450,8 +483,8 @@ var codexRotationSettings = pgTable(
450
483
  // code reads this bit; old binaries safely ignore it and keep the legacy
451
484
  // pin/rotation policy.
452
485
  leaseRotationEnabled: boolean("lease_rotation_enabled").notNull().default(false),
453
- rotationStrategy: text("rotation_strategy").notNull().default("most_remaining"),
454
- // P3, inert
486
+ rotationStrategy: text("rotation_strategy").notNull().default("sharded"),
487
+ // sharded-rotation policy: legacy residue; behavior is always sharded
455
488
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
456
489
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
457
490
  },
@@ -512,6 +545,10 @@ var sessions = pgTable(
512
545
  workspaceId: uuid("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
513
546
  status: text("status").notNull().default("queued"),
514
547
  initialMessage: text("initial_message").notNull(),
548
+ // Invisible host context frozen with the winning session create. The
549
+ // initial turn copies this value so an idempotent repair can never adopt a
550
+ // retrying caller's different instructions.
551
+ initialTurnInstructions: text("initial_turn_instructions"),
515
552
  title: text("title"),
516
553
  titleSource: text("title_source"),
517
554
  // Per-session agent persona/system instructions supplied at create (the
@@ -524,6 +561,11 @@ var sessions = pgTable(
524
561
  resources: jsonb("resources").$type().notNull().default([]),
525
562
  tools: jsonb("tools").$type().notNull().default([]),
526
563
  metadata: jsonb("metadata").$type().notNull().default({}),
564
+ // Frozen creator fact. This is used for creation attribution and for the
565
+ // idempotent first-turn repair only; later turns capture their own actor.
566
+ createdByKind: text("created_by_kind").notNull().default("service"),
567
+ createdBySubjectId: text("created_by_subject_id").notNull().default("unattributed-legacy"),
568
+ createdByContext: jsonb("created_by_context").$type().notNull().default({ backfill: true }),
527
569
  model: text("model").notNull(),
528
570
  sandboxBackend: text("sandbox_backend").notNull(),
529
571
  // The OS this session's box runs. Defaults to 'linux' (today's only OS, so
@@ -539,8 +581,8 @@ var sessions = pgTable(
539
581
  // The app generates the uuid and uses it for both id and sandbox_group_id in
540
582
  // one insert — it cannot SQL-default to id (id is defaultRandom()).
541
583
  sandboxGroupId: uuid("sandbox_group_id").notNull(),
542
- // The first-class swappable-sandbox POINTER (bring-your-own-compute M2,
543
- // dossier §10.3). NULL == "use the session's own group sandbox" (the
584
+ // The first-class swappable-sandbox POINTER (bring-your-own-compute M2).
585
+ // NULL == "use the session's own group sandbox" (the
544
586
  // backward-compat default — every existing/new row is a behavior-preserving
545
587
  // no-op). The routing proxy re-reads (active_sandbox_id, active_epoch) PER
546
588
  // TOOL CALL to make a Modal<->selfhosted hot-swap seamless. The FK
@@ -605,11 +647,15 @@ var sessions = pgTable(
605
647
  queueTailPosition: bigint("queue_tail_position", { mode: "number" }).notNull().default(0),
606
648
  directControlState: text("direct_control_state").notNull().default("active"),
607
649
  directPauseRevision: bigint("direct_pause_revision", { mode: "number" }),
608
- subtreeRunOverrideRevision: bigint("subtree_run_override_revision", { mode: "number" }),
650
+ subtreeRunOverrideRevision: bigint("subtree_run_override_revision", {
651
+ mode: "number"
652
+ }),
609
653
  controlVersion: bigint("control_version", { mode: "number" }).notNull().default(0),
610
654
  directControlReason: text("direct_control_reason"),
611
655
  directControlChangedBy: text("direct_control_changed_by"),
612
- directControlChangedAt: timestamp("direct_control_changed_at", { withTimezone: true }),
656
+ directControlChangedAt: timestamp("direct_control_changed_at", {
657
+ withTimezone: true
658
+ }),
613
659
  lastSequence: integer("last_sequence").notNull().default(0),
614
660
  // The session's PINNED Codex account (manual override from the in-session
615
661
  // switcher). NULL ⇒ follow the workspace active pointer. FK declared in the
@@ -629,7 +675,11 @@ var sessions = pgTable(
629
675
  // account).
630
676
  codexPinSource: text("codex_pin_source"),
631
677
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
632
- updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
678
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
679
+ // Assigned by the database trigger whenever canonical updated_at activity
680
+ // advances. Legacy rows remain zero until touched; raw delta-only writers
681
+ // intentionally omit updated_at and therefore do not allocate revisions.
682
+ activityRevision: bigint("activity_revision", { mode: "number" }).notNull().default(0)
633
683
  },
634
684
  (table) => ({
635
685
  workspaceIdentity: uniqueIndex("sessions_workspace_id_idx").on(table.workspaceId, table.id),
@@ -637,6 +687,25 @@ var sessions = pgTable(
637
687
  table.workspaceId,
638
688
  table.createdAt
639
689
  ),
690
+ // Model-facing monitoring pages use exact (timestamp,id) keysets. Keep the
691
+ // older prefix index during rolling deploys; these composites serve both
692
+ // deterministic traversal and updatedAfter change scans.
693
+ workspaceCreatedId: index("sessions_workspace_created_id_idx").on(
694
+ table.workspaceId,
695
+ table.createdAt.desc(),
696
+ table.id.desc()
697
+ ),
698
+ workspaceUpdatedId: index("sessions_workspace_updated_id_idx").on(
699
+ table.workspaceId,
700
+ table.updatedAt.desc(),
701
+ table.id.desc()
702
+ ),
703
+ workspaceActivityRevision: index("sessions_workspace_activity_revision_idx").on(
704
+ table.workspaceId,
705
+ table.activityRevision.desc(),
706
+ table.updatedAt.desc(),
707
+ table.id.desc()
708
+ ),
640
709
  variableSet: index("sessions_variable_set_idx").on(table.workspaceId, table.variableSetId),
641
710
  parent: index("sessions_parent_idx").on(table.workspaceId, table.parentSessionId),
642
711
  // Routing index: resolve session_id -> sandbox_group_id at every lease entry
@@ -754,6 +823,9 @@ var sessionMcpServers = pgTable(
754
823
  // Human-approval policy: `true` = every tool requires approval, a string[] of
755
824
  // UNPREFIXED tool names = only those require it, null/absent = auto-run.
756
825
  requireApproval: jsonb("require_approval").$type(),
826
+ // Non-secret pointer resolved at request time by the standalone broker or
827
+ // an embedding host. Unlike headersEncrypted, this is safe to project.
828
+ connectionRef: jsonb("connection_ref").$type(),
757
829
  // Map of header name -> AES-GCM ciphertext. Values are decrypted only by the
758
830
  // worker's run-preparation path and never returned by API helpers.
759
831
  headersEncrypted: jsonb("headers_encrypted").$type().notNull().default({}),
@@ -974,6 +1046,9 @@ var sessionTurns = pgTable(
974
1046
  source: text("source").notNull().default("user"),
975
1047
  position: bigint("position", { mode: "number" }).notNull(),
976
1048
  prompt: text("prompt").notNull(),
1049
+ // Host context for this exact turn. System-level at runtime and deliberately
1050
+ // separate from the visible prompt/event payload.
1051
+ turnInstructions: text("turn_instructions"),
977
1052
  resources: jsonb("resources").$type().notNull().default([]),
978
1053
  tools: jsonb("tools").$type().notNull().default([]),
979
1054
  model: text("model").notNull(),
@@ -991,6 +1066,11 @@ var sessionTurns = pgTable(
991
1066
  // the SQL constraint is therefore DEFERRABLE INITIALLY DEFERRED.
992
1067
  activeAttemptId: uuid("active_attempt_id"),
993
1068
  lineage: jsonb("lineage").$type().notNull().default({}),
1069
+ // Required immutable authority captured when the turn is accepted. These
1070
+ // columns are deliberately outside mutable metadata/lineage.
1071
+ initiatorKind: text("initiator_kind").notNull().default("service"),
1072
+ initiatorSubjectId: text("initiator_subject_id").notNull().default("unattributed-legacy"),
1073
+ initiatorContext: jsonb("initiator_context").$type().notNull().default({ backfill: true }),
994
1074
  cancelledBy: text("cancelled_by"),
995
1075
  cancelReason: text("cancel_reason"),
996
1076
  // Atomic per-turn toolspace call budget counter (migration 0043). Incremented
@@ -1033,10 +1113,18 @@ var sessionTurnAttempts = pgTable(
1033
1113
  workerId: text("worker_id"),
1034
1114
  leaseId: text("lease_id"),
1035
1115
  leaseExpiresAt: timestamp("lease_expires_at", { withTimezone: true }),
1036
- verifiedControlRevision: bigint("verified_control_revision", { mode: "number" }).notNull(),
1116
+ verifiedControlRevision: bigint("verified_control_revision", {
1117
+ mode: "number"
1118
+ }).notNull(),
1037
1119
  startedAt: timestamp("started_at", { withTimezone: true }).notNull().defaultNow(),
1038
1120
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
1039
- closedAt: timestamp("closed_at", { withTimezone: true })
1121
+ closedAt: timestamp("closed_at", { withTimezone: true }),
1122
+ // The cancelled activity writes this after losing inference, user-visible
1123
+ // output, and workspace-persistence authority. Fenced/idempotent cleanup
1124
+ // and telemetry may still finish. Temporal activity cancellation or
1125
+ // terminalization is transport state only; queue admission and clients use
1126
+ // this durable receipt as the physical-quiescence authority.
1127
+ quiescedAt: timestamp("quiesced_at", { withTimezone: true })
1040
1128
  },
1041
1129
  (table) => ({
1042
1130
  workspaceAccount: foreignKey({
@@ -1058,8 +1146,21 @@ var sessionTurnAttempts = pgTable(
1058
1146
  table.workspaceId,
1059
1147
  table.id
1060
1148
  ),
1149
+ ownershipIdentity: uniqueIndex("session_turn_attempts_human_input_owner_uq").on(
1150
+ table.accountId,
1151
+ table.workspaceId,
1152
+ table.sessionId,
1153
+ table.turnId,
1154
+ table.id
1155
+ ),
1061
1156
  liveTurn: uniqueIndex("session_turn_attempts_live_turn_uq").on(table.workspaceId, table.turnId).where(sql`${table.state} in ('claimed', 'running')`),
1062
1157
  liveSession: uniqueIndex("session_turn_attempts_live_session_uq").on(table.workspaceId, table.sessionId).where(sql`${table.state} in ('claimed', 'running')`),
1158
+ latestSessionAttempt: index("session_turn_attempts_latest_session_idx").on(
1159
+ table.workspaceId,
1160
+ table.sessionId,
1161
+ table.startedAt.desc(),
1162
+ table.id.desc()
1163
+ ),
1063
1164
  dispatch: uniqueIndex("session_turn_attempts_dispatch_uq").on(
1064
1165
  table.workspaceId,
1065
1166
  table.temporalWorkflowRunId,
@@ -1098,7 +1199,9 @@ var sessionCommandReceipts = pgTable(
1098
1199
  targetTurnId: uuid("target_turn_id"),
1099
1200
  operationKey: text("operation_key").notNull(),
1100
1201
  canonicalRequestHash: text("canonical_request_hash").notNull(),
1101
- appliedControlRevision: bigint("applied_control_revision", { mode: "number" }),
1202
+ appliedControlRevision: bigint("applied_control_revision", {
1203
+ mode: "number"
1204
+ }),
1102
1205
  appliedQueueVersion: integer("applied_queue_version"),
1103
1206
  appliedTurnVersion: integer("applied_turn_version"),
1104
1207
  appliedDraftRevision: bigint("applied_draft_revision", { mode: "number" }),
@@ -1143,7 +1246,7 @@ var sessionCommandReceipts = pgTable(
1143
1246
  and ${table.actorAttemptId} is not null
1144
1247
  and ${table.actorSubjectId} is null
1145
1248
  ) or (
1146
- ${table.actorType} in ('human', 'operator')
1249
+ ${table.actorType} in ('human', 'operator', 'service')
1147
1250
  and ${table.actorSubjectId} is not null
1148
1251
  and ${table.actorAttemptId} is null
1149
1252
  )`
@@ -1162,7 +1265,11 @@ var workspaceControlEvents = pgTable(
1162
1265
  action: text("action").notNull(),
1163
1266
  automatic: boolean("automatic").notNull().default(false),
1164
1267
  reason: text("reason"),
1268
+ reasonOriginalBytes: integer("reason_original_bytes"),
1165
1269
  actor: text("actor").notNull(),
1270
+ // Null is the rolling-upgrade shape for untouched, already-bounded legacy
1271
+ // rows. New writes and rewritten poison rows carry exact source byte facts.
1272
+ actorOriginalBytes: integer("actor_original_bytes"),
1166
1273
  occurredAt: timestamp("occurred_at", { withTimezone: true }).notNull().defaultNow()
1167
1274
  },
1168
1275
  (table) => ({
@@ -1553,6 +1660,39 @@ var sessionEvents = pgTable(
1553
1660
  table.workspaceId,
1554
1661
  table.sessionId,
1555
1662
  table.createdAt
1663
+ ),
1664
+ sessionTypeSequence: index("session_events_workspace_session_type_sequence_idx").on(
1665
+ table.workspaceId,
1666
+ table.sessionId,
1667
+ table.type,
1668
+ table.sequence
1669
+ ),
1670
+ monitoringTail: index("session_events_workspace_session_monitoring_tail_idx").on(table.workspaceId, table.sessionId, table.sequence).where(
1671
+ sql`${table.type} not in ('agent.message.delta', 'agent.reasoning.delta', 'sandbox.command.output.delta', 'terminal.pty.output.delta')`
1672
+ ),
1673
+ payloadBytes: check(
1674
+ "session_events_payload_bytes_check",
1675
+ sql`octet_length(${table.payload}::text) <= 65536`
1676
+ ),
1677
+ typeBytes: check(
1678
+ "session_events_type_bytes_check",
1679
+ sql`octet_length(${table.type}) <= 256 and position(E'\n' in ${table.type}) = 0 and position(E'\r' in ${table.type}) = 0`
1680
+ ),
1681
+ clientEventIdBytes: check(
1682
+ "session_events_client_event_id_bytes_check",
1683
+ sql`${table.clientEventId} is null or octet_length(${table.clientEventId}) <= 1024`
1684
+ ),
1685
+ producerIdBytes: check(
1686
+ "session_events_producer_id_bytes_check",
1687
+ sql`${table.producerId} is null or octet_length(${table.producerId}) <= 1024`
1688
+ ),
1689
+ turnAssociationBytes: check(
1690
+ "session_events_turn_association_bytes_check",
1691
+ sql`${table.turnAssociation} is null or octet_length(${table.turnAssociation}) <= 64`
1692
+ ),
1693
+ duplicateReasonBytes: check(
1694
+ "session_events_duplicate_reason_bytes_check",
1695
+ sql`${table.duplicateReason} is null or octet_length(${table.duplicateReason}) <= 4096`
1556
1696
  )
1557
1697
  })
1558
1698
  );
@@ -1561,7 +1701,9 @@ var agentRunStates = pgTable("agent_run_states", {
1561
1701
  accountId: uuid("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
1562
1702
  workspaceId: uuid("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
1563
1703
  sessionId: uuid("session_id").notNull().references(() => sessions.id, { onDelete: "cascade" }),
1564
- turnId: uuid("turn_id").references(() => sessionTurns.id, { onDelete: "set null" }),
1704
+ turnId: uuid("turn_id").references(() => sessionTurns.id, {
1705
+ onDelete: "set null"
1706
+ }),
1565
1707
  stateVersion: integer("state_version").notNull(),
1566
1708
  serializedRunState: text("serialized_run_state").notNull(),
1567
1709
  pendingApprovals: jsonb("pending_approvals").$type().notNull().default([]),
@@ -1583,6 +1725,79 @@ var agentRunStates = pgTable("agent_run_states", {
1583
1725
  frozenCodexCredentialId: uuid("frozen_codex_credential_id"),
1584
1726
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
1585
1727
  });
1728
+ var sessionHumanInputRequests = pgTable(
1729
+ "session_human_input_requests",
1730
+ {
1731
+ id: uuid("id").primaryKey().defaultRandom(),
1732
+ accountId: uuid("account_id").notNull(),
1733
+ workspaceId: uuid("workspace_id").notNull(),
1734
+ sessionId: uuid("session_id").notNull(),
1735
+ turnId: uuid("turn_id").notNull(),
1736
+ turnGeneration: integer("turn_generation").notNull(),
1737
+ creationAttemptId: uuid("creation_attempt_id").notNull(),
1738
+ toolCallId: text("tool_call_id").notNull(),
1739
+ status: text("status").notNull().default("pending"),
1740
+ questions: jsonb("questions").$type().notNull(),
1741
+ allowSkip: boolean("allow_skip").notNull().default(false),
1742
+ response: jsonb("response").$type(),
1743
+ respondedBy: text("responded_by"),
1744
+ respondedAt: timestamp("responded_at", { withTimezone: true }),
1745
+ expiresAt: timestamp("expires_at", { withTimezone: true }),
1746
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
1747
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
1748
+ },
1749
+ (table) => ({
1750
+ creationAttemptOwner: foreignKey({
1751
+ name: "session_human_input_requests_creation_attempt_fk",
1752
+ columns: [
1753
+ table.accountId,
1754
+ table.workspaceId,
1755
+ table.sessionId,
1756
+ table.turnId,
1757
+ table.creationAttemptId
1758
+ ],
1759
+ foreignColumns: [
1760
+ sessionTurnAttempts.accountId,
1761
+ sessionTurnAttempts.workspaceId,
1762
+ sessionTurnAttempts.sessionId,
1763
+ sessionTurnAttempts.turnId,
1764
+ sessionTurnAttempts.id
1765
+ ]
1766
+ }).onDelete("cascade"),
1767
+ toolCall: uniqueIndex("session_human_input_requests_tool_call_uq").on(
1768
+ table.workspaceId,
1769
+ table.sessionId,
1770
+ table.turnId,
1771
+ table.toolCallId
1772
+ ),
1773
+ pendingSession: index("session_human_input_requests_pending_session_idx").on(table.workspaceId, table.sessionId, table.createdAt, table.id).where(sql`${table.status} = 'pending'`),
1774
+ pendingExpiry: index("session_human_input_requests_pending_expiry_idx").on(table.expiresAt, table.id).where(sql`${table.status} = 'pending' and ${table.expiresAt} is not null`),
1775
+ status: check(
1776
+ "session_human_input_requests_status_check",
1777
+ sql`${table.status} in ('pending','answered','skipped','expired','cancelled')`
1778
+ ),
1779
+ generation: check(
1780
+ "session_human_input_requests_generation_check",
1781
+ sql`${table.turnGeneration} > 0`
1782
+ ),
1783
+ toolCallBytes: check(
1784
+ "session_human_input_requests_tool_call_bytes_check",
1785
+ sql`octet_length(${table.toolCallId}) between 1 and 1024`
1786
+ ),
1787
+ questionsBytes: check(
1788
+ "session_human_input_requests_questions_bytes_check",
1789
+ sql`octet_length(${table.questions}::text) <= 49152`
1790
+ ),
1791
+ responseBytes: check(
1792
+ "session_human_input_requests_response_bytes_check",
1793
+ sql`${table.response} is null or octet_length(${table.response}::text) <= 49152`
1794
+ ),
1795
+ actorBytes: check(
1796
+ "session_human_input_requests_actor_bytes_check",
1797
+ sql`${table.respondedBy} is null or octet_length(${table.respondedBy}) <= 1024`
1798
+ )
1799
+ })
1800
+ );
1586
1801
  var sessionHistoryItems = pgTable(
1587
1802
  "session_history_items",
1588
1803
  {
@@ -1590,7 +1805,9 @@ var sessionHistoryItems = pgTable(
1590
1805
  accountId: uuid("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
1591
1806
  workspaceId: uuid("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
1592
1807
  sessionId: uuid("session_id").notNull().references(() => sessions.id, { onDelete: "cascade" }),
1593
- turnId: uuid("turn_id").references(() => sessionTurns.id, { onDelete: "set null" }),
1808
+ turnId: uuid("turn_id").references(() => sessionTurns.id, {
1809
+ onDelete: "set null"
1810
+ }),
1594
1811
  // Numeric (not integer) so the synthetic compaction-summary row can be
1595
1812
  // inserted at a FRACTIONAL position (boundaryPosition - 0.5) that sorts ahead
1596
1813
  // of the kept tail without colliding with — and thus overwriting — the real
@@ -1778,7 +1995,9 @@ var sessionRecordings = pgTable(
1778
1995
  accountId: uuid("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
1779
1996
  workspaceId: uuid("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
1780
1997
  sessionId: uuid("session_id").notNull().references(() => sessions.id, { onDelete: "cascade" }),
1781
- turnId: uuid("turn_id").references(() => sessionTurns.id, { onDelete: "set null" }),
1998
+ turnId: uuid("turn_id").references(() => sessionTurns.id, {
1999
+ onDelete: "set null"
2000
+ }),
1782
2001
  state: text("state", { enum: sessionRecordingStateValues }).notNull(),
1783
2002
  mode: text("mode", { enum: sessionRecordingModeValues }).notNull(),
1784
2003
  codec: text("codec", { enum: sessionRecordingCodecValues }).notNull(),
@@ -1806,7 +2025,9 @@ var workspaceCaptures = pgTable(
1806
2025
  accountId: uuid("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
1807
2026
  workspaceId: uuid("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
1808
2027
  sessionId: uuid("session_id").notNull().references(() => sessions.id, { onDelete: "cascade" }),
1809
- turnId: uuid("turn_id").references(() => sessionTurns.id, { onDelete: "set null" }),
2028
+ turnId: uuid("turn_id").references(() => sessionTurns.id, {
2029
+ onDelete: "set null"
2030
+ }),
1810
2031
  revision: bigint("revision", { mode: "number" }).notNull(),
1811
2032
  leaseEpoch: integer("lease_epoch").notNull(),
1812
2033
  // 'available' on a committed capture. 'failed' reserved for a future two-phase
@@ -1941,7 +2162,9 @@ var deviceEnrollmentRequests = pgTable(
1941
2162
  machineName: text("machine_name"),
1942
2163
  // The exposure the agent REQUESTED (whole-machine in v1; loudly consented at
1943
2164
  // approve). Mirrors the enrollment column domain.
1944
- requestedExposure: text("requested_exposure", { enum: enrollmentExposureValues }).notNull().default("whole-machine"),
2165
+ requestedExposure: text("requested_exposure", {
2166
+ enum: enrollmentExposureValues
2167
+ }).notNull().default("whole-machine"),
1945
2168
  // The agent CAN offer a display (a real screen / Xvfb is available) — gates
1946
2169
  // whether screen-control consent is even meaningful. has_display on the
1947
2170
  // resulting enrollment is derived from this.
@@ -1959,8 +2182,12 @@ var deviceEnrollmentRequests = pgTable(
1959
2182
  approvedAt: timestamp("approved_at", { withTimezone: true }),
1960
2183
  // The enrollment + sandbox the approve produced (acceptance #2: an enrollment
1961
2184
  // row AND a sandbox row appear). Null until approved.
1962
- enrollmentId: uuid("enrollment_id").references(() => enrollments.id, { onDelete: "set null" }),
1963
- sandboxId: uuid("sandbox_id").references(() => sandboxes.id, { onDelete: "set null" }),
2185
+ enrollmentId: uuid("enrollment_id").references(() => enrollments.id, {
2186
+ onDelete: "set null"
2187
+ }),
2188
+ sandboxId: uuid("sandbox_id").references(() => sandboxes.id, {
2189
+ onDelete: "set null"
2190
+ }),
1964
2191
  // The short-TTL expiry; a pending row past this is EXPIRED on poll.
1965
2192
  expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
1966
2193
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
@@ -1987,7 +2214,9 @@ var sandboxes = pgTable(
1987
2214
  workspaceId: uuid("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
1988
2215
  kind: text("kind", { enum: sandboxKindValues }).notNull(),
1989
2216
  name: text("name").notNull(),
1990
- enrollmentId: uuid("enrollment_id").references(() => enrollments.id, { onDelete: "set null" }),
2217
+ enrollmentId: uuid("enrollment_id").references(() => enrollments.id, {
2218
+ onDelete: "set null"
2219
+ }),
1991
2220
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
1992
2221
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
1993
2222
  },
@@ -2104,7 +2333,9 @@ var scheduledTaskRuns = pgTable(
2104
2333
  triggerType: text("trigger_type").notNull(),
2105
2334
  scheduledAt: timestamp("scheduled_at", { withTimezone: true }),
2106
2335
  firedAt: timestamp("fired_at", { withTimezone: true }).notNull().defaultNow(),
2107
- sessionId: uuid("session_id").references(() => sessions.id, { onDelete: "set null" }),
2336
+ sessionId: uuid("session_id").references(() => sessions.id, {
2337
+ onDelete: "set null"
2338
+ }),
2108
2339
  triggerEventId: uuid("trigger_event_id"),
2109
2340
  // Stable Temporal producer identity. Activity replay/re-dispatch returns
2110
2341
  // the exact run instead of allocating a second schedule source row.
@@ -2135,6 +2366,8 @@ var githubInstallations = pgTable(
2135
2366
  installationId: integer("installation_id").notNull(),
2136
2367
  accountLogin: text("account_login"),
2137
2368
  accountType: text("account_type"),
2369
+ repositoryScope: text("repository_scope").notNull().default("all"),
2370
+ linkedBySubjectId: text("linked_by_subject_id"),
2138
2371
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
2139
2372
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
2140
2373
  },
@@ -2144,7 +2377,43 @@ var githubInstallations = pgTable(
2144
2377
  table.installationId
2145
2378
  ),
2146
2379
  installation: index("github_installations_installation_idx").on(table.installationId),
2147
- workspace: index("github_installations_workspace_idx").on(table.workspaceId)
2380
+ workspace: index("github_installations_workspace_idx").on(table.workspaceId),
2381
+ repositoryScopeCheck: check(
2382
+ "github_installations_repository_scope_check",
2383
+ sql`${table.repositoryScope} in ('all', 'selected')`
2384
+ )
2385
+ })
2386
+ );
2387
+ var githubInstallationRepositories = pgTable(
2388
+ "github_installation_repositories",
2389
+ {
2390
+ id: uuid("id").primaryKey().defaultRandom(),
2391
+ accountId: uuid("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
2392
+ workspaceId: uuid("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
2393
+ installationId: integer("installation_id").notNull(),
2394
+ repositoryId: bigint("repository_id", { mode: "number" }).notNull(),
2395
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
2396
+ },
2397
+ (table) => ({
2398
+ installationRepository: uniqueIndex("github_install_repo_workspace_installation_repo_idx").on(
2399
+ table.workspaceId,
2400
+ table.installationId,
2401
+ table.repositoryId
2402
+ ),
2403
+ workspaceInstallation: index("github_install_repo_workspace_installation_idx").on(
2404
+ table.workspaceId,
2405
+ table.installationId
2406
+ ),
2407
+ workspaceAccount: foreignKey({
2408
+ columns: [table.workspaceId, table.accountId],
2409
+ foreignColumns: [workspaces.id, workspaces.accountId],
2410
+ name: "github_installation_repositories_workspace_account_fk"
2411
+ }).onDelete("cascade"),
2412
+ installationBinding: foreignKey({
2413
+ columns: [table.workspaceId, table.installationId],
2414
+ foreignColumns: [githubInstallations.workspaceId, githubInstallations.installationId],
2415
+ name: "github_installation_repositories_installation_fk"
2416
+ }).onDelete("cascade")
2148
2417
  })
2149
2418
  );
2150
2419
  var usageEvents = pgTable(
@@ -2159,10 +2428,23 @@ var usageEvents = pgTable(
2159
2428
  unit: text("unit").notNull(),
2160
2429
  sourceResourceType: text("source_resource_type"),
2161
2430
  sourceResourceId: text("source_resource_id"),
2431
+ // Exact execution source for host usage export. These are deliberately
2432
+ // validated soft references rather than cascading foreign keys: usage is
2433
+ // an immutable billing/audit fact and must retain its source identity after
2434
+ // a session or turn is deleted.
2435
+ sessionId: uuid("session_id"),
2436
+ turnId: uuid("turn_id"),
2437
+ turnAttemptId: uuid("turn_attempt_id"),
2438
+ initiatorKind: text("initiator_kind"),
2439
+ initiatorSubjectId: text("initiator_subject_id"),
2440
+ initiatorContext: jsonb("initiator_context").$type().notNull().default({}),
2441
+ origin: text("origin"),
2162
2442
  idempotencyKey: text("idempotency_key").notNull(),
2163
2443
  occurredAt: timestamp("occurred_at", { withTimezone: true }).notNull(),
2164
2444
  recordedAt: timestamp("recorded_at", { withTimezone: true }).notNull().defaultNow(),
2165
- exportedToBillingAt: timestamp("exported_to_billing_at", { withTimezone: true }),
2445
+ exportedToBillingAt: timestamp("exported_to_billing_at", {
2446
+ withTimezone: true
2447
+ }),
2166
2448
  billingProviderEventId: text("billing_provider_event_id")
2167
2449
  },
2168
2450
  (table) => ({
@@ -2176,6 +2458,186 @@ var usageEvents = pgTable(
2176
2458
  table.accountId,
2177
2459
  table.eventType,
2178
2460
  table.occurredAt
2461
+ ),
2462
+ workspaceSession: index("usage_events_workspace_session_idx").on(
2463
+ table.workspaceId,
2464
+ table.sessionId,
2465
+ table.occurredAt
2466
+ ),
2467
+ contextHierarchy: check(
2468
+ "usage_events_context_hierarchy_check",
2469
+ sql`(${table.turnId} is null or ${table.sessionId} is not null)
2470
+ and (${table.turnAttemptId} is null or ${table.turnId} is not null)`
2471
+ ),
2472
+ initiatorConsistent: check(
2473
+ "usage_events_initiator_check",
2474
+ sql`(${table.initiatorKind} is null and ${table.initiatorSubjectId} is null)
2475
+ or (${table.initiatorKind} in ('subject', 'service')
2476
+ and ${table.initiatorSubjectId} is not null
2477
+ and octet_length(${table.initiatorSubjectId}) between 1 and 1024)`
2478
+ ),
2479
+ attributionContextBytes: check(
2480
+ "usage_events_initiator_context_bytes_check",
2481
+ sql`octet_length(${table.initiatorContext}::text) <= 4096`
2482
+ ),
2483
+ originValid: check(
2484
+ "usage_events_origin_check",
2485
+ sql`${table.origin} is null or ${table.origin} in (
2486
+ 'user', 'scheduled_task', 'api', 'goal', 'system', 'compaction'
2487
+ )`
2488
+ )
2489
+ })
2490
+ );
2491
+ var hostExportConfig = pgTable(
2492
+ "host_export_config",
2493
+ {
2494
+ id: integer("id").primaryKey().default(1),
2495
+ sessionEventsEnabled: boolean("session_events_enabled").notNull().default(false),
2496
+ usageEventsEnabled: boolean("usage_events_enabled").notNull().default(false),
2497
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
2498
+ },
2499
+ (table) => ({
2500
+ singleton: check("host_export_config_singleton_check", sql`${table.id} = 1`)
2501
+ })
2502
+ );
2503
+ var hostExportOutbox = pgTable(
2504
+ "host_export_outbox",
2505
+ {
2506
+ id: uuid("id").primaryKey().defaultRandom(),
2507
+ exportKind: text("export_kind").notNull(),
2508
+ exportCursor: bigint("export_cursor", { mode: "bigint" }),
2509
+ sourceId: uuid("source_id").notNull(),
2510
+ accountId: uuid("account_id").notNull(),
2511
+ workspaceId: uuid("workspace_id").notNull(),
2512
+ sessionId: uuid("session_id"),
2513
+ rootSessionId: uuid("root_session_id"),
2514
+ turnId: uuid("turn_id"),
2515
+ turnGeneration: integer("turn_generation"),
2516
+ turnAttemptId: uuid("turn_attempt_id"),
2517
+ sessionSequence: integer("session_sequence"),
2518
+ clientEventId: text("client_event_id"),
2519
+ turnAssociation: text("turn_association"),
2520
+ duplicateOfEventId: uuid("duplicate_of_event_id"),
2521
+ duplicateReason: text("duplicate_reason"),
2522
+ eventType: text("event_type").notNull(),
2523
+ idempotencyKey: text("idempotency_key").notNull(),
2524
+ initiator: jsonb("initiator").$type(),
2525
+ initiatorContext: jsonb("initiator_context").$type().notNull().default({}),
2526
+ origin: text("origin"),
2527
+ payload: jsonb("payload").$type().notNull(),
2528
+ envelopeBytes: integer("envelope_bytes").notNull(),
2529
+ occurredAt: timestamp("occurred_at", { withTimezone: true }).notNull(),
2530
+ sourceRecordedAt: timestamp("source_recorded_at", { withTimezone: true }).notNull(),
2531
+ enqueuedAt: timestamp("enqueued_at", { withTimezone: true }).notNull()
2532
+ },
2533
+ (table) => ({
2534
+ kindValid: check(
2535
+ "host_export_outbox_kind_check",
2536
+ sql`${table.exportKind} in ('session_event', 'usage_event')`
2537
+ ),
2538
+ sourceUnique: uniqueIndex("host_export_outbox_source_uq").on(table.exportKind, table.sourceId),
2539
+ cursorUnique: uniqueIndex("host_export_outbox_cursor_uq").on(table.exportKind, table.exportCursor).where(sql`${table.exportCursor} is not null`),
2540
+ unassigned: index("host_export_outbox_unassigned_idx").on(table.exportKind, table.enqueuedAt, table.id).where(sql`${table.exportCursor} is null`),
2541
+ unassignedSession: index("host_export_outbox_unassigned_session_idx").on(table.exportKind, table.sessionId, table.sessionSequence).where(sql`${table.exportCursor} is null and ${table.sessionId} is not null`),
2542
+ contextBytes: check(
2543
+ "host_export_outbox_context_bytes_check",
2544
+ sql`octet_length(${table.initiatorContext}::text) <= 4096`
2545
+ ),
2546
+ originValid: check(
2547
+ "host_export_outbox_origin_check",
2548
+ sql`${table.origin} is null or ${table.origin} in (
2549
+ 'user', 'scheduled_task', 'api', 'goal', 'system', 'compaction'
2550
+ )`
2551
+ )
2552
+ })
2553
+ );
2554
+ var hostExportCursorState = pgTable(
2555
+ "host_export_cursor_state",
2556
+ {
2557
+ exportKind: text("export_kind").primaryKey(),
2558
+ nextCursor: bigint("next_cursor", { mode: "bigint" }).notNull().default(1n),
2559
+ prunedThrough: bigint("pruned_through", { mode: "bigint" }).notNull().default(0n),
2560
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
2561
+ },
2562
+ (table) => ({
2563
+ kindValid: check(
2564
+ "host_export_cursor_state_kind_check",
2565
+ sql`${table.exportKind} in ('session_event', 'usage_event')`
2566
+ ),
2567
+ cursorValid: check(
2568
+ "host_export_cursor_state_next_check",
2569
+ sql`${table.nextCursor} > 0 and ${table.prunedThrough} >= 0
2570
+ and ${table.prunedThrough} < ${table.nextCursor}`
2571
+ )
2572
+ })
2573
+ );
2574
+ var hostExportConsumers = pgTable(
2575
+ "host_export_consumers",
2576
+ {
2577
+ id: uuid("id").primaryKey().defaultRandom(),
2578
+ consumerId: text("consumer_id").notNull(),
2579
+ exportKind: text("export_kind").notNull(),
2580
+ checkpoint: bigint("checkpoint", { mode: "bigint" }).notNull().default(0n),
2581
+ enabled: boolean("enabled").notNull().default(true),
2582
+ leaseToken: uuid("lease_token"),
2583
+ leaseHolderId: text("lease_holder_id"),
2584
+ leaseExpiresAt: timestamp("lease_expires_at", { withTimezone: true }),
2585
+ leaseFrom: bigint("lease_from", { mode: "bigint" }),
2586
+ leaseThrough: bigint("lease_through", { mode: "bigint" }),
2587
+ consecutiveFailures: integer("consecutive_failures").notNull().default(0),
2588
+ nextAttemptAt: timestamp("next_attempt_at", { withTimezone: true }).notNull().defaultNow(),
2589
+ lastError: text("last_error"),
2590
+ lastErrorAt: timestamp("last_error_at", { withTimezone: true }),
2591
+ blockedAt: timestamp("blocked_at", { withTimezone: true }),
2592
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
2593
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
2594
+ },
2595
+ (table) => ({
2596
+ consumerKind: uniqueIndex("host_export_consumers_kind_id_uq").on(
2597
+ table.exportKind,
2598
+ table.consumerId
2599
+ ),
2600
+ kindValid: check(
2601
+ "host_export_consumers_kind_check",
2602
+ sql`${table.exportKind} in ('session_event', 'usage_event')`
2603
+ ),
2604
+ checkpointValid: check("host_export_consumers_checkpoint_check", sql`${table.checkpoint} >= 0`),
2605
+ due: index("host_export_consumers_due_idx").on(
2606
+ table.enabled,
2607
+ table.blockedAt,
2608
+ table.nextAttemptAt
2609
+ )
2610
+ })
2611
+ );
2612
+ var hostExportDeadLetters = pgTable(
2613
+ "host_export_dead_letters",
2614
+ {
2615
+ id: uuid("id").primaryKey().defaultRandom(),
2616
+ consumerId: text("consumer_id").notNull(),
2617
+ exportKind: text("export_kind").notNull(),
2618
+ exportCursor: bigint("export_cursor", { mode: "bigint" }).notNull(),
2619
+ sourceId: uuid("source_id").notNull(),
2620
+ reason: text("reason").notNull(),
2621
+ envelope: jsonb("envelope").$type().notNull(),
2622
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
2623
+ },
2624
+ (table) => ({
2625
+ consumerCursor: uniqueIndex("host_export_dead_letters_consumer_cursor_uq").on(
2626
+ table.exportKind,
2627
+ table.consumerId,
2628
+ table.exportCursor
2629
+ ),
2630
+ kindValid: check(
2631
+ "host_export_dead_letters_kind_check",
2632
+ sql`${table.exportKind} in ('session_event', 'usage_event')`
2633
+ ),
2634
+ reasonValid: check(
2635
+ "host_export_dead_letters_reason_check",
2636
+ sql`length(${table.reason}) between 1 and 500`
2637
+ ),
2638
+ envelopeBytes: check(
2639
+ "host_export_dead_letters_envelope_bytes_check",
2640
+ sql`pg_column_size(${table.envelope}) <= 114688`
2179
2641
  )
2180
2642
  })
2181
2643
  );
@@ -2184,7 +2646,9 @@ var creditLedgerEntries = pgTable(
2184
2646
  {
2185
2647
  id: uuid("id").primaryKey().defaultRandom(),
2186
2648
  accountId: uuid("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
2187
- workspaceId: uuid("workspace_id").references(() => workspaces.id, { onDelete: "set null" }),
2649
+ workspaceId: uuid("workspace_id").references(() => workspaces.id, {
2650
+ onDelete: "set null"
2651
+ }),
2188
2652
  type: text("type").notNull(),
2189
2653
  amountMicros: bigint("amount_micros", { mode: "number" }).notNull(),
2190
2654
  currency: text("currency").notNull().default("usd"),
@@ -2237,8 +2701,12 @@ var auditEvents = pgTable(
2237
2701
  "audit_events",
2238
2702
  {
2239
2703
  id: uuid("id").primaryKey().defaultRandom(),
2240
- accountId: uuid("account_id").references(() => managedAccounts.id, { onDelete: "set null" }),
2241
- workspaceId: uuid("workspace_id").references(() => workspaces.id, { onDelete: "set null" }),
2704
+ accountId: uuid("account_id").references(() => managedAccounts.id, {
2705
+ onDelete: "set null"
2706
+ }),
2707
+ workspaceId: uuid("workspace_id").references(() => workspaces.id, {
2708
+ onDelete: "set null"
2709
+ }),
2242
2710
  subjectId: text("subject_id"),
2243
2711
  action: text("action").notNull(),
2244
2712
  targetType: text("target_type"),
@@ -2321,8 +2789,12 @@ var capabilityCatalogItems = pgTable(
2321
2789
  "capability_catalog_items",
2322
2790
  {
2323
2791
  id: text("id").notNull(),
2324
- accountId: uuid("account_id").references(() => managedAccounts.id, { onDelete: "cascade" }),
2325
- workspaceId: uuid("workspace_id").references(() => workspaces.id, { onDelete: "cascade" }),
2792
+ accountId: uuid("account_id").references(() => managedAccounts.id, {
2793
+ onDelete: "cascade"
2794
+ }),
2795
+ workspaceId: uuid("workspace_id").references(() => workspaces.id, {
2796
+ onDelete: "cascade"
2797
+ }),
2326
2798
  kind: text("kind").notNull(),
2327
2799
  source: text("source").notNull().default("manual"),
2328
2800
  name: text("name").notNull(),
@@ -2555,6 +3027,7 @@ export {
2555
3027
  managedAccounts,
2556
3028
  workspaces,
2557
3029
  workspaceInferenceControls,
3030
+ workspaceSessionActivityRevisions,
2558
3031
  workspaceMemberships,
2559
3032
  apiKeys,
2560
3033
  workspaceVariableSets,
@@ -2589,6 +3062,7 @@ export {
2589
3062
  codexCapacityWaiters,
2590
3063
  sessionEvents,
2591
3064
  agentRunStates,
3065
+ sessionHumanInputRequests,
2592
3066
  sessionHistoryItems,
2593
3067
  sessionPendingToolCalls,
2594
3068
  sandboxSessionEnvelopes,
@@ -2614,7 +3088,13 @@ export {
2614
3088
  scheduledTasks,
2615
3089
  scheduledTaskRuns,
2616
3090
  githubInstallations,
3091
+ githubInstallationRepositories,
2617
3092
  usageEvents,
3093
+ hostExportConfig,
3094
+ hostExportOutbox,
3095
+ hostExportCursorState,
3096
+ hostExportConsumers,
3097
+ hostExportDeadLetters,
2618
3098
  creditLedgerEntries,
2619
3099
  billingCustomers,
2620
3100
  stripeWebhookEvents,
@@ -2631,4 +3111,4 @@ export {
2631
3111
  rigChanges,
2632
3112
  schema_exports
2633
3113
  };
2634
- //# sourceMappingURL=chunk-B22X3IEZ.js.map
3114
+ //# sourceMappingURL=chunk-4LG5NBTC.js.map