Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

feat(web): add Bifrost readiness and one-click Agent switching

Dongdong Chen66201aa63363
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 26fb3d87..f126140c 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -39,9 +39,14 @@ build:assets` to check the initial JS budget.
loaded row, renders tinted family
icon tiles, Agent usage counts, structured capability/parameter badges (never
matched against `name` or `description`), state-distinct cards (`loaded`,
- `recommended`, `failed`, `unavailable`), download speed/ETA, and top
+ `recommended`, `failed`, `unavailable`), download speed/ETA, live Bifrost
+ (`Pi`) `Gateway` readiness, and top
diagnostic callouts with a two-column model-card facts grid from structured
- `LocalModel` fields in `local-models-rules.ts`, and maps every code and enum
+ `LocalModel` fields in `local-models-rules.ts`, resolves Sponsor-owned Agent
+ eligibility and `Pi` runtime switch payloads in `local-model-agents.ts`
+ (`Use with <Another Me>`, `Open chat`, `Switch Agent…` in `Used by`, and
+ `Make room` automatic Agent handoff once the replacement model loads when `Pi`
+ is ready), and maps every code and enum
label to English in `local-models-copy.ts`. Without `?computer=`
the desktop app opens
its own Computer. Only the Computer's owner can act; actions return at once
diff --git a/apps/web/src/features/local-models/local-model-agents.test.ts b/apps/web/src/features/local-models/local-model-agents.test.ts
new file mode 100644
index 00000000..c8c3dd28
--- /dev/null
+++ b/apps/web/src/features/local-models/local-model-agents.test.ts
@@ -0,0 +1,264 @@
+import { describe, expect, it } from "vitest";
+
+import type { TeamHubLocalComputerPage } from "@/features/teamhub/teamhub-types";
+import { createTeamHubTestSeed } from "@/test/teamhub-seed";
+
+import {
+ assignableLocalModelAgents,
+ buildLocalModelRuntimeUpdate,
+ isAgentUsingModel,
+ primaryLocalModelAgent,
+ usedByAgentNames,
+} from "./local-model-agents";
+import { localModel } from "./local-models-test-support";
+
+describe("local-model-agents", () => {
+ it("filters to Sponsor-owned Agents, places Another Me first, and keeps compatible workspace grants", () => {
+ const seed = createTeamHubTestSeed();
+ const computer = {
+ ...seed.localComputers[0]!,
+ computer_id: "computer-lab",
+ workspace_grants: [
+ {
+ grant_id: "grant-ro",
+ label: "Read only",
+ mode: "read-only" as const,
+ },
+ {
+ grant_id: "grant-rw",
+ label: "Workspace",
+ mode: "workspace-write" as const,
+ },
+ {
+ grant_id: "grant-other",
+ label: "Other workspace",
+ mode: "workspace-write" as const,
+ },
+ ],
+ };
+ const [codex, lev8, delegate] = seed.tenantAgents;
+ const codexOnLab = {
+ ...codex!,
+ runtime: {
+ ...codex!.runtime,
+ placement: {
+ computer_id: "computer-lab",
+ runtime_type: "codex" as const,
+ type: "local" as const,
+ workspace_grant_id: "grant-other",
+ },
+ },
+ };
+ const result = assignableLocalModelAgents({
+ agents: [codexOnLab, lev8!, delegate!],
+ anotherMeActorId: delegate!.actor.id,
+ availability: [
+ {
+ actor_id: codexOnLab.actor.id,
+ availability: {
+ active_task_count: 1,
+ label: "Busy",
+ status: "online",
+ },
+ },
+ ],
+ computer,
+ computerId: "computer-lab",
+ currentActorId: seed.identity.actors[0]!.id,
+ });
+
+ // Lev8 GTM is sponsored by Maya, not Jenny.
+ expect(result.map((agent) => agent.actorId)).toEqual([
+ delegate!.actor.id,
+ codexOnLab.actor.id,
+ ]);
+ expect(result[0]!).toMatchObject({
+ busy: false,
+ grantId: "grant-rw",
+ isAnotherMe: true,
+ name: "Jenny's Delegate",
+ });
+ expect(result[1]!).toMatchObject({
+ busy: true,
+ grantId: "grant-other",
+ isAnotherMe: false,
+ name: "Codex",
+ });
+ expect(primaryLocalModelAgent(result)?.actorId).toBe(delegate!.actor.id);
+ });
+
+ it("excludes all Agents on an upgrade-required or read-only Computer", () => {
+ const seed = createTeamHubTestSeed();
+ const upgradeComputer = {
+ ...seed.localComputers[0]!,
+ computer_id: "computer-lab",
+ upgrade_required: true,
+ };
+ expect(
+ assignableLocalModelAgents({
+ agents: seed.tenantAgents,
+ anotherMeActorId: seed.tenantAgents[2]!.actor.id,
+ computer: upgradeComputer,
+ computerId: "computer-lab",
+ currentActorId: seed.identity.actors[0]!.id,
+ }),
+ ).toEqual([]);
+
+ const readOnlyComputer = {
+ ...seed.localComputers[0]!,
+ computer_id: "computer-lab",
+ workspace_grants: [
+ {
+ grant_id: "grant-ro",
+ label: "Read only",
+ mode: "read-only" as const,
+ },
+ ],
+ };
+ expect(
+ assignableLocalModelAgents({
+ agents: seed.tenantAgents,
+ anotherMeActorId: seed.tenantAgents[2]!.actor.id,
+ computer: readOnlyComputer,
+ computerId: "computer-lab",
+ currentActorId: seed.identity.actors[0]!.id,
+ }),
+ ).toEqual([]);
+ });
+
+ it("matches Agents via either snapshot used_by or live Pi placement", () => {
+ const seed = createTeamHubTestSeed();
+ const delegate = {
+ ...seed.tenantAgents[2]!,
+ runtime: {
+ model: "localmodels-library/qwen3-coder-30b",
+ placement: {
+ computer_id: "computer-lab",
+ runtime_type: "pi" as const,
+ type: "local" as const,
+ workspace_grant_id: "grant-rw",
+ },
+ },
+ };
+ const [agent] = assignableLocalModelAgents({
+ agents: [delegate],
+ anotherMeActorId: delegate.actor.id,
+ computerId: "computer-lab",
+ currentActorId: seed.identity.actors[0]!.id,
+ });
+ const entry = {
+ model: localModel({
+ id: "qwen3-coder-30b:Q4_K_M",
+ name: "Qwen3 Coder 30B",
+ pi_model: "localmodels-library/qwen3-coder-30b",
+ state: "loaded",
+ }),
+ status: "loaded" as const,
+ used_by: [{ agent_id: "agent-research", name: "Research agent" }],
+ };
+
+ expect(isAgentUsingModel(entry, agent!, "computer-lab")).toBe(true);
+ expect(isAgentUsingModel(entry, agent!, "computer-other")).toBe(false);
+ expect(usedByAgentNames(entry, [agent!], "computer-lab")).toEqual([
+ "Research agent",
+ "Jenny's Delegate",
+ ]);
+ });
+
+ it("omits incompatible Claude reasoning efforts when Pi has not listed the model yet, and preserves valid Pi efforts when listed", () => {
+ const seed = createTeamHubTestSeed();
+ const computerWithoutPiModel = {
+ ...seed.localComputers[0]!,
+ computer_id: "computer-lab",
+ runtimes: [],
+ };
+ const baseAgent = {
+ actorId: "actor-delegate",
+ busy: false,
+ configurationRevision: 3,
+ currentComputerId: "computer-lab",
+ currentModel: "claude-opus-4-1",
+ currentReasoningEffort: "ultra" as const,
+ currentRuntimeType: "claude" as const,
+ grantId: "grant-rw",
+ isAnotherMe: true,
+ name: "Jenny's Delegate",
+ };
+
+ expect(
+ buildLocalModelRuntimeUpdate(
+ baseAgent,
+ "localmodels-library/qwen3-coder-30b",
+ "computer-lab",
+ computerWithoutPiModel,
+ ),
+ ).toEqual({
+ model: "localmodels-library/qwen3-coder-30b",
+ placement: {
+ computer_id: "computer-lab",
+ runtime_type: "pi",
+ type: "local",
+ workspace_grant_id: "grant-rw",
+ },
+ });
+
+ const computerWithPiModel: TeamHubLocalComputerPage["items"][number] = {
+ ...seed.localComputers[0]!,
+ computer_id: "computer-lab",
+ runtimes: [
+ {
+ models: [
+ {
+ allowed_reasoning_effort: ["low", "medium", "high"],
+ default_reasoning_effort: "medium",
+ id: "localmodels-library/qwen3-coder-30b",
+ label: "Qwen3 Coder 30B",
+ },
+ ],
+ status: "ready",
+ type: "pi",
+ },
+ ],
+ };
+
+ expect(
+ buildLocalModelRuntimeUpdate(
+ baseAgent,
+ "localmodels-library/qwen3-coder-30b",
+ "computer-lab",
+ computerWithPiModel,
+ ),
+ ).toEqual({
+ model: "localmodels-library/qwen3-coder-30b",
+ placement: {
+ computer_id: "computer-lab",
+ runtime_type: "pi",
+ type: "local",
+ workspace_grant_id: "grant-rw",
+ },
+ reasoning_effort: "medium",
+ });
+
+ expect(
+ buildLocalModelRuntimeUpdate(
+ {
+ ...baseAgent,
+ currentReasoningEffort: "high",
+ currentRuntimeType: "pi",
+ },
+ "localmodels-library/qwen3-coder-30b",
+ "computer-lab",
+ computerWithPiModel,
+ ),
+ ).toEqual({
+ model: "localmodels-library/qwen3-coder-30b",
+ placement: {
+ computer_id: "computer-lab",
+ runtime_type: "pi",
+ type: "local",
+ workspace_grant_id: "grant-rw",
+ },
+ reasoning_effort: "high",
+ });
+ });
+});
diff --git a/apps/web/src/features/local-models/local-model-agents.ts b/apps/web/src/features/local-models/local-model-agents.ts
new file mode 100644
index 00000000..e1418492
--- /dev/null
+++ b/apps/web/src/features/local-models/local-model-agents.ts
@@ -0,0 +1,190 @@
+import type {
+ TeamHubAgentReasoningEffort,
+ TeamHubLocalComputerPage,
+ TeamHubLocalRuntimeType,
+ TeamHubTenantAgent,
+ TeamHubTenantAgentAvailabilitySnapshot,
+ TeamHubTenantAgentUpdateInput,
+} from "@/features/teamhub/teamhub-types";
+
+import type { ModelEntry } from "./local-models-rules";
+
+/** A Sponsor-owned Agent eligible to run against a loaded Local Model on one Computer. */
+export interface AssignableLocalModelAgent {
+ actorId: string;
+ busy: boolean;
+ configurationRevision: number;
+ currentComputerId?: string;
+ currentModel: string;
+ currentReasoningEffort?: TeamHubAgentReasoningEffort;
+ currentRuntimeType?: TeamHubLocalRuntimeType;
+ grantId: string;
+ isAnotherMe: boolean;
+ name: string;
+}
+
+export interface AssignableLocalModelAgentsInput {
+ agents?: readonly TeamHubTenantAgent[];
+ anotherMeActorId?: string;
+ availability?: readonly TeamHubTenantAgentAvailabilitySnapshot[];
+ computer?: TeamHubLocalComputerPage["items"][number];
+ computerId: string;
+ currentActorId?: string;
+}
+
+/**
+ * Lists Sponsor-owned Agents that can run on `computerId` with the Pi Runtime,
+ * placing Another Me first so row actions prioritize it consistently.
+ */
+export function assignableLocalModelAgents(
+ input: AssignableLocalModelAgentsInput,
+): AssignableLocalModelAgent[] {
+ if (
+ !input.currentActorId ||
+ !input.agents?.length ||
+ input.computer?.upgrade_required
+ ) {
+ return [];
+ }
+ const busyByActorId = new Map(
+ (input.availability ?? []).map((snapshot) => [
+ snapshot.actor_id,
+ (snapshot.availability.active_task_count ?? 0) > 0,
+ ]),
+ );
+ const writableGrant = input.computer?.workspace_grants.find(
+ (grant) => grant.mode === "workspace-write",
+ );
+ const result: AssignableLocalModelAgent[] = [];
+ for (const agent of input.agents) {
+ if (agent.created_by.id !== input.currentActorId) continue;
+ const placement =
+ agent.runtime.placement?.type === "local"
+ ? agent.runtime.placement
+ : undefined;
+ let grantId: string | undefined;
+ if (placement?.computer_id === input.computerId) {
+ const existingGrantId = placement.workspace_grant_id;
+ const grantStillPresent =
+ !input.computer ||
+ input.computer.workspace_grants.some(
+ (grant) => grant.grant_id === existingGrantId,
+ );
+ grantId = grantStillPresent ? existingGrantId : writableGrant?.grant_id;
+ } else {
+ grantId = writableGrant?.grant_id;
+ }
+ if (!grantId) continue;
+ result.push({
+ actorId: agent.actor.id,
+ busy: busyByActorId.get(agent.actor.id) ?? false,
+ configurationRevision: agent.configuration_revision,
+ currentComputerId: placement?.computer_id,
+ currentModel: agent.runtime.model,
+ currentReasoningEffort: agent.runtime.reasoning_effort,
+ currentRuntimeType: placement?.runtime_type,
+ grantId,
+ isAnotherMe:
+ agent.actor.id === input.anotherMeActorId ||
+ agent.agent_type === "anotherme",
+ name: agent.actor.display_name,
+ });
+ }
+ result.sort((a, b) => {
+ if (a.isAnotherMe !== b.isAnotherMe) return a.isAnotherMe ? -1 : 1;
+ return a.name.localeCompare(b.name);
+ });
+ return result;
+}
+
+/**
+ * Whether `agent` already uses `entry` on `computerId`, combining the snapshot's
+ * `used_by` list with live Agent placement so updates reflect before the next snapshot.
+ */
+export function isAgentUsingModel(
+ entry: ModelEntry,
+ agent: AssignableLocalModelAgent,
+ computerId: string,
+): boolean {
+ if (entry.used_by.some((user) => user.agent_id === agent.actorId)) {
+ return true;
+ }
+ return (
+ Boolean(entry.model.pi_model) &&
+ agent.currentComputerId === computerId &&
+ agent.currentRuntimeType === "pi" &&
+ agent.currentModel === entry.model.pi_model
+ );
+}
+
+/** Display names of all Agents currently using `entry` on `computerId`. */
+export function usedByAgentNames(
+ entry: ModelEntry,
+ assignableAgents: readonly AssignableLocalModelAgent[],
+ computerId: string,
+): string[] {
+ const names = entry.used_by.map((user) => user.name);
+ for (const agent of assignableAgents) {
+ if (
+ isAgentUsingModel(entry, agent, computerId) &&
+ !entry.used_by.some(
+ (user) => user.agent_id === agent.actorId || user.name === agent.name,
+ )
+ ) {
+ names.push(agent.name);
+ }
+ }
+ return names;
+}
+
+/** The featured Agent for one-click row actions: Another Me, or the sole Agent. */
+export function primaryLocalModelAgent(
+ assignableAgents: readonly AssignableLocalModelAgent[],
+): AssignableLocalModelAgent | undefined {
+ return (
+ assignableAgents.find((agent) => agent.isAnotherMe) ??
+ (assignableAgents.length === 1 ? assignableAgents[0] : undefined)
+ );
+}
+
+/**
+ * Builds the `PATCH /agents/{agentId}` runtime payload that switches `agent` onto
+ * a Bifrost-backed local model via Pi without carrying incompatible effort settings.
+ */
+export function buildLocalModelRuntimeUpdate(
+ agent: AssignableLocalModelAgent,
+ piModel: string,
+ computerId: string,
+ computer?: TeamHubLocalComputerPage["items"][number],
+): NonNullable<TeamHubTenantAgentUpdateInput["runtime"]> {
+ const piRuntime = computer?.runtimes.find((item) => item.type === "pi");
+ const catalogModel = piRuntime?.models.find((item) => item.id === piModel);
+ let reasoningEffort: TeamHubAgentReasoningEffort | undefined;
+ if (catalogModel) {
+ const allowed = catalogModel.allowed_reasoning_effort ?? [];
+ if (
+ agent.currentRuntimeType === "pi" &&
+ agent.currentReasoningEffort &&
+ allowed.includes(agent.currentReasoningEffort)
+ ) {
+ reasoningEffort = agent.currentReasoningEffort;
+ } else if (
+ catalogModel.default_reasoning_effort &&
+ allowed.includes(catalogModel.default_reasoning_effort)
+ ) {
+ reasoningEffort = catalogModel.default_reasoning_effort;
+ } else {
+ reasoningEffort = allowed[0];
+ }
+ }
+ return {
+ model: piModel,
+ ...(reasoningEffort ? { reasoning_effort: reasoningEffort } : {}),
+ placement: {
+ computer_id: computerId,
+ runtime_type: "pi",
+ type: "local",
+ workspace_grant_id: agent.grantId,
+ },
+ };
+}
diff --git a/apps/web/src/features/local-models/local-model-details.tsx b/apps/web/src/features/local-models/local-model-details.tsx
index e74b9d88..d89b4b33 100644
--- a/apps/web/src/features/local-models/local-model-details.tsx
+++ b/apps/web/src/features/local-models/local-model-details.tsx
@@ -9,8 +9,16 @@ import { Button } from "@/components/ui/button";
import { FormFeedback } from "@/components/ui/form-feedback";
import { Icon } from "@/components/ui/icon";
import { ModalDialog } from "@/components/ui/modal-dialog";
+import { Select, SelectItem } from "@/components/ui/select";
+import type { TeamHubLocalComputerPage } from "@/features/teamhub/teamhub-types";
import { cn } from "@/lib/cn";
+import {
+ type AssignableLocalModelAgent,
+ isAgentUsingModel,
+ primaryLocalModelAgent,
+ usedByAgentNames,
+} from "./local-model-agents";
import {
capabilityCopy,
modelErrorCopy,
@@ -19,7 +27,6 @@ import {
} from "./local-models-copy";
import type { LocalModelPool, LocalModelsView } from "./local-models-queries";
import {
- agentNames,
contextLabel,
downloadStopped,
formatGigabytes,
@@ -91,12 +98,56 @@ function CopyEndpoint({ endpoint, name }: { endpoint: string; name: string }) {
);
}
+function gatewayFactValue(
+ entry: ModelEntry,
+ view: LocalModelsView,
+ computer?: TeamHubLocalComputerPage["items"][number],
+): ReactNode {
+ if (!computer || !entry.model.pi_model) return "Bifrost";
+ const piRuntime = computer.runtimes.find((runtime) => runtime.type === "pi");
+ if (!piRuntime) {
+ return (
+ <span className="text-muted-foreground">Bifrost · Pi not installed</span>
+ );
+ }
+ if (piRuntime.status === "ready") {
+ if (piRuntime.models.some((item) => item.id === entry.model.pi_model)) {
+ return "Ready · Bifrost (Pi)";
+ }
+ return (
+ <span className="text-muted-foreground">
+ Bifrost · Registering with Pi…
+ </span>
+ );
+ }
+ if (piRuntime.status === "not_installed") {
+ return (
+ <span className="text-muted-foreground">
+ {view.computer.status === "online"
+ ? "Bifrost · Setting up Pi…"
+ : "Bifrost · Pi not installed"}
+ </span>
+ );
+ }
+ return <span className="text-app-warning">Bifrost · Pi unavailable</span>;
+}
+
/** Everything about one model on one Computer, shown when its row expands. */
export function ModelFacts({
+ assignableAgents = [],
+ assigningAgentId,
+ computer,
+ disabled = false,
entry,
+ onAssignAgent,
view,
}: {
+ assignableAgents?: readonly AssignableLocalModelAgent[];
+ assigningAgentId?: string;
+ computer?: TeamHubLocalComputerPage["items"][number];
+ disabled?: boolean;
entry: ModelEntry;
+ onAssignAgent?: (agent: AssignableLocalModelAgent) => void;
view: LocalModelsView;
}) {
const { model, status } = entry;
@@ -117,6 +168,24 @@ export function ModelFacts({
pool !== undefined &&
poolOtherBytes(pool) > 0 &&
poolFreeBytes(pool) < model.memory_bytes;
+ const computerId = view.computer.computer_id;
+ const usedNames = usedByAgentNames(entry, assignableAgents, computerId);
+ const unassigned = assignableAgents.filter(
+ (agent) => !isAgentUsingModel(entry, agent, computerId),
+ );
+ const primaryAgent = primaryLocalModelAgent(assignableAgents);
+ const showAgentPicker =
+ status === "loaded" &&
+ Boolean(model.pi_model) &&
+ Boolean(onAssignAgent) &&
+ (unassigned.some((agent) => !agent.isAnotherMe) || unassigned.length > 1);
+ const primaryBusy =
+ status === "loaded" &&
+ Boolean(model.pi_model) &&
+ Boolean(onAssignAgent) &&
+ primaryAgent !== undefined &&
+ !isAgentUsingModel(entry, primaryAgent, computerId) &&
+ primaryAgent.busy;
return (
<div>
{model.error || status === "unavailable" ? (
@@ -199,10 +268,47 @@ export function ModelFacts({
{model.license ? <Fact label="License">{model.license}</Fact> : null}
{onComputer ? (
<Fact
- className={entry.used_by.length > 1 ? "@xl:col-span-2" : undefined}
+ className={
+ usedNames.length > 1 || showAgentPicker || primaryBusy
+ ? "@xl:col-span-2"
+ : undefined
+ }
label="Used by"
>
- {entry.used_by.length ? agentNames(entry) : "No Agent yet"}
+ <span className="flex flex-wrap items-center gap-2">
+ <span>
+ {usedNames.length ? usedNames.join(", ") : "No Agent yet"}
+ </span>
+ {showAgentPicker && onAssignAgent ? (
+ <Select
+ aria-label={`Switch an Agent to ${model.name}`}
+ disabled={disabled || Boolean(assigningAgentId)}
+ onValueChange={(actorId) => {
+ const target = unassigned.find(
+ (agent) => agent.actorId === actorId,
+ );
+ if (target) onAssignAgent(target);
+ }}
+ placeholder="Switch Agent…"
+ value=""
+ variant="pill"
+ >
+ {unassigned.map((agent) => (
+ <SelectItem
+ disabled={agent.busy}
+ key={agent.actorId}
+ value={agent.actorId}
+ >
+ {agent.busy ? `${agent.name} · Working` : agent.name}
+ </SelectItem>
+ ))}
+ </Select>
+ ) : primaryBusy ? (
+ <span className="text-xs text-muted-foreground">
+ Finish the current turn to switch
+ </span>
+ ) : null}
+ </span>
</Fact>
) : null}
{sourceUrl ? (
@@ -218,6 +324,11 @@ export function ModelFacts({
</a>
</Fact>
) : null}
+ {status === "loaded" && model.endpoint ? (
+ <Fact className="@xl:col-span-2" label="Gateway">
+ {gatewayFactValue(entry, view, computer)}
+ </Fact>
+ ) : null}
{model.endpoint ? (
<Fact className="@xl:col-span-2" label="Endpoint">
<CopyEndpoint
diff --git a/apps/web/src/features/local-models/local-model-dialogs.tsx b/apps/web/src/features/local-models/local-model-dialogs.tsx
index eee661e3..166c9f18 100644
--- a/apps/web/src/features/local-models/local-model-dialogs.tsx
+++ b/apps/web/src/features/local-models/local-model-dialogs.tsx
@@ -6,6 +6,10 @@ import { ModalDialog } from "@/components/ui/modal-dialog";
import { sourceCheckClassName } from "@/features/settings/provider-selection-picker";
import { cn } from "@/lib/cn";
+import {
+ type AssignableLocalModelAgent,
+ isAgentUsingModel,
+} from "./local-model-agents";
import type { LocalModelsView } from "./local-models-queries";
import {
agentNames,
@@ -41,6 +45,7 @@ function AffectedAgents({
/** Loading would overfill the pool: offer to unload loaded models or recheck memory. */
export function MakeRoomDialog({
+ assignableAgents = [],
check,
disabled,
entry,
@@ -50,17 +55,19 @@ export function MakeRoomDialog({
rechecking = false,
view,
}: {
+ assignableAgents?: readonly AssignableLocalModelAgent[];
check: LoadCheck;
/** The model can no longer be loaded, or its Computer took no actions. */
disabled: boolean;
entry: ModelEntry;
onClose: () => void;
- onConfirm: (unloadIds: string[]) => void;
+ onConfirm: (unloadIds: string[], switchAgentIds: string[]) => void;
onRecheck?: () => void;
rechecking?: boolean;
view: LocalModelsView;
}) {
const [selected, setSelected] = useState(() => makeRoomSelection(check));
+ const [switchAgents, setSwitchAgents] = useState(true);
const roomFreeNow = check.freeBytes >= check.needBytes;
const effectiveSelected = roomFreeNow ? [] : selected;
const chosen = new Set(effectiveSelected);
@@ -81,9 +88,19 @@ export function MakeRoomDialog({
...(otherBytes ? [{ bytes: otherBytes, id: "", name: "Other apps" }] : []),
...check.kept,
];
- const affected = check.loaded.flatMap((item) =>
- chosen.has(item.model.id) ? item.used_by.map((user) => user.name) : [],
+ const chosenLoaded = check.loaded.filter((item) => chosen.has(item.model.id));
+ const affected = chosenLoaded.flatMap((item) =>
+ item.used_by.map((user) => user.name),
+ );
+ const affectedAssignable = assignableAgents.filter(
+ (agent) =>
+ !agent.busy &&
+ chosenLoaded.some((item) =>
+ isAgentUsingModel(item, agent, view.computer.computer_id),
+ ),
);
+ const canSwitchOnLoad =
+ Boolean(entry.model.pi_model) && affectedAssignable.length > 0;
return (
<ModalDialog
@@ -102,7 +119,14 @@ export function MakeRoomDialog({
<Button onClick={onClose}>Cancel</Button>
<Button
disabled={disabled || !enough}
- onClick={() => onConfirm(effectiveSelected)}
+ onClick={() =>
+ onConfirm(
+ effectiveSelected,
+ canSwitchOnLoad && switchAgents
+ ? affectedAssignable.map((agent) => agent.actorId)
+ : [],
+ )
+ }
tone="primary"
>
{effectiveSelected.length ? "Unload and load" : "Load"}
@@ -206,6 +230,20 @@ export function MakeRoomDialog({
again.
</FormFeedback>
) : null}
+ {canSwitchOnLoad ? (
+ <label className="flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm text-app-ink">
+ <input
+ checked={switchAgents}
+ className={sourceCheckClassName}
+ onChange={(event) => setSwitchAgents(event.target.checked)}
+ type="checkbox"
+ />
+ <span>
+ Switch {affectedAssignable.map((agent) => agent.name).join(", ")}{" "}
+ to {entry.model.name} once loaded
+ </span>
+ </label>
+ ) : null}
</div>
</ModalDialog>
);
diff --git a/apps/web/src/features/local-models/local-model-row.tsx b/apps/web/src/features/local-models/local-model-row.tsx
index fca89c33..b6f06473 100644
--- a/apps/web/src/features/local-models/local-model-row.tsx
+++ b/apps/web/src/features/local-models/local-model-row.tsx
@@ -13,11 +13,19 @@ import {
QwenIcon,
} from "@hugeicons/core-free-icons";
import { useId, type MouseEvent } from "react";
+import { Link } from "react-router";
-import { Button } from "@/components/ui/button";
+import { Button, buttonClassName } from "@/components/ui/button";
import { Icon, type IconSvgElement } from "@/components/ui/icon";
+import type { TeamHubLocalComputerPage } from "@/features/teamhub/teamhub-types";
import { cn } from "@/lib/cn";
+import {
+ type AssignableLocalModelAgent,
+ isAgentUsingModel,
+ primaryLocalModelAgent,
+ usedByAgentNames,
+} from "./local-model-agents";
import { ModelFacts } from "./local-model-details";
import { unavailableShortCopy } from "./local-models-copy";
import type {
@@ -26,7 +34,6 @@ import type {
LocalModelsView,
} from "./local-models-queries";
import {
- agentNames,
collapsedRowBadges,
downloadPercent,
downloadStatusDetail,
@@ -166,6 +173,28 @@ function stopRowClick(event: MouseEvent) {
event.stopPropagation();
}
+function OpenChatLink({
+ href,
+ onClick,
+}: {
+ href: string;
+ onClick: (event: MouseEvent) => void;
+}) {
+ return (
+ <Link
+ className={buttonClassName({
+ className: "px-2.5",
+ size: "compact",
+ tone: "ghost",
+ })}
+ onClick={onClick}
+ to={href}
+ >
+ Open chat
+ </Link>
+ );
+}
+
function RowStatusLine({
detail,
download,
@@ -232,16 +261,16 @@ function RowStatusLine({
function RowMetadataPills({
badges,
- entry,
overflowTitle,
status,
usedBy,
+ usedByTitle,
}: {
badges: string[];
- entry: ModelEntry;
overflowTitle?: string;
status: ModelStatus;
usedBy?: string;
+ usedByTitle?: string;
}) {
return (
<div
@@ -258,7 +287,7 @@ function RowMetadataPills({
? "bg-[var(--app-status-success-surface)] text-app-success"
: "bg-muted text-secondary-foreground",
)}
- title={`Used by ${agentNames(entry)}`}
+ title={usedByTitle}
>
{usedBy}
</span>
@@ -311,18 +340,28 @@ function DownloadProgress({
* header carries the status and one action, and which expands to the details.
*/
export function ModelRow({
+ anotherMeChatHref,
+ assignableAgents = [],
+ assigningAgentId,
+ computer,
disabled,
entry,
expanded,
+ onAssignAgent,
requested,
switchingForAgents = false,
view,
...handlers
}: Handlers & {
+ anotherMeChatHref?: string;
+ assignableAgents?: readonly AssignableLocalModelAgent[];
+ assigningAgentId?: string;
+ computer?: TeamHubLocalComputerPage["items"][number];
/** Actions are off: the Computer is offline, the viewer only reads, or one is pending. */
disabled: boolean;
entry: ModelEntry;
expanded: boolean;
+ onAssignAgent?: (agent: AssignableLocalModelAgent) => void;
/** An action asked for and not yet in a snapshot. */
requested?: LocalModelAction;
switchingForAgents?: boolean;
@@ -359,7 +398,21 @@ export function ModelRow({
const slower =
status === "available" && !model.recommended && model.fit === "system";
const brand = familyBrand(model.family);
- const usedBy = usedByBadge(entry);
+ const computerId = view.computer.computer_id;
+ const usedNames = usedByAgentNames(entry, assignableAgents, computerId);
+ const usedBy = usedByBadge({ ...entry, status }, usedNames);
+ const usedByTitle = usedNames.length
+ ? `Used by ${usedNames.join(", ")}`
+ : undefined;
+ const primaryAgent = primaryLocalModelAgent(assignableAgents);
+ const primaryUsing = primaryAgent
+ ? isAgentUsingModel(entry, primaryAgent, computerId)
+ : false;
+ const canUsePrimary =
+ status === "loaded" &&
+ Boolean(model.pi_model) &&
+ Boolean(primaryAgent) &&
+ Boolean(onAssignAgent);
const { badges, overflowTitle } = collapsedRowBadges(model);
const hasMeta = Boolean(usedBy) || badges.length > 0;
const detail = {
@@ -450,10 +503,10 @@ export function ModelRow({
{hasMeta ? (
<RowMetadataPills
badges={badges}
- entry={entry}
overflowTitle={overflowTitle}
status={status}
usedBy={usedBy}
+ usedByTitle={usedByTitle}
/>
) : null}
<div
@@ -477,6 +530,37 @@ export function ModelRow({
>
Use for Agents
</Button>
+ ) : canUsePrimary &&
+ primaryAgent &&
+ !primaryUsing &&
+ onAssignAgent ? (
+ <Button
+ aria-label={`Use ${model.name} with ${primaryAgent.name}`}
+ className="px-2.5"
+ disabled={
+ disabled || primaryAgent.busy || Boolean(assigningAgentId)
+ }
+ loading={assigningAgentId === primaryAgent.actorId}
+ onClick={(event) => {
+ stopRowClick(event);
+ onAssignAgent(primaryAgent);
+ }}
+ size="compact"
+ title={
+ primaryAgent.busy
+ ? `Wait for ${primaryAgent.name} to finish the current turn`
+ : undefined
+ }
+ tone="primary"
+ >
+ Use with {primaryAgent.name}
+ </Button>
+ ) : !handlers.onUseForAgents &&
+ canUsePrimary &&
+ primaryAgent?.isAnotherMe &&
+ primaryUsing &&
+ anotherMeChatHref ? (
+ <OpenChatLink href={anotherMeChatHref} onClick={stopRowClick} />
) : null}
{action ? (
<Button
@@ -534,7 +618,15 @@ export function ModelRow({
{model.description}
</p>
) : null}
- <ModelFacts entry={entry} view={view} />
+ <ModelFacts
+ assignableAgents={assignableAgents}
+ assigningAgentId={assigningAgentId}
+ computer={computer}
+ disabled={disabled}
+ entry={entry}
+ onAssignAgent={onAssignAgent}
+ view={view}
+ />
{removable || stopped ? (
<div className="mt-2 border-t border-border/70 pt-2.5">
{removable ? (
diff --git a/apps/web/src/features/local-models/local-models-page.test.tsx b/apps/web/src/features/local-models/local-models-page.test.tsx
index 2fe0e3de..c254351c 100644
--- a/apps/web/src/features/local-models/local-models-page.test.tsx
+++ b/apps/web/src/features/local-models/local-models-page.test.tsx
@@ -15,6 +15,7 @@ import { TeamHubEventSync } from "@/features/rooms/event-sync";
import { TeamHubRuntimeProvider } from "@/features/teamhub/teamhub-runtime";
import type { TeamHubLocalComputerPage } from "@/features/teamhub/teamhub-types";
import {
+ acceptTenantAgentUpdates,
createTestTeamHubRuntime,
type TestTeamHubRuntime,
} from "@/test/teamhub-test-runtime";
@@ -156,6 +157,10 @@ async function renderPage(fixture: Fixture, search = "") {
element={<p>Computers page</p>}
path="/t/:tenantId/settings/computers"
/>
+ <Route
+ element={<p>Another Me room</p>}
+ path="/t/:tenantId/rooms/:roomId/chat"
+ />
</Routes>
</Suspense>
</MemoryRouter>
@@ -231,6 +236,20 @@ function accepted(action: string) {
);
}
+function enableReadyPi(fixture: Fixture) {
+ for (const computer of fixture.runtime.seed.localComputers) {
+ computer.runtimes = [
+ ...computer.runtimes.filter((runtime) => runtime.type !== "pi"),
+ {
+ models: [],
+ status: "ready",
+ type: "pi",
+ version: "1.3.0",
+ },
+ ];
+ }
+}
+
function withModel(
view: LocalModelsView,
modelId: string,
@@ -1443,6 +1462,400 @@ describe("LocalModelsPage", () => {
"GPT-OSS 20B: Downloading · 25% · 50 MB/s · 5m left",
);
});
+
+ it("shows Bifrost gateway readiness above Endpoint on an expanded loaded model", async () => {
+ const view = labView();
+ const computer = {
+ ...inventoryComputer(view),
+ runtimes: [
+ ...inventoryComputer(view).runtimes,
+ {
+ models: [
+ {
+ id: "localmodels-library/qwen3-coder-30b",
+ label: "Qwen3 Coder 30B",
+ },
+ ],
+ status: "ready" as const,
+ type: "pi" as const,
+ version: "1.3.0",
+ },
+ ],
+ };
+ await renderPage(setup([view], [computer]));
+ await findModels();
+
+ fireEvent.click(screen.getByRole("button", { name: "Qwen3 Coder 30B" }));
+ const details = screen.getByRole("region", {
+ name: "Qwen3 Coder 30B details",
+ });
+ expect(details).toHaveTextContent("GatewayReady · Bifrost (Pi)");
+ expect(details).toHaveTextContent("Endpointhttp://127.0.0.1:18100/v1");
+ });
+
+ it("reflects Pi runtime setup, catalog registration, and failure states in the Gateway row", async () => {
+ const fixture = setup([labView()]);
+ await renderPage(fixture);
+ await findModels();
+
+ fireEvent.click(screen.getByRole("button", { name: "Qwen3 Coder 30B" }));
+ const details = screen.getByRole("region", {
+ name: "Qwen3 Coder 30B details",
+ });
+ expect(details).toHaveTextContent("GatewayBifrost · Pi not installed");
+ expect(
+ screen.queryByRole("button", { name: /Use Qwen3 Coder 30B with/u }),
+ ).toBeNull();
+
+ const computer = fixture.runtime.seed.localComputers[0]!;
+ computer.runtimes = [
+ ...computer.runtimes,
+ {
+ models: [],
+ status: "not_installed",
+ type: "pi",
+ },
+ ];
+ fixture.runtime.events.emitSignal({
+ hint: {
+ id: "computer-lab",
+ resource: "computers",
+ tenant_id: tenantId,
+ },
+ type: "resource.invalidated",
+ });
+ await waitFor(() =>
+ expect(details).toHaveTextContent("GatewayBifrost · Setting up Pi…"),
+ );
+ expect(
+ screen.queryByRole("button", { name: /Use Qwen3 Coder 30B with/u }),
+ ).toBeNull();
+
+ computer.runtimes = computer.runtimes.map((runtime) =>
+ runtime.type === "pi"
+ ? { ...runtime, status: "ready", version: "1.3.0" }
+ : runtime,
+ );
+ fixture.runtime.events.emitSignal({
+ hint: {
+ id: "computer-lab",
+ resource: "computers",
+ tenant_id: tenantId,
+ },
+ type: "resource.invalidated",
+ });
+ await waitFor(() =>
+ expect(details).toHaveTextContent(
+ "GatewayBifrost · Registering with Pi…",
+ ),
+ );
+ expect(
+ await screen.findByRole("button", {
+ name: "Use Qwen3 Coder 30B with Jenny's Delegate",
+ }),
+ ).toBeVisible();
+
+ computer.runtimes = computer.runtimes.map((runtime) =>
+ runtime.type === "pi" ? { ...runtime, status: "error" } : runtime,
+ );
+ fixture.runtime.events.emitSignal({
+ hint: {
+ id: "computer-lab",
+ resource: "computers",
+ tenant_id: tenantId,
+ },
+ type: "resource.invalidated",
+ });
+ await waitFor(() =>
+ expect(details).toHaveTextContent("GatewayBifrost · Pi unavailable"),
+ );
+ await waitFor(() =>
+ expect(
+ screen.queryByRole("button", { name: /Use Qwen3 Coder 30B with/u }),
+ ).toBeNull(),
+ );
+ });
+
+ it("switches Another Me to a loaded model in one click and opens its chat", async () => {
+ const fixture = setup();
+ enableReadyPi(fixture);
+ acceptTenantAgentUpdates(fixture.runtime);
+ await renderPage(fixture);
+ await findModels();
+
+ const useButton = await screen.findByRole("button", {
+ name: "Use Qwen3 Coder 30B with Jenny's Delegate",
+ });
+ fireEvent.click(useButton);
+
+ await waitFor(() =>
+ expect(
+ fixture.runtime.server.requestsTo(
+ "PATCH",
+ "/v0/tenants/{tenantId}/agents/{agentId}",
+ ),
+ ).toHaveLength(1),
+ );
+ const openChat = await screen.findByRole("link", { name: "Open chat" });
+ expect(openChat).toHaveAttribute(
+ "href",
+ "/t/tenant-northstar/rooms/room-another-me/chat",
+ );
+ expect(
+ within(card("Qwen3 Coder 30B")).getByText("3 Agents"),
+ ).toHaveAttribute(
+ "title",
+ "Used by Research agent, Code reviewer, Jenny's Delegate",
+ );
+
+ fireEvent.click(openChat);
+ expect(await screen.findByText("Another Me room")).toBeVisible();
+ });
+
+ it("lets the Sponsor switch other Agents from Used by while disabling busy ones", async () => {
+ const fixture = setup();
+ enableReadyPi(fixture);
+ acceptTenantAgentUpdates(fixture.runtime);
+ fixture.runtime.seed.tenantAgents = fixture.runtime.seed.tenantAgents.map(
+ (agent) =>
+ agent.actor.id === "actor-codex"
+ ? {
+ ...agent,
+ availability: {
+ active_task_count: 1,
+ label: "Working",
+ status: "online",
+ },
+ }
+ : agent,
+ );
+ await renderPage(fixture);
+ await findModels();
+
+ await screen.findByRole("button", {
+ name: "Use Qwen3 Coder 30B with Jenny's Delegate",
+ });
+ fireEvent.click(screen.getByRole("button", { name: "Qwen3 Coder 30B" }));
+ const details = screen.getByRole("region", {
+ name: "Qwen3 Coder 30B details",
+ });
+ const switcher = within(details).getByRole("combobox", {
+ name: "Switch an Agent to Qwen3 Coder 30B",
+ });
+ fireEvent.click(switcher);
+ const busyCodex = await screen.findByRole("option", {
+ name: "Codex · Working",
+ });
+ expect(busyCodex).toBeDisabled();
+
+ // Finish Codex's active turn, then switch Codex from Used by.
+ fireEvent.keyDown(screen.getByRole("listbox"), { key: "Escape" });
+ await waitFor(() => expect(screen.queryByRole("listbox")).toBeNull());
+ fixture.runtime.seed.tenantAgents = fixture.runtime.seed.tenantAgents.map(
+ (agent) =>
+ agent.actor.id === "actor-codex"
+ ? {
+ ...agent,
+ availability: {
+ active_task_count: 0,
+ label: "Online",
+ status: "online",
+ },
+ }
+ : agent,
+ );
+ fixture.runtime.events.emitSignal({
+ hint: { id: "actor-codex", resource: "agents", tenant_id: tenantId },
+ type: "resource.invalidated",
+ });
+
+ fireEvent.click(
+ within(details).getByRole("combobox", {
+ name: "Switch an Agent to Qwen3 Coder 30B",
+ }),
+ );
+ fireEvent.click(await screen.findByRole("option", { name: "Codex" }));
+
+ await waitFor(() =>
+ expect(
+ fixture.runtime.server.requestsTo(
+ "PATCH",
+ "/v0/tenants/{tenantId}/agents/{agentId}",
+ ),
+ ).toHaveLength(1),
+ );
+ expect(details).toHaveTextContent("Codex");
+ });
+
+ it("hands affected Agents over automatically once a Make room replacement model loads", async () => {
+ const mac = withModel(macView(), "llama3.3-70b:Q4_K_M", {
+ pi_model: "localmodels-library/llama3.3-70b",
+ });
+ const fixture = setup([mac]);
+ enableReadyPi(fixture);
+ acceptTenantAgentUpdates(fixture.runtime);
+ fixture.runtime.seed.tenantAgents = fixture.runtime.seed.tenantAgents.map(
+ (agent) =>
+ agent.actor.id === "actor-delegate"
+ ? {
+ ...agent,
+ runtime: {
+ model: "localmodels-library/gpt-oss-20b",
+ placement: {
+ computer_id: "computer-mac",
+ runtime_type: "pi",
+ type: "local",
+ workspace_grant_id: "grant-linger-workspace",
+ },
+ },
+ }
+ : agent,
+ );
+ await renderPage(fixture, "?computer=computer-mac");
+ await findModels();
+
+ fireEvent.click(
+ screen.getByRole("button", { name: "Retry Llama 3.3 70B" }),
+ );
+ const dialog = screen.getByRole("dialog", { name: "Make room to load" });
+ const handoff = within(dialog).getByRole("checkbox", {
+ name: "Switch Jenny's Delegate to Llama 3.3 70B once loaded",
+ });
+ expect(handoff).toBeChecked();
+
+ fireEvent.click(
+ within(dialog).getByRole("button", { name: "Unload and load" }),
+ );
+ await waitFor(() => expect(fixture.actions).toHaveLength(1));
+ expect(
+ fixture.runtime.server.requestsTo(
+ "PATCH",
+ "/v0/tenants/{tenantId}/agents/{agentId}",
+ ),
+ ).toHaveLength(0);
+
+ publishSnapshot(
+ fixture,
+ withModel(mac, "llama3.3-70b:Q4_K_M", {
+ endpoint: { base_url: "http://127.0.0.1:18100/v1" },
+ state: "loaded",
+ }),
+ );
+
+ await waitFor(() =>
+ expect(
+ fixture.runtime.server.requestsTo(
+ "PATCH",
+ "/v0/tenants/{tenantId}/agents/{agentId}",
+ ),
+ ).toHaveLength(1),
+ );
+ await waitFor(() =>
+ expect(
+ within(card("Llama 3.3 70B")).getByText("1 Agent"),
+ ).toHaveAttribute("title", "Used by Jenny's Delegate"),
+ );
+ });
+
+ it("explains when an Agent becomes busy before a Make room replacement model finishes loading", async () => {
+ const baseMac = withModel(macView(), "llama3.3-70b:Q4_K_M", {
+ pi_model: "localmodels-library/llama3.3-70b",
+ });
+ const mac = {
+ ...baseMac,
+ models: [
+ ...baseMac.models,
+ modelView(
+ localModel({
+ endpoint: { base_url: "http://127.0.0.1:18100/v1" },
+ fit: "unified",
+ id: "qwen3-coder-30b:Q4_K_M",
+ memory_bytes: gb(4),
+ name: "Qwen3 Coder 30B",
+ pi_model: "localmodels-library/qwen3-coder-30b",
+ pool: "unified",
+ state: "loaded",
+ }),
+ ),
+ ],
+ };
+ const fixture = setup([mac]);
+ enableReadyPi(fixture);
+ acceptTenantAgentUpdates(fixture.runtime);
+ fixture.runtime.seed.tenantAgents = fixture.runtime.seed.tenantAgents.map(
+ (agent) =>
+ agent.actor.id === "actor-delegate"
+ ? {
+ ...agent,
+ runtime: {
+ model: "localmodels-library/gpt-oss-20b",
+ placement: {
+ computer_id: "computer-mac",
+ runtime_type: "pi",
+ type: "local",
+ workspace_grant_id: "grant-linger-workspace",
+ },
+ },
+ }
+ : agent,
+ );
+ await renderPage(fixture, "?computer=computer-mac");
+ await findModels();
+
+ const useQwen = await screen.findByRole("button", {
+ name: "Use Qwen3 Coder 30B with Jenny's Delegate",
+ });
+ expect(useQwen).toBeEnabled();
+
+ fireEvent.click(
+ screen.getByRole("button", { name: "Retry Llama 3.3 70B" }),
+ );
+ const dialog = screen.getByRole("dialog", { name: "Make room to load" });
+ fireEvent.click(
+ within(dialog).getByRole("button", { name: "Unload and load" }),
+ );
+ await waitFor(() => expect(fixture.actions).toHaveLength(1));
+
+ // Jenny's Delegate starts a turn before the replacement model finishes loading.
+ fixture.runtime.seed.tenantAgents = fixture.runtime.seed.tenantAgents.map(
+ (agent) =>
+ agent.actor.id === "actor-delegate"
+ ? {
+ ...agent,
+ availability: {
+ active_task_count: 1,
+ label: "Working",
+ status: "online",
+ },
+ }
+ : agent,
+ );
+ fixture.runtime.events.emitSignal({
+ hint: { id: "actor-delegate", resource: "agents", tenant_id: tenantId },
+ type: "resource.invalidated",
+ });
+ await waitFor(() => expect(useQwen).toBeDisabled());
+
+ publishSnapshot(
+ fixture,
+ withModel(mac, "llama3.3-70b:Q4_K_M", {
+ endpoint: { base_url: "http://127.0.0.1:18100/v1" },
+ state: "loaded",
+ }),
+ );
+
+ expect(
+ await screen.findByText(
+ "Couldn't switch Jenny's Delegate to Llama 3.3 70B while working. Switch once the current turn finishes.",
+ ),
+ ).toBeVisible();
+ expect(
+ fixture.runtime.server.requestsTo(
+ "PATCH",
+ "/v0/tenants/{tenantId}/agents/{agentId}",
+ ),
+ ).toHaveLength(0);
+ });
});
describe("Model source", () => {
diff --git a/apps/web/src/features/local-models/local-models-page.tsx b/apps/web/src/features/local-models/local-models-page.tsx
index 51831a50..4a1de9ee 100644
--- a/apps/web/src/features/local-models/local-models-page.tsx
+++ b/apps/web/src/features/local-models/local-models-page.tsx
@@ -6,7 +6,7 @@ import {
useQueryClient,
useSuspenseQuery,
} from "@tanstack/react-query";
-import { type ReactNode, useState } from "react";
+import { type ReactNode, useEffect, useMemo, useRef, useState } from "react";
import { Link, useParams, useSearchParams } from "react-router";
import { Button } from "@/components/ui/button";
@@ -16,11 +16,29 @@ import { Select, SelectItem } from "@/components/ui/select";
import { relativeTime } from "@/features/local-computer/computer-relative-time";
import { useDesktopComputer } from "@/features/local-computer/desktop-computer";
import { localComputersQueryOptions } from "@/features/local-computer/local-computer-queries";
+import {
+ anotherMeQueryOptions,
+ teamHubIdentityQueryOptions,
+ tenantAgentAvailabilityQueryKey,
+ tenantAgentAvailabilityQueryOptions,
+ tenantAgentsQueryKey,
+ tenantAgentsQueryOptions,
+} from "@/features/rooms/room-queries";
import { requireRoomRouteParam } from "@/features/rooms/room-route-params";
+import { teamHubData } from "@/features/teamhub/teamhub-api";
import { TeamHubError } from "@/features/teamhub/teamhub-error";
import { useTeamHubRuntime } from "@/features/teamhub/teamhub-runtime";
-import type { TeamHubLocalComputerPage } from "@/features/teamhub/teamhub-types";
+import type {
+ TeamHubLocalComputerPage,
+ TeamHubTenantAgent,
+} from "@/features/teamhub/teamhub-types";
+import {
+ type AssignableLocalModelAgent,
+ assignableLocalModelAgents,
+ buildLocalModelRuntimeUpdate,
+ isAgentUsingModel,
+} from "./local-model-agents";
import { AdvancedDialog } from "./local-model-details";
import { ModelRow } from "./local-model-row";
import {
@@ -138,9 +156,9 @@ export function ModelsPage() {
/>
) : computer ? (
<ComputerModels
+ computer={computer}
computerId={computer.computer_id}
displayName={computer.display_name}
- runtimes={computer.runtimes}
computerPicker={
computers.length > 1 ? (
<Select
@@ -219,19 +237,20 @@ function Notice({ children }: { children: ReactNode }) {
}
function ComputerModels({
+ computer,
computerId,
computerPicker,
displayName,
- runtimes = [],
tenantId,
}: {
+ computer?: InventoryComputer;
computerId: string;
computerPicker: ReactNode;
/** Absent for a Computer outside the viewer's own inventory. */
displayName?: string;
- runtimes?: readonly LocalComputerRuntime[];
tenantId: string;
}) {
+ const runtimes: readonly LocalComputerRuntime[] = computer?.runtimes ?? [];
const { client } = useTeamHubRuntime();
const queryClient = useQueryClient();
const query = useQuery(localModelsQueryOptions(client, tenantId, computerId));
@@ -396,6 +415,7 @@ function ComputerModels({
/>
) : null}
<Library
+ computer={computer}
dialog={dialog}
guidance={guidance}
onRefresh={() => refresh.mutate()}
@@ -442,6 +462,7 @@ function ComputerModels({
}
function Library({
+ computer,
dialog,
guidance,
onRefresh,
@@ -454,6 +475,7 @@ function Library({
tenantId,
view,
}: {
+ computer?: InventoryComputer;
dialog: Dialog | null;
guidance: ReturnType<typeof memoryGuidance>;
onRefresh: () => void;
@@ -470,11 +492,30 @@ function Library({
const queryClient = useQueryClient();
const computerId = view.computer.computer_id;
const name = view.computer.display_name;
+ const offline = view.computer.status === "offline";
+ const readOnly = !view.viewer_is_owner;
+ const canManageAgents = !readOnly;
+ const piReady =
+ !computer ||
+ computer.runtimes.some(
+ (runtime) => runtime.type === "pi" && runtime.status === "ready",
+ );
+ const canSwitchAgents =
+ !offline &&
+ canManageAgents &&
+ piReady &&
+ (!status?.mode || status.mode === "local");
const [expandedId, setExpandedId] = useState<string | null>(null);
const [failure, setFailure] = useState<{
code?: string;
modelId: string;
} | null>(null);
+ const [assignError, setAssignError] = useState<string | null>(null);
+ const [pendingSwitch, setPendingSwitch] = useState<{
+ agentIds: string[];
+ modelId: string;
+ } | null>(null);
+ const completedSwitchKeyRef = useRef<string | null>(null);
// An action the Computer accepted, shown on its row until a snapshot moves
// the model on: a different status or a newer snapshot.
const [accepted, setAccepted] = useState<
@@ -483,7 +524,54 @@ function Library({
{ action: LocalModelAction; from?: ModelStatus; observedAt?: string }
>
>({});
- const entries = view.available ? modelEntries(view) : [];
+ const identityQuery = useQuery({
+ ...teamHubIdentityQueryOptions(client),
+ enabled: canManageAgents,
+ });
+ const anotherMeQuery = useQuery({
+ ...anotherMeQueryOptions(client, tenantId),
+ enabled: canManageAgents,
+ });
+ const agentsQuery = useQuery({
+ ...tenantAgentsQueryOptions(client, tenantId),
+ enabled: canManageAgents,
+ });
+ const availabilityQuery = useQuery({
+ ...tenantAgentAvailabilityQueryOptions(client, tenantId),
+ enabled: canManageAgents,
+ });
+ const currentActorId = identityQuery.data?.actors.find(
+ (candidate) => candidate.tenant_id === tenantId,
+ )?.id;
+ const assignableAgents = useMemo(
+ () =>
+ canManageAgents
+ ? assignableLocalModelAgents({
+ agents: agentsQuery.data?.items,
+ anotherMeActorId: anotherMeQuery.data?.agent_actor_id,
+ availability: availabilityQuery.data?.items,
+ computer,
+ computerId,
+ currentActorId,
+ })
+ : [],
+ [
+ agentsQuery.data?.items,
+ anotherMeQuery.data?.agent_actor_id,
+ availabilityQuery.data?.items,
+ canManageAgents,
+ computer,
+ computerId,
+ currentActorId,
+ ],
+ );
+ const anotherMeChatHref = anotherMeQuery.data?.room_id
+ ? `/t/${encodeURIComponent(tenantId)}/rooms/${encodeURIComponent(anotherMeQuery.data.room_id)}/chat`
+ : undefined;
+ const entries = useMemo(
+ () => (view.available ? modelEntries(view) : []),
+ [view],
+ );
const find = (modelId: string) =>
entries.find((entry) => entry.model.id === modelId);
const mutationKey = localModelActionMutationKey(tenantId, computerId);
@@ -491,11 +579,15 @@ function Library({
mutationFn: (input: LocalModelActionInput) =>
actOnLocalComputerModel(client, tenantId, computerId, input),
mutationKey,
- onError: (error, input) =>
+ onError: (error, input) => {
setFailure({
code: error instanceof TeamHubError ? error.code : undefined,
modelId: input.modelId,
- }),
+ });
+ setPendingSwitch((current) =>
+ current?.modelId === input.modelId ? null : current,
+ );
+ },
onMutate: (input) => {
setFailure(null);
return { from: find(input.modelId)?.status };
@@ -518,6 +610,70 @@ function Library({
queryKey: localModelsQueryKey(tenantId, computerId),
}),
});
+ const assignMutation = useMutation({
+ mutationFn: ({
+ agent,
+ piModel,
+ }: {
+ agent: AssignableLocalModelAgent;
+ piModel: string;
+ }) =>
+ teamHubData(
+ client.api.PATCH("/v0/tenants/{tenantId}/agents/{agentId}", {
+ body: {
+ expected_configuration_revision: agent.configurationRevision,
+ runtime: buildLocalModelRuntimeUpdate(
+ agent,
+ piModel,
+ computerId,
+ computer,
+ ),
+ },
+ params: { path: { agentId: agent.actorId, tenantId } },
+ }),
+ ),
+ onError: (error) => {
+ setAssignError(
+ error instanceof Error
+ ? error.message
+ : "Couldn't switch the Agent to this model. Try again.",
+ );
+ },
+ onMutate: () => {
+ setAssignError(null);
+ },
+ onSuccess: (updated) => {
+ queryClient.setQueryData(
+ tenantAgentsQueryKey(tenantId),
+ (current: { items: TeamHubTenantAgent[] } | undefined) =>
+ current
+ ? {
+ ...current,
+ items: current.items.map((item) =>
+ item.actor.id === updated.actor.id
+ ? { ...item, ...updated }
+ : item,
+ ),
+ }
+ : current,
+ );
+ void Promise.all([
+ queryClient.invalidateQueries({
+ queryKey: tenantAgentsQueryKey(tenantId),
+ }),
+ queryClient.invalidateQueries({
+ queryKey: localModelsQueryKey(tenantId, computerId),
+ }),
+ queryClient.invalidateQueries({
+ queryKey: tenantAgentAvailabilityQueryKey(tenantId),
+ }),
+ ]);
+ },
+ });
+ const { mutateAsync: applyAgentAssignment } = assignMutation;
+ const assigningAgentId = assignMutation.isPending
+ ? assignMutation.variables?.agent.actorId
+ : undefined;
const sending = useMutationState({
filters: { mutationKey, status: "pending" },
select: (mutation) =>
@@ -542,8 +698,56 @@ function Library({
requests.has(modelId) &&
(requests.get(modelId) !== "download" ||
sending.some((input) => input?.modelId === modelId));
- const offline = view.computer.status === "offline";
- const readOnly = !view.viewer_is_owner;
+ const pendingLoadInFlight = pendingSwitch
+ ? requests.get(pendingSwitch.modelId) === "load"
+ : false;
+ useEffect(() => {
+ if (!pendingSwitch) return;
+ const target = entries.find(
+ (entry) => entry.model.id === pendingSwitch.modelId,
+ );
+ if (
+ !target ||
+ (!pendingLoadInFlight &&
+ (target.status === "failed" ||
+ target.status === "available" ||
+ target.status === "unavailable"))
+ ) {
+ setPendingSwitch(null);
+ return;
+ }
+ if (target.status !== "loaded" || !target.model.pi_model) return;
+ const key = `${pendingSwitch.modelId}:${view.observed_at ?? ""}:${pendingSwitch.agentIds.join(",")}`;
+ if (completedSwitchKeyRef.current === key) return;
+ completedSwitchKeyRef.current = key;
+ const piModel = target.model.pi_model;
+ const matching = assignableAgents.filter(
+ (agent) =>
+ pendingSwitch.agentIds.includes(agent.actorId) &&
+ !isAgentUsingModel(target, agent, computerId),
+ );
+ const busySkipped = matching.filter((agent) => agent.busy);
+ const targets = matching.filter((agent) => !agent.busy);
+ setPendingSwitch(null);
+ if (busySkipped.length) {
+ const names = busySkipped.map((agent) => agent.name).join(", ");
+ setAssignError(
+ `Couldn't switch ${names} to ${target.model.name} while working. Switch once the current turn finishes.`,
+ );
+ }
+ if (!targets.length) return;
+ void Promise.all(
+ targets.map((agent) => applyAgentAssignment({ agent, piModel })),
+ ).catch(() => undefined);
+ }, [
+ applyAgentAssignment,
+ assignableAgents,
+ computerId,
+ entries,
+ pendingLoadInFlight,
+ pendingSwitch,
+ view.observed_at,
+ ]);
// A dialog stays open across snapshots, so its confirm checks the model
// and Computer as they are now, the way the row's buttons do.
const confirmable = (
@@ -581,6 +785,14 @@ function Library({
function act(input: LocalModelActionInput) {
setDialog(null);
+ if (
+ (input.action === "cancel" ||
+ input.action === "remove" ||
+ input.action === "unload") &&
+ pendingSwitch?.modelId === input.modelId
+ ) {
+ setPendingSwitch(null);
+ }
action.mutate(input);
}
@@ -646,6 +858,11 @@ function Library({
</FormFeedback>
</div>
) : null}
+ {assignError ? (
+ <div className="mt-6">
+ <FormFeedback tone="danger">{assignError}</FormFeedback>
+ </div>
+ ) : null}
{guidanceCopy ? (
<aside
aria-label="Memory guidance"
@@ -678,10 +895,23 @@ function Library({
entry.model.id !== status.runtime_model;
return (
<ModelRow
+ anotherMeChatHref={anotherMeChatHref}
+ assignableAgents={assignableAgents}
+ assigningAgentId={assigningAgentId}
+ computer={computer}
disabled={offline || readOnly || switching || busy(modelId)}
entry={entry}
expanded={expandedId === modelId}
key={modelId}
+ onAssignAgent={
+ entry.model.pi_model && canSwitchAgents
+ ? (agent) =>
+ assignMutation.mutate({
+ agent,
+ piModel: entry.model.pi_model!,
+ })
+ : undefined
+ }
onCancel={() => act({ action: "cancel", modelId })}
onDownload={() => act({ action: "download", modelId })}
onLoad={() => load(entry)}
@@ -710,17 +940,24 @@ function Library({
) : null}
{dialogEntry && makeRoom ? (
<MakeRoomDialog
+ assignableAgents={assignableAgents}
check={makeRoom}
disabled={!confirmable(dialogEntry, "load")}
entry={dialogEntry}
onClose={() => setDialog(null)}
- onConfirm={(unloadFirst) =>
+ onConfirm={(unloadFirst, switchAgentIds) => {
+ completedSwitchKeyRef.current = null;
+ setPendingSwitch(
+ canSwitchAgents && switchAgentIds.length
+ ? { agentIds: switchAgentIds, modelId: dialogEntry.model.id }
+ : null,
+ );
act({
action: "load",
modelId: dialogEntry.model.id,
unloadFirst,
- })
- }
+ });
+ }}
onRecheck={!offline && !readOnly ? onRefresh : undefined}
rechecking={rechecking}
view={view}
diff --git a/apps/web/src/features/local-models/local-models-rules.test.ts b/apps/web/src/features/local-models/local-models-rules.test.ts
index 76b2b0f5..b3d8cf50 100644
--- a/apps/web/src/features/local-models/local-models-rules.test.ts
+++ b/apps/web/src/features/local-models/local-models-rules.test.ts
@@ -436,6 +436,16 @@ describe("local models rules", () => {
used_by: [],
}),
).toBeUndefined();
+ expect(
+ usedByBadge(
+ {
+ model: localModel({ id: "m", name: "M", state: "loaded" }),
+ status: "loaded",
+ used_by: [],
+ },
+ ["Research", "Delegate"],
+ ),
+ ).toBe("2 Agents");
expect(
usedByBadge({
model: localModel({ id: "m", name: "M", state: "absent" }),
diff --git a/apps/web/src/features/local-models/local-models-rules.ts b/apps/web/src/features/local-models/local-models-rules.ts
index 2fa2e962..7972e58f 100644
--- a/apps/web/src/features/local-models/local-models-rules.ts
+++ b/apps/web/src/features/local-models/local-models-rules.ts
@@ -386,13 +386,13 @@ export function agentNames(entry: Pick<LocalModelView, "used_by">) {
/** Compact Agent count chip for a model on the Computer, or undefined when unused. */
export function usedByBadge(
entry: Pick<ModelEntry, "model" | "status" | "used_by">,
+ names?: readonly string[],
): string | undefined {
- if (!isModelOnComputer(entry.model, entry.status) || !entry.used_by.length) {
+ const count = names ? names.length : entry.used_by.length;
+ if (!isModelOnComputer(entry.model, entry.status) || !count) {
return undefined;
}
- return entry.used_by.length === 1
- ? "1 Agent"
- : `${entry.used_by.length} Agents`;
+ return count === 1 ? "1 Agent" : `${count} Agents`;
}
export type LocalModelCapability = NonNullable<
diff --git a/apps/web/src/features/rooms/chat/direct-agent-model-switch.test.tsx b/apps/web/src/features/rooms/chat/direct-agent-model-switch.test.tsx
index d84f7e95..35599aed 100644
--- a/apps/web/src/features/rooms/chat/direct-agent-model-switch.test.tsx
+++ b/apps/web/src/features/rooms/chat/direct-agent-model-switch.test.tsx
@@ -6,9 +6,11 @@ import {
waitFor,
within,
} from "@testing-library/react";
+import { MemoryRouter } from "react-router";
import { describe, expect, it, vi } from "vitest";
import { createTestTeamHubRuntime } from "@/test/teamhub-test-runtime";
+import { labView } from "@/features/local-models/local-models-test-support";
import type { TestRouteHandler } from "@/test/teamhub-test-server";
import type {
TeamHubTenantAgent,
@@ -106,6 +108,68 @@ describe("Direct Agent runtime settings", () => {
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
expect(updateTenantAgent).not.toHaveBeenCalled();
});
+
+ it("resolves Bifrost localmodels-library model names from local-models before Pi lists them", async () => {
+ const base = localAgent();
+ const piAgent: TeamHubTenantAgent = {
+ ...base,
+ runtime: {
+ model: "localmodels-library/qwen3-coder-30b",
+ placement: {
+ computer_id: "computer-1",
+ runtime_type: "pi",
+ type: "local",
+ workspace_grant_id: "grant-1",
+ },
+ },
+ };
+ const runtime = createTestTeamHubRuntime();
+ runtime.server.on("GET", "/v0/tenants/{tenantId}/local-computers", () => ({
+ items: [
+ {
+ computer_id: "computer-1",
+ display_name: "Computer",
+ runtimes: [{ models: [], status: "ready", type: "pi" }],
+ status: "online",
+ workspace_grants: [
+ {
+ grant_id: "grant-1",
+ label: "Workspace",
+ mode: "workspace-write",
+ },
+ ],
+ },
+ ],
+ }));
+ runtime.server.on(
+ "GET",
+ "/v0/tenants/{tenantId}/local-computers/{computerId}/local-models",
+ () => labView(),
+ );
+
+ render(
+ <MemoryRouter>
+ <QueryClientProvider
+ client={
+ new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ })
+ }
+ >
+ <DirectAgentModelSwitch
+ client={runtime.client}
+ currentActorId="actor-jenny"
+ registration={piAgent}
+ tenantId="tenant-northstar"
+ />
+ </QueryClientProvider>
+ </MemoryRouter>,
+ );
+
+ expect(
+ await screen.findByRole("button", { name: "Qwen3 Coder 30B" }),
+ ).toBeVisible();
+ });
});
function renderSwitch({
@@ -143,21 +207,23 @@ function renderSwitch({
],
}));
render(
- <QueryClientProvider
- client={
- new QueryClient({
- defaultOptions: { queries: { retry: false } },
- })
- }
- >
- <DirectAgentModelSwitch
- busy={busy}
- client={runtime.client}
- currentActorId={currentActorId}
- registration={registration}
- tenantId="tenant-northstar"
- />
- </QueryClientProvider>,
+ <MemoryRouter>
+ <QueryClientProvider
+ client={
+ new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ })
+ }
+ >
+ <DirectAgentModelSwitch
+ busy={busy}
+ client={runtime.client}
+ currentActorId={currentActorId}
+ registration={registration}
+ tenantId="tenant-northstar"
+ />
+ </QueryClientProvider>
+ </MemoryRouter>,
);
}
diff --git a/apps/web/src/features/rooms/chat/direct-agent-model-switch.tsx b/apps/web/src/features/rooms/chat/direct-agent-model-switch.tsx
index 9b4c28f4..adf6c658 100644
--- a/apps/web/src/features/rooms/chat/direct-agent-model-switch.tsx
+++ b/apps/web/src/features/rooms/chat/direct-agent-model-switch.tsx
@@ -1,4 +1,4 @@
-import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
+import { useMutation, useQueryClient } from "@tanstack/react-query";
import { lazy, Suspense, useState } from "react";
import { teamHubData } from "@/features/teamhub/teamhub-api";
import { type TeamHubClient } from "@/features/teamhub/teamhub-client";
@@ -11,6 +11,7 @@ const EditAgentRuntimeDialog = lazy(async () => ({
default: (await import("../members/edit-agent-runtime-dialog"))
.EditAgentRuntimeDialog,
}));
+import { useResolvedAgentModelLabel } from "../members/use-agent-model-selection";
import { tenantAgentsQueryKey } from "../room-queries";
import "./direct-agent-model-switch.css";
@@ -42,18 +43,12 @@ export function DirectAgentModelSwitch(props: Props) {
function RuntimeSettingsEntry({ client, registration, tenantId, busy }: Props) {
const queryClient = useQueryClient();
const [open, setOpen] = useState(false);
- const computers = useQuery({
- queryFn: () => client.listTenantLocalComputers(tenantId),
- queryKey: ["teamhub", "local-computers", tenantId],
- retry: false,
- });
- const placement = registration.runtime.placement;
- const models = computers.data?.items
- .find((item) => item.computer_id === placement?.computer_id)
- ?.runtimes.find((item) => item.type === placement?.runtime_type)?.models;
- const model = models?.find((item) => item.id === registration.runtime.model);
const effort = registration.runtime.reasoning_effort;
- const label = model?.label ?? registration.runtime.model;
+ const label = useResolvedAgentModelLabel(
+ client,
+ tenantId,
+ registration.runtime,
+ );
const update = useMutation({
mutationFn: (input: AgentRuntimeUpdateInput) =>
teamHubData(
diff --git a/apps/web/src/features/rooms/members/actor-profile.tsx b/apps/web/src/features/rooms/members/actor-profile.tsx
index 90d69669..55da0427 100644
--- a/apps/web/src/features/rooms/members/actor-profile.tsx
+++ b/apps/web/src/features/rooms/members/actor-profile.tsx
@@ -64,6 +64,7 @@ import type {
AgentRuntimeField,
AgentRuntimeUpdateInput,
} from "./edit-agent-runtime-dialog";
+import { useResolvedAgentModelLabel } from "./use-agent-model-selection";
const EditAgentRuntimeDialog = lazy(async () => ({
default: (await import("./edit-agent-runtime-dialog")).EditAgentRuntimeDialog,
}));
@@ -319,6 +320,11 @@ export function AgentProfileContent({
updateAgent.reset();
setProfileDialogOpen("instructions");
};
+ const resolvedModelLabel = useResolvedAgentModelLabel(
+ client,
+ tenantId,
+ agentRegistration?.runtime,
+ );
return (
<AgentInfoContent
@@ -343,7 +349,7 @@ export function AgentProfileContent({
<PanelAgentRuntimeDetails
localRuntime={agentSnapshot?.local_runtime_status}
placement={agentRegistration?.runtime.placement}
- modelLabel={agentRegistration?.runtime.model}
+ modelLabel={resolvedModelLabel}
reasoning={agentRegistration?.runtime.reasoning_effort}
canEdit={canEditRuntime}
busy={agentBusy}
diff --git a/apps/web/src/features/rooms/members/edit-agent-runtime-dialog.test.tsx b/apps/web/src/features/rooms/members/edit-agent-runtime-dialog.test.tsx
index 68f9f36a..557561db 100644
--- a/apps/web/src/features/rooms/members/edit-agent-runtime-dialog.test.tsx
+++ b/apps/web/src/features/rooms/members/edit-agent-runtime-dialog.test.tsx
@@ -1,5 +1,6 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { MemoryRouter } from "react-router";
import { describe, expect, it, vi } from "vitest";
import type {
@@ -414,15 +415,106 @@ describe("EditAgentRuntimeDialog", () => {
expect(screen.getByRole("button", { name: "Move Agent" })).toBeDisabled();
expect(onSave).not.toHaveBeenCalled();
});
+
+ it("links Pi runtime settings to Local models when ready with models", async () => {
+ const onClose = vi.fn();
+ const computer = localComputer("computer-old", "Old Mac", "online");
+ computer.runtimes = [
+ ...computer.runtimes,
+ {
+ models: [
+ {
+ id: "localmodels-library/qwen3-coder-30b",
+ label: "Qwen3 Coder 30B",
+ },
+ ],
+ status: "ready",
+ type: "pi",
+ },
+ ];
+ renderDialog({
+ computersOverride: { items: [computer] },
+ onClose,
+ onSave: vi.fn(),
+ });
+ const runtime = await screen.findByRole("combobox", {
+ name: "Agent runtime",
+ });
+ fireEvent.click(runtime);
+ fireEvent.click(await screen.findByRole("option", { name: "Pi" }));
+
+ const link = await screen.findByRole("link", { name: "Settings › Models" });
+ expect(link).toHaveAttribute(
+ "href",
+ "/t/tenant-northstar/settings/models?computer=computer-old",
+ );
+ expect(link.closest("p")).toHaveTextContent(
+ "Manage downloaded models in Settings › Models.",
+ );
+ fireEvent.click(link);
+ expect(onClose).toHaveBeenCalledTimes(1);
+ });
+
+ it.each(["ready-empty", "not-installed"] as const)(
+ "guides Pi setup in Local models when %s",
+ async (mode) => {
+ const onClose = vi.fn();
+ const computer = localComputer("computer-old", "Old Mac", "online");
+ computer.runtimes = [
+ ...computer.runtimes,
+ mode === "ready-empty"
+ ? {
+ models: [],
+ status: "ready",
+ type: "pi",
+ }
+ : {
+ message: "Install Pi on this computer.",
+ models: [],
+ status: "not_installed",
+ type: "pi",
+ },
+ ];
+ renderDialog({
+ computersOverride: { items: [computer] },
+ onClose,
+ onSave: vi.fn(),
+ });
+ const runtime = await screen.findByRole("combobox", {
+ name: "Agent runtime",
+ });
+ fireEvent.click(runtime);
+ fireEvent.click(
+ await screen.findByRole("option", {
+ name: mode === "ready-empty" ? "Pi" : "Pi · Unavailable",
+ }),
+ );
+
+ const link = await screen.findByRole("link", {
+ name: "Settings › Models",
+ });
+ expect(link).toHaveAttribute(
+ "href",
+ "/t/tenant-northstar/settings/models?computer=computer-old",
+ );
+ expect(link.closest("p")).toHaveTextContent(
+ "Download and load a local model in Settings › Models to run Agents with Pi on this computer.",
+ );
+ fireEvent.click(link);
+ expect(onClose).toHaveBeenCalledTimes(1);
+ },
+ );
});
function renderDialog({
field = "runtime",
+ onClose = vi.fn(),
onSave,
registration = localCodexAgent(),
computersOverride,
}: {
field?: AgentRuntimeField;
+ onClose?: () => void;
onSave: (input: AgentRuntimeUpdateInput) => void;
registration?: TeamHubTenantAgent;
computersOverride?: TeamHubLocalComputerPage;
@@ -438,21 +530,23 @@ function renderDialog({
};
render(
- <QueryClientProvider
- client={
- new QueryClient({ defaultOptions: { queries: { retry: false } } })
- }
- >
- <EditAgentRuntimeDialog
- field={field}
- client={client}
- isPending={false}
- onClose={vi.fn()}
- onSave={onSave}
- registration={registration}
- tenantId="tenant-northstar"
- />
- </QueryClientProvider>,
+ <MemoryRouter>
+ <QueryClientProvider
+ client={
+ new QueryClient({ defaultOptions: { queries: { retry: false } } })
+ }
+ >
+ <EditAgentRuntimeDialog
+ field={field}
+ client={client}
+ isPending={false}
+ onClose={onClose}
+ onSave={onSave}
+ registration={registration}
+ tenantId="tenant-northstar"
+ />
+ </QueryClientProvider>
+ </MemoryRouter>,
);
}
diff --git a/apps/web/src/features/rooms/members/edit-agent-runtime-dialog.tsx b/apps/web/src/features/rooms/members/edit-agent-runtime-dialog.tsx
index 0c026d6e..e105ce01 100644
--- a/apps/web/src/features/rooms/members/edit-agent-runtime-dialog.tsx
+++ b/apps/web/src/features/rooms/members/edit-agent-runtime-dialog.tsx
@@ -1,9 +1,11 @@
import { useQuery } from "@tanstack/react-query";
import { type FormEvent, useId } from "react";
+import { Link } from "react-router";
import { Button } from "@/components/ui/button";
import { ModalDialog } from "@/components/ui/modal-dialog";
import { Select, SelectItem } from "@/components/ui/select";
+import { localComputersQueryKey } from "@/features/local-computer/local-computer-queries";
import type { TeamHubClient } from "@/features/teamhub/teamhub-client";
import type {
TeamHubAgentReasoningEffort,
@@ -60,7 +62,7 @@ export function EditAgentRuntimeDialog({
const formId = useId();
const computers = useQuery({
queryFn: () => client.listTenantLocalComputers(tenantId),
- queryKey: ["teamhub", "local-computers", tenantId],
+ queryKey: localComputersQueryKey(tenantId),
retry: false,
refetchInterval: 5_000,
});
@@ -149,27 +151,45 @@ export function EditAgentRuntimeDialog({
))}
</Select>
</label>
- <label className="block">
- <span className="mb-1.5 block text-sm font-medium">Model</span>
- <Select
- aria-label="Agent model"
- className="ui-field-control w-full"
- disabled={field === "reasoning"}
- onValueChange={selection.selectModel}
- value={model}
- >
- {model && !modelIsAvailable ? (
- <SelectItem value={model} disabled>
- {model} · Unavailable
- </SelectItem>
- ) : null}
- {selection.modelOptions.map((item) => (
- <SelectItem key={item.id} value={item.id}>
- {item.label}
- </SelectItem>
- ))}
- </Select>
- </label>
+ <div className="space-y-1.5">
+ <label className="block">
+ <span className="mb-1.5 block text-sm font-medium">Model</span>
+ <Select
+ aria-label="Agent model"
+ className="ui-field-control w-full"
+ disabled={field === "reasoning"}
+ onValueChange={selection.selectModel}
+ value={model}
+ >
+ {model && !modelIsAvailable ? (
+ <SelectItem value={model} disabled>
+ {model} · Unavailable
+ </SelectItem>
+ ) : null}
+ {selection.modelOptions.map((item) => (
+ <SelectItem key={item.id} value={item.id}>
+ {item.label}
+ </SelectItem>
+ ))}
+ </Select>
+ </label>
+ {selection.runtimeType === "pi" &&
+ selection.computerId &&
+ !loading &&
+ !unavailable &&
+ localReady &&
+ selection.modelOptions.length > 0 ? (
+ <p className="text-xs text-muted-foreground">
+ Manage downloaded models in{" "}
+ <LocalModelsLink
+ computerId={selection.computerId}
+ onNavigate={onClose}
+ tenantId={tenantId}
+ />
+ .
+ </p>
+ ) : null}
+ </div>
<ReasoningField
allowed={selection.selectedModel?.allowed_reasoning_effort}
onChange={selection.selectReasoningEffort}
@@ -217,6 +237,21 @@ export function EditAgentRuntimeDialog({
"Install and sign in to this runtime on the computer, then wait for it to become ready."}
</p>
) : null}
+ {selection.runtimeType === "pi" &&
+ selection.computerId &&
+ !loading &&
+ !unavailable &&
+ (!localReady || selection.modelOptions.length === 0) ? (
+ <p className="text-xs text-muted-foreground">
+ Download and load a local model in{" "}
+ <LocalModelsLink
+ computerId={selection.computerId}
+ onNavigate={onClose}
+ tenantId={tenantId}
+ />{" "}
+ to run Agents with Pi on this computer.
+ </p>
+ ) : null}
{unavailable ? (
<p className="text-sm text-app-danger" role="alert">
Runtime options are unavailable.
@@ -297,3 +332,24 @@ function ReasoningField({
</label>
);
}
+
+function LocalModelsLink({
+ computerId,
+ onNavigate,
+ tenantId,
+}: {
+ computerId: string;
+ onNavigate: () => void;
+ tenantId: string;
+}) {
+ const to = `/t/${encodeURIComponent(tenantId)}/settings/models?computer=${encodeURIComponent(computerId)}`;
+ return (
+ <Link
+ className="font-medium text-foreground underline underline-offset-2"
+ onClick={onNavigate}
+ to={to}
+ >
+ Settings › Models
+ </Link>
+ );
+}
diff --git a/apps/web/src/features/rooms/members/use-agent-model-selection.ts b/apps/web/src/features/rooms/members/use-agent-model-selection.ts
index 4b89c71f..84dd700e 100644
--- a/apps/web/src/features/rooms/members/use-agent-model-selection.ts
+++ b/apps/web/src/features/rooms/members/use-agent-model-selection.ts
@@ -1,6 +1,13 @@
+import { useQuery } from "@tanstack/react-query";
import { useState } from "react";
-import type { TeamHubAgentReasoningEffort } from "@/features/teamhub/teamhub-types";
+import { localComputersQueryOptions } from "@/features/local-computer/local-computer-queries";
+import { localModelsQueryOptions } from "@/features/local-models/local-models-queries";
+import type { TeamHubClient } from "@/features/teamhub/teamhub-client";
+import type {
+ TeamHubAgentReasoningEffort,
+ TeamHubTenantAgent,
+} from "@/features/teamhub/teamhub-types";
interface RuntimeModel {
id: string;
@@ -53,3 +60,51 @@ export function reasoningEffortLabel(value: TeamHubAgentReasoningEffort) {
} satisfies Record<TeamHubAgentReasoningEffort, string>
)[value];
}
+
+/**
+ * Resolves the human-readable model label for an Agent's current runtime,
+ * falling back to the Computer's local-models catalog for Bifrost-backed Pi
+ * models not yet reflected in the Computer runtime catalog.
+ */
+export function useResolvedAgentModelLabel(
+ client: TeamHubClient,
+ tenantId: string,
+ runtime: TeamHubTenantAgent["runtime"],
+): string;
+export function useResolvedAgentModelLabel(
+ client: TeamHubClient,
+ tenantId: string,
+ runtime: TeamHubTenantAgent["runtime"] | undefined,
+): string | undefined;
+export function useResolvedAgentModelLabel(
+ client: TeamHubClient,
+ tenantId: string,
+ runtime: TeamHubTenantAgent["runtime"] | undefined,
+): string | undefined {
+ const placement = runtime?.placement;
+ const computerId =
+ placement?.type === "local" ? placement.computer_id : undefined;
+ const computers = useQuery({
+ ...localComputersQueryOptions(client, tenantId),
+ enabled: Boolean(computerId),
+ });
+ const catalogLabel = computers.data?.items
+ .find((item) => item.computer_id === computerId)
+ ?.runtimes.find((item) => item.type === placement?.runtime_type)
+ ?.models.find((item) => item.id === runtime?.model)?.label;
+ const localModels = useQuery({
+ ...localModelsQueryOptions(client, tenantId, computerId ?? ""),
+ enabled: Boolean(
+ placement?.runtime_type === "pi" &&
+ computerId &&
+ !catalogLabel &&
+ runtime?.model?.startsWith("localmodels-library/"),
+ ),
+ });
+ const localModelLabel = localModels.data?.available
+ ? localModels.data.models.find(
+ (item) => item.model.pi_model === runtime?.model,
+ )?.model.name
+ : undefined;
+ return catalogLabel ?? localModelLabel ?? runtime?.model;
+}