From 56b15f1d192d3b7c0c13721093f77669867d1971 Mon Sep 17 00:00:00 2001 From: l Date: Fri, 16 Oct 2026 14:54:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20=E4=B8=96=E7=95=8C=E8=A7=82=20?= =?UTF-8?q?=E2=86=94=20=E6=99=BA=E8=83=BD=E4=BD=93=E7=9A=84=E5=8F=8C?= =?UTF-8?q?=E5=90=91=E5=8F=AF=E8=A7=81=EF=BC=88=E7=94=A8=E6=88=B7=E8=A6=81?= =?UTF-8?q?=E6=B1=82=E3=80=8C=E5=93=AA=E4=BA=9B=E6=99=BA=E8=83=BD=E4=BD=93?= =?UTF-8?q?=E7=BB=91=E4=BA=86=E5=AE=83=E3=80=8D=EF=BC=89=EF=BC=88v2.0.50?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 世界观那侧:谁绑了它 资源 → 世界观,每一行现在显示: 3 个智能体在用:玄辰、仙辰、小助手 还没有智能体用它 ← 空的时候是灰字 绑之前能知道"这个世界观已经有谁在用了"(决定是共用它的记忆还是新建一个); 空的则说明**没人用它**,它的共享记忆也没人在读写。 内核:`GET /api/worldviews` 的每一项多一个 `agents: [{id, name}]`。 ★ 为什么不另开一个 `/worldviews//agents` 子路由:界面进资源页本来就要 拉这个列表,多一个子路由只换来"多一次请求 + 一个可能和列表不同步的缓存"。 数据量很小(智能体几个到几十个),一起算的成本可以忽略。 ## 智能体那侧:它绑了谁 智能体管理列表每一行多一行小字: 世界观「九霄」· 记忆与同世界的智能体共用 ★ 文案故意不写"世界观:九霄" —— 干巴巴一个名字看不出**后果**。 绑世界观真正的含义是"我的记忆和同世界的人共用了", 这一点必须在列表上就能看见,否则用户在智能体那边永远想不起自己绑过什么。 ## 验证 探针新增第 13 节(5 项): · 列表每一项都带 agents 字段 · 绑了它的两个智能体都在 · 给的是**名字**而不是只有 id · 没人绑的世界观 agents 为空 · **解绑之后列表跟着少一个**(缓存住了的话这里会露馅) 装机:资源 → 世界观列表,空态显示"还没有智能体用它"。 `audit-ui-entries.py`、两个 probe 全绿。 --- android/app/build.gradle.kts | 4 +- .../com/doubao/lynxclone/ui/AgentsScreen.kt | 20 +++++++++- .../doubao/lynxclone/ui/ResourcesScreen.kt | 15 ++++++++ android/kernel/agent_api.py | 38 ++++++++++++++++++- scripts/probe-agent-system.py | 23 +++++++++++ 5 files changed, 96 insertions(+), 4 deletions(-) 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: