fix(conflicts): Merge branch 'refator' into dev

This commit is contained in:
sophie committed 2026-06-01 19:37:59 +08:00
commit 7f126cfd52
24 files changed
+2314 -4223

No files matched your search

+77 -127
View File
@@ -1,6 +1,4 @@
<script setup lang="ts">
<script setup lang="ts">
/**
* ChatView.vue
* 文件用途:单个 Agent 的对话界面
@@ -29,6 +27,23 @@ import { copyTextToClipboard } from '../utils/clipboard';
import { setLastChatAgentId } from '../utils/lastChatAgent';
import { openAgentChatTab, registerOpenAgentId } from '../utils/agentTabs';
import ChatShell from '../layouts/ChatShell.vue';
import { BusinessError } from '../api/client';
import {
listChatSessions,
deleteAllChatSessions,
deleteChatSession,
listChatMessages,
saveLocalChatMessage,
resolveChatSourceFile,
listOaEmployees,
} from '../api/chat';
import {
getUserProfile,
getLeaveBalance,
submitLeaveWorkflow,
getUserAgent,
listUserAgents,
} from '../api/user';
const { t, locale } = useI18n();
const { appliedTheme, toggleLightDark } = useTheme();
@@ -556,18 +571,11 @@ const resolveSourceLink = async (file: SourceFileLink): Promise<{ name: string;
throw new Error('当前源文件暂未返回可预览链接');
}
const params = new URLSearchParams({
agent_id: String(agentId),
const data = await resolveChatSourceFile({
agent_id: agentId,
dataset_id: file.datasetId,
remote_document_id: file.remoteDocumentId,
});
const response = await fetch(`/api/chat/source-file?${params.toString()}`, {
headers: getAuthHeaders(),
});
const data = await response.json().catch(() => ({}));
if (!response.ok) {
throw new Error(data?.error || `HTTP ${response.status}`);
}
const resolvedUrl = normalizeUrl(data?.source_download_url || '');
if (!resolvedUrl) {
@@ -858,18 +866,17 @@ const fetchLeaveAgents = async (isLoadMore = false) => {
leaveAgentLoading.value = true;
try {
const res = await fetch(`/api/chat/oa/employees?keyword=${encodeURIComponent(leaveAgentKeyword.value)}&page=${leaveAgentPage.value}&page_size=20&agent_id=${agentId}`, {
headers: getAuthHeaders()
const data = await listOaEmployees(agentId, {
keyword: leaveAgentKeyword.value,
page: leaveAgentPage.value,
page_size: 20,
});
if (res.ok) {
const data = await res.json();
if (isLoadMore) {
leaveAgentOptions.value.push(...data.items);
} else {
leaveAgentOptions.value = data.items;
}
leaveAgentHasMore.value = leaveAgentOptions.value.length < data.total;
if (isLoadMore) {
leaveAgentOptions.value.push(...data.items);
} else {
leaveAgentOptions.value = data.items;
}
leaveAgentHasMore.value = leaveAgentOptions.value.length < data.total;
} catch (e) {
console.error('Failed to load OA employees', e);
} finally {
@@ -891,14 +898,13 @@ const loadAllAgents = async () => {
if (!leaveAgentHasMore.value || leaveAgentLoading.value) return;
leaveAgentLoading.value = true;
try {
const res = await fetch(`/api/chat/oa/employees?keyword=${encodeURIComponent(leaveAgentKeyword.value)}&page=1&page_size=100000&agent_id=${agentId}`, {
headers: getAuthHeaders()
const data = await listOaEmployees(agentId, {
keyword: leaveAgentKeyword.value,
page: 1,
page_size: 100000,
});
if (res.ok) {
const data = await res.json();
leaveAgentOptions.value = data.items;
leaveAgentHasMore.value = false;
}
leaveAgentOptions.value = data.items;
leaveAgentHasMore.value = false;
} catch (e) {
console.error('Failed to load all OA employees', e);
} finally {
@@ -1187,29 +1193,19 @@ const isStrongLeaveIntent = (content: string) => {
const saveLocalMessageToBackend = async (msg: any, userQuery: string = '') => {
try {
const res = await fetch('/api/chat/messages/local', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...getAuthHeaders()
},
body: JSON.stringify({
conversation_id: conversationId.value,
type: msg.type,
content: msg.content,
payload: msg.payload,
query: userQuery,
agent_id: agentId
})
const data = await saveLocalChatMessage({
conversation_id: conversationId.value,
type: msg.type,
content: msg.content,
payload: msg.payload,
query: userQuery,
agent_id: agentId,
});
if (res.ok) {
const data = await res.json();
if (!conversationId.value && data.conversation_id) {
conversationId.value = data.conversation_id;
}
if (data.chat_log_id) {
msg.chat_log_id = data.chat_log_id;
}
if (!conversationId.value && data.conversation_id) {
conversationId.value = data.conversation_id;
}
if (data.chat_log_id) {
msg.chat_log_id = data.chat_log_id;
}
} catch (e) {
console.error('Failed to save local message', e);
@@ -1234,11 +1230,7 @@ const checkLeaveBalance = async (leaveTypeCode: string): Promise<{
remaining_hours: number | null;
} | null> => {
try {
const res = await fetch(`/api/user/leave-balance?leave_type=${encodeURIComponent(leaveTypeCode)}`, {
headers: getAuthHeaders(),
});
if (!res.ok) return null;
return await res.json();
return await getLeaveBalance(leaveTypeCode);
} catch (e) {
console.error('Failed to check leave balance', e);
return null;
@@ -1316,10 +1308,8 @@ const startLocalLeaveFlow = async (content: string) => {
try {
const keyword = payload.form.applicantName || payload.form.employeeId;
if (keyword) {
const res = await fetch(`/api/chat/oa/employees?keyword=${encodeURIComponent(keyword)}&page=1&page_size=1&agent_id=${agentId}`, { headers: getAuthHeaders() });
if (res.ok) {
const data = await res.json();
const match = (data.items || []).find((item: LeaveAgentOption) => item.employeeId === payload.form.employeeId);
const data = await listOaEmployees(agentId, { keyword, page: 1, page_size: 1 });
const match = (data.items || []).find((item: LeaveAgentOption) => item.employeeId === payload.form.employeeId);
if (match) {
payload.form.fillerJobTitle = match.jobtitle || '';
payload.form.fillerJobTitleName = match.jobtitleName || '';
@@ -1335,7 +1325,6 @@ const startLocalLeaveFlow = async (content: string) => {
payload.form.applicantDepartmentName = match.departmentName || '';
payload.form.applicantSubCompanyName = match.subcompanyName || '';
}
}
}
} catch (e) {
console.error('Failed to prefill OA user info', e);
@@ -1396,9 +1385,7 @@ const formatYesNoLabel = (value: 0 | 1 | null) => {
const syncCurrentUserProfile = async () => {
if (currentUser.value?.real_name?.trim()) return;
try {
const res = await fetch('/api/user/profile', { headers: getAuthHeaders() });
if (!res.ok) return;
const data = await res.json();
const data = await getUserProfile();
currentUser.value = { ...currentUser.value, ...data };
} catch (e) {
console.error('Failed to load current user profile', e);
@@ -1819,19 +1806,7 @@ const confirmLeaveSubmission = async (chatMsg: any) => {
}
try {
const res = await fetch('/api/user/leave-workflow/submit', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...getAuthHeaders(),
},
body: JSON.stringify(payload.form),
});
const data = await res.json().catch(() => ({}));
if (!res.ok) {
throw new Error(data?.error || t('chat.oaLeaveSubmitFailed'));
}
const data = await submitLeaveWorkflow(payload.form);
const resultMsg = {
role: 'assistant' as const,
type: 'leave-result' as const,
@@ -1916,10 +1891,7 @@ const regenerate = () => {
// 加载历史记录
const loadHistory = async () => {
try {
const res = await fetch(`/api/chat/sessions?agent_id=${agentId}`, { headers: getAuthHeaders() });
if (res.ok) {
history.value = await res.json();
}
history.value = await listChatSessions(agentId);
} catch (e) {
console.error('Failed to load history', e);
}
@@ -1928,16 +1900,11 @@ const loadHistory = async () => {
const clearAllHistory = async () => {
openDeleteConfirmDialog(t('chat.confirmClearHistory'), async () => {
try {
const res = await fetch(`/api/chat/sessions?agent_id=${agentId}`, {
method: 'DELETE',
headers: getAuthHeaders()
});
if (res.ok) {
history.value = [];
runs.value = [];
if (conversationId.value || activeRunId.value) {
startNewChat();
}
await deleteAllChatSessions(agentId);
history.value = [];
runs.value = [];
if (conversationId.value || activeRunId.value) {
startNewChat();
}
} catch (e) {
console.error('Failed to clear history', e);
@@ -1949,15 +1916,10 @@ const deleteHistoryItem = async (id: string, event: Event) => {
event.stopPropagation();
openDeleteConfirmDialog(t('chat.confirmDeleteHistoryItem'), async () => {
try {
const res = await fetch(`/api/chat/sessions/${id}?agent_id=${agentId}`, {
method: 'DELETE',
headers: getAuthHeaders()
});
if (res.ok) {
history.value = history.value.filter(h => h.conversation_id !== id);
if (conversationId.value === id) {
startNewChat();
}
await deleteChatSession(id, agentId);
history.value = history.value.filter(h => h.conversation_id !== id);
if (conversationId.value === id) {
startNewChat();
}
} catch (e) {
console.error('Failed to delete history item', e);
@@ -1971,13 +1933,8 @@ const loadConversation = async (id: string) => {
try {
activeRunId.value = null;
isThinking.value = false;
const res = await fetch(`/api/chat/messages?conversation_id=${id}&agent_id=${agentId}`, { headers: getAuthHeaders() });
if (res.ok) {
messages.value = await res.json();
conversationId.value = id;
// Reset feedback state
}
messages.value = await listChatMessages(id, agentId);
conversationId.value = id;
} catch (e) {
console.error('Failed to load conversation', e);
}
@@ -1989,33 +1946,26 @@ const startNewChat = () => {
const loadAgent = async () => {
try {
const res = await fetch(`/api/user/agents/${agentId}`, { headers: getAuthHeaders() });
if (res.ok) {
currentAgent.value = await res.json();
} else {
if (res.status === 403) {
msg.error(t('workspace.permission.denied') || 'Access denied');
router.push('/workspace?no_redirect=1');
return;
}
currentAgent.value = { name: t('workspace.unknownAgent') };
}
currentAgent.value = await getUserAgent(agentId);
} catch (e) {
if (e instanceof BusinessError && e.status === 403) {
msg.error(t('workspace.permission.denied') || 'Access denied');
router.push('/workspace?no_redirect=1');
return;
}
console.error('Failed to load agent', e);
currentAgent.value = { name: t('workspace.unknownAgent') };
}
};
const loadUserAgents = async () => {
try {
const res = await fetch('/api/agents', { headers: getAuthHeaders() });
if (res.ok) {
const agents = await res.json();
userAgents.value = Array.isArray(agents)
? agents.filter((a: any) => a.id !== agentId && (a.dify_app_type || 'chatflow') === 'chatflow')
: [];
if (userAgents.value.length === 0) {
showAgentPanel.value = false;
}
const agents = await listUserAgents();
userAgents.value = Array.isArray(agents)
? agents.filter((a: any) => a.id !== agentId && (a.dify_app_type || 'chatflow') === 'chatflow')
: [];
if (userAgents.value.length === 0) {
showAgentPanel.value = false;
}
} catch (e) {
userAgents.value = [];