"use client"; import { useState } from "react"; import { contextWindow, sessionCost, turnCost, type ChatSettings, type TurnUsage } from "@/src/core"; import { formatTokens, formatUsd, prettyModel } from "@/components/usage-format"; import { ModelControl } from "@/components/model-picker"; /** * The below-composer stats bar (wave 4 observability): the session's * money/context footprint as one quiet row beneath the composer — * LEFT-aligned: context window + session cost; RIGHT-aligned: model + * thinking level. Clicking the left side opens the per-turn detail popover. * * All folds come from core/prices.ts (sessionCost, contextWindow, turnCost) * — no cost math lives here. Absent data renders "—", never zero (the * doctrine): no turns yet → every figure is "—"; turns the price table * can't price count as unpriced, shown in the popover, never folded into a * fake $0. The RIGHT side is the model + thinking control (components/ * model-picker.tsx): one controller for the conversation agents, backed by * pi-ai's catalog; the buttons show the EFFECTIVE model (the record's * settings, else config's pin), while the left-side figures still fold the * turn log's actual billed models. */ export function StatsBar({ turns, chatId, settings, onSettingsSaved, }: { turns: TurnUsage[]; chatId: string; settings?: ChatSettings; onSettingsSaved: (settings: ChatSettings) => void; }) { const [open, setOpen] = useState(false); const ctx = contextWindow({ turns }); const { cost, unpriced } = sessionCost({ turns }); // Honest cost: show dollars only when at least one turn priced; // otherwise "—" (never a fake $0.0000). const pricedCount = turns.length - unpriced; const costLabel = pricedCount > 0 ? formatUsd(cost) : "—"; const lastModel = turns.at(-1)?.model; return (