iii-browser-sdk 0.21.8 → 0.22.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { R as StreamChannelRef, a as ISdk, b as ChannelItem, r as Channel, y as ChannelDirection } from "./types-Dj_5C0O1.cjs";
1
+ import { R as StreamChannelRef, a as ISdk, b as ChannelItem, r as Channel, y as ChannelDirection } from "./types-dr4ELKgv.cjs";
2
2
  import { IStream } from "./stream.cjs";
3
3
 
4
4
  //#region src/utils.d.ts
@@ -1,4 +1,4 @@
1
- import { R as StreamChannelRef, a as ISdk, b as ChannelItem, r as Channel, y as ChannelDirection } from "./types-DzJ2vn5G.mjs";
1
+ import { R as StreamChannelRef, a as ISdk, b as ChannelItem, r as Channel, y as ChannelDirection } from "./types-Ui5yAF2Q.mjs";
2
2
  import { IStream } from "./stream.mjs";
3
3
 
4
4
  //#region src/utils.d.ts
package/dist/index.cjs CHANGED
@@ -50,6 +50,7 @@ let MessageType = /* @__PURE__ */ function(MessageType) {
50
50
  MessageType["UnregisterTrigger"] = "unregistertrigger";
51
51
  MessageType["UnregisterTriggerType"] = "unregistertriggertype";
52
52
  MessageType["TriggerRegistrationResult"] = "triggerregistrationresult";
53
+ MessageType["RegistrationRejected"] = "registrationrejected";
53
54
  MessageType["WorkerRegistered"] = "workerregistered";
54
55
  MessageType["Reattach"] = "reattach";
55
56
  return MessageType;
@@ -57,6 +58,13 @@ let MessageType = /* @__PURE__ */ function(MessageType) {
57
58
 
58
59
  //#endregion
59
60
  //#region src/iii.ts
61
+ /** Short random suffix; `crypto.randomUUID` is unavailable on insecure origins. */
62
+ function randomId() {
63
+ const c = globalThis.crypto;
64
+ if (c?.randomUUID) return c.randomUUID().slice(0, 8);
65
+ if (c?.getRandomValues) return Array.from(c.getRandomValues(new Uint8Array(4))).map((b) => b.toString(16).padStart(2, "0")).join("");
66
+ return Math.random().toString(16).slice(2, 10);
67
+ }
60
68
  var Sdk = class {
61
69
  constructor(address, options) {
62
70
  this.address = address;
@@ -161,13 +169,14 @@ var Sdk = class {
161
169
  };
162
170
  };
163
171
  this.trigger = async (request) => {
164
- const { function_id, payload, action, timeoutMs } = request;
172
+ const { function_id, payload, action, timeoutMs, namespace } = request;
165
173
  const effectiveTimeout = timeoutMs ?? this.invocationTimeoutMs;
166
174
  if (action?.type === "void") {
167
175
  this.sendMessage(MessageType.InvokeFunction, {
168
176
  function_id,
169
177
  data: payload,
170
- action
178
+ action,
179
+ ...namespace !== void 0 ? { namespace } : {}
171
180
  });
172
181
  return;
173
182
  }
@@ -194,7 +203,8 @@ var Sdk = class {
194
203
  invocation_id,
195
204
  function_id,
196
205
  data: payload,
197
- action
206
+ action,
207
+ ...namespace !== void 0 ? { namespace } : {}
198
208
  });
199
209
  });
200
210
  };
@@ -234,6 +244,8 @@ var Sdk = class {
234
244
  this.connectionListeners.delete(handler);
235
245
  };
236
246
  };
247
+ this.workerName = options?.workerName ?? `browser:${randomId()}`;
248
+ this.namespace = options?.namespace;
237
249
  this.invocationTimeoutMs = options?.invocationTimeoutMs ?? 3e4;
238
250
  this.reconnectionConfig = {
239
251
  ...DEFAULT_BRIDGE_RECONNECTION_CONFIG,
@@ -297,6 +309,7 @@ var Sdk = class {
297
309
  this.ws.onmessage = null;
298
310
  }
299
311
  this.ws = void 0;
312
+ if (this.isShuttingDown) return;
300
313
  this.setConnectionState("disconnected");
301
314
  this.scheduleReconnect();
302
315
  }
@@ -310,6 +323,7 @@ var Sdk = class {
310
323
  previous_worker_id: this.workerId,
311
324
  reattach_token: this.reattachToken
312
325
  }));
326
+ this.registerWorkerMetadata();
313
327
  this.triggerTypes.forEach(({ message }) => {
314
328
  this.sendMessage(MessageType.RegisterTriggerType, message, true);
315
329
  });
@@ -367,6 +381,23 @@ var Sdk = class {
367
381
  ...rest
368
382
  };
369
383
  }
384
+ /**
385
+ * Tells the engine who this connection is. Sent on every open, before any
386
+ * registration, so the engine can resolve this connection's namespace and
387
+ * drain its buffered registrations immediately.
388
+ */
389
+ registerWorkerMetadata() {
390
+ this.sendMessage(MessageType.InvokeFunction, {
391
+ function_id: EngineFunctions.REGISTER_WORKER,
392
+ data: {
393
+ runtime: "browser",
394
+ name: this.workerName,
395
+ os: globalThis.navigator?.userAgent ?? "browser",
396
+ ...this.namespace !== void 0 ? { namespace: this.namespace } : {}
397
+ },
398
+ action: { type: "void" }
399
+ });
400
+ }
370
401
  sendMessage(messageType, message, skipIfClosed = false) {
371
402
  const wireMessage = this.toWireFormat(messageType, message);
372
403
  if (this.isOpen()) this.sendMessageRaw(JSON.stringify(wireMessage));
@@ -514,12 +545,38 @@ var Sdk = class {
514
545
  this.onInvokeFunction(invocation_id, function_id, data, traceparent, baggage);
515
546
  } else if (msgType === MessageType.RegisterTrigger) this.onRegisterTrigger(message);
516
547
  else if (msgType === MessageType.UnregisterTrigger) this.onUnregisterTrigger(message);
548
+ else if (msgType === MessageType.RegistrationRejected) this.onRegistrationRejected(message);
517
549
  else if (msgType === MessageType.WorkerRegistered) {
518
550
  const { worker_id, reattach_token } = message;
519
551
  this.workerId = worker_id;
520
552
  this.reattachToken = reattach_token;
521
553
  }
522
554
  }
555
+ /**
556
+ * The engine rejected a registration. A `FUNCTION_NAMESPACE_CONFLICT` costs
557
+ * one function and leaves the connection open, so log and keep serving. A
558
+ * `WORKER_NAMESPACE_CONFLICT` means another live worker owns this name in the
559
+ * namespace: it is terminal — stop and do not reconnect (otherwise the engine
560
+ * would only reject the same name again, which with `maxRetries: -1` loops
561
+ * forever).
562
+ */
563
+ onRegistrationRejected(init) {
564
+ if (init.code === "FUNCTION_NAMESPACE_CONFLICT") {
565
+ console.warn(`[iii] Function registration rejected: function "${init.worker_name}" in namespace "${init.namespace}" is already exported by worker ${init.owner_worker_id}. Staying connected and serving the rest.`);
566
+ return;
567
+ }
568
+ console.error(`[iii] Registration rejected (${init.code}): worker "${init.worker_name}" in namespace "${init.namespace}" is already owned by ${init.owner_worker_id}. Not reconnecting.`);
569
+ this.isShuttingDown = true;
570
+ this.clearReconnectTimeout();
571
+ const error = /* @__PURE__ */ new Error(`[iii] Registration rejected (${init.code}): worker "${init.worker_name}" in namespace "${init.namespace}" is already owned by ${init.owner_worker_id}.`);
572
+ for (const [, invocation] of this.invocations) {
573
+ if (invocation.timeout) clearTimeout(invocation.timeout);
574
+ invocation.reject(error);
575
+ }
576
+ this.invocations.clear();
577
+ this.setConnectionState("failed");
578
+ this.ws?.close();
579
+ }
523
580
  };
524
581
  /**
525
582
  * Factory object that constructs routing actions for {@link ISdk.trigger}.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["randomUUID","ChannelWriter","ChannelReader","isChannelRef"],"sources":["../src/iii-constants.ts","../src/iii-types.ts","../src/iii.ts"],"sourcesContent":["/**\n * Constants for the III module.\n */\n\n/**\n * Engine function paths for internal operations.\n *\n * Naming note: `LIST_TRIGGERS` / `INFO_TRIGGERS` cover trigger TYPES\n * (templates). `LIST_REGISTERED_TRIGGERS` / `INFO_REGISTERED_TRIGGERS`\n * cover trigger INSTANCES (subscriber rows). The old\n * `engine::trigger-types::list` builtin has been removed and is now\n * served by `engine::triggers::list`.\n */\nexport const EngineFunctions = {\n LIST_FUNCTIONS: 'engine::functions::list',\n INFO_FUNCTIONS: 'engine::functions::info',\n LIST_WORKERS: 'engine::workers::list',\n INFO_WORKERS: 'engine::workers::info',\n LIST_TRIGGERS: 'engine::triggers::list',\n INFO_TRIGGERS: 'engine::triggers::info',\n LIST_REGISTERED_TRIGGERS: 'engine::registered-triggers::list',\n INFO_REGISTERED_TRIGGERS: 'engine::registered-triggers::info',\n REGISTER_WORKER: 'engine::workers::register',\n} as const\n\n/** Engine trigger types */\nexport const EngineTriggers = {\n FUNCTIONS_AVAILABLE: 'engine::functions-available',\n} as const\n\n/** Connection state for the III WebSocket */\nexport type IIIConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'failed'\n\n/** Configuration for WebSocket reconnection behavior */\nexport interface IIIReconnectionConfig {\n /** Starting delay in milliseconds (default: 1000ms) */\n initialDelayMs: number\n /** Maximum delay cap in milliseconds (default: 30000ms) */\n maxDelayMs: number\n /** Exponential backoff multiplier (default: 2) */\n backoffMultiplier: number\n /** Random jitter factor 0-1 (default: 0.3) */\n jitterFactor: number\n /** Maximum retry attempts, -1 for infinite (default: -1) */\n maxRetries: number\n}\n\n/** Default reconnection configuration */\nexport const DEFAULT_BRIDGE_RECONNECTION_CONFIG: IIIReconnectionConfig = {\n initialDelayMs: 1000,\n maxDelayMs: 30000,\n backoffMultiplier: 2,\n jitterFactor: 0.3,\n maxRetries: -1,\n}\n\n/** Default invocation timeout in milliseconds */\nexport const DEFAULT_INVOCATION_TIMEOUT_MS = 30000\n","export enum MessageType {\n RegisterFunction = 'registerfunction',\n UnregisterFunction = 'unregisterfunction',\n InvokeFunction = 'invokefunction',\n InvocationResult = 'invocationresult',\n RegisterTriggerType = 'registertriggertype',\n RegisterTrigger = 'registertrigger',\n UnregisterTrigger = 'unregistertrigger',\n UnregisterTriggerType = 'unregistertriggertype',\n TriggerRegistrationResult = 'triggerregistrationresult',\n WorkerRegistered = 'workerregistered',\n Reattach = 'reattach',\n}\n\nexport type RegisterTriggerTypeMessage = {\n message_type: MessageType.RegisterTriggerType\n /** Unique identifier for the trigger type (e.g. `state`, `durable:subscriber`). */\n id: string\n /** Human-readable description of what this trigger type does. */\n description: string\n}\n\nexport type UnregisterTriggerTypeMessage = {\n message_type: MessageType.UnregisterTriggerType\n id: string\n}\n\nexport type UnregisterTriggerMessage = {\n message_type: MessageType.UnregisterTrigger\n id: string\n type?: string\n}\n\nexport type TriggerRegistrationResultMessage = {\n message_type: MessageType.TriggerRegistrationResult\n id: string\n type: string\n function_id: string\n result?: unknown\n error?: unknown\n}\n\nexport type RegisterTriggerMessage = {\n /** Wire discriminator; always `MessageType.RegisterTrigger`. */\n message_type: MessageType.RegisterTrigger\n /** Unique trigger identifier, generated by the SDK during registration. */\n id: string\n /** Identifier of the registered trigger type this trigger uses (e.g. `storage::object-created`, `http`). */\n type: string\n /** ID of the function this trigger invokes when it fires. */\n function_id: string\n /** Trigger-type-specific configuration, matching the shape the trigger type expects. */\n config: unknown\n}\n\nexport type RegisterFunctionFormat = {\n /**\n * The name of the parameter\n */\n name?: string\n /**\n * The description of the parameter\n */\n description?: string\n /**\n * The type of the parameter\n */\n type?: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null' | 'map' | 'integer'\n /**\n * The body of the parameter (for objects)\n */\n properties?: Record<string, unknown>\n /**\n * The items of the parameter (for arrays)\n */\n items?: unknown\n /**\n * Whether the parameter is required\n */\n required?: string[]\n [key: string]: unknown\n}\n\nexport type RegisterFunctionMessage = {\n message_type: MessageType.RegisterFunction\n /**\n * The path of the function (use :: for namespacing, e.g. external::my_lambda)\n */\n id: string\n /**\n * The description of the function\n */\n description?: string\n /**\n * The request format of the function\n */\n request_format?: RegisterFunctionFormat\n /**\n * The response format of the function\n */\n response_format?: RegisterFunctionFormat\n metadata?: Record<string, unknown>\n}\n\n/**\n * Routing action for {@link TriggerRequest}. Determines how the engine\n * handles the invocation.\n *\n * - `enqueue`: Routes through a named queue for async processing.\n * - `void`: Fire-and-forget, no response.\n */\nexport type TriggerAction = { type: 'enqueue'; queue: string } | { type: 'void' }\n\n/**\n * Input passed to the RBAC auth function during WebSocket upgrade.\n * Contains the HTTP headers, query parameters, and client IP from the\n * connecting worker's upgrade request.\n */\nexport type AuthInput = {\n /** HTTP headers from the WebSocket upgrade request. */\n headers: Record<string, string>\n /** Query parameters from the upgrade URL. Each key maps to an array of values to support repeated keys. */\n query_params: Record<string, string[]>\n /** IP address of the connecting client. */\n ip_address: string\n}\n\n/**\n * Return value from the RBAC auth function. Controls which functions the\n * authenticated worker can invoke and what context is forwarded to the\n * middleware.\n */\nexport type AuthResult = {\n /** Additional function IDs to allow beyond the `expose_functions` config. Defaults to `[]` if omitted. */\n allowed_functions?: string[]\n /** Function IDs to deny even if they match `expose_functions`. Takes precedence over allowed. Defaults to `[]` if omitted. */\n forbidden_functions?: string[]\n /** Trigger type IDs the worker may register triggers for. When omitted, all types are allowed. */\n allowed_trigger_types?: string[]\n /** Whether the worker may register new trigger types. Defaults to `false` if omitted. */\n allow_trigger_type_registration?: boolean\n /** Whether the worker may register new functions. Defaults to `true` if omitted. */\n allow_function_registration?: boolean\n /** Arbitrary context forwarded to the middleware function on every invocation. Defaults to `{}` if omitted. */\n context?: Record<string, unknown>\n /** Optional prefix applied to all function IDs registered by this worker. */\n function_registration_prefix?: string\n}\n\n/**\n * Input passed to the RBAC middleware function on every function invocation\n * through the RBAC port. The middleware can inspect, modify, or reject the\n * call before it reaches the target function.\n */\nexport type MiddlewareFunctionInput = {\n /** ID of the function being invoked. */\n function_id: string\n /** Payload sent by the caller. */\n payload: Record<string, unknown>\n /** Routing action, if any. */\n action?: TriggerAction\n /** Auth context returned by the auth function for this session. */\n context: Record<string, unknown>\n}\n\n/**\n * Input passed to the `on_trigger_type_registration_function_id` hook\n * when a worker attempts to register a new trigger type through the RBAC port.\n * Return an {@link OnTriggerTypeRegistrationResult} with the (possibly mapped)\n * fields, or throw to deny the registration.\n */\nexport type OnTriggerTypeRegistrationInput = {\n /** ID of the trigger type being registered. */\n trigger_type_id: string\n /** Human-readable description of the trigger type. */\n description: string\n /** Auth context from `AuthResult.context` for this session. */\n context: Record<string, unknown>\n}\n\n/**\n * Result returned from the `on_trigger_type_registration_function_id` hook.\n * All fields are optional; omitted fields keep the original value from the\n * registration request.\n */\nexport type OnTriggerTypeRegistrationResult = {\n /** Mapped trigger type ID. */\n trigger_type_id?: string\n /** Mapped description. */\n description?: string\n}\n\n/**\n * Input passed to the `on_trigger_registration_function_id` hook\n * when a worker attempts to register a trigger through the RBAC port.\n * Return an {@link OnTriggerRegistrationResult} with the (possibly mapped)\n * fields, or throw to deny the registration.\n */\nexport type OnTriggerRegistrationInput = {\n /** ID of the trigger being registered. */\n trigger_id: string\n /** Trigger type identifier. */\n trigger_type: string\n /** ID of the function this trigger is bound to. */\n function_id: string\n /** Trigger-specific configuration. */\n config: unknown\n /** Auth context from `AuthResult.context` for this session. */\n context: Record<string, unknown>\n}\n\n/**\n * Result returned from the `on_trigger_registration_function_id` hook.\n * All fields are optional; omitted fields keep the original value from the\n * registration request.\n */\nexport type OnTriggerRegistrationResult = {\n /** Mapped trigger ID. */\n trigger_id?: string\n /** Mapped trigger type. */\n trigger_type?: string\n /** Mapped function ID. */\n function_id?: string\n /** Mapped trigger configuration. */\n config?: unknown\n}\n\n/**\n * Input passed to the `on_function_registration_function_id` hook\n * when a worker attempts to register a function through the RBAC port.\n * Return an {@link OnFunctionRegistrationResult} with the (possibly mapped)\n * fields, or throw to deny the registration.\n */\nexport type OnFunctionRegistrationInput = {\n /** ID of the function being registered. */\n function_id: string\n /** Human-readable description of the function. */\n description?: string\n /** Arbitrary metadata attached to the function. */\n metadata?: Record<string, unknown>\n /** Auth context from `AuthResult.context` for this session. */\n context: Record<string, unknown>\n}\n\n/**\n * Result returned from the `on_function_registration_function_id` hook.\n * All fields are optional; omitted fields keep the original value from the\n * registration request.\n */\nexport type OnFunctionRegistrationResult = {\n /** Mapped function ID. */\n function_id?: string\n /** Mapped description. */\n description?: string\n /** Mapped metadata. */\n metadata?: Record<string, unknown>\n}\n\n/**\n * Result returned when a function is invoked with `TriggerAction.Enqueue`.\n */\nexport type EnqueueResult = {\n /** Unique receipt ID for the enqueued message. */\n messageReceiptId: string\n}\n\n/**\n * Request object passed to {@link ISdk.trigger}.\n *\n * @typeParam TInput - Type of the payload.\n */\nexport type TriggerRequest<TInput = unknown> = {\n /** ID of the function to invoke. */\n function_id: string\n /** Input data passed to the function. */\n payload: TInput\n /** Sets how the trigger is routed. Omit for a synchronous request/response. Specify for a specific routing scheme (e.g. `TriggerAction.Enqueue()`, `TriggerAction.Void()`). */\n action?: TriggerAction\n /** Override the default invocation timeout, in milliseconds. */\n timeoutMs?: number\n}\n\nexport type InvokeFunctionMessage = {\n message_type: MessageType.InvokeFunction\n /**\n * This is optional for async invocations\n */\n invocation_id?: string\n /**\n * The path of the function\n */\n function_id: string\n /**\n * The data to pass to the function\n */\n data: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n /**\n * Trigger action for queue routing or fire-and-forget\n */\n action?: TriggerAction\n}\n\nexport type InvocationResultMessage = {\n message_type: MessageType.InvocationResult\n /**\n * The id of the invocation\n */\n invocation_id: string\n /**\n * The path of the function\n */\n function_id: string\n result?: unknown\n error?: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n}\n\nexport type UnregisterFunctionMessage = {\n message_type: MessageType.UnregisterFunction\n id: string\n}\n\n/**\n * Serializable reference to one end of a streaming channel. Can be included\n * in invocation payloads to pass channel endpoints between workers.\n */\nexport type StreamChannelRef = {\n /** Unique channel identifier. */\n channel_id: string\n /** Access key for authentication. */\n access_key: string\n /** Whether this ref is for reading or writing. */\n direction: 'read' | 'write'\n}\n\nexport type IIIMessage =\n | RegisterFunctionMessage\n | UnregisterFunctionMessage\n | InvokeFunctionMessage\n | InvocationResultMessage\n | RegisterTriggerMessage\n | RegisterTriggerTypeMessage\n | UnregisterTriggerMessage\n | UnregisterTriggerTypeMessage\n | TriggerRegistrationResultMessage\n","import { ChannelReader, ChannelWriter } from './channels'\nimport {\n DEFAULT_BRIDGE_RECONNECTION_CONFIG,\n DEFAULT_INVOCATION_TIMEOUT_MS,\n type IIIConnectionState,\n type IIIReconnectionConfig,\n} from './iii-constants'\nimport {\n type IIIMessage,\n type InvocationResultMessage,\n type InvokeFunctionMessage,\n MessageType,\n type RegisterFunctionMessage,\n type RegisterTriggerMessage,\n type RegisterTriggerTypeMessage,\n type StreamChannelRef,\n type TriggerRegistrationResultMessage,\n type TriggerRequest,\n} from './iii-types'\nimport type { IStream } from './stream'\nimport type { TriggerHandler } from './triggers'\nimport type {\n FunctionRef,\n Invocation,\n ISdk,\n RegisterFunctionOptions,\n RemoteFunctionData,\n RemoteFunctionHandler,\n RemoteTriggerTypeData,\n Trigger,\n TriggerTypeRef,\n} from './types'\nimport { isChannelRef, randomUUID } from './utils'\n\n/** @internal */\nexport type TelemetryOptions = {\n language?: string\n project_name?: string\n framework?: string\n amplitude_api_key?: string\n}\n\n/**\n * Configuration options passed to {@link registerWorker}.\n *\n * @example\n * ```typescript\n * const worker = registerWorker('ws://localhost:49135', {\n * invocationTimeoutMs: 10000,\n * reconnectionConfig: { maxRetries: 5 },\n * })\n * ```\n */\nexport type InitOptions = {\n /** Default timeout for `worker.trigger()` invocations in milliseconds. Defaults to `30000`. */\n invocationTimeoutMs?: number\n /**\n * WebSocket reconnection behavior.\n *\n * @see {@link IIIReconnectionConfig} for available fields and defaults.\n */\n reconnectionConfig?: Partial<IIIReconnectionConfig>\n /** Browser WebSocket connections authenticate via query parameters or cookies; the `headers` option is ignored. */\n headers?: Record<string, string>\n}\n\nclass Sdk implements ISdk {\n private ws?: WebSocket\n private functions = new Map<string, RemoteFunctionData>()\n private invocations = new Map<string, Invocation & { timeout?: ReturnType<typeof setTimeout> }>()\n private triggers = new Map<string, RegisterTriggerMessage>()\n private triggerTypes = new Map<string, RemoteTriggerTypeData>()\n private messagesToSend: Record<string, unknown>[] = []\n private reconnectTimeout?: ReturnType<typeof setTimeout>\n private invocationTimeoutMs: number\n private reconnectionConfig: IIIReconnectionConfig\n private reconnectAttempt = 0\n private connectionState: IIIConnectionState = 'disconnected'\n private connectionListeners = new Set<(state: IIIConnectionState) => void>()\n private isShuttingDown = false\n private workerId?: string\n private reattachToken?: string\n\n constructor(\n private readonly address: string,\n private readonly options?: InitOptions,\n ) {\n this.invocationTimeoutMs = options?.invocationTimeoutMs ?? DEFAULT_INVOCATION_TIMEOUT_MS\n this.reconnectionConfig = {\n ...DEFAULT_BRIDGE_RECONNECTION_CONFIG,\n ...options?.reconnectionConfig,\n }\n\n this.connect()\n }\n\n /**\n * Registers a custom trigger type with the engine. A trigger type defines\n * how external events (HTTP, cron, queue, etc.) map to function invocations.\n *\n * @param triggerType - Trigger type registration input.\n * @param triggerType.id - Unique trigger type identifier.\n * @param triggerType.description - Human-readable description.\n * @param handler - Handler with `registerTrigger` / `unregisterTrigger` callbacks.\n *\n * @example\n * ```typescript\n * worker.registerTriggerType(\n * { id: 'my-trigger', description: 'Custom trigger' },\n * {\n * async registerTrigger({ id, function_id, config }) { },\n * async unregisterTrigger({ id, function_id, config }) { },\n * },\n * )\n * ```\n */\n registerTriggerType = <TConfig>(\n triggerType: Omit<RegisterTriggerTypeMessage, 'message_type'>,\n handler: TriggerHandler<TConfig>,\n ): TriggerTypeRef<TConfig> => {\n this.sendMessage(MessageType.RegisterTriggerType, triggerType, true)\n this.triggerTypes.set(triggerType.id, {\n message: { ...triggerType, message_type: MessageType.RegisterTriggerType },\n handler,\n })\n\n return {\n id: triggerType.id,\n registerTrigger: (functionId: string, config: TConfig) => {\n return this.registerTrigger({\n type: triggerType.id,\n function_id: functionId,\n config,\n })\n },\n registerFunction: (functionId, handler, config) => {\n const ref = this.registerFunction(functionId, handler)\n this.registerTrigger({\n type: triggerType.id,\n function_id: functionId,\n config,\n })\n return ref\n },\n unregister: () => {\n this.unregisterTriggerType(triggerType)\n },\n }\n }\n\n /**\n * Unregisters a previously registered trigger type.\n *\n * @param triggerType - The trigger type to unregister (must match the `id` used during registration).\n */\n unregisterTriggerType = (triggerType: Omit<RegisterTriggerTypeMessage, 'message_type'>): void => {\n this.sendMessage(MessageType.UnregisterTriggerType, triggerType, true)\n this.triggerTypes.delete(triggerType.id)\n }\n\n /**\n * Binds a trigger configuration to a registered function. When the trigger\n * fires, the engine invokes the target function.\n *\n * @param trigger - Trigger registration input.\n * @param trigger.type - Trigger type (e.g. `http`, `durable:subscriber`, `cron`).\n * @param trigger.function_id - ID of the function to invoke.\n * @param trigger.config - Trigger-specific configuration.\n * @returns A {@link Trigger} handle with an `unregister()` method.\n *\n * @example\n * ```typescript\n * const trigger = worker.registerTrigger({\n * type: 'http',\n * function_id: 'greet',\n * config: { api_path: '/greet', http_method: 'GET' },\n * })\n *\n * // Later...\n * trigger.unregister()\n * ```\n */\n registerTrigger = (trigger: Omit<RegisterTriggerMessage, 'message_type' | 'id'>): Trigger => {\n const id = randomUUID()\n const fullTrigger: RegisterTriggerMessage = {\n ...trigger,\n id,\n message_type: MessageType.RegisterTrigger,\n }\n this.sendMessage(MessageType.RegisterTrigger, fullTrigger, true)\n this.triggers.set(id, fullTrigger)\n\n return {\n unregister: () => {\n this.sendMessage(MessageType.UnregisterTrigger, {\n id,\n message_type: MessageType.UnregisterTrigger,\n type: fullTrigger.type,\n })\n this.triggers.delete(id)\n },\n }\n }\n\n /**\n * Registers a function with the engine. The `functionId` is the unique identifier\n * used by triggers and invocations.\n *\n * The handler runs locally in the browser session; HTTP invocation configs\n * are a Node.js SDK feature and are not accepted here.\n *\n * @param functionId - Unique function identifier.\n * @param handlerOrInvocation - Async handler executed when the function is invoked.\n * @param options - Optional function registration options (description, request/response formats, metadata).\n * @returns A {@link FunctionRef} with `id` and `unregister()`.\n *\n * @example\n * ```typescript\n * const fn = worker.registerFunction(\n * 'greet',\n * async (input: { name: string }) => {\n * return { message: `Hello, ${input.name}!` }\n * },\n * { description: 'Greets a user' },\n * )\n * ```\n */\n registerFunction = (\n functionId: string,\n handlerOrInvocation: RemoteFunctionHandler,\n options?: RegisterFunctionOptions,\n ): FunctionRef => {\n if (!functionId || functionId.trim() === '') {\n throw new Error('id is required')\n }\n if (this.functions.has(functionId)) {\n throw new Error(`function id already registered: ${functionId}`)\n }\n\n const fullMessage: RegisterFunctionMessage = {\n ...options,\n id: functionId,\n message_type: MessageType.RegisterFunction,\n }\n\n this.sendMessage(MessageType.RegisterFunction, fullMessage, true)\n\n const handler = handlerOrInvocation as RemoteFunctionHandler\n this.functions.set(functionId, {\n message: fullMessage,\n handler: async (input, _traceparent?: string, _baggage?: string) => {\n return await handler(input)\n },\n })\n\n return {\n id: functionId,\n unregister: () => {\n this.sendMessage(MessageType.UnregisterFunction, { id: functionId }, true)\n this.functions.delete(functionId)\n },\n }\n }\n\n /**\n * @internal Implementation backing the `createChannel` helper in the\n * `iii-browser-sdk/helpers` submodule. Not part of the public `ISdk` surface.\n *\n * Creates a streaming channel pair for worker-to-worker data transfer.\n * Returns a {@link Channel} with a local writer/reader and serializable refs\n * that can be passed as fields in invocation data to other functions.\n */\n __helpers_create_channel = async (bufferSize?: number): Promise<import('./types').Channel> => {\n const result = await this.trigger<{ buffer_size?: number }, { writer: StreamChannelRef; reader: StreamChannelRef }>(\n { function_id: 'engine::channels::create', payload: { buffer_size: bufferSize } },\n )\n\n return {\n writer: new ChannelWriter(this.address, result.writer),\n reader: new ChannelReader(this.address, result.reader),\n writerRef: result.writer,\n readerRef: result.reader,\n }\n }\n\n /**\n * Invokes a remote function. The routing behavior and return type depend\n * on the `action` field of the request.\n *\n * | `action` | Behavior | Return type |\n * |-------------------------------|----------------------------------------------------|----------------------- |\n * | _(none)_ | Synchronous: waits for the function to return | `Promise<TOutput>` |\n * | `TriggerAction.Enqueue(...)` | Async via named queue; engine acknowledges enqueue | `Promise<EnqueueResult>` |\n * | `TriggerAction.Void()` | Fire-and-forget, no response | `Promise<undefined>` |\n *\n * @param request - The trigger request.\n * @param request.function_id - ID of the function to invoke.\n * @param request.payload - Payload to pass to the function.\n * @param request.action - Routing action. Omit for synchronous request/response.\n * @param request.timeoutMs - Override the default invocation timeout.\n * @returns The result of the function invocation.\n *\n * @example\n * ```typescript\n * import { TriggerAction } from 'iii-browser-sdk'\n *\n * // Synchronous\n * const result = await worker.trigger({ function_id: 'get-order', payload: { id: '123' } })\n *\n * // Enqueue\n * const { messageReceiptId } = await worker.trigger({\n * function_id: 'payments::charge',\n * payload: { orderId: '123', amount: 49.99 },\n * action: TriggerAction.Enqueue({ queue: 'payment' }),\n * })\n *\n * // Fire-and-forget\n * worker.trigger({\n * function_id: 'notifications::send',\n * payload: { userId: '123' },\n * action: TriggerAction.Void(),\n * })\n * ```\n */\n // biome-ignore lint/suspicious/noExplicitAny: TOutput defaults to any so untyped calls type-check (the engine cannot express the return type statically)\n trigger = async <TInput = unknown, TOutput = any>(\n request: TriggerRequest<TInput>,\n ): Promise<TOutput> => {\n const { function_id, payload, action, timeoutMs } = request\n const effectiveTimeout = timeoutMs ?? this.invocationTimeoutMs\n\n if (action?.type === 'void') {\n this.sendMessage(MessageType.InvokeFunction, {\n function_id,\n data: payload,\n action,\n })\n return undefined as TOutput\n }\n\n const invocation_id = randomUUID()\n\n return new Promise<TOutput>((resolve, reject) => {\n const timeout = setTimeout(() => {\n const invocation = this.invocations.get(invocation_id)\n if (invocation) {\n this.invocations.delete(invocation_id)\n reject(new Error(`Invocation timeout after ${effectiveTimeout}ms: ${function_id}`))\n }\n }, effectiveTimeout)\n\n this.invocations.set(invocation_id, {\n resolve: (result: TOutput) => {\n clearTimeout(timeout)\n resolve(result)\n },\n reject: (error: unknown) => {\n clearTimeout(timeout)\n reject(error)\n },\n timeout,\n })\n\n this.sendMessage(MessageType.InvokeFunction, {\n invocation_id,\n function_id,\n data: payload,\n action,\n })\n })\n }\n\n /**\n * @internal Implementation backing the `createStream` helper in the\n * `iii-browser-sdk/helpers` submodule. Not part of the public `ISdk` surface.\n *\n * Registers a custom stream implementation, overriding the engine default\n * for the given stream name.\n */\n __helpers_create_stream = <TData>(streamName: string, stream: IStream<TData>): void => {\n this.registerFunction(`stream::get(${streamName})`, stream.get.bind(stream))\n this.registerFunction(`stream::set(${streamName})`, stream.set.bind(stream))\n this.registerFunction(`stream::delete(${streamName})`, stream.delete.bind(stream))\n this.registerFunction(`stream::list(${streamName})`, stream.list.bind(stream))\n this.registerFunction(`stream::list_groups(${streamName})`, stream.listGroups.bind(stream))\n }\n\n /**\n * Gracefully shutdown the SDK, cleaning up all resources.\n */\n shutdown = async (): Promise<void> => {\n this.isShuttingDown = true\n\n this.clearReconnectTimeout()\n\n for (const [_id, invocation] of this.invocations) {\n if (invocation.timeout) {\n clearTimeout(invocation.timeout)\n }\n invocation.reject(new Error('iii is shutting down'))\n }\n this.invocations.clear()\n\n if (this.ws) {\n this.ws.onopen = null\n this.ws.onclose = null\n this.ws.onerror = null\n this.ws.onmessage = null\n this.ws.close()\n this.ws = undefined\n }\n\n this.setConnectionState('disconnected')\n }\n\n /**\n * Subscribe to connection-state transitions. The handler is fired immediately\n * with the current state, then on every transition. Multiple listeners are\n * supported. Returns an unsubscribe function.\n */\n addConnectionStateListener = (handler: (state: IIIConnectionState) => void): (() => void) => {\n this.connectionListeners.add(handler)\n try {\n handler(this.connectionState)\n } catch (e) {\n console.error('[iii] connection listener threw on initial fire', e)\n }\n return () => {\n this.connectionListeners.delete(handler)\n }\n }\n\n // private methods\n\n private setConnectionState(state: IIIConnectionState): void {\n if (this.connectionState !== state) {\n this.connectionState = state\n for (const handler of this.connectionListeners) {\n try {\n handler(state)\n } catch (e) {\n console.error('[iii] connection listener threw', e)\n }\n }\n }\n }\n\n private connect(): void {\n if (this.isShuttingDown) {\n return\n }\n\n this.setConnectionState('connecting')\n this.ws = new WebSocket(this.address)\n this.ws.onopen = this.onSocketOpen.bind(this)\n this.ws.onclose = this.onSocketClose.bind(this)\n this.ws.onerror = this.onSocketError.bind(this)\n }\n\n private clearReconnectTimeout(): void {\n if (this.reconnectTimeout) {\n clearTimeout(this.reconnectTimeout)\n this.reconnectTimeout = undefined\n }\n }\n\n private scheduleReconnect(): void {\n if (this.isShuttingDown) {\n return\n }\n\n const { maxRetries, initialDelayMs, backoffMultiplier, maxDelayMs, jitterFactor } = this.reconnectionConfig\n\n if (maxRetries !== -1 && this.reconnectAttempt >= maxRetries) {\n this.setConnectionState('failed')\n console.error(`[iii] Max reconnection retries (${maxRetries}) reached, giving up`)\n return\n }\n\n if (this.reconnectTimeout) {\n return\n }\n\n const exponentialDelay = initialDelayMs * backoffMultiplier ** this.reconnectAttempt\n const cappedDelay = Math.min(exponentialDelay, maxDelayMs)\n const jitter = cappedDelay * jitterFactor * (2 * Math.random() - 1)\n const delay = Math.floor(cappedDelay + jitter)\n\n this.setConnectionState('reconnecting')\n console.debug(`[iii] Reconnecting in ${delay}ms (attempt ${this.reconnectAttempt + 1})...`)\n\n this.reconnectTimeout = setTimeout(() => {\n this.reconnectTimeout = undefined\n this.reconnectAttempt++\n this.connect()\n }, delay)\n }\n\n private onSocketError(): void {\n console.error('[iii] WebSocket error')\n }\n\n private onSocketClose(): void {\n if (this.ws) {\n this.ws.onopen = null\n this.ws.onclose = null\n this.ws.onerror = null\n this.ws.onmessage = null\n }\n this.ws = undefined\n\n this.setConnectionState('disconnected')\n this.scheduleReconnect()\n }\n\n private onSocketOpen(): void {\n this.clearReconnectTimeout()\n this.reconnectAttempt = 0\n this.setConnectionState('connected')\n\n if (this.ws) {\n this.ws.onmessage = this.onMessage.bind(this)\n }\n\n // Reconnect: present the previous engine-assigned identity BEFORE the\n // registration replay so the engine retires the old connection and the\n // replay lands on a clean slate instead of racing its cleanup. The\n // token proves we ARE that worker (ids alone are publicly listable).\n if (this.workerId) {\n this.sendMessageRaw(\n JSON.stringify({\n type: MessageType.Reattach,\n previous_worker_id: this.workerId,\n reattach_token: this.reattachToken,\n }),\n )\n }\n\n this.triggerTypes.forEach(({ message }) => {\n this.sendMessage(MessageType.RegisterTriggerType, message, true)\n })\n this.functions.forEach(({ message }) => {\n this.sendMessage(MessageType.RegisterFunction, message, true)\n })\n this.triggers.forEach((trigger) => {\n this.sendMessage(MessageType.RegisterTrigger, trigger, true)\n })\n\n const pending = this.messagesToSend\n this.messagesToSend = []\n for (const message of pending) {\n if (\n message.type === MessageType.InvokeFunction &&\n typeof message.invocation_id === 'string' &&\n !this.invocations.has(message.invocation_id)\n ) {\n continue\n }\n this.sendMessageRaw(JSON.stringify(message))\n }\n }\n\n private isOpen(): boolean {\n return this.ws?.readyState === WebSocket.OPEN\n }\n\n private sendMessageRaw(data: string): void {\n if (this.ws && this.isOpen()) {\n try {\n this.ws.send(data)\n } catch (error) {\n console.error('[iii] Exception while sending message', error)\n }\n }\n }\n\n private toWireFormat(messageType: MessageType, message: Omit<IIIMessage, 'message_type'>): Record<string, unknown> {\n const { message_type: _, ...rest } = message as Record<string, unknown>\n if (messageType === MessageType.RegisterTrigger && 'type' in message) {\n const { type: triggerType, ...triggerRest } = message as RegisterTriggerMessage\n return { type: messageType, ...triggerRest, trigger_type: triggerType }\n }\n if (messageType === MessageType.UnregisterTrigger && 'type' in message) {\n const { type: triggerType, ...triggerRest } = message as RegisterTriggerMessage\n return { type: messageType, ...triggerRest, trigger_type: triggerType }\n }\n if (messageType === MessageType.TriggerRegistrationResult && 'type' in message) {\n const { type: triggerType, ...resultRest } = message as TriggerRegistrationResultMessage\n return { type: messageType, ...resultRest, trigger_type: triggerType }\n }\n return { type: messageType, ...rest } as Record<string, unknown>\n }\n\n private sendMessage(messageType: MessageType, message: Omit<IIIMessage, 'message_type'>, skipIfClosed = false): void {\n const wireMessage = this.toWireFormat(messageType, message)\n if (this.isOpen()) {\n this.sendMessageRaw(JSON.stringify(wireMessage))\n } else if (!skipIfClosed) {\n this.messagesToSend.push(wireMessage)\n }\n }\n\n private onInvocationResult(invocation_id: string, result: unknown, error: unknown): void {\n const invocation = this.invocations.get(invocation_id)\n\n if (invocation) {\n if (invocation.timeout) {\n clearTimeout(invocation.timeout)\n }\n error ? invocation.reject(error) : invocation.resolve(result)\n }\n\n this.invocations.delete(invocation_id)\n }\n\n private resolveChannelValue(value: unknown): unknown {\n if (isChannelRef(value)) {\n return value.direction === 'read'\n ? new ChannelReader(this.address, value)\n : new ChannelWriter(this.address, value)\n }\n if (Array.isArray(value)) {\n return value.map((item) => this.resolveChannelValue(item))\n }\n if (value !== null && typeof value === 'object') {\n const out: Record<string, unknown> = {}\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n out[k] = this.resolveChannelValue(v)\n }\n return out\n }\n return value\n }\n\n private async onInvokeFunction<TInput>(\n invocation_id: string | undefined,\n function_id: string,\n input: TInput,\n traceparent?: string,\n baggage?: string,\n ): Promise<unknown> {\n const fn = this.functions.get(function_id)\n\n const resolvedInput = this.resolveChannelValue(input) as TInput\n\n if (fn?.handler) {\n if (!invocation_id) {\n try {\n await fn.handler(resolvedInput, traceparent, baggage)\n } catch (error) {\n console.error(`[iii] Error invoking function ${function_id}`, error)\n }\n return\n }\n\n try {\n const result = await fn.handler(resolvedInput, traceparent, baggage)\n this.sendMessage(MessageType.InvocationResult, {\n invocation_id,\n function_id,\n result,\n traceparent,\n baggage,\n })\n } catch (error) {\n const isError = error instanceof Error\n this.sendMessage(MessageType.InvocationResult, {\n invocation_id,\n function_id,\n error: {\n code: 'invocation_failed',\n message: isError ? error.message : String(error),\n stacktrace: isError ? error.stack : undefined,\n },\n traceparent,\n baggage,\n })\n }\n } else {\n const errorCode = fn ? 'function_not_invokable' : 'function_not_found'\n const errorMessage = fn ? 'Function is HTTP-invoked and cannot be invoked locally' : 'Function not found'\n if (invocation_id) {\n this.sendMessage(MessageType.InvocationResult, {\n invocation_id,\n function_id,\n error: { code: errorCode, message: errorMessage },\n traceparent,\n baggage,\n })\n }\n }\n }\n\n private async onRegisterTrigger(message: { trigger_type: string; id: string; function_id: string; config: unknown }) {\n const { trigger_type, id, function_id, config } = message\n const triggerTypeData = this.triggerTypes.get(trigger_type)\n\n if (triggerTypeData) {\n try {\n await triggerTypeData.handler.registerTrigger({ id, function_id, config })\n this.sendMessage(MessageType.TriggerRegistrationResult, {\n id,\n message_type: MessageType.TriggerRegistrationResult,\n type: trigger_type,\n function_id,\n })\n } catch (error) {\n this.sendMessage(MessageType.TriggerRegistrationResult, {\n id,\n message_type: MessageType.TriggerRegistrationResult,\n type: trigger_type,\n function_id,\n error: { code: 'trigger_registration_failed', message: (error as Error).message },\n })\n }\n } else {\n this.sendMessage(MessageType.TriggerRegistrationResult, {\n id,\n message_type: MessageType.TriggerRegistrationResult,\n type: trigger_type,\n function_id,\n error: { code: 'trigger_type_not_found', message: 'Trigger type not found' },\n })\n }\n }\n\n private async onUnregisterTrigger(message: {\n trigger_type?: string\n id: string\n function_id?: string\n config?: unknown\n }) {\n const trigger_type = message.trigger_type\n if (!trigger_type) return\n\n const triggerTypeData = this.triggerTypes.get(trigger_type)\n if (!triggerTypeData) return\n\n const { id, function_id = '', config } = message\n try {\n await triggerTypeData.handler.unregisterTrigger({ id, function_id, config })\n } catch (error) {\n console.error(`[iii] Error unregistering trigger ${id}`, error)\n }\n }\n\n private onMessage(event: MessageEvent): void {\n let msgType: MessageType\n let message: Record<string, unknown>\n\n try {\n const parsed = JSON.parse(typeof event.data === 'string' ? event.data : '') as Record<string, unknown>\n msgType = parsed.type as MessageType\n const { type: _, ...rest } = parsed\n message = rest\n } catch (error) {\n console.error('[iii] Failed to parse incoming message', error)\n return\n }\n\n if (msgType === MessageType.InvocationResult) {\n const { invocation_id, result, error } = message as InvocationResultMessage\n this.onInvocationResult(invocation_id, result, error)\n } else if (msgType === MessageType.InvokeFunction) {\n const { invocation_id, function_id, data, traceparent, baggage } = message as InvokeFunctionMessage\n this.onInvokeFunction(invocation_id, function_id, data, traceparent, baggage)\n } else if (msgType === MessageType.RegisterTrigger) {\n this.onRegisterTrigger(message as { trigger_type: string; id: string; function_id: string; config: unknown })\n } else if (msgType === MessageType.UnregisterTrigger) {\n this.onUnregisterTrigger(\n message as { trigger_type?: string; id: string; function_id?: string; config?: unknown },\n )\n } else if (msgType === MessageType.WorkerRegistered) {\n const { worker_id, reattach_token } = message as { worker_id: string; reattach_token?: string }\n this.workerId = worker_id\n this.reattachToken = reattach_token\n }\n }\n}\n\n/**\n * Factory object that constructs routing actions for {@link ISdk.trigger}.\n *\n * @example\n * ```typescript\n * import { TriggerAction } from 'iii-browser-sdk'\n *\n * // Enqueue to a named queue\n * worker.trigger({\n * function_id: 'process',\n * payload: { data: 'hello' },\n * action: TriggerAction.Enqueue({ queue: 'jobs' }),\n * })\n *\n * // Fire-and-forget\n * worker.trigger({\n * function_id: 'notify',\n * payload: {},\n * action: TriggerAction.Void(),\n * })\n * ```\n */\nexport const TriggerAction = {\n /**\n * Routes the invocation through a named queue. The engine enqueues the job,\n * acknowledges the caller with `{ messageReceiptId }`, and processes it\n * asynchronously.\n *\n * @param opts - Queue routing options.\n * @param opts.queue - Name of the target queue.\n */\n Enqueue: (opts: { queue: string }) => ({ type: 'enqueue' as const, ...opts }),\n /**\n * Fire-and-forget routing. The engine forwards the invocation without\n * waiting for a response or queuing the job.\n */\n Void: () => ({ type: 'void' as const }),\n} as const\n\n/**\n * Register the worker with a iii instance, returns a connected worker client.\n * The WebSocket connection is established automatically.\n *\n * @param address - WebSocket URL of the III engine (e.g. `ws://localhost:49135`).\n * @param options - Optional {@link InitOptions} for worker name, timeouts, and reconnection.\n * @returns A connected {@link ISdk} instance.\n *\n * @example\n * ```typescript\n * import { registerWorker } from 'iii-browser-sdk'\n *\n * const worker = registerWorker('ws://localhost:49135')\n * ```\n */\nexport const registerWorker = (address: string, options?: InitOptions): ISdk => new Sdk(address, options)\n"],"mappings":";;;;;;;;;;;;;;;;AAaA,MAAa,kBAAkB;CAC7B,gBAAgB;CAChB,gBAAgB;CAChB,cAAc;CACd,cAAc;CACd,eAAe;CACf,eAAe;CACf,0BAA0B;CAC1B,0BAA0B;CAC1B,iBAAiB;CAClB;;AAGD,MAAa,iBAAiB,EAC5B,qBAAqB,+BACtB;;AAoBD,MAAa,qCAA4D;CACvE,gBAAgB;CAChB,YAAY;CACZ,mBAAmB;CACnB,cAAc;CACd,YAAY;CACb;;AAGD,MAAa,gCAAgC;;;;ACzD7C,IAAY,cAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;KACD;;;;ACsDD,IAAM,MAAN,MAA0B;CAiBxB,YACE,AAAiB,SACjB,AAAiB,SACjB;EAFiB;EACA;mCAjBC,IAAI,KAAiC;qCACnC,IAAI,KAAuE;kCAC9E,IAAI,KAAqC;sCACrC,IAAI,KAAoC;wBACX,EAAE;0BAI3B;y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AAgB;;;;;;;;;;;;;;;;;;;;;;;;;;AA2B3B,MAAa,gBAAgB;CAS3B,UAAU,UAA6B;EAAE,MAAM;EAAoB,GAAG;EAAM;CAK5E,aAAa,EAAE,MAAM,QAAiB;CACvC;;;;;;;;;;;;;;;;AAiBD,MAAa,kBAAkB,SAAiB,YAAgC,IAAI,IAAI,SAAS,QAAQ"}
1
+ {"version":3,"file":"index.cjs","names":["randomUUID","ChannelWriter","ChannelReader","isChannelRef"],"sources":["../src/iii-constants.ts","../src/iii-types.ts","../src/iii.ts"],"sourcesContent":["/**\n * Constants for the III module.\n */\n\n/**\n * Engine function paths for internal operations.\n *\n * Naming note: `LIST_TRIGGERS` / `INFO_TRIGGERS` cover trigger TYPES\n * (templates). `LIST_REGISTERED_TRIGGERS` / `INFO_REGISTERED_TRIGGERS`\n * cover trigger INSTANCES (subscriber rows). The old\n * `engine::trigger-types::list` builtin has been removed and is now\n * served by `engine::triggers::list`.\n */\nexport const EngineFunctions = {\n LIST_FUNCTIONS: 'engine::functions::list',\n INFO_FUNCTIONS: 'engine::functions::info',\n LIST_WORKERS: 'engine::workers::list',\n INFO_WORKERS: 'engine::workers::info',\n LIST_TRIGGERS: 'engine::triggers::list',\n INFO_TRIGGERS: 'engine::triggers::info',\n LIST_REGISTERED_TRIGGERS: 'engine::registered-triggers::list',\n INFO_REGISTERED_TRIGGERS: 'engine::registered-triggers::info',\n REGISTER_WORKER: 'engine::workers::register',\n} as const\n\n/** Engine trigger types */\nexport const EngineTriggers = {\n FUNCTIONS_AVAILABLE: 'engine::functions-available',\n} as const\n\n/** Connection state for the III WebSocket */\nexport type IIIConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'failed'\n\n/** Configuration for WebSocket reconnection behavior */\nexport interface IIIReconnectionConfig {\n /** Starting delay in milliseconds (default: 1000ms) */\n initialDelayMs: number\n /** Maximum delay cap in milliseconds (default: 30000ms) */\n maxDelayMs: number\n /** Exponential backoff multiplier (default: 2) */\n backoffMultiplier: number\n /** Random jitter factor 0-1 (default: 0.3) */\n jitterFactor: number\n /** Maximum retry attempts, -1 for infinite (default: -1) */\n maxRetries: number\n}\n\n/** Default reconnection configuration */\nexport const DEFAULT_BRIDGE_RECONNECTION_CONFIG: IIIReconnectionConfig = {\n initialDelayMs: 1000,\n maxDelayMs: 30000,\n backoffMultiplier: 2,\n jitterFactor: 0.3,\n maxRetries: -1,\n}\n\n/** Default invocation timeout in milliseconds */\nexport const DEFAULT_INVOCATION_TIMEOUT_MS = 30000\n","export enum MessageType {\n RegisterFunction = 'registerfunction',\n UnregisterFunction = 'unregisterfunction',\n InvokeFunction = 'invokefunction',\n InvocationResult = 'invocationresult',\n RegisterTriggerType = 'registertriggertype',\n RegisterTrigger = 'registertrigger',\n UnregisterTrigger = 'unregistertrigger',\n UnregisterTriggerType = 'unregistertriggertype',\n TriggerRegistrationResult = 'triggerregistrationresult',\n RegistrationRejected = 'registrationrejected',\n WorkerRegistered = 'workerregistered',\n Reattach = 'reattach',\n}\n\nexport type RegisterTriggerTypeMessage = {\n message_type: MessageType.RegisterTriggerType\n /** Unique identifier for the trigger type (e.g. `state`, `durable:subscriber`). */\n id: string\n /** Human-readable description of what this trigger type does. */\n description: string\n}\n\nexport type UnregisterTriggerTypeMessage = {\n message_type: MessageType.UnregisterTriggerType\n id: string\n}\n\nexport type UnregisterTriggerMessage = {\n message_type: MessageType.UnregisterTrigger\n id: string\n type?: string\n}\n\nexport type TriggerRegistrationResultMessage = {\n message_type: MessageType.TriggerRegistrationResult\n id: string\n type: string\n function_id: string\n result?: unknown\n error?: unknown\n}\n\nexport type RegisterTriggerMessage = {\n /** Wire discriminator; always `MessageType.RegisterTrigger`. */\n message_type: MessageType.RegisterTrigger\n /** Unique trigger identifier, generated by the SDK during registration. */\n id: string\n /** Identifier of the registered trigger type this trigger uses (e.g. `storage::object-created`, `http`). */\n type: string\n /** ID of the function this trigger invokes when it fires. */\n function_id: string\n /** Trigger-type-specific configuration, matching the shape the trigger type expects. */\n config: unknown\n}\n\nexport type RegisterFunctionFormat = {\n /**\n * The name of the parameter\n */\n name?: string\n /**\n * The description of the parameter\n */\n description?: string\n /**\n * The type of the parameter\n */\n type?: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null' | 'map' | 'integer'\n /**\n * The body of the parameter (for objects)\n */\n properties?: Record<string, unknown>\n /**\n * The items of the parameter (for arrays)\n */\n items?: unknown\n /**\n * Whether the parameter is required\n */\n required?: string[]\n [key: string]: unknown\n}\n\nexport type RegisterFunctionMessage = {\n message_type: MessageType.RegisterFunction\n /**\n * The path of the function (use :: for namespacing, e.g. external::my_lambda)\n */\n id: string\n /**\n * The description of the function\n */\n description?: string\n /**\n * The request format of the function\n */\n request_format?: RegisterFunctionFormat\n /**\n * The response format of the function\n */\n response_format?: RegisterFunctionFormat\n metadata?: Record<string, unknown>\n}\n\n/**\n * Routing action for {@link TriggerRequest}. Determines how the engine\n * handles the invocation.\n *\n * - `enqueue`: Routes through a named queue for async processing.\n * - `void`: Fire-and-forget, no response.\n */\nexport type TriggerAction = { type: 'enqueue'; queue: string } | { type: 'void' }\n\n/**\n * Input passed to the RBAC auth function during WebSocket upgrade.\n * Contains the HTTP headers, query parameters, and client IP from the\n * connecting worker's upgrade request.\n */\nexport type AuthInput = {\n /** HTTP headers from the WebSocket upgrade request. */\n headers: Record<string, string>\n /** Query parameters from the upgrade URL. Each key maps to an array of values to support repeated keys. */\n query_params: Record<string, string[]>\n /** IP address of the connecting client. */\n ip_address: string\n}\n\n/**\n * Return value from the RBAC auth function. Controls which functions the\n * authenticated worker can invoke and what context is forwarded to the\n * middleware.\n */\nexport type AuthResult = {\n /** Additional function IDs to allow beyond the `expose_functions` config. Defaults to `[]` if omitted. */\n allowed_functions?: string[]\n /** Function IDs to deny even if they match `expose_functions`. Takes precedence over allowed. Defaults to `[]` if omitted. */\n forbidden_functions?: string[]\n /** Trigger type IDs the worker may register triggers for. When omitted, all types are allowed. */\n allowed_trigger_types?: string[]\n /** Whether the worker may register new trigger types. Defaults to `false` if omitted. */\n allow_trigger_type_registration?: boolean\n /** Whether the worker may register new functions. Defaults to `true` if omitted. */\n allow_function_registration?: boolean\n /** Arbitrary context forwarded to the middleware function on every invocation. Defaults to `{}` if omitted. */\n context?: Record<string, unknown>\n /** Optional prefix applied to all function IDs registered by this worker. */\n function_registration_prefix?: string\n}\n\n/**\n * Input passed to the RBAC middleware function on every function invocation\n * through the RBAC port. The middleware can inspect, modify, or reject the\n * call before it reaches the target function.\n */\nexport type MiddlewareFunctionInput = {\n /** ID of the function being invoked. */\n function_id: string\n /** Payload sent by the caller. */\n payload: Record<string, unknown>\n /** Routing action, if any. */\n action?: TriggerAction\n /** Auth context returned by the auth function for this session. */\n context: Record<string, unknown>\n /**\n * Target namespace the invoke addressed; forward the call here to stay in the\n * caller's namespace. Absent → the engine's default namespace.\n */\n namespace?: string\n}\n\n/**\n * Input passed to the `on_trigger_type_registration_function_id` hook\n * when a worker attempts to register a new trigger type through the RBAC port.\n * Return an {@link OnTriggerTypeRegistrationResult} with the (possibly mapped)\n * fields, or throw to deny the registration.\n */\nexport type OnTriggerTypeRegistrationInput = {\n /** ID of the trigger type being registered. */\n trigger_type_id: string\n /** Human-readable description of the trigger type. */\n description: string\n /** Auth context from `AuthResult.context` for this session. */\n context: Record<string, unknown>\n}\n\n/**\n * Result returned from the `on_trigger_type_registration_function_id` hook.\n * All fields are optional; omitted fields keep the original value from the\n * registration request.\n */\nexport type OnTriggerTypeRegistrationResult = {\n /** Mapped trigger type ID. */\n trigger_type_id?: string\n /** Mapped description. */\n description?: string\n}\n\n/**\n * Input passed to the `on_trigger_registration_function_id` hook\n * when a worker attempts to register a trigger through the RBAC port.\n * Return an {@link OnTriggerRegistrationResult} with the (possibly mapped)\n * fields, or throw to deny the registration.\n */\nexport type OnTriggerRegistrationInput = {\n /** ID of the trigger being registered. */\n trigger_id: string\n /** Trigger type identifier. */\n trigger_type: string\n /** ID of the function this trigger is bound to. */\n function_id: string\n /** Trigger-specific configuration. */\n config: unknown\n /** Auth context from `AuthResult.context` for this session. */\n context: Record<string, unknown>\n}\n\n/**\n * Result returned from the `on_trigger_registration_function_id` hook.\n * All fields are optional; omitted fields keep the original value from the\n * registration request.\n */\nexport type OnTriggerRegistrationResult = {\n /** Mapped trigger ID. */\n trigger_id?: string\n /** Mapped trigger type. */\n trigger_type?: string\n /** Mapped function ID. */\n function_id?: string\n /** Mapped trigger configuration. */\n config?: unknown\n}\n\n/**\n * Input passed to the `on_function_registration_function_id` hook\n * when a worker attempts to register a function through the RBAC port.\n * Return an {@link OnFunctionRegistrationResult} with the (possibly mapped)\n * fields, or throw to deny the registration.\n */\nexport type OnFunctionRegistrationInput = {\n /** ID of the function being registered. */\n function_id: string\n /** Human-readable description of the function. */\n description?: string\n /** Arbitrary metadata attached to the function. */\n metadata?: Record<string, unknown>\n /** Auth context from `AuthResult.context` for this session. */\n context: Record<string, unknown>\n}\n\n/**\n * Result returned from the `on_function_registration_function_id` hook.\n * All fields are optional; omitted fields keep the original value from the\n * registration request.\n */\nexport type OnFunctionRegistrationResult = {\n /** Mapped function ID. */\n function_id?: string\n /** Mapped description. */\n description?: string\n /** Mapped metadata. */\n metadata?: Record<string, unknown>\n}\n\n/**\n * Result returned when a function is invoked with `TriggerAction.Enqueue`.\n */\nexport type EnqueueResult = {\n /** Unique receipt ID for the enqueued message. */\n messageReceiptId: string\n}\n\n/**\n * Request object passed to {@link ISdk.trigger}.\n *\n * @typeParam TInput - Type of the payload.\n */\nexport type TriggerRequest<TInput = unknown> = {\n /** ID of the function to invoke. */\n function_id: string\n /** Input data passed to the function. */\n payload: TInput\n /** Sets how the trigger is routed. Omit for a synchronous request/response. Specify for a specific routing scheme (e.g. `TriggerAction.Enqueue()`, `TriggerAction.Void()`). */\n action?: TriggerAction\n /** Override the default invocation timeout, in milliseconds. */\n timeoutMs?: number\n /** Namespace to route this invocation to. Omit to use the engine's default namespace. */\n namespace?: string\n}\n\nexport type InvokeFunctionMessage = {\n message_type: MessageType.InvokeFunction\n /**\n * This is optional for async invocations\n */\n invocation_id?: string\n /**\n * The path of the function\n */\n function_id: string\n /**\n * The data to pass to the function\n */\n data: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n /**\n * Trigger action for queue routing or fire-and-forget\n */\n action?: TriggerAction\n /**\n * Namespace to route this invocation to. Omitted when routing within the default namespace.\n */\n namespace?: string\n}\n\nexport type InvocationResultMessage = {\n message_type: MessageType.InvocationResult\n /**\n * The id of the invocation\n */\n invocation_id: string\n /**\n * The path of the function\n */\n function_id: string\n result?: unknown\n error?: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n}\n\nexport type UnregisterFunctionMessage = {\n message_type: MessageType.UnregisterFunction\n id: string\n}\n\n/**\n * Serializable reference to one end of a streaming channel. Can be included\n * in invocation payloads to pass channel endpoints between workers.\n */\nexport type StreamChannelRef = {\n /** Unique channel identifier. */\n channel_id: string\n /** Access key for authentication. */\n access_key: string\n /** Whether this ref is for reading or writing. */\n direction: 'read' | 'write'\n}\n\nexport type IIIMessage =\n | RegisterFunctionMessage\n | UnregisterFunctionMessage\n | InvokeFunctionMessage\n | InvocationResultMessage\n | RegisterTriggerMessage\n | RegisterTriggerTypeMessage\n | UnregisterTriggerMessage\n | UnregisterTriggerTypeMessage\n | TriggerRegistrationResultMessage\n","import { ChannelReader, ChannelWriter } from './channels'\nimport {\n DEFAULT_BRIDGE_RECONNECTION_CONFIG,\n DEFAULT_INVOCATION_TIMEOUT_MS,\n EngineFunctions,\n type IIIConnectionState,\n type IIIReconnectionConfig,\n} from './iii-constants'\nimport {\n type IIIMessage,\n type InvocationResultMessage,\n type InvokeFunctionMessage,\n MessageType,\n type RegisterFunctionMessage,\n type RegisterTriggerMessage,\n type RegisterTriggerTypeMessage,\n type StreamChannelRef,\n type TriggerRegistrationResultMessage,\n type TriggerRequest,\n} from './iii-types'\nimport type { IStream } from './stream'\nimport type { TriggerHandler } from './triggers'\nimport type {\n FunctionRef,\n Invocation,\n ISdk,\n RegisterFunctionOptions,\n RemoteFunctionData,\n RemoteFunctionHandler,\n RemoteTriggerTypeData,\n Trigger,\n TriggerTypeRef,\n} from './types'\nimport { isChannelRef, randomUUID } from './utils'\n\n/** @internal */\nexport type TelemetryOptions = {\n language?: string\n project_name?: string\n framework?: string\n amplitude_api_key?: string\n}\n\n/**\n * Configuration options passed to {@link registerWorker}.\n *\n * @example\n * ```typescript\n * const worker = registerWorker('ws://localhost:49135', {\n * invocationTimeoutMs: 10000,\n * reconnectionConfig: { maxRetries: 5 },\n * })\n * ```\n */\nexport type InitOptions = {\n /**\n * Name this worker announces to the engine. Defaults to a unique\n * `browser:<random>` per client: a browser has no pid to disambiguate by, and\n * the engine allows only one live worker per name in a namespace, so two tabs\n * sharing a fixed name would evict each other.\n */\n workerName?: string\n /**\n * Namespace this worker registers under. When omitted the engine applies its\n * `default` namespace. Scopes worker and function registrations so\n * identically-named entries can coexist across namespaces. The browser has no\n * `process.env`, so there is no environment-variable fallback -- pass the\n * option explicitly.\n */\n namespace?: string\n /** Default timeout for `worker.trigger()` invocations in milliseconds. Defaults to `30000`. */\n invocationTimeoutMs?: number\n /**\n * WebSocket reconnection behavior.\n *\n * @see {@link IIIReconnectionConfig} for available fields and defaults.\n */\n reconnectionConfig?: Partial<IIIReconnectionConfig>\n /** Browser WebSocket connections authenticate via query parameters or cookies; the `headers` option is ignored. */\n headers?: Record<string, string>\n}\n\n/** Short random suffix; `crypto.randomUUID` is unavailable on insecure origins. */\nfunction randomId(): string {\n const c = globalThis.crypto\n if (c?.randomUUID) {\n return c.randomUUID().slice(0, 8)\n }\n if (c?.getRandomValues) {\n return Array.from(c.getRandomValues(new Uint8Array(4)))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n }\n return Math.random().toString(16).slice(2, 10)\n}\n\nclass Sdk implements ISdk {\n private ws?: WebSocket\n private functions = new Map<string, RemoteFunctionData>()\n private invocations = new Map<string, Invocation & { timeout?: ReturnType<typeof setTimeout> }>()\n private triggers = new Map<string, RegisterTriggerMessage>()\n private triggerTypes = new Map<string, RemoteTriggerTypeData>()\n private messagesToSend: Record<string, unknown>[] = []\n private reconnectTimeout?: ReturnType<typeof setTimeout>\n private invocationTimeoutMs: number\n private reconnectionConfig: IIIReconnectionConfig\n private reconnectAttempt = 0\n private connectionState: IIIConnectionState = 'disconnected'\n private connectionListeners = new Set<(state: IIIConnectionState) => void>()\n private isShuttingDown = false\n private readonly workerName: string\n private readonly namespace?: string\n private workerId?: string\n private reattachToken?: string\n\n constructor(\n private readonly address: string,\n private readonly options?: InitOptions,\n ) {\n this.workerName = options?.workerName ?? `browser:${randomId()}`\n // No env fallback: the browser has no `process.env`.\n this.namespace = options?.namespace\n this.invocationTimeoutMs = options?.invocationTimeoutMs ?? DEFAULT_INVOCATION_TIMEOUT_MS\n this.reconnectionConfig = {\n ...DEFAULT_BRIDGE_RECONNECTION_CONFIG,\n ...options?.reconnectionConfig,\n }\n\n this.connect()\n }\n\n /**\n * Registers a custom trigger type with the engine. A trigger type defines\n * how external events (HTTP, cron, queue, etc.) map to function invocations.\n *\n * @param triggerType - Trigger type registration input.\n * @param triggerType.id - Unique trigger type identifier.\n * @param triggerType.description - Human-readable description.\n * @param handler - Handler with `registerTrigger` / `unregisterTrigger` callbacks.\n *\n * @example\n * ```typescript\n * worker.registerTriggerType(\n * { id: 'my-trigger', description: 'Custom trigger' },\n * {\n * async registerTrigger({ id, function_id, config }) { },\n * async unregisterTrigger({ id, function_id, config }) { },\n * },\n * )\n * ```\n */\n registerTriggerType = <TConfig>(\n triggerType: Omit<RegisterTriggerTypeMessage, 'message_type'>,\n handler: TriggerHandler<TConfig>,\n ): TriggerTypeRef<TConfig> => {\n this.sendMessage(MessageType.RegisterTriggerType, triggerType, true)\n this.triggerTypes.set(triggerType.id, {\n message: { ...triggerType, message_type: MessageType.RegisterTriggerType },\n handler,\n })\n\n return {\n id: triggerType.id,\n registerTrigger: (functionId: string, config: TConfig) => {\n return this.registerTrigger({\n type: triggerType.id,\n function_id: functionId,\n config,\n })\n },\n registerFunction: (functionId, handler, config) => {\n const ref = this.registerFunction(functionId, handler)\n this.registerTrigger({\n type: triggerType.id,\n function_id: functionId,\n config,\n })\n return ref\n },\n unregister: () => {\n this.unregisterTriggerType(triggerType)\n },\n }\n }\n\n /**\n * Unregisters a previously registered trigger type.\n *\n * @param triggerType - The trigger type to unregister (must match the `id` used during registration).\n */\n unregisterTriggerType = (triggerType: Omit<RegisterTriggerTypeMessage, 'message_type'>): void => {\n this.sendMessage(MessageType.UnregisterTriggerType, triggerType, true)\n this.triggerTypes.delete(triggerType.id)\n }\n\n /**\n * Binds a trigger configuration to a registered function. When the trigger\n * fires, the engine invokes the target function.\n *\n * @param trigger - Trigger registration input.\n * @param trigger.type - Trigger type (e.g. `http`, `durable:subscriber`, `cron`).\n * @param trigger.function_id - ID of the function to invoke.\n * @param trigger.config - Trigger-specific configuration.\n * @returns A {@link Trigger} handle with an `unregister()` method.\n *\n * @example\n * ```typescript\n * const trigger = worker.registerTrigger({\n * type: 'http',\n * function_id: 'greet',\n * config: { api_path: '/greet', http_method: 'GET' },\n * })\n *\n * // Later...\n * trigger.unregister()\n * ```\n */\n registerTrigger = (trigger: Omit<RegisterTriggerMessage, 'message_type' | 'id'>): Trigger => {\n const id = randomUUID()\n const fullTrigger: RegisterTriggerMessage = {\n ...trigger,\n id,\n message_type: MessageType.RegisterTrigger,\n }\n this.sendMessage(MessageType.RegisterTrigger, fullTrigger, true)\n this.triggers.set(id, fullTrigger)\n\n return {\n unregister: () => {\n this.sendMessage(MessageType.UnregisterTrigger, {\n id,\n message_type: MessageType.UnregisterTrigger,\n type: fullTrigger.type,\n })\n this.triggers.delete(id)\n },\n }\n }\n\n /**\n * Registers a function with the engine. The `functionId` is the unique identifier\n * used by triggers and invocations.\n *\n * The handler runs locally in the browser session; HTTP invocation configs\n * are a Node.js SDK feature and are not accepted here.\n *\n * @param functionId - Unique function identifier.\n * @param handlerOrInvocation - Async handler executed when the function is invoked.\n * @param options - Optional function registration options (description, request/response formats, metadata).\n * @returns A {@link FunctionRef} with `id` and `unregister()`.\n *\n * @example\n * ```typescript\n * const fn = worker.registerFunction(\n * 'greet',\n * async (input: { name: string }) => {\n * return { message: `Hello, ${input.name}!` }\n * },\n * { description: 'Greets a user' },\n * )\n * ```\n */\n registerFunction = (\n functionId: string,\n handlerOrInvocation: RemoteFunctionHandler,\n options?: RegisterFunctionOptions,\n ): FunctionRef => {\n if (!functionId || functionId.trim() === '') {\n throw new Error('id is required')\n }\n if (this.functions.has(functionId)) {\n throw new Error(`function id already registered: ${functionId}`)\n }\n\n const fullMessage: RegisterFunctionMessage = {\n ...options,\n id: functionId,\n message_type: MessageType.RegisterFunction,\n }\n\n this.sendMessage(MessageType.RegisterFunction, fullMessage, true)\n\n const handler = handlerOrInvocation as RemoteFunctionHandler\n this.functions.set(functionId, {\n message: fullMessage,\n handler: async (input, _traceparent?: string, _baggage?: string) => {\n return await handler(input)\n },\n })\n\n return {\n id: functionId,\n unregister: () => {\n this.sendMessage(MessageType.UnregisterFunction, { id: functionId }, true)\n this.functions.delete(functionId)\n },\n }\n }\n\n /**\n * @internal Implementation backing the `createChannel` helper in the\n * `iii-browser-sdk/helpers` submodule. Not part of the public `ISdk` surface.\n *\n * Creates a streaming channel pair for worker-to-worker data transfer.\n * Returns a {@link Channel} with a local writer/reader and serializable refs\n * that can be passed as fields in invocation data to other functions.\n */\n __helpers_create_channel = async (bufferSize?: number): Promise<import('./types').Channel> => {\n const result = await this.trigger<{ buffer_size?: number }, { writer: StreamChannelRef; reader: StreamChannelRef }>(\n { function_id: 'engine::channels::create', payload: { buffer_size: bufferSize } },\n )\n\n return {\n writer: new ChannelWriter(this.address, result.writer),\n reader: new ChannelReader(this.address, result.reader),\n writerRef: result.writer,\n readerRef: result.reader,\n }\n }\n\n /**\n * Invokes a remote function. The routing behavior and return type depend\n * on the `action` field of the request.\n *\n * | `action` | Behavior | Return type |\n * |-------------------------------|----------------------------------------------------|----------------------- |\n * | _(none)_ | Synchronous: waits for the function to return | `Promise<TOutput>` |\n * | `TriggerAction.Enqueue(...)` | Async via named queue; engine acknowledges enqueue | `Promise<EnqueueResult>` |\n * | `TriggerAction.Void()` | Fire-and-forget, no response | `Promise<undefined>` |\n *\n * @param request - The trigger request.\n * @param request.function_id - ID of the function to invoke.\n * @param request.payload - Payload to pass to the function.\n * @param request.action - Routing action. Omit for synchronous request/response.\n * @param request.timeoutMs - Override the default invocation timeout.\n * @returns The result of the function invocation.\n *\n * @example\n * ```typescript\n * import { TriggerAction } from 'iii-browser-sdk'\n *\n * // Synchronous\n * const result = await worker.trigger({ function_id: 'get-order', payload: { id: '123' } })\n *\n * // Enqueue\n * const { messageReceiptId } = await worker.trigger({\n * function_id: 'payments::charge',\n * payload: { orderId: '123', amount: 49.99 },\n * action: TriggerAction.Enqueue({ queue: 'payment' }),\n * })\n *\n * // Fire-and-forget\n * worker.trigger({\n * function_id: 'notifications::send',\n * payload: { userId: '123' },\n * action: TriggerAction.Void(),\n * })\n * ```\n */\n // biome-ignore lint/suspicious/noExplicitAny: TOutput defaults to any so untyped calls type-check (the engine cannot express the return type statically)\n trigger = async <TInput = unknown, TOutput = any>(\n request: TriggerRequest<TInput>,\n ): Promise<TOutput> => {\n const { function_id, payload, action, timeoutMs, namespace } = request\n const effectiveTimeout = timeoutMs ?? this.invocationTimeoutMs\n\n if (action?.type === 'void') {\n this.sendMessage(MessageType.InvokeFunction, {\n function_id,\n data: payload,\n action,\n // Omit when absent so the engine routes within its default namespace.\n ...(namespace !== undefined ? { namespace } : {}),\n })\n return undefined as TOutput\n }\n\n const invocation_id = randomUUID()\n\n return new Promise<TOutput>((resolve, reject) => {\n const timeout = setTimeout(() => {\n const invocation = this.invocations.get(invocation_id)\n if (invocation) {\n this.invocations.delete(invocation_id)\n reject(new Error(`Invocation timeout after ${effectiveTimeout}ms: ${function_id}`))\n }\n }, effectiveTimeout)\n\n this.invocations.set(invocation_id, {\n resolve: (result: TOutput) => {\n clearTimeout(timeout)\n resolve(result)\n },\n reject: (error: unknown) => {\n clearTimeout(timeout)\n reject(error)\n },\n timeout,\n })\n\n this.sendMessage(MessageType.InvokeFunction, {\n invocation_id,\n function_id,\n data: payload,\n action,\n // Omit when absent so the engine routes within its default namespace.\n ...(namespace !== undefined ? { namespace } : {}),\n })\n })\n }\n\n /**\n * @internal Implementation backing the `createStream` helper in the\n * `iii-browser-sdk/helpers` submodule. Not part of the public `ISdk` surface.\n *\n * Registers a custom stream implementation, overriding the engine default\n * for the given stream name.\n */\n __helpers_create_stream = <TData>(streamName: string, stream: IStream<TData>): void => {\n this.registerFunction(`stream::get(${streamName})`, stream.get.bind(stream))\n this.registerFunction(`stream::set(${streamName})`, stream.set.bind(stream))\n this.registerFunction(`stream::delete(${streamName})`, stream.delete.bind(stream))\n this.registerFunction(`stream::list(${streamName})`, stream.list.bind(stream))\n this.registerFunction(`stream::list_groups(${streamName})`, stream.listGroups.bind(stream))\n }\n\n /**\n * Gracefully shutdown the SDK, cleaning up all resources.\n */\n shutdown = async (): Promise<void> => {\n this.isShuttingDown = true\n\n this.clearReconnectTimeout()\n\n for (const [_id, invocation] of this.invocations) {\n if (invocation.timeout) {\n clearTimeout(invocation.timeout)\n }\n invocation.reject(new Error('iii is shutting down'))\n }\n this.invocations.clear()\n\n if (this.ws) {\n this.ws.onopen = null\n this.ws.onclose = null\n this.ws.onerror = null\n this.ws.onmessage = null\n this.ws.close()\n this.ws = undefined\n }\n\n this.setConnectionState('disconnected')\n }\n\n /**\n * Subscribe to connection-state transitions. The handler is fired immediately\n * with the current state, then on every transition. Multiple listeners are\n * supported. Returns an unsubscribe function.\n */\n addConnectionStateListener = (handler: (state: IIIConnectionState) => void): (() => void) => {\n this.connectionListeners.add(handler)\n try {\n handler(this.connectionState)\n } catch (e) {\n console.error('[iii] connection listener threw on initial fire', e)\n }\n return () => {\n this.connectionListeners.delete(handler)\n }\n }\n\n // private methods\n\n private setConnectionState(state: IIIConnectionState): void {\n if (this.connectionState !== state) {\n this.connectionState = state\n for (const handler of this.connectionListeners) {\n try {\n handler(state)\n } catch (e) {\n console.error('[iii] connection listener threw', e)\n }\n }\n }\n }\n\n private connect(): void {\n if (this.isShuttingDown) {\n return\n }\n\n this.setConnectionState('connecting')\n this.ws = new WebSocket(this.address)\n this.ws.onopen = this.onSocketOpen.bind(this)\n this.ws.onclose = this.onSocketClose.bind(this)\n this.ws.onerror = this.onSocketError.bind(this)\n }\n\n private clearReconnectTimeout(): void {\n if (this.reconnectTimeout) {\n clearTimeout(this.reconnectTimeout)\n this.reconnectTimeout = undefined\n }\n }\n\n private scheduleReconnect(): void {\n if (this.isShuttingDown) {\n return\n }\n\n const { maxRetries, initialDelayMs, backoffMultiplier, maxDelayMs, jitterFactor } = this.reconnectionConfig\n\n if (maxRetries !== -1 && this.reconnectAttempt >= maxRetries) {\n this.setConnectionState('failed')\n console.error(`[iii] Max reconnection retries (${maxRetries}) reached, giving up`)\n return\n }\n\n if (this.reconnectTimeout) {\n return\n }\n\n const exponentialDelay = initialDelayMs * backoffMultiplier ** this.reconnectAttempt\n const cappedDelay = Math.min(exponentialDelay, maxDelayMs)\n const jitter = cappedDelay * jitterFactor * (2 * Math.random() - 1)\n const delay = Math.floor(cappedDelay + jitter)\n\n this.setConnectionState('reconnecting')\n console.debug(`[iii] Reconnecting in ${delay}ms (attempt ${this.reconnectAttempt + 1})...`)\n\n this.reconnectTimeout = setTimeout(() => {\n this.reconnectTimeout = undefined\n this.reconnectAttempt++\n this.connect()\n }, delay)\n }\n\n private onSocketError(): void {\n console.error('[iii] WebSocket error')\n }\n\n private onSocketClose(): void {\n if (this.ws) {\n this.ws.onopen = null\n this.ws.onclose = null\n this.ws.onerror = null\n this.ws.onmessage = null\n }\n this.ws = undefined\n\n // A fatal registration rejection (or shutdown) sets `isShuttingDown` and a\n // terminal state before closing the socket. Do not overwrite that state with\n // `disconnected`, and do not schedule a reconnect the engine would only\n // reject again. `scheduleReconnect` already no-ops while shutting down.\n if (this.isShuttingDown) {\n return\n }\n\n this.setConnectionState('disconnected')\n this.scheduleReconnect()\n }\n\n private onSocketOpen(): void {\n this.clearReconnectTimeout()\n this.reconnectAttempt = 0\n this.setConnectionState('connected')\n\n if (this.ws) {\n this.ws.onmessage = this.onMessage.bind(this)\n }\n\n // Reconnect: present the previous engine-assigned identity BEFORE the\n // metadata announce and registration replay so the engine retires the old\n // connection and the replay lands on a clean slate instead of racing its\n // cleanup. This must precede registerWorkerMetadata(): otherwise the old\n // connection still holds this (namespace, worker_name) and the announce\n // would trip WORKER_NAMESPACE_CONFLICT against ourselves. The token proves\n // we ARE that worker (ids alone are publicly listable).\n if (this.workerId) {\n this.sendMessageRaw(\n JSON.stringify({\n type: MessageType.Reattach,\n previous_worker_id: this.workerId,\n reattach_token: this.reattachToken,\n }),\n )\n }\n\n // Announce before registering anything. The engine buffers a connection's\n // registrations until it knows the connection's namespace, which it takes\n // from this call — or, failing that, only after a grace period. Registering\n // first would stall every function behind that grace.\n this.registerWorkerMetadata()\n\n\n this.triggerTypes.forEach(({ message }) => {\n this.sendMessage(MessageType.RegisterTriggerType, message, true)\n })\n this.functions.forEach(({ message }) => {\n this.sendMessage(MessageType.RegisterFunction, message, true)\n })\n this.triggers.forEach((trigger) => {\n this.sendMessage(MessageType.RegisterTrigger, trigger, true)\n })\n\n const pending = this.messagesToSend\n this.messagesToSend = []\n for (const message of pending) {\n if (\n message.type === MessageType.InvokeFunction &&\n typeof message.invocation_id === 'string' &&\n !this.invocations.has(message.invocation_id)\n ) {\n continue\n }\n this.sendMessageRaw(JSON.stringify(message))\n }\n }\n\n private isOpen(): boolean {\n return this.ws?.readyState === WebSocket.OPEN\n }\n\n private sendMessageRaw(data: string): void {\n if (this.ws && this.isOpen()) {\n try {\n this.ws.send(data)\n } catch (error) {\n console.error('[iii] Exception while sending message', error)\n }\n }\n }\n\n private toWireFormat(messageType: MessageType, message: Omit<IIIMessage, 'message_type'>): Record<string, unknown> {\n const { message_type: _, ...rest } = message as Record<string, unknown>\n if (messageType === MessageType.RegisterTrigger && 'type' in message) {\n const { type: triggerType, ...triggerRest } = message as RegisterTriggerMessage\n return { type: messageType, ...triggerRest, trigger_type: triggerType }\n }\n if (messageType === MessageType.UnregisterTrigger && 'type' in message) {\n const { type: triggerType, ...triggerRest } = message as RegisterTriggerMessage\n return { type: messageType, ...triggerRest, trigger_type: triggerType }\n }\n if (messageType === MessageType.TriggerRegistrationResult && 'type' in message) {\n const { type: triggerType, ...resultRest } = message as TriggerRegistrationResultMessage\n return { type: messageType, ...resultRest, trigger_type: triggerType }\n }\n return { type: messageType, ...rest } as Record<string, unknown>\n }\n\n /**\n * Tells the engine who this connection is. Sent on every open, before any\n * registration, so the engine can resolve this connection's namespace and\n * drain its buffered registrations immediately.\n */\n private registerWorkerMetadata(): void {\n this.sendMessage(MessageType.InvokeFunction, {\n function_id: EngineFunctions.REGISTER_WORKER,\n data: {\n runtime: 'browser',\n name: this.workerName,\n os: globalThis.navigator?.userAgent ?? 'browser',\n // Omit when absent so the engine falls back to its `default` namespace.\n ...(this.namespace !== undefined ? { namespace: this.namespace } : {}),\n },\n action: { type: 'void' },\n } as unknown as Omit<IIIMessage, 'message_type'>)\n }\n\n private sendMessage(messageType: MessageType, message: Omit<IIIMessage, 'message_type'>, skipIfClosed = false): void {\n const wireMessage = this.toWireFormat(messageType, message)\n if (this.isOpen()) {\n this.sendMessageRaw(JSON.stringify(wireMessage))\n } else if (!skipIfClosed) {\n this.messagesToSend.push(wireMessage)\n }\n }\n\n private onInvocationResult(invocation_id: string, result: unknown, error: unknown): void {\n const invocation = this.invocations.get(invocation_id)\n\n if (invocation) {\n if (invocation.timeout) {\n clearTimeout(invocation.timeout)\n }\n error ? invocation.reject(error) : invocation.resolve(result)\n }\n\n this.invocations.delete(invocation_id)\n }\n\n private resolveChannelValue(value: unknown): unknown {\n if (isChannelRef(value)) {\n return value.direction === 'read'\n ? new ChannelReader(this.address, value)\n : new ChannelWriter(this.address, value)\n }\n if (Array.isArray(value)) {\n return value.map((item) => this.resolveChannelValue(item))\n }\n if (value !== null && typeof value === 'object') {\n const out: Record<string, unknown> = {}\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n out[k] = this.resolveChannelValue(v)\n }\n return out\n }\n return value\n }\n\n private async onInvokeFunction<TInput>(\n invocation_id: string | undefined,\n function_id: string,\n input: TInput,\n traceparent?: string,\n baggage?: string,\n ): Promise<unknown> {\n const fn = this.functions.get(function_id)\n\n const resolvedInput = this.resolveChannelValue(input) as TInput\n\n if (fn?.handler) {\n if (!invocation_id) {\n try {\n await fn.handler(resolvedInput, traceparent, baggage)\n } catch (error) {\n console.error(`[iii] Error invoking function ${function_id}`, error)\n }\n return\n }\n\n try {\n const result = await fn.handler(resolvedInput, traceparent, baggage)\n this.sendMessage(MessageType.InvocationResult, {\n invocation_id,\n function_id,\n result,\n traceparent,\n baggage,\n })\n } catch (error) {\n const isError = error instanceof Error\n this.sendMessage(MessageType.InvocationResult, {\n invocation_id,\n function_id,\n error: {\n code: 'invocation_failed',\n message: isError ? error.message : String(error),\n stacktrace: isError ? error.stack : undefined,\n },\n traceparent,\n baggage,\n })\n }\n } else {\n const errorCode = fn ? 'function_not_invokable' : 'function_not_found'\n const errorMessage = fn ? 'Function is HTTP-invoked and cannot be invoked locally' : 'Function not found'\n if (invocation_id) {\n this.sendMessage(MessageType.InvocationResult, {\n invocation_id,\n function_id,\n error: { code: errorCode, message: errorMessage },\n traceparent,\n baggage,\n })\n }\n }\n }\n\n private async onRegisterTrigger(message: { trigger_type: string; id: string; function_id: string; config: unknown }) {\n const { trigger_type, id, function_id, config } = message\n const triggerTypeData = this.triggerTypes.get(trigger_type)\n\n if (triggerTypeData) {\n try {\n await triggerTypeData.handler.registerTrigger({ id, function_id, config })\n this.sendMessage(MessageType.TriggerRegistrationResult, {\n id,\n message_type: MessageType.TriggerRegistrationResult,\n type: trigger_type,\n function_id,\n })\n } catch (error) {\n this.sendMessage(MessageType.TriggerRegistrationResult, {\n id,\n message_type: MessageType.TriggerRegistrationResult,\n type: trigger_type,\n function_id,\n error: { code: 'trigger_registration_failed', message: (error as Error).message },\n })\n }\n } else {\n this.sendMessage(MessageType.TriggerRegistrationResult, {\n id,\n message_type: MessageType.TriggerRegistrationResult,\n type: trigger_type,\n function_id,\n error: { code: 'trigger_type_not_found', message: 'Trigger type not found' },\n })\n }\n }\n\n private async onUnregisterTrigger(message: {\n trigger_type?: string\n id: string\n function_id?: string\n config?: unknown\n }) {\n const trigger_type = message.trigger_type\n if (!trigger_type) return\n\n const triggerTypeData = this.triggerTypes.get(trigger_type)\n if (!triggerTypeData) return\n\n const { id, function_id = '', config } = message\n try {\n await triggerTypeData.handler.unregisterTrigger({ id, function_id, config })\n } catch (error) {\n console.error(`[iii] Error unregistering trigger ${id}`, error)\n }\n }\n\n private onMessage(event: MessageEvent): void {\n let msgType: MessageType\n let message: Record<string, unknown>\n\n try {\n const parsed = JSON.parse(typeof event.data === 'string' ? event.data : '') as Record<string, unknown>\n msgType = parsed.type as MessageType\n const { type: _, ...rest } = parsed\n message = rest\n } catch (error) {\n console.error('[iii] Failed to parse incoming message', error)\n return\n }\n\n if (msgType === MessageType.InvocationResult) {\n const { invocation_id, result, error } = message as InvocationResultMessage\n this.onInvocationResult(invocation_id, result, error)\n } else if (msgType === MessageType.InvokeFunction) {\n const { invocation_id, function_id, data, traceparent, baggage } = message as InvokeFunctionMessage\n this.onInvokeFunction(invocation_id, function_id, data, traceparent, baggage)\n } else if (msgType === MessageType.RegisterTrigger) {\n this.onRegisterTrigger(message as { trigger_type: string; id: string; function_id: string; config: unknown })\n } else if (msgType === MessageType.UnregisterTrigger) {\n this.onUnregisterTrigger(\n message as { trigger_type?: string; id: string; function_id?: string; config?: unknown },\n )\n } else if (msgType === MessageType.RegistrationRejected) {\n this.onRegistrationRejected(\n message as { code: string; namespace: string; worker_name: string; owner_worker_id: string },\n )\n } else if (msgType === MessageType.WorkerRegistered) {\n const { worker_id, reattach_token } = message as { worker_id: string; reattach_token?: string }\n this.workerId = worker_id\n this.reattachToken = reattach_token\n }\n }\n\n /**\n * The engine rejected a registration. A `FUNCTION_NAMESPACE_CONFLICT` costs\n * one function and leaves the connection open, so log and keep serving. A\n * `WORKER_NAMESPACE_CONFLICT` means another live worker owns this name in the\n * namespace: it is terminal — stop and do not reconnect (otherwise the engine\n * would only reject the same name again, which with `maxRetries: -1` loops\n * forever).\n */\n private onRegistrationRejected(init: {\n code: string\n namespace: string\n worker_name: string\n owner_worker_id: string\n }): void {\n if (init.code === 'FUNCTION_NAMESPACE_CONFLICT') {\n console.warn(\n `[iii] Function registration rejected: function \"${init.worker_name}\" in namespace \"${init.namespace}\" is already exported by worker ${init.owner_worker_id}. Staying connected and serving the rest.`,\n )\n return\n }\n\n console.error(\n `[iii] Registration rejected (${init.code}): worker \"${init.worker_name}\" in namespace \"${init.namespace}\" is already owned by ${init.owner_worker_id}. Not reconnecting.`,\n )\n // Terminal: suppress reconnect so neither onSocketClose nor scheduleReconnect\n // revives a connection the engine would only reject again.\n this.isShuttingDown = true\n this.clearReconnectTimeout()\n\n // Reject every in-flight invocation now rather than leaving them to time out.\n const error = new Error(\n `[iii] Registration rejected (${init.code}): worker \"${init.worker_name}\" in namespace \"${init.namespace}\" is already owned by ${init.owner_worker_id}.`,\n )\n for (const [, invocation] of this.invocations) {\n if (invocation.timeout) {\n clearTimeout(invocation.timeout)\n }\n invocation.reject(error)\n }\n this.invocations.clear()\n\n // Drop the socket. onSocketClose sees `isShuttingDown` and leaves the\n // terminal `failed` state in place instead of overwriting it.\n this.setConnectionState('failed')\n this.ws?.close()\n }\n}\n\n/**\n * Factory object that constructs routing actions for {@link ISdk.trigger}.\n *\n * @example\n * ```typescript\n * import { TriggerAction } from 'iii-browser-sdk'\n *\n * // Enqueue to a named queue\n * worker.trigger({\n * function_id: 'process',\n * payload: { data: 'hello' },\n * action: TriggerAction.Enqueue({ queue: 'jobs' }),\n * })\n *\n * // Fire-and-forget\n * worker.trigger({\n * function_id: 'notify',\n * payload: {},\n * action: TriggerAction.Void(),\n * })\n * ```\n */\nexport const TriggerAction = {\n /**\n * Routes the invocation through a named queue. The engine enqueues the job,\n * acknowledges the caller with `{ messageReceiptId }`, and processes it\n * asynchronously.\n *\n * @param opts - Queue routing options.\n * @param opts.queue - Name of the target queue.\n */\n Enqueue: (opts: { queue: string }) => ({ type: 'enqueue' as const, ...opts }),\n /**\n * Fire-and-forget routing. The engine forwards the invocation without\n * waiting for a response or queuing the job.\n */\n Void: () => ({ type: 'void' as const }),\n} as const\n\n/**\n * Register the worker with a iii instance, returns a connected worker client.\n * The WebSocket connection is established automatically.\n *\n * @param address - WebSocket URL of the III engine (e.g. `ws://localhost:49135`).\n * @param options - Optional {@link InitOptions} for worker name, timeouts, and reconnection.\n * @returns A connected {@link ISdk} instance.\n *\n * @example\n * ```typescript\n * import { registerWorker } from 'iii-browser-sdk'\n *\n * const worker = registerWorker('ws://localhost:49135')\n * ```\n */\nexport const registerWorker = (address: string, options?: InitOptions): ISdk => new Sdk(address, options)\n"],"mappings":";;;;;;;;;;;;;;;;AAaA,MAAa,kBAAkB;CAC7B,gBAAgB;CAChB,gBAAgB;CAChB,cAAc;CACd,cAAc;CACd,eAAe;CACf,eAAe;CACf,0BAA0B;CAC1B,0BAA0B;CAC1B,iBAAiB;CAClB;;AAGD,MAAa,iBAAiB,EAC5B,qBAAqB,+BACtB;;AAoBD,MAAa,qCAA4D;CACvE,gBAAgB;CAChB,YAAY;CACZ,mBAAmB;CACnB,cAAc;CACd,YAAY;CACb;;AAGD,MAAa,gCAAgC;;;;ACzD7C,IAAY,cAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;KACD;;;;;ACsED,SAAS,WAAmB;CAC1B,MAAM,IAAI,WAAW;AACrB,KAAI,GAAG,WACL,QAAO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kBAAkB,KAAK,UAAU,wBAAwB,KAAK,gBAAgB,qBACvJ;AAGD,OAAK,iBAAiB;AACtB,OAAK,uBAAuB;EAG5B,MAAM,wBAAQ,IAAI,MAChB,gCAAgC,KAAK,KAAK,aAAa,KAAK,YAAY,kBAAkB,KAAK,UAAU,wBAAwB,KAAK,gBAAgB,GACvJ;AACD,OAAK,MAAM,GAAG,eAAe,KAAK,aAAa;AAC7C,OAAI,WAAW,QACb,cAAa,WAAW,QAAQ;AAElC,cAAW,OAAO,MAAM;;AAE1B,OAAK,YAAY,OAAO;AAIxB,OAAK,mBAAmB,SAAS;AACjC,OAAK,IAAI,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;AA0BpB,MAAa,gBAAgB;CAS3B,UAAU,UAA6B;EAAE,MAAM;EAAoB,GAAG;EAAM;CAK5E,aAAa,EAAE,MAAM,QAAiB;CACvC;;;;;;;;;;;;;;;;AAiBD,MAAa,kBAAkB,SAAiB,YAAgC,IAAI,IAAI,SAAS,QAAQ"}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as OnTriggerRegistrationInput, C as AuthInput, D as MiddlewareFunctionInput, E as MessageType, F as RegisterFunctionMessage, I as RegisterTriggerMessage, L as RegisterTriggerTypeMessage, M as OnTriggerTypeRegistrationInput, N as OnTriggerTypeRegistrationResult, O as OnFunctionRegistrationInput, P as RegisterFunctionFormat, R as StreamChannelRef, S as ChannelWriter, T as EnqueueResult, _ as IIIConnectionState, a as ISdk, c as RegisterTriggerInput, d as Trigger, f as TriggerTypeRef, g as EngineTriggers, h as EngineFunctions, i as FunctionRef, j as OnTriggerRegistrationResult, k as OnFunctionRegistrationResult, l as RegisterTriggerTypeInput, m as TriggerHandler, n as ApiResponse, o as RegisterFunctionInput, p as TriggerConfig, r as Channel, s as RegisterFunctionOptions, t as ApiRequest, u as RemoteFunctionHandler, v as IIIReconnectionConfig, w as AuthResult, x as ChannelReader, z as TriggerRequest } from "./types-Dj_5C0O1.cjs";
1
+ import { A as OnTriggerRegistrationInput, C as AuthInput, D as MiddlewareFunctionInput, E as MessageType, F as RegisterFunctionMessage, I as RegisterTriggerMessage, L as RegisterTriggerTypeMessage, M as OnTriggerTypeRegistrationInput, N as OnTriggerTypeRegistrationResult, O as OnFunctionRegistrationInput, P as RegisterFunctionFormat, R as StreamChannelRef, S as ChannelWriter, T as EnqueueResult, _ as IIIConnectionState, a as ISdk, c as RegisterTriggerInput, d as Trigger, f as TriggerTypeRef, g as EngineTriggers, h as EngineFunctions, i as FunctionRef, j as OnTriggerRegistrationResult, k as OnFunctionRegistrationResult, l as RegisterTriggerTypeInput, m as TriggerHandler, n as ApiResponse, o as RegisterFunctionInput, p as TriggerConfig, r as Channel, s as RegisterFunctionOptions, t as ApiRequest, u as RemoteFunctionHandler, v as IIIReconnectionConfig, w as AuthResult, x as ChannelReader, z as TriggerRequest } from "./types-dr4ELKgv.cjs";
2
2
 
3
3
  //#region src/iii.d.ts
4
4
  /**
@@ -13,7 +13,22 @@ import { A as OnTriggerRegistrationInput, C as AuthInput, D as MiddlewareFunctio
13
13
  * ```
14
14
  */
15
15
  type InitOptions = {
16
- /** Default timeout for `worker.trigger()` invocations in milliseconds. Defaults to `30000`. */invocationTimeoutMs?: number;
16
+ /**
17
+ * Name this worker announces to the engine. Defaults to a unique
18
+ * `browser:<random>` per client: a browser has no pid to disambiguate by, and
19
+ * the engine allows only one live worker per name in a namespace, so two tabs
20
+ * sharing a fixed name would evict each other.
21
+ */
22
+ workerName?: string;
23
+ /**
24
+ * Namespace this worker registers under. When omitted the engine applies its
25
+ * `default` namespace. Scopes worker and function registrations so
26
+ * identically-named entries can coexist across namespaces. The browser has no
27
+ * `process.env`, so there is no environment-variable fallback -- pass the
28
+ * option explicitly.
29
+ */
30
+ namespace?: string; /** Default timeout for `worker.trigger()` invocations in milliseconds. Defaults to `30000`. */
31
+ invocationTimeoutMs?: number;
17
32
  /**
18
33
  * WebSocket reconnection behavior.
19
34
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/iii.ts"],"mappings":";;;;;;;;;;;;;AAkyBA;KA7uBY,WAAA;iGAEV,mBAAA;;;;;;EAMA,kBAAA,GAAqB,OAAA,CAAQ,qBAAA;EAE7B,OAAA,GAAU,MAAA;AAAA;AAmwBZ;;;;;;;;;;;;;;;;;;;;;;AAAA,cAhCa,aAAA;;;;;;;;;;IASO,KAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;cAuBP,cAAA,GAAkB,OAAA,UAAiB,OAAA,GAAU,WAAA,KAAc,IAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/iii.ts"],"mappings":";;;;;;;;;;;;;;KAsDY,WAAA;EA22BC;;;;;;EAp2BX,UAAA;;;;;;;AAo4BF;EA53BE,SAAA;EAEA,mBAAA;EA03B6B;;;;;EAp3B7B,kBAAA,GAAqB,OAAA,CAAQ,qBAAA;EAE7B,OAAA,GAAU,MAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;cAk1BC,aAAA;;;;;;;;;;IASO,KAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;cAuBP,cAAA,GAAkB,OAAA,UAAiB,OAAA,GAAU,WAAA,KAAc,IAAA"}
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as OnTriggerRegistrationInput, C as AuthInput, D as MiddlewareFunctionInput, E as MessageType, F as RegisterFunctionMessage, I as RegisterTriggerMessage, L as RegisterTriggerTypeMessage, M as OnTriggerTypeRegistrationInput, N as OnTriggerTypeRegistrationResult, O as OnFunctionRegistrationInput, P as RegisterFunctionFormat, R as StreamChannelRef, S as ChannelWriter, T as EnqueueResult, _ as IIIConnectionState, a as ISdk, c as RegisterTriggerInput, d as Trigger, f as TriggerTypeRef, g as EngineTriggers, h as EngineFunctions, i as FunctionRef, j as OnTriggerRegistrationResult, k as OnFunctionRegistrationResult, l as RegisterTriggerTypeInput, m as TriggerHandler, n as ApiResponse, o as RegisterFunctionInput, p as TriggerConfig, r as Channel, s as RegisterFunctionOptions, t as ApiRequest, u as RemoteFunctionHandler, v as IIIReconnectionConfig, w as AuthResult, x as ChannelReader, z as TriggerRequest } from "./types-DzJ2vn5G.mjs";
1
+ import { A as OnTriggerRegistrationInput, C as AuthInput, D as MiddlewareFunctionInput, E as MessageType, F as RegisterFunctionMessage, I as RegisterTriggerMessage, L as RegisterTriggerTypeMessage, M as OnTriggerTypeRegistrationInput, N as OnTriggerTypeRegistrationResult, O as OnFunctionRegistrationInput, P as RegisterFunctionFormat, R as StreamChannelRef, S as ChannelWriter, T as EnqueueResult, _ as IIIConnectionState, a as ISdk, c as RegisterTriggerInput, d as Trigger, f as TriggerTypeRef, g as EngineTriggers, h as EngineFunctions, i as FunctionRef, j as OnTriggerRegistrationResult, k as OnFunctionRegistrationResult, l as RegisterTriggerTypeInput, m as TriggerHandler, n as ApiResponse, o as RegisterFunctionInput, p as TriggerConfig, r as Channel, s as RegisterFunctionOptions, t as ApiRequest, u as RemoteFunctionHandler, v as IIIReconnectionConfig, w as AuthResult, x as ChannelReader, z as TriggerRequest } from "./types-Ui5yAF2Q.mjs";
2
2
 
3
3
  //#region src/iii.d.ts
4
4
  /**
@@ -13,7 +13,22 @@ import { A as OnTriggerRegistrationInput, C as AuthInput, D as MiddlewareFunctio
13
13
  * ```
14
14
  */
15
15
  type InitOptions = {
16
- /** Default timeout for `worker.trigger()` invocations in milliseconds. Defaults to `30000`. */invocationTimeoutMs?: number;
16
+ /**
17
+ * Name this worker announces to the engine. Defaults to a unique
18
+ * `browser:<random>` per client: a browser has no pid to disambiguate by, and
19
+ * the engine allows only one live worker per name in a namespace, so two tabs
20
+ * sharing a fixed name would evict each other.
21
+ */
22
+ workerName?: string;
23
+ /**
24
+ * Namespace this worker registers under. When omitted the engine applies its
25
+ * `default` namespace. Scopes worker and function registrations so
26
+ * identically-named entries can coexist across namespaces. The browser has no
27
+ * `process.env`, so there is no environment-variable fallback -- pass the
28
+ * option explicitly.
29
+ */
30
+ namespace?: string; /** Default timeout for `worker.trigger()` invocations in milliseconds. Defaults to `30000`. */
31
+ invocationTimeoutMs?: number;
17
32
  /**
18
33
  * WebSocket reconnection behavior.
19
34
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/iii.ts"],"mappings":";;;;;;;;;;;;;AAkyBA;KA7uBY,WAAA;iGAEV,mBAAA;;;;;;EAMA,kBAAA,GAAqB,OAAA,CAAQ,qBAAA;EAE7B,OAAA,GAAU,MAAA;AAAA;AAmwBZ;;;;;;;;;;;;;;;;;;;;;;AAAA,cAhCa,aAAA;;;;;;;;;;IASO,KAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;cAuBP,cAAA,GAAkB,OAAA,UAAiB,OAAA,GAAU,WAAA,KAAc,IAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/iii.ts"],"mappings":";;;;;;;;;;;;;;KAsDY,WAAA;EA22BC;;;;;;EAp2BX,UAAA;;;;;;;AAo4BF;EA53BE,SAAA;EAEA,mBAAA;EA03B6B;;;;;EAp3B7B,kBAAA,GAAqB,OAAA,CAAQ,qBAAA;EAE7B,OAAA,GAAU,MAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;cAk1BC,aAAA;;;;;;;;;;IASO,KAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;cAuBP,cAAA,GAAkB,OAAA,UAAiB,OAAA,GAAU,WAAA,KAAc,IAAA"}
package/dist/index.mjs CHANGED
@@ -49,6 +49,7 @@ let MessageType = /* @__PURE__ */ function(MessageType) {
49
49
  MessageType["UnregisterTrigger"] = "unregistertrigger";
50
50
  MessageType["UnregisterTriggerType"] = "unregistertriggertype";
51
51
  MessageType["TriggerRegistrationResult"] = "triggerregistrationresult";
52
+ MessageType["RegistrationRejected"] = "registrationrejected";
52
53
  MessageType["WorkerRegistered"] = "workerregistered";
53
54
  MessageType["Reattach"] = "reattach";
54
55
  return MessageType;
@@ -56,6 +57,13 @@ let MessageType = /* @__PURE__ */ function(MessageType) {
56
57
 
57
58
  //#endregion
58
59
  //#region src/iii.ts
60
+ /** Short random suffix; `crypto.randomUUID` is unavailable on insecure origins. */
61
+ function randomId() {
62
+ const c = globalThis.crypto;
63
+ if (c?.randomUUID) return c.randomUUID().slice(0, 8);
64
+ if (c?.getRandomValues) return Array.from(c.getRandomValues(new Uint8Array(4))).map((b) => b.toString(16).padStart(2, "0")).join("");
65
+ return Math.random().toString(16).slice(2, 10);
66
+ }
59
67
  var Sdk = class {
60
68
  constructor(address, options) {
61
69
  this.address = address;
@@ -160,13 +168,14 @@ var Sdk = class {
160
168
  };
161
169
  };
162
170
  this.trigger = async (request) => {
163
- const { function_id, payload, action, timeoutMs } = request;
171
+ const { function_id, payload, action, timeoutMs, namespace } = request;
164
172
  const effectiveTimeout = timeoutMs ?? this.invocationTimeoutMs;
165
173
  if (action?.type === "void") {
166
174
  this.sendMessage(MessageType.InvokeFunction, {
167
175
  function_id,
168
176
  data: payload,
169
- action
177
+ action,
178
+ ...namespace !== void 0 ? { namespace } : {}
170
179
  });
171
180
  return;
172
181
  }
@@ -193,7 +202,8 @@ var Sdk = class {
193
202
  invocation_id,
194
203
  function_id,
195
204
  data: payload,
196
- action
205
+ action,
206
+ ...namespace !== void 0 ? { namespace } : {}
197
207
  });
198
208
  });
199
209
  };
@@ -233,6 +243,8 @@ var Sdk = class {
233
243
  this.connectionListeners.delete(handler);
234
244
  };
235
245
  };
246
+ this.workerName = options?.workerName ?? `browser:${randomId()}`;
247
+ this.namespace = options?.namespace;
236
248
  this.invocationTimeoutMs = options?.invocationTimeoutMs ?? 3e4;
237
249
  this.reconnectionConfig = {
238
250
  ...DEFAULT_BRIDGE_RECONNECTION_CONFIG,
@@ -296,6 +308,7 @@ var Sdk = class {
296
308
  this.ws.onmessage = null;
297
309
  }
298
310
  this.ws = void 0;
311
+ if (this.isShuttingDown) return;
299
312
  this.setConnectionState("disconnected");
300
313
  this.scheduleReconnect();
301
314
  }
@@ -309,6 +322,7 @@ var Sdk = class {
309
322
  previous_worker_id: this.workerId,
310
323
  reattach_token: this.reattachToken
311
324
  }));
