会议模式:一手势分工、节点可重复/无限循环、停止按钮、结果单开一屏

用户反馈的四条。

【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:
l
2026-10-10 13:58:51 +08:00
parent 27686d6061
commit 24181cd6b6
5 changed files with 654 additions and 88 deletions

View File

@@ -0,0 +1,84 @@
/**
* 验证"一指拖节点 / 两指平移画布"。
*
* ★ 每次跑之前先**删掉所有旧会议、新建一个**。
* 原因:旧会议的节点坐标是历史遗留(可能被拖到画布角落、跑出屏幕),
* 测试点就会落在空白处 —— 上一轮我就是这么得出"节点拖不动"的错误结论的。
* 新建的会议用的是当前默认坐标,位置可预测。
*
* adb 模拟不了真两指,所以两指那项只做说明性检查(代码里已按手指数分支)。
*
* 用法: node scripts/device-meeting-drag.mjs <serial>
*/
import { spawnSync } from 'node:child_process';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
const SERIAL = process.argv[2] || 'emulator-5556';
const ADB = process.env.ADB || 'C:\\Android\\Sdk\\platform-tools\\adb.exe';
const OUT = path.join(os.tmpdir(), 'meeting-shots');
fs.mkdirSync(OUT, { recursive: true });
const sh = (...a) => spawnSync(ADB, ['-s', SERIAL, ...a], { encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 });
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
async function shot(n) {
sh('shell', 'screencap', '-p', '/sdcard/_s.png');
const dst = path.join(OUT, `${n}.png`);
sh('pull', '/sdcard/_s.png', dst);
return dst;
}
/** 去掉状态栏(时钟会变),只比较下面的内容区,避免"时钟变了"被误判成"画面变了" */
const bodyHash = (p) => {
const b = fs.readFileSync(p);
// PNG 没法简单裁,就按字节采样并跳过前 8KB(状态栏在图像顶部,
// PNG 是逐行压缩的,跳过开头基本能避开它)
let h = 0;
for (let i = 8192; i < b.length; i += 53) h = (h * 31 + b[i]) >>> 0;
return h.toString(16);
};
async function tap(x, y, w = 1400) { sh('shell', 'input', 'tap', String(x), String(y)); await sleep(w); }
const api = (p, opt) => sh('shell', `curl -s --max-time 10 ${opt || ''} http://127.0.0.1:5199${p}`).stdout || '';
console.log('清掉旧会议,建一个新的(坐标可预测)…');
const list = api('/api/meetings');
try {
for (const m of JSON.parse(list).meetings || []) {
api(`/api/meetings/${m.id}`, `-X DELETE`);
}
} catch { /* 没有就没有 */ }
api('/api/meetings', `-X POST -H 'Content-Type: application/json' -d '{"name":"DragTest"}'`);
await sleep(800);
console.log('导航到会议编辑器…');
sh('shell', 'input', 'keyevent', 'KEYCODE_WAKEUP');
sh('shell', 'svc', 'power', 'stayon', 'true');
sh('shell', 'am', 'start', '-n', 'com.doubao.lynxclone/.MainActivity');
await sleep(6000);
await tap(45, 105); // 抽屉
await tap(250, 561, 2500); // 会议模式
await tap(300, 300, 3500); // 打开会议
const before = await shot('40-before');
console.log(' 拖动前已截图');
// 新默认:n_start 在 (12,120)dp。密度 2.0、画布区从屏幕 y≈150px 开始。
// 所以节点大致在屏幕 (24..256, 390..566),取中心 (140, 470)。
console.log('① 一指拖「初始输入」节点');
sh('shell', 'input', 'swipe', '140', '470', '420', '700', '900');
await sleep(2500);
const afterDrag = await shot('41-after-node-drag');
console.log('② 一指拖空白处(应什么都不发生)');
sh('shell', 'input', 'swipe', '600', '250', '380', '420', '900');
await sleep(2000);
const afterEmpty = await shot('42-after-empty-drag');
const h0 = bodyHash(before);
const h1 = bodyHash(afterDrag);
const h2 = bodyHash(afterEmpty);
console.log('');
console.log(` 拖动前 : ${h0}`);
console.log(` 拖节点后 : ${h1} ${h0 === h1 ? '❌ 没变 → 节点没拖动' : '✅ 变了 → 节点动了'}`);
console.log(` 拖空白后 : ${h2} ${h1 === h2 ? '✅ 没变 → 空白处不动作(正确)' : '❌ 变了 → 空白处也动了'}`);
console.log('截图在', OUT);

