settings.tsx 40 KB

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