comfy-ts 2.7.0 → 2.9.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/README.md +20 -13
- package/dist/{DefinedWorkflow-BJgt5t0x.js → DefinedWorkflow-BatWaZO1.js} +199 -16
- package/dist/DefinedWorkflow-BatWaZO1.js.map +1 -0
- package/dist/{DraftsSt-dizp3VcC.js → LogsSt-DFxzQfDc.js} +152 -4
- package/dist/LogsSt-DFxzQfDc.js.map +1 -0
- package/dist/cli.js +7 -5
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +284 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +125 -7
- package/dist/index.d.ts +125 -7
- package/dist/index.js +282 -37
- package/dist/index.js.map +1 -1
- package/dist/run-serve-_nrvJYyt.js +1948 -0
- package/dist/run-serve-_nrvJYyt.js.map +1 -0
- package/dist/{run-tui-JxlEbb_f.js → run-tui-BLEdTsOX.js} +106 -157
- package/dist/run-tui-BLEdTsOX.js.map +1 -0
- package/dist/serve-web.js +441 -72
- package/dist/{state-CaHeDL-0.js → state-BbgJeCe6.js} +180 -45
- package/dist/state-BbgJeCe6.js.map +1 -0
- package/dist/web.d.ts +185 -7
- package/dist/web.js +235 -36
- package/dist/web.js.map +1 -1
- package/examples/README.md +1 -0
- package/examples/comfy-cloud/sdk.d.ts +4066 -321
- package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +18 -2
- package/examples/rvion/07-local-llm-text-gen.cflow.ts +220 -0
- package/examples/web/tsconfig.json +3 -0
- package/extra/README.md +32 -0
- package/extra/comfyui-textgen-stream/README.md +35 -0
- package/extra/comfyui-textgen-stream/__init__.py +166 -0
- package/extra/scripts/fetch_text_encoder.py +137 -0
- package/package.json +6 -3
- package/src/cli/comfy-ts-cli.ts +3 -1
- package/src/cli/serve/ServeApp.ts +754 -40
- package/src/cli/serve/applyVarPayload.ts +10 -3
- package/src/cli/serve/describeVar.ts +47 -7
- package/src/cli/serve/hostProtocol.ts +68 -0
- package/src/cli/serve/managerOnlyLoras.ts +27 -0
- package/src/cli/serve/run-serve.ts +35 -38
- package/src/cli/serve/serveSettings.ts +86 -0
- package/src/cli/serve/startupPrint.ts +111 -0
- package/src/cli/serve/web/api.ts +97 -1
- package/src/cli/serve/web/components/App.tsx +61 -22
- package/src/cli/serve/web/components/Gallery.tsx +306 -41
- package/src/cli/serve/web/components/Icon.tsx +160 -0
- package/src/cli/serve/web/components/PromptEnhancer.tsx +12 -9
- package/src/cli/serve/web/components/Sidebar.tsx +43 -19
- package/src/cli/serve/web/components/VarsForm.tsx +440 -91
- package/src/cli/serve/web/components/controls/BasicControls.tsx +38 -5
- package/src/cli/serve/web/components/controls/ImageControl.tsx +3 -2
- package/src/cli/serve/web/components/controls/LorasControl.tsx +498 -81
- package/src/cli/serve/web/components/controls/PresetPicker.tsx +60 -0
- package/src/cli/serve/web/components/controls/SeedControl.tsx +38 -20
- package/src/cli/serve/web/components/controls/SizeControl.tsx +3 -2
- package/src/cli/serve/web/llm.ts +1 -1
- package/src/cli/serve/web/logWeb.ts +6 -0
- package/src/cli/serve/web/state/EnhancerSt.ts +8 -15
- package/src/cli/serve/web/state/FormSt.ts +74 -18
- package/src/cli/serve/web/state/RunSt.ts +22 -1
- package/src/cli/serve/web/state/WebSt.ts +814 -22
- package/src/cli/serve/web/state/host.ts +206 -0
- package/src/cli/serve/web/state/lightbox.ts +44 -0
- package/src/cli/serve/web/state/moduleTree.ts +52 -0
- package/src/cli/serve/web/state/payload.ts +44 -2
- package/src/cli/serve/web/state/urlSelection.ts +53 -0
- package/src/cli/serve/web/styles.ts +422 -57
- package/src/cli/serve/web/tsconfig.json +4 -0
- package/src/cli/tui/components/PickerOverlays.tsx +37 -0
- package/src/cli/tui/components/StatusBar.tsx +14 -1
- package/src/cli/tui/components/TuiApp.tsx +5 -2
- package/src/cli/tui/state/HostSt.ts +3 -2
- package/src/cli/tui/state/PickerSt.ts +48 -2
- package/src/cli/tui/state/TreeSt.ts +1 -1
- package/src/cli/tui/state/TuiSt.ts +2 -1
- package/src/coreExports.ts +8 -1
- package/src/graph/ComfyNode.ts +58 -1
- package/src/host/ComfyHost.ts +13 -2
- package/src/host/ComfyManager.ts +31 -13
- package/src/host/loraInfoCache.ts +35 -1
- package/src/host/loraManagerApi.ts +94 -0
- package/src/index.ts +2 -0
- package/src/promptEnhancers.ts +102 -0
- package/src/runner/ComfyExecution.ts +61 -6
- package/src/runner/ComfyWorkflow.ts +18 -4
- package/src/runner/ComfyWsApi.ts +3 -0
- package/src/runner/describePromptRejection.ts +34 -0
- package/src/sdk-generator/ComfySchema.ts +17 -4
- package/src/sdk-generator/comfyui-sdk-codegen.ts +56 -2
- package/src/utils/ansi.ts +13 -0
- package/src/utils/matchesRegex.ts +13 -0
- package/src/utils/safeName.ts +29 -0
- package/src/utils/stringMap.ts +9 -0
- package/src/vars/ComfyVars.ts +61 -10
- package/src/vars/presets.ts +17 -0
- package/src/web.ts +12 -0
- package/dist/DefinedWorkflow-BJgt5t0x.js.map +0 -1
- package/dist/DraftsSt-dizp3VcC.js.map +0 -1
- package/dist/run-serve-D1Tsuru9.js +0 -1162
- package/dist/run-serve-D1Tsuru9.js.map +0 -1
- package/dist/run-tui-JxlEbb_f.js.map +0 -1
- package/dist/state-CaHeDL-0.js.map +0 -1
- package/src/cli/serve/promptEnhancers.ts +0 -69
- package/src/cli/serve/safeName.ts +0 -12
|
@@ -1,12 +1,41 @@
|
|
|
1
|
-
// layout root:
|
|
2
|
-
//
|
|
1
|
+
// layout root: sidebar drawer + form column + results column (right on wide
|
|
2
|
+
// screens, below on narrow ones). NO title bar: the workflow head box opens the
|
|
3
|
+
// sidebar, so a permanent bar would only spend vertical space naming the app
|
|
3
4
|
import { observer } from 'mobx-react-lite'
|
|
5
|
+
import { useEffect } from 'react'
|
|
4
6
|
import { Gallery } from 'src/cli/serve/web/components/Gallery.tsx'
|
|
5
7
|
import { Sidebar } from 'src/cli/serve/web/components/Sidebar.tsx'
|
|
6
|
-
import { VarsForm } from 'src/cli/serve/web/components/VarsForm.tsx'
|
|
8
|
+
import { GenerateButton, VarsForm } from 'src/cli/serve/web/components/VarsForm.tsx'
|
|
7
9
|
import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
|
|
8
10
|
|
|
11
|
+
/** ⌘A / ctrl+A selects the field you are in. The browser does this on its own until something
|
|
12
|
+
* on the page consumes the event, and this panel has several window-level key handlers plus a
|
|
13
|
+
* drag layer over the rows, rather than hunt which one wins on which browser, the select is
|
|
14
|
+
* performed explicitly. It runs ONLY when focus is already in a text field, so the
|
|
15
|
+
* whole-page select-all everywhere else is untouched. */
|
|
16
|
+
function useSelectAllInFields(): void {
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const onKey = (e: KeyboardEvent): void => {
|
|
19
|
+
if (e.key !== 'a' && e.key !== 'A') return
|
|
20
|
+
if (!e.metaKey && !e.ctrlKey) return
|
|
21
|
+
if (e.altKey) return
|
|
22
|
+
const el = document.activeElement
|
|
23
|
+
const editable =
|
|
24
|
+
el instanceof HTMLInputElement
|
|
25
|
+
? // a number/checkbox input has no text to select
|
|
26
|
+
el.type === 'text' || el.type === 'search' || el.type === 'password' || el.type === 'url'
|
|
27
|
+
: el instanceof HTMLTextAreaElement
|
|
28
|
+
if (!editable) return
|
|
29
|
+
e.preventDefault()
|
|
30
|
+
;(el as HTMLInputElement | HTMLTextAreaElement).select()
|
|
31
|
+
}
|
|
32
|
+
window.addEventListener('keydown', onKey)
|
|
33
|
+
return () => window.removeEventListener('keydown', onKey)
|
|
34
|
+
}, [])
|
|
35
|
+
}
|
|
36
|
+
|
|
9
37
|
export const App = observer(function App(p: { st: WebSt }) {
|
|
38
|
+
useSelectAllInFields()
|
|
10
39
|
if (p.st.phase === 'loading') return <div className="center">loading…</div>
|
|
11
40
|
if (p.st.phase === 'error')
|
|
12
41
|
return (
|
|
@@ -16,21 +45,6 @@ export const App = observer(function App(p: { st: WebSt }) {
|
|
|
16
45
|
)
|
|
17
46
|
return (
|
|
18
47
|
<div className="app">
|
|
19
|
-
<div className="topbar">
|
|
20
|
-
<button
|
|
21
|
-
type="button"
|
|
22
|
-
className="burger"
|
|
23
|
-
title="toggle the workflow menu"
|
|
24
|
-
onClick={() => p.st.toggleSidebar()}
|
|
25
|
-
>
|
|
26
|
-
☰
|
|
27
|
-
</button>
|
|
28
|
-
<h1>comfy-ts serve</h1>
|
|
29
|
-
<span className="dim">
|
|
30
|
-
{p.st.modules.length} workflow{p.st.modules.length === 1 ? '' : 's'} · drafts are the base, edits
|
|
31
|
-
override per run
|
|
32
|
-
</span>
|
|
33
|
-
</div>
|
|
34
48
|
<div className="cols">
|
|
35
49
|
{p.st.sidebarOpen ? <div className="backdrop" onClick={() => p.st.toggleSidebar()} /> : null}
|
|
36
50
|
{p.st.sidebarOpen ? <Sidebar st={p.st} /> : null}
|
|
@@ -38,13 +52,38 @@ export const App = observer(function App(p: { st: WebSt }) {
|
|
|
38
52
|
{p.st.formError != null ? <div className="center error">🔴 {p.st.formError}</div> : null}
|
|
39
53
|
{p.st.formLoading && p.st.form == null ? <div className="center">loading draft…</div> : null}
|
|
40
54
|
{p.st.modules.length === 0 ? <div className="center">no workflow modules loaded</div> : null}
|
|
41
|
-
|
|
55
|
+
{/* the layout buttons drive ONE class, and it is the whole truth: the selected
|
|
56
|
+
button always names where the panel is */}
|
|
57
|
+
<div className={`work layout-${p.st.layout}`}>
|
|
42
58
|
<div className="form-col">
|
|
43
59
|
<VarsForm st={p.st} />
|
|
60
|
+
{/* the ComfyUI console, only while asked for (it polls) */}
|
|
61
|
+
{p.st.showLogs ? (
|
|
62
|
+
<div className="logs">
|
|
63
|
+
<div className="logs-head">
|
|
64
|
+
{/* the host the lines actually come from (pullLogs uses hostFor),
|
|
65
|
+
not the module's declared default */}
|
|
66
|
+
<span>console · {p.st.hostFor(p.st.form?.moduleKey ?? '') || 'host'}</span>
|
|
67
|
+
<button type="button" className="link" onClick={() => p.st.toggleLogs()}>
|
|
68
|
+
hide
|
|
69
|
+
</button>
|
|
70
|
+
</div>
|
|
71
|
+
{p.st.logsError != null ? <div className="error">🔴 {p.st.logsError}</div> : null}
|
|
72
|
+
<pre>{p.st.logLines.join('\n')}</pre>
|
|
73
|
+
</div>
|
|
74
|
+
) : null}
|
|
44
75
|
</div>
|
|
45
|
-
|
|
46
|
-
<
|
|
47
|
-
|
|
76
|
+
{p.st.layout === 'off' ? null : (
|
|
77
|
+
<div className="results-col">
|
|
78
|
+
{p.st.generateInResults ? (
|
|
79
|
+
<div className="results-run">
|
|
80
|
+
<GenerateButton st={p.st} />
|
|
81
|
+
{p.st.run.error != null ? <span className="error">🔴 {p.st.run.error}</span> : null}
|
|
82
|
+
</div>
|
|
83
|
+
) : null}
|
|
84
|
+
<Gallery st={p.st} compact={p.st.layout === 'pinned'} />
|
|
85
|
+
</div>
|
|
86
|
+
)}
|
|
48
87
|
</div>
|
|
49
88
|
</div>
|
|
50
89
|
</div>
|
|
@@ -2,50 +2,114 @@
|
|
|
2
2
|
// included) opens the LIGHTBOX (esc/backdrop closes; copy / open / delete
|
|
3
3
|
// inside). copy needs a secure context (localhost is one, LAN http is not) —
|
|
4
4
|
// the button hides where the clipboard api is absent
|
|
5
|
+
import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
|
|
5
6
|
import { observer, useLocalObservable } from 'mobx-react-lite'
|
|
6
|
-
import { useEffect } from 'react'
|
|
7
|
+
import { useEffect, useRef } from 'react'
|
|
7
8
|
import { runPreviewSrc } from 'src/cli/serve/web/api.ts'
|
|
9
|
+
import { lightboxView, type LightboxTarget } from 'src/cli/serve/web/state/lightbox.ts'
|
|
8
10
|
import { copyImageToClipboard } from 'src/cli/serve/web/clipboard.ts'
|
|
9
11
|
import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
|
|
10
12
|
|
|
11
13
|
const canCopy = typeof navigator !== 'undefined' && navigator.clipboard != null
|
|
12
14
|
|
|
13
|
-
type LightboxTarget = { url: string; title: string; promptId: string | null }
|
|
14
|
-
|
|
15
15
|
type GalleryLocal = {
|
|
16
16
|
copyNote: { url: string; text: string } | null
|
|
17
17
|
lightbox: LightboxTarget | null
|
|
18
|
+
/** lightbox zoom: 1 = fitted. Pan is only meaningful past 1 */
|
|
19
|
+
zoom: number
|
|
20
|
+
panX: number
|
|
21
|
+
panY: number
|
|
18
22
|
setCopyNote(url: string, text: string): void
|
|
19
23
|
openLightbox(target: LightboxTarget): void
|
|
20
24
|
closeLightbox(): void
|
|
25
|
+
zoomBy(factor: number, at: { x: number; y: number }): void
|
|
26
|
+
panBy(dx: number, dy: number): void
|
|
27
|
+
resetZoom(): void
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
function useGalleryLocal(): GalleryLocal {
|
|
24
31
|
return useLocalObservable<GalleryLocal>(() => ({
|
|
25
32
|
copyNote: null,
|
|
26
33
|
lightbox: null,
|
|
34
|
+
zoom: 1,
|
|
35
|
+
panX: 0,
|
|
36
|
+
panY: 0,
|
|
27
37
|
setCopyNote(url: string, text: string) {
|
|
28
38
|
this.copyNote = { url, text }
|
|
29
39
|
},
|
|
30
40
|
openLightbox(target: LightboxTarget) {
|
|
31
41
|
this.lightbox = target
|
|
42
|
+
this.resetZoom()
|
|
32
43
|
},
|
|
33
44
|
closeLightbox() {
|
|
34
45
|
this.lightbox = null
|
|
46
|
+
this.resetZoom()
|
|
47
|
+
},
|
|
48
|
+
/** zoom around the CURSOR: the point under the pointer stays under it, which is what
|
|
49
|
+
* makes wheel zoom usable, a centre-anchored zoom walks the detail off screen */
|
|
50
|
+
zoomBy(factor: number, at: { x: number; y: number }) {
|
|
51
|
+
const next = Math.min(8, Math.max(1, this.zoom * factor))
|
|
52
|
+
if (next === this.zoom) return
|
|
53
|
+
const ratio = next / this.zoom
|
|
54
|
+
this.panX = at.x - (at.x - this.panX) * ratio
|
|
55
|
+
this.panY = at.y - (at.y - this.panY) * ratio
|
|
56
|
+
this.zoom = next
|
|
57
|
+
if (next === 1) {
|
|
58
|
+
this.panX = 0
|
|
59
|
+
this.panY = 0
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
panBy(dx: number, dy: number) {
|
|
63
|
+
if (this.zoom === 1) return
|
|
64
|
+
this.panX += dx
|
|
65
|
+
this.panY += dy
|
|
66
|
+
},
|
|
67
|
+
resetZoom() {
|
|
68
|
+
this.zoom = 1
|
|
69
|
+
this.panX = 0
|
|
70
|
+
this.panY = 0
|
|
35
71
|
},
|
|
36
72
|
}))
|
|
37
73
|
}
|
|
38
74
|
|
|
39
75
|
const Lightbox = observer(function Lightbox(p: { st: WebSt; local: GalleryLocal }) {
|
|
40
|
-
const
|
|
76
|
+
const target = p.local.lightbox
|
|
77
|
+
const box =
|
|
78
|
+
target == null
|
|
79
|
+
? null
|
|
80
|
+
: lightboxView({
|
|
81
|
+
target,
|
|
82
|
+
isRunning: p.st.run.isRunning,
|
|
83
|
+
previewTick: p.st.run.previewTick,
|
|
84
|
+
results: p.st.run.results,
|
|
85
|
+
})
|
|
41
86
|
useEffect(() => {
|
|
42
|
-
if (
|
|
87
|
+
if (target == null) return
|
|
43
88
|
const onKey = (e: KeyboardEvent): void => {
|
|
44
89
|
if (e.key === 'Escape') p.local.closeLightbox()
|
|
45
90
|
}
|
|
46
91
|
window.addEventListener('keydown', onKey)
|
|
47
92
|
return () => window.removeEventListener('keydown', onKey)
|
|
48
|
-
}, [
|
|
93
|
+
}, [target, p.local])
|
|
94
|
+
// wheel is registered BY HAND, non-passive. React attaches wheel at the root as passive, so
|
|
95
|
+
// its onWheel cannot preventDefault: zooming also scrolled the results column behind the
|
|
96
|
+
// lightbox, and every tick logged a console error
|
|
97
|
+
const zoomRef = useRef<HTMLDivElement>(null)
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
const el = zoomRef.current
|
|
100
|
+
if (el == null) return
|
|
101
|
+
const onWheel = (e: WheelEvent): void => {
|
|
102
|
+
e.preventDefault()
|
|
103
|
+
const rect = el.getBoundingClientRect()
|
|
104
|
+
// deltaY is per-line on some mice and per-pixel on others: sign only
|
|
105
|
+
p.local.zoomBy(e.deltaY < 0 ? 1.2 : 1 / 1.2, {
|
|
106
|
+
x: e.clientX - rect.left - rect.width / 2,
|
|
107
|
+
y: e.clientY - rect.top - rect.height / 2,
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
el.addEventListener('wheel', onWheel, { passive: false })
|
|
111
|
+
return () => el.removeEventListener('wheel', onWheel)
|
|
112
|
+
}, [target, p.local])
|
|
49
113
|
if (box == null) return null
|
|
50
114
|
const copy = (): void => {
|
|
51
115
|
copyImageToClipboard(box.url)
|
|
@@ -57,11 +121,43 @@ const Lightbox = observer(function Lightbox(p: { st: WebSt; local: GalleryLocal
|
|
|
57
121
|
return (
|
|
58
122
|
<div className="modal-overlay" onClick={() => p.local.closeLightbox()}>
|
|
59
123
|
<div className="lightbox" onClick={(e) => e.stopPropagation()}>
|
|
60
|
-
<
|
|
124
|
+
<div
|
|
125
|
+
ref={zoomRef}
|
|
126
|
+
className={p.local.zoom > 1 ? 'zoom-view grabbing' : 'zoom-view'}
|
|
127
|
+
onDoubleClick={() => p.local.resetZoom()}
|
|
128
|
+
onPointerDown={(e) => {
|
|
129
|
+
if (p.local.zoom === 1) return
|
|
130
|
+
e.currentTarget.setPointerCapture(e.pointerId)
|
|
131
|
+
}}
|
|
132
|
+
onPointerMove={(e) => {
|
|
133
|
+
if (e.buttons !== 1) return
|
|
134
|
+
p.local.panBy(e.movementX, e.movementY)
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
<img
|
|
138
|
+
src={box.url}
|
|
139
|
+
alt={box.title}
|
|
140
|
+
draggable={false}
|
|
141
|
+
style={{
|
|
142
|
+
transform: `translate(${p.local.panX}px, ${p.local.panY}px) scale(${p.local.zoom})`,
|
|
143
|
+
}}
|
|
144
|
+
/>
|
|
145
|
+
</div>
|
|
61
146
|
<div className="lightbox-bar">
|
|
62
|
-
<span className="hint"
|
|
147
|
+
<span className="hint" data-tip={box.title}>
|
|
63
148
|
{box.title}
|
|
64
149
|
</span>
|
|
150
|
+
{p.local.zoom > 1 ? (
|
|
151
|
+
<button
|
|
152
|
+
type="button"
|
|
153
|
+
data-tip="back to fit (or double click the image)"
|
|
154
|
+
onClick={() => p.local.resetZoom()}
|
|
155
|
+
>
|
|
156
|
+
{p.local.zoom.toFixed(1)}× · fit
|
|
157
|
+
</button>
|
|
158
|
+
) : (
|
|
159
|
+
<span className="hint">scroll to zoom</span>
|
|
160
|
+
)}
|
|
65
161
|
{canCopy ? (
|
|
66
162
|
<button type="button" onClick={copy}>
|
|
67
163
|
copy
|
|
@@ -70,10 +166,28 @@ const Lightbox = observer(function Lightbox(p: { st: WebSt; local: GalleryLocal
|
|
|
70
166
|
<a href={box.url} target="_blank" rel="noreferrer">
|
|
71
167
|
open ↗
|
|
72
168
|
</a>
|
|
169
|
+
{box.promptId != null
|
|
170
|
+
? p.st.hostActions.map((a) => {
|
|
171
|
+
const run = p.st.run.results.find((r) => r.promptId === box.promptId)
|
|
172
|
+
const ix = run?.images.findIndex((i) => i.url === box.url) ?? -1
|
|
173
|
+
if (run == null || ix < 0) return null
|
|
174
|
+
return (
|
|
175
|
+
<button
|
|
176
|
+
key={a.id}
|
|
177
|
+
type="button"
|
|
178
|
+
className="host-action"
|
|
179
|
+
data-tip={a.title}
|
|
180
|
+
onClick={() => p.st.postResultAction(a.id, run, { url: box.url, filename: box.title }, ix)}
|
|
181
|
+
>
|
|
182
|
+
{a.label}
|
|
183
|
+
</button>
|
|
184
|
+
)
|
|
185
|
+
})
|
|
186
|
+
: null}
|
|
73
187
|
{box.promptId != null ? (
|
|
74
188
|
<button
|
|
75
189
|
type="button"
|
|
76
|
-
|
|
190
|
+
data-tip="remove this result"
|
|
77
191
|
onClick={() => {
|
|
78
192
|
if (box.promptId != null) p.st.run.remove(box.promptId)
|
|
79
193
|
p.local.closeLightbox()
|
|
@@ -83,8 +197,8 @@ const Lightbox = observer(function Lightbox(p: { st: WebSt; local: GalleryLocal
|
|
|
83
197
|
</button>
|
|
84
198
|
) : null}
|
|
85
199
|
{p.local.copyNote?.url === box.url ? <span className="hint">{p.local.copyNote.text}</span> : null}
|
|
86
|
-
<button type="button"
|
|
87
|
-
|
|
200
|
+
<button type="button" data-tip="close (esc)" onClick={() => p.local.closeLightbox()}>
|
|
201
|
+
<Icon name="close" />
|
|
88
202
|
</button>
|
|
89
203
|
</div>
|
|
90
204
|
</div>
|
|
@@ -92,6 +206,97 @@ const Lightbox = observer(function Lightbox(p: { st: WebSt; local: GalleryLocal
|
|
|
92
206
|
)
|
|
93
207
|
})
|
|
94
208
|
|
|
209
|
+
/** a reasoning model narrates inside <think> before it answers. The answer is what you asked
|
|
210
|
+
* for, so it reads first and the thinking folds away, dropping it outright would hide the
|
|
211
|
+
* only explanation of a bad answer */
|
|
212
|
+
function splitThinking(text: string): { thinking: string | null; answer: string } {
|
|
213
|
+
const close = text.indexOf('</think>')
|
|
214
|
+
if (close === -1) {
|
|
215
|
+
// no closing tag: the whole budget went into reasoning and the answer never came
|
|
216
|
+
return text.trimStart().startsWith('<think>')
|
|
217
|
+
? { thinking: text.replace(/^\s*<think>/, '').trim(), answer: '' }
|
|
218
|
+
: { thinking: null, answer: text.trim() }
|
|
219
|
+
}
|
|
220
|
+
const thinking = text
|
|
221
|
+
.slice(0, close)
|
|
222
|
+
.replace(/^\s*<think>/, '')
|
|
223
|
+
.trim()
|
|
224
|
+
return { thinking: thinking === '' ? null : thinking, answer: text.slice(close + '</think>'.length).trim() }
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** a STRING output. An llm graph produces ONLY these, so a run card without them shows nothing */
|
|
228
|
+
const TextResult = observer(function TextResult(p: { entry: { nodeKey: string | null; text: string } }) {
|
|
229
|
+
const local = useLocalObservable(() => ({
|
|
230
|
+
showThinking: false,
|
|
231
|
+
copied: false,
|
|
232
|
+
toggle(): void {
|
|
233
|
+
this.showThinking = !this.showThinking
|
|
234
|
+
},
|
|
235
|
+
markCopied(): void {
|
|
236
|
+
this.copied = true
|
|
237
|
+
},
|
|
238
|
+
}))
|
|
239
|
+
const { thinking, answer } = splitThinking(p.entry.text)
|
|
240
|
+
return (
|
|
241
|
+
<div className="run-text">
|
|
242
|
+
<div className="run-text-head">
|
|
243
|
+
<span className="hint">{p.entry.nodeKey ?? 'text'}</span>
|
|
244
|
+
{thinking != null ? (
|
|
245
|
+
<button
|
|
246
|
+
type="button"
|
|
247
|
+
className="link"
|
|
248
|
+
data-tip="the model's reasoning, before its answer"
|
|
249
|
+
onClick={() => local.toggle()}
|
|
250
|
+
>
|
|
251
|
+
{local.showThinking ? 'hide thinking' : 'thinking'}
|
|
252
|
+
</button>
|
|
253
|
+
) : null}
|
|
254
|
+
{canCopy ? (
|
|
255
|
+
<button
|
|
256
|
+
type="button"
|
|
257
|
+
className="link"
|
|
258
|
+
data-tip="copy this text"
|
|
259
|
+
onClick={() => {
|
|
260
|
+
void navigator.clipboard.writeText(answer === '' ? p.entry.text : answer)
|
|
261
|
+
local.markCopied()
|
|
262
|
+
}}
|
|
263
|
+
>
|
|
264
|
+
<Icon name="copy" /> {local.copied ? 'copied' : ''}
|
|
265
|
+
</button>
|
|
266
|
+
) : null}
|
|
267
|
+
</div>
|
|
268
|
+
{thinking != null && local.showThinking ? <pre className="run-thinking">{thinking}</pre> : null}
|
|
269
|
+
{answer === '' ? (
|
|
270
|
+
<div className="noimg">the model reasoned past its token budget and never answered — raise max tokens</div>
|
|
271
|
+
) : (
|
|
272
|
+
<pre className="run-text-body">{answer}</pre>
|
|
273
|
+
)}
|
|
274
|
+
</div>
|
|
275
|
+
)
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
/** text arriving DURING the node. It pins to the bottom because a stream grows downward and
|
|
279
|
+
* the newest words are the ones you are reading */
|
|
280
|
+
const LiveText = observer(function LiveText(p: { text: string }) {
|
|
281
|
+
const { thinking, answer } = splitThinking(p.text)
|
|
282
|
+
const ref = useRef<HTMLPreElement>(null)
|
|
283
|
+
useEffect(() => {
|
|
284
|
+
const el = ref.current
|
|
285
|
+
if (el != null) el.scrollTop = el.scrollHeight
|
|
286
|
+
})
|
|
287
|
+
// mid-stream the answer is usually still empty and the thinking IS the story, so whichever
|
|
288
|
+
// one is live gets shown rather than a blank box under a "thinking" label
|
|
289
|
+
const live = answer !== '' ? answer : (thinking ?? '')
|
|
290
|
+
return (
|
|
291
|
+
<div className="run-live">
|
|
292
|
+
{answer === '' && thinking != null ? <span className="hint">thinking…</span> : null}
|
|
293
|
+
<pre ref={ref} className={answer === '' ? 'run-live-body dim' : 'run-live-body'}>
|
|
294
|
+
{live}
|
|
295
|
+
</pre>
|
|
296
|
+
</div>
|
|
297
|
+
)
|
|
298
|
+
})
|
|
299
|
+
|
|
95
300
|
/** live card while a run is in flight: progress bar + the latest latent frame */
|
|
96
301
|
const RunningCard = observer(function RunningCard(p: { st: WebSt; local: GalleryLocal }) {
|
|
97
302
|
// the RUNNING module, never the selection: switching modules mid-run must not retarget the card
|
|
@@ -99,21 +304,41 @@ const RunningCard = observer(function RunningCard(p: { st: WebSt; local: Gallery
|
|
|
99
304
|
if (!p.st.run.isRunning || moduleKey == null) return null
|
|
100
305
|
const percent = p.st.run.progressPercent
|
|
101
306
|
const previewUrl = runPreviewSrc({ module: moduleKey, tick: p.st.run.previewTick })
|
|
307
|
+
// the node's OWN counter: generated tokens on a text node, sampler steps on a KSampler.
|
|
308
|
+
// A text graph has no latent frame and no image, so without this its card is a bare bar
|
|
309
|
+
const node = p.st.run.progressNode
|
|
310
|
+
const count = p.st.run.progressCount
|
|
311
|
+
const liveText = p.st.run.progressText
|
|
102
312
|
return (
|
|
103
313
|
<div className="run-card running">
|
|
104
314
|
<div className="meta">
|
|
105
315
|
<span>generating {moduleKey}…</span>
|
|
106
316
|
<span>{percent != null ? `${Math.round(percent)}%` : ''}</span>
|
|
107
317
|
</div>
|
|
318
|
+
{node != null ? (
|
|
319
|
+
<div className="run-node">
|
|
320
|
+
{node}
|
|
321
|
+
{count != null ? ` ${count.value}/${count.max}` : ''}
|
|
322
|
+
</div>
|
|
323
|
+
) : null}
|
|
324
|
+
{/* a node streaming its text as it produces it: the answer builds up here before the
|
|
325
|
+
run ends. Same fold as a finished result, so watching and reading look alike */}
|
|
326
|
+
{liveText != null && liveText !== '' ? <LiveText text={liveText} /> : null}
|
|
108
327
|
<div className="progress-track">
|
|
109
328
|
<div className="progress-fill" style={{ width: `${percent ?? 0}%` }} />
|
|
110
329
|
</div>
|
|
111
|
-
{p.st.run.hasPreview ? (
|
|
330
|
+
{p.st.run.hasPreview && p.st.showLatent ? (
|
|
112
331
|
<div className="imgs">
|
|
113
332
|
<button
|
|
114
333
|
type="button"
|
|
115
334
|
className="img-button"
|
|
116
|
-
onClick={() =>
|
|
335
|
+
onClick={() =>
|
|
336
|
+
p.local.openLightbox({
|
|
337
|
+
kind: 'latent',
|
|
338
|
+
module: moduleKey,
|
|
339
|
+
after: p.st.run.results.filter((r) => r.module === moduleKey).length,
|
|
340
|
+
})
|
|
341
|
+
}
|
|
117
342
|
>
|
|
118
343
|
<img src={previewUrl} alt="latent preview" />
|
|
119
344
|
</button>
|
|
@@ -123,23 +348,19 @@ const RunningCard = observer(function RunningCard(p: { st: WebSt; local: Gallery
|
|
|
123
348
|
)
|
|
124
349
|
})
|
|
125
350
|
|
|
126
|
-
|
|
351
|
+
/** compact = the pinned corner: the newest result only, no header. It is a RENDER decision,
|
|
352
|
+
* never a css one, hiding cards with :first-of-type counted div siblings, so the moment the
|
|
353
|
+
* header appeared every card vanished and a finished image disappeared behind the latent */
|
|
354
|
+
export const Gallery = observer(function Gallery(p: { st: WebSt; compact?: boolean }) {
|
|
127
355
|
const local = useGalleryLocal()
|
|
128
356
|
if (p.st.run.results.length === 0 && !p.st.run.isRunning) return null
|
|
357
|
+
const results = p.compact === true ? p.st.run.results.slice(0, 1) : p.st.run.results
|
|
129
358
|
return (
|
|
130
359
|
<div className="gallery">
|
|
131
360
|
<RunningCard st={p.st} local={local} />
|
|
132
|
-
{
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
{p.st.run.results.length} result{p.st.run.results.length === 1 ? '' : 's'}
|
|
136
|
-
</span>
|
|
137
|
-
<button type="button" className="link" onClick={() => p.st.run.clear()}>
|
|
138
|
-
clear all
|
|
139
|
-
</button>
|
|
140
|
-
</div>
|
|
141
|
-
) : null}
|
|
142
|
-
{p.st.run.results.map((r) => (
|
|
361
|
+
{/* the count and clear-all moved onto the run line beside the generate button: two
|
|
362
|
+
headers for one idea is a header too many */}
|
|
363
|
+
{results.map((r) => (
|
|
143
364
|
<div key={r.promptId} className="run-card">
|
|
144
365
|
<div className="meta">
|
|
145
366
|
<span>
|
|
@@ -149,35 +370,79 @@ export const Gallery = observer(function Gallery(p: { st: WebSt }) {
|
|
|
149
370
|
<button
|
|
150
371
|
type="button"
|
|
151
372
|
className="link"
|
|
152
|
-
|
|
373
|
+
data-tip="remove this result"
|
|
153
374
|
onClick={() => p.st.run.remove(r.promptId)}
|
|
154
375
|
>
|
|
155
|
-
|
|
376
|
+
<Icon name="trash" />
|
|
156
377
|
</button>
|
|
157
378
|
</div>
|
|
158
379
|
<div className="imgs">
|
|
159
|
-
{r.images.map((img) =>
|
|
380
|
+
{r.images.map((img, ix) =>
|
|
160
381
|
img.url != null ? (
|
|
161
|
-
<
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
382
|
+
<div key={img.filename} className="img-cell">
|
|
383
|
+
<button
|
|
384
|
+
type="button"
|
|
385
|
+
className="img-button"
|
|
386
|
+
data-tip={img.filename}
|
|
387
|
+
onClick={() => {
|
|
388
|
+
if (img.url != null)
|
|
389
|
+
local.openLightbox({
|
|
390
|
+
kind: 'image',
|
|
391
|
+
url: img.url,
|
|
392
|
+
title: img.filename,
|
|
393
|
+
promptId: r.promptId,
|
|
394
|
+
})
|
|
395
|
+
}}
|
|
396
|
+
>
|
|
397
|
+
<img src={img.url} alt={img.filename} />
|
|
398
|
+
</button>
|
|
399
|
+
{/* the EMBEDDING page's buttons (host protocol): what it does with the
|
|
400
|
+
image is its business — send it somewhere, keep it as something */}
|
|
401
|
+
{p.st.hostActions.length > 0 ? (
|
|
402
|
+
<div className="host-actions">
|
|
403
|
+
{p.st.hostActions.map((a) => (
|
|
404
|
+
<button
|
|
405
|
+
key={a.id}
|
|
406
|
+
type="button"
|
|
407
|
+
className="host-action"
|
|
408
|
+
data-tip={a.title}
|
|
409
|
+
onClick={() => {
|
|
410
|
+
if (img.url != null)
|
|
411
|
+
p.st.postResultAction(
|
|
412
|
+
a.id,
|
|
413
|
+
r,
|
|
414
|
+
{ url: img.url, filename: img.filename },
|
|
415
|
+
ix,
|
|
416
|
+
)
|
|
417
|
+
}}
|
|
418
|
+
>
|
|
419
|
+
{a.label}
|
|
420
|
+
</button>
|
|
421
|
+
))}
|
|
422
|
+
<button
|
|
423
|
+
type="button"
|
|
424
|
+
className="host-action danger"
|
|
425
|
+
data-tip="remove this result"
|
|
426
|
+
onClick={() => p.st.run.remove(r.promptId)}
|
|
427
|
+
>
|
|
428
|
+
✕
|
|
429
|
+
</button>
|
|
430
|
+
</div>
|
|
431
|
+
) : null}
|
|
432
|
+
</div>
|
|
173
433
|
) : (
|
|
174
434
|
<div key={img.filename} className="noimg">
|
|
175
435
|
{img.filename} (not saved locally — no preview)
|
|
176
436
|
</div>
|
|
177
437
|
),
|
|
178
438
|
)}
|
|
179
|
-
{r.images.length === 0
|
|
439
|
+
{r.images.length === 0 && (r.texts ?? []).length === 0 ? (
|
|
440
|
+
<div className="noimg">no outputs</div>
|
|
441
|
+
) : null}
|
|
180
442
|
</div>
|
|
443
|
+
{(r.texts ?? []).map((t, ix) => (
|
|
444
|
+
<TextResult key={`${r.promptId}-${ix}`} entry={t} />
|
|
445
|
+
))}
|
|
181
446
|
</div>
|
|
182
447
|
))}
|
|
183
448
|
<Lightbox st={p.st} local={local} />
|