# Agent approvals

> Human-in-the-loop approval queue for pending agent tool calls with priority badges, JSON arguments and Deny/Always allow/Approve controls.

- Kind: block · Category: Agents · Interactivity: script
- Install: `npx shadcn@latest add @haze/agent-approvals`
- File: `src/components/haze/blocks/agent-approvals.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/blocks/agent-approvals

## Use when
- Reviewing high-impact agent tool calls (refunds, merges, deploys) before execution
- Offering Deny, Always allow and one-time Approve actions in a structured queue

## Avoid when
- Showing a single inline code diff inside one coding run; use agent-run

## Alternatives
- [agent-run](https://hazeui.com/blocks/agent-run.md)
- [alert-dialog](https://hazeui.com/ui/alert-dialog.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` | "haze-agent-approvals" | no | Unique prefix for section heading IDs. |
| heading | `string` | "Pending tool approvals" | no | Queue heading. |
| queue | `ApprovalItem[]` | 2 pending tool calls | no | Queued tool requests with agent, priority, rationale and JSON args. |
| class | `string` |  | no | Extra classes on the outer section. |

## Accessibility
- Tool arguments render inside a horizontally scrollable pre block so long payloads never break mobile layouts.
- Reviewing an item updates the pending counter, reveals an empty state when clear and announces the decision via role="status".
- Key Tab: Move across Deny, Always allow and Approve buttons for each pending request
- Key Enter / Space: Deny, always allow or approve the focused tool call

## Agent prompts

### Install and use

Install the Haze UI block "Agent approvals" with `npx shadcn@latest add @haze/agent-approvals`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import AgentApprovals from "@/components/haze/blocks/agent-approvals.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/blocks/agent-approvals.md

### Customize with real content

Adapt the Haze agent-approvals block for our product. Replace the demo values of these props with our real content: id, heading, queue, class. Keep the layout, the heading level rules and these accessibility details: Tool arguments render inside a horizontally scrollable pre block so long payloads never break mobile layouts. Reviewing an item updates the pending counter, reveals an empty state when clear and announces the decision via role="status". Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using agent-approvals, check it fits: use it when reviewing high-impact agent tool calls (refunds, merges, deploys) before execution; offering deny, always allow and one-time approve actions in a structured queue. Avoid it when showing a single inline code diff inside one coding run; use agent-run. Alternatives: @haze/agent-run, @haze/alert-dialog.

## Example requests that should lead here
- Build a human-in-the-loop agent approvals queue with tool arguments and Deny, Always allow, and Approve buttons

## Source

