-
Notifications
You must be signed in to change notification settings - Fork 240
Expand file tree
/
Copy pathlocal-setting-dialog.tsx
More file actions
67 lines (56 loc) · 1.58 KB
/
local-setting-dialog.tsx
File metadata and controls
67 lines (56 loc) · 1.58 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
import { createDialog } from "@/components/create-dialog";
import LabelInput from "@/components/label-input";
import { Button } from "@/components/orbit/button";
import {
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import {
getAgentFromLocalStorage,
updateAgentFromLocalStorage,
} from "@/lib/ai-agent-storage";
import { useCallback, useEffect, useState } from "react";
export const localSettingDialog = createDialog(({ close }) => {
const [token, setToken] = useState<string>("");
useEffect(() => {
if (typeof window === "undefined") return;
const agentData = getAgentFromLocalStorage();
if (!agentData) return;
setToken(agentData.token);
}, []);
const onSaveClicked = useCallback(() => {
if (!token) return;
updateAgentFromLocalStorage({
provider: "openai",
model: "gpt-4o-mini",
token,
});
close(undefined);
}, [token, close]);
return (
<>
<DialogHeader>
<DialogTitle>Local Setting</DialogTitle>
<DialogDescription>
Bring your OpenAI token to enable the AI assistant. Your token is
stored in localStorage. We do not store your token on our server.
</DialogDescription>
</DialogHeader>
<LabelInput
type="password"
label="Token"
placeholder="Token"
size="lg"
value={token}
onValueChange={setToken}
/>
<DialogFooter>
<Button size="lg" variant="primary" onClick={onSaveClicked}>
Save
</Button>
</DialogFooter>
</>
);
});