1use anyhow::Result;
2use serde::{Deserialize, Serialize};
3use std::sync::Arc;
4
5use crate::config::Config;
6use crate::git::GitRepo;
7
8#[derive(Debug, Clone)]
10pub struct AgentBackend {
11 pub provider_name: String,
12 pub model: String,
14 pub fast_model: String,
16}
17
18impl AgentBackend {
19 pub fn new(provider_name: String, model: String, fast_model: String) -> Self {
20 Self {
21 provider_name,
22 model,
23 fast_model,
24 }
25 }
26
27 pub fn from_config(config: &Config) -> Result<Self> {
29 let provider: crate::providers::Provider = config
30 .default_provider
31 .parse()
32 .map_err(|_| anyhow::anyhow!("Invalid provider: {}", config.default_provider))?;
33
34 let provider_config = config
35 .get_provider_config(&config.default_provider)
36 .ok_or_else(|| {
37 anyhow::anyhow!("No configuration for provider: {}", config.default_provider)
38 })?;
39
40 Ok(Self {
41 provider_name: config.default_provider.clone(),
42 model: provider_config.effective_model(provider).to_string(),
43 fast_model: provider_config.effective_fast_model(provider).to_string(),
44 })
45 }
46}
47
48#[derive(Debug, Clone)]
50pub struct AgentContext {
51 pub config: Config,
52 pub git_repo: Arc<GitRepo>,
53}
54
55impl AgentContext {
56 pub fn new(config: Config, git_repo: GitRepo) -> Self {
57 Self {
58 config,
59 git_repo: Arc::new(git_repo),
60 }
61 }
62
63 pub fn repo(&self) -> &GitRepo {
64 &self.git_repo
65 }
66
67 pub fn config(&self) -> &Config {
68 &self.config
69 }
70}
71
72#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct TaskResult {
75 pub success: bool,
76 pub message: String,
77 pub data: Option<serde_json::Value>,
78 pub confidence: f64,
79 pub execution_time: Option<std::time::Duration>,
80}
81
82impl TaskResult {
83 pub fn success(message: String) -> Self {
84 Self {
85 success: true,
86 message,
87 data: None,
88 confidence: 1.0,
89 execution_time: None,
90 }
91 }
92
93 pub fn success_with_data(message: String, data: serde_json::Value) -> Self {
94 Self {
95 success: true,
96 message,
97 data: Some(data),
98 confidence: 1.0,
99 execution_time: None,
100 }
101 }
102
103 pub fn failure(message: String) -> Self {
104 Self {
105 success: false,
106 message,
107 data: None,
108 confidence: 0.0,
109 execution_time: None,
110 }
111 }
112
113 pub fn with_confidence(mut self, confidence: f64) -> Self {
114 self.confidence = confidence;
115 self
116 }
117
118 pub fn with_execution_time(mut self, duration: std::time::Duration) -> Self {
119 self.execution_time = Some(duration);
120 self
121 }
122}