diff --git a/frontend/src/api/chat.ts b/frontend/src/api/chat.ts index 4331a79..592c908 100644 --- a/frontend/src/api/chat.ts +++ b/frontend/src/api/chat.ts @@ -1,6 +1,5 @@ -import request from './request' import { getToken } from '@/utils/token' -import type { ApiResponse } from '@/types/api' +import type { ChatResult } from '@/types/sse' const API_BASE = '' @@ -28,13 +27,11 @@ export interface ChatOptions { * @param message 用户消息 * @param chatId 会话 ID * @param options 可选参数 - * @param includeEnableRag 是否写入 enableRag 参数(sources 接口无意义,需排除) */ function buildChatQueryParams( message: string, chatId: string, options?: ChatOptions, - includeEnableRag = true, ): URLSearchParams { const params = new URLSearchParams() params.set('message', message) @@ -42,7 +39,7 @@ function buildChatQueryParams( if (options) { if (options.roleId) params.set('roleId', options.roleId) if (options.accountId) params.set('accountId', options.accountId) - if (includeEnableRag && options.enableRag === true) params.set('enableRag', 'true') + if (options.enableRag === true) params.set('enableRag', 'true') if (options.rewriteStrategy) params.set('rewriteStrategy', options.rewriteStrategy) if (options.categoryId !== undefined && options.categoryId !== '') params.set('categoryId', String(options.categoryId)) if (options.categoryIds && options.categoryIds.length > 0) params.set('categoryIds', options.categoryIds.join(',')) @@ -51,10 +48,17 @@ function buildChatQueryParams( return params } -/** 同步对话:GET /ai/chat */ -export function chatSync(message: string, chatId: string, options?: ChatOptions): Promise { - const url = `${API_BASE}/ai/chat?${buildChatQueryParams(message, chatId, options).toString()}` - return fetch(url, { headers: authHeaders() }).then(res => res.text()) +/** 同次回答和引用来源:GET /ai/chat/result(直接 JSON,无 data 包裹)。 */ +export function chatSync(message: string, chatId: string, options?: ChatOptions, signal?: AbortSignal): Promise { + const url = `${API_BASE}/ai/chat/result?${buildChatQueryParams(message, chatId, options).toString()}` + return fetchChatResult(url, authHeaders(), signal) +} + +/** SDK 测试页也复用此响应处理,保留其独立域名与 SDK Token。 */ +export async function fetchChatResult(url: string, headers: Record, signal?: AbortSignal): Promise { + const res = await fetch(url, { headers, signal }) + if (!res.ok) throw new Error((await res.text()) || 'HTTP ' + res.status) + return res.json() } /** 获取 SSE 流式对话 URL:GET /ai/chat/stream */ @@ -62,12 +66,6 @@ export function chatSSEUrl(message: string, chatId: string, options?: ChatOption return `${API_BASE}/ai/chat/stream?${buildChatQueryParams(message, chatId, options).toString()}` } -/** 获取 RAG 引用来源:GET /ai/chat/sources(不传 enableRag,其余参数照传) */ -export function ragSources(message: string, chatId: string, options?: ChatOptions): Promise { - const path = `/ai/chat/sources?${buildChatQueryParams(message, chatId, options, false).toString()}` - return request.get(path).then(r => r.data) -} - /** * 获取 AI 推荐问题列表(管理后台 ChatPanel 用)。 * 调用 /conversation/{id}/suggestions,由管理后台 JwtAuthFilter 守卫。 diff --git a/frontend/src/components/MessageSources.vue b/frontend/src/components/MessageSources.vue index d76c7aa..92b1ab8 100644 --- a/frontend/src/components/MessageSources.vue +++ b/frontend/src/components/MessageSources.vue @@ -5,9 +5,9 @@
📄 {{ group.title || '文档 ' + key }}
-
- #{{ chunk.chunkIndex }} - +
+ #{{ chunk.chunkIndex }} +
@@ -19,17 +19,18 @@