@runware/sdk-js 1.1.18 → 1.1.20-beta.1

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.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __defProps = Object.defineProperties;
@@ -37,10 +36,6 @@ var __objRest = (source, exclude) => {
37
36
  var __commonJS = (cb, mod) => function __require() {
38
37
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
39
38
  };
40
- var __export = (target, all) => {
41
- for (var name in all)
42
- __defProp(target, name, { get: all[name], enumerable: true });
43
- };
44
39
  var __copyProps = (to, from, except, desc) => {
45
40
  if (from && typeof from === "object" || typeof from === "function") {
46
41
  for (let key of __getOwnPropNames(from))
@@ -57,11 +52,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
57
52
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
58
53
  mod
59
54
  ));
60
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
61
55
 
62
56
  // Runware/reconnect.ts
63
57
  var require_reconnect = __commonJS({
64
- "Runware/reconnect.ts"(exports, module2) {
58
+ "Runware/reconnect.ts"(exports, module) {
65
59
  "use strict";
66
60
  var isWebSocket = (constructor) => constructor && constructor.CLOSING === 2;
67
61
  var isGlobalWebSocket = () => typeof WebSocket !== "undefined" && isWebSocket(WebSocket);
@@ -225,26 +219,10 @@ var require_reconnect = __commonJS({
225
219
  ws.removeEventListener(type, listener, options2);
226
220
  };
227
221
  };
228
- module2.exports = ReconnectingWebsocket2;
222
+ module.exports = ReconnectingWebsocket2;
229
223
  }
230
224
  });
231
225
 
232
- // Runware/index.ts
233
- var Runware_exports = {};
234
- __export(Runware_exports, {
235
- EControlMode: () => EControlMode,
236
- EOpenPosePreProcessor: () => EOpenPosePreProcessor,
237
- EPreProcessor: () => EPreProcessor,
238
- EPreProcessorGroup: () => EPreProcessorGroup,
239
- ETaskType: () => ETaskType,
240
- Environment: () => Environment,
241
- Runware: () => Runware,
242
- RunwareClient: () => RunwareClient,
243
- RunwareServer: () => RunwareServer,
244
- SdkType: () => SdkType
245
- });
246
- module.exports = __toCommonJS(Runware_exports);
247
-
248
226
  // Runware/types.ts
249
227
  var Environment = /* @__PURE__ */ ((Environment2) => {
250
228
  Environment2["PRODUCTION"] = "PRODUCTION";
@@ -266,6 +244,7 @@ var ETaskType = /* @__PURE__ */ ((ETaskType2) => {
266
244
  ETaskType2["IMAGE_CONTROL_NET_PRE_PROCESS"] = "imageControlNetPreProcess";
267
245
  ETaskType2["PROMPT_ENHANCE"] = "promptEnhance";
268
246
  ETaskType2["AUTHENTICATION"] = "authentication";
247
+ ETaskType2["MODEL_UPLOAD"] = "modelUpload";
269
248
  return ETaskType2;
270
249
  })(ETaskType || {});
271
250
  var EControlMode = /* @__PURE__ */ ((EControlMode2) => {
@@ -329,7 +308,7 @@ var EOpenPosePreProcessor = /* @__PURE__ */ ((EOpenPosePreProcessor2) => {
329
308
  })(EOpenPosePreProcessor || {});
330
309
 
331
310
  // Runware/utils.ts
332
- var import_uuid = require("uuid");
311
+ import { v4 as uuidv4, validate as validateUUID } from "uuid";
333
312
  var TIMEOUT_DURATION = 6e4;
334
313
  var MINIMUM_TIMEOUT_DURATION = 1e3;
335
314
  var POLLING_INTERVAL = 100;
@@ -379,8 +358,8 @@ var fileToBase64 = (file) => new Promise((resolve) => {
379
358
  resolve(reader.result);
380
359
  };
381
360
  });
382
- var getUUID = () => (0, import_uuid.v4)();
383
- var isValidUUID = (uuid) => (0, import_uuid.validate)(uuid);
361
+ var getUUID = () => uuidv4();
362
+ var isValidUUID = (uuid) => validateUUID(uuid);
384
363
  var accessDeepObject = ({
385
364
  key,
386
365
  data,
@@ -494,7 +473,7 @@ var RunwareBase = class {
494
473
  };
495
474
  this.controlNetPreProcess = async ({
496
475
  inputImage,
497
- preProcessor,
476
+ preProcessorType,
498
477
  height,
499
478
  width,
500
479
  outputType,
@@ -520,7 +499,7 @@ var RunwareBase = class {
520
499
  inputImage: image.imageUUID,
521
500
  taskType: "imageControlNetPreProcess" /* IMAGE_CONTROL_NET_PRE_PROCESS */,
522
501
  taskUUID,
523
- preProcessor
502
+ preProcessorType
524
503
  }, evaluateNonTrue({ key: "height", value: height })), evaluateNonTrue({ key: "width", value: width })), evaluateNonTrue({ key: "outputType", value: outputType })), evaluateNonTrue({ key: "outputFormat", value: outputFormat })), evaluateNonTrue({ key: "includeCost", value: includeCost })), evaluateNonTrue({
525
504
  key: "highThresholdCanny",
526
505
  value: highThresholdCanny
@@ -823,6 +802,54 @@ var RunwareBase = class {
823
802
  throw e;
824
803
  }
825
804
  };
805
+ this.modelUpload = async (payload) => {
806
+ const _a = payload, { onUploadStream, retry, customTaskUUID } = _a, addModelPayload = __objRest(_a, ["onUploadStream", "retry", "customTaskUUID"]);
807
+ const totalRetry = retry || this._globalMaxRetries;
808
+ let lis = void 0;
809
+ try {
810
+ return await asyncRetry(
811
+ async () => {
812
+ await this.ensureConnection();
813
+ const taskUUID = customTaskUUID || getUUID();
814
+ this.send(__spreadProps(__spreadValues({}, addModelPayload), {
815
+ taskUUID,
816
+ taskType: "modelUpload" /* MODEL_UPLOAD */
817
+ }));
818
+ let result;
819
+ lis = this.listenToUpload({
820
+ taskUUID,
821
+ onUploadStream: (response, error) => {
822
+ onUploadStream == null ? void 0 : onUploadStream(response, error);
823
+ if ((response == null ? void 0 : response.statusId) === 1 || error) {
824
+ result = response || error;
825
+ }
826
+ }
827
+ });
828
+ const modelUploadResponse = await getIntervalWithPromise(
829
+ ({ resolve }) => {
830
+ if (result) {
831
+ resolve(result);
832
+ return true;
833
+ }
834
+ },
835
+ {
836
+ shouldThrowError: false,
837
+ timeoutDuration: 60 * 60 * 1e3
838
+ }
839
+ );
840
+ return modelUploadResponse;
841
+ },
842
+ {
843
+ maxRetries: totalRetry,
844
+ callback: () => {
845
+ lis == null ? void 0 : lis.destroy();
846
+ }
847
+ }
848
+ );
849
+ } catch (e) {
850
+ throw e;
851
+ }
852
+ };
826
853
  this.getSingleMessage = ({ taskUUID }) => {
827
854
  var _a;
828
855
  const value = (_a = this._globalMessages[taskUUID]) == null ? void 0 : _a[0];
@@ -880,9 +907,9 @@ var RunwareBase = class {
880
907
  taskUUID
881
908
  }) {
882
909
  const listener = (msg) => {
883
- var _a;
910
+ var _a, _b, _c;
884
911
  const arrayMessage = Array.isArray(msg == null ? void 0 : msg.data) ? msg.data : [msg.data];
885
- const arrayErrors = Array.isArray(msg == null ? void 0 : msg.errors) ? msg.errors : [msg.errors];
912
+ const arrayErrors = ((_a = msg == null ? void 0 : msg[0]) == null ? void 0 : _a.errors) ? (_b = msg == null ? void 0 : msg[0]) == null ? void 0 : _b.errors : Array.isArray(msg == null ? void 0 : msg.errors) ? msg.errors : [msg.errors];
886
913
  const filteredMessage = arrayMessage.filter(
887
914
  (v) => ((v == null ? void 0 : v.taskUUID) || (v == null ? void 0 : v.taskType)) === taskUUID
888
915
  );
@@ -890,7 +917,7 @@ var RunwareBase = class {
890
917
  (v) => ((v == null ? void 0 : v.taskUUID) || (v == null ? void 0 : v.taskType)) === taskUUID
891
918
  );
892
919
  if (filteredErrors.length) {
893
- lis({ error: __spreadValues({}, (_a = arrayErrors[0]) != null ? _a : {}) });
920
+ lis({ error: __spreadValues({}, (_c = arrayErrors[0]) != null ? _c : {}) });
894
921
  return;
895
922
  }
896
923
  if (filteredMessage.length) {
@@ -898,7 +925,7 @@ var RunwareBase = class {
898
925
  return;
899
926
  }
900
927
  };
901
- const groupListener = { key: getUUID(), listener, groupKey };
928
+ const groupListener = { key: taskUUID || getUUID(), listener, groupKey };
902
929
  this._listeners.push(groupListener);
903
930
  const destroy = () => {
904
931
  this._listeners = removeListener(this._listeners, groupListener);
@@ -988,6 +1015,23 @@ var RunwareBase = class {
988
1015
  groupKey
989
1016
  });
990
1017
  }
1018
+ listenToUpload({
1019
+ onUploadStream,
1020
+ taskUUID
1021
+ }) {
1022
+ return this.addListener({
1023
+ taskUUID,
1024
+ lis: (m) => {
1025
+ var _a;
1026
+ const error = m == null ? void 0 : m.error;
1027
+ const result = (_a = m == null ? void 0 : m[taskUUID]) == null ? void 0 : _a[0];
1028
+ let response = (result == null ? void 0 : result.taskUUID) === taskUUID ? result : null;
1029
+ if (response || error) {
1030
+ onUploadStream == null ? void 0 : onUploadStream(response || void 0, error);
1031
+ }
1032
+ }
1033
+ });
1034
+ }
991
1035
  globalListener({ taskUUID }) {
992
1036
  return this.addListener({
993
1037
  // check: (m) => {
@@ -1274,7 +1318,7 @@ var RunwareBase = class {
1274
1318
  };
1275
1319
 
1276
1320
  // Runware/Runware-client.ts
1277
- var import_reconnect = __toESM(require_reconnect());
1321
+ var import_reconnect = __toESM(require_reconnect(), 1);
1278
1322
  var RunwareClient = class extends RunwareBase {
1279
1323
  constructor(props) {
1280
1324
  const _a = props, { shouldReconnect } = _a, rest = __objRest(_a, ["shouldReconnect"]);
@@ -1287,7 +1331,7 @@ var RunwareClient = class extends RunwareBase {
1287
1331
  };
1288
1332
 
1289
1333
  // Runware/Runware-server.ts
1290
- var import_ws = __toESM(require("ws"));
1334
+ import WebSocket2 from "ws";
1291
1335
  var RunwareServer = class extends RunwareBase {
1292
1336
  constructor(props) {
1293
1337
  super(props);
@@ -1342,7 +1386,7 @@ var RunwareServer = class extends RunwareBase {
1342
1386
  if (!this._url)
1343
1387
  return;
1344
1388
  this.resetConnection();
1345
- this._ws = new import_ws.default(this._url, {
1389
+ this._ws = new WebSocket2(this._url, {
1346
1390
  perMessageDeflate: false
1347
1391
  });
1348
1392
  this._ws.on("error", () => {
@@ -1423,8 +1467,7 @@ if (typeof window === "undefined") {
1423
1467
  } else {
1424
1468
  Runware = RunwareClient;
1425
1469
  }
1426
- // Annotate the CommonJS export names for ESM import in node:
1427
- 0 && (module.exports = {
1470
+ export {
1428
1471
  EControlMode,
1429
1472
  EOpenPosePreProcessor,
1430
1473
  EPreProcessor,
@@ -1435,4 +1478,4 @@ if (typeof window === "undefined") {
1435
1478
  RunwareClient,
1436
1479
  RunwareServer,
1437
1480
  SdkType
1438
- });
1481
+ };
package/dist/index.mjs CHANGED
@@ -244,6 +244,7 @@ var ETaskType = /* @__PURE__ */ ((ETaskType2) => {
244
244
  ETaskType2["IMAGE_CONTROL_NET_PRE_PROCESS"] = "imageControlNetPreProcess";
245
245
  ETaskType2["PROMPT_ENHANCE"] = "promptEnhance";
246
246
  ETaskType2["AUTHENTICATION"] = "authentication";
247
+ ETaskType2["MODEL_UPLOAD"] = "modelUpload";
247
248
  return ETaskType2;
248
249
  })(ETaskType || {});
249
250
  var EControlMode = /* @__PURE__ */ ((EControlMode2) => {
@@ -472,7 +473,7 @@ var RunwareBase = class {
472
473
  };
473
474
  this.controlNetPreProcess = async ({
474
475
  inputImage,
475
- preProcessor,
476
+ preProcessorType,
476
477
  height,
477
478
  width,
478
479
  outputType,
@@ -498,7 +499,7 @@ var RunwareBase = class {
498
499
  inputImage: image.imageUUID,
499
500
  taskType: "imageControlNetPreProcess" /* IMAGE_CONTROL_NET_PRE_PROCESS */,
500
501
  taskUUID,
501
- preProcessor
502
+ preProcessorType
502
503
  }, evaluateNonTrue({ key: "height", value: height })), evaluateNonTrue({ key: "width", value: width })), evaluateNonTrue({ key: "outputType", value: outputType })), evaluateNonTrue({ key: "outputFormat", value: outputFormat })), evaluateNonTrue({ key: "includeCost", value: includeCost })), evaluateNonTrue({
503
504
  key: "highThresholdCanny",
504
505
  value: highThresholdCanny
@@ -744,7 +745,7 @@ var RunwareBase = class {
744
745
  }
745
746
  };
746
747
  this.enhancePrompt = async ({
747
- prompt,
748
+ prompt: prompt2,
748
749
  promptMaxLength = 380,
749
750
  promptVersions = 1,
750
751
  includeCost,
@@ -759,7 +760,7 @@ var RunwareBase = class {
759
760
  await this.ensureConnection();
760
761
  const taskUUID = customTaskUUID || getUUID();
761
762
  this.send(__spreadProps(__spreadValues({
762
- prompt,
763
+ prompt: prompt2,
763
764
  taskUUID,
764
765
  promptMaxLength,
765
766
  promptVersions
@@ -801,6 +802,54 @@ var RunwareBase = class {
801
802
  throw e;
802
803
  }
803
804
  };
805
+ this.modelUpload = async (payload) => {
806
+ const _a = payload, { retry, customTaskUUID } = _a, addModelPayload = __objRest(_a, ["retry", "customTaskUUID"]);
807
+ const totalRetry = retry || this._globalMaxRetries;
808
+ let lis = void 0;
809
+ try {
810
+ return await asyncRetry(
811
+ async () => {
812
+ await this.ensureConnection();
813
+ const taskUUID = customTaskUUID || getUUID();
814
+ this.send(__spreadProps(__spreadValues({
815
+ prompt
816
+ }, addModelPayload), {
817
+ taskType: "modelUpload" /* MODEL_UPLOAD */
818
+ }));
819
+ lis = this.globalListener({
820
+ taskUUID
821
+ });
822
+ const response = await getIntervalWithPromise(
823
+ ({ resolve, reject }) => {
824
+ const modelUpload = this.getSingleMessage({ taskUUID });
825
+ if (!modelUpload)
826
+ return;
827
+ if (modelUpload == null ? void 0 : modelUpload.error) {
828
+ reject(modelUpload);
829
+ return true;
830
+ }
831
+ if (modelUpload) {
832
+ delete this._globalMessages[taskUUID];
833
+ resolve(modelUpload);
834
+ return true;
835
+ }
836
+ },
837
+ { debugKey: "modelUpload", timeoutDuration: this._timeoutDuration }
838
+ );
839
+ lis.destroy();
840
+ return response;
841
+ },
842
+ {
843
+ maxRetries: totalRetry,
844
+ callback: () => {
845
+ lis == null ? void 0 : lis.destroy();
846
+ }
847
+ }
848
+ );
849
+ } catch (e) {
850
+ throw e;
851
+ }
852
+ };
804
853
  this.getSingleMessage = ({ taskUUID }) => {
805
854
  var _a;
806
855
  const value = (_a = this._globalMessages[taskUUID]) == null ? void 0 : _a[0];
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@runware/sdk-js",
3
- "version": "1.1.18",
3
+ "version": "1.1.20-beta.1",
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",
7
7
  "types": "dist/index.d.ts",
8
+ "type": "module",
8
9
  "files": [
9
10
  "dist/"
10
11
  ],
@@ -14,7 +15,8 @@
14
15
  "pkg": "npx pkgfiles",
15
16
  "dev:test": "vitest --reporter verbose",
16
17
  "test": "vitest run --reporter verbose",
17
- "test:single": "vitest run --reporter verbose tests/Runware/upscale-gan.test.ts"
18
+ "test:single": "vitest run --reporter verbose tests/Runware/upscale-gan.test.ts",
19
+ "debug": "tsx tests/script.ts"
18
20
  },
19
21
  "keywords": [
20
22
  "runware",
@@ -26,6 +28,7 @@
26
28
  "devDependencies": {
27
29
  "@types/uuid": "^9.0.6",
28
30
  "@types/ws": "^8.5.8",
31
+ "dotenv": "^16.4.5",
29
32
  "mock-socket": "^9.3.1",
30
33
  "tsup": "^7.2.0",
31
34
  "typescript": "^5.2.2",
package/readme.md CHANGED
@@ -231,7 +231,7 @@ return interface IImageToText {
231
231
 
232
232
  const runware = new Runware({ apiKey: "API_KEY" });
233
233
  const image = await runware.removeImageBackground({
234
- imageInitiator: string | File
234
+ inputImage: string | File
235
235
  outputType?: IOutputType;
236
236
  outputFormat?: IOutputFormat;
237
237
  rgba?: number[];
@@ -346,7 +346,7 @@ return interface IEnhancedPrompt {
346
346
  const runware = new Runware({ apiKey: "API_KEY" });
347
347
  const controlNetPreProcessed = await runware.controlNetPreProcess({
348
348
  inputImage: string | File;
349
- preProcessor: EPreProcessor;
349
+ preProcessorType: EPreProcessor;
350
350
  height?: number;
351
351
  width?: number;
352
352
  outputType?: IOutputType;
@@ -392,6 +392,13 @@ return interface IControlNetImage {
392
392
 
393
393
  ## Changelog
394
394
 
395
+ ### - v1.1.19
396
+
397
+ **Added or Changed**
398
+
399
+ - Fix Preprocessor type bug for controlnet
400
+ - Update readme
401
+
395
402
  ### - v1.1.18
396
403
 
397
404
  **Added or Changed**