AI Steps
An agent run you can follow: a live rail whose running step opens to show its output, a track a comet travels from node to node, and a depth stack of step cards.
"use client"
import * as React from "react"
import { ChevronDown, FileCode } from "lucide-react"
import {
AiKitStyles,
AiStyle,
cx,
Face,
Pill,
Roll,
type AiMood,
type AiShape,
type AiStatus,
type AiTone,
} from "@/lib/ai-kit"
const CSS = `
.aik-tl-mark{position:relative;display:inline-block;width:20px;height:20px;flex:none;border-radius:50%}
.aik-tl-mark::before,.aik-tl-mark::after{content:"";position:absolute;inset:0;border-radius:50%}
.aik-tl-mark::before{inset:1px;border:1.5px dashed var(--aik-line-3);transition:background var(--aik-d-state),border-color var(--aik-d-state)}
.aik-tl-mark[data-s="run"]::before{inset:0;border:2px solid color-mix(in oklab,var(--aik-blue) 20%,transparent);border-top-color:var(--aik-blue);border-right-color:var(--aik-blue);animation:aik-spin .9s linear infinite}
.aik-tl-mark[data-s="ask"]::before{border:1.5px dashed var(--aik-amber)}
.aik-tl-mark[data-s="ask"]::after{inset:7px;background:var(--aik-amber)}
.aik-tl-mark[data-s="done"]::before{inset:0;border:0;background:var(--aik-green)}
.aik-tl-mark[data-s="fail"]::before{inset:0;border:0;background:var(--aik-red)}
.aik-tl-mark[data-s="done"]::after,.aik-tl-mark[data-s="fail"]::after{border-radius:0;background:var(--aik-on-fill);-webkit-mask:var(--aik-m-check) center/100% no-repeat;mask:var(--aik-m-check) center/100% no-repeat;animation:aik-tl-draw 260ms var(--aik-ease-out) both}
.aik-tl-mark[data-s="fail"]::after{-webkit-mask-image:var(--aik-m-x);mask-image:var(--aik-m-x)}
@keyframes aik-tl-draw{from{clip-path:inset(0 100% 0 0)}to{clip-path:inset(0 0 0 0)}}
@keyframes aik-tl-rise{from{opacity:0;transform:translateY(8px)}}
@media (prefers-reduced-motion: reduce){.aik-tl-mark::before,.aik-tl-mark::after{animation:none!important}}
.aik-tl-rail{--aik-r-shell:24px;--aik-rim:5px;width:min(100%,560px);container-type:inline-size}
.aik-tl-rcard{overflow:hidden}
.aik-tl-head{display:flex;align-items:center;gap:12px;width:100%;height:54px;padding:0 14px 0 16px;text-align:left;font-size:15px}
.aik-tl-head > b{flex:1;min-width:0;font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-tl-head > b span{font-weight:400;color:var(--aik-text-2)}
.aik-tl-clock{font:12.5px var(--aik-mono);color:var(--aik-text-3);font-variant-numeric:tabular-nums;white-space:nowrap}
.aik-tl-chev{color:var(--aik-text-3);transition:transform var(--aik-d-panel) var(--aik-ease-out)}
.aik-tl-rail[data-open] .aik-tl-chev{transform:rotate(180deg)}
.aik-tl-fold{display:grid;grid-template-rows:0fr;transition:grid-template-rows 420ms var(--aik-ease-move)}
.aik-tl-fold > div{min-height:0;overflow:hidden}
.aik-tl-fold[data-open]{grid-template-rows:1fr}
.aik-tl-list{padding:8px 16px 14px;border-top:1px solid var(--aik-line)}
.aik-tl-row{position:relative;display:grid;grid-template-columns:20px minmax(0,1fr) auto;column-gap:14px;align-items:start;padding:8px 0;animation:aik-tl-rise var(--aik-d-enter) var(--aik-ease-out) both;animation-delay:calc(min(var(--i),8)*30ms)}
.aik-tl-row::before{content:"";position:absolute;left:9.25px;top:32px;bottom:-4px;width:1.5px;border-radius:1px;background:var(--aik-line-2);transition:background var(--aik-d-panel) var(--aik-ease-out)}
.aik-tl-row:last-child::before{display:none}
.aik-tl-row[data-s="done"]::before{background:color-mix(in oklab,var(--aik-green) 70%,transparent)}
.aik-tl-t{font-size:15px;line-height:20px;transition:color var(--aik-d-state)}
.aik-tl-row[data-s="todo"] .aik-tl-t{color:var(--aik-text-3)}
.aik-tl-row[data-s="run"] .aik-tl-t{font-weight:500}
.aik-tl-row[data-s="fail"] .aik-tl-t{text-decoration:line-through;color:var(--aik-text-2)}
.aik-tl-sub{display:block;font:12.5px/18px var(--aik-mono);color:var(--aik-text-3)}
.aik-tl-meta{font:12.5px/20px var(--aik-mono);color:var(--aik-text-3);font-variant-numeric:tabular-nums;white-space:nowrap}
.aik-tl-row[data-s="run"] .aik-tl-meta{color:var(--aik-blue)}
.aik-tl-live{grid-column:2/-1}
.aik-tl-live > div > div{padding-top:10px}
.aik-tl-log{display:grid;gap:4px;padding:10px 12px 12px;border-radius:12px;background:var(--aik-sunk);box-shadow:inset 0 0 0 1px var(--aik-line);font:12.5px/19px var(--aik-mono);color:var(--aik-text-2);min-width:0}
.aik-tl-logh{display:flex;align-items:center;gap:8px;padding-bottom:4px;white-space:nowrap;overflow:hidden;color:var(--aik-text);font-weight:500}
.aik-tl-logh span{margin-left:auto;color:var(--aik-text-3);font-weight:400;font-variant-numeric:tabular-nums}
.aik-tl-log code{display:block;white-space:pre;overflow:hidden;text-overflow:ellipsis;animation:aik-in var(--aik-d-enter) var(--aik-ease-out) both}
.aik-tl-bar{display:block;height:3px;margin-top:6px;border-radius:2px;background:var(--aik-line-2);overflow:hidden}
.aik-tl-bar::after{content:"";display:block;height:100%;border-radius:2px;background:var(--aik-blue);transform-origin:0 50%;transform:scaleX(var(--p,0));transition:transform 420ms var(--aik-ease-out)}
@container (max-width:430px){.aik-tl-list .aik-tl-sub{display:none}.aik-tl-list{padding:6px 12px 10px}.aik-tl-row{column-gap:10px}}
.aik-tl-comet{--aik-r-shell:26px;--aik-rim:5px;width:min(100%,560px);container-type:inline-size}
.aik-tl-ccard{display:grid;gap:26px;padding:30px 30px 24px}
.aik-tl-ctop{display:grid;grid-template-columns:auto minmax(0,1fr) auto;gap:14px;align-items:center}
.aik-tl-ctop{gap:18px}
.aik-tl-ctop h4{font-size:23px;line-height:30px;font-weight:600;letter-spacing:-.02em}
.aik-tl-ctop .aik-tl-clock{align-self:start;font-size:13.5px;line-height:30px}
.aik-tl-note{min-height:44px;padding:12px 14px;border-radius:12px;background:var(--aik-sunk);box-shadow:inset 0 0 0 1px var(--aik-line);font-size:14.5px;line-height:20px;color:var(--aik-text-2)}
.aik-tl-note .aik-roll{display:grid;white-space:normal}
.aik-tl-note .aik-roll > *{white-space:normal}
.aik-tl-labels{position:relative;height:34px;margin:-14px 10px 0}
.aik-tl-labels span{position:absolute;top:0;left:calc(var(--f)*100%);width:92px;margin-left:-46px;text-align:center;font-size:12px;line-height:16px;color:var(--aik-text-3);transition:color var(--aik-d-panel)}
.aik-tl-labels span[data-on]{color:var(--aik-text);font-weight:500}
.aik-tl-labels span:first-child{margin-left:-10px;text-align:left}
.aik-tl-labels span:last-child{margin-left:-82px;text-align:right}
.aik-tl-ctop h4 .aik-roll{max-width:100%;line-height:30px}
.aik-tl-ctop p{font:12.5px/18px var(--aik-mono);color:var(--aik-text-3)}
.aik-tl-track{position:relative;height:20px;margin:0 10px;container-type:inline-size}
.aik-tl-line,.aik-tl-fill{position:absolute;left:0;right:0;top:9px;height:2px;border-radius:1px;background:var(--aik-line-2)}
.aik-tl-fill{background:var(--aik-green);transform-origin:0 50%;transform:scaleX(var(--at,0));transition:transform 620ms var(--aik-ease-move)}
.aik-tl-node{position:absolute;top:0;left:calc(var(--f)*100%);display:grid;place-items:center;width:20px;height:20px;margin-left:-10px;border-radius:50%;background:var(--aik-card)}
.aik-tl-node::after{content:"";position:absolute;inset:-9px}
.aik-tl-head2{position:absolute;top:4px;left:-6px;width:12px;height:12px;border-radius:50%;background:var(--aik-blue);box-shadow:0 0 0 4px color-mix(in oklab,var(--aik-blue) 20%,transparent),0 0 16px 3px color-mix(in oklab,var(--aik-blue) 55%,transparent);transform:translateX(calc(var(--at,0)*100cqw));transition:transform 620ms var(--aik-ease-move),opacity var(--aik-d-panel);pointer-events:none}
.aik-tl-head2::before{content:"";position:absolute;right:8px;top:4px;width:64px;height:4px;border-radius:2px;background:linear-gradient(90deg,transparent,var(--aik-blue))}
.aik-tl-comet[data-s="done"] .aik-tl-head2,.aik-tl-comet[data-s="todo"] .aik-tl-head2{opacity:0}
.aik-tl-cfoot{display:flex;align-items:center;justify-content:space-between;gap:12px;color:var(--aik-text-3);font-size:12.5px}
@container (max-width:460px){.aik-tl-ccard{padding:18px 16px 16px;gap:20px}.aik-tl-ctop{gap:12px}.aik-tl-ctop h4{font-size:17px;line-height:24px}.aik-tl-labels{display:none}.aik-tl-ctop h4 .aik-roll > *{white-space:normal}.aik-tl-cfoot > span:last-child{display:none}.aik-tl-ctop .aik-face{--aik-fs:40px!important}}
@media (prefers-reduced-motion: reduce){.aik-tl-head2,.aik-tl-fill{transition:none}}
.aik-tl-stack{--aik-r-shell:26px;--aik-rim:5px;width:min(100%,540px);container-type:inline-size}
.aik-tl-scard{display:grid;gap:18px;padding:20px 20px 22px}
.aik-tl-card .aik-tl-mark{margin-top:1px}
.aik-tl-shead{display:flex;align-items:baseline;gap:10px;padding:0 4px;font-size:15px;font-weight:600}
.aik-tl-shead .aik-roll{font:500 13px var(--aik-mono);color:var(--aik-text-2);font-variant-numeric:tabular-nums}
.aik-tl-shead .aik-tl-clock{margin-left:auto}
.aik-tl-well{position:relative;height:206px;border-radius:16px;background:var(--aik-sunk);box-shadow:inset 0 0 0 1px var(--aik-line)}
.aik-tl-card{position:absolute;left:16px;right:16px;top:16px;display:grid;grid-template-columns:20px minmax(0,1fr) auto;gap:5px 14px;align-content:start;height:136px;padding:20px 20px 16px;border-radius:14px;background:var(--aik-card);box-shadow:0 0 0 1px var(--aik-line-2),0 2px 6px rgb(12 12 24 / 6%);text-align:left;transform-origin:50% 0;
transform:translateY(calc(var(--k)*17px)) scale(calc(1 - var(--k)*.06));opacity:calc(1 - var(--k)*.22);z-index:calc(10 - var(--k));
transition:transform 520ms var(--aik-ease-move),opacity 520ms var(--aik-ease-move)}
.aik-tl-card[data-k="hid"]{--k:3;opacity:0;pointer-events:none}
.aik-tl-card[data-k="out"]{transform:translateY(-34px) scale(.96);opacity:0;z-index:11;pointer-events:none;transition-delay:420ms}
.aik-tl-card b{font-size:18px;line-height:22px;font-weight:600;letter-spacing:-.01em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-tl-card p{grid-column:2/-1;padding-top:4px;font-size:14.5px;line-height:20px;color:var(--aik-text-2);display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
.aik-tl-card .aik-tl-sub{grid-column:2/-1}
.aik-tl-segs{display:flex;gap:4px;height:8px;padding:0 4px}
.aik-tl-segs i{flex:1;border-radius:4px;background:var(--aik-line-2);position:relative;overflow:hidden;transition:flex-grow 520ms var(--aik-ease-move),background var(--aik-d-panel)}
.aik-tl-segs i[data-s="done"]{background:var(--aik-green)}
.aik-tl-segs i[data-s="fail"]{background:var(--aik-red)}
.aik-tl-segs i[data-s="ask"]{background:var(--aik-amber-fill)}
.aik-tl-segs i[data-s="run"]{flex-grow:1.8;background:color-mix(in oklab,var(--aik-blue) 22%,transparent)}
.aik-tl-segs i[data-s="run"]::after{content:"";position:absolute;inset:0;border-radius:inherit;background:var(--aik-blue);transform-origin:0 50%;animation:aik-tl-grow 2.4s var(--aik-ease-out) both}
@keyframes aik-tl-grow{from{transform:scaleX(.06)}to{transform:scaleX(.92)}}
@container (max-width:430px){.aik-tl-scard{padding:14px 14px 16px}.aik-tl-card{left:10px;right:10px;top:10px;padding:16px 14px;gap:4px 10px}.aik-tl-card b{font-size:16px;line-height:21px;white-space:normal;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}.aik-tl-card .aik-tl-sub{display:none}.aik-tl-card p{font-size:13.5px;line-height:19px}}
@media (prefers-reduced-motion: reduce){.aik-tl-card{transition:none}.aik-tl-segs i[data-s="run"]::after{animation:none;transform:scaleX(.5)}}
`
export interface AiStep {
id: string
title: string
/** The tool the step calls, shown in mono. */
tool?: string
status: AiStatus
/** How long the step took, already formatted. */
duration?: string
/** Extra content: a live panel in the rail, a sentence on a stack card. */
detail?: React.ReactNode
}
/** One status for a whole run: failed, then needs-you, then working, then done. */
export function summarizeSteps(steps: AiStep[]): AiStatus {
if (steps.some((step) => step.status === "fail")) return "fail"
if (steps.some((step) => step.status === "ask")) return "ask"
if (steps.some((step) => step.status === "run")) return "run"
if (steps.length > 0 && steps.every((step) => step.status === "done"))
return "done"
return "todo"
}
const currentOf = (steps: AiStep[]) =>
steps.find((step) => step.status !== "done") ?? steps[steps.length - 1]
const moodOf = (status: AiStatus): AiMood =>
status === "run"
? "work"
: status === "ask"
? "needs"
: status === "done"
? "happy"
: status === "fail"
? "oops"
: "idle"
/** The 20px typed mark: dashed ring, spinning ring, amber ring, drawn check, cross. */
export function AiStepMark({
status,
className,
}: {
status: AiStatus
className?: string
}) {
return <i className={cx("aik-tl-mark", className)} data-s={status} />
}
export interface AiStepLogProps {
/** A file name or command for the panel's first line. */
title: string
/** Lines so far. The panel shows the last four. */
lines: string[]
/** Progress from 0 to 1 for the line at the bottom. */
progress?: number
}
/** A live panel for a running step: a file being written, or a command's output. */
export function AiStepLog({ title, lines, progress }: AiStepLogProps) {
return (
<div className="aik-tl-log">
<div className="aik-tl-logh">
<FileCode size={14} />
{title}
{progress === undefined ? null : (
<span>{Math.round(progress * 100)}%</span>
)}
</div>
{lines.slice(-3).map((line, index) => (
<code key={`${lines.length - index}-${line}`}>{line}</code>
))}
{progress === undefined ? null : (
<i
className="aik-tl-bar"
style={{ "--p": progress } as React.CSSProperties}
/>
)}
</div>
)
}
export interface AiStepsProps extends React.HTMLAttributes<HTMLDivElement> {
steps: AiStep[]
/** Whether the list is showing under the header. */
open: boolean
onOpenChange: (open: boolean) => void
/** The run's one clock, already formatted. */
elapsed?: string
/** What the folded header says once the run has finished. */
summary?: string
}
/**
* A run as a rail. The header is the only clock; the running row opens in
* place to show its `detail`, and a finished run folds to one summary line.
*/
export function AiSteps({
steps,
open,
onOpenChange,
elapsed,
summary,
className,
...rest
}: AiStepsProps) {
const status = summarizeSteps(steps)
const current = currentOf(steps)
const done = steps.filter((step) => step.status === "done").length
const id = React.useId()
return (
<div
{...rest}
className={cx("aik aik-tl-rail", className)}
data-s={status}
data-open={open ? "" : undefined}
>
<AiKitStyles />
<AiStyle id="ai-steps" css={CSS} />
<div className="aik-shell">
<div className="aik-surface aik-tl-rcard">
<button
type="button"
className="aik-tl-head"
aria-expanded={open}
aria-controls={id}
onClick={() => onOpenChange(!open)}
>
<AiStepMark status={status} />
<b>
{status === "done" ? (
(summary ?? `${steps.length} steps done`)
) : status === "run" ? (
<span className="aik-shimmer">{current?.title}</span>
) : status === "ask" ? (
<>
Needs you <span>· {current?.title}</span>
</>
) : status === "fail" ? (
<>
Stopped{" "}
<span>
· {done} of {steps.length} done
</span>
</>
) : (
"Queued"
)}
</b>
{elapsed ? <span className="aik-tl-clock">{elapsed}</span> : null}
<ChevronDown className="aik-tl-chev" size={16} />
</button>
<div
className="aik-tl-fold"
id={id}
data-open={open ? "" : undefined}
inert={!open}
>
<div>
<ol className="aik-tl-list">
{steps.map((step, index) => (
<li
key={step.id}
className="aik-tl-row"
data-s={step.status}
style={{ "--i": index } as React.CSSProperties}
>
<AiStepMark status={step.status} />
<span>
<span
className={cx(
"aik-tl-t",
step.status === "run" && "aik-shimmer"
)}
>
{step.title}
</span>
{step.tool ? (
<span className="aik-tl-sub">{step.tool}</span>
) : null}
</span>
<span className="aik-tl-meta">
{step.status === "run"
? "now"
: step.status === "ask"
? "waiting"
: (step.duration ?? "")}
</span>
<div
className="aik-tl-fold aik-tl-live"
data-open={
step.status === "run" && step.detail ? "" : undefined
}
>
<div>
<div>{step.detail}</div>
</div>
</div>
</li>
))}
</ol>
</div>
</div>
<i className="aik-beam" data-on={status === "run" ? "" : undefined} />
</div>
</div>
</div>
)
}
interface AgentLook {
/** Face colour: a named tone or any CSS colour. */
tone?: AiTone | (string & {})
shape?: AiShape
}
export interface AiStepTrackProps
extends AgentLook, React.HTMLAttributes<HTMLDivElement> {
steps: AiStep[]
/** The run's one clock, already formatted. */
elapsed?: string
/** Called with a step's index when its node is pressed. */
onSelectStep?: (index: number) => void
}
/**
* A run as a track. A comet travels from node to node; each node fills and
* draws its check on arrival, and the current step's title rolls underneath.
*/
export function AiStepTrack({
steps,
elapsed,
onSelectStep,
tone = "blue",
shape = "blob",
className,
...rest
}: AiStepTrackProps) {
const status = summarizeSteps(steps)
const current = currentOf(steps)
const at = current ? steps.indexOf(current) : 0
const last = Math.max(steps.length - 1, 1)
const done = steps.filter((step) => step.status === "done").length
const position = status === "done" ? 1 : at / last
return (
<div
{...rest}
className={cx("aik aik-tl-comet", className)}
data-s={status}
>
<AiKitStyles />
<AiStyle id="ai-steps" css={CSS} />
<div className="aik-shell">
<div className="aik-surface aik-tl-ccard">
<div className="aik-tl-ctop">
<Face size={60} tone={tone} shape={shape} mood={moodOf(status)} />
<div style={{ minWidth: 0 }}>
<h4>
<Roll>
{status === "done"
? "All steps done"
: (current?.title ?? "Queued")}
</Roll>
</h4>
<p>
{status === "done"
? `${steps.length} of ${steps.length}`
: `${current?.tool ?? "step"} · ${at + 1} of ${steps.length}`}
</p>
</div>
{elapsed ? <span className="aik-tl-clock">{elapsed}</span> : null}
</div>
<div
className="aik-tl-track"
style={{ "--at": position } as React.CSSProperties}
>
<i className="aik-tl-line" />
<i className="aik-tl-fill" />
{steps.map((step, index) => (
<button
key={step.id}
type="button"
className="aik-tl-node"
aria-label={`${step.title}: ${step.status}`}
aria-current={index === at ? "step" : undefined}
style={{ "--f": index / last } as React.CSSProperties}
onClick={() => onSelectStep?.(index)}
>
<AiStepMark status={step.status} />
</button>
))}
<i className="aik-tl-head2" />
</div>
<div className="aik-tl-labels" aria-hidden="true">
{steps.map((step, index) => (
<span
key={step.id}
data-on={index === at && status !== "done" ? "" : undefined}
style={{ "--f": index / last } as React.CSSProperties}
>
{step.tool ?? step.title}
</span>
))}
</div>
{typeof current?.detail === "string" ? (
<p className="aik-tl-note">
<Roll>
{status === "done"
? "Everything landed. Nothing needs you."
: current.detail}
</Roll>
</p>
) : null}
<div className="aik-tl-cfoot">
<Pill status={status}>
{status === "run"
? "Working"
: status === "ask"
? "Needs you"
: status === "done"
? "Done"
: status === "fail"
? "Failed"
: "Queued"}
</Pill>
<span>
{done} done · {steps.length - done} to go
</span>
</div>
</div>
</div>
</div>
)
}
export interface AiStepStackProps extends React.HTMLAttributes<HTMLDivElement> {
steps: AiStep[]
/** The run's one clock, already formatted. */
elapsed?: string
/** A short label above the stack. */
label?: string
/** Called when the front card is pressed. */
onAdvance?: (step: AiStep) => void
}
/**
* A run as a stack of cards. The front card is the current step; when it
* finishes it is stamped done, lifts away, and the next card rises to the front.
*/
export function AiStepStack({
steps,
elapsed,
label = "Run",
onAdvance,
className,
...rest
}: AiStepStackProps) {
const status = summarizeSteps(steps)
const current = currentOf(steps)
const front = current ? steps.indexOf(current) : 0
const done = steps.filter((step) => step.status === "done").length
const allDone = status === "done"
return (
<div
{...rest}
className={cx("aik aik-tl-stack", className)}
data-s={status}
>
<AiKitStyles />
<AiStyle id="ai-steps" css={CSS} />
<div className="aik-shell">
<div className="aik-surface aik-tl-scard">
<div className="aik-tl-shead">
{label}
<Roll>{`${Math.min(done + 1, steps.length)} / ${steps.length}`}</Roll>
{elapsed ? <span className="aik-tl-clock">{elapsed}</span> : null}
</div>
<div className="aik-tl-well">
{steps.map((step, index) => {
const k = index - front
const gone = k < 0 && !(allDone && index === steps.length - 1)
return (
<button
key={step.id}
type="button"
className="aik-tl-card"
data-s={step.status}
data-k={gone ? "out" : k > 2 ? "hid" : undefined}
tabIndex={k === 0 ? 0 : -1}
aria-hidden={k !== 0}
style={
{
"--k": gone ? 0 : Math.min(Math.max(k, 0), 3),
} as React.CSSProperties
}
onClick={() => onAdvance?.(step)}
>
<AiStepMark status={step.status} />
<b
className={
step.status === "run" ? "aik-shimmer" : undefined
}
>
{step.title}
</b>
<span className="aik-tl-meta">
{step.status === "run" ? "now" : (step.duration ?? "")}
</span>
{step.tool ? (
<span className="aik-tl-sub">{step.tool}</span>
) : null}
{step.detail ? <p>{step.detail}</p> : null}
</button>
)
})}
</div>
<div className="aik-tl-segs" aria-hidden="true">
{steps.map((step) => (
<i key={step.id} data-s={step.status} />
))}
</div>
</div>
</div>
</div>
)
}
Installation
One command adds ai-steps 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-steps.json
ai-steps-demo
"use client"
import * as React from "react"
import { AiDemo } from "@/lib/ai-demo"
import { useAiLoop, useIdleHands } from "@/lib/ai-kit"
import {
AiStepLog,
AiSteps,
AiStepStack,
AiStepTrack,
type AiStep,
} from "@/registry/tween/ai-steps"
const PLAN = [
{
id: "read",
title: "Read the hero section",
tool: "read_file",
ms: 1000,
duration: "0.8s",
note: "hero.tsx and the page layout, 148 lines in all.",
},
{
id: "find",
title: "Find text-skew-reveal",
tool: "search_registry",
ms: 1200,
duration: "1.1s",
note: "Already in the registry, so no new dependency.",
},
{
id: "write",
title: "Write the pricing section",
tool: "write_file",
ms: 3200,
duration: "3.2s",
note: "A monthly and yearly toggle on a 180ms state change.",
},
{
id: "check",
title: "Run the type check",
tool: "run_command",
ms: 1800,
duration: "1.8s",
note: "pnpm typecheck across 214 files.",
},
{
id: "build",
title: "Rebuild the registry",
tool: "run_command",
ms: 1400,
duration: "1.4s",
note: "Regenerates 104 registry files.",
},
] as const
const CODE = [
"export function PricingSection() {",
" const [yearly, setYearly] = useState(false)",
" return (",
' <section className="pricing">',
" <Toggle on={yearly} onChange={setYearly} />",
" <Plans yearly={yearly} />",
]
const CHECK = ["$ tsc --noEmit", "checked 214 files", "0 errors"]
const clock = (ms: number) => {
const seconds = Math.floor(ms / 1000)
return `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`
}
/** One scripted run. `at` is the index of the running step; PLAN.length means finished. */
function useRun(
root: React.RefObject<HTMLDivElement | null>,
hands: boolean,
onDone?: () => void,
onStart?: () => void
) {
const [at, setAt] = React.useState(2)
const [ms, setMs] = React.useState(4000)
const [lines, setLines] = React.useState(3)
useAiLoop(
root,
async ({ sleep }) => {
const wait = async (total: number) => {
for (let spent = 0; spent < total; spent += 200) {
await sleep(200)
setMs((value) => value + 200)
}
}
onStart?.()
setMs(0)
setLines(0)
setAt(0)
await sleep(500)
for (let index = 0; index < PLAN.length; index++) {
setAt(index)
setLines(0)
const step = PLAN[index]
if (!step) continue
const feed = index === 2 ? CODE.length : index === 3 ? CHECK.length : 0
if (feed === 0) await wait(step.ms)
else
for (let line = 1; line <= feed; line++) {
setLines(line)
await wait(step.ms / feed)
}
}
setAt(PLAN.length)
await sleep(1100)
onDone?.()
await sleep(2600)
},
{
gap: 400,
enabled: !hands,
still: () => {
setAt(2)
setLines(4)
},
}
)
const steps: AiStep[] = PLAN.map((step, index) => {
const status = index < at ? "done" : index === at ? "run" : "todo"
let detail: React.ReactNode = step.note
if (index === 2)
detail = (
<AiStepLog
title="pricing-section.tsx"
lines={CODE.slice(0, lines)}
progress={lines / CODE.length}
/>
)
if (index === 3)
detail = (
<AiStepLog title="pnpm typecheck" lines={CHECK.slice(0, lines)} />
)
return {
id: step.id,
title: step.title,
tool: step.tool,
status,
duration: status === "done" ? step.duration : undefined,
detail,
}
})
return { steps, at, setAt, elapsed: clock(ms) }
}
function Rail() {
const root = React.useRef<HTMLDivElement>(null)
const [hands, touch] = useIdleHands()
const [open, setOpen] = React.useState(true)
const { steps, elapsed } = useRun(
root,
hands,
() => setOpen(false),
() => setOpen(true)
)
return (
<div
ref={root}
style={{
display: "grid",
width: "min(100%, 560px)",
minHeight: 380,
alignContent: "start",
}}
onPointerDown={touch}
onKeyDown={touch}
>
<AiSteps
steps={steps}
open={open}
onOpenChange={setOpen}
elapsed={elapsed}
summary={`Worked for ${Number(elapsed.split(":")[1] ?? 0)}s · read 3 files, wrote 1`}
/>
</div>
)
}
function Track() {
const root = React.useRef<HTMLDivElement>(null)
const [hands, touch] = useIdleHands()
const { steps, setAt, elapsed } = useRun(root, hands)
return (
<div
ref={root}
style={{ display: "grid", width: "min(100%, 560px)" }}
onPointerDown={touch}
onKeyDown={touch}
>
<AiStepTrack
steps={steps.map((step, index) => ({
...step,
detail: PLAN[index]?.note,
}))}
elapsed={elapsed}
onSelectStep={setAt}
/>
</div>
)
}
function Stack() {
const root = React.useRef<HTMLDivElement>(null)
const [hands, touch] = useIdleHands()
const { steps, at, setAt, elapsed } = useRun(root, hands)
return (
<div
ref={root}
style={{ display: "grid", width: "min(100%, 540px)" }}
onPointerDown={touch}
onKeyDown={touch}
>
<AiStepStack
label="Pricing section"
steps={steps.map((step, index) => ({
...step,
detail: PLAN[index]?.note,
}))}
elapsed={elapsed}
onAdvance={() => setAt(at >= PLAN.length ? 0 : at + 1)}
/>
</div>
)
}
export function AiStepsDemo({ only }: { only?: string }) {
return (
<AiDemo
only={only}
tabs={[
{ name: "Live rail", node: <Rail /> },
{ name: "Comet track", node: <Track /> },
{ name: "Card stack", node: <Stack /> },
]}
/>
)
}
Installation
Usage
import {
AiStepLog,
AiSteps,
AiStepStack,
AiStepTrack,
type AiStep,
} from "@/components/ui/ai-steps"const steps: AiStep[] = [
{ id: "read", title: "Read the hero section", tool: "read_file", status: "done", duration: "0.8s" },
{
id: "write",
title: "Write the pricing section",
tool: "write_file",
status: "run",
detail: <AiStepLog title="pricing-section.tsx" lines={lines} progress={0.5} />,
},
{ id: "check", title: "Run the type check", tool: "run_command", status: "todo" },
]
const [open, setOpen] = useState(true)
<AiSteps
steps={steps}
open={open}
onOpenChange={setOpen}
elapsed="0:04"
summary="Worked for 41s · read 3 files, wrote 1"
/>Each step's status is one of todo, run, ask, done or fail. With the AI SDK, map a tool part's input-streaming and input-available to run, approval-requested to ask, output-available to done and output-error to fail.
Versions
AiStepsis the live rail. Marks are typed (a dashed ring, a spinning ring, an amber ring, a drawn check, a cross) and the connector turns green behind finished steps. The running row opens in place to show itsdetail, and the header carries the run's only clock. When every step is done the header reads yoursummary; fold the list by settingopento false.AiStepTrackis a horizontal track. A comet travels from node to node in 620ms, each node draws its check on arrival, and the current title rolls above with the face following the run's mood. A stringdetailshows as a note under the track.AiStepStackis a stack of cards. The front card is the current step; when it finishes it is stamped done, lifts away, and the next card rises. A segmented bar below shows the whole run.
AiStepLog is the small live panel used inside a running row. summarizeSteps(steps) returns one status for a whole run.
Props
AiSteps
| Prop | Type | Default | Description |
|---|---|---|---|
steps | AiStep[] | { id, title, tool?, status, duration?, detail? }. | |
open | boolean | Whether the list shows under the header. | |
onOpenChange | (open: boolean) => void | Called when the header is pressed. | |
elapsed | string | The run's clock, already formatted. | |
summary | string | The header's text once every step is done. |
AiStepTrack
| Prop | Type | Default | Description |
|---|---|---|---|
steps | AiStep[] | The run. A string detail is the note. | |
elapsed | string | The run's clock. | |
onSelectStep | (index: number) => void | Called when a node is pressed. | |
tone | tone or CSS colour | "blue" | Face colour. |
shape | face shape | "blob" | Face shape. |
AiStepStack
| Prop | Type | Default | Description |
|---|---|---|---|
steps | AiStep[] | The run. detail is the card's text. | |
elapsed | string | The run's clock. | |
label | string | "Run" | The heading above the stack. |
onAdvance | (step: AiStep) => void | Called when the front card is pressed. |
AiStepLog
| Prop | Type | Default | Description |
|---|---|---|---|
title | string | A file name or command. | |
lines | string[] | Lines so far. The last three are shown. | |
progress | number | From 0 to 1, drawn as a line at the foot. |