fix(personal): align assistant citations and UI state

This commit is contained in:
2026-07-12 12:07:28 +08:00
parent c8ef15ee9e
commit 36b7bf28bf
14 changed files with 181 additions and 61 deletions
+4 -4
View File
@@ -32,7 +32,7 @@ export const readPayload = <T>(statusCode: number, data: unknown, clearAuthOnUna
const payload = data as ApiPayload<T>;
const code = typeof payload?.code === 'number' ? payload.code : undefined;
if (statusCode < 200 || statusCode >= 300 || (code !== undefined && code !== 200)) {
if (clearAuthOnUnauthorized && (statusCode === 401 || statusCode === 403 || code === 401 || code === 403)) {
if (clearAuthOnUnauthorized && (statusCode === 401 || code === 401)) {
clearAuth();
}
throw new Error(payload?.msg || `HTTP ${statusCode}`);
@@ -45,7 +45,7 @@ export const parsePayloadText = (statusCode: number, text: string, clearAuthOnUn
try {
return JSON.parse(text || '{}');
} catch (error) {
if (clearAuthOnUnauthorized && (statusCode === 401 || statusCode === 403)) clearAuth();
if (clearAuthOnUnauthorized && statusCode === 401) clearAuth();
throw error instanceof SyntaxError
? new Error(statusCode >= 400 ? `HTTP ${statusCode}` : '响应解析失败')
: error;
@@ -120,7 +120,7 @@ export const authenticatedFileUrl = async (url: string): Promise<string> => {
resolve(URL.createObjectURL(xhr.response));
return;
}
if (xhr.status === 401 || xhr.status === 403) clearAuth();
if (xhr.status === 401) clearAuth();
reject(new Error(`HTTP ${xhr.status}`));
};
xhr.onerror = () => reject(new Error('网络请求失败'));
@@ -137,7 +137,7 @@ export const authenticatedFileUrl = async (url: string): Promise<string> => {
resolve(response.tempFilePath);
return;
}
if (response.statusCode === 401 || response.statusCode === 403) clearAuth();
if (response.statusCode === 401) clearAuth();
reject(new Error(`HTTP ${response.statusCode}`));
},
fail: () => reject(new Error('网络请求失败'))
@@ -42,10 +42,15 @@ export const askPersonalAssistant = (payload: {
url: '/api/aihr/personal-assistant/ask',
method: 'POST',
data: payload,
timeout: 45000,
clearAuthOnUnauthorized: false
timeout: 45000
});
export const mergePersonalRows = (current: PersonalItem[], incoming: PersonalItem[]) => {
const rows = new Map<number, PersonalItem>();
[...current, ...incoming].forEach((item) => rows.set(item.id, item));
return Array.from(rows.values());
};
export const loadPersonalSpace = () => apiRequest<PersonalSpace>({
url: '/api/aihr/personal-assistant/space',
method: 'GET'