comfy-ts 0.3.0 → 1.0.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 (73) hide show
  1. package/README.md +349 -255
  2. package/dist/DefinedWorkflow-O3ynII3Y.js +598 -0
  3. package/dist/DefinedWorkflow-O3ynII3Y.js.map +1 -0
  4. package/dist/cli.js +3969 -128
  5. package/dist/cli.js.map +1 -1
  6. package/dist/index.cjs +1208 -170
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.cts +449 -115
  9. package/dist/index.d.ts +449 -115
  10. package/dist/index.js +1200 -171
  11. package/dist/index.js.map +1 -1
  12. package/dist/{run-tui-Io8Xea0L.js → run-tui-BFhba_oG.js} +744 -665
  13. package/dist/run-tui-BFhba_oG.js.map +1 -0
  14. package/examples/01-txt2img.cflow.ts +50 -0
  15. package/examples/02-img2img-upload.cflow.ts +66 -0
  16. package/examples/03-export-workflow-json.cflow.ts +56 -0
  17. package/examples/04-krea2-turbo-t2i.cflow.ts +125 -0
  18. package/examples/05-comfy-cloud.cflow.ts +67 -0
  19. package/examples/comfy-cloud/sdk.d.ts +122674 -0
  20. package/guide-for-agents.md +166 -0
  21. package/package.json +7 -3
  22. package/src/cli/comfy-ts-cli.ts +19 -2
  23. package/src/cli/gen.ts +21 -12
  24. package/src/cli/tui/components/Header.tsx +5 -0
  25. package/src/cli/tui/components/LogsPanel.tsx +23 -0
  26. package/src/cli/tui/components/PreviewPanel.tsx +52 -7
  27. package/src/cli/tui/components/StatusBar.tsx +10 -4
  28. package/src/cli/tui/components/TreePanel.tsx +15 -2
  29. package/src/cli/tui/components/TuiApp.tsx +26 -3
  30. package/src/cli/tui/discoverWorkflows.ts +79 -0
  31. package/src/cli/tui/protocolImagePainter.ts +54 -18
  32. package/src/cli/tui/run-tui.tsx +55 -24
  33. package/src/cli/tui/state/ExecSt.ts +4 -1
  34. package/src/cli/tui/state/HostSt.ts +123 -1
  35. package/src/cli/tui/state/LogsSt.ts +107 -0
  36. package/src/cli/tui/state/PreviewSt.ts +173 -23
  37. package/src/cli/tui/state/SettingsSt.ts +48 -21
  38. package/src/cli/tui/state/TreeSt.ts +30 -6
  39. package/src/cli/tui/state/TuiSt.ts +27 -3
  40. package/src/cli/tui/state/WorkflowsSt.ts +16 -1
  41. package/src/host/ComfyHost.ts +241 -71
  42. package/src/host/ComfyManager.ts +10 -9
  43. package/src/host/ComfyUploader.ts +1 -2
  44. package/src/host/ResilientWebsocket.ts +3 -1
  45. package/src/host/hostUrl.ts +59 -0
  46. package/src/host/loraManagerApi.ts +5 -4
  47. package/src/index.ts +20 -1
  48. package/src/litegraph/CanonicalWorkflow.ts +77 -0
  49. package/src/litegraph/LiteGraphGroup.ts +9 -7
  50. package/src/litegraph/LiteGraphJSON.ts +34 -13
  51. package/src/litegraph/LiteGraphLink.ts +32 -2
  52. package/src/litegraph/LiteGraphNode.ts +18 -33
  53. package/src/litegraph/LiteGraphNodeInput.ts +10 -8
  54. package/src/litegraph/LiteGraphNodeOutput.ts +2 -3
  55. package/src/litegraph/LiteGraphSubgraphDef.ts +74 -0
  56. package/src/litegraph/convertFlowToLiteGraphJSON.ts +4 -4
  57. package/src/litegraph/expandSubgraphs.ts +352 -0
  58. package/src/litegraph/normalizeWorkflow.ts +141 -0
  59. package/src/runner/ComfyExecution.ts +4 -5
  60. package/src/runner/ComfyWorkflow.ts +2 -2
  61. package/src/runner/ComfyWsApi.ts +12 -1
  62. package/src/runner/wsBinaryFrame.ts +48 -0
  63. package/src/sdk-generator/Primitives.ts +6 -24
  64. package/src/sdk-generator/comfy-api-json.ts +3 -1
  65. package/src/sdk-generator/inputWidgetKind.ts +179 -0
  66. package/src/sdk-generator/litegraphToApiRequestPayload.ts +372 -96
  67. package/src/ssh-host-manager/ssh-manager.ts +0 -15
  68. package/src/state.ts +13 -2
  69. package/src/utils/ansi.ts +7 -0
  70. package/src/utils/mojibake.ts +60 -0
  71. package/dist/log-CdfgILde.js +0 -10
  72. package/dist/log-CdfgILde.js.map +0 -1
  73. package/dist/run-tui-Io8Xea0L.js.map +0 -1
