{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "function-call-receipt",
  "title": "Function Call Receipt",
  "description": "A clear record of one tool call by an AI agent: what went in, what came back, how long each part took, and what it cost, set out like a receipt.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/function-call-receipt/function-call-receipt.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ReceiptPhase {\n  label: string;\n  /** In milliseconds. */\n  ms: number;\n}\n\nexport interface FunctionCallReceiptProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  /** The function that was called. */\n  name?: string;\n  /** Who called it and when. */\n  caller?: string;\n  input?: Record<string, unknown>;\n  output?: Record<string, unknown>;\n  phases?: ReceiptPhase[];\n  /** Totals for the foot of the receipt. */\n  lines?: { label: string; value: string }[];\n  onReplay?: () => void;\n}\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 BLUE = \"#4EA7FC\";\nconst GREEN = \"#27A644\";\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\nconst BAR_H = 8;\n\nconst PALETTES = {\n  dark: {\n    card: \"#08090A\",\n    inset: \"#0F1011\",\n    border: \"rgba(255,255,255,0.08)\",\n    dash: \"rgba(255,255,255,0.14)\",\n    track: \"rgba(255,255,255,0.08)\",\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    string: \"#A3ADF0\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    inset: \"#F7F8F8\",\n    border: \"rgba(8,9,10,0.08)\",\n    dash: \"rgba(8,9,10,0.16)\",\n    track: \"rgba(8,9,10,0.08)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.04)\",\n    tab: \"#FFFFFF\",\n    string: \"#4A55B8\",\n  },\n};\n\nconst DEFAULT_INPUT = {\n  order_id: \"5120\",\n  amount: 84,\n  currency: \"USD\",\n  reason: \"damaged_in_transit\",\n  notify_customer: true,\n};\n\nconst DEFAULT_OUTPUT = {\n  refund_id: \"rf_8842\",\n  status: \"succeeded\",\n  arrives_in_days: 3,\n  email_sent: true,\n};\n\nconst DEFAULT_PHASES: ReceiptPhase[] = [\n  { label: \"Checked permissions\", ms: 12 },\n  { label: \"Called the payments API\", ms: 214 },\n  { label: \"Read the response\", ms: 9 },\n];\n\nconst DEFAULT_LINES = [\n  { label: \"Tokens\", value: \"1,204\" },\n  { label: \"Attempts\", value: \"1 of 3\" },\n  { label: \"Cost\", value: \"$0.004\" },\n];\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\nfunction Json({\n  value,\n  c,\n}: {\n  value: Record<string, unknown>;\n  c: (typeof PALETTES)[\"dark\"];\n}) {\n  const entries = Object.entries(value);\n  return (\n    <>\n      <span style={{ color: c.faint }}>{\"{\"}</span>\n      {\"\\n\"}\n      {entries.map(([key, item], i) => (\n        <React.Fragment key={key}>\n          {\"  \"}\n          <span style={{ color: c.soft }}>{key}</span>\n          <span style={{ color: c.faint }}>: </span>\n          <span style={{ color: typeof item === \"string\" ? c.string : BLUE }}>\n            {JSON.stringify(item)}\n          </span>\n          <span style={{ color: c.faint }}>\n            {i < entries.length - 1 ? \",\" : \"\"}\n          </span>\n          {\"\\n\"}\n        </React.Fragment>\n      ))}\n      <span style={{ color: c.faint }}>{\"}\"}</span>\n    </>\n  );\n}\n\nexport function FunctionCallReceipt({\n  theme = \"dark\",\n  name = \"refund_order\",\n  caller = \"Called by Tally at 13:20\",\n  input = DEFAULT_INPUT,\n  output = DEFAULT_OUTPUT,\n  phases = DEFAULT_PHASES,\n  lines = DEFAULT_LINES,\n  onReplay,\n  className,\n  style,\n  ...rest\n}: FunctionCallReceiptProps) {\n  const c = PALETTES[theme];\n  const reduce = useReducedMotion();\n  const [tab, setTab] = React.useState<\"input\" | \"output\">(\"output\");\n  const [copied, setCopied] = React.useState(false);\n  const [progress, setProgress] = React.useState(1);\n  const [wrapRef, width] = useWidth<HTMLDivElement>(440);\n  const raf = React.useRef(0);\n  const copyTimer = React.useRef(0);\n\n  const total = phases.reduce((sum, p) => sum + p.ms, 0);\n  const running = progress < 1;\n  const shownMs = Math.round(progress * total);\n  const scale = (ms: number) => (total ? (ms / total) * width : 0);\n\n  React.useEffect(\n    () => () => {\n      cancelAnimationFrame(raf.current);\n      window.clearTimeout(copyTimer.current);\n    },\n    [],\n  );\n\n  const replay = () => {\n    onReplay?.();\n    if (reduce) return;\n    cancelAnimationFrame(raf.current);\n    const began = performance.now();\n    const tick = (now: number) => {\n      const p = Math.min(1, (now - began) / 1400);\n      setProgress(p);\n      if (p < 1) raf.current = requestAnimationFrame(tick);\n    };\n    setProgress(0);\n    raf.current = requestAnimationFrame(tick);\n  };\n\n  const copy = async () => {\n    const text = JSON.stringify(tab === \"input\" ? input : output, null, 2);\n    await navigator.clipboard?.writeText(text).catch(() => {});\n    setCopied(true);\n    window.clearTimeout(copyTimer.current);\n    copyTimer.current = window.setTimeout(() => setCopied(false), 1400);\n  };\n\n  const tabs = [\n    { id: \"input\" as const, label: \"Input\" },\n    { id: \"output\" as const, label: \"Output\" },\n  ];\n\n  const bars = phases.map((p, i) => ({\n    ...p,\n    start: phases.slice(0, i).reduce((sum, x) => sum + x.ms, 0),\n  }));\n\n  return (\n    <section\n      aria-label={`${name} receipt`}\n      className={`@container w-full rounded-2xl border ${className ?? \"\"}`}\n      style={{\n        background: c.card,\n        borderColor: c.border,\n        color: c.text,\n        fontFamily: FONT,\n        ...style,\n      }}\n      {...rest}\n    >\n      <div className=\"p-5 pb-4\">\n        <div className=\"flex items-start justify-between gap-4\">\n          <header className=\"min-w-0\">\n            <h3\n              className=\"m-0 truncate text-[17px] leading-[26px] font-[510] tracking-[-0.012em]\"\n              style={{ fontFamily: MONO }}\n            >\n              {name}()\n            </h3>\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 : GREEN} />\n              <span className=\"truncate\">{running ? \"Running\" : caller}</span>\n            </p>\n          </header>\n          <div className=\"shrink-0 text-right\">\n            <p className=\"m-0 text-[32px] leading-[32px] font-[510] tracking-[-0.022em] tabular-nums\">\n              {shownMs} ms\n            </p>\n            <p\n              className=\"m-0 mt-1.5 text-[13px] leading-[20px]\"\n              style={{ color: c.sub }}\n            >\n              {running ? \"So far\" : \"Total time\"}\n            </p>\n          </div>\n        </div>\n      </div>\n\n      <div className=\"px-5\">\n        <div\n          role=\"group\"\n          aria-label=\"Show\"\n          className=\"relative grid h-8 grid-cols-2 rounded-full\"\n          style={{ padding: 2, 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(50% - 2px)\",\n              transform: tab === \"output\" ? \"translateX(100%)\" : \"none\",\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\n        {/* Both views share one cell, so switching never changes the height. */}\n        <div\n          className=\"relative mt-2 grid rounded-xl\"\n          style={{\n            background: c.inset,\n            gridTemplateColumns: \"minmax(0, 1fr)\",\n          }}\n        >\n          {tabs.map((t) => (\n            <pre\n              key={t.id}\n              aria-hidden={tab !== t.id}\n              className={`m-0 overflow-x-auto p-3.5 pr-16 text-[12.5px] leading-[20px] [grid-area:1/1] motion-safe:transition-opacity motion-safe:duration-200 ${tab === t.id ? \"visible opacity-100\" : \"invisible opacity-0\"}`}\n              style={{ fontFamily: MONO }}\n            >\n              <Json value={t.id === \"input\" ? input : output} c={c} />\n            </pre>\n          ))}\n          <button\n            type=\"button\"\n            data-copy=\"\"\n            onClick={copy}\n            className={`absolute cursor-pointer rounded-full border-0 text-[12px] leading-[16px] font-[510] ${RING}`}\n            style={{\n              top: 8,\n              right: 8,\n              width: 58,\n              height: 26,\n              background: c.chip,\n              color: copied ? GREEN : c.soft,\n            }}\n          >\n            {copied ? \"Copied\" : \"Copy\"}\n          </button>\n        </div>\n      </div>\n\n      <div className=\"px-5 pt-4\">\n        <div ref={wrapRef} className=\"w-full\" style={{ height: BAR_H }}>\n          <svg\n            role=\"img\"\n            aria-label={phases.map((p) => `${p.label}, ${p.ms} ms`).join(\". \")}\n            width={width}\n            height={BAR_H}\n            className=\"block\"\n          >\n            <rect width={width} height={BAR_H} rx=\"3\" fill={c.track} />\n            {bars.map((p, i) => {\n              const from = p.start / total;\n              const share = Math.max(\n                0,\n                Math.min(p.ms / total, progress - from),\n              );\n              return (\n                <rect\n                  key={p.label}\n                  x={Math.round(scale(p.start))}\n                  width={Math.max(0, Math.round(share * width) - 1)}\n                  height={BAR_H}\n                  rx=\"2\"\n                  fill={[ACCENT, BLUE, c.sub][i % 3]}\n                />\n              );\n            })}\n          </svg>\n        </div>\n        <ul className=\"m-0 mt-2 list-none p-0\">\n          {bars.map((p, i) => (\n            <li\n              key={p.label}\n              className=\"flex items-center justify-between gap-3 py-[3px] text-[13px] leading-[20px] tracking-[-0.011em]\"\n            >\n              <span className=\"flex min-w-0 items-center gap-2\">\n                <Dot size={6} color={[ACCENT, BLUE, c.sub][i % 3]} />\n                <span className=\"truncate\" style={{ color: c.sub }}>\n                  {p.label}\n                </span>\n              </span>\n              <span className=\"shrink-0 tabular-nums\" style={{ color: c.soft }}>\n                {p.ms} ms\n              </span>\n            </li>\n          ))}\n        </ul>\n      </div>\n\n      {/* The tear line is what makes it read as a receipt. */}\n      <svg aria-hidden=\"true\" width=\"100%\" height=\"1\" className=\"mt-3 block\">\n        <line\n          x1=\"0\"\n          x2=\"100%\"\n          y1=\"0.5\"\n          y2=\"0.5\"\n          stroke={c.dash}\n          strokeDasharray=\"4 4\"\n        />\n      </svg>\n\n      <dl className=\"m-0 px-5 pt-3\">\n        {lines.map((line) => (\n          <div\n            key={line.label}\n            className=\"flex items-center justify-between gap-3 py-[3px] text-[13px] leading-[20px] tracking-[-0.011em]\"\n          >\n            <dt style={{ color: c.sub }}>{line.label}</dt>\n            <dd className=\"m-0 font-[510] tabular-nums\">{line.value}</dd>\n          </div>\n        ))}\n      </dl>\n\n      <div className=\"p-5 pt-3\">\n        <button\n          type=\"button\"\n          data-replay=\"\"\n          disabled={running}\n          onClick={replay}\n          className={`h-9 w-full cursor-pointer rounded-full border-0 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] disabled:cursor-default ${RING}`}\n          style={{ background: c.chip, color: running ? c.faint : c.soft }}\n        >\n          {running ? \"Running\" : \"Run this call again\"}\n        </button>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}