@replit/river 0.20.1 → 0.21.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.
@@ -1,10 +1,11 @@
1
- import WebSocket from 'isomorphic-ws';
2
1
  import { ClientTransport, ClientTransportOptions as ProvidedClientTransportOptions } from '../../index.cjs';
3
2
  import { T as TransportClientId } from '../../../index-3ac92295.js';
4
- import { W as WebSocketConnection } from '../../../connection-dba95bc8.js';
3
+ import { W as WebSocketConnection } from '../../../connection-8a71dbe2.js';
5
4
  import '../../../types-3e5768ec.js';
6
5
  import '@sinclair/typebox';
6
+ import 'agnostic-ws';
7
7
 
8
+ type UrlGetter = (to: TransportClientId) => Promise<string> | string;
8
9
  /**
9
10
  * A transport implementation that uses a WebSocket connection with automatic reconnection.
10
11
  * @class
@@ -12,9 +13,9 @@ import '@sinclair/typebox';
12
13
  */
13
14
  declare class WebSocketClientTransport extends ClientTransport<WebSocketConnection> {
14
15
  /**
15
- * A function that returns a Promise that resolves to a WebSocket instance.
16
+ * A function that returns a Promise that resolves to a websocket URL.
16
17
  */
17
- wsGetter: (to: TransportClientId) => Promise<WebSocket>;
18
+ urlGetter: (to: TransportClientId) => Promise<string> | string;
18
19
  /**
19
20
  * Creates a new WebSocketClientTransport instance.
20
21
  * @param wsGetter A function that returns a Promise that resolves to a WebSocket instance.
@@ -22,7 +23,7 @@ declare class WebSocketClientTransport extends ClientTransport<WebSocketConnecti
22
23
  * @param serverId The ID of the server this transport is connecting to.
23
24
  * @param providedOptions An optional object containing configuration options for the transport.
24
25
  */
25
- constructor(wsGetter: () => Promise<WebSocket>, clientId: TransportClientId, providedOptions?: ProvidedClientTransportOptions);
26
+ constructor(urlGetter: UrlGetter, clientId: TransportClientId, providedOptions?: ProvidedClientTransportOptions);
26
27
  createNewOutgoingConnection(to: string): Promise<WebSocketConnection>;
27
28
  }
28
29
 
@@ -1,10 +1,11 @@
1
- import WebSocket from 'isomorphic-ws';
2
1
  import { ClientTransport, ClientTransportOptions as ProvidedClientTransportOptions } from '../../index.js';
3
2
  import { T as TransportClientId } from '../../../index-3ac92295.js';
4
- import { W as WebSocketConnection } from '../../../connection-dba95bc8.js';
3
+ import { W as WebSocketConnection } from '../../../connection-8a71dbe2.js';
5
4
  import '../../../types-3e5768ec.js';
6
5
  import '@sinclair/typebox';
6
+ import 'agnostic-ws';
7
7
 
8
+ type UrlGetter = (to: TransportClientId) => Promise<string> | string;
8
9
  /**
9
10
  * A transport implementation that uses a WebSocket connection with automatic reconnection.
10
11
  * @class
@@ -12,9 +13,9 @@ import '@sinclair/typebox';
12
13
  */
13
14
  declare class WebSocketClientTransport extends ClientTransport<WebSocketConnection> {
14
15
  /**
15
- * A function that returns a Promise that resolves to a WebSocket instance.
16
+ * A function that returns a Promise that resolves to a websocket URL.
16
17
  */
17
- wsGetter: (to: TransportClientId) => Promise<WebSocket>;
18
+ urlGetter: (to: TransportClientId) => Promise<string> | string;
18
19
  /**
19
20
  * Creates a new WebSocketClientTransport instance.
20
21
  * @param wsGetter A function that returns a Promise that resolves to a WebSocket instance.
@@ -22,7 +23,7 @@ declare class WebSocketClientTransport extends ClientTransport<WebSocketConnecti
22
23
  * @param serverId The ID of the server this transport is connecting to.
23
24
  * @param providedOptions An optional object containing configuration options for the transport.
24
25
  */
25
- constructor(wsGetter: () => Promise<WebSocket>, clientId: TransportClientId, providedOptions?: ProvidedClientTransportOptions);
26
+ constructor(urlGetter: UrlGetter, clientId: TransportClientId, providedOptions?: ProvidedClientTransportOptions);
26
27
  createNewOutgoingConnection(to: string): Promise<WebSocketConnection>;
27
28
  }
