comfy-ts 1.0.0 → 1.2.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 +60 -11
- package/dist/cli.js +4 -4439
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +445 -172
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7439 -340
- package/dist/index.d.ts +7457 -358
- package/dist/index.js +444 -172
- package/dist/index.js.map +1 -1
- package/dist/{run-tui-BFhba_oG.js → run-tui-BAdizWsO.js} +1244 -201
- package/dist/run-tui-BAdizWsO.js.map +1 -0
- package/dist/state-BYbxDgfr.js +5258 -0
- package/dist/state-BYbxDgfr.js.map +1 -0
- package/examples/README.md +32 -0
- package/examples/comfy-cloud/ace-step-t2a.cflow.ts +79 -0
- package/examples/comfy-cloud/anima-t2i.cflow.ts +57 -0
- package/examples/comfy-cloud/boogu-i2i.cflow.ts +76 -0
- package/examples/comfy-cloud/capybara-i2i.cflow.ts +85 -0
- package/examples/comfy-cloud/capybara-i2v.cflow.ts +90 -0
- package/examples/comfy-cloud/capybara-t2i.cflow.ts +67 -0
- package/examples/comfy-cloud/chatterbox-t2a.cflow.ts +79 -0
- package/examples/comfy-cloud/chroma-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/cloudHost.ts +41 -0
- package/examples/comfy-cloud/ernie-t2i.cflow.ts +59 -0
- package/examples/comfy-cloud/firered-i2i.cflow.ts +74 -0
- package/examples/comfy-cloud/flux1-i2i.cflow.ts +76 -0
- package/examples/comfy-cloud/flux1-t2i.cflow.ts +63 -0
- package/examples/comfy-cloud/flux2-i2i.cflow.ts +80 -0
- package/examples/comfy-cloud/flux2-t2i.cflow.ts +57 -0
- package/examples/comfy-cloud/hidream-i2i.cflow.ts +89 -0
- package/examples/comfy-cloud/hidream-t2i.cflow.ts +65 -0
- package/examples/comfy-cloud/hunyuan-video-i2v.cflow.ts +93 -0
- package/examples/comfy-cloud/hunyuan-video-t2v.cflow.ts +74 -0
- package/examples/comfy-cloud/ideogram4-t2i.cflow.ts +80 -0
- package/examples/comfy-cloud/kandinsky5-i2v.cflow.ts +95 -0
- package/examples/comfy-cloud/kandinsky5-t2i.cflow.ts +60 -0
- package/examples/comfy-cloud/kandinsky5-t2v.cflow.ts +78 -0
- package/examples/comfy-cloud/krea2-t2i.cflow.ts +59 -0
- package/examples/comfy-cloud/lens-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/longcat-i2i.cflow.ts +74 -0
- package/examples/comfy-cloud/longcat-t2i.cflow.ts +65 -0
- package/examples/comfy-cloud/ltxv-i2v.cflow.ts +92 -0
- package/examples/comfy-cloud/ltxv-t2v.cflow.ts +78 -0
- package/examples/comfy-cloud/newbie-t2i.cflow.ts +67 -0
- package/examples/comfy-cloud/omnigen2-i2i.cflow.ts +86 -0
- package/examples/comfy-cloud/omnigen2-t2i.cflow.ts +62 -0
- package/examples/comfy-cloud/ovis-t2i.cflow.ts +56 -0
- package/examples/comfy-cloud/pixeldit-t2i.cflow.ts +63 -0
- package/examples/comfy-cloud/qwen-image-i2i.cflow.ts +69 -0
- package/examples/comfy-cloud/qwen-image-t2i.cflow.ts +55 -0
- package/examples/comfy-cloud/sd35-t2i.cflow.ts +48 -0
- package/examples/comfy-cloud/sdk.d.ts +445 -57
- package/examples/comfy-cloud/sdxl-t2i.cflow.ts +69 -0
- package/examples/comfy-cloud/stable-audio-t2a.cflow.ts +53 -0
- package/examples/comfy-cloud/svd-i2v.cflow.ts +75 -0
- package/examples/comfy-cloud/wan21-i2v.cflow.ts +83 -0
- package/examples/comfy-cloud/wan21-t2v.cflow.ts +64 -0
- package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +69 -0
- package/examples/comfy-cloud/wan22-i2v.cflow.ts +107 -0
- package/examples/comfy-cloud/wan22-t2v.cflow.ts +98 -0
- package/examples/comfy-cloud/z-image-t2i.cflow.ts +62 -0
- package/examples/images/README.md +18 -0
- package/examples/images/bear_1024x1024.jpg +0 -0
- package/examples/images/deer_768x1344.jpg +0 -0
- package/examples/images/dog_512x512.jpg +0 -0
- package/examples/images/lioness_768x768.jpg +0 -0
- package/examples/images/pug_200x300.jpg +0 -0
- package/examples/images/walrus_1344x768.jpg +0 -0
- package/examples/{01-txt2img.cflow.ts → rvion/01-txt2img.cflow.ts} +1 -1
- package/examples/{02-img2img-upload.cflow.ts → rvion/02-img2img-upload.cflow.ts} +7 -18
- package/examples/{03-export-workflow-json.cflow.ts → rvion/03-export-workflow-json.cflow.ts} +1 -1
- package/examples/{04-krea2-turbo-t2i.cflow.ts → rvion/04-krea2-turbo-t2i.cflow.ts} +2 -2
- package/examples/rvion/05-comfy-cloud.cflow.ts +51 -0
- package/examples/rvion/06-qwen-image-edit.cflow.ts +89 -0
- package/guide-for-agents.md +7 -1
- package/package.json +18 -4
- package/src/cli/tui/components/CopyOverlay.tsx +25 -0
- package/src/cli/tui/components/Header.tsx +9 -4
- package/src/cli/tui/components/HostPanel.tsx +3 -2
- package/src/cli/tui/components/HostsOverlay.tsx +33 -0
- package/src/cli/tui/components/PreviewPanel.tsx +9 -8
- package/src/cli/tui/components/StatusBar.tsx +39 -9
- package/src/cli/tui/components/TreePanel.tsx +17 -7
- package/src/cli/tui/components/TuiApp.tsx +65 -5
- package/src/cli/tui/discoverWorkflows.ts +7 -41
- package/src/cli/tui/imagePicker/ImagePickerOverlay.tsx +72 -0
- package/src/cli/tui/imagePicker/ImagePickerSt.ts +288 -0
- package/src/cli/tui/imagePicker/fsListing.ts +48 -0
- package/src/cli/tui/imagePicker/pickerPrefs.ts +78 -0
- package/src/cli/tui/run-tui.tsx +49 -8
- package/src/cli/tui/state/DraftsSt.ts +3 -2
- package/src/cli/tui/state/ExecSt.ts +108 -12
- package/src/cli/tui/state/HostSt.ts +94 -10
- package/src/cli/tui/state/LorasSt.ts +14 -36
- package/src/cli/tui/state/PickerSt.ts +8 -2
- package/src/cli/tui/state/PreviewSt.ts +28 -2
- package/src/cli/tui/state/QueueSt.ts +2 -2
- package/src/cli/tui/state/SettingsSt.ts +25 -7
- package/src/cli/tui/state/TreeSt.ts +139 -36
- package/src/cli/tui/state/TuiSt.ts +53 -6
- package/src/cli/tui/state/WorkflowsSt.ts +14 -2
- package/src/cli/tui/treeRows.ts +165 -0
- package/src/exampleAssets.ts +56 -0
- package/src/graph/ComfyNode.ts +4 -1
- package/src/host/ComfyHost.ts +7 -0
- package/src/index.ts +7 -0
- package/src/manager/ComfyRegistry.ts +37 -9
- package/src/manager/generated/KnownComfyCustomNodeName.ts +23852 -1926
- package/src/manager/generated/KnownComfyPluginTitle.ts +6854 -236
- package/src/manager/generated/KnownComfyPluginURL.ts +3425 -111
- package/src/manager/generated/KnownModel_Base.ts +23 -7
- package/src/manager/generated/KnownModel_FileName.ts +421 -0
- package/src/manager/generated/KnownModel_Name.ts +421 -0
- package/src/manager/generated/KnownModel_SavePath.ts +34 -8
- package/src/manager/generated/KnownModel_Type.ts +18 -14
- package/src/manager/json/alter-list.json +221 -221
- package/src/manager/json/custom-node-list.json +61020 -21946
- package/src/manager/json/extension-node-map.json +81077 -31176
- package/src/manager/json/github-stats.json +29321 -12601
- package/src/manager/json/model-list.json +5935 -4997
- package/src/manager/loaders/parseReport.ts +55 -0
- package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +15 -49
- package/src/manager/loaders/step2_custom-node-list-loader.ts +38 -83
- package/src/manager/loaders/step3_extension-node-map-loader.ts +36 -142
- package/src/manager/loaders/step4_model-list-loader.ts +25 -36
- package/src/manager/loaders/step5_alter-list-loader.ts +29 -0
- package/src/manager/loaders/step6_github-stats-loader.ts +23 -0
- package/src/manager/script-update-manager.bun.ts +9 -1
- package/src/manager/types/ComfyManagerAlterInfo.ts +13 -0
- package/src/manager/types/ComfyManagerFileModelInfo.ts +7 -3
- package/src/manager/types/ComfyManagerFilePluginContent.ts +6 -9
- package/src/manager/types/ComfyManagerFilePluginList.ts +3 -3
- package/src/manager/types/ComfyManagerGithubStats.ts +9 -0
- package/src/manager/types/ComfyManagerPluginContentMetadata.ts +2 -3
- package/src/manager/types/ComfyManagerPluginInfo.ts +48 -34
- package/src/runner/ComfyWorkflowLayout.ts +6 -4
- package/src/sdk-generator/ComfySchema.ts +14 -1
- package/src/sdk-generator/comfyui-sdk-codegen.ts +15 -0
- package/src/sdk-generator/inputWidgetKind.ts +17 -0
- package/src/state.ts +7 -1
- package/src/vars/ComfyVars.ts +106 -5
- package/src/vars/DefinedWorkflow.ts +28 -10
- package/dist/DefinedWorkflow-O3ynII3Y.js +0 -598
- package/dist/DefinedWorkflow-O3ynII3Y.js.map +0 -1
- package/dist/run-tui-BFhba_oG.js.map +0 -1
- package/examples/05-comfy-cloud.cflow.ts +0 -67
- package/src/utils/tryExtracting.ts +0 -41
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { makeAutoObservable } from 'mobx'
|
|
3
|
+
import { dirname, join } from 'pathe'
|
|
4
|
+
import { logError } from 'src/utils/log.ts'
|
|
5
|
+
|
|
6
|
+
export const RECENTS_CAP = 20
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* image-picker favorites + recents + lastFolder — loraKeywords pattern:
|
|
10
|
+
* observable, loaded once, written through on every mutation. Human-editable
|
|
11
|
+
* json at `.comfy-ts/image-picker.json` (hand-tuned data, NOT under cache/ —
|
|
12
|
+
* survives a cache wipe):
|
|
13
|
+
* { "favorites": ["/abs/dir"], "recents": ["/abs/img.png"], "lastFolder": "/abs/dir" }
|
|
14
|
+
* A corrupt file logs loud and starts fresh, never blocks the TUI. The class
|
|
15
|
+
* takes its file path explicitly so tests round-trip it headless; the TUI
|
|
16
|
+
* uses the ONE lazy module singleton below.
|
|
17
|
+
*/
|
|
18
|
+
export class PickerPrefs {
|
|
19
|
+
/** favorite FOLDERS, absolute — recents cover files */
|
|
20
|
+
favorites: string[] = []
|
|
21
|
+
/** picked images, absolute, newest first, deduped, capped */
|
|
22
|
+
recents: string[] = []
|
|
23
|
+
lastFolder: string | null = null
|
|
24
|
+
|
|
25
|
+
constructor(public readonly path: string) {
|
|
26
|
+
this.load()
|
|
27
|
+
makeAutoObservable(this)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private load(): void {
|
|
31
|
+
if (!existsSync(this.path)) return
|
|
32
|
+
try {
|
|
33
|
+
const raw: unknown = JSON.parse(readFileSync(this.path, 'utf8'))
|
|
34
|
+
if (raw == null || typeof raw !== 'object') throw new Error('not a json object')
|
|
35
|
+
const o = raw as Record<string, unknown>
|
|
36
|
+
if (Array.isArray(o.favorites)) this.favorites = o.favorites.filter((f): f is string => typeof f === 'string')
|
|
37
|
+
if (Array.isArray(o.recents))
|
|
38
|
+
this.recents = o.recents.filter((r): r is string => typeof r === 'string').slice(0, RECENTS_CAP)
|
|
39
|
+
if (typeof o.lastFolder === 'string') this.lastFolder = o.lastFolder
|
|
40
|
+
} catch (e) {
|
|
41
|
+
logError(`[imagePicker] unreadable ${this.path} — starting fresh: ${String(e)}`)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private write(): void {
|
|
46
|
+
try {
|
|
47
|
+
mkdirSync(dirname(this.path), { recursive: true })
|
|
48
|
+
const json = { favorites: this.favorites, recents: this.recents, lastFolder: this.lastFolder }
|
|
49
|
+
writeFileSync(this.path, `${JSON.stringify(json, null, 2)}\n`)
|
|
50
|
+
} catch (e) {
|
|
51
|
+
logError(`[imagePicker] write failed ${this.path}: ${String(e)}`)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
isFavorite(dir: string): boolean {
|
|
56
|
+
return this.favorites.includes(dir)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
toggleFavorite(dir: string): void {
|
|
60
|
+
this.favorites = this.favorites.includes(dir) ? this.favorites.filter((f) => f !== dir) : [...this.favorites, dir]
|
|
61
|
+
this.write()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** a pick records the image (newest first, deduped, capped) AND remembers its folder */
|
|
65
|
+
recordPick(imagePath: string): void {
|
|
66
|
+
this.recents = [imagePath, ...this.recents.filter((r) => r !== imagePath)].slice(0, RECENTS_CAP)
|
|
67
|
+
this.lastFolder = dirname(imagePath)
|
|
68
|
+
this.write()
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let _prefs: PickerPrefs | null = null
|
|
73
|
+
|
|
74
|
+
/** the TUI's store, bound lazily to `.comfy-ts/image-picker.json` (gitignored) */
|
|
75
|
+
export function pickerPrefs(): PickerPrefs {
|
|
76
|
+
if (_prefs == null) _prefs = new PickerPrefs(join(comfyts.baseFolder, 'image-picker.json'))
|
|
77
|
+
return _prefs
|
|
78
|
+
}
|
package/src/cli/tui/run-tui.tsx
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { realpathSync, statSync } from 'node:fs'
|
|
1
|
+
import { readFileSync, realpathSync, statSync } from 'node:fs'
|
|
2
2
|
import { pathToFileURL } from 'node:url'
|
|
3
3
|
import { render } from 'ink'
|
|
4
4
|
import { dirname, resolve } from 'pathe'
|
|
5
5
|
import { COMFY_TS_TUI_ENV } from 'src/cli/tui-env.ts'
|
|
6
|
-
import {
|
|
6
|
+
import { settingsPathFor } from 'src/state.ts'
|
|
7
|
+
import { mergeWorkflowSources, scanCflowFiles } from 'src/cli/tui/discoverWorkflows.ts'
|
|
8
|
+
import { bundledExamplesDir } from 'src/exampleAssets.ts'
|
|
7
9
|
import { findDefinedWorkflow } from 'src/cli/tui/findDefinedWorkflow.ts'
|
|
8
10
|
import { installProtocolImagePainter } from 'src/cli/tui/protocolImagePainter.ts'
|
|
9
11
|
import { TuiApp } from 'src/cli/tui/components/TuiApp.tsx'
|
|
@@ -12,6 +14,22 @@ import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
|
|
|
12
14
|
import { logError } from 'src/utils/log.ts'
|
|
13
15
|
import type { DefinedWorkflow } from 'src/vars/DefinedWorkflow.ts'
|
|
14
16
|
|
|
17
|
+
/** the module the last session was on, IF it is still in this run's tree
|
|
18
|
+
* (settings write: SettingsSt; exported for the headless test) */
|
|
19
|
+
export function rememberedWorkflow(
|
|
20
|
+
workflowFiles: string[],
|
|
21
|
+
settingsPath = settingsPathFor(process.cwd()),
|
|
22
|
+
): string | null {
|
|
23
|
+
try {
|
|
24
|
+
const raw: unknown = JSON.parse(readFileSync(settingsPath, 'utf8'))
|
|
25
|
+
if (raw == null || typeof raw !== 'object') return null
|
|
26
|
+
const last = (raw as Record<string, unknown>).lastWorkflow
|
|
27
|
+
return typeof last === 'string' && workflowFiles.includes(last) ? last : null
|
|
28
|
+
} catch {
|
|
29
|
+
return null // no settings yet, or unreadable json — the default pick is fine
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
15
33
|
export async function runTui(args: string[]): Promise<number> {
|
|
16
34
|
// no arg = cwd scan MERGED with the examples packaged with comfy-ts; an
|
|
17
35
|
// explicit dir/file arg keeps that scope only (a file arg is preselected)
|
|
@@ -34,10 +52,20 @@ export async function runTui(args: string[]): Promise<number> {
|
|
|
34
52
|
const examplesDir = canImportBundled ? bundledExamplesDir() : null
|
|
35
53
|
if (!canImportBundled && target == null)
|
|
36
54
|
logError('packaged examples skipped: importing .cflow.ts from node_modules needs bun (bunx --bun comfy-ts tui)')
|
|
55
|
+
// rvion/ (the numbered didactic sequence) ahead of the zoo: with no file
|
|
56
|
+
// arg the FIRST LOADABLE bundled module is the opening workflow, and that
|
|
57
|
+
// must stay 01-txt2img, not the zoo's alphabetical head (the tree itself
|
|
58
|
+
// stays alphabetical — this only orders the load candidates)
|
|
59
|
+
const bundledFiles =
|
|
60
|
+
examplesDir == null
|
|
61
|
+
? []
|
|
62
|
+
: scanCflowFiles(realpathSync(examplesDir)).sort(
|
|
63
|
+
(a, b) => Number(!a.includes('/rvion/')) - Number(!b.includes('/rvion/')) || a.localeCompare(b),
|
|
64
|
+
)
|
|
37
65
|
const discovery = mergeWorkflowSources({
|
|
38
66
|
explicitTarget: target != null,
|
|
39
67
|
scanned: scannedPlusArg,
|
|
40
|
-
bundledFiles
|
|
68
|
+
bundledFiles,
|
|
41
69
|
})
|
|
42
70
|
const workflowFiles = discovery.files
|
|
43
71
|
if (workflowFiles.length === 0) {
|
|
@@ -45,11 +73,14 @@ export async function runTui(args: string[]): Promise<number> {
|
|
|
45
73
|
return 1
|
|
46
74
|
}
|
|
47
75
|
|
|
48
|
-
// initial module = the file arg, else the
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
76
|
+
// initial module = the file arg, else the workflow the LAST session was on
|
|
77
|
+
// (settings read straight from disk: the comfyts global only exists once a
|
|
78
|
+
// module imports), else the first candidate that LOADS: a module whose
|
|
79
|
+
// import throws (missing schema cache, bad code) or that exports no
|
|
80
|
+
// DefinedWorkflow becomes a red row in the tree, never a crash
|
|
81
|
+
const preferred =
|
|
82
|
+
!isDir && workflowFiles.includes(abs) ? abs : target == null ? rememberedWorkflow(workflowFiles) : null
|
|
83
|
+
const candidates = preferred != null ? [preferred, ...workflowFiles.filter((f) => f !== preferred)] : workflowFiles
|
|
53
84
|
const loadErrors = new Map<string, string>()
|
|
54
85
|
let first: string | null = null
|
|
55
86
|
let wf: DefinedWorkflow | null = null
|
|
@@ -82,10 +113,18 @@ export async function runTui(args: string[]): Promise<number> {
|
|
|
82
113
|
// editor keys); unsupporting terminals ignore it.
|
|
83
114
|
const altScreen = process.stdout.isTTY === true
|
|
84
115
|
if (altScreen) process.stdout.write('\u001b[?1049h\u001b[H\u001b[>4;1m')
|
|
116
|
+
// RAW MODE BEFORE RENDER: ink's kittyKeyboard auto-detect sends its `CSI ? u`
|
|
117
|
+
// query from the Ink constructor, but raw mode only turns on later when
|
|
118
|
+
// useInput mounts. In that window the terminal's `CSI ? 0 u` reply is echoed
|
|
119
|
+
// by termios (ECHOCTL) as literal `^[[?0u` into the first frame (his repro).
|
|
120
|
+
// Raw mode off = echo on, so flip it ourselves first (inside the try so the
|
|
121
|
+
// finally always restores); ink owns it afterwards and restores cooked mode
|
|
122
|
+
// on exit.
|
|
85
123
|
// REAL images over the preview panel rect on OSC-1337 terminals (repaints
|
|
86
124
|
// after every stdout flush + on image change — NOT a React effect)
|
|
87
125
|
const uninstallPainter = installProtocolImagePainter(st)
|
|
88
126
|
try {
|
|
127
|
+
if (process.stdin.isTTY === true) process.stdin.setRawMode(true)
|
|
89
128
|
// kittyKeyboard auto: ink queries `CSI ? u` and enables CSI-u encoding
|
|
90
129
|
// where supported (iTerm2 3.5+/WezTerm/kitty/ghostty) — ⇧⏎ parsed natively
|
|
91
130
|
const app = render(<TuiApp st={st} />, { kittyKeyboard: { mode: 'auto' } })
|
|
@@ -94,6 +133,8 @@ export async function runTui(args: string[]): Promise<number> {
|
|
|
94
133
|
await app.waitUntilExit()
|
|
95
134
|
st.dispose()
|
|
96
135
|
} finally {
|
|
136
|
+
// ink restores cooked mode on clean exit; this covers a throw before mount
|
|
137
|
+
if (process.stdin.isTTY === true) process.stdin.setRawMode(false)
|
|
97
138
|
uninstallPainter()
|
|
98
139
|
// reset colors + erase WHILE STILL in the alt screen: ED deletes iTerm
|
|
99
140
|
// inline images too — without this the last protocol image and stray
|
|
@@ -9,13 +9,14 @@ import {
|
|
|
9
9
|
writeFileSync,
|
|
10
10
|
} from 'node:fs'
|
|
11
11
|
import { makeAutoObservable, reaction } from 'mobx'
|
|
12
|
-
import {
|
|
12
|
+
import { dirname, join } from 'pathe'
|
|
13
|
+
import { moduleName } from 'src/cli/tui/treeRows.ts'
|
|
13
14
|
import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
|
|
14
15
|
import type { TuiMode, TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
15
16
|
|
|
16
17
|
/** module basename (`01-txt2img`) keys the draft folder — knowable for EVERY tree file without importing it */
|
|
17
18
|
export function draftKeyForFile(file: string): string {
|
|
18
|
-
return
|
|
19
|
+
return moduleName(file)
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export function draftsDirForFile(file: string): string {
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process'
|
|
2
2
|
import { makeAutoObservable, runInAction } from 'mobx'
|
|
3
3
|
import { basename } from 'pathe'
|
|
4
|
+
import type { ComfyHost } from 'src/host/ComfyHost.ts'
|
|
4
5
|
import type { ExecutionProgress } from 'src/runner/ComfyExecution.ts'
|
|
5
6
|
import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
|
|
6
7
|
import type { SeedVar } from 'src/vars/ComfyVars.ts'
|
|
7
8
|
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
8
9
|
|
|
10
|
+
/** popup body: summary + the head of the copied json (proof of WHAT is in the clipboard) */
|
|
11
|
+
export function jsonHead(text: string, maxLines: number): string[] {
|
|
12
|
+
const lines = text.split('\n')
|
|
13
|
+
const head = lines.slice(0, maxLines).map((l) => (l.length > 76 ? `${l.slice(0, 75)}…` : l))
|
|
14
|
+
if (lines.length > maxLines) head.push('…')
|
|
15
|
+
return head
|
|
16
|
+
}
|
|
17
|
+
|
|
9
18
|
/** run lifecycle + outputs + status line + clipboard/open actions */
|
|
10
19
|
export class ExecSt {
|
|
11
20
|
constructor(private st: TuiSt) {
|
|
@@ -24,6 +33,11 @@ export class ExecSt {
|
|
|
24
33
|
/** the prompt currently executing on the server (progress belongs to it) */
|
|
25
34
|
private currentPromptId: string | null = null
|
|
26
35
|
|
|
36
|
+
/** every host a latent-preview handler is installed on — a queued run may
|
|
37
|
+
* target a DIFFERENT host after an `h` override switch, and clearing only
|
|
38
|
+
* the last run's host would leak the handler on the first one */
|
|
39
|
+
private latentHosts: Set<ComfyHost> = new Set()
|
|
40
|
+
|
|
27
41
|
get running(): boolean {
|
|
28
42
|
return this.inFlight > 0
|
|
29
43
|
}
|
|
@@ -40,7 +54,7 @@ export class ExecSt {
|
|
|
40
54
|
/** every run takes THIS path, queued ones included: same progress, outputs, previews */
|
|
41
55
|
async run(): Promise<void> {
|
|
42
56
|
const queued = this.running
|
|
43
|
-
const host = this.st.
|
|
57
|
+
const host = this.st.runHost
|
|
44
58
|
runInAction(() => {
|
|
45
59
|
this.inFlight++
|
|
46
60
|
this.error = null
|
|
@@ -54,12 +68,16 @@ export class ExecSt {
|
|
|
54
68
|
// 'latent small' / 'last output' preview settings show it while
|
|
55
69
|
// running (full reset belongs to workflow switches)
|
|
56
70
|
this.st.preview.clearLatent()
|
|
57
|
-
// installed while ANY run is in flight, so queued prompts keep painting latents
|
|
58
|
-
host.onLatentPreview = (p) => void this.st.preview.renderLatent(p.bytes)
|
|
59
71
|
}
|
|
72
|
+
// installed while ANY run is in flight (queued prompts keep painting
|
|
73
|
+
// latents), on THIS run's host — it may differ from the previous
|
|
74
|
+
// run's after an `h` override switch
|
|
75
|
+
host.onLatentPreview = (p) => void this.st.preview.renderLatent(p.bytes)
|
|
76
|
+
this.latentHosts.add(host)
|
|
60
77
|
})
|
|
61
78
|
try {
|
|
62
79
|
const execution = await this.st.wf.run({
|
|
80
|
+
host: this.st.hostOverride ?? undefined,
|
|
63
81
|
onProgress: (p) => runInAction(() => this.onProgress(p)),
|
|
64
82
|
})
|
|
65
83
|
runInAction(() => {
|
|
@@ -80,7 +98,10 @@ export class ExecSt {
|
|
|
80
98
|
this.progress = null
|
|
81
99
|
this.currentPromptId = null
|
|
82
100
|
this.st.preview.clearLatent()
|
|
83
|
-
if (this.inFlight === 0)
|
|
101
|
+
if (this.inFlight === 0) {
|
|
102
|
+
for (const h of this.latentHosts) h.onLatentPreview = null
|
|
103
|
+
this.latentHosts.clear()
|
|
104
|
+
}
|
|
84
105
|
})
|
|
85
106
|
}
|
|
86
107
|
}
|
|
@@ -123,6 +144,30 @@ export class ExecSt {
|
|
|
123
144
|
}
|
|
124
145
|
|
|
125
146
|
// ---- clipboard ----
|
|
147
|
+
|
|
148
|
+
/** `c`/`C` end HERE, success or failure — a copy must never be silent
|
|
149
|
+
* (his repro: 'c does nothing', the notice line was too quiet) */
|
|
150
|
+
copyPopup: { title: string; ok: boolean; lines: string[] } | null = null
|
|
151
|
+
|
|
152
|
+
/** a copy build can hang on a stalled-host upload: guard double-presses */
|
|
153
|
+
private copying = false
|
|
154
|
+
|
|
155
|
+
closeCopyPopup(): void {
|
|
156
|
+
this.copyPopup = null
|
|
157
|
+
this.st.mode = 'nav'
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private showCopyPopup(title: string, ok: boolean, lines: string[]): void {
|
|
161
|
+
// the build is async: if the user moved into an editor meanwhile, never
|
|
162
|
+
// steal their keys — degrade to the notice line instead of a popup
|
|
163
|
+
const m = this.st.mode
|
|
164
|
+
if (m === 'edit' || m.startsWith('overlay-')) {
|
|
165
|
+
this.notice = `${ok ? '✓' : '✗'} ${title}`
|
|
166
|
+
return
|
|
167
|
+
}
|
|
168
|
+
this.copyPopup = { title, ok, lines }
|
|
169
|
+
this.st.mode = 'overlay-copy'
|
|
170
|
+
}
|
|
126
171
|
private toClipboard(text: string): Promise<boolean> {
|
|
127
172
|
const [cmd, ...args] =
|
|
128
173
|
process.platform === 'darwin'
|
|
@@ -141,32 +186,83 @@ export class ExecSt {
|
|
|
141
186
|
|
|
142
187
|
/** 'c': copy workflow.json (litegraph, drag into the ComfyUI editor) */
|
|
143
188
|
async copyWorkflowJson(): Promise<void> {
|
|
189
|
+
if (this.copying) return
|
|
190
|
+
runInAction(() => {
|
|
191
|
+
this.copying = true
|
|
192
|
+
// instant feedback: the i2i upload inside build can hang for a tcp timeout
|
|
193
|
+
this.notice = 'building for copy… (i2i workflows upload their input image first)'
|
|
194
|
+
})
|
|
144
195
|
try {
|
|
145
|
-
const wf = await this.st.wf.build()
|
|
196
|
+
const wf = await this.st.wf.build({ host: this.st.hostOverride ?? undefined })
|
|
146
197
|
const json = await wf.toWorkflowJson()
|
|
147
|
-
const
|
|
198
|
+
const text = JSON.stringify(json, null, 2)
|
|
199
|
+
const ok = await this.toClipboard(text)
|
|
148
200
|
runInAction(() => {
|
|
149
|
-
this.
|
|
201
|
+
this.showCopyPopup(
|
|
202
|
+
'workflow.json → clipboard',
|
|
203
|
+
ok,
|
|
204
|
+
ok
|
|
205
|
+
? [
|
|
206
|
+
`${json.nodes.length} nodes · ${text.length} chars — paste into the ComfyUI editor`,
|
|
207
|
+
'',
|
|
208
|
+
...jsonHead(text, 10),
|
|
209
|
+
]
|
|
210
|
+
: ['CLIPBOARD COPY FAILED — is a clipboard tool available (pbcopy/clip/xclip) ?'],
|
|
211
|
+
)
|
|
150
212
|
})
|
|
151
213
|
} catch (e) {
|
|
152
214
|
runInAction(() => {
|
|
153
|
-
this.
|
|
215
|
+
this.showCopyPopup('workflow.json copy FAILED', false, [
|
|
216
|
+
extractErrorMessage(e),
|
|
217
|
+
'',
|
|
218
|
+
'nothing was copied. i2i/i2v builds upload their input image first —',
|
|
219
|
+
'an unreachable host fails the build itself, not just the run.',
|
|
220
|
+
])
|
|
221
|
+
})
|
|
222
|
+
} finally {
|
|
223
|
+
runInAction(() => {
|
|
224
|
+
this.copying = false
|
|
154
225
|
})
|
|
155
226
|
}
|
|
156
227
|
}
|
|
157
228
|
|
|
158
229
|
/** 'C': copy api.json (the POST /prompt payload) */
|
|
159
230
|
async copyApiJson(): Promise<void> {
|
|
231
|
+
if (this.copying) return
|
|
232
|
+
runInAction(() => {
|
|
233
|
+
this.copying = true
|
|
234
|
+
this.notice = 'building for copy… (i2i workflows upload their input image first)'
|
|
235
|
+
})
|
|
160
236
|
try {
|
|
161
|
-
const wf = await this.st.wf.build()
|
|
237
|
+
const wf = await this.st.wf.build({ host: this.st.hostOverride ?? undefined })
|
|
162
238
|
const json = wf.toApiJson('use_stringified_numbers_only')
|
|
163
|
-
const
|
|
239
|
+
const text = JSON.stringify(json, null, 2)
|
|
240
|
+
const ok = await this.toClipboard(text)
|
|
164
241
|
runInAction(() => {
|
|
165
|
-
this.
|
|
242
|
+
this.showCopyPopup(
|
|
243
|
+
'api.json → clipboard',
|
|
244
|
+
ok,
|
|
245
|
+
ok
|
|
246
|
+
? [
|
|
247
|
+
`${Object.keys(json).length} nodes · ${text.length} chars — the POST /prompt payload`,
|
|
248
|
+
'',
|
|
249
|
+
...jsonHead(text, 10),
|
|
250
|
+
]
|
|
251
|
+
: ['CLIPBOARD COPY FAILED — is a clipboard tool available (pbcopy/clip/xclip) ?'],
|
|
252
|
+
)
|
|
166
253
|
})
|
|
167
254
|
} catch (e) {
|
|
168
255
|
runInAction(() => {
|
|
169
|
-
this.
|
|
256
|
+
this.showCopyPopup('api.json copy FAILED', false, [
|
|
257
|
+
extractErrorMessage(e),
|
|
258
|
+
'',
|
|
259
|
+
'nothing was copied. i2i/i2v builds upload their input image first —',
|
|
260
|
+
'an unreachable host fails the build itself, not just the run.',
|
|
261
|
+
])
|
|
262
|
+
})
|
|
263
|
+
} finally {
|
|
264
|
+
runInAction(() => {
|
|
265
|
+
this.copying = false
|
|
170
266
|
})
|
|
171
267
|
}
|
|
172
268
|
}
|
|
@@ -9,9 +9,29 @@ export type HostStatus = 'unknown' | 'up' | 'down'
|
|
|
9
9
|
|
|
10
10
|
const PROBE_EVERY_MS = 5000
|
|
11
11
|
const PROBE_TIMEOUT_MS = 3000
|
|
12
|
+
/** ws message younger than this = the host is alive, whatever http says */
|
|
13
|
+
export const WS_ALIVE_MS = 10_000
|
|
12
14
|
|
|
13
15
|
const SPIN_FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
|
|
14
16
|
|
|
17
|
+
/**
|
|
18
|
+
* PURE probe verdict (headless-tested). http ok is proof enough; on http
|
|
19
|
+
* failure a RECENTLY TALKING open ws still means up — ComfyUI is
|
|
20
|
+
* single-threaded and stalls new connects mid-generation while established
|
|
21
|
+
* sockets stream (his repro 2026-07-30: 'windows-1 offline' in the header
|
|
22
|
+
* while the browser tab generated fine). A half-open socket receives
|
|
23
|
+
* nothing, so the recency window never revives one.
|
|
24
|
+
*/
|
|
25
|
+
export function probeVerdict(p: { httpOk: boolean; wsOpen: boolean; lastWsMessageAt: number | null; now: number }): {
|
|
26
|
+
status: HostStatus
|
|
27
|
+
via: 'ws' | 'http' | null
|
|
28
|
+
} {
|
|
29
|
+
if (p.httpOk) return { status: 'up', via: p.wsOpen ? 'ws' : 'http' }
|
|
30
|
+
if (p.wsOpen && p.lastWsMessageAt != null && p.now - p.lastWsMessageAt < WS_ALIVE_MS)
|
|
31
|
+
return { status: 'up', via: 'ws' }
|
|
32
|
+
return { status: 'down', via: null }
|
|
33
|
+
}
|
|
34
|
+
|
|
15
35
|
/** host panel (`h`): stats about the connected host + maintenance actions */
|
|
16
36
|
export class HostSt {
|
|
17
37
|
constructor(private st: TuiSt) {
|
|
@@ -23,16 +43,18 @@ export class HostSt {
|
|
|
23
43
|
if (this.spinTimer != null) clearInterval(this.spinTimer)
|
|
24
44
|
if (this.countdownTimer != null) clearInterval(this.countdownTimer)
|
|
25
45
|
})
|
|
26
|
-
// switching workflows can switch hosts: back to
|
|
27
|
-
// probeGen++ kills a chain that is mid-await (its
|
|
28
|
-
// clearing timers alone would leave it alive →
|
|
46
|
+
// switching workflows (or the `h` override) can switch hosts: back to
|
|
47
|
+
// unknown, re-probe now. probeGen++ kills a chain that is mid-await (its
|
|
48
|
+
// loopTimer isn't set yet, clearing timers alone would leave it alive →
|
|
49
|
+
// duplicate chains forever)
|
|
29
50
|
this.st.disposers.push(
|
|
30
51
|
reaction(
|
|
31
|
-
() => this.st.
|
|
52
|
+
() => this.st.runHost,
|
|
32
53
|
() => {
|
|
33
54
|
runInAction(() => {
|
|
34
55
|
this.status = 'unknown'
|
|
35
56
|
this.statusVia = null
|
|
57
|
+
this.lastProbeError = null // the previous host's failure must not show under the new one
|
|
36
58
|
})
|
|
37
59
|
this.probeGen++
|
|
38
60
|
if (this.loopTimer != null) clearTimeout(this.loopTimer)
|
|
@@ -47,6 +69,8 @@ export class HostSt {
|
|
|
47
69
|
status: HostStatus = 'unknown'
|
|
48
70
|
/** 'ws' when the live socket is open, 'http' when only the probe reaches the host */
|
|
49
71
|
statusVia: 'ws' | 'http' | null = null
|
|
72
|
+
/** why the last http probe failed (timeout, dns, http status) — the stats panel shows it */
|
|
73
|
+
lastProbeError: string | null = null
|
|
50
74
|
/** a probe is in flight (drives the spinner while down) */
|
|
51
75
|
probing: boolean = false
|
|
52
76
|
/** seconds until the next probe (shown while down) */
|
|
@@ -86,8 +110,9 @@ export class HostSt {
|
|
|
86
110
|
this.loopTimer.unref?.()
|
|
87
111
|
}
|
|
88
112
|
|
|
89
|
-
/** http
|
|
90
|
-
*
|
|
113
|
+
/** http first — a half-open ws keeps isOpen=true forever, so isOpen alone
|
|
114
|
+
* is never trusted. RECENT MESSAGES are: probeVerdict lets a talking ws
|
|
115
|
+
* beat a stalled http probe (busy single-threaded server) */
|
|
91
116
|
private async probe(): Promise<void> {
|
|
92
117
|
const host = this.host
|
|
93
118
|
runInAction(() => {
|
|
@@ -103,13 +128,16 @@ export class HostSt {
|
|
|
103
128
|
spin.unref?.()
|
|
104
129
|
this.spinTimer = spin
|
|
105
130
|
let ok = false
|
|
131
|
+
let probeError: string | null = null
|
|
106
132
|
try {
|
|
107
133
|
// host.fetch: /api preferred + auth header, so cloud hosts probe up too
|
|
108
134
|
const res = await host.fetch('/prompt', { signal: AbortSignal.timeout(PROBE_TIMEOUT_MS) })
|
|
109
135
|
void res.body?.cancel()
|
|
110
136
|
ok = res.ok
|
|
111
|
-
|
|
137
|
+
if (!ok) probeError = `http ${res.status}`
|
|
138
|
+
} catch (e) {
|
|
112
139
|
ok = false
|
|
140
|
+
probeError = extractErrorMessage(e)
|
|
113
141
|
} finally {
|
|
114
142
|
clearInterval(spin)
|
|
115
143
|
if (this.spinTimer === spin) {
|
|
@@ -120,9 +148,16 @@ export class HostSt {
|
|
|
120
148
|
}
|
|
121
149
|
}
|
|
122
150
|
if (this.host !== host) return // workflow switched mid-flight: stale verdict
|
|
151
|
+
const verdict = probeVerdict({
|
|
152
|
+
httpOk: ok,
|
|
153
|
+
wsOpen: host.isConnected,
|
|
154
|
+
lastWsMessageAt: host.lastWsMessageAt,
|
|
155
|
+
now: Date.now(),
|
|
156
|
+
})
|
|
123
157
|
runInAction(() => {
|
|
124
|
-
this.status =
|
|
125
|
-
this.statusVia =
|
|
158
|
+
this.status = verdict.status
|
|
159
|
+
this.statusVia = verdict.via
|
|
160
|
+
this.lastProbeError = probeError
|
|
126
161
|
})
|
|
127
162
|
}
|
|
128
163
|
|
|
@@ -138,7 +173,7 @@ export class HostSt {
|
|
|
138
173
|
]
|
|
139
174
|
|
|
140
175
|
get host(): ComfyHost {
|
|
141
|
-
return this.st.
|
|
176
|
+
return this.st.runHost
|
|
142
177
|
}
|
|
143
178
|
|
|
144
179
|
get stats(): { label: string; value: string }[] {
|
|
@@ -151,6 +186,8 @@ export class HostSt {
|
|
|
151
186
|
? `down · ${this.probing ? `${this.spinner} probing…` : `retry in ${this.retryInS}s`}`
|
|
152
187
|
: this.status + (this.statusVia != null ? ` (${this.statusVia})` : ''),
|
|
153
188
|
},
|
|
189
|
+
// the WHY behind a down dot (or an up-via-ws with http stalling: busy server)
|
|
190
|
+
...(this.lastProbeError != null ? [{ label: 'http probe', value: this.lastProbeError }] : []),
|
|
154
191
|
{ label: 'node types', value: String(schema.nodes.length) },
|
|
155
192
|
{ label: 'loras', value: String(schema.getLoras().length) },
|
|
156
193
|
{ label: 'embeddings', value: String(schema.data.embeddings.length) },
|
|
@@ -168,6 +205,53 @@ export class HostSt {
|
|
|
168
205
|
this.st.mode = 'nav'
|
|
169
206
|
}
|
|
170
207
|
|
|
208
|
+
// ---- `h` host picker: override the host the current workflow runs against ----
|
|
209
|
+
|
|
210
|
+
pickerIx: number = 0
|
|
211
|
+
|
|
212
|
+
get pickerRows(): { host: ComfyHost | null; label: string; active: boolean }[] {
|
|
213
|
+
const wfHost = this.st.wf.host
|
|
214
|
+
const rows: { host: ComfyHost | null; label: string; active: boolean }[] = [
|
|
215
|
+
{ host: null, label: `workflow default (${wfHost.data.id})`, active: this.st.hostOverride == null },
|
|
216
|
+
]
|
|
217
|
+
// the global registry: every host any imported module registered so far
|
|
218
|
+
for (const host of comfyts.hosts.values()) {
|
|
219
|
+
rows.push({
|
|
220
|
+
host,
|
|
221
|
+
label: `${host.data.id} (${host.base.host}:${host.base.port})`,
|
|
222
|
+
active: this.st.hostOverride === host,
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
return rows
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
beginPicker(): void {
|
|
229
|
+
this.st.mode = 'overlay-hosts'
|
|
230
|
+
const active = this.pickerRows.findIndex((r) => r.active)
|
|
231
|
+
this.pickerIx = active === -1 ? 0 : active
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
cancelPicker(): void {
|
|
235
|
+
this.st.mode = 'nav'
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
pickerMove(delta: number): void {
|
|
239
|
+
const len = this.pickerRows.length
|
|
240
|
+
if (len === 0) return
|
|
241
|
+
this.pickerIx = (this.pickerIx + delta + len) % len
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
commitPicker(): void {
|
|
245
|
+
const row = this.pickerRows[this.pickerIx]
|
|
246
|
+
if (row == null) return
|
|
247
|
+
this.st.setHostOverride(row.host)
|
|
248
|
+
this.st.mode = 'nav'
|
|
249
|
+
this.st.exec.notice =
|
|
250
|
+
row.host == null
|
|
251
|
+
? `host override cleared — runs target the workflow's own host (${this.st.wf.host.data.id})`
|
|
252
|
+
: `runs now target ${row.host.data.id} (overrides ${this.st.wf.host.data.id})`
|
|
253
|
+
}
|
|
254
|
+
|
|
171
255
|
move(delta: number): void {
|
|
172
256
|
const len = this.actions.length
|
|
173
257
|
this.ix = (this.ix + delta + len) % len
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { makeAutoObservable, reaction
|
|
1
|
+
import { makeAutoObservable, reaction } from 'mobx'
|
|
2
2
|
import { fetchLoraPreviewBytes, fetchLoraPreviewMap, loraPreviewKey } from 'src/host/loraManagerApi.ts'
|
|
3
3
|
import { imageBufferToAnsi } from 'src/utils/ansiImage.ts'
|
|
4
4
|
import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
|
|
@@ -43,6 +43,8 @@ export class LorasSt {
|
|
|
43
43
|
this.st.mode = 'overlay-loras'
|
|
44
44
|
this.ix = 0
|
|
45
45
|
this.filter = ''
|
|
46
|
+
// fresh overlay starts on the placeholder, never a stale slot image
|
|
47
|
+
this.st.preview.clearOverlayImage()
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
move(delta: number): void {
|
|
@@ -106,26 +108,16 @@ export class LorasSt {
|
|
|
106
108
|
return this.filteredNames[this.ix] ?? null
|
|
107
109
|
}
|
|
108
110
|
|
|
109
|
-
previewAnsi: string | null = null
|
|
110
|
-
/** protocol mode: raw preview bytes for the overlay painter */
|
|
111
|
-
previewBytes: Uint8Array | null = null
|
|
112
|
-
previewName: string | null = null
|
|
113
|
-
/** placeholder line when no image can be shown (missing extension, no preview, video preview…) */
|
|
114
|
-
previewNote: string | null = null
|
|
115
|
-
|
|
116
111
|
/** undefined = not fetched yet · null = extension absent */
|
|
117
112
|
private previewMap: Map<string, string> | null | undefined = undefined
|
|
118
113
|
private previewMapHostId: string | null = null
|
|
119
114
|
private _busy: boolean = false
|
|
120
115
|
|
|
116
|
+
/** preview goes through PreviewSt's shared overlay slot (one code path with the image picker) */
|
|
121
117
|
async refreshPreview(): Promise<void> {
|
|
122
118
|
if (this.st.mode !== 'overlay-loras') {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
this.previewBytes = null
|
|
126
|
-
this.previewName = null
|
|
127
|
-
this.previewNote = null
|
|
128
|
-
})
|
|
119
|
+
// debounced close: another overlay may ALREADY own the slot — never wipe its image
|
|
120
|
+
if (!this.st.preview.overlayActive) this.st.preview.clearOverlayImage()
|
|
129
121
|
return
|
|
130
122
|
}
|
|
131
123
|
const name = this.selectedName
|
|
@@ -141,12 +133,7 @@ export class LorasSt {
|
|
|
141
133
|
const url = map?.get(loraPreviewKey(name))
|
|
142
134
|
const note = map == null ? 'lora-manager extension not detected' : url == null ? 'no preview available' : null
|
|
143
135
|
if (url == null) {
|
|
144
|
-
|
|
145
|
-
this.previewAnsi = null
|
|
146
|
-
this.previewBytes = null
|
|
147
|
-
this.previewName = name
|
|
148
|
-
this.previewNote = note
|
|
149
|
-
})
|
|
136
|
+
this.st.preview.setOverlayImage({ bytes: null, ansi: null, name: `lora ${name}`, note })
|
|
150
137
|
return
|
|
151
138
|
}
|
|
152
139
|
const bytes = await fetchLoraPreviewBytes(host, url)
|
|
@@ -154,27 +141,18 @@ export class LorasSt {
|
|
|
154
141
|
if (bytes == null) throw new Error('no image preview on the server')
|
|
155
142
|
if (this.st.preview.useNative) {
|
|
156
143
|
// the overlay painter shows the REAL image — no ansi rendering needed
|
|
157
|
-
|
|
158
|
-
this.previewBytes = bytes
|
|
159
|
-
this.previewAnsi = null
|
|
160
|
-
this.previewName = name
|
|
161
|
-
this.previewNote = null
|
|
162
|
-
})
|
|
144
|
+
this.st.preview.setOverlayImage({ bytes, ansi: null, name: `lora ${name}`, note: null })
|
|
163
145
|
return
|
|
164
146
|
}
|
|
165
147
|
const ansi = await imageBufferToAnsi(bytes, { width: this.st.preview.width, height: this.st.preview.height })
|
|
166
|
-
|
|
167
|
-
this.previewAnsi = ansi
|
|
168
|
-
this.previewName = name
|
|
169
|
-
this.previewNote = null
|
|
170
|
-
})
|
|
148
|
+
this.st.preview.setOverlayImage({ bytes: null, ansi, name: `lora ${name}`, note: null })
|
|
171
149
|
} catch (e) {
|
|
172
150
|
// e.g. video previews sharp can't decode — placeholder, not an incident
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
151
|
+
this.st.preview.setOverlayImage({
|
|
152
|
+
bytes: null,
|
|
153
|
+
ansi: null,
|
|
154
|
+
name: `lora ${name}`,
|
|
155
|
+
note: extractErrorMessage(e),
|
|
178
156
|
})
|
|
179
157
|
} finally {
|
|
180
158
|
this._busy = false
|