AI Lanes
Several agents at once: a timeline of lanes on a shared clock, a wall of agent cards, and a handoff where work travels from one face to the next.
"use client"
import * as React from "react"
import { ArrowRight, Hand } from "lucide-react"
import {
AiKitStyles,
AiStyle,
cx,
Face,
Mark,
Pill,
Roll,
type AiMood,
type AiShape,
type AiStatus,
type AiTone,
} from "@/lib/ai-kit"
const CSS = `
.aik-ln-tl{--ln-who:104px;width:min(100%,880px);display:grid;gap:10px}
.aik-ln-top{display:flex;align-items:center;gap:10px}
.aik-ln-top b{font-weight:600;font-size:13.5px}
.aik-ln-top .aik-ln-el{margin-left:auto;font:12px var(--aik-mono);color:var(--aik-text-2);font-variant-numeric:tabular-nums}
.aik-ln-axis{display:grid;grid-template-columns:var(--ln-who) minmax(0,1fr)}
.aik-ln-ticks{display:flex;justify-content:space-between;font:11px/14px var(--aik-mono);color:var(--aik-text-3)}
.aik-ln-body{position:relative}
.aik-ln-row{display:grid;grid-template-columns:var(--ln-who) minmax(0,1fr);align-items:center;height:44px;border-top:1px solid var(--aik-line)}
.aik-ln-who{display:flex;align-items:center;gap:9px;font-weight:500;font-size:13px;min-width:0}
.aik-ln-who .aik-face{--aik-fs:26px}
.aik-ln-track{position:relative;height:100%;background:linear-gradient(90deg,var(--aik-line) 1px,transparent 1px) 0 0/25% 100%}
.aik-ln-bar{position:absolute;top:10px;height:24px;left:calc(var(--l)*1%);width:calc(var(--w)*1% - 3px);border-radius:8px;overflow:hidden;display:flex;align-items:center;gap:5px;padding:0 8px;
font-size:11.5px;font-weight:500;white-space:nowrap;color:var(--aik-text-2);background:var(--aik-raised);box-shadow:inset 0 0 0 1px transparent;
transition:background var(--aik-d-state),color var(--aik-d-state),box-shadow var(--aik-d-state)}
.aik-ln-bar i{position:absolute;inset:0;background:color-mix(in oklab,var(--aik-blue) 26%,transparent);transform:scaleX(var(--p,0));transform-origin:0 50%;opacity:0;transition:transform 180ms linear}
.aik-ln-bar span{position:relative;min-width:0;overflow:hidden;text-overflow:ellipsis}
.aik-ln-bar .ic{position:relative;display:none}
.aik-ln-bar[data-s="todo"]{background:transparent;color:var(--aik-text-3);box-shadow:inset 0 0 0 1px var(--aik-line-2)}
.aik-ln-bar[data-s="run"]{background:color-mix(in oklab,var(--aik-blue) 10%,transparent);color:var(--aik-text);box-shadow:inset 0 0 0 1px color-mix(in oklab,var(--aik-blue) 45%,transparent)}
.aik-ln-bar[data-s="run"] i{opacity:1}
.aik-ln-bar[data-s="ask"]{background:var(--aik-amber-fill);color:rgb(0 0 0 / 84%)}
.aik-ln-bar[data-s="ask"] .ic{display:block}
.aik-ln-over{position:absolute;left:var(--ln-who);right:0;top:0;bottom:0;container-type:inline-size;pointer-events:none}
.aik-ln-now{position:absolute;top:-5px;bottom:0;left:-1px;inline-size:1.5px;background:var(--aik-text);transform:translateX(calc(var(--t,0)*1cqw));transition:transform 180ms linear}
.aik-ln-now::before{content:"";position:absolute;left:-3px;top:-3px;inline-size:7.5px;block-size:7.5px;border-radius:50%;background:var(--aik-text)}
@media (prefers-reduced-motion: reduce){.aik-ln-now,.aik-ln-bar i{transition:none}}
@container (max-width:600px){
.aik-ln-tl{--ln-who:38px}.aik-ln-who b{display:none}.aik-ln-bar{padding:0 5px}.aik-ln-bar span{display:none}.aik-ln-bar[data-s="ask"]{justify-content:center}
.aik-ln-ticks span:nth-child(even){display:none}
}
.aik-ln-cards{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px;width:min(100%,400px)}
.aik-ln-card{display:grid;gap:9px;padding:12px;border-radius:14px;background:var(--aik-card);box-shadow:var(--aik-sh-card);min-width:0}
.aik-ln-chead{display:flex;align-items:center;gap:8px;min-width:0}
.aik-ln-chead .aik-face{--aik-fs:30px}
.aik-ln-chead b{font-weight:600;font-size:13.5px;flex:1;min-width:0}
.aik-ln-card .aik-roll{inline-size:100%;font-size:12.5px;line-height:18px;color:var(--aik-text-2)}
.aik-ln-card[data-s="ask"] .aik-roll,.aik-ln-card[data-s="fail"] .aik-roll{color:var(--aik-c);font-weight:500}
.aik-ln-prog{height:3px;border-radius:2px;background:var(--aik-line-2);overflow:hidden}
.aik-ln-prog i{display:block;height:100%;border-radius:2px;background:var(--aik-c);transform:scaleX(var(--p,0));transform-origin:0 50%;transition:transform var(--aik-d-move) var(--aik-ease-out),background var(--aik-d-state)}
.aik-ln-meta{display:flex;justify-content:space-between;font:11px/14px var(--aik-mono);color:var(--aik-text-3);font-variant-numeric:tabular-nums}
.aik-ln-hand{display:grid;gap:22px;width:min(100%,380px);justify-items:center}
.aik-ln-chain{display:flex;align-items:flex-start;width:100%}
.aik-ln-node{display:grid;justify-items:center;gap:6px;inline-size:76px;flex:none}
.aik-ln-node .aik-face{--aik-fs:48px}
.aik-ln-node b{font-weight:500;font-size:12.5px;line-height:16px}
.aik-ln-node .aik-roll{inline-size:76px;justify-items:center;font-size:11.5px;line-height:15px;color:var(--aik-text-3)}
.aik-ln-conn{flex:1;min-width:22px;height:48px;position:relative;container-type:inline-size}
.aik-ln-conn::before{content:"";position:absolute;left:2px;right:2px;top:23px;height:2px;border-radius:1px;background:linear-gradient(90deg,var(--aik-line-3) 55%,transparent 0) 0 0/8px 100%;transition:background var(--aik-d-state)}
.aik-ln-conn[data-done]::before{background:var(--aik-text-3)}
.aik-ln-pk{position:absolute;left:0;top:12px;inline-size:24px;block-size:24px;border-radius:8px;display:grid;place-items:center;background:var(--aik-card);box-shadow:var(--aik-sh-pop);color:var(--aik-text);opacity:0;transition:opacity var(--aik-d-exit) var(--aik-ease-in)}
.aik-ln-conn[data-go] .aik-ln-pk{opacity:1;transform:translateX(calc(100cqw - 24px));transition:opacity var(--aik-d-state) var(--aik-ease-out),transform calc(var(--aik-d-move)*1.9) var(--aik-ease-move)}
.aik-ln-conn[data-go][data-fade] .aik-ln-pk{opacity:0}
.aik-ln-cap{display:inline-flex;align-items:center;gap:8px;height:32px;padding:0 12px;border-radius:10px;background:var(--aik-raised);font-size:13px;color:var(--aik-text-2);max-width:100%}
.aik-ln-cap .ic{color:var(--aik-text-3)}
.aik-ln-cap .aik-roll{line-height:20px}
.aik-ln-tlw{width:min(100%,880px);container-type:inline-size}
.aik-ln-tl{width:100%}
.aik-ln-top .aik-pill{min-width:0}
.aik-ln-who b{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-ln-cur{display:none;margin-left:auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px;font-weight:400;color:var(--aik-text-2)}
.aik-ln-track{container-type:inline-size}
.aik-ln-bar{border:0;font-family:inherit;text-align:left;cursor:default}
button.aik-ln-bar{cursor:pointer}
button.aik-ln-bar:hover{box-shadow:inset 0 0 0 1px var(--aik-line-3)}
.aik-ln-bar svg{position:relative}
.aik-ln-now{top:-1px;pointer-events:none}
.aik-ln-now::before{display:none}
.aik-ln-row:first-child .aik-ln-now{top:-5px}
.aik-ln-row:first-child .aik-ln-now::before{display:block}
.aik-ln-empty{padding:18px 0;border-top:1px solid var(--aik-line);color:var(--aik-text-3);font-size:13px}
@container (max-width:600px){
.aik-ln-tl{--ln-who:0px}
.aik-ln-axis{grid-template-columns:minmax(0,1fr)}
.aik-ln-axis > span{display:none}
.aik-ln-row{grid-template-columns:minmax(0,1fr);height:auto;gap:7px;padding:9px 0 10px}
.aik-ln-who b{display:block}
.aik-ln-cur{display:block}
.aik-ln-track{height:24px}
.aik-ln-bar{top:0}
.aik-ln-now,.aik-ln-row:first-child .aik-ln-now{top:-2px;bottom:-2px}
.aik-ln-row:first-child .aik-ln-now::before{display:none}
}
.aik-ln-cards{grid-template-columns:repeat(auto-fit,minmax(min(100%,150px),1fr))}
.aik-ln-card{text-align:left;font-family:inherit;transition:box-shadow var(--aik-d-state),transform var(--aik-d-press) var(--aik-ease-out)}
button.aik-ln-card{cursor:pointer}
button.aik-ln-card:hover{box-shadow:0 0 0 1px var(--aik-line-3),0 1px 2px rgb(12 12 24 / 4%)}
button.aik-ln-card:active{transform:scale(.985)}
.aik-ln-chead b{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-ln-conn[data-done] .aik-ln-pk{transform:translateX(calc(100cqw - 24px))}
.aik-ln-cap svg{color:var(--aik-text-3)}
.aik-ln-cap .aik-roll{min-width:0;overflow:hidden}
`
const clock = (seconds: number) =>
`${Math.floor(seconds / 60)}:${String(Math.floor(seconds % 60)).padStart(2, "0")}`
const clamp = (value: number, low: number, high: number) =>
Math.min(high, Math.max(low, value))
interface AgentLook {
/** Face colour: a named tone or any CSS colour. */
tone?: AiTone | (string & {})
shape?: AiShape
}
export interface AiLaneBar {
id: string
label: string
/** Where the bar starts and ends, in the same unit as `now`. */
start: number
end: number
/** A stretch where the lane waited for a person. Shown amber while current. */
ask?: boolean
}
export interface AiLane extends AgentLook {
id: string
name: string
bars: AiLaneBar[]
}
export interface AiTimelineProps extends React.HTMLAttributes<HTMLDivElement> {
/** What the agents are working on. */
title?: string
lanes: AiLane[]
/** The current position on the shared clock. */
now: number
/** The length of the axis. Defaults to the latest bar end. */
duration?: number
/** How many tick labels to draw along the axis. */
ticks?: number
/** Formats `now` and the tick values. Defaults to m:ss. */
formatTime?: (value: number) => string
/** Makes bars pressable. */
onSelectBar?: (laneId: string, barId: string) => void
}
function barStatus(bar: AiLaneBar, now: number): AiStatus {
if (now >= bar.end) return "done"
if (now >= bar.start) return bar.ask ? "ask" : "run"
return "todo"
}
/** One lane per agent on a shared clock, with a now-line that crosses them all. */
export function AiTimeline({
title,
lanes,
now,
duration,
ticks = 5,
formatTime = clock,
onSelectBar,
className,
...rest
}: AiTimelineProps) {
const total =
duration ??
Math.max(1, ...lanes.flatMap((lane) => lane.bars.map((bar) => bar.end)))
const at = clamp(now, 0, total)
const pct = (value: number) => (clamp(value, 0, total) / total) * 100
let asking = 0
let working = 0
let finished = 0
const rows = lanes.map((lane) => {
const first = lane.bars[0]
const last = lane.bars[lane.bars.length - 1]
let mood: AiMood = !first || at < first.start ? "sleep" : "think"
let current: AiLaneBar | undefined
for (const bar of lane.bars) {
const status = barStatus(bar, at)
if (status === "run" || status === "ask") {
current = bar
mood = status === "ask" ? "needs" : "work"
if (status === "ask") asking++
else working++
}
}
if (last && at >= last.end) {
mood = "happy"
finished++
}
return { lane, mood, current, done: Boolean(last && at >= last.end) }
})
const allDone = lanes.length > 0 && finished === lanes.length
const status: AiStatus = asking ? "ask" : allDone ? "done" : "run"
const summary = asking
? asking === 1
? "1 lane needs you"
: `${asking} lanes need you`
: allDone
? `All ${lanes.length} lanes done`
: `${working} agent${working === 1 ? "" : "s"} working`
const steps = Math.max(2, ticks)
return (
<div {...rest} className={cx("aik aik-ln-tlw", className)}>
<AiKitStyles />
<AiStyle id="ai-lanes" css={CSS} />
<div className="aik-ln-tl">
<div className="aik-ln-top">
{title ? <b>{title}</b> : null}
{lanes.length > 0 ? (
<Pill status={status}>
<Mark status={status} />
<span role="status">{summary}</span>
</Pill>
) : null}
<span className="aik-ln-el">{formatTime(at)}</span>
</div>
<div className="aik-ln-axis" aria-hidden="true">
<span />
<div className="aik-ln-ticks">
{Array.from({ length: steps }, (_, index) => (
<span key={index}>
{formatTime((total * index) / (steps - 1))}
</span>
))}
</div>
</div>
<div className="aik-ln-body">
{lanes.length === 0 ? (
<p className="aik-ln-empty">No agents are running yet.</p>
) : null}
{rows.map(({ lane, mood, current, done }) => (
<div key={lane.id} className="aik-ln-row">
<div className="aik-ln-who">
<Face
size={26}
mood={mood}
shape={lane.shape ?? "blob"}
tone={lane.tone ?? "blue"}
/>
<b>{lane.name}</b>
<span className="aik-ln-cur">
{current ? current.label : done ? "Done" : "Waiting"}
</span>
</div>
<div className="aik-ln-track">
{lane.bars.map((bar) => {
const state = barStatus(bar, at)
const span = Math.max(bar.end - bar.start, 0.0001)
const style = {
"--l": pct(bar.start),
"--w": pct(bar.end) - pct(bar.start),
"--p":
state === "run" || state === "ask"
? clamp((at - bar.start) / span, 0, 1).toFixed(3)
: 0,
} as React.CSSProperties
const body = (
<>
<i />
{bar.ask && state === "ask" ? <Hand size={13} /> : null}
<span>{bar.label}</span>
</>
)
return onSelectBar ? (
<button
key={bar.id}
type="button"
className="aik-ln-bar"
data-s={state}
style={style}
title={bar.label}
onClick={() => onSelectBar(lane.id, bar.id)}
>
{body}
</button>
) : (
<div
key={bar.id}
className="aik-ln-bar"
data-s={state}
style={style}
title={bar.label}
>
{body}
</div>
)
})}
<i
className="aik-ln-now"
style={{ "--t": pct(at) } as React.CSSProperties}
/>
</div>
</div>
))}
</div>
</div>
</div>
)
}
export interface AiAgentCard extends AgentLook {
id: string
name: string
status: AiStatus
/** What the agent is doing. Rolls over in place when it changes. */
task: string
/** Progress from 0 to 1. */
progress?: number
/** Elapsed time, already formatted. */
time?: string
/** Cost so far, already formatted. */
cost?: string
/** Overrides the mood derived from `status`. */
mood?: AiMood
}
export interface AiAgentCardsProps extends React.HTMLAttributes<HTMLDivElement> {
agents: AiAgentCard[]
/** Makes each card pressable. */
onSelectAgent?: (id: string) => void
}
const STATUS_MOOD: Record<AiStatus, AiMood> = {
todo: "sleep",
run: "work",
ask: "needs",
done: "happy",
fail: "oops",
}
/** A wall of agent cards: face, task line, progress, time and cost. */
export function AiAgentCards({
agents,
onSelectAgent,
className,
...rest
}: AiAgentCardsProps) {
return (
<div {...rest} className={cx("aik aik-ln-cards", className)}>
<AiKitStyles />
<AiStyle id="ai-lanes" css={CSS} />
{agents.map((agent) => {
const body = (
<>
<div className="aik-ln-chead">
<Face
size={30}
mood={agent.mood ?? STATUS_MOOD[agent.status]}
shape={agent.shape ?? "blob"}
tone={agent.tone ?? "blue"}
/>
<b>{agent.name}</b>
<Mark status={agent.status} />
</div>
<Roll>{agent.task}</Roll>
<div className="aik-ln-prog">
<i
style={
{
"--p": clamp(agent.progress ?? 0, 0, 1),
} as React.CSSProperties
}
/>
</div>
{agent.time || agent.cost ? (
<div className="aik-ln-meta">
<span>{agent.time}</span>
<span>{agent.cost}</span>
</div>
) : null}
</>
)
return onSelectAgent ? (
<button
key={agent.id}
type="button"
className="aik-ln-card"
data-s={agent.status}
onClick={() => onSelectAgent(agent.id)}
>
{body}
</button>
) : (
<div key={agent.id} className="aik-ln-card" data-s={agent.status}>
{body}
</div>
)
})}
</div>
)
}
export interface AiHandoffAgent extends AgentLook {
id: string
name: string
/** A short line under the name. */
label: string
mood?: AiMood
}
export interface AiHandoffProps extends React.HTMLAttributes<HTMLDivElement> {
/** The agents in the order work passes between them. */
agents: AiHandoffAgent[]
/** How many handoffs have already landed, counted from the first agent. */
done?: number
/** Index of the handoff in flight (0 is first to second agent), or null. */
active?: number | null
/** One line saying what moved. Rolls over when it changes. */
caption?: string
/** What travels along the connector. */
packet?: React.ReactNode
}
/** Work as a packet that travels from one agent's face to the next. */
export function AiHandoff({
agents,
done = 0,
active = null,
caption,
packet,
className,
...rest
}: AiHandoffProps) {
return (
<div {...rest} className={cx("aik aik-ln-hand", className)}>
<AiKitStyles />
<AiStyle id="ai-lanes" css={CSS} />
<div className="aik-ln-chain">
{agents.map((agent, index) => (
<React.Fragment key={agent.id}>
{index > 0 ? (
<div
className="aik-ln-conn"
data-done={index - 1 < done ? "" : undefined}
data-go={active === index - 1 ? "" : undefined}
aria-hidden="true"
>
<i className="aik-ln-pk">{packet}</i>
</div>
) : null}
<div className="aik-ln-node">
<Face
size={48}
mood={agent.mood ?? "idle"}
shape={agent.shape ?? "blob"}
tone={agent.tone ?? "blue"}
/>
<b>{agent.name}</b>
<Roll>{agent.label}</Roll>
</div>
</React.Fragment>
))}
</div>
{caption ? (
<div className="aik-ln-cap" role="status">
<ArrowRight size={14} />
<Roll>{caption}</Roll>
</div>
) : null}
</div>
)
}
Installation
One command adds ai-lanes 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/ai-lanes.json
ai-lanes-demo
"use client"
import * as React from "react"
import { CheckCheck, FileCode } from "lucide-react"
import { AiDemo } from "@/lib/ai-demo"
import { useAiLoop, type AiMood, type AiStatus } from "@/lib/ai-kit"
import {
AiAgentCards,
AiHandoff,
AiTimeline,
type AiAgentCard,
type AiLane,
} from "@/registry/tween/ai-lanes"
const clock = (seconds: number) =>
`${Math.floor(seconds / 60)}:${String(Math.floor(seconds % 60)).padStart(2, "0")}`
const LANES: AiLane[] = [
{
id: "mira",
name: "Mira",
shape: "orb",
tone: "blue",
bars: [
{ id: "plan", label: "Plan", start: 0, end: 22 },
{ id: "build", label: "Build pricing section", start: 22, end: 52 },
{ id: "publish", label: "Publish?", start: 52, end: 64, ask: true },
{ id: "ship", label: "Ship", start: 64, end: 90 },
],
},
{
id: "odo",
name: "Odo",
shape: "blob",
tone: "violet",
bars: [
{ id: "tests", label: "Write 24 tests", start: 8, end: 42 },
{ id: "fix", label: "Fix 3 failures", start: 42, end: 68 },
{ id: "again", label: "Run again", start: 68, end: 88 },
],
},
{
id: "juno",
name: "Juno",
shape: "arch",
tone: "amber",
bars: [
{ id: "hero", label: "Hero image", start: 20, end: 38 },
{ id: "crop", label: "Crop?", start: 38, end: 48, ask: true },
{ id: "export", label: "Export three sizes", start: 48, end: 82 },
],
},
{
id: "pim",
name: "Pim",
shape: "leaf",
tone: "green",
bars: [
{ id: "docs", label: "Docs page", start: 30, end: 56 },
{ id: "registry", label: "Registry build", start: 60, end: 92 },
],
},
]
function Timeline() {
const root = React.useRef<HTMLDivElement>(null)
const [now, setNow] = React.useState(58)
const [hands, setHands] = React.useState(false)
useAiLoop(
root,
async ({ sleep }) => {
for (let at = 0; at <= 100; at += 2) {
setNow(at)
await sleep(180)
}
await sleep(900)
},
{ gap: 700, enabled: !hands, still: () => setNow(58) }
)
return (
<div
ref={root}
style={{ display: "grid", justifyItems: "center", width: "100%" }}
onPointerDown={() => setHands(true)}
>
<AiTimeline
title="Pricing section"
lanes={LANES}
now={now}
duration={100}
formatTime={(value) => clock(value * 0.8)}
onSelectBar={(laneId, barId) => {
const bar = LANES.find((lane) => lane.id === laneId)?.bars.find(
(item) => item.id === barId
)
if (bar) setNow((bar.start + bar.end) / 2)
}}
/>
</div>
)
}
type Frame = [AiStatus, AiMood, string, number]
const FRAMES: Frame[][] = [
[
["run", "think", "Planning the section", 0.1],
["todo", "sleep", "Queued", 0],
["run", "work", "Making the hero image", 0.2],
["todo", "sleep", "Queued", 0],
],
[
["run", "work", "Building pricing", 0.35],
["run", "work", "Writing 24 tests", 0.2],
["run", "work", "Exporting three sizes", 0.6],
["todo", "sleep", "Queued", 0],
],
[
["run", "work", "Wiring the toggle", 0.6],
["run", "work", "Running 24 tests", 0.55],
["ask", "needs", "Pick a crop", 0.6],
["run", "think", "Reading the docs", 0.15],
],
[
["ask", "needs", "Publish this?", 0.8],
["fail", "oops", "3 tests failed", 0.55],
["run", "work", "Applying the crop", 0.85],
["run", "work", "Writing the docs", 0.5],
],
[
["run", "work", "Shipping", 0.95],
["run", "work", "Fixing 3 failures", 0.8],
["done", "happy", "Done", 1],
["run", "work", "Building the registry", 0.85],
],
[
["done", "happy", "Shipped", 1],
["done", "happy", "24 tests pass", 1],
["done", "happy", "Done", 1],
["done", "happy", "Docs published", 1],
],
]
const CREW = [
{ id: "mira", name: "Mira", tone: "blue", shape: "orb" },
{ id: "odo", name: "Odo", tone: "violet", shape: "blob" },
{ id: "juno", name: "Juno", tone: "amber", shape: "arch" },
{ id: "pim", name: "Pim", tone: "green", shape: "leaf" },
] as const
/** Seconds an agent has been busy by the end of `frame`: eight per frame it was not queued or done. */
function busySeconds(agent: number, frame: number) {
let seconds = 0
for (let at = 0; at <= frame; at++) {
const status = FRAMES[at]?.[agent]?.[0]
if (status === "run" || status === "ask" || status === "fail") seconds += 8
}
return seconds
}
function Cards() {
const root = React.useRef<HTMLDivElement>(null)
const [frame, setFrame] = React.useState(3)
const [hands, setHands] = React.useState(false)
useAiLoop(
root,
async ({ sleep }) => {
for (let at = 0; at < FRAMES.length; at++) {
setFrame(at)
await sleep(at === FRAMES.length - 1 ? 1900 : 1600)
}
},
{ gap: 400, enabled: !hands, still: () => setFrame(3) }
)
const agents: AiAgentCard[] = CREW.map((agent, index) => {
const [status, mood, task, progress] = FRAMES[frame]?.[index] ?? [
"todo",
"sleep",
"Queued",
0,
]
const seconds = busySeconds(index, frame)
return {
...agent,
status,
mood,
task,
progress,
time: clock(seconds),
cost: `$${(seconds * 0.00375).toFixed(2)}`,
}
})
return (
<div
ref={root}
style={{ display: "grid", width: "min(100%, 400px)" }}
onPointerDown={() => setHands(true)}
>
<AiAgentCards
agents={agents}
onSelectAgent={() =>
setFrame((current) => (current + 1) % FRAMES.length)
}
/>
</div>
)
}
interface Scene {
moods: [AiMood, AiMood, AiMood]
labels: [string, string, string]
done: number
active: number | null
caption: string
hold: number
}
const SCENES: Scene[] = [
{
moods: ["work", "sleep", "sleep"],
labels: ["Writing tests", "Waiting", "Waiting"],
done: 0,
active: null,
caption: "Odo is writing 24 tests",
hold: 2000,
},
{
moods: ["happy", "sleep", "sleep"],
labels: ["Tests written", "Waiting", "Waiting"],
done: 0,
active: 0,
caption: "Odo is writing 24 tests",
hold: 900,
},
{
moods: ["happy", "work", "sleep"],
labels: ["Tests written", "Reviewing", "Waiting"],
done: 1,
active: null,
caption: "Odo handed 24 tests to Juno",
hold: 2100,
},
{
moods: ["happy", "happy", "sleep"],
labels: ["Tests written", "Approved", "Waiting"],
done: 1,
active: 1,
caption: "Odo handed 24 tests to Juno",
hold: 900,
},
{
moods: ["happy", "happy", "work"],
labels: ["Tests written", "Approved", "Publishing"],
done: 2,
active: null,
caption: "Juno handed the review to Pim",
hold: 2100,
},
{
moods: ["happy", "happy", "happy"],
labels: ["Tests written", "Approved", "Published"],
done: 2,
active: null,
caption: "Shipped by three agents in 0:48",
hold: 1700,
},
]
function Handoff() {
const root = React.useRef<HTMLDivElement>(null)
const [at, setAt] = React.useState(2)
const [hands, setHands] = React.useState(false)
useAiLoop(
root,
async ({ sleep }) => {
for (let index = 0; index < SCENES.length; index++) {
setAt(index)
await sleep(SCENES[index]?.hold ?? 1500)
}
},
{ gap: 500, enabled: !hands, still: () => setAt(2) }
)
const scene = SCENES[at] ?? SCENES[0]!
return (
<div
ref={root}
style={{ display: "grid", width: "min(100%, 380px)" }}
onPointerDown={() => {
setHands(true)
setAt((current) => (current + 1) % SCENES.length)
}}
>
<AiHandoff
agents={[
{
id: "odo",
name: "Odo",
tone: "violet",
shape: "blob",
mood: scene.moods[0],
label: scene.labels[0],
},
{
id: "juno",
name: "Juno",
tone: "amber",
shape: "arch",
mood: scene.moods[1],
label: scene.labels[1],
},
{
id: "pim",
name: "Pim",
tone: "green",
shape: "leaf",
mood: scene.moods[2],
label: scene.labels[2],
},
]}
done={scene.done}
active={scene.active}
caption={scene.caption}
packet={
scene.active === 1 || scene.done > 1 ? (
<CheckCheck size={12} />
) : (
<FileCode size={12} />
)
}
/>
</div>
)
}
export function AiLanesDemo({ only }: { only?: string }) {
return (
<AiDemo
only={only}
tabs={[
{ name: "Timeline", node: <Timeline /> },
{ name: "Agent cards", node: <Cards /> },
{ name: "Handoff", node: <Handoff /> },
]}
/>
)
}
Installation
Usage
import { AiAgentCards, AiHandoff, AiTimeline } from "@/components/ui/ai-lanes"<AiTimeline
title="Pricing section"
now={elapsedSeconds}
duration={80}
lanes={[
{
id: "mira",
name: "Mira",
shape: "orb",
bars: [
{ id: "plan", label: "Plan", start: 0, end: 18 },
{ id: "build", label: "Build pricing section", start: 18, end: 42 },
{ id: "publish", label: "Publish?", start: 42, end: 51, ask: true },
],
},
]}
/>Bar states are derived from now: a bar is queued before its start, working (or amber, when ask is set) until its end, and done after. You only move the clock.
Versions
AiTimelinedraws one lane per agent on a shared axis with a now-line. The summary pill counts who is working and who is waiting for you. Below 600px each lane stacks, and the current task is written beside the agent's name.AiAgentCardsis a wall of cards: a face that acts out the status, a task line that rolls over in place, a progress line, and time and cost in mono. PassonSelectAgentto make the cards buttons.AiHandoffshows work passing along a chain of agents. Setactiveto the handoff in flight and the packet travels the connector; raisedonewhen it lands.
Props
AiTimeline
| Prop | Type | Default | Description |
|---|---|---|---|
lanes | { id, name, tone?, shape?, bars }[] | One entry per agent. | |
bars | { id, label, start, end, ask? }[] | Work on a lane, in the same unit as now. | |
now | number | The current position on the clock. | |
duration | number | latest bar end | The length of the axis. |
title | string | What the agents are working on. | |
ticks | number | 5 | How many labels to draw along the axis. |
formatTime | (value: number) => string | m:ss | Formats now and the tick labels. |
onSelectBar | (laneId: string, barId: string) => void | Makes bars pressable. |
AiAgentCards
| Prop | Type | Default | Description |
|---|---|---|---|
agents | { id, name, status, task, progress?, time?, cost?, tone?, shape?, mood? }[] | One card each. progress is 0 to 1. | |
onSelectAgent | (id: string) => void | Makes each card a button. |
AiHandoff
| Prop | Type | Default | Description |
|---|---|---|---|
agents | { id, name, label, mood?, tone?, shape? }[] | The agents in the order work passes between them. | |
active | number | null | null | Index of the handoff in flight. 0 is first to second. |
done | number | 0 | How many handoffs have landed. |
caption | string | One line saying what moved. | |
packet | ReactNode | What travels along the connector, usually an icon. |