Agent Workbench
One agent at work: the person who asked, the agent's work area, the files it was given and its tools as cards, joined by soft connectors that light up while in use.
"use client"
import * as React from "react"
import { FolderOpen } from "lucide-react"
import {
AiKitStyles,
AiStyle,
BrandTile,
cx,
Edge,
elbowPath,
Face,
Mark,
Roll,
type AiShape,
type AiStatus,
type AiTone,
} from "@/lib/ai-kit"
export type WorkbenchFileKind = "xlsx" | "docx" | "pdf" | "csv"
export interface WorkbenchFile {
name: string
kind: WorkbenchFileKind
size: string
}
export interface WorkbenchTool {
id: string
brand: string
name: string
/** What the agent may do with it, and where. */
scope: string
status: "ready" | "busy" | "done"
last: string
when: string
}
export interface WorkbenchStep {
id: string
text: string
status: AiStatus
}
export interface AgentWorkbenchProps {
person: { name: string; tone: AiTone; request: string }
agent: {
name: string
sub: string
tone: AiTone
shape?: AiShape
status: AiStatus
}
/** The agent's work area, newest last. */
steps: readonly WorkbenchStep[]
files: readonly WorkbenchFile[]
/** Name of the file being read. */
activeFile?: string
tools: readonly WorkbenchTool[]
/** Which connector carries work right now: "person", "files" or a tool id. */
live?: string | null
className?: string
}
const FILE_TONE: Record<WorkbenchFileKind, string> = {
xlsx: "#1f9d55",
docx: "#2f6fe4",
pdf: "#e0442f",
csv: "#0f9f8f",
}
const STATE_LABEL: Record<AiStatus, string> = {
todo: "Idle",
run: "Working",
ask: "Needs you",
done: "Done",
fail: "Failed",
}
const CSS = `
.aik-wb{width:min(100%,1100px);container-type:inline-size}
.aik-wb-grid{position:relative;display:grid;grid-template-columns:minmax(0,.86fr) minmax(0,1.22fr) minmax(0,.98fr);gap:64px 56px;align-items:start}
.aik-wb-tools{grid-column:1/-1;display:grid;grid-template-columns:repeat(var(--n),minmax(0,1fr));gap:22px}
.aik-wb-svg{position:absolute;inset:0;width:100%;height:100%;overflow:visible;pointer-events:none}
.aik-wb-port{fill:var(--aik-bg);stroke-width:1.6;transition:stroke var(--aik-d-panel)}
.aik-wb-node{--aik-r-shell:22px;--aik-rim:5px;position:relative;animation:aik-wb-in 520ms var(--aik-ease-soft) both;animation-delay:calc(var(--i,0)*80ms);transition:opacity var(--aik-d-panel)}
.aik-wb-card{display:grid;gap:14px;padding:16px}
.aik-wb-node .aik-beam{animation:aik-beam 2.4s linear infinite;--aik-beam-c:var(--c,var(--aik-blue))}
.aik-wb-top{display:flex;align-items:center;gap:12px;min-width:0}
.aik-wb-id{display:grid;grid-template-columns:minmax(0,1fr);line-height:20px;min-width:0;flex:1 1 auto}
.aik-wb-state,.aik-wb-pill{flex:none}
.aik-wb-id b{font-weight:600;font-size:15.5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.aik-wb-id small{font-size:13.5px;color:var(--aik-text-3);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.aik-wb-top > :last-child:not(.aik-wb-id){margin-left:auto}
.aik-wb-av{display:grid;place-items:center;width:38px;height:38px;flex:none;border-radius:50%;font-weight:600;font-size:14px;color:#fff;background:radial-gradient(120% 120% at 30% 20%,color-mix(in oklab,var(--c) 70%,#fff),var(--c) 60%);box-shadow:0 0 0 3px color-mix(in oklab,var(--c) 22%,transparent)}
.aik-wb-ask{padding:14px 16px;border-radius:16px;border-top-left-radius:6px;background:var(--aik-sunk);box-shadow:inset 0 0 0 1px var(--aik-line);font-size:15.5px;line-height:23px;min-height:96px}
.aik-wb-ask .aik-wb-caret{display:inline-block;width:2px;height:17px;margin-left:2px;vertical-align:-3px;background:var(--aik-blue);animation:aik-wb-blink 1s steps(1) infinite}
.aik-wb-state{display:inline-flex;align-items:center;gap:6px;height:28px;padding:0 10px 0 6px;border-radius:9px;font-size:13px;font-weight:500;color:var(--aik-text-3);background:var(--aik-raised);white-space:nowrap}
.aik-wb-state .aik-mark{transform:scale(.8)}
.aik-wb-state[data-s="run"]{color:var(--aik-blue);background:color-mix(in oklab,var(--aik-blue) 14%,transparent)}
.aik-wb-state[data-s="ask"]{color:var(--aik-amber);background:color-mix(in oklab,var(--aik-amber) 15%,transparent)}
.aik-wb-state[data-s="done"]{color:var(--aik-green);background:color-mix(in oklab,var(--aik-green) 14%,transparent)}
.aik-wb-area{display:grid;align-content:end;gap:4px;min-height:148px;padding:10px 12px;border-radius:14px;background:var(--aik-sunk);box-shadow:inset 0 0 0 1px var(--aik-line);overflow:hidden}
.aik-wb-step{display:flex;align-items:center;gap:10px;min-height:30px;font-size:14.5px;color:var(--aik-text-2);animation:aik-wb-step 420ms var(--aik-ease-soft) both}
.aik-wb-step[data-s="run"]{color:var(--aik-text)}
.aik-wb-step .aik-mark{transform:scale(.86)}
.aik-wb-step span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.aik-wb-folder{display:grid;place-items:center;width:44px;height:44px;flex:none;border-radius:13px;background:color-mix(in oklab,#4a9df8 16%,var(--aik-card));color:#4a9df8;box-shadow:inset 0 0 0 1px color-mix(in oklab,#4a9df8 28%,transparent)}
.aik-wb-files{display:grid;gap:4px}
.aik-wb-file{display:flex;align-items:center;gap:11px;height:44px;padding:0 10px;border-radius:12px;font-size:14.5px;transition:background var(--aik-d-panel),box-shadow var(--aik-d-panel)}
.aik-wb-file[data-on]{background:color-mix(in oklab,var(--aik-blue) 12%,transparent);box-shadow:inset 0 0 0 1px color-mix(in oklab,var(--aik-blue) 30%,transparent)}
.aik-wb-file b{font-weight:500;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.aik-wb-file em{margin-left:auto;font-style:normal;font-size:13px;color:var(--aik-text-3);white-space:nowrap}
.aik-wb-doc{position:relative;width:22px;height:26px;flex:none;border-radius:4px;background:var(--aik-card);box-shadow:inset 0 0 0 1.2px var(--aik-line-3)}
.aik-wb-doc::before{content:"";position:absolute;right:0;top:0;width:7px;height:7px;border-bottom-left-radius:3px;background:var(--aik-line-2)}
.aik-wb-doc i{position:absolute;left:-4px;bottom:3px;padding:0 3px;border-radius:3px;font:700 7.5px/12px var(--aik-sans);font-style:normal;color:#fff;background:var(--c);text-transform:uppercase}
.aik-wb-tool .aik-wb-card{gap:12px}
.aik-wb-tool[data-st="busy"]{--c:var(--aik-blue)}
.aik-wb-pill{height:26px;display:inline-flex;align-items:center;gap:6px;padding:0 9px;border-radius:8px;font-size:12.5px;font-weight:500;color:var(--aik-text-2);background:var(--aik-raised);white-space:nowrap}
.aik-wb-tool[data-st="busy"] .aik-wb-pill{color:var(--aik-blue);background:color-mix(in oklab,var(--aik-blue) 14%,transparent)}
.aik-wb-tool[data-st="done"] .aik-wb-pill{color:var(--aik-green);background:color-mix(in oklab,var(--aik-green) 14%,transparent)}
.aik-wb-last{display:flex;align-items:center;gap:10px;font-size:14px;color:var(--aik-text-2);min-width:0}
.aik-wb-last .aik-roll{min-width:0;flex:1}
.aik-wb-last em{font-style:normal;color:var(--aik-text-3);white-space:nowrap}
@keyframes aik-wb-in{from{opacity:0;transform:translateY(8px)}}
@keyframes aik-wb-step{from{opacity:0;transform:translateY(10px)}}
@keyframes aik-wb-blink{50%{opacity:0}}
@container (max-width:860px){
.aik-wb-grid{grid-template-columns:minmax(0,1fr);gap:22px}
.aik-wb-tools{grid-template-columns:minmax(0,1fr);gap:12px}
.aik-wb-svg{display:none}
}
@media (prefers-reduced-motion: reduce){.aik-wb-node,.aik-wb-step{animation:none}.aik-wb-caret{animation:none}}
`
function offsetBox(node: HTMLElement, stop: HTMLElement | null) {
let left = 0
let top = 0
let el: HTMLElement | null = node
while (el && el !== stop) {
left += el.offsetLeft
top += el.offsetTop
el = el.offsetParent as HTMLElement | null
}
return { left, top, width: node.offsetWidth, height: node.offsetHeight }
}
/**
* One agent at work: the person who asked, the agent's work area, the files
* it was given and the tools it may use, joined by soft connectors. The line
* to whatever the agent is using right now lights up.
*/
export function AgentWorkbench({
person,
agent,
steps,
files,
activeFile,
tools,
live,
className,
}: AgentWorkbenchProps) {
const root = React.useRef<HTMLDivElement>(null)
const grid = React.useRef<HTMLDivElement>(null)
const refs = React.useRef(new Map<string, HTMLElement>())
const [lines, setLines] = React.useState<
Array<{ id: string; d: string; a: [number, number]; b: [number, number] }>
>([])
const reg = (id: string) => (el: HTMLElement | null) => {
if (el) refs.current.set(id, el)
else refs.current.delete(id)
}
const measure = React.useCallback(() => {
const g = grid.current
if (!g || (root.current?.clientWidth ?? 0) <= 860) return setLines([])
const box = (id: string) => {
const el = refs.current.get(id)
return el ? offsetBox(el, g) : null
}
const p = box("person")
const ag = box("agent")
const f = box("files")
if (!p || !ag || !f) return
const y = ag.top + 62
const next: typeof lines = [
{
id: "person",
d: `M${p.left + p.width} ${y}H${ag.left}`,
a: [p.left + p.width, y],
b: [ag.left, y],
},
{
id: "files",
d: `M${ag.left + ag.width} ${y}H${f.left}`,
a: [ag.left + ag.width, y],
b: [f.left, y],
},
]
tools.forEach((tool, i) => {
const t = box(`tool-${tool.id}`)
if (!t) return
const ax = ag.left + (ag.width * (i + 1)) / (tools.length + 1)
const a: [number, number] = [ax, ag.top + ag.height]
const b: [number, number] = [t.left + t.width / 2, t.top]
next.push({
id: tool.id,
d: elbowPath(a[0], a[1], b[0], b[1], "v", 14),
a,
b,
})
})
setLines(next)
}, [tools])
React.useLayoutEffect(() => {
measure()
const observer = new ResizeObserver(() => measure())
if (root.current) observer.observe(root.current)
refs.current.forEach((el) => observer.observe(el))
return () => observer.disconnect()
}, [measure])
const mood =
agent.status === "run"
? "work"
: agent.status === "done"
? "happy"
: agent.status === "ask"
? "needs"
: "idle"
const shown = steps.slice(-4)
// The log is anchored to the bottom like a live feed. When a step lands,
// the earlier ones glide up (FLIP) instead of jumping a line.
const logRef = React.useRef<HTMLDivElement>(null)
const logTops = React.useRef(new Map<string, number>())
React.useLayoutEffect(() => {
const root = logRef.current
if (!root) return
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches
const next = new Map<string, number>()
root.querySelectorAll<HTMLElement>("[data-step]").forEach((el) => {
const key = el.dataset.step!
const top = el.offsetTop
const before = logTops.current.get(key)
if (before !== undefined && !reduce && Math.abs(before - top) > 1) {
el.animate(
[
{ transform: `translateY(${before - top}px)` },
{ transform: "none" },
],
{ duration: 420, easing: "cubic-bezier(.65,0,.15,1)" }
)
}
next.set(key, top)
})
logTops.current = next
})
return (
<div ref={root} className={cx("aik aik-wb", className)}>
<AiKitStyles />
<AiStyle id="agent-workbench" css={CSS} />
<div ref={grid} className="aik-wb-grid">
<svg className="aik-wb-svg" aria-hidden="true">
{lines.map((line) => {
const on = live === line.id
const tool = tools.find((t) => t.id === line.id)
const used = tool
? tool.status !== "ready"
: line.id === "person"
? true
: !!activeFile
return (
<g key={line.id}>
<Edge
d={line.d}
tone="blue"
state={on ? "live" : used ? "done" : "idle"}
duration={1.2}
/>
{[line.a, line.b].map((pt, i) => (
<circle
key={i}
className="aik-wb-port"
cx={pt[0]}
cy={pt[1]}
r={4}
stroke={
on || used ? "var(--aik-blue)" : "var(--aik-line-3)"
}
/>
))}
</g>
)
})}
</svg>
<div
ref={reg("person")}
className="aik-wb-node aik-shell"
style={{ "--i": 0 } as React.CSSProperties}
>
<div className="aik-surface aik-wb-card">
<div className="aik-wb-top">
<span
className="aik-wb-av"
style={
{
"--c": `var(--aik-f-${person.tone})`,
} as React.CSSProperties
}
>
{person.name
.split(" ")
.map((part) => part[0])
.join("")}
</span>
<span className="aik-wb-id">
<b>{person.name}</b>
<small>Asked just now</small>
</span>
</div>
<p className="aik-wb-ask">
{person.request}
{agent.status === "todo" ? (
<span className="aik-wb-caret" />
) : null}
</p>
</div>
</div>
<div
ref={reg("agent")}
className="aik-wb-node aik-shell"
style={
{
"--i": 1,
"--c": `var(--aik-f-${agent.tone})`,
} as React.CSSProperties
}
>
<div className="aik-surface aik-wb-card">
<span
className="aik-beam"
data-on={agent.status === "run" ? "" : undefined}
/>
<div className="aik-wb-top">
<Face
mood={mood}
shape={agent.shape ?? "blob"}
tone={agent.tone}
size={42}
/>
<span className="aik-wb-id">
<b>{agent.name}</b>
<small>{agent.sub}</small>
</span>
<span className="aik-wb-state" data-s={agent.status}>
<Mark status={agent.status} />
<Roll>{STATE_LABEL[agent.status]}</Roll>
</span>
</div>
<div className="aik-wb-area" aria-live="polite" ref={logRef}>
{shown.map((step) => (
<div
key={step.id}
data-step={step.id}
className="aik-wb-step"
data-s={step.status}
>
<Mark status={step.status} />
<span>{step.text}</span>
</div>
))}
</div>
</div>
</div>
<div
ref={reg("files")}
className="aik-wb-node aik-shell"
style={{ "--i": 2 } as React.CSSProperties}
>
<div className="aik-surface aik-wb-card">
<div className="aik-wb-top">
<span className="aik-wb-folder">
<FolderOpen size={21} />
</span>
<span className="aik-wb-id">
<b>Uploaded files</b>
<small>{files.length} files</small>
</span>
</div>
<div className="aik-wb-files">
{files.map((file) => (
<div
key={file.name}
className="aik-wb-file"
data-on={activeFile === file.name ? "" : undefined}
>
<span
className="aik-wb-doc"
style={
{ "--c": FILE_TONE[file.kind] } as React.CSSProperties
}
>
<i>{file.kind}</i>
</span>
<b>{file.name}</b>
<em>{file.size}</em>
</div>
))}
</div>
</div>
</div>
<div
className="aik-wb-tools"
style={{ "--n": tools.length } as React.CSSProperties}
>
{tools.map((tool, i) => (
<div
key={tool.id}
ref={reg(`tool-${tool.id}`)}
className="aik-wb-node aik-wb-tool aik-shell"
data-st={tool.status}
style={{ "--i": 3 + i } as React.CSSProperties}
>
<div className="aik-surface aik-wb-card">
<span
className="aik-beam"
data-on={tool.status === "busy" ? "" : undefined}
/>
<div className="aik-wb-top">
<BrandTile name={tool.brand} size={42} />
<span className="aik-wb-id">
<b>{tool.name}</b>
<small>{tool.scope}</small>
</span>
<span className="aik-wb-pill">
<Roll>
{tool.status === "busy"
? "In use"
: tool.status === "done"
? "Done"
: "Ready"}
</Roll>
</span>
</div>
<div className="aik-wb-last">
<Roll>{tool.last}</Roll>
<em>{tool.when}</em>
</div>
</div>
</div>
))}
</div>
</div>
</div>
)
}
Installation
One command adds agent-workbench and the shared AI Kit layer it is built on (tokens, faces, marks and brand icons). No animation library, light and dark built in.
$npx shadcn@latest add https://tweenui.dev/r/agent-workbench.json