export interface AsyncJob { id: string; type: "bash" | "task"; status: "running" | "completed" | "failed" | "cancelled"; startTime: number; label: string; abortController: AbortController; promise: Promise; resultText?: string; errorText?: string; /** * Registry id of the agent that registered the job (e.g. "0-Main", * "3-AuthLoader"). Used by scoped cancel/list APIs so a subagent's teardown * does not cancel its parent's jobs. Undefined for callers that don't * supply an id (e.g. legacy tests, SDK consumers without an agent context). */ ownerId?: string; } export interface AsyncJobManagerOptions { onJobComplete: (jobId: string, text: string, job?: AsyncJob) => void | Promise; maxRunningJobs?: number; retentionMs?: number; } export interface AsyncJobDeliveryState { queued: number; delivering: boolean; nextRetryAt?: number; pendingJobIds: string[]; } export interface AsyncJobRegisterOptions { id?: string; /** Registry id of the agent that owns this job; used to scope cancelAll. */ ownerId?: string; onProgress?: (text: string, details?: Record) => void | Promise; } /** * Filter applied to job query/cancel APIs. With `ownerId`, results are * restricted to jobs registered by that agent (registry id from * `AgentRegistry`, e.g. "0-Main", "3-AuthLoader"). */ export interface AsyncJobFilter { ownerId?: string; } export declare class AsyncJobManager { #private; /** Process-global instance shared by internal URL protocol handlers and tools. */ static instance(): AsyncJobManager | undefined; /** Install or clear the process-global instance. */ static setInstance(value: AsyncJobManager | undefined): void; /** Reset the process-global instance. Test-only. */ static resetForTests(): void; constructor(options: AsyncJobManagerOptions); register(type: "bash" | "task", label: string, run: (ctx: { jobId: string; signal: AbortSignal; reportProgress: (text: string, details?: Record) => Promise; }) => Promise, options?: AsyncJobRegisterOptions): string; /** * Cancel a single job by id. When `filter.ownerId` is set and does not * match the job's owner, the call is treated as not-found (returns false) * so cross-agent cancellation is rejected at the manager level. */ cancel(id: string, filter?: AsyncJobFilter): boolean; getJob(id: string): AsyncJob | undefined; getRunningJobs(filter?: AsyncJobFilter): AsyncJob[]; getRecentJobs(limit?: number, filter?: AsyncJobFilter): AsyncJob[]; getAllJobs(filter?: AsyncJobFilter): AsyncJob[]; getDeliveryState(filter?: AsyncJobFilter): AsyncJobDeliveryState; hasPendingDeliveries(filter?: AsyncJobFilter): boolean; watchJobs(jobIds: string[]): number; unwatchJobs(jobIds: string[]): number; acknowledgeDeliveries(jobIds: string[]): number; /** * Cancel running jobs. With `filter.ownerId` set, cancels only jobs the * matching agent registered; with no filter, cancels every running job * (used by `dispose()` to nuke the manager's state). */ cancelAll(filter?: AsyncJobFilter): void; waitForAll(): Promise; drainDeliveries(options?: { timeoutMs?: number; filter?: AsyncJobFilter; }): Promise; dispose(options?: { timeoutMs?: number; }): Promise; isDeliverySuppressed(jobId: string): boolean; }