settings.tsx 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  1. import { useState, useEffect, useMemo } from "react";
  2. import styles from "./settings.module.scss";
  3. import ResetIcon from "../icons/reload.svg";
  4. import AddIcon from "../icons/add.svg";
  5. import CloseIcon from "../icons/close.svg";
  6. import CopyIcon from "../icons/copy.svg";
  7. import ClearIcon from "../icons/clear.svg";
  8. import LoadingIcon from "../icons/three-dots.svg";
  9. import EditIcon from "../icons/edit.svg";
  10. import EyeIcon from "../icons/eye.svg";
  11. import DownloadIcon from "../icons/download.svg";
  12. import UploadIcon from "../icons/upload.svg";
  13. import ConfigIcon from "../icons/config.svg";
  14. import ConfirmIcon from "../icons/confirm.svg";
  15. import ConnectionIcon from "../icons/connection.svg";
  16. import CloudSuccessIcon from "../icons/cloud-success.svg";
  17. import CloudFailIcon from "../icons/cloud-fail.svg";
  18. import {
  19. Input,
  20. List,
  21. ListItem,
  22. Modal,
  23. PasswordInput,
  24. Popover,
  25. Select,
  26. showConfirm,
  27. showToast,
  28. } from "./ui-lib";
  29. import { IconButton } from "./button";
  30. import {
  31. useChatStore,
  32. useUpdateStore,
  33. useAccessStore,
  34. useAppConfig,
  35. } from "../store";
  36. import Locale, {
  37. AllLangs,
  38. ALL_LANG_OPTIONS,
  39. changeLang,
  40. getLang,
  41. } from "../locales";
  42. import { copyToClipboard } from "../utils";
  43. import Link from "next/link";
  44. import { Path, RELEASE_URL, STORAGE_KEY, UPDATE_URL } from "../constant";
  45. import { Prompt, SearchService, usePromptStore } from "../store/prompt";
  46. import { ErrorBoundary } from "./error";
  47. import { InputRange } from "./input-range";
  48. import { useNavigate } from "react-router-dom";
  49. import { Avatar, AvatarPicker } from "./emoji";
  50. import { getClientConfig } from "../config/client";
  51. import { useSyncStore } from "../store/sync";
  52. import { nanoid } from "nanoid";
  53. import { useMaskStore } from "../store/mask";
  54. import { ProviderType } from "../utils/cloud";
  55. import {
  56. ChatConfigList,
  57. ModelConfigList,
  58. ProviderConfigList,
  59. ProviderSelectItem,
  60. } from "./config";
  61. import { SubmitKey, Theme } from "../typing";
  62. import { deepClone } from "../utils/clone";
  63. function EditPromptModal(props: { id: string; onClose: () => void }) {
  64. const promptStore = usePromptStore();
  65. const prompt = promptStore.get(props.id);
  66. return prompt ? (
  67. <div className="modal-mask">
  68. <Modal
  69. title={Locale.Settings.Prompt.EditModal.Title}
  70. onClose={props.onClose}
  71. actions={[
  72. <IconButton
  73. key=""
  74. onClick={props.onClose}
  75. text={Locale.UI.Confirm}
  76. bordered
  77. />,
  78. ]}
  79. >
  80. <div className={styles["edit-prompt-modal"]}>
  81. <input
  82. type="text"
  83. value={prompt.title}
  84. readOnly={!prompt.isUser}
  85. className={styles["edit-prompt-title"]}
  86. onInput={(e) =>
  87. promptStore.updatePrompt(
  88. props.id,
  89. (prompt) => (prompt.title = e.currentTarget.value),
  90. )
  91. }
  92. ></input>
  93. <Input
  94. value={prompt.content}
  95. readOnly={!prompt.isUser}
  96. className={styles["edit-prompt-content"]}
  97. rows={10}
  98. onInput={(e) =>
  99. promptStore.updatePrompt(
  100. props.id,
  101. (prompt) => (prompt.content = e.currentTarget.value),
  102. )
  103. }
  104. ></Input>
  105. </div>
  106. </Modal>
  107. </div>
  108. ) : null;
  109. }
  110. function UserPromptModal(props: { onClose?: () => void }) {
  111. const promptStore = usePromptStore();
  112. const userPrompts = promptStore.getUserPrompts();
  113. const builtinPrompts = SearchService.builtinPrompts;
  114. const allPrompts = userPrompts.concat(builtinPrompts);
  115. const [searchInput, setSearchInput] = useState("");
  116. const [searchPrompts, setSearchPrompts] = useState<Prompt[]>([]);
  117. const prompts = searchInput.length > 0 ? searchPrompts : allPrompts;
  118. const [editingPromptId, setEditingPromptId] = useState<string>();
  119. useEffect(() => {
  120. if (searchInput.length > 0) {
  121. const searchResult = SearchService.search(searchInput);
  122. setSearchPrompts(searchResult);
  123. } else {
  124. setSearchPrompts([]);
  125. }
  126. }, [searchInput]);
  127. return (
  128. <div className="modal-mask">
  129. <Modal
  130. title={Locale.Settings.Prompt.Modal.Title}
  131. onClose={() => props.onClose?.()}
  132. actions={[
  133. <IconButton
  134. key="add"
  135. onClick={() => {
  136. const promptId = promptStore.add({
  137. id: nanoid(),
  138. createdAt: Date.now(),
  139. title: "Empty Prompt",
  140. content: "Empty Prompt Content",
  141. });
  142. setEditingPromptId(promptId);
  143. }}
  144. icon={<AddIcon />}
  145. bordered
  146. text={Locale.Settings.Prompt.Modal.Add}
  147. />,
  148. ]}
  149. >
  150. <div className={styles["user-prompt-modal"]}>
  151. <input
  152. type="text"
  153. className={styles["user-prompt-search"]}
  154. placeholder={Locale.Settings.Prompt.Modal.Search}
  155. value={searchInput}
  156. onInput={(e) => setSearchInput(e.currentTarget.value)}
  157. ></input>
  158. <div className={styles["user-prompt-list"]}>
  159. {prompts.map((v, _) => (
  160. <div className={styles["user-prompt-item"]} key={v.id ?? v.title}>
  161. <div className={styles["user-prompt-header"]}>
  162. <div className={styles["user-prompt-title"]}>{v.title}</div>
  163. <div className={styles["user-prompt-content"] + " one-line"}>
  164. {v.content}
  165. </div>
  166. </div>
  167. <div className={styles["user-prompt-buttons"]}>
  168. {v.isUser && (
  169. <IconButton
  170. icon={<ClearIcon />}
  171. className={styles["user-prompt-button"]}
  172. onClick={() => promptStore.remove(v.id!)}
  173. />
  174. )}
  175. {v.isUser ? (
  176. <IconButton
  177. icon={<EditIcon />}
  178. className={styles["user-prompt-button"]}
  179. onClick={() => setEditingPromptId(v.id)}
  180. />
  181. ) : (
  182. <IconButton
  183. icon={<EyeIcon />}
  184. className={styles["user-prompt-button"]}
  185. onClick={() => setEditingPromptId(v.id)}
  186. />
  187. )}
  188. <IconButton
  189. icon={<CopyIcon />}
  190. className={styles["user-prompt-button"]}
  191. onClick={() => copyToClipboard(v.content)}
  192. />
  193. </div>
  194. </div>
  195. ))}
  196. </div>
  197. </div>
  198. </Modal>
  199. {editingPromptId !== undefined && (
  200. <EditPromptModal
  201. id={editingPromptId!}
  202. onClose={() => setEditingPromptId(undefined)}
  203. />
  204. )}
  205. </div>
  206. );
  207. }
  208. function DangerItems() {
  209. const chatStore = useChatStore();
  210. const appConfig = useAppConfig();
  211. return (
  212. <List>
  213. <ListItem
  214. title={Locale.Settings.Danger.Reset.Title}
  215. subTitle={Locale.Settings.Danger.Reset.SubTitle}
  216. >
  217. <IconButton
  218. text={Locale.Settings.Danger.Reset.Action}
  219. onClick={async () => {
  220. if (await showConfirm(Locale.Settings.Danger.Reset.Confirm)) {
  221. appConfig.reset();
  222. }
  223. }}
  224. type="danger"
  225. />
  226. </ListItem>
  227. <ListItem
  228. title={Locale.Settings.Danger.Clear.Title}
  229. subTitle={Locale.Settings.Danger.Clear.SubTitle}
  230. >
  231. <IconButton
  232. text={Locale.Settings.Danger.Clear.Action}
  233. onClick={async () => {
  234. if (await showConfirm(Locale.Settings.Danger.Clear.Confirm)) {
  235. chatStore.clearAllData();
  236. }
  237. }}
  238. type="danger"
  239. />
  240. </ListItem>
  241. </List>
  242. );
  243. }
  244. function CheckButton() {
  245. const syncStore = useSyncStore();
  246. const couldCheck = useMemo(() => {
  247. return syncStore.coundSync();
  248. }, [syncStore]);
  249. const [checkState, setCheckState] = useState<
  250. "none" | "checking" | "success" | "failed"
  251. >("none");
  252. async function check() {
  253. setCheckState("checking");
  254. const valid = await syncStore.check();
  255. setCheckState(valid ? "success" : "failed");
  256. }
  257. if (!couldCheck) return null;
  258. return (
  259. <IconButton
  260. text={Locale.Settings.Sync.Config.Modal.Check}
  261. bordered
  262. onClick={check}
  263. icon={
  264. checkState === "none" ? (
  265. <ConnectionIcon />
  266. ) : checkState === "checking" ? (
  267. <LoadingIcon />
  268. ) : checkState === "success" ? (
  269. <CloudSuccessIcon />
  270. ) : checkState === "failed" ? (
  271. <CloudFailIcon />
  272. ) : (
  273. <ConnectionIcon />
  274. )
  275. }
  276. ></IconButton>
  277. );
  278. }
  279. function SyncConfigModal(props: { onClose?: () => void }) {
  280. const syncStore = useSyncStore();
  281. return (
  282. <div className="modal-mask">
  283. <Modal
  284. title={Locale.Settings.Sync.Config.Modal.Title}
  285. onClose={() => props.onClose?.()}
  286. actions={[
  287. <CheckButton key="check" />,
  288. <IconButton
  289. key="confirm"
  290. onClick={props.onClose}
  291. icon={<ConfirmIcon />}
  292. bordered
  293. text={Locale.UI.Confirm}
  294. />,
  295. ]}
  296. >
  297. <List>
  298. <ListItem
  299. title={Locale.Settings.Sync.Config.SyncType.Title}
  300. subTitle={Locale.Settings.Sync.Config.SyncType.SubTitle}
  301. >
  302. <select
  303. value={syncStore.provider}
  304. onChange={(e) => {
  305. syncStore.update(
  306. (config) =>
  307. (config.provider = e.target.value as ProviderType),
  308. );
  309. }}
  310. >
  311. {Object.entries(ProviderType).map(([k, v]) => (
  312. <option value={v} key={k}>
  313. {k}
  314. </option>
  315. ))}
  316. </select>
  317. </ListItem>
  318. <ListItem
  319. title={Locale.Settings.Sync.Config.Proxy.Title}
  320. subTitle={Locale.Settings.Sync.Config.Proxy.SubTitle}
  321. >
  322. <input
  323. type="checkbox"
  324. checked={syncStore.useProxy}
  325. onChange={(e) => {
  326. syncStore.update(
  327. (config) => (config.useProxy = e.currentTarget.checked),
  328. );
  329. }}
  330. ></input>
  331. </ListItem>
  332. {syncStore.useProxy ? (
  333. <ListItem
  334. title={Locale.Settings.Sync.Config.ProxyUrl.Title}
  335. subTitle={Locale.Settings.Sync.Config.ProxyUrl.SubTitle}
  336. >
  337. <input
  338. type="text"
  339. value={syncStore.proxyUrl}
  340. onChange={(e) => {
  341. syncStore.update(
  342. (config) => (config.proxyUrl = e.currentTarget.value),
  343. );
  344. }}
  345. ></input>
  346. </ListItem>
  347. ) : null}
  348. </List>
  349. {syncStore.provider === ProviderType.WebDAV && (
  350. <>
  351. <List>
  352. <ListItem title={Locale.Settings.Sync.Config.WebDav.Endpoint}>
  353. <input
  354. type="text"
  355. value={syncStore.webdav.endpoint}
  356. onChange={(e) => {
  357. syncStore.update(
  358. (config) =>
  359. (config.webdav.endpoint = e.currentTarget.value),
  360. );
  361. }}
  362. ></input>
  363. </ListItem>
  364. <ListItem title={Locale.Settings.Sync.Config.WebDav.UserName}>
  365. <input
  366. type="text"
  367. value={syncStore.webdav.username}
  368. onChange={(e) => {
  369. syncStore.update(
  370. (config) =>
  371. (config.webdav.username = e.currentTarget.value),
  372. );
  373. }}
  374. ></input>
  375. </ListItem>
  376. <ListItem title={Locale.Settings.Sync.Config.WebDav.Password}>
  377. <PasswordInput
  378. value={syncStore.webdav.password}
  379. onChange={(e) => {
  380. syncStore.update(
  381. (config) =>
  382. (config.webdav.password = e.currentTarget.value),
  383. );
  384. }}
  385. ></PasswordInput>
  386. </ListItem>
  387. </List>
  388. </>
  389. )}
  390. {syncStore.provider === ProviderType.UpStash && (
  391. <List>
  392. <ListItem title={Locale.Settings.Sync.Config.UpStash.Endpoint}>
  393. <input
  394. type="text"
  395. value={syncStore.upstash.endpoint}
  396. onChange={(e) => {
  397. syncStore.update(
  398. (config) =>
  399. (config.upstash.endpoint = e.currentTarget.value),
  400. );
  401. }}
  402. ></input>
  403. </ListItem>
  404. <ListItem title={Locale.Settings.Sync.Config.UpStash.UserName}>
  405. <input
  406. type="text"
  407. value={syncStore.upstash.username}
  408. placeholder={STORAGE_KEY}
  409. onChange={(e) => {
  410. syncStore.update(
  411. (config) =>
  412. (config.upstash.username = e.currentTarget.value),
  413. );
  414. }}
  415. ></input>
  416. </ListItem>
  417. <ListItem title={Locale.Settings.Sync.Config.UpStash.Password}>
  418. <PasswordInput
  419. value={syncStore.upstash.apiKey}
  420. onChange={(e) => {
  421. syncStore.update(
  422. (config) => (config.upstash.apiKey = e.currentTarget.value),
  423. );
  424. }}
  425. ></PasswordInput>
  426. </ListItem>
  427. </List>
  428. )}
  429. </Modal>
  430. </div>
  431. );
  432. }
  433. function SyncItems() {
  434. const syncStore = useSyncStore();
  435. const chatStore = useChatStore();
  436. const promptStore = usePromptStore();
  437. const maskStore = useMaskStore();
  438. const couldSync = useMemo(() => {
  439. return syncStore.coundSync();
  440. }, [syncStore]);
  441. const [showSyncConfigModal, setShowSyncConfigModal] = useState(false);
  442. const stateOverview = useMemo(() => {
  443. const sessions = chatStore.sessions;
  444. const messageCount = sessions.reduce((p, c) => p + c.messages.length, 0);
  445. return {
  446. chat: sessions.length,
  447. message: messageCount,
  448. prompt: Object.keys(promptStore.prompts).length,
  449. mask: Object.keys(maskStore.masks).length,
  450. };
  451. }, [chatStore.sessions, maskStore.masks, promptStore.prompts]);
  452. return (
  453. <>
  454. <List>
  455. <ListItem
  456. title={Locale.Settings.Sync.CloudState}
  457. subTitle={
  458. syncStore.lastProvider
  459. ? `${new Date(syncStore.lastSyncTime).toLocaleString()} [${
  460. syncStore.lastProvider
  461. }]`
  462. : Locale.Settings.Sync.NotSyncYet
  463. }
  464. >
  465. <div style={{ display: "flex" }}>
  466. <IconButton
  467. icon={<ConfigIcon />}
  468. text={Locale.UI.Config}
  469. onClick={() => {
  470. setShowSyncConfigModal(true);
  471. }}
  472. />
  473. {couldSync && (
  474. <IconButton
  475. icon={<ResetIcon />}
  476. text={Locale.UI.Sync}
  477. onClick={async () => {
  478. try {
  479. await syncStore.sync();
  480. showToast(Locale.Settings.Sync.Success);
  481. } catch (e) {
  482. showToast(Locale.Settings.Sync.Fail);
  483. console.error("[Sync]", e);
  484. }
  485. }}
  486. />
  487. )}
  488. </div>
  489. </ListItem>
  490. <ListItem
  491. title={Locale.Settings.Sync.LocalState}
  492. subTitle={Locale.Settings.Sync.Overview(stateOverview)}
  493. >
  494. <div style={{ display: "flex" }}>
  495. <IconButton
  496. icon={<UploadIcon />}
  497. text={Locale.UI.Export}
  498. onClick={() => {
  499. syncStore.export();
  500. }}
  501. />
  502. <IconButton
  503. icon={<DownloadIcon />}
  504. text={Locale.UI.Import}
  505. onClick={() => {
  506. syncStore.import();
  507. }}
  508. />
  509. </div>
  510. </ListItem>
  511. </List>
  512. {showSyncConfigModal && (
  513. <SyncConfigModal onClose={() => setShowSyncConfigModal(false)} />
  514. )}
  515. </>
  516. );
  517. }
  518. export function Settings() {
  519. const navigate = useNavigate();
  520. const [showEmojiPicker, setShowEmojiPicker] = useState(false);
  521. const config = useAppConfig();
  522. const updateConfig = config.update;
  523. const updateStore = useUpdateStore();
  524. const [checkingUpdate, setCheckingUpdate] = useState(false);
  525. const currentVersion = updateStore.formatVersion(updateStore.version);
  526. const remoteId = updateStore.formatVersion(updateStore.remoteVersion);
  527. const hasNewVersion = currentVersion !== remoteId;
  528. const updateUrl = getClientConfig()?.isApp ? RELEASE_URL : UPDATE_URL;
  529. function checkUpdate(force = false) {
  530. setCheckingUpdate(true);
  531. updateStore.getLatestVersion(force).then(() => {
  532. setCheckingUpdate(false);
  533. });
  534. console.log("[Update] local version ", updateStore.version);
  535. console.log("[Update] remote version ", updateStore.remoteVersion);
  536. }
  537. const accessStore = useAccessStore();
  538. const enabledAccessControl = useMemo(
  539. () => accessStore.enabledAccessControl(),
  540. // eslint-disable-next-line react-hooks/exhaustive-deps
  541. [],
  542. );
  543. const promptStore = usePromptStore();
  544. const builtinCount = SearchService.count.builtin;
  545. const customCount = promptStore.getUserPrompts().length ?? 0;
  546. const [shouldShowPromptModal, setShowPromptModal] = useState(false);
  547. const showUsage = accessStore.isAuthorized();
  548. useEffect(() => {
  549. // checks per minutes
  550. checkUpdate();
  551. // eslint-disable-next-line react-hooks/exhaustive-deps
  552. }, []);
  553. useEffect(() => {
  554. const keydownEvent = (e: KeyboardEvent) => {
  555. if (e.key === "Escape") {
  556. navigate(Path.Home);
  557. }
  558. };
  559. document.addEventListener("keydown", keydownEvent);
  560. return () => {
  561. document.removeEventListener("keydown", keydownEvent);
  562. };
  563. // eslint-disable-next-line react-hooks/exhaustive-deps
  564. }, []);
  565. const clientConfig = useMemo(() => getClientConfig(), []);
  566. const showAccessCode = enabledAccessControl && !clientConfig?.isApp;
  567. return (
  568. <ErrorBoundary>
  569. <div className="window-header" data-tauri-drag-region>
  570. <div className="window-header-title">
  571. <div className="window-header-main-title">
  572. {Locale.Settings.Title}
  573. </div>
  574. <div className="window-header-sub-title">
  575. {Locale.Settings.SubTitle}
  576. </div>
  577. </div>
  578. <div className="window-actions">
  579. <div className="window-action-button"></div>
  580. <div className="window-action-button"></div>
  581. <div className="window-action-button">
  582. <IconButton
  583. icon={<CloseIcon />}
  584. onClick={() => navigate(Path.Home)}
  585. bordered
  586. />
  587. </div>
  588. </div>
  589. </div>
  590. <div className={styles["settings"]}>
  591. <List>
  592. <ListItem title={Locale.Settings.Avatar}>
  593. <Popover
  594. onClose={() => setShowEmojiPicker(false)}
  595. content={
  596. <AvatarPicker
  597. onEmojiClick={(avatar: string) => {
  598. updateConfig((config) => (config.avatar = avatar));
  599. setShowEmojiPicker(false);
  600. }}
  601. />
  602. }
  603. open={showEmojiPicker}
  604. >
  605. <div
  606. className={styles.avatar}
  607. onClick={() => setShowEmojiPicker(true)}
  608. >
  609. <Avatar avatar={config.avatar} />
  610. </div>
  611. </Popover>
  612. </ListItem>
  613. <ListItem
  614. title={Locale.Settings.Update.Version(currentVersion ?? "unknown")}
  615. subTitle={
  616. checkingUpdate
  617. ? Locale.Settings.Update.IsChecking
  618. : hasNewVersion
  619. ? Locale.Settings.Update.FoundUpdate(remoteId ?? "ERROR")
  620. : Locale.Settings.Update.IsLatest
  621. }
  622. >
  623. {checkingUpdate ? (
  624. <LoadingIcon />
  625. ) : hasNewVersion ? (
  626. <Link href={updateUrl} target="_blank" className="link">
  627. {Locale.Settings.Update.GoToUpdate}
  628. </Link>
  629. ) : (
  630. <IconButton
  631. icon={<ResetIcon></ResetIcon>}
  632. text={Locale.Settings.Update.CheckUpdate}
  633. onClick={() => checkUpdate(true)}
  634. />
  635. )}
  636. </ListItem>
  637. <ListItem title={Locale.Settings.SendKey}>
  638. <Select
  639. value={config.submitKey}
  640. onChange={(e) => {
  641. updateConfig(
  642. (config) =>
  643. (config.submitKey = e.target.value as any as SubmitKey),
  644. );
  645. }}
  646. >
  647. {Object.values(SubmitKey).map((v) => (
  648. <option value={v} key={v}>
  649. {v}
  650. </option>
  651. ))}
  652. </Select>
  653. </ListItem>
  654. <ListItem title={Locale.Settings.Theme}>
  655. <Select
  656. value={config.theme}
  657. onChange={(e) => {
  658. updateConfig(
  659. (config) => (config.theme = e.target.value as any as Theme),
  660. );
  661. }}
  662. >
  663. {Object.values(Theme).map((v) => (
  664. <option value={v} key={v}>
  665. {v}
  666. </option>
  667. ))}
  668. </Select>
  669. </ListItem>
  670. <ListItem title={Locale.Settings.Lang.Name}>
  671. <Select
  672. value={getLang()}
  673. onChange={(e) => {
  674. changeLang(e.target.value as any);
  675. }}
  676. >
  677. {AllLangs.map((lang) => (
  678. <option value={lang} key={lang}>
  679. {ALL_LANG_OPTIONS[lang]}
  680. </option>
  681. ))}
  682. </Select>
  683. </ListItem>
  684. <ListItem
  685. title={Locale.Settings.FontSize.Title}
  686. subTitle={Locale.Settings.FontSize.SubTitle}
  687. >
  688. <InputRange
  689. title={`${config.fontSize ?? 14}px`}
  690. value={config.fontSize}
  691. min="12"
  692. max="40"
  693. step="1"
  694. onChange={(e) =>
  695. updateConfig(
  696. (config) => (config.fontSize = e.currentTarget.valueAsNumber),
  697. )
  698. }
  699. ></InputRange>
  700. </ListItem>
  701. <ListItem
  702. title={Locale.Settings.AutoGenerateTitle.Title}
  703. subTitle={Locale.Settings.AutoGenerateTitle.SubTitle}
  704. >
  705. <input
  706. type="checkbox"
  707. checked={
  708. config.globalMaskConfig.chatConfig.enableAutoGenerateTitle
  709. }
  710. onChange={(e) =>
  711. updateConfig(
  712. (config) =>
  713. (config.globalMaskConfig.chatConfig.enableAutoGenerateTitle =
  714. e.currentTarget.checked),
  715. )
  716. }
  717. ></input>
  718. </ListItem>
  719. <ListItem
  720. title={Locale.Settings.SendPreviewBubble.Title}
  721. subTitle={Locale.Settings.SendPreviewBubble.SubTitle}
  722. >
  723. <input
  724. type="checkbox"
  725. checked={config.sendPreviewBubble}
  726. onChange={(e) =>
  727. updateConfig(
  728. (config) =>
  729. (config.sendPreviewBubble = e.currentTarget.checked),
  730. )
  731. }
  732. ></input>
  733. </ListItem>
  734. </List>
  735. <List>
  736. {showAccessCode ? (
  737. <ListItem
  738. title={Locale.Settings.AccessCode.Title}
  739. subTitle={Locale.Settings.AccessCode.SubTitle}
  740. >
  741. <PasswordInput
  742. value={accessStore.accessCode}
  743. type="text"
  744. placeholder={Locale.Settings.AccessCode.Placeholder}
  745. onChange={(e) => {
  746. accessStore.update(
  747. (config) => (config.accessCode = e.currentTarget.value),
  748. );
  749. }}
  750. />
  751. </ListItem>
  752. ) : (
  753. <></>
  754. )}
  755. </List>
  756. <SyncItems />
  757. <List>
  758. <ListItem
  759. title={Locale.Settings.Mask.Splash.Title}
  760. subTitle={Locale.Settings.Mask.Splash.SubTitle}
  761. >
  762. <input
  763. type="checkbox"
  764. checked={!config.dontShowMaskSplashScreen}
  765. onChange={(e) =>
  766. updateConfig(
  767. (config) =>
  768. (config.dontShowMaskSplashScreen =
  769. !e.currentTarget.checked),
  770. )
  771. }
  772. ></input>
  773. </ListItem>
  774. <ListItem
  775. title={Locale.Settings.Mask.Builtin.Title}
  776. subTitle={Locale.Settings.Mask.Builtin.SubTitle}
  777. >
  778. <input
  779. type="checkbox"
  780. checked={config.hideBuiltinMasks}
  781. onChange={(e) =>
  782. updateConfig(
  783. (config) =>
  784. (config.hideBuiltinMasks = e.currentTarget.checked),
  785. )
  786. }
  787. ></input>
  788. </ListItem>
  789. </List>
  790. <List>
  791. <ListItem
  792. title={Locale.Settings.Prompt.Disable.Title}
  793. subTitle={Locale.Settings.Prompt.Disable.SubTitle}
  794. >
  795. <input
  796. type="checkbox"
  797. checked={config.disablePromptHint}
  798. onChange={(e) =>
  799. updateConfig(
  800. (config) =>
  801. (config.disablePromptHint = e.currentTarget.checked),
  802. )
  803. }
  804. ></input>
  805. </ListItem>
  806. <ListItem
  807. title={Locale.Settings.Prompt.List}
  808. subTitle={Locale.Settings.Prompt.ListCount(
  809. builtinCount,
  810. customCount,
  811. )}
  812. >
  813. <IconButton
  814. icon={<EditIcon />}
  815. text={Locale.Settings.Prompt.Edit}
  816. onClick={() => setShowPromptModal(true)}
  817. />
  818. </ListItem>
  819. </List>
  820. <List>
  821. <ProviderSelectItem
  822. value={config.globalMaskConfig.provider}
  823. update={(value) =>
  824. config.update((_config) => {
  825. _config.globalMaskConfig.provider = value;
  826. })
  827. }
  828. />
  829. <ProviderConfigList
  830. provider={config.globalMaskConfig.provider}
  831. config={config.providerConfig}
  832. updateConfig={(update) => {
  833. config.update((_config) => update(_config.providerConfig));
  834. }}
  835. />
  836. <ModelConfigList
  837. provider={config.globalMaskConfig.provider}
  838. config={config.globalMaskConfig.modelConfig}
  839. updateConfig={(updater) => {
  840. const modelConfig = { ...config.globalMaskConfig.modelConfig };
  841. updater(modelConfig);
  842. config.update(
  843. (config) => (config.globalMaskConfig.modelConfig = modelConfig),
  844. );
  845. }}
  846. />
  847. <ChatConfigList
  848. config={config.globalMaskConfig.chatConfig}
  849. updateConfig={(updater) => {
  850. const chatConfig = deepClone(config.globalMaskConfig.chatConfig);
  851. updater(chatConfig);
  852. config.update(
  853. (config) => (config.globalMaskConfig.chatConfig = chatConfig),
  854. );
  855. }}
  856. />
  857. </List>
  858. {shouldShowPromptModal && (
  859. <UserPromptModal onClose={() => setShowPromptModal(false)} />
  860. )}
  861. <DangerItems />
  862. </div>
  863. </ErrorBoundary>
  864. );
  865. }