diff --git a/README.md b/README.md index 78a6acc..e84be57 100644 --- a/README.md +++ b/README.md @@ -69,8 +69,8 @@ gh attestation verify "${VMBRIDGE_INSTALL_DIR:-$HOME/.local/bin}/vmbridge" --rep 1. Run `vmbridge` and open one of the setup links it prints. 2. Choose a dashboard password, add a provider, sign in your agents and choose whether to bring your - skills and instructions. GitHub is under **Setup** in the dashboard. -3. Under **Devices**, create a pairing link and paste it into T3 Code as a remote environment. + skills and instructions. GitHub is under **Accounts** in the dashboard. +3. Under **Settings**, **Devices**, create a pairing link and paste it into T3 Code as a remote environment. Start a thread in T3 Code and VM Bridge brings up a VM for it. diff --git a/apps/landing/app/docs/page.tsx b/apps/landing/app/docs/page.tsx index 199e4db..5fcdc8e 100644 --- a/apps/landing/app/docs/page.tsx +++ b/apps/landing/app/docs/page.tsx @@ -293,7 +293,7 @@ bun run compile # dist/vmbridge

- Open /dashboard on any address VM Bridge printed and log in with your password. Setup has three tabs. + Open /dashboard on any address VM Bridge printed and log in with your password. Accounts has three tabs.

- Under Devices, name the device and create a pairing link. In T3 Code, add a remote environment and paste the link. + Under Settings, Devices, name the device and create a pairing link. In T3 Code, add a remote environment and paste the link.

@@ -437,7 +437,7 @@ bun run compile # dist/vmbridge

- Agents and git sign in only with what you add in Setup, never with sign-ins from the VM provider. Each agent sign-in is a profile saved, encrypted, in{" "} + Agents and git sign in only with what you add in Accounts, never with sign-ins from the VM provider. Each agent sign-in is a profile saved, encrypted, in{" "} ~/.vmbridge/main.db. Each agent uses one profile at a time, and VMs get it when they start.

