向 Loop 提供一组访问量,回复里可以直接显示图表。比较几个方案时,回复可以把价格和交付周期排成表格,并提供可点的追问。需要收集偏好时,用户可以在消息里选好并提交。本文用 Intelligent UI 指这类随对话生成、可直接操作的界面,并拆解 Loop Web 和 Desktop 如何通过 OpenUI 实现它。
截图来自 Loop 的真实聊天组件,使用固定的虚构消息在浏览器中验证。可以在自己的会话里试用下面的提问,实际界面取决于模型的回复。前三个案例附有 OpenUI Lang 示例,后七个案例提供可直接粘贴的提问和浏览器验收结果。
1. 看趋势:悬停查看周三的数据
在聊天框里输入「周一到周五的访问量是 12、19、16、24、28。哪天回落了,整体趋势如何?」回复指出周三从 19 降到 16,随后回升到周五的 28。把鼠标移到周三的柱上,工具提示就会显示当天的访问量 16。
柱图的横轴标签和数值由 BarChart 和 Series 接收,悬停提示由 React 图表组件在浏览器中处理。每次移动鼠标都可以读取对应的数据点,无需发出新消息。
markdown```openui
root = Stack([BarChart(["周一", "周二", "周三", "周四", "周五"], [Series("访问量", [12, 19, 16, 24, 28])])])
```2. 比方案:从表格里选一条追问
在聊天框里输入「比较三个虚构方案。基础版 29 元、5 天交付、邮件支持;标准版 49 元、2 天交付、邮件支持;加急版 79 元、1 天交付、优先支持。」表格把价格、交付时间和支持方式排在同一行,方便逐列比较。点击下方的「只比较两天内交付的方案」,Loop 会将这句话作为一条用户消息发送。
Table([Col(...)]) 按列接收数据,各列相同位置的值组成一行。FollowUpItem 则把按钮文案交给聊天提交流程。点击会开始下一轮对话,表格仍保留在原回复中。
markdown```openui
root = Stack([comparison, followups])
comparison = Table([Col("方案", ["基础版", "标准版", "加急版"]), Col("价格", ["¥29", "¥49", "¥79"]), Col("交付", ["5 天", "2 天", "1 天"]), Col("支持", ["邮件", "邮件", "优先"])])
followups = FollowUpBlock([FollowUpItem("只比较两天内交付的方案")])
```3. 选偏好:提交每周报告设置
在聊天框里输入「让我在每周和每月之间选一个发送频率,再推荐合适的报告格式。」选中「每周」,再点「应用」。选择选项时只更新表单状态。点击后,聊天会出现一条新消息「按这个频率推荐报告格式」。
Chips 为每个选项定义稳定值和显示标签。@ToAssistant 提供用户气泡中的文字。下一轮输入还包含独立的结构化表单数据,例如字段名 frequency、字段标签「发送频率」、原始值 weekly 和显示值「每周」。因此即使按钮文案只说「这个频率」,模型也能拿到明确的选择。
markdown```openui
root = Stack([Form("report", actions, [frequency])])
actions = Buttons([Button("应用", @ToAssistant("按这个频率推荐报告格式"))])
frequency = FormControl("发送频率", Chips("frequency", "single", [weekly, monthly]))
weekly = ChipItem("weekly", "每周")
monthly = ChipItem("monthly", "每月")
```4. 路线地图:按需查询步行路线
text请在回复里做一张互动地图,按台北车站、二二八和平公园、总统府的顺序标点。我要能拖动、缩放、点击景点,并按需查询步行路线。拖动地图后用加减按钮缩放,点击 2 号标记查看二二八和平公园,再点击「查找步行路线」。三个站点保持原顺序,绘制路线前后的标记位置一致。
RouteMap 接收按顺序排列的公开地标坐标。MapLibre 在卡片接近视口后加载底图。点击查询才将站点坐标发送给 FOSSGIS,返回的 GeoJSON 线更新现有地图图层,因此查询不会重新定位视角。
底图使用 OpenFreeMap,地图数据 © OpenStreetMap 贡献者,步行路线由 FOSSGIS 提供。OpenFreeMap · OpenStreetMap 授权 · FOSSGIS 路线服务
5. 图文指南:翻页和切换书架版本
text做一份可翻页的桌面书架安装指南,提供单层和双层两个版本。每个版本用三幅线条图展示对齐、装入层板、检查方正。在单层版点「下一步」观察线条图变化,再切到「双层」,此时回到第 1 步。继续翻到「检查方正」,可看到对角线。
StepGuide 把版本和步骤作为结构化数据,每一步持有说明和 SVG 路径。组件按步骤绘制线条图,切换版本时在本地重置步骤索引。
6. 倒计时与 Markdown:计时卡和步骤一起显示
text给我一份手冲咖啡指南。开头保留 **准备:**15 克咖啡粉 的紧接数字写法,在闷蒸步骤旁放一个可开始、暂停和重置的 12 秒测试倒计时。「**准备:**15 克咖啡粉」中的标签仍然加粗,闷蒸步骤和计时器一起显示。点击「开始」,倒数到 11 秒时暂停,再点「重置」回到 12 秒。
AssistantContent 将围栏前的文字交给 Markdown 渲染器,中文冒号紧接数字的加粗写法由 Markdown 的 CJK 处理逻辑识别。Countdown 接收秒数,开始、暂停和重置都由浏览器处理。这里的 12 秒只用于测试控件。
7. 用量换算:把 2 人份调成 5 人份
text做一份 2 人份燕麦早餐购物清单,含 100 克燕麦、300 毫升牛奶和 20 克蜂蜜。让我在回复里用滑块调整份数,立即换算。将滑块从 2 调到 5,清单立即更新为 250 克燕麦、750 毫升牛奶和 50 克蜂蜜。聚焦滑块后也能用方向键调整。
ScaledList 接收基准份数和每种食材的基准用量。每次滑动都按「基准用量 × 当前份数 ÷ 基准份数」计算,单位保持原样。
8. 图片搜索:打开庭院照片的来源
text做一张日式庭院灵感板,给出石材、苔藓和竹篱的搭配建议,并提供一个按钮,从 Wikimedia Commons 查找相关参考图片。先看石材、苔藓和竹篱的配色,再点「在维基共享资源中查找图片」。结果在卡片里显示缩略图,点击结果可打开对应的 Wikimedia Commons 文件页。
ColorSwatch 显示色值和建议用途。SearchImage 在点击后才发送查询词,并校验缩略图与来源链接的域名。截图中的照片来自实际搜索结果。
截图照片按显示顺序授权如下。
- Daderot,CC0。DSC00327 · DSC00324
- Sherwin John Carlquist,CC BY 4.0。Moss-covered stone sculpture · CC BY 4.0
- Z3lvs,CC0。Stone lantern · Raked gravel · Gravel court
9. 销售仪表盘:调低 20% 查看预计总额
text用 Loop 内置的模拟销售数据做一个仪表盘。先画一张按月显示实际营收的柱状图,再加一个能即时调整预计营收的百分比滑块。先看 1 到 6 月的实际营收柱状图,再把滑块设到 −20%。柱状图仍显示实际营收,预计总额更新为 67,360 美元,下方表格逐月列出实际值和预计值。
Query("loop_demo_sales", {}) 读取 Loop 内置的虚构销售数据,BarChart 和 SalesScenario 共享同一份月度数据。预计总额按 84,200 × 0.8 得出,滑块变化只重算本地预测。
10. 鼓机:编辑并播放 16 步节奏
text在回复里放一个 16 步鼓机,初始速度 108 BPM,带底鼓、军鼓、踩镲、摇摆滑块和播放按钮。让我能编辑节奏,也能单独敲击每种鼓。鼓机以 108 BPM 打开。点击三行中的格子编辑节奏,也能单独试听底鼓、军鼓或踩镲。点击「播放」可看到当前拍在 16 列间移动,点击「停止」后高亮消失。
DrumLab 在浏览器中维护三个轨道的步进状态。用户点击后才启动 Web Audio,按速度和摇摆值安排发声时间,并同步更新播放高亮。
11. 让生成和渲染共享组件定义
Loop 使用 @openuidev/react-lang 的解析器和 React 渲染器,以及 @openuidev/react-ui 的官方组件。共享库以独立组件库为基础,再补入追问按钮等聊天组件。后端从 toSpec() 读取组件签名,前端用 toJSONSchema() 和根组件配置建立解析器。两端由同一份定义约束组件名、参数顺序和根节点。OpenUI 源码
Web 后端通过 SDK 的 additionalTools 注册只读工具 load_openui_docs。工具描述引导模型按意图选组件:趋势用图表,多维比较用表格,收集偏好用表单。简单问答可以直接返回 Markdown。每次工具调用只加载一个主题的签名、规则和示例,例如 {"topic":"charts"}。按主题加载可以把组件手册留在模型确实需要的那一轮上下文里。
12. 从文本增量渲染并从历史重建
助手回复仍是文本流。AssistantContent 识别其中顶层的 openui 围栏,将围栏前后的文字交给 Markdown 渲染器。首次遇到可渲染的块才加载 OpenUiCard 及其样式。最新文本片段末尾的围栏在生成期间即使还没闭合,也可以随增量预览。
回复结束时,解析器检查根节点、引用和错误。未闭合、无效或渲染失败的内容保留为可读源码。历史保存原始助手消息,重新打开会话时可重建组件。表单提交记录随用户消息保存,卡片重新挂载时会重新初始化本地控件状态。
13. 把界面交互接入会话边界
图表悬停和表单选项切换留在浏览器。追问和表单提交复用当前会话的消息入口,要求会话已连接且可发送。基础图表、表格和表单可以直接使用消息里的数据。渲染器只允许通过 Query 读取内置的虚构销售数据,并拒绝 Mutation。若下一轮需要调用工具,仍通过 Agent 的常规工具与权限流程。
Give Loop a set of visit counts and its reply can include a chart. Ask for a comparison and the reply can line up prices and delivery times in a table with a clickable follow-up. When the task calls for preferences, the user can choose them and submit them in the message. Here, Intelligent UI means interfaces generated for the conversation and usable within it. This article traces how Loop Web and Desktop implement them with OpenUI.
The screenshots show Loop’s actual chat components in a browser with fixed fictional messages. Try the suggested prompts in a chat to explore the behavior. The interface depends on the model’s reply. The first three cases include OpenUI Lang examples. The next seven include copyable prompts and the results checked in the browser.
1. Read a trend by hovering over Wednesday
Ask “Visits from Monday to Friday were 12, 19, 16, 24, and 28. Which day dipped, and what was the overall trend?” The reply explains that visits dropped from 19 to 16 on Wednesday before climbing to 28 on Friday. Hover over Wednesday’s bar to see its value of 16 in the tooltip.
BarChart and Series take the axis labels and values. The React chart handles the tooltip in the browser so the reader can inspect a data point without sending another message.
markdown```openui
root = Stack([BarChart(["Mon", "Tue", "Wed", "Thu", "Fri"], [Series("Visits", [12, 19, 16, 24, 28])])])
```2. Compare plans and choose a follow-up
Ask “Compare three fictional plans. Basic costs $29 with delivery in 5 days and email support. Standard costs $49 with delivery in 2 days and email support. Express costs $79 with delivery in 1 day and priority support.” The table puts price, delivery, and support side by side. Click “Compare only plans that deliver within two days” below it to send that text as a user message.
Table([Col(...)]) takes data by column. Values at matching positions form a row. FollowUpItem passes its text to the chat submission path. Clicking it starts the next turn and leaves the original table in the conversation.
markdown```openui
root = Stack([comparison, followups])
comparison = Table([Col("Plan", ["Basic", "Standard", "Express"]), Col("Price", ["$29", "$49", "$79"]), Col("Delivery", ["5 days", "2 days", "1 day"]), Col("Support", ["Email", "Email", "Priority"])])
followups = FollowUpBlock([FollowUpItem("Compare only plans that deliver within two days")])
```3. Submit a weekly report preference
Ask “Let me choose weekly or monthly delivery, then recommend a report format.” Select “Weekly” and click “Apply.” Selecting an option updates the form state. Clicking “Apply” adds a new user message that reads “Recommend a report format for this frequency.”
Chips defines a stable value and a visible label for each choice. @ToAssistant supplies the text shown in the user bubble. The next turn also receives structured form data, including the field name frequency, the label “Delivery frequency,” the raw value weekly, and the display value “Weekly.” That gives the model the exact choice when the message says only “this frequency.”
markdown```openui
root = Stack([Form("report", actions, [frequency])])
actions = Buttons([Button("Apply", @ToAssistant("Recommend a report format for this frequency"))])
frequency = FormControl("Delivery frequency", Chips("frequency", "single", [weekly, monthly]))
weekly = ChipItem("weekly", "Weekly")
monthly = ChipItem("monthly", "Monthly")
```4. Route map: request walking directions
textWalk from Taipei Main Station via 228 Peace Memorial Park to the Presidential Office. Mark the stops in that order. Let me pan, zoom, select stops, and request a walking route.Drag the map, use the zoom buttons, then select marker 2 for 228 Peace Memorial Park. Click “Find walking route.” The three stops stay in order and the markers keep their screen positions as the route appears.
RouteMap takes an ordered list of public landmark coordinates. MapLibre loads the map near the viewport. The click sends the stops to FOSSGIS, and the returned GeoJSON line updates the existing map layer while preserving the view.
Basemap by OpenFreeMap. Map data © OpenStreetMap contributors. Walking route by FOSSGIS. OpenFreeMap · OpenStreetMap licensing · FOSSGIS routing
5. Illustrated guide: page through assembly steps
textMake a step-by-step desktop bookshelf assembly guide with single- and double-shelf variants. Draw alignment, shelf installation, and squareness checks for both.Click “Next” on the single-shelf version to change the diagram. Switch to “Double shelf” to return to step 1, then advance to the squareness check to see the diagonals.
StepGuide takes structured variants, each with its own instructions and SVG paths. The browser draws each step’s diagram and resets the step index when the variant changes.
6. Countdown and Markdown: show the timer with the steps
textMake a short pour-over coffee guide. Start with **Prep:**15 g of ground coffee, with no space after the bold label. Add a 12-second test countdown with start, pause, and reset next to the bloom step.The label in “**Prep:**15 g of ground coffee” remains bold. The bloom step and timer appear together. Start the timer, pause it at 11 seconds, then reset it to 12.
AssistantContent sends text outside the fence to the Markdown renderer. The CJK Markdown handling also recognizes the Chinese label ending in a fullwidth colon directly before a digit. Countdown takes a duration in seconds and runs its controls in the browser. The short interval is for testing the controls.
7. Ingredient scaling: change two servings to five
textMake a two-serving oatmeal shopping list with 100 g oats, 300 mL milk, and 20 g honey. Add a slider to scale quantities in the reply.Move the slider from 2 to 5. The list immediately shows 250 g oats, 750 mL milk, and 50 g honey. The arrow keys work when the slider has focus.
ScaledList receives the base serving count and quantities. It multiplies each quantity by the current serving count divided by the base count and keeps the supplied units.
8. Image search: open the source for each garden photo
textCreate a Japanese courtyard mood board with stone, moss, and bamboo, plus a button that searches Wikimedia Commons for reference images.Review the stone, moss, and bamboo swatches, then click “Find images on Wikimedia Commons.” The card shows thumbnails. Each result opens its own Commons file page.
ColorSwatch presents the color code and suggested use. SearchImage sends the query after the click and checks the thumbnail and source domains. The screenshot shows results from a live search.
Photo credits in screenshot order.
- Daderot (CC0). DSC00327 · DSC00324
- Sherwin John Carlquist (CC BY 4.0). Moss-covered stone sculpture · CC BY 4.0
- Z3lvs (CC0). Stone lantern · Raked gravel · Gravel court
9. Sales dashboard: reduce projected revenue by 20%
textBuild a dashboard from Loop’s built-in mock sales data. Plot actual revenue by month and add a slider to adjust projected revenue by a percentage.Read the actual revenue bars for January through June, then move the slider to −20%. The chart still shows actual revenue. The projected total updates to $67,360, with actual and projected values listed below by month.
Query("loop_demo_sales", {}) reads Loop’s bundled fictional data. BarChart and SalesScenario share it. The slider recalculates the projection in the browser, multiplying $84,200 by 0.8.
10. Drum machine: edit and play a 16-step pattern
textPut a 16-step drum machine in the reply at 108 BPM, with kick, snare, hi-hat, a swing slider, and playback. Let me edit the pattern and trigger each drum separately.The sequencer opens at 108 BPM. Toggle cells in any row or audition the kick, snare, and hi-hat individually. Click “Play” to see the highlight move across the 16 columns. “Stop” clears it.
DrumLab stores the three tracks in the browser. A user gesture starts Web Audio. Tempo and swing determine when each sound plays, while the UI tracks the current step.
11. Share component definitions between generation and rendering
Loop uses the parser and React renderer from @openuidev/react-lang and official components from @openuidev/react-ui. The shared library starts with the standalone set and adds chat components such as follow-up buttons. The backend reads component signatures from toSpec(). The frontend creates its parser with toJSONSchema() and the root configuration. One definition governs component names, argument order, and the root on both sides. OpenUI source
The Web backend registers the read-only load_openui_docs tool through the SDK’s additionalTools option. Its description guides the model toward charts for trends, tables for comparisons, and forms for preferences. Simple replies can stay in Markdown. A call such as {"topic":"charts"} loads signatures, rules, and an example for one topic, so component documentation enters the conversation when the model needs it.
12. Render text increments and rebuild from history
The assistant still streams text. AssistantContent identifies top-level openui fences and sends the surrounding text to the Markdown renderer. The first renderable block loads OpenUiCard and its styles. A trailing block in the latest text segment can preview as text arrives, including before its fence closes.
At the end of the reply, the parser checks the root, references, and errors. Unclosed, invalid, or failed blocks remain readable as source. History retains the original assistant message so reopening the chat can rebuild the interface. Form submissions are saved with user messages, and a remounted card starts with fresh local control state.
13. Route interface actions through the chat
Hovering over a chart and changing a form choice happen in the browser. Follow-ups and form submissions use the current session’s message submission path and require a connected chat that can accept the message. Basic charts, tables, and forms can use data already in the message. The renderer allows Query only for the bundled fictional sales data and rejects Mutation. Any tool call in the next turn goes through the agent’s normal tool and permission flow.
