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
@@ -24,6 +24,7 @@ import { COMMENT_LINE_RE, NEGATIVE_LINE_RE, parsePromptText } from 'src/vars/pro
24
24
  import { toPresetList, type VarPreset, type VarPresetSpec } from 'src/vars/presets.ts'
25
25
  import { DEFAULT_MEDIA_EXTENSIONS, extensionOf, mediaMime, type MediaKind } from 'src/runner/mediaKinds.ts'
26
26
  import { hashArrayBuffer } from 'src/utils/hashArrayBuffer.ts'
27
+ import { statelessRegex } from 'src/utils/matchesRegex.ts'
27
28
  import type { ComfyWorkflow } from 'src/runner/ComfyWorkflow.ts'
28
29
  import type { NodeOf } from 'src/types/comfy-sdk.ts'
29
30
 
@@ -410,15 +411,53 @@ export class ToggleVar extends ComfyVar<boolean> {
410
411
  /** how many options a choice holds: exactly one (the default), one or none, or any number */
411
412
  export type ChoiceSelect = 'one' | 'zero-or-one' | 'many'
412
413
 
414
+ /** where a host-bound choice reads its options: one loader input of the host's live schema,
415
+ * optionally narrowed (`v.model`) */
416
+ export type HostSlotSource = { slot: string; filter?: RegExp }
417
+
418
+ /** a fixed list, or the host's list for one slot once bindHost ran */
419
+ class ChoiceList<T extends string> {
420
+ private resolved: readonly T[] | null = null
421
+ constructor(readonly source: readonly T[] | HostSlotSource) {}
422
+ get slot(): HostSlotSource | null {
423
+ return isChoiceList(this.source) ? null : this.source
424
+ }
425
+ get choices(): readonly T[] {
426
+ if (isChoiceList(this.source)) return this.source
427
+ if (this.resolved == null)
428
+ throw new Error(
429
+ `v.model('${this.source.slot}') is host-bound — it only works inside defineWorkflow({ vars }) (pass a name list to v.choice otherwise)`,
430
+ )
431
+ return this.resolved
432
+ }
433
+ /** cast: whitelist family 1 (agent/coding.md) — stringValues() returns the runtime values of
434
+ * the SAME object_info enum the generated slot union comes from */
435
+ bind(host: LorasHost): void {
436
+ const src = this.slot
437
+ if (src == null) return
438
+ const all = host.schema.stringValues(src.slot)
439
+ const filter = src.filter == null ? null : statelessRegex(src.filter)
440
+ this.resolved = (filter == null ? all : all.filter((n) => filter.test(n))) as T[]
441
+ }
442
+ }
443
+
413
444
  export class ChoiceVar<T extends string> extends ComfyVar<T> {
414
445
  readonly kind = 'choice' as const
415
446
  readonly select = 'one' as const
416
- constructor(
417
- public readonly choices: readonly T[],
418
- defaultValue: T,
419
- label?: string,
420
- ) {
447
+ private list: ChoiceList<T>
448
+ constructor(choices: readonly T[] | HostSlotSource, defaultValue: T, label?: string) {
421
449
  super(defaultValue, label)
450
+ this.list = new ChoiceList(choices)
451
+ }
452
+ get choices(): readonly T[] {
453
+ return this.list.choices
454
+ }
455
+ /** set for `v.model`: the loader input this choice lists */
456
+ get hostSlot(): HostSlotSource | null {
457
+ return this.list.slot
458
+ }
459
+ bindHost(host: LorasHost): void {
460
+ this.list.bind(host)
422
461
  }
423
462
  next(delta: number = 1): this {
424
463
  const ix = this.choices.indexOf(this.value)
@@ -437,12 +476,19 @@ export class ChoiceVar<T extends string> extends ComfyVar<T> {
437
476
  export class OptionalChoiceVar<T extends string> extends ComfyVar<T | null> {
438
477
  readonly kind = 'choice' as const
439
478
  readonly select = 'zero-or-one' as const
440
- constructor(
441
- public readonly choices: readonly T[],
442
- defaultValue: T | null,
443
- label?: string,
444
- ) {
479
+ private list: ChoiceList<T>
480
+ constructor(choices: readonly T[] | HostSlotSource, defaultValue: T | null, label?: string) {
445
481
  super(defaultValue, label)
482
+ this.list = new ChoiceList(choices)
483
+ }
484
+ get choices(): readonly T[] {
485
+ return this.list.choices
486
+ }
487
+ get hostSlot(): HostSlotSource | null {
488
+ return this.list.slot
489
+ }
490
+ bindHost(host: LorasHost): void {
491
+ this.list.bind(host)
446
492
  }
447
493
  /** pick `c`, or clear it when it is already the one picked */
448
494
  toggle(c: T): this {
@@ -518,7 +564,7 @@ export type AnyChoiceVar<T extends string = string> = ChoiceVar<T> | OptionalCho
518
564
  type ChoiceOpts<S extends ChoiceSelect> = { label?: string; select: S }
519
565
 
520
566
  /** Array.isArray does not narrow a READONLY array out of a union, this does */
521
- function isChoiceList<T extends string>(v: T | null | readonly T[]): v is readonly T[] {
567
+ function isChoiceList<T extends string>(v: T | null | readonly T[] | HostSlotSource): v is readonly T[] {
522
568
  return Array.isArray(v)
523
569
  }
524
570
 
@@ -555,6 +601,25 @@ function choice<const T extends string>(
555
601
  return new ChoiceVar(choices, defaultValue, o.label)
556
602
  }
557
603
 
604
+ export type ModelVarOpts<T extends string> = {
605
+ /** narrows the host's list: `/krea/i` */
606
+ filter?: RegExp
607
+ label?: string
608
+ /** a file name, or null for "the workflow decides" (the build then reads null) */
609
+ default: T | null
610
+ }
611
+
612
+ /** a choice over the host's LIVE file list for one loader input (`'UNETLoader.unet_name'`),
613
+ * resolved at define time and rebound by serve's refresh-schema: a downloaded model is picked
614
+ * in the draft, never written into the workflow file */
615
+ function model<T extends string>(slot: string, opts: ModelVarOpts<T> & { default: T }): ChoiceVar<T>
616
+ function model<T extends string>(slot: string, opts: ModelVarOpts<T> & { default: null }): OptionalChoiceVar<T>
617
+ function model<T extends string>(slot: string, opts: ModelVarOpts<T>): ChoiceVar<T> | OptionalChoiceVar<T> {
618
+ const source: HostSlotSource = { slot, filter: opts.filter }
619
+ if (opts.default == null) return new OptionalChoiceVar<T>(source, null, opts.label)
620
+ return new ChoiceVar<T>(source, opts.default, opts.label)
621
+ }
622
+
558
623
  /** per-lora setting, every spelling documented in src/vars/loraEntry.ts */
559
624
  export type { LoraStrength } from 'src/vars/loraEntry.ts'
560
625
 
@@ -573,7 +638,10 @@ export function activeLoras<T extends string>(loras: LorasInput<T>): ActiveLora<
573
638
  }
574
639
 
575
640
  /** what LorasVar.bindHost needs — structural, so ComfyVars never imports ComfyHost */
576
- export type LorasHost = { data?: { id?: string }; schema: { getLoras(filter?: RegExp): string[] } }
641
+ export type LorasHost = {
642
+ data?: { id?: string }
643
+ schema: { getLoras(filter?: RegExp): string[]; stringValues(slot: string): string[] }
644
+ }
577
645
 
578
646
  /**
579
647
  * multi-select lora stack over a DYNAMIC options list — a RegExp resolves
@@ -975,7 +1043,7 @@ export class VideoVar extends MediaVar {
975
1043
  }
976
1044
  }
977
1045
 
978
- /** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.loras / v.size / v.image / v.audio / v.video */
1046
+ /** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.model / v.loras / v.size / v.image / v.audio / v.video */
979
1047
  export const v = {
980
1048
  // the old `v.text(x, 'label')` form still works: a bare string IS the label
981
1049
  text: (defaultValue: string, opts: TextVarOpts | string = {}): TextVar =>
@@ -1008,6 +1076,8 @@ export const v = {
1008
1076
  opts: { presets?: SizePreset[]; starred?: readonly string[]; label?: string; image?: ImageVar } = {},
1009
1077
  ): SizeVar =>
1010
1078
  new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
1079
+ /** host-bound: only inside defineWorkflow({ vars: (v) => … }), typed per slot there */
1080
+ model,
1011
1081
  image: (defaultValue: string, opts: MediaVarOpts = {}): ImageVar => new ImageVar(defaultValue, opts),
1012
1082
  audio: (defaultValue: string, opts: MediaVarOpts = {}): AudioVar => new AudioVar(defaultValue, opts),
1013
1083
  video: (defaultValue: string, opts: MediaVarOpts = {}): VideoVar => new VideoVar(defaultValue, opts),
@@ -3,7 +3,17 @@ import type { ComfyExecution } from 'src/runner/ComfyExecution.ts'
3
3
  import type { ComfyWorkflow, RunSettings } from 'src/runner/ComfyWorkflow.ts'
4
4
  import type { SdkForHost } from 'src/types/comfy-sdk.ts'
5
5
  import type { LorasInput } from 'src/vars/lanes.ts'
6
- import { type AnyVar, type LorasVar, v, type VarsSpec, type VarValues, varValues } from 'src/vars/ComfyVars.ts'
6
+ import {
7
+ type AnyVar,
8
+ type ChoiceVar,
9
+ type LorasVar,
10
+ type ModelVarOpts,
11
+ type OptionalChoiceVar,
12
+ v,
13
+ type VarsSpec,
14
+ type VarValues,
15
+ varValues,
16
+ } from 'src/vars/ComfyVars.ts'
7
17
 
8
18
  /** the host's generated lora-name union (plain string when no sdk is generated) */
9
19
  export type LoraNameOf<ID extends string> = 'E_LoraName' extends keyof SdkForHost<ID>['Union']
@@ -14,11 +24,34 @@ export type LoraNameOf<ID extends string> = 'E_LoraName' extends keyof SdkForHos
14
24
  * the `v` handed to a vars LAMBDA: the global factory, host-typed —
15
25
  * `v.loras(regex)` yields the host's lora-name union (resolved via bindHost)
16
26
  */
17
- export type BoundVars<ID extends string> = Omit<typeof v, 'loras'> & {
27
+ export type BoundVars<ID extends string> = Omit<typeof v, 'loras' | 'model'> & {
18
28
  loras(options: RegExp, initial?: LorasInput<LoraNameOf<ID>>, label?: string): LorasVar<LoraNameOf<ID>>
19
29
  loras<T extends string>(options: readonly T[], initial?: LorasInput<T>, label?: string): LorasVar<T>
30
+ /** the host's file list for one loader input: the slot autocompletes, the value is its union */
31
+ model: ModelFactory<SdkForHost<ID>['Slots']>
20
32
  }
21
33
 
34
+ /** `v.model` typed by a host's slot table S (`Slots`): its own interface, so the host id's
35
+ * variance stays measurable (inlined into BoundVars, ComfyHost<ID> stopped being a ComfyHost<string>) */
36
+ export interface ModelFactory<S> {
37
+ <K extends keyof S & string>(
38
+ slot: K,
39
+ opts: ModelVarOpts<S[K] & string> & { default: S[K] & string },
40
+ ): ChoiceVar<S[K] & string>
41
+ <K extends keyof S & string>(
42
+ slot: K,
43
+ opts: ModelVarOpts<S[K] & string> & { default: null },
44
+ ): OptionalChoiceVar<S[K] & string>
45
+ }
46
+
47
+ /** every `Node.input` slot of the host's generated sdk (any string without one) */
48
+ export type SlotNameOf<ID extends string> = keyof SdkForHost<ID>['Slots'] & string
49
+
50
+ /** the value union of one slot, strings only (a loader file list) */
51
+ export type SlotValueOf<ID extends string, K extends string> = K extends keyof SdkForHost<ID>['Slots']
52
+ ? SdkForHost<ID>['Slots'][K] & string
53
+ : string
54
+
22
55
  export type DefineWorkflowSpec<ID extends string, V extends VarsSpec> = {
23
56
  /** short id; also names the workflow instances */
24
57
  id?: string