{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tool-call-card",
  "type": "registry:component",
  "title": "Tool Call Card",
  "description": "A collapsible card for a tool invocation with status, duration, syntax-colored arguments and result, and a copy button.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "agent-kit",
    "tool",
    "function call",
    "json",
    "agent",
    "collapsible",
    "status"
  ],
  "docs": "https://hyperblur.dev/effects/tool-call-card",
  "files": [
    {
      "path": "registry/hyperblur/tool-call-card.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/tool-call-card.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ToolCallCardProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\"> {\n  name?: string;\n  status?: \"running\" | \"done\" | \"error\";\n  duration?: number | string;\n  args?: Record<string, unknown> | unknown[] | string;\n  result?: Record<string, unknown> | unknown[] | string;\n  defaultOpen?: boolean;\n  color?: string;\n}\n\nconst css = `\n@keyframes hb-tcc-spin { to { transform: rotate(360deg); } }\n@keyframes hb-tcc-draw { from { stroke-dashoffset: 16; } to { stroke-dashoffset: 0; } }\n.hb-tcc {\n  box-sizing: border-box;\n  width: 100%;\n  overflow: hidden;\n  border: 1px solid #262626;\n  border-radius: 12px;\n  color: #ededed;\n  font-family: var(--font-sans), ui-sans-serif, system-ui, sans-serif;\n  font-size: 13px;\n  background: #111111;\n}\n.hb-tcc-head { margin: 0; font: inherit; }\n.hb-tcc-toggle {\n  display: flex;\n  align-items: center;\n  gap: 10px;\n  box-sizing: border-box;\n  width: 100%;\n  margin: 0;\n  padding: 10px 12px;\n  border: 0;\n  color: inherit;\n  font: inherit;\n  text-align: left;\n  cursor: pointer;\n  background: transparent;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-tcc-toggle:hover { background: #151515; }\n.hb-tcc-toggle:focus-visible { outline: 2px solid var(--hb-tcc-accent, #2f7bff); outline-offset: -2px; }\n.hb-tcc-icon {\n  display: grid;\n  flex: 0 0 auto;\n  place-items: center;\n  width: 22px;\n  height: 22px;\n  border-radius: 6px;\n  color: #8b5cf6;\n  background: rgba(139,92,246,.14);\n}\n.hb-tcc-icon svg { width: 13px; height: 13px; }\n.hb-tcc-name {\n  flex: 1 1 auto;\n  min-width: 0;\n  overflow: hidden;\n  font-family: var(--font-mono), ui-monospace, SFMono-Regular, Menlo, monospace;\n  font-size: 12.5px;\n  text-overflow: ellipsis;\n  white-space: nowrap;\n}\n.hb-tcc-meta { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 6px; color: #8f8f8f; font-size: 11.5px; }\n.hb-tcc-status { display: inline-flex; align-items: center; gap: 5px; }\n.hb-tcc-status[data-status=\"done\"] { color: #34d399; }\n.hb-tcc-status[data-status=\"error\"] { color: #f87171; }\n.hb-tcc-status[data-status=\"running\"] { color: var(--hb-tcc-accent, #2f7bff); }\n.hb-tcc-status svg { width: 12px; height: 12px; }\n.hb-tcc-spinner {\n  width: 11px;\n  height: 11px;\n  border: 1.5px solid rgba(255,255,255,.14);\n  border-top-color: currentColor;\n  border-radius: 50%;\n  animation: hb-tcc-spin .8s linear infinite;\n}\n.hb-tcc-check { stroke-dasharray: 16; animation: hb-tcc-draw .4s ease both; }\n.hb-tcc-time { font-family: var(--font-mono), ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }\n.hb-tcc-chevron {\n  width: 14px;\n  height: 14px;\n  color: #8f8f8f;\n  transition: transform .3s cubic-bezier(.2, .9, .2, 1);\n}\n.hb-tcc-toggle[aria-expanded=\"true\"] .hb-tcc-chevron { transform: rotate(180deg); }\n.hb-tcc-panel {\n  display: grid;\n  grid-template-rows: 0fr;\n  visibility: hidden;\n  transition: grid-template-rows .3s cubic-bezier(.2, .9, .2, 1), visibility 0s linear .3s;\n}\n.hb-tcc[data-open=\"true\"] .hb-tcc-panel {\n  grid-template-rows: 1fr;\n  visibility: visible;\n  transition: grid-template-rows .3s cubic-bezier(.2, .9, .2, 1), visibility 0s linear 0s;\n}\n.hb-tcc-inner { min-height: 0; overflow: hidden; }\n.hb-tcc-row {\n  position: relative;\n  display: grid;\n  grid-template-columns: 48px minmax(0, 1fr);\n  gap: 8px;\n  padding: 8px 12px;\n  border-top: 1px solid #262626;\n  background: #0d0d0d;\n}\n.hb-tcc-label {\n  padding-top: 1px;\n  color: #8f8f8f;\n  font-size: 10px;\n  font-weight: 600;\n  letter-spacing: .06em;\n  text-transform: uppercase;\n}\n.hb-tcc-code {\n  margin: 0;\n  max-height: 132px;\n  overflow: auto;\n  color: #ededed;\n  font-family: var(--font-mono), ui-monospace, SFMono-Regular, Menlo, monospace;\n  font-size: 11.5px;\n  line-height: 16px;\n  white-space: pre;\n  scrollbar-width: thin;\n  scrollbar-color: #2e2e2e transparent;\n}\n.hb-tcc-code:focus-visible { outline: 2px solid var(--hb-tcc-accent, #2f7bff); outline-offset: 2px; }\n.hb-tcc-row[data-has-copy=\"true\"] .hb-tcc-code { padding-right: 28px; }\n.hb-tcc-k { color: #7cb0ff; }\n.hb-tcc-s { color: #86d9a3; }\n.hb-tcc-n { color: #f0b072; }\n.hb-tcc-empty { color: #8f8f8f; font-size: 12px; }\n.hb-tcc-copy {\n  position: absolute;\n  top: 6px;\n  right: 8px;\n  display: grid;\n  place-items: center;\n  width: 24px;\n  height: 24px;\n  margin: 0;\n  padding: 0;\n  border: 1px solid #262626;\n  border-radius: 6px;\n  color: #8f8f8f;\n  cursor: pointer;\n  background: #171717;\n  transition: color .15s ease, border-color .15s ease;\n}\n.hb-tcc-copy:hover { color: #ededed; border-color: #333333; }\n.hb-tcc-copy[data-copied=\"true\"] { color: #34d399; }\n.hb-tcc-copy:focus-visible { outline: 2px solid var(--hb-tcc-accent, #2f7bff); outline-offset: 1px; }\n.hb-tcc-copy svg { width: 13px; height: 13px; }\n.hb-tcc-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-tcc-spinner { animation-duration: 2.4s; }\n  .hb-tcc-check { animation: none; }\n  .hb-tcc-panel, .hb-tcc[data-open=\"true\"] .hb-tcc-panel, .hb-tcc-chevron { transition: none; }\n}\n`;\n\nconst LABELS = { running: \"Running\", done: \"Done\", error: \"Failed\" } as const;\n\nfunction stringify(value: unknown): string {\n  if (value === undefined) return \"\";\n  if (typeof value === \"string\") {\n    try {\n      const parsed: unknown = JSON.parse(value);\n      if (parsed !== null && typeof parsed === \"object\") return stringify(parsed);\n    } catch {\n      return value;\n    }\n    return value;\n  }\n  const flat = JSON.stringify(value);\n  if (flat === undefined) return String(value);\n  if (flat.length <= 44) {\n    return flat.replace(/^\\{/, \"{ \").replace(/\\}$/, \" }\").replace(/\":/g, '\": ').replace(/,\"/g, ', \"');\n  }\n  return JSON.stringify(value, null, 2);\n}\n\nfunction highlight(text: string): React.ReactNode[] {\n  const nodes: React.ReactNode[] = [];\n  const re = /(\"(?:[^\"\\\\]|\\\\.)*\")(\\s*:)?|(-?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?|\\btrue\\b|\\bfalse\\b|\\bnull\\b)/g;\n  let last = 0;\n  let match: RegExpExecArray | null;\n  while ((match = re.exec(text)) !== null) {\n    if (match.index > last) nodes.push(text.slice(last, match.index));\n    if (match[1] !== undefined) {\n      nodes.push(\n        <span key={match.index} className={match[2] ? \"hb-tcc-k\" : \"hb-tcc-s\"}>\n          {match[1]}\n        </span>\n      );\n      if (match[2]) nodes.push(match[2]);\n    } else {\n      nodes.push(\n        <span key={match.index} className=\"hb-tcc-n\">\n          {match[3]}\n        </span>\n      );\n    }\n    last = match.index + match[0].length;\n  }\n  if (last < text.length) nodes.push(text.slice(last));\n  return nodes;\n}\n\nfunction formatDuration(value: number | string | undefined) {\n  if (value === undefined) return \"\";\n  if (typeof value === \"string\") return value;\n  if (value >= 1000) return `${(value / 1000).toFixed(value >= 10000 ? 0 : 1)}s`;\n  return `${Math.round(value)}ms`;\n}\n\nexport function ToolCallCard({\n  name = \"tool_call\",\n  status = \"done\",\n  duration,\n  args,\n  result,\n  defaultOpen = false,\n  color = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: ToolCallCardProps) {\n  const uid = React.useId();\n  const [open, setOpen] = React.useState(defaultOpen);\n  const [copied, setCopied] = React.useState(false);\n  const timer = React.useRef(0);\n\n  React.useEffect(() => () => window.clearTimeout(timer.current), []);\n\n  const argsText = stringify(args);\n  const resultText = stringify(result);\n  const time = formatDuration(duration);\n  const panelId = `${uid}-panel`;\n\n  async function copy() {\n    try {\n      await navigator.clipboard.writeText(resultText);\n      setCopied(true);\n      window.clearTimeout(timer.current);\n      timer.current = window.setTimeout(() => setCopied(false), 1500);\n    } catch {\n      setCopied(false);\n    }\n  }\n\n  return (\n    <div\n      className={`hb-tcc ${className}`}\n      style={{ \"--hb-tcc-accent\": color, ...style } as React.CSSProperties}\n      data-open={open}\n      data-status={status}\n      {...rest}\n    >\n      <style href=\"hb-tool-call-card\" precedence=\"default\">{css}</style>\n      <h3 className=\"hb-tcc-head\">\n        <button\n          className=\"hb-tcc-toggle\"\n          type=\"button\"\n          aria-expanded={open}\n          aria-controls={panelId}\n          onClick={() => setOpen((v) => !v)}\n        >\n          <span className=\"hb-tcc-icon\" aria-hidden=\"true\">\n            <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n              <path d=\"M9.6 3.4a3 3 0 0 0 3 3.9l-6.7 6.7a1.4 1.4 0 0 1-2-2l6.7-6.7a3 3 0 0 0-1-1.9z\" />\n            </svg>\n          </span>\n          <span className=\"hb-tcc-name\">{name}</span>\n          <span className=\"hb-tcc-meta\">\n            <span className=\"hb-tcc-status\" data-status={status}>\n              {status === \"running\" ? (\n                <span className=\"hb-tcc-spinner\" aria-hidden=\"true\" />\n              ) : status === \"done\" ? (\n                <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                  <path className=\"hb-tcc-check\" d=\"M3 8.5l3.2 3.2L13 4.8\" />\n                </svg>\n              ) : (\n                <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                  <path d=\"M4 4l8 8M12 4l-8 8\" />\n                </svg>\n              )}\n              <span className=\"hb-tcc-sr\">{LABELS[status]}</span>\n            </span>\n            {time ? <span className=\"hb-tcc-time\">{time}</span> : null}\n          </span>\n          <svg className=\"hb-tcc-chevron\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"M3.5 6l4.5 4.5L12.5 6\" />\n          </svg>\n        </button>\n      </h3>\n      <div id={panelId} className=\"hb-tcc-panel\" role=\"region\" aria-label={`${name} details`}>\n        <div className=\"hb-tcc-inner\">\n          <div className=\"hb-tcc-row\">\n            <span className=\"hb-tcc-label\">Args</span>\n            {argsText ? (\n              <pre className=\"hb-tcc-code\" tabIndex={0}>{highlight(argsText)}</pre>\n            ) : (\n              <span className=\"hb-tcc-empty\">No arguments</span>\n            )}\n          </div>\n          <div className=\"hb-tcc-row\" data-has-copy={resultText ? \"true\" : \"false\"}>\n            <span className=\"hb-tcc-label\">Result</span>\n            {resultText ? (\n              <>\n                <pre className=\"hb-tcc-code\" tabIndex={0}>{highlight(resultText)}</pre>\n                <button\n                  className=\"hb-tcc-copy\"\n                  type=\"button\"\n                  data-copied={copied}\n                  aria-label={copied ? \"Result copied\" : \"Copy result\"}\n                  onClick={copy}\n                >\n                  {copied ? (\n                    <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                      <path d=\"M3 8.5l3.2 3.2L13 4.8\" />\n                    </svg>\n                  ) : (\n                    <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                      <rect x=\"5.5\" y=\"5.5\" width=\"8\" height=\"8\" rx=\"1.8\" />\n                      <path d=\"M10.5 5.5V4a1.5 1.5 0 0 0-1.5-1.5H4A1.5 1.5 0 0 0 2.5 4v5A1.5 1.5 0 0 0 4 10.5h1.5\" />\n                    </svg>\n                  )}\n                </button>\n              </>\n            ) : (\n              <span className=\"hb-tcc-empty\">{status === \"running\" ? \"Waiting for result\" : \"No result\"}</span>\n            )}\n          </div>\n        </div>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}