feat(costs): add billing, quota, and budget control plane

This commit is contained in:
Dotta
2026-03-14 22:00:12 -05:00
parent 656b4659fc
commit 76e6cc08a6
91 changed files with 22406 additions and 769 deletions

20
ui/src/api/budgets.ts Normal file
View File

@@ -0,0 +1,20 @@
import type {
BudgetIncident,
BudgetIncidentResolutionInput,
BudgetOverview,
BudgetPolicySummary,
BudgetPolicyUpsertInput,
} from "@paperclipai/shared";
import { api } from "./client";
export const budgetsApi = {
overview: (companyId: string) =>
api.get<BudgetOverview>(`/companies/${companyId}/budgets/overview`),
upsertPolicy: (companyId: string, data: BudgetPolicyUpsertInput) =>
api.post<BudgetPolicySummary>(`/companies/${companyId}/budgets/policies`, data),
resolveIncident: (companyId: string, incidentId: string, data: BudgetIncidentResolutionInput) =>
api.post<BudgetIncident>(
`/companies/${companyId}/budget-incidents/${encodeURIComponent(incidentId)}/resolve`,
data,
),
};

View File

@@ -1,4 +1,17 @@
import type { CostSummary, CostByAgent, CostByProviderModel, CostByAgentModel, CostByProject, CostWindowSpendRow, ProviderQuotaResult } from "@paperclipai/shared";
import type {
CostSummary,
CostByAgent,
CostByProviderModel,
CostByBiller,
CostByAgentModel,
CostByProject,
CostWindowSpendRow,
FinanceSummary,
FinanceByBiller,
FinanceByKind,
FinanceEvent,
ProviderQuotaResult,
} from "@paperclipai/shared";
import { api } from "./client";
function dateParams(from?: string, to?: string): string {
@@ -20,8 +33,27 @@ export const costsApi = {
api.get<CostByProject[]>(`/companies/${companyId}/costs/by-project${dateParams(from, to)}`),
byProvider: (companyId: string, from?: string, to?: string) =>
api.get<CostByProviderModel[]>(`/companies/${companyId}/costs/by-provider${dateParams(from, to)}`),
byBiller: (companyId: string, from?: string, to?: string) =>
api.get<CostByBiller[]>(`/companies/${companyId}/costs/by-biller${dateParams(from, to)}`),
financeSummary: (companyId: string, from?: string, to?: string) =>
api.get<FinanceSummary>(`/companies/${companyId}/costs/finance-summary${dateParams(from, to)}`),
financeByBiller: (companyId: string, from?: string, to?: string) =>
api.get<FinanceByBiller[]>(`/companies/${companyId}/costs/finance-by-biller${dateParams(from, to)}`),
financeByKind: (companyId: string, from?: string, to?: string) =>
api.get<FinanceByKind[]>(`/companies/${companyId}/costs/finance-by-kind${dateParams(from, to)}`),
financeEvents: (companyId: string, from?: string, to?: string, limit: number = 100) =>
api.get<FinanceEvent[]>(`/companies/${companyId}/costs/finance-events${dateParamsWithLimit(from, to, limit)}`),
windowSpend: (companyId: string) =>
api.get<CostWindowSpendRow[]>(`/companies/${companyId}/costs/window-spend`),
quotaWindows: (companyId: string) =>
api.get<ProviderQuotaResult[]>(`/companies/${companyId}/costs/quota-windows`),
};
function dateParamsWithLimit(from?: string, to?: string, limit?: number): string {
const params = new URLSearchParams();
if (from) params.set("from", from);
if (to) params.set("to", to);
if (limit) params.set("limit", String(limit));
const qs = params.toString();
return qs ? `?${qs}` : "";
}