feat(config): add Xiaomi MiMo token plan mode#2800
Conversation
Harvested from PR #2627 by @xyuai. Refs #2621 reported by @springeye.
There was a problem hiding this comment.
Hmbown has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
Code Review
This pull request introduces Xiaomi MiMo mode selection (XIAOMI_MIMO_MODE / MIMO_MODE) to support Token Plan region endpoints (China, Singapore, Amsterdam) and pay-as-you-go routing, along with dedicated Token Plan environment keys. Feedback on the implementation points out that when both mode and base_url are provided, base_url inference can incorrectly override an explicitly configured mode during API key resolution. The reviewer suggests prioritizing explicit mode configuration over base_url inference in both crates/config/src/lib.rs and crates/tui/src/config.rs.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| let standard_selected = normalized_mode | ||
| .as_deref() | ||
| .is_some_and(xiaomi_mimo_mode_uses_standard_endpoint) | ||
| || base_url.is_some_and(xiaomi_mimo_base_url_is_pay_as_you_go); | ||
| if standard_selected { | ||
| return xiaomi_mimo_env_var(STANDARD_ENV_VARS); | ||
| } | ||
|
|
||
| let token_plan_selected = normalized_mode | ||
| .as_deref() | ||
| .and_then(xiaomi_mimo_base_url_for_mode) | ||
| .is_some() | ||
| || base_url.is_some_and(xiaomi_mimo_base_url_uses_token_plan); | ||
| if token_plan_selected { | ||
| return xiaomi_mimo_env_var(TOKEN_PLAN_ENV_VARS); | ||
| } |
There was a problem hiding this comment.
In the current implementation, if both mode and base_url are provided, the base_url inference can override an explicitly configured mode. For example, if mode is set to "token-plan-cn" but base_url is configured to a pay-as-you-go endpoint, standard_selected will evaluate to true, selecting the standard API key instead of the token plan API key. Explicit configuration of mode should take precedence over base_url inference. We can resolve this by matching on normalized_mode first, and only falling back to base_url inference if normalized_mode is None.
let (standard_selected, token_plan_selected) = match normalized_mode.as_deref() {
Some(m) => (
xiaomi_mimo_mode_uses_standard_endpoint(m),
xiaomi_mimo_base_url_for_mode(m).is_some(),
),
None => (
base_url.is_some_and(xiaomi_mimo_base_url_is_pay_as_you_go),
base_url.is_some_and(xiaomi_mimo_base_url_uses_token_plan),
),
};
if standard_selected {
return xiaomi_mimo_env_var(STANDARD_ENV_VARS);
}
if token_plan_selected {
return xiaomi_mimo_env_var(TOKEN_PLAN_ENV_VARS);
}| let standard_selected = normalized_mode | ||
| .as_deref() | ||
| .is_some_and(xiaomi_mimo_mode_uses_standard_endpoint) | ||
| || base_url.is_some_and(xiaomi_mimo_base_url_is_pay_as_you_go); | ||
| if standard_selected { | ||
| return xiaomi_mimo_env_var(STANDARD_ENV_VARS); | ||
| } | ||
|
|
||
| let token_plan_selected = normalized_mode | ||
| .as_deref() | ||
| .and_then(xiaomi_mimo_base_url_for_mode) | ||
| .is_some() | ||
| || base_url.is_some_and(xiaomi_mimo_base_url_uses_token_plan); | ||
| if token_plan_selected { | ||
| return xiaomi_mimo_env_var(TOKEN_PLAN_ENV_VARS); | ||
| } |
There was a problem hiding this comment.
In the current implementation, if both mode and base_url are provided, the base_url inference can override an explicitly configured mode. For example, if mode is set to "token-plan-cn" but base_url is configured to a pay-as-you-go endpoint, standard_selected will evaluate to true, selecting the standard API key instead of the token plan API key. Explicit configuration of mode should take precedence over base_url inference. We can resolve this by matching on normalized_mode first, and only falling back to base_url inference if normalized_mode is None.
let (standard_selected, token_plan_selected) = match normalized_mode.as_deref() {
Some(m) => (
xiaomi_mimo_mode_uses_standard_endpoint(m),
xiaomi_mimo_base_url_for_mode(m).is_some(),
),
None => (
base_url.is_some_and(xiaomi_mimo_base_url_is_pay_as_you_go),
base_url.is_some_and(xiaomi_mimo_base_url_uses_token_plan),
),
};
if standard_selected {
return xiaomi_mimo_env_var(STANDARD_ENV_VARS);
}
if token_plan_selected {
return xiaomi_mimo_env_var(TOKEN_PLAN_ENV_VARS);
}
Harvests the narrow Xiaomi MiMo Token Plan mode/env-selection/docs slice from #2627 by @xyuai for the v0.9.0 stewardship branch.
Credits #2621 reported by @springeye. This does not close #2621; remaining scope there includes model-list behavior, credit/cost display, and rate-limit awareness.
What landed:
providers.xiaomi_mimo.modeplusXIAOMI_MIMO_MODE/MIMO_MODE.token-plan-sgp,token-plan-cn,token-plan-ams, andpay-as-you-goendpoint selection.XIAOMI_MIMO_TOKEN_PLAN_API_KEY/MIMO_TOKEN_PLAN_API_KEYfor Token Plan mode while preserving standard MiMo key env vars for pay-as-you-go.api-keyheader behavior.Verification:
cargo test -p codewhale-config --locked xiaomi -- --nocapturecargo test -p codewhale-tui --locked --bin codewhale-tui xiaomi_mimo -- --nocapturecargo fmt --all -- --checkcargo clippy -p codewhale-config -p codewhale-tui --locked --all-targets --all-features -- -D warningsgit diff --checkgit diff --cached --check./scripts/release/check-versions.shpython3 scripts/check-coauthor-trailers.py --range origin/codex/v0.9.0-stewardship..HEAD --check-authors