comfy-ts 2.22.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.
- package/dist/{ServeApp-DuxYdaZZ.js → ServeApp-fsHtW5zG.js} +51 -17
- package/dist/ServeApp-fsHtW5zG.js.map +1 -0
- package/dist/cli.js +5 -5
- package/dist/{exampleAssets-1NHndnNB.js → exampleAssets-DZynSkZm.js} +405 -39
- package/dist/exampleAssets-DZynSkZm.js.map +1 -0
- package/dist/{findDefinedWorkflow-CRsBTTJK.js → findDefinedWorkflow-qyqFea7q.js} +2 -2
- package/dist/{findDefinedWorkflow-CRsBTTJK.js.map → findDefinedWorkflow-qyqFea7q.js.map} +1 -1
- package/dist/index.cjs +428 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +147 -1
- package/dist/index.d.ts +147 -1
- package/dist/index.js +428 -47
- package/dist/index.js.map +1 -1
- package/dist/{run-run-Y5ZI48vV.js → run-run-Cn2JzKlE.js} +5 -5
- package/dist/{run-run-Y5ZI48vV.js.map → run-run-Cn2JzKlE.js.map} +1 -1
- package/dist/{run-serve-CICU_wTL.js → run-serve-BhGegaCI.js} +4 -4
- package/dist/{run-serve-CICU_wTL.js.map → run-serve-BhGegaCI.js.map} +1 -1
- package/dist/{run-tui-CViJXsHL.js → run-tui-CrM4ijkH.js} +4 -4
- package/dist/{run-tui-CViJXsHL.js.map → run-tui-CrM4ijkH.js.map} +1 -1
- package/dist/{schemaDrift-CzjaIwZX.js → schemaDrift-BGYJZGMD.js} +18 -3
- package/dist/{schemaDrift-CzjaIwZX.js.map → schemaDrift-BGYJZGMD.js.map} +1 -1
- package/dist/serve-web.js +46 -43
- package/dist/web.d.ts +147 -1
- package/dist/web.js +428 -47
- package/dist/web.js.map +1 -1
- package/examples/README.md +1 -0
- package/examples/comfy-cloud/sdk.d.ts +102 -1
- package/examples/depth-explorer/models.ts +6 -56
- package/examples/depth-explorer/serve.ts +12 -133
- package/examples/depth-explorer/web/App.tsx +20 -91
- package/examples/depth-explorer/web/index.html +1 -0
- package/examples/depth-explorer/web/state.ts +26 -109
- package/examples/depth-explorer/web/styles.css +1 -286
- package/examples/explorer-kit/catalog.ts +80 -0
- package/examples/explorer-kit/server.ts +167 -0
- package/examples/explorer-kit/web/base.css +289 -0
- package/examples/explorer-kit/web/runs.ts +160 -0
- package/examples/explorer-kit/web/ui.tsx +125 -0
- package/examples/rvion/17-relight.cflow.ts +2 -1
- package/examples/rvion/18-world.cflow.ts +101 -0
- package/examples/rvion/19-flythrough.cflow.ts +312 -0
- package/examples/rvion/20-grow-splat.cflow.ts +88 -0
- package/examples/rvion/21-photo-to-model.cflow.ts +191 -0
- package/examples/rvion/flythroughChain.ts +171 -0
- package/examples/rvion/flythroughColmap.ts +157 -0
- package/examples/rvion/flythroughFuse.ts +199 -0
- package/examples/rvion/flythroughGuide.ts +300 -0
- package/examples/rvion/flythroughPalette.ts +310 -0
- package/examples/rvion/flythroughPath.ts +177 -0
- package/examples/rvion/flythroughSplat.ts +73 -0
- package/examples/rvion/grow-splat/align.ts +114 -0
- package/examples/rvion/grow-splat/grow.ts +198 -0
- package/examples/rvion/grow-splat/ply.ts +166 -0
- package/examples/rvion/grow-splat/raster.ts +207 -0
- package/examples/rvion/grow-splat/sharp.ts +45 -0
- package/examples/rvion/splatDataset.ts +80 -0
- package/examples/rvion/splatEval.ts +380 -0
- package/examples/upscale-explorer/models.ts +341 -0
- package/examples/upscale-explorer/serve.ts +19 -0
- package/examples/upscale-explorer/web/App.tsx +250 -0
- package/examples/upscale-explorer/web/compare.tsx +285 -0
- package/examples/upscale-explorer/web/index.html +15 -0
- package/examples/upscale-explorer/web/main.tsx +12 -0
- package/examples/upscale-explorer/web/state.ts +279 -0
- package/examples/upscale-explorer/web/styles.css +241 -0
- package/examples/upscale-explorer/web/tsconfig.json +16 -0
- package/examples/upscale-explorer/web/viewport.tsx +130 -0
- package/examples/world-explorer/serve.ts +171 -0
- package/examples/world-explorer/web/index.html +14 -0
- package/examples/world-explorer/web/main.tsx +200 -0
- package/examples/world-explorer/web/state.ts +212 -0
- package/examples/world-explorer/web/styles.css +131 -0
- package/examples/world-explorer/web/thumb.ts +21 -0
- package/examples/world-explorer/web/tsconfig.json +11 -0
- package/examples/world-explorer/world-state.ts +40 -0
- package/package.json +7 -8
- package/src/cli/serve/ServeApp.ts +27 -2
- package/src/cli/serve/resultHistory.ts +22 -4
- package/src/cli/serve/thumbs.ts +19 -8
- package/src/cli/serve/web/api.ts +4 -0
- package/src/cli/serve/web/components/Gallery.tsx +24 -1
- package/src/cli/serve/web/styles.ts +3 -0
- package/src/coreExports.ts +6 -0
- package/src/graph/ComfyNode.ts +12 -2
- package/src/host/ComfyHost.ts +159 -2
- package/src/host/ResilientWebsocket.ts +10 -0
- package/src/manager/script-update-manager.bun.ts +0 -7
- package/src/runner/ComfyExecution.ts +185 -23
- package/src/runner/ComfyWorkflow.ts +22 -0
- package/src/runner/ComfyWsApi.ts +3 -1
- package/src/runner/comfyOrgApiKey.ts +44 -0
- package/src/runner/historyReplay.ts +53 -0
- package/src/runner/outputs3d.ts +18 -0
- package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +2 -0
- package/src/sdk-generator/comfyui-sdk-codegen.ts +7 -2
- package/src/state.ts +2 -0
- package/src/vars/DefinedWorkflow.ts +1 -0
- package/dist/ServeApp-DuxYdaZZ.js.map +0 -1
- package/dist/exampleAssets-1NHndnNB.js.map +0 -1
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { compareStructural, reaction } from 'mobx'
|
|
2
|
+
import { observer } from 'mobx-react-lite'
|
|
3
|
+
import { useEffect, useRef } from 'react'
|
|
4
|
+
import { createRoot } from 'react-dom/client'
|
|
5
|
+
import { frameClient } from 'rvlib-shipkit/src/pages/frame-client.ts'
|
|
6
|
+
import { camText, View3d, type Space } from 'rvlib-shipkit/src/view3d/viewer.ts'
|
|
7
|
+
import { WorldSt, type View } from './state.ts'
|
|
8
|
+
import { postThumb, sendThumb, THUMB_W } from './thumb.ts'
|
|
9
|
+
|
|
10
|
+
// one world of .comfy-ts/worlds, the view page of the `world` thread kind (agent/examples.md, world-explorer). Framed by
|
|
11
|
+
// the hub or alone at its url: the frame client hands it its keys either way
|
|
12
|
+
|
|
13
|
+
/** the house viewer's space for each 3D view; `source` is a flat picture, no viewer */
|
|
14
|
+
const SPACE: Record<Exclude<View, 'source'>, Space> = { pano: 'pano', world: 'mesh', splat: 'splat' }
|
|
15
|
+
const LABEL: Record<View, string> = { pano: '360°', world: 'walk', splat: 'splat', source: 'picture' }
|
|
16
|
+
const HINT: Record<View, string> = {
|
|
17
|
+
pano: 'drag to look around · wheel or pinch to zoom',
|
|
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
|
+
source: '',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** the page's own full screen, for the page opened alone: in the hub's lightbox (`mode=lightbox`) the hub fills the
|
|
24
|
+
* window and closes it. Esc leaves it (the browser's own key); F toggles it */
|
|
25
|
+
async function toggleFull(): Promise<void> {
|
|
26
|
+
if (st.mode === 'lightbox') return
|
|
27
|
+
if (document.fullscreenElement != null) return void (await document.exitFullscreen())
|
|
28
|
+
try {
|
|
29
|
+
await document.documentElement.requestFullscreen()
|
|
30
|
+
} catch (e) {
|
|
31
|
+
st.setNotice(`full screen refused here: ${(e as Error).message}`)
|
|
32
|
+
setTimeout(() => st.setNotice(null), 4000)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
document.addEventListener('fullscreenchange', () => st.setFull(document.fullscreenElement != null))
|
|
36
|
+
window.addEventListener('keydown', (e) => {
|
|
37
|
+
if (e.key === 'Escape' && document.fullscreenElement != null) void document.exitFullscreen()
|
|
38
|
+
if (e.code === 'KeyF' && !e.altKey && !e.metaKey && !e.ctrlKey) void toggleFull()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
let viewer: View3d | null = null
|
|
42
|
+
const st = new WorldSt((k) => frame.setKeys(k))
|
|
43
|
+
// alone at its url, the client hands the address's keys at once: the state exists first. A camera from the keys
|
|
44
|
+
// (the other side of a change) is set on the viewer; one equal to its own is left alone, so a glide goes on
|
|
45
|
+
const frame = frameClient({
|
|
46
|
+
onKeys: (k) => {
|
|
47
|
+
st.fromKeys(k)
|
|
48
|
+
if (viewer != null && camText(viewer.cam) !== camText(st.cam)) viewer.setCam(st.cam)
|
|
49
|
+
},
|
|
50
|
+
// a frame the hub does not show draws nothing
|
|
51
|
+
onFocus: (on) => viewer?.pause(!on),
|
|
52
|
+
})
|
|
53
|
+
// console debugging path (app-state-tree: expose the root)
|
|
54
|
+
Object.assign(window, { world: st })
|
|
55
|
+
|
|
56
|
+
const shotReady = (on: boolean): void =>
|
|
57
|
+
document.querySelector('meta[name="shot-ready"]')?.setAttribute('content', on ? 'ready' : 'wait')
|
|
58
|
+
|
|
59
|
+
/** a world's view drawn once: the shot's ready mark, and its thumbnail when it has none and he has not moved yet */
|
|
60
|
+
function drawn(v: View3d): void {
|
|
61
|
+
shotReady(true)
|
|
62
|
+
if (!st.wantsThumb || st.shown !== st.thumbView || st.touched) return
|
|
63
|
+
st.thumbSent()
|
|
64
|
+
v.snapshot({ type: 'image/webp', quality: 0.85, width: THUMB_W })
|
|
65
|
+
.then((blob) => postThumb(st.name, blob))
|
|
66
|
+
.catch((e: unknown) => st.setNotice((e as Error).message))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** the 3D views through the house viewer: one viewer while a 3D tab shows, each tab's file loaded into it */
|
|
70
|
+
const Scene = observer(function Scene() {
|
|
71
|
+
const host = useRef<HTMLDivElement>(null)
|
|
72
|
+
// in the hub's lightbox the wheel is the view's at once; inline or alone it scrolls until he clicks in
|
|
73
|
+
const mode = st.mode === 'lightbox' ? 'lightbox' : 'thumb'
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
const el = host.current
|
|
76
|
+
if (el == null) return
|
|
77
|
+
const v: View3d = new View3d(el, {
|
|
78
|
+
keys: 'window',
|
|
79
|
+
mode,
|
|
80
|
+
onCam: (c) => st.setCam(c),
|
|
81
|
+
onLoading: (what) => st.setLoading(what),
|
|
82
|
+
onError: (why) => st.setError(why),
|
|
83
|
+
onDrawn: () => drawn(v),
|
|
84
|
+
})
|
|
85
|
+
viewer = v
|
|
86
|
+
const stop = reaction(
|
|
87
|
+
() => {
|
|
88
|
+
const view = st.shown
|
|
89
|
+
if (view == null || view === 'source') return null
|
|
90
|
+
return { space: SPACE[view], url: st.fileUrl(view), fov: st.info?.splatFov ?? undefined }
|
|
91
|
+
},
|
|
92
|
+
(src) => {
|
|
93
|
+
if (src?.url == null) return
|
|
94
|
+
void v.load({ space: src.space, url: src.url, fov: src.fov }).then(() => v.setCam(st.cam))
|
|
95
|
+
},
|
|
96
|
+
{ fireImmediately: true, equals: compareStructural },
|
|
97
|
+
)
|
|
98
|
+
return () => {
|
|
99
|
+
stop()
|
|
100
|
+
v.destroy()
|
|
101
|
+
if (viewer === v) viewer = null
|
|
102
|
+
}
|
|
103
|
+
}, [mode])
|
|
104
|
+
return <div ref={host} className="view" />
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const Stage = observer(function Stage() {
|
|
108
|
+
const shown = st.shown
|
|
109
|
+
const src = shown === 'source' ? st.fileUrl('source') : null
|
|
110
|
+
useEffect(() => shotReady(shown === 'source'), [shown])
|
|
111
|
+
return (
|
|
112
|
+
<div className="stage">
|
|
113
|
+
{shown != null && shown !== 'source' ? <Scene /> : null}
|
|
114
|
+
{src != null ? (
|
|
115
|
+
<img
|
|
116
|
+
src={src}
|
|
117
|
+
alt={st.name}
|
|
118
|
+
draggable={false}
|
|
119
|
+
onLoad={(e) => {
|
|
120
|
+
const img = e.currentTarget
|
|
121
|
+
if (!st.wantsThumb || st.thumbView !== 'source') return
|
|
122
|
+
st.thumbSent()
|
|
123
|
+
sendThumb(st.name, img, img.naturalWidth, img.naturalHeight).catch((x: unknown) =>
|
|
124
|
+
st.setNotice((x as Error).message),
|
|
125
|
+
)
|
|
126
|
+
}}
|
|
127
|
+
/>
|
|
128
|
+
) : null}
|
|
129
|
+
{st.error != null ? (
|
|
130
|
+
<div className="note">{st.error}</div>
|
|
131
|
+
) : st.loading != null ? (
|
|
132
|
+
<div className="note">loading {st.loading}…</div>
|
|
133
|
+
) : null}
|
|
134
|
+
{st.name === '' && st.standalone ? <Worlds /> : null}
|
|
135
|
+
{shown != null && HINT[shown] && !st.touched && st.loading == null && st.mode !== 'thumb' ? (
|
|
136
|
+
<div className="hint">{HINT[shown]}</div>
|
|
137
|
+
) : null}
|
|
138
|
+
{st.notice != null && st.mode !== 'thumb' ? <div className="hint notice">{st.notice}</div> : null}
|
|
139
|
+
</div>
|
|
140
|
+
)
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
const Worlds = observer(function Worlds() {
|
|
144
|
+
return (
|
|
145
|
+
<div className="note worlds">
|
|
146
|
+
<div>
|
|
147
|
+
{st.all.map((w) => (
|
|
148
|
+
<a key={w.name} href={`?key=${w.name}`}>
|
|
149
|
+
{w.name}
|
|
150
|
+
</a>
|
|
151
|
+
))}
|
|
152
|
+
</div>
|
|
153
|
+
</div>
|
|
154
|
+
)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const App = observer(function App() {
|
|
158
|
+
const shown = st.shown
|
|
159
|
+
// the hub's still: the scene alone, no bar, no hint
|
|
160
|
+
if (st.mode === 'thumb')
|
|
161
|
+
return (
|
|
162
|
+
<div className="app thumb">
|
|
163
|
+
<Stage />
|
|
164
|
+
</div>
|
|
165
|
+
)
|
|
166
|
+
return (
|
|
167
|
+
<div className="app">
|
|
168
|
+
<div className="bar">
|
|
169
|
+
{/* tabs only when the page is opened alone: in a thread the hub switches views, one still per view */}
|
|
170
|
+
{(st.standalone ? st.views : []).map((v) => (
|
|
171
|
+
<button key={v} className={`tab${v === shown ? ' on' : ''}`} onClick={() => st.setView(v)}>
|
|
172
|
+
{LABEL[v]}
|
|
173
|
+
</button>
|
|
174
|
+
))}
|
|
175
|
+
<span className="line">
|
|
176
|
+
<b>{st.name || 'worlds'}</b>
|
|
177
|
+
{st.side ? ` · ${st.side}` : ''}
|
|
178
|
+
</span>
|
|
179
|
+
<span className="tools">
|
|
180
|
+
{shown != null && shown !== 'source' ? (
|
|
181
|
+
<button className="tab" title="R, or a double click" onClick={() => viewer?.reset()}>
|
|
182
|
+
reset view
|
|
183
|
+
</button>
|
|
184
|
+
) : null}
|
|
185
|
+
{st.mode === 'lightbox' ? null : (
|
|
186
|
+
<button className="tab" title={st.full ? 'Esc' : 'F'} onClick={() => void toggleFull()}>
|
|
187
|
+
{st.full ? '✕ close' : '⤢ full screen'}
|
|
188
|
+
</button>
|
|
189
|
+
)}
|
|
190
|
+
</span>
|
|
191
|
+
</div>
|
|
192
|
+
<Stage />
|
|
193
|
+
</div>
|
|
194
|
+
)
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
void st.boot()
|
|
198
|
+
const rootEl = document.getElementById('root')
|
|
199
|
+
if (rootEl == null) throw new Error('#root missing from index.html')
|
|
200
|
+
createRoot(rootEl).render(<App />)
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { makeAutoObservable, runInAction } from 'mobx'
|
|
2
|
+
import { CAM0, camOf, camText, type Cam } from 'rvlib-shipkit/src/view3d/cam.ts'
|
|
3
|
+
|
|
4
|
+
// the page's state: which world, which of its files, the tab, the camera. Its keys (agent/examples.md, world-explorer):
|
|
5
|
+
// `key` the world, `view` the tab, `cam` the camera; framed by the hub, `state` is the url of a version's side and
|
|
6
|
+
// `view` + `cam` are what a before and an after share, so both sides switch tab and turn together
|
|
7
|
+
|
|
8
|
+
export const VIEWS = ['pano', 'world', 'splat', 'source'] as const
|
|
9
|
+
export type View = (typeof VIEWS)[number]
|
|
10
|
+
|
|
11
|
+
/** the file each view draws */
|
|
12
|
+
export const FILE_OF: Record<View, string> = {
|
|
13
|
+
pano: 'panorama.png',
|
|
14
|
+
world: 'world.glb',
|
|
15
|
+
splat: 'splat.ply',
|
|
16
|
+
source: 'source.png',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type WorldFile = { name: string; v: string }
|
|
20
|
+
export type WorldInfo = { name: string; files: WorldFile[]; splatFov: number | null }
|
|
21
|
+
|
|
22
|
+
/** the keys posted at most this often while he moves: the other side follows, the hub is not flooded */
|
|
23
|
+
const POST_MS = 40
|
|
24
|
+
|
|
25
|
+
export class WorldSt {
|
|
26
|
+
name = ''
|
|
27
|
+
side = ''
|
|
28
|
+
/** how the hub frames the page: `thumb` for the still it shoots (no ui), `lightbox` (the hub closes it), else inline or alone */
|
|
29
|
+
mode: '' | 'thumb' | 'lightbox' = ''
|
|
30
|
+
/** the files the shown version names: a side's state, else every file the world has on disk */
|
|
31
|
+
wanted: string[] = []
|
|
32
|
+
all: WorldInfo[] = []
|
|
33
|
+
view: View | null = null
|
|
34
|
+
cam: Cam = { ...CAM0 }
|
|
35
|
+
error: string | null = null
|
|
36
|
+
/** what loads now and how far, for the one line */
|
|
37
|
+
loading: string | null = null
|
|
38
|
+
private stateUrl = ''
|
|
39
|
+
|
|
40
|
+
constructor(private post: (keys: string) => void) {
|
|
41
|
+
makeAutoObservable<WorldSt, 'post' | 'postTimer' | 'postedAt'>(this, {
|
|
42
|
+
post: false,
|
|
43
|
+
postTimer: false,
|
|
44
|
+
postedAt: false,
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get info(): WorldInfo | null {
|
|
49
|
+
return this.all.find((w) => w.name === this.name) ?? null
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get views(): View[] {
|
|
53
|
+
const info = this.info
|
|
54
|
+
if (info == null) return []
|
|
55
|
+
return VIEWS.filter((v) => this.wanted.includes(FILE_OF[v]) && info.files.some((f) => f.name === FILE_OF[v]))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** the tab drawn: the one asked when the world has it, else the first */
|
|
59
|
+
get shown(): View | null {
|
|
60
|
+
const vs = this.views
|
|
61
|
+
return this.view != null && vs.includes(this.view) ? this.view : (vs[0] ?? null)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** the view a thumbnail shows: the world's first, at the default camera */
|
|
65
|
+
get thumbView(): View | null {
|
|
66
|
+
return this.views[0] ?? null
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** the page makes the thumbnail when the world has none, or when its keys say `thumb=again` */
|
|
70
|
+
thumbAgain = false
|
|
71
|
+
|
|
72
|
+
get wantsThumb(): boolean {
|
|
73
|
+
const info = this.info
|
|
74
|
+
return info != null && (this.thumbAgain || !info.files.some((f) => f.name === 'thumb.webp'))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** the thumbnail sent: the world lists it now, so no other frame sends one */
|
|
78
|
+
thumbSent(): void {
|
|
79
|
+
this.thumbAgain = false
|
|
80
|
+
const info = this.info
|
|
81
|
+
if (info != null && !info.files.some((f) => f.name === 'thumb.webp'))
|
|
82
|
+
info.files.push({ name: 'thumb.webp', v: 'new' })
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** a world file by its relative path, under its stamp so the browser keeps it */
|
|
86
|
+
fileUrl(view: View): string | null {
|
|
87
|
+
const f = this.info?.files.find((x) => x.name === FILE_OF[view])
|
|
88
|
+
return f == null ? null : `worlds/${this.name}/${f.name}?v=${f.v}`
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
get keys(): string {
|
|
92
|
+
const q = new URLSearchParams()
|
|
93
|
+
if (this.name !== '') q.set('key', this.name)
|
|
94
|
+
if (this.view != null) q.set('view', this.view)
|
|
95
|
+
const cam = camText(this.cam)
|
|
96
|
+
if (cam !== '') q.set('cam', cam)
|
|
97
|
+
return q.toString().replaceAll('%2C', ',')
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** the keys from the hub or the address: they never post back, only a move of his does */
|
|
101
|
+
fromKeys(keys: string): void {
|
|
102
|
+
const q = new URLSearchParams(keys)
|
|
103
|
+
this.side = q.get('side') ?? ''
|
|
104
|
+
const mode = q.get('mode')
|
|
105
|
+
this.mode = mode === 'thumb' || mode === 'lightbox' ? mode : ''
|
|
106
|
+
const view = q.get('view')
|
|
107
|
+
this.view = VIEWS.find((v) => v === view) ?? null
|
|
108
|
+
this.cam = camOf(q.get('cam'))
|
|
109
|
+
this.thumbAgain = q.get('thumb') === 'again'
|
|
110
|
+
const state = q.get('state') ?? ''
|
|
111
|
+
if (state !== '' && state !== this.stateUrl) void this.loadState(state)
|
|
112
|
+
else if (state === '') {
|
|
113
|
+
this.name = q.get('key') ?? ''
|
|
114
|
+
this.wanted = Object.values(FILE_OF)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async boot(): Promise<void> {
|
|
119
|
+
try {
|
|
120
|
+
const r = await fetch('api/worlds')
|
|
121
|
+
if (!r.ok) throw new Error(`api/worlds: ${r.status}`)
|
|
122
|
+
const all = (await r.json()) as WorldInfo[]
|
|
123
|
+
runInAction(() => (this.all = all))
|
|
124
|
+
} catch (e) {
|
|
125
|
+
runInAction(() => (this.error = (e as Error).message))
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private async loadState(url: string): Promise<void> {
|
|
130
|
+
this.stateUrl = url
|
|
131
|
+
try {
|
|
132
|
+
const r = await fetch(url)
|
|
133
|
+
if (!r.ok) throw new Error(`the version's state: ${r.status} ${await r.text()}`)
|
|
134
|
+
const s = (await r.json()) as { json?: { name?: unknown; files?: unknown } }
|
|
135
|
+
const name = s.json?.name
|
|
136
|
+
const files = s.json?.files
|
|
137
|
+
if (typeof name !== 'string') throw new Error('the version names no world')
|
|
138
|
+
runInAction(() => {
|
|
139
|
+
this.name = name
|
|
140
|
+
this.wanted = Array.isArray(files)
|
|
141
|
+
? files.filter((f): f is string => typeof f === 'string')
|
|
142
|
+
: Object.values(FILE_OF)
|
|
143
|
+
this.error = null
|
|
144
|
+
})
|
|
145
|
+
} catch (e) {
|
|
146
|
+
runInAction(() => (this.error = (e as Error).message))
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** standalone: every file of the world on disk */
|
|
151
|
+
get standalone(): boolean {
|
|
152
|
+
return this.stateUrl === ''
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
setView(v: View): void {
|
|
156
|
+
if (v === this.shown) return
|
|
157
|
+
this.view = v
|
|
158
|
+
this.cam = { ...CAM0 }
|
|
159
|
+
this.moved()
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** his move in the viewer: the eye as it is now, posted with the other keys */
|
|
163
|
+
setCam(c: Cam): void {
|
|
164
|
+
this.cam = c
|
|
165
|
+
this.moved()
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private postTimer: ReturnType<typeof setTimeout> | null = null
|
|
169
|
+
private postedAt = 0
|
|
170
|
+
|
|
171
|
+
/** his move: the keys go out now, or once the last post is POST_MS old */
|
|
172
|
+
private moved(): void {
|
|
173
|
+
const wait = this.postedAt + POST_MS - performance.now()
|
|
174
|
+
if (wait <= 0) {
|
|
175
|
+
this.postedAt = performance.now()
|
|
176
|
+
this.post(this.keys)
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
if (this.postTimer != null) return
|
|
180
|
+
this.postTimer = setTimeout(() => {
|
|
181
|
+
this.postTimer = null
|
|
182
|
+
this.postedAt = performance.now()
|
|
183
|
+
this.post(this.keys)
|
|
184
|
+
}, wait)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** the page fills the screen (the browser's fullscreen on its root): the lightbox */
|
|
188
|
+
full = false
|
|
189
|
+
/** a line that says what did not happen (a fullscreen the frame refused), gone after a few seconds */
|
|
190
|
+
notice: string | null = null
|
|
191
|
+
|
|
192
|
+
setFull(on: boolean): void {
|
|
193
|
+
this.full = on
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
setNotice(n: string | null): void {
|
|
197
|
+
this.notice = n
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** his first move hides the hint */
|
|
201
|
+
get touched(): boolean {
|
|
202
|
+
return camText(this.cam) !== ''
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
setLoading(what: string | null): void {
|
|
206
|
+
this.loading = what
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
setError(e: string | null): void {
|
|
210
|
+
this.error = e
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
html,
|
|
2
|
+
body,
|
|
3
|
+
#root {
|
|
4
|
+
height: 100%;
|
|
5
|
+
margin: 0;
|
|
6
|
+
background: #0d0e10;
|
|
7
|
+
color: #d8d9dc;
|
|
8
|
+
font:
|
|
9
|
+
13px system-ui,
|
|
10
|
+
sans-serif;
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.app {
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
height: 100%;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.bar {
|
|
21
|
+
display: flex;
|
|
22
|
+
align-items: center;
|
|
23
|
+
gap: 4px;
|
|
24
|
+
padding: 4px 6px;
|
|
25
|
+
flex: none;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.tab {
|
|
29
|
+
font: inherit;
|
|
30
|
+
color: #9a9ca3;
|
|
31
|
+
background: none;
|
|
32
|
+
border: 1px solid transparent;
|
|
33
|
+
border-radius: 6px;
|
|
34
|
+
padding: 2px 9px;
|
|
35
|
+
cursor: pointer;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.tab.on {
|
|
39
|
+
color: #e8e8ea;
|
|
40
|
+
border-color: #3a3d45;
|
|
41
|
+
background: #1d1f24;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.line {
|
|
45
|
+
margin-left: 6px;
|
|
46
|
+
color: #8a8c93;
|
|
47
|
+
white-space: nowrap;
|
|
48
|
+
overflow: hidden;
|
|
49
|
+
text-overflow: ellipsis;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.line b {
|
|
53
|
+
color: #d8d9dc;
|
|
54
|
+
font-weight: 500;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.stage {
|
|
58
|
+
position: relative;
|
|
59
|
+
flex: 1;
|
|
60
|
+
min-height: 0;
|
|
61
|
+
touch-action: none;
|
|
62
|
+
user-select: none;
|
|
63
|
+
cursor: grab;
|
|
64
|
+
outline: none;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.view {
|
|
68
|
+
position: absolute;
|
|
69
|
+
inset: 0;
|
|
70
|
+
outline: none;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.stage canvas,
|
|
74
|
+
.stage img {
|
|
75
|
+
position: absolute;
|
|
76
|
+
inset: 0;
|
|
77
|
+
width: 100%;
|
|
78
|
+
height: 100%;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.stage img {
|
|
82
|
+
object-fit: contain;
|
|
83
|
+
cursor: default;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.note {
|
|
87
|
+
position: absolute;
|
|
88
|
+
inset: 0;
|
|
89
|
+
display: grid;
|
|
90
|
+
place-items: center;
|
|
91
|
+
color: #8a8c93;
|
|
92
|
+
pointer-events: none;
|
|
93
|
+
text-align: center;
|
|
94
|
+
padding: 12px;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.worlds a {
|
|
98
|
+
display: block;
|
|
99
|
+
color: #d8d9dc;
|
|
100
|
+
padding: 2px 0;
|
|
101
|
+
pointer-events: auto;
|
|
102
|
+
}
|
|
103
|
+
.tools {
|
|
104
|
+
margin-left: auto;
|
|
105
|
+
display: flex;
|
|
106
|
+
gap: 4px;
|
|
107
|
+
flex: none;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* the hub panorama's hint: a pill at the foot of the view */
|
|
111
|
+
.hint {
|
|
112
|
+
position: absolute;
|
|
113
|
+
left: 50%;
|
|
114
|
+
bottom: 10px;
|
|
115
|
+
transform: translateX(-50%);
|
|
116
|
+
max-width: calc(100% - 24px);
|
|
117
|
+
padding: 3px 12px;
|
|
118
|
+
border-radius: 999px;
|
|
119
|
+
background: color-mix(in srgb, #000 55%, transparent);
|
|
120
|
+
color: #d8d9dc;
|
|
121
|
+
font-size: 12px;
|
|
122
|
+
white-space: nowrap;
|
|
123
|
+
overflow: hidden;
|
|
124
|
+
text-overflow: ellipsis;
|
|
125
|
+
pointer-events: none;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.hint.notice {
|
|
129
|
+
bottom: 40px;
|
|
130
|
+
color: #ffb4b4;
|
|
131
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// a world's thumbnail: what the view shows at its default camera, 640 px wide, sent to the server that keeps it as
|
|
2
|
+
// .comfy-ts/worlds/<name>/thumb.webp. A 3D view gives it by `View3d.snapshot`, the picture view by its <img>
|
|
3
|
+
export const THUMB_W = 640
|
|
4
|
+
|
|
5
|
+
export async function sendThumb(name: string, src: CanvasImageSource, w: number, h: number): Promise<void> {
|
|
6
|
+
if (w <= 0 || h <= 0) return
|
|
7
|
+
const c = document.createElement('canvas')
|
|
8
|
+
c.width = THUMB_W
|
|
9
|
+
c.height = Math.round((THUMB_W * h) / w)
|
|
10
|
+
const g = c.getContext('2d')
|
|
11
|
+
if (g == null) throw new Error('thumbnail: no 2d context')
|
|
12
|
+
g.drawImage(src, 0, 0, c.width, c.height)
|
|
13
|
+
const blob = await new Promise<Blob | null>((res) => c.toBlob(res, 'image/webp', 0.85))
|
|
14
|
+
if (blob == null) throw new Error('thumbnail: the browser made no webp')
|
|
15
|
+
await postThumb(name, blob)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function postThumb(name: string, blob: Blob): Promise<void> {
|
|
19
|
+
const r = await fetch(`api/thumb/${encodeURIComponent(name)}`, { method: 'POST', body: blob })
|
|
20
|
+
if (!r.ok) throw new Error(`thumbnail of ${name}: ${r.status} ${await r.text()}`)
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
// the world explorer page: dom-typed like examples/web, so it keeps its own config
|
|
3
|
+
"extends": "../../../tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
|
|
6
|
+
"tsBuildInfoFile": "../../../node_modules/.cache/tsbuildinfo-world-explorer-web.json"
|
|
7
|
+
},
|
|
8
|
+
// MUST override the root's exclude, which lists this directory
|
|
9
|
+
"exclude": [],
|
|
10
|
+
"include": ["."]
|
|
11
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// the state of a `world:<name>` thread version, from the files its folder holds: `{ json: { name, files }, views, card? }`.
|
|
2
|
+
// `views` is one still per view with its legend (the page's `view` key, the word under it); the card (title, chips,
|
|
3
|
+
// sizes) is the hub's line under the stills, `--card` adds it
|
|
4
|
+
//
|
|
5
|
+
// usage: bun examples/world-explorer/world-state.ts <name> [--card] → prints the state file's path
|
|
6
|
+
// then: sk thread post world:<name> --title … --what … --after <path> --image .comfy-ts/worlds/<name>/thumb.webp
|
|
7
|
+
import { existsSync, readdirSync, statSync, writeFileSync } from 'node:fs'
|
|
8
|
+
import { join } from 'pathe'
|
|
9
|
+
|
|
10
|
+
/** the file each view draws, its id (the page's `view` key) and its legend under the still */
|
|
11
|
+
const VIEWS: [file: string, label: string, id: string][] = [
|
|
12
|
+
['panorama.png', '360°', 'pano'],
|
|
13
|
+
['world.glb', 'walk', 'world'],
|
|
14
|
+
['splat.ply', 'splat', 'splat'],
|
|
15
|
+
['source.png', 'picture', 'source'],
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
const name = process.argv[2]
|
|
19
|
+
if (name == null || name.startsWith('-')) throw new Error('usage: world-state.ts <name> [--card]')
|
|
20
|
+
const dir = join(process.cwd(), '.comfy-ts/worlds', name)
|
|
21
|
+
if (!existsSync(dir)) throw new Error(`no world folder ${dir}`)
|
|
22
|
+
const present = new Set(readdirSync(dir))
|
|
23
|
+
const files = VIEWS.map(([f]) => f).filter((f) => present.has(f))
|
|
24
|
+
if (files.length === 0) throw new Error(`${dir} holds none of ${VIEWS.map(([f]) => f).join(', ')}`)
|
|
25
|
+
|
|
26
|
+
const mb = (f: string): string => `${(statSync(join(dir, f)).size / 1e6).toFixed(0)} MB`
|
|
27
|
+
const card = {
|
|
28
|
+
kind: 'world',
|
|
29
|
+
title: name,
|
|
30
|
+
chips: VIEWS.filter(([f]) => present.has(f)).map(([, v]) => v),
|
|
31
|
+
fields: [
|
|
32
|
+
...(present.has('world.glb') ? [{ label: 'mesh', text: mb('world.glb') }] : []),
|
|
33
|
+
...(present.has('splat.ply') ? [{ label: 'splat', text: mb('splat.ply') }] : []),
|
|
34
|
+
],
|
|
35
|
+
}
|
|
36
|
+
const views = VIEWS.filter(([f]) => present.has(f)).map(([, label, id]) => ({ id, label }))
|
|
37
|
+
const state = { json: { name, files }, views, ...(process.argv.includes('--card') ? { card } : {}) }
|
|
38
|
+
const out = join(dir, 'state.json')
|
|
39
|
+
writeFileSync(out, JSON.stringify(state, null, 2))
|
|
40
|
+
console.log(out)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comfy-ts",
|
|
3
|
-
"version": "2.
|
|
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,19 +73,17 @@
|
|
|
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",
|
|
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
|
-
"format": "oxfmt src examples scripts tests",
|
|
79
|
-
"format:check": "oxfmt --check src examples scripts tests",
|
|
80
78
|
"imports:check": "rvt imports --check",
|
|
81
79
|
"imports:fix": "rvt imports --fix",
|
|
82
80
|
"cycles": "rvt cycles 1",
|
|
83
81
|
"rename": "rvt rename",
|
|
84
|
-
"ci": "bun run typecheck && bun run lint && bun run
|
|
82
|
+
"ci": "bun run typecheck && bun run lint && bun run imports:check && bun run test",
|
|
85
83
|
"ci:local": "bun run ci && bun run typecheck:full",
|
|
86
84
|
"gen:manager": "bun src/manager/script-update-manager.bun.ts",
|
|
87
85
|
"gen:sdk": "bun scripts/gen-sdk-from-cache.ts",
|
|
88
|
-
"gen:sdk:cloud": "bun src/cli/comfy-ts-cli.ts gen --id comfy-cloud --host https://cloud.comfy.org --out examples/comfy-cloud/sdk.d.ts
|
|
86
|
+
"gen:sdk:cloud": "bun src/cli/comfy-ts-cli.ts gen --id comfy-cloud --host https://cloud.comfy.org --out examples/comfy-cloud/sdk.d.ts",
|
|
89
87
|
"sdk:outline": "bun scripts/sdk-outline.ts",
|
|
90
88
|
"loras": "bun src/cli/comfy-ts-cli.ts loras",
|
|
91
89
|
"examples:images": "bun scripts/fetch-example-images.ts",
|
|
@@ -103,6 +101,8 @@
|
|
|
103
101
|
"serve:0000:rvion": "bun src/cli/comfy-ts-cli.ts serve --host 0.0.0.0 examples/rvion",
|
|
104
102
|
"serve:rvion": "bun --watch src/cli/comfy-ts-cli.ts serve examples/rvion",
|
|
105
103
|
"depth": "bun examples/depth-explorer/serve.ts",
|
|
104
|
+
"world": "bun --watch examples/world-explorer/serve.ts",
|
|
105
|
+
"upscale": "bun examples/upscale-explorer/serve.ts",
|
|
106
106
|
"check:panel-scroll": "bun scripts/check-panel-scroll.ts"
|
|
107
107
|
},
|
|
108
108
|
"rvt": {
|
|
@@ -140,10 +140,9 @@
|
|
|
140
140
|
"@types/react": "^19.2.17",
|
|
141
141
|
"@types/react-dom": "^19.2.3",
|
|
142
142
|
"@types/ws": "^8.18.1",
|
|
143
|
-
"oxfmt": "^0.60.0",
|
|
144
143
|
"oxlint": "^1.75.0",
|
|
145
144
|
"oxlint-tsgolint": "^7.0.2001",
|
|
146
|
-
"rvlib-shipkit": "^2.
|
|
145
|
+
"rvlib-shipkit": "^2.29.0",
|
|
147
146
|
"rvlib-ts-tools": "^0.3.3",
|
|
148
147
|
"tsdown": "^0.22.14",
|
|
149
148
|
"typescript": "^7.0.2"
|