comfy-ts 2.16.0 → 2.17.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 (59) hide show
  1. package/README.md +23 -0
  2. package/dist/{run-serve-C78hD7t9.js → ServeApp-BSA5yzxZ.js} +17 -444
  3. package/dist/ServeApp-BSA5yzxZ.js.map +1 -0
  4. package/dist/cli.js +18 -5
  5. package/dist/cli.js.map +1 -1
  6. package/dist/exampleAssets-BfWzygoM.js +38 -0
  7. package/dist/exampleAssets-BfWzygoM.js.map +1 -0
  8. package/dist/{LogsSt-Ct7Le0S_.js → findDefinedWorkflow-0lG-VTEd.js} +201 -201
  9. package/dist/findDefinedWorkflow-0lG-VTEd.js.map +1 -0
  10. package/dist/index.cjs +146 -59
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +61 -8
  13. package/dist/index.d.ts +61 -8
  14. package/dist/index.js +146 -59
  15. package/dist/index.js.map +1 -1
  16. package/dist/run-run-DnaMLCFn.js +450 -0
  17. package/dist/run-run-DnaMLCFn.js.map +1 -0
  18. package/dist/run-serve-CbKxIu6i.js +418 -0
  19. package/dist/run-serve-CbKxIu6i.js.map +1 -0
  20. package/dist/{run-tui-nPETFRmk.js → run-tui-B0AQWbad.js} +6 -37
  21. package/dist/run-tui-B0AQWbad.js.map +1 -0
  22. package/dist/{schemaDrift-wb5XkrHV.js → schemaDrift-CbsABBuk.js} +3 -2
  23. package/dist/{schemaDrift-wb5XkrHV.js.map → schemaDrift-CbsABBuk.js.map} +1 -1
  24. package/dist/serve-web.js +37 -37
  25. package/dist/{state-BMW57_M0.js → state-C2oDiQ26.js} +146 -60
  26. package/dist/state-C2oDiQ26.js.map +1 -0
  27. package/dist/web.d.ts +61 -8
  28. package/dist/web.js +146 -59
  29. package/dist/web.js.map +1 -1
  30. package/examples/README.md +1 -0
  31. package/examples/rvion/15-tts-voice-clone.cflow.ts +8 -8
  32. package/examples/rvion/16-tts-voice-design.cflow.ts +71 -0
  33. package/guide-for-agents.md +3 -0
  34. package/package.json +1 -1
  35. package/src/cli/comfy-ts-cli.ts +14 -1
  36. package/src/cli/run/findModules.ts +36 -0
  37. package/src/cli/run/flagValue.ts +61 -0
  38. package/src/cli/run/outputPaths.ts +41 -0
  39. package/src/cli/run/pickModule.ts +41 -0
  40. package/src/cli/run/run-run.ts +250 -0
  41. package/src/cli/run/runArgs.ts +61 -0
  42. package/src/cli/run/sidecar.ts +27 -0
  43. package/src/cli/serve/ServeApp.ts +13 -39
  44. package/src/cli/serve/web/components/DraftTabs.tsx +8 -2
  45. package/src/cli/serve/web/state/draftTabs.ts +12 -0
  46. package/src/cli/serve/web/state/shortcutCatalog.ts +1 -0
  47. package/src/coreExports.ts +2 -0
  48. package/src/host/ComfyHost.ts +73 -40
  49. package/src/host/previewMethod.ts +29 -0
  50. package/src/runner/ComfyExecution.ts +45 -1
  51. package/src/runner/ComfyWorkflow.ts +6 -1
  52. package/src/runner/ComfyWsApi.ts +1 -1
  53. package/src/runner/wsBinaryFrame.ts +48 -25
  54. package/src/vars/ComfyVars.ts +3 -0
  55. package/src/vars/DefinedWorkflow.ts +1 -0
  56. package/dist/LogsSt-Ct7Le0S_.js.map +0 -1
  57. package/dist/run-serve-C78hD7t9.js.map +0 -1
  58. package/dist/run-tui-nPETFRmk.js.map +0 -1
  59. package/dist/state-BMW57_M0.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { X as ansi, a as DefinedWorkflow, at as extractErrorMessage, ct as getComfyStorage, dt as logError, ft as logInfo, ht as sha1HexOfString, it as hashArrayBuffer, lt as resolveComfyStorage, mt as statelessRegex, n as diffSchemas, nt as isVideoFilename, ot as isRecord$1, pt as logSuccess, rt as mediaMime, st as bang, t as MODEL_LISTS, ut as isQuiet } from "./schemaDrift-wb5XkrHV.js";
