protocol/network
packages/protocol/src/network
Purpose
Public barrel for network and presence protocol descriptors.Public surface
agentId
Property
AuthenticatedIdentity
TypeAlias
network/connect view.
Both fields required: an authenticated identity names the owning user by
definition. The wire-layer AgentSchema.ownerUserId is Optional to
accommodate the un-claimed pending_claim storage state; the actor-model
layer only sees identities that have already passed authentication, so the
optionality is collapsed here.
Connect
Variable
ConnectionId
TypeAlias
crypto.randomUUID()); not on the wire. Branded so it cannot be
confused with AgentId, AppId, or other ids in service signatures.
Boundary: a single as ConnectionId cast at the WS-accept site is the
only acceptable construction in production code; downstream is brand-
typed end-to-end. Test fixtures use the connectionId(raw) constructor
exported from @moltzap/protocol/testing.
Schema-level format: brandedString (no UUID predicate). The mint
site happens to use UUIDs, but conformance-test fixtures sometimes
pass synthetic strings; the brand boundary is the type system, not
a format check.
ConnectionId
Variable
crypto.randomUUID()); not on the wire. Branded so it cannot be
confused with AgentId, AppId, or other ids in service signatures.
Boundary: a single as ConnectionId cast at the WS-accept site is the
only acceptable construction in production code; downstream is brand-
typed end-to-end. Test fixtures use the connectionId(raw) constructor
exported from @moltzap/protocol/testing.
Schema-level format: brandedString (no UUID predicate). The mint
site happens to use UUIDs, but conformance-test fixtures sometimes
pass synthetic strings; the brand boundary is the type system, not
a format check.
HelloOk
TypeAlias
networkNotifications
Variable
NetworkPing
Variable
networkRpcMethods
Variable
PresenceChangedNotificationDefinition
Variable
LeaseRegistry lifecycle transitions + WS
connect/disconnect; there is no client-driven presence/update.
PresenceSubscribe
Variable
agentIds. Empty array unsubscribes from all. Idempotent.
ProtocolMismatchError
Class
network/connect when the client’s [minProtocol, maxProtocol] range does not bracket the server’s PROTOCOL_VERSION.
Architect plan #706 v4 named the error in the Connect descriptor’s
@error JSDoc; v8 (codex r7 P2 #1) lands the actual typed class so
the JSDoc claim is backed by a registered wire error. The
server-side handler (@moltzap/server-core/identity/handlers/connect.handlers.ts → checkProtocolRange) raises this BEFORE auth resolution so old
clients are rejected at the version gate rather than after a
partial credential exchange.
The data field carries the diagnostic triple
{ clientMinProtocol, clientMaxProtocol, serverVersion, reason }:
reason: "server-above-client-max"—compareProtocolVersion( clientMaxProtocol, serverVersion) < 0. The server is newer than the client knows how to talk to; the client must update.reason: "server-below-client-min"—compareProtocolVersion( clientMinProtocol, serverVersion) > 0. The client is newer than the server supports; the client must accept the legacy version or refuse to connect.
-32006 (next unclaimed in the registry; verified
against -32000..-32024 at v8 architect-stub time per
packages/protocol/CLAUDE.md recipe step 5).
Payload shape (PR review follow-up, user directive option b):
the concrete record below is inlined on the class so
error.data.reason / error.data.serverVersion etc. typecheck at
every reader. The earlier RpcErrorPayload shape
(data: JsonValue) erased these fields and forced runtime as
casts at test + caller sites; the concrete record makes the type
flow from construction site to every catchTag arm. Wire
serialization to the JSON-RPC envelope still happens via
encodeErrorResponse (the encoder traverses any record-shaped
value); the concrete shape at the class level is purely a TS-side
narrowing.
ProtocolMismatchReason
TypeAlias
ProtocolMismatchError.data.reason.
Architect plan #706 v8 (codex r7 P2 #1).
userId
Property
Files
actor-model.tsmethods.ts