comfy-ts 2.23.0 → 2.24.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 (76) hide show
  1. package/dist/{ServeApp-DolRCMHj.js → ServeApp-fsHtW5zG.js} +3 -3
  2. package/dist/{ServeApp-DolRCMHj.js.map → ServeApp-fsHtW5zG.js.map} +1 -1
  3. package/dist/cli.js +5 -5
  4. package/dist/{exampleAssets-Duneoq6r.js → exampleAssets-DZynSkZm.js} +79 -15
  5. package/dist/exampleAssets-DZynSkZm.js.map +1 -0
  6. package/dist/{findDefinedWorkflow-DjoJA8y7.js → findDefinedWorkflow-qyqFea7q.js} +2 -2
  7. package/dist/{findDefinedWorkflow-DjoJA8y7.js.map → findDefinedWorkflow-qyqFea7q.js.map} +1 -1
  8. package/dist/index.cjs +80 -14
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +53 -19
  11. package/dist/index.d.ts +53 -19
  12. package/dist/index.js +80 -15
  13. package/dist/index.js.map +1 -1
  14. package/dist/{run-run-Cr0L9lCK.js → run-run-Cn2JzKlE.js} +5 -5
  15. package/dist/{run-run-Cr0L9lCK.js.map → run-run-Cn2JzKlE.js.map} +1 -1
  16. package/dist/{run-serve---qA7o_m.js → run-serve-BhGegaCI.js} +4 -4
  17. package/dist/{run-serve---qA7o_m.js.map → run-serve-BhGegaCI.js.map} +1 -1
  18. package/dist/{run-tui-DxXiWo5J.js → run-tui-CrM4ijkH.js} +4 -4
  19. package/dist/{run-tui-DxXiWo5J.js.map → run-tui-CrM4ijkH.js.map} +1 -1
  20. package/dist/{schemaDrift-BTxdABHi.js → schemaDrift-BGYJZGMD.js} +3 -2
  21. package/dist/{schemaDrift-BTxdABHi.js.map → schemaDrift-BGYJZGMD.js.map} +1 -1
  22. package/dist/web.d.ts +53 -19
  23. package/dist/web.js +80 -15
  24. package/dist/web.js.map +1 -1
  25. package/examples/README.md +1 -0
  26. package/examples/depth-explorer/models.ts +6 -56
  27. package/examples/depth-explorer/serve.ts +12 -133
  28. package/examples/depth-explorer/web/App.tsx +20 -91
  29. package/examples/depth-explorer/web/index.html +1 -0
  30. package/examples/depth-explorer/web/state.ts +26 -109
  31. package/examples/depth-explorer/web/styles.css +1 -286
  32. package/examples/explorer-kit/catalog.ts +80 -0
  33. package/examples/explorer-kit/server.ts +167 -0
  34. package/examples/explorer-kit/web/base.css +289 -0
  35. package/examples/explorer-kit/web/runs.ts +160 -0
  36. package/examples/explorer-kit/web/ui.tsx +125 -0
  37. package/examples/rvion/17-relight.cflow.ts +2 -1
  38. package/examples/rvion/19-flythrough.cflow.ts +312 -0
  39. package/examples/rvion/20-grow-splat.cflow.ts +88 -0
  40. package/examples/rvion/21-photo-to-model.cflow.ts +191 -0
  41. package/examples/rvion/flythroughChain.ts +171 -0
  42. package/examples/rvion/flythroughColmap.ts +157 -0
  43. package/examples/rvion/flythroughFuse.ts +199 -0
  44. package/examples/rvion/flythroughGuide.ts +300 -0
  45. package/examples/rvion/flythroughPalette.ts +310 -0
  46. package/examples/rvion/flythroughPath.ts +177 -0
  47. package/examples/rvion/flythroughSplat.ts +73 -0
  48. package/examples/rvion/grow-splat/align.ts +114 -0
  49. package/examples/rvion/grow-splat/grow.ts +198 -0
  50. package/examples/rvion/grow-splat/ply.ts +166 -0
  51. package/examples/rvion/grow-splat/raster.ts +207 -0
  52. package/examples/rvion/grow-splat/sharp.ts +45 -0
  53. package/examples/rvion/splatDataset.ts +80 -0
  54. package/examples/rvion/splatEval.ts +380 -0
  55. package/examples/upscale-explorer/models.ts +341 -0
  56. package/examples/upscale-explorer/serve.ts +19 -0
  57. package/examples/upscale-explorer/web/App.tsx +250 -0
  58. package/examples/upscale-explorer/web/compare.tsx +285 -0
  59. package/examples/upscale-explorer/web/index.html +15 -0
  60. package/examples/upscale-explorer/web/main.tsx +12 -0
  61. package/examples/upscale-explorer/web/state.ts +279 -0
  62. package/examples/upscale-explorer/web/styles.css +241 -0
  63. package/examples/upscale-explorer/web/tsconfig.json +16 -0
  64. package/examples/upscale-explorer/web/viewport.tsx +130 -0
  65. package/examples/world-explorer/web/main.tsx +2 -2
  66. package/package.json +4 -3
  67. package/src/coreExports.ts +5 -0
  68. package/src/host/ComfyHost.ts +6 -0
  69. package/src/runner/ComfyExecution.ts +22 -5
  70. package/src/runner/ComfyWorkflow.ts +22 -0
  71. package/src/runner/ComfyWsApi.ts +1 -1
  72. package/src/runner/comfyOrgApiKey.ts +44 -0
  73. package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +2 -0
  74. package/src/state.ts +2 -0
  75. package/src/vars/DefinedWorkflow.ts +1 -0
  76. package/dist/exampleAssets-Duneoq6r.js.map +0 -1
