From aaee5f044abaf3c7f7f7cda0d47341f0b5f0d6d4 Mon Sep 17 00:00:00 2001 From: MaoMengww <1707647656@qq.com> Date: Fri, 10 Apr 2026 12:49:20 +0800 Subject: [PATCH] feat: attachment_support --- frontend/src/api/agent/index.ts | 2 + frontend/src/api/chat/streame.ts | 6 +- frontend/src/components/AttachmentUpload.vue | 228 +++++++++++++ frontend/src/components/Input-field.vue | 86 ++++- frontend/src/i18n/locales/en-US.ts | 12 + frontend/src/i18n/locales/ko-KR.ts | 12 + frontend/src/i18n/locales/ru-RU.ts | 12 + frontend/src/i18n/locales/zh-CN.ts | 12 + frontend/src/stores/menu.ts | 5 +- frontend/src/views/agent/AgentEditorModal.vue | 29 ++ .../src/views/chat/components/usermsg.vue | 74 ++++ frontend/src/views/chat/index.vue | 46 ++- frontend/src/views/creatChat/creatChat.vue | 12 +- .../chat_pipeline/into_chat_message.go | 8 + .../service/session_knowledge_qa.go | 5 + .../handler/session/attachment_processor.go | 320 ++++++++++++++++++ internal/handler/session/handler.go | 10 + internal/handler/session/helpers.go | 3 +- internal/handler/session/qa.go | 67 +++- internal/handler/session/types.go | 8 + internal/types/chat_manage.go | 4 + internal/types/custom_agent.go | 4 + internal/types/message.go | 80 +++++ internal/types/qa_request.go | 1 + .../versioned/000033_add_attachments.down.sql | 1 + .../versioned/000033_add_attachments.up.sql | 1 + 26 files changed, 1029 insertions(+), 19 deletions(-) create mode 100644 frontend/src/components/AttachmentUpload.vue create mode 100644 internal/handler/session/attachment_processor.go create mode 100644 migrations/versioned/000033_add_attachments.down.sql create mode 100644 migrations/versioned/000033_add_attachments.up.sql diff --git a/frontend/src/api/agent/index.ts b/frontend/src/api/agent/index.ts index 551867e3..f168a619 100644 --- a/frontend/src/api/agent/index.ts +++ b/frontend/src/api/agent/index.ts @@ -39,6 +39,8 @@ export interface CustomAgentConfig { image_upload_enabled?: boolean; // 是否启用图片上传(默认: false) vlm_model_id?: string; // VLM模型ID(图片分析用) image_storage_provider?: string; // 图片存储提供商 + audio_upload_enabled?: boolean; // 是否启用音频上传/ASR转录(默认: false) + asr_model_id?: string; // ASR模型ID(音频转录用) // ===== 文件类型限制 ===== // 支持的文件类型(如 ["csv", "xlsx", "xls"]) diff --git a/frontend/src/api/chat/streame.ts b/frontend/src/api/chat/streame.ts index ec789d92..442b51ec 100644 --- a/frontend/src/api/chat/streame.ts +++ b/frontend/src/api/chat/streame.ts @@ -29,7 +29,7 @@ export function useStream() { let renderTimer: number | null = null // 启动流式请求 - const startStream = async (params: { session_id: any; query: any; knowledge_base_ids?: string[]; knowledge_ids?: string[]; agent_enabled?: boolean; agent_id?: string; web_search_enabled?: boolean; enable_memory?: boolean; summary_model_id?: string; mcp_service_ids?: string[]; mentioned_items?: Array<{id: string; name: string; type: string; kb_type?: string}>; images?: Array<{data: string}>; method: string; url: string }) => { + const startStream = async (params: { session_id: any; query: any; knowledge_base_ids?: string[]; knowledge_ids?: string[]; agent_enabled?: boolean; agent_id?: string; web_search_enabled?: boolean; enable_memory?: boolean; summary_model_id?: string; mcp_service_ids?: string[]; mentioned_items?: Array<{id: string; name: string; type: string; kb_type?: string}>; images?: Array<{data: string}>; attachment_uploads?: Array<{data: string; file_name: string; file_size: number}>; method: string; url: string }) => { // 重置状态 output.value = ''; error.value = null; @@ -118,6 +118,10 @@ export function useStream() { if (params.images !== undefined && params.images.length > 0) { postBody.images = params.images; } + // Include attachment_uploads if provided (documents, audio, etc.) + if (params.attachment_uploads !== undefined && params.attachment_uploads.length > 0) { + postBody.attachment_uploads = params.attachment_uploads; + } postBody.channel = "web"; await fetchEventSource(url, { diff --git a/frontend/src/components/AttachmentUpload.vue b/frontend/src/components/AttachmentUpload.vue new file mode 100644 index 00000000..bddf9b65 --- /dev/null +++ b/frontend/src/components/AttachmentUpload.vue @@ -0,0 +1,228 @@ + + + + + diff --git a/frontend/src/components/Input-field.vue b/frontend/src/components/Input-field.vue index 3f98578c..5ebc8c22 100644 --- a/frontend/src/components/Input-field.vue +++ b/frontend/src/components/Input-field.vue @@ -18,6 +18,7 @@ import { listAgents, type CustomAgent, BUILTIN_QUICK_ANSWER_ID, BUILTIN_SMART_RE import { getTenantWebSearchConfig } from '@/api/web-search'; import { getConversationConfig, updateConversationConfig, type ConversationConfig } from '@/api/system'; import { useI18n } from 'vue-i18n'; +import AttachmentUpload, { type AttachmentFile } from './AttachmentUpload.vue'; const route = useRoute(); const router = useRouter(); @@ -35,6 +36,10 @@ const uploadedImages = ref>([]); const imageInputRef = ref(); const imageUploading = ref(false); +// Attachment upload state +const attachmentUploadRef = ref>(); +const uploadedAttachments = ref([]); + const handleImageSelect = (event: Event) => { const input = event.target as HTMLInputElement; if (!input.files) return; @@ -1338,7 +1343,10 @@ watch([selectedKbIds, selectedFileIds], ([kbIds, fileIds]) => { } }, { deep: true }); -const emit = defineEmits(['send-msg', 'stop-generation']); +const emit = defineEmits<{ + (e: 'send-msg', query: string, modelId: string, mentionedItems: any[], imageFiles: File[], attachmentFiles: AttachmentFile[]): void; + (e: 'stop-generation'): void; +}>(); const createSession = async (val: string) => { if (!val.trim()) { @@ -1375,15 +1383,23 @@ const createSession = async (val: string) => { kb_type: item.type === 'kb' ? (item.kbType || 'document') : undefined })); const imageFiles = uploadedImages.value.map(img => img.file); + const attachmentFiles = uploadedAttachments.value; + // Blur the textarea BEFORE emitting, so that when the parent navigates away // and Vue unmounts this component, TDesign's blur handler won't fire on a // detached DOM element (which causes getComputedStyle to throw). const textarea = getTextareaEl(); if (textarea) textarea.blur(); - emit('send-msg', val, selectedModelId.value, mentionedItems, imageFiles); + emit('send-msg', val, selectedModelId.value, mentionedItems, imageFiles, attachmentFiles); + // Clean up image previews uploadedImages.value.forEach(img => URL.revokeObjectURL(img.preview)); uploadedImages.value = []; + + // Clean up attachments + attachmentUploadRef.value?.clear(); + uploadedAttachments.value = []; + clearvalue(); } @@ -1854,6 +1870,15 @@ defineExpose({ × + + + +
+ + + +
+ + + + + {{ uploadedAttachments.length }} +
+
+