comfy-ts 2.13.0 → 2.15.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 +1 -0
- package/dist/{LogsSt-CUeo843w.js → LogsSt-C3UIWR-o.js} +2 -2
- package/dist/{LogsSt-CUeo843w.js.map → LogsSt-C3UIWR-o.js.map} +1 -1
- package/dist/cli.js +4 -4
- package/dist/index.cjs +213 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +123 -21
- package/dist/index.d.ts +123 -21
- package/dist/index.js +207 -54
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-DlRBv_Nk.js → run-serve-B5PfIuhK.js} +310 -88
- package/dist/run-serve-B5PfIuhK.js.map +1 -0
- package/dist/{run-tui-B5uxm2_l.js → run-tui-D-N4_yyX.js} +15 -9
- package/dist/run-tui-D-N4_yyX.js.map +1 -0
- package/dist/{schemaDrift-E95iTF7E.js → schemaDrift-BkN8rLiZ.js} +163 -25
- package/dist/schemaDrift-BkN8rLiZ.js.map +1 -0
- package/dist/serve-web.js +160 -71
- package/dist/{state-CUp2J1Zy.js → state-CZsYJqB6.js} +45 -35
- package/dist/state-CZsYJqB6.js.map +1 -0
- package/dist/web.d.ts +120 -21
- package/dist/web.js +196 -51
- package/dist/web.js.map +1 -1
- package/examples/media/README.md +8 -0
- package/examples/media/sine_440hz_3s.flac +0 -0
- package/examples/media/testsrc_256x256_3s.mp4 +0 -0
- package/examples/rvion/14-video-soundtrack.cflow.ts +47 -0
- package/guide-for-agents.md +2 -1
- package/package.json +2 -2
- package/src/cli/serve/ServeApp.ts +189 -110
- package/src/cli/serve/applyVarPayload.ts +5 -3
- package/src/cli/serve/describeVar.ts +5 -3
- package/src/cli/serve/resultHistory.ts +141 -0
- package/src/cli/serve/run-serve.ts +4 -1
- package/src/cli/serve/runError.ts +23 -0
- package/src/cli/serve/serveSettings.ts +17 -1
- package/src/cli/serve/web/api.ts +33 -2
- package/src/cli/serve/web/components/App.tsx +6 -4
- package/src/cli/serve/web/components/Gallery.tsx +116 -11
- package/src/cli/serve/web/components/Icon.tsx +4 -0
- package/src/cli/serve/web/components/MemoryBudget.tsx +98 -0
- package/src/cli/serve/web/components/RunError.tsx +19 -0
- package/src/cli/serve/web/components/ShortcutsModal.tsx +54 -0
- package/src/cli/serve/web/components/SideMenu.tsx +14 -0
- package/src/cli/serve/web/components/VarsForm.tsx +75 -55
- package/src/cli/serve/web/components/controls/BasicControls.tsx +8 -1
- package/src/cli/serve/web/components/controls/LorasControl.tsx +6 -3
- package/src/cli/serve/web/components/controls/MediaControl.tsx +111 -0
- package/src/cli/serve/web/promptEditor/promptExtensions.ts +3 -1
- package/src/cli/serve/web/state/FormSt.ts +70 -2
- package/src/cli/serve/web/state/RunSt.ts +61 -3
- package/src/cli/serve/web/state/WebSt.ts +26 -2
- package/src/cli/serve/web/state/formRows.ts +9 -0
- package/src/cli/serve/web/state/host.ts +2 -0
- package/src/cli/serve/web/state/keptResults.ts +26 -0
- package/src/cli/serve/web/state/lightbox.ts +17 -0
- package/src/cli/serve/web/state/mediaDrop.ts +76 -0
- package/src/cli/serve/web/state/shortcutCatalog.ts +100 -0
- package/src/cli/serve/web/state/shortcuts.ts +10 -0
- package/src/cli/serve/web/styles.ts +112 -24
- package/src/cli/tui/imagePicker/ImagePickerOverlay.tsx +4 -1
- package/src/cli/tui/imagePicker/ImagePickerSt.ts +15 -6
- package/src/cli/tui/state/TuiSt.ts +1 -1
- package/src/coreExports.ts +10 -0
- package/src/exampleAssets.ts +13 -3
- package/src/host/ComfyUploader.ts +34 -27
- package/src/index.ts +1 -1
- package/src/runner/ComfyExecution.ts +38 -20
- package/src/runner/ComfyWsApi.ts +3 -0
- package/src/runner/mediaKinds.ts +51 -0
- package/src/vars/ComfyVars.ts +96 -22
- package/dist/run-serve-DlRBv_Nk.js.map +0 -1
- package/dist/run-tui-B5uxm2_l.js.map +0 -1
- package/dist/schemaDrift-E95iTF7E.js.map +0 -1
- package/dist/state-CUp2J1Zy.js.map +0 -1
- package/src/cli/serve/web/components/controls/ImageControl.tsx +0 -72
|
@@ -3,7 +3,16 @@
|
|
|
3
3
|
// reaction is owned here). DRAFTS ARE LIVE (the TUI model): edits autosave
|
|
4
4
|
// through PUT /drafts, generate posts {} — the draft is the one source of truth
|
|
5
5
|
import { makeAutoObservable, observableRef, reaction, runInAction, type IReactionDisposer } from 'mobx'
|
|
6
|
-
import { fetchPreviews, saveDraft, type ModuleDescription } from 'src/cli/serve/web/api.ts'
|
|
6
|
+
import { fetchPreviews, saveDraft, uploadFile, type ModuleDescription } from 'src/cli/serve/web/api.ts'
|
|
7
|
+
import {
|
|
8
|
+
isMediaKind,
|
|
9
|
+
mediaKindOfFile,
|
|
10
|
+
refuseDrop,
|
|
11
|
+
valueForOutput,
|
|
12
|
+
type DraggedOutput,
|
|
13
|
+
} from 'src/cli/serve/web/state/mediaDrop.ts'
|
|
14
|
+
import type { MediaKind } from 'src/runner/mediaKinds.ts'
|
|
15
|
+
import { logWebError } from 'src/cli/serve/web/logWeb.ts'
|
|
7
16
|
import type { VarDescriptor } from 'src/cli/serve/describeVar.ts'
|
|
8
17
|
import { normalizeInitial, payloadSnapshot } from 'src/cli/serve/web/state/payload.ts'
|
|
9
18
|
import {
|
|
@@ -23,8 +32,12 @@ export class VarSt {
|
|
|
23
32
|
value: unknown
|
|
24
33
|
/** changed since the draft loaded — drives the revert affordance, not the payload */
|
|
25
34
|
dirty = false
|
|
26
|
-
/**
|
|
35
|
+
/** media vars only: a browser-visible url for the current value (upload response or http value) */
|
|
27
36
|
uploadedUrl: string | null = null
|
|
37
|
+
/** media vars only: why the last drop or upload did not land, shown on the row */
|
|
38
|
+
mediaError: string | null = null
|
|
39
|
+
/** media vars only: an upload is on its way */
|
|
40
|
+
mediaBusy = false
|
|
28
41
|
|
|
29
42
|
constructor(
|
|
30
43
|
public readonly name: string,
|
|
@@ -52,6 +65,60 @@ export class VarSt {
|
|
|
52
65
|
this.uploadedUrl = url
|
|
53
66
|
}
|
|
54
67
|
|
|
68
|
+
/** the medium this row takes, null for a non-media var */
|
|
69
|
+
get mediaKind(): MediaKind | null {
|
|
70
|
+
return isMediaKind(this.desc.kind) ? this.desc.kind : null
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
setMediaError(message: string | null): void {
|
|
74
|
+
this.mediaError = message
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** a desktop file (picked or dropped): uploaded, the var points at the local copy */
|
|
78
|
+
async takeFile(file: File): Promise<void> {
|
|
79
|
+
const kind = this.mediaKind
|
|
80
|
+
if (kind == null) return
|
|
81
|
+
const refused = refuseDrop(kind, mediaKindOfFile(file), file.name)
|
|
82
|
+
if (refused != null) return this.setMediaError(refused)
|
|
83
|
+
await this.landMedia(file.name, () => uploadFile({ file }))
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** a gallery output (dragged, or its `→ var` button) */
|
|
87
|
+
async takeOutput(o: DraggedOutput): Promise<void> {
|
|
88
|
+
const kind = this.mediaKind
|
|
89
|
+
if (kind == null) return
|
|
90
|
+
const refused = refuseDrop(kind, o.kind, o.filename)
|
|
91
|
+
if (refused != null) return this.setMediaError(refused)
|
|
92
|
+
await this.landMedia(o.filename, () =>
|
|
93
|
+
valueForOutput(o, {
|
|
94
|
+
fetchBlob: async (url) => {
|
|
95
|
+
const res = await fetch(url)
|
|
96
|
+
if (!res.ok) throw new Error(`http ${res.status} on ${url}`)
|
|
97
|
+
return res.blob()
|
|
98
|
+
},
|
|
99
|
+
upload: (file) => uploadFile({ file }),
|
|
100
|
+
}),
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private async landMedia(what: string, get: () => Promise<{ path: string; url: string | null }>): Promise<void> {
|
|
105
|
+
this.mediaBusy = true
|
|
106
|
+
this.mediaError = null
|
|
107
|
+
try {
|
|
108
|
+
const value = await get()
|
|
109
|
+
runInAction(() => {
|
|
110
|
+
this.set(value.path)
|
|
111
|
+
this.uploadedUrl = value.url
|
|
112
|
+
})
|
|
113
|
+
} catch (e) {
|
|
114
|
+
const message = `${what}: ${e instanceof Error ? e.message : String(e)}`
|
|
115
|
+
logWebError('media input did not land', e)
|
|
116
|
+
runInAction(() => (this.mediaError = message))
|
|
117
|
+
} finally {
|
|
118
|
+
runInAction(() => (this.mediaBusy = false))
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
55
122
|
/** the workflow's declared default, in the shape the controls hold */
|
|
56
123
|
get defaultValue(): unknown {
|
|
57
124
|
return normalizeInitial(this.desc, this.desc.default)
|
|
@@ -71,6 +138,7 @@ export class VarSt {
|
|
|
71
138
|
this.value = this.initial
|
|
72
139
|
this.dirty = false
|
|
73
140
|
this.uploadedUrl = null
|
|
141
|
+
this.mediaError = null
|
|
74
142
|
}
|
|
75
143
|
|
|
76
144
|
snapshot(): { name: string; value: unknown } {
|
|
@@ -3,10 +3,23 @@
|
|
|
3
3
|
// ever reaches the host: queued prompts must be clearable, singly or
|
|
4
4
|
// all). Progress + latent preview are polled ~700ms while a prompt is in flight
|
|
5
5
|
import { makeAutoObservable, observableShallow, runInAction } from 'mobx'
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
deleteKeptResults,
|
|
8
|
+
fetchKeptResults,
|
|
9
|
+
fetchRunStatus,
|
|
10
|
+
postGenerate,
|
|
11
|
+
type GenerateOk,
|
|
12
|
+
type MemoryUsage,
|
|
13
|
+
} from 'src/cli/serve/web/api.ts'
|
|
14
|
+
import { mergeKept } from 'src/cli/serve/web/state/keptResults.ts'
|
|
15
|
+
import { logWebError } from 'src/cli/serve/web/logWeb.ts'
|
|
7
16
|
|
|
8
17
|
export type RunResult = GenerateOk & { at: string }
|
|
9
18
|
|
|
19
|
+
function asRunResult(r: GenerateOk): RunResult {
|
|
20
|
+
return { ...r, at: new Date(r.finishedAt ?? Date.now()).toLocaleTimeString() }
|
|
21
|
+
}
|
|
22
|
+
|
|
10
23
|
/** one enqueued prompt. `sent` marks the one on the host — that one is past cancelling */
|
|
11
24
|
export type QueueEntry = {
|
|
12
25
|
id: string
|
|
@@ -24,6 +37,8 @@ export class RunSt {
|
|
|
24
37
|
queue: QueueEntry[] = []
|
|
25
38
|
error: string | null = null
|
|
26
39
|
results: RunResult[] = []
|
|
40
|
+
/** the serve process's unsaved outputs against its budget. null = not read yet */
|
|
41
|
+
memory: MemoryUsage | null = null
|
|
27
42
|
progressPercent: number | null = null
|
|
28
43
|
/** what the host is doing right now, in the node's own unit — `TextGenerate 427/1024`.
|
|
29
44
|
* A text graph has no latent preview and no image, so this is all there is to watch */
|
|
@@ -71,16 +86,58 @@ export class RunSt {
|
|
|
71
86
|
this.queue = this.queue.filter((e) => e.id !== id || e.sent)
|
|
72
87
|
}
|
|
73
88
|
|
|
89
|
+
dismissError(): void {
|
|
90
|
+
this.error = null
|
|
91
|
+
}
|
|
92
|
+
|
|
74
93
|
clearQueue(): void {
|
|
75
94
|
this.queue = this.queue.filter((e) => e.sent)
|
|
76
95
|
}
|
|
77
96
|
|
|
97
|
+
/** the server forgets it too: a reload must not bring back what was removed */
|
|
78
98
|
remove(promptId: string): void {
|
|
79
99
|
this.results = this.results.filter((r) => r.promptId !== promptId)
|
|
100
|
+
void this.forget({ promptId })
|
|
80
101
|
}
|
|
81
102
|
|
|
82
103
|
clear(): void {
|
|
83
104
|
this.results = []
|
|
105
|
+
void this.forget({})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** what the serve process kept: the last runs survive a page reload */
|
|
109
|
+
async loadKept(): Promise<void> {
|
|
110
|
+
try {
|
|
111
|
+
const kept = await fetchKeptResults()
|
|
112
|
+
runInAction(() => {
|
|
113
|
+
this.results = mergeKept(this.results, kept.runs.map(asRunResult))
|
|
114
|
+
this.memory = kept.memory
|
|
115
|
+
})
|
|
116
|
+
} catch (e) {
|
|
117
|
+
logWebError('could not read the kept results', e)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async refreshMemory(): Promise<void> {
|
|
122
|
+
try {
|
|
123
|
+
const kept = await fetchKeptResults()
|
|
124
|
+
runInAction(() => {
|
|
125
|
+
this.memory = kept.memory
|
|
126
|
+
})
|
|
127
|
+
} catch (e) {
|
|
128
|
+
logWebError('could not read the memory usage', e)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private async forget(p: { promptId?: string }): Promise<void> {
|
|
133
|
+
try {
|
|
134
|
+
const reply = await deleteKeptResults(p)
|
|
135
|
+
runInAction(() => {
|
|
136
|
+
this.memory = reply.memory
|
|
137
|
+
})
|
|
138
|
+
} catch (e) {
|
|
139
|
+
logWebError('could not delete the kept result', e)
|
|
140
|
+
}
|
|
84
141
|
}
|
|
85
142
|
|
|
86
143
|
/** one prompt at a time: a queued entry stays cancellable until its turn comes */
|
|
@@ -105,9 +162,10 @@ export class RunSt {
|
|
|
105
162
|
try {
|
|
106
163
|
const result = await postGenerate(next)
|
|
107
164
|
runInAction(() => {
|
|
108
|
-
// capped: full-size <img>s per run would eat the tab
|
|
109
|
-
this.results = [
|
|
165
|
+
// capped like the server's list: full-size <img>s per run would eat the tab
|
|
166
|
+
this.results = mergeKept([asRunResult(result)], this.results)
|
|
110
167
|
})
|
|
168
|
+
void this.refreshMemory()
|
|
111
169
|
// named, because the panel may be on another draft by the time this resolves
|
|
112
170
|
this.onSeeds?.({ module: next.module, draft: next.draft, seeds: result.seeds })
|
|
113
171
|
} catch (e) {
|
|
@@ -35,6 +35,7 @@ import { logWebError } from 'src/cli/serve/web/logWeb.ts'
|
|
|
35
35
|
import { asSeedForm } from 'src/cli/serve/web/state/payload.ts'
|
|
36
36
|
import { readUrlSelection, resolveSelection, writeUrlSelection } from 'src/cli/serve/web/state/urlSelection.ts'
|
|
37
37
|
import { RunSt } from 'src/cli/serve/web/state/RunSt.ts'
|
|
38
|
+
import { DEFAULT_MEMORY_BUDGET_MB } from 'src/cli/serve/resultHistory.ts'
|
|
38
39
|
import { asLoraSort, type LoraSort } from 'src/cli/serve/web/state/loraSort.ts'
|
|
39
40
|
import {
|
|
40
41
|
coerceHostValue,
|
|
@@ -227,7 +228,13 @@ export class WebSt {
|
|
|
227
228
|
omnibox: OmniboxSt
|
|
228
229
|
/** SERVER settings, not browser ones: they decide whether a generation writes files at all
|
|
229
230
|
* and where, so they are shared by every client and read back from GET /settings */
|
|
230
|
-
settings: ServeSettings = {
|
|
231
|
+
settings: ServeSettings = {
|
|
232
|
+
saveToDisk: true,
|
|
233
|
+
hostOverride: {},
|
|
234
|
+
savePrefix: {},
|
|
235
|
+
memoryBudgetMb: DEFAULT_MEMORY_BUDGET_MB,
|
|
236
|
+
effectivePrefix: {},
|
|
237
|
+
}
|
|
231
238
|
savingError: string | null = null
|
|
232
239
|
/** what you are typing in a prefix field, before the debounced write lands */
|
|
233
240
|
private prefixEdits: Record<string, string> = {}
|
|
@@ -521,6 +528,7 @@ export class WebSt {
|
|
|
521
528
|
})
|
|
522
529
|
void this.loadSettings()
|
|
523
530
|
void this.loadHosts()
|
|
531
|
+
void this.run.loadKept()
|
|
524
532
|
const stored = readStoredSelection()
|
|
525
533
|
// the URL wins over the stored selection: a link someone sent is an instruction, the
|
|
526
534
|
// stored one is only a memory of this browser's last visit
|
|
@@ -902,6 +910,13 @@ export class WebSt {
|
|
|
902
910
|
/** results blurred until the pointer is on them: a screen someone else may see */
|
|
903
911
|
blurResults = false
|
|
904
912
|
|
|
913
|
+
/** the popup listing every key the panel binds */
|
|
914
|
+
showShortcuts = false
|
|
915
|
+
|
|
916
|
+
setShowShortcuts(b: boolean): void {
|
|
917
|
+
this.showShortcuts = b
|
|
918
|
+
}
|
|
919
|
+
|
|
905
920
|
/** the last ⌘P / ⌘O jump: the var it targets reacts to a NEW seq, so pressing it twice works */
|
|
906
921
|
jump: { kind: 'prompt' | 'loras'; seq: number } | null = null
|
|
907
922
|
|
|
@@ -1198,7 +1213,16 @@ export class WebSt {
|
|
|
1198
1213
|
)
|
|
1199
1214
|
}
|
|
1200
1215
|
|
|
1201
|
-
|
|
1216
|
+
/** the server evicts at once on a smaller budget, so the usage is re-read after */
|
|
1217
|
+
async setMemoryBudget(mb: number): Promise<void> {
|
|
1218
|
+
if (await this.pushSettings({ memoryBudgetMb: mb })) await this.run.refreshMemory()
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
private async pushSettings(patch: {
|
|
1222
|
+
saveToDisk?: boolean
|
|
1223
|
+
savePrefix?: Record<string, string>
|
|
1224
|
+
memoryBudgetMb?: number
|
|
1225
|
+
}): Promise<boolean> {
|
|
1202
1226
|
try {
|
|
1203
1227
|
const next = await saveSettings(patch)
|
|
1204
1228
|
runInAction(() => {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** the output row's slot in the stored field order. A var name is a js identifier, so it can
|
|
2
|
+
* never collide with this */
|
|
3
|
+
export const OUTPUT_ROW = ':output'
|
|
4
|
+
|
|
5
|
+
/** every row the form draws, in the workflow's order: its vars, then the output. A stored order
|
|
6
|
+
* that predates the output slot keeps the output last (orderedVars appends unknown names) */
|
|
7
|
+
export function formRowNames(varNames: readonly string[]): string[] {
|
|
8
|
+
return [...varNames, OUTPUT_ROW]
|
|
9
|
+
}
|
|
@@ -95,6 +95,8 @@ export function coerceHostValue(desc: VarDescriptor, raw: unknown, current: unkn
|
|
|
95
95
|
case 'prompt':
|
|
96
96
|
case 'text':
|
|
97
97
|
case 'image':
|
|
98
|
+
case 'audio':
|
|
99
|
+
case 'video':
|
|
98
100
|
return typeof raw === 'string' ? { ok: true, value: raw } : REJECT
|
|
99
101
|
case 'int':
|
|
100
102
|
return isFiniteNumber(raw) ? { ok: true, value: Math.trunc(raw) } : REJECT
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// the page's results after a reload: what the serve process kept, merged with what this page
|
|
2
|
+
// already holds (a run can finish while the list is in flight). PURE, headless-tested
|
|
3
|
+
import { KEPT_RUNS } from 'src/cli/serve/resultHistory.ts'
|
|
4
|
+
|
|
5
|
+
type Run = { promptId: string; finishedAt?: number }
|
|
6
|
+
|
|
7
|
+
/** one entry per promptId, the page's own copy first, newest first, capped like the server */
|
|
8
|
+
export function mergeKept<R extends Run>(current: readonly R[], kept: readonly R[]): R[] {
|
|
9
|
+
const seen = new Set(current.map((r) => r.promptId))
|
|
10
|
+
const merged = [...current, ...kept.filter((r) => !seen.has(r.promptId))]
|
|
11
|
+
return merged
|
|
12
|
+
.map((r, ix) => ({ r, ix }))
|
|
13
|
+
.sort((a, b) => (b.r.finishedAt ?? 0) - (a.r.finishedAt ?? 0) || a.ix - b.ix)
|
|
14
|
+
.map((x) => x.r)
|
|
15
|
+
.slice(0, KEPT_RUNS)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** an output that only the serve process holds: gone on a restart, or past the memory budget */
|
|
19
|
+
export function isEphemeral(out: { url: string | null; absPath: string | null }): boolean {
|
|
20
|
+
return out.absPath == null && out.url != null
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function formatMb(bytes: number): string {
|
|
24
|
+
const mb = bytes / (1024 * 1024)
|
|
25
|
+
return mb < 10 ? mb.toFixed(1) : String(Math.round(mb))
|
|
26
|
+
}
|
|
@@ -42,3 +42,20 @@ export function lightboxView(p: {
|
|
|
42
42
|
return { url: image.url, title: image.filename, promptId: finished?.promptId ?? null }
|
|
43
43
|
return { url: runPreviewSrc({ module, tick: p.previewTick }), title: 'latent preview', promptId: null }
|
|
44
44
|
}
|
|
45
|
+
|
|
46
|
+
/** ↑ / ↓ in the lightbox: the image before or after the open one, in the gallery's order
|
|
47
|
+
* (newest first, then each run's own image order). Stops at both ends. Null = no move */
|
|
48
|
+
export function lightboxStep(p: {
|
|
49
|
+
/** newest first */
|
|
50
|
+
results: readonly LightboxRun[]
|
|
51
|
+
url: string
|
|
52
|
+
dir: 1 | -1
|
|
53
|
+
}): Extract<LightboxTarget, { kind: 'image' }> | null {
|
|
54
|
+
const all = p.results.flatMap((r) =>
|
|
55
|
+
r.images.flatMap((i) => (i.url == null ? [] : [{ url: i.url, title: i.filename, promptId: r.promptId }])),
|
|
56
|
+
)
|
|
57
|
+
const ix = all.findIndex((x) => x.url === p.url)
|
|
58
|
+
if (ix < 0) return null
|
|
59
|
+
const next = all[ix + p.dir]
|
|
60
|
+
return next == null ? null : { kind: 'image', ...next }
|
|
61
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// what lands on a media var: a desktop file or a gallery output. PURE (the fetch and the upload
|
|
2
|
+
// are injected), tests/serve-web-media-drop.test.ts. The var must end on a LOCAL PATH, because
|
|
3
|
+
// that is the only value /generate accepts without a download
|
|
4
|
+
import { DEFAULT_MEDIA_EXTENSIONS, extensionOf, MEDIA_KINDS, type MediaKind } from 'src/runner/mediaKinds.ts'
|
|
5
|
+
|
|
6
|
+
/** the dataTransfer type a gallery output drags under */
|
|
7
|
+
export const OUTPUT_DRAG_MIME = 'application/x-comfy-output'
|
|
8
|
+
|
|
9
|
+
export type DraggedOutput = { kind: MediaKind; url: string | null; absPath: string | null; filename: string }
|
|
10
|
+
|
|
11
|
+
export function encodeDraggedOutput(o: DraggedOutput): string {
|
|
12
|
+
return JSON.stringify(o)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** null on anything that is not one of ours: a drop can come from any page */
|
|
16
|
+
export function decodeDraggedOutput(raw: string): DraggedOutput | null {
|
|
17
|
+
let parsed: unknown
|
|
18
|
+
try {
|
|
19
|
+
parsed = JSON.parse(raw)
|
|
20
|
+
} catch {
|
|
21
|
+
return null
|
|
22
|
+
}
|
|
23
|
+
if (parsed == null || typeof parsed !== 'object') return null
|
|
24
|
+
// family 10: every field is checked right below before the object is claimed
|
|
25
|
+
const o = parsed as Record<string, unknown>
|
|
26
|
+
const kind = o.kind
|
|
27
|
+
if (typeof kind !== 'string' || !isMediaKind(kind)) return null
|
|
28
|
+
if (typeof o.filename !== 'string') return null
|
|
29
|
+
// any page can put this type on a drag: only a same-origin url and an absolute path are ours
|
|
30
|
+
const url = typeof o.url === 'string' && /^\/(?!\/)/.test(o.url) ? o.url : null
|
|
31
|
+
const absPath = typeof o.absPath === 'string' && /^(\/|[A-Za-z]:[\\/])/.test(o.absPath) ? o.absPath : null
|
|
32
|
+
if (o.url != null && url == null) return null
|
|
33
|
+
if (o.absPath != null && absPath == null) return null
|
|
34
|
+
if (url == null && absPath == null) return null
|
|
35
|
+
return { kind, url, absPath, filename: o.filename }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function isMediaKind(kind: string): kind is MediaKind {
|
|
39
|
+
return (MEDIA_KINDS as readonly string[]).includes(kind)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** a desktop file's medium: its mime first, its extension when the browser gave no mime */
|
|
43
|
+
export function mediaKindOfFile(file: { name: string; type: string }): MediaKind | null {
|
|
44
|
+
const top = file.type.split('/')[0] ?? ''
|
|
45
|
+
if (isMediaKind(top)) return top
|
|
46
|
+
const ext = extensionOf(file.name)
|
|
47
|
+
return MEDIA_KINDS.find((k) => DEFAULT_MEDIA_EXTENSIONS[k].includes(ext)) ?? null
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** null when the var takes it, else the reason it does not, said to the user */
|
|
51
|
+
export function refuseDrop(varKind: MediaKind, dropped: MediaKind | null, what: string): string | null {
|
|
52
|
+
if (dropped === varKind) return null
|
|
53
|
+
return `this is ${article(varKind)} input: ${what} is ${dropped == null ? 'not a known media file' : article(dropped)}`
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function article(kind: MediaKind): string {
|
|
57
|
+
return kind === 'video' ? `a ${kind}` : `an ${kind}`
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type MediaValue = { path: string; url: string | null }
|
|
61
|
+
|
|
62
|
+
/** a saved output is already a local path. An unsaved one lives in the server memory only, so
|
|
63
|
+
* its bytes are fetched and uploaded, and the var points at the uploaded copy */
|
|
64
|
+
export async function valueForOutput(
|
|
65
|
+
o: DraggedOutput,
|
|
66
|
+
deps: {
|
|
67
|
+
fetchBlob: (url: string) => Promise<Blob>
|
|
68
|
+
upload: (file: File) => Promise<{ path: string; url: string | null }>
|
|
69
|
+
},
|
|
70
|
+
): Promise<MediaValue> {
|
|
71
|
+
if (o.absPath != null) return { path: o.absPath, url: o.url }
|
|
72
|
+
if (o.url == null) throw new Error(`${o.filename} is no longer in memory: nothing to use`)
|
|
73
|
+
const blob = await deps.fetchBlob(o.url)
|
|
74
|
+
const reply = await deps.upload(new File([blob], o.filename, { type: blob.type }))
|
|
75
|
+
return { path: reply.path, url: reply.url }
|
|
76
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { MOD_KEY } from 'src/cli/serve/web/components/modKey.ts'
|
|
2
|
+
import {
|
|
3
|
+
ENHANCER_KEYS,
|
|
4
|
+
SHORTCUT_KEYS,
|
|
5
|
+
type EnhancerShortcut,
|
|
6
|
+
type Shortcut,
|
|
7
|
+
} from 'src/cli/serve/web/state/shortcuts.ts'
|
|
8
|
+
|
|
9
|
+
/** every key the panel binds, as the shortcuts popup lists it. The jump and enhancer rows are
|
|
10
|
+
* DERIVED from their key tables (a Record, so a new shortcut without a line fails typecheck); the
|
|
11
|
+
* prompt editor rows name their codemirror bindings, which tests/serve-web-shortcut-catalog.test.ts
|
|
12
|
+
* checks against promptExtensions.ts */
|
|
13
|
+
export type ShortcutRow = { keys: string[]; what: string; cm?: string[] }
|
|
14
|
+
export type ShortcutGroup = { title: string; rows: ShortcutRow[] }
|
|
15
|
+
|
|
16
|
+
const JUMP_WHAT: Record<Shortcut, string> = {
|
|
17
|
+
'focus-prompt': 'focus the first prompt',
|
|
18
|
+
'open-loras': 'open the lora picker',
|
|
19
|
+
'open-enhancer': 'open the prompt enhancer',
|
|
20
|
+
'rename-draft': 'rename the draft',
|
|
21
|
+
'duplicate-draft': 'duplicate the draft',
|
|
22
|
+
'toggle-menu': 'fold or unfold the menu',
|
|
23
|
+
'toggle-blur': 'blur or unblur the results',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const ENHANCER_WHAT: Record<EnhancerShortcut, string> = {
|
|
27
|
+
enhance: 'enhance the prompt',
|
|
28
|
+
apply: 'apply the rewrite to the prompt',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const cap = (mod: string, k: string): string => (/^F\d{1,2}$/.test(k) ? k : `${mod}${k}`)
|
|
32
|
+
|
|
33
|
+
export function shortcutCatalog(mod: string = MOD_KEY): ShortcutGroup[] {
|
|
34
|
+
const jumps = (Object.keys(JUMP_WHAT) as Shortcut[]).map((s) => ({
|
|
35
|
+
keys: [cap(mod, SHORTCUT_KEYS[s])],
|
|
36
|
+
what: JUMP_WHAT[s],
|
|
37
|
+
}))
|
|
38
|
+
const enhancer = (Object.keys(ENHANCER_WHAT) as EnhancerShortcut[]).map((s) => ({
|
|
39
|
+
keys: [cap(mod, ENHANCER_KEYS[s])],
|
|
40
|
+
what: ENHANCER_WHAT[s],
|
|
41
|
+
}))
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
title: 'anywhere',
|
|
45
|
+
rows: [
|
|
46
|
+
{ keys: [`${mod}⏎`], what: 'run the draft' },
|
|
47
|
+
{ keys: [`${mod}K`, `${mod}J`], what: 'search every workflow and draft' },
|
|
48
|
+
{ keys: [`${mod}1 … ${mod}8`], what: 'open tab 1 to 8' },
|
|
49
|
+
{ keys: [`${mod}9`], what: 'open the last tab' },
|
|
50
|
+
{ keys: [`${mod}PageUp`, `${mod}PageDown`], what: 'previous or next tab, wrapping' },
|
|
51
|
+
...jumps,
|
|
52
|
+
{ keys: [`${mod}A`], what: 'select all in the field you are in' },
|
|
53
|
+
{ keys: ['Esc'], what: 'close the popup on top' },
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
title: 'prompt editor',
|
|
58
|
+
rows: [
|
|
59
|
+
{
|
|
60
|
+
keys: [`${mod}↑`, `${mod}↓`],
|
|
61
|
+
what: 'weight of the word or selection up or down',
|
|
62
|
+
cm: ['Mod-ArrowUp', 'Mod-ArrowDown', 'Ctrl-ArrowUp', 'Ctrl-ArrowDown'],
|
|
63
|
+
},
|
|
64
|
+
{ keys: [`${mod}/`], what: 'comment the line in or out', cm: ['Mod-/'] },
|
|
65
|
+
{ keys: [`${mod}⇧-`], what: 'make the line negative, or positive again', cm: ['Mod-Shift--', 'Mod-_'] },
|
|
66
|
+
{ keys: ['⌥↑', '⌥↓'], what: 'move the line up or down', cm: ['Alt-ArrowUp', 'Alt-ArrowDown'] },
|
|
67
|
+
{ keys: [`${mod}Z`, `${mod}⇧Z`], what: 'undo, redo' },
|
|
68
|
+
{ keys: ['↑', '↓', '⏎', 'Esc'], what: 'in the completion list: move, pick, dismiss' },
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
title: 'prompt enhancer',
|
|
73
|
+
rows: [...enhancer, { keys: [`${mod}⏎`], what: 'run with the rewrite, the prompt stays as it is' }],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
title: 'lightbox',
|
|
77
|
+
rows: [
|
|
78
|
+
{ keys: ['↑', '↓'], what: 'previous or next image of the gallery' },
|
|
79
|
+
{ keys: ['scroll'], what: 'zoom at the pointer, drag to pan' },
|
|
80
|
+
{ keys: ['double click'], what: 'back to fit' },
|
|
81
|
+
{ keys: ['Esc'], what: 'close' },
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
title: 'search and history pickers',
|
|
86
|
+
rows: [
|
|
87
|
+
{ keys: ['↑', '↓'], what: 'move' },
|
|
88
|
+
{ keys: ['⏎'], what: 'open the pick' },
|
|
89
|
+
{ keys: ['Esc'], what: 'close' },
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
title: 'renaming',
|
|
94
|
+
rows: [
|
|
95
|
+
{ keys: ['⏎'], what: 'keep the new name' },
|
|
96
|
+
{ keys: ['Esc'], what: 'cancel' },
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
]
|
|
100
|
+
}
|
|
@@ -73,6 +73,16 @@ export function shortcutOf(e: {
|
|
|
73
73
|
return null
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/** does this ⌘P / ⌘O press act on a var whose last seen press is `seenSeq`. The stored jump
|
|
77
|
+
* outlives the press: a var that mounts later (a tab switch rebuilds the form) must not replay it */
|
|
78
|
+
export function isNewJump(
|
|
79
|
+
jump: { kind: 'prompt' | 'loras'; seq: number } | null,
|
|
80
|
+
kind: 'prompt' | 'loras',
|
|
81
|
+
seenSeq: number,
|
|
82
|
+
): boolean {
|
|
83
|
+
return jump != null && jump.kind === kind && jump.seq > seenSeq
|
|
84
|
+
}
|
|
85
|
+
|
|
76
86
|
/** which var each jump lands on: the FIRST var of that kind in the order shown, skipping one
|
|
77
87
|
* that is disabled (it takes no focus) */
|
|
78
88
|
export function jumpTargets(vars: readonly { name: string; kind: string; inactive: boolean }[]): {
|