comfy-ts 2.15.0 → 2.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/{LogsSt-C3UIWR-o.js → LogsSt-Ct7Le0S_.js} +2 -2
  2. package/dist/{LogsSt-C3UIWR-o.js.map → LogsSt-Ct7Le0S_.js.map} +1 -1
  3. package/dist/cli.js +4 -4
  4. package/dist/index.cjs +57 -4
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +55 -7
  7. package/dist/index.d.ts +55 -7
  8. package/dist/index.js +57 -4
  9. package/dist/index.js.map +1 -1
  10. package/dist/{run-serve-B5PfIuhK.js → run-serve-C78hD7t9.js} +14 -5
  11. package/dist/run-serve-C78hD7t9.js.map +1 -0
  12. package/dist/{run-tui-D-N4_yyX.js → run-tui-nPETFRmk.js} +4 -4
  13. package/dist/{run-tui-D-N4_yyX.js.map → run-tui-nPETFRmk.js.map} +1 -1
  14. package/dist/{schemaDrift-BkN8rLiZ.js → schemaDrift-wb5XkrHV.js} +57 -4
  15. package/dist/schemaDrift-wb5XkrHV.js.map +1 -0
  16. package/dist/serve-web.js +48 -48
  17. package/dist/{state-CZsYJqB6.js → state-BMW57_M0.js} +3 -3
  18. package/dist/{state-CZsYJqB6.js.map → state-BMW57_M0.js.map} +1 -1
  19. package/dist/web.d.ts +55 -7
  20. package/dist/web.js +57 -4
  21. package/dist/web.js.map +1 -1
  22. package/examples/README.md +1 -0
  23. package/examples/media/README.md +6 -5
  24. package/examples/media/voice_en_6s.flac +0 -0
  25. package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +9 -1
  26. package/examples/rvion/10-anima-t2i.cflow.ts +8 -1
  27. package/examples/rvion/15-tts-voice-clone.cflow.ts +111 -0
  28. package/guide-for-agents.md +2 -1
  29. package/package.json +2 -2
  30. package/src/cli/serve/ServeApp.ts +15 -3
  31. package/src/cli/serve/web/components/DraftTabs.tsx +2 -1
  32. package/src/cli/serve/web/components/Gallery.tsx +2 -1
  33. package/src/cli/serve/web/components/HistoryPicker.tsx +5 -3
  34. package/src/cli/serve/web/components/MenuButton.tsx +2 -4
  35. package/src/cli/serve/web/components/Omnibox.tsx +2 -1
  36. package/src/cli/serve/web/components/PromptEnhancer.tsx +4 -3
  37. package/src/cli/serve/web/components/ShortcutsModal.tsx +2 -1
  38. package/src/cli/serve/web/components/SideMenu.tsx +2 -1
  39. package/src/cli/serve/web/components/controls/LorasControl.tsx +4 -3
  40. package/src/cli/serve/web/components/controls/PresetPicker.tsx +2 -1
  41. package/src/cli/serve/web/components/controls/PromptControl.tsx +2 -1
  42. package/src/cli/serve/web/components/controls/SizeControl.tsx +2 -1
  43. package/src/cli/serve/web/state/escape.ts +16 -0
  44. package/src/coreExports.ts +10 -1
  45. package/src/vars/ComfyVars.ts +83 -13
  46. package/src/vars/DefinedWorkflow.ts +35 -2
  47. package/dist/run-serve-B5PfIuhK.js.map +0 -1
  48. package/dist/schemaDrift-BkN8rLiZ.js.map +0 -1
@@ -9,6 +9,7 @@ Every `*.cflow.ts` file here is a runnable workflow module: run it directly with
9
9
  - `rvion/06-qwen-image-edit.cflow.ts` — image editing (qwen image edit 2511) against the same local host.
10
10
  - `rvion/07-local-llm-text-gen.cflow.ts` — a local LLM, no image: core's `TextGenerate` runs a chat model loaded through `CLIPLoader`, and the text comes back in `execution.text`. `--sweep` reports which text encoders on your host actually generate.
11
11
  - `rvion/08-qwen-image-21-t2i.cflow.ts` / `rvion/09-qwen-image-21-edit.cflow.ts` — Qwen Image 2.1 (ComfyUI ≥ 0.37) against the same local host: text to image, and instruction editing of one reference image (its `remove background` preset is the official background-removal template).
