feat(providers): add Xiaomi MiMo (global + China token plan)
Providers 19-20 (22nd & 23rd registry variants), sourced from Pi (earendil-works/pi). Pi's xiaomi.ts / xiaomi-token-plan-cn.ts use plain openAICompletionsApi (no thinking dialect) → Kigi Passthrough. Global: MiMo at api.xiaomimimo.com/v1, XIAOMI_API_KEY, models.dev xiaomi. China token plan: token-plan-cn.xiaomimimo.com/v1, XIAOMI_TOKEN_PLAN_CN_API_KEY, models.dev xiaomi-token-plan-cn. Both Bearer + OpenAI listing + ChatCompletions + restrict_to_enriched; /models auth-gated → validator. id-match proven vs Pi's static ids (mimo-v2.5-pro, mimo-v2-flash, ...). The CN token plan lists 4 mimo TTS models (tool_call=false); restrict's tool_call cut drops them, keeping only the 3 chat models — the e2e proves this non-vacuously with the real mimo-v2-tts. Review found no defects. Registry at 23; picker 24 rows (welcome picker verified rendering all rows at a taller viewport).
This commit is contained in:
@@ -625,7 +625,9 @@ mod tests {
|
||||
"qwen-token-plan-cn",
|
||||
"kimi-coding",
|
||||
"zai",
|
||||
"zai-coding-cn"
|
||||
"zai-coding-cn",
|
||||
"xiaomi",
|
||||
"xiaomi-token-plan-cn"
|
||||
]
|
||||
);
|
||||
assert_eq!(default_id(&built), Some(XAI_API_KEY_METHOD_ID));
|
||||
@@ -669,7 +671,9 @@ mod tests {
|
||||
"qwen-token-plan-cn",
|
||||
"kimi-coding",
|
||||
"zai",
|
||||
"zai-coding-cn"
|
||||
"zai-coding-cn",
|
||||
"xiaomi",
|
||||
"xiaomi-token-plan-cn"
|
||||
]
|
||||
);
|
||||
assert_eq!(default_id(&built), Some(CACHED_TOKEN_AUTH_METHOD_ID));
|
||||
@@ -706,7 +710,9 @@ mod tests {
|
||||
"qwen-token-plan-cn",
|
||||
"kimi-coding",
|
||||
"zai",
|
||||
"zai-coding-cn"
|
||||
"zai-coding-cn",
|
||||
"xiaomi",
|
||||
"xiaomi-token-plan-cn"
|
||||
]
|
||||
);
|
||||
assert_eq!(default_id(&built), Some(CACHED_TOKEN_AUTH_METHOD_ID));
|
||||
@@ -746,7 +752,9 @@ mod tests {
|
||||
"qwen-token-plan-cn",
|
||||
"kimi-coding",
|
||||
"zai",
|
||||
"zai-coding-cn"
|
||||
"zai-coding-cn",
|
||||
"xiaomi",
|
||||
"xiaomi-token-plan-cn"
|
||||
]
|
||||
);
|
||||
assert_eq!(default_id(&built), None);
|
||||
@@ -1147,4 +1155,54 @@ mod tests {
|
||||
"Invalid API key for zai-coding-cn \u{2014} check your key on open.bigmodel.cn"
|
||||
);
|
||||
}
|
||||
|
||||
/// Xiaomi MiMo (global): /models is auth-gated (401 for a bad key).
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn xiaomi_validates_against_models_and_rejects_bad_key() {
|
||||
use wiremock::matchers::{method, path};
|
||||
let server = wiremock::MockServer::start().await;
|
||||
wiremock::Mock::given(method("GET"))
|
||||
.and(path("/models"))
|
||||
.respond_with(wiremock::ResponseTemplate::new(401))
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
let _base = EnvGuard::set(kigi_models::XIAOMI_BASE_URL_ENV, &server.uri());
|
||||
let err = authenticate_platform_api_key(kigi_models::PlatformId::Xiaomi, Some("xm-bad"))
|
||||
.await
|
||||
.expect_err("a 401 from /models must reject the key");
|
||||
assert_eq!(
|
||||
err.message,
|
||||
"Invalid API key for xiaomi \u{2014} check your key on xiaomimimo.com"
|
||||
);
|
||||
}
|
||||
|
||||
/// Xiaomi Token Plan CN: distinct base URL; same auth-gated validation.
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn xiaomi_token_plan_cn_validates_against_models_and_rejects_bad_key() {
|
||||
use wiremock::matchers::{method, path};
|
||||
let server = wiremock::MockServer::start().await;
|
||||
wiremock::Mock::given(method("GET"))
|
||||
.and(path("/models"))
|
||||
.respond_with(wiremock::ResponseTemplate::new(401))
|
||||
.expect(1)
|
||||
.mount(&server)
|
||||
.await;
|
||||
let _base = EnvGuard::set(
|
||||
kigi_models::XIAOMI_TOKEN_PLAN_CN_BASE_URL_ENV,
|
||||
&server.uri(),
|
||||
);
|
||||
let err = authenticate_platform_api_key(
|
||||
kigi_models::PlatformId::XiaomiTokenPlanCn,
|
||||
Some("xm-cn-bad"),
|
||||
)
|
||||
.await
|
||||
.expect_err("a 401 from /models must reject the key");
|
||||
assert_eq!(
|
||||
err.message,
|
||||
"Invalid API key for xiaomi-token-plan-cn \u{2014} check your key on xiaomimimo.com"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2348,6 +2348,96 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// Xiaomi-cycle e2e: OpenAI-compatible MiMo (per Pi, plain completions).
|
||||
/// /models is auth-gated + minimal; enrichment supplies context; restrict's
|
||||
/// tool_call cut drops the mimo TTS models (tool_call=false) the token plan
|
||||
/// lists; bare id round-trips under the xiaomi key; Passthrough.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
#[serial_test::serial]
|
||||
async fn xiaomi_enriches_restricts_and_maps_passthrough() {
|
||||
let platform_server = wiremock::MockServer::start().await;
|
||||
wiremock::Mock::given(wiremock::matchers::method("GET"))
|
||||
.and(wiremock::matchers::path("/models"))
|
||||
.respond_with(wiremock::ResponseTemplate::new(200).set_body_json(
|
||||
serde_json::json!({ "data": [
|
||||
{ "id": "mimo-v2.5-pro", "object": "model" },
|
||||
// a TTS model (tool_call=false in enrichment) → dropped.
|
||||
{ "id": "mimo-v2-tts", "object": "model" }
|
||||
]}),
|
||||
))
|
||||
.expect(1)
|
||||
.mount(&platform_server)
|
||||
.await;
|
||||
let modelsdev_server = wiremock::MockServer::start().await;
|
||||
wiremock::Mock::given(wiremock::matchers::method("GET"))
|
||||
.and(wiremock::matchers::path("/api.json"))
|
||||
.respond_with(wiremock::ResponseTemplate::new(200).set_body_json(
|
||||
serde_json::json!({ "xiaomi": { "models": {
|
||||
"mimo-v2.5-pro": {
|
||||
"limit": {"context": 256000, "output": 32768},
|
||||
"tool_call": true
|
||||
},
|
||||
"mimo-v2-tts": { "limit": {"context": 8192}, "tool_call": false }
|
||||
}}}),
|
||||
))
|
||||
.expect(1)
|
||||
.mount(&modelsdev_server)
|
||||
.await;
|
||||
let cache_dir = tempfile::tempdir().unwrap();
|
||||
let _base = kigi_test_support::EnvGuard::set(
|
||||
kigi_models::XIAOMI_BASE_URL_ENV,
|
||||
platform_server.uri(),
|
||||
);
|
||||
let _mdev = kigi_test_support::EnvGuard::set(
|
||||
crate::agent::enrichment_fetch::MODELS_DEV_URL_ENV,
|
||||
format!("{}/api.json", modelsdev_server.uri()),
|
||||
);
|
||||
let _mdev_cache = kigi_test_support::EnvGuard::set(
|
||||
crate::agent::enrichment_fetch::MODELS_DEV_CACHE_DIR_ENV,
|
||||
cache_dir.path(),
|
||||
);
|
||||
let endpoints = crate::agent::config::EndpointsConfig::default();
|
||||
let keys = crate::agent::models::PlatformApiKeys::test_single(
|
||||
kigi_models::PlatformId::Xiaomi,
|
||||
"xm-1",
|
||||
);
|
||||
let result = tokio::task::spawn_blocking(move || {
|
||||
fetch_platform_models_blocking(&endpoints, None, &keys)
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
.expect("fetch must succeed");
|
||||
assert_eq!(
|
||||
result
|
||||
.models
|
||||
.iter()
|
||||
.map(|m| m.id.as_deref().unwrap_or_default())
|
||||
.collect::<Vec<_>>(),
|
||||
vec!["xiaomi/mimo-v2.5-pro"],
|
||||
"the TTS model (tool_call=false) is dropped by restrict_to_enriched"
|
||||
);
|
||||
let entry = &result.models[0];
|
||||
assert_eq!(
|
||||
entry.context_window.get(),
|
||||
256_000,
|
||||
"context comes from enrichment (the wire listing carries none)"
|
||||
);
|
||||
assert_eq!(entry.max_completion_tokens, Some(32_768));
|
||||
assert_eq!(entry.model, "mimo-v2.5-pro");
|
||||
let model_entry = crate::agent::config::ModelEntry::from_config_entry(entry);
|
||||
let creds = crate::agent::config::ResolvedCredentials {
|
||||
api_key: Some("xm-1".into()),
|
||||
base_url: entry.base_url.clone(),
|
||||
auth_type: kigi_chat_state::AuthType::ApiKey,
|
||||
auth_scheme: Default::default(),
|
||||
};
|
||||
let cfg = crate::agent::config::sampling_config_for_model(&model_entry, creds, None);
|
||||
assert_eq!(
|
||||
cfg.chat_compat,
|
||||
kigi_sampling_types::ChatCompat::Passthrough
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_env_keys_parses_strings_and_rejects_non_strings() {
|
||||
use crate::agent::config::EnvKeys;
|
||||
|
||||
Reference in New Issue
Block a user