settings.tsx 52 KB

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