settings.tsx 52 KB

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