```astro
---
import { Check, ShieldCheck, ShieldQuestion, Terminal, X } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface ApprovalItem {
  id: string;
  agent: string;
  priority: "High" | "Standard";
  tool: string;
  rationale: string;
  args: string;
}

interface Props {
  id?: string;
  heading?: string;
  queue?: ApprovalItem[];
  class?: string;
}

const {
  id = "haze-agent-approvals",
  heading = "Pending tool approvals",
  queue = [
    {
      id: "ap1",
      agent: "Release bot",
      priority: "High",
      tool: "stripe.refunds.create",
      rationale: "Issue duplicate-charge refund of $149.00 requested in ticket 8812.",
      args: '{ "charge": "ch_3Q9aK1", "amount": 14900, "reason": "duplicate" }',
    },
    {
      id: "ap2",
      agent: "Repo maintainer",
      priority: "Standard",
      tool: "github.merge_pull_request",
      rationale: "All 6 CI checks passed on PR 492 (token contrast audit).",
      args: '{ "repo": "haze/ui", "pull_number": 492, "merge_method": "squash" }',
    },
  ],
  class: className,
} = Astro.props;
---

<section aria-labelledby={`${id}-title`} data-haze-agent-approvals class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
  <div class="mx-auto max-w-3xl rounded-2xl border border-border bg-card p-5 sm:p-6">
    <header class="flex flex-wrap items-center justify-between gap-2 border-b border-border pb-4">
      <div class="flex items-center gap-2">
        <ShieldQuestion class="size-4 text-muted-foreground" aria-hidden="true" />
        <h2 id={`${id}-title`} class="text-base/6 font-semibold tracking-tight text-foreground">{heading}</h2>
      </div>
      <span data-ap-count class="rounded-full border border-frame-warning bg-warning/10 px-2.5 py-0.5 text-xs font-medium text-warning tabular-nums">{queue.length} pending</span>
    </header>

    <ul role="list" data-ap-list class="mt-4 space-y-3">
      {
        queue.map((item) => (
          <li data-ap-card class="rounded-xl border border-border bg-muted/40 p-4">
            <div class="flex flex-wrap items-center justify-between gap-2">
              <div class="flex flex-wrap items-center gap-2">
                <span class="text-xs font-semibold text-foreground">{item.agent}</span>
                <span class={cn(
                  "rounded-md border px-2 py-0.5 text-[0.6875rem]/4 font-medium",
                  item.priority === "High" ? "border-frame-destructive bg-destructive/10 text-destructive" : "border-frame bg-card text-muted-foreground",
                )}>{item.priority} priority</span>
              </div>
              <span class="inline-flex items-center gap-1.5 rounded-md border border-frame bg-muted px-2 py-0.5 font-mono text-[0.6875rem] text-foreground">
                <Terminal class="size-3" aria-hidden="true" />
                {item.tool}
              </span>
            </div>

            <p class="mt-2 text-sm/6 text-pretty text-foreground">{item.rationale}</p>
            <pre class="mt-2.5 overflow-x-auto rounded-lg border border-border bg-card px-3 py-2 font-mono text-xs/5 text-muted-foreground">{item.args}</pre>

            <div class="mt-3 flex flex-wrap items-center justify-end gap-2">
              <button type="button" data-ap-act="Denied" data-ap-tool={item.tool} class="inline-flex h-8 cursor-pointer items-center gap-1 rounded-lg border border-frame bg-field px-3 text-xs font-medium text-muted-foreground hover:border-destructive-border hover:text-destructive focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
                <X class="size-3.5" aria-hidden="true" />
                Deny
              </button>
              <button type="button" data-ap-act="Always allowed" data-ap-tool={item.tool} class="inline-flex h-8 cursor-pointer items-center gap-1.5 rounded-lg border border-frame bg-field px-3 text-xs font-medium text-foreground hover:border-frame-strong hover:bg-accent focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
                <ShieldCheck class="size-3.5 text-muted-foreground" aria-hidden="true" />
                Always allow
              </button>
              <button type="button" data-ap-act="Approved" data-ap-tool={item.tool} class="inline-flex h-8 cursor-pointer items-center gap-1.5 rounded-lg bg-primary px-3.5 text-xs font-medium text-primary-foreground hover:opacity-90 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
                <Check class="size-3.5" aria-hidden="true" />
                Approve
              </button>
            </div>
          </li>
        ))
      }
    </ul>

    <p data-ap-empty hidden class="mt-4 rounded-xl border border-dashed border-border py-8 text-center text-xs text-muted-foreground">All queued tool calls have been reviewed.</p>
    <p data-ap-status role="status" class="mt-3 min-h-4 text-xs/4 text-muted-foreground"></p>
  </div>
</section>

<script>
  function initApprovals() {
    document.querySelectorAll<HTMLElement>("[data-haze-agent-approvals]").forEach((root) => {
      if (root.hasAttribute("data-enhanced")) return;
      root.setAttribute("data-enhanced", "");
      const count = root.querySelector<HTMLElement>("[data-ap-count]");
      const empty = root.querySelector<HTMLElement>("[data-ap-empty]");
      const status = root.querySelector<HTMLElement>("[data-ap-status]");

      root.querySelector<HTMLElement>("[data-ap-list]")?.addEventListener("click", (ev) => {
        const btn = (ev.target as HTMLElement | null)?.closest<HTMLButtonElement>("[data-ap-act]");
        if (!btn) return;
        const action = btn.dataset.apAct ?? "Reviewed";
        const tool = btn.dataset.apTool ?? "tool";
        btn.closest("[data-ap-card]")?.remove();
        const left = root.querySelectorAll("[data-ap-card]").length;
        if (count) count.textContent = `${left} pending`;
        if (empty) empty.hidden = left > 0;
        if (status) status.textContent = `${action} ${tool}.`;
      });
    });
  }
  initApprovals();
  document.addEventListener("astro:page-load", initApprovals);
</script>
```
