comfy-ts 2.10.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-DFxzQfDc.js → LogsSt-U1H0mP1m.js} +35 -5
- package/dist/LogsSt-U1H0mP1m.js.map +1 -0
- package/dist/cli.js +4 -4
- package/dist/index.cjs +565 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +210 -31
- package/dist/index.d.ts +210 -31
- package/dist/index.js +561 -63
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-_nrvJYyt.js → run-serve-BeAznay5.js} +549 -43
- package/dist/run-serve-BeAznay5.js.map +1 -0
- package/dist/{run-tui-Atvf9vb3.js → run-tui-BTGjvnKk.js} +75 -18
- package/dist/run-tui-BTGjvnKk.js.map +1 -0
- package/dist/{DefinedWorkflow-BatWaZO1.js → schemaDrift-Cg39vs53.js} +644 -60
- package/dist/schemaDrift-Cg39vs53.js.map +1 -0
- package/dist/serve-web.js +523 -133
- package/dist/{state-6RFDIQwJ.js → state-C7REnHan.js} +18 -3
- package/dist/{state-6RFDIQwJ.js.map → state-C7REnHan.js.map} +1 -1
- package/dist/web.d.ts +210 -31
- package/dist/web.js +561 -63
- package/dist/web.js.map +1 -1
- package/examples/comfy-cloud/capybara-i2v.cflow.ts +2 -0
- package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +2 -0
- package/examples/comfy-cloud/wan22-i2v.cflow.ts +2 -0
- package/examples/comfy-cloud/wan22-t2v.cflow.ts +2 -0
- package/examples/rvion/06-qwen-image-edit.cflow.ts +3 -2
- package/examples/rvion/07-local-llm-text-gen.cflow.ts +2 -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 +17 -7
- package/src/cli/draftMeta.ts +39 -0
- package/src/cli/serve/ServeApp.ts +242 -12
- package/src/cli/serve/applyVarPayload.ts +50 -22
- package/src/cli/serve/describeVar.ts +49 -6
- package/src/cli/serve/favicon.ts +3 -0
- 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 +60 -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 -177
- package/src/cli/serve/web/components/controls/BasicControls.tsx +57 -32
- package/src/cli/serve/web/components/controls/LorasControl.tsx +708 -285
- 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 +281 -57
- 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 +57 -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 +472 -118
- package/src/cli/serve/webBundle.ts +54 -10
- package/src/cli/tui/components/Header.tsx +2 -0
- 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/HostSt.ts +34 -0
- 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/ComfyHost.ts +15 -0
- package/src/host/loraInfoCache.ts +70 -0
- package/src/host/loraManagerApi.ts +27 -0
- package/src/host/schemaDrift.ts +87 -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/DefinedWorkflow-BatWaZO1.js.map +0 -1
- package/dist/LogsSt-DFxzQfDc.js.map +0 -1
- package/dist/run-serve-_nrvJYyt.js.map +0 -1
- package/dist/run-tui-Atvf9vb3.js.map +0 -1
- package/src/cli/serve/web/components/Sidebar.tsx +0 -66
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// generated by scripts/gen-favicon.ts from .shipkit/identity/icon.png, never edited by hand
|
|
2
|
+
export const FAVICON_DATA_URI =
|
|
3
|
+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAAPoAAAD6AG1e1JrAAAKUklEQVR42u1aaWxU1xW2DWEJZCENNgaK8iNRU5UAAYKBWW1ImwbaoqiuQkrUVlRdlDZSGpqAcTKrFyAoJRCRKmpRidKA98Sm0MQhRClOs7CIggiTtniZN4sZe8AeL/Puvef23LeMnwePQdWwhTnS9XvP8zzvft/5znfPfXJWViYykYlMZCITmchEJjKRiUxc4eCcj8ExFkfOzQg+23huvL5pwFNKf8wYexmvZ2m/H6cpQlHFV5IYIXvtaMEh4+CM83/hIS9ZGSOUSvYNnXUNyC3iGgA2KuAZ7+NqvI3jZ6iKp3GsIYQsw+sZOmFJZIy5Ec0uRzufhOMHjMGnGnAUAAdtJALUqxgwOIYs7UBCViFptycTekNkXcv4eMzsL/Hap2Pkw0MQQbTBkj/UbvDjj514ukQvh+uWCOPE8LgUpX7UAJxpY7QAzqh6b1+rzPslZuANvZMdIoR/3/CMMdfNcqqBVyZDOV+P53FV1kCNwCEFbi5uA/U2GjoI5MBsYJFPlTIBRqnxTxnAYTws056bc83VoAP3+XzjMUu7E8AZYRyIBkwreQDDuQBNlHMl7SwO5IvtIFdNAHr8GfUmhb9hJaOTKb71L7FYLN+40lwz8HicgODrtMmRlMkeIf2MxoH53wF6sAjI3vFA6/OA9ZwWAEFXRbI1aMoSdXFWlmXzNSFBb1q09bpGmxvRpU7P7AB6ZhvQ7qPA+kPA5Bhw0seY3Ass1g48/D6jp7wgN5sw65M5rbqNk6o7gDRbFVJUIUFq4phGAhfLKvmeNqexV63dNmR/hyZQYqx01lbNSP00kGvuBLnxXhhs+ibI+7/F5H3fAL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Zkf7qusAvFEKSIK2/FjdHfcVYjuKkz5vq8SlUkwagSMAWRAiDNPsEhmVQBwFIVbF1ERtS9Di60+URPOpPrbwhQ6KpLJCQaoz8LnV3f7ANZX9qMtk8dD20+bwzbS7pOfMLv8RYVjWTQgAuzU0TI51jCRgD+EOyiYPkuLCFxi4muAKQkUp6AQ0Hu2nC51daHTBHqsr8OJKh3Tr9Qk+qX0uLh6aoDBLe3lHgd3d4UEgLWaPFLOWR3jhSwNclIoNX1tZUSXWcjyWdfECp8T2fNyDBknJ02/G+JySYH3xjrPT9O92OG6Q/yxRiEh6ISE2V49U+mYWlUmrcLkstTtbd1md/ibcwX2EajiEBnrMVBbBDs8vF3oCAyYkBZe6NQqRDj4u6wb9X4FsoQjVsFIA4HrZ8LHY1TUXbiXcUtHHbeWRTpvj7D1XvsO7qspw5NhsH4wVYB3KuwYNmAZw5UvS3bh8brW4gvvRKL/zlQKfSiEqCcaR/HnWzfWfZMX6snq1evtMZCITmchEJjKRiUxkIhM3ZfwPK9dyLD4coj4AAAAASUVORK5CYII='
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// one LLM config of the prompt enhancer: where the model runs and how it is asked. PURE (the
|
|
2
|
+
// browser bundle and serve both read it), every field runtime-checked, since the file is
|
|
3
|
+
// hand-editable. No api key here: keys stay in the browser (architecture item 13)
|
|
4
|
+
import { defaultBaseUrl, type ProviderId, type ReasoningEffort } from 'src/cli/serve/web/llm.ts'
|
|
5
|
+
|
|
6
|
+
export type LlmConfig = {
|
|
7
|
+
provider: ProviderId
|
|
8
|
+
baseUrl: string
|
|
9
|
+
model: string
|
|
10
|
+
effort: ReasoningEffort
|
|
11
|
+
/** hide models that report no reasoning support */
|
|
12
|
+
thinkingOnly: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type LlmConfigEntry = { name: string; config: LlmConfig }
|
|
16
|
+
|
|
17
|
+
export function isProvider(raw: unknown): raw is ProviderId {
|
|
18
|
+
return raw === 'openrouter' || raw === 'openwebui' || raw === 'openai'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isEffort(raw: unknown): raw is ReasoningEffort {
|
|
22
|
+
return raw === 'off' || raw === 'low' || raw === 'medium' || raw === 'high'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** explicit model ids, never an alias: behaviour and cost stay reproducible */
|
|
26
|
+
const DEFAULT_MODEL: Record<ProviderId, string> = {
|
|
27
|
+
openrouter: 'anthropic/claude-sonnet-5',
|
|
28
|
+
openwebui: '',
|
|
29
|
+
openai: '',
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** a stored file → a usable config: a half-written or hand-broken field degrades to its
|
|
33
|
+
* default, never breaks the modal */
|
|
34
|
+
export function normalizeLlmConfig(raw: unknown): LlmConfig {
|
|
35
|
+
const o = typeof raw === 'object' && raw !== null && !Array.isArray(raw) ? (raw as Record<string, unknown>) : {}
|
|
36
|
+
const provider = isProvider(o.provider) ? o.provider : 'openrouter'
|
|
37
|
+
return {
|
|
38
|
+
provider,
|
|
39
|
+
baseUrl: typeof o.baseUrl === 'string' && o.baseUrl.trim() !== '' ? o.baseUrl.trim() : defaultBaseUrl(provider),
|
|
40
|
+
model: typeof o.model === 'string' ? o.model : DEFAULT_MODEL[provider],
|
|
41
|
+
effort: isEffort(o.effort) ? o.effort : 'medium',
|
|
42
|
+
thinkingOnly: o.thinkingOnly !== false,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** switching provider resets what belongs to the old one: an openrouter model id sent to a
|
|
47
|
+
* local box, or a local base url sent to openrouter, is never what anyone means */
|
|
48
|
+
export function withProvider(c: LlmConfig, provider: ProviderId): LlmConfig {
|
|
49
|
+
if (provider === c.provider) return c
|
|
50
|
+
return { ...c, provider, baseUrl: defaultBaseUrl(provider), model: DEFAULT_MODEL[provider] }
|
|
51
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// the prompt enhancer's LLM configs as FILES: `.comfy-ts/llm-configs/<name>.json`, the drafts
|
|
2
|
+
// model. The FILENAME is the identity (a rename is a write plus a delete), validStoreName is the
|
|
3
|
+
// same gate the draft routes use. SERVE-ONLY: no workflow reads these
|
|
4
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { join } from 'pathe'
|
|
6
|
+
import { normalizeLlmConfig, type LlmConfig, type LlmConfigEntry } from 'src/cli/serve/llmConfigShape.ts'
|
|
7
|
+
import { validStoreName } from 'src/utils/safeName.ts'
|
|
8
|
+
|
|
9
|
+
const EXT = '.json'
|
|
10
|
+
|
|
11
|
+
export function llmConfigsDir(): string {
|
|
12
|
+
return comfyts.resolveFromLlmConfigs('')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function llmConfigPath(name: string): string | null {
|
|
16
|
+
const safe = validStoreName(name)
|
|
17
|
+
return safe == null ? null : join(llmConfigsDir(), `${safe}${EXT}`)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function listLlmConfigs(): LlmConfigEntry[] {
|
|
21
|
+
const dir = llmConfigsDir()
|
|
22
|
+
if (!existsSync(dir)) return []
|
|
23
|
+
const out: LlmConfigEntry[] = []
|
|
24
|
+
for (const file of readdirSync(dir).sort()) {
|
|
25
|
+
if (!file.endsWith(EXT)) continue
|
|
26
|
+
const name = file.slice(0, -EXT.length)
|
|
27
|
+
if (validStoreName(name) == null) continue
|
|
28
|
+
// one broken file is skipped loudly, the rest still list
|
|
29
|
+
try {
|
|
30
|
+
out.push({ name, config: normalizeLlmConfig(JSON.parse(readFileSync(join(dir, file), 'utf8'))) })
|
|
31
|
+
} catch (e) {
|
|
32
|
+
console.error(`[serve] llm config '${name}' unreadable, skipped:`, e)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return out
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function writeLlmConfig(name: string, config: LlmConfig): string | null {
|
|
39
|
+
const path = llmConfigPath(name)
|
|
40
|
+
if (path == null) return null
|
|
41
|
+
mkdirSync(llmConfigsDir(), { recursive: true })
|
|
42
|
+
writeFileSync(path, `${JSON.stringify(normalizeLlmConfig(config), null, 3)}\n`)
|
|
43
|
+
return path
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** a missing file is still a success: the caller asked for it to be gone, and it is */
|
|
47
|
+
export function deleteLlmConfig(name: string): boolean {
|
|
48
|
+
const path = llmConfigPath(name)
|
|
49
|
+
if (path == null) return false
|
|
50
|
+
if (existsSync(path)) rmSync(path)
|
|
51
|
+
return true
|
|
52
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// a booru tag list in memory: parsed once per source, searched per keystroke. PURE (text in, hits
|
|
2
|
+
// out). Formats: the a1111 tagcomplete csv `name,category,count,"alias,alias"`, or one tag per line
|
|
3
|
+
|
|
4
|
+
export type TagEntry = { name: string; category: number | null; count: number; aliases: string[] }
|
|
5
|
+
export type TagHit = { name: string; category: number | null; count: number; alias?: string }
|
|
6
|
+
|
|
7
|
+
/** one csv line, double-quoted fields with `""` escapes */
|
|
8
|
+
function csvFields(line: string): string[] {
|
|
9
|
+
const out: string[] = []
|
|
10
|
+
let cur = ''
|
|
11
|
+
let quoted = false
|
|
12
|
+
for (let i = 0; i < line.length; i++) {
|
|
13
|
+
const ch = line[i]
|
|
14
|
+
if (quoted) {
|
|
15
|
+
if (ch === '"' && line[i + 1] === '"') {
|
|
16
|
+
cur += '"'
|
|
17
|
+
i++
|
|
18
|
+
} else if (ch === '"') quoted = false
|
|
19
|
+
else cur += ch
|
|
20
|
+
} else if (ch === '"') quoted = true
|
|
21
|
+
else if (ch === ',') {
|
|
22
|
+
out.push(cur)
|
|
23
|
+
cur = ''
|
|
24
|
+
} else cur += ch
|
|
25
|
+
}
|
|
26
|
+
out.push(cur)
|
|
27
|
+
return out
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const intOrNull = (s: string | undefined): number | null => (s != null && /^\d+$/.test(s.trim()) ? Number(s) : null)
|
|
31
|
+
|
|
32
|
+
export function parseTagList(text: string): TagEntry[] {
|
|
33
|
+
const out: TagEntry[] = []
|
|
34
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
35
|
+
const line = raw.trim()
|
|
36
|
+
if (line === '' || line.startsWith('#')) continue
|
|
37
|
+
const f = csvFields(line)
|
|
38
|
+
const name = (f[0] ?? '').trim()
|
|
39
|
+
if (name === '') continue
|
|
40
|
+
// `name,count` (two columns) is a counted plain list; three and more is the tagcomplete shape
|
|
41
|
+
const twoCols = f.length === 2
|
|
42
|
+
out.push({
|
|
43
|
+
name,
|
|
44
|
+
category: twoCols ? null : intOrNull(f[1]),
|
|
45
|
+
count: (twoCols ? intOrNull(f[1]) : intOrNull(f[2])) ?? 0,
|
|
46
|
+
aliases: (f[3] ?? '')
|
|
47
|
+
.split(',')
|
|
48
|
+
.map((a) => a.trim())
|
|
49
|
+
.filter((a) => a !== ''),
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
return out
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** the searchable form: lowercase, spaces as underscores (the lists write `long_hair`) */
|
|
56
|
+
const key = (s: string): string => s.trim().toLowerCase().replace(/\s+/g, '_')
|
|
57
|
+
|
|
58
|
+
export class TagList {
|
|
59
|
+
private rows: { e: TagEntry; name: string; aliases: string[] }[]
|
|
60
|
+
constructor(public readonly entries: TagEntry[]) {
|
|
61
|
+
this.rows = entries.map((e) => ({ e, name: key(e.name), aliases: e.aliases.map(key) }))
|
|
62
|
+
this.rows.sort((a, b) => b.e.count - a.e.count)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static parse(text: string): TagList {
|
|
66
|
+
return new TagList(parseTagList(text))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** prefix of the name first, then prefix of an alias (answered with the name it points to),
|
|
70
|
+
* then a word inside the name (`hair` finds `long_hair`), each by post count */
|
|
71
|
+
search(query: string, limit = 20): TagHit[] {
|
|
72
|
+
const q = key(query)
|
|
73
|
+
if (q === '') return []
|
|
74
|
+
const hits: TagHit[] = []
|
|
75
|
+
const seen = new Set<string>()
|
|
76
|
+
const take = (e: TagEntry, alias?: string): boolean => {
|
|
77
|
+
if (seen.has(e.name)) return false
|
|
78
|
+
seen.add(e.name)
|
|
79
|
+
hits.push(alias == null ? { name: e.name, category: e.category, count: e.count } : { ...pick(e), alias })
|
|
80
|
+
return hits.length >= limit
|
|
81
|
+
}
|
|
82
|
+
for (const r of this.rows) if (r.name.startsWith(q) && take(r.e)) return hits
|
|
83
|
+
for (const r of this.rows) {
|
|
84
|
+
const a = r.aliases.find((x) => x.startsWith(q))
|
|
85
|
+
if (a != null && take(r.e, a)) return hits
|
|
86
|
+
}
|
|
87
|
+
for (const r of this.rows) if (r.name.includes(`_${q}`) && take(r.e)) return hits
|
|
88
|
+
return hits
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const pick = (e: TagEntry): TagHit => ({ name: e.name, category: e.category, count: e.count })
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// where a prompt's tag list comes from: `v.prompt(…, { tags })` names a url, serve reads it once and
|
|
2
|
+
// keeps it in memory. The list never ships with the code: a remote one is fetched on first use and
|
|
3
|
+
// kept under the cache dir, a local one is re-read when its file changes
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { homedir } from 'node:os'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
import { dirname, isAbsolute, join, resolve } from 'pathe'
|
|
8
|
+
import { TagList } from 'src/cli/serve/tagList.ts'
|
|
9
|
+
import { sha1HexOfString } from 'src/utils/sha1.ts'
|
|
10
|
+
|
|
11
|
+
export type TagSourceRef = { kind: 'file'; path: string } | { kind: 'http'; url: string }
|
|
12
|
+
|
|
13
|
+
/** http(s) stays a url; `file://`, `~/`, absolute and relative (to the workflow file) become a path */
|
|
14
|
+
export function resolveTagSource(url: string, moduleFile: string): TagSourceRef {
|
|
15
|
+
if (/^https?:\/\//i.test(url)) return { kind: 'http', url }
|
|
16
|
+
if (url.startsWith('file://')) return { kind: 'file', path: fileURLToPath(url) }
|
|
17
|
+
if (url === '~' || url.startsWith('~/')) return { kind: 'file', path: join(homedir(), url.slice(1)) }
|
|
18
|
+
if (isAbsolute(url)) return { kind: 'file', path: url }
|
|
19
|
+
return { kind: 'file', path: resolve(dirname(moduleFile), url) }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class TagSources {
|
|
23
|
+
private files = new Map<string, { mtimeMs: number; list: TagList }>()
|
|
24
|
+
private remote = new Map<string, Promise<TagList>>()
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
private p: {
|
|
28
|
+
/** where remote lists are kept between runs */
|
|
29
|
+
cacheDir: () => string
|
|
30
|
+
/** a capped download: a tag list url pointing at something huge must not exhaust serve */
|
|
31
|
+
fetchText: (url: string) => Promise<string>
|
|
32
|
+
},
|
|
33
|
+
) {}
|
|
34
|
+
|
|
35
|
+
async load(ref: TagSourceRef): Promise<TagList> {
|
|
36
|
+
if (ref.kind === 'file') return this.loadFile(ref.path)
|
|
37
|
+
const hit = this.remote.get(ref.url)
|
|
38
|
+
if (hit != null) return hit
|
|
39
|
+
const pending = this.loadRemote(ref.url)
|
|
40
|
+
this.remote.set(ref.url, pending)
|
|
41
|
+
// a failure is not remembered: the next keystroke retries (the network may be back)
|
|
42
|
+
pending.catch(() => this.remote.delete(ref.url))
|
|
43
|
+
return pending
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private loadFile(path: string): TagList {
|
|
47
|
+
if (!existsSync(path)) throw new Error(`tag list not found: ${path}`)
|
|
48
|
+
const mtimeMs = statSync(path).mtimeMs
|
|
49
|
+
const cached = this.files.get(path)
|
|
50
|
+
if (cached != null && cached.mtimeMs === mtimeMs) return cached.list
|
|
51
|
+
const list = TagList.parse(readFileSync(path, 'utf8'))
|
|
52
|
+
if (list.entries.length === 0) throw new Error(`tag list is empty: ${path}`)
|
|
53
|
+
this.files.set(path, { mtimeMs, list })
|
|
54
|
+
return list
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private async loadRemote(url: string): Promise<TagList> {
|
|
58
|
+
const file = join(this.p.cacheDir(), `${sha1HexOfString(url)}.txt`)
|
|
59
|
+
if (existsSync(file)) return TagList.parse(readFileSync(file, 'utf8'))
|
|
60
|
+
console.log(`[serve] fetching tag list ${url}`)
|
|
61
|
+
const text = await this.p.fetchText(url)
|
|
62
|
+
const list = TagList.parse(text)
|
|
63
|
+
if (list.entries.length === 0) throw new Error(`tag list is empty: ${url}`)
|
|
64
|
+
mkdirSync(dirname(file), { recursive: true })
|
|
65
|
+
writeFileSync(file, text)
|
|
66
|
+
console.log(`[serve] tag list ${url}: ${list.entries.length} tags, kept in ${file}`)
|
|
67
|
+
return list
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/cli/serve/web/api.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// typed fetch layer over the serve json api — the ONLY web-ui module that talks http
|
|
2
|
+
import type { LlmConfigEntry } from 'src/cli/serve/llmConfigShape.ts'
|
|
2
3
|
import type { VarDescriptor } from 'src/cli/serve/describeVar.ts'
|
|
3
4
|
|
|
4
5
|
export type ModuleDescription = {
|
|
@@ -7,6 +8,8 @@ export type ModuleDescription = {
|
|
|
7
8
|
host: string
|
|
8
9
|
drafts: string[]
|
|
9
10
|
vars: Record<string, VarDescriptor>
|
|
11
|
+
/** names of the workflow's live previews (POST /preview/<module>) */
|
|
12
|
+
previews?: string[]
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
export type IndexPayload = {
|
|
@@ -57,6 +60,20 @@ export function postGenerate(p: {
|
|
|
57
60
|
})
|
|
58
61
|
}
|
|
59
62
|
|
|
63
|
+
/** the workflow's previews for these values: nothing runs, nothing is written */
|
|
64
|
+
export function fetchPreviews(p: {
|
|
65
|
+
module: string
|
|
66
|
+
values: Record<string, unknown>
|
|
67
|
+
signal?: AbortSignal
|
|
68
|
+
}): Promise<{ previews: Record<string, string> }> {
|
|
69
|
+
return jsonFetch(`/preview/${encodeURIComponent(p.module)}`, {
|
|
70
|
+
method: 'POST',
|
|
71
|
+
headers: { 'content-type': 'application/json' },
|
|
72
|
+
body: JSON.stringify(p.values),
|
|
73
|
+
signal: p.signal,
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
60
77
|
export function saveDraft(
|
|
61
78
|
p: { module: string; draft: string; values: Record<string, unknown> },
|
|
62
79
|
opts: { keepalive?: boolean } = {},
|
|
@@ -176,6 +193,18 @@ export function postHostAction(p: { host: string; action: HostAction }): Promise
|
|
|
176
193
|
return jsonFetch(`/hosts/${encodeURIComponent(p.host)}/${p.action}`, { method: 'POST' })
|
|
177
194
|
}
|
|
178
195
|
|
|
196
|
+
export type HostDrift = { host: string; checked: boolean; changed: boolean; summary: string }
|
|
197
|
+
|
|
198
|
+
export function fetchHostDrift(p: { host: string; full: boolean }): Promise<HostDrift> {
|
|
199
|
+
return jsonFetch(`/hosts/${encodeURIComponent(p.host)}/drift${p.full ? '?full=1' : ''}`)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function postLoraCivitai(p: { host: string; lora: string }): Promise<{ ok: true; note: string }> {
|
|
203
|
+
return jsonFetch(`/hosts/${encodeURIComponent(p.host)}/lora-civitai/${encodeURIComponent(p.lora)}`, {
|
|
204
|
+
method: 'POST',
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
|
|
179
208
|
export function fetchHostLogs(p: { host: string }): Promise<{ lines: string[] }> {
|
|
180
209
|
return jsonFetch(`/hosts/${encodeURIComponent(p.host)}/logs`)
|
|
181
210
|
}
|
|
@@ -212,6 +241,23 @@ export function deletePromptEnhancer(p: { name: string }): Promise<{ ok: true; e
|
|
|
212
241
|
return jsonFetch(`/prompt-enhancers/${encodeURIComponent(p.name)}`, { method: 'DELETE' })
|
|
213
242
|
}
|
|
214
243
|
|
|
244
|
+
/** the enhancer's LLM configs, files under `.comfy-ts/llm-configs/` (server-owned) */
|
|
245
|
+
export function fetchLlmConfigs(): Promise<{ configs: LlmConfigEntry[] }> {
|
|
246
|
+
return jsonFetch('/llm-configs')
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function saveLlmConfig(p: LlmConfigEntry): Promise<{ ok: true; configs: LlmConfigEntry[] }> {
|
|
250
|
+
return jsonFetch(`/llm-configs/${encodeURIComponent(p.name)}`, {
|
|
251
|
+
method: 'PUT',
|
|
252
|
+
headers: { 'content-type': 'application/json' },
|
|
253
|
+
body: JSON.stringify(p.config),
|
|
254
|
+
})
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function deleteLlmConfig(p: { name: string }): Promise<{ ok: true; configs: LlmConfigEntry[] }> {
|
|
258
|
+
return jsonFetch(`/llm-configs/${encodeURIComponent(p.name)}`, { method: 'DELETE' })
|
|
259
|
+
}
|
|
260
|
+
|
|
215
261
|
export async function uploadFile(p: { file: File }): Promise<{ path: string; url: string | null }> {
|
|
216
262
|
const bytes = new Uint8Array(await p.file.arrayBuffer())
|
|
217
263
|
let bin = ''
|
|
@@ -222,3 +268,17 @@ export async function uploadFile(p: { file: File }): Promise<{ path: string; url
|
|
|
222
268
|
body: JSON.stringify({ name: p.file.name, dataBase64: btoa(bin) }),
|
|
223
269
|
})
|
|
224
270
|
}
|
|
271
|
+
|
|
272
|
+
export type TagHit = { name: string; category: number | null; count: number; alias?: string }
|
|
273
|
+
|
|
274
|
+
/** completion hits from the tag list a prompt var declares; a missing list throws its reason */
|
|
275
|
+
export function fetchTags(p: {
|
|
276
|
+
module: string
|
|
277
|
+
varName: string
|
|
278
|
+
q: string
|
|
279
|
+
limit?: number
|
|
280
|
+
signal?: AbortSignal
|
|
281
|
+
}): Promise<{ hits: TagHit[] }> {
|
|
282
|
+
const q = new URLSearchParams({ q: p.q, limit: String(p.limit ?? 20) })
|
|
283
|
+
return jsonFetch(`/tags/${encodeURIComponent(p.module)}/${encodeURIComponent(p.varName)}?${q}`, { signal: p.signal })
|
|
284
|
+
}
|