快速开始
即使你已经有了 GUI,也建议从这里入手:无头(headless)桥不需要任何工具包,也不需要切回主线程,因此你可以直接在测试或 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} 的工具。除此之外不暴露任何东西,而这两者都无需你手工拼装。