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
@@ -4,12 +4,13 @@ import { statSync } from 'node:fs'
4
4
  import { createServer, type IncomingMessage, type ServerResponse } from 'node:http'
5
5
  import { networkInterfaces } from 'node:os'
6
6
  import { pathToFileURL } from 'node:url'
7
- import { resolve } from 'pathe'
7
+ import { dirname, resolve } from 'pathe'
8
8
  import { scanCflowFiles } from 'src/cli/tui/discoverWorkflows.ts'
9
9
  import { findDefinedWorkflow } from 'src/cli/tui/findDefinedWorkflow.ts'
10
10
  import { draftKeyForFile } from 'src/cli/tui/state/DraftsSt.ts'
11
11
  import { describeVar, renderDescriptorLine } from 'src/cli/serve/describeVar.ts'
12
12
  import { ServeApp, type ServeModule } from 'src/cli/serve/ServeApp.ts'
13
+ import { withByteRange } from 'src/cli/serve/byteRange.ts'
13
14
  import { renderStartupLines } from 'src/cli/serve/startupPrint.ts'
14
15
  import { loadOrBuildWebJs } from 'src/cli/serve/webBundle.ts'
15
16
  import { colorsAvailable } from 'src/utils/ansi.ts'
@@ -82,7 +83,9 @@ export function makeRequestListener(app: ServeApp): (req: IncomingMessage, res:
82
83
  accept: req.headers.accept,
83
84
  body: Buffer.concat(chunks).toString('utf8'),
84
85
  })
