{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent-console",
  "title": "Agent Console",
  "author": "superzero11 <https://github.com/superzero11/uiset>",
  "description": "The human side of the UI SDK agent bridge: approvals in your app, an activity feed with undo, highlights where the agent changed something, a thread and a prompt.",
  "dependencies": [
    "@ui-sdk/core@0.1.0-beta.5",
    "@ui-sdk/react@0.1.0-beta.5"
  ],
  "registryDependencies": [
    "https://uiset.dev/r/uiset.json",
    "https://uiset.dev/r/button.json"
  ],
  "files": [
    {
      "path": "registry/uiset/ui/agent-console.tsx",
      "content": "\"use client\"\n\nimport {\n  bindPersistentLayer,\n  createInputHistory,\n  createStickToBottom,\n} from \"@ui-sdk/core\"\nimport type { AgentComponent } from \"@ui-sdk/react/agent\"\nimport { describeEntry, type createHistory } from \"@ui-sdk/react/history\"\nimport { elementOf } from \"@ui-sdk/react/observe\"\nimport {\n  useEffect,\n  useId,\n  useMemo,\n  useRef,\n  useState,\n  useSyncExternalStore,\n  type ReactNode,\n} from \"react\"\nimport type { Approvals } from \"./agent/approvals\"\nimport { highlightElement } from \"./agent/highlight\"\nimport type { Agent } from \"./agent/tools\"\nimport { Button } from \"./button\"\nimport \"./agent/console.css\"\n\ntype History = ReturnType<typeof createHistory>\ntype Status = \"idle\" | \"working\" | \"waiting\"\n\nconst statusText: Record<Status, string> = {\n  idle: \"Idle\",\n  working: \"Working…\",\n  waiting: \"Waiting for you\",\n}\n\nfunction AgentConsole({\n  title = \"Agent\",\n  status = \"idle\",\n  className,\n  children,\n}: {\n  title?: string\n  status?: Status\n  className?: string\n  children: ReactNode\n}) {\n  const titleId = useId()\n  return (\n    <section\n      aria-labelledby={titleId}\n      data-agent-hidden=\"\"\n      data-status={status}\n      className={[\"agent-console\", className].filter(Boolean).join(\" \")}\n    >\n      <header className=\"agent-console-header\">\n        <h2 id={titleId}>{title}</h2>\n        <span className=\"agent-console-status\" role=\"status\">\n          <span className=\"agent-console-lamp\" aria-hidden=\"true\" />\n          {statusText[status]}\n        </span>\n      </header>\n      {children}\n    </section>\n  )\n}\n\ntype StepStatus = \"running\" | \"done\" | \"failed\" | \"refused\"\nconst stepText: Record<StepStatus, string> = {\n  running: \"Running\",\n  done: \"Done\",\n  failed: \"Failed\",\n  refused: \"You said no\",\n}\n\nfunction AgentStep({ status, children }: { status: StepStatus; children: ReactNode }) {\n  return (\n    <div className=\"agent-step\" data-status={status}>\n      <span className=\"agent-step-mark\" aria-hidden=\"true\" />\n      <span className=\"agent-step-text\">{children}</span>\n      <span className=\"agent-step-status\">{stepText[status]}</span>\n    </div>\n  )\n}\n\nfunction popoverOpen(el: HTMLElement) {\n  try {\n    return el.matches(\":popover-open\")\n  } catch {\n    return false\n  }\n}\n\nfunction AgentApprovals({ approvals }: { approvals: Approvals }) {\n  const pending = useSyncExternalStore(\n    approvals.subscribe,\n    approvals.pending,\n    approvals.pending,\n  )\n  const latest = pending.at(-1)\n  const layer = useRef<HTMLDivElement>(null)\n\n  // Agents usually ask after opening a modal, whose backdrop covers the page and whose\n  // focus trap makes it inert. The cards go to the top layer, above that modal, and\n  // bindPersistentLayer keeps them usable while it's open.\n  useEffect(() => (layer.current ? bindPersistentLayer(layer.current) : undefined), [])\n  useEffect(() => {\n    const el = layer.current\n    if (!el || typeof el.showPopover !== \"function\") return\n    if (pending.length) {\n      // Showing it again moves it above anything that opened since.\n      if (popoverOpen(el)) el.hidePopover()\n      el.showPopover()\n    } else if (popoverOpen(el)) {\n      el.hidePopover()\n    }\n  }, [pending])\n\n  return (\n    <>\n      <p className=\"agent-visually-hidden\" role=\"status\">\n        {latest ? `The agent is waiting for you: ${latest.message}` : \"\"}\n      </p>\n      {pending.length > 0 && (\n        <p className=\"agent-approvals-waiting\">Waiting for your answer…</p>\n      )}\n      <div\n        ref={layer}\n        popover=\"manual\"\n        role=\"group\"\n        aria-label=\"Agent requests\"\n        className=\"agent-approvals\"\n      >\n        {pending.map((approval) => (\n          <div key={approval.id} className=\"agent-approval\">\n            <p className=\"agent-approval-ask\">The agent wants to:</p>\n            <blockquote>{approval.message}</blockquote>\n            <div className=\"agent-approval-actions\">\n              <Button onClick={() => approvals.approve(approval.id)}>Allow</Button>\n              <Button variant=\"outline\" onClick={() => approvals.deny(approval.id)}>\n                Don&rsquo;t allow\n              </Button>\n            </div>\n          </div>\n        ))}\n      </div>\n    </>\n  )\n}\n\nfunction useVersion(subscribe: (listener: () => void) => () => unknown) {\n  const version = useRef(0)\n  return useSyncExternalStore(\n    (listener) => {\n      const stop = subscribe(() => {\n        version.current++\n        listener()\n      })\n      return () => void stop()\n    },\n    () => version.current,\n    () => version.current,\n  )\n}\n\nfunction AgentActivity({\n  history,\n  source = \"agent\",\n}: {\n  history: History\n  source?: string\n}) {\n  useVersion(history.subscribe)\n  const [problem, setProblem] = useState<string | null>(null)\n  const entries = history.entries().filter((entry) => entry.source === source)\n  const active = entries.filter((entry) => !entry.reverted)\n\n  const undo = async () => {\n    const missed = await history.undoSource(source)\n    setProblem(\n      missed.length\n        ? `Couldn't put back ${missed.length} change${missed.length === 1 ? \"\" : \"s\"}: those controls are gone or locked. Change them yourself.`\n        : null,\n    )\n  }\n\n  return (\n    <div className=\"agent-activity\">\n      <div className=\"agent-activity-header\">\n        <p>\n          {active.length\n            ? `${active.length} change${active.length === 1 ? \"\" : \"s\"} by the agent`\n            : \"No changes to undo\"}\n        </p>\n        <Button variant=\"outline\" disabled={!active.length} onClick={undo}>\n          Undo agent changes\n        </Button>\n      </div>\n      {problem && (\n        <p className=\"agent-activity-problem\" role=\"alert\">\n          {problem}\n        </p>\n      )}\n      {entries.length === 0 ? (\n        <p className=\"agent-empty\">\n          Nothing yet. Changes the agent makes show up here, and you can undo them.\n        </p>\n      ) : (\n        <ol className=\"agent-activity-list\">\n          {[...entries].reverse().map((entry) => (\n            <li key={entry.id} data-reverted={entry.reverted ? \"\" : undefined}>\n              <span>{describeEntry(entry)}</span>\n              {entry.reverted ? (\n                <span className=\"agent-activity-badge\">Undone</span>\n              ) : (\n                <Button\n                  variant=\"ghost\"\n                  aria-label={`Show ${entry.label}`}\n                  onClick={() => highlightElement(elementOf(entry.ref))}\n                >\n                  Show\n                </Button>\n              )}\n            </li>\n          ))}\n        </ol>\n      )}\n    </div>\n  )\n}\n\nfunction stateOf(entry: AgentComponent) {\n  const value = entry.checked ?? entry.value ?? entry.open\n  if (value === undefined || value === null) return \"—\"\n  return typeof value === \"string\" ? `“${value}”` : String(value)\n}\n\nfunction AgentSnapshot({\n  agent,\n  within,\n}: {\n  agent: Agent\n  within?: () => Element | null\n}) {\n  const version = useVersion(agent.subscribe)\n  const [entries, setEntries] = useState<AgentComponent[]>([])\n  useEffect(() => {\n    const frame = requestAnimationFrame(() => {\n      const root = within?.()\n      setEntries(\n        agent\n          .snapshot()\n          .filter(\n            (entry) =>\n              !entry.offPage &&\n              entry.component !== \"more\" &&\n              (!root || root.contains(elementOf(entry.ref) ?? null)),\n          ),\n      )\n    })\n    return () => cancelAnimationFrame(frame)\n  }, [agent, within, version])\n\n  return (\n    <div className=\"agent-snapshot-view\">\n      <table>\n        <caption className=\"agent-visually-hidden\">\n          What the agent can see on this page\n        </caption>\n        <thead>\n          <tr>\n            <th scope=\"col\">Label</th>\n            <th scope=\"col\">Kind</th>\n            <th scope=\"col\">State</th>\n            <th scope=\"col\">Actions</th>\n          </tr>\n        </thead>\n        <tbody>\n          {entries.map((entry) => (\n            <tr key={entry.ref}>\n              <th scope=\"row\">{entry.label ?? \"Unnamed\"}</th>\n              <td>{entry.component}</td>\n              <td>{entry.confirm ? \"Needs you\" : stateOf(entry)}</td>\n              <td>{entry.actions.join(\", \")}</td>\n            </tr>\n          ))}\n        </tbody>\n      </table>\n    </div>\n  )\n}\n\nexport { AgentActivity, AgentApprovals, AgentConsole, AgentSnapshot, AgentStep }\nexport type { Status as AgentStatus, StepStatus as AgentStepStatus }\n",
      "type": "registry:ui",
      "target": "@ui/agent-console.tsx"
    },
    {
      "path": "registry/uiset/ui/agent/approvals.ts",
      "content": "import type { AgentAction } from \"@ui-sdk/core/agent\"\n\ntype Approval = {\n  id: string\n  step: AgentAction\n  message: string\n}\n\ntype Verdict = boolean | \"ask\"\ntype ApprovalOptions = {\n  // Which steps to ask about besides the ones marked data-agent-confirm, which always ask.\n  policy?: (step: AgentAction) => Verdict\n}\n\nconst verbs: Record<string, string> = {\n  setValue: \"Set\",\n  setChecked: \"Turn\",\n  setOpen: \"Open\",\n  press: \"Press\",\n  clear: \"Clear\",\n  toggle: \"Toggle\",\n}\n\nfunction show(value: unknown): string {\n  if (typeof value === \"string\") return `“${value}”`\n  if (typeof value === \"boolean\") return value ? \"on\" : \"off\"\n  if (Array.isArray(value)) return value.map(show).join(\", \")\n  return String(value)\n}\n\nfunction describeStep(step: AgentAction) {\n  const verb =\n    verbs[step.action] ??\n    step.action.replace(/([A-Z])/g, \" $1\").replace(/^./, (c) => c.toUpperCase())\n  const target = step.label ?? step.component\n  if (step.action === \"setChecked\") return `${verb} ${target} ${show(step.args[0])}`\n  if (step.action === \"press\" && step.args.length)\n    return `Press “${step.args[0]}” in ${target}`\n  return step.args.length\n    ? `${verb} ${target} to ${step.args.map(show).join(\", \")}`\n    : `${verb} ${target}`\n}\n\nfunction createApprovals(options: ApprovalOptions = {}) {\n  type Waiting = Approval & { settle: (ok: boolean) => void }\n  let queue: Waiting[] = []\n  let snapshot: readonly Approval[] = []\n  let count = 0\n  const listeners = new Set<() => void>()\n\n  const emit = () => {\n    snapshot = queue.map(({ settle: _, ...approval }) => approval)\n    for (const listener of listeners) listener()\n  }\n\n  const ask = (step: AgentAction, signal: AbortSignal) =>\n    new Promise<boolean>((resolve) => {\n      if (signal.aborted) return resolve(false)\n      const id = `approval-${++count}`\n      let settled = false\n      const settle = (ok: boolean) => {\n        if (settled) return\n        settled = true\n        queue = queue.filter((item) => item.id !== id)\n        emit()\n        resolve(ok)\n      }\n      signal.addEventListener(\"abort\", () => settle(false), { once: true })\n      queue = [\n        ...queue,\n        { id, step, message: step.confirm ?? describeStep(step), settle },\n      ]\n      emit()\n    })\n\n  return {\n    allow(\n      step: AgentAction,\n      { signal }: { signal: AbortSignal },\n    ): boolean | Promise<boolean> {\n      const verdict: Verdict = step.confirm ? \"ask\" : (options.policy?.(step) ?? true)\n      return verdict === \"ask\" ? ask(step, signal) : verdict\n    },\n    pending: () => snapshot,\n    subscribe(listener: () => void) {\n      listeners.add(listener)\n      return () => {\n        listeners.delete(listener)\n      }\n    },\n    approve: (id: string) => queue.find((item) => item.id === id)?.settle(true),\n    deny: (id: string) => queue.find((item) => item.id === id)?.settle(false),\n    denyAll: () => {\n      for (const item of [...queue]) item.settle(false)\n    },\n  }\n}\n\ntype Approvals = ReturnType<typeof createApprovals>\n\nexport { createApprovals, describeStep }\nexport type { Approval, ApprovalOptions, Approvals, Verdict }\n",
      "type": "registry:file",
      "target": "@ui/agent/approvals.ts"
    },
    {
      "path": "registry/uiset/ui/agent/highlight.ts",
      "content": "import { elementOf, observe } from \"@ui-sdk/core/observe\"\n\ntype HighlightOptions = { duration?: number; scroll?: boolean }\n\nconst timers = new WeakMap<Element, ReturnType<typeof setTimeout>>()\n\nfunction inView(el: Element) {\n  const box = el.getBoundingClientRect()\n  return box.bottom > 0 && box.top < window.innerHeight\n}\n\nfunction highlightElement(\n  el: Element | null | undefined,\n  { duration = 1800, scroll = true }: HighlightOptions = {},\n) {\n  if (!el) return\n  el.removeAttribute(\"data-agent-touched\")\n  // Re-adding the attribute in the same frame wouldn't restart the animation.\n  requestAnimationFrame(() => {\n    el.setAttribute(\"data-agent-touched\", \"\")\n    clearTimeout(timers.get(el))\n    timers.set(\n      el,\n      setTimeout(() => el.removeAttribute(\"data-agent-touched\"), duration),\n    )\n  })\n  if (scroll && !inView(el)) {\n    const reduce = matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n    el.scrollIntoView({ block: \"center\", behavior: reduce ? \"auto\" : \"smooth\" })\n  }\n}\n\n// observe() only sees components created after it starts: call this before rendering.\nfunction highlightAgent(options: HighlightOptions = {}) {\n  return observe((change) => {\n    if (change.source === \"agent\") highlightElement(elementOf(change.ref), options)\n  })\n}\n\nexport { highlightAgent, highlightElement }\nexport type { HighlightOptions }\n",
      "type": "registry:file",
      "target": "@ui/agent/highlight.ts"
    },
    {
      "path": "registry/uiset/ui/agent/tools.ts",
      "content": "import { agentTools, type createAgent } from \"@ui-sdk/core/agent\"\n\ntype Agent = ReturnType<typeof createAgent>\ntype ToolName = \"snapshot\" | \"query\" | \"act\"\n\n// Route a model's tool call to the bridge. Pair with `agentTools`, which holds the names,\n// descriptions and JSON Schemas to hand the model.\nasync function runAgentTool(agent: Agent, name: string, input: unknown) {\n  switch (name as ToolName) {\n    case \"snapshot\":\n      return agent.snapshot()\n    case \"query\":\n      return agent.query((input ?? {}) as Parameters<Agent[\"query\"]>[0])\n    case \"act\":\n      return agent.act(input as Parameters<Agent[\"act\"]>[0])\n    default:\n      return { error: `Unknown tool \"${name}\". The tools are snapshot, query and act.` }\n  }\n}\n\nexport { agentTools, runAgentTool }\nexport type { Agent }\n",
      "type": "registry:file",
      "target": "@ui/agent/tools.ts"
    },
    {
      "path": "registry/uiset/ui/agent/console.css",
      "content": "@layer ui-sdk, uiset.tokens, uiset.base, uiset.skin;\n\n@layer uiset.base {\n  .agent-console {\n    --agent-lamp: var(--ui-muted-foreground);\n    display: flex;\n    flex-direction: column;\n    gap: 0.75rem;\n    min-height: 0;\n    padding: 1rem;\n    border: 1px solid var(--ui-border);\n    border-radius: calc(var(--ui-radius, 0px) * 2);\n    background: var(--ui-background);\n    color: var(--ui-foreground);\n    font-size: var(--ui-font-size, 0.875rem);\n\n    &[data-status=\"working\"] {\n      --agent-lamp: var(--ui-primary);\n    }\n\n    &[data-status=\"waiting\"] {\n      --agent-lamp: oklch(0.78 0.16 75);\n    }\n  }\n\n  .agent-console-header {\n    display: flex;\n    align-items: center;\n    justify-content: space-between;\n    gap: 1rem;\n\n    h2 {\n      margin: 0;\n      font-size: 1rem;\n      font-weight: 600;\n    }\n  }\n\n  .agent-console-status {\n    display: inline-flex;\n    align-items: center;\n    gap: 0.5rem;\n    color: var(--ui-muted-foreground);\n  }\n\n  .agent-console-lamp {\n    width: 0.5rem;\n    height: 0.5rem;\n    border-radius: 50%;\n    background: var(--agent-lamp);\n  }\n\n  .agent-console[data-status=\"working\"] .agent-console-lamp {\n    animation: agent-pulse 1.2s ease-in-out infinite;\n  }\n\n  @keyframes agent-pulse {\n    50% {\n      opacity: 0.35;\n    }\n  }\n\n  .agent-step {\n    display: grid;\n    grid-template-columns: auto minmax(0, 1fr) auto;\n    align-items: center;\n    gap: 0.5rem;\n    margin-top: 0.25rem;\n    font-size: 0.8125rem;\n  }\n\n  .agent-step-mark {\n    width: 0.5rem;\n    height: 0.5rem;\n    border: 1.5px solid currentColor;\n    border-radius: 50%;\n  }\n\n  .agent-step[data-status=\"done\"] .agent-step-mark {\n    background: currentColor;\n  }\n\n  .agent-step[data-status=\"running\"] .agent-step-mark {\n    border-style: dashed;\n    animation: agent-pulse 1s ease-in-out infinite;\n  }\n\n  .agent-step[data-status=\"failed\"] .agent-step-mark,\n  .agent-step[data-status=\"refused\"] .agent-step-mark {\n    border-radius: 1px;\n    rotate: 45deg;\n  }\n\n  .agent-step-status {\n    color: var(--ui-muted-foreground);\n  }\n\n  .agent-approvals {\n    inset: auto 1.25rem 1.25rem auto;\n    width: min(24rem, calc(100vw - 2.5rem));\n    margin: 0;\n    padding: 0;\n    overflow: visible;\n    border: 0;\n    background: transparent;\n    color: var(--ui-foreground);\n    font-size: var(--ui-font-size, 0.875rem);\n\n    &:popover-open {\n      display: grid;\n      gap: 0.5rem;\n    }\n  }\n\n  .agent-approvals-waiting {\n    margin: 0;\n    color: var(--ui-muted-foreground);\n  }\n\n  .agent-approval {\n    display: grid;\n    gap: 0.5rem;\n    padding: 0.875rem;\n    border: 2px solid oklch(0.78 0.16 75);\n    border-radius: calc(var(--ui-radius, 0px) + 6px);\n    background: color-mix(in oklab, oklch(0.78 0.16 75) 12%, var(--ui-background));\n    box-shadow: var(--ui-shadow);\n\n    blockquote {\n      margin: 0;\n      font-weight: 600;\n    }\n  }\n\n  .agent-approval-ask {\n    margin: 0;\n    color: var(--ui-muted-foreground);\n  }\n\n  .agent-approval-actions {\n    display: flex;\n    flex-wrap: wrap;\n    gap: 0.5rem;\n  }\n\n  .agent-activity-header {\n    display: flex;\n    flex-wrap: wrap;\n    align-items: center;\n    justify-content: space-between;\n    gap: 0.5rem;\n\n    p {\n      margin: 0;\n      color: var(--ui-muted-foreground);\n    }\n  }\n\n  .agent-activity-problem {\n    margin: 0.5rem 0 0;\n    color: var(--ui-destructive);\n  }\n\n  .agent-activity-list {\n    display: grid;\n    margin: 0.5rem 0 0;\n    padding: 0;\n    list-style: none;\n\n    li {\n      display: flex;\n      align-items: center;\n      justify-content: space-between;\n      gap: 0.75rem;\n      min-height: 2.25rem;\n      border-bottom: 1px solid var(--ui-border);\n    }\n\n    li[data-reverted] > span:first-child {\n      color: var(--ui-muted-foreground);\n      text-decoration: line-through;\n    }\n  }\n\n  .agent-activity-badge {\n    font-size: 0.75rem;\n    color: var(--ui-muted-foreground);\n  }\n\n  .agent-empty {\n    margin: 0.5rem 0;\n    color: var(--ui-muted-foreground);\n  }\n\n  .agent-snapshot-view {\n    max-height: var(--agent-thread-height, 22rem);\n    overflow: auto;\n\n    table {\n      width: 100%;\n      border-collapse: collapse;\n      font-size: 0.8125rem;\n    }\n\n    :is(th, td) {\n      padding: 0.375rem 0.5rem 0.375rem 0;\n      border-bottom: 1px solid var(--ui-border);\n      text-align: start;\n      vertical-align: top;\n    }\n\n    thead th {\n      color: var(--ui-muted-foreground);\n      font-weight: 600;\n    }\n  }\n\n  .agent-visually-hidden {\n    position: absolute;\n    width: 1px;\n    height: 1px;\n    overflow: hidden;\n    clip-path: inset(50%);\n    white-space: nowrap;\n  }\n\n  /* The control an agent just changed. Outline survives forced colors. */\n  /* Dashed in the info tone with a halo, so it never reads as keyboard focus (B29). */\n  [data-agent-touched] {\n    outline: 2px dashed var(--tone-info, var(--ui-ring-border, Highlight));\n    outline-offset: 3px;\n    box-shadow: 0 0 0 6px color-mix(in oklch, var(--tone-info, Highlight) 18%, transparent);\n    animation: agent-touched 1.8s ease-out both;\n  }\n\n  @keyframes agent-touched {\n    0% {\n      outline-offset: 8px;\n      outline-color: transparent;\n    }\n    15% {\n      outline-offset: 3px;\n      outline-color: var(--ui-ring-border, Highlight);\n    }\n    80% {\n      outline-color: var(--ui-ring-border, Highlight);\n    }\n    100% {\n      outline-color: transparent;\n    }\n  }\n\n  @media (prefers-reduced-motion: reduce) {\n    [data-agent-touched],\n    .agent-console-lamp,\n    .agent-step-mark {\n      animation: none !important;\n    }\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/agent/console.css"
    }
  ],
  "type": "registry:ui"
}