comfyui-node 1.0.0
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/LICENSE +21 -0
- package/README.md +601 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/call-wrapper.d.ts +115 -0
- package/dist/call-wrapper.d.ts.map +1 -0
- package/dist/call-wrapper.js +432 -0
- package/dist/call-wrapper.js.map +1 -0
- package/dist/client.d.ts +233 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +719 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +4 -0
- package/dist/constants.js.map +1 -0
- package/dist/features/abstract.d.ts +15 -0
- package/dist/features/abstract.d.ts.map +1 -0
- package/dist/features/abstract.js +19 -0
- package/dist/features/abstract.js.map +1 -0
- package/dist/features/base.d.ts +9 -0
- package/dist/features/base.d.ts.map +1 -0
- package/dist/features/base.js +15 -0
- package/dist/features/base.js.map +1 -0
- package/dist/features/feature-flags.d.ts +14 -0
- package/dist/features/feature-flags.d.ts.map +1 -0
- package/dist/features/feature-flags.js +27 -0
- package/dist/features/feature-flags.js.map +1 -0
- package/dist/features/file.d.ts +86 -0
- package/dist/features/file.d.ts.map +1 -0
- package/dist/features/file.js +160 -0
- package/dist/features/file.js.map +1 -0
- package/dist/features/history.d.ts +16 -0
- package/dist/features/history.d.ts.map +1 -0
- package/dist/features/history.js +23 -0
- package/dist/features/history.js.map +1 -0
- package/dist/features/index.d.ts +14 -0
- package/dist/features/index.d.ts.map +1 -0
- package/dist/features/index.js +14 -0
- package/dist/features/index.js.map +1 -0
- package/dist/features/manager.d.ts +154 -0
- package/dist/features/manager.d.ts.map +1 -0
- package/dist/features/manager.js +309 -0
- package/dist/features/manager.js.map +1 -0
- package/dist/features/misc.d.ts +17 -0
- package/dist/features/misc.d.ts.map +1 -0
- package/dist/features/misc.js +52 -0
- package/dist/features/misc.js.map +1 -0
- package/dist/features/model.d.ts +39 -0
- package/dist/features/model.d.ts.map +1 -0
- package/dist/features/model.js +79 -0
- package/dist/features/model.js.map +1 -0
- package/dist/features/monitoring.d.ts +90 -0
- package/dist/features/monitoring.d.ts.map +1 -0
- package/dist/features/monitoring.js +129 -0
- package/dist/features/monitoring.js.map +1 -0
- package/dist/features/node.d.ts +42 -0
- package/dist/features/node.d.ts.map +1 -0
- package/dist/features/node.js +68 -0
- package/dist/features/node.js.map +1 -0
- package/dist/features/queue.d.ts +23 -0
- package/dist/features/queue.d.ts.map +1 -0
- package/dist/features/queue.js +68 -0
- package/dist/features/queue.js.map +1 -0
- package/dist/features/system.d.ts +21 -0
- package/dist/features/system.d.ts.map +1 -0
- package/dist/features/system.js +45 -0
- package/dist/features/system.js.map +1 -0
- package/dist/features/terminal.d.ts +25 -0
- package/dist/features/terminal.d.ts.map +1 -0
- package/dist/features/terminal.js +32 -0
- package/dist/features/terminal.js.map +1 -0
- package/dist/features/user.d.ts +42 -0
- package/dist/features/user.d.ts.map +1 -0
- package/dist/features/user.js +76 -0
- package/dist/features/user.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/pool.d.ts +171 -0
- package/dist/pool.d.ts.map +1 -0
- package/dist/pool.js +467 -0
- package/dist/pool.js.map +1 -0
- package/dist/prompt-builder.d.ts +131 -0
- package/dist/prompt-builder.d.ts.map +1 -0
- package/dist/prompt-builder.js +266 -0
- package/dist/prompt-builder.js.map +1 -0
- package/dist/tools.d.ts +10 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +16 -0
- package/dist/tools.js.map +1 -0
- package/dist/typed-event-target.d.ts +7 -0
- package/dist/typed-event-target.d.ts.map +1 -0
- package/dist/typed-event-target.js +19 -0
- package/dist/typed-event-target.js.map +1 -0
- package/dist/types/api.d.ts +212 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +16 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/error.d.ts +72 -0
- package/dist/types/error.d.ts.map +1 -0
- package/dist/types/error.js +75 -0
- package/dist/types/error.js.map +1 -0
- package/dist/types/event.d.ts +164 -0
- package/dist/types/event.d.ts.map +1 -0
- package/dist/types/event.js +2 -0
- package/dist/types/event.js.map +1 -0
- package/dist/types/manager.d.ts +157 -0
- package/dist/types/manager.d.ts.map +1 -0
- package/dist/types/manager.js +41 -0
- package/dist/types/manager.js.map +1 -0
- package/dist/types/sampler.d.ts +3 -0
- package/dist/types/sampler.d.ts.map +1 -0
- package/dist/types/sampler.js +2 -0
- package/dist/types/sampler.js.map +1 -0
- package/dist/types/tool.d.ts +10 -0
- package/dist/types/tool.d.ts.map +1 -0
- package/dist/types/tool.js +2 -0
- package/dist/types/tool.js.map +1 -0
- package/dist/utils/response-error.d.ts +4 -0
- package/dist/utils/response-error.d.ts.map +1 -0
- package/dist/utils/response-error.js +62 -0
- package/dist/utils/response-error.js.map +1 -0
- package/dist/utils/ws-reconnect.d.ts +29 -0
- package/dist/utils/ws-reconnect.d.ts.map +1 -0
- package/dist/utils/ws-reconnect.js +91 -0
- package/dist/utils/ws-reconnect.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { WebSocket } from "ws";
|
|
2
|
+
export function runWebSocketReconnect(api, factory, opts = {}) {
|
|
3
|
+
const { maxAttempts = 10, baseDelayMs = 1000, maxDelayMs = 15000, strategy = "exponential", customDelayFn, jitterPercent = 30, triggerEvents, scheduler = setTimeout } = opts;
|
|
4
|
+
if (triggerEvents) {
|
|
5
|
+
api.dispatchEvent(new CustomEvent("disconnected"));
|
|
6
|
+
api.dispatchEvent(new CustomEvent("reconnecting"));
|
|
7
|
+
}
|
|
8
|
+
let attempt = 0;
|
|
9
|
+
let aborted = false;
|
|
10
|
+
let pendingTimer = null;
|
|
11
|
+
const computeDelay = () => {
|
|
12
|
+
if (strategy === "custom" && customDelayFn) {
|
|
13
|
+
return Math.max(0, customDelayFn(attempt, { baseDelayMs, maxDelayMs }));
|
|
14
|
+
}
|
|
15
|
+
let raw;
|
|
16
|
+
if (strategy === "linear") {
|
|
17
|
+
raw = Math.min(baseDelayMs * attempt, maxDelayMs);
|
|
18
|
+
}
|
|
19
|
+
else { // exponential
|
|
20
|
+
raw = Math.min(baseDelayMs * Math.pow(2, attempt - 1), maxDelayMs);
|
|
21
|
+
}
|
|
22
|
+
if (jitterPercent > 0) {
|
|
23
|
+
const jitter = raw * (jitterPercent / 100) * (Math.random() - 0.5);
|
|
24
|
+
raw = raw + jitter;
|
|
25
|
+
}
|
|
26
|
+
return Math.max(0, raw);
|
|
27
|
+
};
|
|
28
|
+
const tryReconnect = () => {
|
|
29
|
+
if (aborted)
|
|
30
|
+
return;
|
|
31
|
+
attempt++;
|
|
32
|
+
api.dispatchEvent(new CustomEvent("log", { detail: { fnName: "ws-reconnect", message: `Attempt #${attempt}` } }));
|
|
33
|
+
// Clean up existing socket if present
|
|
34
|
+
const socket = api.socket;
|
|
35
|
+
if (socket) {
|
|
36
|
+
try {
|
|
37
|
+
if (typeof socket.terminate === "function")
|
|
38
|
+
socket.terminate();
|
|
39
|
+
socket.close?.();
|
|
40
|
+
}
|
|
41
|
+
catch { /* ignore */ }
|
|
42
|
+
api.socket = null;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
factory();
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
api.dispatchEvent(new CustomEvent("log", { detail: { fnName: "ws-reconnect", message: "Factory error", data: err } }));
|
|
49
|
+
}
|
|
50
|
+
if (!aborted && attempt < maxAttempts) {
|
|
51
|
+
const delay = computeDelay();
|
|
52
|
+
pendingTimer = scheduler(() => {
|
|
53
|
+
if (aborted)
|
|
54
|
+
return;
|
|
55
|
+
const s = api.socket;
|
|
56
|
+
if (!s) {
|
|
57
|
+
tryReconnect();
|
|
58
|
+
}
|
|
59
|
+
else if (s.readyState === WebSocket.OPEN || s.readyState === WebSocket.CONNECTING) {
|
|
60
|
+
api.dispatchEvent(new CustomEvent("log", { detail: { fnName: "ws-reconnect", message: "Reconnection successful" } }));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
tryReconnect();
|
|
64
|
+
}
|
|
65
|
+
}, delay);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
if (!aborted) {
|
|
69
|
+
api.dispatchEvent(new CustomEvent("reconnection_failed"));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
tryReconnect();
|
|
74
|
+
return {
|
|
75
|
+
abort() {
|
|
76
|
+
if (aborted)
|
|
77
|
+
return;
|
|
78
|
+
aborted = true;
|
|
79
|
+
if (pendingTimer && typeof pendingTimer === "object" && "ref" in pendingTimer) {
|
|
80
|
+
// Node.js Timeout object: clear via clearTimeout
|
|
81
|
+
try {
|
|
82
|
+
clearTimeout(pendingTimer);
|
|
83
|
+
}
|
|
84
|
+
catch { }
|
|
85
|
+
}
|
|
86
|
+
api.dispatchEvent(new CustomEvent("log", { detail: { fnName: "ws-reconnect", message: "Reconnection aborted" } }));
|
|
87
|
+
},
|
|
88
|
+
attempts() { return attempt; }
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=ws-reconnect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ws-reconnect.js","sourceRoot":"","sources":["../../src/utils/ws-reconnect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AA4B/B,MAAM,UAAU,qBAAqB,CAAC,GAAa,EAAE,OAAmB,EAAE,OAAyB,EAAE;IACnG,MAAM,EACJ,WAAW,GAAG,EAAE,EAChB,WAAW,GAAG,IAAI,EAClB,UAAU,GAAG,KAAK,EAClB,QAAQ,GAAG,aAAa,EACxB,aAAa,EACb,aAAa,GAAG,EAAE,EAClB,aAAa,EACb,SAAS,GAAG,UAAU,EACvB,GA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AAU,EAAE,CAAC;oBACpF,GAAG,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,yBAAyB,EAAE,EAAE,CAAC,CAAC,CAAC;gBACxH,CAAC;qBAAM,CAAC;oBACN,YAAY,EAAE,CAAC;gBACjB,CAAC;YACH,CAAC,EAAE,KAAK,CAAC,CAAC;QACZ,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,GAAG,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,qBAAqB,CAAC,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEF,YAAY,EAAE,CAAC;IACf,OAAO;QACL,KAAK;YACH,IAAI,OAAO;gBAAE,OAAO;YACpB,OAAO,GAAG,IAAI,CAAC;YACf,IAAI,YAAY,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,KAAK,IAAI,YAAY,EAAE,CAAC;gBAC9E,iDAAiD;gBACjD,IAAI,CAAC;oBAAC,YAAY,CAAC,YAAmB,CAAC,CAAC;gBAAC,CAAC;gBAAC,MAAM,CAAC,CAAA,CAAC;YACrD,CAAC;YACD,GAAG,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,sBAAsB,EAAE,EAAE,CAAC,CAAC,CAAC;QACrH,CAAC;QACD,QAAQ,KAAK,OAAO,OAAO,CAAC,CAAC,CAAC;KAC/B,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "comfyui-node",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "ComfyUI Node.js Client",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/igorls/comfyui-node.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/igorls/comfyui-node/issues"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/igorls/comfyui-node#readme",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"comfyui",
|
|
19
|
+
"stable-diffusion",
|
|
20
|
+
"image-generation",
|
|
21
|
+
"ai",
|
|
22
|
+
"client"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=22"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc --project tsconfig.json",
|
|
41
|
+
"build:watch": "tsc --project tsconfig.json --watch",
|
|
42
|
+
"test": "bun test",
|
|
43
|
+
"test:local": "bun test ./test",
|
|
44
|
+
"test:real": "cross-env COMFY_REAL=1 bun test ./test/real.integration.spec.ts",
|
|
45
|
+
"test:full": "cross-env COMFY_REAL=1 COMFY_FULL=1 bun test ./test/real.full.integration.spec.ts",
|
|
46
|
+
"coverage": "bun test --coverage",
|
|
47
|
+
"coverage:lcov": "bun test --coverage --coverage-reporter=lcov",
|
|
48
|
+
"coverage:enforce": "bun run coverage:lcov && bun run coverage:check",
|
|
49
|
+
"coverage:check": "bun scripts/coverage-check.ts",
|
|
50
|
+
"typecov": "type-coverage --detail --ignore-catch --at-least 0",
|
|
51
|
+
"typecov:strict": "type-coverage --detail --ignore-catch --at-least 95",
|
|
52
|
+
"dist:fresh": "bun run build && bun run dist:fresh:check",
|
|
53
|
+
"dist:fresh:check": "bun scripts/dist-fresh-check.mjs",
|
|
54
|
+
"check:all": "bun run build && bun run test && bun run typecov:strict && bun run dist:fresh",
|
|
55
|
+
"prepublishOnly": "bun run check:all"
|
|
56
|
+
},
|
|
57
|
+
"license": "MIT",
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"ws": "8.18.3"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@types/bun": "^1.2.21",
|
|
63
|
+
"@types/jest": "^30.0.0",
|
|
64
|
+
"@types/node": "24.3.1",
|
|
65
|
+
"@types/ws": "^8.18.1",
|
|
66
|
+
"cross-env": "^10.0.0",
|
|
67
|
+
"@istanbuljs/schema": "^0.1.3",
|
|
68
|
+
"typescript": "5.9.2",
|
|
69
|
+
"type-coverage": "^2.29.7"
|
|
70
|
+
}
|
|
71
|
+
}
|