spb/autoscholar
Public
1import { bigint, index, integer, jsonb, numeric, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";2import { researchRuns } from "./runs.js";34export const providerUsage = pgTable(5 "provider_usage",6 {7 id: uuid("id").primaryKey().defaultRandom(),8 runId: uuid("run_id")9 .notNull()10 .references(() => researchRuns.id, { onDelete: "cascade" }),11 attemptId: uuid("attempt_id"),12 stage: text("stage"),13 provider: text("provider").notNull().default("anthropic"),14 model: text("model").notNull(),15 inputTokens: bigint("input_tokens", { mode: "number" }).notNull().default(0),16 outputTokens: bigint("output_tokens", { mode: "number" }).notNull().default(0),17 cacheReadTokens: bigint("cache_read_tokens", { mode: "number" }).notNull().default(0),18 cacheCreateTokens: bigint("cache_create_tokens", { mode: "number" }).notNull().default(0),19 costUsd: numeric("cost_usd", { precision: 10, scale: 4 }).notNull().default("0"),20 turns: integer("turns").notNull().default(0),21 createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),22 },23 (t) => [index("provider_usage_run_idx").on(t.runId)],24);2526export const resourceUsage = pgTable("resource_usage", {27 id: uuid("id").primaryKey().defaultRandom(),28 runId: uuid("run_id")29 .notNull()30 .references(() => researchRuns.id, { onDelete: "cascade" }),31 attemptId: uuid("attempt_id"),32 workerId: uuid("worker_id"),33 cpuSeconds: numeric("cpu_seconds", { precision: 12, scale: 2 }),34 wallSeconds: numeric("wall_seconds", { precision: 12, scale: 2 }),35 diskBytes: bigint("disk_bytes", { mode: "number" }),36 peakRssBytes: bigint("peak_rss_bytes", { mode: "number" }),37 createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),38});3940export const costRecords = pgTable("cost_records", {41 id: uuid("id").primaryKey().defaultRandom(),42 runId: uuid("run_id").references(() => researchRuns.id, { onDelete: "cascade" }),43 kind: text("kind").notNull(),44 amountUsd: numeric("amount_usd", { precision: 10, scale: 4 }).notNull(),45 detail: jsonb("detail").$type<Record<string, unknown>>().notNull().default({}),46 createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),47});48