会议模式:把「转换」「运算」补进界面(上一版只做了引擎,界面里根本找不到)
用户问:"运算节点在哪" —— 问得对。上一版我把引擎的 cast / op 做完了、
实测也过了,但**界面里一个都没加**:
- 节点元信息列表(app.py / index.mjs 的 nodeTypes)里没有 → 加节点面板里看不到
- 界面的引脚定义、配色、标题、预览文字、配置面板全都没有
补的:
- 元信息:转换 / 运算 进列表
- 引脚:
转换 入口什么都收;出口类型 = 配置里选的那个
运算 入口类型由算子决定(加法要 num、拼接要 str、比较要 str),
单目只有一个入口、双目两个;出口按算子(加法出 num、比较出 bool)
- 配色:转换深紫(和"值"同族)、运算深青(和变量同族,都是"算东西")
- 配置面板:
转换 → 转成 str / bool / num,并写明真假转换的规则
运算 → 12 种算子,选完**实时显示**"入口要 X、出口是 Y"
- 卡片预览:转换显示"转成文本"、运算显示"加 +"
【顺带修一个更要命的】
加节点面板**不能滚动**。节点类型加到 10 种之后一屏放不下,
「转换」「运算」永远在屏幕外面 —— **等于没加**。
现在能滚了(截图确认:滚到底能看到这两项)。
【验证】
- 引擎回归 40/40,Node 与 Python 16/16 逐用例一致
- 会议 HTTP 13/13 ×2、语音 41/41、Markdown 19/19
- 设备上 /api/meeting/meta 返回 10 种节点类型;
加节点面板滚到底能看到「转换」「运算」
This commit is contained in:
@@ -1181,7 +1181,14 @@ if (edge.kind == "exec") {
|
||||
onDismissRequest = { adding = false },
|
||||
title = { Text("加节点", fontSize = 16.sp) },
|
||||
text = {
|
||||
Column {
|
||||
// ★ 要能滚:节点类型已经有 10 种,一屏放不下 ——
|
||||
// 不能滚的话「转换」「运算」就永远在屏幕外面,等于没加。
|
||||
Column(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(max = 440.dp)
|
||||
.verticalScroll(rememberScrollState()),
|
||||
) {
|
||||
vm.meetingMeta.nodeTypes.forEach { (key, label, desc) ->
|
||||
Column(
|
||||
Modifier.fillMaxWidth()
|
||||
@@ -1190,9 +1197,10 @@ if (edge.kind == "exec") {
|
||||
val n = MeetingNode(
|
||||
id = "n_${System.currentTimeMillis().toString(36)}",
|
||||
type = key,
|
||||
// 新节点摆在偏右下,避免正好压住已有节点
|
||||
x = (120f + meeting.nodes.size * 26f).coerceAtMost(CANVAS_W - NODE_W),
|
||||
y = (120f + meeting.nodes.size * 26f).coerceAtMost(CANVAS_H - NODE_H),
|
||||
// 新节点摆在偏右下,避免正好压住已有节点;
|
||||
// 画布会跟着长,不用管边界
|
||||
x = 120f + meeting.nodes.size * 26f,
|
||||
y = 120f + meeting.nodes.size * 26f,
|
||||
title = label,
|
||||
)
|
||||
meeting = meeting.copy(nodes = meeting.nodes + n)
|
||||
@@ -1281,8 +1289,46 @@ private data class PinSpec(
|
||||
/** 任何数据类型都能接:除了 while 的条件,其他数据入口要的都是文本(见下面注释) */
|
||||
private val ANY_DATA = listOf("str", "bool", "num")
|
||||
|
||||
/**
|
||||
* 运算表。必须和引擎里的 `OPS` **一致** ——
|
||||
* 两边对不上就会出现"界面上选得到、保存时被丢掉"这种说不清的问题。
|
||||
*/
|
||||
private val OPS_UI = listOf(
|
||||
"add" to "加 +", "sub" to "减 −", "mul" to "乘 ×", "div" to "除 ÷",
|
||||
"mod" to "取余 %", "concat" to "拼接", "eq" to "等于 =", "ne" to "不等于 ≠",
|
||||
"gt" to "大于 >", "lt" to "小于 <", "neg" to "取反(负号)", "not" to "逻辑非 !",
|
||||
)
|
||||
|
||||
/** 运算的 (输入类型, 输出类型, 要几个输入)。和引擎的 OPS 一一对应。 */
|
||||
private fun opSpec(key: String): Triple<String, String, Int> = when (key) {
|
||||
"concat" -> Triple("str", "str", 2)
|
||||
"eq", "ne" -> Triple("str", "bool", 2)
|
||||
"gt", "lt" -> Triple("num", "bool", 2)
|
||||
"neg" -> Triple("num", "num", 1)
|
||||
"not" -> Triple("bool", "bool", 1)
|
||||
else -> Triple("num", "num", 2)
|
||||
}
|
||||
|
||||
/** 运算的显示名 */
|
||||
private fun opLabel(key: String): String =
|
||||
OPS_UI.firstOrNull { it.first == key }?.second ?: key
|
||||
|
||||
private fun inputPins(node: MeetingNode): List<PinSpec> = when (node.type) {
|
||||
"start", "readvar", "value" -> emptyList()
|
||||
// 转换:什么都收(出口类型在配置面板里选)
|
||||
"cast" -> listOf(PinSpec("str", "", "值", accepts = ANY_DATA))
|
||||
// 运算:入口类型由算子决定(加法要数字、拼接要文本),单目只有一个入口
|
||||
"op" -> {
|
||||
val (inType, _, arity) = opSpec(node.op.ifBlank { "add" })
|
||||
if (arity == 1) {
|
||||
listOf(PinSpec(inType, "a", if (inType == "num") "数" else "值"))
|
||||
} else {
|
||||
listOf(
|
||||
PinSpec(inType, "a", "A"),
|
||||
PinSpec(inType, "b", "B"),
|
||||
)
|
||||
}
|
||||
}
|
||||
"while" -> listOf(
|
||||
PinSpec("exec", "", "▶"),
|
||||
// 条件:bool 最自然,但变量是字符串,所以两种都收(见 PinSpec 注释)
|
||||
@@ -1309,6 +1355,10 @@ private fun inputPins(node: MeetingNode): List<PinSpec> = when (node.type) {
|
||||
private fun outputPins(node: MeetingNode): List<PinSpec> = when (node.type) {
|
||||
"end" -> emptyList()
|
||||
"readvar" -> listOf(PinSpec("str", "", "值"))
|
||||
// 转换:出口类型就是它要转成的那个类型
|
||||
"cast" -> listOf(PinSpec(node.castTo.ifBlank { "str" }, "", "值"))
|
||||
// 运算:出口类型由算子决定(加法出数字、比较出真假)
|
||||
"op" -> listOf(PinSpec(opSpec(node.op.ifBlank { "add" }).second, "", "结果"))
|
||||
// 值节点的类型由它自己选(str / bool / num)—— 这决定了它能接到哪去
|
||||
"value" -> listOf(PinSpec(node.valueType.ifBlank { "str" }, "", "值"))
|
||||
"judge" -> listOf(
|
||||
@@ -2284,6 +2334,8 @@ private fun nodeColor(type: String): Color = when (type) {
|
||||
"end" -> Color(0xFF7B61FF) // 最终输出:紫
|
||||
"var", "readvar" -> Color(0xFF00A0A0) // 变量:青,和普通逻辑区分开
|
||||
"value" -> Color(0xFF9C6ADE) // 值/常量:淡紫
|
||||
"cast" -> Color(0xFF7E57C2) // 转换:深一点的紫(和"值"同族)
|
||||
"op" -> Color(0xFF00897B) // 运算:深青(和变量同族,都是"算东西")
|
||||
"while" -> Color(0xFFD93025) // 循环:红,醒目
|
||||
else -> Doubao.Blue
|
||||
}
|
||||
@@ -2350,6 +2402,8 @@ private fun NodeCard(
|
||||
"var" -> "写变量"
|
||||
"readvar" -> "读变量"
|
||||
"value" -> "值"
|
||||
"cast" -> "转换"
|
||||
"op" -> "运算"
|
||||
"while" -> "while 循环"
|
||||
else -> "智能体"
|
||||
}
|
||||
@@ -2423,6 +2477,8 @@ private fun NodeCard(
|
||||
node.type == "var" -> node.varName.ifBlank { "没填变量名" }
|
||||
node.type == "readvar" -> node.varName.ifBlank { "没填变量名" }
|
||||
node.type == "value" -> node.text.ifBlank { "(空值)" }
|
||||
node.type == "cast" -> "转成" + typeLabel(node.castTo.ifBlank { "str" })
|
||||
node.type == "op" -> opLabel(node.op.ifBlank { "add" })
|
||||
node.type == "while" -> "条件为真就跑循环体"
|
||||
node.text.isNotBlank() -> node.text
|
||||
else -> "点一下配置"
|
||||
@@ -2755,6 +2811,57 @@ private fun NodeConfigDialog(
|
||||
)
|
||||
}
|
||||
|
||||
"cast" -> {
|
||||
Spacer(Modifier.height(10.dp))
|
||||
FormLabel("转成什么类型")
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Text(
|
||||
"类型校验是认真的,连错类型接不上 —— 所以要有这么一步显式转换。" +
|
||||
"转真假用的是和 while 判断同一套规则:0 / 空 / false / no 是假," +
|
||||
"其他非空都是真。转数字时解析不了就当 0。",
|
||||
fontSize = 11.sp,
|
||||
color = doubaoTextSecondary(),
|
||||
lineHeight = 16.sp,
|
||||
)
|
||||
Spacer(Modifier.height(6.dp))
|
||||
FlowChips(
|
||||
options = listOf(
|
||||
"str" to "文本 str",
|
||||
"bool" to "真假 bool",
|
||||
"num" to "数字 num",
|
||||
),
|
||||
active = draft.castTo.ifBlank { "str" },
|
||||
onPick = { draft = draft.copy(castTo = it) },
|
||||
)
|
||||
}
|
||||
|
||||
"op" -> {
|
||||
Spacer(Modifier.height(10.dp))
|
||||
FormLabel("算什么")
|
||||
Spacer(Modifier.height(4.dp))
|
||||
FlowChips(
|
||||
options = OPS_UI,
|
||||
active = draft.op.ifBlank { "add" },
|
||||
onPick = { draft = draft.copy(op = it) },
|
||||
)
|
||||
Spacer(Modifier.height(6.dp))
|
||||
val (inType, outType, arity) = opSpec(draft.op.ifBlank { "add" })
|
||||
Text(
|
||||
"入口要「${typeLabel(inType)}」,出口是「${typeLabel(outType)}」" +
|
||||
if (arity == 1) "(单目运算,只有一个入口)" else "(两个入口 A / B)",
|
||||
fontSize = 11.sp,
|
||||
color = Doubao.Blue,
|
||||
lineHeight = 16.sp,
|
||||
)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Text(
|
||||
"除零、把文字当数字算都不会让会议停下,会照常往下跑并把问题记在结果里。",
|
||||
fontSize = 11.sp,
|
||||
color = doubaoTextSecondary(),
|
||||
lineHeight = 16.sp,
|
||||
)
|
||||
}
|
||||
|
||||
"readvar" -> {
|
||||
Spacer(Modifier.height(10.dp))
|
||||
VarPicker(
|
||||
|
||||
@@ -692,6 +692,8 @@ class KernelHandler(BaseHTTPRequestHandler):
|
||||
{'key': 'readvar', 'label': '读变量', 'desc': '纯节点:取变量当前值(只出数据,没有 exec)'},
|
||||
{'key': 'value', 'label': '值', 'desc': '纯节点:一个写死的值,接到智能体的数据输入'},
|
||||
{'key': 'while', 'label': 'while 循环', 'desc': '条件为真就跑循环体,像 C 的 while'},
|
||||
{'key': 'cast', 'label': '转换', 'desc': '纯节点:str / bool / num 互转'},
|
||||
{'key': 'op', 'label': '运算', 'desc': '纯节点:+ − × ÷ % 拼接 取反 比较'},
|
||||
],
|
||||
'judgeKinds': [{'key': k, 'label': v} for k, v in meeting.JUDGE_KINDS],
|
||||
'agents': [
|
||||
|
||||
Reference in New Issue
Block a user