import { useEffect, useState, type CSSProperties, type ReactNode } from "react";
import {
Navigate,
Route,
Routes,
useLocation,
useParams,
} from "react-router-dom";
import { getStoredAuth } from "@/core/auth";
import { getAPIClient } from "@/core/api";
import { isSentimentAgentVisible } from "@/core/sentiment-agent/config";
import {
resolveChatsIframeEntryRedirect,
resolveStandardChatFallback,
} from "@/core/page-layout/chats-iframe-route";
import { isEmbeddedHost } from "@/core/embed/frame-context";
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar";
import { PromptInputProvider } from "@/components/ai-elements/prompt-input";
import {
CompactShortcutButtons,
LayoutModeSwitcher,
ThemeSwitcher,
} from "@/components/workspace/appearance-controls";
import { WorkspaceSidebar } from "@/components/workspace/workspace-sidebar";
import { UserIdentityBadge } from "@/components/workspace/user-identity-badge";
import { CommandPalette } from "@/components/workspace/command-palette";
import { Toaster } from "sonner";
import { SubtasksProvider } from "@/core/tasks/context";
import { ArtifactsProvider } from "@/components/workspace/artifacts";
import { DocumentRewritePresentationProvider } from "@/core/document-rewrite/context";
import { useUploadPolicy } from "@/core/uploads";
import { RouteBaseProvider, useRouteBase } from "@/core/route-base";
import { agentRefOfThread } from "@/core/threads/utils";
import ChatsPage from "./ChatsPage";
import ChatPage from "./ChatPage";
import ArtifactLibraryPage from "./ArtifactLibraryPage";
import IframeChatPage from "./IframeChatPage";
import AgentsPage from "./AgentsPage";
import AgentsOrbitPage from "./AgentsOrbitPage";
import AgentsPlazaPage from "./AgentsPlazaPage";
import AgentChatPage from "./AgentChatPage";
import SentimentAgentChatPage from "./SentimentAgentChatPage";
import NewAgentPage from "./NewAgentPage";
import AdminAgentsPage from "./AdminAgentsPage";
import AdminScheduledTasksPage from "./AdminScheduledTasksPage";
import AdminSkillsPage from "./AdminSkillsPage";
import AdminUserLeaderboardPage from "./AdminUserLeaderboardPage";
import AdminUserLeaderboardSettingsPage from "./AdminUserLeaderboardSettingsPage";
import MenuManagementPage from "./MenuManagementPage";
import FixedQuestionsPage from "./FixedQuestionsPage";
import ScheduledTaskRunDetailPage from "./ScheduledTaskRunDetailPage";
import ScheduledTasksPage from "./ScheduledTasksPage";
import LlmWikiKnowledgePage from "./LlmWikiKnowledgePage";
import AssistantKnowledgePage from "./AssistantKnowledgePage";
import KnowledgeRetrievalDebugPage from "./KnowledgeRetrievalDebugPage";
import WeKnoraWikiManagementPage from "@/strategy-components/components/resource-management/llmwiki/WeKnoraWikiManagementPage";
import WeKnoraWikiPageView from "@/strategy-components/components/resource-management/llmwiki/WeKnoraWikiPageView";
import WeKnoraPackageTransfersPage from "@/strategy-components/components/resource-management/llmwiki/WeKnoraPackageTransfersPage";
import WeKnoraRetrievalDebugPage from "@/strategy-components/components/resource-management/llmwiki/WeKnoraRetrievalDebugPage";
import MarkdownDocxEditorPage from "./MarkdownDocxEditorPage";
import LlmMetricsPage from "./LlmMetricsPage";
import CheckpointMigrationPage from "./CheckpointMigrationPage";
import PromptPrefixSettingsPage from "./PromptPrefixSettingsPage";
import PrivateSquareSettingsPage from "./PrivateSquareSettingsPage";
import ModelConcurrencySettingsPage from "./ModelConcurrencySettingsPage";
import ModelManagementPage from "./ModelManagementPage";
import PublishSquaresSettingsPage from "./PublishSquaresSettingsPage";
import SkillCompressionSettingsPage from "./SkillCompressionSettingsPage";
import SkillEvolutionPage from "./SkillEvolutionPage";
import SkillsPage from "./SkillsPage";
import UsersPage from "./UsersPage";
import AdminUserActivityPage from "./AdminUserActivityPage";
import AdminMemoryPage from "./AdminMemoryPage";
import AdminUserHubPage from "./AdminUserHubPage";
import TagsPage from "./TagsPage";
import PositionsPage from "./PositionsPage";
import PositionRolesPage from "./PositionRolesPage";
import PluginManagementPage from "./PluginManagementPage";
import RecommendedQuestionsPage from "./RecommendedQuestionsPage";
import AIWritingPage from "@/open-canvas/pages/AIWritingPage";
import DeepResearchPage from "./DeepResearchPage";
import ReportStructureCreatePage from "./deep-research/ReportStructureCreatePage";
import EnterpriseResearchPage from "./EnterpriseResearchPage";
import StudioNotebooksPage from "./StudioNotebooksPage";
import StudioNotebookDetailPage from "./StudioNotebookDetailPage";
import RoundtablePlanningPage from "@/roundtable-planning/pages/RoundtablePlanningPage";
import PositionRoundtablePage from "@/position-roundtable/pages/PositionRoundtablePage";
import EightBfRoundtablePage from "@/eightbf-roundtable/pages/EightBfRoundtablePage";
import BusinessChainEditorPage from "@/roundtable-planning/pages/BusinessChainEditorPage";
import BusinessChainListPage from "@/roundtable-planning/pages/BusinessChainListPage";
import DispatchChainPreviewPage from "@/roundtable-planning/pages/DispatchChainPreviewPage";
import "@/roundtable-planning/styles/roundtable-planning.css";
import ReportCollaborationPage, {
ReportCollaborationSessionPage,
} from "@/report-collaboration/pages/ReportCollaborationPage";
import "@/report-collaboration/styles/report-collaboration.css";
import { cn } from "@/lib/utils";
function NotebookDetailPageWithKey() {
const { notebookId } = useParams<{ notebookId: string }>();
return ;
}
// 恢复某条 bootstrap 会话时按 thread_id 重挂,切换会话不串台。
function NewAgentPageWithKey() {
const { thread_id } = useParams<{ thread_id: string }>();
return ;
}
// 报告协作会话页:按 sessionId 重挂(旧 SSE/状态不串台)。
function ReportCollaborationSessionRoute({
layoutProps,
}: {
layoutProps: {
pageSidebarCollapsed: boolean;
pageSidebarHidden: boolean;
workspaceSidebarHidden: boolean;
headerHidden: boolean;
compactActionsHidden: boolean;
compactWorkspaceSidebar: boolean;
pageSidebarDark: boolean;
forceWorkspaceSidebarCollapsed: boolean;
};
}) {
const { sessionId } = useParams<{ sessionId: string }>();
return (
);
}
function shouldShowCompactTopActions(pathname: string): boolean {
return (
pathname === "/page/workspace/agents" ||
pathname === "/page/workspace/skills" ||
pathname === "/page/workspace/library" ||
pathname === "/page/workspace/knowledge" ||
pathname.startsWith("/page/workspace/knowledge/")
);
}
function CompactWorkspaceTopActions() {
return (
);
}
function CompactAppearanceActions() {
return (
<>
>
);
}
export function WorkspaceLayout({
children,
pageSidebarCollapsed,
pageSidebarHidden = false,
workspaceSidebarHidden = false,
headerHidden = false,
compactActionsHidden = false,
compactWorkspaceSidebar = false,
defaultHistorySidebarOpen,
wrapperOverflowHidden = false,
insetOverflowHidden = false,
pageSidebarDark = false,
forceWorkspaceSidebarCollapsed = false,
wxCommonAgents = false,
}: {
children: ReactNode;
pageSidebarCollapsed: boolean;
pageSidebarHidden?: boolean;
workspaceSidebarHidden?: boolean;
headerHidden?: boolean;
compactActionsHidden?: boolean;
compactWorkspaceSidebar?: boolean;
/** 全量模式下通用问答等页:聊天记录侧栏默认展开;未指定时紧凑模式仍默认收起。 */
defaultHistorySidebarOpen?: boolean;
wrapperOverflowHidden?: boolean;
insetOverflowHidden?: boolean;
pageSidebarDark?: boolean;
/** Deployment-level compact mode: keep only the icon menu rail. */
forceWorkspaceSidebarCollapsed?: boolean;
/** Enables wx's shared Agent Gallery category selection. */
wxCommonAgents?: boolean;
}) {
// 全量模式下通用问答(/page/workspace/chats*)的历史侧栏默认展开;其余紧凑页
// (如智能体对话,为聊天区更宽而默认收起)维持原默认。
const pathname = useLocation().pathname;
const isGeneralQa =
pathname.startsWith("/page/workspace/chats") ||
pathname.startsWith("/page/workspace/wx/");
const showCompactTopActions =
headerHidden &&
!compactActionsHidden &&
shouldShowCompactTopActions(pathname);
const pageSidebarWidth = pageSidebarHidden
? "0rem"
: pageSidebarDark
? pageSidebarCollapsed
? "0rem"
: "118px"
: pageSidebarCollapsed
? "4rem"
: "16rem";
return (
undefined : undefined
}
disableToggle={forceWorkspaceSidebarCollapsed}
>
{!workspaceSidebarHidden && (
)}
{showCompactTopActions ? (
<>
{children}
>
) : (
children
)}
);
}
export function ChatRuntime({ children }: { children: ReactNode }) {
const { data: uploadPolicy } = useUploadPolicy();
return (
{children}
);
}
/**
* 通用问答新对话内容区:默认渲染 ChatPage;当 URL 带 ``?agent=``(点击左栏
* 「常用智能体」时由侧边栏写入)时,**在右侧问答区原地嵌入**该智能体的对话页
* (AgentChatPage),路由仍停留在 /chats/new,不跳转出去、不更换左侧栏。
* key 绑定 location.key —— 每次点击(即便同一 agent)都重开一个干净的会话。
*/
function NewChatContent() {
const location = useLocation();
const agentId = new URLSearchParams(location.search).get("agent");
if (agentId) {
return (
);
}
return ;
}
function NewChatEntryRoute({
layoutProps,
}: {
layoutProps: {
pageSidebarCollapsed: boolean;
pageSidebarHidden: boolean;
workspaceSidebarHidden: boolean;
headerHidden: boolean;
compactWorkspaceSidebar: boolean;
compactActionsHidden: boolean;
pageSidebarDark: boolean;
forceWorkspaceSidebarCollapsed: boolean;
};
}) {
const location = useLocation();
const iframeEntryTarget = resolveChatsIframeEntryRedirect(
location.pathname,
location.search,
isEmbeddedHost(),
);
if (iframeEntryTarget) {
return ;
}
// A bare external iframe historically opens the dedicated AgentSelector
// page. `resolveChatsIframeEntryRedirect` records that inferred context as
// `from=iframe`; explicit full-chat/presentation parameters stay here.
return (
);
}
function ChatsIndexEntryRoute({
layoutProps,
compactChrome,
}: {
layoutProps: {
pageSidebarCollapsed: boolean;
pageSidebarHidden: boolean;
workspaceSidebarHidden: boolean;
headerHidden: boolean;
compactWorkspaceSidebar: boolean;
compactActionsHidden: boolean;
pageSidebarDark: boolean;
forceWorkspaceSidebarCollapsed: boolean;
};
compactChrome: boolean;
}) {
const location = useLocation();
const iframeEntryTarget = resolveChatsIframeEntryRedirect(
location.pathname,
location.search,
isEmbeddedHost(),
);
if (iframeEntryTarget) {
return ;
}
return (
);
}
function ChatThreadEntryRoute({
layoutProps,
}: {
layoutProps: {
pageSidebarCollapsed: boolean;
pageSidebarHidden: boolean;
workspaceSidebarHidden: boolean;
headerHidden: boolean;
compactWorkspaceSidebar: boolean;
compactActionsHidden: boolean;
pageSidebarDark: boolean;
forceWorkspaceSidebarCollapsed: boolean;
};
}) {
const location = useLocation();
const iframeEntryTarget = resolveChatsIframeEntryRedirect(
location.pathname,
location.search,
isEmbeddedHost(),
);
if (iframeEntryTarget) {
return ;
}
return (
);
}
/**
* Older bookmarks and a few historic list entries use the generic
* ``/chats/:thread_id`` path even for an agent-owned conversation. Recover the
* owning agent from the persisted thread record before rendering so those
* links keep the agent workspace (agent list and detail panel) instead of
* falling back to the general Q&A page. Task workspace threads intentionally
* remain on their explicit task routes because their surrounding layout is
* part of the task context.
*/
function AgentAwareChatThreadContent() {
const { thread_id: threadId } = useParams<{ thread_id: string }>();
const location = useLocation();
const routeBase = useRouteBase();
const [agentId, setAgentId] = useState(null);
const [resolved, setResolved] = useState(false);
useEffect(() => {
let cancelled = false;
setAgentId(null);
setResolved(false);
if (!threadId) {
setResolved(true);
return () => {
cancelled = true;
};
}
void getAPIClient()
.threads.get(threadId)
.then((thread) => {
if (cancelled) return;
const record = thread as {
context?: { agent_id?: string; agent_name?: string } | null;
metadata?: Record | null;
};
// Task-bound threads need their task host to preserve the purpose gate,
// action partitioning, and other task-specific controls.
const isTaskThread = typeof record.metadata?.taskId === "string";
setAgentId(isTaskThread ? null : (agentRefOfThread(record) ?? null));
})
.catch(() => {
if (!cancelled) setAgentId(null);
})
.finally(() => {
if (!cancelled) setResolved(true);
});
return () => {
cancelled = true;
};
}, [threadId]);
if (!resolved) {
return ;
}
if (threadId && agentId) {
return (
);
}
return ;
}
const WX_CHAT_ROUTE_BASE = "/page/workspace/wx";
type WorkspaceRouteLayoutProps = {
pageSidebarCollapsed: boolean;
pageSidebarHidden: boolean;
workspaceSidebarHidden: boolean;
headerHidden: boolean;
compactWorkspaceSidebar: boolean;
compactActionsHidden: boolean;
pageSidebarDark: boolean;
forceWorkspaceSidebarCollapsed: boolean;
};
/**
* Dedicated full-layout chat page for the wx workflow. It shares the normal
* chat composition but keeps its own route namespace and category-filtered
* common-agents sidebar.
*/
function WxChatLayout({
layoutProps,
children,
}: {
layoutProps: WorkspaceRouteLayoutProps;
children: ReactNode;
}) {
return (
{children}
);
}
function WxNewChatEntryRoute({
layoutProps,
}: {
layoutProps: WorkspaceRouteLayoutProps;
}) {
return (
);
}
function WxChatThreadEntryRoute({
layoutProps,
}: {
layoutProps: WorkspaceRouteLayoutProps;
}) {
return (
);
}
function WxAgentChatEntryRoute({
layoutProps,
}: {
layoutProps: WorkspaceRouteLayoutProps;
}) {
const { agent_id: agentId } = useParams<{ agent_id: string }>();
return (
);
}
function WxSentimentAgentChatEntryRoute({
layoutProps,
}: {
layoutProps: WorkspaceRouteLayoutProps;
}) {
return (
);
}
function WxChatsIndexEntryRoute({
layoutProps,
}: {
layoutProps: WorkspaceRouteLayoutProps;
}) {
return (
);
}
function WxAgentsEntryRoute({
layoutProps,
}: {
layoutProps: WorkspaceRouteLayoutProps;
}) {
return (
);
}
function WxSkillsEntryRoute({
layoutProps,
}: {
layoutProps: WorkspaceRouteLayoutProps;
}) {
return (
);
}
/**
* `chats_iframe` is reserved for the Brainy postMessage protocol. `from=iframe`
* and `chatMode=iframe` opt into this page; ordinary iframe/Wujie embedding
* remains on the normal full chat workspace.
*/
function IframeChatEntryRoute({
layoutProps,
hasThreadParam,
}: {
layoutProps: {
pageSidebarCollapsed: boolean;
pageSidebarHidden: boolean;
workspaceSidebarHidden: boolean;
headerHidden: boolean;
compactWorkspaceSidebar: boolean;
compactActionsHidden: boolean;
pageSidebarDark: boolean;
forceWorkspaceSidebarCollapsed: boolean;
};
hasThreadParam: boolean;
}) {
const location = useLocation();
const standardChatTarget = resolveStandardChatFallback(
location.pathname,
location.search,
);
if (standardChatTarget) {
return ;
}
return (
);
}
export default function WorkspaceRoutes({
pageSidebarCollapsed = false,
pageSidebarHidden = false,
workspaceSidebarHidden = false,
headerHidden = false,
compactActionsHidden = false,
compactWorkspaceSidebar = false,
pageSidebarDark = false,
forceWorkspaceSidebarCollapsed = false,
}: {
pageSidebarCollapsed?: boolean;
pageSidebarHidden?: boolean;
workspaceSidebarHidden?: boolean;
headerHidden?: boolean;
compactActionsHidden?: boolean;
compactWorkspaceSidebar?: boolean;
pageSidebarDark?: boolean;
forceWorkspaceSidebarCollapsed?: boolean;
}) {
const layoutProps = {
pageSidebarCollapsed,
pageSidebarHidden,
workspaceSidebarHidden,
headerHidden,
compactActionsHidden,
compactWorkspaceSidebar,
pageSidebarDark,
forceWorkspaceSidebarCollapsed,
};
return (
} />
} />
}
/>
}
/>
}
/>
}
/>
}
/>
) : (
)
}
/>
) : (
)
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
{/* 从「常用对话」点击智能体创建(bootstrap)会话回到创建页并恢复该会话。
key 绑定 thread_id —— 切换不同 bootstrap 会话时重挂一个干净的页面。 */}
}
/>
{/* 智能体星轨视图:/agents 的另一种展示形式(手写 CSS 圆环星轨布局)。
字面量路由,置于 agents/:agent_id/* 参数路由之前。 */}
}
/>
{/* 智能体广场视图:/agents 的环形展台布局(底部类型球 + 左右智能体)。 */}
}
/>
{/* 舆情分析虚拟智能体:静态段优先于 :agent_id 命中,走 Gateway 转发
外部 AG-UI 网关的专用对话页(不在后端 /api/agents 落库)。 */}
) : (
)
}
/>
) : (
)
}
/>
}
/>
) : undefined
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
{/* AgentScope 报告协作工作台:左对话(复用 MessageList)/右画布的独立新页面,
不与旧多智能体会商共享状态。key 绑定 sessionId——切换会话重挂干净的页面。 */}
}
/>
}
/>
{/* Phase 7 临时预览入口:派活链路流程图弹窗(假数据自测,接通后台后可删) */}
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
{/* Unified admin user hub */}
) : (
)
}
/>
{/* Legacy redirects */}
}
/>
}
/>
}
/>
) : (
)
}
/>
) : (
)
}
/>
) : (
)
}
/>
{/* 用户排行榜(管理员)工作区挂载:简洁模式下 /page/strategy/* 没有任何左侧
导航(无 PageSidebar),「设置和更多」改走这两个工作区地址即可带上
WorkspaceSidebar;/page/strategy/admin/user-leaderboard 旧地址保留给
全量模式侧边栏菜单(sidebar-menu.ts mgmt-user-leaderboard)。 */}
) : (
)
}
/>
) : (
)
}
/>
{/* 菜单管理工作区挂载:管理员维护默认菜单,普通用户维护个人菜单。 */}
}
/>
{/* 问题配置(管理员)工作区挂载:同上。 */}
) : (
)
}
/>
}
/>
) : (
)
}
/>
) : (
)
}
/>
) : (
)
}
/>
) : (
)
}
/>
) : (
)
}
/>
) : (
)
}
/>
) : (
)
}
/>
) : (
)
}
/>
) : (
)
}
/>
) : (
)
}
/>
) : (
)
}
/>
) : (
)
}
/>
);
}
// Suppress unused import warnings for pages referenced only in some branches
void UsersPage;
void AdminUserActivityPage;
void AdminMemoryPage;