entry !== id); settings.set("providers", remaining); - // Its base snapshots are billed until deleted, so a failure stays on the provider in Setup. + // Its base snapshots are billed until deleted, so a failure stays on the provider in Accounts. void fleet.bases.drop(id).catch((error) => this.deps.traffic.record({ kind: "provider", operation: "remove provider", provider: id, status: "error", reason: message(error) }), ); diff --git a/apps/server/src/analytics.ts b/apps/server/src/analytics.ts index 4f5cf57..1aec4e7 100644 --- a/apps/server/src/analytics.ts +++ b/apps/server/src/analytics.ts @@ -68,7 +68,7 @@ const add = (a: Estimate, b: Estimate): Estimate => ({ amount: a.amount + b.amou /** * VM time, spend, lifecycle, turns and errors from `from` to `until` (which ends at `now` at the latest), by day in - * `timeZone` where it helps. Time and spend come from `usage`, so they match the Costs page. + * `timeZone` where it helps. Time and spend come from `usage`, so they match the Costs tab. */ export function analyticsReport(store: Store, usage: Usage, from: number, until: number, timeZone: string, now = Date.now()): AnalyticsReport { const to = Math.min(until, now); diff --git a/apps/server/src/budget.ts b/apps/server/src/budget.ts index 78c44a0..69a7c20 100644 --- a/apps/server/src/budget.ts +++ b/apps/server/src/budget.ts @@ -20,7 +20,7 @@ const dollars = (amount: number) => `$${amount.toFixed(2)}`; export class BudgetReached extends Error {} /** - * One monthly budget for all providers, checked against the same estimate the Costs page shows. It never stops or + * One monthly budget for all providers, checked against the same estimate the Usage page's Costs tab shows. It never stops or * deletes anything: at the limit, early wakes stop, and with `stopAtLimit` on, new VMs and wakes are refused too. */ export class Budget { @@ -53,7 +53,7 @@ export class Budget { refusal(now = Date.now()): string | null { const status = this.status(now); if (status.level !== "over" || !status.stopAtLimit || status.monthlyUsd === null) return null; - return `VM Bridge reached this month's budget of ${dollars(status.monthlyUsd)}, so it is not starting or waking VMs. Raise the budget on the Costs page of the VM Bridge dashboard.`; + return `VM Bridge reached this month's budget of ${dollars(status.monthlyUsd)}, so it is not starting or waking VMs. Raise the budget on the Usage page of the VM Bridge dashboard.`; } /** Early wakes are only a guess that a message follows, so they stop at the limit even without `stopAtLimit`. */ diff --git a/apps/server/src/fleet.ts b/apps/server/src/fleet.ts index f9fed79..4e1054a 100644 --- a/apps/server/src/fleet.ts +++ b/apps/server/src/fleet.ts @@ -248,7 +248,7 @@ export class Fleet extends EventEmitter { async create(choice: { provider?: ProviderId; size?: VmSize; discardOnError?: boolean } = {}): Promise { this.refuse(); const provider = choice.provider ?? this.available(); - if (!this.settings.get("providers").includes(provider)) throw new Error(`Add ${providers[provider].label} in Setup first.`); + if (!this.settings.get("providers").includes(provider)) throw new Error(`Add ${providers[provider].label} in Accounts first.`); if (this.settingUp(provider)) throw new SettingUp(provider); const driver = this.driver(provider); const id = shortId(); @@ -942,7 +942,7 @@ fi`, ) .finally(() => { this.reconciling.delete(provider); - // The provider's flag in Setup comes with the overview. + // The provider's flag in Accounts comes with the overview. this.emit("changed"); }); this.reconciling.set(provider, flight); diff --git a/apps/server/src/settings.ts b/apps/server/src/settings.ts index 5c261b4..93b23f1 100644 --- a/apps/server/src/settings.ts +++ b/apps/server/src/settings.ts @@ -15,7 +15,7 @@ interface SettingValues { onboarded: boolean; /** The name T3 shows for this machine. */ machineName: string; - /** Providers added in Setup, in order. VMs on a removed provider keep running but get no new VMs beside them. */ + /** Providers added in Accounts, in order. VMs on a removed provider keep running but get no new VMs beside them. */ providers: ProviderId[]; /** One of `providers`. New VMs go here unless a repository rule picks another. */ defaultProvider: ProviderId | null; diff --git a/apps/server/src/vm/bases.ts b/apps/server/src/vm/bases.ts index 561d866..d979913 100644 --- a/apps/server/src/vm/bases.ts +++ b/apps/server/src/vm/bases.ts @@ -270,7 +270,7 @@ const tookTooLong = `Setup took longer than ${baseSetupLimitMs / 60_000} minutes /** Why a build failed, short enough to show next to a provider. */ function failureReason(provider: ProviderId, error: unknown) { // A key that was rotated or revoked fails every build, and the provider's HTTP error does not say what to do. - if (error instanceof SandboxError && error.code === "auth") return `${providers[provider].label} refused the API key. Enter a new one in Setup.`; + if (error instanceof SandboxError && error.code === "auth") return `${providers[provider].label} refused the API key. Enter a new one in Accounts.`; const line = (error instanceof Error ? error.message : String(error)).trim().split("\n")[0] ?? ""; if (!line) return "The build failed."; return line.length > 200 ? `${line.slice(0, 197)}...` : line; diff --git a/apps/server/test/analytics.test.ts b/apps/server/test/analytics.test.ts index 2701979..af978a3 100644 --- a/apps/server/test/analytics.test.ts +++ b/apps/server/test/analytics.test.ts @@ -80,7 +80,7 @@ describe("report", () => { const boxd = pricing("boxd"); const boxdDay = (boxd.runningHourly.medium + 23 * boxd.asleepHourly.medium!) * eurUsd.rate; expect(days[1]!.providers[1]!.estimate.amount).toBeCloseTo(boxdDay, 6); - // Matches what the Costs page totals, in US dollars. + // Matches what the Costs tab totals, in US dollars. expect(total.amount).toBeCloseTo(4 * 0.036 + boxdDay, 6); }); diff --git a/apps/server/test/bases.test.ts b/apps/server/test/bases.test.ts index 21fe770..5d3ebab 100644 --- a/apps/server/test/bases.test.ts +++ b/apps/server/test/bases.test.ts @@ -341,7 +341,7 @@ describe("setting up a provider", () => { fleet.prepareBase("boxd"); await fleet.bases.settled(); // A rotated or revoked key: the reason says what to do, not the HTTP error. - expect(fleet.setup("boxd")).toEqual({ state: "failed", reason: "boxd refused the API key. Enter a new one in Setup." }); + expect(fleet.setup("boxd")).toEqual({ state: "failed", reason: "boxd refused the API key. Enter a new one in Accounts." }); driver.create = create; fleet.prepareBase("boxd", true); await fleet.bases.settled(); @@ -351,7 +351,7 @@ describe("setting up a provider", () => { } expect(logs).toEqual([ "[base boxd:medium] build started", - expect.stringMatching(/^\[base boxd:medium\] build failed after \d+ s: boxd refused the API key\. Enter a new one in Setup\.$/), + expect.stringMatching(/^\[base boxd:medium\] build failed after \d+ s: boxd refused the API key\. Enter a new one in Accounts\.$/), "[base boxd:medium] build started", expect.stringMatching(/^\[base boxd:medium\] ready in \d+ s$/), ]); diff --git a/apps/server/test/budget.test.ts b/apps/server/test/budget.test.ts index cf3dafd..31e104a 100644 --- a/apps/server/test/budget.test.ts +++ b/apps/server/test/budget.test.ts @@ -57,7 +57,7 @@ describe("monthly budget", () => { expect(setup(hoursFor(0.9), { monthlyUsd: 1, stopAtLimit: true }).budget.refusal(at)).toBeNull(); const refusal = setup(hoursFor(1.1), { monthlyUsd: 1, stopAtLimit: true }).budget.refusal(at); expect(refusal).toContain("budget of $1.00"); - expect(refusal).toContain("Costs page of the VM Bridge dashboard"); + expect(refusal).toContain("Usage page of the VM Bridge dashboard"); }); test("early wakes stop at 100% even with the setting off", () => { diff --git a/apps/server/test/placement.test.ts b/apps/server/test/placement.test.ts index 8da4219..fbc076c 100644 --- a/apps/server/test/placement.test.ts +++ b/apps/server/test/placement.test.ts @@ -47,7 +47,7 @@ describe("where a new VM goes", () => { test("a VM can only be created on an added provider", async () => { const { fleet } = setup(); - await expect(fleet.create({ provider: "daytona" })).rejects.toThrow("Add Daytona in Setup first."); + await expect(fleet.create({ provider: "daytona" })).rejects.toThrow("Add Daytona in Accounts first."); }); }); diff --git a/apps/web/src/Setup.tsx b/apps/web/src/Accounts.tsx similarity index 99% rename from apps/web/src/Setup.tsx rename to apps/web/src/Accounts.tsx index 665e9aa..9337f7a 100644 --- a/apps/web/src/Setup.tsx +++ b/apps/web/src/Accounts.tsx @@ -18,20 +18,20 @@ import { CopyButton } from "./CopyButton.tsx"; import { Page, Section, type Tab } from "./Page.tsx"; import { Private } from "./Private.tsx"; -type SetupTab = "provider" | "github" | "agents"; +type AccountsTab = "provider" | "github" | "agents"; const sleepModes = { pause: "Pauses: memory and disk kept", stop: "Stops: disk kept", checkpoint: "Checkpoints: disk kept, new sandbox on wake" }; -export function Setup({ overview }: { overview: Overview }) { - const tabs: Tab[] = [ +export function Accounts({ overview }: { overview: Overview }) { + const tabs: Tab[] = [ { id: "provider", label: "Providers", icon: Plug01Icon, attention: !overview.setup.provider }, { id: "github", label: "GitHub", icon: GithubIcon, attention: !overview.setup.github }, { id: "agents", label: "Agent sign-in", icon: Robot01Icon, attention: !overview.setup.agents }, ]; const [tab, setTab] = useQueryState("tab", parseAsStringLiteral(tabs.map((entry) => entry.id)).withDefault(overview.setup.provider ? "agents" : "provider")); return ( - + {tab === "provider" && } {tab === "github" && } {tab === "agents" && } diff --git a/apps/web/src/Analytics.tsx b/apps/web/src/Analytics.tsx index 6c548b3..9de9021 100644 --- a/apps/web/src/Analytics.tsx +++ b/apps/web/src/Analytics.tsx @@ -2,15 +2,13 @@ import { useEffect, useState, type ReactNode } from "react"; import { HugeiconsIcon } from "@hugeicons/react"; import { Analytics01Icon } from "@hugeicons/core-free-icons"; import { agentKinds, providerIds, type AnalyticsDay, type AnalyticsReport, type Overview, type ProviderActivity, type ProviderId } from "@vmbridge/contracts"; -import { Button } from "@/components/ui/button"; -import { ButtonGroup } from "@/components/ui/button-group"; import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from "@/components/ui/empty"; import { FieldError } from "@/components/ui/field"; import { cn } from "@/lib/utils"; import { api, useTick } from "./api.ts"; import { AgentLogo, ProviderLogo } from "./brand.tsx"; -import { Bars, days, hours, money, rangeStart, ranges, Rows, Tile, type Range } from "./Costs.tsx"; -import { Page, Section } from "./Page.tsx"; +import { Bars, days, hours, money, rangeStart, Rows, Tile, type Range } from "./Costs.tsx"; +import { Section } from "./Page.tsx"; /** One fixed color per provider, so a provider keeps its color in every chart and range. */ const providerColors: Record = { @@ -26,8 +24,7 @@ const providerColors: Record = { }; const otherColor = "#5c5c5c"; -export function Analytics({ overview }: { overview: Overview }) { - const [range, setRange] = useState("month"); +export function Analytics({ overview, range }: { overview: Overview; range: Range }) { const [report, setReport] = useState(null); const [error, setError] = useState(null); // Awake time adds up while the page is open, and a VM waking or sleeping changes it. @@ -49,22 +46,10 @@ export function Analytics({ overview }: { overview: Overview }) { const label = (id: ProviderId) => overview.providers.find((provider) => provider.id === id)?.label ?? id[0]!.toUpperCase() + id.slice(1); return ( - - {ranges.map((entry) => ( - - ))} - - } - > + <> {error && {error}} {report && } - + ); } diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx index 2f93a96..b40e056 100644 --- a/apps/web/src/App.tsx +++ b/apps/web/src/App.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from "react"; import { flushSync } from "react-dom"; import { parseAsString, parseAsStringLiteral, useQueryStates } from "nuqs"; import { HugeiconsIcon, type IconSvgElement } from "@hugeicons/react"; -import { Analytics01Icon, Coins01Icon, File01Icon, FlowConnectionIcon, LaptopIcon, Logout01Icon, MagicWand01Icon, Plug01Icon, Settings01Icon } from "@hugeicons/core-free-icons"; +import { Analytics01Icon, File01Icon, FlowConnectionIcon, Logout01Icon, MagicWand01Icon, Settings01Icon, UserAccountIcon } from "@hugeicons/core-free-icons"; import { Button } from "@/components/ui/button"; import { Field, FieldError, FieldGroup, FieldLabel } from "@/components/ui/field"; import { Input } from "@/components/ui/input"; @@ -13,35 +13,42 @@ import { failingDevices, sinceText } from "@/lib/devices"; import { cn } from "@/lib/utils"; import { api, onLoggedOut, useLive, useTick } from "./api.ts"; import { Logo } from "./brand.tsx"; -import { Analytics } from "./Analytics.tsx"; +import { Accounts } from "./Accounts.tsx"; import { Canvas } from "./Canvas.tsx"; import { BudgetBanner } from "./Budget.tsx"; -import { Costs } from "./Costs.tsx"; -import { Devices } from "./Devices.tsx"; import { Logs } from "./Logs.tsx"; import { boxStyle, NavIndicator, useSlidingNav } from "./nav.tsx"; import { Onboarding } from "./Onboarding.tsx"; -import { Settings } from "./Settings.tsx"; -import { Setup } from "./Setup.tsx"; +import { Settings, type SettingsTab } from "./Settings.tsx"; import { Skills } from "./Skills.tsx"; +import { Usage, type UsageTab } from "./Usage.tsx"; const views = [ { id: "canvas", label: "Canvas", icon: FlowConnectionIcon }, { id: "logs", label: "Logs", icon: File01Icon }, - { id: "costs", label: "Costs", icon: Coins01Icon }, - { id: "analytics", label: "Analytics", icon: Analytics01Icon }, - { id: "setup", label: "Setup", icon: Plug01Icon }, + { id: "usage", label: "Usage", icon: Analytics01Icon }, + { id: "accounts", label: "Accounts", icon: UserAccountIcon }, { id: "skills", label: "Skills", icon: MagicWand01Icon }, - { id: "devices", label: "Devices", icon: LaptopIcon }, { id: "settings", label: "Settings", icon: Settings01Icon }, ] as const satisfies readonly { id: string; label: string; icon: IconSvgElement }[]; type View = (typeof views)[number]["id"]; -/** The view and its page's tab live in the URL so a reload keeps your place. A new view starts on its first tab. */ +/** Tabs that other pages link straight to. */ +interface ViewTabs { + usage: UsageTab; + settings: SettingsTab; +} + +type Place = { [V in View]: { view: V; tab?: V extends keyof ViewTabs ? ViewTabs[V] : never } }[View]; + +/** + * The view and its page's tab live in the URL so a reload keeps your place. A new view starts on its first tab unless the link names one. + * Links from before pages were merged are rewritten in main.tsx. + */ function useView() { - const [{ view }, setUrl] = useQueryStates({ view: parseAsStringLiteral(views.map((entry) => entry.id)), tab: parseAsString }); - return [view, (next: View) => void setUrl({ view: next, tab: null })] as const; + const [{ view, tab }, setUrl] = useQueryStates({ view: parseAsStringLiteral(views.map((entry) => entry.id)), tab: parseAsString }); + return [view, tab, (next: Place) => void setUrl({ view: next.view, tab: next.tab ?? null })] as const; } interface AuthState { @@ -115,12 +122,12 @@ function Login({ onLoggedIn }: { onLoggedIn: () => void }) { function Dashboard({ onLoggedOut }: { onLoggedOut: () => void }) { const { overview, traffic, online } = useLive(); - const [chosen, go] = useView(); - const view: View = chosen ?? (overview && !overview.setup.provider ? "setup" : "canvas"); + const [chosen, tab, go] = useView(); + const view: View = chosen ?? (overview && !overview.setup.provider ? "accounts" : "canvas"); const setupDone = overview && overview.setup.provider && overview.setup.github && overview.setup.agents; const current = views.find((entry) => entry.id === view)!; const now = useTick(30_000); - // Only failures: a device that is just away, such as a closed laptop, shows on the Devices page. + // Only failures: a device that is just away, such as a closed laptop, shows on the Devices tab. const failing = overview ? failingDevices(overview.clients, traffic, now) : []; const trouble = overview?.connectTrouble ?? null; @@ -137,13 +144,13 @@ function Dashboard({ onLoggedOut }: { onLoggedOut: () => void }) { {online ? "Live" : "Reconnecting"} - {overview && go("costs")} />} + {overview && go({ view: "usage", tab: "costs" })} />}
go({ view: next })} onLogOut={() => void api("/logout", { body: {} }).finally(onLoggedOut)} /> @@ -153,12 +160,12 @@ function Dashboard({ onLoggedOut }: { onLoggedOut: () => void }) { T3 Code reached VM Bridge {trouble.reads} times since {sinceText(trouble.since, now)} but could not connect. -
)} - {failing.length > 0 && view !== "devices" && ( + {failing.length > 0 && !(view === "settings" && tab === "devices") && (
{failing.map((client) => ( @@ -167,20 +174,18 @@ function Dashboard({ onLoggedOut }: { onLoggedOut: () => void }) { ))} -
)}
- {overview && view === "canvas" && go("devices")} />} + {overview && view === "canvas" && go({ view: "settings", tab: "devices" })} />} {overview && view === "logs" && } - {overview && view === "costs" && } - {overview && view === "analytics" && } - {overview && view === "setup" && } + {overview && view === "usage" && } + {overview && view === "accounts" && } {overview && view === "skills" && } - {overview && view === "devices" && } - {overview && view === "settings" && } + {overview && view === "settings" && }
@@ -225,7 +230,7 @@ function Sidebar({ view, setupPending, onView, onLogOut }: { view?: View; setupP className={cn(item, view === entry.id && "text-foreground")} > - {entry.id === "setup" && setupPending && } + {entry.id === "accounts" && setupPending && } ))} - ))} - - } - > + <> {error && {error}} {report && } -
+ ); } diff --git a/apps/web/src/Devices.tsx b/apps/web/src/Devices.tsx index 777bd43..e03af57 100644 --- a/apps/web/src/Devices.tsx +++ b/apps/web/src/Devices.tsx @@ -23,7 +23,7 @@ import { useAction } from "@/hooks/use-action"; import { failingReason, sinceText } from "@/lib/devices"; import { ago, api, useTick } from "./api.ts"; import { CopyButton } from "./CopyButton.tsx"; -import { Page, Section } from "./Page.tsx"; +import { Section } from "./Page.tsx"; export function Devices({ overview, traffic }: { overview: Overview; traffic: TrafficEvent[] }) { const now = useTick(15_000); @@ -36,7 +36,7 @@ export function Devices({ overview, traffic }: { overview: Overview; traffic: Tr const pending = links.filter((link) => !link.redeemedAt && link.expiresAt > now); return ( - + <>
0 && {overview.clients.length}}> @@ -82,7 +82,7 @@ export function Devices({ overview, traffic }: { overview: Overview; traffic: Tr
)} -
+ ); } diff --git a/apps/web/src/Onboarding.tsx b/apps/web/src/Onboarding.tsx index d3850ac..6f4a1c7 100644 --- a/apps/web/src/Onboarding.tsx +++ b/apps/web/src/Onboarding.tsx @@ -11,7 +11,7 @@ import { useAction } from "@/hooks/use-action"; import { cn } from "@/lib/utils"; import { api, useLive } from "./api.ts"; import { AgentLogo, Logo, ProviderLogo } from "./brand.tsx"; -import { agentNames, AgentSection, githubTokenHint, githubTokenUrl, Providers, ProviderStatus } from "./Setup.tsx"; +import { agentNames, AgentSection, githubTokenHint, githubTokenUrl, Providers, ProviderStatus } from "./Accounts.tsx"; const steps = [ { id: "password", label: "Password", icon: SquareLock02Icon }, @@ -378,7 +378,7 @@ function AgentsStep({ overview, back, onNext }: { overview: Overview; back: Reac ); } -/** Saved through the same route as Setup's GitHub tab, which checks the token with GitHub before keeping it. */ +/** Saved through the same route as the GitHub tab in Accounts, which checks the token with GitHub before keeping it. */ function GitHubStep({ account, back, onNext }: { account: GitHubAccount | null; back: ReactNode; onNext: () => void }) { const [token, setToken] = useState(""); // The saved account shows at once, before the live overview catches up. @@ -453,7 +453,7 @@ function GitHubStep({ account, back, onNext }: { account: GitHubAccount | null; -

VMs use it to clone, push and open pull requests. You can add it later in Setup.

+

VMs use it to clone, push and open pull requests. You can add it later in Accounts.

)} diff --git a/apps/web/src/Settings.tsx b/apps/web/src/Settings.tsx index 1af4c65..5c59e88 100644 --- a/apps/web/src/Settings.tsx +++ b/apps/web/src/Settings.tsx @@ -2,8 +2,8 @@ import { useEffect, useRef, useState } from "react"; import { parseAsStringLiteral, useQueryState } from "nuqs"; import { HugeiconsIcon } from "@hugeicons/react"; import { toast } from "sonner"; -import { Add01Icon, Cancel01Icon, CommandLineIcon, ComputerIcon, Delete02Icon, GitBranchIcon, GithubIcon, GlobalIcon, Key01Icon, Tick02Icon, UnfoldMoreIcon } from "@hugeicons/core-free-icons"; -import { agentFeedbackModes, machineNameMaxLength, vmSizes, type AddressTest, type AgentFeedbackMode, type BridgeNetworkInfo, type BridgeSettings, type CloudflareInfo, type Overview, type ProviderId, type RepoRule, type VmSize } from "@vmbridge/contracts"; +import { Add01Icon, Cancel01Icon, CommandLineIcon, ComputerIcon, Delete02Icon, GitBranchIcon, GithubIcon, GlobalIcon, Key01Icon, LaptopIcon, Tick02Icon, UnfoldMoreIcon } from "@hugeicons/core-free-icons"; +import { agentFeedbackModes, machineNameMaxLength, vmSizes, type AddressTest, type AgentFeedbackMode, type BridgeNetworkInfo, type BridgeSettings, type CloudflareInfo, type Overview, type ProviderId, type RepoRule, type TrafficEvent, type VmSize } from "@vmbridge/contracts"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command"; @@ -19,26 +19,29 @@ import { cn } from "@/lib/utils"; import { api } from "./api.ts"; import { ProviderLogo } from "./brand.tsx"; import { CopyButton } from "./CopyButton.tsx"; +import { Devices } from "./Devices.tsx"; import { Environment } from "./Environment.tsx"; import { Page, Section, type Tab } from "./Page.tsx"; -type SettingsTab = "vms" | "repos" | "env" | "addresses" | "password"; +export type SettingsTab = "vms" | "repos" | "env" | "devices" | "addresses" | "password"; const tabs: Tab[] = [ { id: "vms", label: "VMs", icon: ComputerIcon }, { id: "repos", label: "Repositories", icon: GitBranchIcon }, { id: "env", label: "Environment", icon: CommandLineIcon }, + { id: "devices", label: "Devices", icon: LaptopIcon }, { id: "addresses", label: "Addresses", icon: GlobalIcon }, { id: "password", label: "Password", icon: Key01Icon }, ]; -export function Settings({ overview, onLoggedOut }: { overview: Overview; onLoggedOut: () => void }) { +export function Settings({ overview, traffic, onLoggedOut }: { overview: Overview; traffic: TrafficEvent[]; onLoggedOut: () => void }) { const [tab, setTab] = useQueryState("tab", parseAsStringLiteral(tabs.map((entry) => entry.id)).withDefault("vms")); return ( {tab === "vms" && } {tab === "repos" && } {tab === "env" && } + {tab === "devices" && } {tab === "addresses" && } {tab === "password" && } diff --git a/apps/web/src/Skills.tsx b/apps/web/src/Skills.tsx index 0a606cc..c2ab921 100644 --- a/apps/web/src/Skills.tsx +++ b/apps/web/src/Skills.tsx @@ -49,7 +49,7 @@ import { cn } from "@/lib/utils"; import { skillFromFile, skillFromFolderPick, skillsFromDrop, type SkillUpload } from "@/lib/skill-upload"; import { api } from "./api.ts"; import { Page, Section, type Tab } from "./Page.tsx"; -import { agentNames } from "./Setup.tsx"; +import { agentNames } from "./Accounts.tsx"; type SkillsTab = "installed" | "machine" | "instructions"; diff --git a/apps/web/src/Usage.tsx b/apps/web/src/Usage.tsx new file mode 100644 index 0000000..e25e548 --- /dev/null +++ b/apps/web/src/Usage.tsx @@ -0,0 +1,43 @@ +import { useState } from "react"; +import { parseAsStringLiteral, useQueryState } from "nuqs"; +import { ChartLineData01Icon, Coins01Icon } from "@hugeicons/core-free-icons"; +import type { Overview } from "@vmbridge/contracts"; +import { Button } from "@/components/ui/button"; +import { ButtonGroup } from "@/components/ui/button-group"; +import { Analytics } from "./Analytics.tsx"; +import { Costs, ranges, type Range } from "./Costs.tsx"; +import { Page, type Tab } from "./Page.tsx"; + +export type UsageTab = "costs" | "activity"; + +const tabs: Tab[] = [ + { id: "costs", label: "Costs", icon: Coins01Icon }, + { id: "activity", label: "Activity", icon: ChartLineData01Icon }, +]; + +/** Spend and activity over the same range, which stays put when switching tabs. */ +export function Usage({ overview }: { overview: Overview }) { + const [tab, setTab] = useQueryState("tab", parseAsStringLiteral(tabs.map((entry) => entry.id)).withDefault("costs")); + const [range, setRange] = useState("month"); + return ( + + {ranges.map((entry) => ( + + ))} + + } + > + {tab === "costs" && } + {tab === "activity" && } + + ); +} diff --git a/apps/web/src/lib/moved-links.test.ts b/apps/web/src/lib/moved-links.test.ts new file mode 100644 index 0000000..6056290 --- /dev/null +++ b/apps/web/src/lib/moved-links.test.ts @@ -0,0 +1,16 @@ +import { expect, test } from "bun:test"; +import { movedLink } from "./moved-links.ts"; + +test("links to merged pages open the same place on the new page", () => { + expect(movedLink("?view=costs")).toBe("?view=usage&tab=costs"); + expect(movedLink("?view=analytics")).toBe("?view=usage&tab=activity"); + expect(movedLink("?view=setup&tab=github")).toBe("?view=accounts&tab=github"); + expect(movedLink("?view=setup")).toBe("?view=accounts"); + expect(movedLink("?view=devices")).toBe("?view=settings&tab=devices"); +}); + +test("current links are left alone", () => { + expect(movedLink("")).toBeNull(); + expect(movedLink("?view=settings&tab=env")).toBeNull(); + expect(movedLink("?view=usage&tab=activity")).toBeNull(); +}); diff --git a/apps/web/src/lib/moved-links.ts b/apps/web/src/lib/moved-links.ts new file mode 100644 index 0000000..7f85cb8 --- /dev/null +++ b/apps/web/src/lib/moved-links.ts @@ -0,0 +1,18 @@ +/** Pages that were merged into others, mapped to where their content lives now. */ +const moved: Record = { + costs: { view: "usage", tab: "costs" }, + analytics: { view: "usage", tab: "activity" }, + // Its tabs kept their ids, so an old tab still opens. + setup: { view: "accounts" }, + devices: { view: "settings", tab: "devices" }, +}; + +/** The query string an old dashboard link should use instead, or null when it needs no change. */ +export function movedLink(search: string) { + const query = new URLSearchParams(search); + const target = moved[query.get("view") ?? ""]; + if (!target) return null; + query.set("view", target.view); + if (target.tab) query.set("tab", target.tab); + return `?${query}`; +} diff --git a/apps/web/src/main.tsx b/apps/web/src/main.tsx index a39ed22..bb43bb3 100644 --- a/apps/web/src/main.tsx +++ b/apps/web/src/main.tsx @@ -3,8 +3,13 @@ import "@fontsource/fragment-mono"; import { NuqsAdapter } from "nuqs/adapters/react"; import { createRoot } from "react-dom/client"; import { App } from "./App.tsx"; +import { movedLink } from "./lib/moved-links.ts"; import "./styles.css"; +// Before the first render, so each page reads its new view and tab from the start. +const moved = movedLink(location.search); +if (moved) history.replaceState(history.state, "", `${location.pathname}${moved}${location.hash}`); + createRoot(document.getElementById("root")!).render( diff --git a/packages/contracts/src/index.ts b/packages/contracts/src/index.ts index ec785b0..e8addfa 100644 --- a/packages/contracts/src/index.ts +++ b/packages/contracts/src/index.ts @@ -47,7 +47,7 @@ export interface ProviderInfo { values: Record; secretsSet: string[]; configured: boolean; - /** Added in Setup, so VM Bridge can create VMs on it. */ + /** Added in Accounts, so VM Bridge can create VMs on it. */ added: boolean; /** New VMs go here unless a repository rule picks another provider. */ isDefault: boolean;