wujie应用联调
This commit is contained in:
1 parent
0784f30e23
commit
f3ca996116
35 files changed
+1590
-334
No files matched your search
@@ -97,6 +97,8 @@ import { getChain } from "@/roundtable-planning/api/chains";
|
||||
import { filterRecommendCandidates } from "@/roundtable-planning/api/recommend";
|
||||
import { listAgents } from "@/core/agents";
|
||||
import { listBusinessMappings } from "@/strategy-components/api/business-mapping";
|
||||
import { emitWujieEvent, isWujieEnv, onWujieEvent, readWujieProps } from "@/core/embed/wujie";
|
||||
import { collectRoundtableDeliverables } from "@/roundtable-planning/lib/roundtable-deliverables";
|
||||
|
||||
/** 从任务页带进来的预填(经 navigation state 传递)。见会商自动化串联(模块 C)。 */
|
||||
interface RoundtablePrefill {
|
||||
@@ -104,12 +106,52 @@ interface RoundtablePrefill {
|
||||
taskTitle?: string;
|
||||
/** 任务描述(注入 Step 1 首条用户消息)。 */
|
||||
taskGoal?: string;
|
||||
/** 指定业务链条 id(wujie 抽屉直传,优先于 businessCode;据此自动选链)。 */
|
||||
chainId?: string;
|
||||
/** 来源业务码(如 "6BF"):据此查业务映射拿到要自动选用的业务链。 */
|
||||
businessCode?: string;
|
||||
/** 外部任务 id(无界抽屉):聊天记录按此存取、打开时回显最新一条。 */
|
||||
taskId?: string;
|
||||
/** 是否进入即自动开跑 Step 1 意图分析。 */
|
||||
autoStart?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 无界(wujie)抽屉场景:父页面通过 `window.$wujie.props` 注入「任务名称/描述/业务链条」。
|
||||
* iframe 降级时 props 可能晚于首帧,故再读 hash 路由 query 作兜底(宿主 `appendEmbedQueryToUrl` 写入)。
|
||||
*/
|
||||
function readWujiePrefill(): RoundtablePrefill | null {
|
||||
if (!isWujieEnv()) return null;
|
||||
const p = readWujieProps();
|
||||
const taskTitle = typeof p.taskTitle === "string" ? p.taskTitle : undefined;
|
||||
const taskGoal = typeof p.taskGoal === "string" ? p.taskGoal : undefined;
|
||||
const chainId = typeof p.chainId === "string" ? p.chainId : undefined;
|
||||
const businessCode = typeof p.businessCode === "string" ? p.businessCode : undefined;
|
||||
const taskId = typeof p.taskId === "string" ? p.taskId : undefined;
|
||||
if (!taskTitle && !taskGoal && !chainId && !businessCode && !taskId) {
|
||||
return readEmbedHashQueryPrefill();
|
||||
}
|
||||
return { taskTitle, taskGoal, chainId, businessCode, taskId, autoStart: true };
|
||||
}
|
||||
|
||||
/** 从 `#/embed/roundtable?…` 的 hash query 读取预填(iframe 降级兜底)。 */
|
||||
function readEmbedHashQueryPrefill(): RoundtablePrefill | null {
|
||||
if (typeof window === "undefined") return null;
|
||||
const hash = window.location.hash || "";
|
||||
if (!hash.includes("/embed/roundtable")) return null;
|
||||
const qIndex = hash.indexOf("?");
|
||||
if (qIndex < 0) return null;
|
||||
const params = new URLSearchParams(hash.slice(qIndex + 1));
|
||||
const taskTitle = params.get("taskTitle") ?? undefined;
|
||||
const taskGoal = params.get("taskGoal") ?? undefined;
|
||||
const chainId = params.get("chainId") ?? undefined;
|
||||
const businessCode = params.get("businessCode") ?? undefined;
|
||||
const taskId = params.get("taskId") ?? undefined;
|
||||
if (!taskTitle && !taskGoal && !chainId && !businessCode && !taskId) return null;
|
||||
return { taskTitle, taskGoal, chainId, businessCode, taskId, autoStart: true };
|
||||
}
|
||||
|
||||
|
||||
export default function RoundtablePlanningPage() {
|
||||
const { theme } = useTheme();
|
||||
const isDark = theme === "dark";
|
||||
@@ -118,13 +160,23 @@ export default function RoundtablePlanningPage() {
|
||||
|
||||
// ─── 会商自动化串联(模块 C):任务页带进来的预填 ─────────────────
|
||||
// 只在首次渲染读一次 navigation state;随后清掉 history state,避免刷新/后退重放。
|
||||
// navigation state(站内跳转)优先;无界抽屉场景回退读 window.$wujie.props。
|
||||
const prefillRef = useRef<RoundtablePrefill | null>(
|
||||
((location.state as { roundtablePrefill?: RoundtablePrefill } | null)?.roundtablePrefill) ?? null,
|
||||
((location.state as { roundtablePrefill?: RoundtablePrefill } | null)?.roundtablePrefill) ??
|
||||
readWujiePrefill(),
|
||||
);
|
||||
// 由 prefill.businessCode 解析出的「自动选用业务链」结果;有值时「进入研讨」跳过选链弹窗直接进 Step 2。
|
||||
const [autoChainResult, setAutoChainResult] = useState<SeatSelectionResult | null>(null);
|
||||
const autoStartedRef = useRef(false);
|
||||
const prefillClearedRef = useRef(false);
|
||||
// 共识达成后只向父页面(无界)回传一次交付结果。
|
||||
const consensusEmittedRef = useRef(false);
|
||||
// 带 taskId 时,先按任务回显最新草稿再决定是否 autoStart。用 state 而非 ref:
|
||||
// 解析完成需触发重渲染让 C2 effect 重跑(否则 intentThreadId 先就绪会错过 autoStart)。
|
||||
// 无 taskId 时初始即「已解析」,autoStart 照常。
|
||||
const [taskRestoreResolved, setTaskRestoreResolved] = useState<boolean>(
|
||||
!prefillRef.current?.taskId,
|
||||
);
|
||||
|
||||
const { models: availableModels, isLoading: modelsLoading } = useModels();
|
||||
|
||||
@@ -448,6 +500,7 @@ export default function RoundtablePlanningPage() {
|
||||
currentStep,
|
||||
setCurrentStep,
|
||||
triggerToast,
|
||||
taskId: prefillRef.current?.taskId ?? null,
|
||||
intentSending: step1.isIntentSending,
|
||||
step2FinalizedCount,
|
||||
step3SavedTick,
|
||||
@@ -638,6 +691,8 @@ export default function RoundtablePlanningPage() {
|
||||
step2.resetStep2State();
|
||||
step2.setSelectedAgents(normalized);
|
||||
step2.resetInitGate();
|
||||
// 新一轮研讨 → 允许共识达成后再次向父页面回传。
|
||||
consensusEmittedRef.current = false;
|
||||
// result.mode 决定 Step 2 编排:recommend = 总控自由派活;chain = 按链条顺序派活;
|
||||
// dag = 分层并行(来源链条带 stages,携带 result.plan)。
|
||||
setOrchestrationMode(result.mode);
|
||||
@@ -669,11 +724,34 @@ export default function RoundtablePlanningPage() {
|
||||
}
|
||||
}, []);
|
||||
|
||||
// C1.5(无界回显):带 taskId 时,挂载即按任务取最新草稿回显。命中 → 抑制 autoStart
|
||||
// (避免重复发首条消息);未命中 → 放行 autoStart 走全新任务。只跑一次。
|
||||
useEffect(() => {
|
||||
const tid = prefillRef.current?.taskId;
|
||||
if (!tid) return;
|
||||
let cancelled = false;
|
||||
void (async () => {
|
||||
try {
|
||||
const restored = await drafts.loadLatestByTask(tid);
|
||||
if (cancelled) return;
|
||||
if (restored) autoStartedRef.current = true; // 命中历史 → 不再自动发首条消息
|
||||
} finally {
|
||||
if (!cancelled) setTaskRestoreResolved(true);
|
||||
}
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []); // 仅挂载时执行一次
|
||||
|
||||
// C2:带 autoStart 时,等 Step 1 意图线程就绪后自动把「任务名称/描述」作为首条用户消息发出,
|
||||
// 触发任务理解智能体自动分析(只发一次)。
|
||||
useEffect(() => {
|
||||
const prefill = prefillRef.current;
|
||||
if (!prefill?.autoStart || autoStartedRef.current) return;
|
||||
// 带 taskId 时,等「按任务回显」决策完成再决定是否 autoStart,避免与历史回显抢跑。
|
||||
if (!taskRestoreResolved) return;
|
||||
if (currentStep !== 1) return;
|
||||
if (!step1.intentThreadId || step1.intentReady) return;
|
||||
const title = prefill.taskTitle?.trim();
|
||||
@@ -684,7 +762,7 @@ export default function RoundtablePlanningPage() {
|
||||
if (!text) return;
|
||||
autoStartedRef.current = true;
|
||||
void step1.sendIntentMessage(text);
|
||||
}, [currentStep, step1.intentThreadId, step1.intentReady, step1.sendIntentMessage]);
|
||||
}, [currentStep, taskRestoreResolved, step1.intentThreadId, step1.intentReady, step1.sendIntentMessage]);
|
||||
|
||||
// C3:据 prefill.businessCode 查业务映射 → 取 chainId → 拉公共链 + 候选智能体 → 构造自动选链结果。
|
||||
// 解析成功后「进入研讨」会跳过选链弹窗直接据此进 Step 2;解析失败(未配置 / 链不存在 / 席位不足)
|
||||
@@ -695,13 +773,16 @@ export default function RoundtablePlanningPage() {
|
||||
// 末次 setup 正常落地(生产无 StrictMode 只跑一次)。
|
||||
useEffect(() => {
|
||||
const prefill = prefillRef.current;
|
||||
if (!prefill?.businessCode) return;
|
||||
if (!prefill?.chainId && !prefill?.businessCode) return;
|
||||
let cancelled = false;
|
||||
void (async () => {
|
||||
try {
|
||||
const mappings = await listBusinessMappings();
|
||||
const row = mappings.find((m) => m.businessCode === prefill.businessCode);
|
||||
const chainId = row?.chainId;
|
||||
// chainId 直传(无界抽屉)优先;否则据 businessCode 查业务映射拿 chainId。
|
||||
let chainId: string | null | undefined = prefill.chainId;
|
||||
if (!chainId && prefill.businessCode) {
|
||||
const mappings = await listBusinessMappings();
|
||||
chainId = mappings.find((m) => m.businessCode === prefill.businessCode)?.chainId;
|
||||
}
|
||||
if (!chainId) return;
|
||||
const [chain, agents] = await Promise.all([
|
||||
getChain(chainId),
|
||||
@@ -720,6 +801,31 @@ export default function RoundtablePlanningPage() {
|
||||
};
|
||||
}, []);
|
||||
|
||||
// C4(无界回传):第二步达成共识后,把总控结论 + 各智能体交付一次性广播给父页面。
|
||||
// 用 ref 防重(共识态会多次触发渲染);非无界环境静默跳过。
|
||||
useEffect(() => {
|
||||
if (!step2.hasConsensus || consensusEmittedRef.current) return;
|
||||
if (!isWujieEnv()) return;
|
||||
consensusEmittedRef.current = true;
|
||||
emitWujieEvent("roundtable:consensus", {
|
||||
taskTitle: prefillRef.current?.taskTitle ?? null,
|
||||
chainId: prefillRef.current?.chainId ?? null,
|
||||
chainTitle: chainMeta?.title ?? null,
|
||||
coordinatorName: step2.coordinatorName,
|
||||
consensusText: step2.lastLeaderContent,
|
||||
deliverables: collectRoundtableDeliverables(
|
||||
step2.step2RoundtableDialogues,
|
||||
step2.coordinatorName,
|
||||
),
|
||||
});
|
||||
}, [
|
||||
step2.hasConsensus,
|
||||
step2.coordinatorName,
|
||||
step2.lastLeaderContent,
|
||||
step2.step2RoundtableDialogues,
|
||||
chainMeta,
|
||||
]);
|
||||
|
||||
// 把页面重置回「第一步全新任务」——新建任务 + 后台挂起后都复用。
|
||||
// 注意:只清前端状态,不删后端已建的草稿 / 已挂起的后台作业(它们继续在后台跑,
|
||||
// 在历史记录里可见)。
|
||||
@@ -736,6 +842,8 @@ export default function RoundtablePlanningPage() {
|
||||
step1.stopIntentStream();
|
||||
drafts.loadedFromDraftRef.current = false;
|
||||
drafts.setCurrentDraftId(null);
|
||||
// 重置后新一轮共识仍需回传父页面。
|
||||
consensusEmittedRef.current = false;
|
||||
setCurrentStep(1);
|
||||
// 同步触发 Step 1 init,而不是依赖 useEffect —— 已经在 Step 1 时
|
||||
// currentStep 不变,useEffect 不会 re-fire。
|
||||
@@ -747,6 +855,14 @@ export default function RoundtablePlanningPage() {
|
||||
triggerToast("✨ 已开始新任务,请在第一步与任务理解智能体澄清需求");
|
||||
}, [resetToStep1, triggerToast]);
|
||||
|
||||
// 无界抽屉保活复用:父页面重开抽屉时 `bus.$emit('roundtable:reset')` → 子应用回到第一步。
|
||||
// 非无界环境下 onWujieEvent 返回 no-op,安全无副作用。
|
||||
useEffect(() => {
|
||||
return onWujieEvent("roundtable:reset", () => {
|
||||
resetToStep1();
|
||||
});
|
||||
}, [resetToStep1]);
|
||||
|
||||
// 「后台挂起」:把当前研讨交给后端自动跑到 Step3 结果绘制完成;模型沿用第二步选择。
|
||||
// 挂起后页面像「新建任务」一样重置回第一步(后台作业继续在历史记录里跑)。
|
||||
const handleBackgroundSuspend = useCallback(async () => {
|
||||
|
||||
Reference in new issue
Block a user