325
+ this.registerWorkerMetadata();
312
326
  this.triggerTypes.forEach(({ message }) => {
313
327
  this.sendMessage(MessageType.RegisterTriggerType, message, true);
314
328
  });
@@ -366,6 +380,23 @@ var Sdk = class {
366
380
  ...rest
367
381
  };
368
382
  }
383
+ /**
384
+ * Tells the engine who this connection is. Sent on every open, before any
385
+ * registration, so the engine can resolve this connection's namespace and
386
+ * drain its buffered registrations immediately.
387
+ */
388
+ registerWorkerMetadata() {
389
+ this.sendMessage(MessageType.InvokeFunction, {
390
+ function_id: EngineFunctions.REGISTER_WORKER,
391
+ data: {
392
+ runtime: "browser",
393
+ name: this.workerName,
394
+ os: globalThis.navigator?.userAgent ?? "browser",
395
+ ...this.namespace !== void 0 ? { namespace: this.namespace } : {}
396
+ },
397
+ action: { type: "void" }
398
+ });
399
+ }
369
400
  sendMessage(messageType, message, skipIfClosed = false) {
370
401
  const wireMessage = this.toWireFormat(messageType, message);
371
402
  if (this.isOpen()) this.sendMessageRaw(JSON.stringify(wireMessage));
@@ -513,12 +544,38 @@ var Sdk = class {
513
544
  this.onInvokeFunction(invocation_id, function_id, data, traceparent, baggage);
514
545
  } else if (msgType === MessageType.RegisterTrigger) this.onRegisterTrigger(message);
515
546
  else if (msgType === MessageType.UnregisterTrigger) this.onUnregisterTrigger(message);
547
+ else if (msgType === MessageType.RegistrationRejected) this.onRegistrationRejected(message);
516
548
  else if (msgType === MessageType.WorkerRegistered) {
517
549
  const { worker_id, reattach_token } = message;
518
550
  this.workerId = worker_id;
519
551
  this.reattachToken = reattach_token;
520
552
  }
521
553
  }
