comfy-ts 1.3.0 → 2.0.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/README.md +106 -6
- package/dist/{DefinedWorkflow-gpknV-5f.js → DefinedWorkflow-CqNE_kgR.js} +67 -14
- package/dist/DefinedWorkflow-CqNE_kgR.js.map +1 -0
- package/dist/{DraftsSt-DmA0jWGl.js → DraftsSt-Da4DZUP7.js} +2 -2
- package/dist/{DraftsSt-DmA0jWGl.js.map → DraftsSt-Da4DZUP7.js.map} +1 -1
- package/dist/cli.js +3 -3
- package/dist/index.cjs +548 -239
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +164 -116
- package/dist/index.d.ts +165 -117
- package/dist/index.js +540 -230
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-Bn6yIJB0.js → run-serve-BqeXtf8P.js} +9 -7
- package/dist/run-serve-BqeXtf8P.js.map +1 -0
- package/dist/{run-tui-BtjaOXRh.js → run-tui-CiB7TbYv.js} +18 -13
- package/dist/run-tui-CiB7TbYv.js.map +1 -0
- package/dist/{state-DKCPy105.js → state-C1g_B8zR.js} +398 -201
- package/dist/state-C1g_B8zR.js.map +1 -0
- package/dist/web.d.ts +17335 -0
- package/dist/web.js +5715 -0
- package/dist/web.js.map +1 -0
- package/examples/comfy-cloud/ace-step-t2a.cflow.ts +1 -0
- package/examples/comfy-cloud/anima-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/boogu-i2i.cflow.ts +2 -5
- package/examples/comfy-cloud/capybara-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/capybara-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/capybara-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/chatterbox-t2a.cflow.ts +1 -0
- package/examples/comfy-cloud/chroma-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/ernie-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/firered-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/flux1-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/flux1-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/flux2-i2i.cflow.ts +2 -5
- package/examples/comfy-cloud/flux2-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/hidream-i2i.cflow.ts +2 -5
- package/examples/comfy-cloud/hidream-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/hunyuan-video-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/hunyuan-video-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/ideogram4-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/kandinsky5-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/kandinsky5-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/kandinsky5-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/krea2-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/lens-t2i.cflow.ts +2 -3
- package/examples/comfy-cloud/longcat-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/longcat-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/ltxv-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/ltxv-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/newbie-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/omnigen2-i2i.cflow.ts +2 -5
- package/examples/comfy-cloud/omnigen2-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/ovis-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/pixeldit-t2i.cflow.ts +2 -5
- package/examples/comfy-cloud/qwen-image-i2i.cflow.ts +2 -2
- package/examples/comfy-cloud/qwen-image-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/sd35-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/sdk.d.ts +13251 -11458
- package/examples/comfy-cloud/sdxl-t2i.cflow.ts +2 -2
- package/examples/comfy-cloud/stable-audio-t2a.cflow.ts +1 -0
- package/examples/comfy-cloud/svd-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan21-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan21-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan22-i2v.cflow.ts +1 -0
- package/examples/comfy-cloud/wan22-t2v.cflow.ts +1 -0
- package/examples/comfy-cloud/z-image-t2i.cflow.ts +2 -5
- package/examples/rvion/01-txt2img.cflow.ts +5 -3
- package/examples/rvion/02-img2img-upload.cflow.ts +5 -4
- package/examples/rvion/04-krea2-turbo-t2i.cflow.ts +6 -7
- package/examples/rvion/05-comfy-cloud.cflow.ts +4 -2
- package/examples/rvion/06-qwen-image-edit.cflow.ts +2 -3
- package/examples/web/example.ts +78 -0
- package/examples/web/index.html +77 -0
- package/examples/web/serve.ts +42 -0
- package/examples/web/tsconfig.json +15 -0
- package/package.json +8 -2
- package/src/cli/serve/ServeApp.ts +9 -6
- package/src/cli/tui/state/ExecSt.ts +14 -2
- package/src/coreExports.ts +118 -0
- package/src/host/ComfyHost.ts +56 -24
- package/src/host/ResilientWebsocket.ts +93 -47
- package/src/host/hostUrl.ts +2 -1
- package/src/host/loraManagerApi.ts +6 -7
- package/src/index.ts +8 -107
- package/src/manager/loaders/step2_custom-node-list-loader.ts +4 -4
- package/src/manager/loaders/step3_extension-node-map-loader.ts +3 -3
- package/src/manager/loaders/step4_model-list-loader.ts +7 -7
- package/src/manager/loaders/step5_alter-list-loader.ts +2 -2
- package/src/manager/loaders/step6_github-stats-loader.ts +2 -2
- package/src/runner/ComfyExecution.ts +168 -77
- package/src/runner/ComfyWorkflow.ts +25 -3
- package/src/runner/ComfyWsApi.ts +6 -0
- package/src/runner/MediaImage.ts +73 -38
- package/src/runner/ephemeral.ts +21 -0
- package/src/runner/outputPath.ts +2 -2
- package/src/sdk-generator/ComfySchema.ts +2 -2
- package/src/sdk-generator/_pythonModuleToNamespace.ts +3 -0
- package/src/state.ts +13 -9
- package/src/storage/ComfyStorage.ts +144 -0
- package/src/storage/nodeStorage.ts +9 -0
- package/src/types/index.ts +6 -2
- package/src/utils/downloadFile.ts +11 -69
- package/src/utils/hashArrayBuffer.ts +3 -4
- package/src/utils/lazySharp.ts +25 -0
- package/src/utils/sha1.ts +69 -0
- package/src/vars/ComfyVars.ts +5 -6
- package/src/vars/DefinedWorkflow.ts +3 -1
- package/src/vars/loraKeywords.ts +6 -6
- package/src/web.ts +13 -0
- package/dist/DefinedWorkflow-gpknV-5f.js.map +0 -1
- package/dist/run-serve-Bn6yIJB0.js.map +0 -1
- package/dist/run-tui-BtjaOXRh.js.map +0 -1
- package/dist/state-DKCPy105.js.map +0 -1
- package/src/utils/writeFile.ts +0 -16
package/src/index.ts
CHANGED
|
@@ -1,115 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* comfy-ts — type-safe ComfyUI workflow creation and execution
|
|
2
|
+
* comfy-ts — type-safe ComfyUI workflow creation and execution (NODE entry)
|
|
3
3
|
* @packageDocumentation
|
|
4
4
|
*/
|
|
5
|
+
import { setDefaultComfyStorage } from 'src/storage/ComfyStorage.ts'
|
|
6
|
+
import { createNodeStorage } from 'src/storage/nodeStorage.ts'
|
|
5
7
|
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
+
// entry side effect: node 20/21 dist consumers have no getBuiltinModule
|
|
9
|
+
// autodetect, so the node backend installs here (architecture item 13)
|
|
10
|
+
setDefaultComfyStorage(createNodeStorage())
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
export { ComfyTS } from 'src/state.ts'
|
|
12
|
+
export * from 'src/coreExports.ts'
|
|
11
13
|
|
|
12
|
-
//
|
|
13
|
-
export {
|
|
14
|
-
ComfyHost,
|
|
15
|
-
ComfyHostAuthError,
|
|
16
|
-
type ComfyHostData,
|
|
17
|
-
type ComfyHostID,
|
|
18
|
-
type ConnectOptions,
|
|
19
|
-
} from 'src/host/ComfyHost.ts'
|
|
20
|
-
export { type ParsedHostBase, parseHostBase, renderHttpBase, renderWsUrl } from 'src/host/hostUrl.ts'
|
|
21
|
-
export { ComfyManager } from 'src/host/ComfyManager.ts'
|
|
22
|
-
export { ComfyUploader, type ComfyUploadImageResult } from 'src/host/ComfyUploader.ts'
|
|
23
|
-
export { ComfyWorkflowBuilder } from 'src/host/ComfyWorkflowBuilder.ts'
|
|
24
|
-
export type { Requirements, PluginInstallStatus, PluginSuggestion } from 'src/host/Requirements.ts'
|
|
25
|
-
export { ResilientWebSocketClient } from 'src/host/ResilientWebsocket.ts'
|
|
26
|
-
|
|
27
|
-
// runner
|
|
28
|
-
export {
|
|
29
|
-
ComfyWorkflow,
|
|
30
|
-
type ComfyNodeIdMode,
|
|
31
|
-
type ComfyWorkflowData,
|
|
32
|
-
type ComfyWorkflowID,
|
|
33
|
-
type ExecutionSnapshot,
|
|
34
|
-
type ProgressReport,
|
|
35
|
-
type RunSettings,
|
|
36
|
-
} from 'src/runner/ComfyWorkflow.ts'
|
|
37
|
-
export { ComfyExecution, type ComfyExecutionData, type ExecutionProgress } from 'src/runner/ComfyExecution.ts'
|
|
38
|
-
export type { PromptID, WsMsg, PromptRelated_WsMsg } from 'src/runner/ComfyWsApi.ts'
|
|
39
|
-
export { MediaImage, type MediaImageData } from 'src/runner/MediaImage.ts'
|
|
40
|
-
export type { ComfyExecutionStatus } from 'src/runner/ComfyExecutionStatus.ts'
|
|
41
|
-
export { InvalidPromptError } from 'src/errors/InvalidPromptError.ts'
|
|
42
|
-
|
|
43
|
-
// graph (programmatic node graph)
|
|
44
|
-
export { ComfyNode } from 'src/graph/ComfyNode.ts'
|
|
45
|
-
export { ComfyNodeOutput } from 'src/graph/ComfyNodeOutput.ts'
|
|
46
|
-
export type { ComfyNodeMetadata, ComfyNodeId } from 'src/graph/ComfyNodeID.ts'
|
|
47
|
-
export { auto, auto_ } from 'src/graph/autoValue.ts'
|
|
48
|
-
|
|
49
|
-
// bundled example assets (ship in the tarball)
|
|
14
|
+
// node-only surface: fs-backed example assets + the TUI env contract
|
|
50
15
|
export { exampleImagePath } from 'src/exampleAssets.ts'
|
|
51
|
-
|
|
52
|
-
// sdk generator (schema parsing + per-host codegen)
|
|
53
|
-
export { ComfySchema } from 'src/sdk-generator/ComfySchema.ts'
|
|
54
|
-
export { codegenSDK, hostIdToNamespace, type CodegenOptions } from 'src/sdk-generator/comfyui-sdk-codegen.ts'
|
|
55
|
-
export type { ComfyNodeSchemaJSON, ComfySchemaJSON } from 'src/sdk-generator/ComfyUIObjectInfoTypes.ts'
|
|
56
|
-
export type { ComfyImageName, ComfyUnionValue, QualifiedNodeKey } from 'src/sdk-generator/comfyui-types.ts'
|
|
57
|
-
export type { ComfyApiJson, ComfyApiNodeJson } from 'src/sdk-generator/comfy-api-json.ts'
|
|
58
|
-
|
|
59
|
-
// litegraph (ComfyUI saved-workflow JSON format)
|
|
60
|
-
export type { LiteGraphJSON } from 'src/litegraph/LiteGraphJSON.ts'
|
|
61
|
-
export { convertFlowToLiteGraphJSON } from 'src/litegraph/convertFlowToLiteGraphJSON.ts'
|
|
62
|
-
export type {
|
|
63
|
-
CanonicalGroup,
|
|
64
|
-
CanonicalInput,
|
|
65
|
-
CanonicalLink,
|
|
66
|
-
CanonicalNode,
|
|
67
|
-
CanonicalOutput,
|
|
68
|
-
CanonicalWidgetValues,
|
|
69
|
-
CanonicalWorkflow,
|
|
70
|
-
NodeMode,
|
|
71
|
-
} from 'src/litegraph/CanonicalWorkflow.ts'
|
|
72
|
-
export { normalizeWorkflow, parseWorkflowJson, WorkflowNormalizeError } from 'src/litegraph/normalizeWorkflow.ts'
|
|
73
|
-
export { convertLiteGraphToPrompt, WorkflowConvertError } from 'src/sdk-generator/litegraphToApiRequestPayload.ts'
|
|
74
|
-
|
|
75
|
-
// vars + re-runnable workflows
|
|
76
|
-
export {
|
|
77
|
-
v,
|
|
78
|
-
ComfyVarBase,
|
|
79
|
-
ComfyVar,
|
|
80
|
-
TextVar,
|
|
81
|
-
PromptVar,
|
|
82
|
-
IntVar,
|
|
83
|
-
FloatVar,
|
|
84
|
-
SeedVar,
|
|
85
|
-
ToggleVar,
|
|
86
|
-
ChoiceVar,
|
|
87
|
-
LorasVar,
|
|
88
|
-
SizeVar,
|
|
89
|
-
ImageVar,
|
|
90
|
-
ImageVarEmptyError,
|
|
91
|
-
DEFAULT_SIZE_PRESETS,
|
|
92
|
-
DEFAULT_IMAGE_EXTENSIONS,
|
|
93
|
-
activeLoras,
|
|
94
|
-
} from 'src/vars/ComfyVars.ts'
|
|
95
|
-
export type {
|
|
96
|
-
AnyVar,
|
|
97
|
-
VarKind,
|
|
98
|
-
VarsSpec,
|
|
99
|
-
VarValues,
|
|
100
|
-
PromptValue,
|
|
101
|
-
ActiveLoraSource,
|
|
102
|
-
LorasHost,
|
|
103
|
-
LoraStrength,
|
|
104
|
-
ActiveLora,
|
|
105
|
-
SizeValue,
|
|
106
|
-
SizePreset,
|
|
107
|
-
ImageVarOpts,
|
|
108
|
-
} from 'src/vars/ComfyVars.ts'
|
|
109
|
-
export { DefinedWorkflow, type DefineWorkflowSpec, type BoundVars, type LoraNameOf } from 'src/vars/DefinedWorkflow.ts'
|
|
110
|
-
export { getLoraKeyword, setLoraKeyword } from 'src/vars/loraKeywords.ts'
|
|
111
16
|
export { isTuiActive } from 'src/cli/tui-env.ts'
|
|
112
|
-
export { loraTag } from 'src/utils/loraTag.ts'
|
|
113
|
-
|
|
114
|
-
// shared types
|
|
115
|
-
export * from 'src/types/index.ts'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getComfyStorage } from 'src/storage/ComfyStorage.ts'
|
|
2
2
|
import { type } from 'arktype'
|
|
3
3
|
import { ansi as chalk } from 'src/utils/ansi.ts'
|
|
4
4
|
import { githubRegexpV1 } from 'src/utils/githubRegexes.ts'
|
|
@@ -17,7 +17,7 @@ export const _getKnownPlugins = (DB: ComfyRegistry): void => {
|
|
|
17
17
|
let totalFileSeen = 0
|
|
18
18
|
|
|
19
19
|
// parse rows: loose raw schema per row, skip+report failures, normalize survivors
|
|
20
|
-
const raw: unknown = JSON.parse(
|
|
20
|
+
const raw: unknown = JSON.parse(getComfyStorage().readText('src/manager/json/custom-node-list.json'))
|
|
21
21
|
const root = ComfyManagerFilePluginListRoot_ark(raw)
|
|
22
22
|
if (root instanceof type.errors) throw new ManagerParseError('custom-node-list.json', root.summary)
|
|
23
23
|
|
|
@@ -68,7 +68,7 @@ export const _getKnownPlugins = (DB: ComfyRegistry): void => {
|
|
|
68
68
|
}
|
|
69
69
|
out1 += '\n'
|
|
70
70
|
const out1Path = 'src/manager/generated/KnownComfyPluginTitle.ts'
|
|
71
|
-
|
|
71
|
+
getComfyStorage().writeText(out1Path, out1 + '\n')
|
|
72
72
|
console.log(` > generated: ${chalk.blue.underline(out1Path)}`)
|
|
73
73
|
|
|
74
74
|
// FileType
|
|
@@ -79,7 +79,7 @@ export const _getKnownPlugins = (DB: ComfyRegistry): void => {
|
|
|
79
79
|
out2 += 'export type KnownComfyPluginURL =\n'
|
|
80
80
|
for (const fileName of sortedFileNames) out2 += ` | ${JSON.stringify(fileName)}\n`
|
|
81
81
|
const out2Path = 'src/manager/generated/KnownComfyPluginURL.ts'
|
|
82
|
-
|
|
82
|
+
getComfyStorage().writeText(out2Path, out2)
|
|
83
83
|
console.log(` > generated: ${chalk.blue.underline(out2Path)}`)
|
|
84
84
|
}
|
|
85
85
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getComfyStorage } from 'src/storage/ComfyStorage.ts'
|
|
2
2
|
import { type } from 'arktype'
|
|
3
3
|
import { ansi as chalk } from 'src/utils/ansi.ts'
|
|
4
4
|
import { toQualifiedNodeKey } from 'src/sdk-generator/_toQualifiedNodeKey.ts'
|
|
@@ -14,7 +14,7 @@ export const _getCustomNodeRegistry = (DB: ComfyRegistry): void => {
|
|
|
14
14
|
const counter = DB.report.file('extension-node-map.json')
|
|
15
15
|
let totalCustomNodeSeen: number = 0
|
|
16
16
|
|
|
17
|
-
const raw: unknown = JSON.parse(
|
|
17
|
+
const raw: unknown = JSON.parse(getComfyStorage().readText('src/manager/json/extension-node-map.json'))
|
|
18
18
|
const root = type('Record<string, unknown>')(raw)
|
|
19
19
|
if (root instanceof type.errors) throw new ManagerParseError('extension-node-map.json', root.summary)
|
|
20
20
|
|
|
@@ -64,7 +64,7 @@ export const _getCustomNodeRegistry = (DB: ComfyRegistry): void => {
|
|
|
64
64
|
out += '\n'
|
|
65
65
|
|
|
66
66
|
const outPath = 'src/manager/generated/KnownComfyCustomNodeName.ts'
|
|
67
|
-
|
|
67
|
+
getComfyStorage().writeText(outPath, out + '\n')
|
|
68
68
|
console.log(` > generated: ${chalk.blue.underline(outPath)}`)
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getComfyStorage } from 'src/storage/ComfyStorage.ts'
|
|
2
2
|
import { type } from 'arktype'
|
|
3
3
|
import { ansi as chalk } from 'src/utils/ansi.ts'
|
|
4
4
|
import type { ComfyRegistry } from 'src/manager/ComfyRegistry.ts'
|
|
@@ -10,7 +10,7 @@ import { type ComfyManagerModelInfo, ComfyManagerModelInfo_ark } from 'src/manag
|
|
|
10
10
|
export const _getKnownModels = (DB: ComfyRegistry): void => {
|
|
11
11
|
const counter = DB.report.file('model-list.json')
|
|
12
12
|
|
|
13
|
-
const raw: unknown = JSON.parse(
|
|
13
|
+
const raw: unknown = JSON.parse(getComfyStorage().readText('src/manager/json/model-list.json'))
|
|
14
14
|
const root = ComfyManagerFileModelInfoRoot_ark(raw)
|
|
15
15
|
if (root instanceof type.errors) throw new ManagerParseError('model-list.json', root.summary)
|
|
16
16
|
|
|
@@ -54,7 +54,7 @@ export const _getKnownModels = (DB: ComfyRegistry): void => {
|
|
|
54
54
|
out1 += ` ${JSON.stringify(cat).padEnd(20)}, // x ${count.toString().padStart(3)}\n`
|
|
55
55
|
out1 += ']\n'
|
|
56
56
|
const out1Path = 'src/manager/generated/KnownModel_Type.ts'
|
|
57
|
-
|
|
57
|
+
getComfyStorage().writeText(out1Path, out1 + '\n')
|
|
58
58
|
console.log(` > generated: ${chalk.blue.underline(out1Path)}`)
|
|
59
59
|
|
|
60
60
|
// #region savepath
|
|
@@ -77,7 +77,7 @@ export const _getKnownModels = (DB: ComfyRegistry): void => {
|
|
|
77
77
|
out4 += ` ${JSON.stringify(cat).padEnd(50)}, // x ${count.toString().padStart(3)}\n`
|
|
78
78
|
out4 += ']\n'
|
|
79
79
|
const out4Path = 'src/manager/generated/KnownModel_SavePath.ts'
|
|
80
|
-
|
|
80
|
+
getComfyStorage().writeText(out4Path, out4 + '\n')
|
|
81
81
|
console.log(` > generated: ${chalk.blue.underline(out4Path)}`)
|
|
82
82
|
|
|
83
83
|
// #region base
|
|
@@ -101,7 +101,7 @@ export const _getKnownModels = (DB: ComfyRegistry): void => {
|
|
|
101
101
|
out2 += ` ${JSON.stringify(cat).padEnd(20)}, // x ${count.toString().padStart(3)}\n`
|
|
102
102
|
out2 += ']\n'
|
|
103
103
|
const out2Path = 'src/manager/generated/KnownModel_Base.ts'
|
|
104
|
-
|
|
104
|
+
getComfyStorage().writeText(out2Path, out2 + '\n')
|
|
105
105
|
console.log(` > generated: ${chalk.blue.underline(out2Path)}`)
|
|
106
106
|
|
|
107
107
|
// #region KnownModel_Name
|
|
@@ -118,7 +118,7 @@ export const _getKnownModels = (DB: ComfyRegistry): void => {
|
|
|
118
118
|
}
|
|
119
119
|
out3 += '\n'
|
|
120
120
|
const out3Path = 'src/manager/generated/KnownModel_Name.ts'
|
|
121
|
-
|
|
121
|
+
getComfyStorage().writeText(out3Path, out3 + '\n')
|
|
122
122
|
console.log(` > generated: ${chalk.blue.underline(out3Path)}`)
|
|
123
123
|
|
|
124
124
|
// #region KnownModel_FileName
|
|
@@ -134,7 +134,7 @@ export const _getKnownModels = (DB: ComfyRegistry): void => {
|
|
|
134
134
|
}
|
|
135
135
|
out99 += '\n'
|
|
136
136
|
const out99Path = 'src/manager/generated/KnownModel_FileName.ts'
|
|
137
|
-
|
|
137
|
+
getComfyStorage().writeText(out99Path, out99 + '\n')
|
|
138
138
|
console.log(` > generated: ${chalk.blue.underline(out99Path)}`)
|
|
139
139
|
}
|
|
140
140
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getComfyStorage } from 'src/storage/ComfyStorage.ts'
|
|
2
2
|
import { type } from 'arktype'
|
|
3
3
|
import type { ComfyRegistry } from 'src/manager/ComfyRegistry.ts'
|
|
4
4
|
import { ManagerParseError } from 'src/manager/loaders/parseReport.ts'
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
export const _getAlterList = (DB: ComfyRegistry): void => {
|
|
12
12
|
const counter = DB.report.file('alter-list.json')
|
|
13
13
|
|
|
14
|
-
const raw: unknown = JSON.parse(
|
|
14
|
+
const raw: unknown = JSON.parse(getComfyStorage().readText('src/manager/json/alter-list.json'))
|
|
15
15
|
const root = ComfyManagerFileAlterListRoot_ark(raw)
|
|
16
16
|
if (root instanceof type.errors) throw new ManagerParseError('alter-list.json', root.summary)
|
|
17
17
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getComfyStorage } from 'src/storage/ComfyStorage.ts'
|
|
2
2
|
import { type } from 'arktype'
|
|
3
3
|
import type { ComfyRegistry } from 'src/manager/ComfyRegistry.ts'
|
|
4
4
|
import { ManagerParseError } from 'src/manager/loaders/parseReport.ts'
|
|
@@ -7,7 +7,7 @@ import { ComfyManagerGithubStatEntry_ark } from 'src/manager/types/ComfyManagerG
|
|
|
7
7
|
export const _getGithubStats = (DB: ComfyRegistry): void => {
|
|
8
8
|
const counter = DB.report.file('github-stats.json')
|
|
9
9
|
|
|
10
|
-
const raw: unknown = JSON.parse(
|
|
10
|
+
const raw: unknown = JSON.parse(getComfyStorage().readText('src/manager/json/github-stats.json'))
|
|
11
11
|
const root = type('Record<string, unknown>')(raw)
|
|
12
12
|
if (root instanceof type.errors) throw new ManagerParseError('github-stats.json', root.summary)
|
|
13
13
|
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
|
|
2
|
-
import { dirname } from 'pathe'
|
|
3
1
|
import { localOutputPath, runTimestamp, uniquifyOutputPath } from 'src/runner/outputPath.ts'
|
|
4
2
|
|
|
5
3
|
/** paths claimed by in-flight retrievals: two same-second runs on a
|
|
6
4
|
* counter-resetting cloud host compute the same name before either writes */
|
|
7
5
|
const CLAIMED_OUTPUT_PATHS = new Set<string>()
|
|
8
|
-
import
|
|
6
|
+
import type { FormatEnum } from 'sharp'
|
|
9
7
|
import type { ComfyHost } from 'src/host/ComfyHost.ts'
|
|
8
|
+
import { getComfyStorage } from 'src/storage/ComfyStorage.ts'
|
|
9
|
+
import { importSharp } from 'src/utils/lazySharp.ts'
|
|
10
10
|
import { getPngMetadataFromUint8Array } from 'src/image-utils/_getPngMetadata.ts'
|
|
11
11
|
import type { ComfyNodeId } from 'src/graph/ComfyNodeID.ts'
|
|
12
|
-
import { asAbsolutePath, type
|
|
12
|
+
import { type AbsolutePath, asAbsolutePath, type Maybe, type SaveOptions } from 'src/types/index.ts'
|
|
13
|
+
import { bang } from 'src/utils/bang.ts'
|
|
13
14
|
import { exhaust } from 'src/utils/exhaust.ts'
|
|
14
15
|
import type { ComfyExecutionStatus } from 'src/runner/ComfyExecutionStatus.ts'
|
|
15
16
|
import type { ComfyWorkflow, ComfyWorkflowID, ExecutionSnapshot, ProgressReport } from 'src/runner/ComfyWorkflow.ts'
|
|
@@ -17,7 +18,7 @@ import type { ComfyWorkflow, ComfyWorkflowID, ExecutionSnapshot, ProgressReport
|
|
|
17
18
|
import type {
|
|
18
19
|
ComfyImageInfo,
|
|
19
20
|
PromptID,
|
|
20
|
-
|
|
21
|
+
PendingWsItem,
|
|
21
22
|
WsMsgExecuted,
|
|
22
23
|
WsMsgExecuting,
|
|
23
24
|
WsMsgExecutionError,
|
|
@@ -49,14 +50,18 @@ export class ComfyExecution {
|
|
|
49
50
|
public data: ComfyExecutionData,
|
|
50
51
|
init: {
|
|
51
52
|
snapshot?: ExecutionSnapshot
|
|
52
|
-
|
|
53
|
+
save?: Maybe<boolean | SaveOptions>
|
|
54
|
+
scrubHistory?: boolean
|
|
55
|
+
ephemeral?: boolean
|
|
53
56
|
onProgress?: Maybe<(p: ExecutionProgress) => void>
|
|
54
57
|
logProgress?: boolean
|
|
55
58
|
} = {},
|
|
56
59
|
) {
|
|
57
60
|
// settings FIRST: onCreate flushes buffered ws messages whose handlers read them
|
|
58
61
|
this.snapshot = init.snapshot ?? null
|
|
59
|
-
this.
|
|
62
|
+
this.save = init.save === true ? {} : init.save === false ? null : (init.save ?? null)
|
|
63
|
+
this.scrubHistory = init.scrubHistory ?? false
|
|
64
|
+
this.ephemeral = init.ephemeral ?? false
|
|
60
65
|
this.onProgress = init.onProgress ?? null
|
|
61
66
|
this.logProgress = init.logProgress ?? false
|
|
62
67
|
// register with the host so websocket messages route here,
|
|
@@ -65,8 +70,12 @@ export class ComfyExecution {
|
|
|
65
70
|
this.onCreate()
|
|
66
71
|
}
|
|
67
72
|
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
/** local disk saving, OPT-IN (architecture.md item 14); null = outputs stay in memory */
|
|
74
|
+
save: Maybe<SaveOptions> = null
|
|
75
|
+
/** delete this run's server history entry after `done` */
|
|
76
|
+
scrubHistory: boolean = false
|
|
77
|
+
/** this run's SaveImage nodes were rewritten to SaveImageWebsocket in the snapshot */
|
|
78
|
+
ephemeral: boolean = false
|
|
70
79
|
|
|
71
80
|
/** exactly what was sent to the host, frozen at send time (replayable) */
|
|
72
81
|
snapshot: Maybe<ExecutionSnapshot> = null
|
|
@@ -100,7 +109,7 @@ export class ComfyExecution {
|
|
|
100
109
|
const line = `▶ [${bar}] ${p.percent.toFixed(0).padStart(3)}%${node} · ${(p.elapsedMs / 1000).toFixed(0)}s`
|
|
101
110
|
if (line === this._lastLoggedLine) return
|
|
102
111
|
this._lastLoggedLine = line
|
|
103
|
-
if (process
|
|
112
|
+
if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}`)
|
|
104
113
|
else console.log(line)
|
|
105
114
|
}
|
|
106
115
|
|
|
@@ -108,7 +117,7 @@ export class ComfyExecution {
|
|
|
108
117
|
if (!this.logProgress) return
|
|
109
118
|
const p = this.progress
|
|
110
119
|
const line = `${this.status === 'Failure' ? '🔴' : '🟢'} ${this.status.toLowerCase()} in ${(p.elapsedMs / 1000).toFixed(1)}s · ${this.images.length} image(s)`
|
|
111
|
-
if (process
|
|
120
|
+
if (globalThis.process?.stdout?.isTTY) process.stdout.write(`\r\x1b[2K${line}\n`)
|
|
112
121
|
else console.log(line)
|
|
113
122
|
}
|
|
114
123
|
|
|
@@ -141,8 +150,14 @@ export class ComfyExecution {
|
|
|
141
150
|
return this.data.status ?? 'New'
|
|
142
151
|
}
|
|
143
152
|
|
|
144
|
-
onPromptRelatedMessage = (msg:
|
|
153
|
+
onPromptRelatedMessage = (msg: PendingWsItem): void => {
|
|
145
154
|
const graph = this.workflow
|
|
155
|
+
// replayed pre-registration binary frame: an OUTPUT only when the ws
|
|
156
|
+
// saver was executing at this point of the stream; stale latents drop
|
|
157
|
+
if (msg.type === 'binary_preview_frame') {
|
|
158
|
+
if (this.wsOutputNodeExecuting) this.onWsImageOutput({ bytes: msg.bytes, mime: msg.mime })
|
|
159
|
+
return
|
|
160
|
+
}
|
|
146
161
|
if (msg.type === 'execution_start') return
|
|
147
162
|
else if (msg.type === 'execution_cached') graph.onExecutionCached(msg)
|
|
148
163
|
else if (msg.type === 'executing') this.onExecuting(msg)
|
|
@@ -193,8 +208,9 @@ export class ComfyExecution {
|
|
|
193
208
|
}
|
|
194
209
|
private pendingPromises: Promise<void>[] = []
|
|
195
210
|
|
|
196
|
-
/** image retrievals that failed (their images are missing from `images`)
|
|
197
|
-
|
|
211
|
+
/** image retrievals that failed (their images are missing from `images`);
|
|
212
|
+
* `image` is null for SaveImageWebsocket frames (no server-side file info exists) */
|
|
213
|
+
imageErrors: { image: Maybe<ComfyImageInfo>; error: unknown }[] = []
|
|
198
214
|
|
|
199
215
|
retrieveImage = async (
|
|
200
216
|
//
|
|
@@ -203,98 +219,151 @@ export class ComfyExecution {
|
|
|
203
219
|
): Promise<void> => {
|
|
204
220
|
// retrieve the node
|
|
205
221
|
const promptNode = this.workflow.data.apiJson?.[promptNodeID]
|
|
206
|
-
const promptMeta = this.workflow.data.metadata?.[promptNodeID]
|
|
207
222
|
if (promptNode == null) throw new Error(`❌ invariant violation: promptNode is null`)
|
|
208
223
|
|
|
209
224
|
// image route on the host (cloud answers a 302 signed url — fetchFile follows it unauthed)
|
|
210
225
|
const imgRoute = '/view?' + new URLSearchParams(comfyImageInfo).toString()
|
|
226
|
+
const response = await this.host.fetchFile(imgRoute)
|
|
227
|
+
const bytes = new Uint8Array(await response.arrayBuffer())
|
|
228
|
+
|
|
229
|
+
const comfyUIInfos = { comfyImageInfo, comfyHostHttpURL: this.host.getServerHostHTTP() }
|
|
230
|
+
|
|
231
|
+
// local saving is OPT-IN (architecture.md item 14): no save → in-memory only
|
|
232
|
+
const sf = this.save
|
|
233
|
+
if (sf == null) {
|
|
234
|
+
return this.pushImage(
|
|
235
|
+
new MediaImage({ buffer: bytes, execution: this, promptNodeID: promptNodeID, comfyUIInfos }),
|
|
236
|
+
promptNodeID,
|
|
237
|
+
)
|
|
238
|
+
}
|
|
211
239
|
|
|
212
|
-
// target path on disk: OUR naming, never the raw server filename — a
|
|
213
|
-
// cloud host resets its _00001_ counter per run, so the server name
|
|
214
|
-
// overwrote the same local file on every run (his repro 2026-07-31)
|
|
215
|
-
const sf = this.saveFormat
|
|
216
240
|
const promptPrefix = promptNode.inputs['filename_prefix']
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
241
|
+
const written = await this.encodeAndWrite({
|
|
242
|
+
bytes,
|
|
243
|
+
sf,
|
|
244
|
+
filenamePrefix: typeof promptPrefix === 'string' ? promptPrefix : undefined,
|
|
245
|
+
subfolder: comfyImageInfo.subfolder,
|
|
246
|
+
filename: comfyImageInfo.filename,
|
|
247
|
+
})
|
|
248
|
+
this.pushImage(
|
|
249
|
+
new MediaImage({
|
|
250
|
+
path: written.path,
|
|
251
|
+
buffer: written.bytes,
|
|
252
|
+
execution: this,
|
|
253
|
+
promptNodeID: promptNodeID,
|
|
254
|
+
comfyUIInfos,
|
|
224
255
|
}),
|
|
256
|
+
promptNodeID,
|
|
225
257
|
)
|
|
226
|
-
|
|
227
|
-
const extension = sf.format.split('/')[1]
|
|
228
|
-
absPath += '.' + extension
|
|
229
|
-
}
|
|
230
|
-
// last-resort uniquifier: bump past files on disk AND paths claimed by
|
|
231
|
-
// still-downloading retrievals — never overwrite
|
|
232
|
-
absPath = uniquifyOutputPath({ path: absPath, exists: existsSync, claimed: CLAIMED_OUTPUT_PATHS })
|
|
233
|
-
const dir = dirname(absPath)
|
|
234
|
-
mkdirSync(dir, { recursive: true })
|
|
235
|
-
|
|
236
|
-
// ref
|
|
237
|
-
let img: MediaImage
|
|
258
|
+
}
|
|
238
259
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
260
|
+
/** re-encode when asked, then write under OUR local naming — never the raw
|
|
261
|
+
* server filename: a cloud host resets its _00001_ counter per run, so the
|
|
262
|
+
* server name overwrote the same local file on every run (his repro 2026-07-31) */
|
|
263
|
+
private encodeAndWrite = async (p: {
|
|
264
|
+
bytes: Uint8Array
|
|
265
|
+
sf: SaveOptions
|
|
266
|
+
filenamePrefix?: string
|
|
267
|
+
subfolder: string
|
|
268
|
+
filename: string
|
|
269
|
+
}): Promise<{ path: AbsolutePath; bytes: Uint8Array }> => {
|
|
270
|
+
let bytes = p.bytes
|
|
271
|
+
const reencode = p.sf.format != null && p.sf.format !== 'raw'
|
|
272
|
+
if (reencode) {
|
|
273
|
+
// PNG text chunk (workflow provenance) survives the re-encode as EXIF
|
|
243
274
|
let textChunk = {}
|
|
244
275
|
try {
|
|
245
|
-
const res = getPngMetadataFromUint8Array(
|
|
276
|
+
const res = getPngMetadataFromUint8Array(p.bytes)
|
|
246
277
|
if (res.success) textChunk = res.value
|
|
247
278
|
} catch {}
|
|
248
279
|
|
|
249
280
|
const format = ((): keyof FormatEnum => {
|
|
250
|
-
if (sf.format === 'image/jpeg') return 'jpeg'
|
|
251
|
-
if (sf.format === 'image/
|
|
252
|
-
if (sf.format === 'image/webp') return 'webp'
|
|
281
|
+
if (p.sf.format === 'image/jpeg') return 'jpeg'
|
|
282
|
+
if (p.sf.format === 'image/webp') return 'webp'
|
|
253
283
|
return 'png'
|
|
254
284
|
})()
|
|
255
285
|
|
|
256
|
-
|
|
286
|
+
// node-only branch: re-encoding needs sharp (save 'raw' is the web path)
|
|
287
|
+
const sharp = await importSharp(`save format '${p.sf.format}' re-encoding`)
|
|
288
|
+
const encoded = await sharp(p.bytes)
|
|
257
289
|
.withMetadata()
|
|
258
290
|
.withExif({ IFD0: textChunk })
|
|
259
291
|
// sharp expect quality between 1 and 100
|
|
260
|
-
.toFormat(format, sf.quality ? { quality: Math.round(sf.quality * 100) } : undefined)
|
|
261
|
-
.
|
|
262
|
-
|
|
263
|
-
img = new MediaImage({
|
|
264
|
-
path: asAbsolutePath(absPath),
|
|
265
|
-
execution: this,
|
|
266
|
-
promptNodeID: promptNodeID,
|
|
267
|
-
comfyUIInfos: {
|
|
268
|
-
comfyImageInfo: comfyImageInfo,
|
|
269
|
-
comfyHostHttpURL: this.host.getServerHostHTTP(),
|
|
270
|
-
},
|
|
271
|
-
})
|
|
292
|
+
.toFormat(format, p.sf.quality ? { quality: Math.round(p.sf.quality * 100) } : undefined)
|
|
293
|
+
.toBuffer()
|
|
294
|
+
bytes = new Uint8Array(encoded)
|
|
272
295
|
}
|
|
273
296
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
297
|
+
let absPath: string = comfyts.resolveFromOutput(
|
|
298
|
+
localOutputPath({
|
|
299
|
+
localDir: p.sf.prefix,
|
|
300
|
+
filenamePrefix: p.filenamePrefix,
|
|
301
|
+
subfolder: p.subfolder,
|
|
302
|
+
filename: p.filename,
|
|
303
|
+
timestamp: runTimestamp(new Date(this.startedAt)),
|
|
304
|
+
}),
|
|
305
|
+
)
|
|
306
|
+
if (reencode) absPath += '.' + bang(p.sf.format).split('/')[1]
|
|
307
|
+
// last-resort uniquifier: bump past files on disk AND paths claimed by
|
|
308
|
+
// still-downloading retrievals — never overwrite
|
|
309
|
+
const storage = getComfyStorage()
|
|
310
|
+
absPath = uniquifyOutputPath({ path: absPath, exists: (x) => storage.exists(x), claimed: CLAIMED_OUTPUT_PATHS })
|
|
311
|
+
storage.writeBytes(asAbsolutePath(absPath), bytes)
|
|
312
|
+
return { path: asAbsolutePath(absPath), bytes }
|
|
313
|
+
}
|
|
291
314
|
|
|
292
|
-
|
|
315
|
+
/** accumulate an output on the prompt; tags from node metadata ride along */
|
|
316
|
+
private pushImage(img: MediaImage, promptNodeID: Maybe<string>): void {
|
|
317
|
+
const promptMeta = promptNodeID != null ? this.workflow.data.metadata?.[promptNodeID] : null
|
|
293
318
|
if (promptMeta?.tag) img.tags.push(promptMeta.tag)
|
|
294
319
|
if (promptMeta?.tags) img.tags.push(...promptMeta.tags)
|
|
295
320
|
this.images.push(img)
|
|
296
321
|
}
|
|
297
322
|
|
|
323
|
+
/** true while the currently executing node is a SaveImageWebsocket in the
|
|
324
|
+
* SENT snapshot (the ephemeral rewrite only touches the snapshot, so the
|
|
325
|
+
* live graph may still say SaveImage) — binary frames are then OUTPUTS */
|
|
326
|
+
get wsOutputNodeExecuting(): boolean {
|
|
327
|
+
const uid = this.workflow.currentExecutingNode?.uid
|
|
328
|
+
if (uid == null) return false
|
|
329
|
+
const apiJson = this.snapshot?.apiJson ?? this.workflow.apiJson
|
|
330
|
+
return apiJson[uid]?.class_type === 'SaveImageWebsocket'
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** one binary ws frame = one output image of the executing SaveImageWebsocket
|
|
334
|
+
* node (architecture.md item 14 — the zero-server-disk path) */
|
|
335
|
+
onWsImageOutput = (p: { bytes: Uint8Array; mime: string }): void => {
|
|
336
|
+
const promptNodeID = this.workflow.currentExecutingNode?.uid ?? null
|
|
337
|
+
this.pendingPromises.push(
|
|
338
|
+
this.storeWsImage(p, promptNodeID).catch((e: unknown) => {
|
|
339
|
+
console.error(`🔴 failed to store a SaveImageWebsocket output:`, e)
|
|
340
|
+
this.imageErrors.push({ image: null, error: e })
|
|
341
|
+
}),
|
|
342
|
+
)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
private storeWsImage = async (
|
|
346
|
+
p: { bytes: Uint8Array; mime: string },
|
|
347
|
+
promptNodeID: Maybe<string>,
|
|
348
|
+
): Promise<void> => {
|
|
349
|
+
const sf = this.save
|
|
350
|
+
if (sf == null) {
|
|
351
|
+
return this.pushImage(new MediaImage({ buffer: p.bytes, execution: this, promptNodeID }), promptNodeID)
|
|
352
|
+
}
|
|
353
|
+
const ext = p.mime === 'image/jpeg' ? 'jpg' : (p.mime.split('/')[1] ?? 'png')
|
|
354
|
+
const written = await this.encodeAndWrite({
|
|
355
|
+
bytes: p.bytes,
|
|
356
|
+
sf,
|
|
357
|
+
subfolder: '',
|
|
358
|
+
// ws frames carry no server filename — the workflow id is the stem
|
|
359
|
+
filename: `${this.workflow.id}.${ext}`,
|
|
360
|
+
})
|
|
361
|
+
this.pushImage(
|
|
362
|
+
new MediaImage({ path: written.path, buffer: written.bytes, execution: this, promptNodeID }),
|
|
363
|
+
promptNodeID,
|
|
364
|
+
)
|
|
365
|
+
}
|
|
366
|
+
|
|
298
367
|
/** images retrieved for this execution, in arrival order (final once `done` resolves) */
|
|
299
368
|
images: MediaImage[] = []
|
|
300
369
|
|
|
@@ -311,6 +380,28 @@ export class ComfyExecution {
|
|
|
311
380
|
// finished executions receive no further messages — free the routing maps
|
|
312
381
|
this.host.executions.delete(this.data.id)
|
|
313
382
|
this.host._pendingMsgs.delete(this.data.id)
|
|
383
|
+
|
|
384
|
+
// the inputs gap, stated loud (item 14): ephemeral covers OUTPUTS only —
|
|
385
|
+
// uploaded inputs persist in the server's input/ dir, no upstream delete API
|
|
386
|
+
if (this.ephemeral) {
|
|
387
|
+
const classTypes = Object.values(this.snapshot?.apiJson ?? {}).map((n) => n.class_type)
|
|
388
|
+
if (classTypes.includes('LoadImage') || classTypes.includes('LoadImageMask')) {
|
|
389
|
+
console.warn(
|
|
390
|
+
`🟡 ephemeral run ${this.data.id}: outputs never touched the server disk, but the graph's ` +
|
|
391
|
+
`LoadImage nodes reference files in the host's input/ folder (uploads persist — ComfyUI has ` +
|
|
392
|
+
`no delete API). Use MediaImage.loadInWorkflow_viaBase64Node to keep inputs off the server too.`,
|
|
393
|
+
)
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// history scrub AFTER retrievals: loud but never fatal — a privacy
|
|
398
|
+
// feature that crashes the run would push users to disable it
|
|
399
|
+
if (this.scrubHistory) {
|
|
400
|
+
await this.host.deleteHistory(this.data.id).catch((e: unknown) => {
|
|
401
|
+
console.error(`🔴 failed to scrub history entry ${this.data.id} on host ${this.host.data.id}:`, e)
|
|
402
|
+
})
|
|
403
|
+
}
|
|
404
|
+
|
|
314
405
|
this.finishProgressLine()
|
|
315
406
|
this._resolve(this)
|
|
316
407
|
}
|