import type { WorkflowTaskKind } from "@stigmer/protos/ai/stigmer/agentic/workflow/v1/enum_pb";
import type { TopologyNodeCategory } from "./useWorkflowTopology";
import type { WorkflowGraphModel, WorkflowGraphNode, WorkflowGraphEdge } from "./workflow-graph-model";
/**
 * A reversible mutation on a {@link WorkflowGraphModel}.
 *
 * Commands are the only way to mutate the graph in canvas mode.
 * Each command knows how to apply itself and how to undo itself,
 * enabling a full undo/redo stack without storing model snapshots.
 */
export interface GraphCommand {
    readonly type: string;
    readonly description: string;
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
export declare class AddNodeCommand implements GraphCommand {
    readonly type = "add_node";
    readonly description: string;
    private readonly node;
    private readonly autoEdge;
    /**
     * @param node The node to add.
     * @param autoEdge Optional edge to create alongside the node
     *   (e.g. __start__ -> first task on an empty canvas).
     */
    constructor(node: WorkflowGraphNode, autoEdge?: WorkflowGraphEdge | null);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
export declare class DeleteNodeCommand implements GraphCommand {
    readonly type = "delete_node";
    readonly description: string;
    private readonly nodeId;
    private removedNode;
    private removedEdges;
    constructor(nodeId: string, taskName: string);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
export declare class AddEdgeCommand implements GraphCommand {
    readonly type = "add_edge";
    readonly description: string;
    private readonly edge;
    constructor(edge: WorkflowGraphEdge);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
export declare class DeleteEdgeCommand implements GraphCommand {
    readonly type = "delete_edge";
    readonly description: string;
    private readonly edgeId;
    private removedEdge;
    constructor(edgeId: string);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
interface NodePosition {
    readonly id: string;
    readonly x: number;
    readonly y: number;
}
export declare class MoveNodesCommand implements GraphCommand {
    readonly type = "move_nodes";
    readonly description: string;
    private readonly oldPositions;
    private readonly newPositions;
    constructor(oldPositions: readonly NodePosition[], newPositions: readonly NodePosition[]);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Groups multiple commands into a single undo/redo unit.
 *
 * Applied in order, undone in reverse order.
 */
export declare class CompoundCommand implements GraphCommand {
    readonly type = "compound";
    readonly description: string;
    private readonly commands;
    constructor(description: string, commands: readonly GraphCommand[]);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Updates a single field path within a node's `config` object.
 *
 * Stores the previous value at that path for precise undo.
 * Supports dot-separated paths for nested fields (e.g., "response_schema.type").
 */
export declare class UpdateNodeFieldCommand implements GraphCommand {
    readonly type = "update_node_field";
    readonly description: string;
    private readonly nodeId;
    private readonly fieldPath;
    private readonly newValue;
    private oldValue;
    constructor(nodeId: string, fieldPath: string, newValue: unknown, taskName: string);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Renames a task node, updating its `id`, `taskName`, and all references
 * in edges (source/target) and other nodes' `flow.then` values.
 *
 * Atomic: undo restores all references to the old name.
 */
export declare class RenameNodeCommand implements GraphCommand {
    readonly type = "rename_node";
    readonly description: string;
    private readonly oldName;
    private readonly newName;
    constructor(oldName: string, newName: string);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
    private rename;
}
/** Which meta property is being updated. */
export type NodeMetaField = "export" | "flow";
/**
 * Updates non-config node properties: `export.as` or `flow.then`.
 *
 * Lightweight command for small property mutations that don't touch
 * the task_config object.
 */
export declare class UpdateNodeMetaCommand implements GraphCommand {
    readonly type = "update_node_meta";
    readonly description: string;
    private readonly nodeId;
    private readonly field;
    private readonly newValue;
    private oldValue;
    constructor(nodeId: string, field: NodeMetaField, newValue: string | undefined, taskName: string);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Updates the `sourceHandle` of all edges from a node's old handle ID
 * to a new handle ID. Used when a switch_case case or human_input outcome
 * is renamed (AD-T15-B4: name-based handle IDs).
 */
export declare class MigrateBranchHandleCommand implements GraphCommand {
    readonly type = "migrate_branch_handle";
    readonly description: string;
    private readonly nodeId;
    private readonly oldHandleId;
    private readonly newHandleId;
    constructor(nodeId: string, oldHandleId: string, newHandleId: string);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
    private migrate;
}
/**
 * Duplicates a task node with a new unique name and offset position.
 *
 * Deep-clones the source node's config. Does not duplicate edges — the user
 * connects the duplicate manually. This matches the behavior of n8n and
 * Retool canvas editors where duplicating edges would create ambiguous topology.
 */
export declare class DuplicateNodeCommand implements GraphCommand {
    readonly type = "duplicate_node";
    readonly description: string;
    private readonly sourceNodeId;
    readonly newTaskName: string;
    constructor(sourceNodeId: string, newTaskName: string);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
export declare class AddSwitchCaseCommand implements GraphCommand {
    readonly type = "add_switch_case";
    readonly description: string;
    private readonly switchNodeId;
    private readonly caseName;
    private readonly condition;
    private readonly childNode;
    private readonly childEdge;
    constructor(switchNodeId: string, caseName: string, condition: string, childNode?: WorkflowGraphNode | null, childEdge?: WorkflowGraphEdge | null);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
export declare class AddParallelBranchCommand implements GraphCommand {
    readonly type = "add_parallel_branch";
    readonly description: string;
    private readonly forkNodeId;
    private readonly branchName;
    private readonly childNode;
    private readonly childEdge;
    constructor(forkNodeId: string, branchName: string, childNode?: WorkflowGraphNode | null, childEdge?: WorkflowGraphEdge | null);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
export declare class AddCatchHandlerCommand implements GraphCommand {
    readonly type = "add_catch_handler";
    readonly description: string;
    private readonly tryCatchNodeId;
    private readonly errorType;
    private readonly childNode;
    private readonly childEdge;
    private previousCatch;
    constructor(tryCatchNodeId: string, errorType: string, childNode?: WorkflowGraphNode | null, childEdge?: WorkflowGraphEdge | null);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Removes a case from a switch_case node's `config.cases` array
 * and deletes any associated canvas edge (identified by sourceHandle).
 *
 * @since T09 (Branch Management UX)
 */
export declare class RemoveSwitchCaseCommand implements GraphCommand {
    readonly type = "remove_switch_case";
    readonly description: string;
    private readonly switchNodeId;
    private readonly caseName;
    private removedCase;
    private removedCaseIndex;
    private removedEdges;
    constructor(switchNodeId: string, caseName: string);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Reorders cases in a switch_case node's `config.cases` array.
 *
 * @since T09 (Branch Management UX)
 */
export declare class ReorderSwitchCasesCommand implements GraphCommand {
    readonly type = "reorder_switch_cases";
    readonly description: string;
    private readonly switchNodeId;
    private readonly newOrder;
    private previousOrder;
    constructor(switchNodeId: string, newOrder: readonly string[]);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Removes a branch from a fork node's `config.branches` array.
 * Refuses to execute if it would leave fewer than 2 branches (proto min_items constraint).
 *
 * @since T09 (Branch Management UX)
 */
export declare class RemoveForkBranchCommand implements GraphCommand {
    readonly type = "remove_fork_branch";
    readonly description: string;
    private readonly forkNodeId;
    private readonly branchName;
    private removedBranch;
    private removedIndex;
    constructor(forkNodeId: string, branchName: string);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Reorders branches in a fork node's `config.branches` array.
 *
 * @since T09 (Branch Management UX)
 */
export declare class ReorderForkBranchesCommand implements GraphCommand {
    readonly type = "reorder_fork_branches";
    readonly description: string;
    private readonly forkNodeId;
    private readonly newOrder;
    private previousOrder;
    constructor(forkNodeId: string, newOrder: readonly string[]);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Renames a branch in a fork node's `config.branches` array.
 *
 * @since T09 (Branch Management UX)
 */
export declare class RenameForkBranchCommand implements GraphCommand {
    readonly type = "rename_fork_branch";
    readonly description: string;
    private readonly forkNodeId;
    private readonly oldName;
    private readonly newName;
    constructor(forkNodeId: string, oldName: string, newName: string);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Toggles the `compete` flag on a fork node (race mode vs wait-for-all).
 *
 * @since T09 (Branch Management UX)
 */
export declare class SetForkCompeteCommand implements GraphCommand {
    readonly type = "set_fork_compete";
    readonly description: string;
    private readonly forkNodeId;
    private readonly compete;
    private previousValue;
    constructor(forkNodeId: string, compete: boolean);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Updates catch configuration fields (`as`, `compensate`) on a try_catch node.
 *
 * @since T09 (Branch Management UX)
 */
export declare class UpdateCatchConfigCommand implements GraphCommand {
    readonly type = "update_catch_config";
    readonly description: string;
    private readonly tryCatchNodeId;
    private readonly updates;
    private previousValues;
    private updatedKeys;
    constructor(tryCatchNodeId: string, updates: {
        as?: string;
        compensate?: boolean;
    });
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Removes the catch block from a try_catch node's config.
 *
 * @since T09 (Branch Management UX)
 */
export declare class RemoveCatchBlockCommand implements GraphCommand {
    readonly type = "remove_catch_block";
    readonly description = "Remove catch handler";
    private readonly tryCatchNodeId;
    private previousCatch;
    constructor(tryCatchNodeId: string);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Updates for_each configuration fields on a for_each node.
 *
 * @since T09 (Branch Management UX)
 */
export declare class UpdateForEachConfigCommand implements GraphCommand {
    readonly type = "update_for_each_config";
    readonly description: string;
    private readonly forEachNodeId;
    private readonly updates;
    private previousValues;
    constructor(forEachNodeId: string, updates: Partial<{
        each: string;
        in: string;
        max_parallelism: number;
        batch_size: number;
        on_error: string;
    }>);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Adds a task to a nested `do[]` array within a container node's config.
 * Path format: "branches.0.do" or "try" or "catch.do"
 *
 * @since T09 (Branch Management UX)
 */
export declare class AddNestedTaskCommand implements GraphCommand {
    readonly type = "add_nested_task";
    readonly description: string;
    private readonly containerNodeId;
    private readonly arrayPath;
    private readonly task;
    constructor(containerNodeId: string, arrayPath: string, task: Record<string, unknown>);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Removes a task from a nested `do[]` array at a specific index.
 *
 * @since T09 (Branch Management UX)
 */
export declare class RemoveNestedTaskCommand implements GraphCommand {
    readonly type = "remove_nested_task";
    readonly description: string;
    private readonly containerNodeId;
    private readonly arrayPath;
    private readonly index;
    private removedTask;
    constructor(containerNodeId: string, arrayPath: string, index: number);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Reorders tasks within a nested `do[]` array.
 *
 * @since T09 (Branch Management UX)
 */
export declare class ReorderNestedTasksCommand implements GraphCommand {
    readonly type = "reorder_nested_tasks";
    readonly description = "Reorder nested tasks";
    private readonly containerNodeId;
    private readonly arrayPath;
    private readonly fromIndex;
    private readonly toIndex;
    constructor(containerNodeId: string, arrayPath: string, fromIndex: number, toIndex: number);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
    private reorder;
}
/**
 * Toggles the `disabled` flag on a graph node.
 *
 * Disabled nodes are visually dimmed on the canvas and skipped during
 * execution. The flag round-trips as `x-stigmer-disabled: true` in YAML.
 *
 * @since T10 (Inspector Panel Refactor)
 */
export declare class ToggleNodeDisabledCommand implements GraphCommand {
    readonly type = "toggle_node_disabled";
    readonly description: string;
    private readonly nodeId;
    private previousValue;
    constructor(nodeId: string, taskName: string);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Wraps a single node in a `try_catch` container.
 *
 * Creates a new `try_catch` node that contains the target node in its
 * `try` block and inherits the target node's incoming/outgoing edges.
 *
 * @since T10 (Inspector Panel Refactor)
 */
export declare class WrapInTryCatchCommand implements GraphCommand {
    readonly type = "wrap_in_try_catch";
    readonly description: string;
    private readonly nodeId;
    private readonly tryCatchName;
    private snapshot;
    constructor(nodeId: string, taskName: string, tryCatchName: string);
    apply(model: WorkflowGraphModel): WorkflowGraphModel;
    undo(model: WorkflowGraphModel): WorkflowGraphModel;
}
/**
 * Manages a stack of {@link GraphCommand}s over a {@link WorkflowGraphModel},
 * supporting undo and redo with a bounded history.
 *
 * Pure TypeScript — no React dependencies.
 */
export declare class GraphHistory {
    private model;
    private undoStack;
    private redoStack;
    constructor(initialModel: WorkflowGraphModel);
    get current(): WorkflowGraphModel;
    get canUndo(): boolean;
    get canRedo(): boolean;
    dispatch(command: GraphCommand): WorkflowGraphModel;
    undo(): WorkflowGraphModel;
    redo(): WorkflowGraphModel;
    reset(model: WorkflowGraphModel): void;
}
/** Generates a unique edge ID for new canvas edges. */
export declare function generateEdgeId(): string;
/**
 * Generates a unique task name for a newly dropped task kind.
 *
 * Strategy: `{kind}_{N}` where N is the lowest positive integer
 * that avoids collision with existing task names.
 */
export declare function generateTaskName(kindString: string, existingNames: ReadonlySet<string>): string;
/**
 * Creates a {@link WorkflowGraphNode} for a newly dropped task.
 */
export declare function createTaskNode(taskName: string, kind: WorkflowTaskKind, kindString: string, category: TopologyNodeCategory, position: {
    x: number;
    y: number;
}): WorkflowGraphNode;
/**
 * Returns the set of node IDs that are sentinel (non-deletable) nodes.
 */
export declare function isSentinelNode(nodeId: string): boolean;
export {};
//# sourceMappingURL=graph-commands.d.ts.map