554
+ /**
555
+ * The engine rejected a registration. A `FUNCTION_NAMESPACE_CONFLICT` costs
556
+ * one function and leaves the connection open, so log and keep serving. A
557
+ * `WORKER_NAMESPACE_CONFLICT` means another live worker owns this name in the
558
+ * namespace: it is terminal — stop and do not reconnect (otherwise the engine
559
+ * would only reject the same name again, which with `maxRetries: -1` loops
560
+ * forever).
561
+ */
562
+ onRegistrationRejected(init) {
563
+ if (init.code === "FUNCTION_NAMESPACE_CONFLICT") {
564
+ console.warn(`[iii] Function registration rejected: function "${init.worker_name}" in namespace "${init.namespace}" is already exported by worker ${init.owner_worker_id}. Staying connected and serving the rest.`);
565
+ return;
566
+ }
567
+ console.error(`[iii] Registration rejected (${init.code}): worker "${init.worker_name}" in namespace "${init.namespace}" is already owned by ${init.owner_worker_id}. Not reconnecting.`);
568
+ this.isShuttingDown = true;
569
+ this.clearReconnectTimeout();
570
+ const error = /* @__PURE__ */ new Error(`[iii] Registration rejected (${init.code}): worker "${init.worker_name}" in namespace "${init.namespace}" is already owned by ${init.owner_worker_id}.`);
571
+ for (const [, invocation] of this.invocations) {
572
+ if (invocation.timeout) clearTimeout(invocation.timeout);
573
+ invocation.reject(error);
574
+ }
575
+ this.invocations.clear();
576
+ this.setConnectionState("failed");
577
+ this.ws?.close();
578
+ }
522
579
  };