View File

@@ -104,7 +104,7 @@ const cases = [
wantHas: ['甲 收到[起点]', '乙 收到[起点]'],
},
{
name: '环不会把引擎转死(每个节点最多跑一次)',
name: '环不会把引擎转死(默认每节点只跑一次)',
meeting: {
nodes: [
{ id: 's', type: 'start', text: 'x' },
@@ -119,6 +119,76 @@ const cases = [
},
wantRunCount: 2, // 甲、乙各一次,不会无限循环
},
{
name: 'n1 ↔ n2 环:maxRuns=1 只走一轮',
meeting: {
nodes: [
{ id: 's', type: 'start', text: '起点' },
{ id: 'n1', type: 'agent', title: '甲', agentId: '', maxRuns: 1 },
{ id: 'n2', type: 'agent', title: '乙', agentId: '', maxRuns: 1 },
],
edges: [
{ from: 's', to: 'n1' },
{ from: 'n1', to: 'n2' },
{ from: 'n2', to: 'n1' },
],
},
wantEachRuns: { n1: 1, n2: 1 },
},
{
name: 'n1 ↔ n2 环:maxRuns=3 能来回跑三轮',
meeting: {
nodes: [
{ id: 's', type: 'start', text: '起点' },
{ id: 'n1', type: 'agent', title: '甲', agentId: '', maxRuns: 3 },
{ id: 'n2', type: 'agent', title: '乙', agentId: '', maxRuns: 3 },
],
edges: [
{ from: 's', to: 'n1' },
{ from: 'n1', to: 'n2' },
{ from: 'n2', to: 'n1' },
],
},
wantEachRuns: { n1: 3, n2: 3 },
},
{
name: 'n1 ↔ n2 环:maxRuns=0 无限循环(靠 shouldStop 收尾)',
meeting: {
nodes: [
{ id: 's', type: 'start', text: '起点' },
{ id: 'n1', type: 'agent', title: '甲', agentId: '', maxRuns: 0 },
{ id: 'n2', type: 'agent', title: '乙', agentId: '', maxRuns: 0 },
],
edges: [
{ from: 's', to: 'n1' },
{ from: 'n1', to: 'n2' },
{ from: 'n2', to: 'n1' },
],
},
// 提示跑 6 次之后停下来,模拟用户按停止
stopAfter: 6,
wantEachRuns: { n1: 3, n2: 3 },
wantAborted: true,
},
{
name: '重复时后一轮能拿到前一轮的输出',
meeting: {
nodes: [
{ id: 's', type: 'start', text: '起点' },
{ id: 'n1', type: 'agent', title: '甲', agentId: '', maxRuns: 2 },
{ id: 'n2', type: 'agent', title: '乙', agentId: '', maxRuns: 2 },
],
edges: [
{ from: 's', to: 'n1' },
{ from: 'n1', to: 'n2' },
{ from: 'n2', to: 'n1' },
],
},
// 第二轮甲收到的必须**包含乙第一轮的产出**,不能是空的 ——
// 否则"重复"就只是把同一件事做两遍,没有意义。
// 注意 n1 现在有两条入边(s 和 n2),按设计会拼接,所以还带着起点那句。
wantSecondRoundHas: '乙 收到[甲 收到[起点]]',
},
{
name: '单个节点出错不影响下游继续跑',
meeting: {
@@ -153,8 +223,13 @@ async function runOne(impl, cs) {
const order = [];
const events = [];
let runCount = 0;
// 每个节点跑了几次 / 每次收到的输入(验"重复"用)
const perNode = {};
const inputsByNode = {};
const agentFn = async (node, input, settings, emit, nodeId) => {
runCount += 1;
perNode[nodeId] = (perNode[nodeId] || 0) + 1;
(inputsByNode[nodeId] = inputsByNode[nodeId] || []).push(input);
if (node.title === '会炸的') throw new Error('故意炸一下');
return impl === 'node'
? echoAgent(node, input)
@@ -169,8 +244,13 @@ async function runOne(impl, cs) {
if (e.type === 'node_start') order.push(e.nodeId);
},
runAgentFn: agentFn,
// 无限循环的用例靠这个模拟"用户按了停止"
shouldStop: cs.stopAfter ? () => runCount >= cs.stopAfter : undefined,
});
return { order, events, runCount, output: out.output || '', error: out.error || '' };
return {
order, events, runCount, perNode, inputsByNode,
output: out.output || '', error: out.error || '', aborted: !!out.aborted,
};
}
/* --------------------------------------------- Python 侧:起内核跑同一组 */
@@ -187,30 +267,41 @@ for cs in cases:
order = []
events = []
state = {'runs': 0}
per_node = {}
inputs_by_node = {}
def emit(e):
events.append(e)
if e.get('type') == 'node_start':
order.append(e.get('nodeId'))
def agent_fn(node, incoming, settings, emit_fn, node_id):
state['runs'] += 1
per_node[node_id] = per_node.get(node_id, 0) + 1
inputs_by_node.setdefault(node_id, []).append(incoming)
if node.get('title') == '会炸的':
raise RuntimeError('故意炸一下')
title = node.get('title') or node.get('id')
return f"{title} 收到[{incoming}]"
stop_after = cs.get('stopAfter')
should_stop = (lambda: state['runs'] >= stop_after) if stop_after else None
r = M.run_meeting(meeting=cs['meeting'], settings={}, user_input='',
emit=emit, run_agent_fn=agent_fn)
emit=emit, run_agent_fn=agent_fn, should_stop=should_stop)
out.append({'order': order, 'events': events, 'runCount': state['runs'],
'output': r.get('output') or '', 'error': r.get('error') or ''})
'perNode': per_node, 'inputsByNode': inputs_by_node,
'output': r.get('output') or '', 'error': r.get('error') or '',
'aborted': bool(r.get('aborted'))})
print(json.dumps(out, ensure_ascii=False))
`;
const res = spawnSync(PY, ['-c', script], {
input: JSON.stringify(cases.map((c) => ({ meeting: c.meeting }))),
input: JSON.stringify(cases.map((c) => ({
meeting: c.meeting,
stopAfter: c.stopAfter || null,
}))),
encoding: 'utf8',
maxBuffer: 16 * 1024 * 1024,
maxBuffer: 32 * 1024 * 1024,
env: { ...process.env, PYTHONIOENCODING: 'utf-8' },
});
if (res.status !== 0) {
console.log(' Python 侧执行失败:', (res.stderr || '').slice(0, 500));
console.log(' Python 侧执行失败:', (res.stderr || '').slice(0, 600));
return null;
}
try {
@@ -251,6 +342,21 @@ for (const cs of cases) {
if (cs.wantRunCount !== undefined) {
check(' 环没有把引擎转死', nodeRes.runCount === cs.wantRunCount, `跑了 ${nodeRes.runCount} 次`);
}
if (cs.wantEachRuns) {
const got = JSON.stringify(nodeRes.perNode);
const want = JSON.stringify(cs.wantEachRuns);
check(' 每个节点的执行次数正确', got === want, got);
}
if (cs.wantSecondRoundHas !== undefined) {
// 第二轮拿到的输入必须包含第一轮的产出,不能是空的 ——
// 否则"重复"就只是把同一件事做两遍,没有意义
const second = nodeRes.inputsByNode.n1?.[1] || '';
check(' 第二轮能拿到上一轮的输出', second.includes(cs.wantSecondRoundHas),
JSON.stringify(second));
}
if (cs.wantAborted) {
check(' 被停止后正确报告 aborted', nodeRes.aborted === true, String(nodeRes.aborted));
}
if (cs.wantError) {
const has = nodeRes.events.some((e) => e.type === 'node_error');
check(' 出错上报了 node_error', has);