@opengeni/db 0.12.0 → 0.12.6

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.
@@ -729,6 +729,8 @@ var sessions = pgTable(
729
729
  // mapSession exposes those rows as `legacy` instead of guessing omitted vs
730
730
  // explicit [].
731
731
  toolPolicy: jsonb("tool_policy").$type(),
732
+ // Optimistic-concurrency fence for durable session tool-policy writes.
733
+ toolPolicyVersion: integer("tool_policy_version").notNull().default(1),
732
734
  // The manager session that spawned this one via session_create. Set only
733
735
  // when the creating grant carried a worker-signed sessionId claim (a session
734
736
  // spawning a worker); null for direct API creates and scheduled-task runs.
@@ -1066,7 +1068,8 @@ var documentBases = pgTable(
1066
1068
  workspaceCreated: index("document_bases_workspace_created_idx").on(
1067
1069
  table.workspaceId,
1068
1070
  table.createdAt
1069
- )
1071
+ ),
1072
+ defaultName: uniqueIndex("document_bases_workspace_default_name_uq").on(table.workspaceId).where(sql`lower(btrim(${table.name})) = 'default'`)
1070
1073
  })
1071
1074
  );
1072
1075
  var documents = pgTable(
@@ -1091,6 +1094,17 @@ var documents = pgTable(
1091
1094
  sourceUpdatedAt: timestamp("source_updated_at", { withTimezone: true }),
1092
1095
  sourceVersion: text("source_version"),
1093
1096
  aclTags: jsonb("acl_tags").$type().notNull().default([]),
1097
+ // Per-document access controls. visibility 'private' restricts human reads to
1098
+ // created_by (a grant subject id, not a uuid); agent_access=false hides the
1099
+ // document from agent retrieval surfaces (docs MCP) while humans keep REST.
1100
+ visibility: text("visibility").notNull().default("workspace"),
1101
+ createdBy: text("created_by"),
1102
+ agentAccess: boolean("agent_access").notNull().default(true),
1103
+ // Auto-curation output (knowledge drops).
1104
+ summary: text("summary"),
1105
+ topics: jsonb("topics").$type().notNull().default([]),
1106
+ curationStatus: text("curation_status").notNull().default("none"),
1107
+ curation: jsonb("curation").$type(),
1094
1108
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
1095
1109
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
1096
1110
  },
@@ -1112,6 +1126,27 @@ var documents = pgTable(
1112
1126
  sourceExternalId: index("documents_workspace_source_external_id_idx").on(
1113
1127
  table.workspaceId,
1114
1128
  table.sourceExternalId
1129
+ ),
1130
+ curationStatus: index("documents_workspace_curation_status_idx").on(
1131
+ table.workspaceId,
1132
+ table.curationStatus
1133
+ ),
1134
+ visibilityState: check(
1135
+ "documents_visibility_chk",
1136
+ sql`${table.visibility} in ('workspace', 'private')`
1137
+ ),
1138
+ curationState: check(
1139
+ "documents_curation_status_chk",
1140
+ sql`${table.curationStatus} in ('none', 'pending', 'suggested', 'auto_filed', 'failed')`
1141
+ ),
1142
+ privateCreator: check(
1143
+ "documents_private_creator_chk",
1144
+ sql`${table.visibility} <> 'private' or nullif(btrim(${table.createdBy}), '') is not null`
1145
+ ),
1146
+ topicsArray: check("documents_topics_array_chk", sql`jsonb_typeof(${table.topics}) = 'array'`),
1147
+ curationObject: check(
1148
+ "documents_curation_object_chk",
1149
+ sql`${table.curation} is null or jsonb_typeof(${table.curation}) = 'object'`
1115
1150
  )
1116
1151
  })
1117
1152
  );
@@ -1347,7 +1382,8 @@ var sessionTurnAttempts = pgTable(
1347
1382
  "session_turn_attempts_outcome_check",
1348
1383
  sql`${table.outcome} is null or ${table.outcome} in (
1349
1384
  'completed', 'failed', 'cancelled', 'superseded', 'requires_action',
1350
- 'interrupted_recoverable', 'lease_lost_recoverable', 'pre_cutover_closed'
1385
+ 'waiting_capacity', 'interrupted_recoverable', 'lease_lost_recoverable',
1386
+ 'pre_cutover_closed'
1351
1387
  )`
1352
1388
  ),
