业务链条

This commit is contained in:
fengxiangdebaozi committed 2026-06-02 21:15:46 +08:00
1 parent 30410b0a93
commit 9ae6184dc1
20 files changed
+2440 -24

No files matched your search

@@ -0,0 +1,708 @@
/**
* 业务链条配置页面(路由 `/page/workspace/roundtable/chains`)。
*
* 双栏编辑器:
* - 左栏:候选智能体列表(`listAgents()` + `filterRecommendCandidates` 复用,剔除
* intent/recommender/coordinator),支持**名称检索 + 标签筛选**(`TagSearchBar`,
* 服务端过滤),竖排卡片,可拖到右栏、也可点击快捷加入。
* - 右栏:当前链条的**有序**长条卡片(序号 + 名称 + 描述),可拖拽排序、删除单项;
* 左栏拖入时按落点插入到对应位置。
*
* 拖拽用 `@dnd-kit`:右栏是 `SortableContext`(席位互相排序),左栏卡片是
* `useDraggable`(pool→右栏插入)。落点计算在 `onDragEnd`。
*
* 视觉:套 `roundtable-planning`(+`--dark`) 作用域,与圆桌主页面同一套浅红/深蓝皮肤
* (`styles/roundtable-planning.css`,对齐 docs/浅红色UI规范 + ui规范-深蓝)。
*
* 持久化走 `api/chains.ts`(后端 MySQL `/api/roundtable-chains`)。席位数约束
* 2 ≤ N ≤ 8、agent 去重,保存时校验(后端 `_validate_seats` 也兜底)。
*
* 详见 `docs/multi-agent-business-chain-dev.md` §7 阶段 1。
*/
import { useCallback, useEffect, useMemo, useState } from "react";
import { useNavigate } from "react-router-dom";
import { toast } from "sonner";
import { nanoid } from "nanoid";
import {
ArrowLeft,
GripVertical,
Layers,
ListOrdered,
Loader2,
Plus,
Save,
Trash2,
Users,
X,
} from "lucide-react";
import {
DndContext,
DragOverlay,
PointerSensor,
closestCenter,
useDraggable,
useDroppable,
useSensor,
useSensors,
type DragEndEvent,
type DragStartEvent,
} from "@dnd-kit/core";
import {
SortableContext,
arrayMove,
useSortable,
verticalListSortingStrategy,
} from "@dnd-kit/sortable";
import { CSS } from "@dnd-kit/utilities";
import { cn } from "@/lib/utils";
import { useTheme } from "@/contexts/ThemeContext";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { TagSearchBar } from "@/components/workspace/tags/tag-search-bar";
import { listAgents } from "@/core/agents";
import {
filterRecommendCandidates,
type RecommendCandidate,
} from "@/roundtable-planning/api/recommend";
import {
createChain,
deleteChain,
listChains,
updateChain,
} from "@/roundtable-planning/api/chains";
import {
CHAIN_MAX_SEATS,
CHAIN_MIN_SEATS,
chainTagClasses,
type BusinessChain,
type ChainSeat,
} from "@/roundtable-planning/lib/business-chain";
import { getAvatarTypeFor } from "@/roundtable-planning/lib/roundtable-constants";
const POOL_PREFIX = "pool::";
const SEAT_PREFIX = "seat::";
const SEATS_DROPPABLE_ID = "seats-droppable";
type ActiveDrag =
| { kind: "pool"; agentId: string; name: string }
| { kind: "seat"; agentId: string; name: string }
| null;
export default function BusinessChainEditorPage() {
const navigate = useNavigate();
const { theme } = useTheme();
const isDark = theme === "dark";
// ─── 数据 ────────────────────────────────────────────────────────────
const [pool, setPool] = useState<RecommendCandidate[]>([]);
const [poolLoading, setPoolLoading] = useState(true);
const [chains, setChains] = useState<BusinessChain[]>([]);
// 左栏检索/筛选 —— 服务端过滤(listAgents 支持 search + tag_ids)。
const [search, setSearch] = useState("");
const [filterTagIds, setFilterTagIds] = useState<string[]>([]);
// ─── 当前编辑中的链条 ─────────────────────────────────────────────────
const [currentChainId, setCurrentChainId] = useState<string | null>(null);
const [title, setTitle] = useState("");
const [description, setDescription] = useState("");
const [seats, setSeats] = useState<ChainSeat[]>([]);
const [saving, setSaving] = useState(false);
const [activeDrag, setActiveDrag] = useState<ActiveDrag>(null);
const selectValue = currentChainId ?? "";
const sensors = useSensors(
useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),
);
// 候选池按 agent_id 取元数据。注意 pool 是「当前筛选视图」——已加入但被筛掉
// 的席位名称回退用 seat 自带快照(loadChain 写入),所以 poolById 缺项不影响保存。
const poolById = useMemo(() => {
const m = new Map<string, RecommendCandidate>();
for (const a of pool) m.set(a.agent_id, a);
return m;
}, [pool]);
const seatIdSet = useMemo(() => new Set(seats.map((s) => s.agent_id)), [seats]);
// ─── 链条列表(一次性)─────────────────────────────────────────────────
const refreshChains = useCallback(async () => {
try {
setChains(await listChains());
} catch (err) {
console.warn("[chains] refresh list failed:", err);
}
}, []);
useEffect(() => {
void refreshChains();
}, [refreshChains]);
// ─── 候选池:随 search / tagIds 服务端过滤 ────────────────────────────
useEffect(() => {
let cancelled = false;
setPoolLoading(true);
void (async () => {
try {
const agents = await listAgents({
search: search || undefined,
tagIds: filterTagIds.length ? filterTagIds : undefined,
});
if (cancelled) return;
setPool(filterRecommendCandidates(agents));
} catch (err) {
if (cancelled) return;
toast.error(
`加载候选智能体失败:${err instanceof Error ? err.message : String(err)}`,
);
} finally {
if (!cancelled) setPoolLoading(false);
}
})();
return () => {
cancelled = true;
};
}, [search, filterTagIds]);
// ─── 链条选择 / 新建 ──────────────────────────────────────────────────
const loadChain = useCallback((chain: BusinessChain) => {
setCurrentChainId(chain.id);
setTitle(chain.title);
setDescription(chain.description ?? "");
setSeats(chain.seats.map((s) => ({ ...s })));
}, []);
const startNewChain = useCallback(() => {
setCurrentChainId(null);
setTitle("");
setDescription("");
setSeats([]);
}, []);
// ─── 席位增删改 ───────────────────────────────────────────────────────
const addAgentToSeats = useCallback(
(agentId: string, atIndex?: number) => {
const agent = poolById.get(agentId);
if (!agent) return;
setSeats((prev) => {
if (prev.some((s) => s.agent_id === agentId)) {
toast.info(`「${agent.name}」已在链条中`);
return prev;
}
if (prev.length >= CHAIN_MAX_SEATS) {
toast.warning(`链条最多 ${CHAIN_MAX_SEATS} 个席位`);
return prev;
}
const seat: ChainSeat = {
agent_id: agent.agent_id,
name: agent.name,
description: agent.description,
};
const next = [...prev];
const i = atIndex == null ? next.length : Math.max(0, Math.min(atIndex, next.length));
next.splice(i, 0, seat);
return next;
});
},
[poolById],
);
const removeSeat = useCallback((agentId: string) => {
setSeats((prev) => prev.filter((s) => s.agent_id !== agentId));
}, []);
// ─── DnD ─────────────────────────────────────────────────────────────
const onDragStart = useCallback(
(e: DragStartEvent) => {
const id = String(e.active.id);
if (id.startsWith(POOL_PREFIX)) {
const agentId = id.slice(POOL_PREFIX.length);
const a = poolById.get(agentId);
setActiveDrag({ kind: "pool", agentId, name: a?.name ?? agentId });
} else if (id.startsWith(SEAT_PREFIX)) {
const agentId = id.slice(SEAT_PREFIX.length);
const s = seats.find((x) => x.agent_id === agentId);
setActiveDrag({ kind: "seat", agentId, name: s?.name ?? agentId });
}
},
[poolById, seats],
);
const onDragEnd = useCallback(
(e: DragEndEvent) => {
setActiveDrag(null);
const activeId = String(e.active.id);
const overId = e.over ? String(e.over.id) : null;
if (!overId) return;
// over 落在第几个席位之前(over 是席位则取其索引,否则追加到末尾)。
const overSeatIndex = overId.startsWith(SEAT_PREFIX)
? seats.findIndex((s) => SEAT_PREFIX + s.agent_id === overId)
: -1;
if (activeId.startsWith(POOL_PREFIX)) {
const agentId = activeId.slice(POOL_PREFIX.length);
const insertAt = overSeatIndex >= 0 ? overSeatIndex : seats.length;
addAgentToSeats(agentId, insertAt);
return;
}
if (activeId.startsWith(SEAT_PREFIX)) {
const fromIndex = seats.findIndex(
(s) => SEAT_PREFIX + s.agent_id === activeId,
);
if (fromIndex < 0) return;
const toIndex = overSeatIndex >= 0 ? overSeatIndex : seats.length - 1;
if (fromIndex === toIndex) return;
setSeats((prev) => arrayMove(prev, fromIndex, toIndex));
}
},
[seats, addAgentToSeats],
);
// ─── 保存 / 删除 ──────────────────────────────────────────────────────
const seatCountInvalid =
seats.length < CHAIN_MIN_SEATS || seats.length > CHAIN_MAX_SEATS;
const canSave = title.trim().length > 0 && !seatCountInvalid && !saving;
const handleSave = useCallback(async () => {
if (!title.trim()) {
toast.warning("请先填写链条标题");
return;
}
if (seatCountInvalid) {
toast.warning(`链条席位数须在 ${CHAIN_MIN_SEATS}–${CHAIN_MAX_SEATS} 之间`);
return;
}
setSaving(true);
try {
const payloadSeats = seats.map((s) => ({
agent_id: s.agent_id,
name: poolById.get(s.agent_id)?.name ?? s.name,
description: poolById.get(s.agent_id)?.description ?? s.description ?? "",
}));
if (currentChainId) {
const updated = await updateChain(currentChainId, {
title: title.trim(),
description: description.trim() || undefined,
seats: payloadSeats,
});
if (!updated) {
toast.error("链条已不存在,可能被删除");
startNewChain();
await refreshChains();
return;
}
toast.success("已保存");
} else {
const id = nanoid();
const created = await createChain({
id,
title: title.trim(),
description: description.trim() || undefined,
seats: payloadSeats,
});
setCurrentChainId(created.id);
toast.success("已创建业务链条");
}
await refreshChains();
} catch (err) {
toast.error(`保存失败:${err instanceof Error ? err.message : String(err)}`);
} finally {
setSaving(false);
}
}, [
title,
description,
seats,
seatCountInvalid,
currentChainId,
poolById,
refreshChains,
startNewChain,
]);
const handleDelete = useCallback(async () => {
if (!currentChainId) {
startNewChain();
return;
}
if (!window.confirm(`确认删除业务链条「${title || "未命名"}」?此操作不可恢复。`)) {
return;
}
try {
await deleteChain(currentChainId);
toast.success("已删除");
startNewChain();
await refreshChains();
} catch (err) {
toast.error(`删除失败:${err instanceof Error ? err.message : String(err)}`);
}
}, [currentChainId, title, startNewChain, refreshChains]);
// ─── Render ──────────────────────────────────────────────────────────
const seatItemIds = seats.map((s) => SEAT_PREFIX + s.agent_id);
return (
<div
className={cn(
"roundtable-planning theme-transition flex h-full min-h-0 flex-col bg-[var(--rt-page-bg)] font-sans text-foreground",
isDark && "roundtable-planning--dark",
)}
>
{/* 顶栏 */}
<header className="flex shrink-0 flex-wrap items-center gap-3 border-b border-border bg-card px-5 py-3 shadow-[0_1px_3px_rgba(0,0,0,0.03)]">
<Button
variant="ghost"
size="sm"
onClick={() => navigate("/page/workspace/roundtable/planning")}
className="gap-1.5 text-muted-foreground hover:text-foreground"
>
<ArrowLeft className="size-4" />
返回圆桌
</Button>
<div className="h-5 w-px bg-border" />
<div className="flex items-center gap-2.5">
<span className="flex size-8 items-center justify-center rounded-lg bg-primary/10 text-primary">
<Layers className="size-4" />
</span>
<div className="leading-tight">
<div className="text-sm font-bold">业务链条配置</div>
<div className="text-[11px] text-muted-foreground">编排有序的智能体研讨链路</div>
</div>
</div>
{/* 链条选择 + 新建 */}
<div className="ml-2 flex items-center gap-2">
<select
value={selectValue}
onChange={(e) => {
const id = e.target.value;
if (!id) {
startNewChain();
return;
}
const chain = chains.find((c) => c.id === id);
if (chain) loadChain(chain);
}}
className="h-8 rounded-md border border-input bg-card px-2.5 text-sm font-medium shadow-sm outline-none focus:border-primary/60 focus:ring-2 focus:ring-primary/20"
>
<option value="">+ 新建链条…</option>
{chains.map((c) => (
<option key={c.id} value={c.id}>
{c.title || "未命名"}({c.seats.length} 席)
</option>
))}
</select>
<Button variant="outline" size="sm" onClick={startNewChain} className="gap-1.5">
<Plus className="size-4" />
新建
</Button>
</div>
<div className="ml-auto flex items-center gap-2">
<Button
variant="outline"
size="sm"
onClick={handleDelete}
disabled={!currentChainId}
className="gap-1.5 text-destructive hover:text-destructive"
>
<Trash2 className="size-4" />
删除
</Button>
<Button
size="sm"
onClick={handleSave}
disabled={!canSave}
className="gap-1.5 bg-primary text-primary-foreground hover:opacity-90"
>
{saving ? <Loader2 className="size-4 animate-spin" /> : <Save className="size-4" />}
保存
</Button>
</div>
</header>
{/* 标题 + 描述 */}
<div className="flex shrink-0 flex-col gap-2 border-b border-border bg-card/60 px-5 py-3 sm:flex-row sm:items-center">
<div className="flex items-center gap-2 sm:w-72">
<span className="shrink-0 text-xs font-semibold text-muted-foreground">标题</span>
<Input
value={title}
onChange={(e) => setTitle(e.target.value)}
placeholder="如:应急方案三段链"
className="bg-card"
maxLength={120}
/>
</div>
<div className="flex flex-1 items-center gap-2">
<span className="shrink-0 text-xs font-semibold text-muted-foreground">描述</span>
<Input
value={description}
onChange={(e) => setDescription(e.target.value)}
placeholder="链条用途说明(可选)"
className="bg-card"
maxLength={500}
/>
</div>
</div>
{/* 双栏拖拽编辑器 */}
<DndContext
sensors={sensors}
collisionDetection={closestCenter}
onDragStart={onDragStart}
onDragEnd={onDragEnd}
>
<div className="grid min-h-0 flex-1 grid-cols-1 gap-4 overflow-hidden p-4 md:grid-cols-[360px_1fr]">
{/* 左栏:候选智能体 */}
<section className="flex min-h-0 flex-col overflow-hidden rounded-2xl border border-border bg-card shadow-sm">
<div className="shrink-0 space-y-2.5 border-b border-border px-3.5 pb-3 pt-3">
<div className="flex items-center gap-2 text-xs font-bold uppercase tracking-wide text-muted-foreground">
<Users className="size-3.5 text-primary" />
候选智能体
<span className="rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] font-bold text-primary tabular-nums">
{pool.length}
</span>
<span className="ml-auto text-[10px] font-normal normal-case text-muted-foreground/70">
拖到右侧 / 点击加入
</span>
</div>
<TagSearchBar
targetType="agent"
onSearchChange={setSearch}
tagIds={filterTagIds}
onTagIdsChange={setFilterTagIds}
/>
</div>
<div className="min-h-0 flex-1 space-y-2 overflow-y-auto p-2.5 custom-scrollbar">
{poolLoading ? (
<div className="flex items-center gap-2 px-2 py-6 text-sm text-muted-foreground">
<Loader2 className="size-4 animate-spin" />
正在加载候选智能体…
</div>
) : pool.length === 0 ? (
<div className="px-2 py-6 text-center text-sm text-muted-foreground">
{search || filterTagIds.length
? "没有匹配的智能体,换个关键词或标签试试。"
: `候选池为空,请先在「智能体」里创建至少 ${CHAIN_MIN_SEATS} 个智能体。`}
</div>
) : (
pool.map((a) => (
<PoolAgentCard
key={a.agent_id}
agent={a}
inChain={seatIdSet.has(a.agent_id)}
onAdd={() => addAgentToSeats(a.agent_id)}
/>
))
)}
</div>
</section>
{/* 右栏:有序席位 */}
<SeatsColumn
seats={seats}
seatItemIds={seatItemIds}
seatCountInvalid={seatCountInvalid}
onRemove={removeSeat}
/>
</div>
<DragOverlay>
{activeDrag ? (
<div className="flex items-center gap-2 rounded-lg border border-primary/40 bg-card px-3 py-2 text-sm font-semibold shadow-xl">
<GripVertical className="size-4 text-primary" />
{activeDrag.name}
</div>
) : null}
</DragOverlay>
</DndContext>
</div>
);
}
// ── 左栏候选卡片(draggable)─────────────────────────────────────────────
function PoolAgentCard({
agent,
inChain,
onAdd,
}: {
agent: RecommendCandidate;
inChain: boolean;
onAdd: () => void;
}) {
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
id: POOL_PREFIX + agent.agent_id,
disabled: inChain,
});
return (
<div
ref={setNodeRef}
className={cn(
"group flex items-start gap-2 rounded-xl border p-2.5 transition-all",
inChain
? "cursor-not-allowed border-dashed border-border bg-muted/30 opacity-60"
: "cursor-grab border-border bg-card hover:border-primary/40 hover:bg-primary/[0.04] hover:shadow-sm active:cursor-grabbing",
isDragging && "opacity-30",
)}
{...(inChain ? {} : listeners)}
{...attributes}
>
<div className="min-w-0 flex-1">
<div className="truncate text-sm font-semibold">{agent.name || agent.agent_id}</div>
{agent.description && (
<div className="mt-0.5 line-clamp-2 text-xs text-muted-foreground">
{agent.description}
</div>
)}
</div>
{inChain ? (
<span className="shrink-0 self-center rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary">
已加入
</span>
) : (
<button
type="button"
onClick={onAdd}
onPointerDown={(e) => e.stopPropagation()}
className="shrink-0 self-center rounded-lg p-1.5 text-muted-foreground opacity-0 transition-all hover:bg-primary hover:text-primary-foreground group-hover:opacity-100"
title="加入链条"
>
<Plus className="size-4" />
</button>
)}
</div>
);
}
// ── 右栏(droppable 容器 + sortable 列表)───────────────────────────────
function SeatsColumn({
seats,
seatItemIds,
seatCountInvalid,
onRemove,
}: {
seats: ChainSeat[];
seatItemIds: string[];
seatCountInvalid: boolean;
onRemove: (agentId: string) => void;
}) {
const { setNodeRef, isOver } = useDroppable({ id: SEATS_DROPPABLE_ID });
return (
<section className="flex min-h-0 flex-col overflow-hidden rounded-2xl border border-border bg-card shadow-sm">
<div className="flex shrink-0 items-center gap-2 border-b border-border px-4 py-3 text-xs font-bold uppercase tracking-wide text-muted-foreground">
<ListOrdered className="size-3.5 text-primary" />
链条席位
<span className="rounded-full bg-muted px-1.5 py-0.5 text-[10px] font-medium normal-case text-muted-foreground">
按顺序发言
</span>
<span
className={cn(
"ml-auto rounded-full px-2 py-0.5 text-[11px] font-bold tabular-nums normal-case",
seatCountInvalid
? "bg-destructive/10 text-destructive"
: "bg-primary/10 text-primary",
)}
>
{seats.length} / {CHAIN_MAX_SEATS}
{seats.length < CHAIN_MIN_SEATS && ` · 至少 ${CHAIN_MIN_SEATS}`}
</span>
</div>
<div
ref={setNodeRef}
className={cn(
"min-h-0 flex-1 space-y-2 overflow-y-auto p-3.5 custom-scrollbar transition-colors",
isOver && "bg-primary/[0.04]",
)}
>
{seats.length === 0 ? (
<div className="flex h-full flex-col items-center justify-center gap-2 rounded-xl border-2 border-dashed border-border text-sm text-muted-foreground">
<Layers className="size-7 opacity-40" />
从左侧把智能体拖到这里,组成有序业务链条
</div>
) : (
<SortableContext items={seatItemIds} strategy={verticalListSortingStrategy}>
{seats.map((seat, index) => (
<SeatStrip
key={seat.agent_id}
seat={seat}
index={index}
isLast={index === seats.length - 1}
onRemove={() => onRemove(seat.agent_id)}
/>
))}
</SortableContext>
)}
</div>
</section>
);
}
// ── 单个席位长条(sortable)─────────────────────────────────────────────
function SeatStrip({
seat,
index,
isLast,
onRemove,
}: {
seat: ChainSeat;
index: number;
isLast: boolean;
onRemove: () => void;
}) {
const { attributes, listeners, setNodeRef, transform, transition, isDragging } =
useSortable({ id: SEAT_PREFIX + seat.agent_id });
const avatarType = getAvatarTypeFor(seat.agent_id, index);
return (
<div
ref={setNodeRef}
style={{ transform: CSS.Transform.toString(transform), transition }}
className={cn(
"relative flex items-center gap-3 rounded-xl border border-border bg-card p-3 shadow-sm transition-shadow",
isDragging && "z-10 opacity-70 shadow-lg ring-1 ring-primary/30",
)}
>
{/* 顺序连接线(最后一个不画) */}
{!isLast && (
<span className="pointer-events-none absolute -bottom-2 left-[26px] h-2 w-px bg-border" />
)}
<button
type="button"
className="shrink-0 cursor-grab touch-none text-muted-foreground/60 hover:text-foreground active:cursor-grabbing"
{...attributes}
{...listeners}
title="拖动排序"
>
<GripVertical className="size-4" />
</button>
<span
className={cn(
"flex size-7 shrink-0 items-center justify-center rounded-full border text-[12px] font-bold tabular-nums",
chainTagClasses(avatarType),
)}
>
{index + 1}
</span>
<div className="min-w-0 flex-1">
<div className="truncate text-sm font-semibold">{seat.name || seat.agent_id}</div>
{seat.description && (
<div className="mt-0.5 line-clamp-1 text-xs text-muted-foreground">
{seat.description}
</div>
)}
</div>
<button
type="button"
onClick={onRemove}
className="shrink-0 rounded-lg p-1.5 text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive"
title="移除"
>
<X className="size-4" />
</button>
</div>
);
}
@@ -23,6 +23,7 @@
* 6) 模型选择全局默认 `availableModels[0].name`,Persona 覆盖更高优先级
*/
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useNavigate } from "react-router-dom";
import {
Activity,
Check,
@@ -36,6 +37,7 @@ import {
Clock,
Cpu,
History,
ListOrdered,
Loader2,
Pencil,
Save,
@@ -69,10 +71,12 @@ import {
type RoleEntry,
type SelectedAgent,
} from "@/roundtable-planning/lib/roundtable-constants";
import type { SeatSelectionResult } from "@/roundtable-planning/lib/business-chain";
export default function RoundtablePlanningPage() {
const { theme } = useTheme();
const isDark = theme === "dark";
const navigate = useNavigate();
const { models: availableModels, isLoading: modelsLoading } = useModels();
@@ -81,6 +85,13 @@ export default function RoundtablePlanningPage() {
const [showToast, setShowToast] = useState<string | null>(null);
const [isRecommendDialogOpen, setIsRecommendDialogOpen] = useState<boolean>(false);
const [selectedModel, setSelectedModel] = useState<string>("");
// Step 2 编排模式:recommend = 总控自由派活;chain = 总控按业务链条顺序派活。
// 由推荐弹窗确认时的 SeatSelectionResult.mode 决定(见 handleConfirmAgents)。
const [orchestrationMode, setOrchestrationMode] = useState<"recommend" | "chain">(
"recommend",
);
// chain 模式来源链条(仅展示/持久化用)。
const [chainMeta, setChainMeta] = useState<{ id: string; title: string } | null>(null);
const [step2SidebarExpanded, setStep2SidebarExpanded] = useState(true);
// 角色面板(LeftSidebar)。原页面把它当成两步共用的展示数据,这里继续放在
@@ -154,6 +165,7 @@ export default function RoundtablePlanningPage() {
const step2 = useStep2Orchestration({
currentStep,
selectedModel,
orchestrationMode,
buildInitialIntent,
triggerToast,
setRoles,
@@ -205,9 +217,17 @@ export default function RoundtablePlanningPage() {
consensusPercentage: step2.consensusPercentage,
budgetLimit: step2.budgetLimit,
seatStubMessages: step2.seatStubMessages,
orchestrationMode,
chain: chainMeta,
}),
hydrateStep1: step1.hydrateFromDraft,
hydrateStep2: step2.hydrateFromDraft,
// 包一层:先把页面持有的编排模式 / 链条恢复出来(老草稿无字段 → recommend),
// 再交给 step2 hook 恢复其余 Step 2 状态。
hydrateStep2: (snapshot) => {
setOrchestrationMode(snapshot.orchestrationMode ?? "recommend");
setChainMeta(snapshot.chain ?? null);
step2.hydrateFromDraft(snapshot);
},
cancelAllStreams: () => {
step2.abortAllInFlight();
step1.stopIntentStream();
@@ -267,23 +287,32 @@ export default function RoundtablePlanningPage() {
// ─── 步骤间转场 handler ───────────────────────────────────
const handleConfirmAgents = useCallback(
(agents: Array<{ agent_id: string; name: string }>) => {
const normalized: SelectedAgent[] = agents.map(({ agent_id, name }) => ({
(result: SeatSelectionResult) => {
const normalized: SelectedAgent[] = result.agents.map(({ agent_id, name }) => ({
agent_id,
// 内置 agent 走 BUILTIN_AGENT_META;非内置用候选池传过来的 name。
name: BUILTIN_AGENT_META[agent_id]?.displayName ?? name ?? agent_id,
}));
step2.setSelectedAgents(normalized);
step2.resetInitGate();
// result.mode 决定 Step 2 编排:recommend = 总控自由派活;chain = 按链条顺序派活。
setOrchestrationMode(result.mode);
setChainMeta(result.mode === "chain" ? result.chain ?? null : null);
setIsRecommendDialogOpen(false);
setCurrentStep(2);
triggerToast("成功确认!已切换至第二阶段圆桌研讨系统");
triggerToast(
result.mode === "chain"
? `成功确认!将按业务链条「${result.chain?.title ?? ""}」顺序研讨`
: "成功确认!已切换至第二阶段圆桌研讨系统",
);
},
[step2, triggerToast],
);
const handleStartNewTask = useCallback(() => {
step2.resetStep2State();
setOrchestrationMode("recommend");
setChainMeta(null);
step1.stopIntentStream();
drafts.loadedFromDraftRef.current = false;
drafts.setCurrentDraftId(null);
@@ -353,6 +382,16 @@ export default function RoundtablePlanningPage() {
/>
<div className="flex items-center gap-2">
<button
id="business-chain-btn"
onClick={() => navigate("/page/workspace/roundtable/chains")}
title="配置可复用的业务链条(有序智能体编排)"
className="bg-white hover:bg-slate-50 border border-[#e2e8f0] text-[#334155] text-xs font-bold px-3 py-2 rounded-xl flex items-center gap-1.5 transition dark:border-border dark:bg-secondary dark:text-foreground dark:hover:bg-accent"
>
<ListOrdered className="w-3.5 h-3.5 text-primary" />
业务链条
</button>
<button
id="new-task-btn"
onClick={handleStartNewTask}