@runware/sdk-js 1.1.9 → 1.1.11

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
@@ -81,7 +81,7 @@ type IControlNetPreprocess = {
81
81
  };
82
82
  type IControlNet = IControlNetGeneral;
83
83
  type IControlNetWithUUID = Omit<IControlNet, "guideImage"> & {
84
- guideImage: string;
84
+ guideImage?: string;
85
85
  };
86
86
  interface IError {
87
87
  error: boolean;
@@ -112,7 +112,6 @@ interface IRequestImage {
112
112
  lora?: ILora[];
113
113
  includeCost?: boolean;
114
114
  customTaskUUID?: string;
115
- useCache?: boolean;
116
115
  onPartialImages?: (images: IImage[], error?: IError) => void;
117
116
  retry?: number;
118
117
  }
@@ -243,10 +242,6 @@ type ListenerType = {
243
242
  groupKey?: string;
244
243
  };
245
244
 
246
- declare enum LISTEN_TO_IMAGES_KEY {
247
- REQUEST_IMAGES = "REQUEST_IMAGES"
248
- }
249
-
250
245
  declare class RunwareBase {
251
246
  _ws: ReconnectingWebsocketProps | any;
252
247
  _listeners: ListenerType[];
@@ -268,47 +263,26 @@ declare class RunwareBase {
268
263
  destroy: () => void;
269
264
  };
270
265
  protected connect(): void;
271
- protected send: (msg: Object) => any;
266
+ protected send: (msg: Object) => void;
272
267
  private destroy;
273
268
  private uploadImage;
274
- listenToImages({ onPartialImages, taskUUID, groupKey, positivePrompt, negativePrompt, }: {
275
- taskUUID: string;
276
- onPartialImages?: (images: IImage[], error?: any) => void;
277
- groupKey: LISTEN_TO_IMAGES_KEY;
278
- positivePrompt?: string;
279
- negativePrompt?: string;
280
- }): {
281
- destroy: () => void;
282
- };
283
- globalListener({ taskUUID }: {
284
- taskUUID: string;
285
- }): {
286
- destroy: () => void;
287
- };
288
- requestImages({ outputType, outputFormat, uploadEndpoint, checkNsfw, positivePrompt, negativePrompt, seedImage, maskImage, strength, height, width, model, steps, scheduler, seed, CFGScale, clipSkip, usePromptWeighting, numberResults, controlNet, lora, useCache, onPartialImages, includeCost, customTaskUUID, retry, }: IRequestImage): Promise<ITextToImage[] | undefined>;
269
+ private listenToImages;
270
+ private globalListener;
271
+ requestImages({ outputType, outputFormat, uploadEndpoint, checkNsfw, positivePrompt, negativePrompt, seedImage, maskImage, strength, height, width, model, steps, scheduler, seed, CFGScale, clipSkip, usePromptWeighting, numberResults, controlNet, lora, onPartialImages, includeCost, customTaskUUID, retry, }: IRequestImage): Promise<ITextToImage[] | undefined>;
289
272
  controlNetPreProcess: ({ inputImage, preProcessor, height, width, outputType, outputFormat, highThresholdCanny, lowThresholdCanny, includeHandsAndFaceOpenPose, includeCost, customTaskUUID, }: IControlNetPreprocess) => Promise<IControlNetImage | null>;
290
273
  requestImageToText: ({ inputImage, includeCost, customTaskUUID, }: IRequestImageToText) => Promise<IImageToText>;
291
274
  removeImageBackground: ({ inputImage, outputType, outputFormat, rgba, postProcessMask, returnOnlyMask, alphaMatting, alphaMattingForegroundThreshold, alphaMattingBackgroundThreshold, alphaMattingErodeSize, includeCost, customTaskUUID, }: IRemoveImageBackground) => Promise<IRemoveImage[]>;
292
275
  upscaleGan: ({ inputImage, upscaleFactor, outputType, outputFormat, includeCost, customTaskUUID, }: IUpscaleGan) => Promise<IImage[]>;
293
276
  enhancePrompt: ({ prompt, promptMaxLength, promptVersions, includeCost, customTaskUUID, }: IPromptEnhancer) => Promise<IEnhancedPrompt[]>;
294
277
  ensureConnection(): Promise<unknown>;
295
- getSimilarImages({ taskUUID, numberResults, shouldThrowError, lis, }: {
296
- taskUUID: string | string[];
297
- numberResults: number;
298
- shouldThrowError?: boolean;
299
- lis: any;
300
- }): Promise<IImage[] | IError>;
301
- getSingleMessage: ({ taskUUID }: {
302
- taskUUID: string;
303
- }) => any;
304
- handleIncompleteImages({ taskUUIDs, error, }: {
305
- taskUUIDs: string[];
306
- error: any;
307
- }): IImage[];
308
- connected: () => boolean;
278
+ private getSimilarImages;
279
+ private getSingleMessage;
280
+ private handleIncompleteImages;
281
+ disconnect: () => Promise<void>;
282
+ private connected;
309
283
  }
310
284
 
311
- declare class Runware extends RunwareBase {
285
+ declare class RunwareClient extends RunwareBase {
312
286
  constructor({ apiKey, url }: RunwareBaseType);
313
287
  }
314
288
 
@@ -325,4 +299,6 @@ declare class RunwareServer extends RunwareBase {
325
299
  protected heartBeat(): void;
326
300
  }
327
301
 
328
- export { EControlMode, EOpenPosePreProcessor, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, GetWithPromiseCallBackType, IControlNet, IControlNetGeneral, IControlNetImage, IControlNetPreprocess, IControlNetWithUUID, IEnhancedPrompt, IError, IImage, IImageToText, IOutputFormat, IOutputType, IPromptEnhancer, IRemoveImage, IRemoveImageBackground, IRequestImage, IRequestImageToText, ITextToImage, IUpscaleGan, ListenerType, ReconnectingWebsocketProps, RequireAtLeastOne, RequireOnlyOne, Runware, RunwareBaseType, RunwareServer, SdkType, UploadImageType };
302
+ declare let Runware: any;
303
+
304
+ export { EControlMode, EOpenPosePreProcessor, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, GetWithPromiseCallBackType, IControlNet, IControlNetGeneral, IControlNetImage, IControlNetPreprocess, IControlNetWithUUID, IEnhancedPrompt, IError, IImage, IImageToText, IOutputFormat, IOutputType, IPromptEnhancer, IRemoveImage, IRemoveImageBackground, IRequestImage, IRequestImageToText, ITextToImage, IUpscaleGan, ListenerType, ReconnectingWebsocketProps, RequireAtLeastOne, RequireOnlyOne, Runware, RunwareBaseType, RunwareClient, RunwareServer, SdkType, UploadImageType };
package/dist/index.d.ts CHANGED
@@ -81,7 +81,7 @@ type IControlNetPreprocess = {
81
81
  };
82
82
  type IControlNet = IControlNetGeneral;
83
83
  type IControlNetWithUUID = Omit<IControlNet, "guideImage"> & {
84
- guideImage: string;
84
+ guideImage?: string;
85
85
  };
86
86
  interface IError {
87
87
  error: boolean;
@@ -112,7 +112,6 @@ interface IRequestImage {
112
112
  lora?: ILora[];
113
113
  includeCost?: boolean;
114
114
  customTaskUUID?: string;
115
- useCache?: boolean;
116
115
  onPartialImages?: (images: IImage[], error?: IError) => void;
117
116
  retry?: number;
118
117
  }
@@ -243,10 +242,6 @@ type ListenerType = {
243
242
  groupKey?: string;
244
243
  };
245
244
 
246
- declare enum LISTEN_TO_IMAGES_KEY {
247
- REQUEST_IMAGES = "REQUEST_IMAGES"
248
- }
249
-
250
245
  declare class RunwareBase {
251
246
  _ws: ReconnectingWebsocketProps | any;
252
247
  _listeners: ListenerType[];
@@ -268,47 +263,26 @@ declare class RunwareBase {
268
263
  destroy: () => void;
269
264
  };
270
265
  protected connect(): void;
271
- protected send: (msg: Object) => any;
266
+ protected send: (msg: Object) => void;
272
267
  private destroy;
273
268
  private uploadImage;
274
- listenToImages({ onPartialImages, taskUUID, groupKey, positivePrompt, negativePrompt, }: {
275
- taskUUID: string;
276
- onPartialImages?: (images: IImage[], error?: any) => void;
277
- groupKey: LISTEN_TO_IMAGES_KEY;
278
- positivePrompt?: string;
279
- negativePrompt?: string;
280
- }): {
281
- destroy: () => void;
282
- };
283
- globalListener({ taskUUID }: {
284
- taskUUID: string;
285
- }): {
286
- destroy: () => void;
287
- };
288
- requestImages({ outputType, outputFormat, uploadEndpoint, checkNsfw, positivePrompt, negativePrompt, seedImage, maskImage, strength, height, width, model, steps, scheduler, seed, CFGScale, clipSkip, usePromptWeighting, numberResults, controlNet, lora, useCache, onPartialImages, includeCost, customTaskUUID, retry, }: IRequestImage): Promise<ITextToImage[] | undefined>;
269
+ private listenToImages;
270
+ private globalListener;
271
+ requestImages({ outputType, outputFormat, uploadEndpoint, checkNsfw, positivePrompt, negativePrompt, seedImage, maskImage, strength, height, width, model, steps, scheduler, seed, CFGScale, clipSkip, usePromptWeighting, numberResults, controlNet, lora, onPartialImages, includeCost, customTaskUUID, retry, }: IRequestImage): Promise<ITextToImage[] | undefined>;
289
272
  controlNetPreProcess: ({ inputImage, preProcessor, height, width, outputType, outputFormat, highThresholdCanny, lowThresholdCanny, includeHandsAndFaceOpenPose, includeCost, customTaskUUID, }: IControlNetPreprocess) => Promise<IControlNetImage | null>;
290
273
  requestImageToText: ({ inputImage, includeCost, customTaskUUID, }: IRequestImageToText) => Promise<IImageToText>;
291
274
  removeImageBackground: ({ inputImage, outputType, outputFormat, rgba, postProcessMask, returnOnlyMask, alphaMatting, alphaMattingForegroundThreshold, alphaMattingBackgroundThreshold, alphaMattingErodeSize, includeCost, customTaskUUID, }: IRemoveImageBackground) => Promise<IRemoveImage[]>;
292
275
  upscaleGan: ({ inputImage, upscaleFactor, outputType, outputFormat, includeCost, customTaskUUID, }: IUpscaleGan) => Promise<IImage[]>;
293
276
  enhancePrompt: ({ prompt, promptMaxLength, promptVersions, includeCost, customTaskUUID, }: IPromptEnhancer) => Promise<IEnhancedPrompt[]>;
294
277
  ensureConnection(): Promise<unknown>;
295
- getSimilarImages({ taskUUID, numberResults, shouldThrowError, lis, }: {
296
- taskUUID: string | string[];
297
- numberResults: number;
298
- shouldThrowError?: boolean;
299
- lis: any;
300
- }): Promise<IImage[] | IError>;
301
- getSingleMessage: ({ taskUUID }: {
302
- taskUUID: string;
303
- }) => any;
304
- handleIncompleteImages({ taskUUIDs, error, }: {
305
- taskUUIDs: string[];
306
- error: any;
307
- }): IImage[];
308
- connected: () => boolean;
278
+ private getSimilarImages;
279
+ private getSingleMessage;
280
+ private handleIncompleteImages;
281
+ disconnect: () => Promise<void>;
282
+ private connected;
309
283
  }
310
284
 
311
- declare class Runware extends RunwareBase {
285
+ declare class RunwareClient extends RunwareBase {
312
286
  constructor({ apiKey, url }: RunwareBaseType);
313
287
  }
314
288
 
@@ -325,4 +299,6 @@ declare class RunwareServer extends RunwareBase {
325
299
  protected heartBeat(): void;
326
300
  }
327
301
 
328
- export { EControlMode, EOpenPosePreProcessor, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, GetWithPromiseCallBackType, IControlNet, IControlNetGeneral, IControlNetImage, IControlNetPreprocess, IControlNetWithUUID, IEnhancedPrompt, IError, IImage, IImageToText, IOutputFormat, IOutputType, IPromptEnhancer, IRemoveImage, IRemoveImageBackground, IRequestImage, IRequestImageToText, ITextToImage, IUpscaleGan, ListenerType, ReconnectingWebsocketProps, RequireAtLeastOne, RequireOnlyOne, Runware, RunwareBaseType, RunwareServer, SdkType, UploadImageType };
302
+ declare let Runware: any;
303
+
304
+ export { EControlMode, EOpenPosePreProcessor, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, GetWithPromiseCallBackType, IControlNet, IControlNetGeneral, IControlNetImage, IControlNetPreprocess, IControlNetWithUUID, IEnhancedPrompt, IError, IImage, IImageToText, IOutputFormat, IOutputType, IPromptEnhancer, IRemoveImage, IRemoveImageBackground, IRequestImage, IRequestImageToText, ITextToImage, IUpscaleGan, ListenerType, ReconnectingWebsocketProps, RequireAtLeastOne, RequireOnlyOne, Runware, RunwareBaseType, RunwareClient, RunwareServer, SdkType, UploadImageType };
package/dist/index.js CHANGED
@@ -227,6 +227,7 @@ __export(Runware_exports, {
227
227
  ETaskType: () => ETaskType,
228
228
  Environment: () => Environment,
229
229
  Runware: () => Runware,
230
+ RunwareClient: () => RunwareClient,
230
231
  RunwareServer: () => RunwareServer,
231
232
  SdkType: () => SdkType
232
233
  });
@@ -339,13 +340,6 @@ var getIntervalWithPromise = (callback, {
339
340
  shouldThrowError = true
340
341
  }) => {
341
342
  return new Promise((resolve, reject) => {
342
- let intervalId = setInterval(async () => {
343
- const shouldClear = callback({ resolve, reject, intervalId });
344
- if (shouldClear) {
345
- clearInterval(intervalId);
346
- intervalId = 0;
347
- }
348
- }, POLLING_INTERVAL);
349
343
  const timeoutId = setTimeout(() => {
350
344
  if (intervalId) {
351
345
  clearInterval(intervalId);
@@ -356,6 +350,13 @@ var getIntervalWithPromise = (callback, {
356
350
  }
357
351
  clearTimeout(timeoutId);
358
352
  }, timeOutDuration);
353
+ let intervalId = setInterval(async () => {
354
+ const shouldClear = callback({ resolve, reject, intervalId });
355
+ if (shouldClear) {
356
+ clearInterval(intervalId);
357
+ clearTimeout(timeoutId);
358
+ }
359
+ }, POLLING_INTERVAL);
359
360
  });
360
361
  };
361
362
  var fileToBase64 = (file) => new Promise((resolve) => {
@@ -445,7 +446,9 @@ var RunwareBase = class {
445
446
  return ((_a = this._ws) == null ? void 0 : _a.readyState) === 1;
446
447
  };
447
448
  // We moving to an array format, it make sense to consolidate all request to an array here
448
- this.send = (msg) => this._ws.send(JSON.stringify([msg]));
449
+ this.send = (msg) => {
450
+ this._ws.send(JSON.stringify([msg]));
451
+ };
449
452
  this.uploadImage = async (file) => {
450
453
  try {
451
454
  return await asyncRetry(async () => {
@@ -561,16 +564,12 @@ var RunwareBase = class {
561
564
  try {
562
565
  await this.ensureConnection();
563
566
  return await asyncRetry(async () => {
564
- const imageUploaded = await this.uploadImage(
565
- inputImage
566
- );
567
- if (!(imageUploaded == null ? void 0 : imageUploaded.imageUUID))
568
- return null;
567
+ const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
569
568
  const taskUUID = customTaskUUID || getUUID();
570
569
  this.send(__spreadValues({
571
570
  taskUUID,
572
571
  taskType: "imageCaption" /* IMAGE_CAPTION */,
573
- inputImage: imageUploaded.imageUUID
572
+ inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
574
573
  }, evaluateNonTrue({ key: "includeCost", value: includeCost })));
575
574
  const lis = this.globalListener({
576
575
  taskUUID
@@ -618,16 +617,12 @@ var RunwareBase = class {
618
617
  try {
619
618
  await this.ensureConnection();
620
619
  return await asyncRetry(async () => {
621
- const imageUploaded = await this.uploadImage(
622
- inputImage
623
- );
624
- if (!(imageUploaded == null ? void 0 : imageUploaded.imageUUID))
625
- return null;
620
+ const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
626
621
  const taskUUID = customTaskUUID || getUUID();
627
622
  this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
628
623
  taskType: "imageBackgroundRemoval" /* IMAGE_BACKGROUND_REMOVAL */,
629
624
  taskUUID,
630
- inputImage: imageUploaded.imageUUID
625
+ inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
631
626
  }, evaluateNonTrue({ key: "rgba", value: rgba })), evaluateNonTrue({
632
627
  key: "postProcessMask",
633
628
  value: postProcessMask
@@ -681,8 +676,6 @@ var RunwareBase = class {
681
676
  return await asyncRetry(async () => {
682
677
  let imageUploaded;
683
678
  imageUploaded = await this.uploadImage(inputImage);
684
- if (!(imageUploaded == null ? void 0 : imageUploaded.imageUUID))
685
- return null;
686
679
  const taskUUID = customTaskUUID || getUUID();
687
680
  this.send(__spreadValues(__spreadValues(__spreadValues({
688
681
  taskUUID,
@@ -762,10 +755,16 @@ var RunwareBase = class {
762
755
  }
763
756
  };
764
757
  this.getSingleMessage = ({ taskUUID }) => {
765
- var _a, _b;
766
- if (!((_a = this._globalMessages[taskUUID]) == null ? void 0 : _a[0]))
758
+ var _a;
759
+ const value = this._globalMessages[taskUUID] || ((_a = this._globalMessages[taskUUID]) == null ? void 0 : _a[0]);
760
+ if (!value)
767
761
  return null;
768
- return (_b = this._globalMessages[taskUUID]) == null ? void 0 : _b[0];
762
+ return value;
763
+ };
764
+ this.disconnect = async () => {
765
+ var _a, _b, _c, _d;
766
+ (_b = (_a = this._ws) == null ? void 0 : _a.terminate) == null ? void 0 : _b.call(_a);
767
+ (_d = (_c = this._ws) == null ? void 0 : _c.close) == null ? void 0 : _d.call(_c);
769
768
  };
770
769
  this.connected = () => this.isWebsocketReadyState() && !!this._connectionSessionUUID;
771
770
  this._apiKey = apiKey;
@@ -966,7 +965,6 @@ var RunwareBase = class {
966
965
  numberResults = 1,
967
966
  controlNet,
968
967
  lora,
969
- useCache,
970
968
  onPartialImages,
971
969
  includeCost,
972
970
  customTaskUUID,
@@ -1007,15 +1005,9 @@ var RunwareBase = class {
1007
1005
  endStepPercentage,
1008
1006
  model: controlNetModel
1009
1007
  } = controlData;
1010
- if (!guideImage)
1011
- return;
1012
- const imageUploaded = await this.uploadImage(
1013
- guideImage
1014
- );
1015
- if (!imageUploaded)
1016
- return;
1008
+ const imageUploaded = guideImage ? await this.uploadImage(guideImage) : null;
1017
1009
  controlNetData.push(__spreadProps(__spreadValues(__spreadValues({
1018
- guideImage: imageUploaded.imageUUID,
1010
+ guideImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID,
1019
1011
  model: controlNetModel,
1020
1012
  endStep,
1021
1013
  startStep,
@@ -1031,7 +1023,7 @@ var RunwareBase = class {
1031
1023
  }));
1032
1024
  }
1033
1025
  }
1034
- requestObject = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues(__spreadValues(__spreadValues({
1026
+ requestObject = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues(__spreadValues(__spreadValues({
1035
1027
  taskType: "imageInference" /* IMAGE_INFERENCE */,
1036
1028
  model,
1037
1029
  positivePrompt
@@ -1040,7 +1032,7 @@ var RunwareBase = class {
1040
1032
  }), (lora == null ? void 0 : lora.length) ? { lora } : {}), outputType ? { outputType } : {}), outputFormat ? { outputFormat } : {}), uploadEndpoint ? { uploadEndpoint } : {}), evaluateNonTrue({ key: "checkNsfw", value: checkNsfw })), evaluateNonTrue({ key: "strength", value: strength })), evaluateNonTrue({ key: "CFGScale", value: CFGScale })), evaluateNonTrue({ key: "clipSkip", value: clipSkip })), evaluateNonTrue({
1041
1033
  key: "usePromptWeighting",
1042
1034
  value: usePromptWeighting
1043
- })), evaluateNonTrue({ key: "steps", value: steps })), controlNetData.length ? { controlNet: controlNetData } : {}), seed ? { seed } : {}), scheduler ? { scheduler } : {}), evaluateNonTrue({ key: "includeCost", value: includeCost })), evaluateNonTrue({ key: "useCache", value: useCache })), seedImageUUID ? { seedImage: seedImageUUID } : {}), maskImageUUID ? { maskImage: maskImageUUID } : {});
1035
+ })), evaluateNonTrue({ key: "steps", value: steps })), controlNetData.length ? { controlNet: controlNetData } : {}), seed ? { seed } : {}), scheduler ? { scheduler } : {}), evaluateNonTrue({ key: "includeCost", value: includeCost })), seedImageUUID ? { seedImage: seedImageUUID } : {}), maskImageUUID ? { maskImage: maskImageUUID } : {});
1044
1036
  return await asyncRetry(
1045
1037
  async () => {
1046
1038
  retryCount++;
@@ -1068,6 +1060,7 @@ var RunwareBase = class {
1068
1060
  numberResults,
1069
1061
  lis
1070
1062
  });
1063
+ lis.destroy();
1071
1064
  return promise;
1072
1065
  },
1073
1066
  {
@@ -1098,7 +1091,7 @@ var RunwareBase = class {
1098
1091
  throw this._invalidAPIkey;
1099
1092
  return new Promise((resolve, reject) => {
1100
1093
  let retry = 0;
1101
- const MAX_RETRY = 10;
1094
+ const MAX_RETRY = 30;
1102
1095
  let retryIntervalId;
1103
1096
  let pollingIntervalId;
1104
1097
  const clearAllIntervals = () => {
@@ -1195,9 +1188,9 @@ var RunwareBase = class {
1195
1188
  //end of data
1196
1189
  };
1197
1190
 
1198
- // Runware/Runware.ts
1191
+ // Runware/Runware-client.ts
1199
1192
  var import_reconnect = __toESM(require_reconnect());
1200
- var Runware = class extends RunwareBase {
1193
+ var RunwareClient = class extends RunwareBase {
1201
1194
  constructor({ apiKey, url }) {
1202
1195
  super({ apiKey, url });
1203
1196
  if (apiKey) {
@@ -1258,7 +1251,9 @@ var RunwareServer = class extends RunwareBase {
1258
1251
  });
1259
1252
  this._ws.on("error", () => {
1260
1253
  });
1261
- this._ws.on("close", () => this.handleClose());
1254
+ this._ws.on("close", () => {
1255
+ this.handleClose();
1256
+ });
1262
1257
  this._ws.on("open", () => {
1263
1258
  if (this._reconnectingIntervalId) {
1264
1259
  clearInterval(this._reconnectingIntervalId);
@@ -1311,7 +1306,6 @@ var RunwareServer = class extends RunwareBase {
1311
1306
  if (this._reconnectingIntervalId) {
1312
1307
  clearInterval(this._reconnectingIntervalId);
1313
1308
  }
1314
- this._reconnectingIntervalId = setInterval(() => this.connect(), 1e3);
1315
1309
  }
1316
1310
  heartBeat() {
1317
1311
  clearTimeout(this._pingTimeout);
@@ -1323,6 +1317,14 @@ var RunwareServer = class extends RunwareBase {
1323
1317
  }
1324
1318
  //end of data
1325
1319
  };
1320
+
1321
+ // Runware/Runware.ts
1322
+ var Runware;
1323
+ if (typeof window === "undefined") {
1324
+ Runware = RunwareServer;
1325
+ } else {
1326
+ Runware = RunwareClient;
1327
+ }
1326
1328
  // Annotate the CommonJS export names for ESM import in node:
1327
1329
  0 && (module.exports = {
1328
1330
  EControlMode,
@@ -1332,6 +1334,7 @@ var RunwareServer = class extends RunwareBase {
1332
1334
  ETaskType,
1333
1335
  Environment,
1334
1336
  Runware,
1337
+ RunwareClient,
1335
1338
  RunwareServer,
1336
1339
  SdkType
1337
1340
  });
package/dist/index.mjs CHANGED
@@ -318,13 +318,6 @@ var getIntervalWithPromise = (callback, {
318
318
  shouldThrowError = true
319
319
  }) => {
320
320
  return new Promise((resolve, reject) => {
321
- let intervalId = setInterval(async () => {
322
- const shouldClear = callback({ resolve, reject, intervalId });
323
- if (shouldClear) {
324
- clearInterval(intervalId);
325
- intervalId = 0;
326
- }
327
- }, POLLING_INTERVAL);
328
321
  const timeoutId = setTimeout(() => {
329
322
  if (intervalId) {
330
323
  clearInterval(intervalId);
@@ -335,6 +328,13 @@ var getIntervalWithPromise = (callback, {
335
328
  }
336
329
  clearTimeout(timeoutId);
337
330
  }, timeOutDuration);
331
+ let intervalId = setInterval(async () => {
332
+ const shouldClear = callback({ resolve, reject, intervalId });
333
+ if (shouldClear) {
334
+ clearInterval(intervalId);
335
+ clearTimeout(timeoutId);
336
+ }
337
+ }, POLLING_INTERVAL);
338
338
  });
339
339
  };
340
340
  var fileToBase64 = (file) => new Promise((resolve) => {
@@ -424,7 +424,9 @@ var RunwareBase = class {
424
424
  return ((_a = this._ws) == null ? void 0 : _a.readyState) === 1;
425
425
  };
426
426
  // We moving to an array format, it make sense to consolidate all request to an array here
427
- this.send = (msg) => this._ws.send(JSON.stringify([msg]));
427
+ this.send = (msg) => {
428
+ this._ws.send(JSON.stringify([msg]));
429
+ };
428
430
  this.uploadImage = async (file) => {
429
431
  try {
430
432
  return await asyncRetry(async () => {
@@ -540,16 +542,12 @@ var RunwareBase = class {
540
542
  try {
541
543
  await this.ensureConnection();
542
544
  return await asyncRetry(async () => {
543
- const imageUploaded = await this.uploadImage(
544
- inputImage
545
- );
546
- if (!(imageUploaded == null ? void 0 : imageUploaded.imageUUID))
547
- return null;
545
+ const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
548
546
  const taskUUID = customTaskUUID || getUUID();
549
547
  this.send(__spreadValues({
550
548
  taskUUID,
551
549
  taskType: "imageCaption" /* IMAGE_CAPTION */,
552
- inputImage: imageUploaded.imageUUID
550
+ inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
553
551
  }, evaluateNonTrue({ key: "includeCost", value: includeCost })));
554
552
  const lis = this.globalListener({
555
553
  taskUUID
@@ -597,16 +595,12 @@ var RunwareBase = class {
597
595
  try {
598
596
  await this.ensureConnection();
599
597
  return await asyncRetry(async () => {
600
- const imageUploaded = await this.uploadImage(
601
- inputImage
602
- );
603
- if (!(imageUploaded == null ? void 0 : imageUploaded.imageUUID))
604
- return null;
598
+ const imageUploaded = inputImage ? await this.uploadImage(inputImage) : null;
605
599
  const taskUUID = customTaskUUID || getUUID();
606
600
  this.send(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
607
601
  taskType: "imageBackgroundRemoval" /* IMAGE_BACKGROUND_REMOVAL */,
608
602
  taskUUID,
609
- inputImage: imageUploaded.imageUUID
603
+ inputImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID
610
604
  }, evaluateNonTrue({ key: "rgba", value: rgba })), evaluateNonTrue({
611
605
  key: "postProcessMask",
612
606
  value: postProcessMask
@@ -660,8 +654,6 @@ var RunwareBase = class {
660
654
  return await asyncRetry(async () => {
661
655
  let imageUploaded;
662
656
  imageUploaded = await this.uploadImage(inputImage);
663
- if (!(imageUploaded == null ? void 0 : imageUploaded.imageUUID))
664
- return null;
665
657
  const taskUUID = customTaskUUID || getUUID();
666
658
  this.send(__spreadValues(__spreadValues(__spreadValues({
667
659
  taskUUID,
@@ -741,10 +733,16 @@ var RunwareBase = class {
741
733
  }
742
734
  };
743
735
  this.getSingleMessage = ({ taskUUID }) => {
744
- var _a, _b;
745
- if (!((_a = this._globalMessages[taskUUID]) == null ? void 0 : _a[0]))
736
+ var _a;
737
+ const value = this._globalMessages[taskUUID] || ((_a = this._globalMessages[taskUUID]) == null ? void 0 : _a[0]);
738
+ if (!value)
746
739
  return null;
747
- return (_b = this._globalMessages[taskUUID]) == null ? void 0 : _b[0];
740
+ return value;
741
+ };
742
+ this.disconnect = async () => {
743
+ var _a, _b, _c, _d;
744
+ (_b = (_a = this._ws) == null ? void 0 : _a.terminate) == null ? void 0 : _b.call(_a);
745
+ (_d = (_c = this._ws) == null ? void 0 : _c.close) == null ? void 0 : _d.call(_c);
748
746
  };
749
747
  this.connected = () => this.isWebsocketReadyState() && !!this._connectionSessionUUID;
750
748
  this._apiKey = apiKey;
@@ -945,7 +943,6 @@ var RunwareBase = class {
945
943
  numberResults = 1,
946
944
  controlNet,
947
945
  lora,
948
- useCache,
949
946
  onPartialImages,
950
947
  includeCost,
951
948
  customTaskUUID,
@@ -986,15 +983,9 @@ var RunwareBase = class {
986
983
  endStepPercentage,
987
984
  model: controlNetModel
988
985
  } = controlData;
989
- if (!guideImage)
990
- return;
991
- const imageUploaded = await this.uploadImage(
992
- guideImage
993
- );
994
- if (!imageUploaded)
995
- return;
986
+ const imageUploaded = guideImage ? await this.uploadImage(guideImage) : null;
996
987
  controlNetData.push(__spreadProps(__spreadValues(__spreadValues({
997
- guideImage: imageUploaded.imageUUID,
988
+ guideImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID,
998
989
  model: controlNetModel,
999
990
  endStep,
1000
991
  startStep,
@@ -1010,7 +1001,7 @@ var RunwareBase = class {
1010
1001
  }));
1011
1002
  }
1012
1003
  }
1013
- requestObject = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues(__spreadValues(__spreadValues({
1004
+ requestObject = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues(__spreadValues(__spreadValues({
1014
1005
  taskType: "imageInference" /* IMAGE_INFERENCE */,
1015
1006
  model,
1016
1007
  positivePrompt
@@ -1019,7 +1010,7 @@ var RunwareBase = class {
1019
1010
  }), (lora == null ? void 0 : lora.length) ? { lora } : {}), outputType ? { outputType } : {}), outputFormat ? { outputFormat } : {}), uploadEndpoint ? { uploadEndpoint } : {}), evaluateNonTrue({ key: "checkNsfw", value: checkNsfw })), evaluateNonTrue({ key: "strength", value: strength })), evaluateNonTrue({ key: "CFGScale", value: CFGScale })), evaluateNonTrue({ key: "clipSkip", value: clipSkip })), evaluateNonTrue({
1020
1011
  key: "usePromptWeighting",
1021
1012
  value: usePromptWeighting
1022
- })), evaluateNonTrue({ key: "steps", value: steps })), controlNetData.length ? { controlNet: controlNetData } : {}), seed ? { seed } : {}), scheduler ? { scheduler } : {}), evaluateNonTrue({ key: "includeCost", value: includeCost })), evaluateNonTrue({ key: "useCache", value: useCache })), seedImageUUID ? { seedImage: seedImageUUID } : {}), maskImageUUID ? { maskImage: maskImageUUID } : {});
1013
+ })), evaluateNonTrue({ key: "steps", value: steps })), controlNetData.length ? { controlNet: controlNetData } : {}), seed ? { seed } : {}), scheduler ? { scheduler } : {}), evaluateNonTrue({ key: "includeCost", value: includeCost })), seedImageUUID ? { seedImage: seedImageUUID } : {}), maskImageUUID ? { maskImage: maskImageUUID } : {});
1023
1014
  return await asyncRetry(
1024
1015
  async () => {
1025
1016
  retryCount++;
@@ -1047,6 +1038,7 @@ var RunwareBase = class {
1047
1038
  numberResults,
1048
1039
  lis
1049
1040
  });
1041
+ lis.destroy();
1050
1042
  return promise;
1051
1043
  },
1052
1044
  {
@@ -1077,7 +1069,7 @@ var RunwareBase = class {
1077
1069
  throw this._invalidAPIkey;
1078
1070
  return new Promise((resolve, reject) => {
1079
1071
  let retry = 0;
1080
- const MAX_RETRY = 10;
1072
+ const MAX_RETRY = 30;
1081
1073
  let retryIntervalId;
1082
1074
  let pollingIntervalId;
1083
1075
  const clearAllIntervals = () => {
@@ -1174,9 +1166,9 @@ var RunwareBase = class {
1174
1166
  //end of data
1175
1167
  };
1176
1168
 
1177
- // Runware/Runware.ts
1169
+ // Runware/Runware-client.ts
1178
1170
  var import_reconnect = __toESM(require_reconnect());
1179
- var Runware = class extends RunwareBase {
1171
+ var RunwareClient = class extends RunwareBase {
1180
1172
  constructor({ apiKey, url }) {
1181
1173
  super({ apiKey, url });
1182
1174
  if (apiKey) {
@@ -1237,7 +1229,9 @@ var RunwareServer = class extends RunwareBase {
1237
1229
  });
1238
1230
  this._ws.on("error", () => {
1239
1231
  });
1240
- this._ws.on("close", () => this.handleClose());
1232
+ this._ws.on("close", () => {
1233
+ this.handleClose();
1234
+ });
1241
1235
  this._ws.on("open", () => {
1242
1236
  if (this._reconnectingIntervalId) {
1243
1237
  clearInterval(this._reconnectingIntervalId);
@@ -1290,7 +1284,6 @@ var RunwareServer = class extends RunwareBase {
1290
1284
  if (this._reconnectingIntervalId) {
1291
1285
  clearInterval(this._reconnectingIntervalId);
1292
1286
  }
1293
- this._reconnectingIntervalId = setInterval(() => this.connect(), 1e3);
1294
1287
  }
1295
1288
  heartBeat() {
1296
1289
  clearTimeout(this._pingTimeout);
@@ -1302,6 +1295,14 @@ var RunwareServer = class extends RunwareBase {
1302
1295
  }
1303
1296
  //end of data
1304
1297
  };
1298
+
1299
+ // Runware/Runware.ts
1300
+ var Runware;
1301
+ if (typeof window === "undefined") {
1302
+ Runware = RunwareServer;
1303
+ } else {
1304
+ Runware = RunwareClient;
1305
+ }
1305
1306
  export {
1306
1307
  EControlMode,
1307
1308
  EOpenPosePreProcessor,
@@ -1310,6 +1311,7 @@ export {
1310
1311
  ETaskType,
1311
1312
  Environment,
1312
1313
  Runware,
1314
+ RunwareClient,
1313
1315
  RunwareServer,
1314
1316
  SdkType
1315
1317
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runware/sdk-js",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
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",