MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / init

Method init

crates/opencode-provider/src/bootstrap.rs:1234–1516  ·  view source on GitHub ↗

Initialize the provider bootstrap state from models.dev data and config. This is the Rust equivalent of the TS `state()` function.

(
        models_dev: &ModelsData,
        config: &BootstrapConfig,
        auth_store: &HashMap<String, AuthInfo>,
    )

Source from the content-addressed store, hash-verified

1232 /// Initialize the provider bootstrap state from models.dev data and config.
1233 /// This is the Rust equivalent of the TS `state()` function.
1234 pub fn init(
1235 models_dev: &ModelsData,
1236 config: &BootstrapConfig,
1237 auth_store: &HashMap<String, AuthInfo>,
1238 ) -> Self {
1239 let mut database: HashMap<String, ProviderState> = models_dev
1240 .iter()
1241 .map(|(id, p)| (id.clone(), from_models_dev_provider(p)))
1242 .collect();
1243
1244 let disabled = &config.disabled_providers;
1245 let enabled = &config.enabled_providers;
1246
1247 let mut providers: HashMap<String, ProviderState> = HashMap::new();
1248 let mut model_loaders: HashSet<String> = HashSet::new();
1249
1250 // Add GitHub Copilot Enterprise provider that inherits from GitHub Copilot
1251 if let Some(github_copilot) = database.get("github-copilot").cloned() {
1252 let mut enterprise = github_copilot.clone();
1253 enterprise.id = "github-copilot-enterprise".to_string();
1254 enterprise.name = "GitHub Copilot Enterprise".to_string();
1255 for model in enterprise.models.values_mut() {
1256 model.provider_id = "github-copilot-enterprise".to_string();
1257 }
1258 database.insert("github-copilot-enterprise".to_string(), enterprise);
1259 }
1260
1261 // Helper closure to merge a partial update into providers
1262 let merge_provider = |providers: &mut HashMap<String, ProviderState>,
1263 database: &HashMap<String, ProviderState>,
1264 provider_id: &str,
1265 patch: ProviderPatch| {
1266 if let Some(existing) = providers.get_mut(provider_id) {
1267 apply_patch(existing, patch);
1268 } else if let Some(base) = database.get(provider_id) {
1269 let mut merged = base.clone();
1270 apply_patch(&mut merged, patch);
1271 providers.insert(provider_id.to_string(), merged);
1272 }
1273 };
1274
1275 // Extend database from config providers
1276 for (provider_id, cfg_provider) in &config.providers {
1277 let existing = database.get(provider_id);
1278 let mut parsed = ProviderState {
1279 id: provider_id.clone(),
1280 name: cfg_provider
1281 .name
1282 .clone()
1283 .or_else(|| existing.map(|e| e.name.clone()))
1284 .unwrap_or_else(|| provider_id.clone()),
1285 env: cfg_provider
1286 .env
1287 .clone()
1288 .or_else(|| existing.map(|e| e.env.clone()))
1289 .unwrap_or_default(),
1290 options: merge_json_maps(
1291 existing.map(|e| &e.options).unwrap_or(&HashMap::new()),

Callers

nothing calls this directly

Calls 14

from_models_dev_providerFunction · 0.85
newFunction · 0.85
apply_patchFunction · 0.85
merge_json_mapsFunction · 0.85
config_to_provider_modelFunction · 0.85
get_custom_loaderFunction · 0.85
to_models_provider_infoFunction · 0.85
containsMethod · 0.80
is_emptyMethod · 0.80
cloneMethod · 0.45
getMethod · 0.45
get_mutMethod · 0.45

Tested by

no test coverage detected