comfy-ts 0.4.0 โ 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/README.md +349 -255
- package/dist/DefinedWorkflow-O3ynII3Y.js +598 -0
- package/dist/DefinedWorkflow-O3ynII3Y.js.map +1 -0
- package/dist/cli.js +3969 -128
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1167 -172
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +401 -115
- package/dist/index.d.ts +401 -115
- package/dist/index.js +1159 -173
- package/dist/index.js.map +1 -1
- package/dist/{run-tui-SDSJo1Qf.js โ run-tui-BFhba_oG.js} +132 -609
- package/dist/run-tui-BFhba_oG.js.map +1 -0
- package/examples/01-txt2img.cflow.ts +50 -0
- package/examples/02-img2img-upload.cflow.ts +66 -0
- package/examples/03-export-workflow-json.cflow.ts +56 -0
- package/examples/04-krea2-turbo-t2i.cflow.ts +125 -0
- package/examples/05-comfy-cloud.cflow.ts +67 -0
- package/examples/comfy-cloud/sdk.d.ts +122674 -0
- package/guide-for-agents.md +166 -0
- package/package.json +6 -1
- package/src/cli/comfy-ts-cli.ts +19 -2
- package/src/cli/gen.ts +21 -12
- package/src/cli/tui/components/TreePanel.tsx +15 -2
- package/src/cli/tui/discoverWorkflows.ts +79 -0
- package/src/cli/tui/run-tui.tsx +51 -23
- package/src/cli/tui/state/HostSt.ts +2 -3
- package/src/cli/tui/state/TreeSt.ts +30 -6
- package/src/cli/tui/state/TuiSt.ts +21 -3
- package/src/cli/tui/state/WorkflowsSt.ts +15 -1
- package/src/host/ComfyHost.ts +203 -77
- package/src/host/ComfyManager.ts +10 -9
- package/src/host/ComfyUploader.ts +1 -2
- package/src/host/ResilientWebsocket.ts +3 -1
- package/src/host/hostUrl.ts +59 -0
- package/src/host/loraManagerApi.ts +5 -4
- package/src/index.ts +20 -1
- package/src/litegraph/CanonicalWorkflow.ts +77 -0
- package/src/litegraph/LiteGraphGroup.ts +9 -7
- package/src/litegraph/LiteGraphJSON.ts +34 -13
- package/src/litegraph/LiteGraphLink.ts +32 -2
- package/src/litegraph/LiteGraphNode.ts +18 -33
- package/src/litegraph/LiteGraphNodeInput.ts +10 -8
- package/src/litegraph/LiteGraphNodeOutput.ts +2 -3
- package/src/litegraph/LiteGraphSubgraphDef.ts +74 -0
- package/src/litegraph/convertFlowToLiteGraphJSON.ts +4 -4
- package/src/litegraph/expandSubgraphs.ts +352 -0
- package/src/litegraph/normalizeWorkflow.ts +141 -0
- package/src/runner/ComfyExecution.ts +4 -5
- package/src/runner/ComfyWorkflow.ts +2 -2
- package/src/runner/wsBinaryFrame.ts +48 -0
- package/src/sdk-generator/Primitives.ts +6 -24
- package/src/sdk-generator/comfy-api-json.ts +3 -1
- package/src/sdk-generator/inputWidgetKind.ts +179 -0
- package/src/sdk-generator/litegraphToApiRequestPayload.ts +372 -96
- package/src/state.ts +13 -2
- package/dist/log-CdfgILde.js +0 -10
- package/dist/log-CdfgILde.js.map +0 -1
- package/dist/run-tui-SDSJo1Qf.js.map +0 -1
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "pathe";
|
|
3
|
+
import { action, makeObservable, observable, runInAction } from "mobx";
|
|
4
|
+
//#region src/utils/log.ts
|
|
5
|
+
const isQuiet = () => process.env.COMFY_TS_QUIET === "1";
|
|
6
|
+
const logInfo = (msg) => {
|
|
7
|
+
if (!isQuiet()) console.log(msg);
|
|
8
|
+
};
|
|
9
|
+
const logError = (msg) => console.error(`[comfy-ts] ๐ด ${msg}`);
|
|
10
|
+
const logSuccess = (msg) => console.log(`[comfy-ts] ๐ข ${msg}`);
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/utils/ansi.ts
|
|
13
|
+
const codes = {
|
|
14
|
+
bold: [1, 22],
|
|
15
|
+
underline: [4, 24],
|
|
16
|
+
red: [31, 39],
|
|
17
|
+
green: [32, 39],
|
|
18
|
+
yellow: [33, 39],
|
|
19
|
+
blue: [34, 39],
|
|
20
|
+
greenBright: [92, 39]
|
|
21
|
+
};
|
|
22
|
+
function styler(open = "", close = "") {
|
|
23
|
+
const fn = (s) => open + s + close;
|
|
24
|
+
return new Proxy(fn, { get(_target, prop) {
|
|
25
|
+
const c = codes[prop];
|
|
26
|
+
if (c == null) throw new Error(`unknown ansi style: ${prop}`);
|
|
27
|
+
return styler(`${open}\x1b[${c[0]}m`, `\x1b[${c[1]}m${close}`);
|
|
28
|
+
} });
|
|
29
|
+
}
|
|
30
|
+
const ansi = styler();
|
|
31
|
+
const ANSI_RE = /\x1b\[[0-9;?]*[A-Za-z]|\x1b[A-Za-z]/g;
|
|
32
|
+
function stripAnsi(s) {
|
|
33
|
+
return s.replace(ANSI_RE, "");
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/utils/extractErrorMessage.ts
|
|
37
|
+
/** Extracts an error message from an exception stuff. */
|
|
38
|
+
const extractErrorMessage = (error) => {
|
|
39
|
+
if (error instanceof Error) return error.message;
|
|
40
|
+
if (error === null) return "null";
|
|
41
|
+
if (typeof error === "string") return error;
|
|
42
|
+
if (typeof error === "object") {
|
|
43
|
+
if ("message" in error && typeof error.message === "string") return error.message;
|
|
44
|
+
return JSON.stringify(error);
|
|
45
|
+
}
|
|
46
|
+
return String(error);
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/vars/loraKeywords.ts
|
|
50
|
+
/**
|
|
51
|
+
* hand-assigned trigger keyword(s) per lora name โ set via โK in the TUI loras
|
|
52
|
+
* overlay, consumed by PromptVar's `loraKeywordsFrom` prefixing. Persisted at
|
|
53
|
+
* `.comfy-ts/lora-keywords.json` (NOT under cache/: this is hand-entered data
|
|
54
|
+
* and must survive a cache wipe). Observable map: overlay rows re-render on
|
|
55
|
+
* assignment. Keys are the RAW lora names (folder/file.safetensors).
|
|
56
|
+
*/
|
|
57
|
+
const keywords = observable.map();
|
|
58
|
+
let loaded = false;
|
|
59
|
+
function filePath() {
|
|
60
|
+
return join(comfyts.baseFolder, "lora-keywords.json");
|
|
61
|
+
}
|
|
62
|
+
function loadOnce() {
|
|
63
|
+
if (loaded) return;
|
|
64
|
+
loaded = true;
|
|
65
|
+
const path = filePath();
|
|
66
|
+
if (!existsSync(path)) return;
|
|
67
|
+
try {
|
|
68
|
+
const raw = JSON.parse(readFileSync(path, "utf8"));
|
|
69
|
+
if (raw == null || typeof raw !== "object") return;
|
|
70
|
+
runInAction(() => {
|
|
71
|
+
for (const [name, kw] of Object.entries(raw)) if (typeof kw === "string") keywords.set(name, kw);
|
|
72
|
+
});
|
|
73
|
+
} catch (e) {
|
|
74
|
+
logError(`[loraKeywords] unreadable ${path}: ${String(e)}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function getLoraKeyword(name) {
|
|
78
|
+
loadOnce();
|
|
79
|
+
return keywords.get(name) ?? "";
|
|
80
|
+
}
|
|
81
|
+
/** empty keyword deletes the entry; every set writes the file (tiny, rare) */
|
|
82
|
+
function setLoraKeyword(name, keyword) {
|
|
83
|
+
loadOnce();
|
|
84
|
+
const trimmed = keyword.trim();
|
|
85
|
+
runInAction(() => {
|
|
86
|
+
if (trimmed === "") keywords.delete(name);
|
|
87
|
+
else keywords.set(name, trimmed);
|
|
88
|
+
});
|
|
89
|
+
const path = filePath();
|
|
90
|
+
try {
|
|
91
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
92
|
+
writeFileSync(path, JSON.stringify(Object.fromEntries([...keywords.entries()].sort()), null, 2));
|
|
93
|
+
} catch (e) {
|
|
94
|
+
logError(`[loraKeywords] write failed ${path}: ${String(e)}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/vars/ComfyVars.ts
|
|
99
|
+
/**
|
|
100
|
+
* full base: T is what's STORED/edited, Out what the GRAPH consumes at build
|
|
101
|
+
* time. They usually coincide โ extend `ComfyVar<T>` for that. PromptVar is
|
|
102
|
+
* the one Out-specialized var (string in, PromptValue out); the split keeps
|
|
103
|
+
* outValue() cast-free.
|
|
104
|
+
*/
|
|
105
|
+
var ComfyVarBase = class {
|
|
106
|
+
constructor(defaultValue, label) {
|
|
107
|
+
this.defaultValue = defaultValue;
|
|
108
|
+
this.label = label;
|
|
109
|
+
this.value = defaultValue;
|
|
110
|
+
makeObservable(this, {
|
|
111
|
+
value: observable,
|
|
112
|
+
set: action,
|
|
113
|
+
reset: action,
|
|
114
|
+
parse: action,
|
|
115
|
+
loadJSON: action
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
set(value) {
|
|
119
|
+
this.value = value;
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
/** what drafts persist for this var (subclasses may add fields, e.g. seed mode) */
|
|
123
|
+
toJSON() {
|
|
124
|
+
return this.value;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* restore a value produced by toJSON() (drafts). The cast is sanctioned:
|
|
128
|
+
* drafts are our own round-trip, subclasses re-validate via set().
|
|
129
|
+
*/
|
|
130
|
+
loadJSON(value) {
|
|
131
|
+
return this.set(value);
|
|
132
|
+
}
|
|
133
|
+
reset() {
|
|
134
|
+
this.value = this.defaultValue;
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
/** how the value renders in a var list */
|
|
138
|
+
display() {
|
|
139
|
+
return String(this.value);
|
|
140
|
+
}
|
|
141
|
+
/** the string the inline editor starts from (round-trips through parse) */
|
|
142
|
+
toEditBuffer() {
|
|
143
|
+
return String(this.value);
|
|
144
|
+
}
|
|
145
|
+
/** hook run after every DefinedWorkflow.run() (default no-op; SeedVar advances) */
|
|
146
|
+
afterRun() {}
|
|
147
|
+
};
|
|
148
|
+
/** the standard var: the graph consumes the stored value AS-IS (Out = T) */
|
|
149
|
+
var ComfyVar = class extends ComfyVarBase {
|
|
150
|
+
outValue() {
|
|
151
|
+
return this.value;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
var TextVar = class extends ComfyVar {
|
|
155
|
+
constructor(..._args) {
|
|
156
|
+
super(..._args);
|
|
157
|
+
this.kind = "text";
|
|
158
|
+
}
|
|
159
|
+
parse(raw) {
|
|
160
|
+
this.set(raw);
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const commentLineRe = /^\s*\/\//;
|
|
165
|
+
const negativeLineRe = /^\s*- (.*)$/;
|
|
166
|
+
/**
|
|
167
|
+
* prompt text with editor comforts, all resolved at BUILD time (the editor and
|
|
168
|
+
* drafts keep the raw text):
|
|
169
|
+
* - `//` lines are COMMENTS โ stripped
|
|
170
|
+
* - `- ` lines are NEGATIVE prompt lines โ removed from `.positive`,
|
|
171
|
+
* comma-joined into `.negative`
|
|
172
|
+
* - with `loraKeywordsFrom`, the ACTIVE loras' hand-assigned keywords
|
|
173
|
+
* (src/vars/loraKeywords.ts, โK in the TUI) prefix `.positive` โ
|
|
174
|
+
* `injectedKeywords()` is public so the TUI can PREVIEW the injection.
|
|
175
|
+
*/
|
|
176
|
+
var PromptVar = class extends ComfyVarBase {
|
|
177
|
+
constructor(defaultValue, promptOpts = {}) {
|
|
178
|
+
super(defaultValue, promptOpts.label);
|
|
179
|
+
this.promptOpts = promptOpts;
|
|
180
|
+
this.kind = "text";
|
|
181
|
+
}
|
|
182
|
+
parse(raw) {
|
|
183
|
+
this.set(raw);
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
static isCommentLine(line) {
|
|
187
|
+
return commentLineRe.test(line);
|
|
188
|
+
}
|
|
189
|
+
static isNegativeLine(line) {
|
|
190
|
+
return negativeLineRe.test(line);
|
|
191
|
+
}
|
|
192
|
+
/** the keyword prefix the flag will inject (deduped, lora-list order) โ the TUI previews this */
|
|
193
|
+
injectedKeywords() {
|
|
194
|
+
const src = this.promptOpts.loraKeywordsFrom;
|
|
195
|
+
if (src == null) return [];
|
|
196
|
+
return [...new Set(src.activeNames().map(getLoraKeyword).filter((k) => k !== ""))];
|
|
197
|
+
}
|
|
198
|
+
outValue() {
|
|
199
|
+
const pos = [];
|
|
200
|
+
const neg = [];
|
|
201
|
+
for (const line of this.value.split("\n")) {
|
|
202
|
+
if (commentLineRe.test(line)) continue;
|
|
203
|
+
const m = negativeLineRe.exec(line);
|
|
204
|
+
if (m != null) {
|
|
205
|
+
const text = (m[1] ?? "").trim();
|
|
206
|
+
if (text !== "") neg.push(text);
|
|
207
|
+
} else pos.push(line);
|
|
208
|
+
}
|
|
209
|
+
const body = pos.join("\n").trim();
|
|
210
|
+
const keywords = this.injectedKeywords();
|
|
211
|
+
return {
|
|
212
|
+
positive: keywords.length === 0 ? body : body === "" ? keywords.join(", ") : `${keywords.join(", ")}, ${body}`,
|
|
213
|
+
negative: neg.join(", ")
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
var IntVar = class extends ComfyVar {
|
|
218
|
+
constructor(defaultValue, opts = {}) {
|
|
219
|
+
super(defaultValue, opts.label);
|
|
220
|
+
this.opts = opts;
|
|
221
|
+
this.kind = "int";
|
|
222
|
+
}
|
|
223
|
+
set(value) {
|
|
224
|
+
const clamped = Math.round(Math.min(this.opts.max ?? Infinity, Math.max(this.opts.min ?? -Infinity, value)));
|
|
225
|
+
return super.set(clamped);
|
|
226
|
+
}
|
|
227
|
+
parse(raw) {
|
|
228
|
+
const n = Number(raw);
|
|
229
|
+
if (Number.isNaN(n)) return false;
|
|
230
|
+
this.set(n);
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
var FloatVar = class extends ComfyVar {
|
|
235
|
+
constructor(defaultValue, opts = {}) {
|
|
236
|
+
super(defaultValue, opts.label);
|
|
237
|
+
this.opts = opts;
|
|
238
|
+
this.kind = "float";
|
|
239
|
+
}
|
|
240
|
+
set(value) {
|
|
241
|
+
return super.set(Math.min(this.opts.max ?? Infinity, Math.max(this.opts.min ?? -Infinity, value)));
|
|
242
|
+
}
|
|
243
|
+
parse(raw) {
|
|
244
|
+
const n = Number(raw);
|
|
245
|
+
if (Number.isNaN(n)) return false;
|
|
246
|
+
this.set(n);
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* a seed is a MODE + a number. `value` stays a plain number (what the graph
|
|
252
|
+
* consumes); `mode` decides how it advances after each run (afterRun()):
|
|
253
|
+
* `= 12` fixed ยท `+ 0` auto-increment ยท `- 0` auto-decrement ยท `? 0` random.
|
|
254
|
+
* The number shown is always the seed the NEXT run will use.
|
|
255
|
+
*/
|
|
256
|
+
var SeedVar = class extends ComfyVar {
|
|
257
|
+
constructor(defaultValue = 0, label) {
|
|
258
|
+
super(defaultValue, label);
|
|
259
|
+
this.kind = "seed";
|
|
260
|
+
this.mode = "=";
|
|
261
|
+
makeObservable(this, {
|
|
262
|
+
mode: observable,
|
|
263
|
+
setMode: action,
|
|
264
|
+
randomize: action,
|
|
265
|
+
advance: action
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
setMode(mode) {
|
|
269
|
+
this.mode = mode;
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
randomize() {
|
|
273
|
+
return this.set(Math.floor(Math.random() * 2 ** 32));
|
|
274
|
+
}
|
|
275
|
+
set(value) {
|
|
276
|
+
return super.set(Math.max(0, Math.floor(value)));
|
|
277
|
+
}
|
|
278
|
+
/** move the seed to what the NEXT run should use, per mode */
|
|
279
|
+
advance() {
|
|
280
|
+
if (this.mode === "+") return this.set(this.value + 1);
|
|
281
|
+
if (this.mode === "-") return this.set(this.value - 1);
|
|
282
|
+
if (this.mode === "?") return this.randomize();
|
|
283
|
+
return this;
|
|
284
|
+
}
|
|
285
|
+
afterRun() {
|
|
286
|
+
this.advance();
|
|
287
|
+
}
|
|
288
|
+
/** parse `+` `- 12` `= 5` `?` or a bare number (=> fixed). Keeps the current number when none given */
|
|
289
|
+
parse(raw) {
|
|
290
|
+
const m = raw.trim().match(/^([+\-=?])?\s*(\d+)?$/);
|
|
291
|
+
if (m == null) return false;
|
|
292
|
+
const modeChar = m[1];
|
|
293
|
+
const numStr = m[2];
|
|
294
|
+
if (modeChar == null && numStr == null) return false;
|
|
295
|
+
this.setMode(modeChar == null ? "=" : modeChar);
|
|
296
|
+
if (numStr != null) this.set(Number(numStr));
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
display() {
|
|
300
|
+
return `${this.mode} ${this.value}`;
|
|
301
|
+
}
|
|
302
|
+
toEditBuffer() {
|
|
303
|
+
return `${this.mode} ${this.value}`;
|
|
304
|
+
}
|
|
305
|
+
toJSON() {
|
|
306
|
+
return {
|
|
307
|
+
mode: this.mode,
|
|
308
|
+
value: this.value
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
loadJSON(value) {
|
|
312
|
+
if (typeof value === "number") return this.set(value);
|
|
313
|
+
if (value != null && typeof value === "object") {
|
|
314
|
+
const o = value;
|
|
315
|
+
if (o.mode === "=" || o.mode === "+" || o.mode === "-" || o.mode === "?") this.setMode(o.mode);
|
|
316
|
+
if (typeof o.value === "number") this.set(o.value);
|
|
317
|
+
}
|
|
318
|
+
return this;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
var ToggleVar = class extends ComfyVar {
|
|
322
|
+
constructor(..._args2) {
|
|
323
|
+
super(..._args2);
|
|
324
|
+
this.kind = "toggle";
|
|
325
|
+
}
|
|
326
|
+
toggle() {
|
|
327
|
+
return this.set(!this.value);
|
|
328
|
+
}
|
|
329
|
+
parse(raw) {
|
|
330
|
+
if (raw !== "true" && raw !== "false") return false;
|
|
331
|
+
this.set(raw === "true");
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
display() {
|
|
335
|
+
return this.value ? "ON" : "OFF";
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
var ChoiceVar = class extends ComfyVar {
|
|
339
|
+
constructor(choices, defaultValue, label) {
|
|
340
|
+
super(defaultValue, label);
|
|
341
|
+
this.choices = choices;
|
|
342
|
+
this.kind = "choice";
|
|
343
|
+
}
|
|
344
|
+
next(delta = 1) {
|
|
345
|
+
const nextIx = (this.choices.indexOf(this.value) + delta + this.choices.length) % this.choices.length;
|
|
346
|
+
return this.set(this.choices[nextIx] ?? this.value);
|
|
347
|
+
}
|
|
348
|
+
parse(raw) {
|
|
349
|
+
const hit = this.choices.find((c) => c === raw);
|
|
350
|
+
if (hit == null) return false;
|
|
351
|
+
this.set(hit);
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
/**
|
|
356
|
+
* multi-select lora stack over a DYNAMIC options list โ a RegExp resolves
|
|
357
|
+
* against the host's loras at define time (DefinedWorkflow calls bindHost),
|
|
358
|
+
* or feed it host discovery (`host.schema.getLoras(regex?)`) directly; never
|
|
359
|
+
* a hardcoded inventory. Selection is empty by default.
|
|
360
|
+
*/
|
|
361
|
+
var LorasVar = class LorasVar extends ComfyVar {
|
|
362
|
+
constructor(optionsSource, initial = {}, label) {
|
|
363
|
+
super(initial, label);
|
|
364
|
+
this.optionsSource = optionsSource;
|
|
365
|
+
this.kind = "loras";
|
|
366
|
+
this.prev = {};
|
|
367
|
+
this.resolvedOptions = null;
|
|
368
|
+
}
|
|
369
|
+
get options() {
|
|
370
|
+
if (!(this.optionsSource instanceof RegExp)) return this.optionsSource;
|
|
371
|
+
if (this.resolvedOptions == null) throw new Error(`v.loras(${String(this.optionsSource)}) is host-bound โ it only works inside defineWorkflow({ vars }) (pass a name list otherwise)`);
|
|
372
|
+
return this.resolvedOptions;
|
|
373
|
+
}
|
|
374
|
+
/** DefinedWorkflow binds the host at define time: a RegExp source resolves here.
|
|
375
|
+
* cast: whitelist family 1 (agent/coding.md) โ getLoras() returns the runtime
|
|
376
|
+
* values of the SAME object_info enum the generated E_LoraName union comes from */
|
|
377
|
+
bindHost(host) {
|
|
378
|
+
if (!(this.optionsSource instanceof RegExp)) return;
|
|
379
|
+
this.resolvedOptions = host.schema.getLoras(this.optionsSource);
|
|
380
|
+
}
|
|
381
|
+
get names() {
|
|
382
|
+
return [...this.options];
|
|
383
|
+
}
|
|
384
|
+
/** loras currently ON (PromptVar keyword prefixing consumes this) */
|
|
385
|
+
activeNames() {
|
|
386
|
+
return this.names.filter((n) => this.isOn(n));
|
|
387
|
+
}
|
|
388
|
+
isOn(name) {
|
|
389
|
+
const s = this.value[name];
|
|
390
|
+
return s != null && s !== false;
|
|
391
|
+
}
|
|
392
|
+
toggleItem(name) {
|
|
393
|
+
const cur = this.value[name];
|
|
394
|
+
if (cur == null || cur === false) return this.set({
|
|
395
|
+
...this.value,
|
|
396
|
+
[name]: this.prev[name] ?? true
|
|
397
|
+
});
|
|
398
|
+
this.prev[name] = cur;
|
|
399
|
+
return this.set({
|
|
400
|
+
...this.value,
|
|
401
|
+
[name]: false
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
/** step both strengths by delta (true becomes 1 first); no-op when off */
|
|
405
|
+
adjustItem(name, delta) {
|
|
406
|
+
const cur = this.value[name];
|
|
407
|
+
if (cur == null || cur === false) return this;
|
|
408
|
+
const step = (n) => Math.max(0, Math.round((n + delta) * 100) / 100);
|
|
409
|
+
const next = Array.isArray(cur) ? [step(cur[0]), step(cur[1])] : step(cur === true ? 1 : cur);
|
|
410
|
+
return this.set({
|
|
411
|
+
...this.value,
|
|
412
|
+
[name]: next
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
/** compact per-item strength label for lists */
|
|
416
|
+
strengthLabel(name) {
|
|
417
|
+
const s = this.value[name];
|
|
418
|
+
if (s == null || s === false) return "";
|
|
419
|
+
if (s === true) return "1.00";
|
|
420
|
+
if (Array.isArray(s)) return `m:${s[0].toFixed(2)} c:${s[1].toFixed(2)}`;
|
|
421
|
+
return s.toFixed(2);
|
|
422
|
+
}
|
|
423
|
+
parse(raw) {
|
|
424
|
+
try {
|
|
425
|
+
const parsed = JSON.parse(raw);
|
|
426
|
+
if (typeof parsed !== "object" || parsed == null || Array.isArray(parsed)) return false;
|
|
427
|
+
this.set(parsed);
|
|
428
|
+
return true;
|
|
429
|
+
} catch {
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
/** short human name: subfolder + extension stripped */
|
|
434
|
+
static shortName(name) {
|
|
435
|
+
return (name.split(/[\\/]/).pop() ?? name).replace(/\.safetensors$/, "");
|
|
436
|
+
}
|
|
437
|
+
/** tick (true) or untick (false) every lora in `names` (default: all options) */
|
|
438
|
+
setAll(on, names = this.options) {
|
|
439
|
+
const next = { ...this.value };
|
|
440
|
+
for (const name of names) {
|
|
441
|
+
const cur = next[name];
|
|
442
|
+
if (on) {
|
|
443
|
+
if (cur == null || cur === false) next[name] = this.prev[name] ?? true;
|
|
444
|
+
} else {
|
|
445
|
+
if (cur != null && cur !== false) this.prev[name] = cur;
|
|
446
|
+
next[name] = false;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return this.set(next);
|
|
450
|
+
}
|
|
451
|
+
display() {
|
|
452
|
+
const on = this.activeNames();
|
|
453
|
+
if (on.length === 0) return `(0/${this.options.length}) none`;
|
|
454
|
+
return `(${on.length}/${this.options.length}) ${on.map((n) => LorasVar.shortName(n)).join(", ")}`;
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
/** SDXL-style ~1MP buckets, multiples of 64 โ safe for most latent models */
|
|
458
|
+
const DEFAULT_SIZE_PRESETS = [
|
|
459
|
+
{
|
|
460
|
+
label: "1:1 square",
|
|
461
|
+
width: 1024,
|
|
462
|
+
height: 1024
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
label: "4:3 landscape",
|
|
466
|
+
width: 1152,
|
|
467
|
+
height: 896
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
label: "3:4 portrait",
|
|
471
|
+
width: 896,
|
|
472
|
+
height: 1152
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
label: "3:2 landscape",
|
|
476
|
+
width: 1216,
|
|
477
|
+
height: 832
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
label: "2:3 portrait",
|
|
481
|
+
width: 832,
|
|
482
|
+
height: 1216
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
label: "16:9 widescreen",
|
|
486
|
+
width: 1344,
|
|
487
|
+
height: 768
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
label: "9:16 tall",
|
|
491
|
+
width: 768,
|
|
492
|
+
height: 1344
|
|
493
|
+
}
|
|
494
|
+
];
|
|
495
|
+
/** width/height picker: presets + free `WxH` entry */
|
|
496
|
+
var SizeVar = class extends ComfyVar {
|
|
497
|
+
constructor(defaultValue = {
|
|
498
|
+
width: 1024,
|
|
499
|
+
height: 1024
|
|
500
|
+
}, presets = DEFAULT_SIZE_PRESETS, label) {
|
|
501
|
+
super(defaultValue, label);
|
|
502
|
+
this.presets = presets;
|
|
503
|
+
this.kind = "size";
|
|
504
|
+
}
|
|
505
|
+
/** accepts '1024x768' / '1024ร768' / a preset label */
|
|
506
|
+
parse(raw) {
|
|
507
|
+
const m = raw.trim().match(/^(\d+)\s*[xร]\s*(\d+)$/);
|
|
508
|
+
if (m != null) {
|
|
509
|
+
this.set({
|
|
510
|
+
width: Number(m[1]),
|
|
511
|
+
height: Number(m[2])
|
|
512
|
+
});
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
const preset = this.presets.find((p) => p.label === raw.trim());
|
|
516
|
+
if (preset != null) {
|
|
517
|
+
this.set({
|
|
518
|
+
width: preset.width,
|
|
519
|
+
height: preset.height
|
|
520
|
+
});
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
display() {
|
|
526
|
+
const { width, height } = this.value;
|
|
527
|
+
const hit = this.presets.find((p) => p.width === width && p.height === height);
|
|
528
|
+
return `${width}ร${height}${hit ? ` (${hit.label})` : ""}`;
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
/** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.loras / v.size */
|
|
532
|
+
const v = {
|
|
533
|
+
text: (defaultValue, label) => new TextVar(defaultValue, label),
|
|
534
|
+
prompt: (defaultValue, opts = {}) => new PromptVar(defaultValue, opts),
|
|
535
|
+
int: (defaultValue, opts = {}) => new IntVar(defaultValue, opts),
|
|
536
|
+
float: (defaultValue, opts = {}) => new FloatVar(defaultValue, opts),
|
|
537
|
+
seed: (defaultValue = 0, label) => new SeedVar(defaultValue, label),
|
|
538
|
+
toggle: (defaultValue, label) => new ToggleVar(defaultValue, label),
|
|
539
|
+
choice: (choices, defaultValue, label) => new ChoiceVar(choices, defaultValue, label),
|
|
540
|
+
loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
|
|
541
|
+
size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets, opts.label)
|
|
542
|
+
};
|
|
543
|
+
function varValues(vars) {
|
|
544
|
+
const out = {};
|
|
545
|
+
for (const [k, varDef] of Object.entries(vars)) out[k] = varDef.outValue();
|
|
546
|
+
return out;
|
|
547
|
+
}
|
|
548
|
+
//#endregion
|
|
549
|
+
//#region src/vars/DefinedWorkflow.ts
|
|
550
|
+
/** type predicate (not a cast): a VarsSpec is a plain record, never callable */
|
|
551
|
+
function isVarsThunk(vars) {
|
|
552
|
+
return typeof vars === "function";
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* a re-runnable workflow definition: `build` re-executes per run with the
|
|
556
|
+
* current var values, so every run gets a fresh, deterministic graph.
|
|
557
|
+
*/
|
|
558
|
+
var DefinedWorkflow = class {
|
|
559
|
+
constructor(host, spec) {
|
|
560
|
+
this.host = host;
|
|
561
|
+
this.spec = spec;
|
|
562
|
+
this.lastWorkflow = null;
|
|
563
|
+
this.lastExecution = null;
|
|
564
|
+
this.vars = isVarsThunk(spec.vars) ? spec.vars(v) : spec.vars;
|
|
565
|
+
for (const [, varDef] of this.entries()) varDef.bindHost?.(this.host);
|
|
566
|
+
}
|
|
567
|
+
/** [name, var] pairs, for drivers that enumerate the knobs */
|
|
568
|
+
entries() {
|
|
569
|
+
return Object.entries(this.vars);
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* build a fresh graph from the CURRENT var values (no send). `p.advance`
|
|
573
|
+
* (set by run()) fires each var's afterRun() right after snapshotting the
|
|
574
|
+
* values โ atomically, before any await โ so the graph uses this run's seed
|
|
575
|
+
* while the var moves to the next (queued runs get distinct seeds; a bare
|
|
576
|
+
* build() for copy/export never advances).
|
|
577
|
+
*/
|
|
578
|
+
async build(p = {}) {
|
|
579
|
+
const wf = this.host.workflow({ id: this.spec.id });
|
|
580
|
+
const values = varValues(this.vars);
|
|
581
|
+
if (p.advance) for (const varDef of Object.values(this.vars)) varDef.afterRun();
|
|
582
|
+
await this.spec.build(wf.builder, values, wf);
|
|
583
|
+
this.lastWorkflow = wf;
|
|
584
|
+
return wf;
|
|
585
|
+
}
|
|
586
|
+
/** build a fresh graph from the current var values, send it, wait for outputs.
|
|
587
|
+
* connects first (idempotent) โ modules can import offline from the schema cache */
|
|
588
|
+
async run(settings = {}) {
|
|
589
|
+
await this.host.connect();
|
|
590
|
+
const execution = await (await this.build({ advance: true })).run(settings);
|
|
591
|
+
this.lastExecution = execution;
|
|
592
|
+
return execution;
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
//#endregion
|
|
596
|
+
export { setLoraKeyword as a, stripAnsi as c, logInfo as d, logSuccess as f, getLoraKeyword as i, isQuiet as l, LorasVar as n, extractErrorMessage as o, PromptVar as r, ansi as s, DefinedWorkflow as t, logError as u };
|
|
597
|
+
|
|
598
|
+
//# sourceMappingURL=DefinedWorkflow-O3ynII3Y.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefinedWorkflow-O3ynII3Y.js","names":[],"sources":["../src/utils/log.ts","../src/utils/ansi.ts","../src/utils/extractErrorMessage.ts","../src/vars/loraKeywords.ts","../src/vars/ComfyVars.ts","../src/vars/DefinedWorkflow.ts"],"sourcesContent":["// loud console logging; errors must be observable to human AND LLM.\n// COMFY_TS_QUIET=1 (set by drivers like the TUI) silences INFO chatter only โ\n// errors always print.\nexport const isQuiet = (): boolean => process.env.COMFY_TS_QUIET === '1'\nexport const logInfo = (msg: string): void => {\n if (!isQuiet()) console.log(msg)\n}\nexport const logError = (msg: string): void => console.error(`[comfy-ts] ๐ด ${msg}`)\nexport const logSuccess = (msg: string): void => console.log(`[comfy-ts] ๐ข ${msg}`)\n","// tiny chalk-compatible terminal styler (chainable), keeps chalk out of the deps\nconst codes = {\n bold: [1, 22],\n underline: [4, 24],\n red: [31, 39],\n green: [32, 39],\n yellow: [33, 39],\n blue: [34, 39],\n greenBright: [92, 39],\n} as const\n\ntype StyleName = keyof typeof codes\nexport type Styler = ((s: string) => string) & { [k in StyleName]: Styler }\n\nfunction styler(open: string = '', close: string = ''): Styler {\n const fn = (s: string): string => open + s + close\n return new Proxy(fn, {\n get(_target, prop: string) {\n const c = codes[prop as StyleName]\n if (c == null) throw new Error(`unknown ansi style: ${prop}`)\n return styler(`${open}\\x1b[${c[0]}m`, `\\x1b[${c[1]}m${close}`)\n },\n }) as Styler\n}\n\nexport const ansi: Styler = styler()\n\n// CSI sequences + lone ESC-letter escapes (server logs re-rendered inside ink)\nconst ANSI_RE = /\\x1b\\[[0-9;?]*[A-Za-z]|\\x1b[A-Za-z]/g\n\nexport function stripAnsi(s: string): string {\n return s.replace(ANSI_RE, '')\n}\n","/** Extracts an error message from an exception stuff. */\nexport const extractErrorMessage = (error: unknown): string => {\n if (error instanceof Error) return error.message\n if (error === null) return 'null'\n if (typeof error === 'string') return error\n if (typeof error === 'object') {\n if ('message' in error && typeof error.message === 'string') return error.message\n return JSON.stringify(error)\n }\n return String(error)\n}\n","import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { observable, runInAction } from 'mobx'\nimport { dirname, join } from 'pathe'\nimport { logError } from 'src/utils/log.ts'\n\n/**\n * hand-assigned trigger keyword(s) per lora name โ set via โK in the TUI loras\n * overlay, consumed by PromptVar's `loraKeywordsFrom` prefixing. Persisted at\n * `.comfy-ts/lora-keywords.json` (NOT under cache/: this is hand-entered data\n * and must survive a cache wipe). Observable map: overlay rows re-render on\n * assignment. Keys are the RAW lora names (folder/file.safetensors).\n */\nconst keywords = observable.map<string, string>()\nlet loaded = false\n\nfunction filePath(): string {\n return join(comfyts.baseFolder, 'lora-keywords.json')\n}\n\nfunction loadOnce(): void {\n if (loaded) return\n loaded = true\n const path = filePath()\n if (!existsSync(path)) return\n try {\n const raw: unknown = JSON.parse(readFileSync(path, 'utf8'))\n if (raw == null || typeof raw !== 'object') return\n runInAction(() => {\n for (const [name, kw] of Object.entries(raw)) if (typeof kw === 'string') keywords.set(name, kw)\n })\n } catch (e) {\n logError(`[loraKeywords] unreadable ${path}: ${String(e)}`)\n }\n}\n\nexport function getLoraKeyword(name: string): string {\n loadOnce()\n return keywords.get(name) ?? ''\n}\n\n/** empty keyword deletes the entry; every set writes the file (tiny, rare) */\nexport function setLoraKeyword(name: string, keyword: string): void {\n loadOnce()\n const trimmed = keyword.trim()\n runInAction(() => {\n if (trimmed === '') keywords.delete(name)\n else keywords.set(name, trimmed)\n })\n const path = filePath()\n try {\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, JSON.stringify(Object.fromEntries([...keywords.entries()].sort()), null, 2))\n } catch (e) {\n logError(`[loraKeywords] write failed ${path}: ${String(e)}`)\n }\n}\n","// Vars: the standard \"tweak & re-run\" contract. A workflow defined via\n// host.defineWorkflow({ vars, build }) rebuilds its graph from current var\n// values on every run โ drivers (scripts, the TUI) edit vars between runs.\nimport { action, makeObservable, observable } from 'mobx'\nimport { getLoraKeyword } from 'src/vars/loraKeywords.ts'\n\nexport type VarKind = 'text' | 'int' | 'float' | 'seed' | 'toggle' | 'choice' | 'loras' | 'size'\n\n/**\n * full base: T is what's STORED/edited, Out what the GRAPH consumes at build\n * time. They usually coincide โ extend `ComfyVar<T>` for that. PromptVar is\n * the one Out-specialized var (string in, PromptValue out); the split keeps\n * outValue() cast-free.\n */\nexport abstract class ComfyVarBase<T, Out> {\n abstract readonly kind: VarKind\n value: T\n constructor(\n public readonly defaultValue: T,\n public label?: string,\n ) {\n this.value = defaultValue\n // observable value: the TUI (mobx) re-renders when drivers mutate vars.\n // explicit makeObservable (not makeAutoObservable): base-class + subclass\n // combo. All mutators funnel through set()/reset()/parse() so they are\n // actions โ subclass helpers call this.set(...) rather than assigning.\n makeObservable(this, { value: observable, set: action, reset: action, parse: action, loadJSON: action })\n }\n set(value: T): this {\n this.value = value\n return this\n }\n /** what drafts persist for this var (subclasses may add fields, e.g. seed mode) */\n toJSON(): unknown {\n return this.value\n }\n /** what the GRAPH consumes at build time (varValues maps these return types) */\n abstract outValue(): Out\n /**\n * restore a value produced by toJSON() (drafts). The cast is sanctioned:\n * drafts are our own round-trip, subclasses re-validate via set().\n */\n loadJSON(value: unknown): this {\n return this.set(value as T)\n }\n reset(): this {\n this.value = this.defaultValue\n return this\n }\n /** parse a raw string (TUI text input) into this var's value; returns false when invalid */\n abstract parse(raw: string): boolean\n /** how the value renders in a var list */\n display(): string {\n return String(this.value)\n }\n /** the string the inline editor starts from (round-trips through parse) */\n toEditBuffer(): string {\n return String(this.value)\n }\n /** hook run after every DefinedWorkflow.run() (default no-op; SeedVar advances) */\n afterRun(): void {}\n}\n\n/** the standard var: the graph consumes the stored value AS-IS (Out = T) */\nexport abstract class ComfyVar<T> extends ComfyVarBase<T, T> {\n outValue(): T {\n return this.value\n }\n}\n\nexport class TextVar extends ComfyVar<string> {\n readonly kind = 'text' as const\n parse(raw: string): boolean {\n this.set(raw)\n return true\n }\n}\n\nconst commentLineRe = /^\\s*\\/\\//\nconst negativeLineRe = /^\\s*- (.*)$/\n\n/** what PromptVar needs from a loras var: covariant face, so LorasVar<'a'|'b'> fits */\nexport type ActiveLoraSource = { activeNames(): string[] }\n\n/** what a prompt CONTRIBUTES to build: `vars.prompt.positive` / `.negative` */\nexport type PromptValue = { positive: string; negative: string }\n\n/**\n * prompt text with editor comforts, all resolved at BUILD time (the editor and\n * drafts keep the raw text):\n * - `//` lines are COMMENTS โ stripped\n * - `- ` lines are NEGATIVE prompt lines โ removed from `.positive`,\n * comma-joined into `.negative`\n * - with `loraKeywordsFrom`, the ACTIVE loras' hand-assigned keywords\n * (src/vars/loraKeywords.ts, โK in the TUI) prefix `.positive` โ\n * `injectedKeywords()` is public so the TUI can PREVIEW the injection.\n */\nexport class PromptVar extends ComfyVarBase<string, PromptValue> {\n readonly kind = 'text' as const\n constructor(\n defaultValue: string,\n public promptOpts: { label?: string; loraKeywordsFrom?: ActiveLoraSource } = {},\n ) {\n super(defaultValue, promptOpts.label)\n }\n parse(raw: string): boolean {\n this.set(raw)\n return true\n }\n static isCommentLine(line: string): boolean {\n return commentLineRe.test(line)\n }\n static isNegativeLine(line: string): boolean {\n return negativeLineRe.test(line)\n }\n /** the keyword prefix the flag will inject (deduped, lora-list order) โ the TUI previews this */\n injectedKeywords(): string[] {\n const src = this.promptOpts.loraKeywordsFrom\n if (src == null) return []\n return [\n ...new Set(\n src\n .activeNames()\n .map(getLoraKeyword)\n .filter((k) => k !== ''),\n ),\n ]\n }\n outValue(): PromptValue {\n const pos: string[] = []\n const neg: string[] = []\n for (const line of this.value.split('\\n')) {\n if (commentLineRe.test(line)) continue\n const m = negativeLineRe.exec(line)\n if (m != null) {\n const text = (m[1] ?? '').trim()\n if (text !== '') neg.push(text)\n } else pos.push(line)\n }\n const body = pos.join('\\n').trim()\n const keywords = this.injectedKeywords()\n const positive =\n keywords.length === 0 ? body : body === '' ? keywords.join(', ') : `${keywords.join(', ')}, ${body}`\n return { positive, negative: neg.join(', ') }\n }\n}\n\nexport class IntVar extends ComfyVar<number> {\n readonly kind = 'int' as const\n constructor(\n defaultValue: number,\n public opts: { min?: number; max?: number; label?: string } = {},\n ) {\n super(defaultValue, opts.label)\n }\n override set(value: number): this {\n const clamped = Math.round(Math.min(this.opts.max ?? Infinity, Math.max(this.opts.min ?? -Infinity, value)))\n return super.set(clamped)\n }\n parse(raw: string): boolean {\n const n = Number(raw)\n if (Number.isNaN(n)) return false\n this.set(n)\n return true\n }\n}\n\nexport class FloatVar extends ComfyVar<number> {\n readonly kind = 'float' as const\n constructor(\n defaultValue: number,\n public opts: { min?: number; max?: number; label?: string } = {},\n ) {\n super(defaultValue, opts.label)\n }\n override set(value: number): this {\n return super.set(Math.min(this.opts.max ?? Infinity, Math.max(this.opts.min ?? -Infinity, value)))\n }\n parse(raw: string): boolean {\n const n = Number(raw)\n if (Number.isNaN(n)) return false\n this.set(n)\n return true\n }\n}\n\n/** '=' fixed ยท '+' increment each run ยท '-' decrement each run ยท '?' reroll each run */\nexport type SeedMode = '=' | '+' | '-' | '?'\n\n/**\n * a seed is a MODE + a number. `value` stays a plain number (what the graph\n * consumes); `mode` decides how it advances after each run (afterRun()):\n * `= 12` fixed ยท `+ 0` auto-increment ยท `- 0` auto-decrement ยท `? 0` random.\n * The number shown is always the seed the NEXT run will use.\n */\nexport class SeedVar extends ComfyVar<number> {\n readonly kind = 'seed' as const\n mode: SeedMode = '='\n constructor(defaultValue: number = 0, label?: string) {\n super(defaultValue, label)\n // subclass-owned observable field (base makeObservable already ran in super)\n makeObservable(this, { mode: observable, setMode: action, randomize: action, advance: action })\n }\n setMode(mode: SeedMode): this {\n this.mode = mode\n return this\n }\n randomize(): this {\n return this.set(Math.floor(Math.random() * 2 ** 32))\n }\n override set(value: number): this {\n // seeds are unsigned: clamp at 0 so decrement can't go negative\n return super.set(Math.max(0, Math.floor(value)))\n }\n /** move the seed to what the NEXT run should use, per mode */\n advance(): this {\n if (this.mode === '+') return this.set(this.value + 1)\n if (this.mode === '-') return this.set(this.value - 1)\n if (this.mode === '?') return this.randomize()\n return this // '=' stays fixed\n }\n override afterRun(): void {\n this.advance()\n }\n /** parse `+` `- 12` `= 5` `?` or a bare number (=> fixed). Keeps the current number when none given */\n parse(raw: string): boolean {\n const m = raw.trim().match(/^([+\\-=?])?\\s*(\\d+)?$/)\n if (m == null) return false\n const modeChar = m[1]\n const numStr = m[2]\n if (modeChar == null && numStr == null) return false\n this.setMode(modeChar == null ? '=' : (modeChar as SeedMode))\n if (numStr != null) this.set(Number(numStr))\n return true\n }\n override display(): string {\n return `${this.mode} ${this.value}`\n }\n override toEditBuffer(): string {\n return `${this.mode} ${this.value}`\n }\n override toJSON(): unknown {\n return { mode: this.mode, value: this.value }\n }\n override loadJSON(value: unknown): this {\n if (typeof value === 'number') return this.set(value) // legacy plain-number drafts\n if (value != null && typeof value === 'object') {\n const o = value as { mode?: unknown; value?: unknown }\n if (o.mode === '=' || o.mode === '+' || o.mode === '-' || o.mode === '?') this.setMode(o.mode)\n if (typeof o.value === 'number') this.set(o.value)\n }\n return this\n }\n}\n\nexport class ToggleVar extends ComfyVar<boolean> {\n readonly kind = 'toggle' as const\n toggle(): this {\n return this.set(!this.value)\n }\n parse(raw: string): boolean {\n if (raw !== 'true' && raw !== 'false') return false\n this.set(raw === 'true')\n return true\n }\n override display(): string {\n return this.value ? 'ON' : 'OFF'\n }\n}\n\nexport class ChoiceVar<T extends string> extends ComfyVar<T> {\n readonly kind = 'choice' as const\n constructor(\n public readonly choices: readonly T[],\n defaultValue: T,\n label?: string,\n ) {\n super(defaultValue, label)\n }\n next(delta: number = 1): this {\n const ix = this.choices.indexOf(this.value)\n const nextIx = (ix + delta + this.choices.length) % this.choices.length\n return this.set(this.choices[nextIx] ?? this.value)\n }\n parse(raw: string): boolean {\n const hit = this.choices.find((c) => c === raw)\n if (hit == null) return false\n this.set(hit)\n return true\n }\n}\n\n/**\n * per-lora setting: false = off, true = 1/1, number = both strengths,\n * [strength_model, strength_clip] = each explicitly\n */\nexport type LoraStrength = boolean | number | [strengthModel: number, strengthClip: number]\n\nexport type ActiveLora<T extends string> = { lora_name: T; strength_model: number; strength_clip: number }\n\n/** normalize a loras record into what a standard LoraLoader chain consumes */\nexport function activeLoras<T extends string>(loras: Partial<Record<T, LoraStrength>>): ActiveLora<T>[] {\n const out: ActiveLora<T>[] = []\n for (const [lora_name, s] of Object.entries(loras) as [T, LoraStrength | undefined][]) {\n if (s == null || s === false) continue\n const [strength_model, strength_clip] = Array.isArray(s) ? s : s === true ? [1, 1] : [s, s]\n out.push({ lora_name, strength_model, strength_clip })\n }\n return out\n}\n\n/** what LorasVar.bindHost needs โ structural, so ComfyVars never imports ComfyHost */\nexport type LorasHost = { schema: { getLoras(filter?: RegExp): string[] } }\n\n/**\n * multi-select lora stack over a DYNAMIC options list โ a RegExp resolves\n * against the host's loras at define time (DefinedWorkflow calls bindHost),\n * or feed it host discovery (`host.schema.getLoras(regex?)`) directly; never\n * a hardcoded inventory. Selection is empty by default.\n */\nexport class LorasVar<T extends string> extends ComfyVar<Partial<Record<T, LoraStrength>>> {\n readonly kind = 'loras' as const\n /** last non-false strength per lora, so untick โ re-tick restores it */\n private prev: Partial<Record<T, LoraStrength>> = {}\n /** a RegExp source resolves lazily (bindHost) โ null until then */\n private resolvedOptions: readonly T[] | null = null\n\n constructor(\n private readonly optionsSource: readonly T[] | RegExp,\n initial: Partial<Record<T, LoraStrength>> = {},\n label?: string,\n ) {\n super(initial, label)\n }\n\n get options(): readonly T[] {\n if (!(this.optionsSource instanceof RegExp)) return this.optionsSource\n if (this.resolvedOptions == null)\n throw new Error(\n `v.loras(${String(this.optionsSource)}) is host-bound โ it only works inside defineWorkflow({ vars }) (pass a name list otherwise)`,\n )\n return this.resolvedOptions\n }\n\n /** DefinedWorkflow binds the host at define time: a RegExp source resolves here.\n * cast: whitelist family 1 (agent/coding.md) โ getLoras() returns the runtime\n * values of the SAME object_info enum the generated E_LoraName union comes from */\n bindHost(host: LorasHost): void {\n if (!(this.optionsSource instanceof RegExp)) return\n this.resolvedOptions = host.schema.getLoras(this.optionsSource) as T[]\n }\n\n get names(): T[] {\n return [...this.options]\n }\n\n /** loras currently ON (PromptVar keyword prefixing consumes this) */\n activeNames(): T[] {\n return this.names.filter((n) => this.isOn(n))\n }\n\n isOn(name: T): boolean {\n const s = this.value[name]\n return s != null && s !== false\n }\n\n toggleItem(name: T): this {\n const cur = this.value[name]\n if (cur == null || cur === false) return this.set({ ...this.value, [name]: this.prev[name] ?? true })\n this.prev[name] = cur\n return this.set({ ...this.value, [name]: false })\n }\n\n /** step both strengths by delta (true becomes 1 first); no-op when off */\n adjustItem(name: T, delta: number): this {\n const cur = this.value[name]\n if (cur == null || cur === false) return this\n const step = (n: number): number => Math.max(0, Math.round((n + delta) * 100) / 100)\n const next: LoraStrength = Array.isArray(cur) ? [step(cur[0]), step(cur[1])] : step(cur === true ? 1 : cur)\n return this.set({ ...this.value, [name]: next })\n }\n\n /** compact per-item strength label for lists */\n strengthLabel(name: T): string {\n const s = this.value[name]\n if (s == null || s === false) return ''\n if (s === true) return '1.00'\n if (Array.isArray(s)) return `m:${s[0].toFixed(2)} c:${s[1].toFixed(2)}`\n return s.toFixed(2)\n }\n\n parse(raw: string): boolean {\n try {\n const parsed: unknown = JSON.parse(raw)\n if (typeof parsed !== 'object' || parsed == null || Array.isArray(parsed)) return false\n this.set(parsed as Partial<Record<T, LoraStrength>>)\n return true\n } catch {\n return false\n }\n }\n\n /** short human name: subfolder + extension stripped */\n static shortName(name: string): string {\n return (name.split(/[\\\\/]/).pop() ?? name).replace(/\\.safetensors$/, '')\n }\n\n /** tick (true) or untick (false) every lora in `names` (default: all options) */\n setAll(on: boolean, names: readonly T[] = this.options): this {\n const next = { ...this.value }\n for (const name of names) {\n const cur = next[name]\n if (on) {\n if (cur == null || cur === false) next[name] = this.prev[name] ?? true\n } else {\n if (cur != null && cur !== false) this.prev[name] = cur\n next[name] = false\n }\n }\n return this.set(next)\n }\n\n override display(): string {\n const on = this.activeNames()\n if (on.length === 0) return `(0/${this.options.length}) none`\n return `(${on.length}/${this.options.length}) ${on.map((n) => LorasVar.shortName(n)).join(', ')}`\n }\n}\n\nexport type SizeValue = { width: number; height: number }\nexport type SizePreset = { label: string; width: number; height: number }\n\n/** SDXL-style ~1MP buckets, multiples of 64 โ safe for most latent models */\nexport const DEFAULT_SIZE_PRESETS: SizePreset[] = [\n { label: '1:1 square', width: 1024, height: 1024 },\n { label: '4:3 landscape', width: 1152, height: 896 },\n { label: '3:4 portrait', width: 896, height: 1152 },\n { label: '3:2 landscape', width: 1216, height: 832 },\n { label: '2:3 portrait', width: 832, height: 1216 },\n { label: '16:9 widescreen', width: 1344, height: 768 },\n { label: '9:16 tall', width: 768, height: 1344 },\n]\n\n/** width/height picker: presets + free `WxH` entry */\nexport class SizeVar extends ComfyVar<SizeValue> {\n readonly kind = 'size' as const\n constructor(\n defaultValue: SizeValue = { width: 1024, height: 1024 },\n public readonly presets: SizePreset[] = DEFAULT_SIZE_PRESETS,\n label?: string,\n ) {\n super(defaultValue, label)\n }\n\n /** accepts '1024x768' / '1024ร768' / a preset label */\n parse(raw: string): boolean {\n const m = raw.trim().match(/^(\\d+)\\s*[xร]\\s*(\\d+)$/)\n if (m != null) {\n this.set({ width: Number(m[1]), height: Number(m[2]) })\n return true\n }\n const preset = this.presets.find((p) => p.label === raw.trim())\n if (preset != null) {\n this.set({ width: preset.width, height: preset.height })\n return true\n }\n return false\n }\n\n override display(): string {\n const { width, height } = this.value\n const hit = this.presets.find((p) => p.width === width && p.height === height)\n return `${width}ร${height}${hit ? ` (${hit.label})` : ''}`\n }\n}\n\n/** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.loras / v.size */\nexport const v = {\n text: (defaultValue: string, label?: string): TextVar => new TextVar(defaultValue, label),\n prompt: (defaultValue: string, opts: { label?: string; loraKeywordsFrom?: ActiveLoraSource } = {}): PromptVar =>\n new PromptVar(defaultValue, opts),\n int: (defaultValue: number, opts: { min?: number; max?: number; label?: string } = {}): IntVar =>\n new IntVar(defaultValue, opts),\n float: (defaultValue: number, opts: { min?: number; max?: number; label?: string } = {}): FloatVar =>\n new FloatVar(defaultValue, opts),\n seed: (defaultValue: number = 0, label?: string): SeedVar => new SeedVar(defaultValue, label),\n toggle: (defaultValue: boolean, label?: string): ToggleVar => new ToggleVar(defaultValue, label),\n choice: <const T extends string>(choices: readonly T[], defaultValue: T, label?: string): ChoiceVar<T> =>\n new ChoiceVar(choices, defaultValue, label),\n loras: <T extends string = string>(\n options: readonly T[] | RegExp,\n initial: Partial<Record<T, LoraStrength>> = {},\n label?: string,\n ): LorasVar<T> => new LorasVar(options, initial, label),\n size: (defaultValue?: SizeValue, opts: { presets?: SizePreset[]; label?: string } = {}): SizeVar =>\n new SizeVar(defaultValue, opts.presets, opts.label),\n}\n\n/**\n * structural face of any var: readonly `value` keeps ComfyVar<T> assignable\n * despite T-invariance on the mutable field. VarValues re-derives the exact\n * value types via infer.\n */\nexport type AnyVar = {\n readonly kind: VarKind\n readonly value: unknown\n readonly label?: string\n parse(raw: string): boolean\n loadJSON(value: unknown): unknown\n toJSON(): unknown\n outValue(): unknown\n display(): string\n toEditBuffer(): string\n afterRun(): void\n /** host-dependent vars (LorasVar regex) resolve here โ DefinedWorkflow calls it at define time */\n bindHost?(host: LorasHost): void\n}\n\nexport type VarsSpec = { [key: string]: AnyVar }\n\nexport type VarValues<V extends VarsSpec> = {\n // outValue() return type, not the stored type: PromptVar stores string, contributes PromptValue\n [K in keyof V]: V[K] extends { outValue(): infer O } ? O : never\n}\n\nexport function varValues<V extends VarsSpec>(vars: V): VarValues<V> {\n const out: Record<string, unknown> = {}\n // outValue, not value: PromptVar strips comments / prefixes lora keywords here\n for (const [k, varDef] of Object.entries(vars)) out[k] = varDef.outValue()\n return out as VarValues<V>\n}\n","import type { ComfyHost } from 'src/host/ComfyHost.ts'\nimport type { ComfyExecution } from 'src/runner/ComfyExecution.ts'\nimport type { ComfyWorkflow, RunSettings } from 'src/runner/ComfyWorkflow.ts'\nimport type { SdkForHost } from 'src/types/comfy-sdk.ts'\nimport {\n type AnyVar,\n type LorasVar,\n type LoraStrength,\n v,\n type VarsSpec,\n type VarValues,\n varValues,\n} from 'src/vars/ComfyVars.ts'\n\n/** the host's generated lora-name union (plain string when no sdk is generated) */\nexport type LoraNameOf<ID extends string> = 'E_LoraName' extends keyof SdkForHost<ID>['Union']\n ? SdkForHost<ID>['Union']['E_LoraName'] & string\n : string\n\n/**\n * the `v` handed to a vars LAMBDA: the global factory, host-typed โ\n * `v.loras(regex)` yields the host's lora-name union (resolved via bindHost)\n */\nexport type BoundVars<ID extends string> = Omit<typeof v, 'loras'> & {\n loras(\n options: RegExp,\n initial?: Partial<Record<LoraNameOf<ID>, LoraStrength>>,\n label?: string,\n ): LorasVar<LoraNameOf<ID>>\n loras<T extends string>(\n options: readonly T[],\n initial?: Partial<Record<T, LoraStrength>>,\n label?: string,\n ): LorasVar<T>\n}\n\nexport type DefineWorkflowSpec<ID extends string, V extends VarsSpec> = {\n /** short id; also names the workflow instances */\n id?: string\n /** the tweakable knobs; drivers (scripts, TUI) edit these between runs.\n * A LAMBDA gives cross-referencing vars a scope (loras + prompt with\n * loraKeywordsFrom created inline) โ resolved ONCE at define time, and it\n * RECEIVES the host-typed `v` (no import needed) */\n vars: V | ((v: BoundVars<ID>) => V)\n /** builds the graph from the CURRENT var values; re-executed on every run().\n * may be async (e.g. image uploads through the wf param) */\n build: (b: SdkForHost<ID>['Builder'], vars: VarValues<V>, wf: ComfyWorkflow<ID>) => void | Promise<void>\n}\n\n/** type predicate (not a cast): a VarsSpec is a plain record, never callable */\nfunction isVarsThunk<ID extends string, V extends VarsSpec>(\n vars: V | ((v: BoundVars<ID>) => V),\n): vars is (v: BoundVars<ID>) => V {\n return typeof vars === 'function'\n}\n\n/**\n * a re-runnable workflow definition: `build` re-executes per run with the\n * current var values, so every run gets a fresh, deterministic graph.\n */\nexport class DefinedWorkflow<ID extends string = string, V extends VarsSpec = VarsSpec> {\n /** spec.vars resolved once (may be given as a thunk) โ the SAME instances for the workflow's lifetime */\n readonly vars: V\n\n constructor(\n public host: ComfyHost<ID>,\n public spec: DefineWorkflowSpec<ID, V>,\n ) {\n // cast: whitelist family 1 (agent/coding.md) โ the runtime `v` IS the\n // factory BoundVars describes; the regex-loras typing claim it adds is\n // resolved from the same object_info enum via bindHost below\n this.vars = isVarsThunk(spec.vars) ? spec.vars(v as BoundVars<ID>) : spec.vars\n // host-dependent vars (v.loras(regex)) resolve NOW, at define time\n for (const [, varDef] of this.entries()) varDef.bindHost?.(this.host)\n }\n\n /** [name, var] pairs, for drivers that enumerate the knobs */\n entries(): [string, AnyVar][] {\n return Object.entries(this.vars)\n }\n\n /** the workflow built by the latest run() (null before the first run) */\n lastWorkflow: ComfyWorkflow<ID> | null = null\n /** the latest execution (null before the first run) */\n lastExecution: ComfyExecution | null = null\n\n /**\n * build a fresh graph from the CURRENT var values (no send). `p.advance`\n * (set by run()) fires each var's afterRun() right after snapshotting the\n * values โ atomically, before any await โ so the graph uses this run's seed\n * while the var moves to the next (queued runs get distinct seeds; a bare\n * build() for copy/export never advances).\n */\n async build(p: { advance?: boolean } = {}): Promise<ComfyWorkflow<ID>> {\n const wf = this.host.workflow({ id: this.spec.id })\n const values = varValues(this.vars)\n if (p.advance) for (const varDef of Object.values(this.vars)) varDef.afterRun()\n await this.spec.build(wf.builder, values, wf)\n this.lastWorkflow = wf\n return wf\n }\n\n /** build a fresh graph from the current var values, send it, wait for outputs.\n * connects first (idempotent) โ modules can import offline from the schema cache */\n async run(settings: RunSettings = {}): Promise<ComfyExecution> {\n await this.host.connect()\n const wf = await this.build({ advance: true })\n const execution = await wf.run(settings)\n this.lastExecution = execution\n return execution\n }\n}\n"],"mappings":";;;;AAGA,MAAa,gBAAyB,QAAQ,IAAI,mBAAmB;AACrE,MAAa,WAAW,QAAsB;CAC3C,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,GAAG;AAClC;AACA,MAAa,YAAY,QAAsB,QAAQ,MAAM,iBAAiB,KAAK;AACnF,MAAa,cAAc,QAAsB,QAAQ,IAAI,iBAAiB,KAAK;;;ACPnF,MAAM,QAAQ;CACX,MAAM,C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