summaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/config.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/config.rs b/src/config.rs
index b781637..a1d7c42 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -8,7 +8,10 @@ pub struct Config {
8 pub base_url: String, 8 pub base_url: String,
9 pub api_key: String, 9 pub api_key: String,
10 pub model: String, 10 pub model: String,
11 /// Session id, sent to the provider as `x-opencode-session`. Filled in once
12 /// the session exists.
11 pub session: String, 13 pub session: String,
14 pub yolo: bool,
12} 15}
13 16
14impl Config { 17impl Config {
@@ -16,7 +19,7 @@ impl Config {
16 pub fn resolve( 19 pub fn resolve(
17 model: Option<String>, 20 model: Option<String>,
18 base_url: Option<String>, 21 base_url: Option<String>,
19 session: Option<String>, 22 yolo: bool,
20 ) -> Result<Config, String> { 23 ) -> Result<Config, String> {
21 Ok(Config { 24 Ok(Config {
22 api_key: api_key()?, 25 api_key: api_key()?,
@@ -26,7 +29,8 @@ impl Config {
26 model: model 29 model: model
27 .or_else(|| env_nonempty("AGENT686_MODEL")) 30 .or_else(|| env_nonempty("AGENT686_MODEL"))
28 .unwrap_or_else(|| DEFAULT_MODEL.to_string()), 31 .unwrap_or_else(|| DEFAULT_MODEL.to_string()),
29 session: session.unwrap_or_else(crate::session::new_id), 32 session: String::new(),
33 yolo,
30 }) 34 })
31 } 35 }
32 36
@@ -40,7 +44,7 @@ fn env_nonempty(key: &str) -> Option<String> {
40} 44}
41 45
42/// The key comes from the environment first, then from a file, so a key never 46/// The key comes from the environment first, then from a file, so a key never
43/// has to live in shell history or in a process listing. 47/// has to live in shell history.
44fn api_key() -> Result<String, String> { 48fn api_key() -> Result<String, String> {
45 if let Some(k) = env_nonempty("OPENCODE_API_KEY") { 49 if let Some(k) = env_nonempty("OPENCODE_API_KEY") {
46 return Ok(k.trim().to_string()); 50 return Ok(k.trim().to_string());