Files
group_xinghuo_jinrong/web/src/App.tsx
T
zhanghongyu_0626 bcd6175d4e feat(analyst): Implement data analysis agent with authentication and query handling
- Introduced `analyst_auth_adapter.py` for managing authentication context and access control for the data analysis agent.
- Added new API endpoints in `analyst.py` for chat, dashboard, asset management, and metrics, utilizing the new authentication context.
- Created Pydantic models in `analyst_schemas.py` for request and response structures, ensuring consistent data handling.
- Updated SQL guard logic in `sql_guard.py` to enforce access restrictions based on user roles and contexts.
- Implemented migration scripts for new database tables related to the data analysis agent, enhancing data management capabilities.
- Removed legacy authentication code from `auth.py`, streamlining the authentication process.

This update significantly enhances the data analysis capabilities, providing a robust framework for querying and managing data securely.
2026-09-09 21:02:11 +08:00

111 lines
4.3 KiB
TypeScript

import { Navigate, Route, Routes } from 'react-router-dom'
import { AppLayout } from './layouts/AppLayout'
import { LoginPage } from './pages/login/LoginPage'
import { AnalystQueryPage } from './pages/analytics/AnalystQueryPage'
import { loadAuth } from './stores/authStore'
import { AgentBanner } from './components/AgentBanner'
import { CustomerWealthDashboard } from './pages/dashboard/CustomerWealthDashboard'
import { AdvisorClientsDashboard } from './pages/dashboard/AdvisorClientsDashboard'
import { AnalystMarketDashboard } from './pages/dashboard/AnalystMarketDashboard'
import { RiskAlertsDashboard } from './pages/dashboard/RiskAlertsDashboard'
import { CustomerProfilePage } from './pages/customer/CustomerProfilePage'
import { CustomerHoldingsPage } from './pages/customer/CustomerHoldingsPage'
import { CustomerTradesPage } from './pages/customer/CustomerTradesPage'
import { CustomerChatPage } from './pages/customer/CustomerChatPage'
import { AdvisorCustomersPage } from './pages/advisor/AdvisorCustomersPage'
import { MarketQuotesPage } from './pages/market/MarketQuotesPage'
import { RiskAlertsPage } from './pages/risk/RiskAlertsPage'
import { RiskChatPage } from './pages/risk/RiskChatPage'
import { ChatPanel } from './components/chat'
import { PageShell } from './components/PageShell'
import { useAppAuth } from './layouts/AppLayout'
function AdvisorChatShell() {
const auth = useAppAuth()
return (
<PageShell title="顾问助手">
<ChatPanel token={auth.accessToken} agentType="advisor" mode="stream" title="理财师顾问助手" />
</PageShell>
)
}
function AnalystChatShell() {
const auth = useAppAuth()
return (
<PageShell title="数据分析对话">
<ChatPanel token={auth.accessToken} agentType="analyst" mode="stream" title="数据分析 Agent" />
</PageShell>
)
}
function RequireAuth({ children }: { children: React.ReactNode }) {
const auth = loadAuth()
if (!auth) return <Navigate to="/login" replace />
return children
}
function RoleHomeRedirect() {
const auth = loadAuth()
if (!auth) return <Navigate to="/login" replace />
const path = auth.defaultRoute.replace(/^#/, '')
return <Navigate to={path} replace />
}
export default function AppRoutes() {
const auth = loadAuth()
return (
<Routes>
<Route path="/login" element={auth ? <Navigate to={auth.defaultRoute.replace(/^#/, '')} replace /> : <LoginPage />} />
<Route
path="/app"
element={
<RequireAuth>
<AppLayout auth={loadAuth()!} />
</RequireAuth>
}
>
<Route index element={<RoleHomeRedirect />} />
<Route path="home" element={<RoleHomeRedirect />} />
<Route path="customer/home" element={<CustomerWealthDashboard />} />
<Route path="customer/profile" element={<CustomerProfilePage />} />
<Route path="customer/holdings" element={<CustomerHoldingsPage />} />
<Route path="customer/trades" element={<CustomerTradesPage />} />
<Route path="customer/chat" element={<CustomerChatPage />} />
<Route path="advisor/home" element={<AdvisorClientsDashboard />} />
<Route path="advisor/customers" element={<AdvisorCustomersPage />} />
<Route
path="advisor/chat"
element={
<div className="space-y-4">
<AgentBanner message="顾问 Agent:可查询名下客户持仓/流水与公开知识库;指定客户请在消息中说明 customer_id。" />
<AdvisorChatShell />
</div>
}
/>
<Route path="analyst/home" element={<AnalystMarketDashboard />} />
<Route path="analytics/query" element={<AnalystQueryPage />} />
<Route
path="analytics/chat"
element={
<div className="space-y-4">
<AgentBanner message="轻量对话占位;NL2SQL 查数(表格+SQL)请使用「问数工作台」。" />
<AnalystChatShell />
</div>
}
/>
<Route path="risk/home" element={<RiskAlertsDashboard />} />
<Route path="risk/alerts" element={<RiskAlertsPage />} />
<Route path="risk/chat" element={<RiskChatPage />} />
<Route path="market" element={<MarketQuotesPage />} />
</Route>
<Route path="*" element={<Navigate to={auth ? auth.defaultRoute.replace(/^#/, '') : '/login'} replace />} />
</Routes>
)
}