Skip to main content

server-core/socket

packages/server/src/socket

Purpose

Server WebSocket connection/session runtime primitives.

Public surface

AgentConnection

Interface
Re-exports the public API from current module.

AgentContext

Class
The principal context stored on an authenticated socket connection. Every gated method’s requires head selects this arm.

agentContextFrom

Function
Mint an AgentContext from authenticator fields. The agent_status SQL enum constrains stored values to AgentStatus, but the DB driver types it as string, so any other value is an impossible-state defect. Returns: The agent context from result.

AgentStatus

TypeAlias
Closed agent lifecycle states. Mirrors core-schema.sql → CREATE TYPE agent_status AS ENUM (...). The closed union makes the active-agent check exhaustive — adding a state forces every consumer switch to handle it.

Connection

TypeAlias
The two-arm connection state — the connections map’s only entry shape.

ConnectionManager

Class
Implements connection manager.

connectionManagerLive

Variable
Provides the connection manager live runtime value.

ConnectionManagerTag

Class
Implements connection manager tag.

ConnectionTag

Class
Implements connection tag.

Originator

TypeAlias
The per-connection reverse RpcClient<ReverseRpcGroup> the server fires callbacks/notifications through. Constructed by protocol MoltZapServer during socket accept and passed to ConnectionManager.addUnauthenticated as a primitive-equivalent parameter.

PrincipalBoundaryCanaries

TypeAlias
Compile-time assertions for the principal and boot-failure boundaries.

principalCanaryRefs

Variable
Provides the principal canary refs runtime value.

TransitionOutcome

TypeAlias
Outcome of ConnectionManager.authenticate’s atomic transition. The success arm carries the minted connection so the Connect handler’s Match.value(outcome).pipe(Match.when({ kind: "ok-agent" }, ...)) narrows authed structurally — no as AgentConnection cast.

UnauthenticatedConnection

Interface
Re-exports the public API from current module.

WebSocketRef

Interface
The per-connection socket handle registered with ConnectionManager.

Files

  • connection.ts
  • context.ts
  • layer.ts
  • principal.types-check.ts