sync: 鍚屾灞€鍩熺綉鏈€鏂颁唬鐮?(source master @ b69568e4)

This commit is contained in:
gozeros committed 2026-10-21 14:51:31 +08:00
1 parent 4f7f07504a
commit 8bc8b0e082
1651 files changed
+278599 -11416

No files matched your search

+261 -31
View File
@@ -5,8 +5,13 @@ import {
ChevronDown,
CircleHelp,
Clock3,
FolderKanban,
GitBranch,
Globe,
Landmark,
LoaderCircle,
MessageSquareText,
Network,
PanelLeftClose,
Pause,
Play,
@@ -19,8 +24,15 @@ import {
X,
} from "lucide-react";
import { type FormEvent, useCallback, useMemo, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import { Route, Routes, useLocation, useNavigate } from "react-router-dom";
import AnalysisProjectsPage from "./AnalysisProjectsPage";
import { SidebarProvider } from "@/components/ui/sidebar";
import { Toaster } from "sonner";
import {
MyProjectThreadBadge,
MyProjectThreadIcon,
} from "@/components/workspace/my-project-thread-indicator";
import { useAgent, useAgents } from "@/core/agents";
import { getAccountDisplayName } from "@/core/auth";
import {
@@ -29,30 +41,72 @@ import {
useScheduledTaskRuns,
useScheduledTasks,
} from "@/core/scheduled-tasks";
import { useLocalSettings } from "@/core/settings";
import {
useAppearanceSettings,
useCitationDisplaySettings,
} from "@/core/system-settings/hooks";
import { useThreadStream, useThreads } from "@/core/threads/hooks";
import {
myProjectConversationInfoOfThread,
myProjectConversationTypeFromSearchParams,
myProjectThreadMetadata,
} from "@/core/threads/project-metadata";
import { useProjectThreadNames } from "@/core/threads/use-project-thread-names";
import { textOfMessage, titleOfThread } from "@/core/threads/utils";
import { uuid } from "@/core/utils/uuid";
import {
OFFICIAL_DEERFLOW_HOME_ROUTE,
OFFICIAL_DEERFLOW_ROUTE_PREFIX,
} from "@/core/official-deerflow/routes";
import StrategyProjectsPage from "@/strategy-selection/StrategyProjectsPage";
import StrategySelectionPage from "@/strategy-selection/StrategySelectionPage";
import { strategyProjectWorkbenchPath } from "@/strategy-selection/project-routes";
import {
mergeRecentWorkspaceItems,
useRecentStrategyProjects,
} from "@/strategy-selection/recent-projects";
import OfficialWebAppsPage from "@/pages/OfficialWebAppsPage";
import GongwenWorkbench from "@/pages/deep-research/GongwenWorkbench";
import { ChatRuntime } from "@/components/workspace/chat-runtime";
import MultiAgentTasksPage from "./official-multi-agent-tasks/MultiAgentTasksPage";
import TaskEditPage from "./official-multi-agent-tasks/TaskEditPage";
import TaskAnalysisPage from "./official-task-analysis/TaskAnalysisPage";
import TaskAnalysisDetailPage from "./official-task-analysis/TaskAnalysisDetailPage";
import "./official-deerflow-entry.css";
type OfficialPage = "chat" | "agents" | "agent-chat" | "scheduled" | "settings";
type OfficialPage =
| "chat"
| "projects"
| "web-apps"
| "gongwen"
| "agents"
| "agent-chat"
| "scheduled"
| "multi-agent-tasks"
| "multi-agent-edit"
| "task-analysis"
| "task-analysis-detail"
| "settings";
function pageFromPath(pathname: string): OfficialPage {
const path = pathname.slice(OFFICIAL_DEERFLOW_ROUTE_PREFIX.length);
if (path.startsWith("/workspace/agents/") && path.includes("/chats")) {
return "agent-chat";
}
if (path.startsWith("/workspace/projects")) return "projects";
if (path.startsWith("/workspace/web-app")) return "web-apps";
if (path.startsWith("/workspace/gongwen")) return "gongwen";
if (path.startsWith("/workspace/agents")) return "agents";
if (path.startsWith("/workspace/scheduled-tasks")) return "scheduled";
if (path.startsWith("/workspace/multi-agent-tasks/new")) return "multi-agent-edit";
if (/^\/workspace\/multi-agent-tasks\/[^/]+\/edit$/.test(path)) {
return "multi-agent-edit";
}
if (path.startsWith("/workspace/multi-agent-tasks")) return "multi-agent-tasks";
if (/^\/workspace\/task-analysis\/[^/]+/.test(path)) return "task-analysis-detail";
if (path.startsWith("/workspace/task-analysis")) return "task-analysis";
if (path.startsWith("/workspace/settings")) return "settings";
return "chat";
}
@@ -78,6 +132,38 @@ function parseScheduledTaskId(pathname: string) {
return match ? decodeURIComponent(match[1]!) : null;
}
function parseProjectId(pathname: string) {
const match = pathname.match(/\/workspace\/projects\/([^/]+)/);
return match ? decodeURIComponent(match[1]!) : null;
}
function parseMultiAgentTaskId(pathname: string) {
const match = pathname.match(/\/workspace\/multi-agent-tasks\/([^/]+)/);
const raw = match ? decodeURIComponent(match[1]!) : null;
// 编辑页路由(new / :id/edit)不是任务详情,不驱动列表页的抽屉。
if (!raw || raw === "new") return null;
return raw;
}
function parseTaskAnalysisId(pathname: string) {
const match = pathname.match(/\/workspace\/task-analysis\/([^/]+)/);
return match ? decodeURIComponent(match[1]!) : null;
}
function parseMultiAgentEditTarget(pathname: string): {
mode: "create" | "edit";
taskId: string | null;
} {
const path = pathname.slice(OFFICIAL_DEERFLOW_ROUTE_PREFIX.length);
if (path.startsWith("/workspace/multi-agent-tasks/new")) {
return { mode: "create", taskId: null };
}
const match = path.match(/^\/workspace\/multi-agent-tasks\/([^/]+)\/edit$/);
return match
? { mode: "edit", taskId: decodeURIComponent(match[1]!) }
: { mode: "create", taskId: null };
}
function readableError(error: unknown, fallback: string) {
return error instanceof Error && error.message ? error.message : fallback;
}
@@ -159,20 +245,36 @@ function ChatWorkspace({
routeThreadId: string;
}) {
const navigate = useNavigate();
const location = useLocation();
const [prompt, setPrompt] = useState("");
const [sendError, setSendError] = useState<string | null>(null);
const isNewThread = routeThreadId === "new";
const projectConversationType = isNewThread
? myProjectConversationTypeFromSearchParams(
new URLSearchParams(location.search),
)
: null;
// A new conversation uses the same client-generated id approach as the
// existing ChatPage. The backend owns the persisted id once streaming starts.
const [draftThreadId] = useState<string>(() => uuid() as string);
const activeThreadId = isNewThread ? draftThreadId : routeThreadId;
const { agent } = useAgent(agentId, { enabled: !!agentId });
const [localSettings] = useLocalSettings();
const [thread, sendMessage, isUploading] = useThreadStream({
threadId: isNewThread ? undefined : routeThreadId,
assistantId: agentId ?? undefined,
threadMetadata: projectConversationType
? myProjectThreadMetadata(projectConversationType)
: undefined,
context: {
...localSettings.context,
// This compact official shell has no model/mode controls of its own.
// Do not inherit a hidden selection saved by the customized workspace
// (for example an obsolete or quota-exhausted model); an omitted model
// lets the backend resolve the current system default or the agent's
// globally configured model.
model_name: undefined,
mode: undefined,
reasoning_effort: undefined,
writing_mode: false,
...(agentId ? { agent_id: agentId } : {}),
},
onStart: (createdThreadId) => {
@@ -658,6 +760,22 @@ export default function OfficialDeerFlowEntry() {
() => parseScheduledTaskId(location.pathname),
[location.pathname],
);
const projectId = useMemo(
() => parseProjectId(location.pathname),
[location.pathname],
);
const multiAgentTaskId = useMemo(
() => parseMultiAgentTaskId(location.pathname),
[location.pathname],
);
const multiAgentEditTarget = useMemo(
() => parseMultiAgentEditTarget(location.pathname),
[location.pathname],
);
const taskAnalysisId = useMemo(
() => parseTaskAnalysisId(location.pathname),
[location.pathname],
);
const { data: threads = [], isLoading: threadsLoading, error: threadsError } =
useThreads({
limit: 20,
@@ -665,13 +783,30 @@ export default function OfficialDeerFlowEntry() {
sortOrder: "desc",
select: ["thread_id", "updated_at", "values", "metadata"],
});
const {
data: recentStrategyProjects = [],
isLoading: strategyProjectsLoading,
error: strategyProjectsError,
} = useRecentStrategyProjects();
const projectThreadNames = useProjectThreadNames(threads);
const recentItems = useMemo(
() =>
mergeRecentWorkspaceItems(threads, recentStrategyProjects).slice(0, 20),
[recentStrategyProjects, threads],
);
const go = (path: string) => navigate(path);
const projectBasePath = `${OFFICIAL_DEERFLOW_ROUTE_PREFIX}/workspace/projects`;
const nav = [
{ icon: PlusSquare, label: "新对话", path: OFFICIAL_DEERFLOW_HOME_ROUTE, pages: ["chat"] },
{ icon: MessageSquareText, label: "对话", path: `${OFFICIAL_DEERFLOW_ROUTE_PREFIX}/workspace/chats/new`, pages: ["chat"] },
{ icon: FolderKanban, label: "我的项目", path: projectBasePath, pages: ["projects"] },
{ icon: Globe, label: "Web 应用", path: `${OFFICIAL_DEERFLOW_ROUTE_PREFIX}/workspace/web-app`, pages: ["web-apps"] },
{ icon: Landmark, label: "公文模式", path: `${OFFICIAL_DEERFLOW_ROUTE_PREFIX}/workspace/gongwen`, pages: ["gongwen"] },
{ icon: Bot, label: "智能体", path: `${OFFICIAL_DEERFLOW_ROUTE_PREFIX}/workspace/agents`, pages: ["agents", "agent-chat"] },
{ icon: CalendarClock, label: "定时任务", path: `${OFFICIAL_DEERFLOW_ROUTE_PREFIX}/workspace/scheduled-tasks`, pages: ["scheduled"] },
{ icon: Network, label: "多智能体定时任务", path: `${OFFICIAL_DEERFLOW_ROUTE_PREFIX}/workspace/multi-agent-tasks`, pages: ["multi-agent-tasks", "multi-agent-edit"] },
{ icon: GitBranch, label: "任务分析定时", path: `${OFFICIAL_DEERFLOW_ROUTE_PREFIX}/workspace/task-analysis`, pages: ["task-analysis", "task-analysis-detail"] },
] as const;
return (
@@ -701,34 +836,90 @@ export default function OfficialDeerFlowEntry() {
</nav>
<div className="official-recent-section">
<p>最近对话</p>
{threadsLoading ? (
{recentItems.length ? (
recentItems.map((item) => {
if (item.kind === "strategy-project") {
const { project } = item;
return (
<button
className={`official-recent-chat is-project${projectId === project.id ? " is-active" : ""}`}
key={`strategy-project:${project.id}`}
onClick={() =>
go(strategyProjectWorkbenchPath(projectBasePath, project.id))
}
type="button"
>
<MyProjectThreadIcon type="strategy" />
<span className="official-recent-chat-copy">
<span className="official-recent-chat-title">
{project.title}
</span>
<MyProjectThreadBadge
projectName={project.title}
type="strategy"
/>
</span>
<small>{formatTimestamp(project.updatedAt)}</small>
</button>
);
}
const { thread: chat } = item;
const projectInfo = myProjectConversationInfoOfThread(
chat,
projectThreadNames,
);
return (
<button
className={`official-recent-chat${projectInfo ? " is-project" : ""}${chatRoute.threadId === chat.thread_id ? " is-active" : ""}`}
key={`thread:${chat.thread_id}`}
onClick={() => {
const projectId = chat.metadata?.analysis_project_id;
if (typeof projectId === "string" && projectId) {
const collection =
projectInfo?.type === "solution"
? "solutions"
: "groups";
go(`${projectBasePath}/${collection}/${encodeURIComponent(projectId)}/chats/${encodeURIComponent(chat.thread_id)}`);
return;
}
const agentId = typeof chat.context?.agent_id === "string"
? chat.context.agent_id
: typeof chat.metadata?.agent_id === "string"
? chat.metadata.agent_id
: null;
go(
agentId
? `${OFFICIAL_DEERFLOW_ROUTE_PREFIX}/workspace/agents/${encodeURIComponent(agentId)}/chats/${encodeURIComponent(chat.thread_id)}`
: `${OFFICIAL_DEERFLOW_ROUTE_PREFIX}/workspace/chats/${encodeURIComponent(chat.thread_id)}`,
);
}}
type="button"
>
{projectInfo ? (
<MyProjectThreadIcon type={projectInfo.type} />
) : (
<MessageSquareText aria-hidden="true" size={15} />
)}
<span className="official-recent-chat-copy">
<span className="official-recent-chat-title">
{titleOfThread(chat, "未命名对话")}
</span>
{projectInfo && (
<MyProjectThreadBadge
projectName={projectInfo.projectName}
type={projectInfo.type}
/>
)}
</span>
<small>{formatTimestamp(chat.updated_at)}</small>
</button>
);
})
) : threadsLoading || strategyProjectsLoading ? (
<div className="official-sidebar-loading"><LoaderCircle aria-hidden="true" size={14} /> 加载中…</div>
) : threadsError ? (
) : threadsError || strategyProjectsError ? (
<p className="official-sidebar-error">对话列表加载失败</p>
) : threads.length ? (
threads.map((chat) => (
<button
className={`official-recent-chat${chatRoute.threadId === chat.thread_id ? " is-active" : ""}`}
key={chat.thread_id}
onClick={() => {
const agentId = typeof chat.context?.agent_id === "string"
? chat.context.agent_id
: typeof chat.metadata?.agent_id === "string"
? chat.metadata.agent_id
: null;
go(
agentId
? `${OFFICIAL_DEERFLOW_ROUTE_PREFIX}/workspace/agents/${encodeURIComponent(agentId)}/chats/${encodeURIComponent(chat.thread_id)}`
: `${OFFICIAL_DEERFLOW_ROUTE_PREFIX}/workspace/chats/${encodeURIComponent(chat.thread_id)}`,
);
}}
type="button"
>
<MessageSquareText aria-hidden="true" size={15} />
<span>{titleOfThread(chat, "未命名对话")}</span>
<small>{formatTimestamp(chat.updated_at)}</small>
</button>
))
) : (
<p className="official-sidebar-empty">暂无历史对话</p>
)}
@@ -754,6 +945,30 @@ export default function OfficialDeerFlowEntry() {
routeThreadId={chatRoute.threadId}
/>
)}
{page === "projects" && (
(["groups", "solutions"].some((part) => location.pathname === `${projectBasePath}/${part}` || location.pathname.startsWith(`${projectBasePath}/${part}/`))) ? (
<SidebarProvider className="h-full min-h-0">
<Routes>
<Route path="workspace/projects/solutions/*" element={<AnalysisProjectsPage basePath={`${projectBasePath}/solutions`} listPath={`${projectBasePath}?type=solution`} mode="solution" showSidebarTrigger={false} />} />
<Route path="workspace/projects/groups/*" element={<AnalysisProjectsPage basePath={`${projectBasePath}/groups`} listPath={`${projectBasePath}?type=qa`} mode="qa" showSidebarTrigger={false} />} />
</Routes>
</SidebarProvider>
) : projectId ? (
<StrategySelectionPage
key={projectId}
projectBasePath={projectBasePath}
projectId={projectId}
/>
) : (
<StrategyProjectsPage basePath={projectBasePath} />
)
)}
{page === "web-apps" && <OfficialWebAppsPage />}
{page === "gongwen" && (
<ChatRuntime>
<GongwenWorkbench />
</ChatRuntime>
)}
{page === "agents" && (
<AgentsPage
openAgent={(agentId) =>
@@ -769,8 +984,23 @@ export default function OfficialDeerFlowEntry() {
/>
)}
{page === "scheduled" && <ScheduledTasksPage selectedTaskId={scheduledTaskId} />}
{page === "multi-agent-tasks" && (
<MultiAgentTasksPage routeTaskId={multiAgentTaskId} />
)}
{page === "multi-agent-edit" && (
<TaskEditPage
key={multiAgentEditTarget.taskId ?? "create"}
mode={multiAgentEditTarget.mode}
taskId={multiAgentEditTarget.taskId}
/>
)}
{page === "task-analysis" && <TaskAnalysisPage />}
{page === "task-analysis-detail" && (
<TaskAnalysisDetailPage routeTaskId={taskAnalysisId} />
)}
{page === "settings" && <SettingsPage />}
</div>
<Toaster position="top-center" />
</main>
);
}