/**
 * Workflow mode handlers — ACP surface for the automation workflow engine (plan M2 接入).
 * Exposes workflow.create/get/describe/patch/run/setActive/list/delete over the same RPC host
 * as product/solo. The engine (WorkflowController) lives in qlogicagent (D12); triggers live in
 * the gateway (D7/B) and drive `workflow.run` over ACP.
 *
 * fail-loud throughout (plan §1.5): unknown id / illegal patch / missing capability all throw.
 */
import { AgentProcessManager } from "../../runtime/infra/agent-process.js";
import type { AcpDetector } from "../../runtime/infra/acp-detector.js";
import { type AgentRpcError, type AgentRpcRequest } from "../../protocol/wire/index.js";
import { WorkflowController } from "../../orchestration/workflow/workflow-controller.js";
import { WorkflowStore, type WorkflowRecord } from "../../orchestration/workflow/workflow-store.js";
import { WorkflowRunHistoryStore } from "../../orchestration/workflow/run-history-store.js";
import { WorkflowScheduler } from "../../orchestration/workflow/workflow-scheduler.js";
import { WorkflowAuditStore } from "../../orchestration/workflow/workflow-audit-store.js";
import type { ToolCatalog } from "../../runtime/ports/index.js";
/**
 * One fully-wired engine root. The workflow store is project-scoped on disk
 * (`<project>/.qlogicagent/workflows/`), and "every automation = its own project" (spec D21)
 * means the engine must serve the active project root AND every type:"automation" project
 * root at once — so the singleton controller became this per-root bundle (multi-root,单轨).
 */
