MCPcopy Create free account
hub / github.com/GCWing/BitFun / delete_custom_agent

Function delete_custom_agent

src/apps/desktop/src/api/custom_agent_api.rs:350–427  ·  view source on GitHub ↗
(
    state: State<'_, AppState>,
    request: DeleteCustomAgentRequest,
)

Source from the content-addressed store, hash-verified

348
349#[tauri::command]
350pub async fn delete_custom_agent(
351 state: State<'_, AppState>,
352 request: DeleteCustomAgentRequest,
353) -> Result<(), String> {
354 let agent_id = request.agent_id;
355
356 if let Some(path) = state
357 .agent_registry
358 .remove_custom_agent(&agent_id)
359 .map_err(|error| error.to_string())?
360 {
361 if let Err(error) = std::fs::remove_file(&path) {
362 warn!(
363 "Failed to delete custom agent file: path={}, error={}",
364 path, error
365 );
366 }
367 }
368
369 let config_service = &state.config_service;
370
371 let mut agent_models: HashMap<String, String> = config_service
372 .get_config(Some("ai.agent_models"))
373 .await
374 .unwrap_or_default();
375 if agent_models.remove(&agent_id).is_some() {
376 if let Err(error) = config_service
377 .set_config("ai.agent_models", &agent_models)
378 .await
379 {
380 warn!(
381 "Failed to clean up ai.agent_models after custom agent deletion: agent_id={}, error={}",
382 agent_id, error
383 );
384 }
385 }
386
387 let mut agent_profiles: serde_json::Map<String, serde_json::Value> = config_service
388 .get_config(Some("ai.agent_profiles"))
389 .await
390 .unwrap_or_default();
391 if agent_profiles.remove(&agent_id).is_some() {
392 if let Err(error) = config_service
393 .set_config("ai.agent_profiles", &agent_profiles)
394 .await
395 {
396 warn!(
397 "Failed to clean up ai.agent_profiles after custom agent deletion: agent_id={}, error={}",
398 agent_id, error
399 );
400 }
401 }
402
403 let default_mode_id: Option<String> = config_service
404 .get_config(Some("app.flow_chat.default_mode_id"))
405 .await
406 .unwrap_or_default();
407 if default_mode_id.as_deref() == Some(agent_id.as_str()) {

Callers

nothing calls this directly

Calls 6

remove_custom_agentMethod · 0.80
set_configMethod · 0.80
reload_global_configFunction · 0.70
get_configMethod · 0.45
removeMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected