comfy-ts 2.11.0 → 2.12.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 +1 -0
- package/dist/{LogsSt-qtFzOKpu.js → LogsSt-U1H0mP1m.js} +35 -5
- package/dist/LogsSt-U1H0mP1m.js.map +1 -0
- package/dist/cli.js +4 -4
- package/dist/index.cjs +473 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +191 -31
- package/dist/index.d.ts +191 -31
- package/dist/index.js +469 -63
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-BK7BA2dn.js → run-serve-BeAznay5.js} +461 -43
- package/dist/run-serve-BeAznay5.js.map +1 -0
- package/dist/{run-tui-CQyvMf0N.js → run-tui-BTGjvnKk.js} +43 -18
- package/dist/run-tui-BTGjvnKk.js.map +1 -0
- package/dist/{schemaDrift-DjjEtwfx.js → schemaDrift-Cg39vs53.js} +470 -60
- package/dist/schemaDrift-Cg39vs53.js.map +1 -0
- package/dist/serve-web.js +508 -134
- package/dist/{state--wrz0BQc.js → state-C7REnHan.js} +7 -3
- package/dist/{state--wrz0BQc.js.map → state-C7REnHan.js.map} +1 -1
- package/dist/web.d.ts +191 -31
- package/dist/web.js +469 -63
- package/dist/web.js.map +1 -1
- package/examples/rvion/06-qwen-image-edit.cflow.ts +3 -2
- package/examples/rvion/10-anima-t2i.cflow.ts +229 -0
- package/extra/README.md +4 -0
- package/extra/comfyui-fresh-model-lists/README.md +25 -0
- package/extra/comfyui-fresh-model-lists/__init__.py +36 -0
- package/extra/comfyui-fresh-model-lists/test_fresh_model_lists.py +97 -0
- package/package.json +15 -7
- package/src/cli/draftMeta.ts +39 -0
- package/src/cli/serve/ServeApp.ts +148 -12
- package/src/cli/serve/applyVarPayload.ts +50 -22
- package/src/cli/serve/describeVar.ts +42 -6
- package/src/cli/serve/llmConfigShape.ts +51 -0
- package/src/cli/serve/llmConfigs.ts +52 -0
- package/src/cli/serve/tagList.ts +92 -0
- package/src/cli/serve/tagSource.ts +69 -0
- package/src/cli/serve/web/api.ts +48 -0
- package/src/cli/serve/web/components/App.tsx +336 -44
- package/src/cli/serve/web/components/Gallery.tsx +105 -28
- package/src/cli/serve/web/components/HistoryPicker.tsx +149 -0
- package/src/cli/serve/web/components/Icon.tsx +18 -2
- package/src/cli/serve/web/components/MenuButton.tsx +53 -0
- package/src/cli/serve/web/components/Omnibox.tsx +85 -0
- package/src/cli/serve/web/components/PromptEnhancer.tsx +476 -180
- package/src/cli/serve/web/components/TooltipLayer.tsx +45 -0
- package/src/cli/serve/web/components/VarIcon.tsx +24 -0
- package/src/cli/serve/web/components/VarsForm.tsx +341 -188
- package/src/cli/serve/web/components/controls/BasicControls.tsx +57 -32
- package/src/cli/serve/web/components/controls/LorasControl.tsx +644 -317
- package/src/cli/serve/web/components/controls/PresetPicker.tsx +1 -1
- package/src/cli/serve/web/components/controls/PromptControl.tsx +279 -0
- package/src/cli/serve/web/components/controls/PromptEditor.tsx +113 -0
- package/src/cli/serve/web/components/controls/SeedControl.tsx +17 -10
- package/src/cli/serve/web/components/controls/SizeControl.tsx +111 -18
- package/src/cli/serve/web/components/modKey.ts +2 -0
- package/src/cli/serve/web/llm.ts +23 -12
- package/src/cli/serve/web/promptEditor/promptExtensions.ts +281 -0
- package/src/cli/serve/web/state/EnhancerSt.ts +415 -100
- package/src/cli/serve/web/state/FormSt.ts +193 -29
- package/src/cli/serve/web/state/OmniboxSt.ts +57 -0
- package/src/cli/serve/web/state/WebSt.ts +219 -74
- package/src/cli/serve/web/state/choiceButtons.ts +61 -0
- package/src/cli/serve/web/state/generateButton.ts +16 -0
- package/src/cli/serve/web/state/history.ts +54 -0
- package/src/cli/serve/web/state/host.ts +5 -2
- package/src/cli/serve/web/state/keptLines.ts +53 -0
- package/src/cli/serve/web/state/latentMode.ts +20 -0
- package/src/cli/serve/web/state/loraSort.ts +18 -0
- package/src/cli/serve/web/state/moduleTree.ts +2 -2
- package/src/cli/serve/web/state/omnibox.ts +69 -0
- package/src/cli/serve/web/state/payload.ts +38 -58
- package/src/cli/serve/web/state/shortcuts.ts +54 -0
- package/src/cli/serve/web/state/sizeStars.ts +31 -0
- package/src/cli/serve/web/state/stableSlots.ts +21 -0
- package/src/cli/serve/web/state/varGroups.ts +24 -0
- package/src/cli/serve/web/styles.ts +457 -118
- package/src/cli/serve/webBundle.ts +54 -10
- package/src/cli/tui/components/PickerOverlays.tsx +9 -2
- package/src/cli/tui/imagePicker/ImagePickerSt.ts +1 -1
- package/src/cli/tui/state/DraftsSt.ts +18 -2
- package/src/cli/tui/state/EditorSt.ts +1 -1
- package/src/cli/tui/state/LorasSt.ts +1 -1
- package/src/cli/tui/state/PickerSt.ts +25 -7
- package/src/cli/tui/state/SettingsSt.ts +1 -1
- package/src/cli/tui/state/TuiSt.ts +10 -0
- package/src/coreExports.ts +20 -0
- package/src/host/loraInfoCache.ts +6 -0
- package/src/state.ts +5 -0
- package/src/vars/ComfyVars.ts +337 -67
- package/src/vars/DefinedWorkflow.ts +40 -19
- package/src/vars/lanes.ts +238 -0
- package/src/vars/loraEntry.ts +101 -0
- package/src/vars/promptSyntax.ts +382 -0
- package/dist/LogsSt-qtFzOKpu.js.map +0 -1
- package/dist/run-serve-BK7BA2dn.js.map +0 -1
- package/dist/run-tui-CQyvMf0N.js.map +0 -1
- package/dist/schemaDrift-DjjEtwfx.js.map +0 -1
- package/src/cli/serve/web/components/Sidebar.tsx +0 -66
package/src/vars/ComfyVars.ts
CHANGED
|
@@ -6,6 +6,21 @@ import { action, makeObservable, observable } from 'mobx'
|
|
|
6
6
|
import { basename, isAbsolute, join, resolve } from 'pathe'
|
|
7
7
|
import { getComfyStorage } from 'src/storage/ComfyStorage.ts'
|
|
8
8
|
import { getLoraKeyword } from 'src/vars/loraKeywords.ts'
|
|
9
|
+
import {
|
|
10
|
+
flattenLoras,
|
|
11
|
+
isLorasInput,
|
|
12
|
+
isPromptLanes,
|
|
13
|
+
promptLanesFromText,
|
|
14
|
+
promptLanesToText,
|
|
15
|
+
promptText,
|
|
16
|
+
updateLora,
|
|
17
|
+
type LoraRecord,
|
|
18
|
+
type LorasInput,
|
|
19
|
+
type PromptInput,
|
|
20
|
+
} from 'src/vars/lanes.ts'
|
|
21
|
+
import { keptKeyword, loraIsOn, loraMuted, loraStrengths, withLora, type LoraStrength } from 'src/vars/loraEntry.ts'
|
|
22
|
+
import { logError } from 'src/utils/log.ts'
|
|
23
|
+
import { COMMENT_LINE_RE, NEGATIVE_LINE_RE, parsePromptText } from 'src/vars/promptSyntax.ts'
|
|
9
24
|
import { toPresetList, type VarPreset, type VarPresetSpec } from 'src/vars/presets.ts'
|
|
10
25
|
|
|
11
26
|
/**
|
|
@@ -24,10 +39,38 @@ export type VarKind = 'text' | 'prompt' | 'int' | 'float' | 'seed' | 'toggle' |
|
|
|
24
39
|
* the one Out-specialized var (string in, PromptValue out); the split keeps
|
|
25
40
|
* outValue() cast-free.
|
|
26
41
|
*/
|
|
42
|
+
/** how a var LOOKS in the panel, set by the workflow: `v.int(8).ui({ icon, color, description })`.
|
|
43
|
+
* Every slot is optional, a color is any css color */
|
|
44
|
+
export type VarUi = {
|
|
45
|
+
/** shown as a (?) after the label, the text is its tooltip */
|
|
46
|
+
description?: string
|
|
47
|
+
/** a 24×24 svg path drawn in the icon color, or a whole `<svg …>` string */
|
|
48
|
+
icon?: string
|
|
49
|
+
/** the icon's color */
|
|
50
|
+
color?: string
|
|
51
|
+
labelColor?: string
|
|
52
|
+
/** the whole row, drawn without moving anything in it */
|
|
53
|
+
background?: string
|
|
54
|
+
/** vars that go together: consecutive vars with the same group share one tinted block */
|
|
55
|
+
group?: string
|
|
56
|
+
/** the block's tint, read from the first var of the group that sets it */
|
|
57
|
+
groupColor?: string
|
|
58
|
+
border?: string
|
|
59
|
+
/** choice vars: a look per option, keyed by the option value. The lit option is filled
|
|
60
|
+
* with its own color */
|
|
61
|
+
options?: Record<string, { icon?: string; color?: string }>
|
|
62
|
+
/** the field is shown but disabled unless every named var holds one of the listed values:
|
|
63
|
+
* `{ model: ['aesthetic', 'base'] }`. Checked against the var names when the workflow loads.
|
|
64
|
+
* Display only: a disabled var's value still reaches the build */
|
|
65
|
+
activeWhen?: Record<string, readonly (string | number | boolean)[]>
|
|
66
|
+
}
|
|
67
|
+
|
|
27
68
|
export abstract class ComfyVarBase<T, Out> {
|
|
28
69
|
abstract readonly kind: VarKind
|
|
29
70
|
/** the vars-spec key, stamped by DefinedWorkflow at define time — error messages name the var with it */
|
|
30
71
|
name?: string
|
|
72
|
+
/** panel looks, see VarUi. Never part of the value, never in a draft */
|
|
73
|
+
uiOpts: VarUi = {}
|
|
31
74
|
value: T
|
|
32
75
|
constructor(
|
|
33
76
|
public readonly defaultValue: T,
|
|
@@ -44,6 +87,11 @@ export abstract class ComfyVarBase<T, Out> {
|
|
|
44
87
|
this.value = value
|
|
45
88
|
return this
|
|
46
89
|
}
|
|
90
|
+
/** chainable: `v.choice([...], 'a').ui({ icon: 'M4 12h16', color: '#e0af68' })` */
|
|
91
|
+
ui(p: VarUi): this {
|
|
92
|
+
this.uiOpts = { ...this.uiOpts, ...p }
|
|
93
|
+
return this
|
|
94
|
+
}
|
|
47
95
|
/** what drafts persist for this var (subclasses may add fields, e.g. seed mode) */
|
|
48
96
|
toJSON(): unknown {
|
|
49
97
|
return this.value
|
|
@@ -111,14 +159,36 @@ export class TextVar extends ComfyVar<string> {
|
|
|
111
159
|
}
|
|
112
160
|
}
|
|
113
161
|
|
|
114
|
-
const commentLineRe = /^\s*\/\//
|
|
115
|
-
const negativeLineRe = /^\s*- (.*)$/
|
|
116
|
-
|
|
117
162
|
/** what PromptVar needs from a loras var: covariant face, so LorasVar<'a'|'b'> fits.
|
|
118
163
|
* `hostId` scopes the keyword lookup: the same file name on two hosts is often a
|
|
119
164
|
* different model, and injecting the other host's trigger words is a silently
|
|
120
165
|
* wrong generation. */
|
|
121
|
-
export type ActiveLoraSource = {
|
|
166
|
+
export type ActiveLoraSource = {
|
|
167
|
+
activeNames(): string[]
|
|
168
|
+
hostId?: string
|
|
169
|
+
/** the parts of a lora's keyword left out of the prompt (LorasVar: the `mute` list) */
|
|
170
|
+
mutedWords?(name: string): string[]
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** where a prompt's tag completion comes from (the serve web editor). The list is never shipped:
|
|
174
|
+
* `url` is a local path (relative to the workflow file, `~/`, `file://`) or an http(s) url */
|
|
175
|
+
export type PromptTagsOpts = {
|
|
176
|
+
url: string
|
|
177
|
+
/** insert `long_hair` as written in the list; default inserts `long hair` */
|
|
178
|
+
underscores?: boolean
|
|
179
|
+
/** put in front of an artist tag on insert (Anima: `@`) */
|
|
180
|
+
artistPrefix?: string
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export type PromptVarOpts = {
|
|
184
|
+
label?: string
|
|
185
|
+
loraKeywordsFrom?: ActiveLoraSource
|
|
186
|
+
presets?: VarPresetSpec
|
|
187
|
+
/** booru tag completion for this prompt: a tag list url, or the url with its insert rules */
|
|
188
|
+
tags?: string | PromptTagsOpts
|
|
189
|
+
/** false when the model's encoder ignores `(text:1.2)`: the editor then flags every weight */
|
|
190
|
+
weights?: boolean
|
|
191
|
+
}
|
|
122
192
|
|
|
123
193
|
/** what a prompt CONTRIBUTES to build: `vars.prompt.positive` / `.negative` */
|
|
124
194
|
export type PromptValue = { positive: string; negative: string }
|
|
@@ -126,37 +196,52 @@ export type PromptValue = { positive: string; negative: string }
|
|
|
126
196
|
/**
|
|
127
197
|
* prompt text with editor comforts, all resolved at BUILD time (the editor and
|
|
128
198
|
* drafts keep the raw text):
|
|
129
|
-
* - `//`
|
|
199
|
+
* - `//` starts a COMMENT to the end of the line (src/vars/promptSyntax.ts) — stripped
|
|
130
200
|
* - `- ` lines are NEGATIVE prompt lines — removed from `.positive`,
|
|
131
201
|
* comma-joined into `.negative`
|
|
132
202
|
* - with `loraKeywordsFrom`, the ACTIVE loras' hand-assigned keywords
|
|
133
203
|
* (src/vars/loraKeywords.ts, ⌃K in the TUI) prefix `.positive` —
|
|
134
204
|
* `injectedKeywords()` is public so the TUI can PREVIEW the injection.
|
|
135
205
|
*/
|
|
136
|
-
export class PromptVar extends ComfyVarBase<
|
|
206
|
+
export class PromptVar extends ComfyVarBase<PromptInput, PromptValue> {
|
|
137
207
|
readonly kind = 'prompt' as const
|
|
138
208
|
/** normalized `promptOpts.presets`, in authored order (TextVarOpts.presets owns the WHY) */
|
|
139
209
|
readonly presets: VarPreset[]
|
|
140
210
|
constructor(
|
|
141
|
-
defaultValue:
|
|
142
|
-
public promptOpts: {
|
|
143
|
-
label?: string
|
|
144
|
-
loraKeywordsFrom?: ActiveLoraSource
|
|
145
|
-
presets?: VarPresetSpec
|
|
146
|
-
} = {},
|
|
211
|
+
defaultValue: PromptInput,
|
|
212
|
+
public promptOpts: PromptVarOpts = {},
|
|
147
213
|
) {
|
|
148
214
|
super(defaultValue, promptOpts.label)
|
|
149
215
|
this.presets = toPresetList(promptOpts.presets)
|
|
150
216
|
}
|
|
217
|
+
/** in lanes mode the text carries `# name` headers, so a lane survives a round trip */
|
|
151
218
|
parse(raw: string): boolean {
|
|
152
|
-
this.set(raw)
|
|
219
|
+
this.set(isPromptLanes(this.value) ? promptLanesFromText(raw) : raw)
|
|
153
220
|
return true
|
|
154
221
|
}
|
|
222
|
+
override toEditBuffer(): string {
|
|
223
|
+
return isPromptLanes(this.value) ? promptLanesToText(this.value) : this.value
|
|
224
|
+
}
|
|
225
|
+
/** a var list shows the lanes by name, the inactive ones in parentheses */
|
|
226
|
+
override display(): string {
|
|
227
|
+
if (!isPromptLanes(this.value)) return super.display()
|
|
228
|
+
return `${this.value.lanes.length} lanes: ${this.value.lanes.map((l) => (l.active ? l.name : `(${l.name})`)).join(', ')}`
|
|
229
|
+
}
|
|
230
|
+
/** the text the build reads: the plain string, or the active lanes joined in order */
|
|
231
|
+
get text(): string {
|
|
232
|
+
return promptText(this.value)
|
|
233
|
+
}
|
|
234
|
+
/** the tag list options in their one object form, null when this prompt has no completion */
|
|
235
|
+
get tags(): PromptTagsOpts | null {
|
|
236
|
+
const t = this.promptOpts.tags
|
|
237
|
+
if (t == null) return null
|
|
238
|
+
return typeof t === 'string' ? { url: t } : t
|
|
239
|
+
}
|
|
155
240
|
static isCommentLine(line: string): boolean {
|
|
156
|
-
return
|
|
241
|
+
return COMMENT_LINE_RE.test(line)
|
|
157
242
|
}
|
|
158
243
|
static isNegativeLine(line: string): boolean {
|
|
159
|
-
return
|
|
244
|
+
return NEGATIVE_LINE_RE.test(line)
|
|
160
245
|
}
|
|
161
246
|
/** the keyword prefix the flag will inject (deduped, lora-list order) — the TUI previews this */
|
|
162
247
|
injectedKeywords(): string[] {
|
|
@@ -166,27 +251,18 @@ export class PromptVar extends ComfyVarBase<string, PromptValue> {
|
|
|
166
251
|
...new Set(
|
|
167
252
|
src
|
|
168
253
|
.activeNames()
|
|
169
|
-
.map((name) => getLoraKeyword(name, src.hostId))
|
|
254
|
+
.map((name) => keptKeyword(getLoraKeyword(name, src.hostId), src.mutedWords?.(name) ?? []))
|
|
170
255
|
.filter((k) => k !== ''),
|
|
171
256
|
),
|
|
172
257
|
]
|
|
173
258
|
}
|
|
174
259
|
outValue(): PromptValue {
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
for (const line of this.value.split('\n')) {
|
|
178
|
-
if (commentLineRe.test(line)) continue
|
|
179
|
-
const m = negativeLineRe.exec(line)
|
|
180
|
-
if (m != null) {
|
|
181
|
-
const text = (m[1] ?? '').trim()
|
|
182
|
-
if (text !== '') neg.push(text)
|
|
183
|
-
} else pos.push(line)
|
|
184
|
-
}
|
|
185
|
-
const body = pos.join('\n').trim()
|
|
260
|
+
const parsed = parsePromptText(this.text)
|
|
261
|
+
const body = parsed.positive
|
|
186
262
|
const keywords = this.injectedKeywords()
|
|
187
263
|
const positive =
|
|
188
264
|
keywords.length === 0 ? body : body === '' ? keywords.join(', ') : `${keywords.join(', ')}, ${body}`
|
|
189
|
-
return { positive, negative:
|
|
265
|
+
return { positive, negative: parsed.negative }
|
|
190
266
|
}
|
|
191
267
|
}
|
|
192
268
|
|
|
@@ -327,8 +403,12 @@ export class ToggleVar extends ComfyVar<boolean> {
|
|
|
327
403
|
}
|
|
328
404
|
}
|
|
329
405
|
|
|
406
|
+
/** how many options a choice holds: exactly one (the default), one or none, or any number */
|
|
407
|
+
export type ChoiceSelect = 'one' | 'zero-or-one' | 'many'
|
|
408
|
+
|
|
330
409
|
export class ChoiceVar<T extends string> extends ComfyVar<T> {
|
|
331
410
|
readonly kind = 'choice' as const
|
|
411
|
+
readonly select = 'one' as const
|
|
332
412
|
constructor(
|
|
333
413
|
public readonly choices: readonly T[],
|
|
334
414
|
defaultValue: T,
|
|
@@ -349,20 +429,140 @@ export class ChoiceVar<T extends string> extends ComfyVar<T> {
|
|
|
349
429
|
}
|
|
350
430
|
}
|
|
351
431
|
|
|
352
|
-
/**
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
432
|
+
/** one option or none: `null` is "nothing picked", clicking the lit option clears it */
|
|
433
|
+
export class OptionalChoiceVar<T extends string> extends ComfyVar<T | null> {
|
|
434
|
+
readonly kind = 'choice' as const
|
|
435
|
+
readonly select = 'zero-or-one' as const
|
|
436
|
+
constructor(
|
|
437
|
+
public readonly choices: readonly T[],
|
|
438
|
+
defaultValue: T | null,
|
|
439
|
+
label?: string,
|
|
440
|
+
) {
|
|
441
|
+
super(defaultValue, label)
|
|
442
|
+
}
|
|
443
|
+
/** pick `c`, or clear it when it is already the one picked */
|
|
444
|
+
toggle(c: T): this {
|
|
445
|
+
return this.set(this.value === c ? null : c)
|
|
446
|
+
}
|
|
447
|
+
/** the TUI text form: a choice, or an empty line for none */
|
|
448
|
+
parse(raw: string): boolean {
|
|
449
|
+
if (raw.trim() === '') {
|
|
450
|
+
this.set(null)
|
|
451
|
+
return true
|
|
452
|
+
}
|
|
453
|
+
const hit = this.choices.find((c) => c === raw.trim())
|
|
454
|
+
if (hit == null) return false
|
|
455
|
+
this.set(hit)
|
|
456
|
+
return true
|
|
457
|
+
}
|
|
458
|
+
override toEditBuffer(): string {
|
|
459
|
+
return this.value ?? ''
|
|
460
|
+
}
|
|
461
|
+
/** a draft from when this was a many choice holds a list: its first known option */
|
|
462
|
+
override loadJSON(value: unknown): this {
|
|
463
|
+
const one = Array.isArray(value) ? value[0] : value
|
|
464
|
+
return this.set(this.choices.find((c) => c === one) ?? null)
|
|
465
|
+
}
|
|
466
|
+
override display(): string {
|
|
467
|
+
return this.value ?? 'none'
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** any number of options, kept in the order the choices list them */
|
|
472
|
+
export class MultiChoiceVar<T extends string> extends ComfyVar<T[]> {
|
|
473
|
+
readonly kind = 'choice' as const
|
|
474
|
+
readonly select = 'many' as const
|
|
475
|
+
constructor(
|
|
476
|
+
public readonly choices: readonly T[],
|
|
477
|
+
defaultValue: readonly T[],
|
|
478
|
+
label?: string,
|
|
479
|
+
) {
|
|
480
|
+
super([...defaultValue], label)
|
|
481
|
+
}
|
|
482
|
+
toggle(c: T): this {
|
|
483
|
+
const on = this.value.includes(c)
|
|
484
|
+
return this.set(this.choices.filter((x) => (x === c ? !on : this.value.includes(x))))
|
|
485
|
+
}
|
|
486
|
+
/** the TUI text form: `a, b` */
|
|
487
|
+
parse(raw: string): boolean {
|
|
488
|
+
const wanted = raw
|
|
489
|
+
.split(',')
|
|
490
|
+
.map((w) => w.trim())
|
|
491
|
+
.filter((w) => w !== '')
|
|
492
|
+
const picked = this.choices.filter((c) => wanted.includes(c))
|
|
493
|
+
if (picked.length !== new Set(wanted).size) return false
|
|
494
|
+
this.set(picked)
|
|
495
|
+
return true
|
|
496
|
+
}
|
|
497
|
+
override toEditBuffer(): string {
|
|
498
|
+
return this.value.join(', ')
|
|
499
|
+
}
|
|
500
|
+
/** a draft from when this was a single choice holds one value: a list of one. Unknown
|
|
501
|
+
* options are dropped, the list comes back in the choices order */
|
|
502
|
+
override loadJSON(value: unknown): this {
|
|
503
|
+
const listed: unknown[] = Array.isArray(value) ? value : value == null ? [] : [value]
|
|
504
|
+
return this.set(this.choices.filter((c) => listed.includes(c)))
|
|
505
|
+
}
|
|
506
|
+
override display(): string {
|
|
507
|
+
return this.value.length === 0 ? 'none' : this.value.join(', ')
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/** the three choice shapes, told apart by `select` */
|
|
512
|
+
export type AnyChoiceVar<T extends string = string> = ChoiceVar<T> | OptionalChoiceVar<T> | MultiChoiceVar<T>
|
|
513
|
+
|
|
514
|
+
type ChoiceOpts<S extends ChoiceSelect> = { label?: string; select: S }
|
|
515
|
+
|
|
516
|
+
/** Array.isArray does not narrow a READONLY array out of a union, this does */
|
|
517
|
+
function isChoiceList<T extends string>(v: T | null | readonly T[]): v is readonly T[] {
|
|
518
|
+
return Array.isArray(v)
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function choice<const T extends string>(
|
|
522
|
+
choices: readonly T[],
|
|
523
|
+
defaultValue: T,
|
|
524
|
+
label?: string | { label?: string; select?: 'one' },
|
|
525
|
+
): ChoiceVar<T>
|
|
526
|
+
function choice<const T extends string>(
|
|
527
|
+
choices: readonly T[],
|
|
528
|
+
defaultValue: T | null,
|
|
529
|
+
opts: ChoiceOpts<'zero-or-one'>,
|
|
530
|
+
): OptionalChoiceVar<T>
|
|
531
|
+
function choice<const T extends string>(
|
|
532
|
+
choices: readonly T[],
|
|
533
|
+
defaultValue: readonly T[],
|
|
534
|
+
opts: ChoiceOpts<'many'>,
|
|
535
|
+
): MultiChoiceVar<T>
|
|
536
|
+
function choice<const T extends string>(
|
|
537
|
+
choices: readonly T[],
|
|
538
|
+
defaultValue: T | null | readonly T[],
|
|
539
|
+
opts?: string | { label?: string; select?: ChoiceSelect },
|
|
540
|
+
): AnyChoiceVar<T> {
|
|
541
|
+
const o = typeof opts === 'string' ? { label: opts } : (opts ?? {})
|
|
542
|
+
const select = o.select ?? 'one'
|
|
543
|
+
if (select === 'many') {
|
|
544
|
+
if (!isChoiceList(defaultValue))
|
|
545
|
+
throw new Error(`a 'many' choice takes a list as its default, got ${String(defaultValue)}`)
|
|
546
|
+
return new MultiChoiceVar(choices, defaultValue, o.label)
|
|
547
|
+
}
|
|
548
|
+
if (isChoiceList(defaultValue)) throw new Error(`a '${select}' choice takes one value as its default, not a list`)
|
|
549
|
+
if (select === 'zero-or-one') return new OptionalChoiceVar(choices, defaultValue, o.label)
|
|
550
|
+
if (defaultValue == null) throw new Error("a 'one' choice needs a default: use { select: 'zero-or-one' } for none")
|
|
551
|
+
return new ChoiceVar(choices, defaultValue, o.label)
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/** per-lora setting, every spelling documented in src/vars/loraEntry.ts */
|
|
555
|
+
export type { LoraStrength } from 'src/vars/loraEntry.ts'
|
|
357
556
|
|
|
358
557
|
export type ActiveLora<T extends string> = { lora_name: T; strength_model: number; strength_clip: number }
|
|
359
558
|
|
|
360
559
|
/** normalize a loras record into what a standard LoraLoader chain consumes */
|
|
361
|
-
export function activeLoras<T extends string>(loras:
|
|
560
|
+
export function activeLoras<T extends string>(loras: LorasInput<T>): ActiveLora<T>[] {
|
|
362
561
|
const out: ActiveLora<T>[] = []
|
|
363
|
-
for (const [lora_name, s] of Object.entries(loras) as [T, LoraStrength | undefined][]) {
|
|
364
|
-
|
|
365
|
-
|
|
562
|
+
for (const [lora_name, s] of Object.entries(flattenLoras(loras).record) as [T, LoraStrength | undefined][]) {
|
|
563
|
+
// a paused lora ({ off: true }) is in the palette, never in the graph
|
|
564
|
+
if (!loraIsOn(s)) continue
|
|
565
|
+
const [strength_model, strength_clip] = loraStrengths(s)
|
|
366
566
|
out.push({ lora_name, strength_model, strength_clip })
|
|
367
567
|
}
|
|
368
568
|
return out
|
|
@@ -377,7 +577,12 @@ export type LorasHost = { data?: { id?: string }; schema: { getLoras(filter?: Re
|
|
|
377
577
|
* or feed it host discovery (`host.schema.getLoras(regex?)`) directly; never
|
|
378
578
|
* a hardcoded inventory. Selection is empty by default.
|
|
379
579
|
*/
|
|
380
|
-
|
|
580
|
+
/**
|
|
581
|
+
* the value is EITHER a plain record OR `{ lanes: [...] }` (src/vars/lanes.ts): named groups the
|
|
582
|
+
* build merges in listed order, skipping inactive ones. Every method reads the merged record and
|
|
583
|
+
* writes into the lane that holds the lora, so the TUI never needs to know lanes exist
|
|
584
|
+
*/
|
|
585
|
+
export class LorasVar<T extends string> extends ComfyVarBase<LorasInput<T>, LoraRecord<T>> {
|
|
381
586
|
readonly kind = 'loras' as const
|
|
382
587
|
/** last non-false strength per lora, so untick → re-tick restores it */
|
|
383
588
|
private prev: Partial<Record<T, LoraStrength>> = {}
|
|
@@ -388,7 +593,7 @@ export class LorasVar<T extends string> extends ComfyVar<Partial<Record<T, LoraS
|
|
|
388
593
|
|
|
389
594
|
constructor(
|
|
390
595
|
private readonly optionsSource: readonly T[] | RegExp,
|
|
391
|
-
initial:
|
|
596
|
+
initial: LorasInput<T> = {},
|
|
392
597
|
label?: string,
|
|
393
598
|
) {
|
|
394
599
|
super(initial, label)
|
|
@@ -423,46 +628,78 @@ export class LorasVar<T extends string> extends ComfyVar<Partial<Record<T, LoraS
|
|
|
423
628
|
return [...this.options]
|
|
424
629
|
}
|
|
425
630
|
|
|
631
|
+
/** the loras the build reads: the plain record, or the active lanes merged in order */
|
|
632
|
+
get record(): LoraRecord<T> {
|
|
633
|
+
return flattenLoras(this.value).record
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/** what the graph consumes. A lora in two active lanes runs once, with its FIRST setting */
|
|
637
|
+
outValue(): LoraRecord<T> {
|
|
638
|
+
const flat = flattenLoras(this.value)
|
|
639
|
+
if (flat.duplicates.length > 0)
|
|
640
|
+
logError(
|
|
641
|
+
`loras var '${this.name ?? this.label ?? '?'}': ${flat.duplicates.join(', ')} sit in two active lanes, the first lane's setting is used`,
|
|
642
|
+
)
|
|
643
|
+
return flat.record
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/** rewrite one lora wherever it lives: the plain record, or the lane that holds it */
|
|
647
|
+
private write(name: T, next: LoraStrength | null): this {
|
|
648
|
+
return this.set(updateLora(this.value, name, next))
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/** the parts of this lora's prompt keyword left out of the prompt */
|
|
652
|
+
mutedWords(name: string): string[] {
|
|
653
|
+
return loraMuted(this.record[name as T])
|
|
654
|
+
}
|
|
655
|
+
|
|
426
656
|
/** loras currently ON (PromptVar keyword prefixing consumes this) */
|
|
427
657
|
activeNames(): T[] {
|
|
428
658
|
return this.names.filter((n) => this.isOn(n))
|
|
429
659
|
}
|
|
430
660
|
|
|
431
661
|
isOn(name: T): boolean {
|
|
432
|
-
|
|
433
|
-
return s != null && s !== false
|
|
662
|
+
return loraIsOn(this.record[name])
|
|
434
663
|
}
|
|
435
664
|
|
|
436
665
|
toggleItem(name: T): this {
|
|
437
|
-
const cur = this.
|
|
438
|
-
if (cur == null || cur === false) return this.
|
|
666
|
+
const cur = this.record[name]
|
|
667
|
+
if (cur == null || cur === false) return this.write(name, this.prev[name] ?? true)
|
|
668
|
+
// a paused palette entry resumes in place, strengths kept
|
|
669
|
+
if (!loraIsOn(cur)) return this.write(name, withLora(cur, { on: true }))
|
|
439
670
|
this.prev[name] = cur
|
|
440
|
-
return this.
|
|
671
|
+
return this.write(name, false)
|
|
441
672
|
}
|
|
442
673
|
|
|
443
674
|
/** step both strengths by delta (true becomes 1 first); no-op when off */
|
|
444
675
|
adjustItem(name: T, delta: number): this {
|
|
445
|
-
const cur = this.
|
|
446
|
-
if (cur
|
|
676
|
+
const cur = this.record[name]
|
|
677
|
+
if (!loraIsOn(cur)) return this
|
|
447
678
|
const step = (n: number): number => Math.max(0, Math.round((n + delta) * 100) / 100)
|
|
448
|
-
|
|
449
|
-
|
|
679
|
+
// the short spellings stay short: only a palette entry needs the object form
|
|
680
|
+
const next: LoraStrength =
|
|
681
|
+
typeof cur === 'number' || cur === true
|
|
682
|
+
? step(cur === true ? 1 : cur)
|
|
683
|
+
: Array.isArray(cur)
|
|
684
|
+
? [step(cur[0]), step(cur[1])]
|
|
685
|
+
: withLora(cur, { strength: [step(loraStrengths(cur)[0]), step(loraStrengths(cur)[1])] })
|
|
686
|
+
return this.write(name, next)
|
|
450
687
|
}
|
|
451
688
|
|
|
452
689
|
/** compact per-item strength label for lists */
|
|
453
690
|
strengthLabel(name: T): string {
|
|
454
|
-
const s = this.
|
|
455
|
-
if (s
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
return s.toFixed(2)
|
|
691
|
+
const s = this.record[name]
|
|
692
|
+
if (!loraIsOn(s)) return ''
|
|
693
|
+
const [m, c] = loraStrengths(s)
|
|
694
|
+
return m === c ? m.toFixed(2) : `m:${m.toFixed(2)} c:${c.toFixed(2)}`
|
|
459
695
|
}
|
|
460
696
|
|
|
461
697
|
parse(raw: string): boolean {
|
|
462
698
|
try {
|
|
463
699
|
const parsed: unknown = JSON.parse(raw)
|
|
464
|
-
if (
|
|
465
|
-
this
|
|
700
|
+
if (!isLorasInput(parsed)) return false
|
|
701
|
+
// cast: whitelist family 1, the names are this host's lora enum, checked by the build
|
|
702
|
+
this.set(parsed as LorasInput<T>)
|
|
466
703
|
return true
|
|
467
704
|
} catch {
|
|
468
705
|
return false
|
|
@@ -476,14 +713,17 @@ export class LorasVar<T extends string> extends ComfyVar<Partial<Record<T, LoraS
|
|
|
476
713
|
|
|
477
714
|
/** tick (true) or untick (false) every lora in `names` (default: all options) */
|
|
478
715
|
setAll(on: boolean, names: readonly T[] = this.options): this {
|
|
479
|
-
const
|
|
716
|
+
const record = this.record
|
|
717
|
+
let next = this.value
|
|
480
718
|
for (const name of names) {
|
|
481
|
-
const cur =
|
|
719
|
+
const cur = record[name]
|
|
482
720
|
if (on) {
|
|
483
|
-
if (cur == null || cur === false) next
|
|
721
|
+
if (cur == null || cur === false) next = updateLora(next, name, this.prev[name] ?? true)
|
|
722
|
+
// a paused palette entry resumes in place, strengths kept
|
|
723
|
+
else if (!loraIsOn(cur)) next = updateLora(next, name, withLora(cur, { on: true }))
|
|
484
724
|
} else {
|
|
485
|
-
if (cur
|
|
486
|
-
next
|
|
725
|
+
if (loraIsOn(cur)) this.prev[name] = cur
|
|
726
|
+
next = updateLora(next, name, false)
|
|
487
727
|
}
|
|
488
728
|
}
|
|
489
729
|
return this.set(next)
|
|
@@ -510,6 +750,27 @@ export const DEFAULT_SIZE_PRESETS: SizePreset[] = [
|
|
|
510
750
|
{ label: '9:16 tall', width: 768, height: 1344 },
|
|
511
751
|
]
|
|
512
752
|
|
|
753
|
+
/** the same aspect ratios around 512, for SD1.5-era models trained at ~0.25MP */
|
|
754
|
+
export const SD15_SIZE_PRESETS: SizePreset[] = [
|
|
755
|
+
{ label: '1:1 square', width: 512, height: 512 },
|
|
756
|
+
{ label: '4:3 landscape', width: 576, height: 448 },
|
|
757
|
+
{ label: '3:4 portrait', width: 448, height: 576 },
|
|
758
|
+
{ label: '3:2 landscape', width: 576, height: 384 },
|
|
759
|
+
{ label: '2:3 portrait', width: 384, height: 576 },
|
|
760
|
+
{ label: '16:9 widescreen', width: 704, height: 384 },
|
|
761
|
+
{ label: '9:16 tall', width: 384, height: 704 },
|
|
762
|
+
]
|
|
763
|
+
|
|
764
|
+
/** starred presets are one click away in the panel, before the full list */
|
|
765
|
+
export const DEFAULT_STARRED_SIZES = ['1:1 square', '3:4 portrait', '4:3 landscape']
|
|
766
|
+
|
|
767
|
+
/** the family that matches a workflow's own default: a 512×512 workflow is an SD1.5-era one,
|
|
768
|
+
* and offering it 1024 buckets would be offering sizes it was never trained at */
|
|
769
|
+
export function sizePresetsFor(defaultValue: SizeValue | undefined): SizePreset[] {
|
|
770
|
+
if (defaultValue == null) return DEFAULT_SIZE_PRESETS
|
|
771
|
+
return defaultValue.width * defaultValue.height <= 600 * 600 ? SD15_SIZE_PRESETS : DEFAULT_SIZE_PRESETS
|
|
772
|
+
}
|
|
773
|
+
|
|
513
774
|
/** width/height picker: presets + free `WxH` entry + optionally the LIVE
|
|
514
775
|
* size of a linked image var (the widget shows
|
|
515
776
|
* `WxH size of image '<name>'` as a pickable row) */
|
|
@@ -520,6 +781,8 @@ export class SizeVar extends ComfyVar<SizeValue> {
|
|
|
520
781
|
public readonly presets: SizePreset[] = DEFAULT_SIZE_PRESETS,
|
|
521
782
|
label?: string,
|
|
522
783
|
public readonly imageVar?: ImageVar,
|
|
784
|
+
/** preset LABELS starred by default; a user's own stars live in the panel */
|
|
785
|
+
public readonly starred: readonly string[] = DEFAULT_STARRED_SIZES,
|
|
523
786
|
) {
|
|
524
787
|
super(defaultValue, label)
|
|
525
788
|
}
|
|
@@ -646,8 +909,9 @@ export const v = {
|
|
|
646
909
|
text: (defaultValue: string, opts: TextVarOpts | string = {}): TextVar =>
|
|
647
910
|
new TextVar(defaultValue, typeof opts === 'string' ? { label: opts } : opts),
|
|
648
911
|
prompt: (
|
|
649
|
-
|
|
650
|
-
|
|
912
|
+
/** a string, or `{ lanes: [{ name, prompt, active }] }` merged in listed order */
|
|
913
|
+
defaultValue: PromptInput,
|
|
914
|
+
opts: PromptVarOpts = {},
|
|
651
915
|
): PromptVar => new PromptVar(defaultValue, opts),
|
|
652
916
|
int: (defaultValue: number, opts: { min?: number; max?: number; label?: string } = {}): IntVar =>
|
|
653
917
|
new IntVar(defaultValue, opts),
|
|
@@ -658,15 +922,20 @@ export const v = {
|
|
|
658
922
|
seed: (defaultValue: number = 0, opts: string | { label?: string; mode?: SeedMode } = {}): SeedVar =>
|
|
659
923
|
new SeedVar(defaultValue, opts),
|
|
660
924
|
toggle: (defaultValue: boolean, label?: string): ToggleVar => new ToggleVar(defaultValue, label),
|
|
661
|
-
|
|
662
|
-
|
|
925
|
+
/** exactly one option (the default), `{ select: 'zero-or-one' }` for one or none (value
|
|
926
|
+
* `T | null`), `{ select: 'many' }` for any number (value `T[]`) */
|
|
927
|
+
choice,
|
|
663
928
|
loras: <T extends string = string>(
|
|
664
929
|
options: readonly T[] | RegExp,
|
|
665
|
-
|
|
930
|
+
/** a record, or `{ lanes: [{ name, active, loras }] }` merged in listed order */
|
|
931
|
+
initial: LorasInput<T> = {},
|
|
666
932
|
label?: string,
|
|
667
933
|
): LorasVar<T> => new LorasVar(options, initial, label),
|
|
668
|
-
size: (
|
|
669
|
-
|
|
934
|
+
size: (
|
|
935
|
+
defaultValue?: SizeValue,
|
|
936
|
+
opts: { presets?: SizePreset[]; starred?: readonly string[]; label?: string; image?: ImageVar } = {},
|
|
937
|
+
): SizeVar =>
|
|
938
|
+
new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
|
|
670
939
|
image: (defaultValue: string, opts: ImageVarOpts = {}): ImageVar => new ImageVar(defaultValue, opts),
|
|
671
940
|
}
|
|
672
941
|
|
|
@@ -682,6 +951,7 @@ export type AnyVar = {
|
|
|
682
951
|
readonly label?: string
|
|
683
952
|
/** the vars-spec key — DefinedWorkflow writes it at define time */
|
|
684
953
|
name?: string
|
|
954
|
+
readonly uiOpts: VarUi
|
|
685
955
|
parse(raw: string): boolean
|
|
686
956
|
loadJSON(value: unknown): unknown
|
|
687
957
|
reset(): unknown
|