export interface WorkflowRootBundle {
    cwd: string;
    /** The owning project id (undefined only when the active root has no registered project). */
    projectId?: string;
    store: WorkflowStore;
    controller: WorkflowController;
    scheduler: WorkflowScheduler;
    runHistory: WorkflowRunHistoryStore;
    /** D38 audit trail (config/lifecycle changes; runs live in runHistory). */
    audit: WorkflowAuditStore;
    pm: AgentProcessManager;
}
export interface WorkflowCoordinatorHost {
    acpDetector: AcpDetector;
    getActiveProjectRoot(): string;
    handleMcpToolCall(memberId: string, tool: string, args: Record<string, unknown>): Promise<unknown>;
    sendNotification(method: string, params: Record<string, unknown>): void;
    toolCatalog: ToolCatalog;
    /** Per-root engine bundles keyed by resolved cwd; built lazily by ensureWorkflowRoot. */
    workflowRoots: Map<string, WorkflowRootBundle> | null;
}
export interface WorkflowHandlerHost extends WorkflowCoordinatorHost {
    sendResponse(id: string | number, result?: unknown, error?: AgentRpcError): void;
    /** Community hub access for workflow.publishHub (same injection seam as CommunityHandlerHost). */
    resolveCommunityConsentClient?: () => import("../../runtime/community/community-consent-client.js").CommunityConsentClient | null;
    resolveCommunityConsentStore?: () => import("./community-handler.js").CommunityConsentStore;
}
/** A resolved workflow routing target: which project root an RPC operates on. */
interface WorkflowTarget {
    cwd: string;
    projectId?: string;
}
/** Build (or fetch) the engine bundle for one project root, wired to real capabilities (§1.5). */
export declare function ensureWorkflowRoot(this: WorkflowCoordinatorHost, target: WorkflowTarget): WorkflowRootBundle;
/** `workflow.approvals` — 列出全部挂起审批(刷新/重连后的拉取恢复路径;推送通知是快路径)。 */
export declare function handleWorkflowApprovals(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/** `workflow.approve` — 人工审批决定(approved=false 即拒绝);未知/过期 id fail-loud。 */
export declare function handleWorkflowApprove(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/**
 * `workflow.onForm` — form 触发(D34):校验活跃 form 触发 + 必填字段,以表单值为 $trigger 起 run。
 * attended(用户亲手填表提交)。
 */
export declare function handleWorkflowOnForm(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
export declare function handleWorkflowCreate(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
export declare function handleWorkflowGet(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
export declare function handleWorkflowDescribe(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
export declare function handleWorkflowPatch(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
export declare function handleWorkflowRun(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/**
 * `workflow.update` — record-level meta/def update (rename, whole-def replacement from the
 * chat builder, concurrency). Graph micro-edits stay on workflow.patch; trigger stays a
 * set_trigger patch op (single track each).
 */
export declare function handleWorkflowUpdate(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
export declare function handleWorkflowSetActive(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
export declare function handleWorkflowList(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
export declare function handleWorkflowDelete(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/**
 * `workflow.cancelRun` — stop an in-flight run (D32; engine support landed with the teammate's
 * runId/AbortController work, this exposes it on the RPC face + a UI stop button). Cancels the
 * newest active run when runId is omitted. fail-loud when nothing is running.
 */
export declare function handleWorkflowCancelRun(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/**
 * `workflow.dryRun` — test-run the DRAFT with an optional simulated trigger payload, WITHOUT
 * recording into run history (D36: test runs stay out of production stats). Returns the full
 * outcome incl. per-node trace for inspection.
 */
export declare function handleWorkflowDryRun(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/** `workflow.metrics` — aggregate run history into success-rate/duration/trigger stats (D33). */
export declare function handleWorkflowMetrics(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/** `workflow.publish` — snapshot the draft as the trigger-run version (D31). */
export declare function handleWorkflowPublish(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/** `workflow.archive` — keep the data, kill the lifecycle (deactivate + refuse runs). */
export declare function handleWorkflowArchive(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
export declare function handleCredentialList(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
export declare function handleCredentialCreate(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
export declare function handleCredentialDelete(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/**
 * `credential.oauthStart` — create an oauth2 credential (config persisted, token pending) and
 * return the authorize URL the UI opens in the browser. The gateway's /api/oauth/callback lands
 * the code on credential.oauthComplete.
 */
export declare function handleCredentialOauthStart(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/** `credential.oauthComplete` — exchange the authorization code and store tokens in the vault. */
export declare function handleCredentialOauthComplete(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/**
 * `workflow.setPermissionScope` — the owner's explicit unattended capability grant (D30):
 * which sensitive kinds this workflow may run under schedule/im/webhook triggers.
 */
export declare function handleWorkflowSetPermissionScope(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/**
 * `workflow.capabilities` — enumerate the real agents/tools/skills/mcp/memory a workflow in the
 * target project can reference (single source of truth, five consumers: AI builder prompt,
 * "+" suggestions, advanced node library, config dropdowns, Hub requires checks). Channels are
 * gateway-owned: the gateway merges its channel registry into this response in ws-server.
 */
export declare function handleWorkflowCapabilities(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/** `workflow.export` — serialize one workflow as a sanitized portable bundle (no credentials). */
export declare function handleWorkflowExport(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/**
 * `workflow.publishHub` — publish a workflow to the community Hub (IT-5, spec D35):
 * sanitized bundle (D23 — credential values already stripped) becomes the gzip payload;
 * the WorkflowManifest is DERIVED from the record (trigger summary, node count, sensitive
 * capability kinds as declaredPermissions, credential/capability requirements), so the
 * publisher only supplies presentation fields. Same consent + review pipeline as skills.
 */
export declare function handleWorkflowPublishHub(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/**
 * `workflow.import` — materialize a portable bundle (or raw n8n JSON, format:"n8n") into a target
 * project. The caller creates/owns the project (frontend: WorkspaceStep → POST /api/projects);
 * this RPC only lands the workflow. fail-loud on malformed payloads (§1.5).
 */
export declare function handleWorkflowImport(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/**
 * `workflow.duplicate` — copy a workflow (same graph/trigger, fresh id, inactive) into a target
 * project: export→import in-process (one serialization path, spec D23). 复制/另存为 both land here.
 */
export declare function handleWorkflowDuplicate(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
export declare function handleWorkflowOnImMessage(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
export declare function handleWorkflowOnWebhook(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/**
 * `workflow.onIntent` — fire an intent-triggered run (spec D22). The MATCH already happened
 * (deterministic phrases client-side; semantic fallback via x/workflow.matchIntent) and the user
 * confirmed; this entry point only verifies the workflow really has an ACTIVE intent trigger
 * (fail-loud otherwise — a stale client must not run a disarmed workflow) and starts the run with
 * the utterance as `$trigger` payload.
 */
export declare function handleWorkflowOnIntent(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/** All ACTIVE intent-triggered workflows across the active root + automation projects (D22 索引源). */
export declare function collectActiveIntentWorkflows(this: WorkflowCoordinatorHost): Promise<Array<{
    workflowId: string;
    projectId?: string;
    name: string;
    trigger: Extract<NonNullable<WorkflowRecord["trigger"]>, {
        type: "intent";
    }>;
}>>;
/**
 * `workflow.intentIndex` — the deterministic-match index the CLIENT consumes (phrases/aliases/
 * confirm/surfaces per active intent workflow). The frontend matches utterances locally with zero
 * latency (spec D22); semantic fallback goes through x/workflow.matchIntent.
 */
export declare function handleWorkflowIntentIndex(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/** `workflow.revisions` — newest-first def-revision summaries for the undo/history UI. */
export declare function handleWorkflowRevisions(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/** `workflow.revert` — re-apply a stored revision as a NEW rev (git-revert semantics). */
export declare function handleWorkflowRevert(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/**
 * `workflow.audit` — newest-first config/lifecycle audit entries (D38: who did what when).
 * Runs are NOT here (runHistory is the run audit); a timeline UI merges both.
 */
export declare function handleWorkflowAudit(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/** `workflow.runs` — newest-first run summaries (status/trigger/timing; outputs stay behind runDetail). */
export declare function handleWorkflowRuns(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
/** `workflow.runDetail` — one run incl. per-node output previews (画布点节点看产出). */
export declare function handleWorkflowRunDetail(this: WorkflowHandlerHost, msg: AgentRpcRequest): Promise<void>;
export {};
