feat(roundtable): 第二步席位执行模式(快速/思考/专业问答/多智能体)+ 子智能体任务卡片 + 后台完成跨页通知 + 链条默认模式持久化
- 席位执行模式:选择参会智能体弹窗加模式选择器,映射 thinking/reasoning/subagent 透传 recommend/chain/dag 三条编排;后端 _special_run 覆盖 seat policy(仅席位, 总控不变);ultra 解锁席位 task 子代理(custom 流回传 task_running 实时进度)。 - 子智能体任务卡片:复用主聊天 SubtaskCard + SubtaskContext,从席位流解析 task 调用/结果,在 Step2 气泡渲染多张任务卡片(覆盖业务链条路径)。 - 后台挂起也按所选模式跑(StartParams→inprocess gateway→run_seat 覆盖 policy)。 - 后台作业完成全工作区跨页通知:RoundtableJobNotifier 挂在 PageLayout 常驻层, 作业终态弹「达成共识」同款浮窗。 - 业务链条可配「默认执行模式」并持久化(roundtable_chains.seat_mode;选链时弹窗 默认用它,仍可临时改)。 - 修复后台 Step3 HTML 看板概率截断:deepseek max_tokens=4096 单轮写不完长 HTML, 产物自愈重试上限 2→5,让 append 续写写完整(同惠及 summary/dashboard)。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
fbd237531e
commit
3907034a1d
25 files changed
+834
-40
No files matched your search
@@ -27,6 +27,7 @@ import {
|
||||
type ThreadIdMap,
|
||||
} from "@/roundtable-planning/api/multi-agent";
|
||||
import { uploadFiles } from "@/core/uploads/api";
|
||||
import { useUpdateSubtask } from "@/core/tasks/context";
|
||||
|
||||
/** 干预消息携带的上传文件引用(与 streamMultiAgent 的 files 字段同形)。 */
|
||||
type RunFileRef = NonNullable<StreamMultiAgentRequest["files"]>[number];
|
||||
@@ -37,12 +38,56 @@ function takeOnce<T>(ref: { current: T | null }): T | undefined {
|
||||
ref.current = null;
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从一帧里识别子智能体 custom 事件(task_started/running/completed/failed/cancelled/
|
||||
* timed_out)。custom 流帧通常是裸 payload 对象 `{type:"task_*", task_id, ...}`;
|
||||
* 开启 stream_subgraphs 时也可能被包成 `[namespace, payload]`,这里两种都兼容。
|
||||
*/
|
||||
function asSubagentTaskEvent(frame: unknown): {
|
||||
type: string;
|
||||
task_id: string;
|
||||
message?: unknown;
|
||||
result?: unknown;
|
||||
error?: unknown;
|
||||
description?: unknown;
|
||||
} | null {
|
||||
const cand =
|
||||
frame && typeof frame === "object" && !Array.isArray(frame)
|
||||
? (frame as Record<string, unknown>)
|
||||
: Array.isArray(frame) && frame.length >= 2 && frame[1] && typeof frame[1] === "object"
|
||||
? (frame[1] as Record<string, unknown>)
|
||||
: null;
|
||||
if (!cand) return null;
|
||||
const type = typeof cand.type === "string" ? cand.type : "";
|
||||
const taskId = typeof cand.task_id === "string" ? cand.task_id : "";
|
||||
if (!type.startsWith("task_") || !taskId) return null;
|
||||
return { type, task_id: taskId, message: cand.message, result: cand.result, error: cand.error, description: cand.description };
|
||||
}
|
||||
|
||||
/** 从 LangGraph 消息 chunk 的 content(string 或结构化 block 数组)里抽纯文本。 */
|
||||
function extractFrameText(content: unknown): string {
|
||||
if (typeof content === "string") return content;
|
||||
if (Array.isArray(content)) {
|
||||
let out = "";
|
||||
for (const item of content) {
|
||||
if (typeof item === "string") out += item;
|
||||
else if (item && typeof item === "object") {
|
||||
const block = item as Record<string, unknown>;
|
||||
if (typeof block.text === "string") out += block.text;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
import {
|
||||
buildDagStageLeaderTask,
|
||||
pickDagSeatTask,
|
||||
type OrchestrationPlan,
|
||||
} from "@/roundtable-planning/lib/dag-types";
|
||||
import type { ChainNodeState } from "@/roundtable-planning/lib/job-types";
|
||||
import { seatModeToRequestFields, type SeatMode } from "@/roundtable-planning/lib/seat-mode";
|
||||
import {
|
||||
DEFAULT_SELECTED_AGENTS,
|
||||
MAX_CYCLES,
|
||||
@@ -65,6 +110,12 @@ export type Step2Dialogue = {
|
||||
streaming?: boolean;
|
||||
/** special 席位气泡对应的 LangGraph thread,用于沙箱预览。 */
|
||||
agentThreadId?: string;
|
||||
/**
|
||||
* 「多智能体问答」模式下,本席位用 `task` 工具派生的子智能体任务 id 列表(=task 工具
|
||||
* 调用的 tool_call_id)。渲染时据此从共享 SubtaskContext 取每个 Subtask 渲染任务卡片
|
||||
* (复用主聊天 `SubtaskCard`,见 Step2Panel.Step2Message)。非 ultra 模式恒为空。
|
||||
*/
|
||||
subtaskIds?: string[];
|
||||
steps?: Array<{
|
||||
id: string;
|
||||
key: string;
|
||||
@@ -222,6 +273,12 @@ export interface UseStep2OrchestrationOptions {
|
||||
currentStep: number;
|
||||
/** 全局选中模型(顶栏「推理模型」下拉)。 */
|
||||
selectedModel: string;
|
||||
/**
|
||||
* 席位执行模式(快速/思考/专业问答/多智能体问答)。决定第二步**每个子智能体席位**
|
||||
* 的推理深度(thinking/reasoning_effort/subagent);总控派活不受影响。由「选择参会
|
||||
* 智能体」弹窗确认时的 `SeatSelectionResult.seatMode` 决定。缺省 `pro`。
|
||||
*/
|
||||
selectedMode: SeatMode;
|
||||
/**
|
||||
* 编排模式:
|
||||
* - `recommend`(默认)—— 总控自由派活循环(`runOrchestration`);
|
||||
@@ -376,6 +433,7 @@ export function useStep2Orchestration(
|
||||
const {
|
||||
currentStep,
|
||||
selectedModel,
|
||||
selectedMode,
|
||||
orchestrationMode,
|
||||
orchestrationPlan,
|
||||
dagExecMode = "fast",
|
||||
@@ -507,6 +565,8 @@ export function useStep2Orchestration(
|
||||
// runOrchestration 的 useCallback deps 大幅收窄,避免每次模型切换、agentConfigs
|
||||
// 改写都重建一遍循环函数 —— 之前没收窄时 useEffect 会因 deps 变化重复 init。
|
||||
const selectedModelRef = useRef<string>(selectedModel);
|
||||
// 席位执行模式同样打到 ref,让席位调用在编排循环里读到最新值而不重建回调。
|
||||
const selectedModeRef = useRef<SeatMode>(selectedMode);
|
||||
const agentConfigsRef = useRef<Record<number, AgentConfig>>(agentConfigs);
|
||||
const agentNameToRoleRef = useRef(agentNameToRole);
|
||||
const threadIdsRef = useRef<ThreadIdMap | null>(threadIds);
|
||||
@@ -543,6 +603,9 @@ export function useStep2Orchestration(
|
||||
useEffect(() => {
|
||||
selectedModelRef.current = selectedModel;
|
||||
}, [selectedModel]);
|
||||
useEffect(() => {
|
||||
selectedModeRef.current = selectedMode;
|
||||
}, [selectedMode]);
|
||||
useEffect(() => {
|
||||
agentConfigsRef.current = agentConfigs;
|
||||
}, [agentConfigs]);
|
||||
@@ -945,6 +1008,137 @@ export function useStep2Orchestration(
|
||||
[upsertSeatToolCall],
|
||||
);
|
||||
|
||||
// ── 「多智能体问答」子智能体任务卡片(参照主聊天 message-list 的 task 识别)──────────
|
||||
// ultra 模式下席位用 `task` 工具派生子智能体。从席位流的 messages-tuple 帧里:
|
||||
// (1) AI chunk 的 tool_calls 里 name==="task" → 建/更新一条 Subtask(in_progress);
|
||||
// (2) type==="tool" 且 tool_call_id 命中已知 task id → 据「Task Succeeded./failed./
|
||||
// timed out」前缀更新为 completed/failed(与主聊天 message-list.tsx 同源解析)。
|
||||
// Subtask 存进共享 SubtaskContext(主聊天同一份),气泡只记 id 列表并渲染 <SubtaskCard>。
|
||||
const updateSubtask = useUpdateSubtask();
|
||||
// 已识别的 task tool_call_id —— 用于在收到 tool 结果帧时只认领「子智能体任务」结果,
|
||||
// 不误把 write_file 等其它工具的结果当成子任务处理。
|
||||
const knownTaskIdsRef = useRef<Set<string>>(new Set());
|
||||
|
||||
/** 把某个子任务 id 记到对应席位气泡上(新引用 → 触发气泡重渲染,卡片随之刷新状态)。 */
|
||||
const touchBubbleSubtaskId = useCallback((bubbleId: number, taskId: string) => {
|
||||
setStep2RoundtableDialogues((prev) =>
|
||||
prev.map((d) => {
|
||||
if (d.id !== bubbleId) return d;
|
||||
const ids = d.subtaskIds ?? [];
|
||||
// 每次都换新数组引用,确保状态(in_progress→completed/failed)变化时卡片重渲染。
|
||||
return { ...d, subtaskIds: ids.includes(taskId) ? [...ids] : [...ids, taskId] };
|
||||
}),
|
||||
);
|
||||
}, []);
|
||||
|
||||
/** 处理一条消息(values 快照里的整条 message,或 messages-tuple 的 chunk)的子任务语义。 */
|
||||
const ingestSubagentMessage = useCallback(
|
||||
(msg: Record<string, unknown>, bubbleId: number) => {
|
||||
// (1) AI 消息:抓 task 工具调用 → 建/更新 in_progress 子任务。
|
||||
const toolCalls = msg.tool_calls;
|
||||
if (Array.isArray(toolCalls)) {
|
||||
for (const tc of toolCalls) {
|
||||
if (!tc || typeof tc !== "object") continue;
|
||||
const t = tc as Record<string, unknown>;
|
||||
if (t.name !== "task") continue;
|
||||
const id = typeof t.id === "string" ? t.id : "";
|
||||
if (!id) continue;
|
||||
const a = (t.args && typeof t.args === "object" ? t.args : {}) as Record<string, unknown>;
|
||||
updateSubtask({
|
||||
id,
|
||||
status: "in_progress",
|
||||
subagent_type: typeof a.subagent_type === "string" ? a.subagent_type : "",
|
||||
description: typeof a.description === "string" ? a.description : "",
|
||||
prompt: typeof a.prompt === "string" ? a.prompt : "",
|
||||
});
|
||||
knownTaskIdsRef.current.add(id);
|
||||
touchBubbleSubtaskId(bubbleId, id);
|
||||
}
|
||||
}
|
||||
// (2) tool 结果消息:命中已知 task id 时按前缀判完成/失败(与主聊天解析一致)。
|
||||
const type = typeof msg.type === "string" ? msg.type.toLowerCase() : "";
|
||||
if (type === "tool") {
|
||||
const taskId = typeof msg.tool_call_id === "string" ? msg.tool_call_id : "";
|
||||
if (taskId && knownTaskIdsRef.current.has(taskId)) {
|
||||
const result = extractFrameText(msg.content);
|
||||
if (result.startsWith("Task Succeeded. Result:")) {
|
||||
updateSubtask({
|
||||
id: taskId,
|
||||
status: "completed",
|
||||
result: result.split("Task Succeeded. Result:")[1]?.trim(),
|
||||
});
|
||||
} else if (result.startsWith("Task failed.")) {
|
||||
updateSubtask({
|
||||
id: taskId,
|
||||
status: "failed",
|
||||
error: result.split("Task failed.")[1]?.trim(),
|
||||
});
|
||||
} else if (result.startsWith("Task timed out")) {
|
||||
updateSubtask({ id: taskId, status: "failed", error: result });
|
||||
}
|
||||
touchBubbleSubtaskId(bubbleId, taskId);
|
||||
}
|
||||
}
|
||||
},
|
||||
[updateSubtask, touchBubbleSubtaskId],
|
||||
);
|
||||
|
||||
const ingestSubagentTaskFrame = useCallback(
|
||||
(frame: unknown, bubbleId: number) => {
|
||||
// custom 事件帧(ultra 席位子智能体进度):task_running 带子智能体最新消息 → 回填
|
||||
// latestMessage(卡片实时显示「正在调用 X 工具」);完成/失败即时定状态(比 values 更快)。
|
||||
const ev = asSubagentTaskEvent(frame);
|
||||
if (ev) {
|
||||
knownTaskIdsRef.current.add(ev.task_id);
|
||||
if (ev.type === "task_running") {
|
||||
// latestMessage 非空才会触发 SubtaskContext setTasks 重渲染(见 useUpdateSubtask)。
|
||||
updateSubtask({ id: ev.task_id, status: "in_progress", latestMessage: ev.message as never });
|
||||
} else if (ev.type === "task_started") {
|
||||
updateSubtask({
|
||||
id: ev.task_id,
|
||||
status: "in_progress",
|
||||
description: typeof ev.description === "string" ? ev.description : undefined,
|
||||
});
|
||||
} else if (ev.type === "task_completed") {
|
||||
updateSubtask({
|
||||
id: ev.task_id,
|
||||
status: "completed",
|
||||
result: typeof ev.result === "string" ? ev.result : extractFrameText(ev.result),
|
||||
});
|
||||
} else if (
|
||||
ev.type === "task_failed" ||
|
||||
ev.type === "task_cancelled" ||
|
||||
ev.type === "task_timed_out"
|
||||
) {
|
||||
updateSubtask({
|
||||
id: ev.task_id,
|
||||
status: "failed",
|
||||
error: typeof ev.error === "string" ? ev.error : "子智能体任务失败",
|
||||
});
|
||||
}
|
||||
touchBubbleSubtaskId(bubbleId, ev.task_id);
|
||||
return;
|
||||
}
|
||||
|
||||
// values 快照帧:{messages:[...]} —— 权威来源,按整条消息列表对账(子任务完成/失败)。
|
||||
if (frame && typeof frame === "object" && !Array.isArray(frame)) {
|
||||
const msgs = (frame as Record<string, unknown>).messages;
|
||||
if (Array.isArray(msgs)) {
|
||||
for (const m of msgs) {
|
||||
if (m && typeof m === "object") ingestSubagentMessage(m as Record<string, unknown>, bubbleId);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
// messages-tuple 帧:[chunk, metadata] —— 增量,派活时即时建卡。
|
||||
if (!Array.isArray(frame) || frame.length === 0) return;
|
||||
const chunk = frame[0];
|
||||
if (!chunk || typeof chunk !== "object") return;
|
||||
ingestSubagentMessage(chunk as Record<string, unknown>, bubbleId);
|
||||
},
|
||||
[ingestSubagentMessage, updateSubtask, touchBubbleSubtaskId],
|
||||
);
|
||||
|
||||
// ─── Dialogue / Speaker helpers ────────────────────────────────────
|
||||
const appendDialogue = useCallback(
|
||||
(card: {
|
||||
@@ -1406,6 +1600,8 @@ export function useStep2Orchestration(
|
||||
newMessage: fullTask,
|
||||
peerDeliveries: priorDeliveries,
|
||||
model: perSeatModel || selectedModelRef.current || undefined,
|
||||
// 席位执行模式(快速/思考/专业问答/多智能体问答)→ thinking/reasoning/subagent。
|
||||
...seatModeToRequestFields(selectedModeRef.current),
|
||||
signal: subAborter.signal,
|
||||
onTextDelta: (text) =>
|
||||
a.isParallel ? ingestParallelDelta(a.bubbleId, text) : appendToDialogue(a.bubbleId, text),
|
||||
@@ -1415,7 +1611,10 @@ export function useStep2Orchestration(
|
||||
appendStepIfNew(a.bubbleId, label, `${phase}:${toolName ?? ""}`, args);
|
||||
handleArtifactToolPhase(phase, toolName, args, a.seatThreadId);
|
||||
},
|
||||
onUpstreamFrame: (frame) => handleUpstreamFrame(frame, a.seatThreadId),
|
||||
onUpstreamFrame: (frame) => {
|
||||
handleUpstreamFrame(frame, a.seatThreadId);
|
||||
ingestSubagentTaskFrame(frame, a.bubbleId);
|
||||
},
|
||||
});
|
||||
activeAbortersRef.current.delete(subAborter);
|
||||
if (isStale()) {
|
||||
@@ -1690,6 +1889,7 @@ export function useStep2Orchestration(
|
||||
triggerToast,
|
||||
handleArtifactToolPhase,
|
||||
handleUpstreamFrame,
|
||||
ingestSubagentTaskFrame,
|
||||
resolveSeatThreadId,
|
||||
],
|
||||
);
|
||||
@@ -1829,6 +2029,8 @@ export function useStep2Orchestration(
|
||||
displayName: seatName,
|
||||
newMessage: task,
|
||||
model: perSeatModel || selectedModelRef.current || undefined,
|
||||
// 席位执行模式 → thinking/reasoning/subagent(与推荐/DAG 路径一致)。
|
||||
...seatModeToRequestFields(selectedModeRef.current),
|
||||
signal: subAborter.signal,
|
||||
onTextDelta: (text) => appendToDialogue(subBubbleId, text),
|
||||
onPhaseChange: (phase, toolName, args) => {
|
||||
@@ -1837,7 +2039,10 @@ export function useStep2Orchestration(
|
||||
appendStepIfNew(subBubbleId, label, `${phase}:${toolName ?? ""}`, args);
|
||||
handleArtifactToolPhase(phase, toolName, args, seatThreadId);
|
||||
},
|
||||
onUpstreamFrame: (frame) => handleUpstreamFrame(frame, seatThreadId),
|
||||
onUpstreamFrame: (frame) => {
|
||||
handleUpstreamFrame(frame, seatThreadId);
|
||||
ingestSubagentTaskFrame(frame, subBubbleId);
|
||||
},
|
||||
});
|
||||
if (isStale()) {
|
||||
finalizeDialogue(subBubbleId, specRes.content || "(已停止)", "已停止");
|
||||
@@ -1936,6 +2141,7 @@ export function useStep2Orchestration(
|
||||
triggerToast,
|
||||
handleArtifactToolPhase,
|
||||
handleUpstreamFrame,
|
||||
ingestSubagentTaskFrame,
|
||||
resolveSeatThreadId,
|
||||
],
|
||||
);
|
||||
@@ -2163,6 +2369,8 @@ export function useStep2Orchestration(
|
||||
// 前序各阶段的完整交付 → 供本席位 read_peer_delivery 按需取全文(§12.9)。
|
||||
peerDeliveries: priorDeliveries,
|
||||
model: perSeatModel || selectedModelRef.current || undefined,
|
||||
// 席位执行模式 → thinking/reasoning/subagent(与推荐/链条路径一致)。
|
||||
...seatModeToRequestFields(selectedModeRef.current),
|
||||
signal: subAborter.signal,
|
||||
// §6:并行席位走 ref 全量累积 + 节流 flush(只渲染选中的);单节点
|
||||
// stage 实际串行,1 路流直接 setState 不卡,沿用 appendToDialogue。
|
||||
@@ -2174,7 +2382,10 @@ export function useStep2Orchestration(
|
||||
appendStepIfNew(bubbleId, label, `${phase}:${toolName ?? ""}`, args);
|
||||
handleArtifactToolPhase(phase, toolName, args, seatThreadId);
|
||||
},
|
||||
onUpstreamFrame: (frame) => handleUpstreamFrame(frame, seatThreadId),
|
||||
onUpstreamFrame: (frame) => {
|
||||
handleUpstreamFrame(frame, seatThreadId);
|
||||
ingestSubagentTaskFrame(frame, bubbleId);
|
||||
},
|
||||
});
|
||||
if (isStale()) {
|
||||
finalizeDialogue(bubbleId, specRes.content || "(已停止)", "已停止");
|
||||
@@ -2276,6 +2487,7 @@ export function useStep2Orchestration(
|
||||
triggerToast,
|
||||
handleArtifactToolPhase,
|
||||
handleUpstreamFrame,
|
||||
ingestSubagentTaskFrame,
|
||||
resolveSeatThreadId,
|
||||
ingestParallelDelta,
|
||||
resetParallelStreams,
|
||||
|
||||
Reference in new issue
Block a user