Skip to main content

SessionStore

Trait SessionStore 

Source
pub trait SessionStore: Send + Sync {
Show 18 methods // Required methods fn create_session<'life0, 'async_trait>( &'life0 self, working_dir: PathBuf, name: String, session_type: SessionType, ) -> Pin<Box<dyn Future<Output = Result<Session>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_session<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, include_messages: bool, ) -> Pin<Box<dyn Future<Output = Result<Session>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn add_message<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, session_id: &'life1 str, message: &'life2 Message, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn replace_conversation<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, session_id: &'life1 str, conversation: &'life2 Conversation, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn list_sessions<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Session>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn list_sessions_by_types<'life0, 'life1, 'async_trait>( &'life0 self, types: &'life1 [SessionType], ) -> Pin<Box<dyn Future<Output = Result<Vec<Session>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn delete_session<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_insights<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<SessionInsights>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn export_session<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn import_session<'life0, 'life1, 'async_trait>( &'life0 self, json: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Session>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn copy_session<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, new_name: String, ) -> Pin<Box<dyn Future<Output = Result<Session>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn truncate_conversation<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, timestamp: i64, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn update_session_name<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, name: String, user_set: bool, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn update_extension_data<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, extension_data: ExtensionData, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn update_token_stats<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, stats: TokenStatsUpdate, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn update_provider_config<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, provider_name: Option<String>, model_config: Option<ModelConfig>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn update_recipe<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, recipe: Option<Recipe>, user_recipe_values: Option<HashMap<String, String>>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn search_chat_history<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, limit: Option<usize>, after_date: Option<DateTime<Utc>>, before_date: Option<DateTime<Utc>>, exclude_session_id: Option<String>, ) -> Pin<Box<dyn Future<Output = Result<Vec<ChatHistoryMatch>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait;
}
Expand description

Session 存储 trait

应用层可以实现此 trait 来提供自定义的 session 存储。 框架提供默认的 SQLite 实现 (SqliteSessionStore)。

Required Methods§

Source

fn create_session<'life0, 'async_trait>( &'life0 self, working_dir: PathBuf, name: String, session_type: SessionType, ) -> Pin<Box<dyn Future<Output = Result<Session>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

创建新 session

Source

fn get_session<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, include_messages: bool, ) -> Pin<Box<dyn Future<Output = Result<Session>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

获取 session

Source

fn add_message<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, session_id: &'life1 str, message: &'life2 Message, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

添加消息到 session

Source

fn replace_conversation<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, session_id: &'life1 str, conversation: &'life2 Conversation, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

替换整个对话历史

Source

fn list_sessions<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Session>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

列出所有 session

Source

fn list_sessions_by_types<'life0, 'life1, 'async_trait>( &'life0 self, types: &'life1 [SessionType], ) -> Pin<Box<dyn Future<Output = Result<Vec<Session>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

按类型列出 session

Source

fn delete_session<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

删除 session

Source

fn get_insights<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<SessionInsights>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

获取统计信息

Source

fn export_session<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

导出 session 为 JSON

Source

fn import_session<'life0, 'life1, 'async_trait>( &'life0 self, json: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Session>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

从 JSON 导入 session

Source

fn copy_session<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, new_name: String, ) -> Pin<Box<dyn Future<Output = Result<Session>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

复制 session

Source

fn truncate_conversation<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, timestamp: i64, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

截断对话(删除指定时间戳之后的消息)

Source

fn update_session_name<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, name: String, user_set: bool, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

更新 session 名称

Source

fn update_extension_data<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, extension_data: ExtensionData, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

更新 session 扩展数据

Source

fn update_token_stats<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, stats: TokenStatsUpdate, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

更新 session token 统计

Source

fn update_provider_config<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, provider_name: Option<String>, model_config: Option<ModelConfig>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

更新 session 的 provider 和 model 配置

Source

fn update_recipe<'life0, 'life1, 'async_trait>( &'life0 self, session_id: &'life1 str, recipe: Option<Recipe>, user_recipe_values: Option<HashMap<String, String>>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

更新 session 的 recipe 配置

Source

fn search_chat_history<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, limit: Option<usize>, after_date: Option<DateTime<Utc>>, before_date: Option<DateTime<Utc>>, exclude_session_id: Option<String>, ) -> Pin<Box<dyn Future<Output = Result<Vec<ChatHistoryMatch>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

搜索聊天历史

Implementors§