perf(kb):知识库数据清洗同步改异步优化;chat中查假期请假agent入口优化
This commit is contained in:
1 parent
61ebb46c0f
commit
c3b63df2f5
11 files changed
+839
-171
No files matched your search
+35
-7
@@ -81,6 +81,19 @@ export interface KbJob {
|
||||
finished_at?: string | null;
|
||||
}
|
||||
|
||||
export interface KbQueuedJobResponse extends KbJob {
|
||||
accepted?: boolean;
|
||||
queue_result?: string;
|
||||
}
|
||||
|
||||
export interface KbUploadVersionResponse {
|
||||
accepted?: boolean;
|
||||
message?: string;
|
||||
queue_result?: string;
|
||||
version: KbDocumentVersionItem;
|
||||
clean_job?: KbJob | null;
|
||||
}
|
||||
|
||||
export interface KbDifySettings {
|
||||
DIFY_API_BASE: string;
|
||||
DIFY_API_KEY: string;
|
||||
@@ -339,16 +352,16 @@ export const updateKbDocumentMarkdown = async (
|
||||
export const uploadKbDocumentVersion = async (
|
||||
documentId: number,
|
||||
file: File
|
||||
): Promise<{ ok: boolean; error?: string; version?: KbDocumentVersionItem; status?: number }> => {
|
||||
): Promise<{ ok: boolean; error?: string; version?: KbDocumentVersionItem; clean_job?: KbJob | null; message?: string; status?: number }> => {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const version = await requestJson<KbDocumentVersionItem>(`/api/kb/documents/${documentId}/upload`, {
|
||||
const payload = await requestJson<KbUploadVersionResponse>(`/api/kb/documents/${documentId}/upload`, {
|
||||
method: 'POST',
|
||||
...auth(),
|
||||
body: formData,
|
||||
});
|
||||
return { ok: true, version };
|
||||
return { ok: true, version: payload.version, clean_job: payload.clean_job, message: payload.message };
|
||||
} catch (e) {
|
||||
const err = e as BusinessError;
|
||||
if (err.status === 413) {
|
||||
@@ -362,6 +375,21 @@ export const uploadKbDocumentVersion = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const submitKbDocumentClean = async (
|
||||
documentId: number
|
||||
): Promise<{ ok: boolean; error?: string; job?: KbJob | null; message?: string; status?: number }> => {
|
||||
try {
|
||||
const job = await requestJson<KbQueuedJobResponse>(`/api/kb/documents/${documentId}/clean`, {
|
||||
method: 'POST',
|
||||
...auth(),
|
||||
});
|
||||
return { ok: true, job, message: job.message || undefined };
|
||||
} catch (e) {
|
||||
const err = e as BusinessError;
|
||||
return { ok: false, error: kbErrorMessage(e, '提交清洗任务失败'), status: err.status };
|
||||
}
|
||||
};
|
||||
|
||||
export const createKbPathUploadJob = async (
|
||||
groupId: number,
|
||||
payload: {
|
||||
@@ -431,7 +459,7 @@ export const finalizeKbPathUploadJob = async (
|
||||
jobId: number | string,
|
||||
): Promise<{ ok: boolean; error?: string; job?: KbJob }> => {
|
||||
try {
|
||||
const job = await requestJson<KbJob>(`/api/kb/path-upload-jobs/${jobId}/finalize`, {
|
||||
const job = await requestJson<KbQueuedJobResponse>(`/api/kb/path-upload-jobs/${jobId}/finalize`, {
|
||||
method: 'POST',
|
||||
...auth(),
|
||||
});
|
||||
@@ -476,13 +504,13 @@ export const deleteKbPathJobFile = async (
|
||||
|
||||
export const syncKbDocumentToDify = async (
|
||||
documentId: number
|
||||
): Promise<{ ok: boolean; error?: string; job?: KbJob; run_result?: string }> => {
|
||||
): Promise<{ ok: boolean; error?: string; job?: KbQueuedJobResponse }> => {
|
||||
try {
|
||||
const job = await requestJson<KbJob & { run_result?: string }>(`/api/kb/documents/${documentId}/sync`, {
|
||||
const job = await requestJson<KbQueuedJobResponse>(`/api/kb/documents/${documentId}/sync`, {
|
||||
method: 'POST',
|
||||
...auth(),
|
||||
});
|
||||
return { ok: true, job, run_result: job.run_result };
|
||||
return { ok: true, job };
|
||||
} catch (e) {
|
||||
return { ok: false, error: kbErrorMessage(e, '同步到 Dify 失败') };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user