feat: 添加系统命令支持 (:clear)
- 新增系统命令模块 (core/system-commands) - 支持 :clear/:cls/:c 清空对话历史 - 命令注册表支持别名 - 可扩展的命令执行器 - Server 端支持 - 新增 /api/system-commands API - WebSocket 处理系统命令消息 - 会话清空 API 端点 - UI 端支持 - 新增 SystemCommandMenu 组件 - 输入 : 时显示命令建议菜单 - 键盘导航和选择 - 底部提示添加 : 快捷键
This commit is contained in:
@@ -104,6 +104,47 @@ sessionsRouter.delete('/:id', async (c) => {
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* POST /sessions/:id/clear - 清空会话消息
|
||||
*
|
||||
* 删除会话的所有消息和相关数据,但保留会话本身
|
||||
*/
|
||||
sessionsRouter.post('/:id/clear', async (c) => {
|
||||
const id = c.req.param('id');
|
||||
|
||||
if (!sessionManager.exists(id)) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Session not found',
|
||||
},
|
||||
404
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
// 删除会话的所有消息
|
||||
await MessageStorage.removeBySession(id);
|
||||
|
||||
// 重置会话状态
|
||||
sessionManager.updateStatus(id, 'idle');
|
||||
|
||||
return c.json({
|
||||
success: true,
|
||||
message: 'Session messages cleared',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[Sessions] Failed to clear messages:', error);
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to clear messages',
|
||||
},
|
||||
500
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /sessions/:id/messages - 获取会话消息
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user