settings.tsx 52 KB

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