diff --git a/server/routes/agent-chat.js b/server/routes/agent-chat.js
index a34e0bf..295a46b 100644
--- a/server/routes/agent-chat.js
+++ b/server/routes/agent-chat.js
@@ -807,12 +807,26 @@ function listSubAgentLogs(agentId, convId) {
router.delete('/:agentId/conversations/:convId', (req, res) => {
const { agentId, convId } = req.params;
try {
- const dir = path.join(getAgentDir(agentId), 'conversations', convId);
- if (fs.existsSync(dir)) fs.rmSync(dir, { recursive: true, force: true });
+ const agentDir = getAgentDir(agentId);
+ // 1. 删除对话目录
+ const convDir = path.join(agentDir, 'conversations', convId);
+ if (fs.existsSync(convDir)) fs.rmSync(convDir, { recursive: true, force: true });
+ // 2. 删除关联的日志目录/文件
+ const logsDir = path.join(agentDir, 'logs');
+ if (fs.existsSync(logsDir)) {
+ for (const f of fs.readdirSync(logsDir)) {
+ if (f.includes(convId)) {
+ const fp = path.join(logsDir, f);
+ fs.rmSync(fp, { recursive: true, force: true });
+ }
+ }
+ }
+ // 3. 断开会话
const key = `${agentId}:${convId}`;
const entry = sessions.get(key);
if (entry && entry.protocol) entry.protocol.disconnect();
sessions.delete(key);
+ console.log(`[AgentChat] 🗑️ 已删除对话 ${agentId}/${convId}`);
res.json({ success: true });
} catch (err) { res.status(500).json({ error: err.message }); }
});
@@ -901,6 +915,50 @@ router.get('/:agentId/file/*', (req, res) => {
}
});
+// PUT /api/agent/:agentId/file/* — 保存文件内容
+router.put('/:agentId/file/*', (req, res) => {
+ const filePath = req.params[0];
+ if (!filePath) return res.status(400).json({ error: 'file path required' });
+
+ const agentDir = getAgentDir(req.params.agentId);
+ const fullPath = path.join(agentDir, filePath);
+ if (!fullPath.startsWith(agentDir)) {
+ return res.status(403).json({ error: 'Access denied' });
+ }
+
+ try {
+ // 确保目录存在
+ const dir = path.dirname(fullPath);
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
+ fs.writeFileSync(fullPath, req.body.content || '', 'utf-8');
+ console.log(`[AgentChat] 💾 已保存文件 ${req.params.agentId}/${filePath}`);
+ res.json({ success: true, path: filePath });
+ } catch (err) {
+ res.status(500).json({ error: err.message });
+ }
+});
+
+// DELETE /api/agent/:agentId/file/* — 删除文件或文件夹
+router.delete('/:agentId/file/*', (req, res) => {
+ const filePath = req.params[0];
+ if (!filePath) return res.status(400).json({ error: 'file path required' });
+
+ const agentDir = getAgentDir(req.params.agentId);
+ const fullPath = path.join(agentDir, filePath);
+ if (!fullPath.startsWith(agentDir)) {
+ return res.status(403).json({ error: 'Access denied' });
+ }
+ if (!fs.existsSync(fullPath)) return res.status(404).json({ error: 'Not found' });
+
+ try {
+ fs.rmSync(fullPath, { recursive: true, force: true });
+ console.log(`[AgentChat] 🗑️ 已删除 ${req.params.agentId}/${filePath}`);
+ res.json({ success: true, path: filePath });
+ } catch (err) {
+ res.status(500).json({ error: err.message });
+ }
+});
+
// GET/PUT /api/agent/:agentId/todo
router.get('/:agentId/todo', (req, res) => {
const fp = path.join(getAgentDir(req.params.agentId), 'todo.md');
diff --git a/web/src/components/FileNode.vue b/web/src/components/FileNode.vue
index 68ec1b5..4106faf 100644
--- a/web/src/components/FileNode.vue
+++ b/web/src/components/FileNode.vue
@@ -10,6 +10,7 @@
{{ node.name }}
{{ formatSize(node.size) }}
{{ node.count }}
+