Skip to content

快速開始

即使你已經有 GUI,也建議從這裡開始:headless bridge 不需要任何工具組,也不需要跳回主執行緒,因此你可以在測試或 main 裡直接把投影跑起來。

toml
[dependencies]
purview = "0.1"
tokio = { version = "1", features = ["full"] }
rust
use purview::{ActionError, GuiBridge, Outcome, on_ui};

#[tokio::main]
async fn main() -> Result<(), purview::ServeError> {
    // 1. Build the bridge. `headless()` fixes Cx = () and runs posted work inline.
    let (bridge, app) = GuiBridge::headless()
        .instructions_append("An order-management app.")
        .build();

    // 2. Describe a window and its initial content.
    let win = app.open("Order");
    win.set_summary("Editing order #12345");
    let form = win.blocks().fields([("Recipient", ""), ("Amount", "$0")]);

    // 3. Register an action. It becomes the MCP tool `{winId}__submit`.
    win.actions()
        .add("submit", "Submit order")
        .destructive()
        .on(on_ui(move || {
            form.set("Recipient", "Alice"); // read side: projection follows
            Ok::<_, ActionError>(Outcome::message("submitted"))
        }));

    // 4. Serve until the client disconnects.
    bridge.serve_stdio().await
}

每一次整合的形態都是這樣:建立 → 描述 → 註冊 → 提供服務。本指南其餘部分就是把這四個步驟填滿。

Agent 看到的是什麼

投影會以單一資源 app://windows 對外提供,再加上每個視窗動作各一個工具,命名為 {winId}__{action}。除此之外不會暴露任何東西,而這兩者你都不需要手動組裝。