import { ExecutionTask, ExecutionTaskResult, ParallelExecutionConfig, ParallelExecutionResult, ResultSelectionConfig, ProgressCallbacksInterface, IParallelExecutionCoordinator } from './ParallelExecution.js'; import { AIPromptParams } from '@memberjunction/ai-core-plus'; import { AIPromptRunner } from './AIPromptRunner.js'; /** * Coordinates parallel execution of AI prompt tasks across multiple models and execution groups. * * This class manages the complex orchestration of: * - Grouping tasks by execution group * - Sequential execution of groups with parallel execution within groups * - Result aggregation and selection * - Error handling and partial result collection * - Performance monitoring and metrics collection * - Real-time progress tracking and streaming updates */ /** * Coordinates parallel multi-model prompt execution. * * SUBCLASSES {@link AIPromptRunner} purely to REUSE its execution primitives — most importantly the * `protected executeModel`, which owns credential resolution, driver selection, ChatParams * construction, prefill, media handling, and streaming. Each parallel task delegates to that ONE * method (see {@link executeSingleTask}) instead of re-implementing it, so the parallel and * single-model paths can never drift. The coordinator only adds task fan-out, grouping, timeouts, * result selection, and child-run tracking on top. * * Registered under the base class with a dedicated key so {@link AIPromptRunner.ParallelCoordinator} * can instantiate it via the ClassFactory without a static (circular) import. */ export declare class ParallelExecutionCoordinator extends AIPromptRunner implements IParallelExecutionCoordinator { private readonly _defaultConfig; /** * Creates a new parallel execution coordinator with default configuration. */ constructor(); /** * Executes multiple tasks in parallel according to their execution groups. * * Tasks are grouped by their executionGroup property and executed sequentially by group. * Within each group, tasks are executed in parallel up to the concurrency limit. * * @param tasks - Array of execution tasks to process * @param config - Optional configuration to override defaults * @param parentPromptRunId - Optional parent prompt run ID for hierarchical logging * @param cancellationToken - Optional cancellation token to abort execution * @param progressCallbacks - Optional callbacks for progress tracking * @param agentRunId - Optional agent run ID to link prompt executions to parent agent run * @returns Promise - Aggregated results from all executions */ executeTasksInParallel(params: AIPromptParams, tasks: ExecutionTask[], config?: Partial, parentPromptRunId?: string, cancellationToken?: AbortSignal, progressCallbacks?: ProgressCallbacksInterface, // Using interface to avoid circular dependency agentRunId?: string): Promise; /** * Selects the best result from multiple parallel execution results. * * Uses various strategies to determine which result should be considered * the "best" output from the parallel executions. * * @param results - Array of successful execution results to choose from * @param config - Configuration for result selection method * @param parentPromptRunId - Optional parent prompt run ID for hierarchical logging * @returns Promise - The selected best result, or null if none suitable */ selectBestResult(results: ExecutionTaskResult[], config: ResultSelectionConfig, parentPromptRunId?: string, cancellationToken?: AbortSignal): Promise; /** * Groups execution tasks by their execution group number. * Tasks with the same group number will be executed in parallel. * * @param tasks - Array of tasks to group * @returns ExecutionGroup[] - Sorted array of execution groups */ private groupTasksByExecutionGroup; /** * Executes execution groups sequentially, with parallel execution within each group. * * @param groups - Array of execution groups to process * @param config - Execution configuration * @param parentPromptRunId - Optional parent prompt run ID for tracking * @param cancellationToken - Optional cancellation token to abort execution * @param progressTracker - Progress tracker for monitoring execution * @param agentRunId - Optional agent run ID to link prompt executions to parent agent run * @returns Promise - All task results from all groups */ private executeGroupsSequentially; /** * Executes all tasks within a single execution group in parallel. * * @param group - The execution group to process * @param config - Execution configuration * @param parentPromptRunId - Optional parent prompt run ID for tracking * @param cancellationToken - Optional cancellation token to abort execution * @param progressTracker - Progress tracker for monitoring execution * @param agentRunId - Optional agent run ID to link prompt executions to parent agent run * @returns Promise - Results from all tasks in the group */ private executeGroupInParallel; /** * Executes a single task with retry logic and timeout handling. * * @param task - The execution task to process * @param config - Execution configuration * @param parentPromptRunId - Optional parent prompt run ID for hierarchical logging * @param executionOrder - Execution order for this task * @param agentRunId - Optional agent run ID to link prompt executions to parent agent run * @returns Promise - Result of the task execution */ private executeTask; /** * Executes a single task without retry logic. * * @param task - The execution task to process * @param timeoutMS - Timeout for the execution in milliseconds * @param parentPromptRunId - Optional parent prompt run ID for hierarchical logging * @param executionOrder - Execution order for this task * @param agentRunId - Optional agent run ID to link prompt executions to parent agent run * @returns Promise - Result of the task execution */ private executeSingleTask; /** * Aggregates individual task results into a comprehensive parallel execution result. * * @param taskResults - Array of all task execution results * @param startTime - Start time of the parallel execution * @param endTime - End time of the parallel execution * @returns ParallelExecutionResult - Aggregated results with metrics */ private aggregateResults; /** * Selects the first successful result from the array. * * @param results - Array of successful results to choose from * @returns ExecutionTaskResult - The first result in the array */ private selectFirstResult; /** * Selects a random result from the array. * * @param results - Array of successful results to choose from * @returns ExecutionTaskResult - A randomly selected result */ private selectRandomResult; /** * Uses an AI prompt to select the best result from multiple options. * * @param results - Array of successful results to choose from * @param selectorPromptId - ID of the prompt to use for selection * @param parentPromptRunId - Optional parent prompt run ID for hierarchical logging * @returns Promise - The AI-selected best result with all results ranked */ private selectResultWithPrompt; /** * Formats execution results for the judge prompt. * * @param results - Array of execution results to format * @returns Structured data for judge evaluation */ private formatResultsForJudge; /** * Parses the judge's result to extract rankings. * * @param judgeResult - Raw result from the judge prompt * @returns Array of ranking objects or null if parsing fails */ private parseJudgeResult; /** * Applies rankings to execution task results. * * @param results - Array of execution results to rank * @param rankings - Rankings from the judge */ private applyRankingsToResults; /** * Selects the result that appears most frequently (consensus). * * @param results - Array of successful results to choose from * @returns ExecutionTaskResult - The most common result */ private selectConsensusResult; /** * Builds a per-task copy of the shared prompt params for delegation to the inherited executeModel. * * - Clones (preserving prototype) so concurrently-running tasks never mutate each other's params — * fixing the old `Object.assign(params, task.modelParameters)` that mutated the SHARED object. * - Merges the task's per-model parameters into additionalParameters so executeModel's scalar-param * resolution (temperature/topP/etc.) actually applies them (the old manual ChatParams path * silently ignored them). * - Bridges the task's incremental streaming callback (OnContent) into params.onStreaming so the * base's single streaming path drives it. (OnComplete/OnError are fired by executeSingleTask.) */ private buildPerTaskParams; /** * Creates a child AIPromptRun entity for individual parallel execution tracking. * * @param task - The execution task * @param startTime - When the execution started * @param parentPromptRunId - ID of the parent prompt run * @param executionOrder - Execution order within the parallel group * @param agentRunId - Optional agent run ID to link prompt executions to parent agent run * @returns Promise - The created child prompt run */ private createChildPromptRun; /** * Updates a child AIPromptRun entity with execution results. * * @param promptRun - The child prompt run entity to update * @param modelResult - The result from the AI model * @param endTime - When the execution completed * @param executionTimeMS - Total execution time in milliseconds */ private updateChildPromptRun; /** * Creates a ResultSelector AIPromptRun entity for judge execution tracking. * * @param judgePrompt - The judge prompt being executed * @param judgeData - The data being sent to the judge * @param parentPromptRunId - ID of the parent prompt run * @param executionOrder - Execution order within the parallel group * @returns Promise - The created result selector prompt run */ private createResultSelectorPromptRun; /** * Creates a delay for the specified number of milliseconds. * * @param ms - Number of milliseconds to delay * @returns Promise - Promise that resolves after the delay */ private delay; } //# sourceMappingURL=ParallelExecutionCoordinator.d.ts.map