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
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// what you submitted, kept for the life of the page: every prompt a generate sent, every text an
|
|
2
|
+
// enhance started from. In memory only, closing the page forgets it. PURE, headless-tested
|
|
3
|
+
|
|
4
|
+
export type HistoryEntry<V> = {
|
|
5
|
+
/** what is searched and shown */
|
|
6
|
+
text: string
|
|
7
|
+
/** what a pick writes back (a prompt var holds a string or lanes) */
|
|
8
|
+
value: V
|
|
9
|
+
/** epoch ms of the LAST time this text was submitted */
|
|
10
|
+
at: number
|
|
11
|
+
/** where it was submitted from, shown dim: `04-krea2-turbo-t2i · prompt` */
|
|
12
|
+
source: string
|
|
13
|
+
/** how many times it was submitted */
|
|
14
|
+
count: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** a generous bound: a long session stays searchable without the page growing without limit */
|
|
18
|
+
export const HISTORY_CAP = 1000
|
|
19
|
+
|
|
20
|
+
/** newest first, one entry per distinct text: submitting a text again moves it to the top */
|
|
21
|
+
export function pushHistory<V>(
|
|
22
|
+
list: readonly HistoryEntry<V>[],
|
|
23
|
+
next: { text: string; value: V; at: number; source: string },
|
|
24
|
+
): HistoryEntry<V>[] {
|
|
25
|
+
if (next.text.trim() === '') return [...list]
|
|
26
|
+
const seen = list.find((e) => e.text === next.text)
|
|
27
|
+
const rest = list.filter((e) => e.text !== next.text)
|
|
28
|
+
return [{ ...next, count: (seen?.count ?? 0) + 1 }, ...rest].slice(0, HISTORY_CAP)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** every word of the query must appear in the text (any case, any order); newest first kept.
|
|
32
|
+
* A letter by letter fuzzy match would hit nearly any long prompt, words find the one you mean */
|
|
33
|
+
export function searchHistory<V>(list: readonly HistoryEntry<V>[], query: string): HistoryEntry<V>[] {
|
|
34
|
+
const words = query
|
|
35
|
+
.toLowerCase()
|
|
36
|
+
.split(/\s+/)
|
|
37
|
+
.filter((w) => w !== '')
|
|
38
|
+
if (words.length === 0) return [...list]
|
|
39
|
+
return list.filter((e) => {
|
|
40
|
+
const hay = `${e.text}\n${e.source}`.toLowerCase()
|
|
41
|
+
return words.every((w) => hay.includes(w))
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function timeAgo(at: number, now: number): string {
|
|
46
|
+
const s = Math.max(0, Math.round((now - at) / 1000))
|
|
47
|
+
if (s < 10) return 'just now'
|
|
48
|
+
if (s < 60) return `${s}s ago`
|
|
49
|
+
const m = Math.floor(s / 60)
|
|
50
|
+
if (m < 60) return `${m} min ago`
|
|
51
|
+
const h = Math.floor(m / 60)
|
|
52
|
+
if (h < 24) return `${h} h ${m % 60} min ago`
|
|
53
|
+
return `${Math.floor(h / 24)} d ago`
|
|
54
|
+
}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
// Host messages run IN ORDER, and not before the boot is done: a message that lands while the
|
|
13
13
|
// panel is still loading waits for the form instead of being dropped (WebSt.hostChain).
|
|
14
14
|
// PURE and DOM-free below `isEmbedded`: the parsers are headless-tested.
|
|
15
|
+
import { acceptChoice } from 'src/cli/serve/web/state/choiceButtons.ts'
|
|
15
16
|
import type { VarDescriptor } from 'src/cli/serve/describeVar.ts'
|
|
16
17
|
import type { HostToPanel, PanelHostAction, PanelToHost } from 'src/cli/serve/hostProtocol.ts'
|
|
17
18
|
import { asSeedForm, pruneLorasRecord } from 'src/cli/serve/web/state/payload.ts'
|
|
@@ -101,8 +102,10 @@ export function coerceHostValue(desc: VarDescriptor, raw: unknown, current: unkn
|
|
|
101
102
|
return isFiniteNumber(raw) ? { ok: true, value: raw } : REJECT
|
|
102
103
|
case 'toggle':
|
|
103
104
|
return typeof raw === 'boolean' ? { ok: true, value: raw } : REJECT
|
|
104
|
-
case 'choice':
|
|
105
|
-
|
|
105
|
+
case 'choice': {
|
|
106
|
+
const accepted = acceptChoice({ select: desc.select ?? 'one', choices: desc.choices ?? [], raw })
|
|
107
|
+
return accepted.ok ? { ok: true, value: accepted.value } : REJECT
|
|
108
|
+
}
|
|
106
109
|
case 'seed': {
|
|
107
110
|
const cur = asSeedForm(current)
|
|
108
111
|
if (isFiniteNumber(raw)) return { ok: true, value: { mode: cur.mode, value: Math.max(0, Math.floor(raw)) } }
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// the lines a prompt keeps VERBATIM through an enhance: negatives (`- `) and comments (`// `).
|
|
2
|
+
// The enhancer sends only the body to the model and writes these back itself, each on its own
|
|
3
|
+
// line, because a model asked to copy them glues a negative onto its last sentence often enough
|
|
4
|
+
// that the workflow then reads it as positive text. PURE, headless-tested
|
|
5
|
+
|
|
6
|
+
const isKept = (line: string): boolean => {
|
|
7
|
+
const t = line.trimStart()
|
|
8
|
+
return t.startsWith('- ') || t.startsWith('// ')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function splitKeptLines(text: string): { body: string; kept: string[] } {
|
|
12
|
+
const lines = text.split('\n')
|
|
13
|
+
return {
|
|
14
|
+
body: lines
|
|
15
|
+
.filter((l) => !isKept(l))
|
|
16
|
+
.join('\n')
|
|
17
|
+
.trim(),
|
|
18
|
+
kept: lines.filter(isKept).map((l) => l.trim()),
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** the negative items a kept line names, lowercased: `- blurry, jpeg` → blurry, jpeg */
|
|
23
|
+
function negativeItems(kept: readonly string[]): Set<string> {
|
|
24
|
+
const out = new Set<string>()
|
|
25
|
+
for (const line of kept) {
|
|
26
|
+
if (!line.startsWith('- ')) continue
|
|
27
|
+
for (const item of line.slice(2).split(',')) if (item.trim() !== '') out.add(item.trim().toLowerCase())
|
|
28
|
+
}
|
|
29
|
+
return out
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** the model's rewrite with the kept lines put back: whatever negative or comment lines the
|
|
33
|
+
* model wrote are dropped (the kept ones replace them), and a negative it glued onto a line
|
|
34
|
+
* (`… rain. - blurry, jpeg`) is cut off when its first item is one of the kept negatives */
|
|
35
|
+
export function finishRewrite(model: string, kept: readonly string[]): string {
|
|
36
|
+
const items = negativeItems(kept)
|
|
37
|
+
const body = model
|
|
38
|
+
.split('\n')
|
|
39
|
+
.filter((l) => kept.length === 0 || !isKept(l))
|
|
40
|
+
.map((l) => {
|
|
41
|
+
if (items.size === 0) return l
|
|
42
|
+
let at = l.indexOf(' - ')
|
|
43
|
+
while (at !== -1) {
|
|
44
|
+
const first = (l.slice(at + 3).split(',')[0] ?? '').trim().toLowerCase()
|
|
45
|
+
if (items.has(first)) return l.slice(0, at).trimEnd()
|
|
46
|
+
at = l.indexOf(' - ', at + 3)
|
|
47
|
+
}
|
|
48
|
+
return l
|
|
49
|
+
})
|
|
50
|
+
.join('\n')
|
|
51
|
+
.trim()
|
|
52
|
+
return [body, ...kept].filter((x) => x !== '').join('\n')
|
|
53
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** how a run's latent frames show: `full` in the running card at the top of the gallery, `corner`
|
|
2
|
+
* in a small floating card so the last image stays in view until the next one lands, `off` none */
|
|
3
|
+
export type LatentMode = 'full' | 'corner' | 'off'
|
|
4
|
+
|
|
5
|
+
export const LATENT_MODES: readonly { mode: LatentMode; tip: string }[] = [
|
|
6
|
+
{
|
|
7
|
+
mode: 'corner',
|
|
8
|
+
tip: 'latent small, in a corner: the last image stays where it is, the new one lands at once when done',
|
|
9
|
+
},
|
|
10
|
+
{ mode: 'full', tip: 'latent full size, in the running card at the top of the results' },
|
|
11
|
+
{ mode: 'off', tip: 'no latent: a progress bar, then the image' },
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
/** a stored value → a mode. The blob held a boolean before the corner mode existed: `true` was
|
|
15
|
+
* the old default, never a choice between full and corner, so it takes the new default */
|
|
16
|
+
export function asLatentMode(raw: unknown): LatentMode {
|
|
17
|
+
if (raw === 'full' || raw === 'corner' || raw === 'off') return raw
|
|
18
|
+
if (raw === false) return 'off'
|
|
19
|
+
return 'corner'
|
|
20
|
+
}
|
|
@@ -37,3 +37,21 @@ export function sortLoraMatches(p: {
|
|
|
37
37
|
})
|
|
38
38
|
return out
|
|
39
39
|
}
|
|
40
|
+
|
|
41
|
+
/** what the popup gallery draws: EVERY match, picked ones included, so picking a lora never
|
|
42
|
+
* moves the cards around it. `enterPick` is the first card not picked yet, what enter adds */
|
|
43
|
+
export function popupCards(p: { matches: readonly string[]; picked: readonly string[]; cap: number }): {
|
|
44
|
+
cards: string[]
|
|
45
|
+
enterPick: string | null
|
|
46
|
+
} {
|
|
47
|
+
const cards = p.matches.slice(0, p.cap)
|
|
48
|
+
const picked = new Set(p.picked)
|
|
49
|
+
return { cards, enterPick: cards.find((name) => !picked.has(name)) ?? null }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** a popup card click: the first one adds, every later one pauses or resumes, the same switch as
|
|
53
|
+
* the form card. Only the ✕ removes */
|
|
54
|
+
export function popupCardClick(p: { picked: boolean; on: boolean }): 'add' | 'pause' | 'resume' {
|
|
55
|
+
if (!p.picked) return 'add'
|
|
56
|
+
return p.on ? 'pause' : 'resume'
|
|
57
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//
|
|
1
|
+
// modules keep the folder they came from: the omnibox labels read folder/workflow/draft.
|
|
2
2
|
// PURE and DOM-free (browser side, so no node:path), tests/serve-web-tree.test.ts.
|
|
3
3
|
// the module KEY stays the basename (it is the api identity); this only decides
|
|
4
|
-
//
|
|
4
|
+
// the folder part of the label.
|
|
5
5
|
|
|
6
6
|
export type TreeItem = { module: string; file: string }
|
|
7
7
|
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// the omnibox list and its fuzzy match. PURE and DOM-free, tests/serve-web-omnibox.test.ts.
|
|
2
|
+
// one entry per draft, labelled folder/workflow/draft, so typing a folder, a workflow or a
|
|
3
|
+
// draft name all land on the same list
|
|
4
|
+
import { groupModulesByFolder, type TreeItem } from 'src/cli/serve/web/state/moduleTree.ts'
|
|
5
|
+
|
|
6
|
+
export type OmniboxEntry = { module: string; draft: string; host: string; label: string }
|
|
7
|
+
|
|
8
|
+
export function omniboxEntries(modules: readonly (TreeItem & { host: string; drafts: string[] })[]): OmniboxEntry[] {
|
|
9
|
+
const out: OmniboxEntry[] = []
|
|
10
|
+
for (const group of groupModulesByFolder(modules)) {
|
|
11
|
+
for (const mod of group.modules) {
|
|
12
|
+
// no saved draft still opens: the server serves the spec values as `default`
|
|
13
|
+
const drafts = mod.drafts.length > 0 ? mod.drafts : ['default']
|
|
14
|
+
const prefix = group.folder === '' ? mod.module : `${group.folder}/${mod.module}`
|
|
15
|
+
for (const draft of drafts)
|
|
16
|
+
out.push({ module: mod.module, draft, host: mod.host, label: `${prefix}/${draft}` })
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return out
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isBoundary(ch: string | undefined): boolean {
|
|
23
|
+
return ch == null || ch === '/' || ch === '-' || ch === '_' || ch === ' ' || ch === '.'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function scoreFrom(q: string, t: string, start: number): number | null {
|
|
27
|
+
let score = 0
|
|
28
|
+
let at = start - 1
|
|
29
|
+
for (const ch of q) {
|
|
30
|
+
const found = t.indexOf(ch, at + 1)
|
|
31
|
+
if (found < 0) return null
|
|
32
|
+
score += 1
|
|
33
|
+
if (found === at + 1) score += 3
|
|
34
|
+
if (isBoundary(t[found - 1])) score += 5
|
|
35
|
+
// late hits cost a little, so the same letters earlier in the label win ties
|
|
36
|
+
score -= (found - at - 1) * 0.05
|
|
37
|
+
at = found
|
|
38
|
+
}
|
|
39
|
+
return score
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** subsequence match, higher is better, null when the letters are not all there in order.
|
|
43
|
+
* a letter after a separator or right after the previous hit counts extra. Every place the
|
|
44
|
+
* first letter occurs is tried, since the first `a` of `examples/…/anima` is the wrong one */
|
|
45
|
+
export function fuzzyScore(query: string, text: string): number | null {
|
|
46
|
+
const q = query.toLowerCase().replace(/\s+/g, '')
|
|
47
|
+
if (q === '') return 0
|
|
48
|
+
const t = text.toLowerCase()
|
|
49
|
+
let best: number | null = null
|
|
50
|
+
for (let start = t.indexOf(q[0] ?? ''); start >= 0; start = t.indexOf(q[0] ?? '', start + 1)) {
|
|
51
|
+
const score = scoreFrom(q, t, start)
|
|
52
|
+
if (score != null && (best == null || score > best)) best = score
|
|
53
|
+
}
|
|
54
|
+
return best
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function searchOmnibox(entries: readonly OmniboxEntry[], query: string): OmniboxEntry[] {
|
|
58
|
+
if (query.trim() === '') return [...entries]
|
|
59
|
+
const scored: { entry: OmniboxEntry; score: number; ix: number }[] = []
|
|
60
|
+
for (const [ix, entry] of entries.entries()) {
|
|
61
|
+
// the draft alone first: typing a draft name should not lose to a folder that shares letters
|
|
62
|
+
const draftScore = fuzzyScore(query, entry.draft)
|
|
63
|
+
const labelScore = fuzzyScore(query, entry.label)
|
|
64
|
+
const score = Math.max(draftScore == null ? -Infinity : draftScore + 2, labelScore ?? -Infinity)
|
|
65
|
+
if (score !== -Infinity) scored.push({ entry, score, ix })
|
|
66
|
+
}
|
|
67
|
+
scored.sort((a, b) => b.score - a.score || a.ix - b.ix)
|
|
68
|
+
return scored.map((s) => s.entry)
|
|
69
|
+
}
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
// override payloads any more: drafts are live (autosave through PUT, generate
|
|
4
4
|
// posts {}) — architecture item 12, web ui
|
|
5
5
|
import type { VarDescriptor } from 'src/cli/serve/describeVar.ts'
|
|
6
|
+
import { normalizeChoice } from 'src/cli/serve/web/state/choiceButtons.ts'
|
|
7
|
+
import { isLoraLanes, type LoraRecord, type LorasInput } from 'src/vars/lanes.ts'
|
|
8
|
+
import { isLoraStrength, loraInPalette, loraIsOn as entryIsOn, loraStrengths, withLora } from 'src/vars/loraEntry.ts'
|
|
6
9
|
|
|
7
10
|
export type SeedFormValue = { mode: string; value: number }
|
|
8
11
|
export type SizeFormValue = { width: number; height: number }
|
|
@@ -38,25 +41,33 @@ export function asSizeForm(raw: unknown): SizeFormValue {
|
|
|
38
41
|
return { width: 1024, height: 1024 }
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
/** the record the web keeps holds
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
export function pruneLorasRecord(raw: unknown, options: readonly string[]): Record<string, unknown> {
|
|
44
|
+
/** the record the web keeps holds PALETTE loras only: on, or paused in the palette form. Two
|
|
45
|
+
* things are dropped: keys the host no longer offers (dead weight the ui cannot display, and a
|
|
46
|
+
* server-side build failure), and `false` entries, which LorasVar writes for every lora ever
|
|
47
|
+
* unticked in the TUI, so treating them as palette members put the WHOLE catalog in the row.
|
|
48
|
+
* A pause is `{ strength, off: true }` (src/vars/loraEntry.ts), never `false`, so it survives */
|
|
49
|
+
export function pruneLorasRecord(raw: unknown, options: readonly string[]): LoraRecord {
|
|
48
50
|
if (raw == null || typeof raw !== 'object' || Array.isArray(raw)) return {}
|
|
49
51
|
const known = new Set(options)
|
|
50
|
-
const out:
|
|
51
|
-
for (const [k, st] of Object.entries(raw as Record<string, unknown>))
|
|
52
|
+
const out: LoraRecord = {}
|
|
53
|
+
for (const [k, st] of Object.entries(raw as Record<string, unknown>))
|
|
54
|
+
if (known.has(k) && isLoraStrength(st) && loraInPalette(st)) out[k] = st
|
|
52
55
|
return out
|
|
53
56
|
}
|
|
54
57
|
|
|
58
|
+
/** either shape, pruned the same way: a plain record, or every lane's record */
|
|
59
|
+
export function normalizeLorasInput(raw: unknown, options: readonly string[]): LorasInput {
|
|
60
|
+
if (isLoraLanes(raw)) return { lanes: raw.lanes.map((l) => ({ ...l, loras: pruneLorasRecord(l.loras, options) })) }
|
|
61
|
+
return pruneLorasRecord(raw, options)
|
|
62
|
+
}
|
|
63
|
+
|
|
55
64
|
/** what a fresh VarSt starts from: the draft value when present, else the descriptor default — seed/size/loras normalized so controls never branch on shape */
|
|
56
65
|
export function normalizeInitial(desc: VarDescriptor, raw: unknown): unknown {
|
|
57
66
|
if (desc.kind === 'seed') return asSeedForm(raw ?? desc.default)
|
|
58
67
|
if (desc.kind === 'size') return asSizeForm(raw ?? desc.default)
|
|
59
|
-
if (desc.kind === 'loras') return
|
|
68
|
+
if (desc.kind === 'loras') return normalizeLorasInput(raw ?? desc.default, desc.options ?? [])
|
|
69
|
+
if (desc.kind === 'choice')
|
|
70
|
+
return normalizeChoice({ select: desc.select ?? 'one', choices: desc.choices ?? [], raw: raw ?? desc.default })
|
|
60
71
|
return raw ?? desc.default
|
|
61
72
|
}
|
|
62
73
|
|
|
@@ -64,65 +75,35 @@ export function randomSeed(): number {
|
|
|
64
75
|
return Math.floor(Math.random() * 2 ** 32)
|
|
65
76
|
}
|
|
66
77
|
|
|
67
|
-
// ---- loras record transitions
|
|
68
|
-
//
|
|
69
|
-
// number | [model, clip] | true = on. LorasVar keeps the same `prev` memory so
|
|
70
|
-
// off → on restores the strength instead of snapping to 1
|
|
78
|
+
// ---- loras record transitions: the stored spellings live in src/vars/loraEntry.ts, shared
|
|
79
|
+
// with LorasVar and serve, so the web and the library can never read a lora differently
|
|
71
80
|
|
|
72
81
|
export type LoraStrengthPair = { model: number; clip: number }
|
|
73
82
|
|
|
74
83
|
export function loraIsOn(st: unknown): boolean {
|
|
75
|
-
return st
|
|
84
|
+
return entryIsOn(st)
|
|
76
85
|
}
|
|
77
86
|
|
|
78
87
|
/** any stored strength shape → the {model, clip} pair the inputs edit */
|
|
79
88
|
export function loraStrengthPair(st: unknown): LoraStrengthPair {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return { model: 1, clip: 1 }
|
|
89
|
+
const [model, clip] = loraStrengths(st)
|
|
90
|
+
return { model, clip }
|
|
83
91
|
}
|
|
84
92
|
|
|
85
|
-
/** pause/resume
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
export function setLoraEnabled(
|
|
89
|
-
record: Record<string, unknown>,
|
|
90
|
-
name: string,
|
|
91
|
-
on: boolean,
|
|
92
|
-
prev?: LoraStrengthPair,
|
|
93
|
-
): Record<string, unknown> {
|
|
94
|
-
const next = { ...record }
|
|
95
|
-
// PAUSE KEEPS THE KEY (as `false`): deleting it dropped the lora out of the record's
|
|
96
|
-
// insertion order, so pausing a card sent it to the end of the row. `false` is the same
|
|
97
|
-
// "selected but off" spelling LorasVar uses, every reader ignores it, and normalizeInitial
|
|
98
|
-
// prunes it on load, so nothing accumulates in the draft file
|
|
99
|
-
if (!on) next[name] = false
|
|
100
|
-
else {
|
|
101
|
-
const pair = prev ?? loraStrengthPair(record[name])
|
|
102
|
-
next[name] = [pair.model, pair.clip]
|
|
103
|
-
}
|
|
104
|
-
return next
|
|
93
|
+
/** pause/resume in place: the key, its position and its strengths all stay */
|
|
94
|
+
export function setLoraEnabled(record: Record<string, unknown>, name: string, on: boolean): Record<string, unknown> {
|
|
95
|
+
return { ...record, [name]: withLora(record[name], { on }) }
|
|
105
96
|
}
|
|
106
97
|
|
|
107
|
-
/**
|
|
108
|
-
*
|
|
109
|
-
|
|
110
|
-
* the thing a drag rewrites and a pause must not touch.
|
|
111
|
-
*/
|
|
112
|
-
export function paletteOrder(p: {
|
|
113
|
-
record: Record<string, unknown>
|
|
114
|
-
options: readonly string[]
|
|
115
|
-
/** paused in this session — kept in the palette even when the record no longer lists them */
|
|
116
|
-
paused: ReadonlySet<string>
|
|
117
|
-
}): string[] {
|
|
98
|
+
/** the palette, IN ORDER: the record's own key order, so a lora you add lands at the end and
|
|
99
|
+
* nothing already on screen moves. Pure, because the order is what a drag rewrites */
|
|
100
|
+
export function paletteOrder(p: { record: Record<string, unknown>; options: readonly string[] }): string[] {
|
|
118
101
|
const known = new Set(p.options)
|
|
119
|
-
|
|
120
|
-
const pausedOnly = [...p.paused].filter((n) => known.has(n) && !inRecord.includes(n))
|
|
121
|
-
return [...inRecord, ...pausedOnly].reverse()
|
|
102
|
+
return Object.keys(p.record).filter((n) => known.has(n) && loraInPalette(p.record[n]))
|
|
122
103
|
}
|
|
123
104
|
|
|
124
|
-
/** move a lora to a new slot in the
|
|
125
|
-
*
|
|
105
|
+
/** move a lora to a new slot in the palette and give back the record rewritten in that order,
|
|
106
|
+
* the record's key order IS the stored order */
|
|
126
107
|
export function reorderLoras(p: {
|
|
127
108
|
record: Record<string, unknown>
|
|
128
109
|
/** palette order, as displayed */
|
|
@@ -135,18 +116,17 @@ export function reorderLoras(p: {
|
|
|
135
116
|
if (moved == null) return p.record
|
|
136
117
|
next.splice(p.to, 0, moved)
|
|
137
118
|
const out: Record<string, unknown> = {}
|
|
138
|
-
|
|
139
|
-
for (const name of [...next].reverse()) if (name in p.record) out[name] = p.record[name]
|
|
119
|
+
for (const name of next) if (name in p.record) out[name] = p.record[name]
|
|
140
120
|
// anything the palette does not show (a key pruned from view) keeps its entry
|
|
141
121
|
for (const [k, v] of Object.entries(p.record)) if (!(k in out)) out[k] = v
|
|
142
122
|
return out
|
|
143
123
|
}
|
|
144
124
|
|
|
145
|
-
/** set both strengths;
|
|
125
|
+
/** set both strengths; a paused lora stays paused */
|
|
146
126
|
export function setLoraStrength(
|
|
147
127
|
record: Record<string, unknown>,
|
|
148
128
|
name: string,
|
|
149
129
|
pair: LoraStrengthPair,
|
|
150
130
|
): Record<string, unknown> {
|
|
151
|
-
return { ...record, [name]: [pair.model, pair.clip] }
|
|
131
|
+
return { ...record, [name]: withLora(record[name], { strength: [pair.model, pair.clip] }) }
|
|
152
132
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** the panel's jump keys, with ⌘ (ctrl elsewhere) and no other modifier. Each one works from ANY
|
|
2
|
+
* focus, a prompt editor included: it is a jump, not an edit. Browser defaults they take over
|
|
3
|
+
* (print, open file) are useless on this page */
|
|
4
|
+
export type Shortcut = 'focus-prompt' | 'open-loras' | 'open-enhancer' | 'toggle-blur'
|
|
5
|
+
|
|
6
|
+
export const SHORTCUT_KEYS: Record<Shortcut, string> = {
|
|
7
|
+
'focus-prompt': 'P',
|
|
8
|
+
'open-loras': 'O',
|
|
9
|
+
// the same letter enhances once the enhancer is open (ENHANCER_KEYS): ⌘E, ⌘E
|
|
10
|
+
'open-enhancer': 'E',
|
|
11
|
+
'toggle-blur': 'B',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function shortcutOf(e: {
|
|
15
|
+
key: string
|
|
16
|
+
metaKey: boolean
|
|
17
|
+
ctrlKey: boolean
|
|
18
|
+
altKey: boolean
|
|
19
|
+
shiftKey: boolean
|
|
20
|
+
}): Shortcut | null {
|
|
21
|
+
if (!(e.metaKey || e.ctrlKey) || e.altKey || e.shiftKey) return null
|
|
22
|
+
const key = e.key.toUpperCase()
|
|
23
|
+
for (const [s, k] of Object.entries(SHORTCUT_KEYS) as [Shortcut, string][]) if (k === key) return s
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** which var each jump lands on: the FIRST var of that kind in the order shown, skipping one
|
|
28
|
+
* that is disabled (it takes no focus) */
|
|
29
|
+
export function jumpTargets(vars: readonly { name: string; kind: string; inactive: boolean }[]): {
|
|
30
|
+
prompt: string | null
|
|
31
|
+
loras: string | null
|
|
32
|
+
} {
|
|
33
|
+
const first = (kind: string): string | null => vars.find((v) => v.kind === kind && !v.inactive)?.name ?? null
|
|
34
|
+
return { prompt: first('prompt'), loras: first('loras') }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** the enhancer's own keys, live only while it is open. Never ⌘⏎: that one generates everywhere,
|
|
38
|
+
* and in the enhancer it generates with the rewrite (try, EnhancerSt.generateOverride) */
|
|
39
|
+
export type EnhancerShortcut = 'enhance' | 'apply'
|
|
40
|
+
|
|
41
|
+
export const ENHANCER_KEYS: Record<EnhancerShortcut, string> = { enhance: 'E', apply: 'I' }
|
|
42
|
+
|
|
43
|
+
export function enhancerShortcutOf(e: {
|
|
44
|
+
key: string
|
|
45
|
+
metaKey: boolean
|
|
46
|
+
ctrlKey: boolean
|
|
47
|
+
altKey: boolean
|
|
48
|
+
shiftKey: boolean
|
|
49
|
+
}): EnhancerShortcut | null {
|
|
50
|
+
if (!(e.metaKey || e.ctrlKey) || e.altKey || e.shiftKey) return null
|
|
51
|
+
const key = e.key.toUpperCase()
|
|
52
|
+
for (const [s, k] of Object.entries(ENHANCER_KEYS) as [EnhancerShortcut, string][]) if (k === key) return s
|
|
53
|
+
return null
|
|
54
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// size presets in the panel: which are starred (quick buttons before the list) and the tiny
|
|
2
|
+
// aspect rectangle each one draws. PURE, tests/serve-web-size-stars.test.ts
|
|
3
|
+
|
|
4
|
+
export type SizePresetLike = { label: string; width: number; height: number }
|
|
5
|
+
|
|
6
|
+
/** the starred presets, in PRESET order: your own stars when you set some, else the var's */
|
|
7
|
+
export function starredPresets<P extends SizePresetLike>(p: {
|
|
8
|
+
presets: readonly P[]
|
|
9
|
+
defaults: readonly string[]
|
|
10
|
+
mine: readonly string[] | undefined
|
|
11
|
+
}): P[] {
|
|
12
|
+
const stars = new Set(p.mine ?? p.defaults)
|
|
13
|
+
return p.presets.filter((pr) => stars.has(pr.label))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** flip one star, starting from whatever is effective right now */
|
|
17
|
+
export function toggleStar(p: {
|
|
18
|
+
defaults: readonly string[]
|
|
19
|
+
mine: readonly string[] | undefined
|
|
20
|
+
label: string
|
|
21
|
+
}): string[] {
|
|
22
|
+
const current = p.mine ?? p.defaults
|
|
23
|
+
return current.includes(p.label) ? current.filter((l) => l !== p.label) : [...current, p.label]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** the rectangle for an aspect icon: the long side fills `box`, the short one keeps the ratio */
|
|
27
|
+
export function aspectBox(width: number, height: number, box: number): { w: number; h: number } {
|
|
28
|
+
if (width <= 0 || height <= 0) return { w: box, h: box }
|
|
29
|
+
const scale = box / Math.max(width, height)
|
|
30
|
+
return { w: Math.max(2, Math.round(width * scale)), h: Math.max(2, Math.round(height * scale)) }
|
|
31
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// the preview pane never shifts: every part it can show is always there, at one size. These are
|
|
2
|
+
// the pure halves: what a run chip says and what a collapsed prompt preview shows
|
|
3
|
+
|
|
4
|
+
/** a chip's text at a FIXED shape: the count is the only part that changes, and the css gives it
|
|
5
|
+
* a width and tabular digits, so 9 → 10 → 100 never pushes a neighbour */
|
|
6
|
+
export function runChipText(p: { kind: 'queue' | 'results'; count: number }): { label: string; count: string } {
|
|
7
|
+
return { label: p.kind, count: String(Math.max(0, Math.min(999, Math.round(p.count)))) }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** a collapsed preview is ALWAYS two lines, whatever the prompt holds: the positive lines joined,
|
|
11
|
+
* then the negative ones joined (empty when there are none). Typing a line break or a `- ` line
|
|
12
|
+
* changes what the two lines say, never how many there are */
|
|
13
|
+
export function collapsedPreview(text: string): { positive: string; negative: string } {
|
|
14
|
+
const lines = text
|
|
15
|
+
.split('\n')
|
|
16
|
+
.map((l) => l.trim())
|
|
17
|
+
.filter((l) => l !== '')
|
|
18
|
+
const negative = lines.filter((l) => l.startsWith('- ')).map((l) => l.slice(2).trim())
|
|
19
|
+
const positive = lines.filter((l) => !l.startsWith('- '))
|
|
20
|
+
return { positive: positive.join(' · '), negative: negative.join(' · ') }
|
|
21
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// vars that go together (VarUi.group): CONSECUTIVE rows with the same group share one block.
|
|
2
|
+
// PURE, tests/serve-web-var-groups.test.ts. A group split by a row you dragged between its
|
|
3
|
+
// members becomes two blocks, which is what the eye sees anyway
|
|
4
|
+
|
|
5
|
+
export type GroupPlace = { pos: 'solo' | 'start' | 'mid' | 'end'; color: string | null } | null
|
|
6
|
+
|
|
7
|
+
export function groupPlaces(rows: readonly { group?: string; groupColor?: string }[]): GroupPlace[] {
|
|
8
|
+
const out: GroupPlace[] = rows.map(() => null)
|
|
9
|
+
let i = 0
|
|
10
|
+
while (i < rows.length) {
|
|
11
|
+
const g = rows[i]?.group
|
|
12
|
+
if (g == null) {
|
|
13
|
+
i++
|
|
14
|
+
continue
|
|
15
|
+
}
|
|
16
|
+
let j = i
|
|
17
|
+
while (j + 1 < rows.length && rows[j + 1]?.group === g) j++
|
|
18
|
+
const color = rows.slice(i, j + 1).find((r) => r.groupColor != null)?.groupColor ?? null
|
|
19
|
+
for (let k = i; k <= j; k++)
|
|
20
|
+
out[k] = { pos: i === j ? 'solo' : k === i ? 'start' : k === j ? 'end' : 'mid', color }
|
|
21
|
+
i = j + 1
|
|
22
|
+
}
|
|
23
|
+
return out
|
|
24
|
+
}
|