Skip to content

Graphorin API reference v0.1.0


Graphorin API reference / @graphorin/protocol / server-message

server-message

ServerMessage — discriminated union of every frame a Graphorin server may push to a client. Three families share the channel:

  1. RPC responses ({ jsonrpc, id, result | error }) — correlate with a previously-issued client request.
  2. Typed push events ({ kind: 'event', subject, type, payload, eventId }) — the streaming-first data plane; consumers ignore unknown type strings per the agent-event extensibility convention.
  3. Asynchronous server frames ({ kind: 'lifecycle' | 'error' | 'pong' | 'subscribed' | 'unsubscribed' | 'replay-marker' }) — server-initiated messages that do not correlate with a single client RPC id.

Every frame carries the v: '1' literal so future revisions can negotiate forward-compatible additions without a subprotocol bump.

Type Aliases

Type AliasDescription
ServerErrorFrame-
ServerEventFrameConvenience type aliases for callers that want to reference an individual variant without z.infer<typeof X>.
ServerLifecycleFrame-
ServerMessageInferred TypeScript union for the ServerMessage discriminator.
ServerPongFrame-
ServerReplayMarkerFrame-
ServerRpcFailure-
ServerRpcSuccess-
ServerSubscribedFrame-
ServerUnsubscribedFrame-

Variables

VariableDescription
RPC_ERROR_CODESStable JSON-RPC error code catalogue used by the server when surfacing routine failures (per JSON-RPC 2.0 § 5.1 + Graphorin extensions). Application-level errors use codes in the implementation-defined range (-32000-32099).
ServerMessageSchemaZod schema for every legal server → client frame. Validation runs twice in the server pipeline: first when a route handler enqueues the frame onto the dispatcher's send queue (so a malformed frame never escapes the process), then again on the client side to defend against protocol drift.

Functions

FunctionDescription
isErrorFrame-
isEventFrameType guard helpers, one per discriminator. The narrow over the ServerMessage union without forcing consumers to memorize the exact field names.
isLifecycleFrame-
isPongFrame-
isReplayMarkerFrame-
isRpcFailure-
isRpcSuccess-
isSubscribedFrame-
isUnsubscribedFrame-