@runware/sdk-js 1.1.10 → 1.1.12

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,48 +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
- disconnect: () => void;
309
- connected: () => boolean;
278
+ private getSimilarImages;
279
+ private getSingleMessage;
280
+ private handleIncompleteImages;
281
+ disconnect: () => Promise<void>;
282
+ private connected;
310
283
  }
311
284
 
312
- declare class Runware extends RunwareBase {
285
+ declare class RunwareClient extends RunwareBase {
313
286
  constructor({ apiKey, url }: RunwareBaseType);
314
287
  }
315
288
 
@@ -326,4 +299,6 @@ declare class RunwareServer extends RunwareBase {
326
299
  protected heartBeat(): void;
327
300
  }
328
301
 
329
- 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,48 +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
- disconnect: () => void;
309
- connected: () => boolean;
278
+ private getSimilarImages;
279
+ private getSingleMessage;
280
+ private handleIncompleteImages;
281
+ disconnect: () => Promise<void>;
282
+ private connected;
310
283
  }
311
284
 
312
- declare class Runware extends RunwareBase {
285
+ declare class RunwareClient extends RunwareBase {
313
286
  constructor({ apiKey, url }: RunwareBaseType);
314
287
  }
315
288
 
@@ -326,4 +299,6 @@ declare class RunwareServer extends RunwareBase {
326
299
  protected heartBeat(): void;
327
300
  }
328
301
 
329
- 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
  });
@@ -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
@@ -655,7 +650,7 @@ var RunwareBase = class {
655
650
  }
656
651
  if (newRemoveBackground) {
657
652
  delete this._globalMessages[taskUUID];
658
- resolve([newRemoveBackground]);
653
+ resolve(newRemoveBackground);
659
654
  return true;
660
655
  }
661
656
  },
@@ -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,
@@ -704,7 +697,7 @@ var RunwareBase = class {
704
697
  }
705
698
  if (newUpscaleGan) {
706
699
  delete this._globalMessages[taskUUID];
707
- resolve([newUpscaleGan]);
700
+ resolve(newUpscaleGan);
708
701
  return true;
709
702
  }
710
703
  },
@@ -762,12 +755,13 @@ 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;
769
763
  };
