{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent-trace-timeline",
  "type": "registry:component",
  "title": "Agent Trace Timeline",
  "description": "A vertical trace of an agent run. Each span shows a status icon, a nested name and a bar sized to its start and duration, and spans with a payload expand in place.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "agent-kit",
    "agent",
    "trace",
    "timeline",
    "spans",
    "observability",
    "debug"
  ],
  "docs": "https://hyperblur.dev/effects/agent-trace-timeline",
  "files": [
    {
      "path": "registry/hyperblur/agent-trace-timeline.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/agent-trace-timeline.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type TraceStatus = \"ok\" | \"error\" | \"running\";\n\nexport interface TraceSpan {\n  id: string;\n  name: string;\n  kind?: string;\n  start: number;\n  duration: number;\n  depth?: number;\n  status?: TraceStatus;\n  payload?: string;\n}\n\nexport interface AgentTraceTimelineProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"title\"> {\n  spans?: TraceSpan[];\n  title?: string;\n  total?: number;\n  accent?: string;\n  expandedId?: string | null;\n  defaultExpandedId?: string | null;\n  onExpandedChange?: (id: string | null) => void;\n}\n\nconst defaultSpans: TraceSpan[] = [\n  { id: \"run\", name: \"support_agent.run\", kind: \"agent\", start: 0, duration: 4800, depth: 0, status: \"ok\" },\n  { id: \"plan\", name: \"plan_next_step\", kind: \"model\", start: 40, duration: 760, depth: 1, status: \"ok\", payload: '{\\n  \"tokens_in\": 1840,\\n  \"tokens_out\": 126,\\n  \"decision\": \"search_docs\"\\n}' },\n  { id: \"search\", name: \"search_docs\", kind: \"tool\", start: 840, duration: 1320, depth: 1, status: \"ok\", payload: '{\\n  \"query\": \"refund window annual plan\",\\n  \"results\": 6\\n}' },\n  { id: \"fetch\", name: \"http.get /v2/policies\", kind: \"http\", start: 900, duration: 980, depth: 2, status: \"ok\", payload: '{\\n  \"status\": 200,\\n  \"bytes\": 18240\\n}' },\n  { id: \"refund\", name: \"issue_refund\", kind: \"tool\", start: 2260, duration: 640, depth: 1, status: \"error\", payload: '{\\n  \"error\": \"amount_exceeds_limit\",\\n  \"limit\": 200\\n}' },\n  { id: \"reply\", name: \"write_reply\", kind: \"model\", start: 2980, duration: 1820, depth: 1, status: \"running\" },\n];\n\nconst css = `\n.hb-yf1 {\n  --hb-yf1-ok: #3ecf8e;\n  --hb-yf1-err: #ff5d5d;\n  box-sizing: border-box;\n  width: 100%;\n  padding: 10px 12px 6px;\n  font-family: inherit;\n  font-size: 12px;\n  line-height: 1.3;\n  color: #ededed;\n  background: #111111;\n  border: 1px solid #262626;\n  border-radius: 14px;\n  text-align: left;\n}\n.hb-yf1 *, .hb-yf1 *::before, .hb-yf1 *::after { box-sizing: border-box; font-family: inherit; }\n.hb-yf1-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 6px; }\n.hb-yf1-title { font-size: 12px; font-weight: 600; letter-spacing: -0.005em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-yf1-total { flex: none; font-variant-numeric: tabular-nums; color: #8f8f8f; font-size: 11px; }\n.hb-yf1-ruler {\n  display: grid;\n  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);\n  padding-bottom: 4px;\n  border-bottom: 1px solid #1f1f1f;\n  font-size: 10px;\n  color: #6b6b6b;\n  font-variant-numeric: tabular-nums;\n}\n.hb-yf1-ticks { display: flex; justify-content: space-between; }\n.hb-yf1-list { list-style: none; margin: 0; padding: 0; }\n.hb-yf1-item { border-bottom: 1px solid #191919; }\n.hb-yf1-item:last-child { border-bottom: 0; }\n.hb-yf1-row {\n  display: grid;\n  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);\n  align-items: center;\n  width: 100%;\n  min-height: 24px;\n  margin: 0;\n  padding: 0;\n  font: inherit;\n  color: inherit;\n  text-align: left;\n  background: none;\n  border: 0;\n  border-radius: 6px;\n  cursor: default;\n}\nbutton.hb-yf1-row { cursor: pointer; }\nbutton.hb-yf1-row:hover { background: rgba(255, 255, 255, 0.035); }\n.hb-yf1-row:focus-visible { outline: 2px solid var(--hb-yf1-a, #2f7bff); outline-offset: -2px; }\n.hb-yf1-name { display: flex; align-items: center; gap: 6px; min-width: 0; padding-right: 8px; }\n.hb-yf1-guides {\n  flex: none;\n  width: calc(var(--hb-yf1-d, 0) * 12px);\n  align-self: stretch;\n  background: repeating-linear-gradient(90deg, transparent 0 5px, #2a2a2a 5px 6px, transparent 6px 12px);\n}\n.hb-yf1-icon { flex: none; width: 14px; height: 14px; }\n.hb-yf1-item[data-status=\"ok\"] .hb-yf1-icon { color: var(--hb-yf1-ok); }\n.hb-yf1-item[data-status=\"error\"] .hb-yf1-icon { color: var(--hb-yf1-err); }\n.hb-yf1-item[data-status=\"running\"] .hb-yf1-icon { color: var(--hb-yf1-a, #2f7bff); animation: hb-yf1-spin 0.9s linear infinite; }\n.hb-yf1-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; }\n.hb-yf1-chev { flex: none; width: 10px; height: 10px; margin-left: auto; color: #6b6b6b; transition: transform 0.2s ease; }\n.hb-yf1-item[data-open=\"true\"] .hb-yf1-chev { transform: rotate(90deg); color: #ededed; }\n.hb-yf1-track { position: relative; height: 24px; }\n.hb-yf1-track::before { content: \"\"; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: #1f1f1f; }\n.hb-yf1-bar {\n  position: absolute;\n  top: 7px;\n  bottom: 7px;\n  min-width: 3px;\n  border-radius: 4px;\n  background: var(--hb-yf1-ok);\n  transform-origin: left center;\n  animation: hb-yf1-grow 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both;\n  animation-delay: calc(var(--hb-yf1-i, 0) * 70ms);\n}\n.hb-yf1-item[data-status=\"error\"] .hb-yf1-bar { background: var(--hb-yf1-err); }\n.hb-yf1-item[data-status=\"running\"] .hb-yf1-bar {\n  background: repeating-linear-gradient(115deg, var(--hb-yf1-a, #2f7bff) 0 6px, color-mix(in srgb, var(--hb-yf1-a, #2f7bff) 55%, #0a0a0a) 6px 12px);\n  background-size: 24px 100%;\n  animation: hb-yf1-grow 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both, hb-yf1-run 0.8s linear infinite;\n  animation-delay: calc(var(--hb-yf1-i, 0) * 70ms), 0s;\n}\n.hb-yf1-dur {\n  position: absolute;\n  top: 50%;\n  transform: translateY(-50%);\n  font-size: 10.5px;\n  font-variant-numeric: tabular-nums;\n  color: #a1a1a1;\n  white-space: nowrap;\n}\n.hb-yf1-dur[data-side=\"right\"] { padding-left: 6px; }\n.hb-yf1-dur[data-side=\"left\"] { padding-right: 6px; }\n.hb-yf1-pay {\n  display: grid;\n  grid-template-rows: 0fr;\n  transition: grid-template-rows 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);\n}\n.hb-yf1-item[data-open=\"true\"] .hb-yf1-pay { grid-template-rows: 1fr; }\n.hb-yf1-payin { min-height: 0; overflow: hidden; }\n.hb-yf1-meta { padding: 4px 0 0 calc(20px + var(--hb-yf1-d, 0) * 12px); font-size: 10px; color: #6b6b6b; text-transform: uppercase; letter-spacing: 0.06em; }\n.hb-yf1-code {\n  margin: 4px 0 8px calc(20px + var(--hb-yf1-d, 0) * 12px);\n  padding: 8px 10px;\n  overflow-x: auto;\n  font-family: var(--font-geist-mono, ui-monospace, SFMono-Regular, Menlo, monospace);\n  font-size: 11px;\n  line-height: 1.5;\n  color: #c9d4e8;\n  background: #0a0a0a;\n  border: 1px solid #1f1f1f;\n  border-radius: 8px;\n}\n@keyframes hb-yf1-grow { from { transform: scaleX(0); opacity: 0; } to { transform: scaleX(1); opacity: 1; } }\n@keyframes hb-yf1-run { from { background-position: 0 0; } to { background-position: 24px 0; } }\n@keyframes hb-yf1-spin { to { transform: rotate(360deg); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-yf1-bar, .hb-yf1-item[data-status=\"running\"] .hb-yf1-bar, .hb-yf1-item[data-status=\"running\"] .hb-yf1-icon { animation: none; }\n  .hb-yf1-pay, .hb-yf1-chev { transition: none; }\n}\n`;\n\nfunction fmt(ms: number) {\n  if (ms >= 1000) return `${(ms / 1000).toFixed(1)}s`;\n  return `${Math.round(ms)}ms`;\n}\n\nfunction StatusIcon({ status }: { status: TraceStatus }) {\n  return (\n    <svg className=\"hb-yf1-icon\" viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\">\n      {status === \"running\" ? (\n        <>\n          <circle cx=\"8\" cy=\"8\" r=\"6.2\" stroke=\"currentColor\" strokeOpacity=\"0.25\" strokeWidth=\"1.5\" />\n          <path d=\"M8 1.8a6.2 6.2 0 0 1 6.2 6.2\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n        </>\n      ) : (\n        <>\n          <circle cx=\"8\" cy=\"8\" r=\"6.2\" stroke=\"currentColor\" strokeWidth=\"1.4\" />\n          {status === \"ok\" ? (\n            <path d=\"M5.2 8.2l2 2 3.6-4.1\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n          ) : (\n            <path d=\"M5.8 5.8l4.4 4.4M10.2 5.8l-4.4 4.4\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n          )}\n        </>\n      )}\n    </svg>\n  );\n}\n\nexport function AgentTraceTimeline({\n  spans = defaultSpans,\n  title = \"Run 4821\",\n  total,\n  accent = \"#2f7bff\",\n  expandedId,\n  defaultExpandedId = null,\n  onExpandedChange,\n  className = \"\",\n  style,\n  onKeyDown,\n  ...rest\n}: AgentTraceTimelineProps) {\n  const baseId = React.useId();\n  const listRef = React.useRef<HTMLOListElement>(null);\n  const [inner, setInner] = React.useState<string | null>(defaultExpandedId);\n  const controlled = expandedId !== undefined;\n  const openId = controlled ? expandedId : inner;\n\n  const span = total ?? Math.max(1, ...spans.map((s) => s.start + s.duration));\n\n  function toggle(id: string) {\n    const next = openId === id ? null : id;\n    if (!controlled) setInner(next);\n    onExpandedChange?.(next);\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {\n    onKeyDown?.(e);\n    if (![\"ArrowDown\", \"ArrowUp\", \"Home\", \"End\"].includes(e.key)) return;\n    const rows = Array.from(listRef.current?.querySelectorAll<HTMLButtonElement>(\"button.hb-yf1-row\") ?? []);\n    if (!rows.length) return;\n    const at = rows.indexOf(document.activeElement as HTMLButtonElement);\n    if (at < 0) return;\n    e.preventDefault();\n    let next = at;\n    if (e.key === \"ArrowDown\") next = Math.min(rows.length - 1, at + 1);\n    if (e.key === \"ArrowUp\") next = Math.max(0, at - 1);\n    if (e.key === \"Home\") next = 0;\n    if (e.key === \"End\") next = rows.length - 1;\n    rows[next].focus();\n  }\n\n  return (\n    <>\n      <style href=\"hb-agent-trace-timeline\" precedence=\"default\">{css}</style>\n      <div\n        className={`hb-yf1 ${className}`}\n        style={{ \"--hb-yf1-a\": accent, ...style } as React.CSSProperties}\n        onKeyDown={handleKeyDown}\n        {...rest}\n      >\n        <div className=\"hb-yf1-head\">\n          <span className=\"hb-yf1-title\">{title}</span>\n          <span className=\"hb-yf1-total\">{fmt(span)} total</span>\n        </div>\n        <div className=\"hb-yf1-ruler\" aria-hidden=\"true\">\n          <span>Span</span>\n          <span className=\"hb-yf1-ticks\">\n            <span>0</span>\n            <span>{fmt(span / 2)}</span>\n            <span>{fmt(span)}</span>\n          </span>\n        </div>\n        <ol className=\"hb-yf1-list\" ref={listRef}>\n          {spans.map((s, i) => {\n            const status = s.status ?? \"ok\";\n            const depth = s.depth ?? 0;\n            const open = openId === s.id && !!s.payload;\n            const left = Math.min(100, Math.max(0, (s.start / span) * 100));\n            const width = Math.min(100 - left, Math.max(0.8, (s.duration / span) * 100));\n            const flip = left + width > 70;\n            const payloadId = `${baseId}-${s.id}`;\n            const rowInner = (\n              <>\n                <span className=\"hb-yf1-name\">\n                  <span className=\"hb-yf1-guides\" aria-hidden=\"true\" />\n                  <StatusIcon status={status} />\n                  <span className=\"hb-yf1-label\">{s.name}</span>\n                  {s.payload ? (\n                    <svg className=\"hb-yf1-chev\" viewBox=\"0 0 10 10\" fill=\"none\" aria-hidden=\"true\">\n                      <path d=\"M3.5 1.5L7 5L3.5 8.5\" stroke=\"currentColor\" strokeWidth=\"1.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n                    </svg>\n                  ) : null}\n                </span>\n                <span className=\"hb-yf1-track\" aria-hidden=\"true\">\n                  <span className=\"hb-yf1-bar\" style={{ left: `${left.toFixed(2)}%`, width: `${width.toFixed(2)}%` }} />\n                  <span\n                    className=\"hb-yf1-dur\"\n                    data-side={flip ? \"left\" : \"right\"}\n                    style={\n                      flip\n                        ? { right: `${(100 - left).toFixed(2)}%` }\n                        : { left: `${(left + width).toFixed(2)}%` }\n                    }\n                  >\n                    {status === \"running\" ? \"running\" : fmt(s.duration)}\n                  </span>\n                </span>\n              </>\n            );\n            return (\n              <li\n                key={s.id}\n                className=\"hb-yf1-item\"\n                data-status={status}\n                data-open={open}\n                style={{ \"--hb-yf1-i\": i, \"--hb-yf1-d\": depth } as React.CSSProperties}\n              >\n                {s.payload ? (\n                  <button\n                    type=\"button\"\n                    className=\"hb-yf1-row\"\n                    aria-expanded={open}\n                    aria-controls={payloadId}\n                    aria-label={`${s.name}, ${status}, ${fmt(s.duration)}`}\n                    onClick={() => toggle(s.id)}\n                  >\n                    {rowInner}\n                  </button>\n                ) : (\n                  <div className=\"hb-yf1-row\" role=\"group\" aria-label={`${s.name}, ${status}, ${fmt(s.duration)}`}>\n                    {rowInner}\n                  </div>\n                )}\n                {s.payload ? (\n                  <div id={payloadId} className=\"hb-yf1-pay\" aria-hidden={!open}>\n                    <div className=\"hb-yf1-payin\">\n                      <div className=\"hb-yf1-meta\">\n                        {s.kind ? `${s.kind} · ` : \"\"}starts +{fmt(s.start)} · took {fmt(s.duration)}\n                      </div>\n                      <pre className=\"hb-yf1-code\">{s.payload}</pre>\n                    </div>\n                  </div>\n                ) : null}\n              </li>\n            );\n          })}\n        </ol>\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}