settings.tsx 52 KB

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