Skip to main content

Installation

Initialization

registerWorker

Register the worker with a iii instance, returns a connected worker client. The WebSocket connection is established automatically. Signature
address
string
required
WebSocket URL of the III engine (e.g. ws://localhost:49134).
options
InitOptions
Optional InitOptions for worker name, timeouts, reconnection, and OTel.

Methods

registerTrigger

Registers a new trigger. A trigger is a way to invoke a function when a certain event occurs. Signature
trigger
RegisterTriggerInput
required
The trigger to register.

registerFunction

Registers a new function with a local handler or an HTTP invocation config. Signature
functionId
string
required
Unique identifier for the function.
handler
HttpInvocationConfig | RemoteFunctionHandler<any, any>
required
Async handler for local execution, or an HTTP invocation config for external functions (Lambda, Cloudflare Workers, etc.).
options
RegisterFunctionOptions
Optional function registration options (description, request/response formats, metadata).

trigger

Invokes a function using a request object. Signature
request
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
triggerType
RegisterTriggerTypeInput
required
The trigger type to register.
handler
TriggerHandler<TConfig>
required
The handler for the trigger type.

unregisterTriggerType

Unregisters a trigger type. Signature
triggerType
RegisterTriggerTypeInput
required
The trigger type to unregister.

shutdown

Gracefully shutdown the iii, cleaning up all resources. Signature

Example

Subpath Exports

The iii-sdk package provides additional entry points:

Types

iii-sdk

EnqueueResult · InitOptions · JsonValue · MiddlewareFunctionInput · StreamRequest · StreamResponse · TelemetryOptions · TriggerAction

EnqueueResult

Result returned when a function is invoked with TriggerAction.Enqueue.

InitOptions

Configuration options passed to registerWorker.

JsonValue

Any JSON value: the TypeScript equivalent of the engine’s arbitrary-JSON wire values (Rust serde_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.

StreamRequest

Incoming streaming request received by a function registered with a stream trigger.

StreamResponse

Response object passed to streaming function handlers. Use status() and headers() to set response metadata, write to stream for streaming responses, and call close() when done.

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 the createChannel helper from iii-sdk/helpers.

ChannelReader

Read end of a streaming channel. Provides both a Node.js Readable stream for binary data and an onMessage callback for structured text messages.

ChannelWriter

Write end of a streaming channel. Provides both a Node.js Writable 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 types

RemoteFunctionHandler

Async function handler for a registered function. Receives the invocation payload and an optional per-invocation metadata 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

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 wire ErrorBody 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.

iii-sdk/helpers

ChannelDirection · ChannelItem

ChannelDirection

Direction of a streaming channel endpoint. Mirrors the Rust SDK’s ChannelDirection 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’s ChannelItem 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

ErrorBody · MessageType · RegisterFunctionFormat · RegisterFunctionInput · RegisterFunctionMessage · RegisterFunctionOptions · RegisterTriggerInput · RegisterTriggerMessage · RegisterTriggerTypeInput · RegisterTriggerTypeMessage · TriggerRequest

ErrorBody


MessageType


RegisterFunctionFormat


RegisterFunctionInput


RegisterFunctionMessage


RegisterFunctionOptions


RegisterTriggerInput


RegisterTriggerMessage


RegisterTriggerTypeInput


RegisterTriggerTypeMessage


TriggerRequest

Request object passed to IIIClient.trigger.

iii-sdk/runtime

FunctionRef · IIIConnectionState · TriggerTypeRef

FunctionRef

Handle returned by IIIClient.registerFunction. Contains the function’s id and an unregister() method.

IIIConnectionState

Connection state for the III WebSocket

TriggerTypeRef

Typed handle returned by IIIClient.registerTriggerType. Provides convenience methods to register triggers and functions scoped to this trigger type, so callers don’t need to repeat the type field.

iii-sdk/state

IState · StateDeleteInput · StateDeleteResult · StateEventData · StateEventType · StateGetInput · StateListInput · StateSetInput · StateSetResult · StateUpdateInput · StateUpdateResult

IState

Interface for state management operations. Available via the iii-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 to IIIClient.createStream to override the engine’s built-in stream storage.

iii-sdk/trigger

Trigger · TriggerConfig · TriggerHandler

Trigger

Handle returned by IIIClient.registerTrigger. Use unregister() to remove the trigger from the engine.

TriggerConfig

Configuration passed to a trigger handler when a trigger instance is registered or unregistered.

TriggerHandler

Handler interface for custom trigger types. Passed to IIIClient.registerTriggerType.