@treeseed/sdk 0.10.10 → 0.10.12

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.
@@ -0,0 +1,1822 @@
1
+ import { index, integer, pgTable, primaryKey, real, serial, text, uniqueIndex } from "drizzle-orm/pg-core";
2
+ const subscribers = pgTable("subscribers", {
3
+ email: text("email").primaryKey(),
4
+ createdAt: text("created_at").notNull()
5
+ });
6
+ const agentRuns = pgTable("agent_runs", {
7
+ runId: text("run_id").primaryKey(),
8
+ agentSlug: text("agent_slug").notNull(),
9
+ status: text("status").notNull(),
10
+ createdAt: text("created_at").notNull()
11
+ });
12
+ const agentMessages = pgTable("agent_messages", {
13
+ id: serial("id").primaryKey(),
14
+ typeColumn: text("type").notNull(),
15
+ payloadJson: text("payload_json").notNull(),
16
+ createdAt: text("created_at").notNull()
17
+ });
18
+ const contactSubmissions = pgTable("contact_submissions", {
19
+ id: serial("id").primaryKey(),
20
+ email: text("email").notNull(),
21
+ message: text("message").notNull(),
22
+ createdAt: text("created_at").notNull()
23
+ });
24
+ const runtimeEnvelopes = pgTable("runtime_envelopes", {
25
+ id: serial("id").primaryKey(),
26
+ recordType: text("record_type").notNull(),
27
+ payloadJson: text("payload_json").notNull(),
28
+ createdAt: text("created_at").notNull()
29
+ });
30
+ const workDays = pgTable("work_days", {
31
+ id: text("id").primaryKey(),
32
+ projectId: text("project_id").notNull(),
33
+ state: text("state").notNull(),
34
+ capacityBudget: integer("capacity_budget").notNull().default(0),
35
+ capacityUsed: integer("capacity_used").notNull().default(0),
36
+ graphVersion: text("graph_version"),
37
+ summaryJson: text("summary_json"),
38
+ startedAt: text("started_at").notNull(),
39
+ endedAt: text("ended_at"),
40
+ createdAt: text("created_at").notNull(),
41
+ updatedAt: text("updated_at").notNull()
42
+ });
43
+ const tasks = pgTable("tasks", {
44
+ id: text("id").primaryKey(),
45
+ workDayId: text("work_day_id").notNull(),
46
+ agentId: text("agent_id").notNull(),
47
+ typeColumn: text("type").notNull(),
48
+ state: text("state").notNull(),
49
+ priority: integer("priority").notNull().default(0),
50
+ idempotencyKey: text("idempotency_key").notNull().unique(),
51
+ payloadJson: text("payload_json").notNull(),
52
+ payloadHash: text("payload_hash"),
53
+ attemptCount: integer("attempt_count").notNull().default(0),
54
+ maxAttempts: integer("max_attempts").notNull().default(3),
55
+ claimedBy: text("claimed_by"),
56
+ leaseExpiresAt: text("lease_expires_at"),
57
+ availableAt: text("available_at").notNull(),
58
+ lastErrorCode: text("last_error_code"),
59
+ lastErrorMessage: text("last_error_message"),
60
+ graphVersion: text("graph_version"),
61
+ parentTaskId: text("parent_task_id"),
62
+ createdAt: text("created_at").notNull(),
63
+ startedAt: text("started_at"),
64
+ completedAt: text("completed_at"),
65
+ updatedAt: text("updated_at").notNull()
66
+ }, (table) => [
67
+ index("idx_tasks_runnable").on(table.state, table.priority, table.availableAt),
68
+ index("idx_tasks_work_day_agent").on(table.workDayId, table.agentId, table.createdAt)
69
+ ]);
70
+ const taskEvents = pgTable("task_events", {
71
+ id: text("id").primaryKey(),
72
+ taskId: text("task_id").notNull(),
73
+ seq: integer("seq").notNull(),
74
+ kind: text("kind").notNull(),
75
+ dataJson: text("data_json").notNull(),
76
+ createdAt: text("created_at").notNull()
77
+ }, (table) => [
78
+ uniqueIndex("idx_task_events_seq").on(table.taskId, table.seq)
79
+ ]);
80
+ const taskOutputs = pgTable("task_outputs", {
81
+ id: text("id").primaryKey(),
82
+ taskId: text("task_id").notNull(),
83
+ outputJson: text("output_json").notNull(),
84
+ outputRef: text("output_ref"),
85
+ createdAt: text("created_at").notNull()
86
+ });
87
+ const graphRuns = pgTable("graph_runs", {
88
+ id: text("id").primaryKey(),
89
+ workDayId: text("work_day_id").notNull(),
90
+ corpusHash: text("corpus_hash").notNull(),
91
+ graphVersion: text("graph_version").notNull(),
92
+ queryJson: text("query_json"),
93
+ seedIdsJson: text("seed_ids_json"),
94
+ selectedNodeIdsJson: text("selected_node_ids_json"),
95
+ statsJson: text("stats_json"),
96
+ snapshotRef: text("snapshot_ref"),
97
+ createdAt: text("created_at").notNull()
98
+ });
99
+ const reports = pgTable("reports", {
100
+ id: text("id").primaryKey(),
101
+ workDayId: text("work_day_id").notNull(),
102
+ kind: text("kind").notNull(),
103
+ bodyJson: text("body_json").notNull(),
104
+ renderedRef: text("rendered_ref"),
105
+ sentAt: text("sent_at"),
106
+ createdAt: text("created_at").notNull()
107
+ });
108
+ const users = pgTable("users", {
109
+ id: text("id").primaryKey(),
110
+ email: text("email"),
111
+ displayName: text("display_name"),
112
+ status: text("status").notNull().default("active"),
113
+ metadataJson: text("metadata_json"),
114
+ createdAt: text("created_at").notNull(),
115
+ updatedAt: text("updated_at").notNull(),
116
+ username: text("username")
117
+ }, (table) => [
118
+ uniqueIndex("idx_users_username").on(table.username)
119
+ ]);
120
+ const userIdentities = pgTable("user_identities", {
121
+ id: text("id").primaryKey(),
122
+ userId: text("user_id").notNull(),
123
+ provider: text("provider").notNull(),
124
+ providerSubject: text("provider_subject").notNull(),
125
+ email: text("email"),
126
+ emailVerified: integer("email_verified").notNull().default(0),
127
+ profileJson: text("profile_json"),
128
+ createdAt: text("created_at").notNull(),
129
+ updatedAt: text("updated_at").notNull()
130
+ }, (table) => [
131
+ uniqueIndex("idx_user_identities_provider_subject").on(table.provider, table.providerSubject)
132
+ ]);
133
+ const roles = pgTable("roles", {
134
+ id: text("id").primaryKey(),
135
+ keyColumn: text("key").notNull().unique(),
136
+ description: text("description"),
137
+ createdAt: text("created_at").notNull()
138
+ });
139
+ const permissions = pgTable("permissions", {
140
+ id: text("id").primaryKey(),
141
+ keyColumn: text("key").notNull().unique(),
142
+ resource: text("resource").notNull(),
143
+ action: text("action").notNull(),
144
+ scope: text("scope").notNull(),
145
+ description: text("description"),
146
+ createdAt: text("created_at").notNull()
147
+ });
148
+ const rolePermissions = pgTable("role_permissions", {
149
+ roleId: text("role_id"),
150
+ permissionId: text("permission_id"),
151
+ createdAt: text("created_at").notNull()
152
+ }, (table) => [
153
+ primaryKey({ columns: [table.roleId, table.permissionId] })
154
+ ]);
155
+ const userRoleBindings = pgTable("user_role_bindings", {
156
+ id: text("id").primaryKey(),
157
+ userId: text("user_id").notNull(),
158
+ roleId: text("role_id").notNull(),
159
+ createdAt: text("created_at").notNull()
160
+ }, (table) => [
161
+ uniqueIndex("idx_user_role_bindings_user_role").on(table.userId, table.roleId)
162
+ ]);
163
+ const apiTokens = pgTable("api_tokens", {
164
+ id: text("id").primaryKey(),
165
+ userId: text("user_id").notNull(),
166
+ kind: text("kind").notNull(),
167
+ name: text("name").notNull(),
168
+ tokenPrefix: text("token_prefix").notNull(),
169
+ tokenHash: text("token_hash").notNull(),
170
+ scopesJson: text("scopes_json").notNull(),
171
+ expiresAt: text("expires_at"),
172
+ lastUsedAt: text("last_used_at"),
173
+ revokedAt: text("revoked_at"),
174
+ metadataJson: text("metadata_json"),
175
+ createdAt: text("created_at").notNull(),
176
+ updatedAt: text("updated_at").notNull()
177
+ }, (table) => [
178
+ index("idx_api_tokens_user_id").on(table.userId),
179
+ index("idx_api_tokens_prefix").on(table.tokenPrefix)
180
+ ]);
181
+ const serviceCredentials = pgTable("service_credentials", {
182
+ id: text("id").primaryKey(),
183
+ serviceId: text("service_id").notNull().unique(),
184
+ name: text("name").notNull(),
185
+ secretHash: text("secret_hash").notNull(),
186
+ rolesJson: text("roles_json").notNull(),
187
+ permissionsJson: text("permissions_json").notNull(),
188
+ revokedAt: text("revoked_at"),
189
+ createdAt: text("created_at").notNull(),
190
+ updatedAt: text("updated_at").notNull(),
191
+ lastUsedAt: text("last_used_at")
192
+ });
193
+ const authSessions = pgTable("auth_sessions", {
194
+ id: text("id").primaryKey(),
195
+ userId: text("user_id").notNull(),
196
+ sessionType: text("session_type").notNull(),
197
+ refreshTokenHash: text("refresh_token_hash").notNull(),
198
+ scopesJson: text("scopes_json").notNull(),
199
+ expiresAt: text("expires_at").notNull(),
200
+ revokedAt: text("revoked_at"),
201
+ dataJson: text("data_json"),
202
+ createdAt: text("created_at").notNull(),
203
+ updatedAt: text("updated_at").notNull()
204
+ }, (table) => [
205
+ index("idx_auth_sessions_user_id").on(table.userId)
206
+ ]);
207
+ const auditEvents = pgTable("audit_events", {
208
+ id: text("id").primaryKey(),
209
+ actorType: text("actor_type").notNull(),
210
+ actorId: text("actor_id"),
211
+ eventType: text("event_type").notNull(),
212
+ targetType: text("target_type"),
213
+ targetId: text("target_id"),
214
+ dataJson: text("data_json"),
215
+ createdAt: text("created_at").notNull()
216
+ }, (table) => [
217
+ index("idx_audit_events_target").on(table.targetType, table.targetId)
218
+ ]);
219
+ const deviceCodes = pgTable("device_codes", {
220
+ id: text("id").primaryKey(),
221
+ deviceCode: text("device_code").notNull().unique(),
222
+ userCode: text("user_code").notNull().unique(),
223
+ requestedScopesJson: text("requested_scopes_json").notNull(),
224
+ expiresAt: text("expires_at").notNull(),
225
+ intervalSeconds: integer("interval_seconds").notNull(),
226
+ status: text("status").notNull(),
227
+ userId: text("user_id"),
228
+ createdAt: text("created_at").notNull(),
229
+ updatedAt: text("updated_at").notNull()
230
+ });
231
+ const teams = pgTable("teams", {
232
+ id: text("id").primaryKey(),
233
+ slug: text("slug").notNull().unique(),
234
+ name: text("name").notNull(),
235
+ metadataJson: text("metadata_json"),
236
+ createdAt: text("created_at").notNull(),
237
+ updatedAt: text("updated_at").notNull(),
238
+ displayName: text("display_name"),
239
+ logoUrl: text("logo_url"),
240
+ profileSummary: text("profile_summary")
241
+ }, (table) => [
242
+ uniqueIndex("idx_teams_name").on(table.name)
243
+ ]);
244
+ const teamMemberships = pgTable("team_memberships", {
245
+ id: text("id").primaryKey(),
246
+ teamId: text("team_id").notNull(),
247
+ userId: text("user_id").notNull(),
248
+ status: text("status").notNull().default("active"),
249
+ createdAt: text("created_at").notNull(),
250
+ updatedAt: text("updated_at").notNull()
251
+ }, (table) => [
252
+ uniqueIndex("idx_team_memberships_team_user").on(table.teamId, table.userId)
253
+ ]);
254
+ const teamRoleBindings = pgTable("team_role_bindings", {
255
+ id: text("id").primaryKey(),
256
+ teamMembershipId: text("team_membership_id").notNull(),
257
+ roleId: text("role_id").notNull(),
258
+ createdAt: text("created_at").notNull()
259
+ });
260
+ const webSessions = pgTable("web_sessions", {
261
+ id: text("id").primaryKey(),
262
+ userId: text("user_id").notNull(),
263
+ identityId: text("identity_id"),
264
+ betterAuthSessionId: text("better_auth_session_id"),
265
+ provider: text("provider").notNull(),
266
+ providerSubject: text("provider_subject").notNull(),
267
+ email: text("email"),
268
+ displayName: text("display_name"),
269
+ principalJson: text("principal_json").notNull(),
270
+ csrfToken: text("csrf_token").notNull(),
271
+ ipAddress: text("ip_address"),
272
+ userAgent: text("user_agent"),
273
+ authenticatedAt: text("authenticated_at").notNull(),
274
+ lastSeenAt: text("last_seen_at"),
275
+ expiresAt: text("expires_at").notNull(),
276
+ revokedAt: text("revoked_at"),
277
+ createdAt: text("created_at").notNull(),
278
+ updatedAt: text("updated_at").notNull()
279
+ }, (table) => [
280
+ index("idx_web_sessions_user_id").on(table.userId)
281
+ ]);
282
+ const projects = pgTable("projects", {
283
+ id: text("id").primaryKey(),
284
+ teamId: text("team_id").notNull(),
285
+ slug: text("slug").notNull().unique(),
286
+ name: text("name").notNull(),
287
+ description: text("description"),
288
+ metadataJson: text("metadata_json"),
289
+ createdAt: text("created_at").notNull(),
290
+ updatedAt: text("updated_at").notNull()
291
+ }, (table) => [
292
+ index("idx_projects_team_id").on(table.teamId)
293
+ ]);
294
+ const projectConnections = pgTable("project_connections", {
295
+ id: text("id").primaryKey(),
296
+ projectId: text("project_id").notNull().unique(),
297
+ mode: text("mode").notNull(),
298
+ projectApiBaseUrl: text("project_api_base_url"),
299
+ executionOwner: text("execution_owner").notNull(),
300
+ runnerRegistrationState: text("runner_registration_state").notNull().default("pending"),
301
+ runnerKeyPrefix: text("runner_key_prefix"),
302
+ runnerKeyHash: text("runner_key_hash"),
303
+ runnerRegisteredAt: text("runner_registered_at"),
304
+ runnerLastSeenAt: text("runner_last_seen_at"),
305
+ metadataJson: text("metadata_json"),
306
+ createdAt: text("created_at").notNull(),
307
+ updatedAt: text("updated_at").notNull()
308
+ });
309
+ const projectCapabilityGrants = pgTable("project_capability_grants", {
310
+ id: text("id").primaryKey(),
311
+ projectId: text("project_id").notNull(),
312
+ label: text("label"),
313
+ namespace: text("namespace").notNull(),
314
+ operation: text("operation").notNull(),
315
+ executionClass: text("execution_class").notNull(),
316
+ allowedTargetsJson: text("allowed_targets_json").notNull(),
317
+ defaultDispatchMode: text("default_dispatch_mode").notNull(),
318
+ approvalPolicyJson: text("approval_policy_json").notNull().default("{}"),
319
+ resourceScopeJson: text("resource_scope_json").notNull().default("{}"),
320
+ metadataJson: text("metadata_json").notNull().default("{}"),
321
+ enabled: integer("enabled").notNull().default(1),
322
+ createdAt: text("created_at").notNull(),
323
+ updatedAt: text("updated_at").notNull()
324
+ }, (table) => [
325
+ uniqueIndex("idx_project_capability_grants_project_operation").on(table.projectId, table.namespace, table.operation)
326
+ ]);
327
+ const teamApiKeys = pgTable("team_api_keys", {
328
+ id: text("id").primaryKey(),
329
+ teamId: text("team_id").notNull(),
330
+ name: text("name").notNull(),
331
+ keyPrefix: text("key_prefix").notNull(),
332
+ keyHash: text("key_hash").notNull(),
333
+ permissionsJson: text("permissions_json").notNull(),
334
+ expiresAt: text("expires_at"),
335
+ lastUsedAt: text("last_used_at"),
336
+ revokedAt: text("revoked_at"),
337
+ createdAt: text("created_at").notNull(),
338
+ updatedAt: text("updated_at").notNull()
339
+ }, (table) => [
340
+ index("idx_team_api_keys_prefix").on(table.keyPrefix)
341
+ ]);
342
+ const entitlements = pgTable("entitlements", {
343
+ id: text("id").primaryKey(),
344
+ teamId: text("team_id"),
345
+ projectId: text("project_id"),
346
+ tier: text("tier").notNull(),
347
+ status: text("status").notNull(),
348
+ metadataJson: text("metadata_json"),
349
+ createdAt: text("created_at").notNull(),
350
+ updatedAt: text("updated_at").notNull()
351
+ }, (table) => [
352
+ uniqueIndex("idx_entitlements_project").on(table.projectId)
353
+ ]);
354
+ const remoteJobs = pgTable("remote_jobs", {
355
+ id: text("id").primaryKey(),
356
+ projectId: text("project_id").notNull(),
357
+ namespace: text("namespace").notNull(),
358
+ operation: text("operation").notNull(),
359
+ status: text("status").notNull(),
360
+ preferredMode: text("preferred_mode").notNull(),
361
+ selectedTarget: text("selected_target").notNull(),
362
+ capabilityJson: text("capability_json").notNull(),
363
+ inputJson: text("input_json").notNull(),
364
+ outputJson: text("output_json"),
365
+ errorJson: text("error_json"),
366
+ requestedByType: text("requested_by_type").notNull(),
367
+ requestedById: text("requested_by_id"),
368
+ assignedRunnerId: text("assigned_runner_id"),
369
+ idempotencyKey: text("idempotency_key"),
370
+ createdAt: text("created_at").notNull(),
371
+ updatedAt: text("updated_at").notNull(),
372
+ startedAt: text("started_at"),
373
+ finishedAt: text("finished_at"),
374
+ cancelledAt: text("cancelled_at")
375
+ }, (table) => [
376
+ index("idx_remote_jobs_project_status").on(table.projectId, table.status, table.createdAt),
377
+ index("idx_remote_jobs_project_idempotency").on(table.projectId, table.idempotencyKey)
378
+ ]);
379
+ const remoteJobEvents = pgTable("remote_job_events", {
380
+ id: text("id").primaryKey(),
381
+ jobId: text("job_id").notNull(),
382
+ seq: integer("seq").notNull(),
383
+ kind: text("kind").notNull(),
384
+ dataJson: text("data_json"),
385
+ createdAt: text("created_at").notNull()
386
+ }, (table) => [
387
+ uniqueIndex("idx_remote_job_events_job_seq").on(table.jobId, table.seq)
388
+ ]);
389
+ const knowledgePacks = pgTable("knowledge_packs", {
390
+ id: text("id").primaryKey(),
391
+ teamId: text("team_id").notNull(),
392
+ slug: text("slug").notNull().unique(),
393
+ name: text("name").notNull(),
394
+ summary: text("summary"),
395
+ sourceKind: text("source_kind").notNull(),
396
+ sourceRef: text("source_ref"),
397
+ installStrategy: text("install_strategy").notNull(),
398
+ visibility: text("visibility").notNull(),
399
+ metadataJson: text("metadata_json"),
400
+ createdAt: text("created_at").notNull(),
401
+ updatedAt: text("updated_at").notNull()
402
+ }, (table) => [
403
+ index("idx_knowledge_packs_team_id").on(table.teamId)
404
+ ]);
405
+ const teamStorageLocators = pgTable("team_storage_locators", {
406
+ id: text("id").primaryKey(),
407
+ teamId: text("team_id").notNull().unique(),
408
+ bucketName: text("bucket_name").notNull(),
409
+ manifestKeyTemplate: text("manifest_key_template").notNull(),
410
+ previewRootTemplate: text("preview_root_template").notNull(),
411
+ publicBaseUrl: text("public_base_url"),
412
+ metadataJson: text("metadata_json"),
413
+ createdAt: text("created_at").notNull(),
414
+ updatedAt: text("updated_at").notNull()
415
+ });
416
+ const catalogItems = pgTable("catalog_items", {
417
+ id: text("id").primaryKey(),
418
+ teamId: text("team_id").notNull(),
419
+ kind: text("kind").notNull(),
420
+ slug: text("slug").notNull(),
421
+ title: text("title").notNull(),
422
+ summary: text("summary"),
423
+ visibility: text("visibility").notNull(),
424
+ listingEnabled: integer("listing_enabled").notNull().default(0),
425
+ offerMode: text("offer_mode").notNull(),
426
+ manifestKey: text("manifest_key"),
427
+ artifactKey: text("artifact_key"),
428
+ searchText: text("search_text"),
429
+ metadataJson: text("metadata_json"),
430
+ createdAt: text("created_at").notNull(),
431
+ updatedAt: text("updated_at").notNull()
432
+ }, (table) => [
433
+ uniqueIndex("idx_catalog_items_kind_slug").on(table.kind, table.slug),
434
+ index("idx_catalog_items_team_kind").on(table.teamId, table.kind, table.updatedAt),
435
+ index("idx_catalog_items_visibility_listing").on(table.visibility, table.listingEnabled, table.updatedAt)
436
+ ]);
437
+ const catalogArtifactVersions = pgTable("catalog_artifact_versions", {
438
+ id: text("id").primaryKey(),
439
+ itemId: text("item_id").notNull(),
440
+ teamId: text("team_id").notNull(),
441
+ kind: text("kind").notNull(),
442
+ version: text("version").notNull(),
443
+ contentKey: text("content_key").notNull(),
444
+ manifestKey: text("manifest_key"),
445
+ metadataJson: text("metadata_json"),
446
+ publishedAt: text("published_at").notNull(),
447
+ createdAt: text("created_at").notNull(),
448
+ updatedAt: text("updated_at").notNull()
449
+ }, (table) => [
450
+ uniqueIndex("idx_catalog_artifact_versions_item_version").on(table.itemId, table.version),
451
+ index("idx_catalog_artifact_versions_team_kind").on(table.teamId, table.kind, table.publishedAt)
452
+ ]);
453
+ const catalogItemCollaborators = pgTable("catalog_item_collaborators", {
454
+ id: text("id").primaryKey(),
455
+ itemId: text("item_id").notNull(),
456
+ subjectType: text("subject_type").notNull(),
457
+ subjectId: text("subject_id").notNull(),
458
+ role: text("role").notNull(),
459
+ metadataJson: text("metadata_json"),
460
+ createdAt: text("created_at").notNull(),
461
+ updatedAt: text("updated_at").notNull()
462
+ }, (table) => [
463
+ uniqueIndex("idx_catalog_item_collaborators_subject_role").on(table.itemId, table.subjectType, table.subjectId, table.role)
464
+ ]);
465
+ const projectHosting = pgTable("project_hosting", {
466
+ id: text("id").primaryKey(),
467
+ projectId: text("project_id").notNull().unique(),
468
+ hostingKind: text("hosting_kind").notNull(),
469
+ registration: text("registration").notNull().default("none"),
470
+ marketBaseUrl: text("market_base_url"),
471
+ sourceRepoOwner: text("source_repo_owner"),
472
+ sourceRepoName: text("source_repo_name"),
473
+ sourceRepoUrl: text("source_repo_url"),
474
+ sourceRepoWorkflowPath: text("source_repo_workflow_path"),
475
+ metadataJson: text("metadata_json"),
476
+ createdAt: text("created_at").notNull(),
477
+ updatedAt: text("updated_at").notNull()
478
+ });
479
+ const projectEnvironments = pgTable("project_environments", {
480
+ id: text("id").primaryKey(),
481
+ projectId: text("project_id").notNull(),
482
+ environment: text("environment").notNull(),
483
+ deploymentProfile: text("deployment_profile").notNull(),
484
+ baseUrl: text("base_url"),
485
+ cloudflareAccountId: text("cloudflare_account_id"),
486
+ pagesProjectName: text("pages_project_name"),
487
+ workerName: text("worker_name"),
488
+ r2BucketName: text("r2_bucket_name"),
489
+ d1DatabaseName: text("d1_database_name"),
490
+ queueName: text("queue_name"),
491
+ railwayProjectName: text("railway_project_name"),
492
+ metadataJson: text("metadata_json"),
493
+ createdAt: text("created_at").notNull(),
494
+ updatedAt: text("updated_at").notNull()
495
+ }, (table) => [
496
+ uniqueIndex("idx_project_environments_project_environment").on(table.projectId, table.environment)
497
+ ]);
498
+ const projectInfrastructureResources = pgTable("project_infrastructure_resources", {
499
+ id: text("id").primaryKey(),
500
+ projectId: text("project_id").notNull(),
501
+ environment: text("environment").notNull(),
502
+ provider: text("provider").notNull(),
503
+ resourceKind: text("resource_kind").notNull(),
504
+ logicalName: text("logical_name").notNull(),
505
+ locator: text("locator"),
506
+ metadataJson: text("metadata_json"),
507
+ createdAt: text("created_at").notNull(),
508
+ updatedAt: text("updated_at").notNull()
509
+ }, (table) => [
510
+ uniqueIndex("idx_project_infrastructure_resource_unique").on(table.projectId, table.environment, table.provider, table.resourceKind, table.logicalName)
511
+ ]);
512
+ const projectDeployments = pgTable("project_deployments", {
513
+ id: text("id").primaryKey(),
514
+ projectId: text("project_id").notNull(),
515
+ environment: text("environment").notNull(),
516
+ deploymentKind: text("deployment_kind").notNull(),
517
+ status: text("status").notNull(),
518
+ sourceRef: text("source_ref"),
519
+ releaseTag: text("release_tag"),
520
+ commitSha: text("commit_sha"),
521
+ triggeredByType: text("triggered_by_type"),
522
+ triggeredById: text("triggered_by_id"),
523
+ metadataJson: text("metadata_json"),
524
+ startedAt: text("started_at"),
525
+ finishedAt: text("finished_at"),
526
+ createdAt: text("created_at").notNull(),
527
+ updatedAt: text("updated_at").notNull()
528
+ }, (table) => [
529
+ index("idx_project_deployments_project_environment").on(table.projectId, table.environment, table.createdAt)
530
+ ]);
531
+ const agentPools = pgTable("agent_pools", {
532
+ id: text("id").primaryKey(),
533
+ projectId: text("project_id").notNull(),
534
+ teamId: text("team_id").notNull(),
535
+ environment: text("environment").notNull(),
536
+ name: text("name").notNull(),
537
+ registrationIdentity: text("registration_identity"),
538
+ serviceBaseUrl: text("service_base_url"),
539
+ status: text("status").notNull().default("pending"),
540
+ minWorkers: integer("min_workers").notNull().default(0),
541
+ maxWorkers: integer("max_workers").notNull().default(1),
542
+ targetQueueDepth: integer("target_queue_depth").notNull().default(1),
543
+ cooldownSeconds: integer("cooldown_seconds").notNull().default(60),
544
+ metadataJson: text("metadata_json"),
545
+ createdAt: text("created_at").notNull(),
546
+ updatedAt: text("updated_at").notNull()
547
+ }, (table) => [
548
+ uniqueIndex("idx_agent_pools_project_environment_name").on(table.projectId, table.environment, table.name)
549
+ ]);
550
+ const agentPoolRegistrations = pgTable("agent_pool_registrations", {
551
+ id: text("id").primaryKey(),
552
+ poolId: text("pool_id").notNull(),
553
+ projectId: text("project_id").notNull(),
554
+ runnerId: text("runner_id"),
555
+ managerId: text("manager_id"),
556
+ serviceName: text("service_name"),
557
+ heartbeatAt: text("heartbeat_at").notNull(),
558
+ desiredWorkers: integer("desired_workers"),
559
+ observedQueueDepth: integer("observed_queue_depth"),
560
+ observedActiveLeases: integer("observed_active_leases"),
561
+ metadataJson: text("metadata_json"),
562
+ createdAt: text("created_at").notNull(),
563
+ updatedAt: text("updated_at").notNull()
564
+ }, (table) => [
565
+ index("idx_agent_pool_registrations_pool_heartbeat").on(table.poolId, table.heartbeatAt)
566
+ ]);
567
+ const agentPoolScaleDecisions = pgTable("agent_pool_scale_decisions", {
568
+ id: text("id").primaryKey(),
569
+ poolId: text("pool_id").notNull(),
570
+ projectId: text("project_id").notNull(),
571
+ environment: text("environment").notNull(),
572
+ desiredWorkers: integer("desired_workers").notNull(),
573
+ observedQueueDepth: integer("observed_queue_depth").notNull().default(0),
574
+ observedActiveLeases: integer("observed_active_leases").notNull().default(0),
575
+ workDayId: text("work_day_id"),
576
+ reason: text("reason").notNull(),
577
+ metadataJson: text("metadata_json").notNull(),
578
+ createdAt: text("created_at").notNull(),
579
+ updatedAt: text("updated_at").notNull()
580
+ }, (table) => [
581
+ index("idx_agent_pool_scale_decisions_pool_created").on(table.poolId, table.createdAt)
582
+ ]);
583
+ const projectWorkdaySummaries = pgTable("project_workday_summaries", {
584
+ id: text("id").primaryKey(),
585
+ projectId: text("project_id").notNull(),
586
+ environment: text("environment").notNull(),
587
+ workDayId: text("work_day_id").notNull(),
588
+ kind: text("kind").notNull(),
589
+ state: text("state"),
590
+ startedAt: text("started_at"),
591
+ endedAt: text("ended_at"),
592
+ summaryJson: text("summary_json").notNull(),
593
+ metadataJson: text("metadata_json").notNull(),
594
+ createdAt: text("created_at").notNull(),
595
+ updatedAt: text("updated_at").notNull()
596
+ }, (table) => [
597
+ index("idx_project_workday_summaries_project_environment_created").on(table.projectId, table.environment, table.createdAt)
598
+ ]);
599
+ const workPolicies = pgTable("work_policies", {
600
+ projectId: text("project_id"),
601
+ environment: text("environment"),
602
+ scheduleJson: text("schedule_json").notNull(),
603
+ dailyTaskCreditBudget: integer("daily_task_credit_budget").notNull().default(0),
604
+ maxQueuedTasks: integer("max_queued_tasks").notNull().default(0),
605
+ maxQueuedCredits: integer("max_queued_credits").notNull().default(0),
606
+ autoscaleJson: text("autoscale_json").notNull(),
607
+ creditWeightsJson: text("credit_weights_json").notNull(),
608
+ metadataJson: text("metadata_json").notNull(),
609
+ createdAt: text("created_at").notNull(),
610
+ updatedAt: text("updated_at").notNull(),
611
+ enabled: integer("enabled").notNull().default(1),
612
+ startCron: text("start_cron").notNull().default("0 9 * * 1-5"),
613
+ durationMinutes: integer("duration_minutes").notNull().default(480),
614
+ maxRunners: integer("max_runners").notNull().default(1),
615
+ maxWorkersPerRunner: integer("max_workers_per_runner").notNull().default(4),
616
+ dailyCreditBudget: integer("daily_credit_budget").notNull().default(0),
617
+ closeoutGraceMinutes: integer("closeout_grace_minutes").notNull().default(15)
618
+ }, (table) => [
619
+ primaryKey({ columns: [table.projectId, table.environment] })
620
+ ]);
621
+ const priorityOverrides = pgTable("priority_overrides", {
622
+ id: text("id").primaryKey(),
623
+ projectId: text("project_id").notNull(),
624
+ model: text("model").notNull(),
625
+ subjectId: text("subject_id").notNull(),
626
+ priority: real("priority").notNull().default(0),
627
+ estimatedCredits: real("estimated_credits"),
628
+ metadataJson: text("metadata_json").notNull(),
629
+ createdAt: text("created_at").notNull(),
630
+ updatedAt: text("updated_at").notNull()
631
+ }, (table) => [
632
+ index("idx_priority_overrides_project_priority").on(table.projectId, table.priority, table.updatedAt)
633
+ ]);
634
+ const prioritySnapshots = pgTable("priority_snapshots", {
635
+ id: text("id").primaryKey(),
636
+ projectId: text("project_id").notNull(),
637
+ workDayId: text("work_day_id"),
638
+ snapshotJson: text("snapshot_json").notNull(),
639
+ metadataJson: text("metadata_json").notNull(),
640
+ generatedAt: text("generated_at").notNull(),
641
+ createdAt: text("created_at").notNull(),
642
+ updatedAt: text("updated_at").notNull()
643
+ }, (table) => [
644
+ index("idx_priority_snapshots_project_generated").on(table.projectId, table.generatedAt)
645
+ ]);
646
+ const taskCreditLedger = pgTable("task_credit_ledger", {
647
+ id: text("id").primaryKey(),
648
+ projectId: text("project_id").notNull(),
649
+ workDayId: text("work_day_id").notNull(),
650
+ taskId: text("task_id"),
651
+ phase: text("phase").notNull(),
652
+ credits: real("credits").notNull(),
653
+ metadataJson: text("metadata_json").notNull(),
654
+ createdAt: text("created_at").notNull()
655
+ }, (table) => [
656
+ index("idx_task_credit_ledger_work_day_created").on(table.workDayId, table.createdAt)
657
+ ]);
658
+ const scaleDecisions = pgTable("scale_decisions", {
659
+ id: text("id").primaryKey(),
660
+ projectId: text("project_id").notNull(),
661
+ environment: text("environment").notNull(),
662
+ poolName: text("pool_name").notNull(),
663
+ workDayId: text("work_day_id"),
664
+ desiredWorkers: integer("desired_workers").notNull(),
665
+ observedQueueDepth: integer("observed_queue_depth").notNull().default(0),
666
+ observedActiveLeases: integer("observed_active_leases").notNull().default(0),
667
+ reason: text("reason").notNull(),
668
+ metadataJson: text("metadata_json").notNull(),
669
+ createdAt: text("created_at").notNull()
670
+ }, (table) => [
671
+ index("idx_scale_decisions_project_environment_pool_created").on(table.projectId, table.environment, table.poolName, table.createdAt)
672
+ ]);
673
+ const projectSummarySnapshots = pgTable("project_summary_snapshots", {
674
+ projectId: text("project_id").primaryKey(),
675
+ teamId: text("team_id").notNull(),
676
+ summaryJson: text("summary_json").notNull(),
677
+ generatedAt: text("generated_at").notNull(),
678
+ createdAt: text("created_at").notNull(),
679
+ updatedAt: text("updated_at").notNull()
680
+ }, (table) => [
681
+ index("idx_project_summary_snapshots_team_generated").on(table.teamId, table.generatedAt)
682
+ ]);
683
+ const teamInboxItems = pgTable("team_inbox_items", {
684
+ id: text("id").primaryKey(),
685
+ teamId: text("team_id").notNull(),
686
+ projectId: text("project_id"),
687
+ kind: text("kind").notNull(),
688
+ state: text("state").notNull(),
689
+ title: text("title").notNull(),
690
+ summary: text("summary"),
691
+ href: text("href"),
692
+ itemKey: text("item_key"),
693
+ metadataJson: text("metadata_json").notNull().default("{}"),
694
+ createdAt: text("created_at").notNull(),
695
+ updatedAt: text("updated_at").notNull()
696
+ }, (table) => [
697
+ index("idx_team_inbox_items_team_created").on(table.teamId, table.createdAt)
698
+ ]);
699
+ const betterAuthUser = pgTable("better_auth_user", {
700
+ id: text("id").primaryKey(),
701
+ name: text("name").notNull(),
702
+ email: text("email").notNull().unique(),
703
+ emailVerified: integer("emailVerified").notNull().default(0),
704
+ image: text("image"),
705
+ createdAt: integer("createdAt").notNull(),
706
+ updatedAt: integer("updatedAt").notNull(),
707
+ username: text("username"),
708
+ firstName: text("firstName"),
709
+ lastName: text("lastName")
710
+ }, (table) => [
711
+ uniqueIndex("idx_better_auth_user_username").on(table.username)
712
+ ]);
713
+ const betterAuthSession = pgTable("better_auth_session", {
714
+ id: text("id").primaryKey(),
715
+ expiresAt: integer("expiresAt").notNull(),
716
+ token: text("token").notNull().unique(),
717
+ createdAt: integer("createdAt").notNull(),
718
+ updatedAt: integer("updatedAt").notNull(),
719
+ ipAddress: text("ipAddress"),
720
+ userAgent: text("userAgent"),
721
+ userId: text("userId").notNull()
722
+ }, (table) => [
723
+ index("idx_better_auth_session_token").on(table.token),
724
+ index("idx_better_auth_session_userId").on(table.userId)
725
+ ]);
726
+ const betterAuthAccount = pgTable("better_auth_account", {
727
+ id: text("id").primaryKey(),
728
+ accountId: text("accountId").notNull(),
729
+ providerId: text("providerId").notNull(),
730
+ userId: text("userId").notNull(),
731
+ accessToken: text("accessToken"),
732
+ refreshToken: text("refreshToken"),
733
+ idToken: text("idToken"),
734
+ accessTokenExpiresAt: integer("accessTokenExpiresAt"),
735
+ refreshTokenExpiresAt: integer("refreshTokenExpiresAt"),
736
+ scope: text("scope"),
737
+ password: text("password"),
738
+ createdAt: integer("createdAt").notNull(),
739
+ updatedAt: integer("updatedAt").notNull()
740
+ }, (table) => [
741
+ index("idx_better_auth_account_userId").on(table.userId),
742
+ uniqueIndex("idx_better_auth_account_provider_account").on(table.providerId, table.accountId)
743
+ ]);
744
+ const betterAuthVerification = pgTable("better_auth_verification", {
745
+ id: text("id").primaryKey(),
746
+ identifier: text("identifier").notNull(),
747
+ value: text("value").notNull(),
748
+ expiresAt: integer("expiresAt").notNull(),
749
+ createdAt: integer("createdAt").notNull(),
750
+ updatedAt: integer("updatedAt").notNull()
751
+ }, (table) => [
752
+ index("idx_better_auth_verification_identifier").on(table.identifier)
753
+ ]);
754
+ const teamWebHosts = pgTable("team_web_hosts", {
755
+ id: text("id").primaryKey(),
756
+ teamId: text("team_id").notNull(),
757
+ provider: text("provider").notNull(),
758
+ ownership: text("ownership").notNull(),
759
+ name: text("name").notNull(),
760
+ accountLabel: text("account_label"),
761
+ allowedEnvironmentsJson: text("allowed_environments_json").notNull().default("[]"),
762
+ status: text("status").notNull().default("active"),
763
+ encryptedPayloadJson: text("encrypted_payload_json"),
764
+ metadataJson: text("metadata_json"),
765
+ createdById: text("created_by_id"),
766
+ updatedById: text("updated_by_id"),
767
+ createdAt: text("created_at").notNull(),
768
+ updatedAt: text("updated_at").notNull()
769
+ }, (table) => [
770
+ index("idx_team_web_hosts_team_provider").on(table.teamId, table.provider, table.status),
771
+ uniqueIndex("idx_team_web_hosts_team_provider_name").on(table.teamId, table.provider, table.name)
772
+ ]);
773
+ const teamInvites = pgTable("team_invites", {
774
+ id: text("id").primaryKey(),
775
+ teamId: text("team_id").notNull(),
776
+ email: text("email").notNull(),
777
+ roleKey: text("role_key").notNull(),
778
+ tokenPrefix: text("token_prefix").notNull(),
779
+ tokenHash: text("token_hash").notNull(),
780
+ status: text("status").notNull().default("pending"),
781
+ invitedByUserId: text("invited_by_user_id"),
782
+ acceptedByUserId: text("accepted_by_user_id"),
783
+ acceptedAt: text("accepted_at"),
784
+ expiresAt: text("expires_at").notNull(),
785
+ createdAt: text("created_at").notNull(),
786
+ updatedAt: text("updated_at").notNull()
787
+ }, (table) => [
788
+ index("idx_team_invites_team_status").on(table.teamId, table.status, table.createdAt),
789
+ index("idx_team_invites_token_prefix").on(table.tokenPrefix)
790
+ ]);
791
+ const capacityProviders = pgTable("capacity_providers", {
792
+ id: text("id").primaryKey(),
793
+ teamId: text("team_id"),
794
+ ownerTeamId: text("owner_team_id"),
795
+ name: text("name").notNull(),
796
+ kind: text("kind").notNull(),
797
+ status: text("status").notNull().default("pending"),
798
+ provider: text("provider").notNull(),
799
+ billingScope: text("billing_scope").notNull().default("team"),
800
+ monthlyCreditBudget: real("monthly_credit_budget").notNull().default(0),
801
+ dailyCreditBudget: real("daily_credit_budget").notNull().default(0),
802
+ creditBudgetMode: text("credit_budget_mode").notNull().default("derived"),
803
+ maxConcurrentWorkdays: integer("max_concurrent_workdays").notNull().default(1),
804
+ maxConcurrentWorkers: integer("max_concurrent_workers").notNull().default(1),
805
+ capacityModelJson: text("capacity_model_json").notNull().default("{}"),
806
+ metadataJson: text("metadata_json").notNull().default("{}"),
807
+ createdAt: text("created_at").notNull(),
808
+ updatedAt: text("updated_at").notNull()
809
+ }, (table) => [
810
+ index("idx_capacity_providers_team_status").on(table.teamId, table.status, table.provider)
811
+ ]);
812
+ const capacityProviderHosts = pgTable("capacity_provider_hosts", {
813
+ id: text("id").primaryKey(),
814
+ capacityProviderId: text("capacity_provider_id").notNull(),
815
+ hostId: text("host_id").notNull(),
816
+ role: text("role").notNull(),
817
+ required: integer("required").notNull().default(1),
818
+ metadataJson: text("metadata_json").notNull().default("{}"),
819
+ createdAt: text("created_at").notNull(),
820
+ updatedAt: text("updated_at").notNull()
821
+ }, (table) => [
822
+ uniqueIndex("idx_capacity_provider_hosts_unique").on(table.capacityProviderId, table.hostId, table.role)
823
+ ]);
824
+ const capacityProviderLanes = pgTable("capacity_provider_lanes", {
825
+ id: text("id").primaryKey(),
826
+ capacityProviderId: text("capacity_provider_id").notNull(),
827
+ name: text("name").notNull(),
828
+ businessModel: text("business_model").notNull().default("custom"),
829
+ modelFamily: text("model_family"),
830
+ modelClass: text("model_class"),
831
+ regionPolicy: text("region_policy"),
832
+ unit: text("unit").notNull().default("treeseed_credit"),
833
+ scarcityLevel: text("scarcity_level").notNull().default("medium"),
834
+ hardLimitsJson: text("hard_limits_json").notNull().default("{}"),
835
+ routingPolicyJson: text("routing_policy_json").notNull().default("{}"),
836
+ metadataJson: text("metadata_json").notNull().default("{}"),
837
+ createdAt: text("created_at").notNull(),
838
+ updatedAt: text("updated_at").notNull()
839
+ }, (table) => [
840
+ index("idx_capacity_provider_lanes_provider").on(table.capacityProviderId, table.businessModel, table.scarcityLevel)
841
+ ]);
842
+ const capacityGrants = pgTable("capacity_grants", {
843
+ id: text("id").primaryKey(),
844
+ capacityProviderId: text("capacity_provider_id").notNull(),
845
+ laneId: text("lane_id"),
846
+ grantScope: text("grant_scope").notNull().default("team"),
847
+ teamId: text("team_id").notNull(),
848
+ projectId: text("project_id"),
849
+ environment: text("environment"),
850
+ state: text("state").notNull().default("active"),
851
+ dailyCreditLimit: real("daily_credit_limit"),
852
+ weeklyCreditLimit: real("weekly_credit_limit"),
853
+ monthlyCreditLimit: real("monthly_credit_limit"),
854
+ dailyUsdLimit: real("daily_usd_limit"),
855
+ weeklyQuotaMinutes: real("weekly_quota_minutes"),
856
+ monthlyProviderUnits: real("monthly_provider_units"),
857
+ priorityWeight: real("priority_weight").notNull().default(1),
858
+ overflowPolicy: text("overflow_policy").notNull().default("soft_grant"),
859
+ metadataJson: text("metadata_json").notNull().default("{}"),
860
+ createdAt: text("created_at").notNull(),
861
+ updatedAt: text("updated_at").notNull()
862
+ }, (table) => [
863
+ index("idx_capacity_grants_team_project").on(table.teamId, table.projectId, table.state),
864
+ index("idx_capacity_grants_provider_lane").on(table.capacityProviderId, table.laneId, table.state)
865
+ ]);
866
+ const capacityReservations = pgTable("capacity_reservations", {
867
+ id: text("id").primaryKey(),
868
+ capacityProviderId: text("capacity_provider_id").notNull(),
869
+ executionProviderId: text("execution_provider_id"),
870
+ laneId: text("lane_id").notNull(),
871
+ teamId: text("team_id").notNull(),
872
+ projectId: text("project_id").notNull(),
873
+ workDayId: text("work_day_id"),
874
+ taskId: text("task_id"),
875
+ state: text("state").notNull().default("reserved"),
876
+ reservedCredits: real("reserved_credits").notNull(),
877
+ consumedCredits: real("consumed_credits").notNull().default(0),
878
+ nativeUnit: text("native_unit"),
879
+ reservedNativeAmount: real("reserved_native_amount"),
880
+ consumedNativeAmount: real("consumed_native_amount"),
881
+ reservedProviderUnits: real("reserved_provider_units"),
882
+ consumedProviderUnits: real("consumed_provider_units"),
883
+ reservedUsd: real("reserved_usd"),
884
+ consumedUsd: real("consumed_usd"),
885
+ expiresAt: text("expires_at"),
886
+ metadataJson: text("metadata_json").notNull().default("{}"),
887
+ createdAt: text("created_at").notNull(),
888
+ updatedAt: text("updated_at").notNull()
889
+ }, (table) => [
890
+ index("idx_capacity_reservations_project_workday_state").on(table.projectId, table.workDayId, table.state, table.createdAt),
891
+ index("idx_capacity_reservations_provider_state").on(table.capacityProviderId, table.laneId, table.state),
892
+ index("idx_capacity_reservations_execution_provider_state").on(table.executionProviderId, table.state, table.createdAt)
893
+ ]);
894
+ const capacityLedgerEntries = pgTable("capacity_ledger_entries", {
895
+ id: text("id").primaryKey(),
896
+ capacityProviderId: text("capacity_provider_id").notNull(),
897
+ laneId: text("lane_id"),
898
+ reservationId: text("reservation_id"),
899
+ teamId: text("team_id").notNull(),
900
+ projectId: text("project_id"),
901
+ workDayId: text("work_day_id"),
902
+ taskId: text("task_id"),
903
+ phase: text("phase").notNull(),
904
+ credits: real("credits").notNull(),
905
+ providerUnits: real("provider_units"),
906
+ usd: real("usd"),
907
+ source: text("source").notNull(),
908
+ metadataJson: text("metadata_json").notNull().default("{}"),
909
+ createdAt: text("created_at").notNull()
910
+ }, (table) => [
911
+ index("idx_capacity_ledger_project_workday_created").on(table.projectId, table.workDayId, table.createdAt)
912
+ ]);
913
+ const capacityRoutingDecisions = pgTable("capacity_routing_decisions", {
914
+ id: text("id").primaryKey(),
915
+ taskId: text("task_id"),
916
+ workDayId: text("work_day_id"),
917
+ projectId: text("project_id").notNull(),
918
+ selectedProviderId: text("selected_provider_id").notNull(),
919
+ selectedLaneId: text("selected_lane_id").notNull(),
920
+ selectedModel: text("selected_model"),
921
+ decision: text("decision").notNull().default("selected"),
922
+ reason: text("reason").notNull(),
923
+ candidateJson: text("candidate_json").notNull().default("[]"),
924
+ scoreJson: text("score_json").notNull().default("{}"),
925
+ metadataJson: text("metadata_json").notNull().default("{}"),
926
+ createdAt: text("created_at").notNull()
927
+ }, (table) => [
928
+ index("idx_capacity_routing_decisions_project_workday").on(table.projectId, table.workDayId, table.createdAt)
929
+ ]);
930
+ const taskEstimates = pgTable("task_estimates", {
931
+ id: text("id").primaryKey(),
932
+ taskId: text("task_id"),
933
+ workDayId: text("work_day_id"),
934
+ projectId: text("project_id").notNull(),
935
+ estimatePhase: text("estimate_phase").notNull(),
936
+ taskSignature: text("task_signature").notNull(),
937
+ confidence: text("confidence").notNull(),
938
+ estimatedCreditsP50: real("estimated_credits_p50").notNull(),
939
+ estimatedCreditsP90: real("estimated_credits_p90").notNull(),
940
+ reservedCredits: real("reserved_credits").notNull(),
941
+ estimatedInputTokensP50: integer("estimated_input_tokens_p50"),
942
+ estimatedInputTokensP90: integer("estimated_input_tokens_p90"),
943
+ estimatedOutputTokensP50: integer("estimated_output_tokens_p50"),
944
+ estimatedOutputTokensP90: integer("estimated_output_tokens_p90"),
945
+ estimatedQuotaMinutesP50: real("estimated_quota_minutes_p50"),
946
+ estimatedQuotaMinutesP90: real("estimated_quota_minutes_p90"),
947
+ featuresJson: text("features_json").notNull().default("{}"),
948
+ createdAt: text("created_at").notNull(),
949
+ executionProfileId: text("execution_profile_id").notNull().default("standard-code-model")
950
+ }, (table) => [
951
+ index("idx_task_estimates_project_signature").on(table.projectId, table.taskSignature, table.createdAt),
952
+ index("idx_task_estimates_project_signature_profile").on(table.projectId, table.taskSignature, table.executionProfileId, table.createdAt)
953
+ ]);
954
+ const taskUsageActuals = pgTable("task_usage_actuals", {
955
+ id: text("id").primaryKey(),
956
+ taskId: text("task_id"),
957
+ workDayId: text("work_day_id"),
958
+ projectId: text("project_id").notNull(),
959
+ taskSignature: text("task_signature").notNull(),
960
+ capacityProviderId: text("capacity_provider_id"),
961
+ executionProviderId: text("execution_provider_id"),
962
+ laneId: text("lane_id"),
963
+ businessModel: text("business_model").notNull(),
964
+ modelName: text("model_name"),
965
+ inputTokens: integer("input_tokens"),
966
+ outputTokens: integer("output_tokens"),
967
+ cachedInputTokens: integer("cached_input_tokens"),
968
+ quotaMinutes: real("quota_minutes"),
969
+ wallMinutes: real("wall_minutes"),
970
+ filesOpened: integer("files_opened"),
971
+ filesChanged: integer("files_changed"),
972
+ diffLinesAdded: integer("diff_lines_added"),
973
+ diffLinesRemoved: integer("diff_lines_removed"),
974
+ testRuns: integer("test_runs"),
975
+ retryCount: integer("retry_count"),
976
+ actualCredits: real("actual_credits").notNull(),
977
+ actualUsd: real("actual_usd"),
978
+ creditFormulaVersion: text("credit_formula_version").notNull().default("treeseed.actual-credits.v1"),
979
+ actualCreditSource: text("actual_credit_source").notNull().default("central_calculator"),
980
+ nativeUsageJson: text("native_usage_json").notNull().default("{}"),
981
+ metadataJson: text("metadata_json").notNull().default("{}"),
982
+ createdAt: text("created_at").notNull(),
983
+ executionProfileId: text("execution_profile_id").notNull().default("standard-code-model")
984
+ }, (table) => [
985
+ index("idx_task_usage_actuals_project_signature").on(table.projectId, table.taskSignature, table.createdAt),
986
+ index("idx_task_usage_actuals_project_signature_profile").on(table.projectId, table.taskSignature, table.executionProfileId, table.createdAt),
987
+ index("idx_task_usage_actuals_execution_provider").on(table.executionProviderId, table.createdAt)
988
+ ]);
989
+ const nativeUsageObservations = pgTable("native_usage_observations", {
990
+ id: text("id").primaryKey(),
991
+ taskUsageActualId: text("task_usage_actual_id"),
992
+ taskId: text("task_id"),
993
+ workDayId: text("work_day_id"),
994
+ projectId: text("project_id").notNull(),
995
+ taskSignature: text("task_signature").notNull(),
996
+ executionProfileId: text("execution_profile_id").notNull().default("standard-code-model"),
997
+ capacityProviderId: text("capacity_provider_id"),
998
+ executionProviderId: text("execution_provider_id"),
999
+ nativeUnit: text("native_unit"),
1000
+ nativeUsageJson: text("native_usage_json").notNull().default("{}"),
1001
+ observedAt: text("observed_at").notNull(),
1002
+ source: text("source").notNull().default("provider_report"),
1003
+ formulaVersion: text("formula_version").notNull().default("treeseed.actual-credits.v1"),
1004
+ actualCredits: real("actual_credits").notNull(),
1005
+ metadataJson: text("metadata_json").notNull().default("{}"),
1006
+ createdAt: text("created_at").notNull()
1007
+ }, (table) => [
1008
+ index("idx_native_usage_observations_profile").on(table.projectId, table.taskSignature, table.executionProfileId, table.createdAt),
1009
+ index("idx_native_usage_observations_provider").on(table.executionProviderId, table.createdAt)
1010
+ ]);
1011
+ const approvalRequests = pgTable("approval_requests", {
1012
+ id: text("id").primaryKey(),
1013
+ teamId: text("team_id").notNull(),
1014
+ projectId: text("project_id").notNull(),
1015
+ workDayId: text("work_day_id"),
1016
+ taskId: text("task_id"),
1017
+ kind: text("kind").notNull(),
1018
+ state: text("state").notNull().default("pending"),
1019
+ severity: text("severity").notNull().default("medium"),
1020
+ requestedByType: text("requested_by_type").notNull().default("worker"),
1021
+ requestedById: text("requested_by_id"),
1022
+ title: text("title").notNull(),
1023
+ summary: text("summary").notNull(),
1024
+ optionsJson: text("options_json").notNull().default("[]"),
1025
+ recommendationJson: text("recommendation_json").notNull().default("{}"),
1026
+ policySnapshotJson: text("policy_snapshot_json").notNull().default("{}"),
1027
+ expiresAt: text("expires_at"),
1028
+ decidedByType: text("decided_by_type"),
1029
+ decidedById: text("decided_by_id"),
1030
+ decidedAt: text("decided_at"),
1031
+ decisionJson: text("decision_json"),
1032
+ metadataJson: text("metadata_json").notNull().default("{}"),
1033
+ createdAt: text("created_at").notNull(),
1034
+ updatedAt: text("updated_at").notNull()
1035
+ }, (table) => [
1036
+ index("idx_approval_requests_team_state").on(table.teamId, table.state, table.createdAt),
1037
+ index("idx_approval_requests_project_workday").on(table.projectId, table.workDayId, table.state, table.createdAt)
1038
+ ]);
1039
+ const workdayRequests = pgTable("workday_requests", {
1040
+ id: text("id").primaryKey(),
1041
+ projectId: text("project_id").notNull(),
1042
+ environment: text("environment").notNull(),
1043
+ typeColumn: text("type").notNull(),
1044
+ state: text("state").notNull().default("pending"),
1045
+ workDayId: text("work_day_id"),
1046
+ requestedBy: text("requested_by"),
1047
+ reason: text("reason"),
1048
+ payloadJson: text("payload_json").notNull(),
1049
+ metadataJson: text("metadata_json").notNull(),
1050
+ createdAt: text("created_at").notNull(),
1051
+ updatedAt: text("updated_at").notNull()
1052
+ }, (table) => [
1053
+ index("idx_workday_requests_project_environment_state").on(table.projectId, table.environment, table.state, table.createdAt)
1054
+ ]);
1055
+ const workdayManagerLeases = pgTable("workday_manager_leases", {
1056
+ id: text("id").primaryKey(),
1057
+ projectId: text("project_id").notNull(),
1058
+ environment: text("environment").notNull(),
1059
+ workDayId: text("work_day_id"),
1060
+ managerId: text("manager_id").notNull(),
1061
+ state: text("state").notNull().default("active"),
1062
+ heartbeatAt: text("heartbeat_at").notNull(),
1063
+ expiresAt: text("expires_at").notNull(),
1064
+ metadataJson: text("metadata_json").notNull(),
1065
+ createdAt: text("created_at").notNull(),
1066
+ updatedAt: text("updated_at").notNull()
1067
+ }, (table) => [
1068
+ index("idx_workday_manager_leases_active").on(table.projectId, table.environment, table.state, table.heartbeatAt)
1069
+ ]);
1070
+ const workerRunners = pgTable("worker_runners", {
1071
+ id: text("id").primaryKey(),
1072
+ projectId: text("project_id").notNull(),
1073
+ environment: text("environment").notNull(),
1074
+ runnerId: text("runner_id").notNull(),
1075
+ runnerServiceName: text("runner_service_name").notNull(),
1076
+ volumeIdentity: text("volume_identity").notNull(),
1077
+ state: text("state").notNull().default("active"),
1078
+ maxLocalWorkers: integer("max_local_workers").notNull().default(4),
1079
+ activeLocalWorkers: integer("active_local_workers").notNull().default(0),
1080
+ availableCapacity: integer("available_capacity").notNull().default(4),
1081
+ lastHeartbeatAt: text("last_heartbeat_at"),
1082
+ claimedRepositoryIdsJson: text("claimed_repository_ids_json").notNull(),
1083
+ metadataJson: text("metadata_json").notNull(),
1084
+ createdAt: text("created_at").notNull(),
1085
+ updatedAt: text("updated_at").notNull()
1086
+ }, (table) => [
1087
+ uniqueIndex("idx_worker_runners_identity").on(table.projectId, table.environment, table.runnerId),
1088
+ index("idx_worker_runners_state_capacity").on(table.projectId, table.environment, table.state, table.availableCapacity)
1089
+ ]);
1090
+ const repositoryClaims = pgTable("repository_claims", {
1091
+ id: text("id").primaryKey(),
1092
+ projectId: text("project_id").notNull(),
1093
+ repositoryId: text("repository_id").notNull(),
1094
+ runnerId: text("runner_id").notNull(),
1095
+ runnerServiceName: text("runner_service_name").notNull(),
1096
+ volumeIdentity: text("volume_identity").notNull(),
1097
+ lastSeenCommit: text("last_seen_commit"),
1098
+ lastTaskAt: text("last_task_at"),
1099
+ claimState: text("claim_state").notNull().default("active"),
1100
+ metadataJson: text("metadata_json").notNull(),
1101
+ createdAt: text("created_at").notNull(),
1102
+ updatedAt: text("updated_at").notNull()
1103
+ }, (table) => [
1104
+ uniqueIndex("idx_repository_claims_runner_repo").on(table.projectId, table.repositoryId, table.runnerId),
1105
+ index("idx_repository_claims_repo_state").on(table.projectId, table.repositoryId, table.claimState, table.updatedAt)
1106
+ ]);
1107
+ const runnerScaleDecisions = pgTable("runner_scale_decisions", {
1108
+ id: text("id").primaryKey(),
1109
+ projectId: text("project_id").notNull(),
1110
+ environment: text("environment").notNull(),
1111
+ workDayId: text("work_day_id"),
1112
+ runnerId: text("runner_id"),
1113
+ runnerServiceName: text("runner_service_name"),
1114
+ action: text("action").notNull(),
1115
+ reason: text("reason").notNull(),
1116
+ metadataJson: text("metadata_json").notNull(),
1117
+ createdAt: text("created_at").notNull()
1118
+ }, (table) => [
1119
+ index("idx_runner_scale_decisions_project_workday").on(table.projectId, table.environment, table.workDayId, table.createdAt)
1120
+ ]);
1121
+ const repositoryHosts = pgTable("repository_hosts", {
1122
+ id: text("id").primaryKey(),
1123
+ teamId: text("team_id"),
1124
+ provider: text("provider").notNull(),
1125
+ ownership: text("ownership").notNull(),
1126
+ name: text("name").notNull(),
1127
+ accountLabel: text("account_label"),
1128
+ organizationOrOwner: text("organization_or_owner").notNull(),
1129
+ defaultVisibility: text("default_visibility").notNull().default("private"),
1130
+ softwareRepositoryNameTemplate: text("software_repository_name_template").notNull().default("{hub}-site"),
1131
+ contentRepositoryNameTemplate: text("content_repository_name_template").notNull().default("{hub}-content"),
1132
+ branchPolicyJson: text("branch_policy_json").notNull().default("{}"),
1133
+ workflowPolicyJson: text("workflow_policy_json").notNull().default("{}"),
1134
+ encryptedPayloadJson: text("encrypted_payload_json"),
1135
+ allowedProjectKindsJson: text("allowed_project_kinds_json").notNull().default('["knowledge_hub"]'),
1136
+ metadataJson: text("metadata_json").notNull().default("{}"),
1137
+ status: text("status").notNull().default("active"),
1138
+ createdById: text("created_by_id"),
1139
+ updatedById: text("updated_by_id"),
1140
+ createdAt: text("created_at").notNull(),
1141
+ updatedAt: text("updated_at").notNull()
1142
+ }, (table) => [
1143
+ index("idx_repository_hosts_team_provider").on(table.teamId, table.provider, table.status),
1144
+ uniqueIndex("idx_repository_hosts_team_provider_name").on(table.teamId, table.provider, table.name),
1145
+ uniqueIndex("idx_repository_hosts_platform_provider_name").on(table.provider, table.name)
1146
+ ]);
1147
+ const hubRepositories = pgTable("hub_repositories", {
1148
+ id: text("id").primaryKey(),
1149
+ hubId: text("hub_id").notNull(),
1150
+ teamId: text("team_id").notNull(),
1151
+ role: text("role").notNull(),
1152
+ repositoryHostId: text("repository_host_id"),
1153
+ provider: text("provider").notNull(),
1154
+ owner: text("owner").notNull(),
1155
+ name: text("name").notNull(),
1156
+ url: text("url"),
1157
+ defaultBranch: text("default_branch"),
1158
+ currentBranch: text("current_branch"),
1159
+ status: text("status").notNull().default("queued"),
1160
+ accessPolicyJson: text("access_policy_json").notNull().default("{}"),
1161
+ releasePolicyJson: text("release_policy_json").notNull().default("{}"),
1162
+ publishPolicyJson: text("publish_policy_json").notNull().default("{}"),
1163
+ submodulePath: text("submodule_path"),
1164
+ metadataJson: text("metadata_json").notNull().default("{}"),
1165
+ createdAt: text("created_at").notNull(),
1166
+ updatedAt: text("updated_at").notNull()
1167
+ }, (table) => [
1168
+ uniqueIndex("idx_hub_repositories_hub_role").on(table.hubId, table.role)
1169
+ ]);
1170
+ const hubContentSources = pgTable("hub_content_sources", {
1171
+ id: text("id").primaryKey(),
1172
+ hubId: text("hub_id").notNull().unique(),
1173
+ teamId: text("team_id").notNull(),
1174
+ contentRepositoryId: text("content_repository_id"),
1175
+ productionSource: text("production_source").notNull(),
1176
+ overlayPolicy: text("overlay_policy").notNull(),
1177
+ r2BucketName: text("r2_bucket_name"),
1178
+ r2ManifestKey: text("r2_manifest_key"),
1179
+ r2PublicBaseUrl: text("r2_public_base_url"),
1180
+ latestPublishId: text("latest_publish_id"),
1181
+ latestContentVersion: text("latest_content_version"),
1182
+ metadataJson: text("metadata_json").notNull().default("{}"),
1183
+ createdAt: text("created_at").notNull(),
1184
+ updatedAt: text("updated_at").notNull()
1185
+ });
1186
+ const hubLaunches = pgTable("hub_launches", {
1187
+ id: text("id").primaryKey(),
1188
+ hubId: text("hub_id").notNull(),
1189
+ teamId: text("team_id").notNull(),
1190
+ jobId: text("job_id"),
1191
+ intentJson: text("intent_json").notNull(),
1192
+ planJson: text("plan_json").notNull().default("{}"),
1193
+ state: text("state").notNull(),
1194
+ currentPhase: text("current_phase"),
1195
+ lastSuccessfulPhase: text("last_successful_phase"),
1196
+ resultJson: text("result_json"),
1197
+ errorJson: text("error_json"),
1198
+ createdAt: text("created_at").notNull(),
1199
+ updatedAt: text("updated_at").notNull(),
1200
+ completedAt: text("completed_at")
1201
+ }, (table) => [
1202
+ index("idx_hub_launches_hub_created").on(table.hubId, table.createdAt)
1203
+ ]);
1204
+ const hubLaunchEvents = pgTable("hub_launch_events", {
1205
+ id: text("id").primaryKey(),
1206
+ launchId: text("launch_id").notNull(),
1207
+ seq: integer("seq").notNull(),
1208
+ phase: text("phase").notNull(),
1209
+ status: text("status").notNull(),
1210
+ title: text("title"),
1211
+ summary: text("summary"),
1212
+ startedAt: text("started_at"),
1213
+ finishedAt: text("finished_at"),
1214
+ errorJson: text("error_json"),
1215
+ dataJson: text("data_json").notNull().default("{}"),
1216
+ createdAt: text("created_at").notNull()
1217
+ }, (table) => [
1218
+ uniqueIndex("idx_hub_launch_events_launch_seq").on(table.launchId, table.seq)
1219
+ ]);
1220
+ const hubWorkspaceLinks = pgTable("hub_workspace_links", {
1221
+ id: text("id").primaryKey(),
1222
+ hubId: text("hub_id").notNull(),
1223
+ teamId: text("team_id").notNull(),
1224
+ parentRepositoryHostId: text("parent_repository_host_id"),
1225
+ parentOwner: text("parent_owner"),
1226
+ parentName: text("parent_name"),
1227
+ parentUrl: text("parent_url"),
1228
+ parentBranch: text("parent_branch"),
1229
+ hubMountPath: text("hub_mount_path"),
1230
+ softwareSubmodulePath: text("software_submodule_path"),
1231
+ contentSubmodulePath: text("content_submodule_path"),
1232
+ updateSubmodulePointersEnabled: integer("update_submodule_pointers_enabled").notNull().default(0),
1233
+ accessPolicyJson: text("access_policy_json").notNull().default("{}"),
1234
+ metadataJson: text("metadata_json").notNull().default("{}"),
1235
+ createdAt: text("created_at").notNull(),
1236
+ updatedAt: text("updated_at").notNull()
1237
+ }, (table) => [
1238
+ index("idx_hub_workspace_links_hub").on(table.hubId)
1239
+ ]);
1240
+ const projectUpdatePlans = pgTable("project_update_plans", {
1241
+ id: text("id").primaryKey(),
1242
+ hubId: text("hub_id").notNull(),
1243
+ teamId: text("team_id").notNull(),
1244
+ sourceKind: text("source_kind").notNull(),
1245
+ sourceRef: text("source_ref"),
1246
+ sourceVersion: text("source_version"),
1247
+ planJson: text("plan_json").notNull().default("{}"),
1248
+ state: text("state").notNull().default("planned"),
1249
+ requiresDecision: integer("requires_decision").notNull().default(0),
1250
+ decisionId: text("decision_id"),
1251
+ createdBy: text("created_by"),
1252
+ createdAt: text("created_at").notNull(),
1253
+ updatedAt: text("updated_at").notNull()
1254
+ }, (table) => [
1255
+ index("idx_project_update_plans_hub").on(table.hubId, table.createdAt)
1256
+ ]);
1257
+ const providerCredentialSessions = pgTable("provider_credential_sessions", {
1258
+ id: text("id").primaryKey(),
1259
+ teamId: text("team_id").notNull(),
1260
+ projectId: text("project_id"),
1261
+ jobId: text("job_id"),
1262
+ hostKind: text("host_kind").notNull(),
1263
+ hostId: text("host_id").notNull(),
1264
+ purpose: text("purpose").notNull(),
1265
+ encryptedPayloadJson: text("encrypted_payload_json").notNull(),
1266
+ status: text("status").notNull().default("active"),
1267
+ expiresAt: text("expires_at").notNull(),
1268
+ consumedAt: text("consumed_at"),
1269
+ createdById: text("created_by_id"),
1270
+ createdAt: text("created_at").notNull(),
1271
+ updatedAt: text("updated_at").notNull(),
1272
+ metadataJson: text("metadata_json").notNull().default("{}")
1273
+ }, (table) => [
1274
+ index("idx_provider_credential_sessions_team_host").on(table.teamId, table.hostKind, table.hostId, table.status),
1275
+ index("idx_provider_credential_sessions_job").on(table.jobId, table.status)
1276
+ ]);
1277
+ const capacityProviderApiKeys = pgTable("capacity_provider_api_keys", {
1278
+ id: text("id").primaryKey(),
1279
+ capacityProviderId: text("capacity_provider_id").notNull(),
1280
+ teamId: text("team_id").notNull(),
1281
+ name: text("name").notNull(),
1282
+ keyPrefix: text("key_prefix").notNull(),
1283
+ keyHash: text("key_hash").notNull(),
1284
+ scopesJson: text("scopes_json").notNull().default("[]"),
1285
+ status: text("status").notNull().default("active"),
1286
+ lastUsedAt: text("last_used_at"),
1287
+ rotatedFromKeyId: text("rotated_from_key_id"),
1288
+ expiresAt: text("expires_at"),
1289
+ revokedAt: text("revoked_at"),
1290
+ createdById: text("created_by_id"),
1291
+ createdAt: text("created_at").notNull(),
1292
+ updatedAt: text("updated_at").notNull()
1293
+ }, (table) => [
1294
+ index("idx_capacity_provider_api_keys_provider_status").on(table.capacityProviderId, table.status, table.createdAt),
1295
+ index("idx_capacity_provider_api_keys_prefix").on(table.keyPrefix)
1296
+ ]);
1297
+ const userPreferences = pgTable("user_preferences", {
1298
+ userId: text("user_id").primaryKey(),
1299
+ colorScheme: text("color_scheme").notNull().default("fern"),
1300
+ themeMode: text("theme_mode").notNull().default("system"),
1301
+ createdAt: text("created_at").notNull(),
1302
+ updatedAt: text("updated_at").notNull()
1303
+ });
1304
+ const taskEstimateProfiles = pgTable("task_estimate_profiles", {
1305
+ taskSignature: text("task_signature"),
1306
+ executionProfileId: text("execution_profile_id").default("standard-code-model"),
1307
+ sampleCount: integer("sample_count").notNull().default(0),
1308
+ completedSampleCount: integer("completed_sample_count").notNull().default(0),
1309
+ interruptedSampleCount: integer("interrupted_sample_count").notNull().default(0),
1310
+ inputTokensP50: integer("input_tokens_p50"),
1311
+ inputTokensP90: integer("input_tokens_p90"),
1312
+ outputTokensP50: integer("output_tokens_p50"),
1313
+ outputTokensP90: integer("output_tokens_p90"),
1314
+ quotaMinutesP50: real("quota_minutes_p50"),
1315
+ quotaMinutesP90: real("quota_minutes_p90"),
1316
+ filesChangedP50: real("files_changed_p50"),
1317
+ filesChangedP90: real("files_changed_p90"),
1318
+ creditsP50: real("credits_p50"),
1319
+ creditsP90: real("credits_p90"),
1320
+ creditsVariance: real("credits_variance"),
1321
+ confidenceScore: real("confidence_score"),
1322
+ outlierCount: integer("outlier_count").notNull().default(0),
1323
+ partialCredits: real("partial_credits"),
1324
+ firstSampleAt: text("first_sample_at"),
1325
+ lastSampleAt: text("last_sample_at"),
1326
+ updatedAt: text("updated_at").notNull()
1327
+ }, (table) => [
1328
+ primaryKey({ columns: [table.taskSignature, table.executionProfileId] })
1329
+ ]);
1330
+ const creditConversionProfiles = pgTable("credit_conversion_profiles", {
1331
+ id: text("id").primaryKey(),
1332
+ taskSignature: text("task_signature").notNull(),
1333
+ executionProfileId: text("execution_profile_id").notNull().default("standard-code-model"),
1334
+ executionProviderKind: text("execution_provider_kind").notNull(),
1335
+ nativeUnit: text("native_unit").notNull(),
1336
+ sampleCount: integer("sample_count").notNull().default(0),
1337
+ completedSampleCount: integer("completed_sample_count").notNull().default(0),
1338
+ interruptedSampleCount: integer("interrupted_sample_count").notNull().default(0),
1339
+ nativeUnitsPerCreditP50: real("native_units_per_credit_p50"),
1340
+ nativeUnitsPerCreditP90: real("native_units_per_credit_p90"),
1341
+ creditsPerNativeUnitP50: real("credits_per_native_unit_p50"),
1342
+ creditsPerNativeUnitP90: real("credits_per_native_unit_p90"),
1343
+ actualCreditsP50: real("actual_credits_p50"),
1344
+ actualCreditsP90: real("actual_credits_p90"),
1345
+ confidence: text("confidence").notNull().default("low"),
1346
+ formulaVersion: text("formula_version").notNull(),
1347
+ metadataJson: text("metadata_json").notNull().default("{}"),
1348
+ createdAt: text("created_at").notNull(),
1349
+ updatedAt: text("updated_at").notNull()
1350
+ }, (table) => [
1351
+ uniqueIndex("idx_credit_conversion_profiles_profile_key").on(table.taskSignature, table.executionProfileId, table.executionProviderKind, table.nativeUnit),
1352
+ index("idx_credit_conversion_profiles_kind_unit").on(table.executionProviderKind, table.nativeUnit, table.updatedAt)
1353
+ ]);
1354
+ const seedRuns = pgTable("seed_runs", {
1355
+ id: text("id").primaryKey(),
1356
+ seedName: text("seed_name").notNull(),
1357
+ seedVersion: integer("seed_version").notNull(),
1358
+ environmentsJson: text("environments_json").notNull(),
1359
+ mode: text("mode").notNull(),
1360
+ state: text("state").notNull(),
1361
+ actorType: text("actor_type"),
1362
+ actorId: text("actor_id"),
1363
+ manifestHash: text("manifest_hash").notNull(),
1364
+ planJson: text("plan_json").notNull(),
1365
+ resultJson: text("result_json"),
1366
+ errorJson: text("error_json"),
1367
+ createdAt: text("created_at").notNull(),
1368
+ updatedAt: text("updated_at").notNull(),
1369
+ completedAt: text("completed_at")
1370
+ }, (table) => [
1371
+ index("idx_seed_runs_seed_created").on(table.seedName, table.createdAt),
1372
+ index("idx_seed_runs_state_created").on(table.state, table.createdAt)
1373
+ ]);
1374
+ const runtimeRecords = pgTable("runtime_records", {
1375
+ id: serial("id").primaryKey(),
1376
+ recordType: text("record_type").notNull(),
1377
+ recordKey: text("record_key").notNull(),
1378
+ lookupKey: text("lookup_key"),
1379
+ secondaryKey: text("secondary_key"),
1380
+ status: text("status").notNull(),
1381
+ schemaVersion: integer("schema_version").notNull().default(1),
1382
+ createdAt: text("created_at").notNull(),
1383
+ updatedAt: text("updated_at").notNull(),
1384
+ payloadJson: text("payload_json").notNull(),
1385
+ metaJson: text("meta_json").notNull()
1386
+ }, (table) => [
1387
+ index("idx_runtime_records_type_lookup_updated").on(table.recordType, table.lookupKey, table.updatedAt),
1388
+ index("idx_runtime_records_type_status_updated").on(table.recordType, table.status, table.updatedAt)
1389
+ ]);
1390
+ const cursorState = pgTable("cursor_state", {
1391
+ agentSlug: text("agent_slug"),
1392
+ cursorKey: text("cursor_key"),
1393
+ status: text("status").notNull(),
1394
+ schemaVersion: integer("schema_version").notNull().default(1),
1395
+ updatedAt: text("updated_at").notNull(),
1396
+ payloadJson: text("payload_json").notNull(),
1397
+ metaJson: text("meta_json").notNull()
1398
+ }, (table) => [
1399
+ primaryKey({ columns: [table.agentSlug, table.cursorKey] }),
1400
+ index("idx_cursor_state_updated").on(table.updatedAt)
1401
+ ]);
1402
+ const leaseState = pgTable("lease_state", {
1403
+ model: text("model"),
1404
+ itemKey: text("item_key"),
1405
+ status: text("status").notNull(),
1406
+ schemaVersion: integer("schema_version").notNull().default(1),
1407
+ claimedBy: text("claimed_by"),
1408
+ claimedAt: text("claimed_at"),
1409
+ leaseExpiresAt: text("lease_expires_at"),
1410
+ createdAt: text("created_at").notNull(),
1411
+ updatedAt: text("updated_at").notNull(),
1412
+ payloadJson: text("payload_json").notNull(),
1413
+ metaJson: text("meta_json").notNull()
1414
+ }, (table) => [
1415
+ primaryKey({ columns: [table.model, table.itemKey] }),
1416
+ index("idx_lease_state_status_expires").on(table.status, table.leaseExpiresAt),
1417
+ index("idx_lease_state_claimed_by").on(table.claimedBy, table.updatedAt)
1418
+ ]);
1419
+ const messageQueue = pgTable("message_queue", {
1420
+ id: serial("id").primaryKey(),
1421
+ messageType: text("message_type").notNull(),
1422
+ status: text("status").notNull(),
1423
+ schemaVersion: integer("schema_version").notNull().default(1),
1424
+ relatedModel: text("related_model"),
1425
+ relatedId: text("related_id"),
1426
+ priority: integer("priority").notNull().default(0),
1427
+ availableAt: text("available_at").notNull(),
1428
+ claimedBy: text("claimed_by"),
1429
+ claimedAt: text("claimed_at"),
1430
+ leaseExpiresAt: text("lease_expires_at"),
1431
+ attempts: integer("attempts").notNull().default(0),
1432
+ maxAttempts: integer("max_attempts").notNull().default(3),
1433
+ createdAt: text("created_at").notNull(),
1434
+ updatedAt: text("updated_at").notNull(),
1435
+ payloadJson: text("payload_json").notNull(),
1436
+ metaJson: text("meta_json").notNull()
1437
+ }, (table) => [
1438
+ index("idx_message_queue_claimable").on(table.status, table.availableAt, table.priority),
1439
+ index("idx_message_queue_related").on(table.relatedModel, table.relatedId, table.createdAt)
1440
+ ]);
1441
+ const capacityProviderRegistrations = pgTable("capacity_provider_registrations", {
1442
+ id: text("id").primaryKey(),
1443
+ capacityProviderId: text("capacity_provider_id").notNull(),
1444
+ teamId: text("team_id").notNull(),
1445
+ runtimeVersion: text("runtime_version").notNull(),
1446
+ marketId: text("market_id").notNull(),
1447
+ capabilitiesJson: text("capabilities_json").notNull().default("[]"),
1448
+ budgetsJson: text("budgets_json").notNull().default("{}"),
1449
+ healthJson: text("health_json").notNull().default("{}"),
1450
+ status: text("status").notNull().default("online"),
1451
+ registeredAt: text("registered_at").notNull(),
1452
+ lastSeenAt: text("last_seen_at").notNull(),
1453
+ disconnectedAt: text("disconnected_at"),
1454
+ createdAt: text("created_at").notNull(),
1455
+ updatedAt: text("updated_at").notNull()
1456
+ }, (table) => [
1457
+ index("idx_capacity_provider_registrations_provider_seen").on(table.capacityProviderId, table.lastSeenAt)
1458
+ ]);
1459
+ const capacityProviderDeployments = pgTable("capacity_provider_deployments", {
1460
+ id: text("id").primaryKey(),
1461
+ teamId: text("team_id").notNull(),
1462
+ capacityProviderId: text("capacity_provider_id").notNull(),
1463
+ launchMode: text("launch_mode").notNull(),
1464
+ hostKind: text("host_kind").notNull(),
1465
+ hostId: text("host_id"),
1466
+ status: text("status").notNull(),
1467
+ imageRef: text("image_ref"),
1468
+ serviceRefsJson: text("service_refs_json").notNull().default("{}"),
1469
+ envRefsJson: text("env_refs_json").notNull().default("{}"),
1470
+ resultJson: text("result_json").notNull().default("{}"),
1471
+ errorJson: text("error_json"),
1472
+ createdById: text("created_by_id"),
1473
+ createdAt: text("created_at").notNull(),
1474
+ updatedAt: text("updated_at").notNull(),
1475
+ completedAt: text("completed_at")
1476
+ }, (table) => [
1477
+ index("idx_capacity_provider_deployments_provider_created").on(table.capacityProviderId, table.createdAt)
1478
+ ]);
1479
+ const platformOperations = pgTable("platform_operations", {
1480
+ id: text("id").primaryKey(),
1481
+ namespace: text("namespace").notNull(),
1482
+ operation: text("operation").notNull(),
1483
+ status: text("status").notNull(),
1484
+ target: text("target").notNull(),
1485
+ idempotencyKey: text("idempotency_key"),
1486
+ inputJson: text("input_json").notNull().default("{}"),
1487
+ outputJson: text("output_json"),
1488
+ errorJson: text("error_json"),
1489
+ requestedByType: text("requested_by_type").notNull(),
1490
+ requestedById: text("requested_by_id"),
1491
+ assignedRunnerId: text("assigned_runner_id"),
1492
+ leaseExpiresAt: text("lease_expires_at"),
1493
+ createdAt: text("created_at").notNull(),
1494
+ updatedAt: text("updated_at").notNull(),
1495
+ startedAt: text("started_at"),
1496
+ finishedAt: text("finished_at"),
1497
+ cancelledAt: text("cancelled_at")
1498
+ }, (table) => [
1499
+ uniqueIndex("idx_platform_operations_idempotency").on(table.namespace, table.operation, table.idempotencyKey),
1500
+ index("idx_platform_operations_runnable").on(table.status, table.createdAt)
1501
+ ]);
1502
+ const platformOperationEvents = pgTable("platform_operation_events", {
1503
+ id: text("id").primaryKey(),
1504
+ operationId: text("operation_id").notNull(),
1505
+ seq: integer("seq").notNull(),
1506
+ kind: text("kind").notNull(),
1507
+ dataJson: text("data_json").notNull().default("{}"),
1508
+ createdAt: text("created_at").notNull()
1509
+ }, (table) => [
1510
+ uniqueIndex("idx_platform_operation_events_seq").on(table.operationId, table.seq)
1511
+ ]);
1512
+ const marketOperationRunners = pgTable("market_operation_runners", {
1513
+ id: text("id").primaryKey(),
1514
+ runnerKey: text("runner_key").notNull().unique(),
1515
+ name: text("name").notNull(),
1516
+ environment: text("environment").notNull(),
1517
+ status: text("status").notNull().default("online"),
1518
+ version: text("version"),
1519
+ capabilitiesJson: text("capabilities_json").notNull().default("[]"),
1520
+ activeJobCount: integer("active_job_count").notNull().default(0),
1521
+ maxConcurrentJobs: integer("max_concurrent_jobs").notNull().default(1),
1522
+ heartbeatAt: text("heartbeat_at"),
1523
+ metadataJson: text("metadata_json").notNull().default("{}"),
1524
+ createdAt: text("created_at").notNull(),
1525
+ updatedAt: text("updated_at").notNull()
1526
+ });
1527
+ const platformRepositoryClaims = pgTable("platform_repository_claims", {
1528
+ id: text("id").primaryKey(),
1529
+ repositoryKey: text("repository_key").notNull(),
1530
+ runnerId: text("runner_id").notNull(),
1531
+ workspacePath: text("workspace_path").notNull(),
1532
+ branch: text("branch"),
1533
+ commitSha: text("commit_sha"),
1534
+ claimState: text("claim_state").notNull().default("active"),
1535
+ leaseExpiresAt: text("lease_expires_at"),
1536
+ metadataJson: text("metadata_json").notNull().default("{}"),
1537
+ createdAt: text("created_at").notNull(),
1538
+ updatedAt: text("updated_at").notNull()
1539
+ }, (table) => [
1540
+ uniqueIndex("idx_platform_repository_claims_active").on(table.repositoryKey, table.runnerId),
1541
+ index("idx_platform_repository_claims_runner").on(table.runnerId, table.claimState)
1542
+ ]);
1543
+ const executionProviders = pgTable("execution_providers", {
1544
+ id: text("id").primaryKey(),
1545
+ teamId: text("team_id").notNull(),
1546
+ capacityProviderId: text("capacity_provider_id"),
1547
+ name: text("name").notNull(),
1548
+ kind: text("kind").notNull(),
1549
+ status: text("status").notNull().default("active"),
1550
+ nativeUnit: text("native_unit").notNull(),
1551
+ quotaVisibility: text("quota_visibility").notNull().default("opaque"),
1552
+ maxConcurrentWorkers: integer("max_concurrent_workers").notNull().default(1),
1553
+ resetCadence: text("reset_cadence"),
1554
+ configJson: text("config_json").notNull().default("{}"),
1555
+ metadataJson: text("metadata_json").notNull().default("{}"),
1556
+ createdAt: text("created_at").notNull(),
1557
+ updatedAt: text("updated_at").notNull()
1558
+ }, (table) => [
1559
+ index("idx_execution_providers_team_status").on(table.teamId, table.status, table.kind),
1560
+ index("idx_execution_providers_capacity_provider").on(table.capacityProviderId, table.status)
1561
+ ]);
1562
+ const executionProviderNativeLimits = pgTable("execution_provider_native_limits", {
1563
+ id: text("id").primaryKey(),
1564
+ executionProviderId: text("execution_provider_id").notNull(),
1565
+ scope: text("scope").notNull(),
1566
+ nativeUnit: text("native_unit").notNull(),
1567
+ limitAmount: real("limit_amount").notNull(),
1568
+ reserveBufferPercent: real("reserve_buffer_percent").notNull().default(0),
1569
+ resetCadence: text("reset_cadence"),
1570
+ resetAt: text("reset_at"),
1571
+ confidence: text("confidence").notNull().default("estimated"),
1572
+ source: text("source").notNull().default("configured"),
1573
+ metadataJson: text("metadata_json").notNull().default("{}"),
1574
+ createdAt: text("created_at").notNull(),
1575
+ updatedAt: text("updated_at").notNull()
1576
+ }, (table) => [
1577
+ index("idx_execution_provider_native_limits_provider_scope").on(table.executionProviderId, table.scope, table.nativeUnit)
1578
+ ]);
1579
+ const executionProviderObservations = pgTable("execution_provider_observations", {
1580
+ id: text("id").primaryKey(),
1581
+ executionProviderId: text("execution_provider_id").notNull(),
1582
+ observedAt: text("observed_at").notNull(),
1583
+ health: text("health").notNull().default("unknown"),
1584
+ activeWorkers: integer("active_workers"),
1585
+ queuedTasks: integer("queued_tasks"),
1586
+ throttleState: text("throttle_state"),
1587
+ nativeRemainingJson: text("native_remaining_json").notNull().default("{}"),
1588
+ resetAt: text("reset_at"),
1589
+ confidence: text("confidence").notNull().default("estimated"),
1590
+ metadataJson: text("metadata_json").notNull().default("{}"),
1591
+ createdAt: text("created_at").notNull()
1592
+ }, (table) => [
1593
+ index("idx_execution_provider_observations_provider_observed").on(table.executionProviderId, table.observedAt)
1594
+ ]);
1595
+ const marketAuthCredentials = pgTable("market_auth_credentials", {
1596
+ userId: text("user_id").primaryKey(),
1597
+ email: text("email").notNull().unique(),
1598
+ username: text("username").unique(),
1599
+ passwordHash: text("password_hash").notNull(),
1600
+ status: text("status").notNull().default("active"),
1601
+ createdAt: text("created_at").notNull(),
1602
+ updatedAt: text("updated_at").notNull()
1603
+ });
1604
+ const marketAuthPasswordResets = pgTable("market_auth_password_resets", {
1605
+ id: text("id").primaryKey(),
1606
+ userId: text("user_id").notNull(),
1607
+ tokenHash: text("token_hash").notNull().unique(),
1608
+ expiresAt: text("expires_at").notNull(),
1609
+ usedAt: text("used_at"),
1610
+ createdAt: text("created_at").notNull()
1611
+ });
1612
+ const treeseedMarketSchema = {
1613
+ subscribers,
1614
+ agentRuns,
1615
+ agentMessages,
1616
+ contactSubmissions,
1617
+ runtimeEnvelopes,
1618
+ workDays,
1619
+ tasks,
1620
+ taskEvents,
1621
+ taskOutputs,
1622
+ graphRuns,
1623
+ reports,
1624
+ users,
1625
+ userIdentities,
1626
+ roles,
1627
+ permissions,
1628
+ rolePermissions,
1629
+ userRoleBindings,
1630
+ apiTokens,
1631
+ serviceCredentials,
1632
+ authSessions,
1633
+ auditEvents,
1634
+ deviceCodes,
1635
+ teams,
1636
+ teamMemberships,
1637
+ teamRoleBindings,
1638
+ webSessions,
1639
+ projects,
1640
+ projectConnections,
1641
+ projectCapabilityGrants,
1642
+ teamApiKeys,
1643
+ entitlements,
1644
+ remoteJobs,
1645
+ remoteJobEvents,
1646
+ knowledgePacks,
1647
+ teamStorageLocators,
1648
+ catalogItems,
1649
+ catalogArtifactVersions,
1650
+ catalogItemCollaborators,
1651
+ projectHosting,
1652
+ projectEnvironments,
1653
+ projectInfrastructureResources,
1654
+ projectDeployments,
1655
+ agentPools,
1656
+ agentPoolRegistrations,
1657
+ agentPoolScaleDecisions,
1658
+ projectWorkdaySummaries,
1659
+ workPolicies,
1660
+ priorityOverrides,
1661
+ prioritySnapshots,
1662
+ taskCreditLedger,
1663
+ scaleDecisions,
1664
+ projectSummarySnapshots,
1665
+ teamInboxItems,
1666
+ betterAuthUser,
1667
+ betterAuthSession,
1668
+ betterAuthAccount,
1669
+ betterAuthVerification,
1670
+ teamWebHosts,
1671
+ teamInvites,
1672
+ capacityProviders,
1673
+ capacityProviderHosts,
1674
+ capacityProviderLanes,
1675
+ capacityGrants,
1676
+ capacityReservations,
1677
+ capacityLedgerEntries,
1678
+ capacityRoutingDecisions,
1679
+ taskEstimates,
1680
+ taskUsageActuals,
1681
+ nativeUsageObservations,
1682
+ approvalRequests,
1683
+ workdayRequests,
1684
+ workdayManagerLeases,
1685
+ workerRunners,
1686
+ repositoryClaims,
1687
+ runnerScaleDecisions,
1688
+ repositoryHosts,
1689
+ hubRepositories,
1690
+ hubContentSources,
1691
+ hubLaunches,
1692
+ hubLaunchEvents,
1693
+ hubWorkspaceLinks,
1694
+ projectUpdatePlans,
1695
+ providerCredentialSessions,
1696
+ capacityProviderApiKeys,
1697
+ userPreferences,
1698
+ taskEstimateProfiles,
1699
+ creditConversionProfiles,
1700
+ seedRuns,
1701
+ runtimeRecords,
1702
+ cursorState,
1703
+ leaseState,
1704
+ messageQueue,
1705
+ capacityProviderRegistrations,
1706
+ capacityProviderDeployments,
1707
+ platformOperations,
1708
+ platformOperationEvents,
1709
+ marketOperationRunners,
1710
+ platformRepositoryClaims,
1711
+ executionProviders,
1712
+ executionProviderNativeLimits,
1713
+ executionProviderObservations,
1714
+ marketAuthCredentials,
1715
+ marketAuthPasswordResets
1716
+ };
1717
+ export {
1718
+ agentMessages,
1719
+ agentPoolRegistrations,
1720
+ agentPoolScaleDecisions,
1721
+ agentPools,
1722
+ agentRuns,
1723
+ apiTokens,
1724
+ approvalRequests,
1725
+ auditEvents,
1726
+ authSessions,
1727
+ betterAuthAccount,
1728
+ betterAuthSession,
1729
+ betterAuthUser,
1730
+ betterAuthVerification,
1731
+ capacityGrants,
1732
+ capacityLedgerEntries,
1733
+ capacityProviderApiKeys,
1734
+ capacityProviderDeployments,
1735
+ capacityProviderHosts,
1736
+ capacityProviderLanes,
1737
+ capacityProviderRegistrations,
1738
+ capacityProviders,
1739
+ capacityReservations,
1740
+ capacityRoutingDecisions,
1741
+ catalogArtifactVersions,
1742
+ catalogItemCollaborators,
1743
+ catalogItems,
1744
+ contactSubmissions,
1745
+ creditConversionProfiles,
1746
+ cursorState,
1747
+ deviceCodes,
1748
+ entitlements,
1749
+ executionProviderNativeLimits,
1750
+ executionProviderObservations,
1751
+ executionProviders,
1752
+ graphRuns,
1753
+ hubContentSources,
1754
+ hubLaunchEvents,
1755
+ hubLaunches,
1756
+ hubRepositories,
1757
+ hubWorkspaceLinks,
1758
+ knowledgePacks,
1759
+ leaseState,
1760
+ marketAuthCredentials,
1761
+ marketAuthPasswordResets,
1762
+ marketOperationRunners,
1763
+ messageQueue,
1764
+ nativeUsageObservations,
1765
+ permissions,
1766
+ platformOperationEvents,
1767
+ platformOperations,
1768
+ platformRepositoryClaims,
1769
+ priorityOverrides,
1770
+ prioritySnapshots,
1771
+ projectCapabilityGrants,
1772
+ projectConnections,
1773
+ projectDeployments,
1774
+ projectEnvironments,
1775
+ projectHosting,
1776
+ projectInfrastructureResources,
1777
+ projectSummarySnapshots,
1778
+ projectUpdatePlans,
1779
+ projectWorkdaySummaries,
1780
+ projects,
1781
+ providerCredentialSessions,
1782
+ remoteJobEvents,
1783
+ remoteJobs,
1784
+ reports,
1785
+ repositoryClaims,
1786
+ repositoryHosts,
1787
+ rolePermissions,
1788
+ roles,
1789
+ runnerScaleDecisions,
1790
+ runtimeEnvelopes,
1791
+ runtimeRecords,
1792
+ scaleDecisions,
1793
+ seedRuns,
1794
+ serviceCredentials,
1795
+ subscribers,
1796
+ taskCreditLedger,
1797
+ taskEstimateProfiles,
1798
+ taskEstimates,
1799
+ taskEvents,
1800
+ taskOutputs,
1801
+ taskUsageActuals,
1802
+ tasks,
1803
+ teamApiKeys,
1804
+ teamInboxItems,
1805
+ teamInvites,
1806
+ teamMemberships,
1807
+ teamRoleBindings,
1808
+ teamStorageLocators,
1809
+ teamWebHosts,
1810
+ teams,
1811
+ treeseedMarketSchema,
1812
+ userIdentities,
1813
+ userPreferences,
1814
+ userRoleBindings,
1815
+ users,
1816
+ webSessions,
1817
+ workDays,
1818
+ workPolicies,
1819
+ workdayManagerLeases,
1820
+ workdayRequests,
1821
+ workerRunners
1822
+ };