sync update from LAN repo (source dhk-1 @ 3b1ec5b4)

This commit is contained in:
gozeros committed 2026-11-05 10:56:34 +08:00
1 parent da6521b6cb
commit 264e2200d6
995 files changed
+148105 -13399

No files matched your search

@@ -1204,7 +1204,7 @@ class AssistantKnowledgeRepository:
stats[base_id][stat_name] = int(stat_value or 0)
return stats
async def get_base(self, base_id: str | None = None) -> dict[str, Any] | None:
async def get_base(self, base_id: str | None = None, *, include_stats: bool = True) -> dict[str, Any] | None:
async with self._sf() as session:
if base_id:
row = (
@@ -1215,7 +1215,9 @@ class AssistantKnowledgeRepository:
)
)
).scalar_one_or_none()
return await self._base_with_stats(session, row) if row else None
if row is None:
return None
return await self._base_with_stats(session, row) if include_stats else _dict(row)
row = (
await session.execute(
@@ -1240,15 +1242,17 @@ class AssistantKnowledgeRepository:
row.updated_at = _now()
await session.flush()
await session.commit()
return await self._base_with_stats(session, row) if row else None
if row is None:
return None
return await self._base_with_stats(session, row) if include_stats else _dict(row)
async def list_bases(self) -> list[dict[str, Any]]:
# Keep the library switcher a metadata-only read. Global alignment can
# scan and rewrite the complete Wiki/vector corpus after a process
# restart, so doing it here makes merely opening the assistant-library
# landing page scale with the size of the largest library. Content
# reads/searches still call ``_ensure_base_aligned`` before returning
# data, and imports align atomically before committing their snapshot.
# searches/exports still call ``_ensure_base_aligned`` for legacy data,
# and imports align atomically before committing their snapshot.
async with self._sf() as session:
rows = list(
(
@@ -2367,10 +2371,12 @@ class AssistantKnowledgeRepository:
include_chunks: bool = False,
include_content: bool = True,
) -> list[dict[str, Any]]:
base = await self.get_base(base_id)
base = await self.get_base(base_id, include_stats=False)
if base is None:
return []
await self._ensure_base_aligned(str(base["id"]))
# Browse the last committed snapshot. Imports already align it before
# commit; waiting for the global import/alignment locks here would make
# opening any library hang behind an unrelated long-running import.
stmt = select(AssistantKnowledgeWikiPageRow).where(
AssistantKnowledgeWikiPageRow.base_id == base["id"],
AssistantKnowledgeWikiPageRow.status == "active",
@@ -3020,10 +3026,9 @@ class AssistantKnowledgeRepository:
return results
async def get_page(self, slug: str, *, base_id: str | None = None) -> dict[str, Any] | None:
base = await self.get_base(base_id)
base = await self.get_base(base_id, include_stats=False)
if base is None:
return None
await self._ensure_base_aligned(str(base["id"]))
stmt = select(AssistantKnowledgeWikiPageRow).where(
AssistantKnowledgeWikiPageRow.base_id == base["id"],
AssistantKnowledgeWikiPageRow.slug == slug.strip("/"),
@@ -3122,7 +3127,7 @@ class AssistantKnowledgeRepository:
return data
async def list_sources(self, *, base_id: str | None = None) -> list[dict[str, Any]]:
base = await self.get_base(base_id)
base = await self.get_base(base_id, include_stats=False)
if base is None:
return []
async with self._sf() as session:
@@ -3162,7 +3167,7 @@ class AssistantKnowledgeRepository:
return result
async def list_jobs(self, limit: int = 100, *, base_id: str | None = None) -> list[dict[str, Any]]:
base = await self.get_base(base_id)
base = await self.get_base(base_id, include_stats=False)
if base is None:
return []
async with self._sf() as session: