Skip to content

示例

仓库里的每个示例都在自己的端口上提供 MCP 服务,因此可以同时运行多个。把 MCP 客户端指向对应端点,读取 app://windows,然后调用其中的工具。

示例端口覆盖内容
gpui/counter8931最小的端到端集成
gpui/todo8932表格、带参数的工具、校验、动态可用性
gpui/form8933模态链收缩可操作集合、脱敏
gpui/dashboard8934自更新状态、截断、async 处理器
gpui/multi-window8935运行时创建窗口,每个窗口各有自己的工具
sh
cargo run -p gpui-counter
cargo run -p gpui-todo         # {winId}__add {"text": "buy milk"}
cargo run -p gpui-form         # {winId}__submit → confirm/cancel on the modal
cargo run -p gpui-dashboard    # {winId}__page {"offset": 10}
cargo run -p gpui-multi-window # {winId}__open {"title": "Notes"}

这些示例位于独立的 Cargo workspace(examples/)中,与根 workspace 分离,因此构建或测试 Purview 本身时永远不会去编译某个 GUI 工具包。

各示例暴露的工具

每个工具都命名为 {winId}__{action};当前的 winId 请读取 app://windows 获得。

示例窗口工具参数
counterCounterincrement / decrement
todoTodosadd{ text: string }
toggle / remove{ index: number }(从 1 开始;removedestructive
clear_done—(destructive;在没有已完成项之前处于隐藏状态)
formTransferfill{ recipient?, amount?, account? }
submit—(destructive;会打开模态)
Confirm transferconfirm / cancel
dashboardDashboardpage{ offset: number }read_only
pause
report—(read_onlyasync
multi-windowLibraryopen{ title: string }
每个文档窗口append{ line: string }
clear—(destructive

留意列表的变化

formmulti-window 最值得观察。在 form 中,提交会打开模态,Transfer 的工具随即离开 tools/list,直到模态被关闭。在 multi-window 中,你每打开一个文档,就会新增它自己的那一对工具。参见开箱即得的协议行为

你自己集成时的检查清单

  1. 在活跃上下文存在的地方安装 bridge——对 gpui 而言,就是在 Application::run 内部。
  2. 描述每个窗口,并保留后续需要用到的内容块句柄。
  3. 每个视图写一个 sync 方法,并在每次变更后调用它。绝不在其他任何地方写投影。
  4. 注册动作,让它们调用与按钮完全相同的代码。
  5. set_available 隐藏当前不可调用的动作,并确保模态总有办法被关闭。

关于报文格式(wire format)与规范性要求,请参见协议规范