Fine-tune light, shadows, borders, neumorphic
Light and shadows
Borders
Neumorphic

AI responses

Let the model in your product answer with interface instead of a wall of text: numbers as stats, results as tables and charts, next steps as buttons, questions as forms. All of it in your theme, and safe to draw while it streams.

What the model writes

Sales were **$48,210** last week, up 12% on the week before.

```ui
{"type": "grid", "children": [{"type": "stat", "label": "Revenue", "value": "$48,210", "delta": "+12%", "trend": "up"}, {"type": "stat", "label": "Orders", "value": "1,284", "delta": "+8%", "trend": "up"}, {"type": "stat", "label": "Refunds", "value": "1.9%", "delta": "+0.2%", "trend": "down"}]}
```

Most of the growth came from two countries:

```ui
{"type": "chart", "kind": "bar", "label": "Added revenue by country", "labels": ["Germany", "Brazil", "France", "Japan"], "values": [2140, 1310, 620, 410], "valuePrefix": "$", "height": 200}
```

```ui
{"type": "table", "label": "Top products", "columns": [{"key": "product", "label": "Product"}, {"key": "sold", "label": "Sold", "type": "number", "align": "end"}, {"key": "status", "label": "Stock", "type": "badge", "tones": {"Low": "warning", "OK": "success"}}], "rows": [{"product": "Field backpack", "sold": 412, "status": "Low"}, {"product": "Travel pouch set", "sold": 388, "status": "OK"}, {"product": "Leather luggage tag", "sold": 251, "status": "OK"}]}
```

```ui
{"type": "suggestions", "items": ["Compare the plans", "Book a demo"]}
```

What the reader sees

How did sales go last week?

Use a button, a suggestion or the form in an answer: the event it fires shows here.

How it works

  1. The model learns the components. uiPrompt() returns instructions for your system prompt: how to add components to an answer, and the list of components with their props (about 2,300 tokens).
  2. It answers in Markdown, and where a component is clearer than prose it adds a fenced block with the language ui that holds JSON.
  3. <pm-ai-response> draws it. Text becomes headings, lists, tables and code blocks; each ui block becomes Prismora elements. What the model wrote is checked first, and nothing in it ever becomes HTML.

One typed list of components (UI_CATALOG) is the source of the prompt, the JSON Schema, the check and the renderer, so they cannot disagree. This is the same idea as other typed-component formats for model output, built on the Prismora elements you already use: there is nothing to map and no second design to maintain.

Quick start

On the server, add the prompt to your system prompt and stream the model's text. This example uses the Claude API:

import Anthropic from '@anthropic-ai/sdk'; import { uiPrompt } from '@prismora/elements/ai'; const client = new Anthropic(); // Your own instructions, then how to answer with components. Declare the actions your app handles; // without any, the model is told to use neither forms nor action buttons. const system = `You are the assistant of Lumen, a shop analytics app. ${uiPrompt({ actions: [{ name: 'book_demo', about: 'Book a product demo', params: '{ name: string; time: string }' }] })}`; // POST /api/chat: the answer goes to the browser as it is written. export async function POST(request: Request) { const { messages } = await request.json(); const stream = client.messages.stream({ model: 'claude-opus-5-5', max_tokens: 64000, cache_control: { type: 'ephemeral' }, // the prompt is the same in every request system, messages, }); const encoder = new TextEncoder(); const body = new ReadableStream({ async start(controller) { for await (const event of stream) { if (event.type === 'content_block_delta' && event.delta.type === 'text_delta') controller.enqueue(encoder.encode(event.delta.text)); } controller.close(); }, }); return new Response(body, { headers: { 'content-type': 'text/plain; charset=utf-8' } }); }

In the browser, write the text into the element as it arrives:

import '@prismora/elements/ai-response'; const answer = document.querySelector('pm-ai-response'); const messages = []; async function ask(text) { messages.push({ role: 'user', content: text }); const response = await fetch('/api/chat', { method: 'POST', body: JSON.stringify({ messages }) }); const reader = response.body.pipeThrough(new TextDecoderStream()).getReader(); answer.value = ''; answer.streaming = true; for (;;) { const { value, done } = await reader.read(); if (done) break; answer.write(value); // redraws only what changed } answer.streaming = false; messages.push({ role: 'assistant', content: answer.value }); } // A button with an action, a suggestion or a sent form. Nothing happens unless you do it here. answer.addEventListener('pm-action', (event) => { const { action, params, values, text } = event.detail; if (action === 'book_demo') bookDemo(values); // your own code ask(text); // and the model hears about it }); <pm-chat label="Conversation"> <pm-chat-message from="me" name="You">How did sales go last week?</pm-chat-message> <pm-chat-message from="them" name="Assistant" variant="plain"> <pm-ai-response></pm-ai-response> </pm-chat-message> </pm-chat> <pm-composer label="Ask the assistant"></pm-composer>

The prompt is plain text. With OpenAI, Gemini or a model you host, put uiPrompt() into the system (or developer) instruction the same way, and write the text you receive into the element. Nothing here depends on one provider.

The format

Sales were **$48,210** last week, up 12%. ```ui {"type":"grid","children":[ {"type":"stat","label":"Revenue","value":"$48,210","delta":"+12%","trend":"up"}, {"type":"stat","label":"Orders","value":"1,284","delta":"+8%","trend":"up"} ]} ``` - Orders rose from 1,188 to 1,284. - The **Business** plan made up 61% of revenue.
  • A ui block holds one component or an array of them. A component is an object with type and that type's props; containers take children, an array of components and strings.
  • Strings in children and props of the kind text may use inline Markdown.
  • The Markdown around it is the Markdown models write anyway: headings, lists and task lists, tables, quotes, notes (> [!WARNING]), code fences, links and emphasis.
  • The fence may also be named prismora or pm-ui.

Components

Props marked ? are optional. The full kinds and choices are in the prompt (uiPrompt()) and in the schema (uiSchema()).

TypeWhat it isProps
stackChildren one under another.gap?children
rowChildren side by side, wrapping when there is no room. For buttons, badges and short items.gap?align?children
gridChildren in equal columns that fold to fewer on narrow screens. For stats and cards to compare.min?children
cardA bordered container with an optional heading. Groups one result, option or summary.heading?description?children
tabsAlternative views of the same thing, one visible at a time. Children are `tab`.label?children
tabOne view of `tabs`.Inside tabs.labelchildren
accordionSections that open and close, for details most readers skip. Children are `section`.single?children
sectionOne section of `accordion`.Inside accordion.headingopen?children
dividerA line between two parts.
headingA heading inside a component.textlevel?
textA paragraph inside a component.textsize?muted?
markdownMarkdown inside a component: lists, tables, code.text
badgeA short label for a state or category.texttone?variant?
statusA coloured dot with a label: online, failing, pending.texttone?pulse?
alertA highlighted note: a warning, a tip, an error, a success.tone?heading?text?children
codeSource code with highlighting and a copy button.codelanguage?label?
statOne key number with its label and change.labelvaluedelta?trend?description?icon?
tableRows and columns of data. Prefer it to a Markdown table when values need formatting or sorting.labelcolumnsrowsstriped?
chartA bar, line, area or donut chart. For trends and comparisons of numbers.kindlabellabelsseries?values?stacked?height?valuePrefix?valueSuffix?
progressHow far something has come.labelvaluemax?showValue?variant?
ratingA star rating. With `name` inside a form it is an input.labelvalue?max?name?
detailsLabel and value pairs: the facts of one thing (an order, a person, a booking).itemslayout?columns?
listA list of items with a heading, a description and an optional link or action each.labelitemsdivided?
stepsNumbered steps of a process, with the current one marked.label?itemscurrent?orientation?
timelineEvents in time order.label?items
imageA picture with a caption.srcaltcaption?ratio?
avatarA person: picture or initials.namesrc?size?
resultThe outcome of something that was done: success, failure.statusheadingdescription?children
buttonA button. With `action` it reports back to you; with `href` it is a link.labelaction?params?href?variant?tone?size?icon?
suggestionsShort replies the reader can pick instead of typing. Put them last.items
formFields the reader fills in and sends back to you. Children are fields and text.actionparams?submit?children
inputOne line of text.Inside form.namelabelhint?required?kind?placeholder?value?
textareaSeveral lines of text.Inside form.namelabelhint?required?placeholder?value?rows?
selectOne choice from a dropdown. For more than five options.Inside form.namelabelhint?required?optionsvalue?placeholder?
choiceOne choice from a few visible options.Inside form.namelabelhint?required?optionsvalue?layout?
checkboxA yes or no the reader ticks.Inside form.namelabelhint?checked?
switchA setting that is on or off.Inside form.namelabelhint?checked?
sliderA number picked on a scale.Inside form.namelabelhint?required?min?max?step?value?unit?
dateA date, or a range of dates.Inside form.namelabelhint?required?value?min?max?range?

To give the model fewer components:

import { uiPrompt } from '@prismora/elements/ai'; // Fewer components: a shorter prompt, and nothing else is drawn even if the model writes it. uiPrompt({ types: ['stat', 'grid', 'table', 'chart', 'alert', 'suggestions'] });

Buttons, suggestions and forms

Components never do anything themselves. A button with an action, a picked suggestion and a sent form fire pm-action on the element, and your code decides. The event's detail:

FieldHolds
actionThe name of the action, one of those you declared in uiPrompt({ actions }). A suggestion reports reply.
paramsData the model attached to the button or form.
valuesA form's values by field name: text as strings, sliders and ratings as numbers, checkboxes and switches as true or false.
labelThe text of the button or suggestion.
textA sentence to send to the model as the next user message.

A form checks its required fields before it reports, and is locked once it was sent (call event.preventDefault() to keep it open). Treat action, params and values like any input from outside: the model chose them, so check them on your server before acting.

While it streams

  • Set streaming while text arrives, and assign value (or call write(chunk)) as often as you like. Only the block that changed is drawn again: a finished chart does not flicker while the next paragraph is written.
  • Containers and text appear as they arrive. A chart, a table or a stat appears once all of it is there, so readers never see half a table.
  • Unfinished Markdown is read as what it will become: an open code fence is a code block, **bol is bold.
  • The element sets aria-busy while it streams. Put it in a pm-chat-message for the announcement of a finished answer.

Safety

An answer is untrusted input: the model can be wrong, and text it read (a web page, a document, an email) can try to steer it.

  • No HTML, ever. The answer is parsed into data and drawn with createElement and text nodes. <script> or <img onerror> in an answer shows as text.
  • Only the catalogue. Unknown components and props are left out; values are checked against their kind. There is no way to set a style, a class, an event handler or an arbitrary attribute.
  • Addresses are checked. Links may be http(s), mailto, tel or paths of your site; pictures http(s) or inline PNG, JPEG, GIF and WebP. Never javascript: or data: documents. Links to other sites open in a new tab without access to yours.
  • Pictures can leak. The address of a picture is requested as soon as it is drawn, and can carry text from the conversation to another server. Set images="off", or allow only your own hosts with allowUrl, when the model reads content you do not control.
  • Limits. At most 400 components and 12 levels of nesting in one block.
  • Actions are yours. Nothing is sent or changed until your pm-action handler does it.
<pm-ai-response images="off" heading-level="2"></pm-ai-response> <script type="module"> const answer = document.querySelector('pm-ai-response'); // Decide about every link and picture yourself, after the built-in check. answer.allowUrl = (url, kind) => kind === 'link' || new URL(url, location.href).host === 'cdn.example.com'; // What was left out of the last answer, and why. console.log(answer.problems); </script>

Frameworks

The element has a wrapper in every framework package, like every other component:

import { AiResponse } from '@prismora/react'; export function Answer({ text, busy, onAsk }: { text: string; busy: boolean; onAsk: (text: string) => void }) { return <AiResponse value={text} streaming={busy} onPmAction={(event) => onAsk(event.detail.text)} />; } <script setup lang="ts"> import { AiResponse } from '@prismora/vue'; defineProps<{ text: string; busy: boolean }>(); defineEmits<{ ask: [text: string] }>(); </script> <template> <AiResponse :value="text" :streaming="busy" @pm-action="$emit('ask', $event.detail.text)" /> </template>

The elements an answer uses are loaded the first time an answer needs them, so the chat costs what its answers show. On a server, @prismora/elements/ai has no DOM: the prompt, the schema and the check run in Node, Bun, Deno and edge runtimes.

As a tool instead of a block

Where you prefer tool use (or structured output) to a fenced block, uiTool() is a tool named show_ui whose input is { ui: [...] }. Give that input to the element's ui property; it is drawn after value.

import { checkUi, uiTool } from '@prismora/elements/ai'; const { name, description, schema } = uiTool(); // show_ui, with the JSON Schema of every component const stream = client.messages.stream({ model: 'claude-opus-5-5', max_tokens: 64000, system, messages, tools: [{ name, description, input_schema: schema, eager_input_streaming: true }], }); // While it streams, `input_json_delta` events carry the tool's input in pieces (`event.delta.partial_json`). // Send them on and give the element the JSON so far: text that is still arriving is fine. // answer.ui = jsonSoFar; const message = await stream.finalMessage(); for (const block of message.content) { if (block.type !== 'tool_use' || block.name !== name) continue; // The same check the element runs. Report the problems in the tool_result, and the model corrects itself. const { problems } = checkUi(block.input); }

The fenced block is the default because it works with every model, streams with the text, and keeps text and components in the order the model wrote them.

API

From @prismora/elements/aiDoes
uiPrompt({ actions?, types? })The instructions for the model.
uiSchema(options), uiTool(options)JSON Schema of the components, and the show_ui tool that carries it.
checkUi(value, limits?)Cleans what a model wrote: { nodes, problems }.
renderMarkdown(text, options?), renderUi(ui, options?)Draw without the element; return a fragment.
watchActions(root, report)Reports the actions used inside what you drew.
parseMarkdown, parsePartial, safeUrlThe parts, for your own renderer.
UI_CATALOG, UI_TYPESThe components and their props, as data.

The element's attributes, properties and event are on the component page. For an assistant that writes your code with Prismora, see AI, MCP & CLI.

Other formats

Typed components for model output are becoming a shared idea: Google's A2UI defines a protocol of messages between an agent and a client with a component catalogue, and Vercel's json-render renders a model's JSON through a catalogue of your own components. Prismora's format is deliberately small: Markdown with JSON blocks and a fixed catalogue, which any chat model can write without an agent framework. It is not compatible with those protocols today; an adapter that draws A2UI messages with Prismora elements is on the roadmap.