settings.tsx 48 KB

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