mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-06-16 13:34:04 +08:00
87635e7fc6
* feat(copilot): add GitHub Enterprise Server support * fix(copilot): address GHES PR review findings (P1 + 2×P2) - P1: Use composite account ID (domain:user_id) for GHES to prevent cross-instance ID collisions; github.com keeps plain numeric ID for backward compatibilit - P2-a: Use get_api_endpoint() for model list URL with automatic fallback to static URL when dynamic endpoint resolution fails - P2-b: Add normalize_github_domain() as backend SSOT for domain normalization (lowercase, strip protocol/path/query, reject userinfo) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
107 lines
2.4 KiB
TypeScript
107 lines
2.4 KiB
TypeScript
import { invoke } from "@tauri-apps/api/core";
|
|
|
|
export type ManagedAuthProvider = "github_copilot" | "codex_oauth";
|
|
|
|
export interface ManagedAuthAccount {
|
|
id: string;
|
|
provider: ManagedAuthProvider;
|
|
login: string;
|
|
avatar_url: string | null;
|
|
authenticated_at: number;
|
|
is_default: boolean;
|
|
github_domain: string;
|
|
}
|
|
|
|
export interface ManagedAuthStatus {
|
|
provider: ManagedAuthProvider;
|
|
authenticated: boolean;
|
|
default_account_id: string | null;
|
|
migration_error?: string | null;
|
|
accounts: ManagedAuthAccount[];
|
|
}
|
|
|
|
export interface ManagedAuthDeviceCodeResponse {
|
|
provider: ManagedAuthProvider;
|
|
device_code: string;
|
|
user_code: string;
|
|
verification_uri: string;
|
|
expires_in: number;
|
|
interval: number;
|
|
}
|
|
|
|
export async function authStartLogin(
|
|
authProvider: ManagedAuthProvider,
|
|
githubDomain?: string,
|
|
): Promise<ManagedAuthDeviceCodeResponse> {
|
|
return invoke<ManagedAuthDeviceCodeResponse>("auth_start_login", {
|
|
authProvider,
|
|
githubDomain: githubDomain || null,
|
|
});
|
|
}
|
|
|
|
export async function authPollForAccount(
|
|
authProvider: ManagedAuthProvider,
|
|
deviceCode: string,
|
|
githubDomain?: string,
|
|
): Promise<ManagedAuthAccount | null> {
|
|
return invoke<ManagedAuthAccount | null>("auth_poll_for_account", {
|
|
authProvider,
|
|
deviceCode,
|
|
githubDomain: githubDomain || null,
|
|
});
|
|
}
|
|
|
|
export async function authListAccounts(
|
|
authProvider: ManagedAuthProvider,
|
|
): Promise<ManagedAuthAccount[]> {
|
|
return invoke<ManagedAuthAccount[]>("auth_list_accounts", {
|
|
authProvider,
|
|
});
|
|
}
|
|
|
|
export async function authGetStatus(
|
|
authProvider: ManagedAuthProvider,
|
|
): Promise<ManagedAuthStatus> {
|
|
return invoke<ManagedAuthStatus>("auth_get_status", {
|
|
authProvider,
|
|
});
|
|
}
|
|
|
|
export async function authRemoveAccount(
|
|
authProvider: ManagedAuthProvider,
|
|
accountId: string,
|
|
): Promise<void> {
|
|
return invoke("auth_remove_account", {
|
|
authProvider,
|
|
accountId,
|
|
});
|
|
}
|
|
|
|
export async function authSetDefaultAccount(
|
|
authProvider: ManagedAuthProvider,
|
|
accountId: string,
|
|
): Promise<void> {
|
|
return invoke("auth_set_default_account", {
|
|
authProvider,
|
|
accountId,
|
|
});
|
|
}
|
|
|
|
export async function authLogout(
|
|
authProvider: ManagedAuthProvider,
|
|
): Promise<void> {
|
|
return invoke("auth_logout", {
|
|
authProvider,
|
|
});
|
|
}
|
|
|
|
export const authApi = {
|
|
authStartLogin,
|
|
authPollForAccount,
|
|
authListAccounts,
|
|
authGetStatus,
|
|
authRemoveAccount,
|
|
authSetDefaultAccount,
|
|
authLogout,
|
|
};
|