feat: 完善知识图谱交互与 Agent/线程持久化

- 知识图谱画布、侧边栏、详情面板交互优化,新增图谱相关 API 与 hooks
- Agent 卡片与详情面板调整,对话页面重构
- 线程元数据持久化增强(base/memory/sql),knowledge 仓储与导出补充
- 网关路由 agents/knowledge/threads 同步更新

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
吉鑫升andClaude Opus 4.8 committed 2026-06-11 19:58:34 +08:00
1 parent ea78fe9726
commit f107ebc46d
25 files changed
+929 -279

No files matched your search

@@ -25,10 +25,22 @@ def _vault_key(vault_path: str | None) -> str | None:
return key
def normalize_blacklist(labels: list[str] | set[str] | None) -> set[str]:
"""Normalize blacklist labels for matching (trimmed, lower-cased, non-empty)."""
out: set[str] = set()
for raw in labels or []:
label = (raw or "").strip().lower()
if label:
out.add(label)
return out
def build_graph(
notes: list[dict[str, Any]],
entities: list[dict[str, Any]] | None = None,
relations: list[dict[str, Any]] | None = None,
*,
blacklist: set[str] | None = None,
) -> dict[str, Any]:
"""Return ``{nodes, edges}`` from notes (+ optional entities/relations).
@@ -36,7 +48,20 @@ def build_graph(
when ``entities``/``relations`` are supplied (phase 4), entity nodes and
note→entity / entity→entity edges are added on top of the wikilink and
shared-tag edges.
``blacklist`` is a set of *normalized* labels (see :func:`normalize_blacklist`);
notes whose title and entities whose name match are dropped, together with
every edge touching them (edges only join surviving nodes).
"""
blocked = blacklist or set()
def _is_blocked(label: str | None) -> bool:
return bool(blocked) and (label or "").strip().lower() in blocked
# Drop blacklisted notes up front so the wikilink / shared-tag edge loops
# below never reference them either.
notes = [n for n in notes if not _is_blocked(n.get("title"))]
nodes = []
by_key: dict[str, str] = {}
note_ids: set[str] = set()
@@ -59,6 +84,8 @@ def build_graph(
for ent in entities or []:
if ent["id"] not in mentioned:
continue
if _is_blocked(ent.get("name")):
continue
nodes.append({"id": ent["id"], "type": "entity", "label": ent.get("name") or ent["id"], "category": ent.get("entity_type")})
entity_ids.add(ent["id"])
@@ -156,11 +183,12 @@ def export_all(
relations: list[dict[str, Any]] | None = None,
write_html: bool = True,
write_json: bool = True,
blacklist: set[str] | None = None,
) -> dict[str, Any]:
"""Generate graph artifacts under ``<vault>/wiki-export/`` and return stats."""
out_dir = Path(vault_root).resolve() / "wiki-export"
out_dir.mkdir(parents=True, exist_ok=True)
graph = build_graph(notes, entities, relations)
graph = build_graph(notes, entities, relations, blacklist=blacklist)
written: list[str] = []
if write_json:
(out_dir / "graph.json").write_text(json.dumps(graph, ensure_ascii=False, indent=2), encoding="utf-8")