settings.tsx 44 KB

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