import type { WorkflowDefinition } from '../domain/definition.js'; import type { WorkflowEventEnvelope } from '../domain/event.js'; import type { WorkflowRun, WorkflowRunMetadata, WorkflowRunSource, WorkflowRunView } from '../domain/run.js'; import { WorkflowEventStore } from '../store/event-store.js'; import { WorkflowRunStore } from '../store/run-store.js'; import type { WorkflowRuntime, WorkflowRuntimeSubagentRunner } from '../runtime/workflow-runtime-port.js'; import type { Api, Model } from '@earendil-works/pi-ai'; import type { WorkflowAgentInvocationSnapshot } from '../domain/index.js'; export interface WorkflowEngineOptions { cwd: string; projectId?: string; eventStore: WorkflowEventStore; runStore: WorkflowRunStore; runner: WorkflowRuntimeSubagentRunner; runtime?: WorkflowRuntime; hooks?: WorkflowEngineHook[]; subagentSessionKeyFactory?: (ctx: { runId: string; agentId: string; }) => string; parentSessionKey?: string; onEventAppended?: (event: WorkflowEventEnvelope) => void; onRunViewUpdated?: (view: WorkflowRunView) => void; resolveModelId?: (modelId: string) => Model; } export interface WorkflowEngineHook { beforeRun?(ctx: WorkflowRunHookContext): Promise | void; beforeAgent?(ctx: WorkflowAgentHookContext): Promise | void; afterAgent?(ctx: WorkflowAgentCompletedHookContext): Promise | void; afterRun?(ctx: WorkflowRunCompletedHookContext): Promise | void; } export interface WorkflowRunHookContext { definition: WorkflowDefinition; run: WorkflowRun; } export interface WorkflowAgentHookContext { runId: string; agentId: string; label: string; phaseId?: string; prompt: string; } export interface WorkflowAgentCompletedHookContext { runId: string; agentId: string; status: 'done' | 'error' | 'skipped'; resultPreview?: string; } export interface WorkflowRunCompletedHookContext { runId: string; status: 'succeeded' | 'failed' | 'cancelled'; } export interface StartWorkflowRunOptions { input?: unknown; source: WorkflowRunSource; metadata?: WorkflowRunMetadata; goal?: string; runId?: string; signal?: AbortSignal; concurrency?: number; maxSubagents?: number; tokenBudget?: number | null; timeoutSec?: number; } export interface WorkflowReplayAgentTarget { agentId: string; label: string; phaseId?: string; phaseTitle?: string; prompt: string; invocation?: WorkflowAgentInvocationSnapshot; } export interface StartWorkflowReplayRunOptions extends StartWorkflowRunOptions { sourceRunId: string; replayScope: 'failed_agents' | 'failed_phases'; targets: WorkflowReplayAgentTarget[]; } export declare class WorkflowEngine { private readonly options; constructor(options: WorkflowEngineOptions); startRun(definition: WorkflowDefinition, options: StartWorkflowRunOptions): Promise; startReplayRun(definition: WorkflowDefinition, options: StartWorkflowReplayRunOptions): Promise; private runReplayTargets; private runReplayTarget; private completeOutstandingRuntimeAgents; private callHooks; }