mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-14 01:50:39 +09:00
fix: derive costs by-project from run usage instead of cost events
Joins heartbeat runs to issues via activity log to attribute costs to projects. Shows project names instead of raw IDs in the UI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9ec8c54f41
commit
b459668009
3 changed files with 50 additions and 23 deletions
|
|
@ -1,9 +1,9 @@
|
|||
import type { CostSummary, CostByAgent } from "@paperclip/shared";
|
||||
import { api } from "./client";
|
||||
|
||||
export interface CostByEntity {
|
||||
agentId?: string | null;
|
||||
projectId?: string | null;
|
||||
export interface CostByProject {
|
||||
projectId: string | null;
|
||||
projectName: string | null;
|
||||
costCents: number;
|
||||
inputTokens: number;
|
||||
outputTokens: number;
|
||||
|
|
@ -23,5 +23,5 @@ export const costsApi = {
|
|||
byAgent: (companyId: string, from?: string, to?: string) =>
|
||||
api.get<CostByAgent[]>(`/companies/${companyId}/costs/by-agent${dateParams(from, to)}`),
|
||||
byProject: (companyId: string, from?: string, to?: string) =>
|
||||
api.get<CostByEntity[]>(`/companies/${companyId}/costs/by-project${dateParams(from, to)}`),
|
||||
api.get<CostByProject[]>(`/companies/${companyId}/costs/by-project${dateParams(from, to)}`),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -202,16 +202,16 @@ export function Costs() {
|
|||
<CardContent className="p-4">
|
||||
<h3 className="text-sm font-semibold mb-3">By Project</h3>
|
||||
{data.byProject.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">No project-attributed costs yet.</p>
|
||||
<p className="text-sm text-muted-foreground">No project-attributed run costs yet.</p>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{data.byProject.map((row, idx) => (
|
||||
{data.byProject.map((row) => (
|
||||
<div
|
||||
key={`${row.projectId ?? "na"}-${idx}`}
|
||||
key={row.projectId ?? "na"}
|
||||
className="flex items-center justify-between text-sm"
|
||||
>
|
||||
<span className="font-mono text-xs truncate">
|
||||
{row.projectId ?? "Unattributed"}
|
||||
<span className="truncate">
|
||||
{row.projectName ?? row.projectId ?? "Unattributed"}
|
||||
</span>
|
||||
<span className="font-medium">{formatCents(row.costCents)}</span>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue