# Prompt studio

> Prompt template workbench with System and User editors, variable bindings, a token estimate, and a local test preview.

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

## Use when
- Reviewing parameterized System and User prompts with sample variable values
- Showing estimates for the filled-in prompts and a sample category based on keywords

## Avoid when
- You only need an end-user chat box without template variables; use ai-composer

## Alternatives
- [code-block](https://hazeui.com/ui/code-block.md)
- [tabs](https://hazeui.com/ui/tabs.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` | "haze-prompt-studio" | no | Unique prefix for editor and variable input IDs. |
| title | `string` | "Support triage prompt" | no | Prompt name displayed in the studio header. |
| version | `string` | "v4 · Draft" | no | Initial version status badge. |
| class | `string` |  | no | Extra classes on the outer section. |

## Accessibility
- The System and User tabs use the shared Haze Tabs component. Each editor and variable input has a label.
- The local test and Mark ready action announce updates via a polite status message.
- Key Tab: Move across the action buttons, active tab, prompt editor, and variable inputs
- Key Left / Right: Switch between the System and User editors
- Key Enter / Space: Activate the focused button or tab

## Agent prompts

### Install and use

Install the Haze UI block "Prompt studio" with `npx shadcn@latest add @haze/prompt-studio`. 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 PromptStudio from "@/components/haze/blocks/prompt-studio.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/prompt-studio.md

### Customize with real content

Adapt the Haze prompt-studio block for our product. Replace the demo values of these props with our real content: id, title, version, class. Keep the layout, the heading level rules and these accessibility details: The System and User tabs use the shared Haze Tabs component. Each editor and variable input has a label. The local test and Mark ready action announce updates via a polite status message. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using prompt-studio, check it fits: use it when reviewing parameterized system and user prompts with sample variable values; showing estimates for the filled-in prompts and a sample category based on keywords. Avoid it when you only need an end-user chat box without template variables; use ai-composer. Alternatives: @haze/code-block, @haze/tabs.

## Example requests that should lead here
- Add a prompt studio with System and User tabs, editable variables, a live token estimate, and a local test preview

## Source

```astro
---
import { Play, Rocket, SlidersHorizontal, Variable } from "@lucide/astro";
import Tabs from "../ui/tabs.astro";
import { cn } from "../../../lib/haze/utils";

interface Props {
  id?: string;
  title?: string;
  version?: string;
  class?: string;
}

const {
  id = "haze-prompt-studio",
  title = "Support triage prompt",
  version = "v4 · Draft",
  class: className,
} = Astro.props;

const systemPrompt = "You are a support triage assistant for {{product}}. Classify the ticket into billing, bug, or access, and respond in a {{tone}} tone under 80 words.";
const userPrompt = "Customer ticket: {{ticket}}";
const variables = { product: "Haze Cloud", tone: "calm, direct", ticket: "Our team got charged twice after upgrading seats." };
---

<section aria-labelledby={`${id}-title`} data-haze-prompt-studio class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
  <div class="mx-auto max-w-5xl overflow-hidden rounded-2xl border border-border bg-card">
    <header class="flex flex-wrap items-center justify-between gap-3 border-b border-border px-5 py-3.5">
      <div class="flex items-center gap-2.5">
        <SlidersHorizontal class="size-4 text-muted-foreground" aria-hidden="true" />
        <h2 id={`${id}-title`} class="text-sm/5 font-semibold text-foreground">{title}</h2>
        <span data-ps-ver class="rounded-md border border-frame-warning bg-warning/10 px-2 py-0.5 text-[0.6875rem]/4 font-medium text-warning data-[ready]:border-success-border data-[ready]:bg-success/10 data-[ready]:text-success">{version}</span>
      </div>
      <div class="flex flex-wrap items-center gap-2">
        <span data-ps-tokens class="font-mono text-xs text-muted-foreground tabular-nums"></span>
        <button type="button" data-ps-run disabled class="inline-flex h-8 cursor-pointer items-center gap-1.5 rounded-lg bg-primary px-3 text-xs font-medium text-primary-foreground hover:opacity-90 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring disabled:cursor-not-allowed disabled:opacity-45 transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
          <Play class="size-3.5" aria-hidden="true" />
          Run test
        </button>
        <button type="button" data-ps-promote disabled 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 disabled:cursor-not-allowed disabled:opacity-45 transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
          <Rocket class="size-3.5 text-muted-foreground" aria-hidden="true" />
          Mark ready
        </button>
      </div>
    </header>

    <div class="grid divide-y divide-border lg:grid-cols-[minmax(0,1.2fr)_minmax(0,0.9fr)] lg:divide-x lg:divide-y-0">
      <div class="p-5">
        <Tabs label="Prompt message role" tabs={[{ id: `${id}-system-panel`, label: "System" }, { id: `${id}-user-panel`, label: "User" }]}>
          <div id={`${id}-system-panel`}>
            <label for={`${id}-system`} class="sr-only">System prompt</label>
            <textarea
              id={`${id}-system`}
              data-ps-editor="system"
              rows="5"
              class="w-full rounded-xl border border-frame-input bg-field p-3 font-mono text-xs/6 text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground"
            >{systemPrompt}</textarea>
          </div>
          <div id={`${id}-user-panel`}>
            <label for={`${id}-user`} class="sr-only">User prompt</label>
            <textarea
              id={`${id}-user`}
              data-ps-editor="user"
              rows="5"
              class="w-full rounded-xl border border-frame-input bg-field p-3 font-mono text-xs/6 text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground"
            >{userPrompt}</textarea>
          </div>
        </Tabs>

        <div class="mt-4 space-y-2.5">
          <p class="inline-flex items-center gap-1.5 text-xs font-medium text-muted-foreground">
            <Variable class="size-3.5 text-muted-foreground" aria-hidden="true" />
            Template variables
          </p>
          <div class="grid gap-2.5 sm:grid-cols-2">
            <div class="grid gap-1">
              <label for={`${id}-v-product`} class="font-mono text-[0.6875rem] text-muted-foreground">{"{{product}}"}</label>
              <input id={`${id}-v-product`} data-ps-var="product" type="text" value={variables.product} class="h-9 rounded-lg border border-frame-input bg-field px-2.5 text-xs text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground" />
            </div>
            <div class="grid gap-1">
              <label for={`${id}-v-tone`} class="font-mono text-[0.6875rem] text-muted-foreground">{"{{tone}}"}</label>
              <input id={`${id}-v-tone`} data-ps-var="tone" type="text" value={variables.tone} class="h-9 rounded-lg border border-frame-input bg-field px-2.5 text-xs text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground" />
            </div>
            <div class="grid gap-1 sm:col-span-2">
              <label for={`${id}-v-ticket`} class="font-mono text-[0.6875rem] text-muted-foreground">{"{{ticket}}"}</label>
              <input id={`${id}-v-ticket`} data-ps-var="ticket" type="text" value={variables.ticket} class="h-9 rounded-lg border border-frame-input bg-field px-2.5 text-xs text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground" />
            </div>
          </div>
        </div>
      </div>

      <div class="flex flex-col justify-between bg-muted/40 p-5">
        <div>
          <h3 class="text-xs/4 font-medium tracking-wider text-muted-foreground uppercase">Local test preview</h3>
          <p class="mt-1 text-xs/5 text-muted-foreground">Review the filled-in prompts and a sample ticket category based on keywords.</p>
          <div data-ps-output class="mt-3 space-y-3 rounded-xl border border-border bg-card p-4 text-sm/6 text-foreground">
            <p class="text-xs font-medium text-foreground">Sample category <span data-ps-category class="font-mono">billing</span></p>
            <dl class="grid gap-3">
              <div>
                <dt class="text-xs font-medium text-muted-foreground">System</dt>
                <dd data-ps-output-system class="wrap-anywhere whitespace-pre-wrap">{systemPrompt.replace("{{product}}", variables.product).replace("{{tone}}", variables.tone)}</dd>
              </div>
              <div>
                <dt class="text-xs font-medium text-muted-foreground">User</dt>
                <dd data-ps-output-user class="wrap-anywhere whitespace-pre-wrap">{userPrompt.replace("{{ticket}}", variables.ticket)}</dd>
              </div>
            </dl>
          </div>
        </div>
        <p data-ps-status role="status" class="mt-4 min-h-4 text-xs/4 text-muted-foreground"></p>
      </div>
    </div>
  </div>
</section>

<script>
  function initPromptStudios() {
    document.querySelectorAll<HTMLElement>("[data-haze-prompt-studio]").forEach((root) => {
      if (root.hasAttribute("data-enhanced")) return;
      const sys = root.querySelector<HTMLTextAreaElement>('[data-ps-editor="system"]');
      const usr = root.querySelector<HTMLTextAreaElement>('[data-ps-editor="user"]');
      const variables = Array.from(root.querySelectorAll<HTMLInputElement>("[data-ps-var]"));
      const tokens = root.querySelector<HTMLElement>("[data-ps-tokens]");
      const systemOutput = root.querySelector<HTMLElement>("[data-ps-output-system]");
      const userOutput = root.querySelector<HTMLElement>("[data-ps-output-user]");
      const category = root.querySelector<HTMLElement>("[data-ps-category]");
      const status = root.querySelector<HTMLElement>("[data-ps-status]");
      const ver = root.querySelector<HTMLElement>("[data-ps-ver]");
      const run = root.querySelector<HTMLButtonElement>("[data-ps-run]");
      const markReady = root.querySelector<HTMLButtonElement>("[data-ps-promote]");
      if (!sys || !usr || !tokens || !systemOutput || !userOutput || !category || !status || !ver || !run || !markReady) return;
      root.setAttribute("data-enhanced", "");

      const resolve = (template: string) => template.replace(/\{\{\s*(\w+)\s*\}\}/g, (placeholder, name) =>
        variables.find((field) => field.dataset.psVar === name)?.value ?? placeholder,
      );
      const getPrompts = () => [resolve(sys.value), resolve(usr.value)] as const;

      const countTokens = () => {
        const text = getPrompts().join(" ").trim();
        const estimate = text ? Math.round(text.split(/\s+/).length * 1.35) : 0;
        tokens.textContent = `~${estimate} tokens`;
      };
      for (const field of [sys, usr, ...variables]) field.addEventListener("input", countTokens);
      countTokens();

      run.disabled = false;
      run.addEventListener("click", () => {
        const [system, user] = getPrompts();
        category.textContent = /\b(charg\w*|invoic\w*|bill\w*|refund\w*)\b/i.test(user) ? "billing"
          : /\b(access|log[ -]?in|password|sign[ -]?in)\b/i.test(user) ? "access"
          : /\b(bug|crash\w*|error\w*|broken)\b/i.test(user) ? "bug"
          : "general support";
        systemOutput.textContent = system || "Empty prompt";
        userOutput.textContent = user || "Empty prompt";
        status.textContent = "Local test preview updated.";
      });

      const version = ver.textContent?.replace(/\s+·\s+Draft$/, "");
      markReady.disabled = false;
      markReady.addEventListener("click", () => {
        ver.textContent = version ? `${version} · Ready in demo` : "Ready in demo";
        ver.setAttribute("data-ready", "");
        status.textContent = "Prompt marked ready for this preview.";
      });
    });
  }
  initPromptStudios();
  if (!document.documentElement.hasAttribute("data-haze-prompt-studio-listener")) {
    document.documentElement.setAttribute("data-haze-prompt-studio-listener", "");
    document.addEventListener("astro:page-load", initPromptStudios);
  }
</script>
```
