AI Chat Components
Components built for AI chat scenarios: message bubbles, reasoning chains, tool calls, agent status, plans and test results, cited sources, code diffs, terminals, file trees, artifacts, and more. Each example shows the formatted, highlighted TokUI DSL on the left and the live render on the right; click "Edit" to tweak it instantly.
Reasoning Block think
A collapsible reasoning-process container, closed by [/think]. open expands by default, tt sets the title.
| Prop | Meaning | Example |
|---|---|---|
tt | Title | tt:思考过程 |
open | Expanded by default | open |
Reasoning Chain think-chain / think-step
A step-by-step reasoning container. think-chain sets the overall title; each think-step shows its status, title, and duration.
| Prop | Meaning | Applies to |
|---|---|---|
tt | Overall title | think-chain |
status | Step status (pending/running/done/error) | think-step |
tt | Step title | think-step |
dur | Duration | think-step |
Chat Bubble bubble
A chat message container. role aligns the bubble left/right; model and time appear in the meta row.
| Prop | Meaning | Example |
|---|---|---|
role | Role (user / ai) | role:ai |
model | Model name (AI side) | model:GLM-5.2 |
time | Time text | time:刚刚 |
The bubble avatar and header names (
bubble.you/bubble.ai/bubble.system/bubble.assistant) live in the i18n dictionary —setLocale+rerender()switches their language in place (see i18n).
Toolbar toolbar
A horizontal action bar, usually placed at the top or bottom of a bubble.
| Prop | Meaning | Example |
|---|---|---|
pos | Position | pos:bottom |
align | Alignment | align:right |
Tool Call tool-call
A tool/function-call card showing the name, status, and duration. Status is color-coded: pending/running/done/error/denied.
| Prop | Meaning | Example |
|---|---|---|
name | Tool name | name:web_search |
status | Status | status:done |
duration | Duration | duration:1.2s |
id | Identifier (updatable via upd) | id:tc1 |
approval | Human-approval mode (HITL, paired with status:pending) | approval |
clk | Approval-decision handler | clk:onApproval |
HITL human approval: with approval plus status:pending, the card renders Approve / Reject buttons. The user's decision is reported back through the clk: handler (or on:"approval:h") as {approved, id, name}; once decided, the buttons are disabled and the follow-up status is pushed by the server via upd.
[tool-call id:tc1 name:delete_file approval status:pending clk:onApproval][p About to delete ./tmp/cache — needs human confirmation.[/tool-call]
;; after the user clicks, onApproval receives {approved:true/false, id:"tc1", name:"delete_file"}
;; the server then pushes the follow-up status:
[upd id:tc1 status:running]
[upd id:tc1 status:done duration:0.8s]Typing Indicator typing
A "typing" three-dot animation, self-closing. text shows text alongside it.
| Prop | Meaning | Example |
|---|---|---|
text | Hint text | text:思考中 |
Quick Reply quick-reply
A one-line quick-reply suggestion, self-closing container. items separates multiple suggestions with |.
| Prop | Meaning | Example |
|---|---|---|
items | Suggestion list (` | `-separated) |
clk | Click handler (payload {value: label}) | clk:onPick |
Click reporting: once
on:"select:h"is declared, clicking a suggestion reports{value: label}.
Suggestion Cards suggestions / suggestion
A grid suggestion container; child suggestion nodes show title, description, and icon. cols on suggestions controls the column count.
| Prop | Meaning | Applies to |
|---|---|---|
cols | Column count | suggestions |
clk | Unified click handler | suggestions |
tt | Title | suggestion |
tx | Description | suggestion |
icon | Icon | suggestion |
clk | Click handler | suggestion |
dis | Disabled | suggestion |
Select reporting: once
on:"select:h"is declared, clicking a suggestion card reports{value: title}.
Cited Source source
A cited retrieval source / reference, self-closing. Typically listed as numbered [1] [2] citations under a "web search" answer.
| Prop | Meaning | Example |
|---|---|---|
n | Index | n:1 |
tt | Title (quote if it has spaces) | tt:"TokUI 官方文档" |
sn | Snippet excerpt (quote if it has spaces) | sn:"零依赖流式 UI…" |
u / url | Link | u:https://tokui.jboltai.com |
tt/snvalues containing spaces must be double-quoted, otherwise they get truncated at the first space.
Code Diff diff
A code-diff container with line numbers and red/green coloring. +/- lines are colored; other lines are context. Raw content mode: inner [ is treated as literal text until [/diff].
| Prop | Meaning | Example |
|---|---|---|
title | Title | title:修复登录校验 |
lang | Language tag | lang:js |
Use
\nfor line breaks: lines starting with+are additions (green),-are deletions (red), and the rest are context lines (gray).
Execution Plan plan / plan-step
A task-plan checklist container. plan sets the title; each plan-step is one step, color-coded by status.
| Prop | Meaning | Applies to |
|---|---|---|
tt | Plan title | plan |
status | Step status (pending/running/done/error/skipped) | plan-step |
tt | Step title | plan-step |
desc | Step description | plan-step |
Agent Status agent
An agent-collaboration card showing name, status, current action, and duration; supports streaming status updates.
| Prop | Meaning | Example |
|---|---|---|
name | Name | name:资料研究员 |
status | Status (idle/running/paused/done/error) | status:running |
action | Current action | action:正在检索文档 |
duration | Duration | duration:8s |
id | Identifier (status updatable via upd) | id:agent1 |
File Tree file-tree / ft-folder / ft-file
A file-tree container with ft-folder children (nestable) and ft-file leaves.
| Prop | Meaning | Applies to |
|---|---|---|
name | Name | both |
open | Expanded by default | ft-folder |
badge | Badge (e.g. M modified / A added / D deleted) | ft-file |
Terminal terminal
A container for terminal commands and output. title is the window title; status is the execution result status. A copy button is built into the right side of the title bar (Copy → Copied). Raw content mode: inner [ is treated as literal text.
| Prop | Meaning | Example |
|---|---|---|
title | Window title | title:bash |
status | Execution status | status:success |
Code Sandbox sandbox
A code-sandbox container with live preview that can execute HTML/CSS/JS. Raw content mode: inner [ is treated as literal text, closed by [/sandbox].
| Prop | Meaning | Example |
|---|---|---|
lang | Language | lang:html |
title | Title | title:实时预览 |
height | Preview height | height:160 |
Test Results test-result / test-case (shorthand case)
A test-run summary container; child test-case nodes (shorthand case, equivalent) list each individual case (pass green / fail red + error / skip gray).
| Prop | Meaning | Applies to | Example |
|---|---|---|---|
pass / fail / skip | Pass / fail / skip counts | test-result | pass:3 fail:1 |
total | Total count | test-result | total:5 |
duration | Total duration | test-result | duration:"2.4s" |
status | Case status (pass/fail/skip) | test-case / case | status:fail |
name | Case name (quote if it has spaces) | test-case / case | name:"parser: basic tags" |
duration | Single-case duration | test-case / case | duration:"0.12s" |
error | Error message (on fail; quote if spaces/brackets) | test-case / case | error:"Expected [/card]" |
name/errorcontaining spaces or[]must be double-quoted, otherwise they get truncated or misparsed.
Git Commit commit
A git-commit info card, self-closing.
| Prop | Meaning | Example |
|---|---|---|
hash | Commit hash (first 7 chars) | hash:abc1234 |
msg | Commit message (quote if it has spaces) | msg:"fix: login validation" |
author | Author | author:sdxiaomu |
branch | Branch | branch:master |
time | Time (quote if it has spaces) | time:"2 hours ago" |
additions / deletions | Added / deleted lines | additions:12 deletions:5 |
Values with spaces (e.g.
msg,time) must be double-quoted, otherwise they get truncated at the first space (msg:fix login bugyields onlyfix).
Message Quote quote
A container that quotes a historical message: role for the source role, tx for the quoted text, msgid for the original message identifier.
| Prop | Meaning | Example |
|---|---|---|
role | Source role | role:user |
tx | Quoted text | tx:之前的提问 |
msgid | Original message ID | msgid:m1 |
Latency Marker latency
A model-response latency / throughput indicator, self-closing. v is the value; t is the type (e.g. ttfb for time-to-first-byte, tok/s for tokens per second).
| Prop | Meaning | Example |
|---|---|---|
v | Value | v:320ms |
t | Type label | t:ttfb |
Video video / Audio audio
Media players; both are self-closing.
| Prop | Meaning | Applies to | Example |
|---|---|---|---|
s | Media URL | both | s:https://.../mov.mp4 |
poster | Cover image (shares the player's ratio box — same size & ratio) | video | poster:https://.../pic.jpg |
ratio | Aspect ratio; fills the box when set | video | ratio:"16:9" / "4:3" / "1:1" / "21:9" |
w | Width (plain number → px, otherwise literal %/rem) | both | w:"320" / w:"50%" |
h | Height (overrides ratio) | video | h:"180" |
fit | Fill: cover (crop, default when sized) / contain (letterbox, default when unsized) / fill | video | fit:contain |
tt | Title (left-aligned) | audio | tt:Demo audio |
duration | Duration (right-aligned) | audio | duration:0:48 |
Cover & ratio:
posteris the<video>'s first frame. Settingratio+fitmakes the cover and the playback share one ratio box — same size, same ratio, no distortion. For a side-by-side row, wrap withrow+col span:6.
[video s:https://assets.vdata.chat/jboltai/mov_bbb.mp4 poster:https://picsum.photos/seed/p/640/360 ratio:"16:9"]
[video s:https://assets.vdata.chat/jboltai/mov_bbb.mp4 ratio:"1:1" w:"320" h:"320" fit:cover]
[audio s:https://assets.vdata.chat/jboltai/horse.mp3 tt:Demo duration:0:48]
[row][col span:6][video s:https://assets.vdata.chat/jboltai/mov_bbb.mp4 ratio:"16:9"][/col][col span:6][video s:https://assets.vdata.chat/jboltai/mov_bbb.mp4 ratio:"16:9"][/col][/row]Conversation List conversations / conv
A sidebar conversation-history container; child conv nodes are individual conversations.
| Prop | Meaning | Applies to | Example |
|---|---|---|---|
clk | Unified switch handler | conversations | clk:onSwitch |
act | Action endpoint | conversations | act:conv-1 |
tt | Conversation title (quote if spaces) | conv | tt:"How to use SSE" |
time | Time (quote if spaces) | conv | time:"today 14:20" |
active | Currently selected | conv | active |
act | Single-item action | conv | act:conv-2 |
tt/timewith spaces must be double-quoted, otherwise truncated at the first space. Whenclkfires, the handler's first argument is{ tt, time, act }(attribute snapshot of the selected conversation); works in streaming mode too.
Welcome Screen welcome / welcome-feature (shorthand feature)
A new-session welcome-screen container; child welcome-feature nodes (shorthand feature, self-closing, equivalent) are feature cards.
| Prop | Meaning | Applies to | Example |
|---|---|---|---|
tt | Title | welcome | tt:"Hi, I'm the assistant" |
st | Subtitle | welcome | st:"How can I help?" |
tt | Card title | welcome-feature / feature | tt:Write code |
tx | Card description | welcome-feature / feature | tx:"Generate & debug code" |
i | Icon (code / chart / doc) | welcome-feature / feature | i:chart |
clk | Click handler | welcome-feature / feature | clk:onPick |
[feature tt:x tx:y i:code]is self-closing (recommended);[welcome-feature ...][/welcome-feature]is the container form — equivalent. Cards are attr-driven and render as each tag arrives (true streaming).
Attachments attachments / attach
An attachment-upload / list container; child attach nodes are individual attachment items. The t on attach decides the file-type icon color.
| Prop | Meaning | Applies to |
|---|---|---|
clk | Delete / click handler | attachments |
t | File type (image/pdf/word/excel/ppt/zip/code/video/audio) | attach |
s | File name | attach |
u | Download URL | attach |
size | Size | attach |
clk | Click handler | attach |
Artifact artifact / artifact-code / artifact-preview
A side-preview Artifact container: use artifact-code for the code slot and artifact-preview for the live-preview slot inside.
| Prop | Meaning | Applies to |
|---|---|---|
tt | Title | artifact |
lang | Language | artifact |
pos | Panel position | artifact |
w | Panel width | artifact |
Chat Input chat-input
A chat-input container with a send button. auto enables auto-growing height, rows sets the default row count, and max is the max character count.
| Prop | Meaning | Example |
|---|---|---|
ph | Placeholder | ph:输入消息… |
clk | Send handler | clk:onSend |
dis | Disabled | dis |
auto | Auto-grow height | auto |
rows | Default rows | rows:3 |
max | Max characters | max:2000 |
streaming | Generating state: show the stop button (mutually exclusive with send) | streaming |
on | Event reporting declaration | on:"stop:onStop" |
mention | @-mention data-source handler | mention:onMention |
Send reporting: Enter / the send button triggers the clk handler (payload {value}) and also reports a send event (detail {value}) through on:"send:h" and the unified outlet.
@ mentions: mention:data-source-handler enables the @-mention dropdown — typing @ triggers it; the data source fn({value: query}) returns an array or a Promise (items are strings or {v, tx}); ↑↓ navigates, Enter selects, Esc closes (keys take precedence over sending). Selecting inserts @label and reports the mention event {value, name}.
Stop generating: adding the streaming boolean prop swaps the send button for a "stop generating" button (the two are mutually exclusive). Clicking it fires the on:"stop:h" report (detail {}); when no on is declared, the default behavior is to disconnect the SSE connection of the TokUI instance that owns this component (disconnect(), idempotent and safe — on multi-instance pages it won't stop other instances), and the input immediately returns to the send state (optimistic UI — if the stream hasn't actually stopped, the server can restore it with upd streaming:true). When generation finishes, the server pushes [upd id:x streaming:false] to restore the send button; streaming:true re-enters the generating state.
[chat-input id:ci ph:"Type a message…" clk:onSend streaming on:"stop:onStop"][/chat-input]
[upd id:ci streaming:false] ;; generation finished, restore the send buttonMessage Actions msg-actions
A message-action bar container at the bottom of a bubble; supports copy / regenerate / like-dislike toggles.
| Prop | Meaning | Example |
|---|---|---|
clk | Generic handler | clk:onAct |
copy | Show copy | copy |
regenerate | Show regenerate | regenerate |
like / dislike | Like / dislike | like |
visible | Always visible (default: hover) | visible |
Thumbs thumb
A like / dislike button, self-closing. t decides the variant.
| Prop | Meaning | Example |
|---|---|---|
t | Type (up / down) | t:up |
clk | Click handler | clk:onLike |
v | State / value | v:12 |
When
clkfires, the handler's first argument is{ direction: 'up' | 'down', active: boolean }(active state toggles on click).
Comprehensive Example: A Real AI Reply
Combining bubble, reasoning chain, tool call, cited sources, markdown, and an action bar into a realistic AI reply.
Tip: handlers referenced by
clk:/sub:must be pre-registered viaTokUI.registerHandler(name, fn); the DSL itself carries no executable code. For the full prop tables, see sections 6.3–6.4 of the DSL syntax reference.