feat: AI writing history, Word export, roundtable dispatch chain

This commit is contained in:
fengxiangdebaozi committed 2026-06-04 15:40:15 +08:00
1 parent c0e3c5d692
commit 10334ddfe1
21 files changed
+1888 -143

No files matched your search

@@ -0,0 +1,165 @@
/**
* 派活链路流程图弹窗 —— 预览/自测页(Phase 7 临时入口)。
*
* 路由:/page/workspace/roundtable/chain-preview
*
* 用假数据 + 定时器模拟后台作业推进(初始化 → 总控派活 → 席位逐个发言 → 共识 →
* 结果绘制 → 完成),驱动 `DispatchChainModal` 演示节点 / 连线的加载动画与状态流转。
* 后续 Phase 8 接通真实 `streamJob` 后,本页可删除(连同 WorkspaceRoutes 里的路由)。
*/
import { useEffect, useMemo, useRef, useState } from "react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { DispatchChainModal } from "../components/DispatchChainModal";
import {
DEFAULT_SELECTED_AGENTS,
getAvatarTypeFor,
getDisplayNameFor,
} from "../lib/roundtable-constants";
import type {
DispatchChainNode,
JobPhase,
JobStatus,
} from "../lib/job-types";
import "../styles/roundtable-planning.css";
interface SimFrame {
phase: JobPhase;
status: JobStatus;
cycle: number;
consensus: number;
activeAgentId: string | null;
doneAgentIds: string[];
}
const AGENTS = DEFAULT_SELECTED_AGENTS;
/** 预先生成一条完整的推进时间线(每帧约 1.1s)。 */
function buildFrames(): SimFrame[] {
const ids = AGENTS.map((a) => a.agent_id);
const frames: SimFrame[] = [];
frames.push({ phase: "initializing", status: "running", cycle: 0, consensus: 0, activeAgentId: null, doneAgentIds: [] });
frames.push({ phase: "leader_thinking", status: "running", cycle: 1, consensus: 12, activeAgentId: null, doneAgentIds: [] });
// 第 1 轮:逐个席位发言
ids.forEach((id, i) => {
frames.push({
phase: "dispatching",
status: "running",
cycle: 1,
consensus: 12 + Math.round(((i + 1) / ids.length) * 50),
activeAgentId: id,
doneAgentIds: ids.slice(0, i),
});
});
// 第 2 轮:总控再决策(此时第 1 轮席位都已发言)
frames.push({ phase: "leader_thinking", status: "running", cycle: 2, consensus: 78, activeAgentId: null, doneAgentIds: [...ids] });
// 共识达成
frames.push({ phase: "consensus", status: "running", cycle: 2, consensus: 100, activeAgentId: null, doneAgentIds: [...ids] });
// 结果绘制中
frames.push({ phase: "report_drawing", status: "running", cycle: 2, consensus: 100, activeAgentId: null, doneAgentIds: [...ids] });
// 完成
frames.push({ phase: "report_done", status: "done", cycle: 2, consensus: 100, activeAgentId: null, doneAgentIds: [...ids] });
return frames;
}
export default function DispatchChainPreviewPage() {
const frames = useMemo(buildFrames, []);
const [idx, setIdx] = useState(0);
const [playing, setPlaying] = useState(true);
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
// 自动播放:逐帧推进,跑到最后一帧停 2.2s 再循环
useEffect(() => {
if (!playing) return;
const isLast = idx >= frames.length - 1;
timerRef.current = setTimeout(
() => setIdx((i) => (i >= frames.length - 1 ? 0 : i + 1)),
isLast ? 2200 : 1100,
);
return () => {
if (timerRef.current) clearTimeout(timerRef.current);
};
}, [idx, playing, frames.length]);
const frame = frames[idx];
// 由当前帧推导各席位节点状态
const nodes: DispatchChainNode[] = AGENTS.map((a, i) => {
const state =
frame.doneAgentIds.includes(a.agent_id)
? "done"
: frame.activeAgentId === a.agent_id
? "active"
: "pending";
return {
agentId: a.agent_id,
name: getDisplayNameFor(a),
avatarType: getAvatarTypeFor(a.agent_id, i),
order: i + 1,
state,
};
});
return (
<div className="flex h-full min-h-0 flex-col items-center justify-center gap-6 bg-muted/30 p-8">
<div className="text-center">
<h1 className="text-lg font-bold">派活链路流程图 · 预览</h1>
<p className="mt-1 text-sm text-muted-foreground">
模拟后台作业推进(假数据)。帧 {idx + 1}/{frames.length} · {frame.phase}
</p>
</div>
<div className="flex items-center gap-2">
<Button variant="outline" size="sm" onClick={() => setPlaying((p) => !p)}>
{playing ? "暂停" : "继续"}
</Button>
<Button
variant="outline"
size="sm"
onClick={() => {
setIdx((i) => (i > 0 ? i - 1 : i));
setPlaying(false);
}}
>
上一帧
</Button>
<Button
variant="outline"
size="sm"
onClick={() => {
setIdx((i) => (i < frames.length - 1 ? i + 1 : i));
setPlaying(false);
}}
>
下一帧
</Button>
<Button
size="sm"
onClick={() => {
setIdx(0);
setPlaying(true);
}}
>
重新播放
</Button>
</div>
<DispatchChainModal
open
onOpenChange={() => {}}
title="新能源汽车出口策略研讨(预览)"
status={frame.status}
phase={frame.phase}
cycle={frame.cycle}
nodes={nodes}
consensusPercentage={frame.consensus}
onView={() => toast.info("(预览)点击「查看」→ Phase 8 会进入正在进行的任务")}
/>
</div>
);
}