Skip to main content

sr_ai/ai/
mod.rs

1// Re-export agentspec-provider types under the names sr uses internally.
2pub use agentspec_provider::{
3    AiEvent, AiProvider as AiBackend, AiRequest, AiResponse, AiUsage, Capability,
4    LocalBackend as Backend, ProviderConfig, Sandbox, resolve_local_provider,
5};
6
7/// CLI-facing config — maps to ProviderConfig with sr's read-only sandbox.
8pub struct BackendConfig {
9    pub backend: Option<Backend>,
10    pub model: Option<String>,
11    pub budget: f64,
12    pub debug: bool,
13}
14
15impl BackendConfig {
16    /// Convert to agentspec-provider's ProviderConfig with sr's read-only sandbox.
17    pub fn to_provider_config(&self) -> ProviderConfig {
18        ProviderConfig {
19            backend: self.backend,
20            model: self.model.clone(),
21            budget: Some(self.budget),
22            sandbox: Some(Sandbox {
23                allowed: vec![Capability::GitReadOnly, Capability::ReadFile],
24                denied: vec![
25                    Capability::WriteFile,
26                    Capability::ShellCommand {
27                        pattern: ".*".into(),
28                    },
29                ],
30            }),
31            debug: self.debug,
32        }
33    }
34}
35
36pub async fn resolve_backend(config: &BackendConfig) -> anyhow::Result<Box<dyn AiBackend>> {
37    resolve_local_provider(config.to_provider_config()).await
38}