macOS companion app

畫布

macOS 應用程式使用 WKWebView 嵌入由代理控制的 Canvas 面板。它是用於 HTML/CSS/JS、A2UI 和小型互動式 UI 介面的輕量視覺工作區。

Canvas 所在位置

Canvas 狀態儲存在 Application Support 下:

  • ~/Library/Application Support/OpenClaw/canvas/<session>/...

Canvas 面板透過 自訂 URL scheme 提供這些檔案:

  • openclaw-canvas://<session>/<path>

範例:

  • openclaw-canvas://main/<canvasRoot>/main/index.html
  • openclaw-canvas://main/assets/app.css<canvasRoot>/main/assets/app.css
  • openclaw-canvas://main/widgets/todo/<canvasRoot>/main/widgets/todo/index.html

如果根目錄沒有 index.html,應用程式會顯示 內建 scaffold 頁面

面板行為

  • 無邊框、可調整大小的面板,錨定在選單列附近(或滑鼠游標附近)。
  • 依每個 session 記住大小/位置。
  • 本機 Canvas 檔案變更時自動重新載入。
  • 同一時間只會顯示一個 Canvas 面板(會視需要切換 session)。

可以從「設定」→ 允許 Canvas 停用 Canvas。停用時,canvas 節點命令會回傳 CANVAS_DISABLED

代理 API 介面

Canvas 透過 Gateway WebSocket 暴露,因此代理可以:

  • 顯示/隱藏面板
  • 導覽到路徑或 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 會顯示本機 scaffold 或 index.html

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)

Canvas 目前接受 A2UI v0.8 伺服器→用戶端訊息:

  • beginRendering
  • surfaceUpdate
  • dataModelUpdate
  • deleteSurface

不支援 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 觸發代理執行

Canvas 可以透過深層連結觸發新的代理執行:

  • openclaw://agent?...

範例(在 JS 中):

window.location.href = "openclaw://agent?message=Review%20this%20design";

除非提供有效金鑰,否則應用程式會提示確認。

安全注意事項

  • Canvas scheme 會阻擋目錄遍歷;檔案必須位於 session 根目錄下。
  • 本機 Canvas 內容使用自訂 scheme(不需要 loopback 伺服器)。
  • 只有在明確導覽時,才允許外部 http(s) URL。

相關