comfy-ts 0.2.0 → 0.3.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/LICENSE +21 -0
- package/README.md +363 -0
- package/dist/cli.js +764 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +4128 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9862 -0
- package/dist/index.d.ts +9846 -58
- package/dist/index.js +4049 -2
- package/dist/index.js.map +1 -1
- package/dist/log-CdfgILde.js +10 -0
- package/dist/log-CdfgILde.js.map +1 -0
- package/dist/run-tui-Io8Xea0L.js +3340 -0
- package/dist/run-tui-Io8Xea0L.js.map +1 -0
- package/package.json +104 -75
- package/src/cli/comfy-ts-cli.ts +36 -0
- package/src/cli/gen.ts +47 -0
- package/src/cli/outline.ts +82 -0
- package/src/cli/tui/components/DraftsOverlay.tsx +44 -0
- package/src/cli/tui/components/EditField.tsx +27 -0
- package/src/cli/tui/components/Header.tsx +51 -0
- package/src/cli/tui/components/HostPanel.tsx +37 -0
- package/src/cli/tui/components/LorasOverlay.tsx +49 -0
- package/src/cli/tui/components/OverlayList.tsx +25 -0
- package/src/cli/tui/components/PickerOverlays.tsx +66 -0
- package/src/cli/tui/components/PreviewPanel.tsx +33 -0
- package/src/cli/tui/components/PromptOverlay.tsx +16 -0
- package/src/cli/tui/components/StatusBar.tsx +165 -0
- package/src/cli/tui/components/TextOverlay.tsx +72 -0
- package/src/cli/tui/components/TreePanel.tsx +51 -0
- package/src/cli/tui/components/TuiApp.tsx +223 -0
- package/src/cli/tui/components/VarsPanel.tsx +86 -0
- package/src/cli/tui/findDefinedWorkflow.ts +16 -0
- package/src/cli/tui/keys.ts +20 -0
- package/src/cli/tui/protocolImagePainter.ts +59 -0
- package/src/cli/tui/run-tui.tsx +73 -0
- package/src/cli/tui/state/DraftsSt.ts +273 -0
- package/src/cli/tui/state/EditorSt.ts +289 -0
- package/src/cli/tui/state/ExecSt.ts +170 -0
- package/src/cli/tui/state/HostSt.ts +107 -0
- package/src/cli/tui/state/LorasSt.ts +185 -0
- package/src/cli/tui/state/PickerSt.ts +112 -0
- package/src/cli/tui/state/PreviewSt.ts +138 -0
- package/src/cli/tui/state/QueueSt.ts +59 -0
- package/src/cli/tui/state/SettingsSt.ts +73 -0
- package/src/cli/tui/state/TreeSt.ts +122 -0
- package/src/cli/tui/state/TuiSt.ts +169 -0
- package/src/cli/tui/state/WorkflowsSt.ts +92 -0
- package/src/cli/tui-env.ts +8 -0
- package/src/errors/InvalidPromptError.ts +12 -0
- package/src/graph/ComfyNode.ts +403 -0
- package/src/graph/ComfyNodeID.ts +28 -0
- package/src/graph/ComfyNodeOutput.ts +16 -0
- package/src/graph/NodeSlotSize.ts +4 -0
- package/src/graph/autoValue.ts +17 -0
- package/src/host/ComfyHost.ts +646 -0
- package/src/host/ComfyInstallType.ts +15 -0
- package/src/host/ComfyManager.ts +232 -0
- package/src/host/ComfyUploader.ts +110 -0
- package/src/host/ComfyWorkflowBuilder.ts +60 -0
- package/src/host/Requirements.ts +55 -0
- package/src/host/ResilientWebsocket.ts +147 -0
- package/src/host/loraManagerApi.ts +98 -0
- package/src/image-utils/_getPngMetadata.ts +53 -0
- package/src/image-utils/_getWebpMetadata.ts +38 -0
- package/src/image-utils/_parseExifData.ts +53 -0
- package/src/index.ts +89 -0
- package/src/litegraph/LiteGraphGroup.ts +22 -0
- package/src/litegraph/LiteGraphJSON.ts +46 -0
- package/src/litegraph/LiteGraphLink.ts +23 -0
- package/src/litegraph/LiteGraphLinkID.ts +6 -0
- package/src/litegraph/LiteGraphNode.ts +69 -0
- package/src/litegraph/LiteGraphNodeInput.ts +27 -0
- package/src/litegraph/LiteGraphNodeOutput.ts +23 -0
- package/src/litegraph/LiteGraphSlotIndex.ts +6 -0
- package/src/litegraph/convertFlowToLiteGraphJSON.ts +114 -0
- package/src/manager/ComfyRegistry.ts +124 -0
- package/src/manager/generated/KnownComfyCustomNodeName.ts +19280 -0
- package/src/manager/generated/KnownComfyPluginTitle.ts +5130 -0
- package/src/manager/generated/KnownComfyPluginURL.ts +2589 -0
- package/src/manager/generated/KnownModel_Base.ts +126 -0
- package/src/manager/generated/KnownModel_FileName.ts +2287 -0
- package/src/manager/generated/KnownModel_Name.ts +2287 -0
- package/src/manager/generated/KnownModel_SavePath.ts +263 -0
- package/src/manager/generated/KnownModel_Type.ts +97 -0
- package/src/manager/json/alter-list.json +224 -0
- package/src/manager/json/custom-node-list.extra.ts +13 -0
- package/src/manager/json/custom-node-list.json +21948 -0
- package/src/manager/json/extension-node-map.json +31282 -0
- package/src/manager/json/github-stats.json +12602 -0
- package/src/manager/json/model-list.extra.ts +26 -0
- package/src/manager/json/model-list.json +5052 -0
- package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +56 -0
- package/src/manager/loaders/step2_custom-node-list-loader.ts +149 -0
- package/src/manager/loaders/step3_extension-node-map-loader.ts +189 -0
- package/src/manager/loaders/step4_model-list-loader.ts +159 -0
- package/src/manager/script-update-manager.bun.ts +18 -0
- package/src/manager/types/ComfyManagerAPIFetchPolicy.ts +9 -0
- package/src/manager/types/ComfyManagerAPIModelList.ts +10 -0
- package/src/manager/types/ComfyManagerAPIPluginList.ts +11 -0
- package/src/manager/types/ComfyManagerFileModelInfo.ts +5 -0
- package/src/manager/types/ComfyManagerFilePluginContent.ts +13 -0
- package/src/manager/types/ComfyManagerFilePluginList.ts +5 -0
- package/src/manager/types/ComfyManagerModelInfo.ts +18 -0
- package/src/manager/types/ComfyManagerPluginContentMetadata.ts +16 -0
- package/src/manager/types/ComfyManagerPluginEnums.ts +8 -0
- package/src/manager/types/ComfyManagerPluginInfo.ts +50 -0
- package/src/runner/ComfyExecution.ts +301 -0
- package/src/runner/ComfyExecutionStatus.ts +2 -0
- package/src/runner/ComfyWorkflow.ts +395 -0
- package/src/runner/ComfyWorkflowLayout.ts +96 -0
- package/src/runner/ComfyWsApi.ts +159 -0
- package/src/runner/MediaImage.ts +262 -0
- package/src/sdk-generator/ComfyNodeSchema.ts +79 -0
- package/src/sdk-generator/ComfySchema.ts +369 -0
- package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +95 -0
- package/src/sdk-generator/Primitives.ts +76 -0
- package/src/sdk-generator/_getUnionNameBasedOnFirstFoundEnumName.ts +39 -0
- package/src/sdk-generator/_pythonModuleToNamespace.ts +27 -0
- package/src/sdk-generator/_toQualifiedNodeKey.ts +5 -0
- package/src/sdk-generator/comfy-api-json.ts +16 -0
- package/src/sdk-generator/comfyui-sdk-codegen.ts +287 -0
- package/src/sdk-generator/comfyui-types.ts +56 -0
- package/src/sdk-generator/litegraphToApiRequestPayload.ts +157 -0
- package/src/ssh-host-manager/ssh-config-manager.ts +89 -0
- package/src/ssh-host-manager/ssh-config.windows.md +32 -0
- package/src/ssh-host-manager/ssh-manager.ts +129 -0
- package/src/state.ts +136 -0
- package/src/types/comfy-sdk.ts +106 -0
- package/src/types/index.ts +55 -0
- package/src/utils/CodeBuffer.ts +61 -0
- package/src/utils/ComfyColors.ts +38 -0
- package/src/utils/ansi.ts +26 -0
- package/src/utils/ansiImage.ts +36 -0
- package/src/utils/bang.ts +39 -0
- package/src/utils/deepCopyNaive.ts +1 -0
- package/src/utils/downloadFile.ts +77 -0
- package/src/utils/escapeJSKey.ts +32 -0
- package/src/utils/exhaust.ts +4 -0
- package/src/utils/extractErrorMessage.ts +11 -0
- package/src/utils/fuzzyMatch.ts +8 -0
- package/src/utils/githubRegexes.ts +2 -0
- package/src/utils/hashArrayBuffer.ts +6 -0
- package/src/utils/log.ts +9 -0
- package/src/utils/loraTag.ts +10 -0
- package/src/utils/printArkResultInConsole.ts +16 -0
- package/src/utils/softValidate.ts +8 -0
- package/src/utils/stringifyReadable.ts +32 -0
- package/src/utils/toposort.ts +59 -0
- package/src/utils/tryExtracting.ts +41 -0
- package/src/utils/writeFile.ts +16 -0
- package/src/vars/ComfyVars.ts +531 -0
- package/src/vars/DefinedWorkflow.ts +112 -0
- package/src/vars/loraKeywords.ts +56 -0
- package/dist/index.d.mts +0 -74
- package/dist/index.mjs +0 -3
- package/dist/index.mjs.map +0 -1
- package/readme.md +0 -40
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { makeAutoObservable } from 'mobx'
|
|
2
|
+
import type { TuiMode, TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* line/multiline editor. Inline mode ('edit') escapes newlines into a single
|
|
6
|
+
* line (numbers only, in practice); multiline mode ('overlay-text') keeps REAL
|
|
7
|
+
* newlines. All ops are code-point based so emoji/astral input never splits a
|
|
8
|
+
* surrogate pair (flag/ZWJ clusters may still count as several points).
|
|
9
|
+
*/
|
|
10
|
+
export class EditorSt {
|
|
11
|
+
constructor(private st: TuiSt) {
|
|
12
|
+
makeAutoObservable<EditorSt, 'st'>(this, { st: false })
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
buffer: string = ''
|
|
16
|
+
/** caret position, counted in CODE POINTS (0..pointLen) */
|
|
17
|
+
cursor: number = 0
|
|
18
|
+
invalid: boolean = false
|
|
19
|
+
|
|
20
|
+
/** raw value -> escaped single-line buffer form (order matters: backslashes first) */
|
|
21
|
+
static escapeForBuffer(raw: string): string {
|
|
22
|
+
return raw.replaceAll('\\', '\\\\').replaceAll('\r\n', '\n').replaceAll('\r', '\n').replaceAll('\n', '\\n')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** escaped buffer form -> raw value */
|
|
26
|
+
static unescapeBuffer(buffer: string): string {
|
|
27
|
+
return buffer.replace(/\\\\|\\n/g, (m) => (m === '\\\\' ? '\\' : '\n'))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** non-var session (draft naming etc.): commit goes to the callback, not the selected var */
|
|
31
|
+
customCommit: ((raw: string) => boolean) | null = null
|
|
32
|
+
customTitle: string = ''
|
|
33
|
+
private returnMode: TuiMode = 'nav'
|
|
34
|
+
|
|
35
|
+
get isCustom(): boolean {
|
|
36
|
+
return this.customCommit != null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** inline single-line editor (numbers, seed `mode value`) */
|
|
40
|
+
beginInline(): void {
|
|
41
|
+
const sel = this.st.selected?.[1]
|
|
42
|
+
if (sel == null) return
|
|
43
|
+
this.st.mode = 'edit'
|
|
44
|
+
this.buffer = EditorSt.escapeForBuffer(sel.toEditBuffer())
|
|
45
|
+
this.cursor = [...this.buffer].length
|
|
46
|
+
this.invalid = false
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** modal prompt over an arbitrary string (rendered as PromptOverlay);
|
|
50
|
+
* onCommit returns false to keep editing (invalid); esc/apply lands on returnMode */
|
|
51
|
+
beginCustom(p: { title: string; initial: string; onCommit: (raw: string) => boolean; returnMode?: TuiMode }): void {
|
|
52
|
+
this.st.mode = 'edit'
|
|
53
|
+
this.customCommit = p.onCommit
|
|
54
|
+
this.customTitle = p.title
|
|
55
|
+
this.returnMode = p.returnMode ?? 'nav'
|
|
56
|
+
this.buffer = EditorSt.escapeForBuffer(p.initial)
|
|
57
|
+
this.cursor = [...this.buffer].length
|
|
58
|
+
this.invalid = false
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** modal multiline editor (text vars), no escaping */
|
|
62
|
+
beginMultiline(): void {
|
|
63
|
+
const sel = this.st.selected?.[1]
|
|
64
|
+
if (sel == null) return
|
|
65
|
+
this.st.mode = 'overlay-text'
|
|
66
|
+
this.buffer = String(sel.value)
|
|
67
|
+
this.cursor = [...this.buffer].length
|
|
68
|
+
this.invalid = false
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
commitInline(): void {
|
|
72
|
+
if (this.customCommit != null) {
|
|
73
|
+
if (this.customCommit(EditorSt.unescapeBuffer(this.buffer))) {
|
|
74
|
+
this.customCommit = null
|
|
75
|
+
this.st.mode = this.returnMode
|
|
76
|
+
} else this.invalid = true
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
const sel = this.st.selected?.[1]
|
|
80
|
+
if (sel == null) return
|
|
81
|
+
if (sel.parse(EditorSt.unescapeBuffer(this.buffer))) this.st.mode = 'nav'
|
|
82
|
+
else this.invalid = true
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
commitMultiline(): void {
|
|
86
|
+
const sel = this.st.selected?.[1]
|
|
87
|
+
if (sel == null) return
|
|
88
|
+
if (sel.parse(this.buffer)) this.st.mode = 'nav'
|
|
89
|
+
else this.invalid = true
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
cancel(): void {
|
|
93
|
+
this.st.mode = this.customCommit != null ? this.returnMode : 'nav'
|
|
94
|
+
this.invalid = false
|
|
95
|
+
this.customCommit = null
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ---- readline-style ops (code-point based) ----
|
|
99
|
+
private get chars(): string[] {
|
|
100
|
+
return [...this.buffer]
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private setChars(cs: string[], cursor: number): void {
|
|
104
|
+
this.buffer = cs.join('')
|
|
105
|
+
this.cursor = Math.max(0, Math.min(cursor, cs.length))
|
|
106
|
+
this.invalid = false
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
input(chunk: string): void {
|
|
110
|
+
// multiline keeps real newlines; inline escapes to a single line
|
|
111
|
+
const normalized =
|
|
112
|
+
this.st.mode === 'overlay-text'
|
|
113
|
+
? chunk.replaceAll('\r\n', '\n').replaceAll('\r', '\n')
|
|
114
|
+
: EditorSt.escapeForBuffer(chunk)
|
|
115
|
+
const insert = [...normalized]
|
|
116
|
+
const cs = this.chars
|
|
117
|
+
cs.splice(this.cursor, 0, ...insert)
|
|
118
|
+
this.setChars(cs, this.cursor + insert.length)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
backspace(): void {
|
|
122
|
+
if (this.cursor === 0) return
|
|
123
|
+
const cs = this.chars
|
|
124
|
+
cs.splice(this.cursor - 1, 1)
|
|
125
|
+
this.setChars(cs, this.cursor - 1)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
newline(): void {
|
|
129
|
+
const cs = this.chars
|
|
130
|
+
cs.splice(this.cursor, 0, '\n')
|
|
131
|
+
this.setChars(cs, this.cursor + 1)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** index of the start of the word left of the cursor */
|
|
135
|
+
private wordBoundLeft(): number {
|
|
136
|
+
const cs = this.chars
|
|
137
|
+
let i = this.cursor
|
|
138
|
+
while (i > 0 && /\s/.test(cs[i - 1] ?? '')) i--
|
|
139
|
+
while (i > 0 && !/\s/.test(cs[i - 1] ?? '')) i--
|
|
140
|
+
return i
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** index just past the word right of the cursor */
|
|
144
|
+
private wordBoundRight(): number {
|
|
145
|
+
const cs = this.chars
|
|
146
|
+
let i = this.cursor
|
|
147
|
+
while (i < cs.length && /\s/.test(cs[i] ?? '')) i++
|
|
148
|
+
while (i < cs.length && !/\s/.test(cs[i] ?? '')) i++
|
|
149
|
+
return i
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** alt+backspace / ctrl+w */
|
|
153
|
+
deleteWordBack(): void {
|
|
154
|
+
const from = this.wordBoundLeft()
|
|
155
|
+
const cs = this.chars
|
|
156
|
+
cs.splice(from, this.cursor - from)
|
|
157
|
+
this.setChars(cs, from)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** ctrl+u: clear from start to cursor */
|
|
161
|
+
killToStart(): void {
|
|
162
|
+
this.setChars(this.chars.slice(this.cursor), 0)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** ctrl+k: clear from cursor to end */
|
|
166
|
+
killToEnd(): void {
|
|
167
|
+
this.setChars(this.chars.slice(0, this.cursor), this.cursor)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
cursorLeft(): void {
|
|
171
|
+
if (this.cursor > 0) this.cursor--
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
cursorRight(): void {
|
|
175
|
+
if (this.cursor < this.chars.length) this.cursor++
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** alt+left / esc-b */
|
|
179
|
+
wordLeft(): void {
|
|
180
|
+
this.cursor = this.wordBoundLeft()
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** alt+right / esc-f */
|
|
184
|
+
wordRight(): void {
|
|
185
|
+
this.cursor = this.wordBoundRight()
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** start index (in code points) of the line containing ix */
|
|
189
|
+
private lineStartAt(ix: number): number {
|
|
190
|
+
const cs = this.chars
|
|
191
|
+
let i = ix
|
|
192
|
+
while (i > 0 && cs[i - 1] !== '\n') i--
|
|
193
|
+
return i
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** end index (exclusive, before the \n) of the line containing ix */
|
|
197
|
+
private lineEndAt(ix: number): number {
|
|
198
|
+
const cs = this.chars
|
|
199
|
+
let i = ix
|
|
200
|
+
while (i < cs.length && cs[i] !== '\n') i++
|
|
201
|
+
return i
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Home / ⌘← / ⌃A: start of the LOGICAL line; already there → the previous line's start */
|
|
205
|
+
lineHome(): void {
|
|
206
|
+
const start = this.lineStartAt(this.cursor)
|
|
207
|
+
if (this.cursor !== start || start === 0) return void (this.cursor = start)
|
|
208
|
+
this.cursor = this.lineStartAt(start - 1)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** End / ⌘→ / ⌃E: end of the LOGICAL line; already there → the next line's end */
|
|
212
|
+
lineEnd(): void {
|
|
213
|
+
const end = this.lineEndAt(this.cursor)
|
|
214
|
+
if (this.cursor !== end || end === this.chars.length) return void (this.cursor = end)
|
|
215
|
+
this.cursor = this.lineEndAt(end + 1)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** ⌥↑/⌥↓: swap the cursor's logical line with its neighbor, cursor rides along */
|
|
219
|
+
moveLine(delta: -1 | 1): void {
|
|
220
|
+
const cs = this.chars
|
|
221
|
+
const start = this.lineStartAt(this.cursor)
|
|
222
|
+
const end = this.lineEndAt(this.cursor)
|
|
223
|
+
const col = this.cursor - start
|
|
224
|
+
const cur = cs.slice(start, end)
|
|
225
|
+
if (delta === -1) {
|
|
226
|
+
if (start === 0) return
|
|
227
|
+
const prevStart = this.lineStartAt(start - 1)
|
|
228
|
+
const prev = cs.slice(prevStart, start - 1)
|
|
229
|
+
this.setChars(
|
|
230
|
+
[...cs.slice(0, prevStart), ...cur, '\n', ...prev, ...cs.slice(end)],
|
|
231
|
+
prevStart + Math.min(col, cur.length),
|
|
232
|
+
)
|
|
233
|
+
} else {
|
|
234
|
+
if (end === cs.length) return
|
|
235
|
+
const nextEnd = this.lineEndAt(end + 1)
|
|
236
|
+
const next = cs.slice(end + 1, nextEnd)
|
|
237
|
+
this.setChars(
|
|
238
|
+
[...cs.slice(0, start), ...next, '\n', ...cur, ...cs.slice(nextEnd)],
|
|
239
|
+
start + next.length + 1 + Math.min(col, cur.length),
|
|
240
|
+
)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** ⌘/ / ⌃/ / ⌥/: toggle `// ` at the start of the cursor's line */
|
|
245
|
+
toggleComment(): void {
|
|
246
|
+
const cs = this.chars
|
|
247
|
+
const start = this.lineStartAt(this.cursor)
|
|
248
|
+
const end = this.lineEndAt(this.cursor)
|
|
249
|
+
const line = cs.slice(start, end).join('')
|
|
250
|
+
const m = /^(\s*)\/\/ ?/.exec(line)
|
|
251
|
+
if (m == null) {
|
|
252
|
+
cs.splice(start, 0, '/', '/', ' ')
|
|
253
|
+
this.setChars(cs, this.cursor + 3)
|
|
254
|
+
return
|
|
255
|
+
}
|
|
256
|
+
const indentLen = [...(m[1] ?? '')].length
|
|
257
|
+
const removeLen = [...m[0]].length - indentLen
|
|
258
|
+
cs.splice(start + indentLen, removeLen)
|
|
259
|
+
this.setChars(cs, Math.max(start, this.cursor - removeLen))
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
cursorUp(): void {
|
|
263
|
+
const start = this.lineStartAt(this.cursor)
|
|
264
|
+
if (start === 0) {
|
|
265
|
+
this.cursor = 0
|
|
266
|
+
return
|
|
267
|
+
}
|
|
268
|
+
const col = this.cursor - start
|
|
269
|
+
const prevStart = this.lineStartAt(start - 1)
|
|
270
|
+
const prevLen = start - 1 - prevStart
|
|
271
|
+
this.cursor = prevStart + Math.min(col, prevLen)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
cursorDown(): void {
|
|
275
|
+
const cs = this.chars
|
|
276
|
+
const start = this.lineStartAt(this.cursor)
|
|
277
|
+
const col = this.cursor - start
|
|
278
|
+
let end = this.cursor
|
|
279
|
+
while (end < cs.length && cs[end] !== '\n') end++
|
|
280
|
+
if (end === cs.length) {
|
|
281
|
+
this.cursor = cs.length
|
|
282
|
+
return
|
|
283
|
+
}
|
|
284
|
+
const nextStart = end + 1
|
|
285
|
+
let nextEnd = nextStart
|
|
286
|
+
while (nextEnd < cs.length && cs[nextEnd] !== '\n') nextEnd++
|
|
287
|
+
this.cursor = nextStart + Math.min(col, nextEnd - nextStart)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process'
|
|
2
|
+
import { makeAutoObservable, runInAction } from 'mobx'
|
|
3
|
+
import { basename } from 'pathe'
|
|
4
|
+
import type { ExecutionProgress } from 'src/runner/ComfyExecution.ts'
|
|
5
|
+
import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
|
|
6
|
+
import type { SeedVar } from 'src/vars/ComfyVars.ts'
|
|
7
|
+
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
8
|
+
|
|
9
|
+
/** run lifecycle + outputs + status line + clipboard/open actions */
|
|
10
|
+
export class ExecSt {
|
|
11
|
+
constructor(private st: TuiSt) {
|
|
12
|
+
makeAutoObservable<ExecSt, 'st'>(this, { st: false })
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** runs we launched that have not finished (the server executes them FIFO) */
|
|
16
|
+
inFlight: number = 0
|
|
17
|
+
progress: ExecutionProgress | null = null
|
|
18
|
+
outputs: string[] = []
|
|
19
|
+
runCount: number = 0
|
|
20
|
+
lastStatus: string | null = null
|
|
21
|
+
error: string | null = null
|
|
22
|
+
/** transient status line (copy feedback, draft changes, …) */
|
|
23
|
+
notice: string | null = null
|
|
24
|
+
/** the prompt currently executing on the server (progress belongs to it) */
|
|
25
|
+
private currentPromptId: string | null = null
|
|
26
|
+
|
|
27
|
+
get running(): boolean {
|
|
28
|
+
return this.inFlight > 0
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** workflow switch: wipe run artifacts, keep a hello notice */
|
|
32
|
+
resetForWorkflow(notice: string): void {
|
|
33
|
+
this.outputs = []
|
|
34
|
+
this.error = null
|
|
35
|
+
this.notice = notice
|
|
36
|
+
this.runCount = 0
|
|
37
|
+
this.lastStatus = null
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** every run takes THIS path, queued ones included: same progress, outputs, previews */
|
|
41
|
+
async run(): Promise<void> {
|
|
42
|
+
const queued = this.running
|
|
43
|
+
const host = this.st.wf.host
|
|
44
|
+
runInAction(() => {
|
|
45
|
+
this.inFlight++
|
|
46
|
+
this.error = null
|
|
47
|
+
if (queued) {
|
|
48
|
+
this.notice = `queued another run (server queue: ${this.st.queue.remaining + 1})`
|
|
49
|
+
} else {
|
|
50
|
+
this.progress = null
|
|
51
|
+
this.notice = null
|
|
52
|
+
this.currentPromptId = null
|
|
53
|
+
this.st.preview.reset()
|
|
54
|
+
// installed while ANY run is in flight, so queued prompts keep painting latents
|
|
55
|
+
host.onLatentPreview = (p) => void this.st.preview.renderLatent(p.bytes)
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
try {
|
|
59
|
+
const execution = await this.st.wf.run({
|
|
60
|
+
onProgress: (p) => runInAction(() => this.onProgress(p)),
|
|
61
|
+
})
|
|
62
|
+
runInAction(() => {
|
|
63
|
+
this.outputs = execution.images.map((i) => i.absPath)
|
|
64
|
+
this.lastStatus = execution.status
|
|
65
|
+
this.runCount++
|
|
66
|
+
})
|
|
67
|
+
const lastImage = execution.images[execution.images.length - 1]
|
|
68
|
+
if (lastImage) void this.st.preview.renderOutput(lastImage.absPath)
|
|
69
|
+
} catch (e) {
|
|
70
|
+
runInAction(() => {
|
|
71
|
+
this.error = extractErrorMessage(e)
|
|
72
|
+
})
|
|
73
|
+
} finally {
|
|
74
|
+
runInAction(() => {
|
|
75
|
+
this.inFlight--
|
|
76
|
+
// a queued run is next: blank the bar until its first progress message
|
|
77
|
+
this.progress = null
|
|
78
|
+
this.currentPromptId = null
|
|
79
|
+
this.st.preview.clearLatent()
|
|
80
|
+
if (this.inFlight === 0) host.onLatentPreview = null
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** the server runs prompts one at a time: a NEW promptId = the next queued run just started */
|
|
86
|
+
private onProgress(p: ExecutionProgress): void {
|
|
87
|
+
if (p.promptId !== this.currentPromptId) {
|
|
88
|
+
this.currentPromptId = p.promptId
|
|
89
|
+
this.notice = null
|
|
90
|
+
// stale latents from the previous run must not linger over the new one
|
|
91
|
+
this.st.preview.clearLatent()
|
|
92
|
+
}
|
|
93
|
+
this.progress = p
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
randomizeSeedAndRun(): void {
|
|
97
|
+
for (const [, varDef] of this.st.entries) {
|
|
98
|
+
// kind-narrowing cast sanctioned (agent/coding.md)
|
|
99
|
+
if (varDef.kind === 'seed') (varDef as SeedVar).randomize()
|
|
100
|
+
}
|
|
101
|
+
void this.run()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** 'o': real pixels in the OS viewer — the in-terminal ceiling is half-blocks */
|
|
105
|
+
openLastOutput(): void {
|
|
106
|
+
const last = this.outputs[this.outputs.length - 1]
|
|
107
|
+
if (last == null) {
|
|
108
|
+
this.notice = 'no output image yet'
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open'
|
|
112
|
+
const proc = spawn(cmd, [last], { stdio: 'ignore', detached: true })
|
|
113
|
+
proc.on('error', () => {
|
|
114
|
+
runInAction(() => {
|
|
115
|
+
this.notice = `could not launch ${cmd}`
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
proc.unref()
|
|
119
|
+
this.notice = `opened ${basename(last)}`
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ---- clipboard ----
|
|
123
|
+
private toClipboard(text: string): Promise<boolean> {
|
|
124
|
+
const [cmd, ...args] =
|
|
125
|
+
process.platform === 'darwin'
|
|
126
|
+
? ['pbcopy']
|
|
127
|
+
: process.platform === 'win32'
|
|
128
|
+
? ['clip']
|
|
129
|
+
: ['xclip', '-selection', 'clipboard']
|
|
130
|
+
return new Promise((resolve) => {
|
|
131
|
+
const proc = spawn(cmd ?? 'pbcopy', args, { stdio: ['pipe', 'ignore', 'ignore'] })
|
|
132
|
+
proc.on('error', () => resolve(false))
|
|
133
|
+
proc.on('close', (code) => resolve(code === 0))
|
|
134
|
+
proc.stdin.write(text)
|
|
135
|
+
proc.stdin.end()
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** 'c': copy workflow.json (litegraph, drag into the ComfyUI editor) */
|
|
140
|
+
async copyWorkflowJson(): Promise<void> {
|
|
141
|
+
try {
|
|
142
|
+
const wf = await this.st.wf.build()
|
|
143
|
+
const json = await wf.toWorkflowJson()
|
|
144
|
+
const ok = await this.toClipboard(JSON.stringify(json, null, 2))
|
|
145
|
+
runInAction(() => {
|
|
146
|
+
this.notice = ok ? `workflow.json copied (${json.nodes.length} nodes)` : 'clipboard copy failed'
|
|
147
|
+
})
|
|
148
|
+
} catch (e) {
|
|
149
|
+
runInAction(() => {
|
|
150
|
+
this.notice = `${extractErrorMessage(e)}`
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** 'C': copy api.json (the POST /prompt payload) */
|
|
156
|
+
async copyApiJson(): Promise<void> {
|
|
157
|
+
try {
|
|
158
|
+
const wf = await this.st.wf.build()
|
|
159
|
+
const json = wf.toApiJson('use_stringified_numbers_only')
|
|
160
|
+
const ok = await this.toClipboard(JSON.stringify(json, null, 2))
|
|
161
|
+
runInAction(() => {
|
|
162
|
+
this.notice = ok ? `api.json copied (${Object.keys(json).length} nodes)` : 'clipboard copy failed'
|
|
163
|
+
})
|
|
164
|
+
} catch (e) {
|
|
165
|
+
runInAction(() => {
|
|
166
|
+
this.notice = `${extractErrorMessage(e)}`
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { makeAutoObservable, runInAction } from 'mobx'
|
|
2
|
+
import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
|
|
3
|
+
import type { ComfyHost } from 'src/host/ComfyHost.ts'
|
|
4
|
+
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
5
|
+
|
|
6
|
+
type HostAction = { key: 'refresh' | 'restart' | 'clear-queue' | 'interrupt'; label: string }
|
|
7
|
+
|
|
8
|
+
/** host panel (`h`): stats about the connected host + maintenance actions */
|
|
9
|
+
export class HostSt {
|
|
10
|
+
constructor(private st: TuiSt) {
|
|
11
|
+
makeAutoObservable<HostSt, 'st'>(this, { st: false })
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
ix: number = 0
|
|
15
|
+
/** action key while one runs (actions are serialized) */
|
|
16
|
+
running: HostAction['key'] | null = null
|
|
17
|
+
|
|
18
|
+
readonly actions: HostAction[] = [
|
|
19
|
+
{ key: 'refresh', label: 're-codegen SDK (refetch object_info + reload workflow)' },
|
|
20
|
+
{ key: 'restart', label: 'restart ComfyUI (manager reboot)' },
|
|
21
|
+
{ key: 'clear-queue', label: 'clear pending queue' },
|
|
22
|
+
{ key: 'interrupt', label: 'interrupt current run' },
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
get host(): ComfyHost {
|
|
26
|
+
return this.st.wf.host
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get stats(): { label: string; value: string }[] {
|
|
30
|
+
const schema = this.host.schema
|
|
31
|
+
return [
|
|
32
|
+
{ label: 'node types', value: String(schema.nodes.length) },
|
|
33
|
+
{ label: 'loras', value: String(schema.getLoras().length) },
|
|
34
|
+
{ label: 'embeddings', value: String(schema.data.embeddings.length) },
|
|
35
|
+
{ label: 'queue', value: String(this.st.queue.remaining) },
|
|
36
|
+
{ label: 'ws', value: this.host.getWSUrl() },
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
begin(): void {
|
|
41
|
+
this.st.mode = 'host'
|
|
42
|
+
this.ix = 0
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
blur(): void {
|
|
46
|
+
this.st.mode = 'nav'
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
move(delta: number): void {
|
|
50
|
+
const len = this.actions.length
|
|
51
|
+
this.ix = (this.ix + delta + len) % len
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async commit(): Promise<void> {
|
|
55
|
+
const action = this.actions[this.ix]
|
|
56
|
+
if (action == null || this.running != null) return
|
|
57
|
+
if (action.key === 'refresh') return this.refreshSdk()
|
|
58
|
+
if (action.key === 'restart') return this.restartComfy()
|
|
59
|
+
if (action.key === 'clear-queue') return this.st.queue.clearPending()
|
|
60
|
+
return this.st.queue.interrupt()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** refetch object_info, regen the sdk, then cache-busted reload of the current
|
|
64
|
+
* module so dynamic var options (v.loras…) see the new values */
|
|
65
|
+
private async refreshSdk(): Promise<void> {
|
|
66
|
+
runInAction(() => {
|
|
67
|
+
this.running = 'refresh'
|
|
68
|
+
})
|
|
69
|
+
try {
|
|
70
|
+
await this.host.fetchAndUpdateSchema()
|
|
71
|
+
await this.st.workflows.reload(this.st.drafts.active ?? 'default')
|
|
72
|
+
runInAction(() => {
|
|
73
|
+
const schema = this.host.schema
|
|
74
|
+
this.st.exec.notice = `SDK regenerated: ${schema.nodes.length} node types, ${schema.getLoras().length} loras`
|
|
75
|
+
})
|
|
76
|
+
} catch (e) {
|
|
77
|
+
runInAction(() => {
|
|
78
|
+
this.st.exec.error = extractErrorMessage(e)
|
|
79
|
+
})
|
|
80
|
+
} finally {
|
|
81
|
+
runInAction(() => {
|
|
82
|
+
this.running = null
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private async restartComfy(): Promise<void> {
|
|
88
|
+
runInAction(() => {
|
|
89
|
+
this.running = 'restart'
|
|
90
|
+
})
|
|
91
|
+
try {
|
|
92
|
+
await this.host.manager.restartComfyUI()
|
|
93
|
+
runInAction(() => {
|
|
94
|
+
this.st.exec.notice = 'reboot requested — the ws reconnects when the host is back'
|
|
95
|
+
})
|
|
96
|
+
} catch (e) {
|
|
97
|
+
// the server dropping the connection mid-reboot IS the expected shape
|
|
98
|
+
runInAction(() => {
|
|
99
|
+
this.st.exec.notice = `reboot requested (${extractErrorMessage(e)}) — the ws reconnects when the host is back`
|
|
100
|
+
})
|
|
101
|
+
} finally {
|
|
102
|
+
runInAction(() => {
|
|
103
|
+
this.running = null
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|