feat(shell): custom providers declared in config.toml join the model catalog

[platforms.<name>] with base_url and api (openai or anthropic) declares a provider.
Its key lives in auth.json under the name or in the table; /models is fetched per
provider, entries are keyed <name>/<model>, and the key is stamped in memory only.
This commit is contained in:
雷电芽衣 committed 2026-09-29 14:50:24 -04:00
1 parent 4514b66ffe
commit 2ca1f3baa7
11 files changed
+1048 -23

No files matched your search

@@ -202,6 +202,15 @@ impl CredentialAuthority {
/// Deliberately NOT [`crate::util::is_first_party_url`], which is
/// production-only and would break every custom deployment.
fn is_session_coding_endpoint(&self, base_url: &str) -> bool {
// Declared custom providers are never the session's endpoint.
if self
.endpoints
.custom_provider_bases
.iter()
.any(|base| crate::util::matches_trusted_base_url(base_url, base))
{
return false;
}
if crate::util::is_effective_coding_endpoint_url(base_url) {
return true;
}
@@ -422,6 +431,38 @@ mod tests {
}
}
/// LEAK guard: a declared loopback custom provider never gets the primary.
#[test]
fn declared_custom_provider_hosts_never_receive_the_primary() {
let (_d, kimi) = primary("kimi-tok");
let endpoints = EndpointsConfig {
custom_provider_bases: vec![
"http://localhost:11434/v1".to_owned(),
"https://gw.example/v1".to_owned(),
],
..EndpointsConfig::default()
};
let auth = authority(endpoints, kimi);
for url in [
"http://localhost:11434/v1",
"http://localhost:11434/v1/chat/completions",
"https://gw.example/v1",
] {
assert_eq!(
auth.credential_class(None, url),
CredentialClass::None,
"{url}"
);
assert!(auth.credential_for(None, url).is_none(), "{url}");
assert!(auth.manager_for(None, url).is_none(), "{url}");
}
assert_eq!(
auth.credential_class(None, "http://localhost:3000/v1"),
CredentialClass::Primary,
"an undeclared loopback proxy keeps the session bearer"
);
}
/// LEAK guard: every API-key registry platform, and any platform-less model
/// on a third-party host, gets NO session credential and NO manager.
#[test]
@@ -32,6 +32,7 @@ pub use manager::{AuthManager, shared_api_key_provider};
pub use meta::AuthMeta;
pub use model::{AuthMode, KimiAuth, lookup_auth};
pub(crate) use model::{TOKEN_TTL, is_expired, token_suffix};
pub(crate) use storage::store_scoped_api_key;
pub use storage::{
clear_api_key, read_api_key, read_auth_json, read_platform_api_key, read_token_by_scope,
store_api_key, store_platform_api_key,
+10 -1
View File
@@ -619,6 +619,15 @@ pub fn store_platform_api_key(
),
));
}
store_scoped_api_key(kigi_home, platform.as_str(), api_key)
}
/// Stores a key under `scope`; callers own the name.
pub(crate) fn store_scoped_api_key(
kigi_home: &Path,
scope: &str,
api_key: &str,
) -> std::io::Result<()> {
let path = kigi_home.join("auth.json");
// Serialize with the manager's cross-process auth.json writers (token
// refresh holds the same flock): an unlocked read-modify-write here
@@ -641,7 +650,7 @@ pub fn store_platform_api_key(
};
let mut map = read_auth_json_or_empty_recovering_corrupt(&path)?;
map.insert(
platform.as_str().to_owned(),
scope.to_owned(),
KimiAuth {
key: api_key.to_owned(),
auth_mode: AuthMode::ApiKey,