UNPKG

superaugment

Version:

Enterprise-grade MCP server with world-class C++ analysis, robust error handling, and production-ready architecture for VS Code Augment

139 lines 4.2 kB
/** * Base Tool Class for SuperAugment * * Provides a standardized foundation for all SuperAugment tools with * unified error handling, logging, validation, and performance monitoring. */ import { z } from 'zod'; import type { SuperAugmentTool } from './ToolManager.js'; import type { ConfigManager } from '../config/ConfigManager.js'; import { SuperAugmentError } from '../errors/ErrorTypes.js'; /** * Tool execution context for tracking and monitoring */ export interface ToolExecutionContext { startTime: Date; toolName: string; arguments: Record<string, any>; sessionId?: string; userId?: string; requestId?: string; } /** * Tool execution result with metadata */ export interface ToolExecutionResult { content: Array<{ type: string; text?: string; data?: any; }>; metadata?: { executionTime: number; memoryUsage?: number; warnings?: string[]; performance?: Record<string, any>; }; } /** * Tool performance metrics */ interface ToolMetrics { totalExecutions: number; successfulExecutions: number; failedExecutions: number; averageExecutionTime: number; totalExecutionTime: number; lastExecutionTime?: Date; peakMemoryUsage: number; } /** * Abstract base class for all SuperAugment tools */ export declare abstract class BaseTool implements SuperAugmentTool { abstract readonly name: string; abstract readonly description: string; abstract readonly inputSchema: z.ZodSchema<any>; protected readonly configManager: ConfigManager; private metrics; private readonly maxExecutionTime; private readonly maxMemoryUsage; constructor(configManager: ConfigManager, options?: { maxExecutionTime?: number; maxMemoryUsage?: number; }); /** * Main execution method with full error handling and monitoring */ execute(args: Record<string, any>): Promise<ToolExecutionResult>; /** * Abstract method that subclasses must implement */ protected abstract executeInternal(args: Record<string, any>, context: ToolExecutionContext): Promise<ToolExecutionResult>; /** * Validate input arguments using the tool's schema */ protected validateInput(args: Record<string, any>): Promise<Record<string, any>>; /** * Execute tool with performance monitoring and timeout */ private executeWithMonitoring; /** * Pre-execution hook for setup and validation */ protected preExecute(context: ToolExecutionContext): Promise<void>; /** * Post-execution hook for cleanup and logging */ protected postExecute(context: ToolExecutionContext, _result: ToolExecutionResult): Promise<void>; /** * Handle execution errors with proper context and recovery */ protected handleExecutionError(error: unknown, context: ToolExecutionContext): Promise<void>; /** * Health check to ensure tool is ready for execution */ protected healthCheck(): Promise<void>; /** * Update tool execution metrics */ private updateMetrics; /** * Sanitize arguments for logging (remove sensitive data) */ protected sanitizeArgsForLogging(args: Record<string, any>): Record<string, any>; /** * Generate unique request ID for tracking */ private generateRequestId; /** * Get tool execution metrics */ getMetrics(): ToolMetrics; /** * Reset tool metrics */ resetMetrics(): void; /** * Get tool health status */ getHealthStatus(): Promise<{ healthy: boolean; metrics: ToolMetrics; lastError?: string; }>; /** * Utility method for creating standardized tool responses */ protected createResponse(text: string, additionalContent?: Array<{ type: string; text?: string; data?: any; }>, metadata?: Record<string, any>): ToolExecutionResult; /** * Utility method for creating error responses */ protected createErrorResponse(error: SuperAugmentError, includeDetails?: boolean): ToolExecutionResult; } export {}; //# sourceMappingURL=BaseTool.d.ts.map