@vfarcic/dot-ai 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +203 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +51 -0
- package/dist/core/claude.d.ts +42 -0
- package/dist/core/claude.d.ts.map +1 -0
- package/dist/core/claude.js +229 -0
- package/dist/core/deploy-operation.d.ts +38 -0
- package/dist/core/deploy-operation.d.ts.map +1 -0
- package/dist/core/deploy-operation.js +101 -0
- package/dist/core/discovery.d.ts +162 -0
- package/dist/core/discovery.d.ts.map +1 -0
- package/dist/core/discovery.js +758 -0
- package/dist/core/error-handling.d.ts +167 -0
- package/dist/core/error-handling.d.ts.map +1 -0
- package/dist/core/error-handling.js +399 -0
- package/dist/core/index.d.ts +42 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +123 -0
- package/dist/core/kubernetes-utils.d.ts +38 -0
- package/dist/core/kubernetes-utils.d.ts.map +1 -0
- package/dist/core/kubernetes-utils.js +177 -0
- package/dist/core/memory.d.ts +45 -0
- package/dist/core/memory.d.ts.map +1 -0
- package/dist/core/memory.js +113 -0
- package/dist/core/schema.d.ts +187 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +655 -0
- package/dist/core/session-utils.d.ts +29 -0
- package/dist/core/session-utils.d.ts.map +1 -0
- package/dist/core/session-utils.js +121 -0
- package/dist/core/workflow.d.ts +70 -0
- package/dist/core/workflow.d.ts.map +1 -0
- package/dist/core/workflow.js +161 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/interfaces/cli.d.ts +74 -0
- package/dist/interfaces/cli.d.ts.map +1 -0
- package/dist/interfaces/cli.js +769 -0
- package/dist/interfaces/mcp.d.ts +30 -0
- package/dist/interfaces/mcp.d.ts.map +1 -0
- package/dist/interfaces/mcp.js +105 -0
- package/dist/mcp/server.d.ts +9 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +151 -0
- package/dist/tools/answer-question.d.ts +27 -0
- package/dist/tools/answer-question.d.ts.map +1 -0
- package/dist/tools/answer-question.js +696 -0
- package/dist/tools/choose-solution.d.ts +23 -0
- package/dist/tools/choose-solution.d.ts.map +1 -0
- package/dist/tools/choose-solution.js +171 -0
- package/dist/tools/deploy-manifests.d.ts +25 -0
- package/dist/tools/deploy-manifests.d.ts.map +1 -0
- package/dist/tools/deploy-manifests.js +74 -0
- package/dist/tools/generate-manifests.d.ts +23 -0
- package/dist/tools/generate-manifests.d.ts.map +1 -0
- package/dist/tools/generate-manifests.js +424 -0
- package/dist/tools/index.d.ts +11 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +34 -0
- package/dist/tools/recommend.d.ts +23 -0
- package/dist/tools/recommend.d.ts.map +1 -0
- package/dist/tools/recommend.js +332 -0
- package/package.json +124 -0
- package/prompts/intent-validation.md +65 -0
- package/prompts/manifest-generation.md +79 -0
- package/prompts/question-generation.md +128 -0
- package/prompts/resource-analysis.md +127 -0
- package/prompts/resource-selection.md +55 -0
- package/prompts/resource-solution-ranking.md +77 -0
- package/prompts/solution-enhancement.md +129 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comprehensive Error Handling System for DevOps AI Toolkit
|
|
3
|
+
*
|
|
4
|
+
* Provides centralized error handling, logging, and context management
|
|
5
|
+
* with support for MCP protocol, CLI operations, and core functionality.
|
|
6
|
+
*/
|
|
7
|
+
import { McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Error categories for systematic error classification
|
|
10
|
+
*/
|
|
11
|
+
export declare enum ErrorCategory {
|
|
12
|
+
KUBERNETES = "kubernetes",
|
|
13
|
+
NETWORK = "network",
|
|
14
|
+
AUTHENTICATION = "authentication",
|
|
15
|
+
AUTHORIZATION = "authorization",
|
|
16
|
+
VALIDATION = "validation",
|
|
17
|
+
CONFIGURATION = "configuration",
|
|
18
|
+
OPERATION = "operation",
|
|
19
|
+
AI_SERVICE = "ai_service",
|
|
20
|
+
STORAGE = "storage",
|
|
21
|
+
MCP_PROTOCOL = "mcp_protocol",
|
|
22
|
+
CLI_INTERFACE = "cli_interface",
|
|
23
|
+
INTERNAL = "internal",
|
|
24
|
+
UNKNOWN = "unknown"
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Error severity levels
|
|
28
|
+
*/
|
|
29
|
+
export declare enum ErrorSeverity {
|
|
30
|
+
LOW = "low",// Non-critical, operation can continue
|
|
31
|
+
MEDIUM = "medium",// Important but recoverable
|
|
32
|
+
HIGH = "high",// Significant impact, requires attention
|
|
33
|
+
CRITICAL = "critical"
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Error context interface for comprehensive error tracking
|
|
37
|
+
*/
|
|
38
|
+
export interface ErrorContext {
|
|
39
|
+
operation: string;
|
|
40
|
+
component: string;
|
|
41
|
+
userId?: string;
|
|
42
|
+
sessionId?: string;
|
|
43
|
+
requestId?: string;
|
|
44
|
+
timestamp: Date;
|
|
45
|
+
version: string;
|
|
46
|
+
input?: any;
|
|
47
|
+
parameters?: Record<string, any>;
|
|
48
|
+
originalError?: Error;
|
|
49
|
+
stackTrace?: string;
|
|
50
|
+
suggestedActions?: string[];
|
|
51
|
+
isRetryable?: boolean;
|
|
52
|
+
retryCount?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Structured error interface
|
|
56
|
+
*/
|
|
57
|
+
export interface AppError {
|
|
58
|
+
id: string;
|
|
59
|
+
code: string;
|
|
60
|
+
category: ErrorCategory;
|
|
61
|
+
severity: ErrorSeverity;
|
|
62
|
+
message: string;
|
|
63
|
+
userMessage?: string;
|
|
64
|
+
technicalDetails?: string;
|
|
65
|
+
context: ErrorContext;
|
|
66
|
+
timestamp: Date;
|
|
67
|
+
suggestedActions: string[];
|
|
68
|
+
isRetryable: boolean;
|
|
69
|
+
cause?: AppError;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Log levels for structured logging
|
|
73
|
+
*/
|
|
74
|
+
export declare enum LogLevel {
|
|
75
|
+
DEBUG = "debug",
|
|
76
|
+
INFO = "info",
|
|
77
|
+
WARN = "warn",
|
|
78
|
+
ERROR = "error",
|
|
79
|
+
FATAL = "fatal"
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Structured log entry interface
|
|
83
|
+
*/
|
|
84
|
+
export interface LogEntry {
|
|
85
|
+
level: LogLevel;
|
|
86
|
+
timestamp: Date;
|
|
87
|
+
message: string;
|
|
88
|
+
component: string;
|
|
89
|
+
operation?: string;
|
|
90
|
+
requestId?: string;
|
|
91
|
+
sessionId?: string;
|
|
92
|
+
data?: any;
|
|
93
|
+
error?: AppError;
|
|
94
|
+
duration?: number;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Logger interface for dependency injection
|
|
98
|
+
*/
|
|
99
|
+
export interface Logger {
|
|
100
|
+
debug(message: string, data?: any): void;
|
|
101
|
+
info(message: string, data?: any): void;
|
|
102
|
+
warn(message: string, data?: any): void;
|
|
103
|
+
error(message: string, error?: Error | AppError, data?: any): void;
|
|
104
|
+
fatal(message: string, error?: Error | AppError, data?: any): void;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Default console logger implementation
|
|
108
|
+
*/
|
|
109
|
+
export declare class ConsoleLogger implements Logger {
|
|
110
|
+
private component;
|
|
111
|
+
private minLevel;
|
|
112
|
+
constructor(component: string, minLevel?: LogLevel);
|
|
113
|
+
private shouldLog;
|
|
114
|
+
private formatMessage;
|
|
115
|
+
debug(message: string, data?: any): void;
|
|
116
|
+
info(message: string, data?: any): void;
|
|
117
|
+
warn(message: string, data?: any): void;
|
|
118
|
+
error(message: string, error?: Error | AppError, data?: any): void;
|
|
119
|
+
fatal(message: string, error?: Error | AppError, data?: any): void;
|
|
120
|
+
private serializeError;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Error handler factory and utilities
|
|
124
|
+
*/
|
|
125
|
+
export declare class ErrorHandler {
|
|
126
|
+
private static requestIdCounter;
|
|
127
|
+
private static logger;
|
|
128
|
+
/**
|
|
129
|
+
* Set custom logger implementation
|
|
130
|
+
*/
|
|
131
|
+
static setLogger(logger: Logger): void;
|
|
132
|
+
/**
|
|
133
|
+
* Generate unique request ID
|
|
134
|
+
*/
|
|
135
|
+
static generateRequestId(): string;
|
|
136
|
+
/**
|
|
137
|
+
* Create comprehensive AppError from various error sources
|
|
138
|
+
*/
|
|
139
|
+
static createError(category: ErrorCategory, severity: ErrorSeverity, message: string, context: Partial<ErrorContext>, originalError?: Error): AppError;
|
|
140
|
+
/**
|
|
141
|
+
* Convert AppError to McpError for MCP protocol
|
|
142
|
+
*/
|
|
143
|
+
static toMcpError(appError: AppError): McpError;
|
|
144
|
+
/**
|
|
145
|
+
* Handle error with automatic logging and context enhancement
|
|
146
|
+
*/
|
|
147
|
+
static handleError(error: Error | AppError, context: Partial<ErrorContext>, options?: {
|
|
148
|
+
rethrow?: boolean;
|
|
149
|
+
convertToMcp?: boolean;
|
|
150
|
+
logLevel?: LogLevel;
|
|
151
|
+
}): AppError | McpError;
|
|
152
|
+
/**
|
|
153
|
+
* Wrap operation with error handling
|
|
154
|
+
*/
|
|
155
|
+
static withErrorHandling<T>(operation: () => Promise<T>, context: Partial<ErrorContext>, options?: {
|
|
156
|
+
retryCount?: number;
|
|
157
|
+
convertToMcp?: boolean;
|
|
158
|
+
}): Promise<T>;
|
|
159
|
+
private static generateErrorCode;
|
|
160
|
+
private static mapToMcpErrorCode;
|
|
161
|
+
private static categorizeError;
|
|
162
|
+
private static assessSeverity;
|
|
163
|
+
private static getUserFriendlyMessage;
|
|
164
|
+
private static getDefaultSuggestedActions;
|
|
165
|
+
private static wrapNativeError;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL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CAAC,WAAW,CAChB,QAAQ,EAAE,aAAa,EACvB,QAAQ,EAAE,aAAa,EACvB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,EAC9B,aAAa,CAAC,EAAE,KAAK,GACpB,QAAQ;IA6CX;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ;IAO/C;;OAEG;IACH,MAAM,CAAC,WAAW,CAChB,KAAK,EAAE,KAAK,GAAG,QAAQ,EACvB,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,EAC9B,OAAO,GAAE;QACP,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,QAAQ,CAAC,EAAE,QAAQ,CAAC;KAChB,GACL,QAAQ,GAAG,QAAQ;IAoCtB;;OAEG;WACU,iBAAiB,CAAC,CAAC,EAC9B,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,EAC9B,OAAO,GAAE;QACP,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,OAAO,CAAC;KACnB,GACL,OAAO,CAAC,CAAC,CAAC;IAkDb,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAQhC,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAiBhC,OAAO,CAAC,MAAM,CAAC,eAAe;IAsB9B,OAAO,CAAC,MAAM,CAAC,cAAc;IAgB7B,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAerC,OAAO,CAAC,MAAM,CAAC,0BAA0B;IA6BzC,OAAO,CAAC,MAAM,CAAC,eAAe;CAmC/B"}
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Comprehensive Error Handling System for DevOps AI Toolkit
|
|
4
|
+
*
|
|
5
|
+
* Provides centralized error handling, logging, and context management
|
|
6
|
+
* with support for MCP protocol, CLI operations, and core functionality.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ErrorHandler = exports.ConsoleLogger = exports.LogLevel = exports.ErrorSeverity = exports.ErrorCategory = void 0;
|
|
10
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
11
|
+
/**
|
|
12
|
+
* Error categories for systematic error classification
|
|
13
|
+
*/
|
|
14
|
+
var ErrorCategory;
|
|
15
|
+
(function (ErrorCategory) {
|
|
16
|
+
// Infrastructure errors
|
|
17
|
+
ErrorCategory["KUBERNETES"] = "kubernetes";
|
|
18
|
+
ErrorCategory["NETWORK"] = "network";
|
|
19
|
+
ErrorCategory["AUTHENTICATION"] = "authentication";
|
|
20
|
+
ErrorCategory["AUTHORIZATION"] = "authorization";
|
|
21
|
+
// Application errors
|
|
22
|
+
ErrorCategory["VALIDATION"] = "validation";
|
|
23
|
+
ErrorCategory["CONFIGURATION"] = "configuration";
|
|
24
|
+
ErrorCategory["OPERATION"] = "operation";
|
|
25
|
+
// External service errors
|
|
26
|
+
ErrorCategory["AI_SERVICE"] = "ai_service";
|
|
27
|
+
ErrorCategory["STORAGE"] = "storage";
|
|
28
|
+
// Protocol errors
|
|
29
|
+
ErrorCategory["MCP_PROTOCOL"] = "mcp_protocol";
|
|
30
|
+
ErrorCategory["CLI_INTERFACE"] = "cli_interface";
|
|
31
|
+
// System errors
|
|
32
|
+
ErrorCategory["INTERNAL"] = "internal";
|
|
33
|
+
ErrorCategory["UNKNOWN"] = "unknown";
|
|
34
|
+
})(ErrorCategory || (exports.ErrorCategory = ErrorCategory = {}));
|
|
35
|
+
/**
|
|
36
|
+
* Error severity levels
|
|
37
|
+
*/
|
|
38
|
+
var ErrorSeverity;
|
|
39
|
+
(function (ErrorSeverity) {
|
|
40
|
+
ErrorSeverity["LOW"] = "low";
|
|
41
|
+
ErrorSeverity["MEDIUM"] = "medium";
|
|
42
|
+
ErrorSeverity["HIGH"] = "high";
|
|
43
|
+
ErrorSeverity["CRITICAL"] = "critical"; // System-threatening, immediate action required
|
|
44
|
+
})(ErrorSeverity || (exports.ErrorSeverity = ErrorSeverity = {}));
|
|
45
|
+
/**
|
|
46
|
+
* Log levels for structured logging
|
|
47
|
+
*/
|
|
48
|
+
var LogLevel;
|
|
49
|
+
(function (LogLevel) {
|
|
50
|
+
LogLevel["DEBUG"] = "debug";
|
|
51
|
+
LogLevel["INFO"] = "info";
|
|
52
|
+
LogLevel["WARN"] = "warn";
|
|
53
|
+
LogLevel["ERROR"] = "error";
|
|
54
|
+
LogLevel["FATAL"] = "fatal";
|
|
55
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
56
|
+
/**
|
|
57
|
+
* Default console logger implementation
|
|
58
|
+
*/
|
|
59
|
+
class ConsoleLogger {
|
|
60
|
+
component;
|
|
61
|
+
minLevel;
|
|
62
|
+
constructor(component, minLevel = LogLevel.INFO) {
|
|
63
|
+
this.component = component;
|
|
64
|
+
this.minLevel = minLevel;
|
|
65
|
+
}
|
|
66
|
+
shouldLog(level) {
|
|
67
|
+
const levels = [LogLevel.DEBUG, LogLevel.INFO, LogLevel.WARN, LogLevel.ERROR, LogLevel.FATAL];
|
|
68
|
+
return levels.indexOf(level) >= levels.indexOf(this.minLevel);
|
|
69
|
+
}
|
|
70
|
+
formatMessage(level, message, data) {
|
|
71
|
+
const timestamp = new Date().toISOString();
|
|
72
|
+
const baseMessage = `[${timestamp}] ${level.toUpperCase()} [${this.component}] ${message}`;
|
|
73
|
+
if (data) {
|
|
74
|
+
return `${baseMessage} ${JSON.stringify(data, null, 2)}`;
|
|
75
|
+
}
|
|
76
|
+
return baseMessage;
|
|
77
|
+
}
|
|
78
|
+
debug(message, data) {
|
|
79
|
+
if (this.shouldLog(LogLevel.DEBUG)) {
|
|
80
|
+
console.debug(this.formatMessage(LogLevel.DEBUG, message, data));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
info(message, data) {
|
|
84
|
+
if (this.shouldLog(LogLevel.INFO)) {
|
|
85
|
+
console.info(this.formatMessage(LogLevel.INFO, message, data));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
warn(message, data) {
|
|
89
|
+
if (this.shouldLog(LogLevel.WARN)) {
|
|
90
|
+
console.warn(this.formatMessage(LogLevel.WARN, message, data));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
error(message, error, data) {
|
|
94
|
+
if (this.shouldLog(LogLevel.ERROR)) {
|
|
95
|
+
const errorData = error ? { error: this.serializeError(error), ...data } : data;
|
|
96
|
+
console.error(this.formatMessage(LogLevel.ERROR, message, errorData));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
fatal(message, error, data) {
|
|
100
|
+
if (this.shouldLog(LogLevel.FATAL)) {
|
|
101
|
+
const errorData = error ? { error: this.serializeError(error), ...data } : data;
|
|
102
|
+
console.error(this.formatMessage(LogLevel.FATAL, message, errorData));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
serializeError(error) {
|
|
106
|
+
if ('category' in error) {
|
|
107
|
+
// AppError
|
|
108
|
+
return {
|
|
109
|
+
id: error.id,
|
|
110
|
+
code: error.code,
|
|
111
|
+
category: error.category,
|
|
112
|
+
severity: error.severity,
|
|
113
|
+
message: error.message,
|
|
114
|
+
context: error.context
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// Native Error
|
|
119
|
+
return {
|
|
120
|
+
name: error.name,
|
|
121
|
+
message: error.message,
|
|
122
|
+
stack: error.stack
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.ConsoleLogger = ConsoleLogger;
|
|
128
|
+
/**
|
|
129
|
+
* Error handler factory and utilities
|
|
130
|
+
*/
|
|
131
|
+
class ErrorHandler {
|
|
132
|
+
static requestIdCounter = 0;
|
|
133
|
+
static logger = new ConsoleLogger('ErrorHandler');
|
|
134
|
+
/**
|
|
135
|
+
* Set custom logger implementation
|
|
136
|
+
*/
|
|
137
|
+
static setLogger(logger) {
|
|
138
|
+
this.logger = logger;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Generate unique request ID
|
|
142
|
+
*/
|
|
143
|
+
static generateRequestId() {
|
|
144
|
+
return `req_${Date.now()}_${++this.requestIdCounter}`;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Create comprehensive AppError from various error sources
|
|
148
|
+
*/
|
|
149
|
+
static createError(category, severity, message, context, originalError) {
|
|
150
|
+
const errorId = `err_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
151
|
+
const timestamp = new Date();
|
|
152
|
+
const fullContext = {
|
|
153
|
+
operation: context.operation || 'unknown',
|
|
154
|
+
component: context.component || 'unknown',
|
|
155
|
+
timestamp,
|
|
156
|
+
version: process.env.npm_package_version || '0.1.0',
|
|
157
|
+
originalError,
|
|
158
|
+
stackTrace: originalError?.stack || new Error().stack,
|
|
159
|
+
isRetryable: context.isRetryable || false,
|
|
160
|
+
retryCount: context.retryCount || 0,
|
|
161
|
+
...context
|
|
162
|
+
};
|
|
163
|
+
const suggestedActions = context.suggestedActions || this.getDefaultSuggestedActions(category);
|
|
164
|
+
const appError = {
|
|
165
|
+
id: errorId,
|
|
166
|
+
code: this.generateErrorCode(category, severity),
|
|
167
|
+
category,
|
|
168
|
+
severity,
|
|
169
|
+
message,
|
|
170
|
+
userMessage: this.getUserFriendlyMessage(category),
|
|
171
|
+
technicalDetails: originalError?.message,
|
|
172
|
+
context: fullContext,
|
|
173
|
+
timestamp,
|
|
174
|
+
suggestedActions,
|
|
175
|
+
isRetryable: fullContext.isRetryable || false,
|
|
176
|
+
// Don't wrap the original error to prevent circular references
|
|
177
|
+
cause: undefined
|
|
178
|
+
};
|
|
179
|
+
// Log the error
|
|
180
|
+
this.logger.error(`Error created: ${message}`, appError, {
|
|
181
|
+
category,
|
|
182
|
+
severity,
|
|
183
|
+
operation: fullContext.operation,
|
|
184
|
+
component: fullContext.component
|
|
185
|
+
});
|
|
186
|
+
return appError;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Convert AppError to McpError for MCP protocol
|
|
190
|
+
*/
|
|
191
|
+
static toMcpError(appError) {
|
|
192
|
+
const errorCode = this.mapToMcpErrorCode(appError.category);
|
|
193
|
+
const message = `${appError.message}${appError.technicalDetails ? ` - ${appError.technicalDetails}` : ''}`;
|
|
194
|
+
return new types_js_1.McpError(errorCode, message);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Handle error with automatic logging and context enhancement
|
|
198
|
+
*/
|
|
199
|
+
static handleError(error, context, options = {}) {
|
|
200
|
+
let appError;
|
|
201
|
+
if ('category' in error) {
|
|
202
|
+
// Already an AppError
|
|
203
|
+
appError = error;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
// Convert native Error to AppError
|
|
207
|
+
appError = this.createError(this.categorizeError(error), this.assessSeverity(error), error.message, context, error);
|
|
208
|
+
}
|
|
209
|
+
// Log the handled error
|
|
210
|
+
const logLevel = options.logLevel || LogLevel.ERROR;
|
|
211
|
+
this.logger[logLevel](`Error handled in ${context.component || 'unknown'}`, appError);
|
|
212
|
+
if (options.convertToMcp) {
|
|
213
|
+
const mcpError = this.toMcpError(appError);
|
|
214
|
+
if (options.rethrow) {
|
|
215
|
+
throw mcpError;
|
|
216
|
+
}
|
|
217
|
+
return mcpError;
|
|
218
|
+
}
|
|
219
|
+
if (options.rethrow) {
|
|
220
|
+
throw appError;
|
|
221
|
+
}
|
|
222
|
+
return appError;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Wrap operation with error handling
|
|
226
|
+
*/
|
|
227
|
+
static async withErrorHandling(operation, context, options = {}) {
|
|
228
|
+
const maxRetries = options.retryCount || 0;
|
|
229
|
+
let lastError;
|
|
230
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
231
|
+
try {
|
|
232
|
+
this.logger.debug(`Executing operation: ${context.operation}`, {
|
|
233
|
+
attempt: attempt + 1,
|
|
234
|
+
maxRetries: maxRetries + 1
|
|
235
|
+
});
|
|
236
|
+
return await operation();
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
lastError = error;
|
|
240
|
+
const enhancedContext = {
|
|
241
|
+
...context,
|
|
242
|
+
retryCount: attempt,
|
|
243
|
+
isRetryable: attempt < maxRetries
|
|
244
|
+
};
|
|
245
|
+
const appError = this.handleError(lastError, enhancedContext, {
|
|
246
|
+
logLevel: attempt < maxRetries ? LogLevel.WARN : LogLevel.ERROR
|
|
247
|
+
});
|
|
248
|
+
// Retry if we haven't exceeded max retries and the error is retryable
|
|
249
|
+
// For retry logic, we consider errors retryable by default unless explicitly marked as not retryable
|
|
250
|
+
const shouldRetry = attempt < maxRetries && (appError.isRetryable || enhancedContext.isRetryable);
|
|
251
|
+
if (shouldRetry) {
|
|
252
|
+
this.logger.info(`Retrying operation: ${context.operation}`, {
|
|
253
|
+
attempt: attempt + 1,
|
|
254
|
+
maxRetries: maxRetries + 1,
|
|
255
|
+
reason: appError.message
|
|
256
|
+
});
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
// Final attempt failed or not retryable
|
|
260
|
+
if (options.convertToMcp) {
|
|
261
|
+
throw this.toMcpError(appError);
|
|
262
|
+
}
|
|
263
|
+
throw appError;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// This should never be reached, but TypeScript requires it
|
|
267
|
+
throw lastError;
|
|
268
|
+
}
|
|
269
|
+
static generateErrorCode(category, severity) {
|
|
270
|
+
const categoryCode = category.toUpperCase().replace('_', '');
|
|
271
|
+
const severityCode = severity.charAt(0).toUpperCase();
|
|
272
|
+
const timestamp = Date.now().toString().slice(-6);
|
|
273
|
+
const random = Math.random().toString(36).substring(2, 5);
|
|
274
|
+
return `${categoryCode}_${severityCode}_${timestamp}_${random}`;
|
|
275
|
+
}
|
|
276
|
+
static mapToMcpErrorCode(category) {
|
|
277
|
+
switch (category) {
|
|
278
|
+
case ErrorCategory.VALIDATION:
|
|
279
|
+
return types_js_1.ErrorCode.InvalidParams;
|
|
280
|
+
case ErrorCategory.AUTHENTICATION:
|
|
281
|
+
case ErrorCategory.AUTHORIZATION:
|
|
282
|
+
return types_js_1.ErrorCode.InvalidParams;
|
|
283
|
+
case ErrorCategory.MCP_PROTOCOL:
|
|
284
|
+
return types_js_1.ErrorCode.MethodNotFound;
|
|
285
|
+
case ErrorCategory.OPERATION:
|
|
286
|
+
case ErrorCategory.CLI_INTERFACE:
|
|
287
|
+
return types_js_1.ErrorCode.InvalidRequest;
|
|
288
|
+
default:
|
|
289
|
+
return types_js_1.ErrorCode.InternalError;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
static categorizeError(error) {
|
|
293
|
+
const message = error.message.toLowerCase();
|
|
294
|
+
if (message.includes('kubeconfig') || message.includes('kubernetes')) {
|
|
295
|
+
return ErrorCategory.KUBERNETES;
|
|
296
|
+
}
|
|
297
|
+
if (message.includes('network') || message.includes('connection')) {
|
|
298
|
+
return ErrorCategory.NETWORK;
|
|
299
|
+
}
|
|
300
|
+
if (message.includes('authentication') || message.includes('unauthorized')) {
|
|
301
|
+
return ErrorCategory.AUTHENTICATION;
|
|
302
|
+
}
|
|
303
|
+
if (message.includes('anthropic') || message.includes('ai') || message.includes('claude') || message.includes('api key invalid')) {
|
|
304
|
+
return ErrorCategory.AI_SERVICE;
|
|
305
|
+
}
|
|
306
|
+
if (message.includes('validation') || message.includes('invalid')) {
|
|
307
|
+
return ErrorCategory.VALIDATION;
|
|
308
|
+
}
|
|
309
|
+
return ErrorCategory.UNKNOWN;
|
|
310
|
+
}
|
|
311
|
+
static assessSeverity(error) {
|
|
312
|
+
const message = error.message.toLowerCase();
|
|
313
|
+
if (message.includes('critical') || message.includes('fatal')) {
|
|
314
|
+
return ErrorSeverity.CRITICAL;
|
|
315
|
+
}
|
|
316
|
+
if (message.includes('authentication') || message.includes('authorization')) {
|
|
317
|
+
return ErrorSeverity.HIGH;
|
|
318
|
+
}
|
|
319
|
+
if (message.includes('validation') || message.includes('invalid')) {
|
|
320
|
+
return ErrorSeverity.MEDIUM;
|
|
321
|
+
}
|
|
322
|
+
return ErrorSeverity.LOW;
|
|
323
|
+
}
|
|
324
|
+
static getUserFriendlyMessage(category) {
|
|
325
|
+
switch (category) {
|
|
326
|
+
case ErrorCategory.KUBERNETES:
|
|
327
|
+
return 'Unable to connect to Kubernetes cluster. Please check your kubeconfig and cluster connectivity.';
|
|
328
|
+
case ErrorCategory.AUTHENTICATION:
|
|
329
|
+
return 'Authentication failed. Please verify your credentials.';
|
|
330
|
+
case ErrorCategory.VALIDATION:
|
|
331
|
+
return 'Input validation failed. Please check your parameters and try again.';
|
|
332
|
+
case ErrorCategory.AI_SERVICE:
|
|
333
|
+
return 'AI service is temporarily unavailable. Please try again later.';
|
|
334
|
+
default:
|
|
335
|
+
return 'An unexpected error occurred. Please try again or contact support.';
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
static getDefaultSuggestedActions(category) {
|
|
339
|
+
switch (category) {
|
|
340
|
+
case ErrorCategory.KUBERNETES:
|
|
341
|
+
return [
|
|
342
|
+
'Verify kubeconfig file exists and is valid',
|
|
343
|
+
'Check cluster connectivity with kubectl cluster-info',
|
|
344
|
+
'Ensure proper authentication credentials'
|
|
345
|
+
];
|
|
346
|
+
case ErrorCategory.VALIDATION:
|
|
347
|
+
return [
|
|
348
|
+
'Review input parameters for correct format',
|
|
349
|
+
'Check required fields are provided',
|
|
350
|
+
'Verify data types match expected schema'
|
|
351
|
+
];
|
|
352
|
+
case ErrorCategory.AI_SERVICE:
|
|
353
|
+
return [
|
|
354
|
+
'Check ANTHROPIC_API_KEY environment variable',
|
|
355
|
+
'Verify API key is valid and has sufficient credits',
|
|
356
|
+
'Try again after a short delay'
|
|
357
|
+
];
|
|
358
|
+
default:
|
|
359
|
+
return [
|
|
360
|
+
'Try the operation again',
|
|
361
|
+
'Check system logs for more details',
|
|
362
|
+
'Contact support if problem persists'
|
|
363
|
+
];
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
static wrapNativeError(error) {
|
|
367
|
+
const errorId = `err_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
368
|
+
const timestamp = new Date();
|
|
369
|
+
const category = this.categorizeError(error);
|
|
370
|
+
const severity = this.assessSeverity(error);
|
|
371
|
+
const context = {
|
|
372
|
+
operation: 'error_wrapping',
|
|
373
|
+
component: 'ErrorHandler',
|
|
374
|
+
timestamp,
|
|
375
|
+
version: process.env.npm_package_version || '0.1.0',
|
|
376
|
+
originalError: error,
|
|
377
|
+
stackTrace: error.stack,
|
|
378
|
+
isRetryable: false,
|
|
379
|
+
retryCount: 0
|
|
380
|
+
};
|
|
381
|
+
const appError = {
|
|
382
|
+
id: errorId,
|
|
383
|
+
code: this.generateErrorCode(category, severity),
|
|
384
|
+
category,
|
|
385
|
+
severity,
|
|
386
|
+
message: error.message,
|
|
387
|
+
userMessage: this.getUserFriendlyMessage(category),
|
|
388
|
+
technicalDetails: error.message,
|
|
389
|
+
context,
|
|
390
|
+
timestamp,
|
|
391
|
+
suggestedActions: this.getDefaultSuggestedActions(category),
|
|
392
|
+
isRetryable: false,
|
|
393
|
+
// No cause to prevent circular reference
|
|
394
|
+
cause: undefined
|
|
395
|
+
};
|
|
396
|
+
return appError;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
exports.ErrorHandler = ErrorHandler;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Intelligence Module
|
|
3
|
+
*
|
|
4
|
+
* Shared intelligence for both CLI and MCP interfaces
|
|
5
|
+
*/
|
|
6
|
+
import { KubernetesDiscovery } from './discovery';
|
|
7
|
+
import { MemorySystem } from './memory';
|
|
8
|
+
import { WorkflowEngine } from './workflow';
|
|
9
|
+
import { ClaudeIntegration } from './claude';
|
|
10
|
+
import { SchemaParser, ManifestValidator, ResourceRecommender } from './schema';
|
|
11
|
+
export interface CoreConfig {
|
|
12
|
+
kubernetesConfig?: string;
|
|
13
|
+
anthropicApiKey?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class DotAI {
|
|
16
|
+
private config;
|
|
17
|
+
private initialized;
|
|
18
|
+
readonly discovery: KubernetesDiscovery;
|
|
19
|
+
readonly memory: MemorySystem;
|
|
20
|
+
readonly workflow: WorkflowEngine;
|
|
21
|
+
readonly claude: ClaudeIntegration;
|
|
22
|
+
readonly schema: {
|
|
23
|
+
parser: SchemaParser;
|
|
24
|
+
validator: ManifestValidator;
|
|
25
|
+
ranker: ResourceRecommender | null;
|
|
26
|
+
parseResource: (resourceName: string) => Promise<any>;
|
|
27
|
+
rankResources: (intent: string) => Promise<any>;
|
|
28
|
+
};
|
|
29
|
+
constructor(config?: CoreConfig);
|
|
30
|
+
private validateConfig;
|
|
31
|
+
initialize(): Promise<void>;
|
|
32
|
+
isInitialized(): boolean;
|
|
33
|
+
getVersion(): string;
|
|
34
|
+
getAnthropicApiKey(): string | undefined;
|
|
35
|
+
}
|
|
36
|
+
export { KubernetesDiscovery } from './discovery';
|
|
37
|
+
export { MemorySystem } from './memory';
|
|
38
|
+
export { WorkflowEngine } from './workflow';
|
|
39
|
+
export { ClaudeIntegration } from './claude';
|
|
40
|
+
export { SchemaParser, ManifestValidator, ResourceRecommender } from './schema';
|
|
41
|
+
export default DotAI;
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CA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