Skip to content

Commit 82863d6

Browse files
authored
Minor enhancements (#24)
## Pull Request Overview This PR implements OAuth authentication for the OpenRouter provider along with several UI enhancements and minor configuration improvements. The changes add a complete PKCE-based OAuth flow, redesign the initial user experience to show OAuth login options when no credentials are available, and introduce an advanced settings toggle to simplify the settings interface. - OAuth authentication system with PKCE security for OpenRouter - New welcome screen with OAuth login buttons when no credentials are configured - Advanced settings toggle to hide complex configuration options by default
1 parent 4472486 commit 82863d6

File tree

11 files changed

+1862
-131
lines changed

11 files changed

+1862
-131
lines changed

config/gni/devtools_grd_files.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,8 @@ grd_files_bundled_sources = [
655655
"front_end/panels/ai_chat/tracing/TracingProvider.js",
656656
"front_end/panels/ai_chat/tracing/LangfuseProvider.js",
657657
"front_end/panels/ai_chat/tracing/TracingConfig.js",
658+
"front_end/panels/ai_chat/auth/PKCEUtils.js",
659+
"front_end/panels/ai_chat/auth/OpenRouterOAuth.js",
658660
"front_end/panels/ai_chat/ai_chat-meta.js",
659661
"front_end/panels/ai_chat/ai_chat.js",
660662
"front_end/panels/ai_chat/ai_chat_impl.js",

front_end/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ copy_to_gen_with_grd("embedder-scripts") {
108108
]
109109
}
110110

111+
111112
group("unittests") {
112113
deps = [
113114
"Images:optimize_images",

front_end/panels/ai_chat/BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ devtools_module("ai_chat") {
9090
"tracing/TracingProvider.ts",
9191
"tracing/LangfuseProvider.ts",
9292
"tracing/TracingConfig.ts",
93+
"auth/PKCEUtils.ts",
94+
"auth/OpenRouterOAuth.ts",
9395
]
9496

9597
deps = [
@@ -185,6 +187,8 @@ _ai_chat_sources = [
185187
"tracing/TracingProvider.ts",
186188
"tracing/LangfuseProvider.ts",
187189
"tracing/TracingConfig.ts",
190+
"auth/PKCEUtils.ts",
191+
"auth/OpenRouterOAuth.ts",
188192
]
189193

190194
# Construct the expected JS output paths for the metadata

front_end/panels/ai_chat/LLM/OpenRouterProvider.ts

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,19 @@ export class OpenRouterProvider extends LLMBaseProvider {
436436
}
437437
},
438438
{
439-
id: 'google/gemini-pro-1.5',
440-
name: 'Gemini Pro 1.5',
439+
id: 'google/gemini-2.5-pro',
440+
name: 'Gemini Pro 2.5',
441+
provider: 'openrouter' as LLMProvider,
442+
capabilities: {
443+
functionCalling: true,
444+
reasoning: false,
445+
vision: true,
446+
structured: true
447+
}
448+
},
449+
{
450+
id: 'google/gemini-2.5-flash',
451+
name: 'Gemini Pro 2.5 Flash',
441452
provider: 'openrouter' as LLMProvider,
442453
capabilities: {
443454
functionCalling: true,
@@ -485,17 +496,45 @@ export class OpenRouterProvider extends LLMBaseProvider {
485496
* Validate that required credentials are available for OpenRouter
486497
*/
487498
validateCredentials(): {isValid: boolean, message: string, missingItems?: string[]} {
499+
logger.debug('=== VALIDATING OPENROUTER CREDENTIALS ===');
500+
logger.debug('Timestamp:', new Date().toISOString());
501+
488502
const storageKeys = this.getCredentialStorageKeys();
503+
logger.debug('Storage keys:', storageKeys);
504+
489505
const apiKey = localStorage.getItem(storageKeys.apiKey!);
506+
logger.debug('API key check:');
507+
logger.debug('- Storage key used:', storageKeys.apiKey);
508+
logger.debug('- API key exists:', !!apiKey);
509+
logger.debug('- API key length:', apiKey?.length || 0);
510+
logger.debug('- API key prefix:', apiKey?.substring(0, 8) + '...' || 'none');
511+
512+
// Also check OAuth-related storage for debugging
513+
const authMethod = localStorage.getItem('openrouter_auth_method');
514+
const oauthToken = localStorage.getItem('openrouter_oauth_token');
515+
logger.debug('OAuth-related storage:');
516+
logger.debug('- Auth method:', authMethod);
517+
logger.debug('- OAuth token exists:', !!oauthToken);
518+
519+
// Check all OpenRouter-related localStorage keys
520+
const allKeys = Object.keys(localStorage);
521+
const openRouterKeys = allKeys.filter(key => key.includes('openrouter') || key.includes('ai_chat'));
522+
logger.debug('All OpenRouter-related storage keys:');
523+
openRouterKeys.forEach(key => {
524+
const value = localStorage.getItem(key);
525+
logger.debug(`- ${key}:`, value?.substring(0, 50) + (value && value.length > 50 ? '...' : '') || 'null');
526+
});
490527

491528
if (!apiKey) {
529+
logger.warn('❌ OpenRouter API key missing');
492530
return {
493531
isValid: false,
494532
message: 'OpenRouter API key is required. Please add your API key in Settings.',
495533
missingItems: ['API Key']
496534
};
497535
}
498536

537+
logger.info('✅ OpenRouter credentials validation passed');
499538
return {
500539
isValid: true,
501540
message: 'OpenRouter credentials are configured correctly.'
@@ -506,8 +545,10 @@ export class OpenRouterProvider extends LLMBaseProvider {
506545
* Get the storage keys this provider uses for credentials
507546
*/
508547
getCredentialStorageKeys(): {apiKey: string} {
509-
return {
548+
const keys = {
510549
apiKey: 'ai_chat_openrouter_api_key'
511550
};
551+
logger.debug('OpenRouter credential storage keys:', keys);
552+
return keys;
512553
}
513554
}

0 commit comments

Comments
 (0)