12
+ - `rvion/15-tts-voice-clone.cflow.ts` — text to speech in a cloned voice (needs the [TTS-Audio-Suite](https://github.com/diodiogod/TTS-Audio-Suite) custom node pack on the host): pick an engine (Chatterbox Multilingual v3 by default, Qwen3-TTS, Fish Audio S2 Pro, CosyVoice3, OmniVoice) and a language, drop a voice clip and write its transcript, and the text comes back as audio in `execution.audios`.
12
13
  - `comfy-cloud/<family>-<mode>.cflow.ts` — the model zoo: one clean example per model family × mode (`t2i`, `i2i`, `t2v`, `i2v`, `t2a`), each mirroring an official ComfyUI template (flux, qwen-image, z-image, wan, hidream, ace-step, …). All share `comfy-cloud/cloudHost.ts`.
13
14
 
14
15
  ## Cloud API key
@@ -1,8 +1,9 @@
1
1
  # Bundled example media
2
2
 
3
- Default inputs for the examples that take an audio or a video file. They ship in the npm tarball, so these examples run out of the box. Both are synthetic (ffmpeg test sources), so no license question applies.
3
+ Default inputs for the examples that take an audio or a video file. They ship in the npm tarball, so these examples run out of the box. All are synthetic (ffmpeg test sources, or a voice invented by a TTS model), so no license question applies.
4
4
 
5
- | file | what | made with |
6
- | ------------------------ | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
7
- | `testsrc_256x256_3s.mp4` | 3 s, 256×256, 12 fps, h264, no audio track | `ffmpeg -f lavfi -i "testsrc2=size=256x256:rate=12:duration=3" -c:v libx264 -pix_fmt yuv420p -crf 30 -movflags +faststart` |
8
- | `sine_440hz_3s.flac` | 3 s, 440 Hz sine at 30% volume, 22.05 kHz | `ffmpeg -f lavfi -i "sine=frequency=440:duration=3:sample_rate=22050" -af "volume=0.3" -c:a flac` |
5
+ | file | what | made with |
6
+ | ------------------------ | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
7
+ | `testsrc_256x256_3s.mp4` | 3 s, 256×256, 12 fps, h264, no audio track | `ffmpeg -f lavfi -i "testsrc2=size=256x256:rate=12:duration=3" -c:v libx264 -pix_fmt yuv420p -crf 30 -movflags +faststart` |
8
+ | `sine_440hz_3s.flac` | 3 s, 440 Hz sine at 30% volume, 22.05 kHz | `ffmpeg -f lavfi -i "sine=frequency=440:duration=3:sample_rate=22050" -af "volume=0.3" -c:a flac` |
9
+ | `voice_en_6s.flac` | 6.4 s of English speech, 24 kHz mono, the default voice of example 15 | Qwen3-TTS 1.7B VoiceDesign (Apache 2.0), instruction « a calm, warm adult narrator in his thirties, clear diction, neutral American English accent, steady medium pace », text « This is a short sample of my voice. Clone it, and I can read any text you give me, in many languages. », seed 7 |
Binary file
@@ -45,6 +45,14 @@ export const t2i = host.defineWorkflow({
45
45
  // number still says exactly which one you are on
46
46
  seed: v.seed(517, { mode: '+' }),
47
47
  steps: v.int(8, { min: 1, max: 40 }),
48
+ // the base model: every krea file the box has, read live from the host (serve's
49
+ // "refresh schema" picks up a new download). A finetune is chosen in the draft,
50
+ // so its file name never has to be written here
51
+ checkpoint: v.model('UNETLoader.unet_name', {
52
+ filter: /krea/i,
53
+ default: 'krea2_turbo_fp8_scaled.safetensors',
54
+ label: 'checkpoint',
55
+ }),
48
56
  size: v.size({ width: 1024, height: 1024 }),
49
57
  removeBg: v.toggle(true, 'remove bg'),
50
58
  loras,
@@ -52,7 +60,7 @@ export const t2i = host.defineWorkflow({
52
60
  },
53
61
  build: (b, vars) => {
54
62
  // models
55
- const unet = b.UNETLoader({ unet_name: 'krea2_turbo_fp8_scaled.safetensors', weight_dtype: 'default' })
63
+ const unet = b.UNETLoader({ unet_name: vars.checkpoint, weight_dtype: 'default' })
56
64
  const clipLoader = b.CLIPLoader({
57
65
  clip_name: 'qwen3vl_4b_fp8_scaled.safetensors',
58
66
  type: 'krea2',
@@ -151,6 +151,13 @@ export const animaT2i = host.defineWorkflow({
151
151
  groupColor: 'rgba(122, 162, 247, 0.08)',
152
152
  description: 'turbo and base+turbo: 8 steps at turbo cfg. aesthetic and base: the steps and cfg below',
153
153
  }),
154
+ // a finetune in place of the model's own file, read live from the host. The model
155
+ // choice above still decides the sampling (turbo or not), so pick the one it matches
156
+ checkpoint: v.model('UNETLoader.unet_name', { filter: /anima/i, default: null, label: 'checkpoint' }).ui({
157
+ group: 'sampling',
158
+ description:
159
+ "none = the model choice's own file. Any other file replaces it and keeps that choice's sampling",
160
+ }),
154
161
  // auto = er_sde on aesthetic and base, euler on the distilled ones
155
162
  sampler: v.choice(['auto', 'er_sde', 'euler', 'euler_ancestral'], 'auto', 'sampler').ui({ group: 'sampling' }),
156
163
  // the distilled models ignore these: 8 steps at cfg 1 is what they were distilled for
@@ -187,7 +194,7 @@ export const animaT2i = host.defineWorkflow({
187
194
  device: 'default',
188
195
  })
189
196
  const spec = MODELS[vars.model]
190
- let model = b.UNETLoader({ unet_name: spec.unet, weight_dtype: 'default' })._MODEL
197
+ let model = b.UNETLoader({ unet_name: vars.checkpoint ?? spec.unet, weight_dtype: 'default' })._MODEL
191
198
  let clip = clipLoader._CLIP
192
199
  if (spec.turboLora) model = b.LoraLoaderModelOnly({ model, lora_name: TURBO_LORA, strength_model: 1 })._MODEL
193
200
  for (const l of activeLoras(vars.loras)) {
@@ -0,0 +1,111 @@
1
+ // text to speech in a cloned voice, on windows-1: one reference clip and its transcript become the
2
+ // voice, and the engine you pick reads your text with it, in the language you pick
3
+ // engines: chatterbox (Chatterbox Multilingual v3, 0.5B, fast), qwen3 (Qwen3-TTS 1.7B Base),
4
+ // fishs2 (Fish Audio S2 Pro, fp8), cosyvoice3 (Fun-CosyVoice3 0.5B), omnivoice (OmniVoice)
5
+ // box inventory: custom node pack TTS-Audio-Suite (github.com/diodiogod/TTS-Audio-Suite); every
6
+ // engine downloads its weights on first use, which takes minutes. The bundled voice is synthetic
7
+ // (examples/media/README.md); drop your own clip on `voice` and write what it says in `transcript`
8
+ // run directly: bun examples/rvion/15-tts-voice-clone.cflow.ts ["text"] [engine] [language]
9
+ import { ComfyTS, exampleMediaPath, v } from 'comfy-ts'
10
+
11
+ const comfy = ComfyTS.create()
12
+ const host = comfy.host({ id: 'windows-1', host: 'desktop-im18794', port: 8085 })
13
+ await host.loadSchemaFromCache() // offline import; run() connects lazily
14
+
15
+ const ENGINES = ['chatterbox', 'qwen3', 'fishs2', 'cosyvoice3', 'omnivoice'] as const
16
+ // the languages every engine here names the same way
17
+ const LANGUAGES = [
18
+ 'English',
19
+ 'French',
20
+ 'German',
21
+ 'Spanish',
22
+ 'Italian',
23
+ 'Portuguese',
24
+ 'Russian',
25
+ 'Japanese',
26
+ 'Korean',
27
+ 'Chinese',
28
+ ] as const
29
+
30
+ // bundled default (examples/media/, ships in the tarball)
31
+ const voice = v.audio(exampleMediaPath('voice_en_6s.flac'))
32
+
33
+ export const ttsVoiceClone = host.defineWorkflow({
34
+ id: 'tts-voice-clone',
35
+ tags: ['tts', 'voice'],
36
+ vars: {
37
+ prompt: v.prompt(
38
+ 'Welcome back, traveler. The road ahead is long, but the view from the top is worth every step.',
39
+ ),
40
+ seed: v.seed(1),
41
+ engine: v.choice(ENGINES, 'chatterbox', 'engine'),
42
+ language: v.choice(LANGUAGES, 'English', 'language'),
43
+ voice,
44
+ transcript: v.text(
45
+ 'This is a short sample of my voice. Clone it, and I can read any text you give me, in many languages.',
46
+ {
47
+ label: 'transcript of the voice clip',
48
+ },
49
+ ),
50
+ },
51
+ // async build: the voice clip is uploaded (hash-named, deduped) per run
52
+ build: async (b, vars, wf) => {
53
+ const S = 'TTS-Audio-Suite'
54
+ const engine = (() => {
55
+ switch (vars.engine) {
56
+ case 'chatterbox':
57
+ return b[`${S}.ChatterBoxOfficial23LangEngineNode`]({
58
+ model_version: 'v3',
59
+ language: vars.language,
60
+ device: 'auto',
61
+ })
62
+ case 'qwen3':
63
+ return b[`${S}.Qwen3TTSEngineNode`]({
64
+ model_variant: 'TTS - Base 1.7B (Voice Clone)',
65
+ device: 'auto',
66
+ voice_preset: 'None (Zero-shot / Custom)',
67
+ language: vars.language,
68
+ instruct: '',
69
+ })
70
+ case 'fishs2':
71
+ return b[`${S}.FishAudioS2EngineNode`]({ model: 's2-pro-fp8', device: 'auto' })
72
+ case 'cosyvoice3':
73
+ return b[`${S}.CosyVoiceEngineNode`]({ model_path: 'Fun-CosyVoice3-0.5B-RL', device: 'auto' })
74
+ case 'omnivoice':
75
+ return b[`${S}.OmniVoiceEngineNode`]({
76
+ model_variant: 'OmniVoice',
77
+ device: 'auto',
78
+ language: vars.language,
79
+ })
80
+ }
81
+ })()
82
+ const narrator = b[`${S}.CharacterVoicesNode`]({
83
+ voice_name: 'none',
84
+ reference_text: vars.transcript,
85
+ opt_audio_input: await voice.loadInWorkflow(wf),
86
+ })
87
+ const speech = b[`${S}.UnifiedTTSTextNode`]({
88
+ TTS_engine: engine.outputs.TTS_engine,
89
+ text: vars.prompt.positive,
90
+ narrator_voice: 'none',
91
+ opt_narrator: narrator.outputs.opt_narrator,
92
+ seed: vars.seed,
93
+ enable_chunking: false,
94
+ enable_audio_cache: false,
95
+ })
96
+ b.PreviewAudio({ audio: speech.outputs.audio })
97
+ },
98
+ })
99
+
100
+ export default ttsVoiceClone
101
+
102
+ // standalone run (skipped when another driver — e.g. the TUI — imports this module)
103
+ if (import.meta.main) {
104
+ if (process.argv[2]) ttsVoiceClone.vars.prompt.set(process.argv[2])
105
+ if (process.argv[3]) ttsVoiceClone.vars.engine.set(process.argv[3] as (typeof ENGINES)[number])
106
+ if (process.argv[4]) ttsVoiceClone.vars.language.set(process.argv[4] as (typeof LANGUAGES)[number])
107
+
108
+ const execution = await ttsVoiceClone.run({ log: true, save: { prefix: 'comfy-ts-example/tts-voice-clone' } })
109
+ for (const clip of execution.audios) console.log(`🟢 ${clip.absPath}`)
110
+ host.disconnect()
111
+ }
@@ -71,11 +71,12 @@ if (import.meta.main) {
71
71
  }
72
72
  ```
73
73
 
74
- Var kinds: `v.text`, `v.int`, `v.float`, `v.seed`, `v.toggle`, `v.choice`, `v.size`, `v.loras`, `v.prompt`, `v.image`, `v.audio`, `v.video`. Notes:
74
+ Var kinds: `v.text`, `v.int`, `v.float`, `v.seed`, `v.toggle`, `v.choice`, `v.size`, `v.loras`, `v.prompt`, `v.model`, `v.image`, `v.audio`, `v.video`. Notes:
75
75
 
76
76
  - `v.loras(/regex/)` resolves against the host's real lora list; `activeLoras(vars.loras)` returns `{ lora_name, strength_model, strength_clip }[]` for a standard `LoraLoader` chain.
77
77
  - `v.prompt` is structured: `//` lines are comments (stripped), `- ` lines go to the negative prompt, `{ loraKeywordsFrom: lorasVar }` prefixes lora trigger keywords. The value is `{ positive, negative }`.
78
78
  - `v.image` holds a local image path as a plain string; an empty value throws at build time instead of running a silent placeholder. Capture the var in a const and call `image.absPath()` in `build`. Default it to a bundled sample with `exampleImagePath('bear_1024x1024.jpg')` (ships in the package). In the TUI it opens an image picker (browse, favorite folders, recents, preview).
79
+ - `v.model('UNETLoader.unet_name', { default, filter })` (in a `vars: (v) => …` lambda) is a choice over the host's file list for that loader input; use it instead of writing a model file name into the workflow.
79
80
  - `v.audio` and `v.video` work the same way for audio and video files. In `build`, `await myVar.loadInWorkflow(wf)` uploads the file and returns the loader node (`LoadImage`, `LoadAudio`, `LoadVideo`). Default them with `exampleMediaPath('sine_440hz_3s.flac')` or `exampleMediaPath('testsrc_256x256_3s.mp4')`. Video results land in `execution.videos`.
80
81
  - `vars` may be a lambda `(v) => ({ ... })` so vars can reference each other.
81
82
  - `build` may be async, for uploads: the third param `wf` feeds `MediaImage` helpers (`new MediaImage({ path }).loadInWorkflow_viaLoadImageNode(wf)`). Uploads are hash-named and deduped, nothing is re-sent.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comfy-ts",
3
- "version": "2.15.0",
3
+ "version": "2.16.0",
4
4
  "description": "The complete TypeScript toolkit for ComfyUI and generative AI. Fully type-safe SDK with autocomplete on every node, companion CLI, TUI, agentic docs, and 50+ examples. Design, run and deploy creative pipelines for image, video, audio, 3d and text on any ComfyUI, local, cloud or hosted.",
5
5
  "keywords": [
6
6
  "comfyui",
@@ -140,7 +140,7 @@
140
140
  "oxfmt": "^0.60.0",
141
141
  "oxlint": "^1.75.0",
142
142
  "oxlint-tsgolint": "^7.0.2001",
143
- "rvlib-shipkit": "^1.6.0",
143
+ "rvlib-shipkit": "^1.7.0",
144
144
  "rvlib-ts-tools": "^0.3.3",
145
145
  "tsdown": "^0.22.14",
146
146
  "typescript": "^7.0.2"
@@ -74,7 +74,7 @@ import {
74
74
  import { getLoraKeyword } from 'src/vars/loraKeywords.ts'
75
75
  import type { ComfyHost } from 'src/host/ComfyHost.ts'
76
76
  import { DEFAULT_MEDIA_EXTENSIONS, MEDIA_KINDS, type MediaKind } from 'src/runner/mediaKinds.ts'
77
- import type { LorasVar, MediaVar, PromptVar, SeedVar } from 'src/vars/ComfyVars.ts'
77
+ import type { ChoiceVar, LorasVar, MediaVar, OptionalChoiceVar, PromptVar, SeedVar } from 'src/vars/ComfyVars.ts'
78
78
  import type { DefinedWorkflow } from 'src/vars/DefinedWorkflow.ts'
79
79
  import { bang } from 'src/utils/bang.ts'
80
80
  import { extractErrorMessage } from 'src/utils/extractErrorMessage.ts'
@@ -950,13 +950,13 @@ export class ServeApp {
950
950
  const dropped =
951
951
  rebound.stale.length === 0
952
952
  ? ''
953
- : `. dropped ${rebound.stale.length} selection(s) this host no longer lists`
953
+ : `. ${rebound.stale.length} selection(s) this host no longer lists (a lora is dropped, a model stays picked)`
954
954
  return json(200, {
955
955
  ok: true,
956
956
  host: hostId,
957
957
  action,
958
958
  stale: rebound.stale,
959
- note: `schema refetched: ${nodes} node types, ${loras} loras, ${rebound.widened} lora var(s) changed${dropped}${lorasNote}`,
959
+ note: `schema refetched: ${nodes} node types, ${loras} loras, ${rebound.widened} lora or model var(s) changed${dropped}${lorasNote}`,
960
960
  })
961
961
  }
962
962
  if (action === 'restart') {
@@ -993,6 +993,18 @@ export class ServeApp {
993
993
  if (mod.dw.host.data.id !== hostId) continue
994
994
  await this.exclusive(mod.key, () => {
995
995
  for (const [name, varDef] of mod.dw.entries()) {
996
+ if (varDef.kind === 'choice') {
997
+ const choice = varDef as ChoiceVar<string> | OptionalChoiceVar<string>
998
+ if (choice.hostSlot == null) continue
999
+ const before = choice.choices.length
1000
+ choice.bindHost(host)
1001
+ if (choice.choices.length !== before) widened++
1002
+ // a model the box no longer lists stays picked: the run then fails on the host,
1003
+ // naming the file, instead of silently running another model
1004
+ if (choice.value != null && !choice.choices.includes(choice.value))
1005
+ stale.push(`${mod.key}/${name}: ${choice.value}`)
1006
+ continue
1007
+ }
996
1008
  if (varDef.kind !== 'loras') continue
997
1009
  const lorasVar = varDef as LorasVar<string>
998
1010
  if (lorasVar.optionsFilter == null) continue // a plain array never re-resolves
@@ -18,6 +18,7 @@ import { MOD_KEY } from 'src/cli/serve/web/components/modKey.ts'
18
18
  import { tabForKey, tabStepForKey, type DraftTab } from 'src/cli/serve/web/state/draftTabs.ts'
19
19
  import { shortcutLabel } from 'src/cli/serve/web/state/shortcuts.ts'
20
20
  import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
21
+ import { onEscape } from 'src/cli/serve/web/state/escape.ts'
21
22
 
22
23
  export function useTabShortcuts(st: WebSt): void {
23
24
  useEffect(() => {
@@ -128,7 +129,7 @@ const TabMenu = observer(function TabMenu(p: { st: WebSt; tab: DraftTab; anchor:
128
129
  onChange={(e) => setName(e.target.value)}
129
130
  onKeyDown={(e) => {
130
131
  if (e.key === 'Enter') rename()
131
- if (e.key === 'Escape') p.onClose()
132
+ onEscape(e, () => p.onClose())
132
133
  }}
133
134
  />
134
135
  <button
@@ -14,6 +14,7 @@ import { copyImageToClipboard } from 'src/cli/serve/web/clipboard.ts'
14
14
  import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
15
15
  import { MOD_KEY } from 'src/cli/serve/web/components/modKey.ts'
16
16
  import { SHORTCUT_KEYS } from 'src/cli/serve/web/state/shortcuts.ts'
17
+ import { onEscape } from 'src/cli/serve/web/state/escape.ts'
17
18
 
18
19
  /** on an output only the serve process holds: a restart, or the memory budget, loses it */
19
20
  function EphemeralPill(p: { out: { url: string | null; absPath: string | null } }): ReactNode {
@@ -149,7 +150,7 @@ const Lightbox = observer(function Lightbox(p: { st: WebSt; local: GalleryLocal
149
150
  useEffect(() => {
150
151
  if (target == null) return
151
152
  const onKey = (e: KeyboardEvent): void => {
152
- if (e.key === 'Escape') return p.local.closeLightbox()
153
+ if (onEscape(e, () => p.local.closeLightbox())) return
153
154
  const dir =
154
155
  e.key === 'ArrowDown' || e.key === 'ArrowRight' ? 1 : e.key === 'ArrowUp' || e.key === 'ArrowLeft' ? -1 : 0
155
156
  if (dir === 0) return
@@ -4,6 +4,7 @@
4
4
  import { useEffect, useRef, useState, type ReactNode } from 'react'
5
5
  import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
6
6
  import { searchHistory, timeAgo, type HistoryEntry } from 'src/cli/serve/web/state/history.ts'
7
+ import { onEscape } from 'src/cli/serve/web/state/escape.ts'
7
8
 
8
9
  /** the button that opens it: always there, disabled while nothing was submitted yet. Plain (not
9
10
  * an observer) to stay generic: the observer parent reads the list and passes it down */
@@ -67,9 +68,10 @@ function HistoryPicker<V>(p: {
67
68
  // listener runs first and stops the event there
68
69
  useEffect(() => {
69
70
  const onKey = (e: KeyboardEvent): void => {
70
- if (e.key !== 'Escape') return
71
- e.stopImmediatePropagation()
72
- p.onClose()
71
+ onEscape(e, () => {
72
+ e.stopImmediatePropagation()
73
+ p.onClose()
74
+ })
73
75
  }
74
76
  window.addEventListener('keydown', onKey, true)
75
77
  return () => window.removeEventListener('keydown', onKey, true)
@@ -3,6 +3,7 @@
3
3
  // click, no document listener to leak
4
4
  import { useState, type ReactNode } from 'react'
5
5
  import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
6
+ import { onEscape } from 'src/cli/serve/web/state/escape.ts'
6
7
 
7
8
  export function MenuButton(p: {
8
9
  tip: string
@@ -13,10 +14,7 @@ export function MenuButton(p: {
13
14
  const [open, setOpen] = useState(false)
14
15
  const close = (): void => setOpen(false)
15
16
  return (
16
- <span
17
- className={`preset-box menu-box ${p.className ?? ''}`}
18
- onKeyDown={(e) => (e.key === 'Escape' ? close() : undefined)}
19
- >
17
+ <span className={`preset-box menu-box ${p.className ?? ''}`} onKeyDown={(e) => onEscape(e, close)}>
20
18
  <button
21
19
  type="button"
22
20
  className="menu-btn"
@@ -7,6 +7,7 @@ import { Icon, type IconName } from 'src/cli/serve/web/components/Icon.tsx'
7
7
  import { entryKey, type OmniboxEntry } from 'src/cli/serve/web/state/omnibox.ts'
8
8
  import { isOmniboxKey } from 'src/cli/serve/web/state/shortcuts.ts'
9
9
  import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
10
+ import { onEscape } from 'src/cli/serve/web/state/escape.ts'
10
11
 
11
12
  /** the first media tag picks the icon: what the workflow makes */
12
13
  const ICON_BY_TAG: Record<string, IconName> = { image: 'image', audio: 'audio', video: 'video', text: 'text' }
@@ -94,10 +95,10 @@ export const Omnibox = observer(function Omnibox(p: { st: WebSt }) {
94
95
  value={o.query}
95
96
  onChange={(e) => o.setQuery(e.target.value)}
96
97
  onKeyDown={(e) => {
98
+ if (onEscape(e, () => o.close())) return
97
99
  if (e.key === 'ArrowDown') o.move(1)
98
100
  else if (e.key === 'ArrowUp') o.move(-1)
99
101
  else if (e.key === 'Enter') o.pick()
100
- else if (e.key === 'Escape') o.close()
101
102
  else return
102
103
  e.preventDefault()
103
104
  }}
@@ -16,6 +16,7 @@ import {
16
16
  SHORTCUT_KEYS,
17
17
  type EnhancerShortcut,
18
18
  } from 'src/cli/serve/web/state/shortcuts.ts'
19
+ import { onEscape } from 'src/cli/serve/web/state/escape.ts'
19
20
 
20
21
  const EFFORTS: ReasoningEffort[] = ['off', 'low', 'medium', 'high']
21
22
 
@@ -473,11 +474,11 @@ const Modal = observer(function Modal(p: { e: EnhancerSt; st: WebSt }) {
473
474
  useEffect(() => {
474
475
  const onKey = (ev: KeyboardEvent): void => {
475
476
  // esc closes the editor first, the modal only when nothing is open over the job
476
- if (ev.key === 'Escape') {
477
+ const closed = onEscape(ev, () => {
477
478
  if (e.editing != null) e.setEditing(null)
478
479
  else e.close()
479
- return
480
- }
480
+ })
481
+ if (closed) return
481
482
  const s = enhancerShortcutOf(ev)
482
483
  if (s == null) return
483
484
  ev.preventDefault()
@@ -4,13 +4,14 @@ import { useEffect } from 'react'
4
4
  import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
5
5
  import { shortcutCatalog } from 'src/cli/serve/web/state/shortcutCatalog.ts'
6
6
  import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
7
+ import { onEscape } from 'src/cli/serve/web/state/escape.ts'
7
8
 
8
9
  export const ShortcutsModal = observer(function ShortcutsModal(p: { st: WebSt }) {
9
10
  const open = p.st.showShortcuts
10
11
  useEffect(() => {
11
12
  if (!open) return
12
13
  const onKey = (e: KeyboardEvent): void => {
13
- if (e.key === 'Escape') p.st.setShowShortcuts(false)
14
+ onEscape(e, () => p.st.setShowShortcuts(false))
14
15
  }
15
16
  window.addEventListener('keydown', onKey)
16
17
  return () => window.removeEventListener('keydown', onKey)
@@ -8,6 +8,7 @@ import { SHORTCUT_KEYS, shortcutLabel } from 'src/cli/serve/web/state/shortcuts.
8
8
  import type { PathLabel } from 'src/cli/serve/web/api.ts'
9
9
  import type { FormSt } from 'src/cli/serve/web/state/FormSt.ts'
10
10
  import { LAYOUTS, type WebSt } from 'src/cli/serve/web/state/WebSt.ts'
11
+ import { onEscape } from 'src/cli/serve/web/state/escape.ts'
11
12
 
12
13
  /** a titled block of rows; `actions` sit at the right end of the title */
13
14
  function Section(p: { title: string; actions?: ReactNode; children: ReactNode }): ReactNode {
@@ -67,7 +68,7 @@ const DraftSection = observer(function DraftSection(p: { st: WebSt; form: FormSt
67
68
  onChange={(e) => p.st.setRenaming(e.target.value)}
68
69
  onKeyDown={(e) => {
69
70
  if (e.key === 'Enter') confirm()
70
- if (e.key === 'Escape') p.st.stopRename()
71
+ onEscape(e, () => p.st.stopRename())
71
72
  }}
72
73
  // blur CANCELS, it does not commit: picking another draft blurs this input, and a
73
74
  // rename committed on blur raced that selection, renameDraft bails when the form
@@ -46,6 +46,7 @@ import {
46
46
  type LoraRecord,
47
47
  type LorasInput,
48
48
  } from 'src/vars/lanes.ts'
49
+ import { onEscape } from 'src/cli/serve/web/state/escape.ts'
49
50
 
50
51
  /** one editable list of loras: the whole var, or one of its lanes (ix -1 = no lanes) */
51
52
  type Section = { ix: number; record: LoraRecord; lane: LoraLane | null }
@@ -125,7 +126,7 @@ const LoraLaneBar = observer(function LoraLaneBar(p: {
125
126
  write(patchLane(p.lanes, p.ix, { name: e.currentTarget.value.trim() || lane.name }))
126
127
  setRenaming(false)
127
128
  }
128
- if (e.key === 'Escape') setRenaming(false)
129
+ onEscape(e, () => setRenaming(false))
129
130
  }}
130
131
  onBlur={() => setRenaming(false)}
131
132
  />
@@ -404,7 +405,7 @@ export const LorasControl = observer(function LorasControl(p: {
404
405
  useEffect(() => {
405
406
  if (!open) return
406
407
  const onKey = (e: KeyboardEvent): void => {
407
- if (e.key === 'Escape') local.setOpen(false)
408
+ onEscape(e, () => local.setOpen(false))
408
409
  }
409
410
  window.addEventListener('keydown', onKey)
410
411
  return () => window.removeEventListener('keydown', onKey)
@@ -1095,7 +1096,7 @@ const LoraDetails = observer(function LoraDetails(p: {
1095
1096
  }, [host, name, local])
1096
1097
  useEffect(() => {
1097
1098
  const onKey = (e: KeyboardEvent): void => {
1098
- if (e.key === 'Escape') p.onClose()
1099
+ onEscape(e, () => p.onClose())
1099
1100
  }
1100
1101
  window.addEventListener('keydown', onKey)
1101
1102
  return () => window.removeEventListener('keydown', onKey)
@@ -5,6 +5,7 @@ import { useState } from 'react'
5
5
  import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
6
6
  import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
7
7
  import { activePresetLabel } from 'src/vars/presets.ts'
8
+ import { onEscape } from 'src/cli/serve/web/state/escape.ts'
8
9
 
9
10
  /** one line of a preset's text, enough to tell two of them apart in the menu */
10
11
  function firstLine(text: string): string {
@@ -19,7 +20,7 @@ export const PresetPicker = observer(function PresetPicker(p: { v: VarSt }) {
19
20
  const value = typeof p.v.value === 'string' ? p.v.value : ''
20
21
  const active = activePresetLabel(presets, value)
21
22
  return (
22
- <div className="preset-box" onKeyDown={(e) => (e.key === 'Escape' ? setOpen(false) : undefined)}>
23
+ <div className="preset-box" onKeyDown={(e) => onEscape(e, () => setOpen(false))}>
23
24
  <button
24
25
  type="button"
25
26
  className="preset-btn mini"
@@ -19,6 +19,7 @@ import {
19
19
  toPromptLanes,
20
20
  type PromptLane,
21
21
  } from 'src/vars/lanes.ts'
22
+ import { onEscape } from 'src/cli/serve/web/state/escape.ts'
22
23
 
23
24
  /** the words each active lora adds in front of the prompt. One line per lora, cut with an
24
25
  * ellipsis; clicking opens the full list with a checkbox per word and all / none */
@@ -143,7 +144,7 @@ const LaneBox = observer(function LaneBox(p: {
143
144
  write(patchLane(p.lanes, p.ix, { name: e.currentTarget.value.trim() || lane.name }))
144
145
  setRenaming(false)
145
146
  }
146
- if (e.key === 'Escape') setRenaming(false)
147
+ onEscape(e, () => setRenaming(false))
147
148
  }}
148
149
  onBlur={() => setRenaming(false)}
149
150
  />
@@ -7,6 +7,7 @@ import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
7
7
  import { asSizeForm } from 'src/cli/serve/web/state/payload.ts'
8
8
  import { aspectBox, starredPresets, toggleStar } from 'src/cli/serve/web/state/sizeStars.ts'
9
9
  import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
10
+ import { onEscape } from 'src/cli/serve/web/state/escape.ts'
10
11
 
11
12
  /** a tiny rectangle in the preset's own ratio, centred in a fixed square so a row lines up */
12
13
  function AspectIcon(p: { width: number; height: number; box?: number }): ReactNode {
@@ -66,7 +67,7 @@ export const SizeControl = observer(function SizeControl(p: { v: VarSt; st: WebS
66
67
  ))}
67
68
  </span>
68
69
  ) : null}
69
- <div className="preset-box" onKeyDown={(e) => (e.key === 'Escape' ? setOpen(false) : undefined)}>
70
+ <div className="preset-box" onKeyDown={(e) => onEscape(e, () => setOpen(false))}>
70
71
  <button type="button" className="preset-btn size-pick" aria-expanded={open} onClick={() => setOpen(!open)}>
71
72
  <AspectIcon width={size.width} height={size.height} /> {current?.label ?? 'custom'} ▾
72
73
  </button>
@@ -0,0 +1,16 @@
1
+ // esc is always CLAIMED by the page: a native window (sk gui's WKWebView) beeps on any key the
2
+ // page leaves unhandled, so a popup that closes on esc without preventDefault closes AND beeps.
3
+ // PURE, tests/serve-web-escape.test.ts guards that every esc handler of the panel goes through it
4
+
5
+ /** true when `e` was esc: claimed, then `close` ran */
6
+ export function onEscape(e: { key: string; preventDefault(): void }, close: () => void): boolean {
7
+ if (e.key !== 'Escape') return false
8
+ e.preventDefault()
9
+ close()
10
+ return true
11
+ }
12
+
13
+ /** the lines of a source that test for esc by hand instead of through onEscape */
14
+ export function rawEscapeChecks(source: string): string[] {
15
+ return source.split('\n').filter((line) => /\.key\s*[!=]==?\s*['"]Escape['"]/.test(line))
16
+ }
@@ -122,6 +122,8 @@ export type {
122
122
  SizeValue,
123
123
  SizePreset,
124
124
  MediaVarOpts,
125
+ ModelVarOpts,
126
+ HostSlotSource,
125
127
  ImageVarOpts,
126
128
  AudioVarOpts,
127
129
  VideoVarOpts,
@@ -140,7 +142,14 @@ export type {
140
142
  LoraRecord,
141
143
  } from 'src/vars/lanes.ts'
142
144
  export type { LoraEntry } from 'src/vars/loraEntry.ts'
143
- export { DefinedWorkflow, type DefineWorkflowSpec, type BoundVars, type LoraNameOf } from 'src/vars/DefinedWorkflow.ts'
145
+ export {
146
+ DefinedWorkflow,
147
+ type DefineWorkflowSpec,
148
+ type BoundVars,
149
+ type LoraNameOf,
150
+ type SlotNameOf,
151
+ type SlotValueOf,
152
+ } from 'src/vars/DefinedWorkflow.ts'
144
153
  export {
145
154
  clearLoraKeywordOverride,
146
155
  getLoraKeyword,