feat(roundtable): 业务链条流程图改弹窗 + 每阶段「本阶段目标」注入总控

- 业务链条配置页流程图从底部内嵌改为按钮 + Dialog 弹窗查看
- 每个 Stage 新增可选「本阶段目标」文本框,告诉总控本阶段要产出
  什么、如何依赖上一阶段产出(仅分层 DAG 生效)
- StageGroups 重构为 StageGroup[]({seats, goal?}),goal 随 stage
  在增删改/重排中自动跟随;新增 stageGoals 持久化(与 stages 同下标对齐)
- 运行时注入:buildDagStageLeaderTask(总控派活,主)+ pickDagSeatTask
  (席位任务,兜底)
- 后端 roundtable_chains 加 stage_goals 列 + 校验 + Alembic 20260608_04
- 老链条/草稿无该字段时不注入,行为不变

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
董宏凯andClaude Opus 4.8 committed 2026-06-08 16:10:46 +08:00
1 parent ce431ee155
commit 834df64650
13 files changed
+486 -94

No files matched your search

@@ -32,6 +32,7 @@ import {
GripVertical,
Layers,
Loader2,
Network,
Plus,
Save,
SplitSquareVertical,
@@ -60,6 +61,12 @@ import { CSS } from "@dnd-kit/utilities";
import { cn } from "@/lib/utils";
import { Input } from "@/components/ui/input";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { TagSearchBar } from "@/components/workspace/tags/tag-search-bar";
import { listAgents } from "@/core/agents";
@@ -93,9 +100,12 @@ import {
moveStage,
removeSeat as removeSeatFromGroups,
seatExistsInGroups,
setStageGoal,
splitSeatToNewStage,
stageGroupsToSeats,
stageGroupsToStageGoals,
stageGroupsToStagePayload,
type StageGroup,
type StageGroups,
} from "@/roundtable-planning/lib/chain-stages";
import { getAvatarTypeFor } from "@/roundtable-planning/lib/roundtable-constants";
@@ -144,6 +154,7 @@ export default function BusinessChainEditorPage() {
const [activeDrag, setActiveDrag] = useState<ActiveDrag>(null);
const [dropdownOpen, setDropdownOpen] = useState(false);
const [flowOpen, setFlowOpen] = useState(false);
const sensors = useSensors(
useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),
@@ -155,7 +166,7 @@ export default function BusinessChainEditorPage() {
return m;
}, [pool]);
const seatIdSet = useMemo(
() => new Set(stageGroups.flat().map((s) => s.agent_id)),
() => new Set(stageGroups.flatMap((g) => g.seats).map((s) => s.agent_id)),
[stageGroups],
);
const seatCount = useMemo(() => countSeats(stageGroups), [stageGroups]);
@@ -165,14 +176,14 @@ export default function BusinessChainEditorPage() {
const previewStages = useMemo(
() =>
stageGroups
.filter((g) => g.length > 0)
.map((g, i) => ({ id: `stage-${i}`, agentIds: g.map((s) => s.agent_id) })),
.filter((g) => g.seats.length > 0)
.map((g, i) => ({ id: `stage-${i}`, agentIds: g.seats.map((s) => s.agent_id) })),
[stageGroups],
);
const seatNameById = useMemo(() => {
const m = new Map<string, string>();
for (const g of stageGroups)
for (const s of g) m.set(s.agent_id.toLowerCase(), s.name || s.agent_id);
for (const s of g.seats) m.set(s.agent_id.toLowerCase(), s.name || s.agent_id);
return m;
}, [stageGroups]);
const resolvePreviewSeat = useCallback(
@@ -291,6 +302,10 @@ export default function BusinessChainEditorPage() {
setStageGroups((prev) => moveSeatToStage(prev, agentId, targetStageIdx));
}, []);
const setGoal = useCallback((stageIdx: number, goal: string) => {
setStageGroups((prev) => setStageGoal(prev, stageIdx, goal));
}, []);
const splitSeat = useCallback((agentId: string) => {
setStageGroups((prev) => splitSeatToNewStage(prev, agentId));
}, []);
@@ -306,8 +321,8 @@ export default function BusinessChainEditorPage() {
const removeStage = useCallback((stageIdx: number) => {
setStageGroups((prev) => {
const stage = prev[stageIdx];
if (stage && stage.length > 0) {
if (!window.confirm(`删除 Stage ${stageIdx + 1} 会移除其中 ${stage.length} 个席位,确认?`)) {
if (stage && stage.seats.length > 0) {
if (!window.confirm(`删除 Stage ${stageIdx + 1} 会移除其中 ${stage.seats.length} 个席位,确认?`)) {
return prev;
}
}
@@ -349,7 +364,7 @@ export default function BusinessChainEditorPage() {
} else if (overId.startsWith(SEAT_PREFIX)) {
const overAgent = overId.slice(SEAT_PREFIX.length);
targetStage = findStageIndexOfSeat(stageGroups, overAgent);
atIndex = stageGroups[targetStage]?.findIndex((s) => s.agent_id === overAgent);
atIndex = stageGroups[targetStage]?.seats.findIndex((s) => s.agent_id === overAgent);
}
const toNewStage = overId === NEWSTAGE_DROPPABLE_ID;
@@ -389,7 +404,7 @@ export default function BusinessChainEditorPage() {
// ─── 保存 / 删除 ──────────────────────────────────────────────────────
const seatCountInvalid = seatCount < CHAIN_MIN_SEATS || seatCount > CHAIN_MAX_SEATS;
const hasEmptyStage = stageGroups.some((g) => g.length === 0);
const hasEmptyStage = stageGroups.some((g) => g.seats.length === 0);
const canSave = title.trim().length > 0 && !seatCountInvalid && !saving;
const handleSave = useCallback(async () => {
@@ -411,12 +426,15 @@ export default function BusinessChainEditorPage() {
description: poolById.get(s.agent_id)?.description ?? s.description ?? "",
}));
const stages = stageGroupsToStagePayload(stageGroups);
// 每阶段目标,与 stages 同下标对齐(无并行时同样为 null)。
const stageGoals = stageGroupsToStageGoals(stageGroups);
if (currentChainId) {
const updated = await updateChain(currentChainId, {
title: title.trim(),
description: description.trim() || undefined,
seats: payloadSeats,
stages,
stageGoals,
});
if (!updated) {
toast.error("链条已不存在,可能被删除");
@@ -433,6 +451,7 @@ export default function BusinessChainEditorPage() {
description: description.trim() || undefined,
seats: payloadSeats,
stages,
stageGoals,
});
setCurrentChainId(created.id);
toast.success("已创建业务链条");
@@ -793,6 +812,7 @@ export default function BusinessChainEditorPage() {
onRemoveSeat={removeSeat}
onMergeSeat={mergeSeatToStage}
onSplitSeat={splitSeat}
onStageGoalChange={setGoal}
/>
</main>
@@ -811,24 +831,48 @@ export default function BusinessChainEditorPage() {
</DragOverlay>
</DndContext>
{/* Phase 7:分层 DAG 只读流程图预览(§2.2 底部)。空编排时不渲染。 */}
{/* Phase 7:分层 DAG 只读流程图预览(§2.2 底部)。空编排时不渲染。
改为弹窗查看:底栏一个入口按钮,点击后在 Dialog 内展示完整流程图。 */}
{previewStages.length > 0 && (
<section className="shrink-0 border-t border-border bg-card px-6 py-2">
<div className="mb-1 flex items-center gap-2 text-[11px] font-semibold text-muted-foreground">
<section className="shrink-0 flex items-center justify-between gap-2 border-t border-border bg-card px-6 py-2">
<span className="flex items-center gap-2 text-[11px] font-semibold text-muted-foreground">
<span>编排预览</span>
<span className="text-muted-foreground/50">
总控派活 → 各 Stage(串行)→ 共识 → 结果绘制
</span>
</div>
<DagFlowChart
stages={previewStages}
resolveSeat={resolvePreviewSeat}
showReportMilestone={false}
compact
/>
</span>
<button
type="button"
onClick={() => setFlowOpen(true)}
className="inline-flex items-center gap-1.5 rounded-lg border border-primary/30 bg-primary/5 px-2.5 py-1 text-xs font-semibold text-primary transition hover:bg-primary/10"
>
<Network className="size-3.5" />
查看编排流程图
</button>
</section>
)}
{/* 编排流程图弹窗 */}
{previewStages.length > 0 && (
<Dialog open={flowOpen} onOpenChange={setFlowOpen}>
<DialogContent className="flex max-h-[88vh] w-[94vw] flex-col gap-0 sm:max-w-[1100px]">
<DialogHeader className="shrink-0">
<DialogTitle className="flex items-center gap-2">
<Network className="size-5 text-primary" />
编排流程图
</DialogTitle>
</DialogHeader>
<div className="min-h-0 flex-1 overflow-auto pt-2">
<DagFlowChart
stages={previewStages}
resolveSeat={resolvePreviewSeat}
showReportMilestone={false}
/>
</div>
</DialogContent>
</Dialog>
)}
{/* 页脚 */}
<footer className="shrink-0 select-none border-t border-border bg-card px-6 py-3 text-center text-[11px] text-muted-foreground">
分层编排:同一 Stage 内的席位并行研讨,Stage 之间串行。全单席位 = 线性链。保存后自动同步至圆桌。
@@ -923,6 +967,7 @@ function StagesColumn({
onRemoveSeat,
onMergeSeat,
onSplitSeat,
onStageGoalChange,
}: {
stageGroups: StageGroups;
seatCount: number;
@@ -934,6 +979,7 @@ function StagesColumn({
onRemoveSeat: (agentId: string) => void;
onMergeSeat: (agentId: string, targetStageIdx: number) => void;
onSplitSeat: (agentId: string) => void;
onStageGoalChange: (stageIdx: number, goal: string) => void;
}) {
// 跨 Stage 的全局序号(头像编号):每个 Stage 起始累加。
const stageStartIndex = useMemo(() => {
@@ -941,10 +987,12 @@ function StagesColumn({
let acc = 0;
for (const g of stageGroups) {
out.push(acc);
acc += g.length;
acc += g.seats.length;
}
return out;
}, [stageGroups]);
// 是否含并行 stage → 决定提示「目标仅对含并行的分层链条生效」。
const hasParallelStage = stageGroups.some((g) => g.seats.length > 1);
return (
<section
@@ -1018,11 +1066,13 @@ function StagesColumn({
group={group}
stageCount={stageGroups.length}
startIndex={stageStartIndex[stageIdx]}
hasParallelStage={hasParallelStage}
onRemoveStage={() => onRemoveStage(stageIdx)}
onReorderStage={(dir) => onReorderStage(stageIdx, dir)}
onRemoveSeat={onRemoveSeat}
onMergeSeat={onMergeSeat}
onSplitSeat={onSplitSeat}
onGoalChange={(goal) => onStageGoalChange(stageIdx, goal)}
/>
))}
<NewStageDropZone hasEmptyStage={hasEmptyStage} onAddStage={onAddStage} />
@@ -1040,27 +1090,33 @@ function StageSection({
group,
stageCount,
startIndex,
hasParallelStage,
onRemoveStage,
onReorderStage,
onRemoveSeat,
onMergeSeat,
onSplitSeat,
onGoalChange,
}: {
stageIdx: number;
group: ChainSeat[];
group: StageGroup;
stageCount: number;
startIndex: number;
/** 整条链是否含并行 stage(决定目标输入框的提示语,目标仅 dag 模式生效)。 */
hasParallelStage: boolean;
onRemoveStage: () => void;
onReorderStage: (dir: -1 | 1) => void;
onRemoveSeat: (agentId: string) => void;
onMergeSeat: (agentId: string, targetStageIdx: number) => void;
onSplitSeat: (agentId: string) => void;
onGoalChange: (goal: string) => void;
}) {
const { setNodeRef, isOver } = useDroppable({ id: STAGE_PREFIX + stageIdx });
const isParallel = group.length > 1;
const seats = group.seats;
const isParallel = seats.length > 1;
const isFirstStage = stageIdx === 0;
const isLastStage = stageIdx === stageCount - 1;
const seatItemIds = group.map((s) => SEAT_PREFIX + s.agent_id);
const seatItemIds = seats.map((s) => SEAT_PREFIX + s.agent_id);
return (
<div className={cn("border border-border bg-muted/20", R_CARD, PANEL_SHADOW)}>
@@ -1086,7 +1142,7 @@ function StageSection({
: "border-border bg-muted text-muted-foreground",
)}
>
{isParallel ? `并行 ${group.length}` : "串行"}
{isParallel ? `并行 ${seats.length}` : "串行"}
</span>
</div>
<div className="flex items-center gap-0.5">
@@ -1131,18 +1187,45 @@ function StageSection({
</div>
</div>
{/* 本阶段目标:告诉总控本阶段要产出什么、如何依赖上一阶段产出(仅含并行的分层链条生效)。 */}
{seats.length > 0 && (
<div className="border-b border-border bg-muted/10 px-2.5 py-2">
<textarea
value={group.goal ?? ""}
onChange={(e) => onGoalChange(e.target.value)}
maxLength={500}
rows={2}
placeholder={
isFirstStage
? "本阶段目标(可选):本阶段要产出什么,供后续阶段承接"
: "本阶段目标(可选):本阶段要产出什么、如何依赖上一阶段产出"
}
className={cn(
"w-full resize-y bg-card px-2.5 py-1.5 text-[11px] leading-relaxed text-foreground placeholder:text-muted-foreground/60",
"border border-border focus:border-primary/40 focus:outline-none",
R_CTRL,
)}
/>
{!hasParallelStage && (group.goal?.trim()?.length ?? 0) > 0 && (
<p className="mt-1 text-[10px] text-amber-600 dark:text-amber-400">
提示:当前链条全为串行,目标仅在含并行 Stage 的分层(DAG)研讨中生效。
</p>
)}
</div>
)}
{/* Stage 内席位 */}
<div
ref={setNodeRef}
className={cn("space-y-2 p-2.5 transition-colors", isOver && "bg-primary/[0.04]")}
>
{group.length === 0 ? (
{seats.length === 0 ? (
<div className={cn("border border-dashed border-border bg-card/40 px-3 py-4 text-center text-[11px] text-muted-foreground", R_CARD)}>
空 Stage —— 把席位拖到此处,或删除该 Stage。
</div>
) : (
<SortableContext items={seatItemIds} strategy={verticalListSortingStrategy}>
{group.map((seat, i) => (
{seats.map((seat, i) => (
<SeatStrip
key={seat.agent_id}
seat={seat}