圆桌第三步与业务链条增强:主题跟随/插话暂停/提示词优化/结构化流程图
- 结果绘制跟随日/夜间主题(深色按深蓝 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
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* flow-graph.ts 纯函数单测。
|
||||
* 运行方式(项目无 vitest,对齐 dag-types.test.ts):
|
||||
* npx esbuild src/roundtable-planning/lib/flow-graph.test.ts --bundle --format=esm \
|
||||
* --platform=node --outfile=.tmp-tests/flow-graph.test.mjs
|
||||
* node --test .tmp-tests/flow-graph.test.mjs
|
||||
*/
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import {
|
||||
extractFlowGraph,
|
||||
layoutFlowGraph,
|
||||
stripFlowFence,
|
||||
} from "./flow-graph";
|
||||
|
||||
const FULL = [
|
||||
"报告正文……",
|
||||
"```flow-json",
|
||||
'{"title":"方案执行流程","nodes":[',
|
||||
'{"id":"n1","label":"环境评估","type":"stage","detail":"评估现场环境"},',
|
||||
'{"id":"n2","label":"编制方案","type":"task","from":["n1"]},',
|
||||
'{"id":"n3","label":"是否可行","type":"decision","from":[{"id":"n2","label":"评审"}]}',
|
||||
"]}",
|
||||
"```",
|
||||
].join("\n");
|
||||
|
||||
test("extractFlowGraph:完整块解析出节点/边/标题", () => {
|
||||
const g = extractFlowGraph(FULL);
|
||||
assert.ok(g);
|
||||
assert.equal(g.title, "方案执行流程");
|
||||
assert.equal(g.nodes.length, 3);
|
||||
assert.equal(g.nodes[0].type, "stage");
|
||||
assert.deepEqual(g.edges, [
|
||||
{ from: "n1", to: "n2" },
|
||||
{ from: "n2", to: "n3", label: "评审" },
|
||||
]);
|
||||
});
|
||||
|
||||
test("extractFlowGraph:流式半截(fence 未闭合 + 尾对象截断)只取完整节点", () => {
|
||||
const partial = [
|
||||
"正文",
|
||||
"```flow-json",
|
||||
'{"title":"T","nodes":[',
|
||||
'{"id":"a","label":"A","type":"start"},',
|
||||
'{"id":"b","label":"B","type":"task","from":["a"]},',
|
||||
'{"id":"c","label":"C","ty', // 截断
|
||||
].join("\n");
|
||||
const g = extractFlowGraph(partial);
|
||||
assert.ok(g);
|
||||
assert.equal(g.nodes.length, 2);
|
||||
assert.deepEqual(g.edges, [{ from: "a", to: "b" }]);
|
||||
});
|
||||
|
||||
test("extractFlowGraph:未知 type 落 task、重复 id 去重、悬空边丢弃", () => {
|
||||
const text = [
|
||||
"```flow-json",
|
||||
'{"nodes":[',
|
||||
'{"id":"x","label":"X","type":"banana"},',
|
||||
'{"id":"x","label":"X-dup","type":"task"},',
|
||||
'{"id":"y","label":"Y","type":"risk","from":["x","ghost"]}',
|
||||
"]}",
|
||||
"```",
|
||||
].join("\n");
|
||||
const g = extractFlowGraph(text);
|
||||
assert.ok(g);
|
||||
assert.equal(g.nodes.length, 2);
|
||||
assert.equal(g.nodes[0].type, "task");
|
||||
assert.equal(g.nodes[0].label, "X");
|
||||
assert.deepEqual(g.edges, [{ from: "x", to: "y" }]);
|
||||
});
|
||||
|
||||
test("extractFlowGraph:无 fence / 无完整节点返回 null", () => {
|
||||
assert.equal(extractFlowGraph("普通回复,没有结构化数据"), null);
|
||||
assert.equal(extractFlowGraph('```flow-json\n{"nodes":[{"id":"a"'), null);
|
||||
});
|
||||
|
||||
test("extractFlowGraph:兼容独立 edges 数组(source/target 别名)", () => {
|
||||
const text = [
|
||||
"```flow-json",
|
||||
'{"nodes":[{"id":"a","label":"A"},{"id":"b","label":"B"}],',
|
||||
'"edges":[{"source":"a","target":"b","label":"走"}]}',
|
||||
"```",
|
||||
].join("\n");
|
||||
const g = extractFlowGraph(text);
|
||||
assert.ok(g);
|
||||
assert.deepEqual(g.edges, [{ from: "a", to: "b", label: "走" }]);
|
||||
});
|
||||
|
||||
test("stripFlowFence:闭合块替换为引导语并保留前后文", () => {
|
||||
const out = stripFlowFence(FULL, false);
|
||||
assert.ok(out.includes("报告正文"));
|
||||
assert.ok(!out.includes("```flow-json"));
|
||||
assert.ok(out.includes("已生成结构化流程数据"));
|
||||
});
|
||||
|
||||
test("stripFlowFence:未闭合(流式中)用「正在输出」措辞", () => {
|
||||
const out = stripFlowFence('正文\n```flow-json\n{"nodes":[', true);
|
||||
assert.ok(out.includes("正在输出结构化流程数据"));
|
||||
assert.ok(!out.includes("```flow-json"));
|
||||
});
|
||||
|
||||
test("layoutFlowGraph:按前驱分层(根 0 层,子层递增),保持原始顺序", () => {
|
||||
const g = extractFlowGraph(FULL)!;
|
||||
const positioned = layoutFlowGraph(g);
|
||||
assert.equal(positioned[0].y, 0);
|
||||
assert.ok(positioned[1].y > positioned[0].y);
|
||||
assert.ok(positioned[2].y > positioned[1].y);
|
||||
assert.deepEqual(positioned.map((n) => n.id), ["n1", "n2", "n3"]);
|
||||
});
|
||||
|
||||
test("layoutFlowGraph:环不死循环", () => {
|
||||
const text = [
|
||||
"```flow-json",
|
||||
'{"nodes":[{"id":"a","label":"A","from":["b"]},{"id":"b","label":"B","from":["a"]}]}',
|
||||
"```",
|
||||
].join("\n");
|
||||
const g = extractFlowGraph(text)!;
|
||||
const positioned = layoutFlowGraph(g);
|
||||
assert.equal(positioned.length, 2);
|
||||
positioned.forEach((n) => assert.ok(Number.isFinite(n.x) && Number.isFinite(n.y)));
|
||||
});
|
||||
Reference in new issue
Block a user