feat(rpc): peer mesh layer with cross-peer relay (phases 1-2)#295
Open
feat(rpc): peer mesh layer with cross-peer relay (phases 1-2)#295
Conversation
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>
@vitejs/devtools
@vitejs/devtools-kit
@vitejs/devtools-rolldown
@vitejs/devtools-rpc
@vitejs/devtools-self-inspect
commit: |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, andws-server/ws-clientadapters under@vitejs/devtools-rpc/peer/*— and routes today's WebSocket flow through it with zero public API changes. Exposesrpc.meshon the client andrpcHost._meshon 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 broadcastsdirectory-deltaevents so every peer maintains a replica, andrpc.mesh.peer(target).call(method, args)transparently falls back to relaying through the server viadevtoolskit:internal:mesh:relaywhen no direct link exists. Subsequent phases addin-process/postmessage/broadcastchanneladapters and HMAC-signed origin identity.Linked Issues
Additional context
All existing tests pass unchanged, plus 22 new unit tests cover
PeerDirectoryand the relay fallback.pnpm lint/test/typecheck/buildall clean; playground smoke-tests end-to-end. Reviewers may want to focus onpackages/rpc/src/peer/{mesh,directory,link,types}.ts(the core),packages/core/src/node/rpc/internal/mesh/*.ts(the new relay/announce RPC functions), anddocs/kit/peer-mesh.md(naming/roadmap framing).🤖 Generated with Claude Code