Skip to main content

google_tool/
runtime.rs

1//! Runtime dependencies for user-scoped Google Calendar tools.
2
3use std::sync::Arc;
4
5use agent_service::GoogleCalendarAccessService;
6use agent_storage::ExternalConnectionId;
7
8use crate::{GoogleOAuthConfig, GoogleOAuthError, GoogleOAuthTokenManager};
9
10/// Server-composed configuration for Google Calendar tool execution.
11///
12/// Contains secrets and trusted services; never serialize this value or expose
13/// it to the model.
14#[derive(Clone)]
15pub struct GoogleCalendarRuntimeConfig {
16    pub(crate) oauth: GoogleOAuthConfig,
17    pub(crate) access: Arc<GoogleCalendarAccessService>,
18    token_manager: Arc<GoogleOAuthTokenManager>,
19}
20
21impl GoogleCalendarRuntimeConfig {
22    pub fn new(
23        oauth: GoogleOAuthConfig,
24        access: Arc<GoogleCalendarAccessService>,
25        token_manager: Arc<GoogleOAuthTokenManager>,
26    ) -> Self {
27        Self {
28            oauth,
29            access,
30            token_manager,
31        }
32    }
33
34    /// Refresh credentials through the shared per-connection coordinator.
35    pub(crate) async fn refresh_access_token(
36        &self,
37        connection_id: ExternalConnectionId,
38        refresh_token: &str,
39    ) -> Result<String, GoogleOAuthError> {
40        self.token_manager
41            .refresh_access_token(connection_id, &self.oauth, refresh_token)
42            .await
43    }
44}