0
50
近 7 天 2
23.2
生态多维模型
4 个月前
2026-04-04
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-generative-ui@0.1.5"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-generative-ui@0.1.5"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D opencode-generative-uiopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
OpenCode plugin that recreates Claude-style generative UI widgets with two custom tools:
visualize_read_meshow_widget
The plugin renders HTML fragments and raw SVG in a native macOS window using Glimpse.
This project is an OpenCode-focused extraction and adaptation of the original Michaelliv/pi-generative-ui work for pi. The original repo did the reverse-engineering work and established the shape of the widget tools and guideline set.
The runtime now uses the same morphdom shell-update approach as the pi implementation: Glimpse loads a stable shell document, widget content is injected via win.send(), and DOM updates are diffed into place instead of replacing the whole page.
What it does
When OpenCode decides a response should be visual, the plugin can:
- Load Claude-style widget design guidance with
visualize_read_me - Render the resulting widget with
show_widget - Return any
window.glimpse.send(data)interaction payload back to the model
Typical use cases:
- interactive explainers
- charts and dashboards
- SVG diagrams
- mockups
- calculators
Widget windows include built-in viewport controls:
- pinch or
Cmd/Ctrl + wheelto zoom - middle-mouse drag to pan
Space + dragto pan with a regular mouse or trackpad- keyboard shortcuts:
+,-,0,F, and arrow keys
Install
From npm in OpenCode
OpenCode does not auto-discover this repo or install it just because it exists on GitHub.
For npm installation, all of the following must be true:
- This package has been published to npm
- The package name is listed in your OpenCode config
- OpenCode is restarted so it can install the plugin
After publishing, add the package name to your OpenCode config:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-generative-ui"]
}
OpenCode installs npm plugins listed in opencode.json automatically with Bun on startup.
You do not need to run npm install or bun install inside the repo where you want to use the plugin. Just add the plugin name to your OpenCode config and restart OpenCode.
You can add it either:
- Globally in
~/.config/opencode/opencode.json - Per project in
opencode.json
Example global config:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-generative-ui"]
}
You can verify that OpenCode resolved the plugin with:
opencode debug config
If the package is installed correctly, you should see opencode-generative-ui in the resolved plugin list.
Runtime requirements
- macOS
- Bun
- OpenCode
- a working Swift/Xcode toolchain for
glimpseui
This plugin opens widget windows through Glimpse, which builds a small native Swift binary during install.
If glimpseui fails to build, update your Xcode Command Line Tools or full Xcode install, then rerun:
bun pm trust glimpseui
Depending on how OpenCode installed the plugin, you may need to run that in the OpenCode cache/config directory rather than inside your app repo.
Local plugin development
If you are developing this plugin itself, install dependencies in this plugin repo:
bun install
If Bun blocks the native build:
bun pm trust glimpseui
Use from a local checkout before publishing
Clone this repo, then copy the plugin entry file into your OpenCode plugin directory if you want to run it before publishing to npm.
For project-local use today:
- Copy
src/index.tsto.opencode/plugins/generative-ui.ts - Copy
src/lib/into.opencode/plugins/lib/ - Copy
glimpseui.d.tsinto.opencode/ - Copy this
package.jsoninto.opencode/package.jsonor merge the dependencies into your existing one - Run
bun install - If Bun blocks lifecycle scripts, run
bun pm trust glimpseui
Development
Install dependencies in this repo:
bun install
Typecheck:
bun run typecheck
Build publishable output:
bun run build
Current limitation
This plugin now uses morphdom for in-window DOM updates, but it still does not reproduce pi's token-by-token widget streaming. OpenCode does not currently expose the same tool-argument delta hooks, so widgets still render when the tool executes rather than progressively during argument streaming.
Credits
- Original reverse-engineering and
piimplementation:Michaelliv/pi-generative-ui - Native widget window runtime: Glimpse
License
MIT