安装belt CLI技能:
npx skills add belt-sh/cli
小组件渲染器
通过JSON声明式UI,由ui.inference.sh提供支持。

快速开始
npx shadcn@latest add https://ui.inference.sh/r/widgets.json
基本用法
import { WidgetRenderer } from "@/registry/blocks/widgets/widget-renderer"
import type { Widget, WidgetAction } from "@/registry/blocks/widgets/types"
const widget: Widget = {
type: 'ui',
title: '我的小组件',
children: [
{ type: 'text', value: '您好,世界' },
{ type: 'button', label: '点击我', onClickAction: { type: 'click' } },
],
}
<WidgetRenderer
widget={widget}
onAction={(action, formData) => console.log(action, formData)}
/>
组件类型
布局
{ "type": "row", "gap": 2, "children": [...] }
{ "type": "col", "gap": 2, "children": [...] }
{ "type": "box", "background": "gradient-ocean", "padding": 4, "radius": "lg", "children": [...] }
排版
{ "type": "title", "value": "标题", "size": "2xl", "weight": "bold" }
{ "type": "text", "value": "正文", "variant": "bold" }
{ "type": "caption", "value": "小字" }
{ "type": "label", "value": "字段标签", "fieldName": "email" }
交互
{ "type": "button", "label": "提交", "variant": "default", "onClickAction": { "type": "submit" } }
{ "type": "input", "name": "email", "placeholder": "输入邮箱" }
{ "type": "textarea", "name": "message", "placeholder": "您的消息" }
{ "type": "select", "name": "plan", "options": [{ "value": "pro", "label": "专业版" }] }
{ "type": "checkbox", "name": "agree", "label": "我同意", "defaultChecked": false }
展示
{ "type": "badge", "label": "新", "variant": "secondary" }
{ "type": "icon", "iconName": "check", "size": "lg" }
{ "type": "image", "src": "https://...", "alt": "图片", "width": 100, "height": 100 }
{ "type": "divider" }
示例:航班卡片
const flightWidget: Widget = {
type: 'ui',
children: [
{
type: 'box', background: 'gradient-ocean', padding: 4, radius: 'lg', children: [
{
type: 'row', justify: 'between', children: [
{
type: 'col', gap: 1, children: [
{ type: 'caption', value: '出发' },
{ type: 'title', value: 'SFO', size: '2xl', weight: 'bold' },
]
},
{ type: 'icon', iconName: 'plane', size: 'lg' },
{
type: 'col', gap: 1, align: 'end', children: [
{ type: 'caption', value: '到达' },
{ type: 'title', value: 'JFK', size: '2xl', weight: 'bold' },
]
},
]
},
]
},
],
}
示例:表单
const formWidget: Widget = {
type: 'ui',
title: '联系表单',
asForm: true,
children: [
{
type: 'col', gap: 3, children: [
{ type: 'input', name: 'name', placeholder: '您的姓名' },
{ type: 'input', name: 'email', placeholder: '邮箱地址' },
{ type: 'textarea', name: 'message', placeholder: '消息' },
{ type: 'button', label: '发送', variant: 'default', onClickAction: { type: 'submit' } },
]
},
],
}
渐变
| 名称 | 描述 |
|---|---|
gradient-ocean | 蓝绿色渐变 |
gradient-sunset | 橙粉色渐变 |
gradient-purple | 紫色渐变 |
gradient-cool | 冷蓝色渐变 |
gradient-midnight | 深蓝色渐变 |
处理动作
const handleAction = (action: WidgetAction, formData?: WidgetFormData) => {
switch (action.type) {
case 'submit':
console.log('表单数据:', formData)
break
case 'click':
console.log('按钮被点击')
break
}
}
相关技能
# 完整代理组件
npx skills add inference-sh/skills@agent-ui
# 聊天界面组件
npx skills add inference-sh/skills@chat-ui
# 工具界面
npx skills add inference-sh/skills@tools-ui