use super::builder::ConfigBuilder;
use super::source::{parse_agent_section, parse_tools_config_bundle};
const DEFAULT_CONFIG: &str = include_str!("../../config/default_config.toml");
const SESSION_DEFAULT_CONFIG: &str = include_str!("../../config/session.toml");
const CONTEXT_INJECT_DEFAULT_CONFIG: &str = include_str!("../../config/context_inject.toml");
const TOOLS_DEFAULT_CONFIG: &str = include_str!("../../config/tools.toml");
const SANDBOX_DEFAULT_CONFIG: &str = include_str!("../../config/sandbox.toml");
const PLANNING_DEFAULT_CONFIG: &str = include_str!("../../config/planning.toml");
const MEMORY_DEFAULT_CONFIG: &str = include_str!("../../config/memory.toml");
fn apply_embedded_agent_shard(
b: &mut ConfigBuilder,
shard_label: &'static str,
toml_src: &'static str,
) -> Result<(), String> {
let agent = parse_agent_section(toml_src).map_err(|e| {
format!("嵌入默认配置 {shard_label} TOML 无效(须与仓库 config 一致): {e}")
})?;
if let Some(agent) = agent {
b.apply_section(agent);
}
Ok(())
}
#[cfg(test)]
pub(super) fn apply_embedded_agent_shard_for_test(
b: &mut ConfigBuilder,
shard_label: &'static str,
toml_src: &'static str,
) -> Result<(), String> {
apply_embedded_agent_shard(b, shard_label, toml_src)
}
pub(super) fn apply_embedded_config_shards(b: &mut ConfigBuilder) -> Result<(), String> {
apply_embedded_agent_shard(b, "default_config.toml", DEFAULT_CONFIG)?;
apply_embedded_agent_shard(b, "session.toml", SESSION_DEFAULT_CONFIG)?;
apply_embedded_agent_shard(b, "context_inject.toml", CONTEXT_INJECT_DEFAULT_CONFIG)?;
let (tools_agent, tools_tr) = parse_tools_config_bundle(TOOLS_DEFAULT_CONFIG)
.map_err(|e| format!("嵌入默认配置 tools.toml TOML 无效(须与仓库 config 一致): {e}"))?;
if let Some(agent) = tools_agent {
b.apply_section(agent);
}
if let Some(tr) = tools_tr {
b.apply_tool_registry(tr);
}
apply_embedded_agent_shard(b, "sandbox.toml", SANDBOX_DEFAULT_CONFIG)?;
apply_embedded_agent_shard(b, "planning.toml", PLANNING_DEFAULT_CONFIG)?;
apply_embedded_agent_shard(b, "memory.toml", MEMORY_DEFAULT_CONFIG)?;
Ok(())
}
pub(super) use super::user_config_layers::merge_user_config_layers;