settings.tsx 46 KB

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