Installation
Initialization
registerWorker
Register the worker with a iii instance, returns a connected worker client. The WebSocket connection is established automatically. Signature- Parameters
- Example
Methods
registerTrigger
Registers a new trigger. A trigger is a way to invoke a function when a certain event occurs. Signature- Parameters
- Example
RegisterTriggerInput
required
The trigger to register.
registerFunction
Registers a new function with a local handler or an HTTP invocation config. Signature- Parameters
- Example
string
required
Unique identifier for the function.
HttpInvocationConfig | RemoteFunctionHandler<any, any>
required
Async handler for local execution, or an HTTP invocation config for external functions (Lambda, Cloudflare Workers, etc.).
RegisterFunctionOptions
Optional function registration options (description, request/response formats, metadata).
trigger
Invokes a function using a request object. Signature- Parameters
- Example
TriggerRequest<TInput>
required
The trigger request containing function_id, payload, and optional action/timeout.
registerTriggerType
Registers a new trigger type. A trigger type is a way to invoke a function when a certain event occurs. Signature- Parameters
- Example
unregisterTriggerType
Unregisters a trigger type. Signature- Parameters
- Example
RegisterTriggerTypeInput
required
The trigger type to unregister.
currentInvocation
The invocation the calling code runs in (remote or local handler), orundefined outside any handler.
Signature
getAddress
Engine address this worker resolved to: the explicitregisterWorker
argument, else III_URL, else ws://127.0.0.1:49134.
Signature
getConnectionState
The current WebSocket connection state.'failed' is terminal: it follows
a fatal registration rejection (see getFatalError). Mirrors the
Python/Rust SDKs’ get_connection_state().
Signature
getFatalError
The fatal registration rejection that terminated this connection, if any (e.g. aWORKER_NAMESPACE_CONFLICT); undefined while healthy. Mirrors the
Python (_fatal_error) and Rust (fatal_error()) SDKs.
Signature
observe
Observes a function: every event ofsource that passes its filters
invokes target, a registered function. Returns synchronously (also
before the connection is up); the observer is replayed with the same id
on reconnect. Errors show up as state error and reject ready().
Signature
- Parameters
- Example
shutdown
Gracefully shutdown the iii, cleaning up all resources. SignatureExample
Subpath Exports
Theiii-sdk package provides additional entry points:
Types
iii-sdk
Caller · CallerInfo · Capture · EnqueueResult · Filter · InitOptions · InvocationContext · JsonValue · MiddlewareFunctionInput · Observed · ObserveDoc · ObserveHooks · Observer · ObserveReason · ObserverHandle · ObserverOptions · ObserverState · ObserveSource · StreamRequest · StreamResponse · Target · TelemetryOptions · TriggerAction
Caller
Who started an invocation: the worker (worker_id / worker_name, stamped
by the engine), and the function and invocation the call was made from.
CallerInfo
A caller as the SDK knows it: every field may be missing (a top-level call has no function; a call made beforeWorkerRegistered has no worker id).
Capture
What an observer ships to its target. Default['input', 'output', 'caller'].
EnqueueResult
Result returned when a function is invoked withTriggerAction.Enqueue.
Filter
A declarative filter overinput, output, error, caller and
metadata, with explicit operators only:
{ 'input.amount': { $gte: 500 } }. See the filter language reference.
InitOptions
Configuration options passed to registerWorker.InvocationContext
The invocation the current code runs in, in every handler, remote or local (iii.currentInvocation()).
JsonValue
Any JSON value: the TypeScript equivalent of the engine’s arbitrary-JSON wire values (Rustserde_json::Value). Used where the wire contract is
“any JSON”, e.g. per-invocation metadata.
MiddlewareFunctionInput
Input passed to the RBAC middleware function on every function invocation through the RBAC port. The middleware can inspect, modify, or reject the call before it reaches the target function.Observed
What the target of an auto observer (or ofobs.emit) receives with
deliver: 'envelope' (the default). Fields not in the observer’s
capture are absent.
ObserveDoc
The document an observer’s filters read (filters.md §1).ObserveHooks
Theobserve option of registerFunction: how the function’s observers
are delivered, and the callbacks that run when one is added or removed.
The callbacks of one function run one at a time, in revision order, with
one exception: a callback still running after 30 s is treated as failed
(OWNER_TIMEOUT) and the next one starts, so a hung callback cannot stall
its function forever. It may then overlap with the callbacks after it, and
if a timed-out onObserverAdded completes later, onObserverRemoved runs
for that observer.
Observer
An observer as the function’s owner sees it (onObserverAdded,
FunctionRef.observers()): its args, filters, target, capture and on.
Never its metadata, policy or the observing worker.
ObserveReason
A state reason or an error: a machine-readable code and a message.ObserverHandle
Whatiii.observe returns, synchronously.
ObserverOptions
The observer itself: its id, policy and metadata.ObserverState
An observer’s lifecycle:pending (no owner yet, waiting for the owner’s
ack, or no target yet) → active or error; suspended while its worker
or target is away; disposed at the end.
ObserveSource
The left side ofiii.observe: what is observed.
StreamRequest
Incoming streaming request received by a function registered with a stream trigger.StreamResponse
Response object passed to streaming function handlers. Usestatus() and
headers() to set response metadata, write to stream for streaming
responses, and call close() when done.
Target
The right side ofiii.observe: a registered function.
TelemetryOptions
Worker metadata reported to the engine (language, framework, project).TriggerAction
Factory object that constructs routing actions for IIIClient.trigger.iii-sdk/channel
Channel · ChannelReader · ChannelWriter · StreamChannelRef
Channel
A streaming channel pair for worker-to-worker data transfer. Created via thecreateChannel helper from iii-sdk/helpers.
ChannelReader
Read end of a streaming channel. Provides both a Node.jsReadable stream
for binary data and an onMessage callback for structured text messages.
ChannelWriter
Write end of a streaming channel. Provides both a Node.jsWritable stream
and a sendMessage method for sending structured text messages.
StreamChannelRef
Serializable reference to one end of a streaming channel. Can be included in invocation payloads to pass channel endpoints between workers.iii-sdk/engine
EngineFunctions · EngineTriggers · RemoteFunctionHandler
EngineFunctions
Engine function paths for internal operations. Naming note:LIST_TRIGGERS / INFO_TRIGGERS cover trigger TYPES
(templates). LIST_REGISTERED_TRIGGERS / INFO_REGISTERED_TRIGGERS
cover trigger INSTANCES (subscriber rows). The old
engine::trigger-types::list builtin has been removed and is now
served by engine::triggers::list.
EngineTriggers
Engine trigger typesRemoteFunctionHandler
Async function handler for a registered function. Receives the invocation payload and an optional per-invocationmetadata value, and returns the
result.
metadata is arbitrary JSON travelling on a separate channel from the
payload. It is undefined when the caller did not attach any. Existing
single-argument handlers keep working; they ignore the extra argument.
iii-sdk/errors
InvocationError · InvocationErrorInit · ObserveRejection · RegistrationRejectedError · RegistrationRejectedInit
InvocationError
InvocationErrorInit
Typed error surfaced when an invocation dispatched over the SDK fails, RBAC rejection (FORBIDDEN), handler-level failure, or a timeout waiting for the engine to respond. Wraps the wireErrorBody shape plus the function_id
that was targeted, so callers get a single error type across all failure
modes and can disambiguate via err.code.
Before this existed, rejection values were plain ErrorBody-shaped objects,
which printed as [object Object] when stringified, leaving developers to
grep through SDK source to figure out what tripped. The class name, code
prefix in the message, and function_id field together make a rejection
self-describing.
ObserveRejection
Thrown by anonObserverAdded hook to reject an observer with a code of
its own (HTTP_ROUTE_CONFLICT, INVALID_CRON_EXPRESSION, …); any other
error rejects it with OBSERVE_REJECTED. Also the error ObserverHandle.ready()
rejects with when the observer turns error or disposed.
RegistrationRejectedError
Fatal error surfaced when the engine rejects this worker’s identity because another live worker owns the same(namespace, worker_name), or when an
unknown rejection code is received. The SDK stops and does not reconnect.
A FUNCTION_NAMESPACE_CONFLICT is non-fatal and is logged instead of being
surfaced through this class. The wire fields identify the contested
registration and its current owner.
RegistrationRejectedInit
Fields used to construct a RegistrationRejectedError.iii-sdk/helpers
ChannelDirection · ChannelItem
ChannelDirection
Direction of a streaming channel endpoint. Mirrors the Rust SDK’sChannelDirection enum and matches the literal values used by
StreamChannelRef.direction.
ChannelItem
Discriminated runtime tag for an item observed on a streaming channel. Mirrors the Rust SDK’sChannelItem enum (Text / Binary). Carrier for
factory + type-guard helpers so callers can construct and discriminate
channel items without depending on Rust-specific shape.
iii-sdk/protocol
ActivationWire · CallerWire · CaptureWire · DroppedReportStatsWire · ErrorBody · FunctionRegisteredMessage · InvocationsObservedMessage · LocalFunctionStatsWire · LocalInvocationStatsMessage · MessageType · ObserveDescriptorWire · ObservedItemWire · ObserveMessage · ObserverAckMessage · ObserverAddedMessage · ObserveResultMessage · ObserverInfoWire · ObserverRemovedMessage · ObserverStateChangedMessage · ObserveSourceWire · RegisterFunctionFormat · RegisterFunctionInput · RegisterFunctionMessage · RegisterFunctionOptions · TriggerRequest · UnobserveMessage
ActivationWire
InvokeFunction.activation: present on every activation of an observer’s target.
CallerWire
Who started an invocation. Engine → worker:worker_id / worker_name
are stamped by the engine from the calling connection. Worker → engine:
the SDK sends function_id, invocation_id and parent (the caller of the
handler the call was made from, one level only).
CaptureWire
What an observer ships to its target (capture).
DroppedReportStatsWire
ErrorBody
FunctionRegisteredMessage
InvocationsObservedMessage
LocalFunctionStatsWire
LocalInvocationStatsMessage
MessageType
ObserveDescriptorWire
RegisterFunction.observe: the part of the observe hooks that travels. Callbacks never do.
ObservedItemWire
One matched local invocation (auto) or oneobs.emit event (owner).
ObserveMessage
ObserverAckMessage
ObserverAddedMessage
ObserveResultMessage
ObserverInfoWire
An observer as its function’s owner sees it: never the observer’s metadata, policy or connection.target is the target function id.
ObserverRemovedMessage
ObserverStateChangedMessage
ObserveSourceWire
observe.source: the left side of iii.observe.
RegisterFunctionFormat
RegisterFunctionInput
RegisterFunctionMessage
RegisterFunctionOptions
Options of IIIClient.registerFunction: description, request/response formats, metadata, and the observe hooks.TriggerRequest
Request object passed to IIIClient.trigger.UnobserveMessage
iii-sdk/runtime
FunctionRef · IIIConnectionState
FunctionRef
Handle returned by IIIClient.registerFunction. Contains the function’sid and an unregister() method.
IIIConnectionState
Connection state for the III WebSocketiii-sdk/state
IState · StateDeleteInput · StateDeleteResult · StateEventData · StateEventType · StateGetInput · StateListInput · StateSetInput · StateSetResult · StateUpdateInput · StateUpdateResult
IState
Interface for state management operations. Available via theiii-sdk/state
subpath export.
StateDeleteInput
Input for deleting a state value.StateDeleteResult
Result of a state delete operation.StateEventData
Payload for state change events.StateEventType
Types of state change events.StateGetInput
Input for retrieving a state value.StateListInput
Input for listing all values in a state scope.StateSetInput
Input for setting a state value.StateSetResult
Result of a state set operation.StateUpdateInput
Input for atomically updating a state value.StateUpdateResult
Result of a state update operation.iii-sdk/stream
IStream
IStream
Interface for custom stream implementations. Passed toIIIClient.createStream
to override the engine’s built-in stream storage.