@runware/sdk-js 1.1.6 → 1.1.8
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 +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +64 -32
- package/dist/index.mjs +64 -32
- package/package.json +1 -1
- package/readme.md +26 -4
package/dist/index.d.mts
CHANGED
|
@@ -34,6 +34,10 @@ interface IImage {
|
|
|
34
34
|
NSFWContent?: boolean;
|
|
35
35
|
cost?: number;
|
|
36
36
|
}
|
|
37
|
+
interface ITextToImage extends IImage {
|
|
38
|
+
positivePrompt?: string;
|
|
39
|
+
negativePrompt?: string;
|
|
40
|
+
}
|
|
37
41
|
interface IControlNetImage {
|
|
38
42
|
taskUUID: string;
|
|
39
43
|
inputImageUUID: string;
|
|
@@ -110,6 +114,7 @@ interface IRequestImage {
|
|
|
110
114
|
customTaskUUID?: string;
|
|
111
115
|
useCache?: boolean;
|
|
112
116
|
onPartialImages?: (images: IImage[], error?: IError) => void;
|
|
117
|
+
retry?: number;
|
|
113
118
|
}
|
|
114
119
|
interface IRequestImageToText {
|
|
115
120
|
inputImage?: File | string;
|
|
@@ -266,10 +271,12 @@ declare class RunwareBase {
|
|
|
266
271
|
protected send: (msg: Object) => any;
|
|
267
272
|
private destroy;
|
|
268
273
|
private uploadImage;
|
|
269
|
-
listenToImages({ onPartialImages, taskUUID, groupKey, }: {
|
|
274
|
+
listenToImages({ onPartialImages, taskUUID, groupKey, positivePrompt, negativePrompt, }: {
|
|
270
275
|
taskUUID: string;
|
|
271
276
|
onPartialImages?: (images: IImage[], error?: any) => void;
|
|
272
277
|
groupKey: LISTEN_TO_IMAGES_KEY;
|
|
278
|
+
positivePrompt?: string;
|
|
279
|
+
negativePrompt?: string;
|
|
273
280
|
}): {
|
|
274
281
|
destroy: () => void;
|
|
275
282
|
};
|
|
@@ -278,7 +285,7 @@ declare class RunwareBase {
|
|
|
278
285
|
}): {
|
|
279
286
|
destroy: () => void;
|
|
280
287
|
};
|
|
281
|
-
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, }: IRequestImage): Promise<
|
|
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>;
|
|
282
289
|
controlNetPreProcess: ({ inputImage, preProcessor, height, width, outputType, outputFormat, highThresholdCanny, lowThresholdCanny, includeHandsAndFaceOpenPose, includeCost, customTaskUUID, }: IControlNetPreprocess) => Promise<IControlNetImage | null>;
|
|
283
290
|
requestImageToText: ({ inputImage, includeCost, customTaskUUID, }: IRequestImageToText) => Promise<IImageToText>;
|
|
284
291
|
removeImageBackground: ({ inputImage, outputType, outputFormat, rgba, postProcessMask, returnOnlyMask, alphaMatting, alphaMattingForegroundThreshold, alphaMattingBackgroundThreshold, alphaMattingErodeSize, includeCost, customTaskUUID, }: IRemoveImageBackground) => Promise<IRemoveImage[]>;
|
|
@@ -318,4 +325,4 @@ declare class RunwareServer extends RunwareBase {
|
|
|
318
325
|
protected heartBeat(): void;
|
|
319
326
|
}
|
|
320
327
|
|
|
321
|
-
export { EControlMode, EOpenPosePreProcessor, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, GetWithPromiseCallBackType, IControlNet, IControlNetGeneral, IControlNetImage, IControlNetPreprocess, IControlNetWithUUID, IEnhancedPrompt, IError, IImage, IImageToText, IOutputFormat, IOutputType, IPromptEnhancer, IRemoveImage, IRemoveImageBackground, IRequestImage, IRequestImageToText, IUpscaleGan, ListenerType, ReconnectingWebsocketProps, RequireAtLeastOne, RequireOnlyOne, Runware, RunwareBaseType, RunwareServer, SdkType, UploadImageType };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,10 @@ interface IImage {
|
|
|
34
34
|
NSFWContent?: boolean;
|
|
35
35
|
cost?: number;
|
|
36
36
|
}
|
|
37
|
+
interface ITextToImage extends IImage {
|
|
38
|
+
positivePrompt?: string;
|
|
39
|
+
negativePrompt?: string;
|
|
40
|
+
}
|
|
37
41
|
interface IControlNetImage {
|
|
38
42
|
taskUUID: string;
|
|
39
43
|
inputImageUUID: string;
|
|
@@ -110,6 +114,7 @@ interface IRequestImage {
|
|
|
110
114
|
customTaskUUID?: string;
|
|
111
115
|
useCache?: boolean;
|
|
112
116
|
onPartialImages?: (images: IImage[], error?: IError) => void;
|
|
117
|
+
retry?: number;
|
|
113
118
|
}
|
|
114
119
|
interface IRequestImageToText {
|
|
115
120
|
inputImage?: File | string;
|
|
@@ -266,10 +271,12 @@ declare class RunwareBase {
|
|
|
266
271
|
protected send: (msg: Object) => any;
|
|
267
272
|
private destroy;
|
|
268
273
|
private uploadImage;
|
|
269
|
-
listenToImages({ onPartialImages, taskUUID, groupKey, }: {
|
|
274
|
+
listenToImages({ onPartialImages, taskUUID, groupKey, positivePrompt, negativePrompt, }: {
|
|
270
275
|
taskUUID: string;
|
|
271
276
|
onPartialImages?: (images: IImage[], error?: any) => void;
|
|
272
277
|
groupKey: LISTEN_TO_IMAGES_KEY;
|
|
278
|
+
positivePrompt?: string;
|
|
279
|
+
negativePrompt?: string;
|
|
273
280
|
}): {
|
|
274
281
|
destroy: () => void;
|
|
275
282
|
};
|
|
@@ -278,7 +285,7 @@ declare class RunwareBase {
|
|
|
278
285
|
}): {
|
|
279
286
|
destroy: () => void;
|
|
280
287
|
};
|
|
281
|
-
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, }: IRequestImage): Promise<
|
|
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>;
|
|
282
289
|
controlNetPreProcess: ({ inputImage, preProcessor, height, width, outputType, outputFormat, highThresholdCanny, lowThresholdCanny, includeHandsAndFaceOpenPose, includeCost, customTaskUUID, }: IControlNetPreprocess) => Promise<IControlNetImage | null>;
|
|
283
290
|
requestImageToText: ({ inputImage, includeCost, customTaskUUID, }: IRequestImageToText) => Promise<IImageToText>;
|
|
284
291
|
removeImageBackground: ({ inputImage, outputType, outputFormat, rgba, postProcessMask, returnOnlyMask, alphaMatting, alphaMattingForegroundThreshold, alphaMattingBackgroundThreshold, alphaMattingErodeSize, includeCost, customTaskUUID, }: IRemoveImageBackground) => Promise<IRemoveImage[]>;
|
|
@@ -318,4 +325,4 @@ declare class RunwareServer extends RunwareBase {
|
|
|
318
325
|
protected heartBeat(): void;
|
|
319
326
|
}
|
|
320
327
|
|
|
321
|
-
export { EControlMode, EOpenPosePreProcessor, EPreProcessor, EPreProcessorGroup, ETaskType, Environment, GetWithPromiseCallBackType, IControlNet, IControlNetGeneral, IControlNetImage, IControlNetPreprocess, IControlNetWithUUID, IEnhancedPrompt, IError, IImage, IImageToText, IOutputFormat, IOutputType, IPromptEnhancer, IRemoveImage, IRemoveImageBackground, IRequestImage, IRequestImageToText, IUpscaleGan, ListenerType, ReconnectingWebsocketProps, RequireAtLeastOne, RequireOnlyOne, Runware, RunwareBaseType, RunwareServer, SdkType, UploadImageType };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -842,9 +842,7 @@ var RunwareBase = class {
|
|
|
842
842
|
lis: (m) => {
|
|
843
843
|
var _a, _b;
|
|
844
844
|
if (m == null ? void 0 : m.error) {
|
|
845
|
-
|
|
846
|
-
this._invalidAPIkey = "Invalid API key";
|
|
847
|
-
}
|
|
845
|
+
this._invalidAPIkey = "Invalid API key";
|
|
848
846
|
return;
|
|
849
847
|
}
|
|
850
848
|
this._connectionSessionUUID = (_b = (_a = m == null ? void 0 : m["authentication" /* AUTHENTICATION */]) == null ? void 0 : _a[0]) == null ? void 0 : _b.connectionSessionUUID;
|
|
@@ -874,23 +872,32 @@ var RunwareBase = class {
|
|
|
874
872
|
listenToImages({
|
|
875
873
|
onPartialImages,
|
|
876
874
|
taskUUID,
|
|
877
|
-
groupKey
|
|
875
|
+
groupKey,
|
|
876
|
+
positivePrompt,
|
|
877
|
+
negativePrompt
|
|
878
878
|
}) {
|
|
879
879
|
return this.addListener({
|
|
880
880
|
taskUUID,
|
|
881
881
|
lis: (m) => {
|
|
882
882
|
var _a, _b;
|
|
883
|
-
|
|
883
|
+
let images = (_a = m == null ? void 0 : m[taskUUID]) == null ? void 0 : _a.filter(
|
|
884
884
|
(img) => img.taskUUID === taskUUID
|
|
885
885
|
);
|
|
886
886
|
onPartialImages == null ? void 0 : onPartialImages(images, (m == null ? void 0 : m.error) && m);
|
|
887
887
|
if (m.error) {
|
|
888
888
|
this._globalError = m;
|
|
889
889
|
} else {
|
|
890
|
+
images = images.map((image) => __spreadProps(__spreadValues({}, image), {
|
|
891
|
+
positivePrompt,
|
|
892
|
+
negativePrompt
|
|
893
|
+
}));
|
|
890
894
|
if (this._sdkType === "CLIENT" /* CLIENT */) {
|
|
891
895
|
this._globalImages = [
|
|
892
896
|
...this._globalImages,
|
|
893
|
-
...(_b = m == null ? void 0 : m[taskUUID]) != null ? _b : []
|
|
897
|
+
...((_b = m == null ? void 0 : m[taskUUID]) != null ? _b : []).map((image) => __spreadProps(__spreadValues({}, image), {
|
|
898
|
+
positivePrompt,
|
|
899
|
+
negativePrompt
|
|
900
|
+
}))
|
|
894
901
|
];
|
|
895
902
|
} else {
|
|
896
903
|
this._globalImages = [...this._globalImages, ...images];
|
|
@@ -961,8 +968,10 @@ var RunwareBase = class {
|
|
|
961
968
|
useCache,
|
|
962
969
|
onPartialImages,
|
|
963
970
|
includeCost,
|
|
964
|
-
customTaskUUID
|
|
971
|
+
customTaskUUID,
|
|
972
|
+
retry = 2
|
|
965
973
|
}) {
|
|
974
|
+
await this.ensureConnection();
|
|
966
975
|
let lis = void 0;
|
|
967
976
|
let requestObject = void 0;
|
|
968
977
|
let taskUUIDs = [];
|
|
@@ -1049,7 +1058,9 @@ var RunwareBase = class {
|
|
|
1049
1058
|
lis = this.listenToImages({
|
|
1050
1059
|
onPartialImages,
|
|
1051
1060
|
taskUUID,
|
|
1052
|
-
groupKey: "REQUEST_IMAGES" /* REQUEST_IMAGES
|
|
1061
|
+
groupKey: "REQUEST_IMAGES" /* REQUEST_IMAGES */,
|
|
1062
|
+
positivePrompt,
|
|
1063
|
+
negativePrompt
|
|
1053
1064
|
});
|
|
1054
1065
|
const promise = await this.getSimilarImages({
|
|
1055
1066
|
taskUUID: taskUUIDs,
|
|
@@ -1059,14 +1070,17 @@ var RunwareBase = class {
|
|
|
1059
1070
|
return promise;
|
|
1060
1071
|
},
|
|
1061
1072
|
{
|
|
1062
|
-
maxRetries:
|
|
1073
|
+
maxRetries: retry,
|
|
1063
1074
|
callback: () => {
|
|
1064
1075
|
lis == null ? void 0 : lis.destroy();
|
|
1065
1076
|
}
|
|
1066
1077
|
}
|
|
1067
1078
|
);
|
|
1068
1079
|
} catch (e) {
|
|
1069
|
-
if (
|
|
1080
|
+
if (e.taskUUID) {
|
|
1081
|
+
throw e;
|
|
1082
|
+
}
|
|
1083
|
+
if (retryCount >= retry) {
|
|
1070
1084
|
return this.handleIncompleteImages({ taskUUIDs, error: e });
|
|
1071
1085
|
}
|
|
1072
1086
|
}
|
|
@@ -1076,31 +1090,52 @@ var RunwareBase = class {
|
|
|
1076
1090
|
let isConnected = this.connected();
|
|
1077
1091
|
if (isConnected || this._url === BASE_RUNWARE_URLS.TEST)
|
|
1078
1092
|
return;
|
|
1079
|
-
const
|
|
1093
|
+
const retryInterval = 2e3;
|
|
1094
|
+
const pollingInterval = 200;
|
|
1080
1095
|
try {
|
|
1081
1096
|
if (this._invalidAPIkey)
|
|
1082
1097
|
throw this._invalidAPIkey;
|
|
1083
1098
|
return new Promise((resolve, reject) => {
|
|
1084
1099
|
let retry = 0;
|
|
1085
|
-
const MAX_RETRY =
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1100
|
+
const MAX_RETRY = 10;
|
|
1101
|
+
let retryIntervalId;
|
|
1102
|
+
let pollingIntervalId;
|
|
1103
|
+
const clearAllIntervals = () => {
|
|
1104
|
+
clearInterval(retryIntervalId);
|
|
1105
|
+
clearInterval(pollingIntervalId);
|
|
1106
|
+
};
|
|
1107
|
+
if (this._sdkType === "SERVER" /* SERVER */) {
|
|
1108
|
+
retryIntervalId = setInterval(async () => {
|
|
1109
|
+
try {
|
|
1110
|
+
const hasConnected = this.connected();
|
|
1111
|
+
if (hasConnected) {
|
|
1112
|
+
clearAllIntervals();
|
|
1113
|
+
resolve(true);
|
|
1114
|
+
} else if (retry >= MAX_RETRY) {
|
|
1115
|
+
clearAllIntervals();
|
|
1116
|
+
reject(new Error("Retry timed out"));
|
|
1117
|
+
} else {
|
|
1118
|
+
this.connect();
|
|
1119
|
+
retry++;
|
|
1120
|
+
}
|
|
1121
|
+
} catch (error) {
|
|
1122
|
+
clearAllIntervals();
|
|
1123
|
+
reject(error);
|
|
1098
1124
|
}
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1125
|
+
}, retryInterval);
|
|
1126
|
+
}
|
|
1127
|
+
pollingIntervalId = setInterval(async () => {
|
|
1128
|
+
const hasConnected = this.connected();
|
|
1129
|
+
if (hasConnected) {
|
|
1130
|
+
clearAllIntervals();
|
|
1131
|
+
resolve(true);
|
|
1102
1132
|
}
|
|
1103
|
-
|
|
1133
|
+
if (!!this._invalidAPIkey) {
|
|
1134
|
+
clearAllIntervals();
|
|
1135
|
+
reject(new Error("Invalid API key"));
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
}, pollingInterval);
|
|
1104
1139
|
});
|
|
1105
1140
|
if (!isConnected) {
|
|
1106
1141
|
this.connect();
|
|
@@ -1220,7 +1255,6 @@ var RunwareServer = class extends RunwareBase {
|
|
|
1220
1255
|
this._ws = new import_ws.default(this._url, {
|
|
1221
1256
|
perMessageDeflate: false
|
|
1222
1257
|
});
|
|
1223
|
-
delay(1);
|
|
1224
1258
|
this._ws.on("error", () => {
|
|
1225
1259
|
});
|
|
1226
1260
|
this._ws.on("close", () => this.handleClose());
|
|
@@ -1247,9 +1281,7 @@ var RunwareServer = class extends RunwareBase {
|
|
|
1247
1281
|
lis: (m) => {
|
|
1248
1282
|
var _a, _b;
|
|
1249
1283
|
if (m == null ? void 0 : m.error) {
|
|
1250
|
-
|
|
1251
|
-
this._invalidAPIkey = "Invalid API key";
|
|
1252
|
-
}
|
|
1284
|
+
this._invalidAPIkey = "Invalid API key";
|
|
1253
1285
|
return;
|
|
1254
1286
|
}
|
|
1255
1287
|
this._connectionSessionUUID = (_b = (_a = m == null ? void 0 : m["authentication" /* AUTHENTICATION */]) == null ? void 0 : _a[0]) == null ? void 0 : _b.connectionSessionUUID;
|
package/dist/index.mjs
CHANGED
|
@@ -821,9 +821,7 @@ var RunwareBase = class {
|
|
|
821
821
|
lis: (m) => {
|
|
822
822
|
var _a, _b;
|
|
823
823
|
if (m == null ? void 0 : m.error) {
|
|
824
|
-
|
|
825
|
-
this._invalidAPIkey = "Invalid API key";
|
|
826
|
-
}
|
|
824
|
+
this._invalidAPIkey = "Invalid API key";
|
|
827
825
|
return;
|
|
828
826
|
}
|
|
829
827
|
this._connectionSessionUUID = (_b = (_a = m == null ? void 0 : m["authentication" /* AUTHENTICATION */]) == null ? void 0 : _a[0]) == null ? void 0 : _b.connectionSessionUUID;
|
|
@@ -853,23 +851,32 @@ var RunwareBase = class {
|
|
|
853
851
|
listenToImages({
|
|
854
852
|
onPartialImages,
|
|
855
853
|
taskUUID,
|
|
856
|
-
groupKey
|
|
854
|
+
groupKey,
|
|
855
|
+
positivePrompt,
|
|
856
|
+
negativePrompt
|
|
857
857
|
}) {
|
|
858
858
|
return this.addListener({
|
|
859
859
|
taskUUID,
|
|
860
860
|
lis: (m) => {
|
|
861
861
|
var _a, _b;
|
|
862
|
-
|
|
862
|
+
let images = (_a = m == null ? void 0 : m[taskUUID]) == null ? void 0 : _a.filter(
|
|
863
863
|
(img) => img.taskUUID === taskUUID
|
|
864
864
|
);
|
|
865
865
|
onPartialImages == null ? void 0 : onPartialImages(images, (m == null ? void 0 : m.error) && m);
|
|
866
866
|
if (m.error) {
|
|
867
867
|
this._globalError = m;
|
|
868
868
|
} else {
|
|
869
|
+
images = images.map((image) => __spreadProps(__spreadValues({}, image), {
|
|
870
|
+
positivePrompt,
|
|
871
|
+
negativePrompt
|
|
872
|
+
}));
|
|
869
873
|
if (this._sdkType === "CLIENT" /* CLIENT */) {
|
|
870
874
|
this._globalImages = [
|
|
871
875
|
...this._globalImages,
|
|
872
|
-
...(_b = m == null ? void 0 : m[taskUUID]) != null ? _b : []
|
|
876
|
+
...((_b = m == null ? void 0 : m[taskUUID]) != null ? _b : []).map((image) => __spreadProps(__spreadValues({}, image), {
|
|
877
|
+
positivePrompt,
|
|
878
|
+
negativePrompt
|
|
879
|
+
}))
|
|
873
880
|
];
|
|
874
881
|
} else {
|
|
875
882
|
this._globalImages = [...this._globalImages, ...images];
|
|
@@ -940,8 +947,10 @@ var RunwareBase = class {
|
|
|
940
947
|
useCache,
|
|
941
948
|
onPartialImages,
|
|
942
949
|
includeCost,
|
|
943
|
-
customTaskUUID
|
|
950
|
+
customTaskUUID,
|
|
951
|
+
retry = 2
|
|
944
952
|
}) {
|
|
953
|
+
await this.ensureConnection();
|
|
945
954
|
let lis = void 0;
|
|
946
955
|
let requestObject = void 0;
|
|
947
956
|
let taskUUIDs = [];
|
|
@@ -1028,7 +1037,9 @@ var RunwareBase = class {
|
|
|
1028
1037
|
lis = this.listenToImages({
|
|
1029
1038
|
onPartialImages,
|
|
1030
1039
|
taskUUID,
|
|
1031
|
-
groupKey: "REQUEST_IMAGES" /* REQUEST_IMAGES
|
|
1040
|
+
groupKey: "REQUEST_IMAGES" /* REQUEST_IMAGES */,
|
|
1041
|
+
positivePrompt,
|
|
1042
|
+
negativePrompt
|
|
1032
1043
|
});
|
|
1033
1044
|
const promise = await this.getSimilarImages({
|
|
1034
1045
|
taskUUID: taskUUIDs,
|
|
@@ -1038,14 +1049,17 @@ var RunwareBase = class {
|
|
|
1038
1049
|
return promise;
|
|
1039
1050
|
},
|
|
1040
1051
|
{
|
|
1041
|
-
maxRetries:
|
|
1052
|
+
maxRetries: retry,
|
|
1042
1053
|
callback: () => {
|
|
1043
1054
|
lis == null ? void 0 : lis.destroy();
|
|
1044
1055
|
}
|
|
1045
1056
|
}
|
|
1046
1057
|
);
|
|
1047
1058
|
} catch (e) {
|
|
1048
|
-
if (
|
|
1059
|
+
if (e.taskUUID) {
|
|
1060
|
+
throw e;
|
|
1061
|
+
}
|
|
1062
|
+
if (retryCount >= retry) {
|
|
1049
1063
|
return this.handleIncompleteImages({ taskUUIDs, error: e });
|
|
1050
1064
|
}
|
|
1051
1065
|
}
|
|
@@ -1055,31 +1069,52 @@ var RunwareBase = class {
|
|
|
1055
1069
|
let isConnected = this.connected();
|
|
1056
1070
|
if (isConnected || this._url === BASE_RUNWARE_URLS.TEST)
|
|
1057
1071
|
return;
|
|
1058
|
-
const
|
|
1072
|
+
const retryInterval = 2e3;
|
|
1073
|
+
const pollingInterval = 200;
|
|
1059
1074
|
try {
|
|
1060
1075
|
if (this._invalidAPIkey)
|
|
1061
1076
|
throw this._invalidAPIkey;
|
|
1062
1077
|
return new Promise((resolve, reject) => {
|
|
1063
1078
|
let retry = 0;
|
|
1064
|
-
const MAX_RETRY =
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1079
|
+
const MAX_RETRY = 10;
|
|
1080
|
+
let retryIntervalId;
|
|
1081
|
+
let pollingIntervalId;
|
|
1082
|
+
const clearAllIntervals = () => {
|
|
1083
|
+
clearInterval(retryIntervalId);
|
|
1084
|
+
clearInterval(pollingIntervalId);
|
|
1085
|
+
};
|
|
1086
|
+
if (this._sdkType === "SERVER" /* SERVER */) {
|
|
1087
|
+
retryIntervalId = setInterval(async () => {
|
|
1088
|
+
try {
|
|
1089
|
+
const hasConnected = this.connected();
|
|
1090
|
+
if (hasConnected) {
|
|
1091
|
+
clearAllIntervals();
|
|
1092
|
+
resolve(true);
|
|
1093
|
+
} else if (retry >= MAX_RETRY) {
|
|
1094
|
+
clearAllIntervals();
|
|
1095
|
+
reject(new Error("Retry timed out"));
|
|
1096
|
+
} else {
|
|
1097
|
+
this.connect();
|
|
1098
|
+
retry++;
|
|
1099
|
+
}
|
|
1100
|
+
} catch (error) {
|
|
1101
|
+
clearAllIntervals();
|
|
1102
|
+
reject(error);
|
|
1077
1103
|
}
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
|
|
1104
|
+
}, retryInterval);
|
|
1105
|
+
}
|
|
1106
|
+
pollingIntervalId = setInterval(async () => {
|
|
1107
|
+
const hasConnected = this.connected();
|
|
1108
|
+
if (hasConnected) {
|
|
1109
|
+
clearAllIntervals();
|
|
1110
|
+
resolve(true);
|
|
1081
1111
|
}
|
|
1082
|
-
|
|
1112
|
+
if (!!this._invalidAPIkey) {
|
|
1113
|
+
clearAllIntervals();
|
|
1114
|
+
reject(new Error("Invalid API key"));
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
}, pollingInterval);
|
|
1083
1118
|
});
|
|
1084
1119
|
if (!isConnected) {
|
|
1085
1120
|
this.connect();
|
|
@@ -1199,7 +1234,6 @@ var RunwareServer = class extends RunwareBase {
|
|
|
1199
1234
|
this._ws = new WebSocket2(this._url, {
|
|
1200
1235
|
perMessageDeflate: false
|
|
1201
1236
|
});
|
|
1202
|
-
delay(1);
|
|
1203
1237
|
this._ws.on("error", () => {
|
|
1204
1238
|
});
|
|
1205
1239
|
this._ws.on("close", () => this.handleClose());
|
|
@@ -1226,9 +1260,7 @@ var RunwareServer = class extends RunwareBase {
|
|
|
1226
1260
|
lis: (m) => {
|
|
1227
1261
|
var _a, _b;
|
|
1228
1262
|
if (m == null ? void 0 : m.error) {
|
|
1229
|
-
|
|
1230
|
-
this._invalidAPIkey = "Invalid API key";
|
|
1231
|
-
}
|
|
1263
|
+
this._invalidAPIkey = "Invalid API key";
|
|
1232
1264
|
return;
|
|
1233
1265
|
}
|
|
1234
1266
|
this._connectionSessionUUID = (_b = (_a = m == null ? void 0 : m["authentication" /* AUTHENTICATION */]) == null ? void 0 : _a[0]) == null ? void 0 : _b.connectionSessionUUID;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runware/sdk-js",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
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
|
@@ -13,13 +13,13 @@ For an API Key and free trial credits, [create a free account](https://my.runwar
|
|
|
13
13
|
To install and set up the library, run:
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
|
-
$ npm install runware-
|
|
16
|
+
$ npm install @runware/sdk-js
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
Or if you prefer using Yarn:
|
|
20
20
|
|
|
21
21
|
```sh
|
|
22
|
-
$ yarn add runware-
|
|
22
|
+
$ yarn add @runware/sdk-js
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
## Instantiating the SDK
|
|
@@ -44,6 +44,8 @@ const runware = new RunwareServer({ apiKey: "API_KEY" });
|
|
|
44
44
|
NB: All errors can be caught in the catch block of each request
|
|
45
45
|
|
|
46
46
|
```js
|
|
47
|
+
import { Runware } from "@runware/sdk-js";
|
|
48
|
+
|
|
47
49
|
const runware = new Runware({ apiKey: "API_KEY" });
|
|
48
50
|
const images = await runware.requestImages({
|
|
49
51
|
positivePrompt: string;
|
|
@@ -67,13 +69,15 @@ const images = await runware.requestImages({
|
|
|
67
69
|
usePromptWeighting?: number;
|
|
68
70
|
controlNet?: IControlNet[];
|
|
69
71
|
lora?: ILora[];
|
|
72
|
+
retry?: number;
|
|
73
|
+
|
|
70
74
|
|
|
71
75
|
useCache?: boolean;
|
|
72
76
|
returnBase64Image?: boolean;
|
|
73
77
|
onPartialImages?: (images: IImage[], error: IError) => void;
|
|
74
78
|
})
|
|
75
79
|
|
|
76
|
-
return interface
|
|
80
|
+
return interface ITextToImage {
|
|
77
81
|
taskType: ETaskType;
|
|
78
82
|
imageUUID: string;
|
|
79
83
|
inputImageUUID?: string;
|
|
@@ -83,6 +87,8 @@ return interface IImage {
|
|
|
83
87
|
imageDataURI?: string;
|
|
84
88
|
NSFWContent?: boolean;
|
|
85
89
|
cost: number;
|
|
90
|
+
positivePrompt?: string;
|
|
91
|
+
negativePrompt?: string;
|
|
86
92
|
}[]
|
|
87
93
|
```
|
|
88
94
|
|
|
@@ -113,7 +119,7 @@ const [firstImagesRequest, secondImagesRequest] = await Promise.all([
|
|
|
113
119
|
|
|
114
120
|
console.log({firstImagesRequest, secondImagesRequest})
|
|
115
121
|
|
|
116
|
-
return interface
|
|
122
|
+
return interface ITextToImage {
|
|
117
123
|
taskType: ETaskType;
|
|
118
124
|
imageUUID: string;
|
|
119
125
|
inputImageUUID?: string;
|
|
@@ -123,6 +129,8 @@ return interface IImage {
|
|
|
123
129
|
imageDataURI?: string;
|
|
124
130
|
NSFWContent?: boolean;
|
|
125
131
|
cost: number;
|
|
132
|
+
positivePrompt?: string;
|
|
133
|
+
negativePrompt?: string;
|
|
126
134
|
}[]
|
|
127
135
|
```
|
|
128
136
|
|
|
@@ -356,6 +364,20 @@ return interface IControlNetImage {
|
|
|
356
364
|
|
|
357
365
|
## Changelog
|
|
358
366
|
|
|
367
|
+
### - v1.1.8
|
|
368
|
+
|
|
369
|
+
**Added or Changed**
|
|
370
|
+
|
|
371
|
+
- Fix image generation error
|
|
372
|
+
|
|
373
|
+
### - v1.1.7
|
|
374
|
+
|
|
375
|
+
**Added or Changed**
|
|
376
|
+
|
|
377
|
+
- Fix slow connection time
|
|
378
|
+
- Fix invalid api key error message
|
|
379
|
+
- Return prompt for images generated
|
|
380
|
+
|
|
359
381
|
### - v1.1.6
|
|
360
382
|
|
|
361
383
|
**Added or Changed**
|