/** * @license * Copyright 2025 Vybestack LLC * SPDX-License-Identifier: Apache-2.0 */ import type { OutputObject } from '../core/subagent.js'; export type AsyncTaskStatus = 'running' | 'completed' | 'failed' | 'cancelled'; export interface AsyncTaskInfo { id: string; subagentName: string; goalPrompt: string; status: AsyncTaskStatus; launchedAt: number; completedAt?: number; notifiedAt?: number; output?: OutputObject; error?: string; abortController?: AbortController; } export interface RegisterTaskInput { id: string; subagentName: string; goalPrompt: string; abortController: AbortController; } export declare class AsyncTaskManager { private readonly tasks; private readonly emitter; private maxAsyncTasks; private pendingReservations; constructor(maxAsyncTasks?: number); /** * @pseudocode lines 045-048 */ setMaxAsyncTasks(max: number): void; /** * @pseudocode lines 050-052 */ getMaxAsyncTasks(): number; /** * @pseudocode lines 054-056 */ getAllTasks(): AsyncTaskInfo[]; /** * @pseudocode lines 058-078 */ canLaunchAsync(): { allowed: boolean; reason?: string; }; /** * Atomically check and reserve a slot for task registration * Returns a unique booking ID if successful, or null if limit reached */ tryReserveAsyncSlot(): string | null; /** * Cancel a pending reservation, releasing the slot it occupies. * Safe to call with an invalid or already-consumed bookingId (no-op). */ cancelReservation(bookingId: string): boolean; /** * @pseudocode lines 084-097 */ registerTask(input: RegisterTaskInput, bookingId?: string): AsyncTaskInfo; /** * @pseudocode lines 103-129 */ completeTask(id: string, output: OutputObject): boolean; /** * @pseudocode lines 135-155 */ failTask(id: string, error: string): boolean; /** * @pseudocode lines 161-185 */ cancelTask(id: string): boolean; /** * @pseudocode lines 191-193 */ getTask(id: string): AsyncTaskInfo | undefined; /** * @pseudocode lines 195-213 */ getTaskByPrefix(prefix: string): { task?: AsyncTaskInfo; candidates?: AsyncTaskInfo[]; }; /** * Clean up expired reservations to prevent memory leaks */ private cleanupExpiredReservations; /** * @pseudocode lines 219-221 */ getRunningTasks(): AsyncTaskInfo[]; /** * @pseudocode lines 223-228 */ getPendingNotifications(): AsyncTaskInfo[]; /** * @pseudocode lines 234-239 */ markNotified(id: string): void; /** * @pseudocode lines 245-267 */ private enforceHistoryLimit; /** * @pseudocode lines 273-276 */ onTaskCompleted(handler: (task: AsyncTaskInfo) => void): () => void; /** * @pseudocode lines 278-281 */ onTaskFailed(handler: (task: AsyncTaskInfo) => void): () => void; /** * @pseudocode lines 283-286 */ onTaskCancelled(handler: (task: AsyncTaskInfo) => void): () => void; }