erosolar-cli 1.7.335 → 1.7.336
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/README.md +24 -148
- package/dist/bin/erosolar.js +5 -21
- package/dist/bin/erosolar.js.map +1 -1
- package/dist/capabilities/agentSpawningCapability.d.ts.map +1 -1
- package/dist/capabilities/agentSpawningCapability.js +56 -31
- package/dist/capabilities/agentSpawningCapability.js.map +1 -1
- package/dist/contracts/agent-schemas.json +0 -15
- package/dist/contracts/tools.schema.json +0 -9
- package/dist/core/agent.d.ts +2 -2
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js.map +1 -1
- package/dist/core/customCommands.d.ts +1 -0
- package/dist/core/customCommands.d.ts.map +1 -1
- package/dist/core/customCommands.js +3 -0
- package/dist/core/customCommands.js.map +1 -1
- package/dist/core/hooks.d.ts +113 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/hooks.js +267 -0
- package/dist/core/hooks.js.map +1 -0
- package/dist/core/metricsTracker.d.ts +122 -0
- package/dist/core/metricsTracker.d.ts.map +1 -0
- package/dist/{alpha-zero → core}/metricsTracker.js +2 -5
- package/dist/core/metricsTracker.js.map +1 -0
- package/dist/core/securityAssessment.d.ts +91 -0
- package/dist/core/securityAssessment.d.ts.map +1 -0
- package/dist/core/securityAssessment.js +580 -0
- package/dist/core/securityAssessment.js.map +1 -0
- package/dist/core/toolPreconditions.d.ts.map +1 -1
- package/dist/core/toolPreconditions.js +0 -14
- package/dist/core/toolPreconditions.js.map +1 -1
- package/dist/core/toolRuntime.d.ts +22 -1
- package/dist/core/toolRuntime.d.ts.map +1 -1
- package/dist/core/toolRuntime.js +0 -5
- package/dist/core/toolRuntime.js.map +1 -1
- package/dist/core/toolValidation.d.ts.map +1 -1
- package/dist/core/toolValidation.js +14 -3
- package/dist/core/toolValidation.js.map +1 -1
- package/dist/core/validationRunner.d.ts +1 -3
- package/dist/core/validationRunner.d.ts.map +1 -1
- package/dist/core/validationRunner.js.map +1 -1
- package/dist/core/verification.d.ts +137 -0
- package/dist/core/verification.d.ts.map +1 -0
- package/dist/core/verification.js +323 -0
- package/dist/core/verification.js.map +1 -0
- package/dist/headless/headlessApp.d.ts.map +1 -1
- package/dist/headless/headlessApp.js +21 -0
- package/dist/headless/headlessApp.js.map +1 -1
- package/dist/mcp/sseClient.d.ts.map +1 -1
- package/dist/mcp/sseClient.js +9 -18
- package/dist/mcp/sseClient.js.map +1 -1
- package/dist/plugins/tools/build/buildPlugin.d.ts +0 -6
- package/dist/plugins/tools/build/buildPlugin.d.ts.map +1 -1
- package/dist/plugins/tools/build/buildPlugin.js +4 -10
- package/dist/plugins/tools/build/buildPlugin.js.map +1 -1
- package/dist/plugins/tools/nodeDefaults.d.ts.map +1 -1
- package/dist/plugins/tools/nodeDefaults.js +0 -2
- package/dist/plugins/tools/nodeDefaults.js.map +1 -1
- package/dist/runtime/agentSession.d.ts +2 -2
- package/dist/runtime/agentSession.d.ts.map +1 -1
- package/dist/runtime/agentSession.js +2 -2
- package/dist/runtime/agentSession.js.map +1 -1
- package/dist/shell/interactiveShell.d.ts +16 -7
- package/dist/shell/interactiveShell.d.ts.map +1 -1
- package/dist/shell/interactiveShell.js +235 -166
- package/dist/shell/interactiveShell.js.map +1 -1
- package/dist/shell/shellApp.d.ts +2 -0
- package/dist/shell/shellApp.d.ts.map +1 -1
- package/dist/shell/shellApp.js +40 -9
- package/dist/shell/shellApp.js.map +1 -1
- package/dist/shell/systemPrompt.d.ts.map +1 -1
- package/dist/shell/systemPrompt.js +1 -4
- package/dist/shell/systemPrompt.js.map +1 -1
- package/dist/shell/terminalInput.d.ts +149 -118
- package/dist/shell/terminalInput.d.ts.map +1 -1
- package/dist/shell/terminalInput.js +638 -540
- package/dist/shell/terminalInput.js.map +1 -1
- package/dist/shell/terminalInputAdapter.d.ts +79 -21
- package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
- package/dist/shell/terminalInputAdapter.js +99 -30
- package/dist/shell/terminalInputAdapter.js.map +1 -1
- package/dist/subagents/agentConfig.d.ts +27 -0
- package/dist/subagents/agentConfig.d.ts.map +1 -0
- package/dist/subagents/agentConfig.js +89 -0
- package/dist/subagents/agentConfig.js.map +1 -0
- package/dist/subagents/agentRegistry.d.ts +33 -0
- package/dist/subagents/agentRegistry.d.ts.map +1 -0
- package/dist/subagents/agentRegistry.js +162 -0
- package/dist/subagents/agentRegistry.js.map +1 -0
- package/dist/subagents/taskRunner.d.ts +7 -1
- package/dist/subagents/taskRunner.d.ts.map +1 -1
- package/dist/subagents/taskRunner.js +180 -47
- package/dist/subagents/taskRunner.js.map +1 -1
- package/dist/ui/ShellUIAdapter.d.ts.map +1 -1
- package/dist/ui/ShellUIAdapter.js +13 -12
- package/dist/ui/ShellUIAdapter.js.map +1 -1
- package/dist/ui/display.d.ts +24 -45
- package/dist/ui/display.d.ts.map +1 -1
- package/dist/ui/display.js +140 -259
- package/dist/ui/display.js.map +1 -1
- package/dist/ui/theme.d.ts.map +1 -1
- package/dist/ui/theme.js +6 -8
- package/dist/ui/theme.js.map +1 -1
- package/dist/ui/toolDisplay.d.ts +0 -158
- package/dist/ui/toolDisplay.d.ts.map +1 -1
- package/dist/ui/toolDisplay.js +0 -348
- package/dist/ui/toolDisplay.js.map +1 -1
- package/dist/ui/unified/layout.d.ts +1 -0
- package/dist/ui/unified/layout.d.ts.map +1 -1
- package/dist/ui/unified/layout.js +15 -25
- package/dist/ui/unified/layout.js.map +1 -1
- package/dist/utils/frontmatter.d.ts +10 -0
- package/dist/utils/frontmatter.d.ts.map +1 -0
- package/dist/utils/frontmatter.js +78 -0
- package/dist/utils/frontmatter.js.map +1 -0
- package/package.json +4 -4
- package/dist/alpha-zero/agentWrapper.d.ts +0 -84
- package/dist/alpha-zero/agentWrapper.d.ts.map +0 -1
- package/dist/alpha-zero/agentWrapper.js +0 -171
- package/dist/alpha-zero/agentWrapper.js.map +0 -1
- package/dist/alpha-zero/codeEvaluator.d.ts +0 -25
- package/dist/alpha-zero/codeEvaluator.d.ts.map +0 -1
- package/dist/alpha-zero/codeEvaluator.js +0 -273
- package/dist/alpha-zero/codeEvaluator.js.map +0 -1
- package/dist/alpha-zero/competitiveRunner.d.ts +0 -66
- package/dist/alpha-zero/competitiveRunner.d.ts.map +0 -1
- package/dist/alpha-zero/competitiveRunner.js +0 -224
- package/dist/alpha-zero/competitiveRunner.js.map +0 -1
- package/dist/alpha-zero/index.d.ts +0 -67
- package/dist/alpha-zero/index.d.ts.map +0 -1
- package/dist/alpha-zero/index.js +0 -99
- package/dist/alpha-zero/index.js.map +0 -1
- package/dist/alpha-zero/introspection.d.ts +0 -128
- package/dist/alpha-zero/introspection.d.ts.map +0 -1
- package/dist/alpha-zero/introspection.js +0 -300
- package/dist/alpha-zero/introspection.js.map +0 -1
- package/dist/alpha-zero/metricsTracker.d.ts +0 -71
- package/dist/alpha-zero/metricsTracker.d.ts.map +0 -1
- package/dist/alpha-zero/metricsTracker.js.map +0 -1
- package/dist/alpha-zero/security/core.d.ts +0 -125
- package/dist/alpha-zero/security/core.d.ts.map +0 -1
- package/dist/alpha-zero/security/core.js +0 -271
- package/dist/alpha-zero/security/core.js.map +0 -1
- package/dist/alpha-zero/security/google.d.ts +0 -125
- package/dist/alpha-zero/security/google.d.ts.map +0 -1
- package/dist/alpha-zero/security/google.js +0 -311
- package/dist/alpha-zero/security/google.js.map +0 -1
- package/dist/alpha-zero/security/googleLoader.d.ts +0 -17
- package/dist/alpha-zero/security/googleLoader.d.ts.map +0 -1
- package/dist/alpha-zero/security/googleLoader.js +0 -41
- package/dist/alpha-zero/security/googleLoader.js.map +0 -1
- package/dist/alpha-zero/security/index.d.ts +0 -29
- package/dist/alpha-zero/security/index.d.ts.map +0 -1
- package/dist/alpha-zero/security/index.js +0 -32
- package/dist/alpha-zero/security/index.js.map +0 -1
- package/dist/alpha-zero/security/simulation.d.ts +0 -124
- package/dist/alpha-zero/security/simulation.d.ts.map +0 -1
- package/dist/alpha-zero/security/simulation.js +0 -277
- package/dist/alpha-zero/security/simulation.js.map +0 -1
- package/dist/alpha-zero/selfModification.d.ts +0 -109
- package/dist/alpha-zero/selfModification.d.ts.map +0 -1
- package/dist/alpha-zero/selfModification.js +0 -233
- package/dist/alpha-zero/selfModification.js.map +0 -1
- package/dist/alpha-zero/types.d.ts +0 -170
- package/dist/alpha-zero/types.d.ts.map +0 -1
- package/dist/alpha-zero/types.js +0 -31
- package/dist/alpha-zero/types.js.map +0 -1
- package/dist/capabilities/securityTestingCapability.d.ts +0 -13
- package/dist/capabilities/securityTestingCapability.d.ts.map +0 -1
- package/dist/capabilities/securityTestingCapability.js +0 -25
- package/dist/capabilities/securityTestingCapability.js.map +0 -1
- package/dist/core/aiFlowOptimizer.d.ts +0 -26
- package/dist/core/aiFlowOptimizer.d.ts.map +0 -1
- package/dist/core/aiFlowOptimizer.js +0 -31
- package/dist/core/aiFlowOptimizer.js.map +0 -1
- package/dist/core/aiOptimizationEngine.d.ts +0 -158
- package/dist/core/aiOptimizationEngine.d.ts.map +0 -1
- package/dist/core/aiOptimizationEngine.js +0 -428
- package/dist/core/aiOptimizationEngine.js.map +0 -1
- package/dist/core/aiOptimizationIntegration.d.ts +0 -93
- package/dist/core/aiOptimizationIntegration.d.ts.map +0 -1
- package/dist/core/aiOptimizationIntegration.js +0 -250
- package/dist/core/aiOptimizationIntegration.js.map +0 -1
- package/dist/core/enhancedErrorRecovery.d.ts +0 -100
- package/dist/core/enhancedErrorRecovery.d.ts.map +0 -1
- package/dist/core/enhancedErrorRecovery.js +0 -345
- package/dist/core/enhancedErrorRecovery.js.map +0 -1
- package/dist/core/hooksSystem.d.ts +0 -65
- package/dist/core/hooksSystem.d.ts.map +0 -1
- package/dist/core/hooksSystem.js +0 -273
- package/dist/core/hooksSystem.js.map +0 -1
- package/dist/core/memorySystem.d.ts +0 -48
- package/dist/core/memorySystem.d.ts.map +0 -1
- package/dist/core/memorySystem.js +0 -271
- package/dist/core/memorySystem.js.map +0 -1
- package/dist/core/unified/errors.d.ts +0 -189
- package/dist/core/unified/errors.d.ts.map +0 -1
- package/dist/core/unified/errors.js +0 -497
- package/dist/core/unified/errors.js.map +0 -1
- package/dist/core/unified/index.d.ts +0 -19
- package/dist/core/unified/index.d.ts.map +0 -1
- package/dist/core/unified/index.js +0 -68
- package/dist/core/unified/index.js.map +0 -1
- package/dist/core/unified/schema.d.ts +0 -101
- package/dist/core/unified/schema.d.ts.map +0 -1
- package/dist/core/unified/schema.js +0 -350
- package/dist/core/unified/schema.js.map +0 -1
- package/dist/core/unified/toolRuntime.d.ts +0 -179
- package/dist/core/unified/toolRuntime.d.ts.map +0 -1
- package/dist/core/unified/toolRuntime.js +0 -517
- package/dist/core/unified/toolRuntime.js.map +0 -1
- package/dist/core/unified/tools.d.ts +0 -127
- package/dist/core/unified/tools.d.ts.map +0 -1
- package/dist/core/unified/tools.js +0 -1333
- package/dist/core/unified/tools.js.map +0 -1
- package/dist/core/unified/types.d.ts +0 -352
- package/dist/core/unified/types.d.ts.map +0 -1
- package/dist/core/unified/types.js +0 -12
- package/dist/core/unified/types.js.map +0 -1
- package/dist/core/unified/version.d.ts +0 -209
- package/dist/core/unified/version.d.ts.map +0 -1
- package/dist/core/unified/version.js +0 -454
- package/dist/core/unified/version.js.map +0 -1
- package/dist/plugins/tools/security/securityPlugin.d.ts +0 -3
- package/dist/plugins/tools/security/securityPlugin.d.ts.map +0 -1
- package/dist/plugins/tools/security/securityPlugin.js +0 -12
- package/dist/plugins/tools/security/securityPlugin.js.map +0 -1
- package/dist/security/active-stack-security.d.ts +0 -112
- package/dist/security/active-stack-security.d.ts.map +0 -1
- package/dist/security/active-stack-security.js +0 -296
- package/dist/security/active-stack-security.js.map +0 -1
- package/dist/security/advanced-persistence-research.d.ts +0 -92
- package/dist/security/advanced-persistence-research.d.ts.map +0 -1
- package/dist/security/advanced-persistence-research.js +0 -195
- package/dist/security/advanced-persistence-research.js.map +0 -1
- package/dist/security/advanced-targeting.d.ts +0 -119
- package/dist/security/advanced-targeting.d.ts.map +0 -1
- package/dist/security/advanced-targeting.js +0 -233
- package/dist/security/advanced-targeting.js.map +0 -1
- package/dist/security/assessment/vulnerabilityAssessment.d.ts +0 -104
- package/dist/security/assessment/vulnerabilityAssessment.d.ts.map +0 -1
- package/dist/security/assessment/vulnerabilityAssessment.js +0 -315
- package/dist/security/assessment/vulnerabilityAssessment.js.map +0 -1
- package/dist/security/authorization/securityAuthorization.d.ts +0 -88
- package/dist/security/authorization/securityAuthorization.d.ts.map +0 -1
- package/dist/security/authorization/securityAuthorization.js +0 -172
- package/dist/security/authorization/securityAuthorization.js.map +0 -1
- package/dist/security/comprehensive-targeting.d.ts +0 -85
- package/dist/security/comprehensive-targeting.d.ts.map +0 -1
- package/dist/security/comprehensive-targeting.js +0 -438
- package/dist/security/comprehensive-targeting.js.map +0 -1
- package/dist/security/global-security-integration.d.ts +0 -91
- package/dist/security/global-security-integration.d.ts.map +0 -1
- package/dist/security/global-security-integration.js +0 -218
- package/dist/security/global-security-integration.js.map +0 -1
- package/dist/security/index.d.ts +0 -38
- package/dist/security/index.d.ts.map +0 -1
- package/dist/security/index.js +0 -47
- package/dist/security/index.js.map +0 -1
- package/dist/security/persistence-analyzer.d.ts +0 -56
- package/dist/security/persistence-analyzer.d.ts.map +0 -1
- package/dist/security/persistence-analyzer.js +0 -187
- package/dist/security/persistence-analyzer.js.map +0 -1
- package/dist/security/persistence-cli.d.ts +0 -36
- package/dist/security/persistence-cli.d.ts.map +0 -1
- package/dist/security/persistence-cli.js +0 -160
- package/dist/security/persistence-cli.js.map +0 -1
- package/dist/security/persistence-research.d.ts +0 -92
- package/dist/security/persistence-research.d.ts.map +0 -1
- package/dist/security/persistence-research.js +0 -364
- package/dist/security/persistence-research.js.map +0 -1
- package/dist/security/research/persistenceResearch.d.ts +0 -97
- package/dist/security/research/persistenceResearch.d.ts.map +0 -1
- package/dist/security/research/persistenceResearch.js +0 -282
- package/dist/security/research/persistenceResearch.js.map +0 -1
- package/dist/security/security-integration.d.ts +0 -74
- package/dist/security/security-integration.d.ts.map +0 -1
- package/dist/security/security-integration.js +0 -137
- package/dist/security/security-integration.js.map +0 -1
- package/dist/security/security-testing-framework.d.ts +0 -112
- package/dist/security/security-testing-framework.d.ts.map +0 -1
- package/dist/security/security-testing-framework.js +0 -364
- package/dist/security/security-testing-framework.js.map +0 -1
- package/dist/security/simulation/attackSimulation.d.ts +0 -93
- package/dist/security/simulation/attackSimulation.d.ts.map +0 -1
- package/dist/security/simulation/attackSimulation.js +0 -341
- package/dist/security/simulation/attackSimulation.js.map +0 -1
- package/dist/security/strategic-operations.d.ts +0 -100
- package/dist/security/strategic-operations.d.ts.map +0 -1
- package/dist/security/strategic-operations.js +0 -276
- package/dist/security/strategic-operations.js.map +0 -1
- package/dist/security/tool-security-wrapper.d.ts +0 -58
- package/dist/security/tool-security-wrapper.d.ts.map +0 -1
- package/dist/security/tool-security-wrapper.js +0 -156
- package/dist/security/tool-security-wrapper.js.map +0 -1
- package/dist/shell/claudeCodeStreamHandler.d.ts +0 -145
- package/dist/shell/claudeCodeStreamHandler.d.ts.map +0 -1
- package/dist/shell/claudeCodeStreamHandler.js +0 -322
- package/dist/shell/claudeCodeStreamHandler.js.map +0 -1
- package/dist/shell/inputQueueManager.d.ts +0 -144
- package/dist/shell/inputQueueManager.d.ts.map +0 -1
- package/dist/shell/inputQueueManager.js +0 -290
- package/dist/shell/inputQueueManager.js.map +0 -1
- package/dist/shell/metricsTracker.d.ts +0 -60
- package/dist/shell/metricsTracker.d.ts.map +0 -1
- package/dist/shell/metricsTracker.js +0 -119
- package/dist/shell/metricsTracker.js.map +0 -1
- package/dist/shell/streamingOutputManager.d.ts +0 -115
- package/dist/shell/streamingOutputManager.d.ts.map +0 -1
- package/dist/shell/streamingOutputManager.js +0 -225
- package/dist/shell/streamingOutputManager.js.map +0 -1
- package/dist/tools/securityTools.d.ts +0 -22
- package/dist/tools/securityTools.d.ts.map +0 -1
- package/dist/tools/securityTools.js +0 -448
- package/dist/tools/securityTools.js.map +0 -1
- package/dist/ui/persistentPrompt.d.ts +0 -50
- package/dist/ui/persistentPrompt.d.ts.map +0 -1
- package/dist/ui/persistentPrompt.js +0 -92
- package/dist/ui/persistentPrompt.js.map +0 -1
- package/dist/ui/terminalUISchema.d.ts +0 -195
- package/dist/ui/terminalUISchema.d.ts.map +0 -1
- package/dist/ui/terminalUISchema.js +0 -113
- package/dist/ui/terminalUISchema.js.map +0 -1
- package/scripts/deploy-security-capabilities.js +0 -178
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unified Tool Runtime
|
|
3
|
-
*
|
|
4
|
-
* Core tool execution engine with caching, validation, and lifecycle management.
|
|
5
|
-
* Combines the best features from both TypeScript and Python implementations.
|
|
6
|
-
*
|
|
7
|
-
* Principal Investigator: Bo Shang
|
|
8
|
-
* Framework: erosolar-cli
|
|
9
|
-
*/
|
|
10
|
-
import type { ToolDefinition, ToolSuite, ToolRecord, ToolCallRequest, ToolCallResult, ProviderToolDefinition } from './types.js';
|
|
11
|
-
import { ToolArgumentValidationError } from './schema.js';
|
|
12
|
-
import { validateToolPreconditions, type PreflightWarning } from '../toolPreconditions.js';
|
|
13
|
-
/**
|
|
14
|
-
* Tools that can be safely cached based on their arguments
|
|
15
|
-
*/
|
|
16
|
-
export declare const CACHEABLE_TOOLS: Set<string>;
|
|
17
|
-
export interface ToolRuntimeConfig {
|
|
18
|
-
enableCache: boolean;
|
|
19
|
-
cacheTtlMs: number;
|
|
20
|
-
maxCacheSize: number;
|
|
21
|
-
defaultTimeoutMs: number;
|
|
22
|
-
networkTimeoutMs: number;
|
|
23
|
-
maxOutputLength: number;
|
|
24
|
-
verbose: boolean;
|
|
25
|
-
}
|
|
26
|
-
export interface CacheEntry {
|
|
27
|
-
output: string;
|
|
28
|
-
timestamp: number;
|
|
29
|
-
ttl: number;
|
|
30
|
-
hitCount: number;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Observer interface for tool lifecycle events
|
|
34
|
-
*/
|
|
35
|
-
export interface ToolRuntimeObserver {
|
|
36
|
-
onToolStart?(call: ToolCallRequest): void;
|
|
37
|
-
onToolResult?(call: ToolCallRequest, result: ToolCallResult): void;
|
|
38
|
-
onToolError?(call: ToolCallRequest, error: Error): void;
|
|
39
|
-
onToolWarning?(call: ToolCallRequest, warning: PreflightWarning | string): void;
|
|
40
|
-
onCacheHit?(call: ToolCallRequest, entry: CacheEntry): void;
|
|
41
|
-
onCacheMiss?(call: ToolCallRequest): void;
|
|
42
|
-
onValidationError?(call: ToolCallRequest, error: ToolArgumentValidationError): void;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Unified Tool Runtime
|
|
46
|
-
*
|
|
47
|
-
* Manages tool registration, execution, caching, and validation.
|
|
48
|
-
*/
|
|
49
|
-
export declare class ToolRuntime {
|
|
50
|
-
private registry;
|
|
51
|
-
private cache;
|
|
52
|
-
private config;
|
|
53
|
-
private observers;
|
|
54
|
-
private executionStats;
|
|
55
|
-
constructor(config?: Partial<ToolRuntimeConfig>);
|
|
56
|
-
/**
|
|
57
|
-
* Register a tool suite
|
|
58
|
-
*/
|
|
59
|
-
registerSuite(suite: ToolSuite): void;
|
|
60
|
-
/**
|
|
61
|
-
* Register a single tool
|
|
62
|
-
*/
|
|
63
|
-
registerTool(tool: ToolDefinition, suiteName?: string): void;
|
|
64
|
-
/**
|
|
65
|
-
* Unregister a tool
|
|
66
|
-
*/
|
|
67
|
-
unregisterTool(name: string): boolean;
|
|
68
|
-
/**
|
|
69
|
-
* Get a tool by name
|
|
70
|
-
*/
|
|
71
|
-
getTool(name: string): ToolRecord | undefined;
|
|
72
|
-
/**
|
|
73
|
-
* Check if a tool exists
|
|
74
|
-
*/
|
|
75
|
-
hasTool(name: string): boolean;
|
|
76
|
-
/**
|
|
77
|
-
* Enable or disable a tool
|
|
78
|
-
*/
|
|
79
|
-
setToolEnabled(name: string, enabled: boolean): boolean;
|
|
80
|
-
/**
|
|
81
|
-
* Execute a tool call
|
|
82
|
-
*/
|
|
83
|
-
execute(call: ToolCallRequest): Promise<ToolCallResult>;
|
|
84
|
-
/**
|
|
85
|
-
* Execute with timeout
|
|
86
|
-
*/
|
|
87
|
-
private executeWithTimeout;
|
|
88
|
-
/**
|
|
89
|
-
* Create an error result
|
|
90
|
-
*/
|
|
91
|
-
private createErrorResult;
|
|
92
|
-
/**
|
|
93
|
-
* Check if a tool's results can be cached
|
|
94
|
-
*/
|
|
95
|
-
private isCacheable;
|
|
96
|
-
/**
|
|
97
|
-
* Generate cache key for a tool call
|
|
98
|
-
*/
|
|
99
|
-
private getCacheKey;
|
|
100
|
-
/**
|
|
101
|
-
* Check if a cache entry has expired
|
|
102
|
-
*/
|
|
103
|
-
private isCacheExpired;
|
|
104
|
-
/**
|
|
105
|
-
* Cache a result
|
|
106
|
-
*/
|
|
107
|
-
private cacheResult;
|
|
108
|
-
/**
|
|
109
|
-
* Evict oldest cache entries
|
|
110
|
-
*/
|
|
111
|
-
private evictOldestCacheEntries;
|
|
112
|
-
/**
|
|
113
|
-
* Clear all cache entries
|
|
114
|
-
*/
|
|
115
|
-
clearCache(): void;
|
|
116
|
-
/**
|
|
117
|
-
* Clear expired cache entries
|
|
118
|
-
*/
|
|
119
|
-
clearExpiredCache(): number;
|
|
120
|
-
/**
|
|
121
|
-
* Truncate output if too long
|
|
122
|
-
*
|
|
123
|
-
* PERF: Uses efficient slicing - O(1) for length check, O(n) for truncation only when needed.
|
|
124
|
-
* Binary search not applicable here as we need character boundaries, not search.
|
|
125
|
-
*/
|
|
126
|
-
private truncateOutput;
|
|
127
|
-
/**
|
|
128
|
-
* Add an observer
|
|
129
|
-
*/
|
|
130
|
-
addObserver(observer: ToolRuntimeObserver): void;
|
|
131
|
-
/**
|
|
132
|
-
* Remove an observer
|
|
133
|
-
*/
|
|
134
|
-
removeObserver(observer: ToolRuntimeObserver): boolean;
|
|
135
|
-
/**
|
|
136
|
-
* Notify observers of an event
|
|
137
|
-
*/
|
|
138
|
-
private notifyObservers;
|
|
139
|
-
/**
|
|
140
|
-
* Get tools in provider format
|
|
141
|
-
*/
|
|
142
|
-
listProviderTools(): ProviderToolDefinition[];
|
|
143
|
-
/**
|
|
144
|
-
* Get tools for a specific category
|
|
145
|
-
*/
|
|
146
|
-
getToolsByCategory(category: string): ToolRecord[];
|
|
147
|
-
/**
|
|
148
|
-
* Get execution statistics
|
|
149
|
-
*/
|
|
150
|
-
getStats(): {
|
|
151
|
-
totalCalls: number;
|
|
152
|
-
cacheHits: number;
|
|
153
|
-
cacheHitRate: number;
|
|
154
|
-
errors: number;
|
|
155
|
-
errorRate: number;
|
|
156
|
-
avgExecutionTimeMs: number;
|
|
157
|
-
registeredTools: number;
|
|
158
|
-
cacheSize: number;
|
|
159
|
-
};
|
|
160
|
-
/**
|
|
161
|
-
* Reset statistics
|
|
162
|
-
*/
|
|
163
|
-
resetStats(): void;
|
|
164
|
-
/**
|
|
165
|
-
* Get tool execution counts
|
|
166
|
-
*/
|
|
167
|
-
getToolExecutionCounts(): Map<string, number>;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Create a tool runtime with default configuration
|
|
171
|
-
*/
|
|
172
|
-
export declare function createToolRuntime(config?: Partial<ToolRuntimeConfig>): ToolRuntime;
|
|
173
|
-
/**
|
|
174
|
-
* Create a tool suite from definitions
|
|
175
|
-
*/
|
|
176
|
-
export declare function createToolSuite(name: string, version: string, tools: ToolDefinition[], description?: string): ToolSuite;
|
|
177
|
-
export { validateToolPreconditions };
|
|
178
|
-
export type { PreflightWarning };
|
|
179
|
-
//# sourceMappingURL=toolRuntime.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toolRuntime.d.ts","sourceRoot":"","sources":["../../../src/core/unified/toolRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,UAAU,EACV,eAAe,EACf,cAAc,EACd,sBAAsB,EACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAyB,2BAA2B,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,yBAAyB,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAM3F;;GAEG;AACH,eAAO,MAAM,eAAe,aAkB1B,CAAC;AAmBH,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAAC;IAC1C,YAAY,CAAC,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IACnE,WAAW,CAAC,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACxD,aAAa,CAAC,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,gBAAgB,GAAG,MAAM,GAAG,IAAI,CAAC;IAChF,UAAU,CAAC,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IAC5D,WAAW,CAAC,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAAC;IAC1C,iBAAiB,CAAC,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,2BAA2B,GAAG,IAAI,CAAC;CACrF;AAMD;;;;GAIG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAiC;IACjD,OAAO,CAAC,KAAK,CAAiC;IAC9C,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,SAAS,CAA6B;IAC9C,OAAO,CAAC,cAAc,CAKpB;gBAEU,MAAM,GAAE,OAAO,CAAC,iBAAiB,CAAM;IAQnD;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI;IAUrC;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,cAAc,EAAE,SAAS,SAAY,GAAG,IAAI;IAgB/D;;OAEG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IASrC;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAI7C;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI9B;;OAEG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO;IAWvD;;OAEG;IACG,OAAO,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IA4F7D;;OAEG;YACW,kBAAkB;IAwBhC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAmBzB;;OAEG;IACH,OAAO,CAAC,WAAW;IAOnB;;OAEG;IACH,OAAO,CAAC,WAAW;IAKnB;;OAEG;IACH,OAAO,CAAC,cAAc;IAItB;;OAEG;IACH,OAAO,CAAC,WAAW;IAenB;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAY/B;;OAEG;IACH,UAAU,IAAI,IAAI;IAIlB;;OAEG;IACH,iBAAiB,IAAI,MAAM;IAe3B;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IA+CtB;;OAEG;IACH,WAAW,CAAC,QAAQ,EAAE,mBAAmB,GAAG,IAAI;IAIhD;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,mBAAmB,GAAG,OAAO;IAOtD;;OAEG;IACH,OAAO,CAAC,eAAe;IAmBvB;;OAEG;IACH,iBAAiB,IAAI,sBAAsB,EAAE;IAwB7C;;OAEG;IACH,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,EAAE;IAsBlD;;OAEG;IACH,QAAQ,IAAI;QACV,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,eAAe,EAAE,MAAM,CAAC;QACxB,SAAS,EAAE,MAAM,CAAC;KACnB;IAeD;;OAEG;IACH,UAAU,IAAI,IAAI;IASlB;;OAEG;IACH,sBAAsB,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;CAa9C;AAMD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,WAAW,CAElF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,cAAc,EAAE,EACvB,WAAW,CAAC,EAAE,MAAM,GACnB,SAAS,CAOX;AAMD,OAAO,EAAE,yBAAyB,EAAE,CAAC;AACrC,YAAY,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,517 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unified Tool Runtime
|
|
3
|
-
*
|
|
4
|
-
* Core tool execution engine with caching, validation, and lifecycle management.
|
|
5
|
-
* Combines the best features from both TypeScript and Python implementations.
|
|
6
|
-
*
|
|
7
|
-
* Principal Investigator: Bo Shang
|
|
8
|
-
* Framework: erosolar-cli
|
|
9
|
-
*/
|
|
10
|
-
import { validateToolArguments, ToolArgumentValidationError } from './schema.js';
|
|
11
|
-
import { validateToolPreconditions } from '../toolPreconditions.js';
|
|
12
|
-
// ============================================================================
|
|
13
|
-
// Constants
|
|
14
|
-
// ============================================================================
|
|
15
|
-
/**
|
|
16
|
-
* Tools that can be safely cached based on their arguments
|
|
17
|
-
*/
|
|
18
|
-
export const CACHEABLE_TOOLS = new Set([
|
|
19
|
-
'Read',
|
|
20
|
-
'read',
|
|
21
|
-
'read_file',
|
|
22
|
-
'Glob',
|
|
23
|
-
'glob',
|
|
24
|
-
'glob_search',
|
|
25
|
-
'Grep',
|
|
26
|
-
'grep',
|
|
27
|
-
'grep_search',
|
|
28
|
-
'WebSearch',
|
|
29
|
-
'web_search',
|
|
30
|
-
'WebFetch',
|
|
31
|
-
'web_fetch',
|
|
32
|
-
'find_definition',
|
|
33
|
-
'analyze_code_quality',
|
|
34
|
-
'analyze_complexity',
|
|
35
|
-
'find_dependencies',
|
|
36
|
-
]);
|
|
37
|
-
/**
|
|
38
|
-
* Default configuration
|
|
39
|
-
*/
|
|
40
|
-
const DEFAULT_CONFIG = {
|
|
41
|
-
enableCache: true,
|
|
42
|
-
cacheTtlMs: 5 * 60 * 1000, // 5 minutes
|
|
43
|
-
maxCacheSize: 1000,
|
|
44
|
-
defaultTimeoutMs: 120_000, // 2 minutes
|
|
45
|
-
networkTimeoutMs: 30_000, // 30 seconds
|
|
46
|
-
maxOutputLength: 100_000, // 100k chars
|
|
47
|
-
verbose: false,
|
|
48
|
-
};
|
|
49
|
-
// ============================================================================
|
|
50
|
-
// Tool Runtime
|
|
51
|
-
// ============================================================================
|
|
52
|
-
/**
|
|
53
|
-
* Unified Tool Runtime
|
|
54
|
-
*
|
|
55
|
-
* Manages tool registration, execution, caching, and validation.
|
|
56
|
-
*/
|
|
57
|
-
export class ToolRuntime {
|
|
58
|
-
registry = new Map();
|
|
59
|
-
cache = new Map();
|
|
60
|
-
config;
|
|
61
|
-
observers = [];
|
|
62
|
-
executionStats = {
|
|
63
|
-
totalCalls: 0,
|
|
64
|
-
cacheHits: 0,
|
|
65
|
-
errors: 0,
|
|
66
|
-
totalTimeMs: 0,
|
|
67
|
-
};
|
|
68
|
-
constructor(config = {}) {
|
|
69
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
70
|
-
}
|
|
71
|
-
// ==========================================================================
|
|
72
|
-
// Registration
|
|
73
|
-
// ==========================================================================
|
|
74
|
-
/**
|
|
75
|
-
* Register a tool suite
|
|
76
|
-
*/
|
|
77
|
-
registerSuite(suite) {
|
|
78
|
-
for (const tool of suite.tools) {
|
|
79
|
-
this.registerTool(tool, suite.name);
|
|
80
|
-
}
|
|
81
|
-
if (this.config.verbose) {
|
|
82
|
-
console.log(`[ToolRuntime] Registered suite: ${suite.name} (${suite.tools.length} tools)`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Register a single tool
|
|
87
|
-
*/
|
|
88
|
-
registerTool(tool, suiteName = 'default') {
|
|
89
|
-
const record = {
|
|
90
|
-
definition: tool,
|
|
91
|
-
suite: suiteName,
|
|
92
|
-
enabled: true,
|
|
93
|
-
executionCount: 0,
|
|
94
|
-
};
|
|
95
|
-
this.registry.set(tool.name, record);
|
|
96
|
-
// Also register lowercase version for case-insensitive lookup
|
|
97
|
-
if (tool.name !== tool.name.toLowerCase()) {
|
|
98
|
-
this.registry.set(tool.name.toLowerCase(), record);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Unregister a tool
|
|
103
|
-
*/
|
|
104
|
-
unregisterTool(name) {
|
|
105
|
-
const record = this.registry.get(name);
|
|
106
|
-
if (!record)
|
|
107
|
-
return false;
|
|
108
|
-
this.registry.delete(name);
|
|
109
|
-
this.registry.delete(name.toLowerCase());
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Get a tool by name
|
|
114
|
-
*/
|
|
115
|
-
getTool(name) {
|
|
116
|
-
return this.registry.get(name) || this.registry.get(name.toLowerCase());
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Check if a tool exists
|
|
120
|
-
*/
|
|
121
|
-
hasTool(name) {
|
|
122
|
-
return this.registry.has(name) || this.registry.has(name.toLowerCase());
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Enable or disable a tool
|
|
126
|
-
*/
|
|
127
|
-
setToolEnabled(name, enabled) {
|
|
128
|
-
const record = this.getTool(name);
|
|
129
|
-
if (!record)
|
|
130
|
-
return false;
|
|
131
|
-
record.enabled = enabled;
|
|
132
|
-
return true;
|
|
133
|
-
}
|
|
134
|
-
// ==========================================================================
|
|
135
|
-
// Execution
|
|
136
|
-
// ==========================================================================
|
|
137
|
-
/**
|
|
138
|
-
* Execute a tool call
|
|
139
|
-
*/
|
|
140
|
-
async execute(call) {
|
|
141
|
-
const startTime = Date.now();
|
|
142
|
-
this.executionStats.totalCalls++;
|
|
143
|
-
// Look up tool
|
|
144
|
-
const record = this.getTool(call.name);
|
|
145
|
-
if (!record) {
|
|
146
|
-
return this.createErrorResult(call, startTime, `Unknown tool: ${call.name}`);
|
|
147
|
-
}
|
|
148
|
-
if (!record.enabled) {
|
|
149
|
-
return this.createErrorResult(call, startTime, `Tool is disabled: ${call.name}`);
|
|
150
|
-
}
|
|
151
|
-
const tool = record.definition;
|
|
152
|
-
// Notify observers
|
|
153
|
-
this.notifyObservers('onToolStart', call);
|
|
154
|
-
// Check cache
|
|
155
|
-
if (this.config.enableCache && this.isCacheable(tool)) {
|
|
156
|
-
const cacheKey = this.getCacheKey(call);
|
|
157
|
-
const cached = this.cache.get(cacheKey);
|
|
158
|
-
if (cached && !this.isCacheExpired(cached)) {
|
|
159
|
-
cached.hitCount++;
|
|
160
|
-
this.executionStats.cacheHits++;
|
|
161
|
-
this.notifyObservers('onCacheHit', call, cached);
|
|
162
|
-
return {
|
|
163
|
-
toolCallId: call.id,
|
|
164
|
-
output: cached.output,
|
|
165
|
-
success: true,
|
|
166
|
-
cached: true,
|
|
167
|
-
durationMs: Date.now() - startTime,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
this.notifyObservers('onCacheMiss', call);
|
|
171
|
-
}
|
|
172
|
-
// Validate arguments
|
|
173
|
-
try {
|
|
174
|
-
validateToolArguments(call.name, tool.parameters, call.arguments);
|
|
175
|
-
}
|
|
176
|
-
catch (error) {
|
|
177
|
-
if (error instanceof ToolArgumentValidationError) {
|
|
178
|
-
this.notifyObservers('onValidationError', call, error);
|
|
179
|
-
return this.createErrorResult(call, startTime, error.message);
|
|
180
|
-
}
|
|
181
|
-
throw error;
|
|
182
|
-
}
|
|
183
|
-
// Pre-flight AI flow validation - catch common tool usage failures
|
|
184
|
-
const preflightWarnings = validateToolPreconditions(call.name, call.arguments);
|
|
185
|
-
for (const warning of preflightWarnings) {
|
|
186
|
-
this.notifyObservers('onToolWarning', call, warning);
|
|
187
|
-
}
|
|
188
|
-
// Execute tool
|
|
189
|
-
try {
|
|
190
|
-
const output = await this.executeWithTimeout(tool, call.arguments);
|
|
191
|
-
const truncatedOutput = this.truncateOutput(output, call.name);
|
|
192
|
-
const durationMs = Date.now() - startTime;
|
|
193
|
-
// Update stats
|
|
194
|
-
record.executionCount++;
|
|
195
|
-
record.lastExecuted = Date.now();
|
|
196
|
-
this.executionStats.totalTimeMs += durationMs;
|
|
197
|
-
// Cache result if cacheable
|
|
198
|
-
if (this.config.enableCache && this.isCacheable(tool)) {
|
|
199
|
-
this.cacheResult(call, truncatedOutput);
|
|
200
|
-
}
|
|
201
|
-
const result = {
|
|
202
|
-
toolCallId: call.id,
|
|
203
|
-
output: truncatedOutput,
|
|
204
|
-
success: true,
|
|
205
|
-
cached: false,
|
|
206
|
-
durationMs,
|
|
207
|
-
};
|
|
208
|
-
this.notifyObservers('onToolResult', call, result);
|
|
209
|
-
return result;
|
|
210
|
-
}
|
|
211
|
-
catch (error) {
|
|
212
|
-
this.executionStats.errors++;
|
|
213
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
214
|
-
this.notifyObservers('onToolError', call, error);
|
|
215
|
-
return this.createErrorResult(call, startTime, errorMessage);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Execute with timeout
|
|
220
|
-
*/
|
|
221
|
-
async executeWithTimeout(tool, args) {
|
|
222
|
-
const timeoutMs = this.config.defaultTimeoutMs;
|
|
223
|
-
return new Promise((resolve, reject) => {
|
|
224
|
-
const timer = setTimeout(() => {
|
|
225
|
-
reject(new Error(`Tool execution timed out after ${timeoutMs}ms`));
|
|
226
|
-
}, timeoutMs);
|
|
227
|
-
tool
|
|
228
|
-
.execute(args)
|
|
229
|
-
.then((result) => {
|
|
230
|
-
clearTimeout(timer);
|
|
231
|
-
resolve(result);
|
|
232
|
-
})
|
|
233
|
-
.catch((error) => {
|
|
234
|
-
clearTimeout(timer);
|
|
235
|
-
reject(error);
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Create an error result
|
|
241
|
-
*/
|
|
242
|
-
createErrorResult(call, startTime, error) {
|
|
243
|
-
return {
|
|
244
|
-
toolCallId: call.id,
|
|
245
|
-
output: `Error: ${error}`,
|
|
246
|
-
success: false,
|
|
247
|
-
cached: false,
|
|
248
|
-
durationMs: Date.now() - startTime,
|
|
249
|
-
error,
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
// ==========================================================================
|
|
253
|
-
// Caching
|
|
254
|
-
// ==========================================================================
|
|
255
|
-
/**
|
|
256
|
-
* Check if a tool's results can be cached
|
|
257
|
-
*/
|
|
258
|
-
isCacheable(tool) {
|
|
259
|
-
if (tool.cacheable !== undefined) {
|
|
260
|
-
return tool.cacheable;
|
|
261
|
-
}
|
|
262
|
-
return CACHEABLE_TOOLS.has(tool.name);
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Generate cache key for a tool call
|
|
266
|
-
*/
|
|
267
|
-
getCacheKey(call) {
|
|
268
|
-
const argsStr = JSON.stringify(call.arguments, Object.keys(call.arguments).sort());
|
|
269
|
-
return `${call.name}:${argsStr}`;
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Check if a cache entry has expired
|
|
273
|
-
*/
|
|
274
|
-
isCacheExpired(entry) {
|
|
275
|
-
return Date.now() - entry.timestamp > entry.ttl;
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Cache a result
|
|
279
|
-
*/
|
|
280
|
-
cacheResult(call, output) {
|
|
281
|
-
// Enforce max cache size
|
|
282
|
-
if (this.cache.size >= this.config.maxCacheSize) {
|
|
283
|
-
this.evictOldestCacheEntries(Math.floor(this.config.maxCacheSize * 0.2));
|
|
284
|
-
}
|
|
285
|
-
const cacheKey = this.getCacheKey(call);
|
|
286
|
-
this.cache.set(cacheKey, {
|
|
287
|
-
output,
|
|
288
|
-
timestamp: Date.now(),
|
|
289
|
-
ttl: this.config.cacheTtlMs,
|
|
290
|
-
hitCount: 0,
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Evict oldest cache entries
|
|
295
|
-
*/
|
|
296
|
-
evictOldestCacheEntries(count) {
|
|
297
|
-
const entries = Array.from(this.cache.entries());
|
|
298
|
-
entries.sort(([, a], [, b]) => a.timestamp - b.timestamp);
|
|
299
|
-
for (let i = 0; i < Math.min(count, entries.length); i++) {
|
|
300
|
-
const entry = entries[i];
|
|
301
|
-
if (entry) {
|
|
302
|
-
this.cache.delete(entry[0]);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Clear all cache entries
|
|
308
|
-
*/
|
|
309
|
-
clearCache() {
|
|
310
|
-
this.cache.clear();
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Clear expired cache entries
|
|
314
|
-
*/
|
|
315
|
-
clearExpiredCache() {
|
|
316
|
-
let cleared = 0;
|
|
317
|
-
for (const [key, entry] of Array.from(this.cache.entries())) {
|
|
318
|
-
if (this.isCacheExpired(entry)) {
|
|
319
|
-
this.cache.delete(key);
|
|
320
|
-
cleared++;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
return cleared;
|
|
324
|
-
}
|
|
325
|
-
// ==========================================================================
|
|
326
|
-
// Output Handling
|
|
327
|
-
// ==========================================================================
|
|
328
|
-
/**
|
|
329
|
-
* Truncate output if too long
|
|
330
|
-
*
|
|
331
|
-
* PERF: Uses efficient slicing - O(1) for length check, O(n) for truncation only when needed.
|
|
332
|
-
* Binary search not applicable here as we need character boundaries, not search.
|
|
333
|
-
*/
|
|
334
|
-
truncateOutput(output, toolName) {
|
|
335
|
-
const maxLength = this.config.maxOutputLength;
|
|
336
|
-
const len = output.length;
|
|
337
|
-
// Fast path: no truncation needed
|
|
338
|
-
if (len <= maxLength) {
|
|
339
|
-
return output;
|
|
340
|
-
}
|
|
341
|
-
const truncatedCount = len - maxLength;
|
|
342
|
-
const toolLower = toolName.toLowerCase();
|
|
343
|
-
// For file reads, keep head and tail for better context
|
|
344
|
-
if (toolLower.includes('read') || toolLower === 'glob' || toolLower === 'grep') {
|
|
345
|
-
// Keep 70% head, 30% tail (minus notice overhead)
|
|
346
|
-
const noticeLen = 50;
|
|
347
|
-
const usableLen = maxLength - noticeLen;
|
|
348
|
-
const headSize = Math.floor(usableLen * 0.7);
|
|
349
|
-
const tailSize = usableLen - headSize;
|
|
350
|
-
return (output.slice(0, headSize) +
|
|
351
|
-
`\n\n... [truncated ${truncatedCount} characters] ...\n\n` +
|
|
352
|
-
output.slice(-tailSize));
|
|
353
|
-
}
|
|
354
|
-
// For bash/command output, keep more of the tail (errors usually at end)
|
|
355
|
-
if (toolLower.includes('bash') || toolLower === 'execute') {
|
|
356
|
-
const noticeLen = 50;
|
|
357
|
-
const usableLen = maxLength - noticeLen;
|
|
358
|
-
const tailSize = Math.floor(usableLen * 0.8);
|
|
359
|
-
const headSize = usableLen - tailSize;
|
|
360
|
-
return (output.slice(0, headSize) +
|
|
361
|
-
`\n\n... [truncated ${truncatedCount} characters] ...\n\n` +
|
|
362
|
-
output.slice(-tailSize));
|
|
363
|
-
}
|
|
364
|
-
// Default: keep head only (fastest)
|
|
365
|
-
return output.slice(0, maxLength - 50) + `\n... [truncated ${truncatedCount} characters]`;
|
|
366
|
-
}
|
|
367
|
-
// ==========================================================================
|
|
368
|
-
// Observers
|
|
369
|
-
// ==========================================================================
|
|
370
|
-
/**
|
|
371
|
-
* Add an observer
|
|
372
|
-
*/
|
|
373
|
-
addObserver(observer) {
|
|
374
|
-
this.observers.push(observer);
|
|
375
|
-
}
|
|
376
|
-
/**
|
|
377
|
-
* Remove an observer
|
|
378
|
-
*/
|
|
379
|
-
removeObserver(observer) {
|
|
380
|
-
const index = this.observers.indexOf(observer);
|
|
381
|
-
if (index === -1)
|
|
382
|
-
return false;
|
|
383
|
-
this.observers.splice(index, 1);
|
|
384
|
-
return true;
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* Notify observers of an event
|
|
388
|
-
*/
|
|
389
|
-
notifyObservers(event, ...args) {
|
|
390
|
-
for (const observer of this.observers) {
|
|
391
|
-
const handler = observer[event];
|
|
392
|
-
if (handler) {
|
|
393
|
-
try {
|
|
394
|
-
handler.apply(observer, args);
|
|
395
|
-
}
|
|
396
|
-
catch (error) {
|
|
397
|
-
if (this.config.verbose) {
|
|
398
|
-
console.error(`[ToolRuntime] Observer error:`, error);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
// ==========================================================================
|
|
405
|
-
// Provider Integration
|
|
406
|
-
// ==========================================================================
|
|
407
|
-
/**
|
|
408
|
-
* Get tools in provider format
|
|
409
|
-
*/
|
|
410
|
-
listProviderTools() {
|
|
411
|
-
const tools = [];
|
|
412
|
-
const seen = new Set();
|
|
413
|
-
for (const [, record] of Array.from(this.registry.entries())) {
|
|
414
|
-
if (!record.enabled || seen.has(record.definition.name)) {
|
|
415
|
-
continue;
|
|
416
|
-
}
|
|
417
|
-
seen.add(record.definition.name);
|
|
418
|
-
const tool = record.definition;
|
|
419
|
-
tools.push({
|
|
420
|
-
type: 'function',
|
|
421
|
-
function: {
|
|
422
|
-
name: tool.name,
|
|
423
|
-
description: tool.description,
|
|
424
|
-
parameters: tool.parameters,
|
|
425
|
-
},
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
return tools;
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
* Get tools for a specific category
|
|
432
|
-
*/
|
|
433
|
-
getToolsByCategory(category) {
|
|
434
|
-
const tools = [];
|
|
435
|
-
const seen = new Set();
|
|
436
|
-
for (const record of Array.from(this.registry.values())) {
|
|
437
|
-
if (record.definition.category === category &&
|
|
438
|
-
record.enabled &&
|
|
439
|
-
!seen.has(record.definition.name)) {
|
|
440
|
-
seen.add(record.definition.name);
|
|
441
|
-
tools.push(record);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
return tools;
|
|
445
|
-
}
|
|
446
|
-
// ==========================================================================
|
|
447
|
-
// Statistics
|
|
448
|
-
// ==========================================================================
|
|
449
|
-
/**
|
|
450
|
-
* Get execution statistics
|
|
451
|
-
*/
|
|
452
|
-
getStats() {
|
|
453
|
-
const totalCalls = this.executionStats.totalCalls;
|
|
454
|
-
return {
|
|
455
|
-
totalCalls,
|
|
456
|
-
cacheHits: this.executionStats.cacheHits,
|
|
457
|
-
cacheHitRate: totalCalls > 0 ? this.executionStats.cacheHits / totalCalls : 0,
|
|
458
|
-
errors: this.executionStats.errors,
|
|
459
|
-
errorRate: totalCalls > 0 ? this.executionStats.errors / totalCalls : 0,
|
|
460
|
-
avgExecutionTimeMs: totalCalls > 0 ? this.executionStats.totalTimeMs / totalCalls : 0,
|
|
461
|
-
registeredTools: new Set(Array.from(this.registry.values()).map((r) => r.definition.name))
|
|
462
|
-
.size,
|
|
463
|
-
cacheSize: this.cache.size,
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
/**
|
|
467
|
-
* Reset statistics
|
|
468
|
-
*/
|
|
469
|
-
resetStats() {
|
|
470
|
-
this.executionStats = {
|
|
471
|
-
totalCalls: 0,
|
|
472
|
-
cacheHits: 0,
|
|
473
|
-
errors: 0,
|
|
474
|
-
totalTimeMs: 0,
|
|
475
|
-
};
|
|
476
|
-
}
|
|
477
|
-
/**
|
|
478
|
-
* Get tool execution counts
|
|
479
|
-
*/
|
|
480
|
-
getToolExecutionCounts() {
|
|
481
|
-
const counts = new Map();
|
|
482
|
-
const seen = new Set();
|
|
483
|
-
for (const record of Array.from(this.registry.values())) {
|
|
484
|
-
if (!seen.has(record.definition.name)) {
|
|
485
|
-
seen.add(record.definition.name);
|
|
486
|
-
counts.set(record.definition.name, record.executionCount);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
return counts;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
// ============================================================================
|
|
493
|
-
// Factory Functions
|
|
494
|
-
// ============================================================================
|
|
495
|
-
/**
|
|
496
|
-
* Create a tool runtime with default configuration
|
|
497
|
-
*/
|
|
498
|
-
export function createToolRuntime(config) {
|
|
499
|
-
return new ToolRuntime(config);
|
|
500
|
-
}
|
|
501
|
-
/**
|
|
502
|
-
* Create a tool suite from definitions
|
|
503
|
-
*/
|
|
504
|
-
export function createToolSuite(name, version, tools, description) {
|
|
505
|
-
return {
|
|
506
|
-
name,
|
|
507
|
-
version,
|
|
508
|
-
description,
|
|
509
|
-
tools,
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
// ============================================================================
|
|
513
|
-
// AI Flow Pre-Flight Validation
|
|
514
|
-
// ============================================================================
|
|
515
|
-
// Re-export shared preflight validation to maintain unified runtime parity.
|
|
516
|
-
export { validateToolPreconditions };
|
|
517
|
-
//# sourceMappingURL=toolRuntime.js.map
|