settings.tsx 30 KB

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