Skip to main content

protocol/socket

packages/protocol/src/socket

Purpose

Socket lifecycle surface for protocol-owned clients and server. Owns the concrete MoltZap agent client, app client, server socket lifecycle, connection identifiers, close-info extraction, and socket-local lifecycle helpers used by testing and server wiring.

Public surface

AgentClientOptions

Interface
Configures agent client.

classifyCloseCause

Function
Executes the classify close cause operation. Returns: The classify close cause result.

ClientConnectError

TypeAlias
Represents client connect error conditions.

ClientDefinitionError

TypeAlias
Represents client definition error conditions.

ClientDefinitionPayload

TypeAlias
Represents client definition payload values.

ClientDefinitionSuccess

TypeAlias
Represents client definition success values.

ClientLifecycleOptions

Interface
Configures client lifecycle.

ClientRpcDefinition

Interface
Describes client rpc definition.

CloseInfo

Interface
Describes close info.

CloseKind

TypeAlias
Represents close kind values.

connectionId

Variable
Validates and decodes connection id values.

ConnectionId

TypeAlias
Server-internal WebSocket connection identifier. Minted at WS accept (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: branded string (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.

connectionIdSchema

Variable
Validates and decodes connection id values.

ConnectResult

TypeAlias
Represents the result of connect.

DEFAULT_ABNORMAL_CLOSE

Variable
Default value for abnormal close.

DEFAULT_GRACEFUL_CLOSE

Variable
Default value for graceful close.

extractCloseInfo

Function
Executes the extract close info operation. Returns: The extract close info result.

MoltZapAgentClient

Class
Implements molt zap agent client.

MoltZapServer

Class
Implements molt zap server.

MoltZapServerOptions

Interface
Configures molt zap server.

MoltZapServerSession

Interface
Describes molt zap server session.

newConnectionId

Function
Provides the new connection id runtime value. Returns: The new connection id result.

openProtocolAgentClientSocket

Function
Provides the open protocol agent client socket runtime value. Returns: The open protocol agent client socket result.

ProtocolClientLifecycle

Class
Serializes connection generations through one controller. Each generation has one scoped owner that acquires the socket, runs its reader, and reports OwnerDone only after every session finalizer has completed. The start gate prevents an acquired reader from running unless its generation is still current.

ReverseCallError

TypeAlias
Represents reverse call error conditions.

ReverseClient

Interface
Describes reverse client.

RPC_TIMEOUT_MS

Variable
Provides the rpc timeout ms runtime value.

RpcCallOptions

Interface
Configures rpc call.

ServerSocketWrite

TypeAlias
Represents server socket write values.

Files

  • agent-client.ts
  • close-info.ts
  • connection.ts
  • lifecycle.ts
  • server.ts