1
+ import { X as ansi, a as DefinedWorkflow, at as extractErrorMessage, ct as getComfyStorage, dt as logError, ft as logInfo, ht as sha1HexOfString, it as hashArrayBuffer, lt as resolveComfyStorage, mt as statelessRegex, n as diffSchemas, nt as isVideoFilename, ot as isRecord$1, pt as logSuccess, rt as mediaMime, st as bang, t as MODEL_LISTS, ut as isQuiet } from "./schemaDrift-CbsABBuk.js";
2
2
  import { basename, join } from "pathe";
3
3
  import { scope, type } from "arktype";
4
4
  import { nanoid } from "nanoid";
@@ -850,7 +850,7 @@ var ComfySchema = class {
850
850
  };
851
851
  //#endregion
852
852
  //#region package.json
853
- var version = "2.16.0";
853
+ var version = "2.17.0";
854
854
  //#endregion
855
855
  //#region src/litegraph/LiteGraphLinkID.ts
856
856
  const asLiteGraphLinkID = (id) => id;
@@ -1390,21 +1390,41 @@ const normalizeGroup = (g) => {
1390
1390
  };
1391
1391
  };
1392
1392
  //#endregion
1393
- //#region src/runner/wsBinaryFrame.ts
1394
- function parseBinaryWsFrame(data) {
1395
- const view = new DataView(data);
1396
- const eventType = view.getUint32(0);
1397
- if (eventType === 1) {
1398
- const imageType = view.getUint32(4);
1399
- return {
1400
- kind: "preview",
1401
- bytes: new Uint8Array(data.slice(8)),
1402
- mime: imageType === 2 ? "image/png" : "image/jpeg",
1403
- metadata: null
1404
- };
1393
+ //#region src/host/previewMethod.ts
1394
+ function isPreviewMethod(x) {
1395
+ return x === "none" || x === "auto" || x === "latent2rgb" || x === "taesd";
1396
+ }
1397
+ /** the preview method a host was launched with, from its /system_stats payload. `'none'` when
1398
+ * the flag is absent (ComfyUI's default), null when the payload carries no argv to read (a cloud
1399
+ * host) or the flag holds a value this parser does not know */
1400
+ function previewMethodFromSystemStats(stats) {
1401
+ if (stats == null || typeof stats !== "object" || !("system" in stats)) return null;
1402
+ const system = stats.system;
1403
+ if (system == null || typeof system !== "object" || !("argv" in system)) return null;
1404
+ const argv = system.argv;
1405
+ if (!Array.isArray(argv)) return null;
1406
+ for (let i = 0; i < argv.length; i++) {
1407
+ const arg = argv[i];
1408
+ if (typeof arg !== "string") continue;
1409
+ const value = arg === "--preview-method" ? argv[i + 1] : arg.startsWith("--preview-method=") ? arg.slice(17) : void 0;
1410
+ if (value === void 0) continue;
1411
+ return isPreviewMethod(value) ? value : null;
1405
1412
  }
1413
+ return "none";
1414
+ }
1415
+ /** the frame's event type, read in place: deciding whether anyone wants a frame costs no copy */
1416
+ function binaryFrameType(data) {
1417
+ if (data.byteLength < 4) return -1;
1418
+ return new DataView(data).getUint32(0);
1419
+ }
1420
+ function isPreviewFrameType(eventType) {
1421
+ return eventType === 1 || eventType === 4;
1422
+ }
1423
+ function parseBinaryWsFrame(data) {
1424
+ const eventType = binaryFrameType(data);
1425
+ if (isPreviewFrameType(eventType)) return parsePreviewFrame(data);
1406
1426
  if (eventType === 3) {
1407
- const nodeIdLen = view.getUint32(4);
1427
+ const nodeIdLen = new DataView(data).getUint32(4);
1408
1428
  const decoder = new TextDecoder();
1409
1429
  return {
1410
1430
  kind: "text",
@@ -1412,25 +1432,41 @@ function parseBinaryWsFrame(data) {
1412
1432
  text: decoder.decode(data.slice(8 + nodeIdLen))
1413
1433
  };
1414
1434
  }
1415
- if (eventType === 4) {
1416
- const metadataLen = view.getUint32(4);
1417
- let metadata = null;
1418
- try {
1419
- metadata = JSON.parse(new TextDecoder().decode(data.slice(8, 8 + metadataLen)));
1420
- } catch {}
1421
- const bytes = new Uint8Array(data.slice(8 + metadataLen));
1435
+ return {
1436
+ kind: "unknown",
1437
+ eventType
1438
+ };
1439
+ }
1440
+ /** a type 1 or type 4 frame; the caller checked the type with `isPreviewFrameType` */
1441
+ function parsePreviewFrame(data) {
1442
+ const view = new DataView(data);
1443
+ if (view.getUint32(0) === 1) {
1444
+ const imageType = view.getUint32(4);
1422
1445
  return {
1423
1446
  kind: "preview",
1424
- bytes,
1425
- mime: bytes[0] === 137 && bytes[1] === 80 ? "image/png" : "image/jpeg",
1426
- metadata
1447
+ bytes: new Uint8Array(data.slice(8)),
1448
+ mime: imageType === 2 ? "image/png" : "image/jpeg",
1449
+ metadata: null
1427
1450
  };
1428
1451
  }
1452
+ const metadataLen = view.getUint32(4);
1453
+ let metadata = null;
1454
+ try {
1455
+ metadata = JSON.parse(new TextDecoder().decode(data.slice(8, 8 + metadataLen)));
1456
+ } catch {}
1457
+ const bytes = new Uint8Array(data.slice(8 + metadataLen));
1429
1458
  return {
1430
- kind: "unknown",
1431
- eventType
1459
+ kind: "preview",
1460
+ bytes,
1461
+ mime: bytes[0] === 137 && bytes[1] === 80 ? "image/png" : "image/jpeg",
1462
+ metadata
1432
1463
  };
1433
1464
  }
1465
+ /** the node a type 4 frame names (`node_id` in its metadata), null when absent or malformed */
1466
+ function previewMetadataNodeId(metadata) {
1467
+ if (metadata == null || typeof metadata !== "object" || !("node_id" in metadata)) return null;
1468
+ return typeof metadata.node_id === "string" && metadata.node_id !== "" ? metadata.node_id : null;
1469
+ }
1434
1470
  //#endregion
1435
1471
  //#region src/sdk-generator/litegraphToApiRequestPayload.ts
1436
1472
  /** a canonical workflow the converter cannot turn into a prompt — the code NAMES the feature that failed */
@@ -2674,6 +2710,7 @@ var ComfyExecution = class {
2674
2710
  this.ephemeral = false;
2675
2711
  this.snapshot = null;
2676
2712
  this.onProgress = null;
2713
+ this.onPreview = null;
2677
2714
  this.logProgress = false;
2678
2715
  this.startedAt = Date.now();
2679
2716
  this._lastLoggedLine = "";
@@ -2687,6 +2724,7 @@ var ComfyExecution = class {
2687
2724
  bytes: msg.bytes,
2688
2725
  mime: msg.mime
2689
2726
  });
2727
+ else this.onPreviewFrame(msg);
2690
2728
  return;
2691
2729
  }
2692
2730
  if (msg.type === "execution_start") return;
@@ -2933,6 +2971,7 @@ var ComfyExecution = class {
2933
2971
  this.scrubHistory = init.scrubHistory ?? false;
2934
2972
  this.ephemeral = init.ephemeral ?? false;
2935
2973
  this.onProgress = init.onProgress ?? null;
2974
+ this.onPreview = init.onPreview ?? null;
2936
2975
  this.logProgress = init.logProgress ?? false;
2937
2976
  this.host.executions.set(data.id, this);
2938
2977
  this.onCreate();
@@ -3013,6 +3052,28 @@ var ComfyExecution = class {
3013
3052
  if (uid == null) return false;
3014
3053
  return (this.snapshot?.apiJson ?? this.workflow.apiJson)[uid]?.class_type === "SaveImageWebsocket";
3015
3054
  }
3055
+ /** @internal a live preview frame of this run; never an output (the host routes ws saver frames
3056
+ * to onWsImageOutput before they get here) */
3057
+ onPreviewFrame(p) {
3058
+ const listener = this.onPreview;
3059
+ if (listener == null) return;
3060
+ const current = this.workflow.currentExecutingNode;
3061
+ const nodeId = previewMetadataNodeId(p.metadata) ?? current?.uid ?? null;
3062
+ const apiJson = this.snapshot?.apiJson ?? this.workflow.apiJson;
3063
+ const counter = current != null && current.uid === nodeId ? current.progress : null;
3064
+ listener({
3065
+ promptId: this.data.id,
3066
+ bytes: p.bytes,
3067
+ mime: p.mime,
3068
+ nodeId,
3069
+ nodeName: nodeId != null ? apiJson[nodeId]?.class_type ?? null : null,
3070
+ step: counter != null ? {
3071
+ value: counter.value,
3072
+ max: counter.max
3073
+ } : null,
3074
+ metadata: p.metadata
3075
+ });
3076
+ }
3016
3077
  /** @internal a live-text frame for one node */
3017
3078
  onProgressText(p) {
3018
3079
  this.progressTexts.set(p.nodeId, p.text);
@@ -3321,6 +3382,7 @@ var ComfyWorkflow = class {
3321
3382
  ephemeral: p.ephemeral ?? false,
3322
3383
  scrubHistory: p.scrubHistory ?? p.ephemeral ?? false,
3323
3384
  onProgress: p.onProgress,
3385
+ onPreview: p.onPreview,
3324
3386
  logProgress: p.log ?? false
3325
3387
  });
3326
3388
  };
@@ -4131,6 +4193,11 @@ var ComfyHost = class {
4131
4193
  this.clearHistory = () => {
4132
4194
  return this.postJSON_("/history", { clear: true });
4133
4195
  };
4196
+ this.fetchPreviewMethod = async () => {
4197
+ const res = await this.fetch("/system_stats", {});
4198
+ if (!res.ok) throw new Error(`GET /system_stats failed: ${res.status}`);
4199
+ return previewMethodFromSystemStats(await res.json());
4200
+ };
4134
4201
  this.fetchRawLogs = async () => {
4135
4202
  const res = await this.fetch("/internal/logs/raw", {}, { apiPrefix: false });
4136
4203
  if (!res.ok) throw new Error(`GET /internal/logs/raw failed: ${res.status}`);
@@ -4207,7 +4274,8 @@ var ComfyHost = class {
4207
4274
  this.executions = /* @__PURE__ */ new Map();
4208
4275
  this._pendingMsgs = /* @__PURE__ */ new Map();
4209
4276
  this.activePromptID = null;
4210
- this.latentPreview = null;
4277
+ this._latentFrame = null;
4278
+ this._latentPreview = null;
4211
4279
  this.onLatentPreview = null;
4212
4280
  this.onProgressText = null;
4213
4281
  this.onStatus = null;
@@ -4384,42 +4452,60 @@ var ComfyHost = class {
4384
4452
  }
4385
4453
  prompt.onPromptRelatedMessage(msg);
4386
4454
  }
4455
+ /** the latent image beeing generated, in case you want to display it. Built on read: a
4456
+ * session that never reads it never decodes a frame nor holds an object url */
4457
+ get latentPreview() {
4458
+ if (this._latentPreview != null || this._latentFrame == null) return this._latentPreview;
4459
+ const frame = parsePreviewFrame(this._latentFrame.data);
4460
+ const blob = new Blob([frame.bytes], { type: frame.mime });
4461
+ this._latentPreview = {
4462
+ blob,
4463
+ url: URL.createObjectURL(blob),
4464
+ receivedAt: this._latentFrame.receivedAt,
4465
+ promptID: this._latentFrame.promptID
4466
+ };
4467
+ return this._latentPreview;
4468
+ }
4469
+ /** a type 1 or 4 frame. Parsed only when someone wants it, in this order (architecture.md,
4470
+ * Live previews): the ws saver's output, the pre-registration buffer, the run's onPreview,
4471
+ * the host hook. Nobody listening = the frame is kept by reference and never copied */
4472
+ onPreviewFrame(data) {
4473
+ let parsed = null;
4474
+ const frame = () => parsed ??= parsePreviewFrame(data);
4475
+ const promptID = this.activePromptID;
4476
+ const activeExec = promptID != null ? this.executions.get(promptID) : null;
4477
+ if (activeExec?.wsOutputNodeExecuting) return activeExec.onWsImageOutput({
4478
+ bytes: frame().bytes,
4479
+ mime: frame().mime
4480
+ });
4481
+ const pending = promptID != null ? this._pendingMsgs.get(promptID) : void 0;
4482
+ if (pending != null) pending.push({
4483
+ type: "binary_preview_frame",
4484
+ bytes: frame().bytes,
4485
+ mime: frame().mime,
4486
+ metadata: frame().metadata
4487
+ });
4488
+ if (this._latentPreview != null) URL.revokeObjectURL(this._latentPreview.url);
4489
+ this._latentPreview = null;
4490
+ this._latentFrame = {
4491
+ data,
4492
+ promptID,
4493
+ receivedAt: Date.now()
4494
+ };
4495
+ if (activeExec?.onPreview != null) activeExec.onPreviewFrame(frame());
4496
+ if (this.onLatentPreview != null) this.onLatentPreview({
4497
+ bytes: frame().bytes,
4498
+ mime: frame().mime,
4499
+ promptID
4500
+ });
4501
+ }
4387
4502
  onMessage(e) {
4388
4503
  this.lastWsMessageAt = Date.now();
4389
4504
  if (this.data.onWsMessageAny) this.data.onWsMessageAny(e);
4390
4505
  if (e.data instanceof ArrayBuffer) {
4506
+ if (isPreviewFrameType(binaryFrameType(e.data))) return this.onPreviewFrame(e.data);
4391
4507
  const frame = parseBinaryWsFrame(e.data);
4392
- if (frame.kind === "preview") {
4393
- const activeExec = this.activePromptID != null ? this.executions.get(this.activePromptID) : null;
4394
- if (activeExec?.wsOutputNodeExecuting) {
4395
- activeExec.onWsImageOutput({
4396
- bytes: frame.bytes,
4397
- mime: frame.mime
4398
- });
4399
- return;
4400
- }
4401
- if (this.activePromptID != null) {
4402
- const pending = this._pendingMsgs.get(this.activePromptID);
4403
- if (pending != null) pending.push({
4404
- type: "binary_preview_frame",
4405
- bytes: frame.bytes,
4406
- mime: frame.mime
4407
- });
4408
- }
4409
- if (this.latentPreview != null) URL.revokeObjectURL(this.latentPreview.url);
4410
- const imageBlob = new Blob([frame.bytes], { type: frame.mime });
4411
- this.latentPreview = {
4412
- blob: imageBlob,
4413
- url: URL.createObjectURL(imageBlob),
4414
- receivedAt: Date.now(),
4415
- promptID: this.activePromptID
4416
- };
4417
- this.onLatentPreview?.({
4418
- bytes: frame.bytes,
4419
- mime: frame.mime,
4420
- promptID: this.activePromptID
4421
- });
4422
- } else if (frame.kind === "unknown" && !this._unknownBinaryFrameTypes.has(frame.eventType)) {
4508
+ if (frame.kind === "unknown" && !this._unknownBinaryFrameTypes.has(frame.eventType)) {
4423
4509
  this._unknownBinaryFrameTypes.add(frame.eventType);
4424
4510
  console.error(`🔴 unknown binary ws frame type ${frame.eventType} from host ${this.data.id} — ignored`);
4425
4511
  }
@@ -5138,4 +5224,4 @@ var ComfyTS = class ComfyTS {
5138
5224
  //#endregion
5139
5225
  export { ComfySchema as a, importSharp as i, settingsPathFor as n, readableStringify as r, ComfyTS as t };
5140
5226
 
5141
- //# sourceMappingURL=state-BMW57_M0.js.map
5227
+ //# sourceMappingURL=state-C2oDiQ26.js.map