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§
Sourcefn 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 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
Sourcefn 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 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
Sourcefn 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 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
Sourcefn 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 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,
替换整个对话历史
Sourcefn 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<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<Session>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
列出所有 session
Sourcefn 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 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
Sourcefn 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 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
Sourcefn 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 get_insights<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<SessionInsights>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
获取统计信息
Sourcefn 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 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
Sourcefn 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 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
Sourcefn 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 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
Sourcefn 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 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,
截断对话(删除指定时间戳之后的消息)
Sourcefn 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_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 名称
Sourcefn 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_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 扩展数据
Sourcefn 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_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 统计
Sourcefn 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_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 配置
Sourcefn 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 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 配置
Sourcefn 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,
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,
搜索聊天历史