@@ -0,0 +1,241 @@
1
+ /* the upscale explorer over the shared explorer look (examples/explorer-kit/web/base.css) */
2
+ :root {
3
+ --before: #ff6b6b;
4
+ --after: #4cd07d;
5
+ }
6
+ .toolbar {
7
+ display: flex;
8
+ align-items: center;
9
+ gap: 12px;
10
+ margin-bottom: 14px;
11
+ flex-wrap: wrap;
12
+ }
13
+ .toolbar > .seg {
14
+ width: auto;
15
+ }
16
+ .frame > img {
17
+ width: 100%;
18
+ height: 100%;
19
+ object-fit: contain;
20
+ display: block;
21
+ }
22
+ .facts {
23
+ display: flex;
24
+ flex-wrap: wrap;
25
+ gap: 4px;
26
+ padding: 8px 10px 0;
27
+ }
28
+ .chip {
29
+ font-size: 11px;
30
+ padding: 1px 6px;
31
+ border-radius: 4px;
32
+ background: var(--bg);
33
+ border: 1px solid var(--line);
34
+ color: var(--dim);
35
+ }
36
+ .chip.out {
37
+ color: var(--text);
38
+ }
39
+
40
+ /* a frame on the shared view */
41
+ .viewport {
42
+ position: relative;
43
+ overflow: hidden;
44
+ background: #0c0d0f;
45
+ cursor: grab;
46
+ touch-action: none;
47
+ user-select: none;
48
+ }
49
+ .viewport:active {
50
+ cursor: grabbing;
51
+ }
52
+ .layer {
53
+ position: absolute;
54
+ max-width: none;
55
+ display: block;
56
+ pointer-events: none;
57
+ }
58
+ .layer.px {
59
+ image-rendering: pixelated;
60
+ }
61
+ .fill {
62
+ position: absolute;
63
+ inset: 0;
64
+ }
65
+
66
+ /* the loupe */
67
+ .loupe {
68
+ display: grid;
69
+ gap: 12px;
70
+ }
71
+ .tile {
72
+ background: var(--card);
73
+ border: 1px solid var(--line);
74
+ border-radius: 8px;
75
+ overflow: hidden;
76
+ }
77
+ .tileHead {
78
+ display: flex;
79
+ justify-content: space-between;
80
+ gap: 8px;
81
+ padding: 6px 10px;
82
+ cursor: pointer;
83
+ }
84
+ .tileHead:hover .name {
85
+ color: var(--accent);
86
+ }
87
+ .tileView {
88
+ aspect-ratio: 1;
89
+ }
90
+ .nav {
91
+ position: relative;
92
+ cursor: crosshair;
93
+ touch-action: none;
94
+ border-radius: 6px;
95
+ overflow: hidden;
96
+ }
97
+ .nav img {
98
+ display: block;
99
+ width: 100%;
100
+ height: 100%;
101
+ }
102
+ .navBox {
103
+ position: absolute;
104
+ border: 2px solid var(--accent);
105
+ box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
106
+ pointer-events: none;
107
+ min-width: 4px;
108
+ min-height: 4px;
109
+ }
110
+
111
+ /* the compared pair, over the page */
112
+ .pair {
113
+ position: fixed;
114
+ inset: 0;
115
+ z-index: 10;
116
+ background: var(--bg);
117
+ display: flex;
118
+ flex-direction: column;
119
+ }
120
+ .pairBar {
121
+ display: flex;
122
+ align-items: center;
123
+ gap: 8px;
124
+ padding: 8px 12px;
125
+ border-bottom: 1px solid var(--line);
126
+ flex-wrap: wrap;
127
+ }
128
+ .pairBar select {
129
+ max-width: 240px;
130
+ }
131
+ .pairBar .meta {
132
+ margin-left: auto;
133
+ }
134
+ .modes {
135
+ display: flex;
136
+ align-items: center;
137
+ gap: 6px;
138
+ }
139
+ .modes .seg button {
140
+ font-size: 15px;
141
+ padding: 2px 9px;
142
+ }
143
+ kbd {
144
+ font: 11px ui-monospace, monospace;
145
+ border: 1px solid var(--line);
146
+ border-radius: 4px;
147
+ padding: 1px 5px;
148
+ color: var(--dim);
149
+ }
150
+ .zoombar {
151
+ display: inline-flex;
152
+ align-items: center;
153
+ gap: 4px;
154
+ }
155
+ .zoombar button {
156
+ padding: 3px 8px;
157
+ }
158
+ .zoombar button.on {
159
+ border-color: var(--accent);
160
+ }
161
+ .zoompct {
162
+ min-width: 54px;
163
+ text-align: center;
164
+ font-variant-numeric: tabular-nums;
165
+ }
166
+ .stage {
167
+ flex: 1;
168
+ min-height: 0;
169
+ display: flex;
170
+ flex-direction: column;
171
+ padding: 10px;
172
+ gap: 6px;
173
+ }
174
+ .stage.side {
175
+ flex-direction: row;
176
+ }
177
+ .cell {
178
+ position: relative;
179
+ flex: 1;
180
+ min-height: 0;
181
+ min-width: 0;
182
+ display: flex;
183
+ }
184
+ .cell > .viewport {
185
+ flex: 1;
186
+ border-radius: 6px;
187
+ }
188
+ .viewport.side-before {
189
+ outline: 2px solid var(--before);
190
+ outline-offset: -2px;
191
+ }
192
+ .viewport.side-after {
193
+ outline: 2px solid var(--after);
194
+ outline-offset: -2px;
195
+ }
196
+ .sidetag {
197
+ position: absolute;
198
+ top: 8px;
199
+ right: 8px;
200
+ padding: 2px 8px;
201
+ border-radius: 4px;
202
+ font-size: 12px;
203
+ color: #0b1220;
204
+ pointer-events: none;
205
+ }
206
+ .sidetag.left {
207
+ right: auto;
208
+ left: 8px;
209
+ }
210
+ .sidetag.before {
211
+ background: var(--before);
212
+ }
213
+ .sidetag.after {
214
+ background: var(--after);
215
+ }
216
+ .curtain {
217
+ position: absolute;
218
+ top: 0;
219
+ bottom: 0;
220
+ width: 2px;
221
+ transform: translateX(-1px);
222
+ background: #fff;
223
+ box-shadow: 0 0 6px rgba(0, 0, 0, 0.7);
224
+ cursor: ew-resize;
225
+ pointer-events: none;
226
+ }
227
+ .caption {
228
+ color: var(--dim);
229
+ font-size: 12px;
230
+ text-align: center;
231
+ }
232
+ .keys {
233
+ padding: 0 12px 8px;
234
+ text-align: center;
235
+ }
236
+ aside label.first {
237
+ margin-top: 0;
238
+ }
239
+ .nav {
240
+ margin-bottom: 16px;
241
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ // the upscale explorer page: dom-typed like examples/web, so it keeps its own config; the
3
+ // explorer kit's web files come in through its imports
4
+ "extends": "../../../tsconfig.json",
5
+ "compilerOptions": {
6
+ "lib": ["ESNext", "DOM", "DOM.Iterable"],
7
+ "paths": {
8
+ "src/*": ["../../../src/*"],
9
+ "comfy-ts": ["../../../src/index.ts"]
10
+ },
11
+ "tsBuildInfoFile": "../../../node_modules/.cache/tsbuildinfo-upscale-explorer-web.json"
12
+ },
13
+ // MUST override the root's exclude, which lists this directory
14
+ "exclude": ["../../web"],
15
+ "include": ["."]
16
+ }
@@ -0,0 +1,130 @@
1
+ // a frame on the shared view: every picture inside it is drawn at the results' pixel size, placed by
2
+ // the view's centre and zoom, so every frame of the page shows the same crop. The wheel or a pinch
3
+ // zooms around the pointer, a drag pans, a double click goes from the whole image to 100 % where it
4
+ // landed and back.
5
+ import { observer } from 'mobx-react-lite'
6
+ import { useEffect, useRef, useState, type ReactNode } from 'react'
7
+ import type { AppSt } from './state.ts'
8
+
9
+ /** where the image sits in its frame, css px, and its zoom (device pixels per image pixel) */
10
+ export type Box = { left: number; top: number; width: number; height: number; z: number }
11
+
12
+ /** a picture at the results' pixel size, placed on the box; pixels stay square above 100 % */
13
+ export function Layer(p: { url: string; box: Box; style?: React.CSSProperties; alt?: string }) {
14
+ return (
15
+ <img
16
+ className={`layer ${p.box.z > 1.01 ? 'px' : ''}`}
17
+ src={p.url}
18
+ alt={p.alt ?? ''}
19
+ draggable={false}
20
+ style={{ left: p.box.left, top: p.box.top, width: p.box.width, height: p.box.height, ...p.style }}
21
+ />
22
+ )
23
+ }
24
+
25
+ export const Viewport = observer(function Viewport(p: {
26
+ st: AppSt
27
+ className?: string
28
+ /** a press the caller takes instead of a pan (the curtain's line): true = taken */
29
+ onPress?: (e: React.PointerEvent<HTMLDivElement>, frame: DOMRect) => boolean
30
+ onHover?: (inside: boolean) => void
31
+ children: (box: Box) => ReactNode
32
+ }) {
33
+ const { st } = p
34
+ const ref = useRef<HTMLDivElement>(null)
35
+ const [size, setSize] = useState({ w: 0, h: 0 })
36
+ const drag = useRef<{ x: number; y: number } | null>(null)
37
+
38
+ useEffect(() => {
39
+ const el = ref.current
40
+ if (el == null) return
41
+ const ro = new ResizeObserver(() => {
42
+ setSize({ w: el.clientWidth, h: el.clientHeight })
43
+ st.noteFrame(el.clientWidth, el.clientHeight)
44
+ })
45
+ ro.observe(el)
46
+ // non passive, so the page never scrolls under a zoom; a pinch arrives as a wheel with ctrlKey
47
+ const onWheel = (e: WheelEvent): void => {
48
+ e.preventDefault()
49
+ const r = el.getBoundingClientRect()
50
+ const k = Math.exp(-e.deltaY * (e.ctrlKey ? 0.01 : 0.0015))
51
+ st.zoomAt(k, e.clientX - r.left, e.clientY - r.top, r.width, r.height)
52
+ }
53
+ el.addEventListener('wheel', onWheel, { passive: false })
54
+ return () => {
55
+ ro.disconnect()
56
+ el.removeEventListener('wheel', onWheel)
57
+ }
58
+ }, [st])
59
+
60
+ const z = st.zoomIn(size.w, size.h)
61
+ const s = z / devicePixelRatio
62
+ const fit = st.view.z === 'fit'
63
+ const cx = fit ? 0.5 : st.view.cx
64
+ const cy = fit ? 0.5 : st.view.cy
65
+ const box: Box = {
66
+ width: st.outW * s,
67
+ height: st.outH * s,
68
+ left: size.w / 2 - cx * st.outW * s,
69
+ top: size.h / 2 - cy * st.outH * s,
70
+ z,
71
+ }
72
+ return (
73
+ <div
74
+ ref={ref}
75
+ className={`viewport ${p.className ?? ''}`}
76
+ onPointerDown={(e) => {
77
+ if (!e.isPrimary || e.button !== 0) return
78
+ const el = ref.current
79
+ if (el == null) return
80
+ if (p.onPress?.(e, el.getBoundingClientRect()) === true) return
81
+ drag.current = { x: e.clientX, y: e.clientY }
82
+ el.setPointerCapture(e.pointerId)
83
+ }}
84
+ onPointerMove={(e) => {
85
+ const d = drag.current
86
+ if (d == null) return
87
+ st.pan(e.clientX - d.x, e.clientY - d.y, size.w, size.h)
88
+ drag.current = { x: e.clientX, y: e.clientY }
89
+ }}
90
+ onPointerUp={() => (drag.current = null)}
91
+ onPointerCancel={() => (drag.current = null)}
92
+ onDoubleClick={(e) => {
93
+ const r = e.currentTarget.getBoundingClientRect()
94
+ if (z > 0.99 && !fit) return st.fit()
95
+ const u = (e.clientX - r.left - box.left) / box.width
96
+ const v = (e.clientY - r.top - box.top) / box.height
97
+ st.setView({ cx: u, cy: v, z: 1 })
98
+ }}
99
+ onMouseEnter={() => p.onHover?.(true)}
100
+ onMouseLeave={() => p.onHover?.(false)}
101
+ >
102
+ {st.outW > 0 && size.w > 0 ? p.children(box) : null}
103
+ </div>
104
+ )
105
+ })
106
+
107
+ /** the zoom as a percent of real pixels, and the buttons that set it */
108
+ export const ZoomBar = observer(function ZoomBar(p: { st: AppSt }) {
109
+ const { st } = p
110
+ const z = st.view.z
111
+ return (
112
+ <span className="zoombar">
113
+ <button title="zoom out (−)" onClick={() => st.step(1 / 1.5)}>
114
+ −
115
+ </button>
116
+ <span className="zoompct" title="device pixels per result pixel">
117
+ {z === 'fit' ? 'fit' : `${Math.round(z * 100)} %`}
118
+ </span>
119
+ <button title="zoom in (+)" onClick={() => st.step(1.5)}>
120
+ +
121
+ </button>
122
+ <button className={z === 'fit' ? 'on' : ''} title="the whole image (0)" onClick={() => st.fit()}>
123
+ fit
124
+ </button>
125
+ <button className={z === 1 ? 'on' : ''} title="100 %: one result pixel on one screen pixel (1)" onClick={() => st.actual()}>
126
+ 1:1
127
+ </button>
128
+ </span>
129
+ )
130
+ })
@@ -15,8 +15,8 @@ const SPACE: Record<Exclude<View, 'source'>, Space> = { pano: 'pano', world: 'me
15
15
  const LABEL: Record<View, string> = { pano: '360°', world: 'walk', splat: 'splat', source: 'picture' }
16
16
  const HINT: Record<View, string> = {
17
17
  pano: 'drag to look around · wheel or pinch to zoom',
18
- world: 'drag to look · right drag or shift to pan · WASD to walk, Q E down and up · wheel to go forward',
19
- splat: 'drag to orbit · right drag or shift to pan · WASD to fly, Q E down and up · wheel to go forward',
18
+ world: 'drag to look · ↑ to go forward · ↓ back · double click: back at the start',
19
+ splat: 'drag to look · ↑ to go forward · ↓ back · double click: back at the start',
20
20
  source: '',
21
21
  }
22
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comfy-ts",
3
- "version": "2.23.0",
3
+ "version": "2.24.0",
4
4
  "description": "An efficient way to create, run, maintain and operate your ComfyUI workflows, for humans and agents. A TypeScript SDK typed from your own install, with a CLI, a terminal UI, a web panel and a guide for coding agents.",
5
5
  "keywords": [
6
6
  "comfyui",
@@ -73,7 +73,7 @@
73
73
  "test:raw": "bun test",
74
74
  "test:watch": "bun test --watch",
75
75
  "typecheck": "tsc -p tsconfig.lib.json && tsc -p examples/web/tsconfig.json && tsc -p src/cli/serve/web/tsconfig.json",
76
- "typecheck:full": "tsc --noEmit --tsBuildInfoFile node_modules/.cache/tsbuildinfo-typecheck.json && tsc -p examples/web/tsconfig.json && tsc -p src/cli/serve/web/tsconfig.json && tsc -p examples/depth-explorer/web/tsconfig.json && tsc -p examples/world-explorer/web/tsconfig.json",
76
+ "typecheck:full": "tsc --noEmit --tsBuildInfoFile node_modules/.cache/tsbuildinfo-typecheck.json && tsc -p examples/web/tsconfig.json && tsc -p src/cli/serve/web/tsconfig.json && tsc -p examples/depth-explorer/web/tsconfig.json && tsc -p examples/world-explorer/web/tsconfig.json && tsc -p examples/upscale-explorer/web/tsconfig.json",
77
77
  "lint": "oxlint src examples scripts tests",
78
78
  "imports:check": "rvt imports --check",
79
79
  "imports:fix": "rvt imports --fix",
@@ -102,6 +102,7 @@
102
102
  "serve:rvion": "bun --watch src/cli/comfy-ts-cli.ts serve examples/rvion",
103
103
  "depth": "bun examples/depth-explorer/serve.ts",
104
104
  "world": "bun --watch examples/world-explorer/serve.ts",
105
+ "upscale": "bun examples/upscale-explorer/serve.ts",
105
106
  "check:panel-scroll": "bun scripts/check-panel-scroll.ts"
106
107
  },
107
108
  "rvt": {
@@ -141,7 +142,7 @@
141
142
  "@types/ws": "^8.18.1",
142
143
  "oxlint": "^1.75.0",
143
144
  "oxlint-tsgolint": "^7.0.2001",
144
- "rvlib-shipkit": "^2.26.0",
145
+ "rvlib-shipkit": "^2.29.0",
145
146
  "rvlib-ts-tools": "^0.3.3",
146
147
  "tsdown": "^0.22.14",
147
148
  "typescript": "^7.0.2"
@@ -48,6 +48,11 @@ export type { PromptID, WsMsg, PromptRelated_WsMsg } from 'src/runner/ComfyWsApi
48
48
  export { MediaImage, type MediaImageData } from 'src/runner/MediaImage.ts'
49
49
  export type { ComfyExecutionStatus } from 'src/runner/ComfyExecutionStatus.ts'
50
50
  export { InvalidPromptError } from 'src/errors/InvalidPromptError.ts'
51
+ export {
52
+ ComfyOrgApiKeyMissingError,
53
+ type ComfyOrgApiKeySource,
54
+ type PartnerApiNode,
55
+ } from 'src/runner/comfyOrgApiKey.ts'
51
56
 
52
57
  // graph (programmatic node graph)
53
58
  export { ComfyNode } from 'src/graph/ComfyNode.ts'
@@ -47,6 +47,7 @@ import { ResilientWebSocketClient, type WsMessageEvent } from 'src/host/Resilien
47
47
  import { DefinedWorkflow, type DefineWorkflowSpec } from 'src/vars/DefinedWorkflow.ts'
48
48
  import type { VarsSpec } from 'src/vars/ComfyVars.ts'
49
49
  import { diffSchemas, MODEL_LISTS, type SchemaDrift } from 'src/host/schemaDrift.ts'
50
+ import type { ComfyOrgApiKeySource } from 'src/runner/comfyOrgApiKey.ts'
50
51
 
51
52
  export type ComfyHostID = Tagged<string, { HostID: true }>
52
53
  export type ComfyHostData = {
@@ -63,6 +64,11 @@ export type ComfyHostData = {
63
64
  /** sent as X-API-Key on every request AND the ws upgrade.
64
65
  * NEVER persist the value: read it from an env var (e.g. COMFY_CLOUD_API_KEY) */
65
66
  apiKey?: string
67
+ /** the Comfy account key (platform.comfy.org) that paid partner API nodes bill to, sent as
68
+ * `extra_data.api_key_comfy_org` with a prompt that holds one. A thunk is read only when such
69
+ * a run starts. `RunSettings.comfyOrgApiKey` overrides it for one run; a cloud.comfy.org host
70
+ * falls back to its apiKey. NEVER persist the value (architecture.md, Partner API nodes) */
71
+ comfyOrgApiKey?: ComfyOrgApiKeySource
66
72
  /** default true. false = never write sdk.d.ts to .comfy-ts/hosts/<id>/ —
67
73
  * schema updates stay in-memory. The comfy-cloud example sets false: its sdk
68
74
  * home is the COMMITTED examples/comfy-cloud/sdk.d.ts (gen:sdk:cloud), and a
@@ -53,6 +53,8 @@ export type ComfyAudioOutput = {
53
53
  mime: string
54
54
  bytes: Uint8Array
55
55
  absPath: AbsolutePath | null
56
+ /** the `tag` / `tags` of the output node's metadata, as on images */
57
+ tags: string[]
56
58
  }
57
59
 
58
60
  /** one video file an output node published (SaveVideo, SaveWEBM, VHS_VideoCombine), same
@@ -429,6 +431,10 @@ export class ComfyExecution {
429
431
  await this._finish({ status: 'Failure', error: null, reason })
430
432
  return 'lost'
431
433
  }
434
+ // a SaveImageWebsocket frame in transit is silence too (the message event fires once the frame is
435
+ // whole) and /history never holds one: a quiet socket gets until runSilenceMaxMs to deliver it
436
+ const sinceHeard = Date.now() - this.lastHeardAt
437
+ if (!this.mayHaveMissedEvents && this.sendsWsFrames && sinceHeard < this.host.runSilenceMaxMs) return 'waiting'
432
438
  logInfo(`run ${id}: ended on host '${hostId}' without its end reaching the socket, finishing from its history`)
433
439
  for (const p of replay.problems) logError(`run ${id}: a history entry does not match the ws schemas, skipped: ${p}`)
434
440
  this.replayUnheardOutputs(replay)
@@ -474,8 +480,9 @@ export class ComfyExecution {
474
480
  ): Promise<ComfyAudioOutput> => {
475
481
  const response = await this.host.fetchFile('/view?' + new URLSearchParams(info).toString())
476
482
  const bytes = new Uint8Array(await response.arrayBuffer())
483
+ const tags = this.tagsOf(promptNodeID)
477
484
  const sf = this.save
478
- if (sf == null) return { nodeId: promptNodeID, filename: info.filename, mime, bytes, absPath: null }
485
+ if (sf == null) return { nodeId: promptNodeID, filename: info.filename, mime, bytes, absPath: null, tags }
479
486
  const promptPrefix = this.workflow.data.apiJson?.[promptNodeID]?.inputs['filename_prefix']
480
487
  const written = await this.encodeAndWrite({
481
488
  bytes,
@@ -485,7 +492,7 @@ export class ComfyExecution {
485
492
  subfolder: info.subfolder,
486
493
  filename: info.filename,
487
494
  })
488
- return { nodeId: promptNodeID, filename: info.filename, mime, bytes, absPath: written.path }
495
+ return { nodeId: promptNodeID, filename: info.filename, mime, bytes, absPath: written.path, tags }
489
496
  }
490
497
 
491
498
  /** image retrievals that failed (their images are missing from `images`);
@@ -600,12 +607,22 @@ export class ComfyExecution {
600
607
 
601
608
  /** accumulate an output on the prompt; tags from node metadata ride along */
602
609
  private pushImage(img: MediaImage, promptNodeID: Maybe<string>): void {
603
- const promptMeta = promptNodeID != null ? this.workflow.data.metadata?.[promptNodeID] : null
604
- if (promptMeta?.tag) img.tags.push(promptMeta.tag)
605
- if (promptMeta?.tags) img.tags.push(...promptMeta.tags)
610
+ img.tags.push(...this.tagsOf(promptNodeID))
606
611
  this.images.push(img)
607
612
  }
608
613
 
614
+ /** the tags an output node was built with (`{ tag }` / `{ tags }` metadata) */
615
+ private tagsOf(promptNodeID: Maybe<string>): string[] {
616
+ const promptMeta = promptNodeID != null ? this.workflow.data.metadata?.[promptNodeID] : null
617
+ return [...(promptMeta?.tag ? [promptMeta.tag] : []), ...(promptMeta?.tags ?? [])]
618
+ }
619
+
620
+ /** the sent graph saves through SaveImageWebsocket: those outputs exist only as ws frames */
621
+ private get sendsWsFrames(): boolean {
622
+ const apiJson = this.snapshot?.apiJson ?? this.workflow.apiJson
623
+ return Object.values(apiJson).some((n) => n?.class_type === 'SaveImageWebsocket')
624
+ }
625
+
609
626
  /** true while the currently executing node is a SaveImageWebsocket in the
610
627
  * SENT snapshot (the ephemeral rewrite only touches the snapshot, so the
611
628
  * live graph may still say SaveImage) — binary frames are then OUTPUTS */
@@ -9,6 +9,12 @@ import type { LiteGraphJSON } from 'src/litegraph/LiteGraphJSON.ts'
9
9
  import { ComfyNode } from 'src/graph/ComfyNode.ts'
10
10
  import type { ComfyNodeId, ComfyNodeMetadata } from 'src/graph/ComfyNodeID.ts'
11
11
  import { ComfyExecution, type ExecutionPreview, type ExecutionProgress } from 'src/runner/ComfyExecution.ts'
12
+ import {
13
+ ComfyOrgApiKeyMissingError,
14
+ type ComfyOrgApiKeySource,
15
+ partnerApiNodes,
16
+ resolveComfyOrgApiKey,
17
+ } from 'src/runner/comfyOrgApiKey.ts'
12
18
  import { rewriteSaveNodesToWebsocket } from 'src/runner/ephemeral.ts'
13
19
  import type { ComfySchema } from 'src/sdk-generator/ComfySchema.ts'
14
20
  import type { ComfyApiJson, ComfyApiNodeJson } from 'src/sdk-generator/comfy-api-json.ts'
@@ -56,8 +62,14 @@ export type RunSettings = {
56
62
  * without it no frame is decoded for the run. ComfyUI sends frames only when launched with
57
63
  * `--preview-method`, see `host.fetchPreviewMethod()` */
58
64
  onPreview?: (p: ExecutionPreview) => void
65
+ /** the Comfy account key for this run's paid partner API nodes; overrides the host's
66
+ * `comfyOrgApiKey`. Sent only when the prompt holds one, never saved */
67
+ comfyOrgApiKey?: ComfyOrgApiKeySource
59
68
  }
60
69
 
70
+ /** a Comfy Cloud host's X-API-Key is a platform.comfy.org key, the one partner nodes bill to */
71
+ const COMFY_CLOUD_HOST = 'cloud.comfy.org'
72
+
61
73
  /** exactly what was sent to the host for one execution, frozen at send time */
62
74
  export type ExecutionSnapshot = {
63
75
  apiJson: ComfyApiJson
@@ -385,6 +397,15 @@ export class ComfyWorkflow<ID extends string = string> {
385
397
  `🟡 ephemeral run: no SaveImage/SaveImageWebsocket node in workflow '${this.id}' — nothing streams back`,
386
398
  )
387
399
  }
400
+ // the account key rides the posted body only, never the snapshot (architecture.md, Partner API nodes)
401
+ const partners = partnerApiNodes(snapshot.apiJson, this.schema)
402
+ let comfyOrgApiKey: string | undefined
403
+ if (partners.length > 0) {
404
+ const data = this.host.data
405
+ const cloudKey = data.apiKey != null && this.host.base.host === COMFY_CLOUD_HOST ? data.apiKey : undefined
406
+ comfyOrgApiKey = await resolveComfyOrgApiKey([p.comfyOrgApiKey, data.comfyOrgApiKey, cloudKey])
407
+ if (comfyOrgApiKey == null) throw new ComfyOrgApiKeyMissingError(data.id, partners)
408
+ }
388
409
  const out: ApiPromptInput = {
389
410
  client_id: this.host.comfySessionId,
390
411
  prompt: snapshot.apiJson,
@@ -395,6 +416,7 @@ export class ComfyWorkflow<ID extends string = string> {
395
416
  comfy_ts_workflow_id: this.id,
396
417
  comfy_ts_version: comfyts.version,
397
418
  },
419
+ ...(comfyOrgApiKey != null ? { api_key_comfy_org: comfyOrgApiKey } : {}),
398
420
  },
399
421
  }
400
422
 
@@ -14,7 +14,7 @@ const tempScope = scope({
14
14
 
15
15
  ApiPromptInput: {
16
16
  client_id: 'string',
17
- extra_data: { extra_pnginfo: 'unknown' },
17
+ extra_data: { extra_pnginfo: 'unknown', 'api_key_comfy_org?': 'string' },
18
18
  prompt: 'unknown',
19
19
  },
20
20
 
@@ -0,0 +1,44 @@
1
+ import type { ComfySchema } from 'src/sdk-generator/ComfySchema.ts'
2
+ import type { ComfyApiJson } from 'src/sdk-generator/comfy-api-json.ts'
3
+
4
+ /** a Comfy account key, or a thunk read only when a run with a partner node starts */
5
+ export type ComfyOrgApiKeySource = string | (() => string | undefined | Promise<string | undefined>)
6
+
7
+ /** a partner API node of a prompt: what the error names */
8
+ export type PartnerApiNode = { id: string; classType: string }
9
+
10
+ /** the prompt holds a paid partner node and no Comfy account key was set */
11
+ export class ComfyOrgApiKeyMissingError extends Error {
12
+ /** name, not instanceof: the cli bundle and dist/index.js each define this class */
13
+ override readonly name = 'ComfyOrgApiKeyMissingError'
14
+ constructor(
15
+ public hostId: string,
16
+ public nodes: PartnerApiNode[],
17
+ ) {
18
+ const list = nodes.map((n) => `${n.classType} #${n.id}`).join(', ')
19
+ super(
20
+ `🔴 host '${hostId}': the prompt holds partner API node(s) ${list}, which bill a Comfy account, and no Comfy account key is set. ` +
21
+ `Set it with \`comfy.host({ id: '${hostId}', comfyOrgApiKey })\` or \`run({ comfyOrgApiKey })\` (a string or a thunk; the key comes from platform.comfy.org). Nothing was sent.`,
22
+ )
23
+ }
24
+ }
25
+
26
+ /** the nodes of a prompt whose schema says `api_node: true` */
27
+ export const partnerApiNodes = (apiJson: ComfyApiJson, schema: ComfySchema): PartnerApiNode[] => {
28
+ const out: PartnerApiNode[] = []
29
+ for (const [id, node] of Object.entries(apiJson))
30
+ if (schema.nodesByNameInComfy[node.class_type]?.raw.api_node === true) out.push({ id, classType: node.class_type })
31
+ return out
32
+ }
33
+
34
+ /** the first source set wins; an empty string counts as unset */
35
+ export const resolveComfyOrgApiKey = async (
36
+ sources: readonly (ComfyOrgApiKeySource | undefined)[],
37
+ ): Promise<string | undefined> => {
38
+ for (const src of sources) {
39
+ if (src == null) continue
40
+ const key = typeof src === 'string' ? src : await src()
41
+ if (key != null && key !== '') return key
42
+ }
43
+ return undefined
44
+ }
@@ -27,6 +27,8 @@ export const ComfyUIObjectInfoScope = scope({
27
27
  // Stability Flags
28
28
  'deprecated?': 'boolean',
29
29
  'experimental?': 'boolean',
30
+ // a partner node: a paid service billed to a Comfy account, its key from extra_data.api_key_comfy_org
31
+ 'api_node?': 'boolean',
30
32
  },
31
33
  ComfyInputSpecAlt1: ['ComfyInputType', 'ComfyInputOpts'],
32
34
  ComfyInputSpecAlt2: ['ComfyInputType'],
package/src/state.ts CHANGED
@@ -75,6 +75,8 @@ export class ComfyTS {
75
75
  `host id '${data.id}' already registered ${cur == null ? 'with no address' : `at ${renderHttpBase(cur)}`}${authed(existing.data)} — refusing ${incoming == null ? 'the id alone' : renderHttpBase(incoming)}${authed(data)}`,
76
76
  )
77
77
  }
78
+ // a credential provider, not the address: a later registration hands it over, never drops it
79
+ if (data.comfyOrgApiKey != null) existing.data.comfyOrgApiKey = data.comfyOrgApiKey
78
80
  // cast: whitelist item 7 (agent/coding.md) — id equality checked just above
79
81
  return existing as ComfyHost<ID>
80
82
  }
@@ -204,6 +204,7 @@ export class DefinedWorkflow<ID extends string = string, V extends VarsSpec = Va
204
204
  log: settings.log,
205
205
  onProgress: settings.onProgress,
206
206
  onPreview: settings.onPreview,
207
+ comfyOrgApiKey: settings.comfyOrgApiKey,
207
208
  })
208
209
  this.lastExecution = execution
209
210
  return execution