Revert "Implement token-based context usage in chat UI"
This reverts commit 82aa3e8d36.
This commit is contained in:
parent
82aa3e8d36
commit
a0c367d79b
4 changed files with 838 additions and 1162 deletions
6
package-lock.json
generated
6
package-lock.json
generated
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"name": "botserver",
|
|
||||||
"lockfileVersion": 3,
|
|
||||||
"requires": true,
|
|
||||||
"packages": {}
|
|
||||||
}
|
|
||||||
236
src/main.rs
236
src/main.rs
|
|
@ -56,93 +56,7 @@ use crate::web_server::{bot_index, index, static_files};
|
||||||
use crate::whatsapp::whatsapp_webhook_verify;
|
use crate::whatsapp::whatsapp_webhook_verify;
|
||||||
use crate::whatsapp::WhatsAppAdapter;
|
use crate::whatsapp::WhatsAppAdapter;
|
||||||
|
|
||||||
if args.len() > 1 {
|
|
||||||
let command = &args[1];
|
|
||||||
match command.as_str() {
|
|
||||||
async fn main() -> std::io::Result<()> {
|
|
||||||
trace!("Application starting");
|
|
||||||
let args: Vec<String> = std::env::args().collect();
|
|
||||||
trace!("Command line arguments: {:?}", args);
|
|
||||||
|
|
||||||
if args.len() > 1 {
|
|
||||||
let command = &args[1];
|
|
||||||
trace!("Processing command: {}", command);
|
|
||||||
match command.as_str() {
|
|
||||||
let args: Vec<String> = std::env::args().collect();
|
|
||||||
|
|
||||||
if args.len() > 1 {
|
|
||||||
let command = &args[1];
|
|
||||||
match command.as_str() {
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
|
||||||
trace!("Application starting");
|
|
||||||
let args: Vec<String> = std::env::args().collect();
|
|
||||||
trace!("Command line arguments: {:?}", args);
|
|
||||||
|
|
||||||
if args.len() > 1 {
|
|
||||||
let command = &args[1];
|
|
||||||
trace!("Processing command: {}", command);
|
|
||||||
match command.as_str() {
|
|
||||||
"install" | "remove" | "list" | "status" | "start" | "stop" | "restart" | "--help" | "-h" => {
|
|
||||||
match package_manager::cli::run().expect("Failed to initialize Drive");
|
|
||||||
let drive = init_drive(&config.minio)
|
|
||||||
.await
|
|
||||||
.expect("Failed to initialize Drive");
|
|
||||||
trace!("MinIO drive initialized successfully");
|
|
||||||
.await
|
|
||||||
.expect("Failed to initialize Drive");
|
|
||||||
let drive = init_drive(&config.minio)
|
|
||||||
.await
|
|
||||||
.expect("Failed to initialize Drive");
|
|
||||||
trace!("MinIO drive initialized successfully"); {
|
|
||||||
Ok(_) => return Ok(()),
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!("CLI error: {}", e);
|
|
||||||
return Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
format!("CLI command failed: {}", e),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
eprintln!("Unknown command: {}", command);
|
|
||||||
eprintln!("Run 'botserver --help' for usage information");
|
|
||||||
return Err(std::io::Error::new(
|
|
||||||
std::io::ErrorKind::InvalidInput,
|
|
||||||
format!("Unknown command: {}", command),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if args.len() > 1 {
|
|
||||||
let command = &args[1];
|
|
||||||
match command.as_str() {
|
|
||||||
async fn main() -> std::io::Result<()> {
|
|
||||||
trace!("Application starting");
|
|
||||||
let args: Vec<String> = std::env::args().collect();
|
|
||||||
trace!("Command line arguments: {:?}", args);
|
|
||||||
|
|
||||||
if args.len() > 1 {
|
|
||||||
let command = &args[1];
|
|
||||||
trace!("Processing command: {}", command);
|
|
||||||
match command.as_str() {
|
|
||||||
let args: Vec<String> = std::env::args().collect();
|
|
||||||
|
|
||||||
if args.len() > 1 {
|
|
||||||
let command = &args[1];
|
|
||||||
match command.as_str() {
|
|
||||||
#[tokio::main]
|
|
||||||
async fn main() -> std::io::Result<()> {
|
|
||||||
trace!("Starting main function");
|
|
||||||
let args: Vec<String> = std::env::args().collect();
|
|
||||||
trace!("Command line arguments: {:?}", args);
|
|
||||||
|
|
||||||
if args.len() > 1 {
|
|
||||||
let command = &args[1];
|
|
||||||
trace!("Processing command: {}", command);
|
|
||||||
match command.as_str() {
|
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
let args: Vec<String> = std::env::args().collect();
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
|
||||||
|
|
@ -171,60 +85,12 @@ async fn main() -> std::io::Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Starting BotServer bootstrap process");
|
dotenv().ok();
|
||||||
dotenv().ok();
|
|
||||||
env_logger::Builder::from_env(env_logger::Env::default_filter_or("info")).init();
|
|
||||||
trace!("Environment variables loaded and logger initialized");
|
|
||||||
|
|
||||||
info!("Starting BotServer bootstrap process");
|
|
||||||
trace!("Initializing bootstrap manager");
|
|
||||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
|
||||||
|
|
||||||
info!("Starting BotServer bootstrap process");
|
|
||||||
dotenv().ok();
|
|
||||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
|
||||||
trace!("Environment variables loaded and logger initialized");
|
|
||||||
|
|
||||||
info!("Starting BotServer bootstrap process");
|
|
||||||
trace!("Initializing bootstrap manager");
|
|
||||||
|
|
||||||
info!("Starting BotServer bootstrap process");
|
|
||||||
dotenv().ok();
|
|
||||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
|
||||||
trace!("Environment variables loaded and logger initialized");
|
|
||||||
|
|
||||||
info!("Starting BotServer bootstrap process");
|
|
||||||
trace!("Initializing bootstrap manager");
|
|
||||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
||||||
|
|
||||||
info!("Starting BotServer bootstrap process");
|
info!("Starting BotServer bootstrap process");
|
||||||
|
|
||||||
InstallMode::Container
|
let install_mode = if args.contains(&"--container".to_string()) {
|
||||||
} else {
|
|
||||||
InstallMode::Local
|
|
||||||
};
|
|
||||||
|
|
||||||
let tenant = if let Some(idx) = args.iter().position(|a| a == "--tenant") {
|
|
||||||
args.get(idx + 1).cloned()
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
let install_mode = if args.contains(&"--container".to_string()) {
|
|
||||||
trace!("Running in container mode");
|
|
||||||
InstallMode::Container
|
|
||||||
} else {
|
|
||||||
trace!("Running in local mode");
|
|
||||||
InstallMode::Local
|
|
||||||
};
|
|
||||||
|
|
||||||
let tenant = if let Some(idx) = args.iter().position(|a| a == "--tenant") {
|
|
||||||
let tenant = args.get(idx + 1).cloned();
|
|
||||||
trace!("Tenant specified: {:?}", tenant);
|
|
||||||
tenant
|
|
||||||
} else {
|
|
||||||
trace!("No tenant specified");
|
|
||||||
None
|
|
||||||
};
|
|
||||||
InstallMode::Container
|
InstallMode::Container
|
||||||
} else {
|
} else {
|
||||||
InstallMode::Local
|
InstallMode::Local
|
||||||
|
|
@ -237,28 +103,7 @@ None
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut bootstrap = BootstrapManager::new(install_mode.clone(), tenant.clone());
|
let mut bootstrap = BootstrapManager::new(install_mode.clone(), tenant.clone());
|
||||||
info!("Bootstrap completed successfully, configuration loaded from database");
|
let cfg = match bootstrap.bootstrap() {
|
||||||
config
|
|
||||||
let cfg = match bootstrap.bootstrap() {
|
|
||||||
Ok(config) => {
|
|
||||||
info!("Bootstrap completed successfully, configuration loaded from database");
|
|
||||||
trace!("Bootstrap config: {:?}", config);
|
|
||||||
config
|
|
||||||
Ok(config) => {
|
|
||||||
info!("Bootstrap completed successfully, configuration loaded from database");
|
|
||||||
config
|
|
||||||
let cfg = match bootstrap.bootstrap() {
|
|
||||||
Ok(config) => {
|
|
||||||
info!("Bootstrap completed successfully, configuration loaded from database");
|
|
||||||
trace!("Bootstrap config: {:?}", config);
|
|
||||||
config
|
|
||||||
info!("Bootstrap completed successfully, configuration loaded from database");
|
|
||||||
config
|
|
||||||
let cfg = match bootstrap.bootstrap() {
|
|
||||||
Ok(config) => {
|
|
||||||
info!("Bootstrap completed successfully, configuration loaded from database");
|
|
||||||
trace!("Bootstrap config: {:?}", config);
|
|
||||||
config
|
|
||||||
Ok(config) => {
|
Ok(config) => {
|
||||||
info!("Bootstrap completed successfully, configuration loaded from database");
|
info!("Bootstrap completed successfully, configuration loaded from database");
|
||||||
config
|
config
|
||||||
|
|
@ -286,30 +131,10 @@ config
|
||||||
log::warn!("Failed to upload templates to MinIO: {}", e);
|
log::warn!("Failed to upload templates to MinIO: {}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Establishing database connection to {}", cfg.database_url());
|
let config = std::sync::Arc::new(cfg.clone());
|
||||||
let config = std::sync::Arc::new(cfg.clone());
|
|
||||||
trace!("Configuration loaded: {:?}", cfg);
|
|
||||||
|
|
||||||
info!("Establishing database connection to {}", cfg.database_url());
|
|
||||||
trace!("Database URL: {}", cfg.database_url());
|
|
||||||
|
|
||||||
info!("Establishing database connection to {}", cfg.database_url());
|
info!("Establishing database connection to {}", cfg.database_url());
|
||||||
let db_pool = match diesel::Connection::establish(&cfg.database_url()) {
|
let db_pool = match diesel::Connection::establish(&cfg.database_url()) {
|
||||||
Ok(conn) => {
|
|
||||||
trace!("Database connection established successfully");
|
|
||||||
Arc::new(Mutex::new(conn))
|
|
||||||
}
|
|
||||||
Ok(conn) => Arc::new(Mutex::new(conn)),
|
|
||||||
let db_pool = match diesel::Connection::establish(&cfg.database_url()) {
|
|
||||||
Ok(conn) => {
|
|
||||||
trace!("Database connection established successfully");
|
|
||||||
Arc::new(Mutex::new(conn))
|
|
||||||
}
|
|
||||||
let db_pool = match diesel::Connection::establish(&cfg.database_url()) {
|
|
||||||
Ok(conn) => {
|
|
||||||
trace!("Database connection established successfully");
|
|
||||||
Arc::new(Mutex::new(conn))
|
|
||||||
}
|
|
||||||
Ok(conn) => Arc::new(Mutex::new(conn)),
|
Ok(conn) => Arc::new(Mutex::new(conn)),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("Failed to connect to main database: {}", e);
|
log::error!("Failed to connect to main database: {}", e);
|
||||||
|
|
@ -331,21 +156,6 @@ Arc::new(Mutex::new(conn))
|
||||||
.or_else(|_| std::env::var("REDIS_URL"))
|
.or_else(|_| std::env::var("REDIS_URL"))
|
||||||
.unwrap_or_else(|_| "redis://localhost:6379".to_string());
|
.unwrap_or_else(|_| "redis://localhost:6379".to_string());
|
||||||
let redis_client = match redis::Client::open(cache_url.as_str()) {
|
let redis_client = match redis::Client::open(cache_url.as_str()) {
|
||||||
Ok(client) => {
|
|
||||||
trace!("Redis client created successfully");
|
|
||||||
Some(Arc::new(client))
|
|
||||||
}
|
|
||||||
Ok(client) => Some(Arc::new(client)),
|
|
||||||
let redis_client = match redis::Client::open(cache_url.as_str()) {
|
|
||||||
Ok(client) => {
|
|
||||||
trace!("Redis client created successfully");
|
|
||||||
Some(Arc::new(client))
|
|
||||||
}
|
|
||||||
let redis_client = match redis::Client::open(cache_url.as_str()) {
|
|
||||||
Ok(client) => {
|
|
||||||
trace!("Redis client created successfully");
|
|
||||||
Some(Arc::new(client))
|
|
||||||
}
|
|
||||||
Ok(client) => Some(Arc::new(client)),
|
Ok(client) => Some(Arc::new(client)),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::warn!("Failed to connect to Redis: Redis URL did not parse- {}", e);
|
log::warn!("Failed to connect to Redis: Redis URL did not parse- {}", e);
|
||||||
|
|
@ -373,12 +183,7 @@ Some(Arc::new(client))
|
||||||
let tool_api = Arc::new(tools::ToolApi::new());
|
let tool_api = Arc::new(tools::ToolApi::new());
|
||||||
|
|
||||||
info!("Initializing MinIO drive at {}", cfg.minio.server);
|
info!("Initializing MinIO drive at {}", cfg.minio.server);
|
||||||
.await
|
let drive = init_drive(&config.minio)
|
||||||
.expect("Failed to initialize Drive");
|
|
||||||
let drive = init_drive(&config.minio)
|
|
||||||
.await
|
|
||||||
.expect("Failed to initialize Drive");
|
|
||||||
trace!("MinIO drive initialized successfully");
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to initialize Drive");
|
.expect("Failed to initialize Drive");
|
||||||
|
|
||||||
|
|
@ -421,30 +226,12 @@ trace!("MinIO drive initialized successfully");
|
||||||
config.server.host, config.server.port
|
config.server.host, config.server.port
|
||||||
);
|
);
|
||||||
|
|
||||||
.unwrap_or(4);
|
let worker_count = std::thread::available_parallelism()
|
||||||
let worker_count = std::thread::available_parallelism()
|
|
||||||
.map(|n| n.get())
|
|
||||||
.unwrap_or(4);
|
|
||||||
trace!("Configured worker threads: {}", worker_count);
|
|
||||||
.map(|n| n.get())
|
|
||||||
.unwrap_or(4);
|
|
||||||
let worker_count = std::thread::available_parallelism()
|
|
||||||
.map(|n| n.get())
|
|
||||||
.unwrap_or(4);
|
|
||||||
trace!("Configured worker threads: {}", worker_count);
|
|
||||||
.unwrap_or(4);
|
|
||||||
let worker_count = std::thread::available_parallelism()
|
|
||||||
.map(|n| n.get())
|
|
||||||
.unwrap_or(4);
|
|
||||||
trace!("Configured worker threads: {}", worker_count);
|
|
||||||
.map(|n| n.get())
|
.map(|n| n.get())
|
||||||
.unwrap_or(4);
|
.unwrap_or(4);
|
||||||
|
|
||||||
// Spawn AutomationService in a LocalSet on a separate thread
|
// Spawn AutomationService in a LocalSet on a separate thread
|
||||||
std::thread::spawn(move || {
|
let automation_state = app_state.clone();
|
||||||
let automation_state = app_state.clone();
|
|
||||||
trace!("Spawning automation service thread");
|
|
||||||
std::thread::spawn(move || {
|
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
let rt = tokio::runtime::Builder::new_current_thread()
|
let rt = tokio::runtime::Builder::new_current_thread()
|
||||||
.enable_all()
|
.enable_all()
|
||||||
|
|
@ -467,15 +254,6 @@ std::thread::spawn(move || {
|
||||||
let _drive_handle = drive_monitor.spawn();
|
let _drive_handle = drive_monitor.spawn();
|
||||||
|
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
trace!("Creating new HTTP server instance");
|
|
||||||
let cors = Cors::default()
|
|
||||||
let cors = Cors::default()
|
|
||||||
HttpServer::new(move || {
|
|
||||||
trace!("Creating new HTTP server instance");
|
|
||||||
let cors = Cors::default()
|
|
||||||
HttpServer::new(move || {
|
|
||||||
trace!("Creating new HTTP server instance");
|
|
||||||
let cors = Cors::default()
|
|
||||||
let cors = Cors::default()
|
let cors = Cors::default()
|
||||||
.allow_any_origin()
|
.allow_any_origin()
|
||||||
.allow_any_method()
|
.allow_any_method()
|
||||||
|
|
|
||||||
|
|
@ -1,65 +0,0 @@
|
||||||
pub database: DatabaseConfig,
|
|
||||||
pub drive: DriveConfig,
|
|
||||||
pub meet: MeetConfig,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct DatabaseConfig {
|
|
||||||
pub url: String,
|
|
||||||
pub max_connections: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct DriveConfig {
|
|
||||||
pub storage_path: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct MeetConfig {
|
|
||||||
pub api_key: String,
|
|
||||||
pub api_secret: String,
|
|
||||||
}
|
|
||||||
use serde::Deserialize;
|
|
||||||
use dotenvy::dotenv;
|
|
||||||
use std::env;
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct AppConfig {
|
|
||||||
pub database: DatabaseConfig,
|
|
||||||
pub drive: DriveConfig,
|
|
||||||
pub meet: MeetConfig,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct DatabaseConfig {
|
|
||||||
pub url: String,
|
|
||||||
pub max_connections: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct DriveConfig {
|
|
||||||
pub storage_path: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct MeetConfig {
|
|
||||||
pub api_key: String,
|
|
||||||
pub api_secret: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AppConfig {
|
|
||||||
pub fn load() -> anyhow::Result<Self> {
|
|
||||||
dotenv().ok();
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
database: DatabaseConfig {
|
|
||||||
url: env::var("DATABASE_URL")?,
|
|
||||||
max_connections: env::var("DATABASE_MAX_CONNECTIONS")?.parse()?,
|
|
||||||
},
|
|
||||||
drive: DriveConfig {
|
|
||||||
storage_path: env::var("DRIVE_STORAGE_PATH")?,
|
|
||||||
},
|
|
||||||
meet: MeetConfig {
|
|
||||||
api_key: env::var("MEET_API_KEY")?,
|
|
||||||
api_secret: env::var("MEET_API_SECRET")?,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
1693
web/index.html
1693
web/index.html
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue