Prompt composer
A message field with @ mentions and / commands.
Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/and the colour tokens go into your CSS.$ pnpm dlx asta-ui@latest add prompt-composerOr install the package
Don’t want the file? Import from
asta-ui/prompt-composerand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-uiimport { PromptComposer } from "asta-ui/prompt-composer";Or copy it by hand
Copy this file. Keep the paths, or fix the
@/imports. Then add the tokens fromglobals.css."use client"; import { useEffect, useId, useMemo, useRef, useState, type ClipboardEvent, type DragEvent, type KeyboardEvent, type ReactNode } from "react"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); export interface ComposerMention { id: string; label: string; type: "file" | "person" | "doc"; /** Muted text on the right, e.g. a path or a role. */ hint?: string; } export interface ComposerCommand { id: string; /** Without the slash, e.g. "summarize". */ label: string; hint?: string; } export type ComposerPart = { type: "text"; text: string } | { type: "mention"; item: ComposerMention } | { type: "command"; item: ComposerCommand }; export interface ComposerMessage { /** Plain text with tokens written as @label and /label. */ text: string; /** Text and tokens in order, for when you need the ids. */ parts: ComposerPart[]; files: File[]; } export interface PromptComposerProps { onSend: (message: ComposerMessage) => void; /** Called by the Stop button and by Escape while `running`. */ onStop?: () => void; /** The agent is working: Send turns into Stop and a light orbits the border. */ running?: boolean; /** Offered when you type @. */ mentions?: ComposerMention[]; /** Offered when you type /. */ commands?: ComposerCommand[]; /** A slot in the toolbar, e.g. a `ModelPicker` with variant="chip" side="top". */ model?: ReactNode; placeholder?: string; /** Accessible name of the field. Default "Message". */ label?: string; /** `accept` for the file picker. */ accept?: string; /** Bytes. Default 20 MB. */ maxFileSize?: number; disabled?: boolean; className?: string; } const KEYFRAMES = `@keyframes asta-pc-orbit { from { transform: translate(-50%, -50%) rotate(0turn) } to { transform: translate(-50%, -50%) rotate(1turn) } } @keyframes asta-pc-fade { from { opacity: 0 } } @keyframes asta-pc-chip { from { opacity: 0; transform: scale(.92) } } .asta-pc-ring { -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); mask-composite: exclude } .asta-pc-field:focus { outline: none } @media (prefers-reduced-motion: reduce) { .asta-pc, .asta-pc * { animation: none !important; transition-duration: 0s !important } .asta-pc-spin { background: color-mix(in srgb, var(--color-brand) 60%, transparent) !important } }`; const EASE = "cubic-bezier(.16,1,.3,1)"; const GLYPH: Record<string, string> = { file: "M6 3.5h8l4.5 4.5v12.5H6ZM14 3.5V8h4.5", doc: "M6 3.5h8l4.5 4.5v12.5H6ZM14 3.5V8h4.5M9 13h6M9 16.5h4", person: "M8.25 8.5a3.75 3.75 0 1 0 7.5 0a3.75 3.75 0 1 0-7.5 0M5 20a7 7 0 0 1 14 0", command: "M4.5 7l5 5-5 5M12 17.5h7.5", }; const svg = (d: string, cls = "h-3.5 w-3.5") => `<svg viewBox="0 0 24 24" class="${cls} shrink-0" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${d}"/></svg>`; function Icon({ d, className = "h-4 w-4" }: { d: string; className?: string }) { return ( <svg viewBox="0 0 24 24" className={cx("shrink-0", className)} fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d={d} /> </svg> ); } // Token chips live inside the contenteditable field, so they are plain DOM. Classes kept here for Tailwind. const CHIP = "mx-px inline-flex items-center gap-1 whitespace-nowrap rounded-[5px] px-1.5 align-baseline text-[0.93em] font-medium leading-[1.5] [animation:asta-pc-chip_.2s_cubic-bezier(.16,1,.3,1)]"; const CHIP_MENTION = "bg-[color-mix(in_srgb,var(--color-brand)_11%,transparent)] text-brand"; const CHIP_COMMAND = "bg-ink text-paper"; const GROUPS: { type: ComposerMention["type"]; label: string }[] = [ { type: "file", label: "Files" }, { type: "person", label: "People" }, { type: "doc", label: "Docs" }, ]; const size = (n: number) => (n < 1024 ? `${n} B` : n < 1024 ** 2 ? `${Math.round(n / 1024)} KB` : `${(n / 1024 ** 2).toFixed(1)} MB`); const initials = (s: string) => s .split(/\s+/) .map((w) => w[0]) .join("") .slice(0, 2) .toUpperCase(); type Menu = { kind: "@" | "/"; query: string; x: number }; type Item = { kind: "@"; item: ComposerMention } | { kind: "/"; item: ComposerCommand }; /** * The input of an agent app. The field grows as you type. @ opens a mention menu for files, people and docs, * / opens commands, and a pick becomes a token chip that Backspace removes in one go. Attach files as chips, * put a model picker in the toolbar, and press Enter to send (Shift + Enter for a new line). While the agent * works, Send turns into Stop and a band of light orbits the border. */ export function PromptComposer({ onSend, onStop, running = false, mentions = [], commands = [], model, placeholder = "Ask Astabyte to do something…", label = "Message", accept, maxFileSize = 20 * 1024 ** 2, disabled, className, }: PromptComposerProps) { const [empty, setEmpty] = useState(true); const [menu, setMenu] = useState<Menu | null>(null); const [active, setActive] = useState(0); const [files, setFiles] = useState<{ id: string; file: File }[]>([]); const [error, setError] = useState(""); const [status, setStatus] = useState(""); const [drag, setDrag] = useState(false); const [onScreen, setOnScreen] = useState(true); const root = useRef<HTMLDivElement>(null); const ed = useRef<HTMLDivElement>(null); const picker = useRef<HTMLInputElement>(null); const trig = useRef<{ node: Text; start: number } | null>(null); const dismissed = useRef<{ node: Text; start: number } | null>(null); const seq = useRef(0); const uid = useId(); // The orbit only spins while the composer is on screen and the tab is visible. useEffect(() => { const el = root.current; if (!el) return; let seen = true; const sync = () => setOnScreen(seen && !document.hidden); const io = new IntersectionObserver(([e]) => { seen = e.isIntersecting; sync(); }); io.observe(el); document.addEventListener("visibilitychange", sync); return () => { io.disconnect(); document.removeEventListener("visibilitychange", sync); }; }, []); const items: Item[] = useMemo(() => { if (!menu) return []; const q = menu.query.toLowerCase(); if (menu.kind === "/") return commands.filter((c) => c.label.toLowerCase().includes(q)).map((item) => ({ kind: "/" as const, item })); const hit = mentions.filter((m) => `${m.label} ${m.hint ?? ""}`.toLowerCase().includes(q)); return GROUPS.flatMap((g) => hit.filter((m) => m.type === g.type)).map((item) => ({ kind: "@" as const, item })); }, [menu, mentions, commands]); const act = Math.min(active, Math.max(items.length - 1, 0)); const sync = () => { const el = ed.current; if (el) setEmpty(!el.textContent && !el.querySelector("[data-token]")); }; // Reads the field into text + tokens. const read = (): Omit<ComposerMessage, "files"> => { const parts: ComposerPart[] = []; let buf = ""; const flush = () => { if (buf) parts.push({ type: "text", text: buf }); buf = ""; }; const walk = (node: Node) => { node.childNodes.forEach((c) => { if (c.nodeType === 3) buf += (c as Text).data; else if (c instanceof HTMLElement && c.dataset.token) { flush(); const id = c.dataset.id!; if (c.dataset.token === "/") { const item = commands.find((x) => x.id === id) ?? { id, label: c.dataset.label ?? id }; parts.push({ type: "command", item }); } else { const item = mentions.find((x) => x.id === id) ?? { id, label: c.dataset.label ?? id, type: "doc" as const }; parts.push({ type: "mention", item }); } } else if (c.nodeName === "BR") buf += "\n"; else if (c instanceof HTMLElement) { if (buf && !buf.endsWith("\n")) buf += "\n"; walk(c); } }); }; if (ed.current) walk(ed.current); flush(); const text = parts .map((p) => (p.type === "text" ? p.text : p.type === "mention" ? `@${p.item.label}` : `/${p.item.label}`)) .join("") .replace(/ /g, " ") .trim(); return { text, parts }; }; // Looks at the text before the caret for an @ or / trigger. const detect = () => { const sel = getSelection(); const n = sel?.anchorNode; if (!sel || !sel.isCollapsed || !n || n.nodeType !== 3 || !ed.current?.contains(n)) return setMenu(null); const before = (n as Text).data.slice(0, sel.anchorOffset); const m = before.match(/(?:^|\s)([@/])([^\s@/]{0,30})$/); const kind = m?.[1] as "@" | "/" | undefined; if (!m || !kind || !(kind === "@" ? mentions : commands).length) { trig.current = null; return setMenu(null); } const start = sel.anchorOffset - m[2].length - 1; if (dismissed.current?.node === n && dismissed.current.start === start) return setMenu(null); trig.current = { node: n as Text, start }; const r = document.createRange(); r.setStart(n, start); r.setEnd(n, start + 1); const box = root.current!.getBoundingClientRect(); const w = Math.min(320, box.width); const x = Math.max(0, Math.min(r.getBoundingClientRect().left - box.left - 10, box.width - w)); if (!menu || menu.kind !== kind || menu.query !== m[2]) setActive(0); setMenu({ kind, query: m[2], x }); }; const place = (node: Node, offset: number) => { const sel = getSelection(); const r = document.createRange(); r.setStart(node, offset); r.collapse(true); sel?.removeAllRanges(); sel?.addRange(r); }; const insert = (it: Item | undefined) => { const t = trig.current; const sel = getSelection(); if (!it || !t || !sel?.anchorNode) return; const r = document.createRange(); r.setStart(t.node, t.start); r.setEnd(sel.anchorNode, sel.anchorOffset); r.deleteContents(); const chip = document.createElement("span"); chip.contentEditable = "false"; chip.dataset.token = it.kind; chip.dataset.id = it.item.id; chip.dataset.label = it.item.label; chip.className = cx(CHIP, it.kind === "/" ? CHIP_COMMAND : CHIP_MENTION); chip.innerHTML = svg(GLYPH[it.kind === "/" ? "command" : (it.item as ComposerMention).type], "h-3 w-3"); chip.append(it.item.label); r.insertNode(chip); const space = document.createTextNode(" "); chip.after(space); place(space, 1); trig.current = null; setMenu(null); sync(); setStatus(`Added ${it.kind === "/" ? `command /${it.item.label}` : it.item.label}.`); }; // The token right before (or after) the caret, if any. const nextToken = (dir: -1 | 1): HTMLElement | null => { const sel = getSelection(); if (!sel?.isCollapsed || !sel.anchorNode) return null; const n = sel.anchorNode; const off = sel.anchorOffset; let sib: Node | null; if (n.nodeType === 3) { if (dir < 0 ? off > 0 : off < (n as Text).length) return null; sib = dir < 0 ? n.previousSibling : n.nextSibling; } else sib = n.childNodes[dir < 0 ? off - 1 : off] ?? null; while (sib && sib.nodeType === 3 && !(sib as Text).length) sib = dir < 0 ? sib.previousSibling : sib.nextSibling; return sib instanceof HTMLElement && sib.dataset.token ? sib : null; }; const addFiles = (list: FileList | File[]) => { const ok: { id: string; file: File }[] = []; let msg = ""; for (const file of Array.from(list)) { if (file.size > maxFileSize) msg = `${file.name} is ${size(file.size)}. Attach files under ${size(maxFileSize)}.`; else ok.push({ id: `f${seq.current++}`, file }); } setError(msg); if (ok.length) { setFiles((f) => [...f, ...ok]); setStatus(`Attached ${ok.map((f) => f.file.name).join(", ")}.`); } }; const send = () => { if (running || disabled) return; const msg = read(); if (!msg.text && !files.length) return; onSend({ ...msg, files: files.map((f) => f.file) }); if (ed.current) ed.current.innerHTML = ""; setFiles([]); setError(""); setMenu(null); sync(); ed.current?.focus(); }; const onKey = (e: KeyboardEvent<HTMLDivElement>) => { if (e.nativeEvent.isComposing) return; if (menu) { if (e.key === "ArrowDown" || e.key === "ArrowUp") { e.preventDefault(); if (items.length) setActive((act + (e.key === "ArrowDown" ? 1 : -1) + items.length) % items.length); return; } if ((e.key === "Enter" || e.key === "Tab") && items.length) { e.preventDefault(); return insert(items[act]); } if (e.key === "Escape") { e.preventDefault(); dismissed.current = trig.current; return setMenu(null); } } if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); return send(); } if (e.key === "Escape" && running) { e.preventDefault(); return onStop?.(); } if (e.key === "Backspace" || e.key === "Delete") { const tok = nextToken(e.key === "Backspace" ? -1 : 1); if (!tok) return; e.preventDefault(); const parent = tok.parentNode!; const at = Array.prototype.indexOf.call(parent.childNodes, tok); tok.remove(); place(parent, at); sync(); setStatus(`Removed ${tok.dataset.label}.`); } }; const onPaste = (e: ClipboardEvent<HTMLDivElement>) => { if (e.clipboardData.files.length) { e.preventDefault(); return addFiles(e.clipboardData.files); } // Paste as plain text so no foreign markup lands in the field. e.preventDefault(); const text = e.clipboardData.getData("text/plain"); if (!document.execCommand("insertText", false, text)) { const sel = getSelection(); const r = sel?.rangeCount ? sel.getRangeAt(0) : null; if (!r) return; r.deleteContents(); const node = document.createTextNode(text); r.insertNode(node); place(node, node.length); } sync(); }; const onDrop = (e: DragEvent<HTMLFormElement>) => { setDrag(false); if (!e.dataTransfer.files.length || disabled) return; e.preventDefault(); addFiles(e.dataTransfer.files); }; const canSend = !empty || files.length > 0; const listId = `${uid}-menu`; const optId = (i: number) => `${uid}-o-${i}`; const groupOf = (it: Item) => (it.kind === "/" ? "Commands" : GROUPS.find((g) => g.type === it.item.type)!.label); return ( <div ref={root} className={cx("asta-pc relative w-full", className)}> <style href="asta-prompt-composer" precedence="asta">{KEYFRAMES}</style> <p className="sr-only" aria-live="polite"> {status} </p> {menu && ( <div id={listId} role="listbox" aria-label={menu.kind === "@" ? "Mention" : "Commands"} onPointerDown={(e) => e.preventDefault()} className="absolute bottom-full z-50 mb-2 max-h-[280px] w-[320px] max-w-full overflow-y-auto overscroll-contain rounded-xl bg-paper p-1.5 shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ink)_10%,transparent),0_16px_40px_-12px_rgb(0_0_0/0.25),0_4px_10px_-6px_rgb(0_0_0/0.1)] [scrollbar-width:thin]" style={{ left: menu.x, animation: `asta-pc-fade .12s ${EASE}` }} > {items.length === 0 && <p className="px-2.5 py-5 text-center text-[12.5px] text-mute">Nothing matches “{menu.query}”</p>} {items.map((it, i) => { const group = groupOf(it); const head = i === 0 || group !== groupOf(items[i - 1]); const person = it.kind === "@" && it.item.type === "person"; return ( <div key={`${it.kind}${it.item.id}`} role="presentation"> {head && ( <p role="presentation" className="px-2.5 pt-2 pb-1 font-mono text-[10.5px] uppercase tracking-wider text-mute"> {group} </p> )} <div id={optId(i)} role="option" aria-selected={i === act} onPointerMove={() => i !== act && setActive(i)} onClick={() => insert(it)} className={cx("flex h-9 cursor-pointer select-none items-center gap-2.5 rounded-lg px-2.5 text-[13.5px] transition-colors duration-100", i === act ? "bg-paper-2 text-ink" : "text-ink-2")} > {person ? ( <span aria-hidden className="grid h-5 w-5 shrink-0 place-items-center rounded-full bg-ink text-[9px] font-semibold text-paper"> {initials(it.item.label)} </span> ) : ( <span aria-hidden className={cx("grid h-5 w-5 shrink-0 place-items-center rounded-[5px]", it.kind === "/" ? "bg-ink text-paper" : "bg-paper-2 text-ink-2")}> <Icon d={GLYPH[it.kind === "/" ? "command" : it.item.type]} className="h-3 w-3" /> </span> )} <span className="min-w-0 flex-1 truncate font-medium"> {it.kind === "/" && "/"} {it.item.label} </span> {it.item.hint && <span className="max-w-[45%] shrink-0 truncate text-[12px] text-mute">{it.item.hint}</span>} </div> </div> ); })} </div> )} <form onSubmit={(e) => { e.preventDefault(); send(); }} onDragOver={(e) => { if (!disabled && e.dataTransfer.types.includes("Files")) { e.preventDefault(); setDrag(true); } }} onDragLeave={(e) => !e.currentTarget.contains(e.relatedTarget as Node) && setDrag(false)} onDrop={onDrop} className={cx( "relative flex flex-col rounded-[14px] bg-paper transition-shadow duration-200", "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_12%,transparent),0_1px_2px_rgb(0_0_0/0.04),0_8px_24px_-16px_rgb(0_0_0/0.18)]", !running && "focus-within:shadow-[inset_0_0_0_1px_var(--color-brand),0_0_0_3px_color-mix(in_srgb,var(--color-brand)_14%,transparent)]", drag && "shadow-[inset_0_0_0_1.5px_var(--color-brand),0_0_0_4px_color-mix(in_srgb,var(--color-brand)_14%,transparent)]", disabled && "opacity-50", )} > {/* A band of light orbiting the border while the agent works: a rotating conic layer clipped to a 1.5px ring. */} <span aria-hidden className={cx("asta-pc-ring pointer-events-none absolute -inset-px overflow-hidden rounded-[15px] p-[1.5px] transition-opacity duration-500", running ? "opacity-100" : "opacity-0")}> <span className="asta-pc-spin absolute left-1/2 top-1/2 aspect-square w-[220%]" style={{ background: "conic-gradient(from 0deg, transparent 0 52%, color-mix(in srgb, var(--color-brand) 25%, transparent) 70%, var(--color-brand) 92%, transparent 100%)", animation: `asta-pc-orbit 2.6s linear infinite ${running && onScreen ? "running" : "paused"}`, transform: "translate(-50%, -50%)", }} /> </span> {files.length > 0 && ( <ul aria-label="Attached files" className="flex flex-wrap gap-1.5 px-3 pt-3"> {files.map(({ id, file }) => ( <li key={id} className="flex h-9 max-w-full items-center gap-2 rounded-lg bg-paper-2 pl-2 pr-1 text-[12.5px]" style={{ animation: `asta-pc-chip .22s ${EASE}` }}> <span aria-hidden className="grid h-6 w-6 shrink-0 place-items-center rounded-md bg-paper text-ink-2"> <Icon d={GLYPH.file} className="h-3.5 w-3.5" /> </span> <span className="min-w-0 truncate font-medium text-ink sm:max-w-[180px]">{file.name}</span> <span className="shrink-0 tabular-nums text-mute">{size(file.size)}</span> <button type="button" aria-label={`Remove ${file.name}`} onClick={() => { setFiles((f) => f.filter((x) => x.id !== id)); setStatus(`Removed ${file.name}.`); ed.current?.focus(); }} className="grid h-7 w-7 shrink-0 place-items-center rounded-md text-mute outline-none transition-colors hover:bg-paper hover:text-ink focus-visible:ring-2 focus-visible:ring-brand/50" > <Icon d="M6 6l12 12M18 6 6 18" className="h-3 w-3" /> </button> </li> ))} </ul> )} <div className="relative px-4 pt-3.5"> {empty && ( <span aria-hidden className="pointer-events-none absolute left-4 top-3.5 truncate pr-4 text-[16px] leading-relaxed text-mute sm:text-[14.5px]"> {placeholder} </span> )} <div ref={ed} role="textbox" aria-multiline="true" aria-label={label} aria-placeholder={placeholder} aria-disabled={disabled || undefined} aria-autocomplete="list" aria-controls={menu ? listId : undefined} aria-activedescendant={menu && items.length ? optId(act) : undefined} contentEditable={!disabled} suppressContentEditableWarning spellCheck enterKeyHint="send" onInput={() => { sync(); detect(); }} onKeyDown={onKey} onKeyUp={(e) => (e.key === "ArrowLeft" || e.key === "ArrowRight" || e.key === "Home" || e.key === "End") && detect()} onClick={detect} onBlur={() => setMenu(null)} onPaste={onPaste} className="asta-pc-field max-h-[200px] min-h-[52px] overflow-y-auto whitespace-pre-wrap break-words pb-2 text-[16px] leading-relaxed text-ink outline-none sm:text-[14.5px] [scrollbar-width:thin]" /> </div> <div className="flex items-center gap-1 px-2 pb-2"> <input ref={picker} type="file" multiple accept={accept} tabIndex={-1} className="sr-only" aria-hidden onChange={(e) => { if (e.target.files) addFiles(e.target.files); e.target.value = ""; }} /> <button type="button" disabled={disabled} aria-label="Attach files" title="Attach files" onClick={() => picker.current?.click()} className="grid h-8 w-8 shrink-0 place-items-center rounded-md text-ink-2 outline-none transition-colors duration-150 hover:bg-paper-2 hover:text-ink focus-visible:ring-2 focus-visible:ring-brand/50 disabled:opacity-45" > <Icon d="M19 11.5l-7.4 7.4a4.5 4.5 0 0 1-6.4-6.4L13 4.7a3 3 0 0 1 4.2 4.2l-7.7 7.7a1.5 1.5 0 0 1-2.1-2.1l7-7" /> </button> {model} <span className="ml-auto" /> {running ? ( <button key="stop" type="button" onClick={onStop} aria-label="Stop the agent" className="flex h-8 shrink-0 items-center gap-1.5 rounded-lg bg-ink pl-2.5 pr-3 text-[13px] font-medium text-paper outline-none transition-transform duration-150 active:scale-95 focus-visible:ring-2 focus-visible:ring-brand/50 focus-visible:ring-offset-2 focus-visible:ring-offset-paper" style={{ animation: `asta-pc-chip .22s ${EASE}` }} > <span aria-hidden className="h-2.5 w-2.5 rounded-[2px] bg-current" /> Stop </button> ) : ( <button key="send" type="submit" disabled={!canSend || disabled} aria-label="Send message" className="grid h-8 w-8 shrink-0 place-items-center rounded-lg bg-brand text-on-brand outline-none transition-[opacity,transform] duration-150 active:scale-95 disabled:opacity-35 focus-visible:ring-2 focus-visible:ring-brand/50 focus-visible:ring-offset-2 focus-visible:ring-offset-paper" style={{ animation: `asta-pc-chip .22s ${EASE}` }} > <Icon d="M12 20V5M6 11l6-6 6 6" /> </button> )} </div> </form> <p className={cx("mt-2 flex min-h-[18px] items-center gap-1.5 px-1 text-[12px]", error ? "font-medium text-ink" : "text-mute")} role={error ? "alert" : undefined}> {error ? ( <> <Icon d="M10.3 4.6 3 17.5A2 2 0 0 0 4.7 20.5h14.6a2 2 0 0 0 1.7-3L13.7 4.6a2 2 0 0 0-3.4 0ZM12 9.5v4M12 17h.01" className="h-3.5 w-3.5" /> {error} </> ) : running ? ( "Astabyte is working. Press Esc or Stop to end the run." ) : ( <span className="hidden sm:inline">Enter to send · Shift + Enter for a new line · @ to mention · / for commands</span> )} </p> </div> ); } export default PromptComposer;Or ask your AI agent
Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.
Add the Astabyte UI Prompt composer component to my project. A message field with @ mentions and / commands. It includes: mentions, commands, token chips, attachments, model slot, stop, keys. Install it: ```sh pnpm dlx asta-ui@latest add prompt-composer --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/prompt-composer.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { ModelPicker, type ModelOption } from "@/components/astabyte/model-picker"; import { PromptComposer, type ComposerCommand, type ComposerMention, type ComposerMessage } from "@/components/astabyte/prompt-composer"; ``` Usage example and props: https://ui.astabyte.com/prompt-composer Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Or use plain HTML + CSS
Not on React? Use it from Django, Rails, Laravel, Go
html/template, htmx or a static page. Loadasta.cssandasta.jsonce (thehead.htmltab), then paste the markup. Theui.astabyte.com/cdnlink is temporary: pin a version from jsDelivr for production. More in HTML + CSS.<!-- Prompt composer. asta.js turns @ and / picks into chips, sends on Enter, lists files and fills the hidden inputs. With hx-post on the form it sets data-running during the request. Without action or hx-*, listen for "asta:prompt-send" and toggle data-running yourself. The second composer shows the running state. --> <div style="display:grid;gap:40px;max-width:640px;padding-top:300px"> <div class="asta-prompt" data-asta-prompt> <ul class="asta-prompt-menu" role="listbox" aria-label="Mention a file, person or doc" data-asta-prompt-menu="@" hidden> <li class="asta-prompt-group" role="presentation">Files</li> <li id="pc1-m-1" class="asta-prompt-option" role="option" aria-selected="false" data-id="f1" data-label="pricing-v3.fig" data-type="file"><span class="asta-prompt-option-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 2.5H5A1.5 1.5 0 0 0 3.5 4v8A1.5 1.5 0 0 0 5 13.5h6a1.5 1.5 0 0 0 1.5-1.5V6L9 2.5ZM9 2.5V6h3.5"/></svg></span><b>pricing-v3.fig</b><small>Design</small></li> <li id="pc1-m-2" class="asta-prompt-option" role="option" aria-selected="false" data-id="f2" data-label="q3-revenue.csv" data-type="file"><span class="asta-prompt-option-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 2.5H5A1.5 1.5 0 0 0 3.5 4v8A1.5 1.5 0 0 0 5 13.5h6a1.5 1.5 0 0 0 1.5-1.5V6L9 2.5ZM9 2.5V6h3.5"/></svg></span><b>q3-revenue.csv</b><small>Finance</small></li> <li id="pc1-m-3" class="asta-prompt-option" role="option" aria-selected="false" data-id="f3" data-label="signup-form.tsx" data-type="file"><span class="asta-prompt-option-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 2.5H5A1.5 1.5 0 0 0 3.5 4v8A1.5 1.5 0 0 0 5 13.5h6a1.5 1.5 0 0 0 1.5-1.5V6L9 2.5ZM9 2.5V6h3.5"/></svg></span><b>signup-form.tsx</b><small>app/onboarding</small></li> <li class="asta-prompt-group" role="presentation">People</li> <li id="pc1-m-4" class="asta-prompt-option" role="option" aria-selected="false" data-id="p1" data-label="Rani Wijaya" data-type="person"><span class="asta-prompt-option-avatar" aria-hidden="true">RW</span><b>Rani Wijaya</b><small>Design lead</small></li> <li id="pc1-m-5" class="asta-prompt-option" role="option" aria-selected="false" data-id="p2" data-label="Theo Marsh" data-type="person"><span class="asta-prompt-option-avatar" aria-hidden="true">TM</span><b>Theo Marsh</b><small>Engineering</small></li> <li id="pc1-m-6" class="asta-prompt-option" role="option" aria-selected="false" data-id="p3" data-label="Maya Sato" data-type="person"><span class="asta-prompt-option-avatar" aria-hidden="true">MS</span><b>Maya Sato</b><small>Support</small></li> <li class="asta-prompt-group" role="presentation">Docs</li> <li id="pc1-m-7" class="asta-prompt-option" role="option" aria-selected="false" data-id="d1" data-label="Launch plan" data-type="doc"><span class="asta-prompt-option-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4.5 2.5h7a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1h-7a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1ZM6 6h4M6 8.5h4M6 11h2.5"/></svg></span><b>Launch plan</b><small>Edited 2d ago</small></li> <li id="pc1-m-8" class="asta-prompt-option" role="option" aria-selected="false" data-id="d2" data-label="Pricing FAQ" data-type="doc"><span class="asta-prompt-option-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4.5 2.5h7a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1h-7a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1ZM6 6h4M6 8.5h4M6 11h2.5"/></svg></span><b>Pricing FAQ</b><small>Help center</small></li> <li class="asta-prompt-empty" role="presentation" hidden>No matches. Keep typing to send it as text.</li></ul> <ul class="asta-prompt-menu" role="listbox" aria-label="Commands" data-asta-prompt-menu="/" hidden><li class="asta-prompt-group" role="presentation">Commands</li> <li id="pc1-c-1" class="asta-prompt-option" role="option" aria-selected="false" data-id="summarize" data-label="summarize" data-type="command"><span class="asta-prompt-option-icon asta-prompt-option-command"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.5 2.5 5.5 13.5"/></svg></span><b>/summarize</b><small>A short summary</small></li> <li id="pc1-c-2" class="asta-prompt-option" role="option" aria-selected="false" data-id="draft" data-label="draft" data-type="command"><span class="asta-prompt-option-icon asta-prompt-option-command"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.5 2.5 5.5 13.5"/></svg></span><b>/draft</b><small>Write a first version</small></li> <li id="pc1-c-3" class="asta-prompt-option" role="option" aria-selected="false" data-id="review" data-label="review" data-type="command"><span class="asta-prompt-option-icon asta-prompt-option-command"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.5 2.5 5.5 13.5"/></svg></span><b>/review</b><small>Find problems</small></li> <li id="pc1-c-4" class="asta-prompt-option" role="option" aria-selected="false" data-id="plan" data-label="plan" data-type="command"><span class="asta-prompt-option-icon asta-prompt-option-command"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.5 2.5 5.5 13.5"/></svg></span><b>/plan</b><small>List steps first</small></li> <li id="pc1-c-5" class="asta-prompt-option" role="option" aria-selected="false" data-id="translate" data-label="translate" data-type="command"><span class="asta-prompt-option-icon asta-prompt-option-command"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.5 2.5 5.5 13.5"/></svg></span><b>/translate</b><small>Into another language</small></li> <li class="asta-prompt-empty" role="presentation" hidden>No command by that name.</li></ul> <form class="asta-prompt-box"> <span class="asta-prompt-ring" aria-hidden="true"><span class="asta-prompt-spin"></span></span> <ul class="asta-prompt-files" aria-label="Attached files" data-asta-prompt-files hidden></ul> <div class="asta-prompt-field-wrap"><span class="asta-prompt-placeholder" aria-hidden="true">Ask Astabyte to do something…</span><div class="asta-prompt-field" role="textbox" contenteditable="true" aria-multiline="true" aria-label="Message" aria-autocomplete="list" aria-haspopup="listbox" aria-expanded="false" aria-describedby="pc1-note" data-asta-prompt-field></div></div> <input type="hidden" name="prompt" data-asta-prompt-value><input type="hidden" name="refs" data-asta-prompt-refs> <div class="asta-prompt-bar"><label class="asta-prompt-attach" title="Attach files"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M13 7.5 8.2 12.3a3 3 0 0 1-4.3-4.2l5-5a2 2 0 0 1 2.8 2.8l-5 5a1 1 0 0 1-1.4-1.4L9.8 5"/></svg><span class="asta-sr-only">Attach files</span><input type="file" name="files" multiple class="asta-sr-only" data-asta-prompt-input></label> <div class="asta-model-picker asta-model-picker-chip asta-model-picker-top" data-asta-model> <button type="button" id="pc1-mp-trigger" class="asta-model-picker-trigger" aria-haspopup="listbox" aria-expanded="false" aria-controls="pc1-mp-list" aria-label="Model" data-asta-model-trigger><svg class="asta-model-picker-icon" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path d="M8 1.5c.4 2.9 1.6 4.1 4.5 4.5-2.9.4-4.1 1.6-4.5 4.5-.4-2.9-1.6-4.1-4.5-4.5C6.4 5.6 7.6 4.4 8 1.5Z"/></svg><span class="asta-model-picker-value" data-asta-model-label>Astra 2</span><span class="asta-model-picker-tag" data-asta-model-tag hidden></span><svg class="asta-model-picker-chevron" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m4 10 4-4 4 4"/></svg></button> <input type="hidden" name="model" value="astra-2" data-asta-model-value> <div class="asta-model-picker-panel" hidden> <div class="asta-model-picker-search"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="7" cy="7" r="4.5"/><path d="m10.5 10.5 3 3"/></svg><input type="search" class="asta-model-picker-search-input" role="combobox" aria-expanded="true" aria-controls="pc1-mp-list" aria-autocomplete="list" aria-label="Search models" placeholder="Search models" autocomplete="off" spellcheck="false" data-asta-model-search></div> <div id="pc1-mp-list" class="asta-model-picker-list" role="listbox" aria-label="Models"><span class="asta-model-picker-mark" aria-hidden="true"></span><span class="asta-model-picker-bar" aria-hidden="true"></span> <div role="group" aria-labelledby="pc1-mp-g0"><p id="pc1-mp-g0" class="asta-model-picker-group">Astra 2</p> <div id="pc1-mp-o1" class="asta-model-picker-option" role="option" data-value="astra-2-pro" data-label="Astra 2 Pro" aria-selected="false"> <span class="asta-model-picker-main"><span class="asta-model-picker-name">Astra 2 Pro <span class="asta-model-picker-new">New</span></span><span class="asta-model-picker-hint">Deep reasoning for hard tasks</span></span> <span class="asta-model-picker-meters"><span class="asta-model-picker-meter"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 1.5 3.5 9H8l-1 5.5L12.5 7H8z"/></svg><span class="asta-model-picker-dots" aria-hidden="true"><span data-on></span><span data-on></span><span></span><span></span><span></span></span><span class="asta-sr-only">Speed 2 of 5</span></span><span class="asta-model-picker-meter"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 2.5c.3 2.2 1.3 3.2 3.5 3.5-2.2.3-3.2 1.3-3.5 3.5-.3-2.2-1.3-3.2-3.5-3.5 2.2-.3 3.2-1.3 3.5-3.5ZM12.5 10.5v3M11 12h3"/></svg><span class="asta-model-picker-dots" aria-hidden="true"><span data-on></span><span data-on></span><span data-on></span><span data-on></span><span data-on></span></span><span class="asta-sr-only">Intelligence 5 of 5</span></span></span> <span class="asta-model-picker-context">1M</span> <svg class="asta-model-picker-check" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m3.5 8.5 3 3 6-7"/></svg> </div> <div id="pc1-mp-o2" class="asta-model-picker-option" role="option" data-value="astra-2" data-label="Astra 2" data-tag="Default" aria-selected="true"> <span class="asta-model-picker-main"><span class="asta-model-picker-name">Astra 2</span><span class="asta-model-picker-hint">Balanced for everyday work</span></span> <span class="asta-model-picker-meters"><span class="asta-model-picker-meter"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 1.5 3.5 9H8l-1 5.5L12.5 7H8z"/></svg><span class="asta-model-picker-dots" aria-hidden="true"><span data-on></span><span data-on></span><span data-on></span><span data-on></span><span></span></span><span class="asta-sr-only">Speed 4 of 5</span></span><span class="asta-model-picker-meter"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 2.5c.3 2.2 1.3 3.2 3.5 3.5-2.2.3-3.2 1.3-3.5 3.5-.3-2.2-1.3-3.2-3.5-3.5 2.2-.3 3.2-1.3 3.5-3.5ZM12.5 10.5v3M11 12h3"/></svg><span class="asta-model-picker-dots" aria-hidden="true"><span data-on></span><span data-on></span><span data-on></span><span data-on></span><span></span></span><span class="asta-sr-only">Intelligence 4 of 5</span></span></span> <span class="asta-model-picker-context">400K</span> <svg class="asta-model-picker-check" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m3.5 8.5 3 3 6-7"/></svg> </div> </div> <div role="group" aria-labelledby="pc1-mp-g1"><p id="pc1-mp-g1" class="asta-model-picker-group">Realtime</p> <div id="pc1-mp-o3" class="asta-model-picker-option" role="option" data-value="astra-fast" data-label="Astra Fast" aria-selected="false"> <span class="asta-model-picker-main"><span class="asta-model-picker-name">Astra Fast</span><span class="asta-model-picker-hint">Lowest latency for live chat</span></span> <span class="asta-model-picker-meters"><span class="asta-model-picker-meter"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 1.5 3.5 9H8l-1 5.5L12.5 7H8z"/></svg><span class="asta-model-picker-dots" aria-hidden="true"><span data-on></span><span data-on></span><span data-on></span><span data-on></span><span data-on></span></span><span class="asta-sr-only">Speed 5 of 5</span></span><span class="asta-model-picker-meter"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 2.5c.3 2.2 1.3 3.2 3.5 3.5-2.2.3-3.2 1.3-3.5 3.5-.3-2.2-1.3-3.2-3.5-3.5 2.2-.3 3.2-1.3 3.5-3.5ZM12.5 10.5v3M11 12h3"/></svg><span class="asta-model-picker-dots" aria-hidden="true"><span data-on></span><span data-on></span><span></span><span></span><span></span></span><span class="asta-sr-only">Intelligence 2 of 5</span></span></span> <span class="asta-model-picker-context">32K</span> <svg class="asta-model-picker-check" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m3.5 8.5 3 3 6-7"/></svg> </div> </div> <div class="asta-model-picker-empty" data-asta-model-empty hidden><b>No models found</b><span>Nothing matches “<span data-asta-model-query></span>”. Try a family name.</span></div> </div> </div></div> <button type="submit" class="asta-prompt-send" aria-label="Send message" disabled><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 13V3M3.5 7.5 8 3l4.5 4.5"/></svg></button><button type="button" class="asta-prompt-stop" aria-label="Stop the agent" data-asta-prompt-stop>Stop</button></div> </form> <p id="pc1-note" class="asta-prompt-note" role="status" data-asta-prompt-note>Enter to send · Shift + Enter for a new line · @ to mention · / for commands</p> </div> <div class="asta-prompt" data-asta-prompt data-running data-filled> <form class="asta-prompt-box"> <span class="asta-prompt-ring" aria-hidden="true"><span class="asta-prompt-spin"></span></span> <ul class="asta-prompt-files" aria-label="Attached files" data-asta-prompt-files><li class="asta-prompt-file"><span class="asta-prompt-file-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 2.5H5A1.5 1.5 0 0 0 3.5 4v8A1.5 1.5 0 0 0 5 13.5h6a1.5 1.5 0 0 0 1.5-1.5V6L9 2.5ZM9 2.5V6h3.5"/></svg></span><span class="asta-prompt-file-name">q3-revenue.csv</span><span class="asta-prompt-file-size">184 KB</span><button type="button" class="asta-prompt-file-remove" aria-label="Remove q3-revenue.csv"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m4 4 8 8M12 4l-8 8"/></svg></button></li></ul> <div class="asta-prompt-field-wrap"><span class="asta-prompt-placeholder" aria-hidden="true">Ask Astabyte to do something…</span><div class="asta-prompt-field" role="textbox" contenteditable="true" aria-multiline="true" aria-label="Message" aria-autocomplete="list" aria-haspopup="listbox" aria-expanded="false" aria-describedby="pc2-note" aria-busy="true" data-asta-prompt-field>Compare <span class="asta-prompt-chip" contenteditable="false" data-token="@" data-id="d2" data-label="Pricing FAQ"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4.5 2.5h7a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1h-7a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1ZM6 6h4M6 8.5h4M6 11h2.5"/></svg>Pricing FAQ</span> with the new tiers and <span class="asta-prompt-chip asta-prompt-chip-command" contenteditable="false" data-token="/" data-id="draft" data-label="draft"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.5 2.5 5.5 13.5"/></svg>draft</span> a reply</div></div> <input type="hidden" name="prompt" data-asta-prompt-value><input type="hidden" name="refs" data-asta-prompt-refs> <div class="asta-prompt-bar"><label class="asta-prompt-attach" title="Attach files"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M13 7.5 8.2 12.3a3 3 0 0 1-4.3-4.2l5-5a2 2 0 0 1 2.8 2.8l-5 5a1 1 0 0 1-1.4-1.4L9.8 5"/></svg><span class="asta-sr-only">Attach files</span><input type="file" name="files" multiple class="asta-sr-only" data-asta-prompt-input></label> <div class="asta-model-picker asta-model-picker-chip asta-model-picker-top" data-asta-model> <button type="button" id="pc2-mp-trigger" class="asta-model-picker-trigger" aria-haspopup="listbox" aria-expanded="false" aria-controls="pc2-mp-list" aria-label="Model" data-asta-model-trigger><svg class="asta-model-picker-icon" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path d="M8 1.5c.4 2.9 1.6 4.1 4.5 4.5-2.9.4-4.1 1.6-4.5 4.5-.4-2.9-1.6-4.1-4.5-4.5C6.4 5.6 7.6 4.4 8 1.5Z"/></svg><span class="asta-model-picker-value" data-asta-model-label>Astra 2</span><span class="asta-model-picker-tag" data-asta-model-tag hidden></span><svg class="asta-model-picker-chevron" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m4 10 4-4 4 4"/></svg></button> <input type="hidden" name="model" value="astra-2" data-asta-model-value> <div class="asta-model-picker-panel" hidden> <div class="asta-model-picker-search"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="7" cy="7" r="4.5"/><path d="m10.5 10.5 3 3"/></svg><input type="search" class="asta-model-picker-search-input" role="combobox" aria-expanded="true" aria-controls="pc2-mp-list" aria-autocomplete="list" aria-label="Search models" placeholder="Search models" autocomplete="off" spellcheck="false" data-asta-model-search></div> <div id="pc2-mp-list" class="asta-model-picker-list" role="listbox" aria-label="Models"><span class="asta-model-picker-mark" aria-hidden="true"></span><span class="asta-model-picker-bar" aria-hidden="true"></span> <div role="group" aria-labelledby="pc2-mp-g0"><p id="pc2-mp-g0" class="asta-model-picker-group">Astra 2</p> <div id="pc2-mp-o1" class="asta-model-picker-option" role="option" data-value="astra-2-pro" data-label="Astra 2 Pro" aria-selected="false"> <span class="asta-model-picker-main"><span class="asta-model-picker-name">Astra 2 Pro <span class="asta-model-picker-new">New</span></span><span class="asta-model-picker-hint">Deep reasoning for hard tasks</span></span> <span class="asta-model-picker-meters"><span class="asta-model-picker-meter"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 1.5 3.5 9H8l-1 5.5L12.5 7H8z"/></svg><span class="asta-model-picker-dots" aria-hidden="true"><span data-on></span><span data-on></span><span></span><span></span><span></span></span><span class="asta-sr-only">Speed 2 of 5</span></span><span class="asta-model-picker-meter"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 2.5c.3 2.2 1.3 3.2 3.5 3.5-2.2.3-3.2 1.3-3.5 3.5-.3-2.2-1.3-3.2-3.5-3.5 2.2-.3 3.2-1.3 3.5-3.5ZM12.5 10.5v3M11 12h3"/></svg><span class="asta-model-picker-dots" aria-hidden="true"><span data-on></span><span data-on></span><span data-on></span><span data-on></span><span data-on></span></span><span class="asta-sr-only">Intelligence 5 of 5</span></span></span> <span class="asta-model-picker-context">1M</span> <svg class="asta-model-picker-check" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m3.5 8.5 3 3 6-7"/></svg> </div> <div id="pc2-mp-o2" class="asta-model-picker-option" role="option" data-value="astra-2" data-label="Astra 2" data-tag="Default" aria-selected="true"> <span class="asta-model-picker-main"><span class="asta-model-picker-name">Astra 2</span><span class="asta-model-picker-hint">Balanced for everyday work</span></span> <span class="asta-model-picker-meters"><span class="asta-model-picker-meter"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 1.5 3.5 9H8l-1 5.5L12.5 7H8z"/></svg><span class="asta-model-picker-dots" aria-hidden="true"><span data-on></span><span data-on></span><span data-on></span><span data-on></span><span></span></span><span class="asta-sr-only">Speed 4 of 5</span></span><span class="asta-model-picker-meter"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 2.5c.3 2.2 1.3 3.2 3.5 3.5-2.2.3-3.2 1.3-3.5 3.5-.3-2.2-1.3-3.2-3.5-3.5 2.2-.3 3.2-1.3 3.5-3.5ZM12.5 10.5v3M11 12h3"/></svg><span class="asta-model-picker-dots" aria-hidden="true"><span data-on></span><span data-on></span><span data-on></span><span data-on></span><span></span></span><span class="asta-sr-only">Intelligence 4 of 5</span></span></span> <span class="asta-model-picker-context">400K</span> <svg class="asta-model-picker-check" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m3.5 8.5 3 3 6-7"/></svg> </div> </div> <div role="group" aria-labelledby="pc2-mp-g1"><p id="pc2-mp-g1" class="asta-model-picker-group">Realtime</p> <div id="pc2-mp-o3" class="asta-model-picker-option" role="option" data-value="astra-fast" data-label="Astra Fast" aria-selected="false"> <span class="asta-model-picker-main"><span class="asta-model-picker-name">Astra Fast</span><span class="asta-model-picker-hint">Lowest latency for live chat</span></span> <span class="asta-model-picker-meters"><span class="asta-model-picker-meter"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 1.5 3.5 9H8l-1 5.5L12.5 7H8z"/></svg><span class="asta-model-picker-dots" aria-hidden="true"><span data-on></span><span data-on></span><span data-on></span><span data-on></span><span data-on></span></span><span class="asta-sr-only">Speed 5 of 5</span></span><span class="asta-model-picker-meter"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 2.5c.3 2.2 1.3 3.2 3.5 3.5-2.2.3-3.2 1.3-3.5 3.5-.3-2.2-1.3-3.2-3.5-3.5 2.2-.3 3.2-1.3 3.5-3.5ZM12.5 10.5v3M11 12h3"/></svg><span class="asta-model-picker-dots" aria-hidden="true"><span data-on></span><span data-on></span><span></span><span></span><span></span></span><span class="asta-sr-only">Intelligence 2 of 5</span></span></span> <span class="asta-model-picker-context">32K</span> <svg class="asta-model-picker-check" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m3.5 8.5 3 3 6-7"/></svg> </div> </div> <div class="asta-model-picker-empty" data-asta-model-empty hidden><b>No models found</b><span>Nothing matches “<span data-asta-model-query></span>”. Try a family name.</span></div> </div> </div></div> <button type="submit" class="asta-prompt-send" aria-label="Send message"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 13V3M3.5 7.5 8 3l4.5 4.5"/></svg></button><button type="button" class="asta-prompt-stop" aria-label="Stop the agent" data-asta-prompt-stop>Stop</button></div> </form> <p id="pc2-note" class="asta-prompt-note" role="status" data-asta-prompt-note>Astabyte is working. Press Esc or Stop to end the run.</p> </div> </div>
Usage
The demo above, as code.
"use client";
import { useEffect, useRef, useState } from "react";
import { ModelPicker, type ModelOption } from "@/components/astabyte/model-picker";
import { PromptComposer, type ComposerCommand, type ComposerMention, type ComposerMessage } from "@/components/astabyte/prompt-composer";
const MENTIONS: ComposerMention[] = [
{ id: "f1", type: "file", label: "pricing-v3.fig", hint: "Design" },
{ id: "f2", type: "file", label: "q3-revenue.csv", hint: "Finance" },
{ id: "f3", type: "file", label: "signup-form.tsx", hint: "app/onboarding" },
{ id: "p1", type: "person", label: "Rani Wijaya", hint: "Design lead" },
{ id: "p2", type: "person", label: "Theo Marsh", hint: "Engineering" },
{ id: "p3", type: "person", label: "Maya Sato", hint: "Support" },
{ id: "d1", type: "doc", label: "Launch plan", hint: "Edited 2d ago" },
{ id: "d2", type: "doc", label: "Pricing FAQ", hint: "Help center" },
];
const COMMANDS: ComposerCommand[] = [
{ id: "summarize", label: "summarize", hint: "A short summary" },
{ id: "draft", label: "draft", hint: "Write a first version" },
{ id: "review", label: "review", hint: "Find problems" },
{ id: "plan", label: "plan", hint: "List steps first" },
{ id: "translate", label: "translate", hint: "Into another language" },
];
const MODELS: ModelOption[] = [
{ value: "astra-2-pro", label: "Astra 2 Pro", group: "Astra 2", hint: "Deep reasoning for hard tasks", speed: 2, intelligence: 5, context: "1M", isNew: true },
{ value: "astra-2", label: "Astra 2", group: "Astra 2", hint: "Balanced for everyday work", speed: 4, intelligence: 4, context: "400K" },
{ value: "astra-fast", label: "Astra Fast", group: "Realtime", hint: "Lowest latency", speed: 5, intelligence: 2, context: "32K" },
];
export default function PromptComposerDemo() {
const [model, setModel] = useState("astra-2");
const [running, setRunning] = useState(false);
const [sent, setSent] = useState<ComposerMessage | null>(null);
const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
useEffect(() => () => clearTimeout(timer.current), []);
// Pretend the agent works for a few seconds.
const send = (msg: ComposerMessage) => {
setSent(msg);
setRunning(true);
clearTimeout(timer.current);
timer.current = setTimeout(() => setRunning(false), 4500);
};
const stop = () => {
clearTimeout(timer.current);
setRunning(false);
};
return (
<div className="flex min-h-[460px] w-full flex-col items-center justify-end gap-6 p-4 pb-8 sm:p-10">
<div className="flex w-full max-w-[640px] flex-1 flex-col justify-end">
{sent ? (
<div className="ml-auto max-w-[85%] rounded-xl bg-paper-2 px-3.5 py-2.5 text-[14px] leading-relaxed text-ink">
{sent.parts.map((p, i) =>
p.type === "text" ? (
<span key={i} className="whitespace-pre-wrap">
{p.text}
</span>
) : (
<span key={i} className={p.type === "command" ? "rounded-[5px] bg-ink px-1.5 font-medium text-paper" : "rounded-[5px] bg-brand/10 px-1.5 font-medium text-brand"}>
{p.type === "command" ? `/${p.item.label}` : p.item.label}
</span>
),
)}
{sent.files.length > 0 && <p className="mt-1 text-[12px] text-mute">{sent.files.map((f) => f.name).join(", ")}</p>}
</div>
) : (
<p className="text-center text-[13px] text-mute">Type @ to mention a file, person or doc, or / for a command.</p>
)}
</div>
<div className="w-full max-w-[640px]">
<PromptComposer
mentions={MENTIONS}
commands={COMMANDS}
running={running}
onSend={send}
onStop={stop}
model={<ModelPicker variant="chip" side="top" models={MODELS} value={model} onChange={setModel} />}
/>
</div>
</div>
);
}