@opengeni/db 3.7.4-canary.0 → 3.8.2-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/canonical-human-identities.js +3 -3
  2. package/dist/{chunk-DXJ2WY6W.js → chunk-53A2PEHT.js} +241 -31
  3. package/dist/chunk-53A2PEHT.js.map +1 -0
  4. package/dist/{chunk-JS3AWDKZ.js → chunk-5S4BQAHX.js} +3 -3
  5. package/dist/{chunk-JP6IYGYI.js → chunk-CITYUGMW.js} +3 -3
  6. package/dist/{chunk-6FIVOJ3V.js → chunk-F5YOZEYQ.js} +45 -1
  7. package/dist/chunk-F5YOZEYQ.js.map +1 -0
  8. package/dist/{chunk-ZTSJPFDH.js → chunk-HZV7O6JR.js} +2 -2
  9. package/dist/{chunk-VDXHLVDE.js → chunk-RLQVPOVR.js} +2 -2
  10. package/dist/{chunk-LHKB62GC.js → chunk-UKOGHUGC.js} +2 -2
  11. package/dist/{chunk-QL4AHBYD.js → chunk-X6TO5HII.js} +2 -2
  12. package/dist/{chunk-3ZMN4EXC.js → chunk-Y53WEFYB.js} +2 -2
  13. package/dist/connection-token-resolver.d.ts +4 -0
  14. package/dist/editable-artifact-durable-export.js +2 -2
  15. package/dist/editable-artifacts.js +3 -3
  16. package/dist/index.d.ts +59 -12
  17. package/dist/index.js +5259 -4374
  18. package/dist/index.js.map +1 -1
  19. package/dist/insights.d.ts +9 -0
  20. package/dist/managed-auth-session-sets.js +3 -3
  21. package/dist/new-session-drafts.d.ts +12 -0
  22. package/dist/organization-membership-lifecycle.d.ts +8 -1
  23. package/dist/organization-model-providers.d.ts +101 -0
  24. package/dist/pack-components.d.ts +1 -0
  25. package/dist/provision-roles.js +1 -1
  26. package/dist/runtime-posture.d.ts +5 -5
  27. package/dist/schema.d.ts +645 -0
  28. package/dist/schema.js +7 -1
  29. package/dist/session-background-commands.js +3 -3
  30. package/dist/session-tenancy.js +3 -3
  31. package/dist/video-generation.js +3 -3
  32. package/drizzle/0390_organization_model_provider_connections.sql +197 -0
  33. package/drizzle/0391_sandbox_provider_deadline_interaction_followup.sql +295 -0
  34. package/drizzle/0392_context_compaction_pending_observability.sql +198 -0
  35. package/drizzle/0393_workspace_memory_and_learning_defaults.sql +102 -0
  36. package/drizzle/0394_session_selected_skill_activation.sql +20 -0
  37. package/drizzle/0395_scheduled_task_unclaimed_occurrence_invalidation.sql +154 -0
  38. package/drizzle/0396_model_call_equivalent_credit_cost.sql +28 -0
  39. package/drizzle/0397_sandbox_deadline_rotation_preemption.sql +113 -0
  40. package/drizzle/0398_organization_workspace_management_entry.sql +206 -0
  41. package/drizzle/0399_additional_managed_organization_creation.sql +691 -0
  42. package/package.json +6 -6
  43. package/src/connection-token-resolver.ts +12 -0
  44. package/src/index.ts +701 -155
  45. package/src/insights-model-bundle.ts +54 -5
  46. package/src/insights.ts +32 -0
  47. package/src/new-session-drafts.ts +66 -21
  48. package/src/organization-membership-lifecycle.ts +47 -5
  49. package/src/organization-model-providers.ts +614 -0
  50. package/src/pack-components.ts +15 -2
  51. package/src/provision-roles.ts +2 -0
  52. package/src/runtime-posture.ts +44 -0
  53. package/src/schema.ts +250 -30
  54. package/dist/chunk-6FIVOJ3V.js.map +0 -1
  55. package/dist/chunk-DXJ2WY6W.js.map +0 -1
  56. /package/dist/{chunk-JS3AWDKZ.js.map → chunk-5S4BQAHX.js.map} +0 -0
  57. /package/dist/{chunk-JP6IYGYI.js.map → chunk-CITYUGMW.js.map} +0 -0
  58. /package/dist/{chunk-ZTSJPFDH.js.map → chunk-HZV7O6JR.js.map} +0 -0
  59. /package/dist/{chunk-VDXHLVDE.js.map → chunk-RLQVPOVR.js.map} +0 -0
  60. /package/dist/{chunk-LHKB62GC.js.map → chunk-UKOGHUGC.js.map} +0 -0
  61. /package/dist/{chunk-QL4AHBYD.js.map → chunk-X6TO5HII.js.map} +0 -0
  62. /package/dist/{chunk-3ZMN4EXC.js.map → chunk-Y53WEFYB.js.map} +0 -0
@@ -81,6 +81,8 @@ const KNOWLEDGE_SOURCE_SYNC_LOCK_AUTHORITY_TABLES = [
81
81
  ] as const;
82
82
  const MANAGED_HUMAN_PERSONAL_WORKSPACE_ROUTINE =
