bopodev-db 0.1.26 → 0.1.28
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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-typecheck.log +1 -1
- package/README.md +29 -0
- package/dist/bootstrap.d.ts +3 -3
- package/dist/client.d.ts +34 -6
- package/dist/index.d.ts +2 -0
- package/dist/migrate.d.ts +1 -0
- package/dist/repositories.d.ts +20 -72
- package/dist/schema.d.ts +0 -320
- package/drizzle.config.ts +10 -0
- package/package.json +10 -3
- package/src/bootstrap.ts +9 -606
- package/src/client.ts +499 -9
- package/src/default-paths.ts +1 -1
- package/src/index.ts +2 -0
- package/src/migrate.ts +20 -0
- package/src/migrations/0000_initial.sql +389 -0
- package/src/migrations/meta/_journal.json +13 -0
- package/src/repositories.ts +17 -73
- package/src/schema.ts +0 -19
- package/.turbo/turbo-lint.log +0 -4
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
CREATE TABLE "companies" (
|
|
2
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
3
|
+
"name" text NOT NULL,
|
|
4
|
+
"mission" text,
|
|
5
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
6
|
+
);
|
|
7
|
+
--> statement-breakpoint
|
|
8
|
+
CREATE TABLE "projects" (
|
|
9
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
10
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
11
|
+
"name" text NOT NULL,
|
|
12
|
+
"description" text,
|
|
13
|
+
"status" text DEFAULT 'planned' NOT NULL,
|
|
14
|
+
"planned_start_at" timestamp,
|
|
15
|
+
"monthly_budget_usd" numeric(12, 4) DEFAULT 100 NOT NULL,
|
|
16
|
+
"used_budget_usd" numeric(12, 4) DEFAULT 0 NOT NULL,
|
|
17
|
+
"budget_window_start_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
18
|
+
"execution_workspace_policy" text,
|
|
19
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
20
|
+
"updated_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
21
|
+
);
|
|
22
|
+
--> statement-breakpoint
|
|
23
|
+
CREATE TABLE "project_workspaces" (
|
|
24
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
25
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
26
|
+
"project_id" text NOT NULL REFERENCES "projects"("id") ON DELETE CASCADE,
|
|
27
|
+
"name" text NOT NULL,
|
|
28
|
+
"cwd" text,
|
|
29
|
+
"repo_url" text,
|
|
30
|
+
"repo_ref" text,
|
|
31
|
+
"is_primary" boolean DEFAULT false NOT NULL,
|
|
32
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
33
|
+
"updated_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
34
|
+
);
|
|
35
|
+
--> statement-breakpoint
|
|
36
|
+
CREATE TABLE "goals" (
|
|
37
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
38
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
39
|
+
"project_id" text REFERENCES "projects"("id") ON DELETE SET NULL,
|
|
40
|
+
"parent_goal_id" text,
|
|
41
|
+
"level" text NOT NULL,
|
|
42
|
+
"title" text NOT NULL,
|
|
43
|
+
"description" text,
|
|
44
|
+
"status" text DEFAULT 'draft' NOT NULL,
|
|
45
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
46
|
+
"updated_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
47
|
+
);
|
|
48
|
+
--> statement-breakpoint
|
|
49
|
+
CREATE TABLE "agents" (
|
|
50
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
51
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
52
|
+
"manager_agent_id" text,
|
|
53
|
+
"role" text NOT NULL,
|
|
54
|
+
"role_key" text,
|
|
55
|
+
"title" text,
|
|
56
|
+
"name" text NOT NULL,
|
|
57
|
+
"provider_type" text NOT NULL,
|
|
58
|
+
"status" text DEFAULT 'idle' NOT NULL,
|
|
59
|
+
"heartbeat_cron" text NOT NULL,
|
|
60
|
+
"monthly_budget_usd" numeric(12, 4) DEFAULT 0 NOT NULL,
|
|
61
|
+
"used_budget_usd" numeric(12, 4) DEFAULT 0 NOT NULL,
|
|
62
|
+
"token_usage" integer DEFAULT 0 NOT NULL,
|
|
63
|
+
"can_hire_agents" boolean DEFAULT false NOT NULL,
|
|
64
|
+
"avatar_seed" text DEFAULT '' NOT NULL,
|
|
65
|
+
"runtime_command" text,
|
|
66
|
+
"runtime_args_json" text DEFAULT '[]' NOT NULL,
|
|
67
|
+
"runtime_cwd" text,
|
|
68
|
+
"runtime_env_json" text DEFAULT '{}' NOT NULL,
|
|
69
|
+
"runtime_model" text,
|
|
70
|
+
"runtime_thinking_effort" text DEFAULT 'auto' NOT NULL,
|
|
71
|
+
"bootstrap_prompt" text,
|
|
72
|
+
"runtime_timeout_sec" integer DEFAULT 0 NOT NULL,
|
|
73
|
+
"interrupt_grace_sec" integer DEFAULT 15 NOT NULL,
|
|
74
|
+
"run_policy_json" text DEFAULT '{}' NOT NULL,
|
|
75
|
+
"state_blob" text DEFAULT '{}' NOT NULL,
|
|
76
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
77
|
+
"updated_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
78
|
+
);
|
|
79
|
+
--> statement-breakpoint
|
|
80
|
+
CREATE TABLE "issues" (
|
|
81
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
82
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
83
|
+
"project_id" text NOT NULL REFERENCES "projects"("id") ON DELETE CASCADE,
|
|
84
|
+
"parent_issue_id" text,
|
|
85
|
+
"title" text NOT NULL,
|
|
86
|
+
"body" text,
|
|
87
|
+
"status" text DEFAULT 'todo' NOT NULL,
|
|
88
|
+
"priority" text DEFAULT 'none' NOT NULL,
|
|
89
|
+
"assignee_agent_id" text,
|
|
90
|
+
"labels_json" text DEFAULT '[]' NOT NULL,
|
|
91
|
+
"tags_json" text DEFAULT '[]' NOT NULL,
|
|
92
|
+
"is_claimed" boolean DEFAULT false NOT NULL,
|
|
93
|
+
"claimed_by_heartbeat_run_id" text,
|
|
94
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
95
|
+
"updated_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
96
|
+
);
|
|
97
|
+
--> statement-breakpoint
|
|
98
|
+
CREATE TABLE "issue_comments" (
|
|
99
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
100
|
+
"issue_id" text NOT NULL REFERENCES "issues"("id") ON DELETE CASCADE,
|
|
101
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
102
|
+
"author_type" text NOT NULL,
|
|
103
|
+
"author_id" text,
|
|
104
|
+
"recipients_json" text DEFAULT '[]' NOT NULL,
|
|
105
|
+
"run_id" text,
|
|
106
|
+
"body" text NOT NULL,
|
|
107
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
108
|
+
);
|
|
109
|
+
--> statement-breakpoint
|
|
110
|
+
CREATE TABLE "issue_attachments" (
|
|
111
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
112
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
113
|
+
"issue_id" text NOT NULL REFERENCES "issues"("id") ON DELETE CASCADE,
|
|
114
|
+
"project_id" text NOT NULL REFERENCES "projects"("id") ON DELETE CASCADE,
|
|
115
|
+
"file_name" text NOT NULL,
|
|
116
|
+
"mime_type" text,
|
|
117
|
+
"file_size_bytes" integer NOT NULL,
|
|
118
|
+
"relative_path" text NOT NULL,
|
|
119
|
+
"uploaded_by_actor_type" text DEFAULT 'human' NOT NULL,
|
|
120
|
+
"uploaded_by_actor_id" text,
|
|
121
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
122
|
+
);
|
|
123
|
+
--> statement-breakpoint
|
|
124
|
+
CREATE TABLE "activity_logs" (
|
|
125
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
126
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
127
|
+
"issue_id" text REFERENCES "issues"("id") ON DELETE SET NULL,
|
|
128
|
+
"actor_type" text NOT NULL,
|
|
129
|
+
"actor_id" text,
|
|
130
|
+
"event_type" text NOT NULL,
|
|
131
|
+
"payload_json" text DEFAULT '{}' NOT NULL,
|
|
132
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
133
|
+
);
|
|
134
|
+
--> statement-breakpoint
|
|
135
|
+
CREATE TABLE "heartbeat_runs" (
|
|
136
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
137
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
138
|
+
"agent_id" text NOT NULL REFERENCES "agents"("id") ON DELETE CASCADE,
|
|
139
|
+
"status" text DEFAULT 'started' NOT NULL,
|
|
140
|
+
"started_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
141
|
+
"finished_at" timestamp,
|
|
142
|
+
"message" text
|
|
143
|
+
);
|
|
144
|
+
--> statement-breakpoint
|
|
145
|
+
CREATE TABLE "heartbeat_run_queue" (
|
|
146
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
147
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
148
|
+
"agent_id" text NOT NULL REFERENCES "agents"("id") ON DELETE CASCADE,
|
|
149
|
+
"job_type" text NOT NULL,
|
|
150
|
+
"payload_json" text DEFAULT '{}' NOT NULL,
|
|
151
|
+
"status" text DEFAULT 'pending' NOT NULL,
|
|
152
|
+
"priority" integer DEFAULT 100 NOT NULL,
|
|
153
|
+
"idempotency_key" text,
|
|
154
|
+
"available_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
155
|
+
"attempt_count" integer DEFAULT 0 NOT NULL,
|
|
156
|
+
"max_attempts" integer DEFAULT 10 NOT NULL,
|
|
157
|
+
"last_error" text,
|
|
158
|
+
"started_at" timestamp,
|
|
159
|
+
"finished_at" timestamp,
|
|
160
|
+
"heartbeat_run_id" text REFERENCES "heartbeat_runs"("id") ON DELETE SET NULL,
|
|
161
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
162
|
+
"updated_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
163
|
+
);
|
|
164
|
+
--> statement-breakpoint
|
|
165
|
+
CREATE TABLE "heartbeat_run_messages" (
|
|
166
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
167
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
168
|
+
"run_id" text NOT NULL REFERENCES "heartbeat_runs"("id") ON DELETE CASCADE,
|
|
169
|
+
"sequence" integer NOT NULL,
|
|
170
|
+
"kind" text NOT NULL,
|
|
171
|
+
"label" text,
|
|
172
|
+
"text" text,
|
|
173
|
+
"payload_json" text,
|
|
174
|
+
"signal_level" text,
|
|
175
|
+
"group_key" text,
|
|
176
|
+
"source" text,
|
|
177
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
178
|
+
);
|
|
179
|
+
--> statement-breakpoint
|
|
180
|
+
CREATE TABLE "approval_requests" (
|
|
181
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
182
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
183
|
+
"requested_by_agent_id" text,
|
|
184
|
+
"action" text NOT NULL,
|
|
185
|
+
"payload_json" text DEFAULT '{}' NOT NULL,
|
|
186
|
+
"status" text DEFAULT 'pending' NOT NULL,
|
|
187
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
188
|
+
"resolved_at" timestamp
|
|
189
|
+
);
|
|
190
|
+
--> statement-breakpoint
|
|
191
|
+
CREATE TABLE "approval_inbox_states" (
|
|
192
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
193
|
+
"actor_id" text NOT NULL,
|
|
194
|
+
"approval_id" text NOT NULL REFERENCES "approval_requests"("id") ON DELETE CASCADE,
|
|
195
|
+
"seen_at" timestamp,
|
|
196
|
+
"dismissed_at" timestamp,
|
|
197
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
198
|
+
"updated_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
199
|
+
PRIMARY KEY ("company_id", "actor_id", "approval_id")
|
|
200
|
+
);
|
|
201
|
+
--> statement-breakpoint
|
|
202
|
+
CREATE TABLE "attention_inbox_states" (
|
|
203
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
204
|
+
"actor_id" text NOT NULL,
|
|
205
|
+
"item_key" text NOT NULL,
|
|
206
|
+
"seen_at" timestamp,
|
|
207
|
+
"acknowledged_at" timestamp,
|
|
208
|
+
"dismissed_at" timestamp,
|
|
209
|
+
"resolved_at" timestamp,
|
|
210
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
211
|
+
"updated_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
212
|
+
PRIMARY KEY ("company_id", "actor_id", "item_key")
|
|
213
|
+
);
|
|
214
|
+
--> statement-breakpoint
|
|
215
|
+
CREATE TABLE "cost_ledger" (
|
|
216
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
217
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
218
|
+
"run_id" text REFERENCES "heartbeat_runs"("id") ON DELETE SET NULL,
|
|
219
|
+
"project_id" text REFERENCES "projects"("id") ON DELETE SET NULL,
|
|
220
|
+
"issue_id" text REFERENCES "issues"("id") ON DELETE SET NULL,
|
|
221
|
+
"agent_id" text REFERENCES "agents"("id") ON DELETE SET NULL,
|
|
222
|
+
"provider_type" text NOT NULL,
|
|
223
|
+
"runtime_model_id" text,
|
|
224
|
+
"pricing_provider_type" text,
|
|
225
|
+
"pricing_model_id" text,
|
|
226
|
+
"pricing_source" text,
|
|
227
|
+
"token_input" integer DEFAULT 0 NOT NULL,
|
|
228
|
+
"token_output" integer DEFAULT 0 NOT NULL,
|
|
229
|
+
"usd_cost" numeric(12, 6) DEFAULT 0 NOT NULL,
|
|
230
|
+
"usd_cost_status" text,
|
|
231
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
232
|
+
);
|
|
233
|
+
--> statement-breakpoint
|
|
234
|
+
DROP TABLE IF EXISTS "model_pricing";
|
|
235
|
+
--> statement-breakpoint
|
|
236
|
+
CREATE TABLE "audit_events" (
|
|
237
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
238
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
239
|
+
"actor_type" text NOT NULL,
|
|
240
|
+
"actor_id" text,
|
|
241
|
+
"event_type" text NOT NULL,
|
|
242
|
+
"entity_type" text NOT NULL,
|
|
243
|
+
"entity_id" text NOT NULL,
|
|
244
|
+
"correlation_id" text,
|
|
245
|
+
"payload_json" text DEFAULT '{}' NOT NULL,
|
|
246
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
247
|
+
);
|
|
248
|
+
--> statement-breakpoint
|
|
249
|
+
CREATE TABLE "plugins" (
|
|
250
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
251
|
+
"name" text NOT NULL,
|
|
252
|
+
"version" text NOT NULL,
|
|
253
|
+
"kind" text NOT NULL,
|
|
254
|
+
"runtime_type" text NOT NULL,
|
|
255
|
+
"runtime_entrypoint" text NOT NULL,
|
|
256
|
+
"hooks_json" text DEFAULT '[]' NOT NULL,
|
|
257
|
+
"capabilities_json" text DEFAULT '[]' NOT NULL,
|
|
258
|
+
"manifest_json" text DEFAULT '{}' NOT NULL,
|
|
259
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
260
|
+
"updated_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
261
|
+
);
|
|
262
|
+
--> statement-breakpoint
|
|
263
|
+
CREATE TABLE "templates" (
|
|
264
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
265
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
266
|
+
"slug" text NOT NULL,
|
|
267
|
+
"name" text NOT NULL,
|
|
268
|
+
"description" text,
|
|
269
|
+
"current_version" text DEFAULT '1.0.0' NOT NULL,
|
|
270
|
+
"status" text DEFAULT 'draft' NOT NULL,
|
|
271
|
+
"visibility" text DEFAULT 'company' NOT NULL,
|
|
272
|
+
"variables_json" text DEFAULT '[]' NOT NULL,
|
|
273
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
274
|
+
"updated_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
275
|
+
);
|
|
276
|
+
--> statement-breakpoint
|
|
277
|
+
CREATE TABLE "template_versions" (
|
|
278
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
279
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
280
|
+
"template_id" text NOT NULL REFERENCES "templates"("id") ON DELETE CASCADE,
|
|
281
|
+
"version" text NOT NULL,
|
|
282
|
+
"manifest_json" text DEFAULT '{}' NOT NULL,
|
|
283
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
284
|
+
);
|
|
285
|
+
--> statement-breakpoint
|
|
286
|
+
CREATE TABLE "template_installs" (
|
|
287
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
288
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
289
|
+
"template_id" text REFERENCES "templates"("id") ON DELETE SET NULL,
|
|
290
|
+
"template_version_id" text REFERENCES "template_versions"("id") ON DELETE SET NULL,
|
|
291
|
+
"status" text DEFAULT 'applied' NOT NULL,
|
|
292
|
+
"summary_json" text DEFAULT '{}' NOT NULL,
|
|
293
|
+
"variables_json" text DEFAULT '{}' NOT NULL,
|
|
294
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
295
|
+
);
|
|
296
|
+
--> statement-breakpoint
|
|
297
|
+
CREATE TABLE "plugin_configs" (
|
|
298
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
299
|
+
"plugin_id" text NOT NULL REFERENCES "plugins"("id") ON DELETE CASCADE,
|
|
300
|
+
"enabled" boolean DEFAULT false NOT NULL,
|
|
301
|
+
"priority" integer DEFAULT 100 NOT NULL,
|
|
302
|
+
"config_json" text DEFAULT '{}' NOT NULL,
|
|
303
|
+
"granted_capabilities_json" text DEFAULT '[]' NOT NULL,
|
|
304
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
305
|
+
"updated_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
306
|
+
PRIMARY KEY ("company_id", "plugin_id")
|
|
307
|
+
);
|
|
308
|
+
--> statement-breakpoint
|
|
309
|
+
CREATE TABLE "plugin_runs" (
|
|
310
|
+
"id" text PRIMARY KEY NOT NULL,
|
|
311
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
312
|
+
"run_id" text REFERENCES "heartbeat_runs"("id") ON DELETE CASCADE,
|
|
313
|
+
"plugin_id" text NOT NULL REFERENCES "plugins"("id") ON DELETE CASCADE,
|
|
314
|
+
"hook" text NOT NULL,
|
|
315
|
+
"status" text NOT NULL,
|
|
316
|
+
"duration_ms" integer DEFAULT 0 NOT NULL,
|
|
317
|
+
"error" text,
|
|
318
|
+
"diagnostics_json" text DEFAULT '{}' NOT NULL,
|
|
319
|
+
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL
|
|
320
|
+
);
|
|
321
|
+
--> statement-breakpoint
|
|
322
|
+
CREATE TABLE "agent_issue_labels" (
|
|
323
|
+
"company_id" text NOT NULL REFERENCES "companies"("id") ON DELETE CASCADE,
|
|
324
|
+
"issue_id" text NOT NULL REFERENCES "issues"("id") ON DELETE CASCADE,
|
|
325
|
+
"label" text NOT NULL,
|
|
326
|
+
PRIMARY KEY ("company_id", "issue_id", "label")
|
|
327
|
+
);
|
|
328
|
+
--> statement-breakpoint
|
|
329
|
+
CREATE INDEX "idx_project_workspaces_company_project"
|
|
330
|
+
ON "project_workspaces" ("company_id", "project_id", "is_primary", "created_at");
|
|
331
|
+
--> statement-breakpoint
|
|
332
|
+
CREATE INDEX "idx_issues_company_status"
|
|
333
|
+
ON "issues" ("company_id", "status", "updated_at");
|
|
334
|
+
--> statement-breakpoint
|
|
335
|
+
CREATE INDEX "idx_issues_assignee_claim_priority"
|
|
336
|
+
ON "issues" ("company_id", "assignee_agent_id", "is_claimed", "status", "priority", "updated_at");
|
|
337
|
+
--> statement-breakpoint
|
|
338
|
+
CREATE INDEX "idx_issue_attachments_company_issue"
|
|
339
|
+
ON "issue_attachments" ("company_id", "issue_id", "created_at");
|
|
340
|
+
--> statement-breakpoint
|
|
341
|
+
CREATE INDEX "idx_issue_attachments_company_project"
|
|
342
|
+
ON "issue_attachments" ("company_id", "project_id", "created_at");
|
|
343
|
+
--> statement-breakpoint
|
|
344
|
+
CREATE INDEX "idx_audit_events_company_created"
|
|
345
|
+
ON "audit_events" ("company_id", "created_at");
|
|
346
|
+
--> statement-breakpoint
|
|
347
|
+
CREATE INDEX "idx_cost_ledger_company_created"
|
|
348
|
+
ON "cost_ledger" ("company_id", "created_at");
|
|
349
|
+
--> statement-breakpoint
|
|
350
|
+
CREATE UNIQUE INDEX "idx_heartbeat_runs_single_started"
|
|
351
|
+
ON "heartbeat_runs" ("company_id", "agent_id")
|
|
352
|
+
WHERE "status" = 'started';
|
|
353
|
+
--> statement-breakpoint
|
|
354
|
+
CREATE INDEX "idx_heartbeat_run_queue_status_available_priority"
|
|
355
|
+
ON "heartbeat_run_queue" ("company_id", "status", "available_at", "priority", "created_at");
|
|
356
|
+
--> statement-breakpoint
|
|
357
|
+
CREATE INDEX "idx_heartbeat_run_queue_agent_status"
|
|
358
|
+
ON "heartbeat_run_queue" ("company_id", "agent_id", "status", "available_at", "created_at");
|
|
359
|
+
--> statement-breakpoint
|
|
360
|
+
CREATE UNIQUE INDEX "idx_heartbeat_run_queue_idempotency"
|
|
361
|
+
ON "heartbeat_run_queue" ("company_id", "agent_id", "idempotency_key")
|
|
362
|
+
WHERE "idempotency_key" IS NOT NULL AND btrim("idempotency_key") <> '';
|
|
363
|
+
--> statement-breakpoint
|
|
364
|
+
CREATE INDEX "idx_heartbeat_run_messages_company_run_sequence"
|
|
365
|
+
ON "heartbeat_run_messages" ("company_id", "run_id", "sequence");
|
|
366
|
+
--> statement-breakpoint
|
|
367
|
+
CREATE INDEX "idx_heartbeat_run_messages_company_created"
|
|
368
|
+
ON "heartbeat_run_messages" ("company_id", "created_at");
|
|
369
|
+
--> statement-breakpoint
|
|
370
|
+
CREATE INDEX "idx_approval_inbox_states_company_actor_updated"
|
|
371
|
+
ON "approval_inbox_states" ("company_id", "actor_id", "updated_at");
|
|
372
|
+
--> statement-breakpoint
|
|
373
|
+
CREATE INDEX "idx_attention_inbox_states_company_actor_updated"
|
|
374
|
+
ON "attention_inbox_states" ("company_id", "actor_id", "updated_at");
|
|
375
|
+
--> statement-breakpoint
|
|
376
|
+
CREATE INDEX "idx_plugin_configs_company_enabled_priority"
|
|
377
|
+
ON "plugin_configs" ("company_id", "enabled", "priority", "plugin_id");
|
|
378
|
+
--> statement-breakpoint
|
|
379
|
+
CREATE INDEX "idx_plugin_runs_company_created"
|
|
380
|
+
ON "plugin_runs" ("company_id", "created_at");
|
|
381
|
+
--> statement-breakpoint
|
|
382
|
+
CREATE UNIQUE INDEX "idx_templates_company_slug"
|
|
383
|
+
ON "templates" ("company_id", "slug");
|
|
384
|
+
--> statement-breakpoint
|
|
385
|
+
CREATE INDEX "idx_template_versions_company_template_created"
|
|
386
|
+
ON "template_versions" ("company_id", "template_id", "created_at");
|
|
387
|
+
--> statement-breakpoint
|
|
388
|
+
CREATE INDEX "idx_template_installs_company_created"
|
|
389
|
+
ON "template_installs" ("company_id", "created_at");
|
package/src/repositories.ts
CHANGED
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
issueAttachments,
|
|
18
18
|
issueComments,
|
|
19
19
|
issues,
|
|
20
|
-
modelPricing,
|
|
21
20
|
pluginConfigs,
|
|
22
21
|
pluginRuns,
|
|
23
22
|
plugins,
|
|
@@ -216,7 +215,7 @@ export async function updateProject(
|
|
|
216
215
|
}
|
|
217
216
|
if (input.workspaceLocalPath !== undefined || input.workspaceGithubRepo !== undefined) {
|
|
218
217
|
const existingWorkspaces = await listProjectWorkspaces(db, input.companyId, input.id);
|
|
219
|
-
const primaryWorkspace = existingWorkspaces.find((workspace) => workspace.isPrimary) ?? existingWorkspaces[0] ?? null;
|
|
218
|
+
const primaryWorkspace = existingWorkspaces.find((workspace: any) => workspace.isPrimary) ?? existingWorkspaces[0] ?? null;
|
|
220
219
|
const hasAnyWorkspaceField =
|
|
221
220
|
(input.workspaceLocalPath?.trim() ?? "").length > 0 || (input.workspaceGithubRepo?.trim() ?? "").length > 0;
|
|
222
221
|
if (!hasAnyWorkspaceField) {
|
|
@@ -273,7 +272,7 @@ export async function createProjectWorkspace(
|
|
|
273
272
|
}
|
|
274
273
|
) {
|
|
275
274
|
const id = nanoid(12);
|
|
276
|
-
return db.transaction(async (tx) => {
|
|
275
|
+
return db.transaction(async (tx: any) => {
|
|
277
276
|
const existingWorkspaces = await tx
|
|
278
277
|
.select({ id: projectWorkspaces.id })
|
|
279
278
|
.from(projectWorkspaces)
|
|
@@ -316,7 +315,7 @@ export async function updateProjectWorkspace(
|
|
|
316
315
|
isPrimary?: boolean;
|
|
317
316
|
}
|
|
318
317
|
) {
|
|
319
|
-
return db.transaction(async (tx) => {
|
|
318
|
+
return db.transaction(async (tx: any) => {
|
|
320
319
|
if (input.isPrimary === true) {
|
|
321
320
|
await tx
|
|
322
321
|
.update(projectWorkspaces)
|
|
@@ -386,7 +385,7 @@ export async function deleteProjectWorkspace(
|
|
|
386
385
|
db: BopoDb,
|
|
387
386
|
input: { companyId: string; projectId: string; id: string }
|
|
388
387
|
) {
|
|
389
|
-
return db.transaction(async (tx) => {
|
|
388
|
+
return db.transaction(async (tx: any) => {
|
|
390
389
|
const [workspace] = await tx
|
|
391
390
|
.delete(projectWorkspaces)
|
|
392
391
|
.where(
|
|
@@ -541,6 +540,15 @@ export async function listIssues(db: BopoDb, companyId: string, projectId?: stri
|
|
|
541
540
|
return db.select().from(issues).where(where).orderBy(desc(issues.updatedAt));
|
|
542
541
|
}
|
|
543
542
|
|
|
543
|
+
export async function getIssue(db: BopoDb, companyId: string, issueId: string) {
|
|
544
|
+
const [row] = await db
|
|
545
|
+
.select()
|
|
546
|
+
.from(issues)
|
|
547
|
+
.where(and(eq(issues.companyId, companyId), eq(issues.id, issueId)))
|
|
548
|
+
.limit(1);
|
|
549
|
+
return row ?? null;
|
|
550
|
+
}
|
|
551
|
+
|
|
544
552
|
export async function createIssue(
|
|
545
553
|
db: BopoDb,
|
|
546
554
|
input: {
|
|
@@ -755,7 +763,7 @@ export async function listIssueComments(db: BopoDb, companyId: string, issueId:
|
|
|
755
763
|
.from(issueComments)
|
|
756
764
|
.where(and(eq(issueComments.companyId, companyId), eq(issueComments.issueId, issueId)))
|
|
757
765
|
.orderBy(asc(issueComments.createdAt));
|
|
758
|
-
return comments.map((comment) => normalizeIssueComment(comment));
|
|
766
|
+
return comments.map((comment: any) => normalizeIssueComment(comment));
|
|
759
767
|
}
|
|
760
768
|
|
|
761
769
|
export async function listIssueActivity(db: BopoDb, companyId: string, issueId: string, limit = 100) {
|
|
@@ -1666,7 +1674,7 @@ export async function claimNextHeartbeatJob(db: BopoDb, companyId: string) {
|
|
|
1666
1674
|
WHERE q.id = c.id
|
|
1667
1675
|
RETURNING q.*;
|
|
1668
1676
|
`);
|
|
1669
|
-
const row =
|
|
1677
|
+
const row = result[0] as Record<string, unknown> | undefined;
|
|
1670
1678
|
return row ? normalizeHeartbeatQueueJob(row) : null;
|
|
1671
1679
|
}
|
|
1672
1680
|
|
|
@@ -1796,7 +1804,7 @@ export async function listHeartbeatQueueJobs(
|
|
|
1796
1804
|
.where(and(...conditions))
|
|
1797
1805
|
.orderBy(asc(heartbeatRunQueue.priority), asc(heartbeatRunQueue.availableAt), asc(heartbeatRunQueue.createdAt))
|
|
1798
1806
|
.limit(limit);
|
|
1799
|
-
return rows.map((row) => normalizeHeartbeatQueueJob(row));
|
|
1807
|
+
return rows.map((row: any) => normalizeHeartbeatQueueJob(row));
|
|
1800
1808
|
}
|
|
1801
1809
|
|
|
1802
1810
|
export async function getHeartbeatRun(db: BopoDb, companyId: string, runId: string) {
|
|
@@ -1927,7 +1935,7 @@ export async function listHeartbeatRunMessagesForRuns(
|
|
|
1927
1935
|
WHERE rn <= ${perRunLimit}
|
|
1928
1936
|
ORDER BY run_id ASC, sequence ASC
|
|
1929
1937
|
`);
|
|
1930
|
-
const rows =
|
|
1938
|
+
const rows = rankedRows as unknown as Array<{
|
|
1931
1939
|
id: string;
|
|
1932
1940
|
company_id: string;
|
|
1933
1941
|
run_id: string;
|
|
@@ -2371,70 +2379,6 @@ export async function createTemplateInstall(
|
|
|
2371
2379
|
return row ?? null;
|
|
2372
2380
|
}
|
|
2373
2381
|
|
|
2374
|
-
export async function listModelPricing(db: BopoDb, companyId: string) {
|
|
2375
|
-
return db
|
|
2376
|
-
.select()
|
|
2377
|
-
.from(modelPricing)
|
|
2378
|
-
.where(eq(modelPricing.companyId, companyId))
|
|
2379
|
-
.orderBy(asc(modelPricing.providerType), asc(modelPricing.modelId));
|
|
2380
|
-
}
|
|
2381
|
-
|
|
2382
|
-
export async function getModelPricing(
|
|
2383
|
-
db: BopoDb,
|
|
2384
|
-
input: { companyId: string; providerType: string; modelId: string }
|
|
2385
|
-
) {
|
|
2386
|
-
const rows = await db
|
|
2387
|
-
.select()
|
|
2388
|
-
.from(modelPricing)
|
|
2389
|
-
.where(
|
|
2390
|
-
and(
|
|
2391
|
-
eq(modelPricing.companyId, input.companyId),
|
|
2392
|
-
eq(modelPricing.providerType, input.providerType),
|
|
2393
|
-
eq(modelPricing.modelId, input.modelId)
|
|
2394
|
-
)
|
|
2395
|
-
)
|
|
2396
|
-
.limit(1);
|
|
2397
|
-
return rows[0] ?? null;
|
|
2398
|
-
}
|
|
2399
|
-
|
|
2400
|
-
export async function upsertModelPricing(
|
|
2401
|
-
db: BopoDb,
|
|
2402
|
-
input: {
|
|
2403
|
-
companyId: string;
|
|
2404
|
-
providerType: string;
|
|
2405
|
-
modelId: string;
|
|
2406
|
-
displayName?: string | null;
|
|
2407
|
-
inputUsdPer1M?: string | null;
|
|
2408
|
-
outputUsdPer1M?: string | null;
|
|
2409
|
-
currency?: string | null;
|
|
2410
|
-
updatedBy?: string | null;
|
|
2411
|
-
}
|
|
2412
|
-
) {
|
|
2413
|
-
await db
|
|
2414
|
-
.insert(modelPricing)
|
|
2415
|
-
.values({
|
|
2416
|
-
companyId: input.companyId,
|
|
2417
|
-
providerType: input.providerType,
|
|
2418
|
-
modelId: input.modelId,
|
|
2419
|
-
displayName: input.displayName ?? null,
|
|
2420
|
-
inputUsdPer1M: input.inputUsdPer1M ?? "0.000000",
|
|
2421
|
-
outputUsdPer1M: input.outputUsdPer1M ?? "0.000000",
|
|
2422
|
-
currency: input.currency ?? "USD",
|
|
2423
|
-
updatedBy: input.updatedBy ?? null
|
|
2424
|
-
})
|
|
2425
|
-
.onConflictDoUpdate({
|
|
2426
|
-
target: [modelPricing.companyId, modelPricing.providerType, modelPricing.modelId],
|
|
2427
|
-
set: compactUpdate({
|
|
2428
|
-
displayName: input.displayName ?? null,
|
|
2429
|
-
inputUsdPer1M: input.inputUsdPer1M ?? "0.000000",
|
|
2430
|
-
outputUsdPer1M: input.outputUsdPer1M ?? "0.000000",
|
|
2431
|
-
currency: input.currency ?? "USD",
|
|
2432
|
-
updatedBy: input.updatedBy ?? null,
|
|
2433
|
-
updatedAt: touchUpdatedAtSql
|
|
2434
|
-
})
|
|
2435
|
-
});
|
|
2436
|
-
}
|
|
2437
|
-
|
|
2438
2382
|
function compactUpdate<T extends Record<string, unknown>>(input: T) {
|
|
2439
2383
|
return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== undefined));
|
|
2440
2384
|
}
|
package/src/schema.ts
CHANGED
|
@@ -367,24 +367,6 @@ export const templateInstalls = pgTable("template_installs", {
|
|
|
367
367
|
createdAt: timestamp("created_at", { mode: "date" }).defaultNow().notNull()
|
|
368
368
|
});
|
|
369
369
|
|
|
370
|
-
export const modelPricing = pgTable(
|
|
371
|
-
"model_pricing",
|
|
372
|
-
{
|
|
373
|
-
companyId: text("company_id")
|
|
374
|
-
.notNull()
|
|
375
|
-
.references(() => companies.id, { onDelete: "cascade" }),
|
|
376
|
-
providerType: text("provider_type").notNull(),
|
|
377
|
-
modelId: text("model_id").notNull(),
|
|
378
|
-
displayName: text("display_name"),
|
|
379
|
-
inputUsdPer1M: numeric("input_usd_per_1m", { precision: 12, scale: 6 }).notNull().default("0"),
|
|
380
|
-
outputUsdPer1M: numeric("output_usd_per_1m", { precision: 12, scale: 6 }).notNull().default("0"),
|
|
381
|
-
currency: text("currency").notNull().default("USD"),
|
|
382
|
-
updatedAt: timestamp("updated_at", { mode: "date" }).defaultNow().notNull(),
|
|
383
|
-
updatedBy: text("updated_by")
|
|
384
|
-
},
|
|
385
|
-
(table) => [primaryKey({ columns: [table.companyId, table.providerType, table.modelId] })]
|
|
386
|
-
);
|
|
387
|
-
|
|
388
370
|
export const pluginConfigs = pgTable(
|
|
389
371
|
"plugin_configs",
|
|
390
372
|
{
|
|
@@ -458,7 +440,6 @@ export const schema = {
|
|
|
458
440
|
templates,
|
|
459
441
|
templateVersions,
|
|
460
442
|
templateInstalls,
|
|
461
|
-
modelPricing,
|
|
462
443
|
agentIssueLabels,
|
|
463
444
|
projectWorkspaces
|
|
464
445
|
};
|
package/.turbo/turbo-lint.log
DELETED