/**
 * WorkflowPatch — the single mutation channel for workflow editing (plan D17/D19,
 * spec workflow-conversational-editing-spec.md §C).
 *
 * One change protocol for BOTH agent edits and canvas hand-edits: every edit is a list of
 * `WorkflowPatch` ops applied transactionally to a workflow's graph. This module is the
 * deterministic ENGINE half (no gateway, no UI, no LLM):
 *   - applies the 8 ops to a WorkflowDef (+ workflow meta/trigger),
 *   - enforces scoped-edit boundaries (框选批注: ops may only touch the selection subgraph,
 *     D19) at the PROTOCOL level — not a prompt soft-constraint,
 *   - validates the resulting graph through DagScheduler v2's invariants (acyclic minus
 *     loopBack, edge integrity, loop maxIterations) — the spec's "patch 落库前过 validateDag".
 *
 * Transactional + fail-loud (§1.5): a patch is all-or-nothing. The candidate is built on a deep
 * clone; if any op is illegal, references a missing node/edge, breaks scope, or yields an invalid
 * graph, the WHOLE patch is rejected via `PatchError` (carrying `errors` for agent self-correction)
 * and the input is never mutated. No partial application, no silent drop.
 */
import type { WorkflowDef, WorkflowNodeDef, DataEdge } from "./node-schema.js";
import type { TriggerDef } from "./workflow-trigger.js";
export type { TriggerDef } from "./workflow-trigger.js";
/** A workflow trigger (spec §B / plan D7). Registered by the gateway trigger layer. */
/** Workflow-global fields a patch can set (kept separate from the node graph). */
export interface WorkflowMeta {
    name?: string;
    active?: boolean;
    trigger?: TriggerDef | null;
}
/** The full mutable target of a patch: the node graph plus workflow-global meta. */
export interface PatchTarget {
    def: WorkflowDef;
    meta: WorkflowMeta;
}
export type WorkflowPatch = {
    op: "add_node";
    node: WorkflowNodeDef;
} | {
    op: "remove_node";
    nodeId: string;
} | {
    op: "update_params";
    nodeId: string;
    params: Record<string, unknown>;
} | {
    op: "rename_node";
    nodeId: string;
    name: string;
} | {
    op: "add_edge";
    edge: DataEdge;
} | {
    op: "remove_edge";
    edge: {
        from: string;
        to: string;
        fromPort?: string;
    };
} | {
    op: "set_trigger";
    trigger: TriggerDef | null;
} | {
    op: "set_meta";
    meta: {
        name?: string;
        active?: boolean;
    };
} | {
    op: "set_node_options";
    nodeId: string;
    retry?: {
        maxTries: number;
        backoffMs?: number;
    } | null;
    timeoutMs?: number | null;
    onError?: "stop" | "continue" | "errorPort" | null;
} | {
    op: "set_node_ui";
    positions: Record<string, {
        x: number;
        y: number;
    } | null>;
};
/** A patch + concurrency/scope envelope (spec §C). `scope` present ⇒ scoped (框选) edit. */
export interface PatchEnvelope {
    patch: WorkflowPatch[];
    /** Optimistic-concurrency base revision (LWW handled by the store layer). */
    baseRev?: number;
    /** Selected node ids for a scoped edit; given ⇒ ops may only touch the selection subgraph. */
    scope?: string[];
}
export interface ApplyResult {
    target: PatchTarget;
    applied: WorkflowPatch[];
}
/** Thrown when a patch is rejected. `errors` is the ordered list of reasons (for self-correction). */
export declare class PatchError extends Error {
    readonly errors: string[];
    constructor(errors: string[]);
}
/**
 * Apply a patch transactionally. Returns a NEW PatchTarget (input untouched) or throws PatchError.
 * Scope enforcement (when `scope` is set, spec §C):
 *   - update_params / rename_node / remove_node: the node MUST be in scope.
 *   - add_node: allowed; the new node joins the in-scope set for subsequent ops in this patch.
 *   - add_edge / remove_edge: at least ONE endpoint must be in scope (selection-boundary edges).
 *   - set_trigger / set_meta: workflow-global ⇒ rejected under a scoped edit.
 */
export declare function applyPatch(target: PatchTarget, env: PatchEnvelope): ApplyResult;
/**
 * Validate a standalone WorkflowDef against DagScheduler v2's invariants (acyclic minus loopBack,
 * edge integrity, duplicate ids, loop maxIterations + hard cap). Returns a list of human-readable
 * errors; empty ⇒ valid. This is the SAME graph gate `applyPatch` runs, exported so every
 * persistence path (controller create/update) enforces identical invariants — single-track, no
 * write path may bypass validation (D17 "一个 store").
 */
export declare function validateWorkflowDef(def: WorkflowDef): string[];
