Mock agents server
The scripted agents server on 127.0.0.1:3068: protocol endpoints, envelope checks, scripted turns, and the /dev control endpoints.

The mock agents server speaks the real agents server protocol, signed CBOR over HTTP and JSON frames over WebSocket, with scripted replies instead of a model. It lets the Agents UI be tested for streaming, tools, plans, waiting runs and reconnects without spending a model call.

Files

File

Role

tools/mock-agents/server.ts

The server. Ported from the archived React Native app's dev/mock-agents-server.ts. Binds on import

tools/mock-agents/settings.ts

MOCK_AGENTS_URL = 'http://127.0.0.1:3068', kept in sync with the same constant in src/agents/sources.ts

tools/mock-agents/generate-vector.ts

Regenerates src/agents/__tests__/envelope-vector.json by executing the original client's signing functions

Run it alone with bun tools/mock-agents/server.ts; the test server imports it at startup. It binds loopback only and keeps no persistent state.

Port note

The server binds 3068. Comments in tools/test-server/index.ts and one net.fetch grant in app.ts still say 3058, and agents.test.ts uses 3058 only as an example URL for pure functions. Those references are stale; nothing listens on 3058.

Protocol endpoints

Path

Behaviour

POST /api/message, /agents/api/message, /hm/api/agents/message

A signed AgentsAction envelope in CBOR. The reply is CBOR {_: "<Name>Response", ...} or {_: "Error", message}, always HTTP 200

GET /agents/api/health, /api/health, /hm/api/agents/health

{status: "ok", version: "mock", webTools, codeExec: false, ...}

WebSocket /agents/ws, /hm/api/agents/ws

The first frame is a signed envelope whose action carries key and optional afterSeq. The server answers connected, subscribed, then replays: session events with seq > afterSeq for sessions/<id>, every run of the tree for runs/<rootRunId>

Both path layouts exist because the app resolves a standalone layout and a site mounted layout, see Agents: signed action envelope and endpoints.

Envelope verification

accountFromEnvelope (server.ts L536-L548) requires:

    signer is a 34 byte Ed25519 principal (0xed 0x01 prefix).

    type is AgentsAction and protocol is 3.

    The signature verifies over the envelope encoded with a zero filled 64 byte sig.

    account equals signer: "Fixture requires a direct signer", so delegation is not accepted.

    action.ts is within 300000 ms (5 minutes) of the server's real clock, else Stale request timestamp.

Implemented actions

handleAction (server.ts L308-L523) implements ListAgents, GetAgent, ListModelProviders, SetSecret, SetModelProvider, CreateAgent, ListProviderModels, ListSessions (cursor paging, default limit 50), CreateSession, GetSession, UpdateSession, MessageSession, RetrySession, ListRuns, GetRun, GetRunJournal, SignalRun, CancelRun, StopSession, DeleteSession, and empty lists for ListAgentInvites, ListAgentTriggers, ListAgentTools, ListSigningIdentities. Anything else answers Mock server does not implement <name>.

Scripted turns

MessageSession returns at once and plays the turn over the socket. scriptFor picks a script by keyword in the user's text (server.ts L119-L125):

Keyword

Script

plan

A three step plan updated every 700 ms; the third step is marked resolvedBy: "runtime", and settledAt is stamped before the closing reply

search, read, tool

A read tool call that stays pending 900 ms, then a result and a Markdown answer

ask me, approve

The run parks as waiting with answerWith: "approved" until SignalRun

anything else

A streamed Markdown reply

Assistant text streams as appendPartial frames, one word every 45 ms, followed by one durable append event.

Control endpoints

All are POST on port 3068. From a Contract test they are written as request POST "/dev/..." { }; the driver sends them to 4790 and the test server forwards /dev/*.

Path

Body

Effect

/dev/reset

none

Clears everything and seeds session mock-session ("A place to think") with 17 events

/dev/parity

none

Seeds fixtures: parity-parent with a run tree of three children, parity-child, parity-trigger (trigger context and structured parts), parity-failed (status error), parity-timer and parity-budget-pause (waiting runs)

/dev/complete-child

none

Marks run parity-child-run succeeded

/dev/seed-sessions

none

Adds 55 older sessions, enough for a second page

/dev/reject-next-message

none

The next MessageSession answers an error

/dev/disconnect

none

Closes every socket subscribed to sessions/mock-session, then appends a message the client must recover on reconnect

/dev/clock-checkpoint

none

Records subscription count, last read timestamp and read count

/dev/assert-fresh-reads

none

200 only if no new subscription was opened, at least one read arrived, and the read timestamp advanced by at least 180000 ms; else 409

/dev/assert-provider

{"name", "type", "baseUrl"}

200 only if a provider saved through SetModelProvider matches; else 409

Who uses it

    agents.test.contract: all 15 tests. The file opens at /agents-test, taps agents-test-key to use a fixture signer, and waits with clock until state ... within 15000 because the socket runs on real time. The fixture signer is refused for any server other than MOCK_AGENTS_URL (sources.ts L29-L33).

    The Bun agents tests do not start this server; they stub fetch and feed frames to the stream mapper directly.

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime

Attributes
name
Mock agents server
summary
The scripted agents server on 127.0.0.1:3068: protocol endpoints, envelope checks, scripted turns, and the /dev control endpoints.