settings.tsx 45 KB

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