comfy-ts 2.12.0 → 2.13.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 (69) hide show
  1. package/dist/{LogsSt-U1H0mP1m.js → LogsSt-CUeo843w.js} +18 -4
  2. package/dist/LogsSt-CUeo843w.js.map +1 -0
  3. package/dist/cli.js +4 -4
  4. package/dist/index.cjs +123 -12
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +96 -16
  7. package/dist/index.d.ts +96 -16
  8. package/dist/index.js +123 -12
  9. package/dist/index.js.map +1 -1
  10. package/dist/{run-serve-BeAznay5.js → run-serve-DlRBv_Nk.js} +281 -19
  11. package/dist/run-serve-DlRBv_Nk.js.map +1 -0
  12. package/dist/{run-tui-BTGjvnKk.js → run-tui-B5uxm2_l.js} +4 -4
  13. package/dist/{run-tui-BTGjvnKk.js.map → run-tui-B5uxm2_l.js.map} +1 -1
  14. package/dist/{schemaDrift-Cg39vs53.js → schemaDrift-E95iTF7E.js} +4 -1
  15. package/dist/{schemaDrift-Cg39vs53.js.map → schemaDrift-E95iTF7E.js.map} +1 -1
  16. package/dist/serve-web.js +291 -129
  17. package/dist/{state-C7REnHan.js → state-CUp2J1Zy.js} +122 -14
  18. package/dist/state-CUp2J1Zy.js.map +1 -0
  19. package/dist/web.d.ts +96 -16
  20. package/dist/web.js +123 -12
  21. package/dist/web.js.map +1 -1
  22. package/examples/comfy-cloud/sdk.d.ts +163 -163
  23. package/examples/rvion/10-anima-t2i.cflow.ts +48 -25
  24. package/examples/rvion/11-yue2-t2a.cflow.ts +105 -0
  25. package/examples/rvion/12-stable-audio-3-t2a.cflow.ts +78 -0
  26. package/examples/rvion/13-ace-step-15-xl-t2a.cflow.ts +153 -0
  27. package/examples/rvion/stableAudio3Prompts.ts +19 -0
  28. package/package.json +2 -2
  29. package/src/cli/serve/ServeApp.ts +157 -18
  30. package/src/cli/serve/byteRange.ts +48 -0
  31. package/src/cli/serve/run-serve.ts +12 -3
  32. package/src/cli/serve/web/api.ts +24 -0
  33. package/src/cli/serve/web/components/App.tsx +305 -156
  34. package/src/cli/serve/web/components/DraftTabs.tsx +167 -0
  35. package/src/cli/serve/web/components/Gallery.tsx +44 -19
  36. package/src/cli/serve/web/components/Icon.tsx +40 -0
  37. package/src/cli/serve/web/components/Omnibox.tsx +70 -20
  38. package/src/cli/serve/web/components/SideMenu.tsx +414 -0
  39. package/src/cli/serve/web/components/TooltipLayer.tsx +3 -2
  40. package/src/cli/serve/web/components/VarsForm.tsx +70 -351
  41. package/src/cli/serve/web/components/controls/LorasControl.tsx +24 -22
  42. package/src/cli/serve/web/promptEditor/promptExtensions.ts +6 -3
  43. package/src/cli/serve/web/state/EnhancerSt.ts +17 -2
  44. package/src/cli/serve/web/state/FormSt.ts +22 -2
  45. package/src/cli/serve/web/state/OmniboxSt.ts +3 -1
  46. package/src/cli/serve/web/state/WebSt.ts +172 -33
  47. package/src/cli/serve/web/state/draftNames.ts +16 -0
  48. package/src/cli/serve/web/state/draftTabs.ts +75 -0
  49. package/src/cli/serve/web/state/generateButton.ts +1 -1
  50. package/src/cli/serve/web/state/omnibox.ts +82 -18
  51. package/src/cli/serve/web/state/shortcuts.ts +56 -7
  52. package/src/cli/serve/web/styles.ts +242 -82
  53. package/src/cli/serve/workflowTags.ts +42 -0
  54. package/src/cli/serve/workspaceLabels.ts +23 -0
  55. package/src/cli/tui/state/DraftsSt.ts +10 -6
  56. package/src/coreExports.ts +1 -0
  57. package/src/host/ComfyHost.ts +17 -2
  58. package/src/host/ResilientWebsocket.ts +54 -4
  59. package/src/runner/ComfyExecution.ts +60 -0
  60. package/src/runner/ComfyWorkflow.ts +4 -0
  61. package/src/runner/ComfyWsApi.ts +2 -0
  62. package/src/runner/MediaImage.ts +2 -2
  63. package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +5 -5
  64. package/src/sdk-generator/comfyui-sdk-codegen.ts +1 -1
  65. package/src/utils/copyName.ts +12 -0
  66. package/src/vars/DefinedWorkflow.ts +7 -1
  67. package/dist/LogsSt-U1H0mP1m.js.map +0 -1
  68. package/dist/run-serve-BeAznay5.js.map +0 -1
  69. package/dist/state-C7REnHan.js.map +0 -1
