MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / discover_existing

Method discover_existing

crates/openshell-providers/src/providers/opencode.rs:72–93  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

discover_with_specFunction · 0.85
opencode_config_pathFunction · 0.85
is_emptyMethod · 0.45

Tested by

no test coverage detected