523
580
  /**
524
581
  * Factory object that constructs routing actions for {@link ISdk.trigger}.
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/iii-constants.ts","../src/iii-types.ts","../src/iii.ts"],"sourcesContent":["/**\n * Constants for the III module.\n */\n\n/**\n * Engine function paths for internal operations.\n *\n * Naming note: `LIST_TRIGGERS` / `INFO_TRIGGERS` cover trigger TYPES\n * (templates). `LIST_REGISTERED_TRIGGERS` / `INFO_REGISTERED_TRIGGERS`\n * cover trigger INSTANCES (subscriber rows). The old\n * `engine::trigger-types::list` builtin has been removed and is now\n * served by `engine::triggers::list`.\n */\nexport const EngineFunctions = {\n LIST_FUNCTIONS: 'engine::functions::list',\n INFO_FUNCTIONS: 'engine::functions::info',\n LIST_WORKERS: 'engine::workers::list',\n INFO_WORKERS: 'engine::workers::info',\n LIST_TRIGGERS: 'engine::triggers::list',\n INFO_TRIGGERS: 'engine::triggers::info',\n LIST_REGISTERED_TRIGGERS: 'engine::registered-triggers::list',\n INFO_REGISTERED_TRIGGERS: 'engine::registered-triggers::info',\n REGISTER_WORKER: 'engine::workers::register',\n} as const\n\n/** Engine trigger types */\nexport const EngineTriggers = {\n FUNCTIONS_AVAILABLE: 'engine::functions-available',\n} as const\n\n/** Connection state for the III WebSocket */\nexport type IIIConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'failed'\n\n/** Configuration for WebSocket reconnection behavior */\nexport interface IIIReconnectionConfig {\n /** Starting delay in milliseconds (default: 1000ms) */\n initialDelayMs: number\n /** Maximum delay cap in milliseconds (default: 30000ms) */\n maxDelayMs: number\n /** Exponential backoff multiplier (default: 2) */\n backoffMultiplier: number\n /** Random jitter factor 0-1 (default: 0.3) */\n jitterFactor: number\n /** Maximum retry attempts, -1 for infinite (default: -1) */\n maxRetries: number\n}\n\n/** Default reconnection configuration */\nexport const DEFAULT_BRIDGE_RECONNECTION_CONFIG: IIIReconnectionConfig = {\n initialDelayMs: 1000,\n maxDelayMs: 30000,\n backoffMultiplier: 2,\n jitterFactor: 0.3,\n maxRetries: -1,\n}\n\n/** Default invocation timeout in milliseconds */\nexport const DEFAULT_INVOCATION_TIMEOUT_MS = 30000\n","export enum MessageType {\n RegisterFunction = 'registerfunction',\n UnregisterFunction = 'unregisterfunction',\n InvokeFunction = 'invokefunction',\n InvocationResult = 'invocationresult',\n RegisterTriggerType = 'registertriggertype',\n RegisterTrigger = 'registertrigger',\n UnregisterTrigger = 'unregistertrigger',\n UnregisterTriggerType = 'unregistertriggertype',\n TriggerRegistrationResult = 'triggerregistrationresult',\n WorkerRegistered = 'workerregistered',\n Reattach = 'reattach',\n}\n\nexport type RegisterTriggerTypeMessage = {\n message_type: MessageType.RegisterTriggerType\n /** Unique identifier for the trigger type (e.g. `state`, `durable:subscriber`). */\n id: string\n /** Human-readable description of what this trigger type does. */\n description: string\n}\n\nexport type UnregisterTriggerTypeMessage = {\n message_type: MessageType.UnregisterTriggerType\n id: string\n}\n\nexport type UnregisterTriggerMessage = {\n message_type: MessageType.UnregisterTrigger\n id: string\n type?: string\n}\n\nexport type TriggerRegistrationResultMessage = {\n message_type: MessageType.TriggerRegistrationResult\n id: string\n type: string\n function_id: string\n result?: unknown\n error?: unknown\n}\n\nexport type RegisterTriggerMessage = {\n /** Wire discriminator; always `MessageType.RegisterTrigger`. */\n message_type: MessageType.RegisterTrigger\n /** Unique trigger identifier, generated by the SDK during registration. */\n id: string\n /** Identifier of the registered trigger type this trigger uses (e.g. `storage::object-created`, `http`). */\n type: string\n /** ID of the function this trigger invokes when it fires. */\n function_id: string\n /** Trigger-type-specific configuration, matching the shape the trigger type expects. */\n config: unknown\n}\n\nexport type RegisterFunctionFormat = {\n /**\n * The name of the parameter\n */\n name?: string\n /**\n * The description of the parameter\n */\n description?: string\n /**\n * The type of the parameter\n */\n type?: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null' | 'map' | 'integer'\n /**\n * The body of the parameter (for objects)\n */\n properties?: Record<string, unknown>\n /**\n * The items of the parameter (for arrays)\n */\n items?: unknown\n /**\n * Whether the parameter is required\n */\n required?: string[]\n [key: string]: unknown\n}\n\nexport type RegisterFunctionMessage = {\n message_type: MessageType.RegisterFunction\n /**\n * The path of the function (use :: for namespacing, e.g. external::my_lambda)\n */\n id: string\n /**\n * The description of the function\n */\n description?: string\n /**\n * The request format of the function\n */\n request_format?: RegisterFunctionFormat\n /**\n * The response format of the function\n */\n response_format?: RegisterFunctionFormat\n metadata?: Record<string, unknown>\n}\n\n/**\n * Routing action for {@link TriggerRequest}. Determines how the engine\n * handles the invocation.\n *\n * - `enqueue`: Routes through a named queue for async processing.\n * - `void`: Fire-and-forget, no response.\n */\nexport type TriggerAction = { type: 'enqueue'; queue: string } | { type: 'void' }\n\n/**\n * Input passed to the RBAC auth function during WebSocket upgrade.\n * Contains the HTTP headers, query parameters, and client IP from the\n * connecting worker's upgrade request.\n */\nexport type AuthInput = {\n /** HTTP headers from the WebSocket upgrade request. */\n headers: Record<string, string>\n /** Query parameters from the upgrade URL. Each key maps to an array of values to support repeated keys. */\n query_params: Record<string, string[]>\n /** IP address of the connecting client. */\n ip_address: string\n}\n\n/**\n * Return value from the RBAC auth function. Controls which functions the\n * authenticated worker can invoke and what context is forwarded to the\n * middleware.\n */\nexport type AuthResult = {\n /** Additional function IDs to allow beyond the `expose_functions` config. Defaults to `[]` if omitted. */\n allowed_functions?: string[]\n /** Function IDs to deny even if they match `expose_functions`. Takes precedence over allowed. Defaults to `[]` if omitted. */\n forbidden_functions?: string[]\n /** Trigger type IDs the worker may register triggers for. When omitted, all types are allowed. */\n allowed_trigger_types?: string[]\n /** Whether the worker may register new trigger types. Defaults to `false` if omitted. */\n allow_trigger_type_registration?: boolean\n /** Whether the worker may register new functions. Defaults to `true` if omitted. */\n allow_function_registration?: boolean\n /** Arbitrary context forwarded to the middleware function on every invocation. Defaults to `{}` if omitted. */\n context?: Record<string, unknown>\n /** Optional prefix applied to all function IDs registered by this worker. */\n function_registration_prefix?: string\n}\n\n/**\n * Input passed to the RBAC middleware function on every function invocation\n * through the RBAC port. The middleware can inspect, modify, or reject the\n * call before it reaches the target function.\n */\nexport type MiddlewareFunctionInput = {\n /** ID of the function being invoked. */\n function_id: string\n /** Payload sent by the caller. */\n payload: Record<string, unknown>\n /** Routing action, if any. */\n action?: TriggerAction\n /** Auth context returned by the auth function for this session. */\n context: Record<string, unknown>\n}\n\n/**\n * Input passed to the `on_trigger_type_registration_function_id` hook\n * when a worker attempts to register a new trigger type through the RBAC port.\n * Return an {@link OnTriggerTypeRegistrationResult} with the (possibly mapped)\n * fields, or throw to deny the registration.\n */\nexport type OnTriggerTypeRegistrationInput = {\n /** ID of the trigger type being registered. */\n trigger_type_id: string\n /** Human-readable description of the trigger type. */\n description: string\n /** Auth context from `AuthResult.context` for this session. */\n context: Record<string, unknown>\n}\n\n/**\n * Result returned from the `on_trigger_type_registration_function_id` hook.\n * All fields are optional; omitted fields keep the original value from the\n * registration request.\n */\nexport type OnTriggerTypeRegistrationResult = {\n /** Mapped trigger type ID. */\n trigger_type_id?: string\n /** Mapped description. */\n description?: string\n}\n\n/**\n * Input passed to the `on_trigger_registration_function_id` hook\n * when a worker attempts to register a trigger through the RBAC port.\n * Return an {@link OnTriggerRegistrationResult} with the (possibly mapped)\n * fields, or throw to deny the registration.\n */\nexport type OnTriggerRegistrationInput = {\n /** ID of the trigger being registered. */\n trigger_id: string\n /** Trigger type identifier. */\n trigger_type: string\n /** ID of the function this trigger is bound to. */\n function_id: string\n /** Trigger-specific configuration. */\n config: unknown\n /** Auth context from `AuthResult.context` for this session. */\n context: Record<string, unknown>\n}\n\n/**\n * Result returned from the `on_trigger_registration_function_id` hook.\n * All fields are optional; omitted fields keep the original value from the\n * registration request.\n */\nexport type OnTriggerRegistrationResult = {\n /** Mapped trigger ID. */\n trigger_id?: string\n /** Mapped trigger type. */\n trigger_type?: string\n /** Mapped function ID. */\n function_id?: string\n /** Mapped trigger configuration. */\n config?: unknown\n}\n\n/**\n * Input passed to the `on_function_registration_function_id` hook\n * when a worker attempts to register a function through the RBAC port.\n * Return an {@link OnFunctionRegistrationResult} with the (possibly mapped)\n * fields, or throw to deny the registration.\n */\nexport type OnFunctionRegistrationInput = {\n /** ID of the function being registered. */\n function_id: string\n /** Human-readable description of the function. */\n description?: string\n /** Arbitrary metadata attached to the function. */\n metadata?: Record<string, unknown>\n /** Auth context from `AuthResult.context` for this session. */\n context: Record<string, unknown>\n}\n\n/**\n * Result returned from the `on_function_registration_function_id` hook.\n * All fields are optional; omitted fields keep the original value from the\n * registration request.\n */\nexport type OnFunctionRegistrationResult = {\n /** Mapped function ID. */\n function_id?: string\n /** Mapped description. */\n description?: string\n /** Mapped metadata. */\n metadata?: Record<string, unknown>\n}\n\n/**\n * Result returned when a function is invoked with `TriggerAction.Enqueue`.\n */\nexport type EnqueueResult = {\n /** Unique receipt ID for the enqueued message. */\n messageReceiptId: string\n}\n\n/**\n * Request object passed to {@link ISdk.trigger}.\n *\n * @typeParam TInput - Type of the payload.\n */\nexport type TriggerRequest<TInput = unknown> = {\n /** ID of the function to invoke. */\n function_id: string\n /** Input data passed to the function. */\n payload: TInput\n /** Sets how the trigger is routed. Omit for a synchronous request/response. Specify for a specific routing scheme (e.g. `TriggerAction.Enqueue()`, `TriggerAction.Void()`). */\n action?: TriggerAction\n /** Override the default invocation timeout, in milliseconds. */\n timeoutMs?: number\n}\n\nexport type InvokeFunctionMessage = {\n message_type: MessageType.InvokeFunction\n /**\n * This is optional for async invocations\n */\n invocation_id?: string\n /**\n * The path of the function\n */\n function_id: string\n /**\n * The data to pass to the function\n */\n data: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n /**\n * Trigger action for queue routing or fire-and-forget\n */\n action?: TriggerAction\n}\n\nexport type InvocationResultMessage = {\n message_type: MessageType.InvocationResult\n /**\n * The id of the invocation\n */\n invocation_id: string\n /**\n * The path of the function\n */\n function_id: string\n result?: unknown\n error?: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n}\n\nexport type UnregisterFunctionMessage = {\n message_type: MessageType.UnregisterFunction\n id: string\n}\n\n/**\n * Serializable reference to one end of a streaming channel. Can be included\n * in invocation payloads to pass channel endpoints between workers.\n */\nexport type StreamChannelRef = {\n /** Unique channel identifier. */\n channel_id: string\n /** Access key for authentication. */\n access_key: string\n /** Whether this ref is for reading or writing. */\n direction: 'read' | 'write'\n}\n\nexport type IIIMessage =\n | RegisterFunctionMessage\n | UnregisterFunctionMessage\n | InvokeFunctionMessage\n | InvocationResultMessage\n | RegisterTriggerMessage\n | RegisterTriggerTypeMessage\n | UnregisterTriggerMessage\n | UnregisterTriggerTypeMessage\n | TriggerRegistrationResultMessage\n","import { ChannelReader, ChannelWriter } from './channels'\nimport {\n DEFAULT_BRIDGE_RECONNECTION_CONFIG,\n DEFAULT_INVOCATION_TIMEOUT_MS,\n type IIIConnectionState,\n type IIIReconnectionConfig,\n} from './iii-constants'\nimport {\n type IIIMessage,\n type InvocationResultMessage,\n type InvokeFunctionMessage,\n MessageType,\n type RegisterFunctionMessage,\n type RegisterTriggerMessage,\n type RegisterTriggerTypeMessage,\n type StreamChannelRef,\n type TriggerRegistrationResultMessage,\n type TriggerRequest,\n} from './iii-types'\nimport type { IStream } from './stream'\nimport type { TriggerHandler } from './triggers'\nimport type {\n FunctionRef,\n Invocation,\n ISdk,\n RegisterFunctionOptions,\n RemoteFunctionData,\n RemoteFunctionHandler,\n RemoteTriggerTypeData,\n Trigger,\n TriggerTypeRef,\n} from './types'\nimport { isChannelRef, randomUUID } from './utils'\n\n/** @internal */\nexport type TelemetryOptions = {\n language?: string\n project_name?: string\n framework?: string\n amplitude_api_key?: string\n}\n\n/**\n * Configuration options passed to {@link registerWorker}.\n *\n * @example\n * ```typescript\n * const worker = registerWorker('ws://localhost:49135', {\n * invocationTimeoutMs: 10000,\n * reconnectionConfig: { maxRetries: 5 },\n * })\n * ```\n */\nexport type InitOptions = {\n /** Default timeout for `worker.trigger()` invocations in milliseconds. Defaults to `30000`. */\n invocationTimeoutMs?: number\n /**\n * WebSocket reconnection behavior.\n *\n * @see {@link IIIReconnectionConfig} for available fields and defaults.\n */\n reconnectionConfig?: Partial<IIIReconnectionConfig>\n /** Browser WebSocket connections authenticate via query parameters or cookies; the `headers` option is ignored. */\n headers?: Record<string, string>\n}\n\nclass Sdk implements ISdk {\n private ws?: WebSocket\n private functions = new Map<string, RemoteFunctionData>()\n private invocations = new Map<string, Invocation & { timeout?: ReturnType<typeof setTimeout> }>()\n private triggers = new Map<string, RegisterTriggerMessage>()\n private triggerTypes = new Map<string, RemoteTriggerTypeData>()\n private messagesToSend: Record<string, unknown>[] = []\n private reconnectTimeout?: ReturnType<typeof setTimeout>\n private invocationTimeoutMs: number\n private reconnectionConfig: IIIReconnectionConfig\n private reconnectAttempt = 0\n private connectionState: IIIConnectionState = 'disconnected'\n private connectionListeners = new Set<(state: IIIConnectionState) => void>()\n private isShuttingDown = false\n private workerId?: string\n private reattachToken?: string\n\n constructor(\n private readonly address: string,\n private readonly options?: InitOptions,\n ) {\n this.invocationTimeoutMs = options?.invocationTimeoutMs ?? DEFAULT_INVOCATION_TIMEOUT_MS\n this.reconnectionConfig = {\n ...DEFAULT_BRIDGE_RECONNECTION_CONFIG,\n ...options?.reconnectionConfig,\n }\n\n this.connect()\n }\n\n /**\n * Registers a custom trigger type with the engine. A trigger type defines\n * how external events (HTTP, cron, queue, etc.) map to function invocations.\n *\n * @param triggerType - Trigger type registration input.\n * @param triggerType.id - Unique trigger type identifier.\n * @param triggerType.description - Human-readable description.\n * @param handler - Handler with `registerTrigger` / `unregisterTrigger` callbacks.\n *\n * @example\n * ```typescript\n * worker.registerTriggerType(\n * { id: 'my-trigger', description: 'Custom trigger' },\n * {\n * async registerTrigger({ id, function_id, config }) { },\n * async unregisterTrigger({ id, function_id, config }) { },\n * },\n * )\n * ```\n */\n registerTriggerType = <TConfig>(\n triggerType: Omit<RegisterTriggerTypeMessage, 'message_type'>,\n handler: TriggerHandler<TConfig>,\n ): TriggerTypeRef<TConfig> => {\n this.sendMessage(MessageType.RegisterTriggerType, triggerType, true)\n this.triggerTypes.set(triggerType.id, {\n message: { ...triggerType, message_type: MessageType.RegisterTriggerType },\n handler,\n })\n\n return {\n id: triggerType.id,\n registerTrigger: (functionId: string, config: TConfig) => {\n return this.registerTrigger({\n type: triggerType.id,\n function_id: functionId,\n config,\n })\n },\n registerFunction: (functionId, handler, config) => {\n const ref = this.registerFunction(functionId, handler)\n this.registerTrigger({\n type: triggerType.id,\n function_id: functionId,\n config,\n })\n return ref\n },\n unregister: () => {\n this.unregisterTriggerType(triggerType)\n },\n }\n }\n\n /**\n * Unregisters a previously registered trigger type.\n *\n * @param triggerType - The trigger type to unregister (must match the `id` used during registration).\n */\n unregisterTriggerType = (triggerType: Omit<RegisterTriggerTypeMessage, 'message_type'>): void => {\n this.sendMessage(MessageType.UnregisterTriggerType, triggerType, true)\n this.triggerTypes.delete(triggerType.id)\n }\n\n /**\n * Binds a trigger configuration to a registered function. When the trigger\n * fires, the engine invokes the target function.\n *\n * @param trigger - Trigger registration input.\n * @param trigger.type - Trigger type (e.g. `http`, `durable:subscriber`, `cron`).\n * @param trigger.function_id - ID of the function to invoke.\n * @param trigger.config - Trigger-specific configuration.\n * @returns A {@link Trigger} handle with an `unregister()` method.\n *\n * @example\n * ```typescript\n * const trigger = worker.registerTrigger({\n * type: 'http',\n * function_id: 'greet',\n * config: { api_path: '/greet', http_method: 'GET' },\n * })\n *\n * // Later...\n * trigger.unregister()\n * ```\n */\n registerTrigger = (trigger: Omit<RegisterTriggerMessage, 'message_type' | 'id'>): Trigger => {\n const id = randomUUID()\n const fullTrigger: RegisterTriggerMessage = {\n ...trigger,\n id,\n message_type: MessageType.RegisterTrigger,\n }\n this.sendMessage(MessageType.RegisterTrigger, fullTrigger, true)\n this.triggers.set(id, fullTrigger)\n\n return {\n unregister: () => {\n this.sendMessage(MessageType.UnregisterTrigger, {\n id,\n message_type: MessageType.UnregisterTrigger,\n type: fullTrigger.type,\n })\n this.triggers.delete(id)\n },\n }\n }\n\n /**\n * Registers a function with the engine. The `functionId` is the unique identifier\n * used by triggers and invocations.\n *\n * The handler runs locally in the browser session; HTTP invocation configs\n * are a Node.js SDK feature and are not accepted here.\n *\n * @param functionId - Unique function identifier.\n * @param handlerOrInvocation - Async handler executed when the function is invoked.\n * @param options - Optional function registration options (description, request/response formats, metadata).\n * @returns A {@link FunctionRef} with `id` and `unregister()`.\n *\n * @example\n * ```typescript\n * const fn = worker.registerFunction(\n * 'greet',\n * async (input: { name: string }) => {\n * return { message: `Hello, ${input.name}!` }\n * },\n * { description: 'Greets a user' },\n * )\n * ```\n */\n registerFunction = (\n functionId: string,\n handlerOrInvocation: RemoteFunctionHandler,\n options?: RegisterFunctionOptions,\n ): FunctionRef => {\n if (!functionId || functionId.trim() === '') {\n throw new Error('id is required')\n }\n if (this.functions.has(functionId)) {\n throw new Error(`function id already registered: ${functionId}`)\n }\n\n const fullMessage: RegisterFunctionMessage = {\n ...options,\n id: functionId,\n message_type: MessageType.RegisterFunction,\n }\n\n this.sendMessage(MessageType.RegisterFunction, fullMessage, true)\n\n const handler = handlerOrInvocation as RemoteFunctionHandler\n this.functions.set(functionId, {\n message: fullMessage,\n handler: async (input, _traceparent?: string, _baggage?: string) => {\n return await handler(input)\n },\n })\n\n return {\n id: functionId,\n unregister: () => {\n this.sendMessage(MessageType.UnregisterFunction, { id: functionId }, true)\n this.functions.delete(functionId)\n },\n }\n }\n\n /**\n * @internal Implementation backing the `createChannel` helper in the\n * `iii-browser-sdk/helpers` submodule. Not part of the public `ISdk` surface.\n *\n * Creates a streaming channel pair for worker-to-worker data transfer.\n * Returns a {@link Channel} with a local writer/reader and serializable refs\n * that can be passed as fields in invocation data to other functions.\n */\n __helpers_create_channel = async (bufferSize?: number): Promise<import('./types').Channel> => {\n const result = await this.trigger<{ buffer_size?: number }, { writer: StreamChannelRef; reader: StreamChannelRef }>(\n { function_id: 'engine::channels::create', payload: { buffer_size: bufferSize } },\n )\n\n return {\n writer: new ChannelWriter(this.address, result.writer),\n reader: new ChannelReader(this.address, result.reader),\n writerRef: result.writer,\n readerRef: result.reader,\n }\n }\n\n /**\n * Invokes a remote function. The routing behavior and return type depend\n * on the `action` field of the request.\n *\n * | `action` | Behavior | Return type |\n * |-------------------------------|----------------------------------------------------|----------------------- |\n * | _(none)_ | Synchronous: waits for the function to return | `Promise<TOutput>` |\n * | `TriggerAction.Enqueue(...)` | Async via named queue; engine acknowledges enqueue | `Promise<EnqueueResult>` |\n * | `TriggerAction.Void()` | Fire-and-forget, no response | `Promise<undefined>` |\n *\n * @param request - The trigger request.\n * @param request.function_id - ID of the function to invoke.\n * @param request.payload - Payload to pass to the function.\n * @param request.action - Routing action. Omit for synchronous request/response.\n * @param request.timeoutMs - Override the default invocation timeout.\n * @returns The result of the function invocation.\n *\n * @example\n * ```typescript\n * import { TriggerAction } from 'iii-browser-sdk'\n *\n * // Synchronous\n * const result = await worker.trigger({ function_id: 'get-order', payload: { id: '123' } })\n *\n * // Enqueue\n * const { messageReceiptId } = await worker.trigger({\n * function_id: 'payments::charge',\n * payload: { orderId: '123', amount: 49.99 },\n * action: TriggerAction.Enqueue({ queue: 'payment' }),\n * })\n *\n * // Fire-and-forget\n * worker.trigger({\n * function_id: 'notifications::send',\n * payload: { userId: '123' },\n * action: TriggerAction.Void(),\n * })\n * ```\n */\n // biome-ignore lint/suspicious/noExplicitAny: TOutput defaults to any so untyped calls type-check (the engine cannot express the return type statically)\n trigger = async <TInput = unknown, TOutput = any>(\n request: TriggerRequest<TInput>,\n ): Promise<TOutput> => {\n const { function_id, payload, action, timeoutMs } = request\n const effectiveTimeout = timeoutMs ?? this.invocationTimeoutMs\n\n if (action?.type === 'void') {\n this.sendMessage(MessageType.InvokeFunction, {\n function_id,\n data: payload,\n action,\n })\n return undefined as TOutput\n }\n\n const invocation_id = randomUUID()\n\n return new Promise<TOutput>((resolve, reject) => {\n const timeout = setTimeout(() => {\n const invocation = this.invocations.get(invocation_id)\n if (invocation) {\n this.invocations.delete(invocation_id)\n reject(new Error(`Invocation timeout after ${effectiveTimeout}ms: ${function_id}`))\n }\n }, effectiveTimeout)\n\n this.invocations.set(invocation_id, {\n resolve: (result: TOutput) => {\n clearTimeout(timeout)\n resolve(result)\n },\n reject: (error: unknown) => {\n clearTimeout(timeout)\n reject(error)\n },\n timeout,\n })\n\n this.sendMessage(MessageType.InvokeFunction, {\n invocation_id,\n function_id,\n data: payload,\n action,\n })\n })\n }\n\n /**\n * @internal Implementation backing the `createStream` helper in the\n * `iii-browser-sdk/helpers` submodule. Not part of the public `ISdk` surface.\n *\n * Registers a custom stream implementation, overriding the engine default\n * for the given stream name.\n */\n __helpers_create_stream = <TData>(streamName: string, stream: IStream<TData>): void => {\n this.registerFunction(`stream::get(${streamName})`, stream.get.bind(stream))\n this.registerFunction(`stream::set(${streamName})`, stream.set.bind(stream))\n this.registerFunction(`stream::delete(${streamName})`, stream.delete.bind(stream))\n this.registerFunction(`stream::list(${streamName})`, stream.list.bind(stream))\n this.registerFunction(`stream::list_groups(${streamName})`, stream.listGroups.bind(stream))\n }\n\n /**\n * Gracefully shutdown the SDK, cleaning up all resources.\n */\n shutdown = async (): Promise<void> => {\n this.isShuttingDown = true\n\n this.clearReconnectTimeout()\n\n for (const [_id, invocation] of this.invocations) {\n if (invocation.timeout) {\n clearTimeout(invocation.timeout)\n }\n invocation.reject(new Error('iii is shutting down'))\n }\n this.invocations.clear()\n\n if (this.ws) {\n this.ws.onopen = null\n this.ws.onclose = null\n this.ws.onerror = null\n this.ws.onmessage = null\n this.ws.close()\n this.ws = undefined\n }\n\n this.setConnectionState('disconnected')\n }\n\n /**\n * Subscribe to connection-state transitions. The handler is fired immediately\n * with the current state, then on every transition. Multiple listeners are\n * supported. Returns an unsubscribe function.\n */\n addConnectionStateListener = (handler: (state: IIIConnectionState) => void): (() => void) => {\n this.connectionListeners.add(handler)\n try {\n handler(this.connectionState)\n } catch (e) {\n console.error('[iii] connection listener threw on initial fire', e)\n }\n return () => {\n this.connectionListeners.delete(handler)\n }\n }\n\n // private methods\n\n private setConnectionState(state: IIIConnectionState): void {\n if (this.connectionState !== state) {\n this.connectionState = state\n for (const handler of this.connectionListeners) {\n try {\n handler(state)\n } catch (e) {\n console.error('[iii] connection listener threw', e)\n }\n }\n }\n }\n\n private connect(): void {\n if (this.isShuttingDown) {\n return\n }\n\n this.setConnectionState('connecting')\n this.ws = new WebSocket(this.address)\n this.ws.onopen = this.onSocketOpen.bind(this)\n this.ws.onclose = this.onSocketClose.bind(this)\n this.ws.onerror = this.onSocketError.bind(this)\n }\n\n private clearReconnectTimeout(): void {\n if (this.reconnectTimeout) {\n clearTimeout(this.reconnectTimeout)\n this.reconnectTimeout = undefined\n }\n }\n\n private scheduleReconnect(): void {\n if (this.isShuttingDown) {\n return\n }\n\n const { maxRetries, initialDelayMs, backoffMultiplier, maxDelayMs, jitterFactor } = this.reconnectionConfig\n\n if (maxRetries !== -1 && this.reconnectAttempt >= maxRetries) {\n this.setConnectionState('failed')\n console.error(`[iii] Max reconnection retries (${maxRetries}) reached, giving up`)\n return\n }\n\n if (this.reconnectTimeout) {\n return\n }\n\n const exponentialDelay = initialDelayMs * backoffMultiplier ** this.reconnectAttempt\n const cappedDelay = Math.min(exponentialDelay, maxDelayMs)\n const jitter = cappedDelay * jitterFactor * (2 * Math.random() - 1)\n const delay = Math.floor(cappedDelay + jitter)\n\n this.setConnectionState('reconnecting')\n console.debug(`[iii] Reconnecting in ${delay}ms (attempt ${this.reconnectAttempt + 1})...`)\n\n this.reconnectTimeout = setTimeout(() => {\n this.reconnectTimeout = undefined\n this.reconnectAttempt++\n this.connect()\n }, delay)\n }\n\n private onSocketError(): void {\n console.error('[iii] WebSocket error')\n }\n\n private onSocketClose(): void {\n if (this.ws) {\n this.ws.onopen = null\n this.ws.onclose = null\n this.ws.onerror = null\n this.ws.onmessage = null\n }\n this.ws = undefined\n\n this.setConnectionState('disconnected')\n this.scheduleReconnect()\n }\n\n private onSocketOpen(): void {\n this.clearReconnectTimeout()\n this.reconnectAttempt = 0\n this.setConnectionState('connected')\n\n if (this.ws) {\n this.ws.onmessage = this.onMessage.bind(this)\n }\n\n // Reconnect: present the previous engine-assigned identity BEFORE the\n // registration replay so the engine retires the old connection and the\n // replay lands on a clean slate instead of racing its cleanup. The\n // token proves we ARE that worker (ids alone are publicly listable).\n if (this.workerId) {\n this.sendMessageRaw(\n JSON.stringify({\n type: MessageType.Reattach,\n previous_worker_id: this.workerId,\n reattach_token: this.reattachToken,\n }),\n )\n }\n\n this.triggerTypes.forEach(({ message }) => {\n this.sendMessage(MessageType.RegisterTriggerType, message, true)\n })\n this.functions.forEach(({ message }) => {\n this.sendMessage(MessageType.RegisterFunction, message, true)\n })\n this.triggers.forEach((trigger) => {\n this.sendMessage(MessageType.RegisterTrigger, trigger, true)\n })\n\n const pending = this.messagesToSend\n this.messagesToSend = []\n for (const message of pending) {\n if (\n message.type === MessageType.InvokeFunction &&\n typeof message.invocation_id === 'string' &&\n !this.invocations.has(message.invocation_id)\n ) {\n continue\n }\n this.sendMessageRaw(JSON.stringify(message))\n }\n }\n\n private isOpen(): boolean {\n return this.ws?.readyState === WebSocket.OPEN\n }\n\n private sendMessageRaw(data: string): void {\n if (this.ws && this.isOpen()) {\n try {\n this.ws.send(data)\n } catch (error) {\n console.error('[iii] Exception while sending message', error)\n }\n }\n }\n\n private toWireFormat(messageType: MessageType, message: Omit<IIIMessage, 'message_type'>): Record<string, unknown> {\n const { message_type: _, ...rest } = message as Record<string, unknown>\n if (messageType === MessageType.RegisterTrigger && 'type' in message) {\n const { type: triggerType, ...triggerRest } = message as RegisterTriggerMessage\n return { type: messageType, ...triggerRest, trigger_type: triggerType }\n }\n if (messageType === MessageType.UnregisterTrigger && 'type' in message) {\n const { type: triggerType, ...triggerRest } = message as RegisterTriggerMessage\n return { type: messageType, ...triggerRest, trigger_type: triggerType }\n }\n if (messageType === MessageType.TriggerRegistrationResult && 'type' in message) {\n const { type: triggerType, ...resultRest } = message as TriggerRegistrationResultMessage\n return { type: messageType, ...resultRest, trigger_type: triggerType }\n }\n return { type: messageType, ...rest } as Record<string, unknown>\n }\n\n private sendMessage(messageType: MessageType, message: Omit<IIIMessage, 'message_type'>, skipIfClosed = false): void {\n const wireMessage = this.toWireFormat(messageType, message)\n if (this.isOpen()) {\n this.sendMessageRaw(JSON.stringify(wireMessage))\n } else if (!skipIfClosed) {\n this.messagesToSend.push(wireMessage)\n }\n }\n\n private onInvocationResult(invocation_id: string, result: unknown, error: unknown): void {\n const invocation = this.invocations.get(invocation_id)\n\n if (invocation) {\n if (invocation.timeout) {\n clearTimeout(invocation.timeout)\n }\n error ? invocation.reject(error) : invocation.resolve(result)\n }\n\n this.invocations.delete(invocation_id)\n }\n\n private resolveChannelValue(value: unknown): unknown {\n if (isChannelRef(value)) {\n return value.direction === 'read'\n ? new ChannelReader(this.address, value)\n : new ChannelWriter(this.address, value)\n }\n if (Array.isArray(value)) {\n return value.map((item) => this.resolveChannelValue(item))\n }\n if (value !== null && typeof value === 'object') {\n const out: Record<string, unknown> = {}\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n out[k] = this.resolveChannelValue(v)\n }\n return out\n }\n return value\n }\n\n private async onInvokeFunction<TInput>(\n invocation_id: string | undefined,\n function_id: string,\n input: TInput,\n traceparent?: string,\n baggage?: string,\n ): Promise<unknown> {\n const fn = this.functions.get(function_id)\n\n const resolvedInput = this.resolveChannelValue(input) as TInput\n\n if (fn?.handler) {\n if (!invocation_id) {\n try {\n await fn.handler(resolvedInput, traceparent, baggage)\n } catch (error) {\n console.error(`[iii] Error invoking function ${function_id}`, error)\n }\n return\n }\n\n try {\n const result = await fn.handler(resolvedInput, traceparent, baggage)\n this.sendMessage(MessageType.InvocationResult, {\n invocation_id,\n function_id,\n result,\n traceparent,\n baggage,\n })\n } catch (error) {\n const isError = error instanceof Error\n this.sendMessage(MessageType.InvocationResult, {\n invocation_id,\n function_id,\n error: {\n code: 'invocation_failed',\n message: isError ? error.message : String(error),\n stacktrace: isError ? error.stack : undefined,\n },\n traceparent,\n baggage,\n })\n }\n } else {\n const errorCode = fn ? 'function_not_invokable' : 'function_not_found'\n const errorMessage = fn ? 'Function is HTTP-invoked and cannot be invoked locally' : 'Function not found'\n if (invocation_id) {\n this.sendMessage(MessageType.InvocationResult, {\n invocation_id,\n function_id,\n error: { code: errorCode, message: errorMessage },\n traceparent,\n baggage,\n })\n }\n }\n }\n\n private async onRegisterTrigger(message: { trigger_type: string; id: string; function_id: string; config: unknown }) {\n const { trigger_type, id, function_id, config } = message\n const triggerTypeData = this.triggerTypes.get(trigger_type)\n\n if (triggerTypeData) {\n try {\n await triggerTypeData.handler.registerTrigger({ id, function_id, config })\n this.sendMessage(MessageType.TriggerRegistrationResult, {\n id,\n message_type: MessageType.TriggerRegistrationResult,\n type: trigger_type,\n function_id,\n })\n } catch (error) {\n this.sendMessage(MessageType.TriggerRegistrationResult, {\n id,\n message_type: MessageType.TriggerRegistrationResult,\n type: trigger_type,\n function_id,\n error: { code: 'trigger_registration_failed', message: (error as Error).message },\n })\n }\n } else {\n this.sendMessage(MessageType.TriggerRegistrationResult, {\n id,\n message_type: MessageType.TriggerRegistrationResult,\n type: trigger_type,\n function_id,\n error: { code: 'trigger_type_not_found', message: 'Trigger type not found' },\n })\n }\n }\n\n private async onUnregisterTrigger(message: {\n trigger_type?: string\n id: string\n function_id?: string\n config?: unknown\n }) {\n const trigger_type = message.trigger_type\n if (!trigger_type) return\n\n const triggerTypeData = this.triggerTypes.get(trigger_type)\n if (!triggerTypeData) return\n\n const { id, function_id = '', config } = message\n try {\n await triggerTypeData.handler.unregisterTrigger({ id, function_id, config })\n } catch (error) {\n console.error(`[iii] Error unregistering trigger ${id}`, error)\n }\n }\n\n private onMessage(event: MessageEvent): void {\n let msgType: MessageType\n let message: Record<string, unknown>\n\n try {\n const parsed = JSON.parse(typeof event.data === 'string' ? event.data : '') as Record<string, unknown>\n msgType = parsed.type as MessageType\n const { type: _, ...rest } = parsed\n message = rest\n } catch (error) {\n console.error('[iii] Failed to parse incoming message', error)\n return\n }\n\n if (msgType === MessageType.InvocationResult) {\n const { invocation_id, result, error } = message as InvocationResultMessage\n this.onInvocationResult(invocation_id, result, error)\n } else if (msgType === MessageType.InvokeFunction) {\n const { invocation_id, function_id, data, traceparent, baggage } = message as InvokeFunctionMessage\n this.onInvokeFunction(invocation_id, function_id, data, traceparent, baggage)\n } else if (msgType === MessageType.RegisterTrigger) {\n this.onRegisterTrigger(message as { trigger_type: string; id: string; function_id: string; config: unknown })\n } else if (msgType === MessageType.UnregisterTrigger) {\n this.onUnregisterTrigger(\n message as { trigger_type?: string; id: string; function_id?: string; config?: unknown },\n )\n } else if (msgType === MessageType.WorkerRegistered) {\n const { worker_id, reattach_token } = message as { worker_id: string; reattach_token?: string }\n this.workerId = worker_id\n this.reattachToken = reattach_token\n }\n }\n}\n\n/**\n * Factory object that constructs routing actions for {@link ISdk.trigger}.\n *\n * @example\n * ```typescript\n * import { TriggerAction } from 'iii-browser-sdk'\n *\n * // Enqueue to a named queue\n * worker.trigger({\n * function_id: 'process',\n * payload: { data: 'hello' },\n * action: TriggerAction.Enqueue({ queue: 'jobs' }),\n * })\n *\n * // Fire-and-forget\n * worker.trigger({\n * function_id: 'notify',\n * payload: {},\n * action: TriggerAction.Void(),\n * })\n * ```\n */\nexport const TriggerAction = {\n /**\n * Routes the invocation through a named queue. The engine enqueues the job,\n * acknowledges the caller with `{ messageReceiptId }`, and processes it\n * asynchronously.\n *\n * @param opts - Queue routing options.\n * @param opts.queue - Name of the target queue.\n */\n Enqueue: (opts: { queue: string }) => ({ type: 'enqueue' as const, ...opts }),\n /**\n * Fire-and-forget routing. The engine forwards the invocation without\n * waiting for a response or queuing the job.\n */\n Void: () => ({ type: 'void' as const }),\n} as const\n\n/**\n * Register the worker with a iii instance, returns a connected worker client.\n * The WebSocket connection is established automatically.\n *\n * @param address - WebSocket URL of the III engine (e.g. `ws://localhost:49135`).\n * @param options - Optional {@link InitOptions} for worker name, timeouts, and reconnection.\n * @returns A connected {@link ISdk} instance.\n *\n * @example\n * ```typescript\n * import { registerWorker } from 'iii-browser-sdk'\n *\n * const worker = registerWorker('ws://localhost:49135')\n * ```\n */\nexport const registerWorker = (address: string, options?: InitOptions): ISdk => new Sdk(address, options)\n"],"mappings":";;;;;;;;;;;;;;;AAaA,MAAa,kBAAkB;CAC7B,gBAAgB;CAChB,gBAAgB;CAChB,cAAc;CACd,cAAc;CACd,eAAe;CACf,eAAe;CACf,0BAA0B;CAC1B,0BAA0B;CAC1B,iBAAiB;CAClB;;AAGD,MAAa,iBAAiB,EAC5B,qBAAqB,+BACtB;;AAoBD,MAAa,qCAA4D;CACvE,gBAAgB;CAChB,YAAY;CACZ,mBAAmB;CACnB,cAAc;CACd,YAAY;CACb;;AAGD,M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,EAAE,eAAe,aAAa,MAAM,aAAa,YAAY;AACnE,QAAK,iBAAiB,eAAe,aAAa,MAAM,aAAa,QAAQ;aACpE,YAAY,YAAY,gBACjC,MAAK,kBAAkB,QAAsF;WACpG,YAAY,YAAY,kBACjC,MAAK,oBACH,QACD;WACQ,YAAY,YAAY,kBAAkB;GACnD,MAAM,EAAE,WAAW,mBAAmB;AACtC,QAAK,WAAW;AAChB,QAAK,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;AA2B3B,MAAa,gBAAgB;CAS3B,UAAU,UAA6B;EAAE,MAAM;EAAoB,GAAG;EAAM;CAK5E,aAAa,EAAE,MAAM,QAAiB;CACvC;;;;;;;;;;;;;;;;AAiBD,MAAa,kBAAkB,SAAiB,YAAgC,IAAI,IAAI,SAAS,QAAQ"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/iii-constants.ts","../src/iii-types.ts","../src/iii.ts"],"sourcesContent":["/**\n * Constants for the III module.\n */\n\n/**\n * Engine function paths for internal operations.\n *\n * Naming note: `LIST_TRIGGERS` / `INFO_TRIGGERS` cover trigger TYPES\n * (templates). `LIST_REGISTERED_TRIGGERS` / `INFO_REGISTERED_TRIGGERS`\n * cover trigger INSTANCES (subscriber rows). The old\n * `engine::trigger-types::list` builtin has been removed and is now\n * served by `engine::triggers::list`.\n */\nexport const EngineFunctions = {\n LIST_FUNCTIONS: 'engine::functions::list',\n INFO_FUNCTIONS: 'engine::functions::info',\n LIST_WORKERS: 'engine::workers::list',\n INFO_WORKERS: 'engine::workers::info',\n LIST_TRIGGERS: 'engine::triggers::list',\n INFO_TRIGGERS: 'engine::triggers::info',\n LIST_REGISTERED_TRIGGERS: 'engine::registered-triggers::list',\n INFO_REGISTERED_TRIGGERS: 'engine::registered-triggers::info',\n REGISTER_WORKER: 'engine::workers::register',\n} as const\n\n/** Engine trigger types */\nexport const EngineTriggers = {\n FUNCTIONS_AVAILABLE: 'engine::functions-available',\n} as const\n\n/** Connection state for the III WebSocket */\nexport type IIIConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'failed'\n\n/** Configuration for WebSocket reconnection behavior */\nexport interface IIIReconnectionConfig {\n /** Starting delay in milliseconds (default: 1000ms) */\n initialDelayMs: number\n /** Maximum delay cap in milliseconds (default: 30000ms) */\n maxDelayMs: number\n /** Exponential backoff multiplier (default: 2) */\n backoffMultiplier: number\n /** Random jitter factor 0-1 (default: 0.3) */\n jitterFactor: number\n /** Maximum retry attempts, -1 for infinite (default: -1) */\n maxRetries: number\n}\n\n/** Default reconnection configuration */\nexport const DEFAULT_BRIDGE_RECONNECTION_CONFIG: IIIReconnectionConfig = {\n initialDelayMs: 1000,\n maxDelayMs: 30000,\n backoffMultiplier: 2,\n jitterFactor: 0.3,\n maxRetries: -1,\n}\n\n/** Default invocation timeout in milliseconds */\nexport const DEFAULT_INVOCATION_TIMEOUT_MS = 30000\n","export enum MessageType {\n RegisterFunction = 'registerfunction',\n UnregisterFunction = 'unregisterfunction',\n InvokeFunction = 'invokefunction',\n InvocationResult = 'invocationresult',\n RegisterTriggerType = 'registertriggertype',\n RegisterTrigger = 'registertrigger',\n UnregisterTrigger = 'unregistertrigger',\n UnregisterTriggerType = 'unregistertriggertype',\n TriggerRegistrationResult = 'triggerregistrationresult',\n RegistrationRejected = 'registrationrejected',\n WorkerRegistered = 'workerregistered',\n Reattach = 'reattach',\n}\n\nexport type RegisterTriggerTypeMessage = {\n message_type: MessageType.RegisterTriggerType\n /** Unique identifier for the trigger type (e.g. `state`, `durable:subscriber`). */\n id: string\n /** Human-readable description of what this trigger type does. */\n description: string\n}\n\nexport type UnregisterTriggerTypeMessage = {\n message_type: MessageType.UnregisterTriggerType\n id: string\n}\n\nexport type UnregisterTriggerMessage = {\n message_type: MessageType.UnregisterTrigger\n id: string\n type?: string\n}\n\nexport type TriggerRegistrationResultMessage = {\n message_type: MessageType.TriggerRegistrationResult\n id: string\n type: string\n function_id: string\n result?: unknown\n error?: unknown\n}\n\nexport type RegisterTriggerMessage = {\n /** Wire discriminator; always `MessageType.RegisterTrigger`. */\n message_type: MessageType.RegisterTrigger\n /** Unique trigger identifier, generated by the SDK during registration. */\n id: string\n /** Identifier of the registered trigger type this trigger uses (e.g. `storage::object-created`, `http`). */\n type: string\n /** ID of the function this trigger invokes when it fires. */\n function_id: string\n /** Trigger-type-specific configuration, matching the shape the trigger type expects. */\n config: unknown\n}\n\nexport type RegisterFunctionFormat = {\n /**\n * The name of the parameter\n */\n name?: string\n /**\n * The description of the parameter\n */\n description?: string\n /**\n * The type of the parameter\n */\n type?: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null' | 'map' | 'integer'\n /**\n * The body of the parameter (for objects)\n */\n properties?: Record<string, unknown>\n /**\n * The items of the parameter (for arrays)\n */\n items?: unknown\n /**\n * Whether the parameter is required\n */\n required?: string[]\n [key: string]: unknown\n}\n\nexport type RegisterFunctionMessage = {\n message_type: MessageType.RegisterFunction\n /**\n * The path of the function (use :: for namespacing, e.g. external::my_lambda)\n */\n id: string\n /**\n * The description of the function\n */\n description?: string\n /**\n * The request format of the function\n */\n request_format?: RegisterFunctionFormat\n /**\n * The response format of the function\n */\n response_format?: RegisterFunctionFormat\n metadata?: Record<string, unknown>\n}\n\n/**\n * Routing action for {@link TriggerRequest}. Determines how the engine\n * handles the invocation.\n *\n * - `enqueue`: Routes through a named queue for async processing.\n * - `void`: Fire-and-forget, no response.\n */\nexport type TriggerAction = { type: 'enqueue'; queue: string } | { type: 'void' }\n\n/**\n * Input passed to the RBAC auth function during WebSocket upgrade.\n * Contains the HTTP headers, query parameters, and client IP from the\n * connecting worker's upgrade request.\n */\nexport type AuthInput = {\n /** HTTP headers from the WebSocket upgrade request. */\n headers: Record<string, string>\n /** Query parameters from the upgrade URL. Each key maps to an array of values to support repeated keys. */\n query_params: Record<string, string[]>\n /** IP address of the connecting client. */\n ip_address: string\n}\n\n/**\n * Return value from the RBAC auth function. Controls which functions the\n * authenticated worker can invoke and what context is forwarded to the\n * middleware.\n */\nexport type AuthResult = {\n /** Additional function IDs to allow beyond the `expose_functions` config. Defaults to `[]` if omitted. */\n allowed_functions?: string[]\n /** Function IDs to deny even if they match `expose_functions`. Takes precedence over allowed. Defaults to `[]` if omitted. */\n forbidden_functions?: string[]\n /** Trigger type IDs the worker may register triggers for. When omitted, all types are allowed. */\n allowed_trigger_types?: string[]\n /** Whether the worker may register new trigger types. Defaults to `false` if omitted. */\n allow_trigger_type_registration?: boolean\n /** Whether the worker may register new functions. Defaults to `true` if omitted. */\n allow_function_registration?: boolean\n /** Arbitrary context forwarded to the middleware function on every invocation. Defaults to `{}` if omitted. */\n context?: Record<string, unknown>\n /** Optional prefix applied to all function IDs registered by this worker. */\n function_registration_prefix?: string\n}\n\n/**\n * Input passed to the RBAC middleware function on every function invocation\n * through the RBAC port. The middleware can inspect, modify, or reject the\n * call before it reaches the target function.\n */\nexport type MiddlewareFunctionInput = {\n /** ID of the function being invoked. */\n function_id: string\n /** Payload sent by the caller. */\n payload: Record<string, unknown>\n /** Routing action, if any. */\n action?: TriggerAction\n /** Auth context returned by the auth function for this session. */\n context: Record<string, unknown>\n /**\n * Target namespace the invoke addressed; forward the call here to stay in the\n * caller's namespace. Absent → the engine's default namespace.\n */\n namespace?: string\n}\n\n/**\n * Input passed to the `on_trigger_type_registration_function_id` hook\n * when a worker attempts to register a new trigger type through the RBAC port.\n * Return an {@link OnTriggerTypeRegistrationResult} with the (possibly mapped)\n * fields, or throw to deny the registration.\n */\nexport type OnTriggerTypeRegistrationInput = {\n /** ID of the trigger type being registered. */\n trigger_type_id: string\n /** Human-readable description of the trigger type. */\n description: string\n /** Auth context from `AuthResult.context` for this session. */\n context: Record<string, unknown>\n}\n\n/**\n * Result returned from the `on_trigger_type_registration_function_id` hook.\n * All fields are optional; omitted fields keep the original value from the\n * registration request.\n */\nexport type OnTriggerTypeRegistrationResult = {\n /** Mapped trigger type ID. */\n trigger_type_id?: string\n /** Mapped description. */\n description?: string\n}\n\n/**\n * Input passed to the `on_trigger_registration_function_id` hook\n * when a worker attempts to register a trigger through the RBAC port.\n * Return an {@link OnTriggerRegistrationResult} with the (possibly mapped)\n * fields, or throw to deny the registration.\n */\nexport type OnTriggerRegistrationInput = {\n /** ID of the trigger being registered. */\n trigger_id: string\n /** Trigger type identifier. */\n trigger_type: string\n /** ID of the function this trigger is bound to. */\n function_id: string\n /** Trigger-specific configuration. */\n config: unknown\n /** Auth context from `AuthResult.context` for this session. */\n context: Record<string, unknown>\n}\n\n/**\n * Result returned from the `on_trigger_registration_function_id` hook.\n * All fields are optional; omitted fields keep the original value from the\n * registration request.\n */\nexport type OnTriggerRegistrationResult = {\n /** Mapped trigger ID. */\n trigger_id?: string\n /** Mapped trigger type. */\n trigger_type?: string\n /** Mapped function ID. */\n function_id?: string\n /** Mapped trigger configuration. */\n config?: unknown\n}\n\n/**\n * Input passed to the `on_function_registration_function_id` hook\n * when a worker attempts to register a function through the RBAC port.\n * Return an {@link OnFunctionRegistrationResult} with the (possibly mapped)\n * fields, or throw to deny the registration.\n */\nexport type OnFunctionRegistrationInput = {\n /** ID of the function being registered. */\n function_id: string\n /** Human-readable description of the function. */\n description?: string\n /** Arbitrary metadata attached to the function. */\n metadata?: Record<string, unknown>\n /** Auth context from `AuthResult.context` for this session. */\n context: Record<string, unknown>\n}\n\n/**\n * Result returned from the `on_function_registration_function_id` hook.\n * All fields are optional; omitted fields keep the original value from the\n * registration request.\n */\nexport type OnFunctionRegistrationResult = {\n /** Mapped function ID. */\n function_id?: string\n /** Mapped description. */\n description?: string\n /** Mapped metadata. */\n metadata?: Record<string, unknown>\n}\n\n/**\n * Result returned when a function is invoked with `TriggerAction.Enqueue`.\n */\nexport type EnqueueResult = {\n /** Unique receipt ID for the enqueued message. */\n messageReceiptId: string\n}\n\n/**\n * Request object passed to {@link ISdk.trigger}.\n *\n * @typeParam TInput - Type of the payload.\n */\nexport type TriggerRequest<TInput = unknown> = {\n /** ID of the function to invoke. */\n function_id: string\n /** Input data passed to the function. */\n payload: TInput\n /** Sets how the trigger is routed. Omit for a synchronous request/response. Specify for a specific routing scheme (e.g. `TriggerAction.Enqueue()`, `TriggerAction.Void()`). */\n action?: TriggerAction\n /** Override the default invocation timeout, in milliseconds. */\n timeoutMs?: number\n /** Namespace to route this invocation to. Omit to use the engine's default namespace. */\n namespace?: string\n}\n\nexport type InvokeFunctionMessage = {\n message_type: MessageType.InvokeFunction\n /**\n * This is optional for async invocations\n */\n invocation_id?: string\n /**\n * The path of the function\n */\n function_id: string\n /**\n * The data to pass to the function\n */\n data: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n /**\n * Trigger action for queue routing or fire-and-forget\n */\n action?: TriggerAction\n /**\n * Namespace to route this invocation to. Omitted when routing within the default namespace.\n */\n namespace?: string\n}\n\nexport type InvocationResultMessage = {\n message_type: MessageType.InvocationResult\n /**\n * The id of the invocation\n */\n invocation_id: string\n /**\n * The path of the function\n */\n function_id: string\n result?: unknown\n error?: unknown\n /**\n * W3C trace-context traceparent header for distributed tracing\n */\n traceparent?: string\n /**\n * W3C baggage header for cross-cutting context propagation\n */\n baggage?: string\n}\n\nexport type UnregisterFunctionMessage = {\n message_type: MessageType.UnregisterFunction\n id: string\n}\n\n/**\n * Serializable reference to one end of a streaming channel. Can be included\n * in invocation payloads to pass channel endpoints between workers.\n */\nexport type StreamChannelRef = {\n /** Unique channel identifier. */\n channel_id: string\n /** Access key for authentication. */\n access_key: string\n /** Whether this ref is for reading or writing. */\n direction: 'read' | 'write'\n}\n\nexport type IIIMessage =\n | RegisterFunctionMessage\n | UnregisterFunctionMessage\n | InvokeFunctionMessage\n | InvocationResultMessage\n | RegisterTriggerMessage\n | RegisterTriggerTypeMessage\n | UnregisterTriggerMessage\n | UnregisterTriggerTypeMessage\n | TriggerRegistrationResultMessage\n","import { ChannelReader, ChannelWriter } from './channels'\nimport {\n DEFAULT_BRIDGE_RECONNECTION_CONFIG,\n DEFAULT_INVOCATION_TIMEOUT_MS,\n EngineFunctions,\n type IIIConnectionState,\n type IIIReconnectionConfig,\n} from './iii-constants'\nimport {\n type IIIMessage,\n type InvocationResultMessage,\n type InvokeFunctionMessage,\n MessageType,\n type RegisterFunctionMessage,\n type RegisterTriggerMessage,\n type RegisterTriggerTypeMessage,\n type StreamChannelRef,\n type TriggerRegistrationResultMessage,\n type TriggerRequest,\n} from './iii-types'\nimport type { IStream } from './stream'\nimport type { TriggerHandler } from './triggers'\nimport type {\n FunctionRef,\n Invocation,\n ISdk,\n RegisterFunctionOptions,\n RemoteFunctionData,\n RemoteFunctionHandler,\n RemoteTriggerTypeData,\n Trigger,\n TriggerTypeRef,\n} from './types'\nimport { isChannelRef, randomUUID } from './utils'\n\n/** @internal */\nexport type TelemetryOptions = {\n language?: string\n project_name?: string\n framework?: string\n amplitude_api_key?: string\n}\n\n/**\n * Configuration options passed to {@link registerWorker}.\n *\n * @example\n * ```typescript\n * const worker = registerWorker('ws://localhost:49135', {\n * invocationTimeoutMs: 10000,\n * reconnectionConfig: { maxRetries: 5 },\n * })\n * ```\n */\nexport type InitOptions = {\n /**\n * Name this worker announces to the engine. Defaults to a unique\n * `browser:<random>` per client: a browser has no pid to disambiguate by, and\n * the engine allows only one live worker per name in a namespace, so two tabs\n * sharing a fixed name would evict each other.\n */\n workerName?: string\n /**\n * Namespace this worker registers under. When omitted the engine applies its\n * `default` namespace. Scopes worker and function registrations so\n * identically-named entries can coexist across namespaces. The browser has no\n * `process.env`, so there is no environment-variable fallback -- pass the\n * option explicitly.\n */\n namespace?: string\n /** Default timeout for `worker.trigger()` invocations in milliseconds. Defaults to `30000`. */\n invocationTimeoutMs?: number\n /**\n * WebSocket reconnection behavior.\n *\n * @see {@link IIIReconnectionConfig} for available fields and defaults.\n */\n reconnectionConfig?: Partial<IIIReconnectionConfig>\n /** Browser WebSocket connections authenticate via query parameters or cookies; the `headers` option is ignored. */\n headers?: Record<string, string>\n}\n\n/** Short random suffix; `crypto.randomUUID` is unavailable on insecure origins. */\nfunction randomId(): string {\n const c = globalThis.crypto\n if (c?.randomUUID) {\n return c.randomUUID().slice(0, 8)\n }\n if (c?.getRandomValues) {\n return Array.from(c.getRandomValues(new Uint8Array(4)))\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('')\n }\n return Math.random().toString(16).slice(2, 10)\n}\n\nclass Sdk implements ISdk {\n private ws?: WebSocket\n private functions = new Map<string, RemoteFunctionData>()\n private invocations = new Map<string, Invocation & { timeout?: ReturnType<typeof setTimeout> }>()\n private triggers = new Map<string, RegisterTriggerMessage>()\n private triggerTypes = new Map<string, RemoteTriggerTypeData>()\n private messagesToSend: Record<string, unknown>[] = []\n private reconnectTimeout?: ReturnType<typeof setTimeout>\n private invocationTimeoutMs: number\n private reconnectionConfig: IIIReconnectionConfig\n private reconnectAttempt = 0\n private connectionState: IIIConnectionState = 'disconnected'\n private connectionListeners = new Set<(state: IIIConnectionState) => void>()\n private isShuttingDown = false\n private readonly workerName: string\n private readonly namespace?: string\n private workerId?: string\n private reattachToken?: string\n\n constructor(\n private readonly address: string,\n private readonly options?: InitOptions,\n ) {\n this.workerName = options?.workerName ?? `browser:${randomId()}`\n // No env fallback: the browser has no `process.env`.\n this.namespace = options?.namespace\n this.invocationTimeoutMs = options?.invocationTimeoutMs ?? DEFAULT_INVOCATION_TIMEOUT_MS\n this.reconnectionConfig = {\n ...DEFAULT_BRIDGE_RECONNECTION_CONFIG,\n ...options?.reconnectionConfig,\n }\n\n this.connect()\n }\n\n /**\n * Registers a custom trigger type with the engine. A trigger type defines\n * how external events (HTTP, cron, queue, etc.) map to function invocations.\n *\n * @param triggerType - Trigger type registration input.\n * @param triggerType.id - Unique trigger type identifier.\n * @param triggerType.description - Human-readable description.\n * @param handler - Handler with `registerTrigger` / `unregisterTrigger` callbacks.\n *\n * @example\n * ```typescript\n * worker.registerTriggerType(\n * { id: 'my-trigger', description: 'Custom trigger' },\n * {\n * async registerTrigger({ id, function_id, config }) { },\n * async unregisterTrigger({ id, function_id, config }) { },\n * },\n * )\n * ```\n */\n registerTriggerType = <TConfig>(\n triggerType: Omit<RegisterTriggerTypeMessage, 'message_type'>,\n handler: TriggerHandler<TConfig>,\n ): TriggerTypeRef<TConfig> => {\n this.sendMessage(MessageType.RegisterTriggerType, triggerType, true)\n this.triggerTypes.set(triggerType.id, {\n message: { ...triggerType, message_type: MessageType.RegisterTriggerType },\n handler,\n })\n\n return {\n id: triggerType.id,\n registerTrigger: (functionId: string, config: TConfig) => {\n return this.registerTrigger({\n type: triggerType.id,\n function_id: functionId,\n config,\n })\n },\n registerFunction: (functionId, handler, config) => {\n const ref = this.registerFunction(functionId, handler)\n this.registerTrigger({\n type: triggerType.id,\n function_id: functionId,\n config,\n })\n return ref\n },\n unregister: () => {\n this.unregisterTriggerType(triggerType)\n },\n }\n }\n\n /**\n * Unregisters a previously registered trigger type.\n *\n * @param triggerType - The trigger type to unregister (must match the `id` used during registration).\n */\n unregisterTriggerType = (triggerType: Omit<RegisterTriggerTypeMessage, 'message_type'>): void => {\n this.sendMessage(MessageType.UnregisterTriggerType, triggerType, true)\n this.triggerTypes.delete(triggerType.id)\n }\n\n /**\n * Binds a trigger configuration to a registered function. When the trigger\n * fires, the engine invokes the target function.\n *\n * @param trigger - Trigger registration input.\n * @param trigger.type - Trigger type (e.g. `http`, `durable:subscriber`, `cron`).\n * @param trigger.function_id - ID of the function to invoke.\n * @param trigger.config - Trigger-specific configuration.\n * @returns A {@link Trigger} handle with an `unregister()` method.\n *\n * @example\n * ```typescript\n * const trigger = worker.registerTrigger({\n * type: 'http',\n * function_id: 'greet',\n * config: { api_path: '/greet', http_method: 'GET' },\n * })\n *\n * // Later...\n * trigger.unregister()\n * ```\n */\n registerTrigger = (trigger: Omit<RegisterTriggerMessage, 'message_type' | 'id'>): Trigger => {\n const id = randomUUID()\n const fullTrigger: RegisterTriggerMessage = {\n ...trigger,\n id,\n message_type: MessageType.RegisterTrigger,\n }\n this.sendMessage(MessageType.RegisterTrigger, fullTrigger, true)\n this.triggers.set(id, fullTrigger)\n\n return {\n unregister: () => {\n this.sendMessage(MessageType.UnregisterTrigger, {\n id,\n message_type: MessageType.UnregisterTrigger,\n type: fullTrigger.type,\n })\n this.triggers.delete(id)\n },\n }\n }\n\n /**\n * Registers a function with the engine. The `functionId` is the unique identifier\n * used by triggers and invocations.\n *\n * The handler runs locally in the browser session; HTTP invocation configs\n * are a Node.js SDK feature and are not accepted here.\n *\n * @param functionId - Unique function identifier.\n * @param handlerOrInvocation - Async handler executed when the function is invoked.\n * @param options - Optional function registration options (description, request/response formats, metadata).\n * @returns A {@link FunctionRef} with `id` and `unregister()`.\n *\n * @example\n * ```typescript\n * const fn = worker.registerFunction(\n * 'greet',\n * async (input: { name: string }) => {\n * return { message: `Hello, ${input.name}!` }\n * },\n * { description: 'Greets a user' },\n * )\n * ```\n */\n registerFunction = (\n functionId: string,\n handlerOrInvocation: RemoteFunctionHandler,\n options?: RegisterFunctionOptions,\n ): FunctionRef => {\n if (!functionId || functionId.trim() === '') {\n throw new Error('id is required')\n }\n if (this.functions.has(functionId)) {\n throw new Error(`function id already registered: ${functionId}`)\n }\n\n const fullMessage: RegisterFunctionMessage = {\n ...options,\n id: functionId,\n message_type: MessageType.RegisterFunction,\n }\n\n this.sendMessage(MessageType.RegisterFunction, fullMessage, true)\n\n const handler = handlerOrInvocation as RemoteFunctionHandler\n this.functions.set(functionId, {\n message: fullMessage,\n handler: async (input, _traceparent?: string, _baggage?: string) => {\n return await handler(input)\n },\n })\n\n return {\n id: functionId,\n unregister: () => {\n this.sendMessage(MessageType.UnregisterFunction, { id: functionId }, true)\n this.functions.delete(functionId)\n },\n }\n }\n\n /**\n * @internal Implementation backing the `createChannel` helper in the\n * `iii-browser-sdk/helpers` submodule. Not part of the public `ISdk` surface.\n *\n * Creates a streaming channel pair for worker-to-worker data transfer.\n * Returns a {@link Channel} with a local writer/reader and serializable refs\n * that can be passed as fields in invocation data to other functions.\n */\n __helpers_create_channel = async (bufferSize?: number): Promise<import('./types').Channel> => {\n const result = await this.trigger<{ buffer_size?: number }, { writer: StreamChannelRef; reader: StreamChannelRef }>(\n { function_id: 'engine::channels::create', payload: { buffer_size: bufferSize } },\n )\n\n return {\n writer: new ChannelWriter(this.address, result.writer),\n reader: new ChannelReader(this.address, result.reader),\n writerRef: result.writer,\n readerRef: result.reader,\n }\n }\n\n /**\n * Invokes a remote function. The routing behavior and return type depend\n * on the `action` field of the request.\n *\n * | `action` | Behavior | Return type |\n * |-------------------------------|----------------------------------------------------|----------------------- |\n * | _(none)_ | Synchronous: waits for the function to return | `Promise<TOutput>` |\n * | `TriggerAction.Enqueue(...)` | Async via named queue; engine acknowledges enqueue | `Promise<EnqueueResult>` |\n * | `TriggerAction.Void()` | Fire-and-forget, no response | `Promise<undefined>` |\n *\n * @param request - The trigger request.\n * @param request.function_id - ID of the function to invoke.\n * @param request.payload - Payload to pass to the function.\n * @param request.action - Routing action. Omit for synchronous request/response.\n * @param request.timeoutMs - Override the default invocation timeout.\n * @returns The result of the function invocation.\n *\n * @example\n * ```typescript\n * import { TriggerAction } from 'iii-browser-sdk'\n *\n * // Synchronous\n * const result = await worker.trigger({ function_id: 'get-order', payload: { id: '123' } })\n *\n * // Enqueue\n * const { messageReceiptId } = await worker.trigger({\n * function_id: 'payments::charge',\n * payload: { orderId: '123', amount: 49.99 },\n * action: TriggerAction.Enqueue({ queue: 'payment' }),\n * })\n *\n * // Fire-and-forget\n * worker.trigger({\n * function_id: 'notifications::send',\n * payload: { userId: '123' },\n * action: TriggerAction.Void(),\n * })\n * ```\n */\n // biome-ignore lint/suspicious/noExplicitAny: TOutput defaults to any so untyped calls type-check (the engine cannot express the return type statically)\n trigger = async <TInput = unknown, TOutput = any>(\n request: TriggerRequest<TInput>,\n ): Promise<TOutput> => {\n const { function_id, payload, action, timeoutMs, namespace } = request\n const effectiveTimeout = timeoutMs ?? this.invocationTimeoutMs\n\n if (action?.type === 'void') {\n this.sendMessage(MessageType.InvokeFunction, {\n function_id,\n data: payload,\n action,\n // Omit when absent so the engine routes within its default namespace.\n ...(namespace !== undefined ? { namespace } : {}),\n })\n return undefined as TOutput\n }\n\n const invocation_id = randomUUID()\n\n return new Promise<TOutput>((resolve, reject) => {\n const timeout = setTimeout(() => {\n const invocation = this.invocations.get(invocation_id)\n if (invocation) {\n this.invocations.delete(invocation_id)\n reject(new Error(`Invocation timeout after ${effectiveTimeout}ms: ${function_id}`))\n }\n }, effectiveTimeout)\n\n this.invocations.set(invocation_id, {\n resolve: (result: TOutput) => {\n clearTimeout(timeout)\n resolve(result)\n },\n reject: (error: unknown) => {\n clearTimeout(timeout)\n reject(error)\n },\n timeout,\n })\n\n this.sendMessage(MessageType.InvokeFunction, {\n invocation_id,\n function_id,\n data: payload,\n action,\n // Omit when absent so the engine routes within its default namespace.\n ...(namespace !== undefined ? { namespace } : {}),\n })\n })\n }\n\n /**\n * @internal Implementation backing the `createStream` helper in the\n * `iii-browser-sdk/helpers` submodule. Not part of the public `ISdk` surface.\n *\n * Registers a custom stream implementation, overriding the engine default\n * for the given stream name.\n */\n __helpers_create_stream = <TData>(streamName: string, stream: IStream<TData>): void => {\n this.registerFunction(`stream::get(${streamName})`, stream.get.bind(stream))\n this.registerFunction(`stream::set(${streamName})`, stream.set.bind(stream))\n this.registerFunction(`stream::delete(${streamName})`, stream.delete.bind(stream))\n this.registerFunction(`stream::list(${streamName})`, stream.list.bind(stream))\n this.registerFunction(`stream::list_groups(${streamName})`, stream.listGroups.bind(stream))\n }\n\n /**\n * Gracefully shutdown the SDK, cleaning up all resources.\n */\n shutdown = async (): Promise<void> => {\n this.isShuttingDown = true\n\n this.clearReconnectTimeout()\n\n for (const [_id, invocation] of this.invocations) {\n if (invocation.timeout) {\n clearTimeout(invocation.timeout)\n }\n invocation.reject(new Error('iii is shutting down'))\n }\n this.invocations.clear()\n\n if (this.ws) {\n this.ws.onopen = null\n this.ws.onclose = null\n this.ws.onerror = null\n this.ws.onmessage = null\n this.ws.close()\n this.ws = undefined\n }\n\n this.setConnectionState('disconnected')\n }\n\n /**\n * Subscribe to connection-state transitions. The handler is fired immediately\n * with the current state, then on every transition. Multiple listeners are\n * supported. Returns an unsubscribe function.\n */\n addConnectionStateListener = (handler: (state: IIIConnectionState) => void): (() => void) => {\n this.connectionListeners.add(handler)\n try {\n handler(this.connectionState)\n } catch (e) {\n console.error('[iii] connection listener threw on initial fire', e)\n }\n return () => {\n this.connectionListeners.delete(handler)\n }\n }\n\n // private methods\n\n private setConnectionState(state: IIIConnectionState): void {\n if (this.connectionState !== state) {\n this.connectionState = state\n for (const handler of this.connectionListeners) {\n try {\n handler(state)\n } catch (e) {\n console.error('[iii] connection listener threw', e)\n }\n }\n }\n }\n\n private connect(): void {\n if (this.isShuttingDown) {\n return\n }\n\n this.setConnectionState('connecting')\n this.ws = new WebSocket(this.address)\n this.ws.onopen = this.onSocketOpen.bind(this)\n this.ws.onclose = this.onSocketClose.bind(this)\n this.ws.onerror = this.onSocketError.bind(this)\n }\n\n private clearReconnectTimeout(): void {\n if (this.reconnectTimeout) {\n clearTimeout(this.reconnectTimeout)\n this.reconnectTimeout = undefined\n }\n }\n\n private scheduleReconnect(): void {\n if (this.isShuttingDown) {\n return\n }\n\n const { maxRetries, initialDelayMs, backoffMultiplier, maxDelayMs, jitterFactor } = this.reconnectionConfig\n\n if (maxRetries !== -1 && this.reconnectAttempt >= maxRetries) {\n this.setConnectionState('failed')\n console.error(`[iii] Max reconnection retries (${maxRetries}) reached, giving up`)\n return\n }\n\n if (this.reconnectTimeout) {\n return\n }\n\n const exponentialDelay = initialDelayMs * backoffMultiplier ** this.reconnectAttempt\n const cappedDelay = Math.min(exponentialDelay, maxDelayMs)\n const jitter = cappedDelay * jitterFactor * (2 * Math.random() - 1)\n const delay = Math.floor(cappedDelay + jitter)\n\n this.setConnectionState('reconnecting')\n console.debug(`[iii] Reconnecting in ${delay}ms (attempt ${this.reconnectAttempt + 1})...`)\n\n this.reconnectTimeout = setTimeout(() => {\n this.reconnectTimeout = undefined\n this.reconnectAttempt++\n this.connect()\n }, delay)\n }\n\n private onSocketError(): void {\n console.error('[iii] WebSocket error')\n }\n\n private onSocketClose(): void {\n if (this.ws) {\n this.ws.onopen = null\n this.ws.onclose = null\n this.ws.onerror = null\n this.ws.onmessage = null\n }\n this.ws = undefined\n\n // A fatal registration rejection (or shutdown) sets `isShuttingDown` and a\n // terminal state before closing the socket. Do not overwrite that state with\n // `disconnected`, and do not schedule a reconnect the engine would only\n // reject again. `scheduleReconnect` already no-ops while shutting down.\n if (this.isShuttingDown) {\n return\n }\n\n this.setConnectionState('disconnected')\n this.scheduleReconnect()\n }\n\n private onSocketOpen(): void {\n this.clearReconnectTimeout()\n this.reconnectAttempt = 0\n this.setConnectionState('connected')\n\n if (this.ws) {\n this.ws.onmessage = this.onMessage.bind(this)\n }\n\n // Reconnect: present the previous engine-assigned identity BEFORE the\n // metadata announce and registration replay so the engine retires the old\n // connection and the replay lands on a clean slate instead of racing its\n // cleanup. This must precede registerWorkerMetadata(): otherwise the old\n // connection still holds this (namespace, worker_name) and the announce\n // would trip WORKER_NAMESPACE_CONFLICT against ourselves. The token proves\n // we ARE that worker (ids alone are publicly listable).\n if (this.workerId) {\n this.sendMessageRaw(\n JSON.stringify({\n type: MessageType.Reattach,\n previous_worker_id: this.workerId,\n reattach_token: this.reattachToken,\n }),\n )\n }\n\n // Announce before registering anything. The engine buffers a connection's\n // registrations until it knows the connection's namespace, which it takes\n // from this call — or, failing that, only after a grace period. Registering\n // first would stall every function behind that grace.\n this.registerWorkerMetadata()\n\n\n this.triggerTypes.forEach(({ message }) => {\n this.sendMessage(MessageType.RegisterTriggerType, message, true)\n })\n this.functions.forEach(({ message }) => {\n this.sendMessage(MessageType.RegisterFunction, message, true)\n })\n this.triggers.forEach((trigger) => {\n this.sendMessage(MessageType.RegisterTrigger, trigger, true)\n })\n\n const pending = this.messagesToSend\n this.messagesToSend = []\n for (const message of pending) {\n if (\n message.type === MessageType.InvokeFunction &&\n typeof message.invocation_id === 'string' &&\n !this.invocations.has(message.invocation_id)\n ) {\n continue\n }\n this.sendMessageRaw(JSON.stringify(message))\n }\n }\n\n private isOpen(): boolean {\n return this.ws?.readyState === WebSocket.OPEN\n }\n\n private sendMessageRaw(data: string): void {\n if (this.ws && this.isOpen()) {\n try {\n this.ws.send(data)\n } catch (error) {\n console.error('[iii] Exception while sending message', error)\n }\n }\n }\n\n private toWireFormat(messageType: MessageType, message: Omit<IIIMessage, 'message_type'>): Record<string, unknown> {\n const { message_type: _, ...rest } = message as Record<string, unknown>\n if (messageType === MessageType.RegisterTrigger && 'type' in message) {\n const { type: triggerType, ...triggerRest } = message as RegisterTriggerMessage\n return { type: messageType, ...triggerRest, trigger_type: triggerType }\n }\n if (messageType === MessageType.UnregisterTrigger && 'type' in message) {\n const { type: triggerType, ...triggerRest } = message as RegisterTriggerMessage\n return { type: messageType, ...triggerRest, trigger_type: triggerType }\n }\n if (messageType === MessageType.TriggerRegistrationResult && 'type' in message) {\n const { type: triggerType, ...resultRest } = message as TriggerRegistrationResultMessage\n return { type: messageType, ...resultRest, trigger_type: triggerType }\n }\n return { type: messageType, ...rest } as Record<string, unknown>\n }\n\n /**\n * Tells the engine who this connection is. Sent on every open, before any\n * registration, so the engine can resolve this connection's namespace and\n * drain its buffered registrations immediately.\n */\n private registerWorkerMetadata(): void {\n this.sendMessage(MessageType.InvokeFunction, {\n function_id: EngineFunctions.REGISTER_WORKER,\n data: {\n runtime: 'browser',\n name: this.workerName,\n os: globalThis.navigator?.userAgent ?? 'browser',\n // Omit when absent so the engine falls back to its `default` namespace.\n ...(this.namespace !== undefined ? { namespace: this.namespace } : {}),\n },\n action: { type: 'void' },\n } as unknown as Omit<IIIMessage, 'message_type'>)\n }\n\n private sendMessage(messageType: MessageType, message: Omit<IIIMessage, 'message_type'>, skipIfClosed = false): void {\n const wireMessage = this.toWireFormat(messageType, message)\n if (this.isOpen()) {\n this.sendMessageRaw(JSON.stringify(wireMessage))\n } else if (!skipIfClosed) {\n this.messagesToSend.push(wireMessage)\n }\n }\n\n private onInvocationResult(invocation_id: string, result: unknown, error: unknown): void {\n const invocation = this.invocations.get(invocation_id)\n\n if (invocation) {\n if (invocation.timeout) {\n clearTimeout(invocation.timeout)\n }\n error ? invocation.reject(error) : invocation.resolve(result)\n }\n\n this.invocations.delete(invocation_id)\n }\n\n private resolveChannelValue(value: unknown): unknown {\n if (isChannelRef(value)) {\n return value.direction === 'read'\n ? new ChannelReader(this.address, value)\n : new ChannelWriter(this.address, value)\n }\n if (Array.isArray(value)) {\n return value.map((item) => this.resolveChannelValue(item))\n }\n if (value !== null && typeof value === 'object') {\n const out: Record<string, unknown> = {}\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n out[k] = this.resolveChannelValue(v)\n }\n return out\n }\n return value\n }\n\n private async onInvokeFunction<TInput>(\n invocation_id: string | undefined,\n function_id: string,\n input: TInput,\n traceparent?: string,\n baggage?: string,\n ): Promise<unknown> {\n const fn = this.functions.get(function_id)\n\n const resolvedInput = this.resolveChannelValue(input) as TInput\n\n if (fn?.handler) {\n if (!invocation_id) {\n try {\n await fn.handler(resolvedInput, traceparent, baggage)\n } catch (error) {\n console.error(`[iii] Error invoking function ${function_id}`, error)\n }\n return\n }\n\n try {\n const result = await fn.handler(resolvedInput, traceparent, baggage)\n this.sendMessage(MessageType.InvocationResult, {\n invocation_id,\n function_id,\n result,\n traceparent,\n baggage,\n })\n } catch (error) {\n const isError = error instanceof Error\n this.sendMessage(MessageType.InvocationResult, {\n invocation_id,\n function_id,\n error: {\n code: 'invocation_failed',\n message: isError ? error.message : String(error),\n stacktrace: isError ? error.stack : undefined,\n },\n traceparent,\n baggage,\n })\n }\n } else {\n const errorCode = fn ? 'function_not_invokable' : 'function_not_found'\n const errorMessage = fn ? 'Function is HTTP-invoked and cannot be invoked locally' : 'Function not found'\n if (invocation_id) {\n this.sendMessage(MessageType.InvocationResult, {\n invocation_id,\n function_id,\n error: { code: errorCode, message: errorMessage },\n traceparent,\n baggage,\n })\n }\n }\n }\n\n private async onRegisterTrigger(message: { trigger_type: string; id: string; function_id: string; config: unknown }) {\n const { trigger_type, id, function_id, config } = message\n const triggerTypeData = this.triggerTypes.get(trigger_type)\n\n if (triggerTypeData) {\n try {\n await triggerTypeData.handler.registerTrigger({ id, function_id, config })\n this.sendMessage(MessageType.TriggerRegistrationResult, {\n id,\n message_type: MessageType.TriggerRegistrationResult,\n type: trigger_type,\n function_id,\n })\n } catch (error) {\n this.sendMessage(MessageType.TriggerRegistrationResult, {\n id,\n message_type: MessageType.TriggerRegistrationResult,\n type: trigger_type,\n function_id,\n error: { code: 'trigger_registration_failed', message: (error as Error).message },\n })\n }\n } else {\n this.sendMessage(MessageType.TriggerRegistrationResult, {\n id,\n message_type: MessageType.TriggerRegistrationResult,\n type: trigger_type,\n function_id,\n error: { code: 'trigger_type_not_found', message: 'Trigger type not found' },\n })\n }\n }\n\n private async onUnregisterTrigger(message: {\n trigger_type?: string\n id: string\n function_id?: string\n config?: unknown\n }) {\n const trigger_type = message.trigger_type\n if (!trigger_type) return\n\n const triggerTypeData = this.triggerTypes.get(trigger_type)\n if (!triggerTypeData) return\n\n const { id, function_id = '', config } = message\n try {\n await triggerTypeData.handler.unregisterTrigger({ id, function_id, config })\n } catch (error) {\n console.error(`[iii] Error unregistering trigger ${id}`, error)\n }\n }\n\n private onMessage(event: MessageEvent): void {\n let msgType: MessageType\n let message: Record<string, unknown>\n\n try {\n const parsed = JSON.parse(typeof event.data === 'string' ? event.data : '') as Record<string, unknown>\n msgType = parsed.type as MessageType\n const { type: _, ...rest } = parsed\n message = rest\n } catch (error) {\n console.error('[iii] Failed to parse incoming message', error)\n return\n }\n\n if (msgType === MessageType.InvocationResult) {\n const { invocation_id, result, error } = message as InvocationResultMessage\n this.onInvocationResult(invocation_id, result, error)\n } else if (msgType === MessageType.InvokeFunction) {\n const { invocation_id, function_id, data, traceparent, baggage } = message as InvokeFunctionMessage\n this.onInvokeFunction(invocation_id, function_id, data, traceparent, baggage)\n } else if (msgType === MessageType.RegisterTrigger) {\n this.onRegisterTrigger(message as { trigger_type: string; id: string; function_id: string; config: unknown })\n } else if (msgType === MessageType.UnregisterTrigger) {\n this.onUnregisterTrigger(\n message as { trigger_type?: string; id: string; function_id?: string; config?: unknown },\n )\n } else if (msgType === MessageType.RegistrationRejected) {\n this.onRegistrationRejected(\n message as { code: string; namespace: string; worker_name: string; owner_worker_id: string },\n )\n } else if (msgType === MessageType.WorkerRegistered) {\n const { worker_id, reattach_token } = message as { worker_id: string; reattach_token?: string }\n this.workerId = worker_id\n this.reattachToken = reattach_token\n }\n }\n\n /**\n * The engine rejected a registration. A `FUNCTION_NAMESPACE_CONFLICT` costs\n * one function and leaves the connection open, so log and keep serving. A\n * `WORKER_NAMESPACE_CONFLICT` means another live worker owns this name in the\n * namespace: it is terminal — stop and do not reconnect (otherwise the engine\n * would only reject the same name again, which with `maxRetries: -1` loops\n * forever).\n */\n private onRegistrationRejected(init: {\n code: string\n namespace: string\n worker_name: string\n owner_worker_id: string\n }): void {\n if (init.code === 'FUNCTION_NAMESPACE_CONFLICT') {\n console.warn(\n `[iii] Function registration rejected: function \"${init.worker_name}\" in namespace \"${init.namespace}\" is already exported by worker ${init.owner_worker_id}. Staying connected and serving the rest.`,\n )\n return\n }\n\n console.error(\n `[iii] Registration rejected (${init.code}): worker \"${init.worker_name}\" in namespace \"${init.namespace}\" is already owned by ${init.owner_worker_id}. Not reconnecting.`,\n )\n // Terminal: suppress reconnect so neither onSocketClose nor scheduleReconnect\n // revives a connection the engine would only reject again.\n this.isShuttingDown = true\n this.clearReconnectTimeout()\n\n // Reject every in-flight invocation now rather than leaving them to time out.\n const error = new Error(\n `[iii] Registration rejected (${init.code}): worker \"${init.worker_name}\" in namespace \"${init.namespace}\" is already owned by ${init.owner_worker_id}.`,\n )\n for (const [, invocation] of this.invocations) {\n if (invocation.timeout) {\n clearTimeout(invocation.timeout)\n }\n invocation.reject(error)\n }\n this.invocations.clear()\n\n // Drop the socket. onSocketClose sees `isShuttingDown` and leaves the\n // terminal `failed` state in place instead of overwriting it.\n this.setConnectionState('failed')\n this.ws?.close()\n }\n}\n\n/**\n * Factory object that constructs routing actions for {@link ISdk.trigger}.\n *\n * @example\n * ```typescript\n * import { TriggerAction } from 'iii-browser-sdk'\n *\n * // Enqueue to a named queue\n * worker.trigger({\n * function_id: 'process',\n * payload: { data: 'hello' },\n * action: TriggerAction.Enqueue({ queue: 'jobs' }),\n * })\n *\n * // Fire-and-forget\n * worker.trigger({\n * function_id: 'notify',\n * payload: {},\n * action: TriggerAction.Void(),\n * })\n * ```\n */\nexport const TriggerAction = {\n /**\n * Routes the invocation through a named queue. The engine enqueues the job,\n * acknowledges the caller with `{ messageReceiptId }`, and processes it\n * asynchronously.\n *\n * @param opts - Queue routing options.\n * @param opts.queue - Name of the target queue.\n */\n Enqueue: (opts: { queue: string }) => ({ type: 'enqueue' as const, ...opts }),\n /**\n * Fire-and-forget routing. The engine forwards the invocation without\n * waiting for a response or queuing the job.\n */\n Void: () => ({ type: 'void' as const }),\n} as const\n\n/**\n * Register the worker with a iii instance, returns a connected worker client.\n * The WebSocket connection is established automatically.\n *\n * @param address - WebSocket URL of the III engine (e.g. `ws://localhost:49135`).\n * @param options - Optional {@link InitOptions} for worker name, timeouts, and reconnection.\n * @returns A connected {@link ISdk} instance.\n *\n * @example\n * ```typescript\n * import { registerWorker } from 'iii-browser-sdk'\n *\n * const worker = registerWorker('ws://localhost:49135')\n * ```\n */\nexport const registerWorker = (address: string, options?: InitOptions): ISdk => new Sdk(address, options)\n"],"mappings":";;;;;;;;;;;;;;;AAaA,MAAa,kBAAkB;CAC7B,gBAAgB;CAChB,gBAAgB;CAChB,cAAc;CACd,cAAc;CACd,eAAe;CACf,eAAe;CACf,0BAA0B;CAC1B,0BAA0B;CAC1B,iBAAiB;CAClB;;AAGD,MAAa,iBAAiB,EAC5B,qBAAqB,+BACtB;;AAoBD,MAAa,qCAA4D;CACvE,gBAAgB;CAChB,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;;;;CAYzB,AAAQ,uBAAuB,MAKtB;AACP,MAAI,KAAK,SAAS,+BAA+B;AAC/C,WAAQ,KACN,mDAAmD,KAAK,YAAY,kBAAkB,KAAK,UAAU,kCAAkC,KAAK,gBAAgB,2CAC7J;AACD;;AAGF,UAAQ,MACN,gCAAgC,KAAK,KAAK,aAAa,KAAK,YAAY,kBAAkB,KAAK,UAAU,wBAAwB,KAAK,gBAAgB,qBACvJ;AAGD,OAAK,iBAAiB;AACtB,OAAK,uBAAuB;EAG5B,MAAM,wBAAQ,IAAI,MAChB,gCAAgC,KAAK,KAAK,aAAa,KAAK,YAAY,kBAAkB,KAAK,UAAU,wBAAwB,KAAK,gBAAgB,GACvJ;AACD,OAAK,MAAM,GAAG,eAAe,KAAK,aAAa;AAC7C,OAAI,WAAW,QACb,cAAa,WAAW,QAAQ;AAElC,cAAW,OAAO,MAAM;;AAE1B,OAAK,YAAY,OAAO;AAIxB,OAAK,mBAAmB,SAAS;AACjC,OAAK,IAAI,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;AA0BpB,MAAa,gBAAgB;CAS3B,UAAU,UAA6B;EAAE,MAAM;EAAoB,GAAG;EAAM;CAK5E,aAAa,EAAE,MAAM,QAAiB;CACvC;;;;;;;;;;;;;;;;AAiBD,MAAa,kBAAkB,SAAiB,YAAgC,IAAI,IAAI,SAAS,QAAQ"}
@@ -9,6 +9,7 @@ declare enum MessageType {
9
9
  UnregisterTrigger = "unregistertrigger",
10
10
  UnregisterTriggerType = "unregistertriggertype",
11
11
  TriggerRegistrationResult = "triggerregistrationresult",
12
+ RegistrationRejected = "registrationrejected",
12
13
  WorkerRegistered = "workerregistered",
13
14
  Reattach = "reattach"
14
15
  }
@@ -118,6 +119,11 @@ type MiddlewareFunctionInput = {
118
119
  payload: Record<string, unknown>; /** Routing action, if any. */
119
120
  action?: TriggerAction; /** Auth context returned by the auth function for this session. */
120
121
  context: Record<string, unknown>;
122
+ /**
123
+ * Target namespace the invoke addressed; forward the call here to stay in the
124
+ * caller's namespace. Absent → the engine's default namespace.
125
+ */
126
+ namespace?: string;
121
127
  };
122
128
  /**
123
129
  * Input passed to the `on_trigger_type_registration_function_id` hook
@@ -200,7 +206,8 @@ type TriggerRequest<TInput = unknown> = {
200
206
  /** ID of the function to invoke. */function_id: string; /** Input data passed to the function. */
201
207
  payload: TInput; /** Sets how the trigger is routed. Omit for a synchronous request/response. Specify for a specific routing scheme (e.g. `TriggerAction.Enqueue()`, `TriggerAction.Void()`). */
202
208
  action?: TriggerAction; /** Override the default invocation timeout, in milliseconds. */
203
- timeoutMs?: number;
209
+ timeoutMs?: number; /** Namespace to route this invocation to. Omit to use the engine's default namespace. */
210
+ namespace?: string;
204
211
  };
205
212
  /**
206
213
  * Serializable reference to one end of a streaming channel. Can be included
@@ -649,4 +656,4 @@ type ApiResponse<TStatus extends number = number, TBody = string | Record<string
649
656
  };
650
657
  //#endregion
651
658
  export { OnTriggerRegistrationInput as A, AuthInput as C, MiddlewareFunctionInput as D, MessageType as E, RegisterFunctionMessage as F, RegisterTriggerMessage as I, RegisterTriggerTypeMessage as L, OnTriggerTypeRegistrationInput as M, OnTriggerTypeRegistrationResult as N, OnFunctionRegistrationInput as O, RegisterFunctionFormat as P, StreamChannelRef as R, ChannelWriter as S, EnqueueResult as T, IIIConnectionState as _, ISdk as a, ChannelItem as b, RegisterTriggerInput as c, Trigger as d, TriggerTypeRef as f, EngineTriggers as g, EngineFunctions as h, FunctionRef as i, OnTriggerRegistrationResult as j, OnFunctionRegistrationResult as k, RegisterTriggerTypeInput as l, TriggerHandler as m, ApiResponse as n, RegisterFunctionInput as o, TriggerConfig as p, Channel as r, RegisterFunctionOptions as s, ApiRequest as t, RemoteFunctionHandler as u, IIIReconnectionConfig as v, AuthResult as w, ChannelReader as x, ChannelDirection as y, TriggerRequest as z };
652
- //# sourceMappingURL=types-Dj_5C0O1.d.cts.map
659
+ //# sourceMappingURL=types-Ui5yAF2Q.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-Ui5yAF2Q.d.mts","names":[],"sources":["../src/iii-types.ts","../src/channels.ts","../src/iii-constants.ts","../src/triggers.ts","../src/types.ts"],"mappings":";aAAY,WAAA;EACV,gBAAA;EACA,kBAAA;EACA,cAAA;EACA,gBAAA;EACA,mBAAA;EACA,eAAA;EACA,iBAAA;EACA,qBAAA;EACA,yBAAA;EACA,oBAAA;EACA,gBAAA;EACA,QAAA;AAAA;AAAA,KAGU,0BAAA;EACV,YAAA,EAAc,WAAA,CAAY,mBAAA,EAJ1B;EAMA,EAAA,UANQ;EAQR,WAAA;AAAA;AAAA,KAuBU,sBAAA;EAQV,gEANA,YAAA,EAAc,WAAA,CAAY,eAAA,EAQpB;EANN,EAAA,UASU;EAPV,IAAA;EAEA,WAAA,UASA;EAPA,MAAA;AAAA;AAAA,KAGU,sBAAA;EAgBG;;;EAZb,IAAA;EAqBY;;AAGd;EApBE,WAAA;;;;EAIA,IAAA;EAkCW;;;EA9BX,UAAA,GAAa,MAAA;EAaC;;;EATd,KAAA;EAqBA;;;EAjBA,QAAA;EAAA,CACC,GAAA;AAAA;AAAA,KAGS,uBAAA;EACV,YAAA,EAAc,WAAA,CAAY,gBAAA;EA2BhB;;;EAvBV,EAAA;EAuB4B;;;EAnB5B,WAAA;EAmBqE;AAOvE;;EAtBE,cAAA,GAAiB,sBAAA;EA0BG;;;EAtBpB,eAAA,GAAkB,sBAAA;EAClB,QAAA,GAAW,MAAA;AAAA;;;AA+Bb;;;;;KArBY,aAAA;EAAkB,IAAA;EAAiB,KAAA;AAAA;EAAoB,IAAA;AAAA;;;;AA2CnE;;KApCY,SAAA;EAwCD,uDAtCT,OAAA,EAAS,MAAA,kBA0CA;EAxCT,YAAA,EAAc,MAAA,oBAwCC;EAtCf,UAAA;AAAA;;;;;;KAQU,UAAA;EAmCD,0GAjCT,iBAAA,aA0CU;EAxCV,mBAAA;EAEA,qBAAA,aAwCA;EAtCA,+BAAA,YA0CA;EAxCA,2BAAA,YAwCe;EAt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A;AAAA;;AJ8CF;;;KIvCY,WAAA;EJyCM,sCIvChB,EAAA,UJ+CwB;EI7CxB,UAAA;AAAA;;;;;;;;;;;AJyHF;;;;;;;;;;;;AC1VA;;;;;AAIA;KG4PY,cAAA;qCAEV,EAAA;EH9PoF;AAQtF;;;;;;EG8PE,eAAA,CAAgB,UAAA,UAAoB,MAAA,EAAQ,OAAA,GAAU,OAAA;EH5PlC;;;;AAEtB;;;;EGmQE,gBAAA,CAAiB,UAAA,UAAoB,OAAA,EAAS,qBAAA,EAAuB,MAAA,EAAQ,OAAA,GAAU,WAAA;EH7P5D;;;EGiQ3B,UAAA;AAAA;;;;;KAOU,OAAA;EHxQ4B,iCG0QtC,MAAA,EAAQ,aAAA,EHxPG;EG0PX,MAAA,EAAQ,aAAA;EAER,SAAA,EAAW,gBAAA,EH3Pa;EG6PxB,SAAA,EAAW,gBAAA;AAAA;;;;;;KAQD,UAAA;EACV,WAAA,EAAa,MAAA;EACb,YAAA,EAAc,MAAA;EACd,IAAA,EAAM,KAAA;EACN,OAAA,EAAS,MAAA;EACT,MAAA;AAAA;;;;;AH3JF;;;;;;;;;;;KG6KY,WAAA,mDAA8D,MAAA;EHzKvD,wBG2KjB,WAAA,EAAa,OAAA;EAEb,OAAA,GAAU,MAAA,kBH1K6B;EG4KvC,IAAA,GAAO,KAAA;AAAA"}
@@ -9,6 +9,7 @@ declare enum MessageType {
9
9
  UnregisterTrigger = "unregistertrigger",
10
10
  UnregisterTriggerType = "unregistertriggertype",
11
11
  TriggerRegistrationResult = "triggerregistrationresult",
12
+ RegistrationRejected = "registrationrejected",
12
13
  WorkerRegistered = "workerregistered",
13
14
  Reattach = "reattach"
14
15
  }
@@ -118,6 +119,11 @@ type MiddlewareFunctionInput = {
118
119
  payload: Record<string, unknown>; /** Routing action, if any. */
119
120
  action?: TriggerAction; /** Auth context returned by the auth function for this session. */
120
121
  context: Record<string, unknown>;
122
+ /**
123
+ * Target namespace the invoke addressed; forward the call here to stay in the
124
+ * caller's namespace. Absent → the engine's default namespace.
125
+ */
126
+ namespace?: string;
121
127
  };
