comfy-ts 2.16.0 → 2.17.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 +23 -0
- package/dist/{run-serve-C78hD7t9.js → ServeApp-BSA5yzxZ.js} +17 -444
- package/dist/ServeApp-BSA5yzxZ.js.map +1 -0
- package/dist/cli.js +18 -5
- 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 +146 -59
- 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 +146 -59
- package/dist/index.js.map +1 -1
- package/dist/run-run-DnaMLCFn.js +450 -0
- package/dist/run-run-DnaMLCFn.js.map +1 -0
- package/dist/run-serve-CbKxIu6i.js +418 -0
- package/dist/run-serve-CbKxIu6i.js.map +1 -0
- package/dist/{run-tui-nPETFRmk.js → run-tui-B0AQWbad.js} +6 -37
- package/dist/run-tui-B0AQWbad.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 +37 -37
- package/dist/{state-BMW57_M0.js → state-C2oDiQ26.js} +146 -60
- package/dist/state-C2oDiQ26.js.map +1 -0
- package/dist/web.d.ts +61 -8
- package/dist/web.js +146 -59
- 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 +1 -1
- package/src/cli/comfy-ts-cli.ts +14 -1
- 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/web/components/DraftTabs.tsx +8 -2
- package/src/cli/serve/web/state/draftTabs.ts +12 -0
- package/src/cli/serve/web/state/shortcutCatalog.ts +1 -0
- package/src/coreExports.ts +2 -0
- package/src/host/ComfyHost.ts +73 -40
- package/src/host/previewMethod.ts +29 -0
- 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.0";
|
|
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 = {
|
|
@@ -2341,6 +2377,7 @@ var ComfyExecution = class {
|
|
|
2341
2377
|
this.ephemeral = false;
|
|
2342
2378
|
this.snapshot = null;
|
|
2343
2379
|
this.onProgress = null;
|
|
2380
|
+
this.onPreview = null;
|
|
2344
2381
|
this.logProgress = false;
|
|
2345
2382
|
this.startedAt = Date.now();
|
|
2346
2383
|
this._lastLoggedLine = "";
|
|
@@ -2354,6 +2391,7 @@ var ComfyExecution = class {
|
|
|
2354
2391
|
bytes: msg.bytes,
|
|
2355
2392
|
mime: msg.mime
|
|
2356
2393
|
});
|
|
2394
|
+
else this.onPreviewFrame(msg);
|
|
2357
2395
|
return;
|
|
2358
2396
|
}
|
|
2359
2397
|
if (msg.type === "execution_start") return;
|
|
@@ -2600,6 +2638,7 @@ var ComfyExecution = class {
|
|
|
2600
2638
|
this.scrubHistory = init.scrubHistory ?? false;
|
|
2601
2639
|
this.ephemeral = init.ephemeral ?? false;
|
|
2602
2640
|
this.onProgress = init.onProgress ?? null;
|
|
2641
|
+
this.onPreview = init.onPreview ?? null;
|
|
2603
2642
|
this.logProgress = init.logProgress ?? false;
|
|
2604
2643
|
this.host.executions.set(data.id, this);
|
|
2605
2644
|
this.onCreate();
|
|
@@ -2680,6 +2719,28 @@ var ComfyExecution = class {
|
|
|
2680
2719
|
if (uid == null) return false;
|
|
2681
2720
|
return (this.snapshot?.apiJson ?? this.workflow.apiJson)[uid]?.class_type === "SaveImageWebsocket";
|
|
2682
2721
|
}
|
|
2722
|
+
/** @internal a live preview frame of this run; never an output (the host routes ws saver frames
|
|
2723
|
+
* to onWsImageOutput before they get here) */
|
|
2724
|
+
onPreviewFrame(p) {
|
|
2725
|
+
const listener = this.onPreview;
|
|
2726
|
+
if (listener == null) return;
|
|
2727
|
+
const current = this.workflow.currentExecutingNode;
|
|
2728
|
+
const nodeId = previewMetadataNodeId(p.metadata) ?? current?.uid ?? null;
|
|
2729
|
+
const apiJson = this.snapshot?.apiJson ?? this.workflow.apiJson;
|
|
2730
|
+
const counter = current != null && current.uid === nodeId ? current.progress : null;
|
|
2731
|
+
listener({
|
|
2732
|
+
promptId: this.data.id,
|
|
2733
|
+
bytes: p.bytes,
|
|
2734
|
+
mime: p.mime,
|
|
2735
|
+
nodeId,
|
|
2736
|
+
nodeName: nodeId != null ? apiJson[nodeId]?.class_type ?? null : null,
|
|
2737
|
+
step: counter != null ? {
|
|
2738
|
+
value: counter.value,
|
|
2739
|
+
max: counter.max
|
|
2740
|
+
} : null,
|
|
2741
|
+
metadata: p.metadata
|
|
2742
|
+
});
|
|
2743
|
+
}
|
|
2683
2744
|
/** @internal a live-text frame for one node */
|
|
2684
2745
|
onProgressText(p) {
|
|
2685
2746
|
this.progressTexts.set(p.nodeId, p.text);
|
|
@@ -3019,6 +3080,7 @@ var ComfyWorkflow = class {
|
|
|
3019
3080
|
ephemeral: p.ephemeral ?? false,
|
|
3020
3081
|
scrubHistory: p.scrubHistory ?? p.ephemeral ?? false,
|
|
3021
3082
|
onProgress: p.onProgress,
|
|
3083
|
+
onPreview: p.onPreview,
|
|
3022
3084
|
logProgress: p.log ?? false
|
|
3023
3085
|
});
|
|
3024
3086
|
};
|
|
@@ -5690,7 +5752,8 @@ var DefinedWorkflow = class {
|
|
|
5690
5752
|
scrubHistory: settings.scrubHistory,
|
|
5691
5753
|
idMode: settings.idMode,
|
|
5692
5754
|
log: settings.log,
|
|
5693
|
-
onProgress: settings.onProgress
|
|
5755
|
+
onProgress: settings.onProgress,
|
|
5756
|
+
onPreview: settings.onPreview
|
|
5694
5757
|
});
|
|
5695
5758
|
this.lastExecution = execution;
|
|
5696
5759
|
return execution;
|
|
@@ -5995,6 +6058,11 @@ var ComfyHost = class {
|
|
|
5995
6058
|
this.clearHistory = () => {
|
|
5996
6059
|
return this.postJSON_("/history", { clear: true });
|
|
5997
6060
|
};
|
|
6061
|
+
this.fetchPreviewMethod = async () => {
|
|
6062
|
+
const res = await this.fetch("/system_stats", {});
|
|
6063
|
+
if (!res.ok) throw new Error(`GET /system_stats failed: ${res.status}`);
|
|
6064
|
+
return previewMethodFromSystemStats(await res.json());
|
|
6065
|
+
};
|
|
5998
6066
|
this.fetchRawLogs = async () => {
|
|
5999
6067
|
const res = await this.fetch("/internal/logs/raw", {}, { apiPrefix: false });
|
|
6000
6068
|
if (!res.ok) throw new Error(`GET /internal/logs/raw failed: ${res.status}`);
|
|
@@ -6071,7 +6139,8 @@ var ComfyHost = class {
|
|
|
6071
6139
|
this.executions = /* @__PURE__ */ new Map();
|
|
6072
6140
|
this._pendingMsgs = /* @__PURE__ */ new Map();
|
|
6073
6141
|
this.activePromptID = null;
|
|
6074
|
-
this.
|
|
6142
|
+
this._latentFrame = null;
|
|
6143
|
+
this._latentPreview = null;
|
|
6075
6144
|
this.onLatentPreview = null;
|
|
6076
6145
|
this.onProgressText = null;
|
|
6077
6146
|
this.onStatus = null;
|
|
@@ -6248,42 +6317,60 @@ var ComfyHost = class {
|
|
|
6248
6317
|
}
|
|
6249
6318
|
prompt.onPromptRelatedMessage(msg);
|
|
6250
6319
|
}
|
|
6320
|
+
/** the latent image beeing generated, in case you want to display it. Built on read: a
|
|
6321
|
+
* session that never reads it never decodes a frame nor holds an object url */
|
|
6322
|
+
get latentPreview() {
|
|
6323
|
+
if (this._latentPreview != null || this._latentFrame == null) return this._latentPreview;
|
|
6324
|
+
const frame = parsePreviewFrame(this._latentFrame.data);
|
|
6325
|
+
const blob = new Blob([frame.bytes], { type: frame.mime });
|
|
6326
|
+
this._latentPreview = {
|
|
6327
|
+
blob,
|
|
6328
|
+
url: URL.createObjectURL(blob),
|
|
6329
|
+
receivedAt: this._latentFrame.receivedAt,
|
|
6330
|
+
promptID: this._latentFrame.promptID
|
|
6331
|
+
};
|
|
6332
|
+
return this._latentPreview;
|
|
6333
|
+
}
|
|
6334
|
+
/** a type 1 or 4 frame. Parsed only when someone wants it, in this order (architecture.md,
|
|
6335
|
+
* Live previews): the ws saver's output, the pre-registration buffer, the run's onPreview,
|
|
6336
|
+
* the host hook. Nobody listening = the frame is kept by reference and never copied */
|
|
6337
|
+
onPreviewFrame(data) {
|
|
6338
|
+
let parsed = null;
|
|
6339
|
+
const frame = () => parsed ??= parsePreviewFrame(data);
|
|
6340
|
+
const promptID = this.activePromptID;
|
|
6341
|
+
const activeExec = promptID != null ? this.executions.get(promptID) : null;
|
|
6342
|
+
if (activeExec?.wsOutputNodeExecuting) return activeExec.onWsImageOutput({
|
|
6343
|
+
bytes: frame().bytes,
|
|
6344
|
+
mime: frame().mime
|
|
6345
|
+
});
|
|
6346
|
+
const pending = promptID != null ? this._pendingMsgs.get(promptID) : void 0;
|
|
6347
|
+
if (pending != null) pending.push({
|
|
6348
|
+
type: "binary_preview_frame",
|
|
6349
|
+
bytes: frame().bytes,
|
|
6350
|
+
mime: frame().mime,
|
|
6351
|
+
metadata: frame().metadata
|
|
6352
|
+
});
|
|
6353
|
+
if (this._latentPreview != null) URL.revokeObjectURL(this._latentPreview.url);
|
|
6354
|
+
this._latentPreview = null;
|
|
6355
|
+
this._latentFrame = {
|
|
6356
|
+
data,
|
|
6357
|
+
promptID,
|
|
6358
|
+
receivedAt: Date.now()
|
|
6359
|
+
};
|
|
6360
|
+
if (activeExec?.onPreview != null) activeExec.onPreviewFrame(frame());
|
|
6361
|
+
if (this.onLatentPreview != null) this.onLatentPreview({
|
|
6362
|
+
bytes: frame().bytes,
|
|
6363
|
+
mime: frame().mime,
|
|
6364
|
+
promptID
|
|
6365
|
+
});
|
|
6366
|
+
}
|
|
6251
6367
|
onMessage(e) {
|
|
6252
6368
|
this.lastWsMessageAt = Date.now();
|
|
6253
6369
|
if (this.data.onWsMessageAny) this.data.onWsMessageAny(e);
|
|
6254
6370
|
if (e.data instanceof ArrayBuffer) {
|
|
6371
|
+
if (isPreviewFrameType(binaryFrameType(e.data))) return this.onPreviewFrame(e.data);
|
|
6255
6372
|
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)) {
|
|
6373
|
+
if (frame.kind === "unknown" && !this._unknownBinaryFrameTypes.has(frame.eventType)) {
|
|
6287
6374
|
this._unknownBinaryFrameTypes.add(frame.eventType);
|
|
6288
6375
|
console.error(`🔴 unknown binary ws frame type ${frame.eventType} from host ${this.data.id} — ignored`);
|
|
6289
6376
|
}
|