settings.tsx 53 KB

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