/** * Unified plugin execution dispatcher. * * ALL plugin calls — hook triggers, MCP events, interval ticks — go through * this dispatcher. It provides: * * - Per-plugin bounded event queue (drop oldest on overflow) * - Serial execution per plugin (prevents state races) * - Parallel execution across plugins * - AbortSignal timeout on every call (actually cancels fetch/IO) * - Clean error handling: failures → null result + stderr log, never crash * * The dispatcher is plugin-agnostic. Callers provide an executor function * that receives an AbortSignal and returns a result. The dispatcher manages * queuing, scheduling, and timeout — nothing else. */ import type { GatherResult } from './types.ts'; export interface DispatcherOptions { /** Default timeout in ms for plugin execution (default: 30000). */ defaultTimeout?: number; /** Default max queue depth per plugin (default: 3). */ defaultMaxQueue?: number; } export interface PluginLimits { timeout?: number; maxQueue?: number; } /** Function that does the actual plugin work. Receives AbortSignal for cancellation. */ export type Executor = (signal: AbortSignal) => Promise; export declare class PluginDispatcher { #private; constructor(options?: DispatcherOptions); /** Set per-plugin timeout and queue limits. */ configure(pluginName: string, limits: PluginLimits): void; /** * Dispatch a single plugin execution. * * Queues the executor, processes serially per plugin, applies timeout. * Resolves with the result or null on error/timeout — never rejects. */ dispatch(pluginName: string, executor: Executor): Promise; /** * Dispatch multiple plugins in parallel, collect results. * Each plugin runs independently — one failure doesn't affect others. */ dispatchAll(entries: Array<{ pluginName: string; executor: Executor; }>): Promise>; /** Number of queued (not yet processing) entries for a plugin. */ queueDepth(pluginName: string): number; /** Whether a plugin is currently executing. */ isProcessing(pluginName: string): boolean; }