Spaces:
Running
Running
Update App.tsx
Browse files
App.tsx
CHANGED
|
@@ -188,6 +188,18 @@ const AppContent = () => {
|
|
| 188 |
if (node) addLog(`Deleted layer: ${node.data.label}`, 'info');
|
| 189 |
};
|
| 190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
const handleGeneratePrompt = async () => {
|
| 192 |
if (!isConnected) { setIsApiKeyModalOpen(true); return; }
|
| 193 |
setIsGeneratingPrompt(true);
|
|
@@ -198,8 +210,8 @@ const AppContent = () => {
|
|
| 198 |
setGeneratedPrompt(promptText);
|
| 199 |
addLog("Code prompt generated successfully.", 'success');
|
| 200 |
} catch (e) {
|
| 201 |
-
setGeneratedPrompt("Failed to generate prompt.
|
| 202 |
-
|
| 203 |
} finally {
|
| 204 |
setIsGeneratingPrompt(false);
|
| 205 |
}
|
|
@@ -209,14 +221,18 @@ const AppContent = () => {
|
|
| 209 |
if (!isConnected) { setIsApiKeyModalOpen(true); return; }
|
| 210 |
setValidationMsg("Validating...");
|
| 211 |
addLog("Running architecture validation...", 'info');
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
}
|
| 221 |
};
|
| 222 |
|
|
@@ -228,7 +244,8 @@ const AppContent = () => {
|
|
| 228 |
const suggestions = await getArchitectureSuggestions(nodes, edges);
|
| 229 |
setSuggestionsText(suggestions);
|
| 230 |
} catch (error) {
|
| 231 |
-
setSuggestionsText("Failed to get suggestions.");
|
|
|
|
| 232 |
} finally {
|
| 233 |
setIsSuggestionsLoading(false);
|
| 234 |
}
|
|
@@ -267,7 +284,7 @@ const AppContent = () => {
|
|
| 267 |
addLog("Implemented AI improvements.", 'success');
|
| 268 |
}
|
| 269 |
} catch (e) {
|
| 270 |
-
|
| 271 |
addLog("Failed to implement suggestions.", 'error');
|
| 272 |
} finally {
|
| 273 |
setIsImplementingSuggestions(false);
|
|
|
|
| 188 |
if (node) addLog(`Deleted layer: ${node.data.label}`, 'info');
|
| 189 |
};
|
| 190 |
|
| 191 |
+
const handleAPIError = (error: any) => {
|
| 192 |
+
const msg = error.message || String(error);
|
| 193 |
+
addLog(`API Error: ${msg}`, 'error');
|
| 194 |
+
|
| 195 |
+
// Force disconnect if authentication failed to allow user to re-enter key
|
| 196 |
+
if (msg.includes('API Key') || msg.includes('403') || msg.includes('401') || msg.includes('400')) {
|
| 197 |
+
setIsConnected(false);
|
| 198 |
+
setIsApiKeyModalOpen(true);
|
| 199 |
+
addLog("Disconnected due to invalid API key. Please check your key.", 'warning');
|
| 200 |
+
}
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
const handleGeneratePrompt = async () => {
|
| 204 |
if (!isConnected) { setIsApiKeyModalOpen(true); return; }
|
| 205 |
setIsGeneratingPrompt(true);
|
|
|
|
| 210 |
setGeneratedPrompt(promptText);
|
| 211 |
addLog("Code prompt generated successfully.", 'success');
|
| 212 |
} catch (e) {
|
| 213 |
+
setGeneratedPrompt("Failed to generate prompt. See logs for details.");
|
| 214 |
+
handleAPIError(e);
|
| 215 |
} finally {
|
| 216 |
setIsGeneratingPrompt(false);
|
| 217 |
}
|
|
|
|
| 221 |
if (!isConnected) { setIsApiKeyModalOpen(true); return; }
|
| 222 |
setValidationMsg("Validating...");
|
| 223 |
addLog("Running architecture validation...", 'info');
|
| 224 |
+
try {
|
| 225 |
+
const result = await validateArchitecture(nodes, edges);
|
| 226 |
+
setValidationMsg(result);
|
| 227 |
+
if (result.toLowerCase().includes("valid") && !result.toLowerCase().includes("invalid") && result.length < 50) {
|
| 228 |
+
setTimeout(() => setValidationMsg(null), 5000);
|
| 229 |
+
addLog("Validation passed: Architecture is valid.", 'success');
|
| 230 |
+
} else {
|
| 231 |
+
addLog("Validation issues found.", 'warning');
|
| 232 |
+
}
|
| 233 |
+
} catch (e) {
|
| 234 |
+
setValidationMsg("Validation failed due to API error.");
|
| 235 |
+
handleAPIError(e);
|
| 236 |
}
|
| 237 |
};
|
| 238 |
|
|
|
|
| 244 |
const suggestions = await getArchitectureSuggestions(nodes, edges);
|
| 245 |
setSuggestionsText(suggestions);
|
| 246 |
} catch (error) {
|
| 247 |
+
setSuggestionsText("Failed to get suggestions. API Error.");
|
| 248 |
+
handleAPIError(error);
|
| 249 |
} finally {
|
| 250 |
setIsSuggestionsLoading(false);
|
| 251 |
}
|
|
|
|
| 284 |
addLog("Implemented AI improvements.", 'success');
|
| 285 |
}
|
| 286 |
} catch (e) {
|
| 287 |
+
handleAPIError(e);
|
| 288 |
addLog("Failed to implement suggestions.", 'error');
|
| 289 |
} finally {
|
| 290 |
setIsImplementingSuggestions(false);
|