@runware/sdk-js 1.1.17-beta.2 → 1.1.17-beta.4

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.d.mts CHANGED
@@ -22,7 +22,7 @@ type RunwareBaseType = {
22
22
  url?: string;
23
23
  shouldReconnect?: boolean;
24
24
  globalMaxRetries?: number;
25
- timeOutDuration?: number;
25
+ timeoutDuration?: number;
26
26
  };
27
27
  type IOutputType = "base64Data" | "dataURI" | "URL";
28
28
  type IOutputFormat = "JPG" | "PNG" | "WEBP";
@@ -263,8 +263,8 @@ declare class RunwareBase {
263
263
  _sdkType: SdkType;
264
264
  _shouldReconnect: boolean;
265
265
  _globalMaxRetries: number;
266
- _timeOutDuration: number;
267
- constructor({ apiKey, url, shouldReconnect, globalMaxRetries, timeOutDuration, }: RunwareBaseType);
266
+ _timeoutDuration: number;
267
+ constructor({ apiKey, url, shouldReconnect, globalMaxRetries, timeoutDuration, }: RunwareBaseType);
268
268
  protected isWebsocketReadyState: () => boolean;
269
269
  protected addListener({ lis, groupKey, taskUUID, }: {
270
270
  lis: (v: any) => any;
package/dist/index.d.ts CHANGED
@@ -22,7 +22,7 @@ type RunwareBaseType = {
22
22
  url?: string;
23
23
  shouldReconnect?: boolean;
24
24
  globalMaxRetries?: number;
25
- timeOutDuration?: number;
25
+ timeoutDuration?: number;
26
26
  };
27
27
  type IOutputType = "base64Data" | "dataURI" | "URL";
28
28
  type IOutputFormat = "JPG" | "PNG" | "WEBP";
@@ -263,8 +263,8 @@ declare class RunwareBase {
263
263
  _sdkType: SdkType;
264
264
  _shouldReconnect: boolean;
265
265
  _globalMaxRetries: number;
266
- _timeOutDuration: number;
267
- constructor({ apiKey, url, shouldReconnect, globalMaxRetries, timeOutDuration, }: RunwareBaseType);
266
+ _timeoutDuration: number;
267
+ constructor({ apiKey, url, shouldReconnect, globalMaxRetries, timeoutDuration, }: RunwareBaseType);
268
268
  protected isWebsocketReadyState: () => boolean;
269
269
  protected addListener({ lis, groupKey, taskUUID, }: {
270
270
  lis: (v: any) => any;
package/dist/index.js CHANGED
@@ -180,9 +180,9 @@ var require_reconnect = __commonJS({
180
180
  };
181
181
  log("init");
182
182
  connect();
183
- this.close = (code = 1e3, reason = "", { keepClosed = false, fastClose = true, delay: delay2 = 0 } = {}) => {
184
- if (delay2) {
185
- reconnectDelay = delay2;
183
+ this.close = (code = 1e3, reason = "", { keepClosed = false, fastClose = true, delay: delay3 = 0 } = {}) => {
184
+ if (delay3) {
185
+ reconnectDelay = delay3;
186
186
  }
187
187
  shouldRetry = !keepClosed;
188
188
  ws.close(code, reason);
@@ -331,6 +331,7 @@ var EOpenPosePreProcessor = /* @__PURE__ */ ((EOpenPosePreProcessor2) => {
331
331
  // Runware/utils.ts
332
332
  var import_uuid = require("uuid");
333
333
  var TIMEOUT_DURATION = 6e4;
334
+ var MINIMUM_TIMEOUT_DURATION = 1e3;
334
335
  var POLLING_INTERVAL = 100;
335
336
  var BASE_RUNWARE_URLS = {
336
337
  ["PRODUCTION" /* PRODUCTION */]: "wss://ws-api.runware.ai/v1",
@@ -348,9 +349,10 @@ var removeFromAray = (col, targetElem) => {
348
349
  };
349
350
  var getIntervalWithPromise = (callback, {
350
351
  debugKey = "debugKey",
351
- timeOutDuration = TIMEOUT_DURATION,
352
+ timeoutDuration = TIMEOUT_DURATION,
352
353
  shouldThrowError = true
353
354
  }) => {
355
+ timeoutDuration = timeoutDuration < MINIMUM_TIMEOUT_DURATION ? MINIMUM_TIMEOUT_DURATION : timeoutDuration;
354
356
  return new Promise((resolve, reject) => {
355
357
  const timeoutId = setTimeout(() => {
356
358
  if (intervalId) {
@@ -360,7 +362,7 @@ var getIntervalWithPromise = (callback, {
360
362
  }
361
363
  }
362
364
  clearTimeout(timeoutId);
363
- }, timeOutDuration);
365
+ }, timeoutDuration);
364
366
  let intervalId = setInterval(async () => {
365
367
  const shouldClear = callback({ resolve, reject, intervalId });
366
368
  if (shouldClear) {
@@ -452,7 +454,7 @@ var RunwareBase = class {
452
454
  url = BASE_RUNWARE_URLS.PRODUCTION,
453
455
  shouldReconnect = true,
454
456
  globalMaxRetries = 2,
455
- timeOutDuration = TIMEOUT_DURATION
457
+ timeoutDuration = TIMEOUT_DURATION
456
458
  }) {
457
459
  this._listeners = [];
458
460
  // _globalMessages: any[] = [];
@@ -550,7 +552,7 @@ var RunwareBase = class {
550
552
  },
551
553
  {
552
554
  debugKey: "unprocessed-image",
553
- timeOutDuration: this._timeOutDuration
555
+ timeoutDuration: this._timeoutDuration
554
556
  }
555
557
  );
556
558
  lis.destroy();
@@ -608,7 +610,7 @@ var RunwareBase = class {
608
610
  },
609
611
  {
610
612
  debugKey: "remove-image-background",
611
- timeOutDuration: this._timeOutDuration
613
+ timeoutDuration: this._timeoutDuration
612
614
  }
613
615
  );
614
616
  lis.destroy();
@@ -688,7 +690,7 @@ var RunwareBase = class {
688
690
  },
689
691
  {
690
692
  debugKey: "remove-image-background",
691
- timeOutDuration: this._timeOutDuration
693
+ timeoutDuration: this._timeoutDuration
692
694
  }
693
695
  );
694
696
  lis.destroy();
@@ -747,7 +749,7 @@ var RunwareBase = class {
747
749
  return true;
748
750
  }
749
751
  },
750
- { debugKey: "upscale-gan", timeOutDuration: this._timeOutDuration }
752
+ { debugKey: "upscale-gan", timeoutDuration: this._timeoutDuration }
751
753
  );
752
754
  lis.destroy();
753
755
  return response;
@@ -804,7 +806,7 @@ var RunwareBase = class {
804
806
  },
805
807
  {
806
808
  debugKey: "enhance-prompt",
807
- timeOutDuration: this._timeOutDuration
809
+ timeoutDuration: this._timeoutDuration
808
810
  }
809
811
  );
810
812
  lis.destroy();
@@ -840,7 +842,7 @@ var RunwareBase = class {
840
842
  this._sdkType = "CLIENT" /* CLIENT */;
841
843
  this._shouldReconnect = shouldReconnect;
842
844
  this._globalMaxRetries = globalMaxRetries;
843
- this._timeOutDuration = timeOutDuration;
845
+ this._timeoutDuration = timeoutDuration;
844
846
  }
845
847
  // protected addListener({
846
848
  // lis,
@@ -912,7 +914,7 @@ var RunwareBase = class {
912
914
  lis: (m) => {
913
915
  var _a, _b;
914
916
  if (m == null ? void 0 : m.error) {
915
- this._invalidAPIkey = "Invalid API key";
917
+ this._invalidAPIkey = m;
916
918
  return;
917
919
  }
918
920
  this._connectionSessionUUID = (_b = (_a = m == null ? void 0 : m["authentication" /* AUTHENTICATION */]) == null ? void 0 : _a[0]) == null ? void 0 : _b.connectionSessionUUID;
@@ -1197,18 +1199,15 @@ var RunwareBase = class {
1197
1199
  if (hasConnected) {
1198
1200
  clearAllIntervals();
1199
1201
  resolve(true);
1202
+ return;
1200
1203
  }
1201
1204
  if (!!this._invalidAPIkey) {
1202
1205
  clearAllIntervals();
1203
- reject(new Error("Invalid API key"));
1206
+ reject(this._invalidAPIkey);
1204
1207
  return;
1205
1208
  }
1206
1209
  }, pollingInterval);
1207
1210
  });
1208
- if (!isConnected) {
1209
- this.connect();
1210
- await delay(2);
1211
- }
1212
1211
  } catch (e) {
1213
1212
  throw (_a = this._invalidAPIkey) != null ? _a : "Could not connect to server. Ensure your API key is correct";
1214
1213
  }
@@ -1243,7 +1242,7 @@ var RunwareBase = class {
1243
1242
  {
1244
1243
  debugKey: "getting images",
1245
1244
  shouldThrowError,
1246
- timeOutDuration: this._timeOutDuration
1245
+ timeoutDuration: this._timeoutDuration
1247
1246
  }
1248
1247
  );
1249
1248
  }
@@ -1272,12 +1271,10 @@ var RunwareClient = class extends RunwareBase {
1272
1271
  constructor(props) {
1273
1272
  const _a = props, { shouldReconnect } = _a, rest = __objRest(_a, ["shouldReconnect"]);
1274
1273
  super(rest);
1275
- if (rest.apiKey) {
1276
- this._ws = new import_reconnect.default(
1277
- this._url
1278
- );
1279
- this.connect();
1280
- }
1274
+ this._ws = new import_reconnect.default(
1275
+ this._url
1276
+ );
1277
+ this.connect();
1281
1278
  }
1282
1279
  };
1283
1280
 
@@ -1306,9 +1303,7 @@ var RunwareServer = class extends RunwareBase {
1306
1303
  }
1307
1304
  };
1308
1305
  this._sdkType = "SERVER" /* SERVER */;
1309
- if (props.apiKey) {
1310
- this.connect();
1311
- }
1306
+ this.connect();
1312
1307
  }
1313
1308
  // protected addListener({
1314
1309
  // lis,
@@ -1370,7 +1365,7 @@ var RunwareServer = class extends RunwareBase {
1370
1365
  lis: (m) => {
1371
1366
  var _a, _b;
1372
1367
  if (m == null ? void 0 : m.error) {
1373
- this._invalidAPIkey = "Invalid API key";
1368
+ this._invalidAPIkey = m;
1374
1369
  return;
1375
1370
  }
1376
1371
  this._connectionSessionUUID = (_b = (_a = m == null ? void 0 : m["authentication" /* AUTHENTICATION */]) == null ? void 0 : _a[0]) == null ? void 0 : _b.connectionSessionUUID;
@@ -1393,8 +1388,6 @@ var RunwareServer = class extends RunwareBase {
1393
1388
  }
1394
1389
  handleClose() {
1395
1390
  if (this._invalidAPIkey) {
1396
- console.error(this._invalidAPIkey);
1397
- return;
1398
1391
  }
1399
1392
  if (this._reconnectingIntervalId) {
1400
1393
  clearInterval(this._reconnectingIntervalId);
package/dist/index.mjs CHANGED
@@ -174,9 +174,9 @@ var require_reconnect = __commonJS({
174
174
  };
175
175
  log("init");
176
176
  connect();
177
- this.close = (code = 1e3, reason = "", { keepClosed = false, fastClose = true, delay: delay2 = 0 } = {}) => {
178
- if (delay2) {
179
- reconnectDelay = delay2;
177
+ this.close = (code = 1e3, reason = "", { keepClosed = false, fastClose = true, delay: delay3 = 0 } = {}) => {
178
+ if (delay3) {
179
+ reconnectDelay = delay3;
180
180
  }
181
181
  shouldRetry = !keepClosed;
182
182
  ws.close(code, reason);
@@ -309,6 +309,7 @@ var EOpenPosePreProcessor = /* @__PURE__ */ ((EOpenPosePreProcessor2) => {
309
309
  // Runware/utils.ts
310
310
  import { v4 as uuidv4, validate as validateUUID } from "uuid";
311
311
  var TIMEOUT_DURATION = 6e4;
312
+ var MINIMUM_TIMEOUT_DURATION = 1e3;
312
313
  var POLLING_INTERVAL = 100;
313
314
  var BASE_RUNWARE_URLS = {
314
315
  ["PRODUCTION" /* PRODUCTION */]: "wss://ws-api.runware.ai/v1",
@@ -326,9 +327,10 @@ var removeFromAray = (col, targetElem) => {
326
327
  };
327
328
  var getIntervalWithPromise = (callback, {
328
329
  debugKey = "debugKey",
329
- timeOutDuration = TIMEOUT_DURATION,
330
+ timeoutDuration = TIMEOUT_DURATION,
330
331
  shouldThrowError = true
331
332
  }) => {
333
+ timeoutDuration = timeoutDuration < MINIMUM_TIMEOUT_DURATION ? MINIMUM_TIMEOUT_DURATION : timeoutDuration;
332
334
  return new Promise((resolve, reject) => {
333
335
  const timeoutId = setTimeout(() => {
334
336
  if (intervalId) {
@@ -338,7 +340,7 @@ var getIntervalWithPromise = (callback, {
338
340
  }
339
341
  }
340
342
  clearTimeout(timeoutId);
341
- }, timeOutDuration);
343
+ }, timeoutDuration);
342
344
  let intervalId = setInterval(async () => {
343
345
  const shouldClear = callback({ resolve, reject, intervalId });
344
346
  if (shouldClear) {
@@ -430,7 +432,7 @@ var RunwareBase = class {
430
432
  url = BASE_RUNWARE_URLS.PRODUCTION,
431
433
  shouldReconnect = true,
432
434
  globalMaxRetries = 2,
433
- timeOutDuration = TIMEOUT_DURATION
435
+ timeoutDuration = TIMEOUT_DURATION
434
436
  }) {
435
437
  this._listeners = [];
436
438
  // _globalMessages: any[] = [];
@@ -528,7 +530,7 @@ var RunwareBase = class {
528
530
  },
529
531
  {
530
532
  debugKey: "unprocessed-image",
531
- timeOutDuration: this._timeOutDuration
533
+ timeoutDuration: this._timeoutDuration
532
534
  }
533
535
  );
534
536
  lis.destroy();
@@ -586,7 +588,7 @@ var RunwareBase = class {
586
588
  },
587
589
  {
588
590
  debugKey: "remove-image-background",
589
- timeOutDuration: this._timeOutDuration
591
+ timeoutDuration: this._timeoutDuration
590
592
  }
591
593
  );
592
594
  lis.destroy();
@@ -666,7 +668,7 @@ var RunwareBase = class {
666
668
  },
667
669
  {
668
670
  debugKey: "remove-image-background",
669
- timeOutDuration: this._timeOutDuration
671
+ timeoutDuration: this._timeoutDuration
670
672
  }
671
673
  );
672
674
  lis.destroy();
@@ -725,7 +727,7 @@ var RunwareBase = class {
725
727
  return true;
726
728
  }
727
729
  },
728
- { debugKey: "upscale-gan", timeOutDuration: this._timeOutDuration }
730
+ { debugKey: "upscale-gan", timeoutDuration: this._timeoutDuration }
729
731
  );
730
732
  lis.destroy();
731
733
  return response;
@@ -782,7 +784,7 @@ var RunwareBase = class {
782
784
  },
783
785
  {
784
786
  debugKey: "enhance-prompt",
785
- timeOutDuration: this._timeOutDuration
787
+ timeoutDuration: this._timeoutDuration
786
788
  }
787
789
  );
788
790
  lis.destroy();
@@ -818,7 +820,7 @@ var RunwareBase = class {
818
820
  this._sdkType = "CLIENT" /* CLIENT */;
819
821
  this._shouldReconnect = shouldReconnect;
820
822
  this._globalMaxRetries = globalMaxRetries;
821
- this._timeOutDuration = timeOutDuration;
823
+ this._timeoutDuration = timeoutDuration;
822
824
  }
823
825
  // protected addListener({
824
826
  // lis,
@@ -890,7 +892,7 @@ var RunwareBase = class {
890
892
  lis: (m) => {
891
893
  var _a, _b;
892
894
  if (m == null ? void 0 : m.error) {
893
- this._invalidAPIkey = "Invalid API key";
895
+ this._invalidAPIkey = m;
894
896
  return;
895
897
  }
896
898
  this._connectionSessionUUID = (_b = (_a = m == null ? void 0 : m["authentication" /* AUTHENTICATION */]) == null ? void 0 : _a[0]) == null ? void 0 : _b.connectionSessionUUID;
@@ -1175,18 +1177,15 @@ var RunwareBase = class {
1175
1177
  if (hasConnected) {
1176
1178
  clearAllIntervals();
1177
1179
  resolve(true);
1180
+ return;
1178
1181
  }
1179
1182
  if (!!this._invalidAPIkey) {
1180
1183
  clearAllIntervals();
1181
- reject(new Error("Invalid API key"));
1184
+ reject(this._invalidAPIkey);
1182
1185
  return;
1183
1186
  }
1184
1187
  }, pollingInterval);
1185
1188
  });
1186
- if (!isConnected) {
1187
- this.connect();
1188
- await delay(2);
1189
- }
1190
1189
  } catch (e) {
1191
1190
  throw (_a = this._invalidAPIkey) != null ? _a : "Could not connect to server. Ensure your API key is correct";
1192
1191
  }
@@ -1221,7 +1220,7 @@ var RunwareBase = class {
1221
1220
  {
1222
1221
  debugKey: "getting images",
1223
1222
  shouldThrowError,
1224
- timeOutDuration: this._timeOutDuration
1223
+ timeoutDuration: this._timeoutDuration
1225
1224
  }
1226
1225
  );
1227
1226
  }
@@ -1250,12 +1249,10 @@ var RunwareClient = class extends RunwareBase {
1250
1249
  constructor(props) {
1251
1250
  const _a = props, { shouldReconnect } = _a, rest = __objRest(_a, ["shouldReconnect"]);
1252
1251
  super(rest);
1253
- if (rest.apiKey) {
1254
- this._ws = new import_reconnect.default(
1255
- this._url
1256
- );
1257
- this.connect();
1258
- }
1252
+ this._ws = new import_reconnect.default(
1253
+ this._url
1254
+ );
1255
+ this.connect();
1259
1256
  }
1260
1257
  };
1261
1258
 
@@ -1284,9 +1281,7 @@ var RunwareServer = class extends RunwareBase {
1284
1281
  }
1285
1282
  };
1286
1283
  this._sdkType = "SERVER" /* SERVER */;
1287
- if (props.apiKey) {
1288
- this.connect();
1289
- }
1284
+ this.connect();
1290
1285
  }
1291
1286
  // protected addListener({
1292
1287
  // lis,
@@ -1348,7 +1343,7 @@ var RunwareServer = class extends RunwareBase {
1348
1343
  lis: (m) => {
1349
1344
  var _a, _b;
1350
1345
  if (m == null ? void 0 : m.error) {
1351
- this._invalidAPIkey = "Invalid API key";
1346
+ this._invalidAPIkey = m;
1352
1347
  return;
1353
1348
  }
1354
1349
  this._connectionSessionUUID = (_b = (_a = m == null ? void 0 : m["authentication" /* AUTHENTICATION */]) == null ? void 0 : _a[0]) == null ? void 0 : _b.connectionSessionUUID;
@@ -1371,8 +1366,6 @@ var RunwareServer = class extends RunwareBase {
1371
1366
  }
1372
1367
  handleClose() {
1373
1368
  if (this._invalidAPIkey) {
1374
- console.error(this._invalidAPIkey);
1375
- return;
1376
1369
  }
1377
1370
  if (this._reconnectingIntervalId) {
1378
1371
  clearInterval(this._reconnectingIntervalId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runware/sdk-js",
3
- "version": "1.1.17-beta.2",
3
+ "version": "1.1.17-beta.4",
4
4
  "description": "The SDK is used to run image inference with the Runware API, powered by the RunWare inference platform. It can be used to generate imaged with text-to-image and image-to-image. It also allows the use of an existing gallery of models or selecting any model or LoRA from the CivitAI gallery. The API also supports upscaling, background removal, inpainting and outpainting, and a series of other ControlNet models.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
package/readme.md CHANGED
@@ -32,13 +32,31 @@ const runware = new Runware({ apiKey: "API_KEY" });
32
32
  const runware = new RunwareServer({ apiKey: "API_KEY" });
33
33
  ```
34
34
 
35
- | Parameter | Type | Use |
36
- | ---------------- | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
37
- | url | string | Url to get images from (optional) |
38
- | apiKey | string | The environment api key |
39
- | shouldReconnect | boolean `(default = true)` | This handles reconnection when there is websocket inactivity |
40
- | globalMaxRetries | number `(default = 2)` | The number of retries it should make before throwing an error `(NB: you can specify a retry parameters for every request that overrides the global retry)` |
41
- | timeOutDuration | number `(default = 60000)` | The timeout span per retry before timing out |
35
+ | Parameter | Type | Use |
36
+ | ---------------- | -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
37
+ | url | string | Url to get images from (optional) |
38
+ | apiKey | string | The environment api key |
39
+ | shouldReconnect | boolean `(default = true)` | This handles reconnection when there is websocket inactivity |
40
+ | globalMaxRetries | number `(default = 2)` | The number of retries it should make before throwing an error `(NB: you can specify a retry parameters for every request that overrides the global retry)` |
41
+ | timeoutDuration | number (in milliseconds) `(default = 60000)` | The timeout span per retry before timing out |
42
+
43
+ ## Methods
44
+
45
+ ### Ensure connection is established before making request
46
+
47
+ ```js
48
+ const runware = new RunwareServer({ apiKey: "API_KEY" });
49
+
50
+ await runware.ensureConnection();
51
+ ```
52
+
53
+ ### Manually disconnect
54
+
55
+ ```js
56
+ const runware = new RunwareServer({ apiKey: "API_KEY" });
57
+
58
+ await runware.disconnect();
59
+ ```
42
60
 
43
61
  ## API
44
62
 
@@ -375,7 +393,7 @@ return interface IControlNetImage {
375
393
  **Added or Changed**
376
394
 
377
395
  - Add Global Max Retry and Retry count per request
378
- - Add Timeout duration
396
+ - Add Global timeout duration
379
397
 
380
398
  ### - v1.1.16/v1.1.17
381
399