From 33a9b7c640abeec19c404b946fadf287d8c3376e Mon Sep 17 00:00:00 2001 From: Max Goisser Date: Thu, 30 Jul 2026 19:05:06 +0200 Subject: [PATCH] Extract config modules into erato_config crate Related Linear issue: ERMAIN-515 --- backend/Cargo.lock | 21 ++++++++++++++++--- backend/Cargo.toml | 2 +- backend/erato/Cargo.toml | 5 ++--- backend/erato/src/gen_config_reference.rs | 2 +- backend/erato/src/lib.rs | 8 +++---- backend/erato/src/services/client_actions.rs | 2 +- .../erato/tests/integration_tests/config.rs | 2 +- backend/erato_config/Cargo.toml | 19 +++++++++++++++++ backend/{erato => erato_config}/src/config.rs | 7 +++++-- .../src/config_facet_attrs.rs | 0 .../src/config_reference.rs | 0 backend/erato_config/src/lib.rs | 6 ++++++ .../src/startup_log.rs | 0 13 files changed, 58 insertions(+), 16 deletions(-) create mode 100644 backend/erato_config/Cargo.toml rename backend/{erato => erato_config}/src/config.rs (99%) rename backend/{erato => erato_config}/src/config_facet_attrs.rs (100%) rename backend/{erato => erato_config}/src/config_reference.rs (100%) create mode 100644 backend/erato_config/src/lib.rs rename backend/{erato => erato_config}/src/startup_log.rs (100%) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 2aa37c32d..5ae30a9da 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -2434,13 +2434,12 @@ dependencies = [ "base64 0.22.1", "chrono", "color-eyre", - "config", "console-subscriber", "cron", "ctor 0.2.9", "dotenv-flow", + "erato_config", "eyre", - "facet", "futures", "genai", "graph-rs-sdk", @@ -2479,7 +2478,6 @@ dependencies = [ "rmcp", "rmcp-sse", "sea-orm", - "secrecy", "sentry", "sentry-tower", "serde", @@ -2507,6 +2505,23 @@ dependencies = [ "xberg", ] +[[package]] +name = "erato_config" +version = "0.6.2" +dependencies = [ + "base64 0.22.1", + "config", + "eyre", + "facet", + "regex", + "secrecy", + "serde", + "serde_json", + "tracing", + "url", + "utoipa", +] + [[package]] name = "errno" version = "0.3.14" diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 679d91c0d..68e52bdfb 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["erato", "mock-llm-server", "mock-mcp-server", "rmcp-sse"] +members = ["erato", "erato_config", "mock-llm-server", "mock-mcp-server", "rmcp-sse"] [profile.dev] split-debuginfo = "packed" diff --git a/backend/erato/Cargo.toml b/backend/erato/Cargo.toml index 7f94efc05..30b85489a 100644 --- a/backend/erato/Cargo.toml +++ b/backend/erato/Cargo.toml @@ -18,6 +18,8 @@ name = "record-chat-provider-reqwest" path = "./src/record_chat_provider_reqwest.rs" [dependencies] +erato_config = { path = "../erato_config" } + # Dependencies: Server axum = { version = "0.8.4", features = ["macros", "ws"] } axum-extra = { version = "0.10.1", features = ["typed-header", "multipart"] } @@ -50,7 +52,6 @@ aes-gcm-siv = "0.11.1" hmac = "0.13.0" jsonwebtoken = "10.4.0" regorus = "0.5.0" -secrecy = "0.10.3" sha2 = "0.11.0" # Dependencies: Async runtime @@ -105,10 +106,8 @@ graph-rs-sdk = { version = "3.0", default-features = false, features = ["rustls- regex = "1.12.3" rand = "0.9.4" base64 = "0.22.1" -facet = "0.44.3" # Newtype utility synonym = "0.1.5" -config = "0.15.6" toml_edit = "0.23.10" dotenv-flow = "0.16.2" handlebars = "6" diff --git a/backend/erato/src/gen_config_reference.rs b/backend/erato/src/gen_config_reference.rs index 753cc49f8..3454785d4 100644 --- a/backend/erato/src/gen_config_reference.rs +++ b/backend/erato/src/gen_config_reference.rs @@ -2,7 +2,7 @@ use std::fs; use std::process; -use erato::config_reference::{generate_config_reference, validate_config_reference}; +use erato_config::config_reference::{generate_config_reference, validate_config_reference}; fn main() { let args: Vec = std::env::args().collect(); diff --git a/backend/erato/src/lib.rs b/backend/erato/src/lib.rs index 266b2a15a..4d0931f0d 100644 --- a/backend/erato/src/lib.rs +++ b/backend/erato/src/lib.rs @@ -6,9 +6,9 @@ use server::router::MainRouterApiDoc; use crate::server::router::MAIN_ROUTER_DOC; pub mod actors; -pub mod config; -pub mod config_facet_attrs; -pub mod config_reference; +pub use erato_config::config; +pub use erato_config::config_facet_attrs; +pub use erato_config::config_reference; pub mod db; pub mod frontend_environment; pub mod metrics; @@ -21,7 +21,7 @@ pub mod profiling; pub mod query_metrics; pub mod server; pub mod services; -pub mod startup_log; +pub use erato_config::startup_log; pub mod state; pub mod telemetry; pub mod translation_po; diff --git a/backend/erato/src/services/client_actions.rs b/backend/erato/src/services/client_actions.rs index 802eda53d..a3f201a80 100644 --- a/backend/erato/src/services/client_actions.rs +++ b/backend/erato/src/services/client_actions.rs @@ -13,7 +13,7 @@ use serde_json::{Value, json}; /// Name of the synthetic tool offered to the model when the active action /// facet declares `client_actions`. -pub const CLIENT_ACTION_TOOL_NAME: &str = "propose_client_action"; +pub use erato_config::config::CLIENT_ACTION_TOOL_NAME; /// Build the synthetic client-action tool with an enum-constrained input /// schema, so the model can only select one of the configured actions. diff --git a/backend/erato/tests/integration_tests/config.rs b/backend/erato/tests/integration_tests/config.rs index 6b84194cc..e65a19254 100644 --- a/backend/erato/tests/integration_tests/config.rs +++ b/backend/erato/tests/integration_tests/config.rs @@ -2,7 +2,7 @@ use crate::test_utils::hermetic_app_config; use crate::{MIGRATOR, test_app_state}; -use erato::config::{ +use erato_config::config::{ AppConfig, FileTypeDetectionMode, GenerationConfig, ModelReasoningEffort, ModelVerbosity, PromptSourceSpecification, RuntimeConfigurationConfig, ServerConfig, SharepointAllDrivesSource, }; diff --git a/backend/erato_config/Cargo.toml b/backend/erato_config/Cargo.toml new file mode 100644 index 000000000..a6eaba19f --- /dev/null +++ b/backend/erato_config/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "erato_config" +version = "0.6.2" +description = "Shared configuration representation and loading for Erato" +license = "AGPL-3.0-or-later" +edition = "2024" + +[dependencies] +base64 = "0.22.1" +config = "0.15.6" +eyre = "0.6.12" +facet = "0.44.3" +regex = "1.12.3" +secrecy = "0.10.3" +serde = { version = "1.0.217", features = ["derive"] } +serde_json = "1.0.138" +tracing = "0.1.41" +utoipa = { version = "5.3.1", features = ["uuid", "chrono"] } +url = "2.5.8" diff --git a/backend/erato/src/config.rs b/backend/erato_config/src/config.rs similarity index 99% rename from backend/erato/src/config.rs rename to backend/erato_config/src/config.rs index f90cc4a3c..667804431 100644 --- a/backend/erato/src/config.rs +++ b/backend/erato_config/src/config.rs @@ -16,6 +16,9 @@ use utoipa::ToSchema; use crate::config_facet_attrs as erato_config; use crate::startup_log; +/// Name reserved for the synthetic client-action tool exposed by the backend. +pub const CLIENT_ACTION_TOOL_NAME: &str = "propose_client_action"; + const DEFAULT_PROMPT_OPTIMIZER_PROMPT: &str = r#" You are Lyra, a master-level AI prompt optimization specialist. Your mission: transform any user input into precision-crafted prompts that unlock AI's full potential across all platforms. @@ -1014,7 +1017,7 @@ impl AppConfig { tool.name ); } - if name == crate::services::client_actions::CLIENT_ACTION_TOOL_NAME { + if name == CLIENT_ACTION_TOOL_NAME { panic!("Client tool named '{}' is reserved.", name); } let namespace = tool.namespace_or_default(); @@ -1038,7 +1041,7 @@ impl AppConfig { .chars() .all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-')) { - crate::startup_log::warn_preinit(format!( + startup_log::warn_preinit(format!( "Client tool name '{}' does not match ^[a-zA-Z0-9_-]{{1,64}}$; \ OpenAI/Azure and Anthropic reject such tool names at request time.", name diff --git a/backend/erato/src/config_facet_attrs.rs b/backend/erato_config/src/config_facet_attrs.rs similarity index 100% rename from backend/erato/src/config_facet_attrs.rs rename to backend/erato_config/src/config_facet_attrs.rs diff --git a/backend/erato/src/config_reference.rs b/backend/erato_config/src/config_reference.rs similarity index 100% rename from backend/erato/src/config_reference.rs rename to backend/erato_config/src/config_reference.rs diff --git a/backend/erato_config/src/lib.rs b/backend/erato_config/src/lib.rs new file mode 100644 index 000000000..b47aae0aa --- /dev/null +++ b/backend/erato_config/src/lib.rs @@ -0,0 +1,6 @@ +//! Shared Erato configuration types, loading, validation, and reference metadata. + +pub mod config; +pub mod config_facet_attrs; +pub mod config_reference; +pub mod startup_log; diff --git a/backend/erato/src/startup_log.rs b/backend/erato_config/src/startup_log.rs similarity index 100% rename from backend/erato/src/startup_log.rs rename to backend/erato_config/src/startup_log.rs