代码修改

This commit is contained in:
董宏凯 committed 2026-05-27 19:43:28 +08:00
1 parent b7da062a4c
commit 8bdbf6ab15
3 files changed
+67 -56

No files matched your search

@@ -171,9 +171,13 @@ export interface UseStep2OrchestrationReturn {
// ─── Handlers ───────────────────────────────────────────────────────
/** 中断当前编排循环 + 所有 in-flight SSE。 */
stopOrchestration: () => void;
/** 与 Step2Panel「暂停会商」按钮相同 —— 挂起编排并中止 in-flight SSE。 */
pauseRoundtable: () => void;
/** 与 Step2Panel「恢复会商」按钮相同 —— 恢复自动研讨(含待处理的干预指令)。 */
resumeRoundtable: () => void;
/** 中断所有 in-flight SSE(给新建任务 / 加载草稿用)。 */
abortAllInFlight: () => void;
/** 用户「干预研审」按钮 —— 追加一条人工指令气泡并触发一轮编排。 */
/** 用户「干预研审」—— 先暂停会商,干预指令在恢复后执行。 */
handleInjectToRoundtable: () => void;
/** 总控澄清回复 —— 把回答拼到 prompt 里再起一轮编排。 */
submitClarification: (rawAnswer: string) => void;
@@ -296,9 +300,8 @@ export function useStep2Orchestration(
const orchestrationCancelRef = useRef<boolean>(false);
const step2InitRef = useRef<boolean>(false);
const activeAbortersRef = useRef<Set<AbortController>>(new Set());
/** 干预研审:暂停当前轮次后待执行的 leader prompt。 */
/** 干预研审:恢复会商后待执行的 leader prompt。 */
const pendingInjectPromptRef = useRef<string | null>(null);
const [injectFlushToken, setInjectFlushToken] = useState(0);
// selectedModel / agentConfigs / agentNameToRole / threadIds / coordinatorName
// 等等被 runOrchestration 在循环里反复读取。把它们打到 ref 上,可以让
// runOrchestration 的 useCallback deps 大幅收窄,避免每次模型切换、agentConfigs
@@ -1112,17 +1115,11 @@ export function useStep2Orchestration(
// 挂起 / 恢复:与上面的 init effect 独立。`isRoundTableRunning` toggle 时:
// - false → stopOrchestration
// - true 且 idle → 触发一次「请继续」的 leader cycle
// 注意 deps 故意只有 isRoundTableRunning,不再额外加 currentStep —— 回到 Step 2
// 检视讨论时不应该自动 fire 新的 leader 调用。
// - true 且 idle → 触发 leader cycle(若有干预指令则优先执行)
useEffect(() => {
if (currentStep !== 2) return;
if (!isRoundTableRunning) {
// 干预研审会先写入 pending 再置 false;此时 stop 已在 handler 里触发,
// 避免 effect 再次 stop 误杀随后 flush 启动的 inject 编排。
if (!pendingInjectPromptRef.current) {
stopOrchestration();
}
stopOrchestration();
return;
}
if (
@@ -1132,6 +1129,18 @@ export function useStep2Orchestration(
!coordinatorNameRef.current
)
return;
const pending = pendingInjectPromptRef.current;
if (pending) {
pendingInjectPromptRef.current = null;
void runOrchestration(
pending,
threadIdsRef.current,
coordinatorNameRef.current,
);
return;
}
void runOrchestration(
"用户已恢复研讨,请继续上一轮的协调工作。",
threadIdsRef.current,
@@ -1140,20 +1149,16 @@ export function useStep2Orchestration(
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isRoundTableRunning]);
// 干预研审:当前轮次停止后 flush 待执行的 inject 编排(编排期间 UI 仍为「恢复会商」)。
useEffect(() => {
if (isOrchestrating) return;
const pending = pendingInjectPromptRef.current;
if (!pending) return;
if (!threadIdsRef.current || !coordinatorNameRef.current) return;
pendingInjectPromptRef.current = null;
triggerToast("您的人工纠偏指令已同步至圆桌节点!");
void runOrchestration(
pending,
threadIdsRef.current,
coordinatorNameRef.current,
);
}, [isOrchestrating, injectFlushToken, runOrchestration, triggerToast]);
const pauseRoundtable = useCallback(() => {
setIsRoundTableRunning(false);
stopOrchestration();
triggerToast("⏸️ 会商已暂停");
}, [stopOrchestration, triggerToast]);
const resumeRoundtable = useCallback(() => {
setIsRoundTableRunning(true);
triggerToast("▶️ 恢复大模型并行博弈与推理决策");
}, [triggerToast]);
// ─── Public handlers ─────────────────────────────────────────────
const handleInjectToRoundtable = useCallback(() => {
@@ -1166,12 +1171,8 @@ export function useStep2Orchestration(
const userText = customAgentInput.trim();
setCustomAgentInput("");
const prompt = `用户人工干预新指令:${userText}\n\n请结合当前讨论状态,决定是否继续派活或直接给出更新后的结论。`;
pendingInjectPromptRef.current = prompt;
// 与 Step2Panel 右上角「暂停会商 / 恢复会商」联动:立即进入挂起态。
setIsRoundTableRunning(false);
stopOrchestration();
// 与右上角「暂停会商」完全相同的挂起逻辑。
pauseRoundtable();
appendDialogue({
sender: "用户 (插话干预)",
@@ -1180,13 +1181,8 @@ export function useStep2Orchestration(
confidence: "最高指令",
});
if (isOrchestratingRef.current) {
triggerToast("⏸️ 会商已暂停,当前轮次结束后将处理您的干预指令");
} else {
triggerToast("⏸️ 会商已暂停,正在处理您的干预指令…");
}
setInjectFlushToken((n) => n + 1);
}, [appendDialogue, customAgentInput, stopOrchestration, triggerToast]);
pendingInjectPromptRef.current = `用户人工干预新指令:${userText}\n\n请结合当前讨论状态,决定是否继续派活或直接给出更新后的结论。`;
}, [appendDialogue, customAgentInput, pauseRoundtable, triggerToast]);
const submitClarification = useCallback(
(rawAnswer: string) => {
@@ -1378,6 +1374,8 @@ export function useStep2Orchestration(
setAgentConfigs,
resetInitGate,
stopOrchestration,
pauseRoundtable,
resumeRoundtable,
abortAllInFlight,
handleInjectToRoundtable,
submitClarification,