claude-flow 2.0.0-alpha.64 → 2.0.0-alpha.65
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/CHANGELOG.md +18 -0
- package/bin/claude-flow +1 -1
- package/dist/api/claude-api-errors.d.ts +115 -0
- package/dist/api/claude-api-errors.d.ts.map +1 -0
- package/dist/api/claude-api-errors.js +198 -0
- package/dist/api/claude-api-errors.js.map +1 -0
- package/dist/api/claude-client-enhanced.d.ts +109 -0
- package/dist/api/claude-client-enhanced.d.ts.map +1 -0
- package/dist/api/claude-client-enhanced.js +479 -0
- package/dist/api/claude-client-enhanced.js.map +1 -0
- package/dist/api/claude-client.d.ts +42 -0
- package/dist/api/claude-client.d.ts.map +1 -1
- package/dist/api/claude-client.js +217 -14
- package/dist/api/claude-client.js.map +1 -1
- package/dist/cli/commands/hive-mind/pause.d.ts.map +1 -1
- package/dist/cli/commands/hive-mind/pause.js +6 -5
- package/dist/cli/commands/hive-mind/pause.js.map +1 -1
- package/dist/cli/commands/hive-mind/ps.js.map +1 -1
- package/dist/cli/commands/hive-mind/resume.d.ts.map +1 -1
- package/dist/cli/commands/hive-mind/resume.js +4 -3
- package/dist/cli/commands/hive-mind/resume.js.map +1 -1
- package/dist/cli/commands/hive-mind/stop.js.map +1 -1
- package/dist/cli/repl.d.ts.map +1 -1
- package/dist/cli/repl.js +44 -22
- package/dist/cli/repl.js.map +1 -1
- package/dist/cli/simple-cli.js +4 -3
- package/dist/cli/simple-cli.js.map +1 -1
- package/dist/cli/simple-commands/coordination.js +60 -40
- package/dist/cli/simple-commands/coordination.js.map +1 -1
- package/dist/cli/simple-commands/hive-mind/auto-save-middleware.d.ts +3 -4
- package/dist/cli/simple-commands/hive-mind/auto-save-middleware.d.ts.map +1 -1
- package/dist/cli/simple-commands/hive-mind/auto-save-middleware.js +6 -6
- package/dist/cli/simple-commands/hive-mind/auto-save-middleware.js.map +1 -1
- package/dist/cli/simple-commands/hive-mind/mcp-wrapper.d.ts +1 -1
- package/dist/cli/simple-commands/hive-mind/mcp-wrapper.d.ts.map +1 -1
- package/dist/cli/simple-commands/hive-mind/mcp-wrapper.js +64 -7
- package/dist/cli/simple-commands/hive-mind/mcp-wrapper.js.map +1 -1
- package/dist/cli/simple-commands/hive-mind/session-manager.d.ts +139 -0
- package/dist/cli/simple-commands/hive-mind/session-manager.d.ts.map +1 -0
- package/dist/cli/simple-commands/hive-mind/session-manager.js +308 -95
- package/dist/cli/simple-commands/hive-mind/session-manager.js.map +1 -1
- package/dist/cli/simple-commands/hive-mind.d.ts.map +1 -1
- package/dist/cli/simple-commands/hive-mind.js +88 -10
- package/dist/cli/simple-commands/hive-mind.js.map +1 -1
- package/dist/cli/simple-commands/init/claude-commands/optimized-slash-commands.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/claude-commands/optimized-slash-commands.js +45 -22
- package/dist/cli/simple-commands/init/claude-commands/optimized-slash-commands.js.map +1 -1
- package/dist/cli/simple-commands/init/claude-commands/slash-commands.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/claude-commands/slash-commands.js +34 -13
- package/dist/cli/simple-commands/init/claude-commands/slash-commands.js.map +1 -1
- package/dist/cli/simple-commands/init/claude-commands/sparc-commands.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/claude-commands/sparc-commands.js +107 -30
- package/dist/cli/simple-commands/init/claude-commands/sparc-commands.js.map +1 -1
- package/dist/cli/simple-commands/init/copy-revised-templates.d.ts +29 -0
- package/dist/cli/simple-commands/init/copy-revised-templates.d.ts.map +1 -0
- package/dist/cli/simple-commands/init/copy-revised-templates.js +159 -0
- package/dist/cli/simple-commands/init/copy-revised-templates.js.map +1 -0
- package/dist/cli/simple-commands/init/index.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/index.js +139 -196
- package/dist/cli/simple-commands/init/index.js.map +1 -1
- package/dist/cli/simple-commands/init/template-copier.d.ts +27 -0
- package/dist/cli/simple-commands/init/template-copier.d.ts.map +1 -0
- package/dist/cli/simple-commands/init/template-copier.js +510 -0
- package/dist/cli/simple-commands/init/template-copier.js.map +1 -0
- package/dist/cli/simple-commands/init/templates/sparc-modes.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/templates/sparc-modes.js +634 -23
- package/dist/cli/simple-commands/init/templates/sparc-modes.js.map +1 -1
- package/dist/cli/simple-orchestrator.d.ts.map +1 -1
- package/dist/cli/simple-orchestrator.js +2 -1
- package/dist/cli/simple-orchestrator.js.map +1 -1
- package/dist/cli/ui/compatible-ui.js +1 -1
- package/dist/cli/ui/compatible-ui.js.map +1 -1
- package/dist/cli/ui/index.d.ts.map +1 -1
- package/dist/cli/ui/index.js +4 -2
- package/dist/cli/ui/index.js.map +1 -1
- package/dist/cli/utils/environment-detector.d.ts +5 -0
- package/dist/cli/utils/environment-detector.d.ts.map +1 -1
- package/dist/cli/utils/environment-detector.js.map +1 -1
- package/dist/core/logger.d.ts +2 -0
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +3 -0
- package/dist/core/logger.js.map +1 -1
- package/dist/hive-mind/core/DatabaseManager.d.ts +6 -0
- package/dist/hive-mind/core/DatabaseManager.d.ts.map +1 -1
- package/dist/hive-mind/core/DatabaseManager.js +66 -15
- package/dist/hive-mind/core/DatabaseManager.js.map +1 -1
- package/dist/memory/backends/sqlite.d.ts +1 -0
- package/dist/memory/backends/sqlite.d.ts.map +1 -1
- package/dist/memory/backends/sqlite.js +17 -2
- package/dist/memory/backends/sqlite.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/commands/hive-mind/pause.ts +6 -5
- package/src/cli/commands/hive-mind/ps.ts +4 -4
- package/src/cli/commands/hive-mind/resume.ts +4 -3
- package/src/cli/commands/hive-mind/stop.ts +1 -1
- package/src/cli/help-text.js +1 -1
- package/src/cli/repl.ts +44 -22
- package/src/cli/simple-cli.js +1 -1
- package/src/cli/simple-cli.ts +11 -10
- package/src/cli/simple-commands/init/index.js +1 -0
- package/src/cli/simple-orchestrator.ts +2 -1
- package/src/cli/ui/compatible-ui.ts +1 -1
- package/src/cli/ui/index.ts +4 -2
- package/src/cli/utils/environment-detector.ts +2 -2
- package/src/core/logger.ts +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.0.0-alpha.65] - 2025-01-20
|
|
9
|
+
|
|
10
|
+
### 🔧 Bug Fixes
|
|
11
|
+
- **CRITICAL**: Fixed "table agents has no column named role" error in hive-mind wizard (#403)
|
|
12
|
+
- Added missing `role` column to agents table schema in init/index.js
|
|
13
|
+
- Fixed TypeScript build errors preventing compilation
|
|
14
|
+
- Resolved ILogger interface issues and async/await problems
|
|
15
|
+
- Fixed missing type definitions in multiple modules
|
|
16
|
+
|
|
17
|
+
### 🏗️ Infrastructure
|
|
18
|
+
- **Database Schema**: Synchronized agents table schema across all modules
|
|
19
|
+
- **Build System**: Fixed critical TypeScript compilation errors
|
|
20
|
+
- **Type Safety**: Added proper type annotations throughout codebase
|
|
21
|
+
|
|
22
|
+
### 📚 Documentation
|
|
23
|
+
- Added migration instructions for existing databases
|
|
24
|
+
- Updated test suite with schema validation tests
|
|
25
|
+
|
|
8
26
|
## [2.0.0-alpha.64] - 2025-01-18
|
|
9
27
|
|
|
10
28
|
### 🔧 Bug Fixes
|
package/bin/claude-flow
CHANGED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude API specific error types with enhanced error handling
|
|
3
|
+
*/
|
|
4
|
+
import { ClaudeFlowError } from '../utils/errors.js';
|
|
5
|
+
/**
|
|
6
|
+
* Base error class for Claude API errors
|
|
7
|
+
*/
|
|
8
|
+
export declare class ClaudeAPIError extends ClaudeFlowError {
|
|
9
|
+
readonly statusCode?: number | undefined;
|
|
10
|
+
readonly retryable: boolean;
|
|
11
|
+
constructor(message: string, statusCode?: number | undefined, retryable?: boolean, details?: unknown);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Error for 500 Internal Server Error
|
|
15
|
+
*/
|
|
16
|
+
export declare class ClaudeInternalServerError extends ClaudeAPIError {
|
|
17
|
+
constructor(message: string, details?: unknown);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Error for 503 Service Unavailable
|
|
21
|
+
*/
|
|
22
|
+
export declare class ClaudeServiceUnavailableError extends ClaudeAPIError {
|
|
23
|
+
constructor(message: string, details?: unknown);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Error for 429 Too Many Requests (Rate Limit)
|
|
27
|
+
*/
|
|
28
|
+
export declare class ClaudeRateLimitError extends ClaudeAPIError {
|
|
29
|
+
readonly retryAfter?: number | undefined;
|
|
30
|
+
constructor(message: string, retryAfter?: number | undefined, details?: unknown);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Error for network timeouts
|
|
34
|
+
*/
|
|
35
|
+
export declare class ClaudeTimeoutError extends ClaudeAPIError {
|
|
36
|
+
readonly timeout: number;
|
|
37
|
+
constructor(message: string, timeout: number, details?: unknown);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Error for network-related issues
|
|
41
|
+
*/
|
|
42
|
+
export declare class ClaudeNetworkError extends ClaudeAPIError {
|
|
43
|
+
constructor(message: string, details?: unknown);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Error for authentication issues
|
|
47
|
+
*/
|
|
48
|
+
export declare class ClaudeAuthenticationError extends ClaudeAPIError {
|
|
49
|
+
constructor(message: string, details?: unknown);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Error for invalid requests
|
|
53
|
+
*/
|
|
54
|
+
export declare class ClaudeValidationError extends ClaudeAPIError {
|
|
55
|
+
constructor(message: string, details?: unknown);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Health check result
|
|
59
|
+
*/
|
|
60
|
+
export interface HealthCheckResult {
|
|
61
|
+
healthy: boolean;
|
|
62
|
+
latency?: number;
|
|
63
|
+
error?: string;
|
|
64
|
+
timestamp: Date;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* User-friendly error messages and fallback suggestions
|
|
68
|
+
*/
|
|
69
|
+
export declare const ERROR_MESSAGES: {
|
|
70
|
+
INTERNAL_SERVER_ERROR: {
|
|
71
|
+
title: string;
|
|
72
|
+
message: string;
|
|
73
|
+
suggestions: string[];
|
|
74
|
+
};
|
|
75
|
+
SERVICE_UNAVAILABLE: {
|
|
76
|
+
title: string;
|
|
77
|
+
message: string;
|
|
78
|
+
suggestions: string[];
|
|
79
|
+
};
|
|
80
|
+
RATE_LIMIT: {
|
|
81
|
+
title: string;
|
|
82
|
+
message: string;
|
|
83
|
+
suggestions: string[];
|
|
84
|
+
};
|
|
85
|
+
TIMEOUT: {
|
|
86
|
+
title: string;
|
|
87
|
+
message: string;
|
|
88
|
+
suggestions: string[];
|
|
89
|
+
};
|
|
90
|
+
NETWORK_ERROR: {
|
|
91
|
+
title: string;
|
|
92
|
+
message: string;
|
|
93
|
+
suggestions: string[];
|
|
94
|
+
};
|
|
95
|
+
AUTHENTICATION: {
|
|
96
|
+
title: string;
|
|
97
|
+
message: string;
|
|
98
|
+
suggestions: string[];
|
|
99
|
+
};
|
|
100
|
+
VALIDATION: {
|
|
101
|
+
title: string;
|
|
102
|
+
message: string;
|
|
103
|
+
suggestions: string[];
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Get user-friendly error information
|
|
108
|
+
*/
|
|
109
|
+
export declare function getUserFriendlyError(error: ClaudeAPIError): {
|
|
110
|
+
title: string;
|
|
111
|
+
message: string;
|
|
112
|
+
suggestions: string[];
|
|
113
|
+
retryable: boolean;
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=claude-api-errors.d.ts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EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAS/C;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuE1B,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,cAAc,GAAG;IAC3D,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;CACpB,CAuBA"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude API specific error types with enhanced error handling
|
|
3
|
+
*/
|
|
4
|
+
import { ClaudeFlowError } from '../utils/errors.js';
|
|
5
|
+
/**
|
|
6
|
+
* Base error class for Claude API errors
|
|
7
|
+
*/
|
|
8
|
+
export class ClaudeAPIError extends ClaudeFlowError {
|
|
9
|
+
statusCode;
|
|
10
|
+
retryable;
|
|
11
|
+
constructor(message, statusCode, retryable = false, details) {
|
|
12
|
+
super(message, 'CLAUDE_API_ERROR', details);
|
|
13
|
+
this.statusCode = statusCode;
|
|
14
|
+
this.retryable = retryable;
|
|
15
|
+
this.name = 'ClaudeAPIError';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Error for 500 Internal Server Error
|
|
20
|
+
*/
|
|
21
|
+
export class ClaudeInternalServerError extends ClaudeAPIError {
|
|
22
|
+
constructor(message, details) {
|
|
23
|
+
super(message || 'Claude API internal server error. The service may be temporarily unavailable.', 500, true, // Retryable
|
|
24
|
+
details);
|
|
25
|
+
this.name = 'ClaudeInternalServerError';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Error for 503 Service Unavailable
|
|
30
|
+
*/
|
|
31
|
+
export class ClaudeServiceUnavailableError extends ClaudeAPIError {
|
|
32
|
+
constructor(message, details) {
|
|
33
|
+
super(message || 'Claude API service is temporarily unavailable. Please try again later.', 503, true, // Retryable
|
|
34
|
+
details);
|
|
35
|
+
this.name = 'ClaudeServiceUnavailableError';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Error for 429 Too Many Requests (Rate Limit)
|
|
40
|
+
*/
|
|
41
|
+
export class ClaudeRateLimitError extends ClaudeAPIError {
|
|
42
|
+
retryAfter;
|
|
43
|
+
constructor(message, retryAfter, details) {
|
|
44
|
+
super(message || 'Rate limit exceeded. Please wait before making more requests.', 429, true, // Retryable
|
|
45
|
+
details);
|
|
46
|
+
this.retryAfter = retryAfter;
|
|
47
|
+
this.name = 'ClaudeRateLimitError';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Error for network timeouts
|
|
52
|
+
*/
|
|
53
|
+
export class ClaudeTimeoutError extends ClaudeAPIError {
|
|
54
|
+
timeout;
|
|
55
|
+
constructor(message, timeout, details) {
|
|
56
|
+
super(message || `Request timed out after ${timeout}ms. The API may be slow or unreachable.`, undefined, true, // Retryable
|
|
57
|
+
details);
|
|
58
|
+
this.timeout = timeout;
|
|
59
|
+
this.name = 'ClaudeTimeoutError';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Error for network-related issues
|
|
64
|
+
*/
|
|
65
|
+
export class ClaudeNetworkError extends ClaudeAPIError {
|
|
66
|
+
constructor(message, details) {
|
|
67
|
+
super(message || 'Network error occurred. Please check your internet connection.', undefined, true, // Retryable
|
|
68
|
+
details);
|
|
69
|
+
this.name = 'ClaudeNetworkError';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Error for authentication issues
|
|
74
|
+
*/
|
|
75
|
+
export class ClaudeAuthenticationError extends ClaudeAPIError {
|
|
76
|
+
constructor(message, details) {
|
|
77
|
+
super(message || 'Authentication failed. Please check your API key.', 401, false, // Not retryable
|
|
78
|
+
details);
|
|
79
|
+
this.name = 'ClaudeAuthenticationError';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Error for invalid requests
|
|
84
|
+
*/
|
|
85
|
+
export class ClaudeValidationError extends ClaudeAPIError {
|
|
86
|
+
constructor(message, details) {
|
|
87
|
+
super(message || 'Invalid request. Please check your parameters.', 400, false, // Not retryable
|
|
88
|
+
details);
|
|
89
|
+
this.name = 'ClaudeValidationError';
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* User-friendly error messages and fallback suggestions
|
|
94
|
+
*/
|
|
95
|
+
export const ERROR_MESSAGES = {
|
|
96
|
+
INTERNAL_SERVER_ERROR: {
|
|
97
|
+
title: 'Claude API Service Error',
|
|
98
|
+
message: 'The Claude API is experiencing technical difficulties.',
|
|
99
|
+
suggestions: [
|
|
100
|
+
'Wait a few minutes and try again',
|
|
101
|
+
'Check the Anthropic status page for service updates',
|
|
102
|
+
'Consider using a fallback AI service if available',
|
|
103
|
+
'Cache previous responses for offline usage',
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
SERVICE_UNAVAILABLE: {
|
|
107
|
+
title: 'Service Temporarily Unavailable',
|
|
108
|
+
message: 'Claude API is temporarily unavailable or undergoing maintenance.',
|
|
109
|
+
suggestions: [
|
|
110
|
+
'Try again in 5-10 minutes',
|
|
111
|
+
'Check if there\'s scheduled maintenance',
|
|
112
|
+
'Use cached responses if available',
|
|
113
|
+
'Consider implementing a queue for requests',
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
RATE_LIMIT: {
|
|
117
|
+
title: 'Rate Limit Exceeded',
|
|
118
|
+
message: 'You\'ve made too many requests to the Claude API.',
|
|
119
|
+
suggestions: [
|
|
120
|
+
'Implement request throttling',
|
|
121
|
+
'Batch multiple requests together',
|
|
122
|
+
'Consider upgrading your API plan',
|
|
123
|
+
'Use exponential backoff for retries',
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
TIMEOUT: {
|
|
127
|
+
title: 'Request Timeout',
|
|
128
|
+
message: 'The request took too long to complete.',
|
|
129
|
+
suggestions: [
|
|
130
|
+
'Check your internet connection',
|
|
131
|
+
'Try a simpler request',
|
|
132
|
+
'Increase the timeout duration',
|
|
133
|
+
'Break large requests into smaller ones',
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
NETWORK_ERROR: {
|
|
137
|
+
title: 'Network Connection Error',
|
|
138
|
+
message: 'Unable to connect to the Claude API.',
|
|
139
|
+
suggestions: [
|
|
140
|
+
'Check your internet connection',
|
|
141
|
+
'Verify firewall/proxy settings',
|
|
142
|
+
'Try using a different network',
|
|
143
|
+
'Check if the API endpoint is correct',
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
AUTHENTICATION: {
|
|
147
|
+
title: 'Authentication Failed',
|
|
148
|
+
message: 'Unable to authenticate with the Claude API.',
|
|
149
|
+
suggestions: [
|
|
150
|
+
'Verify your API key is correct',
|
|
151
|
+
'Check if your API key has expired',
|
|
152
|
+
'Ensure the API key has proper permissions',
|
|
153
|
+
'Generate a new API key if needed',
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
VALIDATION: {
|
|
157
|
+
title: 'Invalid Request',
|
|
158
|
+
message: 'The request contains invalid parameters.',
|
|
159
|
+
suggestions: [
|
|
160
|
+
'Check the request parameters',
|
|
161
|
+
'Verify the model name is correct',
|
|
162
|
+
'Ensure message format is valid',
|
|
163
|
+
'Review the API documentation',
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Get user-friendly error information
|
|
169
|
+
*/
|
|
170
|
+
export function getUserFriendlyError(error) {
|
|
171
|
+
let errorInfo = ERROR_MESSAGES.INTERNAL_SERVER_ERROR; // Default
|
|
172
|
+
if (error instanceof ClaudeInternalServerError) {
|
|
173
|
+
errorInfo = ERROR_MESSAGES.INTERNAL_SERVER_ERROR;
|
|
174
|
+
}
|
|
175
|
+
else if (error instanceof ClaudeServiceUnavailableError) {
|
|
176
|
+
errorInfo = ERROR_MESSAGES.SERVICE_UNAVAILABLE;
|
|
177
|
+
}
|
|
178
|
+
else if (error instanceof ClaudeRateLimitError) {
|
|
179
|
+
errorInfo = ERROR_MESSAGES.RATE_LIMIT;
|
|
180
|
+
}
|
|
181
|
+
else if (error instanceof ClaudeTimeoutError) {
|
|
182
|
+
errorInfo = ERROR_MESSAGES.TIMEOUT;
|
|
183
|
+
}
|
|
184
|
+
else if (error instanceof ClaudeNetworkError) {
|
|
185
|
+
errorInfo = ERROR_MESSAGES.NETWORK_ERROR;
|
|
186
|
+
}
|
|
187
|
+
else if (error instanceof ClaudeAuthenticationError) {
|
|
188
|
+
errorInfo = ERROR_MESSAGES.AUTHENTICATION;
|
|
189
|
+
}
|
|
190
|
+
else if (error instanceof ClaudeValidationError) {
|
|
191
|
+
errorInfo = ERROR_MESSAGES.VALIDATION;
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
...errorInfo,
|
|
195
|
+
retryable: error.retryable,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=claude-api-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-api-errors.js","sourceRoot":"","sources":["../../src/api/claude-api-errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,eAAe;IAG/B;IACA;IAHlB,YACE,OAAe,EACC,UAAmB,EACnB,YAAqB,KAAK,EAC1C,OAAiB;QAEjB,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,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AAc,CAAC,aAAa,CAAC;IAC3C,CAAC;SAAM,IAAI,KAAK,YAAY,yBAAyB,EAAE,CAAC;QACtD,SAAS,GAAG,cAAc,CAAC,cAAc,CAAC;IAC5C,CAAC;SAAM,IAAI,KAAK,YAAY,qBAAqB,EAAE,CAAC;QAClD,SAAS,GAAG,cAAc,CAAC,UAAU,CAAC;IACxC,CAAC;IAED,OAAO;QACL,GAAG,SAAS;QACZ,SAAS,EAAE,KAAK,CAAC,SAAS;KAC3B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enhanced Claude API client with comprehensive error handling
|
|
3
|
+
* Implements exponential backoff, health checks, and improved error messages
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
import { ILogger } from '../core/logger.js';
|
|
7
|
+
import { ConfigManager } from '../config/config-manager.js';
|
|
8
|
+
import { HealthCheckResult } from './claude-api-errors.js';
|
|
9
|
+
import { ClaudeAPIConfig, ClaudeModel, ClaudeMessage, ClaudeResponse, ClaudeStreamEvent } from './claude-client.js';
|
|
10
|
+
export interface EnhancedClaudeAPIConfig extends ClaudeAPIConfig {
|
|
11
|
+
enableHealthCheck?: boolean;
|
|
12
|
+
healthCheckInterval?: number;
|
|
13
|
+
circuitBreakerThreshold?: number;
|
|
14
|
+
circuitBreakerTimeout?: number;
|
|
15
|
+
circuitBreakerResetTimeout?: number;
|
|
16
|
+
maxRetries?: number;
|
|
17
|
+
retryBaseDelay?: number;
|
|
18
|
+
retryMaxDelay?: number;
|
|
19
|
+
retryJitter?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare class EnhancedClaudeAPIClient extends EventEmitter {
|
|
22
|
+
private config;
|
|
23
|
+
private logger;
|
|
24
|
+
private configManager;
|
|
25
|
+
private circuitBreaker;
|
|
26
|
+
private lastHealthCheck?;
|
|
27
|
+
private healthCheckTimer?;
|
|
28
|
+
constructor(logger: ILogger, configManager: ConfigManager, config?: Partial<EnhancedClaudeAPIConfig>);
|
|
29
|
+
/**
|
|
30
|
+
* Load configuration with enhanced defaults
|
|
31
|
+
*/
|
|
32
|
+
private loadConfiguration;
|
|
33
|
+
/**
|
|
34
|
+
* Validate configuration
|
|
35
|
+
*/
|
|
36
|
+
private validateConfiguration;
|
|
37
|
+
/**
|
|
38
|
+
* Start periodic health checks
|
|
39
|
+
*/
|
|
40
|
+
private startHealthCheck;
|
|
41
|
+
/**
|
|
42
|
+
* Perform a health check on the API
|
|
43
|
+
*/
|
|
44
|
+
performHealthCheck(): Promise<HealthCheckResult>;
|
|
45
|
+
/**
|
|
46
|
+
* Get last health check result
|
|
47
|
+
*/
|
|
48
|
+
getHealthStatus(): HealthCheckResult | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Send a message with enhanced error handling
|
|
51
|
+
*/
|
|
52
|
+
sendMessage(messages: ClaudeMessage[], options?: {
|
|
53
|
+
model?: ClaudeModel;
|
|
54
|
+
temperature?: number;
|
|
55
|
+
maxTokens?: number;
|
|
56
|
+
systemPrompt?: string;
|
|
57
|
+
stream?: boolean;
|
|
58
|
+
}): Promise<ClaudeResponse | AsyncIterable<ClaudeStreamEvent>>;
|
|
59
|
+
/**
|
|
60
|
+
* Send request with retry logic and enhanced error handling
|
|
61
|
+
*/
|
|
62
|
+
private sendRequestWithRetry;
|
|
63
|
+
/**
|
|
64
|
+
* Send a single request
|
|
65
|
+
*/
|
|
66
|
+
private sendRequestOnce;
|
|
67
|
+
/**
|
|
68
|
+
* Stream request with retry logic
|
|
69
|
+
*/
|
|
70
|
+
private streamRequestWithRetry;
|
|
71
|
+
/**
|
|
72
|
+
* Send a single streaming request
|
|
73
|
+
*/
|
|
74
|
+
private streamRequestOnce;
|
|
75
|
+
/**
|
|
76
|
+
* Create appropriate error based on status code
|
|
77
|
+
*/
|
|
78
|
+
private createAPIError;
|
|
79
|
+
/**
|
|
80
|
+
* Transform generic errors to Claude API errors
|
|
81
|
+
*/
|
|
82
|
+
private transformError;
|
|
83
|
+
/**
|
|
84
|
+
* Calculate retry delay with exponential backoff and jitter
|
|
85
|
+
*/
|
|
86
|
+
private calculateRetryDelay;
|
|
87
|
+
/**
|
|
88
|
+
* Handle errors with user-friendly messages and logging
|
|
89
|
+
*/
|
|
90
|
+
private handleError;
|
|
91
|
+
/**
|
|
92
|
+
* Helper method for simple completions with error handling
|
|
93
|
+
*/
|
|
94
|
+
complete(prompt: string, options?: {
|
|
95
|
+
model?: ClaudeModel;
|
|
96
|
+
temperature?: number;
|
|
97
|
+
maxTokens?: number;
|
|
98
|
+
systemPrompt?: string;
|
|
99
|
+
}): Promise<string>;
|
|
100
|
+
/**
|
|
101
|
+
* Delay helper
|
|
102
|
+
*/
|
|
103
|
+
private delay;
|
|
104
|
+
/**
|
|
105
|
+
* Clean up resources
|
|
106
|
+
*/
|
|
107
|
+
destroy(): void;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=claude-client-enhanced.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-client-enhanced.d.ts","sourceRoot":"","sources":["../../src/api/claude-client-enhanced.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EASL,iBAAiB,EAElB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,eAAe,EACf,WAAW,EACX,aAAa,EAEb,cAAc,EACd,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,uBAAwB,SAAQ,eAAe;IAC9D,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,qBAAqB,CAAC,EAAE,MAAM,CA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