@@ -0,0 +1,77 @@
1
+ import type { LiteGraphLinkID } from 'src/litegraph/LiteGraphLinkID.ts'
2
+
3
+ /**
4
+ * the ONE strict internal shape for imported workflows. ZERO optional fields:
5
+ * semantic absence is `null`, serializer noise gets a default at normalization.
6
+ * Every consumer of an imported workflow JSON (converter, sweeps, TUI) reads
7
+ * this type only — optionality never crosses `normalizeWorkflow`. A new
8
+ * consumer needing a wire field ADDS it here (with a default), it does not
9
+ * reach around the pipeline to the raw document.
10
+ */
11
+ export type CanonicalWorkflow = {
12
+ /** subgraph instances with a definition are expanded away by normalization (expandSubgraphs.ts) */
13
+ nodes: CanonicalNode[]
14
+ /** object form only, both wire eras unified */
15
+ links: CanonicalLink[]
16
+ /** [] when the document had none */
17
+ groups: CanonicalGroup[]
18
+ }
19
+
20
+ export type CanonicalLink = {
21
+ id: LiteGraphLinkID
22
+ originId: number
23
+ originSlot: number
24
+ targetId: number
25
+ targetSlot: number
26
+ type: string
27
+ }
28
+
29
+ /**
30
+ * raw 0/1/3 (always / on-event / on-trigger) → 'normal'; 2 → 'muted'; 4 → 'bypassed'.
31
+ * Literal union on purpose: converter switches are total, no magic ints downstream.
32
+ */
33
+ export type NodeMode = 'normal' | 'muted' | 'bypassed'
34
+
35
+ export type CanonicalNode = {
36
+ id: number
37
+ type: string
38
+ title: string | null
39
+ mode: NodeMode
40
+ isVirtualNode: boolean // false when absent
41
+ inputs: CanonicalInput[] // [] when absent
42
+ outputs: CanonicalOutput[] // [] when absent
43
+ widgets: CanonicalWidgetValues
44
+ pos: [number, number] // real tuples (wire has {0,1} objects AND arrays)
45
+ size: [number, number]
46
+ properties: Record<string, unknown> // raw passthrough (proxyWidgets, cnr_id/ver)
47
+ }
48
+
49
+ export type CanonicalInput = {
50
+ name: string
51
+ type: string
52
+ link: LiteGraphLinkID | null // null = unconnected (incl. omitted key)
53
+ widgetName: string | null // widget.name when widget-backed
54
+ }
55
+
56
+ export type CanonicalOutput = {
57
+ name: string
58
+ type: string
59
+ links: LiteGraphLinkID[] // [] for null/absent
60
+ }
61
+
62
+ /**
63
+ * ONE shape for all three widget-value realities: array form (positional),
64
+ * object form (named, e.g. VHS_*), and subgraph promotion overrides (named).
65
+ * Both fields ALWAYS present.
66
+ */
67
+ export type CanonicalWidgetValues = {
68
+ positional: unknown[]
69
+ named: Record<string, unknown>
70
+ }
71
+
72
+ export type CanonicalGroup = {
73
+ title: string
74
+ bounding: [number, number, number, number]
75
+ color: string // default '#3f789e' (litegraph default)
76
+ fontSize: number // default 24
77
+ }
@@ -3,20 +3,22 @@ import type { EmptyRecord, IsEqual } from 'src/types/index.ts'
3
3
 
4
4
  // prettier-ignore