28
29
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  WebSocketConnection
3
- } from "../../../chunk-FNK44ZN3.js";
3
+ } from "../../../chunk-2ERP6FUE.js";
4
4
  import {
5
5
  ClientTransport
6
6
  } from "../../../chunk-QU2EE6YU.js";
@@ -11,11 +11,12 @@ import {
11
11
  import "../../../chunk-3AW3IXVD.js";
12
12
 
13
13
  // transport/impls/ws/client.ts
14
+ import WebSocket from "agnostic-ws";
14
15
  var WebSocketClientTransport = class extends ClientTransport {
15
16
  /**
16
- * A function that returns a Promise that resolves to a WebSocket instance.
17
+ * A function that returns a Promise that resolves to a websocket URL.
17
18
  */
18
- wsGetter;
19
+ urlGetter;
19
20
  /**
20
21
  * Creates a new WebSocketClientTransport instance.
21
22
  * @param wsGetter A function that returns a Promise that resolves to a WebSocket instance.
@@ -23,9 +24,9 @@ var WebSocketClientTransport = class extends ClientTransport {
23
24
  * @param serverId The ID of the server this transport is connecting to.
24
25
  * @param providedOptions An optional object containing configuration options for the transport.
25
26
  */
26
- constructor(wsGetter, clientId, providedOptions) {
27
+ constructor(urlGetter, clientId, providedOptions) {
27
28
  super(clientId, providedOptions);
28
- this.wsGetter = wsGetter;
29
+ this.urlGetter = urlGetter;
29
30
  }
30
31
  async createNewOutgoingConnection(to) {
31
32
  const wsRes = await new Promise((resolve) => {
@@ -33,12 +34,12 @@ var WebSocketClientTransport = class extends ClientTransport {
33
34
  clientId: this.clientId,
34
35
  connectedTo: to
35
36
  });
36
- this.wsGetter(to).then((ws) => {
37
- if (ws.readyState === ws.OPEN) {
37
+ Promise.resolve(this.urlGetter(to)).then((url) => new WebSocket(url)).then((ws) => {
38
+ if (ws.readyState === WebSocket.OPEN) {
38
39
  resolve({ ws });
39
40
  return;
40
41
  }
41
- if (ws.readyState === ws.CLOSING || ws.readyState === ws.CLOSED) {
42
+ if (ws.readyState === WebSocket.CLOSING || ws.readyState === WebSocket.CLOSED) {
42
43
  resolve({ err: "ws is closing or closed" });
43
44
  return;
44
45
  }
@@ -51,7 +52,7 @@ var WebSocketClientTransport = class extends ClientTransport {
51
52
  ws.onerror = (evt) => {
52
53
  const err = evt.error;
53
54
  resolve({
54
- err: err?.code ?? "unexpected disconnect"
55
+ err: `${err.name}: ${err.message}`
55
56
  });
56
57
  };
57
58
  }).catch((e) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../transport/impls/ws/client.ts"],"sourcesContent":["import WebSocket from 'isomorphic-ws';\nimport {\n ClientTransport,\n ProvidedClientTransportOptions,\n} from '../../transport';\nimport { TransportClientId } from '../../message';\nimport { log } from '../../../logging/log';\nimport { WebSocketConnection } from './connection';\n\ntype WebSocketResult = { ws: WebSocket } | { err: string };\n\n/**\n * A transport implementation that uses a WebSocket connection with automatic reconnection.\n * @class\n * @extends Transport\n */\nexport class WebSocketClientTransport extends ClientTransport<WebSocketConnection> {\n /**\n * A function that returns a Promise that resolves to a WebSocket instance.\n */\n wsGetter: (to: TransportClientId) => Promise<WebSocket>;\n\n /**\n * Creates a new WebSocketClientTransport instance.\n * @param wsGetter A function that returns a Promise that resolves to a WebSocket instance.\n * @param clientId The ID of the client using the transport. This should be unique per session.\n * @param serverId The ID of the server this transport is connecting to.\n * @param providedOptions An optional object containing configuration options for the transport.\n */\n constructor(\n wsGetter: () => Promise<WebSocket>,\n clientId: TransportClientId,\n providedOptions?: ProvidedClientTransportOptions,\n ) {\n super(clientId, providedOptions);\n this.wsGetter = wsGetter;\n }\n\n async createNewOutgoingConnection(to: string) {\n // get a promise to an actual websocket that's ready\n const wsRes = await new Promise<WebSocketResult>((resolve) => {\n log?.info(`establishing a new websocket to ${to}`, {\n clientId: this.clientId,\n connectedTo: to,\n });\n\n this.wsGetter(to)\n .then((ws) => {\n if (ws.readyState === ws.OPEN) {\n resolve({ ws });\n return;\n }\n\n if (ws.readyState === ws.CLOSING || ws.readyState === ws.CLOSED) {\n resolve({ err: 'ws is closing or closed' });\n return;\n }\n\n ws.onopen = () => {\n resolve({ ws });\n };\n\n ws.onclose = (evt: WebSocket.CloseEvent) => {\n resolve({ err: evt.reason });\n };\n\n ws.onerror = (evt: WebSocket.ErrorEvent) => {\n const err = evt.error as { code: string } | undefined;\n resolve({\n err: err?.code ?? 'unexpected disconnect',\n });\n };\n })\n .catch((e) => {\n const reason = e instanceof Error ? e.message : 'unknown reason';\n resolve({ err: `couldn't get a new websocket: ${reason}` });\n });\n });\n\n if ('ws' in wsRes) {\n const conn = new WebSocketConnection(wsRes.ws);\n log?.info(`raw websocket to ${to} ok, starting handshake`, {\n clientId: this.clientId,\n connectedTo: to,\n });\n\n this.handleConnection(conn, to);\n return conn;\n } else {\n throw new Error(wsRes.err);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAgBO,IAAM,2BAAN,cAAuC,gBAAqC;AAAA;AAAA;AAAA;AAAA,EAIjF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,YACE,UACA,UACA,iBACA;AACA,UAAM,UAAU,eAAe;AAC/B,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,MAAM,4BAA4B,IAAY;AAE5C,UAAM,QAAQ,MAAM,IAAI,QAAyB,CAAC,YAAY;AAC5D,WAAK,KAAK,mCAAmC,EAAE,IAAI;AAAA,QACjD,UAAU,KAAK;AAAA,QACf,aAAa;AAAA,MACf,CAAC;AAED,WAAK,SAAS,EAAE,EACb,KAAK,CAAC,OAAO;AACZ,YAAI,GAAG,eAAe,GAAG,MAAM;AAC7B,kBAAQ,EAAE,GAAG,CAAC;AACd;AAAA,QACF;AAEA,YAAI,GAAG,eAAe,GAAG,WAAW,GAAG,eAAe,GAAG,QAAQ;AAC/D,kBAAQ,EAAE,KAAK,0BAA0B,CAAC;AAC1C;AAAA,QACF;AAEA,WAAG,SAAS,MAAM;AAChB,kBAAQ,EAAE,GAAG,CAAC;AAAA,QAChB;AAEA,WAAG,UAAU,CAAC,QAA8B;AAC1C,kBAAQ,EAAE,KAAK,IAAI,OAAO,CAAC;AAAA,QAC7B;AAEA,WAAG,UAAU,CAAC,QAA8B;AAC1C,gBAAM,MAAM,IAAI;AAChB,kBAAQ;AAAA,YACN,KAAK,KAAK,QAAQ;AAAA,UACpB,CAAC;AAAA,QACH;AAAA,MACF,CAAC,EACA,MAAM,CAAC,MAAM;AACZ,cAAM,SAAS,aAAa,QAAQ,EAAE,UAAU;AAChD,gBAAQ,EAAE,KAAK,iCAAiC,MAAM,GAAG,CAAC;AAAA,MAC5D,CAAC;AAAA,IACL,CAAC;AAED,QAAI,QAAQ,OAAO;AACjB,YAAM,OAAO,IAAI,oBAAoB,MAAM,EAAE;AAC7C,WAAK,KAAK,oBAAoB,EAAE,2BAA2B;AAAA,QACzD,UAAU,KAAK;AAAA,QACf,aAAa;AAAA,MACf,CAAC;AAED,WAAK,iBAAiB,MAAM,EAAE;AAC9B,aAAO;AAAA,IACT,OAAO;AACL,YAAM,IAAI,MAAM,MAAM,GAAG;AAAA,IAC3B;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../transport/impls/ws/client.ts"],"sourcesContent":["import WebSocket, { CloseEvent, ErrorEvent } from 'agnostic-ws';\nimport {\n ClientTransport,\n ProvidedClientTransportOptions,\n} from '../../transport';\nimport { TransportClientId } from '../../message';\nimport { log } from '../../../logging/log';\nimport { WebSocketConnection } from './connection';\n\ntype WebSocketResult = { ws: WebSocket } | { err: string };\ntype UrlGetter = (to: TransportClientId) => Promise<string> | string;\n\n/**\n * A transport implementation that uses a WebSocket connection with automatic reconnection.\n * @class\n * @extends Transport\n */\nexport class WebSocketClientTransport extends ClientTransport<WebSocketConnection> {\n /**\n * A function that returns a Promise that resolves to a websocket URL.\n */\n urlGetter: (to: TransportClientId) => Promise<string> | string;\n\n /**\n * Creates a new WebSocketClientTransport instance.\n * @param wsGetter A function that returns a Promise that resolves to a WebSocket instance.\n * @param clientId The ID of the client using the transport. This should be unique per session.\n * @param serverId The ID of the server this transport is connecting to.\n * @param providedOptions An optional object containing configuration options for the transport.\n */\n constructor(\n urlGetter: UrlGetter,\n clientId: TransportClientId,\n providedOptions?: ProvidedClientTransportOptions,\n ) {\n super(clientId, providedOptions);\n this.urlGetter = urlGetter;\n }\n\n async createNewOutgoingConnection(to: string) {\n // get a promise to an actual websocket that's ready\n const wsRes = await new Promise<WebSocketResult>((resolve) => {\n log?.info(`establishing a new websocket to ${to}`, {\n clientId: this.clientId,\n connectedTo: to,\n });\n\n Promise.resolve(this.urlGetter(to))\n .then((url) => new WebSocket(url))\n .then((ws) => {\n if (ws.readyState === WebSocket.OPEN) {\n resolve({ ws });\n return;\n }\n\n if (\n ws.readyState === WebSocket.CLOSING ||\n ws.readyState === WebSocket.CLOSED\n ) {\n resolve({ err: 'ws is closing or closed' });\n return;\n }\n\n ws.onopen = () => {\n resolve({ ws });\n };\n\n ws.onclose = (evt: CloseEvent) => {\n resolve({ err: evt.reason });\n };\n\n ws.onerror = (evt: ErrorEvent) => {\n const err = evt.error;\n resolve({\n err: `${err.name}: ${err.message}`,\n });\n };\n })\n .catch((e) => {\n const reason = e instanceof Error ? e.message : 'unknown reason';\n resolve({ err: `couldn't get a new websocket: ${reason}` });\n });\n });\n\n if ('ws' in wsRes) {\n const conn = new WebSocketConnection(wsRes.ws);\n log?.info(`raw websocket to ${to} ok, starting handshake`, {\n clientId: this.clientId,\n connectedTo: to,\n });\n\n this.handleConnection(conn, to);\n return conn;\n } else {\n throw new Error(wsRes.err);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,OAAO,eAA2C;AAiB3C,IAAM,2BAAN,cAAuC,gBAAqC;AAAA;AAAA;AAAA;AAAA,EAIjF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,YACE,WACA,UACA,iBACA;AACA,UAAM,UAAU,eAAe;AAC/B,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAM,4BAA4B,IAAY;AAE5C,UAAM,QAAQ,MAAM,IAAI,QAAyB,CAAC,YAAY;AAC5D,WAAK,KAAK,mCAAmC,EAAE,IAAI;AAAA,QACjD,UAAU,KAAK;AAAA,QACf,aAAa;AAAA,MACf,CAAC;AAED,cAAQ,QAAQ,KAAK,UAAU,EAAE,CAAC,EAC/B,KAAK,CAAC,QAAQ,IAAI,UAAU,GAAG,CAAC,EAChC,KAAK,CAAC,OAAO;AACZ,YAAI,GAAG,eAAe,UAAU,MAAM;AACpC,kBAAQ,EAAE,GAAG,CAAC;AACd;AAAA,QACF;AAEA,YACE,GAAG,eAAe,UAAU,WAC5B,GAAG,eAAe,UAAU,QAC5B;AACA,kBAAQ,EAAE,KAAK,0BAA0B,CAAC;AAC1C;AAAA,QACF;AAEA,WAAG,SAAS,MAAM;AAChB,kBAAQ,EAAE,GAAG,CAAC;AAAA,QAChB;AAEA,WAAG,UAAU,CAAC,QAAoB;AAChC,kBAAQ,EAAE,KAAK,IAAI,OAAO,CAAC;AAAA,QAC7B;AAEA,WAAG,UAAU,CAAC,QAAoB;AAChC,gBAAM,MAAM,IAAI;AAChB,kBAAQ;AAAA,YACN,KAAK,GAAG,IAAI,IAAI,KAAK,IAAI,OAAO;AAAA,UAClC,CAAC;AAAA,QACH;AAAA,MACF,CAAC,EACA,MAAM,CAAC,MAAM;AACZ,cAAM,SAAS,aAAa,QAAQ,EAAE,UAAU;AAChD,gBAAQ,EAAE,KAAK,iCAAiC,MAAM,GAAG,CAAC;AAAA,MAC5D,CAAC;AAAA,IACL,CAAC;AAED,QAAI,QAAQ,OAAO;AACjB,YAAM,OAAO,IAAI,oBAAoB,MAAM,EAAE;AAC7C,WAAK,KAAK,oBAAoB,EAAE,2BAA2B;AAAA,QACzD,UAAU,KAAK;AAAA,QACf,aAAa;AAAA,MACf,CAAC;AAED,WAAK,iBAAiB,MAAM,EAAE;AAC9B,aAAO;AAAA,IACT,OAAO;AACL,YAAM,IAAI,MAAM,MAAM,GAAG;AAAA,IAC3B;AAAA,EACF;AACF;","names":[]}
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // transport/impls/ws/server.ts
@@ -1020,6 +1030,7 @@ var ServerTransport = class extends Transport {
1020
1030
  };
1021
1031
 
1022
1032
  // transport/impls/ws/connection.ts
1033
+ var import_agnostic_ws = __toESM(require("agnostic-ws"), 1);
1023
1034
  var WebSocketConnection = class extends Connection {
1024
1035
  ws;
1025
1036
  constructor(ws) {
@@ -1037,10 +1048,10 @@ var WebSocketConnection = class extends Connection {
1037
1048
  this.ws.onclose = cb;
1038
1049
  }
1039
1050
  addErrorListener(cb) {
1040
- this.ws.onerror = (err) => cb(new Error(err.message));
1051
+ this.ws.onerror = (err) => cb(err.error);
1041
1052
  }
1042
1053
  send(payload) {
1043
- if (this.ws.readyState === this.ws.OPEN) {
1054
+ if (this.ws.readyState === import_agnostic_ws.default.OPEN) {
1044
1055
  this.ws.send(payload);
1045
1056
  return true;
1046
1057
  } else {