adk_model/opencode/
config.rs1use super::OpenCodeService;
2use crate::anthropic::{Effort, ThinkingMode};
3use crate::gemini::ThinkingConfig;
4use crate::openai::OpenAIReasoningEffort;
5use crate::retry::RetryConfig;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9#[non_exhaustive]
10pub enum OpenCodeApi {
11 ChatCompletions,
13 Responses,
15 Messages,
17 GenerateContent,
19}
20
21#[derive(Clone)]
36pub struct OpenCodeConfig {
37 pub(super) service: OpenCodeService,
38 pub(super) gemini_thinking: Option<ThinkingConfig>,
39 pub(super) api_key: String,
40 pub(super) model: String,
41 pub(super) base_url: String,
42 pub(super) api: Option<OpenCodeApi>,
43 pub(super) user_agent: String,
44 pub(super) session_id: String,
45 pub(super) reasoning_effort: Option<OpenAIReasoningEffort>,
46 pub(super) thinking: Option<ThinkingMode>,
47 pub(super) anthropic_effort: Option<Effort>,
48 pub(super) retry: RetryConfig,
49 pub(super) timeouts: Option<crate::HttpTimeouts>,
50}
51
52impl std::fmt::Debug for OpenCodeConfig {
53 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54 f.debug_struct("OpenCodeConfig")
55 .field("service", &self.service)
56 .field("model", &self.model)
57 .field("api", &self.api)
58 .finish_non_exhaustive()
59 }
60}
61
62impl OpenCodeConfig {
63 pub fn new(
65 service: OpenCodeService,
66 api_key: impl Into<String>,
67 model: impl Into<String>,
68 ) -> Self {
69 Self {
70 service,
71 gemini_thinking: None,
72 api_key: api_key.into(),
73 model: model.into(),
74 base_url: service.base_url().into(),
75 api: None,
76 user_agent: String::new(),
77 session_id: String::new(),
78 reasoning_effort: None,
79 thinking: None,
80 anthropic_effort: None,
81 retry: RetryConfig::default(),
82 timeouts: None,
83 }
84 }
85
86 pub fn with_api(mut self, api: OpenCodeApi) -> Self {
88 self.api = Some(api);
89 self
90 }
91
92 pub fn with_base_url(mut self, base_url: impl Into<String>) -> Self {
94 self.base_url = base_url.into();
95 self
96 }
97
98 pub fn with_user_agent(mut self, user_agent: impl Into<String>) -> Self {
100 self.user_agent = user_agent.into();
101 self
102 }
103
104 pub fn with_session_id(mut self, session_id: impl Into<String>) -> Self {
106 self.session_id = session_id.into();
107 self
108 }
109
110 pub fn with_reasoning_effort(mut self, effort: OpenAIReasoningEffort) -> Self {
114 self.reasoning_effort = Some(effort);
115 self
116 }
117
118 pub fn with_anthropic_thinking(mut self, thinking: ThinkingMode) -> Self {
120 self.thinking = Some(thinking);
121 self
122 }
123
124 pub fn with_anthropic_effort(mut self, effort: Effort) -> Self {
126 self.anthropic_effort = Some(effort);
127 self
128 }
129
130 pub fn with_gemini_thinking(mut self, thinking: ThinkingConfig) -> Self {
132 self.gemini_thinking = Some(thinking);
133 self
134 }
135
136 pub fn with_timeouts(mut self, timeouts: crate::HttpTimeouts) -> Self {
148 self.timeouts = Some(timeouts);
149 self
150 }
151
152 pub fn with_retry_config(mut self, retry: RetryConfig) -> Self {
154 self.retry = retry;
155 self
156 }
157}