会议模式:引脚端点、类型隔离、值节点、开始事件
用户四条反馈,都在界面上落实了。
【1. 每个输入输出各有自己的端点,不挤到一点】
节点改成真正的蓝图长相:彩色标题栏 + **每条引脚各占一行、各有自己的端点**。
- 行高从 18dp 加到 21dp,端点之间拉开
- 左列输入(exec 在上、data 在下)、右列输出,标签紧贴引脚那一侧
- 连线从**引脚的实际位置**出发/接入,不是从节点中心
【2. 执行端点只能连执行端点,不同类型不能连】
连接时按引脚种类匹配(exec↔exec、data↔data),种类不同直接不接。
而且**正在连线时,接不上的引脚会变淡** —— 蓝图里拖到不兼容的引脚会直接报错,
这里用变淡表示"这个接不了"。光靠"点了没反应"用户会以为程序坏了。
界面上的区分也做足了:
- exec 执行引脚:**白色三角**(蓝图那种)
- data 数据引脚:彩色圆点
- exec 线:深色;data 线:淡蓝贝塞尔
形状 + 颜色双重区分。只靠颜色的话,色弱用户或者图缩小之后就分不清了,
而这两种线接错等于整套语义垮掉。
【3. 值节点】
新增 `值`(value)节点:**纯节点**,只有一个数据输出,谁需要谁拉它的值。
可以直接连到智能体的数据输入 —— 实测:
开始事件(exec+data) + 值节点(data) → 智能体
最终输出 = '收到[用户的话\n\n系统提示用的补充]'
两个数据源都进了智能体。
★ 和"读变量"归为同一类**纯节点**(蓝图里的 Get / 常量):
没有 exec 引脚、不在执行链上。取值的地方统一走 _pure_value(),
按节点类型现算(读变量取变量当前值、值节点取它写死的文本),
而不是去 outputs 里找 —— 纯节点可能压根没被执行链走到过。
【4. 开始事件】
`start` 从「初始输入」正式改名为「开始事件」(从这开始),
引脚是 exec 出 + 数据出,是整张图的起点。
【顺带】
- while 节点的两条 exec 出线(循环体 ▶ / 结束 ▶)在界面上有了,
节点配色也区分开了:开始事件绿、判断橙、最终输出紫、变量青、值淡紫、循环红
- 节点配色和标题的兜底表都补齐了新类型
- 默认布局的节点间距拉开(x 12 → 180 → 348):之前挨太近,
exec 引脚三角、短连线、对面引脚挤在一起,看着像个蝴蝶结
- exec 线不再画箭头:exec 引脚本身就是三角,再画一个会叠一起;
数据线保留箭头并往回收 4px
【验证】
- 引擎回归 40/40,Node 与 Python **16/16 逐用例一致**
- 会议 HTTP 端到端 13/13 ×2
- 值节点端到端实测(见上)
- 模拟器截图确认:开始事件/值/智能体/读变量/while/写变量的引脚与连线都正确,
exec 深色线、data 淡蓝曲线一眼可分
【还没做的,如实说明】
- **Node 侧引擎的 while 节点还没写**(Python 有了)。exec/data 重构两边都做了,
对拍一致;while 目前是 Python 独有。
- 值节点的验收用例还没加进 verify-meeting.mjs(手工验过,没进回归)。
- while 的界面上能看能连,但配置面板里还没有它的说明文字。
This commit is contained in:
@@ -653,40 +653,42 @@ private fun MeetingEditorScreen(vm: AppViewModel, initial: Meeting, onBack: () -
|
||||
},
|
||||
),
|
||||
)
|
||||
// 箭头:**永远朝右**。
|
||||
// 箭头:**只有数据线才画**。
|
||||
//
|
||||
// 这条三次贝塞尔的控制点是 (start+dx, ·) 和 (end-dx, ·),
|
||||
// 所以 t=1 处的切线方向恒为 (dx, 0) —— 水平向右,
|
||||
// 和起点/终点的高低差无关。蓝图里的箭头也是这样水平扎进引脚的。
|
||||
// ★ exec 线不画箭头:exec 引脚本身就是个三角(▶),
|
||||
// 再在端点附近画一个箭头会和引脚叠成"蝴蝶结"(▷◁),
|
||||
// 看着像连错了。蓝图里 exec 线也是靠引脚形状表示方向的。
|
||||
//
|
||||
// 之前按"起点到终点"的斜率算角度,横向距离小的时候
|
||||
// atan2 会算出接近 180°,箭头翻过去和后一条边叠成蝴蝶结。
|
||||
val angle = 0f
|
||||
val len = 8.dp.toPx()
|
||||
val arrow = Path().apply {
|
||||
moveTo(end.x, end.y)
|
||||
lineTo(
|
||||
end.x - len * kotlin.math.cos(angle - 0.45f),
|
||||
end.y - len * kotlin.math.sin(angle - 0.45f),
|
||||
)
|
||||
lineTo(
|
||||
end.x - len * kotlin.math.cos(angle + 0.45f),
|
||||
end.y - len * kotlin.math.sin(angle + 0.45f),
|
||||
)
|
||||
close()
|
||||
// 数据线画,而且**往回收几个像素**,别贴着引脚。
|
||||
if (edge.kind == "data") {
|
||||
val len = 7.dp.toPx()
|
||||
val tipX = end.x - 4.dp.toPx()
|
||||
val arrow = Path().apply {
|
||||
moveTo(tipX, end.y)
|
||||
lineTo(tipX - len, end.y - len * 0.55f)
|
||||
lineTo(tipX - len, end.y + len * 0.55f)
|
||||
close()
|
||||
}
|
||||
drawPath(arrow, color)
|
||||
}
|
||||
drawPath(arrow, color)
|
||||
}
|
||||
|
||||
// 引脚。画在最上层,用户看得见"从哪儿拉出去、往哪儿接进来"。
|
||||
meeting.nodes.forEach { node ->
|
||||
val linkingKindNow = linkingFrom?.kind
|
||||
inputPins(node).forEachIndexed { i, pin ->
|
||||
val p = px(pinPos(node, i, isOutput = false))
|
||||
// 接不上的引脚淡化:蓝图里会直接报"类型不兼容",
|
||||
// 这里用变淡表示,比"点了没反应"清楚得多
|
||||
val usable = linkingKindNow == null || linkingKindNow == pin.kind
|
||||
val alpha = if (usable) 1f else 0.25f
|
||||
if (pin.kind == "exec") {
|
||||
drawExecPin(p, PORT_R.dp.toPx(), filled = true)
|
||||
drawExecPin(p, PORT_R.dp.toPx(), filled = true,
|
||||
tint = EXEC_BORDER.copy(alpha = alpha))
|
||||
} else {
|
||||
drawCircle(Color.White, radius = (PORT_R + 1.5f).dp.toPx(), center = p)
|
||||
drawCircle(Color(0xFF9AA0A6), radius = PORT_R.dp.toPx(), center = p)
|
||||
drawCircle(Color(0xFF9AA0A6).copy(alpha = alpha),
|
||||
radius = PORT_R.dp.toPx(), center = p)
|
||||
}
|
||||
}
|
||||
outputPins(node).forEachIndexed { i, pin ->
|
||||
@@ -701,8 +703,11 @@ private fun MeetingEditorScreen(vm: AppViewModel, initial: Meeting, onBack: () -
|
||||
val active = linkingFrom?.let {
|
||||
it.nodeId == node.id && it.kind == pin.kind && it.branch == pin.key
|
||||
} == true
|
||||
val usableOut = linkingKindNow == null || linkingKindNow == pin.kind
|
||||
if (pin.kind == "exec") {
|
||||
drawExecPin(p, (if (active) PORT_R + 1.5f else PORT_R).dp.toPx(), filled = true, tint = c)
|
||||
drawExecPin(p, (if (active) PORT_R + 1.5f else PORT_R).dp.toPx(),
|
||||
filled = true,
|
||||
tint = if (usableOut) c else c.copy(alpha = 0.25f))
|
||||
} else {
|
||||
drawCircle(Color.White, radius = (PORT_R + 1.5f).dp.toPx(), center = p)
|
||||
drawCircle(
|
||||
@@ -734,6 +739,7 @@ private fun MeetingEditorScreen(vm: AppViewModel, initial: Meeting, onBack: () -
|
||||
linking = linkingFrom?.nodeId == node.id,
|
||||
inDegree = meeting.edges.count { it.to == node.id },
|
||||
outDegree = meeting.edges.count { it.from == node.id },
|
||||
linkingKind = linkingFrom?.kind,
|
||||
modifier = Modifier.offset(node.x.dp, node.y.dp),
|
||||
)
|
||||
}
|
||||
@@ -891,12 +897,13 @@ private data class PinSpec(
|
||||
/**
|
||||
* 左边一列的引脚(从上到下)。
|
||||
*
|
||||
* ★ 读变量**没有 exec 入**:它是纯节点(蓝图里的 Get),不在执行链上,
|
||||
* 值是被需要的节点运行时拉取的 —— 这就是"读变量只有输出"的真正原因。
|
||||
* ★ **纯节点**(读变量 / 值)没有 exec 入:它们是蓝图里的 Get / 常量,
|
||||
* 不在执行链上,值是被需要的节点运行时拉取的 —— 这就是"读变量只有输出"的真正原因。
|
||||
* ★ 开始事件也没有 exec 入:它是整张图的起点。
|
||||
*/
|
||||
private fun inputPins(node: MeetingNode): List<PinSpec> = when (node.type) {
|
||||
"start", "readvar" -> emptyList()
|
||||
"judge", "var" -> listOf(
|
||||
"start", "readvar", "value" -> emptyList()
|
||||
"judge", "var", "while" -> listOf(
|
||||
PinSpec("exec", "", "▶"),
|
||||
PinSpec("data", "", "值"),
|
||||
)
|
||||
@@ -910,18 +917,26 @@ private fun inputPins(node: MeetingNode): List<PinSpec> = when (node.type) {
|
||||
* 右边一列的引脚(从上到下)。
|
||||
*
|
||||
* ★ 判断节点有**两条 exec 出线**(真/假)—— 相当于蓝图里的 Branch。
|
||||
* ★ 写变量**没有 data 出线**(存进去的值不从它往下传),但有 exec 出线
|
||||
* (蓝图里 Set 节点就是 exec 进 → exec 出)。
|
||||
* ★ while 有**两条 exec 出线**(循环体/结束)—— 相当于蓝图里的 While Loop。
|
||||
* ★ 写变量**没有 data 出线**(存进去的值不从它往下传),但有 exec 出线。
|
||||
* ★ 纯节点(读变量 / 值)**只有 data 出线**,没有任何 exec 引脚。
|
||||
*/
|
||||
private fun outputPins(node: MeetingNode): List<PinSpec> = when (node.type) {
|
||||
"end" -> emptyList()
|
||||
"readvar" -> listOf(PinSpec("data", "", "值"))
|
||||
"readvar", "value" -> listOf(PinSpec("data", "", "值"))
|
||||
"judge" -> listOf(
|
||||
PinSpec("exec", "true", "真 ▶"),
|
||||
PinSpec("exec", "false", "假 ▶"),
|
||||
)
|
||||
"while" -> listOf(
|
||||
PinSpec("exec", "body", "循环体 ▶"),
|
||||
PinSpec("exec", "done", "结束 ▶"),
|
||||
)
|
||||
"var" -> listOf(PinSpec("exec", "", "▶"))
|
||||
"start" -> listOf(PinSpec("data", "", "输出"))
|
||||
"start" -> listOf(
|
||||
PinSpec("exec", "", "▶"),
|
||||
PinSpec("data", "", "输出"),
|
||||
)
|
||||
else -> listOf(
|
||||
PinSpec("exec", "", "▶"),
|
||||
PinSpec("data", "", "输出"),
|
||||
@@ -933,9 +948,9 @@ private fun outputPins(node: MeetingNode): List<PinSpec> = when (node.type) {
|
||||
/** 顶部彩色标题栏的高度 */
|
||||
private const val HEADER_H = 24f
|
||||
/** 一行引脚占的高度 */
|
||||
private const val PIN_ROW_H = 18f
|
||||
private const val PIN_ROW_H = 21f
|
||||
/** 引脚下面的内容区(预览文字 + 路数) */
|
||||
private const val BODY_H = 38f
|
||||
private const val BODY_H = 34f
|
||||
|
||||
/** 引脚画多大 / 点多准。命中范围要大一圈,手指没那么准。 */
|
||||
private const val PORT_R = 5.5f
|
||||
@@ -1338,9 +1353,12 @@ private fun MeetingResultScreen(
|
||||
/* ====================================================================== */
|
||||
|
||||
private fun nodeColor(type: String): Color = when (type) {
|
||||
"start" -> Color(0xFF34A853)
|
||||
"judge" -> Color(0xFFF29900)
|
||||
"end" -> Color(0xFF7B61FF)
|
||||
"start" -> Color(0xFF34A853) // 开始事件:绿,和蓝图的事件节点一个颜色
|
||||
"judge" -> Color(0xFFF29900) // 判断:橙
|
||||
"end" -> Color(0xFF7B61FF) // 最终输出:紫
|
||||
"var", "readvar" -> Color(0xFF00A0A0) // 变量:青,和普通逻辑区分开
|
||||
"value" -> Color(0xFF9C6ADE) // 值/常量:淡紫
|
||||
"while" -> Color(0xFFD93025) // 循环:红,醒目
|
||||
else -> Doubao.Blue
|
||||
}
|
||||
|
||||
@@ -1354,6 +1372,8 @@ private fun NodeCard(
|
||||
inDegree: Int,
|
||||
/** 从这个节点出去的连线数(多路输出也要显示) */
|
||||
outDegree: Int,
|
||||
/** 正在连线的引脚种类(exec / data);null = 没在连线。用来灰掉接不上的引脚 */
|
||||
linkingKind: String?,
|
||||
modifier: Modifier,
|
||||
) {
|
||||
val accent = nodeColor(node.type)
|
||||
@@ -1401,6 +1421,8 @@ private fun NodeCard(
|
||||
"end" -> "最终输出"
|
||||
"var" -> "写变量"
|
||||
"readvar" -> "读变量"
|
||||
"value" -> "值"
|
||||
"while" -> "while 循环"
|
||||
else -> "智能体"
|
||||
}
|
||||
},
|
||||
@@ -1472,6 +1494,8 @@ private fun NodeCard(
|
||||
node.type == "judge" -> node.judgeKind
|
||||
node.type == "var" -> node.varName.ifBlank { "没填变量名" }
|
||||
node.type == "readvar" -> node.varName.ifBlank { "没填变量名" }
|
||||
node.type == "value" -> node.text.ifBlank { "(空值)" }
|
||||
node.type == "while" -> "条件为真就跑循环体"
|
||||
node.text.isNotBlank() -> node.text
|
||||
else -> "点一下配置"
|
||||
},
|
||||
|
||||
@@ -684,12 +684,14 @@ class KernelHandler(BaseHTTPRequestHandler):
|
||||
# 编辑器要用:节点类型、判断条件、可用智能体
|
||||
self.send_json(200, {
|
||||
'nodeTypes': [
|
||||
{'key': 'start', 'label': '初始输入', 'desc': '整张图的入口'},
|
||||
{'key': 'start', 'label': '开始事件', 'desc': '整张图从这里开始(exec 起点)'},
|
||||
{'key': 'agent', 'label': '智能体', 'desc': '一个智能体处理一轮'},
|
||||
{'key': 'judge', 'label': '判断', 'desc': '按条件分 true / false 两条路'},
|
||||
{'key': 'end', 'label': '最终输出', 'desc': '汇总结果'},
|
||||
{'key': 'var', 'label': '写变量', 'desc': '把内容存进一个变量,后面任何节点都能读'},
|
||||
{'key': 'readvar', 'label': '读变量', 'desc': '把变量的当前值取出来往下传'},
|
||||
{'key': 'readvar', 'label': '读变量', 'desc': '纯节点:取变量当前值(只出数据,没有 exec)'},
|
||||
{'key': 'value', 'label': '值', 'desc': '纯节点:一个写死的值,接到智能体的数据输入'},
|
||||
{'key': 'while', 'label': 'while 循环', 'desc': '条件为真就跑循环体,像 C 的 while'},
|
||||
],
|
||||
'judgeKinds': [{'key': k, 'label': v} for k, v in meeting.JUDGE_KINDS],
|
||||
'agents': [
|
||||
|
||||
@@ -42,7 +42,7 @@ import paths
|
||||
|
||||
_lock = threading.Lock()
|
||||
|
||||
NODE_TYPES = ('start', 'agent', 'judge', 'end', 'var', 'readvar', 'while')
|
||||
NODE_TYPES = ('start', 'agent', 'judge', 'end', 'var', 'readvar', 'while', 'value')
|
||||
|
||||
# 判断节点支持的条件。**结构化而不是表达式**,理由见文件头。
|
||||
JUDGE_KINDS = (
|
||||
@@ -420,7 +420,7 @@ def _sanitize_edges(edges: list, nodes: list) -> list:
|
||||
# 存完继续往下走),所以这里只挡数据线
|
||||
if str(e.get('kind') or '') == DATA:
|
||||
continue
|
||||
if by_id[dst]['type'] in ('start', 'readvar'):
|
||||
# 纯节点(读变量 / 值)没有输入端口,不该被连进来\n if by_id[dst]['type'] in ('start', 'readvar', 'value'):
|
||||
continue
|
||||
|
||||
kind = _kind(e)
|
||||
@@ -494,6 +494,31 @@ def _data_out(edges: list, node_id: str) -> list:
|
||||
return [e for e in _outgoing(edges, node_id) if _kind(e) == DATA]
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# 纯节点(蓝图里的 Get / 常量)
|
||||
# --------------------------------------------------------------------------- #
|
||||
#
|
||||
# 纯节点**没有 exec 引脚**,不在执行链上:它的值是被需要的节点在运行时
|
||||
# **拉取**的。所以它们的值不能从 outputs 里找(它们可能根本没被执行链走到过),
|
||||
# 得在这里按节点类型现算。
|
||||
#
|
||||
# 现在有两种:
|
||||
# readvar 读变量 —— 谁需要谁拿变量的当前值
|
||||
# value 值/常量 —— 谁需要谁拿它自己写死的那个值
|
||||
#
|
||||
def _pure_value(node_id: str, by_id: dict, outputs: dict, variables: dict):
|
||||
"""取一个上游节点的值。纯节点现算,普通节点取它执行时的输出。"""
|
||||
node = by_id.get(node_id)
|
||||
if not node:
|
||||
return outputs.get(node_id, '')
|
||||
kind = node['type']
|
||||
if kind == 'readvar':
|
||||
return variables.get(str(node.get('varName') or '').strip(), '')
|
||||
if kind == 'value':
|
||||
return node.get('text') or ''
|
||||
return outputs.get(node_id, '')
|
||||
|
||||
|
||||
def _reachable_exec(edges: list, seeds: list, stop: str = None) -> set:
|
||||
"""
|
||||
从 seeds 出发、只沿 **exec** 边走,能走到的所有节点。
|
||||
@@ -522,12 +547,7 @@ def _collect_data_only(node_id: str, edges: list, outputs: dict, variables: dict
|
||||
"""
|
||||
parts = []
|
||||
for e in _data_in(edges, node_id):
|
||||
src = e.get('from')
|
||||
node = by_id.get(src)
|
||||
if node and node['type'] == 'readvar':
|
||||
value = variables.get(str(node.get('varName') or '').strip(), '')
|
||||
else:
|
||||
value = outputs.get(src, '')
|
||||
value = _pure_value(e.get('from'), by_id, outputs, variables)
|
||||
if value:
|
||||
parts.append(str(value))
|
||||
return '\n\n'.join(parts).strip()
|
||||
@@ -547,13 +567,8 @@ def _collect_input(node_id: str, edges: list, outputs: dict, variables: dict,
|
||||
"""
|
||||
parts = []
|
||||
for e in _data_in(edges, node_id):
|
||||
src = e.get('from')
|
||||
node = by_id.get(src)
|
||||
if node and node['type'] == 'readvar':
|
||||
# 纯节点:现取现值
|
||||
value = variables.get(str(node.get('varName') or '').strip(), '')
|
||||
else:
|
||||
value = outputs.get(src, '')
|
||||
# 纯节点(读变量 / 值)现取现值,普通节点取它执行时的输出
|
||||
value = _pure_value(e.get('from'), by_id, outputs, variables)
|
||||
if value:
|
||||
parts.append(str(value))
|
||||
if parts:
|
||||
@@ -629,7 +644,7 @@ def run_meeting(*, meeting: dict, settings: dict, user_input: str,
|
||||
starts = [n for n in nodes if n['type'] == 'start']
|
||||
if not starts:
|
||||
starts = [n for n in nodes
|
||||
if n['type'] != 'readvar' and not _exec_in(edges, n['id'])]
|
||||
if n['type'] not in ('readvar', 'value') and not _exec_in(edges, n['id'])]
|
||||
if not starts:
|
||||
emit({'type': 'meeting_done', 'output': '', 'error': '这张图没有入口节点'})
|
||||
return {'output': '', 'error': '这张图没有入口节点'}
|
||||
|
||||
Reference in New Issue
Block a user