generative-ui
它能做什么
这项技能说明智能体如何在聊天中显示内联的交互界面,由沙盒化的 Alpine.js 和 Tailwind 构建。它涵盖一次性控件和已保存的迷你应用。适合希望在对话中使用快速交互辅助工具的人。
适用场景
- ✓当你希望在聊天中使用滑块、选择器或计算器等快速控件的时候。
- ✓当临时图表或预览有助于对话的时候。
- ✓当一个有用的小组件应当保存下来,以便之后重新打开的时候。
技能链接
https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/generative-ui/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请在这个聊天中给我一个滑块,让我调整价格并看到总额随之更新。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体以内联方式渲染一个小型沙盒 HTML 控件。它的值可以在下一轮发回给智能体,已保存的版本之后也可以重新打开。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Generative UI
Generative UI is sandboxed Alpine.js HTML rendered inline in chat. It is not a source-code change and does not go through Builder.
Pick the Lifetime
- Use
render-inline-extensionfor one-off UI that belongs only in the current chat: knobs, controls, pickers, calculators, temporary charts, and previews. - Use
create-extensionwhen the UI should be saved, reusable, or visible in the Extensions view. It also renders inline after creation. - Use
show-extension-inlineto reopen a saved extension inside chat. - Use
update-extensionto edit an existing saved extension.
Inputs From Chat
Pass initial values through the action context argument. The iframe reads them
from window.slotContext and can subscribe to changes with
window.onSlotContext(fn).
<script>
Alpine.data("controls", () => ({
threshold: 50,
init() {
this.threshold = Number(window.slotContext?.threshold ?? 50);
window.onSlotContext?.((ctx) => {
if (ctx.threshold !== undefined) {
this.threshold = Number(ctx.threshold);
}
});
},
}));
</script>
Outputs To The Agent
Use passive output when a control's current value should be visible to the agent on the next turn without requiring a submit click:
<input
type="range"
min="0"
max="100"
x-model.number="threshold"
@input="agentNative.ui.output({ threshold }, { label: 'Threshold' })"
/>
agentNative.ui.output(value, opts?) writes application state at:
inline-ui:<extensionId>:output
The id is scoped automatically; the HTML author must not pass it. When the user says "use that value", "apply the current setting", or "run it with the current selection", read the value with:
const output = await readAppState("inline-ui:<id>:output");
The stored payload includes value, updatedAt, extensionId, and
source: "inline-ui", plus optional label, context, or meta.
Use agentNative.chat.send(message, opts?) or sendToAgentChat(message, opts?)
for a visible Apply/Submit button that should send a prompt or selected value
into the chat. Pass { submit: true } explicitly for that user-triggered
action; extension messages are draft-only otherwise. Never call these helpers
from polling, refresh, or error handlers.
App Data And State
- Prefer
appAction(name, params)for template data and operations. - Use
appFetch(path, options)only for allowed framework endpoints under/_agent-native/*, including application-state reads and writes. - Do not call template
/api/*routes from generated UI. - Use
dbQuery/dbExeconly for known existing SQL tables when no action fits. - Use
extensionFetchfor external APIs through the sandbox proxy and secrets.
Transient extensionData Boundary
For saved extensions, extensionData uses the authenticated database-backed
extension data API.
For transient inline UIs, extensionData is host localStorage. The agent
cannot read it, it does not sync across devices, it does not migrate when a UI
is promoted to a saved Extension, and the server does not garbage-collect it.
Use it only for throwaway local UI state.
For anything the agent or app must observe, use agentNative.ui.output,
application state through appFetch, an appAction, or
agentNative.chat.send.
Styling
Use semantic Tailwind classes so the iframe inherits the parent app theme:
bg-background,text-foreground,border-borderbg-card,text-card-foregroundbg-primary,text-primary-foregroundtext-muted-foreground,bg-accent
Do not hardcode provider tokens, private data, or internal secrets in generated HTML. Do not call an LLM directly from the iframe; route AI work through the agent chat.
常见问题
这会修改我应用的代码吗?
不会。它是聊天中的内联界面,不会改变应用的源代码。
智能体能看到我在控件中设置的内容吗?
能。数值可以作为被动输出传回智能体,无需点击提交。
一次性界面和已保存的界面有什么区别?
一次性界面只存在于当前聊天中,而已保存的界面可以重复使用,并显示在扩展视图中。
详情
作者的原始描述
Generate transient or saved inline chat UI with Alpine/Tailwind controls, outputs, app state, and extensions. Use for knobs, pickers, calculators, dashboards, widgets, or reusable mini-apps.
repo: BuilderIO/agent-native
热度
- GitHub 星标
- 7.6k
- 排名
- #13162
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …