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

@@ -18,6 +18,7 @@ from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
from deerflow.knowledge.models import (
KnowledgeEmbeddingRow,
KnowledgeEntityRow,
KnowledgeGraphBlacklistRow,
KnowledgeNoteRow,
KnowledgeNoteTagRow,
KnowledgeNoteVersionRow,
@@ -485,6 +486,49 @@ class KnowledgeRepository:
rows = (await session.execute(select(KnowledgeEntityRow))).scalars()
return [{"id": r.id, "name": r.name, "entity_type": r.entity_type} for r in rows]
# -- graph blacklist ---------------------------------------------------
async def list_graph_blacklist(self) -> list[dict[str, Any]]:
"""Return every blacklisted graph node label, newest first."""
async with self._sf() as session:
stmt = select(KnowledgeGraphBlacklistRow).order_by(KnowledgeGraphBlacklistRow.created_at.desc())
rows = (await session.execute(stmt)).scalars()
return [{"id": r.id, "label": r.label, "created_by": r.created_by, "created_at": _iso(r.created_at)} for r in rows]
async def add_graph_blacklist(self, labels: list[str], *, created_by: str | None = None) -> int:
"""Add labels to the graph blacklist (trimmed, case-insensitive dedup). Returns the count actually added."""
cleaned: list[str] = []
seen: set[str] = set()
for raw in labels or []:
label = (raw or "").strip()
if not label or label.lower() in seen:
continue
seen.add(label.lower())
cleaned.append(label)
if not cleaned:
return 0
async with self._sf() as session:
existing = {
value
for (value,) in (
await session.execute(select(func.lower(KnowledgeGraphBlacklistRow.label)).where(func.lower(KnowledgeGraphBlacklistRow.label).in_([label.lower() for label in cleaned])))
).all()
}
added = 0
for label in cleaned:
if label.lower() in existing:
continue
session.add(KnowledgeGraphBlacklistRow(id=_new_id("kbblk"), label=label, created_by=created_by, created_at=datetime.now(UTC)))
added += 1
if added:
await session.commit()
return added
async def remove_graph_blacklist(self, entry_id: str) -> bool:
async with self._sf() as session:
result = await session.execute(delete(KnowledgeGraphBlacklistRow).where(KnowledgeGraphBlacklistRow.id == entry_id))
await session.commit()
return bool(result.rowcount)
async def list_relations(self) -> list[dict[str, Any]]:
async with self._sf() as session:
rows = (await session.execute(select(KnowledgeRelationRow))).scalars()