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
12 changes: 9 additions & 3 deletions apps/web/src/bench/bench-pill.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CaretDown } from "@/lib/icons";
import { IdentityAvatar } from "@/chat/avatar";
import type { WorkerStatus } from "../worker-status";

/** Frosted pill centered over the thread: the bench's worker, its name and
* live status. Toggles the bench drawer. */
Expand All @@ -12,7 +13,7 @@ export function BenchPill({
}: {
readonly benchName: string;
readonly worker: { readonly id: string; readonly name: string } | undefined;
readonly status: string;
readonly status: WorkerStatus;
readonly open: boolean;
readonly onToggle: () => void;
}) {
Expand All @@ -25,10 +26,15 @@ export function BenchPill({
onClick={onToggle}
>
{worker === undefined ? null : (
<IdentityAvatar kind="agent" name={worker.name} principalId={worker.id} />
<IdentityAvatar
kind="agent"
name={worker.name}
principalId={worker.id}
status={status.tone}
/>
)}
<b>{benchName}</b>
<span className="bench-pill-status">{status}</span>
<span className="bench-pill-status">{status.text}</span>
<CaretDown size={14} aria-hidden="true" />
</button>
);
Expand Down
6 changes: 4 additions & 2 deletions apps/web/src/pages/workbench-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from "@/chat/threads-api";
import { BenchDrawer } from "../bench/bench-drawer";
import { BenchPill } from "../bench/bench-pill";
import { useWorkerStatus } from "../worker-status";
import { GrantsTab } from "../bench/grants-tab";
import { InformationTab } from "../bench/information-tab";
import { ToolsTab } from "../bench/tools-tab";
Expand Down Expand Up @@ -174,6 +175,7 @@ function Workbench({ workbenchTenantId }: { readonly workbenchTenantId: string }
agent.address === "" && agent.assetName !== undefined,
);
const startingAgent = releasedAgents[0];
const workerStatus = useWorkerStatus(workbenchTenantId, agents[0]?.id);
// Only a live agent can be addressed, so only one can be mentioned.
const mentionables = agents
.filter((agent) => agent.address.includes("@"))
Expand Down Expand Up @@ -230,7 +232,7 @@ function Workbench({ workbenchTenantId }: { readonly workbenchTenantId: string }
<BenchPill
benchName={tenant.data?.name ?? "Workbench"}
worker={agents[0]}
status={startingAgent === undefined ? "Live" : "Starting"}
status={workerStatus}
open={drawerOpen}
onToggle={() => setDrawerOpen((open) => !open)}
/>
Expand Down Expand Up @@ -304,7 +306,7 @@ function Workbench({ workbenchTenantId }: { readonly workbenchTenantId: string }
<BenchDrawer
open={drawerOpen}
title={tenant.data?.name ?? "Workbench"}
subtitle={startingAgent === undefined ? "Live" : "Starting"}
subtitle={workerStatus.text}
onClose={closeDrawer}
tabs={{
Information: (
Expand Down
44 changes: 44 additions & 0 deletions apps/web/src/worker-status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// The one status source for a worker. The inbox stream (see
// `subscribeToInbox`) writes into the participants and approvals caches this
// reads; nothing here fetches on its own.

import { useQuery } from "@tanstack/react-query";

import type { AvatarStatus } from "@/chat/avatar";
import { sameAddress, type WorkbenchParticipant } from "@/chat/threads-api";
import { workbenchKeys } from "./chat-path";
import { TenantApprovalsSchema, useAPIQuery } from "./api";
import { pendingApprovalsPath } from "./pending-approvals";

export type WorkerStatus = {
readonly tone: AvatarStatus;
readonly text: string;
};

// `working` has no stock signal: the inbox stream carries no turn events, and
// a live agent's run stays `running` whether or not a turn is in flight.
export function useWorkerStatus(
tenantId: string | null,
agentId: string | undefined,
): WorkerStatus {
const participants = useQuery({
queryKey: workbenchKeys.participants(tenantId ?? ""),
queryFn: (): readonly WorkbenchParticipant[] => [],
enabled: false,
});
const approvals = useAPIQuery(
tenantId === null ? "" : pendingApprovalsPath(tenantId),
TenantApprovalsSchema,
);

const agent = participants.data?.find((p) => p.kind === "agent" && p.id === agentId);
if (agent === undefined) return { tone: "idle", text: "Live" };
if (agent.address === "") return { tone: "idle", text: "Starting" };

const needsYou =
approvals.kind === "ready" &&
approvals.data.data.some(
(row) => row.status === "pending" && sameAddress(row.agentAddress, agent.address),
);
return needsYou ? { tone: "ready", text: "Needs you" } : { tone: "idle", text: "Live" };
}
Loading