feat(ui): separate options arg for runGraph

This commit is contained in:
psychedelicious
2025-06-29 12:55:49 +10:00
parent 9b16504af9
commit 825d17441c
4 changed files with 28 additions and 27 deletions

View File

@@ -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,
},
})
);

View File

@@ -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,
},
})
);

View File

@@ -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<ImageDTO> => {
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

View File

@@ -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<RunGraphReturn>['resolve'],
_reject: Deferred<RunGraphReturn>['reject']
): Promise<void> => {
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,