Worker & serving
On this page
Building a worker and putting it on a transport.
function buildVgiProtocol
Section titled “function buildVgiProtocol”export function buildVgiProtocol(config: ProtocolConfig): Protocolfunction createLandingRoutes
Section titled “function createLandingRoutes”export function createLandingRoutes(info: LandingInfo): ExtraRouteHandlerDescription
Build the VGI landing surface as a route contributed to vgi-rpc’s HTTP handler.
Serves two paths, both relative to the handler’s mount prefix:
GET {prefix}/— the sharedlanding.htmlfor browsers, or a JSON status document for health checks,?format=json, and the page’s own identity read. Content negotiation matches vgi-python’sLandingPageResource.GET {prefix}/vgi-client.js— the browser build the page imports.
Anything else returns null, which lets normal routing continue.
interface LandingInfo
Section titled “interface LandingInfo”export interface LandingInfoDescription
Worker identity for the standardized VGI landing surface.
The shared landing.html reads catalog metadata by speaking the VGI protocol
through the client bundle the worker serves beside it, so nothing about the
catalog belongs here. What the protocol has no method for — which worker this
is, what it is called, what version it runs — rides on the JSON status
document at GET {prefix}/?format=json.
Fields
namestringWorker name shown as the page heading, e.g. “ishares”.
docstringoptionalOne-line description shown under the heading.
versionstringoptionalWorker version string shown in the footer.
cupolaBasestringoptionalOverride the Cupola base URL the “Explore” links point at.
interface ProtocolConfig
Section titled “interface ProtocolConfig”export interface ProtocolConfigFields
registryFunctionRegistrycatalogInterfaceCatalogInterfaceoptionalcatalogNamestringoptionalrecoverExchangeState(opaqueData: Uint8Array) => anyoptionalRecover accumulated exchange state from FINALIZE init_opaque_data. For HTTP transport, this unpacks the state token that the C++ extension passes from the last INPUT exchange to the FINALIZE init request. Returns the deserialized VGI dispatch state object (with userState field).
signingKeyUint8ArrayoptionalAEAD signing key for sealing catalog opaque-data envelopes. Pass the same 32-byte key used for HTTP state tokens. When omitted (subprocess / unix transports) attach_opaque_data / transaction_opaque_data pass through unsealed — OS process ownership already enforces identity there.
class Worker
Section titled “class Worker”export class WorkerMethods
method run
Section titled “method run”run(argv: readonly string[] = process.argv.slice(2)): voidmethod serveStream
Section titled “method serveStream”async serveStream( readable: ReadableStream<Uint8Array> | NodeJS.ReadableStream, writable?: number | import("node:net").Socket | import("@query-farm/vgi-rpc").ByteSink,): Promise<void>Serve this worker over a caller-provided byte-stream pair, instead of the
argv-selected stdio/unix/tcp transports run() uses. Resolves when the
readable ends.
This is the seam for transports that aren’t a process/socket — most notably
a Web Worker: bridge the worker’s MessagePort to a Node Duplex
(readable side ← port.on('message'), writable side → port.postMessage)
and pass it as both arguments. The same code runs in a browser Web Worker.
interface WorkerConfig
Section titled “interface WorkerConfig”export interface WorkerConfigFields
functionsVgiFunction[]optionalcatalogCatalogDescriptoroptionalcatalogInterfaceCatalogInterfaceoptionalcatalogInterfaceFactory(base: ReadOnlyCatalogInterface) => CatalogInterfaceoptionalFactory that receives the built ReadOnlyCatalogInterface and returns a custom catalog.
catalogNamestringoptionalregistryFunctionRegistryoptionalRegistry to dispatch through. Pass the same instance used to build a pre-constructed
catalogInterface— catalogs record which schema (and catalog) declares each function on the registry they are given, and schema-qualified resolution only works if that is the registry the worker dispatches on. Omit to have the worker create its own.