ALwrity copilot: CopilotKit integration complete
This commit is contained in:
@@ -91,6 +91,10 @@ class RouterManager:
|
|||||||
from api.content_planning.strategy_copilot import router as strategy_copilot_router
|
from api.content_planning.strategy_copilot import router as strategy_copilot_router
|
||||||
self.include_router_safely(strategy_copilot_router, "strategy_copilot")
|
self.include_router_safely(strategy_copilot_router, "strategy_copilot")
|
||||||
|
|
||||||
|
# Error logging router
|
||||||
|
from routers.error_logging import router as error_logging_router
|
||||||
|
self.include_router_safely(error_logging_router, "error_logging")
|
||||||
|
|
||||||
logger.info("✅ Core routers included successfully")
|
logger.info("✅ Core routers included successfully")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
50
backend/routers/error_logging.py
Normal file
50
backend/routers/error_logging.py
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
"""
|
||||||
|
Error Logging Router
|
||||||
|
Provides endpoints for frontend error reporting
|
||||||
|
"""
|
||||||
|
from fastapi import APIRouter, HTTPException
|
||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import Optional
|
||||||
|
import logging
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class ErrorLogRequest(BaseModel):
|
||||||
|
error_message: str
|
||||||
|
error_stack: Optional[str] = None
|
||||||
|
component_stack: Optional[str] = None
|
||||||
|
user_id: Optional[str] = None
|
||||||
|
url: Optional[str] = None
|
||||||
|
user_agent: Optional[str] = None
|
||||||
|
timestamp: Optional[str] = None
|
||||||
|
additional_info: Optional[dict] = None
|
||||||
|
|
||||||
|
@router.post("/log-error")
|
||||||
|
async def log_frontend_error(error_log: ErrorLogRequest):
|
||||||
|
"""
|
||||||
|
Log errors from the frontend for monitoring and debugging
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# Log the error with all details
|
||||||
|
logger.error(
|
||||||
|
f"Frontend Error: {error_log.error_message}",
|
||||||
|
extra={
|
||||||
|
"error_stack": error_log.error_stack,
|
||||||
|
"component_stack": error_log.component_stack,
|
||||||
|
"user_id": error_log.user_id,
|
||||||
|
"url": error_log.url,
|
||||||
|
"user_agent": error_log.user_agent,
|
||||||
|
"timestamp": error_log.timestamp,
|
||||||
|
"additional_info": error_log.additional_info
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"status": "success",
|
||||||
|
"message": "Error logged successfully"
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to log frontend error: {str(e)}")
|
||||||
|
raise HTTPException(status_code=500, detail="Failed to log error")
|
||||||
|
|
||||||
@@ -228,28 +228,13 @@ const App: React.FC = () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
// Render app with or without CopilotKit based on whether we have a key
|
||||||
<ErrorBoundary
|
const renderApp = () => {
|
||||||
context="Application Root"
|
const appContent = (
|
||||||
showDetails={process.env.NODE_ENV === 'development'}
|
<Router>
|
||||||
onError={(error, errorInfo) => {
|
<ConditionalCopilotKit>
|
||||||
// Custom error handler - send to analytics/monitoring
|
<TokenInstaller />
|
||||||
console.error('Global error caught:', { error, errorInfo });
|
<Routes>
|
||||||
// TODO: Send to error tracking service (Sentry, LogRocket, etc.)
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<ClerkProvider publishableKey={clerkPublishableKey}>
|
|
||||||
<OnboardingProvider>
|
|
||||||
<CopilotKit
|
|
||||||
publicApiKey={copilotApiKey}
|
|
||||||
showDevConsole={false}
|
|
||||||
onError={(e) => console.error("CopilotKit Error:", e)}
|
|
||||||
|
|
||||||
>
|
|
||||||
<Router>
|
|
||||||
<ConditionalCopilotKit>
|
|
||||||
<TokenInstaller />
|
|
||||||
<Routes>
|
|
||||||
<Route path="/" element={<RootRoute />} />
|
<Route path="/" element={<RootRoute />} />
|
||||||
<Route
|
<Route
|
||||||
path="/onboarding"
|
path="/onboarding"
|
||||||
@@ -275,10 +260,41 @@ const App: React.FC = () => {
|
|||||||
<Route path="/wix/callback" element={<WixCallbackPage />} />
|
<Route path="/wix/callback" element={<WixCallbackPage />} />
|
||||||
<Route path="/wp/callback" element={<WordPressCallbackPage />} />
|
<Route path="/wp/callback" element={<WordPressCallbackPage />} />
|
||||||
<Route path="/gsc/callback" element={<GSCAuthCallback />} />
|
<Route path="/gsc/callback" element={<GSCAuthCallback />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</ConditionalCopilotKit>
|
</ConditionalCopilotKit>
|
||||||
</Router>
|
</Router>
|
||||||
|
);
|
||||||
|
|
||||||
|
// Only wrap with CopilotKit if we have a valid key
|
||||||
|
if (copilotApiKey && copilotApiKey.trim()) {
|
||||||
|
return (
|
||||||
|
<CopilotKit
|
||||||
|
publicApiKey={copilotApiKey}
|
||||||
|
showDevConsole={false}
|
||||||
|
onError={(e) => console.error("CopilotKit Error:", e)}
|
||||||
|
>
|
||||||
|
{appContent}
|
||||||
</CopilotKit>
|
</CopilotKit>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return app without CopilotKit if no key available
|
||||||
|
return appContent;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ErrorBoundary
|
||||||
|
context="Application Root"
|
||||||
|
showDetails={process.env.NODE_ENV === 'development'}
|
||||||
|
onError={(error, errorInfo) => {
|
||||||
|
// Custom error handler - send to analytics/monitoring
|
||||||
|
console.error('Global error caught:', { error, errorInfo });
|
||||||
|
// TODO: Send to error tracking service (Sentry, LogRocket, etc.)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ClerkProvider publishableKey={clerkPublishableKey}>
|
||||||
|
<OnboardingProvider>
|
||||||
|
{renderApp()}
|
||||||
</OnboardingProvider>
|
</OnboardingProvider>
|
||||||
</ClerkProvider>
|
</ClerkProvider>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
|
|||||||
Reference in New Issue
Block a user