Repository navigation
webapp, sdk/js: a browser joins the mesh from the web app at /node/ - #934
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the 'Agent Mesh Connect' web application, which allows users to enroll and manage their mesh node directly from a browser. The changes include the implementation of the web app (HTML, CSS, and JavaScript), backend integration in both 'agentmesh-one' and 'agentmesh-console' to serve the application at the '/node/' path, and a local relay mechanism to enable local MCP agents to interact with the mesh node. Additionally, the SDK has been updated to support state management via a new 'forget' method and 'NotEnrolledError', with comprehensive unit, integration, and E2E tests added to cover the new functionality. Documentation has been updated to reflect these changes. I have no feedback to provide as there were no review comments to assess.
a5c379b to
3599308
Compare
|
govulncheck is unrelated I will fix it separately, is the console-ui related? |
3599308 to
b896ef6
Compare
Yes, I just pushed a fix |
|
govulncheck, just leave agentmesh-one and console out of this PR and we land the webapp only , I'm unsure we want to create this tighly coupling between control plane and data plane |
A browser had no way onto a mesh: a member needed agentmesh-node, an SDK
program or the Android app. A new agentmesh-webapp binary serves Agent
Mesh Connect, a web app that runs the JavaScript SDK in the page. The
page knows no mesh. The person enters the control plane's address,
pastes the mesh://enroll code agentmesh-one prints (api.EnrollURI),
which carries it, or opens a <page>#server=<url>&token=<token> link
whose fragment never reaches a server. The address takes https, or http
to localhost or 127.0.0.1, the loopback hosts the page's CSP can name. A
browser belongs to one mesh at a time: once it joins, the address is
fixed until Reset device identity, and it follows the control plane the
saved credential names. Cancel once the control plane has answered still
enrolls the device, because the SDK has saved the credential, so the
address locks then too, and Join checks the lock again. The page keeps
its key in the browser's storage and joins through the router over
WebSocket or WebTransport. The dashboard shows the Node ID, peers and
routers, with Start, Stop, Unenroll and Reset device identity. A device
the mesh no longer accepts rejoins with a new pasted token and keeps its
Node ID. A browser that kept its key can always reset it, so a banned
one is never stuck.
When the control plane names a sign-in provider in /info and the
provider's discovery document answers the page with the same issuer, the
welcome and rejoin views also offer Sign in. They ask when the address
is entered and on every entry, so a provider the operator changes or
removes is followed without a reload. A #server=<url> link alone fills
in the address, so a mesh's Sign in shows at once. Leaving the view
cancels the lookup and the provider lookup gives up after 15 s, so a
silent provider never holds the token form or stays offered. The page
runs the authorization code flow with PKCE back to itself and enrolls
with the ID token through /register, which already checks bans and the
node role binding. It keeps no ID token: the credential renews by proof
of possession for the OIDC session, 90 days by default. The page trusts
a return only when its state matches the sign-in the tab started, so a
crafted ?error= or ?code= link shows the page's own words. The testnet
Dex lists https://{bananas,hub}.sam-mesh.dev/node/ as redirect URIs and
allows both origins.
On a computer, the Config tab can also offer the node's five caller
tools to a local agent such as Claude Code, so the agent calls the mesh
as this node. The goal is no configuration: the user copies a prompt
from the page and pastes it into the agent. The page offers the tools
through WebMCP, with @w3c/webmcp-polyfill 0.1.1 where the browser lacks
it, and the agent reaches the page through the MCP-B local relay
(@mcp-b/webmcp-local-relay 6.2.0), which accepts calls from any local
program. So agentmesh-webapp serves a launcher around the relay as one
file, sdk/agentmesh-relay.mjs beside the page, which needs only Node.js
22. It pairs once with a single-use token from the page and signs every
call with the key both sides derive. The page runs only calls signed by
a paired agent, once each even when copies arrive together, within 60 s,
and never a call signed before the page first offered its tools. The key
sits in a file only the user reads, as agentmesh-node's API token does.
The relay library raises the lockfile's ws from 8.21.3 to 8.23.0, the
version its ^8.22.1 range needs.
The SDK gains what any program needs to unenroll: NotEnrolledError,
AgentMesh.forget and StateStore.remove, and a session close that waits
for an in-flight credential refresh or control plane pull. A refresh now
saves the new biscuit as soon as the control plane answers, before it
asks for /keys, in the JavaScript and Python SDKs: the control plane
spends the old biscuit when it answers, so a page reloaded in between
kept only a spent one and was refused at its next refresh ("Biscuit
already rotated"), as CI showed. The SDK's five caller tools become
plain MeshTool values that the stdio MCP server registers. The WebMCP
registration, which runs only signed calls, and the pairing live in
sdk/js/webapp/ beside the launcher: the page bundle and the launcher
build from there, and npm does not ship them.
agentmesh-webapp serves the page at / and shares nothing with the other
components: agentmesh-one, the console and the control plane do not
serve it, and it has no flag that names a mesh. The control plane's mesh
routes already answer any origin. The page's CSP adds http to localhost
and 127.0.0.1, so a page reaches a control plane on the same computer.
It ships as an image and a Helm chart, charts/agentmesh-webapp, whose
optional Gateway follows the agentmesh chart's, and not in release
archives. The testnets mount it at /node/ on the existing host through
its own HTTPRoute, which strips the prefix, so they need no DNS record
or certificate of their own.
make all builds the SDK bundle the page imports, then the binaries; the
agentmesh-webapp image builds both. A binary built with make build only
still runs, says the app is missing and serves a page that says so.
Tests pin the page's state machine, pairing and every refused call
(unsigned, unpaired, stale, replayed, sent twice at once, altered,
signed before a reload), the registration refusing an unsigned call, one
agent per token when two pairing requests overlap, an agent's cancel
reaching the mesh call, close waiting for a refresh and a pull, the
handler's files and headers at / and nothing under /node/, the address
rules, #server= links and the one-mesh lock, and the chart's route and
probe. UI journeys serve the page from agentmesh-webapp on an origin
apart from the mesh, so every journey crosses origins. They enroll from
a link, rejoin after a reload, rejoin with a pasted token after a key
rotation, keep a banned browser able to reset, take the address from the
saved credential, keep it fixed after an unenroll and refuse a code for
another mesh, free the address after a reset, renew a lapsed credential,
and pair a local agent through the downloaded launcher. Against a mock
provider that checks the PKCE verifier, Sign in stays hidden until the
address is entered, without a provider, without CORS, or with a
discovery document for another issuer or without a token endpoint. It
refuses forged returns, gives up on a silent token endpoint after 15 s
and offers Sign in again for the same mesh, locks the address and shows
Reset when Cancel comes after the control plane answered, refuses at
Join a code for another mesh taken before that lock, lets a token join
at once while discovery hangs, drops a provider whose discovery stops
answering, follows the provider being removed and restored, joins,
renews without sending the ID token, joins again after a reload made
while /keys is held after a refresh, and rejoins with the same Node ID.
In both SDKs a process stopped while /keys is asked still refreshes from
what it saved. The two SDK tests and the journey step fail on the
previous save order.
b896ef6 to
318442d
Compare
Summary
A browser can now join a mesh. Before this, a member needed
agentmesh-node, an SDK program or the Android app.agentmesh-oneandagentmesh-consoleserve Agent Mesh Connect at/node/. It is a web app that runs the JavaScript SDK in the page. The browser becomes a normal member, with its own key, credential and Node ID.What a user can do
Join
<url>/node/#token=<token>link. The fragment never reaches a server.Run the node
Connect a local agent (computers only)
Sign in
The page shows Sign in only when:
/infonames an issuer, andstatematches the sign-in this tab started. A crafted?error=or?code=link shows only the page's own text.--oidc-session-ttlonagentmesh-control-plane).Local agent
sequenceDiagram participant Agent as Local agent participant Relay as Relay (Node.js, on the computer) participant Page as Web app (browser) Agent->>Relay: MCP tool call Relay->>Page: call signed with the paired key Page->>Page: verify signature, nonce, 60 s window Page-->>Relay: result Relay-->>Agent: result@w3c/webmcp-polyfill0.1.1 where the browser lacks it.@mcp-b/webmcp-local-relay6.2.0). That relay accepts calls from any local program, so the mesh serves a launcher around it: one file,/node/sdk/agentmesh-relay.mjs, which needs only Node.js 22.agentmesh-node's API token is.SDK changes (
sdk/js)NotEnrolledError,AgentMesh.forgetandStateStore.remove.close()waits for an in-flight credential refresh or control plane pull.MeshToolvalues, which the stdio MCP server registers.sdk/js/webapp/. npm does not ship them.wsfrom 8.21.3 to 8.23.0, which its^8.22.1range needs.Build and deploy
make allbuilds the SDK bundle the page imports, then the binaries. Releases and container images build both.make buildonly still runs. It says the app is missing and serves a page that says so./node/on the control plane's host to the console;https://{bananas,hub}.sam-mesh.dev/node/as redirect URIs and allows both origins.Evidence
Every new test was checked to fail without its fix.
node --test internal/webapp/model.test.mjscd sdk/js && npm test(Node 22)go test ./internal/webapp/ ./cmd/agentmesh-one/ ./cmd/agentmesh-console//node/mount in both binariesmake ui-testUI journeys in
tests/ui/app.spec.js:Merge Danger
Door: two-way. The app is new, under a new path,
/node/. Removing the mount or the route rule turns it off.Blast Radius: small.
/node/.