comfy-ts 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +363 -0
- package/dist/cli.js +764 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +4171 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9910 -0
- package/dist/index.d.ts +9894 -58
- package/dist/index.js +4092 -2
- package/dist/index.js.map +1 -1
- package/dist/log-CdfgILde.js +10 -0
- package/dist/log-CdfgILde.js.map +1 -0
- package/dist/run-tui-SDSJo1Qf.js +3896 -0
- package/dist/run-tui-SDSJo1Qf.js.map +1 -0
- package/package.json +103 -75
- package/src/cli/comfy-ts-cli.ts +36 -0
- package/src/cli/gen.ts +47 -0
- package/src/cli/outline.ts +82 -0
- package/src/cli/tui/components/DraftsOverlay.tsx +44 -0
- package/src/cli/tui/components/EditField.tsx +27 -0
- package/src/cli/tui/components/Header.tsx +56 -0
- package/src/cli/tui/components/HostPanel.tsx +37 -0
- package/src/cli/tui/components/LogsPanel.tsx +23 -0
- package/src/cli/tui/components/LorasOverlay.tsx +49 -0
- package/src/cli/tui/components/OverlayList.tsx +25 -0
- package/src/cli/tui/components/PickerOverlays.tsx +66 -0
- package/src/cli/tui/components/PreviewPanel.tsx +78 -0
- package/src/cli/tui/components/PromptOverlay.tsx +16 -0
- package/src/cli/tui/components/StatusBar.tsx +171 -0
- package/src/cli/tui/components/TextOverlay.tsx +72 -0
- package/src/cli/tui/components/TreePanel.tsx +51 -0
- package/src/cli/tui/components/TuiApp.tsx +246 -0
- package/src/cli/tui/components/VarsPanel.tsx +86 -0
- package/src/cli/tui/findDefinedWorkflow.ts +16 -0
- package/src/cli/tui/keys.ts +20 -0
- package/src/cli/tui/protocolImagePainter.ts +95 -0
- package/src/cli/tui/run-tui.tsx +76 -0
- package/src/cli/tui/state/DraftsSt.ts +273 -0
- package/src/cli/tui/state/EditorSt.ts +289 -0
- package/src/cli/tui/state/ExecSt.ts +173 -0
- package/src/cli/tui/state/HostSt.ts +230 -0
- package/src/cli/tui/state/LogsSt.ts +107 -0
- package/src/cli/tui/state/LorasSt.ts +185 -0
- package/src/cli/tui/state/PickerSt.ts +112 -0
- package/src/cli/tui/state/PreviewSt.ts +288 -0
- package/src/cli/tui/state/QueueSt.ts +59 -0
- package/src/cli/tui/state/SettingsSt.ts +100 -0
- package/src/cli/tui/state/TreeSt.ts +122 -0
- package/src/cli/tui/state/TuiSt.ts +175 -0
- package/src/cli/tui/state/WorkflowsSt.ts +93 -0
- package/src/cli/tui-env.ts +8 -0
- package/src/errors/InvalidPromptError.ts +12 -0
- package/src/graph/ComfyNode.ts +403 -0
- package/src/graph/ComfyNodeID.ts +28 -0
- package/src/graph/ComfyNodeOutput.ts +16 -0
- package/src/graph/NodeSlotSize.ts +4 -0
- package/src/graph/autoValue.ts +17 -0
- package/src/host/ComfyHost.ts +690 -0
- package/src/host/ComfyInstallType.ts +15 -0
- package/src/host/ComfyManager.ts +232 -0
- package/src/host/ComfyUploader.ts +110 -0
- package/src/host/ComfyWorkflowBuilder.ts +60 -0
- package/src/host/Requirements.ts +55 -0
- package/src/host/ResilientWebsocket.ts +147 -0
- package/src/host/loraManagerApi.ts +98 -0
- package/src/image-utils/_getPngMetadata.ts +53 -0
- package/src/image-utils/_getWebpMetadata.ts +38 -0
- package/src/image-utils/_parseExifData.ts +53 -0
- package/src/index.ts +89 -0
- package/src/litegraph/LiteGraphGroup.ts +22 -0
- package/src/litegraph/LiteGraphJSON.ts +46 -0
- package/src/litegraph/LiteGraphLink.ts +23 -0
- package/src/litegraph/LiteGraphLinkID.ts +6 -0
- package/src/litegraph/LiteGraphNode.ts +69 -0
- package/src/litegraph/LiteGraphNodeInput.ts +27 -0
- package/src/litegraph/LiteGraphNodeOutput.ts +23 -0
- package/src/litegraph/LiteGraphSlotIndex.ts +6 -0
- package/src/litegraph/convertFlowToLiteGraphJSON.ts +114 -0
- package/src/manager/ComfyRegistry.ts +124 -0
- package/src/manager/generated/KnownComfyCustomNodeName.ts +19280 -0
- package/src/manager/generated/KnownComfyPluginTitle.ts +5130 -0
- package/src/manager/generated/KnownComfyPluginURL.ts +2589 -0
- package/src/manager/generated/KnownModel_Base.ts +126 -0
- package/src/manager/generated/KnownModel_FileName.ts +2287 -0
- package/src/manager/generated/KnownModel_Name.ts +2287 -0
- package/src/manager/generated/KnownModel_SavePath.ts +263 -0
- package/src/manager/generated/KnownModel_Type.ts +97 -0
- package/src/manager/json/alter-list.json +224 -0
- package/src/manager/json/custom-node-list.extra.ts +13 -0
- package/src/manager/json/custom-node-list.json +21948 -0
- package/src/manager/json/extension-node-map.json +31282 -0
- package/src/manager/json/github-stats.json +12602 -0
- package/src/manager/json/model-list.extra.ts +26 -0
- package/src/manager/json/model-list.json +5052 -0
- package/src/manager/loaders/step1_downloadComfyManagerJSONs.ts +56 -0
- package/src/manager/loaders/step2_custom-node-list-loader.ts +149 -0
- package/src/manager/loaders/step3_extension-node-map-loader.ts +189 -0
- package/src/manager/loaders/step4_model-list-loader.ts +159 -0
- package/src/manager/script-update-manager.bun.ts +18 -0
- package/src/manager/types/ComfyManagerAPIFetchPolicy.ts +9 -0
- package/src/manager/types/ComfyManagerAPIModelList.ts +10 -0
- package/src/manager/types/ComfyManagerAPIPluginList.ts +11 -0
- package/src/manager/types/ComfyManagerFileModelInfo.ts +5 -0
- package/src/manager/types/ComfyManagerFilePluginContent.ts +13 -0
- package/src/manager/types/ComfyManagerFilePluginList.ts +5 -0
- package/src/manager/types/ComfyManagerModelInfo.ts +18 -0
- package/src/manager/types/ComfyManagerPluginContentMetadata.ts +16 -0
- package/src/manager/types/ComfyManagerPluginEnums.ts +8 -0
- package/src/manager/types/ComfyManagerPluginInfo.ts +50 -0
- package/src/runner/ComfyExecution.ts +301 -0
- package/src/runner/ComfyExecutionStatus.ts +2 -0
- package/src/runner/ComfyWorkflow.ts +395 -0
- package/src/runner/ComfyWorkflowLayout.ts +96 -0
- package/src/runner/ComfyWsApi.ts +170 -0
- package/src/runner/MediaImage.ts +262 -0
- package/src/sdk-generator/ComfyNodeSchema.ts +79 -0
- package/src/sdk-generator/ComfySchema.ts +369 -0
- package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +95 -0
- package/src/sdk-generator/Primitives.ts +76 -0
- package/src/sdk-generator/_getUnionNameBasedOnFirstFoundEnumName.ts +39 -0
- package/src/sdk-generator/_pythonModuleToNamespace.ts +27 -0
- package/src/sdk-generator/_toQualifiedNodeKey.ts +5 -0
- package/src/sdk-generator/comfy-api-json.ts +16 -0
- package/src/sdk-generator/comfyui-sdk-codegen.ts +287 -0
- package/src/sdk-generator/comfyui-types.ts +56 -0
- package/src/sdk-generator/litegraphToApiRequestPayload.ts +157 -0
- package/src/ssh-host-manager/ssh-config-manager.ts +89 -0
- package/src/ssh-host-manager/ssh-config.windows.md +32 -0
- package/src/ssh-host-manager/ssh-manager.ts +114 -0
- package/src/state.ts +136 -0
- package/src/types/comfy-sdk.ts +106 -0
- package/src/types/index.ts +55 -0
- package/src/utils/CodeBuffer.ts +61 -0
- package/src/utils/ComfyColors.ts +38 -0
- package/src/utils/ansi.ts +33 -0
- package/src/utils/ansiImage.ts +36 -0
- package/src/utils/bang.ts +39 -0
- package/src/utils/deepCopyNaive.ts +1 -0
- package/src/utils/downloadFile.ts +77 -0
- package/src/utils/escapeJSKey.ts +32 -0
- package/src/utils/exhaust.ts +4 -0
- package/src/utils/extractErrorMessage.ts +11 -0
- package/src/utils/fuzzyMatch.ts +8 -0
- package/src/utils/githubRegexes.ts +2 -0
- package/src/utils/hashArrayBuffer.ts +6 -0
- package/src/utils/log.ts +9 -0
- package/src/utils/loraTag.ts +10 -0
- package/src/utils/mojibake.ts +60 -0
- package/src/utils/printArkResultInConsole.ts +16 -0
- package/src/utils/softValidate.ts +8 -0
- package/src/utils/stringifyReadable.ts +32 -0
- package/src/utils/toposort.ts +59 -0
- package/src/utils/tryExtracting.ts +41 -0
- package/src/utils/writeFile.ts +16 -0
- package/src/vars/ComfyVars.ts +531 -0
- package/src/vars/DefinedWorkflow.ts +112 -0
- package/src/vars/loraKeywords.ts +56 -0
- package/dist/index.d.mts +0 -74
- package/dist/index.mjs +0 -3
- package/dist/index.mjs.map +0 -1
- package/readme.md +0 -40
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Text } from 'ink'
|
|
2
|
+
import { observer } from 'mobx-react-lite'
|
|
3
|
+
import { OverlayList } from 'src/cli/tui/components/OverlayList.tsx'
|
|
4
|
+
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
5
|
+
|
|
6
|
+
/** modal option picker: type to fuzzy-filter, ↑/↓ to move, ⏎ to pick */
|
|
7
|
+
export const ChoiceOverlay = observer((p: { st: TuiSt }) => {
|
|
8
|
+
const s = p.st
|
|
9
|
+
const pk = s.picker
|
|
10
|
+
const options = pk.options
|
|
11
|
+
return (
|
|
12
|
+
<OverlayList
|
|
13
|
+
title={
|
|
14
|
+
<>
|
|
15
|
+
⌥ {s.selected ? (s.selected[1].label ?? s.selected[0]) : ''}{' '}
|
|
16
|
+
<Text color="gray">
|
|
17
|
+
({options.length} option{options.length === 1 ? '' : 's'})
|
|
18
|
+
</Text>
|
|
19
|
+
</>
|
|
20
|
+
}
|
|
21
|
+
extraHeader={<Text color="yellow">filter: {pk.filter}▌</Text>}
|
|
22
|
+
selectedIx={pk.ix}
|
|
23
|
+
lines={s.overlayLines}
|
|
24
|
+
rows={options.map((opt, ix) => ({
|
|
25
|
+
key: opt,
|
|
26
|
+
node: (
|
|
27
|
+
<Text key={opt} inverse={ix === pk.ix}>
|
|
28
|
+
{ix === pk.ix ? '▸ ' : ' '}
|
|
29
|
+
{opt}
|
|
30
|
+
</Text>
|
|
31
|
+
),
|
|
32
|
+
}))}
|
|
33
|
+
footer={options.length === 0 ? <Text color="red">no match</Text> : undefined}
|
|
34
|
+
/>
|
|
35
|
+
)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
/** modal size picker: presets, or type `WxH` and ⏎ for a custom size */
|
|
39
|
+
export const SizeOverlay = observer((p: { st: TuiSt }) => {
|
|
40
|
+
const s = p.st
|
|
41
|
+
const pk = s.picker
|
|
42
|
+
const options = pk.options
|
|
43
|
+
return (
|
|
44
|
+
<OverlayList
|
|
45
|
+
title={
|
|
46
|
+
<>
|
|
47
|
+
size {s.selected ? (s.selected[1].label ?? s.selected[0]) : ''}{' '}
|
|
48
|
+
<Text color="gray">· type WxH for custom</Text>
|
|
49
|
+
</>
|
|
50
|
+
}
|
|
51
|
+
extraHeader={<Text color={pk.invalid ? 'red' : 'yellow'}>filter: {pk.filter}▌</Text>}
|
|
52
|
+
selectedIx={pk.ix}
|
|
53
|
+
lines={s.overlayLines}
|
|
54
|
+
rows={options.map((opt, ix) => ({
|
|
55
|
+
key: opt,
|
|
56
|
+
node: (
|
|
57
|
+
<Text key={opt} inverse={ix === pk.ix}>
|
|
58
|
+
{ix === pk.ix ? '▸ ' : ' '}
|
|
59
|
+
{opt}
|
|
60
|
+
</Text>
|
|
61
|
+
),
|
|
62
|
+
}))}
|
|
63
|
+
footer={options.length === 0 ? <Text color="cyan">⏎ to use custom size “{pk.filter}”</Text> : undefined}
|
|
64
|
+
/>
|
|
65
|
+
)
|
|
66
|
+
})
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Box, Text } from 'ink'
|
|
2
|
+
import { observer } from 'mobx-react-lite'
|
|
3
|
+
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
4
|
+
|
|
5
|
+
/** right-side panel: selected-lora preview in the loras overlay, live latent while running,
|
|
6
|
+
* last output after — plus the `p` settings menu (mode 'preview') rendered in place.
|
|
7
|
+
* protocol terminals: the body is BLANK cells — useProtocolImage paints the real image over them */
|
|
8
|
+
export const PreviewPanel = observer((p: { st: TuiSt }) => {
|
|
9
|
+
const s = p.st
|
|
10
|
+
const pv = s.preview
|
|
11
|
+
|
|
12
|
+
if (pv.menuOpen) {
|
|
13
|
+
return (
|
|
14
|
+
<Box borderStyle="double" paddingX={1} flexDirection="column" flexShrink={0} width={pv.width + 4}>
|
|
15
|
+
<Box marginTop={-1}>
|
|
16
|
+
<Text color="gray">(p)review · settings</Text>
|
|
17
|
+
</Box>
|
|
18
|
+
{pv.menuRows.map((row, ix) => {
|
|
19
|
+
const sel = ix === pv.menuIx
|
|
20
|
+
return (
|
|
21
|
+
<Text key={row.key} inverse={sel} wrap="truncate">
|
|
22
|
+
{sel ? '▸ ' : ' '}
|
|
23
|
+
{row.label.padEnd(14)}
|
|
24
|
+
<Text bold>{row.value}</Text>
|
|
25
|
+
</Text>
|
|
26
|
+
)
|
|
27
|
+
})}
|
|
28
|
+
<Text> </Text>
|
|
29
|
+
<Text color="gray" wrap="truncate">
|
|
30
|
+
←→ change · ↑↓ move · ⏎/p/esc done
|
|
31
|
+
</Text>
|
|
32
|
+
</Box>
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const loraMode = s.mode === 'overlay-loras'
|
|
37
|
+
const running = s.exec.running
|
|
38
|
+
const wantLatent = running && pv.duringRun !== 'last-output'
|
|
39
|
+
const showLatent = !loraMode && wantLatent && (pv.latentAnsi != null || pv.latentBytes != null)
|
|
40
|
+
const label = loraMode
|
|
41
|
+
? `lora ${s.loras.previewName ?? 'lora'}`
|
|
42
|
+
: showLatent
|
|
43
|
+
? pv.duringRun === 'latent-small'
|
|
44
|
+
? 'latent small'
|
|
45
|
+
: 'latent'
|
|
46
|
+
: 'output'
|
|
47
|
+
const placeholder = loraMode
|
|
48
|
+
? (s.loras.previewNote ?? '(pick a lora)')
|
|
49
|
+
: pv.latentsMissing
|
|
50
|
+
? '(no latents from the server — launch comfy with --preview-method auto)'
|
|
51
|
+
: '(no image yet)'
|
|
52
|
+
const content = pv.useNative
|
|
53
|
+
? null
|
|
54
|
+
: loraMode
|
|
55
|
+
? s.loras.previewAnsi
|
|
56
|
+
: showLatent
|
|
57
|
+
? (pv.latentAnsi ?? pv.outputAnsi)
|
|
58
|
+
: pv.outputAnsi
|
|
59
|
+
const reserveRect = pv.useNative && (pv.protocolImage != null || pv.protocolImageCorner != null)
|
|
60
|
+
return (
|
|
61
|
+
<Box borderStyle="round" paddingX={1} flexDirection="column" flexShrink={0} width={pv.width + 4}>
|
|
62
|
+
{/* marginTop -1 lifts the label onto the border line: the panel key IS its title */}
|
|
63
|
+
<Box marginTop={-1}>
|
|
64
|
+
<Text color="gray" wrap="truncate">
|
|
65
|
+
(p)review · {label} · {pv.renderer}
|
|
66
|
+
{pv.latentsMissing ? <Text color="red"> · no latents!</Text> : null}
|
|
67
|
+
</Text>
|
|
68
|
+
</Box>
|
|
69
|
+
{reserveRect ? (
|
|
70
|
+
Array.from({ length: pv.height }, (_, ix) => <Text key={ix}> </Text>)
|
|
71
|
+
) : content != null ? (
|
|
72
|
+
<Text>{content}</Text>
|
|
73
|
+
) : (
|
|
74
|
+
<Text color="gray">{placeholder}</Text>
|
|
75
|
+
)}
|
|
76
|
+
</Box>
|
|
77
|
+
)
|
|
78
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Box, Text } from 'ink'
|
|
2
|
+
import { observer } from 'mobx-react-lite'
|
|
3
|
+
import { EditField } from 'src/cli/tui/components/EditField.tsx'
|
|
4
|
+
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
5
|
+
|
|
6
|
+
/** modal name prompt: renders any EditorSt CUSTOM session (new/rename/duplicate draft, …) */
|
|
7
|
+
export const PromptOverlay = observer((p: { st: TuiSt }) => {
|
|
8
|
+
const ed = p.st.editor
|
|
9
|
+
return (
|
|
10
|
+
<Box borderStyle="double" paddingX={1} flexDirection="column">
|
|
11
|
+
<Text bold>{ed.customTitle}</Text>
|
|
12
|
+
<EditField st={p.st} />
|
|
13
|
+
<Text color="gray">⏎ apply · esc cancel</Text>
|
|
14
|
+
</Box>
|
|
15
|
+
)
|
|
16
|
+
})
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { Box, Text } from 'ink'
|
|
2
|
+
import { observer } from 'mobx-react-lite'
|
|
3
|
+
import type { ReactNode } from 'react'
|
|
4
|
+
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
5
|
+
|
|
6
|
+
export type Hint = [key: string, label: string]
|
|
7
|
+
|
|
8
|
+
/** keys cyan, labels gray — shared by the keybar and overlay footers */
|
|
9
|
+
export const KeyHints = (p: { hints: Hint[] }): ReactNode => (
|
|
10
|
+
<Text wrap="wrap">
|
|
11
|
+
{p.hints.map(([k, label], ix) => (
|
|
12
|
+
<Text key={`${k}·${label}`}>
|
|
13
|
+
{ix > 0 ? <Text color="gray"> · </Text> : null}
|
|
14
|
+
<Text color="cyan">{k}</Text>
|
|
15
|
+
<Text color="gray"> {label}</Text>
|
|
16
|
+
</Text>
|
|
17
|
+
))}
|
|
18
|
+
</Text>
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
export const ProgressLine = observer((p: { st: TuiSt }) => {
|
|
22
|
+
const s = p.st
|
|
23
|
+
const e = s.exec
|
|
24
|
+
const queued = s.queue.remaining
|
|
25
|
+
if (s.mode === 'edit' || s.mode === 'overlay-text') return <Text color="gray">editing…</Text>
|
|
26
|
+
if (e.running) {
|
|
27
|
+
const prog = e.progress
|
|
28
|
+
const width = 16
|
|
29
|
+
const filled = prog ? Math.round((prog.percent / 100) * width) : 0
|
|
30
|
+
const bar = '█'.repeat(filled) + '░'.repeat(width - filled)
|
|
31
|
+
return (
|
|
32
|
+
<Text>
|
|
33
|
+
{'>> '}[{bar}] {prog ? `${prog.percent.toFixed(0)}%` : '…'}
|
|
34
|
+
{prog?.nodeName ? ` · ${prog.nodeName}` : ''}
|
|
35
|
+
{prog ? ` · ${(prog.elapsedMs / 1000).toFixed(0)}s` : ''}
|
|
36
|
+
{queued > 0 ? ` · queue ${queued}` : ''}
|
|
37
|
+
</Text>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
if (e.error) return <Text color="red">{e.error}</Text>
|
|
41
|
+
if (e.notice) return <Text>{e.notice}</Text>
|
|
42
|
+
if (queued > 0) return <Text color="yellow">{queued} queued on the server</Text>
|
|
43
|
+
if (e.runCount > 0)
|
|
44
|
+
return (
|
|
45
|
+
<Text color={e.lastStatus === 'Success' ? 'green' : 'red'}>
|
|
46
|
+
run #{e.runCount} {e.lastStatus?.toLowerCase()}
|
|
47
|
+
</Text>
|
|
48
|
+
)
|
|
49
|
+
return <Text color="gray">ready — r to run</Text>
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const KIND_KEYS: Record<string, Hint[]> = {
|
|
53
|
+
text: [['⏎/→', 'edit']],
|
|
54
|
+
int: [['⏎/→', 'edit']],
|
|
55
|
+
float: [['⏎/→', 'edit']],
|
|
56
|
+
seed: [
|
|
57
|
+
['+', 'increment'],
|
|
58
|
+
['-', 'decrement'],
|
|
59
|
+
['?', 'random'],
|
|
60
|
+
['=', 'fixed'],
|
|
61
|
+
['⏎/→', 'type value'],
|
|
62
|
+
['*', 'reroll'],
|
|
63
|
+
],
|
|
64
|
+
toggle: [['⏎/→', 'flip']],
|
|
65
|
+
choice: [['⏎/→', 'pick']],
|
|
66
|
+
size: [['⏎/→', 'pick']],
|
|
67
|
+
loras: [['⏎/→', 'select']],
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** shown INSIDE the text editor box (TextOverlay footer), not in the keybar */
|
|
71
|
+
export const TEXT_EDIT_HINTS: Hint[] = [
|
|
72
|
+
['⏎', 'save'],
|
|
73
|
+
['⇧⏎/⌥⏎', 'newline'],
|
|
74
|
+
['esc', 'cancel'],
|
|
75
|
+
['⌥⌫', 'del word'],
|
|
76
|
+
['⌥←→', 'jump'],
|
|
77
|
+
['⌘←→/⌃A⌃E', 'line ends'],
|
|
78
|
+
['⌥↑↓', 'move line'],
|
|
79
|
+
['⌘/', 'comment'],
|
|
80
|
+
['⌃U/⌃K', 'kill'],
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
export const DRAFT_OP_HINTS: Hint[] = [
|
|
84
|
+
['n', 'new'],
|
|
85
|
+
['e', 'rename'],
|
|
86
|
+
['c', 'duplicate'],
|
|
87
|
+
['x', 'delete'],
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
const MODE_KEYS: Partial<Record<string, Hint[]>> = {
|
|
91
|
+
edit: [
|
|
92
|
+
['⏎', 'apply'],
|
|
93
|
+
['esc', 'cancel'],
|
|
94
|
+
['⌥⌫/⌃W', 'del word'],
|
|
95
|
+
['⌥←→', 'jump'],
|
|
96
|
+
['⌃A/⌃E', 'line ends'],
|
|
97
|
+
['⌃U/⌃K', 'kill'],
|
|
98
|
+
],
|
|
99
|
+
'overlay-text': TEXT_EDIT_HINTS,
|
|
100
|
+
'overlay-choice': [
|
|
101
|
+
['⏎', 'pick'],
|
|
102
|
+
['↑↓', 'move'],
|
|
103
|
+
['type', 'filter'],
|
|
104
|
+
['esc', 'cancel'],
|
|
105
|
+
],
|
|
106
|
+
'overlay-size': [
|
|
107
|
+
['⏎', 'pick'],
|
|
108
|
+
['↑↓', 'move'],
|
|
109
|
+
['type', 'filter or WxH'],
|
|
110
|
+
['esc', 'cancel'],
|
|
111
|
+
],
|
|
112
|
+
'overlay-loras': [
|
|
113
|
+
['space/⏎', 'tick'],
|
|
114
|
+
['←→', 'strength ±0.05'],
|
|
115
|
+
['type', 'filter'],
|
|
116
|
+
['⌃K', 'keyword'],
|
|
117
|
+
['⌃A', 'all'],
|
|
118
|
+
['⌃N', 'none'],
|
|
119
|
+
['esc', 'done'],
|
|
120
|
+
],
|
|
121
|
+
'overlay-drafts': [['⏎', 'load / new'], ...DRAFT_OP_HINTS, ['↑↓', 'move'], ['esc', 'cancel']],
|
|
122
|
+
tree: [['⏎', 'load'], ['↑↓', 'move'], ['←', 'fold'], ['→', 'unfold / vars'], ...DRAFT_OP_HINTS, ['t/esc', 'back']],
|
|
123
|
+
host: [
|
|
124
|
+
['⏎', 'run action'],
|
|
125
|
+
['↑↓', 'move'],
|
|
126
|
+
['h/esc', 'back'],
|
|
127
|
+
],
|
|
128
|
+
preview: [
|
|
129
|
+
['←→', 'change'],
|
|
130
|
+
['↑↓', 'move'],
|
|
131
|
+
['⏎/p/esc', 'done'],
|
|
132
|
+
],
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** persistent 2-line keybar: EVERYTHING available right now, always visible */
|
|
136
|
+
export const KeyBar = observer((p: { st: TuiSt }) => {
|
|
137
|
+
const s = p.st
|
|
138
|
+
const kind = s.selected?.[1].kind
|
|
139
|
+
const modeHints: Hint[] = MODE_KEYS[s.mode] ?? [
|
|
140
|
+
['↑↓', 'select'],
|
|
141
|
+
['←', 'tree'],
|
|
142
|
+
...(kind ? (KIND_KEYS[kind] ?? []) : []),
|
|
143
|
+
]
|
|
144
|
+
// keys already advertised by a panel title (t/v/p) or a header box (w/d/h)
|
|
145
|
+
// are NOT repeated here — one letter, one place
|
|
146
|
+
const globalHints: Hint[] =
|
|
147
|
+
s.mode === 'nav' || s.mode === 'tree' || s.mode === 'host' || s.mode === 'preview'
|
|
148
|
+
? [
|
|
149
|
+
['r', 'run'],
|
|
150
|
+
['s', 'reroll+run'],
|
|
151
|
+
...(s.mode === 'nav' ? ([['e', 'rename draft']] as Hint[]) : []),
|
|
152
|
+
// the preview panel carries `p` in its title — unless it is hidden
|
|
153
|
+
...(s.preview.show || s.mode === 'preview' ? [] : ([['p', 'preview (off)']] as Hint[])),
|
|
154
|
+
['o', 'open image'],
|
|
155
|
+
// c is duplicate inside the tree — don't advertise the copy pair
|
|
156
|
+
// there; the preview menu doesn't forward it either
|
|
157
|
+
...(s.mode === 'tree' || s.mode === 'preview' ? [] : ([['c/C', 'copy wf/api']] as Hint[])),
|
|
158
|
+
['q', 'quit'],
|
|
159
|
+
]
|
|
160
|
+
: [
|
|
161
|
+
['⌃R', 'run'],
|
|
162
|
+
['esc', 'back'],
|
|
163
|
+
]
|
|
164
|
+
return (
|
|
165
|
+
<Box flexDirection="column" paddingX={1}>
|
|
166
|
+
{/* the text editor shows its keys under its own box */}
|
|
167
|
+
{s.mode !== 'overlay-text' && <KeyHints hints={modeHints} />}
|
|
168
|
+
<KeyHints hints={globalHints} />
|
|
169
|
+
</Box>
|
|
170
|
+
)
|
|
171
|
+
})
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Box, Text } from 'ink'
|
|
2
|
+
import { observer } from 'mobx-react-lite'
|
|
3
|
+
import { KeyHints, TEXT_EDIT_HINTS } from 'src/cli/tui/components/StatusBar.tsx'
|
|
4
|
+
import { PromptVar } from 'src/vars/ComfyVars.ts'
|
|
5
|
+
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
6
|
+
|
|
7
|
+
/** modal multiline editor: real newlines, caret rendered per code point.
|
|
8
|
+
* The cursor's LOGICAL line is background-highlighted (word wrap hides line
|
|
9
|
+
* bounds — the highlight shows exactly what ⌥↑↓ will move); on prompt vars,
|
|
10
|
+
* `//` comment lines render dim gray, `- ` negative lines red, and the
|
|
11
|
+
* injected lora keywords show as a magenta chrome line (not editable). */
|
|
12
|
+
export const TextOverlay = observer((p: { st: TuiSt }) => {
|
|
13
|
+
const s = p.st
|
|
14
|
+
const ed = s.editor
|
|
15
|
+
const winLines = s.overlayLines
|
|
16
|
+
const promptVar = s.selected?.[1]
|
|
17
|
+
const isPrompt = promptVar instanceof PromptVar
|
|
18
|
+
const injected = isPrompt ? promptVar.injectedKeywords() : []
|
|
19
|
+
// lines with their global code-point start offsets
|
|
20
|
+
const lines: { text: string; start: number }[] = []
|
|
21
|
+
let start = 0
|
|
22
|
+
for (const text of ed.buffer.split('\n')) {
|
|
23
|
+
lines.push({ text, start })
|
|
24
|
+
start += [...text].length + 1
|
|
25
|
+
}
|
|
26
|
+
let cursorLine = 0
|
|
27
|
+
for (let i = 0; i < lines.length; i++) if ((lines[i]?.start ?? 0) <= ed.cursor) cursorLine = i
|
|
28
|
+
const winStart = Math.max(0, Math.min(cursorLine - Math.floor(winLines / 2), lines.length - winLines))
|
|
29
|
+
const visible = lines.slice(winStart, winStart + winLines)
|
|
30
|
+
const color = ed.invalid ? 'red' : 'yellow'
|
|
31
|
+
return (
|
|
32
|
+
<Box borderStyle="double" paddingX={1} flexDirection="column">
|
|
33
|
+
<Text bold>{s.selected ? (s.selected[1].label ?? s.selected[0]) : ''}</Text>
|
|
34
|
+
{/* injected lora keywords: CHROME above the buffer — the cursor can never enter it */}
|
|
35
|
+
{injected.length > 0 && (
|
|
36
|
+
<Text color="magenta" wrap="wrap">
|
|
37
|
+
↳ loras: {injected.join(', ')} <Text dimColor>(injected)</Text>
|
|
38
|
+
</Text>
|
|
39
|
+
)}
|
|
40
|
+
{winStart > 0 && <Text color="gray">… {winStart} more line(s)</Text>}
|
|
41
|
+
{visible.map((line, ix) => {
|
|
42
|
+
const globalIx = winStart + ix
|
|
43
|
+
const comment = isPrompt && PromptVar.isCommentLine(line.text)
|
|
44
|
+
const negative = isPrompt && !comment && PromptVar.isNegativeLine(line.text)
|
|
45
|
+
const lineColor = comment ? 'gray' : negative ? 'red' : color
|
|
46
|
+
if (globalIx !== cursorLine)
|
|
47
|
+
return (
|
|
48
|
+
<Text key={globalIx} color={lineColor} dimColor={comment}>
|
|
49
|
+
{line.text === '' ? ' ' : line.text}
|
|
50
|
+
</Text>
|
|
51
|
+
)
|
|
52
|
+
const cs = [...line.text]
|
|
53
|
+
const col = ed.cursor - line.start
|
|
54
|
+
const before = cs.slice(0, col).join('')
|
|
55
|
+
const at = cs[col] ?? ' '
|
|
56
|
+
const after = cs.slice(col + 1).join('')
|
|
57
|
+
return (
|
|
58
|
+
<Text key={globalIx} color={lineColor} dimColor={comment} backgroundColor="blackBright">
|
|
59
|
+
{before}
|
|
60
|
+
<Text inverse>{at}</Text>
|
|
61
|
+
{after}
|
|
62
|
+
</Text>
|
|
63
|
+
)
|
|
64
|
+
})}
|
|
65
|
+
{winStart + winLines < lines.length && (
|
|
66
|
+
<Text color="gray">… {lines.length - winStart - winLines} more line(s)</Text>
|
|
67
|
+
)}
|
|
68
|
+
{/* edit keys sit right under the text, not at the screen bottom */}
|
|
69
|
+
<KeyHints hints={TEXT_EDIT_HINTS} />
|
|
70
|
+
</Box>
|
|
71
|
+
)
|
|
72
|
+
})
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Box, Text } from 'ink'
|
|
2
|
+
import { observer } from 'mobx-react-lite'
|
|
3
|
+
import type { TuiSt } from 'src/cli/tui/state/TuiSt.ts'
|
|
4
|
+
|
|
5
|
+
/** persistent left panel: workflows with their drafts nested; `t` (or ← from vars) focuses it */
|
|
6
|
+
export const TreePanel = observer((p: { st: TuiSt }) => {
|
|
7
|
+
const s = p.st
|
|
8
|
+
const tree = s.tree
|
|
9
|
+
const focused = s.mode === 'tree'
|
|
10
|
+
return (
|
|
11
|
+
<Box
|
|
12
|
+
borderStyle="round"
|
|
13
|
+
borderColor={focused ? 'cyan' : 'gray'}
|
|
14
|
+
flexDirection="column"
|
|
15
|
+
flexShrink={0}
|
|
16
|
+
width={s.treeWidth}
|
|
17
|
+
paddingX={1}
|
|
18
|
+
>
|
|
19
|
+
{/* marginTop -1 lifts the label onto the border line: the panel key IS its title */}
|
|
20
|
+
<Box marginTop={-1}>
|
|
21
|
+
<Text color={focused ? 'cyan' : 'gray'} bold={focused}>
|
|
22
|
+
(t)ree
|
|
23
|
+
</Text>
|
|
24
|
+
</Box>
|
|
25
|
+
{tree.rows.map((row, ix) => {
|
|
26
|
+
const sel = focused && ix === tree.ix
|
|
27
|
+
if (row.kind === 'workflow') {
|
|
28
|
+
const arrow = row.hasDrafts ? (row.expanded ? '▾' : '▸') : ' '
|
|
29
|
+
return (
|
|
30
|
+
<Text key={row.file} inverse={sel} color={row.current ? 'green' : undefined} wrap="truncate">
|
|
31
|
+
{arrow}
|
|
32
|
+
{row.current ? '●' : ' '} {row.name}
|
|
33
|
+
</Text>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
return (
|
|
37
|
+
<Text
|
|
38
|
+
key={`${row.file}·${row.draft}`}
|
|
39
|
+
inverse={sel}
|
|
40
|
+
color={row.active ? 'cyan' : 'gray'}
|
|
41
|
+
wrap="truncate"
|
|
42
|
+
>
|
|
43
|
+
{' '}
|
|
44
|
+
{row.active ? '●' : '·'} {row.draft}
|
|
45
|
+
</Text>
|
|
46
|
+
)
|
|
47
|
+
})}
|
|
48
|
+
{s.workflows.loading ? <Text color="yellow">loading…</Text> : null}
|
|
49
|
+
</Box>
|
|
50
|
+
)
|
|
51
|
+
})
|