Deep Research Progress
An agent researching a question: sources it finds on the left, the report taking shape section by section on the right, and a line from each source to the section it feeds.
"use client"
import * as React from "react"
import { Check, FileText, Square } from "lucide-react"
import {
AgentGlyph,
AiKitStyles,
AiStyle,
BrandIcon,
BrandStack,
BrandTile,
cx,
Edge,
Face,
Mark,
Roll,
type AiStatus,
} from "@/lib/ai-kit"
export interface ResearchSource {
id: string
/** Brand mark for the site. */
brand: string
title: string
domain: string
/** Not opened yet, being read, or read. */
state: "todo" | "read" | "done"
}
export interface ResearchSection {
id: string
title: string
status: AiStatus
/** What the section says, or what it waits for. */
line: string
words: number
/** Brands of the sources feeding it. */
fed: readonly string[]
}
export interface DeepResearchProgressProps {
agent: string
model: string
vendor?: string
elapsed: string
sources: readonly ResearchSource[]
sections: readonly ResearchSection[]
/** The source being read and the section it is feeding right now. */
link?: { source: string; section: string } | null
running?: boolean
onStop?: () => void
className?: string
}
const CSS = `
.aik-dr{--aik-r-shell:26px;--aik-rim:5px;width:min(100%,1000px);container-type:inline-size}
.aik-dr-card{display:grid;gap:18px;padding:18px 20px 20px}
.aik-dr-head{display:flex;align-items:center;gap:12px;min-width:0}
.aik-dr-head b{font-size:16px;font-weight:600}
.aik-dr-chip{display:inline-flex;align-items:center;gap:6px;height:28px;padding:0 10px;border-radius:9px;background:var(--aik-raised);font-size:13px;color:var(--aik-text-2);white-space:nowrap}
.aik-dr-time{margin-left:auto;font:13px var(--aik-mono);color:var(--aik-text-3);font-variant-numeric:tabular-nums}
.aik-dr-body{position:relative;display:grid;grid-template-columns:minmax(0,.9fr) minmax(0,1.1fr);gap:56px}
.aik-dr-svg{position:absolute;inset:0;width:100%;height:100%;overflow:visible;pointer-events:none;z-index:1}
.aik-dr-port{fill:var(--aik-card);stroke:var(--aik-blue);stroke-width:1.5}
.aik-dr-colh{display:flex;align-items:center;gap:8px;height:28px;margin-bottom:8px;font-size:13.5px;color:var(--aik-text-3)}
.aik-dr-colh .aik-pill{margin-left:auto}
.aik-dr-src{display:grid;grid-template-columns:32px minmax(0,1fr) 20px;align-items:center;gap:12px;padding:7px 10px;border-radius:12px;transition:background var(--aik-d-panel),opacity var(--aik-d-panel);animation:aik-dr-in 420ms var(--aik-ease-out) both}
.aik-dr-src[data-s="todo"]{opacity:.42}
.aik-dr-src[data-s="read"]{background:color-mix(in oklab,var(--aik-blue) 12%,transparent);box-shadow:inset 0 0 0 1px color-mix(in oklab,var(--aik-blue) 22%,transparent)}
.aik-dr-src > span{display:grid;min-width:0;line-height:19px}
.aik-dr-src b{font-weight:500;font-size:14.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-dr-src small{font-size:13px;color:var(--aik-text-3)}
.aik-dr-src .aik-dr-check{color:var(--aik-green);animation:aik-dr-pop 380ms var(--aik-ease-out)}
@keyframes aik-dr-pop{from{transform:scale(.4);opacity:0}}
@keyframes aik-dr-in{from{opacity:0;transform:translateX(-8px)}}
.aik-dr-secs{display:grid;gap:10px}
.aik-dr-sec{position:relative;display:grid;grid-template-columns:20px minmax(0,1fr) auto;column-gap:12px;row-gap:3px;padding:14px 16px;border-radius:14px;background:var(--aik-card);box-shadow:var(--aik-sh-card);transition:box-shadow var(--aik-d-panel),opacity var(--aik-d-panel)}
.aik-dr-sec[data-s="todo"]{opacity:.62}
.aik-dr-sec[data-s="run"]{box-shadow:0 0 0 1px color-mix(in oklab,var(--aik-blue) 45%,transparent),0 10px 30px -14px color-mix(in oklab,var(--aik-blue) 55%,transparent)}
.aik-dr-sec .aik-mark{grid-row:1/3;margin-top:1px}
.aik-dr-sec h4{display:flex;gap:8px;font-size:15px;font-weight:600;min-width:0}
.aik-dr-sec h4 em{font-style:normal;color:var(--aik-text-3);font-weight:500;font-variant-numeric:tabular-nums}
.aik-dr-sec h4 span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-dr-words{font:12.5px var(--aik-mono);color:var(--aik-text-3);white-space:nowrap;font-variant-numeric:tabular-nums}
.aik-dr-line{grid-column:2;font-size:13.5px;color:var(--aik-text-2);min-width:0}
.aik-dr-line .aik-roll{max-width:100%}
.aik-dr-sec[data-s="run"] .aik-dr-line{color:var(--aik-blue)}
.aik-dr-fed{grid-column:3;justify-self:end;align-self:end}
.aik-dr-write{position:absolute;left:16px;right:16px;bottom:0;height:2px;border-radius:2px;overflow:hidden}
.aik-dr-write::after{content:"";position:absolute;inset:0;width:40%;background:linear-gradient(90deg,transparent,var(--aik-blue),transparent);animation:aik-dr-write 1.4s linear infinite}
@keyframes aik-dr-write{from{transform:translateX(-100%)}to{transform:translateX(250%)}}
@container (max-width:700px){.aik-dr-body{grid-template-columns:minmax(0,1fr);gap:22px}.aik-dr-svg{display:none}.aik-dr-head .aik-dr-chip{display:none}}
@media (prefers-reduced-motion:reduce){.aik-dr-src,.aik-dr-write::after{animation:none}}
`
/**
* An agent researching a question: sources it finds on the left, the report
* taking shape section by section on the right, and a live line from the
* source being read to the section it feeds.
*/
export function DeepResearchProgress({
agent,
model,
vendor,
elapsed,
sources,
sections,
link,
running = true,
onStop,
className,
}: DeepResearchProgressProps) {
const body = React.useRef<HTMLDivElement>(null)
const refs = React.useRef(new Map<string, HTMLElement>())
const [path, setPath] = React.useState<{
d: string
a: [number, number]
b: [number, number]
} | null>(null)
const place = (node: HTMLElement) => {
let left = 0
let top = 0
let el: HTMLElement | null = node
while (el && el !== body.current) {
left += el.offsetLeft
top += el.offsetTop
el = el.offsetParent as HTMLElement | null
}
return { left, top, width: node.offsetWidth, height: node.offsetHeight }
}
const measure = React.useCallback(() => {
if (!link) return setPath(null)
const s = refs.current.get(link.source)
const t = refs.current.get(link.section)
if (!s || !t) return setPath(null)
const f = place(s)
const g = place(t)
const a: [number, number] = [f.left + f.width + 6, f.top + f.height / 2]
const b: [number, number] = [g.left - 6, g.top + Math.min(g.height / 2, 32)]
const mx = a[0] + (b[0] - a[0]) / 2
const r = Math.min(12, Math.abs(b[1] - a[1]) / 2)
const dy = b[1] > a[1] ? 1 : -1
const d =
Math.abs(b[1] - a[1]) < 1
? `M${a[0]} ${a[1]}H${b[0]}`
: `M${a[0]} ${a[1]}H${mx - r}Q${mx} ${a[1]} ${mx} ${a[1] + dy * r}V${b[1] - dy * r}Q${mx} ${b[1]} ${mx + r} ${b[1]}H${b[0]}`
setPath({ d, a, b })
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [link?.source, link?.section])
React.useLayoutEffect(() => {
measure()
const observer = new ResizeObserver(() => measure())
if (body.current) observer.observe(body.current)
return () => observer.disconnect()
}, [measure, sources.length, sections])
const register = (id: string) => (node: HTMLElement | null) => {
if (node) refs.current.set(id, node)
else refs.current.delete(id)
}
const reading = sources.some((source) => source.state === "read")
return (
<div className={cx("aik aik-dr aik-shell", className)}>
<AiKitStyles />
<AiStyle id="deep-research-progress" css={CSS} />
<div className="aik-surface aik-dr-card">
<span
className="aik-beam"
data-on={running ? "" : undefined}
style={{ animation: "aik-beam 3s linear infinite" }}
/>
<div className="aik-dr-head">
<Face
mood={running ? "think" : "happy"}
shape="leaf"
tone="violet"
size={30}
/>
<b>{agent}</b>
<span className="aik-dr-chip">
{vendor ? <BrandIcon name={vendor} tint="brand" size={13} /> : null}
{model}
</span>
<span className="aik-dr-time">{elapsed}</span>
{running ? (
<button type="button" className="aik-btn line" onClick={onStop}>
<Square size={11} fill="currentColor" />
Stop
</button>
) : (
<span className="aik-pill" data-s="done">
Report ready
</span>
)}
</div>
<div className="aik-dr-body" ref={body}>
<svg className="aik-dr-svg" aria-hidden="true">
{path ? (
<g key={path.d}>
<Edge
d={path.d}
tone="blue"
state="live"
width={1.6}
duration={1.2}
/>
<path
d={path.d}
fill="none"
stroke="var(--aik-blue)"
strokeOpacity={0.5}
strokeWidth={1.5}
pathLength={1}
strokeDasharray="1"
style={{
animation: "aik-dr-draw 520ms var(--aik-ease-out) both",
}}
/>
<circle
className="aik-dr-port"
cx={path.a[0]}
cy={path.a[1]}
r={4}
/>
<circle
className="aik-dr-port"
cx={path.b[0]}
cy={path.b[1]}
r={4}
/>
</g>
) : null}
<style>{`@keyframes aik-dr-draw{from{stroke-dashoffset:1}to{stroke-dashoffset:0}}`}</style>
</svg>
<div>
<div className="aik-dr-colh">
<AgentGlyph seed="sources" tone="blue" size={14} live={reading} />
Sources
<span className="aik-pill" data-s={reading ? "run" : "done"}>
<Roll>
{reading
? "Reading"
: `${sources.filter((s) => s.state === "done").length} read`}
</Roll>
</span>
</div>
{sources.map((source, i) => (
<div
key={source.id}
ref={register(source.id)}
className="aik-dr-src"
data-s={source.state}
style={{ animationDelay: `${i * 30}ms` }}
>
<BrandTile name={source.brand} size={32} />
<span>
<b>{source.title}</b>
<small>{source.domain}</small>
</span>
{source.state === "done" ? (
<Check
className="aik-dr-check"
size={16}
strokeWidth={2.4}
aria-label="Read"
/>
) : source.state === "read" ? (
<Mark status="run" />
) : null}
</div>
))}
</div>
<div>
<div className="aik-dr-colh">
<FileText size={15} aria-hidden="true" />
Report
</div>
<div className="aik-dr-secs">
{sections.map((section, i) => (
<div
key={section.id}
ref={register(section.id)}
className="aik-dr-sec"
data-s={section.status}
>
<Mark status={section.status} />
<h4>
<em>{i + 1}</em>
<span>{section.title}</span>
</h4>
<span className="aik-dr-words">
{section.words ? (
<Roll>{`${section.words} words`}</Roll>
) : null}
</span>
<p className="aik-dr-line">
<Roll>{section.line}</Roll>
</p>
<span className="aik-dr-fed">
{section.fed.length ? (
<BrandStack names={section.fed.slice(0, 3)} size={22} />
) : null}
</span>
{section.status === "run" ? (
<span className="aik-dr-write" aria-hidden="true" />
) : null}
</div>
))}
</div>
</div>
</div>
</div>
</div>
)
}
Installation
One command adds deep-research-progress 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/deep-research-progress.json