Xzero UI
Pro library

AI commandPro

A Cmd+K command palette with an AI mode. Search pages and actions, or press Tab to ask a question: the answer streams inside the palette with numbered sources, and the next steps it suggests, like filing a Linear issue or opening a Notion doc, run straight from the list.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui-pro/ai-command
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui-pro/ai-command

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { AiCommand } from "@/components/xzero/ai-command/ai-command";

// Sample walkthrough
<AiCommand />

// Wired to your app and model
<AiCommand
  items={commands}
  onSelect={item => { router.push(item.id); setOpen(false); }}
  onAsk={async (question, { signal, append, setSources }) => {
    const res = await fetch("/api/ask", { method: "POST", body: JSON.stringify({ question }), signal });
    const { sources, stream } = await readAnswer(res);
    setSources(sources);
    for await (const delta of stream) append(delta);
    return { actions: [{ id: "issue", label: "Create issue in Linear", run: s => createIssue(question, s) }] };
  }}
  onClose={() => setOpen(false)}
  elevated
/>

API reference

AiCommand

A fixed-size command palette with an AI mode. Search pages and actions, or press Tab to ask: the answer streams in place with numbered sources and runnable next steps. With no props it plays a sample walkthrough until someone interacts.

PropTypeDefaultDescription
itemsAiCommandItem[]sample workspacePages and actions to search: { id, label, group?, icon?, meta?, shortcut?, keywords?, suggested?, onSelect? }. Rows marked suggested show while the query is empty.
onSelect(item: AiCommandItem) => void–Runs when a page or action is chosen with Enter or a click. Close your dialog or navigate here.
onAsk(question, { signal, append, setSources }) => Promise<AiCommandAnswer | void>simulated engineAnswers a question. Stream text with append, show sources early with setSources, and resolve with { text?, sources?, actions? }. Throw to show the error state with Retry. The signal aborts when the person asks again or goes back.
onAction(action: AiCommandAction, result: string) => void–Runs after a suggested action finishes, with the label it ended on (for example "Created ENG-2481").
onSourceSelect(source: AiCommandSource) => void–Runs when a source chip or citation is chosen. Sources with an href open in a new tab instead.
suggestedQuestionsstring[]3 sample questionsQuestions offered while Ask AI is open and empty.
model{ name: string; mark?: ReactNode }{ name: "Claude Sonnet 5.5" }The model that answers, shown in the footer, the input and beside each answer.
defaultMode"search" | "ask""search"Mode on first render.
defaultQuerystring""Query on first render.
onModeChange(mode: "search" | "ask") => void–Runs when the palette switches between Search and Ask AI.
onClose() => void–Escape on an empty search. Use it to close the surrounding dialog.
placeholder{ search?: string; ask?: string }–Input placeholders per mode.
thinkingLabelstring"Searching your workspace"Status while the model works, before any text arrives.
autoPlaybooleantrue without items and onAskPlays a looping walkthrough while on screen. Stops for good on the first real pointer or key press inside, and never runs with reduced motion.
hotkeybooleanfalseListens for Cmd+K or Ctrl+K on the page and focuses the input.
heightnumber392Height of the results area in px. The palette keeps this size while typing, switching modes and streaming.
elevatedbooleanfalseAdds the floating shadow, for use inside a dialog or popover.
classNamestring–Class on the root.
styleCSSProperties–Inline styles on the root.
aria-labelstring"Command palette"Accessible name of the palette.

AiCommandAction

A suggested next step returned with an answer and run in place.

PropTypeDefaultDescription
id (required)string–Stable id.
label (required)string–Row label, such as "Create issue in Linear".
metastring–Quiet detail after the label.
markReactNode–16px brand mark or icon.
run(signal: AbortSignal) => Promise<string | void>–Does the work. Resolve with a done label or nothing; throw to show the error state (Enter retries).
runningLabel / doneLabel / errorLabel / doneMetastring–Labels for each state. doneMeta is where a simulated action says nothing was sent.

AiCommandSource

A document the answer cites as [1], [2] in its text.

PropTypeDefaultDescription
id (required)string–Stable id.
title (required)string–Short chip title, such as "billing-api #1893".
descriptionstring–Longer text for the tooltip and screen readers.
markReactNode–14px brand mark or icon.
hrefstring–Opens in a new tab when chosen.

Keyboard interactions

KeysAction
Up / DownMove through results, questions or suggested actions.
EnterOpen the page, run the action, ask the question, or retry a failed answer or action.
TabAsk AI about the current query. With an empty query it opens Ask AI with suggested questions; in that state Tab goes back to search.
EscapeFrom Ask AI, back to search (cancels a streaming answer). In search, clears the query, then calls onClose.
Cmd / Ctrl + KFocuses the input when hotkey is on.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in ai

Guidance for AI tools

AI command: A Cmd+K command palette with an AI mode. Search pages and actions, or press Tab to ask a question: the answer streams inside the palette with numbered sources, and the next steps it suggests, like filing a Linear issue or opening a Notion doc, run straight from the list. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components