清理废弃代码,重构长期记忆系统
核心变更: - 删除 worker.rs + ipc.rs(废弃进程架构) - 删除 ias listen 路径(cmd_listen / listen_loop / ToolExecutor) - 合并 ias service → ias daemon --log-file - 修复 main.rs call_capability 不处理上下文工具的 bug MemoryStore 重构: - write_for 空内容防御 + 精确去重 - 缓存结构 Vec<String> → Vec<(i32, String)>(用数据库 id 标识) - 新增 delete_for / update_for 方法 + LLM 工具定义 - load_if_needed 避免每次消息查 DB - 缓存 TTL(1h) + 每用户 200 条上限 - read_for limit 参数(默认 30 条) daemon.rs: - execute_tool 统一为递归派发,消除 call_capability 重复路由 净减少约 1400 行代码,0 warning,20 测试通过
This commit is contained in:
@@ -126,41 +126,6 @@ pub async fn list_recent_chat_records(
|
||||
|
||||
// ─── LLM 用量 ───
|
||||
|
||||
/// 插入一条 LLM 用量记录
|
||||
/// kind/entry 为 iPet 遗留兼容字段,写入默认值 ("llm_call" / null)
|
||||
pub async fn insert_llm_usage(
|
||||
pool: &PgPool,
|
||||
user_id: &str,
|
||||
model: &str,
|
||||
provider: &str,
|
||||
prompt_tokens: u32,
|
||||
completion_tokens: u32,
|
||||
cache_hit_tokens: u32,
|
||||
cache_miss_tokens: u32,
|
||||
) -> Result<(), String> {
|
||||
let total = prompt_tokens + completion_tokens;
|
||||
sqlx::query(
|
||||
r#"
|
||||
INSERT INTO llm_usage (user_id, model, provider, prompt_tokens, completion_tokens, total_tokens, cache_hit_tokens, cache_miss_tokens, kind, entry)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
"#,
|
||||
)
|
||||
.bind(user_id)
|
||||
.bind(model)
|
||||
.bind(provider)
|
||||
.bind(prompt_tokens as i32)
|
||||
.bind(completion_tokens as i32)
|
||||
.bind(total as i32)
|
||||
.bind(cache_hit_tokens as i32)
|
||||
.bind(cache_miss_tokens as i32)
|
||||
.bind("llm_call")
|
||||
.bind(serde_json::Value::Null)
|
||||
.execute(pool)
|
||||
.await
|
||||
.map_err(|e| format!("插入 LLM 用量失败: {}", e))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// LLM 用量聚合统计
|
||||
#[derive(Debug, Clone, sqlx::FromRow)]
|
||||
pub struct LlmUsageStats {
|
||||
|
||||
Reference in New Issue
Block a user