import type { TaskStateManager } from "../../shared/state.js"; export type QueuePriority = "high" | "normal"; export type QueuedTask = { id: string; key: string; createdAt: number; priority?: QueuePriority; }; export declare function buildDelegationQueueKey(args: { provider?: string; model?: string; agent?: string; }): string; export declare const DEFAULT_CONCURRENCY_LIMIT = 3; export declare class DelegationConcurrencyQueue { private readonly defaultLimit; private readonly lanes; constructor(defaultLimit?: number); acquire(key: string, limit?: number, timeoutMs?: number): Promise<() => void>; enqueue(task: QueuedTask): void; dequeue(key: string, taskID?: string): QueuedTask | undefined; peek(key: string): QueuedTask | undefined; queueSize(key: string): number; snapshot(key: string): { active: number; pending: number; limit: number; }; private getLane; private normalizePriority; private shiftQueuedTask; private removeQueuedTaskByID; private cleanupLane; private makeRelease; } /** * A single reservation against the descendant budget of a root session. * * Lifecycle: * - Created by {@link reserveSubagentSpawn}. * - {@link release} — the spawn succeeded; the reservation is consumed. * - {@link rollback} — the spawn was abandoned; restores the reserved slot. * * Both methods are idempotent; calling either after the other is a no-op. */ export interface SpawnReservation { /** Session ID of the direct parent that initiated the spawn. */ readonly parentID: string; /** Root session ID whose descendant budget was reserved against. */ readonly rootID: string; /** Unix timestamp (ms) recorded at reservation creation. */ readonly reservedAt: number; /** * Marks the reservation as consumed (spawn succeeded). * The budget slot remains occupied — it is not rolled back. * Idempotent: subsequent calls are silently ignored. */ release(): void; /** * Cancels the reservation and returns the budget slot. * Use when the spawn was abandoned before the session started. * Idempotent: subsequent calls are silently ignored. */ rollback(): void; } /** * Attempt to reserve one descendant slot in the root session budget. * * Throws a `[Hivemind]`-prefixed error if the budget is exhausted. * * @param parentSessionID - The session ID of the calling (parent) agent. * @param rootID - The root session whose budget is being charged. * @param taskState - The shared {@link TaskStateManager} instance. * @param maxDescendants - Override for the per-root limit (default: {@link MAX_DESCENDANTS_PER_ROOT}). */ export declare function reserveSubagentSpawn(parentSessionID: string, rootID: string, taskState: TaskStateManager, maxDescendants?: number): SpawnReservation; //# sourceMappingURL=queue.d.ts.map