mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 06:02:42 +00:00
fix: OAuth token refresh failure returns undefined instead of throwing
When OAuth refresh fails during model discovery, getApiKey() now returns undefined instead of throwing. This allows the app to start and fall back to other providers, so the user can /login to re-authenticate. fixes #498
This commit is contained in:
parent
cd797cc407
commit
d2f3b42deb
7 changed files with 94 additions and 10 deletions
|
|
@ -326,7 +326,7 @@ export class AuthStorage {
|
|||
if (result) {
|
||||
return result.apiKey;
|
||||
}
|
||||
} catch (err) {
|
||||
} catch {
|
||||
// Refresh failed - re-read file to check if another instance succeeded
|
||||
this.reload();
|
||||
const updatedCred = this.data[provider];
|
||||
|
|
@ -339,13 +339,9 @@ export class AuthStorage {
|
|||
: updatedCred.access;
|
||||
}
|
||||
|
||||
// Refresh truly failed - DO NOT remove credentials
|
||||
// User can retry or re-authenticate manually
|
||||
const errorMessage = err instanceof Error ? err.message : String(err);
|
||||
throw new Error(
|
||||
`OAuth token refresh failed for ${provider}: ${errorMessage}. ` +
|
||||
`Please try again or re-authenticate with /login.`,
|
||||
);
|
||||
// Refresh truly failed - return undefined so model discovery skips this provider
|
||||
// User can /login to re-authenticate (credentials preserved for retry)
|
||||
return undefined;
|
||||
}
|
||||
} else {
|
||||
// Token not expired, use current access token
|
||||
|
|
|
|||
|
|
@ -171,12 +171,35 @@ function getChangelogForDisplay(parsed: Args, settingsManager: SettingsManager):
|
|||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a session argument to a file path.
|
||||
* If it looks like a path, use as-is. Otherwise try to match as session ID prefix.
|
||||
*/
|
||||
function resolveSessionPath(sessionArg: string, cwd: string, sessionDir?: string): string {
|
||||
// If it looks like a file path, use as-is
|
||||
if (sessionArg.includes("/") || sessionArg.includes("\\") || sessionArg.endsWith(".jsonl")) {
|
||||
return sessionArg;
|
||||
}
|
||||
|
||||
// Try to match as session ID (full or partial UUID)
|
||||
const sessions = SessionManager.list(cwd, sessionDir);
|
||||
const matches = sessions.filter((s) => s.id.startsWith(sessionArg));
|
||||
|
||||
if (matches.length >= 1) {
|
||||
return matches[0].path; // Already sorted by modified time (most recent first)
|
||||
}
|
||||
|
||||
// No match - return original (will create new session)
|
||||
return sessionArg;
|
||||
}
|
||||
|
||||
function createSessionManager(parsed: Args, cwd: string): SessionManager | undefined {
|
||||
if (parsed.noSession) {
|
||||
return SessionManager.inMemory();
|
||||
}
|
||||
if (parsed.session) {
|
||||
return SessionManager.open(parsed.session, parsed.sessionDir);
|
||||
const resolvedPath = resolveSessionPath(parsed.session, cwd, parsed.sessionDir);
|
||||
return SessionManager.open(resolvedPath, parsed.sessionDir);
|
||||
}
|
||||
if (parsed.continue) {
|
||||
return SessionManager.continueRecent(cwd, parsed.sessionDir);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,11 @@ class SessionList implements Component {
|
|||
}
|
||||
|
||||
private filterSessions(query: string): void {
|
||||
this.filteredSessions = fuzzyFilter(this.allSessions, query, (session) => session.allMessagesText);
|
||||
this.filteredSessions = fuzzyFilter(
|
||||
this.allSessions,
|
||||
query,
|
||||
(session) => `${session.id} ${session.allMessagesText}`,
|
||||
);
|
||||
this.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredSessions.length - 1));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue