/** * batch-orchestrator.ts — Enterprise Batch Orchestration Engine * * Manages batch tracking for background agents spawned in the current turn. * Debounced timer captures parallel tool calls across microtasks. * Integrates with GroupJoinManager (fixed groups) and SwarmCoordinator * (dynamic collaborative swarms) with full async lifecycle support. */ import type { AgentManager } from "./agent-manager.js"; import { GroupJoinManager } from "./group-join.js"; import { type SwarmConfig, SwarmCoordinator, type SwarmStrategy } from "./swarm-join.js"; import type { AgentRecord, JoinMode } from "./types.js"; export interface BatchOrchestratorDeps { manager: AgentManager; groupJoin: GroupJoinManager; swarmJoin: SwarmCoordinator; onAgentHandled: (record: AgentRecord) => void; onWidgetUpdate: () => void; } export interface BatchConfig { /** Debounce window for batch finalization (ms). Default: 100. */ debounceMs?: number; /** Minimum agents to form a smart group. Default: 2. */ smartGroupThreshold?: number; /** Minimum agents to form a swarm. Default: 1. */ swarmThreshold?: number; /** Default swarm strategy when not specified. Default: "live". */ defaultSwarmStrategy?: SwarmStrategy; /** Default swarm config overrides. */ defaultSwarmConfig?: Partial>; /** Callback when a batch is finalized. */ onBatchFinalized?: (batchId: number, stats: BatchStats) => void; } export interface BatchStats { batchId: number; totalAgents: number; smartGroups: number; swarmCount: number; individualAgents: number; durationMs: number; } interface PendingAgent { id: string; joinMode: JoinMode; /** Optional per-agent swarm strategy override. */ swarmStrategy?: SwarmStrategy; /** Optional priority for leader election. */ priority?: number; addedAt: number; } export declare class BatchOrchestrator { private deps; private currentBatch; private batchFinalizeTimer; private batchCounter; private config; private isFinalizing; private batchStartTime; constructor(deps: BatchOrchestratorDeps, config?: BatchConfig); /** * Add an agent to the current batch. * Resets the debounce timer to capture parallel tool calls. */ addToBatch(id: string, joinMode: JoinMode, options?: { strategy?: SwarmStrategy; priority?: number; }): void; /** * Force immediate finalization of the current batch. * Useful for shutdown or explicit flush scenarios. */ flush(): Promise; /** * Finalize the current batch: * - smart/group agents → fixed GroupJoinManager groups * - swarm agents → dynamic SwarmCoordinator with full config support * - leftovers → individual nudges */ private finalizeBatch; /** * Check if an agent is currently pending batch finalization. */ isPendingBatchFinalization(agentId: string): boolean; /** * Get current pending batch info (for UI/dashboard). */ getPendingBatch(): { agents: PendingAgent[]; timeUntilFlushMs: number; } | null; /** * Clean up resources (clear timer, reset state, flush pending). */ dispose(): Promise; } export {};