iii-sdk 0.1.0 → 0.2.0

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.
package/README.md CHANGED
@@ -21,7 +21,7 @@ iii.registerFunction({ id: 'myFunction' }, (req) => {
21
21
  })
22
22
 
23
23
  iii.registerTrigger({
24
- trigger_type: 'api',
24
+ type: 'http',
25
25
  function_id: 'myFunction',
26
26
  config: { api_path: 'myApiPath', http_method: 'POST' },
27
27
  })
@@ -44,7 +44,7 @@ III Allows you to register triggers that can be invoked by other services.
44
44
 
45
45
  ```javascript
46
46
  iii.registerTrigger({
47
- trigger_type: 'api',
47
+ type: 'http',
48
48
  function_id: 'myFunction',
49
49
  config: { api_path: 'myApiPath', http_method: 'POST' },
50
50
  })
@@ -9,9 +9,9 @@ import { Instrumentation } from "@opentelemetry/instrumentation";
9
9
  */
10
10
  /** Engine function paths for internal operations */
11
11
  declare const EngineFunctions: {
12
- readonly LIST_FUNCTIONS: "engine.functions.list";
13
- readonly LIST_WORKERS: "engine.workers.list";
14
- readonly REGISTER_WORKER: "engine.workers.register";
12
+ readonly LIST_FUNCTIONS: "engine::functions::list";
13
+ readonly LIST_WORKERS: "engine::workers::list";
14
+ readonly REGISTER_WORKER: "engine::workers::register";
15
15
  };
16
16
  /** Engine trigger types */
17
17
  declare const EngineTriggers: {
@@ -20,10 +20,10 @@ declare const EngineTriggers: {
20
20
  };
21
21
  /** Log function paths */
22
22
  declare const LogFunctions: {
23
- readonly INFO: "log.info";
24
- readonly WARN: "log.warn";
25
- readonly ERROR: "log.error";
26
- readonly DEBUG: "log.debug";
23
+ readonly INFO: "engine::log::info";
24
+ readonly WARN: "engine::log::warn";
25
+ readonly ERROR: "engine::log::error";
26
+ readonly DEBUG: "engine::log::debug";
27
27
  };
28
28
  /** Connection state for the III WebSocket */
29
29
  type IIIConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'failed';
@@ -61,7 +61,7 @@ interface ReconnectionConfig {
61
61
  }
62
62
  /** Configuration for OpenTelemetry initialization. */
63
63
  interface OtelConfig {
64
- /** Whether OpenTelemetry export is enabled. Defaults to OTEL_ENABLED env var. */
64
+ /** Whether OpenTelemetry export is enabled. Defaults to true. Set to false or OTEL_ENABLED=false/0/no/off to disable. */
65
65
  enabled?: boolean;
66
66
  /** The service name to report. Defaults to OTEL_SERVICE_NAME or "iii-node". */
67
67
  serviceName?: string;
@@ -75,7 +75,7 @@ interface OtelConfig {
75
75
  engineWsUrl?: string;
76
76
  /** OpenTelemetry instrumentations to register (e.g., PrismaInstrumentation). */
77
77
  instrumentations?: Instrumentation[];
78
- /** Whether OpenTelemetry metrics export is enabled. Defaults to OTEL_METRICS_ENABLED env var. */
78
+ /** Whether OpenTelemetry metrics export is enabled. Defaults to true. Set to false or OTEL_METRICS_ENABLED=false/0/no/off to disable. */
79
79
  metricsEnabled?: boolean;
80
80
  /** Metrics export interval in milliseconds. Defaults to 60000 (60 seconds). */
81
81
  metricsExportIntervalMs?: number;
@@ -174,24 +174,16 @@ declare enum MessageType {
174
174
  WorkerRegistered = "workerregistered",
175
175
  }
176
176
  type RegisterTriggerTypeMessage = {
177
- type: MessageType.RegisterTriggerType;
177
+ message_type: MessageType.RegisterTriggerType;
178
178
  id: string;
179
179
  description: string;
180
180
  };
181
181
  type RegisterTriggerMessage = {
182
- type: MessageType.RegisterTrigger;
182
+ message_type: MessageType.RegisterTrigger;
183
183
  id: string;
184
- /**
185
- * The type of trigger. Can be 'cron', 'event', 'http', etc.
186
- */
187
- trigger_type: string;
188
- /**
189
- * Engine path for the function, including the service and function name
190
- * Example: software.engineering.code.rust
191
- * Where software, engineering, and code are the service ids
192
- */
184
+ type: string;
193
185
  function_id: string;
194
- config: any;
186
+ config: unknown;
195
187
  };
196
188
  type RegisterFunctionFormat = {
197
189
  name: string;
@@ -217,7 +209,7 @@ type RegisterFunctionFormat = {
217
209
  required?: boolean;
218
210
  };
219
211
  type RegisterFunctionMessage = {
220
- type: MessageType.RegisterFunction;
212
+ message_type: MessageType.RegisterFunction;
221
213
  /**
222
214
  * The path of the function
223
215
  */
@@ -307,9 +299,9 @@ type LogConfig = {
307
299
  };
308
300
  /** Callback type for log events */
309
301
  type LogCallback = (log: OtelLogEvent) => void;
310
- type RegisterTriggerInput = Omit<RegisterTriggerMessage, 'type' | 'id'>;
311
- type RegisterFunctionInput = Omit<RegisterFunctionMessage, 'type'>;
312
- type RegisterTriggerTypeInput = Omit<RegisterTriggerTypeMessage, 'type'>;
302
+ type RegisterTriggerInput = Omit<RegisterTriggerMessage, 'message_type' | 'id'>;
303
+ type RegisterFunctionInput = Omit<RegisterFunctionMessage, 'message_type'>;
304
+ type RegisterTriggerTypeInput = Omit<RegisterTriggerTypeMessage, 'message_type'>;
313
305
  type FunctionsAvailableCallback = (functions: FunctionInfo[]) => void;
314
306
  interface ISdk {
315
307
  /**
@@ -377,6 +369,10 @@ interface ISdk {
377
369
  * @returns A function to unregister the callback
378
370
  */
379
371
  onLog(callback: LogCallback, config?: LogConfig): () => void;
372
+ /**
373
+ * Gracefully shutdown the iii, cleaning up all resources.
374
+ */
375
+ shutdown(): Promise<void>;
380
376
  }
381
377
  type Trigger = {
382
378
  unregister(): void;
@@ -408,11 +404,12 @@ type InitOptions = {
408
404
  invocationTimeoutMs?: number;
409
405
  /** Configuration for WebSocket reconnection behavior */
410
406
  reconnectionConfig?: Partial<IIIReconnectionConfig>;
411
- /** OpenTelemetry configuration. If provided, OTEL will be initialized automatically.
407
+ /** OpenTelemetry configuration. OTel is initialized automatically by default.
408
+ * Set `{ enabled: false }` or env `OTEL_ENABLED=false/0/no/off` to disable.
412
409
  * The engineWsUrl is set automatically from the III address. */
413
410
  otel?: Omit<OtelConfig, 'engineWsUrl'>;
414
411
  };
415
412
  declare const init: (address: string, options?: InitOptions) => ISdk;
416
413
  //#endregion
417
414
  export { extractTraceparent as A, EngineFunctions as B, initOtel as C, currentTraceId as D, currentSpanId as E, removeBaggageEntry as F, IIIConnectionState as H, setBaggageEntry as I, OtelConfig as L, getBaggageEntry as M, injectBaggage as N, extractBaggage as O, injectTraceparent as P, DEFAULT_BRIDGE_RECONNECTION_CONFIG as R, getTracer as S, withSpan as T, IIIReconnectionConfig as U, EngineTriggers as V, LogFunctions as W, SeverityNumber$1 as _, ApiResponse as a, getLogger as b, LogCallback as c, OtelLogEvent as d, FunctionInfo as f, Meter$1 as g, Logger as h, ApiRequest as i, getAllBaggage as j, extractContext as k, LogConfig as l, WorkerStatus as m, InitOptions as n, FunctionsAvailableCallback as o, WorkerInfo as p, init as r, ISdk as s, ConnectionStateCallback as t, LogSeverityLevel as u, Span$1 as v, shutdownOtel as w, getMeter as x, SpanStatusCode as y, DEFAULT_INVOCATION_TIMEOUT_MS as z };
418
- //# sourceMappingURL=iii-DhZKdyS8.d.mts.map
415
+ //# sourceMappingURL=iii-7FpY7bi9.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iii-7FpY7bi9.d.mts","names":[],"sources":["../src/iii-constants.ts","../src/telemetry-system/types.ts","../src/telemetry-system/context.ts","../src/telemetry-system/index.ts","../src/iii-types.ts","../src/triggers.ts","../src/types.ts","../src/iii.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;cAKa;;EAAA,SAAA,YAIH,EAAA,uBAAA;EAGG,SAAA,eAGH,EAAA,2BAAA;AAGV,CAAA;AAQA;AAQiB,cAtBJ,cAsByB,EAAA;EAczB,SAAA,mBAAA,EAAA,6BAAoC;EASpC,SAAA,GAAA,EAAA,KAAA;;;cAvCA;ECOI,SAAA,IAAA,EAAA,mBAAkB;EAuBlB,SAAA,IAAU,EAAA,mBAAA;EAcN,SAAA,KAAA,EAAA,oBAAA;EAMU,SAAA,KAAA,EAAA,oBAAA;CAAR;;KD1CX,kBAAA;;UAQK,qBAAA;EEzBD;EAcA,cAAA,EAAa,MAAA;EAcb;EASA,UAAA,EAAA,MAAA;EAQA;EASA,iBAAc,EAAA,MAAA;EAQd;EAcA,YAAA,EAAA,MAAe;E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,uBAAA,WAAkC;KAElC,WAAA;EPvEC,UAAA,CAAA,EAAA,MAIH;EAGG,sBAGH,CAAA,EAAA,OAAA;EAGG;EAQD,mBAAA,CAAA,EAAkB,MAAA;EAQb;EAcJ,kBAAA,CAAA,EOkCU,OPlCV,COkCkB,qBPlCkB,CAAA;EASpC;;;SO6BJ,KAAK;AN7Dd,CAAA;AAuBiB,cMuvBJ,INvvBc,EAAA,CAAA,OAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EMuvBqB,WNvvBrB,EAAA,GMuvBmC,INvvBnC"}
@@ -9,9 +9,9 @@ import { Instrumentation } from "@opentelemetry/instrumentation";
9
9
  */
10
10
  /** Engine function paths for internal operations */
11
11
  declare const EngineFunctions: {
12
- readonly LIST_FUNCTIONS: "engine.functions.list";
13
- readonly LIST_WORKERS: "engine.workers.list";
14
- readonly REGISTER_WORKER: "engine.workers.register";
12
+ readonly LIST_FUNCTIONS: "engine::functions::list";
13
+ readonly LIST_WORKERS: "engine::workers::list";
14
+ readonly REGISTER_WORKER: "engine::workers::register";
15
15
  };
16
16
  /** Engine trigger types */
17
17
  declare const EngineTriggers: {
@@ -20,10 +20,10 @@ declare const EngineTriggers: {
20
20
  };
21
21
  /** Log function paths */
22
22
  declare const LogFunctions: {
23
- readonly INFO: "log.info";
24
- readonly WARN: "log.warn";
25
- readonly ERROR: "log.error";
26
- readonly DEBUG: "log.debug";
23
+ readonly INFO: "engine::log::info";
24
+ readonly WARN: "engine::log::warn";
25
+ readonly ERROR: "engine::log::error";
26
+ readonly DEBUG: "engine::log::debug";
27
27
  };
28
28
  /** Connection state for the III WebSocket */
29
29
  type IIIConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting' | 'failed';
@@ -61,7 +61,7 @@ interface ReconnectionConfig {
61
61
  }
62
62
  /** Configuration for OpenTelemetry initialization. */
63
63
  interface OtelConfig {
64
- /** Whether OpenTelemetry export is enabled. Defaults to OTEL_ENABLED env var. */
64
+ /** Whether OpenTelemetry export is enabled. Defaults to true. Set to false or OTEL_ENABLED=false/0/no/off to disable. */
65
65
  enabled?: boolean;
66
66
  /** The service name to report. Defaults to OTEL_SERVICE_NAME or "iii-node". */
67
67
  serviceName?: string;
@@ -75,7 +75,7 @@ interface OtelConfig {
75
75
  engineWsUrl?: string;
76
76
  /** OpenTelemetry instrumentations to register (e.g., PrismaInstrumentation). */
77
77
  instrumentations?: Instrumentation[];
78
- /** Whether OpenTelemetry metrics export is enabled. Defaults to OTEL_METRICS_ENABLED env var. */
78
+ /** Whether OpenTelemetry metrics export is enabled. Defaults to true. Set to false or OTEL_METRICS_ENABLED=false/0/no/off to disable. */
79
79
  metricsEnabled?: boolean;
80
80
  /** Metrics export interval in milliseconds. Defaults to 60000 (60 seconds). */
81
81
  metricsExportIntervalMs?: number;
@@ -174,24 +174,16 @@ declare enum MessageType {
174
174
  WorkerRegistered = "workerregistered",
175
175
  }
176
176
  type RegisterTriggerTypeMessage = {
177
- type: MessageType.RegisterTriggerType;
177
+ message_type: MessageType.RegisterTriggerType;
178
178
  id: string;
179
179
  description: string;
180
180
  };
181
181
  type RegisterTriggerMessage = {
182
- type: MessageType.RegisterTrigger;
182
+ message_type: MessageType.RegisterTrigger;
183
183
  id: string;
184
- /**
185
- * The type of trigger. Can be 'cron', 'event', 'http', etc.
186
- */
187
- trigger_type: string;
188
- /**
189
- * Engine path for the function, including the service and function name
190
- * Example: software.engineering.code.rust
191
- * Where software, engineering, and code are the service ids
192
- */
184
+ type: string;
193
185
  function_id: string;
194
- config: any;
186
+ config: unknown;
195
187
  };
196
188
  type RegisterFunctionFormat = {
197
189
  name: string;
@@ -217,7 +209,7 @@ type RegisterFunctionFormat = {
217
209
  required?: boolean;
218
210
  };
219
211
  type RegisterFunctionMessage = {
220
- type: MessageType.RegisterFunction;
212
+ message_type: MessageType.RegisterFunction;
221
213
  /**
222
214
  * The path of the function
223
215
  */
@@ -307,9 +299,9 @@ type LogConfig = {
307
299
  };
308
300
  /** Callback type for log events */
309
301
  type LogCallback = (log: OtelLogEvent) => void;
310
- type RegisterTriggerInput = Omit<RegisterTriggerMessage, 'type' | 'id'>;
311
- type RegisterFunctionInput = Omit<RegisterFunctionMessage, 'type'>;
312
- type RegisterTriggerTypeInput = Omit<RegisterTriggerTypeMessage, 'type'>;
302
+ type RegisterTriggerInput = Omit<RegisterTriggerMessage, 'message_type' | 'id'>;
303
+ type RegisterFunctionInput = Omit<RegisterFunctionMessage, 'message_type'>;
304
+ type RegisterTriggerTypeInput = Omit<RegisterTriggerTypeMessage, 'message_type'>;
313
305
  type FunctionsAvailableCallback = (functions: FunctionInfo[]) => void;
314
306
  interface ISdk {
315
307
  /**
@@ -377,6 +369,10 @@ interface ISdk {
377
369
  * @returns A function to unregister the callback
378
370
  */
379
371
  onLog(callback: LogCallback, config?: LogConfig): () => void;
372
+ /**
373
+ * Gracefully shutdown the iii, cleaning up all resources.
374
+ */
375
+ shutdown(): Promise<void>;
380
376
  }
381
377
  type Trigger = {
382
378
  unregister(): void;
@@ -408,11 +404,12 @@ type InitOptions = {
408
404
  invocationTimeoutMs?: number;
409
405
  /** Configuration for WebSocket reconnection behavior */
410
406
  reconnectionConfig?: Partial<IIIReconnectionConfig>;
411
- /** OpenTelemetry configuration. If provided, OTEL will be initialized automatically.
407
+ /** OpenTelemetry configuration. OTel is initialized automatically by default.
408
+ * Set `{ enabled: false }` or env `OTEL_ENABLED=false/0/no/off` to disable.
412
409
  * The engineWsUrl is set automatically from the III address. */
413
410
  otel?: Omit<OtelConfig, 'engineWsUrl'>;
414
411
  };
415
412
  declare const init: (address: string, options?: InitOptions) => ISdk;
416
413
  //#endregion
417
414
  export { extractTraceparent as A, EngineFunctions as B, initOtel as C, currentTraceId as D, currentSpanId as E, removeBaggageEntry as F, IIIConnectionState as H, setBaggageEntry as I, OtelConfig as L, getBaggageEntry as M, injectBaggage as N, extractBaggage as O, injectTraceparent as P, DEFAULT_BRIDGE_RECONNECTION_CONFIG as R, getTracer as S, withSpan as T, IIIReconnectionConfig as U, EngineTriggers as V, LogFunctions as W, SeverityNumber as _, ApiResponse as a, getLogger as b, LogCallback as c, OtelLogEvent as d, FunctionInfo as f, Meter$1 as g, Logger as h, ApiRequest as i, getAllBaggage as j, extractContext as k, LogConfig as l, WorkerStatus as m, InitOptions as n, FunctionsAvailableCallback as o, WorkerInfo as p, init as r, ISdk as s, ConnectionStateCallback as t, LogSeverityLevel as u, Span$1 as v, shutdownOtel as w, getMeter as x, SpanStatusCode as y, DEFAULT_INVOCATION_TIMEOUT_MS as z };
418
- //# sourceMappingURL=iii-BZ-tGd_y.d.cts.map
415
+ //# sourceMappingURL=iii-BhtLRYBs.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iii-BhtLRYBs.d.cts","names":[],"sources":["../src/iii-constants.ts","../src/telemetry-system/types.ts","../src/telemetry-system/context.ts","../src/telemetry-system/index.ts","../src/iii-types.ts","../src/triggers.ts","../src/types.ts","../src/iii.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;cAKa;;EAAA,SAAA,YAIH,EAAA,uBAAA;EAGG,SAAA,eAGH,EAAA,2BAAA;AAGV,CAAA;AAQA;AAQiB,cAtBJ,cAsByB,EAAA;EAczB,SAAA,mBAAA,EAAA,6BAAoC;EASpC,SAAA,GAAA,EAAA,KAAA;;;cAvCA;ECOI,SAAA,IAAA,EAAA,mBAAkB;EAuBlB,SAAA,IAAU,EAAA,mBAAA;EAcN,SAAA,KAAA,EAAA,oBAAA;EAMU,SAAA,KAAA,EAAA,oBAAA;CAAR;;KD1CX,kBAAA;;UAQK,qBAAA;EEzBD;EAcA,cAAA,EAAa,MAAA;EAcb;EASA,UAAA,EAAA,MAAA;EAQA;EASA,iBAAc,EAAA,MAAA;EAQd;EAcA,YAAA,EAAA,MAAe;EAQf;EASA,UAAA,EAAA,MAAA;AAYhB;;cFlEa,oCAAoC;;AGgBjC,cHPH,6BAAA,GGOmC,KAAA;;;;UFvC/B,kBAAA;;EAAA,cAAA,EAAA,MAAkB;EAuB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J,kBAAA,CAAA,EOkCU,OPlCV,COkCkB,qBPlCkB,CAAA;EASpC;;;SO6BJ,KAAK;AN7Dd,CAAA;AAuBiB,cMuvBJ,INvvBc,EAAA,CAAA,OAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EMuvBqB,WNvvBrB,EAAA,GMuvBmC,INvvBnC"}
package/dist/index.cjs CHANGED
@@ -25,11 +25,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  }) : target, mod));
26
26
 
27
27
  //#endregion
28
- const require_otel_worker_gauges = require('./otel-worker-gauges-bAp_yKcU.cjs');
28
+ const require_otel_worker_gauges = require('./otel-worker-gauges-8AUNGQgJ.cjs');
29
29
  let __opentelemetry_api = require("@opentelemetry/api");
30
- let module$1 = require("module");
31
- let os = require("os");
32
- os = __toESM(os);
30
+ let node_module = require("node:module");
31
+ let node_os = require("node:os");
32
+ node_os = __toESM(node_os);
33
33
  let ws = require("ws");
34
34
  let node_async_hooks = require("node:async_hooks");
35
35
  let __opentelemetry_api_logs = require("@opentelemetry/api-logs");
@@ -57,8 +57,7 @@ var Logger = class {
57
57
  if (!this._otelLogger) this._otelLogger = require_otel_worker_gauges.getLogger();
58
58
  return this._otelLogger;
59
59
  }
60
- constructor(invoker, traceId, serviceName, spanId) {
61
- this.invoker = invoker;
60
+ constructor(traceId, serviceName, spanId) {
62
61
  this.traceId = traceId;
63
62
  this.serviceName = serviceName;
64
63
  this.spanId = spanId;
@@ -122,12 +121,12 @@ const getContext = () => {
122
121
 
123
122
  //#endregion
124
123
  //#region src/iii.ts
125
- const { version: SDK_VERSION } = (0, module$1.createRequire)(require("url").pathToFileURL(__filename).href)("../package.json");
124
+ const { version: SDK_VERSION } = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("../package.json");
126
125
  function getOsInfo() {
127
- return `${os.platform()} ${os.release()} (${os.arch()})`;
126
+ return `${node_os.platform()} ${node_os.release()} (${node_os.arch()})`;
128
127
  }
129
128
  function getDefaultWorkerName() {
130
- return `${os.hostname()}:${process.pid}`;
129
+ return `${node_os.hostname()}:${process.pid}`;
131
130
  }
132
131
  var Sdk = class {
133
132
  constructor(address, options) {
@@ -149,7 +148,7 @@ var Sdk = class {
149
148
  this.triggerTypes.set(triggerType.id, {
150
149
  message: {
151
150
  ...triggerType,
152
- type: MessageType.RegisterTriggerType
151
+ message_type: MessageType.RegisterTriggerType
153
152
  },
154
153
  handler
155
154
  });
@@ -163,19 +162,18 @@ var Sdk = class {
163
162
  };
164
163
  this.registerTrigger = (trigger) => {
165
164
  const id = crypto.randomUUID();
166
- this.sendMessage(MessageType.RegisterTrigger, {
167
- ...trigger,
168
- id
169
- }, true);
170
- this.triggers.set(id, {
165
+ const fullTrigger = {
171
166
  ...trigger,
172
167
  id,
173
- type: MessageType.RegisterTrigger
174
- });
168
+ message_type: MessageType.RegisterTrigger
169
+ };
170
+ this.sendMessage(MessageType.RegisterTrigger, fullTrigger, true);
171
+ this.triggers.set(id, fullTrigger);
175
172
  return { unregister: () => {
176
173
  this.sendMessage(MessageType.UnregisterTrigger, {
177
174
  id,
178
- trigger_type: MessageType.UnregisterTrigger
175
+ message_type: MessageType.UnregisterTrigger,
176
+ type: fullTrigger.type
179
177
  });
180
178
  this.triggers.delete(id);
181
179
  } };
@@ -186,7 +184,7 @@ var Sdk = class {
186
184
  this.functions.set(message.id, {
187
185
  message: {
188
186
  ...message,
189
- type: MessageType.RegisterFunction
187
+ message_type: MessageType.RegisterFunction
190
188
  },
191
189
  handler: async (input, traceparent, baggage) => {
192
190
  if (require_otel_worker_gauges.getTracer()) {
@@ -195,12 +193,12 @@ var Sdk = class {
195
193
  const traceId = require_otel_worker_gauges.currentTraceId() ?? crypto.randomUUID();
196
194
  const spanId = require_otel_worker_gauges.currentSpanId();
197
195
  return withContext(async () => await handler(input), {
198
- logger: new Logger(void 0, traceId, message.id, spanId),
196
+ logger: new Logger(traceId, message.id, spanId),
199
197
  trace: span
200
198
  });
201
199
  }));
202
200
  }
203
- return withContext(async () => await handler(input), { logger: new Logger(void 0, crypto.randomUUID(), message.id) });
201
+ return withContext(async () => await handler(input), { logger: new Logger(crypto.randomUUID(), message.id) });
204
202
  }
205
203
  });
206
204
  return {
@@ -215,7 +213,7 @@ var Sdk = class {
215
213
  this.sendMessage(MessageType.RegisterService, message, true);
216
214
  this.services.set(message.id, {
217
215
  ...message,
218
- type: MessageType.RegisterService
216
+ message_type: MessageType.RegisterService
219
217
  });
220
218
  };
221
219
  this.call = async (function_id, data, timeoutMs) => {
@@ -267,11 +265,11 @@ var Sdk = class {
267
265
  return (await this.call(require_otel_worker_gauges.EngineFunctions.LIST_WORKERS, {})).workers;
268
266
  };
269
267
  this.createStream = (streamName, stream) => {
270
- this.registerFunction({ id: `stream.get(${streamName})` }, stream.get.bind(stream));
271
- this.registerFunction({ id: `stream.set(${streamName})` }, stream.set.bind(stream));
272
- this.registerFunction({ id: `stream.delete(${streamName})` }, stream.delete.bind(stream));
273
- this.registerFunction({ id: `stream.list(${streamName})` }, stream.list.bind(stream));
274
- this.registerFunction({ id: `stream.list_groups(${streamName})` }, stream.listGroups.bind(stream));
268
+ this.registerFunction({ id: `stream::get(${streamName})` }, stream.get.bind(stream));
269
+ this.registerFunction({ id: `stream::set(${streamName})` }, stream.set.bind(stream));
270
+ this.registerFunction({ id: `stream::delete(${streamName})` }, stream.delete.bind(stream));
271
+ this.registerFunction({ id: `stream::list(${streamName})` }, stream.list.bind(stream));
272
+ this.registerFunction({ id: `stream::list_groups(${streamName})` }, stream.listGroups.bind(stream));
275
273
  };
276
274
  this.onFunctionsAvailable = (callback) => {
277
275
  this.functionsAvailableCallbacks.add(callback);
@@ -285,7 +283,7 @@ var Sdk = class {
285
283
  return null;
286
284
  });
287
285
  this.functionsAvailableTrigger = this.registerTrigger({
288
- trigger_type: require_otel_worker_gauges.EngineTriggers.FUNCTIONS_AVAILABLE,
286
+ type: require_otel_worker_gauges.EngineTriggers.FUNCTIONS_AVAILABLE,
289
287
  function_id,
290
288
  config: {}
291
289
  });
@@ -316,7 +314,7 @@ var Sdk = class {
316
314
  return null;
317
315
  });
318
316
  this.logTrigger = this.registerTrigger({
319
- trigger_type: require_otel_worker_gauges.EngineTriggers.LOG,
317
+ type: require_otel_worker_gauges.EngineTriggers.LOG,
320
318
  function_id,
321
319
  config: {
322
320
  level: "all",
@@ -365,8 +363,8 @@ var Sdk = class {
365
363
  ...require_otel_worker_gauges.DEFAULT_BRIDGE_RECONNECTION_CONFIG,
366
364
  ...options?.reconnectionConfig
367
365
  };
368
- if (options?.otel) require_otel_worker_gauges.initOtel({
369
- ...options.otel,
366
+ require_otel_worker_gauges.initOtel({
367
+ ...options?.otel,
370
368
  engineWsUrl: this.address
371
369
  });
372
370
  this.connect();
@@ -470,7 +468,7 @@ var Sdk = class {
470
468
  const pending = this.messagesToSend;
471
469
  this.messagesToSend = [];
472
470
  for (const message of pending) {
473
- if (message.type === MessageType.InvokeFunction && message.invocation_id && !this.invocations.has(message.invocation_id)) continue;
471
+ if (message.type === MessageType.InvokeFunction && typeof message.invocation_id === "string" && !this.invocations.has(message.invocation_id)) continue;
474
472
  this.sendMessageRaw(JSON.stringify(message));
475
473
  }
476
474
  this.registerWorkerMetadata();
@@ -487,13 +485,41 @@ var Sdk = class {
487
485
  this.logError("Exception while sending message", error);
488
486
  }
489
487
  }
490
- sendMessage(type, message, skipIfClosed = false) {
491
- const fullMessage = {
492
- ...message,
493
- type
488
+ toWireFormat(messageType, message) {
489
+ const { message_type: _, ...rest } = message;
490
+ if (messageType === MessageType.RegisterTrigger && "type" in message) {
491
+ const { type: triggerType, ...triggerRest } = message;
492
+ return {
493
+ type: messageType,
494
+ ...triggerRest,
495
+ trigger_type: triggerType
496
+ };
497
+ }
498
+ if (messageType === MessageType.UnregisterTrigger && "type" in message) {
499
+ const { type: triggerType, ...triggerRest } = message;
500
+ return {
501
+ type: messageType,
502
+ ...triggerRest,
503
+ trigger_type: triggerType
504
+ };
505
+ }
506
+ if (messageType === MessageType.TriggerRegistrationResult && "type" in message) {
507
+ const { type: triggerType, ...resultRest } = message;
508
+ return {
509
+ type: messageType,
510
+ ...resultRest,
511
+ trigger_type: triggerType
512
+ };
513
+ }
514
+ return {
515
+ type: messageType,
516
+ ...rest
494
517
  };
495
- if (this.isOpen()) this.sendMessageRaw(JSON.stringify(fullMessage));
496
- else if (!skipIfClosed) this.messagesToSend.push(fullMessage);
518
+ }
519
+ sendMessage(messageType, message, skipIfClosed = false) {
520
+ const wireMessage = this.toWireFormat(messageType, message);
521
+ if (this.isOpen()) this.sendMessageRaw(JSON.stringify(wireMessage));
522
+ else if (!skipIfClosed) this.messagesToSend.push(wireMessage);
497
523
  }
498
524
  logError(message, error) {
499
525
  const otelLogger = require_otel_worker_gauges.getLogger();
@@ -570,8 +596,8 @@ var Sdk = class {
570
596
  });
571
597
  }
572
598
  async onRegisterTrigger(message) {
573
- const triggerTypeData = this.triggerTypes.get(message.trigger_type);
574
- const { id, trigger_type, function_id, config } = message;
599
+ const { trigger_type, id, function_id, config } = message;
600
+ const triggerTypeData = this.triggerTypes.get(trigger_type);
575
601
  if (triggerTypeData) try {
576
602
  await triggerTypeData.handler.registerTrigger({
577
603
  id,
@@ -580,13 +606,15 @@ var Sdk = class {
580
606
  });
581
607
  this.sendMessage(MessageType.TriggerRegistrationResult, {
582
608
  id,
583
- trigger_type,
609
+ message_type: MessageType.TriggerRegistrationResult,
610
+ type: trigger_type,
584
611
  function_id
585
612
  });
586
613
  } catch (error) {
587
614
  this.sendMessage(MessageType.TriggerRegistrationResult, {
588
615
  id,
589
- trigger_type,
616
+ message_type: MessageType.TriggerRegistrationResult,
617
+ type: trigger_type,
590
618
  function_id,
591
619
  error: {
592
620
  code: "trigger_registration_failed",
@@ -596,7 +624,8 @@ var Sdk = class {
596
624
  }
597
625
  else this.sendMessage(MessageType.TriggerRegistrationResult, {
598
626
  id,
599
- trigger_type,
627
+ message_type: MessageType.TriggerRegistrationResult,
628
+ type: trigger_type,
600
629
  function_id,
601
630
  error: {
602
631
  code: "trigger_type_not_found",
@@ -605,25 +634,25 @@ var Sdk = class {
605
634
  });
606
635
  }
607
636
  onMessage(socketMessage) {
608
- let type;
637
+ let msgType;
609
638
  let message;
610
639
  try {
611
640
  const parsed = JSON.parse(socketMessage.toString());
612
- type = parsed.type;
641
+ msgType = parsed.type;
613
642
  const { type: _, ...rest } = parsed;
614
643
  message = rest;
615
644
  } catch (error) {
616
645
  this.logError("Failed to parse incoming message", error);
617
646
  return;
618
647
  }
619
- if (type === MessageType.InvocationResult) {
648
+ if (msgType === MessageType.InvocationResult) {
620
649
  const { invocation_id, result, error } = message;
621
650
  this.onInvocationResult(invocation_id, result, error);
622
- } else if (type === MessageType.InvokeFunction) {
651
+ } else if (msgType === MessageType.InvokeFunction) {
623
652
  const { invocation_id, function_id, data, traceparent, baggage } = message;
624
653
  this.onInvokeFunction(invocation_id, function_id, data, traceparent, baggage);
625
- } else if (type === MessageType.RegisterTrigger) this.onRegisterTrigger(message);
626
- else if (type === MessageType.WorkerRegistered) {
654
+ } else if (msgType === MessageType.RegisterTrigger) this.onRegisterTrigger(message);
655
+ else if (msgType === MessageType.WorkerRegistered) {
627
656
  const { worker_id } = message;
628
657
  this.workerId = worker_id;
629
658
  console.debug("[iii] Worker registered with ID:", worker_id);