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

@@ -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: