生成交互式网页(仪表盘、图表、表格、报告)并通过公共URL提供,适用于用户明确请求数据可视化的场景。
Claw2UI - Agent-to-UI Bridge.是一项面向实际任务的技能,主要用于Generate 交互式网页,来自 TypeScript DSL 规格,并通过公共URL服务.;Pages包括 Tailwind CSS, Alpine.js, 和 Chart.js 出框, 与 .。
实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;
涉及批量任务时,还应保存进度,避免中断后重复操作。该技能适合用于一次性任务,也可以接入自动化工作流,与其他技能或上层代理配合完成更完整的业务链路;在组合使用时,应明确每一步的输入输出关系,并避免不同步骤之间出现参数冲突。
基于 TypeScript DSL 规范生成交互式网页,并通过公开 URL 提供服务。页面默认集成 Tailwind CSS、Alpine.js 和 Chart.js,支持可插拔主题、类型检查及响应式移动端布局。
源码:GitHub · npm · HF Space · 许可证:MIT
每个已发布的页面均可通过公开 URL 访问。未经用户明确授权,严禁发布。
html 组件会在服务端自动清洗,但应避免将未经信任的原始输入直接传给其他组件--ttl 3600000(1 小时)Claw2UI 默认使用公共服务器 https://0xsegfaulted-claw2ui.hf.space,无需本地部署服务端。
npm install -g claw2ui claw2ui register --server https://0xsegfaulted-claw2ui.hf.space # 完成!Token 已自动保存至 ~/.claw2ui.json
自托管:如需自行部署 Claw2UI 服务端(本地、Docker 或 HF Space),请参阅自托管指南。
# 仅需注册一次(Token 自动保存至 ~/.claw2ui.json) claw2ui register --server https://0xsegfaulted-claw2ui.hf.space
编写一个 .ts 文件,内容必须包裹在 container 中。该文件将自动进行类型检查。
cat > /tmp/claw2ui_page.ts << 'SPECEOF'
import { page, container, header, row, stat, card, chart, dataset } from "claw2ui/dsl"
export default page("Page Title", [
container(
header("Title", "Description"),
row(3,
stat("Metric 1", "100", { change: 5.2, icon: "trending_up" }),
stat("Metric 2", "200"),
stat("Metric 3", "300"),
),
card("Trend",
chart("line", {
labels: ["Jan", "Feb", "Mar"],
datasets: [dataset("Value", [10, 20, 15], { borderColor: "#3b82f6", tension: 0.3 })],
}),
),
),
], { style: "anthropic" })
SPECEOF
发布前,请向用户说明将要发布的内容,并确认其是否同意继续操作。该页面将可通过公开 URL访问。例如:
“我已为您准备了一个仪表盘,内容包括:[内容摘要]。是否确认发布至公开 URL?(可添加
--ttl 3600000参数,使页面 1 小时后自动过期。)”
仅在获得用户明确确认后执行:
claw2ui publish --spec-file /tmp/claw2ui_page.ts --title "Dashboard" # 对于敏感或临时数据,始终设置 TTL: claw2ui publish --spec-file /tmp/claw2ui_page.ts --title "Dashboard" --ttl 3600000 # 跳过类型检查以加速发布(不推荐): claw2ui publish --spec-file /tmp/claw2ui_page.ts --title "Dashboard" --no-check
命令将输出公开 URL。
将生成的 URL 包含在您对用户的响应中。
# 连接管理 claw2ui register --server# 自助注册 claw2ui init --server --token # 手动配置 # 发布 claw2ui publish --spec-file --title "Title" # 从 TS DSL 发布(带类型检查) claw2ui publish --spec-file --no-check # 跳过类型检查 claw2ui publish --spec-file --title "Title" # 从 JSON 规范发布(遗留支持) claw2ui publish --html " Hi
" --title "Test" # 原生 HTML claw2ui publish --spec-file--style anthropic # 指定主题 claw2ui publish --spec-file --ttl 3600000 # 设置 TTL(毫秒) # 主题管理 claw2ui themes # 列出可用主题 # 页面管理 claw2ui list # 列出所有已发布页面 claw2ui delete # 删除指定页面 claw2ui status # 检查服务端状态
所有函数均从 "claw2ui/dsl" 导入。
page(title, components[], opts?) // opts: { theme?: "light"|"dark"|"auto", style?: "anthropic"|"classic" }
...children)container(...children) // 最外层容器,必须使用 row(cols, ...children) // 网格行:row(3, stat(...), stat(...), stat(...)) column(span, ...children) // 行内网格列 card(title, ...children) // 带边框/阴影的卡片 list(direction, ...children) // "vertical" 或 "horizontal" modal(title, ...children) // 弹出式对话框
tabs( // 标签页
tab("id", "Label", ...children),
tab("id2", "Label 2", ...children),
)
accordion( // 可折叠区域
section("Title", ...children),
section("Title 2", ...children),
)
stat(label, value, opts?) // opts: { change?: number, icon?: string }
chart(chartType, data, opts?) // opts: { height?, options?, legendPosition?, title? }
table(columns, rows, opts?) // opts: { searchable?, perPage? }
dataset(label, data[], opts?) // Chart.js 数据集:dataset("Rev", [1,2,3], { borderColor: "red" })
col(key, label?, format?) // 列定义:col("name", "Name", "currency")
badge(key, label, badgeMap) // Badge 列:badge("status", "Status", { Active: "success" })
months(n) // 月份标签:months(6) → ["Jan","Feb","Mar","Apr","May","Jun"]
button(label, variant?) // variant: "primary"|"secondary"|"danger"|"outline"
textField(label?, opts?) // opts: { placeholder?, value?, inputType? }
select(label, options) // options: [{ value: "a", label: "Option A" }]
checkbox(label, value?)
choicePicker(label, options, opts?) // opts: { value?, variant?, displayStyle? }
slider(label, opts?) // opts: { min?, max?, value? }
dateTimeInput(label, opts?) // opts: { value?, enableDate?, enableTime?, min?, max? }
markdown(content) // 渲染 Markdown 为样式化 HTML(富文本首选)
text(content, opts?) // opts: { size?, bold?, class? }
code(content, language?) // 带语法高亮的代码块
html(content) // 原生 HTML(服务端自动清洗)
icon(name, size?) // Material Icon:icon("settings", 24)
image(src, alt?)
video(url, poster?)
audioPlayer(url, description?)
divider()
spacer(size?)
header(title, subtitle?) // 页面标题栏 link(href, label?, target?) // 超链接
style 字段)| 主题 | 描述 |
|---|---|
anthropic |
(默认) 温暖的编辑风格 —— Newsreader 衬线体标题、赤陶色强调色、米白背景 |
classic |
原始 Tailwind 风格 —— 蓝色强调色、系统字体、灰色表面 |
DSL 支持类型检查,约节省 60% token 消耗,并可嵌入逻辑。JSON 规范仍受支持,但属于遗留方案。
// 基于数据动态生成 stats
const metrics = [
{ label: "CPU", value: "42%", icon: "monitor" },
{ label: "Memory", value: "6.2 GB", icon: "memory" },
{ label: "Disk", value: "120 MB/s", icon: "storage" },
]
row(3, ...metrics.map(m => stat(m.label, m.value, { icon: m.icon })))
// 条件渲染
container(
header("Report"),
data.length > 0
? card("Trend", chart("line", chartData))
: text("No data available"),
)
// 过滤 falsy 值
container(
header("Dashboard"),
showMetrics && row(3, stat("A", "1"), stat("B", "2"), stat("C", "3")),
card("Details", table(cols, rows)),
)
col() / badge() / dataset() 辅助函数// 推荐 —— 简洁且可读性强
table(
[col("name", "Name"), col("rev", "Revenue", "currency"), badge("status", "Status", { Active: "success" })],
rows,
)
// 避免 —— 冗长的原始对象
table(
[{ key: "name", label: "Name" }, { key: "rev", label: "Revenue", format: "currency" }, { key: "status", label: "Status", format: "badge", badgeMap: { Active: "success" } }],
rows,
)
markdown()card("About",
markdown(`
## Features
- **Fast** — sub-second rendering
- **Secure** — sanitized HTML output
- **Responsive** — mobile-first layouts
> Built with Claw2UI
`),
)
months()chart("bar", {
labels: months(6),
datasets: [dataset("Revenue", [100, 200, 150, 300, 250, 400])],
})
import { page, container, header, row, stat, card, chart, table, col, badge, dataset } from "claw2ui/dsl"
export default page("Dashboard", [
container(
header("Dashboard", "Overview"),
row(3,
stat("Revenue", "$1.2M", { change: 15.3, icon: "payments" }),
stat("Orders", "8,432", { change: 8.1, icon: "shopping_cart" }),
stat("Customers", "2,847", { change: -2.5, icon: "group" }),
),
card("Trend",
chart("line", {
labels: months(6),
datasets: [dataset("Revenue", [320, 410, 380, 450, 480, 520], {
borderColor: "#3b82f6", tension: 0.3, fill: true,
backgroundColor: "rgba(59,130,246,0.1)",
})],
}, { height: 280 }),
),
card("Details",
table(
[col("name", "Name"), col("value", "Value", "currency"), badge("status", "Status", { Active: "success", Inactive: "error" })],
[
{ name: "Product A", value: 450000, status: "Active" },
{ name: "Product B", value: 320000, status: "Active" },
{ name: "Product C", value: 0, status: "Inactive" },
],
),
),
),
], { style: "anthropic" })
import { page, container, header, row, stat, card, chart, table, tabs, tab, text, markdown, col, dataset, months } from "claw2ui/dsl"
export default page("Monthly Report", [
container(
header("Monthly Report", "March 2026"),
tabs(
tab("overview", "Overview",
row(3,
stat("Users", "12,847", { change: 18.5, icon: "group" }),
stat("Revenue", "$89K", { change: 24.3, icon: "payments" }),
stat("Churn", "3.2%", { change: -1.1, icon: "trending_down" }),
),
card("Growth",
chart("line", {
labels: months(6),
datasets: [
dataset("Users", [8000, 9200, 10100, 11000, 11800, 12847], { borderColor: "#3b82f6" }),
dataset("Revenue", [52, 58, 65, 72, 81, 89], { borderColor: "#10b981", yAxisID: "y1" }),
],
}),
),
),
tab("details", "Details",
table(
[col("page", "Page"), col("views", "Views"), col("bounce", "Bounce", "percent")],
[
{ page: "/", views: "23,456", bounce: 28 },
{ page: "/pricing", views: "12,567", bounce: 22 },
{ page: "/docs", views: "9,876", bounce: 18 },
],
),
),
tab("notes", "Notes",
markdown("## Key Takeawaysnn- Revenue up **24.3%** MoMn- Churn improved by 1.1ppn- `/pricing` page has lowest bounce rate"),
),
),
),
], { style: "anthropic" })
import { page, container, header, row, card, stat, text, table, col } from "claw2ui/dsl"
export default page("Plan Comparison", [
container(
header("Plan Comparison", "Choose the right plan"),
row(3,
card("Starter",
stat("Price", "$9/mo"),
text("5 users, 10 GB storage"),
),
card("Pro",
stat("Price", "$29/mo", { icon: "star" }),
text("25 users, 100 GB storage"),
),
card("Enterprise",
stat("Price", "Custom", { icon: "business" }),
text("Unlimited users, 1 TB storage"),
),
),
card("Feature Matrix",
table(
[col("feature", "Feature"), col("starter", "Starter"), col("pro", "Pro"), col("enterprise", "Enterprise")],
[
{ feature: "Users", starter: "5", pro: "25", enterprise: "Unlimited" },
{ feature: "Storage", starter: "10 GB", pro: "100 GB", enterprise: "1 TB" },
{ feature: "Support", starter: "Email", pro: "Priority", enterprise: "Dedicated" },
],
),
),
),
], { style: "anthropic" })
相关专题
热门下载
相关下载
精品课程
共6课时 | 54.6万人学习
共89课时 | 133.4万人学习
共49课时 | 82.2万人学习