comfy-ts 2.17.0 → 2.17.1

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.
Files changed (37) hide show
  1. package/dist/{ServeApp-BSA5yzxZ.js → ServeApp-qXcQfdgT.js} +3 -3
  2. package/dist/ServeApp-qXcQfdgT.js.map +1 -0
  3. package/dist/cli.js +58 -8
  4. package/dist/cli.js.map +1 -1
  5. package/dist/index.cjs +37 -11
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.js +37 -11
  8. package/dist/index.js.map +1 -1
  9. package/dist/{run-run-DnaMLCFn.js → run-run-tg82jUIk.js} +3 -3
  10. package/dist/{run-run-DnaMLCFn.js.map → run-run-tg82jUIk.js.map} +1 -1
  11. package/dist/{run-serve-CbKxIu6i.js → run-serve-DaXzoVTS.js} +58 -12
  12. package/dist/run-serve-DaXzoVTS.js.map +1 -0
  13. package/dist/{run-tui-B0AQWbad.js → run-tui-Bw7BA75d.js} +3 -3
  14. package/dist/{run-tui-B0AQWbad.js.map → run-tui-Bw7BA75d.js.map} +1 -1
  15. package/dist/serve-web.js +56 -48
  16. package/dist/{state-C2oDiQ26.js → state-zTow5ucI.js} +38 -12
  17. package/dist/state-zTow5ucI.js.map +1 -0
  18. package/dist/web.js +37 -11
  19. package/dist/web.js.map +1 -1
  20. package/package.json +2 -2
  21. package/src/cli/bunHop.ts +49 -0
  22. package/src/cli/comfy-ts-cli.ts +4 -4
  23. package/src/cli/serve/run-serve.ts +51 -13
  24. package/src/cli/serve/web/components/App.tsx +2 -0
  25. package/src/cli/serve/web/components/DialogLayer.tsx +55 -0
  26. package/src/cli/serve/web/components/DraftTabs.tsx +8 -3
  27. package/src/cli/serve/web/components/PromptEnhancer.tsx +15 -9
  28. package/src/cli/serve/web/components/SideMenu.tsx +16 -8
  29. package/src/cli/serve/web/state/WebSt.ts +10 -1
  30. package/src/cli/serve/web/state/dialog.ts +59 -0
  31. package/src/cli/serve/web/state/keptLines.ts +1 -1
  32. package/src/cli/serve/web/styles.ts +8 -0
  33. package/src/litegraph/convertFlowToLiteGraphJSON.ts +38 -20
  34. package/src/promptEnhancers.ts +1 -1
  35. package/dist/ServeApp-BSA5yzxZ.js.map +0 -1
  36. package/dist/run-serve-CbKxIu6i.js.map +0 -1
  37. package/dist/state-C2oDiQ26.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comfy-ts",
3
- "version": "2.17.0",
3
+ "version": "2.17.1",
4
4
  "description": "The complete TypeScript toolkit for ComfyUI and generative AI. Fully type-safe SDK with autocomplete on every node, companion CLI, TUI, agentic docs, and 50+ examples. Design, run and deploy creative pipelines for image, video, audio, 3d and text on any ComfyUI, local, cloud or hosted.",