@@ -1,5 +1,5 @@
1
- import { $ as stripAnsi, A as refreshLoraInfoCacheIfChanged, B as lmFilePath, C as getLoraTriggerWords, D as lorasMissingFromMirror, E as loraMirrorEntries, F as fetchLoraExampleImages, G as lmSha256, H as lmFolder, I as fetchLoraList, K as lmTags, L as fetchLoraPreviewBytes, M as writeLoraMirror, N as fetchLoraCivitai, P as fetchLoraDescription, Q as colorsAvailable, R as lmBaseModel, S as getLoraPreviewUrl, V as lmFileSize, W as lmNotes, X as loraPreviewMapFrom, Y as loraKey, Z as ansi, b as getLoraDisplayName, d as isPromptInput, dt as sha1HexOfString, et as extractErrorMessage, f as isLoraStrength, i as summarizeDrift, j as reloadLoraInfoCache, k as recordCivitaiMiss, l as isLoraLanes, lt as statelessRegex, m as getLoraKeyword, nt as bang, o as DEFAULT_IMAGE_EXTENSIONS, r as driftChanged, u as isLorasInput, v as buildLoraMirror, w as getLoraTriggers, x as getLoraInfo, y as getLoraAddedAt, z as lmCivitai } from "./schemaDrift-Cg39vs53.js";
2
- import { a as draftsDirForFile, c as isDraftMetaKey, f as findDefinedWorkflow, i as draftKeyForFile, m as scanCflowFiles, n as assembleLogChunks, o as listDraftsForFile, s as ENHANCE_KEY } from "./LogsSt-U1H0mP1m.js";
1
+ import { $ as stripAnsi, A as refreshLoraInfoCacheIfChanged, B as lmFilePath, C as getLoraTriggerWords, D as lorasMissingFromMirror, E as loraMirrorEntries, F as fetchLoraExampleImages, G as lmSha256, H as lmFolder, I as fetchLoraList, K as lmTags, L as fetchLoraPreviewBytes, M as writeLoraMirror, N as fetchLoraCivitai, P as fetchLoraDescription, Q as colorsAvailable, R as lmBaseModel, S as getLoraPreviewUrl, V as lmFileSize, W as lmNotes, X as loraPreviewMapFrom, Y as loraKey, Z as ansi, b as getLoraDisplayName, d as isPromptInput, dt as sha1HexOfString, et as extractErrorMessage, f as isLoraStrength, i as summarizeDrift, j as reloadLoraInfoCache, k as recordCivitaiMiss, l as isLoraLanes, lt as statelessRegex, m as getLoraKeyword, nt as bang, o as DEFAULT_IMAGE_EXTENSIONS, r as driftChanged, u as isLorasInput, v as buildLoraMirror, w as getLoraTriggers, x as getLoraInfo, y as getLoraAddedAt, z as lmCivitai } from "./schemaDrift-E95iTF7E.js";
2
+ import { a as draftsDirForFile, c as isDraftMetaKey, f as findDefinedWorkflow, i as draftKeyForFile, m as scanCflowFiles, n as assembleLogChunks, o as listDraftsForFile, s as ENHANCE_KEY } from "./LogsSt-CUeo843w.js";
3
3
  import { fileURLToPath, pathToFileURL } from "node:url";
4
4
  import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
5
5
  import { basename, dirname, extname, isAbsolute, join, resolve } from "pathe";
