UNPKG

vscode-ai-model-detector

Version:

Real-time AI model detection with 100% accuracy using Chat Participant API

294 lines (251 loc) 10.8 kB
import * as vscode from 'vscode'; import { ModelDetectorService } from './modelDetector'; import { ModelInfo } from './types'; /** * Status bar integration for continuous AI model monitoring */ export class StatusBarManager { private statusBarItem: vscode.StatusBarItem; private detectorService: ModelDetectorService; private updateInterval: NodeJS.Timeout | undefined; private isEnabled: boolean = false; constructor(detectorService: ModelDetectorService) { this.detectorService = detectorService; // Create status bar item this.statusBarItem = vscode.window.createStatusBarItem( vscode.StatusBarAlignment.Left, 100 // Priority - higher numbers = more left ); // Configure status bar item this.statusBarItem.command = 'aiModelDetector.showQuickPick'; this.statusBarItem.tooltip = 'Click for AI Model Detection details'; // Initialize based on configuration this.loadConfiguration(); } /** * Initialize status bar based on configuration */ private async loadConfiguration(): Promise<void> { const config = vscode.workspace.getConfiguration('aiModelDetector'); const enableStatusBar = config.get<boolean>('enableStatusBar', true); if (enableStatusBar) { await this.enable(); } else { await this.disable(); } } /** * Enable status bar monitoring */ public async enable(): Promise<void> { if (this.isEnabled) { return; } this.isEnabled = true; this.statusBarItem.show(); // Initial update await this.updateModelDisplay(); // Set up periodic updates const config = vscode.workspace.getConfiguration('aiModelDetector'); const updateInterval = config.get<number>('statusBarUpdateInterval', 5000); this.updateInterval = setInterval(async () => { await this.updateModelDisplay(); }, updateInterval); console.log('AI Model Detector: Status bar monitoring enabled'); } /** * Disable status bar monitoring */ public async disable(): Promise<void> { if (!this.isEnabled) { return; } this.isEnabled = false; this.statusBarItem.hide(); // Clear update interval if (this.updateInterval) { clearInterval(this.updateInterval); this.updateInterval = undefined; } console.log('AI Model Detector: Status bar monitoring disabled'); } /** * Toggle status bar monitoring */ public async toggle(): Promise<void> { if (this.isEnabled) { await this.disable(); } else { await this.enable(); } // Update configuration const config = vscode.workspace.getConfiguration('aiModelDetector'); await config.update('enableStatusBar', this.isEnabled, vscode.ConfigurationTarget.Global); } /** * Update the status bar with current model information */ private async updateModelDisplay(): Promise<void> { if (!this.isEnabled) { return; } try { // Try to get current model information const result = await this.detectorService.detectCurrentModel(); if (result.success && result.model) { this.displayModel(result.model); } else { this.displayError(result.error); } } catch (error) { this.displayError(`Detection failed: ${error instanceof Error ? error.message : 'Unknown error'}`); } } /** * Display model information in status bar */ private displayModel(model: ModelInfo): void { // Determine icon based on vendor const vendorIcon = this.getVendorIcon(model.vendor); // Determine accuracy color const accuracyIcon = model.accuracy === 'Perfect' ? '✅' : model.accuracy === 'Available' ? '🔍' : model.accuracy === 'Cached' ? '💾' : '❓'; // Create display text const displayText = `${vendorIcon} ${model.name}`; // Update status bar this.statusBarItem.text = displayText; this.statusBarItem.tooltip = this.createTooltip(model); this.statusBarItem.backgroundColor = undefined; // Normal color this.statusBarItem.color = undefined; // Normal color } /** * Display error state in status bar */ private displayError(error?: string): void { this.statusBarItem.text = `❌ AI Model`; this.statusBarItem.tooltip = `AI Model Detection Error: ${error || 'Unknown error'}`; this.statusBarItem.backgroundColor = new vscode.ThemeColor('statusBarItem.errorBackground'); this.statusBarItem.color = new vscode.ThemeColor('statusBarItem.errorForeground'); } /** * Get appropriate icon for AI vendor */ private getVendorIcon(vendor: string): string { const vendorLower = vendor.toLowerCase(); if (vendorLower.includes('openai') || vendorLower.includes('gpt')) { return '🤖'; // OpenAI/GPT } else if (vendorLower.includes('anthropic') || vendorLower.includes('claude')) { return '🔮'; // Anthropic/Claude } else if (vendorLower.includes('google') || vendorLower.includes('gemini')) { return '🧠'; // Google/Gemini } else if (vendorLower.includes('microsoft') || vendorLower.includes('copilot')) { return '🚀'; // Microsoft/Copilot } else if (vendorLower.includes('meta') || vendorLower.includes('llama')) { return '🦙'; // Meta/LLaMA } else { return '🎯'; // Generic AI } } /** * Create detailed tooltip for status bar item */ private createTooltip(model: ModelInfo): string { const lines = [ `AI Model: ${model.name}`, `Vendor: ${model.vendor}`, `Family: ${model.family}`, `Version: ${model.version}`, `Max Tokens: ${model.maxTokens.toLocaleString()}`, ``, `Accuracy: ${model.accuracy}`, `Source: ${model.source}`, `Last Updated: ${model.timestamp.toLocaleString()}`, ``, `Click for detailed information and controls` ]; return lines.join('\n'); } /** * Show quick pick with model information and actions */ public async showQuickPick(): Promise<void> { try { // Get current model information const result = await this.detectorService.detectCurrentModel(); if (!result.success || !result.model) { vscode.window.showErrorMessage(`AI Model Detection failed: ${result.error}`); return; } const model = result.model; // Create quick pick items const items: vscode.QuickPickItem[] = [ { label: `$(info) Current Model: ${model.name}`, description: `${model.vendor} - ${model.family} v${model.version}`, detail: `Accuracy: ${model.accuracy} | Max Tokens: ${model.maxTokens.toLocaleString()}` }, { label: `$(refresh) Refresh Detection`, description: 'Force a new model detection', detail: 'Updates model information from all available sources' }, { label: `$(history) Show Detection History`, description: 'View previous model detections', detail: 'Shows chronological history of detected models' }, { label: `$(settings-gear) Open Settings`, description: 'Configure AI Model Detector', detail: 'Adjust monitoring intervals and display options' }, { label: this.isEnabled ? `$(eye-closed) Disable Monitoring` : `$(eye) Enable Monitoring`, description: this.isEnabled ? 'Hide status bar item' : 'Show status bar item', detail: 'Toggle continuous model monitoring' } ]; // Show quick pick const selected = await vscode.window.showQuickPick(items, { placeHolder: 'AI Model Detector Actions', title: `Current Model: ${model.name} (${model.vendor})` }); // Handle selection if (selected) { await this.handleQuickPickSelection(selected); } } catch (error) { vscode.window.showErrorMessage(`Error showing model information: ${error instanceof Error ? error.message : 'Unknown error'}`); } } /** * Handle quick pick selection */ private async handleQuickPickSelection(item: vscode.QuickPickItem): Promise<void> { if (item.label.includes('Refresh Detection')) { await vscode.commands.executeCommand('aiModelDetector.detect'); } else if (item.label.includes('Detection History')) { await vscode.commands.executeCommand('aiModelDetector.showHistory'); } else if (item.label.includes('Open Settings')) { await vscode.commands.executeCommand('workbench.action.openSettings', 'aiModelDetector'); } else if (item.label.includes('Disable Monitoring') || item.label.includes('Enable Monitoring')) { await this.toggle(); } } /** * Force update the display */ public async forceUpdate(): Promise<void> { await this.updateModelDisplay(); } /** * Dispose of the status bar item and interval */ public dispose(): void { if (this.updateInterval) { clearInterval(this.updateInterval); } this.statusBarItem.dispose(); } }