comfy-ts 1.3.0 → 1.4.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/README.md +26 -0
- package/dist/{DefinedWorkflow-gpknV-5f.js → DefinedWorkflow-C_QAxKr3.js} +64 -13
- package/dist/DefinedWorkflow-C_QAxKr3.js.map +1 -0
- package/dist/{DraftsSt-DmA0jWGl.js → DraftsSt-DcOTn0QR.js} +2 -2
- package/dist/{DraftsSt-DmA0jWGl.js.map → DraftsSt-DcOTn0QR.js.map} +1 -1
- package/dist/cli.js +3 -3
- package/dist/index.cjs +346 -183
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -40
- package/dist/index.d.ts +94 -41
- package/dist/index.js +338 -174
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-Bn6yIJB0.js → run-serve-CN0DhrsA.js} +3 -3
- package/dist/{run-serve-Bn6yIJB0.js.map → run-serve-CN0DhrsA.js.map} +1 -1
- package/dist/{run-tui-BtjaOXRh.js → run-tui-bN2hSD5i.js} +10 -11
- package/dist/{run-tui-BtjaOXRh.js.map → run-tui-bN2hSD5i.js.map} +1 -1
- package/dist/{state-DKCPy105.js → state-COlKYipO.js} +199 -146
- package/dist/state-COlKYipO.js.map +1 -0
- package/dist/web.d.ts +17340 -0
- package/dist/web.js +5569 -0
- package/dist/web.js.map +1 -0
- package/examples/web/example.ts +71 -0
- package/examples/web/index.html +77 -0
- package/examples/web/serve.ts +42 -0
- package/examples/web/tsconfig.json +15 -0
- package/package.json +8 -2
- package/src/coreExports.ts +118 -0
- package/src/host/ComfyHost.ts +23 -23
- package/src/host/ResilientWebsocket.ts +93 -47
- package/src/host/hostUrl.ts +2 -1
- package/src/host/loraManagerApi.ts +6 -7
- package/src/index.ts +8 -107
- package/src/manager/loaders/step2_custom-node-list-loader.ts +4 -4
- package/src/manager/loaders/step3_extension-node-map-loader.ts +3 -3
- package/src/manager/loaders/step4_model-list-loader.ts +7 -7
- package/src/manager/loaders/step5_alter-list-loader.ts +2 -2
- package/src/manager/loaders/step6_github-stats-loader.ts +2 -2
- package/src/runner/ComfyExecution.ts +14 -11
- package/src/runner/MediaImage.ts +18 -30
- package/src/sdk-generator/ComfySchema.ts +2 -2
- package/src/state.ts +13 -9
- package/src/storage/ComfyStorage.ts +144 -0
- package/src/storage/nodeStorage.ts +9 -0
- package/src/utils/downloadFile.ts +11 -69
- package/src/utils/hashArrayBuffer.ts +3 -4
- package/src/utils/lazySharp.ts +25 -0
- package/src/utils/sha1.ts +69 -0
- package/src/vars/ComfyVars.ts +5 -6
- package/src/vars/loraKeywords.ts +6 -6
- package/src/web.ts +13 -0
- package/dist/DefinedWorkflow-gpknV-5f.js.map +0 -1
- package/dist/state-DKCPy105.js.map +0 -1
- package/src/utils/writeFile.ts +0 -16
package/dist/index.cjs
CHANGED
|
@@ -23,24 +23,118 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
//#endregion
|
|
24
24
|
let node_fs = require("node:fs");
|
|
25
25
|
node_fs = __toESM(node_fs, 1);
|
|
26
|
+
let node_os = require("node:os");
|
|
27
|
+
node_os = __toESM(node_os, 1);
|
|
26
28
|
let pathe = require("pathe");
|
|
27
29
|
let arktype = require("arktype");
|
|
28
30
|
let nanoid = require("nanoid");
|
|
29
|
-
let sharp = require("sharp");
|
|
30
|
-
sharp = __toESM(sharp, 1);
|
|
31
31
|
let image_meta = require("image-meta");
|
|
32
|
-
let node_crypto = require("node:crypto");
|
|
33
|
-
node_crypto = __toESM(node_crypto, 1);
|
|
34
|
-
let ws = require("ws");
|
|
35
|
-
ws = __toESM(ws, 1);
|
|
36
|
-
let node_os = require("node:os");
|
|
37
32
|
let mobx = require("mobx");
|
|
38
|
-
let node_https = require("node:https");
|
|
39
|
-
node_https = __toESM(node_https, 1);
|
|
40
|
-
let node_process = require("node:process");
|
|
41
33
|
let node_url = require("node:url");
|
|
34
|
+
//#region src/storage/ComfyStorage.ts
|
|
35
|
+
function dirnameOf(path) {
|
|
36
|
+
const ix = path.lastIndexOf("/");
|
|
37
|
+
return ix <= 0 ? "/" : path.slice(0, ix);
|
|
38
|
+
}
|
|
39
|
+
/** node backend built from INJECTED modules: nodeStorage.ts passes its static
|
|
40
|
+
* imports, the autodetect below passes process.getBuiltinModule results */
|
|
41
|
+
function createNodeStorageFrom(fs, os) {
|
|
42
|
+
return {
|
|
43
|
+
kind: "node",
|
|
44
|
+
readText: (p) => fs.readFileSync(p, "utf8"),
|
|
45
|
+
readTextIfExists: (p) => fs.existsSync(p) ? fs.readFileSync(p, "utf8") : null,
|
|
46
|
+
readBytes: (p) => new Uint8Array(fs.readFileSync(p)),
|
|
47
|
+
writeText: (p, text) => {
|
|
48
|
+
fs.mkdirSync(dirnameOf(p), { recursive: true });
|
|
49
|
+
fs.writeFileSync(p, text);
|
|
50
|
+
},
|
|
51
|
+
writeBytes: (p, bytes) => {
|
|
52
|
+
fs.mkdirSync(dirnameOf(p), { recursive: true });
|
|
53
|
+
fs.writeFileSync(p, bytes);
|
|
54
|
+
},
|
|
55
|
+
exists: (p) => fs.existsSync(p),
|
|
56
|
+
mkdirp: (p) => void fs.mkdirSync(p, { recursive: true }),
|
|
57
|
+
mtimeMs: (p) => fs.existsSync(p) ? fs.statSync(p).mtimeMs : null,
|
|
58
|
+
homedir: () => os.homedir(),
|
|
59
|
+
cwd: () => process.cwd()
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** in-memory backend: the web default, also handy for hermetic tests.
|
|
63
|
+
* Paths are LITERAL keys (no normalization — core callers resolve through
|
|
64
|
+
* pathe/comfyts already). exists() knows written files and EXPLICIT mkdirp
|
|
65
|
+
* dirs only, never implicit parents. Bytes are copied in AND out so neither
|
|
66
|
+
* side can mutate the store. */
|
|
67
|
+
function createMemoryStorage(p = {}) {
|
|
68
|
+
const files = /* @__PURE__ */ new Map();
|
|
69
|
+
const mtimes = /* @__PURE__ */ new Map();
|
|
70
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
71
|
+
const td = new TextDecoder();
|
|
72
|
+
const te = new TextEncoder();
|
|
73
|
+
const write = (path, bytes) => {
|
|
74
|
+
files.set(path, bytes.slice());
|
|
75
|
+
mtimes.set(path, Date.now());
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
kind: "memory",
|
|
79
|
+
readText: (path) => {
|
|
80
|
+
const hit = files.get(path);
|
|
81
|
+
if (hit == null) throw new Error(`[memory storage] no such file: ${path}`);
|
|
82
|
+
return td.decode(hit);
|
|
83
|
+
},
|
|
84
|
+
readTextIfExists: (path) => {
|
|
85
|
+
const hit = files.get(path);
|
|
86
|
+
return hit == null ? null : td.decode(hit);
|
|
87
|
+
},
|
|
88
|
+
readBytes: (path) => {
|
|
89
|
+
const hit = files.get(path);
|
|
90
|
+
if (hit == null) throw new Error(`[memory storage] no such file: ${path}`);
|
|
91
|
+
return hit.slice();
|
|
92
|
+
},
|
|
93
|
+
writeText: (path, text) => write(path, te.encode(text)),
|
|
94
|
+
writeBytes: write,
|
|
95
|
+
exists: (path) => files.has(path) || dirs.has(path),
|
|
96
|
+
mkdirp: (path) => void dirs.add(path),
|
|
97
|
+
mtimeMs: (path) => mtimes.get(path) ?? null,
|
|
98
|
+
homedir: () => p.homedir ?? "/home/web",
|
|
99
|
+
cwd: () => p.cwd ?? "/"
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
let installedDefault = null;
|
|
103
|
+
/** entries call this at import time: index.ts installs node, web.ts memory */
|
|
104
|
+
function setDefaultComfyStorage(storage) {
|
|
105
|
+
installedDefault = storage;
|
|
106
|
+
}
|
|
107
|
+
function autodetectNodeStorage() {
|
|
108
|
+
const get = globalThis.process?.getBuiltinModule;
|
|
109
|
+
if (typeof get !== "function") return null;
|
|
110
|
+
const fs = get("node:fs");
|
|
111
|
+
const os = get("node:os");
|
|
112
|
+
if (fs == null || os == null) return null;
|
|
113
|
+
return createNodeStorageFrom(fs, os);
|
|
114
|
+
}
|
|
115
|
+
function resolveComfyStorage(explicit) {
|
|
116
|
+
if (explicit != null) return explicit;
|
|
117
|
+
if (installedDefault != null) return installedDefault;
|
|
118
|
+
const detected = autodetectNodeStorage();
|
|
119
|
+
if (detected != null) {
|
|
120
|
+
installedDefault = detected;
|
|
121
|
+
return detected;
|
|
122
|
+
}
|
|
123
|
+
throw new Error(`no ComfyStorage available — import 'comfy-ts' (node) or 'comfy-ts/web' (browser) before creating ComfyTS, or pass ComfyTS.create({ storage })`);
|
|
124
|
+
}
|
|
125
|
+
/** the ONE accessor call sites use: the instance's storage when the global
|
|
126
|
+
* exists, the resolved default otherwise (vars constructed before create()) */
|
|
127
|
+
function getComfyStorage() {
|
|
128
|
+
return globalThis.comfyts?.storage ?? resolveComfyStorage();
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/storage/nodeStorage.ts
|
|
132
|
+
function createNodeStorage() {
|
|
133
|
+
return createNodeStorageFrom(node_fs, node_os);
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
42
136
|
//#region package.json
|
|
43
|
-
var version = "1.
|
|
137
|
+
var version = "1.4.0";
|
|
44
138
|
//#endregion
|
|
45
139
|
//#region src/litegraph/LiteGraphLinkID.ts
|
|
46
140
|
const asLiteGraphLinkID = (id) => id;
|
|
@@ -1644,6 +1738,32 @@ const runTimestamp = (d) => {
|
|
|
1644
1738
|
return `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}-${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`;
|
|
1645
1739
|
};
|
|
1646
1740
|
//#endregion
|
|
1741
|
+
//#region src/utils/extractErrorMessage.ts
|
|
1742
|
+
/** Extracts an error message from an exception stuff. */
|
|
1743
|
+
const extractErrorMessage = (error) => {
|
|
1744
|
+
if (error instanceof Error) return error.message;
|
|
1745
|
+
if (error === null) return "null";
|
|
1746
|
+
if (typeof error === "string") return error;
|
|
1747
|
+
if (typeof error === "object") {
|
|
1748
|
+
if ("message" in error && typeof error.message === "string") return error.message;
|
|
1749
|
+
return JSON.stringify(error);
|
|
1750
|
+
}
|
|
1751
|
+
return String(error);
|
|
1752
|
+
};
|
|
1753
|
+
//#endregion
|
|
1754
|
+
//#region src/utils/lazySharp.ts
|
|
1755
|
+
let cached = null;
|
|
1756
|
+
async function importSharp(reason) {
|
|
1757
|
+
if (cached != null) return cached;
|
|
1758
|
+
const specifier = "sharp";
|
|
1759
|
+
try {
|
|
1760
|
+
cached = (await import(specifier)).default;
|
|
1761
|
+
return cached;
|
|
1762
|
+
} catch (e) {
|
|
1763
|
+
throw new Error(`sharp is unavailable — ${reason} is node-only (browser builds get raw bytes instead): ${extractErrorMessage(e)}`, { cause: e });
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
//#endregion
|
|
1647
1767
|
//#region src/types/index.ts
|
|
1648
1768
|
const asAbsolutePath = (path) => path;
|
|
1649
1769
|
const asRelativePath = (path) => path;
|
|
@@ -1693,10 +1813,78 @@ function exhaust(x) {
|
|
|
1693
1813
|
return x;
|
|
1694
1814
|
}
|
|
1695
1815
|
//#endregion
|
|
1816
|
+
//#region src/utils/sha1.ts
|
|
1817
|
+
function sha1Hex(data) {
|
|
1818
|
+
const ml = data.length;
|
|
1819
|
+
const total = Math.ceil((ml + 1 + 8) / 64) * 64;
|
|
1820
|
+
const bytes = new Uint8Array(total);
|
|
1821
|
+
bytes.set(data);
|
|
1822
|
+
bytes[ml] = 128;
|
|
1823
|
+
const dv = new DataView(bytes.buffer);
|
|
1824
|
+
const bitLen = ml * 8;
|
|
1825
|
+
dv.setUint32(total - 8, Math.floor(bitLen / 2 ** 32));
|
|
1826
|
+
dv.setUint32(total - 4, bitLen >>> 0);
|
|
1827
|
+
let h0 = 1732584193;
|
|
1828
|
+
let h1 = 4023233417;
|
|
1829
|
+
let h2 = 2562383102;
|
|
1830
|
+
let h3 = 271733878;
|
|
1831
|
+
let h4 = 3285377520;
|
|
1832
|
+
const w = /* @__PURE__ */ new Uint32Array(80);
|
|
1833
|
+
for (let i = 0; i < total; i += 64) {
|
|
1834
|
+
for (let j = 0; j < 16; j++) w[j] = dv.getUint32(i + j * 4);
|
|
1835
|
+
for (let j = 16; j < 80; j++) {
|
|
1836
|
+
const n = (w[j - 3] ?? 0) ^ (w[j - 8] ?? 0) ^ (w[j - 14] ?? 0) ^ (w[j - 16] ?? 0);
|
|
1837
|
+
w[j] = n << 1 | n >>> 31;
|
|
1838
|
+
}
|
|
1839
|
+
let a = h0;
|
|
1840
|
+
let b = h1;
|
|
1841
|
+
let c = h2;
|
|
1842
|
+
let d = h3;
|
|
1843
|
+
let e = h4;
|
|
1844
|
+
for (let j = 0; j < 80; j++) {
|
|
1845
|
+
let f;
|
|
1846
|
+
let k;
|
|
1847
|
+
if (j < 20) {
|
|
1848
|
+
f = b & c | ~b & d;
|
|
1849
|
+
k = 1518500249;
|
|
1850
|
+
} else if (j < 40) {
|
|
1851
|
+
f = b ^ c ^ d;
|
|
1852
|
+
k = 1859775393;
|
|
1853
|
+
} else if (j < 60) {
|
|
1854
|
+
f = b & c | b & d | c & d;
|
|
1855
|
+
k = 2400959708;
|
|
1856
|
+
} else {
|
|
1857
|
+
f = b ^ c ^ d;
|
|
1858
|
+
k = 3395469782;
|
|
1859
|
+
}
|
|
1860
|
+
const temp = (a << 5 | a >>> 27) + f + e + k + (w[j] ?? 0) >>> 0;
|
|
1861
|
+
e = d;
|
|
1862
|
+
d = c;
|
|
1863
|
+
c = b << 30 | b >>> 2;
|
|
1864
|
+
b = a;
|
|
1865
|
+
a = temp;
|
|
1866
|
+
}
|
|
1867
|
+
h0 = h0 + a >>> 0;
|
|
1868
|
+
h1 = h1 + b >>> 0;
|
|
1869
|
+
h2 = h2 + c >>> 0;
|
|
1870
|
+
h3 = h3 + d >>> 0;
|
|
1871
|
+
h4 = h4 + e >>> 0;
|
|
1872
|
+
}
|
|
1873
|
+
return [
|
|
1874
|
+
h0,
|
|
1875
|
+
h1,
|
|
1876
|
+
h2,
|
|
1877
|
+
h3,
|
|
1878
|
+
h4
|
|
1879
|
+
].map((x) => x.toString(16).padStart(8, "0")).join("");
|
|
1880
|
+
}
|
|
1881
|
+
function sha1HexOfString(s) {
|
|
1882
|
+
return sha1Hex(new TextEncoder().encode(s));
|
|
1883
|
+
}
|
|
1884
|
+
//#endregion
|
|
1696
1885
|
//#region src/utils/hashArrayBuffer.ts
|
|
1697
1886
|
const hashArrayBuffer = (buffer) => {
|
|
1698
|
-
|
|
1699
|
-
return node_crypto.default.createHash("sha1").update(data).digest("hex");
|
|
1887
|
+
return sha1Hex(buffer);
|
|
1700
1888
|
};
|
|
1701
1889
|
//#endregion
|
|
1702
1890
|
//#region src/graph/ComfyNodeID.ts
|
|
@@ -1875,29 +2063,21 @@ var MediaImage = class MediaImage {
|
|
|
1875
2063
|
this._metadata = null;
|
|
1876
2064
|
this._hash = null;
|
|
1877
2065
|
this.processWithSharp_inplace = async (fn) => {
|
|
1878
|
-
const buff = await fn((
|
|
1879
|
-
(
|
|
2066
|
+
const buff = await fn((await importSharp("processWithSharp_inplace"))(this.buffer)).toBuffer();
|
|
2067
|
+
getComfyStorage().writeBytes(this.absPath, new Uint8Array(buff));
|
|
1880
2068
|
this.updateBuffer(new Uint8Array(buff));
|
|
1881
2069
|
return this;
|
|
1882
2070
|
};
|
|
1883
2071
|
this.processWithSharp = async (fn, path) => {
|
|
1884
|
-
const
|
|
2072
|
+
const sharp = await importSharp("processWithSharp");
|
|
1885
2073
|
path ??= this.absPath + `.processed-${Date.now()}` + this.extension;
|
|
1886
|
-
await
|
|
1887
|
-
|
|
2074
|
+
const buffer = new Uint8Array(await fn(sharp(this.buffer)).toBuffer());
|
|
2075
|
+
getComfyStorage().writeBytes(path, buffer);
|
|
1888
2076
|
return new MediaImage({
|
|
1889
2077
|
path,
|
|
1890
2078
|
buffer
|
|
1891
2079
|
});
|
|
1892
2080
|
};
|
|
1893
|
-
this.generatePreview = async (targetPath) => {
|
|
1894
|
-
const img = (0, sharp.default)(this.absPath).rotate().resize(100).jpeg({ mozjpeg: true });
|
|
1895
|
-
(0, node_fs.mkdirSync)((0, pathe.dirname)(targetPath), { recursive: true });
|
|
1896
|
-
await img.toFile(targetPath);
|
|
1897
|
-
};
|
|
1898
|
-
this.generateMiniPreview = async () => {
|
|
1899
|
-
return (await (0, sharp.default)(this.absPath).resize(32, 32, { fit: "inside" }).webp({ quality: 1 }).toBuffer()).toString("base64");
|
|
1900
|
-
};
|
|
1901
2081
|
this.absPath = data.path;
|
|
1902
2082
|
this.execution = data.execution;
|
|
1903
2083
|
this.promptNodeID = data.promptNodeID;
|
|
@@ -1967,26 +2147,25 @@ var MediaImage = class MediaImage {
|
|
|
1967
2147
|
* does not includes the prefix `data:image/png;base64,`
|
|
1968
2148
|
*/
|
|
1969
2149
|
getBase64Payload() {
|
|
1970
|
-
|
|
2150
|
+
const bytes = this.buffer;
|
|
2151
|
+
let bin = "";
|
|
2152
|
+
const chunk = 32768;
|
|
2153
|
+
for (let i = 0; i < bytes.length; i += chunk) bin += String.fromCharCode(...bytes.subarray(i, i + chunk));
|
|
2154
|
+
return btoa(bin);
|
|
1971
2155
|
}
|
|
1972
2156
|
get buffer() {
|
|
1973
2157
|
if (this._buffer != null) return this._buffer;
|
|
1974
|
-
|
|
1975
|
-
const uint8arr = new Uint8Array(buff);
|
|
1976
|
-
this._buffer = uint8arr;
|
|
2158
|
+
this._buffer = getComfyStorage().readBytes(this.absPath);
|
|
1977
2159
|
return this._buffer;
|
|
1978
2160
|
}
|
|
1979
2161
|
get metadata() {
|
|
1980
2162
|
if (this._metadata != null) return this._metadata;
|
|
1981
|
-
|
|
1982
|
-
const uint8arr = new Uint8Array(buff);
|
|
1983
|
-
this._metadata = (0, image_meta.imageMeta)(uint8arr);
|
|
2163
|
+
this._metadata = (0, image_meta.imageMeta)(this.buffer);
|
|
1984
2164
|
return this._metadata;
|
|
1985
2165
|
}
|
|
1986
2166
|
get hash() {
|
|
1987
2167
|
if (this._hash != null) return this._hash;
|
|
1988
|
-
|
|
1989
|
-
this._hash = hashArrayBuffer(new Uint8Array(buff));
|
|
2168
|
+
this._hash = hashArrayBuffer(this.buffer);
|
|
1990
2169
|
return this._hash;
|
|
1991
2170
|
}
|
|
1992
2171
|
};
|
|
@@ -2072,12 +2251,12 @@ var ComfyExecution = class {
|
|
|
2072
2251
|
const extension = sf.format.split("/")[1];
|
|
2073
2252
|
absPath += "." + extension;
|
|
2074
2253
|
}
|
|
2254
|
+
const storage = getComfyStorage();
|
|
2075
2255
|
absPath = uniquifyOutputPath({
|
|
2076
2256
|
path: absPath,
|
|
2077
|
-
exists:
|
|
2257
|
+
exists: (p) => storage.exists(p),
|
|
2078
2258
|
claimed: CLAIMED_OUTPUT_PATHS
|
|
2079
2259
|
});
|
|
2080
|
-
(0, node_fs.mkdirSync)((0, pathe.dirname)(absPath), { recursive: true });
|
|
2081
2260
|
let img;
|
|
2082
2261
|
if (sf && sf.format !== "raw") {
|
|
2083
2262
|
const buff = await (await this.host.fetchFile(imgRoute)).arrayBuffer();
|
|
@@ -2092,9 +2271,11 @@ var ComfyExecution = class {
|
|
|
2092
2271
|
if (sf.format === "image/webp") return "webp";
|
|
2093
2272
|
return "png";
|
|
2094
2273
|
})();
|
|
2095
|
-
await (
|
|
2274
|
+
const encoded = await (await importSharp(`saveFormat '${sf.format}' re-encoding`))(buff).withMetadata().withExif({ IFD0: textChunk }).toFormat(format, sf.quality ? { quality: Math.round(sf.quality * 100) } : void 0).toBuffer();
|
|
2275
|
+
storage.writeBytes(asAbsolutePath(absPath), new Uint8Array(encoded));
|
|
2096
2276
|
img = new MediaImage({
|
|
2097
2277
|
path: asAbsolutePath(absPath),
|
|
2278
|
+
buffer: new Uint8Array(encoded),
|
|
2098
2279
|
execution: this,
|
|
2099
2280
|
promptNodeID,
|
|
2100
2281
|
comfyUIInfos: {
|
|
@@ -2105,7 +2286,7 @@ var ComfyExecution = class {
|
|
|
2105
2286
|
} else {
|
|
2106
2287
|
const buff = await (await this.host.fetchFile(imgRoute)).arrayBuffer();
|
|
2107
2288
|
const uint8arr = new Uint8Array(buff);
|
|
2108
|
-
|
|
2289
|
+
storage.writeBytes(asAbsolutePath(absPath), uint8arr);
|
|
2109
2290
|
img = new MediaImage({
|
|
2110
2291
|
path: asAbsolutePath(absPath),
|
|
2111
2292
|
buffer: uint8arr,
|
|
@@ -2162,14 +2343,14 @@ var ComfyExecution = class {
|
|
|
2162
2343
|
const line = `▶ [${bar}] ${p.percent.toFixed(0).padStart(3)}%${node} · ${(p.elapsedMs / 1e3).toFixed(0)}s`;
|
|
2163
2344
|
if (line === this._lastLoggedLine) return;
|
|
2164
2345
|
this._lastLoggedLine = line;
|
|
2165
|
-
if (process
|
|
2346
|
+
if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}`);
|
|
2166
2347
|
else console.log(line);
|
|
2167
2348
|
}
|
|
2168
2349
|
finishProgressLine() {
|
|
2169
2350
|
if (!this.logProgress) return;
|
|
2170
2351
|
const p = this.progress;
|
|
2171
2352
|
const line = `${this.status === "Failure" ? "🔴" : "🟢"} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1e3).toFixed(1)}s · ${this.images.length} image(s)`;
|
|
2172
|
-
if (process
|
|
2353
|
+
if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}\n`);
|
|
2173
2354
|
else console.log(line);
|
|
2174
2355
|
}
|
|
2175
2356
|
log(...args) {
|
|
@@ -2918,7 +3099,7 @@ var ComfySchema = class {
|
|
|
2918
3099
|
else if (typeof enumValue === "number") enumValues.push(enumValue);
|
|
2919
3100
|
else enumValues.push(enumValue.content);
|
|
2920
3101
|
const hashContent = enumValues.length === 0 ? `[[empty]]` : enumValues.sort().join("|");
|
|
2921
|
-
const hash =
|
|
3102
|
+
const hash = sha1HexOfString(hashContent).slice(0, 8);
|
|
2922
3103
|
let unionInfo = this.knownUnionByHash.get(hash);
|
|
2923
3104
|
if (unionInfo == null) {
|
|
2924
3105
|
const unionName = getUnionNameBasedOnFirstFoundEnumName(p.slotName, hash, hashContent);
|
|
@@ -3202,19 +3383,6 @@ types.ComfyInputType;
|
|
|
3202
3383
|
types.ComfyEnumDef;
|
|
3203
3384
|
types.ComfyInputOpts;
|
|
3204
3385
|
//#endregion
|
|
3205
|
-
//#region src/utils/extractErrorMessage.ts
|
|
3206
|
-
/** Extracts an error message from an exception stuff. */
|
|
3207
|
-
const extractErrorMessage = (error) => {
|
|
3208
|
-
if (error instanceof Error) return error.message;
|
|
3209
|
-
if (error === null) return "null";
|
|
3210
|
-
if (typeof error === "string") return error;
|
|
3211
|
-
if (typeof error === "object") {
|
|
3212
|
-
if ("message" in error && typeof error.message === "string") return error.message;
|
|
3213
|
-
return JSON.stringify(error);
|
|
3214
|
-
}
|
|
3215
|
-
return String(error);
|
|
3216
|
-
};
|
|
3217
|
-
//#endregion
|
|
3218
3386
|
//#region src/utils/stringifyReadable.ts
|
|
3219
3387
|
const tab = " ";
|
|
3220
3388
|
function readableStringify(obj, maxLevel = 3, level = 0) {
|
|
@@ -3242,17 +3410,6 @@ function readableStringify(obj, maxLevel = 3, level = 0) {
|
|
|
3242
3410
|
return result;
|
|
3243
3411
|
}
|
|
3244
3412
|
//#endregion
|
|
3245
|
-
//#region src/utils/writeFile.ts
|
|
3246
|
-
const writeFileAsync = async (path, data, fmt) => {
|
|
3247
|
-
return new Promise((resolve, reject) => {
|
|
3248
|
-
logInfo(`writing file: ${ansi.blue(path)}`);
|
|
3249
|
-
(0, node_fs.writeFile)(path, data, fmt, (err) => {
|
|
3250
|
-
if (err) reject(err);
|
|
3251
|
-
else resolve();
|
|
3252
|
-
});
|
|
3253
|
-
});
|
|
3254
|
-
};
|
|
3255
|
-
//#endregion
|
|
3256
3413
|
//#region src/manager/types/ComfyManagerAPIModelList.ts
|
|
3257
3414
|
const ComfyManagerAPIModelList_ark = (0, arktype.type)({ models: (0, arktype.type)({
|
|
3258
3415
|
name: arktype.type.string.as(),
|
|
@@ -3490,7 +3647,8 @@ function parseHostBase(p) {
|
|
|
3490
3647
|
function renderHttpBase(p) {
|
|
3491
3648
|
return `${p.scheme}://${p.host}${renderPort(p)}${p.basePath}`;
|
|
3492
3649
|
}
|
|
3493
|
-
/** ws(s) endpoint; auth
|
|
3650
|
+
/** ws(s) endpoint; auth rides the upgrade headers — EXCEPT headerless
|
|
3651
|
+
* transports (browser), where the ws client remaps X-API-Key to ?token= */
|
|
3494
3652
|
function renderWsUrl(p) {
|
|
3495
3653
|
return `${p.scheme === "https" ? "wss" : "ws"}://${p.host}${renderPort(p)}${p.basePath}/ws`;
|
|
3496
3654
|
}
|
|
@@ -3500,6 +3658,27 @@ function renderPort(p) {
|
|
|
3500
3658
|
}
|
|
3501
3659
|
//#endregion
|
|
3502
3660
|
//#region src/host/ResilientWebsocket.ts
|
|
3661
|
+
let transportPromise = null;
|
|
3662
|
+
/** node: the ws package (headers on the upgrade). browser: native WebSocket. */
|
|
3663
|
+
function resolveWsTransport() {
|
|
3664
|
+
transportPromise ??= (async () => {
|
|
3665
|
+
const specifier = "ws";
|
|
3666
|
+
try {
|
|
3667
|
+
return {
|
|
3668
|
+
ctor: (await import(specifier)).default,
|
|
3669
|
+
supportsHeaders: true
|
|
3670
|
+
};
|
|
3671
|
+
} catch {
|
|
3672
|
+
const native = globalThis.WebSocket;
|
|
3673
|
+
if (native != null) return {
|
|
3674
|
+
ctor: native,
|
|
3675
|
+
supportsHeaders: false
|
|
3676
|
+
};
|
|
3677
|
+
throw new Error(`no WebSocket transport: neither the 'ws' package nor a global WebSocket is available`);
|
|
3678
|
+
}
|
|
3679
|
+
})();
|
|
3680
|
+
return transportPromise;
|
|
3681
|
+
}
|
|
3503
3682
|
var ResilientWebSocketClient = class {
|
|
3504
3683
|
addInfo(msg) {
|
|
3505
3684
|
this.debugMessages.push({
|
|
@@ -3534,7 +3713,17 @@ var ResilientWebSocketClient = class {
|
|
|
3534
3713
|
this.currentWS = null;
|
|
3535
3714
|
this.isOpen = false;
|
|
3536
3715
|
}
|
|
3537
|
-
|
|
3716
|
+
/** headerless transports carry the api key as ?token= — everything else is refused loud */
|
|
3717
|
+
headerlessUrl(headers) {
|
|
3718
|
+
const rest = { ...headers };
|
|
3719
|
+
const apiKey = rest["X-API-Key"];
|
|
3720
|
+
delete rest["X-API-Key"];
|
|
3721
|
+
const extra = Object.keys(rest);
|
|
3722
|
+
if (extra.length > 0) throw new Error(`custom ws headers (${extra.join(", ")}) need the 'ws' package — a browser WebSocket cannot set upgrade headers`);
|
|
3723
|
+
if (apiKey == null) return this.url;
|
|
3724
|
+
return this.url + (this.url.includes("?") ? "&" : "?") + "token=" + encodeURIComponent(apiKey);
|
|
3725
|
+
}
|
|
3726
|
+
async connect() {
|
|
3538
3727
|
this.isOpen = false;
|
|
3539
3728
|
const prevWS = this.currentWS;
|
|
3540
3729
|
if (this.reconnectTimeout) clearTimeout(this.reconnectTimeout);
|
|
@@ -3543,30 +3732,41 @@ var ResilientWebSocketClient = class {
|
|
|
3543
3732
|
this.addInfo("Previous WebSocket discarded");
|
|
3544
3733
|
prevWS.close();
|
|
3545
3734
|
}
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3735
|
+
let ws;
|
|
3736
|
+
try {
|
|
3737
|
+
const transport = await resolveWsTransport();
|
|
3738
|
+
if (this.permanentlyClosed) return;
|
|
3739
|
+
const headers = this.options.headers?.() ?? {};
|
|
3740
|
+
ws = transport.supportsHeaders ? new transport.ctor(this.url, { headers }) : new transport.ctor(this.headerlessUrl(headers));
|
|
3741
|
+
} catch (e) {
|
|
3742
|
+
this.addError(`cannot open WebSocket: ${extractErrorMessage(e)}`);
|
|
3743
|
+
this.permanentlyClosed = true;
|
|
3744
|
+
this.options.onTransportDead?.(e);
|
|
3745
|
+
return;
|
|
3746
|
+
}
|
|
3747
|
+
ws.binaryType = "arraybuffer";
|
|
3748
|
+
this.currentWS = ws;
|
|
3749
|
+
ws.onmessage = (event) => {
|
|
3550
3750
|
this.options.onMessage(event);
|
|
3551
3751
|
};
|
|
3552
|
-
ws
|
|
3553
|
-
if (ws
|
|
3752
|
+
ws.onopen = () => {
|
|
3753
|
+
if (ws !== this.currentWS) return;
|
|
3554
3754
|
this.addInfo("✅ WebSocket connected to " + this.url);
|
|
3555
3755
|
this.isOpen = true;
|
|
3556
3756
|
this.options.onConnectOrReconnect();
|
|
3557
3757
|
this.flushMessageBuffer();
|
|
3558
3758
|
};
|
|
3559
|
-
ws
|
|
3560
|
-
if (ws
|
|
3759
|
+
ws.onclose = (event) => {
|
|
3760
|
+
if (ws !== this.currentWS) return;
|
|
3561
3761
|
this.isOpen = false;
|
|
3562
3762
|
this.options.onClose();
|
|
3563
3763
|
if (this.permanentlyClosed) return;
|
|
3564
3764
|
this.addError(`WebSocket closed (reason=${JSON.stringify(event.reason)}, code=${event.code})`);
|
|
3565
3765
|
this.addInfo("⏱️ reconnecting in 2 seconds...");
|
|
3566
|
-
this.reconnectTimeout = setTimeout(() => this.connect(), 2e3);
|
|
3766
|
+
this.reconnectTimeout = setTimeout(() => void this.connect(), 2e3);
|
|
3567
3767
|
};
|
|
3568
|
-
ws
|
|
3569
|
-
if (ws
|
|
3768
|
+
ws.onerror = (event) => {
|
|
3769
|
+
if (ws !== this.currentWS) return;
|
|
3570
3770
|
this.addError(`WebSocket ERROR` + JSON.stringify(event));
|
|
3571
3771
|
console.error({ event });
|
|
3572
3772
|
};
|
|
@@ -3581,14 +3781,6 @@ var ResilientWebSocketClient = class {
|
|
|
3581
3781
|
this.currentWS?.send(message);
|
|
3582
3782
|
}
|
|
3583
3783
|
}
|
|
3584
|
-
/** forward WebSocket add event listeners to the current WebSocket instance */
|
|
3585
|
-
addEventListener(type, listener, options) {
|
|
3586
|
-
this.currentWS?.addEventListener(type, listener, options);
|
|
3587
|
-
}
|
|
3588
|
-
/** forward WebSocket remove event listeners to the current WebSocket instance */
|
|
3589
|
-
removeEventListener(type, listener) {
|
|
3590
|
-
this.currentWS?.removeEventListener(type, listener);
|
|
3591
|
-
}
|
|
3592
3784
|
};
|
|
3593
3785
|
//#endregion
|
|
3594
3786
|
//#region src/vars/loraKeywords.ts
|
|
@@ -3608,9 +3800,10 @@ function loadOnce() {
|
|
|
3608
3800
|
if (loaded) return;
|
|
3609
3801
|
loaded = true;
|
|
3610
3802
|
const path = filePath();
|
|
3611
|
-
|
|
3803
|
+
const text = getComfyStorage().readTextIfExists(path);
|
|
3804
|
+
if (text == null) return;
|
|
3612
3805
|
try {
|
|
3613
|
-
const raw = JSON.parse(
|
|
3806
|
+
const raw = JSON.parse(text);
|
|
3614
3807
|
if (raw == null || typeof raw !== "object") return;
|
|
3615
3808
|
(0, mobx.runInAction)(() => {
|
|
3616
3809
|
for (const [name, kw] of Object.entries(raw)) if (typeof kw === "string") keywords.set(name, kw);
|
|
@@ -3633,8 +3826,7 @@ function setLoraKeyword(name, keyword) {
|
|
|
3633
3826
|
});
|
|
3634
3827
|
const path = filePath();
|
|
3635
3828
|
try {
|
|
3636
|
-
(
|
|
3637
|
-
(0, node_fs.writeFileSync)(path, JSON.stringify(Object.fromEntries([...keywords.entries()].sort()), null, 2));
|
|
3829
|
+
getComfyStorage().writeText(path, JSON.stringify(Object.fromEntries([...keywords.entries()].sort()), null, 2));
|
|
3638
3830
|
} catch (e) {
|
|
3639
3831
|
logError(`[loraKeywords] write failed ${path}: ${String(e)}`);
|
|
3640
3832
|
}
|
|
@@ -4078,7 +4270,7 @@ var SizeVar = class extends ComfyVar {
|
|
|
4078
4270
|
if (iv == null || iv.value === "") return null;
|
|
4079
4271
|
try {
|
|
4080
4272
|
const abs = iv.absPath();
|
|
4081
|
-
const meta = (0, image_meta.imageMeta)(
|
|
4273
|
+
const meta = (0, image_meta.imageMeta)(getComfyStorage().readBytes(abs));
|
|
4082
4274
|
if (meta.width == null || meta.height == null) return null;
|
|
4083
4275
|
return {
|
|
4084
4276
|
width: meta.width,
|
|
@@ -4132,7 +4324,7 @@ var ImageVarEmptyError = class extends Error {
|
|
|
4132
4324
|
/** trim + expand a leading `~/` — every ImageVar write funnels through this */
|
|
4133
4325
|
function expandUserPath(raw) {
|
|
4134
4326
|
const trimmed = raw.trim();
|
|
4135
|
-
return trimmed.startsWith("~/") ? (0, pathe.join)((
|
|
4327
|
+
return trimmed.startsWith("~/") ? (0, pathe.join)(getComfyStorage().homedir(), trimmed.slice(2)) : trimmed;
|
|
4136
4328
|
}
|
|
4137
4329
|
/**
|
|
4138
4330
|
* a local image path. The VALUE is a PLAIN PATH STRING — text-encodable,
|
|
@@ -4168,7 +4360,7 @@ var ImageVar = class extends ComfyVar {
|
|
|
4168
4360
|
absPath() {
|
|
4169
4361
|
if (!this.isSet()) throw this.emptyError();
|
|
4170
4362
|
if ((0, pathe.isAbsolute)(this.value)) return this.value;
|
|
4171
|
-
return (0, pathe.resolve)(this.opts.folder ??
|
|
4363
|
+
return (0, pathe.resolve)(this.opts.folder ?? getComfyStorage().cwd(), this.value);
|
|
4172
4364
|
}
|
|
4173
4365
|
/** empty = unset: the build fails LOUD here (varValues calls outValue) */
|
|
4174
4366
|
outValue() {
|
|
@@ -4177,7 +4369,7 @@ var ImageVar = class extends ComfyVar {
|
|
|
4177
4369
|
}
|
|
4178
4370
|
display() {
|
|
4179
4371
|
if (!this.isSet()) return "(unset) pick a file";
|
|
4180
|
-
const home = (
|
|
4372
|
+
const home = getComfyStorage().homedir();
|
|
4181
4373
|
return this.value.startsWith(`${home}/`) ? `~${this.value.slice(home.length)}` : this.value;
|
|
4182
4374
|
}
|
|
4183
4375
|
};
|
|
@@ -4475,11 +4667,11 @@ var ComfyHost = class {
|
|
|
4475
4667
|
this.isUpdatingSchema = true;
|
|
4476
4668
|
const object_info_json = await this.fetchJSON_("/object_info");
|
|
4477
4669
|
const object_info_str = readableStringify(object_info_json, 4);
|
|
4478
|
-
|
|
4670
|
+
getComfyStorage().writeText(this.comfyJSONPath, object_info_str);
|
|
4479
4671
|
const res = ComfySchemaJSON_ark(object_info_json);
|
|
4480
4672
|
if (res instanceof arktype.type.errors) printArkResultInConsole(res);
|
|
4481
4673
|
const embeddings_json = await this.fetchJSON_("/embeddings").catch(() => []);
|
|
4482
|
-
|
|
4674
|
+
getComfyStorage().writeText(this.embeddingsPath, JSON.stringify(embeddings_json));
|
|
4483
4675
|
this.schema.update({
|
|
4484
4676
|
spec: object_info_json,
|
|
4485
4677
|
embeddings: embeddings_json
|
|
@@ -4496,7 +4688,7 @@ var ComfyHost = class {
|
|
|
4496
4688
|
};
|
|
4497
4689
|
console.error(error);
|
|
4498
4690
|
console.error("🔴 FAILURE TO GENERATE the typed sdk", extractErrorMessage(error));
|
|
4499
|
-
if (!(
|
|
4691
|
+
if (!getComfyStorage().exists(this.sdkDTSPath)) await this.writeSDKToDisk();
|
|
4500
4692
|
this.markFailed(error);
|
|
4501
4693
|
} finally {
|
|
4502
4694
|
this.isUpdatingSchema = false;
|
|
@@ -4517,9 +4709,10 @@ var ComfyHost = class {
|
|
|
4517
4709
|
this.base = parseHostBase(this.data);
|
|
4518
4710
|
/** folder where file related to the host config will be cached */
|
|
4519
4711
|
this.cacheFolder = comfyts.resolveFromHosts(this.data.id);
|
|
4520
|
-
|
|
4712
|
+
const storage = getComfyStorage();
|
|
4713
|
+
if (!storage.exists(this.cacheFolder)) {
|
|
4521
4714
|
console.log("🟢 creating folder", this.cacheFolder);
|
|
4522
|
-
|
|
4715
|
+
storage.mkdirp(this.cacheFolder);
|
|
4523
4716
|
}
|
|
4524
4717
|
this.comfyJSONPath = comfyts.resolve(this.cacheFolder, `object_info.json`);
|
|
4525
4718
|
this.embeddingsPath = comfyts.resolve(this.cacheFolder, `embeddings.json`);
|
|
@@ -4569,19 +4762,20 @@ var ComfyHost = class {
|
|
|
4569
4762
|
}
|
|
4570
4763
|
async writeSDKToDisk() {
|
|
4571
4764
|
if (this.data.sdkAutoWrite === false) return;
|
|
4765
|
+
const storage = getComfyStorage();
|
|
4572
4766
|
const comfySchemaTs = this.schema.codegenDTS({ hostId: this.data.id });
|
|
4573
|
-
if (
|
|
4574
|
-
|
|
4767
|
+
if (storage.readTextIfExists(this.sdkDTSPath) === comfySchemaTs) return;
|
|
4768
|
+
storage.writeText(this.sdkDTSPath, comfySchemaTs);
|
|
4575
4769
|
}
|
|
4576
4770
|
shouldUseSchemaCache() {
|
|
4577
4771
|
if (this._schemaStrategy === "refresh") return false;
|
|
4578
|
-
const
|
|
4772
|
+
const mtimeMs = getComfyStorage().mtimeMs(this.comfyJSONPath);
|
|
4579
4773
|
if (this._schemaStrategy === "cache") {
|
|
4580
|
-
if (
|
|
4774
|
+
if (mtimeMs == null) throw new Error(`connect({schema:'cache'}) but no cache at ${this.comfyJSONPath}`);
|
|
4581
4775
|
return true;
|
|
4582
4776
|
}
|
|
4583
|
-
if (
|
|
4584
|
-
return Date.now() -
|
|
4777
|
+
if (mtimeMs == null) return false;
|
|
4778
|
+
return Date.now() - mtimeMs < this._schemaMaxAgeMs;
|
|
4585
4779
|
}
|
|
4586
4780
|
waitForSession(timeoutMs = 5e3) {
|
|
4587
4781
|
if (this.comfySessionId !== "temp") return Promise.resolve();
|
|
@@ -4616,6 +4810,7 @@ var ComfyHost = class {
|
|
|
4616
4810
|
onMessage: (e) => this.onMessage(e),
|
|
4617
4811
|
url: () => this.getWSUrl(),
|
|
4618
4812
|
headers: () => this.authHeaders(),
|
|
4813
|
+
onTransportDead: (e) => this.markFailed(e),
|
|
4619
4814
|
onClose: () => {
|
|
4620
4815
|
logInfo(`[👢] WEBSOCKET: closed connection to ComfyUI host ${this.data.id}`);
|
|
4621
4816
|
}
|
|
@@ -4635,7 +4830,7 @@ var ComfyHost = class {
|
|
|
4635
4830
|
* examples must still open in the TUI; run() fetches the real schema through
|
|
4636
4831
|
* connect() anyway). Not memoized in that case, so a later gen/connect retries. */
|
|
4637
4832
|
loadSchemaFromCache() {
|
|
4638
|
-
if (this._schemaFromCache == null && !(
|
|
4833
|
+
if (this._schemaFromCache == null && !getComfyStorage().exists(this.comfyJSONPath)) {
|
|
4639
4834
|
logError(`no schema cache for host '${this.data.id}' at ${this.comfyJSONPath} — continuing with base types (no node/model unions); run \`comfy-ts gen --id ${this.data.id} --host <url>\` or connect() once to create it`);
|
|
4640
4835
|
return Promise.resolve();
|
|
4641
4836
|
}
|
|
@@ -4647,7 +4842,7 @@ var ComfyHost = class {
|
|
|
4647
4842
|
embeddings: embeddings_json
|
|
4648
4843
|
});
|
|
4649
4844
|
this.schema.RUN_BASIC_CHECKS();
|
|
4650
|
-
if (!(
|
|
4845
|
+
if (!getComfyStorage().exists(this.sdkDTSPath)) await this.writeSDKToDisk();
|
|
4651
4846
|
})().catch((e) => {
|
|
4652
4847
|
this._schemaFromCache = null;
|
|
4653
4848
|
throw e;
|
|
@@ -4739,55 +4934,13 @@ var ComfyHost = class {
|
|
|
4739
4934
|
};
|
|
4740
4935
|
//#endregion
|
|
4741
4936
|
//#region src/utils/downloadFile.ts
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
* | }
|
|
4750
|
-
* | })()
|
|
4751
|
-
* |
|
|
4752
|
-
*/
|
|
4753
|
-
function downloadFile(url, outputPath, logPrefix = " - ") {
|
|
4754
|
-
(0, node_fs.mkdirSync)((0, pathe.dirname)(outputPath), { recursive: true });
|
|
4755
|
-
return new Promise((resolve, reject) => {
|
|
4756
|
-
node_https.default.get(url, (response) => {
|
|
4757
|
-
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
4758
|
-
const newUrl = response.headers.location;
|
|
4759
|
-
console.log(`Redirected to ${newUrl}`);
|
|
4760
|
-
resolve(downloadFile(newUrl, outputPath));
|
|
4761
|
-
return;
|
|
4762
|
-
}
|
|
4763
|
-
if (response.statusCode !== 200) {
|
|
4764
|
-
reject(`Failed to download file: Status Code ${response.statusCode}`);
|
|
4765
|
-
return;
|
|
4766
|
-
}
|
|
4767
|
-
const rawLen = response.headers["content-length"];
|
|
4768
|
-
if (rawLen == null) console.warn(`download file: progress not available because no content-length header in response.`);
|
|
4769
|
-
else {
|
|
4770
|
-
const totalSize = parseInt(rawLen, 10);
|
|
4771
|
-
let downloaded = 0;
|
|
4772
|
-
let lastLoggedPercentage = 0;
|
|
4773
|
-
response.on("data", (chunk) => {
|
|
4774
|
-
downloaded += chunk.length;
|
|
4775
|
-
const percentage = Math.round(downloaded / totalSize * 100);
|
|
4776
|
-
if (percentage >= lastLoggedPercentage + 1) {
|
|
4777
|
-
node_process.stdout.write(`\r${logPrefix}${percentage}% downloaded`);
|
|
4778
|
-
lastLoggedPercentage = percentage;
|
|
4779
|
-
}
|
|
4780
|
-
});
|
|
4781
|
-
}
|
|
4782
|
-
const fileStream = node_fs.default.createWriteStream(outputPath);
|
|
4783
|
-
response.pipe(fileStream);
|
|
4784
|
-
fileStream.on("finish", () => {
|
|
4785
|
-
console.log(` (DONE)`);
|
|
4786
|
-
fileStream.close();
|
|
4787
|
-
resolve(true);
|
|
4788
|
-
});
|
|
4789
|
-
}).on("error", (err) => reject(err));
|
|
4790
|
-
});
|
|
4937
|
+
async function downloadFile(url, outputPath, logPrefix = " - ") {
|
|
4938
|
+
const res = await fetch(url);
|
|
4939
|
+
if (!res.ok) throw new Error(`Failed to download ${url}: HTTP ${res.status}`);
|
|
4940
|
+
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
4941
|
+
getComfyStorage().writeBytes(outputPath, bytes);
|
|
4942
|
+
console.log(`${logPrefix}${(bytes.length / 1024).toFixed(0)}kB (DONE)`);
|
|
4943
|
+
return true;
|
|
4791
4944
|
}
|
|
4792
4945
|
//#endregion
|
|
4793
4946
|
//#region src/manager/loaders/step1_downloadComfyManagerJSONs.ts
|
|
@@ -4908,7 +5061,7 @@ const ComfyManagerRawPluginInfo_ark = (0, arktype.type)({
|
|
|
4908
5061
|
const _getKnownPlugins = (DB) => {
|
|
4909
5062
|
const counter = DB.report.file("custom-node-list.json");
|
|
4910
5063
|
let totalFileSeen = 0;
|
|
4911
|
-
const root = ComfyManagerFilePluginListRoot_ark(JSON.parse((
|
|
5064
|
+
const root = ComfyManagerFilePluginListRoot_ark(JSON.parse(getComfyStorage().readText("src/manager/json/custom-node-list.json")));
|
|
4912
5065
|
if (root instanceof arktype.type.errors) throw new ManagerParseError("custom-node-list.json", root.summary);
|
|
4913
5066
|
const canonical = [];
|
|
4914
5067
|
for (const row of root.custom_nodes) {
|
|
@@ -4946,7 +5099,7 @@ const _getKnownPlugins = (DB) => {
|
|
|
4946
5099
|
}
|
|
4947
5100
|
out1 += "\n";
|
|
4948
5101
|
const out1Path = "src/manager/generated/KnownComfyPluginTitle.ts";
|
|
4949
|
-
(
|
|
5102
|
+
getComfyStorage().writeText(out1Path, out1 + "\n");
|
|
4950
5103
|
console.log(` > generated: ${ansi.blue.underline(out1Path)}`);
|
|
4951
5104
|
let out2 = "";
|
|
4952
5105
|
const sortedFileNames = [...DB.plugins_byFile.keys()].sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
|
|
@@ -4954,7 +5107,7 @@ const _getKnownPlugins = (DB) => {
|
|
|
4954
5107
|
out2 += "export type KnownComfyPluginURL =\n";
|
|
4955
5108
|
for (const fileName of sortedFileNames) out2 += ` | ${JSON.stringify(fileName)}\n`;
|
|
4956
5109
|
const out2Path = "src/manager/generated/KnownComfyPluginURL.ts";
|
|
4957
|
-
(
|
|
5110
|
+
getComfyStorage().writeText(out2Path, out2);
|
|
4958
5111
|
console.log(` > generated: ${ansi.blue.underline(out2Path)}`);
|
|
4959
5112
|
}
|
|
4960
5113
|
if (DB.opts.check) {
|
|
@@ -5000,7 +5153,7 @@ const ComfyManagerExtensionNodeMapEntry_ark = (0, arktype.type)([ComfyManagerPlu
|
|
|
5000
5153
|
const _getCustomNodeRegistry = (DB) => {
|
|
5001
5154
|
const counter = DB.report.file("extension-node-map.json");
|
|
5002
5155
|
let totalCustomNodeSeen = 0;
|
|
5003
|
-
const raw = JSON.parse((
|
|
5156
|
+
const raw = JSON.parse(getComfyStorage().readText("src/manager/json/extension-node-map.json"));
|
|
5004
5157
|
const root = (0, arktype.type)("Record<string, unknown>")(raw);
|
|
5005
5158
|
if (root instanceof arktype.type.errors) throw new ManagerParseError("extension-node-map.json", root.summary);
|
|
5006
5159
|
for (const [url, value] of Object.entries(root)) {
|
|
@@ -5036,7 +5189,7 @@ const _getCustomNodeRegistry = (DB) => {
|
|
|
5036
5189
|
for (const nodeName of sortedNodeKeys) out += ` | ${JSON.stringify(nodeName)}\n`;
|
|
5037
5190
|
out += "\n";
|
|
5038
5191
|
const outPath = "src/manager/generated/KnownComfyCustomNodeName.ts";
|
|
5039
|
-
(
|
|
5192
|
+
getComfyStorage().writeText(outPath, out + "\n");
|
|
5040
5193
|
console.log(` > generated: ${ansi.blue.underline(outPath)}`);
|
|
5041
5194
|
}
|
|
5042
5195
|
if (DB.opts.check) {
|
|
@@ -5091,7 +5244,7 @@ const ComfyManagerModelInfo_ark = (0, arktype.type)({
|
|
|
5091
5244
|
//#region src/manager/loaders/step4_model-list-loader.ts
|
|
5092
5245
|
const _getKnownModels = (DB) => {
|
|
5093
5246
|
const counter = DB.report.file("model-list.json");
|
|
5094
|
-
const root = ComfyManagerFileModelInfoRoot_ark(JSON.parse((
|
|
5247
|
+
const root = ComfyManagerFileModelInfoRoot_ark(JSON.parse(getComfyStorage().readText("src/manager/json/model-list.json")));
|
|
5095
5248
|
if (root instanceof arktype.type.errors) throw new ManagerParseError("model-list.json", root.summary);
|
|
5096
5249
|
const canonical = [];
|
|
5097
5250
|
for (const row of root.models) {
|
|
@@ -5120,7 +5273,7 @@ const _getKnownModels = (DB) => {
|
|
|
5120
5273
|
for (const [cat, count] of Object.entries(uniqCategories)) out1 += ` ${JSON.stringify(cat).padEnd(20)}, // x ${count.toString().padStart(3)}\n`;
|
|
5121
5274
|
out1 += "]\n";
|
|
5122
5275
|
const out1Path = "src/manager/generated/KnownModel_Type.ts";
|
|
5123
|
-
(
|
|
5276
|
+
getComfyStorage().writeText(out1Path, out1 + "\n");
|
|
5124
5277
|
console.log(` > generated: ${ansi.blue.underline(out1Path)}`);
|
|
5125
5278
|
let out4 = "";
|
|
5126
5279
|
const uniqSavePath = knownModelList.reduce((acc, cur) => {
|
|
@@ -5136,7 +5289,7 @@ const _getKnownModels = (DB) => {
|
|
|
5136
5289
|
for (const [cat, count] of Object.entries(uniqSavePath)) out4 += ` ${JSON.stringify(cat).padEnd(50)}, // x ${count.toString().padStart(3)}\n`;
|
|
5137
5290
|
out4 += "]\n";
|
|
5138
5291
|
const out4Path = "src/manager/generated/KnownModel_SavePath.ts";
|
|
5139
|
-
(
|
|
5292
|
+
getComfyStorage().writeText(out4Path, out4 + "\n");
|
|
5140
5293
|
console.log(` > generated: ${ansi.blue.underline(out4Path)}`);
|
|
5141
5294
|
let out2 = "";
|
|
5142
5295
|
const uniqBases = knownModelList.reduce((acc, cur) => {
|
|
@@ -5153,7 +5306,7 @@ const _getKnownModels = (DB) => {
|
|
|
5153
5306
|
for (const [cat, count] of Object.entries(uniqBases)) out2 += ` ${JSON.stringify(cat).padEnd(20)}, // x ${count.toString().padStart(3)}\n`;
|
|
5154
5307
|
out2 += "]\n";
|
|
5155
5308
|
const out2Path = "src/manager/generated/KnownModel_Base.ts";
|
|
5156
|
-
(
|
|
5309
|
+
getComfyStorage().writeText(out2Path, out2 + "\n");
|
|
5157
5310
|
console.log(` > generated: ${ansi.blue.underline(out2Path)}`);
|
|
5158
5311
|
let out3 = "";
|
|
5159
5312
|
const sortedModels = knownModelList.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
|
|
@@ -5168,7 +5321,7 @@ const _getKnownModels = (DB) => {
|
|
|
5168
5321
|
}
|
|
5169
5322
|
out3 += "\n";
|
|
5170
5323
|
const out3Path = "src/manager/generated/KnownModel_Name.ts";
|
|
5171
|
-
(
|
|
5324
|
+
getComfyStorage().writeText(out3Path, out3 + "\n");
|
|
5172
5325
|
console.log(` > generated: ${ansi.blue.underline(out3Path)}`);
|
|
5173
5326
|
let out99 = "";
|
|
5174
5327
|
out99 += `// prettier-ignore\n`;
|
|
@@ -5182,7 +5335,7 @@ const _getKnownModels = (DB) => {
|
|
|
5182
5335
|
}
|
|
5183
5336
|
out99 += "\n";
|
|
5184
5337
|
const out99Path = "src/manager/generated/KnownModel_FileName.ts";
|
|
5185
|
-
(
|
|
5338
|
+
getComfyStorage().writeText(out99Path, out99 + "\n");
|
|
5186
5339
|
console.log(` > generated: ${ansi.blue.underline(out99Path)}`);
|
|
5187
5340
|
}
|
|
5188
5341
|
if (DB.opts.check) {
|
|
@@ -5203,7 +5356,7 @@ const ComfyManagerFileAlterListRoot_ark = (0, arktype.type)({ items: "unknown[]"
|
|
|
5203
5356
|
//#region src/manager/loaders/step5_alter-list-loader.ts
|
|
5204
5357
|
const _getAlterList = (DB) => {
|
|
5205
5358
|
const counter = DB.report.file("alter-list.json");
|
|
5206
|
-
const root = ComfyManagerFileAlterListRoot_ark(JSON.parse((
|
|
5359
|
+
const root = ComfyManagerFileAlterListRoot_ark(JSON.parse(getComfyStorage().readText("src/manager/json/alter-list.json")));
|
|
5207
5360
|
if (root instanceof arktype.type.errors) throw new ManagerParseError("alter-list.json", root.summary);
|
|
5208
5361
|
const canonical = [];
|
|
5209
5362
|
for (const row of root.items) {
|
|
@@ -5228,7 +5381,7 @@ const ComfyManagerGithubStatEntry_ark = (0, arktype.type)({
|
|
|
5228
5381
|
//#region src/manager/loaders/step6_github-stats-loader.ts
|
|
5229
5382
|
const _getGithubStats = (DB) => {
|
|
5230
5383
|
const counter = DB.report.file("github-stats.json");
|
|
5231
|
-
const raw = JSON.parse((
|
|
5384
|
+
const raw = JSON.parse(getComfyStorage().readText("src/manager/json/github-stats.json"));
|
|
5232
5385
|
const root = (0, arktype.type)("Record<string, unknown>")(raw);
|
|
5233
5386
|
if (root instanceof arktype.type.errors) throw new ManagerParseError("github-stats.json", root.summary);
|
|
5234
5387
|
for (const [url, value] of Object.entries(root)) {
|
|
@@ -5343,13 +5496,12 @@ var ComfyTS = class ComfyTS {
|
|
|
5343
5496
|
this.version = version;
|
|
5344
5497
|
this.hosts = /* @__PURE__ */ new Map();
|
|
5345
5498
|
this._registry = null;
|
|
5346
|
-
this.rootPath = asAbsolutePath(process.cwd());
|
|
5347
5499
|
this.readJSON_ = (absPath, def) => {
|
|
5348
|
-
|
|
5500
|
+
const str = this.storage.readTextIfExists(absPath);
|
|
5501
|
+
if (str == null) {
|
|
5349
5502
|
if (def != null) return def;
|
|
5350
5503
|
throw new Error(`file does not exist ${absPath}`);
|
|
5351
5504
|
}
|
|
5352
|
-
const str = (0, node_fs.readFileSync)(absPath, "utf8");
|
|
5353
5505
|
return JSON.parse(str);
|
|
5354
5506
|
};
|
|
5355
5507
|
this.autolayoutOpts = {
|
|
@@ -5360,7 +5512,8 @@ var ComfyTS = class ComfyTS {
|
|
|
5360
5512
|
const globalHack = globalThis;
|
|
5361
5513
|
if (globalHack.comfyts != null) throw new Error("ComfyTS instance already created");
|
|
5362
5514
|
globalHack.comfyts = this;
|
|
5363
|
-
|
|
5515
|
+
this.storage = resolveComfyStorage(p.storage);
|
|
5516
|
+
this.rootPath = asAbsolutePath(p.rootPath ?? this.storage.cwd());
|
|
5364
5517
|
this.baseFolder = asAbsolutePath((0, pathe.join)(this.rootPath, ".comfy-ts"));
|
|
5365
5518
|
this.hostsFolder = asAbsolutePath((0, pathe.join)(this.baseFolder, "hosts"));
|
|
5366
5519
|
this.outputPath = asAbsolutePath((0, pathe.join)(this.baseFolder, "outputs"));
|
|
@@ -5424,6 +5577,18 @@ var ComfyTS = class ComfyTS {
|
|
|
5424
5577
|
}
|
|
5425
5578
|
};
|
|
5426
5579
|
//#endregion
|
|
5580
|
+
//#region src/utils/loraTag.ts
|
|
5581
|
+
/**
|
|
5582
|
+
* build a LoraManager-style lora tag: `<lora:name:strength>` or
|
|
5583
|
+
* `<lora:name:strength:clipStrength>`. Pin the name to a host union for
|
|
5584
|
+
* autocomplete + validation:
|
|
5585
|
+
*
|
|
5586
|
+
* loraTag<Comfy.Windows1.Union['E_LoraName']>('myLora', 0.8)
|
|
5587
|
+
*/
|
|
5588
|
+
function loraTag(name, strength = 1, clipStrength) {
|
|
5589
|
+
return clipStrength == null ? `<lora:${name}:${strength}>` : `<lora:${name}:${strength}:${clipStrength}>`;
|
|
5590
|
+
}
|
|
5591
|
+
//#endregion
|
|
5427
5592
|
//#region src/exampleAssets.ts
|
|
5428
5593
|
/**
|
|
5429
5594
|
* the examples/ folder shipped in the npm tarball, resolved from THIS module's
|
|
@@ -5476,17 +5641,12 @@ function isTuiActive() {
|
|
|
5476
5641
|
return process.env[COMFY_TS_TUI_ENV] === "1";
|
|
5477
5642
|
}
|
|
5478
5643
|
//#endregion
|
|
5479
|
-
//#region src/
|
|
5644
|
+
//#region src/index.ts
|
|
5480
5645
|
/**
|
|
5481
|
-
*
|
|
5482
|
-
*
|
|
5483
|
-
* autocomplete + validation:
|
|
5484
|
-
*
|
|
5485
|
-
* loraTag<Comfy.Windows1.Union['E_LoraName']>('myLora', 0.8)
|
|
5646
|
+
* comfy-ts — type-safe ComfyUI workflow creation and execution (NODE entry)
|
|
5647
|
+
* @packageDocumentation
|
|
5486
5648
|
*/
|
|
5487
|
-
|
|
5488
|
-
return clipStrength == null ? `<lora:${name}:${strength}>` : `<lora:${name}:${strength}:${clipStrength}>`;
|
|
5489
|
-
}
|
|
5649
|
+
setDefaultComfyStorage(createNodeStorage());
|
|
5490
5650
|
//#endregion
|
|
5491
5651
|
exports.ChoiceVar = ChoiceVar;
|
|
5492
5652
|
exports.ComfyExecution = ComfyExecution;
|
|
@@ -5532,7 +5692,9 @@ exports.auto_ = auto_;
|
|
|
5532
5692
|
exports.codegenSDK = codegenSDK;
|
|
5533
5693
|
exports.convertFlowToLiteGraphJSON = convertFlowToLiteGraphJSON;
|
|
5534
5694
|
exports.convertLiteGraphToPrompt = convertLiteGraphToPrompt;
|
|
5695
|
+
exports.createMemoryStorage = createMemoryStorage;
|
|
5535
5696
|
exports.exampleImagePath = exampleImagePath;
|
|
5697
|
+
exports.getComfyStorage = getComfyStorage;
|
|
5536
5698
|
exports.getLoraKeyword = getLoraKeyword;
|
|
5537
5699
|
exports.hostIdToNamespace = hostIdToNamespace;
|
|
5538
5700
|
exports.isTuiActive = isTuiActive;
|
|
@@ -5544,6 +5706,7 @@ exports.renderHttpBase = renderHttpBase;
|
|
|
5544
5706
|
exports.renderWsUrl = renderWsUrl;
|
|
5545
5707
|
exports.resultFailure = resultFailure;
|
|
5546
5708
|
exports.resultSuccess = resultSuccess;
|
|
5709
|
+
exports.setDefaultComfyStorage = setDefaultComfyStorage;
|
|
5547
5710
|
exports.setLoraKeyword = setLoraKeyword;
|
|
5548
5711
|
exports.v = v;
|
|
5549
5712
|
|