@@ -609,6 +609,63 @@ var TagSources = class {
609
609
  //#region src/cli/serve/favicon.ts
610
610
  const FAVICON_DATA_URI = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAAPoAAAD6AG1e1JrAAAKUklEQVR42u1aaWxU1xW2DWEJZCENNgaK8iNRU5UAAYKBWW1ImwbaoqiuQkrUVlRdlDZSGpqAcTKrFyAoJRCRKmpRidKA98Sm0MQhRClOs7CIggiTtniZN4sZe8AeL/Puvef23LeMnwePQdWwhTnS9XvP8zzvft/5znfPfXJWViYykYlMZCITmchEJjKRiUxc4eCcj8ExFkfOzQg+23huvL5pwFNKf8wYexmvZ2m/H6cpQlHFV5IYIXvtaMEh4+CM83/hIS9ZGSOUSvYNnXUNyC3iGgA2KuAZ7+NqvI3jZ6iKp3GsIYQsw+sZOmFJZIy5Ec0uRzufhOMHjMGnGnAUAAdtJALUqxgwOIYs7UBCViFptycTekNkXcv4eMzsL/Hap2Pkw0MQQbTBkj/UbvDj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WuPwwDxWx2CnBT14Lw58+7IGT/kGQaQqZM5UQNnLNw/4T/cJ44cGN6PQI3uTyM3wes1Vg9j3S6qGu7yqGTkKhq3WdvaKbmcu7uXDjpS6JCV+we0NgcQVgYWkA5pZICimrXw1DxTtRaDwaA18wDtjAsCQlGI0PPjozwH7++jnMekBZ6qweobIANXk6qb0iys3O1t9eE/AJErQH2zz+5ejAPmFGZndQEEBMeMTdmDApEOWBZaKAmLtBggUvIBi8XrklwNYiwOf3RMBV2wU73zsPcTLU8D21qxPuX9cGdqx5QSZ+JzF7z4HVG6EWl/9XaW13/09TyNZJWFHRNsXqkjZbPKE+++YYt3g7ccIBQQQ1aUQIEnDJQkLw3BmEpQ4/PFTqR2n7YfZz7XjeAYGonNDAX1su4ArTgWQpqiK2ivPY6ESiZkf7qusAvFEKSIK2/FjdHfcVYjuKkz5vq8SlUkwagSMAWRAiDNPsEhmVQBwFIVbF1ERtS9Di60+URPOpPrbwhQ6KpLJCQaoz8LnV3f7ANZX9qMtk8dD20+bwzbS7pOfMLv8RYVjWTQgAuzU0TI51jCRgD+EOyiYPkuLCFxi4muAKQkUp6AQ0Hu2nC51daHTBHqsr8OJKh3Tr9Qk+qX0uLh6aoDBLe3lHgd3d4UEgLWaPFLOWR3jhSwNclIoNX1tZUSXWcjyWdfECp8T2fNyDBknJ02/G+JySYH3xjrPT9O92OG6Q/yxRiEh6ISE2V49U+mYWlUmrcLkstTtbd1md/ibcwX2EajiEBnrMVBbBDs8vF3oCAyYkBZe6NQqRDj4u6wb9X4FsoQjVsFIA4HrZ8LHY1TUXbiXcUtHHbeWRTpvj7D1XvsO7qspw5NhsH4wVYB3KuwYNmAZw5UvS3bh8brW4gvvRKL/zlQKfSiEqCcaR/HnWzfWfZMX6snq1evtMZCITmchEJjKRiUxkIhM3ZfwPK9dyLD4coj4AAAAASUVORK5CYII=";
611
611
  //#endregion
612
+ //#region src/cli/serve/workflowTags.ts
613
+ /** display order: what the workflow makes first, then how it works, then free tags */
614
+ const MEDIA_BY_TYPE = {
615
+ IMAGE: "image",
616
+ AUDIO: "audio",
617
+ VIDEO: "video",
618
+ STRING: "text"
619
+ };
620
+ const MEDIA_ORDER = [
621
+ "image",
622
+ "audio",
623
+ "video",
624
+ "text"
625
+ ];
626
+ function workflowTags(p) {
627
+ const byId = new Map(p.nodes.map((n) => [n.id, n]));
628
+ const media = /* @__PURE__ */ new Set();
629
+ for (const node of p.nodes) {
630
+ if (!node.outputNode) continue;
631
+ for (const [producerId, ix] of node.links) {
632
+ const type = byId.get(producerId)?.outputTypes[ix];
633
+ const tag = type == null ? void 0 : MEDIA_BY_TYPE[type];
634
+ if (tag != null) media.add(tag);
635
+ }
636
+ }
637
+ const out = MEDIA_ORDER.filter((t) => media.has(t));
638
+ if (p.nodes.some((n) => /textgenerate/i.test(n.classType))) out.push("llm");
639
+ if (p.varKinds.includes("image")) out.push("edit");
640
+ for (const tag of p.extra ?? []) {
641
+ const t = tag.trim().toLowerCase();
642
+ if (t !== "" && !out.includes(t)) out.push(t);
643
+ }
644
+ return out;
645
+ }
646
+ //#endregion
647
+ //#region src/cli/serve/workspaceLabels.ts
648
+ function tilde(path, home) {
649
+ if (home === "" || home === "/") return path;
650
+ if (path === home) return "~";
651
+ return path.startsWith(`${home}/`) ? `~${path.slice(home.length)}` : path;
652
+ }
653
+ function workspaceLabels(p) {
654
+ const ws = p.workspace.replace(/\/+$/, "");
655
+ const root = p.root.replace(/\/+$/, "");
656
+ const rootLabel = root === ws ? "." : root.startsWith(`${ws}/`) ? root.slice(ws.length + 1) : tilde(root, p.home);
657
+ return {
658
+ workspace: {
659
+ path: ws,
660
+ label: tilde(ws, p.home)
661
+ },
662
+ root: {
663
+ path: root,
664
+ label: rootLabel
665
+ }
666
+ };
667
+ }
668
+ //#endregion
612
669
  //#region src/utils/stringMap.ts
613
670
  function stringMap(raw) {
614
671
  const out = {};
@@ -687,6 +744,29 @@ function writeServeSettings(next) {
687
744
  }, null, 2));
