🔧 Fix: Correction de compatibilité configuration et interface

- Ajout de compatibilité ancienne structure config.ai
- Support des deux types d'interface (Terminal et ModernInterface)
- Helper displayMessage pour unifier l'affichage
- Correction des types de configuration NeuraConfig
- Fix initialisation IA avec nouvelle config unifiée

NeuraTerm v2.0 se lance maintenant correctement avec la nouvelle architecture !
This commit is contained in:
Network Monitor Bot 2025-08-20 07:08:10 +02:00
parent 776bb44120
commit f248062ef1
3 changed files with 64 additions and 11 deletions

View File

@ -9,23 +9,24 @@ export async function initAI(config: any, auth: any): Promise<AIClient> {
const keyManager = auth.getKeyManager(); const keyManager = auth.getKeyManager();
const keys = keyManager.loadKeys(); const keys = keyManager.loadKeys();
// Utiliser la configuration unifiée pour les modèles
const providerConfig: ProviderConfig = { const providerConfig: ProviderConfig = {
openai: { openai: {
apiKey: keys.openai || '', apiKey: keys.openai || '',
model: config.ai.openai?.model || 'gpt-4o-mini', model: config.providers?.openai?.model || 'gpt-4o-mini',
baseUrl: config.ai.openai?.baseUrl baseUrl: config.providers?.openai?.base_url
}, },
mistral: { mistral: {
apiKey: keys.mistral || '', apiKey: keys.mistral || '',
model: config.ai.mistral?.model || 'mistral-large-latest', model: config.providers?.mistral?.model || 'mistral-large-latest',
baseUrl: config.ai.mistral?.baseUrl baseUrl: config.providers?.mistral?.base_url
}, },
defaultProvider: keys.openai ? 'openai' : 'mistral' defaultProvider: keys.openai ? 'openai' : 'mistral'
}; };
// Ajuster le provider par défaut selon les clés disponibles // Ajuster le provider par défaut selon la config et les clés disponibles
if (config.ai.defaultProvider && keys[config.ai.defaultProvider as keyof typeof keys]) { if (config.providers?.default && keys[config.providers.default as keyof typeof keys]) {
providerConfig.defaultProvider = config.ai.defaultProvider; providerConfig.defaultProvider = config.providers.default;
} }
return new AIClient(providerConfig); return new AIClient(providerConfig);

View File

@ -15,23 +15,31 @@ export class CommandProcessor {
constructor( constructor(
private config: any, private config: any,
private dependencies: { private dependencies: {
terminal: Terminal; terminal: any; // Peut être Terminal ou ModernInterface
auth: any; auth: any;
ai: AIClient; ai: AIClient;
codebase: any; codebase: any;
fileOps: any; fileOps: any;
execution: any; execution: any;
errors: any; errors: any;
engine?: any;
memory?: any;
identity?: any;
} }
) { ) {
this.taskPlanner = new TaskPlanner( this.taskPlanner = new TaskPlanner(
this.dependencies.ai, this.dependencies.ai,
this.dependencies.execution.getCommandExecutor() this.dependencies.execution.getCommandExecutor()
); );
// Utiliser le prompt de la nouvelle interface si disponible
const prompt = this.dependencies.terminal.getPrompt ?
this.dependencies.terminal.getPrompt() :
'🧠 NeuraTerm> ';
this.rl = readline.createInterface({ this.rl = readline.createInterface({
input: process.stdin, input: process.stdin,
output: process.stdout, output: process.stdout,
prompt: '🧠 NeuraTerm> ' prompt
}); });
} }
@ -49,7 +57,12 @@ export class CommandProcessor {
try { try {
await this.processCommand(command); await this.processCommand(command);
} catch (error) { } catch (error) {
// Support des deux types d'interface
if (this.dependencies.terminal.displayError) {
this.dependencies.terminal.displayError(error instanceof Error ? error.message : String(error)); this.dependencies.terminal.displayError(error instanceof Error ? error.message : String(error));
} else {
console.error(`❌ Erreur: ${error instanceof Error ? error.message : String(error)}`);
}
logger.error('Erreur lors du traitement de la commande:', error); logger.error('Erreur lors du traitement de la commande:', error);
} }
@ -62,6 +75,44 @@ export class CommandProcessor {
}); });
} }
/**
* Helper pour supporter les deux types d'interface
*/
private displayMessage(type: 'error' | 'success' | 'info' | 'warning', message: string): void {
const terminal = this.dependencies.terminal;
switch (type) {
case 'error':
if (terminal.displayError) {
terminal.displayError(message);
} else {
console.error(`❌ Erreur: ${message}`);
}
break;
case 'success':
if (terminal.displaySuccess) {
terminal.displaySuccess(message);
} else {
console.log(`${message}`);
}
break;
case 'info':
if (terminal.displayInfo) {
terminal.displayInfo(message);
} else {
console.log(`💡 ${message}`);
}
break;
case 'warning':
if (terminal.displayWarning) {
terminal.displayWarning(message);
} else {
console.log(`⚠️ ${message}`);
}
break;
}
}
private async processCommand(command: string): Promise<void> { private async processCommand(command: string): Promise<void> {
const [cmd, ...args] = command.split(' '); const [cmd, ...args] = command.split(' ');

View File

@ -129,8 +129,9 @@ export async function run(app: AppInstance): Promise<void> {
// Présentation de l'identité NeuraTerm // Présentation de l'identité NeuraTerm
console.log(app.identity.generateIntroduction()); console.log(app.identity.generateIntroduction());
// Authentification si nécessaire // Authentification des clés API si nécessaire
if (!app.auth.isAuthenticated()) { if (!app.auth.isAuthenticated()) {
console.log('\n🔑 Configuration des clés API requise...');
await app.auth.authenticate(); await app.auth.authenticate();
} }