@trenchwork/erosolar 1.1.63 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +4 -48
- package/dist/core/agent.js.map +1 -1
- package/dist/core/contextManager.d.ts.map +1 -1
- package/dist/core/contextManager.js +5 -2
- package/dist/core/contextManager.js.map +1 -1
- package/dist/core/errorClassification.d.ts +44 -0
- package/dist/core/errorClassification.d.ts.map +1 -0
- package/dist/core/errorClassification.js +333 -0
- package/dist/core/errorClassification.js.map +1 -0
- package/dist/core/hitl.d.ts.map +1 -1
- package/dist/core/hitl.js +8 -0
- package/dist/core/hitl.js.map +1 -1
- package/dist/core/hostedAuth.d.ts +33 -0
- package/dist/core/hostedAuth.d.ts.map +1 -1
- package/dist/core/hostedAuth.js +85 -0
- package/dist/core/hostedAuth.js.map +1 -1
- package/dist/core/quota.d.ts +61 -0
- package/dist/core/quota.d.ts.map +1 -0
- package/dist/core/quota.js +104 -0
- package/dist/core/quota.js.map +1 -0
- package/dist/core/quotaErrors.d.ts.map +1 -1
- package/dist/core/quotaErrors.js +3 -5
- package/dist/core/quotaErrors.js.map +1 -1
- package/dist/core/resultVerification.d.ts +3 -2
- package/dist/core/resultVerification.d.ts.map +1 -1
- package/dist/core/resultVerification.js +3 -2
- package/dist/core/resultVerification.js.map +1 -1
- package/dist/core/slashCommands.d.ts.map +1 -1
- package/dist/core/slashCommands.js +3 -0
- package/dist/core/slashCommands.js.map +1 -1
- package/dist/core/updateChecker.d.ts.map +1 -1
- package/dist/core/updateChecker.js +5 -1
- package/dist/core/updateChecker.js.map +1 -1
- package/dist/core/usage.d.ts +28 -0
- package/dist/core/usage.d.ts.map +1 -0
- package/dist/core/usage.js +77 -0
- package/dist/core/usage.js.map +1 -0
- package/dist/headless/interactiveShell.d.ts +2 -0
- package/dist/headless/interactiveShell.d.ts.map +1 -1
- package/dist/headless/interactiveShell.js +99 -9
- package/dist/headless/interactiveShell.js.map +1 -1
- package/dist/plugins/providers/deepseek/index.d.ts.map +1 -1
- package/dist/plugins/providers/deepseek/index.js +8 -5
- package/dist/plugins/providers/deepseek/index.js.map +1 -1
- package/dist/providers/baseProvider.d.ts +5 -13
- package/dist/providers/baseProvider.d.ts.map +1 -1
- package/dist/providers/baseProvider.js +12 -66
- package/dist/providers/baseProvider.js.map +1 -1
- package/dist/providers/openaiChatCompletionsProvider.d.ts.map +1 -1
- package/dist/providers/openaiChatCompletionsProvider.js +27 -76
- package/dist/providers/openaiChatCompletionsProvider.js.map +1 -1
- package/dist/providers/resilientProvider.d.ts +2 -9
- package/dist/providers/resilientProvider.d.ts.map +1 -1
- package/dist/providers/resilientProvider.js +13 -199
- package/dist/providers/resilientProvider.js.map +1 -1
- package/dist/shell/toolPresentation.d.ts.map +1 -1
- package/dist/shell/toolPresentation.js +27 -3
- package/dist/shell/toolPresentation.js.map +1 -1
- package/dist/tools/bashTools.d.ts.map +1 -1
- package/dist/tools/bashTools.js +9 -3
- package/dist/tools/bashTools.js.map +1 -1
- package/dist/tools/grepTools.d.ts.map +1 -1
- package/dist/tools/grepTools.js +10 -1
- package/dist/tools/grepTools.js.map +1 -1
- package/dist/tools/searchTools.d.ts.map +1 -1
- package/dist/tools/searchTools.js +5 -4
- package/dist/tools/searchTools.js.map +1 -1
- package/dist/tools/webTools.d.ts.map +1 -1
- package/dist/tools/webTools.js +3 -1
- package/dist/tools/webTools.js.map +1 -1
- package/dist/ui/ink/ChatStatic.d.ts.map +1 -1
- package/dist/ui/ink/ChatStatic.js +21 -5
- package/dist/ui/ink/ChatStatic.js.map +1 -1
- package/dist/ui/ink/InkPromptController.d.ts +3 -0
- package/dist/ui/ink/InkPromptController.d.ts.map +1 -1
- package/dist/ui/ink/InkPromptController.js +12 -6
- package/dist/ui/ink/InkPromptController.js.map +1 -1
- package/dist/ui/ink/Prompt.d.ts +4 -0
- package/dist/ui/ink/Prompt.d.ts.map +1 -1
- package/dist/ui/ink/Prompt.js +62 -10
- package/dist/ui/ink/Prompt.js.map +1 -1
- package/dist/ui/ink/pasteBuffer.d.ts +44 -0
- package/dist/ui/ink/pasteBuffer.d.ts.map +1 -0
- package/dist/ui/ink/pasteBuffer.js +73 -0
- package/dist/ui/ink/pasteBuffer.js.map +1 -0
- package/package.json +1 -1
- package/dist/core/index.d.ts +0 -7
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -7
- package/dist/core/index.js.map +0 -1
- package/dist/core/providerKeys.d.ts +0 -20
- package/dist/core/providerKeys.d.ts.map +0 -1
- package/dist/core/providerKeys.js +0 -40
- package/dist/core/providerKeys.js.map +0 -1
- package/dist/plugins/index.d.ts +0 -49
- package/dist/plugins/index.d.ts.map +0 -1
- package/dist/plugins/index.js +0 -104
- package/dist/plugins/index.js.map +0 -1
- package/dist/plugins/tools/agentSpawning/agentSpawningPlugin.d.ts +0 -10
- package/dist/plugins/tools/agentSpawning/agentSpawningPlugin.d.ts.map +0 -1
- package/dist/plugins/tools/agentSpawning/agentSpawningPlugin.js +0 -110
- package/dist/plugins/tools/agentSpawning/agentSpawningPlugin.js.map +0 -1
- package/dist/plugins/tools/bash/localBashPlugin.d.ts +0 -3
- package/dist/plugins/tools/bash/localBashPlugin.d.ts.map +0 -1
- package/dist/plugins/tools/bash/localBashPlugin.js +0 -14
- package/dist/plugins/tools/bash/localBashPlugin.js.map +0 -1
- package/dist/plugins/tools/edit/editPlugin.d.ts +0 -9
- package/dist/plugins/tools/edit/editPlugin.d.ts.map +0 -1
- package/dist/plugins/tools/edit/editPlugin.js +0 -15
- package/dist/plugins/tools/edit/editPlugin.js.map +0 -1
- package/dist/plugins/tools/enhancedGit/enhancedGitPlugin.d.ts +0 -3
- package/dist/plugins/tools/enhancedGit/enhancedGitPlugin.d.ts.map +0 -1
- package/dist/plugins/tools/enhancedGit/enhancedGitPlugin.js +0 -9
- package/dist/plugins/tools/enhancedGit/enhancedGitPlugin.js.map +0 -1
- package/dist/plugins/tools/filesystem/localFilesystemPlugin.d.ts +0 -3
- package/dist/plugins/tools/filesystem/localFilesystemPlugin.d.ts.map +0 -1
- package/dist/plugins/tools/filesystem/localFilesystemPlugin.js +0 -14
- package/dist/plugins/tools/filesystem/localFilesystemPlugin.js.map +0 -1
- package/dist/plugins/tools/gitHistory/gitHistoryPlugin.d.ts +0 -3
- package/dist/plugins/tools/gitHistory/gitHistoryPlugin.d.ts.map +0 -1
- package/dist/plugins/tools/gitHistory/gitHistoryPlugin.js +0 -9
- package/dist/plugins/tools/gitHistory/gitHistoryPlugin.js.map +0 -1
- package/dist/plugins/tools/index.d.ts +0 -3
- package/dist/plugins/tools/index.d.ts.map +0 -1
- package/dist/plugins/tools/index.js +0 -3
- package/dist/plugins/tools/index.js.map +0 -1
- package/dist/plugins/tools/integrity/integrityPlugin.d.ts +0 -3
- package/dist/plugins/tools/integrity/integrityPlugin.d.ts.map +0 -1
- package/dist/plugins/tools/integrity/integrityPlugin.js +0 -31
- package/dist/plugins/tools/integrity/integrityPlugin.js.map +0 -1
- package/dist/plugins/tools/mcp/mcpPlugin.d.ts +0 -3
- package/dist/plugins/tools/mcp/mcpPlugin.d.ts.map +0 -1
- package/dist/plugins/tools/mcp/mcpPlugin.js +0 -27
- package/dist/plugins/tools/mcp/mcpPlugin.js.map +0 -1
- package/dist/plugins/tools/nodeDefaults.d.ts +0 -13
- package/dist/plugins/tools/nodeDefaults.d.ts.map +0 -1
- package/dist/plugins/tools/nodeDefaults.js +0 -33
- package/dist/plugins/tools/nodeDefaults.js.map +0 -1
- package/dist/plugins/tools/orchestration/orchestrationPlugin.d.ts +0 -3
- package/dist/plugins/tools/orchestration/orchestrationPlugin.d.ts.map +0 -1
- package/dist/plugins/tools/orchestration/orchestrationPlugin.js +0 -340
- package/dist/plugins/tools/orchestration/orchestrationPlugin.js.map +0 -1
- package/dist/plugins/tools/registry.d.ts +0 -22
- package/dist/plugins/tools/registry.d.ts.map +0 -1
- package/dist/plugins/tools/registry.js +0 -58
- package/dist/plugins/tools/registry.js.map +0 -1
- package/dist/plugins/tools/search/localSearchPlugin.d.ts +0 -3
- package/dist/plugins/tools/search/localSearchPlugin.d.ts.map +0 -1
- package/dist/plugins/tools/search/localSearchPlugin.js +0 -14
- package/dist/plugins/tools/search/localSearchPlugin.js.map +0 -1
- package/dist/plugins/tools/skills/skillPlugin.d.ts +0 -3
- package/dist/plugins/tools/skills/skillPlugin.d.ts.map +0 -1
- package/dist/plugins/tools/skills/skillPlugin.js +0 -27
- package/dist/plugins/tools/skills/skillPlugin.js.map +0 -1
- package/dist/plugins/tools/todo/todoPlugin.d.ts +0 -3
- package/dist/plugins/tools/todo/todoPlugin.d.ts.map +0 -1
- package/dist/plugins/tools/todo/todoPlugin.js +0 -10
- package/dist/plugins/tools/todo/todoPlugin.js.map +0 -1
- package/dist/runtime/agentWorkerPool.d.ts +0 -167
- package/dist/runtime/agentWorkerPool.d.ts.map +0 -1
- package/dist/runtime/agentWorkerPool.js +0 -435
- package/dist/runtime/agentWorkerPool.js.map +0 -1
- package/dist/shell/autoExecutor.d.ts +0 -70
- package/dist/shell/autoExecutor.d.ts.map +0 -1
- package/dist/shell/autoExecutor.js +0 -320
- package/dist/shell/autoExecutor.js.map +0 -1
- package/dist/shell/commandRegistry.d.ts +0 -122
- package/dist/shell/commandRegistry.d.ts.map +0 -1
- package/dist/shell/commandRegistry.js +0 -355
- package/dist/shell/commandRegistry.js.map +0 -1
- package/dist/shell/composableMessage.d.ts +0 -178
- package/dist/shell/composableMessage.d.ts.map +0 -1
- package/dist/shell/composableMessage.js +0 -384
- package/dist/shell/composableMessage.js.map +0 -1
- package/dist/shell/vimMode.d.ts +0 -66
- package/dist/shell/vimMode.d.ts.map +0 -1
- package/dist/shell/vimMode.js +0 -435
- package/dist/shell/vimMode.js.map +0 -1
- package/dist/tools/localExplore.d.ts +0 -38
- package/dist/tools/localExplore.d.ts.map +0 -1
- package/dist/tools/localExplore.js +0 -30
- package/dist/tools/localExplore.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"skillPlugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/tools/skills/skillPlugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAyBjD,wBAAgB,qBAAqB,IAAI,UAAU,CAMlD"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
class SkillCapabilityModule {
|
|
2
|
-
id = 'tool.skills';
|
|
3
|
-
description = 'Reusable skill library (stub)';
|
|
4
|
-
async create() {
|
|
5
|
-
const tools = [
|
|
6
|
-
{
|
|
7
|
-
name: 'list_skills',
|
|
8
|
-
description: 'List available skills.',
|
|
9
|
-
handler: async () => 'Skills: summarize, refactor, test',
|
|
10
|
-
},
|
|
11
|
-
];
|
|
12
|
-
const toolSuite = {
|
|
13
|
-
id: 'skills.tools',
|
|
14
|
-
description: 'Skill helpers',
|
|
15
|
-
tools,
|
|
16
|
-
};
|
|
17
|
-
return { id: this.id, description: this.description, toolSuite };
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export function createSkillToolPlugin() {
|
|
21
|
-
return {
|
|
22
|
-
id: 'tool.skills',
|
|
23
|
-
targets: ['universal'],
|
|
24
|
-
create: () => new SkillCapabilityModule(),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=skillPlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"skillPlugin.js","sourceRoot":"","sources":["../../../../src/plugins/tools/skills/skillPlugin.ts"],"names":[],"mappings":"AAIA,MAAM,qBAAqB;IACzB,EAAE,GAAG,aAAa,CAAC;IACnB,WAAW,GAAG,+BAA+B,CAAC;IAE9C,KAAK,CAAC,MAAM;QACV,MAAM,KAAK,GAAqB;YAC9B;gBACE,IAAI,EAAE,aAAa;gBACnB,WAAW,EAAE,wBAAwB;gBACrC,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,mCAAmC;aACzD;SACF,CAAC;QAEF,MAAM,SAAS,GAAc;YAC3B,EAAE,EAAE,cAAc;YAClB,WAAW,EAAE,eAAe;YAC5B,KAAK;SACN,CAAC;QAEF,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC;IACnE,CAAC;CACF;AAED,MAAM,UAAU,qBAAqB;IACnC,OAAO;QACL,EAAE,EAAE,aAAa;QACjB,OAAO,EAAE,CAAC,WAAW,CAAC;QACtB,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,qBAAqB,EAAE;KAC1C,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"todoPlugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/tools/todo/todoPlugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,wBAAgB,oBAAoB,IAAI,UAAU,CAOjD"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { TodoCapabilityModule } from '../../../capabilities/todoCapability.js';
|
|
2
|
-
export function createTodoToolPlugin() {
|
|
3
|
-
return {
|
|
4
|
-
id: 'tool.todo',
|
|
5
|
-
description: 'TodoRead + TodoWrite — Claude-Code-style task list for the agent.',
|
|
6
|
-
targets: ['node', 'cloud', 'browser', 'universal'],
|
|
7
|
-
create: () => new TodoCapabilityModule(),
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=todoPlugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"todoPlugin.js","sourceRoot":"","sources":["../../../../src/plugins/tools/todo/todoPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAG/E,MAAM,UAAU,oBAAoB;IAClC,OAAO;QACL,EAAE,EAAE,WAAW;QACf,WAAW,EAAE,mEAAmE;QAChF,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,CAAC;QAClD,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,oBAAoB,EAAE;KACzC,CAAC;AACJ,CAAC"}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent Worker Pool Module
|
|
3
|
-
*
|
|
4
|
-
* Provides multi-agent parallelism with automatic load balancing,
|
|
5
|
-
* work distribution, and result aggregation for AGI workflows.
|
|
6
|
-
*
|
|
7
|
-
* Principal Investigator: Bo Shang
|
|
8
|
-
* Framework: agi-cli
|
|
9
|
-
*/
|
|
10
|
-
import type { AgentController } from './agentController.js';
|
|
11
|
-
import type { AgentEventUnion } from '../contracts/v1/agent.js';
|
|
12
|
-
export type WorkerStatus = 'idle' | 'busy' | 'error' | 'offline';
|
|
13
|
-
export type BalanceStrategy = 'round-robin' | 'least-busy' | 'random' | 'priority';
|
|
14
|
-
export interface AgentWorkerConfig {
|
|
15
|
-
/** Unique worker identifier */
|
|
16
|
-
id: string;
|
|
17
|
-
/** Agent controller factory or instance */
|
|
18
|
-
createController: () => Promise<AgentController> | AgentController;
|
|
19
|
-
/** Maximum concurrent tasks this worker can handle (default: 1) */
|
|
20
|
-
maxConcurrency?: number;
|
|
21
|
-
/** Priority for task assignment (higher = preferred) */
|
|
22
|
-
priority?: number;
|
|
23
|
-
/** Tags for routing specific task types */
|
|
24
|
-
tags?: string[];
|
|
25
|
-
}
|
|
26
|
-
export interface AgentTask<T = string> {
|
|
27
|
-
/** Unique task identifier */
|
|
28
|
-
id: string;
|
|
29
|
-
/** The message/prompt to send to the agent */
|
|
30
|
-
message: string;
|
|
31
|
-
/** Optional transformer for the result */
|
|
32
|
-
transform?: (result: string) => T;
|
|
33
|
-
/** Required worker tags (task routed to workers with all these tags) */
|
|
34
|
-
requiredTags?: string[];
|
|
35
|
-
/** Preferred worker ID (soft preference) */
|
|
36
|
-
preferredWorker?: string;
|
|
37
|
-
/** Task priority (higher = processed first) */
|
|
38
|
-
priority?: number;
|
|
39
|
-
/** Timeout in milliseconds */
|
|
40
|
-
timeout?: number;
|
|
41
|
-
/** Whether to stream events */
|
|
42
|
-
streaming?: boolean;
|
|
43
|
-
/** Callback for streaming events */
|
|
44
|
-
onEvent?: (event: AgentEventUnion) => void;
|
|
45
|
-
}
|
|
46
|
-
export interface TaskResult<T = string> {
|
|
47
|
-
taskId: string;
|
|
48
|
-
workerId: string;
|
|
49
|
-
success: boolean;
|
|
50
|
-
result?: T;
|
|
51
|
-
error?: Error;
|
|
52
|
-
durationMs: number;
|
|
53
|
-
startedAt: number;
|
|
54
|
-
completedAt: number;
|
|
55
|
-
}
|
|
56
|
-
export interface AgentWorkerPoolConfig {
|
|
57
|
-
/** Worker configurations */
|
|
58
|
-
workers: AgentWorkerConfig[];
|
|
59
|
-
/** Load balancing strategy (default: 'least-busy') */
|
|
60
|
-
balanceStrategy?: BalanceStrategy;
|
|
61
|
-
/** Default task timeout in ms (default: 24 hours - 86400000ms) */
|
|
62
|
-
defaultTimeout?: number;
|
|
63
|
-
/** Maximum queue size before rejecting tasks (default: 100) */
|
|
64
|
-
maxQueueSize?: number;
|
|
65
|
-
/** Callback for pool events */
|
|
66
|
-
onEvent?: (event: PoolEvent) => void;
|
|
67
|
-
}
|
|
68
|
-
export interface PoolEvent {
|
|
69
|
-
type: 'worker.ready' | 'worker.busy' | 'worker.idle' | 'worker.error' | 'task.queued' | 'task.started' | 'task.completed' | 'task.failed' | 'pool.saturated' | 'pool.drained';
|
|
70
|
-
timestamp: number;
|
|
71
|
-
workerId?: string;
|
|
72
|
-
taskId?: string;
|
|
73
|
-
data?: Record<string, unknown>;
|
|
74
|
-
}
|
|
75
|
-
export interface WorkerInfo {
|
|
76
|
-
id: string;
|
|
77
|
-
status: WorkerStatus;
|
|
78
|
-
activeTasks: number;
|
|
79
|
-
completedTasks: number;
|
|
80
|
-
failedTasks: number;
|
|
81
|
-
tags: string[];
|
|
82
|
-
priority: number;
|
|
83
|
-
}
|
|
84
|
-
export interface PoolStats {
|
|
85
|
-
totalWorkers: number;
|
|
86
|
-
activeWorkers: number;
|
|
87
|
-
idleWorkers: number;
|
|
88
|
-
queuedTasks: number;
|
|
89
|
-
activeTasks: number;
|
|
90
|
-
completedTasks: number;
|
|
91
|
-
failedTasks: number;
|
|
92
|
-
averageTaskDurationMs: number;
|
|
93
|
-
}
|
|
94
|
-
export declare class AgentWorkerPool {
|
|
95
|
-
private readonly workers;
|
|
96
|
-
private readonly taskQueue;
|
|
97
|
-
private readonly balanceStrategy;
|
|
98
|
-
private readonly defaultTimeout;
|
|
99
|
-
private readonly maxQueueSize;
|
|
100
|
-
private readonly onEvent;
|
|
101
|
-
private roundRobinIndex;
|
|
102
|
-
private totalTaskDuration;
|
|
103
|
-
private completedTaskCount;
|
|
104
|
-
private processing;
|
|
105
|
-
constructor(config: AgentWorkerPoolConfig);
|
|
106
|
-
/**
|
|
107
|
-
* Initialize all workers
|
|
108
|
-
*/
|
|
109
|
-
initialize(): Promise<void>;
|
|
110
|
-
/**
|
|
111
|
-
* Submit a task to the pool
|
|
112
|
-
*/
|
|
113
|
-
submit<T>(task: AgentTask<T>): Promise<TaskResult<T>>;
|
|
114
|
-
/**
|
|
115
|
-
* Submit multiple tasks and wait for all results
|
|
116
|
-
*/
|
|
117
|
-
submitAll<T>(tasks: AgentTask<T>[]): Promise<TaskResult<T>[]>;
|
|
118
|
-
/**
|
|
119
|
-
* Submit multiple tasks and process results as they complete
|
|
120
|
-
*/
|
|
121
|
-
submitStream<T>(tasks: AgentTask<T>[]): AsyncGenerator<TaskResult<T>>;
|
|
122
|
-
/**
|
|
123
|
-
* Process queued tasks
|
|
124
|
-
*/
|
|
125
|
-
private processQueue;
|
|
126
|
-
/**
|
|
127
|
-
* Execute a task on a worker
|
|
128
|
-
*/
|
|
129
|
-
private executeTask;
|
|
130
|
-
/**
|
|
131
|
-
* Select a worker based on the balancing strategy
|
|
132
|
-
*/
|
|
133
|
-
private selectWorker;
|
|
134
|
-
/**
|
|
135
|
-
* Get available workers filtered by task requirements
|
|
136
|
-
*/
|
|
137
|
-
private getAvailableWorkers;
|
|
138
|
-
/**
|
|
139
|
-
* Get information about all workers
|
|
140
|
-
*/
|
|
141
|
-
getWorkerInfo(): WorkerInfo[];
|
|
142
|
-
/**
|
|
143
|
-
* Get pool statistics
|
|
144
|
-
*/
|
|
145
|
-
getStats(): PoolStats;
|
|
146
|
-
/**
|
|
147
|
-
* Cancel all queued tasks
|
|
148
|
-
*/
|
|
149
|
-
cancelAll(): number;
|
|
150
|
-
private emit;
|
|
151
|
-
private sleep;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Create an agent worker pool with the given configuration
|
|
155
|
-
*/
|
|
156
|
-
export declare function createAgentWorkerPool(config: AgentWorkerPoolConfig): AgentWorkerPool;
|
|
157
|
-
/**
|
|
158
|
-
* Create a simple agent task
|
|
159
|
-
*/
|
|
160
|
-
export declare function createAgentTask<T = string>(id: string, message: string, options?: Partial<Omit<AgentTask<T>, 'id' | 'message'>>): AgentTask<T>;
|
|
161
|
-
declare const _default: {
|
|
162
|
-
AgentWorkerPool: typeof AgentWorkerPool;
|
|
163
|
-
createAgentWorkerPool: typeof createAgentWorkerPool;
|
|
164
|
-
createAgentTask: typeof createAgentTask;
|
|
165
|
-
};
|
|
166
|
-
export default _default;
|
|
167
|
-
//# sourceMappingURL=agentWorkerPool.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"agentWorkerPool.d.ts","sourceRoot":"","sources":["../../src/runtime/agentWorkerPool.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAMhE,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAA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Gd;AAMD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,GAAG,eAAe,CAEpF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,GAAG,MAAM,EACxC,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC,CAAC,GACtD,SAAS,CAAC,CAAC,CAAC,CAMd;;;;;;AAMD,wBAIE"}
|
|
@@ -1,435 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent Worker Pool Module
|
|
3
|
-
*
|
|
4
|
-
* Provides multi-agent parallelism with automatic load balancing,
|
|
5
|
-
* work distribution, and result aggregation for AGI workflows.
|
|
6
|
-
*
|
|
7
|
-
* Principal Investigator: Bo Shang
|
|
8
|
-
* Framework: agi-cli
|
|
9
|
-
*/
|
|
10
|
-
// ============================================================================
|
|
11
|
-
// Agent Worker
|
|
12
|
-
// ============================================================================
|
|
13
|
-
class AgentWorker {
|
|
14
|
-
id;
|
|
15
|
-
maxConcurrency;
|
|
16
|
-
priority;
|
|
17
|
-
tags;
|
|
18
|
-
controller = null;
|
|
19
|
-
createController;
|
|
20
|
-
activeTasks = 0;
|
|
21
|
-
_completedTasks = 0;
|
|
22
|
-
_failedTasks = 0;
|
|
23
|
-
_status = 'idle';
|
|
24
|
-
constructor(config) {
|
|
25
|
-
this.id = config.id;
|
|
26
|
-
this.createController = config.createController;
|
|
27
|
-
this.maxConcurrency = config.maxConcurrency ?? 1;
|
|
28
|
-
this.priority = config.priority ?? 0;
|
|
29
|
-
this.tags = new Set(config.tags ?? []);
|
|
30
|
-
}
|
|
31
|
-
get status() {
|
|
32
|
-
return this._status;
|
|
33
|
-
}
|
|
34
|
-
get completedTasks() {
|
|
35
|
-
return this._completedTasks;
|
|
36
|
-
}
|
|
37
|
-
get failedTasks() {
|
|
38
|
-
return this._failedTasks;
|
|
39
|
-
}
|
|
40
|
-
get currentLoad() {
|
|
41
|
-
return this.activeTasks;
|
|
42
|
-
}
|
|
43
|
-
get isAvailable() {
|
|
44
|
-
return this._status !== 'offline' && this._status !== 'error' && this.activeTasks < this.maxConcurrency;
|
|
45
|
-
}
|
|
46
|
-
hasTags(requiredTags) {
|
|
47
|
-
return requiredTags.every(tag => this.tags.has(tag));
|
|
48
|
-
}
|
|
49
|
-
async initialize() {
|
|
50
|
-
if (this.controller)
|
|
51
|
-
return;
|
|
52
|
-
try {
|
|
53
|
-
this.controller = await this.createController();
|
|
54
|
-
this._status = 'idle';
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
this._status = 'error';
|
|
58
|
-
throw error;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
async execute(task) {
|
|
62
|
-
if (!this.controller) {
|
|
63
|
-
await this.initialize();
|
|
64
|
-
}
|
|
65
|
-
if (!this.controller) {
|
|
66
|
-
throw new Error(`Worker ${this.id} failed to initialize`);
|
|
67
|
-
}
|
|
68
|
-
this.activeTasks++;
|
|
69
|
-
this._status = this.activeTasks >= this.maxConcurrency ? 'busy' : 'idle';
|
|
70
|
-
try {
|
|
71
|
-
let result = '';
|
|
72
|
-
if (task.streaming && task.onEvent) {
|
|
73
|
-
// Streaming mode: collect events and final result
|
|
74
|
-
for await (const event of this.controller.send(task.message)) {
|
|
75
|
-
task.onEvent(event);
|
|
76
|
-
if (event.type === 'message.complete') {
|
|
77
|
-
result = event.content;
|
|
78
|
-
}
|
|
79
|
-
else if (event.type === 'message.delta') {
|
|
80
|
-
result += event.content;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
// Non-streaming: collect complete response
|
|
86
|
-
for await (const event of this.controller.send(task.message)) {
|
|
87
|
-
if (event.type === 'message.complete') {
|
|
88
|
-
result = event.content;
|
|
89
|
-
}
|
|
90
|
-
else if (event.type === 'message.delta') {
|
|
91
|
-
result += event.content;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
this._completedTasks++;
|
|
96
|
-
return task.transform ? task.transform(result) : result;
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
this._failedTasks++;
|
|
100
|
-
throw error;
|
|
101
|
-
}
|
|
102
|
-
finally {
|
|
103
|
-
this.activeTasks--;
|
|
104
|
-
this._status = this.activeTasks > 0 ? 'busy' : 'idle';
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
getInfo() {
|
|
108
|
-
return {
|
|
109
|
-
id: this.id,
|
|
110
|
-
status: this._status,
|
|
111
|
-
activeTasks: this.activeTasks,
|
|
112
|
-
completedTasks: this._completedTasks,
|
|
113
|
-
failedTasks: this._failedTasks,
|
|
114
|
-
tags: Array.from(this.tags),
|
|
115
|
-
priority: this.priority,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
// ============================================================================
|
|
120
|
-
// Agent Worker Pool
|
|
121
|
-
// ============================================================================
|
|
122
|
-
export class AgentWorkerPool {
|
|
123
|
-
workers = new Map();
|
|
124
|
-
taskQueue = [];
|
|
125
|
-
balanceStrategy;
|
|
126
|
-
defaultTimeout;
|
|
127
|
-
maxQueueSize;
|
|
128
|
-
onEvent;
|
|
129
|
-
roundRobinIndex = 0;
|
|
130
|
-
totalTaskDuration = 0;
|
|
131
|
-
completedTaskCount = 0;
|
|
132
|
-
processing = false;
|
|
133
|
-
constructor(config) {
|
|
134
|
-
this.balanceStrategy = config.balanceStrategy ?? 'least-busy';
|
|
135
|
-
this.defaultTimeout = config.defaultTimeout ?? 24 * 60 * 60 * 1000; // 24 hours default timeout
|
|
136
|
-
this.maxQueueSize = config.maxQueueSize ?? 100;
|
|
137
|
-
this.onEvent = config.onEvent ?? (() => { });
|
|
138
|
-
for (const workerConfig of config.workers) {
|
|
139
|
-
const worker = new AgentWorker(workerConfig);
|
|
140
|
-
this.workers.set(worker.id, worker);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Initialize all workers
|
|
145
|
-
*/
|
|
146
|
-
async initialize() {
|
|
147
|
-
const initPromises = Array.from(this.workers.values()).map(async (worker) => {
|
|
148
|
-
try {
|
|
149
|
-
await worker.initialize();
|
|
150
|
-
this.emit({ type: 'worker.ready', workerId: worker.id, timestamp: Date.now() });
|
|
151
|
-
}
|
|
152
|
-
catch (error) {
|
|
153
|
-
this.emit({
|
|
154
|
-
type: 'worker.error',
|
|
155
|
-
workerId: worker.id,
|
|
156
|
-
timestamp: Date.now(),
|
|
157
|
-
data: { error: error instanceof Error ? error.message : String(error) },
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
await Promise.allSettled(initPromises);
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Submit a task to the pool
|
|
165
|
-
*/
|
|
166
|
-
async submit(task) {
|
|
167
|
-
if (this.taskQueue.length >= this.maxQueueSize) {
|
|
168
|
-
throw new Error('Task queue is full');
|
|
169
|
-
}
|
|
170
|
-
return new Promise((resolve, reject) => {
|
|
171
|
-
this.taskQueue.push({
|
|
172
|
-
task: task,
|
|
173
|
-
resolve: resolve,
|
|
174
|
-
reject,
|
|
175
|
-
queuedAt: Date.now(),
|
|
176
|
-
});
|
|
177
|
-
this.emit({
|
|
178
|
-
type: 'task.queued',
|
|
179
|
-
taskId: task.id,
|
|
180
|
-
timestamp: Date.now(),
|
|
181
|
-
data: { queueLength: this.taskQueue.length },
|
|
182
|
-
});
|
|
183
|
-
if (this.taskQueue.length >= this.maxQueueSize) {
|
|
184
|
-
this.emit({ type: 'pool.saturated', timestamp: Date.now() });
|
|
185
|
-
}
|
|
186
|
-
// Trigger processing
|
|
187
|
-
this.processQueue();
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Submit multiple tasks and wait for all results
|
|
192
|
-
*/
|
|
193
|
-
async submitAll(tasks) {
|
|
194
|
-
const promises = tasks.map(task => this.submit(task));
|
|
195
|
-
return Promise.all(promises);
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Submit multiple tasks and process results as they complete
|
|
199
|
-
*/
|
|
200
|
-
async *submitStream(tasks) {
|
|
201
|
-
const pending = tasks.map(task => this.submit(task));
|
|
202
|
-
while (pending.length > 0) {
|
|
203
|
-
const result = await Promise.race(pending.map((p, i) => p.then(r => ({ result: r, index: i }))));
|
|
204
|
-
pending.splice(result.index, 1);
|
|
205
|
-
yield result.result;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Process queued tasks
|
|
210
|
-
*/
|
|
211
|
-
async processQueue() {
|
|
212
|
-
if (this.processing)
|
|
213
|
-
return;
|
|
214
|
-
this.processing = true;
|
|
215
|
-
try {
|
|
216
|
-
while (this.taskQueue.length > 0) {
|
|
217
|
-
const worker = this.selectWorker(this.taskQueue[0]?.task);
|
|
218
|
-
if (!worker) {
|
|
219
|
-
// No available workers, wait and retry
|
|
220
|
-
await this.sleep(50);
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
const item = this.taskQueue.shift();
|
|
224
|
-
if (!item)
|
|
225
|
-
break;
|
|
226
|
-
// Execute task asynchronously (don't await)
|
|
227
|
-
this.executeTask(worker, item.task, item.resolve, item.reject, item.queuedAt);
|
|
228
|
-
}
|
|
229
|
-
if (this.taskQueue.length === 0) {
|
|
230
|
-
this.emit({ type: 'pool.drained', timestamp: Date.now() });
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
finally {
|
|
234
|
-
this.processing = false;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Execute a task on a worker
|
|
239
|
-
*/
|
|
240
|
-
async executeTask(worker, task, resolve, reject, queuedAt) {
|
|
241
|
-
const startedAt = Date.now();
|
|
242
|
-
this.emit({
|
|
243
|
-
type: 'task.started',
|
|
244
|
-
taskId: task.id,
|
|
245
|
-
workerId: worker.id,
|
|
246
|
-
timestamp: startedAt,
|
|
247
|
-
data: { queueWaitMs: startedAt - queuedAt },
|
|
248
|
-
});
|
|
249
|
-
this.emit({ type: 'worker.busy', workerId: worker.id, timestamp: startedAt });
|
|
250
|
-
try {
|
|
251
|
-
const timeout = task.timeout ?? this.defaultTimeout;
|
|
252
|
-
const result = await Promise.race([
|
|
253
|
-
worker.execute(task),
|
|
254
|
-
new Promise((_, rej) => setTimeout(() => rej(new Error(`Task ${task.id} timed out after ${timeout}ms`)), timeout)),
|
|
255
|
-
]);
|
|
256
|
-
const completedAt = Date.now();
|
|
257
|
-
const durationMs = completedAt - startedAt;
|
|
258
|
-
this.totalTaskDuration += durationMs;
|
|
259
|
-
this.completedTaskCount++;
|
|
260
|
-
this.emit({
|
|
261
|
-
type: 'task.completed',
|
|
262
|
-
taskId: task.id,
|
|
263
|
-
workerId: worker.id,
|
|
264
|
-
timestamp: completedAt,
|
|
265
|
-
data: { durationMs },
|
|
266
|
-
});
|
|
267
|
-
resolve({
|
|
268
|
-
taskId: task.id,
|
|
269
|
-
workerId: worker.id,
|
|
270
|
-
success: true,
|
|
271
|
-
result,
|
|
272
|
-
durationMs,
|
|
273
|
-
startedAt,
|
|
274
|
-
completedAt,
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
catch (error) {
|
|
278
|
-
const completedAt = Date.now();
|
|
279
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
280
|
-
this.emit({
|
|
281
|
-
type: 'task.failed',
|
|
282
|
-
taskId: task.id,
|
|
283
|
-
workerId: worker.id,
|
|
284
|
-
timestamp: completedAt,
|
|
285
|
-
data: { error: err.message },
|
|
286
|
-
});
|
|
287
|
-
resolve({
|
|
288
|
-
taskId: task.id,
|
|
289
|
-
workerId: worker.id,
|
|
290
|
-
success: false,
|
|
291
|
-
error: err,
|
|
292
|
-
durationMs: completedAt - startedAt,
|
|
293
|
-
startedAt,
|
|
294
|
-
completedAt,
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
finally {
|
|
298
|
-
if (worker.isAvailable) {
|
|
299
|
-
this.emit({ type: 'worker.idle', workerId: worker.id, timestamp: Date.now() });
|
|
300
|
-
}
|
|
301
|
-
// Continue processing queue
|
|
302
|
-
this.processQueue();
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Select a worker based on the balancing strategy
|
|
307
|
-
*/
|
|
308
|
-
selectWorker(task) {
|
|
309
|
-
const available = this.getAvailableWorkers(task);
|
|
310
|
-
if (available.length === 0)
|
|
311
|
-
return null;
|
|
312
|
-
// Check for preferred worker
|
|
313
|
-
if (task?.preferredWorker) {
|
|
314
|
-
const preferred = available.find(w => w.id === task.preferredWorker);
|
|
315
|
-
if (preferred)
|
|
316
|
-
return preferred;
|
|
317
|
-
}
|
|
318
|
-
switch (this.balanceStrategy) {
|
|
319
|
-
case 'round-robin': {
|
|
320
|
-
const worker = available[this.roundRobinIndex % available.length];
|
|
321
|
-
this.roundRobinIndex++;
|
|
322
|
-
return worker;
|
|
323
|
-
}
|
|
324
|
-
case 'random': {
|
|
325
|
-
const idx = Math.floor(Math.random() * available.length);
|
|
326
|
-
return available[idx];
|
|
327
|
-
}
|
|
328
|
-
case 'priority': {
|
|
329
|
-
// Sort by priority (descending) then by load (ascending)
|
|
330
|
-
available.sort((a, b) => {
|
|
331
|
-
if (b.priority !== a.priority)
|
|
332
|
-
return b.priority - a.priority;
|
|
333
|
-
return a.currentLoad - b.currentLoad;
|
|
334
|
-
});
|
|
335
|
-
return available[0];
|
|
336
|
-
}
|
|
337
|
-
case 'least-busy':
|
|
338
|
-
default: {
|
|
339
|
-
// Sort by current load (ascending)
|
|
340
|
-
available.sort((a, b) => a.currentLoad - b.currentLoad);
|
|
341
|
-
return available[0];
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Get available workers filtered by task requirements
|
|
347
|
-
*/
|
|
348
|
-
getAvailableWorkers(task) {
|
|
349
|
-
const workers = Array.from(this.workers.values()).filter(w => w.isAvailable);
|
|
350
|
-
if (task?.requiredTags && task.requiredTags.length > 0) {
|
|
351
|
-
return workers.filter(w => w.hasTags(task.requiredTags));
|
|
352
|
-
}
|
|
353
|
-
return workers;
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Get information about all workers
|
|
357
|
-
*/
|
|
358
|
-
getWorkerInfo() {
|
|
359
|
-
return Array.from(this.workers.values()).map(w => w.getInfo());
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Get pool statistics
|
|
363
|
-
*/
|
|
364
|
-
getStats() {
|
|
365
|
-
const workerInfos = this.getWorkerInfo();
|
|
366
|
-
const activeWorkers = workerInfos.filter(w => w.status === 'busy').length;
|
|
367
|
-
const activeTasks = workerInfos.reduce((sum, w) => sum + w.activeTasks, 0);
|
|
368
|
-
const completedTasks = workerInfos.reduce((sum, w) => sum + w.completedTasks, 0);
|
|
369
|
-
const failedTasks = workerInfos.reduce((sum, w) => sum + w.failedTasks, 0);
|
|
370
|
-
return {
|
|
371
|
-
totalWorkers: workerInfos.length,
|
|
372
|
-
activeWorkers,
|
|
373
|
-
idleWorkers: workerInfos.length - activeWorkers,
|
|
374
|
-
queuedTasks: this.taskQueue.length,
|
|
375
|
-
activeTasks,
|
|
376
|
-
completedTasks,
|
|
377
|
-
failedTasks,
|
|
378
|
-
averageTaskDurationMs: this.completedTaskCount > 0
|
|
379
|
-
? this.totalTaskDuration / this.completedTaskCount
|
|
380
|
-
: 0,
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Cancel all queued tasks
|
|
385
|
-
*/
|
|
386
|
-
cancelAll() {
|
|
387
|
-
const cancelled = this.taskQueue.length;
|
|
388
|
-
while (this.taskQueue.length > 0) {
|
|
389
|
-
const item = this.taskQueue.shift();
|
|
390
|
-
if (item) {
|
|
391
|
-
item.reject(new Error('Task cancelled'));
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
return cancelled;
|
|
395
|
-
}
|
|
396
|
-
emit(event) {
|
|
397
|
-
try {
|
|
398
|
-
this.onEvent(event);
|
|
399
|
-
}
|
|
400
|
-
catch {
|
|
401
|
-
// Ignore callback errors
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
sleep(ms) {
|
|
405
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
// ============================================================================
|
|
409
|
-
// Convenience Functions
|
|
410
|
-
// ============================================================================
|
|
411
|
-
/**
|
|
412
|
-
* Create an agent worker pool with the given configuration
|
|
413
|
-
*/
|
|
414
|
-
export function createAgentWorkerPool(config) {
|
|
415
|
-
return new AgentWorkerPool(config);
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
* Create a simple agent task
|
|
419
|
-
*/
|
|
420
|
-
export function createAgentTask(id, message, options) {
|
|
421
|
-
return {
|
|
422
|
-
id,
|
|
423
|
-
message,
|
|
424
|
-
...options,
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
// ============================================================================
|
|
428
|
-
// Exports
|
|
429
|
-
// ============================================================================
|
|
430
|
-
export default {
|
|
431
|
-
AgentWorkerPool,
|
|
432
|
-
createAgentWorkerPool,
|
|
433
|
-
createAgentTask,
|
|
434
|
-
};
|
|
435
|
-
//# sourceMappingURL=agentWorkerPool.js.map
|