@@ -5,6 +5,7 @@ import { validateApiKey } from '../../../lib/validApiKey'
5
5
const Auth = ( ) => {
6
6
const [ , setSettings ] = useSettings ( )
7
7
const [ error , setError ] = React . useState < string | null > ( null )
8
+ const [ showAdvanced , setShowAdvanced ] = React . useState ( false )
8
9
9
10
useEffect ( ( ) => {
10
11
if ( error ) {
@@ -18,23 +19,23 @@ const Auth = () => {
18
19
e . preventDefault ( )
19
20
const data = new FormData ( e . currentTarget )
20
21
const key = data . get ( 'openAiKey' ) as string | null
21
- const openAiBaseUrl = data . get ( 'openAiBaseUrl' ) as
22
- | string
23
- | 'https://api.openai.com/v1'
22
+ const openAiBaseUrl =
23
+ ( data . get ( 'openAiBaseUrl' ) as string ) || 'https://api.openai.com/v1'
24
24
25
25
if ( key && ( await validateApiKey ( key , openAiBaseUrl ) ) ) {
26
26
setSettings ( ( prev ) => ( {
27
27
...prev ,
28
28
chat : {
29
29
...prev . chat ,
30
30
openAIKey : key as string ,
31
- openAiBaseUrl : openAiBaseUrl as string ,
31
+ openAiBaseUrl : openAiBaseUrl ,
32
32
} ,
33
33
} ) )
34
34
} else {
35
35
setError ( 'Invalid API key. Please try with a valid one.' )
36
36
}
37
37
}
38
+
38
39
return (
39
40
< form
40
41
onSubmit = { handleOpenAiKeySubmit }
@@ -58,17 +59,48 @@ const Auth = () => {
58
59
< div className = "cdx-text-sm cdx-text-gray-400 cdx-mt-2" >
59
60
sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
60
61
</ div >
61
- < input
62
- name = "openAiKey"
63
- placeholder = "Enter your OpenAI API key"
64
- data-error = { error ? 'true' : undefined }
65
- className = "cdx-mt-4 cdx-text-center cdx-p-2 cdx-w-full cdx-rounded-md cdx-border dark:cdx-border-neutral-600 cdx-border-neutral-200 dark:cdx-bg-neutral-800/90 cdx-bg-neutral-200/90 focus:cdx-outline-none focus:cdx-ring-2 focus:cdx-ring-blue-900 focus:cdx-ring-opacity-50 data-[error]:cdx-text-red-500"
66
- />
67
- < input
68
- name = "openAiBaseUrl"
69
- placeholder = "Enter your OpenAI Base URL"
70
- className = "cdx-mt-4 cdx-text-center cdx-p-2 cdx-w-full cdx-rounded-md cdx-border dark:cdx-border-neutral-600 cdx-border-neutral-200 dark:cdx-bg-neutral-800/90 cdx-bg-neutral-200/90 focus:cdx-outline-none focus:cdx-ring-2 focus:cdx-ring-blue-900 focus:cdx-ring-opacity-50 data-[error]:cdx-text-red-500"
71
- />
62
+
63
+ < div className = "cdx-w-full cdx-mt-6" >
64
+ < label
65
+ htmlFor = "openAiKey"
66
+ className = "cdx-block cdx-text-center cdx-text-sm cdx-text-gray-500 dark:cdx-text-gray-400 cdx-mb-2"
67
+ >
68
+ API Key
69
+ </ label >
70
+ < input
71
+ id = "openAiKey"
72
+ name = "openAiKey"
73
+ placeholder = "Paste your OpenAI API key"
74
+ data-error = { error ? 'true' : undefined }
75
+ className = "cdx-text-center cdx-p-2 cdx-w-full cdx-rounded-md cdx-border dark:cdx-border-neutral-600 cdx-border-neutral-200 dark:cdx-bg-neutral-800/90 cdx-bg-neutral-200/90 focus:cdx-outline-none focus:cdx-ring-2 focus:cdx-ring-blue-900 focus:cdx-ring-opacity-50 data-[error]:cdx-text-red-500"
76
+ />
77
+ </ div >
78
+
79
+ < button
80
+ type = "button"
81
+ onClick = { ( ) => setShowAdvanced ( ! showAdvanced ) }
82
+ className = "cdx-mt-4 cdx-text-sm cdx-text-blue-400 hover:cdx-underline"
83
+ >
84
+ { showAdvanced ? 'Hide Advanced Settings' : 'Show Advanced Settings' }
85
+ </ button >
86
+
87
+ { showAdvanced && (
88
+ < div className = "cdx-w-full cdx-mt-4" >
89
+ < label
90
+ htmlFor = "openAiBaseUrl"
91
+ className = "cdx-block cdx-text-center cdx-text-sm cdx-text-gray-500 dark:cdx-text-gray-400 cdx-mb-2"
92
+ >
93
+ Base URL (optional)
94
+ </ label >
95
+ < input
96
+ id = "openAiBaseUrl"
97
+ name = "openAiBaseUrl"
98
+ placeholder = "https://api.openai.com/v1"
99
+ defaultValue = "https://api.openai.com/v1"
100
+ className = "cdx-text-center cdx-p-2 cdx-w-full cdx-rounded-md cdx-border dark:cdx-border-neutral-600 cdx-border-neutral-200 dark:cdx-bg-neutral-800/90 cdx-bg-neutral-200/90 focus:cdx-outline-none focus:cdx-ring-2 focus:cdx-ring-blue-900 focus:cdx-ring-opacity-50"
101
+ />
102
+ </ div >
103
+ ) }
72
104
73
105
{ error && (
74
106
< div className = "cdx-text-sm cdx-text-red-500 cdx-mt-2" > { error } </ div >
@@ -80,6 +112,7 @@ const Auth = () => {
80
112
>
81
113
Submit
82
114
</ button >
115
+
83
116
< div className = "cdx-text-sm cdx-text-gray-400 cdx-mt-2" >
84
117
(Note: we only store your key locally. We do not send it anywhere. You
85
118
can check the{ ' ' }
0 commit comments