5
5
  export type LiteGraphGroup = {
6
- title: string // 'Create Mask'
6
+ id?: number // 1 (newer serializers only)
7
+ title: string // 'Create Mask'
7
8
  bounding: [number, number, number, number] // [1078, -579, 1589, 614]
8
- color: string // '#3f789e'
9
- font_size: number // 24
10
- flags: EmptyRecord // {}
9
+ color?: string // '#3f789e' (omitted = litegraph default)
10
+ font_size?: number // 24 (omitted = litegraph default)
11
+ flags?: EmptyRecord // {}
11
12
  }
12
13
 
13
14
  export const LiteGraphGroup_ark = type({
15
+ 'id?': 'number',
14
16
  title: 'string',
15
17
  bounding: type(['number', 'number', 'number', 'number']),
16
- color: 'string',
17
- font_size: 'number',
18
+ 'color?': 'string',
19
+ 'font_size?': 'number',
18
20
  // EmptyRecord: an object we don't read any key from
19
- flags: type.Record('string', 'unknown').as<EmptyRecord>(),
21
+ 'flags?': type.Record('string', 'unknown').as<EmptyRecord>(),
20
22
  })
21
23
 
22
24
  true satisfies IsEqual<LiteGraphGroup, typeof LiteGraphGroup_ark.infer>
@@ -3,35 +3,52 @@ import type { EmptyRecord, IsEqual } from 'src/types/index.ts'
3
3
  import { type LiteGraphGroup, LiteGraphGroup_ark } from 'src/litegraph/LiteGraphGroup.ts'
4
4
  import { type LiteGraphLink, LiteGraphLink_ark } from 'src/litegraph/LiteGraphLink.ts'
5
5
  import { type LiteGraphNode, LiteGraphNode_ark } from 'src/litegraph/LiteGraphNode.ts'
6
+ import { type LiteGraphSubgraphDef, LiteGraphSubgraphDef_ark } from 'src/litegraph/LiteGraphSubgraphDef.ts'
6
7
 
7
8
  /** comfy workflows are simply LiteGraphs workflows */
8
9
  export type ComfyWorkflowJSON = LiteGraphJSON
9
10
 
