fix: async document processing in background threads, improve chat UX

- Fix knowledge_base_service calling async process_document synchronously
  in background threads — use asyncio.new_event_loop().run_until_complete()
  instead of bare call that returned unawaited coroutine
- Same fix for _update_document and reindex_document
- Replace ModeSelector with auto-detect: RAG mode when knowledge bases selected
- Convert regenerateMessage to streaming (was synchronous API call)
- Show "知识库检索模式" indicator above input when KB selected
- Remove loadSessions side-effect from streaming onComplete
- Fix chat page loading state to avoid flash
- Improve forum page spacing and sizing

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-27 11:33:32 +08:00
parent 50faf7ad4e
commit 62da8b3c58
5 changed files with 250 additions and 157 deletions
+4 -3
View File
@@ -14,9 +14,10 @@ import { PanelLeftClose, PanelLeftOpen } from "lucide-react";
export default function ChatPage() {
const router = useRouter();
const { isAuthenticated, user, isLoading: authLoading } = useAuthStore();
const { loadSessions, isLoading: chatLoading } = useChatStore();
const { loadSessions, sessions } = useChatStore();
const [isInitialized, setIsInitialized] = useState(false);
const [sidebarOpen, setSidebarOpen] = useState(true);
const [initialLoading, setInitialLoading] = useState(true);
useEffect(() => {
if (!authLoading && !isAuthenticated) {
@@ -25,12 +26,12 @@ export default function ChatPage() {
}
if (isAuthenticated && !isInitialized) {
loadSessions();
loadSessions().then(() => setInitialLoading(false));
setIsInitialized(true);
}
}, [isAuthenticated, authLoading, isInitialized, router, loadSessions]);
if (authLoading || chatLoading) {
if (authLoading || initialLoading) {
return (
<div className="min-h-screen flex items-center justify-center">
<LoadingSpinner size="lg" />