Skip to main content

Installation

Initialization

RegisterWorker

RegisterWorker creates a Client for the engine at url and starts the connection lifecycle in the background, returning immediately. An empty url means EngineURLFromEnv, as with New. It is the idiomatic entry point, matching registerWorker in the Node SDK and register_worker in the Rust SDK. Register functions and observers on the returned client; they are (re)sent on each connection. Call Client.Close to stop. To wait for the first connection (or fail fast on a bad URL), call Client.Connect instead of (or after) RegisterWorker; it blocks until connected, ctx is done, or the reconnect budget is exhausted. Use New if you want to build a client without starting the connection. Signature
string
required
...Option

Methods

Client.RegisterFunction

RegisterFunction registers a function this worker can handle and returns its handle; FunctionRef.Unregister removes it. It may be called before or after Connect; the registration is sent on the next (re)connect. As in the Node, Python and Rust SDKs, an empty id is refused (“id is required”) and so is an id this client already registered (“function id already registered”): to replace a function, unregister it first. Pass a single RegisterFunctionOptions value for a description, request and response formats, metadata, args_format, private, observable or the local dispatch setting. The handler’s return value is what observers observe. Every call of the function, local or routed, runs the handler and is then delivered to the observers that want it (Client.OnObservationMatchFor; by default all of them): by the function’s deliver hook (Client.OnObservationDeliverFor), or by iii, to those whose capture and filters match. Set hooks by id before registering: the SDK acks no observer before RegisterFunction returns, but a hook set on the returned handle can miss observers already accepted, and is caught up for them. Handlers read the optional per-invocation metadata sidecar from their ctx with MetadataFromContext. Signature
string
required
Handler
required
...RegisterFunctionOptions

Client.Call

Call invokes a function. With the default (nil) or an enqueue action it waits for the matching invocation result and returns it, mapping a remote error to InvocationError and a missed deadline to ErrTimeout. With a VoidAction it is fire-and-forget and returns immediately with a nil result. With CallRequest.Observer it calls through that observer. ctx bounds the wait independently of CallRequest.Timeout: if ctx is cancelled first, its error is returned and the pending entry is reclaimed. Inside a handler or a deliver hook, pass its ctx: the call then carries that invocation as its caller (and the observe depth), which observers’ filters and the engine’s loop guard read. A function this worker hosts runs in-process, without touching the wire, once the engine confirmed it for local dispatch, unless the action is enqueue or Dispatch is DispatchRemote. The handler gets its own copy of the payload and the caller its own encoding of the result, except for a RegisterFunctionOptions.Private function, whose input and result pass by reference; errors and timeouts look as on the remote path. The call is delivered to the function’s observers as a routed one is, from snapshots of the payload and metadata taken when it started. The handler runs on a goroutine of its own, so the caller always returns on its Timeout or ctx deadline, even when the handler blocks and ignores its ctx; the handler then runs to completion (as a remote one would on its worker), its result is discarded, and the call is still counted and delivered. A handler that can block for long should honor its ctx (cancelled on Close), or opt out with RegisterFunctionOptions.LocalDispatch. Signature
context.Context
required
CallRequest
required

Client.Observe

Observe observes a function: when source.FunctionID runs, target runs, for every call that the function’s worker delivers to the observer and that passes source.Filters. target is a function registered by some worker (until it is, the observer stays pending). source.Args go to the worker that hosts the function, which reads them in its hooks (a route, a table). It returns the handle immediately, even before the connection is up; the observer is replayed with the same id on every reconnect. Errors from the engine (INVALID_ARGS, INVALID_FILTER, FORBIDDEN, NOT_OBSERVABLE, SELF_TARGET, the host’s rejection, and UNSUPPORTED against an engine without observe) show up as state error and fail ObserverHandle.Ready. An observeresult in state error is the engine’s refusal of that observe and the handle’s final answer: the engine holds no observer for it (it stores nothing for a refused observe, and disposes an observer it holds in error as it answers that observer’s replay), the handle is not sent again on a later connection, and its Dispose sends nothing. An observer that turns error after its observe was answered (the host’s rejection, OWNER_TIMEOUT) is held by the engine: the handle is replayed, and its Dispose unobserves it. The returned error is for a request that cannot be sent at all: a missing function or target, a blank namespace, args or filters that are not JSON, and an id a handle of this client holds. A handle holds its id until it is disposed (by ObserverHandle.Dispose or by the engine); an Observe of a held id sends nothing, leaves the holder alone and returns an *ObserveRejectionError with code OBSERVER_ID_CONFLICT. Once the holder is disposed the id is free at once. Signature
Source
required
string
required
...ObserverOptions

Client.Trigger

Deprecated. Use Client.Call.
Trigger is Client.Call under its 0.25 name. Signature

Parameters

context.Context
required
TriggerRequest
required

Client.AddConnectionStateListener

AddConnectionStateListener calls listener with the current ConnectionState, then with every later change of state (StateConnecting, StateConnected, StateReconnecting, StateDisconnected, StateFailed), in the order the changes happen. Calls are made one at a time on a goroutine of the client’s own, never on the subscribing goroutine or on the SDK’s read loop, so a listener may call any Client method; it should return promptly, since later changes wait for it. A state is reported once per change: the same state is never delivered twice in a row. A listener that panics is logged and keeps its subscription. It returns the function that unsubscribes listener: changes not yet delivered when it returns are dropped for this listener (a call already under way completes). Calling it more than once does nothing. It mirrors addConnectionStateListener in the browser SDK and add_connection_state_listener in the Python SDK. Signature

Parameters

func(ConnectionState)
required

Client.Address

