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
|
@@ -1,2225 +0,0 @@
|
|
|
1
|
-
import { basename, isAbsolute, join, resolve } from "pathe";
|
|
2
|
-
import { type } from "arktype";
|
|
3
|
-
import { imageMeta } from "image-meta";
|
|
4
|
-
import { action, makeObservable, observable, runInAction } from "mobx";
|
|
5
|
-
//#region src/utils/extractErrorMessage.ts
|
|
6
|
-
/** Extracts an error message from an exception stuff. */
|
|
7
|
-
const extractErrorMessage = (error) => {
|
|
8
|
-
if (error instanceof Error) return error.message;
|
|
9
|
-
if (error === null) return "null";
|
|
10
|
-
if (typeof error === "string") return error;
|
|
11
|
-
if (typeof error === "object") {
|
|
12
|
-
if ("message" in error && typeof error.message === "string") return error.message;
|
|
13
|
-
return JSON.stringify(error);
|
|
14
|
-
}
|
|
15
|
-
return String(error);
|
|
16
|
-
};
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/utils/sha1.ts
|
|
19
|
-
function sha1Hex(data) {
|
|
20
|
-
const ml = data.length;
|
|
21
|
-
const total = Math.ceil((ml + 1 + 8) / 64) * 64;
|
|
22
|
-
const bytes = new Uint8Array(total);
|
|
23
|
-
bytes.set(data);
|
|
24
|
-
bytes[ml] = 128;
|
|
25
|
-
const dv = new DataView(bytes.buffer);
|
|
26
|
-
const bitLen = ml * 8;
|
|
27
|
-
dv.setUint32(total - 8, Math.floor(bitLen / 2 ** 32));
|
|
28
|
-
dv.setUint32(total - 4, bitLen >>> 0);
|
|
29
|
-
let h0 = 1732584193;
|
|
30
|
-
let h1 = 4023233417;
|
|
31
|
-
let h2 = 2562383102;
|
|
32
|
-
let h3 = 271733878;
|
|
33
|
-
let h4 = 3285377520;
|
|
34
|
-
const w = /* @__PURE__ */ new Uint32Array(80);
|
|
35
|
-
for (let i = 0; i < total; i += 64) {
|
|
36
|
-
for (let j = 0; j < 16; j++) 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 [
|
|
76
|
-
h0,
|
|
77
|
-
h1,
|
|
78
|
-
h2,
|
|
79
|
-
h3,
|
|
80
|
-
h4
|
|
81
|
-
].map((x) => x.toString(16).padStart(8, "0")).join("");
|
|
82
|
-
}
|
|
83
|
-
function sha1HexOfString(s) {
|
|
84
|
-
return sha1Hex(new TextEncoder().encode(s));
|
|
85
|
-
}
|
|
86
|
-
//#endregion
|
|
87
|
-
//#region src/utils/matchesRegex.ts
|
|
88
|
-
function statelessRegex(re) {
|
|
89
|
-
if (!re.global && !re.sticky) return re;
|
|
90
|
-
const source = re.sticky ? `^(?:${re.source})` : re.source;
|
|
91
|
-
return new RegExp(source, re.flags.replace(/[gy]/g, ""));
|
|
92
|
-
}
|
|
93
|
-
//#endregion
|
|
94
|
-
//#region src/utils/log.ts
|
|
95
|
-
const isQuiet = () => process.env.COMFY_TS_QUIET === "1";
|
|
96
|
-
const logInfo = (msg) => {
|
|
97
|
-
if (!isQuiet()) console.log(msg);
|
|
98
|
-
};
|
|
99
|
-
const logError = (msg) => console.error(`[comfy-ts] 🔴 ${msg}`);
|
|
100
|
-
const logSuccess = (msg) => console.log(`[comfy-ts] 🟢 ${msg}`);
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/storage/ComfyStorage.ts
|
|
103
|
-
function dirnameOf(path) {
|
|
104
|
-
const ix = path.lastIndexOf("/");
|
|
105
|
-
return ix <= 0 ? "/" : path.slice(0, ix);
|
|
106
|
-
}
|
|
107
|
-
/** node backend built from INJECTED modules: nodeStorage.ts passes its static
|
|
108
|
-
* imports, the autodetect below passes process.getBuiltinModule results */
|
|
109
|
-
function createNodeStorageFrom(fs, os) {
|
|
110
|
-
return {
|
|
111
|
-
kind: "node",
|
|
112
|
-
readText: (p) => fs.readFileSync(p, "utf8"),
|
|
113
|
-
readTextIfExists: (p) => fs.existsSync(p) ? fs.readFileSync(p, "utf8") : null,
|
|
114
|
-
readBytes: (p) => new Uint8Array(fs.readFileSync(p)),
|
|
115
|
-
writeText: (p, text) => {
|
|
116
|
-
fs.mkdirSync(dirnameOf(p), { recursive: true });
|
|
117
|
-
fs.writeFileSync(p, text);
|
|
118
|
-
},
|
|
119
|
-
writeBytes: (p, bytes) => {
|
|
120
|
-
fs.mkdirSync(dirnameOf(p), { recursive: true });
|
|
121
|
-
fs.writeFileSync(p, bytes);
|
|
122
|
-
},
|
|
123
|
-
exists: (p) => fs.existsSync(p),
|
|
124
|
-
mkdirp: (p) => void fs.mkdirSync(p, { recursive: true }),
|
|
125
|
-
mtimeMs: (p) => fs.existsSync(p) ? fs.statSync(p).mtimeMs : null,
|
|
126
|
-
homedir: () => os.homedir(),
|
|
127
|
-
cwd: () => process.cwd()
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
let installedDefault = null;
|
|
131
|
-
function autodetectNodeStorage() {
|
|
132
|
-
const get = globalThis.process?.getBuiltinModule;
|
|
133
|
-
if (typeof get !== "function") return null;
|
|
134
|
-
const fs = get("node:fs");
|
|
135
|
-
const os = get("node:os");
|
|
136
|
-
if (fs == null || os == null) return null;
|
|
137
|
-
return createNodeStorageFrom(fs, os);
|
|
138
|
-
}
|
|
139
|
-
function resolveComfyStorage(explicit) {
|
|
140
|
-
if (explicit != null) return explicit;
|
|
141
|
-
if (installedDefault != null) return installedDefault;
|
|
142
|
-
const detected = autodetectNodeStorage();
|
|
143
|
-
if (detected != null) {
|
|
144
|
-
installedDefault = detected;
|
|
145
|
-
return detected;
|
|
146
|
-
}
|
|
147
|
-
throw new Error(`no ComfyStorage available — import 'comfy-ts' (node) or 'comfy-ts/web' (browser) before creating ComfyTS, or pass ComfyTS.create({ storage })`);
|
|
148
|
-
}
|
|
149
|
-
/** the ONE accessor call sites use: the instance's storage when the global
|
|
150
|
-
* exists, the resolved default otherwise (vars constructed before create()) */
|
|
151
|
-
function getComfyStorage() {
|
|
152
|
-
return globalThis.comfyts?.storage ?? resolveComfyStorage();
|
|
153
|
-
}
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/utils/bang.ts
|
|
156
|
-
/** assertNotNull */
|
|
157
|
-
const bang = (x, msg = "") => {
|
|
158
|
-
if (x == null) {
|
|
159
|
-
console.error(`[🔴] BANG FAILED`, msg);
|
|
160
|
-
throw new Error("bang: " + (msg ?? "no message"));
|
|
161
|
-
}
|
|
162
|
-
return x;
|
|
163
|
-
};
|
|
164
|
-
//#endregion
|
|
165
|
-
//#region src/utils/isRecord.ts
|
|
166
|
-
/** narrows unknown wire json to an indexable object (arrays and null excluded) */
|
|
167
|
-
function isRecord(v) {
|
|
168
|
-
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
169
|
-
}
|
|
170
|
-
//#endregion
|
|
171
|
-
//#region src/utils/lazySharp.ts
|
|
172
|
-
let cached = null;
|
|
173
|
-
async function importSharp(reason) {
|
|
174
|
-
if (cached != null) return cached;
|
|
175
|
-
const specifier = "sharp";
|
|
176
|
-
try {
|
|
177
|
-
cached = (await import(specifier)).default;
|
|
178
|
-
return cached;
|
|
179
|
-
} catch (e) {
|
|
180
|
-
throw new Error(`sharp is unavailable — ${reason} is node-only (browser builds get raw bytes instead): ${extractErrorMessage(e)}`, { cause: e });
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
//#endregion
|
|
184
|
-
//#region src/utils/hashArrayBuffer.ts
|
|
185
|
-
const hashArrayBuffer = (buffer) => {
|
|
186
|
-
return sha1Hex(buffer);
|
|
187
|
-
};
|
|
188
|
-
//#endregion
|
|
189
|
-
//#region src/runner/mediaKinds.ts
|
|
190
|
-
const MEDIA_KINDS = [
|
|
191
|
-
"image",
|
|
192
|
-
"audio",
|
|
193
|
-
"video"
|
|
194
|
-
];
|
|
195
|
-
/** picker defaults per kind, lowercase without dots */
|
|
196
|
-
const DEFAULT_MEDIA_EXTENSIONS = {
|
|
197
|
-
image: [
|
|
198
|
-
"png",
|
|
199
|
-
"jpg",
|
|
200
|
-
"jpeg",
|
|
201
|
-
"webp",
|
|
202
|
-
"gif"
|
|
203
|
-
],
|
|
204
|
-
audio: [
|
|
205
|
-
"wav",
|
|
206
|
-
"flac",
|
|
207
|
-
"mp3",
|
|
208
|
-
"ogg",
|
|
209
|
-
"opus",
|
|
210
|
-
"m4a"
|
|
211
|
-
],
|
|
212
|
-
video: [
|
|
213
|
-
"mp4",
|
|
214
|
-
"webm",
|
|
215
|
-
"mov",
|
|
216
|
-
"mkv",
|
|
217
|
-
"m4v"
|
|
218
|
-
]
|
|
219
|
-
};
|
|
220
|
-
const MIMES = {
|
|
221
|
-
png: "image/png",
|
|
222
|
-
jpg: "image/jpeg",
|
|
223
|
-
jpeg: "image/jpeg",
|
|
224
|
-
webp: "image/webp",
|
|
225
|
-
gif: "image/gif",
|
|
226
|
-
flac: "audio/flac",
|
|
227
|
-
mp3: "audio/mpeg",
|
|
228
|
-
opus: "audio/ogg",
|
|
229
|
-
ogg: "audio/ogg",
|
|
230
|
-
wav: "audio/wav",
|
|
231
|
-
m4a: "audio/mp4",
|
|
232
|
-
aac: "audio/aac",
|
|
233
|
-
mp4: "video/mp4",
|
|
234
|
-
m4v: "video/mp4",
|
|
235
|
-
webm: "video/webm",
|
|
236
|
-
mov: "video/quicktime",
|
|
237
|
-
mkv: "video/x-matroska",
|
|
238
|
-
avi: "video/x-msvideo"
|
|
239
|
-
};
|
|
240
|
-
/** video containers an output node can name. An animated webp or gif is an IMAGE: the
|
|
241
|
-
* extension decides, never the `animated` flag */
|
|
242
|
-
const VIDEO_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
243
|
-
"mp4",
|
|
244
|
-
"m4v",
|
|
245
|
-
"webm",
|
|
246
|
-
"mov",
|
|
247
|
-
"mkv",
|
|
248
|
-
"avi"
|
|
249
|
-
]);
|
|
250
|
-
function extensionOf(filename) {
|
|
251
|
-
const dot = filename.lastIndexOf(".");
|
|
252
|
-
return dot < 0 ? "" : filename.slice(dot + 1).toLowerCase();
|
|
253
|
-
}
|
|
254
|
-
function isVideoFilename(filename) {
|
|
255
|
-
return VIDEO_EXTENSIONS.has(extensionOf(filename));
|
|
256
|
-
}
|
|
257
|
-
function mediaMime(filename) {
|
|
258
|
-
return MIMES[extensionOf(filename)] ?? "application/octet-stream";
|
|
259
|
-
}
|
|
260
|
-
//#endregion
|
|
261
|
-
//#region src/runner/outputs3d.ts
|
|
262
|
-
/** ply and spz have no registered mime: the `x-` forms are what three.js and the splat viewers accept */
|
|
263
|
-
const MODEL_3D_MIMES = {
|
|
264
|
-
glb: "model/gltf-binary",
|
|
265
|
-
gltf: "model/gltf+json",
|
|
266
|
-
ply: "model/x-ply",
|
|
267
|
-
spz: "model/x-spz",
|
|
268
|
-
obj: "model/obj",
|
|
269
|
-
stl: "model/stl"
|
|
270
|
-
};
|
|
271
|
-
function model3dMime(filename) {
|
|
272
|
-
return MODEL_3D_MIMES[extensionOf(filename)] ?? "application/octet-stream";
|
|
273
|
-
}
|
|
274
|
-
//#endregion
|
|
275
|
-
//#region src/utils/ansi.ts
|
|
276
|
-
const codes = {
|
|
277
|
-
bold: [1, 22],
|
|
278
|
-
dim: [2, 22],
|
|
279
|
-
underline: [4, 24],
|
|
280
|
-
red: [31, 39],
|
|
281
|
-
green: [32, 39],
|
|
282
|
-
yellow: [33, 39],
|
|
283
|
-
blue: [34, 39],
|
|
284
|
-
cyan: [36, 39],
|
|
285
|
-
gray: [90, 39],
|
|
286
|
-
greenBright: [92, 39]
|
|
287
|
-
};
|
|
288
|
-
function styler(open = "", close = "") {
|
|
289
|
-
const fn = (s) => open + s + close;
|
|
290
|
-
return new Proxy(fn, { get(_target, prop) {
|
|
291
|
-
const c = codes[prop];
|
|
292
|
-
if (c == null) throw new Error(`unknown ansi style: ${prop}`);
|
|
293
|
-
return styler(`${open}\x1b[${c[0]}m`, `\x1b[${c[1]}m${close}`);
|
|
294
|
-
} });
|
|
295
|
-
}
|
|
296
|
-
const ansi = styler();
|
|
297
|
-
const ANSI_RE = /\x1b\[[0-9;?]*[A-Za-z]|\x1b[A-Za-z]/g;
|
|
298
|
-
function stripAnsi(s) {
|
|
299
|
-
return s.replace(ANSI_RE, "");
|
|
300
|
-
}
|
|
301
|
-
/** colors only where they can be seen: a real terminal, NO_COLOR unset, TERM not 'dumb'.
|
|
302
|
-
* A piped or redirected stdout gets plain text, so `serve > log` stays greppable */
|
|
303
|
-
function colorsAvailable() {
|
|
304
|
-
const env = globalThis.process?.env ?? {};
|
|
305
|
-
if (env.NO_COLOR != null && env.NO_COLOR !== "") return false;
|
|
306
|
-
if (env.TERM === "dumb") return false;
|
|
307
|
-
if (env.FORCE_COLOR != null && env.FORCE_COLOR !== "" && env.FORCE_COLOR !== "0") return true;
|
|
308
|
-
return globalThis.process?.stdout?.isTTY === true;
|
|
309
|
-
}
|
|
310
|
-
//#endregion
|
|
311
|
-
//#region src/host/loraManagerApi.ts
|
|
312
|
-
/** only the ENVELOPE is schema'd — items stay unknown so nothing can strip their fields */
|
|
313
|
-
const lmLoraPage = type({
|
|
314
|
-
items: "unknown[]",
|
|
315
|
-
"total?": "number"
|
|
316
|
-
});
|
|
317
|
-
function readString(item, key) {
|
|
318
|
-
const v = item[key];
|
|
319
|
-
return typeof v === "string" && v !== "" ? v : null;
|
|
320
|
-
}
|
|
321
|
-
function readStringArray(item, key) {
|
|
322
|
-
const v = item[key];
|
|
323
|
-
if (!Array.isArray(v)) return [];
|
|
324
|
-
return v.filter((x) => typeof x === "string" && x !== "");
|
|
325
|
-
}
|
|
326
|
-
function lmFileName(item) {
|
|
327
|
-
return readString(item, "file_name");
|
|
328
|
-
}
|
|
329
|
-
function lmFolder(item) {
|
|
330
|
-
return readString(item, "folder") ?? "";
|
|
331
|
-
}
|
|
332
|
-
function lmModelName(item) {
|
|
333
|
-
return readString(item, "model_name");
|
|
334
|
-
}
|
|
335
|
-
function lmBaseModel(item) {
|
|
336
|
-
return readString(item, "base_model");
|
|
337
|
-
}
|
|
338
|
-
function lmPreviewUrl(item) {
|
|
339
|
-
return readString(item, "preview_url");
|
|
340
|
-
}
|
|
341
|
-
/** the file's size in bytes, when the extension reports it */
|
|
342
|
-
/** the file's content hash: what the extension keys its example images by */
|
|
343
|
-
function lmSha256(item) {
|
|
344
|
-
return readString(item, "sha256");
|
|
345
|
-
}
|
|
346
|
-
/** when the file landed on the host (epoch seconds): the lora manager's own "date added" sort reads it */
|
|
347
|
-
function lmModified(item) {
|
|
348
|
-
const raw = item["modified"];
|
|
349
|
-
return typeof raw === "number" && Number.isFinite(raw) ? raw : null;
|
|
350
|
-
}
|
|
351
|
-
function lmFileSize(item) {
|
|
352
|
-
const raw = item["file_size"];
|
|
353
|
-
return typeof raw === "number" && Number.isFinite(raw) ? raw : null;
|
|
354
|
-
}
|
|
355
|
-
/** the note YOU wrote in the lora manager, empty when there is none */
|
|
356
|
-
function lmNotes(item) {
|
|
357
|
-
return readString(item, "notes") ?? "";
|
|
358
|
-
}
|
|
359
|
-
/** the civitai block: what links a local file back to the page it came from */
|
|
360
|
-
function lmCivitai(item) {
|
|
361
|
-
const civitai = item["civitai"];
|
|
362
|
-
if (!isRecord(civitai)) return null;
|
|
363
|
-
const modelId = civitai["modelId"];
|
|
364
|
-
return {
|
|
365
|
-
modelId: typeof modelId === "number" && Number.isFinite(modelId) ? modelId : null,
|
|
366
|
-
name: readString(civitai, "name")
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
function lmTags(item) {
|
|
370
|
-
return readStringArray(item, "tags");
|
|
371
|
-
}
|
|
372
|
-
/** the trigger words: civitai's `trainedWords`, absent for a lora nobody published */
|
|
373
|
-
function lmTrainedWords(item) {
|
|
374
|
-
const civitai = item["civitai"];
|
|
375
|
-
if (!isRecord(civitai)) return [];
|
|
376
|
-
return readStringArray(civitai, "trainedWords");
|
|
377
|
-
}
|
|
378
|
-
/** lm's own absolute path for the file, as it exists on the HOST's disk */
|
|
379
|
-
function lmFilePath(item) {
|
|
380
|
-
return readString(item, "file_path");
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* the ONE key space where a host's object_info spelling of a lora meets
|
|
384
|
-
* lora-manager's: lowercase, forward slashes, no model extension.
|
|
385
|
-
* `styles\Aurora.safetensors` and lm's folder `styles` + file_name `aurora`
|
|
386
|
-
* both become `styles/aurora`.
|
|
387
|
-
*/
|
|
388
|
-
function loraKey(name) {
|
|
389
|
-
return name.replaceAll("\\", "/").replace(/\.(safetensors|st|pt|ckpt)$/i, "").toLowerCase();
|
|
390
|
-
}
|
|
391
|
-
/** the file's own name, windows separators included (`styles\x.safetensors` → `x.safetensors`) */
|
|
392
|
-
function loraBasename(name) {
|
|
393
|
-
return basename(name.replaceAll("\\", "/"));
|
|
394
|
-
}
|
|
395
|
-
/** the mirror key for an lm item: its folder/file_name pair, normalized */
|
|
396
|
-
function lmItemKey(item) {
|
|
397
|
-
const file = lmFileName(item);
|
|
398
|
-
if (file == null) return null;
|
|
399
|
-
const folder = lmFolder(item);
|
|
400
|
-
return loraKey(folder === "" ? file : `${folder}/${file}`);
|
|
401
|
-
}
|
|
402
|
-
/** runaway stop: 20 pages × the server's 100-per-page cap = 2000 loras */
|
|
403
|
-
const MAX_PAGES = 20;
|
|
404
|
-
/** asks the extension to (re)fetch civitai metadata for ONE lora file, trigger words included.
|
|
405
|
-
* The reply says why when civitai has nothing for it (a private or deleted model) */
|
|
406
|
-
async function fetchLoraCivitai(host, filePath) {
|
|
407
|
-
try {
|
|
408
|
-
const res = await host.fetch("/lm/loras/fetch-civitai", {
|
|
409
|
-
method: "POST",
|
|
410
|
-
headers: { "content-type": "application/json" },
|
|
411
|
-
body: JSON.stringify({ file_path: filePath })
|
|
412
|
-
});
|
|
413
|
-
const raw = await res.json().catch(() => null);
|
|
414
|
-
const error = isRecord(raw) && typeof raw["error"] === "string" ? raw["error"] : null;
|
|
415
|
-
if (res.ok && isRecord(raw) && raw["success"] !== false) return { ok: true };
|
|
416
|
-
return {
|
|
417
|
-
ok: false,
|
|
418
|
-
reason: error ?? `the lora manager answered ${res.status}`
|
|
419
|
-
};
|
|
420
|
-
} catch (e) {
|
|
421
|
-
return {
|
|
422
|
-
ok: false,
|
|
423
|
-
reason: extractErrorMessage(e)
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
/** civitai's model description for ONE lora, as PLAIN TEXT. The extension answers html, and
|
|
428
|
-
* html from a third party is never rendered: tags are stripped here, at the seam.
|
|
429
|
-
* null = the extension has no description for it (or does not expose the route) */
|
|
430
|
-
async function fetchLoraDescription(host, filePath) {
|
|
431
|
-
try {
|
|
432
|
-
const res = await host.fetch(`/lm/loras/model-description?file_path=${encodeURIComponent(filePath)}`, {});
|
|
433
|
-
if (!res.ok) {
|
|
434
|
-
if (res.status !== 404) logError(`[lora-manager] description ${res.status} for ${filePath}`);
|
|
435
|
-
return null;
|
|
436
|
-
}
|
|
437
|
-
const raw = await res.json();
|
|
438
|
-
const description = isRecord(raw) ? raw["description"] : null;
|
|
439
|
-
if (typeof description !== "string" || description === "") return null;
|
|
440
|
-
return htmlToText(description);
|
|
441
|
-
} catch (e) {
|
|
442
|
-
logError(`[lora-manager] description unreachable for ${filePath}: ${extractErrorMessage(e)}`);
|
|
443
|
-
return null;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
/** `<p>a</p><br>b` → `a\n\nb`. Deliberately dumb: this text is DISPLAYED, never parsed */
|
|
447
|
-
function htmlToText(html) {
|
|
448
|
-
return html.replaceAll(/<\s*br\s*\/?>/gi, "\n").replaceAll(/<\/\s*(p|div|li|h[1-6])\s*>/gi, "\n\n").replaceAll(/<\s*li[^>]*>/gi, "· ").replaceAll(/<[^>]+>/g, "").replaceAll(" ", " ").replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll(""", "\"").replaceAll("'", "'").replaceAll(/\n{3,}/g, "\n\n").trim();
|
|
449
|
-
}
|
|
450
|
-
/** the example images lora-manager keeps for a lora. `reason` explains an empty list rather
|
|
451
|
-
* than pretending the lora has none, "no example images path configured" is a SETTING */
|
|
452
|
-
async function fetchLoraExampleImages(host, sha256) {
|
|
453
|
-
try {
|
|
454
|
-
const res = await host.fetch(`/lm/example-image-files?model_hash=${encodeURIComponent(sha256)}`, {});
|
|
455
|
-
const raw = await res.json();
|
|
456
|
-
if (!isRecord(raw)) return {
|
|
457
|
-
files: [],
|
|
458
|
-
reason: `unexpected reply (http ${res.status})`
|
|
459
|
-
};
|
|
460
|
-
if (raw["success"] !== true) {
|
|
461
|
-
const err = raw["error"];
|
|
462
|
-
return {
|
|
463
|
-
files: [],
|
|
464
|
-
reason: typeof err === "string" ? err : `http ${res.status}`
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
const files = raw["files"];
|
|
468
|
-
if (!Array.isArray(files)) return {
|
|
469
|
-
files: [],
|
|
470
|
-
reason: null
|
|
471
|
-
};
|
|
472
|
-
const out = [];
|
|
473
|
-
for (const f of files) if (typeof f === "string") out.push(f);
|
|
474
|
-
else if (isRecord(f) && typeof f["path"] === "string") out.push(f["path"]);
|
|
475
|
-
return {
|
|
476
|
-
files: out,
|
|
477
|
-
reason: null
|
|
478
|
-
};
|
|
479
|
-
} catch (e) {
|
|
480
|
-
return {
|
|
481
|
-
files: [],
|
|
482
|
-
reason: e instanceof Error ? e.message : String(e)
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
/**
|
|
487
|
-
* every lora lora-manager knows, RAW, in one paged sweep.
|
|
488
|
-
* page_size asks for 500; the server caps it at 100, so the loop follows `total`.
|
|
489
|
-
*/
|
|
490
|
-
async function fetchLoraList(host) {
|
|
491
|
-
const items = [];
|
|
492
|
-
for (let page = 1; page <= MAX_PAGES; page++) {
|
|
493
|
-
let res;
|
|
494
|
-
try {
|
|
495
|
-
res = await host.fetch(`/api/lm/loras/list?page=${page}&page_size=500`, {}, { apiPrefix: false });
|
|
496
|
-
} catch (e) {
|
|
497
|
-
const reason = `host unreachable at page ${page}: ${extractErrorMessage(e)}`;
|
|
498
|
-
return page === 1 ? {
|
|
499
|
-
status: "unreachable",
|
|
500
|
-
reason
|
|
501
|
-
} : partial(items, reason);
|
|
502
|
-
}
|
|
503
|
-
if (!res.ok) {
|
|
504
|
-
const missing = res.status === 404 || res.status === 405;
|
|
505
|
-
if (page === 1) return missing ? { status: "absent" } : {
|
|
506
|
-
status: "unreachable",
|
|
507
|
-
reason: `answered ${res.status}`
|
|
508
|
-
};
|
|
509
|
-
return partial(items, `page ${page} answered ${res.status}`);
|
|
510
|
-
}
|
|
511
|
-
let parsed;
|
|
512
|
-
try {
|
|
513
|
-
parsed = lmLoraPage(await res.json());
|
|
514
|
-
} catch (e) {
|
|
515
|
-
const reason = `page ${page} did not answer json: ${extractErrorMessage(e)}`;
|
|
516
|
-
return page === 1 ? { status: "absent" } : partial(items, reason);
|
|
517
|
-
}
|
|
518
|
-
if (parsed instanceof type.errors) return partial(items, `page ${page} shape mismatch: ${parsed.summary}`);
|
|
519
|
-
const pageItems = parsed.items.filter(isRecord);
|
|
520
|
-
items.push(...pageItems);
|
|
521
|
-
const total = parsed.total;
|
|
522
|
-
if (total != null && items.length >= total) return {
|
|
523
|
-
status: "ok",
|
|
524
|
-
items
|
|
525
|
-
};
|
|
526
|
-
if (pageItems.length === 0) return total == null || page === 1 ? {
|
|
527
|
-
status: "ok",
|
|
528
|
-
items
|
|
529
|
-
} : partial(items, `page ${page} came back empty with ${items.length}/${total} fetched`);
|
|
530
|
-
}
|
|
531
|
-
return partial(items, `stopped at the ${MAX_PAGES}-page runaway limit`);
|
|
532
|
-
}
|
|
533
|
-
/** a truncated sweep is LOUD at the source, whatever the caller then decides to do */
|
|
534
|
-
function partial(items, reason) {
|
|
535
|
-
logError(`[loraManagerApi] lora sweep INCOMPLETE after ${items.length} loras — ${reason}`);
|
|
536
|
-
return {
|
|
537
|
-
status: "partial",
|
|
538
|
-
items,
|
|
539
|
-
reason
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
/** `loraKey` → server-relative preview_url */
|
|
543
|
-
function loraPreviewMapFrom(items) {
|
|
544
|
-
const map = /* @__PURE__ */ new Map();
|
|
545
|
-
for (const item of items) {
|
|
546
|
-
const key = lmItemKey(item);
|
|
547
|
-
const url = lmPreviewUrl(item);
|
|
548
|
-
if (key != null && url != null) map.set(key, url);
|
|
549
|
-
}
|
|
550
|
-
return map;
|
|
551
|
-
}
|
|
552
|
-
/** the bytes look like an image (magic numbers) — guards against ComfyUI's SPA index.html fallback */
|
|
553
|
-
function looksLikeImage(bytes) {
|
|
554
|
-
if (bytes.length < 3) return false;
|
|
555
|
-
const b = bytes;
|
|
556
|
-
const is = (sig, off = 0) => sig.every((v, i) => b[off + i] === v);
|
|
557
|
-
return is([
|
|
558
|
-
137,
|
|
559
|
-
80,
|
|
560
|
-
78,
|
|
561
|
-
71
|
|
562
|
-
]) || is([
|
|
563
|
-
255,
|
|
564
|
-
216,
|
|
565
|
-
255
|
|
566
|
-
]) || is([
|
|
567
|
-
71,
|
|
568
|
-
73,
|
|
569
|
-
70
|
|
570
|
-
]) || is([
|
|
571
|
-
82,
|
|
572
|
-
73,
|
|
573
|
-
70,
|
|
574
|
-
70
|
|
575
|
-
]) && is([
|
|
576
|
-
87,
|
|
577
|
-
69,
|
|
578
|
-
66,
|
|
579
|
-
80
|
|
580
|
-
], 8);
|
|
581
|
-
}
|
|
582
|
-
/**
|
|
583
|
-
* fetch a preview image's bytes from its server-relative preview_url.
|
|
584
|
-
* cached on success at `.comfy-ts/cache/lora-previews/<sha1(url)>`. Returns null
|
|
585
|
-
* when the file is missing: lora-manager SPA-fallbacks to index.html (HTML), so
|
|
586
|
-
* a non-image content-type OR non-image magic bytes => no preview, not a crash.
|
|
587
|
-
*/
|
|
588
|
-
async function fetchLoraPreviewBytes(host, previewUrl) {
|
|
589
|
-
const storage = getComfyStorage();
|
|
590
|
-
const cachePath = comfyts.resolveFromCache(`lora-previews/${sha1HexOfString(previewUrl)}`);
|
|
591
|
-
if (storage.exists(cachePath)) return storage.readBytes(cachePath);
|
|
592
|
-
try {
|
|
593
|
-
const res = await host.fetch(previewUrl, {}, { apiPrefix: false });
|
|
594
|
-
if (!res.ok) return null;
|
|
595
|
-
const ct = res.headers.get("content-type") ?? "";
|
|
596
|
-
if (ct !== "" && !ct.startsWith("image/")) return null;
|
|
597
|
-
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
598
|
-
if (!looksLikeImage(bytes)) return null;
|
|
599
|
-
storage.writeBytes(cachePath, bytes);
|
|
600
|
-
return bytes;
|
|
601
|
-
} catch {
|
|
602
|
-
return null;
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
//#endregion
|
|
606
|
-
//#region src/host/loraInfoCache.ts
|
|
607
|
-
function loraMirrorPath(hostId) {
|
|
608
|
-
return comfyts.resolveFromHosts(join(hostId, "loras.json"));
|
|
609
|
-
}
|
|
610
|
-
/** pure: the on-disk shape for a sweep. Items without a file_name are dropped (nothing to key them by). */
|
|
611
|
-
function buildLoraMirror(p) {
|
|
612
|
-
const loras = {};
|
|
613
|
-
for (const item of p.items) {
|
|
614
|
-
const key = lmItemKey(item);
|
|
615
|
-
if (key == null) continue;
|
|
616
|
-
if (loras[key] != null) logError(`[loraInfoCache] two loras share the key '${key}' — one of them is shadowed`);
|
|
617
|
-
loras[key] = item;
|
|
618
|
-
}
|
|
619
|
-
return {
|
|
620
|
-
hostId: p.hostId,
|
|
621
|
-
hostUrl: p.hostUrl,
|
|
622
|
-
fetchedAt: p.fetchedAt,
|
|
623
|
-
count: Object.keys(loras).length,
|
|
624
|
-
loras
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
function writeLoraMirror(mirror) {
|
|
628
|
-
const path = loraMirrorPath(mirror.hostId);
|
|
629
|
-
getComfyStorage().writeText(path, JSON.stringify(mirror, null, 2));
|
|
630
|
-
return path;
|
|
631
|
-
}
|
|
632
|
-
/** null = never synced (or unreadable, which is LOGGED) */
|
|
633
|
-
function readLoraMirror(hostId) {
|
|
634
|
-
const path = loraMirrorPath(hostId);
|
|
635
|
-
const text = getComfyStorage().readTextIfExists(path);
|
|
636
|
-
if (text == null) return null;
|
|
637
|
-
try {
|
|
638
|
-
const raw = JSON.parse(text);
|
|
639
|
-
if (!isRecord(raw)) return null;
|
|
640
|
-
const rawLoras = raw["loras"];
|
|
641
|
-
if (!isRecord(rawLoras)) return null;
|
|
642
|
-
const loras = {};
|
|
643
|
-
for (const [key, item] of Object.entries(rawLoras)) if (isRecord(item)) loras[key] = item;
|
|
644
|
-
const str = (key, fallback) => {
|
|
645
|
-
const v = raw[key];
|
|
646
|
-
return typeof v === "string" ? v : fallback;
|
|
647
|
-
};
|
|
648
|
-
return {
|
|
649
|
-
hostId: str("hostId", hostId),
|
|
650
|
-
hostUrl: str("hostUrl", ""),
|
|
651
|
-
fetchedAt: str("fetchedAt", ""),
|
|
652
|
-
count: Object.keys(loras).length,
|
|
653
|
-
loras
|
|
654
|
-
};
|
|
655
|
-
} catch (e) {
|
|
656
|
-
logError(`[loraInfoCache] unreadable ${path}: ${String(e)}`);
|
|
657
|
-
return null;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
/**
|
|
661
|
-
* the read model: each registered host's mirror, kept PER HOST.
|
|
662
|
-
*
|
|
663
|
-
* Per host, not merged into one map, because the same file name on two hosts is
|
|
664
|
-
* routinely a different model. A merged map served whichever host loaded first,
|
|
665
|
-
* so on the other host the overlay showed the wrong model name and the prompt
|
|
666
|
-
* silently received the wrong trigger words — a bad generation with no error
|
|
667
|
-
* anywhere. Callers that know their host say so; the rest fall back to any host
|
|
668
|
-
* that has the lora, which is still better than nothing for a display name.
|
|
669
|
-
*
|
|
670
|
-
* Plain (non-observable) on purpose: the loras overlay reads this from inside a
|
|
671
|
-
* mobx render. The storage seam has no readdir, so the host set comes from
|
|
672
|
-
* `comfyts.hosts` — exactly the hosts this process can be asked about.
|
|
673
|
-
*/
|
|
674
|
-
const byHost = /* @__PURE__ */ new Map();
|
|
675
|
-
/** hosts already looked for, INCLUDING the ones with no mirror on disk → their mtime is null */
|
|
676
|
-
const loadedMtimes = /* @__PURE__ */ new Map();
|
|
677
|
-
/** cheap: no stat, no parse — this runs inside the overlay's render for every row */
|
|
678
|
-
function ensureLoaded() {
|
|
679
|
-
for (const hostId of comfyts.hosts.keys()) if (!loadedMtimes.has(hostId)) loadHost(hostId);
|
|
680
|
-
}
|
|
681
|
-
function loadHost(hostId) {
|
|
682
|
-
const storage = getComfyStorage();
|
|
683
|
-
const path = loraMirrorPath(hostId);
|
|
684
|
-
loadedMtimes.set(hostId, storage.mtimeMs(path));
|
|
685
|
-
const mirror = readLoraMirror(hostId);
|
|
686
|
-
if (mirror != null) byHost.set(hostId, new Map(Object.entries(mirror.loras)));
|
|
687
|
-
else if (storage.exists(path)) byHost.set(hostId, /* @__PURE__ */ new Map());
|
|
688
|
-
else byHost.delete(hostId);
|
|
689
|
-
}
|
|
690
|
-
/**
|
|
691
|
-
* re-read any mirror whose file changed (or appeared) since we loaded it.
|
|
692
|
-
* `comfy-ts loras` in another terminal is the normal case, and without this a
|
|
693
|
-
* TUI session kept the stale data — or kept knowing NOTHING, for a host whose
|
|
694
|
-
* first sync happened while it was open. One stat per registered host, so this
|
|
695
|
-
* belongs at user-initiated moments (opening the loras overlay), never in a render.
|
|
696
|
-
*/
|
|
697
|
-
function refreshLoraInfoCacheIfChanged() {
|
|
698
|
-
const storage = getComfyStorage();
|
|
699
|
-
for (const hostId of comfyts.hosts.keys()) {
|
|
700
|
-
const seen = loadedMtimes.get(hostId);
|
|
701
|
-
const now = storage.mtimeMs(loraMirrorPath(hostId));
|
|
702
|
-
if (!loadedMtimes.has(hostId) || seen !== now) loadHost(hostId);
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
/** forget everything loaded, so the next read re-reads from disk (tests, and a hard refresh) */
|
|
706
|
-
function reloadLoraInfoCache() {
|
|
707
|
-
byHost.clear();
|
|
708
|
-
loadedMtimes.clear();
|
|
709
|
-
}
|
|
710
|
-
/**
|
|
711
|
-
* the lm item for a raw lora name (`styles\x.safetensors`).
|
|
712
|
-
* `hostId` picks the mirror that actually describes this host's file; without
|
|
713
|
-
* it, any host that knows the name answers. null when unsynced/unknown.
|
|
714
|
-
*/
|
|
715
|
-
function getLoraInfo(name, hostId) {
|
|
716
|
-
ensureLoaded();
|
|
717
|
-
const key = loraKey(name);
|
|
718
|
-
if (hostId != null) {
|
|
719
|
-
const own = byHost.get(hostId);
|
|
720
|
-
if (own != null) return own.get(key) ?? null;
|
|
721
|
-
}
|
|
722
|
-
for (const mirror of byHost.values()) {
|
|
723
|
-
const hit = mirror.get(key);
|
|
724
|
-
if (hit != null) return hit;
|
|
725
|
-
}
|
|
726
|
-
return null;
|
|
727
|
-
}
|
|
728
|
-
/** civitai trigger words for this lora, in civitai's order */
|
|
729
|
-
function getLoraTriggerWords(name, hostId) {
|
|
730
|
-
const info = getLoraInfo(name, hostId);
|
|
731
|
-
return info == null ? [] : lmTrainedWords(info);
|
|
732
|
-
}
|
|
733
|
-
/** the human name (`Aurora Ink Wash`), falling back to the file's own name */
|
|
734
|
-
function getLoraDisplayName(name, hostId) {
|
|
735
|
-
const info = getLoraInfo(name, hostId);
|
|
736
|
-
return (info == null ? null : lmModelName(info)) ?? loraBasename(name);
|
|
737
|
-
}
|
|
738
|
-
function loraTriggersOf(item, p = {}) {
|
|
739
|
-
const words = lmTrainedWords(item);
|
|
740
|
-
if (words.length > 0) return {
|
|
741
|
-
state: "words",
|
|
742
|
-
words
|
|
743
|
-
};
|
|
744
|
-
const civitai = item["civitai"];
|
|
745
|
-
if (isRecord(civitai) && (typeof civitai["id"] === "number" || typeof civitai["modelId"] === "number")) return { state: "none" };
|
|
746
|
-
return p.civitaiMiss === true ? { state: "not-on-civitai" } : { state: "unfetched" };
|
|
747
|
-
}
|
|
748
|
-
function getLoraTriggers(name, hostId) {
|
|
749
|
-
const info = getLoraInfo(name, hostId);
|
|
750
|
-
if (info == null) return null;
|
|
751
|
-
const sha = lmSha256(info);
|
|
752
|
-
return loraTriggersOf(info, { civitaiMiss: hostId != null && sha != null && readCivitaiMisses(hostId)[sha] != null });
|
|
753
|
-
}
|
|
754
|
-
function civitaiMissesPath(hostId) {
|
|
755
|
-
return comfyts.resolveFromHosts(join(hostId, "lora-civitai-misses.json"));
|
|
756
|
-
}
|
|
757
|
-
/** sha256 → when civitai said it has no version for that file */
|
|
758
|
-
function readCivitaiMisses(hostId) {
|
|
759
|
-
const text = getComfyStorage().readTextIfExists(civitaiMissesPath(hostId));
|
|
760
|
-
if (text == null) return {};
|
|
761
|
-
try {
|
|
762
|
-
const raw = JSON.parse(text);
|
|
763
|
-
const out = {};
|
|
764
|
-
if (isRecord(raw)) {
|
|
765
|
-
for (const [sha, at] of Object.entries(raw)) if (typeof at === "string") out[sha] = at;
|
|
766
|
-
}
|
|
767
|
-
return out;
|
|
768
|
-
} catch (e) {
|
|
769
|
-
logError(`[loraInfoCache] unreadable ${civitaiMissesPath(hostId)}: ${String(e)}`);
|
|
770
|
-
return {};
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
function recordCivitaiMiss(p) {
|
|
774
|
-
const misses = readCivitaiMisses(p.hostId);
|
|
775
|
-
if (p.miss) misses[p.sha256] = (/* @__PURE__ */ new Date()).toISOString();
|
|
776
|
-
else delete misses[p.sha256];
|
|
777
|
-
getComfyStorage().writeText(civitaiMissesPath(p.hostId), JSON.stringify(misses, null, 2));
|
|
778
|
-
}
|
|
779
|
-
/** when the lora file landed on the host (epoch seconds), null when unsynced/unknown */
|
|
780
|
-
function getLoraAddedAt(name, hostId) {
|
|
781
|
-
const info = getLoraInfo(name, hostId);
|
|
782
|
-
return info == null ? null : lmModified(info);
|
|
783
|
-
}
|
|
784
|
-
/** server-relative preview url from the mirror, null when unsynced/unknown */
|
|
785
|
-
function getLoraPreviewUrl(name, hostId) {
|
|
786
|
-
const info = getLoraInfo(name, hostId);
|
|
787
|
-
return info == null ? null : lmPreviewUrl(info);
|
|
788
|
-
}
|
|
789
|
-
/** the lora's NAMES: the file, and the model name a human would call it by */
|
|
790
|
-
/**
|
|
791
|
-
* every lora the mirror knows for a host: its normalized KEY (comparable with `loraKey(option)`,
|
|
792
|
-
* never with a raw enum value, those keep their case, extension and windows separators) and the
|
|
793
|
-
* NAME a ComfyUI graph would load it by, rebuilt from the manager's folder + real filename.
|
|
794
|
-
* `[]` when the host was never synced.
|
|
795
|
-
*/
|
|
796
|
-
function loraMirrorEntries(hostId, p = {}) {
|
|
797
|
-
ensureLoaded();
|
|
798
|
-
const sep = p.separator ?? "/";
|
|
799
|
-
const out = [];
|
|
800
|
-
for (const [key, item] of byHost.get(hostId) ?? []) {
|
|
801
|
-
const filePath = lmFilePath(item);
|
|
802
|
-
const file = (filePath == null ? null : filePath.split(/[/\\]/).pop() ?? null) ?? lmFileName(item);
|
|
803
|
-
if (file == null) continue;
|
|
804
|
-
const folder = lmFolder(item);
|
|
805
|
-
const joined = folder === "" ? file : `${folder}/${file}`;
|
|
806
|
-
out.push({
|
|
807
|
-
key,
|
|
808
|
-
serverName: joined.replaceAll(/[\\/]/g, sep)
|
|
809
|
-
});
|
|
810
|
-
}
|
|
811
|
-
return out.sort((a, b) => a.serverName.localeCompare(b.serverName));
|
|
812
|
-
}
|
|
813
|
-
function loraSearchNames(name, hostId) {
|
|
814
|
-
const names = [loraBasename(name), name.replaceAll("\\", "/")];
|
|
815
|
-
const info = getLoraInfo(name, hostId);
|
|
816
|
-
const modelName = info == null ? null : lmModelName(info);
|
|
817
|
-
if (modelName != null) names.push(modelName);
|
|
818
|
-
return names;
|
|
819
|
-
}
|
|
820
|
-
/** the lora's FREE TEXT: tags, base model, trigger words */
|
|
821
|
-
function loraSearchText(name, hostId) {
|
|
822
|
-
const info = getLoraInfo(name, hostId);
|
|
823
|
-
if (info == null) return [];
|
|
824
|
-
const text = [...lmTags(info), ...lmTrainedWords(info)];
|
|
825
|
-
const baseModel = lmBaseModel(info);
|
|
826
|
-
if (baseModel != null) text.push(baseModel);
|
|
827
|
-
return text;
|
|
828
|
-
}
|
|
829
|
-
/**
|
|
830
|
-
* the loras overlay filter: find a lora by its human name, not only by the file
|
|
831
|
-
* name. EVERY whitespace-separated token must be a SUBSTRING of some field — order
|
|
832
|
-
* free, so `aurora ink`, `ink aurora` and `styles wash` all land on the same
|
|
833
|
-
* lora. NOT fuzzyMatch: a subsequence match over phrases this long matches
|
|
834
|
-
* nearly everything. Measured on a real collection, filtering by each lora's
|
|
835
|
-
* own file name: this rule peaks at 8 hits where fuzzyMatch matched a third of
|
|
836
|
-
* every lora present.
|
|
837
|
-
* Fields are matched one by one, never as a concatenated haystack, for the same
|
|
838
|
-
* reason. `tests/lora-corpus.private.test.ts` keeps that measurement runnable.
|
|
839
|
-
*/
|
|
840
|
-
function loraMatchesFilter(name, filter, hostId) {
|
|
841
|
-
const tokens = filter.toLowerCase().split(/\s+/).filter((t) => t !== "");
|
|
842
|
-
if (tokens.length === 0) return true;
|
|
843
|
-
const fields = [...loraSearchNames(name, hostId), ...loraSearchText(name, hostId)].map((f) => f.toLowerCase());
|
|
844
|
-
return tokens.every((token) => fields.some((field) => field.includes(token)));
|
|
845
|
-
}
|
|
846
|
-
/** the loras a host lists that the local copy of its lora manager list does not know yet:
|
|
847
|
-
* downloaded after the last sync, so they have no name, preview or trigger words here */
|
|
848
|
-
function lorasMissingFromMirror(hostLoras, inMirror) {
|
|
849
|
-
return hostLoras.filter((n) => !inMirror(n));
|
|
850
|
-
}
|
|
851
|
-
//#endregion
|
|
852
|
-
//#region src/vars/loraKeywords.ts
|
|
853
|
-
/**
|
|
854
|
-
* hand-assigned trigger keyword(s) per lora name — set via ⌃K in the TUI loras
|
|
855
|
-
* overlay, consumed by PromptVar's `loraKeywordsFrom` prefixing. Persisted at
|
|
856
|
-
* `.comfy-ts/lora-keywords.json` (NOT under cache/: this is hand-entered data
|
|
857
|
-
* and must survive a cache wipe). Observable map: overlay rows re-render on
|
|
858
|
-
* assignment. Keys are the RAW lora names (folder/file.safetensors).
|
|
859
|
-
*
|
|
860
|
-
* This file is the OVERRIDE layer. Below it sits the lora-manager mirror's
|
|
861
|
-
* civitai trigger words (src/host/loraInfoCache.ts, refreshed by
|
|
862
|
-
* `comfy-ts loras`), so most loras carry a keyword without anyone typing one.
|
|
863
|
-
* The overlay renders a mirror-sourced keyword dim and a hand-typed one yellow,
|
|
864
|
-
* and ⌃D drops the override to fall back to the mirror again.
|
|
865
|
-
*/
|
|
866
|
-
const keywords = observable.map();
|
|
867
|
-
let loaded = false;
|
|
868
|
-
function filePath() {
|
|
869
|
-
return join(comfyts.baseFolder, "lora-keywords.json");
|
|
870
|
-
}
|
|
871
|
-
function loadOnce() {
|
|
872
|
-
if (loaded) return;
|
|
873
|
-
loaded = true;
|
|
874
|
-
const path = filePath();
|
|
875
|
-
const text = getComfyStorage().readTextIfExists(path);
|
|
876
|
-
if (text == null) return;
|
|
877
|
-
try {
|
|
878
|
-
const raw = JSON.parse(text);
|
|
879
|
-
if (raw == null || typeof raw !== "object") return;
|
|
880
|
-
runInAction(() => {
|
|
881
|
-
for (const [name, kw] of Object.entries(raw)) if (typeof kw === "string") keywords.set(name, kw);
|
|
882
|
-
});
|
|
883
|
-
} catch (e) {
|
|
884
|
-
logError(`[loraKeywords] unreadable ${path}: ${String(e)}`);
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
/** the hand keyword when this lora HAS an entry (`''` included), else the mirror's trigger words */
|
|
888
|
-
function getLoraKeyword(name, hostId) {
|
|
889
|
-
loadOnce();
|
|
890
|
-
const hand = keywords.get(name);
|
|
891
|
-
if (hand != null) return hand;
|
|
892
|
-
return getLoraTriggerWords(name, hostId).join(", ");
|
|
893
|
-
}
|
|
894
|
-
/** true when the keyword shown comes from the lora-manager mirror, not from ⌃K */
|
|
895
|
-
function isLoraKeywordFromMirror(name, hostId) {
|
|
896
|
-
loadOnce();
|
|
897
|
-
return !keywords.has(name) && getLoraTriggerWords(name, hostId).length > 0;
|
|
898
|
-
}
|
|
899
|
-
/** what `clearLoraKeywordOverride` would restore this lora to, `''` when nothing */
|
|
900
|
-
function loraKeywordFromMirror(name, hostId) {
|
|
901
|
-
return getLoraTriggerWords(name, hostId).join(", ");
|
|
902
|
-
}
|
|
903
|
-
/**
|
|
904
|
-
* drop the hand entry entirely, so the mirror's trigger words apply again.
|
|
905
|
-
* The way BACK from an empty-string tombstone: without it, clearing a keyword on
|
|
906
|
-
* a lora that has trigger words was a one-way door only a text editor could undo.
|
|
907
|
-
*/
|
|
908
|
-
function clearLoraKeywordOverride(name) {
|
|
909
|
-
loadOnce();
|
|
910
|
-
if (!keywords.has(name)) return;
|
|
911
|
-
runInAction(() => void keywords.delete(name));
|
|
912
|
-
writeKeywords();
|
|
913
|
-
}
|
|
914
|
-
/**
|
|
915
|
-
* empty keyword deletes the entry — EXCEPT when the mirror has trigger words for
|
|
916
|
-
* this lora: there `''` is stored as an explicit tombstone, the only way to say
|
|
917
|
-
* "inject nothing" about a lora civitai gave words to. Every set writes the file
|
|
918
|
-
* (tiny, rare).
|
|
919
|
-
*/
|
|
920
|
-
function setLoraKeyword(name, keyword, hostId) {
|
|
921
|
-
loadOnce();
|
|
922
|
-
const trimmed = keyword.trim();
|
|
923
|
-
runInAction(() => {
|
|
924
|
-
if (trimmed === "" && getLoraTriggerWords(name, hostId).length === 0) keywords.delete(name);
|
|
925
|
-
else keywords.set(name, trimmed);
|
|
926
|
-
});
|
|
927
|
-
writeKeywords();
|
|
928
|
-
}
|
|
929
|
-
/** every set writes the file: it is tiny and hand-edited rarely */
|
|
930
|
-
function writeKeywords() {
|
|
931
|
-
const path = filePath();
|
|
932
|
-
try {
|
|
933
|
-
getComfyStorage().writeText(path, JSON.stringify(Object.fromEntries([...keywords.entries()].sort()), null, 2));
|
|
934
|
-
} catch (e) {
|
|
935
|
-
logError(`[loraKeywords] write failed ${path}: ${String(e)}`);
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
//#endregion
|
|
939
|
-
//#region src/vars/loraEntry.ts
|
|
940
|
-
function isLoraEntry(s) {
|
|
941
|
-
if (typeof s !== "object" || s == null || Array.isArray(s)) return false;
|
|
942
|
-
const o = s;
|
|
943
|
-
const st = o.strength;
|
|
944
|
-
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"));
|
|
945
|
-
}
|
|
946
|
-
function isLoraStrength(s) {
|
|
947
|
-
if (typeof s === "boolean") return true;
|
|
948
|
-
if (typeof s === "number") return Number.isFinite(s);
|
|
949
|
-
if (Array.isArray(s)) return s.length === 2 && s.every((n) => typeof n === "number" && Number.isFinite(n));
|
|
950
|
-
return isLoraEntry(s);
|
|
951
|
-
}
|
|
952
|
-
/** on = it runs */
|
|
953
|
-
function loraIsOn(s) {
|
|
954
|
-
if (s == null || s === false) return false;
|
|
955
|
-
if (isLoraEntry(s)) return s.off !== true;
|
|
956
|
-
return true;
|
|
957
|
-
}
|
|
958
|
-
/** the strengths, whatever the spelling (1/1 when there is nothing to read) */
|
|
959
|
-
function loraStrengths(s) {
|
|
960
|
-
if (typeof s === "number" && Number.isFinite(s)) return [s, s];
|
|
961
|
-
if (Array.isArray(s) && typeof s[0] === "number" && typeof s[1] === "number") return [s[0], s[1]];
|
|
962
|
-
if (isLoraEntry(s)) return [s.strength[0], s.strength[1]];
|
|
963
|
-
return [1, 1];
|
|
964
|
-
}
|
|
965
|
-
function loraMuted(s) {
|
|
966
|
-
return isLoraEntry(s) && s.mute != null ? s.mute : [];
|
|
967
|
-
}
|
|
968
|
-
/** a prompt keyword's parts, split at commas: each one can be left out on its own */
|
|
969
|
-
function keywordParts(keyword) {
|
|
970
|
-
return [...new Set(keyword.split(",").map((w) => w.trim()).filter((w) => w !== ""))];
|
|
971
|
-
}
|
|
972
|
-
/** the keyword a lora adds to the prompt once its muted parts are left out ('' = nothing) */
|
|
973
|
-
function keptKeyword(keyword, muted) {
|
|
974
|
-
return keywordParts(keyword).filter((w) => !muted.includes(w)).join(", ");
|
|
975
|
-
}
|
|
976
|
-
/** rewrite one setting, keeping what the patch does not name. The result stays in the short
|
|
977
|
-
* spellings while nothing needs the palette form, so a plain draft reads as it always did */
|
|
978
|
-
function withLora(s, patch) {
|
|
979
|
-
const strength = patch.strength ?? loraStrengths(s);
|
|
980
|
-
const off = patch.on == null ? !loraIsOn(s) : !patch.on;
|
|
981
|
-
const mute = [...patch.mute ?? loraMuted(s)];
|
|
982
|
-
if (!off && mute.length === 0) return [strength[0], strength[1]];
|
|
983
|
-
return {
|
|
984
|
-
strength: [strength[0], strength[1]],
|
|
985
|
-
...off ? { off: true } : {},
|
|
986
|
-
...mute.length === 0 ? {} : { mute }
|
|
987
|
-
};
|
|
988
|
-
}
|
|
989
|
-
//#endregion
|
|
990
|
-
//#region src/vars/lanes.ts
|
|
991
|
-
const FIRST_LANE = "main";
|
|
992
|
-
function isObject(v) {
|
|
993
|
-
return typeof v === "object" && v != null && !Array.isArray(v);
|
|
994
|
-
}
|
|
995
|
-
function isPromptLane(v) {
|
|
996
|
-
return isObject(v) && typeof v.name === "string" && typeof v.prompt === "string" && typeof v.active === "boolean";
|
|
997
|
-
}
|
|
998
|
-
function isPromptLanes(v) {
|
|
999
|
-
return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isPromptLane);
|
|
1000
|
-
}
|
|
1001
|
-
function isPromptInput(v) {
|
|
1002
|
-
return typeof v === "string" || isPromptLanes(v);
|
|
1003
|
-
}
|
|
1004
|
-
/** the text the build reads: the active lanes joined in order, one line break between them, so
|
|
1005
|
-
* `//` and `- ` lines keep working inside every lane */
|
|
1006
|
-
function promptText(v) {
|
|
1007
|
-
if (typeof v === "string") return v;
|
|
1008
|
-
return v.lanes.filter((l) => l.active).map((l) => l.prompt).join("\n");
|
|
1009
|
-
}
|
|
1010
|
-
const HEADER = /^# (.+?)( \(off\))?$/;
|
|
1011
|
-
function promptLanesToText(v) {
|
|
1012
|
-
return v.lanes.map((l) => `# ${l.name}${l.active ? "" : " (off)"}\n${l.prompt}`).join("\n");
|
|
1013
|
-
}
|
|
1014
|
-
/** text before the first header lands in a lane named FIRST_LANE, so no typed line is lost */
|
|
1015
|
-
function promptLanesFromText(text) {
|
|
1016
|
-
const lanes = [];
|
|
1017
|
-
let current = null;
|
|
1018
|
-
const body = [];
|
|
1019
|
-
const close = () => {
|
|
1020
|
-
if (current != null) lanes.push({
|
|
1021
|
-
...current,
|
|
1022
|
-
prompt: body.join("\n")
|
|
1023
|
-
});
|
|
1024
|
-
else if (body.some((l) => l.trim() !== "")) lanes.push({
|
|
1025
|
-
name: FIRST_LANE,
|
|
1026
|
-
prompt: body.join("\n"),
|
|
1027
|
-
active: true
|
|
1028
|
-
});
|
|
1029
|
-
body.length = 0;
|
|
1030
|
-
};
|
|
1031
|
-
for (const line of text.split("\n")) {
|
|
1032
|
-
const m = HEADER.exec(line);
|
|
1033
|
-
if (m == null) {
|
|
1034
|
-
body.push(line);
|
|
1035
|
-
continue;
|
|
1036
|
-
}
|
|
1037
|
-
close();
|
|
1038
|
-
current = {
|
|
1039
|
-
name: (m[1] ?? "").trim(),
|
|
1040
|
-
prompt: "",
|
|
1041
|
-
active: m[2] == null
|
|
1042
|
-
};
|
|
1043
|
-
}
|
|
1044
|
-
close();
|
|
1045
|
-
return { lanes: lanes.length > 0 ? lanes : [{
|
|
1046
|
-
name: FIRST_LANE,
|
|
1047
|
-
prompt: "",
|
|
1048
|
-
active: true
|
|
1049
|
-
}] };
|
|
1050
|
-
}
|
|
1051
|
-
function isLoraRecord(v) {
|
|
1052
|
-
return isObject(v) && !("lanes" in v) && Object.values(v).every((s) => s == null || isLoraStrength(s));
|
|
1053
|
-
}
|
|
1054
|
-
function isLoraLane(v) {
|
|
1055
|
-
return isObject(v) && typeof v.name === "string" && typeof v.active === "boolean" && isLoraRecord(v.loras);
|
|
1056
|
-
}
|
|
1057
|
-
function isLoraLanes(v) {
|
|
1058
|
-
return isObject(v) && Array.isArray(v.lanes) && v.lanes.every(isLoraLane);
|
|
1059
|
-
}
|
|
1060
|
-
function isLorasInput(v) {
|
|
1061
|
-
return isLoraRecord(v) || isLoraLanes(v);
|
|
1062
|
-
}
|
|
1063
|
-
/** one record for the build: the active lanes in order. A lora in two active lanes keeps its
|
|
1064
|
-
* FIRST setting, and `duplicates` names it so the caller can say so */
|
|
1065
|
-
function flattenLoras(v) {
|
|
1066
|
-
if (!isLoraLanes(v)) return {
|
|
1067
|
-
record: v,
|
|
1068
|
-
duplicates: []
|
|
1069
|
-
};
|
|
1070
|
-
const record = {};
|
|
1071
|
-
const duplicates = [];
|
|
1072
|
-
for (const lane of v.lanes) {
|
|
1073
|
-
if (!lane.active) continue;
|
|
1074
|
-
for (const [name, st] of Object.entries(lane.loras)) {
|
|
1075
|
-
if (st == null) continue;
|
|
1076
|
-
if (name in record) duplicates.push(name);
|
|
1077
|
-
else record[name] = st;
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
return {
|
|
1081
|
-
record,
|
|
1082
|
-
duplicates
|
|
1083
|
-
};
|
|
1084
|
-
}
|
|
1085
|
-
/** where a lora lives, so an edit lands in the lane that holds it: the first ACTIVE lane that
|
|
1086
|
-
* has it (the one the build reads), else any lane, else -1 */
|
|
1087
|
-
function laneIndexOf(v, name) {
|
|
1088
|
-
const active = v.lanes.findIndex((l) => l.active && l.loras[name] != null);
|
|
1089
|
-
return active !== -1 ? active : v.lanes.findIndex((l) => l.loras[name] != null);
|
|
1090
|
-
}
|
|
1091
|
-
/** rewrite one lora's setting wherever it lives (plain record, or its lane). `null` removes it.
|
|
1092
|
-
* A lora in no lane yet lands in the first lane */
|
|
1093
|
-
function updateLora(v, name, next) {
|
|
1094
|
-
const write = (rec) => {
|
|
1095
|
-
const out = { ...rec };
|
|
1096
|
-
if (next == null) delete out[name];
|
|
1097
|
-
else out[name] = next;
|
|
1098
|
-
return out;
|
|
1099
|
-
};
|
|
1100
|
-
if (!isLoraLanes(v)) return write(v);
|
|
1101
|
-
if (v.lanes.length === 0) return { lanes: [{
|
|
1102
|
-
name: FIRST_LANE,
|
|
1103
|
-
active: true,
|
|
1104
|
-
loras: write({})
|
|
1105
|
-
}] };
|
|
1106
|
-
const found = laneIndexOf(v, name);
|
|
1107
|
-
const ix = found === -1 ? 0 : found;
|
|
1108
|
-
return { lanes: v.lanes.map((l, i) => i === ix ? {
|
|
1109
|
-
...l,
|
|
1110
|
-
loras: write(l.loras)
|
|
1111
|
-
} : l) };
|
|
1112
|
-
}
|
|
1113
|
-
//#endregion
|
|
1114
|
-
//#region src/vars/promptSyntax.ts
|
|
1115
|
-
/** a whole line that is a comment (the TUI colors these) */
|
|
1116
|
-
const COMMENT_LINE_RE = /^\s*\/\//;
|
|
1117
|
-
/** a negative prompt line: `- ` then its text */
|
|
1118
|
-
const NEGATIVE_LINE_RE = /^\s*- (.*)$/;
|
|
1119
|
-
const NEGATIVE_PREFIX_RE = /^(\s*)- /;
|
|
1120
|
-
/** where a `//` comment starts on this line, -1 when none. Only at line start or after
|
|
1121
|
-
* whitespace, so `http://host` is never cut */
|
|
1122
|
-
function commentStart(line) {
|
|
1123
|
-
const m = /(?:^|\s)\/\//.exec(line);
|
|
1124
|
-
if (m == null) return -1;
|
|
1125
|
-
return m.index + m[0].length - 2;
|
|
1126
|
-
}
|
|
1127
|
-
/** the line without its comment, trailing whitespace dropped with it */
|
|
1128
|
-
function withoutComment(line) {
|
|
1129
|
-
const c = commentStart(line);
|
|
1130
|
-
return c < 0 ? {
|
|
1131
|
-
text: line,
|
|
1132
|
-
hadComment: false
|
|
1133
|
-
} : {
|
|
1134
|
-
text: line.slice(0, c).trimEnd(),
|
|
1135
|
-
hadComment: true
|
|
1136
|
-
};
|
|
1137
|
-
}
|
|
1138
|
-
/** the build's reading of a prompt: comments out, `- ` lines comma-joined into the negative */
|
|
1139
|
-
function parsePromptText(text) {
|
|
1140
|
-
const pos = [];
|
|
1141
|
-
const neg = [];
|
|
1142
|
-
for (const raw of text.split("\n")) {
|
|
1143
|
-
const cut = withoutComment(raw);
|
|
1144
|
-
if (cut.hadComment && cut.text.trim() === "") continue;
|
|
1145
|
-
const m = NEGATIVE_PREFIX_RE.exec(raw);
|
|
1146
|
-
if (m != null && m[0].length <= cut.text.length + 1) {
|
|
1147
|
-
const body = cut.text.slice(m[0].length).trim();
|
|
1148
|
-
if (body !== "") neg.push(body);
|
|
1149
|
-
} else pos.push(cut.text);
|
|
1150
|
-
}
|
|
1151
|
-
return {
|
|
1152
|
-
positive: pos.join("\n").trim(),
|
|
1153
|
-
negative: neg.join(", ")
|
|
1154
|
-
};
|
|
1155
|
-
}
|
|
1156
|
-
//#endregion
|
|
1157
|
-
//#region src/vars/presets.ts
|
|
1158
|
-
function toPresetList(spec) {
|
|
1159
|
-
if (spec == null) return [];
|
|
1160
|
-
return Object.entries(spec).map(([label, text]) => ({
|
|
1161
|
-
label,
|
|
1162
|
-
text
|
|
1163
|
-
}));
|
|
1164
|
-
}
|
|
1165
|
-
//#endregion
|
|
1166
|
-
//#region src/vars/ComfyVars.ts
|
|
1167
|
-
var ComfyVarBase = class {
|
|
1168
|
-
constructor(defaultValue, label) {
|
|
1169
|
-
this.defaultValue = defaultValue;
|
|
1170
|
-
this.label = label;
|
|
1171
|
-
this.uiOpts = {};
|
|
1172
|
-
this.value = defaultValue;
|
|
1173
|
-
makeObservable(this, {
|
|
1174
|
-
value: observable,
|
|
1175
|
-
set: action,
|
|
1176
|
-
reset: action,
|
|
1177
|
-
parse: action,
|
|
1178
|
-
loadJSON: action
|
|
1179
|
-
});
|
|
1180
|
-
}
|
|
1181
|
-
set(value) {
|
|
1182
|
-
this.value = value;
|
|
1183
|
-
return this;
|
|
1184
|
-
}
|
|
1185
|
-
/** chainable: `v.choice([...], 'a').ui({ icon: 'M4 12h16', color: '#e0af68' })` */
|
|
1186
|
-
ui(p) {
|
|
1187
|
-
this.uiOpts = {
|
|
1188
|
-
...this.uiOpts,
|
|
1189
|
-
...p
|
|
1190
|
-
};
|
|
1191
|
-
return this;
|
|
1192
|
-
}
|
|
1193
|
-
/** what drafts persist for this var (subclasses may add fields, e.g. seed mode) */
|
|
1194
|
-
toJSON() {
|
|
1195
|
-
return this.value;
|
|
1196
|
-
}
|
|
1197
|
-
/**
|
|
1198
|
-
* restore a value produced by toJSON() (drafts). The cast is sanctioned:
|
|
1199
|
-
* drafts are our own round-trip, subclasses re-validate via set().
|
|
1200
|
-
*/
|
|
1201
|
-
loadJSON(value) {
|
|
1202
|
-
return this.set(value);
|
|
1203
|
-
}
|
|
1204
|
-
reset() {
|
|
1205
|
-
this.value = this.defaultValue;
|
|
1206
|
-
return this;
|
|
1207
|
-
}
|
|
1208
|
-
/** how the value renders in a var list */
|
|
1209
|
-
display() {
|
|
1210
|
-
return String(this.value);
|
|
1211
|
-
}
|
|
1212
|
-
/** the string the inline editor starts from (round-trips through parse) */
|
|
1213
|
-
toEditBuffer() {
|
|
1214
|
-
return String(this.value);
|
|
1215
|
-
}
|
|
1216
|
-
/** hook run after every DefinedWorkflow.run() (default no-op; SeedVar advances) */
|
|
1217
|
-
afterRun() {}
|
|
1218
|
-
};
|
|
1219
|
-
/** the standard var: the graph consumes the stored value AS-IS (Out = T) */
|
|
1220
|
-
var ComfyVar = class extends ComfyVarBase {
|
|
1221
|
-
outValue() {
|
|
1222
|
-
return this.value;
|
|
1223
|
-
}
|
|
1224
|
-
};
|
|
1225
|
-
var TextVar = class extends ComfyVar {
|
|
1226
|
-
/** a bare label string was the whole second parameter before opts existed: a published
|
|
1227
|
-
* consumer passing one must keep working, exactly as SeedVar does */
|
|
1228
|
-
constructor(defaultValue, opts = {}) {
|
|
1229
|
-
const o = typeof opts === "string" ? { label: opts } : opts;
|
|
1230
|
-
super(defaultValue, o.label);
|
|
1231
|
-
this.kind = "text";
|
|
1232
|
-
this.opts = o;
|
|
1233
|
-
this.presets = toPresetList(o.presets);
|
|
1234
|
-
}
|
|
1235
|
-
parse(raw) {
|
|
1236
|
-
this.set(raw);
|
|
1237
|
-
return true;
|
|
1238
|
-
}
|
|
1239
|
-
};
|
|
1240
|
-
/**
|
|
1241
|
-
* prompt text with editor comforts, all resolved at BUILD time (the editor and
|
|
1242
|
-
* drafts keep the raw text):
|
|
1243
|
-
* - `//` starts a COMMENT to the end of the line (src/vars/promptSyntax.ts) — stripped
|
|
1244
|
-
* - `- ` lines are NEGATIVE prompt lines — removed from `.positive`,
|
|
1245
|
-
* comma-joined into `.negative`
|
|
1246
|
-
* - with `loraKeywordsFrom`, the ACTIVE loras' hand-assigned keywords
|
|
1247
|
-
* (src/vars/loraKeywords.ts, ⌃K in the TUI) prefix `.positive` —
|
|
1248
|
-
* `injectedKeywords()` is public so the TUI can PREVIEW the injection.
|
|
1249
|
-
*/
|
|
1250
|
-
var PromptVar = class extends ComfyVarBase {
|
|
1251
|
-
constructor(defaultValue, promptOpts = {}) {
|
|
1252
|
-
super(defaultValue, promptOpts.label);
|
|
1253
|
-
this.promptOpts = promptOpts;
|
|
1254
|
-
this.kind = "prompt";
|
|
1255
|
-
this.presets = toPresetList(promptOpts.presets);
|
|
1256
|
-
}
|
|
1257
|
-
/** in lanes mode the text carries `# name` headers, so a lane survives a round trip */
|
|
1258
|
-
parse(raw) {
|
|
1259
|
-
this.set(isPromptLanes(this.value) ? promptLanesFromText(raw) : raw);
|
|
1260
|
-
return true;
|
|
1261
|
-
}
|
|
1262
|
-
toEditBuffer() {
|
|
1263
|
-
return isPromptLanes(this.value) ? promptLanesToText(this.value) : this.value;
|
|
1264
|
-
}
|
|
1265
|
-
/** a var list shows the lanes by name, the inactive ones in parentheses */
|
|
1266
|
-
display() {
|
|
1267
|
-
if (!isPromptLanes(this.value)) return super.display();
|
|
1268
|
-
return `${this.value.lanes.length} lanes: ${this.value.lanes.map((l) => l.active ? l.name : `(${l.name})`).join(", ")}`;
|
|
1269
|
-
}
|
|
1270
|
-
/** the text the build reads: the plain string, or the active lanes joined in order */
|
|
1271
|
-
get text() {
|
|
1272
|
-
return promptText(this.value);
|
|
1273
|
-
}
|
|
1274
|
-
/** the tag list options in their one object form, null when this prompt has no completion */
|
|
1275
|
-
get tags() {
|
|
1276
|
-
const t = this.promptOpts.tags;
|
|
1277
|
-
if (t == null) return null;
|
|
1278
|
-
return typeof t === "string" ? { url: t } : t;
|
|
1279
|
-
}
|
|
1280
|
-
static isCommentLine(line) {
|
|
1281
|
-
return COMMENT_LINE_RE.test(line);
|
|
1282
|
-
}
|
|
1283
|
-
static isNegativeLine(line) {
|
|
1284
|
-
return NEGATIVE_LINE_RE.test(line);
|
|
1285
|
-
}
|
|
1286
|
-
/** the keyword prefix the flag will inject (deduped, lora-list order) — the TUI previews this */
|
|
1287
|
-
injectedKeywords() {
|
|
1288
|
-
const src = this.promptOpts.loraKeywordsFrom;
|
|
1289
|
-
if (src == null) return [];
|
|
1290
|
-
return [...new Set(src.activeNames().map((name) => keptKeyword(getLoraKeyword(name, src.hostId), src.mutedWords?.(name) ?? [])).filter((k) => k !== ""))];
|
|
1291
|
-
}
|
|
1292
|
-
outValue() {
|
|
1293
|
-
const parsed = parsePromptText(this.text);
|
|
1294
|
-
const body = parsed.positive;
|
|
1295
|
-
const keywords = this.injectedKeywords();
|
|
1296
|
-
return {
|
|
1297
|
-
positive: keywords.length === 0 ? body : body === "" ? keywords.join(", ") : `${keywords.join(", ")}, ${body}`,
|
|
1298
|
-
negative: parsed.negative
|
|
1299
|
-
};
|
|
1300
|
-
}
|
|
1301
|
-
};
|
|
1302
|
-
var IntVar = class extends ComfyVar {
|
|
1303
|
-
constructor(defaultValue, opts = {}) {
|
|
1304
|
-
super(defaultValue, opts.label);
|
|
1305
|
-
this.opts = opts;
|
|
1306
|
-
this.kind = "int";
|
|
1307
|
-
}
|
|
1308
|
-
set(value) {
|
|
1309
|
-
const clamped = Math.round(Math.min(this.opts.max ?? Infinity, Math.max(this.opts.min ?? -Infinity, value)));
|
|
1310
|
-
return super.set(clamped);
|
|
1311
|
-
}
|
|
1312
|
-
parse(raw) {
|
|
1313
|
-
const n = Number(raw);
|
|
1314
|
-
if (Number.isNaN(n)) return false;
|
|
1315
|
-
this.set(n);
|
|
1316
|
-
return true;
|
|
1317
|
-
}
|
|
1318
|
-
};
|
|
1319
|
-
var FloatVar = class extends ComfyVar {
|
|
1320
|
-
constructor(defaultValue, opts = {}) {
|
|
1321
|
-
super(defaultValue, opts.label);
|
|
1322
|
-
this.opts = opts;
|
|
1323
|
-
this.kind = "float";
|
|
1324
|
-
}
|
|
1325
|
-
set(value) {
|
|
1326
|
-
return super.set(Math.min(this.opts.max ?? Infinity, Math.max(this.opts.min ?? -Infinity, value)));
|
|
1327
|
-
}
|
|
1328
|
-
parse(raw) {
|
|
1329
|
-
const n = Number(raw);
|
|
1330
|
-
if (Number.isNaN(n)) return false;
|
|
1331
|
-
this.set(n);
|
|
1332
|
-
return true;
|
|
1333
|
-
}
|
|
1334
|
-
};
|
|
1335
|
-
/**
|
|
1336
|
-
* a seed is a MODE + a number. `value` stays a plain number (what the graph
|
|
1337
|
-
* consumes); `mode` decides how it advances after each run (afterRun()):
|
|
1338
|
-
* `= 12` fixed · `+ 0` auto-increment · `- 0` auto-decrement · `? 0` random.
|
|
1339
|
-
* The number shown is always the seed the NEXT run will use.
|
|
1340
|
-
*/
|
|
1341
|
-
var SeedVar = class extends ComfyVar {
|
|
1342
|
-
/** `opts` is the modern shape; a bare label string stays accepted, since that was the
|
|
1343
|
-
* signature before a workflow could declare the mode it wants to run in */
|
|
1344
|
-
constructor(defaultValue = 0, opts = {}) {
|
|
1345
|
-
const o = typeof opts === "string" ? { label: opts } : opts;
|
|
1346
|
-
super(defaultValue, o.label);
|
|
1347
|
-
this.kind = "seed";
|
|
1348
|
-
this.mode = o.mode ?? "=";
|
|
1349
|
-
this.defaultMode = this.mode;
|
|
1350
|
-
makeObservable(this, {
|
|
1351
|
-
mode: observable,
|
|
1352
|
-
setMode: action,
|
|
1353
|
-
randomize: action,
|
|
1354
|
-
advance: action
|
|
1355
|
-
});
|
|
1356
|
-
}
|
|
1357
|
-
setMode(mode) {
|
|
1358
|
-
this.mode = mode;
|
|
1359
|
-
return this;
|
|
1360
|
-
}
|
|
1361
|
-
randomize() {
|
|
1362
|
-
return this.set(Math.floor(Math.random() * 2 ** 32));
|
|
1363
|
-
}
|
|
1364
|
-
set(value) {
|
|
1365
|
-
return super.set(Math.max(0, Math.floor(value)));
|
|
1366
|
-
}
|
|
1367
|
-
/** move the seed to what the NEXT run should use, per mode */
|
|
1368
|
-
advance() {
|
|
1369
|
-
if (this.mode === "+") return this.set(this.value + 1);
|
|
1370
|
-
if (this.mode === "-") return this.set(this.value - 1);
|
|
1371
|
-
if (this.mode === "?") return this.randomize();
|
|
1372
|
-
return this;
|
|
1373
|
-
}
|
|
1374
|
-
afterRun() {
|
|
1375
|
-
this.advance();
|
|
1376
|
-
}
|
|
1377
|
-
/** mode is part of the seed's state: a reset must not keep a caller's `?`/`+` alive
|
|
1378
|
-
* ('=' is the construction default; drafts restore their own mode via loadJSON) */
|
|
1379
|
-
reset() {
|
|
1380
|
-
this.setMode(this.defaultMode);
|
|
1381
|
-
return super.reset();
|
|
1382
|
-
}
|
|
1383
|
-
/** parse `+` `- 12` `= 5` `?` or a bare number (=> fixed). Keeps the current number when none given */
|
|
1384
|
-
parse(raw) {
|
|
1385
|
-
const m = raw.trim().match(/^([+\-=?])?\s*(\d+)?$/);
|
|
1386
|
-
if (m == null) return false;
|
|
1387
|
-
const modeChar = m[1];
|
|
1388
|
-
const numStr = m[2];
|
|
1389
|
-
if (modeChar == null && numStr == null) return false;
|
|
1390
|
-
this.setMode(modeChar == null ? "=" : modeChar);
|
|
1391
|
-
if (numStr != null) this.set(Number(numStr));
|
|
1392
|
-
return true;
|
|
1393
|
-
}
|
|
1394
|
-
display() {
|
|
1395
|
-
return `${this.mode} ${this.value}`;
|
|
1396
|
-
}
|
|
1397
|
-
toEditBuffer() {
|
|
1398
|
-
return `${this.mode} ${this.value}`;
|
|
1399
|
-
}
|
|
1400
|
-
toJSON() {
|
|
1401
|
-
return {
|
|
1402
|
-
mode: this.mode,
|
|
1403
|
-
value: this.value
|
|
1404
|
-
};
|
|
1405
|
-
}
|
|
1406
|
-
loadJSON(value) {
|
|
1407
|
-
if (typeof value === "number") return this.set(value);
|
|
1408
|
-
if (value != null && typeof value === "object") {
|
|
1409
|
-
const o = value;
|
|
1410
|
-
if (o.mode === "=" || o.mode === "+" || o.mode === "-" || o.mode === "?") this.setMode(o.mode);
|
|
1411
|
-
if (typeof o.value === "number") this.set(o.value);
|
|
1412
|
-
}
|
|
1413
|
-
return this;
|
|
1414
|
-
}
|
|
1415
|
-
};
|
|
1416
|
-
var ToggleVar = class extends ComfyVar {
|
|
1417
|
-
constructor(..._args) {
|
|
1418
|
-
super(..._args);
|
|
1419
|
-
this.kind = "toggle";
|
|
1420
|
-
}
|
|
1421
|
-
toggle() {
|
|
1422
|
-
return this.set(!this.value);
|
|
1423
|
-
}
|
|
1424
|
-
parse(raw) {
|
|
1425
|
-
if (raw !== "true" && raw !== "false") return false;
|
|
1426
|
-
this.set(raw === "true");
|
|
1427
|
-
return true;
|
|
1428
|
-
}
|
|
1429
|
-
display() {
|
|
1430
|
-
return this.value ? "ON" : "OFF";
|
|
1431
|
-
}
|
|
1432
|
-
};
|
|
1433
|
-
/** a fixed list, or the host's list for one slot once bindHost ran */
|
|
1434
|
-
var ChoiceList = class {
|
|
1435
|
-
constructor(source) {
|
|
1436
|
-
this.source = source;
|
|
1437
|
-
this.resolved = null;
|
|
1438
|
-
}
|
|
1439
|
-
get slot() {
|
|
1440
|
-
return isChoiceList(this.source) ? null : this.source;
|
|
1441
|
-
}
|
|
1442
|
-
get choices() {
|
|
1443
|
-
if (isChoiceList(this.source)) return this.source;
|
|
1444
|
-
if (this.resolved == null) 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)`);
|
|
1445
|
-
return this.resolved;
|
|
1446
|
-
}
|
|
1447
|
-
/** cast: whitelist family 1 (agent/coding.md) — stringValues() returns the runtime values of
|
|
1448
|
-
* the SAME object_info enum the generated slot union comes from */
|
|
1449
|
-
bind(host) {
|
|
1450
|
-
const src = this.slot;
|
|
1451
|
-
if (src == null) return;
|
|
1452
|
-
const all = host.schema.stringValues(src.slot);
|
|
1453
|
-
const filter = src.filter == null ? null : statelessRegex(src.filter);
|
|
1454
|
-
this.resolved = filter == null ? all : all.filter((n) => filter.test(n));
|
|
1455
|
-
}
|
|
1456
|
-
};
|
|
1457
|
-
var ChoiceVar = class extends ComfyVar {
|
|
1458
|
-
constructor(choices, defaultValue, label) {
|
|
1459
|
-
super(defaultValue, label);
|
|
1460
|
-
this.kind = "choice";
|
|
1461
|
-
this.select = "one";
|
|
1462
|
-
this.list = new ChoiceList(choices);
|
|
1463
|
-
}
|
|
1464
|
-
get choices() {
|
|
1465
|
-
return this.list.choices;
|
|
1466
|
-
}
|
|
1467
|
-
/** set for `v.model`: the loader input this choice lists */
|
|
1468
|
-
get hostSlot() {
|
|
1469
|
-
return this.list.slot;
|
|
1470
|
-
}
|
|
1471
|
-
bindHost(host) {
|
|
1472
|
-
this.list.bind(host);
|
|
1473
|
-
}
|
|
1474
|
-
next(delta = 1) {
|
|
1475
|
-
const nextIx = (this.choices.indexOf(this.value) + delta + this.choices.length) % this.choices.length;
|
|
1476
|
-
return this.set(this.choices[nextIx] ?? this.value);
|
|
1477
|
-
}
|
|
1478
|
-
parse(raw) {
|
|
1479
|
-
const hit = this.choices.find((c) => c === raw);
|
|
1480
|
-
if (hit == null) return false;
|
|
1481
|
-
this.set(hit);
|
|
1482
|
-
return true;
|
|
1483
|
-
}
|
|
1484
|
-
};
|
|
1485
|
-
/** one option or none: `null` is "nothing picked", clicking the lit option clears it */
|
|
1486
|
-
var OptionalChoiceVar = class extends ComfyVar {
|
|
1487
|
-
constructor(choices, defaultValue, label) {
|
|
1488
|
-
super(defaultValue, label);
|
|
1489
|
-
this.kind = "choice";
|
|
1490
|
-
this.select = "zero-or-one";
|
|
1491
|
-
this.list = new ChoiceList(choices);
|
|
1492
|
-
}
|
|
1493
|
-
get choices() {
|
|
1494
|
-
return this.list.choices;
|
|
1495
|
-
}
|
|
1496
|
-
get hostSlot() {
|
|
1497
|
-
return this.list.slot;
|
|
1498
|
-
}
|
|
1499
|
-
bindHost(host) {
|
|
1500
|
-
this.list.bind(host);
|
|
1501
|
-
}
|
|
1502
|
-
/** pick `c`, or clear it when it is already the one picked */
|
|
1503
|
-
toggle(c) {
|
|
1504
|
-
return this.set(this.value === c ? null : c);
|
|
1505
|
-
}
|
|
1506
|
-
/** the TUI text form: a choice, or an empty line for none */
|
|
1507
|
-
parse(raw) {
|
|
1508
|
-
if (raw.trim() === "") {
|
|
1509
|
-
this.set(null);
|
|
1510
|
-
return true;
|
|
1511
|
-
}
|
|
1512
|
-
const hit = this.choices.find((c) => c === raw.trim());
|
|
1513
|
-
if (hit == null) return false;
|
|
1514
|
-
this.set(hit);
|
|
1515
|
-
return true;
|
|
1516
|
-
}
|
|
1517
|
-
toEditBuffer() {
|
|
1518
|
-
return this.value ?? "";
|
|
1519
|
-
}
|
|
1520
|
-
/** a draft from when this was a many choice holds a list: its first known option */
|
|
1521
|
-
loadJSON(value) {
|
|
1522
|
-
const one = Array.isArray(value) ? value[0] : value;
|
|
1523
|
-
return this.set(this.choices.find((c) => c === one) ?? null);
|
|
1524
|
-
}
|
|
1525
|
-
display() {
|
|
1526
|
-
return this.value ?? "none";
|
|
1527
|
-
}
|
|
1528
|
-
};
|
|
1529
|
-
/** any number of options, kept in the order the choices list them */
|
|
1530
|
-
var MultiChoiceVar = class extends ComfyVar {
|
|
1531
|
-
constructor(choices, defaultValue, label) {
|
|
1532
|
-
super([...defaultValue], label);
|
|
1533
|
-
this.choices = choices;
|
|
1534
|
-
this.kind = "choice";
|
|
1535
|
-
this.select = "many";
|
|
1536
|
-
}
|
|
1537
|
-
toggle(c) {
|
|
1538
|
-
const on = this.value.includes(c);
|
|
1539
|
-
return this.set(this.choices.filter((x) => x === c ? !on : this.value.includes(x)));
|
|
1540
|
-
}
|
|
1541
|
-
/** the TUI text form: `a, b` */
|
|
1542
|
-
parse(raw) {
|
|
1543
|
-
const wanted = raw.split(",").map((w) => w.trim()).filter((w) => w !== "");
|
|
1544
|
-
const picked = this.choices.filter((c) => wanted.includes(c));
|
|
1545
|
-
if (picked.length !== new Set(wanted).size) return false;
|
|
1546
|
-
this.set(picked);
|
|
1547
|
-
return true;
|
|
1548
|
-
}
|
|
1549
|
-
toEditBuffer() {
|
|
1550
|
-
return this.value.join(", ");
|
|
1551
|
-
}
|
|
1552
|
-
/** a draft from when this was a single choice holds one value: a list of one. Unknown
|
|
1553
|
-
* options are dropped, the list comes back in the choices order */
|
|
1554
|
-
loadJSON(value) {
|
|
1555
|
-
const listed = Array.isArray(value) ? value : value == null ? [] : [value];
|
|
1556
|
-
return this.set(this.choices.filter((c) => listed.includes(c)));
|
|
1557
|
-
}
|
|
1558
|
-
display() {
|
|
1559
|
-
return this.value.length === 0 ? "none" : this.value.join(", ");
|
|
1560
|
-
}
|
|
1561
|
-
};
|
|
1562
|
-
/** Array.isArray does not narrow a READONLY array out of a union, this does */
|
|
1563
|
-
function isChoiceList(v) {
|
|
1564
|
-
return Array.isArray(v);
|
|
1565
|
-
}
|
|
1566
|
-
function choice(choices, defaultValue, opts) {
|
|
1567
|
-
const o = typeof opts === "string" ? { label: opts } : opts ?? {};
|
|
1568
|
-
const select = o.select ?? "one";
|
|
1569
|
-
if (select === "many") {
|
|
1570
|
-
if (!isChoiceList(defaultValue)) throw new Error(`a 'many' choice takes a list as its default, got ${String(defaultValue)}`);
|
|
1571
|
-
return new MultiChoiceVar(choices, defaultValue, o.label);
|
|
1572
|
-
}
|
|
1573
|
-
if (isChoiceList(defaultValue)) throw new Error(`a '${select}' choice takes one value as its default, not a list`);
|
|
1574
|
-
if (select === "zero-or-one") return new OptionalChoiceVar(choices, defaultValue, o.label);
|
|
1575
|
-
if (defaultValue == null) throw new Error("a 'one' choice needs a default: use { select: 'zero-or-one' } for none");
|
|
1576
|
-
return new ChoiceVar(choices, defaultValue, o.label);
|
|
1577
|
-
}
|
|
1578
|
-
function model(slot, opts) {
|
|
1579
|
-
const source = {
|
|
1580
|
-
slot,
|
|
1581
|
-
filter: opts.filter
|
|
1582
|
-
};
|
|
1583
|
-
if (opts.default == null) return new OptionalChoiceVar(source, null, opts.label);
|
|
1584
|
-
return new ChoiceVar(source, opts.default, opts.label);
|
|
1585
|
-
}
|
|
1586
|
-
/**
|
|
1587
|
-
* multi-select lora stack over a DYNAMIC options list — a RegExp resolves
|
|
1588
|
-
* against the host's loras at define time (DefinedWorkflow calls bindHost),
|
|
1589
|
-
* or feed it host discovery (`host.schema.getLoras(regex?)`) directly; never
|
|
1590
|
-
* a hardcoded inventory. Selection is empty by default.
|
|
1591
|
-
*/
|
|
1592
|
-
/**
|
|
1593
|
-
* the value is EITHER a plain record OR `{ lanes: [...] }` (src/vars/lanes.ts): named groups the
|
|
1594
|
-
* build merges in listed order, skipping inactive ones. Every method reads the merged record and
|
|
1595
|
-
* writes into the lane that holds the lora, so the TUI never needs to know lanes exist
|
|
1596
|
-
*/
|
|
1597
|
-
var LorasVar = class LorasVar extends ComfyVarBase {
|
|
1598
|
-
constructor(optionsSource, initial = {}, label) {
|
|
1599
|
-
super(initial, label);
|
|
1600
|
-
this.optionsSource = optionsSource;
|
|
1601
|
-
this.kind = "loras";
|
|
1602
|
-
this.prev = {};
|
|
1603
|
-
this.resolvedOptions = null;
|
|
1604
|
-
this.hostId = void 0;
|
|
1605
|
-
}
|
|
1606
|
-
/** the filter the workflow declared, when it declared one (`v.loras(/krea-?2/i)`). Public so
|
|
1607
|
-
* a UI can SHOW it, and so serve applies the same narrowing to loras only its lora-manager
|
|
1608
|
-
* mirror knows, an unfiltered union would put the whole catalog back in a filtered picker */
|
|
1609
|
-
get optionsFilter() {
|
|
1610
|
-
return this.optionsSource instanceof RegExp ? this.optionsSource : null;
|
|
1611
|
-
}
|
|
1612
|
-
get options() {
|
|
1613
|
-
if (!(this.optionsSource instanceof RegExp)) return this.optionsSource;
|
|
1614
|
-
if (this.resolvedOptions == null) throw new Error(`v.loras(${String(this.optionsSource)}) is host-bound — it only works inside defineWorkflow({ vars }) (pass a name list otherwise)`);
|
|
1615
|
-
return this.resolvedOptions;
|
|
1616
|
-
}
|
|
1617
|
-
/** DefinedWorkflow binds the host at define time: a RegExp source resolves here.
|
|
1618
|
-
* cast: whitelist family 1 (agent/coding.md) — getLoras() returns the runtime
|
|
1619
|
-
* values of the SAME object_info enum the generated E_LoraName union comes from */
|
|
1620
|
-
bindHost(host) {
|
|
1621
|
-
this.hostId = host.data?.id;
|
|
1622
|
-
if (!(this.optionsSource instanceof RegExp)) return;
|
|
1623
|
-
this.resolvedOptions = host.schema.getLoras(this.optionsSource);
|
|
1624
|
-
}
|
|
1625
|
-
get names() {
|
|
1626
|
-
return [...this.options];
|
|
1627
|
-
}
|
|
1628
|
-
/** the loras the build reads: the plain record, or the active lanes merged in order */
|
|
1629
|
-
get record() {
|
|
1630
|
-
return flattenLoras(this.value).record;
|
|
1631
|
-
}
|
|
1632
|
-
/** what the graph consumes. A lora in two active lanes runs once, with its FIRST setting */
|
|
1633
|
-
outValue() {
|
|
1634
|
-
const flat = flattenLoras(this.value);
|
|
1635
|
-
if (flat.duplicates.length > 0) logError(`loras var '${this.name ?? this.label ?? "?"}': ${flat.duplicates.join(", ")} sit in two active lanes, the first lane's setting is used`);
|
|
1636
|
-
return flat.record;
|
|
1637
|
-
}
|
|
1638
|
-
/** rewrite one lora wherever it lives: the plain record, or the lane that holds it */
|
|
1639
|
-
write(name, next) {
|
|
1640
|
-
return this.set(updateLora(this.value, name, next));
|
|
1641
|
-
}
|
|
1642
|
-
/** the parts of this lora's prompt keyword left out of the prompt */
|
|
1643
|
-
mutedWords(name) {
|
|
1644
|
-
return loraMuted(this.record[name]);
|
|
1645
|
-
}
|
|
1646
|
-
/** loras currently ON (PromptVar keyword prefixing consumes this) */
|
|
1647
|
-
activeNames() {
|
|
1648
|
-
return this.names.filter((n) => this.isOn(n));
|
|
1649
|
-
}
|
|
1650
|
-
isOn(name) {
|
|
1651
|
-
return loraIsOn(this.record[name]);
|
|
1652
|
-
}
|
|
1653
|
-
toggleItem(name) {
|
|
1654
|
-
const cur = this.record[name];
|
|
1655
|
-
if (cur == null || cur === false) return this.write(name, this.prev[name] ?? true);
|
|
1656
|
-
if (!loraIsOn(cur)) return this.write(name, withLora(cur, { on: true }));
|
|
1657
|
-
this.prev[name] = cur;
|
|
1658
|
-
return this.write(name, false);
|
|
1659
|
-
}
|
|
1660
|
-
/** step both strengths by delta (true becomes 1 first); no-op when off */
|
|
1661
|
-
adjustItem(name, delta) {
|
|
1662
|
-
const cur = this.record[name];
|
|
1663
|
-
if (!loraIsOn(cur)) return this;
|
|
1664
|
-
const step = (n) => Math.max(0, Math.round((n + delta) * 100) / 100);
|
|
1665
|
-
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])] });
|
|
1666
|
-
return this.write(name, next);
|
|
1667
|
-
}
|
|
1668
|
-
/** compact per-item strength label for lists */
|
|
1669
|
-
strengthLabel(name) {
|
|
1670
|
-
const s = this.record[name];
|
|
1671
|
-
if (!loraIsOn(s)) return "";
|
|
1672
|
-
const [m, c] = loraStrengths(s);
|
|
1673
|
-
return m === c ? m.toFixed(2) : `m:${m.toFixed(2)} c:${c.toFixed(2)}`;
|
|
1674
|
-
}
|
|
1675
|
-
parse(raw) {
|
|
1676
|
-
try {
|
|
1677
|
-
const parsed = JSON.parse(raw);
|
|
1678
|
-
if (!isLorasInput(parsed)) return false;
|
|
1679
|
-
this.set(parsed);
|
|
1680
|
-
return true;
|
|
1681
|
-
} catch {
|
|
1682
|
-
return false;
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
/** short human name: subfolder + extension stripped */
|
|
1686
|
-
static shortName(name) {
|
|
1687
|
-
return (name.split(/[\\/]/).pop() ?? name).replace(/\.safetensors$/, "");
|
|
1688
|
-
}
|
|
1689
|
-
/** tick (true) or untick (false) every lora in `names` (default: all options) */
|
|
1690
|
-
setAll(on, names = this.options) {
|
|
1691
|
-
const record = this.record;
|
|
1692
|
-
let next = this.value;
|
|
1693
|
-
for (const name of names) {
|
|
1694
|
-
const cur = record[name];
|
|
1695
|
-
if (on) {
|
|
1696
|
-
if (cur == null || cur === false) next = updateLora(next, name, this.prev[name] ?? true);
|
|
1697
|
-
else if (!loraIsOn(cur)) next = updateLora(next, name, withLora(cur, { on: true }));
|
|
1698
|
-
} else {
|
|
1699
|
-
if (loraIsOn(cur)) this.prev[name] = cur;
|
|
1700
|
-
next = updateLora(next, name, false);
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
return this.set(next);
|
|
1704
|
-
}
|
|
1705
|
-
display() {
|
|
1706
|
-
const on = this.activeNames();
|
|
1707
|
-
if (on.length === 0) return `(0/${this.options.length}) none`;
|
|
1708
|
-
return `(${on.length}/${this.options.length}) ${on.map((n) => LorasVar.shortName(n)).join(", ")}`;
|
|
1709
|
-
}
|
|
1710
|
-
};
|
|
1711
|
-
/** SDXL-style ~1MP buckets, multiples of 64 — safe for most latent models */
|
|
1712
|
-
const DEFAULT_SIZE_PRESETS = [
|
|
1713
|
-
{
|
|
1714
|
-
label: "1:1 square",
|
|
1715
|
-
width: 1024,
|
|
1716
|
-
height: 1024
|
|
1717
|
-
},
|
|
1718
|
-
{
|
|
1719
|
-
label: "4:3 landscape",
|
|
1720
|
-
width: 1152,
|
|
1721
|
-
height: 896
|
|
1722
|
-
},
|
|
1723
|
-
{
|
|
1724
|
-
label: "3:4 portrait",
|
|
1725
|
-
width: 896,
|
|
1726
|
-
height: 1152
|
|
1727
|
-
},
|
|
1728
|
-
{
|
|
1729
|
-
label: "3:2 landscape",
|
|
1730
|
-
width: 1216,
|
|
1731
|
-
height: 832
|
|
1732
|
-
},
|
|
1733
|
-
{
|
|
1734
|
-
label: "2:3 portrait",
|
|
1735
|
-
width: 832,
|
|
1736
|
-
height: 1216
|
|
1737
|
-
},
|
|
1738
|
-
{
|
|
1739
|
-
label: "16:9 widescreen",
|
|
1740
|
-
width: 1344,
|
|
1741
|
-
height: 768
|
|
1742
|
-
},
|
|
1743
|
-
{
|
|
1744
|
-
label: "9:16 tall",
|
|
1745
|
-
width: 768,
|
|
1746
|
-
height: 1344
|
|
1747
|
-
}
|
|
1748
|
-
];
|
|
1749
|
-
/** the same aspect ratios around 512, for SD1.5-era models trained at ~0.25MP */
|
|
1750
|
-
const SD15_SIZE_PRESETS = [
|
|
1751
|
-
{
|
|
1752
|
-
label: "1:1 square",
|
|
1753
|
-
width: 512,
|
|
1754
|
-
height: 512
|
|
1755
|
-
},
|
|
1756
|
-
{
|
|
1757
|
-
label: "4:3 landscape",
|
|
1758
|
-
width: 576,
|
|
1759
|
-
height: 448
|
|
1760
|
-
},
|
|
1761
|
-
{
|
|
1762
|
-
label: "3:4 portrait",
|
|
1763
|
-
width: 448,
|
|
1764
|
-
height: 576
|
|
1765
|
-
},
|
|
1766
|
-
{
|
|
1767
|
-
label: "3:2 landscape",
|
|
1768
|
-
width: 576,
|
|
1769
|
-
height: 384
|
|
1770
|
-
},
|
|
1771
|
-
{
|
|
1772
|
-
label: "2:3 portrait",
|
|
1773
|
-
width: 384,
|
|
1774
|
-
height: 576
|
|
1775
|
-
},
|
|
1776
|
-
{
|
|
1777
|
-
label: "16:9 widescreen",
|
|
1778
|
-
width: 704,
|
|
1779
|
-
height: 384
|
|
1780
|
-
},
|
|
1781
|
-
{
|
|
1782
|
-
label: "9:16 tall",
|
|
1783
|
-
width: 384,
|
|
1784
|
-
height: 704
|
|
1785
|
-
}
|
|
1786
|
-
];
|
|
1787
|
-
/** starred presets are one click away in the panel, before the full list */
|
|
1788
|
-
const DEFAULT_STARRED_SIZES = [
|
|
1789
|
-
"1:1 square",
|
|
1790
|
-
"3:4 portrait",
|
|
1791
|
-
"4:3 landscape"
|
|
1792
|
-
];
|
|
1793
|
-
/** the family that matches a workflow's own default: a 512×512 workflow is an SD1.5-era one,
|
|
1794
|
-
* and offering it 1024 buckets would be offering sizes it was never trained at */
|
|
1795
|
-
function sizePresetsFor(defaultValue) {
|
|
1796
|
-
if (defaultValue == null) return DEFAULT_SIZE_PRESETS;
|
|
1797
|
-
return defaultValue.width * defaultValue.height <= 600 * 600 ? SD15_SIZE_PRESETS : DEFAULT_SIZE_PRESETS;
|
|
1798
|
-
}
|
|
1799
|
-
/** width/height picker: presets + free `WxH` entry + optionally the LIVE
|
|
1800
|
-
* size of a linked image var (the widget shows
|
|
1801
|
-
* `WxH size of image '<name>'` as a pickable row) */
|
|
1802
|
-
var SizeVar = class extends ComfyVar {
|
|
1803
|
-
constructor(defaultValue = {
|
|
1804
|
-
width: 1024,
|
|
1805
|
-
height: 1024
|
|
1806
|
-
}, presets = DEFAULT_SIZE_PRESETS, label, imageVar, starred = DEFAULT_STARRED_SIZES) {
|
|
1807
|
-
super(defaultValue, label);
|
|
1808
|
-
this.presets = presets;
|
|
1809
|
-
this.imageVar = imageVar;
|
|
1810
|
-
this.starred = starred;
|
|
1811
|
-
this.kind = "size";
|
|
1812
|
-
}
|
|
1813
|
-
/** current dimensions of the linked image var — null when no link, unset
|
|
1814
|
-
* path, or an unreadable/undecodable file (those errors belong to the
|
|
1815
|
-
* image var itself, the size row simply disappears) */
|
|
1816
|
-
imageSize() {
|
|
1817
|
-
const iv = this.imageVar;
|
|
1818
|
-
if (iv == null || iv.value === "") return null;
|
|
1819
|
-
try {
|
|
1820
|
-
const abs = iv.absPath();
|
|
1821
|
-
const meta = imageMeta(getComfyStorage().readBytes(abs));
|
|
1822
|
-
if (meta.width == null || meta.height == null) return null;
|
|
1823
|
-
return {
|
|
1824
|
-
width: meta.width,
|
|
1825
|
-
height: meta.height,
|
|
1826
|
-
name: basename(abs)
|
|
1827
|
-
};
|
|
1828
|
-
} catch {
|
|
1829
|
-
return null;
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
/** accepts '1024x768' / '1024×768' / a preset label */
|
|
1833
|
-
parse(raw) {
|
|
1834
|
-
const m = raw.trim().match(/^(\d+)\s*[x×]\s*(\d+)$/);
|
|
1835
|
-
if (m != null) {
|
|
1836
|
-
this.set({
|
|
1837
|
-
width: Number(m[1]),
|
|
1838
|
-
height: Number(m[2])
|
|
1839
|
-
});
|
|
1840
|
-
return true;
|
|
1841
|
-
}
|
|
1842
|
-
const preset = this.presets.find((p) => p.label === raw.trim());
|
|
1843
|
-
if (preset != null) {
|
|
1844
|
-
this.set({
|
|
1845
|
-
width: preset.width,
|
|
1846
|
-
height: preset.height
|
|
1847
|
-
});
|
|
1848
|
-
return true;
|
|
1849
|
-
}
|
|
1850
|
-
return false;
|
|
1851
|
-
}
|
|
1852
|
-
display() {
|
|
1853
|
-
const { width, height } = this.value;
|
|
1854
|
-
const hit = this.presets.find((p) => p.width === width && p.height === height);
|
|
1855
|
-
return `${width}×${height}${hit ? ` (${hit.label})` : ""}`;
|
|
1856
|
-
}
|
|
1857
|
-
};
|
|
1858
|
-
DEFAULT_MEDIA_EXTENSIONS.image;
|
|
1859
|
-
DEFAULT_MEDIA_EXTENSIONS.audio;
|
|
1860
|
-
DEFAULT_MEDIA_EXTENSIONS.video;
|
|
1861
|
-
/** empty media var consumed at build time — typed so drivers surface it apart from real crashes */
|
|
1862
|
-
var MediaVarEmptyError = class extends Error {
|
|
1863
|
-
constructor(varName, media = "image") {
|
|
1864
|
-
super(`${media} var '${varName}' is empty — pick a file (TUI: activate the var; script: .set('/path/to/file'))`);
|
|
1865
|
-
this.varName = varName;
|
|
1866
|
-
this.media = media;
|
|
1867
|
-
this.name = "MediaVarEmptyError";
|
|
1868
|
-
}
|
|
1869
|
-
};
|
|
1870
|
-
/** trim + expand a leading `~/` — every media var write funnels through this */
|
|
1871
|
-
function expandUserPath(raw) {
|
|
1872
|
-
const trimmed = raw.trim();
|
|
1873
|
-
return trimmed.startsWith("~/") ? join(getComfyStorage().homedir(), trimmed.slice(2)) : trimmed;
|
|
1874
|
-
}
|
|
1875
|
-
/** the loader node each medium goes through, and its file input */
|
|
1876
|
-
const MEDIA_LOADERS = {
|
|
1877
|
-
image: {
|
|
1878
|
-
node: "LoadImage",
|
|
1879
|
-
input: "image"
|
|
1880
|
-
},
|
|
1881
|
-
audio: {
|
|
1882
|
-
node: "LoadAudio",
|
|
1883
|
-
input: "audio"
|
|
1884
|
-
},
|
|
1885
|
-
video: {
|
|
1886
|
-
node: "LoadVideo",
|
|
1887
|
-
input: "file"
|
|
1888
|
-
}
|
|
1889
|
-
};
|
|
1890
|
-
/**
|
|
1891
|
-
* a local media file path. The VALUE is a PLAIN PATH STRING — text-encodable,
|
|
1892
|
-
* drafts persist it verbatim (toJSON = the string), hand-editable in the
|
|
1893
|
-
* draft json. Empty = unset: outValue()/absPath() throw MediaVarEmptyError,
|
|
1894
|
-
* so a build never runs on a silent placeholder. The TUI opens the file
|
|
1895
|
-
* picker overlay for every media kind.
|
|
1896
|
-
*/
|
|
1897
|
-
var MediaVar = class extends ComfyVar {
|
|
1898
|
-
constructor(defaultValue, opts = {}) {
|
|
1899
|
-
super(expandUserPath(defaultValue), opts.label);
|
|
1900
|
-
this.opts = opts;
|
|
1901
|
-
}
|
|
1902
|
-
/** what the picker lists (lowercase, no dots) */
|
|
1903
|
-
get extensions() {
|
|
1904
|
-
return this.opts.extensions ?? DEFAULT_MEDIA_EXTENSIONS[this.kind];
|
|
1905
|
-
}
|
|
1906
|
-
/** the one-click starting files, `~/` expanded, in their declared order */
|
|
1907
|
-
get presets() {
|
|
1908
|
-
return Object.entries(this.opts.presets ?? {}).map(([label, value]) => ({
|
|
1909
|
-
label,
|
|
1910
|
-
value: expandUserPath(value)
|
|
1911
|
-
}));
|
|
1912
|
-
}
|
|
1913
|
-
set(value) {
|
|
1914
|
-
return super.set(expandUserPath(value));
|
|
1915
|
-
}
|
|
1916
|
-
parse(raw) {
|
|
1917
|
-
this.set(raw);
|
|
1918
|
-
return true;
|
|
1919
|
-
}
|
|
1920
|
-
isSet() {
|
|
1921
|
-
return this.value !== "";
|
|
1922
|
-
}
|
|
1923
|
-
emptyError() {
|
|
1924
|
-
return new MediaVarEmptyError(this.name ?? this.label ?? this.kind, this.kind);
|
|
1925
|
-
}
|
|
1926
|
-
/** the ONE resolution helper: absolute kept as-is, relative resolved against opts.folder, else cwd */
|
|
1927
|
-
absPath() {
|
|
1928
|
-
if (!this.isSet()) throw this.emptyError();
|
|
1929
|
-
if (isAbsolute(this.value)) return this.value;
|
|
1930
|
-
return resolve(this.opts.folder ?? getComfyStorage().cwd(), this.value);
|
|
1931
|
-
}
|
|
1932
|
-
/** empty = unset: the build fails LOUD here (varValues calls outValue) */
|
|
1933
|
-
outValue() {
|
|
1934
|
-
if (!this.isSet()) throw this.emptyError();
|
|
1935
|
-
return this.value;
|
|
1936
|
-
}
|
|
1937
|
-
display() {
|
|
1938
|
-
if (!this.isSet()) return "(unset) pick a file";
|
|
1939
|
-
const home = getComfyStorage().homedir();
|
|
1940
|
-
return this.value.startsWith(`${home}/`) ? `~${this.value.slice(home.length)}` : this.value;
|
|
1941
|
-
}
|
|
1942
|
-
/** upload the file hash-named (reruns dedupe) and add this medium's loader node. A dry
|
|
1943
|
-
* build names the file by its hash and uploads nothing */
|
|
1944
|
-
async loadVia(wf) {
|
|
1945
|
-
const loader = MEDIA_LOADERS[this.kind];
|
|
1946
|
-
const factory = wf.builderBase[loader.node];
|
|
1947
|
-
if (factory == null) throw new Error(`host '${wf.host.data.id}' has no ${loader.node} node: ${this.kind} var '${this.name ?? "?"}' cannot load`);
|
|
1948
|
-
const abs = this.absPath();
|
|
1949
|
-
const bytes = getComfyStorage().readBytes(abs);
|
|
1950
|
-
const ext = extensionOf(abs);
|
|
1951
|
-
const name = `${hashArrayBuffer(bytes)}${ext === "" ? "" : `.${ext}`}`;
|
|
1952
|
-
const onHost = wf.dry ? name : await wf.host.uploader.uploadInput({
|
|
1953
|
-
blob: new Blob([bytes], { type: mediaMime(abs) }),
|
|
1954
|
-
name,
|
|
1955
|
-
slot: `${loader.node}.${loader.input}`,
|
|
1956
|
-
type: "input"
|
|
1957
|
-
});
|
|
1958
|
-
return factory({ [loader.input]: onHost });
|
|
1959
|
-
}
|
|
1960
|
-
};
|
|
1961
|
-
/** a local image path, loaded through LoadImage */
|
|
1962
|
-
var ImageVar = class extends MediaVar {
|
|
1963
|
-
constructor(..._args2) {
|
|
1964
|
-
super(..._args2);
|
|
1965
|
-
this.kind = "image";
|
|
1966
|
-
}
|
|
1967
|
-
async loadInWorkflow(wf) {
|
|
1968
|
-
return await this.loadVia(wf);
|
|
1969
|
-
}
|
|
1970
|
-
};
|
|
1971
|
-
/** a local audio path, loaded through LoadAudio */
|
|
1972
|
-
var AudioVar = class extends MediaVar {
|
|
1973
|
-
constructor(..._args3) {
|
|
1974
|
-
super(..._args3);
|
|
1975
|
-
this.kind = "audio";
|
|
1976
|
-
}
|
|
1977
|
-
async loadInWorkflow(wf) {
|
|
1978
|
-
return await this.loadVia(wf);
|
|
1979
|
-
}
|
|
1980
|
-
};
|
|
1981
|
-
/** a local video path, loaded through LoadVideo */
|
|
1982
|
-
var VideoVar = class extends MediaVar {
|
|
1983
|
-
constructor(..._args4) {
|
|
1984
|
-
super(..._args4);
|
|
1985
|
-
this.kind = "video";
|
|
1986
|
-
}
|
|
1987
|
-
async loadInWorkflow(wf) {
|
|
1988
|
-
return await this.loadVia(wf);
|
|
1989
|
-
}
|
|
1990
|
-
};
|
|
1991
|
-
/** the var constructors: v.text / v.prompt / v.int / v.float / v.seed / v.toggle / v.choice / v.model / v.loras / v.size / v.image / v.audio / v.video */
|
|
1992
|
-
const v = {
|
|
1993
|
-
text: (defaultValue, opts = {}) => new TextVar(defaultValue, typeof opts === "string" ? { label: opts } : opts),
|
|
1994
|
-
prompt: (defaultValue, opts = {}) => new PromptVar(defaultValue, opts),
|
|
1995
|
-
int: (defaultValue, opts = {}) => new IntVar(defaultValue, opts),
|
|
1996
|
-
float: (defaultValue, opts = {}) => new FloatVar(defaultValue, opts),
|
|
1997
|
-
/** `mode` is the SPEC default the workflow runs in: `'+'` makes every run step the seed,
|
|
1998
|
-
* which is what a tuning session wants, and reset()/revert come back to it */
|
|
1999
|
-
seed: (defaultValue = 0, opts = {}) => new SeedVar(defaultValue, opts),
|
|
2000
|
-
toggle: (defaultValue, label) => new ToggleVar(defaultValue, label),
|
|
2001
|
-
/** exactly one option (the default), `{ select: 'zero-or-one' }` for one or none (value
|
|
2002
|
-
* `T | null`), `{ select: 'many' }` for any number (value `T[]`) */
|
|
2003
|
-
choice,
|
|
2004
|
-
loras: (options, initial = {}, label) => new LorasVar(options, initial, label),
|
|
2005
|
-
size: (defaultValue, opts = {}) => new SizeVar(defaultValue, opts.presets ?? sizePresetsFor(defaultValue), opts.label, opts.image, opts.starred),
|
|
2006
|
-
/** host-bound: only inside defineWorkflow({ vars: (v) => … }), typed per slot there */
|
|
2007
|
-
model,
|
|
2008
|
-
image: (defaultValue, opts = {}) => new ImageVar(defaultValue, opts),
|
|
2009
|
-
audio: (defaultValue, opts = {}) => new AudioVar(defaultValue, opts),
|
|
2010
|
-
video: (defaultValue, opts = {}) => new VideoVar(defaultValue, opts)
|
|
2011
|
-
};
|
|
2012
|
-
function varValues(vars) {
|
|
2013
|
-
const out = {};
|
|
2014
|
-
for (const [k, varDef] of Object.entries(vars)) out[k] = varDef.outValue();
|
|
2015
|
-
return out;
|
|
2016
|
-
}
|
|
2017
|
-
//#endregion
|
|
2018
|
-
//#region src/vars/DefinedWorkflow.ts
|
|
2019
|
-
/** type predicate (not a cast): a VarsSpec is a plain record, never callable */
|
|
2020
|
-
function isVarsThunk(vars) {
|
|
2021
|
-
return typeof vars === "function";
|
|
2022
|
-
}
|
|
2023
|
-
/**
|
|
2024
|
-
* a re-runnable workflow definition: `build` re-executes per run with the
|
|
2025
|
-
* current var values, so every run gets a fresh, deterministic graph.
|
|
2026
|
-
*/
|
|
2027
|
-
var DefinedWorkflow = class {
|
|
2028
|
-
constructor(host, spec) {
|
|
2029
|
-
this.host = host;
|
|
2030
|
-
this.spec = spec;
|
|
2031
|
-
this.lastWorkflow = null;
|
|
2032
|
-
this.lastExecution = null;
|
|
2033
|
-
this.vars = isVarsThunk(spec.vars) ? spec.vars(v) : spec.vars;
|
|
2034
|
-
for (const [key, varDef] of this.entries()) {
|
|
2035
|
-
varDef.name = key;
|
|
2036
|
-
varDef.bindHost?.(this.host);
|
|
2037
|
-
}
|
|
2038
|
-
const names = this.entries().map(([key]) => key);
|
|
2039
|
-
for (const [key, varDef] of this.entries()) for (const other of Object.keys(varDef.uiOpts.activeWhen ?? {})) if (!names.includes(other)) throw new Error(`workflow '${spec.id ?? "?"}': var '${key}' is activeWhen '${other}', which is not one of its vars (${names.join(", ")})`);
|
|
2040
|
-
}
|
|
2041
|
-
/** every preview for the current var values. A preview that throws, or vars that cannot be
|
|
2042
|
-
* read yet (an image var still empty), give a line saying so instead of failing the others */
|
|
2043
|
-
computePreviews() {
|
|
2044
|
-
const previews = this.spec.previews ?? {};
|
|
2045
|
-
const names = Object.keys(previews);
|
|
2046
|
-
if (names.length === 0) return {};
|
|
2047
|
-
let values;
|
|
2048
|
-
try {
|
|
2049
|
-
values = varValues(this.vars);
|
|
2050
|
-
} catch (e) {
|
|
2051
|
-
const why = `unavailable: ${e instanceof Error ? e.message : String(e)}`;
|
|
2052
|
-
return Object.fromEntries(names.map((n) => [n, why]));
|
|
2053
|
-
}
|
|
2054
|
-
const out = {};
|
|
2055
|
-
for (const [name, fn] of Object.entries(previews)) try {
|
|
2056
|
-
out[name] = fn(values);
|
|
2057
|
-
} catch (e) {
|
|
2058
|
-
out[name] = `🔴 preview '${name}' failed: ${e instanceof Error ? e.message : String(e)}`;
|
|
2059
|
-
}
|
|
2060
|
-
return out;
|
|
2061
|
-
}
|
|
2062
|
-
/** [name, var] pairs, for drivers that enumerate the knobs */
|
|
2063
|
-
entries() {
|
|
2064
|
-
return Object.entries(this.vars);
|
|
2065
|
-
}
|
|
2066
|
-
/**
|
|
2067
|
-
* build a fresh graph from the CURRENT var values (no send). `p.advance`
|
|
2068
|
-
* (set by run()) fires each var's afterRun() right after snapshotting the
|
|
2069
|
-
* values — atomically, before any await — so the graph uses this run's seed
|
|
2070
|
-
* while the var moves to the next (queued runs get distinct seeds; a bare
|
|
2071
|
-
* build() for copy/export never advances). `p.host` substitutes the host
|
|
2072
|
-
* the graph is built against (TUI host override): node/model availability
|
|
2073
|
-
* there surfaces as workflow.problems / server validation, by design.
|
|
2074
|
-
* `p.dry` builds a graph only to read it: nothing is uploaded, lastWorkflow is left alone.
|
|
2075
|
-
* `p.values` builds from a snapshot taken earlier (run() takes it at the call).
|
|
2076
|
-
*/
|
|
2077
|
-
async build(p = {}) {
|
|
2078
|
-
const wf = (p.host ?? this.host).workflow({ id: this.spec.id });
|
|
2079
|
-
wf.dry = p.dry === true;
|
|
2080
|
-
const values = p.values ?? this.snapshot({ advance: p.advance === true });
|
|
2081
|
-
await this.spec.build(wf.builder, values, wf);
|
|
2082
|
-
if (wf.dry) return wf;
|
|
2083
|
-
this.lastWorkflow = wf;
|
|
2084
|
-
return wf;
|
|
2085
|
-
}
|
|
2086
|
-
/** the current var values; `advance` then moves each var to its next run (the seed) */
|
|
2087
|
-
snapshot(p) {
|
|
2088
|
-
const values = varValues(this.vars);
|
|
2089
|
-
if (p.advance) for (const varDef of Object.values(this.vars)) varDef.afterRun();
|
|
2090
|
-
return values;
|
|
2091
|
-
}
|
|
2092
|
-
/** build a fresh graph from the var values AT THE CALL, send it, wait for outputs:
|
|
2093
|
-
* set a var, call run(), set it again, and each run keeps its own values.
|
|
2094
|
-
* connects first (idempotent) — modules can import offline from the schema cache.
|
|
2095
|
-
* `settings.host` runs against THAT host instead of the defining one. */
|
|
2096
|
-
async run(settings = {}) {
|
|
2097
|
-
const host = settings.host ?? this.host;
|
|
2098
|
-
const values = this.snapshot({ advance: true });
|
|
2099
|
-
host.runsInFlight++;
|
|
2100
|
-
try {
|
|
2101
|
-
await host.connect();
|
|
2102
|
-
const execution = await (await this.build({
|
|
2103
|
-
host,
|
|
2104
|
-
values
|
|
2105
|
-
})).run({
|
|
2106
|
-
save: settings.save,
|
|
2107
|
-
ephemeral: settings.ephemeral,
|
|
2108
|
-
scrubHistory: settings.scrubHistory,
|
|
2109
|
-
idMode: settings.idMode,
|
|
2110
|
-
log: settings.log,
|
|
2111
|
-
onProgress: settings.onProgress,
|
|
2112
|
-
onPreview: settings.onPreview,
|
|
2113
|
-
comfyOrgApiKey: settings.comfyOrgApiKey
|
|
2114
|
-
});
|
|
2115
|
-
this.lastExecution = execution;
|
|
2116
|
-
return execution;
|
|
2117
|
-
} finally {
|
|
2118
|
-
host.runsInFlight--;
|
|
2119
|
-
}
|
|
2120
|
-
}
|
|
2121
|
-
};
|
|
2122
|
-
//#endregion
|
|
2123
|
-
//#region src/host/schemaDrift.ts
|
|
2124
|
-
/**
|
|
2125
|
-
* what changed on a host since a schema was loaded: node types, and the model files each loader
|
|
2126
|
-
* lists. ComfyUI exposes no boot time, so staleness is decided by CONTENT: a restart that changed
|
|
2127
|
-
* nothing stays quiet, a new lora shows even when nobody knows when the box rebooted.
|
|
2128
|
-
* A light check asks only the loaders (`/object_info/<node>`, a few KB); a full one compares every
|
|
2129
|
-
* node type (`/object_info`, megabytes).
|
|
2130
|
-
*/
|
|
2131
|
-
/** the loader inputs whose combo IS a model folder listing */
|
|
2132
|
-
const MODEL_LISTS = [
|
|
2133
|
-
{
|
|
2134
|
-
noun: "lora",
|
|
2135
|
-
node: "LoraLoader",
|
|
2136
|
-
input: "lora_name"
|
|
2137
|
-
},
|
|
2138
|
-
{
|
|
2139
|
-
noun: "checkpoint",
|
|
2140
|
-
node: "CheckpointLoaderSimple",
|
|
2141
|
-
input: "ckpt_name"
|
|
2142
|
-
},
|
|
2143
|
-
{
|
|
2144
|
-
noun: "unet",
|
|
2145
|
-
node: "UNETLoader",
|
|
2146
|
-
input: "unet_name"
|
|
2147
|
-
},
|
|
2148
|
-
{
|
|
2149
|
-
noun: "text encoder",
|
|
2150
|
-
node: "CLIPLoader",
|
|
2151
|
-
input: "clip_name"
|
|
2152
|
-
},
|
|
2153
|
-
{
|
|
2154
|
-
noun: "vae",
|
|
2155
|
-
node: "VAELoader",
|
|
2156
|
-
input: "vae_name"
|
|
2157
|
-
}
|
|
2158
|
-
];
|
|
2159
|
-
/** a combo's options in both object_info spellings: `[[...options]]` and `['COMBO', { options }]` */
|
|
2160
|
-
function comboOptions(spec, node, input) {
|
|
2161
|
-
const def = spec[node];
|
|
2162
|
-
if (!isRecord(def) || !isRecord(def["input"])) return null;
|
|
2163
|
-
const sections = def["input"];
|
|
2164
|
-
for (const section of ["required", "optional"]) {
|
|
2165
|
-
const sec = sections[section];
|
|
2166
|
-
if (!isRecord(sec)) continue;
|
|
2167
|
-
const slot = sec[input];
|
|
2168
|
-
if (!Array.isArray(slot)) continue;
|
|
2169
|
-
const first = slot[0];
|
|
2170
|
-
if (Array.isArray(first)) return first.filter((x) => typeof x === "string");
|
|
2171
|
-
const opts = slot[1];
|
|
2172
|
-
if (first === "COMBO" && isRecord(opts) && Array.isArray(opts["options"])) return opts["options"].filter((x) => typeof x === "string");
|
|
2173
|
-
}
|
|
2174
|
-
return null;
|
|
2175
|
-
}
|
|
2176
|
-
function delta(before, after) {
|
|
2177
|
-
const was = new Set(before);
|
|
2178
|
-
const now = new Set(after);
|
|
2179
|
-
return {
|
|
2180
|
-
added: after.filter((x) => !was.has(x)),
|
|
2181
|
-
removed: before.filter((x) => !now.has(x))
|
|
2182
|
-
};
|
|
2183
|
-
}
|
|
2184
|
-
/** `live` may be PARTIAL (a light check holds only the loaders): a list is compared only where both
|
|
2185
|
-
* sides have the loader, and node types only when `full` */
|
|
2186
|
-
function diffSchemas(p) {
|
|
2187
|
-
const models = [];
|
|
2188
|
-
for (const m of MODEL_LISTS) {
|
|
2189
|
-
const before = comboOptions(p.loaded, m.node, m.input);
|
|
2190
|
-
const after = comboOptions(p.live, m.node, m.input);
|
|
2191
|
-
if (before == null || after == null) continue;
|
|
2192
|
-
const d = delta(before, after);
|
|
2193
|
-
if (d.added.length > 0 || d.removed.length > 0) models.push({
|
|
2194
|
-
noun: m.noun,
|
|
2195
|
-
...d
|
|
2196
|
-
});
|
|
2197
|
-
}
|
|
2198
|
-
return {
|
|
2199
|
-
nodes: p.full ? delta(Object.keys(p.loaded), Object.keys(p.live)) : null,
|
|
2200
|
-
models
|
|
2201
|
-
};
|
|
2202
|
-
}
|
|
2203
|
-
function driftChanged(d) {
|
|
2204
|
-
return d.models.length > 0 || d.nodes != null && (d.nodes.added.length > 0 || d.nodes.removed.length > 0);
|
|
2205
|
-
}
|
|
2206
|
-
/** `+5 loras, -1 unet, +4 node types`, '' when nothing changed */
|
|
2207
|
-
function summarizeDrift(d) {
|
|
2208
|
-
const parts = [];
|
|
2209
|
-
const say = (n, sign, noun) => {
|
|
2210
|
-
if (n > 0) parts.push(`${sign}${n} ${noun}${n === 1 ? "" : "s"}`);
|
|
2211
|
-
};
|
|
2212
|
-
for (const m of d.models) {
|
|
2213
|
-
say(m.added.length, "+", m.noun);
|
|
2214
|
-
say(m.removed.length, "-", m.noun);
|
|
2215
|
-
}
|
|
2216
|
-
if (d.nodes != null) {
|
|
2217
|
-
say(d.nodes.added.length, "+", "node type");
|
|
2218
|
-
say(d.nodes.removed.length, "-", "node type");
|
|
2219
|
-
}
|
|
2220
|
-
return parts.join(", ");
|
|
2221
|
-
}
|
|
2222
|
-
//#endregion
|
|
2223
|
-
export { MODEL_3D_MIMES as $, reloadLoraInfoCache as A, lmFileSize as B, getLoraTriggers as C, readLoraMirror as D, lorasMissingFromMirror as E, fetchLoraList as F, lmTags as G, lmModelName as H, fetchLoraPreviewBytes as I, loraKey as J, lmTrainedWords as K, lmBaseModel as L, fetchLoraCivitai as M, fetchLoraDescription as N, recordCivitaiMiss as O, fetchLoraExampleImages as P, stripAnsi as Q, lmCivitai as R, getLoraTriggerWords as S, loraMirrorEntries as T, lmNotes as U, lmFolder as V, lmSha256 as W, ansi as X, loraPreviewMapFrom as Y, colorsAvailable as Z, buildLoraMirror as _, sha1HexOfString as _t, DefinedWorkflow as a, mediaMime as at, getLoraInfo as b, isLoraLanes as c, isRecord as ct, isLoraStrength as d, resolveComfyStorage as dt, model3dMime as et, clearLoraKeywordOverride as f, isQuiet as ft, setLoraKeyword as g, statelessRegex as gt, loraKeywordFromMirror as h, logSuccess as ht, summarizeDrift as i, isVideoFilename as it, writeLoraMirror as j, refreshLoraInfoCacheIfChanged as k, isLorasInput as l, bang as lt, isLoraKeywordFromMirror as m, logInfo as mt, diffSchemas as n, MEDIA_KINDS as nt, LorasVar as o, hashArrayBuffer as ot, getLoraKeyword as p, logError as pt, loraBasename as q, driftChanged as r, extensionOf as rt, PromptVar as s, importSharp as st, MODEL_LISTS as t, DEFAULT_MEDIA_EXTENSIONS as tt, isPromptInput as u, getComfyStorage as ut, getLoraAddedAt as v, extractErrorMessage as vt, loraMatchesFilter as w, getLoraPreviewUrl as x, getLoraDisplayName as y, lmFilePath as z };
|
|
2224
|
-
|
|
2225
|
-
//# sourceMappingURL=schemaDrift-BGYJZGMD.js.map
|