Workflows can receive images from other workflows/historical prompts
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { SerializedGraphCanvasState } from '$lib/ComfyGraphCanvas';
|
||||
import { clamp, LGraphNode, type LGraphCanvas, type NodeID, type SerializedLGraph, type UUID, LGraph, LiteGraph } from '@litegraph-ts/core';
|
||||
import { clamp, LGraphNode, type LGraphCanvas, type NodeID, type SerializedLGraph, type UUID, LGraph, LiteGraph, type SlotType, NodeMode } from '@litegraph-ts/core';
|
||||
import { get, writable } from 'svelte/store';
|
||||
import type { Readable, Writable } from 'svelte/store';
|
||||
import { defaultWorkflowAttributes, type SerializedLayoutState, type WritableLayoutStateStore } from './layoutStates';
|
||||
@@ -9,6 +9,7 @@ import { v4 as uuidv4 } from "uuid";
|
||||
import type ComfyGraphCanvas from '$lib/ComfyGraphCanvas';
|
||||
import { blankGraph } from '$lib/defaultGraph';
|
||||
import type { SerializedAppState } from '$lib/components/ComfyApp';
|
||||
import type ComfyReceiveOutputNode from '$lib/nodes/actions/ComfyReceiveOutputNode';
|
||||
|
||||
type ActiveCanvas = {
|
||||
canvas: LGraphCanvas | null;
|
||||
@@ -232,6 +233,11 @@ export type WorkflowState = {
|
||||
activeWorkflow: ComfyWorkflow | null,
|
||||
}
|
||||
|
||||
export type WorkflowReceiveOutputTargets = {
|
||||
workflow: ComfyWorkflow,
|
||||
targetNodes: ComfyReceiveOutputNode[]
|
||||
}
|
||||
|
||||
type WorkflowStateOps = {
|
||||
getWorkflow: (id: WorkflowInstID) => ComfyWorkflow | null
|
||||
getWorkflowByGraph: (graph: LGraph) => ComfyWorkflow | null
|
||||
@@ -243,7 +249,8 @@ type WorkflowStateOps = {
|
||||
addWorkflow: (canvas: ComfyGraphCanvas, data: ComfyWorkflow) => void,
|
||||
closeWorkflow: (canvas: ComfyGraphCanvas, index: number) => void,
|
||||
closeAllWorkflows: (canvas: ComfyGraphCanvas) => void,
|
||||
setActiveWorkflow: (canvas: ComfyGraphCanvas, index: number) => ComfyWorkflow | null
|
||||
setActiveWorkflow: (canvas: ComfyGraphCanvas, index: number | WorkflowInstID) => ComfyWorkflow | null,
|
||||
findReceiveOutputTargets: (type: SlotType | SlotType[]) => WorkflowReceiveOutputTargets[]
|
||||
}
|
||||
|
||||
export type WritableWorkflowStateStore = Writable<WorkflowState> & WorkflowStateOps;
|
||||
@@ -345,7 +352,7 @@ function closeAllWorkflows(canvas: ComfyGraphCanvas) {
|
||||
closeWorkflow(canvas, 0)
|
||||
}
|
||||
|
||||
function setActiveWorkflow(canvas: ComfyGraphCanvas, index: number): ComfyWorkflow | null {
|
||||
function setActiveWorkflow(canvas: ComfyGraphCanvas, index: number | WorkflowInstID): ComfyWorkflow | null {
|
||||
const state = get(store);
|
||||
|
||||
if (state.openedWorkflows.length === 0) {
|
||||
@@ -354,6 +361,10 @@ function setActiveWorkflow(canvas: ComfyGraphCanvas, index: number): ComfyWorkfl
|
||||
return null;
|
||||
}
|
||||
|
||||
if (typeof index === "string") {
|
||||
index = state.openedWorkflows.findIndex(w => w.id === index)
|
||||
}
|
||||
|
||||
if (index < 0 || index >= state.openedWorkflows.length)
|
||||
return state.activeWorkflow;
|
||||
|
||||
@@ -375,6 +386,31 @@ function setActiveWorkflow(canvas: ComfyGraphCanvas, index: number): ComfyWorkfl
|
||||
return workflow;
|
||||
}
|
||||
|
||||
function findReceiveOutputTargets(type: SlotType | SlotType[]): WorkflowReceiveOutputTargets[] {
|
||||
let result = []
|
||||
|
||||
const state = get(store);
|
||||
|
||||
if (!Array.isArray(type))
|
||||
type = [type]
|
||||
|
||||
const types = new Set(type);
|
||||
|
||||
for (const workflow of state.openedWorkflows) {
|
||||
const targetNodes = workflow.graph
|
||||
// can't use class here because of circular import
|
||||
.findNodesByTypeRecursive("events/receive_output")
|
||||
.filter(n => {
|
||||
return types.has(n.properties.type) && n.mode === NodeMode.ALWAYS
|
||||
})
|
||||
|
||||
if (targetNodes.length > 0)
|
||||
result.push({ workflow, targetNodes });
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const workflowStateStore: WritableWorkflowStateStore =
|
||||
{
|
||||
...store,
|
||||
@@ -389,5 +425,6 @@ const workflowStateStore: WritableWorkflowStateStore =
|
||||
closeWorkflow,
|
||||
closeAllWorkflows,
|
||||
setActiveWorkflow,
|
||||
findReceiveOutputTargets
|
||||
}
|
||||
export default workflowStateStore;
|
||||
|
||||
Reference in New Issue
Block a user