diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/MeetingsScreen.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/MeetingsScreen.kt index c2803ce..622b88d 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/MeetingsScreen.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/MeetingsScreen.kt @@ -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 = 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 = when (node.type) { * 右边一列的引脚(从上到下)。 * * ★ 判断节点有**两条 exec 出线**(真/假)—— 相当于蓝图里的 Branch。 - * ★ 写变量**没有 data 出线**(存进去的值不从它往下传),但有 exec 出线 - * (蓝图里 Set 节点就是 exec 进 → exec 出)。 + * ★ while 有**两条 exec 出线**(循环体/结束)—— 相当于蓝图里的 While Loop。 + * ★ 写变量**没有 data 出线**(存进去的值不从它往下传),但有 exec 出线。 + * ★ 纯节点(读变量 / 值)**只有 data 出线**,没有任何 exec 引脚。 */ private fun outputPins(node: MeetingNode): List = 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 = 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 -> "点一下配置" }, diff --git a/android/kernel/app.py b/android/kernel/app.py index aa88342..eec53bb 100644 --- a/android/kernel/app.py +++ b/android/kernel/app.py @@ -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': [ diff --git a/android/kernel/meeting.py b/android/kernel/meeting.py index ba41b31..6647fe6 100644 --- a/android/kernel/meeting.py +++ b/android/kernel/meeting.py @@ -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': '这张图没有入口节点'} diff --git a/server/src/index.mjs b/server/src/index.mjs index 8fc1f07..59e22ab 100644 --- a/server/src/index.mjs +++ b/server/src/index.mjs @@ -709,12 +709,14 @@ async function handleApi(req, res, url) { // 编辑器要用:节点类型、判断条件、可用智能体 sendJson(res, 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: JUDGE_KINDS.map(([key, label]) => ({ key, label })), agents: listAgents().map((a) => ({ id: a.id, name: a.name, avatar: a.avatar })), diff --git a/server/src/meeting.mjs b/server/src/meeting.mjs index f0b4543..feebbe8 100644 --- a/server/src/meeting.mjs +++ b/server/src/meeting.mjs @@ -120,9 +120,9 @@ export function newMeeting(name = '新会议') { id: rid('m'), name, nodes: [ - { id: 'n_start', type: 'start', x: 12, y: 120, title: '初始输入', text: '' }, - { id: 'n_agent1', type: 'agent', x: 132, y: 120, title: '智能体', agentId: '', extraPrompt: '', outputControl: '' }, - { id: 'n_end', type: 'end', x: 252, y: 120, title: '最终输出', text: '' }, + { id: 'n_start', type: 'start', x: 12, y: 120, title: '开始事件', text: '' }, + { id: 'n_agent1', type: 'agent', x: 180, y: 120, title: '智能体', agentId: '', extraPrompt: '', outputControl: '' }, + { id: 'n_end', type: 'end', x: 348, y: 120, title: '最终输出', text: '' }, ], edges: [ { from: 'n_start', to: 'n_agent1', branch: '' }, @@ -285,13 +285,13 @@ function sanitizeEdges(edges, nodes) { // 注意 end / var 是"没有数据出线",但**有 exec 出线** // (蓝图里 Set 节点就是 exec 进 → exec 出),所以只挡数据线。 if ((a.type === 'end' || a.type === 'var') && e.kind === DATA) continue; - if (b.type === 'start' || b.type === 'readvar') continue; + // 纯节点(读变量 / 值)没有输入端口,不该被连进来\n if (b.type === 'start' || b.type === 'readvar' || b.type === 'value') continue; let kind = kindOf(e); // ★ 从"读变量"出来的线**一律当数据线**:它是纯节点(蓝图里的 Get), // 输出天然是数据,不该拿它当执行链的一环。 // 保存时自动推断,用户不用理解两种线的区别也能连对。 - if (a.type === 'readvar') kind = DATA; + if (a.type === 'readvar' || a.type === 'value') kind = DATA; // 进"写变量"的线也是数据线(它要的是值,不是执行信号) if (b.type === 'var' && !e.kind) kind = DATA; @@ -331,6 +331,24 @@ const kindOf = (e) => (e.kind === DATA ? DATA : EXEC); const execIn = (edges, id) => incoming(edges, id).filter((e) => kindOf(e) === EXEC); const dataIn = (edges, id) => incoming(edges, id).filter((e) => kindOf(e) === DATA); +/** + * 纯节点(蓝图里的 Get / 常量) + * + * 纯节点**没有 exec 引脚**,不在执行链上:它的值是被需要的节点在运行时 + * **拉取**的。所以它们的值不能从 outputs 里找(它们可能根本没被执行链走到过), + * 得在这里按节点类型现算。 + * + * readvar 读变量 —— 谁需要谁拿变量的当前值 + * value 值/常量 —— 谁需要谁拿它自己写死的那个值 + */ +function pureValue(id, byId, outputs, variables) { + const node = byId.get(id); + if (!node) return outputs[id]; + if (node.type === 'readvar') return variables[String(node.varName || '').trim()] ?? ''; + if (node.type === 'value') return node.text || ''; + return outputs[id]; +} + function execOut(edges, id, branch = null) { const out = outgoing(edges, id).filter((e) => kindOf(e) === EXEC); if (branch === null) return out; @@ -350,11 +368,8 @@ function execOut(edges, id, branch = null) { function collectInput(id, edges, outputs, variables, byId) { const parts = []; for (const e of dataIn(edges, id)) { - const node = byId.get(e.from); - // 纯节点:现取现值 - const value = node && node.type === 'readvar' - ? (variables[String(node.varName || '').trim()] ?? '') - : outputs[e.from]; + // 纯节点(读变量 / 值)现取现值,普通节点取它执行时的输出 + const value = pureValue(e.from, byId, outputs, variables); if (value) parts.push(String(value)); } if (parts.length) return parts.join('\n\n').trim();