{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent-approval-card",
  "type": "registry:component",
  "title": "Agent Approval Card",
  "description": "A human-in-the-loop card for a proposed agent action, with a before and after summary, an Approve step that asks for confirmation, inline editing and a countdown that rejects on its own.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "agent-kit",
    "agent",
    "approval",
    "human in the loop",
    "confirm",
    "countdown",
    "tool call"
  ],
  "docs": "https://hyperblur.dev/effects/agent-approval-card",
  "files": [
    {
      "path": "registry/hyperblur/agent-approval-card.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/agent-approval-card.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ApprovalChange {\n  label: string;\n  before?: string;\n  after: string;\n}\n\nexport interface AgentApprovalCardProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\"> {\n  title?: string;\n  summary?: string;\n  tool?: string;\n  changes?: ApprovalChange[];\n  timeout?: number;\n  resetAfter?: number;\n  accent?: string;\n  onApprove?: (changes: ApprovalChange[]) => void;\n  onReject?: (reason: \"manual\" | \"timeout\") => void;\n  onEdit?: (changes: ApprovalChange[]) => void;\n}\n\ntype Mode = \"idle\" | \"confirm\" | \"edit\" | \"approved\" | \"rejected\";\n\nconst defaultChanges: ApprovalChange[] = [\n  { label: \"amount\", before: \"$0.00\", after: \"$48.00\" },\n  { label: \"reason\", after: \"damaged_on_arrival\" },\n];\n\nconst css = `\n.hb-yf2 {\n  --hb-yf2-ok: #3ecf8e;\n  --hb-yf2-err: #ff5d5d;\n  position: relative;\n  box-sizing: border-box;\n  display: flex;\n  flex-direction: column;\n  gap: 6px;\n  width: 100%;\n  padding: 12px 14px 12px;\n  overflow: hidden;\n  font-family: inherit;\n  font-size: 12px;\n  line-height: 1.35;\n  color: #ededed;\n  background: #111111;\n  border: 1px solid #262626;\n  border-radius: 14px;\n  text-align: left;\n}\n.hb-yf2 *, .hb-yf2 *::before, .hb-yf2 *::after { box-sizing: border-box; font-family: inherit; }\n.hb-yf2-count { position: absolute; top: 0; left: 0; right: 0; height: 3px; background: #1c1c1c; }\n.hb-yf2-fill {\n  height: 100%;\n  width: var(--hb-yf2-p, 100%);\n  background: var(--hb-yf2-a, #2f7bff);\n  transition: width 0.1s linear, background-color 0.3s ease;\n}\n.hb-yf2[data-low=\"true\"] .hb-yf2-fill { background: var(--hb-yf2-err); }\n.hb-yf2[data-paused=\"true\"] .hb-yf2-fill { opacity: 0.45; }\n.hb-yf2-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 2px; }\n.hb-yf2-title { display: flex; align-items: center; gap: 7px; min-width: 0; margin: 0; font-size: 13px; font-weight: 600; letter-spacing: -0.01em; }\n.hb-yf2-title span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-yf2-shield { flex: none; width: 15px; height: 15px; color: var(--hb-yf2-a, #2f7bff); }\n.hb-yf2-tool {\n  flex: none;\n  padding: 2px 7px;\n  font-family: var(--font-geist-mono, ui-monospace, SFMono-Regular, Menlo, monospace);\n  font-size: 10.5px;\n  color: #a1a1a1;\n  background: #171717;\n  border: 1px solid #262626;\n  border-radius: 999px;\n}\n.hb-yf2-sum { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #a1a1a1; }\n.hb-yf2-diff { border: 1px solid #222222; border-radius: 10px; background: #0d0d0d; overflow: hidden; }\n.hb-yf2-dh { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 10px; font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase; color: #6b6b6b; border-bottom: 1px solid #1c1c1c; }\n.hb-yf2-time { font-variant-numeric: tabular-nums; letter-spacing: 0.02em; text-transform: none; color: #8f8f8f; }\n.hb-yf2[data-low=\"true\"] .hb-yf2-time { color: var(--hb-yf2-err); }\n.hb-yf2-row { display: grid; grid-template-columns: 56px minmax(0, 1fr); align-items: center; gap: 8px; min-height: 26px; padding: 3px 10px; }\n.hb-yf2-row + .hb-yf2-row { border-top: 1px solid #181818; }\n.hb-yf2-key { font-family: var(--font-geist-mono, ui-monospace, SFMono-Regular, Menlo, monospace); font-size: 11px; color: #8f8f8f; }\n.hb-yf2-val { display: flex; align-items: center; gap: 6px; min-width: 0; font-family: var(--font-geist-mono, ui-monospace, SFMono-Regular, Menlo, monospace); font-size: 11px; }\n.hb-yf2-old { flex: none; padding: 1px 5px; color: #ff9a9a; text-decoration: line-through; background: rgba(255, 93, 93, 0.1); border-radius: 4px; }\n.hb-yf2-arrow { flex: none; color: #6b6b6b; }\n.hb-yf2-new { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 1px 5px; color: #7de6b4; background: rgba(62, 207, 142, 0.1); border-radius: 4px; }\n.hb-yf2-input {\n  width: 100%;\n  min-width: 0;\n  padding: 3px 7px;\n  font: inherit;\n  font-family: var(--font-geist-mono, ui-monospace, SFMono-Regular, Menlo, monospace);\n  font-size: 11px;\n  color: #ededed;\n  background: #171717;\n  border: 1px solid #333333;\n  border-radius: 6px;\n  outline: none;\n}\n.hb-yf2-input:focus-visible { border-color: var(--hb-yf2-a, #2f7bff); box-shadow: 0 0 0 2px color-mix(in srgb, var(--hb-yf2-a, #2f7bff) 30%, transparent); }\n.hb-yf2-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 30px; }\n.hb-yf2-grp { display: flex; align-items: center; gap: 6px; }\n.hb-yf2-note { min-width: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; color: #a1a1a1; }\n.hb-yf2-btn {\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  gap: 5px;\n  height: 30px;\n  margin: 0;\n  padding: 0 12px;\n  font: inherit;\n  font-size: 12px;\n  font-weight: 600;\n  color: #ededed;\n  white-space: nowrap;\n  background: transparent;\n  border: 1px solid #2f2f2f;\n  border-radius: 999px;\n  cursor: pointer;\n  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;\n}\n.hb-yf2-btn:hover { background: rgba(255, 255, 255, 0.06); border-color: #444444; }\n.hb-yf2-btn:active { transform: scale(0.97); }\n.hb-yf2-btn:focus-visible { outline: 2px solid var(--hb-yf2-a, #2f7bff); outline-offset: 2px; }\n.hb-yf2-btn svg { width: 12px; height: 12px; }\n.hb-yf2-btn[data-kind=\"ghost\"] { border-color: transparent; color: #a1a1a1; padding: 0 8px; }\n.hb-yf2-btn[data-kind=\"reject\"]:hover { color: #ff9a9a; border-color: rgba(255, 93, 93, 0.5); background: rgba(255, 93, 93, 0.08); }\n.hb-yf2-btn[data-kind=\"primary\"] { color: #fff; background: var(--hb-yf2-a, #2f7bff); border-color: var(--hb-yf2-a, #2f7bff); }\n.hb-yf2-btn[data-kind=\"primary\"]:hover { background: color-mix(in srgb, var(--hb-yf2-a, #2f7bff) 86%, #fff); }\n.hb-yf2-result { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 12px; font-weight: 500; animation: hb-yf2-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both; }\n.hb-yf2-dot { flex: none; display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; color: #0a0a0a; }\n.hb-yf2-dot svg { width: 10px; height: 10px; }\n.hb-yf2[data-mode=\"approved\"] .hb-yf2-dot { background: var(--hb-yf2-ok); }\n.hb-yf2[data-mode=\"rejected\"] .hb-yf2-dot { background: var(--hb-yf2-err); }\n.hb-yf2[data-mode=\"approved\"] .hb-yf2-diff, .hb-yf2[data-mode=\"rejected\"] .hb-yf2-diff { opacity: 0.55; }\n.hb-yf2-diff { transition: opacity 0.3s ease; }\n@keyframes hb-yf2-pop { from { opacity: 0; transform: translateY(4px) scale(0.96); } to { opacity: 1; transform: none; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-yf2-fill, .hb-yf2-btn, .hb-yf2-diff { transition: none; }\n  .hb-yf2-result { animation: none; }\n}\n`;\n\nexport function AgentApprovalCard({\n  title = \"Refund order #4821\",\n  summary = \"Partial refund to the card on file.\",\n  tool = \"payments.refund\",\n  changes = defaultChanges,\n  timeout = 30,\n  resetAfter = 0,\n  accent = \"#2f7bff\",\n  onApprove,\n  onReject,\n  onEdit,\n  className = \"\",\n  style,\n  onKeyDown,\n  onPointerEnter,\n  onPointerLeave,\n  onFocus,\n  onBlur,\n  ...rest\n}: AgentApprovalCardProps) {\n  const total = Math.max(0, timeout) * 1000;\n  const [mode, setMode] = React.useState<Mode>(\"idle\");\n  const [reason, setReason] = React.useState<\"manual\" | \"timeout\">(\"manual\");\n  const [remaining, setRemaining] = React.useState(total);\n  const [values, setValues] = React.useState<string[]>(() => changes.map((c) => c.after));\n  const [draft, setDraft] = React.useState<string[]>([]);\n  const [hover, setHover] = React.useState(false);\n  const [focus, setFocus] = React.useState(false);\n  const confirmRef = React.useRef<HTMLButtonElement>(null);\n  const firstInput = React.useRef<HTMLInputElement>(null);\n  const notified = React.useRef(false);\n\n  const expired = total > 0 && remaining <= 0 && mode === \"idle\";\n  const view: Mode = expired ? \"rejected\" : mode;\n  const viewReason = expired ? \"timeout\" : reason;\n  const paused = hover || focus || mode !== \"idle\";\n  const spent = remaining <= 0;\n\n  const current = React.useMemo(\n    () => changes.map((c, i) => ({ ...c, after: values[i] ?? c.after })),\n    [changes, values],\n  );\n\n  React.useEffect(() => {\n    if (total <= 0 || paused || mode !== \"idle\" || spent) return;\n    const id = window.setInterval(() => setRemaining((r) => Math.max(0, r - 100)), 100);\n    return () => window.clearInterval(id);\n  }, [total, paused, mode, spent]);\n\n  React.useEffect(() => {\n    if (expired && !notified.current) {\n      notified.current = true;\n      onReject?.(\"timeout\");\n    }\n  }, [expired, onReject]);\n\n  React.useEffect(() => {\n    if (mode === \"confirm\") confirmRef.current?.focus({ preventScroll: true });\n    if (mode === \"edit\") firstInput.current?.focus({ preventScroll: true });\n  }, [mode]);\n\n  React.useEffect(() => {\n    if (resetAfter <= 0 || (view !== \"approved\" && view !== \"rejected\")) return;\n    const id = window.setTimeout(() => {\n      notified.current = false;\n      setMode(\"idle\");\n      setReason(\"manual\");\n      setRemaining(total);\n      setValues(changes.map((c) => c.after));\n    }, resetAfter);\n    return () => window.clearTimeout(id);\n  }, [view, resetAfter, total, changes]);\n\n  function reset() {\n    notified.current = false;\n    setMode(\"idle\");\n    setReason(\"manual\");\n    setRemaining(total);\n  }\n\n  function approve() {\n    setMode(\"approved\");\n    onApprove?.(current);\n  }\n\n  function reject() {\n    notified.current = true;\n    setReason(\"manual\");\n    setMode(\"rejected\");\n    onReject?.(\"manual\");\n  }\n\n  function saveEdit() {\n    setValues(draft);\n    setMode(\"idle\");\n    onEdit?.(changes.map((c, i) => ({ ...c, after: draft[i] ?? c.after })));\n  }\n\n  const seconds = Math.ceil(remaining / 1000);\n  const pct = total > 0 ? (remaining / total) * 100 : 100;\n  const low = total > 0 && remaining <= total * 0.25;\n\n  return (\n    <>\n      <style href=\"hb-agent-approval-card\" precedence=\"default\">{css}</style>\n      <div\n        role=\"group\"\n        aria-label={title}\n        className={`hb-yf2 ${className}`}\n        data-mode={view}\n        data-low={low && view === \"idle\"}\n        data-paused={paused && view === \"idle\"}\n        style={\n          {\n            \"--hb-yf2-a\": accent,\n            \"--hb-yf2-p\": `${pct.toFixed(2)}%`,\n            ...style,\n          } as React.CSSProperties\n        }\n        onPointerEnter={(e) => {\n          onPointerEnter?.(e);\n          setHover(true);\n        }}\n        onPointerLeave={(e) => {\n          onPointerLeave?.(e);\n          setHover(false);\n        }}\n        onFocus={(e) => {\n          onFocus?.(e);\n          setFocus(true);\n        }}\n        onBlur={(e) => {\n          onBlur?.(e);\n          if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setFocus(false);\n        }}\n        onKeyDown={(e) => {\n          onKeyDown?.(e);\n          if (e.key === \"Escape\" && (mode === \"confirm\" || mode === \"edit\")) {\n            e.stopPropagation();\n            setMode(\"idle\");\n          }\n        }}\n        {...rest}\n      >\n        {total > 0 ? (\n          <div className=\"hb-yf2-count\" aria-hidden=\"true\">\n            <div className=\"hb-yf2-fill\" />\n          </div>\n        ) : null}\n        <div className=\"hb-yf2-top\">\n          <h3 className=\"hb-yf2-title\">\n            <svg className=\"hb-yf2-shield\" viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\">\n              <path d=\"M8 1.6l5 1.9v4c0 3-2 5.2-5 6.9-3-1.7-5-3.9-5-6.9v-4l5-1.9z\" stroke=\"currentColor\" strokeWidth=\"1.4\" strokeLinejoin=\"round\" />\n              <path d=\"M5.8 8.1l1.6 1.6 2.9-3.2\" stroke=\"currentColor\" strokeWidth=\"1.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n            </svg>\n            <span>{title}</span>\n          </h3>\n          <span className=\"hb-yf2-tool\">{tool}</span>\n        </div>\n        <p className=\"hb-yf2-sum\">{summary}</p>\n        <div className=\"hb-yf2-diff\">\n          <div className=\"hb-yf2-dh\">\n            <span>Proposed changes</span>\n            {total > 0 && view !== \"approved\" && view !== \"rejected\" ? (\n              <span className=\"hb-yf2-time\" role=\"timer\" aria-live=\"off\">\n                {paused ? \"paused\" : `auto-reject ${seconds}s`}\n              </span>\n            ) : null}\n          </div>\n          {changes.map((c, i) => (\n            <div className=\"hb-yf2-row\" key={c.label}>\n              <span className=\"hb-yf2-key\">{c.label}</span>\n              <span className=\"hb-yf2-val\">\n                {mode === \"edit\" ? (\n                  <input\n                    ref={i === 0 ? firstInput : undefined}\n                    className=\"hb-yf2-input\"\n                    aria-label={c.label}\n                    value={draft[i] ?? \"\"}\n                    onChange={(e) => {\n                      const next = draft.slice();\n                      next[i] = e.target.value;\n                      setDraft(next);\n                    }}\n                    onKeyDown={(e) => {\n                      if (e.key === \"Enter\") saveEdit();\n                    }}\n                  />\n                ) : (\n                  <>\n                    {c.before ? (\n                      <>\n                        <span className=\"hb-yf2-old\">{c.before}</span>\n                        <span className=\"hb-yf2-arrow\" aria-hidden=\"true\">→</span>\n                      </>\n                    ) : null}\n                    <span className=\"hb-yf2-new\">{values[i] ?? c.after}</span>\n                  </>\n                )}\n              </span>\n            </div>\n          ))}\n        </div>\n        <div className=\"hb-yf2-foot\">\n          {view === \"approved\" || view === \"rejected\" ? (\n            <>\n              <div className=\"hb-yf2-result\" role=\"status\">\n                <span className=\"hb-yf2-dot\" aria-hidden=\"true\">\n                  <svg viewBox=\"0 0 10 10\" fill=\"none\">\n                    {view === \"approved\" ? (\n                      <path d=\"M2 5.2l2 2 4-4.4\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n                    ) : (\n                      <path d=\"M2.6 2.6l4.8 4.8M7.4 2.6l-4.8 4.8\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" />\n                    )}\n                  </svg>\n                </span>\n                <span>\n                  {view === \"approved\"\n                    ? \"Approved, running now\"\n                    : viewReason === \"timeout\"\n                      ? \"Auto-rejected, no reply\"\n                      : \"Rejected, agent notified\"}\n                </span>\n              </div>\n              {resetAfter <= 0 ? (\n                <button type=\"button\" className=\"hb-yf2-btn\" data-kind=\"ghost\" onClick={reset}>\n                  Review again\n                </button>\n              ) : null}\n            </>\n          ) : mode === \"confirm\" ? (\n            <>\n              <p className=\"hb-yf2-note\">Run {tool} with these values?</p>\n              <span className=\"hb-yf2-grp\">\n                <button type=\"button\" className=\"hb-yf2-btn\" data-kind=\"ghost\" onClick={() => setMode(\"idle\")}>\n                  Back\n                </button>\n                <button type=\"button\" ref={confirmRef} className=\"hb-yf2-btn\" data-kind=\"primary\" onClick={approve}>\n                  Confirm\n                </button>\n              </span>\n            </>\n          ) : mode === \"edit\" ? (\n            <>\n              <p className=\"hb-yf2-note\">Editing values</p>\n              <span className=\"hb-yf2-grp\">\n                <button type=\"button\" className=\"hb-yf2-btn\" data-kind=\"ghost\" onClick={() => setMode(\"idle\")}>\n                  Cancel\n                </button>\n                <button type=\"button\" className=\"hb-yf2-btn\" data-kind=\"primary\" onClick={saveEdit}>\n                  Save\n                </button>\n              </span>\n            </>\n          ) : (\n            <>\n              <button\n                type=\"button\"\n                className=\"hb-yf2-btn\"\n                data-kind=\"ghost\"\n                onClick={() => {\n                  setDraft(values.length ? values.slice() : changes.map((c) => c.after));\n                  setMode(\"edit\");\n                }}\n              >\n                <svg viewBox=\"0 0 12 12\" fill=\"none\" aria-hidden=\"true\">\n                  <path d=\"M2 10l.6-2.6L8.4 1.6a1.2 1.2 0 0 1 1.7 1.7L4.6 9.4 2 10z\" stroke=\"currentColor\" strokeWidth=\"1.2\" strokeLinejoin=\"round\" />\n                </svg>\n                Edit\n              </button>\n              <span className=\"hb-yf2-grp\">\n                <button type=\"button\" className=\"hb-yf2-btn\" data-kind=\"reject\" onClick={reject}>\n                  Reject\n                </button>\n                <button type=\"button\" className=\"hb-yf2-btn\" data-kind=\"primary\" onClick={() => setMode(\"confirm\")}>\n                  Approve\n                </button>\n              </span>\n            </>\n          )}\n        </div>\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}