comfy-ts 2.16.0 → 2.17.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/README.md +23 -0
- package/dist/{run-serve-C78hD7t9.js → ServeApp-qXcQfdgT.js} +18 -445
- package/dist/ServeApp-qXcQfdgT.js.map +1 -0
- package/dist/cli.js +72 -9
- package/dist/cli.js.map +1 -1
- package/dist/exampleAssets-BfWzygoM.js +38 -0
- package/dist/exampleAssets-BfWzygoM.js.map +1 -0
- package/dist/{LogsSt-Ct7Le0S_.js → findDefinedWorkflow-0lG-VTEd.js} +201 -201
- package/dist/findDefinedWorkflow-0lG-VTEd.js.map +1 -0
- package/dist/index.cjs +182 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +61 -8
- package/dist/index.d.ts +61 -8
- package/dist/index.js +182 -69
- package/dist/index.js.map +1 -1
- package/dist/run-run-tg82jUIk.js +450 -0
- package/dist/run-run-tg82jUIk.js.map +1 -0
- package/dist/run-serve-DaXzoVTS.js +464 -0
- package/dist/run-serve-DaXzoVTS.js.map +1 -0
- package/dist/{run-tui-nPETFRmk.js → run-tui-Bw7BA75d.js} +7 -38
- package/dist/run-tui-Bw7BA75d.js.map +1 -0
- package/dist/{schemaDrift-wb5XkrHV.js → schemaDrift-CbsABBuk.js} +3 -2
- package/dist/{schemaDrift-wb5XkrHV.js.map → schemaDrift-CbsABBuk.js.map} +1 -1
- package/dist/serve-web.js +56 -48
- package/dist/{state-BMW57_M0.js → state-zTow5ucI.js} +182 -70
- package/dist/state-zTow5ucI.js.map +1 -0
- package/dist/web.d.ts +61 -8
- package/dist/web.js +182 -69
- package/dist/web.js.map +1 -1
- package/examples/README.md +1 -0
- package/examples/rvion/15-tts-voice-clone.cflow.ts +8 -8
- package/examples/rvion/16-tts-voice-design.cflow.ts +71 -0
- package/guide-for-agents.md +3 -0
- package/package.json +2 -2
- package/src/cli/bunHop.ts +49 -0
- package/src/cli/comfy-ts-cli.ts +18 -5
- package/src/cli/run/findModules.ts +36 -0
- package/src/cli/run/flagValue.ts +61 -0
- package/src/cli/run/outputPaths.ts +41 -0
- package/src/cli/run/pickModule.ts +41 -0
- package/src/cli/run/run-run.ts +250 -0
- package/src/cli/run/runArgs.ts +61 -0
- package/src/cli/run/sidecar.ts +27 -0
- package/src/cli/serve/ServeApp.ts +13 -39
- package/src/cli/serve/run-serve.ts +51 -13
- package/src/cli/serve/web/components/App.tsx +2 -0
- package/src/cli/serve/web/components/DialogLayer.tsx +55 -0
- package/src/cli/serve/web/components/DraftTabs.tsx +16 -5
- package/src/cli/serve/web/components/PromptEnhancer.tsx +15 -9
- package/src/cli/serve/web/components/SideMenu.tsx +16 -8
- package/src/cli/serve/web/state/WebSt.ts +10 -1
- package/src/cli/serve/web/state/dialog.ts +59 -0
- package/src/cli/serve/web/state/draftTabs.ts +12 -0
- package/src/cli/serve/web/state/keptLines.ts +1 -1
- package/src/cli/serve/web/state/shortcutCatalog.ts +1 -0
- package/src/cli/serve/web/styles.ts +8 -0
- package/src/coreExports.ts +2 -0
- package/src/host/ComfyHost.ts +73 -40
- package/src/host/previewMethod.ts +29 -0
- package/src/litegraph/convertFlowToLiteGraphJSON.ts +38 -20
- package/src/promptEnhancers.ts +1 -1
- package/src/runner/ComfyExecution.ts +45 -1
- package/src/runner/ComfyWorkflow.ts +6 -1
- package/src/runner/ComfyWsApi.ts +1 -1
- package/src/runner/wsBinaryFrame.ts +48 -25
- package/src/vars/ComfyVars.ts +3 -0
- package/src/vars/DefinedWorkflow.ts +1 -0
- package/dist/LogsSt-Ct7Le0S_.js.map +0 -1
- package/dist/run-serve-C78hD7t9.js.map +0 -1
- package/dist/run-tui-nPETFRmk.js.map +0 -1
- package/dist/state-BMW57_M0.js.map +0 -1
package/dist/web.d.ts
CHANGED
|
@@ -12283,6 +12283,7 @@ type PendingBinaryFrame = {
|
|
|
12283
12283
|
type: 'binary_preview_frame';
|
|
12284
12284
|
bytes: Uint8Array;
|
|
12285
12285
|
mime: string;
|
|
12286
|
+
metadata: unknown;
|
|
12286
12287
|
};
|
|
12287
12288
|
type PendingWsItem = PromptRelated_WsMsg | PendingBinaryFrame;
|
|
12288
12289
|
type WsMsg = typeof types$1.WsMsg.infer;
|
|
@@ -12759,6 +12760,25 @@ type ExecutionProgress = ProgressReport & {
|
|
|
12759
12760
|
* puts its partial answer here every few tokens */
|
|
12760
12761
|
progressText: string | null;
|
|
12761
12762
|
};
|
|
12763
|
+
/** one live preview frame of a run: the image a sampler is forming, once per step */
|
|
12764
|
+
type ExecutionPreview = {
|
|
12765
|
+
promptId: PromptID;
|
|
12766
|
+
/** the image as ComfyUI encoded it, jpeg or png */
|
|
12767
|
+
bytes: Uint8Array;
|
|
12768
|
+
mime: string;
|
|
12769
|
+
/** the node that sent the frame: the frame's own metadata when it names one (type 4 frames),
|
|
12770
|
+
* else the node executing when it arrived. Null when neither is known */
|
|
12771
|
+
nodeId: ComfyNodeId | null;
|
|
12772
|
+
/** that node's class name in the sent prompt (`KSampler`), null when unknown */
|
|
12773
|
+
nodeName: string | null;
|
|
12774
|
+
/** that node's own counter when the frame arrived (sampler step of total), null when unknown */
|
|
12775
|
+
step: {
|
|
12776
|
+
value: number;
|
|
12777
|
+
max: number;
|
|
12778
|
+
} | null;
|
|
12779
|
+
/** the raw metadata json of a type 4 frame (`node_id`, `prompt_id`, …), null on a type 1 frame */
|
|
12780
|
+
metadata: unknown;
|
|
12781
|
+
};
|
|
12762
12782
|
declare class ComfyExecution {
|
|
12763
12783
|
workflow: ComfyWorkflow;
|
|
12764
12784
|
data: ComfyExecutionData;
|
|
@@ -12769,6 +12789,7 @@ declare class ComfyExecution {
|
|
|
12769
12789
|
scrubHistory?: boolean;
|
|
12770
12790
|
ephemeral?: boolean;
|
|
12771
12791
|
onProgress?: Maybe<(p: ExecutionProgress) => void>;
|
|
12792
|
+
onPreview?: Maybe<(p: ExecutionPreview) => void>;
|
|
12772
12793
|
logProgress?: boolean;
|
|
12773
12794
|
});
|
|
12774
12795
|
/** local disk saving, OPT-IN (architecture.md item 14); null = outputs stay in memory */
|
|
@@ -12781,6 +12802,8 @@ declare class ComfyExecution {
|
|
|
12781
12802
|
snapshot: Maybe<ExecutionSnapshot>;
|
|
12782
12803
|
/** called on every progress-relevant websocket message */
|
|
12783
12804
|
onProgress: Maybe<(p: ExecutionProgress) => void>;
|
|
12805
|
+
/** called on every live preview frame of this run. Null = frames are never decoded for it */
|
|
12806
|
+
onPreview: Maybe<(p: ExecutionPreview) => void>;
|
|
12784
12807
|
/** render a live single-line progress report to the console */
|
|
12785
12808
|
logProgress: boolean;
|
|
12786
12809
|
readonly startedAt: number;
|
|
@@ -12834,6 +12857,13 @@ declare class ComfyExecution {
|
|
|
12834
12857
|
* SENT snapshot (the ephemeral rewrite only touches the snapshot, so the
|
|
12835
12858
|
* live graph may still say SaveImage) — binary frames are then OUTPUTS */
|
|
12836
12859
|
get wsOutputNodeExecuting(): boolean;
|
|
12860
|
+
/** @internal a live preview frame of this run; never an output (the host routes ws saver frames
|
|
12861
|
+
* to onWsImageOutput before they get here) */
|
|
12862
|
+
onPreviewFrame(p: {
|
|
12863
|
+
bytes: Uint8Array;
|
|
12864
|
+
mime: string;
|
|
12865
|
+
metadata: unknown;
|
|
12866
|
+
}): void;
|
|
12837
12867
|
/** one binary ws frame = one output image of the executing SaveImageWebsocket
|
|
12838
12868
|
* node (architecture.md item 14 — the zero-server-disk path) */
|
|
12839
12869
|
onWsImageOutput: (p: {
|
|
@@ -12863,6 +12893,9 @@ declare class ComfyExecution {
|
|
|
12863
12893
|
private _finish;
|
|
12864
12894
|
}
|
|
12865
12895
|
//#endregion
|
|
12896
|
+
//#region src/host/previewMethod.d.ts
|
|
12897
|
+
type PreviewMethod = 'none' | 'auto' | 'latent2rgb' | 'taesd';
|
|
12898
|
+
//#endregion
|
|
12866
12899
|
//#region src/sdk-generator/comfyui-sdk-codegen.d.ts
|
|
12867
12900
|
/**
|
|
12868
12901
|
* convert a host id to the namespace name it gets inside the global `Comfy` namespace
|
|
@@ -16586,6 +16619,9 @@ type MediaVarOpts = {
|
|
|
16586
16619
|
* not what the api accepts) */
|
|
16587
16620
|
extensions?: readonly string[];
|
|
16588
16621
|
label?: string;
|
|
16622
|
+
/** the text var a file's `<name>.txt` sidecar fills, when a driver sets this var from a file
|
|
16623
|
+
* and leaves that one unset: a voice clip's transcript (`comfy-ts run`) */
|
|
16624
|
+
sidecarText?: TextVar;
|
|
16589
16625
|
};
|
|
16590
16626
|
type ImageVarOpts = MediaVarOpts;
|
|
16591
16627
|
type AudioVarOpts = MediaVarOpts;
|
|
@@ -16887,6 +16923,12 @@ declare class ComfyHostAuthError extends Error {
|
|
|
16887
16923
|
hostId: string;
|
|
16888
16924
|
constructor(code: 401 | 402 | 429, hostId: string, message: string);
|
|
16889
16925
|
}
|
|
16926
|
+
type LatentPreview = {
|
|
16927
|
+
promptID: Maybe<PromptID>;
|
|
16928
|
+
receivedAt: number_Timestamp;
|
|
16929
|
+
blob: Blob;
|
|
16930
|
+
url: string;
|
|
16931
|
+
};
|
|
16890
16932
|
declare class ComfyHost<ID extends string = string> {
|
|
16891
16933
|
data: ComfyHostData & {
|
|
16892
16934
|
id: ID;
|
|
@@ -17028,6 +17070,10 @@ declare class ComfyHost<ID extends string = string> {
|
|
|
17028
17070
|
deleteHistory: (promptId: string) => Promise<void>;
|
|
17029
17071
|
/** wipe the server's WHOLE prompt history (every user of that server) */
|
|
17030
17072
|
clearHistory: () => Promise<void>;
|
|
17073
|
+
/** the `--preview-method` this host was launched with, read from `GET /system_stats`.
|
|
17074
|
+
* `'none'` (ComfyUI's default) means no live preview frame will ever arrive; null = the host
|
|
17075
|
+
* does not publish its launch flags (a cloud host), so only a run can tell */
|
|
17076
|
+
fetchPreviewMethod: () => Promise<PreviewMethod | null>;
|
|
17031
17077
|
/** the server's recent console buffer (entries are write CHUNKS, not lines) */
|
|
17032
17078
|
fetchRawLogs: () => Promise<{
|
|
17033
17079
|
entries: LogEntry[];
|
|
@@ -17056,13 +17102,12 @@ declare class ComfyHost<ID extends string = string> {
|
|
|
17056
17102
|
private activePromptID;
|
|
17057
17103
|
/** method to either execute or buffer the incoming message */
|
|
17058
17104
|
routeOrBuffer(prompt_id: PromptID, msg: PromptRelated_WsMsg): void;
|
|
17059
|
-
/** the
|
|
17060
|
-
|
|
17061
|
-
|
|
17062
|
-
|
|
17063
|
-
|
|
17064
|
-
|
|
17065
|
-
}>;
|
|
17105
|
+
/** the last raw preview frame; `latentPreview` decodes it only when read */
|
|
17106
|
+
private _latentFrame;
|
|
17107
|
+
private _latentPreview;
|
|
17108
|
+
/** the latent image beeing generated, in case you want to display it. Built on read: a
|
|
17109
|
+
* session that never reads it never decodes a frame nor holds an object url */
|
|
17110
|
+
get latentPreview(): Maybe<LatentPreview>;
|
|
17066
17111
|
/** byte-level latent-preview hook (e.g. TUI live preview panel) */
|
|
17067
17112
|
onLatentPreview: Maybe<(p: {
|
|
17068
17113
|
bytes: Uint8Array;
|
|
@@ -17097,6 +17142,10 @@ declare class ComfyHost<ID extends string = string> {
|
|
|
17097
17142
|
* sockets keep streaming (a half-open socket receives nothing, so this
|
|
17098
17143
|
* never revives one) */
|
|
17099
17144
|
lastWsMessageAt: number | null;
|
|
17145
|
+
/** a type 1 or 4 frame. Parsed only when someone wants it, in this order (architecture.md,
|
|
17146
|
+
* Live previews): the ws saver's output, the pre-registration buffer, the run's onPreview,
|
|
17147
|
+
* the host hook. Nobody listening = the frame is kept by reference and never copied */
|
|
17148
|
+
private onPreviewFrame;
|
|
17100
17149
|
onMessage(e: WsMessageEvent): void;
|
|
17101
17150
|
}
|
|
17102
17151
|
//#endregion
|
|
@@ -17294,6 +17343,10 @@ type RunSettings = {
|
|
|
17294
17343
|
log?: boolean;
|
|
17295
17344
|
/** called on every progress-relevant websocket message */
|
|
17296
17345
|
onProgress?: (p: ExecutionProgress) => void;
|
|
17346
|
+
/** called on every live preview frame of this run (the image a sampler is forming). Opt in:
|
|
17347
|
+
* without it no frame is decoded for the run. ComfyUI sends frames only when launched with
|
|
17348
|
+
* `--preview-method`, see `host.fetchPreviewMethod()` */
|
|
17349
|
+
onPreview?: (p: ExecutionPreview) => void;
|
|
17297
17350
|
};
|
|
17298
17351
|
/** exactly what was sent to the host for one execution, frozen at send time */
|
|
17299
17352
|
type ExecutionSnapshot = {
|
|
@@ -18091,5 +18144,5 @@ type HostToPanel = {
|
|
|
18091
18144
|
comfyTs: 'get-state';
|
|
18092
18145
|
};
|
|
18093
18146
|
//#endregion
|
|
18094
|
-
export { AbsolutePath, type ActiveLora, type ActiveLoraSource, type AnyChoiceVar, type AnyVar, AudioVar, type AudioVarOpts, BaseNode, BaseNodeFactory, BaseNodeInputs, BaseNodeOutputs, type BoundVars, Branded, type CanonicalGroup, type CanonicalInput, type CanonicalLink, type CanonicalNode, type CanonicalOutput, type CanonicalWidgetValues, type CanonicalWorkflow, type ChoiceSelect, ChoiceVar, type CodegenOptions, type ComfyApiJson, type ComfyApiNodeJson, type ComfyAudioOutput, ComfyExecution, type ComfyExecutionData, type ComfyExecutionStatus, ComfyHost, ComfyHostAuthError, type ComfyHostData, type ComfyHostID, ComfyHostUnreachableError, type ComfyImageName, ComfyManager, ComfyNode, type ComfyNodeId, type ComfyNodeIdMode, type ComfyNodeMetadata, ComfyNodeOutput, type ComfyNodeSchemaJSON, ComfySchema, type ComfySchemaJSON, ComfySdkBase, ComfySdkShape, type ComfyStorage, ComfyTS, type ComfyTextOutput, type ComfyUnionValue, type ComfyUploadImageResult, ComfyUploader, ComfyVar, ComfyVarBase, type ComfyVideoOutput, ComfyWorkflow, ComfyWorkflowBuilder, type ComfyWorkflowData, type ComfyWorkflowID, type ConnectOptions, ConvertibleImageFormat, DEFAULT_AUDIO_EXTENSIONS, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, DEFAULT_STARRED_SIZES, DEFAULT_VIDEO_EXTENSIONS, type DefineWorkflowSpec, DefinedWorkflow, Either, EmptyRecord, type ExecutionProgress, type ExecutionSnapshot, Flavor, FloatVar, HTMLContent, type HostSlotSource, type HostToPanel, ImageVar, ImageVarEmptyError, type ImageVarOpts, IntVar, InvalidPromptError, IsEqual, type LiteGraphJSON, type LmLoraItem, type LoraEntry, type LoraLane, type LoraLanes, type LoraMirror, type LoraNameOf, type LoraRecord, type LoraStrength, type LoraSweep, type LorasHost, type LorasInput, LorasVar, MDContent, Maybe, MediaImage, type MediaImageData, MediaVar, MediaVarEmptyError, type MediaVarOpts, type ModelVarOpts, MultiChoiceVar, type NodeMode, NodeOf, OptionalChoiceVar, type PanelError, type PanelHostAction, type PanelRequest, type PanelResultAction, type PanelState, type PanelToHost, type ParsedHostBase, PartialOmit, type PluginInstallStatus, type PluginSuggestion, type ProgressReport, type PromptID, type PromptInput, type PromptLane, type PromptLanes, type PromptRelated_WsMsg, type PromptTagsOpts, type PromptValue, PromptVar, type PromptVarOpts, type QualifiedNodeKey, RelativePath, type Requirements, ResilientWebSocketClient, Result, ResultFailure, type RunSettings, SD15_SIZE_PRESETS, SaveOptions, SdkForHost, SeedVar, type SizePreset, type SizeValue, SizeVar, type SlotNameOf, type SlotValueOf, Tagged, TextVar, type TextVarOpts, ToggleVar, type VarKind, type VarPreset, type VarPresetSpec, type VarUi, type VarValues, type VarsSpec, VideoVar, type VideoVarOpts, WorkflowConvertError, WorkflowNormalizeError, type WsLike, type WsMessageEvent, type WsMsg, __FAIL, __OK, activeLoras, activePresetLabel, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, clearLoraKeywordOverride, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, number_Timestamp, parseHostBase, parseWorkflowJson, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, sizePresetsFor, toPresetList, v };
|
|
18147
|
+
export { AbsolutePath, type ActiveLora, type ActiveLoraSource, type AnyChoiceVar, type AnyVar, AudioVar, type AudioVarOpts, BaseNode, BaseNodeFactory, BaseNodeInputs, BaseNodeOutputs, type BoundVars, Branded, type CanonicalGroup, type CanonicalInput, type CanonicalLink, type CanonicalNode, type CanonicalOutput, type CanonicalWidgetValues, type CanonicalWorkflow, type ChoiceSelect, ChoiceVar, type CodegenOptions, type ComfyApiJson, type ComfyApiNodeJson, type ComfyAudioOutput, ComfyExecution, type ComfyExecutionData, type ComfyExecutionStatus, ComfyHost, ComfyHostAuthError, type ComfyHostData, type ComfyHostID, ComfyHostUnreachableError, type ComfyImageName, ComfyManager, ComfyNode, type ComfyNodeId, type ComfyNodeIdMode, type ComfyNodeMetadata, ComfyNodeOutput, type ComfyNodeSchemaJSON, ComfySchema, type ComfySchemaJSON, ComfySdkBase, ComfySdkShape, type ComfyStorage, ComfyTS, type ComfyTextOutput, type ComfyUnionValue, type ComfyUploadImageResult, ComfyUploader, ComfyVar, ComfyVarBase, type ComfyVideoOutput, ComfyWorkflow, ComfyWorkflowBuilder, type ComfyWorkflowData, type ComfyWorkflowID, type ConnectOptions, ConvertibleImageFormat, DEFAULT_AUDIO_EXTENSIONS, DEFAULT_IMAGE_EXTENSIONS, DEFAULT_SIZE_PRESETS, DEFAULT_STARRED_SIZES, DEFAULT_VIDEO_EXTENSIONS, type DefineWorkflowSpec, DefinedWorkflow, Either, EmptyRecord, type ExecutionPreview, type ExecutionProgress, type ExecutionSnapshot, Flavor, FloatVar, HTMLContent, type HostSlotSource, type HostToPanel, ImageVar, ImageVarEmptyError, type ImageVarOpts, IntVar, InvalidPromptError, IsEqual, type LiteGraphJSON, type LmLoraItem, type LoraEntry, type LoraLane, type LoraLanes, type LoraMirror, type LoraNameOf, type LoraRecord, type LoraStrength, type LoraSweep, type LorasHost, type LorasInput, LorasVar, MDContent, Maybe, MediaImage, type MediaImageData, MediaVar, MediaVarEmptyError, type MediaVarOpts, type ModelVarOpts, MultiChoiceVar, type NodeMode, NodeOf, OptionalChoiceVar, type PanelError, type PanelHostAction, type PanelRequest, type PanelResultAction, type PanelState, type PanelToHost, type ParsedHostBase, PartialOmit, type PluginInstallStatus, type PluginSuggestion, type PreviewMethod, type ProgressReport, type PromptID, type PromptInput, type PromptLane, type PromptLanes, type PromptRelated_WsMsg, type PromptTagsOpts, type PromptValue, PromptVar, type PromptVarOpts, type QualifiedNodeKey, RelativePath, type Requirements, ResilientWebSocketClient, Result, ResultFailure, type RunSettings, SD15_SIZE_PRESETS, SaveOptions, SdkForHost, SeedVar, type SizePreset, type SizeValue, SizeVar, type SlotNameOf, type SlotValueOf, Tagged, TextVar, type TextVarOpts, ToggleVar, type VarKind, type VarPreset, type VarPresetSpec, type VarUi, type VarValues, type VarsSpec, VideoVar, type VideoVarOpts, WorkflowConvertError, WorkflowNormalizeError, type WsLike, type WsMessageEvent, type WsMsg, __FAIL, __OK, activeLoras, activePresetLabel, asAbsolutePath, asHTMLContent, asMDContent, asRelativePath, auto, auto_, clearLoraKeywordOverride, codegenSDK, convertFlowToLiteGraphJSON, convertLiteGraphToPrompt, createMemoryStorage, getComfyStorage, getLoraDisplayName, getLoraInfo, getLoraKeyword, getLoraPreviewUrl, getLoraTriggerWords, hostIdToNamespace, isLoraKeywordFromMirror, loraKey, loraKeywordFromMirror, loraMatchesFilter, loraSearchNames, loraSearchText, loraTag, normalizeWorkflow, number_Timestamp, parseHostBase, parseWorkflowJson, refreshLoraInfoCacheIfChanged, reloadLoraInfoCache, renderHttpBase, renderWsUrl, resultFailure, resultSuccess, setDefaultComfyStorage, setLoraKeyword, sizePresetsFor, toPresetList, v };
|
|
18095
18148
|
//# sourceMappingURL=web.d.ts.map
|
package/dist/web.js
CHANGED
|
@@ -101,7 +101,7 @@ function getComfyStorage() {
|
|
|
101
101
|
}
|
|
102
102
|
//#endregion
|
|
103
103
|
//#region package.json
|
|
104
|
-
var version = "2.
|
|
104
|
+
var version = "2.17.1";
|
|
105
105
|
//#endregion
|
|
106
106
|
//#region src/litegraph/LiteGraphLinkID.ts
|
|
107
107
|
const asLiteGraphLinkID = (id) => id;
|
|
@@ -651,21 +651,41 @@ const normalizeGroup = (g) => {
|
|
|
651
651
|
};
|
|
652
652
|
};
|
|
653
653
|
//#endregion
|
|
654
|
-
//#region src/
|
|
655
|
-
function
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
654
|
+
//#region src/host/previewMethod.ts
|
|
655
|
+
function isPreviewMethod(x) {
|
|
656
|
+
return x === "none" || x === "auto" || x === "latent2rgb" || x === "taesd";
|
|
657
|
+
}
|
|
658
|
+
/** the preview method a host was launched with, from its /system_stats payload. `'none'` when
|
|
659
|
+
* the flag is absent (ComfyUI's default), null when the payload carries no argv to read (a cloud
|
|
660
|
+
* host) or the flag holds a value this parser does not know */
|
|
661
|
+
function previewMethodFromSystemStats(stats) {
|
|
662
|
+
if (stats == null || typeof stats !== "object" || !("system" in stats)) return null;
|
|
663
|
+
const system = stats.system;
|
|
664
|
+
if (system == null || typeof system !== "object" || !("argv" in system)) return null;
|
|
665
|
+
const argv = system.argv;
|
|
666
|
+
if (!Array.isArray(argv)) return null;
|
|
667
|
+
for (let i = 0; i < argv.length; i++) {
|
|
668
|
+
const arg = argv[i];
|
|
669
|
+
if (typeof arg !== "string") continue;
|
|
670
|
+
const value = arg === "--preview-method" ? argv[i + 1] : arg.startsWith("--preview-method=") ? arg.slice(17) : void 0;
|
|
671
|
+
if (value === void 0) continue;
|
|
672
|
+
return isPreviewMethod(value) ? value : null;
|
|
666
673
|
}
|
|
674
|
+
return "none";
|
|
675
|
+
}
|
|
676
|
+
/** the frame's event type, read in place: deciding whether anyone wants a frame costs no copy */
|
|
677
|
+
function binaryFrameType(data) {
|
|
678
|
+
if (data.byteLength < 4) return -1;
|
|
679
|
+
return new DataView(data).getUint32(0);
|
|
680
|
+
}
|
|
681
|
+
function isPreviewFrameType(eventType) {
|
|
682
|
+
return eventType === 1 || eventType === 4;
|
|
683
|
+
}
|
|
684
|
+
function parseBinaryWsFrame(data) {
|
|
685
|
+
const eventType = binaryFrameType(data);
|
|
686
|
+
if (isPreviewFrameType(eventType)) return parsePreviewFrame(data);
|
|
667
687
|
if (eventType === 3) {
|
|
668
|
-
const nodeIdLen =
|
|
688
|
+
const nodeIdLen = new DataView(data).getUint32(4);
|
|
669
689
|
const decoder = new TextDecoder();
|
|
670
690
|
return {
|
|
671
691
|
kind: "text",
|
|
@@ -673,25 +693,41 @@ function parseBinaryWsFrame(data) {
|
|
|
673
693
|
text: decoder.decode(data.slice(8 + nodeIdLen))
|
|
674
694
|
};
|
|
675
695
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
696
|
+
return {
|
|
697
|
+
kind: "unknown",
|
|
698
|
+
eventType
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
/** a type 1 or type 4 frame; the caller checked the type with `isPreviewFrameType` */
|
|
702
|
+
function parsePreviewFrame(data) {
|
|
703
|
+
const view = new DataView(data);
|
|
704
|
+
if (view.getUint32(0) === 1) {
|
|
705
|
+
const imageType = view.getUint32(4);
|
|
683
706
|
return {
|
|
684
707
|
kind: "preview",
|
|
685
|
-
bytes,
|
|
686
|
-
mime:
|
|
687
|
-
metadata
|
|
708
|
+
bytes: new Uint8Array(data.slice(8)),
|
|
709
|
+
mime: imageType === 2 ? "image/png" : "image/jpeg",
|
|
710
|
+
metadata: null
|
|
688
711
|
};
|
|
689
712
|
}
|
|
713
|
+
const metadataLen = view.getUint32(4);
|
|
714
|
+
let metadata = null;
|
|
715
|
+
try {
|
|
716
|
+
metadata = JSON.parse(new TextDecoder().decode(data.slice(8, 8 + metadataLen)));
|
|
717
|
+
} catch {}
|
|
718
|
+
const bytes = new Uint8Array(data.slice(8 + metadataLen));
|
|
690
719
|
return {
|
|
691
|
-
kind: "
|
|
692
|
-
|
|
720
|
+
kind: "preview",
|
|
721
|
+
bytes,
|
|
722
|
+
mime: bytes[0] === 137 && bytes[1] === 80 ? "image/png" : "image/jpeg",
|
|
723
|
+
metadata
|
|
693
724
|
};
|
|
694
725
|
}
|
|
726
|
+
/** the node a type 4 frame names (`node_id` in its metadata), null when absent or malformed */
|
|
727
|
+
function previewMetadataNodeId(metadata) {
|
|
728
|
+
if (metadata == null || typeof metadata !== "object" || !("node_id" in metadata)) return null;
|
|
729
|
+
return typeof metadata.node_id === "string" && metadata.node_id !== "" ? metadata.node_id : null;
|
|
730
|
+
}
|
|
695
731
|
//#endregion
|
|
696
732
|
//#region src/sdk-generator/Primitives.ts
|
|
697
733
|
const ComfyPrimitiveMapping = {
|
|
@@ -1668,20 +1704,40 @@ const convertFlowToLiteGraphJSON = (graph) => {
|
|
|
1668
1704
|
const convertNodeToLiteGraphNode = (ctx, node) => {
|
|
1669
1705
|
const inputs = [];
|
|
1670
1706
|
const widgets_values = [];
|
|
1707
|
+
const pushLinked = (name, type, link, shape) => {
|
|
1708
|
+
const nodeUidNumber = bang(ctx.graph.nodes.find((n) => n.uid === link[0])?.uidNumber, `link target node "${link[0]}" not found in graph`);
|
|
1709
|
+
const linkId = ctx.allocateLink(nodeUidNumber, link[1], node.uidNumber, asLiteGraphSlotIndex(inputs.length), type);
|
|
1710
|
+
inputs.push(shape == null ? {
|
|
1711
|
+
name,
|
|
1712
|
+
type,
|
|
1713
|
+
link: linkId
|
|
1714
|
+
} : {
|
|
1715
|
+
name,
|
|
1716
|
+
type,
|
|
1717
|
+
shape,
|
|
1718
|
+
link: linkId
|
|
1719
|
+
});
|
|
1720
|
+
};
|
|
1671
1721
|
for (const ipt of node.$schema.inputs) {
|
|
1672
|
-
const raw = node.serializeValue(ipt.nameInComfy, node.json.inputs[ipt.nameInComfy]);
|
|
1673
1722
|
const kind = classifySchemaInput(ipt);
|
|
1674
|
-
if (
|
|
1675
|
-
const
|
|
1676
|
-
|
|
1677
|
-
name
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1723
|
+
if (kind.kind === "dynamic-container") {
|
|
1724
|
+
const type = containerInstanceSlotType(ipt.opts) ?? "*";
|
|
1725
|
+
for (const instance of kind.instanceNames) {
|
|
1726
|
+
const name = `${ipt.nameInComfy}.${instance}`;
|
|
1727
|
+
const value = node.json.inputs[name];
|
|
1728
|
+
if (value == null) continue;
|
|
1729
|
+
const raw = node.serializeValue(name, value);
|
|
1730
|
+
if (!_isLink(raw)) throw new Error(`🔴 [toWorkflowJson] ${node.$schema.nameInComfy}#${node.uid} "${name}" holds a literal; an autogrow instance is a link slot in the editor`);
|
|
1731
|
+
pushLinked(name, type, raw, 7);
|
|
1732
|
+
}
|
|
1733
|
+
continue;
|
|
1734
|
+
}
|
|
1735
|
+
const raw = node.serializeValue(ipt.nameInComfy, node.json.inputs[ipt.nameInComfy]);
|
|
1736
|
+
if (_isLink(raw)) pushLinked(ipt.nameInComfy, ipt.typeName, raw);
|
|
1737
|
+
else if (kind.kind === "widget") {
|
|
1682
1738
|
widgets_values.push(...kind.prefixValues, raw);
|
|
1683
1739
|
const phantoms = kind.consumes - 1 - kind.prefixValues.length;
|
|
1684
|
-
for (let i = 0; i < phantoms; i++) widgets_values.push(
|
|
1740
|
+
for (let i = 0; i < phantoms; i++) widgets_values.push(controlMode(ipt.opts));
|
|
1685
1741
|
} else inputs.push({
|
|
1686
1742
|
name: ipt.nameInComfy,
|
|
1687
1743
|
type: ipt.typeName,
|
|
@@ -1704,6 +1760,12 @@ const convertNodeToLiteGraphNode = (ctx, node) => {
|
|
|
1704
1760
|
widgets_values
|
|
1705
1761
|
};
|
|
1706
1762
|
};
|
|
1763
|
+
/** the editor's control widget is a combo (fixed, increment, decrement, randomize):
|
|
1764
|
+
* a config naming a mode keeps it, anything else is `fixed`, the seed the code pinned */
|
|
1765
|
+
const controlMode = (opts) => {
|
|
1766
|
+
const mode = typeof opts === "object" && opts != null ? Reflect.get(opts, "control_after_generate") : null;
|
|
1767
|
+
return typeof mode === "string" ? mode : "fixed";
|
|
1768
|
+
};
|
|
1707
1769
|
const _isLink = (v) => {
|
|
1708
1770
|
return Array.isArray(v) && v.length === 2 && typeof v[0] === "string" && typeof v[1] === "number";
|
|
1709
1771
|
};
|
|
@@ -2341,6 +2403,7 @@ var ComfyExecution = class {
|
|
|
2341
2403
|
this.ephemeral = false;
|
|
2342
2404
|
this.snapshot = null;
|
|
2343
2405
|
this.onProgress = null;
|
|
2406
|
+
this.onPreview = null;
|
|
2344
2407
|
this.logProgress = false;
|
|
2345
2408
|
this.startedAt = Date.now();
|
|
2346
2409
|
this._lastLoggedLine = "";
|
|
@@ -2354,6 +2417,7 @@ var ComfyExecution = class {
|
|
|
2354
2417
|
bytes: msg.bytes,
|
|
2355
2418
|
mime: msg.mime
|
|
2356
2419
|
});
|
|
2420
|
+
else this.onPreviewFrame(msg);
|
|
2357
2421
|
return;
|
|
2358
2422
|
}
|
|
2359
2423
|
if (msg.type === "execution_start") return;
|
|
@@ -2600,6 +2664,7 @@ var ComfyExecution = class {
|
|
|
2600
2664
|
this.scrubHistory = init.scrubHistory ?? false;
|
|
2601
2665
|
this.ephemeral = init.ephemeral ?? false;
|
|
2602
2666
|
this.onProgress = init.onProgress ?? null;
|
|
2667
|
+
this.onPreview = init.onPreview ?? null;
|
|
2603
2668
|
this.logProgress = init.logProgress ?? false;
|
|
2604
2669
|
this.host.executions.set(data.id, this);
|
|
2605
2670
|
this.onCreate();
|
|
@@ -2680,6 +2745,28 @@ var ComfyExecution = class {
|
|
|
2680
2745
|
if (uid == null) return false;
|
|
2681
2746
|
return (this.snapshot?.apiJson ?? this.workflow.apiJson)[uid]?.class_type === "SaveImageWebsocket";
|
|
2682
2747
|
}
|
|
2748
|
+
/** @internal a live preview frame of this run; never an output (the host routes ws saver frames
|
|
2749
|
+
* to onWsImageOutput before they get here) */
|
|
2750
|
+
onPreviewFrame(p) {
|
|
2751
|
+
const listener = this.onPreview;
|
|
2752
|
+
if (listener == null) return;
|
|
2753
|
+
const current = this.workflow.currentExecutingNode;
|
|
2754
|
+
const nodeId = previewMetadataNodeId(p.metadata) ?? current?.uid ?? null;
|
|
2755
|
+
const apiJson = this.snapshot?.apiJson ?? this.workflow.apiJson;
|
|
2756
|
+
const counter = current != null && current.uid === nodeId ? current.progress : null;
|
|
2757
|
+
listener({
|
|
2758
|
+
promptId: this.data.id,
|
|
2759
|
+
bytes: p.bytes,
|
|
2760
|
+
mime: p.mime,
|
|
2761
|
+
nodeId,
|
|
2762
|
+
nodeName: nodeId != null ? apiJson[nodeId]?.class_type ?? null : null,
|
|
2763
|
+
step: counter != null ? {
|
|
2764
|
+
value: counter.value,
|
|
2765
|
+
max: counter.max
|
|
2766
|
+
} : null,
|
|
2767
|
+
metadata: p.metadata
|
|
2768
|
+
});
|
|
2769
|
+
}
|
|
2683
2770
|
/** @internal a live-text frame for one node */
|
|
2684
2771
|
onProgressText(p) {
|
|
2685
2772
|
this.progressTexts.set(p.nodeId, p.text);
|
|
@@ -3019,6 +3106,7 @@ var ComfyWorkflow = class {
|
|
|
3019
3106
|
ephemeral: p.ephemeral ?? false,
|
|
3020
3107
|
scrubHistory: p.scrubHistory ?? p.ephemeral ?? false,
|
|
3021
3108
|
onProgress: p.onProgress,
|
|
3109
|
+
onPreview: p.onPreview,
|
|
3022
3110
|
logProgress: p.log ?? false
|
|
3023
3111
|
});
|
|
3024
3112
|
};
|
|
@@ -5690,7 +5778,8 @@ var DefinedWorkflow = class {
|
|
|
5690
5778
|
scrubHistory: settings.scrubHistory,
|
|
5691
5779
|
idMode: settings.idMode,
|
|
5692
5780
|
log: settings.log,
|
|
5693
|
-
onProgress: settings.onProgress
|
|
5781
|
+
onProgress: settings.onProgress,
|
|
5782
|
+
onPreview: settings.onPreview
|
|
5694
5783
|
});
|
|
5695
5784
|
this.lastExecution = execution;
|
|
5696
5785
|
return execution;
|
|
@@ -5995,6 +6084,11 @@ var ComfyHost = class {
|
|
|
5995
6084
|
this.clearHistory = () => {
|
|
5996
6085
|
return this.postJSON_("/history", { clear: true });
|
|
5997
6086
|
};
|
|
6087
|
+
this.fetchPreviewMethod = async () => {
|
|
6088
|
+
const res = await this.fetch("/system_stats", {});
|
|
6089
|
+
if (!res.ok) throw new Error(`GET /system_stats failed: ${res.status}`);
|
|
6090
|
+
return previewMethodFromSystemStats(await res.json());
|
|
6091
|
+
};
|
|
5998
6092
|
this.fetchRawLogs = async () => {
|
|
5999
6093
|
const res = await this.fetch("/internal/logs/raw", {}, { apiPrefix: false });
|
|
6000
6094
|
if (!res.ok) throw new Error(`GET /internal/logs/raw failed: ${res.status}`);
|
|
@@ -6071,7 +6165,8 @@ var ComfyHost = class {
|
|
|
6071
6165
|
this.executions = /* @__PURE__ */ new Map();
|
|
6072
6166
|
this._pendingMsgs = /* @__PURE__ */ new Map();
|
|
6073
6167
|
this.activePromptID = null;
|
|
6074
|
-
this.
|
|
6168
|
+
this._latentFrame = null;
|
|
6169
|
+
this._latentPreview = null;
|
|
6075
6170
|
this.onLatentPreview = null;
|
|
6076
6171
|
this.onProgressText = null;
|
|
6077
6172
|
this.onStatus = null;
|
|
@@ -6248,42 +6343,60 @@ var ComfyHost = class {
|
|
|
6248
6343
|
}
|
|
6249
6344
|
prompt.onPromptRelatedMessage(msg);
|
|
6250
6345
|
}
|
|
6346
|
+
/** the latent image beeing generated, in case you want to display it. Built on read: a
|
|
6347
|
+
* session that never reads it never decodes a frame nor holds an object url */
|
|
6348
|
+
get latentPreview() {
|
|
6349
|
+
if (this._latentPreview != null || this._latentFrame == null) return this._latentPreview;
|
|
6350
|
+
const frame = parsePreviewFrame(this._latentFrame.data);
|
|
6351
|
+
const blob = new Blob([frame.bytes], { type: frame.mime });
|
|
6352
|
+
this._latentPreview = {
|
|
6353
|
+
blob,
|
|
6354
|
+
url: URL.createObjectURL(blob),
|
|
6355
|
+
receivedAt: this._latentFrame.receivedAt,
|
|
6356
|
+
promptID: this._latentFrame.promptID
|
|
6357
|
+
};
|
|
6358
|
+
return this._latentPreview;
|
|
6359
|
+
}
|
|
6360
|
+
/** a type 1 or 4 frame. Parsed only when someone wants it, in this order (architecture.md,
|
|
6361
|
+
* Live previews): the ws saver's output, the pre-registration buffer, the run's onPreview,
|
|
6362
|
+
* the host hook. Nobody listening = the frame is kept by reference and never copied */
|
|
6363
|
+
onPreviewFrame(data) {
|
|
6364
|
+
let parsed = null;
|
|
6365
|
+
const frame = () => parsed ??= parsePreviewFrame(data);
|
|
6366
|
+
const promptID = this.activePromptID;
|
|
6367
|
+
const activeExec = promptID != null ? this.executions.get(promptID) : null;
|
|
6368
|
+
if (activeExec?.wsOutputNodeExecuting) return activeExec.onWsImageOutput({
|
|
6369
|
+
bytes: frame().bytes,
|
|
6370
|
+
mime: frame().mime
|
|
6371
|
+
});
|
|
6372
|
+
const pending = promptID != null ? this._pendingMsgs.get(promptID) : void 0;
|
|
6373
|
+
if (pending != null) pending.push({
|
|
6374
|
+
type: "binary_preview_frame",
|
|
6375
|
+
bytes: frame().bytes,
|
|
6376
|
+
mime: frame().mime,
|
|
6377
|
+
metadata: frame().metadata
|
|
6378
|
+
});
|
|
6379
|
+
if (this._latentPreview != null) URL.revokeObjectURL(this._latentPreview.url);
|
|
6380
|
+
this._latentPreview = null;
|
|
6381
|
+
this._latentFrame = {
|
|
6382
|
+
data,
|
|
6383
|
+
promptID,
|
|
6384
|
+
receivedAt: Date.now()
|
|
6385
|
+
};
|
|
6386
|
+
if (activeExec?.onPreview != null) activeExec.onPreviewFrame(frame());
|
|
6387
|
+
if (this.onLatentPreview != null) this.onLatentPreview({
|
|
6388
|
+
bytes: frame().bytes,
|
|
6389
|
+
mime: frame().mime,
|
|
6390
|
+
promptID
|
|
6391
|
+
});
|
|
6392
|
+
}
|
|
6251
6393
|
onMessage(e) {
|
|
6252
6394
|
this.lastWsMessageAt = Date.now();
|
|
6253
6395
|
if (this.data.onWsMessageAny) this.data.onWsMessageAny(e);
|
|
6254
6396
|
if (e.data instanceof ArrayBuffer) {
|
|
6397
|
+
if (isPreviewFrameType(binaryFrameType(e.data))) return this.onPreviewFrame(e.data);
|
|
6255
6398
|
const frame = parseBinaryWsFrame(e.data);
|
|
6256
|
-
if (frame.kind === "
|
|
6257
|
-
const activeExec = this.activePromptID != null ? this.executions.get(this.activePromptID) : null;
|
|
6258
|
-
if (activeExec?.wsOutputNodeExecuting) {
|
|
6259
|
-
activeExec.onWsImageOutput({
|
|
6260
|
-
bytes: frame.bytes,
|
|
6261
|
-
mime: frame.mime
|
|
6262
|
-
});
|
|
6263
|
-
return;
|
|
6264
|
-
}
|
|
6265
|
-
if (this.activePromptID != null) {
|
|
6266
|
-
const pending = this._pendingMsgs.get(this.activePromptID);
|
|
6267
|
-
if (pending != null) pending.push({
|
|
6268
|
-
type: "binary_preview_frame",
|
|
6269
|
-
bytes: frame.bytes,
|
|
6270
|
-
mime: frame.mime
|
|
6271
|
-
});
|
|
6272
|
-
}
|
|
6273
|
-
if (this.latentPreview != null) URL.revokeObjectURL(this.latentPreview.url);
|
|
6274
|
-
const imageBlob = new Blob([frame.bytes], { type: frame.mime });
|
|
6275
|
-
this.latentPreview = {
|
|
6276
|
-
blob: imageBlob,
|
|
6277
|
-
url: URL.createObjectURL(imageBlob),
|
|
6278
|
-
receivedAt: Date.now(),
|
|
6279
|
-
promptID: this.activePromptID
|
|
6280
|
-
};
|
|
6281
|
-
this.onLatentPreview?.({
|
|
6282
|
-
bytes: frame.bytes,
|
|
6283
|
-
mime: frame.mime,
|
|
6284
|
-
promptID: this.activePromptID
|
|
6285
|
-
});
|
|
6286
|
-
} else if (frame.kind === "unknown" && !this._unknownBinaryFrameTypes.has(frame.eventType)) {
|
|
6399
|
+
if (frame.kind === "unknown" && !this._unknownBinaryFrameTypes.has(frame.eventType)) {
|
|
6287
6400
|
this._unknownBinaryFrameTypes.add(frame.eventType);
|
|
6288
6401
|
console.error(`🔴 unknown binary ws frame type ${frame.eventType} from host ${this.data.id} — ignored`);
|
|
6289
6402
|
}
|