settings.tsx 56 KB

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