Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/apps/desktop/src/api/config_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ pub async fn set_config(
.await
{
Ok(_) => {
if let Err(e) = bitfun_core::service::config::reload_global_config().await {
warn!(
"Failed to sync global config after set_config: path={}, error={}",
request.path, e
);
} else {
info!(
"Global config synced after set_config: path={}",
request.path
);
}

if request.path.starts_with("ai.models")
|| request.path.starts_with("ai.default_models")
|| request.path.starts_with("ai.agent_models")
Expand Down Expand Up @@ -90,6 +102,18 @@ pub async fn reset_config(

match config_service.reset_config(request.path.as_deref()).await {
Ok(_) => {
if let Err(e) = bitfun_core::service::config::reload_global_config().await {
warn!(
"Failed to sync global config after reset_config: path={:?}, error={}",
request.path, e
);
} else {
info!(
"Global config synced after reset_config: path={:?}",
request.path
);
}

let message = if let Some(path) = &request.path {
format!("Configuration '{}' reset successfully", path)
} else {
Expand Down Expand Up @@ -142,6 +166,11 @@ pub async fn import_config(state: State<'_, AppState>, config: Value) -> Result<

match config_service.import_config(export_data).await {
Ok(result) => {
if let Err(e) = bitfun_core::service::config::reload_global_config().await {
warn!("Failed to sync global config after import_config: {}", e);
} else {
info!("Global config synced after import_config");
}
state.ai_client_factory.invalidate_cache();
info!("Config imported, AI client cache invalidated");
Ok(to_json_value(result, "import config result")?)
Expand Down
47 changes: 30 additions & 17 deletions src/crates/core/src/agentic/execution/execution_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,13 @@ impl ExecutionEngine {
ai_config: &crate::service::config::types::AIConfig,
model_id: &str,
) -> String {
let trimmed = model_id.trim();
if trimmed.is_empty() || trimmed == "auto" || trimmed == "default" {
return "auto".to_string();
}
ai_config
.resolve_model_selection(model_id)
.unwrap_or_else(|| model_id.to_string())
.resolve_model_selection(trimmed)
.unwrap_or_else(|| "auto".to_string())
}

fn resolve_locked_auto_model_id(
Expand Down Expand Up @@ -167,23 +171,32 @@ impl ExecutionEngine {
turn_index: usize,
) -> BitFunResult<String> {
let agent_registry = get_agent_registry();
let configured_model_id = agent_registry
let fallback_model_id = agent_registry
.get_model_id_for_agent(agent_type, workspace.map(|binding| binding.root_path()))
.await
.map_err(|e| BitFunError::AIClient(format!("Failed to get model ID: {}", e)))?;

let model_id = if configured_model_id == "auto" {
let config_service = get_global_config_service().await.map_err(|e| {
BitFunError::AIClient(format!(
"Failed to get config service for auto model resolution: {}",
e
))
})?;
let ai_config: crate::service::config::types::AIConfig = config_service
.get_config(Some("ai"))
.await
.unwrap_or_default();

let config_service = get_global_config_service().await.map_err(|e| {
BitFunError::AIClient(format!(
"Failed to get config service for model resolution: {}",
e
))
})?;
let ai_config: crate::service::config::types::AIConfig = config_service
.get_config(Some("ai"))
.await
.unwrap_or_default();
let configured_model_id = session
.config
.model_id
.as_ref()
.map(|model_id| model_id.trim())
.filter(|model_id| !model_id.is_empty())
.map(str::to_string)
.unwrap_or(fallback_model_id);
let resolved_configured_model_id =
Self::resolve_configured_model_id(&ai_config, &configured_model_id);

let model_id = if configured_model_id == "auto" || resolved_configured_model_id == "auto" {
let locked_model_id =
Self::resolve_locked_auto_model_id(&ai_config, session.config.model_id.as_ref());
let raw_locked_model_id = session.config.model_id.clone();
Expand Down Expand Up @@ -230,7 +243,7 @@ impl ExecutionEngine {
}
}
} else {
configured_model_id
resolved_configured_model_id
};

Ok(model_id)
Expand Down
Loading
Loading