use super::types::{CodeExecutionInput, CodeExecutionResult};
use async_trait::async_trait;
#[derive(Debug, thiserror::Error)]
pub enum CodeExecutorError {
#[error("Code execution failed: {0}")]
ExecutionFailed(String),
#[error("Unsupported model: {0}")]
UnsupportedModel(String),
#[error("Execution timed out after {0}s")]
Timeout(u64),
#[error("{0}")]
Other(String),
}
#[async_trait]
pub trait CodeExecutor: Send + Sync {
fn code_block_delimiters(&self) -> Vec<(String, String)> {
vec![
("```tool_code\n".into(), "\n```".into()),
("```python\n".into(), "\n```".into()),
]
}
fn execution_result_delimiters(&self) -> (String, String) {
("```tool_output\n".into(), "\n```".into())
}
fn error_retry_attempts(&self) -> u32 {
2
}
fn stateful(&self) -> bool {
false
}
async fn execute_code(
&self,
input: CodeExecutionInput,
) -> Result<CodeExecutionResult, CodeExecutorError>;
}