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
package/dist/index.d.cts CHANGED
@@ -5262,6 +5262,10 @@ declare const types$1: import("arktype").Module<{
5262
5262
  sid?: string | undefined;
5263
5263
  };
5264
5264
  };
5265
+ LogEntry: {
5266
+ t: string;
5267
+ m: string;
5268
+ };
5265
5269
  NodeProgress: {
5266
5270
  value: number;
5267
5271
  max: number;
@@ -5422,6 +5426,15 @@ declare const types$1: import("arktype").Module<{
5422
5426
  sid?: string | undefined;
5423
5427
  };
5424
5428
  };
5429
+ } | {
5430
+ type: "logs";
5431
+ data: {
5432
+ entries: {
5433
+ t: string;
5434
+ m: string;
5435
+ }[];
5436
+ size?: unknown;
5437
+ };
5425
5438
  };
5426
5439
  WsMsgExecuted: {
5427
5440
  type: "executed";
@@ -5485,6 +5498,16 @@ declare const types$1: import("arktype").Module<{
5485
5498
  prompt_id: PromptID;
5486
5499
  timestamp: number;
5487
5500
  };
5501
+ WsMsgLogs: {
5502
+ type: "logs";
5503
+ data: {
5504
+ entries: {
5505
+ t: string;
5506
+ m: string;
5507
+ }[];
5508
+ size?: unknown;
5509
+ };
5510
+ };
5488
5511
  WsMsgProgress: {
5489
5512
  type: "progress";
5490
5513
  data: {
@@ -5547,6 +5570,13 @@ declare const types$1: import("arktype").Module<{
5547
5570
  _WsMsgExecutionStartData: {
5548
5571
  prompt_id: PromptID;
5549
5572
  };
5573
+ _WsMsgLogsData: {
5574
+ entries: {
5575
+ t: string;
5576
+ m: string;
5577
+ }[];
5578
+ size?: unknown;
5579
+ };
5550
5580
  _WsMsgProgressStateData: {
5551
5581
  prompt_id: PromptID;
5552
5582
  nodes: Record<string, unknown>;
@@ -5560,6 +5590,7 @@ type WsMsgExecutionCached = typeof types$1.WsMsgExecutionCached.infer;
5560
5590
  type WsMsgExecuting = typeof types$1.WsMsgExecuting.infer;
5561
5591
  type WsMsgProgress = typeof types$1.WsMsgProgress.infer;
5562
5592
  type WsMsgExecutionError = typeof types$1.WsMsgExecutionError.infer;
5593
+ type LogEntry = typeof types$1.LogEntry.infer;
5563
5594
  type ComfyImageInfo = typeof types$1.ComfyImageInfo.infer;
5564
5595
  //#endregion
5565
5596
  //#region src/sdk-generator/comfy-api-json.d.ts
@@ -5573,7 +5604,9 @@ type ComfyApiJson = {
5573
5604
  };
5574
5605
  type ComfyApiNodeJson = {
5575
5606
  inputs: {
5576
- [key: string]: [string, number] | string | number | boolean | null;
5607
+ [key: string]: [string, number] | string | number | boolean | null | {
5608
+ [key: string]: unknown;
5609
+ };
5577
5610
  };
5578
5611
  class_type: string;
5579
5612
  };
@@ -6040,112 +6073,6 @@ declare class ComfyExecution {
6040
6073
  private _finish;
6041
6074
  }
6042
6075
  //#endregion
6043
- //#region src/litegraph/LiteGraphGroup.d.ts
6044
- type LiteGraphGroup = {
6045
- title: string;
6046
- bounding: [number, number, number, number];
6047
- color: string;
6048
- font_size: number;
6049
- flags: EmptyRecord;
6050
- };
6051
- //#endregion
6052
- //#region src/litegraph/LiteGraphLinkID.d.ts
6053
- declare const LiteGraphLinkID_: import("arktype/internal/variants/object.ts").ObjectType<Branded<number, {
6054
- LiteGraphLinkID: true;
6055
- }>, {}>;
6056
- type LiteGraphLinkID = typeof LiteGraphLinkID_.infer;
6057
- //#endregion
6058
- //#region src/litegraph/LiteGraphLink.d.ts
6059
- type LiteGraphLink = [linkId: LiteGraphLinkID, fromNodeId: number, fromNodeOutputIx: number, toNodeId: number, toNodeInputIx: number, linkType: string];
6060
- //#endregion
6061
- //#region src/litegraph/LiteGraphNodeInput.d.ts
6062
- type LiteGraphNodeInput = {
6063
- name: string;
6064
- type: string;
6065
- link: LiteGraphLinkID | null;
6066
- shape?: number;
6067
- widget?: {
6068
- name: string;
6069
- config: unknown;
6070
- };
6071
- };
6072
- //#endregion
6073
- //#region src/litegraph/LiteGraphSlotIndex.d.ts
6074
- declare const LiteGraphSlotIndex_: import("arktype/internal/variants/object.ts").ObjectType<Branded<number, {
6075
- LiteGraphSlotIndex: true;
6076
- }>, {}>;
6077
- type LiteGraphSlotIndex = typeof LiteGraphSlotIndex_.infer;
6078
- //#endregion
6079
- //#region src/litegraph/LiteGraphNodeOutput.d.ts
6080
- type LiteGraphNodeOutput = {
6081
- name: string;
6082
- type: string;
6083
- links: LiteGraphLinkID[] | null;
6084
- shape?: number;
6085
- slot_index?: LiteGraphSlotIndex;
6086
- };
6087
- //#endregion
6088
- //#region src/litegraph/LiteGraphNode.d.ts
6089
- type LiteGraphNode = {
6090
- id: number;
6091
- type: string;
6092
- title?: string;
6093
- color?: string;
6094
- bgColor?: string;
6095
- pos: {
6096
- '0': number;
6097
- '1': number;
6098
- };
6099
- size: {
6100
- '0': number;
6101
- '1': number;
6102
- };
6103
- flags?: EmptyRecord;
6104
- order?: number;
6105
- /**
6106
- * 0 = normal
6107
- * 1 = ?????
6108
- * 2 = muted
6109
- * */
6110
- mode?: number;
6111
- inputs?: LiteGraphNodeInput[];
6112
- outputs: LiteGraphNodeOutput[];
6113
- isVirtualNode?: boolean;
6114
- properties?: {
6115
- /**
6116
- * S&R stands for search and replace
6117
- * // 💬 2024-11-13 rvion: do we want to populate taht someday soon
6118
- */
6119
- 'Node name for S&R'?: string;
6120
- /** when set to true, it.... */
6121
- showOutputText?: boolean;
6122
- /** no clue what it does */
6123
- horizontal?: boolean;
6124
- };
6125
- widgets_values?: unknown[];
6126
- };
6127
- //#endregion
6128
- //#region src/litegraph/LiteGraphJSON.d.ts
6129
- /** litegraph workflow are stored... in a very unpractical format */
6130
- type LiteGraphJSON = {
6131
- last_node_id: number;
6132
- last_link_id: number;
6133
- nodes: LiteGraphNode[];
6134
- links: LiteGraphLink[];
6135
- groups: LiteGraphGroup[];
6136
- config: EmptyRecord;
6137
- extra: {
6138
- ds?: {
6139
- scale: number;
6140
- offset: {
6141
- 0: number;
6142
- 1: number;
6143
- };
6144
- };
6145
- };
6146
- version: 0.4;
6147
- };
6148
- //#endregion
6149
6076
  //#region src/sdk-generator/comfyui-sdk-codegen.d.ts
6150
6077
  /**
6151
6078
  * convert a host id to the namespace name it gets inside the global `Comfy` namespace
@@ -8759,9 +8686,15 @@ type PluginSuggestion = {
8759
8686
  declare class ComfyManager {
8760
8687
  host: {
8761
8688
  getServerHostHTTP: () => string;
8689
+ fetch: (route: string, init?: RequestInit, p?: {
8690
+ apiPrefix?: boolean;
8691
+ }) => Promise<Response>;
8762
8692
  };
8763
8693
  constructor(host: {
8764
8694
  getServerHostHTTP: () => string;
8695
+ fetch: (route: string, init?: RequestInit, p?: {
8696
+ apiPrefix?: boolean;
8697
+ }) => Promise<Response>;
8765
8698
  });
8766
8699
  get registry(): ComfyRegistry;
8767
8700
  fetchPluginsAndModels: () => Promise<void>;
@@ -8813,6 +8746,29 @@ declare class ComfyUploader {
8813
8746
  }) => Promise<ComfyImageName>;
8814
8747
  }
8815
8748
  //#endregion
8749
+ //#region src/host/hostUrl.d.ts
8750
+ /** pure url layer for ComfyHost: parse once, render everywhere. No comfyts global. */
8751
+ type ParsedHostBase = {
8752
+ scheme: 'http' | 'https';
8753
+ host: string;
8754
+ /** always concrete (defaults 80/443 from the scheme when the url omits it) */
8755
+ port: number;
8756
+ /** '' or '/segment…' with no trailing slash */
8757
+ basePath: string;
8758
+ };
8759
+ /** exactly ONE of `url` or the legacy `host`+`port` (+`https?`) spelling */
8760
+ declare function parseHostBase(p: {
8761
+ id: string;
8762
+ url?: string;
8763
+ host?: string;
8764
+ port?: number;
8765
+ https?: boolean;
8766
+ }): ParsedHostBase;
8767
+ /** http(s) base, port omitted when it is the scheme default */
8768
+ declare function renderHttpBase(p: ParsedHostBase): string;
8769
+ /** ws(s) endpoint; auth NEVER rides the query string (headers own it) */
8770
+ declare function renderWsUrl(p: ParsedHostBase): string;
8771
+ //#endregion
8816
8772
  //#region src/host/ResilientWebsocket.d.ts
8817
8773
  type Message = string | Buffer;
8818
8774
  type WsDebugMessage = {
@@ -8823,6 +8779,8 @@ type WsDebugMessage = {
8823
8779
  declare class ResilientWebSocketClient {
8824
8780
  options: {
8825
8781
  url: () => string;
8782
+ /** upgrade-request headers (auth: X-API-Key & co) — a thunk, re-read on every reconnect */
8783
+ headers?: () => Record<string, string>;
8826
8784
  onMessage: (event: MessageEvent) => void;
8827
8785
  onConnectOrReconnect: () => void;
8828
8786
  onClose: () => void;
@@ -8836,6 +8794,8 @@ declare class ResilientWebSocketClient {
8836
8794
  private addError;
8837
8795
  constructor(options: {
8838
8796
  url: () => string;
8797
+ /** upgrade-request headers (auth: X-API-Key & co) — a thunk, re-read on every reconnect */
8798
+ headers?: () => Record<string, string>;
8839
8799
  onMessage: (event: MessageEvent) => void;
8840
8800
  onConnectOrReconnect: () => void;
8841
8801
  onClose: () => void;
@@ -9194,9 +9154,23 @@ type ComfyHostID = Tagged<string, {
9194
9154
  }>;
9195
9155
  type ComfyHostData = {
9196
9156
  id: string;
9197
- host: string;
9198
- port: number;
9157
+ /** full base url as pasted from a provider (https://cloud.comfy.org,
9158
+ * https://xxx.modal.run, http://192.168.1.5:8188/comfy).
9159
+ * Exactly ONE of url OR the legacy host+port (+https?) spelling. */
9160
+ url?: string;
9161
+ host?: string;
9162
+ port?: number;
9199
9163
  https?: boolean;
9164
+ /** sent as X-API-Key on every request AND the ws upgrade.
9165
+ * NEVER persist the value: read it from an env var (e.g. COMFY_CLOUD_API_KEY) */
9166
+ apiKey?: string;
9167
+ /** default true. false = never write sdk.d.ts to .comfy-ts/hosts/<id>/ —
9168
+ * schema updates stay in-memory. The comfy-cloud example sets false: its sdk
9169
+ * home is the COMMITTED examples/comfy-cloud/sdk.d.ts (gen:sdk:cloud), and a
9170
+ * second copy under .comfy-ts/hosts/ would double-declare the globals. */
9171
+ sdkAutoWrite?: boolean;
9172
+ /** extra headers merged into every request + the ws upgrade (Modal-style auth pairs) */
9173
+ headers?: Record<string, string>;
9200
9174
  installType?: ComfyInstallType;
9201
9175
  onWsMessageAny?: (e: MessageEvent) => void;
9202
9176
  onWsMessageArrayBuffer?: (e: ArrayBuffer) => void;
@@ -9219,6 +9193,14 @@ type ServerLog = {
9219
9193
  content: string;
9220
9194
  id: number;
9221
9195
  };
9196
+ /** auth failure with a SPECIFIC meaning (per the Comfy Cloud error table):
9197
+ * 401 invalid/missing key · 402 insufficient credits · 429 subscription inactive
9198
+ * (or plain rate limiting on non-cloud hosts). The key value never appears here. */
9199
+ declare class ComfyHostAuthError extends Error {
9200
+ code: 401 | 402 | 429;
9201
+ hostId: string;
9202
+ constructor(code: 401 | 402 | 429, hostId: string, message: string);
9203
+ }
9222
9204
  declare class ComfyHost<ID extends string = string> {
9223
9205
  data: ComfyHostData & {
9224
9206
  id: ID;
@@ -9230,6 +9212,8 @@ declare class ComfyHost<ID extends string = string> {
9230
9212
  /** the schema instance with all methods to interract with the host schema */
9231
9213
  schema: ComfySchema;
9232
9214
  uploader: ComfyUploader;
9215
+ /** parsed ONCE from data (url-first or legacy host/port/https) — the url ground truth */
9216
+ readonly base: ParsedHostBase;
9233
9217
  constructor(data: ComfyHostData & {
9234
9218
  id: ID;
9235
9219
  });
@@ -9254,6 +9238,30 @@ declare class ComfyHost<ID extends string = string> {
9254
9238
  installCustomNode: (customNode: ComfyManagerPluginInfo) => Promise<boolean>;
9255
9239
  getServerHostHTTP(): string;
9256
9240
  getWSUrl: () => string;
9241
+ /** extra headers + X-API-Key, for every http request AND the ws upgrade */
9242
+ private authHeaders;
9243
+ /** remembered /api-prefix verdict for this host; null until first probed */
9244
+ private _apiPrefix;
9245
+ /**
9246
+ * the ONE http path to this host: joins basePath, injects X-API-Key + extra
9247
+ * headers, prefers `/api<route>` (required by Comfy Cloud, canonical since
9248
+ * custom nodes hijack bare routes) with a bare-route fallback on 404/405 for
9249
+ * old local servers (winner memoized; the other spelling is still retried
9250
+ * when the memo misses — mixed servers exist, e.g. /internal is bare-only).
9251
+ * Auth failures throw a typed ComfyHostAuthError instead of generic noise.
9252
+ * `p.apiPrefix: false` opts a route out of the prefix game entirely.
9253
+ */
9254
+ fetch: (route: string, init?: RequestInit, p?: {
9255
+ apiPrefix?: boolean;
9256
+ }) => Promise<Response>;
9257
+ /**
9258
+ * binary download path: Comfy Cloud answers `/api/view` with a 302 to a
9259
+ * temporary signed URL. fetch only auto-strips Authorization/cookies on
9260
+ * cross-origin redirects — a custom X-API-Key WOULD be forwarded to the
9261
+ * storage host — so we follow the Location manually with a CLEAN fetch.
9262
+ */
9263
+ fetchFile: (route: string) => Promise<Response>;
9264
+ private throwOnAuthError;
9257
9265
  schemaRetrievalLogs: string[];
9258
9266
  resetLog: () => void;
9259
9267
  get isConnected(): boolean;
@@ -9266,8 +9274,12 @@ declare class ComfyHost<ID extends string = string> {
9266
9274
  * (scripts, the TUI).
9267
9275
  */
9268
9276
  defineWorkflow: <V extends VarsSpec>(spec: DefineWorkflowSpec<ID, V>) => DefinedWorkflow<ID, V>;
9269
- /** import a workflow.json (litegraph format) as a live, editable workflow */
9270
- importWorkflowJson: (json: LiteGraphJSON, p?: {
9277
+ /**
9278
+ * import a workflow.json (litegraph format) as a live, editable workflow.
9279
+ * Accepts unknown: the JSON is ark-validated + normalized (parseWorkflowJson)
9280
+ * before conversion — invalid documents throw WorkflowNormalizeError.
9281
+ */
9282
+ importWorkflowJson: (json: unknown, p?: {
9271
9283
  id?: string;
9272
9284
  }) => ComfyWorkflow<ID>;
9273
9285
  /** import an api.json (ComfyUI prompt format) as a live, editable workflow */
@@ -9308,15 +9320,29 @@ declare class ComfyHost<ID extends string = string> {
9308
9320
  schemaUpdateResult: SchemaUpdateResult;
9309
9321
  private _schemaFromCache;
9310
9322
  /** load the schema from .comfy-ts/hosts/<id>/ without connecting (offline workflows, fast starts).
9311
- * idempotent like connect(): N co-imported modules parse the ~4MB cache once */
9323
+ * idempotent like connect(): N co-imported modules parse the ~4MB cache once.
9324
+ * A MISSING cache degrades LOUDLY to the base types instead of failing the
9325
+ * module import (a fresh consumer project has no cache yet — the bundled
9326
+ * examples must still open in the TUI; run() fetches the real schema through
9327
+ * connect() anyway). Not memoized in that case, so a later gen/connect retries. */
9312
9328
  loadSchemaFromCache(): Promise<void>;
9313
- /** POST a JSON route, preferring the /api prefix, falling back to the bare route */
9329
+ /** POST a JSON route through host.fetch (/api preferred, bare fallback) */
9314
9330
  private postJSON_;
9315
9331
  /** drop every PENDING prompt from the server queue (the running one keeps going) */
9316
9332
  clearQueue: () => Promise<void>;
9317
9333
  /** interrupt the CURRENTLY RUNNING prompt */
9318
9334
  interrupt: () => Promise<void>;
9319
- /** GET a JSON route, preferring the /api prefix, falling back to the bare route */
9335
+ /** the server's recent console buffer (entries are write CHUNKS, not lines) */
9336
+ fetchRawLogs: () => Promise<{
9337
+ entries: LogEntry[];
9338
+ }>;
9339
+ /** (un)subscribe THIS session to ws 'logs' messages — per-sid server state,
9340
+ * must be re-sent after every reconnect (see onSession) */
9341
+ subscribeLogs: (p: {
9342
+ enabled: boolean;
9343
+ clientId: string;
9344
+ }) => Promise<void>;
9345
+ /** GET a JSON route through host.fetch (/api preferred, bare fallback) */
9320
9346
  private fetchJSON_;
9321
9347
  /** retrieve the comfy spec from the schema*/
9322
9348
  fetchAndUpdateSchema: () => Promise<void>;
@@ -9409,13 +9435,192 @@ declare class ComfyHost<ID extends string = string> {
9409
9435
  onStatus: Maybe<(p: {
9410
9436
  queueRemaining: number;
9411
9437
  }) => void>;
9438
+ /** fires when the server assigns a NEW session id (first connect AND every
9439
+ * reconnect — per-sid server state like log subscriptions must be redone) */
9440
+ onSession: Maybe<(sid: string) => void>;
9441
+ /** fires on ws 'logs' messages (server console stream, see subscribeLogs) */
9442
+ onLogs: Maybe<(p: {
9443
+ entries: LogEntry[];
9444
+ }) => void>;
9412
9445
  /** the session assigned to us by the server */
9413
9446
  comfySessionId: string; /** send by ComfyUI server */
9447
+ /** binary frame types we already complained about (one log per type, no spam) */
9448
+ private _unknownBinaryFrameTypes;
9414
9449
  /** handy to keep around */
9415
9450
  status: ComfyStatusData['status'] | null;
9416
9451
  onMessage(e: MessageEvent): void;
9417
9452
  }
9418
9453
  //#endregion
9454
+ //#region src/litegraph/LiteGraphGroup.d.ts
9455
+ type LiteGraphGroup = {
9456
+ id?: number;
9457
+ title: string;
9458
+ bounding: [number, number, number, number];
9459
+ color?: string;
9460
+ font_size?: number;
9461
+ flags?: EmptyRecord;
9462
+ };
9463
+ //#endregion
9464
+ //#region src/litegraph/LiteGraphLinkID.d.ts
9465
+ declare const LiteGraphLinkID_: import("arktype/internal/variants/object.ts").ObjectType<Branded<number, {
9466
+ LiteGraphLinkID: true;
9467
+ }>, {}>;
9468
+ type LiteGraphLinkID = typeof LiteGraphLinkID_.infer;
9469
+ //#endregion
9470
+ //#region src/litegraph/LiteGraphLink.d.ts
9471
+ /** v0.4 serialization: links are 6-tuples (our EXPORT path emits this form) */
9472
+ type LiteGraphLinkTuple = [linkId: LiteGraphLinkID, fromNodeId: number, fromNodeOutputIx: number, toNodeId: number, toNodeInputIx: number, linkType: string];
9473
+ /** v1 serialization: links are objects (subgraph definition interiors use this) */
9474
+ type LiteGraphLinkObject = {
9475
+ id: LiteGraphLinkID;
9476
+ origin_id: number;
9477
+ origin_slot: number;
9478
+ target_id: number;
9479
+ target_slot: number;
9480
+ type: string;
9481
+ parentId?: number;
9482
+ };
9483
+ type LiteGraphLink = LiteGraphLinkTuple | LiteGraphLinkObject;
9484
+ //#endregion
9485
+ //#region src/litegraph/LiteGraphNodeInput.d.ts
9486
+ type LiteGraphNodeInput = {
9487
+ name: string;
9488
+ type: string;
9489
+ link?: LiteGraphLinkID | null;
9490
+ shape?: number;
9491
+ label?: string;
9492
+ widget?: {
9493
+ name: string;
9494
+ config?: unknown;
9495
+ };
9496
+ };
9497
+ //#endregion
9498
+ //#region src/litegraph/LiteGraphSlotIndex.d.ts
9499
+ declare const LiteGraphSlotIndex_: import("arktype/internal/variants/object.ts").ObjectType<Branded<number, {
9500
+ LiteGraphSlotIndex: true;
9501
+ }>, {}>;
9502
+ type LiteGraphSlotIndex = typeof LiteGraphSlotIndex_.infer;
9503
+ //#endregion
9504
+ //#region src/litegraph/LiteGraphNodeOutput.d.ts
9505
+ type LiteGraphNodeOutput = {
9506
+ name: string;
9507
+ type: string;
9508
+ links?: LiteGraphLinkID[] | null;
9509
+ shape?: number;
9510
+ slot_index?: LiteGraphSlotIndex;
9511
+ };
9512
+ //#endregion
9513
+ //#region src/litegraph/LiteGraphNode.d.ts
9514
+ type LiteGraphNode = {
9515
+ id: number;
9516
+ type: string;
9517
+ title?: string;
9518
+ color?: string;
9519
+ bgcolor?: string;
9520
+ pos: {
9521
+ '0': number;
9522
+ '1': number;
9523
+ };
9524
+ size: {
9525
+ '0': number;
9526
+ '1': number;
9527
+ };
9528
+ flags?: Record<string, unknown>;
9529
+ order?: number;
9530
+ /**
9531
+ * 0 = always (normal), 1 = on-event, 2 = muted (never),
9532
+ * 3 = on-trigger, 4 = bypassed
9533
+ */
9534
+ mode?: number;
9535
+ inputs?: LiteGraphNodeInput[];
9536
+ outputs?: LiteGraphNodeOutput[];
9537
+ isVirtualNode?: boolean;
9538
+ /** open record: proxyWidgets (subgraph widget promotion), cnr_id/ver (pack provenance), … */
9539
+ properties?: Record<string, unknown>;
9540
+ /** array form (positional) OR object form (named, e.g. VHS_VideoCombine) */
9541
+ widgets_values?: unknown[] | Record<string, unknown>;
9542
+ };
9543
+ //#endregion
9544
+ //#region src/litegraph/LiteGraphSubgraphDef.d.ts
9545
+ /** one exposed input/output slot of a subgraph definition */
9546
+ type LiteGraphSubgraphIO = {
9547
+ id: string;
9548
+ name: string;
9549
+ type: string;
9550
+ linkIds?: LiteGraphLinkID[];
9551
+ label?: string;
9552
+ localized_name?: string;
9553
+ pos?: {
9554
+ '0': number;
9555
+ '1': number;
9556
+ };
9557
+ shape?: number;
9558
+ };
9559
+ /**
9560
+ * a subgraph definition body (definitions.subgraphs[] entry). Corpus fact:
9561
+ * every one is a v1-shaped interior (object links, `state`) even when the
9562
+ * root document is v0.4 — instances reference it via node.type = this uuid.
9563
+ */
9564
+ type LiteGraphSubgraphDef = {
9565
+ id: string;
9566
+ name: string;
9567
+ version: number;
9568
+ state?: Record<string, unknown>;
9569
+ revision?: number;
9570
+ config?: EmptyRecord;
9571
+ extra?: unknown;
9572
+ nodes: LiteGraphNode[];
9573
+ links: LiteGraphLinkObject[];
9574
+ groups?: LiteGraphGroup[];
9575
+ inputNode: {
9576
+ id: number;
9577
+ bounding: number[];
9578
+ };
9579
+ outputNode: {
9580
+ id: number;
9581
+ bounding: number[];
9582
+ };
9583
+ inputs: LiteGraphSubgraphIO[];
9584
+ outputs: LiteGraphSubgraphIO[];
9585
+ widgets: unknown[];
9586
+ };
9587
+ //#endregion
9588
+ //#region src/litegraph/LiteGraphJSON.d.ts
9589
+ /**
9590
+ * litegraph workflow root, TOLERANT: models what upstream actually serializes
9591
+ * across eras — v0.4 (tuple links, last_*_id) and v1 (object links, `state`),
9592
+ * including hybrid files (v0.4 root + v1-shaped subgraph definitions).
9593
+ * Downstream code never reads this shape: `normalizeWorkflow` turns it into
9594
+ * the strict `CanonicalWorkflow`.
9595
+ */
9596
+ type LiteGraphJSON = {
9597
+ id?: string;
9598
+ revision?: number;
9599
+ last_node_id?: number;
9600
+ last_link_id?: number;
9601
+ state?: Record<string, unknown>;
9602
+ nodes: LiteGraphNode[];
9603
+ links: LiteGraphLink[];
9604
+ groups?: LiteGraphGroup[];
9605
+ config?: EmptyRecord;
9606
+ extra?: {
9607
+ ds?: {
9608
+ scale: number;
9609
+ offset: {
9610
+ 0: number;
9611
+ 1: number;
9612
+ };
9613
+ };
9614
+ };
9615
+ models?: unknown[];
9616
+ definitions?: {
9617
+ subgraphs: LiteGraphSubgraphDef[];
9618
+ };
9619
+ reroutes?: unknown[];
9620
+ floatingLinks?: unknown[];
9621
+ version: 0.4 | 1;
9622
+ };
9623
+ //#endregion
9419
9624
  //#region src/runner/ComfyWorkflow.d.ts
9420
9625
  type ProgressReport = {
9421
9626
  percent: number;
@@ -9840,6 +10045,135 @@ declare const auto_: AUTO;
9840
10045
  //#region src/litegraph/convertFlowToLiteGraphJSON.d.ts
9841
10046
  declare const convertFlowToLiteGraphJSON: (graph: ComfyWorkflow) => LiteGraphJSON;
9842
10047
  //#endregion
10048
+ //#region src/litegraph/CanonicalWorkflow.d.ts
10049
+ /**
10050
+ * the ONE strict internal shape for imported workflows. ZERO optional fields:
10051
+ * semantic absence is `null`, serializer noise gets a default at normalization.
10052
+ * Every consumer of an imported workflow JSON (converter, sweeps, TUI) reads
10053
+ * this type only — optionality never crosses `normalizeWorkflow`. A new
10054
+ * consumer needing a wire field ADDS it here (with a default), it does not
10055
+ * reach around the pipeline to the raw document.
10056
+ */
10057
+ type CanonicalWorkflow = {
10058
+ /** subgraph instances with a definition are expanded away by normalization (expandSubgraphs.ts) */
10059
+ nodes: CanonicalNode[];
10060
+ /** object form only, both wire eras unified */
10061
+ links: CanonicalLink[];
10062
+ /** [] when the document had none */
10063
+ groups: CanonicalGroup[];
10064
+ };
10065
+ type CanonicalLink = {
10066
+ id: LiteGraphLinkID;
10067
+ originId: number;
10068
+ originSlot: number;
10069
+ targetId: number;
10070
+ targetSlot: number;
10071
+ type: string;
10072
+ };
10073
+ /**
10074
+ * raw 0/1/3 (always / on-event / on-trigger) → 'normal'; 2 → 'muted'; 4 → 'bypassed'.
10075
+ * Literal union on purpose: converter switches are total, no magic ints downstream.
10076
+ */
10077
+ type NodeMode = 'normal' | 'muted' | 'bypassed';
10078
+ type CanonicalNode = {
10079
+ id: number;
10080
+ type: string;
10081
+ title: string | null;
10082
+ mode: NodeMode;
10083
+ isVirtualNode: boolean;
10084
+ inputs: CanonicalInput[];
10085
+ outputs: CanonicalOutput[];
10086
+ widgets: CanonicalWidgetValues;
10087
+ pos: [number, number];
10088
+ size: [number, number];
10089
+ properties: Record<string, unknown>;
10090
+ };
10091
+ type CanonicalInput = {
10092
+ name: string;
10093
+ type: string;
10094
+ link: LiteGraphLinkID | null;
10095
+ widgetName: string | null;
10096
+ };
10097
+ type CanonicalOutput = {
10098
+ name: string;
10099
+ type: string;
10100
+ links: LiteGraphLinkID[];
10101
+ };
10102
+ /**
10103
+ * ONE shape for all three widget-value realities: array form (positional),
10104
+ * object form (named, e.g. VHS_*), and subgraph promotion overrides (named).
10105
+ * Both fields ALWAYS present.
10106
+ */
10107
+ type CanonicalWidgetValues = {
10108
+ positional: unknown[];
10109
+ named: Record<string, unknown>;
10110
+ };
10111
+ type CanonicalGroup = {
10112
+ title: string;
10113
+ bounding: [number, number, number, number];
10114
+ color: string;
10115
+ fontSize: number;
10116
+ };
10117
+ //#endregion
10118
+ //#region src/litegraph/normalizeWorkflow.d.ts
10119
+ type WorkflowNormalizeErrorCode = 'schema-reject' | 'subgraph-cycle' | 'subgraph-io-mismatch' | 'bad-document';
10120
+ /** a workflow JSON we cannot turn into a CanonicalWorkflow — loud, typed, never a cast */
10121
+ declare class WorkflowNormalizeError extends Error {
10122
+ code: WorkflowNormalizeErrorCode;
10123
+ detail?: unknown;
10124
+ constructor(code: WorkflowNormalizeErrorCode, message: string, detail?: unknown);
10125
+ }
10126
+ /**
10127
+ * THE one entry for foreign workflow JSON (files, clipboard, imports):
10128
+ * tolerant ark validation, then normalization to the strict canonical shape.
10129
+ */
10130
+ declare const parseWorkflowJson: (json: unknown) => CanonicalWorkflow;
10131
+ /**
10132
+ * loose wire document → strict canonical document. Defaults filled, both link
10133
+ * eras unified, cosmetic fields dropped, subgraph definitions expanded away
10134
+ * (see expandSubgraphs.ts — def interiors go through the SAME per-shape
10135
+ * normalizers, they are v1 bodies).
10136
+ */
10137
+ declare const normalizeWorkflow: (raw: LiteGraphJSON) => CanonicalWorkflow;
10138
+ //#endregion
10139
+ //#region src/sdk-generator/litegraphToApiRequestPayload.d.ts
10140
+ type WorkflowConvertErrorCode = 'unknown-node' | 'missing-widget-value' | 'invalid-widget-value' | 'unknown-dynamic-combo-option' | 'dangling-link' | 'missing-required-input' | 'unsupported-feature';
10141
+ /** a canonical workflow the converter cannot turn into a prompt — the code NAMES the feature that failed */
10142
+ declare class WorkflowConvertError extends Error {
10143
+ code: WorkflowConvertErrorCode;
10144
+ node?: {
10145
+ id: number;
10146
+ type: string;
10147
+ } | undefined;
10148
+ constructor(code: WorkflowConvertErrorCode, message: string, node?: {
10149
+ id: number;
10150
+ type: string;
10151
+ } | undefined);
10152
+ }
10153
+ /**
10154
+ * convert a normalized workflow (CanonicalWorkflow — see parseWorkflowJson)
10155
+ * into the api.json (prompt format) ComfyUI's POST /prompt takes.
10156
+ * Handles: muted nodes (skipped, consumers resolve unconnected), bypassed
10157
+ * nodes (mode 4: link resolution walks through to the first type-matching
10158
+ * input), Note/MarkdownNote/Reroute/PrimitiveNode virtual nodes (reroutes
10159
+ * unwrapped, primitives inlined into their consumers), widget values both
10160
+ * positional (with the phantom `control_after_generate` offset after seeds)
10161
+ * and named (object-form widgets_values + subgraph promotion overrides —
10162
+ * named wins, but a live link wins over both). Widget-ness is decided from
10163
+ * the input CONFIG (inputWidgetKind.ts): V3 string-spelled widget types
10164
+ * (COMBO options, dynamic combos, autogrow containers, socketless customs)
10165
+ * and 2024-era enums go through ONE classifier; a positional array shorter
10166
+ * than the schema's widget list fills schema defaults, never throws
10167
+ * (agent/architecture.md owns both decisions).
10168
+ */
10169
+ declare const convertLiteGraphToPrompt: (
10170
+ /** the ComfySchema object (to look for references/definitions) */
10171
+ schema: ComfySchema,
10172
+ /** the normalized litegraph document */
10173
+ workflow: CanonicalWorkflow, opts?: {
10174
+ verbose?: boolean;
10175
+ }) => ComfyApiJson;
10176
+ //#endregion
9843
10177
  //#region src/vars/loraKeywords.d.ts
9844
10178
  declare function getLoraKeyword(name: string): string;
9845
10179
  /** empty keyword deletes the entry; every set writes the file (tiny, rare) */
@@ -9858,5 +10192,5 @@ declare function isTuiActive(): boolean;
9858
10192
  */
9859
10193
  declare function loraTag<N extends string = string>(name: N, strength?: number, clipStrength?: number): string;
9860
10194
  //#endregion
9861
- export { AbsolutePath, type ActiveLora, type ActiveLoraSource, type AnyVar, BaseNode, BaseNodeFactory, BaseNodeInputs, BaseNodeOutputs, type BoundVars, Branded, ChoiceVar, type CodegenOptions, type ComfyApiJson, type ComfyApiNodeJson, ComfyExecution, type ComfyExecutionData, type ComfyExecutionStatus, ComfyHost, type ComfyHostData, type ComfyHostID, type ComfyImageName, ComfyManager, ComfyNode, type ComfyNodeId, type ComfyNodeIdMode, type ComfyNodeMetadata, ComfyNodeOutput, type ComfyNodeSchemaJSON, ComfySchema, type ComfySchemaJSON, ComfySdkBase, ComfySdkShape, ComfyTS, type ComfyUnionValue, type ComfyUploadImageResult, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, type ComfyWorkflowData, type ComfyWorkflowID, type ConnectOptions, ConvertibleImageFormat, DEFAULT_SIZE_PRESETS, type DefineWorkflowSpec, DefinedWorkflow, Either, EmptyRecord, type ExecutionProgress, type ExecutionSnapshot, Flavor, FloatVar, HTMLContent, ImageSaveFormat, IntVar, InvalidPromptError, IsEqual, type LiteGraphJSON, type LoraNameOf, type LoraStrength, type LorasHost, LorasVar, MDContent, Maybe, MediaImage, type MediaImageData, NodeOf, PartialOmit, type PluginInstallStatus, type PluginSuggestion, type ProgressReport, type PromptID, type PromptRelated_WsMsg, type PromptValue, PromptVar, type QualifiedNodeKey, RelativePath, type Requirements, ResilientWebSocketClient, Result, ResultFailure, type RunSettings, SdkForHost, SeedVar, type SizePreset, type SizeValue, SizeVar, Tagged, TextVar, ToggleVar, type VarKind, type VarValues, type VarsSpec, type WsMsg, __FAIL, __OK, activeLoras, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, codegenSDK, convertFlowToLiteGraphJSON, getLoraKeyword, hostIdToNamespace, isTuiActive, loraTag, number_Timestamp, resultFailure, resultSuccess, setLoraKeyword, v };
10195
+ export { AbsolutePath, type ActiveLora, type ActiveLoraSource, type AnyVar, BaseNode, BaseNodeFactory, BaseNodeInputs, BaseNodeOutputs, type BoundVars, Branded, type CanonicalGroup, type CanonicalInput, type CanonicalLink, type CanonicalNode, type CanonicalOutput, type CanonicalWidgetValues, type CanonicalWorkflow, ChoiceVar, type CodegenOptions, type ComfyApiJson, type ComfyApiNodeJson, ComfyExecution, type ComfyExecutionData, type ComfyExecutionStatus, ComfyHost, ComfyHostAuthError, type ComfyHostData, type ComfyHostID, type ComfyImageName, ComfyManager, ComfyNode, type ComfyNodeId, type ComfyNodeIdMode, type ComfyNodeMetadata, ComfyNodeOutput, type ComfyNodeSchemaJSON, ComfySchema, type ComfySchemaJSON, ComfySdkBase, ComfySdkShape, ComfyTS, type ComfyUnionValue, type ComfyUploadImageResult, ComfyUploader, ComfyVar, ComfyVarBase, ComfyWorkflow, ComfyWorkflowBuilder, type ComfyWorkflowData, type ComfyWorkflowID, type ConnectOptions, ConvertibleImageFormat, DEFAULT_SIZE_PRESETS, type DefineWorkflowSpec, DefinedWorkflow, Either, EmptyRecord, type ExecutionProgress, type ExecutionSnapshot, Flavor, FloatVar, HTMLContent, ImageSaveFormat, IntVar, InvalidPromptError, IsEqual, type LiteGraphJSON, type LoraNameOf, type LoraStrength, type LorasHost, LorasVar, MDContent, Maybe, MediaImage, type MediaImageData, type NodeMode, NodeOf, type ParsedHostBase, PartialOmit, type PluginInstallStatus, type PluginSuggestion, type ProgressReport, type PromptID, type PromptRelated_WsMsg, type PromptValue, PromptVar, type QualifiedNodeKey, RelativePath, type Requirements, ResilientWebSocketClient, Result, ResultFailure, type RunSettings, SdkForHost, SeedVar, type SizePreset, type SizeValue, SizeVar, Tagged, TextVar, ToggleVar, type VarKind, type VarValues, type VarsSpec, WorkflowConvertError, WorkflowNormalizeError, type WsMsg, __FAIL, __OK, activeLoras, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, getLoraKeyword, hostIdToNamespace, isTuiActive, loraTag, normalizeWorkflow, number_Timestamp, parseHostBase, parseWorkflowJson, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setLoraKeyword, v };
9862
10196
  //# sourceMappingURL=index.d.cts.map