Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Merge pull request #5080 from BunBnnuy/feat/model-usage-colors
milind-sonia7dce136aa95
diff --cc src/components/UsageSection.tsxindex c2d7730ca5,d911358f99..0759069dd1--- a/src/components/UsageSection.tsx+++ b/src/components/UsageSection.tsx@@@ -4,8 -3,9 +4,9 @@@ import { ArrowLeft, ChevronRight, Downlimport { cn } from "@/lib/cn";import { activeLocale, documentLanguage, t } from "@/lib/i18n";import { listenLiveFrames } from "@/lib/live-events";+ import { modelColor, modelFamily } from "@/lib/model-color";import { formatTokens, hasFiniteCost, headlineTokens } from "@/lib/usage";-import { fetchTraces, formatCost, formatDuration, USAGE_PERIODS, usageExportHref, usagePeriodRange, type UsagePeriod } from "@/lib/usage-trace";+import { currentBotName, fetchTraces, formatCost, formatDuration, runTitle, USAGE_PERIODS, usageExportHref, usagePeriodRange, type UsagePeriod } from "@/lib/usage-trace";import { api, useStore } from "@/state/store";import type { LocaleKey } from "@/locales";import type { TraceList, TraceRootSummary } from "../../shared/usage-trace";@@@ -79,27 -94,57 +95,60 @@@ function useUsageGroupsreturn summary;}+ /** One bar: a group's models stacked in their own colours, or a single solid bar when it has no split. */+ function Bar({ group, width, color }: { group: UsageGroup; width: number; color?: string }) {+ const { state } = useStore();+ const segments = group.segments ?? [];+ const stack = segments.reduce((sum, piece) => sum + barTokens(piece), 0);+ if (segments.length && stack > 0) {+ return (+ <span className="flex h-full" style={{ width: `${width}%` }}>+ {segments.map((piece) => {+ const tokens = barTokens(piece);+ const share = Math.round((tokens / stack) * 100);+ return (+ <span+ key={piece.key}+ className="h-full"+ data-model-color={modelColor(piece.key)}+ style={{ width: `${(tokens / stack) * 100}%`, backgroundColor: modelColor(piece.key) }}+ title={`${modelName(piece.label, state.instances)} · ${formatTokens(tokens)} · ${share}%`}+ />+ );+ })}+ </span>+ );+ }+ return <span data-model-color={color} className={cn("block h-full rounded-full", !color && "bg-accent/70")} style={{ width: `${width}%`, backgroundColor: color }} />;+ }++ /** The six largest groups as proportional bars, with a model colour dot when the grouping is by model. */export function GroupBars({ groupBy, groups }: { groupBy: UsageGroupBy; groups: readonly UsageGroup[] }) {const { state } = useStore();+ const settings = useContext(SettingsLook);- const top = [...groups].sort((a, b) => headlineTokens(b) - headlineTokens(a)).slice(0, 6);- const max = Math.max(...top.map(headlineTokens), 0);+ const top = [...groups].sort((a, b) => barTokens(b) - barTokens(a)).slice(0, 6);+ const max = Math.max(...top.map(barTokens), 0);if (!top.length || max <= 0) return <p className="text-[13px] text-ink-secondary">{t("usage.page.whereEmpty")}</p>;return (<ul className="flex flex-col gap-2.5">{top.map((group) => {const bot = groupBy === "bot" ? state.bots.find((item) => `bot:${item.id}` === group.key) : undefined;- const family = groupBy === "model" ? modelFamily(group.key) : undefined;++ const family = !settings && groupBy === "model" ? modelFamily(group.key) : undefined;+ const color = family ? modelColor(group.key) : undefined;return (<li key={group.key} className="grid grid-cols-[minmax(0,9rem)_1fr_auto] items-center gap-3 text-[13px]" title={t("usage.page.turns", { count: String(group.turns) })}><span className="flex min-w-0 items-center gap-2 text-ink">{bot && <BotAvatar bot={bot} state="idle" size={18} animated={false} />}+ {family && <span aria-hidden="true" title={family.label} data-model-color={color} className="size-2 shrink-0 rounded-full" style={{ backgroundColor: color }} />}- <span className="truncate">{groupBy === "model" ? modelName(group.label, state.instances) : usageGroupLabel(groupBy, group)}</span>+ <span className="truncate">{bot ? bot.name : groupBy === "model" ? modelName(group.label, state.instances) : usageGroupLabel(groupBy, group)}</span></span>- <span className="h-2 overflow-hidden rounded-full bg-raised">- <Bar group={group} width={Math.max(2, (barTokens(group) / max) * 100)} color={color} />+ <span className={cn("h-2 overflow-hidden rounded-full", settings ? "bg-ink/[0.08]" : "bg-raised")}>- <span className={cn("block h-full rounded-full", settings ? "bg-ink" : "bg-accent/70")} style={{ width: `${Math.max(2, (headlineTokens(group) / max) * 100)}%` }} />++ {settings++ ? <span className="block h-full rounded-full bg-ink" style={{ width: `${Math.max(2, (barTokens(group) / max) * 100)}%` }} />++ : <Bar group={group} width={Math.max(2, (barTokens(group) / max) * 100)} color={color} />}</span><span className="min-w-[4.5rem] text-right tabular-nums text-ink-secondary">- {formatTokens(headlineTokens(group))}+ {formatTokens(barTokens(group))}{hasFiniteCost(group.costUsd) && group.costUsd > 0 && ` · ${formatCost(group.costUsd)}`}</span></li>@@@ -109,13 -154,36 +158,38 @@@);}+ /** The colours a stacked bar is made of, so its slices read without hovering. */+ function ModelLegend({ groups }: { groups: readonly UsageGroup[] }) {+ const { state } = useStore();+ const totals = new Map<string, { label: string; tokens: number }>();+ for (const group of groups) {+ for (const piece of group.segments ?? []) {+ const seen = totals.get(piece.key);+ totals.set(piece.key, { label: piece.label, tokens: (seen?.tokens ?? 0) + headlineTokens(piece) });+ }+ }+ const items = [...totals.entries()].sort((a, b) => b[1].tokens - a[1].tokens);+ if (items.length < 2) return null;+ return (+ <ul className="mt-2.5 flex flex-wrap gap-x-3 gap-y-1">+ {items.map(([key, item]) => (+ <li key={key} className="flex min-w-0 items-center gap-1.5 text-[11px] text-ink-secondary">+ <span aria-hidden="true" data-model-color={modelColor(key)} className="size-2 shrink-0 rounded-full" style={{ backgroundColor: modelColor(key) }} />+ <span className="max-w-[9rem] truncate">{modelName(item.label, state.instances)}</span>+ </li>+ ))}+ </ul>+ );+ }++ /** The "Where it went" panel: bots on one side, the chosen grouping on the other, both split by model. */function WhereItWent({ range, version, onBudget }: { range: { from: string; to: string }; version: number; onBudget: (budget: BudgetState | null) => void }) {const [other, setOther] = useState<UsageGroupBy>("model");+ const settings = useContext(SettingsLook);- const byBot = useUsageGroups(range, "bot", version);- const byOther = useUsageGroups(range, other, version);+ const byBot = useUsageGroups(range, "bot", version, "model");+ const byOther = useUsageGroups(range, other, version, other === "model" ? undefined : "model");useEffect(() => { onBudget(byBot?.budget ?? null); }, [byBot, onBudget]);+ if (settings) return null;return (<section className="rounded-2xl border border-hairline/50 bg-card p-5" aria-label={t("usage.page.where")}><h3 className="text-[15px] font-medium text-ink">{t("usage.page.where")}</h3>