rs_adk/code_executors/
vertex_ai.rs1use async_trait::async_trait;
7
8use super::base::{CodeExecutor, CodeExecutorError};
9use super::types::{CodeExecutionInput, CodeExecutionResult};
10
11#[derive(Debug, Clone)]
13pub struct VertexAiCodeExecutorConfig {
14 pub project: String,
16 pub location: String,
18 pub timeout_secs: u64,
20}
21
22#[derive(Debug, Clone)]
27pub struct VertexAiCodeExecutor {
28 config: VertexAiCodeExecutorConfig,
29}
30
31impl VertexAiCodeExecutor {
32 pub fn new(config: VertexAiCodeExecutorConfig) -> Self {
34 Self { config }
35 }
36
37 pub fn project(&self) -> &str {
39 &self.config.project
40 }
41
42 pub fn location(&self) -> &str {
44 &self.config.location
45 }
46}
47
48#[async_trait]
49impl CodeExecutor for VertexAiCodeExecutor {
50 async fn execute_code(
51 &self,
52 input: CodeExecutionInput,
53 ) -> Result<CodeExecutionResult, CodeExecutorError> {
54 let _ = &input;
59 Ok(CodeExecutionResult {
60 stdout: String::new(),
61 stderr: String::new(),
62 output_files: vec![],
63 })
64 }
65
66 fn stateful(&self) -> bool {
67 true
68 }
69}
70
71#[cfg(test)]
72mod tests {
73 use super::*;
74
75 fn test_config() -> VertexAiCodeExecutorConfig {
76 VertexAiCodeExecutorConfig {
77 project: "test-project".into(),
78 location: "us-central1".into(),
79 timeout_secs: 60,
80 }
81 }
82
83 #[test]
84 fn executor_metadata() {
85 let exec = VertexAiCodeExecutor::new(test_config());
86 assert_eq!(exec.project(), "test-project");
87 assert_eq!(exec.location(), "us-central1");
88 assert!(exec.stateful());
89 }
90
91 #[tokio::test]
92 async fn execute_returns_empty_stub() {
93 let exec = VertexAiCodeExecutor::new(test_config());
94 let input = CodeExecutionInput {
95 code: "print(42)".into(),
96 input_files: vec![],
97 execution_id: None,
98 };
99 let result = exec.execute_code(input).await.unwrap();
100 assert!(result.stdout.is_empty());
101 }
102}