83
83
  "ensure_managed_human_personal_workspace(uuid, text, uuid)";
84
+ const ADDITIONAL_ORGANIZATION_CREATION_ROUTINE =
85
+ "create_additional_managed_organization(text, text, text, text, uuid)";
84
86
  const ORGANIZATION_MEMBERSHIP_LIFECYCLE_ROUTINES = [
85
87
  "list_self_organization_memberships(text)",
86
88
  "list_self_organization_invitations(text)",
@@ -94,9 +96,11 @@ const ORGANIZATION_MEMBERSHIP_LIFECYCLE_ROUTINES = [
94
96
  "resolve_workspace_codex_subscription_source(uuid, uuid)",
95
97
  "list_organization_workspace_ids(uuid)",
96
98
  "organization_workspace_command(jsonb)",
99
+ "authorize_organization_shared_workspace_administration(uuid, uuid, text)",
97
100
  "resolve_organization_workspace_removal_subject(uuid, text, uuid)",
98
101
  "prepare_organization_workspace_member_removal(jsonb)",
99
102
  "record_organization_workspace_member_removal(jsonb, uuid, uuid)",
103
+ ADDITIONAL_ORGANIZATION_CREATION_ROUTINE,
100
104
  "create_managed_organization(text, text, text, uuid)",
101
105
  "assert_organization_shared_workspace_administrator(uuid, uuid, text)",
102
106
  "open_organization_shared_workspace_administration_capability(uuid, uuid, text)",
@@ -154,6 +158,10 @@ const ORGANIZATION_MEMBERSHIP_LIFECYCLE_AUTHORITY_TABLES = [
154
158
  "organization_workspace_operation_receipts",
155
159
  "self_service_organization_setup_receipts",
156
160
  ] as const;
161
+ const ADDITIONAL_ORGANIZATION_CREATION_AUTHORITY_TABLES = [
162
+ ...ORGANIZATION_MEMBERSHIP_LIFECYCLE_AUTHORITY_TABLES,
163
+ "additional_organization_creation_receipts",
164
+ ] as const;
157
165
  const PRIVATE_SESSION_CREATE_POLICY_ROUTINE = "get_private_session_create_policy(uuid, uuid, text)";
158
166
  const ORGANIZATION_PRIVATE_SESSION_SETTINGS_READ_ROUTINE =
159
167
  "get_organization_private_session_settings(uuid, text)";
@@ -489,6 +497,8 @@ const TENANCY_BACKFILL_ACTIVATION_EVIDENCE_ROUTINE =
489
497
  "check_tenancy_backfill_activation_evidence(uuid)";
490
498
  const GREENFIELD_SESSION_TENANCY_ACTIVATION_ROUTINE =
491
499
  "activate_greenfield_session_tenancy_from_setup(text)";
500
+ const ADDITIONAL_ORGANIZATION_SESSION_TENANCY_ACTIVATION_ROUTINE =
501
+ "activate_session_tenancy_from_additional_organization(uuid)";
492
502
  const SESSION_VISIBILITY_LIFECYCLE_CAPABILITY_ROUTINE =
493
503
  "session_visibility_lifecycle_capability_held()";
494
504
  const PRIVATE_SESSION_CREATE_CAPABILITY_ROUTINES = [
@@ -597,6 +607,7 @@ const RUNTIME_TARGET_SCHEMA_PUBLIC_POLICY_PREDICATE_ROUTINE_SET = new Set<string
597
607
 
598
608
  /** Owner-internal helpers that must exist but must never be callable by the runtime role. */
599
609
  export const RUNTIME_TARGET_SCHEMA_FORBIDDEN_ROUTINES = [
610
+ ADDITIONAL_ORGANIZATION_SESSION_TENANCY_ACTIVATION_ROUTINE,
600
611
  AUTOMATIC_SESSION_TITLE_QUARANTINE_FENCE_ROUTINE,
601
612
  ORGANIZATION_PRIVATE_SESSIONS_ENABLED_ROUTINE,
602
613
  GREENFIELD_SESSION_TENANCY_ACTIVATION_ROUTINE,
@@ -620,6 +631,7 @@ const RUNTIME_TARGET_SCHEMA_INVOKER_ROUTINE_SET = new Set<string>(
620
631
  * commit as the migration so startup cannot silently accept an unreviewed gap.
621
632
  */
622
633
  export const FORCE_RLS_TABLES = [
634
+ "additional_organization_creation_receipts",
623
635
  "agent_run_states",
624
636
  "api_keys",
625
637
  "attached_browser_devices",
@@ -786,6 +798,9 @@ export const FORCE_RLS_TABLES = [
786
798
  "organization_membership_lifecycle_events",
787
799
  "organization_membership_operation_receipts",
788
800
  "organization_memberships",
801
+ "organization_model_provider_connection_operations",
802
+ "organization_model_provider_connections",
803
+ "organization_model_provider_custom_models",
789
804
  "organization_private_session_setting_events",
790
805
  "organization_private_session_settings",
791
806
  "organization_profile_events",
@@ -883,6 +898,7 @@ export const FORCE_RLS_TABLES = [
883
898
  "session_system_update_outbox",
884
899
  "session_system_updates",
885
900
  "session_tenancy_activations",
901
+ "session_tenancy_additional_organization_activation_evidence",
886
902
  "session_tenancy_greenfield_activation_evidence",
887
903
  "session_turn_attempts",
888
904
  "session_turn_startup_milestones",
@@ -1069,6 +1085,9 @@ export const RUNTIME_FULL_DML_TABLES = [
1069
1085
  "model_call_facts",
1070
1086
  "new_session_drafts",
1071
1087
  "organization_codex_rotation_settings",
1088
+ "organization_model_provider_connection_operations",
1089
+ "organization_model_provider_connections",
1090
+ "organization_model_provider_custom_models",
1072
1091
  "pack_installation_components",
1073
1092
  "pack_installations",
1074
1093
  "pr_review_app_registrations",
@@ -1274,6 +1293,7 @@ export const RUNTIME_READ_INSERT_UPDATE_TABLES = [
1274
1293
  * The ordinary application role must have no direct table privileges on them.
1275
1294
  */
1276
1295
  export const PROTECTED_NO_DIRECT_DML_TABLES = [
1296
+ "additional_organization_creation_receipts",
1277
1297
  "canonical_human_identities",
1278
1298
  "canonical_human_identity_operations",
1279
1299
  "canonical_human_identity_subjects",
@@ -1363,6 +1383,7 @@ export const PROTECTED_NO_DIRECT_DML_TABLES = [
1363
1383
  "session_attempt_personal_document_snapshots",
1364
1384
  "session_attempt_personal_resource_admissions",
1365
1385
  "session_attempt_personal_resource_snapshots",
1386
+ "session_tenancy_additional_organization_activation_evidence",
1366
1387
  "session_tenancy_greenfield_activation_evidence",
1367
1388
  "session_variable_set_attachments",
1368
1389
  "session_visibility_write_capabilities",
@@ -2299,6 +2320,29 @@ export function evaluateRuntimeDatabasePosture(
2299
2320
  );
2300
2321
  }
2301
2322
  }
2323
+ } else if (routine.name === ADDITIONAL_ORGANIZATION_CREATION_ROUTINE) {
2324
+ const missingAuthorityTables = ADDITIONAL_ORGANIZATION_CREATION_AUTHORITY_TABLES.filter(
2325
+ (tableName) => !tableByName.has(tableName),
2326
+ );
2327
+ if (missingAuthorityTables.length > 0) {
2328
+ violations.push(
2329
+ `target-schema runtime capability ${routine.name} authority tables are missing: ${missingAuthorityTables.join(", ")}`,
2330
+ );
2331
+ } else {
2332
+ const authorityTables = ADDITIONAL_ORGANIZATION_CREATION_AUTHORITY_TABLES.map(
2333
+ (tableName) => tableByName.get(tableName)!,
2334
+ );
2335
+ const authorityOwners = new Set(authorityTables.map((table) => table.owner));
2336
+ if (authorityOwners.size !== 1) {
2337
+ violations.push(
2338
+ `target-schema runtime capability ${routine.name} authority table owners do not match: ${authorityTables.map((table) => `${table.name}=${table.owner}`).join(", ")}`,
2339
+ );
2340
+ } else if (routine.owner !== authorityTables[0]!.owner) {
2341
+ violations.push(
2342
+ `target-schema runtime capability ${routine.name} owner ${routine.owner} does not match authority table owner ${authorityTables[0]!.owner}`,
2343
+ );
2344
+ }
2345
+ }
2302
2346
  } else if (
2303
2347
  (ORGANIZATION_MEMBERSHIP_LIFECYCLE_ROUTINES as readonly string[]).includes(routine.name)
2304
2348
  ) {
package/src/schema.ts CHANGED
@@ -110,9 +110,12 @@ export const workspaces = pgTable(
110
110
  // White-label agent persona template override. NULL means the deployment
111
111
  // default (OPENGENI_AGENT_INSTRUCTIONS_TEMPLATE / DEFAULT_AGENT_INSTRUCTIONS).
112
112
  agentInstructions: text("agent_instructions"),
113
- // Growth-ready per-workspace settings bag (migration 0045). Holds memoryEnabled
114
- // and future workspace-level toggles; validated/merged via WorkspaceSettingsSchema.
115
- settings: jsonb("settings").$type<Record<string, unknown>>().notNull().default({}),
113
+ // Growth-ready per-workspace settings bag (migration 0045). Migration 0393
114
+ // makes Memory enabled by default; explicit false remains authoritative.
115
+ settings: jsonb("settings")
116
+ .$type<Record<string, unknown>>()
117
+ .notNull()
118
+ .default({ memoryEnabled: true }),
116
119
  // The workspace's default rig (migration 0047). NULL ⇒ no default; sessions
117
120
  // created without an explicit rig ride no rig (today's behavior exactly). FK
118
121
  // (-> rigs(id) ON DELETE SET NULL) lives in migration 0047, not a Drizzle
@@ -524,8 +527,12 @@ export const organizationProfileEvents = pgTable(
524
527
  actorMembershipId: uuid("actor_membership_id").notNull(),
525
528
  previousName: text("previous_name").notNull(),
526
529
  requestedName: text("requested_name").notNull(),
527
- expectedUpdatedAt: timestamp("expected_updated_at", { withTimezone: true }).notNull(),
528
- resultUpdatedAt: timestamp("result_updated_at", { withTimezone: true }).notNull(),
530
+ expectedUpdatedAt: timestamp("expected_updated_at", {
531
+ withTimezone: true,
532
+ }).notNull(),
533
+ resultUpdatedAt: timestamp("result_updated_at", {
534
+ withTimezone: true,
535
+ }).notNull(),
529
536
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
530
537
  },
531
538
  (table) => ({
@@ -613,7 +620,9 @@ export const organizationPrivateSessionSettingEvents = pgTable(
613
620
  expectedVersion: bigint("expected_version", { mode: "number" }).notNull(),
614
621
  resultEnabled: boolean("result_enabled").notNull(),
615
622
  resultVersion: bigint("result_version", { mode: "number" }).notNull(),
616
- resultUpdatedAt: timestamp("result_updated_at", { withTimezone: true }).notNull(),
623
+ resultUpdatedAt: timestamp("result_updated_at", {
624
+ withTimezone: true,
625
+ }).notNull(),
617
626
  changed: boolean("changed").notNull(),
618
627
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
619
628
  },
@@ -751,7 +760,9 @@ export const organizationInvitationBindingEvents = pgTable(
751
760
  .references(() => managedAccounts.id, { onDelete: "cascade" }),
752
761
  invitationId: uuid("invitation_id").notNull(),
753
762
  targetSubjectId: text("target_subject_id").notNull(),
754
- resultingRevision: bigint("resulting_revision", { mode: "number" }).notNull(),
763
+ resultingRevision: bigint("resulting_revision", {
764
+ mode: "number",
765
+ }).notNull(),
755
766
  boundAt: timestamp("bound_at", { withTimezone: true }).notNull().defaultNow(),
756
767
  },
757
768
  (table) => ({
@@ -854,13 +865,19 @@ export const organizationUserRetentionDeletions = pgTable(
854
865
  .notNull()
855
866
  .references(() => managedAccounts.id, { onDelete: "cascade" }),
856
867
  membershipId: uuid("membership_id").notNull(),
857
- retentionUntil: timestamp("retention_until", { withTimezone: true }).notNull(),
868
+ retentionUntil: timestamp("retention_until", {
869
+ withTimezone: true,
870
+ }).notNull(),
858
871
  state: text("state").notNull().default("claimed"),
859
872
  claimOperationId: uuid("claim_operation_id").notNull(),
860
- claimExpiresAt: timestamp("claim_expires_at", { withTimezone: true }).notNull(),
873
+ claimExpiresAt: timestamp("claim_expires_at", {
874
+ withTimezone: true,
875
+ }).notNull(),
861
876
  attemptCount: integer("attempt_count").notNull().default(1),
862
877
  databaseResult: jsonb("database_result").$type<Record<string, unknown>>(),
863
- databaseFinalizedAt: timestamp("database_finalized_at", { withTimezone: true }),
878
+ databaseFinalizedAt: timestamp("database_finalized_at", {
879
+ withTimezone: true,
880
+ }),
864
881
  result: jsonb("result").$type<Record<string, unknown>>(),
865
882
  completedAt: timestamp("completed_at", { withTimezone: true }),
866
883
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
@@ -1262,7 +1279,9 @@ export const codexSubscriptionCredentials = pgTable(
1262
1279
  accountId: uuid("account_id")
1263
1280
  .notNull()
1264
1281
  .references(() => managedAccounts.id, { onDelete: "cascade" }),
1265
- workspaceId: uuid("workspace_id").references(() => workspaces.id, { onDelete: "cascade" }),
1282
+ workspaceId: uuid("workspace_id").references(() => workspaces.id, {
1283
+ onDelete: "cascade",
1284
+ }),
1266
1285
  organizationId: uuid("organization_id").references(() => managedAccounts.id, {
1267
1286
  onDelete: "cascade",
1268
1287
  }),
@@ -1836,7 +1855,9 @@ export const connectionUseOnceConsumptionReceipts = pgTable(
1836
1855
  .notNull()
1837
1856
  .references(() => managedAccounts.id, { onDelete: "cascade" }),
1838
1857
  authorityId: uuid("authority_id").notNull(),
1839
- authorityGeneration: bigint("authority_generation", { mode: "number" }).notNull(),
1858
+ authorityGeneration: bigint("authority_generation", {
1859
+ mode: "number",
1860
+ }).notNull(),
1840
1861
  grantGeneration: bigint("grant_generation", { mode: "number" }).notNull(),
1841
1862
  acceptedWorkKind: text("accepted_work_kind").notNull(),
1842
1863
  acceptedWorkId: uuid("accepted_work_id").notNull(),
@@ -2621,7 +2642,9 @@ export const slackInteractionInbox = pgTable(
2621
2642
  targetAccountId: uuid("target_account_id"),
2622
2643
  targetWorkspaceId: uuid("target_workspace_id"),
2623
2644
  routePromptId: uuid("route_prompt_id"),
2624
- routePromptExpiresAt: timestamp("route_prompt_expires_at", { withTimezone: true }),
2645
+ routePromptExpiresAt: timestamp("route_prompt_expires_at", {
2646
+ withTimezone: true,
2647
+ }),
2625
2648
  processedAt: timestamp("processed_at", { withTimezone: true }),
2626
2649
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
2627
2650
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
@@ -6185,7 +6208,9 @@ export const turnPersonalResourceSnapshots = pgTable(
6185
6208
  mode: "number",
6186
6209
  }).notNull(),
6187
6210
  authorityId: uuid("authority_id").notNull(),
6188
- authorityGeneration: bigint("authority_generation", { mode: "number" }).notNull(),
6211
+ authorityGeneration: bigint("authority_generation", {
6212
+ mode: "number",
6213
+ }).notNull(),
6189
6214
  grantId: uuid("grant_id").notNull(),
6190
6215
  grantGeneration: bigint("grant_generation", { mode: "number" }).notNull(),
6191
6216
  grantMode: text("grant_mode").notNull(),
@@ -6197,7 +6222,9 @@ export const turnPersonalResourceSnapshots = pgTable(
6197
6222
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
6198
6223
  },
6199
6224
  (table) => ({
6200
- pk: primaryKey({ columns: [table.turnId, table.resourceKind, table.resourceId] }),
6225
+ pk: primaryKey({
6226
+ columns: [table.turnId, table.resourceKind, table.resourceId],
6227
+ }),
6201
6228
  receipt: foreignKey({
6202
6229
  name: "turn_personal_resource_snapshots_receipt_fk",
6203
6230
  columns: [table.turnId],
@@ -6246,7 +6273,9 @@ export const turnPersonalResourceOnceReceipts = pgTable(
6246
6273
  turnId: uuid("turn_id").notNull(),
6247
6274
  accountId: uuid("account_id").notNull(),
6248
6275
  authorityId: uuid("authority_id").notNull(),
6249
- authorityGeneration: bigint("authority_generation", { mode: "number" }).notNull(),
6276
+ authorityGeneration: bigint("authority_generation", {
6277
+ mode: "number",
6278
+ }).notNull(),
6250
6279
  grantGeneration: bigint("grant_generation", { mode: "number" }).notNull(),
6251
6280
  consumedAt: timestamp("consumed_at", { withTimezone: true }).notNull().defaultNow(),
6252
6281
  },
@@ -6541,7 +6570,9 @@ export const turnConnectionAuthoritySnapshots = pgTable(
6541
6570
  turnId: uuid("turn_id").notNull(),
6542
6571
  serverId: text("server_id").notNull(),
6543
6572
  connectionId: uuid("connection_id").notNull(),
6544
- connectionGeneration: bigint("connection_generation", { mode: "number" }).notNull(),
6573
+ connectionGeneration: bigint("connection_generation", {
6574
+ mode: "number",
6575
+ }).notNull(),
6545
6576
  originWorkspaceId: uuid("origin_workspace_id").notNull(),
6546
6577
  providerDomain: text("provider_domain").notNull(),
6547
6578
  connectionKind: text("connection_kind").notNull(),
@@ -7584,9 +7615,13 @@ export const sessionGoals = pgTable(
7584
7615
  // Any newer finished turn, a passed deadline, or a goal mutation clears all
7585
7616
  // four columns together.
7586
7617
  continuationHoldTurnId: uuid("continuation_hold_turn_id"),
7587
- continuationHoldUntil: timestamp("continuation_hold_until", { withTimezone: true }),
7618
+ continuationHoldUntil: timestamp("continuation_hold_until", {
7619
+ withTimezone: true,
7620
+ }),
7588
7621
  continuationHoldReason: text("continuation_hold_reason"),
7589
- continuationHoldSetAt: timestamp("continuation_hold_set_at", { withTimezone: true }),
7622
+ continuationHoldSetAt: timestamp("continuation_hold_set_at", {
7623
+ withTimezone: true,
7624
+ }),
7590
7625
  metadata: jsonb("metadata").$type<Record<string, unknown>>().notNull().default({}),
7591
7626
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
7592
7627
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
@@ -8861,7 +8896,9 @@ export const sandboxWorkspaceMutationAdmissions = pgTable(
8861
8896
  // authorization revision observed at admission. The revision is audit
8862
8897
  // evidence: a role change is not a revocation and must not fence a writer.
8863
8898
  initiatorOrganizationMembershipId: uuid("initiator_organization_membership_id"),
8864
- initiatorAuthorizationRevision: bigint("initiator_authorization_revision", { mode: "number" }),
8899
+ initiatorAuthorizationRevision: bigint("initiator_authorization_revision", {
8900
+ mode: "number",
8901
+ }),
8865
8902
  // Session tenancy authority observed when the operation was admitted; the
8866
8903
  // same triple `session_turn_attempts` freezes for a turn.
8867
8904
  authorityEpoch: integer("authority_epoch"),
@@ -9083,7 +9120,9 @@ export const sandboxRetainedProcesses = pgTable(
9083
9120
  initiatorSubjectId: text("initiator_subject_id").notNull().default("unattributed-legacy"),
9084
9121
  initiatingHumanSubjectId: text("initiating_human_subject_id"),
9085
9122
  initiatorOrganizationMembershipId: uuid("initiator_organization_membership_id"),
9086
- initiatorAuthorizationRevision: bigint("initiator_authorization_revision", { mode: "number" }),
9123
+ initiatorAuthorizationRevision: bigint("initiator_authorization_revision", {
9124
+ mode: "number",
9125
+ }),
9087
9126
  authorityEpoch: integer("authority_epoch"),
9088
9127
  authorityVisibility: text("authority_visibility", {
9089
9128
  enum: ["user_private", "workspace_shared"],
@@ -9342,7 +9381,9 @@ export const sessionBackgroundCommands = pgTable(
9342
9381
  accountId: uuid("account_id").notNull(),
9343
9382
  workspaceId: uuid("workspace_id").notNull(),
9344
9383
  sessionId: uuid("session_id").notNull(),
9345
- provider: text("provider", { enum: ["managed", "connected_machine"] }).notNull(),
9384
+ provider: text("provider", {
9385
+ enum: ["managed", "connected_machine"],
9386
+ }).notNull(),
9346
9387
  state: text("state", { enum: ["running", "stopping", "exited", "lost"] })
9347
9388
  .notNull()
9348
9389
  .default("running"),
@@ -9360,13 +9401,19 @@ export const sessionBackgroundCommands = pgTable(
9360
9401
  settledAt: timestamp("settled_at", { withTimezone: true }),
9361
9402
  reconcileAfter: timestamp("reconcile_after", { withTimezone: true }).notNull().defaultNow(),
9362
9403
  reconcileClaimId: uuid("reconcile_claim_id"),
9363
- reconcileClaimedAt: timestamp("reconcile_claimed_at", { withTimezone: true }),
9404
+ reconcileClaimedAt: timestamp("reconcile_claimed_at", {
9405
+ withTimezone: true,
9406
+ }),
9364
9407
  reconcileAttempts: integer("reconcile_attempts").notNull().default(0),
9365
9408
  lastReconcileOutcome: text("last_reconcile_outcome"),
9366
- reconcileProofOutcome: text("reconcile_proof_outcome", { enum: ["exited", "lost"] }),
9409
+ reconcileProofOutcome: text("reconcile_proof_outcome", {
9410
+ enum: ["exited", "lost"],
9411
+ }),
9367
9412
  reconcileProofExitCode: integer("reconcile_proof_exit_code"),
9368
9413
  reconcileProofReason: text("reconcile_proof_reason"),
9369
- reconcileProofObservedAt: timestamp("reconcile_proof_observed_at", { withTimezone: true }),
9414
+ reconcileProofObservedAt: timestamp("reconcile_proof_observed_at", {
9415
+ withTimezone: true,
9416
+ }),
9370
9417
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
9371
9418
  },
9372
9419
  (table) => ({
@@ -10606,12 +10653,18 @@ export const prReviewAppRegistrations = pgTable(
10606
10653
  providerAccountType: text("provider_account_type"),
10607
10654
  githubActorId: text("github_actor_id"),
10608
10655
  authorityKind: text("authority_kind"),
10609
- authorityCheckedAt: timestamp("authority_checked_at", { withTimezone: true }),
10610
- authorityExpiresAt: timestamp("authority_expires_at", { withTimezone: true }),
10656
+ authorityCheckedAt: timestamp("authority_checked_at", {
10657
+ withTimezone: true,
10658
+ }),
10659
+ authorityExpiresAt: timestamp("authority_expires_at", {
10660
+ withTimezone: true,
10661
+ }),
10611
10662
  authorityNonce: text("authority_nonce"),
10612
10663
  credentialKind: text("credential_kind").notNull(),
10613
10664
  credentialEncrypted: text("credential_encrypted"),
10614
- accessTokenExpiresAt: timestamp("access_token_expires_at", { withTimezone: true }),
10665
+ accessTokenExpiresAt: timestamp("access_token_expires_at", {
10666
+ withTimezone: true,
10667
+ }),
10615
10668
  webhookAuthKind: text("webhook_auth_kind").notNull(),
10616
10669
  webhookUsername: text("webhook_username"),
10617
10670
  status: text("status").notNull().default("active"),
@@ -10757,7 +10810,9 @@ export const prReviewManagedGithubAuthorityNonces = pgTable(
10757
10810
  .notNull()
10758
10811
  .references(() => workspaces.id, { onDelete: "cascade" }),
10759
10812
  installationId: text("installation_id").notNull(),
10760
- authorityExpiresAt: timestamp("authority_expires_at", { withTimezone: true }).notNull(),
10813
+ authorityExpiresAt: timestamp("authority_expires_at", {
10814
+ withTimezone: true,
10815
+ }).notNull(),
10761
10816
  consumedAt: timestamp("consumed_at", { withTimezone: true }).notNull().defaultNow(),
10762
10817
  },
10763
10818
  (table) => ({
@@ -10939,6 +10994,9 @@ export const modelCallFacts = pgTable(
10939
10994
  estimatedProviderCostMicros: bigint("estimated_provider_cost_micros", {
10940
10995
  mode: "number",
10941
10996
  }),
10997
+ equivalentCreditCostMicros: bigint("equivalent_credit_cost_micros", {
10998
+ mode: "number",
10999
+ }),
10942
11000
  pricingSource: text("pricing_source"),
10943
11001
  contextContributions:
10944
11002
  jsonb("context_contributions").$type<readonly ModelContextContributionSummary[]>(),
@@ -10983,6 +11041,10 @@ export const modelCallFacts = pgTable(
10983
11041
  "model_call_facts_estimated_provider_cost_check",
10984
11042
  sql`${table.estimatedProviderCostMicros} is null or ${table.estimatedProviderCostMicros} >= 0`,
10985
11043
  ),
11044
+ equivalentCreditCostValid: check(
11045
+ "model_call_facts_equivalent_credit_cost_check",
11046
+ sql`${table.equivalentCreditCostMicros} is null or (${table.equivalentCreditCostMicros} >= 0 and ${table.estimatedProviderCostMicros} is not null)`,
11047
+ ),
10986
11048
  pricingSourceValid: check(
10987
11049
  "model_call_facts_pricing_source_check",
10988
11050
  sql`(${table.estimatedProviderCostMicros} is null and ${table.pricingSource} is null)
@@ -11634,7 +11696,9 @@ export const automationRuns = pgTable(
11634
11696
  occurrenceKey: text("occurrence_key").notNull(),
11635
11697
  acceptedExecution: jsonb("accepted_execution").$type<AutomationAcceptedExecution>().notNull(),
11636
11698
  status: text("status").notNull().default("queued"),
11637
- sessionId: uuid("session_id").references(() => sessions.id, { onDelete: "set null" }),
11699
+ sessionId: uuid("session_id").references(() => sessions.id, {
11700
+ onDelete: "set null",
11701
+ }),
11638
11702
  errorCode: text("error_code"),
11639
11703
  createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
11640
11704
  updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
@@ -12724,6 +12788,162 @@ export const workspaceGatewayCustomModels = pgTable(
12724
12788
  }),
12725
12789
  );
12726
12790
 
12791
+ export const organizationModelProviderConnections = pgTable(
12792
+ "organization_model_provider_connections",
12793
+ {
12794
+ id: uuid("id").primaryKey().defaultRandom(),
12795
+ accountId: uuid("account_id")
12796
+ .notNull()
12797
+ .references(() => managedAccounts.id, { onDelete: "cascade" }),
12798
+ providerKind: text("provider_kind").$type<"vercel_gateway" | "openrouter">().notNull(),
12799
+ status: text("status").$type<"active" | "revoked">().notNull().default("active"),
12800
+ credentialEncrypted: text("credential_encrypted").notNull(),
12801
+ version: integer("version").notNull().default(1),
12802
+ operationId: uuid("operation_id").notNull(),
12803
+ requestHash: text("request_hash").notNull(),
12804
+ updatedBySubjectId: text("updated_by_subject_id").notNull(),
12805
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
12806
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
12807
+ },
12808
+ (table) => ({
12809
+ accountProvider: uniqueIndex("organization_model_provider_connections_account_provider_uq").on(
12810
+ table.accountId,
12811
+ table.providerKind,
12812
+ ),
12813
+ operation: uniqueIndex("organization_model_provider_connections_operation_uq").on(
12814
+ table.accountId,
12815
+ table.providerKind,
12816
+ table.operationId,
12817
+ ),
12818
+ providerKindCheck: check(
12819
+ "organization_model_provider_connections_provider_kind_chk",
12820
+ sql`${table.providerKind} in ('vercel_gateway', 'openrouter')`,
12821
+ ),
12822
+ statusCheck: check(
12823
+ "organization_model_provider_connections_status_chk",
12824
+ sql`${table.status} in ('active', 'revoked')`,
12825
+ ),
12826
+ versionCheck: check(
12827
+ "organization_model_provider_connections_version_chk",
12828
+ sql`${table.version} > 0`,
12829
+ ),
12830
+ requestHashCheck: check(
12831
+ "organization_model_provider_connections_request_hash_chk",
12832
+ sql`${table.requestHash} ~ '^[a-f0-9]{64}$'`,
12833
+ ),
12834
+ actorCheck: check(
12835
+ "organization_model_provider_connections_actor_chk",
12836
+ sql`octet_length(${table.updatedBySubjectId}) between 1 and 1024`,
12837
+ ),
12838
+ }),
12839
+ );
12840
+
12841
+ export const organizationModelProviderConnectionOperations = pgTable(
12842
+ "organization_model_provider_connection_operations",
12843
+ {
12844
+ id: uuid("id").primaryKey().defaultRandom(),
12845
+ accountId: uuid("account_id")
12846
+ .notNull()
12847
+ .references(() => managedAccounts.id, { onDelete: "cascade" }),
12848
+ providerKind: text("provider_kind").$type<"vercel_gateway" | "openrouter">().notNull(),
12849
+ operationId: uuid("operation_id").notNull(),
12850
+ requestHash: text("request_hash").notNull(),
12851
+ resultStatus: text("result_status").$type<"active" | "revoked">().notNull(),
12852
+ resultVersion: integer("result_version").notNull(),
12853
+ resultCreatedAt: timestamp("result_created_at", {
12854
+ withTimezone: true,
12855
+ }).notNull(),
12856
+ resultUpdatedAt: timestamp("result_updated_at", {
12857
+ withTimezone: true,
12858
+ }).notNull(),
12859
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
12860
+ },
12861
+ (table) => ({
12862
+ operation: uniqueIndex("organization_model_provider_connection_operations_operation_uq").on(
12863
+ table.accountId,
12864
+ table.providerKind,
12865
+ table.operationId,
12866
+ ),
12867
+ providerKindCheck: check(
12868
+ "organization_model_provider_connection_operations_provider_kind_chk",
12869
+ sql`${table.providerKind} in ('vercel_gateway', 'openrouter')`,
12870
+ ),
12871
+ resultStatusCheck: check(
12872
+ "organization_model_provider_connection_operations_result_status_chk",
12873
+ sql`${table.resultStatus} in ('active', 'revoked')`,
12874
+ ),
12875
+ resultVersionCheck: check(
12876
+ "organization_model_provider_connection_operations_result_version_chk",
12877
+ sql`${table.resultVersion} > 0`,
12878
+ ),
12879
+ requestHashCheck: check(
12880
+ "organization_model_provider_connection_operations_request_hash_chk",
12881
+ sql`${table.requestHash} ~ '^[a-f0-9]{64}$'`,
12882
+ ),
12883
+ }),
12884
+ );
12885
+
12886
+ export const organizationModelProviderCustomModels = pgTable(
12887
+ "organization_model_provider_custom_models",
12888
+ {
12889
+ id: uuid("id").primaryKey().defaultRandom(),
12890
+ accountId: uuid("account_id")
12891
+ .notNull()
12892
+ .references(() => managedAccounts.id, { onDelete: "cascade" }),
12893
+ providerKind: text("provider_kind").$type<"vercel_gateway" | "openrouter">().notNull(),
12894
+ upstreamModelId: text("upstream_model_id").notNull(),
12895
+ label: text("label"),
12896
+ version: integer("version").notNull().default(1),
12897
+ createOperationId: uuid("create_operation_id").notNull(),
12898
+ createRequestHash: text("create_request_hash").notNull(),
12899
+ deleteOperationId: uuid("delete_operation_id"),
12900
+ deleteRequestHash: text("delete_request_hash"),
12901
+ createdBySubjectId: text("created_by_subject_id").notNull(),
12902
+ retiredAt: timestamp("retired_at", { withTimezone: true }),
12903
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
12904
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
12905
+ },
12906
+ (table) => ({
12907
+ accountUpstream: uniqueIndex("organization_model_provider_custom_models_active_uq")
12908
+ .on(table.accountId, table.providerKind, table.upstreamModelId)
12909
+ .where(sql`${table.retiredAt} is null`),
12910
+ createOperation: uniqueIndex(
12911
+ "organization_model_provider_custom_models_create_operation_uq",
12912
+ ).on(table.accountId, table.providerKind, table.createOperationId),
12913
+ deleteOperation: uniqueIndex("organization_model_provider_custom_models_delete_operation_uq")
12914
+ .on(table.accountId, table.providerKind, table.deleteOperationId)
12915
+ .where(sql`${table.deleteOperationId} is not null`),
12916
+ providerKindCheck: check(
12917
+ "organization_model_provider_custom_models_provider_kind_chk",
12918
+ sql`${table.providerKind} in ('vercel_gateway', 'openrouter')`,
12919
+ ),
12920
+ upstreamCheck: check(
12921
+ "organization_model_provider_custom_models_upstream_chk",
12922
+ sql`octet_length(${table.upstreamModelId}) between 1 and 238 and ${table.upstreamModelId} ~ '^[!-~]+$' and ${table.upstreamModelId} !~ '[|]'`,
12923
+ ),
12924
+ labelCheck: check(
12925
+ "organization_model_provider_custom_models_label_chk",
12926
+ sql`${table.label} is null or (octet_length(${table.label}) between 1 and 128 and ${table.label} !~ '[\r\n|]')`,
12927
+ ),
12928
+ versionCheck: check(
12929
+ "organization_model_provider_custom_models_version_chk",
12930
+ sql`${table.version} > 0`,
12931
+ ),
12932
+ actorCheck: check(
12933
+ "organization_model_provider_custom_models_actor_chk",
12934
+ sql`octet_length(${table.createdBySubjectId}) between 1 and 1024`,
12935
+ ),
12936
+ createHashCheck: check(
12937
+ "organization_model_provider_custom_models_create_hash_chk",
12938
+ sql`${table.createRequestHash} ~ '^[a-f0-9]{64}$'`,
12939
+ ),
12940
+ deleteReceiptCheck: check(
12941
+ "organization_model_provider_custom_models_delete_receipt_chk",
12942
+ sql`(${table.deleteOperationId} is null and ${table.deleteRequestHash} is null) or (${table.deleteOperationId} is not null and ${table.deleteRequestHash} ~ '^[a-f0-9]{64}$' and ${table.retiredAt} is not null)`,
12943
+ ),
12944
+ }),
12945
+ );
12946
+
12727
12947
  export * from "./workspace-instruction-policies-schema";
12728
12948
  export * from "./company-profile-schema";
12729
12949
  export * from "./workspace-learning-policy-schema";