fix: preserve knowledge base references

This commit is contained in:
吉鑫升 committed 2026-08-31 18:02:05 +08:00
1 parent 40542db400
commit 8e0d755b57
7 files changed
+43 -13

No files matched your search

@@ -86,7 +86,11 @@ const ChatBox: React.FC<{
threadId, threadId,
disableArtifacts = false, disableArtifacts = false,
}) => { }) => {
const { isMock, thread } = useThread(); const {
isMock,
thread,
knowledgeReferencesEnabled = false,
} = useThread();
const pathname = usePathname(); const pathname = usePathname();
const threadIdRef = useRef(threadId); const threadIdRef = useRef(threadId);
const artifactsCountRef = useRef(0); const artifactsCountRef = useRef(0);
@@ -107,7 +111,8 @@ const ChatBox: React.FC<{
citationDisplay?.reference_mode_enabled ?? false; citationDisplay?.reference_mode_enabled ?? false;
const ragModeEnabled = const ragModeEnabled =
(referenceModeEntryEnabled && settings.display.ragModeEnabled) || (referenceModeEntryEnabled && settings.display.ragModeEnabled) ||
isThreadRagModeLocked(threadId); isThreadRagModeLocked(threadId) ||
knowledgeReferencesEnabled;
// Frontend RAG modes write their own hidden source tool messages. They use // Frontend RAG modes write their own hidden source tool messages. They use
// the existing reference panel, but must not request or write reference // the existing reference panel, but must not request or write reference
// batches through DeerFlow's backend APIs. // batches through DeerFlow's backend APIs.
@@ -121,7 +126,7 @@ const ChatBox: React.FC<{
); );
const referencesEnabled = ragModeEnabled || hasFrontendRag; const referencesEnabled = ragModeEnabled || hasFrontendRag;
const shouldFetchBackendReferenceBatches = const shouldFetchBackendReferenceBatches =
referencesEnabled && !hasFrontendRag; referencesEnabled && !hasFrontendRag && !!threadId && threadId !== "new";
const { skills } = useSkills(); const { skills } = useSkills();
const canScanArtifactDirectory = const canScanArtifactDirectory =
@@ -4,11 +4,17 @@ import { createContext, useContext } from "react";
import type { RuntimeDisplaySource } from "@/core/skill-display/runtime"; import type { RuntimeDisplaySource } from "@/core/skill-display/runtime";
import type { AgentThreadState } from "@/core/threads"; import type { AgentThreadState } from "@/core/threads";
export interface ThreadContextType { export interface ThreadContextType {
thread: BaseStream<AgentThreadState>; thread: BaseStream<AgentThreadState>;
isMock?: boolean; isMock?: boolean;
/** /**
* When set, the conversation is rendered from a public read-only share. * True when the active conversation has selected LLMWiki knowledge bases.
* Knowledge-base Q&A should always expose its source documents, independent
* from the admin-controlled manual reference-mode button.
*/
knowledgeReferencesEnabled?: boolean;
/**
* When set, the conversation is rendered from a public read-only share.
* Artifact/image URLs then resolve to the unauthenticated * Artifact/image URLs then resolve to the unauthenticated
* `/api/public/shares/{code}/files/...` endpoint instead of the * `/api/public/shares/{code}/files/...` endpoint instead of the
* auth-gated thread artifact route. * auth-gated thread artifact route.
@@ -305,9 +305,12 @@ export function MessageList({
const { data: citationDisplay } = useCitationDisplaySettings(); const { data: citationDisplay } = useCitationDisplaySettings();
const referenceModeEntryEnabled = const referenceModeEntryEnabled =
citationDisplay?.reference_mode_enabled ?? false; citationDisplay?.reference_mode_enabled ?? false;
const knowledgeReferencesEnabled =
threadContext?.knowledgeReferencesEnabled === true;
const ragModeEnabled = const ragModeEnabled =
(referenceModeEntryEnabled && settings.display.ragModeEnabled) || (referenceModeEntryEnabled && settings.display.ragModeEnabled) ||
isThreadRagModeLocked(threadId); isThreadRagModeLocked(threadId) ||
knowledgeReferencesEnabled;
const hasSingleRoundRag = useMemo( const hasSingleRoundRag = useMemo(
() => () =>
messages.some( messages.some(
+7 -1
View File
@@ -779,7 +779,13 @@ export default function AgentChatPage({
: "ready"; : "ready";
return ( return (
<ThreadContext.Provider value={{ thread: displayThread }}> <ThreadContext.Provider
value={{
thread: displayThread,
knowledgeReferencesEnabled:
knowledgeSelectionReady && selectedKnowledgeBaseIds.length > 0,
}}
>
{/* Root: fixed-height horizontal split. ChatBox (chat + artifact {/* Root: fixed-height horizontal split. ChatBox (chat + artifact
preview) lives in the left flex cell; the agent detail panel is a preview) lives in the left flex cell; the agent detail panel is a
separate flex sibling OUTSIDE ChatBox, so the artifact preview separate flex sibling OUTSIDE ChatBox, so the artifact preview
+8 -1
View File
@@ -688,7 +688,14 @@ export default function ChatPage() {
!isWujieEnv(); !isWujieEnv();
return ( return (
<ThreadContext.Provider value={{ thread: displayThread, isMock }}> <ThreadContext.Provider
value={{
thread: displayThread,
isMock,
knowledgeReferencesEnabled:
knowledgeSelectionReady && selectedKnowledgeBaseIds.length > 0,
}}
>
<ChatBox threadId={threadId}> <ChatBox threadId={threadId}>
<div <div
className={cn( className={cn(
+2 -1
View File
@@ -486,7 +486,8 @@ frontend can hide or show the entry consistently; `PUT` is admin-only and
partially updates `reference_mode_enabled` and/or `cleanup_words`. The normal partially updates `reference_mode_enabled` and/or `cleanup_words`. The normal
workspace input box, iframe chat toolbar, send context, right reference panel, workspace input box, iframe chat toolbar, send context, right reference panel,
and appearance settings all use this flag, while already locked citation and appearance settings all use this flag, while already locked citation
threads and knowledge-base selections still render their references. Tests: threads and selected LLMWiki knowledge bases still render their source
documents in the reference panel. Tests:
`tests/test_prompt_prefix.py` and `tests/test_prompt_prefix.py` and
`frontend-web/src/pages/iframe-chat-mode-buttons.test.ts`. `frontend-web/src/pages/iframe-chat-mode-buttons.test.ts`.
+3 -1
View File
@@ -670,7 +670,9 @@ Reference-mode entry points are controlled by `citation_display` in
`.deer-flow/system_settings.json`. `reference_mode_enabled` defaults to `false`; `.deer-flow/system_settings.json`. `reference_mode_enabled` defaults to `false`;
when disabled, the frontend hides the "参考文献" composer button in both the when disabled, the frontend hides the "参考文献" composer button in both the
normal workspace and iframe chat, and hides the per-user RAG citation toggle normal workspace and iframe chat, and hides the per-user RAG citation toggle
from appearance settings. `GET /api/system-settings/citation-display` is from appearance settings. Conversations with selected LLMWiki knowledge bases
still show their source documents in the reference panel even when the manual
entry is hidden. `GET /api/system-settings/citation-display` is
readable by logged-in users so the UI can decide whether to expose the entry; readable by logged-in users so the UI can decide whether to expose the entry;
`PUT /api/system-settings/citation-display` is admin-only and supports partial `PUT /api/system-settings/citation-display` is admin-only and supports partial
updates for both `reference_mode_enabled` and `cleanup_words`. updates for both `reference_mode_enabled` and `cleanup_words`.