UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

114 lines (113 loc) • 2.98 kB
/** * Task Distributor - Distributes and balances tasks across agents * * The Task Distributor handles: * - Task decomposition into subtasks * - Load balancing across available agents * - Priority-based task queuing * - Task affinity and skill matching */ import type { Agent } from "../agent.js"; import type { TaskAnalysis, DistributableTask, DistributionResult, AgentCapability, TaskDistributorConfig } from "../../types/index.js"; /** * Task Distributor - Manages task distribution across agents */ export declare class TaskDistributor { private agents; private capabilities; private taskQueue; private activeResults; private config; private emitter; private isProcessing; constructor(config: TaskDistributorConfig); /** * Register an agent with capabilities */ registerAgent(agent: Agent, capability?: Partial<AgentCapability>): void; /** * Unregister an agent */ unregisterAgent(agentId: string): void; /** * Update agent capability */ updateCapability(agentId: string, update: Partial<AgentCapability>): void; /** * Submit a task for distribution */ submitTask(task: DistributableTask): Promise<DistributionResult>; /** * Submit multiple tasks */ submitTasks(tasks: DistributableTask[]): Promise<DistributionResult[]>; /** * Decompose a complex task into subtasks */ decomposeTask(task: DistributableTask, analysis: TaskAnalysis): Promise<DistributableTask[]>; /** * Process the task queue */ private processQueue; /** * Select an agent based on strategy */ private selectAgent; /** * Select agent by skill match */ private selectBySkill; /** * Select agent by load */ private selectByLoad; /** * Select agent by priority matching */ private selectByPriority; /** * Select agent by affinity */ private selectByAffinity; /** * Execute a task on an agent */ private executeTask; /** * Broadcast a task to all agents */ broadcastTask(task: DistributableTask): Promise<Map<string, DistributionResult>>; /** * Get task result */ getTaskResult(taskId: string): DistributionResult | undefined; /** * Get queue status */ getQueueStatus(): { pending: number; active: number; completed: number; failed: number; }; /** * Clear completed/failed tasks */ clearCompleted(): void; /** * Fail all queued tasks (used on deadlock detection) */ private failAllQueuedTasks; /** * Helper delay function */ private delay; /** * Subscribe to distributor events */ on(event: string, handler: (...args: unknown[]) => void): void; /** * Unsubscribe from distributor events */ off(event: string, handler: (...args: unknown[]) => void): void; }