@hyperfixation/db 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/app-state.d.ts +12 -0
- package/dist/app-state.js +18 -0
- package/dist/boot-checks.d.ts +56 -0
- package/dist/boot-checks.js +228 -0
- package/dist/classify.d.ts +6 -0
- package/dist/classify.js +75 -0
- package/dist/control-plane.d.ts +75 -0
- package/dist/control-plane.js +155 -0
- package/dist/delete-guard.d.ts +32 -0
- package/dist/delete-guard.js +62 -0
- package/dist/fenced-client.d.ts +35 -0
- package/dist/fenced-client.js +153 -0
- package/dist/grant-ro.d.ts +23 -0
- package/dist/grant-ro.js +49 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +10 -0
- package/dist/internal/control-pool.d.ts +20 -0
- package/dist/internal/control-pool.js +17 -0
- package/dist/loader.d.ts +15 -0
- package/dist/loader.js +82 -0
- package/dist/migrate.d.ts +54 -0
- package/dist/migrate.js +143 -0
- package/dist/migration-policy.d.ts +14 -0
- package/dist/migration-policy.js +85 -0
- package/dist/migrator.d.ts +9 -0
- package/dist/migrator.js +9 -0
- package/dist/roles.d.ts +47 -0
- package/dist/roles.js +112 -0
- package/dist/schema/app.d.ts +235 -0
- package/dist/schema/app.js +23 -0
- package/dist/schema/approvals.d.ts +352 -0
- package/dist/schema/approvals.js +43 -0
- package/dist/schema/auth.d.ts +1272 -0
- package/dist/schema/auth.js +120 -0
- package/dist/schema/index.d.ts +7 -0
- package/dist/schema/index.js +7 -0
- package/dist/schema/ledger.d.ts +722 -0
- package/dist/schema/ledger.js +68 -0
- package/dist/schema/machinery.d.ts +1343 -0
- package/dist/schema/machinery.js +146 -0
- package/dist/schema/records.d.ts +15 -0
- package/dist/schema/records.js +16 -0
- package/dist/schema/runs.d.ts +213 -0
- package/dist/schema/runs.js +26 -0
- package/dist/step-pool.d.ts +26 -0
- package/dist/step-pool.js +57 -0
- package/migrations/0000_core_schema.sql +185 -0
- package/migrations/0001_llm_call_reservation_index.sql +4 -0
- package/migrations/0002_approvals.sql +25 -0
- package/migrations/0003_auth_invitation.sql +13 -0
- package/migrations/0004_machinery.sql +105 -0
- package/migrations/0005_nullable_activity_task_record.sql +4 -0
- package/migrations/0006_activity_score_key.sql +5 -0
- package/migrations/0007_score_spec_name.sql +3 -0
- package/migrations/meta/0000_snapshot.json +1238 -0
- package/migrations/meta/0001_snapshot.json +1238 -0
- package/migrations/meta/0002_snapshot.json +1426 -0
- package/migrations/meta/0003_snapshot.json +1516 -0
- package/migrations/meta/0004_snapshot.json +2353 -0
- package/migrations/meta/0005_snapshot.json +2353 -0
- package/migrations/meta/0006_snapshot.json +2415 -0
- package/migrations/meta/0007_snapshot.json +2427 -0
- package/migrations/meta/_journal.json +62 -0
- package/package.json +58 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { sql } from "drizzle-orm";
|
|
2
|
+
import { bigint, boolean, check, index, integer, jsonb, numeric, pgTable, text, timestamp, uniqueIndex, } from "drizzle-orm/pg-core";
|
|
3
|
+
export const llmCallStatuses = ["started", "ok", "error", "abandoned"];
|
|
4
|
+
export const actionLogStatuses = ["started", "ok", "failed", "uncertain"];
|
|
5
|
+
export const hfBudgetPeriod = pgTable("hf_budget_period", {
|
|
6
|
+
period: text("period").primaryKey(),
|
|
7
|
+
budgetUsd: numeric("budget_usd", { precision: 12, scale: 4 }).notNull(),
|
|
8
|
+
spentUsd: numeric("spent_usd", { precision: 12, scale: 4 }).notNull().default("0"),
|
|
9
|
+
createdAt: timestamp("created_at", { withTimezone: true, mode: "date" })
|
|
10
|
+
.notNull()
|
|
11
|
+
.defaultNow(),
|
|
12
|
+
}, (t) => [check("hf_budget_period_spent_non_negative", sql `${t.spentUsd} >= 0`)]);
|
|
13
|
+
export const hfLlmCall = pgTable("hf_llm_call", {
|
|
14
|
+
id: bigint("id", { mode: "number" }).generatedAlwaysAsIdentity().primaryKey(),
|
|
15
|
+
runId: text("run_id").notNull(),
|
|
16
|
+
key: text("key").notNull(),
|
|
17
|
+
// The attempt that wrote the row: informational once `ok`, load-bearing while
|
|
18
|
+
// `started` because the derived reservation only counts rows whose workflow_id
|
|
19
|
+
// still equals their run's current_workflow_id.
|
|
20
|
+
workflowId: text("workflow_id").notNull(),
|
|
21
|
+
period: text("period").notNull(),
|
|
22
|
+
stepName: text("step_name"),
|
|
23
|
+
promptName: text("prompt_name"),
|
|
24
|
+
promptHash: text("prompt_hash"),
|
|
25
|
+
inputHash: text("input_hash").notNull(),
|
|
26
|
+
model: text("model"),
|
|
27
|
+
status: text("status", { enum: llmCallStatuses }).notNull(),
|
|
28
|
+
input: jsonb("input"),
|
|
29
|
+
output: jsonb("output"),
|
|
30
|
+
tokensIn: integer("tokens_in"),
|
|
31
|
+
tokensOut: integer("tokens_out"),
|
|
32
|
+
estimatedCostUsd: numeric("estimated_cost_usd", { precision: 12, scale: 6 }).notNull(),
|
|
33
|
+
costUsd: numeric("cost_usd", { precision: 12, scale: 6 }),
|
|
34
|
+
possibleDoubleCharge: boolean("possible_double_charge").notNull().default(false),
|
|
35
|
+
latencyMs: integer("latency_ms"),
|
|
36
|
+
traceId: text("trace_id"),
|
|
37
|
+
startedAt: timestamp("started_at", { withTimezone: true, mode: "date" })
|
|
38
|
+
.notNull()
|
|
39
|
+
.defaultNow(),
|
|
40
|
+
finishedAt: timestamp("finished_at", { withTimezone: true, mode: "date" }),
|
|
41
|
+
}, (t) => [
|
|
42
|
+
uniqueIndex("hf_llm_call_run_key_uq").on(t.runId, t.key),
|
|
43
|
+
// The drift index. The reservation's covering index — (period, run_id,
|
|
44
|
+
// workflow_id) INCLUDE (estimated_cost_usd) WHERE status = 'started' — cannot
|
|
45
|
+
// be declared here: Drizzle has no builder for INCLUDE. It ships as a
|
|
46
|
+
// hand-written migration, and is invisible to `drizzle-kit generate`'s diff
|
|
47
|
+
// because the snapshot never learns about it.
|
|
48
|
+
index("hf_llm_call_period_status_idx").on(t.period, t.status),
|
|
49
|
+
]);
|
|
50
|
+
export const hfActionLog = pgTable("hf_action_log", {
|
|
51
|
+
id: bigint("id", { mode: "number" }).generatedAlwaysAsIdentity().primaryKey(),
|
|
52
|
+
runId: text("run_id").notNull(),
|
|
53
|
+
key: text("key").notNull(),
|
|
54
|
+
workflowId: text("workflow_id").notNull(),
|
|
55
|
+
channel: text("channel").notNull(),
|
|
56
|
+
idempotencyKey: text("idempotency_key").notNull(),
|
|
57
|
+
status: text("status", { enum: actionLogStatuses }).notNull(),
|
|
58
|
+
externalId: text("external_id"),
|
|
59
|
+
approvalId: bigint("approval_id", { mode: "number" }),
|
|
60
|
+
recordType: text("record_type"),
|
|
61
|
+
recordId: text("record_id"),
|
|
62
|
+
request: jsonb("request"),
|
|
63
|
+
response: jsonb("response"),
|
|
64
|
+
startedAt: timestamp("started_at", { withTimezone: true, mode: "date" })
|
|
65
|
+
.notNull()
|
|
66
|
+
.defaultNow(),
|
|
67
|
+
finishedAt: timestamp("finished_at", { withTimezone: true, mode: "date" }),
|
|
68
|
+
}, (t) => [uniqueIndex("hf_action_log_run_key_uq").on(t.runId, t.key)]);
|