@opengeni/db 3.7.4 → 4.0.0-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.
- package/dist/automations.d.ts +4 -0
- package/dist/canonical-human-identities.js +3 -3
- package/dist/capability-integrations.d.ts +2 -0
- package/dist/{chunk-6DPJA36C.js → chunk-2XEZK4LF.js} +7 -1
- package/dist/chunk-2XEZK4LF.js.map +1 -0
- package/dist/{chunk-4NAR7FBA.js → chunk-3RI33YQN.js} +67 -1
- package/dist/chunk-3RI33YQN.js.map +1 -0
- package/dist/{chunk-SZAWDXQC.js → chunk-CJROYHSC.js} +3 -3
- package/dist/{chunk-DZCYW2WT.js → chunk-MX6V5F65.js} +2 -2
- package/dist/{chunk-S3TDDCS2.js → chunk-N5VXJ4I2.js} +151 -78
- package/dist/chunk-N5VXJ4I2.js.map +1 -0
- package/dist/{chunk-U4WPPEBH.js → chunk-NLFHMPUB.js} +2 -2
- package/dist/{chunk-5NNCGFQY.js → chunk-P6NSEG2S.js} +2 -2
- package/dist/{chunk-O56DM5GZ.js → chunk-QM6YOWHZ.js} +624 -57
- package/dist/chunk-QM6YOWHZ.js.map +1 -0
- package/dist/{chunk-US4IS6IV.js → chunk-RZNOSEMC.js} +2 -2
- package/dist/{chunk-F6PBS6WE.js → chunk-UFAMOUWL.js} +2 -2
- package/dist/codemode-operations.d.ts +5 -0
- package/dist/codex-token-resolver.d.ts +6 -2
- package/dist/connection-token-resolver.d.ts +8 -0
- package/dist/editable-artifact-durable-export.js +2 -2
- package/dist/editable-artifacts.js +3 -3
- package/dist/generated-images.d.ts +15 -0
- package/dist/index.d.ts +393 -91
- package/dist/index.js +9992 -6069
- package/dist/index.js.map +1 -1
- package/dist/insights.d.ts +9 -0
- package/dist/managed-auth-session-sets.js +3 -3
- package/dist/managed-user-setup.d.ts +3 -0
- package/dist/mcp-oauth.d.ts +80 -0
- package/dist/migrate.d.ts +1 -0
- package/dist/migrate.js +3 -1
- package/dist/model-catalog.d.ts +153 -0
- package/dist/model-context-snapshots.d.ts +20 -0
- package/dist/new-session-drafts.d.ts +12 -0
- package/dist/organization-membership-lifecycle.d.ts +8 -1
- package/dist/organization-model-providers.d.ts +101 -0
- package/dist/pack-components.d.ts +1 -0
- package/dist/pr-review.d.ts +9 -0
- package/dist/provision-roles.js +1 -1
- package/dist/runtime-posture.d.ts +8 -8
- package/dist/schema.d.ts +7708 -5050
- package/dist/schema.js +25 -1
- package/dist/session-background-commands.d.ts +18 -6
- package/dist/session-background-commands.js +15 -9
- package/dist/session-control.d.ts +37 -2
- package/dist/session-goal-pacing.d.ts +3 -6
- package/dist/session-queue-commands.d.ts +17 -0
- package/dist/session-tenancy.js +3 -3
- package/dist/tool-gateway-approvals.d.ts +31 -0
- package/dist/video-generation.js +3 -3
- package/dist/workspace-artifacts.d.ts +17 -3
- package/dist/xai-subscription.d.ts +8 -0
- package/drizzle/0387_bound_host_export_session_payloads.sql +165 -0
- package/drizzle/0388_sandbox_provider_deadline_interactions.sql +491 -0
- package/drizzle/0389_model_catalog_and_gateway_custom_models.sql +241 -0
- package/drizzle/0390_organization_model_provider_connections.sql +197 -0
- package/drizzle/0391_sandbox_provider_deadline_interaction_followup.sql +295 -0
- package/drizzle/0392_context_compaction_pending_observability.sql +198 -0
- package/drizzle/0393_workspace_memory_and_learning_defaults.sql +102 -0
- package/drizzle/0394_session_selected_skill_activation.sql +20 -0
- package/drizzle/0395_scheduled_task_unclaimed_occurrence_invalidation.sql +154 -0
- package/drizzle/0396_model_call_equivalent_credit_cost.sql +28 -0
- package/drizzle/0397_sandbox_deadline_rotation_preemption.sql +113 -0
- package/drizzle/0398_organization_workspace_management_entry.sql +206 -0
- package/drizzle/0399_additional_managed_organization_creation.sql +691 -0
- package/drizzle/0400_session_attempt_model_context_snapshots.sql +65 -0
- package/drizzle/0401_organization_user_setup_token_transport.sql +178 -0
- package/drizzle/0402_session_input_wait_and_background_command_results.sql +1023 -0
- package/drizzle/0403_codex_unconditional_credential_leasing.sql +181 -0
- package/drizzle/0404_mcp_oauth_authorization_server.sql +471 -0
- package/drizzle/0405_tool_gateway_approval_capabilities.sql +184 -0
- package/drizzle/0406_workspace_html_site_sources.sql +71 -0
- package/package.json +6 -6
- package/src/automations.ts +9 -1
- package/src/capability-integrations.ts +8 -0
- package/src/codemode-operations.ts +31 -21
- package/src/codex-token-resolver.ts +16 -6
- package/src/connection-token-resolver.ts +52 -3
- package/src/generated-images.ts +70 -6
- package/src/index.ts +3894 -994
- package/src/insights-model-bundle.ts +54 -5
- package/src/insights.ts +53 -7
- package/src/managed-user-setup.ts +14 -3
- package/src/mcp-oauth.ts +488 -0
- package/src/migrate.ts +9 -1
- package/src/model-catalog.ts +682 -0
- package/src/model-context-snapshots.ts +151 -0
- package/src/new-session-drafts.ts +66 -21
- package/src/organization-membership-lifecycle.ts +47 -5
- package/src/organization-model-providers.ts +614 -0
- package/src/pack-components.ts +15 -2
- package/src/pr-review.ts +19 -0
- package/src/provision-roles.ts +4 -0
- package/src/runtime-posture.ts +64 -0
- package/src/schema.ts +666 -61
- package/src/session-background-commands.ts +180 -78
- package/src/session-control.ts +181 -12
- package/src/session-goal-pacing.ts +4 -8
- package/src/session-queue-commands.ts +157 -82
- package/src/tool-gateway-approvals.ts +168 -0
- package/src/workspace-artifacts.ts +633 -178
- package/src/xai-subscription.ts +66 -14
- package/dist/chunk-4NAR7FBA.js.map +0 -1
- package/dist/chunk-6DPJA36C.js.map +0 -1
- package/dist/chunk-O56DM5GZ.js.map +0 -1
- package/dist/chunk-S3TDDCS2.js.map +0 -1
- /package/dist/{chunk-SZAWDXQC.js.map → chunk-CJROYHSC.js.map} +0 -0
- /package/dist/{chunk-DZCYW2WT.js.map → chunk-MX6V5F65.js.map} +0 -0
- /package/dist/{chunk-U4WPPEBH.js.map → chunk-NLFHMPUB.js.map} +0 -0
- /package/dist/{chunk-5NNCGFQY.js.map → chunk-P6NSEG2S.js.map} +0 -0
- /package/dist/{chunk-US4IS6IV.js.map → chunk-RZNOSEMC.js.map} +0 -0
- /package/dist/{chunk-F6PBS6WE.js.map → chunk-UFAMOUWL.js.map} +0 -0
package/src/schema.ts
CHANGED
|
@@ -8,8 +8,10 @@ import type {
|
|
|
8
8
|
McpPersonalConnectionDelegation,
|
|
9
9
|
PersonalResourceAttachmentIntent,
|
|
10
10
|
PersonalResourceAttachmentSummary,
|
|
11
|
+
Permission,
|
|
11
12
|
McpServerConnectionRef,
|
|
12
13
|
ModelContextContributionSummary,
|
|
14
|
+
ModelContextSnapshot,
|
|
13
15
|
RigProviderImages,
|
|
14
16
|
SessionMcpApprovalPolicy,
|
|
15
17
|
SessionGoalChangeKind,
|
|
@@ -17,6 +19,7 @@ import type {
|
|
|
17
19
|
SessionGoalSnapshot,
|
|
18
20
|
SlackUserLinkAccessRequest,
|
|
19
21
|
TimelineAnnotation,
|
|
22
|
+
ToolGatewayIdentity,
|
|
20
23
|
UserResourceDelegation,
|
|
21
24
|
XaiProviderAccountAuthoritySnapshotV1,
|
|
22
25
|
} from "@opengeni/contracts";
|
|
@@ -110,9 +113,12 @@ export const workspaces = pgTable(
|
|
|
110
113
|
// White-label agent persona template override. NULL means the deployment
|
|
111
114
|
// default (OPENGENI_AGENT_INSTRUCTIONS_TEMPLATE / DEFAULT_AGENT_INSTRUCTIONS).
|
|
112
115
|
agentInstructions: text("agent_instructions"),
|
|
113
|
-
// Growth-ready per-workspace settings bag (migration 0045).
|
|
114
|
-
//
|
|
115
|
-
settings: jsonb("settings")
|
|
116
|
+
// Growth-ready per-workspace settings bag (migration 0045). Migration 0393
|
|
117
|
+
// makes Memory enabled by default; explicit false remains authoritative.
|
|
118
|
+
settings: jsonb("settings")
|
|
119
|
+
.$type<Record<string, unknown>>()
|
|
120
|
+
.notNull()
|
|
121
|
+
.default({ memoryEnabled: true }),
|
|
116
122
|
// The workspace's default rig (migration 0047). NULL ⇒ no default; sessions
|
|
117
123
|
// created without an explicit rig ride no rig (today's behavior exactly). FK
|
|
118
124
|
// (-> rigs(id) ON DELETE SET NULL) lives in migration 0047, not a Drizzle
|
|
@@ -190,6 +196,11 @@ export const workspaceArtifacts = pgTable(
|
|
|
190
196
|
),
|
|
191
197
|
workspaceId: uniqueIndex("workspace_artifacts_workspace_id_uq").on(table.workspaceId, table.id),
|
|
192
198
|
list: index("workspace_artifacts_list_idx").on(table.workspaceId, table.updatedAt),
|
|
199
|
+
statusList: index("workspace_artifacts_status_list_idx").on(
|
|
200
|
+
table.workspaceId,
|
|
201
|
+
table.status,
|
|
202
|
+
table.updatedAt,
|
|
203
|
+
),
|
|
193
204
|
}),
|
|
194
205
|
);
|
|
195
206
|
|
|
@@ -209,6 +220,10 @@ export const workspaceArtifactVersions = pgTable(
|
|
|
209
220
|
contentType: text("content_type").$type<"text/html">().notNull().default("text/html"),
|
|
210
221
|
contentSha256: text("content_sha256").notNull(),
|
|
211
222
|
sizeBytes: integer("size_bytes").notNull(),
|
|
223
|
+
sourceKey: text("source_key"),
|
|
224
|
+
sourceSha256: text("source_sha256"),
|
|
225
|
+
sourceSizeBytes: integer("source_size_bytes"),
|
|
226
|
+
requestedTools: jsonb("requested_tools").$type<ToolGatewayIdentity[]>().notNull().default([]),
|
|
212
227
|
operationKey: text("operation_key").notNull(),
|
|
213
228
|
sourceSessionId: uuid("source_session_id"),
|
|
214
229
|
sourceTurnId: uuid("source_turn_id"),
|
|
@@ -269,10 +284,11 @@ export const workspaceArtifactEvents = pgTable(
|
|
|
269
284
|
.notNull()
|
|
270
285
|
.references(() => workspaces.id, { onDelete: "cascade" }),
|
|
271
286
|
artifactId: uuid("artifact_id").notNull(),
|
|
272
|
-
type: text("type").$type<"published" | "rolled_back">().notNull(),
|
|
287
|
+
type: text("type").$type<"published" | "rolled_back" | "archived" | "restored">().notNull(),
|
|
273
288
|
fromVersionId: uuid("from_version_id"),
|
|
274
289
|
toVersionId: uuid("to_version_id").notNull(),
|
|
275
290
|
operationKey: text("operation_key").notNull(),
|
|
291
|
+
requestDigest: text("request_digest"),
|
|
276
292
|
sourceSessionId: uuid("source_session_id"),
|
|
277
293
|
sourceTurnId: uuid("source_turn_id"),
|
|
278
294
|
sourceAttemptId: uuid("source_attempt_id"),
|
|
@@ -524,8 +540,12 @@ export const organizationProfileEvents = pgTable(
|
|
|
524
540
|
actorMembershipId: uuid("actor_membership_id").notNull(),
|
|
525
541
|
previousName: text("previous_name").notNull(),
|
|
526
542
|
requestedName: text("requested_name").notNull(),
|
|
527
|
-
expectedUpdatedAt: timestamp("expected_updated_at", {
|
|
528
|
-
|
|
543
|
+
expectedUpdatedAt: timestamp("expected_updated_at", {
|
|
544
|
+
withTimezone: true,
|
|
545
|
+
}).notNull(),
|
|
546
|
+
resultUpdatedAt: timestamp("result_updated_at", {
|
|
547
|
+
withTimezone: true,
|
|
548
|
+
}).notNull(),
|
|
529
549
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
530
550
|
},
|
|
531
551
|
(table) => ({
|
|
@@ -613,7 +633,9 @@ export const organizationPrivateSessionSettingEvents = pgTable(
|
|
|
613
633
|
expectedVersion: bigint("expected_version", { mode: "number" }).notNull(),
|
|
614
634
|
resultEnabled: boolean("result_enabled").notNull(),
|
|
615
635
|
resultVersion: bigint("result_version", { mode: "number" }).notNull(),
|
|
616
|
-
resultUpdatedAt: timestamp("result_updated_at", {
|
|
636
|
+
resultUpdatedAt: timestamp("result_updated_at", {
|
|
637
|
+
withTimezone: true,
|
|
638
|
+
}).notNull(),
|
|
617
639
|
changed: boolean("changed").notNull(),
|
|
618
640
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
619
641
|
},
|
|
@@ -751,7 +773,9 @@ export const organizationInvitationBindingEvents = pgTable(
|
|
|
751
773
|
.references(() => managedAccounts.id, { onDelete: "cascade" }),
|
|
752
774
|
invitationId: uuid("invitation_id").notNull(),
|
|
753
775
|
targetSubjectId: text("target_subject_id").notNull(),
|
|
754
|
-
resultingRevision: bigint("resulting_revision", {
|
|
776
|
+
resultingRevision: bigint("resulting_revision", {
|
|
777
|
+
mode: "number",
|
|
778
|
+
}).notNull(),
|
|
755
779
|
boundAt: timestamp("bound_at", { withTimezone: true }).notNull().defaultNow(),
|
|
756
780
|
},
|
|
757
781
|
(table) => ({
|
|
@@ -854,13 +878,19 @@ export const organizationUserRetentionDeletions = pgTable(
|
|
|
854
878
|
.notNull()
|
|
855
879
|
.references(() => managedAccounts.id, { onDelete: "cascade" }),
|
|
856
880
|
membershipId: uuid("membership_id").notNull(),
|
|
857
|
-
retentionUntil: timestamp("retention_until", {
|
|
881
|
+
retentionUntil: timestamp("retention_until", {
|
|
882
|
+
withTimezone: true,
|
|
883
|
+
}).notNull(),
|
|
858
884
|
state: text("state").notNull().default("claimed"),
|
|
859
885
|
claimOperationId: uuid("claim_operation_id").notNull(),
|
|
860
|
-
claimExpiresAt: timestamp("claim_expires_at", {
|
|
886
|
+
claimExpiresAt: timestamp("claim_expires_at", {
|
|
887
|
+
withTimezone: true,
|
|
888
|
+
}).notNull(),
|
|
861
889
|
attemptCount: integer("attempt_count").notNull().default(1),
|
|
862
890
|
databaseResult: jsonb("database_result").$type<Record<string, unknown>>(),
|
|
863
|
-
databaseFinalizedAt: timestamp("database_finalized_at", {
|
|
891
|
+
databaseFinalizedAt: timestamp("database_finalized_at", {
|
|
892
|
+
withTimezone: true,
|
|
893
|
+
}),
|
|
864
894
|
result: jsonb("result").$type<Record<string, unknown>>(),
|
|
865
895
|
completedAt: timestamp("completed_at", { withTimezone: true }),
|
|
866
896
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
@@ -1262,7 +1292,9 @@ export const codexSubscriptionCredentials = pgTable(
|
|
|
1262
1292
|
accountId: uuid("account_id")
|
|
1263
1293
|
.notNull()
|
|
1264
1294
|
.references(() => managedAccounts.id, { onDelete: "cascade" }),
|
|
1265
|
-
workspaceId: uuid("workspace_id").references(() => workspaces.id, {
|
|
1295
|
+
workspaceId: uuid("workspace_id").references(() => workspaces.id, {
|
|
1296
|
+
onDelete: "cascade",
|
|
1297
|
+
}),
|
|
1266
1298
|
organizationId: uuid("organization_id").references(() => managedAccounts.id, {
|
|
1267
1299
|
onDelete: "cascade",
|
|
1268
1300
|
}),
|
|
@@ -1400,7 +1432,6 @@ export const organizationCodexRotationSettings = pgTable(
|
|
|
1400
1432
|
.references(() => managedAccounts.id, { onDelete: "cascade" }),
|
|
1401
1433
|
activeCredentialId: uuid("active_credential_id"),
|
|
1402
1434
|
rotationEnabled: boolean("rotation_enabled").notNull().default(false),
|
|
1403
|
-
leaseRotationEnabled: boolean("lease_rotation_enabled").notNull().default(false),
|
|
1404
1435
|
rotationStrategy: text("rotation_strategy").notNull().default("sharded"),
|
|
1405
1436
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
1406
1437
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
@@ -1836,7 +1867,9 @@ export const connectionUseOnceConsumptionReceipts = pgTable(
|
|
|
1836
1867
|
.notNull()
|
|
1837
1868
|
.references(() => managedAccounts.id, { onDelete: "cascade" }),
|
|
1838
1869
|
authorityId: uuid("authority_id").notNull(),
|
|
1839
|
-
authorityGeneration: bigint("authority_generation", {
|
|
1870
|
+
authorityGeneration: bigint("authority_generation", {
|
|
1871
|
+
mode: "number",
|
|
1872
|
+
}).notNull(),
|
|
1840
1873
|
grantGeneration: bigint("grant_generation", { mode: "number" }).notNull(),
|
|
1841
1874
|
acceptedWorkKind: text("accepted_work_kind").notNull(),
|
|
1842
1875
|
acceptedWorkId: uuid("accepted_work_id").notNull(),
|
|
@@ -2621,7 +2654,9 @@ export const slackInteractionInbox = pgTable(
|
|
|
2621
2654
|
targetAccountId: uuid("target_account_id"),
|
|
2622
2655
|
targetWorkspaceId: uuid("target_workspace_id"),
|
|
2623
2656
|
routePromptId: uuid("route_prompt_id"),
|
|
2624
|
-
routePromptExpiresAt: timestamp("route_prompt_expires_at", {
|
|
2657
|
+
routePromptExpiresAt: timestamp("route_prompt_expires_at", {
|
|
2658
|
+
withTimezone: true,
|
|
2659
|
+
}),
|
|
2625
2660
|
processedAt: timestamp("processed_at", { withTimezone: true }),
|
|
2626
2661
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
2627
2662
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
@@ -3459,6 +3494,219 @@ export const integrationOauthStateNonces = pgTable(
|
|
|
3459
3494
|
}),
|
|
3460
3495
|
);
|
|
3461
3496
|
|
|
3497
|
+
export const mcpOauthClients = pgTable(
|
|
3498
|
+
"mcp_oauth_clients",
|
|
3499
|
+
{
|
|
3500
|
+
clientId: text("client_id").primaryKey(),
|
|
3501
|
+
redirectUris: jsonb("redirect_uris").$type<string[]>().notNull(),
|
|
3502
|
+
clientName: text("client_name"),
|
|
3503
|
+
tokenEndpointAuthMethod: text("token_endpoint_auth_method").notNull().default("none"),
|
|
3504
|
+
grantTypes: jsonb("grant_types")
|
|
3505
|
+
.$type<Array<"authorization_code" | "refresh_token">>()
|
|
3506
|
+
.notNull(),
|
|
3507
|
+
responseTypes: jsonb("response_types").$type<["code"]>().notNull(),
|
|
3508
|
+
registrationScopeHash: text("registration_scope_hash").notNull(),
|
|
3509
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3510
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
3511
|
+
},
|
|
3512
|
+
(table) => ({
|
|
3513
|
+
created: index("mcp_oauth_clients_created_idx").on(table.createdAt),
|
|
3514
|
+
scopeCreated: index("mcp_oauth_clients_scope_created_idx").on(
|
|
3515
|
+
table.registrationScopeHash,
|
|
3516
|
+
table.createdAt,
|
|
3517
|
+
),
|
|
3518
|
+
expires: index("mcp_oauth_clients_expires_idx").on(table.expiresAt, table.clientId),
|
|
3519
|
+
}),
|
|
3520
|
+
);
|
|
3521
|
+
|
|
3522
|
+
const mcpOauthGrantColumns = () => ({
|
|
3523
|
+
accountId: uuid("account_id")
|
|
3524
|
+
.notNull()
|
|
3525
|
+
.references(() => managedAccounts.id, { onDelete: "cascade" }),
|
|
3526
|
+
workspaceId: uuid("workspace_id")
|
|
3527
|
+
.notNull()
|
|
3528
|
+
.references(() => workspaces.id, { onDelete: "cascade" }),
|
|
3529
|
+
subjectId: text("subject_id").notNull(),
|
|
3530
|
+
resource: text("resource").notNull(),
|
|
3531
|
+
permissions: jsonb("permissions").$type<Permission[]>().notNull(),
|
|
3532
|
+
toolIdentities: jsonb("tool_identities").$type<ToolGatewayIdentity[]>().notNull(),
|
|
3533
|
+
});
|
|
3534
|
+
|
|
3535
|
+
export const mcpOauthAuthorizationRequests = pgTable(
|
|
3536
|
+
"mcp_oauth_authorization_requests",
|
|
3537
|
+
{
|
|
3538
|
+
requestHash: text("request_hash").primaryKey(),
|
|
3539
|
+
clientId: text("client_id")
|
|
3540
|
+
.notNull()
|
|
3541
|
+
.references(() => mcpOauthClients.clientId, { onDelete: "cascade" }),
|
|
3542
|
+
...mcpOauthGrantColumns(),
|
|
3543
|
+
redirectUri: text("redirect_uri").notNull(),
|
|
3544
|
+
codeChallenge: text("code_challenge").notNull(),
|
|
3545
|
+
state: text("state"),
|
|
3546
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
3547
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3548
|
+
},
|
|
3549
|
+
(table) => ({
|
|
3550
|
+
workspaceAccount: foreignKey({
|
|
3551
|
+
name: "mcp_oauth_authorization_requests_workspace_account_fk",
|
|
3552
|
+
columns: [table.workspaceId, table.accountId],
|
|
3553
|
+
foreignColumns: [workspaces.id, workspaces.accountId],
|
|
3554
|
+
}).onDelete("cascade"),
|
|
3555
|
+
expires: index("mcp_oauth_authorization_requests_expires_idx").on(table.expiresAt),
|
|
3556
|
+
}),
|
|
3557
|
+
);
|
|
3558
|
+
|
|
3559
|
+
export const mcpOauthAuthorizationCodes = pgTable(
|
|
3560
|
+
"mcp_oauth_authorization_codes",
|
|
3561
|
+
{
|
|
3562
|
+
codeHash: text("code_hash").primaryKey(),
|
|
3563
|
+
clientId: text("client_id")
|
|
3564
|
+
.notNull()
|
|
3565
|
+
.references(() => mcpOauthClients.clientId, { onDelete: "cascade" }),
|
|
3566
|
+
...mcpOauthGrantColumns(),
|
|
3567
|
+
redirectUri: text("redirect_uri").notNull(),
|
|
3568
|
+
codeChallenge: text("code_challenge").notNull(),
|
|
3569
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
3570
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3571
|
+
},
|
|
3572
|
+
(table) => ({
|
|
3573
|
+
workspaceAccount: foreignKey({
|
|
3574
|
+
name: "mcp_oauth_authorization_codes_workspace_account_fk",
|
|
3575
|
+
columns: [table.workspaceId, table.accountId],
|
|
3576
|
+
foreignColumns: [workspaces.id, workspaces.accountId],
|
|
3577
|
+
}).onDelete("cascade"),
|
|
3578
|
+
expires: index("mcp_oauth_authorization_codes_expires_idx").on(table.expiresAt),
|
|
3579
|
+
}),
|
|
3580
|
+
);
|
|
3581
|
+
|
|
3582
|
+
export const mcpOauthRefreshTokens = pgTable(
|
|
3583
|
+
"mcp_oauth_refresh_tokens",
|
|
3584
|
+
{
|
|
3585
|
+
tokenHash: text("token_hash").primaryKey(),
|
|
3586
|
+
familyId: uuid("family_id").notNull(),
|
|
3587
|
+
generation: integer("generation").notNull(),
|
|
3588
|
+
clientId: text("client_id")
|
|
3589
|
+
.notNull()
|
|
3590
|
+
.references(() => mcpOauthClients.clientId, { onDelete: "cascade" }),
|
|
3591
|
+
...mcpOauthGrantColumns(),
|
|
3592
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
3593
|
+
revokedAt: timestamp("revoked_at", { withTimezone: true }),
|
|
3594
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3595
|
+
},
|
|
3596
|
+
(table) => ({
|
|
3597
|
+
workspaceAccount: foreignKey({
|
|
3598
|
+
name: "mcp_oauth_refresh_tokens_workspace_account_fk",
|
|
3599
|
+
columns: [table.workspaceId, table.accountId],
|
|
3600
|
+
foreignColumns: [workspaces.id, workspaces.accountId],
|
|
3601
|
+
}).onDelete("cascade"),
|
|
3602
|
+
familyGeneration: uniqueIndex("mcp_oauth_refresh_tokens_family_generation_uq").on(
|
|
3603
|
+
table.familyId,
|
|
3604
|
+
table.generation,
|
|
3605
|
+
),
|
|
3606
|
+
expires: index("mcp_oauth_refresh_tokens_expires_idx").on(table.expiresAt),
|
|
3607
|
+
}),
|
|
3608
|
+
);
|
|
3609
|
+
|
|
3610
|
+
export const mcpOauthAccessTokens = pgTable(
|
|
3611
|
+
"mcp_oauth_access_tokens",
|
|
3612
|
+
{
|
|
3613
|
+
tokenHash: text("token_hash").primaryKey(),
|
|
3614
|
+
refreshFamilyId: uuid("refresh_family_id").notNull(),
|
|
3615
|
+
refreshGeneration: integer("refresh_generation").notNull(),
|
|
3616
|
+
clientId: text("client_id")
|
|
3617
|
+
.notNull()
|
|
3618
|
+
.references(() => mcpOauthClients.clientId, { onDelete: "cascade" }),
|
|
3619
|
+
...mcpOauthGrantColumns(),
|
|
3620
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
3621
|
+
revokedAt: timestamp("revoked_at", { withTimezone: true }),
|
|
3622
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3623
|
+
},
|
|
3624
|
+
(table) => ({
|
|
3625
|
+
workspaceAccount: foreignKey({
|
|
3626
|
+
name: "mcp_oauth_access_tokens_workspace_account_fk",
|
|
3627
|
+
columns: [table.workspaceId, table.accountId],
|
|
3628
|
+
foreignColumns: [workspaces.id, workspaces.accountId],
|
|
3629
|
+
}).onDelete("cascade"),
|
|
3630
|
+
family: index("mcp_oauth_access_tokens_family_idx").on(
|
|
3631
|
+
table.refreshFamilyId,
|
|
3632
|
+
table.refreshGeneration,
|
|
3633
|
+
),
|
|
3634
|
+
expires: index("mcp_oauth_access_tokens_expires_idx").on(table.expiresAt),
|
|
3635
|
+
}),
|
|
3636
|
+
);
|
|
3637
|
+
|
|
3638
|
+
export const toolGatewayApprovalCapabilities = pgTable(
|
|
3639
|
+
"tool_gateway_approval_capabilities",
|
|
3640
|
+
{
|
|
3641
|
+
tokenHash: text("token_hash").primaryKey(),
|
|
3642
|
+
accountId: uuid("account_id")
|
|
3643
|
+
.notNull()
|
|
3644
|
+
.references(() => managedAccounts.id, { onDelete: "cascade" }),
|
|
3645
|
+
workspaceId: uuid("workspace_id")
|
|
3646
|
+
.notNull()
|
|
3647
|
+
.references(() => workspaces.id, { onDelete: "cascade" }),
|
|
3648
|
+
subjectId: text("subject_id").notNull(),
|
|
3649
|
+
operationId: uuid("operation_id").notNull(),
|
|
3650
|
+
catalogDigest: text("catalog_digest").notNull(),
|
|
3651
|
+
serverId: text("server_id").notNull(),
|
|
3652
|
+
toolName: text("tool_name").notNull(),
|
|
3653
|
+
argumentsDigest: text("arguments_digest").notNull(),
|
|
3654
|
+
authorityDigest: text("authority_digest").notNull(),
|
|
3655
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
3656
|
+
consumedAt: timestamp("consumed_at", { withTimezone: true }),
|
|
3657
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3658
|
+
},
|
|
3659
|
+
(table) => ({
|
|
3660
|
+
workspaceAccount: foreignKey({
|
|
3661
|
+
name: "tool_gateway_approval_capabilities_workspace_account_fk",
|
|
3662
|
+
columns: [table.workspaceId, table.accountId],
|
|
3663
|
+
foreignColumns: [workspaces.id, workspaces.accountId],
|
|
3664
|
+
}).onDelete("cascade"),
|
|
3665
|
+
operation: uniqueIndex("tool_gateway_approval_capabilities_operation_uq").on(
|
|
3666
|
+
table.workspaceId,
|
|
3667
|
+
table.subjectId,
|
|
3668
|
+
table.operationId,
|
|
3669
|
+
),
|
|
3670
|
+
expires: index("tool_gateway_approval_capabilities_expires_idx").on(
|
|
3671
|
+
table.expiresAt,
|
|
3672
|
+
table.tokenHash,
|
|
3673
|
+
),
|
|
3674
|
+
liveSubjectExpiry: index("tool_gateway_approval_capabilities_live_subject_expiry_idx")
|
|
3675
|
+
.on(table.workspaceId, table.subjectId, table.expiresAt, table.tokenHash)
|
|
3676
|
+
.where(sql`${table.consumedAt} is null`),
|
|
3677
|
+
tokenHashValid: check(
|
|
3678
|
+
"tool_gateway_approval_capabilities_token_hash_chk",
|
|
3679
|
+
sql`${table.tokenHash} ~ '^[0-9a-f]{64}$'`,
|
|
3680
|
+
),
|
|
3681
|
+
catalogDigestValid: check(
|
|
3682
|
+
"tool_gateway_approval_capabilities_catalog_digest_chk",
|
|
3683
|
+
sql`${table.catalogDigest} ~ '^[0-9a-f]{64}$'`,
|
|
3684
|
+
),
|
|
3685
|
+
argumentsDigestValid: check(
|
|
3686
|
+
"tool_gateway_approval_capabilities_arguments_digest_chk",
|
|
3687
|
+
sql`${table.argumentsDigest} ~ '^[0-9a-f]{64}$'`,
|
|
3688
|
+
),
|
|
3689
|
+
authorityDigestValid: check(
|
|
3690
|
+
"tool_gateway_approval_capabilities_authority_digest_chk",
|
|
3691
|
+
sql`${table.authorityDigest} ~ '^[0-9a-f]{64}$'`,
|
|
3692
|
+
),
|
|
3693
|
+
subjectValid: check(
|
|
3694
|
+
"tool_gateway_approval_capabilities_subject_chk",
|
|
3695
|
+
sql`length(btrim(${table.subjectId})) between 1 and 1024`,
|
|
3696
|
+
),
|
|
3697
|
+
identityValid: check(
|
|
3698
|
+
"tool_gateway_approval_capabilities_identity_chk",
|
|
3699
|
+
sql`length(${table.serverId}) between 1 and 256
|
|
3700
|
+
and length(${table.toolName}) between 1 and 512`,
|
|
3701
|
+
),
|
|
3702
|
+
expiryValid: check(
|
|
3703
|
+
"tool_gateway_approval_capabilities_expiry_chk",
|
|
3704
|
+
sql`${table.expiresAt} > ${table.createdAt}
|
|
3705
|
+
and ${table.expiresAt} <= ${table.createdAt} + interval '10 minutes'`,
|
|
3706
|
+
),
|
|
3707
|
+
}),
|
|
3708
|
+
);
|
|
3709
|
+
|
|
3462
3710
|
// Per-workspace Codex account selection (the ACTIVE pointer) + P3 rotation
|
|
3463
3711
|
// forward-compat. One row per workspace. The only P1-load-bearing column is
|
|
3464
3712
|
// activeCredentialId — the account a session runs on when it has no pin. NULL ⇒
|
|
@@ -3478,14 +3726,10 @@ export const codexRotationSettings = pgTable(
|
|
|
3478
3726
|
.notNull()
|
|
3479
3727
|
.references(() => workspaces.id, { onDelete: "cascade" }),
|
|
3480
3728
|
activeCredentialId: uuid("active_credential_id"),
|
|
3481
|
-
//
|
|
3482
|
-
// only
|
|
3483
|
-
//
|
|
3729
|
+
// User-owned account-selection policy. When false, every new turn may lease
|
|
3730
|
+
// only the active credential and waits if that credential is unavailable.
|
|
3731
|
+
// When true, the allocator may choose another eligible account.
|
|
3484
3732
|
rotationEnabled: boolean("rotation_enabled").notNull().default(false),
|
|
3485
|
-
// Revision-aware allocator cutover. Only migration-compatible API/worker
|
|
3486
|
-
// code reads this bit; old binaries safely ignore it and keep the legacy
|
|
3487
|
-
// pin/rotation policy.
|
|
3488
|
-
leaseRotationEnabled: boolean("lease_rotation_enabled").notNull().default(false),
|
|
3489
3733
|
rotationStrategy: text("rotation_strategy").notNull().default("sharded"), // sharded-rotation policy: legacy residue; behavior is always sharded
|
|
3490
3734
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
3491
3735
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
@@ -3531,9 +3775,9 @@ export const workspaceModelPolicies = pgTable(
|
|
|
3531
3775
|
// insertion happen atomically while codex_rotation_settings is locked FOR
|
|
3532
3776
|
// UPDATE, so concurrent replicas in the SAME workspace see one another's
|
|
3533
3777
|
// assignments before choosing. Workspaces never share or correlate lease state.
|
|
3534
|
-
// The
|
|
3535
|
-
//
|
|
3536
|
-
//
|
|
3778
|
+
// The turn workspace FK is declared in migration 0053 and the account/credential
|
|
3779
|
+
// FK is installed in migration 0381 (sessionTurns is defined later in this
|
|
3780
|
+
// module).
|
|
3537
3781
|
export const codexCredentialLeases = pgTable(
|
|
3538
3782
|
"codex_credential_leases",
|
|
3539
3783
|
{
|
|
@@ -3546,9 +3790,12 @@ export const codexCredentialLeases = pgTable(
|
|
|
3546
3790
|
.references(() => workspaces.id, { onDelete: "cascade" }),
|
|
3547
3791
|
credentialId: uuid("credential_id").notNull(),
|
|
3548
3792
|
turnId: uuid("turn_id").notNull(),
|
|
3549
|
-
//
|
|
3550
|
-
// durable turn
|
|
3551
|
-
//
|
|
3793
|
+
// Durable turn-attempt fence. The worker holder includes the
|
|
3794
|
+
// durable workflow turn-attempt identity; dispatchId remains a separate
|
|
3795
|
+
// attempt/audit identity. A successor dispatch for the same durable turn
|
|
3796
|
+
// replaces holderId and increments generation atomically; stale/zombie
|
|
3797
|
+
// heartbeats and releases must match both values. Generation may restart
|
|
3798
|
+
// at 1 after an expired row is reaped, so holder identity cannot be reused.
|
|
3552
3799
|
holderId: text("holder_id").notNull(),
|
|
3553
3800
|
generation: integer("generation").notNull().default(1),
|
|
3554
3801
|
leasedUntil: timestamp("leased_until", { withTimezone: true }).notNull(),
|
|
@@ -3561,7 +3808,6 @@ export const codexCredentialLeases = pgTable(
|
|
|
3561
3808
|
table.turnId,
|
|
3562
3809
|
),
|
|
3563
3810
|
activeCredential: index("codex_credential_leases_active_credential_idx").on(
|
|
3564
|
-
table.workspaceId,
|
|
3565
3811
|
table.credentialId,
|
|
3566
3812
|
table.leasedUntil,
|
|
3567
3813
|
),
|
|
@@ -3965,6 +4211,14 @@ export const sessions = pgTable(
|
|
|
3965
4211
|
nestedAgentDepthPolicySessionId: uuid("nested_agent_depth_policy_session_id"),
|
|
3966
4212
|
temporalWorkflowId: text("temporal_workflow_id"),
|
|
3967
4213
|
activeTurnId: uuid("active_turn_id"),
|
|
4214
|
+
// Session-scoped out-of-turn wait (`wait_for_input`). The exact declaring
|
|
4215
|
+
// turn and absolute deadline are durable PostgreSQL authority; workflow
|
|
4216
|
+
// signals and timers only nudge reevaluation. A newer finished turn or a
|
|
4217
|
+
// terminal timeout input retires all four fields together.
|
|
4218
|
+
inputWaitTurnId: uuid("input_wait_turn_id"),
|
|
4219
|
+
inputWaitUntil: timestamp("input_wait_until", { withTimezone: true }),
|
|
4220
|
+
inputWaitReason: text("input_wait_reason"),
|
|
4221
|
+
inputWaitSetAt: timestamp("input_wait_set_at", { withTimezone: true }),
|
|
3968
4222
|
// Actual input tokens reported for the latest authoritative ordinary model
|
|
3969
4223
|
// call. Compaction/context clearing invalidates it to null; local history
|
|
3970
4224
|
// estimates must never be stored here.
|
|
@@ -4122,6 +4376,21 @@ export const sessions = pgTable(
|
|
|
4122
4376
|
sql`${table.initialModelContext} is null
|
|
4123
4377
|
or opengeni_private.model_context_value_valid(${table.initialModelContext})`,
|
|
4124
4378
|
),
|
|
4379
|
+
inputWaitValid: check(
|
|
4380
|
+
"sessions_input_wait_check",
|
|
4381
|
+
sql`(
|
|
4382
|
+
${table.inputWaitTurnId} is null
|
|
4383
|
+
and ${table.inputWaitUntil} is null
|
|
4384
|
+
and ${table.inputWaitReason} is null
|
|
4385
|
+
and ${table.inputWaitSetAt} is null
|
|
4386
|
+
) or (
|
|
4387
|
+
${table.inputWaitTurnId} is not null
|
|
4388
|
+
and ${table.inputWaitUntil} is not null
|
|
4389
|
+
and ${table.inputWaitReason} is not null
|
|
4390
|
+
and octet_length(btrim(${table.inputWaitReason})) between 1 and 2048
|
|
4391
|
+
and ${table.inputWaitSetAt} is not null
|
|
4392
|
+
)`,
|
|
4393
|
+
),
|
|
4125
4394
|
}),
|
|
4126
4395
|
);
|
|
4127
4396
|
|
|
@@ -6185,7 +6454,9 @@ export const turnPersonalResourceSnapshots = pgTable(
|
|
|
6185
6454
|
mode: "number",
|
|
6186
6455
|
}).notNull(),
|
|
6187
6456
|
authorityId: uuid("authority_id").notNull(),
|
|
6188
|
-
authorityGeneration: bigint("authority_generation", {
|
|
6457
|
+
authorityGeneration: bigint("authority_generation", {
|
|
6458
|
+
mode: "number",
|
|
6459
|
+
}).notNull(),
|
|
6189
6460
|
grantId: uuid("grant_id").notNull(),
|
|
6190
6461
|
grantGeneration: bigint("grant_generation", { mode: "number" }).notNull(),
|
|
6191
6462
|
grantMode: text("grant_mode").notNull(),
|
|
@@ -6197,7 +6468,9 @@ export const turnPersonalResourceSnapshots = pgTable(
|
|
|
6197
6468
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
6198
6469
|
},
|
|
6199
6470
|
(table) => ({
|
|
6200
|
-
pk: primaryKey({
|
|
6471
|
+
pk: primaryKey({
|
|
6472
|
+
columns: [table.turnId, table.resourceKind, table.resourceId],
|
|
6473
|
+
}),
|
|
6201
6474
|
receipt: foreignKey({
|
|
6202
6475
|
name: "turn_personal_resource_snapshots_receipt_fk",
|
|
6203
6476
|
columns: [table.turnId],
|
|
@@ -6246,7 +6519,9 @@ export const turnPersonalResourceOnceReceipts = pgTable(
|
|
|
6246
6519
|
turnId: uuid("turn_id").notNull(),
|
|
6247
6520
|
accountId: uuid("account_id").notNull(),
|
|
6248
6521
|
authorityId: uuid("authority_id").notNull(),
|
|
6249
|
-
authorityGeneration: bigint("authority_generation", {
|
|
6522
|
+
authorityGeneration: bigint("authority_generation", {
|
|
6523
|
+
mode: "number",
|
|
6524
|
+
}).notNull(),
|
|
6250
6525
|
grantGeneration: bigint("grant_generation", { mode: "number" }).notNull(),
|
|
6251
6526
|
consumedAt: timestamp("consumed_at", { withTimezone: true }).notNull().defaultNow(),
|
|
6252
6527
|
},
|
|
@@ -6541,7 +6816,9 @@ export const turnConnectionAuthoritySnapshots = pgTable(
|
|
|
6541
6816
|
turnId: uuid("turn_id").notNull(),
|
|
6542
6817
|
serverId: text("server_id").notNull(),
|
|
6543
6818
|
connectionId: uuid("connection_id").notNull(),
|
|
6544
|
-
connectionGeneration: bigint("connection_generation", {
|
|
6819
|
+
connectionGeneration: bigint("connection_generation", {
|
|
6820
|
+
mode: "number",
|
|
6821
|
+
}).notNull(),
|
|
6545
6822
|
originWorkspaceId: uuid("origin_workspace_id").notNull(),
|
|
6546
6823
|
providerDomain: text("provider_domain").notNull(),
|
|
6547
6824
|
connectionKind: text("connection_kind").notNull(),
|
|
@@ -6742,6 +7019,59 @@ export const sessionAttemptToolCatalogs = pgTable(
|
|
|
6742
7019
|
}),
|
|
6743
7020
|
);
|
|
6744
7021
|
|
|
7022
|
+
export const sessionAttemptModelContextSnapshots = pgTable(
|
|
7023
|
+
"session_attempt_model_context_snapshots",
|
|
7024
|
+
{
|
|
7025
|
+
attemptId: uuid("attempt_id").primaryKey(),
|
|
7026
|
+
accountId: uuid("account_id").notNull(),
|
|
7027
|
+
workspaceId: uuid("workspace_id").notNull(),
|
|
7028
|
+
sessionId: uuid("session_id").notNull(),
|
|
7029
|
+
turnId: uuid("turn_id").notNull(),
|
|
7030
|
+
executionGeneration: integer("execution_generation").notNull(),
|
|
7031
|
+
requestIndex: integer("request_index").notNull(),
|
|
7032
|
+
capturedAt: timestamp("captured_at", { withTimezone: true }).notNull(),
|
|
7033
|
+
snapshot: jsonb("snapshot").$type<ModelContextSnapshot>().notNull(),
|
|
7034
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
|
|
7035
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(),
|
|
7036
|
+
},
|
|
7037
|
+
(table) => ({
|
|
7038
|
+
attemptOwner: foreignKey({
|
|
7039
|
+
name: "session_attempt_model_context_snapshots_attempt_owner_fk",
|
|
7040
|
+
columns: [table.accountId, table.workspaceId, table.sessionId, table.turnId, table.attemptId],
|
|
7041
|
+
foreignColumns: [
|
|
7042
|
+
sessionTurnAttempts.accountId,
|
|
7043
|
+
sessionTurnAttempts.workspaceId,
|
|
7044
|
+
sessionTurnAttempts.sessionId,
|
|
7045
|
+
sessionTurnAttempts.turnId,
|
|
7046
|
+
sessionTurnAttempts.id,
|
|
7047
|
+
],
|
|
7048
|
+
}).onDelete("cascade"),
|
|
7049
|
+
sessionLatest: index("session_attempt_model_context_snapshots_session_idx").on(
|
|
7050
|
+
table.workspaceId,
|
|
7051
|
+
table.sessionId,
|
|
7052
|
+
table.capturedAt.desc(),
|
|
7053
|
+
),
|
|
7054
|
+
requestIndexValid: check(
|
|
7055
|
+
"session_attempt_model_context_snapshots_request_index_check",
|
|
7056
|
+
sql`${table.requestIndex} > 0 and ${table.executionGeneration} > 0`,
|
|
7057
|
+
),
|
|
7058
|
+
snapshotSize: check(
|
|
7059
|
+
"session_attempt_model_context_snapshots_size_check",
|
|
7060
|
+
sql`octet_length(${table.snapshot}::text) between 2 and 16777216`,
|
|
7061
|
+
),
|
|
7062
|
+
snapshotIdentity: check(
|
|
7063
|
+
"session_attempt_model_context_snapshots_identity_check",
|
|
7064
|
+
sql`jsonb_typeof(${table.snapshot}) = 'object'
|
|
7065
|
+
and ${table.snapshot} ?& array['version', 'capturedAt', 'source', 'requestIndex', 'instructions', 'layers', 'tools', 'skills', 'tokens']::text[]
|
|
7066
|
+
and (${table.snapshot}->>'version')::integer = 1
|
|
7067
|
+
and ${table.snapshot}->>'source' = 'model_request'
|
|
7068
|
+
and jsonb_typeof(${table.snapshot}->'layers') = 'array'
|
|
7069
|
+
and jsonb_typeof(${table.snapshot}->'tools') = 'array'
|
|
7070
|
+
and jsonb_typeof(${table.snapshot}->'skills') = 'array'`,
|
|
7071
|
+
),
|
|
7072
|
+
}),
|
|
7073
|
+
);
|
|
7074
|
+
|
|
6745
7075
|
// Durable idempotency and outcome journal for calls made programmatically from
|
|
6746
7076
|
// an attempt's sandbox. The active worker executes these through the exact same
|
|
6747
7077
|
// in-memory AttemptToolEnvironment as model MCP calls.
|
|
@@ -7080,9 +7410,21 @@ export const sessionCommandReceipts = pgTable(
|
|
|
7080
7410
|
table.targetSessionId,
|
|
7081
7411
|
table.createdAt,
|
|
7082
7412
|
),
|
|
7413
|
+
promptActorOperation: index("session_command_receipts_prompt_actor_operation_idx")
|
|
7414
|
+
.on(
|
|
7415
|
+
table.workspaceId,
|
|
7416
|
+
table.actorType,
|
|
7417
|
+
table.actorSubjectId,
|
|
7418
|
+
table.actorAttemptId,
|
|
7419
|
+
table.operationKey,
|
|
7420
|
+
)
|
|
7421
|
+
.where(sql`${table.action} in ('prompt.send', 'prompt.steer')`),
|
|
7083
7422
|
goalUpdateOperation: uniqueIndex("session_command_receipts_goal_update_operation_uq")
|
|
7084
7423
|
.on(table.workspaceId, table.action, table.targetSessionId, table.operationKey)
|
|
7085
7424
|
.where(sql`${table.action} = 'goal.update'`),
|
|
7425
|
+
waitForInputOperation: uniqueIndex("session_command_receipts_wait_for_input_operation_uq")
|
|
7426
|
+
.on(table.workspaceId, table.action, table.targetSessionId, table.operationKey)
|
|
7427
|
+
.where(sql`${table.action} = 'session.wait_for_input'`),
|
|
7086
7428
|
actorValid: check(
|
|
7087
7429
|
"session_command_receipts_actor_check",
|
|
7088
7430
|
sql`(
|
|
@@ -7357,7 +7699,7 @@ export const sessionSystemUpdates = pgTable(
|
|
|
7357
7699
|
(table) => ({
|
|
7358
7700
|
kindValid: check(
|
|
7359
7701
|
"system_updates_kind_check",
|
|
7360
|
-
sql`${table.kind} in ('scheduled_occurrence', 'goal_continuation', 'agent_message', 'agent_steer_instruction', 'child_terminal_result', 'media_generation_result', 'child_requires_action', 'child_requires_action_resolved', 'child_paused', 'child_waiting_capacity', 'child_progress')`,
|
|
7702
|
+
sql`${table.kind} in ('scheduled_occurrence', 'goal_continuation', 'agent_message', 'agent_steer_instruction', 'session_wait_timeout', 'background_command_result', 'child_terminal_result', 'media_generation_result', 'child_requires_action', 'child_requires_action_resolved', 'child_paused', 'child_waiting_capacity', 'child_progress')`,
|
|
7361
7703
|
),
|
|
7362
7704
|
payloadKindValid: check(
|
|
7363
7705
|
"system_updates_payload_kind_check",
|
|
@@ -7569,15 +7911,10 @@ export const sessionGoals = pgTable(
|
|
|
7569
7911
|
})
|
|
7570
7912
|
.notNull()
|
|
7571
7913
|
.default(0),
|
|
7572
|
-
//
|
|
7573
|
-
//
|
|
7574
|
-
// the
|
|
7575
|
-
|
|
7576
|
-
// four columns together.
|
|
7577
|
-
continuationHoldTurnId: uuid("continuation_hold_turn_id"),
|
|
7578
|
-
continuationHoldUntil: timestamp("continuation_hold_until", { withTimezone: true }),
|
|
7579
|
-
continuationHoldReason: text("continuation_hold_reason"),
|
|
7580
|
-
continuationHoldSetAt: timestamp("continuation_hold_set_at", { withTimezone: true }),
|
|
7914
|
+
// A terminal condition can keep the goal active while making unchanged
|
|
7915
|
+
// autonomous input unsafe. The fence is honored only while this remains
|
|
7916
|
+
// the newest finished turn; newer work or a goal mutation clears it.
|
|
7917
|
+
continuationSuppressedTurnId: uuid("continuation_suppressed_turn_id"),
|
|
7581
7918
|
metadata: jsonb("metadata").$type<Record<string, unknown>>().notNull().default({}),
|
|
7582
7919
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
7583
7920
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
@@ -7596,10 +7933,6 @@ export const sessionGoals = pgTable(
|
|
|
7596
7933
|
"session_goals_continuation_revision_check",
|
|
7597
7934
|
sql`${table.continuationWakeRevision} >= 0 and ${table.continuationObservedRevision} >= 0 and ${table.continuationObservedRevision} <= ${table.continuationWakeRevision} and ${table.continuationWakeRevision} <= 9007199254740991 and ${table.continuationObservedRevision} <= 9007199254740991`,
|
|
7598
7935
|
),
|
|
7599
|
-
continuationHoldValid: check(
|
|
7600
|
-
"session_goals_continuation_hold_check",
|
|
7601
|
-
sql`(${table.continuationHoldTurnId} is null and ${table.continuationHoldUntil} is null and ${table.continuationHoldReason} is null and ${table.continuationHoldSetAt} is null) or (${table.continuationHoldTurnId} is not null and ${table.continuationHoldUntil} is not null and ${table.continuationHoldSetAt} is not null and (${table.continuationHoldReason} is null or octet_length(${table.continuationHoldReason}) <= 2048))`,
|
|
7602
|
-
),
|
|
7603
7936
|
}),
|
|
7604
7937
|
);
|
|
7605
7938
|
|
|
@@ -7739,7 +8072,7 @@ export const codexCapacityWaiters = pgTable(
|
|
|
7739
8072
|
policyHash: text("policy_hash"),
|
|
7740
8073
|
earliestResetAt: timestamp("earliest_reset_at", { withTimezone: true }),
|
|
7741
8074
|
nextCheckAt: timestamp("next_check_at", { withTimezone: true }).notNull(),
|
|
7742
|
-
resetKind: text("reset_kind").notNull(), // authoritative | bounded_refresh
|
|
8075
|
+
resetKind: text("reset_kind").notNull(), // authoritative | bounded_refresh | mutation_only
|
|
7743
8076
|
refreshAttempt: integer("refresh_attempt").notNull().default(0),
|
|
7744
8077
|
// Coalescing outbox generation. Every eligibility-affecting mutation bumps
|
|
7745
8078
|
// wakeRevision. Duplicate/lost Temporal signals are harmless because only
|
|
@@ -8852,7 +9185,9 @@ export const sandboxWorkspaceMutationAdmissions = pgTable(
|
|
|
8852
9185
|
// authorization revision observed at admission. The revision is audit
|
|
8853
9186
|
// evidence: a role change is not a revocation and must not fence a writer.
|
|
8854
9187
|
initiatorOrganizationMembershipId: uuid("initiator_organization_membership_id"),
|
|
8855
|
-
initiatorAuthorizationRevision: bigint("initiator_authorization_revision", {
|
|
9188
|
+
initiatorAuthorizationRevision: bigint("initiator_authorization_revision", {
|
|
9189
|
+
mode: "number",
|
|
9190
|
+
}),
|
|
8856
9191
|
// Session tenancy authority observed when the operation was admitted; the
|
|
8857
9192
|
// same triple `session_turn_attempts` freezes for a turn.
|
|
8858
9193
|
authorityEpoch: integer("authority_epoch"),
|
|
@@ -9074,7 +9409,9 @@ export const sandboxRetainedProcesses = pgTable(
|
|
|
9074
9409
|
initiatorSubjectId: text("initiator_subject_id").notNull().default("unattributed-legacy"),
|
|
9075
9410
|
initiatingHumanSubjectId: text("initiating_human_subject_id"),
|
|
9076
9411
|
initiatorOrganizationMembershipId: uuid("initiator_organization_membership_id"),
|
|
9077
|
-
initiatorAuthorizationRevision: bigint("initiator_authorization_revision", {
|
|
9412
|
+
initiatorAuthorizationRevision: bigint("initiator_authorization_revision", {
|
|
9413
|
+
mode: "number",
|
|
9414
|
+
}),
|
|
9078
9415
|
authorityEpoch: integer("authority_epoch"),
|
|
9079
9416
|
authorityVisibility: text("authority_visibility", {
|
|
9080
9417
|
enum: ["user_private", "workspace_shared"],
|
|
@@ -9333,7 +9670,9 @@ export const sessionBackgroundCommands = pgTable(
|
|
|
9333
9670
|
accountId: uuid("account_id").notNull(),
|
|
9334
9671
|
workspaceId: uuid("workspace_id").notNull(),
|
|
9335
9672
|
sessionId: uuid("session_id").notNull(),
|
|
9336
|
-
provider: text("provider", {
|
|
9673
|
+
provider: text("provider", {
|
|
9674
|
+
enum: ["managed", "connected_machine"],
|
|
9675
|
+
}).notNull(),
|
|
9337
9676
|
state: text("state", { enum: ["running", "stopping", "exited", "lost"] })
|
|
9338
9677
|
.notNull()
|
|
9339
9678
|
.default("running"),
|
|
@@ -9351,13 +9690,19 @@ export const sessionBackgroundCommands = pgTable(
|
|
|
9351
9690
|
settledAt: timestamp("settled_at", { withTimezone: true }),
|
|
9352
9691
|
reconcileAfter: timestamp("reconcile_after", { withTimezone: true }).notNull().defaultNow(),
|
|
9353
9692
|
reconcileClaimId: uuid("reconcile_claim_id"),
|
|
9354
|
-
reconcileClaimedAt: timestamp("reconcile_claimed_at", {
|
|
9693
|
+
reconcileClaimedAt: timestamp("reconcile_claimed_at", {
|
|
9694
|
+
withTimezone: true,
|
|
9695
|
+
}),
|
|
9355
9696
|
reconcileAttempts: integer("reconcile_attempts").notNull().default(0),
|
|
9356
9697
|
lastReconcileOutcome: text("last_reconcile_outcome"),
|
|
9357
|
-
reconcileProofOutcome: text("reconcile_proof_outcome", {
|
|
9698
|
+
reconcileProofOutcome: text("reconcile_proof_outcome", {
|
|
9699
|
+
enum: ["exited", "lost"],
|
|
9700
|
+
}),
|
|
9358
9701
|
reconcileProofExitCode: integer("reconcile_proof_exit_code"),
|
|
9359
9702
|
reconcileProofReason: text("reconcile_proof_reason"),
|
|
9360
|
-
reconcileProofObservedAt: timestamp("reconcile_proof_observed_at", {
|
|
9703
|
+
reconcileProofObservedAt: timestamp("reconcile_proof_observed_at", {
|
|
9704
|
+
withTimezone: true,
|
|
9705
|
+
}),
|
|
9361
9706
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
9362
9707
|
},
|
|
9363
9708
|
(table) => ({
|
|
@@ -10597,12 +10942,18 @@ export const prReviewAppRegistrations = pgTable(
|
|
|
10597
10942
|
providerAccountType: text("provider_account_type"),
|
|
10598
10943
|
githubActorId: text("github_actor_id"),
|
|
10599
10944
|
authorityKind: text("authority_kind"),
|
|
10600
|
-
authorityCheckedAt: timestamp("authority_checked_at", {
|
|
10601
|
-
|
|
10945
|
+
authorityCheckedAt: timestamp("authority_checked_at", {
|
|
10946
|
+
withTimezone: true,
|
|
10947
|
+
}),
|
|
10948
|
+
authorityExpiresAt: timestamp("authority_expires_at", {
|
|
10949
|
+
withTimezone: true,
|
|
10950
|
+
}),
|
|
10602
10951
|
authorityNonce: text("authority_nonce"),
|
|
10603
10952
|
credentialKind: text("credential_kind").notNull(),
|
|
10604
10953
|
credentialEncrypted: text("credential_encrypted"),
|
|
10605
|
-
accessTokenExpiresAt: timestamp("access_token_expires_at", {
|
|
10954
|
+
accessTokenExpiresAt: timestamp("access_token_expires_at", {
|
|
10955
|
+
withTimezone: true,
|
|
10956
|
+
}),
|
|
10606
10957
|
webhookAuthKind: text("webhook_auth_kind").notNull(),
|
|
10607
10958
|
webhookUsername: text("webhook_username"),
|
|
10608
10959
|
status: text("status").notNull().default("active"),
|
|
@@ -10748,7 +11099,9 @@ export const prReviewManagedGithubAuthorityNonces = pgTable(
|
|
|
10748
11099
|
.notNull()
|
|
10749
11100
|
.references(() => workspaces.id, { onDelete: "cascade" }),
|
|
10750
11101
|
installationId: text("installation_id").notNull(),
|
|
10751
|
-
authorityExpiresAt: timestamp("authority_expires_at", {
|
|
11102
|
+
authorityExpiresAt: timestamp("authority_expires_at", {
|
|
11103
|
+
withTimezone: true,
|
|
11104
|
+
}).notNull(),
|
|
10752
11105
|
consumedAt: timestamp("consumed_at", { withTimezone: true }).notNull().defaultNow(),
|
|
10753
11106
|
},
|
|
10754
11107
|
(table) => ({
|
|
@@ -10930,6 +11283,9 @@ export const modelCallFacts = pgTable(
|
|
|
10930
11283
|
estimatedProviderCostMicros: bigint("estimated_provider_cost_micros", {
|
|
10931
11284
|
mode: "number",
|
|
10932
11285
|
}),
|
|
11286
|
+
equivalentCreditCostMicros: bigint("equivalent_credit_cost_micros", {
|
|
11287
|
+
mode: "number",
|
|
11288
|
+
}),
|
|
10933
11289
|
pricingSource: text("pricing_source"),
|
|
10934
11290
|
contextContributions:
|
|
10935
11291
|
jsonb("context_contributions").$type<readonly ModelContextContributionSummary[]>(),
|
|
@@ -10974,6 +11330,10 @@ export const modelCallFacts = pgTable(
|
|
|
10974
11330
|
"model_call_facts_estimated_provider_cost_check",
|
|
10975
11331
|
sql`${table.estimatedProviderCostMicros} is null or ${table.estimatedProviderCostMicros} >= 0`,
|
|
10976
11332
|
),
|
|
11333
|
+
equivalentCreditCostValid: check(
|
|
11334
|
+
"model_call_facts_equivalent_credit_cost_check",
|
|
11335
|
+
sql`${table.equivalentCreditCostMicros} is null or (${table.equivalentCreditCostMicros} >= 0 and ${table.estimatedProviderCostMicros} is not null)`,
|
|
11336
|
+
),
|
|
10977
11337
|
pricingSourceValid: check(
|
|
10978
11338
|
"model_call_facts_pricing_source_check",
|
|
10979
11339
|
sql`(${table.estimatedProviderCostMicros} is null and ${table.pricingSource} is null)
|
|
@@ -11027,8 +11387,9 @@ export const hostExportConfig = pgTable(
|
|
|
11027
11387
|
/**
|
|
11028
11388
|
* Transactional delivery buffer. It intentionally has no tenant/source FKs:
|
|
11029
11389
|
* a workspace deletion must not erase an already-committed, unacknowledged
|
|
11030
|
-
* host fact. Session-event
|
|
11031
|
-
*
|
|
11390
|
+
* host fact. Session-event rows retain exact storage bytes while they fit the
|
|
11391
|
+
* bounded host wire; larger canonical events carry an explicit content-free
|
|
11392
|
+
* projection plus literal-JSON codec truth. Usage payloads remain ordinary JSON.
|
|
11032
11393
|
*/
|
|
11033
11394
|
export const hostExportOutbox = pgTable(
|
|
11034
11395
|
"host_export_outbox",
|
|
@@ -11624,7 +11985,9 @@ export const automationRuns = pgTable(
|
|
|
11624
11985
|
occurrenceKey: text("occurrence_key").notNull(),
|
|
11625
11986
|
acceptedExecution: jsonb("accepted_execution").$type<AutomationAcceptedExecution>().notNull(),
|
|
11626
11987
|
status: text("status").notNull().default("queued"),
|
|
11627
|
-
sessionId: uuid("session_id").references(() => sessions.id, {
|
|
11988
|
+
sessionId: uuid("session_id").references(() => sessions.id, {
|
|
11989
|
+
onDelete: "set null",
|
|
11990
|
+
}),
|
|
11628
11991
|
errorCode: text("error_code"),
|
|
11629
11992
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
11630
11993
|
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
@@ -12628,6 +12991,248 @@ export const rigChanges = pgTable(
|
|
|
12628
12991
|
}),
|
|
12629
12992
|
);
|
|
12630
12993
|
|
|
12994
|
+
export const deploymentModelCatalog = pgTable(
|
|
12995
|
+
"deployment_model_catalog",
|
|
12996
|
+
{
|
|
12997
|
+
singleton: boolean("singleton").primaryKey().notNull().default(true),
|
|
12998
|
+
document: jsonb("document").$type<unknown>().notNull(),
|
|
12999
|
+
version: bigint("version", { mode: "number" }).notNull().default(1),
|
|
13000
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
13001
|
+
},
|
|
13002
|
+
(table) => ({
|
|
13003
|
+
singletonCheck: check("deployment_model_catalog_singleton_chk", sql`${table.singleton}`),
|
|
13004
|
+
documentCheck: check(
|
|
13005
|
+
"deployment_model_catalog_document_chk",
|
|
13006
|
+
sql`jsonb_typeof(${table.document}) = 'object'`,
|
|
13007
|
+
),
|
|
13008
|
+
versionCheck: check("deployment_model_catalog_version_chk", sql`${table.version} > 0`),
|
|
13009
|
+
}),
|
|
13010
|
+
);
|
|
13011
|
+
|
|
13012
|
+
export const workspaceGatewayCustomModels = pgTable(
|
|
13013
|
+
"workspace_gateway_custom_models",
|
|
13014
|
+
{
|
|
13015
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
13016
|
+
accountId: uuid("account_id")
|
|
13017
|
+
.notNull()
|
|
13018
|
+
.references(() => managedAccounts.id, { onDelete: "cascade" }),
|
|
13019
|
+
workspaceId: uuid("workspace_id")
|
|
13020
|
+
.notNull()
|
|
13021
|
+
.references(() => workspaces.id, { onDelete: "cascade" }),
|
|
13022
|
+
providerKind: text("provider_kind").$type<"vercel_gateway" | "openrouter">().notNull(),
|
|
13023
|
+
upstreamModelId: text("upstream_model_id").notNull(),
|
|
13024
|
+
label: text("label"),
|
|
13025
|
+
version: integer("version").notNull().default(1),
|
|
13026
|
+
createOperationId: uuid("create_operation_id").notNull(),
|
|
13027
|
+
createRequestHash: text("create_request_hash").notNull(),
|
|
13028
|
+
deleteOperationId: uuid("delete_operation_id"),
|
|
13029
|
+
deleteRequestHash: text("delete_request_hash"),
|
|
13030
|
+
createdBySubjectId: text("created_by_subject_id").notNull(),
|
|
13031
|
+
retiredAt: timestamp("retired_at", { withTimezone: true }),
|
|
13032
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
13033
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
13034
|
+
},
|
|
13035
|
+
(table) => ({
|
|
13036
|
+
workspaceAccountFk: foreignKey({
|
|
13037
|
+
name: "workspace_gateway_custom_models_workspace_account_fk",
|
|
13038
|
+
columns: [table.workspaceId, table.accountId],
|
|
13039
|
+
foreignColumns: [workspaces.id, workspaces.accountId],
|
|
13040
|
+
}).onDelete("cascade"),
|
|
13041
|
+
workspaceUpstream: uniqueIndex("workspace_gateway_custom_models_workspace_upstream_uq")
|
|
13042
|
+
.on(table.workspaceId, table.providerKind, table.upstreamModelId)
|
|
13043
|
+
.where(sql`${table.retiredAt} is null`),
|
|
13044
|
+
createOperation: uniqueIndex("workspace_gateway_custom_models_create_operation_uq").on(
|
|
13045
|
+
table.workspaceId,
|
|
13046
|
+
table.providerKind,
|
|
13047
|
+
table.createOperationId,
|
|
13048
|
+
),
|
|
13049
|
+
deleteOperation: uniqueIndex("workspace_gateway_custom_models_delete_operation_uq")
|
|
13050
|
+
.on(table.workspaceId, table.providerKind, table.deleteOperationId)
|
|
13051
|
+
.where(sql`${table.deleteOperationId} is not null`),
|
|
13052
|
+
providerKindCheck: check(
|
|
13053
|
+
"workspace_gateway_custom_models_provider_kind_chk",
|
|
13054
|
+
sql`${table.providerKind} in ('vercel_gateway', 'openrouter')`,
|
|
13055
|
+
),
|
|
13056
|
+
upstreamCheck: check(
|
|
13057
|
+
"workspace_gateway_custom_models_upstream_chk",
|
|
13058
|
+
sql`octet_length(${table.upstreamModelId}) between 1 and 238 and ${table.upstreamModelId} ~ '^[!-~]+$' and ${table.upstreamModelId} !~ '[|]'`,
|
|
13059
|
+
),
|
|
13060
|
+
labelCheck: check(
|
|
13061
|
+
"workspace_gateway_custom_models_label_chk",
|
|
13062
|
+
sql`${table.label} is null or (octet_length(${table.label}) between 1 and 128 and ${table.label} !~ '[\r\n|]')`,
|
|
13063
|
+
),
|
|
13064
|
+
actorCheck: check(
|
|
13065
|
+
"workspace_gateway_custom_models_actor_chk",
|
|
13066
|
+
sql`octet_length(${table.createdBySubjectId}) between 1 and 1024`,
|
|
13067
|
+
),
|
|
13068
|
+
versionCheck: check("workspace_gateway_custom_models_version_chk", sql`${table.version} > 0`),
|
|
13069
|
+
createHashCheck: check(
|
|
13070
|
+
"workspace_gateway_custom_models_create_hash_chk",
|
|
13071
|
+
sql`${table.createRequestHash} ~ '^[a-f0-9]{64}$'`,
|
|
13072
|
+
),
|
|
13073
|
+
deleteReceiptCheck: check(
|
|
13074
|
+
"workspace_gateway_custom_models_delete_receipt_chk",
|
|
13075
|
+
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)`,
|
|
13076
|
+
),
|
|
13077
|
+
}),
|
|
13078
|
+
);
|
|
13079
|
+
|
|
13080
|
+
export const organizationModelProviderConnections = pgTable(
|
|
13081
|
+
"organization_model_provider_connections",
|
|
13082
|
+
{
|
|
13083
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
13084
|
+
accountId: uuid("account_id")
|
|
13085
|
+
.notNull()
|
|
13086
|
+
.references(() => managedAccounts.id, { onDelete: "cascade" }),
|
|
13087
|
+
providerKind: text("provider_kind").$type<"vercel_gateway" | "openrouter">().notNull(),
|
|
13088
|
+
status: text("status").$type<"active" | "revoked">().notNull().default("active"),
|
|
13089
|
+
credentialEncrypted: text("credential_encrypted").notNull(),
|
|
13090
|
+
version: integer("version").notNull().default(1),
|
|
13091
|
+
operationId: uuid("operation_id").notNull(),
|
|
13092
|
+
requestHash: text("request_hash").notNull(),
|
|
13093
|
+
updatedBySubjectId: text("updated_by_subject_id").notNull(),
|
|
13094
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
13095
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
13096
|
+
},
|
|
13097
|
+
(table) => ({
|
|
13098
|
+
accountProvider: uniqueIndex("organization_model_provider_connections_account_provider_uq").on(
|
|
13099
|
+
table.accountId,
|
|
13100
|
+
table.providerKind,
|
|
13101
|
+
),
|
|
13102
|
+
operation: uniqueIndex("organization_model_provider_connections_operation_uq").on(
|
|
13103
|
+
table.accountId,
|
|
13104
|
+
table.providerKind,
|
|
13105
|
+
table.operationId,
|
|
13106
|
+
),
|
|
13107
|
+
providerKindCheck: check(
|
|
13108
|
+
"organization_model_provider_connections_provider_kind_chk",
|
|
13109
|
+
sql`${table.providerKind} in ('vercel_gateway', 'openrouter')`,
|
|
13110
|
+
),
|
|
13111
|
+
statusCheck: check(
|
|
13112
|
+
"organization_model_provider_connections_status_chk",
|
|
13113
|
+
sql`${table.status} in ('active', 'revoked')`,
|
|
13114
|
+
),
|
|
13115
|
+
versionCheck: check(
|
|
13116
|
+
"organization_model_provider_connections_version_chk",
|
|
13117
|
+
sql`${table.version} > 0`,
|
|
13118
|
+
),
|
|
13119
|
+
requestHashCheck: check(
|
|
13120
|
+
"organization_model_provider_connections_request_hash_chk",
|
|
13121
|
+
sql`${table.requestHash} ~ '^[a-f0-9]{64}$'`,
|
|
13122
|
+
),
|
|
13123
|
+
actorCheck: check(
|
|
13124
|
+
"organization_model_provider_connections_actor_chk",
|
|
13125
|
+
sql`octet_length(${table.updatedBySubjectId}) between 1 and 1024`,
|
|
13126
|
+
),
|
|
13127
|
+
}),
|
|
13128
|
+
);
|
|
13129
|
+
|
|
13130
|
+
export const organizationModelProviderConnectionOperations = pgTable(
|
|
13131
|
+
"organization_model_provider_connection_operations",
|
|
13132
|
+
{
|
|
13133
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
13134
|
+
accountId: uuid("account_id")
|
|
13135
|
+
.notNull()
|
|
13136
|
+
.references(() => managedAccounts.id, { onDelete: "cascade" }),
|
|
13137
|
+
providerKind: text("provider_kind").$type<"vercel_gateway" | "openrouter">().notNull(),
|
|
13138
|
+
operationId: uuid("operation_id").notNull(),
|
|
13139
|
+
requestHash: text("request_hash").notNull(),
|
|
13140
|
+
resultStatus: text("result_status").$type<"active" | "revoked">().notNull(),
|
|
13141
|
+
resultVersion: integer("result_version").notNull(),
|
|
13142
|
+
resultCreatedAt: timestamp("result_created_at", {
|
|
13143
|
+
withTimezone: true,
|
|
13144
|
+
}).notNull(),
|
|
13145
|
+
resultUpdatedAt: timestamp("result_updated_at", {
|
|
13146
|
+
withTimezone: true,
|
|
13147
|
+
}).notNull(),
|
|
13148
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
13149
|
+
},
|
|
13150
|
+
(table) => ({
|
|
13151
|
+
operation: uniqueIndex("organization_model_provider_connection_operations_operation_uq").on(
|
|
13152
|
+
table.accountId,
|
|
13153
|
+
table.providerKind,
|
|
13154
|
+
table.operationId,
|
|
13155
|
+
),
|
|
13156
|
+
providerKindCheck: check(
|
|
13157
|
+
"organization_model_provider_connection_operations_provider_kind_chk",
|
|
13158
|
+
sql`${table.providerKind} in ('vercel_gateway', 'openrouter')`,
|
|
13159
|
+
),
|
|
13160
|
+
resultStatusCheck: check(
|
|
13161
|
+
"organization_model_provider_connection_operations_result_status_chk",
|
|
13162
|
+
sql`${table.resultStatus} in ('active', 'revoked')`,
|
|
13163
|
+
),
|
|
13164
|
+
resultVersionCheck: check(
|
|
13165
|
+
"organization_model_provider_connection_operations_result_version_chk",
|
|
13166
|
+
sql`${table.resultVersion} > 0`,
|
|
13167
|
+
),
|
|
13168
|
+
requestHashCheck: check(
|
|
13169
|
+
"organization_model_provider_connection_operations_request_hash_chk",
|
|
13170
|
+
sql`${table.requestHash} ~ '^[a-f0-9]{64}$'`,
|
|
13171
|
+
),
|
|
13172
|
+
}),
|
|
13173
|
+
);
|
|
13174
|
+
|
|
13175
|
+
export const organizationModelProviderCustomModels = pgTable(
|
|
13176
|
+
"organization_model_provider_custom_models",
|
|
13177
|
+
{
|
|
13178
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
13179
|
+
accountId: uuid("account_id")
|
|
13180
|
+
.notNull()
|
|
13181
|
+
.references(() => managedAccounts.id, { onDelete: "cascade" }),
|
|
13182
|
+
providerKind: text("provider_kind").$type<"vercel_gateway" | "openrouter">().notNull(),
|
|
13183
|
+
upstreamModelId: text("upstream_model_id").notNull(),
|
|
13184
|
+
label: text("label"),
|
|
13185
|
+
version: integer("version").notNull().default(1),
|
|
13186
|
+
createOperationId: uuid("create_operation_id").notNull(),
|
|
13187
|
+
createRequestHash: text("create_request_hash").notNull(),
|
|
13188
|
+
deleteOperationId: uuid("delete_operation_id"),
|
|
13189
|
+
deleteRequestHash: text("delete_request_hash"),
|
|
13190
|
+
createdBySubjectId: text("created_by_subject_id").notNull(),
|
|
13191
|
+
retiredAt: timestamp("retired_at", { withTimezone: true }),
|
|
13192
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
13193
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
13194
|
+
},
|
|
13195
|
+
(table) => ({
|
|
13196
|
+
accountUpstream: uniqueIndex("organization_model_provider_custom_models_active_uq")
|
|
13197
|
+
.on(table.accountId, table.providerKind, table.upstreamModelId)
|
|
13198
|
+
.where(sql`${table.retiredAt} is null`),
|
|
13199
|
+
createOperation: uniqueIndex(
|
|
13200
|
+
"organization_model_provider_custom_models_create_operation_uq",
|
|
13201
|
+
).on(table.accountId, table.providerKind, table.createOperationId),
|
|
13202
|
+
deleteOperation: uniqueIndex("organization_model_provider_custom_models_delete_operation_uq")
|
|
13203
|
+
.on(table.accountId, table.providerKind, table.deleteOperationId)
|
|
13204
|
+
.where(sql`${table.deleteOperationId} is not null`),
|
|
13205
|
+
providerKindCheck: check(
|
|
13206
|
+
"organization_model_provider_custom_models_provider_kind_chk",
|
|
13207
|
+
sql`${table.providerKind} in ('vercel_gateway', 'openrouter')`,
|
|
13208
|
+
),
|
|
13209
|
+
upstreamCheck: check(
|
|
13210
|
+
"organization_model_provider_custom_models_upstream_chk",
|
|
13211
|
+
sql`octet_length(${table.upstreamModelId}) between 1 and 238 and ${table.upstreamModelId} ~ '^[!-~]+$' and ${table.upstreamModelId} !~ '[|]'`,
|
|
13212
|
+
),
|
|
13213
|
+
labelCheck: check(
|
|
13214
|
+
"organization_model_provider_custom_models_label_chk",
|
|
13215
|
+
sql`${table.label} is null or (octet_length(${table.label}) between 1 and 128 and ${table.label} !~ '[\r\n|]')`,
|
|
13216
|
+
),
|
|
13217
|
+
versionCheck: check(
|
|
13218
|
+
"organization_model_provider_custom_models_version_chk",
|
|
13219
|
+
sql`${table.version} > 0`,
|
|
13220
|
+
),
|
|
13221
|
+
actorCheck: check(
|
|
13222
|
+
"organization_model_provider_custom_models_actor_chk",
|
|
13223
|
+
sql`octet_length(${table.createdBySubjectId}) between 1 and 1024`,
|
|
13224
|
+
),
|
|
13225
|
+
createHashCheck: check(
|
|
13226
|
+
"organization_model_provider_custom_models_create_hash_chk",
|
|
13227
|
+
sql`${table.createRequestHash} ~ '^[a-f0-9]{64}$'`,
|
|
13228
|
+
),
|
|
13229
|
+
deleteReceiptCheck: check(
|
|
13230
|
+
"organization_model_provider_custom_models_delete_receipt_chk",
|
|
13231
|
+
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)`,
|
|
13232
|
+
),
|
|
13233
|
+
}),
|
|
13234
|
+
);
|
|
13235
|
+
|
|
12631
13236
|
export * from "./workspace-instruction-policies-schema";
|
|
12632
13237
|
export * from "./company-profile-schema";
|
|
12633
13238
|
export * from "./workspace-learning-policy-schema";
|