fix(aia): stabilize attachment parsing and expand spreadsheet support
Align AIA attachment handling with actual extractor capability by adding xlsx/csv gray support, guiding doc/xls users to convert formats, and enforcing attachment-only answering to prevent system knowledge leakage. Made-with: Cursor
This commit is contained in:
@@ -42,6 +42,7 @@ const getFileIcon = (filename: string): string => {
|
||||
docx: 'word',
|
||||
xls: 'excel',
|
||||
xlsx: 'excel',
|
||||
csv: 'excel',
|
||||
ppt: 'ppt',
|
||||
pptx: 'ppt',
|
||||
txt: 'default',
|
||||
@@ -421,11 +422,17 @@ export const ChatWorkspace: React.FC<ChatWorkspaceProps> = ({
|
||||
}
|
||||
|
||||
const file = files[0];
|
||||
const allowedTypes = ['.pdf', '.docx', '.doc', '.txt', '.xlsx'];
|
||||
const allowedTypes = ['.pdf', '.docx', '.txt', '.xlsx', '.csv'];
|
||||
const ext = '.' + file.name.split('.').pop()?.toLowerCase();
|
||||
|
||||
if (!allowedTypes.includes(ext)) {
|
||||
alert(`不支持的文件类型: ${ext}\n支持的类型: ${allowedTypes.join(', ')}`);
|
||||
if (ext === '.doc') {
|
||||
alert('系统为了保证文档解析的精确度,当前仅支持 .docx 格式。请您在本地 Word 中打开该文件,选择“另存为 -> Word 文档 (.docx)”后再次上传。');
|
||||
} else if (ext === '.xls') {
|
||||
alert('系统为了保证表格解析的稳定性,当前仅支持 .xlsx 格式。请您在本地 Excel/WPS 中打开该文件,选择“另存为 -> Excel 工作簿 (.xlsx)”后再次上传。');
|
||||
} else {
|
||||
alert(`不支持的文件类型: ${ext}\n当前支持: ${allowedTypes.join(', ')}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -453,7 +460,9 @@ export const ChatWorkspace: React.FC<ChatWorkspaceProps> = ({
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`上传失败: ${response.status}`);
|
||||
const errorJson = await response.json().catch(() => null);
|
||||
const backendMessage = errorJson?.error?.message;
|
||||
throw new Error(backendMessage || `上传失败: ${response.status}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
@@ -469,7 +478,8 @@ export const ChatWorkspace: React.FC<ChatWorkspaceProps> = ({
|
||||
console.error('[ChatWorkspace] 上传附件失败:', error);
|
||||
// 移除失败的附件
|
||||
setAttachments(prev => prev.filter(a => a.id !== tempId));
|
||||
alert('附件上传失败,请重试');
|
||||
const message = error instanceof Error ? error.message : '附件上传失败,请重试';
|
||||
alert(message);
|
||||
} finally {
|
||||
setIsUploading(false);
|
||||
// 清空 input,允许重复选择同一文件
|
||||
@@ -780,7 +790,7 @@ export const ChatWorkspace: React.FC<ChatWorkspaceProps> = ({
|
||||
className={`attachment-btn ${attachments.length > 0 ? 'has-attachments' : ''}`}
|
||||
onClick={handleAttachmentClick}
|
||||
disabled={isUploading}
|
||||
title="添加附件(PDF、Word、TXT、Excel)"
|
||||
title="添加附件(PDF、DOCX、TXT、XLSX、CSV)"
|
||||
>
|
||||
<Paperclip size={16} />
|
||||
{attachments.length > 0 && (
|
||||
@@ -818,7 +828,7 @@ export const ChatWorkspace: React.FC<ChatWorkspaceProps> = ({
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept=".pdf,.docx,.doc,.txt,.xlsx"
|
||||
accept=".pdf,.docx,.txt,.xlsx,.xls,.csv"
|
||||
onChange={handleFileChange}
|
||||
style={{ display: 'none' }}
|
||||
/>
|
||||
|
||||
@@ -186,6 +186,7 @@ export const BRAND_COLORS = {
|
||||
teal: '#0D9488',
|
||||
purple: '#9333EA',
|
||||
yellow: '#CA8A04',
|
||||
indigo: '#6366F1',
|
||||
} as const;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user