feat(frontend): 上线报告协作与多轮 RAG 消息聚合体验
功能说明:\n- 新增报告协作页(Report Collaboration)核心状态层、消息适配与会话面板,支持按节点/阶段选择和协作上下文展示\n- 补齐 report-collaboration API 与类型定义,并接入页面路由/构建路径,形成可运行的协作链路\n- 重构多轮 RAG 与 write/artefact 消息分组逻辑,优化 AgentChat 与 DeepResearch 场景下的消息展示顺序与可读性\n- 新增/更新 DeepResearch 前端页面(Workbench、报告配置、沙箱联动)以承接报告生成与复用能力\n- 增加报表协作相关单测,覆盖事件归并、消息适配与关键 reducer 行为
This commit is contained in:
1 parent
e58da3fbdf
commit
438772f0b7
25 files changed
+1740
-399
No files matched your search
@@ -1,11 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
import type { Message } from "@langchain/langgraph-sdk";
|
||||
import { toast } from "sonner";
|
||||
import { FileText, Sparkles } from "lucide-react";
|
||||
|
||||
import { ArtifactsProvider } from "@/components/workspace/artifacts";
|
||||
import { ThreadContext } from "@/components/workspace/messages/context";
|
||||
import { SubtasksProvider } from "@/core/tasks/context";
|
||||
import { getReportCollaborationDriver } from "@/report-collaboration/api/driver";
|
||||
import { AgentStageSelector } from "@/report-collaboration/components/AgentStageSelector";
|
||||
import { ConnectionStatusBar } from "@/report-collaboration/components/ConnectionStatusBar";
|
||||
@@ -21,6 +24,7 @@ import {
|
||||
ReportAvailableCard,
|
||||
ReportPreviewDialog,
|
||||
} from "@/report-collaboration/components/ReportPreviewDialog";
|
||||
import { ReportSandboxOverlay } from "@/report-collaboration/components/ReportSandboxOverlay";
|
||||
import { SessionHistoryPanel } from "@/report-collaboration/components/SessionHistoryPanel";
|
||||
import { useReportPanelLayout } from "@/report-collaboration/hooks/useReportPanelLayout";
|
||||
import { useReportCollaborationMessages } from "@/report-collaboration/hooks/useReportCollaborationMessages";
|
||||
@@ -34,11 +38,11 @@ import {
|
||||
} from "@/report-collaboration/state/message-adapter";
|
||||
import {
|
||||
derivePagePhase,
|
||||
selectAgentRunForNode,
|
||||
selectAgentTabs,
|
||||
selectAwaitingInputNodes,
|
||||
selectHeadReportVersion,
|
||||
selectNodeStatusMap,
|
||||
selectParallelMembers,
|
||||
selectPendingConfirmationCommands,
|
||||
selectPlanForCanvas,
|
||||
selectPreferredParallelFocus,
|
||||
@@ -101,6 +105,7 @@ export default function ReportCollaborationPage() {
|
||||
);
|
||||
|
||||
return (
|
||||
<ArtifactsProvider>
|
||||
<ReportCollaborationLayout
|
||||
layout={layout}
|
||||
header={
|
||||
@@ -151,6 +156,7 @@ export default function ReportCollaborationPage() {
|
||||
canvas={<ReportFlowCanvas plan={null} nodeStates={{}} selectedNodeId={null} onSelectNode={() => undefined} />}
|
||||
statusBar={<ConnectionStatusBar status="idle" runId={null} lastSeq={0} />}
|
||||
/>
|
||||
</ArtifactsProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -167,13 +173,21 @@ export function ReportCollaborationSessionPage({ sessionId }: { sessionId: strin
|
||||
const [focusedAgentRunId, setFocusedAgentRunId] = useState<string | null>(null);
|
||||
const [focusPinned, setFocusPinned] = useState(false);
|
||||
const tabIds = useMemo(() => new Set(agentTabs.map((tab) => tab.agent_run_id)), [agentTabs]);
|
||||
const pinnedAgent =
|
||||
focusPinned && focusedAgentRunId && !tabIds.has(focusedAgentRunId)
|
||||
? (state.agentRuns[focusedAgentRunId] ?? null)
|
||||
: null;
|
||||
const effectiveFocus =
|
||||
agentTabs.length === 0
|
||||
? null
|
||||
: focusedAgentRunId && tabIds.has(focusedAgentRunId)
|
||||
? focusedAgentRunId
|
||||
: agentTabs[0].agent_run_id;
|
||||
const focusedTab = agentTabs.find((tab) => tab.agent_run_id === effectiveFocus) ?? null;
|
||||
focusPinned && focusedAgentRunId && state.agentRuns[focusedAgentRunId]
|
||||
? focusedAgentRunId
|
||||
: agentTabs.length === 0
|
||||
? null
|
||||
: focusedAgentRunId && tabIds.has(focusedAgentRunId)
|
||||
? focusedAgentRunId
|
||||
: agentTabs[0].agent_run_id;
|
||||
const focusedTab =
|
||||
agentTabs.find((tab) => tab.agent_run_id === effectiveFocus) ??
|
||||
(effectiveFocus ? state.agentRuns[effectiveFocus] ?? null : null);
|
||||
|
||||
const { previewPlanId, previewPlan, effectivePlanId } = useReportPlanSelection(
|
||||
state.plans,
|
||||
@@ -216,14 +230,17 @@ export function ReportCollaborationSessionPage({ sessionId }: { sessionId: strin
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [session.actionError]);
|
||||
|
||||
// 并行波次:默认落到正在执行的成员;点头像/画布后保持该成员,直到波次结束。
|
||||
// 执行波次:默认落到正在输出的成员;点头像/画布后保持该成员直到该波次结束。
|
||||
// 全部结束后若用户钉住某个节点,保留回看,不强制清回全量时间线。
|
||||
useEffect(() => {
|
||||
if (agentTabs.length === 0) {
|
||||
if (focusedAgentRunId) setFocusedAgentRunId(null);
|
||||
if (focusPinned) setFocusPinned(false);
|
||||
if (!focusPinned && focusedAgentRunId) setFocusedAgentRunId(null);
|
||||
return;
|
||||
}
|
||||
if (focusedAgentRunId && tabIds.has(focusedAgentRunId)) return;
|
||||
if (focusPinned && focusedAgentRunId && tabIds.has(focusedAgentRunId)) return;
|
||||
if (focusPinned && focusedAgentRunId && !tabIds.has(focusedAgentRunId)) {
|
||||
setFocusPinned(false);
|
||||
}
|
||||
const next = selectPreferredParallelFocus(agentTabs);
|
||||
if (next) setFocusedAgentRunId(next);
|
||||
}, [agentTabs, focusPinned, focusedAgentRunId, tabIds]);
|
||||
@@ -236,7 +253,7 @@ export function ReportCollaborationSessionPage({ sessionId }: { sessionId: strin
|
||||
if (
|
||||
state.plans.length > 0 &&
|
||||
!runStarted &&
|
||||
(phase === "proposal_ready" || phase === "planning")
|
||||
phase === "proposal_ready"
|
||||
) {
|
||||
cards.push(
|
||||
buildPlanGroupCard(state.plans, state.selectedPlanId, state.session?.requirement_revision ?? 1),
|
||||
@@ -273,17 +290,7 @@ export function ReportCollaborationSessionPage({ sessionId }: { sessionId: strin
|
||||
}, [state]);
|
||||
|
||||
const findMemberOfNode = useCallback(
|
||||
(nodeId: string) => {
|
||||
const members = selectParallelMembers(state);
|
||||
return (
|
||||
members.find((member) => member.node_run_id?.startsWith(`${nodeId}-`)) ??
|
||||
Object.values(state.agentRuns).find(
|
||||
(agentRun) =>
|
||||
agentRun.role !== "协调者" && agentRun.node_run_id?.startsWith(`${nodeId}-`),
|
||||
) ??
|
||||
null
|
||||
);
|
||||
},
|
||||
(nodeId: string) => selectAgentRunForNode(state, nodeId),
|
||||
[state],
|
||||
);
|
||||
|
||||
@@ -291,30 +298,29 @@ export function ReportCollaborationSessionPage({ sessionId }: { sessionId: strin
|
||||
(nodeId: string | null) => {
|
||||
setSelectedNodeId(nodeId);
|
||||
setDrawerOpen(Boolean(nodeId));
|
||||
// 点并行智能体节点时,消息列表切到该成员的执行过程(与头像条同一套聚焦)。
|
||||
if (nodeId) {
|
||||
const member = findMemberOfNode(nodeId);
|
||||
if (member && tabIds.has(member.agent_run_id)) {
|
||||
if (member) {
|
||||
setFocusedAgentRunId(member.agent_run_id);
|
||||
setFocusPinned(true);
|
||||
}
|
||||
}
|
||||
},
|
||||
[findMemberOfNode, tabIds],
|
||||
[findMemberOfNode],
|
||||
);
|
||||
|
||||
const handleNodeComment = useCallback(
|
||||
(nodeId: string, nodeName: string) => {
|
||||
const member = findMemberOfNode(nodeId);
|
||||
setComposerTarget({ nodeId, nodeName, agentRunId: member?.agent_run_id ?? null });
|
||||
if (member && tabIds.has(member.agent_run_id)) {
|
||||
if (member) {
|
||||
setFocusedAgentRunId(member.agent_run_id);
|
||||
setFocusPinned(true);
|
||||
}
|
||||
setDrawerOpen(false);
|
||||
setFocusSignal((signal) => signal + 1);
|
||||
},
|
||||
[findMemberOfNode, tabIds],
|
||||
[findMemberOfNode],
|
||||
);
|
||||
|
||||
const handleRestore = useCallback(
|
||||
@@ -395,7 +401,7 @@ export function ReportCollaborationSessionPage({ sessionId }: { sessionId: strin
|
||||
? "start"
|
||||
: outgoingIds.size > 0
|
||||
? "agent"
|
||||
: "end") as const,
|
||||
: "end") as "start" | "agent" | "end",
|
||||
mission: selectedPlanNode?.mission ?? null,
|
||||
input_artifact_types: selectedPlanNode?.input_artifact_types ?? [],
|
||||
output_artifact_type: selectedPlanNode?.output_artifact_type ?? null,
|
||||
@@ -438,114 +444,128 @@ export function ReportCollaborationSessionPage({ sessionId }: { sessionId: strin
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<ReportCollaborationLayout
|
||||
layout={layout}
|
||||
header={
|
||||
<ReportCollaborationHeader
|
||||
title={state.session?.title ?? "报告协作"}
|
||||
phase={phase}
|
||||
onBack={() => navigate("/page/workspace/chats/new")}
|
||||
onNewSession={() => navigate("/page/workspace/report-collaboration")}
|
||||
onOpenReport={() => {
|
||||
if (headVersion) {
|
||||
setPreviewVersionId(headVersion.id);
|
||||
setPreviewOpen(true);
|
||||
}
|
||||
}}
|
||||
hasReport={Boolean(headVersion)}
|
||||
running={runActive}
|
||||
onCancelRun={() => void session.cancelRun()}
|
||||
extra={
|
||||
layout.isNarrow ? (
|
||||
<NarrowSwitch narrowView={layout.narrowView} setNarrowView={layout.setNarrowView} />
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
}
|
||||
conversation={
|
||||
<ConversationSidebarTabs
|
||||
conversation={
|
||||
<ReportConversationPanel
|
||||
sessionId={sessionId}
|
||||
thread={displayThread}
|
||||
businessCardSlot={businessCardSlot}
|
||||
listKey={effectiveFocus ?? "timeline"}
|
||||
loading={session.snapshotLoading}
|
||||
stageSelector={
|
||||
<AgentStageSelector
|
||||
tabs={agentTabs}
|
||||
phaseLabel={`并行 ${agentTabs.length} 席`}
|
||||
focusedAgentRunId={effectiveFocus}
|
||||
onFocus={(agentRunId) => {
|
||||
setFocusedAgentRunId(agentRunId);
|
||||
setFocusPinned(true);
|
||||
}}
|
||||
streamingAgentRunIds={streamingIds}
|
||||
awaitingAgentRunIds={awaitingIds}
|
||||
/>
|
||||
}
|
||||
emptyHint={
|
||||
effectiveFocus
|
||||
? `${focusedTab?.display_name ?? "智能体"}正在执行,输出会出现在这里`
|
||||
: undefined
|
||||
}
|
||||
composer={
|
||||
<ReportComposer
|
||||
phase={phase}
|
||||
busy={session.sendBusy}
|
||||
target={composerTarget}
|
||||
onClearTarget={() => setComposerTarget(null)}
|
||||
onSend={(text) =>
|
||||
void session.send(text, {
|
||||
nodeId: composerTarget?.nodeId ?? null,
|
||||
agentRunId: composerTarget?.agentRunId ?? null,
|
||||
})
|
||||
}
|
||||
focusSignal={focusSignal}
|
||||
/>
|
||||
<SubtasksProvider>
|
||||
<ArtifactsProvider>
|
||||
<ThreadContext.Provider value={{ thread: displayThread, isMock: true }}>
|
||||
<ReportCollaborationLayout
|
||||
layout={layout}
|
||||
header={
|
||||
<ReportCollaborationHeader
|
||||
title={state.session?.title ?? "报告协作"}
|
||||
phase={phase}
|
||||
onBack={() => navigate("/page/workspace/chats/new")}
|
||||
onNewSession={() => navigate("/page/workspace/report-collaboration")}
|
||||
onOpenReport={() => {
|
||||
if (headVersion) {
|
||||
setPreviewVersionId(headVersion.id);
|
||||
setPreviewOpen(true);
|
||||
}
|
||||
}}
|
||||
hasReport={Boolean(headVersion)}
|
||||
running={runActive}
|
||||
onCancelRun={() => void session.cancelRun()}
|
||||
extra={
|
||||
layout.isNarrow ? (
|
||||
<NarrowSwitch narrowView={layout.narrowView} setNarrowView={layout.setNarrowView} />
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
}
|
||||
history={<SessionHistoryPanel activeSessionId={sessionId} />}
|
||||
conversation={
|
||||
<ConversationSidebarTabs
|
||||
conversation={
|
||||
<ReportConversationPanel
|
||||
sessionId={sessionId}
|
||||
thread={displayThread}
|
||||
businessCardSlot={businessCardSlot}
|
||||
listKey={effectiveFocus ?? "timeline"}
|
||||
loading={session.snapshotLoading}
|
||||
stageSelector={
|
||||
<AgentStageSelector
|
||||
tabs={agentTabs}
|
||||
pinnedAgent={pinnedAgent}
|
||||
phaseLabel={
|
||||
agentTabs.length > 1
|
||||
? `并行 ${agentTabs.length} 席`
|
||||
: focusedTab?.display_name ?? (agentTabs[0]?.display_name ?? null)
|
||||
}
|
||||
focusedAgentRunId={effectiveFocus}
|
||||
onFocus={(agentRunId) => {
|
||||
setFocusedAgentRunId(agentRunId);
|
||||
setFocusPinned(true);
|
||||
}}
|
||||
onShowAll={() => {
|
||||
setFocusedAgentRunId(null);
|
||||
setFocusPinned(false);
|
||||
}}
|
||||
streamingAgentRunIds={streamingIds}
|
||||
awaitingAgentRunIds={awaitingIds}
|
||||
/>
|
||||
}
|
||||
emptyHint={
|
||||
effectiveFocus
|
||||
? `${focusedTab?.display_name ?? "智能体"}正在执行,输出会出现在这里`
|
||||
: undefined
|
||||
}
|
||||
composer={
|
||||
<ReportComposer
|
||||
phase={phase}
|
||||
busy={session.sendBusy}
|
||||
target={composerTarget}
|
||||
onClearTarget={() => setComposerTarget(null)}
|
||||
onSend={(text) =>
|
||||
void session.send(text, {
|
||||
nodeId: composerTarget?.nodeId ?? null,
|
||||
agentRunId: composerTarget?.agentRunId ?? null,
|
||||
})
|
||||
}
|
||||
focusSignal={focusSignal}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
}
|
||||
history={<SessionHistoryPanel activeSessionId={sessionId} />}
|
||||
/>
|
||||
}
|
||||
canvas={
|
||||
<>
|
||||
<ReportFlowCanvas
|
||||
plan={canvasPlan}
|
||||
nodeStates={nodeStates}
|
||||
selectedNodeId={selectedNodeId}
|
||||
onSelectNode={handleSelectNode}
|
||||
/>
|
||||
<NodeInspectorDrawer
|
||||
open={drawerOpen}
|
||||
nodeId={selectedNodeId}
|
||||
runId={state.run?.id ?? state.session?.active_run_id ?? null}
|
||||
fallback={drawerFallback}
|
||||
onClose={() => setDrawerOpen(false)}
|
||||
onComment={handleNodeComment}
|
||||
/>
|
||||
<ReportSandboxOverlay threadId={sessionId} />
|
||||
</>
|
||||
}
|
||||
statusBar={
|
||||
<ConnectionStatusBar
|
||||
status={session.streamStatus.status}
|
||||
runId={state.run?.id ?? null}
|
||||
lastSeq={state.lastSeq}
|
||||
message={session.streamStatus.message}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
}
|
||||
canvas={
|
||||
<>
|
||||
<ReportFlowCanvas
|
||||
plan={canvasPlan}
|
||||
nodeStates={nodeStates}
|
||||
selectedNodeId={selectedNodeId}
|
||||
onSelectNode={handleSelectNode}
|
||||
/>
|
||||
<NodeInspectorDrawer
|
||||
open={drawerOpen}
|
||||
nodeId={selectedNodeId}
|
||||
runId={state.run?.id ?? state.session?.active_run_id ?? null}
|
||||
fallback={drawerFallback}
|
||||
onClose={() => setDrawerOpen(false)}
|
||||
onComment={handleNodeComment}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
statusBar={
|
||||
<ConnectionStatusBar
|
||||
status={session.streamStatus.status}
|
||||
runId={state.run?.id ?? null}
|
||||
lastSeq={state.lastSeq}
|
||||
message={session.streamStatus.message}
|
||||
<ReportPreviewDialog
|
||||
open={previewOpen}
|
||||
onClose={() => setPreviewOpen(false)}
|
||||
versions={state.reportVersions}
|
||||
activeVersionId={previewVersionId}
|
||||
onSelectVersion={setPreviewVersionId}
|
||||
onRestore={(versionId) => void handleRestore(versionId)}
|
||||
restoreBusy={restoreBusy}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<ReportPreviewDialog
|
||||
open={previewOpen}
|
||||
onClose={() => setPreviewOpen(false)}
|
||||
versions={state.reportVersions}
|
||||
activeVersionId={previewVersionId}
|
||||
onSelectVersion={setPreviewVersionId}
|
||||
onRestore={(versionId) => void handleRestore(versionId)}
|
||||
restoreBusy={restoreBusy}
|
||||
/>
|
||||
</>
|
||||
</ThreadContext.Provider>
|
||||
</ArtifactsProvider>
|
||||
</SubtasksProvider>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user