Skip to content

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.

ui
$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:

tsx
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, @Join and @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 ​

  1. The host tells the agent the language with uiSessionNote.
  2. The agent writes a fenced ui block in its reply.
  3. The backend compiles the reply while it streams and stores the final blocks on the assistant item.
  4. The page evaluates each block against its local state and draws the nodes.
  5. A person changes inputs in the block. Nothing leaves the block until they pick a Choice, which sends one message back.
  6. 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 ​

The package is licensed under FSL-1.1-MIT.

Licenses and third-party notices are listed in each package.