settings.tsx 56 KB

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