Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions apps/server/src/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import type { Hub } from "./gateway/hub.ts";
import { keptIconHeaders, projectIcon } from "./gateway/icons.ts";
import type { T3Gateway } from "./gateway/http.ts";
import { githubName } from "./gateway/repos.ts";
import { isWorking } from "./gateway/types.ts";
import { agentKind, agentName } from "./gateway/agents.ts";
import { isWorking, str } from "./gateway/types.ts";
import { hasScreen, providers } from "./providers/index.ts";
import { envVars, machineName, saveEnvVars, type Secrets, type Settings } from "./settings.ts";
import { InstructionsError, isInstructionName } from "./instructions.ts";
Expand Down Expand Up @@ -674,6 +675,8 @@ export class Admin {
const skills = this.deps.skills.state();
const screenSkills = this.deps.skills.state(true);
const problems = this.deps.traffic.problems();
// What T3 lists for each agent, from the VMs' last reports: its name and its models' names.
const agentReports = new Map(hub.agents().map((report) => [report.instanceId, report]));
const vms = store
.vms()
.filter((vm) => vm.state !== "gone")
Expand All @@ -696,13 +699,18 @@ export class Admin {
sleepsAt: idle ? (vm.lastActivityAt ?? vm.createdAt) + idleMs : null,
projects: projects.filter((project) => project.vms.some((entry) => entry.vmId === vm.id)).map((project) => project.id),
sessions: hub.vmThreads(vm.id).map((thread) => {
const model = thread.modelSelection as { model?: unknown } | undefined;
const selection = thread.modelSelection as { model?: unknown; provider?: unknown } | undefined;
const instance = str(thread.providerInstanceId) ?? str(selection?.provider);
const report = instance ? agentReports.get(instance) : undefined;
const driver = report?.driver ?? instance;
const slug = str(selection?.model) ?? null;
const listed = (report?.models as { slug?: unknown; name?: unknown }[] | undefined)?.find((model) => model.slug === slug);
return {
threadId: thread.id,
title: String(thread.title ?? "Untitled"),
projectId: typeof thread.projectId === "string" ? thread.projectId : null,
model: typeof model?.model === "string" ? model.model : null,
provider: typeof thread.providerInstanceId === "string" ? thread.providerInstanceId : null,
model: str(listed?.name) ?? slug,
agent: driver ? { kind: agentKind(driver), name: report?.displayName ?? agentName(driver) } : null,
status: String(thread.status ?? "idle"),
working: isWorking(thread),
updatedAt: typeof thread.updatedAt === "string" ? thread.updatedAt : null,
Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/gateway/agents.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AgentKind } from "@vmbridge/contracts";
import type { ProviderPreference } from "../settings.ts";
import type { ProviderEntry, Wire } from "./types.ts";

Expand All @@ -6,6 +7,11 @@ const names: Record<string, string> = { codex: "Codex", claudeAgent: "Claude", o
/** An agent's display name from its T3 driver or instance ID. */
export const agentName = (id: string) => names[id] ?? id;

const kinds: Record<string, AgentKind> = { codex: "codex", claudeAgent: "claude", opencode: "opencode" };

/** Which of the agents VM Bridge has a logo for a T3 driver is, if any. */
export const agentKind = (driver: string): AgentKind | null => kinds[driver] ?? null;

/** Agents every VM gets installed, so T3 lists them before any VM has reported. */
export const defaultAgents = ["codex", "claudeAgent"];

Expand Down
49 changes: 49 additions & 0 deletions apps/server/test/sessions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { afterEach, expect, test } from "bun:test";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import type { Overview } from "@vmbridge/contracts";
import { openDatabase } from "../src/bun/sqlite.ts";
import { dashboardKey, databasePath, start } from "../src/index.ts";

const password = "sessions test password";
let cleanup = async () => {};
afterEach(() => cleanup());

test("a VM's sessions name their agent and model as T3 lists them", async () => {
const dir = mkdtempSync(join(tmpdir(), "vmbridge-sessions-"));
const keys = dashboardKey(dir);
await keys.set(password);
keys.close();
const db = openDatabase(databasePath(dir));
db.run("INSERT INTO vms (id, provider, name, size, state, created_at) VALUES ('a1b2c3d4e5f6', 'e2b', 'vm1', 'medium', 'sleeping', 0)");
const config = {
environment: { environmentId: "env1", orchestrationProtocolVersion: 2 },
providers: [
{ instanceId: "claudeAgent", driver: "claudeAgent", enabled: true, models: [{ slug: "claude-opus-5-5", name: "Claude Opus 5.5" }] },
{ instanceId: "codex", driver: "codex", enabled: true, models: [] },
],
};
const thread = (id: string, provider: string, model: string) => ({ id, projectId: null, title: id, status: "idle", providerInstanceId: provider, modelSelection: { provider, model } });
const shell = { snapshotSequence: 1, projects: [], threads: [thread("t1", "claudeAgent", "claude-opus-5-5"), thread("t2", "codex", "gpt-6"), thread("t3", "pi", "pi-1")], archivedThreads: [] };
for (const id of ["t1", "t2", "t3"]) db.run("INSERT INTO threads (id, vm_id) VALUES (?, 'a1b2c3d4e5f6')", id);
db.run("INSERT INTO vm_snapshots (vm_id, config, shell) VALUES ('a1b2c3d4e5f6', ?, ?)", JSON.stringify(config), JSON.stringify(shell));
db.close();

const bridge = await start({ dir, host: "127.0.0.1", port: 0 });
cleanup = async () => {
await bridge.stop();
rmSync(dir, { recursive: true, force: true });
};
const base = `http://127.0.0.1:${bridge.port}`;
const login = await fetch(`${base}/admin/api/login`, { method: "POST", headers: { "content-type": "application/json", origin: base }, body: JSON.stringify({ key: password }) });
const cookie = login.headers.get("set-cookie")!.split(";")[0]!;
const overview = (await (await fetch(`${base}/admin/api/overview`, { headers: { cookie } })).json()) as Overview;

expect(overview.vms[0]!.sessions.map(({ agent, model }) => ({ agent, model }))).toEqual([
{ agent: { kind: "claude", name: "Claude" }, model: "Claude Opus 5.5" },
// A model its agent does not list keeps its ID. An agent VM Bridge has no logo for keeps its name.
{ agent: { kind: "codex", name: "Codex" }, model: "gpt-6" },
{ agent: { kind: null, name: "Pi" }, model: "pi-1" },
]);
});
37 changes: 31 additions & 6 deletions apps/web/src/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from "@xyflow/react";
import { HugeiconsIcon } from "@hugeicons/react";
import { Add01Icon, Alert02Icon, Cancel01Icon, CenterFocusIcon, Delete02Icon, InformationCircleIcon, LaptopIcon, Message01Icon, Moon02Icon, PowerIcon, ZoomInIcon, ZoomOutIcon } from "@hugeicons/core-free-icons";
import { vmSizes, type BridgeUpdate, type ClientInfo, type Overview, type ProjectInfo, type ProviderId, type TrafficEvent, type Usage, type VmInfo, type VmSize, type VmState, type VmStats } from "@vmbridge/contracts";
import { vmSizes, type BridgeUpdate, type ClientInfo, type Overview, type ProjectInfo, type ProviderId, type SessionAgent, type TrafficEvent, type Usage, type VmInfo, type VmSize, type VmState, type VmStats } from "@vmbridge/contracts";
import {
AlertDialog,
AlertDialogAction,
Expand Down Expand Up @@ -54,7 +54,7 @@ import { useAction } from "@/hooks/use-action";
import { sinceText } from "@/lib/devices";
import { cn } from "@/lib/utils";
import { ago, api, useTick } from "./api.ts";
import { Logo, ProjectIcon, ProviderLogo } from "./brand.tsx";
import { AgentLogo, Logo, ProjectIcon, ProviderLogo } from "./brand.tsx";
import { CopyButton } from "./CopyButton.tsx";

/** A connection animates while it carried a request this recently. */
Expand Down Expand Up @@ -223,6 +223,25 @@ function CloudflareUpdate({ version }: { version: string }) {
);
}

/** An agent's logo, or its first letter when VM Bridge has no logo for it. */
function AgentAvatar({ agent, className }: { agent: SessionAgent; className?: string }) {
if (agent.kind) return <AgentLogo agent={agent.kind} bare className={className} />;
return <span className={cn("grid shrink-0 place-items-center text-[11px] font-semibold text-muted-foreground", className)}>{agent.name.slice(0, 1).toUpperCase()}</span>;
}

/** Every agent with a session on a VM, once each, side by side: without tiles, overlapping logos would run together. */
function AgentStack({ agents }: { agents: SessionAgent[] }) {
const unique = [...new Map(agents.map((agent) => [agent.kind ?? agent.name, agent])).values()];
if (!unique.length) return null;
return (
<span className="flex items-center gap-1" title={unique.map((agent) => agent.name).join(", ")}>
{unique.map((agent) => (
<AgentAvatar key={agent.kind ?? agent.name} agent={agent} className="size-4" />
))}
</span>
);
}

function VmCard({ data }: NodeProps<VmNode>) {
const { vm, projects, selected } = data;
const state = vmStates[vm.state];
Expand All @@ -245,9 +264,12 @@ function VmCard({ data }: NodeProps<VmNode>) {
<div className="truncate text-xs text-muted-foreground">{vm.sizeLabel}</div>
</div>
{vm.sessions.length > 0 && (
<span className="flex shrink-0 items-center gap-1.5 self-start text-xs text-muted-foreground" title={`${vm.sessions.length} ${vm.sessions.length === 1 ? "session" : "sessions"}`}>
<HugeiconsIcon icon={Message01Icon} className="size-3.5 text-faint" strokeWidth={1.75} />
{vm.sessions.length}
<span className="flex shrink-0 items-center gap-2.5 self-start text-xs text-muted-foreground">
<AgentStack agents={vm.sessions.flatMap((session) => (session.agent ? [session.agent] : []))} />
<span className="flex items-center gap-1.5" title={`${vm.sessions.length} ${vm.sessions.length === 1 ? "session" : "sessions"}`}>
<HugeiconsIcon icon={Message01Icon} className="size-3.5 text-faint" strokeWidth={1.75} />
{vm.sessions.length}
</span>
</span>
)}
</div>
Expand Down Expand Up @@ -845,7 +867,10 @@ function VmDetails({ vm, overview, now, onClose }: { vm: VmInfo; overview: Overv
<span className="truncate">{session.title}</span>
<Badge variant={session.working ? "default" : "secondary"}>{session.status}</Badge>
</ItemTitle>
<ItemDescription className="font-mono text-xs">{[session.provider, session.model].filter(Boolean).join(" · ") || "No model"}</ItemDescription>
<ItemDescription className="flex min-w-0 items-center gap-1.5 text-xs">
{session.agent && <AgentAvatar agent={session.agent} className="size-4" />}
<span className="truncate">{[session.agent?.name, session.model].filter(Boolean).join(" · ") || "No model"}</span>
</ItemDescription>
</ItemContent>
</Item>
);
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/brand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ const agentLogos: Record<AgentKind, { src: string; tile: string; inset: string }
opencode: { src: opencode, tile: "bg-black", inset: "" },
};

export function AgentLogo({ agent, className }: { agent: AgentKind; className?: string }) {
/** An agent's logo on its tile. `bare` drops the tile, for small logos beside text. */
export function AgentLogo({ agent, className, bare = false }: { agent: AgentKind; className?: string; bare?: boolean }) {
const logo = agentLogos[agent];
if (bare) return <img src={logo.src} alt="" className={cn("size-6 shrink-0 object-contain", className)} draggable={false} />;
return (
<span className={cn("grid size-6 shrink-0 place-items-center overflow-hidden rounded-md ring-1 ring-white/10", logo.tile, className)}>
<img src={logo.src} alt="" className={cn("size-full object-contain", logo.inset)} draggable={false} />
Expand Down
9 changes: 8 additions & 1 deletion packages/contracts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,19 @@ export interface ClientInfo {

export type VmState = "provisioning" | "starting" | "ready" | "busy" | "sleeping" | "error" | "gone";

/** The agent running a session: the name T3 shows, and which logo it has, when VM Bridge knows it. */
export interface SessionAgent {
kind: AgentKind | null;
name: string;
}

export interface VmSession {
threadId: string;
title: string;
projectId: string | null;
/** The model's name as its agent lists it, such as "Claude Opus 5.5", or its ID when the agent does not list it. */
model: string | null;
provider: string | null;
agent: SessionAgent | null;
status: string;
/** A turn is running, queued, or waiting on an approval. */
working: boolean;
Expand Down