- 后端新增 y_log 公开只读配置:YLogConfig + AppConfig.y_log + GET /api/public/config/y-log,地址写在 config.yaml(mtime 热重载) - 前端核心 src/core/log/:writeYLog(双门控/异步即发即忘/永不抛错/ 去ip-host/对象序列化裁剪/optResult恒0)+ 配置加载 + token1 隔离存取 - 登录(token)持久化 token1 并报登录、登出先报后清;启动预热配置 - 各 API client 成功路径埋点:敏感词/菜单/按钮/技能地址/轻应用、 会商草稿+任务草稿+后台任务、智能体/定时任务/知识库、Word导出, 以及问答完成钩子(ChatPage/AgentChatPage onFinish) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
171 lines
6.7 KiB
TypeScript
171 lines
6.7 KiB
TypeScript
import { useEffect, useMemo } from "react";
|
|
import { Navigate, Route, Routes } from "react-router-dom";
|
|
import { ThemeProvider as NextThemesProvider } from "next-themes";
|
|
|
|
import { DesensitizeWordsLoader } from "@/components/desensitize-words-loader";
|
|
import { FontScaleApplier } from "@/components/font-scale";
|
|
import { QueryClientProvider } from "@/components/query-client-provider";
|
|
import { AuthSyncWatcher } from "@/core/auth/sync";
|
|
import { I18nProvider } from "@/core/i18n/context";
|
|
import { fetchYLogConfig } from "@/core/log/y-log-config";
|
|
import { detectLocale } from "@/core/i18n/locale";
|
|
import { resolveForcedThemeForPath } from "@/core/page-layout/chats-iframe-route";
|
|
import { ChatProvider } from "@/contexts/ChatContext";
|
|
import { ThemeProvider } from "@/contexts/ThemeContext";
|
|
import {
|
|
resolveEmbedRoundtableTheme,
|
|
resolveEmbedTheme,
|
|
} from "@/core/embed/params";
|
|
import { usePublicEmbedTheme } from "@/core/embed/background";
|
|
import { readWujieProps } from "@/core/embed/wujie";
|
|
import {
|
|
resolveForcedEmbedTheme,
|
|
syncEmbedSessionFromSearch,
|
|
} from "@/core/embed/embed-session";
|
|
|
|
import { HashRouter, useLocation } from "react-router-dom";
|
|
|
|
import LandingPage from "./pages/LandingPage";
|
|
import LoginPage from "./pages/LoginPage";
|
|
import PageRoutes from "./pages/PageRoutes";
|
|
import PublicScheduledTaskPage, {
|
|
PublicScheduledTaskFullscreenPage,
|
|
} from "./pages/PublicScheduledTaskPage";
|
|
import PublicSharePage from "./pages/PublicSharePage";
|
|
import PublicLeaderboardPage from "./pages/PublicLeaderboardPage";
|
|
import PublicRoundtableSharePage from "./pages/PublicRoundtableSharePage";
|
|
import EmbedChatPage from "./pages/EmbedChatPage";
|
|
import EmbedRoundtablePage from "./pages/EmbedRoundtablePage";
|
|
import DashboardStandalonePage from "@/roundtable-planning/pages/DashboardStandalonePage";
|
|
import { ChatRuntime } from "./pages/WorkspaceRoutes";
|
|
import { NotFoundPage } from "./pages/NotFoundPage";
|
|
|
|
const PUBLIC_EMBED_PREFIXES = ["/share/", "/public/", "/roundtable-share/"];
|
|
|
|
function AppProviders({ children }: { children: React.ReactNode }) {
|
|
const locale = useMemo(() => detectLocale(), []);
|
|
const location = useLocation();
|
|
const publicEmbedTheme = usePublicEmbedTheme();
|
|
// iframe 嵌入会话(按标签页 sessionStorage)集中在此同步:任何带 `&embed=1` 的入口(深链登录页
|
|
// 或直接深链路由)一进来就启用、`embed=0` 关闭,后续干净路由靠会话维持去 chrome + 强制主题。
|
|
useEffect(() => {
|
|
syncEmbedSessionFromSearch(location.search);
|
|
}, [location.search]);
|
|
// 操作日志(Y-Log):启动早期预热上报配置,使 writeYLog 同步读缓存即可工作
|
|
// (刷新后 module 缓存清空,token 登录用户也能继续上报)。失败静默。
|
|
useEffect(() => {
|
|
void fetchYLogConfig();
|
|
}, []);
|
|
const forcedTheme = useMemo(() => {
|
|
// iframe 嵌入模式(外部系统 `&embed=1`)最高优先:按本标签页的嵌入主题强制明/暗。
|
|
// 走 next-themes forcedTheme(不写 localStorage)→ 同浏览器另开的正常系统页不受影响。
|
|
const embedTheme = resolveForcedEmbedTheme(location.search);
|
|
if (embedTheme) return embedTheme;
|
|
const routeTheme = resolveForcedThemeForPath(location.pathname);
|
|
if (routeTheme) return routeTheme;
|
|
if (location.pathname === "/embed/roundtable") {
|
|
const wp = readWujieProps();
|
|
const raw =
|
|
(typeof wp.theme === "string" && wp.theme.trim()) ||
|
|
new URLSearchParams(location.search).get("theme")?.trim() ||
|
|
"dark";
|
|
return resolveEmbedRoundtableTheme(raw);
|
|
}
|
|
if (location.pathname.startsWith("/embed/chats")) {
|
|
const raw = new URLSearchParams(location.search).get("theme")?.trim();
|
|
return raw ? resolveEmbedTheme(raw) : undefined;
|
|
}
|
|
if (PUBLIC_EMBED_PREFIXES.some((p) => location.pathname.startsWith(p))) {
|
|
return publicEmbedTheme;
|
|
}
|
|
return undefined;
|
|
}, [location.pathname, location.search, publicEmbedTheme]);
|
|
|
|
return (
|
|
<NextThemesProvider
|
|
attribute="class"
|
|
storageKey="strategy-theme"
|
|
defaultTheme="light"
|
|
themes={["light", "dark", "lightblue"]}
|
|
enableSystem={false}
|
|
disableTransitionOnChange
|
|
forcedTheme={forcedTheme}
|
|
>
|
|
<QueryClientProvider>
|
|
<I18nProvider initialLocale={locale}>
|
|
<ThemeProvider>
|
|
<ChatProvider>
|
|
<AuthSyncWatcher />
|
|
<DesensitizeWordsLoader />
|
|
<FontScaleApplier />
|
|
{children}
|
|
</ChatProvider>
|
|
</ThemeProvider>
|
|
</I18nProvider>
|
|
</QueryClientProvider>
|
|
</NextThemesProvider>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 根路由 `/` → `/login` 重定向,**保留 query string**。
|
|
* 外部系统的任务深链落在 `#/?taskId=...&goPath=...`,裸 `<Navigate to="/login">` 会丢掉
|
|
* query,导致 LoginPage 读不到参数;这里把 search 一并带过去。
|
|
*/
|
|
function RootRedirect() {
|
|
const { search } = useLocation();
|
|
return <Navigate to={`/login${search}`} replace />;
|
|
}
|
|
|
|
export function App() {
|
|
return (
|
|
<HashRouter>
|
|
<AppProviders>
|
|
<Routes>
|
|
<Route path="/" element={<RootRedirect />} />
|
|
<Route path="/login" element={<LoginPage />} />
|
|
<Route path="/login/:username" element={<LoginPage />} />
|
|
<Route path="/landing" element={<LandingPage />} />
|
|
<Route path="/share/:shareCode" element={<PublicSharePage />} />
|
|
<Route path="/public/leaderboard" element={<PublicLeaderboardPage />} />
|
|
<Route
|
|
path="/roundtable-share/:shareCode"
|
|
element={<PublicRoundtableSharePage view="landing" />}
|
|
/>
|
|
<Route
|
|
path="/roundtable-share/:shareCode/report"
|
|
element={<PublicRoundtableSharePage view="report" />}
|
|
/>
|
|
<Route
|
|
path="/roundtable-share/:shareCode/dashboard"
|
|
element={<PublicRoundtableSharePage view="dashboard" />}
|
|
/>
|
|
<Route
|
|
path="/public/scheduled-tasks/:taskId"
|
|
element={<PublicScheduledTaskPage />}
|
|
/>
|
|
<Route
|
|
path="/public/scheduled-tasks/:taskId/runs/:runId/fullscreen"
|
|
element={<PublicScheduledTaskFullscreenPage />}
|
|
/>
|
|
<Route
|
|
path="/embed/chats/:thread_id"
|
|
element={
|
|
<ChatRuntime>
|
|
<EmbedChatPage />
|
|
</ChatRuntime>
|
|
}
|
|
/>
|
|
<Route path="/embed/roundtable" element={<EmbedRoundtablePage />} />
|
|
<Route
|
|
path="/roundtable-dashboard"
|
|
element={<DashboardStandalonePage />}
|
|
/>
|
|
<Route path="/page/*" element={<PageRoutes />} />
|
|
<Route path="*" element={<NotFoundPage />} />
|
|
</Routes>
|
|
</AppProviders>
|
|
</HashRouter>
|
|
);
|
|
}
|