erosolar-cli 1.7.346 → 1.7.347
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/sessionStore.d.ts +2 -0
- package/dist/core/sessionStore.d.ts.map +1 -1
- package/dist/core/sessionStore.js +1 -0
- package/dist/core/sessionStore.js.map +1 -1
- 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 +43 -7
- package/dist/shell/interactiveShell.d.ts.map +1 -1
- package/dist/shell/interactiveShell.js +417 -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 +82 -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 +252 -120
- package/dist/shell/terminalInput.d.ts.map +1 -1
- package/dist/shell/terminalInput.js +1117 -541
- package/dist/shell/terminalInput.js.map +1 -1
- package/dist/shell/terminalInputAdapter.d.ts +106 -24
- package/dist/shell/terminalInputAdapter.d.ts.map +1 -1
- package/dist/shell/terminalInputAdapter.js +141 -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 +7 -1
- package/dist/ui/ShellUIAdapter.d.ts.map +1 -1
- package/dist/ui/ShellUIAdapter.js +42 -18
- 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 +20 -0
- package/dist/ui/unified/layout.d.ts.map +1 -1
- package/dist/ui/unified/layout.js +105 -216
- 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,189 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unified Error Handling
|
|
3
|
-
*
|
|
4
|
-
* Structured error system with severity levels, auto-fix capabilities,
|
|
5
|
-
* and recovery strategies.
|
|
6
|
-
*
|
|
7
|
-
* Principal Investigator: Bo Shang
|
|
8
|
-
* Framework: erosolar-cli
|
|
9
|
-
*/
|
|
10
|
-
import type { ErrorSeverity, ErrorCategory, ErrorSuggestion, StructuredErrorData } from './types.js';
|
|
11
|
-
/**
|
|
12
|
-
* Base class for all structured errors
|
|
13
|
-
*/
|
|
14
|
-
export declare abstract class StructuredError extends Error {
|
|
15
|
-
readonly code: string;
|
|
16
|
-
readonly severity: ErrorSeverity;
|
|
17
|
-
readonly category: ErrorCategory;
|
|
18
|
-
readonly suggestions: ErrorSuggestion[];
|
|
19
|
-
readonly recoverable: boolean;
|
|
20
|
-
readonly metadata: Record<string, unknown>;
|
|
21
|
-
readonly timestamp: number;
|
|
22
|
-
constructor(message: string, options?: {
|
|
23
|
-
code?: string;
|
|
24
|
-
severity?: ErrorSeverity;
|
|
25
|
-
category?: ErrorCategory;
|
|
26
|
-
suggestions?: ErrorSuggestion[];
|
|
27
|
-
recoverable?: boolean;
|
|
28
|
-
metadata?: Record<string, unknown>;
|
|
29
|
-
});
|
|
30
|
-
/**
|
|
31
|
-
* Infer error code from message
|
|
32
|
-
*/
|
|
33
|
-
protected inferCode(message: string): string;
|
|
34
|
-
/**
|
|
35
|
-
* Infer category from message
|
|
36
|
-
*/
|
|
37
|
-
protected inferCategory(message: string): ErrorCategory;
|
|
38
|
-
/**
|
|
39
|
-
* Infer if error is recoverable
|
|
40
|
-
*/
|
|
41
|
-
protected inferRecoverable(): boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Try to auto-fix the error
|
|
44
|
-
*/
|
|
45
|
-
tryAutoFix(): Promise<{
|
|
46
|
-
fixed: boolean;
|
|
47
|
-
result?: unknown;
|
|
48
|
-
error?: string;
|
|
49
|
-
}>;
|
|
50
|
-
/**
|
|
51
|
-
* Convert to plain object
|
|
52
|
-
*/
|
|
53
|
-
toJSON(): StructuredErrorData;
|
|
54
|
-
/**
|
|
55
|
-
* Format for display
|
|
56
|
-
*/
|
|
57
|
-
toDisplayString(): string;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Error for dangerous operations that could cause harm
|
|
61
|
-
*/
|
|
62
|
-
export declare class DangerousOperationError extends StructuredError {
|
|
63
|
-
readonly operation: string;
|
|
64
|
-
readonly safeAlternatives: string[];
|
|
65
|
-
constructor(message: string, operation: string, safeAlternatives?: string[], metadata?: Record<string, unknown>);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Error for blocked operations due to policy
|
|
69
|
-
*/
|
|
70
|
-
export declare class BlockedOperationError extends StructuredError {
|
|
71
|
-
readonly operation: string;
|
|
72
|
-
readonly policy: string;
|
|
73
|
-
constructor(message: string, operation: string, policy: string, metadata?: Record<string, unknown>);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Error for validation failures
|
|
77
|
-
*/
|
|
78
|
-
export declare class ValidationError extends StructuredError {
|
|
79
|
-
readonly field: string;
|
|
80
|
-
readonly expectedType?: string;
|
|
81
|
-
readonly actualValue?: unknown;
|
|
82
|
-
constructor(message: string, field: string, options?: {
|
|
83
|
-
expectedType?: string;
|
|
84
|
-
actualValue?: unknown;
|
|
85
|
-
examples?: string[];
|
|
86
|
-
metadata?: Record<string, unknown>;
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Error for resource limits
|
|
91
|
-
*/
|
|
92
|
-
export declare class ResourceLimitError extends StructuredError {
|
|
93
|
-
readonly resource: string;
|
|
94
|
-
readonly limit: number;
|
|
95
|
-
readonly current: number;
|
|
96
|
-
constructor(message: string, resource: string, limit: number, current: number, metadata?: Record<string, unknown>);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Error for context overflow
|
|
100
|
-
*/
|
|
101
|
-
export declare class ContextOverflowError extends StructuredError {
|
|
102
|
-
readonly maxTokens: number;
|
|
103
|
-
readonly currentTokens: number;
|
|
104
|
-
readonly truncatable: boolean;
|
|
105
|
-
constructor(message: string, maxTokens: number, currentTokens: number, truncatable?: boolean, metadata?: Record<string, unknown>);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Error for provider/API issues
|
|
109
|
-
*/
|
|
110
|
-
export declare class ProviderError extends StructuredError {
|
|
111
|
-
readonly providerId: string;
|
|
112
|
-
readonly statusCode?: number;
|
|
113
|
-
readonly retryable: boolean;
|
|
114
|
-
constructor(message: string, providerId: string, options?: {
|
|
115
|
-
statusCode?: number;
|
|
116
|
-
retryable?: boolean;
|
|
117
|
-
retryAfterMs?: number;
|
|
118
|
-
metadata?: Record<string, unknown>;
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Error for tool execution failures
|
|
123
|
-
*/
|
|
124
|
-
export declare class ToolExecutionError extends StructuredError {
|
|
125
|
-
readonly toolName: string;
|
|
126
|
-
readonly phase: 'validation' | 'execution' | 'timeout';
|
|
127
|
-
constructor(message: string, toolName: string, phase: 'validation' | 'execution' | 'timeout', metadata?: Record<string, unknown>);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Error for network issues
|
|
131
|
-
*/
|
|
132
|
-
export declare class NetworkError extends StructuredError {
|
|
133
|
-
readonly url?: string;
|
|
134
|
-
readonly retryable: boolean;
|
|
135
|
-
constructor(message: string, options?: {
|
|
136
|
-
url?: string;
|
|
137
|
-
retryable?: boolean;
|
|
138
|
-
metadata?: Record<string, unknown>;
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
export type RecoveryStrategy = 'retry' | 'fallback' | 'skip' | 'abort' | 'prompt_user';
|
|
142
|
-
export interface RecoveryAttempt {
|
|
143
|
-
strategy: RecoveryStrategy;
|
|
144
|
-
success: boolean;
|
|
145
|
-
result?: unknown;
|
|
146
|
-
error?: string;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Error recovery manager
|
|
150
|
-
*/
|
|
151
|
-
export declare class ErrorRecoveryManager {
|
|
152
|
-
private maxRetries;
|
|
153
|
-
private retryDelayMs;
|
|
154
|
-
constructor(options?: {
|
|
155
|
-
maxRetries?: number;
|
|
156
|
-
retryDelayMs?: number;
|
|
157
|
-
});
|
|
158
|
-
/**
|
|
159
|
-
* Attempt recovery for an error
|
|
160
|
-
*/
|
|
161
|
-
attemptRecovery(error: StructuredError, strategies: RecoveryStrategy[], context?: {
|
|
162
|
-
retryFn?: () => Promise<unknown>;
|
|
163
|
-
fallbackFn?: () => Promise<unknown>;
|
|
164
|
-
}): Promise<RecoveryAttempt>;
|
|
165
|
-
/**
|
|
166
|
-
* Try a specific recovery strategy
|
|
167
|
-
*/
|
|
168
|
-
private tryStrategy;
|
|
169
|
-
/**
|
|
170
|
-
* Retry with exponential backoff
|
|
171
|
-
*/
|
|
172
|
-
private retryWithBackoff;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Check if an error is a structured error
|
|
176
|
-
*/
|
|
177
|
-
export declare function isStructuredError(error: unknown): error is StructuredError;
|
|
178
|
-
/**
|
|
179
|
-
* Wrap any error as a structured error
|
|
180
|
-
*/
|
|
181
|
-
export declare function wrapError(error: unknown, category?: ErrorCategory): StructuredError;
|
|
182
|
-
/**
|
|
183
|
-
* Create error recovery manager
|
|
184
|
-
*/
|
|
185
|
-
export declare function createErrorRecoveryManager(options?: {
|
|
186
|
-
maxRetries?: number;
|
|
187
|
-
retryDelayMs?: number;
|
|
188
|
-
}): ErrorRecoveryManager;
|
|
189
|
-
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/core/unified/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,eAAe,EACf,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAMpB;;GAEG;AACH,8BAAsB,eAAgB,SAAQ,KAAK;IACjD,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,QAAQ,EAAE,aAAa,CAAC;IACxC,SAAgB,QAAQ,EAAE,aAAa,CAAC;IACxC,SAAgB,WAAW,EAAE,eAAe,EAAE,CAAC;IAC/C,SAAgB,WAAW,EAAE,OAAO,CAAC;IACrC,SAAgB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClD,SAAgB,SAAS,EAAE,MAAM,CAAC;gBAGhC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QACP,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,aAAa,CAAC;QACzB,QAAQ,CAAC,EAAE,aAAa,CAAC;QACzB,WAAW,CAAC,EAAE,eAAe,EAAE,CAAC;QAChC,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC/B;IAkBR;;OAEG;IACH,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM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jC,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;KACrC,GACA,OAAO,CAAC,eAAe,CAAC;IAW3B;;OAEG;YACW,WAAW;IAwCzB;;OAEG;YACW,gBAAgB;CAsB/B;AAMD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,eAAe,CAE1E;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,aAAa,GAAG,eAAe,CAqBnF;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,CAAC,EAAE;IACnD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,oBAAoB,CAEvB"}
|
|
@@ -1,497 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unified Error Handling
|
|
3
|
-
*
|
|
4
|
-
* Structured error system with severity levels, auto-fix capabilities,
|
|
5
|
-
* and recovery strategies.
|
|
6
|
-
*
|
|
7
|
-
* Principal Investigator: Bo Shang
|
|
8
|
-
* Framework: erosolar-cli
|
|
9
|
-
*/
|
|
10
|
-
// ============================================================================
|
|
11
|
-
// Base Structured Error
|
|
12
|
-
// ============================================================================
|
|
13
|
-
/**
|
|
14
|
-
* Base class for all structured errors
|
|
15
|
-
*/
|
|
16
|
-
export class StructuredError extends Error {
|
|
17
|
-
code;
|
|
18
|
-
severity;
|
|
19
|
-
category;
|
|
20
|
-
suggestions;
|
|
21
|
-
recoverable;
|
|
22
|
-
metadata;
|
|
23
|
-
timestamp;
|
|
24
|
-
constructor(message, options = {}) {
|
|
25
|
-
super(message);
|
|
26
|
-
this.name = this.constructor.name;
|
|
27
|
-
this.code = options.code || this.inferCode(message);
|
|
28
|
-
this.severity = options.severity || 'error';
|
|
29
|
-
this.category = options.category || this.inferCategory(message);
|
|
30
|
-
this.suggestions = options.suggestions || [];
|
|
31
|
-
this.recoverable = options.recoverable ?? this.inferRecoverable();
|
|
32
|
-
this.metadata = options.metadata || {};
|
|
33
|
-
this.timestamp = Date.now();
|
|
34
|
-
// Maintain proper stack trace
|
|
35
|
-
if (Error.captureStackTrace) {
|
|
36
|
-
Error.captureStackTrace(this, this.constructor);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Infer error code from message
|
|
41
|
-
*/
|
|
42
|
-
inferCode(message) {
|
|
43
|
-
const msgLower = message.toLowerCase();
|
|
44
|
-
if (msgLower.includes('permission') || msgLower.includes('denied'))
|
|
45
|
-
return 'PERMISSION_DENIED';
|
|
46
|
-
if (msgLower.includes('not found') || msgLower.includes('missing'))
|
|
47
|
-
return 'NOT_FOUND';
|
|
48
|
-
if (msgLower.includes('timeout'))
|
|
49
|
-
return 'TIMEOUT';
|
|
50
|
-
if (msgLower.includes('validation') || msgLower.includes('invalid'))
|
|
51
|
-
return 'VALIDATION_ERROR';
|
|
52
|
-
if (msgLower.includes('network') || msgLower.includes('connection'))
|
|
53
|
-
return 'NETWORK_ERROR';
|
|
54
|
-
return 'UNKNOWN_ERROR';
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Infer category from message
|
|
58
|
-
*/
|
|
59
|
-
inferCategory(message) {
|
|
60
|
-
const msgLower = message.toLowerCase();
|
|
61
|
-
if (msgLower.includes('dangerous') || msgLower.includes('unsafe'))
|
|
62
|
-
return 'dangerous';
|
|
63
|
-
if (msgLower.includes('blocked') || msgLower.includes('not allowed'))
|
|
64
|
-
return 'blocked';
|
|
65
|
-
if (msgLower.includes('validation') || msgLower.includes('invalid'))
|
|
66
|
-
return 'validation';
|
|
67
|
-
if (msgLower.includes('resource') || msgLower.includes('limit'))
|
|
68
|
-
return 'resource';
|
|
69
|
-
if (msgLower.includes('context') || msgLower.includes('token'))
|
|
70
|
-
return 'context';
|
|
71
|
-
if (msgLower.includes('provider') || msgLower.includes('api'))
|
|
72
|
-
return 'provider';
|
|
73
|
-
if (msgLower.includes('tool'))
|
|
74
|
-
return 'tool';
|
|
75
|
-
if (msgLower.includes('permission'))
|
|
76
|
-
return 'permission';
|
|
77
|
-
if (msgLower.includes('network'))
|
|
78
|
-
return 'network';
|
|
79
|
-
return 'unknown';
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Infer if error is recoverable
|
|
83
|
-
*/
|
|
84
|
-
inferRecoverable() {
|
|
85
|
-
// Most errors are recoverable except critical ones
|
|
86
|
-
return this.severity !== 'critical';
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Try to auto-fix the error
|
|
90
|
-
*/
|
|
91
|
-
async tryAutoFix() {
|
|
92
|
-
for (const suggestion of this.suggestions) {
|
|
93
|
-
if (suggestion.autoFixable && suggestion.fixFn) {
|
|
94
|
-
try {
|
|
95
|
-
const result = await suggestion.fixFn();
|
|
96
|
-
if (result) {
|
|
97
|
-
return { fixed: true, result };
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
return { fixed: false, error: String(error) };
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return { fixed: false };
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Convert to plain object
|
|
109
|
-
*/
|
|
110
|
-
toJSON() {
|
|
111
|
-
return {
|
|
112
|
-
code: this.code,
|
|
113
|
-
message: this.message,
|
|
114
|
-
severity: this.severity,
|
|
115
|
-
category: this.category,
|
|
116
|
-
suggestions: this.suggestions.map((s) => ({
|
|
117
|
-
action: s.action,
|
|
118
|
-
description: s.description,
|
|
119
|
-
autoFixable: s.autoFixable,
|
|
120
|
-
})),
|
|
121
|
-
recoverable: this.recoverable,
|
|
122
|
-
metadata: this.metadata,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Format for display
|
|
127
|
-
*/
|
|
128
|
-
toDisplayString() {
|
|
129
|
-
let str = `[${this.severity.toUpperCase()}] ${this.message}`;
|
|
130
|
-
if (this.suggestions.length > 0) {
|
|
131
|
-
str += '\n\nSuggestions:';
|
|
132
|
-
for (const suggestion of this.suggestions) {
|
|
133
|
-
str += `\n - ${suggestion.action}: ${suggestion.description}`;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return str;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
// ============================================================================
|
|
140
|
-
// Specific Error Types
|
|
141
|
-
// ============================================================================
|
|
142
|
-
/**
|
|
143
|
-
* Error for dangerous operations that could cause harm
|
|
144
|
-
*/
|
|
145
|
-
export class DangerousOperationError extends StructuredError {
|
|
146
|
-
operation;
|
|
147
|
-
safeAlternatives;
|
|
148
|
-
constructor(message, operation, safeAlternatives = [], metadata) {
|
|
149
|
-
super(message, {
|
|
150
|
-
code: 'DANGEROUS_OPERATION',
|
|
151
|
-
severity: 'critical',
|
|
152
|
-
category: 'dangerous',
|
|
153
|
-
recoverable: false,
|
|
154
|
-
metadata: { ...metadata, operation, safeAlternatives },
|
|
155
|
-
suggestions: safeAlternatives.map((alt) => ({
|
|
156
|
-
action: 'Use safe alternative',
|
|
157
|
-
description: alt,
|
|
158
|
-
autoFixable: false,
|
|
159
|
-
})),
|
|
160
|
-
});
|
|
161
|
-
this.operation = operation;
|
|
162
|
-
this.safeAlternatives = safeAlternatives;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Error for blocked operations due to policy
|
|
167
|
-
*/
|
|
168
|
-
export class BlockedOperationError extends StructuredError {
|
|
169
|
-
operation;
|
|
170
|
-
policy;
|
|
171
|
-
constructor(message, operation, policy, metadata) {
|
|
172
|
-
super(message, {
|
|
173
|
-
code: 'BLOCKED_OPERATION',
|
|
174
|
-
severity: 'error',
|
|
175
|
-
category: 'blocked',
|
|
176
|
-
recoverable: false,
|
|
177
|
-
metadata: { ...metadata, operation, policy },
|
|
178
|
-
suggestions: [
|
|
179
|
-
{
|
|
180
|
-
action: 'Review policy',
|
|
181
|
-
description: `This operation is blocked by policy: ${policy}`,
|
|
182
|
-
autoFixable: false,
|
|
183
|
-
},
|
|
184
|
-
],
|
|
185
|
-
});
|
|
186
|
-
this.operation = operation;
|
|
187
|
-
this.policy = policy;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Error for validation failures
|
|
192
|
-
*/
|
|
193
|
-
export class ValidationError extends StructuredError {
|
|
194
|
-
field;
|
|
195
|
-
expectedType;
|
|
196
|
-
actualValue;
|
|
197
|
-
constructor(message, field, options) {
|
|
198
|
-
const suggestions = [];
|
|
199
|
-
if (options?.expectedType) {
|
|
200
|
-
suggestions.push({
|
|
201
|
-
action: 'Fix type',
|
|
202
|
-
description: `Expected type: ${options.expectedType}`,
|
|
203
|
-
autoFixable: false,
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
if (options?.examples) {
|
|
207
|
-
suggestions.push({
|
|
208
|
-
action: 'See examples',
|
|
209
|
-
description: options.examples.join(', '),
|
|
210
|
-
autoFixable: false,
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
super(message, {
|
|
214
|
-
code: 'VALIDATION_ERROR',
|
|
215
|
-
severity: 'error',
|
|
216
|
-
category: 'validation',
|
|
217
|
-
recoverable: true,
|
|
218
|
-
metadata: { ...options?.metadata, field, expectedType: options?.expectedType },
|
|
219
|
-
suggestions,
|
|
220
|
-
});
|
|
221
|
-
this.field = field;
|
|
222
|
-
this.expectedType = options?.expectedType;
|
|
223
|
-
this.actualValue = options?.actualValue;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Error for resource limits
|
|
228
|
-
*/
|
|
229
|
-
export class ResourceLimitError extends StructuredError {
|
|
230
|
-
resource;
|
|
231
|
-
limit;
|
|
232
|
-
current;
|
|
233
|
-
constructor(message, resource, limit, current, metadata) {
|
|
234
|
-
super(message, {
|
|
235
|
-
code: 'RESOURCE_LIMIT',
|
|
236
|
-
severity: 'error',
|
|
237
|
-
category: 'resource',
|
|
238
|
-
recoverable: true,
|
|
239
|
-
metadata: { ...metadata, resource, limit, current },
|
|
240
|
-
suggestions: [
|
|
241
|
-
{
|
|
242
|
-
action: 'Reduce usage',
|
|
243
|
-
description: `Current: ${current}, Limit: ${limit}`,
|
|
244
|
-
autoFixable: false,
|
|
245
|
-
},
|
|
246
|
-
],
|
|
247
|
-
});
|
|
248
|
-
this.resource = resource;
|
|
249
|
-
this.limit = limit;
|
|
250
|
-
this.current = current;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Error for context overflow
|
|
255
|
-
*/
|
|
256
|
-
export class ContextOverflowError extends StructuredError {
|
|
257
|
-
maxTokens;
|
|
258
|
-
currentTokens;
|
|
259
|
-
truncatable;
|
|
260
|
-
constructor(message, maxTokens, currentTokens, truncatable = true, metadata) {
|
|
261
|
-
const suggestions = [];
|
|
262
|
-
if (truncatable) {
|
|
263
|
-
suggestions.push({
|
|
264
|
-
action: 'Truncate context',
|
|
265
|
-
description: 'Older messages can be removed to free up space',
|
|
266
|
-
autoFixable: true,
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
suggestions.push({
|
|
270
|
-
action: 'Reduce input',
|
|
271
|
-
description: `Reduce input size by ${currentTokens - maxTokens} tokens`,
|
|
272
|
-
autoFixable: false,
|
|
273
|
-
});
|
|
274
|
-
super(message, {
|
|
275
|
-
code: 'CONTEXT_OVERFLOW',
|
|
276
|
-
severity: 'warning',
|
|
277
|
-
category: 'context',
|
|
278
|
-
recoverable: truncatable,
|
|
279
|
-
metadata: { ...metadata, maxTokens, currentTokens },
|
|
280
|
-
suggestions,
|
|
281
|
-
});
|
|
282
|
-
this.maxTokens = maxTokens;
|
|
283
|
-
this.currentTokens = currentTokens;
|
|
284
|
-
this.truncatable = truncatable;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Error for provider/API issues
|
|
289
|
-
*/
|
|
290
|
-
export class ProviderError extends StructuredError {
|
|
291
|
-
providerId;
|
|
292
|
-
statusCode;
|
|
293
|
-
retryable;
|
|
294
|
-
constructor(message, providerId, options) {
|
|
295
|
-
const retryable = options?.retryable ?? (options?.statusCode ? options.statusCode >= 500 : false);
|
|
296
|
-
const suggestions = [];
|
|
297
|
-
if (retryable) {
|
|
298
|
-
suggestions.push({
|
|
299
|
-
action: 'Retry',
|
|
300
|
-
description: options?.retryAfterMs
|
|
301
|
-
? `Retry after ${options.retryAfterMs}ms`
|
|
302
|
-
: 'Retry the request',
|
|
303
|
-
autoFixable: true,
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
super(message, {
|
|
307
|
-
code: 'PROVIDER_ERROR',
|
|
308
|
-
severity: options?.statusCode === 500 ? 'error' : 'warning',
|
|
309
|
-
category: 'provider',
|
|
310
|
-
recoverable: retryable,
|
|
311
|
-
metadata: { ...options?.metadata, providerId, statusCode: options?.statusCode },
|
|
312
|
-
suggestions,
|
|
313
|
-
});
|
|
314
|
-
this.providerId = providerId;
|
|
315
|
-
this.statusCode = options?.statusCode;
|
|
316
|
-
this.retryable = retryable;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Error for tool execution failures
|
|
321
|
-
*/
|
|
322
|
-
export class ToolExecutionError extends StructuredError {
|
|
323
|
-
toolName;
|
|
324
|
-
phase;
|
|
325
|
-
constructor(message, toolName, phase, metadata) {
|
|
326
|
-
const suggestions = [];
|
|
327
|
-
if (phase === 'validation') {
|
|
328
|
-
suggestions.push({
|
|
329
|
-
action: 'Fix arguments',
|
|
330
|
-
description: 'Check the tool arguments match the expected schema',
|
|
331
|
-
autoFixable: false,
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
else if (phase === 'timeout') {
|
|
335
|
-
suggestions.push({
|
|
336
|
-
action: 'Increase timeout',
|
|
337
|
-
description: 'The operation took too long - try increasing the timeout',
|
|
338
|
-
autoFixable: false,
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
super(message, {
|
|
342
|
-
code: 'TOOL_EXECUTION_ERROR',
|
|
343
|
-
severity: phase === 'timeout' ? 'warning' : 'error',
|
|
344
|
-
category: 'tool',
|
|
345
|
-
recoverable: phase !== 'validation',
|
|
346
|
-
metadata: { ...metadata, toolName, phase },
|
|
347
|
-
suggestions,
|
|
348
|
-
});
|
|
349
|
-
this.toolName = toolName;
|
|
350
|
-
this.phase = phase;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* Error for network issues
|
|
355
|
-
*/
|
|
356
|
-
export class NetworkError extends StructuredError {
|
|
357
|
-
url;
|
|
358
|
-
retryable;
|
|
359
|
-
constructor(message, options) {
|
|
360
|
-
super(message, {
|
|
361
|
-
code: 'NETWORK_ERROR',
|
|
362
|
-
severity: 'error',
|
|
363
|
-
category: 'network',
|
|
364
|
-
recoverable: options?.retryable ?? true,
|
|
365
|
-
metadata: { ...options?.metadata, url: options?.url },
|
|
366
|
-
suggestions: [
|
|
367
|
-
{
|
|
368
|
-
action: 'Check connection',
|
|
369
|
-
description: 'Verify network connectivity',
|
|
370
|
-
autoFixable: false,
|
|
371
|
-
},
|
|
372
|
-
{
|
|
373
|
-
action: 'Retry',
|
|
374
|
-
description: 'The request can be retried',
|
|
375
|
-
autoFixable: true,
|
|
376
|
-
},
|
|
377
|
-
],
|
|
378
|
-
});
|
|
379
|
-
this.url = options?.url;
|
|
380
|
-
this.retryable = options?.retryable ?? true;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Error recovery manager
|
|
385
|
-
*/
|
|
386
|
-
export class ErrorRecoveryManager {
|
|
387
|
-
maxRetries;
|
|
388
|
-
retryDelayMs;
|
|
389
|
-
constructor(options) {
|
|
390
|
-
this.maxRetries = options?.maxRetries ?? 3;
|
|
391
|
-
this.retryDelayMs = options?.retryDelayMs ?? 1000;
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Attempt recovery for an error
|
|
395
|
-
*/
|
|
396
|
-
async attemptRecovery(error, strategies, context) {
|
|
397
|
-
for (const strategy of strategies) {
|
|
398
|
-
const result = await this.tryStrategy(error, strategy, context);
|
|
399
|
-
if (result.success) {
|
|
400
|
-
return result;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
return { strategy: 'abort', success: false, error: 'All recovery strategies failed' };
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Try a specific recovery strategy
|
|
407
|
-
*/
|
|
408
|
-
async tryStrategy(error, strategy, context) {
|
|
409
|
-
switch (strategy) {
|
|
410
|
-
case 'retry':
|
|
411
|
-
if (!context?.retryFn) {
|
|
412
|
-
return { strategy, success: false, error: 'No retry function provided' };
|
|
413
|
-
}
|
|
414
|
-
return this.retryWithBackoff(context.retryFn);
|
|
415
|
-
case 'fallback':
|
|
416
|
-
if (!context?.fallbackFn) {
|
|
417
|
-
return { strategy, success: false, error: 'No fallback function provided' };
|
|
418
|
-
}
|
|
419
|
-
try {
|
|
420
|
-
const result = await context.fallbackFn();
|
|
421
|
-
return { strategy, success: true, result };
|
|
422
|
-
}
|
|
423
|
-
catch (e) {
|
|
424
|
-
return { strategy, success: false, error: String(e) };
|
|
425
|
-
}
|
|
426
|
-
case 'skip':
|
|
427
|
-
return { strategy, success: true };
|
|
428
|
-
case 'abort':
|
|
429
|
-
return { strategy, success: false, error: error.message };
|
|
430
|
-
case 'prompt_user':
|
|
431
|
-
return { strategy, success: false, error: 'User intervention required' };
|
|
432
|
-
default:
|
|
433
|
-
return { strategy, success: false, error: 'Unknown strategy' };
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Retry with exponential backoff
|
|
438
|
-
*/
|
|
439
|
-
async retryWithBackoff(fn) {
|
|
440
|
-
let lastError;
|
|
441
|
-
for (let attempt = 0; attempt < this.maxRetries; attempt++) {
|
|
442
|
-
try {
|
|
443
|
-
const result = await fn();
|
|
444
|
-
return { strategy: 'retry', success: true, result };
|
|
445
|
-
}
|
|
446
|
-
catch (e) {
|
|
447
|
-
lastError = e;
|
|
448
|
-
const delay = this.retryDelayMs * Math.pow(2, attempt);
|
|
449
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
return {
|
|
453
|
-
strategy: 'retry',
|
|
454
|
-
success: false,
|
|
455
|
-
error: lastError?.message || 'Max retries exceeded',
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
// ============================================================================
|
|
460
|
-
// Utility Functions
|
|
461
|
-
// ============================================================================
|
|
462
|
-
/**
|
|
463
|
-
* Check if an error is a structured error
|
|
464
|
-
*/
|
|
465
|
-
export function isStructuredError(error) {
|
|
466
|
-
return error instanceof StructuredError;
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Wrap any error as a structured error
|
|
470
|
-
*/
|
|
471
|
-
export function wrapError(error, category) {
|
|
472
|
-
if (isStructuredError(error)) {
|
|
473
|
-
return error;
|
|
474
|
-
}
|
|
475
|
-
if (error instanceof Error) {
|
|
476
|
-
const errMessage = error.message;
|
|
477
|
-
const errStack = error.stack;
|
|
478
|
-
return new (class extends StructuredError {
|
|
479
|
-
constructor() {
|
|
480
|
-
super(errMessage, { category });
|
|
481
|
-
this.stack = errStack;
|
|
482
|
-
}
|
|
483
|
-
})();
|
|
484
|
-
}
|
|
485
|
-
return new (class extends StructuredError {
|
|
486
|
-
constructor() {
|
|
487
|
-
super(String(error), { category });
|
|
488
|
-
}
|
|
489
|
-
})();
|
|
490
|
-
}
|
|
491
|
-
/**
|
|
492
|
-
* Create error recovery manager
|
|
493
|
-
*/
|
|
494
|
-
export function createErrorRecoveryManager(options) {
|
|
495
|
-
return new ErrorRecoveryManager(options);
|
|
496
|
-
}
|
|
497
|
-
//# sourceMappingURL=errors.js.map
|