Conversion to standard prompt format
This commit is contained in:
@@ -40,6 +40,7 @@ import { ComfyComboNode } from "$lib/nodes/widgets";
|
||||
import parseA1111, { type A1111ParsedInfotext } from "$lib/parseA1111";
|
||||
import convertA1111ToStdPrompt from "$lib/convertA1111ToStdPrompt";
|
||||
import type { ComfyBoxStdPrompt } from "$lib/ComfyBoxStdPrompt";
|
||||
import ComfyBoxStdPromptSerializer from "./ComfyBoxStdPromptSerializer";
|
||||
|
||||
export const COMFYBOX_SERIAL_VERSION = 1;
|
||||
|
||||
@@ -86,19 +87,21 @@ export type SerializedAppState = {
|
||||
/** [link_origin, link_slot_index] | input_value */
|
||||
export type SerializedPromptInput = [ComfyNodeID, number] | any
|
||||
|
||||
export type SerializedPromptInputs = Record<string, SerializedPromptInput>;
|
||||
|
||||
/*
|
||||
* A single node in the prompt and its input values.
|
||||
*/
|
||||
export type SerializedPromptInputs = {
|
||||
export type SerializedPromptInputsForNode = {
|
||||
/* property name -> value or link */
|
||||
inputs: Record<string, SerializedPromptInput>,
|
||||
inputs: SerializedPromptInputs,
|
||||
class_type: string
|
||||
}
|
||||
|
||||
/*
|
||||
* All nodes in the graph and their input values.
|
||||
*/
|
||||
export type SerializedPromptInputsAll = Record<ComfyNodeID, SerializedPromptInputs>
|
||||
export type SerializedPromptInputsAll = Record<ComfyNodeID, SerializedPromptInputsForNode>
|
||||
|
||||
export type SerializedPrompt = {
|
||||
workflow: SerializedLGraph,
|
||||
@@ -144,10 +147,12 @@ export default class ComfyApp {
|
||||
private queueItems: QueueItem[] = [];
|
||||
private processingQueue: boolean = false;
|
||||
private promptSerializer: ComfyPromptSerializer;
|
||||
private stdPromptSerializer: ComfyBoxStdPromptSerializer;
|
||||
|
||||
constructor() {
|
||||
this.api = new ComfyAPI();
|
||||
this.promptSerializer = new ComfyPromptSerializer();
|
||||
this.stdPromptSerializer = new ComfyBoxStdPromptSerializer();
|
||||
}
|
||||
|
||||
async setup(): Promise<void> {
|
||||
@@ -649,6 +654,9 @@ export default class ComfyApp {
|
||||
console.debug(graphToGraphVis(this.lGraph))
|
||||
console.debug(promptToGraphVis(p))
|
||||
|
||||
const stdPrompt = this.stdPromptSerializer.serialize(p);
|
||||
console.warn("STD", stdPrompt);
|
||||
|
||||
const extraData: ComfyBoxPromptExtraData = {
|
||||
extra_pnginfo: {
|
||||
workflow: p.workflow,
|
||||
|
||||
35
src/lib/components/ComfyBoxStdPromptSerializer.ts
Normal file
35
src/lib/components/ComfyBoxStdPromptSerializer.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { ComfyBoxStdPrompt } from "$lib/ComfyBoxStdPrompt";
|
||||
import type { SerializedPrompt } from "./ComfyApp";
|
||||
import comfyStdPromptConverters from "$lib/comfyStdPromptConverters"
|
||||
|
||||
const COMMIT_HASH: string = "asdf";
|
||||
|
||||
export default class ComfyBoxStdPromptSerializer {
|
||||
serialize(prompt: SerializedPrompt): ComfyBoxStdPrompt {
|
||||
const stdPrompt: ComfyBoxStdPrompt = {
|
||||
version: 1,
|
||||
metadata: {
|
||||
created_with: "ComfyBox",
|
||||
commit_hash: COMMIT_HASH,
|
||||
extra_data: {
|
||||
comfybox: {
|
||||
}
|
||||
}
|
||||
},
|
||||
parameters: {}
|
||||
}
|
||||
|
||||
for (const [nodeID, inputs] of Object.entries(prompt.output)) {
|
||||
const classType = inputs.class_type
|
||||
const converter = comfyStdPromptConverters[classType]
|
||||
if (converter) {
|
||||
converter(stdPrompt, inputs.inputs, nodeID)
|
||||
}
|
||||
else {
|
||||
console.warn("No StdPrompt type converter for comfy class!", classType)
|
||||
}
|
||||
}
|
||||
|
||||
return stdPrompt
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import type ComfyGraph from "$lib/ComfyGraph";
|
||||
import type { ComfyBackendNode } from "$lib/nodes/ComfyBackendNode";
|
||||
import type ComfyGraphNode from "$lib/nodes/ComfyGraphNode";
|
||||
import { GraphInput, GraphOutput, LGraph, LGraphNode, LLink, NodeMode, Subgraph, type SlotIndex } from "@litegraph-ts/core";
|
||||
import type { SerializedPrompt, SerializedPromptInput, SerializedPromptInputs, SerializedPromptInputsAll } from "./ComfyApp";
|
||||
import type { SerializedPrompt, SerializedPromptInput, SerializedPromptInputsForNode, SerializedPromptInputsAll, SerializedPromptInputs } from "./ComfyApp";
|
||||
import type IComfyInputSlot from "$lib/IComfyInputSlot";
|
||||
|
||||
function hasTag(node: LGraphNode, tag: string): boolean {
|
||||
@@ -150,7 +150,7 @@ export class UpstreamNodeLocator {
|
||||
}
|
||||
|
||||
export default class ComfyPromptSerializer {
|
||||
serializeInputValues(node: ComfyBackendNode): Record<string, SerializedPromptInput> {
|
||||
serializeInputValues(node: ComfyBackendNode): SerializedPromptInputs {
|
||||
// Store input values passed by frontend-only nodes
|
||||
if (!node.inputs) {
|
||||
return {}
|
||||
|
||||
Reference in New Issue
Block a user