use crate::bigquery::tools::{
BigQueryExecuteSql, BigQueryGetTableSchema, BigQueryListDatasets, BigQueryListTables,
};
use adk_core::{ReadonlyContext, Result, Tool, Toolset};
use async_trait::async_trait;
use std::sync::Arc;
#[derive(Debug, Clone)]
pub enum CredentialSource {
ApplicationDefault,
SecretRef(String),
}
pub struct BigQueryToolset {
pub(crate) project_id: Option<String>,
pub(crate) credentials: CredentialSource,
}
impl BigQueryToolset {
pub fn new() -> Self {
Self { project_id: None, credentials: CredentialSource::ApplicationDefault }
}
pub fn with_project(project_id: impl Into<String>) -> Self {
Self {
project_id: Some(project_id.into()),
credentials: CredentialSource::ApplicationDefault,
}
}
pub fn from_secret(secret_name: impl Into<String>) -> Self {
Self { project_id: None, credentials: CredentialSource::SecretRef(secret_name.into()) }
}
}
impl Default for BigQueryToolset {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl Toolset for BigQueryToolset {
fn name(&self) -> &str {
"bigquery"
}
async fn tools(&self, _ctx: Arc<dyn ReadonlyContext>) -> Result<Vec<Arc<dyn Tool>>> {
let project_id = self.project_id.clone();
let credentials = self.credentials.clone();
Ok(vec![
Arc::new(BigQueryExecuteSql::new(project_id.clone(), credentials.clone())),
Arc::new(BigQueryGetTableSchema::new(project_id.clone(), credentials.clone())),
Arc::new(BigQueryListDatasets::new(project_id.clone(), credentials.clone())),
Arc::new(BigQueryListTables::new(project_id, credentials)),
])
}
}