圆桌第三步与业务链条增强:主题跟随/插话暂停/提示词优化/结构化流程图
- 结果绘制跟随日/夜间主题(深色按深蓝 UI 规范令牌绘制),提示词注入真实生成时间 - 绘制支持暂停与随时插话(线程存活时免带原料续线程省 token)、失败自动重试一次、草稿主题不匹配提示条 - 总结报告优先执行用户最终总结要求(结构化输出/重点席位可整体替换默认章节) - 业务链条总控提示词与各阶段目标加「AI 优化」按钮(新接口 POST /api/roundtable-chains/optimize-prompt) - 总结报告 flow-json 结构化流程图:流式增量绘制、最新连线蚂蚁线动画、拖拽/缩放/复位/全屏、节点详情弹窗、沙箱切换按钮/无沙箱自动打开 - roundtable-report / roundtable-summary 两个内置智能体 SOUL 更新(双主题、多轮修改允许读底稿、KPI 估算标注、流程数据契约) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a4a9a4d26e
commit
df8bf895ef
13 files changed
+1600
-83
No files matched your search
@@ -39,6 +39,7 @@ import {
|
||||
SplitSquareVertical,
|
||||
Trash2,
|
||||
UserPlus,
|
||||
Wand2,
|
||||
X,
|
||||
} from "lucide-react";
|
||||
import {
|
||||
@@ -79,6 +80,7 @@ import {
|
||||
createChain,
|
||||
deleteChain,
|
||||
listChains,
|
||||
optimizeChainPrompt,
|
||||
setChainPublic,
|
||||
updateChain,
|
||||
} from "@/roundtable-planning/api/chains";
|
||||
@@ -317,6 +319,80 @@ export default function BusinessChainEditorPage() {
|
||||
setStageGroups((prev) => setStageGoal(prev, stageIdx, goal));
|
||||
}, []);
|
||||
|
||||
// ── 提示词 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));
|
||||
}, []);
|
||||
@@ -759,9 +835,32 @@ export default function BusinessChainEditorPage() {
|
||||
>
|
||||
<div className="flex items-center justify-between border-b border-border bg-muted/50 px-4 py-2">
|
||||
<span className="select-none text-sm font-medium text-muted-foreground">总控提示词</span>
|
||||
<span className="select-none text-[10px] text-muted-foreground/70">
|
||||
写给总控:怎么派活、做什么(仅分层研讨生效,可选)
|
||||
</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="select-none text-[10px] text-muted-foreground/70">
|
||||
写给总控:怎么派活、做什么(仅分层研讨生效,可选)
|
||||
</span>
|
||||
<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 py-0.5 text-[10px] font-semibold text-primary transition hover:bg-primary/10 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>
|
||||
<textarea
|
||||
value={coordinatorPrompt}
|
||||
@@ -856,6 +955,8 @@ export default function BusinessChainEditorPage() {
|
||||
onMergeSeat={mergeSeatToStage}
|
||||
onSplitSeat={splitSeat}
|
||||
onStageGoalChange={setGoal}
|
||||
goalOptimizingIdx={goalOptimizingIdx}
|
||||
onOptimizeGoal={handleOptimizeStageGoal}
|
||||
onSeatDetail={showDetail}
|
||||
/>
|
||||
</main>
|
||||
@@ -1049,6 +1150,8 @@ function StagesColumn({
|
||||
onMergeSeat,
|
||||
onSplitSeat,
|
||||
onStageGoalChange,
|
||||
goalOptimizingIdx,
|
||||
onOptimizeGoal,
|
||||
onSeatDetail,
|
||||
}: {
|
||||
stageGroups: StageGroups;
|
||||
@@ -1062,6 +1165,9 @@ function StagesColumn({
|
||||
onMergeSeat: (agentId: string, targetStageIdx: number) => void;
|
||||
onSplitSeat: (agentId: string) => 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 起始累加。
|
||||
@@ -1156,6 +1262,9 @@ function StagesColumn({
|
||||
onMergeSeat={onMergeSeat}
|
||||
onSplitSeat={onSplitSeat}
|
||||
onGoalChange={(goal) => onStageGoalChange(stageIdx, goal)}
|
||||
goalOptimizing={goalOptimizingIdx === stageIdx}
|
||||
anyGoalOptimizing={goalOptimizingIdx !== null}
|
||||
onOptimizeGoal={() => onOptimizeGoal(stageIdx)}
|
||||
onSeatDetail={onSeatDetail}
|
||||
/>
|
||||
))}
|
||||
@@ -1181,6 +1290,9 @@ function StageSection({
|
||||
onMergeSeat,
|
||||
onSplitSeat,
|
||||
onGoalChange,
|
||||
goalOptimizing,
|
||||
anyGoalOptimizing,
|
||||
onOptimizeGoal,
|
||||
onSeatDetail,
|
||||
}: {
|
||||
stageIdx: number;
|
||||
@@ -1195,6 +1307,11 @@ function StageSection({
|
||||
onMergeSeat: (agentId: string, targetStageIdx: number) => void;
|
||||
onSplitSeat: (agentId: string) => 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 });
|
||||
@@ -1292,11 +1409,36 @@ function StageSection({
|
||||
R_CTRL,
|
||||
)}
|
||||
/>
|
||||
{!hasParallelStage && (group.goal?.trim()?.length ?? 0) > 0 && (
|
||||
<p className="mt-1 text-[10px] text-muted-foreground">
|
||||
提示:填写本阶段目标后,本链条将按阶段顺序由总控逐阶段派活(分层研讨),并把该目标注入总控。
|
||||
</p>
|
||||
)}
|
||||
<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>
|
||||
)}
|
||||
|
||||
|
||||
Reference in new issue
Block a user