Files
imeai-aKode/akode-rs/app-server/src/gateway_oauth_notifications.rs
andrea.difonzo 7c1c6dfa8d Rinomina: crate akode-*, cartelle akode-rs/ e akode-cli/, binario akode, ~/.akode, AKODE_* (A)
Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
  nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 12:37:52 +01:00

69 lines
2.7 KiB
Rust

//! Forward OAuth progress for every configured provider sharing the changed grant.
use crate::config_manager::ConfigManager;
use crate::outgoing_message::OutgoingMessageSender;
use akode_app_server_protocol::GatewayOAuthChangedNotification;
use akode_app_server_protocol::GatewayOAuthStatus;
use akode_app_server_protocol::ServerNotification;
use akode_login::AuthManager;
use akode_login::GatewayAuthStatus;
use std::sync::Arc;
use tokio::sync::broadcast::error::RecvError;
use tokio_util::task::AbortOnDropHandle;
pub(crate) fn status_fields(status: GatewayAuthStatus) -> (GatewayOAuthStatus, Option<String>) {
match status {
GatewayAuthStatus::NotReady => (GatewayOAuthStatus::NotReady, None),
GatewayAuthStatus::Started => (GatewayOAuthStatus::Started, None),
GatewayAuthStatus::Succeeded => (GatewayOAuthStatus::Succeeded, None),
GatewayAuthStatus::Failed { message } => (GatewayOAuthStatus::Failed, Some(message)),
}
}
pub(crate) fn spawn(
auth_manager: Arc<AuthManager>,
config_manager: ConfigManager,
outgoing: Arc<OutgoingMessageSender>,
) -> AbortOnDropHandle<()> {
let mut events = akode_login::subscribe_gateway_auth_status(&auth_manager.runtime_config());
AbortOnDropHandle::new(tokio::spawn(async move {
loop {
let change = match events.recv().await {
Ok(change) => change,
Err(RecvError::Lagged(_)) => continue,
Err(RecvError::Closed) => break,
};
let Ok(config) = config_manager
.load_latest_config(/*fallback_cwd*/ None)
.await
else {
continue;
};
for (provider_id, provider) in &config.model_providers {
let Ok(Some(manager)) = akode_model_provider::create_model_provider(
provider.clone(),
Some(Arc::clone(&auth_manager)),
)
.gateway_auth_manager() else {
continue;
};
if !matches!(manager.oauth_session(), Some(oauth) if oauth.config() == &change.config)
{
continue;
}
let (status, error) = status_fields(change.status.clone());
outgoing
.send_server_notification(ServerNotification::GatewayOAuthChanged(
GatewayOAuthChangedNotification {
auth_url: None,
provider_id: provider_id.clone(),
status,
error,
},
))
.await;
}
}
}))
}