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.

Installation

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
components/ui/ai-lanes-demo.tsx
"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

pnpm dlx shadcn@latest add https://tweenui.dev/r/ai-lanes.json

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

  • AiTimeline draws 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.
  • AiAgentCards is 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. Pass onSelectAgent to make the cards buttons.
  • AiHandoff shows work passing along a chain of agents. Set active to the handoff in flight and the packet travels the connector; raise done when it lands.

Props

AiTimeline

PropTypeDefaultDescription
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.
nownumberThe current position on the clock.
durationnumberlatest bar endThe length of the axis.
titlestringWhat the agents are working on.
ticksnumber5How many labels to draw along the axis.
formatTime(value: number) => stringm:ssFormats now and the tick labels.
onSelectBar(laneId: string, barId: string) => voidMakes bars pressable.

AiAgentCards

PropTypeDefaultDescription
agents{ id, name, status, task, progress?, time?, cost?, tone?, shape?, mood? }[]One card each. progress is 0 to 1.
onSelectAgent(id: string) => voidMakes each card a button.

AiHandoff

PropTypeDefaultDescription
agents{ id, name, label, mood?, tone?, shape? }[]The agents in the order work passes between them.
activenumber | nullnullIndex of the handoff in flight. 0 is first to second.
donenumber0How many handoffs have landed.
captionstringOne line saying what moved.
packetReactNodeWhat travels along the connector, usually an icon.