@opengeni/db 0.7.0 → 0.7.1

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.
@@ -15,6 +15,7 @@ __export(schema_exports, {
15
15
  codexCredentialLeases: () => codexCredentialLeases,
16
16
  codexRotationSettings: () => codexRotationSettings,
17
17
  codexSubscriptionCredentials: () => codexSubscriptionCredentials,
18
+ composerDrafts: () => composerDrafts,
18
19
  connections: () => connections,
19
20
  creditLedgerEntries: () => creditLedgerEntries,
20
21
  deviceEnrollmentRequests: () => deviceEnrollmentRequests,
@@ -40,7 +41,6 @@ __export(schema_exports, {
40
41
  rigChanges: () => rigChanges,
41
42
  rigVersions: () => rigVersions,
42
43
  rigs: () => rigs,
43
- runtimeControlOperations: () => runtimeControlOperations,
44
44
  sandboxKindValues: () => sandboxKindValues,
45
45
  sandboxLeaseHolders: () => sandboxLeaseHolders,
46
46
  sandboxLeaseLivenessValues: () => sandboxLeaseLivenessValues,
@@ -50,6 +50,8 @@ __export(schema_exports, {
50
50
  sandboxes: () => sandboxes,
51
51
  scheduledTaskRuns: () => scheduledTaskRuns,
52
52
  scheduledTasks: () => scheduledTasks,
53
+ sessionAttemptInterruptions: () => sessionAttemptInterruptions,
54
+ sessionCommandReceipts: () => sessionCommandReceipts,
53
55
  sessionEvents: () => sessionEvents,
54
56
  sessionGoals: () => sessionGoals,
55
57
  sessionHistoryItems: () => sessionHistoryItems,
@@ -63,6 +65,7 @@ __export(schema_exports, {
63
65
  sessionRecordings: () => sessionRecordings,
64
66
  sessionSystemUpdateOutbox: () => sessionSystemUpdateOutbox,
65
67
  sessionSystemUpdates: () => sessionSystemUpdates,
68
+ sessionTurnAttempts: () => sessionTurnAttempts,
66
69
  sessionTurns: () => sessionTurns,
67
70
  sessionWorkflowWakeOutbox: () => sessionWorkflowWakeOutbox,
68
71
  sessions: () => sessions,
@@ -71,6 +74,8 @@ __export(schema_exports, {
71
74
  stripeWebhookEvents: () => stripeWebhookEvents,
72
75
  usageEvents: () => usageEvents,
73
76
  workspaceCaptures: () => workspaceCaptures,
77
+ workspaceControlEvents: () => workspaceControlEvents,
78
+ workspaceInferenceControls: () => workspaceInferenceControls,
74
79
  workspaceMemberships: () => workspaceMemberships,
75
80
  workspaceModelPolicies: () => workspaceModelPolicies,
76
81
  workspacePacks: () => workspacePacks,
@@ -135,11 +140,6 @@ var workspaces = pgTable(
135
140
  // Growth-ready per-workspace settings bag (migration 0045). Holds memoryEnabled
136
141
  // and future workspace-level toggles; validated/merged via WorkspaceSettingsSchema.
137
142
  settings: jsonb("settings").$type().notNull().default({}),
138
- inferenceState: text("inference_state").notNull().default("active"),
139
- inferenceGeneration: integer("inference_generation").notNull().default(0),
140
- inferenceReason: text("inference_reason"),
141
- inferenceChangedBy: text("inference_changed_by"),
142
- inferenceChangedAt: timestamp("inference_changed_at", { withTimezone: true }),
143
143
  // The workspace's default rig (migration 0047). NULL ⇒ no default; sessions
144
144
  // created without an explicit rig ride no rig (today's behavior exactly). FK
145
145
  // (-> rigs(id) ON DELETE SET NULL) lives in migration 0047, not a Drizzle
@@ -155,6 +155,45 @@ var workspaces = pgTable(
155
155
  external: uniqueIndex("workspaces_external_idx").on(table.externalSource, table.externalId)
156
156
  })
157
157
  );
158
+ var workspaceInferenceControls = pgTable(
159
+ "workspace_inference_controls",
160
+ {
161
+ workspaceId: uuid("workspace_id").primaryKey(),
162
+ accountId: uuid("account_id").notNull(),
163
+ revision: bigint("revision", { mode: "number" }).notNull().default(0),
164
+ workspaceState: text("workspace_state").notNull().default("active"),
165
+ workspacePauseRevision: bigint("workspace_pause_revision", { mode: "number" }),
166
+ reason: text("reason"),
167
+ changedBy: text("changed_by"),
168
+ changedAt: timestamp("changed_at", { withTimezone: true }),
169
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
170
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
171
+ },
172
+ (table) => ({
173
+ workspaceAccount: foreignKey({
174
+ name: "workspace_inference_controls_workspace_account_fk",
175
+ columns: [table.workspaceId, table.accountId],
176
+ foreignColumns: [workspaces.id, workspaces.accountId]
177
+ }).onDelete("cascade"),
178
+ workspaceAccountIdentity: uniqueIndex("workspace_inference_controls_workspace_account_uq").on(
179
+ table.workspaceId,
180
+ table.accountId
181
+ ),
182
+ stateValid: check(
183
+ "workspace_inference_controls_state_check",
184
+ sql`${table.workspaceState} in ('active', 'paused')`
185
+ ),
186
+ pauseRevisionConsistent: check(
187
+ "workspace_inference_controls_pause_revision_check",
188
+ sql`(${table.workspaceState} = 'active' and ${table.workspacePauseRevision} is null)
189
+ or (${table.workspaceState} = 'paused' and ${table.workspacePauseRevision} is not null)`
190
+ ),
191
+ revisionValid: check(
192
+ "workspace_inference_controls_revision_check",
193
+ sql`${table.revision} >= 0 and (${table.workspacePauseRevision} is null or ${table.workspacePauseRevision} <= ${table.revision})`
194
+ )
195
+ })
196
+ );
158
197
  var workspaceMemberships = pgTable(
159
198
  "workspace_memberships",
160
199
  {
@@ -564,17 +603,13 @@ var sessions = pgTable(
564
603
  queueVersion: integer("queue_version").notNull().default(0),
565
604
  queueHeadPosition: bigint("queue_head_position", { mode: "number" }).notNull().default(0),
566
605
  queueTailPosition: bigint("queue_tail_position", { mode: "number" }).notNull().default(0),
567
- controlState: text("control_state").notNull().default("active"),
568
- controlGeneration: integer("control_generation").notNull().default(0),
569
- controlReason: text("control_reason"),
570
- controlChangedBy: text("control_changed_by"),
571
- controlChangedAt: timestamp("control_changed_at", { withTimezone: true }),
572
- pendingControlEventId: uuid("pending_control_event_id"),
573
- pendingControlKind: text("pending_control_kind"),
574
- pendingControlExpectedTurnId: uuid("pending_control_expected_turn_id"),
575
- pendingControlExpectedGeneration: integer("pending_control_expected_generation"),
576
- pendingControlExpectedAttemptId: uuid("pending_control_expected_attempt_id"),
577
- workspaceRunExceptionGeneration: integer("workspace_run_exception_generation"),
606
+ directControlState: text("direct_control_state").notNull().default("active"),
607
+ directPauseRevision: bigint("direct_pause_revision", { mode: "number" }),
608
+ subtreeRunOverrideRevision: bigint("subtree_run_override_revision", { mode: "number" }),
609
+ controlVersion: bigint("control_version", { mode: "number" }).notNull().default(0),
610
+ directControlReason: text("direct_control_reason"),
611
+ directControlChangedBy: text("direct_control_changed_by"),
612
+ directControlChangedAt: timestamp("direct_control_changed_at", { withTimezone: true }),
578
613
  lastSequence: integer("last_sequence").notNull().default(0),
579
614
  // The session's PINNED Codex account (manual override from the in-session
580
615
  // switcher). NULL ⇒ follow the workspace active pointer. FK declared in the
@@ -950,6 +985,10 @@ var sessionTurns = pgTable(
950
985
  metadata: jsonb("metadata").$type().notNull().default({}),
951
986
  version: integer("version").notNull().default(1),
952
987
  executionGeneration: integer("execution_generation").notNull().default(0),
988
+ // Composite FK to session_turn_attempts is installed by migration 0063.
989
+ // It lives in SQL because attempts carry the reciprocal turn FK and because
990
+ // the claim transaction preallocates this ID before inserting the attempt;
991
+ // the SQL constraint is therefore DEFERRABLE INITIALLY DEFERRED.
953
992
  activeAttemptId: uuid("active_attempt_id"),
954
993
  lineage: jsonb("lineage").$type().notNull().default({}),
955
994
  cancelledBy: text("cancelled_by"),
@@ -977,6 +1016,282 @@ var sessionTurns = pgTable(
977
1016
  oneCurrentInference: uniqueIndex("session_turns_one_current_inference_uq").on(table.workspaceId, table.sessionId).where(sql`${table.status} in ('running','requires_action','recovering','waiting_capacity')`)
978
1017
  })
979
1018
  );
1019
+ var sessionTurnAttempts = pgTable(
1020
+ "session_turn_attempts",
1021
+ {
1022
+ id: uuid("id").primaryKey(),
1023
+ accountId: uuid("account_id").notNull(),
1024
+ workspaceId: uuid("workspace_id").notNull(),
1025
+ sessionId: uuid("session_id").notNull(),
1026
+ turnId: uuid("turn_id").notNull(),
1027
+ executionGeneration: integer("execution_generation").notNull(),
1028
+ state: text("state").notNull().default("claimed"),
1029
+ outcome: text("outcome"),
1030
+ temporalWorkflowId: text("temporal_workflow_id").notNull(),
1031
+ temporalWorkflowRunId: text("temporal_workflow_run_id").notNull(),
1032
+ temporalActivityId: text("temporal_activity_id").notNull(),
1033
+ workerId: text("worker_id"),
1034
+ leaseId: text("lease_id"),
1035
+ leaseExpiresAt: timestamp("lease_expires_at", { withTimezone: true }),
1036
+ verifiedControlRevision: bigint("verified_control_revision", { mode: "number" }).notNull(),
1037
+ startedAt: timestamp("started_at", { withTimezone: true }).notNull().defaultNow(),
1038
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
1039
+ closedAt: timestamp("closed_at", { withTimezone: true })
1040
+ },
1041
+ (table) => ({
1042
+ workspaceAccount: foreignKey({
1043
+ name: "session_turn_attempts_workspace_account_fk",
1044
+ columns: [table.workspaceId, table.accountId],
1045
+ foreignColumns: [workspaces.id, workspaces.accountId]
1046
+ }).onDelete("cascade"),
1047
+ workspaceSession: foreignKey({
1048
+ name: "session_turn_attempts_workspace_session_fk",
1049
+ columns: [table.workspaceId, table.sessionId],
1050
+ foreignColumns: [sessions.workspaceId, sessions.id]
1051
+ }).onDelete("restrict"),
1052
+ workspaceTurn: foreignKey({
1053
+ name: "session_turn_attempts_workspace_turn_fk",
1054
+ columns: [table.workspaceId, table.turnId],
1055
+ foreignColumns: [sessionTurns.workspaceId, sessionTurns.id]
1056
+ }).onDelete("restrict"),
1057
+ workspaceIdentity: uniqueIndex("session_turn_attempts_workspace_id_uq").on(
1058
+ table.workspaceId,
1059
+ table.id
1060
+ ),
1061
+ liveTurn: uniqueIndex("session_turn_attempts_live_turn_uq").on(table.workspaceId, table.turnId).where(sql`${table.state} in ('claimed', 'running')`),
1062
+ liveSession: uniqueIndex("session_turn_attempts_live_session_uq").on(table.workspaceId, table.sessionId).where(sql`${table.state} in ('claimed', 'running')`),
1063
+ dispatch: uniqueIndex("session_turn_attempts_dispatch_uq").on(
1064
+ table.workspaceId,
1065
+ table.temporalWorkflowRunId,
1066
+ table.temporalActivityId
1067
+ ),
1068
+ leaseExpiry: index("session_turn_attempts_lease_expiry_idx").on(table.leaseExpiresAt, table.workspaceId, table.sessionId).where(sql`${table.state} in ('claimed', 'running')`),
1069
+ stateValid: check(
1070
+ "session_turn_attempts_state_check",
1071
+ sql`${table.state} in ('claimed', 'running', 'closed')`
1072
+ ),
1073
+ outcomeValid: check(
1074
+ "session_turn_attempts_outcome_check",
1075
+ sql`${table.outcome} is null or ${table.outcome} in (
1076
+ 'completed', 'failed', 'cancelled', 'superseded', 'requires_action',
1077
+ 'interrupted_recoverable', 'lease_lost_recoverable', 'pre_cutover_closed'
1078
+ )`
1079
+ ),
1080
+ closedConsistent: check(
1081
+ "session_turn_attempts_closed_check",
1082
+ sql`(${table.state} = 'closed' and ${table.outcome} is not null and ${table.closedAt} is not null)
1083
+ or (${table.state} <> 'closed' and ${table.outcome} is null and ${table.closedAt} is null)`
1084
+ )
1085
+ })
1086
+ );
1087
+ var sessionCommandReceipts = pgTable(
1088
+ "session_command_receipts",
1089
+ {
1090
+ id: uuid("id").primaryKey().defaultRandom(),
1091
+ accountId: uuid("account_id").notNull(),
1092
+ workspaceId: uuid("workspace_id").notNull(),
1093
+ actorType: text("actor_type").notNull(),
1094
+ actorSubjectId: text("actor_subject_id"),
1095
+ actorAttemptId: uuid("actor_attempt_id"),
1096
+ action: text("action").notNull(),
1097
+ targetSessionId: uuid("target_session_id"),
1098
+ targetTurnId: uuid("target_turn_id"),
1099
+ operationKey: text("operation_key").notNull(),
1100
+ canonicalRequestHash: text("canonical_request_hash").notNull(),
1101
+ appliedControlRevision: bigint("applied_control_revision", { mode: "number" }),
1102
+ appliedQueueVersion: integer("applied_queue_version"),
1103
+ appliedTurnVersion: integer("applied_turn_version"),
1104
+ appliedDraftRevision: bigint("applied_draft_revision", { mode: "number" }),
1105
+ result: jsonb("result").$type().notNull().default({}),
1106
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
1107
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
1108
+ },
1109
+ (table) => ({
1110
+ workspaceAccount: foreignKey({
1111
+ name: "session_command_receipts_workspace_account_fk",
1112
+ columns: [table.workspaceId, table.accountId],
1113
+ foreignColumns: [workspaces.id, workspaces.accountId]
1114
+ }).onDelete("cascade"),
1115
+ actorAttempt: foreignKey({
1116
+ name: "session_command_receipts_actor_attempt_fk",
1117
+ columns: [table.workspaceId, table.actorAttemptId],
1118
+ foreignColumns: [sessionTurnAttempts.workspaceId, sessionTurnAttempts.id]
1119
+ }).onDelete("restrict"),
1120
+ targetSession: foreignKey({
1121
+ name: "session_command_receipts_target_session_fk",
1122
+ columns: [table.workspaceId, table.targetSessionId],
1123
+ foreignColumns: [sessions.workspaceId, sessions.id]
1124
+ }).onDelete("restrict"),
1125
+ targetTurn: foreignKey({
1126
+ name: "session_command_receipts_target_turn_fk",
1127
+ columns: [table.workspaceId, table.targetTurnId],
1128
+ foreignColumns: [sessionTurns.workspaceId, sessionTurns.id]
1129
+ }).onDelete("restrict"),
1130
+ workspaceIdentity: uniqueIndex("session_command_receipts_workspace_id_uq").on(
1131
+ table.workspaceId,
1132
+ table.id
1133
+ ),
1134
+ targetCreated: index("session_command_receipts_target_created_idx").on(
1135
+ table.workspaceId,
1136
+ table.targetSessionId,
1137
+ table.createdAt
1138
+ ),
1139
+ actorValid: check(
1140
+ "session_command_receipts_actor_check",
1141
+ sql`(
1142
+ ${table.actorType} = 'agent_attempt'
1143
+ and ${table.actorAttemptId} is not null
1144
+ and ${table.actorSubjectId} is null
1145
+ ) or (
1146
+ ${table.actorType} in ('human', 'operator')
1147
+ and ${table.actorSubjectId} is not null
1148
+ and ${table.actorAttemptId} is null
1149
+ )`
1150
+ )
1151
+ })
1152
+ );
1153
+ var workspaceControlEvents = pgTable(
1154
+ "workspace_control_events",
1155
+ {
1156
+ id: uuid("id").primaryKey().defaultRandom(),
1157
+ accountId: uuid("account_id").notNull(),
1158
+ workspaceId: uuid("workspace_id").notNull(),
1159
+ revision: bigint("revision", { mode: "number" }).notNull(),
1160
+ scope: text("scope").notNull(),
1161
+ rootSessionId: uuid("root_session_id"),
1162
+ action: text("action").notNull(),
1163
+ automatic: boolean("automatic").notNull().default(false),
1164
+ reason: text("reason"),
1165
+ actor: text("actor").notNull(),
1166
+ occurredAt: timestamp("occurred_at", { withTimezone: true }).notNull().defaultNow()
1167
+ },
1168
+ (table) => ({
1169
+ workspaceAccount: foreignKey({
1170
+ name: "workspace_control_events_workspace_account_fk",
1171
+ columns: [table.workspaceId, table.accountId],
1172
+ foreignColumns: [workspaces.id, workspaces.accountId]
1173
+ }).onDelete("cascade"),
1174
+ rootSession: foreignKey({
1175
+ name: "workspace_control_events_root_session_fk",
1176
+ columns: [table.workspaceId, table.rootSessionId],
1177
+ foreignColumns: [sessions.workspaceId, sessions.id]
1178
+ }).onDelete("restrict"),
1179
+ workspaceRevision: uniqueIndex("workspace_control_events_workspace_revision_uq").on(
1180
+ table.workspaceId,
1181
+ table.revision
1182
+ ),
1183
+ revisionValid: check("workspace_control_events_revision_check", sql`${table.revision} > 0`),
1184
+ shapeValid: check(
1185
+ "workspace_control_events_shape_check",
1186
+ sql`(${table.scope} = 'workspace' and ${table.rootSessionId} is null)
1187
+ or (${table.scope} = 'session' and ${table.rootSessionId} is not null)`
1188
+ ),
1189
+ actionValid: check(
1190
+ "workspace_control_events_action_check",
1191
+ sql`${table.action} in ('pause', 'resume')`
1192
+ )
1193
+ })
1194
+ );
1195
+ var sessionAttemptInterruptions = pgTable(
1196
+ "session_attempt_interruptions",
1197
+ {
1198
+ id: uuid("id").primaryKey().defaultRandom(),
1199
+ accountId: uuid("account_id").notNull(),
1200
+ workspaceId: uuid("workspace_id").notNull(),
1201
+ sessionId: uuid("session_id").notNull(),
1202
+ operationId: uuid("operation_id").notNull(),
1203
+ attemptId: uuid("attempt_id").notNull(),
1204
+ kind: text("kind").notNull(),
1205
+ controlRevision: bigint("control_revision", { mode: "number" }).notNull(),
1206
+ state: text("state").notNull().default("pending"),
1207
+ requestedAt: timestamp("requested_at", { withTimezone: true }).notNull().defaultNow(),
1208
+ deliveredAt: timestamp("delivered_at", { withTimezone: true }),
1209
+ acknowledgedAt: timestamp("acknowledged_at", { withTimezone: true }),
1210
+ settledAt: timestamp("settled_at", { withTimezone: true })
1211
+ },
1212
+ (table) => ({
1213
+ workspaceAccount: foreignKey({
1214
+ name: "session_attempt_interruptions_workspace_account_fk",
1215
+ columns: [table.workspaceId, table.accountId],
1216
+ foreignColumns: [workspaces.id, workspaces.accountId]
1217
+ }).onDelete("cascade"),
1218
+ workspaceSession: foreignKey({
1219
+ name: "session_attempt_interruptions_workspace_session_fk",
1220
+ columns: [table.workspaceId, table.sessionId],
1221
+ foreignColumns: [sessions.workspaceId, sessions.id]
1222
+ }).onDelete("restrict"),
1223
+ operation: foreignKey({
1224
+ name: "session_attempt_interruptions_operation_fk",
1225
+ columns: [table.workspaceId, table.operationId],
1226
+ foreignColumns: [sessionCommandReceipts.workspaceId, sessionCommandReceipts.id]
1227
+ }).onDelete("restrict"),
1228
+ attempt: foreignKey({
1229
+ name: "session_attempt_interruptions_attempt_fk",
1230
+ columns: [table.workspaceId, table.attemptId],
1231
+ foreignColumns: [sessionTurnAttempts.workspaceId, sessionTurnAttempts.id]
1232
+ }).onDelete("restrict"),
1233
+ operationAttempt: uniqueIndex("session_attempt_interruptions_operation_attempt_uq").on(
1234
+ table.operationId,
1235
+ table.attemptId
1236
+ ),
1237
+ unsettled: index("session_attempt_interruptions_unsettled_idx").on(table.workspaceId, table.sessionId, table.requestedAt).where(sql`${table.state} in ('pending', 'delivered', 'acknowledged')`),
1238
+ kindValid: check(
1239
+ "session_attempt_interruptions_kind_check",
1240
+ sql`${table.kind} in ('session_pause', 'workspace_pause', 'steer', 'maintenance')`
1241
+ ),
1242
+ stateValid: check(
1243
+ "session_attempt_interruptions_state_check",
1244
+ sql`${table.state} in ('pending', 'delivered', 'acknowledged', 'settled', 'rejected_stale')`
1245
+ )
1246
+ })
1247
+ );
1248
+ var composerDrafts = pgTable(
1249
+ "composer_drafts",
1250
+ {
1251
+ id: uuid("id").primaryKey().defaultRandom(),
1252
+ accountId: uuid("account_id").notNull(),
1253
+ workspaceId: uuid("workspace_id").notNull(),
1254
+ sessionId: uuid("session_id").notNull(),
1255
+ subjectId: text("subject_id").notNull(),
1256
+ revision: bigint("revision", { mode: "number" }).notNull().default(1),
1257
+ text: text("text").notNull().default(""),
1258
+ resources: jsonb("resources").$type().notNull().default([]),
1259
+ tools: jsonb("tools").$type().notNull().default([]),
1260
+ model: text("model").notNull(),
1261
+ reasoningEffort: text("reasoning_effort").notNull(),
1262
+ sourceTurnId: uuid("source_turn_id"),
1263
+ sourceTurnVersion: integer("source_turn_version"),
1264
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
1265
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
1266
+ },
1267
+ (table) => ({
1268
+ workspaceAccount: foreignKey({
1269
+ name: "composer_drafts_workspace_account_fk",
1270
+ columns: [table.workspaceId, table.accountId],
1271
+ foreignColumns: [workspaces.id, workspaces.accountId]
1272
+ }).onDelete("cascade"),
1273
+ workspaceSession: foreignKey({
1274
+ name: "composer_drafts_workspace_session_fk",
1275
+ columns: [table.workspaceId, table.sessionId],
1276
+ foreignColumns: [sessions.workspaceId, sessions.id]
1277
+ }).onDelete("cascade"),
1278
+ sourceTurn: foreignKey({
1279
+ name: "composer_drafts_source_turn_fk",
1280
+ columns: [table.workspaceId, table.sourceTurnId],
1281
+ foreignColumns: [sessionTurns.workspaceId, sessionTurns.id]
1282
+ }).onDelete("restrict"),
1283
+ subjectSession: uniqueIndex("composer_drafts_subject_session_uq").on(
1284
+ table.workspaceId,
1285
+ table.sessionId,
1286
+ table.subjectId
1287
+ ),
1288
+ subjectValid: check(
1289
+ "composer_drafts_subject_check",
1290
+ sql`length(btrim(${table.subjectId})) > 0`
1291
+ ),
1292
+ revisionValid: check("composer_drafts_revision_check", sql`${table.revision} >= 1`)
1293
+ })
1294
+ );
980
1295
  var sessionSystemUpdates = pgTable(
981
1296
  "session_system_updates",
982
1297
  {
@@ -1003,6 +1318,18 @@ var sessionSystemUpdates = pgTable(
1003
1318
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
1004
1319
  },
1005
1320
  (table) => ({
1321
+ kindValid: check(
1322
+ "system_updates_kind_check",
1323
+ sql`${table.kind} in ('scheduled_occurrence', 'goal_continuation', 'agent_message', 'agent_steer_instruction', 'child_terminal_result')`
1324
+ ),
1325
+ payloadKindValid: check(
1326
+ "system_updates_payload_kind_check",
1327
+ sql`${table.payload} ->> 'type' = ${table.kind}`
1328
+ ),
1329
+ stateValid: check(
1330
+ "system_updates_state_check",
1331
+ sql`${table.state} in ('pending', 'deferred', 'delivered', 'cancelled', 'superseded', 'failed')`
1332
+ ),
1006
1333
  dedupe: uniqueIndex("session_system_updates_dedupe_uq").on(
1007
1334
  table.workspaceId,
1008
1335
  table.sessionId,
@@ -1016,35 +1343,6 @@ var sessionSystemUpdates = pgTable(
1016
1343
  )
1017
1344
  })
1018
1345
  );
1019
- var runtimeControlOperations = pgTable(
1020
- "runtime_control_operations",
1021
- {
1022
- id: uuid("id").primaryKey().defaultRandom(),
1023
- accountId: uuid("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
1024
- workspaceId: uuid("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
1025
- scope: text("scope").notNull(),
1026
- targetId: uuid("target_id").notNull(),
1027
- clientEventId: text("client_event_id").notNull(),
1028
- requestedState: text("requested_state").notNull(),
1029
- expectedState: text("expected_state"),
1030
- expectedGeneration: integer("expected_generation"),
1031
- result: jsonb("result").$type().notNull().default({}),
1032
- createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
1033
- updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
1034
- },
1035
- (table) => ({
1036
- idempotency: uniqueIndex("runtime_control_operations_client_uq").on(
1037
- table.workspaceId,
1038
- table.clientEventId
1039
- ),
1040
- target: index("runtime_control_operations_target_idx").on(
1041
- table.workspaceId,
1042
- table.scope,
1043
- table.targetId,
1044
- table.createdAt
1045
- )
1046
- })
1047
- );
1048
1346
  var sessionSystemUpdateOutbox = pgTable(
1049
1347
  "session_system_update_outbox",
1050
1348
  {
@@ -1069,6 +1367,14 @@ var sessionSystemUpdateOutbox = pgTable(
1069
1367
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
1070
1368
  },
1071
1369
  (table) => ({
1370
+ kindValid: check(
1371
+ "system_update_outbox_kind_check",
1372
+ sql`${table.kind} = 'child_terminal_result'`
1373
+ ),
1374
+ payloadKindValid: check(
1375
+ "system_update_outbox_payload_kind_check",
1376
+ sql`${table.payload} ->> 'type' = 'child_terminal_result'`
1377
+ ),
1072
1378
  dedupe: uniqueIndex("session_system_update_outbox_dedupe_uq").on(
1073
1379
  table.workspaceId,
1074
1380
  table.dedupeKey
@@ -1171,7 +1477,6 @@ var codexCapacityWaiters = pgTable(
1171
1477
  status: text("status").notNull().default("waiting"),
1172
1478
  // waiting | resumed | superseded
1173
1479
  goalVersion: integer("goal_version").notNull(),
1174
- controlGeneration: integer("control_generation").notNull().default(0),
1175
1480
  policyHash: text("policy_hash"),
1176
1481
  earliestResetAt: timestamp("earliest_reset_at", { withTimezone: true }),
1177
1482
  nextCheckAt: timestamp("next_check_at", { withTimezone: true }).notNull(),
@@ -1232,6 +1537,11 @@ var sessionEvents = pgTable(
1232
1537
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
1233
1538
  },
1234
1539
  (table) => ({
1540
+ workspaceAttempt: foreignKey({
1541
+ name: "session_events_workspace_attempt_fk",
1542
+ columns: [table.workspaceId, table.turnAttemptId],
1543
+ foreignColumns: [sessionTurnAttempts.workspaceId, sessionTurnAttempts.id]
1544
+ }).onDelete("restrict"),
1235
1545
  sessionSequence: uniqueIndex("session_events_workspace_session_sequence_idx").on(
1236
1546
  table.workspaceId,
1237
1547
  table.sessionId,
@@ -1334,6 +1644,11 @@ var sessionPendingToolCalls = pgTable(
1334
1644
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow()
1335
1645
  },
1336
1646
  (table) => ({
1647
+ workspaceAttempt: foreignKey({
1648
+ name: "pending_tool_calls_workspace_attempt_fk",
1649
+ columns: [table.workspaceId, table.attemptId],
1650
+ foreignColumns: [sessionTurnAttempts.workspaceId, sessionTurnAttempts.id]
1651
+ }).onDelete("restrict"),
1337
1652
  turnCall: uniqueIndex("session_pending_tool_calls_turn_call_idx").on(
1338
1653
  table.workspaceId,
1339
1654
  table.turnId,
@@ -2239,6 +2554,7 @@ var rigChanges = pgTable(
2239
2554
  export {
2240
2555
  managedAccounts,
2241
2556
  workspaces,
2557
+ workspaceInferenceControls,
2242
2558
  workspaceMemberships,
2243
2559
  apiKeys,
2244
2560
  workspaceVariableSets,
@@ -2261,8 +2577,12 @@ export {
2261
2577
  documentChunks,
2262
2578
  knowledgeMemories,
2263
2579
  sessionTurns,
2580
+ sessionTurnAttempts,
2581
+ sessionCommandReceipts,
2582
+ workspaceControlEvents,
2583
+ sessionAttemptInterruptions,
2584
+ composerDrafts,
2264
2585
  sessionSystemUpdates,
2265
- runtimeControlOperations,
2266
2586
  sessionSystemUpdateOutbox,
2267
2587
  sessionWorkflowWakeOutbox,
2268
2588
  sessionGoals,
@@ -2311,4 +2631,4 @@ export {
2311
2631
  rigChanges,
2312
2632
  schema_exports
2313
2633
  };
2314
- //# sourceMappingURL=chunk-O3D7DABC.js.map
2634
+ //# sourceMappingURL=chunk-B22X3IEZ.js.map