refactor(agents): dedupe portal CLI credential parsing
This commit is contained in:
@@ -218,6 +218,13 @@ function readCodexKeychainCredentials(options?: {
|
||||
|
||||
function readQwenCliCredentials(options?: { homeDir?: string }): QwenCliCredential | null {
|
||||
const credPath = resolveQwenCliCredentialsPath(options?.homeDir);
|
||||
return readPortalCliOauthCredentials(credPath, "qwen-portal");
|
||||
}
|
||||
|
||||
function readPortalCliOauthCredentials<TProvider extends string>(
|
||||
credPath: string,
|
||||
provider: TProvider,
|
||||
): { type: "oauth"; provider: TProvider; access: string; refresh: string; expires: number } | null {
|
||||
const raw = loadJsonFile(credPath);
|
||||
if (!raw || typeof raw !== "object") {
|
||||
return null;
|
||||
@@ -239,7 +246,7 @@ function readQwenCliCredentials(options?: { homeDir?: string }): QwenCliCredenti
|
||||
|
||||
return {
|
||||
type: "oauth",
|
||||
provider: "qwen-portal",
|
||||
provider,
|
||||
access: accessToken,
|
||||
refresh: refreshToken,
|
||||
expires: expiresAt,
|
||||
@@ -248,32 +255,7 @@ function readQwenCliCredentials(options?: { homeDir?: string }): QwenCliCredenti
|
||||
|
||||
function readMiniMaxCliCredentials(options?: { homeDir?: string }): MiniMaxCliCredential | null {
|
||||
const credPath = resolveMiniMaxCliCredentialsPath(options?.homeDir);
|
||||
const raw = loadJsonFile(credPath);
|
||||
if (!raw || typeof raw !== "object") {
|
||||
return null;
|
||||
}
|
||||
const data = raw as Record<string, unknown>;
|
||||
const accessToken = data.access_token;
|
||||
const refreshToken = data.refresh_token;
|
||||
const expiresAt = data.expiry_date;
|
||||
|
||||
if (typeof accessToken !== "string" || !accessToken) {
|
||||
return null;
|
||||
}
|
||||
if (typeof refreshToken !== "string" || !refreshToken) {
|
||||
return null;
|
||||
}
|
||||
if (typeof expiresAt !== "number" || !Number.isFinite(expiresAt)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
type: "oauth",
|
||||
provider: "minimax-portal",
|
||||
access: accessToken,
|
||||
refresh: refreshToken,
|
||||
expires: expiresAt,
|
||||
};
|
||||
return readPortalCliOauthCredentials(credPath, "minimax-portal");
|
||||
}
|
||||
|
||||
function readClaudeCliKeychainCredentials(
|
||||
|
||||
Reference in New Issue
Block a user