import { StreamHelper } from "../stream/stream-helpers.js";
import { FullExecutionContext, Part } from "@inkeep/agents-core";

//#region src/domains/run/handlers/executionHandler.d.ts
interface ExecutionHandlerParams {
  executionContext: FullExecutionContext;
  conversationId: string;
  userMessage: string;
  /** Optional message parts for rich content (text + data). Used on first iteration only. */
  messageParts?: Part[];
  initialAgentId: string;
  requestId: string;
  sseHelper: StreamHelper;
  emitOperations?: boolean;
  datasetRunId?: string;
  /** Headers to forward to MCP servers (e.g., x-forwarded-cookie for auth) */
  forwardedHeaders?: Record<string, string>;
  responseMessageId?: string;
  /** Durable workflow run ID — present when running inside a WDK workflow */
  durableWorkflowRunId?: string;
  /** Pre-approved tool decisions keyed by toolName — accumulated across approval loops */
  approvedToolCalls?: Record<string, Array<{
    approved: boolean;
    reason?: string;
    originalToolCallId?: string;
  }>>;
}
interface ExecutionResult {
  success: boolean;
  error?: string;
  iterations: number;
  response?: string;
  pendingApproval?: {
    toolCallId: string;
    toolName: string;
    args: unknown;
  };
}
declare class ExecutionHandler {
  private readonly MAX_ERRORS;
  /**
   * performs exeuction loop
   *
   * Do up to limit of MAX_ITERATIONS
   *
   * 1. lookup active agent for thread
   * 2. Send A2A message to selected agent
   * 3. Parse A2A message response
   * 4. Handle transfer messages (if any)
   * 5. Handle completion messages (if any)
   * 6. If no valid response or transfer, return error
   * @param params
   * @returns
   */
  execute(params: ExecutionHandlerParams): Promise<ExecutionResult>;
}
//#endregion
export { ExecutionHandler, ExecutionHandlerParams };