comfy-ts 2.7.0 → 2.8.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-BPw-SZYW.js} +106 -157
- package/dist/run-tui-BPw-SZYW.js.map +1 -0
- package/dist/serve-web.js +432 -72
- package/dist/{state-CaHeDL-0.js → state-B-boDz-Z.js} +180 -45
- package/dist/state-B-boDz-Z.js.map +1 -0
- package/dist/web.d.ts +109 -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/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 +243 -30
- 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 +66 -17
- package/src/cli/serve/web/state/RunSt.ts +22 -1
- package/src/cli/serve/web/state/WebSt.ts +518 -14
- 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 +413 -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/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
|
|
@@ -73,7 +169,7 @@ const Lightbox = observer(function Lightbox(p: { st: WebSt; local: GalleryLocal
|
|
|
73
169
|
{box.promptId != null ? (
|
|
74
170
|
<button
|
|
75
171
|
type="button"
|
|
76
|
-
|
|
172
|
+
data-tip="remove this result"
|
|
77
173
|
onClick={() => {
|
|
78
174
|
if (box.promptId != null) p.st.run.remove(box.promptId)
|
|
79
175
|
p.local.closeLightbox()
|
|
@@ -83,8 +179,8 @@ const Lightbox = observer(function Lightbox(p: { st: WebSt; local: GalleryLocal
|
|
|
83
179
|
</button>
|
|
84
180
|
) : null}
|
|
85
181
|
{p.local.copyNote?.url === box.url ? <span className="hint">{p.local.copyNote.text}</span> : null}
|
|
86
|
-
<button type="button"
|
|
87
|
-
|
|
182
|
+
<button type="button" data-tip="close (esc)" onClick={() => p.local.closeLightbox()}>
|
|
183
|
+
<Icon name="close" />
|
|
88
184
|
</button>
|
|
89
185
|
</div>
|
|
90
186
|
</div>
|
|
@@ -92,6 +188,97 @@ const Lightbox = observer(function Lightbox(p: { st: WebSt; local: GalleryLocal
|
|
|
92
188
|
)
|
|
93
189
|
})
|
|
94
190
|
|
|
191
|
+
/** a reasoning model narrates inside <think> before it answers. The answer is what you asked
|
|
192
|
+
* for, so it reads first and the thinking folds away, dropping it outright would hide the
|
|
193
|
+
* only explanation of a bad answer */
|
|
194
|
+
function splitThinking(text: string): { thinking: string | null; answer: string } {
|
|
195
|
+
const close = text.indexOf('</think>')
|
|
196
|
+
if (close === -1) {
|
|
197
|
+
// no closing tag: the whole budget went into reasoning and the answer never came
|
|
198
|
+
return text.trimStart().startsWith('<think>')
|
|
199
|
+
? { thinking: text.replace(/^\s*<think>/, '').trim(), answer: '' }
|
|
200
|
+
: { thinking: null, answer: text.trim() }
|
|
201
|
+
}
|
|
202
|
+
const thinking = text
|
|
203
|
+
.slice(0, close)
|
|
204
|
+
.replace(/^\s*<think>/, '')
|
|
205
|
+
.trim()
|
|
206
|
+
return { thinking: thinking === '' ? null : thinking, answer: text.slice(close + '</think>'.length).trim() }
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** a STRING output. An llm graph produces ONLY these, so a run card without them shows nothing */
|
|
210
|
+
const TextResult = observer(function TextResult(p: { entry: { nodeKey: string | null; text: string } }) {
|
|
211
|
+
const local = useLocalObservable(() => ({
|
|
212
|
+
showThinking: false,
|
|
213
|
+
copied: false,
|
|
214
|
+
toggle(): void {
|
|
215
|
+
this.showThinking = !this.showThinking
|
|
216
|
+
},
|
|
217
|
+
markCopied(): void {
|
|
218
|
+
this.copied = true
|
|
219
|
+
},
|
|
220
|
+
}))
|
|
221
|
+
const { thinking, answer } = splitThinking(p.entry.text)
|
|
222
|
+
return (
|
|
223
|
+
<div className="run-text">
|
|
224
|
+
<div className="run-text-head">
|
|
225
|
+
<span className="hint">{p.entry.nodeKey ?? 'text'}</span>
|
|
226
|
+
{thinking != null ? (
|
|
227
|
+
<button
|
|
228
|
+
type="button"
|
|
229
|
+
className="link"
|
|
230
|
+
data-tip="the model's reasoning, before its answer"
|
|
231
|
+
onClick={() => local.toggle()}
|
|
232
|
+
>
|
|
233
|
+
{local.showThinking ? 'hide thinking' : 'thinking'}
|
|
234
|
+
</button>
|
|
235
|
+
) : null}
|
|
236
|
+
{canCopy ? (
|
|
237
|
+
<button
|
|
238
|
+
type="button"
|
|
239
|
+
className="link"
|
|
240
|
+
data-tip="copy this text"
|
|
241
|
+
onClick={() => {
|
|
242
|
+
void navigator.clipboard.writeText(answer === '' ? p.entry.text : answer)
|
|
243
|
+
local.markCopied()
|
|
244
|
+
}}
|
|
245
|
+
>
|
|
246
|
+
<Icon name="copy" /> {local.copied ? 'copied' : ''}
|
|
247
|
+
</button>
|
|
248
|
+
) : null}
|
|
249
|
+
</div>
|
|
250
|
+
{thinking != null && local.showThinking ? <pre className="run-thinking">{thinking}</pre> : null}
|
|
251
|
+
{answer === '' ? (
|
|
252
|
+
<div className="noimg">the model reasoned past its token budget and never answered — raise max tokens</div>
|
|
253
|
+
) : (
|
|
254
|
+
<pre className="run-text-body">{answer}</pre>
|
|
255
|
+
)}
|
|
256
|
+
</div>
|
|
257
|
+
)
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
/** text arriving DURING the node. It pins to the bottom because a stream grows downward and
|
|
261
|
+
* the newest words are the ones you are reading */
|
|
262
|
+
const LiveText = observer(function LiveText(p: { text: string }) {
|
|
263
|
+
const { thinking, answer } = splitThinking(p.text)
|
|
264
|
+
const ref = useRef<HTMLPreElement>(null)
|
|
265
|
+
useEffect(() => {
|
|
266
|
+
const el = ref.current
|
|
267
|
+
if (el != null) el.scrollTop = el.scrollHeight
|
|
268
|
+
})
|
|
269
|
+
// mid-stream the answer is usually still empty and the thinking IS the story, so whichever
|
|
270
|
+
// one is live gets shown rather than a blank box under a "thinking" label
|
|
271
|
+
const live = answer !== '' ? answer : (thinking ?? '')
|
|
272
|
+
return (
|
|
273
|
+
<div className="run-live">
|
|
274
|
+
{answer === '' && thinking != null ? <span className="hint">thinking…</span> : null}
|
|
275
|
+
<pre ref={ref} className={answer === '' ? 'run-live-body dim' : 'run-live-body'}>
|
|
276
|
+
{live}
|
|
277
|
+
</pre>
|
|
278
|
+
</div>
|
|
279
|
+
)
|
|
280
|
+
})
|
|
281
|
+
|
|
95
282
|
/** live card while a run is in flight: progress bar + the latest latent frame */
|
|
96
283
|
const RunningCard = observer(function RunningCard(p: { st: WebSt; local: GalleryLocal }) {
|
|
97
284
|
// the RUNNING module, never the selection: switching modules mid-run must not retarget the card
|
|
@@ -99,21 +286,41 @@ const RunningCard = observer(function RunningCard(p: { st: WebSt; local: Gallery
|
|
|
99
286
|
if (!p.st.run.isRunning || moduleKey == null) return null
|
|
100
287
|
const percent = p.st.run.progressPercent
|
|
101
288
|
const previewUrl = runPreviewSrc({ module: moduleKey, tick: p.st.run.previewTick })
|
|
289
|
+
// the node's OWN counter: generated tokens on a text node, sampler steps on a KSampler.
|
|
290
|
+
// A text graph has no latent frame and no image, so without this its card is a bare bar
|
|
291
|
+
const node = p.st.run.progressNode
|
|
292
|
+
const count = p.st.run.progressCount
|
|
293
|
+
const liveText = p.st.run.progressText
|
|
102
294
|
return (
|
|
103
295
|
<div className="run-card running">
|
|
104
296
|
<div className="meta">
|
|
105
297
|
<span>generating {moduleKey}…</span>
|
|
106
298
|
<span>{percent != null ? `${Math.round(percent)}%` : ''}</span>
|
|
107
299
|
</div>
|
|
300
|
+
{node != null ? (
|
|
301
|
+
<div className="run-node">
|
|
302
|
+
{node}
|
|
303
|
+
{count != null ? ` ${count.value}/${count.max}` : ''}
|
|
304
|
+
</div>
|
|
305
|
+
) : null}
|
|
306
|
+
{/* a node streaming its text as it produces it: the answer builds up here before the
|
|
307
|
+
run ends. Same fold as a finished result, so watching and reading look alike */}
|
|
308
|
+
{liveText != null && liveText !== '' ? <LiveText text={liveText} /> : null}
|
|
108
309
|
<div className="progress-track">
|
|
109
310
|
<div className="progress-fill" style={{ width: `${percent ?? 0}%` }} />
|
|
110
311
|
</div>
|
|
111
|
-
{p.st.run.hasPreview ? (
|
|
312
|
+
{p.st.run.hasPreview && p.st.showLatent ? (
|
|
112
313
|
<div className="imgs">
|
|
113
314
|
<button
|
|
114
315
|
type="button"
|
|
115
316
|
className="img-button"
|
|
116
|
-
onClick={() =>
|
|
317
|
+
onClick={() =>
|
|
318
|
+
p.local.openLightbox({
|
|
319
|
+
kind: 'latent',
|
|
320
|
+
module: moduleKey,
|
|
321
|
+
after: p.st.run.results.filter((r) => r.module === moduleKey).length,
|
|
322
|
+
})
|
|
323
|
+
}
|
|
117
324
|
>
|
|
118
325
|
<img src={previewUrl} alt="latent preview" />
|
|
119
326
|
</button>
|
|
@@ -123,23 +330,19 @@ const RunningCard = observer(function RunningCard(p: { st: WebSt; local: Gallery
|
|
|
123
330
|
)
|
|
124
331
|
})
|
|
125
332
|
|
|
126
|
-
|
|
333
|
+
/** compact = the pinned corner: the newest result only, no header. It is a RENDER decision,
|
|
334
|
+
* never a css one, hiding cards with :first-of-type counted div siblings, so the moment the
|
|
335
|
+
* header appeared every card vanished and a finished image disappeared behind the latent */
|
|
336
|
+
export const Gallery = observer(function Gallery(p: { st: WebSt; compact?: boolean }) {
|
|
127
337
|
const local = useGalleryLocal()
|
|
128
338
|
if (p.st.run.results.length === 0 && !p.st.run.isRunning) return null
|
|
339
|
+
const results = p.compact === true ? p.st.run.results.slice(0, 1) : p.st.run.results
|
|
129
340
|
return (
|
|
130
341
|
<div className="gallery">
|
|
131
342
|
<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) => (
|
|
343
|
+
{/* the count and clear-all moved onto the run line beside the generate button: two
|
|
344
|
+
headers for one idea is a header too many */}
|
|
345
|
+
{results.map((r) => (
|
|
143
346
|
<div key={r.promptId} className="run-card">
|
|
144
347
|
<div className="meta">
|
|
145
348
|
<span>
|
|
@@ -149,10 +352,10 @@ export const Gallery = observer(function Gallery(p: { st: WebSt }) {
|
|
|
149
352
|
<button
|
|
150
353
|
type="button"
|
|
151
354
|
className="link"
|
|
152
|
-
|
|
355
|
+
data-tip="remove this result"
|
|
153
356
|
onClick={() => p.st.run.remove(r.promptId)}
|
|
154
357
|
>
|
|
155
|
-
|
|
358
|
+
<Icon name="trash" />
|
|
156
359
|
</button>
|
|
157
360
|
</div>
|
|
158
361
|
<div className="imgs">
|
|
@@ -162,10 +365,15 @@ export const Gallery = observer(function Gallery(p: { st: WebSt }) {
|
|
|
162
365
|
key={img.filename}
|
|
163
366
|
type="button"
|
|
164
367
|
className="img-button"
|
|
165
|
-
|
|
368
|
+
data-tip={img.filename}
|
|
166
369
|
onClick={() => {
|
|
167
370
|
if (img.url != null)
|
|
168
|
-
local.openLightbox({
|
|
371
|
+
local.openLightbox({
|
|
372
|
+
kind: 'image',
|
|
373
|
+
url: img.url,
|
|
374
|
+
title: img.filename,
|
|
375
|
+
promptId: r.promptId,
|
|
376
|
+
})
|
|
169
377
|
}}
|
|
170
378
|
>
|
|
171
379
|
<img src={img.url} alt={img.filename} />
|
|
@@ -176,8 +384,13 @@ export const Gallery = observer(function Gallery(p: { st: WebSt }) {
|
|
|
176
384
|
</div>
|
|
177
385
|
),
|
|
178
386
|
)}
|
|
179
|
-
{r.images.length === 0
|
|
387
|
+
{r.images.length === 0 && (r.texts ?? []).length === 0 ? (
|
|
388
|
+
<div className="noimg">no outputs</div>
|
|
389
|
+
) : null}
|
|
180
390
|
</div>
|
|
391
|
+
{(r.texts ?? []).map((t, ix) => (
|
|
392
|
+
<TextResult key={`${r.promptId}-${ix}`} entry={t} />
|
|
393
|
+
))}
|
|
181
394
|
</div>
|
|
182
395
|
))}
|
|
183
396
|
<Lightbox st={p.st} local={local} />
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// ONE inline svg icon set for the panel. No icon font, no dependency, no emoji:
|
|
2
|
+
// emoji render differently per platform (and a phone shows its own set), so an
|
|
3
|
+
// affordance drawn with one is not the same button on two devices.
|
|
4
|
+
// every path uses currentColor and 1em, so an icon inherits the text it sits in.
|
|
5
|
+
import type { ReactNode } from 'react'
|
|
6
|
+
|
|
7
|
+
export type IconName =
|
|
8
|
+
| 'close'
|
|
9
|
+
| 'trash'
|
|
10
|
+
| 'copy'
|
|
11
|
+
| 'external'
|
|
12
|
+
| 'dice'
|
|
13
|
+
| 'image'
|
|
14
|
+
| 'tag'
|
|
15
|
+
| 'sparkle'
|
|
16
|
+
| 'play'
|
|
17
|
+
| 'pause'
|
|
18
|
+
| 'save'
|
|
19
|
+
| 'ghost'
|
|
20
|
+
| 'panel-off'
|
|
21
|
+
| 'panel-bottom'
|
|
22
|
+
| 'panel-side'
|
|
23
|
+
| 'panel-left'
|
|
24
|
+
| 'panel-corner'
|
|
25
|
+
| 'swap'
|
|
26
|
+
| 'plus'
|
|
27
|
+
| 'copy-plus'
|
|
28
|
+
| 'pen'
|
|
29
|
+
| 'broom'
|
|
30
|
+
| 'expand'
|
|
31
|
+
| 'shrink'
|
|
32
|
+
| 'power'
|
|
33
|
+
| 'warn'
|
|
34
|
+
| 'grip'
|
|
35
|
+
| 'link'
|
|
36
|
+
| 'unlink'
|
|
37
|
+
| 'refresh'
|
|
38
|
+
| 'terminal'
|
|
39
|
+
| 'folder'
|
|
40
|
+
| 'dot'
|
|
41
|
+
|
|
42
|
+
/** 24x24 viewBox paths, stroked (fill: none) unless the shape reads better solid */
|
|
43
|
+
const PATHS: Record<IconName, ReactNode> = {
|
|
44
|
+
close: <path d="M6 6l12 12M18 6L6 18" />,
|
|
45
|
+
trash: <path d="M4 7h16M10 7V5h4v2M6 7l1 12h10l1-12M10 11v5M14 11v5" />,
|
|
46
|
+
copy: <path d="M9 9h10v10H9zM5 15V5h10" />,
|
|
47
|
+
external: <path d="M14 5h5v5M19 5l-8 8M18 14v5H5V6h5" />,
|
|
48
|
+
dice: (
|
|
49
|
+
<>
|
|
50
|
+
<rect x="4" y="4" width="16" height="16" rx="3" />
|
|
51
|
+
<circle cx="9" cy="9" r="1.3" fill="currentColor" stroke="none" />
|
|
52
|
+
<circle cx="15" cy="15" r="1.3" fill="currentColor" stroke="none" />
|
|
53
|
+
<circle cx="12" cy="12" r="1.3" fill="currentColor" stroke="none" />
|
|
54
|
+
</>
|
|
55
|
+
),
|
|
56
|
+
image: (
|
|
57
|
+
<>
|
|
58
|
+
<rect x="3" y="5" width="18" height="14" rx="2" />
|
|
59
|
+
<circle cx="8.5" cy="10" r="1.5" />
|
|
60
|
+
<path d="M4 17l5-5 4 4 3-2 4 4" />
|
|
61
|
+
</>
|
|
62
|
+
),
|
|
63
|
+
tag: (
|
|
64
|
+
<>
|
|
65
|
+
<path d="M4 11V4h7l9 9-7 7-9-9z" />
|
|
66
|
+
<circle cx="8" cy="8" r="1.3" fill="currentColor" stroke="none" />
|
|
67
|
+
</>
|
|
68
|
+
),
|
|
69
|
+
sparkle: (
|
|
70
|
+
<path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9zM18 15l.8 2.2L21 18l-2.2.8L18 21l-.8-2.2L15 18l2.2-.8z" />
|
|
71
|
+
),
|
|
72
|
+
play: <path d="M7 4l13 8-13 8z" fill="currentColor" stroke="none" />,
|
|
73
|
+
pause: <path d="M8 5v14M16 5v14" />,
|
|
74
|
+
save: <path d="M5 4h11l3 3v13H5zM8 4v6h7V4M8 20v-6h8v6" />,
|
|
75
|
+
ghost: <path d="M5 20V10a7 7 0 0114 0v10l-2.3-2-2.4 2-2.3-2-2.4 2zM9.5 10h.01M14.5 10h.01" />,
|
|
76
|
+
'panel-off': (
|
|
77
|
+
<>
|
|
78
|
+
<rect x="3" y="4" width="18" height="16" rx="2" />
|
|
79
|
+
<path d="M4 5l16 14" />
|
|
80
|
+
</>
|
|
81
|
+
),
|
|
82
|
+
'panel-bottom': (
|
|
83
|
+
<>
|
|
84
|
+
<rect x="3" y="4" width="18" height="16" rx="2" />
|
|
85
|
+
<path d="M3 14h18" />
|
|
86
|
+
<rect x="4.5" y="15.5" width="15" height="3" fill="currentColor" stroke="none" opacity="0.85" />
|
|
87
|
+
</>
|
|
88
|
+
),
|
|
89
|
+
'panel-side': (
|
|
90
|
+
<>
|
|
91
|
+
<rect x="3" y="4" width="18" height="16" rx="2" />
|
|
92
|
+
<path d="M14 4v16" />
|
|
93
|
+
<rect x="15.5" y="5.5" width="4" height="13" fill="currentColor" stroke="none" opacity="0.85" />
|
|
94
|
+
</>
|
|
95
|
+
),
|
|
96
|
+
'panel-left': (
|
|
97
|
+
<>
|
|
98
|
+
<rect x="3" y="4" width="18" height="16" rx="2" />
|
|
99
|
+
<path d="M10 4v16" />
|
|
100
|
+
<rect x="4.5" y="5.5" width="4" height="13" fill="currentColor" stroke="none" opacity="0.85" />
|
|
101
|
+
</>
|
|
102
|
+
),
|
|
103
|
+
/* same frame as the other placements, filled in the corner it actually occupies — a pin
|
|
104
|
+
said "sticky" while every sibling said WHERE */
|
|
105
|
+
'panel-corner': (
|
|
106
|
+
<>
|
|
107
|
+
<rect x="3" y="4" width="18" height="16" rx="2" />
|
|
108
|
+
<rect x="12.5" y="12.5" width="7" height="6" fill="currentColor" stroke="none" opacity="0.85" />
|
|
109
|
+
</>
|
|
110
|
+
),
|
|
111
|
+
swap: <path d="M4 8h13l-3-3M20 16H7l3 3" />,
|
|
112
|
+
plus: <path d="M12 5v14M5 12h14" />,
|
|
113
|
+
'copy-plus': <path d="M9 9h10v10H9zM5 15V5h10M14 12v4M12 14h4" />,
|
|
114
|
+
pen: <path d="M4 20h4L20 8l-4-4L4 16zM14 6l4 4" />,
|
|
115
|
+
broom: <path d="M19 4l-7 7M9.5 8.5l6 6-5 5-6-6zM4.5 13.5L2 21l7.5-2.5" />,
|
|
116
|
+
expand: <path d="M4 9V4h5M20 15v5h-5M15 4h5v5M9 20H4v-5" />,
|
|
117
|
+
shrink: <path d="M9 4v5H4M15 20v-5h5M20 9h-5V4M4 15h5v5" />,
|
|
118
|
+
power: <path d="M12 3v9M7.5 6.5a7 7 0 109 0" />,
|
|
119
|
+
warn: <path d="M12 4l9 16H3zM12 10v4M12 17h.01" />,
|
|
120
|
+
link: (
|
|
121
|
+
<path d="M10 14a4 4 0 015.7 0l2.6-2.6a4 4 0 10-5.7-5.7L11 7.3M14 10a4 4 0 01-5.7 0l-2.6 2.6a4 4 0 105.7 5.7L13 16.7" />
|
|
122
|
+
),
|
|
123
|
+
unlink: <path d="M9 15l-1.6 1.6a4 4 0 01-5.7-5.7L3.3 9.3M15 9l1.6-1.6a4 4 0 015.7 5.7L20.7 14.7M4 4l16 16" />,
|
|
124
|
+
grip: (
|
|
125
|
+
<>
|
|
126
|
+
<circle cx="9" cy="6" r="1.4" fill="currentColor" stroke="none" />
|
|
127
|
+
<circle cx="15" cy="6" r="1.4" fill="currentColor" stroke="none" />
|
|
128
|
+
<circle cx="9" cy="12" r="1.4" fill="currentColor" stroke="none" />
|
|
129
|
+
<circle cx="15" cy="12" r="1.4" fill="currentColor" stroke="none" />
|
|
130
|
+
<circle cx="9" cy="18" r="1.4" fill="currentColor" stroke="none" />
|
|
131
|
+
<circle cx="15" cy="18" r="1.4" fill="currentColor" stroke="none" />
|
|
132
|
+
</>
|
|
133
|
+
),
|
|
134
|
+
refresh: <path d="M20 11a8 8 0 10-2 6M20 6v5h-5" />,
|
|
135
|
+
terminal: <path d="M4 5h16v14H4zM7 9l3 3-3 3M13 15h4" />,
|
|
136
|
+
folder: <path d="M3 7h6l2 2h10v10H3z" />,
|
|
137
|
+
dot: <circle cx="12" cy="12" r="5" fill="currentColor" stroke="none" />,
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** `size` is a multiplier of the surrounding font size, so icons scale with their button */
|
|
141
|
+
export function Icon(p: { name: IconName; size?: number; title?: string }): ReactNode {
|
|
142
|
+
return (
|
|
143
|
+
<svg
|
|
144
|
+
className="icon"
|
|
145
|
+
viewBox="0 0 24 24"
|
|
146
|
+
width={`${p.size ?? 1.15}em`}
|
|
147
|
+
height={`${p.size ?? 1.15}em`}
|
|
148
|
+
fill="none"
|
|
149
|
+
stroke="currentColor"
|
|
150
|
+
strokeWidth={1.8}
|
|
151
|
+
strokeLinecap="round"
|
|
152
|
+
strokeLinejoin="round"
|
|
153
|
+
aria-hidden={p.title == null}
|
|
154
|
+
role={p.title == null ? undefined : 'img'}
|
|
155
|
+
>
|
|
156
|
+
{p.title == null ? null : <title>{p.title}</title>}
|
|
157
|
+
{PATHS[p.name]}
|
|
158
|
+
</svg>
|
|
159
|
+
)
|
|
160
|
+
}
|