fix 文档管理模块 & 法规对话模块

This commit is contained in:
wangwei
2026-05-20 23:34:08 +08:00
parent c22b03dc07
commit b065d55c86
39 changed files with 1671 additions and 540 deletions
+17 -10
View File
@@ -2,15 +2,21 @@ import type { QuickQuestionsResponse, SSEMessage } from './index';
const AGENT_API_BASE = '/api/v1';
const _FALLBACK_QUESTIONS = [
{ id: '1', question: '请总结最新入库法规对电池安全的核心要求', category: '法规解读' },
{ id: '2', question: '我上传的制度文档与新能源法规有哪些潜在冲突?', category: '差距分析' },
{ id: '3', question: '请给出法规依据,并按条款列出整改建议', category: '整改建议' },
{ id: '4', question: '请解释 UN-ECE 与 GB 标准在网络安全方面的差异', category: '标准对比' },
];
export async function getQuickQuestions(): Promise<QuickQuestionsResponse> {
return {
questions: [
{ id: '1', question: '请总结最新入库法规对电池安全的核心要求', category: '法规解读' },
{ id: '2', question: '我上传的制度文档与新能源法规有哪些潜在冲突?', category: '差距分析' },
{ id: '3', question: '请给出法规依据,并按条款列出整改建议', category: '整改建议' },
{ id: '4', question: '请解释 UN-ECE 与 GB 标准在网络安全方面的差异', category: '标准对比' },
],
};
try {
const response = await fetch(`${AGENT_API_BASE}/rag/quick-questions`);
if (!response.ok) throw new Error(`status ${response.status}`);
return response.json() as Promise<QuickQuestionsResponse>;
} catch {
return { questions: _FALLBACK_QUESTIONS };
}
}
function parseSSEChunk(raw: string, onMessage: (data: SSEMessage) => void) {
@@ -67,7 +73,8 @@ export async function ragChat(
topK: number = 5,
onMessage: (data: SSEMessage) => void,
onError?: (error: Error) => void,
onComplete?: () => void
onComplete?: () => void,
filters?: string
): Promise<void> {
try {
const response = await fetch(`${AGENT_API_BASE}/agent/chat/stream`, {
@@ -76,7 +83,7 @@ export async function ragChat(
'Content-Type': 'application/json',
Accept: 'text/event-stream',
},
body: JSON.stringify({ query, top_k: topK }),
body: JSON.stringify({ query, top_k: topK, ...(filters ? { filters } : {}) }),
});
if (!response.ok || !response.body) {