@fungi.computer/capnweb

中文文档
0.12.0-fungi.0发布于 2026/11/08MITTypeScriptESM + CJS零依赖近 30 天下载 1.5万

Fork of capnweb 0.12.0 with corrected tuple declarations and idle stream cancellation

原始使用文档
文档目录5 节
  1. Fungi fork
  2. Install
  3. Example
  4. Where it's used
  5. License

@fungi.computer/capnweb

Cap'n Web is a JavaScript-native, object-capability RPC system: no schemas, no code generation, human-readable (JSON-based) wire format, and support for bidirectional calling, passing functions/objects by reference, and promise pipelining (chaining dependent calls into a single network round trip). It works over HTTP, WebSocket, and postMessage(), in browsers, Cloudflare Workers, Node.js, Bun, and Deno.

Fungi fork

This package is a Fungi fork of cloudflare/capnweb at the 0.12.0 release (commit 7702075). It carries two fixes:

  • In src/types.ts, UnstubifyInner spreads a tuple tail through UnstubifyAll<Tail> instead of Unstubify<Tail>. Unstubify<Tail> is a union that includes Promise, so the upstream declarations fail with TS2574 ("A rest element type must be an array type") under skipLibCheck: false and lose tuple parameter types.
  • In src/streams.ts and src/rpc.ts, exported stubs report breakage through the existing onBroken callback and broken-reference reject message. Native writable-stream hooks now report writer failure through that machinery. Writable proxies observe that callback, so cancelling a received readable interrupts an idle sender's pipe without waiting for another chunk. This does not expose writer properties or add wire messages, peer negotiation or a fallback. Upstream 0.12.0 and Fungi's 0.6.0-era peers keep streaming normally with their previous cancellation latency; immediate idle cancellation requires the fix at both ends. Import entries release their callback registrations when disposed, including normally completed pipes; session abort notifies a snapshot of live observers so one observer's cleanup cannot suppress the others.

Drop this fork when upstream Cap'n Web includes both fixes. Agent and inbox transport cancellation is exercised through actual MessagePort RPC and native HTTP in packages/agar/src/agents-rpc.test.ts. pnpm test exercises mixed-peer streaming against maintained upstream [email protected], a test-only dependency, and resource release in a live session plus complete observer delivery on abort. Its resource law uses Node's maintained V8 object counter rather than private RPC tables.

Install

npm install @fungi.computer/capnweb

Example

A client:

import { newWebSocketRpcSession } from "@fungi.computer/capnweb";

// One-line setup.
let api = newWebSocketRpcSession("wss://example.com/api");

// Call a method on the server!
let result = await api.hello("World");

console.log(result);

A server:

import { RpcTarget, newWorkersRpcResponse } from "@fungi.computer/capnweb";

// This is the server implementation.
class MyApiServer extends RpcTarget {
  hello(name) {
    return `Hello, ${name}!`;
  }
}

// Standard Cloudflare Workers HTTP handler.
//
// (Node, Deno, Bun and other runtimes are supported too.)
export default {
  fetch(request, env, ctx) {
    let url = new URL(request.url);

    if (url.pathname === "/api") {
      return newWorkersRpcResponse(request, new MyApiServer());
    }

    return new Response("Not found", { status: 404 });
  },
};

Three dependent calls, one round trip:

using api = newHttpBatchRpcSession<Api>("https://example.com/api");

// No awaits, so no round trips yet.
using authed = api.authenticate(apiToken);
let friendIds = authed.getFriendIds();

// One await. One round trip. Everything above travelled together.
let friends = await friendIds.map((id) => api.getUserProfile(id));

For the full API, transports, and server-runtime guides, see the upstream documentation site and the upstream README.

Where it's used

Oyster, the Hub and App SDK use this fork for browser/frame RPC and Agent/inbox Request and Response bodies. The Computer client and Cordyceps's bundled computerd also use it for WebSocket and HTTP-batch RPC, including file/Blob and execution-event streams. App Releases, hosts, CLI bundles and Computer images can be built independently; normal streaming must remain valid with their upstream 0.12.0-era peers.

License

MIT. This package carries the upstream Cloudflare copyright and license unchanged — see LICENSE.txt and NOTICE.

版本与发布记录

@fungi.computer/capnweb 共发布 3 个版本,首次发布于 2026/10/15;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.12.0-fungi.0latest2026/11/088 天前
0.12.02026/10/151 个月前
0.0.0-stage2026/10/151 个月前

关于 @fungi.computer/capnweb 的常见问题

@fungi.computer/capnweb 是什么?

Fork of capnweb 0.12.0 with corrected tuple declarations and idle stream cancellation

如何安装 @fungi.computer/capnweb?

在项目目录运行 npm install @fungi.computer/capnweb,或使用 pnpm add / yarn add / bun add。

@fungi.computer/capnweb 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fungi.computer/capnweb 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@fungi.computer/capnweb 可以商用吗?

@fungi.computer/capnweb 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fungi.computer/capnweb 的下载量有多少?

根据 npm 官方下载统计,@fungi.computer/capnweb 在 2026/10/16 – 2026/11/14 这 30 天内被下载 14,851 次,日均约 495 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fungi.computer/capnweb 还在维护吗?

最新版本 0.12.0-fungi.0 发布于 2026/11/08(8 天前);至今共发布 3 个版本,其中过去 12 个月发布了 3 个;首次发布于 2026/10/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。