diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 6edb1d4..6614977 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -30,8 +30,8 @@ android { * versionCode 每次发版 +1(Android 靠它判断"能不能覆盖安装", * 改小了会装不上)。 */ - versionCode = 249 - versionName = "2.0.49" + versionCode = 250 + versionName = "2.0.50" ndk { // Chaquopy 只支持这两个;Termux bootstrap 也只准备了这两份 diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/AgentsScreen.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/AgentsScreen.kt index 19639c7..95297c6 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/AgentsScreen.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/AgentsScreen.kt @@ -1,4 +1,4 @@ -package com.doubao.lynxclone.ui +package com.doubao.lynxclone.ui import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.background @@ -47,6 +47,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.doubao.lynxclone.data.Agent @@ -124,6 +125,8 @@ fun AgentsScreen(vm: AppViewModel) { onEdit = { vm.openAgentEdit(agent) }, onMemories = { vm.openMemories(agent.id) }, onDelete = { confirmDelete = agent }, + worldName = vm.state.worldviews + .firstOrNull { it.id == agent.worldviewId }?.name.orEmpty(), ) } @@ -189,6 +192,8 @@ private fun AgentRow( /** 看这个智能体记住了什么(记忆管理界面的入口之一) */ onMemories: () -> Unit, onDelete: () -> Unit, + /** 它绑的世界观叫什么(空 = 没绑)。交互是双向的,这边也要看得见 */ + worldName: String = "", ) { Surface( modifier = Modifier.fillMaxWidth().clickable(onClick = onUse), @@ -224,6 +229,19 @@ private fun AgentRow( color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1, ) + // ★ 绑了哪个世界观(用户要求"互通")—— + // 重点不是"它有个世界观",而是**它和谁共用记忆**。 + // 所以文案直接写"共用记忆",而不是干巴巴一个名字。 + if (agent.worldviewId.isNotBlank()) { + Spacer(Modifier.height(3.dp)) + Text( + "世界观「${worldName.ifBlank { "已失效" }}」· 记忆与同世界的智能体共用", + fontSize = 10.sp, + color = Doubao.Blue, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + } } // ★「记忆」放在「编辑」**左边**:它是"看它记住了什么", // 属于日常动作;编辑是配置动作,用得少。 diff --git a/android/app/src/main/java/com/doubao/lynxclone/ui/ResourcesScreen.kt b/android/app/src/main/java/com/doubao/lynxclone/ui/ResourcesScreen.kt index 2558fb5..e1ce497 100644 --- a/android/app/src/main/java/com/doubao/lynxclone/ui/ResourcesScreen.kt +++ b/android/app/src/main/java/com/doubao/lynxclone/ui/ResourcesScreen.kt @@ -283,6 +283,21 @@ fun ResourcesScreen(vm: AppViewModel, onBack: () -> Unit) { maxLines = 2, ) } + // ★ 谁绑了它(用户要求)—— 反过来也得看得见: + // 绑之前你要知道"这个世界观已经有谁在用了", + // 空的则说明没人用它、共享记忆也没人在读写。 + if (kind.id == "worldviews") { + val users = vm.state.worldviews.firstOrNull { it.id == id }?.agents ?: emptyList() + Spacer(Modifier.height(3.dp)) + Text( + if (users.isEmpty()) "还没有智能体用它" + else "${users.size} 个智能体在用:${users.joinToString("、") { it.name }}", + fontSize = 10.sp, + lineHeight = 14.sp, + color = if (users.isEmpty()) doubaoTextSecondary() else Doubao.Blue, + maxLines = 2, + ) + } } RowAction("记忆") { // ★ 世界观的**共享记忆**("大家共同记得什么")—— diff --git a/android/kernel/agent_api.py b/android/kernel/agent_api.py index af9f2f9..246e914 100644 --- a/android/kernel/agent_api.py +++ b/android/kernel/agent_api.py @@ -691,6 +691,34 @@ _RES_PATH = { } +def _tag_world_agents(items: list) -> list: + """ + 给每个世界观补一个 `agents: [{id, name}]` —— "谁绑了它"。 + + ★ 为什么在**列表接口**里一起给,而不是开一个 `/worldviews//agents`: + 界面本来就要拉这个列表(进资源页就拉),多一个子路由只换来 + "多一次请求 + 一个可能和列表不同步的缓存"。这个数据量很小 + (智能体通常几个到几十个),一起算的成本可以忽略。 + + ★ 顺便能看出**没绑的**(`agents` 为空)—— 那意味着这个世界观 + 目前没人用,它的共享记忆也没有人在读写。 + """ + by_world = {} + for a in store.list_agents(): + wid = (a.get('worldviewId') or '').strip() + if wid: + by_world.setdefault(wid, []).append({ + 'id': a.get('id') or '', + 'name': a.get('name') or '未命名', + }) + out = [] + for it in items or []: + it = dict(it) + it['agents'] = by_world.get((it.get('id') or '').strip(), []) + out.append(it) + return out + + def _resource_route(handler, seg: list, method: str, body, err): if seg[1] not in _RES_PATH: return None @@ -712,7 +740,15 @@ def _resource_route(handler, seg: list, method: str, body, err): if len(seg) == 2: if method == 'GET': - handler.send_json(200, {'ok': True, 'items': store.list_resource(name)}) + items = store.list_resource(name) + if name == 'worldviews': + # ★ 给世界观补上"哪些智能体绑了它"(用户要求)。 + # 没有这个的话,你在绑之前想知道"这个世界观已经有谁在用了", + # 只能回智能体列表一个个翻 —— 而那正是"互通"该解决的问题。 + # 在**列表接口里一起给**,而不是再开一个 `/agents` 子路由: + # 界面本来就要拉列表,多一次请求只是多一次等待。 + items = _tag_world_agents(items) + handler.send_json(200, {'ok': True, 'items': items}) return True if method == 'POST': handler.send_json(200, {'ok': True, 'item': store.create_resource(name, body())}) diff --git a/scripts/probe-agent-system.py b/scripts/probe-agent-system.py index 17f028b..2d22089 100644 --- a/scripts/probe-agent-system.py +++ b/scripts/probe-agent-system.py @@ -350,6 +350,29 @@ def main(): r = h.call(f"/api/skills/{sid}", "DELETE") check("删 skill", r.get("deleted") is True) + # ---------------------------------------------------------------- 13 + section("13. 世界观的引用列表(谁绑了它)") + lonely = store.create_resource("worldviews", {"name": "没人用的世界", "setting": "空"}) + r = h.call("/api/worldviews", "GET") + items = r.get("items") or [] + check("列表每一项都带 agents 字段", items and all("agents" in it for it in items)) + mine = next((it for it in items if it.get("id") == wv["id"]), None) + check("绑了它的两个智能体都在", mine is not None and len(mine.get("agents") or []) == 2, + str(mine and mine.get("agents"))) + check("给的是名字而不是只有 id", + bool(mine) and all(a.get("name") for a in mine.get("agents") or []), + str(mine and mine.get("agents"))) + empty = next((it for it in items if it.get("id") == lonely["id"]), None) + check("没人绑的世界观 agents 为空(能看出没人用)", + empty is not None and empty.get("agents") == [], str(empty and empty.get("agents"))) + # 解绑之后要跟着变(缓存住了的话这里会露馅) + store.update_agent(a2["id"], {"worldviewId": ""}) + again = next((it for it in (h.call("/api/worldviews", "GET").get("items") or []) + if it.get("id") == wv["id"]), None) + check("解绑之后列表跟着少一个", again is not None and len(again.get("agents") or []) == 1, + str(again and again.get("agents"))) + store.update_agent(a2["id"], {"worldviewId": wv["id"]}) + # ---------------------------------------------------------------- 汇总 print() if fails: