mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 03:51:25 +00:00
chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -14,11 +14,7 @@ export type CachedCopilotToken = {
|
||||
};
|
||||
|
||||
function resolveCopilotTokenCachePath(env: NodeJS.ProcessEnv = process.env) {
|
||||
return path.join(
|
||||
resolveStateDir(env),
|
||||
"credentials",
|
||||
"github-copilot.token.json",
|
||||
);
|
||||
return path.join(resolveStateDir(env), "credentials", "github-copilot.token.json");
|
||||
}
|
||||
|
||||
function isTokenUsable(cache: CachedCopilotToken, now = Date.now()): boolean {
|
||||
@@ -57,8 +53,7 @@ function parseCopilotTokenResponse(value: unknown): {
|
||||
return { token, expiresAt: expiresAtMs };
|
||||
}
|
||||
|
||||
export const DEFAULT_COPILOT_API_BASE_URL =
|
||||
"https://api.individual.githubcopilot.com";
|
||||
export const DEFAULT_COPILOT_API_BASE_URL = "https://api.individual.githubcopilot.com";
|
||||
|
||||
export function deriveCopilotApiBaseUrlFromToken(token: string): string | null {
|
||||
const trimmed = token.trim();
|
||||
@@ -91,19 +86,13 @@ export async function resolveCopilotApiToken(params: {
|
||||
const env = params.env ?? process.env;
|
||||
const cachePath = resolveCopilotTokenCachePath(env);
|
||||
const cached = loadJsonFile(cachePath) as CachedCopilotToken | undefined;
|
||||
if (
|
||||
cached &&
|
||||
typeof cached.token === "string" &&
|
||||
typeof cached.expiresAt === "number"
|
||||
) {
|
||||
if (cached && typeof cached.token === "string" && typeof cached.expiresAt === "number") {
|
||||
if (isTokenUsable(cached)) {
|
||||
return {
|
||||
token: cached.token,
|
||||
expiresAt: cached.expiresAt,
|
||||
source: `cache:${cachePath}`,
|
||||
baseUrl:
|
||||
deriveCopilotApiBaseUrlFromToken(cached.token) ??
|
||||
DEFAULT_COPILOT_API_BASE_URL,
|
||||
baseUrl: deriveCopilotApiBaseUrlFromToken(cached.token) ?? DEFAULT_COPILOT_API_BASE_URL,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -133,8 +122,6 @@ export async function resolveCopilotApiToken(params: {
|
||||
token: payload.token,
|
||||
expiresAt: payload.expiresAt,
|
||||
source: `fetched:${COPILOT_TOKEN_URL}`,
|
||||
baseUrl:
|
||||
deriveCopilotApiBaseUrlFromToken(payload.token) ??
|
||||
DEFAULT_COPILOT_API_BASE_URL,
|
||||
baseUrl: deriveCopilotApiBaseUrlFromToken(payload.token) ?? DEFAULT_COPILOT_API_BASE_URL,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user