@@ -34,6 +34,7 @@ use crate::utils::sanitize_unicode_tags;
3434use anyhow:: Result ;
3535use fs_err as fs;
3636use futures:: future:: { BoxFuture , Either } ;
37+ use futures:: stream:: { self , StreamExt } ;
3738use futures:: FutureExt ;
3839use goose_acp_macros:: custom_methods;
3940use rmcp:: model:: {
@@ -119,6 +120,7 @@ const ELEVENLABS_TRANSCRIPTION_MODEL_CONFIG_KEY: &str = "ELEVENLABS_TRANSCRIPTIO
119120const OPENAI_TRANSCRIPTION_MODEL : & str = "whisper-1" ;
120121const GROQ_TRANSCRIPTION_MODEL : & str = "whisper-large-v3-turbo" ;
121122const ELEVENLABS_TRANSCRIPTION_MODEL : & str = "scribe_v1" ;
123+ const PROVIDER_CONFIG_STATUS_CHECK_CONCURRENCY : usize = 16 ;
122124
123125async fn ensure_refresh_identity_current (
124126 provider_id : & str ,
@@ -2473,8 +2475,6 @@ impl GooseAcpAgent {
24732475 . await
24742476 . internal_err_ctx ( "Error getting agent reply" ) ?;
24752477
2476- use futures:: StreamExt ;
2477-
24782478 let mut was_cancelled = false ;
24792479 let mut first_event_logged = false ;
24802480 let mut event_count: u32 = 0 ;
@@ -3165,21 +3165,31 @@ impl GooseAcpAgent {
31653165 } )
31663166 }
31673167
3168- async fn provider_config_status ( & self , provider_id : & str ) -> ProviderConfigStatusDto {
3169- let is_configured = crate :: providers:: get_from_registry ( provider_id)
3170- . await
3171- . map ( |entry| entry. inventory_configured ( ) )
3172- . unwrap_or ( false ) ;
3168+ async fn provider_config_status ( provider_id : String ) -> ProviderConfigStatusDto {
3169+ let is_configured = match crate :: providers:: get_from_registry ( & provider_id) . await {
3170+ Ok ( entry) => {
3171+ match tokio:: task:: spawn_blocking ( move || entry. inventory_configured ( ) ) . await {
3172+ Ok ( is_configured) => is_configured,
3173+ Err ( error) => {
3174+ warn ! (
3175+ provider = %provider_id,
3176+ error = %error,
3177+ "provider config status check failed"
3178+ ) ;
3179+ false
3180+ }
3181+ }
3182+ }
3183+ Err ( _) => false ,
3184+ } ;
3185+
31733186 ProviderConfigStatusDto {
3174- provider_id : provider_id . to_string ( ) ,
3187+ provider_id,
31753188 is_configured,
31763189 }
31773190 }
31783191
3179- async fn provider_config_statuses (
3180- & self ,
3181- provider_ids : & [ String ] ,
3182- ) -> Vec < ProviderConfigStatusDto > {
3192+ async fn provider_config_statuses ( provider_ids : & [ String ] ) -> Vec < ProviderConfigStatusDto > {
31833193 let mut ids = if provider_ids. is_empty ( ) {
31843194 crate :: providers:: providers ( )
31853195 . await
@@ -3192,10 +3202,12 @@ impl GooseAcpAgent {
31923202 ids. sort ( ) ;
31933203 ids. dedup ( ) ;
31943204
3195- let mut statuses = Vec :: with_capacity ( ids. len ( ) ) ;
3196- for provider_id in ids {
3197- statuses. push ( self . provider_config_status ( & provider_id) . await ) ;
3198- }
3205+ let mut statuses = stream:: iter ( ids)
3206+ . map ( Self :: provider_config_status)
3207+ . buffer_unordered ( PROVIDER_CONFIG_STATUS_CHECK_CONCURRENCY )
3208+ . collect :: < Vec < _ > > ( )
3209+ . await ;
3210+ statuses. sort_by ( |a, b| a. provider_id . cmp ( & b. provider_id ) ) ;
31993211 statuses
32003212 }
32013213
@@ -3323,7 +3335,7 @@ impl GooseAcpAgent {
33233335 req : ProviderConfigStatusRequest ,
33243336 ) -> Result < ProviderConfigStatusResponse , sacp:: Error > {
33253337 Ok ( ProviderConfigStatusResponse {
3326- statuses : self . provider_config_statuses ( & req. provider_ids ) . await ,
3338+ statuses : Self :: provider_config_statuses ( & req. provider_ids ) . await ,
33273339 } )
33283340 }
33293341
@@ -3379,7 +3391,7 @@ impl GooseAcpAgent {
33793391 Config :: global ( ) . invalidate_secrets_cache ( ) ;
33803392
33813393 let provider_ids = [ req. provider_id . clone ( ) ] ;
3382- let status = self . provider_config_status ( & req. provider_id ) . await ;
3394+ let status = Self :: provider_config_status ( req. provider_id . clone ( ) ) . await ;
33833395 let refresh = self . start_provider_inventory_refresh ( & provider_ids) . await ?;
33843396 Ok ( ProviderConfigChangeResponse { status, refresh } )
33853397 }
@@ -3415,7 +3427,7 @@ impl GooseAcpAgent {
34153427 Config :: global ( ) . invalidate_secrets_cache ( ) ;
34163428
34173429 let provider_ids = [ req. provider_id . clone ( ) ] ;
3418- let status = self . provider_config_status ( & req. provider_id ) . await ;
3430+ let status = Self :: provider_config_status ( req. provider_id . clone ( ) ) . await ;
34193431 let refresh = self . start_provider_inventory_refresh ( & provider_ids) . await ?;
34203432 Ok ( ProviderConfigChangeResponse { status, refresh } )
34213433 }
0 commit comments