Skip to content

feat(rpc): peer mesh layer with cross-peer relay (phases 1-2)#295

Open
antfu wants to merge 2 commits intomainfrom
antfu/peer-mesh
Open

feat(rpc): peer mesh layer with cross-peer relay (phases 1-2)#295
antfu wants to merge 2 commits intomainfrom
antfu/peer-mesh

Conversation

@antfu
Copy link
Copy Markdown
Member

@antfu antfu commented Apr 21, 2026

Description

Introduces a pluggable peer/transport abstraction beneath the existing RPC layer to enable any-to-any communication (iframe↔parent for DOM access, Nitro↔devtools-server, arbitrary peer-to-peer). The branch delivers the first two phases of a phased rollout documented at docs/kit/peer-mesh.md.

Phase 1 lands the foundation — PeerMesh, PeerDirectory, Link, and ws-server/ws-client adapters under @vitejs/devtools-rpc/peer/* — and routes today's WebSocket flow through it with zero public API changes. Exposes rpc.mesh on the client and rpcHost._mesh on the server for inspection.

Phase 2 lights up cross-peer calls: each peer announces its role/capabilities to the server via devtoolskit:internal:peer:announce, the server broadcasts directory-delta events so every peer maintains a replica, and rpc.mesh.peer(target).call(method, args) transparently falls back to relaying through the server via devtoolskit:internal:mesh:relay when no direct link exists. Subsequent phases add in-process/postmessage/broadcastchannel adapters and HMAC-signed origin identity.

Linked Issues

Additional context

All existing tests pass unchanged, plus 22 new unit tests cover PeerDirectory and the relay fallback. pnpm lint/test/typecheck/build all clean; playground smoke-tests end-to-end. Reviewers may want to focus on packages/rpc/src/peer/{mesh,directory,link,types}.ts (the core), packages/core/src/node/rpc/internal/mesh/*.ts (the new relay/announce RPC functions), and docs/kit/peer-mesh.md (naming/roadmap framing).

🤖 Generated with Claude Code

Add a pluggable peer/transport abstraction beneath the existing RPC layer
to enable any-to-any communication (iframe↔parent, Nitro↔server, etc.) in
upcoming phases. Phase 1 lands the foundation — PeerMesh, PeerDirectory,
Link, and ws-server/ws-client adapters — and routes today's WebSocket flow
through it with no public API changes. Adds `rpc.mesh` / `rpcHost._mesh`
for inspection, plus a docs page describing the model and roadmap.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 21, 2026

Open in StackBlitz

@vitejs/devtools

npm i https://pkg.pr.new/@vitejs/devtools@295

@vitejs/devtools-kit

npm i https://pkg.pr.new/@vitejs/devtools-kit@295

@vitejs/devtools-rolldown

npm i https://pkg.pr.new/@vitejs/devtools-rolldown@295

@vitejs/devtools-rpc

npm i https://pkg.pr.new/@vitejs/devtools-rpc@295

@vitejs/devtools-self-inspect

npm i https://pkg.pr.new/@vitejs/devtools-self-inspect@295

commit: ca6efe4

Lights up any-to-any messaging on top of the phase 1 mesh: peers announce
their role/capabilities to the server, the server pushes directory-delta
events so every peer maintains a replica, and `rpc.mesh.peer(target).call(
method, args)` now falls back to relaying through the server when there is
no direct link. Two new internal RPC functions carry the relay traffic —
`devtoolskit:internal:mesh:relay` (awaited) and `:relay-event` (fire-and-
forget) — plus `devtoolskit:internal:peer:announce` / `:directory-delta`
for directory sync. Adds unit tests for `PeerDirectory` and the relay
fallback path (22 new tests), updates the docs to cover current capability
and the Phase 2 API. Origin identity is not yet signed across hops — that
remains a phase 5 item.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@antfu antfu changed the title feat(rpc): introduce peer mesh layer (phase 1) feat(rpc): peer mesh layer with cross-peer relay (phases 1-2) Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant