Canvas(macOS 应用)
macOS 应用使用 WKWebView 嵌入了一个画布面板,由智能体控制。它是一个轻量级的视觉工作区,用于 HTML/CSS/JS、A2UI 和小型交互式 UI 表面。
画布的位置
画布状态存储在 Application Support 下:
~/Library/Application Support/OpenClaw/canvas/<session>/...
画布面板通过自定义 URL 方案提供这些文件:
openclaw-canvas://<session>/<path>
示例:
openclaw-canvas://main/→<canvasRoot>/main/index.htmlopenclaw-canvas://main/assets/app.css→<canvasRoot>/main/assets/app.cssopenclaw-canvas://main/widgets/todo/→<canvasRoot>/main/widgets/todo/index.html
如果根目录不存在 index.html,应用会显示一个内置脚手架页面。
面板行为
- 无边框、可调整大小的面板,锚定在菜单栏附近(或鼠标光标位置)。
- 记住每个会话的大小/位置。
- 当本地画布文件更改时自动重新加载。
- 一次只显示一个画布面板(根据需要切换会话)。
可以从设置中禁用画布 → 允许画布。禁用后,画布节点命令返回 CANVAS_DISABLED。
智能体 API 表面
画布通过网关 WebSocket 公开,因此智能体可以:
- 显示/隐藏面板
- 导航到路径或 URL
- 执行 JavaScript
- 捕获快照图像
CLI 示例:
bash
openclaw nodes canvas present --node <id>
openclaw nodes canvas navigate --node <id> --url "/"
openclaw nodes canvas eval --node <id> --js "document.title"
openclaw nodes canvas snapshot --node <id>注意:
canvas.navigate接受本地画布路径、http(s)URL 和file://URL。- 如果传递
"/",画布显示本地脚手架或index.html。
画布中的 A2UI
A2UI 由网关画布主机托管,并在画布面板内渲染。当网关广告画布主机时,macOS 应用在首次打开时自动导航到 A2UI 主机页面。
默认 A2UI 主机 URL:
http://<gateway-host>:18793/__openclaw__/a2ui/A2UI 命令(v0.8)
画布目前接受 A2UI v0.8 服务器→客户端消息:
beginRenderingsurfaceUpdatedataModelUpdatedeleteSurface
不支持 createSurface(v0.9)。
CLI 示例:
bash
cat > /tmp/a2ui-v0.8.jsonl <<'EOFA2'
{"surfaceUpdate":{"surfaceId":"main","components":[{"id":"root","component":{"Column":{"children":{"explicitList":["title","content"]}}}},{"id":"title","component":{"Text":{"text":{"literalString":"Canvas (A2UI v0.8)"},"usageHint":"h1"}}},{"id":"content","component":{"Text":{"text":{"literalString":"If you can read this, A2UI push works."},"usageHint":"body"}}}]}}
{"beginRendering":{"surfaceId":"main","root":"root"}}
EOFA2
openclaw nodes canvas a2ui push --jsonl /tmp/a2ui-v0.8.jsonl --node <id>快速冒烟测试:
bash
openclaw nodes canvas a2ui push --node <id> --text "Hello from A2UI"从画布触发智能体运行
画布可以通过深层链接触发新的智能体运行:
openclaw://agent?...
示例(在 JS 中):
js
window.location.href = "openclaw://agent?message=Review%20this%20design";除非提供有效的密钥,否则应用会提示确认。
安全说明
- 画布方案阻止目录遍历;文件必须位于会话根目录下。
- 本地画布内容使用自定义方案(不需要本地环回服务器)。
- 仅在显式导航时才允许外部
http(s)URL。