settings.tsx 55 KB

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