770
- this.disconnect = () => {
764
+ this.disconnect = async () => {
771
765
  var _a, _b, _c, _d;
772
766
  (_b = (_a = this._ws) == null ? void 0 : _a.terminate) == null ? void 0 : _b.call(_a);
773
767
  (_d = (_c = this._ws) == null ? void 0 : _c.close) == null ? void 0 : _d.call(_c);
@@ -971,7 +965,6 @@ var RunwareBase = class {
971
965
  numberResults = 1,
972
966
  controlNet,
973
967
  lora,
974
- useCache,
975
968
  onPartialImages,
976
969
  includeCost,
977
970
  customTaskUUID,
@@ -1012,15 +1005,9 @@ var RunwareBase = class {
1012
1005
  endStepPercentage,
1013
1006
  model: controlNetModel
1014
1007
  } = controlData;
1015
- if (!guideImage)
1016
- return;
1017
- const imageUploaded = await this.uploadImage(
1018
- guideImage
1019
- );
1020
- if (!imageUploaded)
1021
- return;
1008
+ const imageUploaded = guideImage ? await this.uploadImage(guideImage) : null;
1022
1009
  controlNetData.push(__spreadProps(__spreadValues(__spreadValues({
1023
- guideImage: imageUploaded.imageUUID,
1010
+ guideImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID,
1024
1011
  model: controlNetModel,
1025
1012
  endStep,
1026
1013
  startStep,
@@ -1036,7 +1023,7 @@ var RunwareBase = class {
1036
1023
  }));
1037
1024
  }
1038
1025
  }
1039
- 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({
1040
1027
  taskType: "imageInference" /* IMAGE_INFERENCE */,
1041
1028
  model,
1042
1029
  positivePrompt
@@ -1045,7 +1032,7 @@ var RunwareBase = class {
1045
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({
1046
1033
  key: "usePromptWeighting",
1047
1034
  value: usePromptWeighting
1048
- })), 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 } : {});
1049
1036
  return await asyncRetry(
1050
1037
  async () => {
1051
1038
  retryCount++;
@@ -1104,7 +1091,7 @@ var RunwareBase = class {
1104
1091
  throw this._invalidAPIkey;
1105
1092
  return new Promise((resolve, reject) => {
1106
1093
  let retry = 0;
1107
- const MAX_RETRY = 10;
1094
+ const MAX_RETRY = 30;
1108
1095
  let retryIntervalId;
1109
1096
  let pollingIntervalId;
1110
1097
  const clearAllIntervals = () => {
@@ -1201,9 +1188,9 @@ var RunwareBase = class {
1201
1188
  //end of data
1202
1189
  };
1203
1190
 
1204
- // Runware/Runware.ts
1191
+ // Runware/Runware-client.ts
1205
1192
  var import_reconnect = __toESM(require_reconnect());
1206
- var Runware = class extends RunwareBase {
1193
+ var RunwareClient = class extends RunwareBase {
1207
1194
  constructor({ apiKey, url }) {
1208
1195
  super({ apiKey, url });
1209
1196
  if (apiKey) {
@@ -1330,6 +1317,14 @@ var RunwareServer = class extends RunwareBase {
1330
1317
  }
1331
1318
  //end of data
1332
1319
  };
1320
+
1321
+ // Runware/Runware.ts
1322
+ var Runware;
1323
+ if (typeof window === "undefined") {
1324
+ Runware = RunwareServer;
1325
+ } else {
1326
+ Runware = RunwareClient;
1327
+ }
1333
1328
  // Annotate the CommonJS export names for ESM import in node:
1334
1329
  0 && (module.exports = {
1335
1330
  EControlMode,
@@ -1339,6 +1334,7 @@ var RunwareServer = class extends RunwareBase {
1339
1334
  ETaskType,
1340
1335
  Environment,
1341
1336
  Runware,
1337
+ RunwareClient,
1342
1338
  RunwareServer,
1343
1339
  SdkType
1344
1340
  });
package/dist/index.mjs CHANGED
@@ -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
@@ -634,7 +628,7 @@ var RunwareBase = class {
634
628
  }
635
629
  if (newRemoveBackground) {
636
630
  delete this._globalMessages[taskUUID];
637
- resolve([newRemoveBackground]);
631
+ resolve(newRemoveBackground);
638
632
  return true;
639
633
  }
640
634
  },
@@ -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,
@@ -683,7 +675,7 @@ var RunwareBase = class {
683
675
  }
684
676
  if (newUpscaleGan) {
685
677
  delete this._globalMessages[taskUUID];
686
- resolve([newUpscaleGan]);
678
+ resolve(newUpscaleGan);
687
679
  return true;
688
680
  }
689
681
  },
@@ -741,12 +733,13 @@ 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;
748
741
  };
749
- this.disconnect = () => {
742
+ this.disconnect = async () => {
750
743
  var _a, _b, _c, _d;
751
744
  (_b = (_a = this._ws) == null ? void 0 : _a.terminate) == null ? void 0 : _b.call(_a);
752
745
  (_d = (_c = this._ws) == null ? void 0 : _c.close) == null ? void 0 : _d.call(_c);
@@ -950,7 +943,6 @@ var RunwareBase = class {
950
943
  numberResults = 1,
951
944
  controlNet,
952
945
  lora,
953
- useCache,
954
946
  onPartialImages,
955
947
  includeCost,
956
948
  customTaskUUID,
@@ -991,15 +983,9 @@ var RunwareBase = class {
991
983
  endStepPercentage,
992
984
  model: controlNetModel
993
985
  } = controlData;
994
- if (!guideImage)
995
- return;
996
- const imageUploaded = await this.uploadImage(
997
- guideImage
998
- );
999
- if (!imageUploaded)
1000
- return;
986
+ const imageUploaded = guideImage ? await this.uploadImage(guideImage) : null;
1001
987
  controlNetData.push(__spreadProps(__spreadValues(__spreadValues({
1002
- guideImage: imageUploaded.imageUUID,
988
+ guideImage: imageUploaded == null ? void 0 : imageUploaded.imageUUID,
1003
989
  model: controlNetModel,
1004
990
  endStep,
1005
991
  startStep,
@@ -1015,7 +1001,7 @@ var RunwareBase = class {
1015
1001
  }));
1016
1002
  }
1017
1003
  }
1018
- 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({
1019
1005
  taskType: "imageInference" /* IMAGE_INFERENCE */,
1020
1006
  model,
1021
1007
  positivePrompt
@@ -1024,7 +1010,7 @@ var RunwareBase = class {
1024
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({
1025
1011
  key: "usePromptWeighting",
1026
1012
  value: usePromptWeighting
1027
- })), 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 } : {});
1028
1014
  return await asyncRetry(
1029
1015
  async () => {
1030
1016
  retryCount++;
@@ -1083,7 +1069,7 @@ var RunwareBase = class {
1083
1069
  throw this._invalidAPIkey;
1084
1070
  return new Promise((resolve, reject) => {
1085
1071
  let retry = 0;
1086
- const MAX_RETRY = 10;
1072
+ const MAX_RETRY = 30;
1087
1073
  let retryIntervalId;
1088
1074
  let pollingIntervalId;
1089
1075
  const clearAllIntervals = () => {
@@ -1180,9 +1166,9 @@ var RunwareBase = class {
1180
1166
  //end of data
1181
1167
  };
1182
1168
 
1183
- // Runware/Runware.ts
1169
+ // Runware/Runware-client.ts
1184
1170
  var import_reconnect = __toESM(require_reconnect());
1185
- var Runware = class extends RunwareBase {
1171
+ var RunwareClient = class extends RunwareBase {
1186
1172
  constructor({ apiKey, url }) {
1187
1173
  super({ apiKey, url });
1188
1174
  if (apiKey) {
@@ -1309,6 +1295,14 @@ var RunwareServer = class extends RunwareBase {
1309
1295
  }
1310
1296
  //end of data
1311
1297
  };
1298
+
1299
+ // Runware/Runware.ts
1300
+ var Runware;
1301
+ if (typeof window === "undefined") {
1302
+ Runware = RunwareServer;
1303
+ } else {
1304
+ Runware = RunwareClient;
1305
+ }
1312
1306
  export {
1313
1307
  EControlMode,
1314
1308
  EOpenPosePreProcessor,
@@ -1317,6 +1311,7 @@ export {
1317
1311
  ETaskType,
1318
1312
  Environment,
1319
1313
  Runware,
1314
+ RunwareClient,
1320
1315
  RunwareServer,
1321
1316
  SdkType
1322
1317
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runware/sdk-js",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
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
@@ -62,7 +62,7 @@ const images = await runware.requestImages({
62
62
  maskImage?: File | string;
63
63
  strength?: number;
64
64
  steps?: number;
65
- schedular?: string;
65
+ scheduler?: string;
66
66
  seed?: number;
67
67
  CFGScale?: number;
68
68
  clipSkip?: number;
@@ -70,10 +70,6 @@ const images = await runware.requestImages({
70
70
  controlNet?: IControlNet[];
71
71
  lora?: ILora[];
72
72
  retry?: number;
73
-
74
-
75
- useCache?: boolean;
76
- returnBase64Image?: boolean;
77
73
  onPartialImages?: (images: IImage[], error: IError) => void;
78
74
  })
79
75
 
@@ -364,6 +360,19 @@ return interface IControlNetImage {
364
360
 
365
361
  ## Changelog
366
362
 
363
+ ### - v1.1.12
364
+
365
+ **Added or Changed**
366
+
367
+ - Fix imageUpscale and backgroundRemoval wrong response
368
+
369
+ ### - v1.1.11
370
+
371
+ **Added or Changed**
372
+
373
+ - Automatically detect environment with Runware class
374
+ - Fix invalid input image not returning server errors
375
+
367
376
  ### - v1.1.10
368
377
 
369
378
  **Added or Changed**