{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "execution-detail-view",
  "title": "Execution Detail View",
  "description": "A full record of one AI agent run: status and totals at the top, every step with its timing, and the input, output and log behind each one.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/execution-detail-view/execution-detail-view.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type StepState = \"ok\" | \"failed\";\n\nexport interface ExecutionStep {\n  id: string;\n  name: string;\n  /** \"Model\" or \"Tool\", or any short kind. */\n  kind: string;\n  /** Seconds from the start of the run. */\n  start: number;\n  end: number;\n  tokens: number;\n  state?: StepState;\n  input: string;\n  output: string;\n  log: string[];\n}\n\nexport interface ExecutionDetailViewProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  /** Short id, e.g. \"482\". */\n  runId?: string;\n  bot?: string;\n  /** Dollars. */\n  cost?: number;\n  steps?: ExecutionStep[];\n  onRerun?: () => void;\n  onShare?: () => void;\n}\n\ntype Tab = \"input\" | \"output\" | \"log\";\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\nconst MONO =\n  'ui-monospace, \"SF Mono\", SFMono-Regular, Menlo, Consolas, monospace';\nconst ACCENT = \"#5E6AD2\";\nconst GREEN = \"#27A644\";\nconst ORANGE = \"#FC7840\";\nconst RED = \"#EB5757\";\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\nconst LANE = 26;\nconst AXIS = 20;\n\nconst PALETTES = {\n  dark: {\n    bg: \"#08090A\",\n    inset: \"#0F1011\",\n    border: \"rgba(255,255,255,0.08)\",\n    grid: \"rgba(255,255,255,0.05)\",\n    bar: \"rgba(255,255,255,0.14)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.05)\",\n    tab: \"rgba(255,255,255,0.08)\",\n    row: \"rgba(255,255,255,0.05)\",\n    btn: \"#E5E5E6\",\n    btnText: \"#08090A\",\n  },\n  light: {\n    bg: \"#FFFFFF\",\n    inset: \"#F7F8F8\",\n    border: \"rgba(8,9,10,0.08)\",\n    grid: \"rgba(8,9,10,0.06)\",\n    bar: \"rgba(8,9,10,0.14)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.04)\",\n    tab: \"#FFFFFF\",\n    row: \"rgba(8,9,10,0.04)\",\n    btn: \"#08090A\",\n    btnText: \"#F7F8F8\",\n  },\n};\n\nconst DEFAULT_STEPS: ExecutionStep[] = [\n  {\n    id: \"plan\",\n    name: \"Make a plan\",\n    kind: \"Model\",\n    start: 0,\n    end: 8,\n    tokens: 1840,\n    input: \"Sort this week's refund tickets and draft replies.\",\n    output:\n      \"1. Find the tickets\\n2. Read the orders\\n3. Group by reason\\n4. Draft replies\",\n    log: [\"Picked 4 steps\", \"Budget set to $1.00\"],\n  },\n  {\n    id: \"search\",\n    name: \"search_tickets\",\n    kind: \"Tool\",\n    start: 8,\n    end: 11,\n    tokens: 310,\n    input: '{ \"query\": \"refund\", \"limit\": 40 }',\n    output: '{ \"found\": 40, \"oldest\": \"9 days\" }',\n    log: [\"Called the helpdesk API\", \"Answered in 214 ms\"],\n  },\n  {\n    id: \"orders\",\n    name: \"read_orders\",\n    kind: \"Tool\",\n    start: 11,\n    end: 19,\n    tokens: 2260,\n    input: '{ \"ids\": [\"5120\", \"5121\", \"... 38 more\"] }',\n    output: '{ \"read\": 40, \"missing\": 0 }',\n    log: [\"Read 40 orders in 4 batches\"],\n  },\n  {\n    id: \"group\",\n    name: \"Group the reasons\",\n    kind: \"Model\",\n    start: 19,\n    end: 46,\n    tokens: 18420,\n    input: \"40 tickets with their orders.\",\n    output: \"Damaged 17, late 11, wrong item 7, changed mind 3, other 2.\",\n    log: [\"Used the large model\", \"Longest step of the run\"],\n  },\n  {\n    id: \"draft-1\",\n    name: \"draft_reply\",\n    kind: \"Tool\",\n    start: 46,\n    end: 58,\n    tokens: 960,\n    state: \"failed\",\n    input: '{ \"ticket\": 8841, \"template\": \"refund_v2\" }',\n    output: '{ \"error\": \"template not found\" }',\n    log: [\"Template refund_v2 is missing\", \"Marked for retry\"],\n  },\n  {\n    id: \"draft-2\",\n    name: \"draft_reply\",\n    kind: \"Tool\",\n    start: 58,\n    end: 83,\n    tokens: 6120,\n    input: '{ \"ticket\": 8841, \"template\": \"default\" }',\n    output: '{ \"drafted\": 12 }',\n    log: [\"Retried with the default template\", \"Drafted 12 replies\"],\n  },\n  {\n    id: \"save\",\n    name: \"save_drafts\",\n    kind: \"Tool\",\n    start: 83,\n    end: 88,\n    tokens: 240,\n    input: '{ \"drafts\": 12, \"review\": true }',\n    output: '{ \"saved\": 12 }',\n    log: [\"Saved for review\"],\n  },\n];\n\nconst TABS: { id: Tab; label: string }[] = [\n  { id: \"input\", label: \"Input\" },\n  { id: \"output\", label: \"Output\" },\n  { id: \"log\", label: \"Log\" },\n];\n\nconst round = (n: number) => Math.round(n * 10) / 10;\n\nconst clock = (s: number) =>\n  s >= 60\n    ? `${Math.floor(s / 60)}m ${Math.round(s % 60)}s`\n    : `${Math.round(s)}s`;\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nfunction useWidth<T extends HTMLElement>(fallback: number) {\n  const ref = React.useRef<T>(null);\n  const [width, setWidth] = React.useState(fallback);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const ro = new ResizeObserver(([entry]) => {\n      setWidth(Math.round(entry.contentRect.width));\n    });\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n  return [ref, width] as const;\n}\n\n/** Drawn as SVG, because a tiny border-radius circle turns lumpy on 1x screens. */\nfunction Dot({ size, color }: { size: number; color: string }) {\n  const r = size / 2;\n  return (\n    <svg\n      aria-hidden=\"true\"\n      width={size}\n      height={size}\n      viewBox={`0 0 ${size} ${size}`}\n      className=\"block shrink-0\"\n    >\n      <circle\n        cx={r}\n        cy={r}\n        r={r}\n        className=\"motion-safe:transition-[fill] motion-safe:duration-200\"\n        style={{ fill: color }}\n      />\n    </svg>\n  );\n}\n\nexport function ExecutionDetailView({\n  theme = \"dark\",\n  title = \"Sort refund tickets\",\n  runId = \"482\",\n  bot = \"Sift\",\n  cost = 0.38,\n  steps = DEFAULT_STEPS,\n  onRerun,\n  onShare,\n  className,\n  style,\n  ...rest\n}: ExecutionDetailViewProps) {\n  const c = PALETTES[theme];\n  const reduce = useReducedMotion();\n  const [selected, setSelected] = React.useState(steps[3]?.id ?? \"\");\n  const [tab, setTab] = React.useState<Tab>(\"output\");\n  const [sweep, setSweep] = React.useState<number | null>(null);\n  const [shared, setShared] = React.useState(false);\n  const [chartRef, width] = useWidth<HTMLDivElement>(720);\n  const raf = React.useRef(0);\n  const shareTimer = React.useRef(0);\n\n  const total = Math.max(...steps.map((s) => s.end), 1);\n  const tokens = steps.reduce((sum, s) => sum + s.tokens, 0);\n  const failed = steps.filter((s) => s.state === \"failed\").length;\n  const tools = steps.filter((s) => s.kind === \"Tool\").length;\n  const at = Math.max(\n    0,\n    steps.findIndex((s) => s.id === selected),\n  );\n  const running = sweep !== null;\n  const tabIndex = TABS.findIndex((t) => t.id === tab);\n\n  const chartH = AXIS + steps.length * LANE;\n  const x = (s: number) => round((s / total) * (width - 2));\n  const ticks = [0, 0.25, 0.5, 0.75, 1].map((p) => Math.round(p * total));\n\n  React.useEffect(\n    () => () => {\n      cancelAnimationFrame(raf.current);\n      window.clearTimeout(shareTimer.current);\n    },\n    [],\n  );\n\n  const rerun = () => {\n    onRerun?.();\n    if (reduce || running) return;\n    const began = performance.now();\n    const tick = (now: number) => {\n      const p = Math.min(1, (now - began) / 2600);\n      if (p >= 1) {\n        setSweep(null);\n        return;\n      }\n      setSweep(p * total);\n      raf.current = requestAnimationFrame(tick);\n    };\n    setSweep(0);\n    raf.current = requestAnimationFrame(tick);\n  };\n\n  const share = () => {\n    onShare?.();\n    setShared(true);\n    window.clearTimeout(shareTimer.current);\n    shareTimer.current = window.setTimeout(() => setShared(false), 1400);\n  };\n\n  const go = (by: number) => {\n    const next = steps[at + by];\n    if (next) setSelected(next.id);\n  };\n\n  const metrics = [\n    { label: \"Duration\", value: clock(total) },\n    { label: \"Tokens\", value: tokens.toLocaleString(\"en-US\") },\n    { label: \"Cost\", value: `$${cost.toFixed(2)}` },\n    { label: \"Tool calls\", value: String(tools) },\n  ];\n\n  return (\n    <section\n      aria-label={title}\n      className={`@container w-full ${className ?? \"\"}`}\n      style={{ background: c.bg, color: c.text, fontFamily: FONT, ...style }}\n      {...rest}\n    >\n      <header className=\"flex flex-wrap items-start justify-between gap-x-6 gap-y-3 px-5 pt-6 pb-5 @3xl:px-8\">\n        <div className=\"min-w-0\">\n          <p\n            className=\"m-0 text-[13px] leading-[20px] tracking-[-0.011em] tabular-nums\"\n            style={{ color: c.faint }}\n          >\n            Runs / {runId}\n          </p>\n          <h2 className=\"m-0 mt-1 text-[24px] leading-[32px] font-[590] tracking-[-0.018em]\">\n            {title}\n          </h2>\n          <p\n            aria-live=\"polite\"\n            className=\"m-0 mt-1 flex items-center gap-2 text-[13px] leading-[20px] tracking-[-0.011em]\"\n            style={{ color: c.sub }}\n          >\n            <Dot size={8} color={running ? ACCENT : failed ? ORANGE : GREEN} />\n            {running\n              ? \"Running again\"\n              : failed\n                ? `Finished by ${bot}, ${failed} step retried`\n                : `Finished by ${bot}`}\n          </p>\n        </div>\n        <div className=\"flex shrink-0 gap-2\">\n          <button\n            type=\"button\"\n            data-share=\"\"\n            onClick={share}\n            className={`h-9 cursor-pointer rounded-full border-0 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] ${RING}`}\n            style={{\n              width: 76,\n              background: c.chip,\n              color: shared ? GREEN : c.soft,\n            }}\n          >\n            {shared ? \"Copied\" : \"Share\"}\n          </button>\n          <button\n            type=\"button\"\n            data-rerun=\"\"\n            disabled={running}\n            onClick={rerun}\n            className={`h-9 cursor-pointer rounded-full border-0 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] disabled:cursor-default ${RING}`}\n            style={{\n              width: 92,\n              background: running ? c.chip : c.btn,\n              color: running ? c.faint : c.btnText,\n            }}\n          >\n            {running ? \"Running\" : \"Run again\"}\n          </button>\n        </div>\n      </header>\n\n      {/* Hairlines come from a gap over the border colour, so they line up at any width. */}\n      <dl\n        className=\"m-0 grid grid-cols-2 gap-px border-y @3xl:grid-cols-4\"\n        style={{ background: c.border, borderColor: c.border }}\n      >\n        {metrics.map((m) => (\n          <div\n            key={m.label}\n            className=\"min-w-0 px-5 py-3.5 @3xl:px-8\"\n            style={{ background: c.bg }}\n          >\n            <dt\n              className=\"text-[12px] leading-[16px] tracking-[-0.005em]\"\n              style={{ color: c.faint }}\n            >\n              {m.label}\n            </dt>\n            <dd className=\"m-0 mt-0.5 text-[20px] leading-[28px] font-[510] tracking-[-0.018em] tabular-nums\">\n              {m.value}\n            </dd>\n          </div>\n        ))}\n      </dl>\n\n      <div className=\"grid @3xl:grid-cols-[280px_minmax(0,1fr)]\">\n        {/* Wide layouts list the steps. Phones step through them instead. */}\n        <ol\n          className=\"m-0 hidden list-none flex-col gap-0.5 border-r p-3 @3xl:flex\"\n          style={{ borderColor: c.border }}\n        >\n          {steps.map((s) => {\n            const on = s.id === selected;\n            return (\n              <li key={s.id}>\n                <button\n                  type=\"button\"\n                  data-step={s.id}\n                  aria-current={on ? \"true\" : undefined}\n                  onClick={() => setSelected(s.id)}\n                  onKeyDown={(e) => {\n                    if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n                      e.preventDefault();\n                      go(e.key === \"ArrowDown\" ? 1 : -1);\n                    }\n                  }}\n                  className={`flex w-full cursor-pointer items-center gap-2.5 rounded-lg border-0 bg-transparent px-2.5 py-1.5 text-left motion-safe:transition-colors motion-safe:duration-150 ${RING}`}\n                  style={{ background: on ? c.row : \"transparent\" }}\n                >\n                  <Dot size={8} color={s.state === \"failed\" ? RED : GREEN} />\n                  <span className=\"min-w-0 flex-1\">\n                    <span\n                      className=\"block truncate text-[13px] leading-[20px] font-[510] tracking-[-0.011em]\"\n                      style={{ color: c.text }}\n                    >\n                      {s.name}\n                    </span>\n                    <span\n                      className=\"block truncate text-[12px] leading-[16px] tracking-[-0.005em]\"\n                      style={{ color: c.faint }}\n                    >\n                      {s.kind}\n                    </span>\n                  </span>\n                  <span\n                    className=\"shrink-0 text-[12px] leading-[16px] tracking-[-0.005em] tabular-nums\"\n                    style={{ color: c.sub }}\n                  >\n                    {clock(s.end - s.start)}\n                  </span>\n                </button>\n              </li>\n            );\n          })}\n        </ol>\n\n        <div className=\"min-w-0 p-5 @3xl:p-6\">\n          <div ref={chartRef} className=\"w-full\" style={{ height: chartH }}>\n            <svg\n              role=\"group\"\n              aria-label=\"Step timing\"\n              width={width}\n              height={chartH}\n              className=\"block\"\n            >\n              {ticks.map((t, i) => (\n                <g key={t}>\n                  <line\n                    x1={x(t)}\n                    x2={x(t)}\n                    y1={AXIS - 4}\n                    y2={chartH}\n                    stroke={c.grid}\n                  />\n                  <text\n                    x={x(t)}\n                    y={11}\n                    textAnchor={i === 0 ? \"start\" : i === 4 ? \"end\" : \"middle\"}\n                    fontSize=\"11\"\n                    fill={c.faint}\n                    style={{ fontVariantNumeric: \"tabular-nums\" }}\n                  >\n                    {t}s\n                  </text>\n                </g>\n              ))}\n              {steps.map((s, i) => {\n                const on = s.id === selected;\n                const y = AXIS + i * LANE + 5;\n                const fill = s.state === \"failed\" ? RED : on ? ACCENT : c.bar;\n                return (\n                  <g\n                    key={s.id}\n                    data-bar={s.id}\n                    onClick={() => setSelected(s.id)}\n                    className=\"cursor-pointer\"\n                  >\n                    <rect\n                      x={0}\n                      y={y - 5}\n                      width={width}\n                      height={LANE}\n                      fill=\"transparent\"\n                    />\n                    <rect\n                      x={x(s.start)}\n                      y={y}\n                      width={Math.max(4, round(x(s.end) - x(s.start)))}\n                      height={LANE - 10}\n                      rx=\"3\"\n                      fill={fill}\n                      opacity={running && (sweep ?? 0) < s.start ? 0.25 : 1}\n                      className=\"motion-safe:transition-[fill] motion-safe:duration-150\"\n                    />\n                  </g>\n                );\n              })}\n              {running && (\n                <line\n                  x1={x(sweep ?? 0)}\n                  x2={x(sweep ?? 0)}\n                  y1={AXIS - 4}\n                  y2={chartH}\n                  stroke={c.text}\n                  strokeWidth=\"1.25\"\n                />\n              )}\n            </svg>\n          </div>\n\n          <p className=\"m-0 mt-4 flex items-center gap-2 text-[13.5px] leading-[20px] font-[510] tracking-[-0.011em] @3xl:hidden\">\n            <Dot size={8} color={steps[at]?.state === \"failed\" ? RED : GREEN} />\n            <span className=\"truncate\">{steps[at]?.name}</span>\n          </p>\n          <div className=\"mt-3 flex flex-wrap items-center justify-between gap-3 @3xl:mt-5\">\n            <div className=\"flex items-center gap-2 @3xl:hidden\">\n              <button\n                type=\"button\"\n                aria-label=\"Previous step\"\n                disabled={at === 0}\n                onClick={() => go(-1)}\n                className={`h-8 cursor-pointer rounded-full border-0 px-3 text-[12.5px] leading-[18px] font-[510] disabled:cursor-default ${RING}`}\n                style={{\n                  background: c.chip,\n                  color: at === 0 ? c.faint : c.soft,\n                }}\n              >\n                Back\n              </button>\n              <span\n                className=\"text-[12.5px] leading-[18px] tabular-nums\"\n                style={{ color: c.sub }}\n              >\n                {at + 1} of {steps.length}\n              </span>\n              <button\n                type=\"button\"\n                aria-label=\"Next step\"\n                disabled={at === steps.length - 1}\n                onClick={() => go(1)}\n                className={`h-8 cursor-pointer rounded-full border-0 px-3 text-[12.5px] leading-[18px] font-[510] disabled:cursor-default ${RING}`}\n                style={{\n                  background: c.chip,\n                  color: at === steps.length - 1 ? c.faint : c.soft,\n                }}\n              >\n                Next\n              </button>\n            </div>\n            <div\n              role=\"group\"\n              aria-label=\"Step details\"\n              className=\"relative grid h-8 grid-cols-3 rounded-full\"\n              style={{ padding: 2, width: 228, background: c.chip }}\n            >\n              <span\n                aria-hidden=\"true\"\n                className=\"absolute rounded-full motion-safe:transition-transform motion-safe:duration-300\"\n                style={{\n                  top: 2,\n                  bottom: 2,\n                  left: 2,\n                  width: \"calc((100% - 4px) / 3)\",\n                  transform: `translateX(${tabIndex * 100}%)`,\n                  background: c.tab,\n                }}\n              />\n              {TABS.map((t) => (\n                <button\n                  key={t.id}\n                  type=\"button\"\n                  data-tab={t.id}\n                  aria-pressed={tab === t.id}\n                  onClick={() => setTab(t.id)}\n                  className={`relative cursor-pointer rounded-full border-0 bg-transparent text-[12.5px] leading-[18px] font-[510] tracking-[-0.011em] motion-safe:transition-colors motion-safe:duration-200 ${RING}`}\n                  style={{ color: tab === t.id ? c.text : c.sub }}\n                >\n                  {t.label}\n                </button>\n              ))}\n            </div>\n          </div>\n\n          {/* Every step and tab shares one cell, so nothing here changes the block's height. */}\n          <div\n            className=\"mt-3 grid rounded-xl\"\n            style={{\n              background: c.inset,\n              gridTemplateColumns: \"minmax(0, 1fr)\",\n            }}\n          >\n            {steps.flatMap((s) =>\n              TABS.map((t) => {\n                const on = s.id === selected && t.id === tab;\n                const text =\n                  t.id === \"input\"\n                    ? s.input\n                    : t.id === \"output\"\n                      ? s.output\n                      : s.log.join(\"\\n\");\n                return (\n                  <pre\n                    key={`${s.id}-${t.id}`}\n                    aria-hidden={!on}\n                    className={`m-0 overflow-x-auto p-3.5 text-[12.5px] leading-[20px] [grid-area:1/1] ${on ? \"visible\" : \"invisible\"}`}\n                    style={{\n                      fontFamily: MONO,\n                      color:\n                        s.state === \"failed\" && t.id === \"output\"\n                          ? RED\n                          : c.soft,\n                    }}\n                  >\n                    {text}\n                  </pre>\n                );\n              }),\n            )}\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}