wujie应用联调

This commit is contained in:
董宏凯 committed 2026-06-11 17:11:28 +08:00
1 parent 0784f30e23
commit f3ca996116
35 files changed
+1590 -334

No files matched your search

@@ -0,0 +1,81 @@
import assert from "node:assert/strict";
import test from "node:test";
import { collectRoundtableDeliverables } from "./roundtable-deliverables";
import type { Step2Dialogue } from "../hooks/useStep2Orchestration";
/** 构造一条最小 Step2Dialogue(只填测试关心的字段)。 */
function bubble(partial: Partial<Step2Dialogue> & { sender: string }): Step2Dialogue {
return {
id: partial.id ?? Math.floor(Math.random() * 1e6),
sender: partial.sender,
avatarType: partial.avatarType ?? "default",
content: partial.content ?? "",
time: partial.time ?? "00:00",
confidence: partial.confidence ?? "",
streaming: partial.streaming,
agentThreadId: partial.agentThreadId,
steps: partial.steps,
};
}
test("收集每个席位的交付,剔除总控", () => {
const dialogues = [
bubble({ sender: "总控", content: "派活中…" }),
bubble({ sender: "方案设计", content: "方案A", agentThreadId: "t-a" }),
bubble({ sender: "风险审查", content: "风险B", agentThreadId: "t-b" }),
bubble({ sender: "总控", content: "已达成共识" }),
];
const result = collectRoundtableDeliverables(dialogues, "总控");
assert.deepEqual(result, [
{ agentName: "方案设计", content: "方案A", threadId: "t-a" },
{ agentName: "风险审查", content: "风险B", threadId: "t-b" },
]);
});
test("同一席位多轮发言只保留最后一条", () => {
const dialogues = [
bubble({ sender: "方案设计", content: "初稿" }),
bubble({ sender: "方案设计", content: "终稿", agentThreadId: "t-final" }),
];
const result = collectRoundtableDeliverables(dialogues, null);
assert.equal(result.length, 1);
assert.deepEqual(result[0], { agentName: "方案设计", content: "终稿", threadId: "t-final" });
});
test("跳过流式中(streaming)与空内容气泡", () => {
const dialogues = [
bubble({ sender: "方案设计", content: "正在生成", streaming: true }),
bubble({ sender: "风险审查", content: " " }), // 空白
bubble({ sender: "数据分析", content: "有效交付" }),
];
const result = collectRoundtableDeliverables(dialogues, null);
assert.deepEqual(result, [{ agentName: "数据分析", content: "有效交付", threadId: null }]);
});
test("流式气泡被同席位后续完成稿覆盖", () => {
const dialogues = [
bubble({ sender: "方案设计", content: "流式片段", streaming: true }),
bubble({ sender: "方案设计", content: "完成稿", agentThreadId: "t-x" }),
];
const result = collectRoundtableDeliverables(dialogues, null);
assert.deepEqual(result, [{ agentName: "方案设计", content: "完成稿", threadId: "t-x" }]);
});
test("无 agentThreadId 时 threadId 为 null", () => {
const result = collectRoundtableDeliverables([bubble({ sender: "A", content: "x" })], null);
assert.equal(result[0]!.threadId, null);
});
test("空输入返回空数组", () => {
assert.deepEqual(collectRoundtableDeliverables([], "总控"), []);
});
test("coordinatorName 为 null 时不剔除任何席位", () => {
const dialogues = [
bubble({ sender: "总控", content: "也算一条" }),
bubble({ sender: "方案设计", content: "方案A" }),
];
const result = collectRoundtableDeliverables(dialogues, null);
assert.equal(result.length, 2);
});
@@ -0,0 +1,35 @@
import type { Step2Dialogue } from "../hooks/useStep2Orchestration";
/**
* 回传父页面(无界)的单个智能体交付。
* 与 Vue 宿主 `roundtable-embed/RoundtableDrawer.vue` 的 `RoundtableDeliverable` 对齐。
*/
export interface RoundtableDeliverable {
agentName: string;
content: string;
threadId: string | null;
}
/**
* 从 Step 2 全部对话气泡里收集「各智能体最终交付」。
*
* 规则:按发言者(`sender`)分组,取每个席位**最后一条**「已完成(非流式)且非空」的气泡;
* 总控(coordinator)单独回传(`consensusText`),故在此剔除。纯函数,便于单测。
*/
export function collectRoundtableDeliverables(
dialogues: Step2Dialogue[],
coordinatorName: string | null,
): RoundtableDeliverable[] {
const lastBySeat = new Map<string, Step2Dialogue>();
for (const d of dialogues) {
if (d.streaming) continue;
if (!d.content?.trim()) continue;
if (coordinatorName && d.sender === coordinatorName) continue;
lastBySeat.set(d.sender, d); // 后出现的覆盖前者 → 每席位保留最后一条
}
return Array.from(lastBySeat.values()).map((d) => ({
agentName: d.sender,
content: d.content,
threadId: d.agentThreadId ?? null,
}));
}