Address returns the engine WebSocket base URL this client dials (e.g. “ws://127.0.0.1:49134”): the url given to New or RegisterWorker, else EngineURLFromEnv. Channel readers/writers build their own URLs from it. Signature

Client.Close

Close shuts the client down at once: it stops the reconnect loop, gives buffered observe reports and telemetry a short, fixed time to go out (250ms for the reports, at most 10s for the telemetry flush), cancels all pending calls with ErrNotConnected, and drops the socket without a closing handshake. It does not send unregister frames (matching the reference SDKs). Use Client.Shutdown to wait for the flushes under a deadline of your own and close the socket gracefully. Close is idempotent and implements io.Closer; it always returns nil. Called while a Shutdown runs, it cuts that Shutdown short (as http.Server.Close does) and returns once it has finished. Signature

Client.Connect

Connect starts the connection lifecycle (if not already started) and blocks until the first connection is established, ctx is cancelled, or the reconnect budget is exhausted. The supervisor goroutine then keeps the connection alive (reconnecting with backoff) until Close. Connect is safe to call multiple times and from multiple goroutines; only one supervisor ever runs. Signature

Parameters

context.Context
required

Client.ConnectionState

ConnectionState returns the current state of the connection to the engine. It mirrors getConnectionState in the Node SDK; Client.AddConnectionStateListener reports every change. Signature

Client.CreateChannel

CreateChannel asks the engine to allocate a streaming channel and returns both ends. bufferSize bounds the engine’s internal queue; nil uses the engine default. Signature

Parameters

context.Context
required
*int
required

Client.FatalError

FatalError returns the terminal registration rejection that stopped this worker, or nil while healthy. Mirrors the Node/Python/Rust SDKs’ fatal-error accessors. Signature

Client.IsObserved

IsObserved reports whether functionID, registered by this worker, has active observers, so a source can skip building an event nobody wants. It takes no lock: a lookup of functionID and one atomic load. FunctionRef.IsObserved is the load alone. Signature

Parameters

string
required

Client.IsObservedFor

IsObservedFor reports whether call of functionID, registered by this worker, would reach an observer. On a function matched by keys (MatchKeys) it is true when an observer is filed under one of the call’s keys (one lookup per key); on any other function call is ignored, and it is Client.IsObserved. Set what the keys read (Input, Metadata). Signature

Parameters

string
required
*Call
required

Client.LocalDispatchActive

LocalDispatchActive reports whether Call runs functionID in-process: it is registered here, the engine confirmed it with local_dispatch, and RegisterFunctionOptions.LocalDispatch did not opt out. Signature

Parameters

string
required

Client.ObserveFunction

ObserveFunction observes functionID with target, every call and the observer defaults: Client.Observe with Source{FunctionID: functionID}. Signature
string
required
string
required
...ObserverOptions

Client.Observers

Observers returns the active observers of functionID, registered by this worker, as its host sees them. Signature

Parameters

string
required

Client.OnObservationDeliverFor

OnObservationDeliverFor sets the hook that delivers each call of functionID itself; nil restores iii’s delivery, which delivers each call to every matched observer whose capture and filters accept it, and gives the caller the handler’s result. It is stored by id, as Client.OnObserverAddedFor is. A function with a deliver hook needs an engine with observe.v2: against an older one it stays unregistered, and the SDK logs UNSUPPORTED once. A deliver hook does not run for a function registered with Client.RegisterHTTPFunction: the engine delivers its calls. It returns the client, for chaining. Signature
string
required
DeliverHook
required

Client.OnObservationMatchFor

OnObservationMatchFor sets which observers want each call of functionID: MatchFunc or MatchKeys; nil restores the default, where every observer wants every call. It is stored by id, as Client.OnObserverAddedFor is. A match hook set on a registered function takes effect on the function’s hook queue, after the hooks queued before it, and calls use the previous one until then. A hook by keys set while the function has active observers rebuilds the index from them; an observer whose keys panic is late-rejected with OBSERVE_REJECTED. A function with a match hook needs an engine with observe.v2: against an older one it stays unregistered, and the SDK logs UNSUPPORTED once. It returns the client, for chaining. Signature

Parameters

string
required
*MatchHook
required

Client.OnObserverAdded

OnObserverAdded sets the hook that runs when an observer is added to any function this worker hosts, before the function’s own; nil removes it. A hook set while functions have active observers runs for each of them at once (see Client.OnObserverAddedFor). It returns the client, for chaining. Signature

Parameters

AddedHook
required

Client.OnObserverAddedFor

OnObserverAddedFor sets the hook that runs when an observer is added to functionID, after the worker’s; nil removes it. Hooks are stored by function id: set them before RegisterFunction, so they run for every observer, and they stay across FunctionRef.Unregister and a later registration of the id. A hook set once the function already has active observers is caught up: it runs for each of them at once, an error late-rejects that observer, and the SDK logs one warning naming the function and how many observers were active without it. It returns the client, for chaining. Signature

Parameters

string
required
AddedHook
required

Client.OnObserverRemoved

OnObserverRemoved sets the hook that runs when an observer is removed from any function this worker hosts, after the function’s own; nil removes it. It returns the client, for chaining. Signature

Parameters

RemovedHook
required

Client.OnObserverRemovedFor

OnObserverRemovedFor sets the hook that runs when an observer is removed from functionID, before the worker’s; nil removes it. It is stored by function id, as Client.OnObserverAddedFor is. It returns the client, for chaining. Signature

Parameters

string
required
RemovedHook
required

Client.OpenReader

OpenReader returns a reader for the read end described by ref (typically received in a call payload), against this client’s engine address. Like the ends returned by Client.CreateChannel, its handshake sends the client’s WithHeaders plus “Authorization: Bearer $III_TOKEN” when that variable is set and the headers have no Authorization header. The socket connects on first read. Signature

Parameters

StreamChannelRef
required

Client.OpenWriter

OpenWriter returns a writer for the write end described by ref (typically received in a call payload), against this client’s engine address. Like the ends returned by Client.CreateChannel, its handshake sends the client’s WithHeaders plus “Authorization: Bearer $III_TOKEN” when that variable is set and the headers have no Authorization header. The socket connects on first send. Signature

Parameters

StreamChannelRef
required

Client.RegisterHTTPFunction

RegisterHTTPFunction registers a function that has no handler in this process: the engine invokes it by sending an HTTP request as described by invocation, which travels as the registration’s “invocation” field. invocation.URL is required; an empty Method means POST, as in the Node SDK. invocation.Auth, when set, must be valid JSON; build it with HMACAuth, BearerAuth or APIKeyAuth. Pass at most one RegisterFunctionOptions for the description, formats, metadata, args_format, private or observable; LocalDispatch does not apply, since there is nothing to run in-process. The engine delivers the function’s calls itself, so a deliver hook does not run for it; the added and removed hooks do. Like every registration it is kept in memory and sent again on each reconnect. An empty id, or one this client already registered, is refused as in Client.RegisterFunction; FunctionRef.Unregister on the returned handle removes it. Signature

Parameters

string
required
HTTPInvocationRef
required
...RegisterFunctionOptions

Client.Shutdown

Shutdown shuts the client down gracefully, as the Node SDK’s shutdown does, bounded by ctx like http.Server.Shutdown: it stops the reconnect loop, waits until the buffered observe reports and counters are written, stops the worker gauges, flushes and stops the telemetry exporters, cancels all pending calls with ErrNotConnected, and closes the socket with a normal-closure handshake. When ctx is done before those steps finish, the remaining work is cut short (the socket is closed at once, also when the engine never answers the close handshake) and ctx.Err() is returned; the client is shut down either way and nil means everything was delivered. A Client.Close called meanwhile cuts it short the same way, and Shutdown then returns context.Canceled. Like Close it does not send unregister frames. Shutdown is idempotent: a later Shutdown returns once the first shutdown has finished, or ctx.Err() if its own ctx ends first. Signature
context.Context
required

Client.State

Deprecated. Use Client.ConnectionState.
State returns the current connection state. Signature

Client.WaitUntilRegistered

WaitUntilRegistered blocks until the engine has acknowledged this worker on the current connection, with the WorkerRegistered frame it sends on each connection, and then returns nil. While the client is disconnected it waits for the next connection’s acknowledgement. It returns the error of Client.FatalError when the worker was terminally rejected (for example a WORKER_NAMESPACE_CONFLICT, or a blank WithNamespace), and ctx.Err() when ctx is done first. Like the Rust SDK’s wait_until_registered, which it mirrors with ctx in place of a timeout, it returns ErrNotConnected when the client was never started (call it after Client.Connect or RegisterWorker), has been closed, or gave up reconnecting (ReconnectConfig.MaxRetries). Signature

Parameters

context.Context
required

Client.WorkerID

WorkerID returns the worker id the engine assigned with its last WorkerRegistered, or "" before the first one. The id is kept across a disconnect (the next connection presents it to reattach) until the engine assigns the next one. It mirrors worker_id in the Python SDK. Signature

Functions

APIKeyAuth

APIKeyAuth returns the HTTPInvocationRef.Auth that has the engine send an API key in the request header named header, the key being held in the engine’s environment variable valueKey: {“type”:“api_key”,“header”:header,“value_key”:valueKey}. Same shape as the api_key variant of the Node SDK’s HttpAuthConfig. Signature

Parameters

string
required
string
required

BearerAuth

BearerAuth returns the HTTPInvocationRef.Auth that has the engine send “Authorization: Bearer <token>”, the token being held in the engine’s environment variable tokenKey: {“type”:“bearer”,“token_key”:tokenKey}. Same shape as the bearer variant of the Node SDK’s HttpAuthConfig. Signature

Parameters

string
required

DefaultReconnectConfig

DefaultReconnectConfig is the reconnect schedule shared with the Node SDK: start at 1s, double each time, cap at 30s, ±30% jitter, retry forever. Signature

EngineURLFromEnv

EngineURLFromEnv returns the engine address a worker connects to when its code names none: the III_URL environment variable, trimmed, when it is not blank, else DefaultEngineURL. The supervisor that spawned the process (iii compose, a container runtime, systemd) sets III_URL the same way it sets III_NAMESPACE and III_WORKER_NAME. New and RegisterWorker call it when their url argument is empty, so an explicit address wins, then III_URL, then the default, as in the Node SDK. Signature

EnqueueAction

EnqueueAction routes an invocation through a named queue; the engine acknowledges with an enqueue receipt rather than the function’s result. Signature

Parameters

string
required

ExtractChannelRefs

ExtractChannelRefs recursively walks a JSON value and returns every StreamChannelRef found, keyed by its dotted path (e.g. “reader”, “data.writer”). A node is a ref iff it is an object with string channel_id, access_key, and direction fields. Mirrors extract_channel_refs and is_channel_ref in the Rust SDK: the receiving worker uses it to find a ref another worker embedded in a call payload. Signature

Parameters

json.RawMessage
required

HMACAuth

HMACAuth returns the HTTPInvocationRef.Auth that has the engine sign each request with HMAC, using the secret held in the engine’s environment variable secretKey: {“type”:“hmac”,“secret_key”:secretKey}. Same shape as the hmac variant of the Node SDK’s HttpAuthConfig. Signature

Parameters

string
required

Identity

Identity is a handler that returns the input it is called with. An event source registers it: its observers observe each event as both input and output. Signature

Parameters

context.Context
required
json.RawMessage
required

InferSchema

InferSchema reflects a JSON Schema for T, exposed for callers that want to build a registration manually or inspect the schema the typed API would send. Signature

InvocationFromContext

InvocationFromContext returns the invocation a handler’s ctx belongs to, remote or local. ok is false outside any handler. Signature
context.Context
required

MarshalMessage

MarshalMessage encodes a variant struct as a wire frame, injecting the “type” tag. Pass one of the *Message structs (by pointer or value) from this file. Signature

Parameters

any
required

MatchFunc

MatchFunc is a match hook that asks predicate, once per active observer per call, whether the observer wants the call. A predicate that panics counts as no match, and the SDK logs it once per function. A nil predicate gives a nil MatchHook. Signature
func(obs *Observer, call *Call) bool
required

MatchKeys

MatchKeys is a match hook by keys: an observer wants a call when they share a key, and the SDK keeps an index of the active observers by key instead of asking each of them. observerKeys says what an observer listens for: the SDK computes it once, when the observer is accepted, files the observer under each key and unfiles it when it is removed. An observer whose observerKeys panics is rejected with OBSERVE_REJECTED. callKeys says what a call is: the call matches the observers filed under any of its keys, each once; a callKeys that panics matches nothing, and the SDK logs it once per function. Keys express wildcards by listing them: an observer of every table is filed under “primary|*|insert”, and a change matches “primary|orders|insert”, “primary|orders|*”, “primary|*|insert” and “primary|*|*”. A nil function gives a nil MatchHook. On a function matched by keys, Client.IsObservedFor answers with one lookup per call key. Signature
func(obs *Observer) []string
required
func(call *Call) []string
required

MetadataFromContext

MetadataFromContext returns the per-invocation metadata attached to a handler’s ctx. The bool is false (and the value nil) when the invocation carried no metadata, letting a handler distinguish “no metadata” from a present-but-empty value. Metadata is any JSON value; JSON null is no metadata. Signature
context.Context
required

New

New creates a Client for the engine at url (e.g. DefaultEngineURL). An empty url means EngineURLFromEnv: III_URL when set, else DefaultEngineURL. It does not connect; call Client.Connect to start the connection lifecycle, or use RegisterWorker to create and connect in one step. Signature

Parameters

string
required
...Option

ObserveRejection

ObserveRejection builds the error an AddedHook returns to reject an observer with code (any other error rejects it with OBSERVE_REJECTED). Signature

Parameters

string
required
string
required

OpenReader

OpenReader returns a reader for the read end described by ref, against the given engine WS base (typically Client.Address()). The socket connects on first read and authenticates with III_TOKEN, when set; channels from Client.CreateChannel also send the client’s WithHeaders. Prefer Client.OpenReader, which uses the client’s address and headers. Signature

Parameters

string
required
StreamChannelRef
required

OpenWriter

OpenWriter returns a writer for the write end described by ref, against the given engine WS base (typically Client.Address()). The socket connects on first send and authenticates with III_TOKEN, when set; channels from Client.CreateChannel also send the client’s WithHeaders. Prefer Client.OpenWriter, which uses the client’s address and headers. Signature

Parameters

string
required
StreamChannelRef
required

RegisterFunctionTyped

RegisterFunctionTyped registers a function whose request and response schemas are inferred from the Req and Resp type parameters and advertised to the engine. It is the schema-aware counterpart of Client.RegisterFunction; reach for it when you want the engine (and its dashboard / typed callers) to know the function’s contract. It returns the function’s handle, as Client.RegisterFunction does. Use Client.RegisterFunction directly for schemaless functions. See InferSchema to obtain a type’s schema on its own. Pass a single RegisterFunctionOptions value to attach a description, registration metadata, args_format, private or observable; its RequestFormat and ResponseFormat, when set, replace the inferred schemas (that type is then not reflected). Its handle sets the function’s hooks, as Client.RegisterFunction’s does. Signature
*Client
required
string
required
TypedHandler[Req, Resp]
required
...RegisterFunctionOptions

UnmarshalMessage

UnmarshalMessage decodes a wire frame by peeking at “type” and then decoding into the matching variant struct. It is the Go counterpart of serde’s tag dispatch. Signature

Parameters

[]byte
required

VoidAction

VoidAction returns the fire-and-forget action. A call with this action carries no invocation_id, so the engine sends no reply (see Client.Call). Signature

WithDescription

WithDescription sets a one-line, human/LLM-readable summary of what this worker does. Surfaces in engine::workers::list / engine::workers::info. Signature

Parameters

string
required

WithHeaders

WithHeaders sets HTTP headers sent on the WebSocket handshake of the main connection and of channels created with Client.CreateChannel. The III_TOKEN environment variable, when set and not blank, adds “Authorization: Bearer <token>” unless h already carries an Authorization header. Signature

Parameters

http.Header
required

WithInvocationTimeout

WithInvocationTimeout sets how long Client.Call waits for a result when CallRequest.Timeout is zero, in place of DefaultInvocationTimeout. It is the invocationTimeoutMs option of the Node SDK’s registerWorker. A d of zero or less keeps the default. Signature

Parameters

time.Duration
required

WithMetricsReporting

WithMetricsReporting turns the worker resource gauges on or off (Node enableMetricsReporting): the iii.worker.memory.*, iii.worker.cpu.*, iii.worker.event_loop.lag_ms and iii.worker.uptime_seconds metrics, tagged with worker.id and worker.name. The default is true. The gauges start when the engine acknowledges the worker and stop when the connection drops; they need telemetry and its metrics to be enabled (see OtelConfig). Signature

Parameters

bool
required

WithName

WithName sets the worker name reported to the engine. A non-empty III_WORKER_NAME takes precedence. The default is “hostname:pid”. Signature

Parameters

string
required

WithNamespace

WithNamespace sets the namespace this worker registers into. Takes precedence over the III_NAMESPACE environment variable. A namespace named and left blank is refused, not read as “no namespace”: the client is put in a terminal failed state, so Client.Connect returns the reason and Client.FatalError reports it. Absent and blank ask for opposite things: absent asks for the engine’s default, blank names a namespace and gives nothing to name it with. Read as absent, the worker registers in default, and since a worker’s calls and observers follow its namespace, the whole project quietly serves from a place its declaration never named. To register in the engine’s default namespace, do not call this. Signature

Parameters

string
required

WithOtel

WithOtel configures the client’s OpenTelemetry pipeline (the otel option of Node registerWorker). Telemetry starts with the connection lifecycle (RegisterWorker or Client.Connect) and Client.Close flushes and stops it. Without this option the defaults documented on OtelConfig apply, and they enable telemetry. Signature
OtelConfig
required

WithReconnectConfig

WithReconnectConfig overrides the default reconnect schedule. Signature

Parameters

ReconnectConfig
required

WithTelemetry

WithTelemetry sets what the worker reports about its language, project and framework on every connection. Blank fields keep their defaults (see TelemetryOptions). Signature

Parameters

TelemetryOptions
required

filter.Compile

Compile validates and compiles a filter given as a Go value. A json.RawMessage or []byte is read as JSON text; any other value is read through encoding/json, so what is validated is exactly what travels on the wire. It returns an *Error with code INVALID_FILTER when the filter is not valid. Signature

Parameters

any
required

filter.MatchAll

MatchAll returns the filter that matches every document ({}). Signature

filter.Parse

Parse validates and compiles a filter given as JSON text. It returns an *Error with code INVALID_FILTER when the filter is not valid. Signature

Parameters

[]byte
required

filter.ParseNormalized

ParseNormalized compiles a filter in the normal form the engine pushes (functionregistered, observeradded). Every rule applies except the encoded size limit, which the engine checked on the filter as written (a normal form can be longer). Signature

Parameters

[]byte
required

Constants

iii

EngineFunctions are the engine’s built-in function paths a worker can invoke with Client.Call. Mirrors EngineFunctions in the Node SDK. A function row of engine::functions::list and engine::functions::info carries observer_count, and args_format, private and observable when set. Engine-hosted sources: private functions of the engine whose handler returns the event, so input and output are both the event. Observe them with Client.Observe and filters on input; only the engine calls them. EngineSources names them as the other SDKs do. Log function paths. Mirrors LogFunctions in the Node SDK. Call these with VoidAction (fire-and-forget) to write to the engine log. Features this SDK declares in its engine::workers::register payload. The engine advertises the first three in WorkerRegistered: observe.v2 includes observe.v1, and with it this worker runs the match and deliver hooks of the functions it hosts for their routed calls, whose observers’ capture and filters the engine evaluates. FeatureLargeMessagesV1 is declared by the SDK only: it receives JSON messages up to 64 MiB, so the engine sends it messages of that size whatever version it reports. Engine functions of the observer registry.

iii/filter

Structural limits of a filter (the conformance vectors define how they count).

Variables

iii

Sentinel errors for the two failure modes that carry no payload. Compare with errors.Is. These line up with the Rust IIIError::NotConnected / ::Timeout variants.

Types

iii

Package iii is a Go SDK for the iii worker protocol. Activation · AddedHook · Args · Call · CallAction · CallRequest · Caller · Capture · Channel · ChannelDirection · ChannelReader · ChannelWriter · ConnectionState · DecodedMessage · DeliverHook · Dispatch · DroppedReports · ErrorBody · Filters · FunctionOptions · FunctionRef · FunctionRegisteredMessage · HTTPInvocationRef · Handler · Invocation · InvocationError · InvocationResultMessage · InvocationsObservedMessage · InvokeFunctionMessage · LocalFunctionStats · LocalInvocationStatsMessage · MatchHook · MessageType · MiddlewareFunctionInput · ObserveMessage · ObserveMessageSource · ObserveMessageTarget · ObserveReason · ObserveRejectionError · ObserveResultMessage · Observed · ObservedItem · Observer · ObserverAckMessage · ObserverAddedMessage · ObserverHandle · ObserverInfo · ObserverOptions · ObserverRemovedMessage · ObserverState · ObserverStateChangedMessage · Op · Option · OtelConfig · PingMessage · PongMessage · ReattachMessage · ReconnectConfig · RegisterFunctionMessage · RegisterFunctionOptions · RegisterServiceMessage · RegistrationRejectedError · RegistrationRejectedMessage · RemovedHook · Source · StreamChannelRef · TelemetryOptions · TypedHandler · UnobserveMessage · UnregisterFunctionMessage · WorkerRegisteredMessage

Activation

Activation marks the invocation of an observer’s target.

AddedHook

AddedHook runs when an observer is added to a function this worker hosts, before the SDK acks it. Returning nil accepts the observer; an error built with ObserveRejection rejects it with that code, any other error with OBSERVE_REJECTED. ctx is cancelled after 30 s, when the observer fails with OWNER_TIMEOUT.

Args

Args are an observer’s arguments, for the worker that hosts the observed function: validated against the function’s args_format by the engine, and read by its hooks.

Call

Call is one call of a function, as its host sees it in a MatchHook, a DeliverHook and Observer.Matches. The fields of a call the SDK hands over are read-only.

CallAction

CallAction mirrors the engine’s CallAction enum, a “type”-tagged lowercase union: {“type”:“void”} or {“type”:“enqueue”,“queue”:”…”}. It rides on InvokeFunction.Action (the wire field “action”) and selects the delivery semantics of a Client.Call.

CallRequest

CallRequest is the input to Client.Call. The Action field selects the delivery semantics: nil/await (default) waits for the result; VoidAction is fire-and-forget; EnqueueAction routes through a named queue and awaits its receipt.

Caller

Caller is who started an invocation: the worker (WorkerID / WorkerName, stamped by the engine and never forgeable), and the function and invocation the call was made from. Parent is the caller of that handler, one level only. Every field may be empty: a top-level call has no function.

Capture

Capture names a part of an observed invocation shipped to an observer’s target. The default is input, output and caller. Capture also decides which outcomes fire the target: input and output fire on success, error on error; caller and metadata only add to the payload.

Channel

Channel is a freshly created channel: a live writer/reader plus the refs for each end. Pass WriterRef or ReaderRef to another worker (in a call payload) so it opens the opposite end with Client.OpenReader / Client.OpenWriter. Created by Client.CreateChannel.

ChannelDirection

ChannelDirection is the end of a streaming channel a StreamChannelRef refers to. On the wire it is lowercase: “read” or “write”.

ChannelReader

ChannelReader is the read end of a channel: a WebSocket opened lazily on first use. Binary frames are stream data (NextBinary / ReadAll); text frames are messages delivered to OnMessage callbacks. The reader reads from a single goroutine internally, so register OnMessage callbacks before the first NextBinary/ReadAll call.

ChannelWriter

ChannelWriter is the write end of a channel: a WebSocket opened lazily on first use. SendMessage emits a text frame; Write emits 64 KiB-chunked binary frames. Close finishes the stream. A ChannelWriter is safe for serial use by one goroutine; it is not designed for concurrent writers (mirroring the reference SDKs).

ConnectionState

ConnectionState is the lifecycle state of a Client’s WebSocket. Mirrors IIIConnectionState in the Node SDK.

DecodedMessage

DecodedMessage is the result of UnmarshalMessage: the decoded “type” plus exactly one populated variant pointer (the rest are nil). Callers switch on Type, or check which pointer is non-nil.

DeliverHook

DeliverHook delivers each call of one function itself. It receives the call and the observers that matched it (MatchHook, or every active observer), as they were when the call started. What it returns is the caller’s result, encoded as a handler’s is; the error it returns is the caller’s error. iii delivers nothing for the function: the hook calls a target through its observer (CallRequest.Observer) and applies the observer’s capture and filters with Observer.Matches. It runs inside the function’s invocation, so calls made with ctx have that invocation as their caller.

Dispatch

Dispatch selects how Client.Call reaches a function this worker hosts.

DroppedReports

DroppedReports counts report items the SDK dropped (BUFFER_FULL, TOO_LARGE, DISCONNECTED, INACTIVE).

ErrorBody

ErrorBody is the wire representation of a remote error: a code, a message and an optional stack trace. It is intentionally minimal; a Client.Call caller receives it as an InvocationError (read it with errors.As).

Filters

Filters is a declarative filter over input, output, error, caller and metadata, with explicit operators only (the language of the filter subpackage):
The engine evaluates them for the calls it routes, and the worker that hosts the function for the calls it makes to it in-process. Both match through an index of the observers’ equality conditions: each observer is filed under one eqofascalar,oroneeq of a scalar, or one in of scalars, on a path of its filter’s top-level $and, and costs a call nothing when the call’s value at that path is none of that condition’s values. A call evaluates the whole filter of the observers filed under its value and of those with no such condition.

FunctionOptions

FunctionOptions is another name for RegisterFunctionOptions, the one the cross-SDK specification uses.

FunctionRef

FunctionRef is the handle of a registered function, returned by Client.RegisterFunction, Client.RegisterHTTPFunction and RegisterFunctionTyped. It mirrors the FunctionRef of the Node SDK: its hook methods set the function’s hooks by its id, and return the handle for chaining.

FunctionRegisteredMessage

FunctionRegisteredMessage is the RegisterFunction success ack, with the full current observer set. Always accepted: it replaces the set the SDK holds.

HTTPInvocationRef

HTTPInvocationRef describes an externally-hosted function the engine calls directly over HTTP: the Node SDK’s HttpInvocationConfig. Register one with Client.RegisterHTTPFunction; it travels as the registration’s “invocation” field. Auth is raw JSON because the engine’s HttpAuthConfig is a tagged union: build it with HMACAuth, BearerAuth or APIKeyAuth.

Handler

Handler is a registered function’s implementation. data is the raw JSON the engine sent. The returned value is marshaled into the InvocationResult.result. Returning an error produces an InvocationResult.error; if the error is an *InvocationError its code and stacktrace are preserved, otherwise it is reported with code “invocation_failed” (matching the Rust and Node SDKs). Per-invocation metadata, when the call carries any, rides on ctx rather than the signature (so adding it is non-breaking): read it with MetadataFromContext.

Invocation

Invocation is the invocation a handler runs in, remote or local (InvocationFromContext).

InvocationError

InvocationError wraps a remote ErrorBody returned by the engine in InvocationResult.error, annotated with the function that was invoked. It is the Go counterpart of Node’s IIIInvocationError: one error type across all remote failure modes (RBAC FORBIDDEN, handler error, …), disambiguated by Code. Recover the details with errors.As:

InvocationResultMessage

InvocationResult is the worker’s reply to a non-fire-and-forget InvokeFunction. InvocationID is REQUIRED (a value, not a pointer): a result with no id cannot be routed back to its caller. At most one of Result/Error is set.

InvocationsObservedMessage

InvocationsObservedMessage carries the matches of the local calls this worker delivered, batched. The engine delivers routed calls itself (InvocationResultMessage says which observers it evaluates).

InvokeFunctionMessage

InvokeFunction is the engine->worker (and worker->engine, via Call) call. InvocationID is a POINTER and omitempty: when absent, the call is fire-and-forget and no InvocationResult is expected. Traceparent/Baggage carry W3C trace context across the hop. Action selects void/enqueue semantics. Metadata is OPTIONAL per-invocation metadata (arbitrary JSON) that travels as its own channel alongside Data, NOT folded into the payload. Like the engine’s skip_serializing_if optional fields it is omitted when nil; an inbound frame without a metadata key decodes to nil (“no metadata”), so older engines that never send it stay backward compatible. Distinct from RegisterFunction’s registration-level Metadata: this one is scoped to a single call.

LocalFunctionStats

LocalFunctionStats counts one function’s local invocations in a stats window.

LocalInvocationStatsMessage

LocalInvocationStatsMessage reports local invocations and SDK-side report drops, periodically and only when non-zero.

MatchHook

MatchHook says which observers want each call of one function; without one, every observer wants every call. Build it with MatchFunc (a predicate) or MatchKeys (keys the SDK indexes). The observers it matches are what iii delivers the call to, after their capture and filters, or what the function’s DeliverHook receives. A nil MatchHook, and the zero one, match every observer. A host that sends one observer something of its own (its initial state) calls the function with metadata {“for_observer”: <observer id>}, and the hook gives such a call to that observer alone: a predicate compares the ids, and observerKeys also files each observer under “for_observer:<id>”, the one key callKeys gives such a call.

MessageType

MessageType is the value of the envelope “type” field: the lowercase name of the message variant, as the engine expects it.

MiddlewareFunctionInput

MiddlewareFunctionInput is the payload the engine sends to the RBAC middleware function (the worker-manager rbac.middleware_function_id) on every function invocation that arrives through the RBAC port. The middleware can inspect, modify or reject the call before it reaches the target function: forward it with Client.Call, or return an error to reject it. It mirrors MiddlewareFunctionInput in the Node and Rust SDKs field for field; the JSON names are the wire contract. Register the middleware with RegisterFunctionTyped to receive it decoded, or unmarshal the raw handler payload into it. When forwarding, note that an empty Namespace means the engine’s default namespace, whereas an empty CallRequest.Namespace means this worker’s own namespace: pass “default” explicitly when Namespace is empty and the worker is namespaced.

ObserveMessage

ObserveMessage creates, or idempotently replays, an observer owned by this connection: Source is the left side of Client.Observe, Target the right side.

ObserveMessageSource

ObserveMessageSource is what an observer observes. Capture is omitted when nil and sent when empty (capture: [] is valid: a success with ids, status and timings only).

ObserveMessageTarget

ObserveMessageTarget is the function an observer invokes.

ObserveReason

ObserveReason is why an observer is in its state: a machine-readable code and a message.

ObserveRejectionError

ObserveRejectionError is an observe error carrying its code: what ObserverHandle.Ready returns when the observer turns error or disposed, what Client.Observe returns for an id a handle of the client holds (OBSERVER_ID_CONFLICT), and what an AddedHook returns (built with ObserveRejection) to reject an observer with a code of its own. Recover it with errors.As.

ObserveResultMessage

ObserveResultMessage is the engine’s reply to an observe (also on a replay).

Observed

Observed is what an observer’s target receives when iii delivers: the top-level fields, plus whichever of the observer’s capture apply to the outcome. Fields not captured, or that do not apply, are absent. Decode a target’s payload into it:

ObservedItem

ObservedItem is one reported call. Input, Output, Error and Metadata keep JSON null apart from absent: “output”: null is a function that returned null, a nil Output was not captured or equals Input (OutputIsInput).

Observer

Observer is an observer as the worker that hosts the observed function sees it (in its hooks and in Client.Observers): its args, filters, target and capture. Never its metadata, policy or the observing worker. Its fields are set when it is added; the SDK keeps its own copy of what it reads, so changing them changes nothing but the host’s view. The pointer is stable while the engine announces the same view of the observer, so hosts keep it in their own index (expression -> observers, route table). The engine may announce an observer again with the same args and other filters, target or capture (a replay): it stays the same observer and no hook runs. From then on it is served, and listed by Client.Observers, as a new *Observer with that view; Reject and Accepted act on the observer through either pointer, and pointers handed out earlier keep the view they were made with.

ObserverAckMessage

ObserverAckMessage is the host’s answer to one added observer, sent once every OnObserverAdded hook that applies to it has returned. Error rejects it; a host may re-send it with an error for an active observer (a late rejection).

ObserverAddedMessage

ObserverAddedMessage attaches one observer to a function this connection hosts.

ObserverHandle

ObserverHandle is what Client.Observe returns: the observing side of one observer. It is kept for replay, with the same id, on every connection until it is disposed. Safe for concurrent use.

ObserverInfo

ObserverInfo is an observer as the host sees it: never its metadata, policy or the observing worker. Filters are in normal form.

ObserverOptions

ObserverOptions are the observer’s own settings: its id, policy and metadata. A zero field is unset.

ObserverRemovedMessage

ObserverRemovedMessage detaches one observer.

ObserverState

ObserverState is an observer’s lifecycle: pending (no host yet, waiting for the host’s ack, or no target yet) -> active or error; suspended while its worker or target is away; disposed at the end.

ObserverStateChangedMessage

ObserverStateChangedMessage is a lifecycle transition of an observer this connection owns.

Op

Op is the operator object of one filter path: iii.Op{“$eq”: “insert”}.

Option

Option configures a Client. Pass options to New.

OtelConfig

OtelConfig configures the OpenTelemetry pipeline a Client runs: spans, metrics and logs exported to the engine over a dedicated WebSocket at <engine address>/otel, the “execute <function id>” span around every handler, and the worker resource gauges. It mirrors the Node SDK’s OtelConfig (the otel option of registerWorker) field for field. The engine URL and the handshake headers are not part of it: the client uses its own address and its WithHeaders headers (plus the III_TOKEN bearer), as Node does for engineWsUrl and engineWsHeaders. Telemetry is enabled by default, as in the Node SDK: a client started without WithOtel exports unless OTEL_ENABLED is “false”, “0”, “no” or “off”. A zero field means “not set”: the environment variable named on the field, then the default, fills it in. OpenTelemetry globals: when telemetry starts, the client installs its tracer provider, its meter provider and the W3C Trace Context + Baggage propagator as the OpenTelemetry globals (otel.Tracer, otel.Meter, otel.GetTextMapPropagator), each only while that global is still the otel default. A provider or propagator the application installed earlier, or another client installed first, is never replaced: first registration wins, as in the Node SDK. Client.Close puts the default back into every global that still holds this client’s. The client’s invocation spans and worker gauges, and the observability helpers (which use the client started last), always use the client’s own providers, so they reach the engine either way. Spans the application creates with its own provider are parented to the invocation span through ctx and exported wherever that provider exports. Call and inbound invocations always propagate W3C Trace Context and Baggage, whatever the global propagator.

PingMessage

PingMessage is the payloadless keepalive the engine sends; it serializes to {“type”:“ping”}. The client replies with a PongMessage.

PongMessage

PongMessage is the payloadless reply to a PingMessage; it serializes to {“type”:“pong”}.

ReattachMessage

Reattach is sent worker->engine as the first message of a reconnect, before the registration replay: PreviousWorkerID is the id the engine assigned via WorkerRegistered on the previous connection. The engine retires that connection so the replay lands on a clean slate instead of racing its cleanup.

ReconnectConfig

ReconnectConfig controls the exponential-backoff-with-jitter reconnect loop. The defaults below match the Node SDK’s DEFAULT_BRIDGE_RECONNECTION_CONFIG exactly, so a Go worker reconnects on the same schedule as a Node one.

RegisterFunctionMessage

RegisterFunction announces a function this worker can handle. RequestFormat and ResponseFormat are optional JSON Schemas; Invocation is set only for externally HTTP-hosted functions (Client.RegisterHTTPFunction). Optional fields are omitted when unset, as the engine writes them (skip_serializing_if); the engine reads an absent format and a JSON null alike. ArgsFormat, Private and Observable describe the function to the engine’s observer registry; private: false and observable: true are the defaults and are omitted.

RegisterFunctionOptions

RegisterFunctionOptions configures a function registration. The zero value preserves the default registration shape. FunctionOptions is the same type. ArgsFormat, Private and Observable false need an engine with observe.v2, as a match or deliver hook does: against an older one the function stays unregistered, and the SDK logs UNSUPPORTED once. What the worker does when the function is observed is set with hooks (FunctionRef.OnObserverAdded and its siblings).

RegisterServiceMessage

RegisterService groups functions under a service for the dashboard.

RegistrationRejectedError

RegistrationRejectedError is the terminal error the engine returns when a worker’s registration is refused for good, typically a WORKER_NAMESPACE_CONFLICT, where another live worker already owns this name in the namespace. It is delivered to every pending invocation and reported by Client.FatalError; the worker stops and does not reconnect. Mirrors the Node/Python/Rust SDKs. Recover the details with errors.As:

RegistrationRejectedMessage

RegistrationRejectedMessage is the engine’s refusal of a registration. A FUNCTION_NAMESPACE_CONFLICT costs one function and leaves the connection open; a WORKER_NAMESPACE_CONFLICT is terminal: another live worker owns this name in the namespace.

RemovedHook

RemovedHook runs once for every accepted observer when it is removed (unobserve, disposal, late rejection with Observer.Reject). For an observer rejected before it is accepted (by another level’s AddedHook, or by Observer.Reject while the added hooks run), it runs for each level whose AddedHook resolved. A panic is logged; the observer is removed either way.

Source

Source is the left side of Client.Observe: what is observed.

StreamChannelRef

StreamChannelRef is a capability handle to one end of a streaming data channel. The engine’s engine::channels::create returns a writer ref and a reader ref that share a channel_id and access_key; a ref travels as plain JSON inside a call payload or result, and the holder opens its own WebSocket to the channel with it (Client.OpenReader, Client.OpenWriter).

TelemetryOptions

TelemetryOptions is what the worker reports about its language, project and framework in the telemetry object of engine::workers::register, shown by engine::workers::list and engine::workers::info. A blank field takes its default. Mirrors TelemetryOptions in the Node and Rust SDKs.

TypedHandler

TypedHandler is a function handler with a typed request and response. The SDK unmarshals the invocation payload into Req before calling it and marshals the returned Resp into the result, so handlers work with concrete types instead of json.RawMessage. Per-invocation metadata, when the call carries any, rides on ctx rather than the signature (so adding it is non-breaking): read it with MetadataFromContext.

UnobserveMessage

UnobserveMessage removes an observer this connection owns.

UnregisterFunctionMessage

UnregisterFunction removes a previously registered function.

WorkerRegisteredMessage

WorkerRegistered is sent engine->worker on connect to announce the worker’s id. The worker treats it as informational.

iii/filter

Package filter is the observer filter language (iii-filter v1): validation and evaluation with the same semantics as the engine’s evaluator and the other SDKs, pinned down by the conformance vectors all of them share. Doc · Error · ErrorCode · Filter · Map · Root · Roots

Doc

Doc is the document a filter reads: the value of each root, and whether it is present. A missing root is absent; a present nil is JSON null.

Error

Error is a filter the language rejects. Recover it with errors.As.

ErrorCode

ErrorCode is the protocol error code of a rejected filter.

Filter

Filter is a validated filter, compiled once into a closure tree. It is immutable and safe for concurrent use.

Map

Map is a Doc backed by a map keyed by root name: a missing key is an absent root, a nil value is JSON null. Keys other than the five roots are ignored.

Root

Root is a path’s first segment: the part of the document it reads.

Roots

Roots tells which document roots a filter’s clauses read.