Composer and Slash Menu
Part of the drop-in UI blocks: headless rules in @reactive-agents/ui-core, thin Svelte 5 components in @reactive-agents/svelte/components, sharing @reactive-agents/svelte/styles.css, the --ra-* variables and the icons registry. The same blocks ship for React and Vue.
Composer and slash menu
Section titled “Composer and slash menu”Composer is a chat input: a textarea, a send button that turns into queue or stop during a run, a strip for the message queued behind the run, an optional slash menu, file drop and paste, and a highlight layer. SlashMenu is the keyboard-driven listbox above it. Neither makes a request or owns app state; createComposer from ui-core holds the rules.
Headless rules (ui-core)
Section titled “Headless rules (ui-core)”| Rule | What it gives you |
|---|---|
createSlashRegistry(commands) |
Binds a command list to parse, match, resolve and find |
parseSlash(input) |
{ query, arg, hasArg } for a single line that starts with / and a word of letters and dashes; otherwise null, so /usr/bin/env is an ordinary message |
matchCommands(commands, query) |
Commands for the typed word: exact name, then prefix, then substring, each in list order |
resolveCommand, choiceMatches |
The command a parsed input names; a case-insensitive “does any part contain the query” test for picker rows |
commandWantsArg(command), commandInsertText(command) |
True when the command has a picker or an argument hint starting with < or "; the text a menu pick puts in the input (/name, plus a space when it waits for an argument) |
composerKeyAction(event, { menuOpen, enterSends?, hasQueued }) |
One decision per key: ignore (IME composing), menu-move, menu-pick (via "tab" or "enter"), menu-close, clear-queued, submit or none. composerKeyHandled(action) says whether to call preventDefault |
queueMessage(queued, text), queuePreview(queued, max?) |
Park a message typed during a run (a second one is appended on a new line); one line for the queued strip |
queuedAfterRun({ wasSending, sending, queued, aborted }), lastRunFailed(turns) |
send only when the run ended normally; stop or failure keeps the message queued. lastRunFailed catches a run that ended with success: false and no stream error |
composerAction({ sending, hasText, configCommand? }) |
What the send button does: send, queue or stop |
replaceDraft(current, next, chipCmd?), restoreDraft(current, stash) |
Put text in the input without silently losing a draft; returns the new text and the displaced draft for a Restore action |
mentionTrigger(text, caret, marker?), removeMention |
The partial @query (or #query) at the caret that opens a picker; [email protected] is not a trigger |
SlashMenuItem, keepsMenuOpen, moveMenuIndex, clampMenuIndex, startsGroup, menuRowIcon, menuOptionId, menuFooterHint |
Menu rows and their small rules (wrapping highlight, group titles, check icons, the aria-activedescendant row id) |
A SlashCommand is { name, summary, icon?, arg?, needsTurns?, picker? }. A SlashMenuItem is { key, icon, label, run, hint?, detail?, active?, badge?, multi?, group?, disabled?, complete? }.
createComposer
Section titled “createComposer”createComposer({ commands, onSend, onCommand?, onStop?, onUnknownCommand?, runsDuringRun?, menuItems?, initialText? }) returns a framework-free controller. commands is a list or a registry; with none there is no slash menu.
- State:
getState()returns{ text, caret, sending, queued, menuIndex, menuDismissed };subscribe(fn)follows the store contract. - Input:
setText(text, caret?),setCaret,keydown(event)(returns{ action, handled }and has already done the work),submit(),stop(),sendAction(). - Run lifecycle:
setSending(true)when a run starts,setSending(false)when it ends. PasssetSending(false, true)when the run was stopped or failed. A message typed during a run is queued and sent when it ends normally;sendQueuedNow()andclearQueued()act on it. A command named byrunsDuringRunruns at once instead of queueing. - Menu:
menu()returns{ open, items, index, slash };hover(i),choose(i)anddismissMenu()drive it. By default the rows are the matching commands, and choosing one runs it or completes it when it waits for an argument.menuItems(ctx)replaces the rows, for a second-level picker such as/model <partial>.
Drop-in mode
Section titled “Drop-in mode”<script lang="ts"> import "@reactive-agents/svelte/styles.css"; import { createComposer, type SlashCommand } from "@reactive-agents/ui-core"; import { Composer } from "@reactive-agents/svelte/components";
const commands: SlashCommand[] = [ { name: "clear", summary: "Start a new chat" }, { name: "model", summary: "Switch model", arg: "<name>" }, ];
let running = $state(false);
const composer = createComposer({ commands, onSend: (text) => startRun(text), onCommand: (command, arg) => runCommand(command.name, arg), onStop: () => stopRun(), });
// Tell the controller when a run starts and ends. $effect(() => composer.setSending(running));</script>
<Composer {composer} />startRun, runCommand and stopRun are your own functions. When a run is stopped or fails, call composer.setSending(false, true) so the queued message stays queued instead of going out.
Controlled mode
Section titled “Controlled mode”Keep the state yourself when the app already has it. Bind value, pass sending, queued and (with a menu) menuOpen, menuIndex and menuItems, and handle the callbacks.
<script lang="ts"> import { queueMessage } from "@reactive-agents/ui-core"; import { Composer } from "@reactive-agents/svelte/components";
let value = $state(""); let sending = $state(false); let queued = $state<string | null>(null);
function onSubmit() { const text = value.trim(); if (text === "") return; value = ""; if (sending) queued = queueMessage(queued, text); else startRun(text); }</script>
<Composer bind:value {sending} {queued} {onSubmit} onStop={() => stopRun()} onClearQueued={() => (queued = null)} onSendQueuedNow={() => { if (queued !== null) startRun(queued); queued = null; }}/>With a menu in controlled mode, also pass onMenuMove(delta), onMenuPick(via), onMenuClose(), onMenuHover(index) and onMenuDismiss(); Enter sends even with the menu open when enterSends is true. Without menuItems you can render a SlashMenu yourself and pass its menuId so the input’s aria-activedescendant points at the right row.
Composer
Section titled “Composer”- Props:
composer(drop-in),valueandcaret(bindable),inputEl(bindable textarea),sending,queued,sendAction,busyandbusyText(a stop in flight: the send button is inert),sendLabel,menuOpen,menuIndex,enterSends,menuItems,menuHeader(a Back row),menuId,menuKeepSelector,highlights(pieces{ text, mark }drawn behind the text; they must concatenate tovalue),describedBy,commandHint,onFiles(files dropped or pasted),onShortcut(runs first on every key; returntrueto claim it),tooltipEnabled,labels,rows(default 3),icons,class(wrapper),boxClass. Other attributes pass to the box. - Snippets:
leading(top of the box),attachments,banner,belowField,footerStart,hint(replaces the key hints),actions(before the send button),trailing(after it) andemptyMenu(shown in the menu when it has no rows). labelstakes any subset ofComposerLabels(every visible string:input,placeholder,send,queue,stop,queuedPrefix,sendNow,clear,menuand so on).DEFAULT_COMPOSER_LABELSholds the English defaults.- The send button reads
send,queueorstopfromsendAction(). While the menu is open the textarea setsaria-controlsandaria-activedescendantto the highlighted row. - Hooks:
data-ra-composer,data-ra-composer-box,data-ra-composer-input,data-ra-send(withdata-actionset tosend,queueorstop),data-ra-queued, anddata-ra-menu-keep(a press on an element with it never counts as outside the menu).
SlashMenu
Section titled “SlashMenu”Rendered by Composer when a menu is open; use it directly for your own layout. The host owns keyboard state: the textarea keeps focus and the rows are never focusable.
- Props:
items,selected,onHover(index),onDismiss()(a press outside the list),header({ title, alias, onBack }, a Back row),id(base of the row ids; defaultra-slash-menu),label,backLabel,badgeLabel,footer(text, orfalseto hide the key hints),keepSelector(default[data-ra-menu-keep]),icons,class. - Snippets:
row(item, { index, selected })replaces a row’s content;emptyshows when there are no rows. - Row fields:
multi(a check box row that toggles in place and keeps the menu open),group(a title above the first row of a run),disabled(a reason string; the row shows it as unavailable),badge,hint,detail,active, andrunandcomplete(Tab). - Each row has the id
menuOptionId(id, index), which the input’saria-activedescendantpoints at. - Hooks:
data-ra-slash-menu,data-ra-menu-row,data-selected,data-active,data-disabled.
Composer tokens: --ra-composer-width (widest the box and menu grow, default 48rem), --ra-radius-panel (10px), --ra-z-menu (30), --ra-text-md (input text, 15px), --ra-text-2xs (key hints, 11px) and --ra-lh-read (input line height, 1.6), on top of the surface, border, accent and focus tokens already in styles.css.
What’s Next
Section titled “What’s Next”- Drop-in UI blocks overview: the other block pages
- Agentic UI Core: the protocol, run state and the other Svelte blocks
- Web Integration: React, Vue and Svelte bindings
Install
Bun (recommended)bun add reactive-agentsNode 22.5+npm install reactive-agentsGet notified on new releases
Release notes, about once a month.