comfy-ts 2.12.0 → 2.14.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.
Files changed (81) hide show
  1. package/dist/{LogsSt-U1H0mP1m.js → LogsSt-CUeo843w.js} +18 -4
  2. package/dist/LogsSt-CUeo843w.js.map +1 -0
  3. package/dist/cli.js +4 -4
  4. package/dist/index.cjs +123 -12
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +96 -16
  7. package/dist/index.d.ts +96 -16
  8. package/dist/index.js +123 -12
  9. package/dist/index.js.map +1 -1
  10. package/dist/{run-serve-BeAznay5.js → run-serve-DUqcn0h3.js} +477 -63
  11. package/dist/run-serve-DUqcn0h3.js.map +1 -0
  12. package/dist/{run-tui-BTGjvnKk.js → run-tui-D-LaSqgB.js} +4 -4
  13. package/dist/{run-tui-BTGjvnKk.js.map → run-tui-D-LaSqgB.js.map} +1 -1
  14. package/dist/{schemaDrift-Cg39vs53.js → schemaDrift-E95iTF7E.js} +4 -1
  15. package/dist/{schemaDrift-Cg39vs53.js.map → schemaDrift-E95iTF7E.js.map} +1 -1
  16. package/dist/serve-web.js +378 -141
  17. package/dist/{state-C7REnHan.js → state-BytbdZ8s.js} +122 -14
  18. package/dist/state-BytbdZ8s.js.map +1 -0
  19. package/dist/web.d.ts +96 -16
  20. package/dist/web.js +123 -12
  21. package/dist/web.js.map +1 -1
  22. package/examples/comfy-cloud/sdk.d.ts +163 -163
  23. package/examples/rvion/10-anima-t2i.cflow.ts +48 -25
  24. package/examples/rvion/11-yue2-t2a.cflow.ts +105 -0
  25. package/examples/rvion/12-stable-audio-3-t2a.cflow.ts +78 -0
  26. package/examples/rvion/13-ace-step-15-xl-t2a.cflow.ts +153 -0
  27. package/examples/rvion/stableAudio3Prompts.ts +19 -0
  28. package/package.json +2 -2
  29. package/src/cli/serve/ServeApp.ts +224 -77
  30. package/src/cli/serve/byteRange.ts +48 -0
  31. package/src/cli/serve/resultHistory.ts +125 -0
  32. package/src/cli/serve/run-serve.ts +12 -3
  33. package/src/cli/serve/runError.ts +23 -0
  34. package/src/cli/serve/serveSettings.ts +17 -1
  35. package/src/cli/serve/web/api.ts +53 -2
  36. package/src/cli/serve/web/components/App.tsx +311 -160
  37. package/src/cli/serve/web/components/DraftTabs.tsx +167 -0
  38. package/src/cli/serve/web/components/Gallery.tsx +75 -25
  39. package/src/cli/serve/web/components/Icon.tsx +44 -0
  40. package/src/cli/serve/web/components/MemoryBudget.tsx +98 -0
  41. package/src/cli/serve/web/components/Omnibox.tsx +70 -20
  42. package/src/cli/serve/web/components/RunError.tsx +19 -0
  43. package/src/cli/serve/web/components/ShortcutsModal.tsx +54 -0
  44. package/src/cli/serve/web/components/SideMenu.tsx +428 -0
  45. package/src/cli/serve/web/components/TooltipLayer.tsx +3 -2
  46. package/src/cli/serve/web/components/VarsForm.tsx +141 -404
  47. package/src/cli/serve/web/components/controls/BasicControls.tsx +8 -1
  48. package/src/cli/serve/web/components/controls/LorasControl.tsx +30 -25
  49. package/src/cli/serve/web/promptEditor/promptExtensions.ts +9 -4
  50. package/src/cli/serve/web/state/EnhancerSt.ts +17 -2
  51. package/src/cli/serve/web/state/FormSt.ts +22 -2
  52. package/src/cli/serve/web/state/OmniboxSt.ts +3 -1
  53. package/src/cli/serve/web/state/RunSt.ts +61 -3
  54. package/src/cli/serve/web/state/WebSt.ts +198 -35
  55. package/src/cli/serve/web/state/draftNames.ts +16 -0
  56. package/src/cli/serve/web/state/draftTabs.ts +75 -0
  57. package/src/cli/serve/web/state/formRows.ts +9 -0
  58. package/src/cli/serve/web/state/generateButton.ts +1 -1
  59. package/src/cli/serve/web/state/keptResults.ts +26 -0
  60. package/src/cli/serve/web/state/lightbox.ts +17 -0
  61. package/src/cli/serve/web/state/omnibox.ts +82 -18
  62. package/src/cli/serve/web/state/shortcutCatalog.ts +100 -0
  63. package/src/cli/serve/web/state/shortcuts.ts +66 -7
  64. package/src/cli/serve/web/styles.ts +327 -93
  65. package/src/cli/serve/workflowTags.ts +42 -0
  66. package/src/cli/serve/workspaceLabels.ts +23 -0
  67. package/src/cli/tui/state/DraftsSt.ts +10 -6
  68. package/src/coreExports.ts +1 -0
  69. package/src/host/ComfyHost.ts +17 -2
  70. package/src/host/ResilientWebsocket.ts +54 -4
  71. package/src/runner/ComfyExecution.ts +60 -0
  72. package/src/runner/ComfyWorkflow.ts +4 -0
  73. package/src/runner/ComfyWsApi.ts +2 -0
  74. package/src/runner/MediaImage.ts +2 -2
  75. package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +5 -5
  76. package/src/sdk-generator/comfyui-sdk-codegen.ts +1 -1
  77. package/src/utils/copyName.ts +12 -0
  78. package/src/vars/DefinedWorkflow.ts +7 -1
  79. package/dist/LogsSt-U1H0mP1m.js.map +0 -1
  80. package/dist/run-serve-BeAznay5.js.map +0 -1
  81. package/dist/state-C7REnHan.js.map +0 -1
