Canvas
macOS 應用程式使用 WKWebView 嵌入了一個由代理程式控制的 Canvas 面板。它是
一個輕量級的視覺化工作區,用於 HTML/CSS/JS、A2UI 和小型互動式
UI 介面。
Canvas 的位置
Section titled “Canvas 的位置”Canvas 的狀態儲存在 Application Support 下:
~/Library/Application Support/OpenClaw/canvas/<session>/...
Canvas 面板透過 自訂 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 檔案變更時自動重新載入。
- 一次只能看到一個 Canvas 面板(會視需要切換工作階段)。
可以在設定 → 允許 Canvas 中停用 Canvas。停用時,canvas 節點指令會傳回 CANVAS_DISABLED。
Agent API 介面
Section titled “Agent API 介面”Canvas 透過 Gateway WebSocket 暴露出來,因此 Agent 可以:
- 顯示/隱藏面板
- 導覽至路徑或 URL
- 執行 JavaScript
- 擷取快照圖片
CLI 範例:
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接受 本地 canvas 路徑、http(s)URL 和file://URL。- 如果您傳遞
"/",Canvas 會顯示本地鷹架或index.html。
Canvas 中的 A2UI
Section titled “Canvas 中的 A2UI”A2UI 由 Gateway canvas host 託管,並在 Canvas 面板內進行轉譯。 當 Gateway 發布 Canvas host 時,macOS 應用程式會在首次開啟時 自動瀏覽至 A2UI host 頁面。
預設 A2UI host URL:
http://<gateway-host>:18789/__openclaw__/a2ui/A2UI 指令 (v0.8)
Section titled “A2UI 指令 (v0.8)”Canvas 目前接受 A2UI v0.8 伺服器→客戶端訊息:
beginRenderingsurfaceUpdatedataModelUpdatedeleteSurface
createSurface (v0.9) 不受支援。
CLI 範例:
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>快速測試:
openclaw nodes canvas a2ui push --node <id> --text "Hello from A2UI"從 Canvas 觸發 Agent 執行
Section titled “從 Canvas 觸發 Agent 執行”Canvas 可以透過深層連結觸發新的 Agent 執行:
openclaw://agent?...
範例(在 JS 中):
window.location.href = "openclaw://agent?message=Review%20this%20design";除非提供了有效的密鑰,否則應用程式會提示確認。
- Canvas 配置會阻止目錄遍歷;檔案必須位於 session 根目錄下。
- 本機 Canvas 內容使用自訂配置(不需要回環伺服器)。
- 只有在明確導航時才允許外部
http(s)URL。