forked from InvolutionHell/involutionhell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsDialog.tsx
More file actions
196 lines (182 loc) · 7.17 KB
/
SettingsDialog.tsx
File metadata and controls
196 lines (182 loc) · 7.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
"use client";
import { useAssistantSettings } from "@/app/hooks/useAssistantSettings";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogFooter,
} from "@/components/ui/dialog";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { RadioGroup, RadioGroupItem } from "@/app/components/ui/radio-group";
import { Button } from "@/components/ui/button";
import { Checkbox } from "@/app/components/ui/checkbox";
import { AlertCircle } from "lucide-react";
interface SettingsDialogProps {
isOpen: boolean;
onOpenChange: (isOpen: boolean) => void;
}
export const SettingsDialog = ({
isOpen,
onOpenChange,
}: SettingsDialogProps) => {
const {
provider,
setProvider,
openaiApiKey,
setOpenaiApiKey,
geminiApiKey,
setGeminiApiKey,
saveToLocalStorage,
setSaveToLocalStorage,
refreshFromStorage,
} = useAssistantSettings();
const handleSave = () => {
// Force refresh from localStorage to ensure all components get the latest values
refreshFromStorage();
onOpenChange(false);
};
return (
<Dialog open={isOpen} onOpenChange={onOpenChange}>
<DialogContent>
<DialogHeader>
<DialogTitle>AI Assistant Settings</DialogTitle>
</DialogHeader>
<div className="space-y-4 py-4">
<div className="space-y-2">
<Label>AI Provider</Label>
<RadioGroup
value={provider}
onValueChange={(value) =>
setProvider(value as "openai" | "gemini" | "intern")
}
>
<div className="flex items-center space-x-2">
<RadioGroupItem value="intern" id="intern" />
<Label htmlFor="intern">InternS1 (Free)</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="openai" id="openai" />
<Label htmlFor="openai">OpenAI</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="gemini" id="gemini" />
<Label htmlFor="gemini">Google Gemini</Label>
</div>
</RadioGroup>
</div>
{provider === "openai" && (
<div className="space-y-4">
<div className="space-y-2">
<Label htmlFor="openai-key">OpenAI API Key</Label>
<Input
id="openai-key"
type="password"
placeholder="sk-..."
value={openaiApiKey}
onChange={(e) => setOpenaiApiKey(e.target.value)}
/>
</div>
<div className="space-y-3">
<div className="flex items-center space-x-2">
<Checkbox
id="save-to-storage"
checked={saveToLocalStorage}
onCheckedChange={(checked) =>
setSaveToLocalStorage(checked === true)
}
/>
<Label
htmlFor="save-to-storage"
className="text-sm font-normal cursor-pointer"
>
保存 API Key 到本地存储
</Label>
</div>
{saveToLocalStorage && (
<div className="rounded-lg border border-amber-200 bg-amber-50 dark:border-amber-900/50 dark:bg-amber-950/20 p-3">
<div className="flex gap-2">
<AlertCircle className="size-4 text-amber-600 dark:text-amber-500 shrink-0 mt-0.5" />
<div className="space-y-1 text-xs text-amber-900 dark:text-amber-200">
<p className="font-medium">安全提示</p>
<ul className="space-y-0.5 list-disc list-inside">
<li>
API Key 将以明文形式存储在浏览器的 localStorage 中
</li>
<li>任何能访问此浏览器的人都可能获取您的 API Key</li>
<li>请勿在公用电脑或共享设备上勾选此选项</li>
<li>建议定期更换 API Key 以提高安全性</li>
</ul>
</div>
</div>
</div>
)}
</div>
</div>
)}
{provider === "gemini" && (
<div className="space-y-4">
<div className="space-y-2">
<Label htmlFor="gemini-key">Gemini API Key</Label>
<Input
id="gemini-key"
type="password"
placeholder="AIzaSy..."
value={geminiApiKey}
onChange={(e) => setGeminiApiKey(e.target.value)}
/>
</div>
<div className="space-y-3">
<div className="flex items-center space-x-2">
<Checkbox
id="save-to-storage"
checked={saveToLocalStorage}
onCheckedChange={(checked) =>
setSaveToLocalStorage(checked === true)
}
/>
<Label
htmlFor="save-to-storage"
className="text-sm font-normal cursor-pointer"
>
保存 API Key 到本地存储
</Label>
</div>
{saveToLocalStorage && (
<div className="rounded-lg border border-amber-200 bg-amber-50 dark:border-amber-900/50 dark:bg-amber-950/20 p-3">
<div className="flex gap-2">
<AlertCircle className="size-4 text-amber-600 dark:text-amber-500 shrink-0 mt-0.5" />
<div className="space-y-1 text-xs text-amber-900 dark:text-amber-200">
<p className="font-medium">安全提示</p>
<ul className="space-y-0.5 list-disc list-inside">
<li>
API Key 将以明文形式存储在浏览器的 localStorage 中
</li>
<li>任何能访问此浏览器的人都可能获取您的 API Key</li>
<li>请勿在公用电脑或共享设备上勾选此选项</li>
<li>建议定期更换 API Key 以提高安全性</li>
</ul>
</div>
</div>
</div>
)}
</div>
</div>
)}
{provider === "intern" && (
<div className="space-y-2">
<div className="text-sm text-muted-foreground">
感谢上海AILab的书生大模型对本项目的算力支持,Intern-AI
模型已预配置,无需提供 API Key。
</div>
</div>
)}
</div>
<DialogFooter>
<Button onClick={handleSave}>Save & Close</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
};