Merge branch 'dhk-1' of http://192.168.0.200/knowledge-base-bj/deerflow-server into dhk-1
# Conflicts: # frontend-web/src/roundtable-planning/hooks/useStep3Dashboard.ts
This commit is contained in:
commit
b04b830039
20 files changed
+1396
-271
No files matched your search
@@ -0,0 +1,377 @@
|
||||
/**
|
||||
* 「大屏绘制智能体」独立页面(带导航 + 侧边栏,挂在 StrategyRoutes 下)。
|
||||
*
|
||||
* 按外部 `taskId`(URL `?taskId=` / 路由 state / 登录暂存的任务详情 id)存取:
|
||||
* - 进入时按 taskId 拉取已存会话(`/api/dashboard-sessions/by-task`,**不按 user 分权**)。
|
||||
* - **已有有效结果(可解析的 report-json)** → 直接展示大屏页面(应用内 `DashboardApp`)。
|
||||
* - **没有有效结果** → 进入「生成过程」视图:自动让智能体分析登录拉取的业务 JSON
|
||||
* (现为占位适配,接口就绪后改后台转换 + 智能体校验)→ 边抽边在右侧沙箱显示,
|
||||
* **完成不自动跳**;底部输入框可随时改。
|
||||
* - 聊天记录 + 最新 report-json 防抖回存(按 taskId 共享,跨用户可见)。
|
||||
*
|
||||
* 数据抽取/聊天/沙箱/渲染全部复用 `useStep3Dashboard` + `DashboardChatPanel` +
|
||||
* `DashboardApp`,仅把输入从「圆桌研讨成果」换成「任务原始 JSON」。
|
||||
*/
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useLocation, useSearchParams } from "react-router-dom";
|
||||
import {
|
||||
ArrowLeft,
|
||||
Boxes,
|
||||
Code2,
|
||||
ExternalLink,
|
||||
LayoutPanelTop,
|
||||
Loader2,
|
||||
Pencil,
|
||||
Sparkles,
|
||||
} from "lucide-react";
|
||||
|
||||
import { fetchDashboardInputJson } from "@/core/auth/dashboard-input";
|
||||
import { readCopTaskDetail } from "@/core/auth/task-deeplink";
|
||||
import { desensitizeDeep } from "@/lib/desensitize";
|
||||
import { useModels } from "@/core/models/hooks";
|
||||
import { useTheme } from "@/contexts/ThemeContext";
|
||||
import { DashboardApp } from "@/roundtable-planning/dashboard/DashboardApp";
|
||||
import { adaptReportData } from "@/roundtable-planning/dashboard/data-context";
|
||||
import { DashboardChatPanel } from "@/roundtable-planning/components/DashboardChatPanel";
|
||||
import { Step2SandboxLayout } from "@/roundtable-planning/components/Step2SandboxLayout";
|
||||
import { DASHBOARD_VIEW_STORAGE_PREFIX } from "@/roundtable-planning/pages/DashboardStandalonePage";
|
||||
import { useStep3Dashboard } from "@/roundtable-planning/hooks/useStep3Dashboard";
|
||||
import type { Step2Dialogue } from "@/roundtable-planning/hooks/useStep2Orchestration";
|
||||
import {
|
||||
buildDashboardPromptFromJson,
|
||||
parseReportJson,
|
||||
renderDashboardHtml,
|
||||
type DashboardTheme,
|
||||
} from "@/roundtable-planning/lib/report-template";
|
||||
import {
|
||||
getDashboardSessionByTask,
|
||||
putDashboardSessionByTask,
|
||||
} from "@/roundtable-planning/api/dashboard-sessions";
|
||||
|
||||
function formatNow(): string {
|
||||
const d = new Date();
|
||||
const pad = (n: number) => n.toString().padStart(2, "0");
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
}
|
||||
|
||||
type DashView = "chat" | "page";
|
||||
type RenderMode = "app" | "html";
|
||||
|
||||
/** 从 URL / 路由 state / 登录暂存任务详情解析 taskId。 */
|
||||
function useTaskId(): string {
|
||||
const [searchParams] = useSearchParams();
|
||||
const location = useLocation();
|
||||
return useMemo(() => {
|
||||
const fromQuery = searchParams.get("taskId")?.trim();
|
||||
if (fromQuery) return fromQuery;
|
||||
const fromState = (location.state as { taskId?: string } | null)?.taskId;
|
||||
if (fromState && String(fromState).trim()) return String(fromState).trim();
|
||||
const detail = readCopTaskDetail();
|
||||
if (detail?.id != null && String(detail.id).trim()) return String(detail.id).trim();
|
||||
return "";
|
||||
}, [searchParams, location.state]);
|
||||
}
|
||||
|
||||
export default function DashboardAgentPage() {
|
||||
const taskId = useTaskId();
|
||||
const { models: availableModels, isLoading: modelsLoading } = useModels();
|
||||
const [selectedModel, setSelectedModel] = useState("");
|
||||
const { theme } = useTheme();
|
||||
const themeMode: DashboardTheme = theme === "dark" ? "dark" : "light";
|
||||
|
||||
// 输入 JSON(登录拉取/占位)——auto-start 时由 buildInitialPrompt 闭包读取。
|
||||
const inputRef = useRef<unknown>(null);
|
||||
|
||||
const dashboard = useStep3Dashboard({
|
||||
intentReady: null,
|
||||
seatDeliveries: [],
|
||||
consensusText: "",
|
||||
selectedModel,
|
||||
themeMode,
|
||||
buildInitialPrompt: () => {
|
||||
const inp = inputRef.current;
|
||||
return inp ? buildDashboardPromptFromJson(inp) : null;
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
phase,
|
||||
dialogues,
|
||||
data,
|
||||
seatStubMessages,
|
||||
activeArtifactThreadId,
|
||||
busy,
|
||||
redraw,
|
||||
ask,
|
||||
abort,
|
||||
setPreviewEnabled,
|
||||
openDashboardPreview,
|
||||
start,
|
||||
hydrateTranscript,
|
||||
} = dashboard;
|
||||
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [view, setView] = useState<DashView>("chat");
|
||||
const [renderMode, setRenderMode] = useState<RenderMode>("app");
|
||||
|
||||
// 默认选中第一个模型。
|
||||
useEffect(() => {
|
||||
if (availableModels.length === 0) return;
|
||||
if (!availableModels.some((m) => m.name === selectedModel)) {
|
||||
setSelectedModel(availableModels[0].name);
|
||||
}
|
||||
}, [availableModels, selectedModel]);
|
||||
|
||||
// ── 挂载:按 taskId 取会话 → 决定直显大屏 / 看生成过程(只跑一次) ──
|
||||
const didInitRef = useRef(false);
|
||||
useEffect(() => {
|
||||
if (didInitRef.current) return;
|
||||
if (!taskId) {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
didInitRef.current = true;
|
||||
let cancelled = false;
|
||||
void (async () => {
|
||||
try {
|
||||
const session = await getDashboardSessionByTask(taskId).catch(() => null);
|
||||
if (cancelled) return;
|
||||
const savedDialogues = (session?.transcript as Step2Dialogue[] | undefined) ?? [];
|
||||
const validReport = session?.reportJson && parseReportJson(session.reportJson);
|
||||
if (validReport) {
|
||||
// 有有效结果 → 恢复并直接展示大屏页面。
|
||||
hydrateTranscript(savedDialogues, session!.reportJson);
|
||||
setView("page");
|
||||
} else if (savedDialogues.length > 0) {
|
||||
// 有历史聊天但无有效结果 → 进生成过程展示历史,不自动重跑。
|
||||
hydrateTranscript(savedDialogues, session?.reportJson ?? null);
|
||||
setView("chat");
|
||||
} else {
|
||||
// 无任何记录 → 拉输入 JSON 自动开跑,让用户看生成过程(不自动跳)。
|
||||
const input = await fetchDashboardInputJson(taskId).catch(() => null);
|
||||
if (cancelled) return;
|
||||
inputRef.current = input;
|
||||
setView("chat");
|
||||
if (input) start();
|
||||
}
|
||||
} finally {
|
||||
if (!cancelled) setLoading(false);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [taskId, hydrateTranscript, start]);
|
||||
|
||||
// ── 防抖回存聊天记录 + 最新 report-json(按 taskId 共享) ──
|
||||
useEffect(() => {
|
||||
if (!taskId || loading) return;
|
||||
if (dialogues.length === 0) return;
|
||||
const t = window.setTimeout(() => {
|
||||
void putDashboardSessionByTask(taskId, {
|
||||
transcript: dialogues,
|
||||
reportJson: data ? JSON.stringify(data) : undefined,
|
||||
}).catch(() => {
|
||||
/* 回存失败不打扰用户 */
|
||||
});
|
||||
}, 800);
|
||||
return () => window.clearTimeout(t);
|
||||
}, [taskId, loading, dialogues, data]);
|
||||
|
||||
// 仅在交互区允许本流自动接管沙箱(并行流防抢);离开/卸载时让出。
|
||||
useEffect(() => {
|
||||
setPreviewEnabled(view === "chat");
|
||||
return () => setPreviewEnabled(false);
|
||||
}, [view, setPreviewEnabled]);
|
||||
|
||||
// ── 大屏渲染数据(深度脱敏后渲染,覆盖大屏所有展示文本) ──
|
||||
const report = useMemo(() => (data ? desensitizeDeep(data) : null), [data]);
|
||||
const dashboardData = useMemo(
|
||||
() => (report ? adaptReportData(report, formatNow()) : undefined),
|
||||
[report],
|
||||
);
|
||||
const dashboardHtml = useMemo(
|
||||
() => (report ? renderDashboardHtml(report, { generatedAt: formatNow(), theme: themeMode }) : null),
|
||||
[report, themeMode],
|
||||
);
|
||||
const hasResult = !!dashboardData || !!dashboardHtml;
|
||||
|
||||
// 网页渲染:blob URL 作 iframe src(:target 导航需独立文档 URL,见 Step3DashboardMode 注释)。
|
||||
const [htmlBlobUrl, setHtmlBlobUrl] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined" || !dashboardHtml) {
|
||||
setHtmlBlobUrl(null);
|
||||
return;
|
||||
}
|
||||
const url = URL.createObjectURL(new Blob([dashboardHtml], { type: "text/html;charset=utf-8" }));
|
||||
setHtmlBlobUrl(url);
|
||||
return () => URL.revokeObjectURL(url);
|
||||
}, [dashboardHtml]);
|
||||
|
||||
const isStreaming =
|
||||
phase === "creating" || phase === "streaming" || dialogues.some((d) => d.streaming === true);
|
||||
|
||||
const handleOpenNewWindow = () => {
|
||||
if (typeof window === "undefined") return;
|
||||
if (renderMode === "html" && dashboardHtml) {
|
||||
const blobUrl = URL.createObjectURL(new Blob([dashboardHtml], { type: "text/html;charset=utf-8" }));
|
||||
window.open(blobUrl, "_blank", "noopener,noreferrer");
|
||||
window.setTimeout(() => URL.revokeObjectURL(blobUrl), 60_000);
|
||||
return;
|
||||
}
|
||||
const key = `${DASHBOARD_VIEW_STORAGE_PREFIX}${Date.now()}`;
|
||||
try {
|
||||
for (let i = window.localStorage.length - 1; i >= 0; i -= 1) {
|
||||
const k = window.localStorage.key(i);
|
||||
if (k && k.startsWith(DASHBOARD_VIEW_STORAGE_PREFIX)) window.localStorage.removeItem(k);
|
||||
}
|
||||
if (dashboardData) window.localStorage.setItem(key, JSON.stringify(dashboardData));
|
||||
} catch {
|
||||
/* localStorage 不可用:新窗口回落 DEMO */
|
||||
}
|
||||
const base = `${window.location.origin}${window.location.pathname}`;
|
||||
window.open(`${base}#/roundtable-dashboard?k=${encodeURIComponent(key)}`, "_blank", "noopener,noreferrer");
|
||||
};
|
||||
|
||||
if (!taskId) {
|
||||
return (
|
||||
<div className="flex h-full min-h-0 items-center justify-center p-8 text-center text-sm text-slate-500">
|
||||
<div>
|
||||
<Sparkles className="mx-auto mb-3 h-8 w-8 text-primary/40" />
|
||||
缺少任务标识(taskId)。请通过带 <code className="px-1">?taskId=</code> 的链接进入大屏绘制页。
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-full min-h-0 flex-col text-slate-800">
|
||||
{/* 顶栏 */}
|
||||
<div className="shrink-0 flex flex-wrap items-center justify-between gap-3 border-b border-slate-100 bg-gradient-to-r from-slate-50 to-white px-6 py-3">
|
||||
<div className="flex items-center gap-2.5">
|
||||
<Sparkles className="h-4.5 w-4.5 text-primary" />
|
||||
<h3 className="text-sm font-black tracking-tight text-slate-900">大屏绘制智能体</h3>
|
||||
<span className="inline-flex items-center gap-1.5 rounded-full border border-red-200/50 bg-[var(--brand-200)]/60 px-2 py-0.5 text-[10px] font-bold text-primary">
|
||||
{(phase === "creating" || phase === "streaming") && <Loader2 className="h-3 w-3 animate-spin" />}
|
||||
{view === "chat" ? "生成过程" : "大屏页面"}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
{view === "page" ? (
|
||||
<>
|
||||
<div className="inline-flex items-center gap-0.5 rounded-xl border border-slate-200 bg-slate-50 p-0.5">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setRenderMode("app")}
|
||||
title="用应用内 React 组件渲染(Tab 切换、动画、席位钻取)"
|
||||
className={`flex items-center gap-1 rounded-lg px-2.5 py-1 text-[10.5px] font-bold transition ${
|
||||
renderMode === "app"
|
||||
? "border border-slate-200 bg-white text-primary shadow-sm"
|
||||
: "text-slate-500 hover:text-slate-700"
|
||||
}`}
|
||||
>
|
||||
<Boxes className="h-3.5 w-3.5" />
|
||||
应用渲染
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setRenderMode("html")}
|
||||
disabled={!dashboardHtml}
|
||||
title={dashboardHtml ? "用自包含 HTML 大屏渲染(与新窗口/下载一致)" : "尚无已生成的 HTML,先完成一次绘制"}
|
||||
className={`flex items-center gap-1 rounded-lg px-2.5 py-1 text-[10.5px] font-bold transition disabled:cursor-not-allowed disabled:opacity-40 ${
|
||||
renderMode === "html"
|
||||
? "border border-slate-200 bg-white text-primary shadow-sm"
|
||||
: "text-slate-500 hover:text-slate-700"
|
||||
}`}
|
||||
>
|
||||
<Code2 className="h-3.5 w-3.5" />
|
||||
网页渲染
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setView("chat")}
|
||||
title="回到生成过程,加载聊天记录继续问答修改"
|
||||
className="flex items-center gap-1 rounded-xl border border-slate-200 bg-white px-3 py-1.5 text-[10.5px] font-bold text-slate-700 transition hover:bg-slate-50"
|
||||
>
|
||||
<Pencil className="h-3.5 w-3.5 text-slate-500" />
|
||||
编辑
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleOpenNewWindow}
|
||||
title={renderMode === "html" ? "新标签页打开自包含 HTML 大屏" : "新标签页打开应用内 React 大屏(全屏)"}
|
||||
className="flex items-center gap-1 rounded-xl border border-slate-200 bg-white px-3 py-1.5 text-[10.5px] font-bold text-slate-700 transition hover:bg-slate-50"
|
||||
>
|
||||
<ExternalLink className="h-3.5 w-3.5 text-slate-500" />
|
||||
新窗口打开
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
hasResult && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setView("page")}
|
||||
title="查看已生成的大屏页面"
|
||||
className="flex items-center gap-1 rounded-xl border border-slate-200 bg-white px-3 py-1.5 text-[10.5px] font-bold text-slate-700 transition hover:bg-slate-50"
|
||||
>
|
||||
<LayoutPanelTop className="h-3.5 w-3.5 text-slate-500" />
|
||||
查看大屏
|
||||
</button>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 主体 */}
|
||||
{loading ? (
|
||||
<div className="flex flex-1 items-center justify-center gap-2 text-sm text-slate-500">
|
||||
<Loader2 className="h-4 w-4 animate-spin text-primary" />
|
||||
正在加载任务大屏…
|
||||
</div>
|
||||
) : view === "page" ? (
|
||||
renderMode === "html" && htmlBlobUrl ? (
|
||||
<iframe
|
||||
title="任务研讨大屏"
|
||||
src={htmlBlobUrl}
|
||||
className="min-h-0 w-full flex-1 border-0 bg-white"
|
||||
sandbox="allow-scripts allow-popups allow-downloads allow-same-origin"
|
||||
/>
|
||||
) : (
|
||||
<div className="min-h-0 flex-1 overflow-auto">
|
||||
<DashboardApp data={dashboardData} />
|
||||
</div>
|
||||
)
|
||||
) : (
|
||||
<div className="min-h-0 flex-1 p-3">
|
||||
<section className="h-full min-h-0 overflow-hidden rounded-2xl border border-slate-200/60 bg-white">
|
||||
<Step2SandboxLayout
|
||||
activeThreadId={activeArtifactThreadId}
|
||||
isStreaming={isStreaming}
|
||||
seatMessages={activeArtifactThreadId ? seatStubMessages[activeArtifactThreadId] : undefined}
|
||||
>
|
||||
<DashboardChatPanel
|
||||
phase={phase}
|
||||
dialogues={dialogues}
|
||||
busy={busy}
|
||||
error={dashboard.error}
|
||||
onAsk={ask}
|
||||
onRedraw={redraw}
|
||||
onPause={abort}
|
||||
onOpenPreview={openDashboardPreview}
|
||||
hasResult={hasResult}
|
||||
selectedModel={selectedModel}
|
||||
availableModels={availableModels}
|
||||
modelsLoading={modelsLoading}
|
||||
setSelectedModel={setSelectedModel}
|
||||
subtitle="分析任务原始数据,提炼为大屏结构化数据(右侧实时显示抽取过程)"
|
||||
doneHint="数据已就绪,点右上「查看大屏」查看。"
|
||||
/>
|
||||
</Step2SandboxLayout>
|
||||
</section>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -2564,22 +2564,31 @@ function RoundtableEntryRail({
|
||||
该业务链暂无智能体席位
|
||||
</p>
|
||||
) : (
|
||||
<div className="flex flex-col items-center gap-1.5">
|
||||
{stageGroups.map((stage, si) => (
|
||||
<div
|
||||
key={si}
|
||||
className="flex flex-col items-center gap-1"
|
||||
>
|
||||
{si > 0 && (
|
||||
<ChevronDown className="h-3 w-3 text-neutral-300" />
|
||||
)}
|
||||
{stage.length > 1 && (
|
||||
<span className="rounded-full bg-primary/5 px-1.5 text-[8.5px] font-semibold text-primary">
|
||||
并行 {stage.length}
|
||||
</span>
|
||||
)}
|
||||
<div className="flex flex-wrap items-center justify-center gap-1.5">
|
||||
{stage.map((seat, sj) => {
|
||||
<div className="flex flex-row flex-wrap items-center justify-center gap-1">
|
||||
{stageGroups.flatMap((stage, si) => {
|
||||
// 横向编排:阶段从左到右排列,阶段之间用 → 串联;并行阶段的
|
||||
// 席位在该列内竖向堆叠(宽度可控,符合「同层并行·层间串行」示意)。
|
||||
const items: React.ReactNode[] = [];
|
||||
if (si > 0) {
|
||||
items.push(
|
||||
<ChevronRight
|
||||
key={`arrow-${si}`}
|
||||
className="h-3 w-3 shrink-0 text-neutral-300"
|
||||
/>,
|
||||
);
|
||||
}
|
||||
items.push(
|
||||
<div
|
||||
key={`stage-${si}`}
|
||||
className="flex flex-col items-center gap-1"
|
||||
>
|
||||
{stage.length > 1 && (
|
||||
<span className="rounded-full bg-primary/5 px-1.5 text-[8.5px] font-semibold text-primary">
|
||||
并行 {stage.length}
|
||||
</span>
|
||||
)}
|
||||
<div className="flex flex-col items-center gap-1.5">
|
||||
{stage.map((seat, sj) => {
|
||||
const palette =
|
||||
SEAT_CHIP_PALETTE[
|
||||
seatColorIndex++ %
|
||||
@@ -2614,10 +2623,12 @@ function RoundtableEntryRail({
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
})}
|
||||
</div>
|
||||
</div>,
|
||||
);
|
||||
return items;
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user