@@ -57,7 +57,8 @@ export const NumberControl = observer(function NumberControl(p: { v: VarSt }) {
57
57
  {min != null && max != null ? (
58
58
  <input
59
59
  type="range"
60
- style={{ flex: 1, minWidth: 120 }}
60
+ className="num-range"
61
+ style={{ flex: 1, minWidth: 120, backgroundImage: rangeFill(num, min, max) }}
61
62
  value={num}
62
63
  min={min}
63
64
  max={max}
@@ -70,6 +71,12 @@ export const NumberControl = observer(function NumberControl(p: { v: VarSt }) {
70
71
  )
71
72
  })
72
73
 
74
+ // the accent up to the value, drawn on the input: the track itself is transparent
75
+ function rangeFill(num: number, min: number, max: number): string {
76
+ const pct = max > min ? ((Math.min(max, Math.max(min, num)) - min) / (max - min)) * 100 : 0
77
+ return `linear-gradient(90deg, var(--accent) ${pct}%, var(--border) ${pct}%)`
78
+ }
79
+
73
80
  export const ToggleControl = observer(function ToggleControl(p: { v: VarSt }) {
74
81
  return (
75
82
  <label className="row-inline" style={{ cursor: 'pointer' }}>
@@ -16,6 +16,7 @@ import { MenuButton, MenuItem } from 'src/cli/serve/web/components/MenuButton.ts
16
16
  import { logWebError } from 'src/cli/serve/web/logWeb.ts'
17
17
  import { observer, useLocalObservable } from 'mobx-react-lite'
18
18
  import { useEffect, useRef, useState, type DragEvent, type ReactNode } from 'react'
19
+ import { isNewJump } from 'src/cli/serve/web/state/shortcuts.ts'
19
20
  import { fetchLoraAbout, fetchLoraInfo, loraPreviewSrc, type LoraAbout, type LoraInfo } from 'src/cli/serve/web/api.ts'
20
21
  import type { LoraStrength } from 'src/vars/loraEntry.ts'
21
22
  import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
@@ -356,8 +357,8 @@ export const LorasControl = observer(function LorasControl(p: {
356
357
  </button>
357
358
  <input
358
359
  type="range"
359
- min={-1}
360
- max={2}
360
+ min={0}
361
+ max={1}
361
362
  step={0.05}
362
363
  value={value}
363
364
  onChange={(e) => write(which, parseFloat(e.target.value))}
@@ -392,8 +393,10 @@ export const LorasControl = observer(function LorasControl(p: {
392
393
  // ⌘O: a NEW jump opens the picker on the first section, as its own `add` would
393
394
  const jump = p.st.jump
394
395
  const firstIx = sections[0]?.ix ?? -1
396
+ const seenJump = useRef(jump?.seq ?? 0)
395
397
  useEffect(() => {
396
- if (!p.jumpTarget || jump == null || jump.kind !== 'loras') return
398
+ if (!p.jumpTarget || !isNewJump(jump, 'loras', seenJump.current)) return
399
+ seenJump.current = jump?.seq ?? 0
397
400
  local.openFor(firstIx)
398
401
  }, [jump, p.jumpTarget, firstIx, local])
399
402
 
@@ -459,11 +462,12 @@ export const LorasControl = observer(function LorasControl(p: {
459
462
  filterRef.current?.select()
460
463
  }
461
464
 
462
- // ONE size factor for every lora image (the slider): the palette card, its image, and the
463
- // popup's grid all follow it. 168/130 and 120/110 are the base card and image sizes
464
- const scale = p.st.loraScale
465
- const cardWidth = Math.round(168 * scale)
466
- const gridMin = Math.round(120 * scale)
465
+ // two size factors, each with its own slider: the form's cards follow formScale, the
466
+ // popup's grid follows popupScale. 168/130 and 120/110 are the base card and image sizes
467
+ const formScale = p.st.loraFormScale
468
+ const popupScale = p.st.loraPopupScale
469
+ const cardWidth = Math.round(168 * formScale)
470
+ const gridMin = Math.round(120 * popupScale)
467
471
  const thumb = (name: string, height?: number): ReactNode => {
468
472
  if (!showImages) return null
469
473
  const style = height == null ? undefined : { height }
@@ -491,19 +495,20 @@ export const LorasControl = observer(function LorasControl(p: {
491
495
  </span>
492
496
  )
493
497
 
494
- /** the image size, a small slider: only while images are shown */
495
- const sizeSlider = showImages ? (
496
- <input
497
- type="range"
498
- className="setting-range"
499
- min={0.6}
500
- max={2}
501
- step={0.05}
502
- value={scale}
503
- data-tip={`lora image size ×${scale.toFixed(2)}`}
504
- onChange={(e) => p.st.setLoraScale(parseFloat(e.target.value))}
505
- />
506
- ) : null
498
+ /** an image size, a small slider: only while images are shown */
499
+ const sizeSlider = (where: string, scale: number, set: (v: number) => void): ReactNode =>
500
+ showImages ? (
501
+ <input
502
+ type="range"
503
+ className="setting-range"
504
+ min={0.6}
505
+ max={2}
506
+ step={0.05}
507
+ value={scale}
508
+ data-tip={`lora image size in the ${where} ×${scale.toFixed(2)}`}
509
+ onChange={(e) => set(parseFloat(e.target.value))}
510
+ />
511
+ ) : null
507
512
 
508
513
  const visibilityToggles = (
509
514
  <>
@@ -577,7 +582,7 @@ export const LorasControl = observer(function LorasControl(p: {
577
582
  <label className="menu-item menu-range">
578
583
  <span className="menu-check" />
579
584
  size
580
- {sizeSlider}
585
+ {sizeSlider('form', formScale, (v) => p.st.setLoraFormScale(v))}
581
586
  </label>
582
587
  ) : null}
583
588
  <div className="menu-sep" />
@@ -735,7 +740,7 @@ export const LorasControl = observer(function LorasControl(p: {
735
740
  data-tip={`${name}\nclick to ${isOn(sec, name) ? 'pause' : 'resume'}, click the title for details`}
736
741
  onClick={() => toggleOn(sec, name, !isOn(sec, name))}
737
742
  >
738
- {thumb(name, Math.round(130 * scale))}
743
+ {thumb(name, Math.round(130 * formScale))}
739
744
  {showImages && !isOn(sec, name) ? pausedMark : null}
740
745
  </button>
741
746
  <button
@@ -836,7 +841,7 @@ export const LorasControl = observer(function LorasControl(p: {
836
841
  {/* the display toggles first, the search in the middle, close alone at the end */}
837
842
  <div className="modal-head">
838
843
  <span className="btn-group">{visibilityToggles}</span>
839
- {sizeSlider}
844
+ {sizeSlider('popup', popupScale, (v) => p.st.setLoraPopupScale(v))}
840
845
  <input
841
846
  ref={filterRef}
842
847
  type="text"
@@ -961,7 +966,7 @@ export const LorasControl = observer(function LorasControl(p: {
961
966
  }}
962
967
  >
963
968
  <span className="thumb-box">
964
- {thumb(name, Math.round(110 * scale))}
969
+ {thumb(name, Math.round(110 * popupScale))}
965
970
  {showImages && picked && !on ? pausedMark : null}
966
971
  </span>
967
972
  <div className="lora-label">
@@ -153,8 +153,11 @@ function applyTag(insert: string): Completion['apply'] {
153
153
  }
154
154
  }
155
155
 
156
- /** the options for one search text: lora words containing it, then the tag list's hits */
157
- async function optionsFor(c: PromptEditorCtx, text: string, signal: AbortSignal): Promise<Completion[]> {
156
+ /** the options for one search text: lora words containing it, then the tag list's hits. Only
157
+ * for a prompt that declares a tag list (v.prompt(…, { tags })): completion is opt in per
158
+ * workflow, the loras words included */
159
+ export async function optionsFor(c: PromptEditorCtx, text: string, signal: AbortSignal): Promise<Completion[]> {
160
+ if (c.tags == null) return []
158
161
  const q = text.trim().toLowerCase()
159
162
  const options: Completion[] = []
160
163
  const seenWords = new Set<string>()
@@ -164,7 +167,7 @@ async function optionsFor(c: PromptEditorCtx, text: string, signal: AbortSignal)
164
167
  seenWords.add(lower)
165
168
  options.push({ label: w.word, detail: w.source, type: 'lora', boost: 50, apply: applyTag(w.word) })
166
169
  }
167
- if (c.tags == null || q === '') return options
170
+ if (q === '') return options
168
171
  const hits = await c.searchTags(text.trim(), signal)
169
172
  c.onTagError(null)
170
173
  hits.forEach((h, ix) => {
@@ -221,8 +224,10 @@ const theme = EditorView.theme(
221
224
  '.cm-content': { padding: '6px 0', caretColor: 'var(--text)' },
222
225
  '.cm-line': { padding: '0 8px' },
223
226
  '.cm-cursor': { borderLeftColor: 'var(--text)' },
227
+ // opaque on purpose: webkit blends a translucent selection down to near the background
224
228
  '&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection': {
225
- background: 'var(--accent-dim) !important',
229
+ background: '#c3d1f4 !important',
230
+ color: '#000 !important',
226
231
  },
227
232
  '.cm-placeholder': { color: 'var(--dim)' },
228
233
  '.pe-comment': { color: 'var(--dim)', fontStyle: 'italic' },
@@ -7,6 +7,7 @@
7
7
  // normalizeSettings/nextPresetName are PURE and headless-tested.
8
8
  import { makeAutoObservable, reaction, runInAction, type IReactionDisposer } from 'mobx'
9
9
  import { stringMap } from 'src/utils/stringMap.ts'
10
+ import { copyName } from 'src/utils/copyName.ts'
10
11
  import {
11
12
  deleteLlmConfig,
12
13
  deletePromptEnhancer,
@@ -405,7 +406,14 @@ export class EnhancerSt {
405
406
 
406
407
  duplicateConfig(): void {
407
408
  const c = this.configEntry
408
- if (c != null) this.addConfig(`${c.name} copy`, c.config)
409
+ if (c != null)
410
+ this.addConfig(
411
+ copyName(
412
+ c.name,
413
+ this.configs.map((x) => x.name),
414
+ ),
415
+ c.config,
416
+ )
409
417
  }
410
418
 
411
419
  /** rename = write the new file, delete the old one (the filename IS the identity) */
@@ -568,7 +576,14 @@ export class EnhancerSt {
568
576
 
569
577
  duplicatePreset(): void {
570
578
  const p = this.preset
571
- if (p != null) this.addPreset(`${p.name} copy`, p.text)
579
+ if (p != null)
580
+ this.addPreset(
581
+ copyName(
582
+ p.name,
583
+ this.presets.map((x) => x.name),
584
+ ),
585
+ p.text,
586
+ )
572
587
  }
573
588
 
574
589
  /** rename = write the new file, delete the old one (the filename IS the identity) */
@@ -52,6 +52,21 @@ export class VarSt {
52
52
  this.uploadedUrl = url
53
53
  }
54
54
 
55
+ /** the workflow's declared default, in the shape the controls hold */
56
+ get defaultValue(): unknown {
57
+ return normalizeInitial(this.desc, this.desc.default)
58
+ }
59
+
60
+ /** by value: a size or a choice list is a fresh object every time */
61
+ get isAtDefault(): boolean {
62
+ return JSON.stringify(this.value) === JSON.stringify(this.defaultValue)
63
+ }
64
+
65
+ /** back to what the workflow declares; an edit like any other (autosaved, revertable) */
66
+ resetToDefault(): void {
67
+ this.set(this.defaultValue)
68
+ }
69
+
55
70
  revert(): void {
56
71
  this.value = this.initial
57
72
  this.dirty = false
@@ -76,7 +91,7 @@ export class FormSt {
76
91
  private disposers: IReactionDisposer[] = []
77
92
  /** saves are chained so two PUTs can never land out of order */
78
93
  private saveChain: Promise<boolean> = Promise.resolve(true)
79
- /** the values json the server last CONFIRMED — what is really on disk */
94
+ /** the values json the server last CONFIRMED — what is really on disk. Observable: `unsaved` reads it */
80
95
  private lastSaved: string
81
96
  /** the values json last HANDED to the chain, confirmed or still in flight. save() no-ops
82
97
  * against this one, never against lastSaved: while a PUT is open the disk does not hold
@@ -120,7 +135,7 @@ export class FormSt {
120
135
  host: false,
121
136
  disposers: false,
122
137
  saveChain: false,
123
- lastSaved: false,
138
+ lastSaved: true,
124
139
  lastQueued: false,
125
140
  queueSeq: false,
126
141
  onSettled: false,
@@ -348,6 +363,11 @@ export class FormSt {
348
363
  found.source.set(updateLora(found.value, lora, withLora(loraSetting(found.value, lora), { mute })))
349
364
  }
350
365
 
366
+ /** the values on screen are not on disk yet: inside the autosave debounce, or a PUT still open */
367
+ get unsaved(): boolean {
368
+ return JSON.stringify(this.valuesJSON()) !== this.lastSaved
369
+ }
370
+
351
371
  get dirtyCount(): number {
352
372
  return this.vars.filter((v) => v.dirty).length
353
373
  }
@@ -25,7 +25,9 @@ export class OmniboxSt {
25
25
  const ix =
26
26
  current == null
27
27
  ? -1
28
- : this.results.findIndex((e) => e.module === current.moduleKey && e.draft === current.draft)
28
+ : this.results.findIndex(
29
+ (e) => e.kind === 'draft' && e.module === current.moduleKey && e.draft === current.draft,
30
+ )
29
31
  this.cursor = Math.max(0, ix)
30
32
  }
31
33
 
@@ -3,10 +3,23 @@
3
3
  // ever reaches the host: queued prompts must be clearable, singly or
4
4
  // all). Progress + latent preview are polled ~700ms while a prompt is in flight
5
5
  import { makeAutoObservable, observableShallow, runInAction } from 'mobx'
6
- import { fetchRunStatus, postGenerate, type GenerateOk } from 'src/cli/serve/web/api.ts'
6
+ import {
7
+ deleteKeptResults,
8
+ fetchKeptResults,
9
+ fetchRunStatus,
10
+ postGenerate,
11
+ type GenerateOk,
12
+ type MemoryUsage,
13
+ } from 'src/cli/serve/web/api.ts'
14
+ import { mergeKept } from 'src/cli/serve/web/state/keptResults.ts'
15
+ import { logWebError } from 'src/cli/serve/web/logWeb.ts'
7
16
 
8
17
  export type RunResult = GenerateOk & { at: string }
9
18
 
19
+ function asRunResult(r: GenerateOk): RunResult {
20
+ return { ...r, at: new Date(r.finishedAt ?? Date.now()).toLocaleTimeString() }
21
+ }
22
+
10
23
  /** one enqueued prompt. `sent` marks the one on the host — that one is past cancelling */
11
24
  export type QueueEntry = {
12
25
  id: string
@@ -24,6 +37,8 @@ export class RunSt {
24
37
  queue: QueueEntry[] = []
25
38
  error: string | null = null
26
39
  results: RunResult[] = []
40
+ /** the serve process's unsaved outputs against its budget. null = not read yet */
41
+ memory: MemoryUsage | null = null
27
42
  progressPercent: number | null = null
28
43
  /** what the host is doing right now, in the node's own unit — `TextGenerate 427/1024`.
29
44
  * A text graph has no latent preview and no image, so this is all there is to watch */
@@ -71,16 +86,58 @@ export class RunSt {
71
86
  this.queue = this.queue.filter((e) => e.id !== id || e.sent)
72
87
  }
73
88
 
89
+ dismissError(): void {
90
+ this.error = null
91
+ }
92
+
74
93
  clearQueue(): void {
75
94
  this.queue = this.queue.filter((e) => e.sent)
76
95
  }
77
96
 
97
+ /** the server forgets it too: a reload must not bring back what was removed */
78
98
  remove(promptId: string): void {
79
99
  this.results = this.results.filter((r) => r.promptId !== promptId)
100
+ void this.forget({ promptId })
80
101
  }
81
102
 
82
103
  clear(): void {
83
104
  this.results = []
105
+ void this.forget({})
106
+ }
107
+
108
+ /** what the serve process kept: the last runs survive a page reload */
109
+ async loadKept(): Promise<void> {
110
+ try {
111
+ const kept = await fetchKeptResults()
112
+ runInAction(() => {
113
+ this.results = mergeKept(this.results, kept.runs.map(asRunResult))
114
+ this.memory = kept.memory
115
+ })
116
+ } catch (e) {
117
+ logWebError('could not read the kept results', e)
118
+ }
119
+ }
120
+
121
+ async refreshMemory(): Promise<void> {
122
+ try {
123
+ const kept = await fetchKeptResults()
124
+ runInAction(() => {
125
+ this.memory = kept.memory
126
+ })
127
+ } catch (e) {
128
+ logWebError('could not read the memory usage', e)
129
+ }
130
+ }
131
+
132
+ private async forget(p: { promptId?: string }): Promise<void> {
133
+ try {
134
+ const reply = await deleteKeptResults(p)
135
+ runInAction(() => {
136
+ this.memory = reply.memory
137
+ })
138
+ } catch (e) {
139
+ logWebError('could not delete the kept result', e)
140
+ }
84
141
  }
85
142
 
86
143
  /** one prompt at a time: a queued entry stays cancellable until its turn comes */
@@ -105,9 +162,10 @@ export class RunSt {
105
162
  try {
106
163
  const result = await postGenerate(next)
107
164
  runInAction(() => {
108
- // capped: full-size <img>s per run would eat the tab
109
- this.results = [{ ...result, at: new Date().toLocaleTimeString() }, ...this.results].slice(0, 20)
165
+ // capped like the server's list: full-size <img>s per run would eat the tab
166
+ this.results = mergeKept([asRunResult(result)], this.results)
110
167
  })
168
+ void this.refreshMemory()
111
169
  // named, because the panel may be on another draft by the time this resolves
112
170
  this.onSeeds?.({ module: next.module, draft: next.draft, seeds: result.seeds })
113
171
  } catch (e) {