@runware/sdk-js 1.1.1 → 1.1.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.d.mts CHANGED
@@ -279,7 +279,7 @@ declare class RunwareBase {
279
279
  removeImageBackground: ({ inputImage, outputType, outputFormat, rgba, postProcessMask, returnOnlyMask, alphaMatting, alphaMattingForegroundThreshold, alphaMattingBackgroundThreshold, alphaMattingErodeSize, includeCost, }: IRemoveImageBackground) => Promise<IRemoveImage[]>;
280
280
  upscaleGan: ({ inputImage, upscaleFactor, outputType, outputFormat, includeCost, }: IUpscaleGan) => Promise<IImage[]>;
281
281
  enhancePrompt: ({ prompt, promptMaxLength, promptVersions, includeCost, }: IPromptEnhancer) => Promise<IEnhancedPrompt[]>;
282
- ensureConnection(): Promise<void>;
282
+ ensureConnection(): Promise<unknown>;
283
283
  getSimilarImages({ taskUUID, numberResults, shouldThrowError, lis, }: {
284
284
  taskUUID: string | string[];
285
285
  numberResults: number;
package/dist/index.d.ts CHANGED
@@ -279,7 +279,7 @@ declare class RunwareBase {
279
279
  removeImageBackground: ({ inputImage, outputType, outputFormat, rgba, postProcessMask, returnOnlyMask, alphaMatting, alphaMattingForegroundThreshold, alphaMattingBackgroundThreshold, alphaMattingErodeSize, includeCost, }: IRemoveImageBackground) => Promise<IRemoveImage[]>;
280
280
  upscaleGan: ({ inputImage, upscaleFactor, outputType, outputFormat, includeCost, }: IUpscaleGan) => Promise<IImage[]>;
281
281
  enhancePrompt: ({ prompt, promptMaxLength, promptVersions, includeCost, }: IPromptEnhancer) => Promise<IEnhancedPrompt[]>;
282
- ensureConnection(): Promise<void>;
282
+ ensureConnection(): Promise<unknown>;
283
283
  getSimilarImages({ taskUUID, numberResults, shouldThrowError, lis, }: {
284
284
  taskUUID: string | string[];
285
285
  numberResults: number;
package/dist/index.js CHANGED
@@ -1068,9 +1068,34 @@ var RunwareBase = class {
1068
1068
  async ensureConnection() {
1069
1069
  var _a;
1070
1070
  let isConnected = this.connected();
1071
+ if (isConnected)
1072
+ return;
1073
+ const interval = 2e3;
1071
1074
  try {
1072
1075
  if (this._invalidAPIkey)
1073
1076
  throw this._invalidAPIkey;
1077
+ return new Promise((resolve, reject) => {
1078
+ let retry = 0;
1079
+ const MAX_RETRY = 2;
1080
+ const intervalId = setInterval(async () => {
1081
+ try {
1082
+ const hasConnected = this.connected();
1083
+ if (hasConnected) {
1084
+ clearInterval(intervalId);
1085
+ resolve(true);
1086
+ } else if (retry >= MAX_RETRY) {
1087
+ clearInterval(intervalId);
1088
+ reject(new Error("Polling timed out"));
1089
+ } else {
1090
+ this.connect();
1091
+ retry++;
1092
+ }
1093
+ } catch (error) {
1094
+ clearInterval(intervalId);
1095
+ reject(error);
1096
+ }
1097
+ }, interval);
1098
+ });
1074
1099
  if (!isConnected) {
1075
1100
  this.connect();
1076
1101
  await delay(2);
@@ -1211,6 +1236,20 @@ var RunwareServer = class extends RunwareBase {
1211
1236
  });
1212
1237
  }
1213
1238
  }
1239
+ this.addListener({
1240
+ taskUUID: "authentication" /* AUTHENTICATION */,
1241
+ lis: (m) => {
1242
+ var _a, _b;
1243
+ if (m == null ? void 0 : m.error) {
1244
+ if (m.errorId === 19) {
1245
+ this._invalidAPIkey = "Invalid API key";
1246
+ }
1247
+ return;
1248
+ }
1249
+ this._connectionSessionUUID = (_b = (_a = m == null ? void 0 : m["authentication" /* AUTHENTICATION */]) == null ? void 0 : _a[0]) == null ? void 0 : _b.connectionSessionUUID;
1250
+ this._invalidAPIkey = void 0;
1251
+ }
1252
+ });
1214
1253
  });
1215
1254
  this._ws.on("message", (e, isBinary) => {
1216
1255
  const data = isBinary ? e : e == null ? void 0 : e.toString();
package/dist/index.mjs CHANGED
@@ -1047,9 +1047,34 @@ var RunwareBase = class {
1047
1047
  async ensureConnection() {
1048
1048
  var _a;
1049
1049
  let isConnected = this.connected();
1050
+ if (isConnected)
1051
+ return;
1052
+ const interval = 2e3;
1050
1053
  try {
1051
1054
  if (this._invalidAPIkey)
1052
1055
  throw this._invalidAPIkey;
1056
+ return new Promise((resolve, reject) => {
1057
+ let retry = 0;
1058
+ const MAX_RETRY = 2;
1059
+ const intervalId = setInterval(async () => {
1060
+ try {
1061
+ const hasConnected = this.connected();
1062
+ if (hasConnected) {
1063
+ clearInterval(intervalId);
1064
+ resolve(true);
1065
+ } else if (retry >= MAX_RETRY) {
1066
+ clearInterval(intervalId);
1067
+ reject(new Error("Polling timed out"));
1068
+ } else {
1069
+ this.connect();
1070
+ retry++;
1071
+ }
1072
+ } catch (error) {
1073
+ clearInterval(intervalId);
1074
+ reject(error);
1075
+ }
1076
+ }, interval);
1077
+ });
1053
1078
  if (!isConnected) {
1054
1079
  this.connect();
1055
1080
  await delay(2);
@@ -1190,6 +1215,20 @@ var RunwareServer = class extends RunwareBase {
1190
1215
  });
1191
1216
  }
1192
1217
  }
1218
+ this.addListener({
1219
+ taskUUID: "authentication" /* AUTHENTICATION */,
1220
+ lis: (m) => {
1221
+ var _a, _b;
1222
+ if (m == null ? void 0 : m.error) {
1223
+ if (m.errorId === 19) {
1224
+ this._invalidAPIkey = "Invalid API key";
1225
+ }
1226
+ return;
1227
+ }
1228
+ this._connectionSessionUUID = (_b = (_a = m == null ? void 0 : m["authentication" /* AUTHENTICATION */]) == null ? void 0 : _a[0]) == null ? void 0 : _b.connectionSessionUUID;
1229
+ this._invalidAPIkey = void 0;
1230
+ }
1231
+ });
1193
1232
  });
1194
1233
  this._ws.on("message", (e, isBinary) => {
1195
1234
  const data = isBinary ? e : e == null ? void 0 : e.toString();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runware/sdk-js",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
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",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "uuid": "^9.0.1",
36
- "ws": "^8.14.2"
36
+ "ws": "^8.18.0"
37
37
  },
38
38
  "optionalDependencies": {
39
39
  "bufferutil": "^4.0.8"
package/readme.md CHANGED
@@ -356,10 +356,17 @@ return interface IControlNetImage {
356
356
 
357
357
  ## Changelog
358
358
 
359
+ ### - v1.1.2
360
+
361
+ **Added or Changed**
362
+
363
+ - Retry connection for server side
364
+
359
365
  ### - v1.1.1
360
366
 
361
367
  **Added or Changed**
362
368
 
369
+ - Upgraded WS
363
370
  - Fix delay time
364
371
 
365
372
  ### - v1.1.0