Loading component…
Loading component…
This component has not been implemented locally yet.
To reuse this local React demo, copy all files from the Code tab into the same folder, then import AIChat/SpendPlanner from ./ai-chat-spend.
import { SpendChatScreen, type ChartFocus } from "@/components/ui/ai-chat-spend";
export default function Page() {
return (
<SpendChatScreen
onAsk={async (question: string, focus?: ChartFocus) => {
const res = await fetch("/api/spend", { method: "POST", body: JSON.stringify({ question, focus }) });
return res.json(); // { role: "assistant", text, kpis?, chart?, caption?, sources?, next? }
}}
onNavigate={(label) => router.push(routes[label])}
/>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| onAsk | (question, focus?) => Answer \| Promise<Answer> | How the screen answers – an answer is { role: "assistant", text, kpis?: { label; value; change?; since?; goodWhenDown? }[], chart?, caption?, sources?, next? }. focus is set when the question is about part of a chart: { chart, from, to, label, detail }. Without it the screen answers the questions it offers from its sample | |
| chart | { kind: "split" \| "trend" \| "forecast" \| "plan"; … } | "split": { title, previous?, since?, groups: { name, logo?, color?, parts: { name, value }[] }[] } – one bar per provider or team, a segment per model, drawn with Model Usage (values in dollars). "trend": { labels, current, previous, mark? } and "forecast": { labels, actual, forecast, target? } – drawn with Trend Chart (values in thousands). "plan": { now, months, growth, levers } – the totals, the levers and the forecast that follows them | |
| levers | { id; label; detail; kind: "range" \| "switch"; base; save; max?; value }[] | The changes a plan offers. base is what it touches a month in dollars, save the share of that it saves at full; a slider goes from 0 to max %, a switch is on (1) or off (0). What each saves, the totals and the six-month forecast follow as they move. Turn into rules asks the next question with the plan quoted above it | |
| turns | ChatTurn[] | The conversation so far – { role: "user", text, quote? } and answers as above | |
| chats | ShellChat[] | The chats in the sidebar | |
| loading | boolean | Gray lines, cards and chart in place of the conversation | |
| empty | boolean | A new chat – a short note and questions to start with | |
| onNavigate | (label: string) => void | Called with the label of a sidebar item | |
| className | string | Extra class on the root |
The sidebar starts folded to its icons so the chat has the room; the column stays at 760px in the middle, cards and charts as wide as the composer
On phones the mark steps back, cards sit two by two, sliders take the whole width and grow to touch size
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"