fix: restore rag chat permission feedback

This commit is contained in:
wren
2026-05-22 15:36:13 +08:00
parent 9434f2b22b
commit d52b1cfdb9
5 changed files with 258 additions and 4 deletions
@@ -1,3 +1,5 @@
"""RAG 聊天服务实现。"""
from __future__ import annotations
import asyncio
@@ -49,6 +51,8 @@ MANUAL_TITLE_SOURCE = "manual"
class RagChatServiceImpl(IRagChatService):
"""RAG 聊天服务实现。"""
_message_tasks: dict[str, asyncio.Task] = {}
_task_events: dict[str, list[dict]] = {}
_task_done: dict[str, bool] = {}
@@ -1143,14 +1147,17 @@ class RagChatServiceImpl(IRagChatService):
except Exception:
followups = []
sources = self._build_sources(context_chunks, dataset_name)
if message_end_payload:
message_end_payload.setdefault("metadata", {})["suggested_questions"] = followups
message_end_metadata = message_end_payload.setdefault("metadata", {})
message_end_metadata["suggested_questions"] = followups
message_end_metadata["retriever_resources"] = sources
await self._append_task_event(task_id, message_end_payload)
await self._finalize_message_record(
conversation_id=conversation_id,
message_id=message_id,
content=collected_answer,
sources=self._build_sources(context_chunks, dataset_name),
sources=sources,
metadata={"suggested_questions": followups, "status": "completed", "task_id": task_id},
)
await self._maybe_schedule_auto_title(
@@ -1,3 +1,5 @@
"""RAG 知识库服务实现。"""
from __future__ import annotations
import asyncio
@@ -42,6 +44,8 @@ from fastapi_modules.fastapi_leaudit.services.impl.tenantResolver import TenantR
class RagDatasetServiceImpl(IRagDatasetService):
"""RAG 知识库服务实现。"""
_ACTIVE_INDEXING_STATUSES = {"waiting", "parsing", "cleaning", "splitting", "indexing"}
_DELETABLE_DOCUMENT_STATUSES = {"completed", "error", "paused"}
_APP_LINK_SQL = """
@@ -295,7 +299,32 @@ class RagDatasetServiceImpl(IRagDatasetService):
if target_is_default:
await self._clear_default_flags(session, tenant_code=resolved_tenant_code)
elif existing.get("is_default") and Body.get("is_default") is False:
raise LeauditException(StatusCodeEnum.HTTP_400_BAD_REQUEST, "默认知识库不能直接取消,请先将其他知识库设为默认")
normalized_tenant_code = str(resolved_tenant_code or "").strip()
default_filters = [
"deleted_at IS NULL",
"is_default = TRUE",
"id <> :dataset_id",
]
default_params = {"dataset_id": DatasetId}
if normalized_tenant_code:
default_filters.append("tenant_code = :tenant_code")
default_params["tenant_code"] = normalized_tenant_code
else:
default_filters.append("(tenant_code IS NULL OR BTRIM(tenant_code) = '')")
other_default_count = (
await session.execute(
text(
f"""
SELECT COUNT(1)
FROM rag_dataset
WHERE {" AND ".join(default_filters)}
"""
),
default_params,
)
).scalar_one()
if int(other_default_count or 0) <= 0:
raise LeauditException(StatusCodeEnum.HTTP_400_BAD_REQUEST, "默认知识库不能直接取消,请先将其他知识库设为默认")
await session.execute(
text(
"""