@theokit/gateway 0.10.0 → 0.12.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/dist/index.cjs CHANGED
@@ -28,6 +28,35 @@ var BasePlatformAdapter = class {
28
28
  }
29
29
  return "ok";
30
30
  }
31
+ /**
32
+ * Whether {@link editMessage} can replace the text of a message this adapter sent.
33
+ *
34
+ * Read it before starting a preview: on `false`, send the final text instead. An adapter sets
35
+ * it at construction and MUST NOT change it with `connect()`. Annotated as `boolean` so that an
36
+ * edit-capable adapter can override it with `true`.
37
+ */
38
+ supportsEdit = false;
39
+ /**
40
+ * Replace the text of a message this adapter sent, keeping its id.
41
+ *
42
+ * Returns `{ ok: true, messageId }` on success and a `SendResult` error otherwise; it never
43
+ * throws on platform errors. An edit-capable adapter applies, with no request, the same local
44
+ * checks its `sendMessage` applies (such as `empty_text`, and `not_connected` where the send
45
+ * checks the connection), plus `invalid_message_id`, and `edit_too_long` where the adapter
46
+ * splits text: an edit that would need more than one platform message is refused, never split.
47
+ *
48
+ * Default: refuses with `edit_unsupported`, makes no platform call, and checks nothing else
49
+ * first, so capability is answered before input.
50
+ */
51
+ async editMessage(_messageId, _out) {
52
+ return {
53
+ ok: false,
54
+ error: {
55
+ code: "edit_unsupported",
56
+ message: `${this.platform} adapter cannot edit a sent message`
57
+ }
58
+ };
59
+ }
31
60
  /** Lifecycle: emit a typing indicator. Default: noop. */
32
61
  async startTyping(_channelId) {
33
62
  }
@@ -36,6 +65,90 @@ var BasePlatformAdapter = class {
36
65
  }
37
66
  };
38
67
 
68
+ // src/errors/config-error.ts
69
+ var GatewayConfigurationError = class extends Error {
70
+ name = "GatewayConfigurationError";
71
+ code;
72
+ detail;
73
+ /**
74
+ * @param prefix Package prefix used in the default message (e.g. `"gateway-line"`).
75
+ * @param opts `code` (required), optional explicit `message`, optional `detail`.
76
+ */
77
+ constructor(prefix, opts) {
78
+ super(opts.message ?? `${prefix}: ${opts.code}`);
79
+ this.code = opts.code;
80
+ this.detail = opts.detail;
81
+ }
82
+ };
83
+
84
+ // src/channel/create-channels.ts
85
+ function isAbsent(value) {
86
+ return value === void 0 || value === null || value === "";
87
+ }
88
+ function missingRequiredKeys(entry, values) {
89
+ return entry.descriptor.config.filter((field) => field.required && isAbsent(values[field.key])).map((field) => field.key);
90
+ }
91
+ function refused(platform, code, reason) {
92
+ return {
93
+ refusal: {
94
+ platform,
95
+ error: new GatewayConfigurationError("gateway", {
96
+ code,
97
+ message: `channel ${platform}: ${reason}`
98
+ })
99
+ }
100
+ };
101
+ }
102
+ function refuseBeforeCreate(entry, values, builtPlatforms) {
103
+ const platform = entry.descriptor.platform;
104
+ if (builtPlatforms.has(platform)) {
105
+ return refused(platform, "duplicate_channel", "a channel for this platform was already built");
106
+ }
107
+ const missing = missingRequiredKeys(entry, values);
108
+ if (missing.length > 0) {
109
+ return refused(
110
+ platform,
111
+ "missing_required_config",
112
+ `missing required config ${missing.join(", ")}`
113
+ );
114
+ }
115
+ return void 0;
116
+ }
117
+ function createAdapter(entry, values) {
118
+ const platform = entry.descriptor.platform;
119
+ let adapter;
120
+ try {
121
+ adapter = entry.descriptor.create(values);
122
+ } catch (err) {
123
+ if (!(err instanceof GatewayConfigurationError)) throw err;
124
+ return { refusal: { platform, error: err } };
125
+ }
126
+ if (adapter.platform !== platform) {
127
+ return refused(
128
+ platform,
129
+ "platform_mismatch",
130
+ `create returned an adapter reporting platform ${adapter.platform}`
131
+ );
132
+ }
133
+ return { adapter };
134
+ }
135
+ function createChannels(entries) {
136
+ const adapters = [];
137
+ const rejected = [];
138
+ const builtPlatforms = /* @__PURE__ */ new Set();
139
+ for (const entry of entries) {
140
+ const values = entry.config ?? {};
141
+ const outcome = refuseBeforeCreate(entry, values, builtPlatforms) ?? createAdapter(entry, values);
142
+ if (outcome.refusal !== void 0) {
143
+ rejected.push(outcome.refusal);
144
+ continue;
145
+ }
146
+ adapters.push(outcome.adapter);
147
+ builtPlatforms.add(entry.descriptor.platform);
148
+ }
149
+ return { adapters, rejected };
150
+ }
151
+
39
152
  // src/delivery/router.ts
