prompt-plus-plus-mcp
Version:
Advanced MCP server with 44+ metaprompt strategies including AI Core Principles, Vibe Coding Rules, and metadata-driven intelligent selection
142 lines • 4.94 kB
JavaScript
export var ErrorCode;
(function (ErrorCode) {
ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
ErrorCode["VALIDATION_ERROR"] = "VALIDATION_ERROR";
ErrorCode["MCP_PROTOCOL_ERROR"] = "MCP_PROTOCOL_ERROR";
ErrorCode["STRATEGY_NOT_FOUND"] = "STRATEGY_NOT_FOUND";
ErrorCode["STRATEGY_ERROR"] = "STRATEGY_ERROR";
ErrorCode["WORKFLOW_ERROR"] = "WORKFLOW_ERROR";
ErrorCode["CACHE_ERROR"] = "CACHE_ERROR";
ErrorCode["CACHE_CAPACITY_EXCEEDED"] = "CACHE_CAPACITY_EXCEEDED";
ErrorCode["TIMEOUT_ERROR"] = "TIMEOUT_ERROR";
ErrorCode["RATE_LIMIT_ERROR"] = "RATE_LIMIT_ERROR";
ErrorCode["CONFIGURATION_ERROR"] = "CONFIGURATION_ERROR";
ErrorCode["PERMISSION_ERROR"] = "PERMISSION_ERROR";
})(ErrorCode || (ErrorCode = {}));
export var ErrorSeverity;
(function (ErrorSeverity) {
ErrorSeverity["LOW"] = "LOW";
ErrorSeverity["MEDIUM"] = "MEDIUM";
ErrorSeverity["HIGH"] = "HIGH";
ErrorSeverity["CRITICAL"] = "CRITICAL";
})(ErrorSeverity || (ErrorSeverity = {}));
export class BaseError extends Error {
code;
context;
timestamp;
severity;
cause;
constructor(message, code = ErrorCode.UNKNOWN_ERROR, context = {}, cause) {
super(message);
this.name = this.constructor.name;
this.code = code;
this.context = context;
this.timestamp = new Date();
this.severity = context.severity || ErrorSeverity.MEDIUM;
this.cause = cause;
// Maintain proper prototype chain
Object.setPrototypeOf(this, new.target.prototype);
// Capture stack trace
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
}
toJSON() {
return {
name: this.name,
message: this.message,
code: this.code,
severity: this.severity,
timestamp: this.timestamp.toISOString(),
context: this.sanitizeContext()
};
}
sanitizeContext() {
const sanitized = {};
for (const [key, value] of Object.entries(this.context)) {
// Don't include sensitive information
if (key.toLowerCase().includes('password') ||
key.toLowerCase().includes('token') ||
key.toLowerCase().includes('secret')) {
sanitized[key] = '[REDACTED]';
}
else if (typeof value === 'object' && value !== null) {
// Truncate large objects
sanitized[key] = JSON.stringify(value).substring(0, 100) + '...';
}
else {
sanitized[key] = value;
}
}
return sanitized;
}
}
export class ValidationError extends BaseError {
constructor(message, context) {
super(message, ErrorCode.VALIDATION_ERROR, context);
}
}
export class MCPProtocolError extends BaseError {
constructor(message, context) {
super(message, ErrorCode.MCP_PROTOCOL_ERROR, {
...context,
severity: ErrorSeverity.HIGH
});
}
}
export class StrategyError extends BaseError {
constructor(message, context) {
super(message, ErrorCode.STRATEGY_ERROR, context);
}
}
export class CacheError extends BaseError {
constructor(message, context) {
super(message, ErrorCode.CACHE_ERROR, context);
}
}
export class TimeoutError extends BaseError {
constructor(message, timeout, context) {
super(message, ErrorCode.TIMEOUT_ERROR, {
...context,
timeout,
severity: ErrorSeverity.HIGH
});
}
}
export class ConfigurationError extends BaseError {
constructor(message, context) {
super(message, ErrorCode.CONFIGURATION_ERROR, {
...context,
severity: ErrorSeverity.CRITICAL
});
}
}
// Error utilities
export function isPromptPlusError(error) {
return error instanceof BaseError;
}
export function createError(code, message, context) {
switch (code) {
case ErrorCode.VALIDATION_ERROR:
return new ValidationError(message, context);
case ErrorCode.MCP_PROTOCOL_ERROR:
return new MCPProtocolError(message, context);
case ErrorCode.STRATEGY_ERROR:
return new StrategyError(message, context);
case ErrorCode.CACHE_ERROR:
return new CacheError(message, context);
case ErrorCode.CONFIGURATION_ERROR:
return new ConfigurationError(message, context);
default:
return new BaseError(message, code, context);
}
}
export function wrapError(error, code, context) {
if (isPromptPlusError(error)) {
return error;
}
const message = error instanceof Error ? error.message : String(error);
const cause = error instanceof Error ? error : undefined;
return new BaseError(message, code, context, cause);
}
//# sourceMappingURL=errors.js.map