会议模式:一手势分工、节点可重复/无限循环、停止按钮、结果单开一屏
用户反馈的四条。
【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:
@@ -204,12 +204,20 @@ def _sanitize_nodes(nodes: list) -> list:
|
||||
if not nid or nid in seen or ntype not in NODE_TYPES:
|
||||
continue
|
||||
seen.add(nid)
|
||||
try:
|
||||
max_runs = int(n.get('maxRuns')) if n.get('maxRuns') is not None else 1
|
||||
except (TypeError, ValueError):
|
||||
max_runs = 1
|
||||
out.append({
|
||||
**n,
|
||||
'id': nid,
|
||||
'type': ntype,
|
||||
'x': float(n.get('x') or 0),
|
||||
'y': float(n.get('y') or 0),
|
||||
# 夹在 0~20:**0 = 无限循环**(两个智能体互相点评那种用法),
|
||||
# 1~20 是有限次。负数或大于 20 的值都不认,退回 1 ——
|
||||
# 不然用户手改文件写成 99999 会一直烧额度。
|
||||
'maxRuns': 0 if max_runs <= 0 else min(max_runs, 20),
|
||||
})
|
||||
return out
|
||||
|
||||
@@ -317,12 +325,52 @@ def run_meeting(*, meeting: dict, settings: dict, user_input: str,
|
||||
return {'output': '', 'error': '这张图没有入口节点'}
|
||||
|
||||
queue = [n['id'] for n in starts]
|
||||
# 每个节点最多处理一次;总步数再兜一个上限,防止用户画出很长的环
|
||||
visited = set()
|
||||
|
||||
# ★ 每个节点跑了几次(不是"跑没跑过")。
|
||||
#
|
||||
# 用户要的是"n1 → n2 → n1 只有一轮,但**能重复**":
|
||||
# 默认每节点 1 次(= 不重复,和以前一样),把节点上的「最多执行次数」
|
||||
# 调大就能来回跑 —— 比如两个节点都设 3,就是 n1/n2 各跑三轮。
|
||||
#
|
||||
# 以前用的是 visited 集合(跑过就不再跑),环永远只转一圈,没法重复。
|
||||
runs = {}
|
||||
steps = 0
|
||||
max_steps = max(20, len(nodes) * 4)
|
||||
|
||||
def limit_of(node: dict) -> int:
|
||||
"""
|
||||
节点的执行次数上限。**0 表示无限**。
|
||||
|
||||
为什么要支持无限:两个智能体互相点评(甲评乙、乙再评甲)是常见用法,
|
||||
用户希望一直怼下去,自己觉得够了再按停止。
|
||||
|
||||
为什么敢开无限:引擎每一轮都会检查 should_stop(客户端断开或用户点了停止),
|
||||
所以"无限"实际是"跑到你喊停为止",不是真的停不下来。
|
||||
另外还兜了一个很大的硬上限 MAX_STEPS_HARD,防止用户忘了停、
|
||||
或者客户端异常断开时把额度烧光。
|
||||
"""
|
||||
raw = node.get('maxRuns')
|
||||
try:
|
||||
value = int(raw) if raw is not None else 1
|
||||
except (TypeError, ValueError):
|
||||
value = 1
|
||||
return 0 if value <= 0 else min(value, 20)
|
||||
|
||||
budget = sum((limit_of(n) or 200) for n in nodes)
|
||||
# 硬上限:无限循环时预算按每节点 200 次估,再乘 2 留余量。
|
||||
# 这不是"限制用户",是**防止客户端异常断开时把额度烧光** ——
|
||||
# 正常用停止按钮就能收尾,根本碰不到这个数。
|
||||
max_steps = max(20, budget * 2 + len(nodes))
|
||||
|
||||
final_output = ''
|
||||
|
||||
def can_run(node_id: str) -> bool:
|
||||
node = by_id.get(node_id)
|
||||
if not node:
|
||||
return False
|
||||
limit = limit_of(node)
|
||||
# 0 = 无限:永远还能再跑一次
|
||||
return limit == 0 or runs.get(node_id, 0) < limit
|
||||
|
||||
while queue and steps < max_steps:
|
||||
if should_stop and should_stop():
|
||||
emit({'type': 'meeting_done', 'output': final_output, 'aborted': True})
|
||||
@@ -330,33 +378,37 @@ def run_meeting(*, meeting: dict, settings: dict, user_input: str,
|
||||
|
||||
node_id = queue.pop(0)
|
||||
steps += 1
|
||||
if node_id in visited:
|
||||
if not can_run(node_id):
|
||||
continue
|
||||
visited.add(node_id)
|
||||
|
||||
node = by_id.get(node_id)
|
||||
if not node:
|
||||
continue
|
||||
|
||||
run_index = runs.get(node_id, 0) + 1
|
||||
runs[node_id] = run_index
|
||||
node_type = node['type']
|
||||
title = node.get('title') or {'start': '初始输入', 'agent': '智能体',
|
||||
'judge': '判断', 'end': '最终输出'}.get(node_type, node_type)
|
||||
emit({'type': 'node_start', 'nodeId': node_id, 'nodeType': node_type, 'title': title})
|
||||
emit({'type': 'node_start', 'nodeId': node_id, 'nodeType': node_type,
|
||||
'title': title, 'run': run_index, 'maxRuns': limit_of(node)})
|
||||
|
||||
incoming = _collect_input(node_id, edges, outputs)
|
||||
|
||||
try:
|
||||
if node_type == 'start':
|
||||
text = (node.get('text') or '').strip() or (user_input or '')
|
||||
# 第二轮开始,"初始输入"要把**自己上一轮的输出**当输入,
|
||||
# 否则循环回来的内容会被起点覆盖掉,重复就没意义了
|
||||
text = incoming or (node.get('text') or '').strip() or (user_input or '')
|
||||
outputs[node_id] = text
|
||||
emit({'type': 'node_done', 'nodeId': node_id, 'output': text,
|
||||
'note': '用的初始输入'})
|
||||
'run': run_index, 'note': '用的初始输入'})
|
||||
next_ids = [e['to'] for e in _outgoing(edges, node_id)]
|
||||
|
||||
elif node_type == 'agent':
|
||||
out = run_agent_fn(node, incoming, settings, emit, node_id)
|
||||
outputs[node_id] = out
|
||||
emit({'type': 'node_done', 'nodeId': node_id, 'output': out})
|
||||
emit({'type': 'node_done', 'nodeId': node_id, 'output': out, 'run': run_index})
|
||||
next_ids = [e['to'] for e in _outgoing(edges, node_id)]
|
||||
|
||||
elif node_type == 'judge':
|
||||
@@ -373,6 +425,7 @@ def run_meeting(*, meeting: dict, settings: dict, user_input: str,
|
||||
outputs[node_id] = incoming
|
||||
emit({'type': 'node_done', 'nodeId': node_id,
|
||||
'output': incoming,
|
||||
'run': run_index,
|
||||
'verdict': passed,
|
||||
'branch': 'true' if passed else 'false',
|
||||
'note': f'判断结果:{passed}'})
|
||||
@@ -389,7 +442,7 @@ def run_meeting(*, meeting: dict, settings: dict, user_input: str,
|
||||
elif node_type == 'end':
|
||||
outputs[node_id] = (node.get('text') or '').strip() or incoming
|
||||
final_output = outputs[node_id]
|
||||
emit({'type': 'node_done', 'nodeId': node_id, 'output': final_output})
|
||||
emit({'type': 'node_done', 'nodeId': node_id, 'output': final_output, 'run': run_index})
|
||||
next_ids = []
|
||||
|
||||
else:
|
||||
@@ -398,12 +451,15 @@ def run_meeting(*, meeting: dict, settings: dict, user_input: str,
|
||||
|
||||
except Exception as exc: # noqa: BLE001
|
||||
# 单个节点出错不该让整场会议停摆:记下来,继续跑下游
|
||||
emit({'type': 'node_error', 'nodeId': node_id, 'error': str(exc)})
|
||||
emit({'type': 'node_error', 'nodeId': node_id, 'error': str(exc), 'run': run_index})
|
||||
outputs[node_id] = ''
|
||||
next_ids = [e['to'] for e in _outgoing(edges, node_id)]
|
||||
|
||||
# ★ 只有"还能再跑"的节点才重新入队。
|
||||
# 这就是"重复"的开关:maxRuns=1(默认)时,跑过的节点不会再进来,
|
||||
# 环也只转一圈;把它调大,环就会来回转到次数用完为止。
|
||||
for nid in next_ids:
|
||||
if nid not in visited:
|
||||
if can_run(nid):
|
||||
queue.append(nid)
|
||||
|
||||
emit({'type': 'meeting_done', 'output': final_output})
|
||||
|
||||
Reference in New Issue
Block a user