688
745
  }
689
746
  //#endregion
747
+ //#region src/cli/serve/web/state/draftTabs.ts
748
+ /** where the serve process keeps them, under .comfy-ts/: draft names are private, so this file
749
+ * must stay gitignored (tests/serve-tabs.test.ts runs git check-ignore on it) */
750
+ const SERVE_TABS_FILE = "serve-tabs.json";
751
+ const same = (a, b) => a.module === b.module && a.draft === b.draft;
752
+ /** a stored list, shape-checked, keeping only drafts that still exist */
753
+ function readTabs(raw, modules) {
754
+ if (!Array.isArray(raw)) return [];
755
+ const out = [];
756
+ for (const x of raw) {
757
+ if (x == null || typeof x !== "object") continue;
758
+ const o = x;
759
+ if (typeof o.module !== "string" || typeof o.draft !== "string") continue;
760
+ const t = {
761
+ module: o.module,
762
+ draft: o.draft
763
+ };
764
+ if (!modules.some((m) => m.module === t.module && m.drafts.includes(t.draft))) continue;
765
+ if (!out.some((y) => same(y, t))) out.push(t);
766
+ }
767
+ return out;
768
+ }
769
+ //#endregion
690
770
  //#region src/cli/serve/ServeApp.ts
691
771
  /** what serve will read off the disk and upload. Wider than the picker default: ComfyUI's
692
772
  * LoadImage takes bmp and tiff too, and a var declaring one of those must not be refused */
@@ -793,6 +873,12 @@ const CONTENT_TYPES = {
793
873
  ".gif": "image/gif",
794
874
  ".mp4": "video/mp4",
795
875
  ".webm": "video/webm",
876
+ ".flac": "audio/flac",
877
+ ".mp3": "audio/mpeg",
878
+ ".opus": "audio/ogg",
879
+ ".ogg": "audio/ogg",
880
+ ".wav": "audio/wav",
881
+ ".m4a": "audio/mp4",
796
882
  ".json": "application/json",
797
883
  ".txt": "text/plain"
798
884
  };
@@ -851,6 +937,7 @@ const USAGE = [
851
937
  "GET /hosts/<hostId>/ping — is that host answering right now (restart watch)",
852
938
  "GET /hosts/<hostId>/logs — the last lines of that host console",
853
939
  "GET /images/<promptId>/<ix> — an in-memory output (saving off), while the process lives",
940
+ "GET /audio/<promptId>/<ix> — the same for an in-memory audio output",
854
941
  "GET /outputs/<path> — generated files"
855
942
  ];
856
943
  /** content hash of the bundle, so the script URL CHANGES whenever the code does. no-store
@@ -892,7 +979,9 @@ var ServeApp = class {
892
979
  this.chains = /* @__PURE__ */ new Map();
893
980
  this.settingsCache = null;
894
981
  this.memoryImages = /* @__PURE__ */ new Map();
982
+ this.tagsByModule = /* @__PURE__ */ new Map();
895
983
  this.MEMORY_IMAGE_CAP = 60;
984
+ this.tabs = null;
896
985
  this.tagSources = new TagSources({
897
986
  cacheDir: () => join(comfyts.baseFolder, "cache", "tags"),
898
987
  fetchText: async (url) => {
@@ -934,7 +1023,7 @@ var ServeApp = class {
934
1023
  headers: NO_STORE
935
1024
  };
936
1025
  }
937
- if (segs.length === 0 || segs[0] === "drafts" && segs.length === 1) return this.replyIndex();
1026
+ if (segs.length === 0 || segs[0] === "drafts" && segs.length === 1) return await this.replyIndex();
938
1027
  if (segs[0] === "web" && segs[1] === "app.js" && segs.length === 2) return await this.replyWebJs();
939
1028
  if (segs[0] === "drafts" && segs.length === 3 && segs[1] != null && segs[2] != null) return this.replyDraft(segs[1], segs[2]);
940
1029
  if (segs[0] === "run" && segs.length === 2 && segs[1] != null) return this.replyRunStatus(segs[1]);
@@ -946,11 +1035,13 @@ var ServeApp = class {
946
1035
  if (segs[0] === "llm-configs" && segs.length === 1) return this.replyLlmConfigs();
947
1036
  if (segs[0] === "tags" && segs.length === 3 && segs[1] != null && segs[2] != null) return await this.replyTags(segs[1], segs[2], req.url);
948
1037
  if (segs[0] === "settings" && segs.length === 1) return this.replySettings();
1038
+ if (segs[0] === "tabs" && segs.length === 1) return this.replyTabs();
949
1039
  if (segs[0] === "hosts" && segs.length === 1) return this.replyHosts();
950
1040
  if (segs[0] === "hosts" && segs.length === 3 && segs[1] != null && segs[2] === "logs") return await this.replyHostLogs(segs[1]);
951
1041
  if (segs[0] === "hosts" && segs.length === 3 && segs[1] != null && segs[2] === "ping") return await this.replyHostPing(segs[1]);
952
1042
  if (segs[0] === "hosts" && segs.length === 3 && segs[1] != null && segs[2] === "drift") return await this.replyHostDrift(segs[1], req.url.includes("full=1"));
953
1043
  if (segs[0] === "images" && segs.length === 3 && segs[1] != null && segs[2] != null) return this.replyMemoryImage(`${segs[1]}/${segs[2]}`);
1044
+ if (segs[0] === "audio" && segs.length === 3 && segs[1] != null && segs[2] != null) return this.replyMemoryImage(`audio/${segs[1]}/${segs[2]}`);
954
1045
  if (segs[0] === "outputs") return this.replyOutput(segs.slice(1));
955
1046
  return json(404, {
956
1047
  error: `no route: GET ${path}`,
@@ -967,6 +1058,7 @@ var ServeApp = class {
967
1058
  if (req.method === "PUT" && segs[0] === "drafts" && segs.length === 3 && segs[1] != null && segs[2] != null) return await this.replySaveDraft(segs[1], segs[2], req);
968
1059
  if (req.method === "DELETE" && segs[0] === "drafts" && segs.length === 3 && segs[1] != null && segs[2] != null) return await this.replyDeleteDraft(segs[1], segs[2]);
969
1060
  if (req.method === "PUT" && segs[0] === "settings" && segs.length === 1) return this.replySaveSettings(req);
1061
+ if (req.method === "PUT" && segs[0] === "tabs" && segs.length === 1) return this.replySaveTabs(req);
970
1062
  if (req.method === "PUT" && segs[0] === "hosts" && segs.length === 2 && segs[1] != null) return this.replySetHost(segs[1], req);
971
1063
  if (req.method === "POST" && segs[0] === "hosts" && segs.length === 3 && segs[1] != null && segs[2] != null) return await this.replyHostAction(segs[1], segs[2]);
972
1064
  if (req.method === "POST" && segs[0] === "hosts" && segs.length === 4 && segs[1] != null && segs[2] === "lora-civitai" && segs[3] != null) return await this.replyLoraCivitaiFetch(segs[1], segs[3]);
@@ -1115,14 +1207,50 @@ var ServeApp = class {
1115
1207
  drafts: this.draftsFor(mod),
1116
1208
  routes: this.draftsFor(mod).map((d) => `POST /generate/${encodeURIComponent(mod.key)}/${encodeURIComponent(d)}`),
1117
1209
  vars,
1118
- previews: Object.keys(mod.dw.spec.previews ?? {})
1210
+ previews: Object.keys(mod.dw.spec.previews ?? {}),
1211
+ tags: this.tagsByModule.get(mod.key) ?? mod.dw.spec.tags ?? []
1119
1212
  };
1120
1213
  }
1121
- replyIndex() {
1214
+ async tagsFor(mod) {
1215
+ const known = this.tagsByModule.get(mod.key);
1216
+ if (known != null) return known;
1217
+ const extra = mod.dw.spec.tags ?? [];
1218
+ const varKinds = mod.dw.entries().map(([, varDef]) => varDef.kind);
1219
+ let tags;
1220
+ try {
1221
+ tags = workflowTags({
1222
+ nodes: (await mod.dw.build({ dry: true })).nodes.map((n) => ({
1223
+ id: n.uid,
1224
+ classType: n.json.class_type,
1225
+ outputNode: n.$schema.raw.output_node,
1226
+ outputTypes: n.$schema.outputs.map((o) => o.typeName),
1227
+ links: Object.values(n.json.inputs).flatMap((v) => Array.isArray(v) && v.length === 2 && typeof v[1] === "number" ? [[String(v[0]), v[1]]] : [])
1228
+ })),
1229
+ varKinds,
1230
+ extra
1231
+ });
1232
+ } catch (e) {
1233
+ console.error(`[serve] 🔴 tags for ${mod.key}: dry build failed, spec tags only: ${extractErrorMessage(e)}`);
1234
+ tags = workflowTags({
1235
+ nodes: [],
1236
+ varKinds,
1237
+ extra
1238
+ });
1239
+ }
1240
+ this.tagsByModule.set(mod.key, tags);
1241
+ return tags;
1242
+ }
1243
+ async replyIndex() {
1244
+ for (const m of this.modules) await this.tagsFor(m);
1122
1245
  return json(200, {
1123
1246
  server: "comfy-ts serve",
1124
1247
  usage: USAGE,
1125
1248
  workflows: this.modules.map((m) => this.describeModule(m)),
1249
+ ...this.opts.workspace == null ? {} : workspaceLabels({
1250
+ workspace: this.opts.workspace,
1251
+ root: this.opts.root ?? this.opts.workspace,
1252
+ home: process.env.HOME ?? ""
1253
+ }),
1126
1254
  ...this.opts.loadErrors != null && Object.keys(this.opts.loadErrors).length > 0 ? { loadErrors: this.opts.loadErrors } : {}
1127
1255
  });
1128
1256
  }
@@ -1575,7 +1703,7 @@ var ServeApp = class {
1575
1703
  }
1576
1704
  replyMemoryImage(key) {
1577
1705
  const hit = this.memoryImages.get(key);
1578
- if (hit == null) return json(404, { error: `no in-memory image '${key}' — it expired (only the last ${this.MEMORY_IMAGE_CAP} are kept) or the server restarted. Turn saving on to keep outputs.` });
1706
+ if (hit == null) return json(404, { error: `no in-memory output '${key}' — it expired (only the last ${this.MEMORY_IMAGE_CAP} are kept) or the server restarted. Turn saving on to keep outputs.` });
1579
1707
  return {
1580
1708
  status: 200,
1581
1709
  contentType: hit.contentType,
@@ -1639,6 +1767,52 @@ var ServeApp = class {
1639
1767
  effectivePrefix: Object.fromEntries(this.modules.map((m) => [m.key, this.savePrefixFor(m.key)]))
1640
1768
  });
1641
1769
  }
1770
+ tabsFile() {
1771
+ return join(comfyts.baseFolder, SERVE_TABS_FILE);
1772
+ }
1773
+ /** only drafts that still exist: a tab whose file was deleted elsewhere is dropped on read */
1774
+ liveTabs(raw) {
1775
+ return readTabs(raw, this.modules.map((m) => ({
1776
+ module: m.key,
1777
+ drafts: this.draftsFor(m)
1778
+ })));
1779
+ }
1780
+ replyTabs() {
1781
+ if (this.tabs == null) {
1782
+ const path = this.tabsFile();
1783
+ let raw = [];
1784
+ try {
1785
+ if (existsSync(path)) raw = JSON.parse(readFileSync(path, "utf8"));
1786
+ } catch (e) {
1787
+ console.error(`[serve] 🔴 open tabs unreadable (${path}), starting with none:`, e);
1788
+ }
1789
+ this.tabs = this.liveTabs(raw);
1790
+ }
1791
+ this.tabs = this.liveTabs(this.tabs);
1792
+ return json(200, { tabs: this.tabs });
1793
+ }
1794
+ replySaveTabs(req) {
1795
+ let parsed;
1796
+ try {
1797
+ parsed = JSON.parse(req.body ?? "");
1798
+ } catch (e) {
1799
+ return json(400, { error: `body is not valid json: ${extractErrorMessage(e)}` });
1800
+ }
1801
+ const raw = parsed != null && typeof parsed === "object" ? parsed.tabs : void 0;
1802
+ if (!Array.isArray(raw) || raw.length > 100) return json(400, { error: "expects { \"tabs\": [{ \"module\", \"draft\" }, …] }" });
1803
+ this.tabs = this.liveTabs(raw);
1804
+ try {
1805
+ mkdirSync(comfyts.baseFolder, { recursive: true });
1806
+ writeFileSync(this.tabsFile(), JSON.stringify(this.tabs, null, 2));
1807
+ } catch (e) {
1808
+ console.error(`[serve] 🔴 open tabs not saved to ${this.tabsFile()}:`, e);
1809
+ return json(200, {
1810
+ tabs: this.tabs,
1811
+ warning: `not saved: ${extractErrorMessage(e)}`
1812
+ });
1813
+ }
1814
+ return json(200, { tabs: this.tabs });
1815
+ }
1642
1816
  async replyTags(modKey, varName, url) {
1643
1817
  const mod = this.moduleByKey(modKey);
1644
1818
  if (mod == null) return json(404, { error: `unknown workflow '${modKey}'` });
@@ -1925,6 +2099,8 @@ var ServeApp = class {
1925
2099
  });
1926
2100
  }
1927
2101
  const produced = [`${execution.images.length} image(s)`];
2102
+ const audios = execution.audios ?? [];
2103
+ if (audios.length > 0) produced.push(`${audios.length} audio(s)`);
1928
2104
  if ((execution.texts ?? []).length > 0) produced.push(`${(execution.texts ?? []).length} text(s)`);
1929
2105
  console.log(`[serve] 🟢 ${mod.key}/${draft} done in ${(durationMs / 1e3).toFixed(1)}s · ${produced.join(" · ")}`);
1930
2106
  const memoryKeys = /* @__PURE__ */ new Map();
@@ -1934,6 +2110,13 @@ var ServeApp = class {
1934
2110
  this.rememberMemoryImage(key, img.buffer, img.filename);
1935
2111
  memoryKeys.set(ix, key);
1936
2112
  }
2113
+ const audioKeys = /* @__PURE__ */ new Map();
2114
+ for (const [ix, a] of audios.entries()) {
2115
+ if (a.absPath != null) continue;
2116
+ const key = `${execution.data.id}/${ix}`;
2117
+ this.rememberMemoryImage(`audio/${key}`, a.bytes, a.filename);
2118
+ audioKeys.set(ix, key);
2119
+ }
1937
2120
  const first = execution.images[0];
1938
2121
  if (req.accept?.includes("image/") && first != null) {
1939
2122
  if (first.absPath != null) return {
@@ -1964,6 +2147,12 @@ var ServeApp = class {
1964
2147
  filename: img.filename,
1965
2148
  url: img.absPath != null ? this.outputUrl(img.absPath) : memoryKeys.has(ix) ? `/images/${(memoryKeys.get(ix) ?? "").split("/").map((seg) => encodeURIComponent(seg)).join("/")}` : null,
1966
2149
  absPath: img.absPath
2150
+ })),
2151
+ audios: audios.map((a, ix) => ({
2152
+ filename: a.filename,
2153
+ mime: a.mime,
2154
+ url: a.absPath != null ? this.outputUrl(a.absPath) : audioKeys.has(ix) ? `/audio/${(audioKeys.get(ix) ?? "").split("/").map((seg) => encodeURIComponent(seg)).join("/")}` : null,
2155
+ absPath: a.absPath
1967
2156
  }))
1968
2157
  });
1969
2158
  }
@@ -2041,17 +2230,21 @@ var ServeApp = class {
2041
2230
  const seedVar = varDef;
2042
2231
  const stateKey = `${mod.key}/${draft}/${k}`;
2043
2232
  const draftValue = draftSeedValues.get(k) ?? seedVar.value;
2044
- if (!(k in payload)) {
2045
- if (seedVar.mode === "?") seedVar.randomize();
2046
- else if (seedVar.mode === "+" || seedVar.mode === "-") {
2047
- const prev = this.seedState.get(stateKey);
2048
- const ours = prev != null && (prev.draftBase === draftValue || prev.last === draftValue);
2049
- if (prev != null && ours) seedVar.set(prev.last + (seedVar.mode === "+" ? 1 : -1));
2050
- }
2051
- }
2052
- this.seedState.set(stateKey, {
2233
+ const prev = this.seedState.get(stateKey);
2234
+ const continues = !(k in payload) && (seedVar.mode === "+" || seedVar.mode === "-") && prev != null && (prev.draftBase === draftValue || prev.served.includes(draftValue));
2235
+ if (!(k in payload) && seedVar.mode === "?") seedVar.randomize();
2236
+ if (continues) {
2237
+ seedVar.set(prev.last + (seedVar.mode === "+" ? 1 : -1));
2238
+ const served = [...prev.served, seedVar.value].slice(-256);
2239
+ this.seedState.set(stateKey, {
2240
+ last: seedVar.value,
2241
+ draftBase: prev.draftBase,
2242
+ served
2243
+ });
2244
+ } else this.seedState.set(stateKey, {
2053
2245
  last: seedVar.value,
2054
- draftBase: draftValue
2246
+ draftBase: draftValue,
2247
+ served: [seedVar.value]
2055
2248
  });
2056
2249
  seeds[k] = seedVar.value;
2057
2250
  }
@@ -2114,6 +2307,68 @@ var ServeApp = class {
2114
2307
  }
2115
2308
  };
2116
2309
  //#endregion
2310
+ //#region src/cli/serve/byteRange.ts
2311
+ /** one range, the only kind media players send: `bytes=a-b`, `bytes=a-`, `bytes=-n` */
2312
+ function parseRange(header, size) {
2313
+ const m = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
2314
+ if (m == null) return null;
2315
+ const a = m[1] ?? "";
2316
+ const b = m[2] ?? "";
2317
+ if (a === "" && b === "") return null;
2318
+ if (a === "") {
2319
+ const n = Number(b);
2320
+ if (n === 0) return "unsatisfiable";
2321
+ return {
2322
+ start: Math.max(0, size - n),
2323
+ end: size - 1
2324
+ };
2325
+ }
2326
+ const start = Number(a);
2327
+ const end = b === "" ? size - 1 : Math.min(Number(b), size - 1);
2328
+ if (start >= size || start > end) return "unsatisfiable";
2329
+ return {
2330
+ start,
2331
+ end
2332
+ };
2333
+ }
2334
+ /** a whole 200 binary reply gets its length and `accept-ranges`; a range request gets 206 with
2335
+ * those bytes, or 416 past the end. Text replies and errors pass through untouched */
2336
+ function withByteRange(reply, req) {
2337
+ if (req.method !== "GET" || reply.status !== 200 || typeof reply.body === "string") return reply;
2338
+ const size = reply.body.length;
2339
+ const base = {
2340
+ ...reply.headers,
2341
+ "accept-ranges": "bytes"
2342
+ };
2343
+ const range = req.range == null ? null : parseRange(req.range, size);
2344
+ if (range == null) return {
2345
+ ...reply,
2346
+ headers: {
2347
+ ...base,
2348
+ "content-length": String(size)
2349
+ }
2350
+ };
2351
+ if (range === "unsatisfiable") return {
2352
+ status: 416,
2353
+ contentType: reply.contentType,
2354
+ body: /* @__PURE__ */ new Uint8Array(0),
2355
+ headers: {
2356
+ ...base,
2357
+ "content-range": `bytes */${size}`
2358
+ }
2359
+ };
2360
+ return {
2361
+ status: 206,
2362
+ contentType: reply.contentType,
2363
+ body: reply.body.subarray(range.start, range.end + 1),
2364
+ headers: {
2365
+ ...base,
2366
+ "content-range": `bytes ${range.start}-${range.end}/${size}`,
2367
+ "content-length": String(range.end - range.start + 1)
2368
+ }
2369
+ };
2370
+ }
2371
+ //#endregion
2117
2372
  //#region src/cli/serve/startupPrint.ts
2118
2373
  const RULE_WIDTH = 64;
2119
2374
  /** 100.64.0.0/10 is the CGNAT range tailscale hands out — worth naming, it is the one
@@ -2347,7 +2602,12 @@ function makeRequestListener(app) {
2347
2602
  url: req.url ?? "/",
2348
2603
  accept: req.headers.accept,
2349
2604
  body: Buffer.concat(chunks).toString("utf8")
2350
- }).then((reply) => {
2605
+ }).then((whole) => {
2606
+ const range = req.headers.range;
2607
+ const reply = withByteRange(whole, {
2608
+ method: req.method ?? "GET",
2609
+ range
2610
+ });
2351
2611
  res.writeHead(reply.status, {
2352
2612
  "content-type": reply.contentType,
2353
2613
  ...reply.headers,
@@ -2402,7 +2662,9 @@ async function runServe(args) {
2402
2662
  }
2403
2663
  const app = new ServeApp(modules, {
2404
2664
  loadErrors,
2405
- webJs: loadOrBuildWebJs
2665
+ webJs: loadOrBuildWebJs,
2666
+ workspace: typeof comfyts === "undefined" ? process.cwd() : comfyts.rootPath,
2667
+ root: statSync(target).isDirectory() ? target : dirname(target)
2406
2668
  });
2407
2669
  printStartup(app, parsed.bind, parsed.port);
2408
2670
  const server = createServer(makeRequestListener(app));
@@ -2451,4 +2713,4 @@ function printStartup(app, bind, port) {
2451
2713
  //#endregion
2452
2714
  export { runServe };
2453
2715
 
2454
- //# sourceMappingURL=run-serve-BeAznay5.js.map
2716
+ //# sourceMappingURL=run-serve-DlRBv_Nk.js.map