import { type ModelMessage, type ToolSet } from 'ai'; import type { FlowAgentConfig, AgentConfig, RunContext, HarnessStreamPart, FlowManagerState, ToolCallRecord, HarnessConfig, Session, OutputProcessor } from '../types/index.js'; import type { TurnUsage } from '../types/telemetry.js'; export interface FlowExecutorHelpers { emit: (context: RunContext, part: HarnessStreamPart) => AsyncGenerator; runOutputProcessing: (agent: AgentConfig, context: RunContext, text: string) => Promise<{ text: string; tripwire?: { processorId: string; reason: string; message?: string; }; }>; appendSessionMessage: (session: Session, message: ModelMessage) => void; appendSessionMessages: (session: Session, messages: ModelMessage[]) => void; postProcessPersistedAssistantMessages: (agent: AgentConfig, context: RunContext, startIndex: number) => Promise>; getAgentOutputProcessors: (agent: AgentConfig) => OutputProcessor[]; getSessionTurn: (session: Session) => number; buildToolIdempotencyKey: (context: RunContext, toolName: string, toolCallId: string) => string; setFlowState: (session: Session, agentId: string, state: FlowManagerState) => void; getFlowState: (session: Session, agentId: string) => FlowManagerState | undefined; updateFlowStateSnapshot: (session: Session, agentId: string, state: FlowManagerState) => void; clearFlowState: (session: Session, agentId: string) => void; buildFlowWithHandoff: (agent: FlowAgentConfig, handoffTool: ToolSet[string] | undefined, suppressAutoRespond: boolean) => FlowAgentConfig['flow']; getFlowNode: (agent: FlowAgentConfig, nodeId?: string) => FlowAgentConfig['flow']['nodes'][number] | undefined; touchSession: (session: Session) => void; matchesDetourRule: (input: string, patterns?: string[]) => boolean; enforcecheck: (call: ToolCallRecord, context: RunContext) => Promise<{ allowed: boolean; reason?: string; }>; enforcecheckResult: (call: ToolCallRecord, context: RunContext) => Promise<{ allowed: boolean; reason?: string; }>; onToolCallHook: (context: RunContext, call: ToolCallRecord) => Promise; onToolResultHook: (context: RunContext, call: ToolCallRecord) => Promise; onToolErrorHook: (context: RunContext, call: ToolCallRecord, error: Error) => Promise; /** Optional metrics emitter for flow-level timing/counters. Converts to custom stream events. */ emitMetric?: (name: string, data: Record) => void; onTokensUpdate?: (context: RunContext, turn: TurnUsage) => Promise; } export declare class FlowExecutor { private config; constructor(config: HarnessConfig); shouldHandleFlowInput(agent: FlowAgentConfig, input: string, flowState: FlowManagerState | undefined, helpers: FlowExecutorHelpers, abortSignal?: AbortSignal): Promise; private emitRoutingMetric; runDetourResponse(agent: FlowAgentConfig, context: RunContext, input: string, flowState: FlowManagerState | undefined, handoffTool: ToolSet[string] | undefined, onHandoff: (target: string, reason?: string) => void, helpers: FlowExecutorHelpers, abortSignal?: AbortSignal): AsyncGenerator; runFlowAgent(agent: FlowAgentConfig, context: RunContext, input: string, systemPrompt: string, handoffTool: ToolSet[string] | undefined, onHandoff: (target: string, reason?: string) => void, toolCalls: ToolCallRecord[], helpers: FlowExecutorHelpers, abortSignal?: AbortSignal): AsyncGenerator; /** * Shared event handler for flow manager async iterables. * Used by both the initialization and processing phases to avoid duplication. */ private processFlowEvents; }