diff --git a/src/lib/components/ComfyApp.ts b/src/lib/components/ComfyApp.ts index a711f05..bb10431 100644 --- a/src/lib/components/ComfyApp.ts +++ b/src/lib/components/ComfyApp.ts @@ -40,6 +40,7 @@ import { deserializeTemplateFromSVG, type SerializedComfyBoxTemplate } from "$li import templateState from "$lib/stores/templateState"; import { formatValidationError, type ComfyAPIPromptErrorResponse, formatExecutionError, type ComfyExecutionError } from "$lib/apiErrors"; import systemState from "$lib/stores/systemState"; +import type { JourneyNode } from "$lib/stores/journeyStates"; export const COMFYBOX_SERIAL_VERSION = 1; @@ -610,6 +611,7 @@ export default class ComfyApp { if (node?.onExecuted) { node.onExecuted(output); } + workflow.journey.onExecuted(promptID, nodeID, output, queueEntry); } } }); @@ -1028,6 +1030,15 @@ export default class ComfyApp { notify("Prompt queued.", { type: "info", showOn: "web" }); } + let journeyNode: JourneyNode | null; + + if (get(uiState).autoPushJourney) { + const activeNode = targetWorkflow.journey.getActiveNode(); + if (activeNode != null) { + journeyNode = targetWorkflow.journey.pushPatchOntoActive(targetWorkflow, activeNode); + } + } + this.processingQueue = true; let workflow: ComfyBoxWorkflow; @@ -1097,6 +1108,9 @@ export default class ComfyApp { else { queueState.afterQueued(workflow.id, response.promptID, response.number, p.output, extraData) workflowState.afterQueued(workflow.id, response.promptID) + if (journeyNode != null) { + journeyNode.promptID = response.promptID; + } } } catch (err) { errorMes = err?.toString(); diff --git a/src/lib/components/ComfyJourneyView.svelte b/src/lib/components/ComfyJourneyView.svelte index 69bdabd..6322fb3 100644 --- a/src/lib/components/ComfyJourneyView.svelte +++ b/src/lib/components/ComfyJourneyView.svelte @@ -7,12 +7,14 @@ import type ComfyApp from './ComfyApp'; import type { ComfyBoxWorkflow } from '$lib/stores/workflowState'; import workflowState from '$lib/stores/workflowState'; - import { calculateWorkflowParamsPatch, resolvePatch, type JourneyPatchNode, type WritableJourneyStateStore } from '$lib/stores/journeyStates'; + import uiState from '$lib/stores/uiState'; + import { calculateWorkflowParamsPatch, resolvePatch, type JourneyPatchNode, type WritableJourneyStateStore, diffParams } from '$lib/stores/journeyStates'; import JourneyRenderer from './JourneyRenderer.svelte'; import { Plus } from "svelte-bootstrap-icons"; - import { getWorkflowRestoreParams, getWorkflowRestoreParamsFromWorkflow } from '$lib/restoreParameters'; - import notify from '$lib/notify'; - import selectionState from '$lib/stores/selectionState'; + import { getWorkflowRestoreParams, getWorkflowRestoreParamsFromWorkflow } from '$lib/restoreParameters'; + import notify from '$lib/notify'; + import selectionState from '$lib/stores/selectionState'; + import { Checkbox } from '@gradio/form'; export let app: ComfyApp; @@ -30,32 +32,7 @@ const workflowParams = getWorkflowRestoreParamsFromWorkflow(workflow) const activeNode = journey.getActiveNode(); - - let journeyNode - - if (activeNode == null) { - // add root node - if ($journey.root != null) { - return; - } - journeyNode = journey.addNode(workflowParams, null); - notify("Pushed a new base workflow state.", { type: "info" }) - } - else { - // add patch node - const patch = calculateWorkflowParamsPatch(activeNode, workflowParams); - const patchedCount = Object.keys(patch).length; - if (patchedCount === 0) { - notify("No changes were made to active parameters yet.", { type: "warning" }) - return; - } - journeyNode = journey.addNode(patch, activeNode); - notify(`Pushed new state with ${patchedCount} changes.`, { type: "info" }) - } - - if (journeyNode != null) { - journey.selectNode(journeyNode); - } + journey.pushPatchOntoActive(workflow, activeNode, true) } function onSelectNode(e: CustomEvent<{ cyto: cytoscape.Core, node: cytoscape.NodeSingular }>) { @@ -85,12 +62,11 @@ return; } - if (journeyNode.type === "patch") { - $selectionState.currentPatchHoveredNodes = new Set(Object.keys((journeyNode as JourneyPatchNode).patch)) - } - else { - $selectionState.currentPatchHoveredNodes = new Set(); - } + const patch = resolvePatch(journeyNode); + const workflowParams = getWorkflowRestoreParamsFromWorkflow(workflow); + const diff = diffParams(patch, workflowParams); + + $selectionState.currentPatchHoveredNodes = new Set(Object.keys(diff)); } function onHoverNodeOut(e: CustomEvent<{ cyto: cytoscape.Core, node: cytoscape.NodeSingular }>) { @@ -104,6 +80,9 @@ on:hover_node={onHoverNode} on:hover_node_out={onHoverNodeOut} /> +
+ +