feat(ui): 世界观 ↔ 智能体的双向可见(用户要求「哪些智能体绑了它」)(v2.0.50)

## 世界观那侧:谁绑了它

资源 → 世界观,每一行现在显示:

    3 个智能体在用:玄辰、仙辰、小助手
    还没有智能体用它                      ← 空的时候是灰字

绑之前能知道"这个世界观已经有谁在用了"(决定是共用它的记忆还是新建一个);
空的则说明**没人用它**,它的共享记忆也没人在读写。

内核:`GET /api/worldviews` 的每一项多一个 `agents: [{id, name}]`。

★ 为什么不另开一个 `/worldviews/<id>/agents` 子路由:界面进资源页本来就要
拉这个列表,多一个子路由只换来"多一次请求 + 一个可能和列表不同步的缓存"。
数据量很小(智能体几个到几十个),一起算的成本可以忽略。

## 智能体那侧:它绑了谁

智能体管理列表每一行多一行小字:

    世界观「九霄」· 记忆与同世界的智能体共用

★ 文案故意不写"世界观:九霄" —— 干巴巴一个名字看不出**后果**。
  绑世界观真正的含义是"我的记忆和同世界的人共用了",
  这一点必须在列表上就能看见,否则用户在智能体那边永远想不起自己绑过什么。

## 验证

探针新增第 13 节(5 项):
  · 列表每一项都带 agents 字段
  · 绑了它的两个智能体都在
  · 给的是**名字**而不是只有 id
  · 没人绑的世界观 agents 为空
  · **解绑之后列表跟着少一个**(缓存住了的话这里会露馅)

装机:资源 → 世界观列表,空态显示"还没有智能体用它"。
`audit-ui-entries.py`、两个 probe 全绿。
This commit is contained in:
l
2026-10-16 14:54:33 +08:00
parent d3a327da26
commit 56b15f1d19
5 changed files with 96 additions and 4 deletions

View File

@@ -30,8 +30,8 @@ android {
* versionCode 每次发版 +1(Android 靠它判断"能不能覆盖安装", * versionCode 每次发版 +1(Android 靠它判断"能不能覆盖安装",
* 改小了会装不上)。 * 改小了会装不上)。
*/ */
versionCode = 249 versionCode = 250
versionName = "2.0.49" versionName = "2.0.50"
ndk { ndk {
// Chaquopy 只支持这两个;Termux bootstrap 也只准备了这两份 // Chaquopy 只支持这两个;Termux bootstrap 也只准备了这两份

View File

@@ -1,4 +1,4 @@
package com.doubao.lynxclone.ui package com.doubao.lynxclone.ui
import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background import androidx.compose.foundation.background
@@ -47,6 +47,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight 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.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import com.doubao.lynxclone.data.Agent import com.doubao.lynxclone.data.Agent
@@ -124,6 +125,8 @@ fun AgentsScreen(vm: AppViewModel) {
onEdit = { vm.openAgentEdit(agent) }, onEdit = { vm.openAgentEdit(agent) },
onMemories = { vm.openMemories(agent.id) }, onMemories = { vm.openMemories(agent.id) },
onDelete = { confirmDelete = agent }, onDelete = { confirmDelete = agent },
worldName = vm.state.worldviews
.firstOrNull { it.id == agent.worldviewId }?.name.orEmpty(),
) )
} }
@@ -189,6 +192,8 @@ private fun AgentRow(
/** 看这个智能体记住了什么(记忆管理界面的入口之一) */ /** 看这个智能体记住了什么(记忆管理界面的入口之一) */
onMemories: () -> Unit, onMemories: () -> Unit,
onDelete: () -> Unit, onDelete: () -> Unit,
/** 它绑的世界观叫什么(空 = 没绑)。交互是双向的,这边也要看得见 */
worldName: String = "",
) { ) {
Surface( Surface(
modifier = Modifier.fillMaxWidth().clickable(onClick = onUse), modifier = Modifier.fillMaxWidth().clickable(onClick = onUse),
@@ -224,6 +229,19 @@ private fun AgentRow(
color = MaterialTheme.colorScheme.onSurfaceVariant, color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 1, 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,
)
}
} }
// ★「记忆」放在「编辑」**左边**:它是"看它记住了什么", // ★「记忆」放在「编辑」**左边**:它是"看它记住了什么",
// 属于日常动作;编辑是配置动作,用得少。 // 属于日常动作;编辑是配置动作,用得少。

View File

@@ -283,6 +283,21 @@ fun ResourcesScreen(vm: AppViewModel, onBack: () -> Unit) {
maxLines = 2, 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("记忆") { RowAction("记忆") {
// ★ 世界观的**共享记忆**("大家共同记得什么")—— // ★ 世界观的**共享记忆**("大家共同记得什么")——

View File

@@ -691,6 +691,34 @@ _RES_PATH = {
} }
def _tag_world_agents(items: list) -> list:
"""
给每个世界观补一个 `agents: [{id, name}]` —— "谁绑了它"。
★ 为什么在**列表接口**里一起给,而不是开一个 `/worldviews/<id>/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): def _resource_route(handler, seg: list, method: str, body, err):
if seg[1] not in _RES_PATH: if seg[1] not in _RES_PATH:
return None return None
@@ -712,7 +740,15 @@ def _resource_route(handler, seg: list, method: str, body, err):
if len(seg) == 2: if len(seg) == 2:
if method == 'GET': 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 return True
if method == 'POST': if method == 'POST':
handler.send_json(200, {'ok': True, 'item': store.create_resource(name, body())}) handler.send_json(200, {'ok': True, 'item': store.create_resource(name, body())})

View File

@@ -350,6 +350,29 @@ def main():
r = h.call(f"/api/skills/{sid}", "DELETE") r = h.call(f"/api/skills/{sid}", "DELETE")
check("删 skill", r.get("deleted") is True) 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() print()
if fails: if fails: