feat(oauth): v0.7.7 — 双区域 OAuth 支持(适配 kimi-code 0.38.0 global 账号)+ 修复模型占位别名跟随 + models.dev 快照刷新
Release / Version consistency (push) Canceled after 0s
Release / Build (macos-latest) (push) Canceled after 0s
Release / Build (ubuntu-latest) (push) Canceled after 0s
Release / Build (windows-latest) (push) Canceled after 0s
Release / Attach macOS install script (push) Canceled after 0s

This commit is contained in:
KimiSwitch Dev committed 2026-08-22 14:00:20 +08:00
1 parent 6b761251bc
commit 8221e05db1
16 files changed
+20602 -2868

No files matched your search

+21 -9
View File
@@ -658,7 +658,12 @@ pub async fn query_provider_usage(
});
let mut oauth_err: Option<String> = None;
if api_key.is_none() && provider.managed {
match crate::oauth::get_valid_access_token().await {
// Resolve the credential slot + refresh host from the provider's oauth
// ref (region-aware); with no ref this falls back to the mainland
// default, preserving pre-region behavior.
let oauth_ref = crate::oauth::oauth_ref_from_provider(provider);
let oauth_base_url = provider.base_url.as_deref().unwrap_or("");
match crate::oauth::get_valid_access_token(oauth_ref.as_ref(), oauth_base_url).await {
Ok(token) => api_key = Some(token),
Err(e) => oauth_err = Some(e),
}
@@ -1249,22 +1254,29 @@ pub fn open_external_url(app: tauri::AppHandle, url: String) -> Result<(), Strin
// Kimi OAuth device-code sign-in (in-app replacement for `kimi login`)
// ---------------------------------------------------------------------------
/// Step 1: ask auth.kimi.com for a user_code + verification URI.
/// Step 1: ask the region's OAuth host for a user_code + verification URI.
/// `region` is `"cn"` (default) or `"global"`.
#[tauri::command]
pub async fn kimi_oauth_start() -> Result<crate::oauth::DeviceAuthorization, String> {
crate::oauth::start_device_authorization().await
pub async fn kimi_oauth_start(
region: Option<String>,
) -> Result<crate::oauth::DeviceAuthorization, String> {
let region = crate::oauth::KimiRegion::from_opt(region.as_deref());
crate::oauth::start_device_authorization(region).await
}
/// Step 2: poll the token endpoint until the user approves. On success the
/// tokens are written to the CLI credentials file (`kimi login` no longer
/// needed). Errors are transient (network); deterministic outcomes
/// (pending / success / expired / denied / timeout) come back in the enum.
/// Step 2: poll the region's token endpoint until the user approves. On
/// success the tokens are written to the region's credentials file and the
/// provider is provisioned in config.toml (`kimi login` no longer needed).
/// Errors are transient (network); deterministic outcomes (pending / success /
/// expired / denied / timeout) come back in the enum.
#[tauri::command]
pub async fn kimi_oauth_poll(
device_code: String,
interval: i64,
region: Option<String>,
) -> Result<crate::oauth::DevicePollStatus, String> {
crate::oauth::poll_device_token(&device_code, interval).await
let region = crate::oauth::KimiRegion::from_opt(region.as_deref());
crate::oauth::poll_device_token(&device_code, interval, region).await
}
// ---------------------------------------------------------------------------