122
128
  /**
123
129
  * Input passed to the `on_trigger_type_registration_function_id` hook
@@ -200,7 +206,8 @@ type TriggerRequest<TInput = unknown> = {
200
206
  /** ID of the function to invoke. */function_id: string; /** Input data passed to the function. */
201
207
  payload: TInput; /** Sets how the trigger is routed. Omit for a synchronous request/response. Specify for a specific routing scheme (e.g. `TriggerAction.Enqueue()`, `TriggerAction.Void()`). */
202
208
  action?: TriggerAction; /** Override the default invocation timeout, in milliseconds. */
203
- timeoutMs?: number;
209
+ timeoutMs?: number; /** Namespace to route this invocation to. Omit to use the engine's default namespace. */
210
+ namespace?: string;
204
211
  };
205
212
  /**
206
213
  * Serializable reference to one end of a streaming channel. Can be included
@@ -649,4 +656,4 @@ type ApiResponse<TStatus extends number = number, TBody = string | Record<string
649
656
  };
650
657
  //#endregion
651
658
  export { OnTriggerRegistrationInput as A, AuthInput as C, MiddlewareFunctionInput as D, MessageType as E, RegisterFunctionMessage as F, RegisterTriggerMessage as I, RegisterTriggerTypeMessage as L, OnTriggerTypeRegistrationInput as M, OnTriggerTypeRegistrationResult as N, OnFunctionRegistrationInput as O, RegisterFunctionFormat as P, StreamChannelRef as R, ChannelWriter as S, EnqueueResult as T, IIIConnectionState as _, ISdk as a, ChannelItem as b, RegisterTriggerInput as c, Trigger as d, TriggerTypeRef as f, EngineTriggers as g, EngineFunctions as h, FunctionRef as i, OnTriggerRegistrationResult as j, OnFunctionRegistrationResult as k, RegisterTriggerTypeInput as l, TriggerHandler as m, ApiResponse as n, RegisterFunctionInput as o, TriggerConfig as p, Channel as r, RegisterFunctionOptions as s, ApiRequest as t, RemoteFunctionHandler as u, IIIReconnectionConfig as v, AuthResult as w, ChannelReader as x, ChannelDirection as y, TriggerRequest as z };
652
- //# sourceMappingURL=types-DzJ2vn5G.d.mts.map
659
+ //# sourceMappingURL=types-dr4ELKgv.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-d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F;;;KIvCY,WAAA;EJyCM,sCIvChB,EAAA,UJ+CwB;EI7CxB,UAAA;AAAA;;;;;;;;;;;AJyHF;;;;;;;;;;;;AC1VA;;;;;AAIA;KG4PY,cAAA;qCAEV,EAAA;EH9PoF;AAQtF;;;;;;EG8PE,eAAA,CAAgB,UAAA,UAAoB,MAAA,EAAQ,OAAA,GAAU,OAAA;EH5PlC;;;;AAEtB;;;;EGmQE,gBAAA,CAAiB,UAAA,UAAoB,OAAA,EAAS,qBAAA,EAAuB,MAAA,EAAQ,OAAA,GAAU,WAAA;EH7P5D;;;EGiQ3B,UAAA;AAAA;;;;;KAOU,OAAA;EHxQ4B,iCG0QtC,MAAA,EAAQ,aAAA,EHxPG;EG0PX,MAAA,EAAQ,aAAA;EAER,SAAA,EAAW,gBAAA,EH3Pa;EG6PxB,SAAA,EAAW,gBAAA;AAAA;;;;;;KAQD,UAAA;EACV,WAAA,EAAa,MAAA;EACb,YAAA,EAAc,MAAA;EACd,IAAA,EAAM,KAAA;EACN,OAAA,EAAS,MAAA;EACT,MAAA;AAAA;;;;;AH3JF;;;;;;;;;;;KG6KY,WAAA,mDAA8D,MAAA;EHzKvD,wBG2KjB,WAAA,EAAa,OAAA;EAEb,OAAA,GAAU,MAAA,kBH1K6B;EG4KvC,IAAA,GAAO,KAAA;AAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iii-browser-sdk",
3
- "version": "0.21.8",
3
+ "version": "0.22.0-alpha.1",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-Dj_5C0O1.d.cts","names":[],"sources":["../src/iii-types.ts","../src/channels.ts","../src/iii-constants.ts","../src/triggers.ts","../src/types.ts"],"mappings":";aAAY,WAAA;EACV,gBAAA;EACA,kBAAA;EACA,cAAA;EACA,gBAAA;EACA,mBAAA;EACA,eAAA;EACA,iBAAA;EACA,qBAAA;EACA,yBAAA;EACA,gBAAA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A,UAAoB,OAAA,EAAS,qBAAA,EAAuB,MAAA,EAAQ,OAAA,GAAU,WAAA;;;;EAIvF,UAAA;AAAA;;;;;KAOU,OAAA;EHtPc,iCGwPxB,MAAA,EAAQ,aAAA,EHvMmB;EGyM3B,MAAA,EAAQ,aAAA,EHxPA;EG0PR,SAAA,EAAW,gBAAA,EHxPM;EG0PjB,SAAA,EAAW,gBAAA;AAAA;;;;;;KAQD,UAAA;EACV,WAAA,EAAa,MAAA;EACb,YAAA,EAAc,MAAA;EACd,IAAA,EAAM,KAAA;EACN,OAAA,EAAS,MAAA;EACT,MAAA;AAAA;;AH3JF;;;;;;;;;;;;;;KG6KY,WAAA,mDAA8D,MAAA;EHtK5D,wBGwKZ,WAAA,EAAa,OAAA,EHxKqB;EG0KlC,OAAA,GAAU,MAAA,kBHxIV;EG0IA,IAAA,GAAO,KAAA;AAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-DzJ2vn5G.d.mts","names":[],"sources":["../src/iii-types.ts","../src/channels.ts","../src/iii-constants.ts","../src/triggers.ts","../src/types.ts"],"mappings":";aAAY,WAAA;EACV,gBAAA;EACA,kBAAA;EACA,cAAA;EACA,gBAAA;EACA,mBAAA;EACA,eAAA;EACA,iBAAA;EACA,qBAAA;EACA,yBAAA;EACA,gBAAA;EACA,QAAA;AAAA;AAAA,KAGU,0BAAA;EACV,YAAA,EAAc,WAAA,CAAY,mBAAA,EAJ1B;EAMA,EAAA,UANQ;EAQR,WAAA;AAAA;AAAA,KAuBU,sBAAA;EAQV,gEANA,YAAA,EAAc,WAAA,CAAY,eAAA,EAQpB;EANN,EAAA,UASU;EAPV,IAAA;EAEA,WAAA,UASA;EAPA,MAAA;AAAA;AAAA,KAGU,sBAAA;EAgBG;;;EAZb,IAAA;EAqBY;;AAGd;EApBE,WAAA;;;;EAIA,IAAA;EAkCW;;;EA9BX,UAAA,GAAa,MAAA;EAaC;;;EATd,KAAA;EAqBA;;;EAjBA,QAAA;EAAA,CACC,GAAA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