The relay and the registry are separate Cloudflare Workers. You can run the relay without the registry.
You need Node 22+, a Cloudflare account and this repo:
git clone https://github.com/blitzdotdev/agent-socket
cd agent-socket
npm installThe relay is a Worker with one Durable Object class and a rate-limit binding. It keeps each session in Durable Object storage while it lasts, and for up to 24 hours after its app drops; see protocol.md.
npm run dev # wrangler dev on http://localhost:8787Extra arguments go to wrangler dev, e.g. npm run dev -- --port 9000 --ip 0.0.0.0. To turn on the /_debug/* endpoints, copy relay/.dev.vars.example to relay/.dev.vars.
cd relay
npx wrangler login
npx wrangler deploy --env=""The relay is then at https://agent-socket-relay.<your-subdomain>.workers.dev. --env="" selects the top level of relay/wrangler.jsonc. Without it wrangler deploys the same thing but warns, because the file also has a production environment. That environment holds the routes of the hosted relay at agentsocket.dev; don't deploy it.
For a non-interactive deploy, set CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID instead of running wrangler login (see .env.example for the token scopes).
Add a route at the top level of relay/wrangler.jsonc. The zone must be on the same Cloudflare account.
Then deploy as above.
ratelimits[0].namespace_id(48001) must be unique within your Cloudflare account. Change it if another Worker already uses that number.- Settings are in
vars:MAX_SYNC_TOOL_MS,HEARTBEAT_TIMEOUT_MS,RESUME_GRACE_MS(how long a dropped session is held, 24 h by default). See relay/README.md. - Sessions are kept in Durable Object storage while they last, so the relay bills for storage and an alarm per session as well as requests; an idle session hibernates and costs no duration. Each session's storage is deleted when it ends.
- Never set
DEBUGinwrangler.jsonc. It enables endpoints that close other people's sessions. - The relay does not know its own hostname. Minted links use the base URL the app connected with.
- SDK:
connect({ baseUrl: "https://relay.example.com", ... }). - Chrome extension: popup, Settings, relay URL.
Check it:
curl -i https://relay.example.com/v1/t/notarealtoken00000/agents.md # 404 not_found
curl -i https://relay.example.com/v1/_ws # 400 protocol_errorThe registry (registry/) serves shared per-site tool profiles to the Chrome extension and takes submissions that an admin reviews. It is a Worker plus a D1 database, built with teenybase, and its admin pages must sit behind Cloudflare Access.
The full steps are in registry/README.md under "Deploy". In short:
- In
registry/wrangler.jsonc, change theroutespattern to your domain and make sure the rate-limitnamespace_idis unique in your account.workers_devstays off, so/adminis only reachable through Access. - Create a Cloudflare Access application for
<your domain>/adminand put its team domain and audience tag invars.ACCESS_TEAM_DOMAINandvars.ACCESS_AUD. - Put
JWT_SECRET,ADMIN_JWT_SECRET,ADMIN_SERVICE_TOKENandIP_HASH_SECRETinregistry/.prod.vars. - From
registry/:npx teeny deploy --remote(creates the D1 database, applies migrations, deploys), thennpx teeny secrets --remote --upload. - Check
curl https://<your domain>/v1/sites.