Skip post-commit ORM refresh on threads_meta creates so concurrent MySQL read/write-split deployments no longer fail with Could not refresh instance; clean up partial roundtable threads on checkpoint failure, and ship related position-roundtable/frontend build fixes. Co-authored-by: Cursor <cursoragent@cursor.com>
2164 lines
87 KiB
TypeScript
2164 lines
87 KiB
TypeScript
/**
|
||
* 业务链条配置页面(路由 `/page/workspace/roundtable/chains`)。
|
||
*
|
||
* 双栏编辑器:
|
||
* - 左栏:候选智能体列表(`listAgents()` + `filterRecommendCandidates` 复用,剔除
|
||
* intent/recommender/coordinator),支持**名称检索 + 标签筛选**(`TagSearchBar`,
|
||
* 服务端过滤),竖排卡片,可拖到右栏、也可点击快捷加入。
|
||
* - 右栏:**分层编排** —— 把席位分到若干 **Stage**(竖向分组):同一 Stage 内并行、
|
||
* Stage 之间串行。可拖席位跨 Stage、整段 Stage 上下移、新建 / 删除 Stage;也提供
|
||
* 按钮(并入上/下一阶段、独立成阶段、移除)做无拖拽兜底。全单席位 Stage = 线性链。
|
||
*
|
||
* 拖拽用 `@dnd-kit`:每个 Stage 是一个 droppable,Stage 内席位 `SortableContext`;
|
||
* 左栏卡片 `useDraggable`(pool→某 Stage / 新建 Stage 区插入)。落点计算在 `onDragEnd`。
|
||
*
|
||
* 持久化走 `api/chains.ts`:`seats` = 各 Stage 展平的有序席位;`stages` = 分层(全单
|
||
* 席位时存 null,即线性,老行为不变)。席位数约束 2 ≤ N ≤ 8、agent 去重。分层操作的
|
||
* 纯逻辑在 `lib/chain-stages.ts`(可单测)。
|
||
*
|
||
* 详见 `docs/roundtable-dag-orchestration.md` §2(Phase 2,分层编辑器)。
|
||
*/
|
||
import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||
import { useNavigate, useSearchParams } from "react-router-dom";
|
||
import { toast } from "sonner";
|
||
import { nanoid } from "nanoid";
|
||
import {
|
||
ArrowLeft,
|
||
Bot,
|
||
ChevronDown,
|
||
ChevronUp,
|
||
Gauge,
|
||
GitBranch,
|
||
Globe,
|
||
GripVertical,
|
||
Info,
|
||
Layers,
|
||
Loader2,
|
||
Network,
|
||
Plus,
|
||
Save,
|
||
Sliders,
|
||
Sparkles,
|
||
SplitSquareVertical,
|
||
Trash2,
|
||
UserPlus,
|
||
Wand2,
|
||
X,
|
||
} from "lucide-react";
|
||
import {
|
||
DndContext,
|
||
DragOverlay,
|
||
PointerSensor,
|
||
closestCenter,
|
||
useDraggable,
|
||
useDroppable,
|
||
useSensor,
|
||
useSensors,
|
||
type DragEndEvent,
|
||
type DragStartEvent,
|
||
} from "@dnd-kit/core";
|
||
import {
|
||
SortableContext,
|
||
useSortable,
|
||
verticalListSortingStrategy,
|
||
} from "@dnd-kit/sortable";
|
||
import { CSS } from "@dnd-kit/utilities";
|
||
|
||
import { cn } from "@/lib/utils";
|
||
import {
|
||
DropdownMenu,
|
||
DropdownMenuContent,
|
||
DropdownMenuItem,
|
||
DropdownMenuLabel,
|
||
DropdownMenuSeparator,
|
||
DropdownMenuTrigger,
|
||
} from "@/components/ui/dropdown-menu";
|
||
import { Switch } from "@/components/ui/switch";
|
||
import { useDesensitizeSubtree } from "@/roundtable-planning/lib/use-desensitize-subtree";
|
||
import { TagSearchBar } from "@/components/workspace/tags/tag-search-bar";
|
||
import { ModelNameSelect } from "@/components/workspace/model-name-select";
|
||
import { Select as TSelect } from "tdesign-react";
|
||
import { listAgents } from "@/core/agents";
|
||
import { getStoredAuth } from "@/core/auth";
|
||
import {
|
||
POSITION_OPTIONS,
|
||
setRuntimePositionOptions,
|
||
type PositionOption,
|
||
type PositionId,
|
||
} from "@/position-roundtable/lib/positions";
|
||
import { usePositionRoles } from "@/strategy-components/api/position-roles";
|
||
|
||
import {
|
||
filterRecommendCandidates,
|
||
type RecommendCandidate,
|
||
} from "@/roundtable-planning/api/recommend";
|
||
import {
|
||
createChain,
|
||
deleteChain,
|
||
getChain,
|
||
listChains,
|
||
optimizeChainPrompt,
|
||
setChainPublic,
|
||
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 {
|
||
DEFAULT_SEAT_MODE,
|
||
SEAT_MODE_OPTIONS,
|
||
type SeatMode,
|
||
} from "@/roundtable-planning/lib/seat-mode";
|
||
import {
|
||
addEmptyStage,
|
||
addSeatAsNewStage,
|
||
addSeatToStage,
|
||
chainToStageGroups,
|
||
countSeats,
|
||
deleteStage as deleteStageGroup,
|
||
findStageIndexOfSeat,
|
||
moveSeatToStage,
|
||
moveStage,
|
||
removeSeat as removeSeatFromGroups,
|
||
seatExistsInGroups,
|
||
setSeatMode as setSeatModeOnGroups,
|
||
setSeatModel,
|
||
setSeatSkillDirective,
|
||
setStageGoal,
|
||
splitSeatToNewStage,
|
||
stageGroupsToSeats,
|
||
stageGroupsToStageGoals,
|
||
stageGroupsToStagePayload,
|
||
type StageGroup,
|
||
type StageGroups,
|
||
} from "@/roundtable-planning/lib/chain-stages";
|
||
import { getAvatarTypeFor } from "@/roundtable-planning/lib/roundtable-constants";
|
||
import { ChainFlowDiagram } from "@/roundtable-planning/components/ChainFlowDiagram";
|
||
import { AgentDetailSheet } from "@/roundtable-planning/components/AgentDetailSheet";
|
||
|
||
const POOL_PREFIX = "pool::";
|
||
const SEAT_PREFIX = "seat::";
|
||
const STAGE_PREFIX = "stage::";
|
||
const NEWSTAGE_DROPPABLE_ID = "newstage-droppable";
|
||
|
||
// 规范圆角(§4):输入/按钮/tag 2px,卡片/分栏 4px。app 默认 --radius=12px 偏大,
|
||
// 这里用 arbitrary 值精确命中规范。
|
||
const R_CARD = "rounded-[4px]";
|
||
const R_CTRL = "rounded-[2px]";
|
||
// 规范阴影(§3):克制的浅投影,深色下几乎不可见。
|
||
const PANEL_SHADOW = "shadow-[0_1px_2px_rgba(15,23,42,0.05)]";
|
||
|
||
type ActiveDrag =
|
||
| { kind: "pool"; agentId: string; name: string }
|
||
| { kind: "seat"; agentId: string; name: string }
|
||
| null;
|
||
|
||
export default function BusinessChainEditorPage() {
|
||
const navigate = useNavigate();
|
||
const [searchParams] = useSearchParams();
|
||
// 岗位配置只由岗位协同页入口开启,普通圆桌编辑器完全不显示也不依赖该控件。
|
||
// `returnTo` 只接受站内绝对路径,避免把导航带往外部地址。
|
||
const positionConfigMode = searchParams.get("mode") === "position";
|
||
// This is the same directory the administrator edits in “岗位角色配置”.
|
||
// The editor used to read the static POSITION_OPTIONS array below, which
|
||
// meant a newly configured role never appeared in this seat dropdown.
|
||
const { data: configuredPositionRoles = [] } = usePositionRoles({
|
||
refreshOnMountOrFocus: positionConfigMode,
|
||
});
|
||
const positionOptions = useMemo<PositionOption[]>(
|
||
() =>
|
||
configuredPositionRoles.length > 0
|
||
? [...configuredPositionRoles]
|
||
.sort((left, right) => left.sortOrder - right.sortOrder)
|
||
.map((role) => ({
|
||
id: role.id,
|
||
name: role.name,
|
||
description: role.description,
|
||
isIntentPosition: role.roleType === "intent",
|
||
enabled: role.enabled,
|
||
isBuiltin: role.isBuiltin,
|
||
sortOrder: role.sortOrder,
|
||
}))
|
||
: [...POSITION_OPTIONS],
|
||
[configuredPositionRoles],
|
||
);
|
||
// Keep flow previews and historical seat labels on the same live directory.
|
||
useEffect(() => {
|
||
setRuntimePositionOptions(positionOptions);
|
||
}, [positionOptions]);
|
||
const requestedReturnTo = searchParams.get("returnTo");
|
||
const returnPath =
|
||
positionConfigMode && requestedReturnTo?.startsWith("/")
|
||
? requestedReturnTo
|
||
: "/page/workspace/roundtable/planning";
|
||
// 整片脱敏:链条配置页展示文本(链条名/描述/席位名/标题)。可编辑的 input/textarea 不脱敏(Hook 跳过),保证编辑用原文。
|
||
const dzRef = useDesensitizeSubtree<HTMLDivElement>();
|
||
|
||
// ─── 数据 ────────────────────────────────────────────────────────────
|
||
const [pool, setPool] = useState<RecommendCandidate[]>([]);
|
||
const [poolLoading, setPoolLoading] = useState(true);
|
||
// 名称解析专用:一次性拉「全量」智能体(不受左栏搜索/标签过滤影响),用于把链条里
|
||
// 落库的名称快照刷新成最新名称——agent 改名后此页能同步显示。解析不到才回退到快照。
|
||
const [agentLiveById, setAgentLiveById] = useState<
|
||
Map<string, { name: string; description?: string }>
|
||
>(new Map());
|
||
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 [currentChainPublic, setCurrentChainPublic] = useState(false);
|
||
const [currentChainMine, setCurrentChainMine] = useState(true);
|
||
// 管理员:可编辑 / 发布 / 删除任意账号的链条(与「全部链条」筛选配套)。
|
||
const isAdmin = getStoredAuth()?.system_role === "admin";
|
||
const [publishing, setPublishing] = useState(false);
|
||
const [title, setTitle] = useState("");
|
||
const [description, setDescription] = useState("");
|
||
// 写给总控的「编排提示」:告诉总控该怎么派活、做什么(仅分层 DAG 模式注入)。
|
||
const [coordinatorPrompt, setCoordinatorPrompt] = useState("");
|
||
// 默认席位执行模式(快速/思考/专业问答/多智能体)—— 选入研讨时弹窗默认用它。
|
||
const [seatMode, setSeatMode] = useState<SeatMode>(DEFAULT_SEAT_MODE);
|
||
// 链条级「研讨前并行取数」开关(逐条 opt-in,默认关):开 = 选入研讨时研讨前先并行取数再研讨。
|
||
const [gatherFirst, setGatherFirst] = useState<boolean>(false);
|
||
// 分层编排是唯一数据源;落库时展平为 seats + 折叠为 stages。
|
||
const [stageGroups, setStageGroups] = useState<StageGroups>([]);
|
||
const [saving, setSaving] = useState(false);
|
||
|
||
const [activeDrag, setActiveDrag] = useState<ActiveDrag>(null);
|
||
const [dropdownOpen, setDropdownOpen] = useState(false);
|
||
// 两步向导:1=链条编排(双栏拖拽编辑器),2=基本信息(标题/描述/总控提示词 + 流程图预览)。
|
||
const [step, setStep] = useState<1 | 2>(1);
|
||
// 详情抽屉:左栏点卡片本体、右栏点「查看详情」都打开它,展示该智能体详情。
|
||
const [detailAgent, setDetailAgent] = useState<{ id: string; name?: string } | null>(null);
|
||
const showDetail = useCallback((id: string, name?: string) => {
|
||
setDetailAgent({ id, name });
|
||
}, []);
|
||
|
||
const sensors = useSensors(
|
||
useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),
|
||
);
|
||
|
||
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(stageGroups.flatMap((g) => g.seats).map((s) => s.agent_id)),
|
||
[stageGroups],
|
||
);
|
||
const seatCount = useMemo(() => countSeats(stageGroups), [stageGroups]);
|
||
|
||
// 展示用 stageGroups:把每个席位的名称/描述刷新为最新(agent 改名同步),
|
||
// 解析不到再回退落库快照。仅用于显示,编辑操作仍作用于原始 stageGroups。
|
||
const displayStageGroups = useMemo<StageGroups>(
|
||
() =>
|
||
stageGroups.map((g) => ({
|
||
...g,
|
||
seats: g.seats.map((s) => {
|
||
const live = agentLiveById.get(s.agent_id.toLowerCase());
|
||
return live
|
||
? { ...s, name: live.name || s.name, description: live.description ?? s.description }
|
||
: s;
|
||
}),
|
||
})),
|
||
[stageGroups, agentLiveById],
|
||
);
|
||
|
||
// ─── Phase 7 只读流程图预览(§2.2 底部 / §7)──────────────────────────────
|
||
// 步骤二右侧「精美流程图」的数据源:过滤空 stage,带上各阶段目标作为依赖标签。
|
||
const flowStages = useMemo(
|
||
() =>
|
||
displayStageGroups
|
||
.filter((g) => g.seats.length > 0)
|
||
.map((g) => ({ seats: g.seats, goal: g.goal ?? null })),
|
||
[displayStageGroups],
|
||
);
|
||
const hasFlowContent = flowStages.length > 0;
|
||
|
||
// ─── 链条列表(一次性)─────────────────────────────────────────────────
|
||
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]);
|
||
|
||
// ─── 全量名称表(一次性,不受搜索过滤):用于刷新席位的快照名称 ──────────────
|
||
useEffect(() => {
|
||
let cancelled = false;
|
||
void (async () => {
|
||
try {
|
||
const agents = filterRecommendCandidates(await listAgents());
|
||
if (cancelled) return;
|
||
const m = new Map<string, { name: string; description?: string }>();
|
||
// 大小写不敏感:席位落库的 agent_id 与 agent.id 大小写可能不一致(同页 seatNameById
|
||
// 也按 toLowerCase 匹配),统一小写键避免解析失败回退到旧快照名。
|
||
for (const a of agents)
|
||
m.set(a.agent_id.toLowerCase(), { name: a.name, description: a.description });
|
||
setAgentLiveById(m);
|
||
} catch {
|
||
// 静默失败:解析不到就回退到席位的名称快照。
|
||
}
|
||
})();
|
||
return () => {
|
||
cancelled = true;
|
||
};
|
||
}, []);
|
||
|
||
// ─── 链条选择 / 新建 ──────────────────────────────────────────────────
|
||
const loadChain = useCallback((chain: BusinessChain) => {
|
||
setCurrentChainId(chain.id);
|
||
setCurrentChainPublic(chain.isPublic ?? false);
|
||
setCurrentChainMine(chain.isMine !== false);
|
||
setTitle(chain.title);
|
||
setDescription(chain.description ?? "");
|
||
setCoordinatorPrompt(chain.coordinatorPrompt ?? "");
|
||
setSeatMode(chain.seatMode ?? DEFAULT_SEAT_MODE);
|
||
setGatherFirst(chain.gatherFirst ?? false);
|
||
setStageGroups(chainToStageGroups(chain));
|
||
setStep(1);
|
||
}, []);
|
||
|
||
const startNewChain = useCallback(() => {
|
||
setCurrentChainId(null);
|
||
setCurrentChainPublic(false);
|
||
setCurrentChainMine(true);
|
||
setTitle("");
|
||
setDescription("");
|
||
setCoordinatorPrompt("");
|
||
setSeatMode(DEFAULT_SEAT_MODE);
|
||
setGatherFirst(false);
|
||
setStageGroups([]);
|
||
setStep(1);
|
||
}, []);
|
||
|
||
// ─── URL 参数 chainId:从「业务链条」弹窗 / 列表点「设置」进来时自动切到该链条 ──────
|
||
// 按「已应用的 chainId」做闸门(而非「只应用一次」):当 URL 的 chainId 变化时重新加载。
|
||
// 关键修复:此编辑器实例在多次导航间可能不卸载(从弹窗进来时尤甚),用「只应用一次」的
|
||
// 旧闸门会导致第二次打开另一条链条时根本不加载,currentChainId 停在上一条 → 保存打到错误
|
||
// 的 id → 后端 404「已删除」,必须重新登录(整页刷新重建组件)才恢复。改为追踪已应用的 id
|
||
// 后,chainId 变了就重载;同一 chainId 不重复加载,也不覆盖用户在编辑器内的手动切换。
|
||
const appliedChainIdRef = useRef<string | null>(null);
|
||
useEffect(() => {
|
||
const chainId = searchParams.get("chainId");
|
||
if (!chainId) return;
|
||
if (appliedChainIdRef.current === chainId) return; // 这条已加载过,别覆盖用户后续操作
|
||
appliedChainIdRef.current = chainId;
|
||
// 优先用「我的链条」列表里已拉到的对象(省一次请求);不在列表里(管理员从「全部链条」
|
||
// 点设置 / 公共链条 / 自己没有任何链条)则直接按 id 拉取。后端对管理员放开任意链条、
|
||
// 对所有人放开已发布公共链条;拉不到给出提示并保持空白新建态。
|
||
const local = chains.find((c) => c.id === chainId);
|
||
if (local) {
|
||
loadChain(local);
|
||
return;
|
||
}
|
||
void (async () => {
|
||
try {
|
||
const chain = await getChain(chainId);
|
||
if (chain) loadChain(chain);
|
||
else toast.error("该业务链条不存在或无权访问");
|
||
} catch {
|
||
// 静默:取不到就保持当前(空白)状态。
|
||
}
|
||
})();
|
||
}, [chains, searchParams, loadChain]);
|
||
|
||
// ─── 席位增删改(全部委托给 lib/chain-stages 纯函数)────────────────────
|
||
const toChainSeat = useCallback(
|
||
(agentId: string): ChainSeat | null => {
|
||
const agent = poolById.get(agentId);
|
||
if (!agent) return null;
|
||
return { agent_id: agent.agent_id, name: agent.name, description: agent.description };
|
||
},
|
||
[poolById],
|
||
);
|
||
|
||
/** pool 点击加入:末尾追加一个新单席位 Stage(线性追加,默认行为)。 */
|
||
const addAgentAsNewStage = useCallback(
|
||
(agentId: string) => {
|
||
const seat = toChainSeat(agentId);
|
||
if (!seat) return;
|
||
setStageGroups((prev) => {
|
||
if (seatExistsInGroups(prev, agentId)) {
|
||
toast.info(`「${seat.name}」已在链条中`);
|
||
return prev;
|
||
}
|
||
if (countSeats(prev) >= CHAIN_MAX_SEATS) {
|
||
toast.warning(`链条最多 ${CHAIN_MAX_SEATS} 个席位`);
|
||
return prev;
|
||
}
|
||
return addSeatAsNewStage(prev, seat);
|
||
});
|
||
},
|
||
[toChainSeat],
|
||
);
|
||
|
||
const removeSeat = useCallback((agentId: string) => {
|
||
setStageGroups((prev) => removeSeatFromGroups(prev, agentId));
|
||
}, []);
|
||
|
||
const mergeSeatToStage = useCallback((agentId: string, targetStageIdx: number) => {
|
||
setStageGroups((prev) => moveSeatToStage(prev, agentId, targetStageIdx));
|
||
}, []);
|
||
|
||
const setGoal = useCallback((stageIdx: number, goal: string) => {
|
||
setStageGroups((prev) => setStageGoal(prev, stageIdx, goal));
|
||
}, []);
|
||
|
||
// 席位模型覆盖:编辑器席位下拉 onChange(null = 清除,跟随全局)。
|
||
const setSeatModelCb = useCallback((agentId: string, model: string | null) => {
|
||
setStageGroups((prev) => setSeatModel(prev, agentId, model));
|
||
}, []);
|
||
|
||
// 席位「会商技能识别强化」开关:编辑器席位下拉 onChange。
|
||
const setSeatSkillDirectiveCb = useCallback((agentId: string, enabled: boolean) => {
|
||
setStageGroups((prev) => setSeatSkillDirective(prev, agentId, enabled));
|
||
}, []);
|
||
|
||
// 席位「推理深度覆盖」:编辑器席位小图标下拉 onChange(null = 清除,跟随链条级 seatMode)。
|
||
const setSeatModeCb = useCallback((agentId: string, mode: SeatMode | null) => {
|
||
setStageGroups((prev) => setSeatModeOnGroups(prev, agentId, mode));
|
||
}, []);
|
||
|
||
// 岗位协同专用席位归属。保留在同一个 ChainSeat JSON 内,普通会商不会读取它。
|
||
const setSeatPositionCb = useCallback((agentId: string, positionId: PositionId | null) => {
|
||
setStageGroups((prev) =>
|
||
prev.map((group) => ({
|
||
...group,
|
||
seats: group.seats.map((seat) =>
|
||
seat.agent_id === agentId ? { ...seat, position_id: positionId } : seat,
|
||
),
|
||
})),
|
||
);
|
||
}, []);
|
||
|
||
// ── 提示词 AI 优化(总控提示词 / 各 Stage 阶段目标)────────────────────────
|
||
const [optimizingCoordinator, setOptimizingCoordinator] = useState(false);
|
||
const [goalOptimizingIdx, setGoalOptimizingIdx] = useState<number | null>(null);
|
||
|
||
// 把链条当前结构拼成上下文,让模型贴着「这条链有哪些阶段/席位」来优化。
|
||
const buildChainContextText = useCallback((): string => {
|
||
const lines: string[] = [];
|
||
if (title.trim()) lines.push(`链条标题:${title.trim()}`);
|
||
if (description.trim()) lines.push(`链条描述:${description.trim()}`);
|
||
stageGroups.forEach((g, i) => {
|
||
const seatNames = g.seats.map((s) => s.name || s.agent_id).join("、") || "(空)";
|
||
const goal = g.goal?.trim() ? `;阶段目标:${g.goal.trim()}` : "";
|
||
lines.push(`Stage ${i + 1}(${g.seats.length > 1 ? "并行" : "串行"}):${seatNames}${goal}`);
|
||
});
|
||
return lines.join("\n");
|
||
}, [title, description, stageGroups]);
|
||
|
||
const handleOptimizeCoordinatorPrompt = useCallback(async () => {
|
||
if (optimizingCoordinator) return;
|
||
const text = coordinatorPrompt.trim();
|
||
if (!text) {
|
||
toast.warning("请先写一版总控提示词,再让 AI 优化");
|
||
return;
|
||
}
|
||
setOptimizingCoordinator(true);
|
||
try {
|
||
const optimized = await optimizeChainPrompt({
|
||
promptText: text,
|
||
kind: "coordinator",
|
||
context: buildChainContextText(),
|
||
});
|
||
if (optimized.trim()) {
|
||
setCoordinatorPrompt(optimized.trim().slice(0, 4000));
|
||
toast.success("总控提示词已优化,可继续手动调整");
|
||
} else {
|
||
toast.error("优化失败:模型未返回内容");
|
||
}
|
||
} catch (err) {
|
||
toast.error(`优化失败:${err instanceof Error ? err.message : String(err)}`);
|
||
} finally {
|
||
setOptimizingCoordinator(false);
|
||
}
|
||
}, [optimizingCoordinator, coordinatorPrompt, buildChainContextText]);
|
||
|
||
const handleOptimizeStageGoal = useCallback(
|
||
async (stageIdx: number) => {
|
||
if (goalOptimizingIdx !== null) return;
|
||
const goal = stageGroups[stageIdx]?.goal?.trim() ?? "";
|
||
if (!goal) {
|
||
toast.warning("请先写一版本阶段目标,再让 AI 优化");
|
||
return;
|
||
}
|
||
setGoalOptimizingIdx(stageIdx);
|
||
try {
|
||
const optimized = await optimizeChainPrompt({
|
||
promptText: goal,
|
||
kind: "stage_goal",
|
||
context: `${buildChainContextText()}\n本次优化的是 Stage ${stageIdx + 1} 的阶段目标。`,
|
||
});
|
||
if (optimized.trim()) {
|
||
setStageGroups((prev) => setStageGoal(prev, stageIdx, optimized.trim().slice(0, 500)));
|
||
toast.success(`Stage ${stageIdx + 1} 阶段目标已优化`);
|
||
} else {
|
||
toast.error("优化失败:模型未返回内容");
|
||
}
|
||
} catch (err) {
|
||
toast.error(`优化失败:${err instanceof Error ? err.message : String(err)}`);
|
||
} finally {
|
||
setGoalOptimizingIdx(null);
|
||
}
|
||
},
|
||
[goalOptimizingIdx, stageGroups, buildChainContextText],
|
||
);
|
||
|
||
const splitSeat = useCallback((agentId: string) => {
|
||
setStageGroups((prev) => splitSeatToNewStage(prev, agentId));
|
||
}, []);
|
||
|
||
const reorderStage = useCallback((stageIdx: number, dir: -1 | 1) => {
|
||
setStageGroups((prev) => moveStage(prev, stageIdx, dir));
|
||
}, []);
|
||
|
||
const appendEmptyStage = useCallback(() => {
|
||
setStageGroups((prev) => addEmptyStage(prev));
|
||
}, []);
|
||
|
||
const removeStage = useCallback((stageIdx: number) => {
|
||
setStageGroups((prev) => {
|
||
const stage = prev[stageIdx];
|
||
if (stage && stage.seats.length > 0) {
|
||
if (!window.confirm(`删除 Stage ${stageIdx + 1} 会移除其中 ${stage.seats.length} 个席位,确认?`)) {
|
||
return prev;
|
||
}
|
||
}
|
||
return deleteStageGroup(prev, stageIdx);
|
||
});
|
||
}, []);
|
||
|
||
// ─── 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 a = poolById.get(agentId);
|
||
setActiveDrag({ kind: "seat", agentId, name: a?.name ?? agentId });
|
||
}
|
||
},
|
||
[poolById],
|
||
);
|
||
|
||
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;
|
||
|
||
// 解析落点 → 目标 Stage 下标 + 该 Stage 内插入位置;-1 表示「新建 Stage 区」。
|
||
let targetStage = -1;
|
||
let atIndex: number | undefined;
|
||
if (overId === NEWSTAGE_DROPPABLE_ID) {
|
||
targetStage = -1;
|
||
} else if (overId.startsWith(STAGE_PREFIX)) {
|
||
targetStage = Number(overId.slice(STAGE_PREFIX.length));
|
||
} else if (overId.startsWith(SEAT_PREFIX)) {
|
||
const overAgent = overId.slice(SEAT_PREFIX.length);
|
||
targetStage = findStageIndexOfSeat(stageGroups, overAgent);
|
||
atIndex = stageGroups[targetStage]?.seats.findIndex((s) => s.agent_id === overAgent);
|
||
}
|
||
|
||
const toNewStage = overId === NEWSTAGE_DROPPABLE_ID;
|
||
|
||
if (activeId.startsWith(POOL_PREFIX)) {
|
||
const agentId = activeId.slice(POOL_PREFIX.length);
|
||
if (seatIdSet.has(agentId)) return;
|
||
const seat = toChainSeat(agentId);
|
||
if (!seat) return;
|
||
if (seatCount >= CHAIN_MAX_SEATS) {
|
||
toast.warning(`链条最多 ${CHAIN_MAX_SEATS} 个席位`);
|
||
return;
|
||
}
|
||
setStageGroups((prev) =>
|
||
toNewStage || targetStage < 0
|
||
? addSeatAsNewStage(prev, seat)
|
||
: addSeatToStage(prev, seat, targetStage, atIndex),
|
||
);
|
||
return;
|
||
}
|
||
|
||
if (activeId.startsWith(SEAT_PREFIX)) {
|
||
const agentId = activeId.slice(SEAT_PREFIX.length);
|
||
setStageGroups((prev) => {
|
||
if (toNewStage) {
|
||
// 拖到「新建 Stage」区 = 抽出独立成最后一个 Stage。
|
||
const withEmpty = addEmptyStage(prev);
|
||
return moveSeatToStage(withEmpty, agentId, withEmpty.length - 1);
|
||
}
|
||
if (targetStage < 0) return prev;
|
||
return moveSeatToStage(prev, agentId, targetStage, atIndex);
|
||
});
|
||
}
|
||
},
|
||
[stageGroups, seatIdSet, seatCount, toChainSeat],
|
||
);
|
||
|
||
// ─── 保存 / 删除 ──────────────────────────────────────────────────────
|
||
const seatCountInvalid = seatCount < CHAIN_MIN_SEATS || seatCount > CHAIN_MAX_SEATS;
|
||
const hasEmptyStage = stageGroups.some((g) => g.seats.length === 0);
|
||
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 {
|
||
// 展平 + 折叠:seats 用候选池最新 name/description 覆盖快照;stages 在「全单席位且无
|
||
// 目标」时折叠为 null(线性链),有并行或填了「本阶段目标」时落显式分层。
|
||
const flat = stageGroupsToSeats(stageGroups);
|
||
const payloadSeats = flat.map((s) => {
|
||
// 优先全量名称表(不受搜索过滤)→ 候选池 → 落库快照,保证改名后保存写入最新名。
|
||
const live = agentLiveById.get(s.agent_id.toLowerCase()) ?? poolById.get(s.agent_id);
|
||
return {
|
||
agent_id: s.agent_id,
|
||
name: live?.name ?? s.name,
|
||
description: live?.description ?? s.description ?? "",
|
||
// 席位模型覆盖:随席位一起落库(空 → null = 跟随全局)。
|
||
model: s.model ?? null,
|
||
// 席位「会商技能识别强化」开关:随席位一起落库(缺省 = false 关)。
|
||
seat_skill_directive: s.seat_skill_directive ?? false,
|
||
// 席位「推理深度覆盖」:随席位一起落库(null = 跟随链条级 seatMode)。
|
||
seat_mode: s.seat_mode ?? null,
|
||
// 岗位协同专用岗位归属:普通圆桌忽略,但保存时必须原样保留。
|
||
position_id: s.position_id ?? null,
|
||
};
|
||
});
|
||
// 总控编排提示:trim 后空串落 null(清空),与后端「空=不注入」一致。
|
||
const coordPrompt = coordinatorPrompt.trim() || null;
|
||
// 填了「总控编排提示」也强制落显式分层 —— 该提示仅 dag 模式注入,否则纯线性链里被静默忽略。
|
||
const forceExplicit = coordPrompt !== null;
|
||
const stages = stageGroupsToStagePayload(stageGroups, forceExplicit);
|
||
// 每阶段目标,与 stages 同下标对齐、同步折叠(stages 为 null 时这里也是 null)。
|
||
const stageGoals = stageGroupsToStageGoals(stageGroups, forceExplicit);
|
||
if (currentChainId) {
|
||
const updated = await updateChain(currentChainId, {
|
||
title: title.trim(),
|
||
description: description.trim() || undefined,
|
||
seats: payloadSeats,
|
||
stages,
|
||
stageGoals,
|
||
coordinatorPrompt: coordPrompt,
|
||
seatMode,
|
||
gatherFirst,
|
||
});
|
||
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,
|
||
stages,
|
||
stageGoals,
|
||
coordinatorPrompt: coordPrompt,
|
||
seatMode,
|
||
gatherFirst,
|
||
});
|
||
setCurrentChainId(created.id);
|
||
toast.success("已创建业务链条");
|
||
}
|
||
await refreshChains();
|
||
} catch (err) {
|
||
toast.error(`保存失败:${err instanceof Error ? err.message : String(err)}`);
|
||
} finally {
|
||
setSaving(false);
|
||
}
|
||
}, [
|
||
title,
|
||
description,
|
||
coordinatorPrompt,
|
||
seatMode,
|
||
gatherFirst,
|
||
stageGroups,
|
||
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]);
|
||
|
||
// 发布 / 取消发布:把当前链条设为公共(所有账号可见 / 选用)或收回。
|
||
const handleTogglePublish = useCallback(async () => {
|
||
if (!currentChainId) {
|
||
toast.warning("请先保存链条再发布");
|
||
return;
|
||
}
|
||
const next = !currentChainPublic;
|
||
setPublishing(true);
|
||
try {
|
||
const updated = await setChainPublic(currentChainId, next);
|
||
if (!updated) {
|
||
toast.error("链条已不存在,可能被删除");
|
||
startNewChain();
|
||
await refreshChains();
|
||
return;
|
||
}
|
||
setCurrentChainPublic(updated.isPublic ?? next);
|
||
toast.success(next ? "已发布为公共,所有账号都能查看 / 选用" : "已取消发布");
|
||
await refreshChains();
|
||
} catch (err) {
|
||
toast.error(`${next ? "发布" : "取消发布"}失败:${err instanceof Error ? err.message : String(err)}`);
|
||
} finally {
|
||
setPublishing(false);
|
||
}
|
||
}, [currentChainId, currentChainPublic, startNewChain, refreshChains]);
|
||
|
||
// ─── Render ──────────────────────────────────────────────────────────
|
||
const triggerLabel = currentChainId ? title || "未命名链条" : "+ 新建链条…";
|
||
|
||
// 步骤一左侧「基本信息」表单(标题 / 描述 / 总控提示词,描述与总控均为多行文本)。
|
||
// 抽成元素:无编排内容时居中单列,有内容时与右侧流程图并排(左列)。
|
||
// 样式按设计稿「配置参数面板」还原:label 在上、圆角输入;按钮配色沿用现有 primary。
|
||
const FIELD =
|
||
"w-full rounded-md border border-border bg-muted/30 px-3.5 py-2 text-sm text-foreground outline-none transition placeholder:text-muted-foreground/55 hover:bg-muted/50 focus:border-primary focus:bg-card";
|
||
const basicInfoForm = (
|
||
<div className="space-y-5">
|
||
{/* 面板头:配置参数面板 / 实时编译中 */}
|
||
<div className="flex items-center justify-between">
|
||
<span className="flex select-none items-center gap-1.5 text-[10px] font-bold uppercase tracking-wider text-muted-foreground">
|
||
<Sliders className="size-3" />
|
||
配置参数面板
|
||
</span>
|
||
<span className="flex select-none items-center gap-1 text-[11px] font-medium text-primary">
|
||
实时编译中
|
||
<span className="ml-1 size-1.5 animate-pulse rounded-full bg-emerald-500" />
|
||
</span>
|
||
</div>
|
||
|
||
{/* 标题 */}
|
||
<div className="space-y-1.5">
|
||
<label htmlFor="chain-title" className="flex items-center gap-1 text-xs font-semibold text-foreground">
|
||
标题
|
||
<span className="text-destructive">*</span>
|
||
</label>
|
||
<input
|
||
id="chain-title"
|
||
type="text"
|
||
value={title}
|
||
onChange={(e) => setTitle(e.target.value)}
|
||
placeholder="如:应急方案三段链"
|
||
maxLength={120}
|
||
className={cn(FIELD, "font-medium")}
|
||
/>
|
||
</div>
|
||
|
||
{/* 描述 */}
|
||
<div className="space-y-1.5">
|
||
<label htmlFor="chain-desc" className="text-xs font-semibold text-foreground">
|
||
描述
|
||
</label>
|
||
<textarea
|
||
id="chain-desc"
|
||
value={description}
|
||
onChange={(e) => setDescription(e.target.value)}
|
||
maxLength={2000}
|
||
rows={2}
|
||
placeholder="链条用途说明:解决什么问题、适用什么场景(可选)…"
|
||
className={cn(FIELD, "resize-none leading-relaxed")}
|
||
/>
|
||
</div>
|
||
|
||
{/* 默认执行模式:选入研讨时弹窗默认用它(仍可临时改)。 */}
|
||
<div className="space-y-2">
|
||
<label className="flex items-center gap-1 text-xs font-semibold text-foreground">
|
||
默认执行模式
|
||
<span className="text-[10px] font-normal text-muted-foreground">
|
||
(选入研讨时默认用它,进研讨前仍可临时切换)
|
||
</span>
|
||
</label>
|
||
<div className="inline-flex flex-wrap gap-0.5 rounded-lg border border-border bg-muted/40 p-0.5 text-xs font-medium">
|
||
{SEAT_MODE_OPTIONS.map((opt) => (
|
||
<button
|
||
key={opt.value}
|
||
type="button"
|
||
onClick={() => setSeatMode(opt.value)}
|
||
title={opt.description}
|
||
className={cn(
|
||
"rounded-md px-2.5 py-1 transition-colors",
|
||
seatMode === opt.value
|
||
? "bg-card text-primary shadow-sm"
|
||
: "text-muted-foreground hover:text-foreground",
|
||
)}
|
||
>
|
||
{opt.label}
|
||
</button>
|
||
))}
|
||
</div>
|
||
<p className="text-[11px] leading-relaxed text-muted-foreground">
|
||
{SEAT_MODE_OPTIONS.find((o) => o.value === seatMode)?.description}
|
||
</p>
|
||
</div>
|
||
|
||
{/* 研讨前并行取数:逐条 opt-in 的提速开关(默认关)。 */}
|
||
<div className={cn("flex items-start justify-between gap-3 border border-border bg-muted/30 p-3", R_CARD)}>
|
||
<div className="space-y-1">
|
||
<label className="flex items-center gap-1 text-xs font-semibold text-foreground">
|
||
<Gauge className="size-3.5 text-primary" />
|
||
研讨前并行取数(提速)
|
||
</label>
|
||
<p className="text-[11px] leading-relaxed text-muted-foreground">
|
||
开启后,选入研讨时会**先并行跑一轮「只取数」**:各席位同时用技能把相关信息收集回来(不研讨),
|
||
产出作为共享资料注入后续研讨轮。把最慢的技能检索前置、并行做一次,给(尤其按链条顺序串行的)
|
||
研讨段大幅提速;研讨阶段席位仍可按需再调技能。
|
||
</p>
|
||
</div>
|
||
<Switch checked={gatherFirst} onCheckedChange={setGatherFirst} className="mt-0.5 shrink-0" />
|
||
</div>
|
||
|
||
{/* 总控提示词:label + AI 优化(配色沿用现有 primary)+ 大号等宽编辑区 */}
|
||
<div className="space-y-2">
|
||
<div className="flex items-center justify-between gap-2">
|
||
<label htmlFor="chain-coord" className="flex items-center gap-1 text-xs font-semibold text-foreground">
|
||
总控提示词
|
||
<span className="text-[10px] font-normal text-muted-foreground">(写给总控怎么分发、汇总)</span>
|
||
</label>
|
||
<button
|
||
type="button"
|
||
onClick={handleOptimizeCoordinatorPrompt}
|
||
disabled={optimizingCoordinator || !coordinatorPrompt.trim()}
|
||
title={
|
||
coordinatorPrompt.trim()
|
||
? "让 AI 按链条结构重写这段提示词(更明确的派活方式、交付口径与总结要求)"
|
||
: "先写一版提示词,AI 才能在它基础上优化"
|
||
}
|
||
className={cn(
|
||
"inline-flex shrink-0 items-center gap-1 border border-primary/30 bg-primary/5 px-2.5 py-1 text-[11px] font-semibold text-primary transition hover:bg-primary/10 active:scale-[0.97] disabled:cursor-not-allowed disabled:opacity-50",
|
||
R_CTRL,
|
||
)}
|
||
>
|
||
{optimizingCoordinator ? (
|
||
<Loader2 className="size-3 animate-spin" />
|
||
) : (
|
||
<Wand2 className="size-3" />
|
||
)}
|
||
{optimizingCoordinator ? "优化中…" : "AI 优化提示词"}
|
||
</button>
|
||
</div>
|
||
|
||
<div className="relative">
|
||
<textarea
|
||
id="chain-coord"
|
||
value={coordinatorPrompt}
|
||
onChange={(e) => setCoordinatorPrompt(e.target.value)}
|
||
maxLength={4000}
|
||
placeholder="例如:你是本次研讨的总控。请严格按阶段顺序派活,每阶段先明确产出目标再分配;要求各席位的交付聚焦本职、显式承接上一阶段结论;最终阶段做综合收口,给出可落地的全案。"
|
||
className={cn(
|
||
FIELD,
|
||
"h-[260px] resize-y p-4 font-mono text-[12px] leading-relaxed",
|
||
)}
|
||
/>
|
||
<div className="pointer-events-none absolute bottom-2 right-2 rounded-md border border-border bg-card/90 px-2 py-1 font-mono text-[9px] text-muted-foreground">
|
||
Markdown 格式可用
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
{/* 提示:分层并行调度规则 */}
|
||
<div className={cn("space-y-2 border border-primary/15 bg-primary/[0.05] p-4", R_CARD)}>
|
||
<div className="flex items-center gap-1.5 text-xs font-semibold text-primary">
|
||
<Info className="size-4" />
|
||
分层并行调度规则
|
||
</div>
|
||
<p className="text-[11px] leading-relaxed text-muted-foreground">
|
||
处于同一<strong className="font-semibold text-foreground">阶段(Stage)</strong>的席位会被并行下发任务以压缩时延;阶段之间串行,由总控在下一阶段承接并合并上一阶段产出。
|
||
</p>
|
||
</div>
|
||
</div>
|
||
);
|
||
|
||
return (
|
||
<div ref={dzRef} className="flex h-full min-h-0 flex-col bg-muted/40 text-foreground">
|
||
{/* 顶栏 */}
|
||
<header className="flex shrink-0 flex-wrap items-center gap-3 border-b border-border bg-card px-6 py-3">
|
||
<button
|
||
type="button"
|
||
onClick={() => navigate(returnPath)}
|
||
className={cn(
|
||
"flex items-center gap-1.5 border border-border bg-card px-3 py-1.5 text-sm font-medium text-muted-foreground transition hover:bg-muted hover:text-foreground active:scale-[0.98]",
|
||
R_CTRL,
|
||
)}
|
||
>
|
||
<ArrowLeft className="size-4" />
|
||
{positionConfigMode ? "返回岗位协同" : "返回圆桌"}
|
||
</button>
|
||
|
||
{/* 品牌标识 */}
|
||
<div className="flex items-center gap-2.5">
|
||
<div
|
||
className={cn(
|
||
"flex size-8 select-none items-center justify-center bg-gradient-to-tr from-primary to-primary/40 text-sm font-bold text-primary-foreground shadow-sm",
|
||
R_CARD,
|
||
)}
|
||
>
|
||
链
|
||
</div>
|
||
<div className="leading-tight">
|
||
<div className="text-base font-bold text-foreground">业务链条配置</div>
|
||
<div className="text-[11px] font-medium tracking-wide text-muted-foreground">
|
||
分层编排:同层并行 · 层间串行
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
{positionConfigMode && (
|
||
<span
|
||
className={cn(
|
||
"border border-primary/30 bg-primary/10 px-2 py-1 text-[11px] font-semibold text-primary",
|
||
R_CTRL,
|
||
)}
|
||
>
|
||
岗位协同配置
|
||
</span>
|
||
)}
|
||
|
||
{/* 链条选择下拉 */}
|
||
<div className="relative ml-2">
|
||
<button
|
||
type="button"
|
||
onClick={() => setDropdownOpen((o) => !o)}
|
||
className={cn(
|
||
"flex min-w-[150px] items-center justify-between gap-3 border border-border bg-card px-3 py-1.5 text-sm text-foreground transition hover:border-primary/50 focus:outline-none focus:ring-1 focus:ring-primary/30",
|
||
R_CTRL,
|
||
)}
|
||
>
|
||
<span className="truncate font-medium">{triggerLabel}</span>
|
||
<ChevronDown className="size-4 text-muted-foreground" />
|
||
</button>
|
||
|
||
{dropdownOpen && (
|
||
<>
|
||
<div className="fixed inset-0 z-30" onClick={() => setDropdownOpen(false)} />
|
||
<div
|
||
className={cn(
|
||
"absolute left-0 z-40 mt-1 max-h-[280px] w-[260px] overflow-y-auto border border-border bg-card py-1 shadow-lg",
|
||
R_CARD,
|
||
)}
|
||
>
|
||
<div className="border-b border-border px-3 py-1 text-xs font-semibold text-muted-foreground">
|
||
切换已有链条
|
||
</div>
|
||
{chains.length === 0 ? (
|
||
<div className="px-3 py-2 text-xs text-muted-foreground">暂无已保存链条</div>
|
||
) : (
|
||
chains.map((c) => (
|
||
<button
|
||
key={c.id}
|
||
type="button"
|
||
onClick={() => {
|
||
loadChain(c);
|
||
setDropdownOpen(false);
|
||
}}
|
||
className={cn(
|
||
"flex w-full items-center justify-between px-3 py-2 text-xs transition hover:bg-primary/5",
|
||
c.id === currentChainId
|
||
? "bg-primary/5 font-bold text-primary"
|
||
: "text-muted-foreground",
|
||
)}
|
||
>
|
||
<span className="truncate">
|
||
{c.title || "未命名链条"}({c.seats.length} 席{c.stages?.length ? " · 分层" : ""})
|
||
</span>
|
||
{c.id === currentChainId && (
|
||
<span className={cn("ml-2 shrink-0 bg-primary/15 px-1.5 py-0.5 text-[10px] text-primary", R_CTRL)}>
|
||
当前
|
||
</span>
|
||
)}
|
||
</button>
|
||
))
|
||
)}
|
||
<div className="mt-1 border-t border-border pt-1">
|
||
<button
|
||
type="button"
|
||
onClick={() => {
|
||
startNewChain();
|
||
setDropdownOpen(false);
|
||
}}
|
||
className="flex w-full items-center gap-1.5 px-3 py-2 text-xs font-medium text-primary transition hover:bg-primary/5"
|
||
>
|
||
<Plus className="size-3.5" />
|
||
新建另一条链路
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</>
|
||
)}
|
||
</div>
|
||
|
||
{/* 快捷新建 */}
|
||
<button
|
||
type="button"
|
||
onClick={startNewChain}
|
||
className={cn(
|
||
"flex items-center gap-1.5 border border-border bg-card px-3 py-1.5 text-sm text-muted-foreground transition hover:bg-muted hover:text-foreground active:scale-[0.98]",
|
||
R_CTRL,
|
||
)}
|
||
>
|
||
<Plus className="size-4" />
|
||
新建
|
||
</button>
|
||
|
||
{/* 右侧操作 */}
|
||
<div className="ml-auto flex items-center gap-2">
|
||
{/* 发布 / 取消发布:已保存且本人所有(或管理员)的链条。发布后所有账号可在「公共」筛选查看 / 选用。 */}
|
||
{currentChainId && (currentChainMine || isAdmin) && (
|
||
<button
|
||
type="button"
|
||
onClick={handleTogglePublish}
|
||
disabled={publishing}
|
||
title={currentChainPublic ? "已发布为公共,点击收回为私有" : "发布为公共,所有账号都能查看 / 选用"}
|
||
className={cn(
|
||
"flex items-center gap-1.5 border px-3 py-1.5 text-sm font-medium transition active:scale-[0.98] disabled:cursor-not-allowed disabled:opacity-60",
|
||
currentChainPublic
|
||
? "border-emerald-400/50 bg-emerald-500/10 text-emerald-600 hover:bg-emerald-500/15 dark:text-emerald-400"
|
||
: "border-border bg-card text-muted-foreground hover:bg-muted hover:text-foreground",
|
||
R_CTRL,
|
||
)}
|
||
>
|
||
{publishing ? (
|
||
<Loader2 className="size-4 animate-spin" />
|
||
) : (
|
||
<Globe className="size-4" />
|
||
)}
|
||
{currentChainPublic ? "已发布" : "发布"}
|
||
</button>
|
||
)}
|
||
<button
|
||
type="button"
|
||
onClick={handleDelete}
|
||
className={cn(
|
||
"flex items-center gap-1.5 border border-primary/30 bg-card px-3 py-1.5 text-sm font-medium text-primary transition hover:bg-primary/5 active:scale-[0.98]",
|
||
R_CTRL,
|
||
)}
|
||
>
|
||
<Trash2 className="size-4" />
|
||
删除
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={handleSave}
|
||
disabled={!canSave}
|
||
className={cn(
|
||
"flex items-center gap-1.5 bg-primary px-4 py-1.5 text-sm font-medium text-primary-foreground shadow-sm transition hover:bg-primary/90 active:scale-[0.98] disabled:cursor-not-allowed disabled:opacity-50",
|
||
R_CTRL,
|
||
)}
|
||
>
|
||
{saving ? <Loader2 className="size-4 animate-spin" /> : <Save className="size-4" />}
|
||
保存
|
||
</button>
|
||
</div>
|
||
</header>
|
||
|
||
{/* 步骤导航:① 基本信息 → ② 链条编排(点击可切换)。 */}
|
||
<nav className="flex shrink-0 items-center justify-center gap-3 border-b border-border bg-card px-6 py-2.5">
|
||
{([
|
||
{ n: 1 as const, label: "链条编排" },
|
||
{ n: 2 as const, label: "基本信息" },
|
||
]).map((s, i) => (
|
||
<Fragment key={s.n}>
|
||
{i > 0 && <span className="h-px w-10 bg-border" />}
|
||
<button
|
||
type="button"
|
||
onClick={() => setStep(s.n)}
|
||
className={cn(
|
||
"flex items-center gap-2 border px-3 py-1 text-sm font-medium transition",
|
||
R_CTRL,
|
||
step === s.n
|
||
? "border-primary bg-primary/10 text-primary"
|
||
: "border-border bg-card text-muted-foreground hover:text-foreground",
|
||
)}
|
||
>
|
||
<span
|
||
className={cn(
|
||
"flex size-5 items-center justify-center rounded-full text-[11px] font-bold tabular-nums",
|
||
step === s.n ? "bg-primary text-primary-foreground" : "bg-muted text-muted-foreground",
|
||
)}
|
||
>
|
||
{s.n}
|
||
</span>
|
||
{s.label}
|
||
</button>
|
||
</Fragment>
|
||
))}
|
||
</nav>
|
||
|
||
{/* 步骤二:左=基本信息,右=精美流程图预览(有编排内容时)。无内容则居中单列。 */}
|
||
{step === 2 && (
|
||
<div className="flex min-h-0 flex-1 overflow-hidden">
|
||
{hasFlowContent ? (
|
||
<>
|
||
{/* 左:基本信息(这几个描述信息) */}
|
||
<section className="w-[400px] shrink-0 overflow-y-auto border-r border-border bg-card px-6 py-5">
|
||
{basicInfoForm}
|
||
</section>
|
||
{/* 右:编排流程图(直角连线 / 点节点看详情 / 连线显示依赖 / 缩放平移全屏) */}
|
||
<section className="relative min-w-0 flex-1">
|
||
<ChainFlowDiagram
|
||
stages={flowStages}
|
||
onNodeClick={showDetail}
|
||
className="h-full w-full"
|
||
/>
|
||
</section>
|
||
</>
|
||
) : (
|
||
<div className="mx-auto w-full max-w-3xl overflow-y-auto px-6 py-6">
|
||
{basicInfoForm}
|
||
<p className="mt-4 text-center text-xs text-muted-foreground">
|
||
还没有编排内容。点击上方「① 链条编排」去配置链条,保存后这里会显示流程图预览。
|
||
</p>
|
||
</div>
|
||
)}
|
||
</div>
|
||
)}
|
||
|
||
{/* 双栏拖拽编辑器(步骤一)*/}
|
||
{step === 1 && (
|
||
<DndContext
|
||
sensors={sensors}
|
||
collisionDetection={closestCenter}
|
||
onDragStart={onDragStart}
|
||
onDragEnd={onDragEnd}
|
||
>
|
||
<main className="grid min-h-0 flex-1 grid-cols-1 gap-6 overflow-hidden px-6 py-6 lg:grid-cols-12">
|
||
{/* 左栏:候选智能体 */}
|
||
<section
|
||
className={cn(
|
||
"flex min-h-0 flex-col overflow-hidden border border-border bg-card lg:col-span-4",
|
||
R_CARD,
|
||
PANEL_SHADOW,
|
||
)}
|
||
>
|
||
<div className="flex shrink-0 items-center justify-between border-b border-border bg-muted/40 px-5 py-4">
|
||
<div className="flex items-center gap-2">
|
||
<span className={cn("flex size-5 items-center justify-center bg-primary/10", R_CTRL)}>
|
||
<UserPlus className="size-3.5 text-primary" />
|
||
</span>
|
||
<h2 className="text-sm font-bold tracking-wide text-foreground">候选智能体</h2>
|
||
<span
|
||
className={cn(
|
||
"min-w-[20px] border border-primary/30 bg-primary/10 px-2 py-0.5 text-center text-xs font-bold text-primary tabular-nums",
|
||
"rounded-full",
|
||
)}
|
||
>
|
||
{pool.length}
|
||
</span>
|
||
</div>
|
||
<span className="text-[11px] font-medium text-muted-foreground">拖手柄到右侧 / 点卡片看详情</span>
|
||
</div>
|
||
|
||
<div className="shrink-0 border-b border-border px-4 py-3">
|
||
<TagSearchBar
|
||
targetType="agent"
|
||
onSearchChange={setSearch}
|
||
tagIds={filterTagIds}
|
||
onTagIdsChange={setFilterTagIds}
|
||
/>
|
||
</div>
|
||
|
||
<div className="min-h-0 flex-1 space-y-2.5 overflow-y-auto p-4">
|
||
{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-12 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={() => addAgentAsNewStage(a.agent_id)}
|
||
onShowDetail={() => showDetail(a.agent_id, a.name)}
|
||
/>
|
||
))
|
||
)}
|
||
</div>
|
||
</section>
|
||
|
||
{/* 右栏:分层 Stage(用展示版,名称已按实时 agent 刷新) */}
|
||
<StagesColumn
|
||
stageGroups={displayStageGroups}
|
||
seatCount={seatCount}
|
||
seatCountInvalid={seatCountInvalid}
|
||
hasEmptyStage={hasEmptyStage}
|
||
onAddStage={appendEmptyStage}
|
||
onRemoveStage={removeStage}
|
||
onReorderStage={reorderStage}
|
||
onRemoveSeat={removeSeat}
|
||
onMergeSeat={mergeSeatToStage}
|
||
onSplitSeat={splitSeat}
|
||
onSeatModelChange={setSeatModelCb}
|
||
onSeatSkillDirectiveChange={setSeatSkillDirectiveCb}
|
||
onSeatModeChange={setSeatModeCb}
|
||
positionConfigMode={positionConfigMode}
|
||
positionOptions={positionOptions}
|
||
onSeatPositionChange={setSeatPositionCb}
|
||
onStageGoalChange={setGoal}
|
||
goalOptimizingIdx={goalOptimizingIdx}
|
||
onOptimizeGoal={handleOptimizeStageGoal}
|
||
onSeatDetail={showDetail}
|
||
/>
|
||
</main>
|
||
|
||
<DragOverlay>
|
||
{activeDrag ? (
|
||
<div
|
||
className={cn(
|
||
"flex items-center gap-2 border border-primary/50 bg-card px-3 py-2 text-sm font-medium text-foreground shadow-[0_4px_12px_rgba(15,23,42,0.12)]",
|
||
R_CTRL,
|
||
)}
|
||
>
|
||
<GripVertical className="size-4 text-primary" />
|
||
{activeDrag.name}
|
||
</div>
|
||
) : null}
|
||
</DragOverlay>
|
||
</DndContext>
|
||
)}
|
||
|
||
{/* Phase 7:分层 DAG 只读流程图预览(§2.2 底部)。空编排时不渲染。
|
||
底栏入口按钮直接进入第二步「基本信息」,右侧展示完整流程图。 */}
|
||
{step === 1 && hasFlowContent && (
|
||
<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>
|
||
</span>
|
||
<button
|
||
type="button"
|
||
onClick={() => setStep(2)}
|
||
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>
|
||
)}
|
||
|
||
{/* 智能体详情抽屉(左栏卡片 / 右栏席位共用) */}
|
||
<AgentDetailSheet
|
||
agentId={detailAgent?.id ?? null}
|
||
fallbackName={detailAgent?.name}
|
||
open={detailAgent !== null}
|
||
onOpenChange={(o) => {
|
||
if (!o) setDetailAgent(null);
|
||
}}
|
||
/>
|
||
|
||
{/* 页脚(步骤一):分层编排说明。步骤切换走顶部步骤导航。 */}
|
||
{step === 1 && (
|
||
<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 之间串行。全单席位 = 线性链。保存后自动同步至圆桌。
|
||
</footer>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
// ── 左栏候选卡片(draggable)─────────────────────────────────────────────
|
||
|
||
function PoolAgentCard({
|
||
agent,
|
||
inChain,
|
||
onAdd,
|
||
onShowDetail,
|
||
}: {
|
||
agent: RecommendCandidate;
|
||
inChain: boolean;
|
||
onAdd: () => void;
|
||
onShowDetail: () => void;
|
||
}) {
|
||
// 只把拖拽 listeners 挂到左侧手柄上 —— 点手柄才拖动;点卡片本体打开详情抽屉。
|
||
const { attributes, listeners, setNodeRef, isDragging } = useDraggable({
|
||
id: POOL_PREFIX + agent.agent_id,
|
||
disabled: inChain,
|
||
});
|
||
return (
|
||
<div
|
||
ref={setNodeRef}
|
||
onClick={onShowDetail}
|
||
className={cn(
|
||
"group relative flex items-stretch overflow-hidden border transition-all duration-150",
|
||
R_CARD,
|
||
inChain
|
||
? "cursor-pointer border-primary/30 bg-primary/[0.03]"
|
||
: "cursor-pointer border-border bg-card hover:border-primary hover:shadow-[0_2px_8px_rgba(0,0,0,0.04)]",
|
||
isDragging && "opacity-30",
|
||
)}
|
||
{...attributes}
|
||
>
|
||
{/* 拖拽手柄(与右栏席位一致):点手柄才开始拖动;已加入则禁用拖拽。 */}
|
||
<button
|
||
type="button"
|
||
onClick={(e) => e.stopPropagation()}
|
||
className={cn(
|
||
"flex w-7 shrink-0 items-center justify-center border-r border-border bg-muted/40 text-muted-foreground/60 transition-colors",
|
||
inChain
|
||
? "cursor-not-allowed opacity-40"
|
||
: "cursor-grab touch-none hover:text-foreground active:cursor-grabbing",
|
||
)}
|
||
title={inChain ? "已在链条中" : "拖动到右侧加入 / 排序"}
|
||
{...(inChain ? {} : listeners)}
|
||
>
|
||
<GripVertical className="size-3.5" />
|
||
</button>
|
||
|
||
<div className="flex min-w-0 flex-1 items-start gap-3 p-3 pr-2">
|
||
<div
|
||
className={cn(
|
||
"mt-0.5 flex size-6 shrink-0 items-center justify-center transition-colors",
|
||
R_CARD,
|
||
inChain
|
||
? "bg-primary/10 text-primary"
|
||
: "bg-muted text-muted-foreground group-hover:bg-primary/10 group-hover:text-primary",
|
||
)}
|
||
>
|
||
<Bot className="size-3.5" />
|
||
</div>
|
||
|
||
<div className="min-w-0 flex-1">
|
||
<div className="truncate text-xs font-bold leading-tight text-foreground transition-colors group-hover:text-primary">
|
||
{agent.name || agent.agent_id}
|
||
</div>
|
||
{agent.description && (
|
||
<div className="mt-1 line-clamp-2 text-[11px] font-medium leading-normal text-muted-foreground">
|
||
{agent.description}
|
||
</div>
|
||
)}
|
||
</div>
|
||
</div>
|
||
|
||
{/* 加入按钮:只有点它才加入(点卡片其它区域是看详情)。已加入显示「已加入」。 */}
|
||
<div className="flex shrink-0 items-center pr-3 pl-1 select-none">
|
||
{inChain ? (
|
||
<span className={cn("border border-primary/30 bg-primary/10 px-2 py-1 text-[10px] font-bold text-primary", R_CTRL)}>
|
||
已加入
|
||
</span>
|
||
) : (
|
||
<button
|
||
type="button"
|
||
onClick={(e) => {
|
||
e.stopPropagation();
|
||
onAdd();
|
||
}}
|
||
className={cn(
|
||
"inline-flex items-center gap-1 border border-primary/30 bg-primary/5 px-2 py-1 text-[10px] font-semibold text-primary transition-all hover:bg-primary/10",
|
||
R_CTRL,
|
||
)}
|
||
>
|
||
<Plus className="size-3" />
|
||
加入
|
||
</button>
|
||
)}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
// ── 右栏(分层 Stage 容器)───────────────────────────────────────────────
|
||
|
||
function StagesColumn({
|
||
stageGroups,
|
||
seatCount,
|
||
seatCountInvalid,
|
||
hasEmptyStage,
|
||
onAddStage,
|
||
onRemoveStage,
|
||
onReorderStage,
|
||
onRemoveSeat,
|
||
onMergeSeat,
|
||
onSplitSeat,
|
||
onSeatModelChange,
|
||
onSeatSkillDirectiveChange,
|
||
onSeatModeChange,
|
||
positionConfigMode,
|
||
positionOptions,
|
||
onSeatPositionChange,
|
||
onStageGoalChange,
|
||
goalOptimizingIdx,
|
||
onOptimizeGoal,
|
||
onSeatDetail,
|
||
}: {
|
||
stageGroups: StageGroups;
|
||
seatCount: number;
|
||
seatCountInvalid: boolean;
|
||
hasEmptyStage: boolean;
|
||
onAddStage: () => void;
|
||
onRemoveStage: (stageIdx: number) => void;
|
||
onReorderStage: (stageIdx: number, dir: -1 | 1) => void;
|
||
onRemoveSeat: (agentId: string) => void;
|
||
onMergeSeat: (agentId: string, targetStageIdx: number) => void;
|
||
onSplitSeat: (agentId: string) => void;
|
||
onSeatModelChange: (agentId: string, model: string | null) => void;
|
||
onSeatSkillDirectiveChange: (agentId: string, enabled: boolean) => void;
|
||
onSeatModeChange: (agentId: string, mode: SeatMode | null) => void;
|
||
/** 仅岗位协同入口启用;普通圆桌编辑器不显示岗位控件。 */
|
||
positionConfigMode: boolean;
|
||
/** Live directory from the administrator's position-role configuration. */
|
||
positionOptions: readonly PositionOption[];
|
||
onSeatPositionChange: (agentId: string, positionId: PositionId | null) => void;
|
||
onStageGoalChange: (stageIdx: number, goal: string) => void;
|
||
/** 正在 AI 优化阶段目标的 stage 下标(null = 没有进行中的优化)。 */
|
||
goalOptimizingIdx: number | null;
|
||
onOptimizeGoal: (stageIdx: number) => void;
|
||
onSeatDetail: (agentId: string, name?: string) => void;
|
||
}) {
|
||
// 跨 Stage 的全局序号(头像编号):每个 Stage 起始累加。
|
||
const stageStartIndex = useMemo(() => {
|
||
const out: number[] = [];
|
||
let acc = 0;
|
||
for (const g of stageGroups) {
|
||
out.push(acc);
|
||
acc += g.seats.length;
|
||
}
|
||
return out;
|
||
}, [stageGroups]);
|
||
// 是否含并行 stage → 决定提示「目标仅对含并行的分层链条生效」。
|
||
const hasParallelStage = stageGroups.some((g) => g.seats.length > 1);
|
||
|
||
return (
|
||
<section
|
||
className={cn(
|
||
"flex min-h-0 flex-col overflow-hidden border border-border bg-card lg:col-span-8",
|
||
R_CARD,
|
||
PANEL_SHADOW,
|
||
)}
|
||
>
|
||
<div className="flex shrink-0 items-center justify-between border-b border-border bg-muted/40 px-5 py-4">
|
||
<div className="flex items-center gap-2">
|
||
<span className={cn("flex size-5 items-center justify-center bg-primary/10", R_CTRL)}>
|
||
<Layers className="size-3.5 text-primary" />
|
||
</span>
|
||
<h2 className="text-sm font-bold tracking-wide text-foreground">链条编排</h2>
|
||
<span className={cn("border border-border bg-muted px-2 py-0.5 text-[10px] font-bold text-muted-foreground", R_CTRL)}>
|
||
同层并行 · 层间串行
|
||
</span>
|
||
{positionConfigMode && (
|
||
<span className={cn("border border-primary/25 bg-primary/5 px-2 py-0.5 text-[10px] font-semibold text-primary", R_CTRL)}>
|
||
为每个席位指定岗位
|
||
</span>
|
||
)}
|
||
</div>
|
||
|
||
<div className="flex select-none items-center gap-2 text-xs">
|
||
<button
|
||
type="button"
|
||
onClick={onAddStage}
|
||
className={cn(
|
||
"flex items-center gap-1 border border-primary/30 bg-primary/5 px-2 py-1 font-medium text-primary transition hover:bg-primary/10",
|
||
R_CTRL,
|
||
)}
|
||
>
|
||
<Plus className="size-3.5" />
|
||
新建 Stage
|
||
</button>
|
||
<span
|
||
className={cn(
|
||
"border px-2 py-0.5 font-bold tabular-nums",
|
||
R_CTRL,
|
||
seatCountInvalid
|
||
? "border-destructive/30 bg-destructive/10 text-destructive"
|
||
: "border-primary/30 bg-primary/10 text-primary",
|
||
)}
|
||
>
|
||
{seatCount} / {CHAIN_MAX_SEATS}
|
||
{seatCount < CHAIN_MIN_SEATS && ` · 至少 ${CHAIN_MIN_SEATS}`}
|
||
</span>
|
||
</div>
|
||
</div>
|
||
|
||
<div className="min-h-0 flex-1 space-y-3 overflow-y-auto p-5">
|
||
{seatCount === 0 && stageGroups.length === 0 ? (
|
||
<div
|
||
className={cn(
|
||
"m-1 flex h-full flex-col items-center justify-center border border-dashed border-border bg-card/50 px-8 py-16 text-center",
|
||
R_CARD,
|
||
)}
|
||
>
|
||
<div className="mb-3 flex size-12 items-center justify-center rounded-full bg-primary/10 text-primary">
|
||
<Layers className="size-6" />
|
||
</div>
|
||
<h3 className="mb-1 text-sm font-bold text-foreground">暂无席位</h3>
|
||
<p className="max-w-sm text-xs leading-relaxed text-muted-foreground">
|
||
从左侧「候选智能体」点击或拖拽加入。每次加入是一个串行 Stage;把席位拖到同一个
|
||
Stage 里即可让它们并行。
|
||
</p>
|
||
</div>
|
||
) : (
|
||
<>
|
||
{stageGroups.map((group, stageIdx) => (
|
||
<StageSection
|
||
key={stageIdx}
|
||
stageIdx={stageIdx}
|
||
group={group}
|
||
stageCount={stageGroups.length}
|
||
startIndex={stageStartIndex[stageIdx]}
|
||
hasParallelStage={hasParallelStage}
|
||
onRemoveStage={() => onRemoveStage(stageIdx)}
|
||
onReorderStage={(dir) => onReorderStage(stageIdx, dir)}
|
||
onRemoveSeat={onRemoveSeat}
|
||
onMergeSeat={onMergeSeat}
|
||
onSplitSeat={onSplitSeat}
|
||
onSeatModelChange={onSeatModelChange}
|
||
onSeatSkillDirectiveChange={onSeatSkillDirectiveChange}
|
||
onSeatModeChange={onSeatModeChange}
|
||
positionConfigMode={positionConfigMode}
|
||
positionOptions={positionOptions}
|
||
onSeatPositionChange={onSeatPositionChange}
|
||
onGoalChange={(goal) => onStageGoalChange(stageIdx, goal)}
|
||
goalOptimizing={goalOptimizingIdx === stageIdx}
|
||
anyGoalOptimizing={goalOptimizingIdx !== null}
|
||
onOptimizeGoal={() => onOptimizeGoal(stageIdx)}
|
||
onSeatDetail={onSeatDetail}
|
||
/>
|
||
))}
|
||
<NewStageDropZone hasEmptyStage={hasEmptyStage} onAddStage={onAddStage} />
|
||
</>
|
||
)}
|
||
</div>
|
||
</section>
|
||
);
|
||
}
|
||
|
||
// ── 单个 Stage(droppable 容器 + Stage 内 sortable 列表)──────────────────
|
||
|
||
function StageSection({
|
||
stageIdx,
|
||
group,
|
||
stageCount,
|
||
startIndex,
|
||
hasParallelStage,
|
||
onRemoveStage,
|
||
onReorderStage,
|
||
onRemoveSeat,
|
||
onMergeSeat,
|
||
onSplitSeat,
|
||
onSeatModelChange,
|
||
onSeatSkillDirectiveChange,
|
||
onSeatModeChange,
|
||
positionConfigMode,
|
||
positionOptions,
|
||
onSeatPositionChange,
|
||
onGoalChange,
|
||
goalOptimizing,
|
||
anyGoalOptimizing,
|
||
onOptimizeGoal,
|
||
onSeatDetail,
|
||
}: {
|
||
stageIdx: number;
|
||
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;
|
||
onSeatModelChange: (agentId: string, model: string | null) => void;
|
||
onSeatSkillDirectiveChange: (agentId: string, enabled: boolean) => void;
|
||
onSeatModeChange: (agentId: string, mode: SeatMode | null) => void;
|
||
positionConfigMode: boolean;
|
||
positionOptions: readonly PositionOption[];
|
||
onSeatPositionChange: (agentId: string, positionId: PositionId | null) => void;
|
||
onGoalChange: (goal: string) => void;
|
||
/** 本 Stage 的阶段目标正在 AI 优化中。 */
|
||
goalOptimizing: boolean;
|
||
/** 任意 Stage 的优化在途(互斥,避免并发请求互相覆盖)。 */
|
||
anyGoalOptimizing: boolean;
|
||
onOptimizeGoal: () => void;
|
||
onSeatDetail: (agentId: string, name?: string) => void;
|
||
}) {
|
||
const { setNodeRef, isOver } = useDroppable({ id: STAGE_PREFIX + stageIdx });
|
||
const seats = group.seats;
|
||
const isParallel = seats.length > 1;
|
||
const isFirstStage = stageIdx === 0;
|
||
const isLastStage = stageIdx === stageCount - 1;
|
||
const seatItemIds = seats.map((s) => SEAT_PREFIX + s.agent_id);
|
||
|
||
return (
|
||
<div className={cn("border border-border bg-muted/20", R_CARD, PANEL_SHADOW)}>
|
||
{/* Stage 头 */}
|
||
<div className="flex items-center justify-between gap-2 border-b border-border bg-muted/40 px-3 py-2">
|
||
<div className="flex items-center gap-2">
|
||
<span
|
||
className={cn(
|
||
"flex items-center gap-1 border px-2 py-0.5 text-[11px] font-bold tabular-nums",
|
||
R_CTRL,
|
||
"border-primary/30 bg-primary/10 text-primary",
|
||
)}
|
||
>
|
||
<GitBranch className="size-3" />
|
||
Stage {stageIdx + 1}
|
||
</span>
|
||
<span
|
||
className={cn(
|
||
"border px-1.5 py-0.5 text-[10px] font-semibold",
|
||
R_CTRL,
|
||
isParallel
|
||
? "border-amber-400/40 bg-amber-400/10 text-amber-600 dark:text-amber-300"
|
||
: "border-border bg-muted text-muted-foreground",
|
||
)}
|
||
>
|
||
{isParallel ? `并行 ${seats.length}` : "串行"}
|
||
</span>
|
||
</div>
|
||
<div className="flex items-center gap-0.5">
|
||
<button
|
||
type="button"
|
||
onClick={() => onReorderStage(-1)}
|
||
disabled={isFirstStage}
|
||
title="上移 Stage"
|
||
className={cn(
|
||
"p-1 transition",
|
||
R_CTRL,
|
||
isFirstStage
|
||
? "pointer-events-none text-muted-foreground/30"
|
||
: "text-muted-foreground hover:bg-muted hover:text-foreground",
|
||
)}
|
||
>
|
||
<ChevronUp className="size-3.5" />
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={() => onReorderStage(1)}
|
||
disabled={isLastStage}
|
||
title="下移 Stage"
|
||
className={cn(
|
||
"p-1 transition",
|
||
R_CTRL,
|
||
isLastStage
|
||
? "pointer-events-none text-muted-foreground/30"
|
||
: "text-muted-foreground hover:bg-muted hover:text-foreground",
|
||
)}
|
||
>
|
||
<ChevronDown className="size-3.5" />
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={onRemoveStage}
|
||
title="删除 Stage"
|
||
className={cn("ml-0.5 p-1 text-muted-foreground/60 transition-colors hover:bg-primary/10 hover:text-primary", R_CTRL)}
|
||
>
|
||
<Trash2 className="size-3.5" />
|
||
</button>
|
||
</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,
|
||
)}
|
||
/>
|
||
<div className="mt-1 flex items-start justify-between gap-2">
|
||
{!hasParallelStage && (group.goal?.trim()?.length ?? 0) > 0 ? (
|
||
<p className="text-[10px] text-muted-foreground">
|
||
提示:填写本阶段目标后,本链条将按阶段顺序由总控逐阶段派活(分层研讨),并把该目标注入总控。
|
||
</p>
|
||
) : (
|
||
<span />
|
||
)}
|
||
<button
|
||
type="button"
|
||
onClick={onOptimizeGoal}
|
||
disabled={anyGoalOptimizing || !(group.goal?.trim())}
|
||
title={
|
||
group.goal?.trim()
|
||
? "让 AI 重写本阶段目标(明确产出物与对上一阶段的承接)"
|
||
: "先写一版阶段目标,AI 才能在它基础上优化"
|
||
}
|
||
className={cn(
|
||
"inline-flex shrink-0 items-center gap-1 border border-primary/30 bg-primary/5 px-2 py-0.5 text-[10px] font-semibold text-primary transition hover:bg-primary/10 disabled:cursor-not-allowed disabled:opacity-50",
|
||
R_CTRL,
|
||
)}
|
||
>
|
||
{goalOptimizing ? (
|
||
<Loader2 className="size-3 animate-spin" />
|
||
) : (
|
||
<Wand2 className="size-3" />
|
||
)}
|
||
{goalOptimizing ? "优化中…" : "AI 优化"}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
)}
|
||
|
||
{/* Stage 内席位 */}
|
||
<div
|
||
ref={setNodeRef}
|
||
className={cn("space-y-2 p-2.5 transition-colors", isOver && "bg-primary/[0.04]")}
|
||
>
|
||
{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}>
|
||
{seats.map((seat, i) => (
|
||
<SeatStrip
|
||
key={seat.agent_id}
|
||
seat={seat}
|
||
globalIndex={startIndex + i}
|
||
stageIdx={stageIdx}
|
||
isFirstStage={isFirstStage}
|
||
isLastStage={isLastStage}
|
||
canSplit={isParallel}
|
||
onRemove={() => onRemoveSeat(seat.agent_id)}
|
||
onMergeUp={() => onMergeSeat(seat.agent_id, stageIdx - 1)}
|
||
onMergeDown={() => onMergeSeat(seat.agent_id, stageIdx + 1)}
|
||
onSplit={() => onSplitSeat(seat.agent_id)}
|
||
onModelChange={(model) => onSeatModelChange(seat.agent_id, model)}
|
||
onSkillDirectiveChange={(enabled) => onSeatSkillDirectiveChange(seat.agent_id, enabled)}
|
||
onSeatModeChange={(mode) => onSeatModeChange(seat.agent_id, mode)}
|
||
showPositionConfig={positionConfigMode}
|
||
positionOptions={positionOptions}
|
||
onPositionChange={(positionId) => onSeatPositionChange(seat.agent_id, positionId)}
|
||
onDetail={() => onSeatDetail(seat.agent_id, seat.name)}
|
||
/>
|
||
))}
|
||
</SortableContext>
|
||
)}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
// ── 单个席位长条(sortable)─────────────────────────────────────────────
|
||
|
||
function SeatStrip({
|
||
seat,
|
||
globalIndex,
|
||
isFirstStage,
|
||
isLastStage,
|
||
canSplit,
|
||
onRemove,
|
||
onMergeUp,
|
||
onMergeDown,
|
||
onSplit,
|
||
onModelChange,
|
||
onSkillDirectiveChange,
|
||
onSeatModeChange,
|
||
showPositionConfig,
|
||
positionOptions,
|
||
onPositionChange,
|
||
onDetail,
|
||
}: {
|
||
seat: ChainSeat;
|
||
globalIndex: number;
|
||
stageIdx: number;
|
||
isFirstStage: boolean;
|
||
isLastStage: boolean;
|
||
canSplit: boolean;
|
||
onRemove: () => void;
|
||
onMergeUp: () => void;
|
||
onMergeDown: () => void;
|
||
onSplit: () => void;
|
||
/** 席位模型覆盖变更(null = 清除,跟随全局)。 */
|
||
onModelChange: (model: string | null) => void;
|
||
/** 席位「会商技能识别强化」开关变更。 */
|
||
onSkillDirectiveChange: (enabled: boolean) => void;
|
||
/** 席位「推理深度覆盖」变更(null = 跟随链条级 seatMode)。 */
|
||
onSeatModeChange: (mode: SeatMode | null) => void;
|
||
/** 仅岗位协同入口展示的岗位配置。 */
|
||
showPositionConfig: boolean;
|
||
/** Current position directory, injected by the business-chain editor. */
|
||
positionOptions: readonly PositionOption[];
|
||
onPositionChange: (positionId: PositionId | null) => void;
|
||
onDetail: () => void;
|
||
}) {
|
||
const { attributes, listeners, setNodeRef, transform, transition, isDragging } =
|
||
useSortable({ id: SEAT_PREFIX + seat.agent_id });
|
||
const avatarType = getAvatarTypeFor(seat.agent_id, globalIndex);
|
||
const selectablePositionOptions = useMemo(() => {
|
||
const assignedId = seat.position_id ?? null;
|
||
const assigned = assignedId
|
||
? positionOptions.find((position) => position.id === assignedId)
|
||
: undefined;
|
||
const enabled = positionOptions.filter((position) => position.enabled !== false);
|
||
// Do not silently erase an archived configuration from a saved chain.
|
||
// It remains visible but cannot be selected for another seat.
|
||
const historical =
|
||
assignedId && (!assigned || assigned.enabled === false)
|
||
? [
|
||
{
|
||
label: assigned
|
||
? `${assigned.name}(已停用)`
|
||
: `${assignedId}(岗位已删除)`,
|
||
value: assignedId,
|
||
disabled: true,
|
||
},
|
||
]
|
||
: [];
|
||
|
||
return [
|
||
{ label: "未分配", value: "" },
|
||
...historical,
|
||
...enabled.map((position) => ({ label: position.name, value: position.id })),
|
||
];
|
||
}, [positionOptions, seat.position_id]);
|
||
return (
|
||
<div
|
||
ref={setNodeRef}
|
||
style={{ transform: CSS.Transform.toString(transform), transition }}
|
||
className={cn(
|
||
"flex items-stretch overflow-hidden border border-border bg-card",
|
||
R_CARD,
|
||
PANEL_SHADOW,
|
||
isDragging && "z-10 opacity-70 shadow-[0_4px_12px_rgba(15,23,42,0.12)]",
|
||
)}
|
||
>
|
||
{/* 拖拽手柄 */}
|
||
<button
|
||
type="button"
|
||
className="flex w-7 shrink-0 cursor-grab touch-none items-center justify-center border-r border-border bg-muted/40 text-muted-foreground/60 transition-colors hover:text-foreground active:cursor-grabbing"
|
||
{...attributes}
|
||
{...listeners}
|
||
title="拖动到其它 Stage / 排序"
|
||
>
|
||
<GripVertical className="size-3.5" />
|
||
</button>
|
||
|
||
{/* 序号 */}
|
||
<div className="flex shrink-0 select-none items-center pl-2.5">
|
||
<span
|
||
className={cn(
|
||
"flex size-6 items-center justify-center border text-xs font-bold tabular-nums",
|
||
R_CTRL,
|
||
chainTagClasses(avatarType),
|
||
)}
|
||
>
|
||
{globalIndex + 1}
|
||
</span>
|
||
</div>
|
||
|
||
{/* 详情 */}
|
||
<div className="flex min-w-0 flex-1 flex-col justify-center px-2.5 py-2">
|
||
<div className="truncate text-xs font-bold text-foreground">{seat.name || seat.agent_id}</div>
|
||
{seat.description && (
|
||
<div className="mt-0.5 line-clamp-1 text-[11px] font-medium text-muted-foreground">
|
||
{seat.description}
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
{/* 岗位协同从专用入口进来时才展示。使用 TDesign Select,未分配不会阻塞普通圆桌使用。 */}
|
||
{showPositionConfig && (
|
||
<div className="flex shrink-0 items-center gap-1.5 border-l border-border px-2.5">
|
||
<span className="shrink-0 text-[10px] font-medium text-muted-foreground">岗位</span>
|
||
<TSelect
|
||
size="small"
|
||
value={seat.position_id ?? ""}
|
||
options={selectablePositionOptions}
|
||
onChange={(value) =>
|
||
onPositionChange(value ? (String(value) as PositionId) : null)
|
||
}
|
||
className="w-[132px]"
|
||
popupProps={{ overlayClassName: "z-[80]" }}
|
||
/>
|
||
</div>
|
||
)}
|
||
|
||
{/* 席位模型覆盖(右侧操作区):空 = 跟随全局所选模型;选了则该席位作为子智能体
|
||
执行时用此模型。技能重的席位配强模型、边角席位配快模型,配合技能白名单实现
|
||
「强弱搭配」。放到右侧操作区,与名称/描述解耦,卡片更整洁。 */}
|
||
<div className="flex shrink-0 items-center border-l border-border px-2.5">
|
||
<div
|
||
className={cn(
|
||
"flex items-center gap-1.5 border border-border/70 bg-muted/40 py-1 pl-2 pr-1",
|
||
R_CTRL,
|
||
)}
|
||
title="该席位作为子智能体执行时使用的模型;「跟随全局」= 用第二步顶部所选模型"
|
||
>
|
||
<span className="shrink-0 select-none text-[10px] font-medium text-muted-foreground">模型</span>
|
||
<ModelNameSelect
|
||
value={seat.model ?? null}
|
||
onChange={onModelChange}
|
||
defaultLabel="跟随全局"
|
||
triggerClassName="h-6 max-w-[150px] border-none bg-transparent text-[11px] shadow-none hover:bg-background/60"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
{/* 控制:推理深度 / 技能识别强化 / 查看详情 / 并入上一阶段 / 独立成阶段 / 并入下一阶段 / 移除 */}
|
||
<div className="flex shrink-0 items-center gap-0.5 border-l border-border px-2">
|
||
{/* 席位推理深度覆盖:小图标 → 下拉框(跟随链条默认 + 四档)。设了覆盖 = 高亮。
|
||
「卡顿提速」用:把信息收集/边角席位降到「快速」,只给关键席位留「专业/多智能体」。 */}
|
||
<DropdownMenu>
|
||
<DropdownMenuTrigger asChild>
|
||
<button
|
||
type="button"
|
||
title="席位推理深度(覆盖链条默认;降到「快速」可在模型卡顿时大幅提速)"
|
||
className={cn(
|
||
"p-1 transition",
|
||
R_CTRL,
|
||
seat.seat_mode
|
||
? "bg-primary/10 text-primary"
|
||
: "text-muted-foreground hover:bg-muted hover:text-foreground",
|
||
)}
|
||
>
|
||
<Gauge className="size-3.5" />
|
||
</button>
|
||
</DropdownMenuTrigger>
|
||
<DropdownMenuContent align="end" className="w-60">
|
||
<DropdownMenuLabel className="text-[11px] font-semibold">
|
||
席位推理深度
|
||
<span className="mt-0.5 block text-[10px] font-normal text-muted-foreground">
|
||
覆盖链条级默认,仅本席位生效。模型卡顿时把次要席位降到「快速」可大幅提速。
|
||
</span>
|
||
</DropdownMenuLabel>
|
||
<DropdownMenuSeparator />
|
||
<DropdownMenuItem
|
||
className={cn("text-xs", !seat.seat_mode && "font-semibold text-primary")}
|
||
onClick={() => onSeatModeChange(null)}
|
||
>
|
||
跟随链条默认
|
||
</DropdownMenuItem>
|
||
{SEAT_MODE_OPTIONS.map((opt) => (
|
||
<DropdownMenuItem
|
||
key={opt.value}
|
||
className={cn("flex-col items-start gap-0 text-xs", seat.seat_mode === opt.value && "font-semibold text-primary")}
|
||
onClick={() => onSeatModeChange(opt.value)}
|
||
>
|
||
<span>{opt.label}</span>
|
||
<span className="text-[10px] font-normal leading-tight text-muted-foreground">{opt.description}</span>
|
||
</DropdownMenuItem>
|
||
))}
|
||
</DropdownMenuContent>
|
||
</DropdownMenu>
|
||
{/* 会商技能识别强化:小图标 → 下拉框(开关 + 说明)。开启 = 高亮。 */}
|
||
<DropdownMenu>
|
||
<DropdownMenuTrigger asChild>
|
||
<button
|
||
type="button"
|
||
title="会商技能识别强化(弱模型补偿)"
|
||
className={cn(
|
||
"p-1 transition",
|
||
R_CTRL,
|
||
seat.seat_skill_directive
|
||
? "bg-primary/10 text-primary"
|
||
: "text-muted-foreground hover:bg-muted hover:text-foreground",
|
||
)}
|
||
>
|
||
<Sparkles className="size-3.5" />
|
||
</button>
|
||
</DropdownMenuTrigger>
|
||
<DropdownMenuContent align="end" className="w-64 p-3">
|
||
<div className="flex items-start justify-between gap-3">
|
||
<div className="space-y-0.5">
|
||
<p className="text-xs font-semibold text-foreground">会商技能识别强化</p>
|
||
<p className="text-[11px] leading-relaxed text-muted-foreground">
|
||
开启后,该席位作为会商子智能体执行时,会把已配置的技能(含 SKILL.md
|
||
路径与「先 read_file 再用」硬指令)拼进任务,补偿弱模型不识别技能。也可在该智能体编辑里打开(任一即生效)。
|
||
</p>
|
||
</div>
|
||
<Switch
|
||
checked={seat.seat_skill_directive ?? false}
|
||
onCheckedChange={onSkillDirectiveChange}
|
||
/>
|
||
</div>
|
||
</DropdownMenuContent>
|
||
</DropdownMenu>
|
||
<button
|
||
type="button"
|
||
onClick={onDetail}
|
||
title="查看详情"
|
||
className={cn(
|
||
"p-1 text-muted-foreground transition hover:bg-muted hover:text-foreground",
|
||
R_CTRL,
|
||
)}
|
||
>
|
||
<Info className="size-3.5" />
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={onMergeUp}
|
||
disabled={isFirstStage}
|
||
title="并入上一阶段(与其并行)"
|
||
className={cn(
|
||
"p-1 transition",
|
||
R_CTRL,
|
||
isFirstStage
|
||
? "pointer-events-none text-muted-foreground/30"
|
||
: "text-muted-foreground hover:bg-muted hover:text-foreground",
|
||
)}
|
||
>
|
||
<ChevronUp className="size-3.5" />
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={onSplit}
|
||
disabled={!canSplit}
|
||
title="从本阶段拆出,独立成新阶段"
|
||
className={cn(
|
||
"p-1 transition",
|
||
R_CTRL,
|
||
!canSplit
|
||
? "pointer-events-none text-muted-foreground/30"
|
||
: "text-muted-foreground hover:bg-muted hover:text-foreground",
|
||
)}
|
||
>
|
||
<SplitSquareVertical className="size-3.5" />
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={onMergeDown}
|
||
disabled={isLastStage}
|
||
title="并入下一阶段(与其并行)"
|
||
className={cn(
|
||
"p-1 transition",
|
||
R_CTRL,
|
||
isLastStage
|
||
? "pointer-events-none text-muted-foreground/30"
|
||
: "text-muted-foreground hover:bg-muted hover:text-foreground",
|
||
)}
|
||
>
|
||
<ChevronDown className="size-3.5" />
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onClick={onRemove}
|
||
title="移出此席位"
|
||
className={cn(
|
||
"ml-0.5 p-1 text-muted-foreground/60 transition-colors hover:bg-primary/10 hover:text-primary",
|
||
R_CTRL,
|
||
)}
|
||
>
|
||
<X className="size-3.5" />
|
||
</button>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
// ── 「新建 Stage」落区(拖席位到此 = 独立成最后一个 Stage)──────────────────
|
||
|
||
function NewStageDropZone({
|
||
hasEmptyStage,
|
||
onAddStage,
|
||
}: {
|
||
hasEmptyStage: boolean;
|
||
onAddStage: () => void;
|
||
}) {
|
||
const { setNodeRef, isOver } = useDroppable({ id: NEWSTAGE_DROPPABLE_ID });
|
||
return (
|
||
<button
|
||
type="button"
|
||
ref={setNodeRef}
|
||
onClick={onAddStage}
|
||
disabled={hasEmptyStage}
|
||
className={cn(
|
||
"flex w-full items-center justify-center gap-1.5 border border-dashed px-3 py-3 text-xs font-medium transition",
|
||
R_CARD,
|
||
isOver
|
||
? "border-primary bg-primary/[0.06] text-primary"
|
||
: "border-border bg-card/40 text-muted-foreground hover:border-primary/40 hover:text-primary",
|
||
hasEmptyStage && "cursor-not-allowed opacity-50 hover:border-border hover:text-muted-foreground",
|
||
)}
|
||
title={hasEmptyStage ? "已有空 Stage,先填充它" : "新建一个串在最后的 Stage"}
|
||
>
|
||
<Plus className="size-3.5" />
|
||
新建 Stage(串在最后) · 或把席位拖到此处独立成阶段
|
||
</button>
|
||
);
|
||
}
|