1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//! 数据持久化模块
//!
//! 基于微内核设计理念的可选数据持久化能力。
//!
//! # 设计理念
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────┐
//! │ Persistence Architecture │
//! ├─────────────────────────────────────────────────────────────────┤
//! │ │
//! │ ┌──────────────────────────────────────────────────────────┐ │
//! │ │ Core Traits (微内核) │ │
//! │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │ │
//! │ │ │MessageStore │ │ ApiCallStore│ │ SessionStore │ │ │
//! │ │ └─────────────┘ └─────────────┘ └─────────────────────┘ │ │
//! │ └──────────────────────────────────────────────────────────┘ │
//! │ │ │
//! │ ▼ │
//! │ ┌──────────────────────────────────────────────────────────┐ │
//! │ │ Backend Implementations │ │
//! │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │ │
//! │ │ │ PostgreSQL │ │ MySQL │ │ SQLite │ │ │
//! │ │ │ (sqlx-pg) │ │ (sqlx-mysql)│ │ (sqlx-sqlite) │ │ │
//! │ │ └─────────────┘ └─────────────┘ └─────────────────────┘ │ │
//! │ │ ┌─────────────────────────────────────┐ │ │
//! │ │ │ In-Memory (default) │ │ │
//! │ │ └─────────────────────────────────────┘ │ │
//! │ └──────────────────────────────────────────────────────────┘ │
//! │ │ │
//! │ ▼ │
//! │ ┌──────────────────────────────────────────────────────────┐ │
//! │ │ Plugin Integration │ │
//! │ │ ┌─────────────────────────────────────────────────────┐ │ │
//! │ │ │ PersistencePlugin - 自动记录 LLM 调用和消息 │ │ │
//! │ │ └─────────────────────────────────────────────────────┘ │ │
//! │ └──────────────────────────────────────────────────────────┘ │
//! │ │
//! └─────────────────────────────────────────────────────────────────┘
//! ```
//!
//! # 特性
//!
//! - **可选依赖**: 通过 feature flags 控制后端实现
//! - **trait 抽象**: 核心功能通过 trait 定义,支持自定义实现
//! - **插件集成**: 提供 `PersistencePlugin` 无缝集成到 LLMAgent
//! - **异步设计**: 全异步 API,不阻塞主流程
//!
//! # 使用示例
//!
//! ## 内存存储 (默认)
//!
//! ```rust,ignore
//! use mofa_foundation::persistence::{InMemoryStore, PersistencePlugin};
//! use uuid::Uuid;
//!
//! let store = InMemoryStore::new();
//! let plugin = PersistencePlugin::from_store(
//! "persistence-plugin",
//! store,
//! Uuid::now_v7(),
//! Uuid::now_v7(),
//! Uuid::now_v7(),
//! Uuid::now_v7(),
//! );
//! ```
//!
//! ## PostgreSQL 存储 (需要 `persistence-postgres` feature)
//!
//! ```rust,ignore
//! use mofa_foundation::persistence::{PostgresStore, PersistencePlugin};
//! use uuid::Uuid;
//!
//! let store = PostgresStore::connect("postgres://localhost/mofa").await?;
//! let plugin = PersistencePlugin::from_store(
//! "persistence-plugin",
//! store,
//! Uuid::now_v7(),
//! Uuid::now_v7(),
//! Uuid::now_v7(),
//! Uuid::now_v7(),
//! );
//! ```
//!
//! ## MySQL 存储 (需要 `persistence-mysql` feature)
//!
//! ```rust,ignore
//! use mofa_foundation::persistence::{MySqlStore, PersistencePlugin};
//! use uuid::Uuid;
//!
//! let store = MySqlStore::connect("mysql://localhost/mofa").await?;
//! let plugin = PersistencePlugin::from_store(
//! "persistence-plugin",
//! store,
//! Uuid::now_v7(),
//! Uuid::now_v7(),
//! Uuid::now_v7(),
//! Uuid::now_v7(),
//! );
//! ```
//!
//! ## SQLite 存储 (需要 `persistence-sqlite` feature)
//!
//! ```rust,ignore
//! use mofa_foundation::persistence::{SqliteStore, PersistencePlugin};
//! use uuid::Uuid;
//!
//! // 文件数据库
//! let store = SqliteStore::connect("sqlite:./data.db").await?;
//!
//! // 内存数据库 (适用于测试)
//! let store = SqliteStore::in_memory().await?;
//!
//! let plugin = PersistencePlugin::from_store(
//! "persistence-plugin",
//! store,
//! Uuid::now_v7(),
//! Uuid::now_v7(),
//! Uuid::now_v7(),
//! Uuid::now_v7(),
//! );
//! ```
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;