Skip to content

Protocol

Defined in: src/protocol.ts:25

Fluent builder for defining RPC methods. Register unary, producer, and exchange methods, then pass to VgiRpcServer.

new Protocol(name, options?): Protocol;

Defined in: src/protocol.ts:40

Parameter Type
name string
options? { protocolVersion?: string; }
options.protocolVersion? string

Protocol

readonly name: string;

Defined in: src/protocol.ts:27

Service / protocol name, exposed to clients via introspection.


readonly protocolVersion: string;

Defined in: src/protocol.ts:35

Application protocol surface version. When non-empty, the server enforces exact major+minor match (patch ignored) against every request’s vgi_rpc.protocol_version metadata; clients bound to this Protocol emit the value on every request. Format: canonical semver MAJOR.MINOR.PATCH. Mirrors Python’s Protocol.protocol_version ClassVar.


readonly protocolVersionParts: readonly [number, number, number] | null;

Defined in: src/protocol.ts:37

Parsed semver tuple; null when protocolVersion is unset.

exchange<S>(name, config): this;

Defined in: src/protocol.ts:130

Register an exchange (bidirectional-streaming) method. The generic S is inferred from the init return type and threaded to exchange.

Type Parameter
S
Parameter Type
name string
config { defaults?: Record<string, any>; doc?: string; exchange: ExchangeFn<S>; headerInit?: HeaderInit; headerSchema?: SchemaLike; init: ExchangeInit<S>; inputSchema: SchemaLike; onCancel?: OnCancelFn<S>; outputSchema: SchemaLike; params: SchemaLike; paramTypes?: Record<string, string>; }
config.defaults? Record<string, any>
config.doc? string
config.exchange ExchangeFn<S>
config.headerInit? HeaderInit
config.headerSchema? SchemaLike
config.init ExchangeInit<S>
config.inputSchema SchemaLike
config.onCancel? OnCancelFn<S>
config.outputSchema SchemaLike
config.params SchemaLike
config.paramTypes? Record<string, string>

this


getMethod(name):
| MethodDefinition
| undefined;

Defined in: src/protocol.ts:174

Look up a single method without copying the whole map — for the per-request dispatch path. Callers must not mutate the returned value.

Parameter Type
name string

| MethodDefinition | undefined


getMethods(): Map<string, MethodDefinition>;

Defined in: src/protocol.ts:168

Snapshot of the registered methods, keyed by method name. Returns a copy, so mutating it does not affect the protocol.

Map<string, MethodDefinition>


methodNames(): string[];

Defined in: src/protocol.ts:179

Registered method names, sorted — for diagnostics/error messages only.

string[]


producer<S>(name, config): this;

Defined in: src/protocol.ts:91

Register a producer (server-streaming) method. The generic S is inferred from the init return type and threaded to produce.

Type Parameter
S
Parameter Type
name string
config { defaults?: Record<string, any>; doc?: string; headerInit?: HeaderInit; headerSchema?: SchemaLike; init: ProducerInit<S>; onCancel?: OnCancelFn<S>; outputSchema: SchemaLike; params: SchemaLike; paramTypes?: Record<string, string>; produce: ProducerFn<S>; }
config.defaults? Record<string, any>
config.doc? string
config.headerInit? HeaderInit
config.headerSchema? SchemaLike
config.init ProducerInit<S>
config.onCancel? OnCancelFn<S>
config.outputSchema SchemaLike
config.params SchemaLike
config.paramTypes? Record<string, string>
config.produce ProducerFn<S>

this


unary(name, config): this;

Defined in: src/protocol.ts:62

Register a unary (request-response) method.

Parameter Type Description
name string Method name exposed to clients
config { defaults?: Record<string, any>; doc?: string; handler: UnaryHandler; params: SchemaLike; paramTypes?: Record<string, string>; result: SchemaLike; } -
config.defaults? Record<string, any> Optional default parameter values
config.doc? string Optional documentation string
config.handler UnaryHandler Async function receiving params and returning result values
config.params SchemaLike Parameter schema (SchemaLike)
config.paramTypes? Record<string, string> Optional parameter type hints (inferred from params if omitted)
config.result SchemaLike Result schema (SchemaLike)

this