Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend): clean up agent briefing cost breakdown UX (#13196)

Ubbe4ff22cd0e579
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/BriefingTabContent.tsx b/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/BriefingTabContent.tsx
index 6223a43ba2..9a806ce6a1 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/BriefingTabContent.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/BriefingTabContent.tsx
@@ -1,21 +1,12 @@
"use client";
-import type { CoPilotUsagePublic } from "@/app/api/__generated__/models/coPilotUsagePublic";
import type { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";
-import { useGetV2GetCopilotUsage } from "@/app/api/__generated__/endpoints/chat/chat";
import { useListCopilotSkills } from "@/app/api/__generated__/endpoints/skills/skills";
import {
useGetV1ListExecutionSchedulesForAUser,
useListCopilotFollowupSchedules,
} from "@/app/api/__generated__/endpoints/schedules/schedules";
-import {
- formatResetTime,
- formatTierLabel,
- TIER_BADGE_CLASS_NAME,
-} from "@/app/(platform)/copilot/components/usageHelpers";
import { Button } from "@/components/atoms/Button/Button";
-import { Badge } from "@/components/atoms/Badge/Badge";
-import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
import { useSitrepItems } from "../SitrepItem/useSitrepItems";
import { SitrepItem } from "../SitrepItem/SitrepItem";
import { useAgentStatusMap } from "../../hooks/useAgentStatus";
@@ -32,7 +23,12 @@ interface Props {
export function BriefingTabContent({ activeTab, agents }: Props) {
if (activeTab === "all") {
- return <UsageSection agents={agents} />;
+ return (
+ <div className="py-2">
+ <CostsBreakdown agents={agents} />
+ <CopilotLibrarySummary />
+ </div>
+ );
}
if (
@@ -46,71 +42,6 @@ export function BriefingTabContent({ activeTab, agents }: Props) {
return <AgentListSection activeTab={activeTab} agents={agents} />;
}
-function UsageSection({ agents }: { agents: LibraryAgent[] }) {
- const { data: usage, isSuccess } = useGetV2GetCopilotUsage({
- query: {
- select: (res) => res.data as CoPilotUsagePublic,
- refetchInterval: 30000,
- staleTime: 10000,
- },
- });
-
- const isBillingEnabled = useGetFlag(Flag.ENABLE_PLATFORM_PAYMENT);
-
- const hasUsageMeters = isSuccess && usage && (usage.daily || usage.weekly);
- const tierLabel = hasUsageMeters ? formatTierLabel(usage.tier) : null;
-
- return (
- <div className="py-2">
- {hasUsageMeters && (
- <>
- <div className="flex items-center gap-2">
- <Text variant="h5" className="text-neutral-800">
- Usage limits
- </Text>
- {tierLabel && (
- <Badge
- variant="info"
- size="small"
- className={TIER_BADGE_CLASS_NAME}
- >
- {tierLabel} plan
- </Badge>
- )}
- <div className="flex-1" />
- {isBillingEnabled && (
- <Link
- href="/settings/billing"
- className="text-sm text-blue-600 hover:underline"
- >
- Manage billing
- </Link>
- )}
- </div>
- <div className="mt-4 grid grid-cols-1 gap-6 sm:grid-cols-2">
- {usage.daily && (
- <UsageMeter
- label="Today"
- percentUsed={usage.daily.percent_used}
- resetsAt={usage.daily.resets_at}
- />
- )}
- {usage.weekly && (
- <UsageMeter
- label="This week"
- percentUsed={usage.weekly.percent_used}
- resetsAt={usage.weekly.resets_at}
- />
- )}
- </div>
- </>
- )}
- <CostsBreakdown agents={agents} />
- <CopilotLibrarySummary />
- </div>
- );
-}
-
function CopilotLibrarySummary() {
// Discoverability is already gated by AGENT_BRIEFING at the parent
// panel — this pill renders only inside AgentBriefingPanel, which is
@@ -318,50 +249,6 @@ function AgentListSection({
);
}
-function UsageMeter({
- label,
- percentUsed,
- resetsAt,
-}: {
- label: string;
- percentUsed: number;
- resetsAt: Date | string;
-}) {
- const percent = Math.min(100, Math.max(0, Math.round(percentUsed)));
- const isHigh = percent >= 80;
- const percentLabel =
- percentUsed > 0 && percent === 0 ? "<1% used" : `${percent}% used`;
-
- return (
- <div className="flex flex-col gap-2">
- <div className="flex items-baseline justify-between">
- <Text variant="body-medium" className="text-neutral-700">
- {label}
- </Text>
- <Text variant="body" className="tabular-nums text-neutral-500">
- {percentLabel}
- </Text>
- </div>
- <div className="h-2 w-full overflow-hidden rounded-full bg-neutral-200">
- <div
- role="progressbar"
- aria-label={`${label} usage`}
- aria-valuemin={0}
- aria-valuemax={100}
- aria-valuenow={percent}
- className={`h-full rounded-full transition-[width] duration-300 ease-out ${
- isHigh ? "bg-orange-500" : "bg-blue-500"
- }`}
- style={{ width: `${Math.max(percent > 0 ? 1 : 0, percent)}%` }}
- />
- </div>
- <Text variant="small" className="text-neutral-400">
- Resets {formatResetTime(resetsAt)}
- </Text>
- </div>
- );
-}
-
const EMPTY_MESSAGES: Record<string, string> = {
running: "No agents running right now",
attention: "No agents that need attention",
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/CostsBreakdown/CostsBreakdown.tsx b/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/CostsBreakdown/CostsBreakdown.tsx
index 4c19564610..10c4bf7f74 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/CostsBreakdown/CostsBreakdown.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/CostsBreakdown/CostsBreakdown.tsx
@@ -102,6 +102,9 @@ function ExpandedBody({
return (
<>
+ <Text variant="small" className="text-neutral-500">
+ Calendar month so far · {formatMonthRangeLabel()}
+ </Text>
<StatRow
items={[
{
@@ -126,12 +129,27 @@ function ExpandedBody({
<SpendByAgentList
rollups={summary.by_agent}
agentLookup={agentLookup}
+ totalCents={summary.total_cents}
/>
</div>
</>
);
}
+function formatMonthRangeLabel(): string {
+ const now = new Date();
+ const monthStart = new Date(
+ Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1),
+ );
+ const fmt = (d: Date) =>
+ d.toLocaleDateString(undefined, {
+ month: "short",
+ day: "numeric",
+ timeZone: "UTC",
+ });
+ return `${fmt(monthStart)} – today (UTC)`;
+}
+
interface StatItem {
label: string;
value: string;
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/CostsBreakdown/components/SpendByAgentList.tsx b/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/CostsBreakdown/components/SpendByAgentList.tsx
index ff495f11f8..b22d23cea4 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/CostsBreakdown/components/SpendByAgentList.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/CostsBreakdown/components/SpendByAgentList.tsx
@@ -11,31 +11,41 @@ import type { AgentLookupEntry } from "../helpers";
interface Props {
rollups: UserAgentCostRollup[];
agentLookup: Map<string, AgentLookupEntry>;
+ totalCents: number;
}
const INITIAL_VISIBLE = 5;
-export function SpendByAgentList({ rollups, agentLookup }: Props) {
+export function SpendByAgentList({ rollups, agentLookup, totalCents }: Props) {
const [showAll, setShowAll] = useState(false);
- if (rollups.length === 0) return null;
- const maxCost = Math.max(...rollups.map((r) => r.cost_cents), 1);
- const visible = showAll ? rollups : rollups.slice(0, INITIAL_VISIBLE);
- const hasMore = rollups.length > INITIAL_VISIBLE;
+ const billable = rollups.filter((r) => r.cost_cents > 0);
+ if (billable.length === 0) return null;
+
+ const visible = showAll ? billable : billable.slice(0, INITIAL_VISIBLE);
+ const hasMore = billable.length > INITIAL_VISIBLE;
return (
<section className="flex flex-col gap-2 lg:mt-[1rem]">
- <Text variant="body-medium" className="text-neutral-800 lg:mb-[.5rem]">
- Spend by agent
- </Text>
+ <div className="flex items-baseline justify-between gap-2 lg:mb-[.5rem]">
+ <Text variant="body-medium" className="text-neutral-800">
+ Spend by agent
+ </Text>
+ <Text variant="small" className="text-neutral-400">
+ % of monthly spend
+ </Text>
+ </div>
<ul className="flex flex-col gap-4">
{visible.map((rollup) => {
const agent = agentLookup.get(rollup.graph_id);
const label = agent?.name ?? `Agent ${rollup.graph_id.slice(0, 8)}`;
- const widthPct = Math.max(
- 2,
- Math.round((rollup.cost_cents / maxCost) * 100),
- );
+ const share = totalCents > 0 ? rollup.cost_cents / totalCents : 0;
+ const sharePct = Math.round(share * 100);
+ const widthPct = Math.max(2, sharePct);
+ const shareLabel =
+ share > 0 && sharePct === 0 ? "<1%" : `${sharePct}%`;
+ const avgPerRun =
+ rollup.run_count > 0 ? rollup.cost_cents / rollup.run_count : 0;
const href = agent ? `/library/agents/${agent.libraryAgentId}` : null;
const row = (
@@ -55,15 +65,25 @@ export function SpendByAgentList({ rollups, agentLookup }: Props) {
className="ml-2 text-neutral-400"
>
{rollup.run_count} run{rollup.run_count === 1 ? "" : "s"}
+ {avgPerRun > 0 &&
+ ` · avg ${formatCents(Math.round(avgPerRun))}`}
</Text>
</Text>
</div>
- <div className="h-1.5 w-full overflow-hidden rounded-full bg-zinc-100">
- <div
- className="h-full rounded-full bg-blue-500"
- style={{ width: `${widthPct}%` }}
- aria-hidden="true"
- />
+ <div className="flex items-center gap-2">
+ <div className="h-1.5 flex-1 overflow-hidden rounded-full bg-zinc-100">
+ <div
+ className="h-full rounded-full bg-blue-500"
+ style={{ width: `${widthPct}%` }}
+ aria-hidden="true"
+ />
+ </div>
+ <Text
+ variant="small"
+ className="w-9 shrink-0 text-right tabular-nums text-neutral-400"
+ >
+ {shareLabel}
+ </Text>
</div>
</div>
);
@@ -91,7 +111,7 @@ export function SpendByAgentList({ rollups, agentLookup }: Props) {
size="small"
onClick={() => setShowAll(!showAll)}
>
- {showAll ? "Collapse" : `Show all (${rollups.length})`}
+ {showAll ? "Collapse" : `Show all (${billable.length})`}
</Button>
</div>
)}
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/__tests__/BriefingTabContent.test.tsx b/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/__tests__/BriefingTabContent.test.tsx
index a6984dedec..4f7559b85f 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/__tests__/BriefingTabContent.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/__tests__/BriefingTabContent.test.tsx
@@ -12,19 +12,7 @@ import { fireEvent, render, screen } from "@/tests/integrations/test-utils";
import { afterEach, describe, expect, it, vi } from "vitest";
import { BriefingTabContent } from "../BriefingTabContent";
-const mockUseGetV2GetCopilotUsage = vi.fn();
const mockUseGetV1UserCostSummary = vi.fn();
-vi.mock("@/app/api/__generated__/endpoints/chat/chat", () => ({
- useGetV2GetCopilotUsage: (opts: {
- query?: { select?: (r: { data: unknown }) => unknown };
- }) => {
- const ret = mockUseGetV2GetCopilotUsage(opts) as { data?: unknown };
- if (ret?.data !== undefined && typeof opts?.query?.select === "function") {
- opts.query.select({ data: ret.data });
- }
- return ret;
- },
-}));
vi.mock(
"@/app/api/__generated__/endpoints/graphs/graphs",
async (importOriginal) => {
@@ -51,47 +39,11 @@ vi.mock(
},
);
-const mockUseGetFlag = vi.fn();
-vi.mock("@/services/feature-flags/use-get-flag", async () => {
- const actual = await vi.importActual<
- typeof import("@/services/feature-flags/use-get-flag")
- >("@/services/feature-flags/use-get-flag");
- return {
- ...actual,
- useGetFlag: (flag: unknown) => mockUseGetFlag(flag),
- };
-});
-
afterEach(() => {
- mockUseGetV2GetCopilotUsage.mockReset();
mockUseGetV1UserCostSummary.mockReset();
- mockUseGetFlag.mockReset();
server.resetHandlers();
});
-function makeUsage({
- dailyPercent = 5,
- weeklyPercent = 4,
- tier = "BASIC",
-}: {
- dailyPercent?: number | null;
- weeklyPercent?: number | null;
- tier?: string;
-} = {}) {
- const future = new Date(Date.now() + 3600 * 1000).toISOString();
- return {
- daily:
- dailyPercent === null
- ? null
- : { percent_used: dailyPercent, resets_at: future },
- weekly:
- weeklyPercent === null
- ? null
- : { percent_used: weeklyPercent, resets_at: future },
- tier,
- };
-}
-
function emptyCostSummary() {
return {
data: {
@@ -130,87 +82,22 @@ function makeAgent(overrides: Partial<LibraryAgent> = {}): LibraryAgent {
} as unknown as LibraryAgent;
}
-describe("BriefingTabContent — UsageSection", () => {
- it("renders no usage block when usage fetch has not succeeded", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: undefined,
- isSuccess: false,
- });
- mockUseGetV1UserCostSummary.mockReturnValue(emptyCostSummary());
- mockUseGetFlag.mockReturnValue(false);
- render(<BriefingTabContent activeTab="all" agents={[]} />);
- expect(screen.queryByText("Usage limits")).toBeNull();
- });
-
- it("renders no usage block when both windows are null", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: makeUsage({ dailyPercent: null, weeklyPercent: null }),
- isSuccess: true,
- });
+describe("BriefingTabContent — dispatching", () => {
+ it("renders the costs breakdown toggle on the 'all' tab and no AutoPilot usage limits", () => {
mockUseGetV1UserCostSummary.mockReturnValue(emptyCostSummary());
- mockUseGetFlag.mockReturnValue(false);
render(<BriefingTabContent activeTab="all" agents={[]} />);
+ expect(
+ screen.getByRole("button", { name: /see costs breakdown/i }),
+ ).toBeDefined();
+ // AutoPilot rate-limit meters live in the Copilot section, not here.
expect(screen.queryByText("Usage limits")).toBeNull();
- });
-
- it("renders tier badge + daily+weekly meters at normal usage", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: makeUsage({ dailyPercent: 12, weeklyPercent: 4, tier: "PRO" }),
- isSuccess: true,
- });
- mockUseGetV1UserCostSummary.mockReturnValue(emptyCostSummary());
- mockUseGetFlag.mockReturnValue(true);
- render(<BriefingTabContent activeTab="all" agents={[]} />);
-
- expect(screen.getByText("Usage limits")).toBeDefined();
- expect(screen.getByText("Pro plan")).toBeDefined();
- expect(screen.getByText("12% used")).toBeDefined();
- expect(screen.getByText("4% used")).toBeDefined();
- expect(screen.getByText("Today")).toBeDefined();
- expect(screen.getByText("This week")).toBeDefined();
- expect(screen.getByText("Manage billing")).toBeDefined();
- });
-
- it("shows 'Manage billing' when billing flag is on", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: makeUsage({ dailyPercent: 100, weeklyPercent: 40 }),
- isSuccess: true,
- });
- mockUseGetV1UserCostSummary.mockReturnValue(emptyCostSummary());
- mockUseGetFlag.mockReturnValue(true);
- render(<BriefingTabContent activeTab="all" agents={[]} />);
- expect(screen.getByText("Manage billing")).toBeDefined();
- });
-
- it("hides 'Manage billing' when billing flag is off", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: makeUsage({ dailyPercent: 100, weeklyPercent: 40 }),
- isSuccess: true,
- });
- mockUseGetV1UserCostSummary.mockReturnValue(emptyCostSummary());
- mockUseGetFlag.mockReturnValue(false);
- render(<BriefingTabContent activeTab="all" agents={[]} />);
+ expect(screen.queryByText("Today")).toBeNull();
+ expect(screen.queryByText("This week")).toBeNull();
expect(screen.queryByText("Manage billing")).toBeNull();
});
- it("renders <1% used when percent is >0 but rounds to 0", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: makeUsage({ dailyPercent: 0.4, weeklyPercent: 0 }),
- isSuccess: true,
- });
- mockUseGetV1UserCostSummary.mockReturnValue(emptyCostSummary());
- mockUseGetFlag.mockReturnValue(false);
- render(<BriefingTabContent activeTab="all" agents={[]} />);
- expect(screen.getByText("<1% used")).toBeDefined();
- });
-
it("dispatches to ExecutionListSection for running/attention/completed tabs", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: undefined,
- isSuccess: false,
- });
mockUseGetV1UserCostSummary.mockReturnValue(emptyCostSummary());
- mockUseGetFlag.mockReturnValue(false);
for (const tab of ["running", "attention", "completed"] as const) {
const { unmount } = render(
@@ -224,12 +111,7 @@ describe("BriefingTabContent — UsageSection", () => {
});
it("dispatches to AgentListSection for listening/scheduled/idle tabs", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: undefined,
- isSuccess: false,
- });
mockUseGetV1UserCostSummary.mockReturnValue(emptyCostSummary());
- mockUseGetFlag.mockReturnValue(false);
for (const tab of ["listening", "scheduled", "idle"] as const) {
const { unmount } = render(
@@ -243,12 +125,7 @@ describe("BriefingTabContent — UsageSection", () => {
describe("BriefingTabContent — CostsBreakdown", () => {
it("shows 'No spend this month yet' when total is zero", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: undefined,
- isSuccess: false,
- });
mockUseGetV1UserCostSummary.mockReturnValue(emptyCostSummary());
- mockUseGetFlag.mockReturnValue(false);
render(<BriefingTabContent activeTab="all" agents={[]} />);
fireEvent.click(
screen.getByRole("button", { name: /see costs breakdown/i }),
@@ -257,10 +134,6 @@ describe("BriefingTabContent — CostsBreakdown", () => {
});
it("renders headline stats, top runs, and by-agent sections when spend > 0", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: undefined,
- isSuccess: false,
- });
mockUseGetV1UserCostSummary.mockReturnValue({
data: {
total_cents: 4250,
@@ -299,7 +172,6 @@ describe("BriefingTabContent — CostsBreakdown", () => {
isLoading: false,
isError: false,
});
- mockUseGetFlag.mockReturnValue(false);
render(
<BriefingTabContent
@@ -331,16 +203,11 @@ describe("BriefingTabContent — CostsBreakdown", () => {
});
it("surfaces an inline error when the cost-summary endpoint fails", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: undefined,
- isSuccess: false,
- });
mockUseGetV1UserCostSummary.mockReturnValue({
data: undefined,
isLoading: false,
isError: true,
});
- mockUseGetFlag.mockReturnValue(false);
render(<BriefingTabContent activeTab="all" agents={[]} />);
fireEvent.click(
@@ -350,10 +217,6 @@ describe("BriefingTabContent — CostsBreakdown", () => {
});
it("falls back to short graph_id label when agent isn't in the library", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: undefined,
- isSuccess: false,
- });
mockUseGetV1UserCostSummary.mockReturnValue({
data: {
total_cents: 500,
@@ -369,7 +232,6 @@ describe("BriefingTabContent — CostsBreakdown", () => {
isLoading: false,
isError: false,
});
- mockUseGetFlag.mockReturnValue(false);
render(<BriefingTabContent activeTab="all" agents={[]} />);
fireEvent.click(
@@ -379,10 +241,6 @@ describe("BriefingTabContent — CostsBreakdown", () => {
});
it("computes Avg / run from billable_run_count, not run_count", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: undefined,
- isSuccess: false,
- });
// 6 total runs but only 2 with cost > 0 — avg must be $5.00 (1000/2),
// not $1.67 (1000/6) which is what dividing by run_count would yield.
mockUseGetV1UserCostSummary.mockReturnValue({
@@ -398,7 +256,6 @@ describe("BriefingTabContent — CostsBreakdown", () => {
isLoading: false,
isError: false,
});
- mockUseGetFlag.mockReturnValue(false);
render(
<BriefingTabContent
@@ -413,16 +270,104 @@ describe("BriefingTabContent — CostsBreakdown", () => {
expect(screen.getByText("$5.00")).toBeDefined();
expect(screen.queryByText("$1.67")).toBeNull();
});
+
+ it("scales spend-by-agent bars as share of total monthly spend and hides zero-cost rollups", () => {
+ // Alpha: 75% of total, Beta: 25% of total, Gamma: $0.00 — should be hidden.
+ mockUseGetV1UserCostSummary.mockReturnValue({
+ data: {
+ total_cents: 4000,
+ run_count: 12,
+ billable_run_count: 10,
+ failed_cost_cents: 0,
+ by_agent: [
+ { graph_id: "g-1", cost_cents: 3000, run_count: 6 },
+ { graph_id: "g-2", cost_cents: 1000, run_count: 4 },
+ { graph_id: "g-3", cost_cents: 0, run_count: 2 },
+ ],
+ top_runs: [],
+ daily: [],
+ },
+ isLoading: false,
+ isError: false,
+ });
+
+ render(
+ <BriefingTabContent
+ activeTab="all"
+ agents={[
+ makeAgent({ id: "lib-1", graph_id: "g-1", name: "Alpha" }),
+ makeAgent({ id: "lib-2", graph_id: "g-2", name: "Beta" }),
+ makeAgent({ id: "lib-3", graph_id: "g-3", name: "Gamma" }),
+ ]}
+ />,
+ );
+ fireEvent.click(
+ screen.getByRole("button", { name: /see costs breakdown/i }),
+ );
+
+ expect(screen.getByText("% of monthly spend")).toBeDefined();
+ expect(screen.getByText("75%")).toBeDefined();
+ expect(screen.getByText("25%")).toBeDefined();
+ // Zero-cost agent omitted entirely.
+ expect(screen.queryByText("Gamma")).toBeNull();
+ });
+
+ it("renders an avg-per-run pill next to each agent's run count", () => {
+ mockUseGetV1UserCostSummary.mockReturnValue({
+ data: {
+ total_cents: 2000,
+ run_count: 4,
+ billable_run_count: 4,
+ failed_cost_cents: 0,
+ by_agent: [{ graph_id: "g-1", cost_cents: 2000, run_count: 4 }],
+ top_runs: [],
+ daily: [],
+ },
+ isLoading: false,
+ isError: false,
+ });
+
+ render(
+ <BriefingTabContent
+ activeTab="all"
+ agents={[makeAgent({ id: "lib-1", graph_id: "g-1", name: "Alpha" })]}
+ />,
+ );
+ fireEvent.click(
+ screen.getByRole("button", { name: /see costs breakdown/i }),
+ );
+
+ // 2000c / 4 runs = $5.00 per run, shown inline with the run count.
+ expect(screen.getByText(/4 runs · avg \$5\.00/)).toBeDefined();
+ });
+
+ it("renders the calendar-month range subtitle when expanded", () => {
+ mockUseGetV1UserCostSummary.mockReturnValue({
+ data: {
+ total_cents: 100,
+ run_count: 1,
+ billable_run_count: 1,
+ failed_cost_cents: 0,
+ by_agent: [{ graph_id: "g-1", cost_cents: 100, run_count: 1 }],
+ top_runs: [],
+ daily: [],
+ },
+ isLoading: false,
+ isError: false,
+ });
+
+ render(<BriefingTabContent activeTab="all" agents={[]} />);
+ fireEvent.click(
+ screen.getByRole("button", { name: /see costs breakdown/i }),
+ );
+ expect(screen.getByText(/Calendar month so far/)).toBeDefined();
+ expect(screen.getByText(/today \(UTC\)/)).toBeDefined();
+ });
});
describe("BriefingTabContent — CopilotLibrarySummary (Autopilot pill)", () => {
function setupBriefingMocks() {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: undefined,
- isSuccess: false,
- });
mockUseGetV1UserCostSummary.mockReturnValue(emptyCostSummary());
- mockUseGetFlag.mockReturnValue(false);
}
function makeSkill(overrides: { name?: string } = {}): CopilotSkillInfo {