settings.tsx 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665
  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. Baidu,
  51. Tencent,
  52. ByteDance,
  53. Alibaba,
  54. Moonshot,
  55. Google,
  56. GoogleSafetySettingsThreshold,
  57. OPENAI_BASE_URL,
  58. Path,
  59. RELEASE_URL,
  60. STORAGE_KEY,
  61. ServiceProvider,
  62. SlotID,
  63. UPDATE_URL,
  64. Stability,
  65. Iflytek,
  66. } from "../constant";
  67. import { Prompt, SearchService, usePromptStore } from "../store/prompt";
  68. import { ErrorBoundary } from "./error";
  69. import { InputRange } from "./input-range";
  70. import { useNavigate } from "react-router-dom";
  71. import { Avatar, AvatarPicker } from "./emoji";
  72. import { getClientConfig } from "../config/client";
  73. import { useSyncStore } from "../store/sync";
  74. import { nanoid } from "nanoid";
  75. import { useMaskStore } from "../store/mask";
  76. import { ProviderType } from "../utils/cloud";
  77. import { TTSConfigList } from "./tts-config";
  78. function EditPromptModal(props: { id: string; onClose: () => void }) {
  79. const promptStore = usePromptStore();
  80. const prompt = promptStore.get(props.id);
  81. return prompt ? (
  82. <div className="modal-mask">
  83. <Modal
  84. title={Locale.Settings.Prompt.EditModal.Title}
  85. onClose={props.onClose}
  86. actions={[
  87. <IconButton
  88. key=""
  89. onClick={props.onClose}
  90. text={Locale.UI.Confirm}
  91. bordered
  92. />,
  93. ]}
  94. >
  95. <div className={styles["edit-prompt-modal"]}>
  96. <input
  97. type="text"
  98. value={prompt.title}
  99. readOnly={!prompt.isUser}
  100. className={styles["edit-prompt-title"]}
  101. onInput={(e) =>
  102. promptStore.updatePrompt(
  103. props.id,
  104. (prompt) => (prompt.title = e.currentTarget.value),
  105. )
  106. }
  107. ></input>
  108. <Input
  109. value={prompt.content}
  110. readOnly={!prompt.isUser}
  111. className={styles["edit-prompt-content"]}
  112. rows={10}
  113. onInput={(e) =>
  114. promptStore.updatePrompt(
  115. props.id,
  116. (prompt) => (prompt.content = e.currentTarget.value),
  117. )
  118. }
  119. ></Input>
  120. </div>
  121. </Modal>
  122. </div>
  123. ) : null;
  124. }
  125. function UserPromptModal(props: { onClose?: () => void }) {
  126. const promptStore = usePromptStore();
  127. const userPrompts = promptStore.getUserPrompts();
  128. const builtinPrompts = SearchService.builtinPrompts;
  129. const allPrompts = userPrompts.concat(builtinPrompts);
  130. const [searchInput, setSearchInput] = useState("");
  131. const [searchPrompts, setSearchPrompts] = useState<Prompt[]>([]);
  132. const prompts = searchInput.length > 0 ? searchPrompts : allPrompts;
  133. const [editingPromptId, setEditingPromptId] = useState<string>();
  134. useEffect(() => {
  135. if (searchInput.length > 0) {
  136. const searchResult = SearchService.search(searchInput);
  137. setSearchPrompts(searchResult);
  138. } else {
  139. setSearchPrompts([]);
  140. }
  141. }, [searchInput]);
  142. return (
  143. <div className="modal-mask">
  144. <Modal
  145. title={Locale.Settings.Prompt.Modal.Title}
  146. onClose={() => props.onClose?.()}
  147. actions={[
  148. <IconButton
  149. key="add"
  150. onClick={() => {
  151. const promptId = promptStore.add({
  152. id: nanoid(),
  153. createdAt: Date.now(),
  154. title: "Empty Prompt",
  155. content: "Empty Prompt Content",
  156. });
  157. setEditingPromptId(promptId);
  158. }}
  159. icon={<AddIcon />}
  160. bordered
  161. text={Locale.Settings.Prompt.Modal.Add}
  162. />,
  163. ]}
  164. >
  165. <div className={styles["user-prompt-modal"]}>
  166. <input
  167. type="text"
  168. className={styles["user-prompt-search"]}
  169. placeholder={Locale.Settings.Prompt.Modal.Search}
  170. value={searchInput}
  171. onInput={(e) => setSearchInput(e.currentTarget.value)}
  172. ></input>
  173. <div className={styles["user-prompt-list"]}>
  174. {prompts.map((v, _) => (
  175. <div className={styles["user-prompt-item"]} key={v.id ?? v.title}>
  176. <div className={styles["user-prompt-header"]}>
  177. <div className={styles["user-prompt-title"]}>{v.title}</div>
  178. <div className={styles["user-prompt-content"] + " one-line"}>
  179. {v.content}
  180. </div>
  181. </div>
  182. <div className={styles["user-prompt-buttons"]}>
  183. {v.isUser && (
  184. <IconButton
  185. icon={<ClearIcon />}
  186. className={styles["user-prompt-button"]}
  187. onClick={() => promptStore.remove(v.id!)}
  188. />
  189. )}
  190. {v.isUser ? (
  191. <IconButton
  192. icon={<EditIcon />}
  193. className={styles["user-prompt-button"]}
  194. onClick={() => setEditingPromptId(v.id)}
  195. />
  196. ) : (
  197. <IconButton
  198. icon={<EyeIcon />}
  199. className={styles["user-prompt-button"]}
  200. onClick={() => setEditingPromptId(v.id)}
  201. />
  202. )}
  203. <IconButton
  204. icon={<CopyIcon />}
  205. className={styles["user-prompt-button"]}
  206. onClick={() => copyToClipboard(v.content)}
  207. />
  208. </div>
  209. </div>
  210. ))}
  211. </div>
  212. </div>
  213. </Modal>
  214. {editingPromptId !== undefined && (
  215. <EditPromptModal
  216. id={editingPromptId!}
  217. onClose={() => setEditingPromptId(undefined)}
  218. />
  219. )}
  220. </div>
  221. );
  222. }
  223. function DangerItems() {
  224. const chatStore = useChatStore();
  225. const appConfig = useAppConfig();
  226. return (
  227. <List>
  228. <ListItem
  229. title={Locale.Settings.Danger.Reset.Title}
  230. subTitle={Locale.Settings.Danger.Reset.SubTitle}
  231. >
  232. <IconButton
  233. aria={Locale.Settings.Danger.Reset.Title}
  234. text={Locale.Settings.Danger.Reset.Action}
  235. onClick={async () => {
  236. if (await showConfirm(Locale.Settings.Danger.Reset.Confirm)) {
  237. appConfig.reset();
  238. }
  239. }}
  240. type="danger"
  241. />
  242. </ListItem>
  243. <ListItem
  244. title={Locale.Settings.Danger.Clear.Title}
  245. subTitle={Locale.Settings.Danger.Clear.SubTitle}
  246. >
  247. <IconButton
  248. aria={Locale.Settings.Danger.Clear.Title}
  249. text={Locale.Settings.Danger.Clear.Action}
  250. onClick={async () => {
  251. if (await showConfirm(Locale.Settings.Danger.Clear.Confirm)) {
  252. chatStore.clearAllData();
  253. }
  254. }}
  255. type="danger"
  256. />
  257. </ListItem>
  258. </List>
  259. );
  260. }
  261. function CheckButton() {
  262. const syncStore = useSyncStore();
  263. const couldCheck = useMemo(() => {
  264. return syncStore.cloudSync();
  265. }, [syncStore]);
  266. const [checkState, setCheckState] = useState<
  267. "none" | "checking" | "success" | "failed"
  268. >("none");
  269. async function check() {
  270. setCheckState("checking");
  271. const valid = await syncStore.check();
  272. setCheckState(valid ? "success" : "failed");
  273. }
  274. if (!couldCheck) return null;
  275. return (
  276. <IconButton
  277. text={Locale.Settings.Sync.Config.Modal.Check}
  278. bordered
  279. onClick={check}
  280. icon={
  281. checkState === "none" ? (
  282. <ConnectionIcon />
  283. ) : checkState === "checking" ? (
  284. <LoadingIcon />
  285. ) : checkState === "success" ? (
  286. <CloudSuccessIcon />
  287. ) : checkState === "failed" ? (
  288. <CloudFailIcon />
  289. ) : (
  290. <ConnectionIcon />
  291. )
  292. }
  293. ></IconButton>
  294. );
  295. }
  296. function SyncConfigModal(props: { onClose?: () => void }) {
  297. const syncStore = useSyncStore();
  298. return (
  299. <div className="modal-mask">
  300. <Modal
  301. title={Locale.Settings.Sync.Config.Modal.Title}
  302. onClose={() => props.onClose?.()}
  303. actions={[
  304. <CheckButton key="check" />,
  305. <IconButton
  306. key="confirm"
  307. onClick={props.onClose}
  308. icon={<ConfirmIcon />}
  309. bordered
  310. text={Locale.UI.Confirm}
  311. />,
  312. ]}
  313. >
  314. <List>
  315. <ListItem
  316. title={Locale.Settings.Sync.Config.SyncType.Title}
  317. subTitle={Locale.Settings.Sync.Config.SyncType.SubTitle}
  318. >
  319. <select
  320. value={syncStore.provider}
  321. onChange={(e) => {
  322. syncStore.update(
  323. (config) =>
  324. (config.provider = e.target.value as ProviderType),
  325. );
  326. }}
  327. >
  328. {Object.entries(ProviderType).map(([k, v]) => (
  329. <option value={v} key={k}>
  330. {k}
  331. </option>
  332. ))}
  333. </select>
  334. </ListItem>
  335. <ListItem
  336. title={Locale.Settings.Sync.Config.Proxy.Title}
  337. subTitle={Locale.Settings.Sync.Config.Proxy.SubTitle}
  338. >
  339. <input
  340. type="checkbox"
  341. checked={syncStore.useProxy}
  342. onChange={(e) => {
  343. syncStore.update(
  344. (config) => (config.useProxy = e.currentTarget.checked),
  345. );
  346. }}
  347. ></input>
  348. </ListItem>
  349. {syncStore.useProxy ? (
  350. <ListItem
  351. title={Locale.Settings.Sync.Config.ProxyUrl.Title}
  352. subTitle={Locale.Settings.Sync.Config.ProxyUrl.SubTitle}
  353. >
  354. <input
  355. type="text"
  356. value={syncStore.proxyUrl}
  357. onChange={(e) => {
  358. syncStore.update(
  359. (config) => (config.proxyUrl = e.currentTarget.value),
  360. );
  361. }}
  362. ></input>
  363. </ListItem>
  364. ) : null}
  365. </List>
  366. {syncStore.provider === ProviderType.WebDAV && (
  367. <>
  368. <List>
  369. <ListItem title={Locale.Settings.Sync.Config.WebDav.Endpoint}>
  370. <input
  371. type="text"
  372. value={syncStore.webdav.endpoint}
  373. onChange={(e) => {
  374. syncStore.update(
  375. (config) =>
  376. (config.webdav.endpoint = e.currentTarget.value),
  377. );
  378. }}
  379. ></input>
  380. </ListItem>
  381. <ListItem title={Locale.Settings.Sync.Config.WebDav.UserName}>
  382. <input
  383. type="text"
  384. value={syncStore.webdav.username}
  385. onChange={(e) => {
  386. syncStore.update(
  387. (config) =>
  388. (config.webdav.username = e.currentTarget.value),
  389. );
  390. }}
  391. ></input>
  392. </ListItem>
  393. <ListItem title={Locale.Settings.Sync.Config.WebDav.Password}>
  394. <PasswordInput
  395. value={syncStore.webdav.password}
  396. onChange={(e) => {
  397. syncStore.update(
  398. (config) =>
  399. (config.webdav.password = e.currentTarget.value),
  400. );
  401. }}
  402. ></PasswordInput>
  403. </ListItem>
  404. </List>
  405. </>
  406. )}
  407. {syncStore.provider === ProviderType.UpStash && (
  408. <List>
  409. <ListItem title={Locale.Settings.Sync.Config.UpStash.Endpoint}>
  410. <input
  411. type="text"
  412. value={syncStore.upstash.endpoint}
  413. onChange={(e) => {
  414. syncStore.update(
  415. (config) =>
  416. (config.upstash.endpoint = e.currentTarget.value),
  417. );
  418. }}
  419. ></input>
  420. </ListItem>
  421. <ListItem title={Locale.Settings.Sync.Config.UpStash.UserName}>
  422. <input
  423. type="text"
  424. value={syncStore.upstash.username}
  425. placeholder={STORAGE_KEY}
  426. onChange={(e) => {
  427. syncStore.update(
  428. (config) =>
  429. (config.upstash.username = e.currentTarget.value),
  430. );
  431. }}
  432. ></input>
  433. </ListItem>
  434. <ListItem title={Locale.Settings.Sync.Config.UpStash.Password}>
  435. <PasswordInput
  436. value={syncStore.upstash.apiKey}
  437. onChange={(e) => {
  438. syncStore.update(
  439. (config) => (config.upstash.apiKey = e.currentTarget.value),
  440. );
  441. }}
  442. ></PasswordInput>
  443. </ListItem>
  444. </List>
  445. )}
  446. </Modal>
  447. </div>
  448. );
  449. }
  450. function SyncItems() {
  451. const syncStore = useSyncStore();
  452. const chatStore = useChatStore();
  453. const promptStore = usePromptStore();
  454. const maskStore = useMaskStore();
  455. const couldSync = useMemo(() => {
  456. return syncStore.cloudSync();
  457. }, [syncStore]);
  458. const [showSyncConfigModal, setShowSyncConfigModal] = useState(false);
  459. const stateOverview = useMemo(() => {
  460. const sessions = chatStore.sessions;
  461. const messageCount = sessions.reduce((p, c) => p + c.messages.length, 0);
  462. return {
  463. chat: sessions.length,
  464. message: messageCount,
  465. prompt: Object.keys(promptStore.prompts).length,
  466. mask: Object.keys(maskStore.masks).length,
  467. };
  468. }, [chatStore.sessions, maskStore.masks, promptStore.prompts]);
  469. return (
  470. <>
  471. <List>
  472. <ListItem
  473. title={Locale.Settings.Sync.CloudState}
  474. subTitle={
  475. syncStore.lastProvider
  476. ? `${new Date(syncStore.lastSyncTime).toLocaleString()} [${
  477. syncStore.lastProvider
  478. }]`
  479. : Locale.Settings.Sync.NotSyncYet
  480. }
  481. >
  482. <div style={{ display: "flex" }}>
  483. <IconButton
  484. aria={Locale.Settings.Sync.CloudState + Locale.UI.Config}
  485. icon={<ConfigIcon />}
  486. text={Locale.UI.Config}
  487. onClick={() => {
  488. setShowSyncConfigModal(true);
  489. }}
  490. />
  491. {couldSync && (
  492. <IconButton
  493. icon={<ResetIcon />}
  494. text={Locale.UI.Sync}
  495. onClick={async () => {
  496. try {
  497. await syncStore.sync();
  498. showToast(Locale.Settings.Sync.Success);
  499. } catch (e) {
  500. showToast(Locale.Settings.Sync.Fail);
  501. console.error("[Sync]", e);
  502. }
  503. }}
  504. />
  505. )}
  506. </div>
  507. </ListItem>
  508. <ListItem
  509. title={Locale.Settings.Sync.LocalState}
  510. subTitle={Locale.Settings.Sync.Overview(stateOverview)}
  511. >
  512. <div style={{ display: "flex" }}>
  513. <IconButton
  514. aria={Locale.Settings.Sync.LocalState + Locale.UI.Export}
  515. icon={<UploadIcon />}
  516. text={Locale.UI.Export}
  517. onClick={() => {
  518. syncStore.export();
  519. }}
  520. />
  521. <IconButton
  522. aria={Locale.Settings.Sync.LocalState + Locale.UI.Import}
  523. icon={<DownloadIcon />}
  524. text={Locale.UI.Import}
  525. onClick={() => {
  526. syncStore.import();
  527. }}
  528. />
  529. </div>
  530. </ListItem>
  531. </List>
  532. {showSyncConfigModal && (
  533. <SyncConfigModal onClose={() => setShowSyncConfigModal(false)} />
  534. )}
  535. </>
  536. );
  537. }
  538. export function Settings() {
  539. const navigate = useNavigate();
  540. const [showEmojiPicker, setShowEmojiPicker] = useState(false);
  541. const config = useAppConfig();
  542. const updateConfig = config.update;
  543. const updateStore = useUpdateStore();
  544. const [checkingUpdate, setCheckingUpdate] = useState(false);
  545. const currentVersion = updateStore.formatVersion(updateStore.version);
  546. const remoteId = updateStore.formatVersion(updateStore.remoteVersion);
  547. const hasNewVersion = currentVersion !== remoteId;
  548. const updateUrl = getClientConfig()?.isApp ? RELEASE_URL : UPDATE_URL;
  549. function checkUpdate(force = false) {
  550. setCheckingUpdate(true);
  551. updateStore.getLatestVersion(force).then(() => {
  552. setCheckingUpdate(false);
  553. });
  554. console.log("[Update] local version ", updateStore.version);
  555. console.log("[Update] remote version ", updateStore.remoteVersion);
  556. }
  557. const accessStore = useAccessStore();
  558. const shouldHideBalanceQuery = useMemo(() => {
  559. const isOpenAiUrl = accessStore.openaiUrl.includes(OPENAI_BASE_URL);
  560. return (
  561. accessStore.hideBalanceQuery ||
  562. isOpenAiUrl ||
  563. accessStore.provider === ServiceProvider.Azure
  564. );
  565. }, [
  566. accessStore.hideBalanceQuery,
  567. accessStore.openaiUrl,
  568. accessStore.provider,
  569. ]);
  570. const usage = {
  571. used: updateStore.used,
  572. subscription: updateStore.subscription,
  573. };
  574. const [loadingUsage, setLoadingUsage] = useState(false);
  575. function checkUsage(force = false) {
  576. if (shouldHideBalanceQuery) {
  577. return;
  578. }
  579. setLoadingUsage(true);
  580. updateStore.updateUsage(force).finally(() => {
  581. setLoadingUsage(false);
  582. });
  583. }
  584. const enabledAccessControl = useMemo(
  585. () => accessStore.enabledAccessControl(),
  586. // eslint-disable-next-line react-hooks/exhaustive-deps
  587. [],
  588. );
  589. const promptStore = usePromptStore();
  590. const builtinCount = SearchService.count.builtin;
  591. const customCount = promptStore.getUserPrompts().length ?? 0;
  592. const [shouldShowPromptModal, setShowPromptModal] = useState(false);
  593. const showUsage = accessStore.isAuthorized();
  594. useEffect(() => {
  595. // checks per minutes
  596. checkUpdate();
  597. showUsage && checkUsage();
  598. // eslint-disable-next-line react-hooks/exhaustive-deps
  599. }, []);
  600. useEffect(() => {
  601. const keydownEvent = (e: KeyboardEvent) => {
  602. if (e.key === "Escape") {
  603. navigate(Path.Home);
  604. }
  605. };
  606. if (clientConfig?.isApp) {
  607. // Force to set custom endpoint to true if it's app
  608. accessStore.update((state) => {
  609. state.useCustomConfig = true;
  610. });
  611. }
  612. document.addEventListener("keydown", keydownEvent);
  613. return () => {
  614. document.removeEventListener("keydown", keydownEvent);
  615. };
  616. // eslint-disable-next-line react-hooks/exhaustive-deps
  617. }, []);
  618. const clientConfig = useMemo(() => getClientConfig(), []);
  619. const showAccessCode = enabledAccessControl && !clientConfig?.isApp;
  620. const accessCodeComponent = showAccessCode && (
  621. <ListItem
  622. title={Locale.Settings.Access.AccessCode.Title}
  623. subTitle={Locale.Settings.Access.AccessCode.SubTitle}
  624. >
  625. <PasswordInput
  626. value={accessStore.accessCode}
  627. type="text"
  628. placeholder={Locale.Settings.Access.AccessCode.Placeholder}
  629. onChange={(e) => {
  630. accessStore.update(
  631. (access) => (access.accessCode = e.currentTarget.value),
  632. );
  633. }}
  634. />
  635. </ListItem>
  636. );
  637. const useCustomConfigComponent = // Conditionally render the following ListItem based on clientConfig.isApp
  638. !clientConfig?.isApp && ( // only show if isApp is false
  639. <ListItem
  640. title={Locale.Settings.Access.CustomEndpoint.Title}
  641. subTitle={Locale.Settings.Access.CustomEndpoint.SubTitle}
  642. >
  643. <input
  644. aria-label={Locale.Settings.Access.CustomEndpoint.Title}
  645. type="checkbox"
  646. checked={accessStore.useCustomConfig}
  647. onChange={(e) =>
  648. accessStore.update(
  649. (access) => (access.useCustomConfig = e.currentTarget.checked),
  650. )
  651. }
  652. ></input>
  653. </ListItem>
  654. );
  655. const openAIConfigComponent = accessStore.provider ===
  656. ServiceProvider.OpenAI && (
  657. <>
  658. <ListItem
  659. title={Locale.Settings.Access.OpenAI.Endpoint.Title}
  660. subTitle={Locale.Settings.Access.OpenAI.Endpoint.SubTitle}
  661. >
  662. <input
  663. aria-label={Locale.Settings.Access.OpenAI.Endpoint.Title}
  664. type="text"
  665. value={accessStore.openaiUrl}
  666. placeholder={OPENAI_BASE_URL}
  667. onChange={(e) =>
  668. accessStore.update(
  669. (access) => (access.openaiUrl = e.currentTarget.value),
  670. )
  671. }
  672. ></input>
  673. </ListItem>
  674. <ListItem
  675. title={Locale.Settings.Access.OpenAI.ApiKey.Title}
  676. subTitle={Locale.Settings.Access.OpenAI.ApiKey.SubTitle}
  677. >
  678. <PasswordInput
  679. aria={Locale.Settings.ShowPassword}
  680. aria-label={Locale.Settings.Access.OpenAI.ApiKey.Title}
  681. value={accessStore.openaiApiKey}
  682. type="text"
  683. placeholder={Locale.Settings.Access.OpenAI.ApiKey.Placeholder}
  684. onChange={(e) => {
  685. accessStore.update(
  686. (access) => (access.openaiApiKey = e.currentTarget.value),
  687. );
  688. }}
  689. />
  690. </ListItem>
  691. </>
  692. );
  693. const azureConfigComponent = accessStore.provider ===
  694. ServiceProvider.Azure && (
  695. <>
  696. <ListItem
  697. title={Locale.Settings.Access.Azure.Endpoint.Title}
  698. subTitle={
  699. Locale.Settings.Access.Azure.Endpoint.SubTitle + Azure.ExampleEndpoint
  700. }
  701. >
  702. <input
  703. aria-label={Locale.Settings.Access.Azure.Endpoint.Title}
  704. type="text"
  705. value={accessStore.azureUrl}
  706. placeholder={Azure.ExampleEndpoint}
  707. onChange={(e) =>
  708. accessStore.update(
  709. (access) => (access.azureUrl = e.currentTarget.value),
  710. )
  711. }
  712. ></input>
  713. </ListItem>
  714. <ListItem
  715. title={Locale.Settings.Access.Azure.ApiKey.Title}
  716. subTitle={Locale.Settings.Access.Azure.ApiKey.SubTitle}
  717. >
  718. <PasswordInput
  719. aria-label={Locale.Settings.Access.Azure.ApiKey.Title}
  720. value={accessStore.azureApiKey}
  721. type="text"
  722. placeholder={Locale.Settings.Access.Azure.ApiKey.Placeholder}
  723. onChange={(e) => {
  724. accessStore.update(
  725. (access) => (access.azureApiKey = e.currentTarget.value),
  726. );
  727. }}
  728. />
  729. </ListItem>
  730. <ListItem
  731. title={Locale.Settings.Access.Azure.ApiVerion.Title}
  732. subTitle={Locale.Settings.Access.Azure.ApiVerion.SubTitle}
  733. >
  734. <input
  735. aria-label={Locale.Settings.Access.Azure.ApiVerion.Title}
  736. type="text"
  737. value={accessStore.azureApiVersion}
  738. placeholder="2023-08-01-preview"
  739. onChange={(e) =>
  740. accessStore.update(
  741. (access) => (access.azureApiVersion = e.currentTarget.value),
  742. )
  743. }
  744. ></input>
  745. </ListItem>
  746. </>
  747. );
  748. const googleConfigComponent = accessStore.provider ===
  749. ServiceProvider.Google && (
  750. <>
  751. <ListItem
  752. title={Locale.Settings.Access.Google.Endpoint.Title}
  753. subTitle={
  754. Locale.Settings.Access.Google.Endpoint.SubTitle +
  755. Google.ExampleEndpoint
  756. }
  757. >
  758. <input
  759. aria-label={Locale.Settings.Access.Google.Endpoint.Title}
  760. type="text"
  761. value={accessStore.googleUrl}
  762. placeholder={Google.ExampleEndpoint}
  763. onChange={(e) =>
  764. accessStore.update(
  765. (access) => (access.googleUrl = e.currentTarget.value),
  766. )
  767. }
  768. ></input>
  769. </ListItem>
  770. <ListItem
  771. title={Locale.Settings.Access.Google.ApiKey.Title}
  772. subTitle={Locale.Settings.Access.Google.ApiKey.SubTitle}
  773. >
  774. <PasswordInput
  775. aria-label={Locale.Settings.Access.Google.ApiKey.Title}
  776. value={accessStore.googleApiKey}
  777. type="text"
  778. placeholder={Locale.Settings.Access.Google.ApiKey.Placeholder}
  779. onChange={(e) => {
  780. accessStore.update(
  781. (access) => (access.googleApiKey = e.currentTarget.value),
  782. );
  783. }}
  784. />
  785. </ListItem>
  786. <ListItem
  787. title={Locale.Settings.Access.Google.ApiVersion.Title}
  788. subTitle={Locale.Settings.Access.Google.ApiVersion.SubTitle}
  789. >
  790. <input
  791. aria-label={Locale.Settings.Access.Google.ApiVersion.Title}
  792. type="text"
  793. value={accessStore.googleApiVersion}
  794. placeholder="2023-08-01-preview"
  795. onChange={(e) =>
  796. accessStore.update(
  797. (access) => (access.googleApiVersion = e.currentTarget.value),
  798. )
  799. }
  800. ></input>
  801. </ListItem>
  802. <ListItem
  803. title={Locale.Settings.Access.Google.GoogleSafetySettings.Title}
  804. subTitle={Locale.Settings.Access.Google.GoogleSafetySettings.SubTitle}
  805. >
  806. <Select
  807. aria-label={Locale.Settings.Access.Google.GoogleSafetySettings.Title}
  808. value={accessStore.googleSafetySettings}
  809. onChange={(e) => {
  810. accessStore.update(
  811. (access) =>
  812. (access.googleSafetySettings = e.target
  813. .value as GoogleSafetySettingsThreshold),
  814. );
  815. }}
  816. >
  817. {Object.entries(GoogleSafetySettingsThreshold).map(([k, v]) => (
  818. <option value={v} key={k}>
  819. {k}
  820. </option>
  821. ))}
  822. </Select>
  823. </ListItem>
  824. </>
  825. );
  826. const anthropicConfigComponent = accessStore.provider ===
  827. ServiceProvider.Anthropic && (
  828. <>
  829. <ListItem
  830. title={Locale.Settings.Access.Anthropic.Endpoint.Title}
  831. subTitle={
  832. Locale.Settings.Access.Anthropic.Endpoint.SubTitle +
  833. Anthropic.ExampleEndpoint
  834. }
  835. >
  836. <input
  837. aria-label={Locale.Settings.Access.Anthropic.Endpoint.Title}
  838. type="text"
  839. value={accessStore.anthropicUrl}
  840. placeholder={Anthropic.ExampleEndpoint}
  841. onChange={(e) =>
  842. accessStore.update(
  843. (access) => (access.anthropicUrl = e.currentTarget.value),
  844. )
  845. }
  846. ></input>
  847. </ListItem>
  848. <ListItem
  849. title={Locale.Settings.Access.Anthropic.ApiKey.Title}
  850. subTitle={Locale.Settings.Access.Anthropic.ApiKey.SubTitle}
  851. >
  852. <PasswordInput
  853. aria-label={Locale.Settings.Access.Anthropic.ApiKey.Title}
  854. value={accessStore.anthropicApiKey}
  855. type="text"
  856. placeholder={Locale.Settings.Access.Anthropic.ApiKey.Placeholder}
  857. onChange={(e) => {
  858. accessStore.update(
  859. (access) => (access.anthropicApiKey = e.currentTarget.value),
  860. );
  861. }}
  862. />
  863. </ListItem>
  864. <ListItem
  865. title={Locale.Settings.Access.Anthropic.ApiVerion.Title}
  866. subTitle={Locale.Settings.Access.Anthropic.ApiVerion.SubTitle}
  867. >
  868. <input
  869. aria-label={Locale.Settings.Access.Anthropic.ApiVerion.Title}
  870. type="text"
  871. value={accessStore.anthropicApiVersion}
  872. placeholder={Anthropic.Vision}
  873. onChange={(e) =>
  874. accessStore.update(
  875. (access) => (access.anthropicApiVersion = e.currentTarget.value),
  876. )
  877. }
  878. ></input>
  879. </ListItem>
  880. </>
  881. );
  882. const baiduConfigComponent = accessStore.provider ===
  883. ServiceProvider.Baidu && (
  884. <>
  885. <ListItem
  886. title={Locale.Settings.Access.Baidu.Endpoint.Title}
  887. subTitle={Locale.Settings.Access.Baidu.Endpoint.SubTitle}
  888. >
  889. <input
  890. aria-label={Locale.Settings.Access.Baidu.Endpoint.Title}
  891. type="text"
  892. value={accessStore.baiduUrl}
  893. placeholder={Baidu.ExampleEndpoint}
  894. onChange={(e) =>
  895. accessStore.update(
  896. (access) => (access.baiduUrl = e.currentTarget.value),
  897. )
  898. }
  899. ></input>
  900. </ListItem>
  901. <ListItem
  902. title={Locale.Settings.Access.Baidu.ApiKey.Title}
  903. subTitle={Locale.Settings.Access.Baidu.ApiKey.SubTitle}
  904. >
  905. <PasswordInput
  906. aria-label={Locale.Settings.Access.Baidu.ApiKey.Title}
  907. value={accessStore.baiduApiKey}
  908. type="text"
  909. placeholder={Locale.Settings.Access.Baidu.ApiKey.Placeholder}
  910. onChange={(e) => {
  911. accessStore.update(
  912. (access) => (access.baiduApiKey = e.currentTarget.value),
  913. );
  914. }}
  915. />
  916. </ListItem>
  917. <ListItem
  918. title={Locale.Settings.Access.Baidu.SecretKey.Title}
  919. subTitle={Locale.Settings.Access.Baidu.SecretKey.SubTitle}
  920. >
  921. <PasswordInput
  922. aria-label={Locale.Settings.Access.Baidu.SecretKey.Title}
  923. value={accessStore.baiduSecretKey}
  924. type="text"
  925. placeholder={Locale.Settings.Access.Baidu.SecretKey.Placeholder}
  926. onChange={(e) => {
  927. accessStore.update(
  928. (access) => (access.baiduSecretKey = e.currentTarget.value),
  929. );
  930. }}
  931. />
  932. </ListItem>
  933. </>
  934. );
  935. const tencentConfigComponent = accessStore.provider ===
  936. ServiceProvider.Tencent && (
  937. <>
  938. <ListItem
  939. title={Locale.Settings.Access.Tencent.Endpoint.Title}
  940. subTitle={Locale.Settings.Access.Tencent.Endpoint.SubTitle}
  941. >
  942. <input
  943. aria-label={Locale.Settings.Access.Tencent.Endpoint.Title}
  944. type="text"
  945. value={accessStore.tencentUrl}
  946. placeholder={Tencent.ExampleEndpoint}
  947. onChange={(e) =>
  948. accessStore.update(
  949. (access) => (access.tencentUrl = e.currentTarget.value),
  950. )
  951. }
  952. ></input>
  953. </ListItem>
  954. <ListItem
  955. title={Locale.Settings.Access.Tencent.ApiKey.Title}
  956. subTitle={Locale.Settings.Access.Tencent.ApiKey.SubTitle}
  957. >
  958. <PasswordInput
  959. aria-label={Locale.Settings.Access.Tencent.ApiKey.Title}
  960. value={accessStore.tencentSecretId}
  961. type="text"
  962. placeholder={Locale.Settings.Access.Tencent.ApiKey.Placeholder}
  963. onChange={(e) => {
  964. accessStore.update(
  965. (access) => (access.tencentSecretId = e.currentTarget.value),
  966. );
  967. }}
  968. />
  969. </ListItem>
  970. <ListItem
  971. title={Locale.Settings.Access.Tencent.SecretKey.Title}
  972. subTitle={Locale.Settings.Access.Tencent.SecretKey.SubTitle}
  973. >
  974. <PasswordInput
  975. aria-label={Locale.Settings.Access.Tencent.SecretKey.Title}
  976. value={accessStore.tencentSecretKey}
  977. type="text"
  978. placeholder={Locale.Settings.Access.Tencent.SecretKey.Placeholder}
  979. onChange={(e) => {
  980. accessStore.update(
  981. (access) => (access.tencentSecretKey = e.currentTarget.value),
  982. );
  983. }}
  984. />
  985. </ListItem>
  986. </>
  987. );
  988. const byteDanceConfigComponent = accessStore.provider ===
  989. ServiceProvider.ByteDance && (
  990. <>
  991. <ListItem
  992. title={Locale.Settings.Access.ByteDance.Endpoint.Title}
  993. subTitle={
  994. Locale.Settings.Access.ByteDance.Endpoint.SubTitle +
  995. ByteDance.ExampleEndpoint
  996. }
  997. >
  998. <input
  999. aria-label={Locale.Settings.Access.ByteDance.Endpoint.Title}
  1000. type="text"
  1001. value={accessStore.bytedanceUrl}
  1002. placeholder={ByteDance.ExampleEndpoint}
  1003. onChange={(e) =>
  1004. accessStore.update(
  1005. (access) => (access.bytedanceUrl = e.currentTarget.value),
  1006. )
  1007. }
  1008. ></input>
  1009. </ListItem>
  1010. <ListItem
  1011. title={Locale.Settings.Access.ByteDance.ApiKey.Title}
  1012. subTitle={Locale.Settings.Access.ByteDance.ApiKey.SubTitle}
  1013. >
  1014. <PasswordInput
  1015. aria-label={Locale.Settings.Access.ByteDance.ApiKey.Title}
  1016. value={accessStore.bytedanceApiKey}
  1017. type="text"
  1018. placeholder={Locale.Settings.Access.ByteDance.ApiKey.Placeholder}
  1019. onChange={(e) => {
  1020. accessStore.update(
  1021. (access) => (access.bytedanceApiKey = e.currentTarget.value),
  1022. );
  1023. }}
  1024. />
  1025. </ListItem>
  1026. </>
  1027. );
  1028. const alibabaConfigComponent = accessStore.provider ===
  1029. ServiceProvider.Alibaba && (
  1030. <>
  1031. <ListItem
  1032. title={Locale.Settings.Access.Alibaba.Endpoint.Title}
  1033. subTitle={
  1034. Locale.Settings.Access.Alibaba.Endpoint.SubTitle +
  1035. Alibaba.ExampleEndpoint
  1036. }
  1037. >
  1038. <input
  1039. aria-label={Locale.Settings.Access.Alibaba.Endpoint.Title}
  1040. type="text"
  1041. value={accessStore.alibabaUrl}
  1042. placeholder={Alibaba.ExampleEndpoint}
  1043. onChange={(e) =>
  1044. accessStore.update(
  1045. (access) => (access.alibabaUrl = e.currentTarget.value),
  1046. )
  1047. }
  1048. ></input>
  1049. </ListItem>
  1050. <ListItem
  1051. title={Locale.Settings.Access.Alibaba.ApiKey.Title}
  1052. subTitle={Locale.Settings.Access.Alibaba.ApiKey.SubTitle}
  1053. >
  1054. <PasswordInput
  1055. aria-label={Locale.Settings.Access.Alibaba.ApiKey.Title}
  1056. value={accessStore.alibabaApiKey}
  1057. type="text"
  1058. placeholder={Locale.Settings.Access.Alibaba.ApiKey.Placeholder}
  1059. onChange={(e) => {
  1060. accessStore.update(
  1061. (access) => (access.alibabaApiKey = e.currentTarget.value),
  1062. );
  1063. }}
  1064. />
  1065. </ListItem>
  1066. </>
  1067. );
  1068. const moonshotConfigComponent = accessStore.provider ===
  1069. ServiceProvider.Moonshot && (
  1070. <>
  1071. <ListItem
  1072. title={Locale.Settings.Access.Moonshot.Endpoint.Title}
  1073. subTitle={
  1074. Locale.Settings.Access.Moonshot.Endpoint.SubTitle +
  1075. Moonshot.ExampleEndpoint
  1076. }
  1077. >
  1078. <input
  1079. aria-label={Locale.Settings.Access.Moonshot.Endpoint.Title}
  1080. type="text"
  1081. value={accessStore.moonshotUrl}
  1082. placeholder={Moonshot.ExampleEndpoint}
  1083. onChange={(e) =>
  1084. accessStore.update(
  1085. (access) => (access.moonshotUrl = e.currentTarget.value),
  1086. )
  1087. }
  1088. ></input>
  1089. </ListItem>
  1090. <ListItem
  1091. title={Locale.Settings.Access.Moonshot.ApiKey.Title}
  1092. subTitle={Locale.Settings.Access.Moonshot.ApiKey.SubTitle}
  1093. >
  1094. <PasswordInput
  1095. aria-label={Locale.Settings.Access.Moonshot.ApiKey.Title}
  1096. value={accessStore.moonshotApiKey}
  1097. type="text"
  1098. placeholder={Locale.Settings.Access.Moonshot.ApiKey.Placeholder}
  1099. onChange={(e) => {
  1100. accessStore.update(
  1101. (access) => (access.moonshotApiKey = e.currentTarget.value),
  1102. );
  1103. }}
  1104. />
  1105. </ListItem>
  1106. </>
  1107. );
  1108. const stabilityConfigComponent = accessStore.provider ===
  1109. ServiceProvider.Stability && (
  1110. <>
  1111. <ListItem
  1112. title={Locale.Settings.Access.Stability.Endpoint.Title}
  1113. subTitle={
  1114. Locale.Settings.Access.Stability.Endpoint.SubTitle +
  1115. Stability.ExampleEndpoint
  1116. }
  1117. >
  1118. <input
  1119. aria-label={Locale.Settings.Access.Stability.Endpoint.Title}
  1120. type="text"
  1121. value={accessStore.stabilityUrl}
  1122. placeholder={Stability.ExampleEndpoint}
  1123. onChange={(e) =>
  1124. accessStore.update(
  1125. (access) => (access.stabilityUrl = e.currentTarget.value),
  1126. )
  1127. }
  1128. ></input>
  1129. </ListItem>
  1130. <ListItem
  1131. title={Locale.Settings.Access.Stability.ApiKey.Title}
  1132. subTitle={Locale.Settings.Access.Stability.ApiKey.SubTitle}
  1133. >
  1134. <PasswordInput
  1135. aria-label={Locale.Settings.Access.Stability.ApiKey.Title}
  1136. value={accessStore.stabilityApiKey}
  1137. type="text"
  1138. placeholder={Locale.Settings.Access.Stability.ApiKey.Placeholder}
  1139. onChange={(e) => {
  1140. accessStore.update(
  1141. (access) => (access.stabilityApiKey = e.currentTarget.value),
  1142. );
  1143. }}
  1144. />
  1145. </ListItem>
  1146. </>
  1147. );
  1148. const lflytekConfigComponent = accessStore.provider ===
  1149. ServiceProvider.Iflytek && (
  1150. <>
  1151. <ListItem
  1152. title={Locale.Settings.Access.Iflytek.Endpoint.Title}
  1153. subTitle={
  1154. Locale.Settings.Access.Iflytek.Endpoint.SubTitle +
  1155. Iflytek.ExampleEndpoint
  1156. }
  1157. >
  1158. <input
  1159. aria-label={Locale.Settings.Access.Iflytek.Endpoint.Title}
  1160. type="text"
  1161. value={accessStore.iflytekUrl}
  1162. placeholder={Iflytek.ExampleEndpoint}
  1163. onChange={(e) =>
  1164. accessStore.update(
  1165. (access) => (access.iflytekUrl = e.currentTarget.value),
  1166. )
  1167. }
  1168. ></input>
  1169. </ListItem>
  1170. <ListItem
  1171. title={Locale.Settings.Access.Iflytek.ApiKey.Title}
  1172. subTitle={Locale.Settings.Access.Iflytek.ApiKey.SubTitle}
  1173. >
  1174. <PasswordInput
  1175. aria-label={Locale.Settings.Access.Iflytek.ApiKey.Title}
  1176. value={accessStore.iflytekApiKey}
  1177. type="text"
  1178. placeholder={Locale.Settings.Access.Iflytek.ApiKey.Placeholder}
  1179. onChange={(e) => {
  1180. accessStore.update(
  1181. (access) => (access.iflytekApiKey = e.currentTarget.value),
  1182. );
  1183. }}
  1184. />
  1185. </ListItem>
  1186. <ListItem
  1187. title={Locale.Settings.Access.Iflytek.ApiSecret.Title}
  1188. subTitle={Locale.Settings.Access.Iflytek.ApiSecret.SubTitle}
  1189. >
  1190. <PasswordInput
  1191. aria-label={Locale.Settings.Access.Iflytek.ApiSecret.Title}
  1192. value={accessStore.iflytekApiSecret}
  1193. type="text"
  1194. placeholder={Locale.Settings.Access.Iflytek.ApiSecret.Placeholder}
  1195. onChange={(e) => {
  1196. accessStore.update(
  1197. (access) => (access.iflytekApiSecret = e.currentTarget.value),
  1198. );
  1199. }}
  1200. />
  1201. </ListItem>
  1202. </>
  1203. );
  1204. return (
  1205. <ErrorBoundary>
  1206. <div className="window-header" data-tauri-drag-region>
  1207. <div className="window-header-title">
  1208. <div className="window-header-main-title">
  1209. {Locale.Settings.Title}
  1210. </div>
  1211. <div className="window-header-sub-title">
  1212. {Locale.Settings.SubTitle}
  1213. </div>
  1214. </div>
  1215. <div className="window-actions">
  1216. <div className="window-action-button"></div>
  1217. <div className="window-action-button"></div>
  1218. <div className="window-action-button">
  1219. <IconButton
  1220. aria={Locale.UI.Close}
  1221. icon={<CloseIcon />}
  1222. onClick={() => navigate(Path.Home)}
  1223. bordered
  1224. />
  1225. </div>
  1226. </div>
  1227. </div>
  1228. <div className={styles["settings"]}>
  1229. <List>
  1230. <ListItem title={Locale.Settings.Avatar}>
  1231. <Popover
  1232. onClose={() => setShowEmojiPicker(false)}
  1233. content={
  1234. <AvatarPicker
  1235. onEmojiClick={(avatar: string) => {
  1236. updateConfig((config) => (config.avatar = avatar));
  1237. setShowEmojiPicker(false);
  1238. }}
  1239. />
  1240. }
  1241. open={showEmojiPicker}
  1242. >
  1243. <div
  1244. aria-label={Locale.Settings.Avatar}
  1245. tabIndex={0}
  1246. className={styles.avatar}
  1247. onClick={() => {
  1248. setShowEmojiPicker(!showEmojiPicker);
  1249. }}
  1250. >
  1251. <Avatar avatar={config.avatar} />
  1252. </div>
  1253. </Popover>
  1254. </ListItem>
  1255. <ListItem
  1256. title={Locale.Settings.Update.Version(currentVersion ?? "unknown")}
  1257. subTitle={
  1258. checkingUpdate
  1259. ? Locale.Settings.Update.IsChecking
  1260. : hasNewVersion
  1261. ? Locale.Settings.Update.FoundUpdate(remoteId ?? "ERROR")
  1262. : Locale.Settings.Update.IsLatest
  1263. }
  1264. >
  1265. {checkingUpdate ? (
  1266. <LoadingIcon />
  1267. ) : hasNewVersion ? (
  1268. <Link href={updateUrl} target="_blank" className="link">
  1269. {Locale.Settings.Update.GoToUpdate}
  1270. </Link>
  1271. ) : (
  1272. <IconButton
  1273. icon={<ResetIcon></ResetIcon>}
  1274. text={Locale.Settings.Update.CheckUpdate}
  1275. onClick={() => checkUpdate(true)}
  1276. />
  1277. )}
  1278. </ListItem>
  1279. <ListItem title={Locale.Settings.SendKey}>
  1280. <Select
  1281. aria-label={Locale.Settings.SendKey}
  1282. value={config.submitKey}
  1283. onChange={(e) => {
  1284. updateConfig(
  1285. (config) =>
  1286. (config.submitKey = e.target.value as any as SubmitKey),
  1287. );
  1288. }}
  1289. >
  1290. {Object.values(SubmitKey).map((v) => (
  1291. <option value={v} key={v}>
  1292. {v}
  1293. </option>
  1294. ))}
  1295. </Select>
  1296. </ListItem>
  1297. <ListItem title={Locale.Settings.Theme}>
  1298. <Select
  1299. aria-label={Locale.Settings.Theme}
  1300. value={config.theme}
  1301. onChange={(e) => {
  1302. updateConfig(
  1303. (config) => (config.theme = e.target.value as any as Theme),
  1304. );
  1305. }}
  1306. >
  1307. {Object.values(Theme).map((v) => (
  1308. <option value={v} key={v}>
  1309. {v}
  1310. </option>
  1311. ))}
  1312. </Select>
  1313. </ListItem>
  1314. <ListItem title={Locale.Settings.Lang.Name}>
  1315. <Select
  1316. aria-label={Locale.Settings.Lang.Name}
  1317. value={getLang()}
  1318. onChange={(e) => {
  1319. changeLang(e.target.value as any);
  1320. }}
  1321. >
  1322. {AllLangs.map((lang) => (
  1323. <option value={lang} key={lang}>
  1324. {ALL_LANG_OPTIONS[lang]}
  1325. </option>
  1326. ))}
  1327. </Select>
  1328. </ListItem>
  1329. <ListItem
  1330. title={Locale.Settings.FontSize.Title}
  1331. subTitle={Locale.Settings.FontSize.SubTitle}
  1332. >
  1333. <InputRange
  1334. aria={Locale.Settings.FontSize.Title}
  1335. title={`${config.fontSize ?? 14}px`}
  1336. value={config.fontSize}
  1337. min="12"
  1338. max="40"
  1339. step="1"
  1340. onChange={(e) =>
  1341. updateConfig(
  1342. (config) =>
  1343. (config.fontSize = Number.parseInt(e.currentTarget.value)),
  1344. )
  1345. }
  1346. ></InputRange>
  1347. </ListItem>
  1348. <ListItem
  1349. title={Locale.Settings.FontFamily.Title}
  1350. subTitle={Locale.Settings.FontFamily.SubTitle}
  1351. >
  1352. <input
  1353. aria-label={Locale.Settings.FontFamily.Title}
  1354. type="text"
  1355. value={config.fontFamily}
  1356. placeholder={Locale.Settings.FontFamily.Placeholder}
  1357. onChange={(e) =>
  1358. updateConfig(
  1359. (config) => (config.fontFamily = e.currentTarget.value),
  1360. )
  1361. }
  1362. ></input>
  1363. </ListItem>
  1364. <ListItem
  1365. title={Locale.Settings.AutoGenerateTitle.Title}
  1366. subTitle={Locale.Settings.AutoGenerateTitle.SubTitle}
  1367. >
  1368. <input
  1369. aria-label={Locale.Settings.AutoGenerateTitle.Title}
  1370. type="checkbox"
  1371. checked={config.enableAutoGenerateTitle}
  1372. onChange={(e) =>
  1373. updateConfig(
  1374. (config) =>
  1375. (config.enableAutoGenerateTitle = e.currentTarget.checked),
  1376. )
  1377. }
  1378. ></input>
  1379. </ListItem>
  1380. <ListItem
  1381. title={Locale.Settings.SendPreviewBubble.Title}
  1382. subTitle={Locale.Settings.SendPreviewBubble.SubTitle}
  1383. >
  1384. <input
  1385. aria-label={Locale.Settings.SendPreviewBubble.Title}
  1386. type="checkbox"
  1387. checked={config.sendPreviewBubble}
  1388. onChange={(e) =>
  1389. updateConfig(
  1390. (config) =>
  1391. (config.sendPreviewBubble = e.currentTarget.checked),
  1392. )
  1393. }
  1394. ></input>
  1395. </ListItem>
  1396. </List>
  1397. <SyncItems />
  1398. <List>
  1399. <ListItem
  1400. title={Locale.Settings.Mask.Splash.Title}
  1401. subTitle={Locale.Settings.Mask.Splash.SubTitle}
  1402. >
  1403. <input
  1404. aria-label={Locale.Settings.Mask.Splash.Title}
  1405. type="checkbox"
  1406. checked={!config.dontShowMaskSplashScreen}
  1407. onChange={(e) =>
  1408. updateConfig(
  1409. (config) =>
  1410. (config.dontShowMaskSplashScreen =
  1411. !e.currentTarget.checked),
  1412. )
  1413. }
  1414. ></input>
  1415. </ListItem>
  1416. <ListItem
  1417. title={Locale.Settings.Mask.Builtin.Title}
  1418. subTitle={Locale.Settings.Mask.Builtin.SubTitle}
  1419. >
  1420. <input
  1421. aria-label={Locale.Settings.Mask.Builtin.Title}
  1422. type="checkbox"
  1423. checked={config.hideBuiltinMasks}
  1424. onChange={(e) =>
  1425. updateConfig(
  1426. (config) =>
  1427. (config.hideBuiltinMasks = e.currentTarget.checked),
  1428. )
  1429. }
  1430. ></input>
  1431. </ListItem>
  1432. </List>
  1433. <List>
  1434. <ListItem
  1435. title={Locale.Settings.Prompt.Disable.Title}
  1436. subTitle={Locale.Settings.Prompt.Disable.SubTitle}
  1437. >
  1438. <input
  1439. aria-label={Locale.Settings.Prompt.Disable.Title}
  1440. type="checkbox"
  1441. checked={config.disablePromptHint}
  1442. onChange={(e) =>
  1443. updateConfig(
  1444. (config) =>
  1445. (config.disablePromptHint = e.currentTarget.checked),
  1446. )
  1447. }
  1448. ></input>
  1449. </ListItem>
  1450. <ListItem
  1451. title={Locale.Settings.Prompt.List}
  1452. subTitle={Locale.Settings.Prompt.ListCount(
  1453. builtinCount,
  1454. customCount,
  1455. )}
  1456. >
  1457. <IconButton
  1458. aria={Locale.Settings.Prompt.List + Locale.Settings.Prompt.Edit}
  1459. icon={<EditIcon />}
  1460. text={Locale.Settings.Prompt.Edit}
  1461. onClick={() => setShowPromptModal(true)}
  1462. />
  1463. </ListItem>
  1464. </List>
  1465. <List id={SlotID.CustomModel}>
  1466. {accessCodeComponent}
  1467. {!accessStore.hideUserApiKey && (
  1468. <>
  1469. {useCustomConfigComponent}
  1470. {accessStore.useCustomConfig && (
  1471. <>
  1472. <ListItem
  1473. title={Locale.Settings.Access.Provider.Title}
  1474. subTitle={Locale.Settings.Access.Provider.SubTitle}
  1475. >
  1476. <Select
  1477. aria-label={Locale.Settings.Access.Provider.Title}
  1478. value={accessStore.provider}
  1479. onChange={(e) => {
  1480. accessStore.update(
  1481. (access) =>
  1482. (access.provider = e.target
  1483. .value as ServiceProvider),
  1484. );
  1485. }}
  1486. >
  1487. {Object.entries(ServiceProvider).map(([k, v]) => (
  1488. <option value={v} key={k}>
  1489. {k}
  1490. </option>
  1491. ))}
  1492. </Select>
  1493. </ListItem>
  1494. {openAIConfigComponent}
  1495. {azureConfigComponent}
  1496. {googleConfigComponent}
  1497. {anthropicConfigComponent}
  1498. {baiduConfigComponent}
  1499. {byteDanceConfigComponent}
  1500. {alibabaConfigComponent}
  1501. {tencentConfigComponent}
  1502. {moonshotConfigComponent}
  1503. {stabilityConfigComponent}
  1504. {lflytekConfigComponent}
  1505. </>
  1506. )}
  1507. </>
  1508. )}
  1509. {!shouldHideBalanceQuery && !clientConfig?.isApp ? (
  1510. <ListItem
  1511. title={Locale.Settings.Usage.Title}
  1512. subTitle={
  1513. showUsage
  1514. ? loadingUsage
  1515. ? Locale.Settings.Usage.IsChecking
  1516. : Locale.Settings.Usage.SubTitle(
  1517. usage?.used ?? "[?]",
  1518. usage?.subscription ?? "[?]",
  1519. )
  1520. : Locale.Settings.Usage.NoAccess
  1521. }
  1522. >
  1523. {!showUsage || loadingUsage ? (
  1524. <div />
  1525. ) : (
  1526. <IconButton
  1527. icon={<ResetIcon></ResetIcon>}
  1528. text={Locale.Settings.Usage.Check}
  1529. onClick={() => checkUsage(true)}
  1530. />
  1531. )}
  1532. </ListItem>
  1533. ) : null}
  1534. <ListItem
  1535. title={Locale.Settings.Access.CustomModel.Title}
  1536. subTitle={Locale.Settings.Access.CustomModel.SubTitle}
  1537. >
  1538. <input
  1539. aria-label={Locale.Settings.Access.CustomModel.Title}
  1540. type="text"
  1541. value={config.customModels}
  1542. placeholder="model1,model2,model3"
  1543. onChange={(e) =>
  1544. config.update(
  1545. (config) => (config.customModels = e.currentTarget.value),
  1546. )
  1547. }
  1548. ></input>
  1549. </ListItem>
  1550. </List>
  1551. <List>
  1552. <ModelConfigList
  1553. modelConfig={config.modelConfig}
  1554. updateConfig={(updater) => {
  1555. const modelConfig = { ...config.modelConfig };
  1556. updater(modelConfig);
  1557. config.update((config) => (config.modelConfig = modelConfig));
  1558. }}
  1559. />
  1560. </List>
  1561. {shouldShowPromptModal && (
  1562. <UserPromptModal onClose={() => setShowPromptModal(false)} />
  1563. )}
  1564. <List>
  1565. <TTSConfigList
  1566. ttsConfig={config.ttsConfig}
  1567. updateConfig={(updater) => {
  1568. const ttsConfig = { ...config.ttsConfig };
  1569. updater(ttsConfig);
  1570. config.update((config) => (config.ttsConfig = ttsConfig));
  1571. }}
  1572. />
  1573. </List>
  1574. <DangerItems />
  1575. </div>
  1576. </ErrorBoundary>
  1577. );
  1578. }