@kinotic-ai/core 5.0.0-beta.0 → 5.0.0-beta.2

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.js CHANGED
@@ -1,4 +1,4 @@
1
- // packages/core/src/api/ConnectionInfo.ts
1
+ // packages/core/src/api/ConnectOptions.ts
2
2
  class ServerInfo {
3
3
  host;
4
4
  port;
@@ -10,12 +10,6 @@ var SessionKeepAliveMode;
10
10
  SessionKeepAliveMode2["ACTIVITY"] = "ACTIVITY";
11
11
  SessionKeepAliveMode2["CONNECTION"] = "CONNECTION";
12
12
  })(SessionKeepAliveMode ||= {});
13
-
14
- class ConnectionInfo extends ServerInfo {
15
- webSocketFactory;
16
- maxConnectionAttempts;
17
- sessionKeepAlive = "ACTIVITY" /* ACTIVITY */;
18
- }
19
13
  // packages/core/src/api/event/IEventBus.ts
20
14
  var EventConstants;
21
15
  ((EventConstants2) => {
@@ -46,34 +40,6 @@ var EventConstants;
46
40
  EventConstants2["TRACESTATE_HEADER"] = "tracestate";
47
41
  })(EventConstants ||= {});
48
42
 
49
- // packages/core/src/internal/api/Util.ts
50
- class Util {
51
- static createReplyEvent(incomingHeaders, headers, body) {
52
- if (!incomingHeaders) {
53
- throw new Error("incomingHeaders cannot be null");
54
- }
55
- const replyCRI = incomingHeaders.get("reply-to" /* REPLY_TO_HEADER */);
56
- if (!replyCRI || replyCRI.trim() === "") {
57
- throw new Error("No reply-to header found, cannot create outgoing message");
58
- }
59
- const newHeaders = new Map;
60
- for (const [key, value] of incomingHeaders) {
61
- if (key.startsWith("__")) {
62
- newHeaders.set(key, value);
63
- }
64
- }
65
- if (headers) {
66
- for (const [key, value] of headers) {
67
- newHeaders.set(key, value);
68
- }
69
- }
70
- return new Event(replyCRI, newHeaders, body || undefined);
71
- }
72
- static buildBrokerUrl(serverInfo) {
73
- return "ws" + (serverInfo.useSSL ? "s" : "") + "://" + serverInfo.host + (serverInfo.port ? ":" + serverInfo.port : "") + "/v1";
74
- }
75
- }
76
-
77
43
  // packages/core/src/internal/api/StompConnectionManager.ts
78
44
  import { RxStomp } from "@stomp/rx-stomp";
79
45
  import { ReconnectionTimeMode } from "@stomp/stompjs";
