diff --git a/frontend/src/api/chat/index.ts b/frontend/src/api/chat/index.ts index 38e71136..dcc139f5 100644 --- a/frontend/src/api/chat/index.ts +++ b/frontend/src/api/chat/index.ts @@ -19,8 +19,17 @@ export async function knowledgeChat(data: { session_id: string; query: string; } } // Agent chat with streaming support -export async function agentChat(data: { session_id: string; query: string; }) { - return postChat(`/api/v1/agent-chat/${data.session_id}`, { query: data.query }); +export async function agentChat(data: { + session_id: string; + query: string; + knowledge_base_ids?: string[]; + agent_enabled: boolean; +}) { + return postChat(`/api/v1/agent-chat/${data.session_id}`, { + query: data.query, + knowledge_base_ids: data.knowledge_base_ids, + agent_enabled: data.agent_enabled + }); } export async function getMessageList(data: { session_id: string; limit: number, created_at: string }) { @@ -33,4 +42,8 @@ export async function getMessageList(data: { session_id: string; limit: number, export async function delSession(session_id: string) { return del(`/api/v1/sessions/${session_id}`); +} + +export async function getSession(session_id: string) { + return get(`/api/v1/sessions/${session_id}`); } \ No newline at end of file diff --git a/frontend/src/api/chat/streame.ts b/frontend/src/api/chat/streame.ts index 26cb4901..eb8580a2 100644 --- a/frontend/src/api/chat/streame.ts +++ b/frontend/src/api/chat/streame.ts @@ -28,7 +28,7 @@ export function useStream() { let renderTimer: number | null = null // 启动流式请求 - const startStream = async (params: { session_id: any; query: any; method: string; url: string }) => { + const startStream = async (params: { session_id: any; query: any; knowledge_base_ids?: string[]; agent_enabled?: boolean; method: string; url: string }) => { // 重置状态 output.value = ''; error.value = null; @@ -46,11 +46,33 @@ export function useStream() { return; } + // Validate knowledge_base_ids for agent-chat requests + 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; + } + } + try { let url = params.method == "POST" ? `${apiUrl}${params.url}/${params.session_id}` : `${apiUrl}${params.url}/${params.session_id}?message_id=${params.query}`; + + // Prepare POST body with required fields for agent-chat + // knowledge_base_ids array and agent_enabled can update Session's SessionAgentConfig + const postBody: any = { + query: params.query, + agent_enabled: params.agent_enabled !== undefined ? params.agent_enabled : true + }; + // Always include knowledge_base_ids for agent-chat (already validated above) + if (params.knowledge_base_ids !== undefined && params.knowledge_base_ids.length > 0) { + postBody.knowledge_base_ids = params.knowledge_base_ids; + } + await fetchEventSource(url, { method: params.method, headers: { @@ -60,7 +82,7 @@ export function useStream() { }, body: params.method == "POST" - ? JSON.stringify({ query: params.query }) + ? JSON.stringify(postBody) : null, signal: controller.signal, openWhenHidden: true, diff --git a/frontend/src/api/knowledge-base/index.ts b/frontend/src/api/knowledge-base/index.ts index e507d332..74181014 100644 --- a/frontend/src/api/knowledge-base/index.ts +++ b/frontend/src/api/knowledge-base/index.ts @@ -5,7 +5,18 @@ export function listKnowledgeBases() { return get(`/api/v1/knowledge-bases`); } -export function createKnowledgeBase(data: { name: string; description?: string; chunking_config?: any }) { +export function createKnowledgeBase(data: { + name: string; + description?: string; + chunking_config?: any; + embedding_model_id?: string; + summary_model_id?: string; + rerank_model_id?: string; + vlm_model_id?: string; + vlm_config?: any; + cos_config?: any; + extract_config?: any; +}) { return post(`/api/v1/knowledge-bases`, data); } diff --git a/frontend/src/components/menu.vue b/frontend/src/components/menu.vue index 9c4929c7..4fb84d81 100644 --- a/frontend/src/components/menu.vue +++ b/frontend/src/components/menu.vue @@ -49,32 +49,34 @@ +