85
- .then((reply) => {
86
+ .then((whole) => {
87
+ const range = req.headers.range
88
+ const reply = withByteRange(whole, { method: req.method ?? 'GET', range })
86
89
  res.writeHead(reply.status, { 'content-type': reply.contentType, ...reply.headers, ...cors })
87
90
  res.end(reply.body)
88
91
  })
@@ -138,7 +141,13 @@ export async function runServe(args: string[]): Promise<number> {
138
141
  return 1
139
142
  }
140
143
 
141
- const app = new ServeApp(modules, { loadErrors, webJs: loadOrBuildWebJs })
144
+ const app = new ServeApp(modules, {
145
+ loadErrors,
146
+ webJs: loadOrBuildWebJs,
147
+ // the modules registered comfyts on import: its root holds `.comfy-ts/`
148
+ workspace: typeof comfyts === 'undefined' ? process.cwd() : comfyts.rootPath,
149
+ root: statSync(target).isDirectory() ? target : dirname(target),
150
+ })
142
151
  printStartup(app, parsed.bind, parsed.port)
143
152
 
144
153
  const server = createServer(makeRequestListener(app))
@@ -0,0 +1,23 @@
1
+ // a failed run's error as ONE readable line. ComfyExecution stores ComfyUI's whole
2
+ // execution_error message; every client reads `error` as text
3
+ export function describeRunError(error: unknown): string {
4
+ if (error == null) return 'execution failed'
5
+ if (typeof error === 'string') return error
6
+ if (error instanceof Error) return error.message
7
+ if (typeof error === 'object') {
8
+ const data = (error as { data?: unknown }).data
9
+ if (typeof data === 'object' && data !== null) {
10
+ const d = data as Record<string, unknown>
11
+ if (typeof d.exception_message === 'string') {
12
+ const where = typeof d.node_type === 'string' ? `${d.node_type} (node ${String(d.node_id)}): ` : ''
13
+ const kind = typeof d.exception_type === 'string' && d.exception_type !== '' ? `${d.exception_type}: ` : ''
14
+ return `${where}${kind}${d.exception_message.trim()}`
15
+ }
16
+ }
17
+ }
18
+ try {
19
+ return JSON.stringify(error)
20
+ } catch {
21
+ return String(error)
22
+ }
23
+ }
@@ -7,6 +7,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
7
7
  import { stringMap } from 'src/utils/stringMap.ts'
8
8
  import { validSavePrefix } from 'src/utils/safeName.ts'
9
9
  import { dirname } from 'pathe'
10
+ import { DEFAULT_MEMORY_BUDGET_MB } from 'src/cli/serve/resultHistory.ts'
10
11
 
11
12
  export type ServeSettings = {
12
13
  /** false = generations stay in memory, streamed to the client, nothing written to outputs/ */
@@ -17,9 +18,23 @@ export type ServeSettings = {
17
18
  /** module key → subfolder under outputs/ its images land in. Empty/absent = the module key,
18
19
  * which is what serve always used before it was choosable */
19
20
  savePrefix: Record<string, string>
21
+ /** byte budget of the unsaved outputs the process keeps for a reload, oldest dropped first */
22
+ memoryBudgetMb: number
20
23
  }
21
24
 
22
- const DEFAULT_SERVE_SETTINGS: ServeSettings = { saveToDisk: true, hostOverride: {}, savePrefix: {} }
25
+ const DEFAULT_SERVE_SETTINGS: ServeSettings = {
26
+ saveToDisk: true,
27
+ hostOverride: {},
28
+ savePrefix: {},
29
+ memoryBudgetMb: DEFAULT_MEMORY_BUDGET_MB,
30
+ }
31
+
32
+ /** null = not a budget. A hand-written file goes through the same gate as PUT /settings */
33
+ export function validMemoryBudgetMb(raw: unknown): number | null {
34
+ if (typeof raw !== 'number' || !Number.isFinite(raw)) return null
35
+ if (raw < 1 || raw > 100_000) return null
36
+ return Math.round(raw)
37
+ }
23
38
 
24
39
  /** null when no comfyts is registered yet: a ServeApp can be constructed before the global
25
40
  * exists (tests do), and reading a setting must degrade to defaults, never throw */
@@ -69,6 +84,7 @@ export function readServeSettings(): ServeSettings {
69
84
  // hand-written file did not go through that route, and this value becomes an output
70
85
  // directory. One gate on one side is not a gate
71
86
  savePrefix: cleanValues(stringMap(o.savePrefix), validSavePrefix),
87
+ memoryBudgetMb: validMemoryBudgetMb(o.memoryBudgetMb) ?? DEFAULT_SERVE_SETTINGS.memoryBudgetMb,
72
88
  }
73
89
  }
74
90
 
@@ -10,10 +10,17 @@ export type ModuleDescription = {
10
10
  vars: Record<string, VarDescriptor>
11
11
  /** names of the workflow's live previews (POST /preview/<module>) */
12
12
  previews?: string[]
13
+ /** search tags: what the graph outputs (image, audio, video, text), llm, edit, then free tags */
14
+ tags?: string[]
13
15
  }
14
16
 
17
+ export type PathLabel = { path: string; label: string }
18
+
15
19
  export type IndexPayload = {
16
20
  workflows: ModuleDescription[]
21
+ /** where `.comfy-ts/` lives, and the folder serve scanned */
22
+ workspace?: PathLabel
23
+ root?: PathLabel
17
24
  loadErrors?: Record<string, string>
18
25
  }
19
26
 
@@ -22,6 +29,9 @@ export type GeneratedImage = { filename: string; url: string | null; absPath: st
22
29
  /** a STRING output (PreviewAny). An llm graph produces these and no images at all */
23
30
  export type GeneratedText = { nodeKey: string | null; text: string }
24
31
 
32
+ /** an audio file (SaveAudio*, PreviewAudio): the panel plays it in an <audio> player */
33
+ export type GeneratedAudio = { filename: string; mime: string; url: string | null; absPath: string | null }
34
+
25
35
  export type GenerateOk = {
26
36
  ok: true
27
37
  module: string
@@ -29,14 +39,23 @@ export type GenerateOk = {
29
39
  promptId: string
30
40
  durationMs: number
31
41
  seeds: Record<string, number>
42
+ /** epoch ms, stamped by the server */
43
+ finishedAt?: number
32
44
  images: GeneratedImage[]
33
45
  texts?: GeneratedText[]
46
+ audios?: GeneratedAudio[]
34
47
  }
35
48
 
36
49
  async function jsonFetch<T>(url: string, init?: RequestInit): Promise<T> {
37
50
  const res = await fetch(url, init)
38
51
  const body = (await res.json().catch(() => null)) as (T & { error?: string }) | null
39
- if (!res.ok || body == null) throw new Error(body?.error ?? `http ${res.status} on ${url}`)
52
+ if (!res.ok || body == null) {
53
+ // a non-string error would print as "[object Object]"
54
+ const error: unknown = body?.error
55
+ throw new Error(
56
+ typeof error === 'string' ? error : error != null ? JSON.stringify(error) : `http ${res.status} on ${url}`,
57
+ )
58
+ }
40
59
  return body
41
60
  }
42
61
 
@@ -60,6 +79,20 @@ export function postGenerate(p: {
60
79
  })
61
80
  }
62
81
 
82
+ /** the unsaved outputs the serve process holds, against its byte budget */
83
+ export type MemoryUsage = { usedBytes: number; budgetBytes: number; outputs: number; runs: number }
84
+
85
+ /** the last runs the serve process kept: a reload shows them again */
86
+ export function fetchKeptResults(): Promise<{ runs: GenerateOk[]; memory: MemoryUsage }> {
87
+ return jsonFetch('/results')
88
+ }
89
+
90
+ /** no promptId = every kept run */
91
+ export function deleteKeptResults(p: { promptId?: string } = {}): Promise<{ memory: MemoryUsage }> {
92
+ const url = p.promptId == null ? '/results' : `/results/${encodeURIComponent(p.promptId)}`
93
+ return jsonFetch(url, { method: 'DELETE' })
94
+ }
95
+
63
96
  /** the workflow's previews for these values: nothing runs, nothing is written */
64
97
  export function fetchPreviews(p: {
65
98
  module: string
@@ -87,6 +120,19 @@ export function saveDraft(
87
120
  })
88
121
  }
89
122
 
123
+ /** the open draft tabs: the serve process keeps them, so every window shows the same ones */
124
+ export function fetchTabs(): Promise<{ tabs: unknown }> {
125
+ return jsonFetch('/tabs')
126
+ }
127
+
128
+ export function saveTabs(tabs: readonly { module: string; draft: string }[]): Promise<{ tabs: unknown }> {
129
+ return jsonFetch('/tabs', {
130
+ method: 'PUT',
131
+ headers: { 'content-type': 'application/json' },
132
+ body: JSON.stringify({ tabs }),
133
+ })
134
+ }
135
+
90
136
  export function deleteDraft(p: { module: string; draft: string }): Promise<{ ok: true; drafts: string[] }> {
91
137
  return jsonFetch(`/drafts/${encodeURIComponent(p.module)}/${encodeURIComponent(p.draft)}`, { method: 'DELETE' })
92
138
  }
@@ -157,6 +203,7 @@ export type ServeSettings = {
157
203
  saveToDisk: boolean
158
204
  hostOverride: Record<string, string>
159
205
  savePrefix: Record<string, string>
206
+ memoryBudgetMb: number
160
207
  effectivePrefix: Record<string, string>
161
208
  }
162
209
 
@@ -164,7 +211,11 @@ export function fetchSettings(): Promise<ServeSettings> {
164
211
  return jsonFetch('/settings')
165
212
  }
166
213
 
167
- export function saveSettings(p: { saveToDisk?: boolean; savePrefix?: Record<string, string> }): Promise<ServeSettings> {
214
+ export function saveSettings(p: {
215
+ saveToDisk?: boolean
216
+ savePrefix?: Record<string, string>
217
+ memoryBudgetMb?: number
218
+ }): Promise<ServeSettings> {
168
219
  return jsonFetch('/settings', {
169
220
  method: 'PUT',
170
221
  headers: { 'content-type': 'application/json' },