5
5
  "keywords": [
6
6
  "comfyui",
@@ -140,7 +140,7 @@
140
140
  "oxfmt": "^0.60.0",
141
141
  "oxlint": "^1.75.0",
142
142
  "oxlint-tsgolint": "^7.0.2001",
143
- "rvlib-shipkit": "^1.7.0",
143
+ "rvlib-shipkit": "^2.6.0",
144
144
  "rvlib-ts-tools": "^0.3.3",
145
145
  "tsdown": "^0.22.14",
146
146
  "typescript": "^7.0.2"
@@ -0,0 +1,49 @@
1
+ // `tui`, `serve` and `run` import .cflow.ts modules, which need bun: the bin's
2
+ // node shebang re-execs the same command line through it. The wrapper is the pid
3
+ // a terminal, a supervisor or an agent holds and stops, so the child must never
4
+ // outlive it (agent/architecture.md item 10)
5
+ import { spawn } from 'node:child_process'
6
+ import { constants } from 'node:os'
7
+
8
+ const HOP_PARENT_ENV = 'COMFY_TS_HOP_PARENT'
9
+ const FORWARDED: NodeJS.Signals[] = ['SIGINT', 'SIGTERM', 'SIGHUP']
10
+
11
+ /** runs `bun <argv>` with the terminal inherited, forwarding the stop signals;
12
+ * resolves the child's exit code, or `error` when bun cannot start */
13
+ export function hopToBun(argv: string[]): Promise<{ code: number } | { error: Error }> {
14
+ return new Promise((resolve) => {
15
+ const child = spawn('bun', argv, {
16
+ stdio: 'inherit',
17
+ env: { ...process.env, [HOP_PARENT_ENV]: String(process.pid) },
18
+ })
19
+ const forward = (signal: NodeJS.Signals): void => {
20
+ child.kill(signal)
21
+ }
22
+ for (const signal of FORWARDED) process.on(signal, forward)
23
+ const done = (r: { code: number } | { error: Error }): void => {
24
+ for (const signal of FORWARDED) process.off(signal, forward)
25
+ resolve(r)
26
+ }
27
+ child.once('error', (error) => done({ error }))
28
+ child.once('exit', (code, signal) => {
29
+ if (code != null) return done({ code })
30
+ done({ code: signal == null ? 1 : 128 + (constants.signals[signal] ?? 0) })
31
+ })
32
+ })
33
+ }
34
+
35
+ /** in the bun child: exit once the process that started it is gone. A SIGKILL to
36
+ * the wrapper reaches no handler, so the child polls its own ppid, which changes
37
+ * (to 1, or a subreaper) when its parent dies. It watches the ppid it started
38
+ * with, not the wrapper pid: a version manager shim may sit between the two */
39
+ export function armHopChild(p: { intervalMs?: number } = {}): void {
40
+ if (process.env[HOP_PARENT_ENV] == null) return
41
+ // a grandchild has another parent: it must never inherit the watch
42
+ Reflect.deleteProperty(process.env, HOP_PARENT_ENV)
43
+ const parent = process.ppid
44
+ setInterval(() => {
45
+ if (process.ppid === parent) return
46
+ console.error(`[comfy-ts] the process that started this one (pid ${parent}) is gone: exiting`)
47
+ process.exit(1)
48
+ }, p.intervalMs ?? 1000).unref()
49
+ }
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  // sidekick CLI: `bunx comfy-ts <command>` — codegen without writing any code
3
- import { spawnSync } from 'node:child_process'
3
+ import { armHopChild, hopToBun } from 'src/cli/bunHop.ts'
4
4
  import { fileURLToPath } from 'node:url'
5
5
  import { runGen } from 'src/cli/gen.ts'
6
6
  import { runLoras } from 'src/cli/loras.ts'
@@ -62,13 +62,13 @@ async function main(): Promise<number> {
62
62
  // node shebang means `bunx comfy-ts tui|serve` lands here under NODE. Hop
63
63
  // to bun when we are not already in it; without bun, degrade loudly.
64
64
  if (process.versions.bun == null) {
65
- const self = fileURLToPath(import.meta.url)
66
- const res = spawnSync('bun', [self, cmd, ...rest], { stdio: 'inherit' })
67
- if (res.error == null) return res.status ?? 1
65
+ const res = await hopToBun([fileURLToPath(import.meta.url), cmd, ...rest])
66
+ if ('code' in res) return res.code
68
67
  console.error(
69
68
  `[comfy-ts ${cmd}] bun not found (${res.error.message}) — continuing under node: the examples packaged in node_modules cannot load here, and your own .cflow.ts modules rely on node's type stripping`,
70
69
  )
71
70
  }
71
+ armHopChild()
72
72
  if (cmd === 'run') {
73
73
  const { runRun } = await import('src/cli/run/run-run.ts')
74
74
  return runRun(rest)
@@ -1,7 +1,8 @@
1
1
  // `comfy-ts serve [dir | module.cflow.ts] [--port N] [--host ADDR]`
2
2
  // drafts as a local HTTP generation API — agent/architecture.md item 12
3
+ import { spawnSync } from 'node:child_process'
3
4
  import { statSync } from 'node:fs'
4
- import { createServer, type IncomingMessage, type ServerResponse } from 'node:http'
5
+ import { createServer, type IncomingMessage, type Server, type ServerResponse } from 'node:http'
5
6
  import { networkInterfaces } from 'node:os'
6
7
  import { pathToFileURL } from 'node:url'
7
8
  import { dirname, resolve } from 'pathe'
@@ -151,23 +152,60 @@ export async function runServe(args: string[]): Promise<number> {
151
152
  workspace: typeof comfyts === 'undefined' ? process.cwd() : comfyts.rootPath,
152
153
  root: statSync(target).isDirectory() ? target : dirname(target),
153
154
  })
154
- printStartup(app, parsed.bind, parsed.port)
155
-
156
- const server = createServer(makeRequestListener(app))
157
-
158
- server.on('error', (e) => {
159
- console.error(`[comfy-ts serve] server error: ${extractErrorMessage(e)}`)
160
- process.exitCode = 1
161
- server.close()
162
- })
163
- server.listen(parsed.port, parsed.bind)
155
+ return listenUntilClosed(createServer(makeRequestListener(app)), parsed.port, parsed.bind, () =>
156
+ printStartup(app, parsed.bind, parsed.port),
157
+ )
158
+ }
164
159
 
165
- // stays up until the process is interrupted or the server dies
160
+ /** listens, then stays up until the server closes; resolves the exit code. A listen
161
+ * failure resolves 1 AT ONCE: bun fires no `close` for a server that never listened,
162
+ * and a cli awaiting one never ends (agent/architecture.md item 12) */
163
+ export function listenUntilClosed(
164
+ server: Server,
165
+ port: number,
166
+ bind: string,
167
+ onListening?: () => void,
168
+ ): Promise<number> {
166
169
  return new Promise<number>((resolveExit) => {
167
- server.on('close', () => resolveExit(typeof process.exitCode === 'number' ? process.exitCode : 0))
170
+ let listening = false
171
+ server.once('listening', () => {
172
+ listening = true
173
+ onListening?.()
174
+ })
175
+ server.on('error', (e) => {
176
+ if (!listening) {
177
+ console.error(`[comfy-ts serve] 🔴 ${describeListenError(e, port, bind)}`)
178
+ resolveExit(1)
179
+ return
180
+ }
181
+ console.error(`[comfy-ts serve] server error: ${extractErrorMessage(e)}`)
182
+ server.close()
183
+ resolveExit(1)
184
+ })
185
+ server.on('close', () => resolveExit(0))
186
+ server.listen(port, bind)
168
187
  })
169
188
  }
170
189
 
190
+ function describeListenError(e: Error, port: number, bind: string): string {
191
+ const code = 'code' in e ? e.code : undefined
192
+ if (code !== 'EADDRINUSE') return `cannot listen on ${bind}:${port}: ${extractErrorMessage(e)}`
193
+ const holder = portHolder(port)
194
+ const by = holder == null ? '' : ` by ${holder}`
195
+ return `port ${port} on ${bind} is taken${by}: stop it, or pick another port with --port <n>`
196
+ }
197
+
198
+ /** `pid <n> (<command>)` of the process listening on a tcp port; null when unknowable
199
+ * (no lsof on this box, or the holder is not visible to this user) */
200
+ export function portHolder(port: number): string | null {
201
+ const lsof = spawnSync('lsof', ['-nP', `-iTCP:${port}`, '-sTCP:LISTEN', '-t'], { encoding: 'utf8', timeout: 2000 })
202
+ const pid = lsof.error == null ? lsof.stdout.split('\n')[0]?.trim() : undefined
203
+ if (pid == null || pid === '') return null
204
+ const ps = spawnSync('ps', ['-o', 'command=', '-p', pid], { encoding: 'utf8', timeout: 2000 })
205
+ const command = ps.error == null ? ps.stdout.trim().slice(0, 160) : ''
206
+ return command === '' ? `pid ${pid}` : `pid ${pid} (${command})`
207
+ }
208
+
171
209
  export type Nic = { address: string; family: string | number; internal: boolean }
172
210
 
173
211
  /** the addresses this bind actually answers on. `0.0.0.0` means every interface, so printing
@@ -18,6 +18,7 @@ import { collapsedPreview } from 'src/cli/serve/web/state/stableSlots.ts'
18
18
  import { GenerateButton, VarsForm } from 'src/cli/serve/web/components/VarsForm.tsx'
19
19
  import { DraftTabs, useTabShortcuts } from 'src/cli/serve/web/components/DraftTabs.tsx'
20
20
  import { ShortcutsModal } from 'src/cli/serve/web/components/ShortcutsModal.tsx'
21
+ import { DialogLayer } from 'src/cli/serve/web/components/DialogLayer.tsx'
21
22
  import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
22
23
 
23
24
  /** ⌘A / ctrl+A selects the field you are in. The browser does this on its own until something
@@ -529,6 +530,7 @@ export const App = observer(function App(p: { st: WebSt }) {
529
530
  {narrow ? <MenuDrawer st={p.st} /> : null}
530
531
  <Omnibox st={p.st} />
531
532
  <ShortcutsModal st={p.st} />
533
+ <DialogLayer />
532
534
  <TooltipLayer />
533
535
  </div>
534
536
  )
@@ -0,0 +1,55 @@
1
+ // the one open confirm or text prompt (state/dialog.ts), above every modal. Enter and esc are
2
+ // caught on the window in the CAPTURE phase, so the modal under it never sees them (esc there
3
+ // would close the enhancer along with the dialog)
4
+ import { observer } from 'mobx-react-lite'
5
+ import { useEffect } from 'react'
6
+ import { dialogs } from 'src/cli/serve/web/state/dialog.ts'
7
+ import { onEscape } from 'src/cli/serve/web/state/escape.ts'
8
+
9
+ export const DialogLayer = observer(function DialogLayer() {
10
+ const c = dialogs.current
11
+ const open = c != null
12
+ useEffect(() => {
13
+ if (!open) return
14
+ const onKey = (ev: KeyboardEvent): void => {
15
+ const handled =
16
+ onEscape(ev, () => dialogs.cancel()) ||
17
+ (ev.key === 'Enter' && !ev.isComposing && (ev.preventDefault(), dialogs.accept(), true))
18
+ if (handled) ev.stopPropagation()
19
+ }
20
+ window.addEventListener('keydown', onKey, true)
21
+ return () => window.removeEventListener('keydown', onKey, true)
22
+ }, [open])
23
+ if (c == null) return null
24
+ return (
25
+ <div className="modal-overlay dialog-overlay" onClick={() => dialogs.cancel()}>
26
+ <div className="modal dialog-modal" role="dialog" onClick={(ev) => ev.stopPropagation()}>
27
+ <div className="modal-body dialog-body">
28
+ <div className="dialog-message">{c.message}</div>
29
+ {c.kind === 'prompt' ? (
30
+ <input
31
+ type="text"
32
+ autoFocus
33
+ value={c.value}
34
+ onFocus={(ev) => ev.currentTarget.select()}
35
+ onChange={(ev) => dialogs.setValue(ev.target.value)}
36
+ />
37
+ ) : null}
38
+ </div>
39
+ <div className="dialog-actions">
40
+ <button type="button" onClick={() => dialogs.cancel()}>
41
+ cancel
42
+ </button>
43
+ <button
44
+ type="button"
45
+ autoFocus={c.kind === 'confirm'}
46
+ className={c.kind === 'confirm' && c.danger ? 'dialog-danger' : 'primary'}
47
+ onClick={() => dialogs.accept()}
48
+ >
49
+ {c.kind === 'confirm' ? c.ok : 'ok'}
50
+ </button>
51
+ </div>
52
+ </div>
53
+ </div>
54
+ )
55
+ })
@@ -1,6 +1,7 @@
1
1
  // the open drafts as tabs over the work area: a click opens one (a click on the open one shows
2
2
  // its actions), × or a middle click closes it, ⌘1 to ⌘8 pick one, ⌘9 the last, ⌘PageUp and
3
3
  // ⌘PageDown step, ⌘W closes the open one unless it is the last (ctrl elsewhere), from any focus
4
+ import { dialogs } from 'src/cli/serve/web/state/dialog.ts'
4
5
  import {
5
6
  autoUpdate,
6
7
  flip,
@@ -159,9 +160,13 @@ const TabMenu = observer(function TabMenu(p: { st: WebSt; tab: DraftTab; anchor:
159
160
  type="button"
160
161
  className="menu-row menu-action danger"
161
162
  onClick={() =>
162
- run(() => {
163
- if (window.confirm(`delete draft '${p.tab.draft}' of ${p.tab.module}? the file is removed.`))
164
- return p.st.deleteDraft(p.tab)
163
+ run(async () => {
164
+ const ok = await dialogs.confirm({
165
+ message: `delete draft '${p.tab.draft}' of ${p.tab.module}? the file is removed.`,
166
+ ok: 'delete',
167
+ danger: true,
168
+ })
169
+ if (ok) await p.st.deleteDraft(p.tab)
165
170
  })
166
171
  }
167
172
  >
@@ -1,6 +1,7 @@
1
1
  // ✨ on a prompt row → the refine modal: the LLM configs and the master prompts as two lists of
2
2
  // vertical tabs on the left, the job (yours → rewrite) alone on the right. A tab's pen opens its
3
3
  // editor over the job. Nothing touches the var until APPLY.
4
+ import { dialogs } from 'src/cli/serve/web/state/dialog.ts'
4
5
  import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
5
6
  import { observer } from 'mobx-react-lite'
6
7
  import { useEffect, useRef, type ReactNode } from 'react'
@@ -51,8 +52,8 @@ const TabList = observer(function TabList(p: {
51
52
  onSelect(name: string): void
52
53
  onCreate(name: string): void
53
54
  }) {
54
- const create = (): void => {
55
- const name = window.prompt(`name the new ${p.kind}`, p.newName)
55
+ const create = async (): Promise<void> => {
56
+ const name = await dialogs.prompt({ message: `name the new ${p.kind}`, value: p.newName })
56
57
  if (name != null) p.onCreate(name)
57
58
  }
58
59
  const dot = (name: string): ReactNode => {
@@ -96,7 +97,7 @@ const TabList = observer(function TabList(p: {
96
97
  ) : null}
97
98
  </div>
98
99
  ))}
99
- <button type="button" className="enh-tab-new" onClick={create}>
100
+ <button type="button" className="enh-tab-new" onClick={() => void create()}>
100
101
  <Icon name="plus" /> new {p.kind}
101
102
  </button>
102
103
  </div>
@@ -184,14 +185,19 @@ function EditPanel(p: {
184
185
  onClose(): void
185
186
  children: ReactNode
186
187
  }): ReactNode {
187
- const rename = (): void => {
188
+ const rename = async (): Promise<void> => {
188
189
  if (p.name == null) return
189
- const name = window.prompt(`rename this ${p.kind} (renames the file)`, p.name)
190
+ const name = await dialogs.prompt({ message: `rename this ${p.kind} (renames the file)`, value: p.name })
190
191
  if (name != null) p.onRename(name)
191
192
  }
192
- const remove = (): void => {
193
+ const remove = async (): Promise<void> => {
193
194
  if (p.name == null) return
194
- if (window.confirm(`delete ${p.kind} '${p.name}'? its file is removed.`)) p.onDelete()
195
+ const ok = await dialogs.confirm({
196
+ message: `delete ${p.kind} '${p.name}'? its file is removed.`,
197
+ ok: 'delete',
198
+ danger: true,
199
+ })
200
+ if (ok) p.onDelete()
195
201
  }
196
202
  return (
197
203
  <section className="enh-edit">
@@ -204,10 +210,10 @@ function EditPanel(p: {
204
210
  <button type="button" onClick={() => p.onDuplicate()}>
205
211
  duplicate
206
212
  </button>
207
- <button type="button" onClick={rename}>
213
+ <button type="button" onClick={() => void rename()}>
208
214
  rename
209
215
  </button>
210
- <button type="button" className="quiet-danger" onClick={remove}>
216
+ <button type="button" className="quiet-danger" onClick={() => void remove()}>
211
217
  <Icon name="trash" /> delete
212
218
  </button>
213
219
  </span>
@@ -1,5 +1,6 @@
1
1
  // the menu column: where you are, widest scope first (workspace, workflow, draft, host, preview).
2
2
  // a left Panel above 760px (collapsible to an icon rail), a drawer behind ☰ below
3
+ import { dialogs } from 'src/cli/serve/web/state/dialog.ts'
3
4
  import { observer, useLocalObservable } from 'mobx-react-lite'
4
5
  import type { ReactNode } from 'react'
5
6
  import { Icon, type IconName } from 'src/cli/serve/web/components/Icon.tsx'
@@ -96,11 +97,14 @@ const DraftSection = observer(function DraftSection(p: { st: WebSt; form: FormSt
96
97
  type="button"
97
98
  className="head-icon danger"
98
99
  data-tip="delete this draft's file (default resets to the workflow's own values)"
99
- onClick={() => {
100
- if (
101
- window.confirm(`delete draft '${p.form.draft}' of ${p.form.moduleKey}? the file is removed.`)
102
- )
103
- void p.st.deleteDraft({ module: p.form.moduleKey, draft: p.form.draft })
100
+ onClick={async () => {
101
+ const target = { module: p.form.moduleKey, draft: p.form.draft }
102
+ const ok = await dialogs.confirm({
103
+ message: `delete draft '${target.draft}' of ${target.module}? the file is removed.`,
104
+ ok: 'delete',
105
+ danger: true,
106
+ })
107
+ if (ok) void p.st.deleteDraft(target)
104
108
  }}
105
109
  >
106
110
  <Icon name="trash" />
@@ -277,9 +281,13 @@ export const MenuCards = observer(function MenuCards(p: { st: WebSt }) {
277
281
  type="button"
278
282
  className="head-icon danger"
279
283
  data-tip="restart ComfyUI on that host (manager reboot) — it reconnects when back"
280
- onClick={() => {
281
- if (window.confirm(`restart ComfyUI on '${p.st.hostFor(form.moduleKey)}'?`))
282
- void p.st.hostAction('restart')
284
+ onClick={async () => {
285
+ const ok = await dialogs.confirm({
286
+ message: `restart ComfyUI on '${p.st.hostFor(form.moduleKey)}'?`,
287
+ ok: 'restart',
288
+ danger: true,
289
+ })
290
+ if (ok) void p.st.hostAction('restart')
283
291
  }}
284
292
  >
285
293
  <Icon name="power" />
@@ -1,5 +1,6 @@
1
1
  // ROOT state tree of the serve web ui (app-state-tree doctrine: one root,
2
2
  // child stores hang off it, components read and call)
3
+ import { dialogs } from 'src/cli/serve/web/state/dialog.ts'
3
4
  import { makeAutoObservable, observableRef, observableShallow, runInAction } from 'mobx'
4
5
  import {
5
6
  deleteDraft,
@@ -1398,7 +1399,15 @@ export class WebSt {
1398
1399
  const name = rawName.trim()
1399
1400
  if (form == null || name === '') return
1400
1401
  const existing = this.moduleByKey(form.moduleKey)?.drafts.includes(name) === true
1401
- if (existing && !window.confirm(`draft '${name}' already exists — overwrite it?`)) return
1402
+ if (
1403
+ existing &&
1404
+ !(await dialogs.confirm({
1405
+ message: `draft '${name}' already exists: overwrite it?`,
1406
+ ok: 'overwrite',
1407
+ danger: true,
1408
+ }))
1409
+ )
1410
+ return
1402
1411
  try {
1403
1412
  const reply = await saveDraft({ module: form.moduleKey, draft: name, values })
1404
1413
  runInAction(() => {
@@ -0,0 +1,59 @@
1
+ // the panel's own confirm and text prompt, drawn in the page (DialogLayer). Never window.prompt /
2
+ // confirm / alert: sk gui's WKWebView implements no js panel, so there they return null / false
3
+ // at once and the button that asked does nothing; browsers also suppress them after a few.
4
+ // tests/serve-web-dialog.test.ts guards that no panel source calls the native ones
5
+ import { makeAutoObservable } from 'mobx'
6
+
7
+ export type DialogRequest =
8
+ | { kind: 'confirm'; message: string; ok: string; danger: boolean; resolve(ok: boolean): void }
9
+ | { kind: 'prompt'; message: string; value: string; resolve(value: string | null): void }
10
+
11
+ export class DialogSt {
12
+ current: DialogRequest | null = null
13
+
14
+ constructor() {
15
+ makeAutoObservable(this)
16
+ }
17
+
18
+ confirm(p: { message: string; ok?: string; danger?: boolean }): Promise<boolean> {
19
+ this.cancel()
20
+ return new Promise((resolve) => {
21
+ this.current = { kind: 'confirm', message: p.message, ok: p.ok ?? 'ok', danger: p.danger ?? false, resolve }
22
+ })
23
+ }
24
+
25
+ /** the typed text on ok, null on cancel */
26
+ prompt(p: { message: string; value: string }): Promise<string | null> {
27
+ this.cancel()
28
+ return new Promise((resolve) => {
29
+ this.current = { kind: 'prompt', message: p.message, value: p.value, resolve }
30
+ })
31
+ }
32
+
33
+ setValue(value: string): void {
34
+ if (this.current?.kind === 'prompt') this.current = { ...this.current, value }
35
+ }
36
+
37
+ accept(): void {
38
+ const c = this.current
39
+ if (c == null) return
40
+ this.current = null
41
+ if (c.kind === 'confirm') c.resolve(true)
42
+ else c.resolve(c.value)
43
+ }
44
+
45
+ cancel(): void {
46
+ const c = this.current
47
+ if (c == null) return
48
+ this.current = null
49
+ if (c.kind === 'confirm') c.resolve(false)
50
+ else c.resolve(null)
51
+ }
52
+ }
53
+
54
+ export const dialogs = new DialogSt()
55
+
56
+ /** the lines of a source that call a native browser dialog */
57
+ export function nativeDialogCalls(source: string): string[] {
58
+ return source.split('\n').filter((line) => /\b(window|globalThis)\.(prompt|confirm|alert)\s*\(/.test(line))
59
+ }
@@ -36,7 +36,7 @@ export function finishRewrite(model: string, kept: readonly string[]): string {
36
36
  const items = negativeItems(kept)
37
37
  const body = model
38
38
  .split('\n')
39
- .filter((l) => kept.length === 0 || !isKept(l))
39
+ .filter((l) => !isKept(l))
40
40
  .map((l) => {
41
41
  if (items.size === 0) return l
42
42
  let at = l.indexOf(' - ')
@@ -882,6 +882,14 @@ button.enh-big { font-size: 14px; padding: 8px 18px; }
882
882
  .modal-overlay.hist-overlay { z-index: 60; }
883
883
  .modal.hist-modal { width: min(1100px, 100%); height: min(76vh, 100%); max-height: none; }
884
884
  .hist-modal .modal-head { align-items: center; }
885
+ /* the panel's confirm and text prompt (DialogLayer): above every modal, the enhancer included */
886
+ .modal-overlay.dialog-overlay { z-index: 70; }
887
+ .modal.dialog-modal { width: min(420px, 100%); }
888
+ .dialog-body { display: flex; flex-direction: column; gap: 10px; }
889
+ .dialog-message { white-space: pre-line; }
890
+ .dialog-body input { width: 100%; }
891
+ .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 10px 10px; }
892
+ .dialog-actions button.dialog-danger { color: var(--red); border-color: var(--red); }
885
893
  .hist-cols { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
886
894
  .hist-list { min-height: 0; overflow-y: auto; border-right: 1px solid var(--border); padding: 6px; display: flex; flex-direction: column; gap: 2px; }
887
895
  .hist-row {
@@ -1,7 +1,7 @@
1
1
  import type { ComfyNode } from 'src/graph/ComfyNode.ts'
2
2
  import type { ComfyWorkflow } from 'src/runner/ComfyWorkflow.ts'
3
3
  import { bang } from 'src/utils/bang.ts'
4
- import { classifySchemaInput } from 'src/sdk-generator/inputWidgetKind.ts'
4
+ import { classifySchemaInput, containerInstanceSlotType } from 'src/sdk-generator/inputWidgetKind.ts'
5
5
  import type { LiteGraphJSON } from 'src/litegraph/LiteGraphJSON.ts'
6
6
  import type { LiteGraphLinkTuple } from 'src/litegraph/LiteGraphLink.ts'
7
7
  import { asLiteGraphLinkID, type LiteGraphLinkID } from 'src/litegraph/LiteGraphLinkID.ts'
@@ -40,27 +40,38 @@ export const convertFlowToLiteGraphJSON = (graph: ComfyWorkflow): LiteGraphJSON
40
40
  const convertNodeToLiteGraphNode = (ctx: LiteGraphCtx, node: ComfyNode<any>): LiteGraphNode => {
41
41
  const inputs: LiteGraphNodeInput[] = []
42
42
  const widgets_values: unknown[] = []
43
+ // target_slot = index within THIS node's litegraph inputs array,
44
+ // not the schema input index (widget inputs are not litegraph slots)
45
+ const pushLinked = (name: string, type: string, link: [string, number], shape?: number): void => {
46
+ const nodeUidNumber = bang(
47
+ ctx.graph.nodes.find((n) => n.uid === link[0])?.uidNumber,
48
+ `link target node "${link[0]}" not found in graph`,
49
+ )
50
+ const linkId = ctx.allocateLink(nodeUidNumber, link[1], node.uidNumber, asLiteGraphSlotIndex(inputs.length), type)
51
+ inputs.push(shape == null ? { name, type, link: linkId } : { name, type, shape, link: linkId })
52
+ }
43
53
  for (const ipt of node.$schema.inputs) {
44
- const raw = node.serializeValue(ipt.nameInComfy, node.json.inputs[ipt.nameInComfy])
45
54
  const kind = classifySchemaInput(ipt)
55
+ if (kind.kind === 'dynamic-container') {
56
+ // the declaration is never a slot: each grown instance is its own
57
+ // optional slot `decl.<instance>` (shape 7), as the editor stores it
58
+ const type = containerInstanceSlotType(ipt.opts) ?? '*'
59
+ for (const instance of kind.instanceNames) {
60
+ const name = `${ipt.nameInComfy}.${instance}`
61
+ const value = node.json.inputs[name]
62
+ if (value == null) continue
63
+ const raw = node.serializeValue(name, value)
64
+ if (!_isLink(raw))
65
+ throw new Error(
66
+ `🔴 [toWorkflowJson] ${node.$schema.nameInComfy}#${node.uid} "${name}" holds a literal; an autogrow instance is a link slot in the editor`,
67
+ )
68
+ pushLinked(name, type, raw, 7)
69
+ }
70
+ continue
71
+ }
72
+ const raw = node.serializeValue(ipt.nameInComfy, node.json.inputs[ipt.nameInComfy])
46
73
  if (_isLink(raw)) {
47
- const nodeUidNumber = bang(
48
- ctx.graph.nodes.find((n) => n.uid === raw[0])?.uidNumber,
49
- `link target node "${raw[0]}" not found in graph`,
50
- )
51
- inputs.push({
52
- name: ipt.nameInComfy,
53
- type: ipt.typeName,
54
- // target_slot = index within THIS node's litegraph inputs array,
55
- // not the schema input index (widget inputs are not litegraph slots)
56
- link: ctx.allocateLink(
57
- nodeUidNumber,
58
- raw[1],
59
- node.uidNumber,
60
- asLiteGraphSlotIndex(inputs.length),
61
- ipt.typeName,
62
- ),
63
- })
74
+ pushLinked(ipt.nameInComfy, ipt.typeName, raw)
64
75
  } else if (kind.kind === 'widget') {
65
76
  // frontend button-widget values ride BEFORE the real value (LOAD_3D)
66
77
  widgets_values.push(...kind.prefixValues, raw)
@@ -69,7 +80,7 @@ const convertNodeToLiteGraphNode = (ctx: LiteGraphCtx, node: ComfyNode<any>): Li
69
80
  // INT-named-seed heuristic lives inside controlConsumes), so export
70
81
  // and import can never disagree on the run length
71
82
  const phantoms = kind.consumes - 1 - kind.prefixValues.length
72
- for (let i = 0; i < phantoms; i++) widgets_values.push(false)
83
+ for (let i = 0; i < phantoms; i++) widgets_values.push(controlMode(ipt.opts))
73
84
  } else {
74
85
  // unconnected link-kind input: a litegraph slot with no link —
75
86
  // NEVER a widget value (that would misalign the round-trip import)
@@ -96,6 +107,13 @@ const convertNodeToLiteGraphNode = (ctx: LiteGraphCtx, node: ComfyNode<any>): Li
96
107
  }
97
108
  }
98
109
 
110
+ /** the editor's control widget is a combo (fixed, increment, decrement, randomize):
111
+ * a config naming a mode keeps it, anything else is `fixed`, the seed the code pinned */
112
+ const controlMode = (opts: unknown): string => {
113
+ const mode = typeof opts === 'object' && opts != null ? Reflect.get(opts, 'control_after_generate') : null
114
+ return typeof mode === 'string' ? mode : 'fixed'
115
+ }
116
+
99
117
  const _isLink = (v: unknown): v is [string, number] => {
100
118
  return Array.isArray(v) && v.length === 2 && typeof v[0] === 'string' && typeof v[1] === 'number'
101
119
  }
@@ -39,7 +39,7 @@ Rewrite it into ONE paragraph a reader could picture with their eyes closed:
39
39
  - plain descriptive english. Flowing sentences and comma separated descriptive clauses both read well; disconnected keyword soup does not. No praise words, never "masterpiece", "8k", "highly detailed", "award winning", "trending on". The model is steered by what you name, not by what you forbid.
40
40
  - text that must appear inside the image is spelled out in "quotes", exactly as it should be rendered.
41
41
  - roughly 60 to 150 words, one paragraph, no lists, no headings, no quotes around the result itself.
42
- - keep any "// " comment line and any "- " negative line from the input verbatim, each on its own line.
42
+ - never write a negative ("- ...") line or a comment ("// ...") line: the panel keeps the user's own and adds them back after your prompt.
43
43
 
44
44
  Answer with the rewritten prompt and nothing else: no preamble, no explanation.
45
45
  `,