11import * as React from 'react' ;
2- import { Column } from '../Row' ;
2+ import { Column , Row } from '../Row' ;
33import { Checkbox , CheckboxLabel } from '../forms/Checkbox' ;
44import { InputStyled , InputWrapper } from '../forms/InputStyles' ;
55import { MCPServersManager } from '../MCPServersManager' ;
66import styled from 'styled-components' ;
77import { transition } from '../../helpers/transition' ;
88import { useSettings } from '../../helpers/AppSettings' ;
99import { useEffect , useState } from 'react' ;
10+ import { OpenRouterLoginButton } from './OpenRouterLoginButton' ;
1011
1112interface CreditUsage {
1213 total : number ;
1314 used : number ;
1415}
1516
17+ const CREDITS_ENDPOINT = 'https://openrouter.ai/api/v1/credits' ;
18+
1619const AISettings : React . FC = ( ) => {
1720 const {
1821 enableAI,
@@ -29,10 +32,12 @@ const AISettings: React.FC = () => {
2932
3033 useEffect ( ( ) => {
3134 if ( ! openRouterApiKey ) {
35+ setCreditUsage ( undefined ) ;
36+
3237 return ;
3338 }
3439
35- fetch ( 'https://openrouter.ai/api/v1/credits' , {
40+ fetch ( CREDITS_ENDPOINT , {
3641 headers : {
3742 Authorization : `Bearer ${ openRouterApiKey } ` ,
3843 } ,
@@ -57,20 +62,40 @@ const AISettings: React.FC = () => {
5762 < label htmlFor = 'openrouter-api-key' >
5863 < Column gap = '0.5rem' >
5964 OpenRouter API Key
60- < InputWrapper >
61- < InputStyled
62- id = 'openrouter-api-key'
63- type = 'password'
64- value = { openRouterApiKey || '' }
65- onChange = { e => setOpenRouterApiKey ( e . target . value || undefined ) }
66- placeholder = 'Enter your OpenRouter API key'
67- />
68- </ InputWrapper >
65+ < Row center >
66+ { ! openRouterApiKey && (
67+ < >
68+ < OpenRouterLoginButton />
69+ or
70+ </ >
71+ ) }
72+ < InputWrapper >
73+ < InputStyled
74+ id = 'openrouter-api-key'
75+ type = 'password'
76+ value = { openRouterApiKey || '' }
77+ onChange = { e =>
78+ setOpenRouterApiKey ( e . target . value || undefined )
79+ }
80+ placeholder = 'Enter your OpenRouter API key'
81+ />
82+ </ InputWrapper >
83+ </ Row >
6984 { creditUsage && (
7085 < CreditUsage >
7186 Credits used: { creditUsage . used } / Total: { creditUsage . total }
7287 </ CreditUsage >
7388 ) }
89+ { ! openRouterApiKey && (
90+ < CreditUsage >
91+ < p >
92+ OpenRouter provides a unified API that gives you access to
93+ hundreds of AI models from all major vendors, while
94+ automatically handling fallbacks and selecting the most
95+ cost-effective options.
96+ </ p >
97+ </ CreditUsage >
98+ ) }
7499 </ Column >
75100 </ label >
76101 < CheckboxLabel >
0 commit comments