refactor: worker进程 → tokio task 架构 + 多渠道消息队列 + JSON工具系统

核心变更:
- daemon: 废弃 worker 子进程模型,替换为 LLM/Tool/Send 三消费者 tokio task
- queue: 新增公平轮转 MessageQueue + QueueRunner 路由,严格 ChannelId 渠道隔离
- channel: ChannelId(platform + user_id) 统一渠道标识,替代散列 user_id+platform
- tools: 全部工具统一经由 execute_tool() → Tool Consumer 单一执行路径
- llm: chat_with_tools 返回 ChatResult,支持异步工具调用 → 保留/恢复 session
- tools: 新增 JSON 工具定义系统 (ToolDef) 及 SubprocessRunner (HTTP 模板引擎)
- bin: ias-auth 独立 JWT 生成器,ias-fetch headless Chrome 网页抓取
- 所有出站消息通过 Send Consumer 队列转发,无直接 send_text 调用
- Session TTL 清理 (5分钟),QueueRunner 通道容错
- cargo check 零警告,cargo test 23/23 通过
This commit is contained in:
2026-06-09 16:32:49 +08:00
parent 8dc232ebab
commit 937556917c
17 changed files with 2937 additions and 729 deletions
+38
View File
@@ -0,0 +1,38 @@
//! 渠道 / 通道基础类型
//!
//! 定义消息的来源/目标渠道标识,以及从外部(微信等)收到的原始消息。
use serde::{Deserialize, Serialize};
use std::fmt;
/// 渠道标识 —— 区分消息来自哪个平台和哪个用户
#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub struct ChannelId {
/// 平台名称,如 "wechat"、"telegram"、"console"
pub platform: String,
/// 在该平台上的用户 ID
pub user_id: String,
}
impl ChannelId {
/// 快捷构造微信渠道
pub fn wechat(user_id: impl Into<String>) -> Self {
Self { platform: "wechat".into(), user_id: user_id.into() }
}
}
impl fmt::Display for ChannelId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}:{}", self.platform, self.user_id)
}
}
/// 从外部轮询收到的原始消息
#[derive(Debug, Clone, Serialize, Deserialize)]
#[allow(dead_code)]
pub struct IncomingMessage {
pub channel: ChannelId,
pub text: String,
pub message_id: String,
pub context_token: Option<String>,
}