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
package/dist/run-tui-CrM4ijkH.js
DELETED
|
@@ -1,4569 +0,0 @@
|
|
|
1
|
-
import { i as settingsPathFor, t as bundledExamplesDir } from "./exampleAssets-DZynSkZm.js";
|
|
2
|
-
import { F as fetchLoraList, I as fetchLoraPreviewBytes, J as loraKey, Y as loraPreviewMapFrom, f as clearLoraKeywordOverride, g as setLoraKeyword, h as loraKeywordFromMirror, i as summarizeDrift, k as refreshLoraInfoCacheIfChanged, m as isLoraKeywordFromMirror, o as LorasVar, p as getLoraKeyword, pt as logError, q as loraBasename, rt as extensionOf, s as PromptVar, st as importSharp, vt as extractErrorMessage, w as loraMatchesFilter, x as getLoraPreviewUrl, y as getLoraDisplayName } from "./schemaDrift-BGYJZGMD.js";
|
|
3
|
-
import { a as draftKeyForFile, c as LogsSt, f as assignFamilyColors, i as DraftsSt, m as familyOf, n as mergeWorkflowSources, p as buildFileRows, r as scanCflowFiles, s as listDraftsForFile, t as findDefinedWorkflow } from "./findDefinedWorkflow-qyqFea7q.js";
|
|
4
|
-
import { spawn } from "node:child_process";
|
|
5
|
-
import { homedir, tmpdir } from "node:os";
|
|
6
|
-
import { pathToFileURL } from "node:url";
|
|
7
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
8
|
-
import { basename, dirname, join, resolve } from "pathe";
|
|
9
|
-
import { imageMeta } from "image-meta";
|
|
10
|
-
import { makeAutoObservable, observableRef, reaction, runInAction } from "mobx";
|
|
11
|
-
import { Box, Text, measureElement, render, useApp, useInput, useStdin } from "ink";
|
|
12
|
-
import sharp from "sharp";
|
|
13
|
-
import { observer } from "mobx-react-lite";
|
|
14
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
-
import { useEffect, useRef } from "react";
|
|
16
|
-
//#region src/cli/tui-env.ts
|
|
17
|
-
const COMFY_TS_TUI_ENV = "COMFY_TS_TUI";
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/cli/tui/imageEscapes.ts
|
|
20
|
-
const ESC = "\x1B";
|
|
21
|
-
/** APC terminator: ESC backslash */
|
|
22
|
-
const ST = "\x1B\\";
|
|
23
|
-
/** one OSC 1337 paint: cursor save → CUP → image sized in CELLS → cursor restore */
|
|
24
|
-
function itermImageEscape(bytes, row, col, w, h) {
|
|
25
|
-
const b64 = Buffer.from(bytes).toString("base64");
|
|
26
|
-
return `${ESC}7${ESC}[${row};${col}H${ESC}]1337;File=inline=1;size=${bytes.byteLength};width=${w};height=${h};preserveAspectRatio=1:${b64}\u0007${ESC}8`;
|
|
27
|
-
}
|
|
28
|
-
/** kitty stretches to the given cell box (no preserveAspectRatio key): fit the
|
|
29
|
-
* box to the image aspect first. Cells are ~1:2 (w:h), same as cornerBox. */
|
|
30
|
-
function fitCellBox(p) {
|
|
31
|
-
if (p.imgW <= 0 || p.imgH <= 0) return {
|
|
32
|
-
w: p.w,
|
|
33
|
-
h: p.h
|
|
34
|
-
};
|
|
35
|
-
const aspect = p.imgW / p.imgH;
|
|
36
|
-
let w = p.w;
|
|
37
|
-
let h = Math.max(1, Math.round(w / aspect / 2));
|
|
38
|
-
if (h > p.h) {
|
|
39
|
-
h = p.h;
|
|
40
|
-
w = Math.max(1, Math.min(p.w, Math.round(h * aspect * 2)));
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
w,
|
|
44
|
-
h
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const dimsCache = /* @__PURE__ */ new WeakMap();
|
|
48
|
-
/** header-only parse, cached per bytes object (the painter runs on every flush) */
|
|
49
|
-
function imageDims(bytes) {
|
|
50
|
-
const hit = dimsCache.get(bytes);
|
|
51
|
-
if (hit != null) return hit;
|
|
52
|
-
let dims = {
|
|
53
|
-
w: 0,
|
|
54
|
-
h: 0
|
|
55
|
-
};
|
|
56
|
-
try {
|
|
57
|
-
const meta = imageMeta(bytes);
|
|
58
|
-
if (meta.width != null && meta.height != null) dims = {
|
|
59
|
-
w: meta.width,
|
|
60
|
-
h: meta.height
|
|
61
|
-
};
|
|
62
|
-
} catch {}
|
|
63
|
-
dimsCache.set(bytes, dims);
|
|
64
|
-
return dims;
|
|
65
|
-
}
|
|
66
|
-
/** spec cap for one APC payload; continuation chunks carry only the m key */
|
|
67
|
-
const KITTY_CHUNK = 4096;
|
|
68
|
-
/** transmit png data under a fixed image id WITHOUT displaying it (a=t),
|
|
69
|
-
* base64 chunked with m=1/0 continuation */
|
|
70
|
-
function kittyTransmitEscape(bytes, id) {
|
|
71
|
-
const b64 = Buffer.from(bytes).toString("base64");
|
|
72
|
-
let out = "";
|
|
73
|
-
for (let i = 0; i < b64.length; i += KITTY_CHUNK) {
|
|
74
|
-
const last = i + KITTY_CHUNK >= b64.length;
|
|
75
|
-
const ctrl = i === 0 ? `a=t,f=100,t=d,i=${id},q=2,m=${last ? 0 : 1}` : `m=${last ? 0 : 1}`;
|
|
76
|
-
out += `${ESC}_G${ctrl};${b64.slice(i, i + KITTY_CHUNK)}${ST}`;
|
|
77
|
-
}
|
|
78
|
-
return out;
|
|
79
|
-
}
|
|
80
|
-
/** display a transmitted id at the cursor: same i,p replaces the previous
|
|
81
|
-
* placement, so repaints never accumulate; C=1 keeps the cursor put; z pins
|
|
82
|
-
* stacking (same-z overlaps draw newest-on-top, recency is not a contract) */
|
|
83
|
-
function kittyPlaceEscape(id, row, col, w, h, z) {
|
|
84
|
-
const zKey = z == null ? "" : `,z=${z}`;
|
|
85
|
-
return `${ESC}7${ESC}[${row};${col}H${ESC}_Ga=p,i=${id},p=1,c=${w},r=${h},C=1,q=2${zKey}${ST}${ESC}8`;
|
|
86
|
-
}
|
|
87
|
-
/** delete this id's placements AND free its data (uppercase I) */
|
|
88
|
-
function kittyDeleteEscape(id) {
|
|
89
|
-
return `${ESC}_Ga=d,d=I,i=${id},q=2${ST}`;
|
|
90
|
-
}
|
|
91
|
-
/** free every image + placement — the quit path: ED does not clear kitty images */
|
|
92
|
-
const KITTY_DELETE_ALL = `${ESC}_Ga=d,d=A,q=2${ST}`;
|
|
93
|
-
/**
|
|
94
|
-
* per-id transmit-once bookkeeping: data uploads when the bytes OBJECT changes
|
|
95
|
-
* (delete-before-retransmit sidesteps the spec's underspecified reuse of a live
|
|
96
|
-
* id), a cheap placement re-paints every flush, drop deletes exactly once.
|
|
97
|
-
*/
|
|
98
|
-
var KittyImageSlot = class {
|
|
99
|
-
constructor(id) {
|
|
100
|
-
this.id = id;
|
|
101
|
-
this.transmitted = null;
|
|
102
|
-
}
|
|
103
|
-
show(bytes, row, col, w, h, z) {
|
|
104
|
-
let out = "";
|
|
105
|
-
if (this.transmitted !== bytes) {
|
|
106
|
-
out += kittyDeleteEscape(this.id) + kittyTransmitEscape(bytes, this.id);
|
|
107
|
-
this.transmitted = bytes;
|
|
108
|
-
}
|
|
109
|
-
return out + kittyPlaceEscape(this.id, row, col, w, h, z);
|
|
110
|
-
}
|
|
111
|
-
drop() {
|
|
112
|
-
if (this.transmitted == null) return "";
|
|
113
|
-
this.transmitted = null;
|
|
114
|
-
return kittyDeleteEscape(this.id);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
//#endregion
|
|
118
|
-
//#region src/cli/tui/protocolImage.ts
|
|
119
|
-
function imageProtocol() {
|
|
120
|
-
if (process.env.COMFY_TS_NO_ITERM_IMAGES === "1") return null;
|
|
121
|
-
const term = process.env.TERM ?? "";
|
|
122
|
-
const program = process.env.TERM_PROGRAM ?? "";
|
|
123
|
-
if (term.includes("kitty") || term.includes("ghostty") || process.env.KITTY_WINDOW_ID != null || process.env.GHOSTTY_RESOURCES_DIR != null) return "kitty";
|
|
124
|
-
return program === "iTerm.app" || program === "WezTerm" || program === "vscode" || process.env.LC_TERMINAL === "iTerm2" ? "iterm" : null;
|
|
125
|
-
}
|
|
126
|
-
function protocolCapable() {
|
|
127
|
-
return imageProtocol() != null;
|
|
128
|
-
}
|
|
129
|
-
const PNG_MAGIC = [
|
|
130
|
-
137,
|
|
131
|
-
80,
|
|
132
|
-
78,
|
|
133
|
-
71,
|
|
134
|
-
13,
|
|
135
|
-
10,
|
|
136
|
-
26,
|
|
137
|
-
10
|
|
138
|
-
];
|
|
139
|
-
function isPng(bytes) {
|
|
140
|
-
return PNG_MAGIC.every((byte, ix) => bytes[ix] === byte);
|
|
141
|
-
}
|
|
142
|
-
/** kitty only draws png (f=100), never jpeg/webp; iterm takes any format.
|
|
143
|
-
* Pass every native-renderer byte source that is not sharp-produced png through here. */
|
|
144
|
-
async function protocolReadyBytes(bytes) {
|
|
145
|
-
if (imageProtocol() !== "kitty" || isPng(bytes)) return bytes;
|
|
146
|
-
return new Uint8Array(await sharp(bytes).png().toBuffer());
|
|
147
|
-
}
|
|
148
|
-
//#endregion
|
|
149
|
-
//#region src/cli/tui/protocolImagePainter.ts
|
|
150
|
-
const SYNC_BEGIN = "\x1B[?2026h";
|
|
151
|
-
const SYNC_END = "\x1B[?2026l";
|
|
152
|
-
/** below this a write is a terminal query/reply, not a frame — no cells damaged */
|
|
153
|
-
const MIN_FRAME_BYTES = 64;
|
|
154
|
-
/** kitty image ids: fixed, transmit-once bookkeeping keys */
|
|
155
|
-
const MAIN_ID = 1;
|
|
156
|
-
const CORNER_ID = 2;
|
|
157
|
-
/** corner placement z: pins the small latent ABOVE the main image (same-z
|
|
158
|
-
* stacking is recency, and a fresh output recreates MAIN after the corner) */
|
|
159
|
-
const CORNER_Z = 1;
|
|
160
|
-
/**
|
|
161
|
-
* paints the REAL image (iTerm OSC 1337 / kitty APC _G) over the preview
|
|
162
|
-
* panel's cell rect. Protocol images cannot go THROUGH ink (layout shreds the
|
|
163
|
-
* escape) and every ink frame write ERASES the image's cells — so this hooks
|
|
164
|
-
* stdout.write and re-paints SYNCHRONOUSLY within the same flush, the whole
|
|
165
|
-
* batch wrapped in DEC 2026 synchronized-update markers: the terminal never
|
|
166
|
-
* presents the erased-frame intermediate state. (The previous deferred
|
|
167
|
-
* setImmediate repaint WAS the native-mode flicker.) A mobx reaction covers
|
|
168
|
-
* byte-only changes (fresh latent/output/lora bytes with no frame write).
|
|
169
|
-
* NOT React: effects only fire for the component that re-rendered, which is
|
|
170
|
-
* why a useEffect painter missed frames (reported: the image waited for input).
|
|
171
|
-
* Kitty differs from iterm in three ways the code below encodes: data uploads
|
|
172
|
-
* ONCE per bytes object then a tiny placement re-paints per flush (same i,p
|
|
173
|
-
* replaces); kitty draws images OVER later text, so a gone image needs an
|
|
174
|
-
* explicit delete or it covers the menu; the cell box stretches, so it is
|
|
175
|
-
* fitted to the image aspect first.
|
|
176
|
-
*/
|
|
177
|
-
function installProtocolImagePainter(st) {
|
|
178
|
-
const proto = imageProtocol();
|
|
179
|
-
if (proto == null || process.stdout.isTTY !== true) return () => {};
|
|
180
|
-
const original = process.stdout.write.bind(process.stdout);
|
|
181
|
-
const CONTENT_ROW = 6;
|
|
182
|
-
const kittyMain = new KittyImageSlot(MAIN_ID);
|
|
183
|
-
const kittyCorner = new KittyImageSlot(CORNER_ID);
|
|
184
|
-
/** both images as ONE escape string ('' when nothing to paint or delete) */
|
|
185
|
-
const imageEscapes = () => {
|
|
186
|
-
const pv = st.preview;
|
|
187
|
-
const main = pv.protocolImage;
|
|
188
|
-
const corner = pv.protocolImageCorner;
|
|
189
|
-
const col = Math.max(1, st.termCols - (pv.width + 4) + 3);
|
|
190
|
-
if (proto === "iterm") {
|
|
191
|
-
if (main == null && corner == null) return "";
|
|
192
|
-
let out = "";
|
|
193
|
-
if (main != null) out += itermImageEscape(main, CONTENT_ROW, col, pv.width, pv.height);
|
|
194
|
-
if (corner != null) {
|
|
195
|
-
const box = pv.cornerBox;
|
|
196
|
-
out += itermImageEscape(corner, CONTENT_ROW, col + pv.width - box.w, box.w, box.h);
|
|
197
|
-
}
|
|
198
|
-
return out;
|
|
199
|
-
}
|
|
200
|
-
let out = "";
|
|
201
|
-
if (main == null) out += kittyMain.drop();
|
|
202
|
-
else {
|
|
203
|
-
const dims = imageDims(main);
|
|
204
|
-
const box = fitCellBox({
|
|
205
|
-
imgW: dims.w,
|
|
206
|
-
imgH: dims.h,
|
|
207
|
-
w: pv.width,
|
|
208
|
-
h: pv.height
|
|
209
|
-
});
|
|
210
|
-
const row = CONTENT_ROW + Math.max(0, Math.floor((pv.height - box.h) / 2));
|
|
211
|
-
const c = col + Math.max(0, Math.floor((pv.width - box.w) / 2));
|
|
212
|
-
out += kittyMain.show(main, row, c, box.w, box.h);
|
|
213
|
-
}
|
|
214
|
-
if (corner == null) out += kittyCorner.drop();
|
|
215
|
-
else {
|
|
216
|
-
const box = pv.cornerBox;
|
|
217
|
-
out += kittyCorner.show(corner, CONTENT_ROW, col + pv.width - box.w, box.w, box.h, CORNER_Z);
|
|
218
|
-
}
|
|
219
|
-
return out;
|
|
220
|
-
};
|
|
221
|
-
let disposed = false;
|
|
222
|
-
/** byte-only changes (no frame write erased anything): paint alone, atomically */
|
|
223
|
-
let scheduled = false;
|
|
224
|
-
const schedule = () => {
|
|
225
|
-
if (scheduled || disposed) return;
|
|
226
|
-
scheduled = true;
|
|
227
|
-
setImmediate(() => {
|
|
228
|
-
scheduled = false;
|
|
229
|
-
if (disposed) return;
|
|
230
|
-
const images = imageEscapes();
|
|
231
|
-
if (images !== "") original(SYNC_BEGIN + images + SYNC_END);
|
|
232
|
-
});
|
|
233
|
-
};
|
|
234
|
-
const patched = ((chunk, encodingOrCb, cb) => {
|
|
235
|
-
const images = !disposed && (typeof chunk === "string" ? chunk.length : chunk.byteLength) >= MIN_FRAME_BYTES ? imageEscapes() : "";
|
|
236
|
-
if (images !== "") original(SYNC_BEGIN);
|
|
237
|
-
const res = typeof encodingOrCb === "function" ? original(chunk, encodingOrCb) : original(chunk, encodingOrCb, cb);
|
|
238
|
-
if (images !== "") original(images + SYNC_END);
|
|
239
|
-
return res;
|
|
240
|
-
});
|
|
241
|
-
process.stdout.write = patched;
|
|
242
|
-
const disposeReaction = reaction(() => [st.preview.protocolImage, st.preview.protocolImageCorner], schedule);
|
|
243
|
-
return () => {
|
|
244
|
-
disposed = true;
|
|
245
|
-
if (proto === "kitty") original(KITTY_DELETE_ALL);
|
|
246
|
-
process.stdout.write = original;
|
|
247
|
-
disposeReaction();
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
//#endregion
|
|
251
|
-
//#region src/cli/tui/components/StatusBar.tsx
|
|
252
|
-
/** keys cyan, labels gray — shared by the keybar and overlay footers */
|
|
253
|
-
const KeyHints = (p) => /* @__PURE__ */ jsx(Text, {
|
|
254
|
-
wrap: "wrap",
|
|
255
|
-
children: p.hints.map(([k, label], ix) => /* @__PURE__ */ jsxs(Text, { children: [
|
|
256
|
-
ix > 0 ? /* @__PURE__ */ jsx(Text, {
|
|
257
|
-
color: "gray",
|
|
258
|
-
children: " · "
|
|
259
|
-
}) : null,
|
|
260
|
-
/* @__PURE__ */ jsx(Text, {
|
|
261
|
-
color: "cyan",
|
|
262
|
-
children: k
|
|
263
|
-
}),
|
|
264
|
-
/* @__PURE__ */ jsxs(Text, {
|
|
265
|
-
color: "gray",
|
|
266
|
-
children: [" ", label]
|
|
267
|
-
})
|
|
268
|
-
] }, `${k}·${label}`))
|
|
269
|
-
});
|
|
270
|
-
const ProgressLine = observer((p) => {
|
|
271
|
-
const s = p.st;
|
|
272
|
-
const e = s.exec;
|
|
273
|
-
const queued = s.queue.remaining;
|
|
274
|
-
if (s.mode === "edit" || s.mode === "overlay-text") return /* @__PURE__ */ jsx(Text, {
|
|
275
|
-
color: "gray",
|
|
276
|
-
children: "editing…"
|
|
277
|
-
});
|
|
278
|
-
if (e.running) {
|
|
279
|
-
const prog = e.progress;
|
|
280
|
-
const width = 16;
|
|
281
|
-
const filled = prog ? Math.round(prog.percent / 100 * width) : 0;
|
|
282
|
-
return /* @__PURE__ */ jsxs(Text, { children: [
|
|
283
|
-
">> ",
|
|
284
|
-
"[",
|
|
285
|
-
"█".repeat(filled) + "░".repeat(width - filled),
|
|
286
|
-
"] ",
|
|
287
|
-
prog ? `${prog.percent.toFixed(0)}%` : "…",
|
|
288
|
-
prog?.nodeName ? ` · ${prog.nodeName}` : "",
|
|
289
|
-
prog ? ` · ${(prog.elapsedMs / 1e3).toFixed(0)}s` : "",
|
|
290
|
-
queued > 0 ? ` · queue ${queued}` : ""
|
|
291
|
-
] });
|
|
292
|
-
}
|
|
293
|
-
if (e.error) return /* @__PURE__ */ jsx(Text, {
|
|
294
|
-
color: "red",
|
|
295
|
-
children: e.error
|
|
296
|
-
});
|
|
297
|
-
if (e.notice) return /* @__PURE__ */ jsx(Text, { children: e.notice });
|
|
298
|
-
if (queued > 0) return /* @__PURE__ */ jsxs(Text, {
|
|
299
|
-
color: "yellow",
|
|
300
|
-
children: [queued, " queued on the server"]
|
|
301
|
-
});
|
|
302
|
-
if (e.runCount > 0) return /* @__PURE__ */ jsxs(Text, {
|
|
303
|
-
color: e.lastStatus === "Success" ? "green" : "red",
|
|
304
|
-
children: [
|
|
305
|
-
"run #",
|
|
306
|
-
e.runCount,
|
|
307
|
-
" ",
|
|
308
|
-
e.lastStatus?.toLowerCase()
|
|
309
|
-
]
|
|
310
|
-
});
|
|
311
|
-
return /* @__PURE__ */ jsx(Text, {
|
|
312
|
-
color: "gray",
|
|
313
|
-
children: "ready — r to run"
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
const KIND_KEYS = {
|
|
317
|
-
text: [["⏎/→", "edit"]],
|
|
318
|
-
prompt: [["⏎/→", "edit"]],
|
|
319
|
-
int: [["⏎/→", "edit"]],
|
|
320
|
-
float: [["⏎/→", "edit"]],
|
|
321
|
-
seed: [
|
|
322
|
-
["+", "increment"],
|
|
323
|
-
["-", "decrement"],
|
|
324
|
-
["?", "random"],
|
|
325
|
-
["=", "fixed"],
|
|
326
|
-
["⏎/→", "type value"],
|
|
327
|
-
["*", "reroll"]
|
|
328
|
-
],
|
|
329
|
-
toggle: [["⏎/→", "flip"]],
|
|
330
|
-
choice: [["⏎/→", "pick"]],
|
|
331
|
-
size: [["⏎/→", "pick"]],
|
|
332
|
-
loras: [["⏎/→", "select"]],
|
|
333
|
-
image: [["⏎/→", "browse"]]
|
|
334
|
-
};
|
|
335
|
-
/** shown INSIDE the text editor box (TextOverlay footer), not in the keybar */
|
|
336
|
-
const TEXT_EDIT_HINTS = [
|
|
337
|
-
["⏎", "save"],
|
|
338
|
-
["⇧⏎/⌥⏎", "newline"],
|
|
339
|
-
["esc", "cancel"],
|
|
340
|
-
["⌥⌫", "del word"],
|
|
341
|
-
["⌥←→", "jump"],
|
|
342
|
-
["⌘←→/⌃A⌃E", "line ends"],
|
|
343
|
-
["⌥↑↓", "move line"],
|
|
344
|
-
["⌘/", "comment"],
|
|
345
|
-
["⌃U/⌃K", "kill"]
|
|
346
|
-
];
|
|
347
|
-
const DRAFT_OP_HINTS = [
|
|
348
|
-
["n", "new"],
|
|
349
|
-
["e", "rename"],
|
|
350
|
-
["c", "duplicate"],
|
|
351
|
-
["x", "delete"]
|
|
352
|
-
];
|
|
353
|
-
const MODE_KEYS = {
|
|
354
|
-
edit: [
|
|
355
|
-
["⏎", "apply"],
|
|
356
|
-
["esc", "cancel"],
|
|
357
|
-
["⌥⌫/⌃W", "del word"],
|
|
358
|
-
["⌥←→", "jump"],
|
|
359
|
-
["⌃A/⌃E", "line ends"],
|
|
360
|
-
["⌃U/⌃K", "kill"]
|
|
361
|
-
],
|
|
362
|
-
"overlay-text": TEXT_EDIT_HINTS,
|
|
363
|
-
"overlay-choice": [
|
|
364
|
-
["⏎", "pick"],
|
|
365
|
-
["↑↓", "move"],
|
|
366
|
-
["type", "filter"],
|
|
367
|
-
["esc", "cancel"]
|
|
368
|
-
],
|
|
369
|
-
"overlay-preset": [
|
|
370
|
-
["⏎", "use this text"],
|
|
371
|
-
["↑↓", "move"],
|
|
372
|
-
["type", "filter"],
|
|
373
|
-
["esc", "cancel"]
|
|
374
|
-
],
|
|
375
|
-
"overlay-size": [
|
|
376
|
-
["⏎", "pick"],
|
|
377
|
-
["↑↓", "move"],
|
|
378
|
-
["type", "filter or WxH"],
|
|
379
|
-
["esc", "cancel"]
|
|
380
|
-
],
|
|
381
|
-
"overlay-loras": [
|
|
382
|
-
["space/⏎", "tick"],
|
|
383
|
-
["←→", "strength ±0.05"],
|
|
384
|
-
["type", "filter"],
|
|
385
|
-
["⌃K", "keyword"],
|
|
386
|
-
["⌃D", "reset keyword"],
|
|
387
|
-
["⌃A", "all"],
|
|
388
|
-
["⌃N", "none"],
|
|
389
|
-
["esc", "done"]
|
|
390
|
-
],
|
|
391
|
-
"overlay-image": [
|
|
392
|
-
["⏎", "pick / enter dir"],
|
|
393
|
-
["←", "parent"],
|
|
394
|
-
["→", "enter dir"],
|
|
395
|
-
["tab", "pane"],
|
|
396
|
-
["↑↓", "move"],
|
|
397
|
-
["type", "filter"],
|
|
398
|
-
["⌃F", "fav folder"],
|
|
399
|
-
["esc", "cancel"]
|
|
400
|
-
],
|
|
401
|
-
"overlay-drafts": [
|
|
402
|
-
["⏎", "load / new"],
|
|
403
|
-
...DRAFT_OP_HINTS,
|
|
404
|
-
["↑↓", "move"],
|
|
405
|
-
["esc", "cancel"]
|
|
406
|
-
],
|
|
407
|
-
"overlay-hosts": [
|
|
408
|
-
["⏎", "pick run host"],
|
|
409
|
-
["↑↓", "move"],
|
|
410
|
-
["esc", "cancel"]
|
|
411
|
-
],
|
|
412
|
-
"overlay-copy": [["⏎/esc", "close"]],
|
|
413
|
-
tree: [
|
|
414
|
-
["⏎", "load"],
|
|
415
|
-
["↑↓", "move"],
|
|
416
|
-
["←", "fold"],
|
|
417
|
-
["→", "unfold / vars"],
|
|
418
|
-
["/", "filter"],
|
|
419
|
-
...DRAFT_OP_HINTS,
|
|
420
|
-
["t/esc", "back"]
|
|
421
|
-
],
|
|
422
|
-
host: [
|
|
423
|
-
["⏎", "run action"],
|
|
424
|
-
["↑↓", "move"],
|
|
425
|
-
["h", "change host"],
|
|
426
|
-
["a/esc", "back"]
|
|
427
|
-
],
|
|
428
|
-
preview: [
|
|
429
|
-
["←→", "change"],
|
|
430
|
-
["↑↓", "move"],
|
|
431
|
-
["⏎/p/esc", "done"]
|
|
432
|
-
]
|
|
433
|
-
};
|
|
434
|
-
/** persistent 2-line keybar: EVERYTHING available right now, always visible */
|
|
435
|
-
const KeyBar = observer((p) => {
|
|
436
|
-
const s = p.st;
|
|
437
|
-
const kind = s.selected?.[1].kind;
|
|
438
|
-
const treeFiltering = s.mode === "tree" && s.tree.filtering;
|
|
439
|
-
const modeHints = treeFiltering ? [
|
|
440
|
-
["type", "filter"],
|
|
441
|
-
["⏎", "load"],
|
|
442
|
-
["↑↓", "move"],
|
|
443
|
-
["esc", "clear"]
|
|
444
|
-
] : MODE_KEYS[s.mode] ?? [
|
|
445
|
-
["↑↓", "select"],
|
|
446
|
-
["←", "tree"],
|
|
447
|
-
...kind ? KIND_KEYS[kind] ?? [] : [],
|
|
448
|
-
...s.picker.presetVar != null ? [["P", "presets"]] : []
|
|
449
|
-
];
|
|
450
|
-
const globalHints = !treeFiltering && (s.mode === "nav" || s.mode === "tree" || s.mode === "host" || s.mode === "preview") ? [
|
|
451
|
-
["r", "run"],
|
|
452
|
-
["s", "reroll+run"],
|
|
453
|
-
...s.mode === "nav" ? [["e", "rename draft"]] : [],
|
|
454
|
-
...s.preview.show || s.mode === "preview" ? [] : [["p", "preview (off)"]],
|
|
455
|
-
["o", "open image"],
|
|
456
|
-
["i", "copy image"],
|
|
457
|
-
...s.mode === "tree" || s.mode === "preview" ? [] : [["c/C", "copy wf/api"]],
|
|
458
|
-
["q", "quit"]
|
|
459
|
-
] : [["⌃R", "run"], ["esc", "back"]];
|
|
460
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
461
|
-
flexDirection: "column",
|
|
462
|
-
paddingX: 1,
|
|
463
|
-
children: [s.mode !== "overlay-text" && /* @__PURE__ */ jsx(KeyHints, { hints: modeHints }), /* @__PURE__ */ jsx(KeyHints, { hints: globalHints })]
|
|
464
|
-
});
|
|
465
|
-
});
|
|
466
|
-
//#endregion
|
|
467
|
-
//#region src/cli/tui/components/CopyOverlay.tsx
|
|
468
|
-
/** `c`/`C` confirmation popup: WHAT landed in the clipboard (or the loud
|
|
469
|
-
* failure) — a copy is never silent again. ⏎/esc closes. */
|
|
470
|
-
const CopyOverlay = observer((p) => {
|
|
471
|
-
const popup = p.st.exec.copyPopup;
|
|
472
|
-
if (popup == null) return null;
|
|
473
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
474
|
-
borderStyle: "double",
|
|
475
|
-
borderColor: popup.ok ? "green" : "red",
|
|
476
|
-
paddingX: 1,
|
|
477
|
-
flexDirection: "column",
|
|
478
|
-
children: [
|
|
479
|
-
/* @__PURE__ */ jsxs(Text, {
|
|
480
|
-
bold: true,
|
|
481
|
-
color: popup.ok ? "green" : "red",
|
|
482
|
-
children: [popup.ok ? "✓ " : "✗ ", popup.title]
|
|
483
|
-
}),
|
|
484
|
-
popup.lines.slice(0, p.st.overlayLines).map((line, ix) => /* @__PURE__ */ jsx(Text, {
|
|
485
|
-
color: popup.ok ? void 0 : "red",
|
|
486
|
-
wrap: "truncate",
|
|
487
|
-
children: line
|
|
488
|
-
}, `${ix}·${line.slice(0, 12)}`)),
|
|
489
|
-
/* @__PURE__ */ jsx(KeyHints, { hints: [["⏎/esc", "close"]] })
|
|
490
|
-
]
|
|
491
|
-
});
|
|
492
|
-
});
|
|
493
|
-
//#endregion
|
|
494
|
-
//#region src/cli/tui/components/OverlayList.tsx
|
|
495
|
-
/** generic modal list: title + rows windowed around the selected index */
|
|
496
|
-
const OverlayList = (p) => {
|
|
497
|
-
const winStart = Math.max(0, Math.min(p.selectedIx - Math.floor(p.lines / 2), p.rows.length - p.lines));
|
|
498
|
-
const visible = p.rows.slice(winStart, winStart + p.lines);
|
|
499
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
500
|
-
borderStyle: "double",
|
|
501
|
-
paddingX: 1,
|
|
502
|
-
flexDirection: "column",
|
|
503
|
-
children: [
|
|
504
|
-
/* @__PURE__ */ jsx(Text, {
|
|
505
|
-
bold: true,
|
|
506
|
-
children: p.title
|
|
507
|
-
}),
|
|
508
|
-
p.extraHeader,
|
|
509
|
-
winStart > 0 && /* @__PURE__ */ jsx(Text, {
|
|
510
|
-
color: "gray",
|
|
511
|
-
children: "…"
|
|
512
|
-
}),
|
|
513
|
-
visible.map((r) => r.node),
|
|
514
|
-
winStart + p.lines < p.rows.length && /* @__PURE__ */ jsx(Text, {
|
|
515
|
-
color: "gray",
|
|
516
|
-
children: "…"
|
|
517
|
-
}),
|
|
518
|
-
p.footer
|
|
519
|
-
]
|
|
520
|
-
});
|
|
521
|
-
};
|
|
522
|
-
//#endregion
|
|
523
|
-
//#region src/cli/tui/components/DraftsOverlay.tsx
|
|
524
|
-
/** modal draft picker: row 0 creates a new draft, the rest load existing ones */
|
|
525
|
-
const DraftsOverlay = observer((p) => {
|
|
526
|
-
const s = p.st;
|
|
527
|
-
const d = s.drafts;
|
|
528
|
-
const rows = [{
|
|
529
|
-
key: "·new·",
|
|
530
|
-
node: /* @__PURE__ */ jsxs(Text, {
|
|
531
|
-
inverse: d.ix === 0,
|
|
532
|
-
children: [d.ix === 0 ? "▸ " : " ", "new draft"]
|
|
533
|
-
}, "·new·")
|
|
534
|
-
}, ...d.list.map((name, ix) => ({
|
|
535
|
-
key: name,
|
|
536
|
-
node: /* @__PURE__ */ jsxs(Text, {
|
|
537
|
-
inverse: ix + 1 === d.ix,
|
|
538
|
-
children: [
|
|
539
|
-
ix + 1 === d.ix ? "▸ " : " ",
|
|
540
|
-
name === d.active ? "● " : " ",
|
|
541
|
-
name
|
|
542
|
-
]
|
|
543
|
-
}, name)
|
|
544
|
-
}))];
|
|
545
|
-
return /* @__PURE__ */ jsx(OverlayList, {
|
|
546
|
-
title: /* @__PURE__ */ jsxs(Fragment, { children: ["drafts ", /* @__PURE__ */ jsxs(Text, {
|
|
547
|
-
color: "gray",
|
|
548
|
-
children: ["· ", s.wf.spec.id ?? "workflow"]
|
|
549
|
-
})] }),
|
|
550
|
-
selectedIx: d.ix,
|
|
551
|
-
lines: s.overlayLines,
|
|
552
|
-
rows,
|
|
553
|
-
footer: /* @__PURE__ */ jsx(KeyHints, { hints: DRAFT_OP_HINTS })
|
|
554
|
-
});
|
|
555
|
-
});
|
|
556
|
-
//#endregion
|
|
557
|
-
//#region src/cli/tui/components/Header.tsx
|
|
558
|
-
const HeaderBox = (p) => /* @__PURE__ */ jsxs(Box, {
|
|
559
|
-
borderStyle: "round",
|
|
560
|
-
borderColor: "gray",
|
|
561
|
-
paddingX: 1,
|
|
562
|
-
flexDirection: "column",
|
|
563
|
-
flexShrink: 0,
|
|
564
|
-
children: [p.title != null && /* @__PURE__ */ jsx(Box, {
|
|
565
|
-
marginTop: -1,
|
|
566
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
567
|
-
color: "gray",
|
|
568
|
-
children: p.title
|
|
569
|
-
})
|
|
570
|
-
}), /* @__PURE__ */ jsx(Box, { children: p.children })]
|
|
571
|
-
});
|
|
572
|
-
/** labeled header boxes: brand · (w)orkflow · (d)raft · (h)ost·(a)ctions — the keys open each surface */
|
|
573
|
-
const Header = observer((p) => {
|
|
574
|
-
const s = p.st;
|
|
575
|
-
const runHost = s.runHost;
|
|
576
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
577
|
-
flexDirection: "row",
|
|
578
|
-
children: [
|
|
579
|
-
/* @__PURE__ */ jsx(HeaderBox, { children: /* @__PURE__ */ jsx(Text, {
|
|
580
|
-
bold: true,
|
|
581
|
-
color: "magenta",
|
|
582
|
-
children: "comfy-ts"
|
|
583
|
-
}) }),
|
|
584
|
-
/* @__PURE__ */ jsx(HeaderBox, {
|
|
585
|
-
title: "(w)orkflow",
|
|
586
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
587
|
-
bold: true,
|
|
588
|
-
color: "yellow",
|
|
589
|
-
children: s.wf.spec.id ?? "workflow"
|
|
590
|
-
})
|
|
591
|
-
}),
|
|
592
|
-
/* @__PURE__ */ jsx(HeaderBox, {
|
|
593
|
-
title: "(d)raft",
|
|
594
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
595
|
-
bold: true,
|
|
596
|
-
color: "cyan",
|
|
597
|
-
children: s.drafts.active ?? "default"
|
|
598
|
-
})
|
|
599
|
-
}),
|
|
600
|
-
/* @__PURE__ */ jsx(HeaderBox, {
|
|
601
|
-
title: "(h)ost · (a)ctions",
|
|
602
|
-
children: /* @__PURE__ */ jsxs(Text, { children: [
|
|
603
|
-
/* @__PURE__ */ jsx(Text, {
|
|
604
|
-
color: s.host.status === "up" ? "green" : s.host.status === "down" ? "red" : "gray",
|
|
605
|
-
children: "● "
|
|
606
|
-
}),
|
|
607
|
-
/* @__PURE__ */ jsx(Text, {
|
|
608
|
-
bold: true,
|
|
609
|
-
color: "green",
|
|
610
|
-
children: runHost.data.id
|
|
611
|
-
}),
|
|
612
|
-
/* @__PURE__ */ jsxs(Text, {
|
|
613
|
-
color: "gray",
|
|
614
|
-
children: [
|
|
615
|
-
" (",
|
|
616
|
-
runHost.addressLabel,
|
|
617
|
-
")"
|
|
618
|
-
]
|
|
619
|
-
}),
|
|
620
|
-
s.hostOverride != null && s.hostOverride !== s.wf.host && /* @__PURE__ */ jsxs(Text, {
|
|
621
|
-
color: "yellow",
|
|
622
|
-
children: [" ⇄ overrides ", s.wf.host.data.id]
|
|
623
|
-
}),
|
|
624
|
-
s.host.drift !== "" && /* @__PURE__ */ jsxs(Text, {
|
|
625
|
-
color: "yellow",
|
|
626
|
-
children: [
|
|
627
|
-
" ⚠ changed: ",
|
|
628
|
-
s.host.drift,
|
|
629
|
-
" · a → re-codegen"
|
|
630
|
-
]
|
|
631
|
-
}),
|
|
632
|
-
s.host.status === "down" && /* @__PURE__ */ jsxs(Text, {
|
|
633
|
-
color: "red",
|
|
634
|
-
children: [" ", s.host.probing ? s.host.spinner : `↻ ${s.host.retryInS}s`]
|
|
635
|
-
})
|
|
636
|
-
] })
|
|
637
|
-
})
|
|
638
|
-
]
|
|
639
|
-
});
|
|
640
|
-
});
|
|
641
|
-
//#endregion
|
|
642
|
-
//#region src/cli/tui/components/HostPanel.tsx
|
|
643
|
-
/** host stats + maintenance actions (mode 'host', key `h`) */
|
|
644
|
-
const HostPanel = observer((p) => {
|
|
645
|
-
const s = p.st;
|
|
646
|
-
const h = s.host;
|
|
647
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
648
|
-
borderStyle: "double",
|
|
649
|
-
paddingX: 1,
|
|
650
|
-
flexDirection: "column",
|
|
651
|
-
children: [
|
|
652
|
-
/* @__PURE__ */ jsxs(Text, {
|
|
653
|
-
bold: true,
|
|
654
|
-
children: [
|
|
655
|
-
"host actions · ",
|
|
656
|
-
/* @__PURE__ */ jsx(Text, {
|
|
657
|
-
color: "green",
|
|
658
|
-
children: h.host.data.id
|
|
659
|
-
}),
|
|
660
|
-
" ",
|
|
661
|
-
/* @__PURE__ */ jsxs(Text, {
|
|
662
|
-
color: "gray",
|
|
663
|
-
children: [
|
|
664
|
-
"(",
|
|
665
|
-
h.host.addressLabel,
|
|
666
|
-
")"
|
|
667
|
-
]
|
|
668
|
-
}),
|
|
669
|
-
s.hostOverride != null && /* @__PURE__ */ jsx(Text, {
|
|
670
|
-
color: "yellow",
|
|
671
|
-
children: " ⇄ override"
|
|
672
|
-
})
|
|
673
|
-
]
|
|
674
|
-
}),
|
|
675
|
-
h.stats.map((row) => /* @__PURE__ */ jsxs(Text, { children: [/* @__PURE__ */ jsx(Text, {
|
|
676
|
-
color: "gray",
|
|
677
|
-
children: row.label.padEnd(12)
|
|
678
|
-
}), row.value] }, row.label)),
|
|
679
|
-
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
680
|
-
h.actions.map((action, ix) => {
|
|
681
|
-
const sel = ix === h.ix;
|
|
682
|
-
const busy = h.running === action.key;
|
|
683
|
-
return /* @__PURE__ */ jsxs(Text, {
|
|
684
|
-
inverse: sel,
|
|
685
|
-
color: busy ? "yellow" : void 0,
|
|
686
|
-
children: [
|
|
687
|
-
sel ? "▸ " : " ",
|
|
688
|
-
action.label,
|
|
689
|
-
busy ? " …" : ""
|
|
690
|
-
]
|
|
691
|
-
}, action.key);
|
|
692
|
-
})
|
|
693
|
-
]
|
|
694
|
-
});
|
|
695
|
-
});
|
|
696
|
-
//#endregion
|
|
697
|
-
//#region src/cli/tui/components/HostsOverlay.tsx
|
|
698
|
-
/** modal host picker (`h`): row 0 restores the workflow's own host, the rest
|
|
699
|
-
* override where runs are built and sent (every registered host is listed) */
|
|
700
|
-
const HostsOverlay = observer((p) => {
|
|
701
|
-
const s = p.st;
|
|
702
|
-
const h = s.host;
|
|
703
|
-
const rows = h.pickerRows.map((row, ix) => ({
|
|
704
|
-
key: row.host?.data.id ?? "·default·",
|
|
705
|
-
node: /* @__PURE__ */ jsxs(Text, {
|
|
706
|
-
inverse: ix === h.pickerIx,
|
|
707
|
-
children: [
|
|
708
|
-
ix === h.pickerIx ? "▸ " : " ",
|
|
709
|
-
row.active ? "● " : " ",
|
|
710
|
-
row.label
|
|
711
|
-
]
|
|
712
|
-
}, row.host?.data.id ?? "·default·")
|
|
713
|
-
}));
|
|
714
|
-
return /* @__PURE__ */ jsx(OverlayList, {
|
|
715
|
-
title: /* @__PURE__ */ jsxs(Fragment, { children: ["run host ", /* @__PURE__ */ jsx(Text, {
|
|
716
|
-
color: "gray",
|
|
717
|
-
children: "· overrides the workflow's configured host"
|
|
718
|
-
})] }),
|
|
719
|
-
selectedIx: h.pickerIx,
|
|
720
|
-
lines: s.overlayLines,
|
|
721
|
-
rows
|
|
722
|
-
});
|
|
723
|
-
});
|
|
724
|
-
//#endregion
|
|
725
|
-
//#region src/cli/tui/components/LorasOverlay.tsx
|
|
726
|
-
/** modal multi-select: tick/untick loras, filter, bulk ops, step strengths */
|
|
727
|
-
const LorasOverlay = observer((p) => {
|
|
728
|
-
const s = p.st;
|
|
729
|
-
const lo = s.loras;
|
|
730
|
-
const lv = lo.selectedVar;
|
|
731
|
-
if (lv == null) return null;
|
|
732
|
-
const names = lo.filteredNames;
|
|
733
|
-
return /* @__PURE__ */ jsx(OverlayList, {
|
|
734
|
-
title: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
735
|
-
s.selected?.[1].label ?? s.selected?.[0],
|
|
736
|
-
" ",
|
|
737
|
-
/* @__PURE__ */ jsx(Text, {
|
|
738
|
-
color: "gray",
|
|
739
|
-
children: lv.display()
|
|
740
|
-
})
|
|
741
|
-
] }),
|
|
742
|
-
extraHeader: /* @__PURE__ */ jsxs(Text, {
|
|
743
|
-
color: "yellow",
|
|
744
|
-
children: [
|
|
745
|
-
"filter: ",
|
|
746
|
-
lo.filter,
|
|
747
|
-
"▌"
|
|
748
|
-
]
|
|
749
|
-
}),
|
|
750
|
-
selectedIx: lo.ix,
|
|
751
|
-
lines: s.overlayLines,
|
|
752
|
-
rows: names.map((name, ix) => {
|
|
753
|
-
const on = lv.isOn(name);
|
|
754
|
-
const keyword = getLoraKeyword(name, lo.hostId);
|
|
755
|
-
const fromMirror = isLoraKeywordFromMirror(name, lo.hostId);
|
|
756
|
-
const file = loraBasename(name);
|
|
757
|
-
const display = getLoraDisplayName(name, lo.hostId);
|
|
758
|
-
return {
|
|
759
|
-
key: name,
|
|
760
|
-
node: /* @__PURE__ */ jsxs(Text, {
|
|
761
|
-
inverse: ix === lo.ix,
|
|
762
|
-
bold: on,
|
|
763
|
-
color: on ? "green" : "gray",
|
|
764
|
-
children: [
|
|
765
|
-
ix === lo.ix ? "▸ " : " ",
|
|
766
|
-
on ? "✔" : "·",
|
|
767
|
-
" ",
|
|
768
|
-
file,
|
|
769
|
-
on ? ` ${lv.strengthLabel(name)}` : "",
|
|
770
|
-
display !== file && /* @__PURE__ */ jsxs(Text, {
|
|
771
|
-
color: "cyan",
|
|
772
|
-
dimColor: true,
|
|
773
|
-
bold: false,
|
|
774
|
-
children: [" ", display]
|
|
775
|
-
}),
|
|
776
|
-
keyword !== "" && /* @__PURE__ */ jsxs(Text, {
|
|
777
|
-
color: fromMirror ? "gray" : "yellow",
|
|
778
|
-
dimColor: fromMirror,
|
|
779
|
-
bold: false,
|
|
780
|
-
children: [" kw: ", keyword]
|
|
781
|
-
})
|
|
782
|
-
]
|
|
783
|
-
}, name)
|
|
784
|
-
};
|
|
785
|
-
}),
|
|
786
|
-
footer: names.length === 0 ? /* @__PURE__ */ jsx(Text, {
|
|
787
|
-
color: "red",
|
|
788
|
-
children: "no match"
|
|
789
|
-
}) : void 0
|
|
790
|
-
});
|
|
791
|
-
});
|
|
792
|
-
//#endregion
|
|
793
|
-
//#region src/cli/tui/components/PickerOverlays.tsx
|
|
794
|
-
/** modal option picker: type to fuzzy-filter, ↑/↓ to move, ⏎ to pick */
|
|
795
|
-
const ChoiceOverlay = observer((p) => {
|
|
796
|
-
const s = p.st;
|
|
797
|
-
const pk = s.picker;
|
|
798
|
-
const options = pk.options;
|
|
799
|
-
return /* @__PURE__ */ jsx(OverlayList, {
|
|
800
|
-
title: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
801
|
-
"⌥ ",
|
|
802
|
-
s.selected ? s.selected[1].label ?? s.selected[0] : "",
|
|
803
|
-
" ",
|
|
804
|
-
/* @__PURE__ */ jsxs(Text, {
|
|
805
|
-
color: "gray",
|
|
806
|
-
children: [
|
|
807
|
-
"(",
|
|
808
|
-
options.length,
|
|
809
|
-
" option",
|
|
810
|
-
options.length === 1 ? "" : "s",
|
|
811
|
-
")"
|
|
812
|
-
]
|
|
813
|
-
})
|
|
814
|
-
] }),
|
|
815
|
-
extraHeader: /* @__PURE__ */ jsxs(Text, {
|
|
816
|
-
color: "yellow",
|
|
817
|
-
children: [
|
|
818
|
-
"filter: ",
|
|
819
|
-
pk.filter,
|
|
820
|
-
"▌"
|
|
821
|
-
]
|
|
822
|
-
}),
|
|
823
|
-
selectedIx: pk.ix,
|
|
824
|
-
lines: s.overlayLines,
|
|
825
|
-
rows: options.map((opt, ix) => ({
|
|
826
|
-
key: opt,
|
|
827
|
-
node: /* @__PURE__ */ jsxs(Text, {
|
|
828
|
-
inverse: ix === pk.ix,
|
|
829
|
-
children: [
|
|
830
|
-
ix === pk.ix ? "▸ " : " ",
|
|
831
|
-
pk.isPicked(opt) ? "● " : "○ ",
|
|
832
|
-
opt
|
|
833
|
-
]
|
|
834
|
-
}, opt)
|
|
835
|
-
})),
|
|
836
|
-
footer: options.length === 0 ? /* @__PURE__ */ jsx(Text, {
|
|
837
|
-
color: "red",
|
|
838
|
-
children: "no match"
|
|
839
|
-
}) : pk.choiceIsMany ? /* @__PURE__ */ jsx(Text, {
|
|
840
|
-
color: "gray",
|
|
841
|
-
children: "⏎ toggles · esc done"
|
|
842
|
-
}) : void 0
|
|
843
|
-
});
|
|
844
|
-
});
|
|
845
|
-
/** modal preset picker (`P` on a text/prompt var): the label, then a dim peek at the text it
|
|
846
|
-
* writes — two presets whose names are close are told apart by their first line, not by memory */
|
|
847
|
-
const PresetOverlay = observer((p) => {
|
|
848
|
-
const s = p.st;
|
|
849
|
-
const pk = s.picker;
|
|
850
|
-
const options = pk.presetOptions;
|
|
851
|
-
const current = pk.presetVar?.toEditBuffer().trim() ?? "";
|
|
852
|
-
return /* @__PURE__ */ jsx(OverlayList, {
|
|
853
|
-
title: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
854
|
-
"presets ",
|
|
855
|
-
s.selected ? s.selected[1].label ?? s.selected[0] : "",
|
|
856
|
-
" ",
|
|
857
|
-
/* @__PURE__ */ jsx(Text, {
|
|
858
|
-
color: "gray",
|
|
859
|
-
children: "· ⏎ replaces the text"
|
|
860
|
-
})
|
|
861
|
-
] }),
|
|
862
|
-
extraHeader: /* @__PURE__ */ jsxs(Text, {
|
|
863
|
-
color: "yellow",
|
|
864
|
-
children: [
|
|
865
|
-
"filter: ",
|
|
866
|
-
pk.filter,
|
|
867
|
-
"▌"
|
|
868
|
-
]
|
|
869
|
-
}),
|
|
870
|
-
selectedIx: pk.ix,
|
|
871
|
-
lines: s.overlayLines,
|
|
872
|
-
rows: options.map((opt, ix) => ({
|
|
873
|
-
key: opt.label,
|
|
874
|
-
node: /* @__PURE__ */ jsxs(Text, {
|
|
875
|
-
inverse: ix === pk.ix,
|
|
876
|
-
wrap: "truncate",
|
|
877
|
-
children: [
|
|
878
|
-
ix === pk.ix ? "▸ " : " ",
|
|
879
|
-
opt.text.trim() === current ? "• " : " ",
|
|
880
|
-
opt.label,
|
|
881
|
-
" ",
|
|
882
|
-
/* @__PURE__ */ jsx(Text, {
|
|
883
|
-
color: "gray",
|
|
884
|
-
children: firstLine(opt.text)
|
|
885
|
-
})
|
|
886
|
-
]
|
|
887
|
-
}, opt.label)
|
|
888
|
-
})),
|
|
889
|
-
footer: options.length === 0 ? /* @__PURE__ */ jsx(Text, {
|
|
890
|
-
color: "red",
|
|
891
|
-
children: "no match"
|
|
892
|
-
}) : void 0
|
|
893
|
-
});
|
|
894
|
-
});
|
|
895
|
-
function firstLine(text) {
|
|
896
|
-
return text.split("\n").find((l) => l.trim() !== "") ?? "";
|
|
897
|
-
}
|
|
898
|
-
/** modal size picker: presets, or type `WxH` and ⏎ for a custom size */
|
|
899
|
-
const SizeOverlay = observer((p) => {
|
|
900
|
-
const s = p.st;
|
|
901
|
-
const pk = s.picker;
|
|
902
|
-
const options = pk.options;
|
|
903
|
-
return /* @__PURE__ */ jsx(OverlayList, {
|
|
904
|
-
title: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
905
|
-
"size ",
|
|
906
|
-
s.selected ? s.selected[1].label ?? s.selected[0] : "",
|
|
907
|
-
" ",
|
|
908
|
-
/* @__PURE__ */ jsx(Text, {
|
|
909
|
-
color: "gray",
|
|
910
|
-
children: "· type WxH for custom"
|
|
911
|
-
})
|
|
912
|
-
] }),
|
|
913
|
-
extraHeader: /* @__PURE__ */ jsxs(Text, {
|
|
914
|
-
color: pk.invalid ? "red" : "yellow",
|
|
915
|
-
children: [
|
|
916
|
-
"filter: ",
|
|
917
|
-
pk.filter,
|
|
918
|
-
"▌"
|
|
919
|
-
]
|
|
920
|
-
}),
|
|
921
|
-
selectedIx: pk.ix,
|
|
922
|
-
lines: s.overlayLines,
|
|
923
|
-
rows: options.map((opt, ix) => ({
|
|
924
|
-
key: opt,
|
|
925
|
-
node: /* @__PURE__ */ jsxs(Text, {
|
|
926
|
-
inverse: ix === pk.ix,
|
|
927
|
-
children: [ix === pk.ix ? "▸ " : " ", opt]
|
|
928
|
-
}, opt)
|
|
929
|
-
})),
|
|
930
|
-
footer: options.length === 0 ? /* @__PURE__ */ jsxs(Text, {
|
|
931
|
-
color: "cyan",
|
|
932
|
-
children: [
|
|
933
|
-
"⏎ to use custom size “",
|
|
934
|
-
pk.filter,
|
|
935
|
-
"”"
|
|
936
|
-
]
|
|
937
|
-
}) : void 0
|
|
938
|
-
});
|
|
939
|
-
});
|
|
940
|
-
//#endregion
|
|
941
|
-
//#region src/cli/tui/components/PreviewPanel.tsx
|
|
942
|
-
/** right-side panel: selected-lora preview in the loras overlay, live latent while running,
|
|
943
|
-
* last output after — plus the `p` settings menu (mode 'preview') rendered in place.
|
|
944
|
-
* protocol terminals: the body is BLANK cells — useProtocolImage paints the real image over them */
|
|
945
|
-
const PreviewPanel = observer((p) => {
|
|
946
|
-
const s = p.st;
|
|
947
|
-
const pv = s.preview;
|
|
948
|
-
if (pv.menuOpen) return /* @__PURE__ */ jsxs(Box, {
|
|
949
|
-
borderStyle: "double",
|
|
950
|
-
paddingX: 1,
|
|
951
|
-
flexDirection: "column",
|
|
952
|
-
flexShrink: 0,
|
|
953
|
-
width: pv.width + 4,
|
|
954
|
-
children: [
|
|
955
|
-
/* @__PURE__ */ jsx(Box, {
|
|
956
|
-
marginTop: -1,
|
|
957
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
958
|
-
color: "gray",
|
|
959
|
-
children: "(p)review · settings"
|
|
960
|
-
})
|
|
961
|
-
}),
|
|
962
|
-
pv.menuRows.map((row, ix) => {
|
|
963
|
-
const sel = ix === pv.menuIx;
|
|
964
|
-
return /* @__PURE__ */ jsxs(Text, {
|
|
965
|
-
inverse: sel,
|
|
966
|
-
wrap: "truncate",
|
|
967
|
-
children: [
|
|
968
|
-
sel ? "▸ " : " ",
|
|
969
|
-
row.label.padEnd(14),
|
|
970
|
-
/* @__PURE__ */ jsx(Text, {
|
|
971
|
-
bold: true,
|
|
972
|
-
children: row.value
|
|
973
|
-
})
|
|
974
|
-
]
|
|
975
|
-
}, row.key);
|
|
976
|
-
}),
|
|
977
|
-
/* @__PURE__ */ jsx(Text, { children: " " }),
|
|
978
|
-
/* @__PURE__ */ jsx(Text, {
|
|
979
|
-
color: "gray",
|
|
980
|
-
wrap: "truncate",
|
|
981
|
-
children: "←→ change · ↑↓ move · ⏎/p/esc done"
|
|
982
|
-
})
|
|
983
|
-
]
|
|
984
|
-
});
|
|
985
|
-
const overlayMode = pv.overlayActive;
|
|
986
|
-
const wantLatent = s.exec.running && pv.duringRun !== "last-output";
|
|
987
|
-
const showLatent = !overlayMode && wantLatent && (pv.latentAnsi != null || pv.latentBytes != null);
|
|
988
|
-
const label = overlayMode ? pv.overlay?.name ?? (s.mode === "overlay-loras" ? "lora" : "image") : showLatent ? pv.duringRun === "latent-small" ? "latent small" : "latent" : "output";
|
|
989
|
-
const placeholder = overlayMode ? pv.overlay?.note ?? (s.mode === "overlay-loras" ? "(pick a lora)" : "(pick an image)") : pv.latentsMissing ? "(no latents from the server — launch comfy with --preview-method auto)" : "(no image yet)";
|
|
990
|
-
const content = pv.useNative ? null : overlayMode ? pv.overlay?.ansi ?? null : showLatent ? pv.latentAnsi ?? pv.outputAnsi : pv.outputAnsi;
|
|
991
|
-
const reserveRect = pv.useNative && (pv.protocolImage != null || pv.protocolImageCorner != null);
|
|
992
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
993
|
-
borderStyle: "round",
|
|
994
|
-
paddingX: 1,
|
|
995
|
-
flexDirection: "column",
|
|
996
|
-
flexShrink: 0,
|
|
997
|
-
width: pv.width + 4,
|
|
998
|
-
children: [/* @__PURE__ */ jsx(Box, {
|
|
999
|
-
marginTop: -1,
|
|
1000
|
-
children: /* @__PURE__ */ jsxs(Text, {
|
|
1001
|
-
color: "gray",
|
|
1002
|
-
wrap: "truncate",
|
|
1003
|
-
children: [
|
|
1004
|
-
"(p)review · ",
|
|
1005
|
-
label,
|
|
1006
|
-
" · ",
|
|
1007
|
-
pv.renderer,
|
|
1008
|
-
pv.latentsMissing ? /* @__PURE__ */ jsx(Text, {
|
|
1009
|
-
color: "red",
|
|
1010
|
-
children: " · no latents!"
|
|
1011
|
-
}) : null
|
|
1012
|
-
]
|
|
1013
|
-
})
|
|
1014
|
-
}), reserveRect ? Array.from({ length: pv.height }, (_, ix) => /* @__PURE__ */ jsx(Text, { children: " " }, ix)) : content != null ? /* @__PURE__ */ jsx(Text, { children: content }) : /* @__PURE__ */ jsx(Text, {
|
|
1015
|
-
color: "gray",
|
|
1016
|
-
children: placeholder
|
|
1017
|
-
})]
|
|
1018
|
-
});
|
|
1019
|
-
});
|
|
1020
|
-
//#endregion
|
|
1021
|
-
//#region src/cli/tui/components/EditField.tsx
|
|
1022
|
-
const EDIT_WINDOW = 56;
|
|
1023
|
-
/** inline single-line editor rendering (numbers, custom prompts) */
|
|
1024
|
-
const EditField = observer((p) => {
|
|
1025
|
-
const ed = p.st.editor;
|
|
1026
|
-
const cs = [...ed.buffer];
|
|
1027
|
-
const windowStart = Math.max(0, Math.min(ed.cursor - Math.floor(EDIT_WINDOW * .7), cs.length - EDIT_WINDOW));
|
|
1028
|
-
const before = cs.slice(windowStart, ed.cursor).join("");
|
|
1029
|
-
const at = cs[ed.cursor] ?? " ";
|
|
1030
|
-
const after = cs.slice(ed.cursor + 1, windowStart + EDIT_WINDOW).join("");
|
|
1031
|
-
return /* @__PURE__ */ jsxs(Text, {
|
|
1032
|
-
color: ed.invalid ? "red" : "yellow",
|
|
1033
|
-
children: [
|
|
1034
|
-
windowStart > 0 ? "…" : "",
|
|
1035
|
-
before,
|
|
1036
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1037
|
-
inverse: true,
|
|
1038
|
-
children: at
|
|
1039
|
-
}),
|
|
1040
|
-
after,
|
|
1041
|
-
windowStart + EDIT_WINDOW < cs.length ? "…" : ""
|
|
1042
|
-
]
|
|
1043
|
-
});
|
|
1044
|
-
});
|
|
1045
|
-
//#endregion
|
|
1046
|
-
//#region src/cli/tui/components/PromptOverlay.tsx
|
|
1047
|
-
/** modal name prompt: renders any EditorSt CUSTOM session (new/rename/duplicate draft, …) */
|
|
1048
|
-
const PromptOverlay = observer((p) => {
|
|
1049
|
-
const ed = p.st.editor;
|
|
1050
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
1051
|
-
borderStyle: "double",
|
|
1052
|
-
paddingX: 1,
|
|
1053
|
-
flexDirection: "column",
|
|
1054
|
-
children: [
|
|
1055
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1056
|
-
bold: true,
|
|
1057
|
-
children: ed.customTitle
|
|
1058
|
-
}),
|
|
1059
|
-
/* @__PURE__ */ jsx(EditField, { st: p.st }),
|
|
1060
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1061
|
-
color: "gray",
|
|
1062
|
-
children: "⏎ apply · esc cancel"
|
|
1063
|
-
})
|
|
1064
|
-
]
|
|
1065
|
-
});
|
|
1066
|
-
});
|
|
1067
|
-
//#endregion
|
|
1068
|
-
//#region src/cli/tui/imagePicker/fsListing.ts
|
|
1069
|
-
/** `name.PNG` matches extensions `['png']` — extensions are lowercase, no dots */
|
|
1070
|
-
function hasImageExtension(name, extensions) {
|
|
1071
|
-
const dot = name.lastIndexOf(".");
|
|
1072
|
-
if (dot <= 0) return false;
|
|
1073
|
-
return extensions.includes(name.slice(dot + 1).toLowerCase());
|
|
1074
|
-
}
|
|
1075
|
-
/**
|
|
1076
|
-
* ONE folder for the picker: dirs first then images, both alphabetical,
|
|
1077
|
-
* images filtered by extension. Dot FILES are junk (.DS_Store) and skipped;
|
|
1078
|
-
* dot DIRS are listed — .comfy-ts/outputs must be browsable. Symlinks are
|
|
1079
|
-
* followed (a dangling one is skipped). Pure over fs — an unreadable dir
|
|
1080
|
-
* THROWS, the caller surfaces it (never a silent empty listing).
|
|
1081
|
-
*/
|
|
1082
|
-
function listImageDir(dir, extensions) {
|
|
1083
|
-
const dirs = [];
|
|
1084
|
-
const images = [];
|
|
1085
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1086
|
-
let isDir = entry.isDirectory();
|
|
1087
|
-
let isFile = entry.isFile();
|
|
1088
|
-
if (entry.isSymbolicLink()) try {
|
|
1089
|
-
const target = statSync(join(dir, entry.name));
|
|
1090
|
-
isDir = target.isDirectory();
|
|
1091
|
-
isFile = target.isFile();
|
|
1092
|
-
} catch {
|
|
1093
|
-
continue;
|
|
1094
|
-
}
|
|
1095
|
-
if (entry.name.startsWith(".") && !isDir) continue;
|
|
1096
|
-
if (isDir) dirs.push(entry.name);
|
|
1097
|
-
else if (isFile && hasImageExtension(entry.name, extensions)) images.push(entry.name);
|
|
1098
|
-
}
|
|
1099
|
-
dirs.sort((a, b) => a.localeCompare(b));
|
|
1100
|
-
images.sort((a, b) => a.localeCompare(b));
|
|
1101
|
-
return {
|
|
1102
|
-
dirs,
|
|
1103
|
-
images
|
|
1104
|
-
};
|
|
1105
|
-
}
|
|
1106
|
-
/** parent for `←` navigation — the fs root is its own parent (never ascends past it) */
|
|
1107
|
-
function parentDir(dir) {
|
|
1108
|
-
return dirname(dir);
|
|
1109
|
-
}
|
|
1110
|
-
/**
|
|
1111
|
-
* image-picker favorites + recents + lastFolder — loraKeywords pattern:
|
|
1112
|
-
* observable, loaded once, written through on every mutation. Human-editable
|
|
1113
|
-
* json at `.comfy-ts/image-picker.json` (hand-tuned data, NOT under cache/ —
|
|
1114
|
-
* survives a cache wipe):
|
|
1115
|
-
* { "favorites": ["/abs/dir"], "recents": ["/abs/img.png"], "lastFolder": "/abs/dir" }
|
|
1116
|
-
* A corrupt file logs loud and starts fresh, never blocks the TUI. The class
|
|
1117
|
-
* takes its file path explicitly so tests round-trip it headless; the TUI
|
|
1118
|
-
* uses the ONE lazy module singleton below.
|
|
1119
|
-
*/
|
|
1120
|
-
var PickerPrefs = class {
|
|
1121
|
-
constructor(path) {
|
|
1122
|
-
this.path = path;
|
|
1123
|
-
this.favorites = [];
|
|
1124
|
-
this.recents = [];
|
|
1125
|
-
this.lastFolder = null;
|
|
1126
|
-
this.load();
|
|
1127
|
-
makeAutoObservable(this);
|
|
1128
|
-
}
|
|
1129
|
-
load() {
|
|
1130
|
-
if (!existsSync(this.path)) return;
|
|
1131
|
-
try {
|
|
1132
|
-
const raw = JSON.parse(readFileSync(this.path, "utf8"));
|
|
1133
|
-
if (raw == null || typeof raw !== "object") throw new Error("not a json object");
|
|
1134
|
-
const o = raw;
|
|
1135
|
-
if (Array.isArray(o.favorites)) this.favorites = o.favorites.filter((f) => typeof f === "string");
|
|
1136
|
-
if (Array.isArray(o.recents)) this.recents = o.recents.filter((r) => typeof r === "string").slice(0, 20);
|
|
1137
|
-
if (typeof o.lastFolder === "string") this.lastFolder = o.lastFolder;
|
|
1138
|
-
} catch (e) {
|
|
1139
|
-
logError(`[imagePicker] unreadable ${this.path} — starting fresh: ${String(e)}`);
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
write() {
|
|
1143
|
-
try {
|
|
1144
|
-
mkdirSync(dirname(this.path), { recursive: true });
|
|
1145
|
-
const json = {
|
|
1146
|
-
favorites: this.favorites,
|
|
1147
|
-
recents: this.recents,
|
|
1148
|
-
lastFolder: this.lastFolder
|
|
1149
|
-
};
|
|
1150
|
-
writeFileSync(this.path, `${JSON.stringify(json, null, 2)}\n`);
|
|
1151
|
-
} catch (e) {
|
|
1152
|
-
logError(`[imagePicker] write failed ${this.path}: ${String(e)}`);
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
isFavorite(dir) {
|
|
1156
|
-
return this.favorites.includes(dir);
|
|
1157
|
-
}
|
|
1158
|
-
toggleFavorite(dir) {
|
|
1159
|
-
this.favorites = this.favorites.includes(dir) ? this.favorites.filter((f) => f !== dir) : [...this.favorites, dir];
|
|
1160
|
-
this.write();
|
|
1161
|
-
}
|
|
1162
|
-
/** a pick records the image (newest first, deduped, capped) AND remembers its folder */
|
|
1163
|
-
recordPick(imagePath) {
|
|
1164
|
-
this.recents = [imagePath, ...this.recents.filter((r) => r !== imagePath)].slice(0, 20);
|
|
1165
|
-
this.lastFolder = dirname(imagePath);
|
|
1166
|
-
this.write();
|
|
1167
|
-
}
|
|
1168
|
-
};
|
|
1169
|
-
let _prefs = null;
|
|
1170
|
-
/** the TUI's store, bound lazily to `.comfy-ts/image-picker.json` (gitignored) */
|
|
1171
|
-
function pickerPrefs() {
|
|
1172
|
-
if (_prefs == null) _prefs = new PickerPrefs(join(comfyts.baseFolder, "image-picker.json"));
|
|
1173
|
-
return _prefs;
|
|
1174
|
-
}
|
|
1175
|
-
//#endregion
|
|
1176
|
-
//#region src/utils/fuzzyMatch.ts
|
|
1177
|
-
/** case-insensitive subsequence match: 'wide' hits '16:9 (Widescreen)' */
|
|
1178
|
-
function fuzzyMatch(needle, hay) {
|
|
1179
|
-
const n = needle.toLowerCase();
|
|
1180
|
-
const h = hay.toLowerCase();
|
|
1181
|
-
let i = 0;
|
|
1182
|
-
for (const ch of h) if (ch === n[i]) i++;
|
|
1183
|
-
return i >= n.length;
|
|
1184
|
-
}
|
|
1185
|
-
//#endregion
|
|
1186
|
-
//#region src/utils/ansiImage.ts
|
|
1187
|
-
/**
|
|
1188
|
-
* render an image as truecolor half-block ANSI: each char cell is 1px wide and
|
|
1189
|
-
* 2px tall (bg color = top pixel, fg '▄' = bottom pixel). Works in any
|
|
1190
|
-
* truecolor terminal and — unlike protocol images (iTerm/kitty/sixel) —
|
|
1191
|
-
* survives ink's layout engine. width/height are CHAR CELLS.
|
|
1192
|
-
*/
|
|
1193
|
-
async function imageBufferToAnsi(input, p) {
|
|
1194
|
-
const { data, info } = await sharp(input).flatten({ background: p.background ?? "#1e1e1e" }).resize(p.width, p.height * 2, { fit: "inside" }).raw().toBuffer({ resolveWithObject: true });
|
|
1195
|
-
const w = info.width;
|
|
1196
|
-
const h = info.height;
|
|
1197
|
-
const c = info.channels;
|
|
1198
|
-
const px = (x, y) => {
|
|
1199
|
-
const i = (y * w + x) * c;
|
|
1200
|
-
return [
|
|
1201
|
-
data[i] ?? 0,
|
|
1202
|
-
data[i + 1] ?? 0,
|
|
1203
|
-
data[i + 2] ?? 0
|
|
1204
|
-
];
|
|
1205
|
-
};
|
|
1206
|
-
const rows = [];
|
|
1207
|
-
for (let y = 0; y < h; y += 2) {
|
|
1208
|
-
let row = "";
|
|
1209
|
-
for (let x = 0; x < w; x++) {
|
|
1210
|
-
const [tr, tg, tb] = px(x, y);
|
|
1211
|
-
const [br, bg, bb] = y + 1 < h ? px(x, y + 1) : px(x, y);
|
|
1212
|
-
row += `\x1b[48;2;${tr};${tg};${tb}m\x1b[38;2;${br};${bg};${bb}m▄`;
|
|
1213
|
-
}
|
|
1214
|
-
rows.push(row + "\x1B[0m");
|
|
1215
|
-
}
|
|
1216
|
-
return rows.join("\n");
|
|
1217
|
-
}
|
|
1218
|
-
//#endregion
|
|
1219
|
-
//#region src/cli/tui/imagePicker/ImagePickerSt.ts
|
|
1220
|
-
const PICKER_PANES = [
|
|
1221
|
-
"browse",
|
|
1222
|
-
"favorites",
|
|
1223
|
-
"recents"
|
|
1224
|
-
];
|
|
1225
|
-
/** `~`-contract $HOME for display (ImageVar.display's convention) */
|
|
1226
|
-
function contractHome(path) {
|
|
1227
|
-
const home = homedir();
|
|
1228
|
-
return path.startsWith(`${home}/`) ? `~${path.slice(home.length)}` : path;
|
|
1229
|
-
}
|
|
1230
|
-
/**
|
|
1231
|
-
* image-picker overlay (mode 'overlay-image'): browse the disk for an image
|
|
1232
|
-
* var, three panes (browse / favorites / recents), filter-as-you-type, the
|
|
1233
|
-
* highlighted image previews into the panel via PreviewSt's overlay slot.
|
|
1234
|
-
*/
|
|
1235
|
-
var ImagePickerSt = class {
|
|
1236
|
-
constructor(st) {
|
|
1237
|
-
this.st = st;
|
|
1238
|
-
this.pane = "browse";
|
|
1239
|
-
this.folder = process.cwd();
|
|
1240
|
-
this.ix = 0;
|
|
1241
|
-
this.filter = "";
|
|
1242
|
-
this._busy = false;
|
|
1243
|
-
makeAutoObservable(this, { st: false });
|
|
1244
|
-
this.st.disposers.push(reaction(() => this.st.mode === "overlay-image" ? this.highlightedImage : null, () => void this.refreshPreview(), { delay: this.st.timing.previewMs }));
|
|
1245
|
-
}
|
|
1246
|
-
/** kind-narrowing cast sanctioned (agent/coding.md), `kind` is the tag */
|
|
1247
|
-
get selectedVar() {
|
|
1248
|
-
const sel = this.st.selected?.[1];
|
|
1249
|
-
return sel?.kind === "image" || sel?.kind === "audio" || sel?.kind === "video" ? sel : null;
|
|
1250
|
-
}
|
|
1251
|
-
get folderDisplay() {
|
|
1252
|
-
return contractHome(this.folder);
|
|
1253
|
-
}
|
|
1254
|
-
/** begin() open order: dirname(value) → persisted lastFolder → opts.folder → cwd */
|
|
1255
|
-
initialFolder(iv) {
|
|
1256
|
-
const candidates = [
|
|
1257
|
-
iv.isSet() ? dirname(iv.absPath()) : null,
|
|
1258
|
-
pickerPrefs().lastFolder,
|
|
1259
|
-
iv.opts.folder != null ? resolve(iv.opts.folder) : null
|
|
1260
|
-
];
|
|
1261
|
-
for (const c of candidates) try {
|
|
1262
|
-
if (c != null && statSync(c).isDirectory()) return c;
|
|
1263
|
-
} catch {}
|
|
1264
|
-
return process.cwd();
|
|
1265
|
-
}
|
|
1266
|
-
begin() {
|
|
1267
|
-
const iv = this.selectedVar;
|
|
1268
|
-
if (iv == null) return;
|
|
1269
|
-
this.st.mode = "overlay-image";
|
|
1270
|
-
this.pane = "browse";
|
|
1271
|
-
this.filter = "";
|
|
1272
|
-
this.ix = 0;
|
|
1273
|
-
this.folder = this.initialFolder(iv);
|
|
1274
|
-
this.st.preview.clearOverlayImage();
|
|
1275
|
-
}
|
|
1276
|
-
cancel() {
|
|
1277
|
-
this.st.mode = "nav";
|
|
1278
|
-
}
|
|
1279
|
-
/** every row of the active pane BEFORE the filter, plus the browse-pane
|
|
1280
|
-
* read error (unreadable folder: shown IN the overlay, browsing elsewhere
|
|
1281
|
-
* stays possible). Computed with NO side effects — mobx forbids them. */
|
|
1282
|
-
get paneListing() {
|
|
1283
|
-
if (this.pane === "favorites") return {
|
|
1284
|
-
rows: pickerPrefs().favorites.map((dir) => ({
|
|
1285
|
-
kind: "dir",
|
|
1286
|
-
name: contractHome(dir),
|
|
1287
|
-
path: dir
|
|
1288
|
-
})),
|
|
1289
|
-
error: null
|
|
1290
|
-
};
|
|
1291
|
-
if (this.pane === "recents") return {
|
|
1292
|
-
rows: this.recentsForVar().map((img) => ({
|
|
1293
|
-
kind: "image",
|
|
1294
|
-
name: contractHome(img),
|
|
1295
|
-
path: img,
|
|
1296
|
-
missing: !existsSync(img)
|
|
1297
|
-
})),
|
|
1298
|
-
error: null
|
|
1299
|
-
};
|
|
1300
|
-
const iv = this.selectedVar;
|
|
1301
|
-
if (iv == null) return {
|
|
1302
|
-
rows: [],
|
|
1303
|
-
error: null
|
|
1304
|
-
};
|
|
1305
|
-
try {
|
|
1306
|
-
const listing = listImageDir(this.folder, iv.extensions);
|
|
1307
|
-
return {
|
|
1308
|
-
rows: [...listing.dirs.map((d) => ({
|
|
1309
|
-
kind: "dir",
|
|
1310
|
-
name: d,
|
|
1311
|
-
path: resolve(this.folder, d)
|
|
1312
|
-
})), ...listing.images.map((f) => ({
|
|
1313
|
-
kind: "image",
|
|
1314
|
-
name: f,
|
|
1315
|
-
path: resolve(this.folder, f),
|
|
1316
|
-
missing: false
|
|
1317
|
-
}))],
|
|
1318
|
-
error: null
|
|
1319
|
-
};
|
|
1320
|
-
} catch (e) {
|
|
1321
|
-
return {
|
|
1322
|
-
rows: [],
|
|
1323
|
-
error: extractErrorMessage(e)
|
|
1324
|
-
};
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
recentsForVar() {
|
|
1328
|
-
const exts = this.selectedVar?.extensions ?? [];
|
|
1329
|
-
return pickerPrefs().recents.filter((f) => exts.includes(extensionOf(f)));
|
|
1330
|
-
}
|
|
1331
|
-
get listingError() {
|
|
1332
|
-
return this.paneListing.error;
|
|
1333
|
-
}
|
|
1334
|
-
/** what the overlay renders: pane rows surviving the filter */
|
|
1335
|
-
get rows() {
|
|
1336
|
-
const all = this.paneListing.rows;
|
|
1337
|
-
if (this.filter === "") return all;
|
|
1338
|
-
return all.filter((r) => fuzzyMatch(this.filter, r.name));
|
|
1339
|
-
}
|
|
1340
|
-
get current() {
|
|
1341
|
-
return this.rows[this.ix] ?? null;
|
|
1342
|
-
}
|
|
1343
|
-
/** feeds the preview reaction: only a real, present image highlights (an audio or video
|
|
1344
|
-
* row has nothing to paint) */
|
|
1345
|
-
get highlightedImage() {
|
|
1346
|
-
if (this.selectedVar?.kind !== "image") return null;
|
|
1347
|
-
const row = this.current;
|
|
1348
|
-
return row?.kind === "image" && !row.missing ? row.path : null;
|
|
1349
|
-
}
|
|
1350
|
-
move(delta) {
|
|
1351
|
-
const len = this.rows.length;
|
|
1352
|
-
if (len === 0) return;
|
|
1353
|
-
this.ix = (this.ix + delta + len) % len;
|
|
1354
|
-
}
|
|
1355
|
-
cyclePane() {
|
|
1356
|
-
const ix = PICKER_PANES.indexOf(this.pane);
|
|
1357
|
-
this.pane = PICKER_PANES[(ix + 1) % PICKER_PANES.length] ?? "browse";
|
|
1358
|
-
this.ix = 0;
|
|
1359
|
-
this.filter = "";
|
|
1360
|
-
}
|
|
1361
|
-
goto(dir) {
|
|
1362
|
-
this.pane = "browse";
|
|
1363
|
-
this.folder = dir;
|
|
1364
|
-
this.ix = 0;
|
|
1365
|
-
this.filter = "";
|
|
1366
|
-
}
|
|
1367
|
-
/** `→`: enter the highlighted dir (browse pane; images select via ⏎ only) */
|
|
1368
|
-
enter() {
|
|
1369
|
-
const row = this.current;
|
|
1370
|
-
if (this.pane === "browse" && row?.kind === "dir") this.goto(row.path);
|
|
1371
|
-
}
|
|
1372
|
-
/** `←`: parent dir (browse pane; the fs root is its own parent) */
|
|
1373
|
-
goParent() {
|
|
1374
|
-
if (this.pane !== "browse") return;
|
|
1375
|
-
const parent = parentDir(this.folder);
|
|
1376
|
-
if (parent !== this.folder) this.goto(parent);
|
|
1377
|
-
}
|
|
1378
|
-
/** ⏎: enter a dir (a favorite jumps browse into it), select an image */
|
|
1379
|
-
commit() {
|
|
1380
|
-
const row = this.current;
|
|
1381
|
-
if (row == null) return;
|
|
1382
|
-
if (row.kind === "dir") return this.goto(row.path);
|
|
1383
|
-
if (row.missing) return;
|
|
1384
|
-
this.select(row.path);
|
|
1385
|
-
}
|
|
1386
|
-
/** the pick: absolute path into the var, recents + lastFolder recorded */
|
|
1387
|
-
select(absPath) {
|
|
1388
|
-
const iv = this.selectedVar;
|
|
1389
|
-
if (iv == null) return;
|
|
1390
|
-
iv.set(absPath);
|
|
1391
|
-
pickerPrefs().recordPick(absPath);
|
|
1392
|
-
this.st.mode = "nav";
|
|
1393
|
-
}
|
|
1394
|
-
/** ⌃F: favorite FOLDERS only — a dir row favorites it, an image row favorites the current folder */
|
|
1395
|
-
toggleFavorite() {
|
|
1396
|
-
const row = this.current;
|
|
1397
|
-
const dir = row == null ? this.pane === "browse" ? this.folder : null : row.kind === "dir" ? row.path : this.pane === "browse" ? this.folder : dirname(row.path);
|
|
1398
|
-
if (dir == null) return;
|
|
1399
|
-
pickerPrefs().toggleFavorite(dir);
|
|
1400
|
-
this.ix = Math.max(0, Math.min(this.ix, this.rows.length - 1));
|
|
1401
|
-
}
|
|
1402
|
-
isFavorite(dir) {
|
|
1403
|
-
return pickerPrefs().isFavorite(dir);
|
|
1404
|
-
}
|
|
1405
|
-
filterInput(chunk) {
|
|
1406
|
-
this.filter += chunk;
|
|
1407
|
-
this.ix = 0;
|
|
1408
|
-
}
|
|
1409
|
-
filterBackspace() {
|
|
1410
|
-
this.filter = this.filter.slice(0, -1);
|
|
1411
|
-
this.ix = 0;
|
|
1412
|
-
}
|
|
1413
|
-
/** ⌥⌫ / ⌃W: drop the last word of the filter */
|
|
1414
|
-
filterDeleteWord() {
|
|
1415
|
-
this.filter = this.filter.replace(/\s*\S+\s*$/, "");
|
|
1416
|
-
this.ix = 0;
|
|
1417
|
-
}
|
|
1418
|
-
async refreshPreview() {
|
|
1419
|
-
if (this.st.mode !== "overlay-image") {
|
|
1420
|
-
if (!this.st.preview.overlayActive) this.st.preview.clearOverlayImage();
|
|
1421
|
-
return;
|
|
1422
|
-
}
|
|
1423
|
-
const path = this.highlightedImage;
|
|
1424
|
-
if (path == null) {
|
|
1425
|
-
this.st.preview.clearOverlayImage();
|
|
1426
|
-
return;
|
|
1427
|
-
}
|
|
1428
|
-
if (this._busy) return;
|
|
1429
|
-
this._busy = true;
|
|
1430
|
-
try {
|
|
1431
|
-
const bytes = new Uint8Array(readFileSync(path));
|
|
1432
|
-
if (this.st.preview.useNative) this.st.preview.setOverlayImage({
|
|
1433
|
-
bytes: await protocolReadyBytes(bytes),
|
|
1434
|
-
ansi: null,
|
|
1435
|
-
name: basename(path),
|
|
1436
|
-
note: null
|
|
1437
|
-
}, "overlay-image");
|
|
1438
|
-
else {
|
|
1439
|
-
const ansi = await imageBufferToAnsi(bytes, {
|
|
1440
|
-
width: this.st.preview.width,
|
|
1441
|
-
height: this.st.preview.height
|
|
1442
|
-
});
|
|
1443
|
-
this.st.preview.setOverlayImage({
|
|
1444
|
-
bytes: null,
|
|
1445
|
-
ansi,
|
|
1446
|
-
name: basename(path),
|
|
1447
|
-
note: null
|
|
1448
|
-
}, "overlay-image");
|
|
1449
|
-
}
|
|
1450
|
-
} catch (e) {
|
|
1451
|
-
this.st.preview.setOverlayImage({
|
|
1452
|
-
bytes: null,
|
|
1453
|
-
ansi: null,
|
|
1454
|
-
name: basename(path),
|
|
1455
|
-
note: extractErrorMessage(e)
|
|
1456
|
-
}, "overlay-image");
|
|
1457
|
-
} finally {
|
|
1458
|
-
this._busy = false;
|
|
1459
|
-
if (this.st.mode === "overlay-image" && this.highlightedImage !== path) this.refreshPreview();
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
};
|
|
1463
|
-
//#endregion
|
|
1464
|
-
//#region src/cli/tui/imagePicker/ImagePickerOverlay.tsx
|
|
1465
|
-
/** modal image browser: three panes (tab), dirs enter, ⏎ picks, ★ = favorite folder */
|
|
1466
|
-
const ImagePickerOverlay = observer((p) => {
|
|
1467
|
-
const s = p.st;
|
|
1468
|
-
const ip = s.imagePicker;
|
|
1469
|
-
const iv = ip.selectedVar;
|
|
1470
|
-
if (iv == null) return null;
|
|
1471
|
-
const rows = ip.rows;
|
|
1472
|
-
return /* @__PURE__ */ jsx(OverlayList, {
|
|
1473
|
-
title: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1474
|
-
s.selected?.[1].label ?? s.selected?.[0],
|
|
1475
|
-
" ",
|
|
1476
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1477
|
-
color: "gray",
|
|
1478
|
-
children: iv.display()
|
|
1479
|
-
})
|
|
1480
|
-
] }),
|
|
1481
|
-
extraHeader: /* @__PURE__ */ jsxs(Box, {
|
|
1482
|
-
flexDirection: "column",
|
|
1483
|
-
children: [/* @__PURE__ */ jsxs(Text, { children: [PICKER_PANES.map((pane, ix) => /* @__PURE__ */ jsxs(Text, { children: [ix > 0 ? /* @__PURE__ */ jsx(Text, {
|
|
1484
|
-
color: "gray",
|
|
1485
|
-
children: " · "
|
|
1486
|
-
}) : null, /* @__PURE__ */ jsx(Text, {
|
|
1487
|
-
color: pane === ip.pane ? "cyan" : "gray",
|
|
1488
|
-
bold: pane === ip.pane,
|
|
1489
|
-
underline: pane === ip.pane,
|
|
1490
|
-
children: pane
|
|
1491
|
-
})] }, pane)), ip.pane === "browse" ? /* @__PURE__ */ jsxs(Text, {
|
|
1492
|
-
color: "gray",
|
|
1493
|
-
children: [" ", ip.folderDisplay]
|
|
1494
|
-
}) : null] }), /* @__PURE__ */ jsxs(Text, {
|
|
1495
|
-
color: "yellow",
|
|
1496
|
-
children: [
|
|
1497
|
-
"filter: ",
|
|
1498
|
-
ip.filter,
|
|
1499
|
-
"▌"
|
|
1500
|
-
]
|
|
1501
|
-
})]
|
|
1502
|
-
}),
|
|
1503
|
-
selectedIx: ip.ix,
|
|
1504
|
-
lines: s.overlayLines,
|
|
1505
|
-
rows: rows.map((row, ix) => {
|
|
1506
|
-
const sel = ix === ip.ix;
|
|
1507
|
-
const fav = row.kind === "dir" && ip.isFavorite(row.path);
|
|
1508
|
-
const missing = row.kind === "image" && row.missing;
|
|
1509
|
-
return {
|
|
1510
|
-
key: `${row.kind}:${row.path}`,
|
|
1511
|
-
node: /* @__PURE__ */ jsxs(Text, {
|
|
1512
|
-
inverse: sel,
|
|
1513
|
-
color: row.kind === "dir" ? "blue" : missing ? "gray" : void 0,
|
|
1514
|
-
dimColor: missing,
|
|
1515
|
-
children: [
|
|
1516
|
-
sel ? "▸ " : " ",
|
|
1517
|
-
fav ? "★ " : " ",
|
|
1518
|
-
row.name,
|
|
1519
|
-
row.kind === "dir" ? "/" : "",
|
|
1520
|
-
missing ? " (missing)" : ""
|
|
1521
|
-
]
|
|
1522
|
-
}, `${row.kind}:${row.path}`)
|
|
1523
|
-
};
|
|
1524
|
-
}),
|
|
1525
|
-
footer: rows.length === 0 ? /* @__PURE__ */ jsx(Text, {
|
|
1526
|
-
color: "red",
|
|
1527
|
-
children: ip.listingError ?? (ip.filter !== "" ? "no match" : `no ${ip.selectedVar?.kind ?? "image"} files here`)
|
|
1528
|
-
}) : void 0
|
|
1529
|
-
});
|
|
1530
|
-
});
|
|
1531
|
-
//#endregion
|
|
1532
|
-
//#region src/cli/tui/components/LogsPanel.tsx
|
|
1533
|
-
const ERROR_RE = /error|exception|traceback|failed/i;
|
|
1534
|
-
/** last server console lines (LogsSt), below the vars panel */
|
|
1535
|
-
const LogsPanel = observer((p) => {
|
|
1536
|
-
const rows = p.st.logs.tail(p.st.termRows < 30 ? 4 : 8);
|
|
1537
|
-
if (rows.length === 0) return null;
|
|
1538
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
1539
|
-
borderStyle: "round",
|
|
1540
|
-
borderColor: "gray",
|
|
1541
|
-
paddingX: 1,
|
|
1542
|
-
flexDirection: "column",
|
|
1543
|
-
flexShrink: 0,
|
|
1544
|
-
children: [/* @__PURE__ */ jsx(Box, {
|
|
1545
|
-
marginTop: -1,
|
|
1546
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1547
|
-
color: "gray",
|
|
1548
|
-
children: "comfy host logs"
|
|
1549
|
-
})
|
|
1550
|
-
}), rows.map((line, ix) => /* @__PURE__ */ jsx(Text, {
|
|
1551
|
-
color: ERROR_RE.test(line) ? "red" : "gray",
|
|
1552
|
-
wrap: "truncate-end",
|
|
1553
|
-
children: line
|
|
1554
|
-
}, ix))]
|
|
1555
|
-
});
|
|
1556
|
-
});
|
|
1557
|
-
//#endregion
|
|
1558
|
-
//#region src/cli/tui/components/TextOverlay.tsx
|
|
1559
|
-
/** modal multiline editor: real newlines, caret rendered per code point.
|
|
1560
|
-
* The cursor's LOGICAL line is background-highlighted (word wrap hides line
|
|
1561
|
-
* bounds — the highlight shows exactly what ⌥↑↓ will move); on prompt vars,
|
|
1562
|
-
* `//` comment lines render dim gray, `- ` negative lines red, and the
|
|
1563
|
-
* injected lora keywords show as a magenta chrome line (not editable). */
|
|
1564
|
-
const TextOverlay = observer((p) => {
|
|
1565
|
-
const s = p.st;
|
|
1566
|
-
const ed = s.editor;
|
|
1567
|
-
const winLines = s.overlayLines;
|
|
1568
|
-
const selectedVar = s.selected?.[1];
|
|
1569
|
-
const promptVar = selectedVar?.kind === "prompt" ? selectedVar : null;
|
|
1570
|
-
const isPrompt = promptVar != null;
|
|
1571
|
-
const injected = promptVar?.injectedKeywords() ?? [];
|
|
1572
|
-
const lines = [];
|
|
1573
|
-
let start = 0;
|
|
1574
|
-
for (const text of ed.buffer.split("\n")) {
|
|
1575
|
-
lines.push({
|
|
1576
|
-
text,
|
|
1577
|
-
start
|
|
1578
|
-
});
|
|
1579
|
-
start += [...text].length + 1;
|
|
1580
|
-
}
|
|
1581
|
-
let cursorLine = 0;
|
|
1582
|
-
for (let i = 0; i < lines.length; i++) if ((lines[i]?.start ?? 0) <= ed.cursor) cursorLine = i;
|
|
1583
|
-
const winStart = Math.max(0, Math.min(cursorLine - Math.floor(winLines / 2), lines.length - winLines));
|
|
1584
|
-
const visible = lines.slice(winStart, winStart + winLines);
|
|
1585
|
-
const color = ed.invalid ? "red" : "yellow";
|
|
1586
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
1587
|
-
borderStyle: "double",
|
|
1588
|
-
paddingX: 1,
|
|
1589
|
-
flexDirection: "column",
|
|
1590
|
-
children: [
|
|
1591
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1592
|
-
bold: true,
|
|
1593
|
-
children: s.selected ? s.selected[1].label ?? s.selected[0] : ""
|
|
1594
|
-
}),
|
|
1595
|
-
injected.length > 0 && /* @__PURE__ */ jsxs(Text, {
|
|
1596
|
-
color: "magenta",
|
|
1597
|
-
wrap: "wrap",
|
|
1598
|
-
children: [
|
|
1599
|
-
"↳ loras: ",
|
|
1600
|
-
injected.join(", "),
|
|
1601
|
-
" ",
|
|
1602
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1603
|
-
dimColor: true,
|
|
1604
|
-
children: "(injected)"
|
|
1605
|
-
})
|
|
1606
|
-
]
|
|
1607
|
-
}),
|
|
1608
|
-
winStart > 0 && /* @__PURE__ */ jsxs(Text, {
|
|
1609
|
-
color: "gray",
|
|
1610
|
-
children: [
|
|
1611
|
-
"… ",
|
|
1612
|
-
winStart,
|
|
1613
|
-
" more line(s)"
|
|
1614
|
-
]
|
|
1615
|
-
}),
|
|
1616
|
-
visible.map((line, ix) => {
|
|
1617
|
-
const globalIx = winStart + ix;
|
|
1618
|
-
const comment = isPrompt && PromptVar.isCommentLine(line.text);
|
|
1619
|
-
const negative = isPrompt && !comment && PromptVar.isNegativeLine(line.text);
|
|
1620
|
-
const lineColor = comment ? "gray" : negative ? "red" : color;
|
|
1621
|
-
if (globalIx !== cursorLine) return /* @__PURE__ */ jsx(Text, {
|
|
1622
|
-
color: lineColor,
|
|
1623
|
-
dimColor: comment,
|
|
1624
|
-
children: line.text === "" ? " " : line.text
|
|
1625
|
-
}, globalIx);
|
|
1626
|
-
const cs = [...line.text];
|
|
1627
|
-
const col = ed.cursor - line.start;
|
|
1628
|
-
const before = cs.slice(0, col).join("");
|
|
1629
|
-
const at = cs[col] ?? " ";
|
|
1630
|
-
const after = cs.slice(col + 1).join("");
|
|
1631
|
-
return /* @__PURE__ */ jsxs(Text, {
|
|
1632
|
-
color: lineColor,
|
|
1633
|
-
dimColor: comment,
|
|
1634
|
-
backgroundColor: "blackBright",
|
|
1635
|
-
children: [
|
|
1636
|
-
before,
|
|
1637
|
-
/* @__PURE__ */ jsx(Text, {
|
|
1638
|
-
inverse: true,
|
|
1639
|
-
children: at
|
|
1640
|
-
}),
|
|
1641
|
-
after
|
|
1642
|
-
]
|
|
1643
|
-
}, globalIx);
|
|
1644
|
-
}),
|
|
1645
|
-
winStart + winLines < lines.length && /* @__PURE__ */ jsxs(Text, {
|
|
1646
|
-
color: "gray",
|
|
1647
|
-
children: [
|
|
1648
|
-
"… ",
|
|
1649
|
-
lines.length - winStart - winLines,
|
|
1650
|
-
" more line(s)"
|
|
1651
|
-
]
|
|
1652
|
-
}),
|
|
1653
|
-
/* @__PURE__ */ jsx(KeyHints, { hints: TEXT_EDIT_HINTS })
|
|
1654
|
-
]
|
|
1655
|
-
});
|
|
1656
|
-
});
|
|
1657
|
-
//#endregion
|
|
1658
|
-
//#region src/cli/tui/components/TreePanel.tsx
|
|
1659
|
-
/** persistent left panel: directory hierarchy + workflows with their drafts
|
|
1660
|
-
* nested; `t` (or ← from vars) focuses it, `/` filters it. The Box is
|
|
1661
|
-
* measured (keybar wraps, chrome height is width-dependent — arithmetic
|
|
1662
|
-
* lies) and the row list windows to the measured budget; overflow hidden
|
|
1663
|
-
* is the backstop for the one pre-measure frame. */
|
|
1664
|
-
const TreePanel = observer((p) => {
|
|
1665
|
-
const s = p.st;
|
|
1666
|
-
const tree = s.tree;
|
|
1667
|
-
const focused = s.mode === "tree";
|
|
1668
|
-
const boxRef = useRef(null);
|
|
1669
|
-
useEffect(() => {
|
|
1670
|
-
if (boxRef.current != null) tree.setViewH(measureElement(boxRef.current).height);
|
|
1671
|
-
});
|
|
1672
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
1673
|
-
ref: boxRef,
|
|
1674
|
-
borderStyle: "round",
|
|
1675
|
-
borderColor: focused ? "cyan" : "gray",
|
|
1676
|
-
flexDirection: "column",
|
|
1677
|
-
flexShrink: 0,
|
|
1678
|
-
width: s.treeWidth,
|
|
1679
|
-
paddingX: 1,
|
|
1680
|
-
overflow: "hidden",
|
|
1681
|
-
children: [
|
|
1682
|
-
/* @__PURE__ */ jsx(Box, {
|
|
1683
|
-
marginTop: -1,
|
|
1684
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1685
|
-
color: focused ? "cyan" : "gray",
|
|
1686
|
-
bold: focused,
|
|
1687
|
-
children: "(t)ree"
|
|
1688
|
-
})
|
|
1689
|
-
}),
|
|
1690
|
-
(tree.filtering || tree.filter !== "") && /* @__PURE__ */ jsxs(Text, {
|
|
1691
|
-
color: "yellow",
|
|
1692
|
-
wrap: "truncate",
|
|
1693
|
-
children: [
|
|
1694
|
-
"/",
|
|
1695
|
-
tree.filter,
|
|
1696
|
-
tree.filtering ? "▌" : ""
|
|
1697
|
-
]
|
|
1698
|
-
}),
|
|
1699
|
-
tree.window.moreAbove && /* @__PURE__ */ jsx(Text, {
|
|
1700
|
-
color: "gray",
|
|
1701
|
-
children: "…"
|
|
1702
|
-
}),
|
|
1703
|
-
tree.rows.slice(tree.window.start, tree.window.end).map((row, sliceIx) => {
|
|
1704
|
-
const ix = tree.window.start + sliceIx;
|
|
1705
|
-
const sel = focused && ix === tree.ix;
|
|
1706
|
-
const indent = " ".repeat(row.depth * 2);
|
|
1707
|
-
if (row.kind === "dir") return /* @__PURE__ */ jsxs(Text, {
|
|
1708
|
-
inverse: sel,
|
|
1709
|
-
color: "gray",
|
|
1710
|
-
bold: true,
|
|
1711
|
-
wrap: "truncate",
|
|
1712
|
-
children: [
|
|
1713
|
-
indent,
|
|
1714
|
-
row.expanded ? "▾" : "▸",
|
|
1715
|
-
" ",
|
|
1716
|
-
row.label
|
|
1717
|
-
]
|
|
1718
|
-
}, `dir·${row.path}`);
|
|
1719
|
-
if (row.kind === "workflow") {
|
|
1720
|
-
const arrow = row.hasDrafts ? row.expanded ? "▾" : "▸" : " ";
|
|
1721
|
-
const marker = row.error != null ? "✗" : row.current ? "●" : " ";
|
|
1722
|
-
return /* @__PURE__ */ jsxs(Text, {
|
|
1723
|
-
inverse: sel,
|
|
1724
|
-
bold: row.current,
|
|
1725
|
-
color: row.error != null ? "red" : row.color,
|
|
1726
|
-
wrap: "truncate",
|
|
1727
|
-
children: [
|
|
1728
|
-
indent,
|
|
1729
|
-
arrow,
|
|
1730
|
-
marker,
|
|
1731
|
-
" ",
|
|
1732
|
-
row.name
|
|
1733
|
-
]
|
|
1734
|
-
}, row.file);
|
|
1735
|
-
}
|
|
1736
|
-
return /* @__PURE__ */ jsxs(Text, {
|
|
1737
|
-
inverse: sel,
|
|
1738
|
-
color: row.active ? "cyan" : "gray",
|
|
1739
|
-
wrap: "truncate",
|
|
1740
|
-
children: [
|
|
1741
|
-
indent,
|
|
1742
|
-
" ",
|
|
1743
|
-
row.active ? "●" : "·",
|
|
1744
|
-
" ",
|
|
1745
|
-
row.draft
|
|
1746
|
-
]
|
|
1747
|
-
}, `${row.file}·${row.draft}`);
|
|
1748
|
-
}),
|
|
1749
|
-
tree.window.moreBelow && /* @__PURE__ */ jsx(Text, {
|
|
1750
|
-
color: "gray",
|
|
1751
|
-
children: "…"
|
|
1752
|
-
}),
|
|
1753
|
-
s.workflows.loading ? /* @__PURE__ */ jsx(Text, {
|
|
1754
|
-
color: "yellow",
|
|
1755
|
-
children: "loading…"
|
|
1756
|
-
}) : null
|
|
1757
|
-
]
|
|
1758
|
-
});
|
|
1759
|
-
});
|
|
1760
|
-
//#endregion
|
|
1761
|
-
//#region src/cli/tui/components/VarsPanel.tsx
|
|
1762
|
-
const VALUE_CAP = 300;
|
|
1763
|
-
/** prompt value cell: magenta injected-keywords chrome line (not part of the
|
|
1764
|
-
* text), `//` comments dim gray, `- ` negative lines red */
|
|
1765
|
-
const PromptCell = observer((p) => {
|
|
1766
|
-
const injected = p.varDef.injectedKeywords();
|
|
1767
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
1768
|
-
flexDirection: "column",
|
|
1769
|
-
children: [injected.length > 0 && /* @__PURE__ */ jsxs(Text, {
|
|
1770
|
-
color: "magenta",
|
|
1771
|
-
wrap: "wrap",
|
|
1772
|
-
children: ["↳ loras: ", injected.join(", ")]
|
|
1773
|
-
}), p.value.split("\n").map((line, ix) => {
|
|
1774
|
-
const comment = PromptVar.isCommentLine(line);
|
|
1775
|
-
const negative = !comment && PromptVar.isNegativeLine(line);
|
|
1776
|
-
return /* @__PURE__ */ jsx(Text, {
|
|
1777
|
-
color: comment ? "gray" : negative ? "red" : "cyan",
|
|
1778
|
-
dimColor: comment,
|
|
1779
|
-
wrap: "wrap",
|
|
1780
|
-
children: line === "" ? " " : line
|
|
1781
|
-
}, ix);
|
|
1782
|
-
})]
|
|
1783
|
-
});
|
|
1784
|
-
});
|
|
1785
|
-
const VarRow = observer((p) => {
|
|
1786
|
-
const editing = p.selected && p.st.mode === "edit" && !p.st.editor.isCustom;
|
|
1787
|
-
const label = p.varDef.label ?? p.name;
|
|
1788
|
-
const raw = p.varDef.display();
|
|
1789
|
-
const value = raw.length > VALUE_CAP ? `${raw.slice(0, VALUE_CAP)}…` : raw;
|
|
1790
|
-
const oneLine = p.compact && !p.selected;
|
|
1791
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
1792
|
-
flexDirection: "row",
|
|
1793
|
-
children: [
|
|
1794
|
-
/* @__PURE__ */ jsx(Box, {
|
|
1795
|
-
width: p.labelW,
|
|
1796
|
-
flexShrink: 0,
|
|
1797
|
-
children: /* @__PURE__ */ jsxs(Text, {
|
|
1798
|
-
inverse: p.selected,
|
|
1799
|
-
children: [p.selected ? "▸ " : " ", label]
|
|
1800
|
-
})
|
|
1801
|
-
}),
|
|
1802
|
-
/* @__PURE__ */ jsx(Box, {
|
|
1803
|
-
width: 9,
|
|
1804
|
-
flexShrink: 0,
|
|
1805
|
-
children: /* @__PURE__ */ jsxs(Text, {
|
|
1806
|
-
color: "gray",
|
|
1807
|
-
children: [
|
|
1808
|
-
"[",
|
|
1809
|
-
p.varDef.kind,
|
|
1810
|
-
"]"
|
|
1811
|
-
]
|
|
1812
|
-
})
|
|
1813
|
-
}),
|
|
1814
|
-
/* @__PURE__ */ jsx(Box, {
|
|
1815
|
-
flexGrow: 1,
|
|
1816
|
-
children: editing ? /* @__PURE__ */ jsx(EditField, { st: p.st }) : oneLine ? /* @__PURE__ */ jsx(Text, {
|
|
1817
|
-
color: "cyan",
|
|
1818
|
-
wrap: "truncate",
|
|
1819
|
-
children: value.replaceAll("\n", " ")
|
|
1820
|
-
}) : p.varDef.kind === "prompt" ? /* @__PURE__ */ jsx(PromptCell, {
|
|
1821
|
-
varDef: p.varDef,
|
|
1822
|
-
value
|
|
1823
|
-
}) : /* @__PURE__ */ jsx(Text, {
|
|
1824
|
-
color: "cyan",
|
|
1825
|
-
wrap: "wrap",
|
|
1826
|
-
children: value
|
|
1827
|
-
})
|
|
1828
|
-
})
|
|
1829
|
-
]
|
|
1830
|
-
});
|
|
1831
|
-
});
|
|
1832
|
-
const VarsPanel = observer((p) => {
|
|
1833
|
-
const s = p.st;
|
|
1834
|
-
const labelW = Math.max(12, ...s.entries.map(([name, v]) => (v.label ?? name).length)) + 3;
|
|
1835
|
-
const focused = s.mode === "nav" || s.mode === "edit";
|
|
1836
|
-
const boxRef = useRef(null);
|
|
1837
|
-
useEffect(() => {
|
|
1838
|
-
if (boxRef.current != null) s.setVarsViewH(measureElement(boxRef.current).height);
|
|
1839
|
-
});
|
|
1840
|
-
const w = s.varsWindow;
|
|
1841
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
1842
|
-
ref: boxRef,
|
|
1843
|
-
borderStyle: "round",
|
|
1844
|
-
borderColor: focused ? "cyan" : "gray",
|
|
1845
|
-
paddingX: 1,
|
|
1846
|
-
flexDirection: "column",
|
|
1847
|
-
overflow: "hidden",
|
|
1848
|
-
children: [
|
|
1849
|
-
/* @__PURE__ */ jsx(Box, {
|
|
1850
|
-
marginTop: -1,
|
|
1851
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1852
|
-
color: focused ? "cyan" : "gray",
|
|
1853
|
-
bold: focused,
|
|
1854
|
-
children: "(v)ars"
|
|
1855
|
-
})
|
|
1856
|
-
}),
|
|
1857
|
-
w.moreAbove && /* @__PURE__ */ jsx(Text, {
|
|
1858
|
-
color: "gray",
|
|
1859
|
-
children: "…"
|
|
1860
|
-
}),
|
|
1861
|
-
s.entries.slice(w.start, Math.min(w.end, s.entries.length)).map(([name, varDef], sliceIx) => /* @__PURE__ */ jsx(VarRow, {
|
|
1862
|
-
name,
|
|
1863
|
-
varDef,
|
|
1864
|
-
selected: w.start + sliceIx === s.selIx,
|
|
1865
|
-
labelW,
|
|
1866
|
-
st: s,
|
|
1867
|
-
compact: s.varsCompact
|
|
1868
|
-
}, name)),
|
|
1869
|
-
w.end > s.entries.length && /* @__PURE__ */ jsxs(Box, {
|
|
1870
|
-
flexDirection: "row",
|
|
1871
|
-
children: [
|
|
1872
|
-
/* @__PURE__ */ jsx(Box, {
|
|
1873
|
-
width: labelW,
|
|
1874
|
-
flexShrink: 0,
|
|
1875
|
-
children: /* @__PURE__ */ jsxs(Text, {
|
|
1876
|
-
inverse: s.onSaveRow,
|
|
1877
|
-
children: [s.onSaveRow ? "▸ " : " ", "save to disk"]
|
|
1878
|
-
})
|
|
1879
|
-
}),
|
|
1880
|
-
/* @__PURE__ */ jsx(Box, {
|
|
1881
|
-
width: 9,
|
|
1882
|
-
flexShrink: 0,
|
|
1883
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1884
|
-
color: "gray",
|
|
1885
|
-
children: "[tui]"
|
|
1886
|
-
})
|
|
1887
|
-
}),
|
|
1888
|
-
/* @__PURE__ */ jsx(Box, {
|
|
1889
|
-
flexGrow: 1,
|
|
1890
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1891
|
-
color: s.settings.saveToDisk ? "cyan" : "yellow",
|
|
1892
|
-
wrap: "truncate",
|
|
1893
|
-
children: s.settings.saveToDisk ? "on" : "off — outputs stay in memory"
|
|
1894
|
-
})
|
|
1895
|
-
})
|
|
1896
|
-
]
|
|
1897
|
-
}),
|
|
1898
|
-
s.settings.saveToDisk && w.end > s.entries.length + 1 && /* @__PURE__ */ jsxs(Box, {
|
|
1899
|
-
flexDirection: "row",
|
|
1900
|
-
children: [
|
|
1901
|
-
/* @__PURE__ */ jsx(Box, {
|
|
1902
|
-
width: labelW,
|
|
1903
|
-
flexShrink: 0,
|
|
1904
|
-
children: /* @__PURE__ */ jsxs(Text, {
|
|
1905
|
-
inverse: s.onPrefixRow,
|
|
1906
|
-
children: [s.onPrefixRow ? "▸ " : " ", "save prefix"]
|
|
1907
|
-
})
|
|
1908
|
-
}),
|
|
1909
|
-
/* @__PURE__ */ jsx(Box, {
|
|
1910
|
-
width: 9,
|
|
1911
|
-
flexShrink: 0,
|
|
1912
|
-
children: /* @__PURE__ */ jsx(Text, {
|
|
1913
|
-
color: "gray",
|
|
1914
|
-
children: "[tui]"
|
|
1915
|
-
})
|
|
1916
|
-
}),
|
|
1917
|
-
/* @__PURE__ */ jsx(Box, {
|
|
1918
|
-
flexGrow: 1,
|
|
1919
|
-
children: /* @__PURE__ */ jsxs(Text, {
|
|
1920
|
-
color: "cyan",
|
|
1921
|
-
wrap: "truncate",
|
|
1922
|
-
children: [
|
|
1923
|
-
".comfy-ts/outputs/",
|
|
1924
|
-
s.savePrefix,
|
|
1925
|
-
"/"
|
|
1926
|
-
]
|
|
1927
|
-
})
|
|
1928
|
-
})
|
|
1929
|
-
]
|
|
1930
|
-
}),
|
|
1931
|
-
w.moreBelow && /* @__PURE__ */ jsx(Text, {
|
|
1932
|
-
color: "gray",
|
|
1933
|
-
children: "…"
|
|
1934
|
-
})
|
|
1935
|
-
]
|
|
1936
|
-
});
|
|
1937
|
-
});
|
|
1938
|
-
//#endregion
|
|
1939
|
-
//#region src/cli/tui/keys.ts
|
|
1940
|
-
/**
|
|
1941
|
-
* xterm modifyOtherKeys (vscode/xterm.js — enabled by run-tui via `CSI > 4;1 m`)
|
|
1942
|
-
* encodes modified ⏎ as `CSI 27;<mods>;13~`. ink 7 leaves that sequence
|
|
1943
|
-
* unparsed: it reaches useInput as the LITERAL input `[27;<mods>;13~` with no
|
|
1944
|
-
* key flags, which would otherwise be typed into editors/filters. Translate it
|
|
1945
|
-
* back into return + modifier bits (mods is xterm's modifier-1 bitfield:
|
|
1946
|
-
* 1 shift · 2 alt · 4 ctrl · 8 meta — alt|meta fold into ink's `meta`, same
|
|
1947
|
-
* mask ink uses for legacy fn-keys). Kitty-protocol terminals never hit this:
|
|
1948
|
-
* their `CSI 13;2u` is parsed natively by ink. Returns null when `input` is
|
|
1949
|
-
* not a modified enter.
|
|
1950
|
-
*/
|
|
1951
|
-
function parseModifyOtherKeysEnter(input) {
|
|
1952
|
-
const m = /^\[27;(\d+);13~$/.exec(input);
|
|
1953
|
-
if (m == null) return null;
|
|
1954
|
-
const mods = Number(m[1]) - 1;
|
|
1955
|
-
return {
|
|
1956
|
-
return: true,
|
|
1957
|
-
shift: (mods & 1) !== 0,
|
|
1958
|
-
meta: (mods & 10) !== 0,
|
|
1959
|
-
ctrl: (mods & 4) !== 0
|
|
1960
|
-
};
|
|
1961
|
-
}
|
|
1962
|
-
//#endregion
|
|
1963
|
-
//#region src/cli/tui/components/TuiApp.tsx
|
|
1964
|
-
const TuiApp = observer((p) => {
|
|
1965
|
-
const app = useApp();
|
|
1966
|
-
const s = p.st;
|
|
1967
|
-
useInput((input, key) => {
|
|
1968
|
-
const modEnter = parseModifyOtherKeysEnter(input);
|
|
1969
|
-
if (modEnter != null) {
|
|
1970
|
-
input = "";
|
|
1971
|
-
key = {
|
|
1972
|
-
...key,
|
|
1973
|
-
...modEnter
|
|
1974
|
-
};
|
|
1975
|
-
}
|
|
1976
|
-
if (key.ctrl && input === "r") return void s.exec.run();
|
|
1977
|
-
if (s.mode === "edit" || s.mode === "overlay-text") {
|
|
1978
|
-
const ed = s.editor;
|
|
1979
|
-
const multi = s.mode === "overlay-text";
|
|
1980
|
-
if (key.escape) return ed.cancel();
|
|
1981
|
-
if (multi && key.ctrl && input === "s") return ed.commitMultiline();
|
|
1982
|
-
if (multi && key.return && (key.shift || key.meta)) return ed.newline();
|
|
1983
|
-
if (key.return) return multi ? ed.commitMultiline() : ed.commitInline();
|
|
1984
|
-
if (key.meta && (key.backspace || key.delete) || key.ctrl && input === "w") return ed.deleteWordBack();
|
|
1985
|
-
if (key.backspace || key.delete) return ed.backspace();
|
|
1986
|
-
if (key.meta && key.leftArrow) return ed.wordLeft();
|
|
1987
|
-
if (key.meta && key.rightArrow) return ed.wordRight();
|
|
1988
|
-
if (key.meta && input === "b") return ed.wordLeft();
|
|
1989
|
-
if (key.meta && input === "f") return ed.wordRight();
|
|
1990
|
-
if (key.super && key.leftArrow || key.home || key.ctrl && input === "a") return ed.lineHome();
|
|
1991
|
-
if (key.super && key.rightArrow || key.end || key.ctrl && input === "e") return ed.lineEnd();
|
|
1992
|
-
if (multi && key.meta && key.upArrow) return ed.moveLine(-1);
|
|
1993
|
-
if (multi && key.meta && key.downArrow) return ed.moveLine(1);
|
|
1994
|
-
if (multi && input === "/" && (key.super || key.ctrl || key.meta)) return ed.toggleComment();
|
|
1995
|
-
if (multi && input.length === 1 && input.charCodeAt(0) === 31) return ed.toggleComment();
|
|
1996
|
-
if (key.leftArrow) return ed.cursorLeft();
|
|
1997
|
-
if (key.rightArrow) return ed.cursorRight();
|
|
1998
|
-
if (multi && key.upArrow) return ed.cursorUp();
|
|
1999
|
-
if (multi && key.downArrow) return ed.cursorDown();
|
|
2000
|
-
if (key.ctrl && input === "u") return ed.killToStart();
|
|
2001
|
-
if (key.ctrl && input === "k") return ed.killToEnd();
|
|
2002
|
-
if (input && !key.ctrl && !key.meta) return ed.input(input);
|
|
2003
|
-
return;
|
|
2004
|
-
}
|
|
2005
|
-
if (s.mode === "overlay-choice" || s.mode === "overlay-size" || s.mode === "overlay-preset") {
|
|
2006
|
-
const pk = s.picker;
|
|
2007
|
-
if (key.escape) return s.editor.cancel();
|
|
2008
|
-
if (key.return) return pk.commit();
|
|
2009
|
-
if (key.upArrow) return pk.move(-1);
|
|
2010
|
-
if (key.downArrow) return pk.move(1);
|
|
2011
|
-
if (key.meta && (key.backspace || key.delete) || key.ctrl && input === "w") return pk.filterDeleteWord();
|
|
2012
|
-
if (key.backspace || key.delete) return pk.filterBackspace();
|
|
2013
|
-
if (input && !key.ctrl && !key.meta) return pk.filterInput(input);
|
|
2014
|
-
return;
|
|
2015
|
-
}
|
|
2016
|
-
if (s.mode === "overlay-loras") {
|
|
2017
|
-
const lo = s.loras;
|
|
2018
|
-
if (key.escape) return s.editor.cancel();
|
|
2019
|
-
if (key.ctrl && input === "a") return lo.setAll(true);
|
|
2020
|
-
if (key.ctrl && input === "n") return lo.setAll(false);
|
|
2021
|
-
if (key.ctrl && input === "k") return lo.beginKeyword();
|
|
2022
|
-
if (key.ctrl && input === "d") return lo.resetKeyword();
|
|
2023
|
-
if (key.return || input === " ") return lo.toggle();
|
|
2024
|
-
if (key.upArrow) return lo.move(-1);
|
|
2025
|
-
if (key.downArrow) return lo.move(1);
|
|
2026
|
-
if (key.leftArrow) return lo.adjust(-.05);
|
|
2027
|
-
if (key.rightArrow) return lo.adjust(.05);
|
|
2028
|
-
if (key.meta && (key.backspace || key.delete) || key.ctrl && input === "w") return lo.filterDeleteWord();
|
|
2029
|
-
if (key.backspace || key.delete) return lo.filterBackspace();
|
|
2030
|
-
if (input && !key.ctrl && !key.meta) return lo.filterInput(input);
|
|
2031
|
-
return;
|
|
2032
|
-
}
|
|
2033
|
-
if (s.mode === "overlay-image") {
|
|
2034
|
-
const ip = s.imagePicker;
|
|
2035
|
-
if (key.escape) return ip.cancel();
|
|
2036
|
-
if (key.tab || input === " ") return ip.cyclePane();
|
|
2037
|
-
if (key.ctrl && input === "f") return ip.toggleFavorite();
|
|
2038
|
-
if (key.return) return ip.commit();
|
|
2039
|
-
if (key.upArrow) return ip.move(-1);
|
|
2040
|
-
if (key.downArrow) return ip.move(1);
|
|
2041
|
-
if (key.leftArrow) return ip.goParent();
|
|
2042
|
-
if (key.rightArrow) return ip.enter();
|
|
2043
|
-
if (key.meta && (key.backspace || key.delete) || key.ctrl && input === "w") return ip.filterDeleteWord();
|
|
2044
|
-
if (key.backspace || key.delete) return ip.filterBackspace();
|
|
2045
|
-
if (input && !key.ctrl && !key.meta) return ip.filterInput(input);
|
|
2046
|
-
return;
|
|
2047
|
-
}
|
|
2048
|
-
if (s.mode === "tree") {
|
|
2049
|
-
const tr = s.tree;
|
|
2050
|
-
if (tr.filtering) {
|
|
2051
|
-
if (key.escape) return tr.clearFilter();
|
|
2052
|
-
if (key.return) return void tr.commit();
|
|
2053
|
-
if (key.upArrow) return tr.move(-1);
|
|
2054
|
-
if (key.downArrow) return tr.move(1);
|
|
2055
|
-
if (key.leftArrow) return tr.fold();
|
|
2056
|
-
if (key.rightArrow) return tr.unfold();
|
|
2057
|
-
if (key.backspace || key.delete) return tr.filterBackspace();
|
|
2058
|
-
if (input && !key.ctrl && !key.meta) return tr.filterInput(input);
|
|
2059
|
-
return;
|
|
2060
|
-
}
|
|
2061
|
-
if (key.escape) return tr.filter !== "" ? tr.clearFilter() : tr.blur();
|
|
2062
|
-
if (input === "t") return tr.blur();
|
|
2063
|
-
if (input === "/") return tr.beginFilter();
|
|
2064
|
-
if (key.return || input === " ") return void tr.commit();
|
|
2065
|
-
if (key.upArrow) return tr.move(-1);
|
|
2066
|
-
if (key.downArrow) return tr.move(1);
|
|
2067
|
-
if (key.leftArrow) return tr.fold();
|
|
2068
|
-
if (key.rightArrow) return tr.unfold();
|
|
2069
|
-
if (input === "v") return tr.blur();
|
|
2070
|
-
if (input === "n") return tr.promptNewDraft();
|
|
2071
|
-
if (input === "e") return tr.draftOp("rename");
|
|
2072
|
-
if (input === "c") return tr.draftOp("duplicate");
|
|
2073
|
-
if (input === "x") return tr.draftOp("delete");
|
|
2074
|
-
if (input === "r") return void s.exec.run();
|
|
2075
|
-
if (input === "s") return s.exec.randomizeSeedAndRun();
|
|
2076
|
-
if (input === "d") return s.drafts.begin();
|
|
2077
|
-
if (input === "h") return s.host.beginPicker();
|
|
2078
|
-
if (input === "a") return s.host.begin();
|
|
2079
|
-
if (input === "p") return s.preview.beginMenu();
|
|
2080
|
-
if (input === "o") return s.exec.openLastOutput();
|
|
2081
|
-
if (input === "i") return void s.exec.copyLastImage();
|
|
2082
|
-
if (input === "q") {
|
|
2083
|
-
s.onExit();
|
|
2084
|
-
return app.exit();
|
|
2085
|
-
}
|
|
2086
|
-
return;
|
|
2087
|
-
}
|
|
2088
|
-
if (s.mode === "host") {
|
|
2089
|
-
const h = s.host;
|
|
2090
|
-
if (key.escape || input === "a" || input === "v") return h.blur();
|
|
2091
|
-
if (input === "h") return h.beginPicker();
|
|
2092
|
-
if (key.return || input === " ") return void h.commit();
|
|
2093
|
-
if (key.upArrow) return h.move(-1);
|
|
2094
|
-
if (key.downArrow) return h.move(1);
|
|
2095
|
-
if (input === "q") {
|
|
2096
|
-
s.onExit();
|
|
2097
|
-
return app.exit();
|
|
2098
|
-
}
|
|
2099
|
-
return;
|
|
2100
|
-
}
|
|
2101
|
-
if (s.mode === "overlay-hosts") {
|
|
2102
|
-
const h = s.host;
|
|
2103
|
-
if (key.escape || input === "h") return h.cancelPicker();
|
|
2104
|
-
if (key.return || input === " ") return h.commitPicker();
|
|
2105
|
-
if (key.upArrow) return h.pickerMove(-1);
|
|
2106
|
-
if (key.downArrow) return h.pickerMove(1);
|
|
2107
|
-
return;
|
|
2108
|
-
}
|
|
2109
|
-
if (s.mode === "overlay-copy") {
|
|
2110
|
-
if (key.escape || key.return || input === " " || input === "c" || input === "C" || input === "q") return s.exec.closeCopyPopup();
|
|
2111
|
-
return;
|
|
2112
|
-
}
|
|
2113
|
-
if (s.mode === "preview") {
|
|
2114
|
-
const pv = s.preview;
|
|
2115
|
-
if (key.escape || key.return || input === "p" || input === "v") return pv.blurMenu();
|
|
2116
|
-
if (key.upArrow) return pv.menuMove(-1);
|
|
2117
|
-
if (key.downArrow) return pv.menuMove(1);
|
|
2118
|
-
if (key.leftArrow) return pv.menuCycle(-1);
|
|
2119
|
-
if (key.rightArrow || input === " ") return pv.menuCycle(1);
|
|
2120
|
-
if (input === "r") return void s.exec.run();
|
|
2121
|
-
if (input === "s") return s.exec.randomizeSeedAndRun();
|
|
2122
|
-
if (input === "d") return s.drafts.begin();
|
|
2123
|
-
if (input === "h") return s.host.beginPicker();
|
|
2124
|
-
if (input === "a") return s.host.begin();
|
|
2125
|
-
if (input === "o") return s.exec.openLastOutput();
|
|
2126
|
-
if (input === "i") return void s.exec.copyLastImage();
|
|
2127
|
-
if (input === "q") {
|
|
2128
|
-
s.onExit();
|
|
2129
|
-
return app.exit();
|
|
2130
|
-
}
|
|
2131
|
-
return;
|
|
2132
|
-
}
|
|
2133
|
-
if (s.mode === "overlay-drafts") {
|
|
2134
|
-
const d = s.drafts;
|
|
2135
|
-
if (key.escape) return s.editor.cancel();
|
|
2136
|
-
if (key.return) return d.commit();
|
|
2137
|
-
if (key.upArrow) return d.move(-1);
|
|
2138
|
-
if (key.downArrow) return d.move(1);
|
|
2139
|
-
if (input === "n") return d.promptNew("overlay-drafts");
|
|
2140
|
-
if (input === "e" && d.selectedName != null) return d.promptRename(d.selectedName, void 0, "overlay-drafts");
|
|
2141
|
-
if (input === "c" && d.selectedName != null) return d.promptDuplicate(d.selectedName, void 0, "overlay-drafts");
|
|
2142
|
-
if (input === "x" && d.selectedName != null) {
|
|
2143
|
-
d.deleteDraft(d.selectedName);
|
|
2144
|
-
return d.begin();
|
|
2145
|
-
}
|
|
2146
|
-
return;
|
|
2147
|
-
}
|
|
2148
|
-
if (input === "q") {
|
|
2149
|
-
s.onExit();
|
|
2150
|
-
return app.exit();
|
|
2151
|
-
}
|
|
2152
|
-
if (key.upArrow) return s.moveSel(-1);
|
|
2153
|
-
if (key.downArrow) return s.moveSel(1);
|
|
2154
|
-
if (key.leftArrow) return s.tree.focus();
|
|
2155
|
-
if (key.rightArrow || key.return || input === " ") return s.activate();
|
|
2156
|
-
if (s.navKey(input)) return;
|
|
2157
|
-
if (input === "/") {
|
|
2158
|
-
s.tree.focus();
|
|
2159
|
-
return s.tree.beginFilter();
|
|
2160
|
-
}
|
|
2161
|
-
if (input === "P") return s.picker.beginPresets();
|
|
2162
|
-
if (input === "e") return s.drafts.beginRename();
|
|
2163
|
-
if (input === "r") return void s.exec.run();
|
|
2164
|
-
if (input === "s") return s.exec.randomizeSeedAndRun();
|
|
2165
|
-
if (input === "t" || input === "w") return s.tree.focus();
|
|
2166
|
-
if (input === "h") return s.host.beginPicker();
|
|
2167
|
-
if (input === "a") return s.host.begin();
|
|
2168
|
-
if (input === "d") return s.drafts.begin();
|
|
2169
|
-
if (input === "p") return s.preview.beginMenu();
|
|
2170
|
-
if (input === "o") return s.exec.openLastOutput();
|
|
2171
|
-
if (input === "i") return void s.exec.copyLastImage();
|
|
2172
|
-
if (input === "c") return void s.exec.copyWorkflowJson();
|
|
2173
|
-
if (input === "C") return void s.exec.copyApiJson();
|
|
2174
|
-
}, { isActive: useStdin().isRawModeSupported === true });
|
|
2175
|
-
return /* @__PURE__ */ jsxs(Box, {
|
|
2176
|
-
flexDirection: "column",
|
|
2177
|
-
height: s.termRows - 1,
|
|
2178
|
-
children: [
|
|
2179
|
-
/* @__PURE__ */ jsx(Header, { st: s }),
|
|
2180
|
-
/* @__PURE__ */ jsxs(Box, {
|
|
2181
|
-
flexDirection: "row",
|
|
2182
|
-
flexGrow: 1,
|
|
2183
|
-
flexShrink: 1,
|
|
2184
|
-
overflow: "hidden",
|
|
2185
|
-
children: [
|
|
2186
|
-
/* @__PURE__ */ jsx(TreePanel, { st: s }),
|
|
2187
|
-
/* @__PURE__ */ jsxs(Box, {
|
|
2188
|
-
flexDirection: "column",
|
|
2189
|
-
flexGrow: 1,
|
|
2190
|
-
children: [
|
|
2191
|
-
s.mode === "edit" && s.editor.isCustom ? /* @__PURE__ */ jsx(PromptOverlay, { st: s }) : s.mode === "host" ? /* @__PURE__ */ jsx(HostPanel, { st: s }) : s.mode === "overlay-text" ? /* @__PURE__ */ jsx(TextOverlay, { st: s }) : s.mode === "overlay-choice" ? /* @__PURE__ */ jsx(ChoiceOverlay, { st: s }) : s.mode === "overlay-preset" ? /* @__PURE__ */ jsx(PresetOverlay, { st: s }) : s.mode === "overlay-size" ? /* @__PURE__ */ jsx(SizeOverlay, { st: s }) : s.mode === "overlay-loras" ? /* @__PURE__ */ jsx(LorasOverlay, { st: s }) : s.mode === "overlay-image" ? /* @__PURE__ */ jsx(ImagePickerOverlay, { st: s }) : s.mode === "overlay-drafts" ? /* @__PURE__ */ jsx(DraftsOverlay, { st: s }) : s.mode === "overlay-hosts" ? /* @__PURE__ */ jsx(HostsOverlay, { st: s }) : s.mode === "overlay-copy" ? /* @__PURE__ */ jsx(CopyOverlay, { st: s }) : /* @__PURE__ */ jsx(VarsPanel, { st: s }),
|
|
2192
|
-
/* @__PURE__ */ jsx(Box, {
|
|
2193
|
-
paddingX: 1,
|
|
2194
|
-
children: /* @__PURE__ */ jsx(ProgressLine, { st: s })
|
|
2195
|
-
}),
|
|
2196
|
-
s.exec.outputLabels.length > 0 && /* @__PURE__ */ jsx(Box, {
|
|
2197
|
-
borderStyle: "round",
|
|
2198
|
-
paddingX: 1,
|
|
2199
|
-
flexDirection: "column",
|
|
2200
|
-
children: s.exec.outputLabels.map((o, ix) => /* @__PURE__ */ jsxs(Text, {
|
|
2201
|
-
color: o.memory ? "yellow" : "green",
|
|
2202
|
-
wrap: "truncate",
|
|
2203
|
-
children: [
|
|
2204
|
-
o.name,
|
|
2205
|
-
" ",
|
|
2206
|
-
/* @__PURE__ */ jsx(Text, {
|
|
2207
|
-
color: "gray",
|
|
2208
|
-
children: o.detail
|
|
2209
|
-
})
|
|
2210
|
-
]
|
|
2211
|
-
}, `${ix}-${o.name}`))
|
|
2212
|
-
}),
|
|
2213
|
-
!s.mode.startsWith("overlay-") && !(s.mode === "edit" && s.editor.isCustom) && /* @__PURE__ */ jsx(LogsPanel, { st: s })
|
|
2214
|
-
]
|
|
2215
|
-
}),
|
|
2216
|
-
(s.preview.show || s.preview.menuOpen) && /* @__PURE__ */ jsx(PreviewPanel, { st: s })
|
|
2217
|
-
]
|
|
2218
|
-
}),
|
|
2219
|
-
/* @__PURE__ */ jsx(KeyBar, { st: s })
|
|
2220
|
-
]
|
|
2221
|
-
});
|
|
2222
|
-
});
|
|
2223
|
-
//#endregion
|
|
2224
|
-
//#region src/cli/tui/listWindow.ts
|
|
2225
|
-
/**
|
|
2226
|
-
* window a list around the selection so that
|
|
2227
|
-
* (moreAbove ? 1 : 0) + (end - start) + (moreBelow ? 1 : 0) <= budget,
|
|
2228
|
-
* with the selection always inside [start, end). Degenerate budgets (<= 2)
|
|
2229
|
-
* drop the markers and show a bare slice at the selection.
|
|
2230
|
-
*/
|
|
2231
|
-
const listWindow = (p) => {
|
|
2232
|
-
if (p.count === 0 || p.budget <= 0) {
|
|
2233
|
-
const at = Math.max(0, Math.min(p.selected, p.count));
|
|
2234
|
-
return {
|
|
2235
|
-
start: at,
|
|
2236
|
-
end: at,
|
|
2237
|
-
moreAbove: false,
|
|
2238
|
-
moreBelow: false
|
|
2239
|
-
};
|
|
2240
|
-
}
|
|
2241
|
-
if (p.count <= p.budget) return {
|
|
2242
|
-
start: 0,
|
|
2243
|
-
end: p.count,
|
|
2244
|
-
moreAbove: false,
|
|
2245
|
-
moreBelow: false
|
|
2246
|
-
};
|
|
2247
|
-
const sel = Math.max(0, Math.min(p.selected, p.count - 1));
|
|
2248
|
-
if (p.budget <= 2) {
|
|
2249
|
-
const start = Math.min(sel, p.count - p.budget);
|
|
2250
|
-
return {
|
|
2251
|
-
start,
|
|
2252
|
-
end: start + p.budget,
|
|
2253
|
-
moreAbove: false,
|
|
2254
|
-
moreBelow: false
|
|
2255
|
-
};
|
|
2256
|
-
}
|
|
2257
|
-
if (sel < p.budget - 1) return {
|
|
2258
|
-
start: 0,
|
|
2259
|
-
end: p.budget - 1,
|
|
2260
|
-
moreAbove: false,
|
|
2261
|
-
moreBelow: true
|
|
2262
|
-
};
|
|
2263
|
-
if (sel >= p.count - (p.budget - 1)) return {
|
|
2264
|
-
start: p.count - (p.budget - 1),
|
|
2265
|
-
end: p.count,
|
|
2266
|
-
moreAbove: true,
|
|
2267
|
-
moreBelow: false
|
|
2268
|
-
};
|
|
2269
|
-
const visible = p.budget - 2;
|
|
2270
|
-
const start = Math.max(1, Math.min(sel - Math.floor(visible / 2), p.count - visible - 1));
|
|
2271
|
-
return {
|
|
2272
|
-
start,
|
|
2273
|
-
end: start + visible,
|
|
2274
|
-
moreAbove: true,
|
|
2275
|
-
moreBelow: true
|
|
2276
|
-
};
|
|
2277
|
-
};
|
|
2278
|
-
//#endregion
|
|
2279
|
-
//#region src/cli/tui/state/EditorSt.ts
|
|
2280
|
-
/**
|
|
2281
|
-
* line/multiline editor. Inline mode ('edit') escapes newlines into a single
|
|
2282
|
-
* line (numbers only, in practice); multiline mode ('overlay-text') keeps REAL
|
|
2283
|
-
* newlines. All ops are code-point based so emoji/astral input never splits a
|
|
2284
|
-
* surrogate pair (flag/ZWJ clusters may still count as several points).
|
|
2285
|
-
*/
|
|
2286
|
-
var EditorSt = class EditorSt {
|
|
2287
|
-
constructor(st) {
|
|
2288
|
-
this.st = st;
|
|
2289
|
-
this.buffer = "";
|
|
2290
|
-
this.cursor = 0;
|
|
2291
|
-
this.invalid = false;
|
|
2292
|
-
this.customCommit = null;
|
|
2293
|
-
this.customTitle = "";
|
|
2294
|
-
this.returnMode = "nav";
|
|
2295
|
-
makeAutoObservable(this, { st: false });
|
|
2296
|
-
}
|
|
2297
|
-
/** raw value -> escaped single-line buffer form (order matters: backslashes first) */
|
|
2298
|
-
static escapeForBuffer(raw) {
|
|
2299
|
-
return raw.replaceAll("\\", "\\\\").replaceAll("\r\n", "\n").replaceAll("\r", "\n").replaceAll("\n", "\\n");
|
|
2300
|
-
}
|
|
2301
|
-
/** escaped buffer form -> raw value */
|
|
2302
|
-
static unescapeBuffer(buffer) {
|
|
2303
|
-
return buffer.replace(/\\\\|\\n/g, (m) => m === "\\\\" ? "\\" : "\n");
|
|
2304
|
-
}
|
|
2305
|
-
get isCustom() {
|
|
2306
|
-
return this.customCommit != null;
|
|
2307
|
-
}
|
|
2308
|
-
/** inline single-line editor (numbers, seed `mode value`) */
|
|
2309
|
-
beginInline() {
|
|
2310
|
-
const sel = this.st.selected?.[1];
|
|
2311
|
-
if (sel == null) return;
|
|
2312
|
-
this.st.mode = "edit";
|
|
2313
|
-
this.buffer = EditorSt.escapeForBuffer(sel.toEditBuffer());
|
|
2314
|
-
this.cursor = [...this.buffer].length;
|
|
2315
|
-
this.invalid = false;
|
|
2316
|
-
}
|
|
2317
|
-
/** modal prompt over an arbitrary string (rendered as PromptOverlay);
|
|
2318
|
-
* onCommit returns false to keep editing (invalid); esc/apply lands on returnMode */
|
|
2319
|
-
beginCustom(p) {
|
|
2320
|
-
this.st.mode = "edit";
|
|
2321
|
-
this.customCommit = p.onCommit;
|
|
2322
|
-
this.customTitle = p.title;
|
|
2323
|
-
this.returnMode = p.returnMode ?? "nav";
|
|
2324
|
-
this.buffer = EditorSt.escapeForBuffer(p.initial);
|
|
2325
|
-
this.cursor = [...this.buffer].length;
|
|
2326
|
-
this.invalid = false;
|
|
2327
|
-
}
|
|
2328
|
-
/** modal multiline editor (text vars), no escaping */
|
|
2329
|
-
beginMultiline() {
|
|
2330
|
-
const sel = this.st.selected?.[1];
|
|
2331
|
-
if (sel == null) return;
|
|
2332
|
-
this.st.mode = "overlay-text";
|
|
2333
|
-
this.buffer = sel.toEditBuffer();
|
|
2334
|
-
this.cursor = [...this.buffer].length;
|
|
2335
|
-
this.invalid = false;
|
|
2336
|
-
}
|
|
2337
|
-
commitInline() {
|
|
2338
|
-
if (this.customCommit != null) {
|
|
2339
|
-
if (this.customCommit(EditorSt.unescapeBuffer(this.buffer))) {
|
|
2340
|
-
this.customCommit = null;
|
|
2341
|
-
this.st.mode = this.returnMode;
|
|
2342
|
-
} else this.invalid = true;
|
|
2343
|
-
return;
|
|
2344
|
-
}
|
|
2345
|
-
const sel = this.st.selected?.[1];
|
|
2346
|
-
if (sel == null) return;
|
|
2347
|
-
if (sel.parse(EditorSt.unescapeBuffer(this.buffer))) this.st.mode = "nav";
|
|
2348
|
-
else this.invalid = true;
|
|
2349
|
-
}
|
|
2350
|
-
commitMultiline() {
|
|
2351
|
-
const sel = this.st.selected?.[1];
|
|
2352
|
-
if (sel == null) return;
|
|
2353
|
-
if (sel.parse(this.buffer)) this.st.mode = "nav";
|
|
2354
|
-
else this.invalid = true;
|
|
2355
|
-
}
|
|
2356
|
-
cancel() {
|
|
2357
|
-
this.st.mode = this.customCommit != null ? this.returnMode : "nav";
|
|
2358
|
-
this.invalid = false;
|
|
2359
|
-
this.customCommit = null;
|
|
2360
|
-
}
|
|
2361
|
-
get chars() {
|
|
2362
|
-
return [...this.buffer];
|
|
2363
|
-
}
|
|
2364
|
-
setChars(cs, cursor) {
|
|
2365
|
-
this.buffer = cs.join("");
|
|
2366
|
-
this.cursor = Math.max(0, Math.min(cursor, cs.length));
|
|
2367
|
-
this.invalid = false;
|
|
2368
|
-
}
|
|
2369
|
-
input(chunk) {
|
|
2370
|
-
const insert = [...this.st.mode === "overlay-text" ? chunk.replaceAll("\r\n", "\n").replaceAll("\r", "\n") : EditorSt.escapeForBuffer(chunk)];
|
|
2371
|
-
const cs = this.chars;
|
|
2372
|
-
cs.splice(this.cursor, 0, ...insert);
|
|
2373
|
-
this.setChars(cs, this.cursor + insert.length);
|
|
2374
|
-
}
|
|
2375
|
-
backspace() {
|
|
2376
|
-
if (this.cursor === 0) return;
|
|
2377
|
-
const cs = this.chars;
|
|
2378
|
-
cs.splice(this.cursor - 1, 1);
|
|
2379
|
-
this.setChars(cs, this.cursor - 1);
|
|
2380
|
-
}
|
|
2381
|
-
newline() {
|
|
2382
|
-
const cs = this.chars;
|
|
2383
|
-
cs.splice(this.cursor, 0, "\n");
|
|
2384
|
-
this.setChars(cs, this.cursor + 1);
|
|
2385
|
-
}
|
|
2386
|
-
/** index of the start of the word left of the cursor */
|
|
2387
|
-
wordBoundLeft() {
|
|
2388
|
-
const cs = this.chars;
|
|
2389
|
-
let i = this.cursor;
|
|
2390
|
-
while (i > 0 && /\s/.test(cs[i - 1] ?? "")) i--;
|
|
2391
|
-
while (i > 0 && !/\s/.test(cs[i - 1] ?? "")) i--;
|
|
2392
|
-
return i;
|
|
2393
|
-
}
|
|
2394
|
-
/** index just past the word right of the cursor */
|
|
2395
|
-
wordBoundRight() {
|
|
2396
|
-
const cs = this.chars;
|
|
2397
|
-
let i = this.cursor;
|
|
2398
|
-
while (i < cs.length && /\s/.test(cs[i] ?? "")) i++;
|
|
2399
|
-
while (i < cs.length && !/\s/.test(cs[i] ?? "")) i++;
|
|
2400
|
-
return i;
|
|
2401
|
-
}
|
|
2402
|
-
/** alt+backspace / ctrl+w */
|
|
2403
|
-
deleteWordBack() {
|
|
2404
|
-
const from = this.wordBoundLeft();
|
|
2405
|
-
const cs = this.chars;
|
|
2406
|
-
cs.splice(from, this.cursor - from);
|
|
2407
|
-
this.setChars(cs, from);
|
|
2408
|
-
}
|
|
2409
|
-
/** ctrl+u: clear from start to cursor */
|
|
2410
|
-
killToStart() {
|
|
2411
|
-
this.setChars(this.chars.slice(this.cursor), 0);
|
|
2412
|
-
}
|
|
2413
|
-
/** ctrl+k: clear from cursor to end */
|
|
2414
|
-
killToEnd() {
|
|
2415
|
-
this.setChars(this.chars.slice(0, this.cursor), this.cursor);
|
|
2416
|
-
}
|
|
2417
|
-
cursorLeft() {
|
|
2418
|
-
if (this.cursor > 0) this.cursor--;
|
|
2419
|
-
}
|
|
2420
|
-
cursorRight() {
|
|
2421
|
-
if (this.cursor < this.chars.length) this.cursor++;
|
|
2422
|
-
}
|
|
2423
|
-
/** alt+left / esc-b */
|
|
2424
|
-
wordLeft() {
|
|
2425
|
-
this.cursor = this.wordBoundLeft();
|
|
2426
|
-
}
|
|
2427
|
-
/** alt+right / esc-f */
|
|
2428
|
-
wordRight() {
|
|
2429
|
-
this.cursor = this.wordBoundRight();
|
|
2430
|
-
}
|
|
2431
|
-
/** start index (in code points) of the line containing ix */
|
|
2432
|
-
lineStartAt(ix) {
|
|
2433
|
-
const cs = this.chars;
|
|
2434
|
-
let i = ix;
|
|
2435
|
-
while (i > 0 && cs[i - 1] !== "\n") i--;
|
|
2436
|
-
return i;
|
|
2437
|
-
}
|
|
2438
|
-
/** end index (exclusive, before the \n) of the line containing ix */
|
|
2439
|
-
lineEndAt(ix) {
|
|
2440
|
-
const cs = this.chars;
|
|
2441
|
-
let i = ix;
|
|
2442
|
-
while (i < cs.length && cs[i] !== "\n") i++;
|
|
2443
|
-
return i;
|
|
2444
|
-
}
|
|
2445
|
-
/** Home / ⌘← / ⌃A: start of the LOGICAL line; already there → the previous line's start */
|
|
2446
|
-
lineHome() {
|
|
2447
|
-
const start = this.lineStartAt(this.cursor);
|
|
2448
|
-
if (this.cursor !== start || start === 0) return void (this.cursor = start);
|
|
2449
|
-
this.cursor = this.lineStartAt(start - 1);
|
|
2450
|
-
}
|
|
2451
|
-
/** End / ⌘→ / ⌃E: end of the LOGICAL line; already there → the next line's end */
|
|
2452
|
-
lineEnd() {
|
|
2453
|
-
const end = this.lineEndAt(this.cursor);
|
|
2454
|
-
if (this.cursor !== end || end === this.chars.length) return void (this.cursor = end);
|
|
2455
|
-
this.cursor = this.lineEndAt(end + 1);
|
|
2456
|
-
}
|
|
2457
|
-
/** ⌥↑/⌥↓: swap the cursor's logical line with its neighbor, cursor rides along */
|
|
2458
|
-
moveLine(delta) {
|
|
2459
|
-
const cs = this.chars;
|
|
2460
|
-
const start = this.lineStartAt(this.cursor);
|
|
2461
|
-
const end = this.lineEndAt(this.cursor);
|
|
2462
|
-
const col = this.cursor - start;
|
|
2463
|
-
const cur = cs.slice(start, end);
|
|
2464
|
-
if (delta === -1) {
|
|
2465
|
-
if (start === 0) return;
|
|
2466
|
-
const prevStart = this.lineStartAt(start - 1);
|
|
2467
|
-
const prev = cs.slice(prevStart, start - 1);
|
|
2468
|
-
this.setChars([
|
|
2469
|
-
...cs.slice(0, prevStart),
|
|
2470
|
-
...cur,
|
|
2471
|
-
"\n",
|
|
2472
|
-
...prev,
|
|
2473
|
-
...cs.slice(end)
|
|
2474
|
-
], prevStart + Math.min(col, cur.length));
|
|
2475
|
-
} else {
|
|
2476
|
-
if (end === cs.length) return;
|
|
2477
|
-
const nextEnd = this.lineEndAt(end + 1);
|
|
2478
|
-
const next = cs.slice(end + 1, nextEnd);
|
|
2479
|
-
this.setChars([
|
|
2480
|
-
...cs.slice(0, start),
|
|
2481
|
-
...next,
|
|
2482
|
-
"\n",
|
|
2483
|
-
...cur,
|
|
2484
|
-
...cs.slice(nextEnd)
|
|
2485
|
-
], start + next.length + 1 + Math.min(col, cur.length));
|
|
2486
|
-
}
|
|
2487
|
-
}
|
|
2488
|
-
/** ⌘/ / ⌃/ / ⌥/: toggle `// ` at the start of the cursor's line */
|
|
2489
|
-
toggleComment() {
|
|
2490
|
-
const cs = this.chars;
|
|
2491
|
-
const start = this.lineStartAt(this.cursor);
|
|
2492
|
-
const end = this.lineEndAt(this.cursor);
|
|
2493
|
-
const line = cs.slice(start, end).join("");
|
|
2494
|
-
const m = /^(\s*)\/\/ ?/.exec(line);
|
|
2495
|
-
if (m == null) {
|
|
2496
|
-
cs.splice(start, 0, "/", "/", " ");
|
|
2497
|
-
this.setChars(cs, this.cursor + 3);
|
|
2498
|
-
return;
|
|
2499
|
-
}
|
|
2500
|
-
const indentLen = [...m[1] ?? ""].length;
|
|
2501
|
-
const removeLen = [...m[0]].length - indentLen;
|
|
2502
|
-
cs.splice(start + indentLen, removeLen);
|
|
2503
|
-
this.setChars(cs, Math.max(start, this.cursor - removeLen));
|
|
2504
|
-
}
|
|
2505
|
-
cursorUp() {
|
|
2506
|
-
const start = this.lineStartAt(this.cursor);
|
|
2507
|
-
if (start === 0) {
|
|
2508
|
-
this.cursor = 0;
|
|
2509
|
-
return;
|
|
2510
|
-
}
|
|
2511
|
-
const col = this.cursor - start;
|
|
2512
|
-
const prevStart = this.lineStartAt(start - 1);
|
|
2513
|
-
const prevLen = start - 1 - prevStart;
|
|
2514
|
-
this.cursor = prevStart + Math.min(col, prevLen);
|
|
2515
|
-
}
|
|
2516
|
-
cursorDown() {
|
|
2517
|
-
const cs = this.chars;
|
|
2518
|
-
const start = this.lineStartAt(this.cursor);
|
|
2519
|
-
const col = this.cursor - start;
|
|
2520
|
-
let end = this.cursor;
|
|
2521
|
-
while (end < cs.length && cs[end] !== "\n") end++;
|
|
2522
|
-
if (end === cs.length) {
|
|
2523
|
-
this.cursor = cs.length;
|
|
2524
|
-
return;
|
|
2525
|
-
}
|
|
2526
|
-
const nextStart = end + 1;
|
|
2527
|
-
let nextEnd = nextStart;
|
|
2528
|
-
while (nextEnd < cs.length && cs[nextEnd] !== "\n") nextEnd++;
|
|
2529
|
-
this.cursor = nextStart + Math.min(col, nextEnd - nextStart);
|
|
2530
|
-
}
|
|
2531
|
-
};
|
|
2532
|
-
//#endregion
|
|
2533
|
-
//#region src/cli/tui/imageClipboard.ts
|
|
2534
|
-
const extOf = (path) => {
|
|
2535
|
-
const dot = path.lastIndexOf(".");
|
|
2536
|
-
return dot === -1 ? "" : path.slice(dot + 1).toLowerCase();
|
|
2537
|
-
};
|
|
2538
|
-
const imageClipboardStdinCommand = (platform, pngBytes) => {
|
|
2539
|
-
if (platform === "darwin") {
|
|
2540
|
-
const hex = Buffer.from(pngBytes).toString("hex").toUpperCase();
|
|
2541
|
-
return {
|
|
2542
|
-
cmd: "osascript",
|
|
2543
|
-
args: ["-"],
|
|
2544
|
-
stdin: new TextEncoder().encode(`set the clipboard to «data PNGf${hex}»`)
|
|
2545
|
-
};
|
|
2546
|
-
}
|
|
2547
|
-
if (platform === "win32") return {
|
|
2548
|
-
cmd: "powershell",
|
|
2549
|
-
args: [
|
|
2550
|
-
"-NoProfile",
|
|
2551
|
-
"-Sta",
|
|
2552
|
-
"-Command",
|
|
2553
|
-
"$b=[Convert]::FromBase64String([Console]::In.ReadToEnd()); $ms=New-Object System.IO.MemoryStream(,$b); Add-Type -AssemblyName System.Windows.Forms,System.Drawing; $img=[System.Drawing.Image]::FromStream($ms); [System.Windows.Forms.Clipboard]::SetImage($img); $img.Dispose()"
|
|
2554
|
-
],
|
|
2555
|
-
stdin: new TextEncoder().encode(Buffer.from(pngBytes).toString("base64"))
|
|
2556
|
-
};
|
|
2557
|
-
return {
|
|
2558
|
-
cmd: "xclip",
|
|
2559
|
-
args: [
|
|
2560
|
-
"-selection",
|
|
2561
|
-
"clipboard",
|
|
2562
|
-
"-t",
|
|
2563
|
-
"image/png"
|
|
2564
|
-
],
|
|
2565
|
-
stdin: pngBytes
|
|
2566
|
-
};
|
|
2567
|
-
};
|
|
2568
|
-
const imageClipboardCommand = (platform, path) => {
|
|
2569
|
-
const ext = extOf(path);
|
|
2570
|
-
if (platform === "darwin") {
|
|
2571
|
-
if (ext !== "png" && ext !== "jpg" && ext !== "jpeg") return null;
|
|
2572
|
-
const cls = ext === "png" ? "«class PNGf»" : "JPEG picture";
|
|
2573
|
-
return {
|
|
2574
|
-
cmd: "osascript",
|
|
2575
|
-
args: ["-e", `set the clipboard to (read (POSIX file ${JSON.stringify(path)}) as ${cls})`]
|
|
2576
|
-
};
|
|
2577
|
-
}
|
|
2578
|
-
if (platform === "win32") return {
|
|
2579
|
-
cmd: "powershell",
|
|
2580
|
-
args: [
|
|
2581
|
-
"-NoProfile",
|
|
2582
|
-
"-Sta",
|
|
2583
|
-
"-Command",
|
|
2584
|
-
`Add-Type -AssemblyName System.Windows.Forms,System.Drawing; $img=[System.Drawing.Image]::FromFile(${`'${path.replaceAll("'", "''")}'`}); [System.Windows.Forms.Clipboard]::SetImage($img); $img.Dispose()`
|
|
2585
|
-
]
|
|
2586
|
-
};
|
|
2587
|
-
return {
|
|
2588
|
-
cmd: "xclip",
|
|
2589
|
-
args: [
|
|
2590
|
-
"-selection",
|
|
2591
|
-
"clipboard",
|
|
2592
|
-
"-t",
|
|
2593
|
-
ext === "jpg" || ext === "jpeg" ? "image/jpeg" : ext === "webp" ? "image/webp" : "image/png",
|
|
2594
|
-
"-i",
|
|
2595
|
-
path
|
|
2596
|
-
]
|
|
2597
|
-
};
|
|
2598
|
-
};
|
|
2599
|
-
//#endregion
|
|
2600
|
-
//#region src/cli/tui/state/ExecSt.ts
|
|
2601
|
-
/** popup body: summary + the head of the copied json (proof of WHAT is in the clipboard) */
|
|
2602
|
-
function jsonHead(text, maxLines) {
|
|
2603
|
-
const lines = text.split("\n");
|
|
2604
|
-
const head = lines.slice(0, maxLines).map((l) => l.length > 76 ? `${l.slice(0, 75)}…` : l);
|
|
2605
|
-
if (lines.length > maxLines) head.push("…");
|
|
2606
|
-
return head;
|
|
2607
|
-
}
|
|
2608
|
-
/** run lifecycle + outputs + status line + clipboard/open actions */
|
|
2609
|
-
var ExecSt = class {
|
|
2610
|
-
constructor(st) {
|
|
2611
|
-
this.st = st;
|
|
2612
|
-
this.inFlight = 0;
|
|
2613
|
-
this.progress = null;
|
|
2614
|
-
this.outputImages = [];
|
|
2615
|
-
this.runCount = 0;
|
|
2616
|
-
this.lastStatus = null;
|
|
2617
|
-
this.error = null;
|
|
2618
|
-
this.notice = null;
|
|
2619
|
-
this.currentPromptId = null;
|
|
2620
|
-
this.latentHosts = /* @__PURE__ */ new Set();
|
|
2621
|
-
this.copyPopup = null;
|
|
2622
|
-
this.copying = false;
|
|
2623
|
-
makeAutoObservable(this, { st: false });
|
|
2624
|
-
}
|
|
2625
|
-
get running() {
|
|
2626
|
-
return this.inFlight > 0;
|
|
2627
|
-
}
|
|
2628
|
-
/** workflow switch: wipe run artifacts, keep a hello notice */
|
|
2629
|
-
resetForWorkflow(notice) {
|
|
2630
|
-
this.outputImages = [];
|
|
2631
|
-
this.error = null;
|
|
2632
|
-
this.notice = notice;
|
|
2633
|
-
this.runCount = 0;
|
|
2634
|
-
this.lastStatus = null;
|
|
2635
|
-
}
|
|
2636
|
-
/** outputs box rows: path when saved, honest memory label otherwise */
|
|
2637
|
-
get outputLabels() {
|
|
2638
|
-
return this.outputImages.map((img) => {
|
|
2639
|
-
if (img.absPath != null) return {
|
|
2640
|
-
name: basename(img.absPath),
|
|
2641
|
-
detail: img.absPath,
|
|
2642
|
-
memory: false
|
|
2643
|
-
};
|
|
2644
|
-
const dims = img.width != null && img.height != null ? `${img.width}x${img.height}, ` : "";
|
|
2645
|
-
return {
|
|
2646
|
-
name: img.filename,
|
|
2647
|
-
detail: `(${dims}in memory — i copies, o opens)`,
|
|
2648
|
-
memory: true
|
|
2649
|
-
};
|
|
2650
|
-
});
|
|
2651
|
-
}
|
|
2652
|
-
/** a file path for viewer/clipboard: the saved file, or the bytes
|
|
2653
|
-
* materialized into os tmpdir (deliberate user action, never a silent
|
|
2654
|
-
* save — architecture item 14). The path derives from the content hash,
|
|
2655
|
-
* so re-materializing is a cheap existsSync, no retention needed. */
|
|
2656
|
-
materialize(img) {
|
|
2657
|
-
if (img.absPath != null) return img.absPath;
|
|
2658
|
-
const path = join(tmpdir(), `comfy-ts-mem-${img.hash.slice(0, 8)}${img.extension}`);
|
|
2659
|
-
if (!existsSync(path)) writeFileSync(path, img.buffer);
|
|
2660
|
-
return path;
|
|
2661
|
-
}
|
|
2662
|
-
/** every run takes THIS path, queued ones included: same progress, outputs, previews */
|
|
2663
|
-
async run() {
|
|
2664
|
-
const queued = this.running;
|
|
2665
|
-
const host = this.st.runHost;
|
|
2666
|
-
runInAction(() => {
|
|
2667
|
-
this.inFlight++;
|
|
2668
|
-
this.error = null;
|
|
2669
|
-
if (queued) this.notice = `queued another run (server queue: ${this.st.queue.remaining + 1})`;
|
|
2670
|
-
else {
|
|
2671
|
-
this.progress = null;
|
|
2672
|
-
this.notice = null;
|
|
2673
|
-
this.currentPromptId = null;
|
|
2674
|
-
this.st.preview.clearLatent();
|
|
2675
|
-
}
|
|
2676
|
-
host.onLatentPreview = (p) => void this.st.preview.renderLatent(p.bytes);
|
|
2677
|
-
this.latentHosts.add(host);
|
|
2678
|
-
});
|
|
2679
|
-
try {
|
|
2680
|
-
const execution = await this.st.wf.run({
|
|
2681
|
-
host: this.st.hostOverride ?? void 0,
|
|
2682
|
-
save: this.st.settings.saveToDisk ? { prefix: this.st.savePrefix } : false,
|
|
2683
|
-
onProgress: (p) => runInAction(() => this.onProgress(p))
|
|
2684
|
-
});
|
|
2685
|
-
runInAction(() => {
|
|
2686
|
-
this.outputImages = execution.images.slice();
|
|
2687
|
-
this.lastStatus = execution.status;
|
|
2688
|
-
this.runCount++;
|
|
2689
|
-
});
|
|
2690
|
-
const lastImage = execution.images[execution.images.length - 1];
|
|
2691
|
-
if (lastImage != null) this.st.preview.renderOutput(lastImage.absPath ?? lastImage.buffer);
|
|
2692
|
-
} catch (e) {
|
|
2693
|
-
runInAction(() => {
|
|
2694
|
-
this.error = extractErrorMessage(e);
|
|
2695
|
-
});
|
|
2696
|
-
} finally {
|
|
2697
|
-
runInAction(() => {
|
|
2698
|
-
this.inFlight--;
|
|
2699
|
-
this.progress = null;
|
|
2700
|
-
this.currentPromptId = null;
|
|
2701
|
-
this.st.preview.clearLatent();
|
|
2702
|
-
if (this.inFlight === 0) {
|
|
2703
|
-
for (const h of this.latentHosts) h.onLatentPreview = null;
|
|
2704
|
-
this.latentHosts.clear();
|
|
2705
|
-
}
|
|
2706
|
-
});
|
|
2707
|
-
}
|
|
2708
|
-
}
|
|
2709
|
-
/** the server runs prompts one at a time: a NEW promptId = the next queued run just started */
|
|
2710
|
-
onProgress(p) {
|
|
2711
|
-
if (p.promptId !== this.currentPromptId) {
|
|
2712
|
-
this.currentPromptId = p.promptId;
|
|
2713
|
-
this.notice = null;
|
|
2714
|
-
this.st.preview.clearLatent();
|
|
2715
|
-
}
|
|
2716
|
-
this.progress = p;
|
|
2717
|
-
}
|
|
2718
|
-
randomizeSeedAndRun() {
|
|
2719
|
-
for (const [, varDef] of this.st.entries) if (varDef.kind === "seed") varDef.randomize();
|
|
2720
|
-
this.run();
|
|
2721
|
-
}
|
|
2722
|
-
/** 'o': real pixels in the OS viewer — the in-terminal ceiling is half-blocks */
|
|
2723
|
-
openLastOutput() {
|
|
2724
|
-
const lastImg = this.outputImages[this.outputImages.length - 1];
|
|
2725
|
-
if (lastImg == null) {
|
|
2726
|
-
this.notice = "no output image yet";
|
|
2727
|
-
return;
|
|
2728
|
-
}
|
|
2729
|
-
let last;
|
|
2730
|
-
try {
|
|
2731
|
-
last = this.materialize(lastImg);
|
|
2732
|
-
} catch (e) {
|
|
2733
|
-
this.notice = `open failed: ${extractErrorMessage(e)}`;
|
|
2734
|
-
return;
|
|
2735
|
-
}
|
|
2736
|
-
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
2737
|
-
const proc = spawn(cmd, [last], {
|
|
2738
|
-
stdio: "ignore",
|
|
2739
|
-
detached: true
|
|
2740
|
-
});
|
|
2741
|
-
proc.on("error", () => {
|
|
2742
|
-
runInAction(() => {
|
|
2743
|
-
this.notice = `could not launch ${cmd}`;
|
|
2744
|
-
});
|
|
2745
|
-
});
|
|
2746
|
-
proc.unref();
|
|
2747
|
-
this.notice = `opened ${basename(last)}${lastImg.absPath == null ? ` (memory image via ${last})` : ""}`;
|
|
2748
|
-
}
|
|
2749
|
-
closeCopyPopup() {
|
|
2750
|
-
this.copyPopup = null;
|
|
2751
|
-
this.st.mode = "nav";
|
|
2752
|
-
}
|
|
2753
|
-
/** makeAutoObservable already annotates this method as an action, so the
|
|
2754
|
-
* post-await callers below need no runInAction of their own (verified
|
|
2755
|
-
* against mobx: a TS-private prototype method called after an `await`
|
|
2756
|
-
* opens its own action context; only a CONSTRUCTOR body does not) */
|
|
2757
|
-
showCopyPopup(title, ok, lines) {
|
|
2758
|
-
const m = this.st.mode;
|
|
2759
|
-
if (m === "edit" || m.startsWith("overlay-")) {
|
|
2760
|
-
this.notice = `${ok ? "✓" : "✗"} ${title}`;
|
|
2761
|
-
return;
|
|
2762
|
-
}
|
|
2763
|
-
this.copyPopup = {
|
|
2764
|
-
title,
|
|
2765
|
-
ok,
|
|
2766
|
-
lines
|
|
2767
|
-
};
|
|
2768
|
-
this.st.mode = "overlay-copy";
|
|
2769
|
-
}
|
|
2770
|
-
/** 'i': the LAST generated image's pixels → clipboard (paste anywhere).
|
|
2771
|
-
* The primary route pipes png bytes over stdin, so no disk write happens at
|
|
2772
|
-
* all; only when that tool fails does it fall back to the materialized-file
|
|
2773
|
-
* command, and the popup says which route ran. */
|
|
2774
|
-
async copyLastImage() {
|
|
2775
|
-
const lastImg = this.outputImages[this.outputImages.length - 1];
|
|
2776
|
-
if (lastImg == null) {
|
|
2777
|
-
this.showCopyPopup("image → clipboard", false, ["no output image yet — r runs the workflow first"]);
|
|
2778
|
-
return;
|
|
2779
|
-
}
|
|
2780
|
-
let pngBytes;
|
|
2781
|
-
try {
|
|
2782
|
-
pngBytes = lastImg.metadata.type === "png" ? lastImg.buffer : await this.toPngBytes(lastImg.buffer);
|
|
2783
|
-
} catch (e) {
|
|
2784
|
-
this.showCopyPopup("image → clipboard", false, [`COPY FAILED for ${lastImg.filename}`, `png transcode failed: ${extractErrorMessage(e)}`]);
|
|
2785
|
-
return;
|
|
2786
|
-
}
|
|
2787
|
-
const piped = imageClipboardStdinCommand(process.platform, pngBytes);
|
|
2788
|
-
if (await this.runWithStdin(piped)) {
|
|
2789
|
-
this.showCopyPopup("image → clipboard", true, [
|
|
2790
|
-
`${lastImg.filename} — paste the pixels anywhere`,
|
|
2791
|
-
"",
|
|
2792
|
-
"nothing written to disk"
|
|
2793
|
-
]);
|
|
2794
|
-
return;
|
|
2795
|
-
}
|
|
2796
|
-
let file;
|
|
2797
|
-
try {
|
|
2798
|
-
file = this.materialize(lastImg);
|
|
2799
|
-
} catch (e) {
|
|
2800
|
-
this.showCopyPopup("image → clipboard", false, [`COPY FAILED for ${lastImg.filename}`, `piped ${piped.cmd} failed, and the tmp-file fallback could not write: ${extractErrorMessage(e)}`]);
|
|
2801
|
-
return;
|
|
2802
|
-
}
|
|
2803
|
-
const command = imageClipboardCommand(process.platform, file);
|
|
2804
|
-
const ok = command != null && await new Promise((resolve) => {
|
|
2805
|
-
const proc = spawn(command.cmd, command.args, { stdio: "ignore" });
|
|
2806
|
-
proc.on("error", () => resolve(false));
|
|
2807
|
-
proc.on("close", (code) => resolve(code === 0));
|
|
2808
|
-
});
|
|
2809
|
-
this.showCopyPopup("image → clipboard", ok, ok ? [
|
|
2810
|
-
`${basename(file)} — paste the pixels anywhere`,
|
|
2811
|
-
"",
|
|
2812
|
-
`via fallback file ${file}`
|
|
2813
|
-
] : [`COPY FAILED for ${lastImg.filename}`, `could not run ${piped.cmd} — is it installed and allowed ?`]);
|
|
2814
|
-
}
|
|
2815
|
-
async toPngBytes(bytes) {
|
|
2816
|
-
const sharp = await importSharp("the clipboard png normalize");
|
|
2817
|
-
return new Uint8Array(await sharp(bytes).png().toBuffer());
|
|
2818
|
-
}
|
|
2819
|
-
runWithStdin(p) {
|
|
2820
|
-
return new Promise((resolve) => {
|
|
2821
|
-
const proc = spawn(p.cmd, p.args, { stdio: [
|
|
2822
|
-
"pipe",
|
|
2823
|
-
"ignore",
|
|
2824
|
-
"ignore"
|
|
2825
|
-
] });
|
|
2826
|
-
proc.on("error", () => resolve(false));
|
|
2827
|
-
proc.on("close", (code) => resolve(code === 0));
|
|
2828
|
-
proc.stdin.on("error", () => {});
|
|
2829
|
-
proc.stdin.write(p.stdin);
|
|
2830
|
-
proc.stdin.end();
|
|
2831
|
-
});
|
|
2832
|
-
}
|
|
2833
|
-
toClipboard(text) {
|
|
2834
|
-
const [cmd, ...args] = process.platform === "darwin" ? ["pbcopy"] : process.platform === "win32" ? ["clip"] : [
|
|
2835
|
-
"xclip",
|
|
2836
|
-
"-selection",
|
|
2837
|
-
"clipboard"
|
|
2838
|
-
];
|
|
2839
|
-
return new Promise((resolve) => {
|
|
2840
|
-
const proc = spawn(cmd ?? "pbcopy", args, { stdio: [
|
|
2841
|
-
"pipe",
|
|
2842
|
-
"ignore",
|
|
2843
|
-
"ignore"
|
|
2844
|
-
] });
|
|
2845
|
-
proc.on("error", () => resolve(false));
|
|
2846
|
-
proc.on("close", (code) => resolve(code === 0));
|
|
2847
|
-
proc.stdin.write(text);
|
|
2848
|
-
proc.stdin.end();
|
|
2849
|
-
});
|
|
2850
|
-
}
|
|
2851
|
-
/** 'c': copy workflow.json (litegraph, drag into the ComfyUI editor) */
|
|
2852
|
-
async copyWorkflowJson() {
|
|
2853
|
-
if (this.copying) return;
|
|
2854
|
-
runInAction(() => {
|
|
2855
|
-
this.copying = true;
|
|
2856
|
-
this.notice = "building for copy… (i2i workflows upload their input image first)";
|
|
2857
|
-
});
|
|
2858
|
-
try {
|
|
2859
|
-
const json = await (await this.st.wf.build({ host: this.st.hostOverride ?? void 0 })).toWorkflowJson();
|
|
2860
|
-
const text = JSON.stringify(json, null, 2);
|
|
2861
|
-
const ok = await this.toClipboard(text);
|
|
2862
|
-
this.showCopyPopup("workflow.json → clipboard", ok, ok ? [
|
|
2863
|
-
`${json.nodes.length} nodes · ${text.length} chars — paste into the ComfyUI editor`,
|
|
2864
|
-
"",
|
|
2865
|
-
...jsonHead(text, 10)
|
|
2866
|
-
] : ["CLIPBOARD COPY FAILED — is a clipboard tool available (pbcopy/clip/xclip) ?"]);
|
|
2867
|
-
} catch (e) {
|
|
2868
|
-
this.showCopyPopup("workflow.json copy FAILED", false, [
|
|
2869
|
-
extractErrorMessage(e),
|
|
2870
|
-
"",
|
|
2871
|
-
"nothing was copied. i2i/i2v builds upload their input image first —",
|
|
2872
|
-
"an unreachable host fails the build itself, not just the run."
|
|
2873
|
-
]);
|
|
2874
|
-
} finally {
|
|
2875
|
-
runInAction(() => {
|
|
2876
|
-
this.copying = false;
|
|
2877
|
-
});
|
|
2878
|
-
}
|
|
2879
|
-
}
|
|
2880
|
-
/** 'C': copy api.json (the POST /prompt payload) */
|
|
2881
|
-
async copyApiJson() {
|
|
2882
|
-
if (this.copying) return;
|
|
2883
|
-
runInAction(() => {
|
|
2884
|
-
this.copying = true;
|
|
2885
|
-
this.notice = "building for copy… (i2i workflows upload their input image first)";
|
|
2886
|
-
});
|
|
2887
|
-
try {
|
|
2888
|
-
const json = (await this.st.wf.build({ host: this.st.hostOverride ?? void 0 })).toApiJson("use_stringified_numbers_only");
|
|
2889
|
-
const text = JSON.stringify(json, null, 2);
|
|
2890
|
-
const ok = await this.toClipboard(text);
|
|
2891
|
-
this.showCopyPopup("api.json → clipboard", ok, ok ? [
|
|
2892
|
-
`${Object.keys(json).length} nodes · ${text.length} chars — the POST /prompt payload`,
|
|
2893
|
-
"",
|
|
2894
|
-
...jsonHead(text, 10)
|
|
2895
|
-
] : ["CLIPBOARD COPY FAILED — is a clipboard tool available (pbcopy/clip/xclip) ?"]);
|
|
2896
|
-
} catch (e) {
|
|
2897
|
-
this.showCopyPopup("api.json copy FAILED", false, [
|
|
2898
|
-
extractErrorMessage(e),
|
|
2899
|
-
"",
|
|
2900
|
-
"nothing was copied. i2i/i2v builds upload their input image first —",
|
|
2901
|
-
"an unreachable host fails the build itself, not just the run."
|
|
2902
|
-
]);
|
|
2903
|
-
} finally {
|
|
2904
|
-
runInAction(() => {
|
|
2905
|
-
this.copying = false;
|
|
2906
|
-
});
|
|
2907
|
-
}
|
|
2908
|
-
}
|
|
2909
|
-
};
|
|
2910
|
-
//#endregion
|
|
2911
|
-
//#region src/cli/tui/state/HostSt.ts
|
|
2912
|
-
const PROBE_EVERY_MS = 5e3;
|
|
2913
|
-
/** a light drift check (the loaders only) at most this often while the host is up */
|
|
2914
|
-
const DRIFT_EVERY_MS = 6e4;
|
|
2915
|
-
const PROBE_TIMEOUT_MS = 3e3;
|
|
2916
|
-
const SPIN_FRAMES = [
|
|
2917
|
-
"⠋",
|
|
2918
|
-
"⠙",
|
|
2919
|
-
"⠹",
|
|
2920
|
-
"⠸",
|
|
2921
|
-
"⠼",
|
|
2922
|
-
"⠴",
|
|
2923
|
-
"⠦",
|
|
2924
|
-
"⠧",
|
|
2925
|
-
"⠇",
|
|
2926
|
-
"⠏"
|
|
2927
|
-
];
|
|
2928
|
-
/**
|
|
2929
|
-
* PURE probe verdict (headless-tested). http ok is proof enough; on http
|
|
2930
|
-
* failure a RECENTLY TALKING open ws still means up — ComfyUI is
|
|
2931
|
-
* single-threaded and stalls new connects mid-generation while established
|
|
2932
|
-
* sockets stream (observed: a host shown 'offline' in the header
|
|
2933
|
-
* while the browser tab generated fine). A half-open socket receives
|
|
2934
|
-
* nothing, so the recency window never revives one.
|
|
2935
|
-
*/
|
|
2936
|
-
function probeVerdict(p) {
|
|
2937
|
-
if (p.httpOk) return {
|
|
2938
|
-
status: "up",
|
|
2939
|
-
via: p.wsOpen ? "ws" : "http"
|
|
2940
|
-
};
|
|
2941
|
-
if (p.wsOpen && p.lastWsMessageAt != null && p.now - p.lastWsMessageAt < 1e4) return {
|
|
2942
|
-
status: "up",
|
|
2943
|
-
via: "ws"
|
|
2944
|
-
};
|
|
2945
|
-
return {
|
|
2946
|
-
status: "down",
|
|
2947
|
-
via: null
|
|
2948
|
-
};
|
|
2949
|
-
}
|
|
2950
|
-
/** host panel (`h`): stats about the connected host + maintenance actions */
|
|
2951
|
-
var HostSt = class {
|
|
2952
|
-
constructor(st) {
|
|
2953
|
-
this.st = st;
|
|
2954
|
-
this.status = "unknown";
|
|
2955
|
-
this.statusVia = null;
|
|
2956
|
-
this.lastProbeError = null;
|
|
2957
|
-
this.probing = false;
|
|
2958
|
-
this.retryInS = 0;
|
|
2959
|
-
this.spinFrame = 0;
|
|
2960
|
-
this.disposed = false;
|
|
2961
|
-
this.probeGen = 0;
|
|
2962
|
-
this.loopTimer = null;
|
|
2963
|
-
this.spinTimer = null;
|
|
2964
|
-
this.countdownTimer = null;
|
|
2965
|
-
this.drift = "";
|
|
2966
|
-
this.driftAt = 0;
|
|
2967
|
-
this.ix = 0;
|
|
2968
|
-
this.running = null;
|
|
2969
|
-
this.actions = [
|
|
2970
|
-
{
|
|
2971
|
-
key: "refresh",
|
|
2972
|
-
label: "re-codegen SDK (refetch object_info + reload workflow)"
|
|
2973
|
-
},
|
|
2974
|
-
{
|
|
2975
|
-
key: "restart",
|
|
2976
|
-
label: "restart ComfyUI (manager reboot)"
|
|
2977
|
-
},
|
|
2978
|
-
{
|
|
2979
|
-
key: "clear-queue",
|
|
2980
|
-
label: "clear pending queue"
|
|
2981
|
-
},
|
|
2982
|
-
{
|
|
2983
|
-
key: "interrupt",
|
|
2984
|
-
label: "interrupt current run"
|
|
2985
|
-
}
|
|
2986
|
-
];
|
|
2987
|
-
this.pickerIx = 0;
|
|
2988
|
-
makeAutoObservable(this, { st: false });
|
|
2989
|
-
this.probeLoop();
|
|
2990
|
-
this.st.disposers.push(() => {
|
|
2991
|
-
this.disposed = true;
|
|
2992
|
-
if (this.loopTimer != null) clearTimeout(this.loopTimer);
|
|
2993
|
-
if (this.spinTimer != null) clearInterval(this.spinTimer);
|
|
2994
|
-
if (this.countdownTimer != null) clearInterval(this.countdownTimer);
|
|
2995
|
-
});
|
|
2996
|
-
this.st.disposers.push(reaction(() => this.st.runHost, () => {
|
|
2997
|
-
runInAction(() => {
|
|
2998
|
-
this.status = "unknown";
|
|
2999
|
-
this.statusVia = null;
|
|
3000
|
-
this.lastProbeError = null;
|
|
3001
|
-
this.drift = "";
|
|
3002
|
-
});
|
|
3003
|
-
this.probeGen++;
|
|
3004
|
-
if (this.loopTimer != null) clearTimeout(this.loopTimer);
|
|
3005
|
-
if (this.countdownTimer != null) clearInterval(this.countdownTimer);
|
|
3006
|
-
this.probeLoop();
|
|
3007
|
-
}));
|
|
3008
|
-
}
|
|
3009
|
-
get spinner() {
|
|
3010
|
-
return SPIN_FRAMES[this.spinFrame % SPIN_FRAMES.length] ?? "⠋";
|
|
3011
|
-
}
|
|
3012
|
-
/** probe → schedule the next one (setTimeout chain: the countdown is exact) */
|
|
3013
|
-
async probeLoop() {
|
|
3014
|
-
const gen = this.probeGen;
|
|
3015
|
-
await this.probe();
|
|
3016
|
-
if (this.disposed || gen !== this.probeGen) return;
|
|
3017
|
-
const nextAt = Date.now() + PROBE_EVERY_MS;
|
|
3018
|
-
runInAction(() => {
|
|
3019
|
-
this.retryInS = Math.ceil(PROBE_EVERY_MS / 1e3);
|
|
3020
|
-
});
|
|
3021
|
-
if (this.countdownTimer != null) clearInterval(this.countdownTimer);
|
|
3022
|
-
this.countdownTimer = setInterval(() => {
|
|
3023
|
-
runInAction(() => {
|
|
3024
|
-
this.retryInS = Math.max(0, Math.ceil((nextAt - Date.now()) / 1e3));
|
|
3025
|
-
});
|
|
3026
|
-
}, 250);
|
|
3027
|
-
this.countdownTimer.unref?.();
|
|
3028
|
-
this.loopTimer = setTimeout(() => {
|
|
3029
|
-
if (this.countdownTimer != null) clearInterval(this.countdownTimer);
|
|
3030
|
-
this.probeLoop();
|
|
3031
|
-
}, PROBE_EVERY_MS);
|
|
3032
|
-
this.loopTimer.unref?.();
|
|
3033
|
-
}
|
|
3034
|
-
/** http first — a half-open ws keeps isOpen=true forever, so isOpen alone
|
|
3035
|
-
* is never trusted. RECENT MESSAGES are: probeVerdict lets a talking ws
|
|
3036
|
-
* beat a stalled http probe (busy single-threaded server) */
|
|
3037
|
-
async probe() {
|
|
3038
|
-
const host = this.host;
|
|
3039
|
-
runInAction(() => {
|
|
3040
|
-
this.probing = true;
|
|
3041
|
-
});
|
|
3042
|
-
const spin = setInterval(() => {
|
|
3043
|
-
runInAction(() => {
|
|
3044
|
-
this.spinFrame++;
|
|
3045
|
-
});
|
|
3046
|
-
}, 120);
|
|
3047
|
-
spin.unref?.();
|
|
3048
|
-
this.spinTimer = spin;
|
|
3049
|
-
let ok = false;
|
|
3050
|
-
let probeError = null;
|
|
3051
|
-
try {
|
|
3052
|
-
const res = await host.fetch("/prompt", { signal: AbortSignal.timeout(PROBE_TIMEOUT_MS) });
|
|
3053
|
-
res.body?.cancel();
|
|
3054
|
-
ok = res.ok;
|
|
3055
|
-
if (!ok) probeError = `http ${res.status}`;
|
|
3056
|
-
} catch (e) {
|
|
3057
|
-
ok = false;
|
|
3058
|
-
probeError = extractErrorMessage(e);
|
|
3059
|
-
} finally {
|
|
3060
|
-
clearInterval(spin);
|
|
3061
|
-
if (this.spinTimer === spin) {
|
|
3062
|
-
this.spinTimer = null;
|
|
3063
|
-
runInAction(() => {
|
|
3064
|
-
this.probing = false;
|
|
3065
|
-
});
|
|
3066
|
-
}
|
|
3067
|
-
}
|
|
3068
|
-
if (this.host !== host) return;
|
|
3069
|
-
const before = this.status;
|
|
3070
|
-
const verdict = probeVerdict({
|
|
3071
|
-
httpOk: ok,
|
|
3072
|
-
wsOpen: host.isConnected,
|
|
3073
|
-
lastWsMessageAt: host.lastWsMessageAt,
|
|
3074
|
-
now: Date.now()
|
|
3075
|
-
});
|
|
3076
|
-
runInAction(() => {
|
|
3077
|
-
this.status = verdict.status;
|
|
3078
|
-
this.statusVia = verdict.via;
|
|
3079
|
-
this.lastProbeError = probeError;
|
|
3080
|
-
});
|
|
3081
|
-
if (verdict.status === "up") {
|
|
3082
|
-
if (before !== "up") this.checkDrift(true);
|
|
3083
|
-
else if (Date.now() - this.driftAt > DRIFT_EVERY_MS) this.checkDrift(false);
|
|
3084
|
-
}
|
|
3085
|
-
}
|
|
3086
|
-
async checkDrift(full) {
|
|
3087
|
-
const host = this.host;
|
|
3088
|
-
if (host.data.sdkAutoWrite === false) return;
|
|
3089
|
-
this.driftAt = Date.now();
|
|
3090
|
-
try {
|
|
3091
|
-
const summary = summarizeDrift(await host.checkSchemaDrift({ full }));
|
|
3092
|
-
if (this.host !== host) return;
|
|
3093
|
-
runInAction(() => {
|
|
3094
|
-
if (summary !== "") this.drift = summary;
|
|
3095
|
-
else if (full) this.drift = "";
|
|
3096
|
-
});
|
|
3097
|
-
} catch {}
|
|
3098
|
-
}
|
|
3099
|
-
get host() {
|
|
3100
|
-
return this.st.runHost;
|
|
3101
|
-
}
|
|
3102
|
-
get stats() {
|
|
3103
|
-
const schema = this.host.schema;
|
|
3104
|
-
return [
|
|
3105
|
-
{
|
|
3106
|
-
label: "status",
|
|
3107
|
-
value: this.status === "down" ? `down · ${this.probing ? `${this.spinner} probing…` : `retry in ${this.retryInS}s`}` : this.status + (this.statusVia != null ? ` (${this.statusVia})` : "")
|
|
3108
|
-
},
|
|
3109
|
-
...this.lastProbeError != null ? [{
|
|
3110
|
-
label: "http probe",
|
|
3111
|
-
value: this.lastProbeError
|
|
3112
|
-
}] : [],
|
|
3113
|
-
{
|
|
3114
|
-
label: "node types",
|
|
3115
|
-
value: String(schema.nodes.length)
|
|
3116
|
-
},
|
|
3117
|
-
{
|
|
3118
|
-
label: "loras",
|
|
3119
|
-
value: String(schema.getLoras().length)
|
|
3120
|
-
},
|
|
3121
|
-
{
|
|
3122
|
-
label: "embeddings",
|
|
3123
|
-
value: String(schema.data.embeddings.length)
|
|
3124
|
-
},
|
|
3125
|
-
{
|
|
3126
|
-
label: "queue",
|
|
3127
|
-
value: String(this.st.queue.remaining)
|
|
3128
|
-
},
|
|
3129
|
-
{
|
|
3130
|
-
label: "ws",
|
|
3131
|
-
value: this.host.noAddress ?? this.host.getWSUrl()
|
|
3132
|
-
}
|
|
3133
|
-
];
|
|
3134
|
-
}
|
|
3135
|
-
begin() {
|
|
3136
|
-
this.st.mode = "host";
|
|
3137
|
-
this.ix = 0;
|
|
3138
|
-
}
|
|
3139
|
-
blur() {
|
|
3140
|
-
this.st.mode = "nav";
|
|
3141
|
-
}
|
|
3142
|
-
get pickerRows() {
|
|
3143
|
-
const rows = [{
|
|
3144
|
-
host: null,
|
|
3145
|
-
label: `workflow default (${this.st.wf.host.data.id})`,
|
|
3146
|
-
active: this.st.hostOverride == null
|
|
3147
|
-
}];
|
|
3148
|
-
for (const host of comfyts.hosts.values()) rows.push({
|
|
3149
|
-
host,
|
|
3150
|
-
label: `${host.data.id} (${host.addressLabel})`,
|
|
3151
|
-
active: this.st.hostOverride === host
|
|
3152
|
-
});
|
|
3153
|
-
return rows;
|
|
3154
|
-
}
|
|
3155
|
-
beginPicker() {
|
|
3156
|
-
this.st.mode = "overlay-hosts";
|
|
3157
|
-
const active = this.pickerRows.findIndex((r) => r.active);
|
|
3158
|
-
this.pickerIx = active === -1 ? 0 : active;
|
|
3159
|
-
}
|
|
3160
|
-
cancelPicker() {
|
|
3161
|
-
this.st.mode = "nav";
|
|
3162
|
-
}
|
|
3163
|
-
pickerMove(delta) {
|
|
3164
|
-
const len = this.pickerRows.length;
|
|
3165
|
-
if (len === 0) return;
|
|
3166
|
-
this.pickerIx = (this.pickerIx + delta + len) % len;
|
|
3167
|
-
}
|
|
3168
|
-
commitPicker() {
|
|
3169
|
-
const row = this.pickerRows[this.pickerIx];
|
|
3170
|
-
if (row == null) return;
|
|
3171
|
-
this.st.setHostOverride(row.host);
|
|
3172
|
-
this.st.mode = "nav";
|
|
3173
|
-
this.st.exec.notice = row.host == null ? `host override cleared — runs target the workflow's own host (${this.st.wf.host.data.id})` : `runs now target ${row.host.data.id} (overrides ${this.st.wf.host.data.id})`;
|
|
3174
|
-
}
|
|
3175
|
-
move(delta) {
|
|
3176
|
-
const len = this.actions.length;
|
|
3177
|
-
this.ix = (this.ix + delta + len) % len;
|
|
3178
|
-
}
|
|
3179
|
-
async commit() {
|
|
3180
|
-
const action = this.actions[this.ix];
|
|
3181
|
-
if (action == null || this.running != null) return;
|
|
3182
|
-
if (action.key === "refresh") return this.refreshSdk();
|
|
3183
|
-
if (action.key === "restart") return this.restartComfy();
|
|
3184
|
-
if (action.key === "clear-queue") return this.st.queue.clearPending();
|
|
3185
|
-
return this.st.queue.interrupt();
|
|
3186
|
-
}
|
|
3187
|
-
/** refetch object_info, regen the sdk, then cache-busted reload of the current
|
|
3188
|
-
* module so dynamic var options (v.loras…) see the new values */
|
|
3189
|
-
async refreshSdk() {
|
|
3190
|
-
runInAction(() => {
|
|
3191
|
-
this.running = "refresh";
|
|
3192
|
-
});
|
|
3193
|
-
try {
|
|
3194
|
-
await this.host.fetchAndUpdateSchema();
|
|
3195
|
-
await this.st.workflows.reload(this.st.drafts.active ?? "default");
|
|
3196
|
-
runInAction(() => {
|
|
3197
|
-
const schema = this.host.schema;
|
|
3198
|
-
this.st.exec.notice = `SDK regenerated: ${schema.nodes.length} node types, ${schema.getLoras().length} loras`;
|
|
3199
|
-
this.drift = "";
|
|
3200
|
-
});
|
|
3201
|
-
} catch (e) {
|
|
3202
|
-
runInAction(() => {
|
|
3203
|
-
this.st.exec.error = extractErrorMessage(e);
|
|
3204
|
-
});
|
|
3205
|
-
} finally {
|
|
3206
|
-
runInAction(() => {
|
|
3207
|
-
this.running = null;
|
|
3208
|
-
});
|
|
3209
|
-
}
|
|
3210
|
-
}
|
|
3211
|
-
async restartComfy() {
|
|
3212
|
-
runInAction(() => {
|
|
3213
|
-
this.running = "restart";
|
|
3214
|
-
});
|
|
3215
|
-
try {
|
|
3216
|
-
await this.host.manager.restartComfyUI();
|
|
3217
|
-
runInAction(() => {
|
|
3218
|
-
this.st.exec.notice = "reboot requested — the ws reconnects when the host is back";
|
|
3219
|
-
});
|
|
3220
|
-
} catch (e) {
|
|
3221
|
-
runInAction(() => {
|
|
3222
|
-
this.st.exec.notice = `🔴 reboot refused: ${extractErrorMessage(e)}`;
|
|
3223
|
-
});
|
|
3224
|
-
} finally {
|
|
3225
|
-
runInAction(() => {
|
|
3226
|
-
this.running = null;
|
|
3227
|
-
});
|
|
3228
|
-
}
|
|
3229
|
-
}
|
|
3230
|
-
};
|
|
3231
|
-
//#endregion
|
|
3232
|
-
//#region src/cli/tui/state/LorasSt.ts
|
|
3233
|
-
/** loras overlay: filter + tick/untick + strengths + bulk ops + lora-manager metadata & preview */
|
|
3234
|
-
var LorasSt = class {
|
|
3235
|
-
constructor(st) {
|
|
3236
|
-
this.st = st;
|
|
3237
|
-
this.ix = 0;
|
|
3238
|
-
this.filter = "";
|
|
3239
|
-
this.previewMap = void 0;
|
|
3240
|
-
this.previewMapHostId = null;
|
|
3241
|
-
this.previewSweepStatus = null;
|
|
3242
|
-
this._busy = false;
|
|
3243
|
-
makeAutoObservable(this, { st: false });
|
|
3244
|
-
this.st.disposers.push(reaction(() => this.st.mode === "overlay-loras" ? this.selectedName : null, () => void this.refreshPreview(), { delay: this.st.timing.previewMs }));
|
|
3245
|
-
}
|
|
3246
|
-
/** kind-narrowing cast sanctioned (agent/coding.md), `kind` is the tag */
|
|
3247
|
-
get selectedVar() {
|
|
3248
|
-
const sel = this.st.selected?.[1];
|
|
3249
|
-
return sel?.kind === "loras" ? sel : null;
|
|
3250
|
-
}
|
|
3251
|
-
/**
|
|
3252
|
-
* the host a run will actually target, which is what the metadata must
|
|
3253
|
-
* describe. NOT `wf.host`: pressing `h` overrides the run host, and reading
|
|
3254
|
-
* the defining host's mirror then showed one host's model names while the
|
|
3255
|
-
* generation went to another. `bindHost` also stamped the defining host onto
|
|
3256
|
-
* the var at define time, so the injected keywords are re-pointed with it.
|
|
3257
|
-
*/
|
|
3258
|
-
get hostId() {
|
|
3259
|
-
return this.st.runHost.data.id;
|
|
3260
|
-
}
|
|
3261
|
-
/**
|
|
3262
|
-
* options surviving the filter (bulk ops apply to exactly these).
|
|
3263
|
-
* The filter matches the file name OR anything the lora-manager mirror knows:
|
|
3264
|
-
* model name, tags, base model, trigger words.
|
|
3265
|
-
*/
|
|
3266
|
-
get filteredNames() {
|
|
3267
|
-
const lv = this.selectedVar;
|
|
3268
|
-
if (lv == null) return [];
|
|
3269
|
-
if (this.filter === "") return lv.names;
|
|
3270
|
-
return lv.names.filter((n) => loraMatchesFilter(n, this.filter, this.hostId));
|
|
3271
|
-
}
|
|
3272
|
-
begin() {
|
|
3273
|
-
if (this.selectedVar == null) return;
|
|
3274
|
-
refreshLoraInfoCacheIfChanged();
|
|
3275
|
-
const lv = this.selectedVar;
|
|
3276
|
-
if (lv != null) lv.hostId = this.hostId;
|
|
3277
|
-
this.st.mode = "overlay-loras";
|
|
3278
|
-
this.ix = 0;
|
|
3279
|
-
this.filter = "";
|
|
3280
|
-
this.st.preview.clearOverlayImage();
|
|
3281
|
-
}
|
|
3282
|
-
move(delta) {
|
|
3283
|
-
const len = this.filteredNames.length;
|
|
3284
|
-
if (len === 0) return;
|
|
3285
|
-
this.ix = (this.ix + delta + len) % len;
|
|
3286
|
-
}
|
|
3287
|
-
filterInput(chunk) {
|
|
3288
|
-
this.filter += chunk;
|
|
3289
|
-
this.ix = 0;
|
|
3290
|
-
}
|
|
3291
|
-
filterBackspace() {
|
|
3292
|
-
this.filter = this.filter.slice(0, -1);
|
|
3293
|
-
this.ix = 0;
|
|
3294
|
-
}
|
|
3295
|
-
/** ⌥⌫ / ⌃W: drop the last word of the filter */
|
|
3296
|
-
filterDeleteWord() {
|
|
3297
|
-
this.filter = this.filter.replace(/\s*\S+\s*$/, "");
|
|
3298
|
-
this.ix = 0;
|
|
3299
|
-
}
|
|
3300
|
-
toggle() {
|
|
3301
|
-
const lv = this.selectedVar;
|
|
3302
|
-
const name = this.filteredNames[this.ix];
|
|
3303
|
-
if (lv == null || name == null) return;
|
|
3304
|
-
lv.toggleItem(name);
|
|
3305
|
-
}
|
|
3306
|
-
/** ⌃A / ⌃N: tick / untick every lora surviving the filter */
|
|
3307
|
-
setAll(on) {
|
|
3308
|
-
this.selectedVar?.setAll(on, this.filteredNames);
|
|
3309
|
-
}
|
|
3310
|
-
adjust(delta) {
|
|
3311
|
-
const lv = this.selectedVar;
|
|
3312
|
-
const name = this.filteredNames[this.ix];
|
|
3313
|
-
if (lv == null || name == null) return;
|
|
3314
|
-
lv.adjustItem(name, delta);
|
|
3315
|
-
}
|
|
3316
|
-
/** ⌃K: assign the selected lora's trigger keyword (PromptVar prefixes actives with it) */
|
|
3317
|
-
beginKeyword() {
|
|
3318
|
-
const name = this.selectedName;
|
|
3319
|
-
if (name == null) return;
|
|
3320
|
-
const fromMirror = loraKeywordFromMirror(name, this.hostId);
|
|
3321
|
-
const hint = fromMirror === "" ? "empty clears" : isLoraKeywordFromMirror(name, this.hostId) ? "from lora-manager · empty = inject nothing" : `overrides lora-manager · esc then ⌃D restores "${fromMirror}"`;
|
|
3322
|
-
this.st.editor.beginCustom({
|
|
3323
|
-
title: `keyword for ${LorasVar.shortName(name)} (${hint})`,
|
|
3324
|
-
initial: getLoraKeyword(name, this.hostId),
|
|
3325
|
-
onCommit: (raw) => {
|
|
3326
|
-
setLoraKeyword(name, raw, this.hostId);
|
|
3327
|
-
return true;
|
|
3328
|
-
},
|
|
3329
|
-
returnMode: "overlay-loras"
|
|
3330
|
-
});
|
|
3331
|
-
}
|
|
3332
|
-
/** ⌃D: drop the hand keyword, so this lora falls back to lora-manager's trigger words */
|
|
3333
|
-
resetKeyword() {
|
|
3334
|
-
const name = this.selectedName;
|
|
3335
|
-
if (name == null) return;
|
|
3336
|
-
clearLoraKeywordOverride(name);
|
|
3337
|
-
}
|
|
3338
|
-
get selectedName() {
|
|
3339
|
-
return this.filteredNames[this.ix] ?? null;
|
|
3340
|
-
}
|
|
3341
|
-
/** preview goes through PreviewSt's shared overlay slot (one code path with the image picker) */
|
|
3342
|
-
async refreshPreview() {
|
|
3343
|
-
if (this.st.mode !== "overlay-loras") {
|
|
3344
|
-
if (!this.st.preview.overlayActive) this.st.preview.clearOverlayImage();
|
|
3345
|
-
return;
|
|
3346
|
-
}
|
|
3347
|
-
const name = this.selectedName;
|
|
3348
|
-
if (name == null || this._busy) return;
|
|
3349
|
-
this._busy = true;
|
|
3350
|
-
try {
|
|
3351
|
-
const host = this.st.runHost;
|
|
3352
|
-
let url = getLoraPreviewUrl(name, host.data.id);
|
|
3353
|
-
let miss = "no preview available";
|
|
3354
|
-
if (url == null) {
|
|
3355
|
-
if (this.previewMap === void 0 || this.previewMapHostId !== host.data.id) {
|
|
3356
|
-
const sweep = await fetchLoraList(host);
|
|
3357
|
-
this.previewMap = sweep.status === "absent" || sweep.status === "unreachable" ? null : loraPreviewMapFrom(sweep.items);
|
|
3358
|
-
this.previewSweepStatus = sweep.status;
|
|
3359
|
-
this.previewMapHostId = host.data.id;
|
|
3360
|
-
}
|
|
3361
|
-
url = this.previewMap?.get(loraKey(name)) ?? null;
|
|
3362
|
-
if (this.previewSweepStatus === "absent") miss = "lora-manager extension not detected";
|
|
3363
|
-
else if (this.previewSweepStatus === "unreachable") miss = "host unreachable";
|
|
3364
|
-
else if (this.previewSweepStatus === "partial") miss = "lora-manager answered only part of its list";
|
|
3365
|
-
}
|
|
3366
|
-
const note = url != null ? null : miss;
|
|
3367
|
-
if (url == null) {
|
|
3368
|
-
this.st.preview.setOverlayImage({
|
|
3369
|
-
bytes: null,
|
|
3370
|
-
ansi: null,
|
|
3371
|
-
name: `lora ${name}`,
|
|
3372
|
-
note
|
|
3373
|
-
}, "overlay-loras");
|
|
3374
|
-
return;
|
|
3375
|
-
}
|
|
3376
|
-
const bytes = await fetchLoraPreviewBytes(host, url);
|
|
3377
|
-
if (bytes == null) throw new Error("no image preview on the server");
|
|
3378
|
-
if (this.st.preview.useNative) {
|
|
3379
|
-
this.st.preview.setOverlayImage({
|
|
3380
|
-
bytes: await protocolReadyBytes(bytes),
|
|
3381
|
-
ansi: null,
|
|
3382
|
-
name: `lora ${name}`,
|
|
3383
|
-
note: null
|
|
3384
|
-
}, "overlay-loras");
|
|
3385
|
-
return;
|
|
3386
|
-
}
|
|
3387
|
-
const ansi = await imageBufferToAnsi(bytes, {
|
|
3388
|
-
width: this.st.preview.width,
|
|
3389
|
-
height: this.st.preview.height
|
|
3390
|
-
});
|
|
3391
|
-
this.st.preview.setOverlayImage({
|
|
3392
|
-
bytes: null,
|
|
3393
|
-
ansi,
|
|
3394
|
-
name: `lora ${name}`,
|
|
3395
|
-
note: null
|
|
3396
|
-
}, "overlay-loras");
|
|
3397
|
-
} catch (e) {
|
|
3398
|
-
this.st.preview.setOverlayImage({
|
|
3399
|
-
bytes: null,
|
|
3400
|
-
ansi: null,
|
|
3401
|
-
name: `lora ${name}`,
|
|
3402
|
-
note: extractErrorMessage(e)
|
|
3403
|
-
}, "overlay-loras");
|
|
3404
|
-
} finally {
|
|
3405
|
-
this._busy = false;
|
|
3406
|
-
if (this.st.mode === "overlay-loras" && this.selectedName !== name) this.refreshPreview();
|
|
3407
|
-
}
|
|
3408
|
-
}
|
|
3409
|
-
};
|
|
3410
|
-
//#endregion
|
|
3411
|
-
//#region src/cli/tui/state/PickerSt.ts
|
|
3412
|
-
/**
|
|
3413
|
-
* choice + size + preset overlays: a windowed option list with a fuzzy type-to-filter.
|
|
3414
|
-
* For sizes the filter doubles as free `WxH` entry.
|
|
3415
|
-
*/
|
|
3416
|
-
var PickerSt = class {
|
|
3417
|
-
constructor(st) {
|
|
3418
|
-
this.st = st;
|
|
3419
|
-
this.filter = "";
|
|
3420
|
-
this.ix = 0;
|
|
3421
|
-
this.invalid = false;
|
|
3422
|
-
this.imageSizeRow = null;
|
|
3423
|
-
makeAutoObservable(this, { st: false });
|
|
3424
|
-
}
|
|
3425
|
-
get choiceVar() {
|
|
3426
|
-
const sel = this.st.selected?.[1];
|
|
3427
|
-
return sel?.kind === "choice" ? sel : null;
|
|
3428
|
-
}
|
|
3429
|
-
/** is this option currently picked (one, one or none, or one of many) */
|
|
3430
|
-
isPicked(option) {
|
|
3431
|
-
const cv = this.choiceVar;
|
|
3432
|
-
if (cv == null) return false;
|
|
3433
|
-
return cv.select === "many" ? cv.value.includes(option) : cv.value === option;
|
|
3434
|
-
}
|
|
3435
|
-
/** a many-choice stays open after ⏎: you toggle several, esc leaves */
|
|
3436
|
-
get choiceIsMany() {
|
|
3437
|
-
return this.choiceVar?.select === "many";
|
|
3438
|
-
}
|
|
3439
|
-
get sizeVar() {
|
|
3440
|
-
const sel = this.st.selected?.[1];
|
|
3441
|
-
return sel?.kind === "size" ? sel : null;
|
|
3442
|
-
}
|
|
3443
|
-
/** null when the selected var is not text/prompt, or carries no presets */
|
|
3444
|
-
get presetVar() {
|
|
3445
|
-
const sel = this.st.selected?.[1];
|
|
3446
|
-
if (sel == null || sel.kind !== "text" && sel.kind !== "prompt") return null;
|
|
3447
|
-
const withPresets = sel;
|
|
3448
|
-
return withPresets.presets.length === 0 ? null : withPresets;
|
|
3449
|
-
}
|
|
3450
|
-
/** the preset rows the filter kept — the label AND the text are searched, since what you
|
|
3451
|
-
* remember of a preset is often a phrase inside it */
|
|
3452
|
-
get presetOptions() {
|
|
3453
|
-
const pv = this.presetVar;
|
|
3454
|
-
if (pv == null) return [];
|
|
3455
|
-
if (this.filter === "") return pv.presets;
|
|
3456
|
-
return pv.presets.filter((x) => fuzzyMatch(this.filter, `${x.label} ${x.text}`));
|
|
3457
|
-
}
|
|
3458
|
-
get options() {
|
|
3459
|
-
if (this.presetVar != null) return this.presetOptions.map((x) => x.label);
|
|
3460
|
-
const cv = this.choiceVar;
|
|
3461
|
-
if (cv != null) {
|
|
3462
|
-
if (this.filter === "") return [...cv.choices];
|
|
3463
|
-
return cv.choices.filter((c) => fuzzyMatch(this.filter, c));
|
|
3464
|
-
}
|
|
3465
|
-
const sv = this.sizeVar;
|
|
3466
|
-
if (sv != null) {
|
|
3467
|
-
const labels = sv.presets.map((p) => `${p.width}×${p.height} ${p.label}`);
|
|
3468
|
-
if (this.imageSizeRow != null) labels.unshift(this.imageSizeRow);
|
|
3469
|
-
if (this.filter === "") return labels;
|
|
3470
|
-
return labels.filter((l) => fuzzyMatch(this.filter, l));
|
|
3471
|
-
}
|
|
3472
|
-
return [];
|
|
3473
|
-
}
|
|
3474
|
-
beginChoice() {
|
|
3475
|
-
const cv = this.choiceVar;
|
|
3476
|
-
if (cv == null) return;
|
|
3477
|
-
this.st.mode = "overlay-choice";
|
|
3478
|
-
this.filter = "";
|
|
3479
|
-
this.invalid = false;
|
|
3480
|
-
const first = cv.select === "many" ? cv.value[0] : cv.value;
|
|
3481
|
-
this.ix = Math.max(0, first == null ? 0 : cv.choices.indexOf(first));
|
|
3482
|
-
}
|
|
3483
|
-
/** `P` on a text/prompt var that declares presets. A var without any stays on `nav`:
|
|
3484
|
-
* the keybar only advertises the key when the row has some */
|
|
3485
|
-
beginPresets() {
|
|
3486
|
-
const pv = this.presetVar;
|
|
3487
|
-
if (pv == null) return;
|
|
3488
|
-
this.st.mode = "overlay-preset";
|
|
3489
|
-
this.filter = "";
|
|
3490
|
-
this.invalid = false;
|
|
3491
|
-
const value = pv.toEditBuffer().trim();
|
|
3492
|
-
const ix = pv.presets.findIndex((x) => x.text.trim() === value);
|
|
3493
|
-
this.ix = ix === -1 ? 0 : ix;
|
|
3494
|
-
}
|
|
3495
|
-
beginSize() {
|
|
3496
|
-
const sv = this.sizeVar;
|
|
3497
|
-
if (sv == null) return;
|
|
3498
|
-
this.st.mode = "overlay-size";
|
|
3499
|
-
this.filter = "";
|
|
3500
|
-
this.invalid = false;
|
|
3501
|
-
const img = sv.imageSize();
|
|
3502
|
-
this.imageSizeRow = img == null ? null : `${img.width}×${img.height} size of image '${img.name}'`;
|
|
3503
|
-
const presetIx = sv.presets.findIndex((p) => p.width === sv.value.width && p.height === sv.value.height);
|
|
3504
|
-
this.ix = presetIx === -1 ? 0 : presetIx + (this.imageSizeRow != null ? 1 : 0);
|
|
3505
|
-
}
|
|
3506
|
-
move(delta) {
|
|
3507
|
-
const len = this.options.length;
|
|
3508
|
-
if (len === 0) return;
|
|
3509
|
-
this.ix = (this.ix + delta + len) % len;
|
|
3510
|
-
}
|
|
3511
|
-
filterInput(chunk) {
|
|
3512
|
-
this.filter += chunk;
|
|
3513
|
-
this.ix = 0;
|
|
3514
|
-
this.invalid = false;
|
|
3515
|
-
}
|
|
3516
|
-
filterBackspace() {
|
|
3517
|
-
this.filter = this.filter.slice(0, -1);
|
|
3518
|
-
this.ix = 0;
|
|
3519
|
-
this.invalid = false;
|
|
3520
|
-
}
|
|
3521
|
-
/** ⌥⌫ / ⌃W: drop the last word of the filter */
|
|
3522
|
-
filterDeleteWord() {
|
|
3523
|
-
this.filter = this.filter.replace(/\s*\S+\s*$/, "");
|
|
3524
|
-
this.ix = 0;
|
|
3525
|
-
this.invalid = false;
|
|
3526
|
-
}
|
|
3527
|
-
commit() {
|
|
3528
|
-
const pv = this.presetVar;
|
|
3529
|
-
if (pv != null) {
|
|
3530
|
-
const hit = this.presetOptions[this.ix];
|
|
3531
|
-
if (hit == null) return;
|
|
3532
|
-
pv.set(hit.text);
|
|
3533
|
-
this.st.mode = "nav";
|
|
3534
|
-
return;
|
|
3535
|
-
}
|
|
3536
|
-
const cv = this.choiceVar;
|
|
3537
|
-
if (cv != null) {
|
|
3538
|
-
const hit = cv.choices.find((c) => c === this.options[this.ix]);
|
|
3539
|
-
if (hit == null) return;
|
|
3540
|
-
if (cv.select === "many") {
|
|
3541
|
-
cv.toggle(hit);
|
|
3542
|
-
return;
|
|
3543
|
-
}
|
|
3544
|
-
if (cv.select === "zero-or-one") cv.toggle(hit);
|
|
3545
|
-
else cv.set(hit);
|
|
3546
|
-
this.st.mode = "nav";
|
|
3547
|
-
return;
|
|
3548
|
-
}
|
|
3549
|
-
const sv = this.sizeVar;
|
|
3550
|
-
if (sv == null) return;
|
|
3551
|
-
const hit = this.options[this.ix];
|
|
3552
|
-
if (hit != null) {
|
|
3553
|
-
const m = hit.match(/^(\d+)×(\d+)/);
|
|
3554
|
-
if (m != null) sv.set({
|
|
3555
|
-
width: Number(m[1]),
|
|
3556
|
-
height: Number(m[2])
|
|
3557
|
-
});
|
|
3558
|
-
this.st.mode = "nav";
|
|
3559
|
-
return;
|
|
3560
|
-
}
|
|
3561
|
-
if (sv.parse(this.filter)) this.st.mode = "nav";
|
|
3562
|
-
else this.invalid = true;
|
|
3563
|
-
}
|
|
3564
|
-
};
|
|
3565
|
-
//#endregion
|
|
3566
|
-
//#region src/cli/tui/state/PreviewSt.ts
|
|
3567
|
-
/** small-latent corner: fraction of the panel each dimension takes */
|
|
3568
|
-
const CORNER_FRACTION = .38;
|
|
3569
|
-
/** pixel 'latent small': the sharp-composited thumb takes this fraction of the panel */
|
|
3570
|
-
const PIXEL_SMALL_FRACTION = .4;
|
|
3571
|
-
/**
|
|
3572
|
-
* right-side preview panel + its `p` settings menu (mode 'preview').
|
|
3573
|
-
* Three independent axes live in SettingsSt: panel on/off, renderer
|
|
3574
|
-
* native/pixel, and what to show while running (latent / latent small /
|
|
3575
|
-
* last output). Sources: live latent while running, last output after,
|
|
3576
|
-
* selected lora while the loras overlay is open.
|
|
3577
|
-
*/
|
|
3578
|
-
var PreviewSt = class {
|
|
3579
|
-
constructor(st) {
|
|
3580
|
-
this.st = st;
|
|
3581
|
-
this.outputAnsi = null;
|
|
3582
|
-
this.latentAnsi = null;
|
|
3583
|
-
this.outputBytes = null;
|
|
3584
|
-
this.latentBytes = null;
|
|
3585
|
-
this.latentDims = null;
|
|
3586
|
-
this.latentSeenThisRun = false;
|
|
3587
|
-
this.lastOutput = null;
|
|
3588
|
-
this.overlay = null;
|
|
3589
|
-
this.menuIx = 0;
|
|
3590
|
-
this._busy = false;
|
|
3591
|
-
makeAutoObservable(this, { st: false });
|
|
3592
|
-
}
|
|
3593
|
-
get show() {
|
|
3594
|
-
return this.st.settings.previewPanel;
|
|
3595
|
-
}
|
|
3596
|
-
get renderer() {
|
|
3597
|
-
return this.st.settings.previewRenderer;
|
|
3598
|
-
}
|
|
3599
|
-
get useNative() {
|
|
3600
|
-
return this.renderer === "native";
|
|
3601
|
-
}
|
|
3602
|
-
get duringRun() {
|
|
3603
|
-
return this.st.settings.previewDuringRun;
|
|
3604
|
-
}
|
|
3605
|
-
get menuOpen() {
|
|
3606
|
-
return this.st.mode === "preview";
|
|
3607
|
-
}
|
|
3608
|
-
get overlayActive() {
|
|
3609
|
-
return this.st.mode === "overlay-loras" || this.st.mode === "overlay-image";
|
|
3610
|
-
}
|
|
3611
|
-
/** owner = the overlay mode the render was FOR: every writer awaits (file
|
|
3612
|
-
* read, fetch, transcode) before landing here, and by then another overlay
|
|
3613
|
-
* can own the slot — a stale write would overwrite its image */
|
|
3614
|
-
setOverlayImage(p, owner) {
|
|
3615
|
-
if (this.st.mode !== owner) return;
|
|
3616
|
-
this.overlay = p;
|
|
3617
|
-
}
|
|
3618
|
-
clearOverlayImage() {
|
|
3619
|
-
this.overlay = null;
|
|
3620
|
-
}
|
|
3621
|
-
/** running + latents wanted + sampling well underway + none arrived = server
|
|
3622
|
-
* sends none. The ≥20% gate keeps healthy runs from red-flashing: the first
|
|
3623
|
-
* progress tick lands a beat before the first preview frame */
|
|
3624
|
-
get latentsMissing() {
|
|
3625
|
-
return this.st.exec.running && this.duringRun !== "last-output" && (this.st.exec.progress?.percent ?? 0) >= 20 && !this.latentSeenThisRun;
|
|
3626
|
-
}
|
|
3627
|
-
get menuRows() {
|
|
3628
|
-
return [
|
|
3629
|
-
{
|
|
3630
|
-
key: "panel",
|
|
3631
|
-
label: "panel",
|
|
3632
|
-
value: this.show ? "on" : "off"
|
|
3633
|
-
},
|
|
3634
|
-
{
|
|
3635
|
-
key: "renderer",
|
|
3636
|
-
label: "renderer",
|
|
3637
|
-
value: this.renderer + (protocolCapable() ? "" : " (this terminal cannot show real images)")
|
|
3638
|
-
},
|
|
3639
|
-
{
|
|
3640
|
-
key: "during-run",
|
|
3641
|
-
label: "while running",
|
|
3642
|
-
value: this.duringRun === "latent" ? "latent" : this.duringRun === "latent-small" ? "latent small" : "last output"
|
|
3643
|
-
}
|
|
3644
|
-
];
|
|
3645
|
-
}
|
|
3646
|
-
beginMenu() {
|
|
3647
|
-
this.st.mode = "preview";
|
|
3648
|
-
this.menuIx = 0;
|
|
3649
|
-
}
|
|
3650
|
-
blurMenu() {
|
|
3651
|
-
this.st.mode = "nav";
|
|
3652
|
-
}
|
|
3653
|
-
menuMove(delta) {
|
|
3654
|
-
const len = this.menuRows.length;
|
|
3655
|
-
this.menuIx = (this.menuIx + delta + len) % len;
|
|
3656
|
-
}
|
|
3657
|
-
/** cycle the selected row's value (settings persist via SettingsSt reaction) */
|
|
3658
|
-
menuCycle(delta) {
|
|
3659
|
-
const row = this.menuRows[this.menuIx];
|
|
3660
|
-
if (row == null) return;
|
|
3661
|
-
const s = this.st.settings;
|
|
3662
|
-
if (row.key === "panel") s.previewPanel = !s.previewPanel;
|
|
3663
|
-
else if (row.key === "renderer") {
|
|
3664
|
-
if (protocolCapable()) s.previewRenderer = s.previewRenderer === "native" ? "pixel" : "native";
|
|
3665
|
-
} else {
|
|
3666
|
-
const order = [
|
|
3667
|
-
"latent",
|
|
3668
|
-
"latent-small",
|
|
3669
|
-
"last-output"
|
|
3670
|
-
];
|
|
3671
|
-
s.previewDuringRun = order[(order.indexOf(s.previewDuringRun) + delta + order.length) % order.length] ?? "latent";
|
|
3672
|
-
}
|
|
3673
|
-
this.onSettingsChanged();
|
|
3674
|
-
}
|
|
3675
|
-
reset() {
|
|
3676
|
-
this.outputAnsi = null;
|
|
3677
|
-
this.latentAnsi = null;
|
|
3678
|
-
this.outputBytes = null;
|
|
3679
|
-
this.latentBytes = null;
|
|
3680
|
-
this.latentDims = null;
|
|
3681
|
-
this.latentSeenThisRun = false;
|
|
3682
|
-
this.lastOutput = null;
|
|
3683
|
-
}
|
|
3684
|
-
/** run boundary: drop the latents so the next run never shows the previous one's */
|
|
3685
|
-
clearLatent() {
|
|
3686
|
-
this.latentAnsi = null;
|
|
3687
|
-
this.latentBytes = null;
|
|
3688
|
-
this.latentDims = null;
|
|
3689
|
-
this.latentSeenThisRun = false;
|
|
3690
|
-
}
|
|
3691
|
-
/** re-render the last output for the newly chosen settings */
|
|
3692
|
-
onSettingsChanged() {
|
|
3693
|
-
this.outputAnsi = null;
|
|
3694
|
-
this.outputBytes = null;
|
|
3695
|
-
if (this.show && this.lastOutput != null) this.renderOutput(this.lastOutput);
|
|
3696
|
-
}
|
|
3697
|
-
/** what the painter should show RIGHT NOW (native renderer only; mirrors the panel's source) */
|
|
3698
|
-
get protocolImage() {
|
|
3699
|
-
if (!this.useNative || !this.show || this.menuOpen) return null;
|
|
3700
|
-
if (this.overlayActive) return this.overlay?.bytes ?? null;
|
|
3701
|
-
if (this.st.exec.running) {
|
|
3702
|
-
if (this.duringRun === "latent") return this.latentBytes ?? this.outputBytes;
|
|
3703
|
-
return this.outputBytes;
|
|
3704
|
-
}
|
|
3705
|
-
return this.outputBytes;
|
|
3706
|
-
}
|
|
3707
|
-
/** small latent painted over the panel's top-right corner (native + 'latent small' only) */
|
|
3708
|
-
get protocolImageCorner() {
|
|
3709
|
-
if (!this.useNative || !this.show || this.menuOpen) return null;
|
|
3710
|
-
if (this.overlayActive) return null;
|
|
3711
|
-
if (this.st.exec.running && this.duringRun === "latent-small") return this.latentBytes;
|
|
3712
|
-
return null;
|
|
3713
|
-
}
|
|
3714
|
-
/** corner cell box matched to the latent's REAL aspect (a mismatched box
|
|
3715
|
-
* letterboxes in iTerm, showing a tall rectangle). Cells are
|
|
3716
|
-
* ~1:2 (w:h), hence the ×2 when converting image aspect to cells. */
|
|
3717
|
-
get cornerBox() {
|
|
3718
|
-
let w = Math.max(8, Math.floor(this.width * CORNER_FRACTION));
|
|
3719
|
-
const maxH = Math.max(4, Math.floor(this.height * CORNER_FRACTION));
|
|
3720
|
-
const dims = this.latentDims;
|
|
3721
|
-
if (dims == null || dims.width === 0 || dims.height === 0) return {
|
|
3722
|
-
w,
|
|
3723
|
-
h: maxH
|
|
3724
|
-
};
|
|
3725
|
-
const aspect = dims.width / dims.height;
|
|
3726
|
-
let h = Math.max(2, Math.round(w / aspect / 2));
|
|
3727
|
-
if (h > maxH) {
|
|
3728
|
-
h = maxH;
|
|
3729
|
-
w = Math.max(4, Math.round(h * aspect * 2));
|
|
3730
|
-
}
|
|
3731
|
-
return {
|
|
3732
|
-
w,
|
|
3733
|
-
h
|
|
3734
|
-
};
|
|
3735
|
-
}
|
|
3736
|
-
get width() {
|
|
3737
|
-
return Math.max(24, Math.min(80, this.st.termCols - 68 - this.st.treeWidth));
|
|
3738
|
-
}
|
|
3739
|
-
get height() {
|
|
3740
|
-
return Math.max(10, this.st.termRows - 12);
|
|
3741
|
-
}
|
|
3742
|
-
async renderOutput(src) {
|
|
3743
|
-
this.lastOutput = src;
|
|
3744
|
-
if (!this.show) return;
|
|
3745
|
-
try {
|
|
3746
|
-
if (this.useNative) {
|
|
3747
|
-
const shrunk = await sharp(src).resize(896, 896, {
|
|
3748
|
-
fit: "inside",
|
|
3749
|
-
withoutEnlargement: true
|
|
3750
|
-
}).png().toBuffer();
|
|
3751
|
-
runInAction(() => {
|
|
3752
|
-
this.outputBytes = new Uint8Array(shrunk);
|
|
3753
|
-
});
|
|
3754
|
-
return;
|
|
3755
|
-
}
|
|
3756
|
-
const rendered = await imageBufferToAnsi(src, {
|
|
3757
|
-
width: this.width,
|
|
3758
|
-
height: this.height
|
|
3759
|
-
});
|
|
3760
|
-
runInAction(() => {
|
|
3761
|
-
this.outputAnsi = rendered;
|
|
3762
|
-
});
|
|
3763
|
-
} catch (e) {
|
|
3764
|
-
runInAction(() => {
|
|
3765
|
-
this.st.exec.notice = `preview: ${extractErrorMessage(e)}`;
|
|
3766
|
-
});
|
|
3767
|
-
}
|
|
3768
|
-
}
|
|
3769
|
-
async renderLatent(bytes) {
|
|
3770
|
-
runInAction(() => {
|
|
3771
|
-
this.latentSeenThisRun = true;
|
|
3772
|
-
});
|
|
3773
|
-
if (!this.show || this.duringRun === "last-output") return;
|
|
3774
|
-
if (this.useNative) {
|
|
3775
|
-
const meta = imageMeta(bytes);
|
|
3776
|
-
const dims = meta.width != null && meta.height != null ? {
|
|
3777
|
-
width: meta.width,
|
|
3778
|
-
height: meta.height
|
|
3779
|
-
} : null;
|
|
3780
|
-
if (imageProtocol() !== "kitty") {
|
|
3781
|
-
this.latentBytes = bytes;
|
|
3782
|
-
this.latentDims = dims;
|
|
3783
|
-
return;
|
|
3784
|
-
}
|
|
3785
|
-
if (this._busy) return;
|
|
3786
|
-
this._busy = true;
|
|
3787
|
-
try {
|
|
3788
|
-
const png = await protocolReadyBytes(bytes);
|
|
3789
|
-
runInAction(() => {
|
|
3790
|
-
this.latentBytes = png;
|
|
3791
|
-
this.latentDims = dims;
|
|
3792
|
-
});
|
|
3793
|
-
} catch (e) {
|
|
3794
|
-
runInAction(() => {
|
|
3795
|
-
this.st.exec.notice = `latent preview: ${extractErrorMessage(e)}`;
|
|
3796
|
-
});
|
|
3797
|
-
} finally {
|
|
3798
|
-
this._busy = false;
|
|
3799
|
-
}
|
|
3800
|
-
return;
|
|
3801
|
-
}
|
|
3802
|
-
if (this._busy) return;
|
|
3803
|
-
this._busy = true;
|
|
3804
|
-
try {
|
|
3805
|
-
const ansi = this.duringRun === "latent-small" ? await this.renderLatentSmallPixel(bytes) : await imageBufferToAnsi(bytes, {
|
|
3806
|
-
width: this.width,
|
|
3807
|
-
height: this.height
|
|
3808
|
-
});
|
|
3809
|
-
runInAction(() => {
|
|
3810
|
-
this.latentAnsi = ansi;
|
|
3811
|
-
});
|
|
3812
|
-
} catch (e) {
|
|
3813
|
-
runInAction(() => {
|
|
3814
|
-
this.st.exec.notice = `latent preview: ${extractErrorMessage(e)}`;
|
|
3815
|
-
});
|
|
3816
|
-
} finally {
|
|
3817
|
-
this._busy = false;
|
|
3818
|
-
}
|
|
3819
|
-
}
|
|
3820
|
-
/** pixel 'latent small': sharp-composite the latent thumb onto the last
|
|
3821
|
-
* output (top-right), then ONE half-block render — a string-level overlay
|
|
3822
|
-
* was tried and dropped: its space padding reads as black bars */
|
|
3823
|
-
async renderLatentSmallPixel(bytes) {
|
|
3824
|
-
const pxW = this.width;
|
|
3825
|
-
const pxH = this.height * 2;
|
|
3826
|
-
const thumb = await sharp(bytes).resize(Math.max(8, Math.floor(pxW * PIXEL_SMALL_FRACTION)), Math.max(8, Math.floor(pxH * PIXEL_SMALL_FRACTION)), { fit: "inside" }).png().toBuffer();
|
|
3827
|
-
const out = this.lastOutput;
|
|
3828
|
-
if (out == null) return imageBufferToAnsi(thumb, {
|
|
3829
|
-
width: this.width,
|
|
3830
|
-
height: this.height
|
|
3831
|
-
});
|
|
3832
|
-
return imageBufferToAnsi(await sharp(await sharp(out).resize(pxW, pxH, { fit: "inside" }).png().toBuffer()).composite([{
|
|
3833
|
-
input: thumb,
|
|
3834
|
-
gravity: "northeast"
|
|
3835
|
-
}]).png().toBuffer(), {
|
|
3836
|
-
width: this.width,
|
|
3837
|
-
height: this.height
|
|
3838
|
-
});
|
|
3839
|
-
}
|
|
3840
|
-
};
|
|
3841
|
-
//#endregion
|
|
3842
|
-
//#region src/cli/tui/state/QueueSt.ts
|
|
3843
|
-
/** live server queue length (ws 'status' messages) + queue actions */
|
|
3844
|
-
var QueueSt = class {
|
|
3845
|
-
constructor(st) {
|
|
3846
|
-
this.st = st;
|
|
3847
|
-
this.remaining = 0;
|
|
3848
|
-
this.attached = null;
|
|
3849
|
-
makeAutoObservable(this, { st: false });
|
|
3850
|
-
this.attach(this.st.wf.host);
|
|
3851
|
-
this.st.disposers.push(() => {
|
|
3852
|
-
if (this.attached != null) this.attached.onStatus = null;
|
|
3853
|
-
});
|
|
3854
|
-
}
|
|
3855
|
-
/** follow the CURRENT workflow's host (re-called on workflow switch) */
|
|
3856
|
-
attach(host) {
|
|
3857
|
-
if (this.attached === host) return;
|
|
3858
|
-
if (this.attached != null) this.attached.onStatus = null;
|
|
3859
|
-
this.attached = host;
|
|
3860
|
-
this.remaining = 0;
|
|
3861
|
-
host.onStatus = (p) => {
|
|
3862
|
-
runInAction(() => {
|
|
3863
|
-
this.remaining = p.queueRemaining;
|
|
3864
|
-
});
|
|
3865
|
-
};
|
|
3866
|
-
}
|
|
3867
|
-
async clearPending() {
|
|
3868
|
-
try {
|
|
3869
|
-
await this.st.runHost.clearQueue();
|
|
3870
|
-
runInAction(() => {
|
|
3871
|
-
this.st.exec.notice = "pending queue cleared";
|
|
3872
|
-
});
|
|
3873
|
-
} catch (e) {
|
|
3874
|
-
runInAction(() => {
|
|
3875
|
-
this.st.exec.error = extractErrorMessage(e);
|
|
3876
|
-
});
|
|
3877
|
-
}
|
|
3878
|
-
}
|
|
3879
|
-
async interrupt() {
|
|
3880
|
-
try {
|
|
3881
|
-
await this.st.runHost.interrupt();
|
|
3882
|
-
runInAction(() => {
|
|
3883
|
-
this.st.exec.notice = "interrupt requested";
|
|
3884
|
-
});
|
|
3885
|
-
} catch (e) {
|
|
3886
|
-
runInAction(() => {
|
|
3887
|
-
this.st.exec.error = extractErrorMessage(e);
|
|
3888
|
-
});
|
|
3889
|
-
}
|
|
3890
|
-
}
|
|
3891
|
-
};
|
|
3892
|
-
//#endregion
|
|
3893
|
-
//#region src/cli/tui/state/SettingsSt.ts
|
|
3894
|
-
/** read stored preview settings, migrating the legacy single `previewMode`
|
|
3895
|
-
* (native|ansi|off) into the three independent axes */
|
|
3896
|
-
function migratePreviewSettings(raw, defaults) {
|
|
3897
|
-
const out = { ...defaults };
|
|
3898
|
-
const legacy = raw.previewMode;
|
|
3899
|
-
if (legacy === "native") out.previewRenderer = "native";
|
|
3900
|
-
if (legacy === "ansi") out.previewRenderer = "pixel";
|
|
3901
|
-
if (legacy === "off") out.previewPanel = false;
|
|
3902
|
-
if (typeof raw.previewPanel === "boolean") out.previewPanel = raw.previewPanel;
|
|
3903
|
-
if (raw.previewRenderer === "native" || raw.previewRenderer === "pixel") out.previewRenderer = raw.previewRenderer;
|
|
3904
|
-
if (raw.previewDuringRun === "latent" || raw.previewDuringRun === "latent-small" || raw.previewDuringRun === "last-output") out.previewDuringRun = raw.previewDuringRun;
|
|
3905
|
-
return out;
|
|
3906
|
-
}
|
|
3907
|
-
/** persisted TUI settings at `.comfy-ts/settings.json` (LOCAL state, gitignored) */
|
|
3908
|
-
var SettingsSt = class {
|
|
3909
|
-
constructor(st) {
|
|
3910
|
-
this.st = st;
|
|
3911
|
-
this.previewPanel = true;
|
|
3912
|
-
this.previewRenderer = protocolCapable() ? "native" : "pixel";
|
|
3913
|
-
this.previewDuringRun = "latent";
|
|
3914
|
-
this.lastDraft = {};
|
|
3915
|
-
this.lastWorkflow = null;
|
|
3916
|
-
this.hostOverrideId = null;
|
|
3917
|
-
this.collapsedDirs = [];
|
|
3918
|
-
this.saveToDisk = true;
|
|
3919
|
-
this.savePrefix = {};
|
|
3920
|
-
this.load();
|
|
3921
|
-
if (this.previewRenderer === "native" && !protocolCapable()) this.previewRenderer = "pixel";
|
|
3922
|
-
makeAutoObservable(this, { st: false });
|
|
3923
|
-
this.st.disposers.push(reaction(() => this.snapshotJson(), (json) => this.write(json), { delay: this.st.timing.autosaveMs }));
|
|
3924
|
-
this.st.disposers.push(() => this.write(this.snapshotJson()));
|
|
3925
|
-
}
|
|
3926
|
-
snapshotJson() {
|
|
3927
|
-
return JSON.stringify({
|
|
3928
|
-
previewPanel: this.previewPanel,
|
|
3929
|
-
previewRenderer: this.previewRenderer,
|
|
3930
|
-
previewDuringRun: this.previewDuringRun,
|
|
3931
|
-
lastDraft: this.lastDraft,
|
|
3932
|
-
lastWorkflow: this.lastWorkflow,
|
|
3933
|
-
hostOverrideId: this.hostOverrideId,
|
|
3934
|
-
collapsedDirs: this.collapsedDirs,
|
|
3935
|
-
saveToDisk: this.saveToDisk,
|
|
3936
|
-
savePrefix: this.savePrefix
|
|
3937
|
-
});
|
|
3938
|
-
}
|
|
3939
|
-
rememberDraft(moduleKey, draft) {
|
|
3940
|
-
this.lastDraft[moduleKey] = draft;
|
|
3941
|
-
}
|
|
3942
|
-
load() {
|
|
3943
|
-
const path = comfyts.settingsPath;
|
|
3944
|
-
if (!existsSync(path)) return;
|
|
3945
|
-
try {
|
|
3946
|
-
const raw = JSON.parse(readFileSync(path, "utf8"));
|
|
3947
|
-
if (raw == null || typeof raw !== "object") return;
|
|
3948
|
-
const o = raw;
|
|
3949
|
-
const preview = migratePreviewSettings(o, {
|
|
3950
|
-
previewPanel: this.previewPanel,
|
|
3951
|
-
previewRenderer: this.previewRenderer,
|
|
3952
|
-
previewDuringRun: this.previewDuringRun
|
|
3953
|
-
});
|
|
3954
|
-
this.previewPanel = preview.previewPanel;
|
|
3955
|
-
this.previewRenderer = preview.previewRenderer;
|
|
3956
|
-
this.previewDuringRun = preview.previewDuringRun;
|
|
3957
|
-
if (o.lastDraft != null && typeof o.lastDraft === "object") this.lastDraft = { ...o.lastDraft };
|
|
3958
|
-
if (typeof o.lastWorkflow === "string") this.lastWorkflow = o.lastWorkflow;
|
|
3959
|
-
if (typeof o.hostOverrideId === "string") this.hostOverrideId = o.hostOverrideId;
|
|
3960
|
-
if (Array.isArray(o.collapsedDirs)) this.collapsedDirs = o.collapsedDirs.filter((d) => typeof d === "string");
|
|
3961
|
-
if (typeof o.saveToDisk === "boolean") this.saveToDisk = o.saveToDisk;
|
|
3962
|
-
if (o.savePrefix != null && typeof o.savePrefix === "object") this.savePrefix = Object.fromEntries(Object.entries(o.savePrefix).filter((kv) => typeof kv[1] === "string"));
|
|
3963
|
-
} catch {}
|
|
3964
|
-
}
|
|
3965
|
-
write(json) {
|
|
3966
|
-
const path = comfyts.settingsPath;
|
|
3967
|
-
try {
|
|
3968
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
3969
|
-
writeFileSync(path, json);
|
|
3970
|
-
} catch (e) {
|
|
3971
|
-
runInAction(() => {
|
|
3972
|
-
this.st.exec.notice = `settings save failed: ${String(e)}`;
|
|
3973
|
-
});
|
|
3974
|
-
}
|
|
3975
|
-
}
|
|
3976
|
-
};
|
|
3977
|
-
//#endregion
|
|
3978
|
-
//#region src/cli/tui/state/TreeSt.ts
|
|
3979
|
-
/** the left `(t)ree`: directory hierarchy + workflows with their drafts nested */
|
|
3980
|
-
var TreeSt = class {
|
|
3981
|
-
constructor(st) {
|
|
3982
|
-
this.st = st;
|
|
3983
|
-
this.ix = 0;
|
|
3984
|
-
this.expandedFiles = /* @__PURE__ */ new Set();
|
|
3985
|
-
this.filter = "";
|
|
3986
|
-
this.filtering = false;
|
|
3987
|
-
this.viewH = 0;
|
|
3988
|
-
this.collapsedDirs = new Set(st.settings.collapsedDirs);
|
|
3989
|
-
makeAutoObservable(this, { st: false });
|
|
3990
|
-
}
|
|
3991
|
-
/** fold state is hand-tuned: mirror every change into the settings file */
|
|
3992
|
-
persistFolds() {
|
|
3993
|
-
this.st.settings.collapsedDirs = [...this.collapsedDirs];
|
|
3994
|
-
}
|
|
3995
|
-
/** family → color over the FULL file list (stable under filter/fold) */
|
|
3996
|
-
get familyColors() {
|
|
3997
|
-
return assignFamilyColors(this.st.workflows.files);
|
|
3998
|
-
}
|
|
3999
|
-
get rows() {
|
|
4000
|
-
this.st.drafts.version;
|
|
4001
|
-
const w = this.st.workflows;
|
|
4002
|
-
const fileRows = buildFileRows({
|
|
4003
|
-
userFiles: w.files.filter((f) => !w.bundled.has(f)),
|
|
4004
|
-
bundledFiles: w.files.filter((f) => w.bundled.has(f)),
|
|
4005
|
-
collapsedDirs: this.collapsedDirs,
|
|
4006
|
-
filter: this.filter
|
|
4007
|
-
});
|
|
4008
|
-
const colors = this.familyColors;
|
|
4009
|
-
const rows = [];
|
|
4010
|
-
for (const row of fileRows) {
|
|
4011
|
-
if (row.kind === "dir") {
|
|
4012
|
-
rows.push(row);
|
|
4013
|
-
continue;
|
|
4014
|
-
}
|
|
4015
|
-
const current = row.file === w.currentPath;
|
|
4016
|
-
const expanded = this.expandedFiles.has(row.file);
|
|
4017
|
-
const drafts = listDraftsForFile(row.file);
|
|
4018
|
-
rows.push({
|
|
4019
|
-
kind: "workflow",
|
|
4020
|
-
file: row.file,
|
|
4021
|
-
name: row.name,
|
|
4022
|
-
depth: row.depth,
|
|
4023
|
-
expanded,
|
|
4024
|
-
current,
|
|
4025
|
-
hasDrafts: drafts.length > 0,
|
|
4026
|
-
error: w.loadErrors.get(row.file) ?? null,
|
|
4027
|
-
color: w.specColors.get(row.file) ?? colors.get(familyOf(row.name)) ?? "white"
|
|
4028
|
-
});
|
|
4029
|
-
if (!expanded) continue;
|
|
4030
|
-
for (const draft of drafts) rows.push({
|
|
4031
|
-
kind: "draft",
|
|
4032
|
-
file: row.file,
|
|
4033
|
-
draft,
|
|
4034
|
-
active: current && draft === this.st.drafts.active,
|
|
4035
|
-
depth: row.depth + 1
|
|
4036
|
-
});
|
|
4037
|
-
}
|
|
4038
|
-
return rows;
|
|
4039
|
-
}
|
|
4040
|
-
get selected() {
|
|
4041
|
-
return this.rows[this.ix];
|
|
4042
|
-
}
|
|
4043
|
-
/** 't' / ←: focus the tree ON THE ACTIVE DRAFT (where you actually are), workflow row as fallback */
|
|
4044
|
-
focus() {
|
|
4045
|
-
const w = this.st.workflows;
|
|
4046
|
-
if (w.files.length === 0) {
|
|
4047
|
-
this.st.exec.notice = "no workflow tree — start the tui in a folder containing **/*.cflow.ts";
|
|
4048
|
-
return;
|
|
4049
|
-
}
|
|
4050
|
-
if (w.currentPath != null) {
|
|
4051
|
-
this.expandedFiles.add(w.currentPath);
|
|
4052
|
-
let changed = false;
|
|
4053
|
-
const collapsed = [...this.collapsedDirs];
|
|
4054
|
-
for (const dir of collapsed) if (w.currentPath.startsWith(`${dir}/`)) {
|
|
4055
|
-
this.collapsedDirs.delete(dir);
|
|
4056
|
-
changed = true;
|
|
4057
|
-
}
|
|
4058
|
-
if (changed) this.persistFolds();
|
|
4059
|
-
}
|
|
4060
|
-
this.st.mode = "tree";
|
|
4061
|
-
const rows = this.rows;
|
|
4062
|
-
const draftIx = rows.findIndex((r) => r.kind === "draft" && r.active);
|
|
4063
|
-
const ix = draftIx === -1 ? rows.findIndex((r) => r.kind === "workflow" && r.current) : draftIx;
|
|
4064
|
-
this.ix = ix === -1 ? 0 : ix;
|
|
4065
|
-
}
|
|
4066
|
-
setViewH(h) {
|
|
4067
|
-
this.viewH = h;
|
|
4068
|
-
}
|
|
4069
|
-
/** rows available for tree content: measured panel height minus the panel's
|
|
4070
|
-
* own chrome (2 border rows, the filter line when visible, the loading
|
|
4071
|
-
* line). Pre-measure fallback: termRows minus the header+keybar estimate —
|
|
4072
|
-
* one frame only, the measurement replaces it. */
|
|
4073
|
-
get viewBudget() {
|
|
4074
|
-
const h = this.viewH > 0 ? this.viewH : Math.max(5, this.st.termRows - 5);
|
|
4075
|
-
const filterLine = this.filtering || this.filter !== "" ? 1 : 0;
|
|
4076
|
-
const loadingLine = this.st.workflows.loading ? 1 : 0;
|
|
4077
|
-
return Math.max(1, h - 2 - filterLine - loadingLine);
|
|
4078
|
-
}
|
|
4079
|
-
/** the visible slice, selection always inside, markers within the budget */
|
|
4080
|
-
get window() {
|
|
4081
|
-
return listWindow({
|
|
4082
|
-
count: this.rows.length,
|
|
4083
|
-
selected: this.ix,
|
|
4084
|
-
budget: this.viewBudget
|
|
4085
|
-
});
|
|
4086
|
-
}
|
|
4087
|
-
/** esc/t inside the tree, → on a draft row, `v` anywhere: back to the vars list */
|
|
4088
|
-
blur() {
|
|
4089
|
-
this.filtering = false;
|
|
4090
|
-
this.st.mode = "nav";
|
|
4091
|
-
}
|
|
4092
|
-
move(delta) {
|
|
4093
|
-
const len = this.rows.length;
|
|
4094
|
-
if (len === 0) return;
|
|
4095
|
-
this.ix = (this.ix + delta + len) % len;
|
|
4096
|
-
}
|
|
4097
|
-
beginFilter() {
|
|
4098
|
-
this.filtering = true;
|
|
4099
|
-
}
|
|
4100
|
-
filterInput(ch) {
|
|
4101
|
-
this.filter += ch;
|
|
4102
|
-
this.clampToSelectable();
|
|
4103
|
-
}
|
|
4104
|
-
filterBackspace() {
|
|
4105
|
-
this.filter = this.filter.slice(0, -1);
|
|
4106
|
-
this.clampToSelectable();
|
|
4107
|
-
}
|
|
4108
|
-
/** esc while the filter owns the keys: drop it, stay in the tree */
|
|
4109
|
-
clearFilter() {
|
|
4110
|
-
this.filter = "";
|
|
4111
|
-
this.filtering = false;
|
|
4112
|
-
this.clampToSelectable();
|
|
4113
|
-
}
|
|
4114
|
-
/** filter edits reshape rows: keep the cursor on a workflow row when one exists */
|
|
4115
|
-
clampToSelectable() {
|
|
4116
|
-
const rows = this.rows;
|
|
4117
|
-
this.ix = Math.min(this.ix, Math.max(0, rows.length - 1));
|
|
4118
|
-
if (rows[this.ix]?.kind !== "workflow") {
|
|
4119
|
-
const first = rows.findIndex((r) => r.kind === "workflow");
|
|
4120
|
-
if (first !== -1) this.ix = first;
|
|
4121
|
-
}
|
|
4122
|
-
}
|
|
4123
|
-
/** →: unfold the dir/workflow under the cursor; on a draft row there is
|
|
4124
|
-
* nothing left to unfold, so → continues rightwards into the vars panel */
|
|
4125
|
-
unfold() {
|
|
4126
|
-
const row = this.selected;
|
|
4127
|
-
if (row == null) return;
|
|
4128
|
-
if (row.kind === "dir") {
|
|
4129
|
-
this.collapsedDirs.delete(row.path);
|
|
4130
|
-
this.persistFolds();
|
|
4131
|
-
} else if (row.kind === "workflow") this.expandedFiles.add(row.file);
|
|
4132
|
-
else this.blur();
|
|
4133
|
-
}
|
|
4134
|
-
/** ←: fold under the cursor; on an already-folded row, jump to the parent */
|
|
4135
|
-
fold() {
|
|
4136
|
-
const row = this.selected;
|
|
4137
|
-
if (row == null) return;
|
|
4138
|
-
if (row.kind === "dir") {
|
|
4139
|
-
this.collapsedDirs.add(row.path);
|
|
4140
|
-
this.persistFolds();
|
|
4141
|
-
return;
|
|
4142
|
-
}
|
|
4143
|
-
if (row.kind === "draft") {
|
|
4144
|
-
const ix = this.rows.findIndex((r) => r.kind === "workflow" && r.file === row.file);
|
|
4145
|
-
if (ix !== -1) this.ix = ix;
|
|
4146
|
-
this.expandedFiles.delete(row.file);
|
|
4147
|
-
return;
|
|
4148
|
-
}
|
|
4149
|
-
if (row.expanded) {
|
|
4150
|
-
this.expandedFiles.delete(row.file);
|
|
4151
|
-
return;
|
|
4152
|
-
}
|
|
4153
|
-
for (let ix = this.ix - 1; ix >= 0; ix--) {
|
|
4154
|
-
const r = this.rows[ix];
|
|
4155
|
-
if (r?.kind === "dir" && r.depth < row.depth) {
|
|
4156
|
-
this.ix = ix;
|
|
4157
|
-
return;
|
|
4158
|
-
}
|
|
4159
|
-
}
|
|
4160
|
-
}
|
|
4161
|
-
/** ⏎: toggle a dir, load the workflow (into 'default'), or load the exact draft */
|
|
4162
|
-
async commit() {
|
|
4163
|
-
const row = this.selected;
|
|
4164
|
-
if (row == null) return;
|
|
4165
|
-
if (row.kind === "dir") {
|
|
4166
|
-
if (this.filter !== "") return;
|
|
4167
|
-
if (row.expanded) this.collapsedDirs.add(row.path);
|
|
4168
|
-
else this.collapsedDirs.delete(row.path);
|
|
4169
|
-
this.persistFolds();
|
|
4170
|
-
return;
|
|
4171
|
-
}
|
|
4172
|
-
this.filter = "";
|
|
4173
|
-
this.filtering = false;
|
|
4174
|
-
if (row.kind === "workflow") return this.st.workflows.commit(row.file);
|
|
4175
|
-
return this.st.workflows.commit(row.file, row.draft);
|
|
4176
|
-
}
|
|
4177
|
-
/** n: new draft — current workflow only (a draft snapshots its LIVE var values) */
|
|
4178
|
-
promptNewDraft() {
|
|
4179
|
-
const row = this.selected;
|
|
4180
|
-
if (row?.kind === "dir") return;
|
|
4181
|
-
if (row != null && row.file !== this.st.workflows.currentPath) {
|
|
4182
|
-
this.st.exec.notice = "load that workflow first (⏎) — a new draft snapshots its live vars";
|
|
4183
|
-
return;
|
|
4184
|
-
}
|
|
4185
|
-
this.st.drafts.promptNew("tree");
|
|
4186
|
-
}
|
|
4187
|
-
/** f2/c/x on a draft row: rename / duplicate / delete (file ops, work on ANY workflow's drafts) */
|
|
4188
|
-
draftOp(op) {
|
|
4189
|
-
const row = this.selected;
|
|
4190
|
-
if (row?.kind !== "draft") {
|
|
4191
|
-
this.st.exec.notice = "select a draft row (unfold a workflow with →)";
|
|
4192
|
-
return;
|
|
4193
|
-
}
|
|
4194
|
-
if (op === "rename") return this.st.drafts.promptRename(row.draft, row.file, "tree");
|
|
4195
|
-
if (op === "duplicate") return this.st.drafts.promptDuplicate(row.draft, row.file, "tree");
|
|
4196
|
-
this.st.drafts.deleteDraft(row.draft, row.file);
|
|
4197
|
-
this.ix = Math.min(this.ix, Math.max(0, this.rows.length - 1));
|
|
4198
|
-
}
|
|
4199
|
-
};
|
|
4200
|
-
//#endregion
|
|
4201
|
-
//#region src/cli/tui/state/WorkflowsSt.ts
|
|
4202
|
-
/** workflow-module data layer: scanned files, module loading, opened-host set (TreeSt is the UI over it) */
|
|
4203
|
-
var WorkflowsSt = class {
|
|
4204
|
-
constructor(st, files, currentPath = null, bundled = /* @__PURE__ */ new Set(), loadErrors = /* @__PURE__ */ new Map()) {
|
|
4205
|
-
this.st = st;
|
|
4206
|
-
this.files = files;
|
|
4207
|
-
this.loading = false;
|
|
4208
|
-
this.specColors = /* @__PURE__ */ new Map();
|
|
4209
|
-
this.loadedHosts = /* @__PURE__ */ new Set();
|
|
4210
|
-
this.currentPath = currentPath;
|
|
4211
|
-
this.bundled = bundled;
|
|
4212
|
-
this.loadErrors = loadErrors;
|
|
4213
|
-
makeAutoObservable(this, { st: false });
|
|
4214
|
-
}
|
|
4215
|
-
recordSpecColor(path, wf) {
|
|
4216
|
-
if (wf.spec.color != null) this.specColors.set(path, wf.spec.color);
|
|
4217
|
-
}
|
|
4218
|
-
disconnectAllHosts() {
|
|
4219
|
-
this.loadedHosts.add(this.st.wf.host);
|
|
4220
|
-
for (const host of this.loadedHosts) host.disconnect();
|
|
4221
|
-
}
|
|
4222
|
-
/** load a workflow module; `draft` null => the remembered draft, else that exact draft */
|
|
4223
|
-
async commit(path, draft = null) {
|
|
4224
|
-
if (path === this.currentPath) {
|
|
4225
|
-
if (this.loading) return;
|
|
4226
|
-
if (draft == null) this.st.drafts.activateRemembered();
|
|
4227
|
-
else this.st.drafts.activate(draft);
|
|
4228
|
-
this.st.mode = "nav";
|
|
4229
|
-
return;
|
|
4230
|
-
}
|
|
4231
|
-
return this.load(path, draft, false);
|
|
4232
|
-
}
|
|
4233
|
-
/** cache-busted re-import of the CURRENT module: defineWorkflow re-executes,
|
|
4234
|
-
* so dynamic var option lists (v.loras over getLoras()…) pick up fresh schema values */
|
|
4235
|
-
async reload(draft) {
|
|
4236
|
-
const path = this.currentPath;
|
|
4237
|
-
if (path == null) return;
|
|
4238
|
-
return this.load(path, draft, true);
|
|
4239
|
-
}
|
|
4240
|
-
async load(path, draft, bustCache) {
|
|
4241
|
-
if (this.loading) return;
|
|
4242
|
-
runInAction(() => {
|
|
4243
|
-
this.loading = true;
|
|
4244
|
-
});
|
|
4245
|
-
try {
|
|
4246
|
-
const wf = findDefinedWorkflow(await import(pathToFileURL(resolve(path)).href + (bustCache ? `?v=${Date.now()}` : "")));
|
|
4247
|
-
if (wf == null) throw new Error(`${path} exports no DefinedWorkflow`);
|
|
4248
|
-
runInAction(() => {
|
|
4249
|
-
this.loadErrors.delete(path);
|
|
4250
|
-
this.loadedHosts.add(this.st.wf.host);
|
|
4251
|
-
this.loadedHosts.add(wf.host);
|
|
4252
|
-
this.recordSpecColor(path, wf);
|
|
4253
|
-
this.st.wf = wf;
|
|
4254
|
-
this.st.applyPersistedHostOverride();
|
|
4255
|
-
this.st.queue.attach(this.st.runHost);
|
|
4256
|
-
this.st.logs.attach(this.st.runHost);
|
|
4257
|
-
this.currentPath = path;
|
|
4258
|
-
this.st.settings.lastWorkflow = path;
|
|
4259
|
-
this.st.selIx = 0;
|
|
4260
|
-
this.st.mode = "nav";
|
|
4261
|
-
this.st.exec.resetForWorkflow(`${basename(path)}`);
|
|
4262
|
-
if (draft == null) this.st.drafts.activateRemembered();
|
|
4263
|
-
else this.st.drafts.activate(draft);
|
|
4264
|
-
this.st.preview.reset();
|
|
4265
|
-
});
|
|
4266
|
-
} catch (e) {
|
|
4267
|
-
runInAction(() => {
|
|
4268
|
-
const msg = extractErrorMessage(e);
|
|
4269
|
-
this.loadErrors.set(path, msg);
|
|
4270
|
-
this.st.mode = "nav";
|
|
4271
|
-
this.st.exec.error = msg;
|
|
4272
|
-
});
|
|
4273
|
-
} finally {
|
|
4274
|
-
runInAction(() => {
|
|
4275
|
-
this.loading = false;
|
|
4276
|
-
});
|
|
4277
|
-
}
|
|
4278
|
-
}
|
|
4279
|
-
};
|
|
4280
|
-
//#endregion
|
|
4281
|
-
//#region src/cli/tui/state/TuiSt.ts
|
|
4282
|
-
const TUI_TIMING = {
|
|
4283
|
-
previewMs: 120,
|
|
4284
|
-
autosaveMs: 300
|
|
4285
|
-
};
|
|
4286
|
-
var TuiSt = class {
|
|
4287
|
-
/** the host runs actually target right now */
|
|
4288
|
-
get runHost() {
|
|
4289
|
-
return this.hostOverride ?? this.wf.host;
|
|
4290
|
-
}
|
|
4291
|
-
setHostOverride(host) {
|
|
4292
|
-
this.hostOverride = host;
|
|
4293
|
-
if (host != null) this.workflows.loadedHosts.add(host);
|
|
4294
|
-
this.queue.attach(this.runHost);
|
|
4295
|
-
this.logs.attach(this.runHost);
|
|
4296
|
-
this.settings.hostOverrideId = host?.data.id ?? null;
|
|
4297
|
-
}
|
|
4298
|
-
/** re-resolve a persisted override id — hosts register as modules import */
|
|
4299
|
-
applyPersistedHostOverride() {
|
|
4300
|
-
const id = this.settings.hostOverrideId;
|
|
4301
|
-
if (id == null || this.hostOverride != null) return;
|
|
4302
|
-
const host = comfyts.hosts.get(id);
|
|
4303
|
-
if (host != null) this.setHostOverride(host);
|
|
4304
|
-
}
|
|
4305
|
-
constructor(wf, opts = {}) {
|
|
4306
|
-
this.mode = "nav";
|
|
4307
|
-
this.selIx = 0;
|
|
4308
|
-
this.hostOverride = null;
|
|
4309
|
-
this.disposers = [];
|
|
4310
|
-
this.onExit = () => {};
|
|
4311
|
-
this.termCols = process.stdout.columns ?? 80;
|
|
4312
|
-
this.termRows = (process.stdout.rows ?? 24) - 1;
|
|
4313
|
-
this.varsViewH = 0;
|
|
4314
|
-
this.wf = wf;
|
|
4315
|
-
this.timing = opts.timing ?? TUI_TIMING;
|
|
4316
|
-
makeAutoObservable(this, {
|
|
4317
|
-
wf: observableRef,
|
|
4318
|
-
hostOverride: observableRef,
|
|
4319
|
-
onExit: false,
|
|
4320
|
-
timing: false,
|
|
4321
|
-
editor: false,
|
|
4322
|
-
picker: false,
|
|
4323
|
-
loras: false,
|
|
4324
|
-
imagePicker: false,
|
|
4325
|
-
workflows: false,
|
|
4326
|
-
tree: false,
|
|
4327
|
-
drafts: false,
|
|
4328
|
-
exec: false,
|
|
4329
|
-
preview: false,
|
|
4330
|
-
host: false,
|
|
4331
|
-
queue: false,
|
|
4332
|
-
logs: false,
|
|
4333
|
-
settings: false
|
|
4334
|
-
});
|
|
4335
|
-
this.settings = new SettingsSt(this);
|
|
4336
|
-
this.editor = new EditorSt(this);
|
|
4337
|
-
this.picker = new PickerSt(this);
|
|
4338
|
-
this.loras = new LorasSt(this);
|
|
4339
|
-
this.imagePicker = new ImagePickerSt(this);
|
|
4340
|
-
this.workflows = new WorkflowsSt(this, opts.workflowFiles ?? [], opts.currentFile ?? null, opts.bundledFiles, opts.loadErrors);
|
|
4341
|
-
this.tree = new TreeSt(this);
|
|
4342
|
-
this.drafts = new DraftsSt(this);
|
|
4343
|
-
this.exec = new ExecSt(this);
|
|
4344
|
-
this.preview = new PreviewSt(this);
|
|
4345
|
-
this.host = new HostSt(this);
|
|
4346
|
-
this.queue = new QueueSt(this);
|
|
4347
|
-
this.logs = new LogsSt(this);
|
|
4348
|
-
this.applyPersistedHostOverride();
|
|
4349
|
-
this.drafts.activateRemembered();
|
|
4350
|
-
if (opts.currentFile != null) {
|
|
4351
|
-
const currentFile = opts.currentFile;
|
|
4352
|
-
runInAction(() => {
|
|
4353
|
-
this.tree.expandedFiles.add(currentFile);
|
|
4354
|
-
this.workflows.recordSpecColor(currentFile, wf);
|
|
4355
|
-
this.settings.lastWorkflow = currentFile;
|
|
4356
|
-
});
|
|
4357
|
-
}
|
|
4358
|
-
const onResize = () => {
|
|
4359
|
-
runInAction(() => {
|
|
4360
|
-
this.termCols = process.stdout.columns ?? 80;
|
|
4361
|
-
this.termRows = (process.stdout.rows ?? 24) - 1;
|
|
4362
|
-
});
|
|
4363
|
-
};
|
|
4364
|
-
process.stdout.on?.("resize", onResize);
|
|
4365
|
-
this.disposers.push(() => process.stdout.off?.("resize", onResize));
|
|
4366
|
-
}
|
|
4367
|
-
dispose() {
|
|
4368
|
-
for (const d of this.disposers.splice(0)) d();
|
|
4369
|
-
this.workflows.disconnectAllHosts();
|
|
4370
|
-
}
|
|
4371
|
-
/** rows available inside a modal overlay list */
|
|
4372
|
-
get overlayLines() {
|
|
4373
|
-
return Math.max(8, this.termRows - 12);
|
|
4374
|
-
}
|
|
4375
|
-
/** left tree panel width: longest row (depth-indented), clamped */
|
|
4376
|
-
get treeWidth() {
|
|
4377
|
-
const longest = Math.max(8, ...this.tree.rows.map((r) => r.depth * 2 + (r.kind === "workflow" ? r.name.length : r.kind === "draft" ? r.draft.length + 3 : r.label.length + 2)));
|
|
4378
|
-
return Math.min(34, longest + 7);
|
|
4379
|
-
}
|
|
4380
|
-
get entries() {
|
|
4381
|
-
return this.wf.entries();
|
|
4382
|
-
}
|
|
4383
|
-
get selected() {
|
|
4384
|
-
return this.entries[this.selIx];
|
|
4385
|
-
}
|
|
4386
|
-
/** module key of the loaded workflow (drafts + savePrefix are keyed by it) */
|
|
4387
|
-
get moduleKey() {
|
|
4388
|
-
const cur = this.workflows.currentPath;
|
|
4389
|
-
return cur != null ? draftKeyForFile(cur) : this.wf.spec.id ?? "workflow";
|
|
4390
|
-
}
|
|
4391
|
-
/** the local save dir under .comfy-ts/outputs/ — per-module override, else the module key */
|
|
4392
|
-
get savePrefix() {
|
|
4393
|
-
return this.settings.savePrefix[this.moduleKey] ?? this.moduleKey;
|
|
4394
|
-
}
|
|
4395
|
-
/** empty input resets to the module-key default */
|
|
4396
|
-
setSavePrefix(raw) {
|
|
4397
|
-
const trimmed = raw.trim().replace(/^\/+|\/+$/g, "");
|
|
4398
|
-
if (trimmed === "" || trimmed === this.moduleKey) delete this.settings.savePrefix[this.moduleKey];
|
|
4399
|
-
else this.settings.savePrefix[this.moduleKey] = trimmed;
|
|
4400
|
-
}
|
|
4401
|
-
/** the vars list carries the TUI-owned rows after the workflow vars: the
|
|
4402
|
-
* save-to-disk toggle, plus the save-prefix row while saving is on
|
|
4403
|
-
* (architecture item 14) */
|
|
4404
|
-
get varRowCount() {
|
|
4405
|
-
return this.entries.length + (this.settings.saveToDisk ? 2 : 1);
|
|
4406
|
-
}
|
|
4407
|
-
/** true while the selection sits on the save-to-disk pseudo-row */
|
|
4408
|
-
get onSaveRow() {
|
|
4409
|
-
return this.selIx === this.entries.length;
|
|
4410
|
-
}
|
|
4411
|
-
/** true while the selection sits on the save-prefix pseudo-row */
|
|
4412
|
-
get onPrefixRow() {
|
|
4413
|
-
return this.settings.saveToDisk && this.selIx === this.entries.length + 1;
|
|
4414
|
-
}
|
|
4415
|
-
moveSel(delta) {
|
|
4416
|
-
const len = this.varRowCount;
|
|
4417
|
-
this.selIx = (this.selIx + delta + len) % len;
|
|
4418
|
-
}
|
|
4419
|
-
setVarsViewH(h) {
|
|
4420
|
-
this.varsViewH = h;
|
|
4421
|
-
}
|
|
4422
|
-
/** row budget: measured height minus the 2 border rows; pre-measure fallback estimate */
|
|
4423
|
-
get varsBudget() {
|
|
4424
|
-
const h = this.varsViewH > 0 ? this.varsViewH : Math.max(5, this.termRows - 5);
|
|
4425
|
-
return Math.max(1, h - 2);
|
|
4426
|
-
}
|
|
4427
|
-
get varsWindow() {
|
|
4428
|
-
return listWindow({
|
|
4429
|
-
count: this.varRowCount,
|
|
4430
|
-
selected: this.selIx,
|
|
4431
|
-
budget: this.varsBudget
|
|
4432
|
-
});
|
|
4433
|
-
}
|
|
4434
|
-
/**
|
|
4435
|
-
* while the list cannot fit, NON-selected rows collapse to one truncated
|
|
4436
|
-
* line (prompt values wrap tall) — rows above the selection then cost one
|
|
4437
|
-
* line each, so the selection can never be pushed off-screen. Reads only
|
|
4438
|
-
* entry count + measured height, never its own rendering: no oscillation.
|
|
4439
|
-
*/
|
|
4440
|
-
get varsCompact() {
|
|
4441
|
-
const w = this.varsWindow;
|
|
4442
|
-
if (w.moreAbove || w.moreBelow) return true;
|
|
4443
|
-
const h = this.varsViewH > 0 ? this.varsViewH : Math.max(5, this.termRows - 5);
|
|
4444
|
-
return this.varRowCount + 2 > h;
|
|
4445
|
-
}
|
|
4446
|
-
/** enter/space on a var: toggle, open an overlay, or inline-edit */
|
|
4447
|
-
activate() {
|
|
4448
|
-
if (this.onSaveRow) {
|
|
4449
|
-
this.settings.saveToDisk = !this.settings.saveToDisk;
|
|
4450
|
-
return;
|
|
4451
|
-
}
|
|
4452
|
-
if (this.onPrefixRow) {
|
|
4453
|
-
this.editor.beginCustom({
|
|
4454
|
-
title: `save prefix — dir under .comfy-ts/outputs/ (empty = ${this.moduleKey})`,
|
|
4455
|
-
initial: this.savePrefix,
|
|
4456
|
-
onCommit: (raw) => {
|
|
4457
|
-
this.setSavePrefix(raw);
|
|
4458
|
-
return true;
|
|
4459
|
-
}
|
|
4460
|
-
});
|
|
4461
|
-
return;
|
|
4462
|
-
}
|
|
4463
|
-
const sel = this.selected?.[1];
|
|
4464
|
-
if (sel == null) return;
|
|
4465
|
-
if (sel.kind === "toggle") sel.toggle();
|
|
4466
|
-
else if (sel.kind === "text" || sel.kind === "prompt") this.editor.beginMultiline();
|
|
4467
|
-
else if (sel.kind === "choice") this.picker.beginChoice();
|
|
4468
|
-
else if (sel.kind === "size") this.picker.beginSize();
|
|
4469
|
-
else if (sel.kind === "loras") this.loras.begin();
|
|
4470
|
-
else if (sel.kind === "image" || sel.kind === "audio" || sel.kind === "video") this.imagePicker.begin();
|
|
4471
|
-
else this.editor.beginInline();
|
|
4472
|
-
}
|
|
4473
|
-
/** kind-specific nav keys (documented in the keybar): seed `+`/`-`/`=`/`?` mode, `*` reroll */
|
|
4474
|
-
navKey(input) {
|
|
4475
|
-
const sel = this.selected?.[1];
|
|
4476
|
-
if (sel?.kind === "seed") {
|
|
4477
|
-
if (input === "+" || input === "-" || input === "=" || input === "?") {
|
|
4478
|
-
sel.setMode(input);
|
|
4479
|
-
return true;
|
|
4480
|
-
}
|
|
4481
|
-
if (input === "*") {
|
|
4482
|
-
sel.randomize();
|
|
4483
|
-
return true;
|
|
4484
|
-
}
|
|
4485
|
-
}
|
|
4486
|
-
return false;
|
|
4487
|
-
}
|
|
4488
|
-
};
|
|
4489
|
-
//#endregion
|
|
4490
|
-
//#region src/cli/tui/run-tui.tsx
|
|
4491
|
-
/** the module the last session was on, IF it is still in this run's tree
|
|
4492
|
-
* (settings write: SettingsSt; exported for the headless test) */
|
|
4493
|
-
function rememberedWorkflow(workflowFiles, settingsPath = settingsPathFor(process.cwd())) {
|
|
4494
|
-
try {
|
|
4495
|
-
const raw = JSON.parse(readFileSync(settingsPath, "utf8"));
|
|
4496
|
-
if (raw == null || typeof raw !== "object") return null;
|
|
4497
|
-
const last = raw.lastWorkflow;
|
|
4498
|
-
return typeof last === "string" && workflowFiles.includes(last) ? last : null;
|
|
4499
|
-
} catch {
|
|
4500
|
-
return null;
|
|
4501
|
-
}
|
|
4502
|
-
}
|
|
4503
|
-
async function runTui(args) {
|
|
4504
|
-
const target = args.find((a) => !a.startsWith("--"));
|
|
4505
|
-
process.env[COMFY_TS_TUI_ENV] = "1";
|
|
4506
|
-
process.env.COMFY_TS_QUIET = "1";
|
|
4507
|
-
const abs = realpathSync(resolve(target ?? "."));
|
|
4508
|
-
const isDir = statSync(abs).isDirectory();
|
|
4509
|
-
const scanned = scanCflowFiles(isDir ? abs : dirname(abs));
|
|
4510
|
-
const scannedPlusArg = isDir || scanned.includes(abs) ? scanned : [abs, ...scanned];
|
|
4511
|
-
const canImportBundled = process.versions.bun != null;
|
|
4512
|
-
const examplesDir = canImportBundled ? bundledExamplesDir() : null;
|
|
4513
|
-
if (!canImportBundled && target == null) logError("packaged examples skipped: importing .cflow.ts from node_modules needs bun (bunx --bun comfy-ts tui)");
|
|
4514
|
-
const bundledFiles = examplesDir == null ? [] : scanCflowFiles(realpathSync(examplesDir)).sort((a, b) => Number(!a.includes("/rvion/")) - Number(!b.includes("/rvion/")) || a.localeCompare(b));
|
|
4515
|
-
const discovery = mergeWorkflowSources({
|
|
4516
|
-
explicitTarget: target != null,
|
|
4517
|
-
scanned: scannedPlusArg,
|
|
4518
|
-
bundledFiles
|
|
4519
|
-
});
|
|
4520
|
-
const workflowFiles = discovery.files;
|
|
4521
|
-
if (workflowFiles.length === 0) {
|
|
4522
|
-
console.error(`[comfy-ts tui] no **/*.cflow.ts found under ${abs}`);
|
|
4523
|
-
return 1;
|
|
4524
|
-
}
|
|
4525
|
-
const preferred = !isDir && workflowFiles.includes(abs) ? abs : target == null ? rememberedWorkflow(workflowFiles) : null;
|
|
4526
|
-
const candidates = preferred != null ? [preferred, ...workflowFiles.filter((f) => f !== preferred)] : workflowFiles;
|
|
4527
|
-
const loadErrors = /* @__PURE__ */ new Map();
|
|
4528
|
-
let first = null;
|
|
4529
|
-
let wf = null;
|
|
4530
|
-
for (const file of candidates) try {
|
|
4531
|
-
const found = findDefinedWorkflow(await import(pathToFileURL(file).href));
|
|
4532
|
-
if (found == null) throw new Error(`${file} exports no DefinedWorkflow — export the result of host.defineWorkflow(...)`);
|
|
4533
|
-
first = file;
|
|
4534
|
-
wf = found;
|
|
4535
|
-
break;
|
|
4536
|
-
} catch (e) {
|
|
4537
|
-
loadErrors.set(file, extractErrorMessage(e));
|
|
4538
|
-
}
|
|
4539
|
-
if (first == null || wf == null) {
|
|
4540
|
-
console.error(`[comfy-ts tui] no loadable workflow module among ${candidates.length} file(s):`);
|
|
4541
|
-
for (const [file, err] of loadErrors) console.error(` ${file}: ${err}`);
|
|
4542
|
-
return 1;
|
|
4543
|
-
}
|
|
4544
|
-
const st = new TuiSt(wf, {
|
|
4545
|
-
workflowFiles,
|
|
4546
|
-
currentFile: first,
|
|
4547
|
-
bundledFiles: discovery.bundled,
|
|
4548
|
-
loadErrors
|
|
4549
|
-
});
|
|
4550
|
-
const altScreen = process.stdout.isTTY === true;
|
|
4551
|
-
if (altScreen) process.stdout.write("\x1B[?1049h\x1B[H\x1B[>4;1m");
|
|
4552
|
-
const uninstallPainter = installProtocolImagePainter(st);
|
|
4553
|
-
try {
|
|
4554
|
-
if (process.stdin.isTTY === true) process.stdin.setRawMode(true);
|
|
4555
|
-
const app = render(/* @__PURE__ */ jsx(TuiApp, { st }), { kittyKeyboard: { mode: "auto" } });
|
|
4556
|
-
st.onExit = () => st.dispose();
|
|
4557
|
-
await app.waitUntilExit();
|
|
4558
|
-
st.dispose();
|
|
4559
|
-
} finally {
|
|
4560
|
-
if (process.stdin.isTTY === true) process.stdin.setRawMode(false);
|
|
4561
|
-
uninstallPainter();
|
|
4562
|
-
if (altScreen) process.stdout.write("\x1B[0m\x1B[2J\x1B[H\x1B[>4;0m\x1B[?1049l");
|
|
4563
|
-
}
|
|
4564
|
-
return 0;
|
|
4565
|
-
}
|
|
4566
|
-
//#endregion
|
|
4567
|
-
export { runTui };
|
|
4568
|
-
|
|
4569
|
-
//# sourceMappingURL=run-tui-CrM4ijkH.js.map
|