feat: 拆分 worker 架构并增强 assistant 安全保护
- 新增 daemon/channel/assistant/function/scheduler/logging worker 架构和 JetStream 消息协议 - 修复邮件通知误入 assistant、迁移 checksum、日志 subject 和工具调用无限循环风险 - 新增 assistant 工具轮次熔断、工具结果截断和提示词软收敛规则 - 补充邮件推送关键字、可信发件人配置、升级日志和验证测试
This commit is contained in:
+14
-2
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ias-main"
|
||||
version = "0.2.27"
|
||||
version = "0.3.0"
|
||||
edition = "2024"
|
||||
|
||||
[[bin]]
|
||||
@@ -11,9 +11,21 @@ path = "src/main.rs"
|
||||
ias-db = { path = "../ias-db" }
|
||||
ias-service = { path = "../ias-service" }
|
||||
ias-mail = { path = "../ias-mail" }
|
||||
ias-daemon = { path = "../ias-daemon" }
|
||||
ias-channel = { path = "../ias-channel" }
|
||||
ias-assistant = { path = "../ias-assistant" }
|
||||
ias-function = { path = "../ias-function" }
|
||||
ias-scheduler = { path = "../ias-scheduler" }
|
||||
ias-logging = { path = "../ias-logging" }
|
||||
ias-http = { path = "../ias-http" }
|
||||
clap = { version = "4.6.1", features = ["derive"] }
|
||||
anyhow = "1"
|
||||
tokio = { version = "1.0", features = ["rt-multi-thread", "macros"] }
|
||||
sqlx = { version = "0.9.0", features = [
|
||||
"runtime-tokio",
|
||||
"tls-rustls",
|
||||
"postgres",
|
||||
] }
|
||||
tokio = { version = "1.0", features = ["rt-multi-thread", "macros", "signal", "sync"] }
|
||||
dotenvy = "0.15.7"
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
|
||||
@@ -16,6 +16,22 @@ pub enum Commands {
|
||||
#[command(subcommand)]
|
||||
command: Option<ServiceAction>,
|
||||
},
|
||||
/// 运行 daemon 控制面
|
||||
Daemon {
|
||||
#[command(subcommand)]
|
||||
command: DaemonAction,
|
||||
},
|
||||
/// 运行独立 worker
|
||||
Worker {
|
||||
#[command(subcommand)]
|
||||
command: WorkerAction,
|
||||
},
|
||||
/// 独立运行 HTTP 服务
|
||||
Http {
|
||||
/// HTTP 监听地址
|
||||
#[arg(long, default_value = "0.0.0.0:9003")]
|
||||
host: String,
|
||||
},
|
||||
/// 配置邮件账户
|
||||
Mail {
|
||||
#[command(subcommand)]
|
||||
@@ -48,6 +64,36 @@ pub enum ServiceAction {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Subcommand)]
|
||||
pub enum DaemonAction {
|
||||
/// 前台运行 daemon 控制面
|
||||
Run,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Subcommand)]
|
||||
pub enum WorkerAction {
|
||||
/// 运行 Assistant Worker
|
||||
Assistant,
|
||||
/// 运行 WeChat Worker
|
||||
Wechat {
|
||||
/// 限定微信账号 ID,多个值可用逗号分隔
|
||||
#[arg(long, value_delimiter = ',')]
|
||||
account_ids: Vec<String>,
|
||||
},
|
||||
/// 运行 Mail Worker
|
||||
Mail,
|
||||
/// 运行 Function Worker
|
||||
Function {
|
||||
/// worker 名称,用于 durable consumer 命名
|
||||
#[arg(long)]
|
||||
name: Option<String>,
|
||||
},
|
||||
/// 运行 Scheduler Worker
|
||||
Scheduler,
|
||||
/// 运行 Logging Worker
|
||||
Logging,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum Channels {
|
||||
/// 微信渠道配置
|
||||
@@ -96,6 +142,11 @@ pub enum MailAction {
|
||||
/// 邮件账户 ID
|
||||
id: i64,
|
||||
},
|
||||
/// 修改邮件推送过滤和可信发件人设置
|
||||
Settings {
|
||||
/// 邮件账户 ID
|
||||
id: i64,
|
||||
},
|
||||
/// 检查邮件账户 IMAP 连通性
|
||||
Check {
|
||||
/// 邮件账户 ID
|
||||
|
||||
+40
-8
@@ -1,14 +1,14 @@
|
||||
mod cli;
|
||||
|
||||
use clap::Parser;
|
||||
use cli::{Channels, Cli, Commands, MailAction, ServiceAction, WechatAction};
|
||||
use ias_db::connect_db;
|
||||
use ias_service::supervisor::{
|
||||
use cli::{
|
||||
Channels, Cli, Commands, DaemonAction, MailAction, ServiceAction, WechatAction, WorkerAction,
|
||||
};
|
||||
use ias_daemon::supervisor::{
|
||||
print_logs, restart_service, start_service, status_service, stop_service,
|
||||
};
|
||||
use ias_service::{
|
||||
delete_account, init_logging, list_accounts, login_user, rename_account, run_service,
|
||||
};
|
||||
use ias_db::connect_db;
|
||||
use ias_service::{delete_account, init_logging, list_accounts, login_user, rename_account};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
@@ -20,8 +20,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
let action = command.unwrap_or(ServiceAction::Run);
|
||||
match action {
|
||||
ServiceAction::Run => {
|
||||
let pool = connect_db().await?;
|
||||
run_service(pool).await?;
|
||||
ias_daemon::run_daemon().await?;
|
||||
}
|
||||
ServiceAction::Start => start_service().await?,
|
||||
ServiceAction::Stop => stop_service().await?,
|
||||
@@ -30,6 +29,26 @@ async fn main() -> anyhow::Result<()> {
|
||||
ServiceAction::Logs { lines } => print_logs(lines)?,
|
||||
}
|
||||
}
|
||||
Commands::Daemon { command } => match command {
|
||||
DaemonAction::Run => ias_daemon::run_daemon().await?,
|
||||
},
|
||||
Commands::Worker { command } => {
|
||||
let pool = connect_db().await?;
|
||||
match command {
|
||||
WorkerAction::Assistant => ias_assistant::run_worker(pool).await?,
|
||||
WorkerAction::Wechat { account_ids } => {
|
||||
ias_channel::run_wechat_worker(pool, account_ids).await?
|
||||
}
|
||||
WorkerAction::Mail => ias_channel::run_mail_worker(pool).await?,
|
||||
WorkerAction::Function { name } => ias_function::run_worker(name).await?,
|
||||
WorkerAction::Scheduler => ias_scheduler::run_worker(pool).await?,
|
||||
WorkerAction::Logging => ias_logging::run_worker(pool).await?,
|
||||
}
|
||||
}
|
||||
Commands::Http { host } => {
|
||||
let pool = connect_db().await?;
|
||||
run_http(pool, host).await?;
|
||||
}
|
||||
Commands::Channel { command } => {
|
||||
let pool = connect_db().await?;
|
||||
match command {
|
||||
@@ -50,6 +69,9 @@ async fn main() -> anyhow::Result<()> {
|
||||
MailAction::List => ias_mail::auth::list_accounts(&pool).await?,
|
||||
MailAction::Show { id } => ias_mail::auth::show_account(&pool, id).await?,
|
||||
MailAction::Edit { id } => ias_mail::auth::edit_account(&pool, id).await?,
|
||||
MailAction::Settings { id } => {
|
||||
ias_mail::auth::configure_account_settings(&pool, id).await?
|
||||
}
|
||||
MailAction::Check { id } => ias_mail::auth::check_account(&pool, id).await?,
|
||||
MailAction::Pull { id } => ias_mail::auth::pull_mail(&pool, id).await?,
|
||||
MailAction::Delete { id } => ias_mail::auth::delete_account(&pool, id).await?,
|
||||
@@ -69,3 +91,13 @@ async fn main() -> anyhow::Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn run_http(pool: sqlx::PgPool, host: String) -> anyhow::Result<()> {
|
||||
let (shutdown_tx, shutdown_rx) = tokio::sync::watch::channel(false);
|
||||
tokio::spawn(async move {
|
||||
let _ = tokio::signal::ctrl_c().await;
|
||||
let _ = shutdown_tx.send(true);
|
||||
});
|
||||
let routes = ias_service::extra_http_routes(pool.clone());
|
||||
ias_http::create_http(host, shutdown_rx, pool, routes).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user