diff --git a/frontend/src/utils/files.ts b/frontend/src/utils/files.ts index 163c0f7b..b6b74db9 100644 --- a/frontend/src/utils/files.ts +++ b/frontend/src/utils/files.ts @@ -33,7 +33,9 @@ export function getFileIcon(input: string | { type?: string; file_type?: string; if (['ppt', 'pptx'].includes(ext)) return 'file-powerpoint'; // TDesign 无稳定 `file-text` 字形时会导致空白,纯文类统一用 `file` if (['txt', 'md', 'markdown', 'json', 'log', 'yaml', 'yml', 'xml'].includes(ext)) return 'file'; - if (['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp'].includes(ext)) return 'image'; + if (['py', 'pyc', 'pyo', 'js', 'mjs', 'cjs', 'ts', 'tsx', 'jsx', 'go', 'rs', 'java', 'c', 'cc', 'cpp', 'h', 'hpp', 'sh', 'bash', 'rb', 'php', 'sql', 'html', 'htm'].includes(ext)) return 'code'; + if (['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'svg'].includes(ext)) return 'image'; if (['mp3', 'wav', 'm4a', 'flac', 'ogg', 'aac'].includes(ext)) return 'sound'; + if (['mp4', 'mov', 'webm', 'mkv', 'avi'].includes(ext)) return 'video'; return 'file'; } diff --git a/frontend/src/views/chat/components/ChatArtifactsDrawer.vue b/frontend/src/views/chat/components/ChatArtifactsDrawer.vue index 76cdb4b6..3d04a266 100644 --- a/frontend/src/views/chat/components/ChatArtifactsDrawer.vue +++ b/frontend/src/views/chat/components/ChatArtifactsDrawer.vue @@ -18,28 +18,36 @@ --> +
{{ $t('common.loading') }}
- + {{ $t('agent.artifactDrawer.empty') }}
- - -
- -
+
    +
  • + + +
    {{ item.file_name }}
    @@ -49,19 +57,20 @@
    - - - {{ $t('agent.artifactDrawer.download') }} - + - - +
  • +
@@ -83,6 +92,7 @@ import { computed, ref, watch, reactive } from 'vue' import { useI18n } from 'vue-i18n' import { MessagePlugin } from 'tdesign-vue-next' import { downloadArtifact, listMessageArtifacts, type ArtifactMeta } from '@/api/chat' +import { getFileIcon } from '@/utils/files' const props = defineProps<{ visible: boolean @@ -144,7 +154,6 @@ function handleClose() { emit('update:visible', false) } -// Format helpers. function formatFileSize(size: number): string { if (!size || size < 0) return '0 B' const units = ['B', 'KB', 'MB', 'GB'] @@ -154,7 +163,6 @@ function formatFileSize(size: number): string { s /= 1024 unit++ } - // Keep one decimal for non-integer units; integers stay integer. return unit === 0 ? `${s} ${units[unit]}` : `${s.toFixed(1)} ${units[unit]}` } @@ -162,59 +170,10 @@ function formatDateTime(raw: string): string { if (!raw) return '—' const d = new Date(raw) if (Number.isNaN(d.getTime())) return raw - // Local time, seconds precision — matches how the rest of the app - // renders message timestamps. const pad = (n: number) => String(n).padStart(2, '0') return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}` } -function iconForFile(name: string): string { - const ext = (name.split('.').pop() || '').toLowerCase() - switch (ext) { - case 'pptx': - case 'ppt': - return 'chart-pie' - case 'xlsx': - case 'xls': - case 'csv': - return 'file-excel' - case 'docx': - case 'doc': - return 'file-word' - case 'pdf': - return 'file-pdf' - case 'md': - case 'markdown': - return 'file' - case 'html': - case 'htm': - return 'code-1' - case 'json': - return 'code-1' - case 'png': - case 'jpg': - case 'jpeg': - case 'gif': - case 'svg': - case 'webp': - return 'image' - case 'mp3': - case 'wav': - case 'ogg': - return 'sound-up' - case 'mp4': - case 'mov': - case 'webm': - return 'video' - case 'zip': - case 'tar': - case 'gz': - return 'folder-zip' - default: - return 'file-attachment' - } -} - async function handleDownload(item: ArtifactMeta) { if (!props.sessionId || !props.messageId) { MessagePlugin.error(t('agent.artifactDrawer.downloadFailed')) @@ -245,6 +204,39 @@ async function handleDownload(item: ArtifactMeta) { + +