agentic-qe
Version:
Agentic Quality Engineering Fleet System - AI-driven quality management platform
264 lines • 6.48 kB
TypeScript
/**
* Task - Represents a unit of work to be executed by agents
*
* @remarks
* The Task class encapsulates all information needed to execute a unit of work
* in the AQE Fleet, including data, requirements, status tracking, and results.
*
* Tasks are automatically assigned to capable agents by the FleetManager and
* provide event-based progress tracking.
*
* @example
* ```typescript
* // Create a test generation task
* const task = new Task(
* 'test-generation',
* 'Generate unit tests for UserService',
* {
* filePath: './src/services/UserService.ts',
* framework: 'jest',
* coverageTarget: 95
* },
* {
* capabilities: ['ai-test-generation'],
* agentTypes: ['test-generator']
* },
* TaskPriority.HIGH
* );
*
* // Monitor task progress
* task.on('status:changed', (data) => {
* console.log(`Task ${data.taskId} status: ${data.newStatus}`);
* });
*
* await fleet.submitTask(task);
* const result = await task.waitForCompletion();
* ```
*
* @public
*/
/// <reference types="node" />
import { EventEmitter } from 'events';
/**
* Current execution status of a task
*
* @public
*/
export declare enum TaskStatus {
/** Task has been created but not submitted */
CREATED = "created",
/** Task is queued waiting for an available agent */
QUEUED = "queued",
/** Task has been assigned to an agent */
ASSIGNED = "assigned",
/** Task is currently being executed */
RUNNING = "running",
/** Task completed successfully */
COMPLETED = "completed",
/** Task execution failed */
FAILED = "failed",
/** Task was cancelled before completion */
CANCELLED = "cancelled"
}
/**
* Priority level for task execution
*
* @public
*/
export declare enum TaskPriority {
/** Low priority task */
LOW = 0,
/** Medium priority task (default) */
MEDIUM = 1,
/** High priority task */
HIGH = 2,
/** Critical priority task (executed first) */
CRITICAL = 3
}
/**
* Metadata about task execution
*
* @public
*/
export interface TaskMetadata {
/** When the task was created */
createdAt: Date;
/** When the task started executing */
startedAt?: Date;
/** When the task completed or failed */
completedAt?: Date;
/** ID of the agent assigned to this task */
assignedAgent?: string;
/** Number of times this task has been retried */
retryCount: number;
/** Maximum number of retry attempts allowed */
maxRetries: number;
/** Timeout in milliseconds for task execution */
timeout?: number;
}
/**
* Requirements that must be met for task execution
*
* @public
*/
export interface TaskRequirements {
/** Specific agent types that can handle this task */
agentTypes?: string[];
/** Required capabilities an agent must have */
capabilities?: string[];
/** Required resources (memory, CPU, etc.) */
resources?: Record<string, any>;
/** Task IDs that must complete before this task */
dependencies?: string[];
}
export declare class Task extends EventEmitter {
private readonly id;
private readonly type;
private readonly name;
private readonly data;
private readonly requirements;
private status;
private priority;
private result;
private error;
private metadata;
constructor(type: string, name: string, data?: any, requirements?: TaskRequirements, priority?: TaskPriority);
/**
* Get task ID
*
* @returns Unique identifier for this task
* @public
*/
getId(): string;
/**
* Get task type
*
* @returns The type of task (e.g., 'test-generation', 'coverage-analysis')
* @public
*/
getType(): string;
/**
* Get task name
*
* @returns Human-readable name for this task
* @public
*/
getName(): string;
/**
* Get task data
*
* @returns The data payload for task execution
* @public
*/
getData(): any;
/**
* Get task requirements
*/
getRequirements(): TaskRequirements;
/**
* Get task status
*/
getStatus(): TaskStatus;
/**
* Set task status and update metadata
*
* @param status - The new status for the task
* @fires status:changed
* @public
*/
setStatus(status: TaskStatus): void;
/**
* Get task priority
*/
getPriority(): TaskPriority;
/**
* Set task priority
*/
setPriority(priority: TaskPriority): void;
/**
* Get task result
*/
getResult(): any;
/**
* Set task result
*/
setResult(result: any): void;
/**
* Get task error
*/
getError(): Error | null;
/**
* Set task error
*/
setError(error: Error): void;
/**
* Get task metadata
*/
getMetadata(): TaskMetadata;
/**
* Assign agent to task
*/
assignAgent(agentId: string): void;
/**
* Check if task can be retried
*/
canRetry(): boolean;
/**
* Increment retry count
*/
incrementRetry(): void;
/**
* Set maximum retries
*/
setMaxRetries(maxRetries: number): void;
/**
* Set timeout for task execution
*/
setTimeout(timeout: number): void;
/**
* Check if task has timed out
*/
hasTimedOut(): boolean;
/**
* Get task execution duration
*/
getExecutionDuration(): number | null;
/**
* Check if task is complete (either completed or failed)
*/
isComplete(): boolean;
/**
* Wait for task completion
*
* @remarks
* Returns a promise that resolves when the task completes successfully
* or rejects if the task fails or is cancelled.
*
* @returns A promise that resolves to the task result
* @throws {Error} If the task fails or is cancelled
*
* @example
* ```typescript
* const task = new Task('test-generation', 'Generate tests', data);
* await fleet.submitTask(task);
* const result = await task.waitForCompletion();
* console.log('Tests generated:', result);
* ```
*
* @public
*/
waitForCompletion(): Promise<any>;
/**
* Cancel the task
*/
cancel(): void;
/**
* Convert task to JSON representation
*/
toJSON(): any;
/**
* Create task from JSON representation
*/
static fromJSON(json: any): Task;
}
//# sourceMappingURL=Task.d.ts.map