后端新增 load_messages_for_topic_page(seq < cursor + limit 分页,走 (session_id, seq) 索引替代 OFFSET 深翻页),ChatMessage 增加 seq 游标;历史批次消息带 topic_id 下发,前端以 seq+topic_id 双重判定批次归属,规避切话题瞬间在途旧批次污染。 前端触顶增量加载:批次缓存在 pendingHistoryRef,收到 topic_history_end 一次性去重 prepend,scrollTop 按新增高度补偿锚定原头部消息;不足一屏自动补页,loading 超时 10s 自愈;流式输出中加载历史不清空流式累加器,避免已流出文本丢失。
116 lines
4.0 KiB
Rust
116 lines
4.0 KiB
Rust
pub mod adapter;
|
||
pub mod adapters;
|
||
pub mod context;
|
||
pub mod handler;
|
||
pub mod handlers;
|
||
pub mod response;
|
||
|
||
use serde::{Deserialize, Serialize};
|
||
|
||
/// 统一命令枚举 - 与渠道无关
|
||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||
#[serde(tag = "type", rename_all = "snake_case")]
|
||
pub enum Command {
|
||
/// 创建新话题(在同一个 Session 内)
|
||
CreateSession { title: Option<String> },
|
||
/// 保存当前话题内容到 Markdown 文件
|
||
SaveTopic {
|
||
filepath: Option<String>,
|
||
include_subagents: bool,
|
||
},
|
||
/// 保存会话内容到 Markdown 文件
|
||
SaveSession {
|
||
filepath: Option<String>,
|
||
include_all: bool,
|
||
include_subagents: bool,
|
||
},
|
||
/// 列出当前 Session 的所有话题
|
||
ListSessions { include_archived: bool },
|
||
/// 加载指定话题
|
||
LoadTopic { topic_id: String },
|
||
/// 切换到指定话题(清理当前历史并加载新话题)
|
||
SwitchTopic { topic_id: String },
|
||
/// 获取当前话题信息
|
||
GetCurrentSession,
|
||
/// 显示所有支持的命令
|
||
Help,
|
||
/// 列出所有可用通道
|
||
ListChannels,
|
||
/// 列出指定通道的所有会话
|
||
ListSessionsByChannel {
|
||
channel_name: String,
|
||
include_archived: bool,
|
||
},
|
||
/// 列出 Session 的所有 Topics
|
||
ListTopics { session_id: String },
|
||
/// 加载子智能体任务的消息历史
|
||
LoadTaskMessages { task_id: String },
|
||
/// 列出所有定时任务
|
||
ListSchedulerJobs,
|
||
/// 加载指定 channel + chat_id 的对话消息
|
||
LoadChatMessages { channel: String, chat_id: String },
|
||
/// 分页加载话题更早的历史消息(用户向上滚动触发)
|
||
LoadOlderMessages {
|
||
topic_id: String,
|
||
before_seq: i64,
|
||
},
|
||
/// 删除指定话题
|
||
DeleteTopic { topic_id: String },
|
||
/// 重命名指定话题
|
||
RenameTopic { topic_id: String, title: String },
|
||
/// 停止当前正在执行的 Agent
|
||
StopExecution,
|
||
/// 列出所有记忆
|
||
ListMemories,
|
||
/// 创建新记忆
|
||
CreateMemory {
|
||
namespace: String,
|
||
key: String,
|
||
content: String,
|
||
},
|
||
/// 更新已有记忆
|
||
UpdateMemory { id: String, content: String },
|
||
/// 删除记忆
|
||
DeleteMemory { id: String },
|
||
/// 列出所有技能
|
||
ListSkills,
|
||
/// 列出当前 Todo 列表
|
||
ListTodos {
|
||
/// 子代理的 task_id(进入子代理视图时传入)
|
||
#[serde(default)]
|
||
task_id: Option<String>,
|
||
},
|
||
}
|
||
|
||
impl Command {
|
||
/// 获取命令名称(用于日志和调试)
|
||
pub fn name(&self) -> &'static str {
|
||
match self {
|
||
Command::CreateSession { .. } => "create_session",
|
||
Command::SaveTopic { .. } => "save_topic",
|
||
Command::SaveSession { .. } => "save_session",
|
||
Command::ListSessions { .. } => "list_sessions",
|
||
Command::LoadTopic { .. } => "load_topic",
|
||
Command::SwitchTopic { .. } => "switch_topic",
|
||
Command::GetCurrentSession => "get_current_session",
|
||
Command::Help => "help",
|
||
Command::ListChannels => "list_channels",
|
||
Command::ListSessionsByChannel { .. } => "list_sessions_by_channel",
|
||
Command::ListTopics { .. } => "list_topics",
|
||
Command::LoadTaskMessages { .. } => "load_task_messages",
|
||
Command::ListSchedulerJobs => "list_scheduler_jobs",
|
||
Command::LoadChatMessages { .. } => "load_chat_messages",
|
||
Command::LoadOlderMessages { .. } => "load_older_messages",
|
||
Command::DeleteTopic { .. } => "delete_topic",
|
||
Command::RenameTopic { .. } => "rename_topic",
|
||
Command::StopExecution => "stop_execution",
|
||
Command::ListMemories => "list_memories",
|
||
Command::CreateMemory { .. } => "create_memory",
|
||
Command::UpdateMemory { .. } => "update_memory",
|
||
Command::DeleteMemory { .. } => "delete_memory",
|
||
Command::ListSkills => "list_skills",
|
||
Command::ListTodos { .. } => "list_todos",
|
||
}
|
||
}
|
||
}
|