feat: 网页端添加文件上传功能

- 支持图片上传(预览显示)
- 支持文本文件上传(txt, md, json, csv等)
- 支持 PDF 和 Word 文档
- 文件内容自动添加到消息中供 AI 分析
- 多文件同时上传支持
This commit is contained in:
2026-04-13 23:31:20 +08:00
parent d1431ac521
commit fe65f23fa7
2 changed files with 168 additions and 7 deletions

View File

@@ -766,6 +766,7 @@ async def websocket_endpoint(websocket: WebSocket, user_id: str):
elif action == "chat":
message = data.get("message", "")
files = data.get("files", []) # 上传的文件
conversation_id = data.get("conversation_id")
enable_thinking = data.get("enable_thinking", True)
agent_id_override = data.get("agent_id")
@@ -776,9 +777,22 @@ async def websocket_endpoint(websocket: WebSocket, user_id: str):
if agent and agent.is_active:
current_agent_id = agent_id_override
if not message.strip():
# 如果没有消息但有文件,构造消息
if not message.strip() and files:
message = "[上传文件]"
if not message.strip() and not files:
continue
# 处理文件内容,添加到消息
if files:
for f in files:
if f.get('type') and f['type'].startswith('image/'):
message += f"\n[图片: {f['name']}]"
elif f.get('content'):
# 文本文件内容
message += f"\n\n文件 {f['name']} 内容:\n{f['content'][:3000]}"
# 1. 获取Agent配置
agent_config = agent_service.get_agent_config(current_agent_id)
agent_tools = agent_config.get('agent', {}).get('tools', [])