adk_tool/spanner/
toolset.rs1use crate::spanner::tools::{SpannerExecuteSql, SpannerGetTableSchema, SpannerListTables};
4use adk_core::{ReadonlyContext, Result, Tool, Toolset};
5use async_trait::async_trait;
6use std::sync::Arc;
7
8#[derive(Debug, Clone)]
10pub enum CredentialSource {
11 ApplicationDefault,
13 SecretRef(String),
15}
16
17pub struct SpannerToolset {
41 pub(crate) project_id: String,
42 pub(crate) instance_id: String,
43 pub(crate) database_id: String,
44 pub(crate) credentials: CredentialSource,
45}
46
47impl SpannerToolset {
48 pub fn new(
53 project_id: impl Into<String>,
54 instance_id: impl Into<String>,
55 database_id: impl Into<String>,
56 ) -> Self {
57 Self {
58 project_id: project_id.into(),
59 instance_id: instance_id.into(),
60 database_id: database_id.into(),
61 credentials: CredentialSource::ApplicationDefault,
62 }
63 }
64
65 pub fn from_secret(
68 project_id: impl Into<String>,
69 instance_id: impl Into<String>,
70 database_id: impl Into<String>,
71 secret_name: impl Into<String>,
72 ) -> Self {
73 Self {
74 project_id: project_id.into(),
75 instance_id: instance_id.into(),
76 database_id: database_id.into(),
77 credentials: CredentialSource::SecretRef(secret_name.into()),
78 }
79 }
80}
81
82#[async_trait]
83impl Toolset for SpannerToolset {
84 fn name(&self) -> &str {
85 "spanner"
86 }
87
88 async fn tools(&self, _ctx: Arc<dyn ReadonlyContext>) -> Result<Vec<Arc<dyn Tool>>> {
89 let project_id = self.project_id.clone();
90 let instance_id = self.instance_id.clone();
91 let database_id = self.database_id.clone();
92 let credentials = self.credentials.clone();
93
94 Ok(vec![
95 Arc::new(SpannerExecuteSql::new(
96 project_id.clone(),
97 instance_id.clone(),
98 database_id.clone(),
99 credentials.clone(),
100 )),
101 Arc::new(SpannerGetTableSchema::new(
102 project_id.clone(),
103 instance_id.clone(),
104 database_id.clone(),
105 credentials.clone(),
106 )),
107 Arc::new(SpannerListTables::new(project_id, instance_id, database_id, credentials)),
108 ])
109 }
110}