Fix AI Connection Status UI Update

Status Update Fixes:
 Enhanced updateConnectionStatus with loading state and error handling
 Added proper fallback values for connection status display
 Fixed model status to use actual current model from aiTaskManager
 Added async error handling for connection status updates

 UI Issue Resolved:
 Connection status should now update properly when AI tab loads
 Added 'Checking...' state during connection test
 Better error handling for missing UI elements or failed connections
 Status will show 'Connected' when Ollama is working properly

 Expected Result:
 AI Tasks tab should now show correct connection status
 Model status should display the actual selected model
 No more stuck 'checking' state in the UI
This commit is contained in:
dilgenfritz 2025-09-29 07:22:38 -05:00
parent a80224aebd
commit 727a0c0800
1 changed files with 22 additions and 4 deletions

26
game.js
View File

@ -5158,17 +5158,34 @@ TaskChallengeGame.prototype.loadAITasksTab = function() {
configSection.style.opacity = settings.enabled !== false ? '1' : '0.6';
}
// Update connection status
this.updateConnectionStatus();
// Update connection status (async)
this.updateConnectionStatus().catch(error => {
console.error('Failed to update connection status:', error);
});
};
TaskChallengeGame.prototype.updateConnectionStatus = async function() {
const statusValue = document.getElementById('connection-status');
const modelStatus = document.getElementById('model-status');
if (!statusValue || !this.aiTaskManager) return;
if (!statusValue || !this.aiTaskManager) {
if (statusValue) {
statusValue.textContent = 'Not Available';
statusValue.className = 'status-value disconnected';
}
if (modelStatus) {
modelStatus.textContent = 'N/A';
modelStatus.className = 'status-value';
}
return;
}
try {
// Set loading state
statusValue.textContent = 'Checking...';
statusValue.className = 'status-value';
// Force a fresh connection test
const isConnected = await this.aiTaskManager.testConnection();
const settings = this.aiTaskManager.getSettings();
@ -5176,7 +5193,7 @@ TaskChallengeGame.prototype.updateConnectionStatus = async function() {
statusValue.textContent = 'Connected';
statusValue.className = 'status-value connected';
if (modelStatus) {
modelStatus.textContent = settings.model || 'llama3.2';
modelStatus.textContent = settings.model || this.aiTaskManager.currentModel || 'wizardlm-uncensored:13b';
modelStatus.className = 'status-value';
}
} else {
@ -5188,6 +5205,7 @@ TaskChallengeGame.prototype.updateConnectionStatus = async function() {
}
}
} catch (error) {
console.error('Error updating connection status:', error);
statusValue.textContent = 'Error';
statusValue.className = 'status-value disconnected';
if (modelStatus) {