Vercel 开源 vgpu:面向 AI Agent 的 TypeScript
Vercel AI Open-Sources vgpu: A TypeScript WebGPU Library for AI Agent Shaders
Shaders are still the hardest thing to ship on a normal web team. WebGPU gives you the hardware, then hands you adapters, bind group layouts, and pipeline descriptors before a single pixel moves. Vercel spent that cost internally building the shaders on vercel.com, and has now open-sourced the result. vgpu is a TypeScript library that treats .wgsl files as importable modules, exposes one Gpu context, and runs the same shader in a browser canvas, in headless Node.js, and in a CI snapshot test.
着色器仍然是普通网页团队最难交付的部分。WebGPU 提供了硬件,但在渲染出第一个像素之前,就交给你适配器、绑定组布局和管线描述符。Vercel 在内部为 vercel.com 构建着色器时承担了这些成本,现在已将成果开源。vgpu 是一个 TypeScript 库,将 .wgsl 文件视为可导入模块,暴露一个 Gpu 上下文,并在浏览器画布、无头 Node.js 和 CI 快照测试中运行相同的着色器。
Is it deployable?
它可以部署吗?
Yes,vgpu is MIT licensed and published to npm, so pnpm add vgpu is the entire acquisition path. It is a library, not a hosted service, so there is no account, quota, or inference bill.
是的,vgpu 采用 MIT 许可证并发布到 npm,因此 pnpm add vgpu 就是完整的获取路径。它是一个库,而非托管服务,所以没有账户、配额或推理费用。
Interactive explainer — use the arrows, dots, sliders and toggles. Six steps.
交互式讲解——使用箭头、圆点、滑块和开关。共六步。
One context, no hidden global state
单一上下文,无隐藏全局状态
init acquires an adapter and device and returns a single Gpu handle. Everything else hangs off it. The browser quick start in the README is four lines:
init 获取适配器和设备,并返回一个 Gpu 句柄。其他一切都挂靠在其上。README 中的浏览器快速入门只有四行代码:
const gpu = await init();
const surface = gpu.surface(canvas, { dpr: [1, 2] });
const wave = gpu.effect(WAVE_WGSL, { set: { speed: 2 } });
gpu.frame.loop(() => { wave.set({ time: gpu.time }); wave.draw(); });const gpu = await init();
const surface = gpu.surface(canvas, { dpr: [1, 2] });
const wave = gpu.effect(WAVE_WGSL, { set: { speed: 2 } });
gpu.frame.loop(() => { wave.set({ time: gpu.time }); wave.draw(); });surface wraps the canvas and clamps device pixel ratio between 1 and 2. effect compiles WGSL into a fullscreen effect whose uniforms are addressed by their WGSL names through set . Frames are explicit: passes, clears, and draws are calls, never implicit scene-graph state.
surface 包装画布并将设备像素比限制在 1 到 2 之间。effect 将 WGSL 编译为全屏效果,其 uniforms 通过 set 以 WGSL 名称寻址。帧是显式的:pass、clear 和 draw 都是调用,而非隐式场景图状态。
WGSL as a Module System
WGSL 作为模块系统
The differentiator is shader tooling. .wgsl files import and export like TypeScript modules. vgpu resolves the module graph, reflects bindings, removes unused declarations, and emits compact shader source at build time. That removes the hand-written binding declarations that normally drift out of sync with the shader. The README states a complete fullscreen effect ships in 25 KB gzipped, and that the budget is enforced in CI.
差异化在于着色器工具。.wgsl 文件像 TypeScript 模块一样导入和导出。vgpu 解析模块图、反射绑定、移除未使用的声明,并在构建时生成紧凑的着色器源码。这消除了通常与着色器不同步的手写绑定声明。README 声明一个完整的全屏效果以 25 KB gzip 大小交付,并且该预算在 CI 中强制执行。
Three Runtimes, One API
三个运行时,一个 API
The package exposes subpath exports for vgpu, vgpu/node, vgpu/mock, vgpu/scene, vgpu/client, and vgpu/core. The Node path is Dawn-backed and renders offscreen:
该包为 vgpu、vgpu/node、vgpu/mock、vgpu/scene、vgpu/client 和 vgpu/core 暴露子路径导出。Node 路径由 Dawn 支持并渲染离屏:
const target = gpu.target({ size: [256, 256], format: "rgba8unorm" });
const pixels = await target.read();const target = gpu.target({ size: [256, 256], format: "rgba8unorm" });
const pixels = await target.read();That is what makes CI rendering practical. pixelmatch and pngjs are direct dependencies of the published package, consistent with the documented workflow where CI compiles the shader, renders a headless frame, and compares the snapshot. The mock adapter is deterministic and exists for tests that should not touch a GPU at all.
这就是使 CI 渲染变得实用的原因。pixelmatch 和 pngjs 是发布包的直接依赖,与文档化的工作流程一致,即 CI 编译着色器、渲染无头帧并比较快照。mock 适配器是确定性的,适用于不应接触 GPU 的测试。
The Agent Surface
代理表面
Vercel calls this an agent-first library, and the packaging backs that up. The package ships a vgpu binary, so npx vgpu docs, npx vgpu examples, and npx vgpu check work without a global install. vgpu.sh publishes agents.md, llms.txt, and a full documentation export, plus a tokenless examples discovery API with an OpenAPI 3.1 description. A hosted read-only MCP server is available at vgpu.sh/api/mcp, and @modelcontextprotocol/server is a direct dependency. There is also an installable agent skill in the repo.
Vercel 称其为代理优先的库,其打包方式也印证了这一点。该包附带一个 vgpu 二进制文件,因此无需全局安装即可运行 npx vgpu docs、npx vgpu examples 和 npx vgpu check。vgpu.sh 发布了 agents.md、llms.txt 和完整的文档导出,以及一个无令牌的示例发现 API,并附有 OpenAPI 3.1 描述。托管只读 MCP 服务器可在 vgpu.sh/api/mcp 上使用,@modelcontextprotocol/server 是直接依赖项。仓库中还有一个可安装的代理技能。
Comparison
比较
Tap any column header to spotlight one library. Scroll the table sideways on narrow screens.
点击任意列标题可突出显示一个库。在窄屏上可横向滚动表格。
Key Takeaways
关键要点
- Vercel open-sourced vgpu, the WebGPU library it built to ship shaders on vercel.com.
- One API surface runs in the browser, in headless Node.js via Dawn, and in a deterministic mock.
- .wgsl files import and export like TypeScript modules, with reflection for bindings and layouts.
- A complete fullscreen effect ships in 25 KB gzipped, a budget the repo says CI enforces.
- MIT licensed, on npm at v0.3.1, with a CLI, llms.txt, and a hosted read-only MCP endpoint.
- Vercel 开源了 vgpu,这是其为在 vercel.com 上发布着色器而构建的 WebGPU 库。
- 一个 API 接口可在浏览器、通过 Dawn 的无头 Node.js 以及确定性模拟中运行。
- .wgsl 文件像 TypeScript 模块一样导入和导出,并支持绑定和布局的反射。
- 一个完整的全屏效果以 25 KB gzip 压缩包发布,仓库称 CI 强制执行此预算。
- MIT 许可,npm 上版本为 v0.3.1,附带 CLI、llms.txt 和托管的只读 MCP 端点。
Check out the GitHub Repo, Docs and Examples, and the npm package. Also, feel free to follow us on Twitter and don’t forget to join our 150k+ML SubReddit and Subscribe to our Newsletter. Wait! are you on telegram? now you can join us on telegram as well.
查看 GitHub 仓库、文档和示例,以及 npm 包。另外,欢迎在 Twitter 上关注我们,别忘了加入我们的 150k+ ML SubReddit 并订阅我们的通讯。等等!你在 Telegram 上吗?现在你也可以在 Telegram 上加入我们。
The post Vercel AI Open-Sources vgpu: A TypeScript WebGPU Library for AI Agent Shaders appeared first on MarkTechPost.
文章《Vercel AI 开源 vgpu:用于 AI 代理着色器的 TypeScript WebGPU 库》首发于 MarkTechPost。
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力