Intelligent UI
@adecore/intelligent-ui lets an agent answer with a block of components instead of prose: a summary, a table, a checklist, next steps to pick from. The package defines the catalog, compiles blocks out of a streaming reply and evaluates them in a bounded interpreter. It has no framework and no DOM, depends only on zod, and runs in Bun, Node and a browser. A renderer draws the result.
$selected = ["links"]
<Summary tone="warning" badge="2 findings">The review found two problems</Summary>
<Checklist value={$selected}>
<Item value="links"><File path="src/terminal/links.ts" line={148}>Cuts a path at a space</File></Item>
<Item value="preload"><File path="src/preload.ts" line={62}>Bridge method not optional</File></Item>
</Checklist>
<Choices>
<Choice primary={true} context={"Fix these findings: " + @Join($selected)}>Fix {@Count($selected)}</Choice>
<Choice>Leave it</Choice>
</Choices>The agent writes this in a fenced code block. The chat timeline draws it:
import { useState } from 'react';
import { bound, ui } from '../shared/intelligent-ui-tree.ts';
import { DemoBlock } from '../shared/intelligent-ui.tsx';
export default function IntelligentUiDemo() {
const [selected, setSelected] = useState<unknown[]>(['links', 'preload']);
return (
<DemoBlock
nodes={[
ui('Summary', { tone: 'danger', badge: '2 blocking' }, `${selected.length} of 2 findings selected`),
bound(
ui(
'Checklist',
{},
ui('Item', { value: 'links' }, ui('File', { path: 'src/terminal/links.ts', line: 148 }, 'Cuts a path at a space')),
ui('Item', { value: 'preload' }, ui('File', { path: 'src/preload.ts', line: 62 }, 'Bridge method not optional'))
),
selected,
(next) => setSelected(next as unknown[])
),
ui(
'Stats',
{},
ui('Stat', { label: 'Cold start', value: 1.42, previous: 1.9, unit: 's', tone: 'success' }),
ui('Stat', { label: 'First chunk', value: 812, previous: 790, unit: 'kB' })
),
ui(
'Choices',
{},
ui('Choice', { context: `Fix these findings: ${selected.join(', ')}`, primary: true }, `Fix ${selected.length}`),
ui('Choice', {}, 'Leave it')
)
]}
context={{ link: () => ({ state: 'chip' }), openLink: () => undefined }}
/>
);
}What it does
- Shows status, numbers, records and charts from the catalog.
- Keeps local state: a checklist, a switch, a slider, a segmented control and buttons that set or reset values.
- Computes text and props with a small expression language: arithmetic, comparisons,
@Count,@Filter,@Sum,@Joinand@Round. - Reads live data from a source the host registered.
- Names a file, a diff, a commit or a node, which the host turns into a link.
- Offers follow-ups after finished work with Choices. A question the turn waits on goes through the agent's question tool or prose.
A block cannot run code, fetch an address, style anything or act outside itself; see the security model.
How a block travels
- The host tells the agent the language with
uiSessionNote. - The agent writes a fenced
uiblock in its reply. - The backend compiles the reply while it streams and stores the final blocks on the assistant item.
- The page evaluates each block against its local state and draws the nodes.
- A person changes inputs in the block. Nothing leaves the block until they pick a Choice, which sends one message back.
- Live data and links go through the host, which checks every read and every target.
What it leaves to the app
The package draws nothing and reads nothing. The app tells the agent the language, stores the compiled blocks, and decides what a block may reach: which sources a live query reads, which targets a link opens, and what a Choice sends. @adecore/agents compiles the blocks in a chat session, and @adecore/agents-react draws them.
Where to next
- Getting started wires blocks end to end: the note, the compiler, the wire and the page.
- Security model covers what a block can and cannot do.
- Syntax, Expressions and State and inputs cover the language.
- Status, Data, Structure, Content, Places, Host links, Inputs and Choices cover the catalog.
- Live queries, Choices, Links and Compilation and streaming cover the host's side.
- Reference lists every export of every entry point.
The package is licensed under FSL-1.1-MIT.