feat: 拆分 worker 架构并增强 assistant 安全保护
- 新增 daemon/channel/assistant/function/scheduler/logging worker 架构和 JetStream 消息协议 - 修复邮件通知误入 assistant、迁移 checksum、日志 subject 和工具调用无限循环风险 - 新增 assistant 工具轮次熔断、工具结果截断和提示词软收敛规则 - 补充邮件推送关键字、可信发件人配置、升级日志和验证测试
This commit is contained in:
+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