(&self)
| 70 | } |
| 71 | |
| 72 | fn discover_existing(&self) -> Result<Option<DiscoveredProvider>, ProviderError> { |
| 73 | let mut discovered = discover_with_spec(&SPEC, &RealDiscoveryContext)?.unwrap_or_default(); |
| 74 | |
| 75 | // Supplement env-var discovery with credentials stored in the opencode config file. |
| 76 | // opencode's native config lives at $XDG_CONFIG_HOME/opencode/opencode.json and stores |
| 77 | // API keys under `provider.<name>.options.apiKey`. If the user configured opencode |
| 78 | // normally (i.e. no env vars set), this is the only place the keys exist. |
| 79 | if let Some(path) = opencode_config_path() |
| 80 | && let Some(file_creds) = read_opencode_config_file(&path) |
| 81 | { |
| 82 | for (key, value) in file_creds { |
| 83 | // Env vars already set take priority; config file fills the gaps. |
| 84 | discovered.credentials.entry(key).or_insert(value); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if discovered.is_empty() { |
| 89 | Ok(None) |
| 90 | } else { |
| 91 | Ok(Some(discovered)) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | fn credential_env_vars(&self) -> &'static [&'static str] { |
| 96 | SPEC.credential_env_vars |
nothing calls this directly
no test coverage detected