40
153
  var DeliveryRouter = class {
41
154
  adapters = /* @__PURE__ */ new Map();
@@ -59,22 +172,6 @@ var DeliveryRouter = class {
59
172
  }
60
173
  };
61
174
 
62
- // src/errors/config-error.ts
63
- var GatewayConfigurationError = class extends Error {
64
- name = "GatewayConfigurationError";
65
- code;
66
- detail;
67
- /**
68
- * @param prefix Package prefix used in the default message (e.g. `"gateway-line"`).
69
- * @param opts `code` (required), optional explicit `message`, optional `detail`.
70
- */
71
- constructor(prefix, opts) {
72
- super(opts.message ?? `${prefix}: ${opts.code}`);
73
- this.code = opts.code;
74
- this.detail = opts.detail;
75
- }
76
- };
77
-
78
175
  // src/errors/lifecycle-error.ts
79
176
  var GatewayLifecycleError = class extends Error {
80
177
  name = "GatewayLifecycleError";
@@ -139,6 +236,18 @@ var CREDENTIAL_SHAPES = {
139
236
  field: "gateway-whatsapp `appSecret`",
140
237
  why: "32 lowercase hex, the same shape as the Twilio auth token above and as every md5 and dashless UUID. Masking it would eat the correlation ids in a log."
141
238
  },
239
+ {
240
+ field: "gateway-nextcloud-talk `secret`",
241
+ why: "a Talk bot secret is a string of 40 to 128 characters the administrator chose for `occ talk:bot:install`, with no prefix or format to recognise. It never travels: both sides send only an HMAC made with it, and the adapter never logs it."
242
+ },
243
+ {
244
+ field: "gateway-irc `password` and `saslPassword`",
245
+ why: "a server password and a NickServ password are passphrases the operator chose, with no format to recognise. The SDK's `key=value` rule masks them as fields wherever they appear as `password=...`; the SASL payload on the wire is their base64, which the adapter never logs."
246
+ },
247
+ {
248
+ field: "gateway-google-chat `privateKey`",
249
+ why: "a PEM block spans lines, and in a log it usually arrives inside a JSON string with its line breaks escaped as \\n, which no single-line shape can claim whole. The SDK's `key=value` rule masks it as a field wherever it appears as `private_key=...` or `privateKey=...`."
250
+ },
142
251
  {
143
252
  field: "gateway-line `channelAccessToken`, gateway-sms `authToken` (Plivo)",
144
253
  why: "long base64 runs with no prefix, indistinguishable from any encoded blob a platform library puts in an error message."
@@ -254,6 +363,26 @@ var HookExecutor = class {
254
363
  // src/runner/gateway-runner.ts
255
364
  var DEFAULT_DRAIN_MS = 1e4;
256
365
  var DEFAULT_COMMAND_PREFIXES = ["/"];
366
+ function connectFailureReason(outcome) {
367
+ if (outcome.status === "fulfilled") return "connect returned false";
368
+ const message = outcome.reason instanceof Error ? outcome.reason.message : String(outcome.reason);
369
+ return redactSecrets(message);
370
+ }
371
+ async function releaseAdapters(adapters, during) {
372
+ await Promise.all(
373
+ adapters.map(async (a) => {
374
+ try {
375
+ await a.disconnect();
376
+ } catch (err) {
377
+ const message = err instanceof Error ? err.message : String(err);
378
+ process.stderr.write(
379
+ `[gateway] adapter "${a.platform}" disconnect failed while ${during}: ${redactSecrets(message)}
380
+ `
381
+ );
382
+ }
383
+ })
384
+ );
385
+ }
257
386
  var GatewayRunner = class {
258
387
  constructor(opts) {
259
388
  this.opts = opts;
@@ -267,7 +396,9 @@ var GatewayRunner = class {
267
396
  unsubs = [];
268
397
  /** Slash command registry: name → handler (word-boundary match, EC-A). */
269
398
  commands = /* @__PURE__ */ new Map();
270
- connected = false;
399
+ startResult;
400
+ /** The start that has not settled yet, shared by every overlapping `start()` call. */
401
+ startInFlight;
271
402
  stopped = false;
272
403
  /**
273
404
  * Register a slash command. Match rule (EC-A): text === "/" + name
@@ -279,10 +410,29 @@ var GatewayRunner = class {
279
410
  this.commands.set(name, handler);
280
411
  }
281
412
  /**
282
- * Connect all adapters and wire inbound dispatch.
413
+ * Connect the adapters and wire inbound dispatch for the ones that connected.
414
+ *
415
+ * Resolves with what connected. A second call after the first resolved returns the same result
416
+ * without connecting again.
417
+ *
418
+ * Overlapping calls share one start; a start overtaken by stop resolves with no adapter connected.
419
+ * A call made before `stop()` while another is still connecting connects nothing and settles
420
+ * with it; a call made after `stop()` throws `runner_stopped`. When `stop()` runs before the
421
+ * connect settles, the adapters that connected are disconnected, no inbound dispatch is wired,
422
+ * and the start resolves `{ connected: [], failed }`, keeping the `"isolate"` failures. Under
423
+ * `"rollback"`, a connect that fails still rejects the start.
424
+ *
425
+ * Under `connectFailure: "rollback"`, every connect settles before the rollback, so a failing
426
+ * start rejects only once its slowest connect settles, as a successful one resolves only then.
427
+ *
428
+ * An adapter whose `disconnect()` fails while a start rolls back, or while a start that `stop()`
429
+ * overtook gives its adapters back, is named on stderr with the error redacted; how the start
430
+ * settles does not change.
283
431
  *
284
432
  * @throws {GatewayLifecycleError} `runner_stopped` — the runner was already
285
433
  * stopped. A stopped runner is spent; construct a new one.
434
+ * @throws {Error} under the default `connectFailure: "rollback"`, the first connect failure, after
435
+ * every connect settled and the adapters that did connect were disconnected.
286
436
  */
287
437
  async start() {
288
438
  if (this.stopped) {
@@ -291,21 +441,80 @@ var GatewayRunner = class {
291
441
  message: "GatewayRunner.start(): this runner has already been stopped and cannot be restarted. Construct a new GatewayRunner instead."
292
442
  });
293
443
  }
294
- if (this.connected) return;
295
- const connected = [];
296
- try {
297
- await Promise.all(
298
- this.opts.adapters.map(async (a) => {
299
- const ok = await a.connect();
300
- if (ok) connected.push(a);
301
- else throw new Error(`adapter "${a.platform}" connect returned false`);
302
- })
303
- );
304
- } catch (err) {
305
- await Promise.all(connected.map((a) => a.disconnect().catch(() => void 0)));
306
- throw err;
444
+ if (this.startResult !== void 0) return this.startResult;
445
+ if (this.startInFlight === void 0) {
446
+ const pending = this.runStart();
447
+ this.startInFlight = pending;
448
+ pending.catch(() => {
449
+ if (this.startInFlight === pending) this.startInFlight = void 0;
450
+ });
451
+ }
452
+ return this.startInFlight;
453
+ }
454
+ async runStart() {
455
+ const result = (this.opts.connectFailure ?? "rollback") === "isolate" ? await this.connectIsolated() : await this.connectAllOrRollback();
456
+ if (this.stopped) {
457
+ await releaseAdapters(result.connected, "releasing a start that stop() overtook");
458
+ this.startResult = { connected: [], failed: result.failed };
459
+ return this.startResult;
460
+ }
461
+ this.wireInbound(result.connected);
462
+ this.startResult = {
463
+ connected: result.connected.map((a) => a.platform),
464
+ failed: result.failed
465
+ };
466
+ return this.startResult;
467
+ }
468
+ /**
469
+ * All or nothing: when any connect fails, disconnect the adapters that did connect, then rethrow
470
+ * the first failure. Every connect settles before the rollback: rolling back while one is still
471
+ * pending left that adapter live once it connected.
472
+ */
473
+ async connectAllOrRollback() {
474
+ const adapters = this.opts.adapters;
475
+ const failures = [];
476
+ const settled = await Promise.allSettled(
477
+ adapters.map(async (a) => {
478
+ let ok;
479
+ try {
480
+ ok = await a.connect();
481
+ } catch (err) {
482
+ failures.push(err);
483
+ throw err;
484
+ }
485
+ if (!ok) {
486
+ const refusal = new Error(`adapter "${a.platform}" connect returned false`);
487
+ failures.push(refusal);
488
+ throw refusal;
489
+ }
490
+ })
491
+ );
492
+ if (failures.length > 0) {
493
+ const connected = adapters.filter((_, i) => settled[i]?.status === "fulfilled");
494
+ await releaseAdapters(connected, "rolling back a failed start");
495
+ throw failures[0];
307
496
  }
308
- for (const a of this.opts.adapters) {
497
+ return { connected: [...adapters], failed: [] };
498
+ }
499
+ /**
500
+ * Connect every adapter and keep the ones that connected. The `async` wrapper turns a
501
+ * synchronous throw inside `connect()` into a rejection `allSettled` sees; a bare
502
+ * `a => a.connect()` would let it escape `map` and reject `start()` itself.
503
+ */
504
+ async connectIsolated() {
505
+ const adapters = this.opts.adapters;
506
+ const settled = await Promise.allSettled(adapters.map(async (a) => a.connect()));
507
+ const connected = [];
508
+ const failed = [];
509
+ settled.forEach((outcome, i) => {
510
+ const adapter = adapters[i];
511
+ if (outcome.status === "fulfilled" && outcome.value) connected.push(adapter);
512
+ else failed.push({ platform: adapter.platform, reason: connectFailureReason(outcome) });
513
+ });
514
+ return { connected, failed };
515
+ }
516
+ wireInbound(adapters) {
517
+ for (const a of adapters) {
309
518
  const unsub = a.onInbound(async (event) => {
310
519
  const p = this.dispatch(event);
311
520
  this.inflight.add(p);
@@ -313,11 +522,15 @@ var GatewayRunner = class {
313
522
  });
314
523
  this.unsubs.push(unsub);
315
524
  }
316
- this.connected = true;
317
525
  }
318
526
  /**
319
527
  * Stop the runner. Drains in-flight handlers up to `drainTimeoutMs`,
320
- * then disconnects adapters. Idempotent (EC-E).
528
+ * then disconnects adapters. Idempotent (EC-E). A disconnect that fails does not make `stop()`
529
+ * reject and does not stop the other disconnects; it is written to stderr, redacted, naming the
530
+ * platform.
531
+ *
532
+ * An adapter still connecting under an in-flight start is released when that start settles;
533
+ * `stop()` does not wait for it.
321
534
  */
322
535
  async stop() {
323
536
  if (this.stopped) return;
@@ -343,10 +556,7 @@ var GatewayRunner = class {
343
556
  if (timer !== void 0) clearTimeout(timer);
344
557
  }
345
558
  }
346
- await Promise.all(
347
- [...this.adaptersByPlatform.values()].map((a) => a.disconnect().catch(() => void 0))
348
- );
349
- this.connected = false;
559
+ await releaseAdapters([...this.adaptersByPlatform.values()], "stopping the runner");
350
560
  }
351
561
  /**
352
562
  * @internal Test seam, following `EmailAdapter._threadStoreSize`. The drain set must SHRINK: a
@@ -471,6 +681,74 @@ var SessionRouter = class {
471
681
  }
472
682
  };
473
683
 
684
+ // src/text/dialect.ts
685
+ var DIALECTS = {
686
+ // WhatsApp emphasis is inline and single-character: *bold*, _italic_, ~strike~, ```mono```.
687
+ whatsapp: { bold: "*", italic: "_", strike: "~", code: "```" },
688
+ // LINE text messages carry no rich text at all — decoration is emoji-only. Markers are dropped.
689
+ line: {},
690
+ // SMS is plain text by definition of the medium.
691
+ sms: {}
692
+ };
693
+ var PATTERN = /\*\*(?<bold>.+?)\*\*|~~(?<strike>.+?)~~|(?<![*\w])\*(?!\s)(?<italicStar>.+?)(?<!\s)\*(?!\*)|(?<![_\w])_(?!\s)(?<italicUnderscore>.+?)(?<!\s)_(?!\w)|`(?<code>.+?)`/gu;
694
+ var GROUP_MARKERS = [
695
+ ["bold", "bold"],
696
+ ["strike", "strike"],
697
+ ["italicStar", "italic"],
698
+ ["italicUnderscore", "italic"],
699
+ ["code", "code"]
700
+ ];
701
+ function toDialect(text, platform) {
702
+ const dialect = DIALECTS[platform];
703
+ if (dialect === void 0) return text;
704
+ return rewriteMarkers(text, dialect);
705
+ }
706
+ function rewriteMarkers(text, dialect) {
707
+ return text.replace(PATTERN, (matched, ...args) => {
708
+ const groups = args.at(-1);
709
+ if (groups === void 0) return matched;
710
+ for (const [group, marker] of GROUP_MARKERS) {
711
+ const content = groups[group];
712
+ if (content === void 0) continue;
713
+ const wrap = dialect[marker];
714
+ return wrap === void 0 ? content : `${wrap}${content}${wrap}`;
715
+ }
716
+ return matched;
717
+ });
718
+ }
719
+
720
+ // src/text/channel-rendering.ts
721
+ var SLACK = { bold: "*", italic: "_", strike: "~", code: "`" };
722
+ var STRIP = {};
723
+ var identity = (text) => text;
724
+ var translateWith = (dialect) => (text) => rewriteMarkers(text, dialect);
725
+ var RENDERINGS = {
726
+ whatsapp: { format: "plain", translate: translateWith(DIALECTS.whatsapp) },
727
+ slack: { format: "markdown", translate: translateWith(SLACK) },
728
+ discord: { format: "markdown", translate: identity },
729
+ mattermost: { format: "markdown", translate: identity },
730
+ teams: { format: "markdown", translate: identity },
731
+ signal: { format: "markdown", translate: identity },
732
+ line: { format: "plain", translate: translateWith(DIALECTS.line) },
733
+ sms: { format: "plain", translate: translateWith(DIALECTS.sms) },
734
+ telegram: { format: "plain", translate: translateWith(STRIP) },
735
+ matrix: { format: "plain", translate: translateWith(STRIP) },
736
+ email: { format: "plain", translate: translateWith(STRIP) },
737
+ imessage: { format: "plain", translate: translateWith(STRIP) },
738
+ google_chat: { format: "plain", translate: translateWith(STRIP) },
739
+ irc: { format: "plain", translate: translateWith(STRIP) },
740
+ nextcloud_talk: { format: "markdown", translate: identity }
741
+ };
742
+ function channelRendering(platform) {
743
+ const rendering = Object.hasOwn(RENDERINGS, platform) ? RENDERINGS[platform] : void 0;
744
+ if (rendering === void 0) {
745
+ throw new RangeError(
746
+ `channelRendering: unknown platform "${String(platform)}"; expected one of ${Object.keys(RENDERINGS).join(", ")}`
747
+ );
748
+ }
749
+ return rendering;
750
+ }
751
+
474
752
  // src/text/chunk.ts
475
753
  function searchBoundary(remaining, window, boundaries) {
476
754
  let cut = window;
@@ -547,39 +825,6 @@ function chunkByGrapheme(text, options) {
547
825
  return parts;
548
826
  }
549
827
 
550
- // src/text/dialect.ts
551
- var DIALECTS = {
552
- // WhatsApp emphasis is inline and single-character: *bold*, _italic_, ~strike~, ```mono```.
553
- whatsapp: { bold: "*", italic: "_", strike: "~", code: "```" },
554
- // LINE text messages carry no rich text at all — decoration is emoji-only. Markers are dropped.
555
- line: {},
556
- // SMS is plain text by definition of the medium.
557
- sms: {}
558
- };
559
- var PATTERN = /\*\*(?<bold>.+?)\*\*|~~(?<strike>.+?)~~|(?<![*\w])\*(?!\s)(?<italicStar>.+?)(?<!\s)\*(?!\*)|(?<![_\w])_(?!\s)(?<italicUnderscore>.+?)(?<!\s)_(?!\w)|`(?<code>.+?)`/gu;
560
- var GROUP_MARKERS = [
561
- ["bold", "bold"],
562
- ["strike", "strike"],
563
- ["italicStar", "italic"],
564
- ["italicUnderscore", "italic"],
565
- ["code", "code"]
566
- ];
567
- function toDialect(text, platform) {
568
- const dialect = DIALECTS[platform];
569
- if (dialect === void 0) return text;
570
- return text.replace(PATTERN, (matched, ...args) => {
571
- const groups = args.at(-1);
572
- if (groups === void 0) return matched;
573
- for (const [group, marker] of GROUP_MARKERS) {
574
- const content = groups[group];
575
- if (content === void 0) continue;
576
- const wrap = dialect[marker];
577
- return wrap === void 0 ? content : `${wrap}${content}${wrap}`;
578
- }
579
- return matched;
580
- });
581
- }
582
-
583
828
  // src/webhook/express-server.ts
584
829
  async function loadPeer(load, onMissing) {
585
830
  try {
@@ -589,8 +834,14 @@ async function loadPeer(load, onMissing) {
589
834
  onMissing();
590
835
  }
591
836
  }
592
- function rawBodyCapture(tag) {
593
- return (rawReq, _res, next) => {
837
+ function rawBodyCapture(tag, options = {}) {
838
+ const { maxBytes } = options;
839
+ if (maxBytes !== void 0 && !(Number.isFinite(maxBytes) && maxBytes >= 0)) {
840
+ throw new RangeError(
841
+ `[${tag}] rawBodyCapture: maxBytes must be a finite number of zero or more, got ${maxBytes}`
842
+ );
843
+ }
844
+ return (rawReq, rawRes, next) => {
594
845
  const req = rawReq;
595
846
  if (req.readableEnded === true || req.complete === true) {
596
847
  process.stderr.write(
@@ -602,17 +853,48 @@ function rawBodyCapture(tag) {
602
853
  return;
603
854
  }
604
855
  let buf = "";
856
+ let bytes = 0;
857
+ let refused2 = maxBytes !== void 0 && declaredLength(req) > maxBytes;
858
+ let settled = false;
605
859
  req.setEncoding("utf8");
606
860
  req.on("data", (chunk) => {
861
+ if (refused2 || settled) return;
862
+ bytes += Buffer.byteLength(chunk);
863
+ if (maxBytes !== void 0 && bytes > maxBytes) {
864
+ refused2 = true;
865
+ buf = "";
866
+ return;
867
+ }
607
868
  buf += chunk;
608
869
  });
609
870
  req.on("end", () => {
871
+ if (settled) return;
872
+ settled = true;
873
+ if (refused2) {
874
+ answerTooLarge(rawRes, tag, maxBytes ?? 0);
875
+ return;
876
+ }
610
877
  req.rawBody = buf;
611
878
  next();
612
879
  });
613
- req.on("error", (err) => next(err));
880
+ req.on("error", (err) => {
881
+ if (settled) return;
882
+ settled = true;
883
+ if (refused2) return;
884
+ next(err);
885
+ });
614
886
  };
615
887
  }
888
+ function declaredLength(req) {
889
+ const value = req.headers?.["content-length"];
890
+ const declared = Number(Array.isArray(value) ? value[0] : value);
891
+ return Number.isFinite(declared) ? declared : 0;
892
+ }
893
+ function answerTooLarge(res, tag, maxBytes) {
894
+ process.stderr.write(`[${tag}] refused a request (413): body larger than ${maxBytes} bytes
895
+ `);
896
+ res.status(413).json({ error: "request body too large" });
897
+ }
616
898
  function listenerLifecycle(opts) {
617
899
  let started = false;
618
900
  let stopped = false;
@@ -624,8 +906,17 @@ function listenerLifecycle(opts) {
624
906
  return;
625
907
  }
626
908
  stopped = false;
627
- await new Promise((resolve) => {
628
- listener = opts.app.listen(opts.port, () => resolve());
909
+ await new Promise((resolve, reject) => {
910
+ const settle = (err) => {
911
+ if (err === void 0) resolve();
912
+ else reject(err);
913
+ };
914
+ const current = opts.app.listen(opts.port, settle);
915
+ listener = current;
916
+ current.once?.("error", settle);
917
+ }).catch((err) => {
918
+ listener = void 0;
919
+ throw err;
629
920
  });
630
921
  started = true;
631
922
  },
@@ -651,8 +942,10 @@ exports.GatewayLifecycleError = GatewayLifecycleError;
651
942
  exports.GatewayRunner = GatewayRunner;
652
943
  exports.HookExecutor = HookExecutor;
653
944
  exports.SessionRouter = SessionRouter;
945
+ exports.channelRendering = channelRendering;
654
946
  exports.chunkByGrapheme = chunkByGrapheme;
655
947
  exports.chunkText = chunkText;
948
+ exports.createChannels = createChannels;
656
949
  exports.defaultStrategy = defaultStrategy;
657
950
  exports.listenerLifecycle = listenerLifecycle;
658
951
  exports.loadPeer = loadPeer;