@@ -6,12 +6,12 @@ use tauri::{AppHandle, State};
66use crate :: {
77 app_state:: AppState ,
88 managed_agents:: {
9- build_managed_agent_summary , default_agent_workdir , find_managed_agent_mut ,
10- known_acp_runtime, load_managed_agents, load_personas, managed_agent_avatar_url ,
11- missing_command_message, normalize_agent_args, resolve_command,
12- resolve_effective_prompt_model_provider, save_managed_agents , sync_managed_agent_processes ,
13- try_regenerate_nest, AgentModelInfo , AgentModelsResponse , UpdateManagedAgentRequest ,
14- UpdateManagedAgentResponse ,
9+ build_databricks_defaults , build_managed_agent_summary , default_agent_workdir ,
10+ find_managed_agent_mut , known_acp_runtime, load_managed_agents, load_personas,
11+ managed_agent_avatar_url , missing_command_message, normalize_agent_args, resolve_command,
12+ resolve_effective_prompt_model_provider, runtime_metadata_env_vars , save_managed_agents ,
13+ sync_managed_agent_processes , try_regenerate_nest, AgentModelInfo , AgentModelsResponse ,
14+ UpdateManagedAgentRequest , UpdateManagedAgentResponse ,
1515 } ,
1616 relay:: { relay_ws_url_with_override, sync_managed_agent_profile} ,
1717 util:: now_iso,
@@ -27,7 +27,16 @@ pub async fn get_agent_models(
2727 app : AppHandle ,
2828 state : State < ' _ , AppState > ,
2929) -> Result < AgentModelsResponse , String > {
30- let ( resolved_acp, agent_command, agent_args, persisted_model, merged_env) = {
30+ let (
31+ resolved_acp,
32+ agent_command,
33+ agent_args,
34+ persisted_model,
35+ runtime_default_env,
36+ runtime_metadata_env,
37+ databricks_defaults,
38+ merged_env,
39+ ) = {
3140 let _store_guard = state
3241 . managed_agents_store_lock
3342 . lock ( )
@@ -75,14 +84,51 @@ pub async fn get_agent_models(
7584
7685 // Resolve the effective model from the linked persona so the ModelPicker
7786 // dropdown shows the current persona model as selected.
78- let ( _prompt, effective_model, _provider) = resolve_effective_prompt_model_provider (
79- record. persona_id . as_deref ( ) ,
80- & personas,
81- record. system_prompt . clone ( ) ,
82- record. model . clone ( ) ,
83- ) ;
84-
85- ( resolved, resolved_agent, args, effective_model, env)
87+ let ( _prompt, effective_model, effective_provider) =
88+ resolve_effective_prompt_model_provider (
89+ record. persona_id . as_deref ( ) ,
90+ & personas,
91+ record. system_prompt . clone ( ) ,
92+ record. model . clone ( ) ,
93+ ) ;
94+ let runtime = known_acp_runtime ( & record. agent_command ) ;
95+ let runtime_default_env: Vec < ( String , String ) > = runtime
96+ . map ( |meta| {
97+ meta. default_env
98+ . iter ( )
99+ . map ( |( key, value) | ( ( * key) . to_string ( ) , ( * value) . to_string ( ) ) )
100+ . collect ( )
101+ } )
102+ . unwrap_or_default ( ) ;
103+ let runtime_metadata_env: Vec < ( String , String ) > = runtime
104+ . map ( |meta| {
105+ runtime_metadata_env_vars (
106+ meta. model_env_var ,
107+ meta. provider_env_var ,
108+ meta. provider_locked ,
109+ effective_model. as_deref ( ) ,
110+ effective_provider. as_deref ( ) ,
111+ )
112+ . into_iter ( )
113+ . map ( |( key, value) | ( key. to_string ( ) , value. to_string ( ) ) )
114+ . collect ( )
115+ } )
116+ . unwrap_or_default ( ) ;
117+ let databricks_defaults: Vec < ( String , String ) > = build_databricks_defaults ( )
118+ . into_iter ( )
119+ . map ( |( key, value) | ( key. to_string ( ) , value. to_string ( ) ) )
120+ . collect ( ) ;
121+
122+ (
123+ resolved,
124+ resolved_agent,
125+ args,
126+ effective_model,
127+ runtime_default_env,
128+ runtime_metadata_env,
129+ databricks_defaults,
130+ env,
131+ )
86132 } ; // store lock released — subprocess runs without holding the lock
87133
88134 // Clone the env map for redaction below — `merged_env` is moved
@@ -105,13 +151,17 @@ pub async fn get_agent_models(
105151 . arg ( "--json" )
106152 . env ( "BUZZ_ACP_AGENT_COMMAND" , & agent_command)
107153 . env ( "BUZZ_ACP_AGENT_ARGS" , agent_args. join ( "," ) ) ;
108- if let Some ( meta) = known_acp_runtime ( & agent_command) {
109- for ( key, value) in meta. default_env {
110- if std:: env:: var ( key) . is_err ( ) {
111- cmd. env ( key, value) ;
112- }
154+ for ( key, value) in & runtime_default_env {
155+ if std:: env:: var ( key) . is_err ( ) {
156+ cmd. env ( key, value) ;
113157 }
114158 }
159+ for ( key, value) in & runtime_metadata_env {
160+ cmd. env ( key, value) ;
161+ }
162+ for ( key, value) in & databricks_defaults {
163+ cmd. env ( key, value) ;
164+ }
115165 // User env layering — written LAST so it overrides any Buzz-set env above.
116166 for ( k, v) in & merged_env {
117167 cmd. env ( k, v) ;
@@ -132,6 +182,12 @@ pub async fn get_agent_models(
132182 // a failing child process echoed back.
133183 let stderr_redacted =
134184 crate :: managed_agents:: redact_env_values_in ( stderr. as_ref ( ) , & env_for_redaction) ;
185+ if let Some ( configuration_error) = model_configuration_error ( & stderr_redacted) {
186+ return Ok ( unavailable_agent_models (
187+ persisted_model,
188+ configuration_error,
189+ ) ) ;
190+ }
135191 return Err ( format ! (
136192 "buzz-acp models failed (exit {}): {stderr_redacted}" ,
137193 output. status. code( ) . unwrap_or( -1 )
@@ -413,5 +469,53 @@ fn normalize_agent_models(
413469 agent_default_model,
414470 selected_model : persisted_model,
415471 supports_switching,
472+ configuration_error : None ,
473+ }
474+ }
475+
476+ fn unavailable_agent_models (
477+ persisted_model : Option < String > ,
478+ configuration_error : String ,
479+ ) -> AgentModelsResponse {
480+ AgentModelsResponse {
481+ agent_name : "unknown" . to_string ( ) ,
482+ agent_version : "unknown" . to_string ( ) ,
483+ models : Vec :: new ( ) ,
484+ agent_default_model : None ,
485+ selected_model : persisted_model,
486+ supports_switching : false ,
487+ configuration_error : Some ( configuration_error) ,
488+ }
489+ }
490+
491+ fn model_configuration_error ( stderr : & str ) -> Option < String > {
492+ let normalized = stderr. to_ascii_lowercase ( ) ;
493+
494+ if normalized. contains ( "buzz_agent_provider required" ) {
495+ return Some (
496+ "This agent does not have an LLM provider configured. Set a provider and model on the persona or agent, then retry."
497+ . to_string ( ) ,
498+ ) ;
416499 }
500+
501+ if normalized. contains ( "anthropic_model required" )
502+ || normalized. contains ( "openai_compat_model required" )
503+ || normalized. contains ( "databricks_model required" )
504+ {
505+ return Some (
506+ "This agent does not have an LLM model configured. Set a model on the persona or agent, then retry."
507+ . to_string ( ) ,
508+ ) ;
509+ }
510+
511+ if normalized. contains ( "anthropic_api_key required" )
512+ || normalized. contains ( "openai_compat_api_key required" )
513+ {
514+ return Some (
515+ "This agent is missing credentials for its configured LLM provider. Add the provider credentials, then retry."
516+ . to_string ( ) ,
517+ ) ;
518+ }
519+
520+ None
417521}
0 commit comments