Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

refactor: Update chat and knowledge base handling for improved flexibility

wizardchen288dfbd19eb7
diff --git a/frontend/src/api/chat/streame.ts b/frontend/src/api/chat/streame.ts
index eb8580a26..e82b1fc07 100644
--- a/frontend/src/api/chat/streame.ts
+++ b/frontend/src/api/chat/streame.ts
@@ -47,14 +47,11 @@ export function useStream() {
}
// Validate knowledge_base_ids for agent-chat requests
+ // Note: knowledge_base_ids can be empty if user hasn't selected any, but we allow it
+ // The backend will handle the case when no knowledge bases are selected
const isAgentChat = params.url === '/api/v1/agent-chat';
- if (isAgentChat && params.method === 'POST') {
- if (!params.knowledge_base_ids || params.knowledge_base_ids.length === 0) {
- error.value = "请至少选择一个知识库";
- stopStream();
- return;
- }
- }
+ // Removed validation - allow empty knowledge_base_ids array
+ // The backend should handle this case appropriately
try {
let url =
diff --git a/frontend/src/components/menu.vue b/frontend/src/components/menu.vue
index 2a5c3f1aa..8e8d4caaf 100644
--- a/frontend/src/components/menu.vue
+++ b/frontend/src/components/menu.vue
@@ -538,12 +538,13 @@ const handleLogout = () => {
}
const getCurrentKbId = async (): Promise<string | null> => {
+ // Session 不再和知识库绑定,从当前路由获取知识库ID(仅用于知识库详情页)
let kbId = (route.params as any)?.kbId as string
- // 新的路由格式:/platform/chat/:kbId/:chatid,直接从路由参数获取
- if (!kbId && route.name === 'chat' && (route.params as any)?.kbId) {
- kbId = (route.params as any).kbId
+ // 如果当前在知识库详情页,返回知识库ID
+ if (route.name === 'knowledgeBaseDetail' && kbId) {
+ return kbId
}
- return kbId || null
+ return null
}
const gotopage = async (path: string) => {
diff --git a/frontend/src/views/chat/index.vue b/frontend/src/views/chat/index.vue
index 603f6af61..52e6694a6 100644
--- a/frontend/src/views/chat/index.vue
+++ b/frontend/src/views/chat/index.vue
@@ -228,11 +228,8 @@ const sendMsg = async (value) => {
scrollToBottom();
// Always use agent mode with unified architecture
- // Get knowledge_base_ids from session's agent_config.knowledge_bases to update SessionAgentConfig
- let kbIds = [];
- if (sessionData.value?.agent_config?.knowledge_bases?.length > 0) {
- kbIds = sessionData.value.agent_config.knowledge_bases;
- }
+ // Get knowledge_base_ids from settings store (selected by user via KnowledgeBaseSelector)
+ const kbIds = useSettingsStoreInstance.settings.selectedKnowledgeBases || [];
// Validate knowledge_base_ids before sending
if (kbIds.length === 0) {
diff --git a/frontend/src/views/knowledge/KnowledgeBase.vue b/frontend/src/views/knowledge/KnowledgeBase.vue
index 610b531af..e6d0dfc55 100644
--- a/frontend/src/views/knowledge/KnowledgeBase.vue
+++ b/frontend/src/views/knowledge/KnowledgeBase.vue
@@ -179,7 +179,7 @@ const getTitle = (session_id: string, value: string) => {
const now = new Date().toISOString();
let obj = {
title: '新会话',
- path: `chat/${kbId.value}/${session_id}`,
+ path: `chat/${session_id}`,
id: session_id,
isMore: false,
isNoTitle: true,
@@ -189,32 +189,12 @@ const getTitle = (session_id: string, value: string) => {
usemenuStore.updataMenuChildren(obj);
usemenuStore.changeIsFirstSession(true);
usemenuStore.changeFirstQuery(value);
- router.push(`/platform/chat/${kbId.value}/${session_id}`);
+ router.push(`/platform/chat/${session_id}`);
};
async function createNewSession(value: string): Promise<void> {
- // 优先使用当前页面的知识库ID
- let sessionKbId = kbId.value;
-
- // 如果当前页面没有知识库ID,尝试从localStorage获取设置中的知识库ID
- if (!sessionKbId) {
- const settingsStr = localStorage.getItem("WeKnora_settings");
- if (settingsStr) {
- try {
- const settings = JSON.parse(settingsStr);
- sessionKbId = settings.knowledgeBaseId;
- } catch (e) {
- console.error("解析设置失败:", e);
- }
- }
- }
-
- if (!sessionKbId) {
- MessagePlugin.warning("请先选择一个知识库");
- return;
- }
-
- createSessions({ knowledge_base_id: sessionKbId }).then(res => {
+ // Session 不再和知识库绑定,直接创建 Session
+ createSessions({}).then(res => {
if (res.data && res.data.id) {
getTitle(res.data.id, value);
} else {