1353
1389
  closedConsistent: check(
@@ -1801,13 +1837,14 @@ var codexCapacityWaiters = pgTable(
1801
1837
  accountId: uuid("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
1802
1838
  workspaceId: uuid("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
1803
1839
  sessionId: uuid("session_id").notNull(),
1804
- goalId: uuid("goal_id").notNull(),
1840
+ goalId: uuid("goal_id"),
1805
1841
  blockedTurnId: uuid("blocked_turn_id").notNull(),
1842
+ blockedTurnGeneration: integer("blocked_turn_generation").notNull(),
1806
1843
  workflowId: text("workflow_id").notNull(),
1807
1844
  generation: integer("generation").notNull().default(1),
1808
1845
  status: text("status").notNull().default("waiting"),
1809
1846
  // waiting | resumed | superseded
1810
- goalVersion: integer("goal_version").notNull(),
1847
+ goalVersion: integer("goal_version"),
1811
1848
  policyHash: text("policy_hash"),
1812
1849
  earliestResetAt: timestamp("earliest_reset_at", { withTimezone: true }),
1813
1850
  nextCheckAt: timestamp("next_check_at", { withTimezone: true }).notNull(),
@@ -1894,6 +1931,7 @@ var sessionEvents = pgTable(
1894
1931
  monitoringTail: index("session_events_workspace_session_monitoring_tail_idx").on(table.workspaceId, table.sessionId, table.sequence).where(
1895
1932
  sql`${table.type} not in ('agent.message.delta', 'agent.reasoning.delta', 'sandbox.command.output.delta', 'terminal.pty.output.delta')`
1896
1933
  ),
1934
+ duplicateOfEvent: index("session_events_duplicate_of_event_idx").on(table.duplicateOfEventId),
1897
1935
  payloadBytes: check(
1898
1936
  "session_events_payload_bytes_check",
1899
1937
  sql`octet_length(${table.payload}::text) <= 65536`
@@ -2197,6 +2235,7 @@ var sandboxLeases = pgTable(
2197
2235
  table.id
2198
2236
  ),
2199
2237
  reaperIdx: index("sandbox_leases_reaper_idx").on(table.expiresAt).where(sql`${table.liveness} in ('warming','warm','draining')`),
2238
+ expiredDrainingInventory: index("sandbox_leases_expired_draining_inventory_idx").on(table.expiresAt, table.backend).where(sql`${table.liveness} = 'draining'`),
2200
2239
  workspaceGenerationValid: check(
2201
2240
  "sandbox_leases_workspace_generation_check",
2202
2241
  sql`${table.workspaceGeneration} >= 0`
@@ -2403,7 +2442,20 @@ var sandboxRetainedProcesses = pgTable(
2403
2442
  exitCode: integer("exit_code"),
2404
2443
  settlementReason: text("settlement_reason"),
2405
2444
  startedAt: timestamp("started_at", { withTimezone: true }).notNull().defaultNow(),
2406
- settledAt: timestamp("settled_at", { withTimezone: true })
2445
+ settledAt: timestamp("settled_at", { withTimezone: true }),
2446
+ // Coordination state for bounded terminal-owner reconciliation. While a
2447
+ // claim is live, reconcileAfter is its expiry; otherwise it is the next
2448
+ // retry time. Becoming due only licenses an exact provider probe and is
2449
+ // never exit/loss proof.
2450
+ reconcileAfter: timestamp("reconcile_after", { withTimezone: true }).notNull().defaultNow(),
2451
+ reconcileClaimId: uuid("reconcile_claim_id"),
2452
+ reconcileClaimedAt: timestamp("reconcile_claimed_at", { withTimezone: true }),
2453
+ reconcileAttempts: integer("reconcile_attempts").notNull().default(0),
2454
+ lastReconcileOutcome: text("last_reconcile_outcome"),
2455
+ reconcileProofOutcome: text("reconcile_proof_outcome", { enum: ["exited", "lost"] }),
2456
+ reconcileProofExitCode: integer("reconcile_proof_exit_code"),
2457
+ reconcileProofReason: text("reconcile_proof_reason"),
2458
+ reconcileProofObservedAt: timestamp("reconcile_proof_observed_at", { withTimezone: true })
2407
2459
  },
2408
2460
  (table) => ({
2409
2461
  workspaceAccount: foreignKey({
@@ -2452,6 +2504,8 @@ var sandboxRetainedProcesses = pgTable(
2452
2504
  ).where(sql`${table.state} = 'active'`),
2453
2505
  holder: uniqueIndex("sandbox_retained_processes_holder_uq").on(table.leaseId, table.holderId),
2454
2506
  active: index("sandbox_retained_processes_active_idx").on(table.workspaceId, table.sessionId, table.startedAt).where(sql`${table.state} = 'active'`),
2507
+ reconcileDue: index("sandbox_retained_processes_reconcile_due_idx").on(table.reconcileAfter, table.startedAt, table.id).where(sql`${table.state} = 'active'`),
2508
+ activeInventory: index("sandbox_retained_processes_active_inventory_idx").on(table.ownerActorKind, table.workspaceId, table.ownerTurnId, table.ownerAttemptId).where(sql`${table.state} = 'active'`),
2455
2509
  identityValid: check(
2456
2510
  "sandbox_retained_processes_identity_check",
2457
2511
  sql`${table.leaseEpoch} >= 0
@@ -2487,6 +2541,41 @@ var sandboxRetainedProcesses = pgTable(
2487
2541
  "sandbox_retained_processes_reason_check",
2488
2542
  sql`${table.settlementReason} is null
2489
2543
  or octet_length(${table.settlementReason}) between 1 and 512`
2544
+ ),
2545
+ reconcileClaimValid: check(
2546
+ "sandbox_retained_processes_reconcile_claim_check",
2547
+ sql`(${table.reconcileClaimId} is null and ${table.reconcileClaimedAt} is null)
2548
+ or (${table.reconcileClaimId} is not null and ${table.reconcileClaimedAt} is not null)`
2549
+ ),
2550
+ reconcileAttemptsValid: check(
2551
+ "sandbox_retained_processes_reconcile_attempts_check",
2552
+ sql`${table.reconcileAttempts} >= 0`
2553
+ ),
2554
+ reconcileOutcomeValid: check(
2555
+ "sandbox_retained_processes_reconcile_outcome_check",
2556
+ sql`${table.lastReconcileOutcome} is null
2557
+ or octet_length(${table.lastReconcileOutcome}) between 1 and 64`
2558
+ ),
2559
+ reconcileProofValid: check(
2560
+ "sandbox_retained_processes_reconcile_proof_check",
2561
+ sql`(
2562
+ ${table.reconcileProofOutcome} is null
2563
+ and ${table.reconcileProofExitCode} is null
2564
+ and ${table.reconcileProofReason} is null
2565
+ and ${table.reconcileProofObservedAt} is null
2566
+ ) or (
2567
+ ${table.reconcileProofOutcome} = 'exited'
2568
+ and ${table.reconcileProofExitCode} is not null
2569
+ and ${table.reconcileProofReason} = 'provider_exit_banner'
2570
+ and ${table.reconcileProofObservedAt} is not null
2571
+ ) or (
2572
+ ${table.reconcileProofOutcome} = 'lost'
2573
+ and ${table.reconcileProofExitCode} is null
2574
+ and ${table.reconcileProofReason} in (
2575
+ 'provider_session_lost_banner', 'provider_instance_not_found'
2576
+ )
2577
+ and ${table.reconcileProofObservedAt} is not null
2578
+ )`
2490
2579
  )
2491
2580
  })
2492
2581
  );
@@ -2916,10 +3005,17 @@ var githubInstallations = pgTable(
2916
3005
  accountId: uuid("account_id").notNull().references(() => managedAccounts.id, { onDelete: "cascade" }),
2917
3006
  workspaceId: uuid("workspace_id").notNull().references(() => workspaces.id, { onDelete: "cascade" }),
2918
3007
  installationId: integer("installation_id").notNull(),
3008
+ githubAccountId: bigint("github_account_id", { mode: "number" }),
2919
3009
  accountLogin: text("account_login"),
2920
3010
  accountType: text("account_type"),
2921
3011
  repositoryScope: text("repository_scope").notNull().default("all"),
2922
3012
  linkedBySubjectId: text("linked_by_subject_id"),
3013
+ githubActorId: bigint("github_actor_id", { mode: "number" }),
3014
+ githubActorLogin: text("github_actor_login"),
3015
+ authorityKind: text("authority_kind"),
3016
+ authorityCheckedAt: timestamp("authority_checked_at", { withTimezone: true }),
3017
+ authorityExpiresAt: timestamp("authority_expires_at", { withTimezone: true }),
3018
+ authorityNonce: text("authority_nonce"),
2923
3019
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
2924
3020
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow()
2925
3021
  },
@@ -2933,7 +3029,54 @@ var githubInstallations = pgTable(
2933
3029
  repositoryScopeCheck: check(
2934
3030
  "github_installations_repository_scope_check",
2935
3031
  sql`${table.repositoryScope} in ('all', 'selected')`
2936
- )
3032
+ ),
3033
+ authorityKindCheck: check(
3034
+ "github_installations_authority_kind_check",
3035
+ sql`
3036
+ (
3037
+ ${table.githubAccountId} is null
3038
+ and ${table.githubActorId} is null
3039
+ and ${table.githubActorLogin} is null
3040
+ and ${table.authorityKind} is null
3041
+ and ${table.authorityCheckedAt} is null
3042
+ and ${table.authorityExpiresAt} is null
3043
+ and ${table.authorityNonce} is null
3044
+ )
3045
+ or (
3046
+ ${table.githubAccountId} is not null
3047
+ and ${table.githubAccountId} > 0
3048
+ and ${table.githubActorId} is not null
3049
+ and ${table.githubActorId} > 0
3050
+ and ${table.githubActorLogin} is not null
3051
+ and length(${table.githubActorLogin}) > 0
3052
+ and ${table.accountLogin} is not null
3053
+ and length(${table.accountLogin}) > 0
3054
+ and ${table.accountType} is not null
3055
+ and ${table.linkedBySubjectId} is not null
3056
+ and length(${table.linkedBySubjectId}) > 0
3057
+ and ${table.authorityKind} is not null
3058
+ and ${table.authorityCheckedAt} is not null
3059
+ and ${table.authorityExpiresAt} is not null
3060
+ and ${table.authorityCheckedAt} < ${table.authorityExpiresAt}
3061
+ and ${table.authorityExpiresAt} <= ${table.authorityCheckedAt} + interval '10 minutes'
3062
+ and ${table.authorityNonce} is not null
3063
+ and length(${table.authorityNonce}) > 0
3064
+ and ${table.repositoryScope} = 'selected'
3065
+ and (
3066
+ (
3067
+ ${table.authorityKind} = 'personal_owner'
3068
+ and ${table.accountType} = 'User'
3069
+ and ${table.githubActorId} = ${table.githubAccountId}
3070
+ )
3071
+ or (
3072
+ ${table.authorityKind} = 'organization_owner'
3073
+ and ${table.accountType} = 'Organization'
3074
+ )
3075
+ )
3076
+ )
3077
+ `
3078
+ ),
3079
+ authorityNonce: uniqueIndex("github_installations_authority_nonce_uq").on(table.authorityNonce).where(sql`${table.authorityNonce} is not null`)
2937
3080
  })
2938
3081
  );
2939
3082
  var githubInstallationRepositories = pgTable(
@@ -3676,4 +3819,4 @@ export {
3676
3819
  rigChanges,
3677
3820
  schema_exports
3678
3821
  };
3679
- //# sourceMappingURL=chunk-VUKRIBO5.js.map
3822
+ //# sourceMappingURL=chunk-CYA6BHV6.js.map