会议模式:双指缩放(像看图片)、写变量只进 / 读变量只出
用户反馈的两条。
【1. 像缩放图片那样】
两指现在不只是平移,还能**捏合缩放**(0.4× ~ 3×):
- 双指拖动 = 平移
- 双指捏合 = 缩放,**以两指中点为锚**(中点底下的东西保持不动)
- 单指拖 = 拖节点
★ 锚点修正很重要:不做的话捏合时画面会往左上角跑,手感完全不对。
式子:锚点 = (中点 - 平移) / 缩放;平移' = 中点 - 锚点 × 缩放'
★ graphicsLayer 的 transformOrigin 固定成**左上角**,这样
"屏幕 = 画布 × 缩放 + 平移" 才成立,命中判断的反解就一行。
用默认的中心原点还得带上控件尺寸,最容易算错。
★ 顺手修了"视图挪不动"的老问题:clampPan 里画布尺寸原本写死 ×2.75(拍的),
密度 2.0 的机器上纵向只能挪一点点。改成按**真实密度**算。
【2. 写变量只有输入、读变量只有输出】
这不是画得好不好看,是**数据流语义**:
start 源:没有输入
readvar 源:读变量是"取数据",不该被喂东西,只有输出
var 汇:写变量是"存数据",只管收,没有输出
end 汇:只管收
agent / judge 中间节点,进出都有
配套改了三处:
- 端口按语义画,接错的连线在保存时**直接被丢掉**
(连线文件可以手改、也可能来自旧版本,留着会变成一个永远不触发的节点 ——
图看着连了就是不跑,这种最难查)
- 读变量不再算"入口节点"。它没有输入,如果当入口就会一上来读个空值,顺序全反
- **变量被写入时唤醒读它的节点**:写变量没有输出端口,下游不是靠连线接上的,
靠这条。而且"写变量节点写的"和"智能体用 [[SET]] 写的"**必须走同一条路** ——
两处不一致就会出现"用节点写能读到、让智能体写就读不到"这种极难查的问题
(测试抓到过一次,已修)
【验证】
- 引擎测试新增/调整变量用例(端口语义变了,写→读之间不再有连线),
总 40/40,**Node 与 Python 16/16 逐用例一致**
- HTTP 端到端 13/13 ×2
- 模拟器实测执行顺序:`s → a → j → w → rd → e`(写变量跑完才唤醒读变量)
- 模拟器截图确认端口:start 只有出、var 只有入、readvar 只有出、end 只有入、
judge 一进两出(绿真 / 红假)
- 全部回归:Markdown 19/19、语音 41/41 ×2
【没实测的】双指捏合缩放 adb 模拟不了(input 只能单指),
代码按 hand-numer 分支写的,锚点算式也推过一遍,但**真机手感要你试**。
This commit is contained in:
@@ -267,17 +267,23 @@ function sanitizeNodes(nodes) {
|
||||
return out;
|
||||
}
|
||||
|
||||
/** 丢掉指向不存在节点的连线 —— 悬空连线是崩溃的常见来源 */
|
||||
/** 丢掉指向不存在节点的连线,以及**接到没有那个端口的节点上的连线**。 */
|
||||
function sanitizeEdges(edges, nodes) {
|
||||
const ids = new Set(nodes.map((n) => n.id));
|
||||
const byId = new Map(nodes.map((n) => [n.id, n]));
|
||||
const out = [];
|
||||
for (const e of edges) {
|
||||
if (!e || typeof e !== 'object') continue;
|
||||
const src = String(e.from || '');
|
||||
const dst = String(e.to || '');
|
||||
if (ids.has(src) && ids.has(dst) && src !== dst) {
|
||||
out.push({ from: src, to: dst, branch: String(e.branch || '') });
|
||||
}
|
||||
const a = byId.get(src);
|
||||
const b = byId.get(dst);
|
||||
if (!a || !b || src === dst) continue;
|
||||
// 端口语义是硬约束:写变量只有输入、读变量只有输出。
|
||||
// 连线文件可以手改、也可能来自旧版本会议,留着"接到不存在端口上的边"
|
||||
// 会变成一个永远不触发的节点 —— 图看着连了就是不跑,最难查。
|
||||
if (a.type === 'end' || a.type === 'var') continue;
|
||||
if (b.type === 'start' || b.type === 'readvar') continue;
|
||||
out.push({ from: src, to: dst, branch: String(e.branch || '') });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -342,9 +348,18 @@ export async function runMeeting({ meeting, settings, userInput, emit, runAgentF
|
||||
|
||||
emit({ type: 'meeting_start', nodes: nodes.length, edges: edges.length });
|
||||
|
||||
// 入口:优先 start 节点;没有就从"没有入边"的节点开始
|
||||
// 入口:优先 start 节点;没有就从"没有入边"的节点开始。
|
||||
//
|
||||
// ★ 读变量节点**不算入口**:它没有输入端口,是"变量被写入时"才触发的。
|
||||
// 把它当入口的话,一上来就会读出一个空值 —— 顺序完全反了。
|
||||
let starts = nodes.filter((n) => n.type === 'start');
|
||||
if (!starts.length) starts = nodes.filter((n) => incoming(edges, n.id).length === 0);
|
||||
if (!starts.length) {
|
||||
starts = nodes.filter((n) => n.type !== 'readvar' && incoming(edges, n.id).length === 0);
|
||||
}
|
||||
if (!starts.length) {
|
||||
// 整张图只有读变量节点:那就让它跑一次(读到的可能是空的)
|
||||
starts = nodes.filter((n) => n.type === 'readvar');
|
||||
}
|
||||
if (!starts.length) {
|
||||
emit({ type: 'meeting_done', output: '', error: '这张图没有入口节点' });
|
||||
return { output: '', error: '这张图没有入口节点' };
|
||||
@@ -391,6 +406,24 @@ export async function runMeeting({ meeting, settings, userInput, emit, runAgentF
|
||||
return limit === 0 || (runs[id] || 0) < limit;
|
||||
};
|
||||
|
||||
/**
|
||||
* 某个变量被写入后,把读它的读变量节点唤醒。
|
||||
*
|
||||
* 写变量没有输出端口(它是"汇"),所以下游不是靠连线接上的 —— 靠这里。
|
||||
* **不管是写变量节点写的,还是智能体用 [[SET]] 写的,都要走这一条**:
|
||||
* 两处不一致的话,就会出现"用节点写能读到、让智能体写就读不到"
|
||||
* 这种极难查的问题(测试抓到过一次)。
|
||||
*/
|
||||
const wakeReaders = (varName) => {
|
||||
for (const other of nodes) {
|
||||
if (other.type === 'readvar'
|
||||
&& String(other.varName || '').trim() === varName
|
||||
&& canRun(other.id)) {
|
||||
queue.push(other.id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
while (queue.length && steps < maxSteps) {
|
||||
if (shouldStop && shouldStop()) {
|
||||
emit({ type: 'meeting_done', output: finalOutput, aborted: true });
|
||||
@@ -449,6 +482,8 @@ export async function runMeeting({ meeting, settings, userInput, emit, runAgentF
|
||||
vars: changed,
|
||||
note: Object.entries(changed).map(([k, v]) => `${k} = ${String(v).slice(0, 30)}`).join('、'),
|
||||
});
|
||||
// 和写变量节点一样,唤醒读这些变量的节点
|
||||
for (const key of Object.keys(changed)) wakeReaders(key);
|
||||
}
|
||||
nextIds = outgoing(edges, nodeId).map((e) => e.to);
|
||||
} else if (nodeType === 'var') {
|
||||
@@ -457,12 +492,15 @@ export async function runMeeting({ meeting, settings, userInput, emit, runAgentF
|
||||
if (!name) throw new Error('变量节点没填变量名');
|
||||
const value = String(node.varValue || '').trim() || input;
|
||||
variables[name] = value;
|
||||
// 写变量是"汇"(没有输出端口),唤醒读它的节点
|
||||
wakeReaders(name);
|
||||
outputs[nodeId] = value;
|
||||
emit({
|
||||
type: 'node_done', nodeId, output: value, run: runIndex,
|
||||
note: `变量 ${name} = ${value.slice(0, 40)}`,
|
||||
});
|
||||
nextIds = outgoing(edges, nodeId).map((e) => e.to);
|
||||
// 写变量没有输出端口,所以不往下游走
|
||||
nextIds = [];
|
||||
} else if (nodeType === 'readvar') {
|
||||
// 读变量节点:把变量的当前值当成输出往下传
|
||||
const name = String(node.varName || '').trim();
|
||||
|
||||
Reference in New Issue
Block a user