@@ -111,42 +77,50 @@ class StompConnectionManager {
111
77
  get fatalErrors() {
112
78
  return this._fatalErrors;
113
79
  }
114
- activate(connectionInfo) {
115
- return new Promise((resolve, reject) => {
116
- if (!connectionInfo) {
117
- reject("You must supply a valid connectionInfo object");
118
- return;
119
- }
120
- if (!connectionInfo.host) {
121
- reject("No host provided");
122
- return;
80
+ async activate(options) {
81
+ if (!options?.host) {
82
+ throw new Error("No host provided");
83
+ }
84
+ if (this.rxStomp) {
85
+ throw new Error("Stomp connection already active");
86
+ }
87
+ const server = { host: options.host, port: options.port, useSSL: options.useSSL };
88
+ const credentialsResolver = options.credentials;
89
+ let headerAuth = false;
90
+ if (!options.webSocketFactory) {
91
+ if (!credentialsResolver) {
92
+ throw new Error("No credentials supplied and no default resolution applied");
123
93
  }
124
- if (this.rxStomp) {
125
- reject("Stomp connection already active");
126
- return;
94
+ const resolved = await credentialsResolver.resolve(server);
95
+ if (resolved === null) {
96
+ throw new Error("No Kinotic credentials found; consulted: " + credentialsResolver.name);
127
97
  }
98
+ headerAuth = resolved.authHeaders != null;
99
+ }
100
+ return new Promise((resolve, reject) => {
128
101
  this.connectionAttempts = 0;
129
102
  this.initialConnectionSuccessful = false;
130
103
  this.lastWebsocketError = null;
131
104
  this.maxConnectionAttemptsReached = false;
132
- const url = Util.buildBrokerUrl(connectionInfo);
105
+ const url = Util.buildBrokerUrl(server);
133
106
  this.rxStomp = new RxStomp;
134
107
  let preparedSocket = null;
135
- const userWebSocketFactory = connectionInfo.webSocketFactory;
108
+ const userWebSocketFactory = options.webSocketFactory;
109
+ const usesPreparedSocket = userWebSocketFactory != null || headerAuth;
136
110
  const stompConfig = {
137
111
  brokerURL: url,
138
112
  connectHeaders: {
139
- ["session-keep-alive" /* SESSION_KEEP_ALIVE_HEADER */]: connectionInfo.sessionKeepAlive
113
+ ["session-keep-alive" /* SESSION_KEEP_ALIVE_HEADER */]: options.sessionKeepAlive ?? "ACTIVITY" /* ACTIVITY */
140
114
  },
141
115
  heartbeatIncoming: 120000,
142
116
  heartbeatOutgoing: 30000,
143
117
  reconnectDelay: this.INITIAL_RECONNECT_DELAY,
144
118
  maxReconnectDelay: this.MAX_RECONNECT_DELAY,
145
119
  reconnectTimeMode: ReconnectionTimeMode.EXPONENTIAL,
146
- webSocketFactory: userWebSocketFactory ? () => preparedSocket : undefined,
120
+ webSocketFactory: usesPreparedSocket ? () => preparedSocket : undefined,
147
121
  beforeConnect: async () => {
148
- if (!userWebSocketFactory) {
149
- const sessionCheckUrl = "http" + (connectionInfo.useSSL ? "s" : "") + "://" + connectionInfo.host + (connectionInfo.port ? ":" + connectionInfo.port : "") + SESSION_CHECK_PATH;
122
+ if (!usesPreparedSocket) {
123
+ const sessionCheckUrl = "http" + (server.useSSL ? "s" : "") + "://" + server.host + (server.port ? ":" + server.port : "") + SESSION_CHECK_PATH;
150
124
  try {
151
125
  const res = await fetch(sessionCheckUrl, { credentials: "include" });
152
126
  if (res.status === 401) {
@@ -155,9 +129,9 @@ class StompConnectionManager {
155
129
  }
156
130
  } catch {}
157
131
  }
158
- if (connectionInfo?.maxConnectionAttempts) {
132
+ if (options?.maxConnectionAttempts) {
159
133
  this.connectionAttempts++;
160
- if (this.connectionAttempts > connectionInfo.maxConnectionAttempts) {
134
+ if (this.connectionAttempts > options.maxConnectionAttempts) {
161
135
  this.maxConnectionAttemptsReached = true;
162
136
  await this.signalFatal(new Error("Max number of reconnection attempts reached", { cause: this.lastWebsocketError ?? undefined }));
163
137
  return;
@@ -173,6 +147,18 @@ class StompConnectionManager {
173
147
  } catch (e) {
174
148
  await this.signalFatal(new Error("WebSocket factory failed", { cause: e }));
175
149
  }
150
+ } else if (headerAuth) {
151
+ try {
152
+ const resolved = await credentialsResolver.resolve(server);
153
+ if (resolved?.authHeaders == null) {
154
+ await this.signalFatal(new Error("Credentials resolver no longer supplies auth headers: " + credentialsResolver.name));
155
+ } else {
156
+ const WS = WebSocket;
157
+ preparedSocket = new WS(url, { headers: resolved.authHeaders });
158
+ }
159
+ } catch (e) {
160
+ await this.signalFatal(new Error("Credential resolution failed", { cause: e }));
161
+ }
176
162
  }
177
163
  }
178
164
  };
@@ -182,8 +168,12 @@ class StompConnectionManager {
182
168
  };
183
169
  }
184
170
  this.rxStomp.configure(stompConfig);
185
- this.rxStomp.webSocketErrors$.subscribe((value) => {
171
+ this.rxStomp.webSocketErrors$.subscribe(async (value) => {
186
172
  this.lastWebsocketError = value;
173
+ if (options?.maxConnectionAttempts && this.connectionAttempts >= options.maxConnectionAttempts) {
174
+ this.maxConnectionAttemptsReached = true;
175
+ await this.signalFatal(new Error("Max number of reconnection attempts reached", { cause: value ?? undefined }));
176
+ }
187
177
  });
188
178
  this.stompErrorsSubscription = this.rxStomp.stompErrors$.subscribe(async (frame) => {
189
179
  const stompError = new Error(frame.headers["message"], { cause: frame });
@@ -328,15 +318,15 @@ class EventBus {
328
318
  isConnected() {
329
319
  return this.stompConnectionManager.connected;
330
320
  }
331
- connect(connectionInfo) {
321
+ connect(options) {
332
322
  return this.serializeLifecycle(async () => {
333
323
  if (!this.stompConnectionManager.active) {
334
324
  this.cleanup();
335
- const connectedInfo = await this.stompConnectionManager.activate(connectionInfo);
325
+ const connectedInfo = await this.stompConnectionManager.activate(options);
336
326
  this.serverInfo = new ServerInfo;
337
- this.serverInfo.host = connectionInfo.host;
338
- this.serverInfo.port = connectionInfo.port;
339
- this.serverInfo.useSSL = connectionInfo.useSSL;
327
+ this.serverInfo.host = options.host;
328
+ this.serverInfo.port = options.port;
329
+ this.serverInfo.useSSL = options.useSSL;
340
330
  this.replyToCri = this.stompConnectionManager.replyToCri;
341
331
  return connectedInfo;
342
332
  } else {
@@ -502,6 +492,130 @@ class EventBus {
502
492
  }
503
493
  }
504
494
 
495
+ // packages/core/src/api/security/ChainedCredentialsResolver.ts
496
+ class ChainedCredentialsResolver {
497
+ name;
498
+ resolvers;
499
+ constructor(...resolvers) {
500
+ this.resolvers = resolvers;
501
+ this.name = `ChainedCredentialsResolver(${resolvers.map((r) => r.name).join(" -> ")})`;
502
+ }
503
+ async resolve(server) {
504
+ for (const resolver of this.resolvers) {
505
+ const resolved = await resolver.resolve(server);
506
+ if (resolved !== null) {
507
+ return resolved;
508
+ }
509
+ }
510
+ return null;
511
+ }
512
+ }
513
+
514
+ // packages/core/src/api/security/EnvCredentialsResolver.ts
515
+ class EnvCredentialsResolver {
516
+ name = "EnvCredentialsResolver";
517
+ async resolve(_server) {
518
+ const env = typeof process !== "undefined" ? process.env : undefined;
519
+ let ret = null;
520
+ if (env?.KINOTIC_CLIENT_ID && env?.KINOTIC_CLIENT_SECRET) {
521
+ const authHeaders = {
522
+ clientId: env.KINOTIC_CLIENT_ID,
523
+ clientSecret: env.KINOTIC_CLIENT_SECRET
524
+ };
525
+ if (env.KINOTIC_ORGANIZATION_ID)
526
+ authHeaders.organizationId = env.KINOTIC_ORGANIZATION_ID;
527
+ if (env.KINOTIC_APPLICATION_ID)
528
+ authHeaders.applicationId = env.KINOTIC_APPLICATION_ID;
529
+ ret = {
530
+ authHeaders,
531
+ organizationId: env.KINOTIC_ORGANIZATION_ID,
532
+ applicationId: env.KINOTIC_APPLICATION_ID
533
+ };
534
+ } else if (env?.KINOTIC_TOKEN) {
535
+ ret = { authHeaders: { Authorization: `Bearer ${env.KINOTIC_TOKEN}` } };
536
+ }
537
+ return ret;
538
+ }
539
+ }
540
+
541
+ // packages/core/src/api/security/SessionCredentialsResolver.ts
542
+ class SessionCredentialsResolver {
543
+ name = "SessionCredentialsResolver";
544
+ async resolve(_server) {
545
+ return typeof document !== "undefined" ? {} : null;
546
+ }
547
+ }
548
+
549
+ // packages/core/src/internal/api/Util.ts
550
+ var DEFAULT_PORT = 58503;
551
+ var DEFAULT_HOST = "api.kinotic.com";
552
+
553
+ class Util {
554
+ static createReplyEvent(incomingHeaders, headers, body) {
555
+ if (!incomingHeaders) {
556
+ throw new Error("incomingHeaders cannot be null");
557
+ }
558
+ const replyCRI = incomingHeaders.get("reply-to" /* REPLY_TO_HEADER */);
559
+ if (!replyCRI || replyCRI.trim() === "") {
560
+ throw new Error("No reply-to header found, cannot create outgoing message");
561
+ }
562
+ const newHeaders = new Map;
563
+ for (const [key, value] of incomingHeaders) {
564
+ if (key.startsWith("__")) {
565
+ newHeaders.set(key, value);
566
+ }
567
+ }
568
+ if (headers) {
569
+ for (const [key, value] of headers) {
570
+ newHeaders.set(key, value);
571
+ }
572
+ }
573
+ return new Event(replyCRI, newHeaders, body || undefined);
574
+ }
575
+ static buildBrokerUrl(serverInfo) {
576
+ return "ws" + (serverInfo.useSSL ? "s" : "") + "://" + serverInfo.host + (serverInfo.port ? ":" + serverInfo.port : "") + "/v1";
577
+ }
578
+ static resolveConnectOptions(options) {
579
+ const opts = options ?? {};
580
+ const env = typeof process !== "undefined" ? process.env : undefined;
581
+ const location = typeof window !== "undefined" ? window.location : undefined;
582
+ let host = opts.host ?? env?.KINOTIC_SERVER_HOST;
583
+ const hostFromLocation = host == null && location != null;
584
+ const hostDefaulted = host == null && location == null;
585
+ if (host == null) {
586
+ host = location?.hostname ?? DEFAULT_HOST;
587
+ }
588
+ let useSSL = opts.useSSL;
589
+ if (useSSL == null) {
590
+ if (env?.KINOTIC_SERVER_USE_SSL != null) {
591
+ useSSL = env.KINOTIC_SERVER_USE_SSL === "true";
592
+ } else if (hostFromLocation) {
593
+ useSSL = location.protocol === "https:";
594
+ } else {
595
+ useSSL = hostDefaulted;
596
+ }
597
+ }
598
+ let port = opts.port;
599
+ if (port === undefined) {
600
+ if (env?.KINOTIC_SERVER_PORT != null) {
601
+ port = Number(env.KINOTIC_SERVER_PORT);
602
+ } else if (hostFromLocation) {
603
+ port = location.port ? Number(location.port) : null;
604
+ } else {
605
+ port = useSSL ? null : DEFAULT_PORT;
606
+ }
607
+ }
608
+ return {
609
+ ...opts,
610
+ host,
611
+ port,
612
+ useSSL,
613
+ sessionKeepAlive: opts.sessionKeepAlive ?? "ACTIVITY" /* ACTIVITY */,
614
+ credentials: opts.credentials ?? new ChainedCredentialsResolver(new EnvCredentialsResolver, new SessionCredentialsResolver)
615
+ };
616
+ }
617
+ }
618
+
505
619
  // packages/core/src/api/ServiceRegistry.ts
506
620
  import debug3 from "debug";
507
621
 
@@ -1053,7 +1167,7 @@ import { first, map as map2 } from "rxjs/operators";
1053
1167
  // packages/core/package.json
1054
1168
  var package_default = {
1055
1169
  name: "@kinotic-ai/core",
1056
- version: "5.0.0-beta.0",
1170
+ version: "5.0.0-beta.2",
1057
1171
  type: "module",
1058
1172
  files: [
1059
1173
  "dist"
@@ -1072,6 +1186,16 @@ var package_default = {
1072
1186
  default: "./dist/index.cjs"
1073
1187
  }
1074
1188
  },
1189
+ "./node": {
1190
+ import: {
1191
+ types: "./dist/node/index.d.ts",
1192
+ default: "./dist/node/index.js"
1193
+ },
1194
+ require: {
1195
+ types: "./dist/node/index.d.cts",
1196
+ default: "./dist/node/index.cjs"
1197
+ }
1198
+ },
1075
1199
  "./package.json": "./package.json"
1076
1200
  },
1077
1201
  homepage: "https://github.com/kinotic-ai/kinotic",
@@ -1093,7 +1217,7 @@ var package_default = {
1093
1217
  "@opentelemetry/sdk-trace-node": "^2.6.1",
1094
1218
  "@types/node": "^25.6.0",
1095
1219
  "@types/uuid": "^11.0.0",
1096
- "@types/ws": "^8.18.1",
1220
+ "@types/ws": "^8.18.0",
1097
1221
  "@vitest/coverage-v8": "^4.1.4",
1098
1222
  "@vitest/runner": "^4.1.4",
1099
1223
  "@vitest/ui": "^4.1.4",
@@ -1117,7 +1241,8 @@ var package_default = {
1117
1241
  "p-tap": "^4.0.0",
1118
1242
  rxjs: "^7.8.2",
1119
1243
  "typescript-optional": "3.0.0-alpha.3",
1120
- uuid: "^13.0.0"
1244
+ uuid: "^13.0.0",
1245
+ ws: "^8.18.0"
1121
1246
  },
1122
1247
  peerDependenciesMeta: {
1123
1248
  typescript: {
@@ -1290,8 +1415,8 @@ class KinoticSingleton {
1290
1415
  this._eventBus = eventBus;
1291
1416
  this.serviceRegistry.eventBus = eventBus;
1292
1417
  }
1293
- connect(connectionInfo) {
1294
- return this._eventBus.connect(connectionInfo);
1418
+ connect(options) {
1419
+ return this._eventBus.connect(Util.resolveConnectOptions(options));
1295
1420
  }
1296
1421
  disconnect(force) {
1297
1422
  return this._eventBus.disconnect(force);
@@ -1534,39 +1659,32 @@ class Order {
1534
1659
  class Sort {
1535
1660
  orders = [];
1536
1661
  }
1537
- // packages/core/src/api/security/AuthenticatedWebSocketFactory.ts
1538
- function createAuthenticatedWebSocketFactory(serverInfo, authProvider) {
1539
- const brokerUrl = Util.buildBrokerUrl(serverInfo);
1540
- return async () => {
1541
- const headers = await authProvider.getAuthHeaders();
1542
- const WS = WebSocket;
1543
- return new WS(brokerUrl, { headers });
1544
- };
1545
- }
1546
- // packages/core/src/api/security/BasicAuthProvider.ts
1547
- class BasicAuthProvider {
1548
- authHeader;
1549
- constructor(login, passcode) {
1550
- const bytes = new TextEncoder().encode(`${login}:${passcode}`);
1551
- let binary = "";
1552
- for (const byte of bytes) {
1553
- binary += String.fromCharCode(byte);
1554
- }
1555
- this.authHeader = `Basic ${btoa(binary)}`;
1556
- }
1557
- getAuthHeaders() {
1558
- return { Authorization: this.authHeader };
1662
+ // packages/core/src/api/security/BasicCredentialsResolver.ts
1663
+ class BasicCredentialsResolver {
1664
+ name = "BasicCredentialsResolver";
1665
+ credentials;
1666
+ constructor(clientId, clientSecret, organizationId, applicationId) {
1667
+ const authHeaders = { clientId, clientSecret };
1668
+ if (organizationId != null)
1669
+ authHeaders.organizationId = organizationId;
1670
+ if (applicationId != null)
1671
+ authHeaders.applicationId = applicationId;
1672
+ this.credentials = { authHeaders, organizationId, applicationId };
1673
+ }
1674
+ async resolve(_server) {
1675
+ return this.credentials;
1559
1676
  }
1560
1677
  }
1561
- // packages/core/src/api/security/BearerTokenAuthProvider.ts
1562
- class BearerTokenAuthProvider {
1678
+ // packages/core/src/api/security/BearerCredentialsResolver.ts
1679
+ class BearerCredentialsResolver {
1680
+ name = "BearerCredentialsResolver";
1563
1681
  token;
1564
1682
  constructor(token) {
1565
1683
  this.token = token;
1566
1684
  }
1567
- async getAuthHeaders() {
1685
+ async resolve(_server) {
1568
1686
  const token = typeof this.token === "function" ? await this.token() : this.token;
1569
- return { Authorization: `Bearer ${token}` };
1687
+ return { authHeaders: { Authorization: `Bearer ${token}` } };
1570
1688
  }
1571
1689
  }
1572
1690
  // packages/core/src/api/security/ConnectedInfo.ts
@@ -1577,10 +1695,9 @@ class ConnectedInfo {
1577
1695
  // packages/core/src/api/security/ParticipantConstants.ts
1578
1696
  class ParticipantConstants {
1579
1697
  static PARTICIPANT_TYPE_METADATA_KEY = "type";
1580
- static PARTICIPANT_TYPE_DEVICE = "device";
1581
- static PARTICIPANT_TYPE_CLI = "cli";
1582
1698
  static PARTICIPANT_TYPE_USER = "user";
1583
- static PARTICIPANT_TYPE_NODE = "node";
1699
+ static PARTICIPANT_TYPE_DELEGATE = "delegate";
1700
+ static PARTICIPANT_TYPE_MACHINE = "machine";
1584
1701
  static CLI_PARTICIPANT_ID = "-42-Kinotic-CLI-42-";
1585
1702
  }
1586
1703
  export {
@@ -1589,12 +1706,12 @@ export {
1589
1706
  receivesContext,
1590
1707
  isAdvertised,
1591
1708
  createCRI,
1592
- createAuthenticatedWebSocketFactory,
1593
1709
  Zone,
1594
1710
  Version,
1595
1711
  TextEventFactory,
1596
1712
  Sort,
1597
1713
  SessionKeepAliveMode,
1714
+ SessionCredentialsResolver,
1598
1715
  ServiceRegistry,
1599
1716
  ServerInfo,
1600
1717
  Scope,
@@ -1611,6 +1728,7 @@ export {
1611
1728
  EventConstants,
1612
1729
  EventBus,
1613
1730
  Event,
1731
+ EnvCredentialsResolver,
1614
1732
  Direction,
1615
1733
  DefaultCRI,
1616
1734
  DataSourceUtils,
@@ -1618,9 +1736,9 @@ export {
1618
1736
  CrudServiceProxyFactory,
1619
1737
  CrudServiceProxy,
1620
1738
  Context,
1621
- ConnectionInfo,
1622
1739
  ConnectedInfo,
1623
- BearerTokenAuthProvider,
1624
- BasicAuthProvider,
1740
+ ChainedCredentialsResolver,
1741
+ BearerCredentialsResolver,
1742
+ BasicCredentialsResolver,
1625
1743
  AbstractIterablePage
1626
1744
  };
@@ -0,0 +1,79 @@
1
+ var import_node_module = require("node:module");
2
+ var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ function __accessProp(key) {
9
+ return this[key];
10
+ }
11
+ var __toESMCache_node;
12
+ var __toESMCache_esm;
13
+ var __toESM = (mod, isNodeMode, target) => {
14
+ var canCache = mod != null && typeof mod === "object";
15
+ if (canCache) {
16
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
17
+ var cached = cache.get(mod);
18
+ if (cached)
19
+ return cached;
20
+ }
21
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
22
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
23
+ for (let key of __getOwnPropNames(mod))
24
+ if (!__hasOwnProp.call(to, key))
25
+ __defProp(to, key, {
26
+ get: __accessProp.bind(mod, key),
27
+ enumerable: true
28
+ });
29
+ if (canCache)
30
+ cache.set(mod, to);
31
+ return to;
32
+ };
33
+ var __toCommonJS = (from) => {
34
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
35
+ if (entry)
36
+ return entry;
37
+ entry = __defProp({}, "__esModule", { value: true });
38
+ if (from && typeof from === "object" || typeof from === "function") {
39
+ for (var key of __getOwnPropNames(from))
40
+ if (!__hasOwnProp.call(entry, key))
41
+ __defProp(entry, key, {
42
+ get: __accessProp.bind(from, key),
43
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
44
+ });
45
+ }
46
+ __moduleCache.set(from, entry);
47
+ return entry;
48
+ };
49
+ var __moduleCache;
50
+ var __returnValue = (v) => v;
51
+ function __exportSetter(name, newValue) {
52
+ this[name] = __returnValue.bind(null, newValue);
53
+ }
54
+ var __export = (target, all) => {
55
+ for (var name in all)
56
+ __defProp(target, name, {
57
+ get: all[name],
58
+ enumerable: true,
59
+ configurable: true,
60
+ set: __exportSetter.bind(all, name)
61
+ });
62
+ };
63
+
64
+ // packages/core/src/node/index.ts
65
+ var exports_node = {};
66
+ __export(exports_node, {
67
+ ensureNodeWebSocket: () => ensureNodeWebSocket
68
+ });
69
+ module.exports = __toCommonJS(exports_node);
70
+ var import_ws = require("ws");
71
+ function ensureNodeWebSocket() {
72
+ if (typeof globalThis.WebSocket === "undefined") {
73
+ Object.assign(globalThis, { WebSocket: import_ws.WebSocket });
74
+ return;
75
+ }
76
+ if (typeof process !== "undefined" && process.versions?.node && !process.versions?.bun) {
77
+ Object.assign(globalThis, { WebSocket: import_ws.WebSocket });
78
+ }
79
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Installs the `ws` WebSocket as the global WebSocket when the runtime does not provide a
3
+ * header-capable one. Upgrade-header authentication (client credentials, bearer tokens)
4
+ * needs a WebSocket constructor that accepts a `headers` option — `ws` and Bun's built-in
5
+ * do; browsers and some Node versions do not. Call once before {@code Kinotic.connect()}
6
+ * in a Node process.
7
+ */
8
+ declare function ensureNodeWebSocket(): void;
9
+ export { ensureNodeWebSocket };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Installs the `ws` WebSocket as the global WebSocket when the runtime does not provide a
3
+ * header-capable one. Upgrade-header authentication (client credentials, bearer tokens)
4
+ * needs a WebSocket constructor that accepts a `headers` option — `ws` and Bun's built-in
5
+ * do; browsers and some Node versions do not. Call once before {@code Kinotic.connect()}
6
+ * in a Node process.
7
+ */
8
+ declare function ensureNodeWebSocket(): void;
9
+ export { ensureNodeWebSocket };
@@ -0,0 +1,14 @@
1
+ // packages/core/src/node/index.ts
2
+ import { WebSocket as NodeWebSocket } from "ws";
3
+ function ensureNodeWebSocket() {
4
+ if (typeof globalThis.WebSocket === "undefined") {
5
+ Object.assign(globalThis, { WebSocket: NodeWebSocket });
6
+ return;
7
+ }
8
+ if (typeof process !== "undefined" && process.versions?.node && !process.versions?.bun) {
9
+ Object.assign(globalThis, { WebSocket: NodeWebSocket });
10
+ }
11
+ }
12
+ export {
13
+ ensureNodeWebSocket
14
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kinotic-ai/core",
3
- "version": "5.0.0-beta.0",
3
+ "version": "5.0.0-beta.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -19,6 +19,16 @@
19
19
  "default": "./dist/index.cjs"
20
20
  }
21
21
  },
22
+ "./node": {
23
+ "import": {
24
+ "types": "./dist/node/index.d.ts",
25
+ "default": "./dist/node/index.js"
26
+ },
27
+ "require": {
28
+ "types": "./dist/node/index.d.cts",
29
+ "default": "./dist/node/index.cjs"
30
+ }
31
+ },
22
32
  "./package.json": "./package.json"
23
33
  },
24
34
  "homepage": "https://github.com/kinotic-ai/kinotic",
@@ -40,7 +50,7 @@
40
50
  "@opentelemetry/sdk-trace-node": "^2.6.1",
41
51
  "@types/node": "^25.6.0",
42
52
  "@types/uuid": "^11.0.0",
43
- "@types/ws": "^8.18.1",
53
+ "@types/ws": "^8.18.0",
44
54
  "@vitest/coverage-v8": "^4.1.4",
45
55
  "@vitest/runner": "^4.1.4",
46
56
  "@vitest/ui": "^4.1.4",
@@ -64,7 +74,8 @@
64
74
  "p-tap": "^4.0.0",
65
75
  "rxjs": "^7.8.2",
66
76
  "typescript-optional": "3.0.0-alpha.3",
67
- "uuid": "^13.0.0"
77
+ "uuid": "^13.0.0",
78
+ "ws": "^8.18.0"
68
79
  },
69
80
  "peerDependenciesMeta": {
70
81
  "typescript": {