10
- /** litegraph workflow are stored... in a very unpractical format */
11
+ /**
12
+ * litegraph workflow root, TOLERANT: models what upstream actually serializes
13
+ * across eras — v0.4 (tuple links, last_*_id) and v1 (object links, `state`),
14
+ * including hybrid files (v0.4 root + v1-shaped subgraph definitions).
15
+ * Downstream code never reads this shape: `normalizeWorkflow` turns it into
16
+ * the strict `CanonicalWorkflow`.
17
+ */
11
18
  export type LiteGraphJSON = {
12
- last_node_id: number
13
- last_link_id: number
19
+ id?: string // uuid (newer serializers)
20
+ revision?: number
21
+ last_node_id?: number // v0.4 (recomputable, absent in v1)
22
+ last_link_id?: number // v0.4
23
+ state?: Record<string, unknown> // v1: {lastNodeId, lastLinkId, …}
14
24
  nodes: LiteGraphNode[]
15
25
  links: LiteGraphLink[]
16
- groups: LiteGraphGroup[]
17
- config: EmptyRecord
18
- extra: {
26
+ groups?: LiteGraphGroup[]
27
+ config?: EmptyRecord
28
+ extra?: {
19
29
  ds?: {
20
30
  scale: number
21
31
  offset: { 0: number; 1: number }
22
32
  }
23
33
  }
24
- version: 0.4
34
+ models?: unknown[] // model download manifest — never read
35
+ definitions?: { subgraphs: LiteGraphSubgraphDef[] }
36
+ reroutes?: unknown[] // v1 cosmetic link routing — dropped at normalization
37
+ floatingLinks?: unknown[] // v1 cosmetic — dropped at normalization
38
+ version: 0.4 | 1
25
39
  }
26
40
 
27
41
  export const LiteGraphJSON_ark = type({
28
- last_node_id: 'number',
29
- last_link_id: 'number',
42
+ 'id?': 'string',
43
+ 'revision?': 'number',
44
+ 'last_node_id?': 'number',
45
+ 'last_link_id?': 'number',
46
+ 'state?': type.Record('string', 'unknown'),
30
47
  nodes: LiteGraphNode_ark.array(),
31
48
  links: LiteGraphLink_ark.array(),
32
- groups: LiteGraphGroup_ark.array(),
33
- config: type.Record('never', 'never'),
34
- extra: {
49
+ 'groups?': LiteGraphGroup_ark.array(),
50
+ 'config?': type.Record('never', 'never'),
51
+ 'extra?': {
35
52
  'ds?': {
36
53
  scale: 'number',
37
54
  offset: {
@@ -40,7 +57,11 @@ export const LiteGraphJSON_ark = type({
40
57
  },
41
58
  },
42
59
  },
43
- version: '0.4',
60
+ 'models?': 'unknown[]',
61
+ 'definitions?': { subgraphs: LiteGraphSubgraphDef_ark.array() },
62
+ 'reroutes?': 'unknown[]',
63
+ 'floatingLinks?': 'unknown[]',
64
+ version: '0.4 | 1',
44
65
  })
45
66
 
46
67
  true satisfies IsEqual<LiteGraphJSON, typeof LiteGraphJSON_ark.infer>
@@ -2,7 +2,8 @@ import { type } from 'arktype'
2
2
  import type { IsEqual } from 'src/types/index.ts'
3
3
  import { type LiteGraphLinkID, LiteGraphLinkID_ } from 'src/litegraph/LiteGraphLinkID.ts'
4
4
 
5
- export type LiteGraphLink = [
5
+ /** v0.4 serialization: links are 6-tuples (our EXPORT path emits this form) */
6
+ export type LiteGraphLinkTuple = [
6
7
  linkId: LiteGraphLinkID, // 9, - linkId
7
8
  fromNodeId: number, // 8, - fromNodeId
8
9
  fromNodeOutputIx: number, // 0, - fromNodeOutputIx
@@ -11,7 +12,7 @@ export type LiteGraphLink = [
11
12
  linkType: string, // "IMAGE" - type
12
13
  ]
13
14
 
14
- export const LiteGraphLink_ark = type([
15
+ export const LiteGraphLinkTuple_ark = type([
15
16
  LiteGraphLinkID_, // 9, - linkId
16
17
  'number', // 8, - fromNodeId
17
18
  'number', // 0, - fromNodeOutputIx
@@ -20,4 +21,33 @@ export const LiteGraphLink_ark = type([
20
21
  'string', // "IMAGE" - linkType
21
22
  ])
22
23
 
24
+ true satisfies IsEqual<typeof LiteGraphLinkTuple_ark.infer, LiteGraphLinkTuple>
25
+
26
+ /** v1 serialization: links are objects (subgraph definition interiors use this) */
27
+ export type LiteGraphLinkObject = {
28
+ id: LiteGraphLinkID
29
+ origin_id: number // -10 = the subgraph's inputNode boundary
30
+ origin_slot: number
31
+ target_id: number // -20 = the subgraph's outputNode boundary
32
+ target_slot: number
33
+ type: string
34
+ parentId?: number // reroute chain parent (cosmetic)
35
+ }
36
+
37
+ export const LiteGraphLinkObject_ark = type({
38
+ id: LiteGraphLinkID_,
39
+ origin_id: 'number',
40
+ origin_slot: 'number',
41
+ target_id: 'number',
42
+ target_slot: 'number',
43
+ type: 'string',
44
+ 'parentId?': 'number',
45
+ })
46
+
47
+ true satisfies IsEqual<typeof LiteGraphLinkObject_ark.infer, LiteGraphLinkObject>
48
+
49
+ export type LiteGraphLink = LiteGraphLinkTuple | LiteGraphLinkObject
50
+
51
+ export const LiteGraphLink_ark = LiteGraphLinkTuple_ark.or(LiteGraphLinkObject_ark)
52
+
23
53
  true satisfies IsEqual<typeof LiteGraphLink_ark.infer, LiteGraphLink>
@@ -1,69 +1,54 @@
1
1
  import { type } from 'arktype'
2
- import type { EmptyRecord, IsEqual } from 'src/types/index.ts'
2
+ import type { IsEqual } from 'src/types/index.ts'
3
3
  import { type LiteGraphNodeInput, LiteGraphNodeInput_ark } from 'src/litegraph/LiteGraphNodeInput.ts'
4
4
  import { type LiteGraphNodeOutput, LiteGraphNodeOutput_ark } from 'src/litegraph/LiteGraphNodeOutput.ts'
5
5
 
6
6
  // prettier-ignore
7
7
  export type LiteGraphNode = {
8
8
  id: number // 5
9
- type: string // 'CLIPTextEncode'
9
+ type: string // 'CLIPTextEncode', or a definitions.subgraphs uuid (instance)
10
10
 
11
11
  // cosmetics
12
12
  title?: string // "Inpaint (Positive)",
13
13
  color?: string // "#222", or "#3f789e"
14
- bgColor?: string // "#3f789e"
15
- pos: { '0': number; '1': number } // was: [number, number]
14
+ bgcolor?: string // "#3f789e" (lowercase, like upstream)
15
+ pos: { '0': number; '1': number } // serialized as [number, number] OR {0,1}
16
16
  size: { '0': number; '1': number }
17
- flags?: EmptyRecord
17
+ flags?: Record<string, unknown> // collapsed?, pinned?, … — never read
18
18
  order?: number
19
19
  /**
20
- * 0 = normal
21
- * 1 = ?????
22
- * 2 = muted
23
- * */
20
+ * 0 = always (normal), 1 = on-event, 2 = muted (never),
21
+ * 3 = on-trigger, 4 = bypassed
22
+ */
24
23
  mode?: number
25
24
  inputs?: LiteGraphNodeInput[]
26
- outputs: LiteGraphNodeOutput[]
25
+ outputs?: LiteGraphNodeOutput[]
27
26
 
28
27
  isVirtualNode?: boolean // frontend only
29
- properties?: {
30
- /**
31
- * S&R stands for search and replace
32
- * // 💬 2024-11-13 rvion: do we want to populate taht someday soon
33
- */
34
- 'Node name for S&R'?: string
35
-
36
- /** when set to true, it.... */
37
- showOutputText?: boolean
38
-
39
- /** no clue what it does */
40
- horizontal?: boolean
41
- }
42
- widgets_values?: unknown[]
28
+ /** open record: proxyWidgets (subgraph widget promotion), cnr_id/ver (pack provenance), … */
29
+ properties?: Record<string, unknown>
30
+ /** array form (positional) OR object form (named, e.g. VHS_VideoCombine) */
31
+ widgets_values?: unknown[] | Record<string, unknown>
43
32
  }
44
33
 
45
34
  export const LiteGraphNode_ark = type({
46
35
  id: 'number',
47
36
  type: 'string',
48
37
 
49
- // cospetics
38
+ // cosmetics
50
39
  'title?': 'string',
51
40
  'color?': 'string',
52
41
  'bgcolor?': 'string',
53
42
  pos: { '0': 'number', '1': 'number' },
54
43
  size: { '0': 'number', '1': 'number' },
55
- 'flags?': { '[never]': 'never' },
44
+ 'flags?': type.Record('string', 'unknown'),
56
45
  'order?': 'number',
57
46
  'mode?': 'number',
58
47
  'inputs?': LiteGraphNodeInput_ark.array(),
59
- outputs: LiteGraphNodeOutput_ark.array(),
48
+ 'outputs?': LiteGraphNodeOutput_ark.array(),
60
49
  'isVirtualNode?': 'boolean',
61
- 'properties?': {
62
- 'Node name for S&R?': 'string',
63
- 'showOutputText?': 'boolean',
64
- 'horizontal?': 'boolean',
65
- },
66
- 'widgets_values?': `unknown[]`,
50
+ 'properties?': type.Record('string', 'unknown'),
51
+ 'widgets_values?': type('unknown[]').or(type.Record('string', 'unknown')),
67
52
  })
68
53
 
69
54
  true satisfies IsEqual<LiteGraphNode, typeof LiteGraphNode_ark.infer>
@@ -3,24 +3,26 @@ import type { IsEqual } from 'src/types/index.ts'
3
3
  import { type LiteGraphLinkID, LiteGraphLinkID_ } from 'src/litegraph/LiteGraphLinkID.ts'
4
4
 
5
5
  export type LiteGraphNodeInput = {
6
- name: string // | 'clip'
7
- type: string // | 'CLIP'
8
- link: LiteGraphLinkID | null // | 5
9
- shape?: number // | '2D'
6
+ name: string // | 'clip'
7
+ type: string // | 'CLIP'
8
+ link?: LiteGraphLinkID | null // | 5 (widget-backed inputs omit the key)
9
+ shape?: number // | 7
10
+ label?: string // | 'select'
10
11
  widget?: {
11
- name: string // | 'select'
12
- config: unknown // | 🔴
12
+ name: string // | 'select'
13
+ config?: unknown // | 2022-era serializer only, gone since
13
14
  }
14
15
  }
15
16
 
16
17
  export const LiteGraphNodeInput_ark = type({
17
18
  name: 'string',
18
19
  type: 'string',
19
- link: LiteGraphLinkID_.or(type.null),
20
+ 'link?': LiteGraphLinkID_.or(type.null),
20
21
  'shape?': 'number',
22
+ 'label?': 'string',
21
23
  'widget?': type({
22
24
  name: 'string',
23
- config: type.unknown,
25
+ 'config?': 'unknown',
24
26
  }),
25
27
  })
26
28
 
@@ -4,10 +4,9 @@ import { type LiteGraphLinkID, LiteGraphLinkID_ } from 'src/litegraph/LiteGraphL
4
4
  import { type LiteGraphSlotIndex, LiteGraphSlotIndex_ } from 'src/litegraph/LiteGraphSlotIndex.ts'
5
5
 
6
6
  export type LiteGraphNodeOutput = {
7
- // ❌9 name: string // 'CONDITIONING'
8
7
  name: string
9
8
  type: string // 'CONDITIONING'
10
- links: LiteGraphLinkID[] | null
9
+ links?: LiteGraphLinkID[] | null // unconnected outputs may omit the key
11
10
  shape?: number // '2D'
12
11
  slot_index?: LiteGraphSlotIndex
13
12
  }
@@ -15,7 +14,7 @@ export type LiteGraphNodeOutput = {
15
14
  export const LiteGraphNodeOutput_ark = type({
16
15
  name: 'string',
17
16
  type: 'string',
18
- links: LiteGraphLinkID_.array().or(type.null),
17
+ 'links?': LiteGraphLinkID_.array().or(type.null),
19
18
  'shape?': 'number',
20
19
  'slot_index?': LiteGraphSlotIndex_,
21
20
  })
@@ -0,0 +1,74 @@
1
+ import { type } from 'arktype'
2
+ import type { EmptyRecord, IsEqual } from 'src/types/index.ts'
3
+ import { type LiteGraphGroup, LiteGraphGroup_ark } from 'src/litegraph/LiteGraphGroup.ts'
4
+ import { type LiteGraphLinkID, LiteGraphLinkID_ } from 'src/litegraph/LiteGraphLinkID.ts'
5
+ import { type LiteGraphLinkObject, LiteGraphLinkObject_ark } from 'src/litegraph/LiteGraphLink.ts'
6
+ import { type LiteGraphNode, LiteGraphNode_ark } from 'src/litegraph/LiteGraphNode.ts'
7
+
8
+ /** one exposed input/output slot of a subgraph definition */
9
+ export type LiteGraphSubgraphIO = {
10
+ id: string // uuid
11
+ name: string // 'image'
12
+ type: string // 'IMAGE'
13
+ linkIds?: LiteGraphLinkID[]
14
+ label?: string
15
+ localized_name?: string
16
+ pos?: { '0': number; '1': number }
17
+ shape?: number
18
+ }
19
+
20
+ export const LiteGraphSubgraphIO_ark = type({
21
+ id: 'string',
22
+ name: 'string',
23
+ type: 'string',
24
+ 'linkIds?': LiteGraphLinkID_.array(),
25
+ 'label?': 'string',
26
+ 'localized_name?': 'string',
27
+ 'pos?': { '0': 'number', '1': 'number' },
28
+ 'shape?': 'number',
29
+ })
30
+
31
+ true satisfies IsEqual<LiteGraphSubgraphIO, typeof LiteGraphSubgraphIO_ark.infer>
32
+
33
+ /**
34
+ * a subgraph definition body (definitions.subgraphs[] entry). Corpus fact:
35
+ * every one is a v1-shaped interior (object links, `state`) even when the
36
+ * root document is v0.4 — instances reference it via node.type = this uuid.
37
+ */
38
+ export type LiteGraphSubgraphDef = {
39
+ id: string // uuid, referenced by instance nodes' `type`
40
+ name: string
41
+ version: number // 1 in the whole corpus
42
+ state?: Record<string, unknown> // {lastNodeId, lastLinkId, …} — recomputable
43
+ revision?: number
44
+ config?: EmptyRecord
45
+ extra?: unknown
46
+ nodes: LiteGraphNode[]
47
+ links: LiteGraphLinkObject[]
48
+ groups?: LiteGraphGroup[]
49
+ inputNode: { id: number; bounding: number[] } // id is -10 in boundary links
50
+ outputNode: { id: number; bounding: number[] } // id is -20 in boundary links
51
+ inputs: LiteGraphSubgraphIO[]
52
+ outputs: LiteGraphSubgraphIO[]
53
+ widgets: unknown[] // empty in the whole corpus
54
+ }
55
+
56
+ export const LiteGraphSubgraphDef_ark = type({
57
+ id: 'string',
58
+ name: 'string',
59
+ version: 'number',
60
+ 'state?': type.Record('string', 'unknown'),
61
+ 'revision?': 'number',
62
+ 'config?': type.Record('string', 'unknown').as<EmptyRecord>(),
63
+ 'extra?': 'unknown',
64
+ nodes: LiteGraphNode_ark.array(),
65
+ links: LiteGraphLinkObject_ark.array(),
66
+ 'groups?': LiteGraphGroup_ark.array(),
67
+ inputNode: { id: 'number', bounding: 'number[]' },
68
+ outputNode: { id: 'number', bounding: 'number[]' },
69
+ inputs: LiteGraphSubgraphIO_ark.array(),
70
+ outputs: LiteGraphSubgraphIO_ark.array(),
71
+ widgets: 'unknown[]',
72
+ })
73
+
74
+ true satisfies IsEqual<LiteGraphSubgraphDef, typeof LiteGraphSubgraphDef_ark.infer>
@@ -1,9 +1,9 @@
1
1
  import type { ComfyNode } from 'src/graph/ComfyNode.ts'
2
2
  import type { ComfyWorkflow } from 'src/runner/ComfyWorkflow.ts'
3
3
  import { bang } from 'src/utils/bang.ts'
4
- import { howManyWidgetValuesForThisSchemaType } from 'src/sdk-generator/Primitives.ts'
4
+ import { howManyWidgetValuesForThisSchemaType } from 'src/sdk-generator/inputWidgetKind.ts'
5
5
  import type { LiteGraphJSON } from 'src/litegraph/LiteGraphJSON.ts'
6
- import type { LiteGraphLink } from 'src/litegraph/LiteGraphLink.ts'
6
+ import type { LiteGraphLinkTuple } from 'src/litegraph/LiteGraphLink.ts'
7
7
  import { asLiteGraphLinkID, type LiteGraphLinkID } from 'src/litegraph/LiteGraphLinkID.ts'
8
8
  import type { LiteGraphNode } from 'src/litegraph/LiteGraphNode.ts'
9
9
  import type { LiteGraphNodeInput } from 'src/litegraph/LiteGraphNodeInput.ts'
@@ -21,7 +21,7 @@ export const convertFlowToLiteGraphJSON = (graph: ComfyWorkflow): LiteGraphJSON
21
21
  const n = xx.liteGraphNode
22
22
  n.pos[0] = bang(xx.comfyNode.x)
23
23
  n.pos[1] = bang(xx.comfyNode.y)
24
- for (const o of n.outputs) {
24
+ for (const o of n.outputs ?? []) {
25
25
  o.links = ctx.links.filter((l) => l[3] === n.id && l[4] === o.slot_index).map((l) => l[0])
26
26
  }
27
27
  }
@@ -99,7 +99,7 @@ const _isLink = (v: unknown): v is [string, number] => {
99
99
  export class LiteGraphCtx {
100
100
  constructor(public graph: ComfyWorkflow) {}
101
101
  nextLinkId: number = 0
102
- links: LiteGraphLink[] = []
102
+ links: LiteGraphLinkTuple[] = []
103
103
  allocateLink = (
104
104
  fromNodeId: number,
105
105
  fromNodeOutputIx: number,