comfy-ts 2.24.0 → 2.25.1
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/chunk-6mgjbrp6.js +579 -0
- package/dist/chunk-6mgjbrp6.js.map +17 -0
- package/dist/chunk-6tsg7fm5.js +1876 -0
- package/dist/chunk-6tsg7fm5.js.map +31 -0
- package/dist/chunk-dvxjvwe7.js +2593 -0
- package/dist/chunk-dvxjvwe7.js.map +29 -0
- package/dist/chunk-dw0t1nye.js +457 -0
- package/dist/chunk-dw0t1nye.js.map +16 -0
- package/dist/chunk-he70ewwx.js +444 -0
- package/dist/chunk-he70ewwx.js.map +13 -0
- package/dist/chunk-n22qz0j1.js +6663 -0
- package/dist/chunk-n22qz0j1.js.map +95 -0
- package/dist/chunk-n35nffm8.js +4777 -0
- package/dist/chunk-n35nffm8.js.map +51 -0
- package/dist/cli/serve/hostProtocol.d.cts +74 -0
- package/dist/cli/serve/hostProtocol.d.ts +74 -0
- package/dist/cli/tui-env.d.cts +2 -0
- package/dist/cli/tui-env.d.ts +2 -0
- package/dist/cli.js +494 -485
- package/dist/cli.js.map +16 -1
- package/dist/coreExports.d.cts +45 -0
- package/dist/coreExports.d.ts +45 -0
- package/dist/errors/InvalidPromptError.d.cts +10 -0
- package/dist/errors/InvalidPromptError.d.ts +10 -0
- package/dist/exampleAssets.d.cts +24 -0
- package/dist/exampleAssets.d.ts +24 -0
- package/dist/graph/ComfyNode.d.cts +109 -0
- package/dist/graph/ComfyNode.d.ts +109 -0
- package/dist/graph/ComfyNodeID.d.cts +15 -0
- package/dist/graph/ComfyNodeID.d.ts +15 -0
- package/dist/graph/ComfyNodeOutput.d.cts +21 -0
- package/dist/graph/ComfyNodeOutput.d.ts +21 -0
- package/dist/graph/NodeSlotSize.d.cts +4 -0
- package/dist/graph/NodeSlotSize.d.ts +4 -0
- package/dist/graph/autoValue.d.cts +16 -0
- package/dist/graph/autoValue.d.ts +16 -0
- package/dist/host/ComfyHost.d.cts +383 -0
- package/dist/host/ComfyHost.d.ts +383 -0
- package/dist/host/ComfyInstallType.d.cts +11 -0
- package/dist/host/ComfyInstallType.d.ts +11 -0
- package/dist/host/ComfyManager.d.cts +152 -0
- package/dist/host/ComfyManager.d.ts +152 -0
- package/dist/host/ComfyUploader.d.cts +42 -0
- package/dist/host/ComfyUploader.d.ts +42 -0
- package/dist/host/ComfyWorkflowBuilder.d.cts +19 -0
- package/dist/host/ComfyWorkflowBuilder.d.ts +19 -0
- package/dist/host/Requirements.d.cts +43 -0
- package/dist/host/Requirements.d.ts +43 -0
- package/dist/host/ResilientWebsocket.d.cts +122 -0
- package/dist/host/ResilientWebsocket.d.ts +122 -0
- package/dist/host/hostFile.d.cts +23 -0
- package/dist/host/hostFile.d.ts +23 -0
- package/dist/host/hostUrl.d.cts +22 -0
- package/dist/host/hostUrl.d.ts +22 -0
- package/dist/host/leastBusy.d.cts +9 -0
- package/dist/host/leastBusy.d.ts +9 -0
- package/dist/host/loraInfoCache.d.cts +110 -0
- package/dist/host/loraInfoCache.d.ts +110 -0
- package/dist/host/loraManagerApi.d.cts +106 -0
- package/dist/host/loraManagerApi.d.ts +106 -0
- package/dist/host/previewMethod.d.cts +5 -0
- package/dist/host/previewMethod.d.ts +5 -0
- package/dist/host/schemaDrift.d.cts +54 -0
- package/dist/host/schemaDrift.d.ts +54 -0
- package/dist/image-utils/_getPngMetadata.d.cts +5 -0
- package/dist/image-utils/_getPngMetadata.d.ts +5 -0
- package/dist/index.cjs +8197 -8509
- package/dist/index.cjs.map +124 -1
- package/dist/index.d.cts +4 -19116
- package/dist/index.d.ts +4 -19116
- package/dist/index.js +8129 -8390
- package/dist/index.js.map +124 -1
- package/dist/litegraph/CanonicalWorkflow.d.cts +75 -0
- package/dist/litegraph/CanonicalWorkflow.d.ts +75 -0
- package/dist/litegraph/LiteGraphGroup.d.cts +17 -0
- package/dist/litegraph/LiteGraphGroup.d.ts +17 -0
- package/dist/litegraph/LiteGraphJSON.d.cts +242 -0
- package/dist/litegraph/LiteGraphJSON.d.ts +242 -0
- package/dist/litegraph/LiteGraphLink.d.cts +48 -0
- package/dist/litegraph/LiteGraphLink.d.ts +48 -0
- package/dist/litegraph/LiteGraphLinkID.d.cts +6 -0
- package/dist/litegraph/LiteGraphLinkID.d.ts +6 -0
- package/dist/litegraph/LiteGraphNode.d.cts +76 -0
- package/dist/litegraph/LiteGraphNode.d.ts +76 -0
- package/dist/litegraph/LiteGraphNodeInput.d.cts +25 -0
- package/dist/litegraph/LiteGraphNodeInput.d.ts +25 -0
- package/dist/litegraph/LiteGraphNodeOutput.d.cts +20 -0
- package/dist/litegraph/LiteGraphNodeOutput.d.ts +20 -0
- package/dist/litegraph/LiteGraphSlotIndex.d.cts +6 -0
- package/dist/litegraph/LiteGraphSlotIndex.d.ts +6 -0
- package/dist/litegraph/LiteGraphSubgraphDef.d.cts +174 -0
- package/dist/litegraph/LiteGraphSubgraphDef.d.ts +174 -0
- package/dist/litegraph/convertFlowToLiteGraphJSON.d.cts +12 -0
- package/dist/litegraph/convertFlowToLiteGraphJSON.d.ts +12 -0
- package/dist/litegraph/expandSubgraphs.d.cts +27 -0
- package/dist/litegraph/expandSubgraphs.d.ts +27 -0
- package/dist/litegraph/normalizeWorkflow.d.cts +21 -0
- package/dist/litegraph/normalizeWorkflow.d.ts +21 -0
- package/dist/manager/ComfyRegistry.d.cts +54 -0
- package/dist/manager/ComfyRegistry.d.ts +54 -0
- package/dist/manager/generated/KnownComfyCustomNodeName.d.cts +1 -0
- package/dist/manager/generated/KnownComfyCustomNodeName.d.ts +1 -0
- package/dist/manager/generated/KnownComfyPluginTitle.d.cts +12109 -0
- package/dist/manager/generated/KnownComfyPluginTitle.d.ts +12109 -0
- package/dist/manager/generated/KnownComfyPluginURL.d.cts +1 -0
- package/dist/manager/generated/KnownComfyPluginURL.d.ts +1 -0
- package/dist/manager/generated/KnownModel_Base.d.cts +2 -0
- package/dist/manager/generated/KnownModel_Base.d.ts +2 -0
- package/dist/manager/generated/KnownModel_Name.d.cts +2842 -0
- package/dist/manager/generated/KnownModel_Name.d.ts +2842 -0
- package/dist/manager/generated/KnownModel_SavePath.d.cts +2 -0
- package/dist/manager/generated/KnownModel_SavePath.d.ts +2 -0
- package/dist/manager/generated/KnownModel_Type.d.cts +2 -0
- package/dist/manager/generated/KnownModel_Type.d.ts +2 -0
- package/dist/manager/installedView.d.cts +65 -0
- package/dist/manager/installedView.d.ts +65 -0
- package/dist/manager/json/custom-node-list.extra.d.cts +2 -0
- package/dist/manager/json/custom-node-list.extra.d.ts +2 -0
- package/dist/manager/json/model-list.extra.d.cts +2 -0
- package/dist/manager/json/model-list.extra.d.ts +2 -0
- package/dist/manager/loaders/parseReport.d.cts +24 -0
- package/dist/manager/loaders/parseReport.d.ts +24 -0
- package/dist/manager/loaders/step1_downloadComfyManagerJSONs.d.cts +1 -0
- package/dist/manager/loaders/step1_downloadComfyManagerJSONs.d.ts +1 -0
- package/dist/manager/loaders/step2_custom-node-list-loader.d.cts +2 -0
- package/dist/manager/loaders/step2_custom-node-list-loader.d.ts +2 -0
- package/dist/manager/loaders/step3_extension-node-map-loader.d.cts +2 -0
- package/dist/manager/loaders/step3_extension-node-map-loader.d.ts +2 -0
- package/dist/manager/loaders/step4_model-list-loader.d.cts +2 -0
- package/dist/manager/loaders/step4_model-list-loader.d.ts +2 -0
- package/dist/manager/loaders/step5_alter-list-loader.d.cts +2 -0
- package/dist/manager/loaders/step5_alter-list-loader.d.ts +2 -0
- package/dist/manager/loaders/step6_github-stats-loader.d.cts +2 -0
- package/dist/manager/loaders/step6_github-stats-loader.d.ts +2 -0
- package/dist/manager/types/ComfyManagerAPIFetchPolicy.d.cts +7 -0
- package/dist/manager/types/ComfyManagerAPIFetchPolicy.d.ts +7 -0
- package/dist/manager/types/ComfyManagerAPIModelList.d.cts +10 -0
- package/dist/manager/types/ComfyManagerAPIModelList.d.ts +10 -0
- package/dist/manager/types/ComfyManagerAPIPluginList.d.cts +33 -0
- package/dist/manager/types/ComfyManagerAPIPluginList.d.ts +33 -0
- package/dist/manager/types/ComfyManagerAlterInfo.d.cts +12 -0
- package/dist/manager/types/ComfyManagerAlterInfo.d.ts +12 -0
- package/dist/manager/types/ComfyManagerFileModelInfo.d.cts +10 -0
- package/dist/manager/types/ComfyManagerFileModelInfo.d.ts +10 -0
- package/dist/manager/types/ComfyManagerFilePluginContent.d.cts +11 -0
- package/dist/manager/types/ComfyManagerFilePluginContent.d.ts +11 -0
- package/dist/manager/types/ComfyManagerFilePluginList.d.cts +5 -0
- package/dist/manager/types/ComfyManagerFilePluginList.d.ts +5 -0
- package/dist/manager/types/ComfyManagerGithubStats.d.cts +7 -0
- package/dist/manager/types/ComfyManagerGithubStats.d.ts +7 -0
- package/dist/manager/types/ComfyManagerModelInfo.d.cts +12 -0
- package/dist/manager/types/ComfyManagerModelInfo.d.ts +12 -0
- package/dist/manager/types/ComfyManagerPluginContentMetadata.d.cts +10 -0
- package/dist/manager/types/ComfyManagerPluginContentMetadata.d.ts +10 -0
- package/dist/manager/types/ComfyManagerPluginEnums.d.cts +5 -0
- package/dist/manager/types/ComfyManagerPluginEnums.d.ts +5 -0
- package/dist/manager/types/ComfyManagerPluginInfo.d.cts +54 -0
- package/dist/manager/types/ComfyManagerPluginInfo.d.ts +54 -0
- package/dist/promptEnhancers.d.cts +22 -0
- package/dist/promptEnhancers.d.ts +22 -0
- package/dist/runner/ComfyExecution.d.cts +230 -0
- package/dist/runner/ComfyExecution.d.ts +230 -0
- package/dist/runner/ComfyExecutionStatus.d.cts +1 -0
- package/dist/runner/ComfyExecutionStatus.d.ts +1 -0
- package/dist/runner/ComfyWorkflow.d.cts +141 -0
- package/dist/runner/ComfyWorkflow.d.ts +141 -0
- package/dist/runner/ComfyWorkflowLayout.d.cts +17 -0
- package/dist/runner/ComfyWorkflowLayout.d.ts +17 -0
- package/dist/runner/ComfyWsApi.d.cts +2174 -0
- package/dist/runner/ComfyWsApi.d.ts +2174 -0
- package/dist/runner/MediaImage.d.cts +127 -0
- package/dist/runner/MediaImage.d.ts +127 -0
- package/dist/runner/comfyOrgApiKey.d.cts +21 -0
- package/dist/runner/comfyOrgApiKey.d.ts +21 -0
- package/dist/runner/describePromptRejection.d.cts +1 -0
- package/dist/runner/describePromptRejection.d.ts +1 -0
- package/dist/runner/ephemeral.d.cts +10 -0
- package/dist/runner/ephemeral.d.ts +10 -0
- package/dist/runner/historyReplay.d.cts +13 -0
- package/dist/runner/historyReplay.d.ts +13 -0
- package/dist/runner/mediaKinds.d.cts +7 -0
- package/dist/runner/mediaKinds.d.ts +7 -0
- package/dist/runner/outputPath.d.cts +40 -0
- package/dist/runner/outputPath.d.ts +40 -0
- package/dist/runner/outputs3d.d.cts +3 -0
- package/dist/runner/outputs3d.d.ts +3 -0
- package/dist/runner/wsBinaryFrame.d.cts +25 -0
- package/dist/runner/wsBinaryFrame.d.ts +25 -0
- package/dist/sdk-generator/ComfyNodeSchema.d.cts +25 -0
- package/dist/sdk-generator/ComfyNodeSchema.d.ts +25 -0
- package/dist/sdk-generator/ComfySchema.d.cts +74 -0
- package/dist/sdk-generator/ComfySchema.d.ts +74 -0
- package/dist/sdk-generator/ComfyUIObjectInfoTypes.d.cts +3072 -0
- package/dist/sdk-generator/ComfyUIObjectInfoTypes.d.ts +3072 -0
- package/dist/sdk-generator/Primitives.d.cts +12 -0
- package/dist/sdk-generator/Primitives.d.ts +12 -0
- package/dist/sdk-generator/_getUnionNameBasedOnFirstFoundEnumName.d.cts +2 -0
- package/dist/sdk-generator/_getUnionNameBasedOnFirstFoundEnumName.d.ts +2 -0
- package/dist/sdk-generator/_pythonModuleToNamespace.d.cts +1 -0
- package/dist/sdk-generator/_pythonModuleToNamespace.d.ts +1 -0
- package/dist/sdk-generator/_toQualifiedNodeKey.d.cts +1 -0
- package/dist/sdk-generator/_toQualifiedNodeKey.d.ts +1 -0
- package/dist/sdk-generator/comfy-api-json.d.cts +16 -0
- package/dist/sdk-generator/comfy-api-json.d.ts +16 -0
- package/dist/sdk-generator/comfyui-sdk-codegen.d.cts +23 -0
- package/dist/sdk-generator/comfyui-sdk-codegen.d.ts +23 -0
- package/dist/sdk-generator/comfyui-types.d.cts +55 -0
- package/dist/sdk-generator/comfyui-types.d.ts +55 -0
- package/dist/sdk-generator/inputWidgetKind.d.cts +80 -0
- package/dist/sdk-generator/inputWidgetKind.d.ts +80 -0
- package/dist/sdk-generator/litegraphToApiRequestPayload.d.cts +41 -0
- package/dist/sdk-generator/litegraphToApiRequestPayload.d.ts +41 -0
- package/dist/serve-web.js +51 -51
- package/dist/ssh-host-manager/ssh-config-manager.d.cts +17 -0
- package/dist/ssh-host-manager/ssh-config-manager.d.ts +17 -0
- package/dist/state.d.cts +80 -0
- package/dist/state.d.ts +80 -0
- package/dist/storage/ComfyStorage.d.cts +55 -0
- package/dist/storage/ComfyStorage.d.ts +55 -0
- package/dist/storage/nodeStorage.d.cts +2 -0
- package/dist/storage/nodeStorage.d.ts +2 -0
- package/dist/types/comfy-sdk.d.cts +85 -0
- package/dist/types/comfy-sdk.d.ts +85 -0
- package/dist/types/index.d.cts +65 -0
- package/dist/types/index.d.ts +65 -0
- package/dist/utils/CodeBuffer.d.cts +20 -0
- package/dist/utils/CodeBuffer.d.ts +20 -0
- package/dist/utils/ComfyColors.d.cts +14 -0
- package/dist/utils/ComfyColors.d.ts +14 -0
- package/dist/utils/ansi.d.cts +22 -0
- package/dist/utils/ansi.d.ts +22 -0
- package/dist/utils/bang.d.cts +9 -0
- package/dist/utils/bang.d.ts +9 -0
- package/dist/utils/deepCopyNaive.d.cts +1 -0
- package/dist/utils/deepCopyNaive.d.ts +1 -0
- package/dist/utils/downloadFile.d.cts +2 -0
- package/dist/utils/downloadFile.d.ts +2 -0
- package/dist/utils/escapeJSKey.d.cts +2 -0
- package/dist/utils/escapeJSKey.d.ts +2 -0
- package/dist/utils/exhaust.d.cts +1 -0
- package/dist/utils/exhaust.d.ts +1 -0
- package/dist/utils/extractErrorMessage.d.cts +2 -0
- package/dist/utils/extractErrorMessage.d.ts +2 -0
- package/dist/utils/githubRegexes.d.cts +2 -0
- package/dist/utils/githubRegexes.d.ts +2 -0
- package/dist/utils/hashArrayBuffer.d.cts +1 -0
- package/dist/utils/hashArrayBuffer.d.ts +1 -0
- package/dist/utils/isRecord.d.cts +2 -0
- package/dist/utils/isRecord.d.ts +2 -0
- package/dist/utils/lazySharp.d.cts +3 -0
- package/dist/utils/lazySharp.d.ts +3 -0
- package/dist/utils/log.d.cts +4 -0
- package/dist/utils/log.d.ts +4 -0
- package/dist/utils/loraTag.d.cts +8 -0
- package/dist/utils/loraTag.d.ts +8 -0
- package/dist/utils/matchesRegex.d.cts +2 -0
- package/dist/utils/matchesRegex.d.ts +2 -0
- package/dist/utils/printArkResultInConsole.d.cts +2 -0
- package/dist/utils/printArkResultInConsole.d.ts +2 -0
- package/dist/utils/safeName.d.cts +6 -0
- package/dist/utils/safeName.d.ts +6 -0
- package/dist/utils/sha1.d.cts +2 -0
- package/dist/utils/sha1.d.ts +2 -0
- package/dist/utils/softValidate.d.cts +2 -0
- package/dist/utils/softValidate.d.ts +2 -0
- package/dist/utils/stringifyReadable.d.cts +1 -0
- package/dist/utils/stringifyReadable.d.ts +1 -0
- package/dist/utils/toposort.d.cts +3 -0
- package/dist/utils/toposort.d.ts +3 -0
- package/dist/vars/ComfyVars.d.cts +607 -0
- package/dist/vars/ComfyVars.d.ts +607 -0
- package/dist/vars/DefinedWorkflow.d.cts +104 -0
- package/dist/vars/DefinedWorkflow.d.ts +104 -0
- package/dist/vars/lanes.d.cts +81 -0
- package/dist/vars/lanes.d.ts +81 -0
- package/dist/vars/loraEntry.d.cts +26 -0
- package/dist/vars/loraEntry.d.ts +26 -0
- package/dist/vars/loraKeywords.d.cts +19 -0
- package/dist/vars/loraKeywords.d.ts +19 -0
- package/dist/vars/outputWidgets.d.cts +33 -0
- package/dist/vars/outputWidgets.d.ts +33 -0
- package/dist/vars/presets.d.cts +9 -0
- package/dist/vars/presets.d.ts +9 -0
- package/dist/vars/promptSyntax.d.cts +98 -0
- package/dist/vars/promptSyntax.d.ts +98 -0
- package/dist/web.d.cts +2 -0
- package/dist/web.d.ts +2 -19160
- package/dist/web.js +8040 -8292
- package/dist/web.js.map +119 -1
- package/examples/depth-explorer/web/tsconfig.json +1 -2
- package/examples/upscale-explorer/web/tsconfig.json +1 -2
- package/examples/web/tsconfig.json +1 -4
- package/examples/world-explorer/web/tsconfig.json +1 -2
- package/package.json +27 -32
- package/src/cli/serve/web/components/SideMenu.tsx +1 -1
- package/src/cli/serve/web/components/controls/LorasControl.tsx +2 -0
- package/src/cli/serve/web/components/controls/RichSelect.tsx +1 -0
- package/src/cli/serve/web/state/RunSt.poll.test.ts +2 -1
- package/src/cli/serve/web/tsconfig.json +1 -2
- package/src/cli/serve/web/widgets/RelightWidget.tsx +1 -0
- package/src/cli/tui/state/HostSt.ts +1 -1
- package/src/host/loraManagerApi.ts +8 -3
- package/src/runner/ComfyExecution.ts +3 -1
- package/src/runner/ComfyWsApi.ts +2 -1
- package/src/storage/ComfyStorage.ts +5 -4
- package/src/types/comfy-sdk.ts +1 -0
- package/src/utils/ansi.ts +1 -0
- package/dist/ServeApp-fsHtW5zG.js +0 -2689
- package/dist/ServeApp-fsHtW5zG.js.map +0 -1
- package/dist/exampleAssets-DZynSkZm.js +0 -6674
- package/dist/exampleAssets-DZynSkZm.js.map +0 -1
- package/dist/findDefinedWorkflow-qyqFea7q.js +0 -625
- package/dist/findDefinedWorkflow-qyqFea7q.js.map +0 -1
- package/dist/run-run-Cn2JzKlE.js +0 -449
- package/dist/run-run-Cn2JzKlE.js.map +0 -1
- package/dist/run-serve-BhGegaCI.js +0 -464
- package/dist/run-serve-BhGegaCI.js.map +0 -1
- package/dist/run-tui-CrM4ijkH.js +0 -4569
- package/dist/run-tui-CrM4ijkH.js.map +0 -1
- package/dist/schemaDrift-BGYJZGMD.js +0 -2225
- package/dist/schemaDrift-BGYJZGMD.js.map +0 -1
|
@@ -0,0 +1,1876 @@
|
|
|
1
|
+
// src/utils/extractErrorMessage.ts
|
|
2
|
+
var extractErrorMessage = (error) => {
|
|
3
|
+
if (error instanceof Error)
|
|
4
|
+
return error.message;
|
|
5
|
+
if (error === null)
|
|
6
|
+
return "null";
|
|
7
|
+
if (typeof error === "string")
|
|
8
|
+
return error;
|
|
9
|
+
if (typeof error === "object") {
|
|
10
|
+
if ("message" in error && typeof error.message === "string")
|
|
11
|
+
return error.message;
|
|
12
|
+
return JSON.stringify(error);
|
|
13
|
+
}
|
|
14
|
+
return String(error);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/utils/sha1.ts
|
|
18
|
+
function sha1Hex(data) {
|
|
19
|
+
const ml = data.length;
|
|
20
|
+
const total = Math.ceil((ml + 1 + 8) / 64) * 64;
|
|
21
|
+
const bytes = new Uint8Array(total);
|
|
22
|
+
bytes.set(data);
|
|
23
|
+
bytes[ml] = 128;
|
|
24
|
+
const dv = new DataView(bytes.buffer);
|
|
25
|
+
const bitLen = ml * 8;
|
|
26
|
+
dv.setUint32(total - 8, Math.floor(bitLen / 2 ** 32));
|
|
27
|
+
dv.setUint32(total - 4, bitLen >>> 0);
|
|
28
|
+
let h0 = 1732584193;
|
|
29
|
+
let h1 = 4023233417;
|
|
30
|
+
let h2 = 2562383102;
|
|
31
|
+
let h3 = 271733878;
|
|
32
|
+
let h4 = 3285377520;
|
|
33
|
+
const w = new Uint32Array(80);
|
|
34
|
+
for (let i = 0;i < total; i += 64) {
|
|
35
|
+
for (let j = 0;j < 16; j++)
|
|
36
|
+
w[j] = dv.getUint32(i + j * 4);
|
|
37
|
+
for (let j = 16;j < 80; j++) {
|
|
38
|
+
const n = (w[j - 3] ?? 0) ^ (w[j - 8] ?? 0) ^ (w[j - 14] ?? 0) ^ (w[j - 16] ?? 0);
|
|
39
|
+
w[j] = n << 1 | n >>> 31;
|
|
40
|
+
}
|
|
41
|
+
let a = h0;
|
|
42
|
+
let b = h1;
|
|
43
|
+
let c = h2;
|
|
44
|
+
let d = h3;
|
|
45
|
+
let e = h4;
|
|
46
|
+
for (let j = 0;j < 80; j++) {
|
|
47
|
+
let f;
|
|
48
|
+
let k;
|
|
49
|
+
if (j < 20) {
|
|
50
|
+
f = b & c | ~b & d;
|
|
51
|
+
k = 1518500249;
|
|
52
|
+
} else if (j < 40) {
|
|
53
|
+
f = b ^ c ^ d;
|
|
54
|
+
k = 1859775393;
|
|
55
|
+
} else if (j < 60) {
|
|
56
|
+
f = b & c | b & d | c & d;
|
|
57
|
+
k = 2400959708;
|
|
58
|
+
} else {
|
|
59
|
+
f = b ^ c ^ d;
|
|
60
|
+
k = 3395469782;
|
|
61
|
+
}
|
|
62
|
+
const temp = (a << 5 | a >>> 27) + f + e + k + (w[j] ?? 0) >>> 0;
|
|
63
|
+
e = d;
|
|
64
|
+
d = c;
|
|
65
|
+
c = b << 30 | b >>> 2;
|
|
66
|
+
b = a;
|
|
67
|
+
a = temp;
|
|
68
|
+
}
|
|
69
|
+
h0 = h0 + a >>> 0;
|
|
70
|
+
h1 = h1 + b >>> 0;
|
|
71
|
+
h2 = h2 + c >>> 0;
|
|
72
|
+
h3 = h3 + d >>> 0;
|
|
73
|
+
h4 = h4 + e >>> 0;
|
|
74
|
+
}
|
|
75
|
+
return [h0, h1, h2, h3, h4].map((x) => x.toString(16).padStart(8, "0")).join("");
|
|
76
|
+
}
|
|
77
|
+
function sha1HexOfString(s) {
|
|
78
|
+
return sha1Hex(new TextEncoder().encode(s));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/utils/matchesRegex.ts
|
|
82
|
+
function statelessRegex(re) {
|
|
83
|
+
if (!re.global && !re.sticky)
|
|
84
|
+
return re;
|
|
85
|
+
const source = re.sticky ? `^(?:${re.source})` : re.source;
|
|
86
|
+
return new RegExp(source, re.flags.replace(/[gy]/g, ""));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/utils/log.ts
|
|
90
|
+
var isQuiet = () => process.env.COMFY_TS_QUIET === "1";
|
|
91
|
+
var logInfo = (msg) => {
|
|
92
|
+
if (!isQuiet())
|
|
93
|
+
console.log(msg);
|
|
94
|
+
};
|
|
95
|
+
var logError = (msg) => console.error(`[comfy-ts] \uD83D\uDD34 ${msg}`);
|
|
96
|
+
var logSuccess = (msg) => console.log(`[comfy-ts] \uD83D\uDFE2 ${msg}`);
|
|
97
|
+
|
|
98
|
+
// src/storage/ComfyStorage.ts
|
|
99
|
+
function dirnameOf(path) {
|
|
100
|
+
const ix = path.lastIndexOf("/");
|
|
101
|
+
return ix <= 0 ? "/" : path.slice(0, ix);
|
|
102
|
+
}
|
|
103
|
+
function createNodeStorageFrom(fs, os) {
|
|
104
|
+
return {
|
|
105
|
+
kind: "node",
|
|
106
|
+
readText: (p) => fs.readFileSync(p, "utf8"),
|
|
107
|
+
readTextIfExists: (p) => fs.existsSync(p) ? fs.readFileSync(p, "utf8") : null,
|
|
108
|
+
readBytes: (p) => new Uint8Array(fs.readFileSync(p)),
|
|
109
|
+
writeText: (p, text) => {
|
|
110
|
+
fs.mkdirSync(dirnameOf(p), { recursive: true });
|
|
111
|
+
fs.writeFileSync(p, text);
|
|
112
|
+
},
|
|
113
|
+
writeBytes: (p, bytes) => {
|
|
114
|
+
fs.mkdirSync(dirnameOf(p), { recursive: true });
|
|
115
|
+
fs.writeFileSync(p, bytes);
|
|
116
|
+
},
|
|
117
|
+
exists: (p) => fs.existsSync(p),
|
|
118
|
+
mkdirp: (p) => void fs.mkdirSync(p, { recursive: true }),
|
|
119
|
+
mtimeMs: (p) => fs.existsSync(p) ? fs.statSync(p).mtimeMs : null,
|
|
120
|
+
homedir: () => os.homedir(),
|
|
121
|
+
cwd: () => process.cwd()
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
var installedDefault = null;
|
|
125
|
+
function autodetectNodeStorage() {
|
|
126
|
+
const get = globalThis.process?.getBuiltinModule;
|
|
127
|
+
if (typeof get !== "function")
|
|
128
|
+
return null;
|
|
129
|
+
const fs = get("node:fs");
|
|
130
|
+
const os = get("node:os");
|
|
131
|
+
if (fs == null || os == null)
|
|
132
|
+
return null;
|
|
133
|
+
return createNodeStorageFrom(fs, os);
|
|
134
|
+
}
|
|
135
|
+
function resolveComfyStorage(explicit) {
|
|
136
|
+
if (explicit != null)
|
|
137
|
+
return explicit;
|
|
138
|
+
if (installedDefault != null)
|
|
139
|
+
return installedDefault;
|
|
140
|
+
const detected = autodetectNodeStorage();
|
|
141
|
+
if (detected != null) {
|
|
142
|
+
installedDefault = detected;
|
|
143
|
+
return detected;
|
|
144
|
+
}
|
|
145
|
+
throw new Error(`no ComfyStorage available — import 'comfy-ts' (node) or 'comfy-ts/web' (browser) before creating ComfyTS, or pass ComfyTS.create({ storage })`);
|
|
146
|
+
}
|
|
147
|
+
function getComfyStorage() {
|
|
148
|
+
const g = globalThis;
|
|
149
|
+
return g.comfyts?.storage ?? resolveComfyStorage();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/utils/bang.ts
|
|
153
|
+
var bang = (x, msg = "") => {
|
|
154
|
+
if (x == null) {
|
|
155
|
+
console.error(`[\uD83D\uDD34] BANG FAILED`, msg);
|
|
156
|
+
throw new Error("bang: " + (msg ?? "no message"));
|
|
157
|
+
}
|
|
158
|
+
return x;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// src/utils/isRecord.ts
|
|
162
|
+
function isRecord(v) {
|
|
163
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/utils/lazySharp.ts
|
|
167
|
+
var cached = null;
|
|
168
|
+
async function importSharp(reason) {
|
|
169
|
+
if (cached != null)
|
|
170
|
+
return cached;
|
|
171
|
+
const specifier = "sharp";
|
|
172
|
+
try {
|
|
173
|
+
const mod = await import(specifier);
|
|
174
|
+
cached = mod.default;
|
|
175
|
+
return cached;
|
|
176
|
+
} catch (e) {
|
|
177
|
+
throw new Error(`sharp is unavailable — ${reason} is node-only (browser builds get raw bytes instead): ${extractErrorMessage(e)}`, { cause: e });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/utils/hashArrayBuffer.ts
|
|
182
|
+
var hashArrayBuffer = (buffer) => {
|
|
183
|
+
return sha1Hex(buffer);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// src/runner/mediaKinds.ts
|
|
187
|
+
var MEDIA_KINDS = ["image", "audio", "video"];
|
|
188
|
+
var DEFAULT_MEDIA_EXTENSIONS = {
|
|
189
|
+
image: ["png", "jpg", "jpeg", "webp", "gif"],
|
|
190
|
+
audio: ["wav", "flac", "mp3", "ogg", "opus", "m4a"],
|
|
191
|
+
video: ["mp4", "webm", "mov", "mkv", "m4v"]
|
|
192
|
+
};
|
|
193
|
+
var MIMES = {
|
|
194
|
+
png: "image/png",
|
|
195
|
+
jpg: "image/jpeg",
|
|
196
|
+
jpeg: "image/jpeg",
|
|
197
|
+
webp: "image/webp",
|
|
198
|
+
gif: "image/gif",
|
|
199
|
+
flac: "audio/flac",
|
|
200
|
+
mp3: "audio/mpeg",
|
|
201
|
+
opus: "audio/ogg",
|
|
202
|
+
ogg: "audio/ogg",
|
|
203
|
+
wav: "audio/wav",
|
|
204
|
+
m4a: "audio/mp4",
|
|
205
|
+
aac: "audio/aac",
|
|
206
|
+
mp4: "video/mp4",
|
|
207
|
+
m4v: "video/mp4",
|
|
208
|
+
webm: "video/webm",
|
|
209
|
+
mov: "video/quicktime",
|
|
210
|
+
mkv: "video/x-matroska",
|
|
211
|
+
avi: "video/x-msvideo"
|
|
212
|
+
};
|
|
213
|
+
var VIDEO_EXTENSIONS = new Set(["mp4", "m4v", "webm", "mov", "mkv", "avi"]);
|
|
214
|
+
function extensionOf(filename) {
|
|
215
|
+
const dot = filename.lastIndexOf(".");
|
|
216
|
+
return dot < 0 ? "" : filename.slice(dot + 1).toLowerCase();
|
|
217
|
+
}
|
|
218
|
+
function isVideoFilename(filename) {
|
|
219
|
+
return VIDEO_EXTENSIONS.has(extensionOf(filename));
|
|
220
|
+
}
|
|
221
|
+
function mediaMime(filename) {
|
|
222
|
+
return MIMES[extensionOf(filename)] ?? "application/octet-stream";
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/runner/outputs3d.ts
|
|
226
|
+
var MODEL_3D_MIMES = {
|
|
227
|
+
glb: "model/gltf-binary",
|
|
228
|
+
gltf: "model/gltf+json",
|
|
229
|
+
ply: "model/x-ply",
|
|
230
|
+
spz: "model/x-spz",
|
|
231
|
+
obj: "model/obj",
|
|
232
|
+
stl: "model/stl"
|
|
233
|
+
};
|
|
234
|
+
function model3dMime(filename) {
|
|
235
|
+
return MODEL_3D_MIMES[extensionOf(filename)] ?? "application/octet-stream";
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/utils/ansi.ts
|
|
239
|
+
var codes = {
|
|
240
|
+
bold: [1, 22],
|
|
241
|
+
dim: [2, 22],
|
|
242
|
+
underline: [4, 24],
|
|
243
|
+
red: [31, 39],
|
|
244
|
+
green: [32, 39],
|
|
245
|
+
yellow: [33, 39],
|
|
246
|
+
blue: [34, 39],
|
|
247
|
+
cyan: [36, 39],
|
|
248
|
+
gray: [90, 39],
|
|
249
|
+
greenBright: [92, 39]
|
|
250
|
+
};
|
|
251
|
+
function styler(open = "", close = "") {
|
|
252
|
+
const fn = (s) => open + s + close;
|
|
253
|
+
return new Proxy(fn, {
|
|
254
|
+
get(_target, prop) {
|
|
255
|
+
const c = codes[prop];
|
|
256
|
+
if (c == null)
|
|
257
|
+
throw new Error(`unknown ansi style: ${prop}`);
|
|
258
|
+
return styler(`${open}\x1B[${c[0]}m`, `\x1B[${c[1]}m${close}`);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
var ansi = styler();
|
|
263
|
+
var ANSI_RE = /\x1b\[[0-9;?]*[A-Za-z]|\x1b[A-Za-z]/g;
|
|
264
|
+
function stripAnsi(s) {
|
|
265
|
+
return s.replace(ANSI_RE, "");
|
|
266
|
+
}
|
|
267
|
+
function colorsAvailable() {
|
|
268
|
+
const env = globalThis.process?.env ?? {};
|
|
269
|
+
if (env.NO_COLOR != null && env.NO_COLOR !== "")
|
|
270
|
+
return false;
|
|
271
|
+
if (env.TERM === "dumb")
|
|
272
|
+
return false;
|
|
273
|
+
if (env.FORCE_COLOR != null && env.FORCE_COLOR !== "" && env.FORCE_COLOR !== "0")
|
|
274
|
+
return true;
|
|
275
|
+
return globalThis.process?.stdout?.isTTY === true;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// src/vars/ComfyVars.ts
|
|
279
|
+
import { imageMeta } from "image-meta";
|
|
280
|
+
import { action, makeObservable, observable as observable2 } from "mobx";
|
|
281
|
+
import { basename as basename2, isAbsolute, join as join3, resolve } from "pathe";
|
|
282
|
+
|
|
283
|
+
// src/vars/loraKeywords.ts
|
|
284
|
+
import { observable, runInAction } from "mobx";
|
|
285
|
+
import { join as join2 } from "pathe";
|
|
286
|
+
|
|
287
|
+
// src/host/loraInfoCache.ts
|
|
288
|
+
import { join } from "pathe";
|
|
289
|
+
|
|
290
|
+
// src/host/loraManagerApi.ts
|
|
291
|
+
import { type } from "arktype";
|
|
292
|
+
import { basename } from "pathe";
|
|
293
|
+
var lmLoraPage = type({
|
|
294
|
+
items: "unknown[]",
|
|
295
|
+
"total?": "number"
|
|
296
|
+
});
|
|
297
|
+
function readString(item, key) {
|
|
298
|
+
const v = item[key];
|
|
299
|
+
return typeof v === "string" && v !== "" ? v : null;
|
|
300
|
+
}
|
|
301
|
+
function readStringArray(item, key) {
|
|
302
|
+
const v = item[key];
|
|
303
|
+
if (!Array.isArray(v))
|
|
304
|
+
return [];
|
|
305
|
+
return v.filter((x) => typeof x === "string" && x !== "");
|
|
306
|
+
}
|
|
307
|
+
function lmFileName(item) {
|
|
308
|
+
return readString(item, "file_name");
|
|
309
|
+
}
|
|
310
|
+
function lmFolder(item) {
|
|
311
|
+
return readString(item, "folder") ?? "";
|
|
312
|
+
}
|
|
313
|
+
function lmModelName(item) {
|
|
314
|
+
return readString(item, "model_name");
|
|
315
|
+
}
|
|
316
|
+
function lmBaseModel(item) {
|
|
317
|
+
return readString(item, "base_model");
|
|
318
|
+
}
|
|
319
|
+
function lmPreviewUrl(item) {
|
|
320
|
+
return readString(item, "preview_url");
|
|
321
|
+
}
|
|
322
|
+
function lmSha256(item) {
|
|
323
|
+
return readString(item, "sha256");
|
|
324
|
+
}
|
|
325
|
+
function lmModified(item) {
|
|
326
|
+
const raw = item["modified"];
|
|
327
|
+
return typeof raw === "number" && Number.isFinite(raw) ? raw : null;
|
|
328
|
+
}
|
|
329
|
+
function lmFileSize(item) {
|
|
330
|
+
const raw = item["file_size"];
|
|
331
|
+
return typeof raw === "number" && Number.isFinite(raw) ? raw : null;
|
|
332
|
+
}
|
|
333
|
+
function lmNotes(item) {
|
|
334
|
+
return readString(item, "notes") ?? "";
|
|
335
|
+
}
|
|
336
|
+
function lmCivitai(item) {
|
|
337
|
+
const civitai = item["civitai"];
|
|
338
|
+
if (!isRecord(civitai))
|
|
339
|
+
return null;
|
|
340
|
+
const modelId = civitai["modelId"];
|
|
341
|
+
return {
|
|
342
|
+
modelId: typeof modelId === "number" && Number.isFinite(modelId) ? modelId : null,
|
|
343
|
+
name: readString(civitai, "name")
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
function lmTags(item) {
|
|
347
|
+
return readStringArray(item, "tags");
|
|
348
|
+
}
|
|
349
|
+
function lmTrainedWords(item) {
|
|
350
|
+
const civitai = item["civitai"];
|
|
351
|
+
if (!isRecord(civitai))
|
|
352
|
+
return [];
|
|
353
|
+
return readStringArray(civitai, "trainedWords");
|
|
354
|
+
}
|
|
355
|
+
function lmFilePath(item) {
|
|
356
|
+
return readString(item, "file_path");
|
|
357
|
+
}
|
|
358
|
+
function loraKey(name) {
|
|
359
|
+
return name.replaceAll("\\", "/").replace(/\.(safetensors|st|pt|ckpt)$/i, "").toLowerCase();
|
|
360
|
+
}
|
|
361
|
+
function loraBasename(name) {
|
|
362
|
+
return basename(name.replaceAll("\\", "/"));
|
|
363
|
+
}
|
|
364
|
+
function lmItemKey(item) {
|
|
365
|
+
const file = lmFileName(item);
|
|
366
|
+
if (file == null)
|
|
367
|
+
return null;
|
|
368
|
+
const folder = lmFolder(item);
|
|
369
|
+
return loraKey(folder === "" ? file : `${folder}/${file}`);
|
|
370
|
+
}
|
|
371
|
+
var MAX_PAGES = 20;
|
|
372
|
+
async function fetchLoraCivitai(host, filePath) {
|
|
373
|
+
try {
|
|
374
|
+
const res = await host.fetch("/lm/loras/fetch-civitai", {
|
|
375
|
+
method: "POST",
|
|
376
|
+
headers: { "content-type": "application/json" },
|
|
377
|
+
body: JSON.stringify({ file_path: filePath })
|
|
378
|
+
});
|
|
379
|
+
const raw = await res.json().catch(() => null);
|
|
380
|
+
const error = isRecord(raw) && typeof raw["error"] === "string" ? raw["error"] : null;
|
|
381
|
+
if (res.ok && isRecord(raw) && raw["success"] !== false)
|
|
382
|
+
return { ok: true };
|
|
383
|
+
return { ok: false, reason: error ?? `the lora manager answered ${res.status}` };
|
|
384
|
+
} catch (e) {
|
|
385
|
+
return { ok: false, reason: extractErrorMessage(e) };
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
async function fetchLoraDescription(host, filePath) {
|
|
389
|
+
try {
|
|
390
|
+
const res = await host.fetch(`/lm/loras/model-description?file_path=${encodeURIComponent(filePath)}`, {});
|
|
391
|
+
if (!res.ok) {
|
|
392
|
+
if (res.status !== 404)
|
|
393
|
+
logError(`[lora-manager] description ${res.status} for ${filePath}`);
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
const raw = await res.json();
|
|
397
|
+
const description = isRecord(raw) ? raw["description"] : null;
|
|
398
|
+
if (typeof description !== "string" || description === "")
|
|
399
|
+
return null;
|
|
400
|
+
return htmlToText(description);
|
|
401
|
+
} catch (e) {
|
|
402
|
+
logError(`[lora-manager] description unreachable for ${filePath}: ${extractErrorMessage(e)}`);
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function htmlToText(html) {
|
|
407
|
+
return html.replaceAll(/<\s*br\s*\/?>/gi, `
|
|
408
|
+
`).replaceAll(/<\/\s*(p|div|li|h[1-6])\s*>/gi, `
|
|
409
|
+
|
|
410
|
+
`).replaceAll(/<\s*li[^>]*>/gi, "· ").replaceAll(/<[^>]+>/g, "").replaceAll(" ", " ").replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll(""", '"').replaceAll("'", "'").replaceAll(/\n{3,}/g, `
|
|
411
|
+
|
|
412
|
+
`).trim();
|
|
413
|
+
}
|
|
414
|
+
async function fetchLoraExampleImages(host, sha256) {
|
|
415
|
+
try {
|
|
416
|
+
const res = await host.fetch(`/lm/example-image-files?model_hash=${encodeURIComponent(sha256)}`, {});
|
|
417
|
+
const raw = await res.json();
|
|
418
|
+
if (!isRecord(raw))
|
|
419
|
+
return { files: [], reason: `unexpected reply (http ${res.status})` };
|
|
420
|
+
if (raw["success"] !== true) {
|
|
421
|
+
const err = raw["error"];
|
|
422
|
+
return { files: [], reason: typeof err === "string" ? err : `http ${res.status}` };
|
|
423
|
+
}
|
|
424
|
+
const files = raw["files"];
|
|
425
|
+
if (!Array.isArray(files))
|
|
426
|
+
return { files: [], reason: null };
|
|
427
|
+
const out = [];
|
|
428
|
+
for (const f of files) {
|
|
429
|
+
if (typeof f === "string")
|
|
430
|
+
out.push(f);
|
|
431
|
+
else if (isRecord(f) && typeof f["path"] === "string")
|
|
432
|
+
out.push(f["path"]);
|
|
433
|
+
}
|
|
434
|
+
return { files: out, reason: null };
|
|
435
|
+
} catch (e) {
|
|
436
|
+
return { files: [], reason: e instanceof Error ? e.message : String(e) };
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
async function fetchLoraList(host) {
|
|
440
|
+
const items = [];
|
|
441
|
+
for (let page = 1;page <= MAX_PAGES; page++) {
|
|
442
|
+
let res;
|
|
443
|
+
try {
|
|
444
|
+
res = await host.fetch(`/api/lm/loras/list?page=${page}&page_size=500`, {}, { apiPrefix: false });
|
|
445
|
+
} catch (e) {
|
|
446
|
+
const reason = `host unreachable at page ${page}: ${extractErrorMessage(e)}`;
|
|
447
|
+
return page === 1 ? { status: "unreachable", reason } : partial(items, reason);
|
|
448
|
+
}
|
|
449
|
+
if (!res.ok) {
|
|
450
|
+
const missing = res.status === 404 || res.status === 405;
|
|
451
|
+
if (page === 1)
|
|
452
|
+
return missing ? { status: "absent" } : { status: "unreachable", reason: `answered ${res.status}` };
|
|
453
|
+
return partial(items, `page ${page} answered ${res.status}`);
|
|
454
|
+
}
|
|
455
|
+
let parsed;
|
|
456
|
+
try {
|
|
457
|
+
parsed = lmLoraPage(await res.json());
|
|
458
|
+
} catch (e) {
|
|
459
|
+
const reason = `page ${page} did not answer json: ${extractErrorMessage(e)}`;
|
|
460
|
+
return page === 1 ? { status: "absent" } : partial(items, reason);
|
|
461
|
+
}
|
|
462
|
+
if (parsed instanceof type.errors) {
|
|
463
|
+
return partial(items, `page ${page} shape mismatch: ${parsed.summary}`);
|
|
464
|
+
}
|
|
465
|
+
const pageItems = parsed.items.filter(isRecord);
|
|
466
|
+
items.push(...pageItems);
|
|
467
|
+
const total = parsed.total;
|
|
468
|
+
if (total != null && items.length >= total)
|
|
469
|
+
return { status: "ok", items };
|
|
470
|
+
if (pageItems.length === 0) {
|
|
471
|
+
return total == null || page === 1 ? { status: "ok", items } : partial(items, `page ${page} came back empty with ${items.length}/${total} fetched`);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return partial(items, `stopped at the ${MAX_PAGES}-page runaway limit`);
|
|
475
|
+
}
|
|
476
|
+
function partial(items, reason) {
|
|
477
|
+
logError(`[loraManagerApi] lora sweep INCOMPLETE after ${items.length} loras — ${reason}`);
|
|
478
|
+
return { status: "partial", items, reason };
|
|
479
|
+
}
|
|
480
|
+
function loraPreviewMapFrom(items) {
|
|
481
|
+
const map = new Map;
|
|
482
|
+
for (const item of items) {
|
|
483
|
+
const key = lmItemKey(item);
|
|
484
|
+
const url = lmPreviewUrl(item);
|
|
485
|
+
if (key != null && url != null)
|
|
486
|
+
map.set(key, url);
|
|
487
|
+
}
|
|
488
|
+
return map;
|
|
489
|
+
}
|
|
490
|
+
function looksLikeImage(bytes) {
|
|
491
|
+
if (bytes.length < 3)
|
|
492
|
+
return false;
|
|
493
|
+
const b = bytes;
|
|
494
|
+
const is = (sig, off = 0) => sig.every((v, i) => b[off + i] === v);
|
|
495
|
+
return is([137, 80, 78, 71]) || is([255, 216, 255]) || is([71, 73, 70]) || is([82, 73, 70, 70]) && is([87, 69, 66, 80], 8);
|
|
496
|
+
}
|
|
497
|
+
function previewContentTypeMayBeImage(ct) {
|
|
498
|
+
return ct === "" || ct.startsWith("image/") || ct.startsWith("application/octet-stream");
|
|
499
|
+
}
|
|
500
|
+
async function fetchLoraPreviewBytes(host, previewUrl) {
|
|
501
|
+
const storage = getComfyStorage();
|
|
502
|
+
const cachePath = comfyts.resolveFromCache(`lora-previews/${sha1HexOfString(previewUrl)}`);
|
|
503
|
+
if (storage.exists(cachePath))
|
|
504
|
+
return storage.readBytes(cachePath);
|
|
505
|
+
try {
|
|
506
|
+
const res = await host.fetch(previewUrl, {}, { apiPrefix: false });
|
|
507
|
+
if (!res.ok)
|
|
508
|
+
return null;
|
|
509
|
+
if (!previewContentTypeMayBeImage(res.headers.get("content-type") ?? ""))
|
|
510
|
+
return null;
|
|
511
|
+
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
512
|
+
if (!looksLikeImage(bytes))
|
|
513
|
+
return null;
|
|
514
|
+
storage.writeBytes(cachePath, bytes);
|
|
515
|
+
return bytes;
|
|
516
|
+
} catch {
|
|
517
|
+
return null;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// src/host/loraInfoCache.ts
|
|
522
|
+
function loraMirrorPath(hostId) {
|
|
523
|
+
return comfyts.resolveFromHosts(join(hostId, "loras.json"));
|
|
524
|
+
}
|
|
525
|
+
function buildLoraMirror(p) {
|
|
526
|
+
const loras = {};
|
|
527
|
+
for (const item of p.items) {
|
|
528
|
+
const key = lmItemKey(item);
|
|
529
|
+
if (key == null)
|
|
530
|
+
continue;
|
|
531
|
+
if (loras[key] != null)
|
|
532
|
+
logError(`[loraInfoCache] two loras share the key '${key}' — one of them is shadowed`);
|
|
533
|
+
loras[key] = item;
|
|
534
|
+
}
|
|
535
|
+
return {
|
|
536
|
+
hostId: p.hostId,
|
|
537
|
+
hostUrl: p.hostUrl,
|
|
538
|
+
fetchedAt: p.fetchedAt,
|
|
539
|
+
count: Object.keys(loras).length,
|
|
540
|
+
loras
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
function writeLoraMirror(mirror) {
|
|
544
|
+
const path = loraMirrorPath(mirror.hostId);
|
|
545
|
+
getComfyStorage().writeText(path, JSON.stringify(mirror, null, 2));
|
|
546
|
+
return path;
|
|
547
|
+
}
|
|
548
|
+
function readLoraMirror(hostId) {
|
|
549
|
+
const path = loraMirrorPath(hostId);
|
|
550
|
+
const text = getComfyStorage().readTextIfExists(path);
|
|
551
|
+
if (text == null)
|
|
552
|
+
return null;
|
|
553
|
+
try {
|
|
554
|
+
const raw = JSON.parse(text);
|
|
555
|
+
if (!isRecord(raw))
|
|
556
|
+
return null;
|
|
557
|
+
const rawLoras = raw["loras"];
|
|
558
|
+
if (!isRecord(rawLoras))
|
|
559
|
+
return null;
|
|
560
|
+
const loras = {};
|
|
561
|
+
for (const [key, item] of Object.entries(rawLoras))
|
|
562
|
+
if (isRecord(item))
|
|
563
|
+
loras[key] = item;
|
|
564
|
+
const str = (key, fallback) => {
|
|
565
|
+
const v = raw[key];
|
|
566
|
+
return typeof v === "string" ? v : fallback;
|
|
567
|
+
};
|
|
568
|
+
return {
|
|
569
|
+
hostId: str("hostId", hostId),
|
|
570
|
+
hostUrl: str("hostUrl", ""),
|
|
571
|
+
fetchedAt: str("fetchedAt", ""),
|
|
572
|
+
count: Object.keys(loras).length,
|
|
573
|
+
loras
|
|
574
|
+
};
|
|
575
|
+
} catch (e) {
|
|
576
|
+
logError(`[loraInfoCache] unreadable ${path}: ${String(e)}`);
|
|
577
|
+
return null;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
var byHost = new Map;
|
|
581
|
+
var loadedMtimes = new Map;
|
|
582
|
+
function ensureLoaded() {
|
|
583
|
+
for (const hostId of comfyts.hosts.keys())
|
|
584
|
+
if (!loadedMtimes.has(hostId))
|
|
585
|
+
loadHost(hostId);
|
|
586
|
+
}
|
|
587
|
+
function loadHost(hostId) {
|
|
588
|
+
const storage = getComfyStorage();
|
|
589
|
+
const path = loraMirrorPath(hostId);
|
|
590
|
+
loadedMtimes.set(hostId, storage.mtimeMs(path));
|
|
591
|
+
const mirror = readLoraMirror(hostId);
|
|
592
|
+
if (mirror != null)
|
|
593
|
+
byHost.set(hostId, new Map(Object.entries(mirror.loras)));
|
|
594
|
+
else if (storage.exists(path))
|
|
595
|
+
byHost.set(hostId, new Map);
|
|
596
|
+
else
|
|
597
|
+
byHost.delete(hostId);
|
|
598
|
+
}
|
|
599
|
+
function refreshLoraInfoCacheIfChanged() {
|
|
600
|
+
const storage = getComfyStorage();
|
|
601
|
+
for (const hostId of comfyts.hosts.keys()) {
|
|
602
|
+
const seen = loadedMtimes.get(hostId);
|
|
603
|
+
const now = storage.mtimeMs(loraMirrorPath(hostId));
|
|
604
|
+
if (!loadedMtimes.has(hostId) || seen !== now)
|
|
605
|
+
loadHost(hostId);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
function reloadLoraInfoCache() {
|
|
609
|
+
byHost.clear();
|
|
610
|
+
loadedMtimes.clear();
|
|
611
|
+
}
|
|
612
|
+
function getLoraInfo(name, hostId) {
|
|
613
|
+
ensureLoaded();
|
|
614
|
+
const key = loraKey(name);
|
|
615
|
+
if (hostId != null) {
|
|
616
|
+
const own = byHost.get(hostId);
|
|
617
|
+
if (own != null)
|
|
618
|
+
return own.get(key) ?? null;
|
|
619
|
+
}
|
|
620
|
+
for (const mirror of byHost.values()) {
|
|
621
|
+
const hit = mirror.get(key);
|
|
622
|
+
if (hit != null)
|
|
623
|
+
return hit;
|
|
624
|
+
}
|
|
625
|
+
return null;
|
|
626
|
+
}
|
|
627
|
+
function getLoraTriggerWords(name, hostId) {
|
|
628
|
+
const info = getLoraInfo(name, hostId);
|
|
629
|
+
return info == null ? [] : lmTrainedWords(info);
|
|
630
|
+
}
|
|
631
|
+
function getLoraDisplayName(name, hostId) {
|
|
632
|
+
const info = getLoraInfo(name, hostId);
|
|
633
|
+
return (info == null ? null : lmModelName(info)) ?? loraBasename(name);
|
|
634
|
+
}
|
|
635
|
+
function loraTriggersOf(item, p = {}) {
|
|
636
|
+
const words = lmTrainedWords(item);
|
|
637
|
+
if (words.length > 0)
|
|
638
|
+
return { state: "words", words };
|
|
639
|
+
const civitai = item["civitai"];
|
|
640
|
+
if (isRecord(civitai) && (typeof civitai["id"] === "number" || typeof civitai["modelId"] === "number"))
|
|
641
|
+
return { state: "none" };
|
|
642
|
+
return p.civitaiMiss === true ? { state: "not-on-civitai" } : { state: "unfetched" };
|
|
643
|
+
}
|
|
644
|
+
function getLoraTriggers(name, hostId) {
|
|
645
|
+
const info = getLoraInfo(name, hostId);
|
|
646
|
+
if (info == null)
|
|
647
|
+
return null;
|
|
648
|
+
const sha = lmSha256(info);
|
|
649
|
+
return loraTriggersOf(info, { civitaiMiss: hostId != null && sha != null && readCivitaiMisses(hostId)[sha] != null });
|
|
650
|
+
}
|
|
651
|
+
function civitaiMissesPath(hostId) {
|
|
652
|
+
return comfyts.resolveFromHosts(join(hostId, "lora-civitai-misses.json"));
|
|
653
|
+
}
|
|
654
|
+
function readCivitaiMisses(hostId) {
|
|
655
|
+
const text = getComfyStorage().readTextIfExists(civitaiMissesPath(hostId));
|
|
656
|
+
if (text == null)
|
|
657
|
+
return {};
|
|
658
|
+
try {
|
|
659
|
+
const raw = JSON.parse(text);
|
|
660
|
+
const out = {};
|
|
661
|
+
if (isRecord(raw)) {
|
|
662
|
+
for (const [sha, at] of Object.entries(raw))
|
|
663
|
+
if (typeof at === "string")
|
|
664
|
+
out[sha] = at;
|
|
665
|
+
}
|
|
666
|
+
return out;
|
|
667
|
+
} catch (e) {
|
|
668
|
+
logError(`[loraInfoCache] unreadable ${civitaiMissesPath(hostId)}: ${String(e)}`);
|
|
669
|
+
return {};
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
function recordCivitaiMiss(p) {
|
|
673
|
+
const misses = readCivitaiMisses(p.hostId);
|
|
674
|
+
if (p.miss)
|
|
675
|
+
misses[p.sha256] = new Date().toISOString();
|
|
676
|
+
else
|
|
677
|
+
delete misses[p.sha256];
|
|
678
|
+
getComfyStorage().writeText(civitaiMissesPath(p.hostId), JSON.stringify(misses, null, 2));
|
|
679
|
+
}
|
|
680
|
+
function getLoraAddedAt(name, hostId) {
|
|
681
|
+
const info = getLoraInfo(name, hostId);
|
|
682
|
+
return info == null ? null : lmModified(info);
|
|
683
|
+
}
|
|
684
|
+
function getLoraPreviewUrl(name, hostId) {
|
|
685
|
+
const info = getLoraInfo(name, hostId);
|
|
686
|
+
return info == null ? null : lmPreviewUrl(info);
|
|
687
|
+
}
|
|
688
|
+
function loraMirrorEntries(hostId, p = {}) {
|
|
689
|
+
ensureLoaded();
|
|
690
|
+
const sep = p.separator ?? "/";
|
|
691
|
+
const out = [];
|
|
692
|
+
for (const [key, item] of byHost.get(hostId) ?? []) {
|
|
693
|
+
const filePath = lmFilePath(item);
|
|
694
|
+
const base = filePath == null ? null : filePath.split(/[/\\]/).pop() ?? null;
|
|
695
|
+
const file = base ?? lmFileName(item);
|
|
696
|
+
if (file == null)
|
|
697
|
+
continue;
|
|
698
|
+
const folder = lmFolder(item);
|
|
699
|
+
const joined = folder === "" ? file : `${folder}/${file}`;
|
|
700
|
+
out.push({ key, serverName: joined.replaceAll(/[\\/]/g, sep) });
|
|
701
|
+
}
|
|
702
|
+
return out.sort((a, b) => a.serverName.localeCompare(b.serverName));
|
|
703
|
+
}
|
|
704
|
+
function loraSearchNames(name, hostId) {
|
|
705
|
+
const names = [loraBasename(name), name.replaceAll("\\", "/")];
|
|
706
|
+
const info = getLoraInfo(name, hostId);
|
|
707
|
+
const modelName = info == null ? null : lmModelName(info);
|
|
708
|
+
if (modelName != null)
|
|
709
|
+
names.push(modelName);
|
|
710
|
+
return names;
|
|
711
|
+
}
|
|
712
|
+
function loraSearchText(name, hostId) {
|
|
713
|
+
const info = getLoraInfo(name, hostId);
|
|
714
|
+
if (info == null)
|
|
715
|
+
return [];
|
|
716
|
+
const text = [...lmTags(info), ...lmTrainedWords(info)];
|
|
717
|
+
const baseModel = lmBaseModel(info);
|
|
718
|
+
if (baseModel != null)
|
|
719
|
+
text.push(baseModel);
|
|
720
|
+
return text;
|
|
721
|
+
}
|
|
722
|
+
function loraMatchesFilter(name, filter, hostId) {
|
|
723
|
+
const tokens = filter.toLowerCase().split(/\s+/).filter((t) => t !== "");
|
|
724
|
+
if (tokens.length === 0)
|
|
725
|
+
return true;
|
|
726
|
+
const fields = [...loraSearchNames(name, hostId), ...loraSearchText(name, hostId)].map((f) => f.toLowerCase());
|
|
727
|
+
return tokens.every((token) => fields.some((field) => field.includes(token)));
|
|
728
|
+
}
|
|
729
|
+
function lorasMissingFromMirror(hostLoras, inMirror) {
|
|
730
|
+
return hostLoras.filter((n) => !inMirror(n));
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// src/vars/loraKeywords.ts
|
|
734
|
+
var keywords = observable.map();
|
|
735
|
+
var loaded = false;
|
|
736
|
+
function filePath() {
|
|
737
|
+
return join2(comfyts.baseFolder, "lora-keywords.json");
|
|
738
|
+
}
|
|
739
|
+
function loadOnce() {
|
|
740
|
+
if (loaded)
|
|
741
|
+
return;
|
|
742
|
+
loaded = true;
|
|
743
|
+
const path = filePath();
|
|
744
|
+
const text = getComfyStorage().readTextIfExists(path);
|
|
745
|
+
if (text == null)
|
|
746
|
+
return;
|
|
747
|
+
try {
|
|
748
|
+
const raw = JSON.parse(text);
|
|
749
|
+
if (raw == null || typeof raw !== "object")
|
|
750
|
+
return;
|
|
751
|
+
runInAction(() => {
|
|
752
|
+
for (const [name, kw] of Object.entries(raw))
|
|
753
|
+
if (typeof kw === "string")
|
|
754
|
+
keywords.set(name, kw);
|
|
755
|
+
});
|
|
756
|
+
} catch (e) {
|
|
757
|
+
logError(`[loraKeywords] unreadable ${path}: ${String(e)}`);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
function getLoraKeyword(name, hostId) {
|
|
761
|
+
loadOnce();
|
|
762
|
+
const hand = keywords.get(name);
|
|
763
|
+
if (hand != null)
|
|
764
|
+
return hand;
|
|
765
|
+
return getLoraTriggerWords(name, hostId).join(", ");
|
|
766
|
+
}
|
|
767
|
+
function isLoraKeywordFromMirror(name, hostId) {
|
|
768
|
+
loadOnce();
|
|
769
|
+
return !keywords.has(name) && getLoraTriggerWords(name, hostId).length > 0;
|
|
770
|
+
}
|
|
771
|
+
function loraKeywordFromMirror(name, hostId) {
|
|
772
|
+
return getLoraTriggerWords(name, hostId).join(", ");
|
|
773
|
+
}
|
|
774
|
+
function clearLoraKeywordOverride(name) {
|
|
775
|
+
loadOnce();
|
|
776
|
+
if (!keywords.has(name))
|
|
777
|
+
return;
|
|
778
|
+
runInAction(() => void keywords.delete(name));
|
|
779
|
+
writeKeywords();
|
|
780
|
+
}
|
|
781
|
+
function setLoraKeyword(name, keyword, hostId) {
|
|
782
|
+
loadOnce();
|
|
783
|
+
const trimmed = keyword.trim();
|
|
784
|
+
runInAction(() => {
|
|
785
|
+
if (trimmed === "" && getLoraTriggerWords(name, hostId).length === 0)
|
|
786
|
+
keywords.delete(name);
|
|
787
|
+
else
|
|
788
|
+
keywords.set(name, trimmed);
|
|
789
|
+
});
|
|
790
|
+
writeKeywords();
|
|
791
|
+
}
|
|
792
|
+
function writeKeywords() {
|
|
793
|
+
const path = filePath();
|
|
794
|
+
try {
|
|
795
|
+
getComfyStorage().writeText(path, JSON.stringify(Object.fromEntries([...keywords.entries()].sort()), null, 2));
|
|
796
|
+
} catch (e) {
|
|
797
|
+
logError(`[loraKeywords] write failed ${path}: ${String(e)}`);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
// src/vars/loraEntry.ts
|
|
802
|
+
function isLoraEntry(s) {
|
|
803
|
+
if (typeof s !== "object" || s == null || Array.isArray(s))
|
|
804
|
+
return false;
|
|
805
|
+
const o = s;
|
|
806
|
+
const st = o.strength;
|
|
807
|
+
return Array.isArray(st) && st.length === 2 && typeof st[0] === "number" && Number.isFinite(st[0]) && typeof st[1] === "number" && Number.isFinite(st[1]) && (o.off == null || typeof o.off === "boolean") && (o.mute == null || Array.isArray(o.mute) && o.mute.every((w) => typeof w === "string"));
|
|
808
|
+
}
|
|
809
|
+
function isLoraStrength(s) {
|
|
810
|
+
if (typeof s === "boolean")
|
|
811
|
+
return true;
|
|
812
|
+
if (typeof s === "number")
|
|
813
|
+
return Number.isFinite(s);
|
|
814
|
+
if (Array.isArray(s))
|
|
815
|
+
return s.length === 2 && s.every((n) => typeof n === "number" && Number.isFinite(n));
|
|
816
|
+
return isLoraEntry(s);
|
|
817
|
+
}
|
|
818
|
+
function loraIsOn(s) {
|
|
819
|
+
if (s == null || s === false)
|
|
820
|
+
return false;
|
|
821
|
+
if (isLoraEntry(s))
|
|
822
|
+
return s.off !== true;
|
|
823
|
+
return true;
|
|
824
|
+
}
|
|
825
|
+
function loraStrengths(s) {
|
|
826
|
+
if (typeof s === "number" && Number.isFinite(s))
|
|
827
|
+
return [s, s];
|
|
828
|
+
if (Array.isArray(s) && typeof s[0] === "number" && typeof s[1] === "number")
|
|
829
|
+
return [s[0], s[1]];
|
|
830
|
+
if (isLoraEntry(s))
|
|
831
|
+
return [s.strength[0], s.strength[1]];
|
|
832
|
+
return [1, 1];
|
|
833
|
+
}
|
|
834
|
+
function loraMuted(s) {
|
|
835
|
+
return isLoraEntry(s) && s.mute != null ? s.mute : [];
|
|
836
|
+
}
|
|
837
|
+
function keywordParts(keyword) {
|
|
838
|
+
return [
|
|
839
|
+
...new Set(keyword.split(",").map((w) => w.trim()).filter((w) => w !== ""))
|
|
840
|
+
];
|
|
841
|
+
}
|
|
842
|
+
function keptKeyword(keyword, muted) {
|
|
843
|
+
return keywordParts(keyword).filter((w) => !muted.includes(w)).join(", ");
|
|
844
|
+
}
|
|
845
|
+
function withLora(s, patch) {
|
|
846
|
+
const strength = patch.strength ?? loraStrengths(s);
|
|
847
|
+
const off = patch.on == null ? !loraIsOn(s) : !patch.on;
|
|
848
|
+
const mute = [...patch.mute ?? loraMuted(s)];
|
|
849
|
+
if (!off && mute.length === 0)
|
|
850
|
+
return [strength[0], strength[1]];
|
|
851
|
+
return {
|
|
852
|
+
strength: [strength[0], strength[1]],
|
|
853
|
+
...off ? { off: true } : {},
|
|
854
|
+
...mute.length === 0 ? {} : { mute }
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// src/vars/lanes.ts
|
|
859
|
+
var FIRST_LANE = "main";
|
|
860
|
+
function isObject(v) {
|
|
861
|
+
return typeof v === "object" && v != null && !Array.isArray(v);
|
|
862
|
+
}
|
|
863
|
+
function isPromptLane(v) {
|
|
864
|
+
return isObject(v) && typeof v.name === "string" && typeof v.prompt === "string" && typeof v.active === "boolean";
|
|
865
|
+
}
|
|
866
|
+
function isPromptLanes(v) {
|
|
867
|
+
return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isPromptLane);
|
|
868
|
+
}
|
|
869
|
+
function isPromptInput(v) {
|
|
870
|
+
return typeof v === "string" || isPromptLanes(v);
|
|
871
|
+
}
|
|
872
|
+
function promptText(v) {
|
|
873
|
+
if (typeof v === "string")
|
|
874
|
+
return v;
|
|
875
|
+
return v.lanes.filter((l) => l.active).map((l) => l.prompt).join(`
|
|
876
|
+
`);
|
|
877
|
+
}
|
|
878
|
+
var HEADER = /^# (.+?)( \(off\))?$/;
|
|
879
|
+
function promptLanesToText(v) {
|
|
880
|
+
return v.lanes.map((l) => `# ${l.name}${l.active ? "" : " (off)"}
|
|
881
|
+
${l.prompt}`).join(`
|
|
882
|
+
`);
|
|
883
|
+
}
|
|
884
|
+
function promptLanesFromText(text) {
|
|
885
|
+
const lanes = [];
|
|
886
|
+
let current = null;
|
|
887
|
+
const body = [];
|
|
888
|
+
const close = () => {
|
|
889
|
+
if (current != null)
|
|
890
|
+
lanes.push({ ...current, prompt: body.join(`
|
|
891
|
+
`) });
|
|
892
|
+
else if (body.some((l) => l.trim() !== ""))
|
|
893
|
+
lanes.push({ name: FIRST_LANE, prompt: body.join(`
|
|
894
|
+
`), active: true });
|
|
895
|
+
body.length = 0;
|
|
896
|
+
};
|
|
897
|
+
for (const line of text.split(`
|
|
898
|
+
`)) {
|
|
899
|
+
const m = HEADER.exec(line);
|
|
900
|
+
if (m == null) {
|
|
901
|
+
body.push(line);
|
|
902
|
+
continue;
|
|
903
|
+
}
|
|
904
|
+
close();
|
|
905
|
+
current = { name: (m[1] ?? "").trim(), prompt: "", active: m[2] == null };
|
|
906
|
+
}
|
|
907
|
+
close();
|
|
908
|
+
return { lanes: lanes.length > 0 ? lanes : [{ name: FIRST_LANE, prompt: "", active: true }] };
|
|
909
|
+
}
|
|
910
|
+
function isLoraRecord(v) {
|
|
911
|
+
return isObject(v) && !("lanes" in v) && Object.values(v).every((s) => s == null || isLoraStrength(s));
|
|
912
|
+
}
|
|
913
|
+
function isLoraLane(v) {
|
|
914
|
+
return isObject(v) && typeof v.name === "string" && typeof v.active === "boolean" && isLoraRecord(v.loras);
|
|
915
|
+
}
|
|
916
|
+
function isLoraLanes(v) {
|
|
917
|
+
return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isLoraLane);
|
|
918
|
+
}
|
|
919
|
+
function isLorasInput(v) {
|
|
920
|
+
return isLoraRecord(v) || isLoraLanes(v);
|
|
921
|
+
}
|
|
922
|
+
function flattenLoras(v) {
|
|
923
|
+
if (!isLoraLanes(v))
|
|
924
|
+
return { record: v, duplicates: [] };
|
|
925
|
+
const record = {};
|
|
926
|
+
const duplicates = [];
|
|
927
|
+
for (const lane of v.lanes) {
|
|
928
|
+
if (!lane.active)
|
|
929
|
+
continue;
|
|
930
|
+
for (const [name, st] of Object.entries(lane.loras)) {
|
|
931
|
+
if (st == null)
|
|
932
|
+
continue;
|
|
933
|
+
if (name in record)
|
|
934
|
+
duplicates.push(name);
|
|
935
|
+
else
|
|
936
|
+
record[name] = st;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
return { record, duplicates };
|
|
940
|
+
}
|
|
941
|
+
function laneIndexOf(v, name) {
|
|
942
|
+
const active = v.lanes.findIndex((l) => l.active && l.loras[name] != null);
|
|
943
|
+
return active !== -1 ? active : v.lanes.findIndex((l) => l.loras[name] != null);
|
|
944
|
+
}
|
|
945
|
+
function updateLora(v, name, next) {
|
|
946
|
+
const write = (rec) => {
|
|
947
|
+
const out = { ...rec };
|
|
948
|
+
if (next == null)
|
|
949
|
+
delete out[name];
|
|
950
|
+
else
|
|
951
|
+
out[name] = next;
|
|
952
|
+
return out;
|
|
953
|
+
};
|
|
954
|
+
if (!isLoraLanes(v))
|
|
955
|
+
return write(v);
|
|
956
|
+
if (v.lanes.length === 0)
|
|
957
|
+
return { lanes: [{ name: FIRST_LANE, active: true, loras: write({}) }] };
|
|
958
|
+
const found = laneIndexOf(v, name);
|
|
959
|
+
const ix = found === -1 ? 0 : found;
|
|
960
|
+
return { lanes: v.lanes.map((l, i) => i === ix ? { ...l, loras: write(l.loras) } : l) };
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
// src/vars/promptSyntax.ts
|
|
964
|
+
var COMMENT_LINE_RE = /^\s*\/\//;
|
|
965
|
+
var NEGATIVE_LINE_RE = /^\s*- (.*)$/;
|
|
966
|
+
var NEGATIVE_PREFIX_RE = /^(\s*)- /;
|
|
967
|
+
function commentStart(line) {
|
|
968
|
+
const m = /(?:^|\s)\/\//.exec(line);
|
|
969
|
+
if (m == null)
|
|
970
|
+
return -1;
|
|
971
|
+
return m.index + m[0].length - 2;
|
|
972
|
+
}
|
|
973
|
+
function withoutComment(line) {
|
|
974
|
+
const c = commentStart(line);
|
|
975
|
+
return c < 0 ? { text: line, hadComment: false } : { text: line.slice(0, c).trimEnd(), hadComment: true };
|
|
976
|
+
}
|
|
977
|
+
function parsePromptText(text) {
|
|
978
|
+
const pos = [];
|
|
979
|
+
const neg = [];
|
|
980
|
+
for (const raw of text.split(`
|
|
981
|
+
`)) {
|
|
982
|
+
const cut = withoutComment(raw);
|
|
983
|
+
if (cut.hadComment && cut.text.trim() === "")
|
|
984
|
+
continue;
|
|
985
|
+
const m = NEGATIVE_PREFIX_RE.exec(raw);
|
|
986
|
+
if (m != null && m[0].length <= cut.text.length + 1) {
|
|
987
|
+
const body = cut.text.slice(m[0].length).trim();
|
|
988
|
+
if (body !== "")
|
|
989
|
+
neg.push(body);
|
|
990
|
+
} else
|
|
991
|
+
pos.push(cut.text);
|
|
992
|
+
}
|
|
993
|
+
return { positive: pos.join(`
|
|
994
|
+
`).trim(), negative: neg.join(", ") };
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
// src/vars/presets.ts
|
|
998
|
+
function toPresetList(spec) {
|
|
999
|
+
if (spec == null)
|
|
1000
|
+
return [];
|
|
1001
|
+
return Object.entries(spec).map(([label, text]) => ({ label, text }));
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
// src/vars/ComfyVars.ts
|
|
1005
|
+
class ComfyVarBase {
|
|
1006
|
+
defaultValue;
|
|
1007
|
+
label;
|
|
1008
|
+
name;
|
|
1009
|
+
uiOpts = {};
|
|
1010
|
+
value;
|
|
1011
|
+
constructor(defaultValue, label) {
|
|
1012
|
+
this.defaultValue = defaultValue;
|
|
1013
|
+
this.label = label;
|
|
1014
|
+
this.value = defaultValue;
|
|
1015
|
+
makeObservable(this, { value: observable2, set: action, reset: action, parse: action, loadJSON: action });
|
|
1016
|
+
}
|
|
1017
|
+
set(value) {
|
|
1018
|
+
this.value = value;
|
|
1019
|
+
return this;
|
|
1020
|
+
}
|
|
1021
|
+
ui(p) {
|
|
1022
|
+
this.uiOpts = { ...this.uiOpts, ...p };
|
|
1023
|
+
return this;
|
|
1024
|
+
}
|
|
1025
|
+
toJSON() {
|
|
1026
|
+
return this.value;
|
|
1027
|
+
}
|
|
1028
|
+
loadJSON(value) {
|
|
1029
|
+
return this.set(value);
|
|
1030
|
+
}
|
|
1031
|
+
reset() {
|
|
1032
|
+
this.value = this.defaultValue;
|
|
1033
|
+
return this;
|
|
1034
|
+
}
|
|
1035
|
+
display() {
|
|
1036
|
+
return String(this.value);
|
|
1037
|
+
}
|
|
1038
|
+
toEditBuffer() {
|
|
1039
|
+
return String(this.value);
|
|
1040
|
+
}
|
|
1041
|
+
afterRun() {}
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
class ComfyVar extends ComfyVarBase {
|
|
1045
|
+
outValue() {
|
|
1046
|
+
return this.value;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
class TextVar extends ComfyVar {
|
|
1051
|
+
kind = "text";
|
|
1052
|
+
presets;
|
|
1053
|
+
opts;
|
|
1054
|
+
constructor(defaultValue, opts = {}) {
|
|
1055
|
+
const o = typeof opts === "string" ? { label: opts } : opts;
|
|
1056
|
+
super(defaultValue, o.label);
|
|
1057
|
+
this.opts = o;
|
|
1058
|
+
this.presets = toPresetList(o.presets);
|
|
1059
|
+
}
|
|
1060
|
+
parse(raw) {
|
|
1061
|
+
this.set(raw);
|
|
1062
|
+
return true;
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
class PromptVar extends ComfyVarBase {
|
|
1067
|
+
promptOpts;
|
|
1068
|
+
kind = "prompt";
|
|
1069
|
+
presets;
|
|
1070
|
+
constructor(defaultValue, promptOpts = {}) {
|
|
1071
|
+
super(defaultValue, promptOpts.label);
|
|
1072
|
+
this.promptOpts = promptOpts;
|
|
1073
|
+
this.presets = toPresetList(promptOpts.presets);
|
|
1074
|
+
}
|
|
1075
|
+
parse(raw) {
|
|
1076
|
+
this.set(isPromptLanes(this.value) ? promptLanesFromText(raw) : raw);
|
|
1077
|
+
return true;
|
|
1078
|
+
}
|
|
1079
|
+
toEditBuffer() {
|
|
1080
|
+
return isPromptLanes(this.value) ? promptLanesToText(this.value) : this.value;
|
|
1081
|
+
}
|
|
1082
|
+
display() {
|
|
1083
|
+
if (!isPromptLanes(this.value))
|
|
1084
|
+
return super.display();
|
|
1085
|
+
return `${this.value.lanes.length} lanes: ${this.value.lanes.map((l) => l.active ? l.name : `(${l.name})`).join(", ")}`;
|
|
1086
|
+
}
|
|
1087
|
+
get text() {
|
|
1088
|
+
return promptText(this.value);
|
|
1089
|
+
}
|
|
1090
|
+
get tags() {
|
|
1091
|
+
const t = this.promptOpts.tags;
|
|
1092
|
+
if (t == null)
|
|
1093
|
+
return null;
|
|
1094
|
+
return typeof t === "string" ? { url: t } : t;
|
|
1095
|
+
}
|
|
1096
|
+
static isCommentLine(line) {
|
|
1097
|
+
return COMMENT_LINE_RE.test(line);
|
|
1098
|
+
}
|
|
1099
|
+
static isNegativeLine(line) {
|
|
1100
|
+
return NEGATIVE_LINE_RE.test(line);
|
|
1101
|
+
}
|
|
1102
|
+
injectedKeywords() {
|
|
1103
|
+
const src = this.promptOpts.loraKeywordsFrom;
|
|
1104
|
+
if (src == null)
|
|
1105
|
+
return [];
|
|
1106
|
+
return [
|
|
1107
|
+
...new Set(src.activeNames().map((name) => keptKeyword(getLoraKeyword(name, src.hostId), src.mutedWords?.(name) ?? [])).filter((k) => k !== ""))
|
|
1108
|
+
];
|
|
1109
|
+
}
|
|
1110
|
+
outValue() {
|
|
1111
|
+
const parsed = parsePromptText(this.text);
|
|
1112
|
+
const body = parsed.positive;
|
|
1113
|
+
const keywords = this.injectedKeywords();
|
|
1114
|
+
const positive = keywords.length === 0 ? body : body === "" ? keywords.join(", ") : `${keywords.join(", ")}, ${body}`;
|
|
1115
|
+
return { positive, negative: parsed.negative };
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
class IntVar extends ComfyVar {
|
|
1120
|
+
opts;
|
|
1121
|
+
kind = "int";
|
|
1122
|
+
constructor(defaultValue, opts = {}) {
|
|
1123
|
+
super(defaultValue, opts.label);
|
|
1124
|
+
this.opts = opts;
|
|
1125
|
+
}
|
|
1126
|
+
set(value) {
|
|
1127
|
+
const clamped = Math.round(Math.min(this.opts.max ?? Infinity, Math.max(this.opts.min ?? -Infinity, value)));
|
|
1128
|
+
return super.set(clamped);
|
|
1129
|
+
}
|
|
1130
|
+
parse(raw) {
|
|
1131
|
+
const n = Number(raw);
|
|
1132
|
+
if (Number.isNaN(n))
|
|
1133
|
+
return false;
|
|
1134
|
+
this.set(n);
|
|
1135
|
+
return true;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
class FloatVar extends ComfyVar {
|
|
1140
|
+
opts;
|
|
1141
|
+
kind = "float";
|
|
1142
|
+
constructor(defaultValue, opts = {}) {
|
|
1143
|
+
super(defaultValue, opts.label);
|
|
1144
|
+
this.opts = opts;
|
|
1145
|
+
}
|
|
1146
|
+
set(value) {
|
|
1147
|
+
return super.set(Math.min(this.opts.max ?? Infinity, Math.max(this.opts.min ?? -Infinity, value)));
|
|
1148
|
+
}
|
|
1149
|
+
parse(raw) {
|
|
1150
|
+
const n = Number(raw);
|
|
1151
|
+
if (Number.isNaN(n))
|
|
1152
|
+
return false;
|
|
1153
|
+
this.set(n);
|
|
1154
|
+
return true;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
class SeedVar extends ComfyVar {
|
|
1159
|
+
kind = "seed";
|
|
1160
|
+
mode;
|
|
1161
|
+
defaultMode;
|
|
1162
|
+
constructor(defaultValue = 0, opts = {}) {
|
|
1163
|
+
const o = typeof opts === "string" ? { label: opts } : opts;
|
|
1164
|
+
super(defaultValue, o.label);
|
|
1165
|
+
this.mode = o.mode ?? "=";
|
|
1166
|
+
this.defaultMode = this.mode;
|
|
1167
|
+
makeObservable(this, { mode: observable2, setMode: action, randomize: action, advance: action });
|
|
1168
|
+
}
|
|
1169
|
+
setMode(mode) {
|
|
1170
|
+
this.mode = mode;
|
|
1171
|
+
return this;
|
|
1172
|
+
}
|
|
1173
|
+
randomize() {
|
|
1174
|
+
return this.set(Math.floor(Math.random() * 2 ** 32));
|
|
1175
|
+
}
|
|
1176
|
+
set(value) {
|
|
1177
|
+
return super.set(Math.max(0, Math.floor(value)));
|
|
1178
|
+
}
|
|
1179
|
+
advance() {
|
|
1180
|
+
if (this.mode === "+")
|
|
1181
|
+
return this.set(this.value + 1);
|
|
1182
|
+
if (this.mode === "-")
|
|
1183
|
+
return this.set(this.value - 1);
|
|
1184
|
+
if (this.mode === "?")
|
|
1185
|
+
return this.randomize();
|
|
1186
|
+
return this;
|
|
1187
|
+
}
|
|
1188
|
+
afterRun() {
|
|
1189
|
+
this.advance();
|
|
1190
|
+
}
|
|
1191
|
+
reset() {
|
|
1192
|
+
this.setMode(this.defaultMode);
|
|
1193
|
+
return super.reset();
|
|
1194
|
+
}
|
|
1195
|
+
parse(raw) {
|
|
1196
|
+
const m = raw.trim().match(/^([+\-=?])?\s*(\d+)?$/);
|
|
1197
|
+
if (m == null)
|
|
1198
|
+
return false;
|
|
1199
|
+
const modeChar = m[1];
|
|
1200
|
+
const numStr = m[2];
|
|
1201
|
+
if (modeChar == null && numStr == null)
|
|
1202
|
+
return false;
|
|
1203
|
+
this.setMode(modeChar == null ? "=" : modeChar);
|
|
1204
|
+
if (numStr != null)
|
|
1205
|
+
this.set(Number(numStr));
|
|
1206
|
+
return true;
|
|
1207
|
+
}
|
|
1208
|
+
display() {
|
|
1209
|
+
return `${this.mode} ${this.value}`;
|
|
1210
|
+
}
|
|
1211
|
+
toEditBuffer() {
|
|
1212
|
+
return `${this.mode} ${this.value}`;
|
|
1213
|
+
}
|
|
1214
|
+
toJSON() {
|
|
1215
|
+
return { mode: this.mode, value: this.value };
|
|
1216
|
+
}
|
|
1217
|
+
loadJSON(value) {
|
|
1218
|
+
if (typeof value === "number")
|
|
1219
|
+
return this.set(value);
|
|
1220
|
+
if (value != null && typeof value === "object") {
|
|
1221
|
+
const o = value;
|
|
1222
|
+
if (o.mode === "=" || o.mode === "+" || o.mode === "-" || o.mode === "?")
|
|
1223
|
+
this.setMode(o.mode);
|
|
1224
|
+
if (typeof o.value === "number")
|
|
1225
|
+
this.set(o.value);
|
|
1226
|
+
}
|
|
1227
|
+
return this;
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
class ToggleVar extends ComfyVar {
|
|
1232
|
+
kind = "toggle";
|
|
1233
|
+
toggle() {
|
|
1234
|
+
return this.set(!this.value);
|
|
1235
|
+
}
|
|
1236
|
+
parse(raw) {
|
|
1237
|
+
if (raw !== "true" && raw !== "false")
|
|
1238
|
+
return false;
|
|
1239
|
+
this.set(raw === "true");
|
|
1240
|
+
return true;
|
|
1241
|
+
}
|
|
1242
|
+
display() {
|
|
1243
|
+
return this.value ? "ON" : "OFF";
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
class ChoiceList {
|
|
1248
|
+
source;
|
|
1249
|
+
resolved = null;
|
|
1250
|
+
constructor(source) {
|
|
1251
|
+
this.source = source;
|
|
1252
|
+
}
|
|
1253
|
+
get slot() {
|
|
1254
|
+
return isChoiceList(this.source) ? null : this.source;
|
|
1255
|
+
}
|
|
1256
|
+
get choices() {
|
|
1257
|
+
if (isChoiceList(this.source))
|
|
1258
|
+
return this.source;
|
|
1259
|
+
if (this.resolved == null)
|
|
1260
|
+
throw new Error(`v.model('${this.source.slot}') is host-bound — it only works inside defineWorkflow({ vars }) (pass a name list to v.choice otherwise)`);
|
|
1261
|
+
return this.resolved;
|
|
1262
|
+
}
|
|
1263
|
+
bind(host) {
|
|
1264
|
+
const src = this.slot;
|
|
1265
|
+
if (src == null)
|
|
1266
|
+
return;
|
|
1267
|
+
const all = host.schema.stringValues(src.slot);
|
|
1268
|
+
const filter = src.filter == null ? null : statelessRegex(src.filter);
|
|
1269
|
+
this.resolved = filter == null ? all : all.filter((n) => filter.test(n));
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
class ChoiceVar extends ComfyVar {
|
|
1274
|
+
kind = "choice";
|
|
1275
|
+
select = "one";
|
|
1276
|
+
list;
|
|
1277
|
+
constructor(choices, defaultValue, label) {
|
|
1278
|
+
super(defaultValue, label);
|
|
1279
|
+
this.list = new ChoiceList(choices);
|
|
1280
|
+
}
|
|
1281
|
+
get choices() {
|
|
1282
|
+
return this.list.choices;
|
|
1283
|
+
}
|
|
1284
|
+
get hostSlot() {
|
|
1285
|
+
return this.list.slot;
|
|
1286
|
+
}
|
|
1287
|
+
bindHost(host) {
|
|
1288
|
+
this.list.bind(host);
|
|
1289
|
+
}
|
|
1290
|
+
next(delta = 1) {
|
|
1291
|
+
const ix = this.choices.indexOf(this.value);
|
|
1292
|
+
const nextIx = (ix + delta + this.choices.length) % this.choices.length;
|
|
1293
|
+
return this.set(this.choices[nextIx] ?? this.value);
|
|
1294
|
+
}
|
|
1295
|
+
parse(raw) {
|
|
1296
|
+
const hit = this.choices.find((c) => c === raw);
|
|
1297
|
+
if (hit == null)
|
|
1298
|
+
return false;
|
|
1299
|
+
this.set(hit);
|
|
1300
|
+
return true;
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
class OptionalChoiceVar extends ComfyVar {
|
|
1305
|
+
kind = "choice";
|
|
1306
|
+
select = "zero-or-one";
|
|
1307
|
+
list;
|
|
1308
|
+
constructor(choices, defaultValue, label) {
|
|
1309
|
+
super(defaultValue, label);
|
|
1310
|
+
this.list = new ChoiceList(choices);
|
|
1311
|
+
}
|
|
1312
|
+
get choices() {
|
|
1313
|
+
return this.list.choices;
|
|
1314
|
+
}
|
|
1315
|
+
get hostSlot() {
|
|
1316
|
+
return this.list.slot;
|
|
1317
|
+
}
|
|
1318
|
+
bindHost(host) {
|
|
1319
|
+
this.list.bind(host);
|
|
1320
|
+
}
|
|
1321
|
+
toggle(c) {
|
|
1322
|
+
return this.set(this.value === c ? null : c);
|
|
1323
|
+
}
|
|
1324
|
+
parse(raw) {
|
|
1325
|
+
if (raw.trim() === "") {
|
|
1326
|
+
this.set(null);
|
|
1327
|
+
return true;
|
|
1328
|
+
}
|
|
1329
|
+
const hit = this.choices.find((c) => c === raw.trim());
|
|
1330
|
+
if (hit == null)
|
|
1331
|
+
return false;
|
|
1332
|
+
this.set(hit);
|
|
1333
|
+
return true;
|
|
1334
|
+
}
|
|
1335
|
+
toEditBuffer() {
|
|
1336
|
+
return this.value ?? "";
|
|
1337
|
+
}
|
|
1338
|
+
loadJSON(value) {
|
|
1339
|
+
const one = Array.isArray(value) ? value[0] : value;
|
|
1340
|
+
return this.set(this.choices.find((c) => c === one) ?? null);
|
|
1341
|
+
}
|
|
1342
|
+
display() {
|
|
1343
|
+
return this.value ?? "none";
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
class MultiChoiceVar extends ComfyVar {
|
|
1348
|
+
choices;
|
|
1349
|
+
kind = "choice";
|
|
1350
|
+
select = "many";
|
|
1351
|
+
constructor(choices, defaultValue, label) {
|
|
1352
|
+
super([...defaultValue], label);
|
|
1353
|
+
this.choices = choices;
|
|
1354
|
+
}
|
|
1355
|
+
toggle(c) {
|
|
1356
|
+
const on = this.value.includes(c);
|
|
1357
|
+
return this.set(this.choices.filter((x) => x === c ? !on : this.value.includes(x)));
|
|
1358
|
+
}
|
|
1359
|
+
parse(raw) {
|
|
1360
|
+
const wanted = raw.split(",").map((w) => w.trim()).filter((w) => w !== "");
|
|
1361
|
+
const picked = this.choices.filter((c) => wanted.includes(c));
|
|
1362
|
+
if (picked.length !== new Set(wanted).size)
|
|
1363
|
+
return false;
|
|
1364
|
+
this.set(picked);
|
|
1365
|
+
return true;
|
|
1366
|
+
}
|
|
1367
|
+
toEditBuffer() {
|
|
1368
|
+
return this.value.join(", ");
|
|
1369
|
+
}
|
|
1370
|
+
loadJSON(value) {
|
|
1371
|
+
const listed = Array.isArray(value) ? value : value == null ? [] : [value];
|
|
1372
|
+
return this.set(this.choices.filter((c) => listed.includes(c)));
|
|
1373
|
+
}
|
|
1374
|
+
display() {
|
|
1375
|
+
return this.value.length === 0 ? "none" : this.value.join(", ");
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
function isChoiceList(v) {
|
|
1379
|
+
return Array.isArray(v);
|
|
1380
|
+
}
|
|
1381
|
+
function choice(choices, defaultValue, opts) {
|
|
1382
|
+
const o = typeof opts === "string" ? { label: opts } : opts ?? {};
|
|
1383
|
+
const select = o.select ?? "one";
|
|
1384
|
+
if (select === "many") {
|
|
1385
|
+
if (!isChoiceList(defaultValue))
|
|
1386
|
+
throw new Error(`a 'many' choice takes a list as its default, got ${String(defaultValue)}`);
|
|
1387
|
+
return new MultiChoiceVar(choices, defaultValue, o.label);
|
|
1388
|
+
}
|
|
1389
|
+
if (isChoiceList(defaultValue))
|
|
1390
|
+
throw new Error(`a '${select}' choice takes one value as its default, not a list`);
|
|
1391
|
+
if (select === "zero-or-one")
|
|
1392
|
+
return new OptionalChoiceVar(choices, defaultValue, o.label);
|
|
1393
|
+
if (defaultValue == null)
|
|
1394
|
+
throw new Error("a 'one' choice needs a default: use { select: 'zero-or-one' } for none");
|
|
1395
|
+
return new ChoiceVar(choices, defaultValue, o.label);
|
|
1396
|
+
}
|
|
1397
|
+
function model(slot, opts) {
|
|
1398
|
+
const source = { slot, filter: opts.filter };
|
|
1399
|
+
if (opts.default == null)
|
|
1400
|
+
return new OptionalChoiceVar(source, null, opts.label);
|
|
1401
|
+
return new ChoiceVar(source, opts.default, opts.label);
|
|
1402
|
+
}
|
|
1403
|
+
class LorasVar extends ComfyVarBase {
|
|
1404
|
+
optionsSource;
|
|
1405
|
+
kind = "loras";
|
|
1406
|
+
prev = {};
|
|
1407
|
+
resolvedOptions = null;
|
|
1408
|
+
hostId = undefined;
|
|
1409
|
+
constructor(optionsSource, initial = {}, label) {
|
|
1410
|
+
super(initial, label);
|
|
1411
|
+
this.optionsSource = optionsSource;
|
|
1412
|
+
}
|
|
1413
|
+
get optionsFilter() {
|
|
1414
|
+
return this.optionsSource instanceof RegExp ? this.optionsSource : null;
|
|
1415
|
+
}
|
|
1416
|
+
get options() {
|
|
1417
|
+
if (!(this.optionsSource instanceof RegExp))
|
|
1418
|
+
return this.optionsSource;
|
|
1419
|
+
if (this.resolvedOptions == null)
|
|
1420
|
+
throw new Error(`v.loras(${String(this.optionsSource)}) is host-bound — it only works inside defineWorkflow({ vars }) (pass a name list otherwise)`);
|
|
1421
|
+
return this.resolvedOptions;
|
|
1422
|
+
}
|
|
1423
|
+
bindHost(host) {
|
|
1424
|
+
this.hostId = host.data?.id;
|
|
1425
|
+
if (!(this.optionsSource instanceof RegExp))
|
|
1426
|
+
return;
|
|
1427
|
+
this.resolvedOptions = host.schema.getLoras(this.optionsSource);
|
|
1428
|
+
}
|
|
1429
|
+
get names() {
|
|
1430
|
+
return [...this.options];
|
|
1431
|
+
}
|
|
1432
|
+
get record() {
|
|
1433
|
+
return flattenLoras(this.value).record;
|
|
1434
|
+
}
|
|
1435
|
+
outValue() {
|
|
1436
|
+
const flat = flattenLoras(this.value);
|
|
1437
|
+
if (flat.duplicates.length > 0)
|
|
1438
|
+
logError(`loras var '${this.name ?? this.label ?? "?"}': ${flat.duplicates.join(", ")} sit in two active lanes, the first lane's setting is used`);
|
|
1439
|
+
return flat.record;
|
|
1440
|
+
}
|
|
1441
|
+
write(name, next) {
|
|
1442
|
+
return this.set(updateLora(this.value, name, next));
|
|
1443
|
+
}
|
|
1444
|
+
mutedWords(name) {
|
|
1445
|
+
return loraMuted(this.record[name]);
|
|
1446
|
+
}
|
|
1447
|
+
activeNames() {
|
|
1448
|
+
return this.names.filter((n) => this.isOn(n));
|
|
1449
|
+
}
|
|
1450
|
+
isOn(name) {
|
|
1451
|
+
return loraIsOn(this.record[name]);
|
|
1452
|
+
}
|
|
1453
|
+
toggleItem(name) {
|
|
1454
|
+
const cur = this.record[name];
|
|
1455
|
+
if (cur == null || cur === false)
|
|
1456
|
+
return this.write(name, this.prev[name] ?? true);
|
|
1457
|
+
if (!loraIsOn(cur))
|
|
1458
|
+
return this.write(name, withLora(cur, { on: true }));
|
|
1459
|
+
this.prev[name] = cur;
|
|
1460
|
+
return this.write(name, false);
|
|
1461
|
+
}
|
|
1462
|
+
adjustItem(name, delta) {
|
|
1463
|
+
const cur = this.record[name];
|
|
1464
|
+
if (!loraIsOn(cur))
|
|
1465
|
+
return this;
|
|
1466
|
+
const step = (n) => Math.max(0, Math.round((n + delta) * 100) / 100);
|
|
1467
|
+
const next = typeof cur === "number" || cur === true ? step(cur === true ? 1 : cur) : Array.isArray(cur) ? [step(cur[0]), step(cur[1])] : withLora(cur, { strength: [step(loraStrengths(cur)[0]), step(loraStrengths(cur)[1])] });
|
|
1468
|
+
return this.write(name, next);
|
|
1469
|
+
}
|
|
1470
|
+
strengthLabel(name) {
|
|
1471
|
+
const s = this.record[name];
|
|
1472
|
+
if (!loraIsOn(s))
|
|
1473
|
+
return "";
|
|
1474
|
+
const [m, c] = loraStrengths(s);
|
|
1475
|
+
return m === c ? m.toFixed(2) : `m:${m.toFixed(2)} c:${c.toFixed(2)}`;
|
|
1476
|
+
}
|
|
1477
|
+
parse(raw) {
|
|
1478
|
+
try {
|
|
1479
|
+
const parsed = JSON.parse(raw);
|
|
1480
|
+
if (!isLorasInput(parsed))
|
|
1481
|
+
return false;
|
|
1482
|
+
this.set(parsed);
|
|
1483
|
+
return true;
|
|
1484
|
+
} catch {
|
|
1485
|
+
return false;
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
static shortName(name) {
|
|
1489
|
+
return (name.split(/[\\/]/).pop() ?? name).replace(/\.safetensors$/, "");
|
|
1490
|
+
}
|
|
1491
|
+
setAll(on, names = this.options) {
|
|
1492
|
+
const record = this.record;
|
|
1493
|
+
let next = this.value;
|
|
1494
|
+
for (const name of names) {
|
|
1495
|
+
const cur = record[name];
|
|
1496
|
+
if (on) {
|
|
1497
|
+
if (cur == null || cur === false)
|
|
1498
|
+
next = updateLora(next, name, this.prev[name] ?? true);
|
|
1499
|
+
else if (!loraIsOn(cur))
|
|
1500
|
+
next = updateLora(next, name, withLora(cur, { on: true }));
|
|
1501
|
+
} else {
|
|
1502
|
+
if (loraIsOn(cur))
|
|
1503
|
+
this.prev[name] = cur;
|
|
1504
|
+
next = updateLora(next, name, false);
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
return this.set(next);
|
|
1508
|
+
}
|
|
1509
|
+
display() {
|
|
1510
|
+
const on = this.activeNames();
|
|
1511
|
+
if (on.length === 0)
|
|
1512
|
+
return `(0/${this.options.length}) none`;
|
|
1513
|
+
return `(${on.length}/${this.options.length}) ${on.map((n) => LorasVar.shortName(n)).join(", ")}`;
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
var DEFAULT_SIZE_PRESETS = [
|
|
1517
|
+
{ label: "1:1 square", width: 1024, height: 1024 },
|
|
1518
|
+
{ label: "4:3 landscape", width: 1152, height: 896 },
|
|
1519
|
+
{ label: "3:4 portrait", width: 896, height: 1152 },
|
|
1520
|
+
{ label: "3:2 landscape", width: 1216, height: 832 },
|
|
1521
|
+
{ label: "2:3 portrait", width: 832, height: 1216 },
|
|
1522
|
+
{ label: "16:9 widescreen", width: 1344, height: 768 },
|
|
1523
|
+
{ label: "9:16 tall", width: 768, height: 1344 }
|
|
1524
|
+
];
|
|
1525
|
+
var SD15_SIZE_PRESETS = [
|
|
1526
|
+
{ label: "1:1 square", width: 512, height: 512 },
|
|
1527
|
+
{ label: "4:3 landscape", width: 576, height: 448 },
|
|
1528
|
+
{ label: "3:4 portrait", width: 448, height: 576 },
|
|
1529
|
+
{ label: "3:2 landscape", width: 576, height: 384 },
|
|
1530
|
+
{ label: "2:3 portrait", width: 384, height: 576 },
|
|
1531
|
+
{ label: "16:9 widescreen", width: 704, height: 384 },
|
|
1532
|
+
{ label: "9:16 tall", width: 384, height: 704 }
|
|
1533
|
+
];
|
|
1534
|
+
var DEFAULT_STARRED_SIZES = ["1:1 square", "3:4 portrait", "4:3 landscape"];
|
|
1535
|
+
function sizePresetsFor(defaultValue) {
|
|
1536
|
+
if (defaultValue == null)
|
|
1537
|
+
return DEFAULT_SIZE_PRESETS;
|
|
1538
|
+
return defaultValue.width * defaultValue.height <= 600 * 600 ? SD15_SIZE_PRESETS : DEFAULT_SIZE_PRESETS;
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
class SizeVar extends ComfyVar {
|
|
1542
|
+
presets;
|
|
1543
|
+
imageVar;
|
|
1544
|
+
starred;
|
|
1545
|
+
kind = "size";
|
|
1546
|
+
constructor(defaultValue = { width: 1024, height: 1024 }, presets = DEFAULT_SIZE_PRESETS, label, imageVar, starred = DEFAULT_STARRED_SIZES) {
|
|
1547
|
+
super(defaultValue, label);
|
|
1548
|
+
this.presets = presets;
|
|
1549
|
+
this.imageVar = imageVar;
|
|
1550
|
+
this.starred = starred;
|
|
1551
|
+
}
|
|
1552
|
+
imageSize() {
|
|
1553
|
+
const iv = this.imageVar;
|
|
1554
|
+
if (iv == null || iv.value === "")
|
|
1555
|
+
return null;
|
|
1556
|
+
try {
|
|
1557
|
+
const abs = iv.absPath();
|
|
1558
|
+
const meta = imageMeta(getComfyStorage().readBytes(abs));
|
|
1559
|
+
if (meta.width == null || meta.height == null)
|
|
1560
|
+
return null;
|
|
1561
|
+
return { width: meta.width, height: meta.height, name: basename2(abs) };
|
|
1562
|
+
} catch {
|
|
1563
|
+
return null;
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
parse(raw) {
|
|
1567
|
+
const m = raw.trim().match(/^(\d+)\s*[x×]\s*(\d+)$/);
|
|
1568
|
+
if (m != null) {
|
|
1569
|
+
this.set({ width: Number(m[1]), height: Number(m[2]) });
|
|
1570
|
+
return true;
|
|
1571
|
+
}
|
|
1572
|
+
const preset = this.presets.find((p) => p.label === raw.trim());
|
|
1573
|
+
if (preset != null) {
|
|
1574
|
+
this.set({ width: preset.width, height: preset.height });
|
|
1575
|
+
return true;
|
|
1576
|
+
}
|
|
1577
|
+
return false;
|
|
1578
|
+
}
|
|
1579
|
+
display() {
|
|
1580
|
+
const { width, height } = this.value;
|
|
1581
|
+
const hit = this.presets.find((p) => p.width === width && p.height === height);
|
|
1582
|
+
return `${width}×${height}${hit ? ` (${hit.label})` : ""}`;
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
var DEFAULT_IMAGE_EXTENSIONS = DEFAULT_MEDIA_EXTENSIONS.image;
|
|
1586
|
+
var DEFAULT_AUDIO_EXTENSIONS = DEFAULT_MEDIA_EXTENSIONS.audio;
|
|
1587
|
+
var DEFAULT_VIDEO_EXTENSIONS = DEFAULT_MEDIA_EXTENSIONS.video;
|
|
1588
|
+
|
|
1589
|
+
class MediaVarEmptyError extends Error {
|
|
1590
|
+
varName;
|
|
1591
|
+
media;
|
|
1592
|
+
name = "MediaVarEmptyError";
|
|
1593
|
+
constructor(varName, media = "image") {
|
|
1594
|
+
super(`${media} var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/file'))`);
|
|
1595
|
+
this.varName = varName;
|
|
1596
|
+
this.media = media;
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
function expandUserPath(raw) {
|
|
1600
|
+
const trimmed = raw.trim();
|
|
1601
|
+
return trimmed.startsWith("~/") ? join3(getComfyStorage().homedir(), trimmed.slice(2)) : trimmed;
|
|
1602
|
+
}
|
|
1603
|
+
var MEDIA_LOADERS = {
|
|
1604
|
+
image: { node: "LoadImage", input: "image" },
|
|
1605
|
+
audio: { node: "LoadAudio", input: "audio" },
|
|
1606
|
+
video: { node: "LoadVideo", input: "file" }
|
|
1607
|
+
};
|
|
1608
|
+
|
|
1609
|
+
class MediaVar extends ComfyVar {
|
|
1610
|
+
opts;
|
|
1611
|
+
constructor(defaultValue, opts = {}) {
|
|
1612
|
+
super(expandUserPath(defaultValue), opts.label);
|
|
1613
|
+
this.opts = opts;
|
|
1614
|
+
}
|
|
1615
|
+
get extensions() {
|
|
1616
|
+
return this.opts.extensions ?? DEFAULT_MEDIA_EXTENSIONS[this.kind];
|
|
1617
|
+
}
|
|
1618
|
+
get presets() {
|
|
1619
|
+
return Object.entries(this.opts.presets ?? {}).map(([label, value]) => ({ label, value: expandUserPath(value) }));
|
|
1620
|
+
}
|
|
1621
|
+
set(value) {
|
|
1622
|
+
return super.set(expandUserPath(value));
|
|
1623
|
+
}
|
|
1624
|
+
parse(raw) {
|
|
1625
|
+
this.set(raw);
|
|
1626
|
+
return true;
|
|
1627
|
+
}
|
|
1628
|
+
isSet() {
|
|
1629
|
+
return this.value !== "";
|
|
1630
|
+
}
|
|
1631
|
+
emptyError() {
|
|
1632
|
+
return new MediaVarEmptyError(this.name ?? this.label ?? this.kind, this.kind);
|
|
1633
|
+
}
|
|
1634
|
+
absPath() {
|
|
1635
|
+
if (!this.isSet())
|
|
1636
|
+
throw this.emptyError();
|
|
1637
|
+
if (isAbsolute(this.value))
|
|
1638
|
+
return this.value;
|
|
1639
|
+
return resolve(this.opts.folder ?? getComfyStorage().cwd(), this.value);
|
|
1640
|
+
}
|
|
1641
|
+
outValue() {
|
|
1642
|
+
if (!this.isSet())
|
|
1643
|
+
throw this.emptyError();
|
|
1644
|
+
return this.value;
|
|
1645
|
+
}
|
|
1646
|
+
display() {
|
|
1647
|
+
if (!this.isSet())
|
|
1648
|
+
return "(unset) pick a file";
|
|
1649
|
+
const home = getComfyStorage().homedir();
|
|
1650
|
+
return this.value.startsWith(`${home}/`) ? `~${this.value.slice(home.length)}` : this.value;
|
|
1651
|
+
}
|
|
1652
|
+
async loadVia(wf) {
|
|
1653
|
+
const loader = MEDIA_LOADERS[this.kind];
|
|
1654
|
+
const factory = wf.builderBase[loader.node];
|
|
1655
|
+
if (factory == null)
|
|
1656
|
+
throw new Error(`host '${wf.host.data.id}' has no ${loader.node} node: ${this.kind} var '${this.name ?? "?"}' cannot load`);
|
|
1657
|
+
const abs = this.absPath();
|
|
1658
|
+
const bytes = getComfyStorage().readBytes(abs);
|
|
1659
|
+
const ext = extensionOf(abs);
|
|
1660
|
+
const name = `${hashArrayBuffer(bytes)}${ext === "" ? "" : `.${ext}`}`;
|
|
1661
|
+
const onHost = wf.dry ? name : await wf.host.uploader.uploadInput({
|
|
1662
|
+
blob: new Blob([bytes], { type: mediaMime(abs) }),
|
|
1663
|
+
name,
|
|
1664
|
+
slot: `${loader.node}.${loader.input}`,
|
|
1665
|
+
type: "input"
|
|
1666
|
+
});
|
|
1667
|
+
return factory({ [loader.input]: onHost });
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
class ImageVar extends MediaVar {
|
|
1672
|
+
kind = "image";
|
|
1673
|
+
async loadInWorkflow(wf) {
|
|
1674
|
+
return await this.loadVia(wf);
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
class AudioVar extends MediaVar {
|
|
1679
|
+
kind = "audio";
|
|
1680
|
+
async loadInWorkflow(wf) {
|
|
1681
|
+
return await this.loadVia(wf);
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
class VideoVar extends MediaVar {
|
|
1686
|
+
kind = "video";
|
|
1687
|
+
async loadInWorkflow(wf) {
|
|
1688
|
+
return await this.loadVia(wf);
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
var v = {
|
|
1692
|
+
text: (defaultValue, opts = {}) => new TextVar(defaultValue, typeof opts === "string" ? { label: opts } : opts),
|
|
1693
|
+
prompt: (defaultValue, opts = {}) => new PromptVar(defaultValue, opts),
|
|
1694
|
+
int: (defaultValue, opts = {}) => new IntVar(defaultValue, opts),
|
|
1695
|
+
float: (defaultValue, opts = {}) => new FloatVar(defaultValue, opts),
|
|
1696
|
+
seed: (defaultValue = 0, opts = {}) => new SeedVar(defaultValue, opts),
|
|
1697
|
+
toggle: (defaultValue, label) => new ToggleVar(defaultValue, label),
|
|
1698
|
+
choice,
|
|
1699
|
+
loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
|
|
1700
|
+
size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
|
|
1701
|
+
model,
|
|
1702
|
+
image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts),
|
|
1703
|
+
audio: (defaultValue, opts = {}) => new AudioVar(defaultValue, opts),
|
|
1704
|
+
video: (defaultValue, opts = {}) => new VideoVar(defaultValue, opts)
|
|
1705
|
+
};
|
|
1706
|
+
function varValues(vars) {
|
|
1707
|
+
const out = {};
|
|
1708
|
+
for (const [k, varDef] of Object.entries(vars))
|
|
1709
|
+
out[k] = varDef.outValue();
|
|
1710
|
+
return out;
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
// src/vars/DefinedWorkflow.ts
|
|
1714
|
+
function isVarsThunk(vars) {
|
|
1715
|
+
return typeof vars === "function";
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
class DefinedWorkflow {
|
|
1719
|
+
host;
|
|
1720
|
+
spec;
|
|
1721
|
+
vars;
|
|
1722
|
+
constructor(host, spec) {
|
|
1723
|
+
this.host = host;
|
|
1724
|
+
this.spec = spec;
|
|
1725
|
+
this.vars = isVarsThunk(spec.vars) ? spec.vars(v) : spec.vars;
|
|
1726
|
+
for (const [key, varDef] of this.entries()) {
|
|
1727
|
+
varDef.name = key;
|
|
1728
|
+
varDef.bindHost?.(this.host);
|
|
1729
|
+
}
|
|
1730
|
+
const names = this.entries().map(([key]) => key);
|
|
1731
|
+
for (const [key, varDef] of this.entries())
|
|
1732
|
+
for (const other of Object.keys(varDef.uiOpts.activeWhen ?? {}))
|
|
1733
|
+
if (!names.includes(other))
|
|
1734
|
+
throw new Error(`workflow '${spec.id ?? "?"}': var '${key}' is activeWhen '${other}', which is not one of its vars (${names.join(", ")})`);
|
|
1735
|
+
}
|
|
1736
|
+
computePreviews() {
|
|
1737
|
+
const previews = this.spec.previews ?? {};
|
|
1738
|
+
const names = Object.keys(previews);
|
|
1739
|
+
if (names.length === 0)
|
|
1740
|
+
return {};
|
|
1741
|
+
let values;
|
|
1742
|
+
try {
|
|
1743
|
+
values = varValues(this.vars);
|
|
1744
|
+
} catch (e) {
|
|
1745
|
+
const why = `unavailable: ${e instanceof Error ? e.message : String(e)}`;
|
|
1746
|
+
return Object.fromEntries(names.map((n) => [n, why]));
|
|
1747
|
+
}
|
|
1748
|
+
const out = {};
|
|
1749
|
+
for (const [name, fn] of Object.entries(previews)) {
|
|
1750
|
+
try {
|
|
1751
|
+
out[name] = fn(values);
|
|
1752
|
+
} catch (e) {
|
|
1753
|
+
out[name] = `\uD83D\uDD34 preview '${name}' failed: ${e instanceof Error ? e.message : String(e)}`;
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
return out;
|
|
1757
|
+
}
|
|
1758
|
+
entries() {
|
|
1759
|
+
return Object.entries(this.vars);
|
|
1760
|
+
}
|
|
1761
|
+
lastWorkflow = null;
|
|
1762
|
+
lastExecution = null;
|
|
1763
|
+
async build(p = {}) {
|
|
1764
|
+
const host = p.host ?? this.host;
|
|
1765
|
+
const wf = host.workflow({ id: this.spec.id });
|
|
1766
|
+
wf.dry = p.dry === true;
|
|
1767
|
+
const values = p.values ?? this.snapshot({ advance: p.advance === true });
|
|
1768
|
+
await this.spec.build(wf.builder, values, wf);
|
|
1769
|
+
if (wf.dry)
|
|
1770
|
+
return wf;
|
|
1771
|
+
this.lastWorkflow = wf;
|
|
1772
|
+
return wf;
|
|
1773
|
+
}
|
|
1774
|
+
snapshot(p) {
|
|
1775
|
+
const values = varValues(this.vars);
|
|
1776
|
+
if (p.advance)
|
|
1777
|
+
for (const varDef of Object.values(this.vars))
|
|
1778
|
+
varDef.afterRun();
|
|
1779
|
+
return values;
|
|
1780
|
+
}
|
|
1781
|
+
async run(settings = {}) {
|
|
1782
|
+
const host = settings.host ?? this.host;
|
|
1783
|
+
const values = this.snapshot({ advance: true });
|
|
1784
|
+
host.runsInFlight++;
|
|
1785
|
+
try {
|
|
1786
|
+
await host.connect();
|
|
1787
|
+
const wf = await this.build({ host, values });
|
|
1788
|
+
const execution = await wf.run({
|
|
1789
|
+
save: settings.save,
|
|
1790
|
+
ephemeral: settings.ephemeral,
|
|
1791
|
+
scrubHistory: settings.scrubHistory,
|
|
1792
|
+
idMode: settings.idMode,
|
|
1793
|
+
log: settings.log,
|
|
1794
|
+
onProgress: settings.onProgress,
|
|
1795
|
+
onPreview: settings.onPreview,
|
|
1796
|
+
comfyOrgApiKey: settings.comfyOrgApiKey
|
|
1797
|
+
});
|
|
1798
|
+
this.lastExecution = execution;
|
|
1799
|
+
return execution;
|
|
1800
|
+
} finally {
|
|
1801
|
+
host.runsInFlight--;
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
// src/host/schemaDrift.ts
|
|
1807
|
+
var MODEL_LISTS = [
|
|
1808
|
+
{ noun: "lora", node: "LoraLoader", input: "lora_name" },
|
|
1809
|
+
{ noun: "checkpoint", node: "CheckpointLoaderSimple", input: "ckpt_name" },
|
|
1810
|
+
{ noun: "unet", node: "UNETLoader", input: "unet_name" },
|
|
1811
|
+
{ noun: "text encoder", node: "CLIPLoader", input: "clip_name" },
|
|
1812
|
+
{ noun: "vae", node: "VAELoader", input: "vae_name" }
|
|
1813
|
+
];
|
|
1814
|
+
function comboOptions(spec, node, input) {
|
|
1815
|
+
const def = spec[node];
|
|
1816
|
+
if (!isRecord(def) || !isRecord(def["input"]))
|
|
1817
|
+
return null;
|
|
1818
|
+
const sections = def["input"];
|
|
1819
|
+
for (const section of ["required", "optional"]) {
|
|
1820
|
+
const sec = sections[section];
|
|
1821
|
+
if (!isRecord(sec))
|
|
1822
|
+
continue;
|
|
1823
|
+
const slot = sec[input];
|
|
1824
|
+
if (!Array.isArray(slot))
|
|
1825
|
+
continue;
|
|
1826
|
+
const first = slot[0];
|
|
1827
|
+
if (Array.isArray(first))
|
|
1828
|
+
return first.filter((x) => typeof x === "string");
|
|
1829
|
+
const opts = slot[1];
|
|
1830
|
+
if (first === "COMBO" && isRecord(opts) && Array.isArray(opts["options"]))
|
|
1831
|
+
return opts["options"].filter((x) => typeof x === "string");
|
|
1832
|
+
}
|
|
1833
|
+
return null;
|
|
1834
|
+
}
|
|
1835
|
+
function delta(before, after) {
|
|
1836
|
+
const was = new Set(before);
|
|
1837
|
+
const now = new Set(after);
|
|
1838
|
+
return { added: after.filter((x) => !was.has(x)), removed: before.filter((x) => !now.has(x)) };
|
|
1839
|
+
}
|
|
1840
|
+
function diffSchemas(p) {
|
|
1841
|
+
const models = [];
|
|
1842
|
+
for (const m of MODEL_LISTS) {
|
|
1843
|
+
const before = comboOptions(p.loaded, m.node, m.input);
|
|
1844
|
+
const after = comboOptions(p.live, m.node, m.input);
|
|
1845
|
+
if (before == null || after == null)
|
|
1846
|
+
continue;
|
|
1847
|
+
const d = delta(before, after);
|
|
1848
|
+
if (d.added.length > 0 || d.removed.length > 0)
|
|
1849
|
+
models.push({ noun: m.noun, ...d });
|
|
1850
|
+
}
|
|
1851
|
+
return { nodes: p.full ? delta(Object.keys(p.loaded), Object.keys(p.live)) : null, models };
|
|
1852
|
+
}
|
|
1853
|
+
function driftChanged(d) {
|
|
1854
|
+
return d.models.length > 0 || d.nodes != null && (d.nodes.added.length > 0 || d.nodes.removed.length > 0);
|
|
1855
|
+
}
|
|
1856
|
+
function summarizeDrift(d) {
|
|
1857
|
+
const parts = [];
|
|
1858
|
+
const say = (n, sign, noun) => {
|
|
1859
|
+
if (n > 0)
|
|
1860
|
+
parts.push(`${sign}${n} ${noun}${n === 1 ? "" : "s"}`);
|
|
1861
|
+
};
|
|
1862
|
+
for (const m of d.models) {
|
|
1863
|
+
say(m.added.length, "+", m.noun);
|
|
1864
|
+
say(m.removed.length, "-", m.noun);
|
|
1865
|
+
}
|
|
1866
|
+
if (d.nodes != null) {
|
|
1867
|
+
say(d.nodes.added.length, "+", "node type");
|
|
1868
|
+
say(d.nodes.removed.length, "-", "node type");
|
|
1869
|
+
}
|
|
1870
|
+
return parts.join(", ");
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
export { extractErrorMessage, sha1HexOfString, statelessRegex, isQuiet, logInfo, logError, logSuccess, resolveComfyStorage, getComfyStorage, bang, isRecord, importSharp, hashArrayBuffer, MEDIA_KINDS, DEFAULT_MEDIA_EXTENSIONS, extensionOf, isVideoFilename, mediaMime, MODEL_3D_MIMES, model3dMime, ansi, stripAnsi, colorsAvailable, lmFolder, lmModelName, lmBaseModel, lmSha256, lmFileSize, lmNotes, lmCivitai, lmTags, lmTrainedWords, lmFilePath, loraKey, loraBasename, fetchLoraCivitai, fetchLoraDescription, fetchLoraExampleImages, fetchLoraList, loraPreviewMapFrom, fetchLoraPreviewBytes, buildLoraMirror, writeLoraMirror, readLoraMirror, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, getLoraInfo, getLoraTriggerWords, getLoraDisplayName, getLoraTriggers, recordCivitaiMiss, getLoraAddedAt, getLoraPreviewUrl, loraMirrorEntries, loraMatchesFilter, lorasMissingFromMirror, getLoraKeyword, isLoraKeywordFromMirror, loraKeywordFromMirror, clearLoraKeywordOverride, setLoraKeyword, isLoraStrength, isPromptInput, isLoraLanes, isLorasInput, PromptVar, LorasVar, DefinedWorkflow, MODEL_LISTS, diffSchemas, driftChanged, summarizeDrift };
|
|
1874
|
+
|
|
1875
|
+
//# debugId=F31026EF6BD649FB64756E2164756E21
|
|
1876
|
+
//# sourceMappingURL=chunk-6tsg7fm5.js.map
|