mirror of
https://github.com/hanzoai/codex.git
synced 2026-10-30 14:59:26 +00:00
## What changed - Support `model_provider` and `model_providers` in managed requirements. Required selection overrides local and session configuration; each required provider definition replaces the corresponding local entry, including its authentication and headers. - Merge provider requirement fragments before validation, preserving source-relative `auth.cwd` paths. Reject invalid cloud provider definitions before replacing the cached bundle, including unsupported Bedrock overrides. - Expose `modelProvider` and `modelProviders` through the configuration requirements API and generated schemas. Reject writes to managed provider settings and omit their local origins, including for provider IDs containing dots. ## Testing Add tests for requirement precedence, authentication fragment merging, path resolution, cloud cache preservation, and read-only configuration RPCs. Integration tests verify that model discovery and inference use the required gateway and ChatGPT authentication without leaking local headers, and that provider requirements survive configuration rebuilds. GitOrigin-RevId: d1448604d4ef5662ebb5df7b693712d3b8ad6d54
46 lines
1.5 KiB
Rust
46 lines
1.5 KiB
Rust
//! Projects complete required provider definitions before config parsing.
|
|
//! Selection is applied with the other exact requirements after config parsing.
|
|
|
|
use crate::ConfigRequirementsToml;
|
|
use crate::config_toml::validate_model_providers;
|
|
use std::io;
|
|
use toml::Value;
|
|
|
|
pub(crate) fn to_config(requirements: &ConfigRequirementsToml) -> io::Result<Value> {
|
|
let mut config = toml::Table::new();
|
|
if let Some(providers) = &requirements.model_providers {
|
|
validate_model_providers(providers)
|
|
.map_err(|message| io::Error::new(io::ErrorKind::InvalidData, message))?;
|
|
config.insert(
|
|
"model_providers".to_string(),
|
|
Value::try_from(providers)
|
|
.map_err(|error| io::Error::new(io::ErrorKind::InvalidData, error))?,
|
|
);
|
|
}
|
|
Ok(Value::Table(config))
|
|
}
|
|
|
|
pub(crate) fn apply(config: &mut Value, requirements: &Value) {
|
|
let Some(config) = config.as_table_mut() else {
|
|
return;
|
|
};
|
|
if let Some(required) = requirements
|
|
.get("model_providers")
|
|
.and_then(Value::as_table)
|
|
{
|
|
let providers = config
|
|
.entry("model_providers")
|
|
.or_insert_with(|| Value::Table(Default::default()));
|
|
if !providers.is_table() {
|
|
*providers = Value::Table(Default::default());
|
|
}
|
|
if let Some(providers) = providers.as_table_mut() {
|
|
providers.extend(required.clone());
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "model_provider_requirements_tests.rs"]
|
|
mod tests;
|