Merge branch 'runny&xinxin' into dev
This commit is contained in:
commit
8d73343bd8
77 files changed
+17955
-274
No files matched your search
@@ -0,0 +1,557 @@
|
||||
import { getAuthHeaders } from '../utils/auth';
|
||||
|
||||
export interface KbGroup {
|
||||
id: number;
|
||||
name: string;
|
||||
description?: string | null;
|
||||
department_id?: number | null;
|
||||
document_count?: number;
|
||||
created_at?: string | null;
|
||||
updated_at?: string | null;
|
||||
}
|
||||
|
||||
export interface KbDocumentItem {
|
||||
id: number;
|
||||
group_id?: number;
|
||||
title: string;
|
||||
description?: string | null;
|
||||
status?: string;
|
||||
source_type?: string | null;
|
||||
created_at?: string | null;
|
||||
updated_at?: string;
|
||||
version_count?: number;
|
||||
latest_version?: KbDocumentVersionItem | null;
|
||||
}
|
||||
|
||||
export interface KbDocumentVersionItem {
|
||||
id: number;
|
||||
document_id: number;
|
||||
version_no: number;
|
||||
status: string;
|
||||
is_current: boolean;
|
||||
source_file_name: string;
|
||||
source_file_ext?: string | null;
|
||||
source_file_size?: number | null;
|
||||
sha256?: string | null;
|
||||
cleaned_file_path?: string | null;
|
||||
cleaned_preview_path?: string | null;
|
||||
error_message?: string | null;
|
||||
created_at?: string | null;
|
||||
}
|
||||
|
||||
export interface KbSyncRecordItem {
|
||||
id: number;
|
||||
group_id?: number | null;
|
||||
document_id?: number | null;
|
||||
document_version_id: number;
|
||||
dataset_id: string;
|
||||
dataset_name?: string | null;
|
||||
remote_document_id: string;
|
||||
remote_document_name?: string | null;
|
||||
status: string;
|
||||
sync_hash?: string | null;
|
||||
error_message?: string | null;
|
||||
synced_at?: string | null;
|
||||
updated_at?: string | null;
|
||||
}
|
||||
|
||||
export interface KbDocumentMarkdown {
|
||||
document_id: number;
|
||||
title: string;
|
||||
version: KbDocumentVersionItem | null;
|
||||
content: string;
|
||||
kind: 'markdown' | 'preview';
|
||||
}
|
||||
|
||||
export interface KbJob {
|
||||
id: number | string;
|
||||
job_type: string;
|
||||
status: string;
|
||||
group_id?: number | null;
|
||||
document_id?: number | null;
|
||||
document_version_id?: number | null;
|
||||
progress?: number;
|
||||
message?: string | null;
|
||||
error_message?: string | null;
|
||||
payload_json?: Record<string, any> | null;
|
||||
result_json?: Record<string, any> | null;
|
||||
created_at?: string;
|
||||
started_at?: string | null;
|
||||
finished_at?: string | null;
|
||||
}
|
||||
|
||||
export interface KbDifySettings {
|
||||
DIFY_API_BASE: string;
|
||||
DIFY_API_KEY: string;
|
||||
KB_DIFY_PERMISSION: string;
|
||||
KB_DIFY_INDEXING_TECHNIQUE: string;
|
||||
KB_DIFY_SEARCH_METHOD: string;
|
||||
KB_DIFY_DOC_FORM: string;
|
||||
dify_api_configured?: boolean;
|
||||
}
|
||||
|
||||
export interface KbDifyHealth {
|
||||
dify_base_url: string;
|
||||
dify_api_configured: boolean;
|
||||
api: {
|
||||
configured: boolean;
|
||||
reachable: boolean;
|
||||
dataset_count?: number | null;
|
||||
error?: string | null;
|
||||
};
|
||||
local_sync_health: {
|
||||
dataset_bound_groups: number;
|
||||
sync_records: number;
|
||||
syncing_versions: number;
|
||||
synced_versions: number;
|
||||
failed_sync_records: number;
|
||||
pending_sync_jobs: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface KbListResponse<T> {
|
||||
ok: boolean;
|
||||
data: T;
|
||||
error?: string;
|
||||
status?: number;
|
||||
}
|
||||
|
||||
const getJson = async <T>(path: string, fallback: T): Promise<T> => {
|
||||
try {
|
||||
const res = await fetch(path, { headers: getAuthHeaders() });
|
||||
if (!res.ok) return fallback;
|
||||
return (await res.json()) as T;
|
||||
} catch {
|
||||
return fallback;
|
||||
}
|
||||
};
|
||||
|
||||
const getJsonWithStatus = async <T>(path: string, fallback: T): Promise<KbListResponse<T>> => {
|
||||
try {
|
||||
const res = await fetch(path, { headers: getAuthHeaders() });
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return {
|
||||
ok: false,
|
||||
data: fallback,
|
||||
error: data?.error || '知识库接口请求失败',
|
||||
status: res.status,
|
||||
};
|
||||
}
|
||||
return { ok: true, data: (await res.json()) as T, status: res.status };
|
||||
} catch {
|
||||
return { ok: false, data: fallback, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const getKbGroups = async (): Promise<KbGroup[]> => {
|
||||
return getJson<KbGroup[]>('/api/kb/groups', []);
|
||||
};
|
||||
|
||||
export const getKbGroupFiles = async (groupId: number): Promise<KbDocumentItem[]> => {
|
||||
return getJson<KbDocumentItem[]>(`/api/kb/groups/${groupId}/files`, []);
|
||||
};
|
||||
|
||||
export const getKbGroupsSafe = async (): Promise<KbListResponse<KbGroup[]>> => {
|
||||
return getJsonWithStatus<KbGroup[]>('/api/kb/groups', []);
|
||||
};
|
||||
|
||||
export const getKbGroupFilesSafe = async (groupId: number): Promise<KbListResponse<KbDocumentItem[]>> => {
|
||||
return getJsonWithStatus<KbDocumentItem[]>(`/api/kb/groups/${groupId}/files`, []);
|
||||
};
|
||||
|
||||
export const createKbGroup = async (payload: {
|
||||
name: string;
|
||||
description?: string;
|
||||
}): Promise<{ ok: boolean; error?: string; group?: KbGroup }> => {
|
||||
try {
|
||||
const res = await fetch('/api/kb/groups', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...getAuthHeaders(),
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return { ok: false, error: data?.error || '创建知识库分组失败' };
|
||||
}
|
||||
return { ok: true, group: (await res.json()) as KbGroup };
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const getKbJobs = async (): Promise<KbJob[]> => {
|
||||
return getJson<KbJob[]>('/api/kb/jobs', []);
|
||||
};
|
||||
|
||||
export const getKbJobsSafe = async (): Promise<KbListResponse<KbJob[]>> => {
|
||||
return getJsonWithStatus<KbJob[]>('/api/kb/jobs', []);
|
||||
};
|
||||
|
||||
export const getKbDifySettings = async (): Promise<KbDifySettings | null> => {
|
||||
return getJson<KbDifySettings | null>('/api/kb/dify/settings', null);
|
||||
};
|
||||
|
||||
export const updateKbDifySettings = async (
|
||||
payload: Partial<KbDifySettings>
|
||||
): Promise<{ ok: boolean; error?: string; settings?: KbDifySettings }> => {
|
||||
try {
|
||||
const res = await fetch('/api/kb/dify/settings', {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...getAuthHeaders(),
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return { ok: false, error: data?.error || '保存 Dify 设置失败' };
|
||||
}
|
||||
return { ok: true, settings: (await res.json()) as KbDifySettings };
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const getKbDifyHealth = async (): Promise<KbDifyHealth | null> => {
|
||||
return getJson<KbDifyHealth | null>('/api/kb/dify/health', null);
|
||||
};
|
||||
|
||||
export const runKbJob = async (
|
||||
jobId: number | string
|
||||
): Promise<{ ok: boolean; error?: string; job?: KbJob; run_result?: string }> => {
|
||||
try {
|
||||
const res = await fetch(`/api/kb/jobs/${jobId}/run`, {
|
||||
method: 'POST',
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return { ok: false, error: data?.error || '执行任务失败' };
|
||||
}
|
||||
const job = (await res.json()) as KbJob & { run_result?: string };
|
||||
return { ok: true, job, run_result: job.run_result };
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const createKbDocument = async (
|
||||
groupId: number,
|
||||
payload: { title: string; description?: string }
|
||||
): Promise<{ ok: boolean; error?: string; document?: KbDocumentItem }> => {
|
||||
try {
|
||||
const res = await fetch(`/api/kb/groups/${groupId}/files`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...getAuthHeaders(),
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return { ok: false, error: data?.error || '创建文档失败' };
|
||||
}
|
||||
return { ok: true, document: (await res.json()) as KbDocumentItem };
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const updateKbDocument = async (
|
||||
documentId: number,
|
||||
payload: { title: string; description?: string; status?: string }
|
||||
): Promise<{ ok: boolean; error?: string; document?: KbDocumentItem }> => {
|
||||
try {
|
||||
const res = await fetch(`/api/kb/documents/${documentId}`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...getAuthHeaders(),
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return { ok: false, error: data?.error || '更新文档失败' };
|
||||
}
|
||||
return { ok: true, document: (await res.json()) as KbDocumentItem };
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteKbDocument = async (
|
||||
documentId: number
|
||||
): Promise<{ ok: boolean; error?: string }> => {
|
||||
try {
|
||||
const res = await fetch(`/api/kb/documents/${documentId}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return { ok: false, error: data?.error || '删除文档失败' };
|
||||
}
|
||||
return { ok: true };
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const getKbDocumentVersions = async (
|
||||
documentId: number
|
||||
): Promise<KbDocumentVersionItem[]> => {
|
||||
return getJson<KbDocumentVersionItem[]>(`/api/kb/documents/${documentId}/versions`, []);
|
||||
};
|
||||
|
||||
export const getKbDocumentVersionSourceFile = async (
|
||||
versionId: number
|
||||
): Promise<{ ok: boolean; error?: string; blob?: Blob; filename?: string; contentType?: string }> => {
|
||||
try {
|
||||
const res = await fetch(`/api/kb/document-versions/${versionId}/source-file`, {
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return { ok: false, error: data?.error || '读取原始文件失败' };
|
||||
}
|
||||
const disposition = res.headers.get('content-disposition') || '';
|
||||
const filenameMatch = disposition.match(/filename\*=UTF-8''([^;]+)|filename="?([^"]+)"?/i);
|
||||
const filename = decodeURIComponent(filenameMatch?.[1] || filenameMatch?.[2] || '');
|
||||
return {
|
||||
ok: true,
|
||||
blob: await res.blob(),
|
||||
filename: filename || undefined,
|
||||
contentType: res.headers.get('content-type') || undefined,
|
||||
};
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const getKbDocumentSyncRecords = async (
|
||||
documentId: number
|
||||
): Promise<KbSyncRecordItem[]> => {
|
||||
return getJson<KbSyncRecordItem[]>(`/api/kb/documents/${documentId}/sync-records`, []);
|
||||
};
|
||||
|
||||
export const getKbDocumentMarkdown = async (
|
||||
documentId: number
|
||||
): Promise<{ ok: boolean; error?: string; data?: KbDocumentMarkdown }> => {
|
||||
try {
|
||||
const res = await fetch(`/api/kb/documents/${documentId}/markdown`, {
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return { ok: false, error: data?.error || '读取清洗后的 Markdown 失败' };
|
||||
}
|
||||
return { ok: true, data: (await res.json()) as KbDocumentMarkdown };
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const updateKbDocumentMarkdown = async (
|
||||
documentId: number,
|
||||
payload: { content: string }
|
||||
): Promise<{ ok: boolean; error?: string; data?: KbDocumentMarkdown }> => {
|
||||
try {
|
||||
const res = await fetch(`/api/kb/documents/${documentId}/markdown`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...getAuthHeaders(),
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return { ok: false, error: data?.error || '保存 Markdown 失败' };
|
||||
}
|
||||
return { ok: true, data: (await res.json()) as KbDocumentMarkdown };
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const uploadKbDocumentVersion = async (
|
||||
documentId: number,
|
||||
file: File
|
||||
): Promise<{ ok: boolean; error?: string; version?: KbDocumentVersionItem; status?: number }> => {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
const res = await fetch(`/api/kb/documents/${documentId}/upload`, {
|
||||
method: 'POST',
|
||||
headers: getAuthHeaders(),
|
||||
body: formData,
|
||||
});
|
||||
if (!res.ok) {
|
||||
if (res.status === 413) {
|
||||
return { ok: false, error: '文件过大,超过当前上传限制,请联系管理员放宽限制后重试', status: res.status };
|
||||
}
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return { ok: false, error: data?.error || '上传文档版本失败', status: res.status };
|
||||
}
|
||||
return { ok: true, version: (await res.json()) as KbDocumentVersionItem, status: res.status };
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const createKbPathUploadJob = async (
|
||||
groupId: number,
|
||||
payload: { total_files: number; selected_paths: string[] }
|
||||
): Promise<{ ok: boolean; error?: string; job?: KbJob; status?: number }> => {
|
||||
try {
|
||||
const res = await fetch(`/api/kb/groups/${groupId}/path-upload-jobs`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...getAuthHeaders(),
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
return { ok: false, error: data?.error || '创建路径上传任务失败', status: res.status };
|
||||
}
|
||||
return { ok: true, job: data as KbJob, status: res.status };
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const uploadKbPathJobFile = async (
|
||||
jobId: number | string,
|
||||
file: File,
|
||||
relativePath: string,
|
||||
): Promise<{ ok: boolean; error?: string; job?: KbJob }> => {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('relative_path', relativePath);
|
||||
|
||||
const res = await fetch(`/api/kb/path-upload-jobs/${jobId}/files`, {
|
||||
method: 'POST',
|
||||
headers: getAuthHeaders(),
|
||||
body: formData,
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
return { ok: false, error: data?.error || '上传路径文件失败' };
|
||||
}
|
||||
return { ok: true, job: data as KbJob };
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const finalizeKbPathUploadJob = async (
|
||||
jobId: number | string,
|
||||
): Promise<{ ok: boolean; error?: string; job?: KbJob }> => {
|
||||
try {
|
||||
const res = await fetch(`/api/kb/path-upload-jobs/${jobId}/finalize`, {
|
||||
method: 'POST',
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
return { ok: false, error: data?.error || '提交路径上传任务失败' };
|
||||
}
|
||||
return { ok: true, job: data as KbJob };
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const retryFailedKbPathUploadJob = async (
|
||||
jobId: number | string,
|
||||
payload?: { relative_paths?: string[] },
|
||||
): Promise<{ ok: boolean; error?: string; job?: KbJob; status?: number }> => {
|
||||
try {
|
||||
const res = await fetch(`/api/kb/path-upload-jobs/${jobId}/retry-failed`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...getAuthHeaders(),
|
||||
},
|
||||
body: JSON.stringify(payload || {}),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
return { ok: false, error: data?.error || '重试失败文件失败', status: res.status };
|
||||
}
|
||||
return { ok: true, job: data as KbJob, status: res.status };
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const syncKbDocumentToDify = async (
|
||||
documentId: number
|
||||
): Promise<{ ok: boolean; error?: string; job?: KbJob; run_result?: string }> => {
|
||||
try {
|
||||
const res = await fetch(`/api/kb/documents/${documentId}/sync`, {
|
||||
method: 'POST',
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return { ok: false, error: data?.error || data?.error_message || data?.run_result || '同步到 Dify 失败' };
|
||||
}
|
||||
const job = (await res.json()) as KbJob & { run_result?: string };
|
||||
return { ok: true, job, run_result: job.run_result };
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const updateKbGroup = async (
|
||||
groupId: number,
|
||||
payload: { name: string; description?: string }
|
||||
): Promise<{ ok: boolean; error?: string; group?: KbGroup }> => {
|
||||
try {
|
||||
const res = await fetch(`/api/kb/groups/${groupId}`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...getAuthHeaders(),
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return { ok: false, error: data?.error || '更新知识库分组失败' };
|
||||
}
|
||||
return { ok: true, group: (await res.json()) as KbGroup };
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteKbGroup = async (
|
||||
groupId: number
|
||||
): Promise<{ ok: boolean; error?: string }> => {
|
||||
try {
|
||||
const res = await fetch(`/api/kb/groups/${groupId}`, {
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return { ok: false, error: data?.error || '删除知识库分组失败' };
|
||||
}
|
||||
return { ok: true };
|
||||
} catch {
|
||||
return { ok: false, error: '知识库接口暂未就绪,请稍后再试' };
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,115 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue';
|
||||
import { getKbDifyHealth, type KbDifyHealth } from '../../api/kb';
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: [];
|
||||
error: [message: string];
|
||||
}>();
|
||||
|
||||
const loading = ref(false);
|
||||
const payload = ref<KbDifyHealth | null>(null);
|
||||
|
||||
const close = () => emit('close');
|
||||
|
||||
const loadHealth = async () => {
|
||||
loading.value = true;
|
||||
payload.value = await getKbDifyHealth();
|
||||
loading.value = false;
|
||||
if (!payload.value) {
|
||||
emit('error', '加载 Dify 健康状态失败');
|
||||
}
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
(open) => {
|
||||
if (open) {
|
||||
void loadHealth();
|
||||
}
|
||||
}
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="open"
|
||||
class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/35 px-4 py-8 backdrop-blur-sm"
|
||||
@click="close"
|
||||
>
|
||||
<div class="w-full max-w-4xl rounded-3xl border border-slate-200 bg-white p-6 shadow-xl dark:border-slate-700 dark:bg-slate-900" @click.stop>
|
||||
<div class="flex items-center justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="text-xl font-bold text-slate-900 dark:text-slate-100">Dify 健康检查</h3>
|
||||
<p class="mt-1 text-sm text-slate-500 dark:text-slate-400">
|
||||
查看知识库模块当前的 Dify 连接情况和本地同步概况。
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<button class="rounded-2xl border border-slate-200 px-3 py-2 text-sm text-slate-600 hover:bg-slate-50 dark:border-slate-700 dark:text-slate-300 dark:hover:bg-slate-800" @click="loadHealth">
|
||||
刷新
|
||||
</button>
|
||||
<button class="rounded-2xl border border-slate-200 px-3 py-2 text-sm text-slate-600 hover:bg-slate-50 dark:border-slate-700 dark:text-slate-300 dark:hover:bg-slate-800" @click="close">
|
||||
关闭
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="py-16 text-center text-sm text-slate-400">正在检测...</div>
|
||||
<div v-else-if="payload" class="mt-6 grid gap-4 md:grid-cols-2 xl:grid-cols-3">
|
||||
<div class="rounded-2xl border border-slate-200 px-4 py-4 dark:border-slate-700">
|
||||
<div class="text-xs font-semibold uppercase tracking-[0.18em] text-slate-400">Dify API</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-slate-900 dark:text-slate-100">
|
||||
{{ payload.api.reachable ? '可访问' : '不可访问' }}
|
||||
</div>
|
||||
<div class="mt-2 break-all text-xs text-slate-500 dark:text-slate-400">
|
||||
{{ payload.dify_base_url || '未配置' }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="rounded-2xl border border-slate-200 px-4 py-4 dark:border-slate-700">
|
||||
<div class="text-xs font-semibold uppercase tracking-[0.18em] text-slate-400">Dataset 数量</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-slate-900 dark:text-slate-100">
|
||||
{{ payload.api.dataset_count ?? '--' }}
|
||||
</div>
|
||||
<div class="mt-2 text-xs text-slate-500 dark:text-slate-400">
|
||||
配置完成:{{ payload.dify_api_configured ? '是' : '否' }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="rounded-2xl border border-slate-200 px-4 py-4 dark:border-slate-700">
|
||||
<div class="text-xs font-semibold uppercase tracking-[0.18em] text-slate-400">已绑定分组</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-slate-900 dark:text-slate-100">
|
||||
{{ payload.local_sync_health.dataset_bound_groups }}
|
||||
</div>
|
||||
<div class="mt-2 text-xs text-slate-500 dark:text-slate-400">
|
||||
本地同步记录:{{ payload.local_sync_health.sync_records }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="rounded-2xl border border-slate-200 px-4 py-4 dark:border-slate-700">
|
||||
<div class="text-xs font-semibold uppercase tracking-[0.18em] text-slate-400">同步中版本</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-slate-900 dark:text-slate-100">
|
||||
{{ payload.local_sync_health.syncing_versions }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="rounded-2xl border border-slate-200 px-4 py-4 dark:border-slate-700">
|
||||
<div class="text-xs font-semibold uppercase tracking-[0.18em] text-slate-400">已同步版本</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-slate-900 dark:text-slate-100">
|
||||
{{ payload.local_sync_health.synced_versions }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="rounded-2xl border border-slate-200 px-4 py-4 dark:border-slate-700">
|
||||
<div class="text-xs font-semibold uppercase tracking-[0.18em] text-slate-400">待同步任务</div>
|
||||
<div class="mt-3 text-2xl font-semibold text-slate-900 dark:text-slate-100">
|
||||
{{ payload.local_sync_health.pending_sync_jobs }}
|
||||
</div>
|
||||
<div class="mt-2 text-xs text-rose-500" v-if="payload.api.error">
|
||||
{{ payload.api.error }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,134 @@
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref, watch } from 'vue';
|
||||
import { getKbDifySettings, updateKbDifySettings } from '../../api/kb';
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: [];
|
||||
saved: [message: string];
|
||||
error: [message: string];
|
||||
}>();
|
||||
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const form = reactive({
|
||||
DIFY_API_BASE: '',
|
||||
DIFY_API_KEY: '',
|
||||
KB_DIFY_PERMISSION: 'only_me',
|
||||
KB_DIFY_INDEXING_TECHNIQUE: 'high_quality',
|
||||
KB_DIFY_SEARCH_METHOD: 'semantic_search',
|
||||
KB_DIFY_DOC_FORM: 'text_model',
|
||||
});
|
||||
|
||||
const close = () => emit('close');
|
||||
|
||||
const loadSettings = async () => {
|
||||
loading.value = true;
|
||||
const settings = await getKbDifySettings();
|
||||
loading.value = false;
|
||||
if (!settings) {
|
||||
emit('error', '加载 Dify 设置失败');
|
||||
return;
|
||||
}
|
||||
Object.assign(form, settings);
|
||||
};
|
||||
|
||||
const save = async () => {
|
||||
saving.value = true;
|
||||
const result = await updateKbDifySettings(form);
|
||||
saving.value = false;
|
||||
if (!result.ok) {
|
||||
emit('error', result.error || '保存 Dify 设置失败');
|
||||
return;
|
||||
}
|
||||
emit('saved', 'Dify 设置已保存');
|
||||
emit('close');
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
(open) => {
|
||||
if (open) {
|
||||
void loadSettings();
|
||||
}
|
||||
}
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="open"
|
||||
class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/35 px-4 py-8 backdrop-blur-sm"
|
||||
@click="close"
|
||||
>
|
||||
<div class="w-full max-w-3xl rounded-3xl border border-slate-200 bg-white p-6 shadow-xl dark:border-slate-700 dark:bg-slate-900" @click.stop>
|
||||
<div class="flex items-center justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="text-xl font-bold text-slate-900 dark:text-slate-100">Dify 设置</h3>
|
||||
<p class="mt-1 text-sm text-slate-500 dark:text-slate-400">
|
||||
管理知识库模块使用的 Dify 连接和默认同步参数。
|
||||
</p>
|
||||
</div>
|
||||
<button class="rounded-2xl border border-slate-200 px-3 py-2 text-sm text-slate-600 hover:bg-slate-50 dark:border-slate-700 dark:text-slate-300 dark:hover:bg-slate-800" @click="close">
|
||||
关闭
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="py-16 text-center text-sm text-slate-400">正在加载设置...</div>
|
||||
<div v-else class="mt-6 grid gap-4 md:grid-cols-2">
|
||||
<label class="space-y-2 md:col-span-2">
|
||||
<span class="text-sm font-medium text-slate-600 dark:text-slate-300">Dify Base URL</span>
|
||||
<input v-model="form.DIFY_API_BASE" class="input-field" placeholder="https://api.dify.ai/v1" />
|
||||
</label>
|
||||
<label class="space-y-2 md:col-span-2">
|
||||
<span class="text-sm font-medium text-slate-600 dark:text-slate-300">Dify API Key</span>
|
||||
<input v-model="form.DIFY_API_KEY" class="input-field" placeholder="app-..." />
|
||||
</label>
|
||||
<label class="space-y-2">
|
||||
<span class="text-sm font-medium text-slate-600 dark:text-slate-300">Permission</span>
|
||||
<select v-model="form.KB_DIFY_PERMISSION" class="input-field">
|
||||
<option value="only_me">only_me</option>
|
||||
<option value="all_team_members">all_team_members</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-2">
|
||||
<span class="text-sm font-medium text-slate-600 dark:text-slate-300">Indexing Technique</span>
|
||||
<select v-model="form.KB_DIFY_INDEXING_TECHNIQUE" class="input-field">
|
||||
<option value="high_quality">high_quality</option>
|
||||
<option value="economy">economy</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-2">
|
||||
<span class="text-sm font-medium text-slate-600 dark:text-slate-300">Search Method</span>
|
||||
<select v-model="form.KB_DIFY_SEARCH_METHOD" class="input-field">
|
||||
<option value="semantic_search">semantic_search</option>
|
||||
<option value="hybrid_search">hybrid_search</option>
|
||||
<option value="full_text_search">full_text_search</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-2">
|
||||
<span class="text-sm font-medium text-slate-600 dark:text-slate-300">Doc Form</span>
|
||||
<select v-model="form.KB_DIFY_DOC_FORM" class="input-field">
|
||||
<option value="text_model">text_model</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex justify-end gap-3">
|
||||
<button class="rounded-2xl border border-slate-200 px-4 py-2.5 text-sm font-medium text-slate-700 hover:bg-slate-50 dark:border-slate-700 dark:text-slate-200 dark:hover:bg-slate-800" @click="close">
|
||||
取消
|
||||
</button>
|
||||
<button
|
||||
class="rounded-2xl bg-brand-600 px-4 py-2.5 text-sm font-medium text-white hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="saving"
|
||||
@click="save"
|
||||
>
|
||||
{{ saving ? '保存中...' : '保存设置' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+13
-6
@@ -1,4 +1,4 @@
|
||||
import { createApp } from 'vue'
|
||||
import { createApp } from 'vue'
|
||||
import './style.css'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
@@ -52,10 +52,17 @@ createApp(App)
|
||||
.use(i18n)
|
||||
.mount('#app')
|
||||
|
||||
if (import.meta.env.PROD && 'serviceWorker' in navigator) {
|
||||
window.addEventListener('load', () => {
|
||||
navigator.serviceWorker.register('/sw.js').catch((err) => {
|
||||
console.error('Service worker registration failed:', err);
|
||||
});
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', async () => {
|
||||
try {
|
||||
const registrations = await navigator.serviceWorker.getRegistrations();
|
||||
await Promise.all(registrations.map((registration) => registration.unregister()));
|
||||
if ('caches' in window) {
|
||||
const cacheKeys = await window.caches.keys();
|
||||
await Promise.all(cacheKeys.map((key) => window.caches.delete(key)));
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Service worker cleanup failed:', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import ChatView from '../views/ChatView.vue';
|
||||
import AdminView from '../views/AdminView.vue';
|
||||
import ProfileView from '../views/ProfileView.vue';
|
||||
import ResetPasswordView from '../views/ResetPasswordView.vue';
|
||||
import KbWorkspaceView from '../views/KbWorkspaceView.vue';
|
||||
import KbAdminView from '../views/KbAdminView.vue';
|
||||
import { config } from '../config';
|
||||
import { getStoredAuthUser } from '../utils/auth';
|
||||
|
||||
@@ -45,6 +47,18 @@ const routes = [
|
||||
name: 'Admin',
|
||||
component: AdminView
|
||||
},
|
||||
{
|
||||
path: '/kb/workspace',
|
||||
name: 'KbWorkspace',
|
||||
component: KbWorkspaceView,
|
||||
meta: { title: '知识库工作台' }
|
||||
},
|
||||
{
|
||||
path: '/kb/admin',
|
||||
name: 'KbAdmin',
|
||||
component: KbAdminView,
|
||||
meta: { title: '知识库管理台' }
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
|
||||
@@ -2544,6 +2544,13 @@ const handlePermissionImport = async (event: Event) => {
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
<button
|
||||
@click="router.push('/kb/admin')"
|
||||
class="hidden md:inline-flex items-center gap-2 rounded-xl border border-slate-200 px-4 py-2 text-sm font-medium text-slate-600 transition-colors hover:bg-slate-50 hover:text-slate-900 dark:border-slate-700 dark:text-slate-300 dark:hover:bg-slate-800 dark:hover:text-slate-100"
|
||||
>
|
||||
<Settings2 class="w-4 h-4" />
|
||||
<span>知识库管理</span>
|
||||
</button>
|
||||
<ThemeToggleButton />
|
||||
<!-- Language Selector -->
|
||||
<div class="flex items-center gap-2">
|
||||
|
||||
@@ -628,26 +628,10 @@ const getLeaveIntentNormalized = (content: string) => (content || '').replace(/\
|
||||
|
||||
const isStrongLeaveIntent = (content: string) => {
|
||||
const normalized = getLeaveIntentNormalized(content);
|
||||
return /(我要请假|申请请假|发起请假|请假申请|我要休假|申请休假|我要请个假|想请假|我要走请假流程)/.test(normalized);
|
||||
};
|
||||
|
||||
const startLocalLeaveFlow = (content: string) => {
|
||||
const formId = newLocalMessageId('leave-form');
|
||||
const payload: LeaveFormPayload = {
|
||||
formId,
|
||||
form: createLeaveFormData(),
|
||||
submitting: false,
|
||||
confirmationGenerated: false,
|
||||
};
|
||||
messages.value.push({ role: 'user', content, type: 'text' });
|
||||
messages.value.push({
|
||||
role: 'assistant',
|
||||
type: 'leave-form',
|
||||
content: '已为你生成请假申请表,请直接在下方填写并提交。或登录OA系统直接申请',
|
||||
payload,
|
||||
local_id: formId,
|
||||
local_only: true,
|
||||
});
|
||||
// 弱意图(咨询流程/步骤)应走正常问答,不触发表单分流。
|
||||
const weakConsultationIntent = /(请假流程|请假怎么走|请假步骤|请假如何申请|请假如何走流程|请假怎么办|请假需要什么|请假规定)/;
|
||||
if (weakConsultationIntent.test(normalized)) return false;
|
||||
return /(我要请假|申请请假|发起请假|请假申请|我要休假|申请休假|我要请个假|想请假|帮我请假|代我请假|提交请假)/.test(normalized);
|
||||
};
|
||||
|
||||
const getLeaveFormPayload = (msg: any): LeaveFormPayload | null => (
|
||||
|
||||
@@ -0,0 +1,360 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { ArrowLeft, FolderPlus, Pencil, Play, RefreshCw, Settings, Trash2, Wrench, X } from 'lucide-vue-next';
|
||||
import DifyHealthDialog from '../components/kb/DifyHealthDialog.vue';
|
||||
import DifySettingsDialog from '../components/kb/DifySettingsDialog.vue';
|
||||
import {
|
||||
createKbGroup,
|
||||
deleteKbGroup,
|
||||
getKbGroupsSafe,
|
||||
getKbJobsSafe,
|
||||
runKbJob,
|
||||
updateKbGroup,
|
||||
type KbGroup,
|
||||
type KbJob,
|
||||
} from '../api/kb';
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const groups = ref<KbGroup[]>([]);
|
||||
const jobs = ref<KbJob[]>([]);
|
||||
const isSubmitting = ref(false);
|
||||
const isRefreshing = ref(false);
|
||||
const editingGroupId = ref<number | null>(null);
|
||||
const form = ref({
|
||||
name: '',
|
||||
description: '',
|
||||
});
|
||||
const feedback = ref('');
|
||||
const feedbackType = ref<'success' | 'error' | ''>('');
|
||||
const runningJobId = ref<number | string | null>(null);
|
||||
const settingsDialogOpen = ref(false);
|
||||
const healthDialogOpen = ref(false);
|
||||
|
||||
const formTitle = computed(() => editingGroupId.value ? '编辑知识库分组' : '新建知识库分组');
|
||||
const formDescription = computed(() => editingGroupId.value
|
||||
? '修改知识库分组名称和描述,保存后会立即刷新列表。'
|
||||
: '用于验证主平台里的知识库管理入口和基础接口壳。');
|
||||
const submitText = computed(() => {
|
||||
if (isSubmitting.value) return editingGroupId.value ? '保存中...' : '提交中...';
|
||||
return editingGroupId.value ? '保存修改' : '创建分组';
|
||||
});
|
||||
|
||||
const loadData = async () => {
|
||||
isRefreshing.value = true;
|
||||
const [groupsResult, jobsResult] = await Promise.all([getKbGroupsSafe(), getKbJobsSafe()]);
|
||||
if (groupsResult.ok) {
|
||||
groups.value = groupsResult.data;
|
||||
} else {
|
||||
feedback.value = groupsResult.error || '加载知识库分组失败';
|
||||
feedbackType.value = 'error';
|
||||
}
|
||||
if (jobsResult.ok) {
|
||||
jobs.value = jobsResult.data;
|
||||
} else {
|
||||
feedback.value = jobsResult.error || '加载任务列表失败';
|
||||
feedbackType.value = 'error';
|
||||
}
|
||||
isRefreshing.value = false;
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
editingGroupId.value = null;
|
||||
form.value = { name: '', description: '' };
|
||||
};
|
||||
|
||||
const handleCreateGroup = async () => {
|
||||
if (!form.value.name.trim()) {
|
||||
feedback.value = '请输入知识库分组名称';
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
isSubmitting.value = true;
|
||||
const payload = {
|
||||
name: form.value.name.trim(),
|
||||
description: form.value.description.trim(),
|
||||
};
|
||||
const result = editingGroupId.value
|
||||
? await updateKbGroup(editingGroupId.value, payload)
|
||||
: await createKbGroup(payload);
|
||||
isSubmitting.value = false;
|
||||
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '创建失败';
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
|
||||
feedback.value = editingGroupId.value ? '知识库分组已更新' : '知识库分组创建成功';
|
||||
feedbackType.value = 'success';
|
||||
resetForm();
|
||||
await loadData();
|
||||
};
|
||||
|
||||
const handleEditGroup = (group: KbGroup) => {
|
||||
editingGroupId.value = group.id;
|
||||
form.value = {
|
||||
name: group.name,
|
||||
description: group.description || '',
|
||||
};
|
||||
feedback.value = '';
|
||||
feedbackType.value = '';
|
||||
};
|
||||
|
||||
const handleDeleteGroup = async (group: KbGroup) => {
|
||||
const confirmed = window.confirm(`确认删除知识库分组「${group.name}」吗?`);
|
||||
if (!confirmed) return;
|
||||
|
||||
const result = await deleteKbGroup(group.id);
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '删除失败';
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
|
||||
if (editingGroupId.value === group.id) {
|
||||
resetForm();
|
||||
}
|
||||
feedback.value = '知识库分组已删除';
|
||||
feedbackType.value = 'success';
|
||||
await loadData();
|
||||
};
|
||||
|
||||
const handleRunJob = async (job: KbJob) => {
|
||||
runningJobId.value = job.id;
|
||||
const result = await runKbJob(job.id);
|
||||
runningJobId.value = null;
|
||||
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '任务执行失败';
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
|
||||
feedback.value = result.run_result || '任务已执行';
|
||||
feedbackType.value = 'success';
|
||||
await loadData();
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
await loadData();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="min-h-screen bg-gray-50 dark:bg-slate-950 text-slate-800 dark:text-slate-200">
|
||||
<div class="mx-auto max-w-7xl px-4 py-6 md:px-6 lg:px-8">
|
||||
<div class="mb-6 flex flex-col gap-4 rounded-3xl border border-slate-200 bg-white p-6 shadow-sm md:flex-row md:items-center md:justify-between dark:border-slate-700 dark:bg-slate-900">
|
||||
<div class="flex items-start gap-4">
|
||||
<button
|
||||
@click="router.push('/admin')"
|
||||
class="rounded-2xl border border-slate-200 p-3 text-slate-500 transition-colors hover:bg-slate-50 hover:text-slate-900 dark:border-slate-700 dark:text-slate-300 dark:hover:bg-slate-800 dark:hover:text-white"
|
||||
title="返回管理后台"
|
||||
>
|
||||
<ArrowLeft class="h-5 w-5" />
|
||||
</button>
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="flex h-12 w-12 items-center justify-center rounded-2xl bg-brand-50 text-brand-600 dark:bg-brand-500/10">
|
||||
<Settings class="h-6 w-6" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-slate-900 dark:text-slate-100">知识库管理台</h1>
|
||||
<p class="mt-1 text-sm text-slate-500 dark:text-slate-400">
|
||||
第一阶段先承接分组、任务和 Dify 管理入口,后续再接入清洗链路。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<button
|
||||
@click="loadData"
|
||||
class="inline-flex items-center gap-2 rounded-2xl border border-slate-200 px-4 py-2.5 text-sm font-medium text-slate-700 transition-colors hover:bg-slate-50 dark:border-slate-700 dark:text-slate-200 dark:hover:bg-slate-800"
|
||||
>
|
||||
<RefreshCw class="h-4 w-4" />
|
||||
刷新数据
|
||||
</button>
|
||||
<button
|
||||
@click="settingsDialogOpen = true"
|
||||
class="inline-flex items-center gap-2 rounded-2xl border border-slate-200 px-4 py-2.5 text-sm font-medium text-slate-700 transition-colors hover:bg-slate-50 dark:border-slate-700 dark:text-slate-200 dark:hover:bg-slate-800"
|
||||
>
|
||||
<Settings class="h-4 w-4" />
|
||||
Dify 设置
|
||||
</button>
|
||||
<button
|
||||
@click="healthDialogOpen = true"
|
||||
class="inline-flex items-center gap-2 rounded-2xl border border-slate-200 px-4 py-2.5 text-sm font-medium text-slate-700 transition-colors hover:bg-slate-50 dark:border-slate-700 dark:text-slate-200 dark:hover:bg-slate-800"
|
||||
>
|
||||
<RefreshCw class="h-4 w-4" />
|
||||
健康检查
|
||||
</button>
|
||||
<button
|
||||
@click="router.push('/kb/workspace')"
|
||||
class="inline-flex items-center gap-2 rounded-2xl bg-brand-600 px-4 py-2.5 text-sm font-medium text-white transition-colors hover:bg-brand-700"
|
||||
>
|
||||
<Wrench class="h-4 w-4" />
|
||||
前往工作台
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 gap-6 xl:grid-cols-[420px_minmax(0,1fr)]">
|
||||
<section class="rounded-3xl border border-slate-200 bg-white p-6 shadow-sm dark:border-slate-700 dark:bg-slate-900">
|
||||
<div class="mb-5 flex items-center gap-3">
|
||||
<div class="flex h-10 w-10 items-center justify-center rounded-2xl bg-brand-50 text-brand-600 dark:bg-brand-500/10">
|
||||
<FolderPlus class="h-5 w-5" />
|
||||
</div>
|
||||
<div>
|
||||
<h2 class="text-lg font-semibold text-slate-900 dark:text-slate-100">{{ formTitle }}</h2>
|
||||
<p class="text-sm text-slate-500 dark:text-slate-400">{{ formDescription }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<label class="mb-2 block text-sm font-medium text-slate-600 dark:text-slate-300">分组名称</label>
|
||||
<input v-model="form.name" class="input-field" placeholder="例如:财务制度库" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-2 block text-sm font-medium text-slate-600 dark:text-slate-300">分组描述</label>
|
||||
<textarea
|
||||
v-model="form.description"
|
||||
rows="4"
|
||||
class="input-field"
|
||||
placeholder="描述该知识库分组的业务范围或清洗目标"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
@click="handleCreateGroup"
|
||||
:disabled="isSubmitting"
|
||||
class="inline-flex w-full items-center justify-center gap-2 rounded-2xl bg-brand-600 px-4 py-3 text-sm font-medium text-white transition-colors hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
<FolderPlus class="h-4 w-4" />
|
||||
{{ submitText }}
|
||||
</button>
|
||||
<button
|
||||
v-if="editingGroupId"
|
||||
@click="resetForm"
|
||||
type="button"
|
||||
class="inline-flex w-full items-center justify-center gap-2 rounded-2xl border border-slate-200 px-4 py-3 text-sm font-medium text-slate-700 transition-colors hover:bg-slate-50 dark:border-slate-700 dark:text-slate-200 dark:hover:bg-slate-800"
|
||||
>
|
||||
<X class="h-4 w-4" />
|
||||
取消编辑
|
||||
</button>
|
||||
<p
|
||||
v-if="feedback"
|
||||
class="text-sm"
|
||||
:class="feedbackType === 'error' ? 'text-rose-500' : 'text-emerald-600 dark:text-emerald-400'"
|
||||
>
|
||||
{{ feedback }}
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="space-y-6">
|
||||
<section class="rounded-3xl border border-slate-200 bg-white p-6 shadow-sm dark:border-slate-700 dark:bg-slate-900">
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<h2 class="text-lg font-semibold text-slate-900 dark:text-slate-100">知识库分组概览</h2>
|
||||
<span class="text-xs text-slate-400">{{ isRefreshing ? '加载中...' : '`/api/kb/groups`' }}</span>
|
||||
</div>
|
||||
<div v-if="groups.length === 0" class="rounded-2xl border border-dashed border-slate-200 px-4 py-10 text-center text-sm text-slate-400 dark:border-slate-700">
|
||||
当前暂无分组,或知识库接口尚未联调完成。
|
||||
</div>
|
||||
<div v-else class="grid grid-cols-1 gap-3 md:grid-cols-2">
|
||||
<div
|
||||
v-for="group in groups"
|
||||
:key="group.id"
|
||||
class="rounded-2xl border border-slate-200 px-4 py-4 dark:border-slate-700"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<div class="font-semibold text-slate-900 dark:text-slate-100">{{ group.name }}</div>
|
||||
<div class="mt-1 text-sm text-slate-500 dark:text-slate-400">{{ group.description || '暂无描述' }}</div>
|
||||
</div>
|
||||
<div class="rounded-full bg-slate-100 px-2.5 py-1 text-xs font-medium text-slate-600 dark:bg-slate-800 dark:text-slate-300">
|
||||
{{ group.document_count ?? 0 }} 文档
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4 flex flex-wrap items-center justify-between gap-3">
|
||||
<div class="text-xs text-slate-400">
|
||||
更新时间:{{ group.updated_at || '--' }}
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
@click="handleEditGroup(group)"
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-slate-200 px-3 py-2 text-xs font-medium text-slate-600 transition-colors hover:bg-slate-50 dark:border-slate-700 dark:text-slate-300 dark:hover:bg-slate-800"
|
||||
>
|
||||
<Pencil class="h-3.5 w-3.5" />
|
||||
编辑
|
||||
</button>
|
||||
<button
|
||||
@click="handleDeleteGroup(group)"
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-rose-200 px-3 py-2 text-xs font-medium text-rose-600 transition-colors hover:bg-rose-50 dark:border-rose-500/30 dark:text-rose-400 dark:hover:bg-rose-500/10"
|
||||
>
|
||||
<Trash2 class="h-3.5 w-3.5" />
|
||||
删除
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="rounded-3xl border border-slate-200 bg-white p-6 shadow-sm dark:border-slate-700 dark:bg-slate-900">
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<h2 class="text-lg font-semibold text-slate-900 dark:text-slate-100">任务队列占位</h2>
|
||||
<span class="text-xs text-slate-400">`/api/kb/jobs`</span>
|
||||
</div>
|
||||
<div v-if="jobs.length === 0" class="rounded-2xl border border-dashed border-slate-200 px-4 py-10 text-center text-sm text-slate-400 dark:border-slate-700">
|
||||
暂无任务。第二阶段会在这里接入清洗、同步和重试任务。
|
||||
</div>
|
||||
<div v-else class="space-y-3">
|
||||
<div
|
||||
v-for="job in jobs"
|
||||
:key="job.id"
|
||||
class="rounded-2xl border border-slate-200 px-4 py-4 dark:border-slate-700"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<div class="font-semibold text-slate-900 dark:text-slate-100">{{ job.job_type }}</div>
|
||||
<div class="mt-1 text-sm text-slate-500 dark:text-slate-400">{{ job.created_at || '--' }}</div>
|
||||
<div class="mt-2 text-sm text-slate-500 dark:text-slate-400">
|
||||
{{ job.message || '暂无任务说明' }}
|
||||
</div>
|
||||
<div class="mt-2 text-xs text-slate-400">
|
||||
文档:{{ job.document_id ?? '--' }} · 版本:{{ job.document_version_id ?? '--' }} · 进度:{{ job.progress ?? 0 }}%
|
||||
</div>
|
||||
</div>
|
||||
<span class="rounded-full bg-slate-100 px-2.5 py-1 text-xs font-medium text-slate-600 dark:bg-slate-800 dark:text-slate-300">
|
||||
{{ job.status }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-3 flex justify-end" v-if="['clean', 'sync_dify'].includes(job.job_type) && job.status !== 'success'">
|
||||
<button
|
||||
@click="handleRunJob(job)"
|
||||
:disabled="runningJobId === job.id"
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-brand-200 px-3 py-2 text-xs font-medium text-brand-700 transition-colors hover:bg-brand-50 disabled:cursor-not-allowed disabled:opacity-60 dark:border-brand-500/30 dark:text-brand-300 dark:hover:bg-brand-500/10"
|
||||
>
|
||||
<Play class="h-3.5 w-3.5" />
|
||||
{{ runningJobId === job.id ? '执行中...' : '执行任务' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<DifySettingsDialog
|
||||
:open="settingsDialogOpen"
|
||||
@close="settingsDialogOpen = false"
|
||||
@saved="(message) => { feedback = message; feedbackType = 'success'; void loadData(); }"
|
||||
@error="(message) => { feedback = message; feedbackType = 'error'; }"
|
||||
/>
|
||||
<DifyHealthDialog
|
||||
:open="healthDialogOpen"
|
||||
@close="healthDialogOpen = false"
|
||||
@error="(message) => { feedback = message; feedbackType = 'error'; }"
|
||||
/>
|
||||
</template>
|
||||
File diff suppressed because it is too large.
Load diff
@@ -33,6 +33,7 @@ import {
|
||||
Edit,
|
||||
ExternalLink,
|
||||
Bot,
|
||||
FileText,
|
||||
Lock,
|
||||
User,
|
||||
Mail,
|
||||
@@ -48,6 +49,8 @@ import {
|
||||
ChevronUp
|
||||
} from 'lucide-vue-next';
|
||||
|
||||
import KbWorkspaceView from './KbWorkspaceView.vue';
|
||||
|
||||
const { t, locale } = useI18n();
|
||||
const { showMessageDialog } = useGlobalMessageDialog();
|
||||
const router = useRouter();
|
||||
@@ -755,7 +758,7 @@ const handleRegister = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const activeSidebarItem = ref<'profile' | 'applications' | 'feedback' | 'updates'>('applications');
|
||||
const activeSidebarItem = ref<'profile' | 'applications' | 'feedback' | 'updates' | 'knowledge_base'>('applications');
|
||||
const isProfileLoading = ref(false);
|
||||
const isProfileSaving = ref(false);
|
||||
const isProfileEditing = ref(false);
|
||||
@@ -971,6 +974,10 @@ const navigateToApplications = () => openWorkspaceSection('favorites', 'applicat
|
||||
|
||||
const navigateToUpdates = () => openWorkspaceSection('announcements', 'updates');
|
||||
|
||||
const navigateToKnowledgeBase = () => {
|
||||
activeSidebarItem.value = 'knowledge_base';
|
||||
};
|
||||
|
||||
const navigateToGeneralChat = () => {
|
||||
router.push(`/chat/${DEFAULT_POST_LOGIN_AGENT_ID}`);
|
||||
};
|
||||
@@ -1378,6 +1385,14 @@ onMounted(async () => {
|
||||
<LayoutGrid class="h-4 w-4" />
|
||||
<span>应用管理</span>
|
||||
</button>
|
||||
<button
|
||||
@click="navigateToKnowledgeBase"
|
||||
class="flex w-full items-center gap-3 rounded-2xl px-4 py-3 text-left text-[15px] font-medium transition-all"
|
||||
:class="activeSidebarItem === 'knowledge_base' ? 'bg-brand-50 text-brand-700 shadow-sm' : 'text-slate-600 hover:bg-slate-50 hover:text-slate-900'"
|
||||
>
|
||||
<FileText class="h-4 w-4" />
|
||||
<span>知识库管理</span>
|
||||
</button>
|
||||
<button
|
||||
@click="openGeneralFeedback"
|
||||
class="flex w-full items-center gap-3 rounded-2xl px-4 py-3 text-left text-[15px] font-medium transition-all"
|
||||
@@ -1593,6 +1608,10 @@ onMounted(async () => {
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else-if="activeSidebarItem === 'knowledge_base'">
|
||||
<KbWorkspaceView :embedded="true" />
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div v-if="wecomEntryHint" class="rounded-2xl border border-blue-200 bg-blue-50 px-4 py-3 text-sm text-blue-700">
|
||||
{{ wecomEntryHint }}
|
||||
|
||||
Reference in new issue
Block a user