fix: route PAT login through pi LoginDialog callbacks

The custom ctx.ui.custom login menu stole focus from pi's built-in
LoginDialog, so onPrompt never received keystrokes and PAT login
silently failed with 'No API key found'. Drive login via the provided
onPrompt/onAuth/onProgress callbacks instead, and drop login-ui.ts and
the now-unused pi-tui dependency. Also clears remaining lint warnings
by removing any-casts in models/oauth/stream/transform.
This commit is contained in:
Simon Shi
2026-06-16 13:39:16 +08:00
parent 842bec6eb2
commit bcaa66091e
10 changed files with 139 additions and 303 deletions
+7 -9
View File
@@ -29,7 +29,7 @@ export function getCachedCredentials(_accessToken: string): QoderCredentials | n
try {
const auth = JSON.parse(readFileSync(AUTH_FILE, "utf-8"));
const creds = auth?.qoder;
if (creds && creds.userID) {
if (creds?.userID) {
return creds as QoderCredentials;
}
} catch {}
@@ -91,6 +91,9 @@ export async function refreshQoderToken(credentials: OAuthCredentials): Promise<
const refreshToken = parts[0] || "";
const userID = parts[1] || "";
const machineID = parts[2] || getMachineId();
const prev = credentials as Partial<QoderCredentials>;
const prevName = prev.name || "";
const prevEmail = prev.email || "";
const refreshURL = "https://center.qoder.sh/algo/api/v3/user/refresh_token";
try {
@@ -130,19 +133,14 @@ export async function refreshQoderToken(credentials: OAuthCredentials): Promise<
access: newAccess,
expires: expireMs - 5 * 60 * 1000,
userID,
email: (credentials as any).email || "",
name: (credentials as any).name || "",
email: prevEmail,
name: prevName,
machineID,
};
// pi persists the refreshed credentials in auth.json itself.
// Cache models in background
updateQoderModelsCache(
newAccess,
userID,
(credentials as any).name || "",
(credentials as any).email || "",
).catch(() => {});
updateQoderModelsCache(newAccess, userID, prevName, prevEmail).catch(() => {});
return refreshed;
}