# AI inline app connect

> Inline OAuth connection card inside a chat turn that pauses a tool call, authorizes GitHub and resumes to output a pull request card.

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

## Use when
- Unblocking an agent tool call that lacks an active third-party app connection without leaving the chat
- Showing explicit repository permission scopes before a user authorizes GitHub or another integration
- Automatically resuming a paused action and displaying the created pull request card once connected

## Avoid when
- Managing a full settings directory of persistent MCP servers and API keys; use mcp-servers
- Asking yes/no permission for an already connected local command; use ai-tool-approval

## Alternatives
- [mcp-servers](https://hazeui.com/blocks/mcp-servers.md)
- [ai-tool-approval](https://hazeui.com/blocks/ai-tool-approval.md)
- [ai-tool-calls](https://hazeui.com/blocks/ai-tool-calls.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` | "haze-ai-connect" | no | Unique prefix for section heading IDs. |
| heading | `string` | "Inline app connection" | no | Card header title. |
| userPrompt | `string` | "Open a pull request with the dark mode contrast fix" | no | User request that triggered the paused tool call. |
| repository | `string` | "linden-labs/web" | no | Target repository displayed in the tool call and scope note. |
| provider | `string` | "GitHub" | no | Integration name shown on the embedded connection card. |
| permissions | `string` | "Read & write pull requests · No force push" | no | Summary of requested access scopes. |
| prNumber | `string` | "418" | no | Pull request number rendered after authorization succeeds. |
| prTitle | `string` | "Fix contrast on dark status chips" | no | Title shown on the resulting pull request link card. |
| class | `string` |  | no | Extra classes on the outer section. |

## Accessibility
- Authorization progress, resumed execution, cancellation and reset states announce clearly through a polite role="status" live region.
- Under prefers-reduced-motion, clicking Connect GitHub completes immediately without intermediate spinner transitions.
- Key Tab: Move across Reset, Cancel, Connect GitHub and the resulting View PR link
- Key Enter / Space: Authorize the integration, cancel the paused call or reset the flow

## Agent prompts

### Install and use

Install the Haze UI block "AI inline app connect" with `npx shadcn@latest add @haze/ai-connect`. 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 AiConnect from "@/components/haze/blocks/ai-connect.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/ai-connect.md

### Customize with real content

Adapt the Haze ai-connect block for our product. Replace the demo values of these props with our real content: id, heading, userPrompt, repository, provider, permissions, prNumber, prTitle, class. Keep the layout, the heading level rules and these accessibility details: Authorization progress, resumed execution, cancellation and reset states announce clearly through a polite role="status" live region. Under prefers-reduced-motion, clicking Connect GitHub completes immediately without intermediate spinner transitions. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using ai-connect, check it fits: use it when unblocking an agent tool call that lacks an active third-party app connection without leaving the chat; showing explicit repository permission scopes before a user authorizes github or another integration; automatically resuming a paused action and displaying the created pull request card once connected. Avoid it when managing a full settings directory of persistent mcp servers and api keys; use mcp-servers; asking yes/no permission for an already connected local command; use ai-tool-approval. Alternatives: @haze/mcp-servers, @haze/ai-tool-approval, @haze/ai-tool-calls.

## Example requests that should lead here
- Build an inline AI app connect card that pauses a GitHub PR tool call, authorizes OAuth, and prints the created PR card
- Create an in-chat integration prompt with scope details, Connect and Cancel actions, and automatic tool resumption

## Source

```astro
---
import { Ban, Check, ExternalLink, Eye, GitBranch, GitPullRequest, LoaderCircle, Lock, Pause, RotateCcw, X } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface Props {
  id?: string;
  heading?: string;
  userPrompt?: string;
  repository?: string;
  provider?: string;
  permissions?: string;
  prNumber?: string;
  prTitle?: string;
  class?: string;
}

const {
  id = "haze-ai-connect",
  heading = "Inline app connection",
  userPrompt = "Open a PR with the dark mode fix",
  repository = "linden-labs/web",
  provider = "GitHub",
  permissions = "Open and update pull requests",
  prNumber = "418",
  prTitle = "Fix contrast on dark status chips",
  class: className,
} = Astro.props;
---

<section aria-labelledby={`${id}-title`} data-haze-ai-connect class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
  <h2 id={`${id}-title`} class="sr-only">{heading}</h2>

  <div class="mx-auto max-w-md space-y-4">
    {/* User bubble */}
    <div class="flex justify-end">
      <p class="max-w-[85%] rounded-2xl rounded-br-sm bg-muted px-4 py-2.5 text-sm/6 text-foreground">
        {userPrompt}
      </p>
    </div>

    {/* Nested two-layer connection card */}
    <div class="rounded-2xl border border-border bg-muted/40 p-1.5 shadow-key">
      {/* Slim top tool strip */}
      <div class="flex flex-wrap items-center justify-between gap-2 px-3 py-2 text-xs/5">
        <div class="flex min-w-0 items-center gap-2">
          <span data-ac-icon-pause class="inline-flex shrink-0 text-muted-foreground" aria-hidden="true">
            <Pause class="size-3.5" />
          </span>
          <span data-ac-icon-spin hidden class="inline-flex shrink-0 text-muted-foreground" aria-hidden="true">
            <LoaderCircle class="size-3.5 animate-spin" />
          </span>
          <span data-ac-icon-done hidden class="inline-flex shrink-0 text-success" aria-hidden="true">
            <Check class="size-3.5" />
          </span>
          <span data-ac-icon-cancel hidden class="inline-flex shrink-0 text-destructive" aria-hidden="true">
            <X class="size-3.5" />
          </span>
          <span class="font-semibold text-foreground">Opening a pull request</span>
          <span class="truncate font-mono text-muted-foreground">{repository}</span>
        </div>
        <span data-ac-strip-status class="shrink-0 text-muted-foreground">Needs {provider}</span>
      </div>

      {/* Inner card */}
      <div class="rounded-xl border border-border bg-card p-6">
        {/* Authorization view */}
        <div data-ac-connect-view class="text-center">
          {/* Connector bridge */}
          <div class="mx-auto flex items-center justify-center" aria-hidden="true">
            <span class="grid size-11 place-items-center rounded-xl border border-frame bg-muted/70 text-sm font-bold text-foreground shadow-key">
              H
            </span>
            <span class="w-8 border-t border-dashed border-border-strong"></span>
            <span class="grid size-7 place-items-center rounded-full border border-frame bg-field text-muted-foreground">
              <Lock class="size-3.5" />
            </span>
            <span class="w-8 border-t border-dashed border-border-strong"></span>
            <span class="grid size-11 place-items-center rounded-xl border border-frame bg-muted/70 text-foreground shadow-key">
              <GitBranch class="size-5" />
            </span>
          </div>

          <h3 class="mt-5 text-base/6 font-semibold tracking-tight text-foreground">Connect {provider} to continue</h3>
          <p class="mt-1.5 text-xs/5 text-muted-foreground">
            Haze needs access to open a pull request on <span class="font-mono text-foreground">{repository}</span>.
          </p>

          {/* Left-aligned permissions list */}
          <ul role="list" class="mt-5 space-y-2.5 rounded-xl border border-border bg-muted/30 p-3.5 text-left text-xs/5">
            <li class="flex items-center gap-2.5 text-foreground">
              <Eye class="size-3.5 shrink-0 text-muted-foreground" aria-hidden="true" />
              <span class="min-w-0 wrap-anywhere">Read code in <span class="font-mono">{repository}</span></span>
            </li>
            <li class="flex items-center gap-2.5 text-foreground">
              <GitPullRequest class="size-3.5 shrink-0 text-muted-foreground" aria-hidden="true" />
              <span class="min-w-0 wrap-anywhere">{permissions}</span>
            </li>
            <li class="flex flex-wrap items-center justify-between gap-2 text-muted-foreground">
              <span class="inline-flex min-w-0 items-center gap-2.5">
                <Ban class="size-3.5 shrink-0" aria-hidden="true" />
                <span class="line-through">Push to main or change settings</span>
              </span>
              <span class="shrink-0 text-[0.6875rem]">Not asked</span>
            </li>
          </ul>

          <button
            type="button"
            data-ac-connect
            class="mt-5 inline-flex h-10 w-full cursor-pointer items-center justify-center gap-2 rounded-xl border border-frame-strong bg-muted px-4 text-sm font-medium text-foreground transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy hover:bg-accent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring disabled:cursor-wait disabled:opacity-70 active:scale-[0.99] active:duration-75"
          >
            <span data-ac-btn-icon class="inline-flex" aria-hidden="true">
              <GitBranch class="size-4" />
            </span>
            <span data-ac-btn-spin hidden class="inline-flex" aria-hidden="true">
              <LoaderCircle class="size-4 animate-spin" />
            </span>
            <span data-ac-btn-label>Continue with {provider}</span>
          </button>

          <button
            type="button"
            data-ac-cancel
            class="mt-2 inline-flex min-h-8 cursor-pointer items-center justify-center rounded-lg px-3 text-xs font-medium text-muted-foreground transition-colors duration-150 ease-snappy hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring"
          >
            Not now
          </button>
        </div>

        {/* Opened PR view */}
        <div data-ac-pr-view hidden class="space-y-4 animate-rise">
          <div class="flex items-start gap-3">
            <span class="grid size-8 shrink-0 place-items-center rounded-lg bg-muted text-muted-foreground" aria-hidden="true">
              <GitPullRequest class="size-4" />
            </span>
            <div class="min-w-0 flex-1">
              <p class="text-sm/5 font-semibold text-foreground wrap-anywhere">
                <span class="font-mono text-success">&#35;{prNumber}</span> {prTitle}
              </p>
              <p class="mt-0.5 text-xs/5 text-muted-foreground">
                <span class="font-mono">fix/dark-chip-contrast</span> &rarr; <span class="font-mono">main</span>
              </p>
            </div>
          </div>

          <p class="text-xs/5 text-muted-foreground">
            Connected {provider} for <span class="font-mono text-foreground">{repository}</span> and opened the pull request with 3 passing visual checks.
          </p>

          <div class="flex flex-wrap items-center justify-between gap-2 border-t border-border pt-3">
            <a
              href={`#pr-${prNumber}`}
              data-ac-pr-link
              class="inline-flex min-h-8 items-center gap-1.5 rounded-lg border border-frame bg-muted/50 px-3 text-xs font-medium text-foreground transition-colors duration-150 ease-snappy hover:bg-accent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring"
            >
              View pull request
              <ExternalLink class="size-3" aria-hidden="true" />
            </a>
            <button
              type="button"
              data-ac-reset
              class="inline-flex min-h-8 cursor-pointer items-center gap-1 rounded-lg px-2.5 text-xs font-medium text-muted-foreground transition-colors duration-150 ease-snappy hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring"
            >
              <RotateCcw class="size-3" aria-hidden="true" />
              Reset
            </button>
          </div>
        </div>

        {/* Canceled view */}
        <div data-ac-canceled-view hidden class="space-y-3 text-center animate-rise">
          <p class="text-sm/5 font-medium text-foreground">{provider} connection skipped</p>
          <p class="text-xs/5 text-muted-foreground">
            Your branch stays local and no pull request was opened on <span class="font-mono text-foreground">{repository}</span>.
          </p>
          <button
            type="button"
            data-ac-reset
            class="inline-flex min-h-8 cursor-pointer items-center gap-1.5 rounded-lg border border-frame bg-muted/50 px-3 text-xs font-medium text-foreground transition-colors duration-150 ease-snappy hover:bg-accent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring"
          >
            <RotateCcw class="size-3" aria-hidden="true" />
            Try again
          </button>
        </div>
      </div>
    </div>
  </div>

  <div hidden data-ac-config data-provider={provider} data-repo={repository} data-pr={prNumber}></div>
  <p data-ac-status role="status" class="sr-only"></p>
</section>

<script>
  function initAiConnect() {
    document.querySelectorAll<HTMLElement>("[data-haze-ai-connect]").forEach((root) => {
      if (root.hasAttribute("data-enhanced")) return;
      root.setAttribute("data-enhanced", "");

      const cfg = root.querySelector<HTMLElement>("[data-ac-config]");
      const stripStatus = root.querySelector<HTMLElement>("[data-ac-strip-status]");
      const iconPause = root.querySelector<HTMLElement>("[data-ac-icon-pause]");
      const iconSpin = root.querySelector<HTMLElement>("[data-ac-icon-spin]");
      const iconDone = root.querySelector<HTMLElement>("[data-ac-icon-done]");
      const iconCancel = root.querySelector<HTMLElement>("[data-ac-icon-cancel]");
      const connectView = root.querySelector<HTMLElement>("[data-ac-connect-view]");
      const prView = root.querySelector<HTMLElement>("[data-ac-pr-view]");
      const canceledView = root.querySelector<HTMLElement>("[data-ac-canceled-view]");
      const connectBtn = root.querySelector<HTMLButtonElement>("[data-ac-connect]");
      const btnIcon = root.querySelector<HTMLElement>("[data-ac-btn-icon]");
      const btnSpin = root.querySelector<HTMLElement>("[data-ac-btn-spin]");
      const btnLabel = root.querySelector<HTMLElement>("[data-ac-btn-label]");
      const cancelBtn = root.querySelector<HTMLButtonElement>("[data-ac-cancel]");
      const resetBtns = root.querySelectorAll<HTMLButtonElement>("[data-ac-reset]");
      const prLink = root.querySelector<HTMLAnchorElement>("[data-ac-pr-link]");
      const status = root.querySelector<HTMLElement>("[data-ac-status]");

      if (!cfg || !stripStatus || !connectView || !prView || !canceledView || !connectBtn || !cancelBtn) return;

      const provider = cfg.dataset.provider ?? "GitHub";
      const repo = cfg.dataset.repo ?? "linden-labs/web";
      const prNum = cfg.dataset.pr ?? "418";

      let runId = 0;
      const timers: number[] = [];

      const clearTimers = () => {
        while (timers.length) window.clearTimeout(timers.pop());
      };

      const setIcon = (which: "pause" | "spin" | "done" | "cancel") => {
        if (iconPause) iconPause.hidden = which !== "pause";
        if (iconSpin) iconSpin.hidden = which !== "spin";
        if (iconDone) iconDone.hidden = which !== "done";
        if (iconCancel) iconCancel.hidden = which !== "cancel";
      };

      const setInitial = (announce: boolean) => {
        runId++;
        clearTimers();
        setIcon("pause");
        stripStatus.textContent = `Needs ${provider}`;
        stripStatus.className = "shrink-0 text-muted-foreground";

        connectBtn.disabled = false;
        cancelBtn.disabled = false;
        if (btnIcon) btnIcon.hidden = false;
        if (btnSpin) btnSpin.hidden = true;
        if (btnLabel) btnLabel.textContent = `Continue with ${provider}`;

        connectView.hidden = false;
        prView.hidden = true;
        canceledView.hidden = true;
        if (announce && status) status.textContent = `Reset ${provider} connection prompt.`;
      };

      const finishConnected = (myRun: number) => {
        if (myRun !== runId) return;
        setIcon("done");
        stripStatus.textContent = "Opened";
        stripStatus.className = "shrink-0 font-medium text-success";
        connectView.hidden = true;
        canceledView.hidden = true;
        prView.hidden = false;
        if (status) status.textContent = `${provider} connected. Opened pull request \u0023${prNum} on ${repo}.`;
      };

      connectBtn.addEventListener("click", () => {
        const myRun = ++runId;
        clearTimers();
        const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;

        if (reduced) {
          finishConnected(myRun);
          return;
        }

        connectBtn.disabled = true;
        cancelBtn.disabled = true;
        if (btnIcon) btnIcon.hidden = true;
        if (btnSpin) btnSpin.hidden = false;
        if (btnLabel) btnLabel.textContent = "Authorizing…";
        setIcon("spin");
        stripStatus.textContent = "Authorizing…";
        stripStatus.className = "shrink-0 text-muted-foreground";
        if (status) status.textContent = `Authorizing ${provider} access…`;

        timers.push(
          window.setTimeout(() => {
            if (myRun !== runId) return;
            stripStatus.textContent = "Resuming…";
            if (btnLabel) btnLabel.textContent = "Opening pull request…";
          }, 600),
        );

        timers.push(window.setTimeout(() => finishConnected(myRun), 1250));
      });

      cancelBtn.addEventListener("click", () => {
        runId++;
        clearTimers();
        setIcon("cancel");
        stripStatus.textContent = "Skipped";
        stripStatus.className = "shrink-0 text-muted-foreground";
        connectView.hidden = true;
        prView.hidden = true;
        canceledView.hidden = false;
        if (status) status.textContent = `Skipped ${provider} connection. No pull request was opened.`;
      });

      prLink?.addEventListener("click", (ev) => {
        ev.preventDefault();
        if (status) status.textContent = `Opened preview link for pull request \u0023${prNum}.`;
      });

      resetBtns.forEach((btn) => {
        btn.addEventListener("click", () => setInitial(true));
      });
    });
  }
  initAiConnect();
  document.addEventListener("astro:page-load", initAiConnect);
</script>
```
