(
state: State<'_, AppState>,
request: UpdateSubagentConfigRequest,
)
| 414 | |
| 415 | #[tauri::command] |
| 416 | pub async fn update_subagent_config( |
| 417 | state: State<'_, AppState>, |
| 418 | request: UpdateSubagentConfigRequest, |
| 419 | ) -> Result<UpdateSubagentConfigResponse, String> { |
| 420 | let subagent_id = &request.subagent_id; |
| 421 | let workspace = workspace_root_from_request(request.workspace_path.as_deref()); |
| 422 | if let Some(workspace) = workspace.as_deref() { |
| 423 | state.agent_registry.load_custom_subagents(workspace).await; |
| 424 | } |
| 425 | |
| 426 | let mut availability_updated = false; |
| 427 | let mut model_updated = false; |
| 428 | |
| 429 | if let Some(enabled) = request.enabled { |
| 430 | let parent_agent_type = request.parent_agent_type.as_deref().ok_or_else(|| { |
| 431 | "parentAgentType is required when updating subagent availability".to_string() |
| 432 | })?; |
| 433 | state |
| 434 | .agent_registry |
| 435 | .update_subagent_override( |
| 436 | parent_agent_type, |
| 437 | subagent_id, |
| 438 | enabled, |
| 439 | workspace.as_deref(), |
| 440 | ) |
| 441 | .await |
| 442 | .map_err(|e| format!("Failed to update subagent availability: {}", e))?; |
| 443 | availability_updated = true; |
| 444 | } |
| 445 | |
| 446 | if state |
| 447 | .agent_registry |
| 448 | .get_custom_subagent_config(subagent_id, workspace.as_deref()) |
| 449 | .is_some() |
| 450 | { |
| 451 | if request.model.is_some() { |
| 452 | state |
| 453 | .agent_registry |
| 454 | .update_and_save_custom_subagent_config( |
| 455 | subagent_id, |
| 456 | request.model, |
| 457 | workspace.as_deref(), |
| 458 | ) |
| 459 | .map_err(|e| format!("Failed to update configuration: {}", e))?; |
| 460 | model_updated = true; |
| 461 | } |
| 462 | Ok(UpdateSubagentConfigResponse { |
| 463 | availability_updated, |
| 464 | model_updated, |
| 465 | }) |
| 466 | } else { |
| 467 | if state |
| 468 | .agent_registry |
| 469 | .has_project_custom_subagent(subagent_id) |
| 470 | { |
| 471 | if let Some(workspace) = workspace.as_deref() { |
| 472 | return Err(format!( |
| 473 | "Project Sub-Agent '{}' was not found in workspace '{}'", |
nothing calls this directly
no test coverage detected