@syncshio/kano-plugin-comfyui 0.0.0-stage → 2.1.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.
package/dist/entry.js ADDED
@@ -0,0 +1,4497 @@
1
+ import { BreadcrumbBar as e, Button as t, CapacityMeter as n, ConfirmDialog as r, CopyButton as i, DataList as a, DataRow as o, Dialog as s, Disclosure as c, EmptyState as l, FilterBar as u, FormField as d, InputText as f, InspectorDrawer as p, KanoIcon as m, PageShell as h, SearchInput as g, SegmentedControl as _, Select as v, SettingsSection as y, SkeletonCard as b, ToggleSwitch as x, createLaunchCheck as S, getPythonProbeDetails as C, getRuntimePackageVersion as w, resolvePath as T, selectLaunchCapability as E } from "@syncshio/kano-plugin-sdk/host";
2
+ import { Fragment as D, computed as O, createBlock as k, createCommentVNode as A, createElementBlock as j, createElementVNode as M, createSlots as N, createTextVNode as ee, createVNode as P, defineComponent as F, h as I, isRef as L, nextTick as te, normalizeClass as R, onBeforeUnmount as ne, onMounted as z, onUnmounted as re, openBlock as B, ref as V, renderList as H, resolveComponent as ie, shallowRef as ae, toDisplayString as U, unref as W, useId as G, vShow as oe, watch as K, withCtx as q, withDirectives as se, withKeys as ce, withModifiers as le } from "vue";
3
+ //#region ../kano-plugin-sdk/src/contracts/launch.ts
4
+ var J = {
5
+ RefreshHostCapabilities: "refresh-host-capabilities",
6
+ OpenPythonSettings: "open-python-settings",
7
+ OpenLaunchSettings: "open-launch-settings",
8
+ OpenVersionManagement: "open-version-management",
9
+ OpenExtensionManagement: "open-extension-management",
10
+ ApplyLaunchParam: "apply-launch-param",
11
+ ApplyBackendSelection: "apply-backend-selection",
12
+ OpenUrl: "open-url"
13
+ };
14
+ //#endregion
15
+ //#region ../kano-plugin-sdk/src/helpers/define-plugin.ts
16
+ function ue(e) {
17
+ return e;
18
+ }
19
+ //#endregion
20
+ //#region ../kano-plugin-sdk/src/helpers/params.ts
21
+ function de(e) {
22
+ let t = new Set(e.ownedArgs), n = (e) => {
23
+ for (let n of Array.isArray(e) ? e : e ? [e] : []) typeof n == "string" ? t.add(n) : (t.add(n.arg), n.falseArg && t.add(n.falseArg));
24
+ };
25
+ for (let r of e.params ?? []) {
26
+ for (let e of r.ownedArgs ?? []) t.add(e);
27
+ typeof r.cli != "function" && n(r.cli);
28
+ for (let e of r.options ?? []) n(e.cli);
29
+ }
30
+ return [...t];
31
+ }
32
+ //#endregion
33
+ //#region packages/plugins/comfyui/omnixpu.ts
34
+ function fe({ os: e, selection: t, params: n }) {
35
+ return e === "windows" && t?.backend === "level-zero" && t.vendor === "intel" && t.selectable && /\bArc\b/i.test(t.name) && n.vramMode !== "cpu";
36
+ }
37
+ function pe(e) {
38
+ return fe({
39
+ os: e.host.os.name,
40
+ selection: E(e),
41
+ params: e.params
42
+ }) && (e.params.omniXpu ?? !0) === !0;
43
+ }
44
+ var me = [{
45
+ id: "omniXpu",
46
+ label: "Omni XPU 整合包",
47
+ description: "Intel Arc 默认优先使用;需要已准备好的 Windows Omni 环境,关闭后使用普通 XPU",
48
+ type: "boolean",
49
+ defaultFn: fe,
50
+ group: "performance",
51
+ audience: "basic",
52
+ showWhen: {
53
+ param: "omniXpuAvailable",
54
+ equals: !0
55
+ }
56
+ }, {
57
+ id: "omniSolAttention",
58
+ label: "Sol-Attn",
59
+ description: "允许工作流中的 Patch Sol-Attn 节点使用内核提供的稀疏注意力",
60
+ type: "boolean",
61
+ default: !0,
62
+ group: "precision",
63
+ audience: "advanced",
64
+ showWhen: {
65
+ param: "omniXpu",
66
+ equals: !0
67
+ }
68
+ }], he = [{
69
+ id: "omnixpu-dynamic-vram",
70
+ params: [
71
+ "omniXpu",
72
+ "dynamicVram",
73
+ "vramMode"
74
+ ],
75
+ message: "Omni XPU 的 AIMDO provider 需要动态显存,请使用自动显存模式并开启动态显存",
76
+ when: { and: [{
77
+ param: "omniXpu",
78
+ equals: !0
79
+ }, { or: [{
80
+ param: "dynamicVram",
81
+ equals: "disabled"
82
+ }, { not: {
83
+ param: "vramMode",
84
+ equals: "normal"
85
+ } }] }] }
86
+ }, {
87
+ id: "omnixpu-attention",
88
+ params: ["omniXpu", "attention"],
89
+ message: "启用 Omni XPU 时请将通用注意力设为自动,由 Omni 使用 CUTE 路由",
90
+ when: { and: [{
91
+ param: "omniXpu",
92
+ equals: !0
93
+ }, { not: {
94
+ param: "attention",
95
+ equals: "auto"
96
+ } }] }
97
+ }];
98
+ function ge(e) {
99
+ let t = fe(e), n = { omniXpuAvailable: t };
100
+ return e.selection?.backend === "cpu" && (n.vramMode = "cpu"), t ? (e.getParam("omniXpu") && (e.getParam("dynamicVram") === "auto" && (n.dynamicVram = "enabled"), e.getParam("reserveVram") === "" && (n.reserveVram = 4)), n) : {
101
+ ...n,
102
+ omniXpu: !1
103
+ };
104
+ }
105
+ function _e(e) {
106
+ if (!e.getParam("omniXpu")) return {};
107
+ let t = e.runtime.python?.path || e.app.configuredPythonPath || "", n = e.resolvePath(t).replace(/\\/g, "/").replace(/\/[^/]+$/, ""), r = n.replace(/\/Scripts$/i, ""), i = Object.entries(e.app.configuredEnv ?? {}).find(([e]) => e.toUpperCase() === "PATH")?.[1], a = String(e.runtime.metadata?.path_env ?? "");
108
+ return {
109
+ PYTHONHOME: "",
110
+ PYTHONPATH: "",
111
+ PATH: [
112
+ n,
113
+ `${r}/Scripts`,
114
+ `${r}/Library/bin`,
115
+ `${r}/Lib/site-packages/torch/lib`,
116
+ i ?? a
117
+ ].filter(Boolean).join(";"),
118
+ OMNIXPU_ENABLE: "1",
119
+ OMNIXPU_PROVIDER_BOOTSTRAP: "required",
120
+ OMNI_IMAGE_XPU_TARGET: "bmg",
121
+ OMNI_ATTN_BACKEND: "cute",
122
+ SOL_ATTN_XPU_EXPERIMENTAL: e.getParam("omniSolAttention") ? "1" : "0",
123
+ OMNIXPU_INTERPOLATE_FIX: "0",
124
+ KANO_COMFYUI_OMNIXPU_NODE: e.resolvePath(`${e.getParam("baseDirectory") || e.app.path}/custom_nodes/ComfyUI-OmniXPU`)
125
+ };
126
+ }
127
+ //#endregion
128
+ //#region packages/plugins/comfyui/shared-models.ts
129
+ var ve = ".kano/extra_model_paths.yaml", ye = {
130
+ checkpoints: ["checkpoints"],
131
+ loras: ["loras"],
132
+ vae: ["vae"],
133
+ embeddings: ["embeddings"],
134
+ controlnet: ["controlnet", "t2i_adapter"],
135
+ text_encoders: ["text_encoders", "clip"],
136
+ clip_vision: ["clip_vision"],
137
+ upscale_models: ["upscale_models"],
138
+ diffusion_models: ["diffusion_models", "unet"],
139
+ diffusers: ["diffusers"],
140
+ ipadapter: ["ipadapter"],
141
+ style_models: ["style_models"],
142
+ latent_upscale_models: ["latent_upscale_models"],
143
+ audio_encoders: ["audio_encoders"]
144
+ }, be = {
145
+ checkpoints: ["models/Stable-diffusion"],
146
+ loras: ["models/Lora"],
147
+ vae: ["models/VAE"],
148
+ embeddings: ["embeddings"],
149
+ controlnet: ["extensions/sd-webui-controlnet/models", "models/ControlNet"],
150
+ upscale_models: [
151
+ "models/ESRGAN",
152
+ "models/RealESRGAN",
153
+ "models/SwinIR"
154
+ ]
155
+ };
156
+ function xe(e) {
157
+ return e.layout === "sd-webui" ? be : ye;
158
+ }
159
+ function Se(e) {
160
+ let t = e.sharedModelRoots;
161
+ return Array.isArray(t) ? t.filter((e) => e && typeof e.path == "string" && !!e.path && typeof e.label == "string" && (e.layout === "comfyui" || e.layout === "sd-webui")) : [];
162
+ }
163
+ function Ce(e, t) {
164
+ let n = Object.keys(ye).find((e) => ye[e].includes(t)) ?? t;
165
+ return [...new Set(Se(e.params).flatMap((e) => (t ? xe(e)[n] ?? [] : Object.values(xe(e)).flat()).map((t) => T(e.path, t))))];
166
+ }
167
+ function we(e) {
168
+ return e.length ? e.map((e, t) => [
169
+ `kano_${t + 1}:`,
170
+ ` base_path: ${JSON.stringify(e.path)}`,
171
+ ...Object.entries(xe(e)).map(([e, t]) => ` ${e}: ${JSON.stringify(t.join("\n"))}`)
172
+ ].join("\n")).join("\n") + "\n" : "{}\n";
173
+ }
174
+ async function Te(e, t, n) {
175
+ await e.mkdir(T(t, ".kano"));
176
+ let r = T(t, ve), i = we(n);
177
+ if (await e.exists(r)) {
178
+ let t = await e.readTextFile(r);
179
+ t.content !== i && await e.saveTextFile(r, i, t.version);
180
+ } else await e.writeFile(r, i);
181
+ }
182
+ //#endregion
183
+ //#region packages/plugins/comfyui/bindings.ts
184
+ var Ee = [
185
+ "--cuda-device",
186
+ "--directml",
187
+ "--oneapi-device-selector",
188
+ "--windows-standalone-build"
189
+ ];
190
+ function De(e) {
191
+ let t = [], n = _e(e);
192
+ if (Se(e.params).length && t.push({
193
+ arg: "--extra-model-paths-config",
194
+ values: [{ literal: e.resolvePath(ve) }]
195
+ }), e.getParam("omniXpu") && t.push({
196
+ arg: "--windows-standalone-build",
197
+ format: "flag"
198
+ }), e.getParam("vramMode") === "cpu") return {
199
+ args: t,
200
+ env: n
201
+ };
202
+ let r = e.selection?.backend;
203
+ if (r === "cuda" || r === "hip" || r === "zluda") {
204
+ let r = e.getParam("cudaDevices"), i = e.getParam("defaultDevice");
205
+ if (r === "all") t.push({
206
+ arg: "--cuda-device",
207
+ values: [{ literal: "all" }]
208
+ });
209
+ else if (r || i === "") {
210
+ let i = r || String(e.selection?.gpuOrdinal ?? 0);
211
+ t.push({
212
+ arg: "--cuda-device",
213
+ values: [{ literal: i }]
214
+ }), n.CUDA_VISIBLE_DEVICES = n.HIP_VISIBLE_DEVICES = i;
215
+ } else {
216
+ let e = Array.from({ length: 32 }, (e, t) => t).filter((e) => e !== Number(i));
217
+ e.unshift(Number(i)), n.CUDA_VISIBLE_DEVICES = n.HIP_VISIBLE_DEVICES = e.join(",");
218
+ }
219
+ } else if (r === "directml") t.push({
220
+ arg: "--directml",
221
+ values: [{ literal: e.selection?.gpuOrdinal ?? -1 }]
222
+ });
223
+ else if (r === "level-zero") {
224
+ let r = e.getParam("oneapiDeviceSelector") || `level_zero:${e.selection?.gpuOrdinal ?? 0}`;
225
+ t.push({
226
+ arg: "--oneapi-device-selector",
227
+ values: [{ literal: r }]
228
+ }), n.ONEAPI_DEVICE_SELECTOR = r;
229
+ }
230
+ return {
231
+ args: t,
232
+ env: n
233
+ };
234
+ }
235
+ //#endregion
236
+ //#region packages/plugins/comfyui/types.ts
237
+ var Y = /* @__PURE__ */ function(e) {
238
+ return e.Normal = "normal", e.Low = "low", e.High = "high", e.NoVram = "novram", e.GpuOnly = "gpu-only", e.CPU = "cpu", e;
239
+ }({}), Oe = /* @__PURE__ */ function(e) {
240
+ return e.Auto = "auto", e.FP16 = "fp16", e.FP32 = "fp32", e.BF16 = "bf16", e;
241
+ }({}), ke = /* @__PURE__ */ function(e) {
242
+ return e.Auto = "auto", e.FP32 = "fp32", e.FP64 = "fp64", e.FP16 = "fp16", e.BF16 = "bf16", e.FP8E4M3FN = "fp8_e4m3fn", e.FP8E5M2 = "fp8_e5m2", e.FP8E8M0FNU = "fp8_e8m0fnu", e;
243
+ }({}), Ae = /* @__PURE__ */ function(e) {
244
+ return e.Auto = "auto", e.Latent2RGB = "latent2rgb", e.TAESD = "taesd", e.None = "none", e;
245
+ }({}), je = [
246
+ {
247
+ id: "general",
248
+ label: "常规设置",
249
+ icon: "i-lucide-settings-2",
250
+ order: 0
251
+ },
252
+ {
253
+ id: "network",
254
+ label: "网络设置",
255
+ icon: "i-lucide-globe",
256
+ order: 1
257
+ },
258
+ {
259
+ id: "performance",
260
+ label: "显存与性能",
261
+ icon: "i-lucide-gauge",
262
+ order: 2,
263
+ collapsed: !0
264
+ },
265
+ {
266
+ id: "precision",
267
+ label: "精度与注意力",
268
+ icon: "i-lucide-sliders-horizontal",
269
+ order: 3,
270
+ collapsed: !0
271
+ },
272
+ {
273
+ id: "cache",
274
+ label: "节点缓存",
275
+ icon: "i-lucide-database",
276
+ order: 4,
277
+ collapsed: !0
278
+ },
279
+ {
280
+ id: "paths",
281
+ label: "路径设置",
282
+ icon: "i-lucide-folder",
283
+ order: 5,
284
+ collapsed: !0
285
+ },
286
+ {
287
+ id: "nodes",
288
+ label: "节点与管理器",
289
+ icon: "i-lucide-puzzle",
290
+ order: 6,
291
+ collapsed: !0
292
+ },
293
+ {
294
+ id: "advanced",
295
+ label: "高级选项",
296
+ icon: "i-lucide-wrench",
297
+ order: 7,
298
+ collapsed: !0
299
+ }
300
+ ];
301
+ function X(e, t, n, r, i) {
302
+ return {
303
+ id: e,
304
+ label: t,
305
+ description: n,
306
+ group: r,
307
+ type: "boolean",
308
+ default: !1,
309
+ audience: "advanced",
310
+ cli: i
311
+ };
312
+ }
313
+ function Z(e, t, n, r, i, a = {}) {
314
+ return {
315
+ id: e,
316
+ label: t,
317
+ description: n,
318
+ group: r,
319
+ type: "string",
320
+ default: "",
321
+ audience: "advanced",
322
+ cli: {
323
+ arg: i,
324
+ format: "value",
325
+ when: "changed"
326
+ },
327
+ ...a
328
+ };
329
+ }
330
+ function Me(e, t, n, r, i, a, o, s = 1) {
331
+ return Z(e, t, n, r, i, {
332
+ type: "number",
333
+ default: a,
334
+ min: o,
335
+ step: s,
336
+ integer: s === 1,
337
+ optional: a === "",
338
+ cli: {
339
+ arg: i,
340
+ when: "changed"
341
+ }
342
+ });
343
+ }
344
+ function Ne(e, t, n, r, i, a = "auto") {
345
+ return {
346
+ id: e,
347
+ label: t,
348
+ description: n,
349
+ group: r,
350
+ type: "select",
351
+ default: a,
352
+ audience: "advanced",
353
+ options: i.map(([e, t, n]) => ({
354
+ value: e,
355
+ label: t,
356
+ cli: n
357
+ }))
358
+ };
359
+ }
360
+ function Pe(e, t, n, r, i, a, o) {
361
+ return Ne(e, t, n, r, [
362
+ ["auto", "自动"],
363
+ [
364
+ "enabled",
365
+ "开启",
366
+ o ? {
367
+ arg: i,
368
+ format: "values",
369
+ values: o
370
+ } : i
371
+ ],
372
+ [
373
+ "disabled",
374
+ "关闭",
375
+ a
376
+ ]
377
+ ]);
378
+ }
379
+ function Fe(e) {
380
+ return String(e ?? "").split(/\r?\n/).map((e) => e.trim()).filter(Boolean);
381
+ }
382
+ function Ie(e, t, n, r, i, a = !1) {
383
+ return Z(e, t, n, r, i, {
384
+ type: "text",
385
+ cli: {
386
+ arg: i,
387
+ format: a ? "repeat" : "values",
388
+ split: "lines"
389
+ }
390
+ });
391
+ }
392
+ var Le = [
393
+ "DEBUG",
394
+ "DETAIL",
395
+ "INFO",
396
+ "WARNING",
397
+ "ERROR",
398
+ "CRITICAL"
399
+ ].map((e) => ({
400
+ label: e,
401
+ value: e
402
+ })), Re = [
403
+ ...me,
404
+ Z("previewMethod", "预览方法", "采样节点的默认预览方式;ComfyUI 默认不生成预览", "general", "--preview-method", {
405
+ type: "select",
406
+ default: Ae.None,
407
+ options: Object.values(Ae).map((e) => ({
408
+ value: e,
409
+ label: {
410
+ none: "禁用",
411
+ auto: "自动",
412
+ latent2rgb: "Latent2RGB",
413
+ taesd: "TAESD"
414
+ }[e]
415
+ })),
416
+ audience: "basic"
417
+ }),
418
+ Me("previewSize", "预览尺寸上限(像素)", "", "general", "--preview-size", 512, 1),
419
+ {
420
+ ...X("autoLaunch", "启动时打开浏览器", "", "general", "--auto-launch"),
421
+ audience: "basic",
422
+ cli: {
423
+ arg: "--auto-launch",
424
+ format: "flag",
425
+ falseArg: "--disable-auto-launch",
426
+ when: "always"
427
+ }
428
+ },
429
+ X("multiUser", "多用户存储", "为不同用户分别保存设置与工作流", "general", "--multi-user"),
430
+ X("disableMetadata", "禁用输出元数据", "不在生成文件中保存提示词与工作流元数据", "general", "--disable-metadata"),
431
+ {
432
+ ...Me("port", "监听端口", "", "network", "--port", 8188, 1),
433
+ type: "port",
434
+ max: 65535,
435
+ audience: "basic"
436
+ },
437
+ Z("listen", "监听地址", "支持逗号分隔的多个 IP;0.0.0.0,:: 监听所有 IPv4 和 IPv6 地址", "network", "--listen", {
438
+ default: "127.0.0.1",
439
+ required: !0,
440
+ placeholder: "127.0.0.1",
441
+ validate: (e) => typeof e == "string" && e.split(",").every((e) => e.trim()) ? null : "请填写监听地址,多个地址用逗号分隔",
442
+ cli: {
443
+ arg: "--listen",
444
+ split: "comma",
445
+ join: ",",
446
+ when: "changed"
447
+ }
448
+ }),
449
+ Z("enableCorsHeader", "允许跨域来源", "留空不启用 CORS;* 允许所有来源", "network", "--enable-cors-header", { placeholder: "*" }),
450
+ Me("maxUploadSize", "上传大小上限(MB)", "", "network", "--max-upload-size", 100, .001, .1),
451
+ Z("tlsKeyfile", "TLS 私钥", "启用 HTTPS 时需同时配置证书和私钥文件", "network", "--tls-keyfile"),
452
+ Z("tlsCertfile", "TLS 证书", "与 TLS 私钥配套的证书文件", "network", "--tls-certfile"),
453
+ X("enableCompressResponseBody", "压缩 HTTP 响应", "", "network", "--enable-compress-response-body"),
454
+ Z("comfyApiBase", "Comfy API 地址", "API 节点的服务地址,可填写本机、局域网或代理地址", "network", "--comfy-api-base", {
455
+ default: "https://api.comfy.org",
456
+ required: !0,
457
+ validate: (e) => {
458
+ try {
459
+ return ["http:", "https:"].includes(new URL(String(e)).protocol) ? null : "请输入 HTTP 或 HTTPS 地址";
460
+ } catch {
461
+ return "请输入有效的 HTTP 或 HTTPS 地址";
462
+ }
463
+ }
464
+ }),
465
+ {
466
+ ...Ne("vramMode", "显存模式", "自动模式由 ComfyUI 管理;低显存在动态显存启用时无效", "performance", [
467
+ [Y.Normal, "自动"],
468
+ [
469
+ Y.Low,
470
+ "低显存",
471
+ "--lowvram"
472
+ ],
473
+ [
474
+ Y.NoVram,
475
+ "极低显存",
476
+ "--novram"
477
+ ],
478
+ [
479
+ Y.High,
480
+ "保留模型在显存",
481
+ "--highvram"
482
+ ],
483
+ [
484
+ Y.GpuOnly,
485
+ "全部使用 GPU",
486
+ "--gpu-only"
487
+ ],
488
+ [
489
+ Y.CPU,
490
+ "全部使用 CPU",
491
+ "--cpu"
492
+ ]
493
+ ], Y.Normal),
494
+ audience: "basic"
495
+ },
496
+ Pe("dynamicVram", "动态显存", "自动按设备与 PyTorch 支持情况启用;关闭后使用估算式模型加载", "performance", "--enable-dynamic-vram", "--disable-dynamic-vram"),
497
+ Me("reserveVram", "预留显存(GB)", "为系统和其他软件预留;留空由 ComfyUI 决定", "performance", "--reserve-vram", "", 0, .1),
498
+ Me("vramHeadroom", "动态显存额外余量(GB)", "在默认余量之外保持空闲,也计入其他应用占用", "performance", "--vram-headroom", 0, 0, .1),
499
+ X("disableNvmlPressure", "禁用 NVML 压力检测", "动态显存使用 CUDA 查询内存压力", "performance", "--disable-nvml-pressure"),
500
+ Pe("asyncOffload", "异步权重卸载", "NVIDIA 和 AMD 默认启用;可显式开启或关闭", "performance", "--async-offload", "--disable-async-offload", [{ param: "offloadStreams" }]),
501
+ {
502
+ ...Me("offloadStreams", "卸载流数量", "异步卸载的并发流数", "performance", "--async-offload", 2, 1),
503
+ showWhen: {
504
+ param: "asyncOffload",
505
+ equals: "enabled"
506
+ },
507
+ cli: void 0
508
+ },
509
+ Pe("cudaMalloc", "CUDA 内存分配器", "自动遵循 ComfyUI 的 cudaMallocAsync 决策", "performance", "--cuda-malloc", "--disable-cuda-malloc"),
510
+ X("disableSmartMemory", "积极卸载模型", "尽可能将模型卸载到系统内存", "performance", "--disable-smart-memory"),
511
+ X("disablePinnedMemory", "禁用锁页内存", "关闭 pinned memory", "performance", "--disable-pinned-memory"),
512
+ X("forceNonBlocking", "强制非阻塞传输", "可能改善部分非 NVIDIA 设备的性能,也可能影响工作流", "performance", "--force-non-blocking"),
513
+ X("fastDisk", "优先使用快速磁盘", "动态加载和卸载时优先使用磁盘而非未锁页内存,适合快速 NVMe", "performance", "--fast-disk"),
514
+ X("mmapTorchFiles", "映射 Torch 模型文件", "加载 ckpt / pt 文件时使用 mmap", "performance", "--mmap-torch-files"),
515
+ X("disableMmap", "禁用 safetensors 映射", "加载 safetensors 时不使用 mmap", "performance", "--disable-mmap"),
516
+ X("disableCudaGraphs", "禁用 CUDA Graphs", "关闭模型编译器的 CUDA Graphs 子功能", "performance", "--disable-cuda-graphs"),
517
+ X("disableComfyCompiler", "禁用模型编译器", "关闭 Comfy 模型编译器,同时关闭 CUDA Graphs", "performance", "--disable-comfy-compiler"),
518
+ X("deterministic", "确定性算法", "尽可能使用较慢的确定性算法,仍不保证所有图像完全一致", "performance", "--deterministic"),
519
+ Z("fast", "实验性优化", "空白关闭;all 开启全部,或以空格分隔 fp16_accumulation、fp8_matrix_mult、cublas_ops、autotune", "performance", "--fast", {
520
+ audience: "expert",
521
+ ownedArgs: ["--fast"],
522
+ cli: (e) => String(e).trim() ? String(e).trim() === "all" ? ["--fast"] : ["--fast", ...String(e).trim().split(/\s+/)] : [],
523
+ validate: (e) => String(e).trim() === "all" || String(e).trim().split(/\s+/).every((e) => [
524
+ "",
525
+ "fp16_accumulation",
526
+ "fp8_matrix_mult",
527
+ "cublas_ops",
528
+ "autotune"
529
+ ].includes(e)) ? null : "请填写 all 或列出的优化名称"
530
+ }),
531
+ Pe("tritonBackend", "Triton 后端", "控制 comfy-kitchen 的 Triton 后端,默认关闭", "performance", "--enable-triton-backend", "--disable-triton-backend"),
532
+ Ne("forcePrecision", "全局精度", "强制 FP16 同时将扩散模型设为 FP16", "precision", [
533
+ ["auto", "自动"],
534
+ [
535
+ "fp32",
536
+ "FP32",
537
+ "--force-fp32"
538
+ ],
539
+ [
540
+ "fp16",
541
+ "FP16",
542
+ "--force-fp16"
543
+ ]
544
+ ]),
545
+ Ne("unetPrecision", "扩散模型精度", "设置扩散模型的计算精度或 FP8 权重存储格式", "precision", Object.values(ke).map((e) => [
546
+ e,
547
+ e === "auto" ? "自动" : e.toUpperCase(),
548
+ e === "auto" ? void 0 : `--${e}-unet`
549
+ ])),
550
+ Ne("vaePrecision", "VAE 精度", "FP16 可能产生黑图,可改用 FP32 或 BF16", "precision", Object.values(Oe).map((e) => [
551
+ e,
552
+ e === "auto" ? "自动" : e.toUpperCase(),
553
+ e === "auto" ? void 0 : `--${e}-vae`
554
+ ])),
555
+ Ne("textEncoderPrecision", "文本编码器权重精度", "", "precision", [
556
+ "auto",
557
+ "fp16",
558
+ "fp32",
559
+ "bf16",
560
+ "fp8_e4m3fn",
561
+ "fp8_e5m2"
562
+ ].map((e) => [
563
+ e,
564
+ e === "auto" ? "自动" : e.toUpperCase(),
565
+ e === "auto" ? void 0 : `--${e}-text-enc`
566
+ ])),
567
+ X("cpuVae", "在 CPU 上运行 VAE", "", "precision", "--cpu-vae"),
568
+ X("fp16Intermediates", "FP16 中间张量", "实验性:节点之间使用 FP16 中间张量", "precision", "--fp16-intermediates"),
569
+ X("forceChannelsLast", "Channels Last 格式", "", "precision", "--force-channels-last"),
570
+ X("supportsFp8Compute", "强制 FP8 计算支持", "让 ComfyUI 假定设备支持 FP8 计算,仅用于已确认兼容的设备", "precision", "--supports-fp8-compute"),
571
+ Ne("attention", "注意力实现", "Sage / Flash 需要对应 Python 包;split / quad 在 xformers 启用时会被忽略", "precision", [
572
+ ["auto", "自动"],
573
+ [
574
+ "pytorch",
575
+ "PyTorch",
576
+ "--use-pytorch-cross-attention"
577
+ ],
578
+ [
579
+ "split",
580
+ "Split",
581
+ "--use-split-cross-attention"
582
+ ],
583
+ [
584
+ "quad",
585
+ "Sub-quadratic",
586
+ "--use-quad-cross-attention"
587
+ ],
588
+ [
589
+ "sage",
590
+ "SageAttention",
591
+ "--use-sage-attention"
592
+ ],
593
+ [
594
+ "flash",
595
+ "FlashAttention",
596
+ "--use-flash-attention"
597
+ ],
598
+ [
599
+ "ck",
600
+ "Comfy Kitchen",
601
+ "--use-ck-attention"
602
+ ]
603
+ ]),
604
+ X("disableXformers", "禁用 xformers", "", "precision", "--disable-xformers"),
605
+ Pe("attentionUpcast", "注意力升精度", "自动由 ComfyUI 决定;黑图时可尝试开启", "precision", "--force-upcast-attention", "--dont-upcast-attention"),
606
+ Ne("cacheMode", "缓存模式", "默认按系统 RAM 压力缓存;LRU 可能使用更多 RAM / VRAM", "cache", [
607
+ [
608
+ "ram",
609
+ "RAM 压力缓存",
610
+ {
611
+ arg: "--cache-ram",
612
+ format: "values",
613
+ values: [{
614
+ param: "cacheRam",
615
+ optional: !0
616
+ }, {
617
+ param: "cacheRamInactive",
618
+ optional: !0
619
+ }]
620
+ }
621
+ ],
622
+ [
623
+ "classic",
624
+ "经典缓存",
625
+ "--cache-classic"
626
+ ],
627
+ [
628
+ "lru",
629
+ "LRU 缓存",
630
+ {
631
+ arg: "--cache-lru",
632
+ values: [{ param: "cacheLru" }]
633
+ }
634
+ ],
635
+ [
636
+ "none",
637
+ "禁用缓存",
638
+ "--cache-none"
639
+ ],
640
+ [
641
+ "high-ram",
642
+ "高 RAM 模式",
643
+ "--high-ram"
644
+ ]
645
+ ], "ram"),
646
+ {
647
+ ...Me("cacheRam", "活跃缓存 RAM 余量(GB)", "留空按总 RAM 的 10%,最低 2 GB、最高 10 GB", "cache", "--cache-ram", "", 0, .1),
648
+ showWhen: {
649
+ param: "cacheMode",
650
+ equals: "ram"
651
+ },
652
+ cli: void 0
653
+ },
654
+ {
655
+ ...Me("cacheRamInactive", "非活跃缓存 RAM 余量(GB)", "留空按总 RAM,最高 128 GB", "cache", "--cache-ram", "", 0, .1),
656
+ showWhen: {
657
+ param: "cacheMode",
658
+ equals: "ram"
659
+ },
660
+ cli: void 0
661
+ },
662
+ {
663
+ ...Me("cacheLru", "LRU 节点结果数量", "", "cache", "--cache-lru", 10, 1),
664
+ showWhen: {
665
+ param: "cacheMode",
666
+ equals: "lru"
667
+ },
668
+ cli: void 0
669
+ },
670
+ ...[
671
+ [
672
+ "baseDirectory",
673
+ "基础目录",
674
+ "模型、custom_nodes、输入、输出、临时和用户目录的基础路径",
675
+ "--base-directory"
676
+ ],
677
+ [
678
+ "outputDirectory",
679
+ "输出目录",
680
+ "生成文件的保存目录,覆盖基础目录",
681
+ "--output-directory"
682
+ ],
683
+ [
684
+ "inputDirectory",
685
+ "输入目录",
686
+ "输入文件目录,覆盖基础目录",
687
+ "--input-directory"
688
+ ],
689
+ [
690
+ "tempDirectory",
691
+ "临时目录的父目录",
692
+ "ComfyUI 在此目录下使用 temp 子目录,并在启动和退出时清空该子目录",
693
+ "--temp-directory"
694
+ ],
695
+ [
696
+ "userDirectory",
697
+ "用户目录",
698
+ "已存在的用户目录,覆盖基础目录",
699
+ "--user-directory"
700
+ ],
701
+ [
702
+ "modelsDirectory",
703
+ "模型目录",
704
+ "已存在的模型目录,覆盖基础目录中的 models",
705
+ "--models-directory"
706
+ ],
707
+ [
708
+ "frontEndRoot",
709
+ "本地前端目录",
710
+ "已存在的前端文件目录,优先于前端版本设置",
711
+ "--front-end-root"
712
+ ]
713
+ ].map(([e, t, n, r]) => Z(e, t, e === "tempDirectory" ? "" : n, "paths", r, {
714
+ type: "path",
715
+ warning: e === "tempDirectory" ? n : void 0,
716
+ cli: {
717
+ arg: r,
718
+ resolvePath: !0
719
+ }
720
+ })),
721
+ Ie("extraModelPathsConfig", "额外模型路径配置", "每行一个 YAML 文件路径,包含空格的路径无需引号", "paths", "--extra-model-paths-config", !0),
722
+ X("disableAllCustomNodes", "禁用自定义节点", "排查节点问题时停止加载所有自定义节点,白名单除外", "nodes", "--disable-all-custom-nodes"),
723
+ {
724
+ ...Ie("whitelistCustomNodes", "自定义节点白名单", "每行一个节点文件夹名称,仍加载这些节点", "nodes", "--whitelist-custom-nodes"),
725
+ showWhen: {
726
+ param: "disableAllCustomNodes",
727
+ truthy: !0
728
+ }
729
+ },
730
+ X("disableApiNodes", "禁用 API 节点", "不加载 API 节点,并阻止前端与互联网通信", "nodes", "--disable-api-nodes"),
731
+ X("enableManager", "启用 ComfyUI Manager", "需要安装 manager_requirements.txt 中的管理器依赖", "nodes", "--enable-manager"),
732
+ Ne("managerUi", "管理器界面", "旧版界面会隐式启用管理器;关闭界面仍保留后台安装任务", "nodes", [
733
+ ["auto", "默认"],
734
+ [
735
+ "disabled",
736
+ "关闭界面",
737
+ "--disable-manager-ui"
738
+ ],
739
+ [
740
+ "legacy",
741
+ "旧版界面",
742
+ "--enable-manager-legacy-ui"
743
+ ]
744
+ ]),
745
+ Z("cudaDevices", "可见 CUDA / ROCm 设备", "留空使用生成引擎选择的 GPU;可填写 0,1 或 all 覆盖单卡选择", "advanced", "--cuda-device", {
746
+ audience: "expert",
747
+ cli: void 0,
748
+ validate: (e) => /^(?:|all|\d+(?:,\d+)*)$/.test(String(e)) ? null : "请填写设备序号、逗号分隔的序号或 all"
749
+ }),
750
+ {
751
+ ...Me("defaultDevice", "默认设备序号", "保留其他设备可见并选择默认设备;留空由 ComfyUI 决定", "advanced", "--default-device", "", 0),
752
+ max: 31
753
+ },
754
+ Z("oneapiDeviceSelector", "oneAPI 设备选择器", "留空使用生成引擎选择的 Intel GPU;可填写自定义选择表达式", "advanced", "--oneapi-device-selector", {
755
+ cli: void 0,
756
+ audience: "expert"
757
+ }),
758
+ Z("frontEndVersion", "前端版本", "留空使用安装的前端;指定 owner/repo@版本 时从 GitHub 获取", "advanced", "--front-end-version", {
759
+ placeholder: "Comfy-Org/ComfyUI_frontend@latest",
760
+ validate: (e) => !e || /^[^/\s]+\/[^@\s]+@[^\s]+$/.test(String(e)) ? null : "格式应为 owner/repo@版本"
761
+ }),
762
+ Z("defaultHashingFunction", "文件比较哈希", "重复文件名或内容比较所用的哈希算法", "advanced", "--default-hashing-function", {
763
+ type: "select",
764
+ default: "sha256",
765
+ options: [
766
+ "md5",
767
+ "sha1",
768
+ "sha256",
769
+ "sha512"
770
+ ].map((e) => ({
771
+ label: e,
772
+ value: e
773
+ }))
774
+ }),
775
+ Z("databaseUrl", "数据库 URL", "留空使用有效用户目录中的 comfyui.db;内存数据库可填 sqlite:///:memory:", "advanced", "--database-url"),
776
+ X("enableAssets", "启用资源系统", "启用资源 API、数据库同步与后台扫描", "advanced", "--enable-assets"),
777
+ X("enableAssetHashing", "资源内容哈希", "扫描时计算 blake3 哈希,会增加大型模型目录扫描与输出成本", "advanced", "--enable-asset-hashing"),
778
+ Ie("featureFlags", "服务特性开关", "每行一个 KEY 或 KEY=VALUE,重复传递给 ComfyUI", "advanced", "--feature-flag", !0),
779
+ Z("verbose", "控制台日志级别", "", "advanced", "--verbose", {
780
+ type: "select",
781
+ default: "INFO",
782
+ options: Le
783
+ }),
784
+ Z("logFile", "日志文件", "额外写入的日志文件路径;留空仅输出控制台", "advanced", "--verbose", { cli: {
785
+ arg: "--verbose",
786
+ format: "values",
787
+ values: [{ param: "logFileLevel" }, { param: "logFile" }]
788
+ } }),
789
+ {
790
+ id: "logFileLevel",
791
+ label: "文件日志级别",
792
+ type: "select",
793
+ default: "INFO",
794
+ options: Le,
795
+ group: "advanced",
796
+ audience: "advanced",
797
+ showWhen: {
798
+ param: "logFile",
799
+ truthy: !0
800
+ }
801
+ },
802
+ X("logStdout", "日志输出到 stdout", "将普通日志从 stderr 改为 stdout", "advanced", "--log-stdout"),
803
+ X("dontPrintServer", "隐藏服务地址输出", "", "advanced", "--dont-print-server"),
804
+ X("debugHang", "卡住时输出调用栈", "使用 Ctrl+C 输出调用栈以排查卡住问题", "advanced", "--debug-hang"),
805
+ X("assertGraphBreaks", "编译图中断时报错", "模型编译器发生 graph break 时直接失败,供调试使用", "advanced", "--assert-graph-breaks"),
806
+ {
807
+ id: "extraArgs",
808
+ label: "额外启动参数",
809
+ description: "追加当前页面未提供的参数;已有选项请在对应设置中修改",
810
+ type: "text",
811
+ default: "",
812
+ group: "advanced",
813
+ audience: "expert"
814
+ }
815
+ ], ze = de({
816
+ params: Re,
817
+ ownedArgs: Ee
818
+ }), Be = [
819
+ ...he,
820
+ {
821
+ id: "tls-pair",
822
+ params: ["tlsKeyfile", "tlsCertfile"],
823
+ message: "HTTPS 需要同时设置 TLS 证书和私钥",
824
+ when: { or: [{ and: [{
825
+ param: "tlsKeyfile",
826
+ set: !0
827
+ }, {
828
+ param: "tlsCertfile",
829
+ set: !1
830
+ }] }, { and: [{
831
+ param: "tlsKeyfile",
832
+ set: !1
833
+ }, {
834
+ param: "tlsCertfile",
835
+ set: !0
836
+ }] }] }
837
+ },
838
+ {
839
+ id: "cache-ram-pair",
840
+ params: ["cacheRam", "cacheRamInactive"],
841
+ message: "设置非活跃缓存余量时,请同时填写活跃缓存余量",
842
+ when: { and: [
843
+ {
844
+ param: "cacheMode",
845
+ equals: "ram"
846
+ },
847
+ {
848
+ param: "cacheRam",
849
+ set: !1
850
+ },
851
+ {
852
+ param: "cacheRamInactive",
853
+ set: !0
854
+ }
855
+ ] }
856
+ },
857
+ {
858
+ id: "precision-conflict",
859
+ params: ["forcePrecision", "unetPrecision"],
860
+ message: "全局 FP16 会覆盖扩散模型精度,请将扩散模型精度设为自动或 FP16",
861
+ when: { and: [{
862
+ param: "forcePrecision",
863
+ equals: "fp16"
864
+ }, { not: {
865
+ param: "unetPrecision",
866
+ in: ["auto", "fp16"]
867
+ } }] }
868
+ },
869
+ {
870
+ id: "default-device-ignored",
871
+ params: ["defaultDevice", "cudaDevices"],
872
+ severity: "warning",
873
+ message: "可见 CUDA / ROCm 设备设置会覆盖默认设备序号",
874
+ when: { and: [{
875
+ param: "defaultDevice",
876
+ set: !0
877
+ }, {
878
+ param: "cudaDevices",
879
+ set: !0
880
+ }] }
881
+ }
882
+ ], Ve = [
883
+ {
884
+ id: "default",
885
+ name: "默认配置",
886
+ description: "由 ComfyUI 自动选择显存与精度策略,使用 RAM 压力缓存",
887
+ icon: "i-lucide-check",
888
+ isDefault: !0,
889
+ params: {
890
+ port: 8188,
891
+ vramMode: Y.Normal,
892
+ vaePrecision: Oe.Auto,
893
+ unetPrecision: ke.Auto
894
+ }
895
+ },
896
+ {
897
+ id: "low-vram",
898
+ name: "低显存",
899
+ description: "关闭动态显存,使用传统低显存模式并减少节点缓存",
900
+ icon: "i-lucide-gauge",
901
+ params: {
902
+ omniXpu: !1,
903
+ vramMode: Y.Low,
904
+ dynamicVram: "disabled",
905
+ cacheMode: "none"
906
+ }
907
+ },
908
+ {
909
+ id: "troubleshoot",
910
+ name: "节点排查",
911
+ description: "禁用自定义节点并开启调试日志",
912
+ icon: "i-lucide-wrench",
913
+ params: {
914
+ omniXpu: !1,
915
+ disableAllCustomNodes: !0,
916
+ verbose: "DEBUG"
917
+ }
918
+ },
919
+ {
920
+ id: "cpu",
921
+ name: "CPU 模式",
922
+ description: "无 GPU 时使用",
923
+ icon: "i-lucide-cpu",
924
+ params: {
925
+ port: 8188,
926
+ vramMode: Y.CPU,
927
+ vaePrecision: Oe.FP32,
928
+ unetPrecision: ke.Auto
929
+ }
930
+ }
931
+ ];
932
+ //#endregion
933
+ //#region packages/plugins/comfyui/configuration.ts
934
+ function Q(e, t, n = "error") {
935
+ return S(`comfyui-${e}`, "compile", !1, n, t, "请在启动参数页调整对应设置", [{
936
+ id: J.OpenLaunchSettings,
937
+ label: "启动参数"
938
+ }]);
939
+ }
940
+ function He(e) {
941
+ let t = e.params;
942
+ if (pe(e)) return !1;
943
+ let n = T(e.app.path, String(t.baseDirectory || e.app.path)), r = [{ path: "requirements.txt" }];
944
+ if ((t.enableManager || t.managerUi === "legacy") && r.push({ path: "manager_requirements.txt" }), t.disableAllCustomNodes) {
945
+ for (let e of Fe(t.whitelistCustomNodes)) r.push({
946
+ path: T(n, `custom_nodes/${e}/requirements.txt`),
947
+ optional: !0
948
+ });
949
+ return { files: r };
950
+ }
951
+ return {
952
+ files: r,
953
+ directories: [{
954
+ path: T(n, "custom_nodes"),
955
+ disabled_suffix: ".disabled",
956
+ exclude: ["example_node", "__pycache__"]
957
+ }]
958
+ };
959
+ }
960
+ function Ue(e) {
961
+ let t = String(e.listen || "127.0.0.1").split(",")[0].trim(), n = t === "0.0.0.0" ? "127.0.0.1" : ["::", "[::]"].includes(t) ? "::1" : t, r = n.includes(":") && !n.startsWith("[") ? `[${n}]` : n, i = Number(e.port ?? 8188);
962
+ return `${e.tlsKeyfile && e.tlsCertfile ? "https" : "http"}://${r}:${Number.isInteger(i) && i > 0 && i <= 65535 ? i : 8188}`;
963
+ }
964
+ //#endregion
965
+ //#region packages/plugins/comfyui/preflight.ts
966
+ async function We(e, t) {
967
+ let n = [], r = [[
968
+ "core",
969
+ "comfy",
970
+ !0
971
+ ]];
972
+ for (let t of [
973
+ "userDirectory",
974
+ "modelsDirectory",
975
+ "frontEndRoot"
976
+ ]) e.params[t] && r.push([
977
+ t,
978
+ String(e.params[t]),
979
+ !0
980
+ ]);
981
+ for (let t of ["tlsKeyfile", "tlsCertfile"]) e.params[t] && r.push([
982
+ t,
983
+ String(e.params[t]),
984
+ !1
985
+ ]);
986
+ Fe(e.params.extraModelPathsConfig).forEach((e, t) => r.push([
987
+ `model-config-${t}`,
988
+ e,
989
+ !1
990
+ ])), await Promise.all(r.map(async ([r, i, a]) => {
991
+ let o = T(e.app.path, i);
992
+ try {
993
+ let e = (await t.fs.stat(o)).is_dir === a;
994
+ n.push(S(`comfyui-path-${r}`, "host", e, e ? "info" : "error", e ? `已找到${a ? "目录" : "文件"}:${o}` : `路径类型不正确:${o}`, e ? void 0 : `请选择${a ? "目录" : "文件"}`));
995
+ } catch {
996
+ n.push(S(`comfyui-path-${r}`, "host", !1, "error", `路径不存在或无法读取:${o}`, "请检查路径和读取权限", [{
997
+ id: r === "core" ? J.OpenVersionManagement : J.OpenLaunchSettings,
998
+ label: r === "core" ? "版本管理" : "启动参数"
999
+ }]));
1000
+ }
1001
+ }));
1002
+ let i = (t) => {
1003
+ let n = [];
1004
+ for (let r of T(e.app.path, t).replace(/\\/g, "/").split("/")) r === ".." ? n.pop() : r !== "." && n.push(r);
1005
+ let r = n.join("/").replace(/\/$/, "");
1006
+ return /win/i.test(e.host.os.name) ? r.toLowerCase() : r;
1007
+ }, a = T(e.app.path, String(e.params.baseDirectory || e.app.path)), o = i(T(String(e.params.tempDirectory || a), "temp"));
1008
+ return [
1009
+ e.app.path,
1010
+ ...Se(e.params).map((e) => e.path),
1011
+ ...[
1012
+ "input",
1013
+ "output",
1014
+ "user",
1015
+ "models"
1016
+ ].map((t) => String(e.params[`${t}Directory`] || T(a, t)))
1017
+ ].some((e) => {
1018
+ let t = i(e);
1019
+ return t === o || t.startsWith(`${o}/`);
1020
+ }) && n.push(Q("temp-directory-overlap", "ComfyUI 会清空临时目录;当前临时目录包含应用、模型、输入、输出或用户目录,请改用独立目录")), n;
1021
+ }
1022
+ async function Ge(e, t) {
1023
+ let n = E(e), r = e.params.vramMode === Y.CPU || n?.backend === "cpu", i = pe(e), a = n?.backend === "level-zero", o = [];
1024
+ if (a && !r && (e.params.cudaMalloc === "enabled" && o.push(Q("xpu-cuda-malloc", "Intel XPU 不能启用 CUDA 内存分配器")), (e.params.cudaDevices || e.params.defaultDevice !== "" && e.params.defaultDevice != null) && o.push(Q("xpu-device-options", "Intel XPU 请使用生成引擎或 oneAPI 设备选择器,清空 CUDA 设备和默认设备序号"))), i && e.params.disableAllCustomNodes) {
1025
+ let t = Fe(e.params.whitelistCustomNodes);
1026
+ (!t.includes("ComfyUI-OmniXPU") || e.params.omniSolAttention !== !1 && !t.includes("ComfyUI-SolAttn")) && o.push(Q("omnixpu-node-disabled", "Omni XPU 和已启用的 Sol-Attn 节点必须加入自定义节点白名单"));
1027
+ }
1028
+ i && !Object.keys(e.app.configuredEnv ?? {}).some((e) => e.toUpperCase() === "PATH") && typeof e.runtime.metadata?.path_env != "string" && o.push(Q("omnixpu-path-env", "未能读取执行端 PATH,请更新后端并重新检测 Python 环境"));
1029
+ let s;
1030
+ try {
1031
+ s = new URL(Ue(e.params));
1032
+ } catch {
1033
+ return [Q("listen-address", "监听地址无法生成有效的 WebUI 地址")];
1034
+ }
1035
+ let [c, l, u] = await Promise.all([
1036
+ We(e, t),
1037
+ t.launch.checkHttpPort(Number(e.params.port ?? 8188), "comfyui-port", s.hostname, "port", s.protocol === "https:" ? "https" : "http"),
1038
+ n?.selectable && !r && !o.length ? t.launch.runRuntimeProbe(e, i ? "omnixpu-runtime" : a ? "xpu-runtime" : "torch-runtime", { timeoutMs: 3e4 }) : void 0
1039
+ ]), d = [
1040
+ ...o,
1041
+ ...c,
1042
+ ...l
1043
+ ];
1044
+ if (i && e.params.omniSolAttention !== !1) {
1045
+ let n = T(e.app.path, String(e.params.baseDirectory || e.app.path));
1046
+ try {
1047
+ if ((await t.fs.stat(T(n, "custom_nodes/ComfyUI-SolAttn/__init__.py"))).is_dir) throw Error("not a file");
1048
+ } catch {
1049
+ d.push(Q("omnixpu-solattn-node", "未找到 ComfyUI-SolAttn 节点,请按整合包文档准备节点或关闭 Sol-Attn"));
1050
+ }
1051
+ }
1052
+ if (e.execution) try {
1053
+ let n = await t.fs.readFile(T(e.app.path, "comfy/cli_args.py")), r = new Set([...n.matchAll(/\.add_argument\(\s*['"](--[\w-]+)['"]/g)].map((e) => e[1]));
1054
+ if (r.size) {
1055
+ let t = [...new Set(e.execution.args.filter((e) => ze.includes(e) && !r.has(e)))];
1056
+ t.length && d.push(S("comfyui-unsupported-args", "compile", !1, "error", `当前 ComfyUI 源码不支持:${t.join("、")}`, "请更新 ComfyUI,或关闭对应选项", [{
1057
+ id: J.OpenVersionManagement,
1058
+ label: "版本管理"
1059
+ }, {
1060
+ id: J.OpenLaunchSettings,
1061
+ label: "启动参数"
1062
+ }]));
1063
+ }
1064
+ } catch {
1065
+ d.push(S("comfyui-cli-source", "compile", !1, "warning", "无法读取 comfy/cli_args.py,未能核对当前安装支持的参数", "请检查安装目录和读取权限"));
1066
+ }
1067
+ if (!r && (!n || !n.selectable)) return d.push(S("comfyui-selection-missing", "selection", !1, "error", "未找到可用的生成引擎", "请重新选择设备或切换到 CPU", [{
1068
+ id: J.RefreshHostCapabilities,
1069
+ label: "重新探测"
1070
+ }, {
1071
+ id: J.ApplyBackendSelection,
1072
+ label: "切到 CPU",
1073
+ payload: { backend: "cpu" },
1074
+ confirm: !1
1075
+ }])), d;
1076
+ d.push(S("comfyui-selection-resolved", "selection", !0, "info", `将使用 ${r ? "CPU" : `${n.backend.toUpperCase()} (${n.name})`}`)), r && (d.push(S("comfyui-cpu-mode", "selection", !1, "warning", "当前使用 CPU 生成,速度可能明显下降")), e.params.vramMode && ![Y.Normal, Y.CPU].includes(e.params.vramMode) && d.push(Q("cpu-vram-mode", "生成引擎选择了 CPU,GPU 显存模式不会生效", "warning")));
1077
+ let f = [{
1078
+ id: J.OpenPythonSettings,
1079
+ label: "Python 管理"
1080
+ }], p = e.runtime.status === "collected", m = C(u);
1081
+ if (i && !o.length) {
1082
+ let e = m?.omnixpu_available === !0;
1083
+ d.push(S("comfyui-omnixpu-runtime", "runtime", e, e ? "info" : "error", e ? "Omni XPU 内核和 Kitchen / AIMDO provider 检查通过" : typeof m?.omnixpu_error == "string" ? `Omni XPU 启动检查失败:${m.omnixpu_error}` : "未能完成 Omni XPU 启动检查,请重新检测", e ? void 0 : "请按 Omni Windows Portable 文档修复所选环境;Kano 不会自动替换其 Torch 依赖", e ? void 0 : f));
1084
+ }
1085
+ if (!p) d.push(S("comfyui-runtime-unknown", "runtime", !1, "warning", "未能完整读取 Python 环境,无法确认可选依赖", "请重新检查 Python 环境", f));
1086
+ else {
1087
+ let t = e.runtime.python?.version?.match(/(\d+)\.(\d+)/);
1088
+ t && (Number(t[1]) < 3 || Number(t[1]) === 3 && Number(t[2]) < 10) && d.push(S("comfyui-python-version", "runtime", !1, "error", "ComfyUI 需要 Python 3.10 或更高版本", "请选择符合要求的 Python 环境", f)), e.runtime.torch?.version || d.push(S("comfyui-torch-missing", "runtime", !1, "error", "当前 Python 环境未检测到 PyTorch", "请准备应用依赖", f));
1089
+ for (let [t, n] of [
1090
+ [e.params.attention === "sage", "sageattention"],
1091
+ [e.params.attention === "flash", "flash-attn"],
1092
+ [e.params.tritonBackend === "enabled", "triton"]
1093
+ ]) t && !w(e.runtime, n) && d.push(S(`comfyui-package-${n}`, "runtime", !1, "error", `当前设置需要 ${n},但 Python 环境尚未安装`, "安装对应依赖,或将该选项改回自动", f));
1094
+ }
1095
+ if (!r && n) {
1096
+ let t = n.backend, r = [
1097
+ "cuda",
1098
+ "hip",
1099
+ "zluda"
1100
+ ].includes(t) ? "cuda_available" : t === "mps" ? "mps_available" : t === "level-zero" ? "xpu_available" : "supports_directml";
1101
+ m?.[r] === !1 || m?.torch === !1 || a && m?.xpu_error ? d.push(S("comfyui-backend-runtime", "runtime", !1, "error", `当前 Python 环境无法使用 ${a ? "Intel XPU" : t.toUpperCase()} 后端${m?.xpu_error ? `:${m.xpu_error}` : ""}`, "请选择匹配的 PyTorch 环境或生成引擎", f)) : m?.[r] !== !0 && d.push(S("comfyui-backend-unverified", "runtime", !1, "warning", `未能实测确认 ${t.toUpperCase()} 后端可用`, "请检查 Python 环境后重试", f)), t === "hip" && m?.cuda_available === !0 && !m.hip_version && d.push(S("comfyui-hip-runtime", "runtime", !1, "error", "选择了 ROCm,但当前 PyTorch 不是 HIP 构建", "请选择 ROCm 版 PyTorch", f)), t === "directml" && d.push(Q("directml-support", "参考 ComfyUI 已提示 DirectML 支持有限且速度较慢,可优先考虑其他可用后端", "warning")), e.params.cudaMalloc === "enabled" && n.features.memoryPools === !1 && d.push(Q("cuda-malloc-support", "当前设备不支持异步内存池,请将 CUDA 内存分配器改为自动或关闭"));
1102
+ }
1103
+ e.params.vramMode === Y.Low && e.params.dynamicVram !== "disabled" && d.push(Q("lowvram-dynamic", "动态显存启用时 --lowvram 不生效;需要传统低显存模式时请关闭动态显存", "warning")), e.params.dynamicVram === "enabled" && r && d.push(Q("dynamic-vram-cpu", "CPU 模式不能强制启用动态显存"));
1104
+ let h = e.runtime.torch?.version?.match(/^(\d+)\.(\d+)/);
1105
+ return e.params.dynamicVram === "enabled" && h && Number(h[1]) === 2 && Number(h[2]) < 8 && d.push(Q("dynamic-vram-torch", "动态显存需要 PyTorch 2.8 或更高版本,请更新环境或改为自动")), ["split", "quad"].includes(String(e.params.attention)) && !e.params.disableXformers && w(e.runtime, "xformers") && d.push(Q("attention-xformers", "已安装的 xformers 会优先于 Split / Quad 注意力,请禁用 xformers 以使用所选实现", "warning")), d;
1106
+ }
1107
+ //#endregion
1108
+ //#region packages/plugins/comfyui/launch.ts
1109
+ var Ke = {
1110
+ persistentParams: ["sharedModelRoots", "snapshotBeforeUpdate"],
1111
+ entry: {
1112
+ type: "python",
1113
+ script: "main.py",
1114
+ prelude: (e) => e.getParam("omniXpu") ? ["-s"] : []
1115
+ },
1116
+ dependencies: He,
1117
+ ownedArgs: Ee,
1118
+ extraArgs: {
1119
+ param: "extraArgs",
1120
+ target: "argv"
1121
+ },
1122
+ rules: Be,
1123
+ resolveParams: ge,
1124
+ bindings: De,
1125
+ groups: je,
1126
+ params: Re,
1127
+ presets: Ve,
1128
+ startOptions: [{
1129
+ id: "safe-mode",
1130
+ label: "以安全模式启动(本次禁用全部自定义节点)",
1131
+ params: {
1132
+ disableAllCustomNodes: !0,
1133
+ whitelistCustomNodes: "",
1134
+ omniXpu: !1
1135
+ }
1136
+ }],
1137
+ strategy: {
1138
+ requirements: {
1139
+ pythonRuntime: !0,
1140
+ backendSelection: !0
1141
+ },
1142
+ preflight: Ge
1143
+ },
1144
+ getWebViewUrl: Ue
1145
+ };
1146
+ //#endregion
1147
+ //#region packages/plugins/comfyui/models.ts
1148
+ function qe(e) {
1149
+ return e.params.modelsDirectory ? T(e.path, String(e.params.modelsDirectory)) : T(T(e.path, String(e.params.baseDirectory || e.path)), "models");
1150
+ }
1151
+ function Je(e) {
1152
+ return Ye.categories?.find((t) => t.paths.includes("models/" + e))?.id;
1153
+ }
1154
+ var Ye = {
1155
+ resolveCategoryLocation(e, t) {
1156
+ let n = Ce(e, t.paths[0].replace(/^models\//, ""));
1157
+ return !e.params.modelsDirectory && !e.params.baseDirectory ? {
1158
+ paths: t.paths,
1159
+ sharedPaths: n
1160
+ } : {
1161
+ sharedPaths: n,
1162
+ basePath: qe(e),
1163
+ paths: t.paths.map((e) => e.replace(/^models\//, ""))
1164
+ };
1165
+ },
1166
+ categories: [
1167
+ {
1168
+ id: "checkpoint",
1169
+ marketTypes: ["checkpoint"],
1170
+ label: "Checkpoints",
1171
+ icon: "i-lucide-cpu",
1172
+ paths: ["models/checkpoints"],
1173
+ extensions: [
1174
+ ".safetensors",
1175
+ ".ckpt",
1176
+ ".pt",
1177
+ ".pth"
1178
+ ]
1179
+ },
1180
+ {
1181
+ id: "lora",
1182
+ marketTypes: ["lora", "lycoris"],
1183
+ label: "LoRA",
1184
+ icon: "i-lucide-sparkles",
1185
+ paths: ["models/loras"],
1186
+ extensions: [".safetensors", ".pt"]
1187
+ },
1188
+ {
1189
+ id: "vae",
1190
+ marketTypes: ["vae"],
1191
+ label: "VAE",
1192
+ icon: "i-lucide-palette",
1193
+ paths: ["models/vae"],
1194
+ extensions: [
1195
+ ".safetensors",
1196
+ ".pt",
1197
+ ".ckpt"
1198
+ ]
1199
+ },
1200
+ {
1201
+ id: "embedding",
1202
+ marketTypes: ["embedding"],
1203
+ label: "Embeddings",
1204
+ icon: "i-lucide-text",
1205
+ paths: ["models/embeddings"],
1206
+ extensions: [
1207
+ ".safetensors",
1208
+ ".pt",
1209
+ ".bin"
1210
+ ]
1211
+ },
1212
+ {
1213
+ id: "controlnet",
1214
+ marketTypes: ["controlnet"],
1215
+ label: "ControlNet",
1216
+ icon: "i-lucide-scan",
1217
+ paths: ["models/controlnet"],
1218
+ extensions: [
1219
+ ".safetensors",
1220
+ ".pth",
1221
+ ".pt"
1222
+ ]
1223
+ },
1224
+ {
1225
+ id: "clip",
1226
+ label: "文本编码器",
1227
+ icon: "i-lucide-type",
1228
+ paths: ["models/text_encoders", "models/clip"],
1229
+ extensions: [
1230
+ ".safetensors",
1231
+ ".pt",
1232
+ ".bin",
1233
+ ".gguf"
1234
+ ]
1235
+ },
1236
+ {
1237
+ id: "clip_vision",
1238
+ label: "CLIP Vision",
1239
+ icon: "i-lucide-eye",
1240
+ paths: ["models/clip_vision"],
1241
+ extensions: [
1242
+ ".safetensors",
1243
+ ".pt",
1244
+ ".bin"
1245
+ ]
1246
+ },
1247
+ {
1248
+ id: "upscale",
1249
+ marketTypes: ["upscaler"],
1250
+ label: "Upscale Models",
1251
+ icon: "i-lucide-maximize",
1252
+ paths: ["models/upscale_models"],
1253
+ extensions: [
1254
+ ".pth",
1255
+ ".pt",
1256
+ ".safetensors"
1257
+ ]
1258
+ },
1259
+ {
1260
+ id: "unet",
1261
+ label: "扩散模型",
1262
+ icon: "i-lucide-layers",
1263
+ marketTypes: ["checkpoint"],
1264
+ paths: ["models/diffusion_models", "models/unet"],
1265
+ extensions: [
1266
+ ".safetensors",
1267
+ ".pt",
1268
+ ".gguf"
1269
+ ]
1270
+ },
1271
+ {
1272
+ id: "ipadapter",
1273
+ label: "IP-Adapter",
1274
+ icon: "i-lucide-scan-face",
1275
+ paths: ["models/ipadapter"],
1276
+ extensions: [
1277
+ ".safetensors",
1278
+ ".bin",
1279
+ ".pt"
1280
+ ]
1281
+ },
1282
+ {
1283
+ id: "style_models",
1284
+ label: "风格模型",
1285
+ icon: "i-lucide-paintbrush",
1286
+ paths: ["models/style_models"],
1287
+ extensions: [
1288
+ ".safetensors",
1289
+ ".bin",
1290
+ ".pth"
1291
+ ]
1292
+ },
1293
+ {
1294
+ id: "latent_upscale_models",
1295
+ label: "潜空间放大模型",
1296
+ icon: "i-lucide-maximize",
1297
+ paths: ["models/latent_upscale_models"],
1298
+ extensions: [
1299
+ ".safetensors",
1300
+ ".pt",
1301
+ ".pth"
1302
+ ]
1303
+ },
1304
+ {
1305
+ id: "audio_encoders",
1306
+ label: "音频编码器",
1307
+ icon: "i-lucide-audio-lines",
1308
+ paths: ["models/audio_encoders"],
1309
+ extensions: [
1310
+ ".safetensors",
1311
+ ".bin",
1312
+ ".pt",
1313
+ ".pth"
1314
+ ]
1315
+ },
1316
+ {
1317
+ id: "diffusers",
1318
+ label: "Diffusers",
1319
+ icon: "i-lucide-folder-tree",
1320
+ paths: ["models/diffusers"],
1321
+ extensions: []
1322
+ }
1323
+ ]
1324
+ }, Xe = /* @__PURE__ */ RegExp("\x1B\\[[0-9;]*m", "g"), Ze = /(?:^|\s)\d+(?:\.\d+)? seconds\s*(\(IMPORT FAILED\))?:\s*(.+)$/, Qe = /\b([\w.]+(?:Error|Exception)(?::.*)?)$/, $e = "Import times for custom nodes:";
1325
+ function et(e) {
1326
+ let t = e.lastIndexOf("[系统] 正在准备启动..."), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = !1, a = !1, o = "";
1327
+ for (let s = Math.max(0, t); s < e.length; s++) for (let t of e[s].split(/\r?\n/)) {
1328
+ let e = t.replace(Xe, "").replace(/^\[[^\]]+\] (?:stdout|stderr): /, "").trim();
1329
+ if (!e) continue;
1330
+ if (e.endsWith($e)) {
1331
+ i = a = !0, r.clear(), o = "";
1332
+ continue;
1333
+ }
1334
+ let s = e.match(Ze);
1335
+ if (s && (a || s[1])) {
1336
+ let e = s[2].replace(/\\/g, "/").replace(/\/$/, ""), t = e.split("/").pop() || e, a = s[1] ? n.get(e) || o || "日志未记录具体原因" : "";
1337
+ r.set(e, {
1338
+ name: t,
1339
+ path: e,
1340
+ reason: a
1341
+ }), i = !0, o = "";
1342
+ continue;
1343
+ }
1344
+ let c = e.match(/Cannot import (.+?) module for custom nodes:\s*(.*)/), l = e.match(/Skip (.+?) module for custom nodes due to (.+)/), u = e.match(/Error while calling comfy_entrypoint in (.+?): (.+)/), d = c ?? l ?? u;
1345
+ if (d) {
1346
+ let e = d[2].trim();
1347
+ n.set(d[1].replace(/\\/g, "/"), o && o.includes(e) ? o : e);
1348
+ }
1349
+ o = e.match(Qe)?.[1] ?? "", a = !1;
1350
+ }
1351
+ if (!i) return null;
1352
+ let s = [...r.values()];
1353
+ return {
1354
+ loaded: s.filter((e) => !e.reason).length,
1355
+ failures: s.filter((e) => e.reason)
1356
+ };
1357
+ }
1358
+ //#endregion
1359
+ //#region packages/plugins/comfyui/extensions.ts
1360
+ var tt = {
1361
+ directory: "custom_nodes",
1362
+ supportsToggle: !0
1363
+ };
1364
+ function nt(e) {
1365
+ return e.trim().replace(/[?#].*$/, "").replace(/\/$/, "").replace(/\.git$/, "").match(/\/([^/]+)$/)?.[1] ?? null;
1366
+ }
1367
+ function rt(e) {
1368
+ return e.trim().replace(/\s+/g, "-");
1369
+ }
1370
+ function it(e) {
1371
+ if (e.install_type !== "git-clone") return null;
1372
+ let t = e.files?.length === 1 && typeof e.files[0] == "string" ? e.files[0] : "";
1373
+ if (!t) return null;
1374
+ let n = e.title?.trim() || nt(t) || t, r = (e.reference?.trim() || t).replace(/\.git$/, ""), i = e.tags?.filter((e) => typeof e == "string");
1375
+ return {
1376
+ id: e.id?.trim() || nt(t) || rt(n),
1377
+ name: n,
1378
+ description: e.description || "",
1379
+ gitUrl: t,
1380
+ author: e.author,
1381
+ stars: typeof e.stars == "number" ? e.stars : void 0,
1382
+ tags: i && i.length > 0 ? i : void 0,
1383
+ homepage: r
1384
+ };
1385
+ }
1386
+ var at = {
1387
+ resolveBasePath(e) {
1388
+ return T(e.path, String(e.params.baseDirectory || e.path));
1389
+ },
1390
+ parseLoadReport: et,
1391
+ getConfig() {
1392
+ return tt;
1393
+ }
1394
+ }, ot = { sources: [{
1395
+ id: "comfy-registry",
1396
+ name: "ComfyUI Manager",
1397
+ url: "https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json",
1398
+ description: "ComfyUI Manager 节点列表",
1399
+ type: "json",
1400
+ transform: (e) => (e.custom_nodes ?? []).map(it).filter((e) => e !== null)
1401
+ }] }, st = {
1402
+ kind: "git",
1403
+ defaultBranch: "master",
1404
+ recommendedRemotes: [{
1405
+ id: "official",
1406
+ name: "ComfyUI 官方",
1407
+ url: "https://github.com/comfyanonymous/ComfyUI.git",
1408
+ description: "官方仓库",
1409
+ isDefault: !0
1410
+ }],
1411
+ presets: [{
1412
+ id: "latest",
1413
+ name: "最新版",
1414
+ description: "跟随主分支,包含最新功能",
1415
+ branch: "master",
1416
+ isRecommended: !0
1417
+ }],
1418
+ getChangelogUrl() {
1419
+ return "https://github.com/comfyanonymous/ComfyUI/commits/master";
1420
+ }
1421
+ };
1422
+ //#endregion
1423
+ //#region packages/plugins/comfyui/discover-import.ts
1424
+ async function ct(e, t) {
1425
+ let n = "extra_model_paths.yaml", r = t.launch.resolvePath(e, t.launch.isWindowsPlatform() ? "../python_embeded/python.exe" : "../python_embeded/python"), [i, a] = await Promise.all([t.fs.exists(t.launch.resolvePath(e, n)), t.fs.exists(r)]);
1426
+ return !i && !a ? null : {
1427
+ ...i && { initialParams: { extraModelPathsConfig: n } },
1428
+ ...a && { pythonPath: r }
1429
+ };
1430
+ }
1431
+ //#endregion
1432
+ //#region packages/plugins/comfyui/SharedModelSettings.vue?vue&type=script&setup=true&lang.ts
1433
+ var lt = {
1434
+ key: 0,
1435
+ class: "kano-button-count",
1436
+ "aria-hidden": "true"
1437
+ }, ut = { class: "space-y-6" }, dt = {
1438
+ key: 0,
1439
+ class: "space-y-2"
1440
+ }, ft = {
1441
+ "aria-label": "已引用的目录",
1442
+ class: "kano-settings-group overflow-hidden"
1443
+ }, pt = { class: "min-w-0" }, mt = {
1444
+ key: 0,
1445
+ class: "kano-field-label break-words"
1446
+ }, ht = { class: "kano-field-hint break-all" }, gt = ["id"], _t = {
1447
+ key: 1,
1448
+ class: "kano-field-hint"
1449
+ }, vt = { class: "flex flex-wrap items-center gap-2" }, yt = { class: "flex flex-wrap items-center gap-2" }, bt = {
1450
+ key: 3,
1451
+ role: "alert",
1452
+ class: "break-words text-sm text-danger"
1453
+ }, xt = /* @__PURE__ */ F({
1454
+ __name: "SharedModelSettings",
1455
+ props: {
1456
+ api: {},
1457
+ app: {}
1458
+ },
1459
+ setup(e) {
1460
+ let n = e, r = O(() => Se(n.app.params)), i = O(() => [...n.api.apps.list().filter((e) => e.id !== n.app.id).map((e) => ({
1461
+ appId: e.id,
1462
+ name: e.name,
1463
+ path: qe(e),
1464
+ layout: "comfyui"
1465
+ })), ...n.api.services.list("kano:shared-model-directories").flatMap((e) => e.list())]), a = V(""), o = V(""), s = V(!1), c = V(""), l = V(!1), u = G(), m = G(), h = G(), g = G(), _ = ae();
1466
+ function y(e) {
1467
+ _.value = e.currentTarget, l.value = !0;
1468
+ }
1469
+ async function b() {
1470
+ if (!s.value) {
1471
+ s.value = !0, c.value = "";
1472
+ try {
1473
+ let e = await n.api.ui.openDirectory({
1474
+ title: "选择外部 ComfyUI 模型根目录",
1475
+ defaultPath: o.value.trim() ? T(n.app.path, o.value.trim()) : void 0
1476
+ });
1477
+ e && (o.value = e);
1478
+ } catch (e) {
1479
+ c.value = String(e), l.value || n.api.ui.toast.error(c.value);
1480
+ } finally {
1481
+ s.value = !1;
1482
+ }
1483
+ }
1484
+ }
1485
+ async function x(e, t = !1) {
1486
+ if (s.value) return;
1487
+ s.value = !0, c.value = "";
1488
+ let { api: u, app: d } = n;
1489
+ try {
1490
+ let n = [...r.value];
1491
+ if (e) n = n.filter((t) => t.path !== e.path);
1492
+ else {
1493
+ let e = t ? i.value.find((e) => e.appId === a.value) : void 0;
1494
+ if (t && !e) throw Error("请选择应用");
1495
+ let r = e?.path ?? T(d.path, o.value.trim());
1496
+ if (!await u.fs.isDir(r)) throw Error("执行端未找到目录:" + r);
1497
+ if (n.some((e) => e.path === r) || r === qe(d)) throw Error("模型目录已在当前模型库中");
1498
+ n.push({
1499
+ path: r,
1500
+ layout: e?.layout ?? "comfyui",
1501
+ label: e?.name || r
1502
+ });
1503
+ }
1504
+ await Te(u.fs, d.path, n);
1505
+ try {
1506
+ await u.apps.setParam(d.id, "sharedModelRoots", n);
1507
+ } catch (e) {
1508
+ throw await Te(u.fs, d.path, Se(u.apps.getParams(d.id))), e;
1509
+ }
1510
+ e || (t ? a.value = "" : o.value = ""), u.ui.toast.success(d.status === "running" ? "共享目录已保存,重启 ComfyUI 后生效" : "共享模型目录已保存");
1511
+ } catch (e) {
1512
+ c.value = String(e), l.value || u.ui.toast.error(c.value);
1513
+ } finally {
1514
+ s.value = !1;
1515
+ }
1516
+ }
1517
+ return (e, n) => (B(), j(D, null, [P(W(t), {
1518
+ severity: "secondary",
1519
+ "aria-label": r.value.length ? `共享目录,已配置 ${r.value.length} 个` : "共享目录",
1520
+ "aria-haspopup": "dialog",
1521
+ "aria-expanded": l.value,
1522
+ "aria-controls": l.value ? W(u) : void 0,
1523
+ onClick: y
1524
+ }, {
1525
+ default: q(() => [
1526
+ n[6] ||= M("span", {
1527
+ class: "i-lucide-folder-symlink shrink-0",
1528
+ "aria-hidden": "true"
1529
+ }, null, -1),
1530
+ n[7] ||= M("span", null, "共享目录", -1),
1531
+ r.value.length ? (B(), j("span", lt, U(r.value.length), 1)) : A("", !0)
1532
+ ]),
1533
+ _: 1
1534
+ }, 8, [
1535
+ "aria-label",
1536
+ "aria-expanded",
1537
+ "aria-controls"
1538
+ ]), P(W(p), {
1539
+ id: W(u),
1540
+ visible: l.value,
1541
+ "onUpdate:visible": n[4] ||= (e) => l.value = e,
1542
+ title: "共享模型目录",
1543
+ onAfterHide: n[5] ||= (e) => _.value?.focus({ preventScroll: !0 })
1544
+ }, {
1545
+ default: q(() => [M("div", ut, [
1546
+ r.value.length ? (B(), j("div", dt, [M("ul", ft, [(B(!0), j(D, null, H(r.value, (e) => (B(), j("li", {
1547
+ key: e.path,
1548
+ class: "kano-settings-row flex items-center justify-between gap-3"
1549
+ }, [M("div", pt, [e.label === e.path ? A("", !0) : (B(), j("p", mt, U(e.label), 1)), M("p", ht, U(e.path), 1)]), P(W(t), {
1550
+ label: "移除引用",
1551
+ text: "",
1552
+ size: "small",
1553
+ severity: "secondary",
1554
+ class: "shrink-0",
1555
+ "aria-label": `移除引用 ${e.label}`,
1556
+ "aria-describedby": W(g),
1557
+ disabled: s.value,
1558
+ onClick: (t) => x(e)
1559
+ }, null, 8, [
1560
+ "aria-label",
1561
+ "aria-describedby",
1562
+ "disabled",
1563
+ "onClick"
1564
+ ])]))), 128))]), M("p", {
1565
+ id: W(g),
1566
+ class: "kano-field-hint"
1567
+ }, "移除引用后,磁盘文件会保留。", 8, gt)])) : (B(), j("p", _t, "尚未引用外部共享目录。")),
1568
+ i.value.length ? (B(), j("form", {
1569
+ key: 2,
1570
+ class: "space-y-2",
1571
+ onSubmit: n[1] ||= le((e) => a.value && x(void 0, !0), ["prevent"])
1572
+ }, [P(W(d), {
1573
+ "field-id": W(m),
1574
+ label: "已注册应用"
1575
+ }, {
1576
+ default: q(() => [M("div", vt, [P(W(v), {
1577
+ modelValue: a.value,
1578
+ "onUpdate:modelValue": n[0] ||= (e) => a.value = e,
1579
+ "input-id": W(m),
1580
+ placeholder: "选择应用",
1581
+ options: i.value,
1582
+ "option-value": "appId",
1583
+ "option-label": "name",
1584
+ class: "min-w-40 flex-1",
1585
+ disabled: s.value
1586
+ }, null, 8, [
1587
+ "modelValue",
1588
+ "input-id",
1589
+ "options",
1590
+ "disabled"
1591
+ ]), P(W(t), {
1592
+ type: "submit",
1593
+ label: "引用模型目录",
1594
+ severity: "secondary",
1595
+ class: "shrink-0",
1596
+ disabled: s.value || !a.value
1597
+ }, null, 8, ["disabled"])])]),
1598
+ _: 1
1599
+ }, 8, ["field-id"])], 32)) : A("", !0),
1600
+ M("form", {
1601
+ class: "space-y-2",
1602
+ onSubmit: n[3] ||= le((e) => o.value.trim() && x(), ["prevent"])
1603
+ }, [P(W(d), {
1604
+ "field-id": W(h),
1605
+ label: "外部 ComfyUI 模型根目录"
1606
+ }, {
1607
+ default: q(() => [M("div", yt, [
1608
+ P(W(f), {
1609
+ id: W(h),
1610
+ modelValue: o.value,
1611
+ "onUpdate:modelValue": n[2] ||= (e) => o.value = e,
1612
+ class: "min-w-40 flex-1",
1613
+ disabled: s.value
1614
+ }, null, 8, [
1615
+ "id",
1616
+ "modelValue",
1617
+ "disabled"
1618
+ ]),
1619
+ P(W(t), {
1620
+ type: "button",
1621
+ label: "浏览…",
1622
+ severity: "secondary",
1623
+ outlined: "",
1624
+ class: "shrink-0",
1625
+ disabled: s.value,
1626
+ onClick: b
1627
+ }, null, 8, ["disabled"]),
1628
+ P(W(t), {
1629
+ type: "submit",
1630
+ label: "添加目录",
1631
+ severity: "secondary",
1632
+ class: "shrink-0",
1633
+ disabled: s.value || !o.value.trim()
1634
+ }, null, 8, ["disabled"])
1635
+ ])]),
1636
+ _: 1
1637
+ }, 8, ["field-id"])], 32),
1638
+ c.value ? (B(), j("p", bt, U(c.value), 1)) : A("", !0)
1639
+ ])]),
1640
+ _: 1
1641
+ }, 8, ["id", "visible"])], 64));
1642
+ }
1643
+ }), St = /^(?:[a-f\d]{40}|[a-f\d]{64})$/i, Ct = (e) => typeof e == "string" && !!e && !/[<>:"/\\|?*]/u.test(e) && ![...e].some((e) => e.charCodeAt(0) < 32) && !/[. ]$/.test(e) && !e.startsWith("."), wt = (e) => T(e.path, ".kano/snapshots"), Tt = (e) => T(e.path, String(e.params.baseDirectory || e.path)), Et = (e) => T(Tt(e), "custom_nodes"), Dt = (e) => e.name + (e.enabled ? "" : ".disabled"), Ot = {
1644
+ timeoutMs: 18e5,
1645
+ retryAfterDispatch: !1
1646
+ };
1647
+ function kt(e) {
1648
+ let t = e.pythonPath || e.params.pythonPath;
1649
+ if (typeof t != "string" || !t.trim()) throw Error("请先为当前应用选择 Python 解释器");
1650
+ return T(e.path, t);
1651
+ }
1652
+ var At = (e) => JSON.stringify([
1653
+ e.id,
1654
+ e.path,
1655
+ Tt(e),
1656
+ e.pythonPath || e.params.pythonPath || "",
1657
+ e.pythonPackageIndex || ""
1658
+ ]), jt = /* @__PURE__ */ new Set(), Mt = /* @__PURE__ */ new Map();
1659
+ function Nt(e) {
1660
+ if (jt.has(e)) throw Error("当前环境正在恢复,请稍后重试");
1661
+ }
1662
+ async function Pt(e, t, n) {
1663
+ let r = e.apps.list().find((e) => e.id === t.id);
1664
+ if (!r || r.path !== t.path) throw Error("应用目录已变更,请重新打开管理页");
1665
+ Nt(t.path), Mt.set(t.path, (Mt.get(t.path) ?? 0) + 1);
1666
+ let i = () => {
1667
+ let e = (Mt.get(t.path) ?? 1) - 1;
1668
+ e ? Mt.set(t.path, e) : Mt.delete(t.path);
1669
+ };
1670
+ try {
1671
+ return n && r.params.snapshotBeforeUpdate === !0 && await Bt(e, r), i;
1672
+ } catch (e) {
1673
+ throw i(), e;
1674
+ }
1675
+ }
1676
+ function Ft(e) {
1677
+ let t = JSON.parse(e);
1678
+ if (t?.version !== 1 || typeof t.created != "string" || !Number.isFinite(Date.parse(t.created)) || t.note !== void 0 && typeof t.note != "string" || !St.test(t.commit) || !Array.isArray(t.nodes) || !Array.isArray(t.packages) || t.nodes.some((e) => !e || !Ct(e.name) || typeof e.enabled != "boolean" || typeof e.url != "string" || e.commit !== "" && !St.test(e.commit)) || t.packages.some((e) => typeof e != "string" || !e.trim() || /[\r\n]/.test(e) || e.includes("\0") || e.startsWith("-") && !e.startsWith("-e ")) || new Set(t.nodes.map((e) => e.name)).size !== t.nodes.length) throw Error("快照格式无效,或含重名节点");
1679
+ return t;
1680
+ }
1681
+ function It(e) {
1682
+ return JSON.stringify({
1683
+ ...e,
1684
+ nodes: [...e.nodes].sort((e, t) => e.name.localeCompare(t.name)),
1685
+ packages: [...e.packages].sort()
1686
+ }, null, 2) + "\n";
1687
+ }
1688
+ function Lt(e, t) {
1689
+ let n = new Set(e);
1690
+ return [...t.flatMap((e) => {
1691
+ if (n.has(e)) return [];
1692
+ let t = /^(torch|torchvision|torchaudio)==[\w.]+\+(cpu|cu\d+)$/i.exec(e);
1693
+ return t ? [`--find-links https://download.pytorch.org/whl/${t[2].toLowerCase()}/${t[1].toLowerCase()}/`] : [];
1694
+ }), ...t].join("\n") + "\n";
1695
+ }
1696
+ function Rt(e, t) {
1697
+ let n = [];
1698
+ e.commit !== t.commit && n.push({
1699
+ group: "core",
1700
+ kind: "change",
1701
+ text: `${e.commit.slice(0, 9)} → ${t.commit.slice(0, 9)}`
1702
+ });
1703
+ let r = (e) => [
1704
+ e.enabled ? "启用" : "禁用",
1705
+ e.commit.slice(0, 9) || "本地节点",
1706
+ e.url
1707
+ ].filter(Boolean).join(" · "), i = new Map(e.nodes.map((e) => [e.name, e]));
1708
+ for (let e of t.nodes) {
1709
+ let t = i.get(e.name);
1710
+ t ? (t.commit !== e.commit || t.enabled !== e.enabled || t.url !== e.url) && n.push({
1711
+ group: "nodes",
1712
+ kind: "change",
1713
+ text: `${e.name} · ${r(t)} → ${r(e)}`
1714
+ }) : n.push({
1715
+ group: "nodes",
1716
+ kind: "add",
1717
+ text: `${e.name} · ${r(e)}`
1718
+ }), i.delete(e.name);
1719
+ }
1720
+ for (let e of i.keys()) n.push({
1721
+ group: "nodes",
1722
+ kind: "remove",
1723
+ text: e
1724
+ });
1725
+ let a = new Set(e.packages), o = new Set(t.packages);
1726
+ for (let e of o) a.delete(e) && o.delete(e);
1727
+ let s = (e) => /^([\w.-]+)(?:==|\s+@\s+)/.exec(e)?.[1].toLowerCase().replace(/[-_.]+/g, "-"), c = new Map([...o].map((e) => [s(e), e]));
1728
+ for (let e of a) {
1729
+ let t = s(e), r = t && c.get(t);
1730
+ r && o.delete(r) ? n.push({
1731
+ group: "packages",
1732
+ kind: "change",
1733
+ text: `${e} → ${r}`
1734
+ }) : n.push({
1735
+ group: "packages",
1736
+ kind: "remove",
1737
+ text: e
1738
+ });
1739
+ }
1740
+ for (let e of o) n.push({
1741
+ group: "packages",
1742
+ kind: "add",
1743
+ text: e
1744
+ });
1745
+ return n;
1746
+ }
1747
+ async function zt(e, t) {
1748
+ let n = kt(t), r = e.fs, i = Et(t), a = await r.exists(i) ? await r.listDir(i) : [], o = await Promise.all(a.filter((e) => !e.name.startsWith(".") && e.name !== "__pycache__" && (e.is_dir || /\.py(?:\.disabled)?$/i.test(e.name))).map(async (e) => ({
1749
+ name: e.name.replace(/\.disabled$/, ""),
1750
+ enabled: !e.name.endsWith(".disabled"),
1751
+ path: T(i, e.name),
1752
+ git: e.is_dir && await r.exists(T(T(i, e.name), ".git"))
1753
+ }))), [s, c] = await Promise.all([e.rpc.request("git.batchGetRepoBasicInfo", {
1754
+ paths: [t.path, ...o.filter((e) => e.git).map((e) => e.path)],
1755
+ force_reload: !0
1756
+ }), e.rpc.request("python.freeze", { path: n })]), l = new Map(s.map((e) => [e.path.replaceAll("\\", "/"), e])), u = (e) => {
1757
+ let t = l.get(e.replaceAll("\\", "/"));
1758
+ if (!t?.info?.current_commit?.hash) throw Error(`读取 Git 提交失败:${e} ${t?.error ?? ""}`);
1759
+ return {
1760
+ commit: t.info.current_commit.hash,
1761
+ url: t.info.remote_url || ""
1762
+ };
1763
+ };
1764
+ return Ft(It({
1765
+ version: 1,
1766
+ created: (/* @__PURE__ */ new Date()).toISOString(),
1767
+ commit: u(t.path).commit,
1768
+ nodes: o.map(({ name: e, enabled: t, path: n, git: r }) => ({
1769
+ name: e,
1770
+ enabled: t,
1771
+ ...r ? u(n) : {
1772
+ commit: "",
1773
+ url: ""
1774
+ }
1775
+ })),
1776
+ packages: c.split(/\r?\n/).map((e) => e.trim()).filter(Boolean)
1777
+ }));
1778
+ }
1779
+ async function Bt(e, t, n) {
1780
+ let r = await zt(e, t);
1781
+ n?.trim() && (r.note = n.trim());
1782
+ let i = wt(t);
1783
+ await e.fs.mkdir(i);
1784
+ let a = r.created.replaceAll(":", "-") + "-" + crypto.randomUUID().slice(0, 8) + ".json", o = T(i, a);
1785
+ return await e.fs.writeFile(o + ".tmp", It(r)), await e.fs.rename(o + ".tmp", o), a;
1786
+ }
1787
+ async function Vt(e, t) {
1788
+ let n = e.fs, r = wt(t);
1789
+ if (!await n.exists(r)) return [];
1790
+ let i = (await n.listDir(r)).filter((e) => !e.is_dir && Ct(e.name) && e.name.endsWith(".json"));
1791
+ return (await Promise.all(i.map(async (n) => {
1792
+ try {
1793
+ let { created: r, note: i } = await Ut(e, t, n.name);
1794
+ return {
1795
+ file: n.name,
1796
+ created: r,
1797
+ note: i
1798
+ };
1799
+ } catch (e) {
1800
+ return {
1801
+ file: n.name,
1802
+ created: n.mod_time,
1803
+ error: String(e)
1804
+ };
1805
+ }
1806
+ }))).sort((e, t) => (Date.parse(t.created ?? "") || 0) - (Date.parse(e.created ?? "") || 0) || t.file.localeCompare(e.file));
1807
+ }
1808
+ function Ht(e, t) {
1809
+ if (!Ct(t) || !t.endsWith(".json")) throw Error("请选择有效快照");
1810
+ return T(wt(e), t);
1811
+ }
1812
+ async function Ut(e, t, n) {
1813
+ return Ft(await e.fs.readFile(Ht(t, n)));
1814
+ }
1815
+ async function Wt(e, t, n) {
1816
+ await e.fs.trash(Ht(t, n));
1817
+ }
1818
+ async function Gt(e, t, n) {
1819
+ if (Nt(t.path), Mt.has(t.path)) throw Error("版本或节点正在更新,请稍后恢复快照");
1820
+ if (!["stopped", "error"].includes(e.apps.getRuntime(t.id).status)) throw Error("请先停止 ComfyUI 再恢复环境");
1821
+ let r = e.apps.list().find((e) => e.id === t.id);
1822
+ if (!r || At(t) !== At(r)) throw Error("环境目录或解释器已变更,请重新查看差异");
1823
+ jt.add(t.path);
1824
+ try {
1825
+ let r = (t, n) => e.rpc.request("git.checkout", {
1826
+ path: t,
1827
+ ref: n
1828
+ }, Ot), i = await zt(e, t);
1829
+ i.commit !== n.commit && (await r(t.path, n.commit), i = await zt(e, t));
1830
+ let a = e.fs, o = Et(t), s = new Map(i.nodes.map((e) => [e.name, e]));
1831
+ for (let e of n.nodes) {
1832
+ let t = s.get(e.name);
1833
+ if ((!t || e.url !== t.url || !!e.commit != !!t.commit) && (!e.url || !e.commit)) throw Error(`节点 ${e.name} 缺少可还原的仓库来源,请先放回本地节点`);
1834
+ }
1835
+ let c = T(Tt(t), ".kano/restore-" + crypto.randomUUID());
1836
+ await a.mkdir(c);
1837
+ let l = /* @__PURE__ */ new Map();
1838
+ for (let t of n.nodes) {
1839
+ let n = s.get(t.name);
1840
+ if (n && n.url === t.url && !!n.commit == !!t.commit) continue;
1841
+ let i = T(c, "incoming/" + t.name);
1842
+ await a.mkdir(T(c, "incoming")), await e.rpc.request("git.clone", {
1843
+ url: t.url,
1844
+ path: i
1845
+ }, Ot), await r(i, t.commit), l.set(t.name, i);
1846
+ }
1847
+ await a.mkdir(o);
1848
+ let u = new Set(n.nodes.map((e) => e.name));
1849
+ for (let e of i.nodes) (!u.has(e.name) || l.has(e.name)) && (await a.mkdir(T(c, "previous")), await a.rename(T(o, Dt(e)), T(c, "previous/" + Dt(e))));
1850
+ for (let e of n.nodes) {
1851
+ let t = T(o, Dt(e)), n = l.get(e.name);
1852
+ if (n) {
1853
+ await a.rename(n, t);
1854
+ continue;
1855
+ }
1856
+ let i = s.get(e.name), c = T(o, Dt(i));
1857
+ e.commit && i.commit !== e.commit && await r(c, e.commit), i.enabled !== e.enabled && await a.rename(c, t);
1858
+ }
1859
+ if (i.packages.join("\n") !== n.packages.slice().sort().join("\n")) {
1860
+ let r = T(c, "requirements.txt");
1861
+ await a.writeFile(r, Lt(i.packages, n.packages)), await e.rpc.request("python.syncFrozen", {
1862
+ python_path: kt(t),
1863
+ requirements_path: r,
1864
+ index: t.pythonPackageIndex
1865
+ }, Ot);
1866
+ }
1867
+ let d = Rt(await zt(e, t), n);
1868
+ if (d.length) throw Error("尚有差异:" + d.map((e) => e.text).join("\n"));
1869
+ } catch (e) {
1870
+ throw Error(`环境恢复未完成,请重新查看差异。\n${e instanceof Error ? e.message : String(e)}`, { cause: e });
1871
+ } finally {
1872
+ jt.delete(t.path);
1873
+ }
1874
+ }
1875
+ //#endregion
1876
+ //#region packages/plugins/comfyui/EnvironmentSnapshots.vue?vue&type=script&setup=true&lang.ts
1877
+ var Kt = { class: "space-y-4" }, qt = { class: "flex flex-wrap items-center gap-2" }, Jt = {
1878
+ key: 0,
1879
+ "aria-label": "已保存的环境快照",
1880
+ class: "space-y-2"
1881
+ }, Yt = { class: "min-w-0 flex-1" }, Xt = ["datetime"], Zt = {
1882
+ key: 0,
1883
+ class: "mt-1 block break-words text-sm text-text-secondary"
1884
+ }, Qt = {
1885
+ key: 1,
1886
+ class: "mt-1 block break-words text-xs text-danger"
1887
+ }, $t = {
1888
+ key: 1,
1889
+ class: "kano-field-hint"
1890
+ }, en = {
1891
+ key: 2,
1892
+ role: "status",
1893
+ class: "flex items-center gap-1.5 text-sm text-text-muted"
1894
+ }, tn = { class: "kano-field-label" }, nn = { class: "space-y-1.5 text-xs" }, rn = { class: "min-w-0 break-all font-mono" }, an = {
1895
+ key: 0,
1896
+ class: "kano-field-hint"
1897
+ }, on = {
1898
+ key: 1,
1899
+ role: "status",
1900
+ class: "text-sm text-text-secondary"
1901
+ }, sn = {
1902
+ key: 4,
1903
+ role: "alert",
1904
+ class: "break-words text-sm text-danger"
1905
+ }, cn = /* @__PURE__ */ F({
1906
+ __name: "EnvironmentSnapshots",
1907
+ props: {
1908
+ app: {},
1909
+ api: {}
1910
+ },
1911
+ emits: ["changed"],
1912
+ setup(e, { emit: n }) {
1913
+ let i = e, a = n, o = V(!1), s = V(!1), c = V(!1), l = V(""), u = G(), m = G(), h = G(), g = V(""), _ = V(), v = V([]), y = V(""), b = V([]), S = O(() => [
1914
+ {
1915
+ title: "ComfyUI 核心",
1916
+ items: b.value.filter((e) => e.group === "core")
1917
+ },
1918
+ {
1919
+ title: "自定义节点",
1920
+ items: b.value.filter((e) => e.group === "nodes")
1921
+ },
1922
+ {
1923
+ title: "Python 依赖",
1924
+ items: b.value.filter((e) => e.group === "packages")
1925
+ }
1926
+ ].filter((e) => e.items.length)), C = {
1927
+ add: {
1928
+ label: "新增",
1929
+ color: "text-success"
1930
+ },
1931
+ remove: {
1932
+ label: "移除",
1933
+ color: "text-danger"
1934
+ },
1935
+ change: {
1936
+ label: "修改",
1937
+ color: "text-warning"
1938
+ }
1939
+ }, w = new Intl.DateTimeFormat(void 0, {
1940
+ dateStyle: "medium",
1941
+ timeStyle: "medium"
1942
+ });
1943
+ function T(e) {
1944
+ let t = Date.parse(e.created ?? "");
1945
+ return Number.isFinite(t) ? w.format(t) : e.file;
1946
+ }
1947
+ let E = ae(), k = ae(), N = 0, ee = O(() => ["stopped", "error"].includes(i.app.status));
1948
+ K(() => At(i.app), () => {
1949
+ N++, s.value = o.value = c.value = !1, E.value = k.value = void 0, v.value = [], b.value = [], _.value = void 0, y.value = g.value = l.value = "";
1950
+ }, { flush: "sync" }), K(ee, (e) => {
1951
+ e || (s.value = !1);
1952
+ }, { flush: "sync" });
1953
+ async function F(e) {
1954
+ if (c.value) return;
1955
+ let t = N;
1956
+ c.value = !0, l.value = "";
1957
+ try {
1958
+ await e(t);
1959
+ } catch (e) {
1960
+ t === N && (l.value = String(e), o.value || i.api.ui.toast.error(l.value));
1961
+ } finally {
1962
+ t === N && (c.value = !1);
1963
+ }
1964
+ }
1965
+ async function I(e) {
1966
+ let t = await Vt(i.api, i.app);
1967
+ e === N && (v.value = t);
1968
+ }
1969
+ let L = ae();
1970
+ function te(e) {
1971
+ L.value = e.currentTarget, o.value = !0, !c.value && (E.value = void 0, y.value = "", F(I));
1972
+ }
1973
+ function ne() {
1974
+ F(async (e) => {
1975
+ let t = await Bt(i.api, i.app, g.value);
1976
+ e === N && (y.value = t, g.value = "", i.api.ui.toast.success("环境快照已保存"), await I(e));
1977
+ });
1978
+ }
1979
+ function z(e) {
1980
+ F(async (t) => {
1981
+ y.value = e, E.value = void 0;
1982
+ let n = {
1983
+ ...i.app,
1984
+ params: { ...i.app.params }
1985
+ }, [r, a] = await Promise.all([Ut(i.api, n, e), zt(i.api, n)]);
1986
+ t === N && (k.value = n, b.value = Rt(a, r), E.value = r);
1987
+ });
1988
+ }
1989
+ function re() {
1990
+ s.value = !1;
1991
+ let e = E.value, t = k.value;
1992
+ e && t && At(t) === At(i.app) && F(async (n) => {
1993
+ E.value = void 0;
1994
+ try {
1995
+ await Gt(i.api, t, e);
1996
+ } finally {
1997
+ n === N && a("changed");
1998
+ }
1999
+ n === N && (i.api.ui.toast.success("已恢复环境并核对快照"), await I(n));
2000
+ });
2001
+ }
2002
+ K(y, () => {
2003
+ s.value = !1, k.value = void 0, E.value = void 0, b.value = [];
2004
+ });
2005
+ function ie() {
2006
+ let e = _.value;
2007
+ e && (_.value = void 0, F(async (t) => {
2008
+ await Wt(i.api, i.app, e.file), t === N && (y.value === e.file && (y.value = ""), v.value = v.value.filter((t) => t.file !== e.file), i.api.ui.toast.success("快照已移至回收站"));
2009
+ }));
2010
+ }
2011
+ function oe(e) {
2012
+ F(() => i.api.apps.setParam(i.app.id, "snapshotBeforeUpdate", e));
2013
+ }
2014
+ return (n, i) => (B(), j(D, null, [
2015
+ P(W(t), {
2016
+ icon: "i-lucide-history",
2017
+ label: "环境快照",
2018
+ severity: "secondary",
2019
+ loading: c.value,
2020
+ "aria-haspopup": "dialog",
2021
+ "aria-expanded": o.value,
2022
+ "aria-controls": o.value ? W(m) : void 0,
2023
+ onClick: te
2024
+ }, null, 8, [
2025
+ "loading",
2026
+ "aria-expanded",
2027
+ "aria-controls"
2028
+ ]),
2029
+ P(W(p), {
2030
+ id: W(m),
2031
+ visible: o.value,
2032
+ title: "环境快照",
2033
+ "onUpdate:visible": i[2] ||= (e) => !s.value && !_.value && (o.value = e),
2034
+ onAfterHide: i[3] ||= (e) => L.value?.focus({ preventScroll: !0 })
2035
+ }, {
2036
+ default: q(() => [M("div", Kt, [
2037
+ P(W(d), {
2038
+ class: "kano-settings-group p-4",
2039
+ layout: "inline",
2040
+ label: "更新前自动保存快照",
2041
+ "field-id": W(u)
2042
+ }, {
2043
+ default: q(() => [P(W(x), {
2044
+ "input-id": W(u),
2045
+ class: "block shrink-0",
2046
+ "model-value": e.app.params.snapshotBeforeUpdate === !0,
2047
+ disabled: c.value,
2048
+ "onUpdate:modelValue": oe
2049
+ }, null, 8, [
2050
+ "input-id",
2051
+ "model-value",
2052
+ "disabled"
2053
+ ])]),
2054
+ _: 1
2055
+ }, 8, ["field-id"]),
2056
+ M("form", {
2057
+ class: "space-y-2",
2058
+ onSubmit: le(ne, ["prevent"])
2059
+ }, [P(W(d), {
2060
+ "field-id": W(h),
2061
+ label: "备注(可选)"
2062
+ }, {
2063
+ default: q(() => [M("div", qt, [P(W(f), {
2064
+ id: W(h),
2065
+ modelValue: g.value,
2066
+ "onUpdate:modelValue": i[0] ||= (e) => g.value = e,
2067
+ disabled: c.value,
2068
+ class: "min-w-40 flex-1"
2069
+ }, null, 8, [
2070
+ "id",
2071
+ "modelValue",
2072
+ "disabled"
2073
+ ]), P(W(t), {
2074
+ type: "submit",
2075
+ label: "保存当前环境",
2076
+ icon: "i-lucide-camera",
2077
+ class: "shrink-0",
2078
+ disabled: c.value
2079
+ }, null, 8, ["disabled"])])]),
2080
+ _: 1
2081
+ }, 8, ["field-id"])], 32),
2082
+ v.value.length ? (B(), j("ul", Jt, [(B(!0), j(D, null, H(v.value, (e) => (B(), j("li", {
2083
+ key: e.file,
2084
+ class: "flex items-center gap-2"
2085
+ }, [P(W(t), {
2086
+ unstyled: "",
2087
+ type: "button",
2088
+ class: "kano-choice flex min-w-0 flex-1 items-center gap-3 p-3 text-left",
2089
+ "aria-pressed": e.file === y.value,
2090
+ disabled: c.value,
2091
+ title: "查看差异 · " + e.file,
2092
+ onClick: (t) => z(e.file)
2093
+ }, {
2094
+ default: q(() => [
2095
+ i[6] ||= M("span", {
2096
+ class: "i-lucide-history size-4 shrink-0 text-text-secondary",
2097
+ "aria-hidden": "true"
2098
+ }, null, -1),
2099
+ M("span", Yt, [
2100
+ M("time", {
2101
+ datetime: e.created,
2102
+ class: "kano-field-label block tabular-nums"
2103
+ }, U(T(e)), 9, Xt),
2104
+ e.note ? (B(), j("span", Zt, U(e.note), 1)) : A("", !0),
2105
+ e.error ? (B(), j("span", Qt, U(e.file) + " · " + U(e.error), 1)) : A("", !0)
2106
+ ]),
2107
+ i[7] ||= M("span", { class: "sr-only" }, "查看差异", -1),
2108
+ i[8] ||= M("span", {
2109
+ class: "i-lucide-chevron-right size-4 shrink-0 text-text-muted",
2110
+ "aria-hidden": "true"
2111
+ }, null, -1)
2112
+ ]),
2113
+ _: 2
2114
+ }, 1032, [
2115
+ "aria-pressed",
2116
+ "disabled",
2117
+ "title",
2118
+ "onClick"
2119
+ ]), P(W(t), {
2120
+ icon: "i-lucide-trash-2",
2121
+ text: "",
2122
+ size: "small",
2123
+ severity: "danger",
2124
+ class: "shrink-0",
2125
+ "aria-label": "删除快照 " + T(e),
2126
+ title: "将快照移至回收站",
2127
+ disabled: c.value,
2128
+ onClick: (t) => _.value = e
2129
+ }, null, 8, [
2130
+ "aria-label",
2131
+ "disabled",
2132
+ "onClick"
2133
+ ])]))), 128))])) : !c.value && !l.value ? (B(), j("p", $t, "尚未保存环境快照")) : A("", !0),
2134
+ c.value ? (B(), j("p", en, [...i[9] ||= [M("span", {
2135
+ class: "i-lucide-loader-2 size-4 shrink-0 motion-safe:animate-spin",
2136
+ "aria-hidden": "true"
2137
+ }, null, -1), M("span", null, "正在处理…", -1)]])) : A("", !0),
2138
+ E.value ? (B(), j(D, { key: 3 }, [b.value.length ? (B(), j(D, { key: 0 }, [
2139
+ i[10] ||= M("h3", { class: "kano-section-title" }, "恢复此快照将应用的更改", -1),
2140
+ (B(!0), j(D, null, H(S.value, (e) => (B(), j("section", {
2141
+ key: e.title,
2142
+ class: "space-y-2"
2143
+ }, [M("h4", tn, U(e.title), 1), M("ul", nn, [(B(!0), j(D, null, H(e.items, (e) => (B(), j("li", {
2144
+ key: e.kind + e.text,
2145
+ class: "flex items-baseline gap-2"
2146
+ }, [M("span", { class: R(["shrink-0 text-xs", C[e.kind].color]) }, U(C[e.kind].label), 3), M("span", rn, U(e.text), 1)]))), 128))])]))), 128)),
2147
+ ee.value ? A("", !0) : (B(), j("p", an, "停止 ComfyUI 后可恢复环境。")),
2148
+ P(W(t), {
2149
+ label: "恢复此快照",
2150
+ severity: "secondary",
2151
+ disabled: c.value || !ee.value,
2152
+ onClick: i[1] ||= (e) => s.value = !0
2153
+ }, null, 8, ["disabled"])
2154
+ ], 64)) : (B(), j("p", on, "当前环境与快照一致"))], 64)) : A("", !0),
2155
+ l.value ? (B(), j("p", sn, U(l.value), 1)) : A("", !0)
2156
+ ])]),
2157
+ _: 1
2158
+ }, 8, ["id", "visible"]),
2159
+ P(W(r), {
2160
+ visible: s.value,
2161
+ "onUpdate:visible": i[4] ||= (e) => s.value = e,
2162
+ title: "恢复环境快照",
2163
+ type: "warning",
2164
+ "confirm-text": "恢复环境",
2165
+ message: `将回退 ComfyUI 和节点提交,覆盖对应仓库内已跟踪文件的修改。多余节点移到基础目录的 .kano/restore-*,并将当前解释器 ${E.value && W(kt)(e.app)} 的包同步至快照版本,移除额外的包。`,
2166
+ onConfirm: re
2167
+ }, null, 8, ["visible", "message"]),
2168
+ P(W(r), {
2169
+ visible: !!_.value,
2170
+ title: "删除环境快照",
2171
+ type: "danger",
2172
+ "confirm-text": "移至回收站",
2173
+ message: _.value ? `将快照 ${T(_.value)}(${_.value.file})移至执行端回收站。当前环境会保留。` : "",
2174
+ "onUpdate:visible": i[5] ||= (e) => !e && (_.value = void 0),
2175
+ onConfirm: ie
2176
+ }, null, 8, ["visible", "message"])
2177
+ ], 64));
2178
+ }
2179
+ }), ln = 16777216;
2180
+ async function un(e) {
2181
+ let t = new Blob([e]).stream().pipeThrough(new DecompressionStream("deflate")).getReader(), n = [], r = 0;
2182
+ try {
2183
+ for (;;) {
2184
+ let { value: e, done: i } = await t.read();
2185
+ if (i) break;
2186
+ if (r += e.length, r > ln) throw Error("PNG 工作流元数据过大");
2187
+ n.push(e);
2188
+ }
2189
+ } finally {
2190
+ await t.cancel();
2191
+ }
2192
+ let i = new Uint8Array(r), a = 0;
2193
+ for (let e of n) i.set(e, a), a += e.length;
2194
+ return new TextDecoder().decode(i);
2195
+ }
2196
+ async function dn(e) {
2197
+ let t = new Uint8Array(e);
2198
+ if (![
2199
+ 137,
2200
+ 80,
2201
+ 78,
2202
+ 71,
2203
+ 13,
2204
+ 10,
2205
+ 26,
2206
+ 10
2207
+ ].every((e, n) => t[n] === e)) throw Error("无效的 PNG 文件");
2208
+ let n = new DataView(e), r = new TextDecoder(), i = {}, a = !1;
2209
+ for (let e = 8; e + 12 <= t.length;) {
2210
+ let o = n.getUint32(e);
2211
+ if (e + o + 12 > t.length) throw Error("PNG 数据不完整");
2212
+ let s = r.decode(t.subarray(e + 4, e + 8)), c = t.subarray(e + 8, e + 8 + o);
2213
+ if (e += o + 12, s === "IEND") {
2214
+ a = !0;
2215
+ break;
2216
+ }
2217
+ if (![
2218
+ "tEXt",
2219
+ "iTXt",
2220
+ "zTXt"
2221
+ ].includes(s)) continue;
2222
+ let l = c.indexOf(0);
2223
+ if (l < 0) continue;
2224
+ let u = r.decode(c.subarray(0, l));
2225
+ if (u !== "workflow" && u !== "prompt" && u !== "parameters") continue;
2226
+ if (o > ln) throw Error("PNG 工作流元数据过大");
2227
+ let d = c.subarray(l + 1), f = !1;
2228
+ if (s === "zTXt") {
2229
+ if (d[0] !== 0) throw Error("不支持的 PNG 压缩方式");
2230
+ f = !0, d = d.subarray(1);
2231
+ } else if (s === "iTXt") {
2232
+ if (d.length < 4 || d[0] > 1 || d[1] !== 0) throw Error("无效的 PNG 文本块");
2233
+ f = d[0] === 1, d = d.subarray(2);
2234
+ for (let e = 0; e < 2; e++) {
2235
+ let e = d.indexOf(0);
2236
+ if (e < 0) throw Error("无效的 PNG 文本块");
2237
+ d = d.subarray(e + 1);
2238
+ }
2239
+ }
2240
+ i[u] = f ? await un(d) : r.decode(d);
2241
+ }
2242
+ if (!a) throw Error("PNG 数据不完整");
2243
+ return i;
2244
+ }
2245
+ //#endregion
2246
+ //#region packages/plugins/comfyui/workflow.ts
2247
+ var fn = /* @__PURE__ */ new Set([
2248
+ "Reroute",
2249
+ "PrimitiveNode",
2250
+ "Note",
2251
+ "MarkdownNote"
2252
+ ]);
2253
+ function $(e) {
2254
+ return typeof e == "object" && !!e && !Array.isArray(e);
2255
+ }
2256
+ function pn(e, t) {
2257
+ return typeof e == "number" && Number.isFinite(e) ? e : t;
2258
+ }
2259
+ function mn(e, t = "工作流") {
2260
+ if (!$(e)) throw Error("文件不是 ComfyUI 工作流");
2261
+ if ($(e.workflow)) return mn(e.workflow, t);
2262
+ let n = [], r = [];
2263
+ if (Array.isArray(e.nodes)) {
2264
+ let i = $(e.definitions) && Array.isArray(e.definitions.subgraphs) ? e.definitions.subgraphs : [], a = new Map(i.filter($).map((e) => [e.id, e])), o = (e, t, i) => {
2265
+ if (!Array.isArray(e.nodes)) throw Error("子工作流缺少节点列表");
2266
+ let s = /* @__PURE__ */ new Set();
2267
+ for (let [r, c] of e.nodes.entries()) {
2268
+ if (!$(c) || typeof c.type != "string" || !c.type.trim() || typeof c.id != "number" && typeof c.id != "string") throw Error("工作流包含无效节点");
2269
+ let e = String(c.id);
2270
+ if (s.has(e)) throw Error(`工作流节点 ID 重复:${e}`);
2271
+ s.add(e);
2272
+ let l = t + e, u = a.get(c.type);
2273
+ if (u) {
2274
+ if (i.has(c.type)) throw Error("工作流包含循环子图引用");
2275
+ o(u, `${l}/`, /* @__PURE__ */ new Set([...i, c.type]));
2276
+ continue;
2277
+ }
2278
+ let d = c.pos;
2279
+ if (n.push({
2280
+ id: l,
2281
+ type: c.type,
2282
+ title: typeof c.title == "string" ? c.title : c.type,
2283
+ x: pn(d?.[0], r % 4 * 260),
2284
+ y: pn(d?.[1], Math.floor(r / 4) * 110),
2285
+ properties: $(c.properties) ? c.properties : {},
2286
+ widgets: Array.isArray(c.widgets_values) ? c.widgets_values : []
2287
+ }), n.length > 1e4) throw Error("工作流超过 10000 个节点,无法预览");
2288
+ }
2289
+ for (let n of Array.isArray(e.links) ? e.links : []) Array.isArray(n) && n.length >= 5 ? r.push({
2290
+ from: t + n[1],
2291
+ to: t + n[3]
2292
+ }) : $(n) && n.origin_id !== void 0 && n.target_id !== void 0 && r.push({
2293
+ from: t + n.origin_id,
2294
+ to: t + n.target_id
2295
+ });
2296
+ };
2297
+ if (o(e, "", /* @__PURE__ */ new Set()), !n.length) throw Error("工作流中没有可预览的节点");
2298
+ return {
2299
+ name: t,
2300
+ format: "workflow",
2301
+ source: e,
2302
+ nodes: n,
2303
+ links: r
2304
+ };
2305
+ }
2306
+ let i = $(e.prompt) ? e.prompt : e;
2307
+ for (let [e, t] of Object.entries(i)) {
2308
+ if (!$(t) || typeof t.class_type != "string" || !t.class_type.trim()) continue;
2309
+ let i = n.length, a = $(t.inputs) ? t.inputs : {};
2310
+ n.push({
2311
+ id: e,
2312
+ type: t.class_type,
2313
+ title: $(t._meta) && typeof t._meta.title == "string" ? t._meta.title : t.class_type,
2314
+ x: i % 4 * 260,
2315
+ y: Math.floor(i / 4) * 110,
2316
+ properties: {},
2317
+ inputs: a,
2318
+ widgets: Object.values(a).filter((e) => !Array.isArray(e))
2319
+ });
2320
+ for (let t of Object.values(a)) Array.isArray(t) && t.length === 2 && (typeof t[0] == "string" || typeof t[0] == "number") && Number.isInteger(t[1]) && r.push({
2321
+ from: String(t[0]),
2322
+ to: e
2323
+ });
2324
+ }
2325
+ if (!n.length) throw Error("未找到 ComfyUI nodes 或 API prompt");
2326
+ if (n.length > 1e4) throw Error("工作流超过 10000 个节点,无法预览");
2327
+ return {
2328
+ name: t,
2329
+ format: "prompt",
2330
+ source: i,
2331
+ nodes: n,
2332
+ links: r
2333
+ };
2334
+ }
2335
+ async function hn(e) {
2336
+ if (e.size > 33554432) throw Error("工作流文件不能超过 32 MiB");
2337
+ let t;
2338
+ if (e.name.toLowerCase().endsWith(".png")) {
2339
+ let n = await dn(await e.arrayBuffer());
2340
+ if (t = n.workflow || n.prompt, !t) throw Error("PNG 中没有 ComfyUI 工作流元数据");
2341
+ } else if (e.name.toLowerCase().endsWith(".json")) t = await e.text();
2342
+ else throw Error("请选择 JSON 工作流或带工作流的 PNG 图片");
2343
+ return gn(t, e.name);
2344
+ }
2345
+ function gn(e, t) {
2346
+ let n;
2347
+ try {
2348
+ n = JSON.parse(e.replace(/^\uFEFF/, ""));
2349
+ } catch {
2350
+ throw Error("工作流 JSON 格式无效");
2351
+ }
2352
+ return mn(n, t);
2353
+ }
2354
+ //#endregion
2355
+ //#region packages/plugins/comfyui/workflow-nodes.ts
2356
+ function _n(e) {
2357
+ return e.trim().replace(/^git@([^:]+):/, "https://$1/").replace(/^https?:\/\//, "").replace(/[?#].*$/, "").replace(/\/+$/, "").replace(/\.git$/, "").toLowerCase();
2358
+ }
2359
+ function vn(e, t) {
2360
+ if (!$(t) || !Object.keys(t).length || !Object.values(t).every($)) throw Error("ComfyUI 返回了无效的节点列表,无法判断缺失节点");
2361
+ let n = /* @__PURE__ */ new Map();
2362
+ for (let r of e.nodes) !fn.has(r.type) && !Object.hasOwn(t, r.type) && n.set(r.type, (n.get(r.type) ?? 0) + 1);
2363
+ return [...n].map(([e, t]) => ({
2364
+ type: e,
2365
+ count: t
2366
+ }));
2367
+ }
2368
+ function yn(e, t, n, r, i) {
2369
+ if (!$(n) || !Object.values(n).some((e) => Array.isArray(e) && Array.isArray(e[0]))) throw Error("节点来源索引格式无效");
2370
+ let a = new Map(r.map((e) => [_n(e.gitUrl), e])), o = /* @__PURE__ */ new Map();
2371
+ for (let [e, t] of Object.entries(n)) {
2372
+ if (!Array.isArray(t) || !Array.isArray(t[0])) continue;
2373
+ let n = a.get(_n(e));
2374
+ if (n) for (let e of t[0]) {
2375
+ if (typeof e != "string") continue;
2376
+ let t = o.get(e) ?? /* @__PURE__ */ new Map();
2377
+ t.set(_n(n.gitUrl), n), o.set(e, t);
2378
+ }
2379
+ }
2380
+ return t.map((t) => {
2381
+ let n = e.nodes.filter((e) => e.type === t.type).map((e) => e.properties), a = n.some((e) => e.cnr_id === "comfy-core"), s = new Map(o.get(t.type)), c = r.filter((e) => n.some((t) => typeof t.cnr_id == "string" && e.id === t.cnr_id || typeof t.aux_id == "string" && _n(e.gitUrl) === `github.com/${t.aux_id.toLowerCase()}`));
2382
+ for (let e of c) s.set(_n(e.gitUrl), e);
2383
+ let l = a ? [] : c.length === 1 ? c : [...s.values()], u = i.find((e) => e.gitRemoteUrl && l.some((t) => _n(t.gitUrl) === _n(e.gitRemoteUrl)));
2384
+ return {
2385
+ ...t,
2386
+ core: a,
2387
+ candidates: l,
2388
+ installed: u
2389
+ };
2390
+ });
2391
+ }
2392
+ function bn(e, t = {}) {
2393
+ let n = /* @__PURE__ */ new Map();
2394
+ for (let r of e) {
2395
+ if (r.installed || r.core) continue;
2396
+ let e = r.candidates.length === 1 ? r.candidates[0] : r.candidates.find((e) => e.gitUrl === t[r.type]);
2397
+ e && n.set(_n(e.gitUrl), e);
2398
+ }
2399
+ return [...n.values()];
2400
+ }
2401
+ //#endregion
2402
+ //#region packages/plugins/comfyui/workflow-service.ts
2403
+ var xn = "https://raw.githubusercontent.com/Comfy-Org/ComfyUI-Manager/main/extension-node-map.json", Sn = {
2404
+ directory: "custom_nodes",
2405
+ supportsToggle: !0
2406
+ };
2407
+ function Cn(e) {
2408
+ return T(e.path, String(e.params.baseDirectory || e.path));
2409
+ }
2410
+ async function wn(e, t, n) {
2411
+ n.enabled || await e.extensions.toggle(t.id, n.id, !0);
2412
+ }
2413
+ async function Tn(e, t, n) {
2414
+ if (t.status !== "running") throw Error("请先启动 ComfyUI 再保存工作流");
2415
+ let r = `${(n.name.split(/[\\/]/).pop() || "workflow").replace(/\.(json|png)$/i, "").replace(/[^\p{L}\p{N} _.-]/gu, "_").slice(0, 64) || "workflow"}-${crypto.randomUUID().slice(0, 8)}.json`, i = t.webUrl || Ue(t.params), a = "workflows/" + r, o = await e.http.postJson(`${i.replace(/\/$/, "")}/userdata/${encodeURIComponent(a)}?overwrite=false`, n.source);
2416
+ if (o.status_code < 200 || o.status_code >= 300) throw Error(`保存工作流失败(HTTP ${o.status_code})${o.body.slice(0, 256)}`);
2417
+ return a;
2418
+ }
2419
+ async function En(e, t, n) {
2420
+ if (t.status !== "running") throw Error("请先启动目标 ComfyUI,再检查实际加载的节点");
2421
+ let r = t.webUrl || Ue(t.params);
2422
+ return vn(n, await e.http.getJson(`${r.replace(/\/$/, "")}/object_info`)).map((e) => ({
2423
+ ...e,
2424
+ candidates: [],
2425
+ core: !1
2426
+ }));
2427
+ }
2428
+ async function Dn(e, t, n, r) {
2429
+ if (!r.length) return [];
2430
+ let i = ot.sources[0], [a, o, s] = await Promise.all([
2431
+ e.http.getJson(xn),
2432
+ e.http.getJson(i.url),
2433
+ e.extensions.defaultScan({
2434
+ ...t,
2435
+ path: Cn(t)
2436
+ }, Sn, { strict: !0 })
2437
+ ]), c = i.transform(o);
2438
+ if (!c.length) throw Error("节点市场没有返回可安装的节点包");
2439
+ return yn(n, r, a, c, s);
2440
+ }
2441
+ //#endregion
2442
+ //#region packages/plugins/comfyui/workflow-camera.ts
2443
+ var On = (e) => ({
2444
+ x: e.x + e.width / 2,
2445
+ y: e.y + e.height / 2
2446
+ });
2447
+ function kn(e, t, n, r = On(e)) {
2448
+ let i = Math.min(t.width / 8, 200), a = Math.max(i, Math.min(t.width * 4, e.width * n)), o = a / e.width;
2449
+ return {
2450
+ x: r.x - (r.x - e.x) * o,
2451
+ y: r.y - (r.y - e.y) * o,
2452
+ width: a,
2453
+ height: e.height * o
2454
+ };
2455
+ }
2456
+ function An(e, t, n, r) {
2457
+ return r ? {
2458
+ ...e,
2459
+ x: e.x - t / r,
2460
+ y: e.y - n / r
2461
+ } : e;
2462
+ }
2463
+ //#endregion
2464
+ //#region packages/plugins/comfyui/workflow-presentation.ts
2465
+ var jn = {
2466
+ CLIPTextEncode: ["text"],
2467
+ KSampler: [
2468
+ "seed",
2469
+ "control_after_generate",
2470
+ "steps",
2471
+ "cfg",
2472
+ "sampler_name",
2473
+ "scheduler",
2474
+ "denoise"
2475
+ ],
2476
+ KSamplerAdvanced: [
2477
+ "add_noise",
2478
+ "noise_seed",
2479
+ "control_after_generate",
2480
+ "steps",
2481
+ "cfg",
2482
+ "sampler_name",
2483
+ "scheduler",
2484
+ "start_at_step",
2485
+ "end_at_step",
2486
+ "return_with_leftover_noise"
2487
+ ],
2488
+ EmptyLatentImage: [
2489
+ "width",
2490
+ "height",
2491
+ "batch_size"
2492
+ ],
2493
+ CheckpointLoaderSimple: ["ckpt_name"],
2494
+ LoraLoader: [
2495
+ "lora_name",
2496
+ "strength_model",
2497
+ "strength_clip"
2498
+ ],
2499
+ VAELoader: ["vae_name"]
2500
+ }, Mn = {
2501
+ text: "提示词",
2502
+ positive: "正向提示词",
2503
+ negative: "负向提示词",
2504
+ seed: "随机种子",
2505
+ noise_seed: "噪声种子",
2506
+ steps: "采样步数",
2507
+ cfg: "提示词引导系数",
2508
+ sampler_name: "采样器",
2509
+ scheduler: "调度器",
2510
+ denoise: "降噪强度",
2511
+ control_after_generate: "生成后种子操作",
2512
+ width: "宽度",
2513
+ height: "高度",
2514
+ batch_size: "批次数量",
2515
+ ckpt_name: "基础模型",
2516
+ lora_name: "LoRA 模型",
2517
+ vae_name: "VAE 模型",
2518
+ strength_model: "模型强度",
2519
+ strength_clip: "文本编码强度",
2520
+ add_noise: "添加噪声",
2521
+ start_at_step: "起始步数",
2522
+ end_at_step: "结束步数",
2523
+ return_with_leftover_noise: "保留剩余噪声",
2524
+ model: "模型",
2525
+ latent_image: "潜空间图像"
2526
+ };
2527
+ function Nn(e, t) {
2528
+ return Object.entries(e).map(([n, r]) => {
2529
+ let i = Array.isArray(e) ? t && jn[t]?.[Number(n)] || "参数 " + (Number(n) + 1) : n, a = Array.isArray(r) || $(r) ? r : void 0, o = a ? "" : r === !0 ? "开启" : r === !1 ? "关闭" : r === null ? "未设置" : r === "" ? "空字符串" : String(r);
2530
+ return {
2531
+ key: n,
2532
+ label: Mn[i] || i,
2533
+ group: a,
2534
+ text: o,
2535
+ copy: typeof r == "number" || typeof r == "string" && !!r
2536
+ };
2537
+ });
2538
+ }
2539
+ function Pn(e, t = 25) {
2540
+ let n = [""], r = 0;
2541
+ for (let i of e) {
2542
+ let e = i.charCodeAt(0) > 255 ? 2 : 1, a = n.length === 1 ? t : 25;
2543
+ if (r + e > a) {
2544
+ if (n.length === 2) {
2545
+ n[1] += "…";
2546
+ break;
2547
+ }
2548
+ n.push(""), r = 0;
2549
+ }
2550
+ n[n.length - 1] += i, r += e;
2551
+ }
2552
+ return n;
2553
+ }
2554
+ function Fn(e, t) {
2555
+ let n = [];
2556
+ for (let r of [...e].sort((e, t) => e.y - t.y)) {
2557
+ let e = Pn(r.title, t?.has(r.type) ? 21 : 25), i = Nn(r.inputs ?? r.widgets, r.type).filter((e) => !e.group && e.copy).slice(0, 3).map((e) => e.label + " · " + e.text.replace(/\s+/g, " ").slice(0, 48)), a = 18 + e.length * 18 + (r.type === r.title ? 0 : 16) + i.length * 16, o = r.y;
2558
+ for (let e of [...n].sort((e, t) => e.y - t.y)) r.x < e.x + 228 && r.x + 228 > e.x && o < e.y + e.height + 12 && o + a + 12 > e.y && (o = e.y + e.height + 12);
2559
+ n.push({
2560
+ ...r,
2561
+ y: o,
2562
+ height: a,
2563
+ titleLines: e,
2564
+ summary: i
2565
+ });
2566
+ }
2567
+ return n;
2568
+ }
2569
+ //#endregion
2570
+ //#region packages/plugins/comfyui/WorkflowGraph.vue?vue&type=script&setup=true&lang.ts
2571
+ var In = { class: "flex min-h-0 min-w-0 flex-col overflow-hidden rounded-xl border border-border bg-surface-subtle" }, Ln = { class: "workflow-canvas relative min-h-0 flex-1" }, Rn = {
2572
+ role: "group",
2573
+ "aria-label": "画布控制",
2574
+ class: "absolute bottom-3 right-3 z-10 flex items-center gap-0.5 rounded-full border border-border bg-surface-overlay/90 p-1 shadow-sm backdrop-blur-md"
2575
+ }, zn = ["viewBox"], Bn = ["id"], Vn = ["height"], Hn = [
2576
+ "d",
2577
+ "stroke",
2578
+ "stroke-width",
2579
+ "opacity"
2580
+ ], Un = [
2581
+ "transform",
2582
+ "data-node-id",
2583
+ "aria-label",
2584
+ "aria-pressed",
2585
+ "onClick",
2586
+ "onKeydown"
2587
+ ], Wn = ["height"], Gn = [
2588
+ "height",
2589
+ "fill",
2590
+ "stroke",
2591
+ "stroke-width",
2592
+ "stroke-dasharray"
2593
+ ], Kn = ["stroke"], qn = {
2594
+ key: 2,
2595
+ transform: "translate(12 10)",
2596
+ fill: "none",
2597
+ stroke: "var(--kano-danger)",
2598
+ "stroke-width": "1.8",
2599
+ "stroke-linejoin": "round",
2600
+ "stroke-linecap": "round",
2601
+ "aria-hidden": "true"
2602
+ }, Jn = ["clip-path"], Yn = ["x", "y"], Xn = ["y"], Zn = ["y"], Qn = {
2603
+ key: 0,
2604
+ class: "border-t border-border-light p-3 kano-field-hint"
2605
+ }, $n = /*@__PURE__*/ F({
2606
+ __name: "WorkflowGraph",
2607
+ props: {
2608
+ workflow: {},
2609
+ missing: {},
2610
+ selected: {}
2611
+ },
2612
+ emits: ["select"],
2613
+ setup(e, { emit: n }) {
2614
+ let r = e, i = n, a = G(), o = O(() => new Set(r.missing)), s = O(() => r.workflow.nodes.filter((e) => o.value.has(e.type))), c = V(""), l = O(() => {
2615
+ let e = r.workflow.nodes.slice(0, 200), t = r.workflow.nodes.find((e) => e.id === (r.selected || c.value));
2616
+ return t && !e.includes(t) && e.push(t), Fn(e, o.value);
2617
+ }), u = O(() => new Map(l.value.map((e) => [e.id, e]))), d = O(() => r.workflow.links.flatMap((e) => {
2618
+ let t = u.value.get(e.from), n = u.value.get(e.to);
2619
+ return t && n ? [{
2620
+ from: t,
2621
+ to: n,
2622
+ selected: t.id === r.selected || n.id === r.selected
2623
+ }] : [];
2624
+ }).sort((e, t) => Number(e.selected) - Number(t.selected))), f = O(() => {
2625
+ let e = l.value.map((e) => e.x), t = l.value.map((e) => e.y), n = Math.min(...e) - 20, r = Math.min(...t) - 20;
2626
+ return {
2627
+ x: n,
2628
+ y: r,
2629
+ width: Math.max(...e) - n + 240,
2630
+ height: Math.max(...l.value.map((e) => e.y + e.height)) - r + 20
2631
+ };
2632
+ }), p = V(), m = V(f.value);
2633
+ K(() => r.workflow, () => {
2634
+ c.value = "", h();
2635
+ });
2636
+ function h() {
2637
+ m.value = { ...f.value };
2638
+ }
2639
+ function g(e) {
2640
+ m.value = {
2641
+ x: e.x - 160,
2642
+ y: e.y - 90,
2643
+ width: 540,
2644
+ height: e.height + 180
2645
+ };
2646
+ }
2647
+ K(() => r.selected, (e) => {
2648
+ let t = e && u.value.get(e);
2649
+ if (!t) return;
2650
+ let { x: n, y: r, width: i, height: a } = m.value;
2651
+ (t.x + 220 < n || t.x > n + i || t.y + t.height < r || t.y > r + a) && g(t);
2652
+ });
2653
+ function _() {
2654
+ let e = s.value;
2655
+ if (!e.length) return;
2656
+ let t = e[(e.findIndex((e) => e.id === c.value) + 1) % e.length];
2657
+ c.value = t.id;
2658
+ let n = u.value.get(t.id);
2659
+ n && g(n), i("select", t.id);
2660
+ }
2661
+ function v(e) {
2662
+ return /sampler|scheduler/i.test(e) ? "var(--kano-warning)" : /load|model/i.test(e) ? "var(--kano-info)" : /save|preview|decode/i.test(e) ? "var(--kano-success)" : "var(--kano-text-description)";
2663
+ }
2664
+ function y(e) {
2665
+ let t = p.value?.getScreenCTM();
2666
+ if (!t) return;
2667
+ let n = new DOMPoint(e.clientX, e.clientY).matrixTransform(t.inverse());
2668
+ m.value = kn(m.value, f.value, Math.exp(Math.max(-300, Math.min(300, e.deltaY)) * .003), n);
2669
+ }
2670
+ let b;
2671
+ function x(e) {
2672
+ if (e.button !== 0 || !p.value || b) return;
2673
+ let t = p.value.getScreenCTM()?.a;
2674
+ if (!t) return;
2675
+ let n = e.target.closest("[data-node-id]")?.getAttribute("data-node-id") || void 0;
2676
+ b = {
2677
+ id: e.pointerId,
2678
+ x: e.clientX,
2679
+ y: e.clientY,
2680
+ scale: t,
2681
+ frame: m.value,
2682
+ node: n
2683
+ }, p.value.setPointerCapture(e.pointerId);
2684
+ }
2685
+ function S(e) {
2686
+ b?.id === e.pointerId && b && (m.value = An(b.frame, e.clientX - b.x, e.clientY - b.y, b.scale));
2687
+ }
2688
+ function C(e) {
2689
+ b?.id === e.pointerId && b && (b.node && Math.hypot(e.clientX - b.x, e.clientY - b.y) < 4 && i("select", b.node), b = void 0);
2690
+ }
2691
+ return (n, r) => (B(), j("div", In, [M("div", Ln, [M("div", Rn, [
2692
+ P(W(t), {
2693
+ size: "small",
2694
+ icon: "i-lucide-zoom-out",
2695
+ "aria-label": "缩小",
2696
+ title: "缩小",
2697
+ text: "",
2698
+ rounded: "",
2699
+ severity: "secondary",
2700
+ onClick: r[0] ||= (e) => m.value = W(kn)(m.value, f.value, 1.4)
2701
+ }),
2702
+ P(W(t), {
2703
+ size: "small",
2704
+ icon: "i-lucide-zoom-in",
2705
+ "aria-label": "放大",
2706
+ title: "放大",
2707
+ text: "",
2708
+ rounded: "",
2709
+ severity: "secondary",
2710
+ onClick: r[1] ||= (e) => m.value = W(kn)(m.value, f.value, 1 / 1.4)
2711
+ }),
2712
+ P(W(t), {
2713
+ size: "small",
2714
+ icon: "i-lucide-scan",
2715
+ "aria-label": "适应画布",
2716
+ title: "适应画布",
2717
+ text: "",
2718
+ rounded: "",
2719
+ severity: "secondary",
2720
+ onClick: h
2721
+ }),
2722
+ s.value.length ? (B(), k(W(t), {
2723
+ key: 0,
2724
+ size: "small",
2725
+ icon: "i-lucide-locate",
2726
+ "aria-label": "定位下一个缺失节点",
2727
+ title: "定位下一个缺失节点",
2728
+ text: "",
2729
+ rounded: "",
2730
+ severity: "secondary",
2731
+ onClick: _
2732
+ })) : A("", !0)
2733
+ ]), (B(), j("svg", {
2734
+ ref_key: "svg",
2735
+ ref: p,
2736
+ viewBox: `${m.value.x} ${m.value.y} ${m.value.width} ${m.value.height}`,
2737
+ class: "block h-full w-full touch-none select-none cursor-grab active:cursor-grabbing",
2738
+ role: "group",
2739
+ "aria-label": "工作流节点连接预览",
2740
+ onWheel: le(y, ["prevent"]),
2741
+ onPointerdown: x,
2742
+ onPointermove: S,
2743
+ onPointerup: C,
2744
+ onPointercancel: r[2] ||= (e) => L(b) ? b.value = void 0 : b = void 0,
2745
+ onLostpointercapture: r[3] ||= (e) => L(b) ? b.value = void 0 : b = void 0
2746
+ }, [
2747
+ M("defs", null, [(B(!0), j(D, null, H(l.value, (e, t) => (B(), j("clipPath", {
2748
+ id: W(a) + t,
2749
+ key: e.id,
2750
+ clipPathUnits: "userSpaceOnUse"
2751
+ }, [M("rect", {
2752
+ x: "12",
2753
+ y: "0",
2754
+ width: "196",
2755
+ height: e.height
2756
+ }, null, 8, Vn)], 8, Bn))), 128))]),
2757
+ (B(!0), j(D, null, H(d.value, (t, n) => (B(), j("path", {
2758
+ key: n,
2759
+ d: `M ${t.from.x + 220} ${t.from.y + t.from.height / 2} C ${t.from.x + 270} ${t.from.y + t.from.height / 2}, ${t.to.x - 50} ${t.to.y + t.to.height / 2}, ${t.to.x} ${t.to.y + t.to.height / 2}`,
2760
+ fill: "none",
2761
+ stroke: t.selected ? "var(--kano-text-link)" : "var(--kano-text-description)",
2762
+ "stroke-width": t.selected ? 3 : 2,
2763
+ opacity: e.selected && !t.selected ? .35 : 1
2764
+ }, null, 8, Hn))), 128)),
2765
+ (B(!0), j(D, null, H(l.value, (t, n) => (B(), j("g", {
2766
+ key: t.id,
2767
+ transform: `translate(${t.x},${t.y})`,
2768
+ role: "button",
2769
+ tabindex: "0",
2770
+ "data-node-id": t.id,
2771
+ "aria-label": `查看 ${t.title} 的参数`,
2772
+ "aria-pressed": e.selected === t.id,
2773
+ onClick: (e) => e.detail === 0 && i("select", t.id),
2774
+ onKeydown: [ce(le((e) => i("select", t.id), ["prevent"]), ["enter"]), ce(le((e) => i("select", t.id), ["prevent"]), ["space"])]
2775
+ }, [
2776
+ M("title", null, U(t.id) + " · " + U(t.title) + " · " + U(t.type) + U(o.value.has(t.type) ? " · 缺失节点" : ""), 1),
2777
+ e.selected === t.id ? (B(), j("rect", {
2778
+ key: 0,
2779
+ x: "-3",
2780
+ y: "-3",
2781
+ width: "226",
2782
+ height: t.height + 6,
2783
+ rx: "12",
2784
+ fill: "none",
2785
+ stroke: "var(--kano-text-link)",
2786
+ "stroke-width": "3",
2787
+ "aria-hidden": "true"
2788
+ }, null, 8, Wn)) : A("", !0),
2789
+ M("rect", {
2790
+ width: "220",
2791
+ height: t.height,
2792
+ rx: "8",
2793
+ fill: e.selected === t.id ? "var(--kano-bg-selected)" : "var(--kano-surface-group)",
2794
+ stroke: o.value.has(t.type) ? "var(--kano-danger)" : "var(--kano-border)",
2795
+ "stroke-width": o.value.has(t.type) ? 2 : 1,
2796
+ "stroke-dasharray": o.value.has(t.type) ? "6 3" : void 0
2797
+ }, null, 8, Gn),
2798
+ o.value.has(t.type) ? A("", !0) : (B(), j("path", {
2799
+ key: 1,
2800
+ d: "M 8 2 H 212",
2801
+ stroke: v(t.type),
2802
+ "stroke-width": "3",
2803
+ opacity: ".7",
2804
+ "aria-hidden": "true"
2805
+ }, null, 8, Kn)),
2806
+ o.value.has(t.type) ? (B(), j("g", qn, [...r[4] ||= [M("path", { d: "M9 1 17 16H1Z M9 6v4 M9 13h.01" }, null, -1)]])) : A("", !0),
2807
+ M("g", { "clip-path": `url(#${W(a) + n})` }, [
2808
+ (B(!0), j(D, null, H(t.titleLines, (e, n) => (B(), j("text", {
2809
+ key: "title" + n,
2810
+ x: o.value.has(t.type) && n === 0 ? 36 : 12,
2811
+ y: 23 + n * 18,
2812
+ fill: "var(--kano-text-base)",
2813
+ "font-size": "13"
2814
+ }, U(e), 9, Yn))), 128)),
2815
+ t.type === t.title ? A("", !0) : (B(), j("text", {
2816
+ key: 0,
2817
+ x: "12",
2818
+ y: 23 + t.titleLines.length * 18,
2819
+ fill: "var(--kano-text-secondary)",
2820
+ "font-size": "11"
2821
+ }, U(t.type), 9, Xn)),
2822
+ (B(!0), j(D, null, H(t.summary, (e, n) => (B(), j("text", {
2823
+ key: n,
2824
+ x: "12",
2825
+ y: 23 + (t.type === t.title ? 0 : 16) + t.titleLines.length * 18 + n * 16,
2826
+ fill: "var(--kano-text-secondary)",
2827
+ "font-size": "11"
2828
+ }, U(e), 9, Zn))), 128))
2829
+ ], 8, Jn)
2830
+ ], 40, Un))), 128))
2831
+ ], 40, zn))]), e.workflow.nodes.length > 200 ? (B(), j("p", Qn, " 画布显示前 200 个节点及当前选中的节点。 ")) : A("", !0)]));
2832
+ }
2833
+ }), er = (e, t) => {
2834
+ let n = e.__vccOpts || e;
2835
+ for (let [e, r] of t) n[e] = r;
2836
+ return n;
2837
+ }, tr = /*#__PURE__*/ er($n, [["__scopeId", "data-v-72d901db"]]), nr = { class: "min-w-0 divide-y divide-border-light" }, rr = { class: "sr-only" }, ir = { class: "text-xs text-text-muted" }, ar = { class: "mt-0.5 flex min-w-0 items-start justify-between gap-2" }, or = { class: "min-w-0 flex-1 max-h-44 overflow-auto whitespace-pre-wrap break-words [overflow-wrap:anywhere] text-sm leading-6 tabular-nums" }, sr = /* @__PURE__ */ F({
2838
+ __name: "WorkflowParameters",
2839
+ props: {
2840
+ values: {},
2841
+ nodeType: {},
2842
+ nodeNames: {}
2843
+ },
2844
+ setup(e) {
2845
+ let n = e, r = V(50), a = V({}), o = O(() => Nn(n.values, n.nodeType).map((e) => {
2846
+ let t = e.group;
2847
+ return Array.isArray(t) && t.length === 2 && Number.isInteger(t[1]) && n.nodeNames?.[String(t[0])] ? {
2848
+ ...e,
2849
+ group: void 0,
2850
+ text: n.nodeNames[String(t[0])] + " · 输出 " + (Number(t[1]) + 1)
2851
+ } : e;
2852
+ }));
2853
+ return (n, s) => {
2854
+ let l = ie("WorkflowParameters", !0);
2855
+ return B(), j(D, null, [M("dl", nr, [(B(!0), j(D, null, H(o.value.slice(0, r.value), (t) => (B(), j("div", {
2856
+ key: t.key,
2857
+ class: "group py-2"
2858
+ }, [t.group ? (B(), j(D, { key: 0 }, [M("dt", rr, U(t.label), 1), M("dd", null, [P(W(c), {
2859
+ open: a.value[t.key],
2860
+ "onUpdate:open": (e) => a.value[t.key] = e,
2861
+ variant: "subtle",
2862
+ title: t.label
2863
+ }, {
2864
+ default: q(() => [a.value[t.key] ? (B(), k(l, {
2865
+ key: 0,
2866
+ values: t.group,
2867
+ "node-names": e.nodeNames
2868
+ }, null, 8, ["values", "node-names"])) : A("", !0)]),
2869
+ _: 2
2870
+ }, 1032, [
2871
+ "open",
2872
+ "onUpdate:open",
2873
+ "title"
2874
+ ])])], 64)) : (B(), j(D, { key: 1 }, [M("dt", ir, U(t.label), 1), M("dd", ar, [M("span", or, U(t.text), 1), t.copy ? (B(), k(W(i), {
2875
+ key: 0,
2876
+ text: t.text,
2877
+ label: "复制 " + t.label,
2878
+ class: R(["-mt-0.5 shrink-0", { "kano-row-actions": t.text.length < 80 && !t.text.includes("\n") }])
2879
+ }, null, 8, [
2880
+ "text",
2881
+ "label",
2882
+ "class"
2883
+ ])) : A("", !0)])], 64))]))), 128))]), o.value.length > r.value ? (B(), k(W(t), {
2884
+ key: 0,
2885
+ label: "显示更多参数",
2886
+ size: "small",
2887
+ class: "mt-2",
2888
+ text: "",
2889
+ severity: "secondary",
2890
+ onClick: s[0] ||= (e) => r.value += 50
2891
+ })) : A("", !0)], 64);
2892
+ };
2893
+ }
2894
+ }), cr = /\.(?:safetensors|gguf|ckpt|pt|pth|bin|onnx|sft|pt2)$/i, lr = new Map(Object.entries({
2895
+ checkpointloadersimple: "checkpoints",
2896
+ checkpointloader: "checkpoints",
2897
+ loraloader: "loras",
2898
+ loraloaderonly: "loras",
2899
+ loraloadermodelonly: "loras",
2900
+ vaeloader: "vae",
2901
+ unetloader: "diffusion_models",
2902
+ unetloadergguf: "diffusion_models",
2903
+ cliploader: "text_encoders",
2904
+ dualcliploader: "text_encoders",
2905
+ triplecliploader: "text_encoders",
2906
+ quadruplecliploader: "text_encoders",
2907
+ cliploadergguf: "text_encoders",
2908
+ dualcliploadergguf: "text_encoders",
2909
+ controlnetloader: "controlnet",
2910
+ clipvisionloader: "clip_vision",
2911
+ upscalemodelloader: "upscale_models",
2912
+ ipadaptermodelloader: "ipadapter",
2913
+ stylemodelloader: "style_models",
2914
+ latentupscalemodelloader: "latent_upscale_models",
2915
+ audioencoderloader: "audio_encoders"
2916
+ })), ur = new Map(Object.entries({
2917
+ ckpt_name: "checkpoints",
2918
+ lora_name: "loras",
2919
+ vae_name: "vae",
2920
+ unet_name: "diffusion_models",
2921
+ control_net_name: "controlnet",
2922
+ clip_name: "text_encoders",
2923
+ clip_vision_name: "clip_vision"
2924
+ })), dr = new Map(Object.entries({
2925
+ diffusion_models: ["diffusion_models", "unet"],
2926
+ unet: ["unet", "diffusion_models"],
2927
+ clip: ["clip", "text_encoders"],
2928
+ text_encoders: ["text_encoders", "clip"],
2929
+ controlnet: ["controlnet", "t2i_adapter"]
2930
+ }));
2931
+ function fr(e) {
2932
+ if (typeof e != "string" || !e || /[<>:"|?*]/.test(e) || [...e].some((e) => e.charCodeAt(0) < 32)) return;
2933
+ let t = e.replaceAll("\\", "/").split("/");
2934
+ if (!t.some((e) => !e || /^\.+$/.test(e) || /[. ]$/.test(e))) return t.join("/");
2935
+ }
2936
+ function pr(e) {
2937
+ if (typeof e == "string") try {
2938
+ let t = new URL(e);
2939
+ if (["http:", "https:"].includes(t.protocol)) return t.href;
2940
+ } catch {}
2941
+ }
2942
+ function mr(e) {
2943
+ let t = /* @__PURE__ */ new Map();
2944
+ function n(e, n, r) {
2945
+ let i = fr(e);
2946
+ if (!i || !cr.test(i)) return;
2947
+ let a = n + "/" + i;
2948
+ (!t.has(a) || r && !t.get(a)?.url) && t.set(a, {
2949
+ name: i,
2950
+ directory: n,
2951
+ url: r
2952
+ });
2953
+ }
2954
+ for (let t of e.nodes) {
2955
+ let e = lr.get(t.type.toLowerCase()) || "", r = /* @__PURE__ */ new Set();
2956
+ for (let i of Array.isArray(t.properties.models) ? t.properties.models : []) {
2957
+ if (!$(i)) continue;
2958
+ let t = fr(i.name), a = i.directory === void 0 ? e : fr(i.directory);
2959
+ t && a !== void 0 && (n(t, a.replace(/^models\//, ""), pr(i.url)), r.add(t));
2960
+ }
2961
+ if (t.inputs) for (let [i, a] of Object.entries(t.inputs)) {
2962
+ let o = ur.get(i.replace(/^(clip_name)\d+$/, "$1")) || e;
2963
+ (o || /loader/i.test(t.type)) && !r.has(fr(a) || "") && n(a, o);
2964
+ }
2965
+ else for (let i of t.widgets) !r.has(fr(i) || "") && (e || /loader/i.test(t.type)) && n(i, e);
2966
+ }
2967
+ return [...t.values()];
2968
+ }
2969
+ function hr(e, t, n = []) {
2970
+ return [...(dr.get(t.directory) || [t.directory]).map((n) => e.replace(/[\\/]+$/, "") + "/" + [n, t.name].filter(Boolean).join("/")), ...n.map((e) => e.replace(/[\\/]+$/, "") + "/" + t.name)];
2971
+ }
2972
+ function gr(e, t, n, r = () => []) {
2973
+ let i = /^[a-z]:[\\/]/i.test(n) || /^[\\/]{2}/.test(n), a = (e) => {
2974
+ let t = e.replaceAll("\\", "/");
2975
+ return i ? t.toLowerCase() : t;
2976
+ }, o = new Set(t.map((e) => a(e.full_path)));
2977
+ return e.map((e) => e.directory ? hr(n, e, r(e.directory)).some((e) => o.has(a(e))) : t.some((t) => a(t.full_path).endsWith("/" + a(e.name)) && [n, ...r("")].some((e) => a(t.full_path).startsWith(a(e).replace(/\/$/, "") + "/"))));
2978
+ }
2979
+ function _r(e) {
2980
+ let t = e.replaceAll("\\", "/").split("/").at(-1).toLowerCase(), n = t.lastIndexOf(".");
2981
+ return {
2982
+ stem: t.slice(0, n).replace(/[^\p{L}\p{N}]/gu, ""),
2983
+ ext: t.slice(n)
2984
+ };
2985
+ }
2986
+ function vr(e) {
2987
+ return new Set(Array.from({ length: Math.max(0, e.length - 1) }, (t, n) => e.slice(n, n + 2)));
2988
+ }
2989
+ function yr(e, t, n) {
2990
+ let r = _r(e.name), i = vr(r.stem), a = .82, o;
2991
+ for (let e of t) {
2992
+ let t = e.full_path.replaceAll("\\", "/");
2993
+ if (!n.some((e) => t.startsWith(e.replaceAll("\\", "/").replace(/\/$/, "") + "/"))) continue;
2994
+ let s = _r(t);
2995
+ if (s.ext !== r.ext) continue;
2996
+ let c = t.split("/").at(-1);
2997
+ if (s.stem === r.stem) return c;
2998
+ if (r.stem.length < 5 || Math.min(s.stem.length, r.stem.length) / Math.max(s.stem.length, r.stem.length) < .7) continue;
2999
+ let l = vr(s.stem), u = 0;
3000
+ for (let e of i) l.has(e) && u++;
3001
+ let d = 2 * u / (i.size + l.size);
3002
+ d > a && (a = d, o = c);
3003
+ }
3004
+ return o;
3005
+ }
3006
+ //#endregion
3007
+ //#region packages/plugins/comfyui/WorkflowModels.vue?vue&type=script&setup=true&lang.ts
3008
+ var br = { class: "flex flex-col gap-3" }, xr = { class: "kano-settings-group" }, Sr = { class: "min-w-0 break-words [overflow-wrap:anywhere] text-sm" }, Cr = {
3009
+ key: 0,
3010
+ class: "inline-flex shrink-0 items-center gap-1 text-xs text-text-secondary"
3011
+ }, wr = {
3012
+ key: 1,
3013
+ role: "status",
3014
+ class: "shrink-0 text-xs text-text-secondary"
3015
+ }, Tr = {
3016
+ key: 3,
3017
+ class: "kano-field-hint w-full break-all"
3018
+ }, Er = { class: "flex flex-wrap items-center gap-2" }, Dr = {
3019
+ key: 0,
3020
+ role: "alert",
3021
+ class: "whitespace-pre-wrap break-words text-sm text-danger"
3022
+ }, Or = {
3023
+ key: 1,
3024
+ class: "kano-field-hint"
3025
+ }, kr = /* @__PURE__ */ F({
3026
+ __name: "WorkflowModels",
3027
+ props: {
3028
+ api: {},
3029
+ app: {},
3030
+ workflow: {}
3031
+ },
3032
+ emits: ["close"],
3033
+ setup(e, { emit: n }) {
3034
+ let r = e, i = n, a = O(() => mr(r.workflow)), o = O(() => r.app && qe(r.app)), s = V([]), c = V([]), l = V(/* @__PURE__ */ new Set()), u = V(/* @__PURE__ */ new Set()), d = V(!1), f = O(() => a.value.flatMap((e, t) => e.url && s.value[t] === !1 && !l.value.has(t) ? [t] : [])), p = V(""), m = V(!1), h = 0;
3035
+ ne(() => h++), K([
3036
+ () => r.app?.id,
3037
+ () => JSON.stringify(r.app?.params),
3038
+ o,
3039
+ a
3040
+ ], () => {
3041
+ h++, l.value.clear(), u.value.clear(), d.value = !1, g();
3042
+ }, { immediate: !0 });
3043
+ async function g() {
3044
+ let e = ++h;
3045
+ s.value = [], c.value = [], p.value = "", m.value = !1;
3046
+ let t = r.app, n = o.value, i = a.value;
3047
+ if (t && n && i.length) {
3048
+ m.value = !0;
3049
+ try {
3050
+ let a = await r.api.models.list(t.id), o = (e) => Ce(t, e), l = gr(i, a, n, o), u = [];
3051
+ for (let [t, s] of i.entries()) {
3052
+ if (e !== h) return;
3053
+ if (!l[t] && s.directory) {
3054
+ for (let e of hr(n, s, o(s.directory))) if (await r.api.fs.exists(e) && !await r.api.fs.isDir(e)) {
3055
+ l[t] = !0;
3056
+ break;
3057
+ }
3058
+ }
3059
+ l[t] || (u[t] = yr(s, a, s.directory ? hr(n, s, o(s.directory)).map((e) => e.slice(0, -s.name.length - 1)) : [n, ...o("")]));
3060
+ }
3061
+ e === h && (s.value = l, c.value = u);
3062
+ } catch (t) {
3063
+ e === h && (p.value = String(t));
3064
+ } finally {
3065
+ e === h && (m.value = !1);
3066
+ }
3067
+ }
3068
+ }
3069
+ async function _(e, t) {
3070
+ let n = r.app?.id, a = o.value;
3071
+ if (!n || !a || u.value.has(t) || l.value.has(t) || s.value[t] !== !1) return;
3072
+ let c = h;
3073
+ u.value.add(t), d.value || (p.value = "");
3074
+ try {
3075
+ if (e.url) {
3076
+ let i = hr(a, e)[0], o = i.lastIndexOf("/");
3077
+ await r.api.downloads.enqueue({
3078
+ appId: n,
3079
+ url: e.url,
3080
+ directory: i.slice(0, o),
3081
+ filename: i.slice(o + 1)
3082
+ }), c === h && l.value.add(t);
3083
+ } else await r.api.models.openMarket(e.name.split("/").at(-1), n, Je(e.directory)), c === h && i("close");
3084
+ } catch (t) {
3085
+ c === h && (p.value = [p.value, e.name + ":" + String(t)].filter(Boolean).join("\n"));
3086
+ } finally {
3087
+ c === h && u.value.delete(t);
3088
+ }
3089
+ }
3090
+ async function v() {
3091
+ if (d.value || u.value.size) return;
3092
+ let e = h, t = f.value;
3093
+ d.value = !0, p.value = "";
3094
+ try {
3095
+ for (let n of t) {
3096
+ if (e !== h) break;
3097
+ await _(a.value[n], n);
3098
+ }
3099
+ } finally {
3100
+ e === h && (d.value = !1);
3101
+ }
3102
+ }
3103
+ return (n, r) => a.value.length ? (B(), k(W(y), {
3104
+ key: 0,
3105
+ title: `引用模型(${a.value.length})`
3106
+ }, {
3107
+ default: q(() => [M("div", br, [
3108
+ M("div", xr, [(B(!0), j(D, null, H(a.value, (e, n) => (B(), j("div", {
3109
+ key: e.directory + "/" + e.name,
3110
+ class: "kano-settings-row flex flex-wrap items-center justify-between gap-2"
3111
+ }, [
3112
+ M("span", Sr, U([e.directory, e.name].filter(Boolean).join("/")), 1),
3113
+ s.value[n] ? (B(), j("span", Cr, [...r[0] ||= [M("span", {
3114
+ class: "i-lucide-circle-check size-3.5 shrink-0 text-success",
3115
+ "aria-hidden": "true"
3116
+ }, null, -1), ee("已安装 ", -1)]])) : l.value.has(n) ? (B(), j("span", wr, "已加入下载")) : s.value[n] === !1 ? (B(), k(W(t), {
3117
+ key: 2,
3118
+ size: "small",
3119
+ class: "shrink-0",
3120
+ label: e.url ? "加入下载" : "在模型市场搜索",
3121
+ severity: "secondary",
3122
+ loading: u.value.has(n),
3123
+ disabled: d.value,
3124
+ onClick: (t) => _(e, n)
3125
+ }, null, 8, [
3126
+ "label",
3127
+ "loading",
3128
+ "disabled",
3129
+ "onClick"
3130
+ ])) : A("", !0),
3131
+ c.value[n] && !s.value[n] ? (B(), j("p", Tr, " 本地有相似文件:" + U(c.value[n]), 1)) : A("", !0)
3132
+ ]))), 128))]),
3133
+ M("div", Er, [f.value.length ? (B(), k(W(t), {
3134
+ key: 0,
3135
+ size: "small",
3136
+ label: "全部加入下载",
3137
+ severity: "secondary",
3138
+ loading: d.value,
3139
+ disabled: u.value.size > 0,
3140
+ onClick: v
3141
+ }, null, 8, ["loading", "disabled"])) : A("", !0), e.app ? (B(), k(W(t), {
3142
+ key: 1,
3143
+ size: "small",
3144
+ label: "重新检查模型",
3145
+ severity: "secondary",
3146
+ loading: m.value,
3147
+ disabled: u.value.size > 0 || d.value,
3148
+ onClick: g
3149
+ }, null, 8, ["loading", "disabled"])) : A("", !0)]),
3150
+ p.value ? (B(), j("p", Dr, U(p.value), 1)) : A("", !0)
3151
+ ])]),
3152
+ _: 1
3153
+ }, 8, ["title"])) : (B(), j("p", Or, "此工作流未引用可识别的模型文件。"));
3154
+ }
3155
+ });
3156
+ //#endregion
3157
+ //#region packages/plugins/comfyui/workflow-offline.ts
3158
+ function Ar(e, t, n) {
3159
+ let r = /* @__PURE__ */ new Map();
3160
+ if ($(n)) {
3161
+ for (let [e, t] of Object.entries(n)) if (Array.isArray(t) && Array.isArray(t[0])) for (let n of t[0]) {
3162
+ if (typeof n != "string") continue;
3163
+ let t = r.get(n) ?? /* @__PURE__ */ new Set();
3164
+ t.add(_n(e)), r.set(n, t);
3165
+ }
3166
+ }
3167
+ let i = {
3168
+ installed: 0,
3169
+ unknown: 0,
3170
+ issues: []
3171
+ }, a = /* @__PURE__ */ new Set();
3172
+ for (let n of e.nodes) {
3173
+ if (a.has(n.type) || fn.has(n.type)) continue;
3174
+ a.add(n.type);
3175
+ let { cnr_id: e, aux_id: o } = n.properties;
3176
+ if (e === "comfy-core") {
3177
+ i.unknown++;
3178
+ continue;
3179
+ }
3180
+ let s = typeof o == "string" ? /* @__PURE__ */ new Set([_n("github.com/" + o)]) : r.get(n.type), c = t.filter((t) => typeof e == "string" && t.id.toLowerCase() === e.toLowerCase() || t.gitRemoteUrl && s?.has(_n(t.gitRemoteUrl)) || !t.gitRemoteUrl && s && [...s].some((e) => e.split("/").at(-1) === t.id.toLowerCase()));
3181
+ c.some((e) => e.enabled) ? i.installed++ : c.length ? i.issues.push({
3182
+ type: n.type,
3183
+ reason: "对应节点包已禁用"
3184
+ }) : s?.size || e ? i.issues.push({
3185
+ type: n.type,
3186
+ reason: "未找到对应的节点包目录"
3187
+ }) : i.unknown++;
3188
+ }
3189
+ return i;
3190
+ }
3191
+ async function jr(e, t, n) {
3192
+ let r = await e.extensions.defaultScan({
3193
+ ...t,
3194
+ path: Cn(t)
3195
+ }, Sn, { strict: !0 }), i = r.find((e) => [e.id, e.gitRemoteUrl && _n(e.gitRemoteUrl).split("/").at(-1)].some((e) => e?.toLowerCase() === "comfyui-manager")), a;
3196
+ if (i) {
3197
+ let t = T(i.path, "extension-node-map.json");
3198
+ await e.fs.exists(t) && (a = JSON.parse(await e.fs.readFile(t)));
3199
+ }
3200
+ return Ar(n, r, a);
3201
+ }
3202
+ //#endregion
3203
+ //#region packages/plugins/comfyui/WorkflowPreview.vue?vue&type=script&setup=true&lang.ts
3204
+ var Mr = { class: "workflow-preview flex flex-col gap-5" }, Nr = { class: "flex flex-wrap items-center justify-between gap-3" }, Pr = { class: "min-w-0" }, Fr = { class: "kano-field-label break-all" }, Ir = { class: "kano-field-hint tabular-nums" }, Lr = {
3205
+ key: 0,
3206
+ class: "text-sm text-warning"
3207
+ }, Rr = { class: "flex flex-wrap items-center gap-2" }, zr = {
3208
+ key: 1,
3209
+ role: "alert",
3210
+ class: "whitespace-pre-wrap break-words text-sm text-danger"
3211
+ }, Br = {
3212
+ key: 2,
3213
+ role: "status",
3214
+ class: "break-words text-sm text-text-secondary"
3215
+ }, Vr = {
3216
+ key: 3,
3217
+ "aria-live": "polite",
3218
+ class: "flex flex-col gap-2 text-sm"
3219
+ }, Hr = {
3220
+ key: 0,
3221
+ class: "text-text-secondary"
3222
+ }, Ur = {
3223
+ key: 1,
3224
+ role: "alert",
3225
+ class: "whitespace-pre-wrap break-words text-danger"
3226
+ }, Wr = { class: "workflow-layout" }, Gr = {
3227
+ class: "min-w-0 space-y-4 overflow-auto",
3228
+ "aria-label": "工作流检视栏"
3229
+ }, Kr = {
3230
+ key: 0,
3231
+ class: "space-y-3"
3232
+ }, qr = { class: "kano-field-label break-all" }, Jr = {
3233
+ key: 0,
3234
+ class: "kano-field-hint break-all"
3235
+ }, Yr = {
3236
+ key: 2,
3237
+ class: "kano-field-hint"
3238
+ }, Xr = {
3239
+ key: 1,
3240
+ class: "space-y-3"
3241
+ }, Zr = {
3242
+ key: 0,
3243
+ class: "kano-field-hint"
3244
+ }, Qr = {
3245
+ key: 1,
3246
+ role: "status",
3247
+ class: "flex items-center gap-1.5 text-sm text-text-secondary"
3248
+ }, $r = {
3249
+ key: 2,
3250
+ class: "space-y-2"
3251
+ }, ei = { class: "kano-field-hint" }, ti = {
3252
+ key: 0,
3253
+ class: "kano-settings-group"
3254
+ }, ni = { class: "kano-field-label break-all" }, ri = { class: "kano-field-hint" }, ii = { class: "kano-settings-group" }, ai = { class: "min-w-[min(12rem,100%)] flex-1" }, oi = { class: "kano-field-label break-all" }, si = { class: "tabular-nums text-text-description" }, ci = {
3255
+ key: 0,
3256
+ class: "text-xs text-warning"
3257
+ }, li = {
3258
+ key: 1,
3259
+ class: "text-xs text-warning"
3260
+ }, ui = {
3261
+ key: 2,
3262
+ class: "kano-field-hint"
3263
+ }, di = {
3264
+ key: 3,
3265
+ class: "kano-field-hint break-all"
3266
+ }, fi = /*#__PURE__*/ er(/* @__PURE__ */ F({
3267
+ __name: "WorkflowPreview",
3268
+ props: {
3269
+ api: {},
3270
+ workflow: {},
3271
+ initialAppId: {},
3272
+ fixedApp: {}
3273
+ },
3274
+ emits: ["close"],
3275
+ setup(e, { emit: n }) {
3276
+ let r = e, i = n, a = O(() => r.fixedApp ? [r.fixedApp] : r.api.apps.list()), o = V(r.initialAppId || (a.value.length === 1 ? a.value[0].id : "")), s = O(() => a.value.find((e) => e.id === o.value)), c = V(""), l = V(""), u = 0, d = V("nodes"), f = [
3277
+ {
3278
+ value: "nodes",
3279
+ label: "缺失节点"
3280
+ },
3281
+ {
3282
+ value: "models",
3283
+ label: "引用模型"
3284
+ },
3285
+ {
3286
+ value: "parameters",
3287
+ label: "节点参数"
3288
+ }
3289
+ ], p = V(), m = V(""), h = O(() => r.workflow.nodes.find((e) => e.id === m.value));
3290
+ async function g(e) {
3291
+ m.value = e, d.value = "parameters", await te(), p.value?.focus({ preventScroll: !0 });
3292
+ }
3293
+ K([o, () => r.workflow], () => {
3294
+ u++, l.value = "";
3295
+ });
3296
+ async function b(e, t) {
3297
+ let n = s.value;
3298
+ if (!n || c.value || T.value) return;
3299
+ c.value = e;
3300
+ let a = u;
3301
+ E.value = "";
3302
+ try {
3303
+ if (e === "launch") n.status === "running" ? await r.api.apps.restart(n.id) : await r.api.apps.start(n.id);
3304
+ else if (e === "enable" && t?.installed) {
3305
+ let e = t.installed;
3306
+ await wn(r.api, n, e), n.id === o.value && (x.value = x.value.map((t) => t.installed?.id === e.id ? {
3307
+ ...t,
3308
+ installed: {
3309
+ ...t.installed,
3310
+ enabled: !0
3311
+ }
3312
+ } : t));
3313
+ } else if (e === "save") {
3314
+ if (!l.value) {
3315
+ let e = await Tn(r.api, n, r.workflow);
3316
+ if (a !== u) return;
3317
+ l.value = e;
3318
+ }
3319
+ await r.api.apps.openTab(n.id, "webview"), a === u && i("close");
3320
+ }
3321
+ } catch (e) {
3322
+ E.value = e instanceof Error ? e.message : String(e);
3323
+ } finally {
3324
+ c.value = "";
3325
+ }
3326
+ }
3327
+ let x = ae([]), S = V(!1), C = ae(), w = V(!1), T = V(!1), E = V(""), N = V(""), F = V({}), I = ae(), L = ae([]), R = O(() => bn(x.value, F.value)), z = O(() => !!(I.value?.failures.length || I.value?.dependenciesError)), re = O(() => z.value || !!E.value && !I.value && L.value.length > 0), ie = O(() => Object.fromEntries(r.workflow.nodes.map((e) => [e.id, e.title]))), G = O(() => [...new Set(r.workflow.nodes.map((e) => e.type))]), ce = O(() => x.value.map((e) => e.type)), le = O(() => JSON.stringify(s.value && [
3328
+ s.value.id,
3329
+ s.value.path,
3330
+ s.value.params,
3331
+ s.value.pythonPath,
3332
+ s.value.webUrl,
3333
+ s.value.processId,
3334
+ s.value.status
3335
+ ])), J = 0;
3336
+ K([le, () => r.workflow], () => {
3337
+ J++, w.value = !1, S.value = !1, x.value = [], F.value = {}, E.value = "", T.value || (I.value = void 0, L.value = []), C.value = void 0, s.value && [
3338
+ "running",
3339
+ "stopped",
3340
+ "error"
3341
+ ].includes(s.value.status) && ue();
3342
+ }, { immediate: !0 }), ne(() => {
3343
+ u++, J++;
3344
+ });
3345
+ async function ue() {
3346
+ if (!s.value || w.value || T.value) return;
3347
+ let e = ++J, t = s.value;
3348
+ w.value = !0, S.value = !1, x.value = [], F.value = {}, I.value = void 0, L.value = [], C.value = void 0, E.value = "";
3349
+ try {
3350
+ if (t.status !== "running") {
3351
+ let n = await jr(r.api, t, r.workflow);
3352
+ e === J && (C.value = n);
3353
+ return;
3354
+ }
3355
+ let n = await En(r.api, t, r.workflow);
3356
+ if (e !== J) return;
3357
+ x.value = n, S.value = !0;
3358
+ let i = await Dn(r.api, t, r.workflow, n);
3359
+ e === J && (x.value = i);
3360
+ } catch (t) {
3361
+ e === J && (E.value = t instanceof Error ? t.message : String(t));
3362
+ } finally {
3363
+ e === J && (w.value = !1);
3364
+ }
3365
+ }
3366
+ async function de(e = !1) {
3367
+ if (!s.value || T.value || w.value) return;
3368
+ let t = s.value, n = e ? L.value : R.value;
3369
+ if (n.length) {
3370
+ L.value = [...n], T.value = !0, E.value = "", I.value = void 0;
3371
+ try {
3372
+ I.value = await r.api.extensions.installBatch(t.id, n, (e) => {
3373
+ N.value = e;
3374
+ });
3375
+ } catch (e) {
3376
+ E.value = e instanceof Error ? e.message : String(e);
3377
+ } finally {
3378
+ T.value = !1, N.value = "";
3379
+ }
3380
+ }
3381
+ }
3382
+ return (n, r) => (B(), j("div", Mr, [
3383
+ M("div", Nr, [M("div", Pr, [M("p", Fr, U(e.workflow.name), 1), M("p", Ir, U(e.workflow.nodes.length) + " 个节点 · " + U(G.value.length) + " 种类型 · " + U(e.workflow.links.length) + " 条连接 ", 1)]), e.fixedApp ? A("", !0) : (B(), k(W(v), {
3384
+ key: 0,
3385
+ modelValue: o.value,
3386
+ "onUpdate:modelValue": r[0] ||= (e) => o.value = e,
3387
+ options: a.value,
3388
+ "option-label": "name",
3389
+ "option-value": "id",
3390
+ placeholder: "选择 ComfyUI 应用",
3391
+ "aria-label": "检查和安装节点的目标应用",
3392
+ class: "kano-select-adaptive",
3393
+ disabled: T.value || !!c.value
3394
+ }, null, 8, [
3395
+ "modelValue",
3396
+ "options",
3397
+ "disabled"
3398
+ ]))]),
3399
+ a.value.length ? A("", !0) : (B(), j("p", Lr, " 请先在 Kano 中添加 ComfyUI 应用。当前仍可预览工作流。 ")),
3400
+ M("div", Rr, [
3401
+ s.value ? (B(), k(W(t), {
3402
+ key: 0,
3403
+ label: s.value.status === "running" ? l.value ? "打开 WebUI" : "保存工作流并打开 WebUI" : "启动 ComfyUI",
3404
+ loading: c.value === (s.value.status === "running" ? "save" : "launch"),
3405
+ disabled: !!c.value || T.value || s.value.status !== "running" && (w.value || !["stopped", "error"].includes(s.value.status)),
3406
+ onClick: r[1] ||= (e) => b(s.value.status === "running" ? "save" : "launch")
3407
+ }, null, 8, [
3408
+ "label",
3409
+ "loading",
3410
+ "disabled"
3411
+ ])) : A("", !0),
3412
+ s.value?.status === "running" ? (B(), k(W(t), {
3413
+ key: 1,
3414
+ label: "重启 ComfyUI",
3415
+ severity: "secondary",
3416
+ loading: c.value === "launch",
3417
+ disabled: !!c.value || T.value || w.value,
3418
+ onClick: r[2] ||= (e) => b("launch")
3419
+ }, null, 8, ["loading", "disabled"])) : A("", !0),
3420
+ P(W(t), {
3421
+ label: s.value?.status === "running" ? "检查缺失节点" : "离线预检",
3422
+ severity: "secondary",
3423
+ text: "",
3424
+ loading: w.value,
3425
+ disabled: !s.value || ![
3426
+ "running",
3427
+ "stopped",
3428
+ "error"
3429
+ ].includes(s.value.status) || T.value || !!c.value,
3430
+ onClick: ue
3431
+ }, null, 8, [
3432
+ "label",
3433
+ "loading",
3434
+ "disabled"
3435
+ ]),
3436
+ R.value.length && !I.value && !re.value ? (B(), k(W(t), {
3437
+ key: 2,
3438
+ severity: "secondary",
3439
+ label: `安装 ${R.value.length} 个节点包`,
3440
+ loading: T.value,
3441
+ disabled: w.value || !!c.value,
3442
+ onClick: r[3] ||= (e) => de()
3443
+ }, null, 8, [
3444
+ "label",
3445
+ "loading",
3446
+ "disabled"
3447
+ ])) : A("", !0),
3448
+ re.value ? (B(), k(W(t), {
3449
+ key: 3,
3450
+ severity: "secondary",
3451
+ label: "重试安装",
3452
+ disabled: T.value || w.value || !!c.value,
3453
+ onClick: r[4] ||= (e) => de(!0)
3454
+ }, null, 8, ["disabled"])) : A("", !0)
3455
+ ]),
3456
+ E.value ? (B(), j("p", zr, U(E.value), 1)) : A("", !0),
3457
+ T.value ? (B(), j("p", Br, U(N.value || "正在准备安装…") + " 关闭预览后任务继续。 ", 1)) : A("", !0),
3458
+ I.value ? (B(), j("div", Vr, [
3459
+ I.value.installed.length ? (B(), j("p", Hr, " 已准备 " + U(I.value.installed.length) + " 个节点包。" + U(z.value ? "请修复下方失败项后重启 ComfyUI。" : "请重启 ComfyUI,再重新检查;安装完成不代表节点已加载。"), 1)) : A("", !0),
3460
+ I.value.dependenciesError ? (B(), j("p", Ur, " 依赖安装失败:" + U(I.value.dependenciesError), 1)) : A("", !0),
3461
+ (B(!0), j(D, null, H(I.value.failures, (e) => (B(), j("p", {
3462
+ key: e.name,
3463
+ role: "alert",
3464
+ class: "break-words text-danger"
3465
+ }, U(e.name) + ":" + U(e.error), 1))), 128))
3466
+ ])) : A("", !0),
3467
+ M("div", Wr, [P(tr, {
3468
+ workflow: e.workflow,
3469
+ missing: ce.value,
3470
+ selected: m.value,
3471
+ onSelect: g
3472
+ }, null, 8, [
3473
+ "workflow",
3474
+ "missing",
3475
+ "selected"
3476
+ ]), M("aside", Gr, [
3477
+ P(W(_), {
3478
+ modelValue: d.value,
3479
+ "onUpdate:modelValue": r[5] ||= (e) => d.value = e,
3480
+ options: f,
3481
+ label: "检视内容",
3482
+ size: "xs",
3483
+ variant: "inline"
3484
+ }, null, 8, ["modelValue"]),
3485
+ se(P(kr, {
3486
+ api: e.api,
3487
+ app: s.value,
3488
+ workflow: e.workflow,
3489
+ onClose: r[6] ||= (e) => i("close")
3490
+ }, null, 8, [
3491
+ "api",
3492
+ "app",
3493
+ "workflow"
3494
+ ]), [[oe, d.value === "models"]]),
3495
+ d.value === "parameters" ? (B(), j("section", Kr, [P(W(v), {
3496
+ modelValue: m.value,
3497
+ "onUpdate:modelValue": r[7] ||= (e) => m.value = e,
3498
+ options: e.workflow.nodes,
3499
+ "option-label": "title",
3500
+ "option-value": "id",
3501
+ "aria-label": "选择工作流节点",
3502
+ placeholder: "选择节点",
3503
+ class: "w-full"
3504
+ }, null, 8, ["modelValue", "options"]), h.value ? (B(), j("div", {
3505
+ key: 0,
3506
+ ref_key: "parameters",
3507
+ ref: p,
3508
+ tabindex: "-1",
3509
+ class: "kano-settings-group kano-settings-row space-y-2"
3510
+ }, [
3511
+ M("p", qr, U(h.value.id) + " · " + U(h.value.title), 1),
3512
+ h.value.title === h.value.type ? A("", !0) : (B(), j("p", Jr, U(h.value.type), 1)),
3513
+ (h.value.inputs ? Object.keys(h.value.inputs).length : h.value.widgets.length) ? (B(), k(sr, {
3514
+ key: h.value.id,
3515
+ values: h.value.inputs ?? h.value.widgets,
3516
+ "node-type": h.value.type,
3517
+ "node-names": ie.value
3518
+ }, null, 8, [
3519
+ "values",
3520
+ "node-type",
3521
+ "node-names"
3522
+ ])) : (B(), j("p", Yr, "此节点没有参数。"))
3523
+ ], 512)) : A("", !0)])) : A("", !0),
3524
+ d.value === "nodes" ? (B(), j("section", Xr, [
3525
+ !s.value && a.value.length ? (B(), j("p", Zr, "请选择要检查的 ComfyUI 应用。")) : A("", !0),
3526
+ S.value && !x.value.length ? (B(), j("p", Qr, [...r[8] ||= [M("span", {
3527
+ class: "i-lucide-circle-check text-success",
3528
+ "aria-hidden": "true"
3529
+ }, null, -1), M("span", null, "所需节点均已加载。", -1)]])) : A("", !0),
3530
+ C.value ? (B(), j("div", $r, [M("p", ei, U(`离线预检 · 已匹配 ${C.value.installed} 种节点,${C.value.unknown} 种需启动后确认。`), 1), C.value.issues.length ? (B(), j("div", ti, [(B(!0), j(D, null, H(C.value.issues, (e) => (B(), j("div", {
3531
+ key: e.type,
3532
+ class: "kano-settings-row"
3533
+ }, [M("p", ni, U(e.type), 1), M("p", ri, U(e.reason), 1)]))), 128))])) : A("", !0)])) : A("", !0),
3534
+ S.value && x.value.length ? (B(), k(W(y), {
3535
+ key: 3,
3536
+ title: `缺失节点(${x.value.length} 种)`
3537
+ }, {
3538
+ default: q(() => [M("div", ii, [(B(!0), j(D, null, H(x.value, (e) => (B(), j("div", {
3539
+ key: e.type,
3540
+ class: "kano-settings-row flex flex-wrap items-center justify-between gap-3"
3541
+ }, [
3542
+ M("div", ai, [M("p", oi, [ee(U(e.type) + " ", 1), M("span", si, "× " + U(e.count), 1)]), e.core ? (B(), j("p", ci, " 内置节点不可用,请检查 ComfyUI 版本和启动日志。 ")) : e.installed ? (B(), j("p", li, U(e.installed.enabled ? "节点包已存在但未加载,请重启并检查依赖与日志。" : "节点包已禁用。"), 1)) : e.candidates.length ? e.candidates.length === 1 ? (B(), j("p", di, U(e.candidates[0].name) + " · " + U(e.candidates[0].gitUrl), 1)) : A("", !0) : (B(), j("p", ui, U(w.value ? "正在匹配来源…" : "未找到可自动安装的来源。"), 1))]),
3543
+ e.installed && !e.installed.enabled ? (B(), k(W(t), {
3544
+ key: 0,
3545
+ size: "small",
3546
+ class: "ml-auto shrink-0",
3547
+ label: "启用节点包",
3548
+ severity: "secondary",
3549
+ disabled: !!c.value || T.value || w.value,
3550
+ onClick: (t) => b("enable", e)
3551
+ }, null, 8, ["disabled", "onClick"])) : A("", !0),
3552
+ e.candidates.length > 1 && !e.installed ? (B(), k(W(v), {
3553
+ key: 1,
3554
+ modelValue: F.value[e.type],
3555
+ "onUpdate:modelValue": (t) => F.value[e.type] = t,
3556
+ options: e.candidates,
3557
+ "option-label": "gitUrl",
3558
+ "option-value": "gitUrl",
3559
+ placeholder: "选择节点来源",
3560
+ "aria-label": `${e.type} 的安装来源`,
3561
+ class: "kano-select-adaptive ml-auto",
3562
+ disabled: T.value
3563
+ }, null, 8, [
3564
+ "modelValue",
3565
+ "onUpdate:modelValue",
3566
+ "options",
3567
+ "aria-label",
3568
+ "disabled"
3569
+ ])) : A("", !0)
3570
+ ]))), 128))])]),
3571
+ _: 1
3572
+ }, 8, ["title"])) : A("", !0)
3573
+ ])) : A("", !0)
3574
+ ])])
3575
+ ]));
3576
+ }
3577
+ }), [["__scopeId", "data-v-a9b97dce"]]);
3578
+ //#endregion
3579
+ //#region packages/plugins/comfyui/runtime-control.ts
3580
+ function pi(e) {
3581
+ return typeof e == "object" && !!e;
3582
+ }
3583
+ function mi(e) {
3584
+ return typeof e == "number" && Number.isFinite(e) && e >= 0;
3585
+ }
3586
+ function hi(e, t) {
3587
+ if (!pi(t) || !Array.isArray(t.queue_pending) || !Array.isArray(t.queue_running)) throw Error("ComfyUI 队列数据格式异常");
3588
+ if (!pi(e) || !Array.isArray(e.devices)) throw Error("ComfyUI 设备数据格式异常");
3589
+ let n = e.devices.flatMap((e) => {
3590
+ if (!pi(e) || ["cpu", "mps"].includes(String(e.type))) return [];
3591
+ let { torch_vram_total: t, torch_vram_free: n, vram_total: r } = e;
3592
+ if (!mi(r) || !r) return [];
3593
+ let i = mi(t) && mi(n) ? {
3594
+ allocated: Math.max(0, t - n),
3595
+ reserved: t
3596
+ } : void 0, a = mi(e.vram_free) ? Math.max(0, r - e.vram_free) : void 0;
3597
+ return !i && a === void 0 ? [] : [{
3598
+ name: String(e.name || e.type || "GPU"),
3599
+ ...i,
3600
+ ...a === void 0 ? {} : { used: a },
3601
+ total: r
3602
+ }];
3603
+ });
3604
+ return {
3605
+ pending: t.queue_pending.length,
3606
+ running: t.queue_running.length,
3607
+ devices: n
3608
+ };
3609
+ }
3610
+ async function gi(e, t) {
3611
+ let [n, r] = await Promise.all([e.getJson(t + "/system_stats"), e.getJson(t + "/queue")]);
3612
+ return hi(n, r);
3613
+ }
3614
+ function _i(e) {
3615
+ return !!e && (e.running > 0 || e.pending > 0);
3616
+ }
3617
+ async function vi(e, t, n) {
3618
+ let r = n === "free" ? {
3619
+ unload_models: !0,
3620
+ free_memory: !0
3621
+ } : {}, i = await e.postJson(t + "/" + n, r);
3622
+ if (i.status_code < 200 || i.status_code >= 300) throw Error("HTTP " + i.status_code + " " + i.body.slice(0, 256));
3623
+ }
3624
+ function yi(e, t, n, r) {
3625
+ let i = !1, a = 0, o = !1, s;
3626
+ async function c(i) {
3627
+ try {
3628
+ let n = await e();
3629
+ if (i !== a) return;
3630
+ t(n);
3631
+ let s = n.pending + n.running > 0, c = o && !s;
3632
+ o = s, c && r();
3633
+ } catch (e) {
3634
+ i === a && n(e);
3635
+ } finally {
3636
+ i === a && (s = setTimeout(() => void c(i), 3e3));
3637
+ }
3638
+ }
3639
+ return { setActive(e) {
3640
+ i !== e && (i = e, clearTimeout(s), ++a, i && c(a));
3641
+ } };
3642
+ }
3643
+ //#endregion
3644
+ //#region packages/plugins/comfyui/RuntimeControls.vue?vue&type=script&setup=true&lang.ts
3645
+ var bi = {
3646
+ key: 0,
3647
+ role: "status",
3648
+ class: "min-w-0 max-w-full break-words text-warning"
3649
+ }, xi = { class: "inline-flex items-center gap-2 tabular-nums" }, Si = {
3650
+ key: 0,
3651
+ "aria-hidden": "true",
3652
+ class: "size-2 shrink-0 rounded-full bg-success-dot motion-safe:animate-pulse"
3653
+ }, Ci = ["title"], wi = { class: "flex items-center justify-between gap-2" }, Ti = { class: "min-w-0 truncate text-text-secondary" }, Ei = { class: "shrink-0 tabular-nums" }, Di = {
3654
+ key: 0,
3655
+ class: "text-xs text-text-muted"
3656
+ }, Oi = {
3657
+ key: 2,
3658
+ role: "status",
3659
+ class: "text-text-muted"
3660
+ }, ki = { class: "ml-auto flex flex-wrap items-center gap-2" }, Ai = /* @__PURE__ */ F({
3661
+ __name: "RuntimeControls",
3662
+ props: {
3663
+ app: {},
3664
+ api: {}
3665
+ },
3666
+ setup(e) {
3667
+ let r = e, i = V(), a = V(!1), o = V(!1), s = V(), c = V(""), l = V(), u = O(() => (r.app.webUrl || Ue(r.app.params)).replace(/\/$/, "")), d = O(() => o.value && a.value && r.app.status === "running"), f, p, m = 0;
3668
+ function h() {
3669
+ o.value = document.visibilityState === "visible";
3670
+ }
3671
+ K([
3672
+ () => r.app.id,
3673
+ () => r.app.executionId,
3674
+ () => r.app.status,
3675
+ u
3676
+ ], () => {
3677
+ ++m, p?.setActive(!1), s.value = void 0, l.value = void 0, c.value = "", p = yi(() => gi(r.api.http, u.value), (e) => {
3678
+ s.value = e, c.value = "";
3679
+ }, (e) => {
3680
+ c.value = e instanceof Error ? e.message : String(e);
3681
+ }, () => r.api.ui.notifyDesktop("ComfyUI 生成已完成", r.app.name)), p.setActive(d.value);
3682
+ }, { immediate: !0 }), K(d, (e) => p?.setActive(e)), z(() => {
3683
+ h(), document.addEventListener("visibilitychange", h), f = new IntersectionObserver(([e]) => {
3684
+ a.value = e.isIntersecting;
3685
+ }), i.value && f.observe(i.value);
3686
+ }), re(() => {
3687
+ m++, p?.setActive(!1), f?.disconnect(), document.removeEventListener("visibilitychange", h);
3688
+ });
3689
+ let g = (e) => (e / 1024 ** 3).toFixed(2), _ = O(() => (s.value?.devices ?? []).map((e) => {
3690
+ let t = e.used ?? e.reserved ?? 0;
3691
+ return {
3692
+ ...e,
3693
+ percent: Math.min(100, 100 * t / e.total),
3694
+ summary: g(t) + " / " + g(e.total) + " GiB",
3695
+ detail: e.allocated !== void 0 && e.reserved !== void 0 ? "PyTorch 已分配 " + g(e.allocated) + " GiB,已保留 " + g(e.reserved) + " GiB" : "设备显存占用 " + g(t) + " GiB"
3696
+ };
3697
+ })), v = O(() => _i(s.value));
3698
+ async function y(e) {
3699
+ if (l.value || !d.value || e === "interrupt" && !v.value) return;
3700
+ let t = m;
3701
+ l.value = e;
3702
+ try {
3703
+ await vi(r.api.http, u.value, e), t === m && r.api.ui.toast.success(e === "free" ? "已请求卸载模型并释放显存" : "已请求中断当前生成");
3704
+ } catch (n) {
3705
+ t === m && r.api.ui.toast.exception(e === "free" ? "释放显存失败" : "中断生成失败", n);
3706
+ } finally {
3707
+ t === m && (l.value = void 0);
3708
+ }
3709
+ }
3710
+ return (e, r) => (B(), j("section", {
3711
+ ref_key: "host",
3712
+ ref: i,
3713
+ "aria-label": "ComfyUI 实时状态",
3714
+ class: "kano-card flex flex-wrap items-center gap-x-5 gap-y-2 p-4 text-sm"
3715
+ }, [c.value ? (B(), j("p", bi, " 状态读取失败 · " + U(c.value), 1)) : s.value ? (B(), j(D, { key: 1 }, [
3716
+ M("span", xi, [s.value.running > 0 ? (B(), j("span", Si)) : A("", !0), ee(" 运行中 " + U(s.value.running) + " · 排队 " + U(s.value.pending), 1)]),
3717
+ (B(!0), j(D, null, H(_.value, (e, t) => (B(), j("div", {
3718
+ key: t,
3719
+ class: "min-w-0 max-w-full flex-[1_1_11rem] text-xs",
3720
+ title: e.detail
3721
+ }, [M("div", wi, [M("span", Ti, U(_.value.length > 1 ? e.name : e.used === void 0 ? "显存保留量" : "显存占用"), 1), M("span", Ei, U(e.summary), 1)]), P(W(n), {
3722
+ class: "mt-1",
3723
+ label: e.name + " 显存占用",
3724
+ percent: e.percent,
3725
+ description: e.detail
3726
+ }, null, 8, [
3727
+ "label",
3728
+ "percent",
3729
+ "description"
3730
+ ])], 8, Ci))), 128)),
3731
+ s.value.devices.length ? A("", !0) : (B(), j("span", Di, "当前设备未提供独立显存统计"))
3732
+ ], 64)) : (B(), j("span", Oi, "正在读取队列与显存…")), M("div", ki, [v.value || l.value === "interrupt" ? (B(), k(W(t), {
3733
+ key: 0,
3734
+ size: "small",
3735
+ severity: "secondary",
3736
+ label: "中断生成",
3737
+ icon: "i-lucide-square",
3738
+ disabled: !!l.value || !v.value,
3739
+ loading: l.value === "interrupt",
3740
+ onClick: r[0] ||= (e) => y("interrupt")
3741
+ }, null, 8, ["disabled", "loading"])) : A("", !0), P(W(t), {
3742
+ size: "small",
3743
+ severity: "secondary",
3744
+ label: "释放显存",
3745
+ icon: "i-lucide-memory-stick",
3746
+ disabled: !!l.value,
3747
+ loading: l.value === "free",
3748
+ onClick: r[1] ||= (e) => y("free")
3749
+ }, null, 8, ["disabled", "loading"])])], 512));
3750
+ }
3751
+ }), ji = [
3752
+ "B",
3753
+ "KiB",
3754
+ "MiB",
3755
+ "GiB",
3756
+ "TiB",
3757
+ "PiB"
3758
+ ], Mi = new Intl.NumberFormat("zh-CN", { maximumFractionDigits: 1 });
3759
+ function Ni(e) {
3760
+ let t = e, n = 0;
3761
+ for (; t >= 1024 && n < ji.length - 1;) t /= 1024, n++;
3762
+ return `${Mi.format(t)} ${ji[n]}`;
3763
+ }
3764
+ //#endregion
3765
+ //#region packages/plugins/comfyui/workflow-library.ts
3766
+ function Pi(e) {
3767
+ let t = e.params.userDirectory ? T(e.path, String(e.params.userDirectory)) : T(Cn(e), "user");
3768
+ return T(t, "default/workflows");
3769
+ }
3770
+ async function Fi(e, t, n) {
3771
+ let r = n.reduce((e, t) => T(e, t), t), i = e.fs;
3772
+ return !n.length && !await i.exists(r) ? [] : (await i.listDir(r)).filter((e) => e.is_dir || /\.json$/i.test(e.name)).sort((e, t) => Number(t.is_dir) - Number(e.is_dir) || e.name.localeCompare(t.name)).map((e) => ({
3773
+ ...e,
3774
+ path: T(r, e.name)
3775
+ }));
3776
+ }
3777
+ async function Ii(e, t, n) {
3778
+ let r = e.fs;
3779
+ if ((await r.stat(t)).size > 33554432) throw Error("工作流文件不能超过 32 MiB");
3780
+ return gn(await r.readFile(t), n);
3781
+ }
3782
+ async function Li(e, t, n) {
3783
+ let r = (n.name.split(/[\\/]/).pop() || "工作流").replace(/\.(json|png)$/i, "").replace(/[^\p{L}\p{N} _.()-]/gu, "_").slice(0, 100) || "工作流", i = crypto.randomUUID();
3784
+ await e.fs.mkdir(t);
3785
+ let a = r + ".json", o = T(t, a), s = await e.fs.exists(o) ? T(t, r + "-" + i + ".json") : o, c = T(t, ".kano-import-" + i + ".tmp");
3786
+ await e.fs.writeFile(c, JSON.stringify(n.source));
3787
+ try {
3788
+ await e.fs.rename(c, s);
3789
+ } catch (t) {
3790
+ throw await e.fs.trash(c).catch(() => {}), t;
3791
+ }
3792
+ return s;
3793
+ }
3794
+ //#endregion
3795
+ //#region packages/plugins/comfyui/WorkflowPreviewDialog.vue
3796
+ var Ri = /* @__PURE__ */ F({
3797
+ __name: "WorkflowPreviewDialog",
3798
+ props: {
3799
+ api: {},
3800
+ workflow: {},
3801
+ initialAppId: {},
3802
+ fixedApp: {}
3803
+ },
3804
+ emits: ["close"],
3805
+ setup(e, { emit: t }) {
3806
+ let n = t;
3807
+ return (t, r) => (B(), k(W(s), {
3808
+ visible: !!e.workflow,
3809
+ header: "ComfyUI 工作流预览",
3810
+ modal: "",
3811
+ maximizable: "",
3812
+ class: "w-[min(84rem,95vw)]",
3813
+ "onUpdate:visible": r[1] ||= (e) => !e && n("close")
3814
+ }, {
3815
+ default: q(() => [e.workflow ? (B(), k(fi, {
3816
+ key: 0,
3817
+ api: e.api,
3818
+ workflow: e.workflow,
3819
+ "initial-app-id": e.initialAppId,
3820
+ "fixed-app": e.fixedApp,
3821
+ onClose: r[0] ||= (e) => n("close")
3822
+ }, null, 8, [
3823
+ "api",
3824
+ "workflow",
3825
+ "initial-app-id",
3826
+ "fixed-app"
3827
+ ])) : A("", !0)]),
3828
+ _: 1
3829
+ }, 8, ["visible"]));
3830
+ }
3831
+ }), zi = {
3832
+ key: 0,
3833
+ role: "alert",
3834
+ class: "mb-3 break-words text-sm text-danger"
3835
+ }, Bi = {
3836
+ key: 1,
3837
+ role: "status",
3838
+ "aria-label": "正在读取工作流",
3839
+ class: "space-y-2"
3840
+ }, Vi = { class: "kano-field-label block truncate" }, Hi = { class: "kano-field-hint flex flex-wrap gap-x-3 tabular-nums" }, Ui = ["datetime"], Wi = { key: 1 }, Gi = /* @__PURE__ */ F({
3841
+ __name: "WorkflowsPage",
3842
+ props: {
3843
+ api: {},
3844
+ app: {}
3845
+ },
3846
+ setup(n) {
3847
+ let i = n, s = O(() => Pi(i.app)), c = V([]), d = O(() => [{
3848
+ label: "工作流目录",
3849
+ path: s.value
3850
+ }, ...c.value.map((e, t) => ({
3851
+ label: e,
3852
+ path: c.value.slice(0, t + 1).reduce((e, t) => T(e, t), s.value)
3853
+ }))]), f = V(), p = V(!1);
3854
+ async function _(e) {
3855
+ if (p.value || I.value || !e.length) return;
3856
+ if (e.length !== 1) {
3857
+ R.value = "请每次选择一个 JSON 或 PNG 工作流文件。";
3858
+ return;
3859
+ }
3860
+ let t = z, n = d.value.at(-1).path, r = i.api;
3861
+ p.value = !0, R.value = "";
3862
+ try {
3863
+ let i = await hn(e[0]);
3864
+ if (t !== z || (await Li(r, n, i), t !== z)) return;
3865
+ await G();
3866
+ } catch (e) {
3867
+ t === z && (R.value = String(e));
3868
+ } finally {
3869
+ p.value = !1;
3870
+ }
3871
+ }
3872
+ function v(e) {
3873
+ let t = e.target, n = Array.from(t.files ?? []);
3874
+ t.value = "", _(n);
3875
+ }
3876
+ function y(e) {
3877
+ e.dataTransfer?.types.includes("Files") && e.preventDefault();
3878
+ }
3879
+ function x(e) {
3880
+ e.dataTransfer?.files.length && (e.preventDefault(), e.stopPropagation(), _(Array.from(e.dataTransfer.files)));
3881
+ }
3882
+ let S = ae([]), C = V(""), w = O(() => C.value.trim().toLowerCase()), E = O(() => S.value.filter((e) => e.name.toLowerCase().includes(w.value))), ee = ae(), F = ae(), I = V(""), L = V(!1), te = V(""), R = V(""), z = 0, re = new Intl.DateTimeFormat("zh-CN", {
3883
+ dateStyle: "medium",
3884
+ timeStyle: "short"
3885
+ });
3886
+ function ie(e) {
3887
+ let t = Date.parse(e);
3888
+ return Number.isFinite(t) ? re.format(t) : e;
3889
+ }
3890
+ K([() => i.app.id, s], () => {
3891
+ c.value = [];
3892
+ }, { flush: "sync" }), K(c, () => {
3893
+ C.value = "", G();
3894
+ }, { immediate: !0 }), ne(() => z++);
3895
+ async function G() {
3896
+ let e = ++z;
3897
+ te.value = "", I.value = "", F.value = void 0, ee.value = void 0, S.value = [], R.value = "", L.value = !0;
3898
+ try {
3899
+ let t = await Fi(i.api, s.value, c.value);
3900
+ e === z && (S.value = t);
3901
+ } catch (t) {
3902
+ e === z && (R.value = String(t));
3903
+ } finally {
3904
+ e === z && (L.value = !1);
3905
+ }
3906
+ }
3907
+ async function oe(e) {
3908
+ if (I.value) return;
3909
+ if (e.is_dir) {
3910
+ c.value = [...c.value, e.name];
3911
+ return;
3912
+ }
3913
+ let t = ++z;
3914
+ te.value = e.path, R.value = "";
3915
+ try {
3916
+ let n = await Ii(i.api, e.path, e.name);
3917
+ t === z && (ee.value = n);
3918
+ } catch (e) {
3919
+ t === z && (R.value = String(e));
3920
+ } finally {
3921
+ t === z && (te.value = "");
3922
+ }
3923
+ }
3924
+ async function se() {
3925
+ let e = F.value;
3926
+ if (!e || e.is_dir || I.value) return;
3927
+ let t = ++z;
3928
+ F.value = void 0, te.value = "", I.value = e.path, R.value = "";
3929
+ try {
3930
+ await i.api.fs.trash(e.path), t === z && (S.value = S.value.filter((t) => t.path !== e.path));
3931
+ } catch (e) {
3932
+ t === z && (R.value = String(e));
3933
+ } finally {
3934
+ t === z && (I.value = "");
3935
+ }
3936
+ }
3937
+ return (i, s) => (B(), k(W(h), {
3938
+ title: "工作流",
3939
+ onDragover: y,
3940
+ onDrop: x
3941
+ }, {
3942
+ actions: q(() => [
3943
+ M("input", {
3944
+ ref_key: "picker",
3945
+ ref: f,
3946
+ type: "file",
3947
+ accept: ".json,.png",
3948
+ hidden: "",
3949
+ onChange: v
3950
+ }, null, 544),
3951
+ P(W(t), {
3952
+ icon: "i-lucide-refresh-cw",
3953
+ label: R.value ? "重新读取目录" : "刷新",
3954
+ severity: "secondary",
3955
+ disabled: !!I.value || p.value,
3956
+ loading: L.value,
3957
+ onClick: G
3958
+ }, null, 8, [
3959
+ "label",
3960
+ "disabled",
3961
+ "loading"
3962
+ ]),
3963
+ P(W(t), {
3964
+ label: "导入工作流文件",
3965
+ title: "选择 JSON 或 PNG 文件,也可拖到此页面",
3966
+ icon: "i-lucide-file-input",
3967
+ disabled: !!I.value || p.value,
3968
+ loading: p.value,
3969
+ onClick: s[0] ||= (e) => f.value?.click()
3970
+ }, null, 8, ["disabled", "loading"])
3971
+ ]),
3972
+ toolbar: q(() => [P(W(e), {
3973
+ items: d.value,
3974
+ label: "工作流目录",
3975
+ disabled: !!I.value || p.value,
3976
+ onNavigate: s[1] ||= (e) => c.value = c.value.slice(0, d.value.findIndex((t) => t.path === e.path))
3977
+ }, null, 8, ["items", "disabled"]), P(W(u), null, {
3978
+ leading: q(() => [P(W(g), {
3979
+ modelValue: C.value,
3980
+ "onUpdate:modelValue": s[2] ||= (e) => C.value = e,
3981
+ width: "w-full",
3982
+ class: "min-w-36 max-w-64 flex-1",
3983
+ placeholder: "搜索文件名",
3984
+ "aria-label": "搜索工作流文件名"
3985
+ }, null, 8, ["modelValue"])]),
3986
+ _: 1
3987
+ })]),
3988
+ default: q(() => [
3989
+ R.value ? (B(), j("p", zi, U(R.value), 1)) : A("", !0),
3990
+ L.value ? (B(), j("div", Bi, [(B(), j(D, null, H(3, (e) => P(W(b), {
3991
+ key: e,
3992
+ decorative: "",
3993
+ lines: 1
3994
+ })), 64))])) : E.value.length ? (B(), k(W(a), {
3995
+ key: 2,
3996
+ "aria-label": "工作流文件"
3997
+ }, {
3998
+ default: q(() => [(B(!0), j(D, null, H(E.value, (e) => (B(), k(W(o), {
3999
+ key: e.path,
4000
+ class: "relative transition-colors hover:bg-bg-hover",
4001
+ "actions-open": te.value === e.path || I.value === e.path
4002
+ }, N({
4003
+ leading: q(() => [P(W(m), {
4004
+ name: e.is_dir ? "i-lucide-folder" : "i-lucide-workflow",
4005
+ class: "text-text-secondary"
4006
+ }, null, 8, ["name"])]),
4007
+ default: q(() => [P(W(t), {
4008
+ unstyled: "",
4009
+ class: "w-full min-w-0 text-left after:absolute after:inset-0",
4010
+ title: e.name,
4011
+ "aria-label": (e.is_dir ? "打开目录 " : "预览 ") + e.name,
4012
+ disabled: !!I.value || p.value,
4013
+ onClick: (t) => oe(e)
4014
+ }, {
4015
+ default: q(() => [M("span", Vi, U(e.name), 1), M("span", Hi, [e.mod_time ? (B(), j("time", {
4016
+ key: 0,
4017
+ datetime: e.mod_time,
4018
+ title: "修改时间"
4019
+ }, U(ie(e.mod_time)), 9, Ui)) : A("", !0), e.is_dir ? A("", !0) : (B(), j("span", Wi, U(W(Ni)(e.size)), 1))])]),
4020
+ _: 2
4021
+ }, 1032, [
4022
+ "title",
4023
+ "aria-label",
4024
+ "disabled",
4025
+ "onClick"
4026
+ ])]),
4027
+ _: 2
4028
+ }, [e.is_dir ? void 0 : {
4029
+ name: "actions",
4030
+ fn: q(() => [P(W(t), {
4031
+ icon: "i-lucide-trash-2",
4032
+ size: "small",
4033
+ text: "",
4034
+ severity: "danger",
4035
+ class: "relative z-10",
4036
+ title: "移至回收站",
4037
+ "aria-label": "移至回收站 " + e.name,
4038
+ loading: I.value === e.path,
4039
+ disabled: !!I.value || !!te.value || p.value,
4040
+ onClick: (t) => F.value = e
4041
+ }, null, 8, [
4042
+ "aria-label",
4043
+ "loading",
4044
+ "disabled",
4045
+ "onClick"
4046
+ ])]),
4047
+ key: "0"
4048
+ }]), 1032, ["actions-open"]))), 128))]),
4049
+ _: 1
4050
+ })) : R.value ? A("", !0) : (B(), k(W(l), {
4051
+ key: 3,
4052
+ title: w.value ? "没有匹配的工作流" : "此目录暂无工作流",
4053
+ description: w.value ? void 0 : "支持导入 JSON 或包含工作流元数据的 PNG 图片,也可直接拖入此页面",
4054
+ icon: "i-lucide-workflow"
4055
+ }, {
4056
+ default: q(() => [w.value ? (B(), k(W(t), {
4057
+ key: 0,
4058
+ text: "",
4059
+ severity: "secondary",
4060
+ label: "清空搜索",
4061
+ onClick: s[3] ||= (e) => C.value = ""
4062
+ })) : (B(), k(W(t), {
4063
+ key: 1,
4064
+ severity: "secondary",
4065
+ label: "导入工作流文件",
4066
+ icon: "i-lucide-file-input",
4067
+ disabled: p.value,
4068
+ loading: p.value,
4069
+ onClick: s[4] ||= (e) => f.value?.click()
4070
+ }, null, 8, ["disabled", "loading"]))]),
4071
+ _: 1
4072
+ }, 8, ["title", "description"])),
4073
+ P(Ri, {
4074
+ api: n.api,
4075
+ workflow: ee.value,
4076
+ "initial-app-id": n.app.id,
4077
+ onClose: s[5] ||= (e) => ee.value = void 0
4078
+ }, null, 8, [
4079
+ "api",
4080
+ "workflow",
4081
+ "initial-app-id"
4082
+ ]),
4083
+ F.value ? (B(), k(W(r), {
4084
+ key: 4,
4085
+ visible: "",
4086
+ title: "移至回收站",
4087
+ message: F.value.path + "\n\n可从执行机器的回收站恢复。",
4088
+ "confirm-text": "移至回收站",
4089
+ type: "danger",
4090
+ onConfirm: se,
4091
+ "onUpdate:visible": s[6] ||= (e) => !e && (F.value = void 0)
4092
+ }, null, 8, ["message"])) : A("", !0)
4093
+ ]),
4094
+ _: 1
4095
+ }));
4096
+ }
4097
+ }), Ki = "kano:output-gallery";
4098
+ function qi(e, t) {
4099
+ let n = [];
4100
+ e.services.watch(Ki, ([r]) => {
4101
+ for (let e of n) e.dispose();
4102
+ if (n = [], !r) return;
4103
+ let i = r.page, a = F({
4104
+ props: {
4105
+ app: {
4106
+ type: Object,
4107
+ required: !0
4108
+ },
4109
+ api: {
4110
+ type: Object,
4111
+ required: !0
4112
+ }
4113
+ },
4114
+ setup(e) {
4115
+ let n = O(() => t(() => e.app, e.api));
4116
+ return () => I(i, {
4117
+ key: e.app.id,
4118
+ source: n.value,
4119
+ instanceId: e.app.id
4120
+ });
4121
+ }
4122
+ }), o = "输出图库", s = "i-lucide-image";
4123
+ n.push(e.ui.registerTab({
4124
+ id: "outputs",
4125
+ label: o,
4126
+ icon: s,
4127
+ order: 46,
4128
+ component: a,
4129
+ keepAlive: !1
4130
+ })), n.push(e.apps.registerAction({
4131
+ id: "output",
4132
+ label: o,
4133
+ icon: s,
4134
+ order: 3,
4135
+ kind: "tab",
4136
+ target: "outputs"
4137
+ }));
4138
+ });
4139
+ }
4140
+ //#endregion
4141
+ //#region packages/plugins/comfyui/WorkflowOutputActions.vue
4142
+ var Ji = /* @__PURE__ */ F({
4143
+ __name: "WorkflowOutputActions",
4144
+ props: {
4145
+ app: {},
4146
+ api: {},
4147
+ workflow: {},
4148
+ disabled: { type: Boolean }
4149
+ },
4150
+ emits: ["active", "close"],
4151
+ setup(e, { emit: n }) {
4152
+ let r = e, i = n, a = V(!1), o = V(!1), s = V(!1), c = !0;
4153
+ K(() => a.value || o.value, (e) => i("active", e), { flush: "sync" }), ne(() => {
4154
+ c = !1, i("active", !1);
4155
+ });
4156
+ async function l() {
4157
+ if (o.value || r.disabled) return;
4158
+ let { app: e, api: t, workflow: n } = r;
4159
+ o.value = !0;
4160
+ try {
4161
+ if (!s.value) {
4162
+ let r = await Tn(t, e, n);
4163
+ s.value = !0, t.ui.toast.success("工作流已保存", r);
4164
+ }
4165
+ if (!c) return;
4166
+ await t.apps.openTab(e.id, "webview"), c && i("close");
4167
+ } catch (e) {
4168
+ t.ui.toast.exception(s.value ? "打开 WebUI 失败" : "保存工作流失败", e);
4169
+ } finally {
4170
+ o.value = !1;
4171
+ }
4172
+ }
4173
+ return (n, r) => (B(), j(D, null, [
4174
+ P(W(t), {
4175
+ label: "检查工作流",
4176
+ severity: "secondary",
4177
+ disabled: e.disabled || o.value,
4178
+ onClick: r[0] ||= (e) => a.value = !0
4179
+ }, null, 8, ["disabled"]),
4180
+ P(W(t), {
4181
+ label: s.value ? "打开 WebUI" : "保存并打开 WebUI",
4182
+ disabled: e.disabled || o.value || e.app.status !== "running",
4183
+ title: e.app.status === "running" ? void 0 : "请先启动 ComfyUI",
4184
+ loading: o.value,
4185
+ onClick: l
4186
+ }, null, 8, [
4187
+ "label",
4188
+ "disabled",
4189
+ "title",
4190
+ "loading"
4191
+ ]),
4192
+ a.value ? (B(), k(Ri, {
4193
+ key: 0,
4194
+ api: e.api,
4195
+ "initial-app-id": e.app.id,
4196
+ "fixed-app": e.app,
4197
+ workflow: e.workflow,
4198
+ onClose: r[1] ||= (e) => a.value = !1
4199
+ }, null, 8, [
4200
+ "api",
4201
+ "initial-app-id",
4202
+ "fixed-app",
4203
+ "workflow"
4204
+ ])) : A("", !0)
4205
+ ], 64));
4206
+ }
4207
+ });
4208
+ //#endregion
4209
+ //#region packages/plugins/comfyui/gallery-source.ts
4210
+ function Yi(e) {
4211
+ let t = T(e.path, String(e.params.baseDirectory || e.path));
4212
+ return e.params.outputDirectory ? T(e.path, String(e.params.outputDirectory)) : T(t, "output");
4213
+ }
4214
+ function Xi(e, t) {
4215
+ return {
4216
+ root: Yi(e()),
4217
+ describe(n, r) {
4218
+ let { workflow: i, ...a } = ea(n, r);
4219
+ return {
4220
+ ...a,
4221
+ actions: i ? (n) => I(Ji, {
4222
+ ...n,
4223
+ app: e(),
4224
+ api: t,
4225
+ workflow: i
4226
+ }) : void 0
4227
+ };
4228
+ }
4229
+ };
4230
+ }
4231
+ function Zi(e) {
4232
+ let t = /* @__PURE__ */ new Map();
4233
+ if (e.format === "prompt") {
4234
+ for (let n of e.nodes) t.set(n.id, {
4235
+ type: n.type,
4236
+ inputs: n.inputs ?? {}
4237
+ });
4238
+ return t;
4239
+ }
4240
+ let n = e.source, r = /* @__PURE__ */ new Map();
4241
+ for (let e of Array.isArray(n.links) ? n.links : []) Array.isArray(e) ? r.set(e[0], [e[1], e[2]]) : $(e) && r.set(e.id, [e.origin_id, e.origin_slot]);
4242
+ for (let e of Array.isArray(n.nodes) ? n.nodes : []) {
4243
+ if (!$(e) || typeof e.type != "string") continue;
4244
+ let n = {}, i = Array.isArray(e.widgets_values) ? e.widgets_values : [];
4245
+ e.type === "CLIPTextEncode" && (n.text = i[0]), (e.type === "KSampler" || e.type === "KSamplerAdvanced") && (e.type === "KSampler" ? [
4246
+ "seed",
4247
+ "",
4248
+ "steps",
4249
+ "cfg",
4250
+ "sampler_name",
4251
+ "scheduler",
4252
+ "denoise"
4253
+ ] : [
4254
+ "add_noise",
4255
+ "noise_seed",
4256
+ "",
4257
+ "steps",
4258
+ "cfg",
4259
+ "sampler_name",
4260
+ "scheduler",
4261
+ "start_at_step",
4262
+ "end_at_step"
4263
+ ]).forEach((e, t) => {
4264
+ e && (n[e] = i[t]);
4265
+ });
4266
+ for (let t of Array.isArray(e.inputs) ? e.inputs : []) $(t) && typeof t.name == "string" && r.has(t.link) && (n[t.name] = r.get(t.link));
4267
+ t.set(String(e.id), {
4268
+ type: e.type,
4269
+ inputs: n
4270
+ });
4271
+ }
4272
+ return t;
4273
+ }
4274
+ var Qi = {
4275
+ seed: "种子",
4276
+ noise_seed: "噪声种子",
4277
+ steps: "步数",
4278
+ cfg: "CFG",
4279
+ sampler_name: "采样器",
4280
+ scheduler: "调度器",
4281
+ denoise: "降噪强度",
4282
+ start_at_step: "起始步",
4283
+ end_at_step: "结束步"
4284
+ };
4285
+ function $i(e, t) {
4286
+ let n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = [t];
4287
+ for (; i.length;) {
4288
+ let t = i.pop();
4289
+ if (typeof t == "string") {
4290
+ t.trim() && n.add(t);
4291
+ continue;
4292
+ }
4293
+ if (!Array.isArray(t)) continue;
4294
+ let a = e.get(String(t[0])), o = t[0] + ":" + t[1];
4295
+ if (!a || r.has(o)) continue;
4296
+ if (r.add(o), a.inputs.positive !== void 0 && a.inputs.negative !== void 0) {
4297
+ (t[1] === 0 || t[1] === 1) && i.push(t[1] === 0 ? a.inputs.positive : a.inputs.negative);
4298
+ continue;
4299
+ }
4300
+ let s = Object.entries(a.inputs).filter(([e]) => /^(text(?:_[gl])?|string|value|prompt|conditioning(?:_\w+)?|positive|negative)$/i.test(e));
4301
+ i.push(...s.map(([, e]) => e).reverse());
4302
+ }
4303
+ return [...n].join("\n\n");
4304
+ }
4305
+ function ea(e, t) {
4306
+ function n(n) {
4307
+ if (e[n]) try {
4308
+ return mn(JSON.parse(e[n]), t);
4309
+ } catch {
4310
+ return;
4311
+ }
4312
+ }
4313
+ let r = n("workflow"), i = n("prompt"), a = r ?? i;
4314
+ if (!a && (e.workflow || e.prompt)) throw Error("无法解析 PNG 中的 ComfyUI 工作流");
4315
+ let o = a ? Zi(i ?? a) : /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), l = [];
4316
+ for (let [e, { type: t, inputs: n }] of o) {
4317
+ n.positive === void 0 ? t === "BasicGuider" && s.add($i(o, n.conditioning)) : s.add($i(o, n.positive)), n.negative !== void 0 && c.add($i(o, n.negative));
4318
+ let r = Object.entries(Qi).flatMap(([e, t]) => {
4319
+ let r = n[e];
4320
+ return typeof r == "number" || typeof r == "string" ? [{
4321
+ label: t,
4322
+ value: String(r)
4323
+ }] : [];
4324
+ });
4325
+ r.length && l.push({
4326
+ title: t + " · " + e,
4327
+ values: r
4328
+ });
4329
+ }
4330
+ let u = /* @__PURE__ */ new Set();
4331
+ for (let e of [r, i]) if (e) for (let t of mr(e)) u.add([t.directory, t.name].filter(Boolean).join("/"));
4332
+ return {
4333
+ workflow: a,
4334
+ positive: [...s].filter(Boolean).join("\n\n"),
4335
+ negative: [...c].filter(Boolean).join("\n\n"),
4336
+ samples: l,
4337
+ models: [...u]
4338
+ };
4339
+ }
4340
+ var ta = ue({
4341
+ id: "comfyui",
4342
+ activate(e) {
4343
+ qi(e, Xi);
4344
+ },
4345
+ app: {
4346
+ beforeUpdate: Pt,
4347
+ icon: "i-lucide-workflow",
4348
+ color: "#4A6CF7",
4349
+ identifiers: [
4350
+ {
4351
+ type: "file",
4352
+ pattern: "main.py",
4353
+ weight: 5
4354
+ },
4355
+ {
4356
+ type: "folder",
4357
+ pattern: "comfy",
4358
+ weight: 10
4359
+ },
4360
+ {
4361
+ type: "folder",
4362
+ pattern: "custom_nodes",
4363
+ weight: 8
4364
+ },
4365
+ {
4366
+ type: "git-remote",
4367
+ pattern: "comfyanonymous/ComfyUI",
4368
+ weight: 20
4369
+ },
4370
+ {
4371
+ type: "file",
4372
+ pattern: "comfy/model_management.py",
4373
+ weight: 15
4374
+ }
4375
+ ],
4376
+ async detect(e, t) {
4377
+ let n = await t.fs.listDir(e);
4378
+ return n.some((e) => e.name === "main.py" && !e.is_dir) && n.some((e) => e.name === "comfy" && e.is_dir) && n.some((e) => e.name === "custom_nodes" && e.is_dir);
4379
+ },
4380
+ webview: {
4381
+ urlTemplate: "http://127.0.0.1:{port}",
4382
+ defaultPort: 8188,
4383
+ portParamId: "port",
4384
+ autoOpen: !1
4385
+ },
4386
+ actions: [
4387
+ {
4388
+ id: "models",
4389
+ label: "模型管理",
4390
+ icon: "i-lucide-box",
4391
+ kind: "tab",
4392
+ target: "model-library",
4393
+ order: 1
4394
+ },
4395
+ {
4396
+ id: "custom-nodes",
4397
+ label: "自定义节点",
4398
+ icon: "i-lucide-puzzle",
4399
+ kind: "tab",
4400
+ target: "extension-management",
4401
+ order: 2
4402
+ },
4403
+ {
4404
+ id: "workflows",
4405
+ label: "工作流",
4406
+ icon: "i-lucide-folder",
4407
+ kind: "tab",
4408
+ target: "comfyui-workflows",
4409
+ order: 4
4410
+ },
4411
+ {
4412
+ id: "model-market",
4413
+ label: "模型市场",
4414
+ icon: "i-lucide-download",
4415
+ run: (e, t) => t.models.openMarket("", e.id),
4416
+ order: 5
4417
+ },
4418
+ {
4419
+ id: "settings",
4420
+ label: "启动配置",
4421
+ icon: "i-lucide-settings",
4422
+ kind: "tab",
4423
+ target: "settings",
4424
+ order: 6
4425
+ }
4426
+ ],
4427
+ python: { minVersion: "3.10" },
4428
+ discoverImport: ct,
4429
+ launchProvider: Ke,
4430
+ modelProvider: Ye,
4431
+ extensionProvider: at,
4432
+ extensionMarketProvider: ot,
4433
+ versionProvider: st,
4434
+ tabs: [{
4435
+ id: "comfyui-workflows",
4436
+ label: "工作流",
4437
+ icon: "i-lucide-workflow",
4438
+ order: 47,
4439
+ component: Gi,
4440
+ keepAlive: !1
4441
+ }]
4442
+ },
4443
+ slots: [
4444
+ {
4445
+ id: "shared-models",
4446
+ slot: "app:models:settings",
4447
+ component: xt,
4448
+ visibleWhen: ({ app: e }) => e?.pluginId === "comfyui"
4449
+ },
4450
+ {
4451
+ id: "environment-snapshots",
4452
+ slot: "app:maintenance",
4453
+ component: cn,
4454
+ visibleWhen: ({ app: e }) => e?.pluginId === "comfyui"
4455
+ },
4456
+ {
4457
+ id: "runtime-controls",
4458
+ slot: "app:overview:sections",
4459
+ label: "实时队列与显存",
4460
+ component: Ai,
4461
+ visibleWhen: ({ app: e }) => e?.pluginId === "comfyui" && e.status === "running"
4462
+ }
4463
+ ],
4464
+ launchParticipants: [{
4465
+ id: "shared-model-config",
4466
+ filter: { pluginIds: ["comfyui"] },
4467
+ async collectFacts(e) {
4468
+ e.mode === "start" && Nt(e.input.path);
4469
+ },
4470
+ async beforeSpawn(e) {
4471
+ Nt(e.facts.app.path);
4472
+ let t = Se(e.facts.params);
4473
+ t.length && await Te(e.api.fs, e.facts.app.path, t);
4474
+ }
4475
+ }],
4476
+ drops: ["app", "window"].map((e) => ({
4477
+ id: `workflow-${e}`,
4478
+ label: "预览 ComfyUI 工作流",
4479
+ scope: e,
4480
+ accept: { extensions: [".json", ".png"] },
4481
+ async handle(e, t) {
4482
+ if (e.files.length !== 1) throw Error("请一次拖入一个工作流文件");
4483
+ return {
4484
+ title: "ComfyUI 工作流预览",
4485
+ maximizable: !0,
4486
+ component: fi,
4487
+ props: {
4488
+ api: t,
4489
+ workflow: await hn(e.files[0]),
4490
+ initialAppId: e.app?.pluginId === "comfyui" ? e.app.id : void 0
4491
+ }
4492
+ };
4493
+ }
4494
+ }))
4495
+ });
4496
+ //#endregion
4497
+ export { ta as comfyuiPlugin, ta as default };