会议模式:一手势分工、节点可重复/无限循环、停止按钮、结果单开一屏
用户反馈的四条。
【1. 节点拖不动 → 改成"一指拖节点 / 两指移画布"】
复现出来是"拖节点变成了平移画布"。查的过程比较绕,值得记:
先后试过两种写法都不行:
a) 节点自己 detectDragGestures + 父级平移 → 父级总是赢
b) 节点按下就 consume 抢手势 → 还是父级赢
最后按用户提的**手指数分工**来做,才彻底没有争抢:
一指 → 拖手指底下那个节点(空白处则什么都不做)
两指 → 平移画布(按在哪都行)
★ 中途我一度以为"拖拽根本没生效",其实是**验证方法错了**:
测试点 (240,648) 落在空白处 —— 那个会议的节点早被拖到画布角落
(784,712)(784=CANVAS_W-NODE_W、712=CANVAS_H-NODE_H,正是四角限位),
跑出屏幕了。日志一打就清楚了。
所以测试脚本现在**先删掉旧会议、新建一个**,坐标才可预测。
【2. 停止按钮】
跑起来时"运行"变红色"停止"。一场会议可能跑好几分钟(每个智能体都是一次
完整模型调用),发现配错了却停不下来最让人抓狂。
点了停止会把还在"跑"的节点标成中断,不让界面上一直转圈。
【3. 节点可重复 / 无限循环】
原来引擎用 visited 集合(跑过就不再跑),环只转一圈 —— 用户要的是
"n1 → n2 → n1 只有一轮,但**能重复,可以无限循环**"。
改成**每个节点一个「最多执行次数」**:
1(默认) 只跑一次,有环也只转一圈 —— 和以前一样
2~20 环来回跑对应轮数
**0 无限循环**,靠「停止」收尾(两个智能体互相点评的用法)
节点卡片上会标 ×N / ∞,不然跑起来发现它转了三轮会很意外。
★ 敢开无限是有前提的:引擎每一轮都检查 should_stop(客户端断开或用户点停止),
所以"无限"实际是"跑到你喊停为止"。另外兜了个很大的硬上限,
防止用户忘了停或客户端异常断开时把额度烧光。
【4. 结果单开一屏】
节点卡片就那么点大,长回答只能看两行。新增「结果」:最终输出放最上面
(那才是用户要的),下面按**节点在图上从左到右的顺序**列各自的产出,
带「复制」按钮。按 x 坐标排而不是按事件到达顺序 —— 用户脑子里的顺序是
图上那个顺序。
【测试抓到的】
- 引擎改完漏了 `final_output = ''` 的初始化 → UnboundLocalError
- Kotlin `awaitPointerEvent` 是 AwaitPointerEventScope 的方法,不用 import
- 环用例的测试图**没有入口节点**(n1、n2 都有入边)→ 引擎直接报"没有入口节点",
跑不起来。真实的环一定是从某个起点进去的,测试图也得有
【验证】
- verify-meeting.mjs:新增 4 个环用例(1 轮 / 3 轮 / 无限+停止 / 第二轮拿到上一轮输出),
Node 与 Python **11/11 逐用例一致**,总共 29/29
- 模拟器实测:一指拖节点 → 节点移动、**连线跟着走**;一指拖空白 → 不动
- 全部回归:Markdown 19/19、语音 41/41 ×2、会议引擎 29/29、会议 HTTP 12/12 ×2
This commit is contained in:
@@ -143,7 +143,12 @@ function sanitizeNodes(nodes) {
|
||||
const ntype = String(n.type || '');
|
||||
if (!nid || seen.has(nid) || !NODE_TYPES.includes(ntype)) continue;
|
||||
seen.add(nid);
|
||||
out.push({ ...n, id: nid, type: ntype, x: Number(n.x) || 0, y: Number(n.y) || 0 });
|
||||
// 夹在 0~20:**0 = 无限循环**(两个智能体互相点评那种用法),1~20 是有限次。
|
||||
// 负数或大于 20 的值都不认,退回 1 —— 不然手改文件写成 99999 会一直烧额度。
|
||||
const raw = Number(n.maxRuns);
|
||||
const value = Number.isFinite(raw) ? Math.trunc(raw) : 1;
|
||||
const maxRuns = value <= 0 ? 0 : Math.min(value, 20);
|
||||
out.push({ ...n, id: nid, type: ntype, x: Number(n.x) || 0, y: Number(n.y) || 0, maxRuns });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -232,11 +237,43 @@ export async function runMeeting({ meeting, settings, userInput, emit, runAgentF
|
||||
}
|
||||
|
||||
const queue = starts.map((n) => n.id);
|
||||
const visited = new Set();
|
||||
|
||||
// ★ 每个节点跑了几次(不是"跑没跑过")。
|
||||
//
|
||||
// 用户要的是"n1 → n2 → n1 只有一轮,但**能重复**":
|
||||
// 默认每节点 1 次(= 不重复),把节点上的「最多执行次数」调大就能来回跑。
|
||||
// 以前用的是 visited 集合(跑过就不再跑),环永远只转一圈,没法重复。
|
||||
const runs = {};
|
||||
let steps = 0;
|
||||
const maxSteps = Math.max(20, nodes.length * 4);
|
||||
|
||||
/**
|
||||
* 节点的执行次数上限。**0 表示无限**。
|
||||
*
|
||||
* 为什么要支持无限:两个智能体互相点评(甲评乙、乙再评甲)是常见用法,
|
||||
* 用户希望一直怼下去,自己觉得够了再按停止。
|
||||
*
|
||||
* 为什么敢开无限:引擎每一轮都检查 shouldStop(客户端断开或用户点了停止),
|
||||
* 所以"无限"实际是"跑到你喊停为止"。另外兜了一个很大的硬上限,
|
||||
* 防止用户忘了停、或客户端异常断开时把额度烧光。
|
||||
*/
|
||||
const limitOf = (node) => {
|
||||
const raw = Number(node.maxRuns);
|
||||
const value = Number.isFinite(raw) ? Math.trunc(raw) : 1;
|
||||
return value <= 0 ? 0 : Math.min(value, 20);
|
||||
};
|
||||
|
||||
const budget = nodes.reduce((sum, n) => sum + (limitOf(n) || 200), 0);
|
||||
const maxSteps = Math.max(20, budget * 2 + nodes.length);
|
||||
let finalOutput = '';
|
||||
|
||||
const canRun = (id) => {
|
||||
const node = byId.get(id);
|
||||
if (!node) return false;
|
||||
const limit = limitOf(node);
|
||||
// 0 = 无限:永远还能再跑一次
|
||||
return limit === 0 || (runs[id] || 0) < limit;
|
||||
};
|
||||
|
||||
while (queue.length && steps < maxSteps) {
|
||||
if (shouldStop && shouldStop()) {
|
||||
emit({ type: 'meeting_done', output: finalOutput, aborted: true });
|
||||
@@ -245,31 +282,41 @@ export async function runMeeting({ meeting, settings, userInput, emit, runAgentF
|
||||
|
||||
const nodeId = queue.shift();
|
||||
steps += 1;
|
||||
if (visited.has(nodeId)) continue;
|
||||
visited.add(nodeId);
|
||||
if (!canRun(nodeId)) continue;
|
||||
|
||||
const node = byId.get(nodeId);
|
||||
if (!node) continue;
|
||||
|
||||
const runIndex = (runs[nodeId] || 0) + 1;
|
||||
runs[nodeId] = runIndex;
|
||||
const nodeType = node.type;
|
||||
const title = node.title
|
||||
|| { start: '初始输入', agent: '智能体', judge: '判断', end: '最终输出' }[nodeType]
|
||||
|| nodeType;
|
||||
emit({ type: 'node_start', nodeId, nodeType, title });
|
||||
emit({
|
||||
type: 'node_start',
|
||||
nodeId,
|
||||
nodeType,
|
||||
title,
|
||||
run: runIndex,
|
||||
maxRuns: limitOf(node),
|
||||
});
|
||||
|
||||
const input = collectInput(nodeId, edges, outputs);
|
||||
let nextIds = [];
|
||||
|
||||
try {
|
||||
if (nodeType === 'start') {
|
||||
const text = String(node.text || '').trim() || (userInput || '');
|
||||
// 第二轮开始,"初始输入"要把**自己上一轮的输出**当输入,
|
||||
// 否则循环回来的内容会被起点覆盖掉,重复就没意义了
|
||||
const text = input || String(node.text || '').trim() || (userInput || '');
|
||||
outputs[nodeId] = text;
|
||||
emit({ type: 'node_done', nodeId, output: text, note: '用的初始输入' });
|
||||
emit({ type: 'node_done', nodeId, output: text, run: runIndex, note: '用的初始输入' });
|
||||
nextIds = outgoing(edges, nodeId).map((e) => e.to);
|
||||
} else if (nodeType === 'agent') {
|
||||
const out = await runAgentFn(node, input, settings, emit, nodeId);
|
||||
outputs[nodeId] = out;
|
||||
emit({ type: 'node_done', nodeId, output: out });
|
||||
emit({ type: 'node_done', nodeId, output: out, run: runIndex });
|
||||
nextIds = outgoing(edges, nodeId).map((e) => e.to);
|
||||
} else if (nodeType === 'judge') {
|
||||
const kind = String(node.judgeKind || 'not_empty');
|
||||
@@ -289,19 +336,18 @@ export async function runMeeting({ meeting, settings, userInput, emit, runAgentF
|
||||
type: 'node_done',
|
||||
nodeId,
|
||||
output: input,
|
||||
run: runIndex,
|
||||
verdict: passed,
|
||||
branch: passed ? 'true' : 'false',
|
||||
note: `判断结果:${passed}`,
|
||||
});
|
||||
// 判断节点走 true / false 两条出边;没标分支的那条当默认(true)
|
||||
const outs = outgoing(edges, nodeId);
|
||||
nextIds = outs.filter((e) => (e.branch || 'true') === (passed ? 'true' : 'false')).map((e) => e.to);
|
||||
// 没连对应的分支就顺走第一条,免得图直接断在这儿
|
||||
if (!nextIds.length) nextIds = outs.slice(0, 1).map((e) => e.to);
|
||||
} else if (nodeType === 'end') {
|
||||
outputs[nodeId] = String(node.text || '').trim() || input;
|
||||
finalOutput = outputs[nodeId];
|
||||
emit({ type: 'node_done', nodeId, output: finalOutput });
|
||||
emit({ type: 'node_done', nodeId, output: finalOutput, run: runIndex });
|
||||
nextIds = [];
|
||||
} else {
|
||||
emit({ type: 'node_error', nodeId, error: `不认识的节点类型:${nodeType}` });
|
||||
@@ -309,13 +355,16 @@ export async function runMeeting({ meeting, settings, userInput, emit, runAgentF
|
||||
}
|
||||
} catch (err) {
|
||||
// 单个节点出错不该让整场会议停摆:记下来,继续跑下游
|
||||
emit({ type: 'node_error', nodeId, error: err.message });
|
||||
emit({ type: 'node_error', nodeId, error: err.message, run: runIndex });
|
||||
outputs[nodeId] = '';
|
||||
nextIds = outgoing(edges, nodeId).map((e) => e.to);
|
||||
}
|
||||
|
||||
// ★ 只有"还能再跑"的节点才重新入队。
|
||||
// 这就是"重复"的开关:maxRuns=1(默认)时跑过的节点不会再进来,环只转一圈;
|
||||
// 把它调大,环就会来回转到次数用完为止。
|
||||
for (const nid of nextIds) {
|
||||
if (!visited.has(nid)) queue.push(nid);
|
||||
if (canRun(nid)) queue.push(nid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user