Open-source SEO, GEO, and marketing skills for AI agents.
feat(sidebar): replace cost meter with Paired OpenClaw pill
Yuting Zhong6b709680f840
diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsxindex 99b08679..2f6d51eb 100644--- a/src/components/app-sidebar.tsx+++ b/src/components/app-sidebar.tsx@@ -28,7 +28,7 @@ import { getActiveProject } from "@/server/active-project";import { pendingApprovalCount } from "@/server/db/approvals";import { listProjectAgents } from "@/server/agent-meta";import { ProjectSwitcher } from "./project-switcher";-import { CostMeter } from "./cost-meter";+import { PairedOpenclawPill } from "./paired-openclaw-pill";import { AgentNav } from "./agent-nav";import { CreateAgentButton } from "./create-agent-button";import { Badge } from "@/components/ui/badge";@@ -123,7 +123,9 @@ export async function AppSidebar() {<SidebarFooter><SidebarSeparator />- {active && <CostMeter project_slug={active.slug} />}+ <div className="px-2 py-1.5">+ <PairedOpenclawPill />+ </div></SidebarFooter></Sidebar>);diff --git a/src/components/cost-meter.tsx b/src/components/cost-meter.tsxdeleted file mode 100644index 84dd6753..00000000--- a/src/components/cost-meter.tsx+++ /dev/null@@ -1,95 +0,0 @@-import { costToday } from "@/server/db/cost";-import { getGuardrails } from "@/server/db/guardrails";-import {- Tooltip,- TooltipContent,- TooltipTrigger,-} from "@/components/ui/tooltip";-import { cn } from "@/lib/utils";--type CostMeterProps = {- project_slug: string;-};--function formatUsd(amount: number): string {- return amount.toLocaleString("en-US", { style: "currency", currency: "USD" });-}--export function CostMeter({ project_slug }: CostMeterProps) {- const cost = costToday(project_slug);- const guardrails = getGuardrails(project_slug);- const cap = guardrails.max_daily_spend_usd;- const pct = cap > 0 ? Math.min(100, (cost.total_usd / cap) * 100) : 0;-- const status =- pct >= 100 ? "halted" : pct >= 90 ? "danger" : pct >= 75 ? "warn" : "ok";-- const barColor = {- ok: "bg-zinc-400 dark:bg-zinc-500",- warn: "bg-amber-500",- danger: "bg-red-500",- halted: "bg-red-600",- }[status];-- return (- <Tooltip>- <TooltipTrigger asChild>- <button- type="button"- className="w-full space-y-1.5 px-2 py-2 text-left text-xs transition-colors hover:bg-sidebar-accent/50 rounded-md"- >- <div className="flex items-center justify-between gap-2">- <span className="text-muted-foreground">Today</span>- <span- className={cn(- "tabular-nums font-medium",- status === "halted" && "text-red-600 dark:text-red-400",- status === "danger" && "text-red-600 dark:text-red-400",- )}- >- {formatUsd(cost.total_usd)} / {formatUsd(cap)}- </span>- </div>- <div className="h-1.5 w-full overflow-hidden rounded-full bg-muted">- <div- className={cn("h-full transition-all", barColor)}- style={{ width: `${pct}%` }}- aria-label={`${pct.toFixed(0)}% of daily budget`}- />- </div>- {status === "halted" && (- <p className="text-[11px] font-medium text-red-600 dark:text-red-400">- Daily cap reached- </p>- )}- </button>- </TooltipTrigger>- <TooltipContent side="right" align="end" className="w-56 space-y-1.5">- <p className="text-xs font-medium">Today’s spend</p>- <div className="space-y-1 text-[11px]">- <CostRow label="LLM" value={cost.by_source.llm} />- <CostRow label="Google Ads" value={cost.by_source.google_ads} />- <CostRow label="GSC" value={cost.by_source.gsc} />- <CostRow label="Other" value={cost.by_source.other} />- <div className="mt-1 flex items-center justify-between border-t pt-1 font-medium">- <span>Total</span>- <span className="tabular-nums">{formatUsd(cost.total_usd)}</span>- </div>- <div className="flex items-center justify-between text-muted-foreground">- <span>Daily cap</span>- <span className="tabular-nums">{formatUsd(cap)}</span>- </div>- </div>- </TooltipContent>- </Tooltip>- );-}--function CostRow({ label, value }: { label: string; value: number }) {- return (- <div className="flex items-center justify-between">- <span className="text-muted-foreground">{label}</span>- <span className="tabular-nums">{formatUsd(value)}</span>- </div>- );-}diff --git a/src/components/paired-openclaw-pill.tsx b/src/components/paired-openclaw-pill.tsxnew file mode 100644index 00000000..01baa7cc--- /dev/null+++ b/src/components/paired-openclaw-pill.tsx@@ -0,0 +1,56 @@+import { ExternalLink } from "lucide-react";+import { discoverGateway } from "@/server/openclaw/gateway-client";+import { cn } from "@/lib/utils";++/**+ * Sidebar pill that opens the OpenClaw gateway dashboard in a new tab with+ * token-based auto-auth. The token is embedded in the URL fragment (`#token=`)+ * — same mechanism `openclaw dashboard` uses — so it isn't sent to the server+ * in the HTTP request line. We render nothing when the gateway config can't+ * be discovered (rather than a broken-looking pill).+ */+export function PairedOpenclawPill() {+ let dashboardUrl: string | null = null;+ try {+ const gw = discoverGateway();+ // gw.url is ws://host:port — the dashboard lives at the same host:port+ // over http. Token goes in the fragment so it never hits server access+ // logs or HTTP referer headers.+ const httpBase = gw.url.replace(/^ws/, "http");+ dashboardUrl = gw.token+ ? `${httpBase}/#token=${encodeURIComponent(gw.token)}`+ : `${httpBase}/`;+ } catch {+ return null;+ }++ return (+ <a+ href={dashboardUrl}+ target="_blank"+ rel="noopener noreferrer"+ className={cn(+ "group inline-flex w-full items-center gap-2 rounded-full",+ "border border-border bg-background px-3 py-1.5",+ "text-xs font-medium text-foreground",+ "transition-colors hover:bg-sidebar-accent",+ "focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",+ // In icon-collapsed sidebar, keep the dot visible and hide the label.+ "group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:px-2",+ )}+ title="Open OpenClaw dashboard"+ >+ <span+ aria-hidden+ className="size-2 shrink-0 rounded-full bg-emerald-500"+ />+ <span className="flex-1 truncate group-data-[collapsible=icon]:hidden">+ Paired OpenClaw+ </span>+ <ExternalLink+ className="size-3.5 shrink-0 text-muted-foreground group-data-[collapsible=icon]:hidden"+ aria-hidden+ />+ </a>+ );+}