1
1
import * as React from 'react' ;
2
- import { Column } from '../Row' ;
2
+ import { Column , Row } from '../Row' ;
3
3
import { Checkbox , CheckboxLabel } from '../forms/Checkbox' ;
4
4
import { InputStyled , InputWrapper } from '../forms/InputStyles' ;
5
5
import { MCPServersManager } from '../MCPServersManager' ;
6
6
import styled from 'styled-components' ;
7
7
import { transition } from '../../helpers/transition' ;
8
8
import { useSettings } from '../../helpers/AppSettings' ;
9
9
import { useEffect , useState } from 'react' ;
10
+ import { OpenRouterLoginButton } from './OpenRouterLoginButton' ;
10
11
11
12
interface CreditUsage {
12
13
total : number ;
13
14
used : number ;
14
15
}
15
16
17
+ const CREDITS_ENDPOINT = 'https://openrouter.ai/api/v1/credits' ;
18
+
16
19
const AISettings : React . FC = ( ) => {
17
20
const {
18
21
enableAI,
@@ -29,10 +32,12 @@ const AISettings: React.FC = () => {
29
32
30
33
useEffect ( ( ) => {
31
34
if ( ! openRouterApiKey ) {
35
+ setCreditUsage ( undefined ) ;
36
+
32
37
return ;
33
38
}
34
39
35
- fetch ( 'https://openrouter.ai/api/v1/credits' , {
40
+ fetch ( CREDITS_ENDPOINT , {
36
41
headers : {
37
42
Authorization : `Bearer ${ openRouterApiKey } ` ,
38
43
} ,
@@ -57,20 +62,40 @@ const AISettings: React.FC = () => {
57
62
< label htmlFor = 'openrouter-api-key' >
58
63
< Column gap = '0.5rem' >
59
64
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 >
69
84
{ creditUsage && (
70
85
< CreditUsage >
71
86
Credits used: { creditUsage . used } / Total: { creditUsage . total }
72
87
</ CreditUsage >
73
88
) }
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
+ ) }
74
99
</ Column >
75
100
</ label >
76
101
< CheckboxLabel >
0 commit comments