mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:08:26 +00:00
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 {
|
function readQwenCliCredentials(options?: { homeDir?: string }): QwenCliCredential | null {
|
||||||
const credPath = resolveQwenCliCredentialsPath(options?.homeDir);
|
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);
|
const raw = loadJsonFile(credPath);
|
||||||
if (!raw || typeof raw !== "object") {
|
if (!raw || typeof raw !== "object") {
|
||||||
return null;
|
return null;
|
||||||
@@ -239,7 +246,7 @@ function readQwenCliCredentials(options?: { homeDir?: string }): QwenCliCredenti
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
type: "oauth",
|
type: "oauth",
|
||||||
provider: "qwen-portal",
|
provider,
|
||||||
access: accessToken,
|
access: accessToken,
|
||||||
refresh: refreshToken,
|
refresh: refreshToken,
|
||||||
expires: expiresAt,
|
expires: expiresAt,
|
||||||
@@ -248,32 +255,7 @@ function readQwenCliCredentials(options?: { homeDir?: string }): QwenCliCredenti
|
|||||||
|
|
||||||
function readMiniMaxCliCredentials(options?: { homeDir?: string }): MiniMaxCliCredential | null {
|
function readMiniMaxCliCredentials(options?: { homeDir?: string }): MiniMaxCliCredential | null {
|
||||||
const credPath = resolveMiniMaxCliCredentialsPath(options?.homeDir);
|
const credPath = resolveMiniMaxCliCredentialsPath(options?.homeDir);
|
||||||
const raw = loadJsonFile(credPath);
|
return readPortalCliOauthCredentials(credPath, "minimax-portal");
|
||||||
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,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function readClaudeCliKeychainCredentials(
|
function readClaudeCliKeychainCredentials(
|
||||||
|
|||||||
Reference in New Issue
Block a user