From 825d17441cf5531366ad88a4643c4a427ce1a58f Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sun, 29 Jun 2025 12:55:49 +1000 Subject: [PATCH] feat(ui): separate options arg for runGraph --- .../CanvasEntity/CanvasEntityFilterer.ts | 6 ++-- .../konva/CanvasSegmentAnythingModule.ts | 6 ++-- .../konva/CanvasStateApiModule.ts | 15 ++-------- .../web/src/services/api/run-graph.ts | 28 +++++++++++-------- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasEntity/CanvasEntityFilterer.ts b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasEntity/CanvasEntityFilterer.ts index fa9afaa2ae..2308e0d86e 100644 --- a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasEntity/CanvasEntityFilterer.ts +++ b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasEntity/CanvasEntityFilterer.ts @@ -274,8 +274,10 @@ export class CanvasEntityFilterer extends CanvasModuleBase { this.manager.stateApi.runGraphAndReturnImageOutput({ graph, outputNodeId, - prepend: true, - signal: controller.signal, + options: { + prepend: true, + signal: controller.signal, + }, }) ); diff --git a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasSegmentAnythingModule.ts b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasSegmentAnythingModule.ts index e9c217b299..4691bc26eb 100644 --- a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasSegmentAnythingModule.ts +++ b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasSegmentAnythingModule.ts @@ -594,8 +594,10 @@ export class CanvasSegmentAnythingModule extends CanvasModuleBase { this.manager.stateApi.runGraphAndReturnImageOutput({ graph, outputNodeId, - prepend: true, - signal: controller.signal, + options: { + prepend: true, + signal: controller.signal, + }, }) ); diff --git a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasStateApiModule.ts b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasStateApiModule.ts index f03f90fc96..79f5a956f7 100644 --- a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasStateApiModule.ts +++ b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasStateApiModule.ts @@ -53,6 +53,7 @@ import type { Graph } from 'features/nodes/util/graph/generation/Graph'; import { atom, computed } from 'nanostores'; import type { Logger } from 'roarr'; import { getImageDTO } from 'services/api/endpoints/images'; +import type { RunGraphOptions } from 'services/api/run-graph'; import { buildRunGraphDependencies, runGraph } from 'services/api/run-graph'; import type { ImageDTO, S } from 'services/api/types'; import type { Param0 } from 'tsafe'; @@ -267,23 +268,13 @@ export class CanvasStateApiModule extends CanvasModuleBase { runGraphAndReturnImageOutput = async (arg: { graph: Graph; outputNodeId: string; - destination?: string; - prepend?: boolean; - timeout?: number; - signal?: AbortSignal; + options?: RunGraphOptions; }): Promise => { - const { graph, outputNodeId, destination, prepend, timeout, signal } = arg; - const dependencies = buildRunGraphDependencies(this.store, this.manager.socket); const { output } = await runGraph({ - graph, - outputNodeId, dependencies, - destination, - prepend, - timeout, - signal, + ...arg, }); // Extract the image from the result - we expect a single image diff --git a/invokeai/frontend/web/src/services/api/run-graph.ts b/invokeai/frontend/web/src/services/api/run-graph.ts index b110cb8d45..fa533773d5 100644 --- a/invokeai/frontend/web/src/services/api/run-graph.ts +++ b/invokeai/frontend/web/src/services/api/run-graph.ts @@ -53,16 +53,20 @@ type GraphRunnerDependencies = { eventHandler: QueueStatusEventHandler; }; -type RunGraphArg = { - graph: Graph; - outputNodeId: string; - dependencies: GraphRunnerDependencies; +export type RunGraphOptions = { destination?: string; prepend?: boolean; timeout?: number; signal?: AbortSignal; }; +type RunGraphArg = { + graph: Graph; + outputNodeId: string; + dependencies: GraphRunnerDependencies; + options?: RunGraphOptions; +}; + type RunGraphReturn = { session: S['SessionQueueItem']['session']; output: S['GraphExecutionState']['results'][string]; @@ -79,13 +83,14 @@ type RunGraphReturn = { * @param arg.graph The graph to execute as an instance of the Graph class. * @param arg.outputNodeId The id of the node whose output will be retrieved. * @param arg.dependencies The dependencies for queue operations and event handling. - * @param arg.destination The destination to assign to the batch. If omitted, the destination is not set. - * @param arg.prepend Whether to prepend the graph to the front of the queue. If omitted, the graph is appended to the + * @param arg.options Optional parameters for the run: + * @param arg.options.destination The destination to assign to the batch. If omitted, the destination is not set. + * @param arg.options.prepend Whether to prepend the graph to the front of the queue. If omitted, the graph is appended to the * end of the queue. - * @param arg.timeout The timeout for the run in milliseconds. The promise rejects with a SessionTimeoutError when + * @param arg.options.timeout The timeout for the run in milliseconds. The promise rejects with a SessionTimeoutError when * the run times out. If the queue item was enqueued, a best effort is made to cancel it. **If omitted, there is * no timeout and the run will wait indefinitely for completion.** - * @param arg.signal An optional signal to cancel the operation. The promise rejects with a SessionAbortedError when + * @param arg.options.signal An optional signal to cancel the operation. The promise rejects with a SessionAbortedError when * the run is canceled via signal. If the queue item was enqueued, a best effort is made to cancel it. **If omitted, * the run cannot easily be canceled.** * @@ -168,10 +173,11 @@ export const buildRunGraphDependencies = ( */ const _runGraph = async ( arg: RunGraphArg, - _resolve: (value: RunGraphReturn) => void, - _reject: (error: Error) => void + _resolve: Deferred['resolve'], + _reject: Deferred['reject'] ): Promise => { - const { graph, outputNodeId, dependencies, destination, prepend, timeout, signal } = arg; + const { graph, outputNodeId, dependencies, options } = arg; + const { destination, prepend, timeout, signal } = options ?? {}; const loggingCtx: JsonObject = { graphId: graph.id,