forked from farhoodlabs/paperclip
feat(costs): add billing, quota, and budget control plane
This commit is contained in:
@@ -4,6 +4,7 @@ import { agents } from "./agents.js";
|
||||
import { issues } from "./issues.js";
|
||||
import { projects } from "./projects.js";
|
||||
import { goals } from "./goals.js";
|
||||
import { heartbeatRuns } from "./heartbeat_runs.js";
|
||||
|
||||
export const costEvents = pgTable(
|
||||
"cost_events",
|
||||
@@ -14,10 +15,14 @@ export const costEvents = pgTable(
|
||||
issueId: uuid("issue_id").references(() => issues.id),
|
||||
projectId: uuid("project_id").references(() => projects.id),
|
||||
goalId: uuid("goal_id").references(() => goals.id),
|
||||
heartbeatRunId: uuid("heartbeat_run_id").references(() => heartbeatRuns.id),
|
||||
billingCode: text("billing_code"),
|
||||
provider: text("provider").notNull(),
|
||||
biller: text("biller").notNull().default("unknown"),
|
||||
billingType: text("billing_type").notNull().default("unknown"),
|
||||
model: text("model").notNull(),
|
||||
inputTokens: integer("input_tokens").notNull().default(0),
|
||||
cachedInputTokens: integer("cached_input_tokens").notNull().default(0),
|
||||
outputTokens: integer("output_tokens").notNull().default(0),
|
||||
costCents: integer("cost_cents").notNull(),
|
||||
occurredAt: timestamp("occurred_at", { withTimezone: true }).notNull(),
|
||||
@@ -30,5 +35,19 @@ export const costEvents = pgTable(
|
||||
table.agentId,
|
||||
table.occurredAt,
|
||||
),
|
||||
companyProviderOccurredIdx: index("cost_events_company_provider_occurred_idx").on(
|
||||
table.companyId,
|
||||
table.provider,
|
||||
table.occurredAt,
|
||||
),
|
||||
companyBillerOccurredIdx: index("cost_events_company_biller_occurred_idx").on(
|
||||
table.companyId,
|
||||
table.biller,
|
||||
table.occurredAt,
|
||||
),
|
||||
companyHeartbeatRunIdx: index("cost_events_company_heartbeat_run_idx").on(
|
||||
table.companyId,
|
||||
table.heartbeatRunId,
|
||||
),
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user