@kodama-run/sdk 0.3.0 → 0.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kodama-run/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
package/src/room.ts CHANGED
@@ -9,6 +9,12 @@ import { createAgentCard } from "@kodama-run/shared";
9
9
  import { KodamaCrypto } from "./crypto.ts";
10
10
  import { PermissionChecker } from "./permissions.ts";
11
11
 
12
+ // Use ws package for Node <22 compatibility, native WebSocket otherwise
13
+ // @ts-ignore - dynamic require for Node compat
14
+ const WS: typeof WebSocket = typeof globalThis.WebSocket !== "undefined"
15
+ ? globalThis.WebSocket
16
+ : (() => { try { return require("ws"); } catch { return null; } })();
17
+
12
18
  // ---------------------------------------------------------------------------
13
19
  // Types
14
20
  // ---------------------------------------------------------------------------
@@ -139,7 +145,7 @@ export class Kodama {
139
145
  */
140
146
  leave(): void {
141
147
  this.closed = true;
142
- if (this.ws && this.ws.readyState === WebSocket.OPEN) {
148
+ if (this.ws && this.ws.readyState === WS.OPEN) {
143
149
  this.ws.send(JSON.stringify({ action: "leave" }));
144
150
  this.ws.close();
145
151
  }
@@ -172,7 +178,7 @@ export class Kodama {
172
178
  // -----------------------------------------------------------------------
173
179
 
174
180
  private connect(): void {
175
- const ws = new WebSocket(this.relayUrl);
181
+ const ws = new WS(this.relayUrl) as unknown as WebSocket;
176
182
  this.ws = ws;
177
183
 
178
184
  ws.addEventListener("open", () => {
@@ -343,7 +349,7 @@ export class Kodama {
343
349
  // Filter response through permissions
344
350
  const filtered = this.permissions.filterMessage(content);
345
351
 
346
- if (this.ws && this.ws.readyState === WebSocket.OPEN) {
352
+ if (this.ws && this.ws.readyState === WS.OPEN) {
347
353
  this.ws.send(
348
354
  JSON.stringify({
349
355
  action: "message",