settings.tsx 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703
  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. // 移除内置提示词,仅使用用户提示词
  173. const allPrompts = userPrompts;
  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. // 移除内置提示词,设置count为0
  635. const builtinCount = 0;
  636. const customCount = promptStore.getUserPrompts().length ?? 0;
  637. const [shouldShowPromptModal, setShowPromptModal] = useState(false);
  638. const showUsage = accessStore.isAuthorized();
  639. useEffect(() => {
  640. // checks per minutes
  641. checkUpdate();
  642. showUsage && checkUsage();
  643. // eslint-disable-next-line react-hooks/exhaustive-deps
  644. }, []);
  645. useEffect(() => {
  646. const keydownEvent = (e: KeyboardEvent) => {
  647. if (e.key === "Escape") {
  648. navigate(Path.Home);
  649. }
  650. };
  651. if (clientConfig?.isApp) {
  652. // Force to set custom endpoint to true if it's app
  653. accessStore.update((state) => {
  654. state.useCustomConfig = true;
  655. });
  656. }
  657. document.addEventListener("keydown", keydownEvent);
  658. return () => {
  659. document.removeEventListener("keydown", keydownEvent);
  660. };
  661. // eslint-disable-next-line react-hooks/exhaustive-deps
  662. }, []);
  663. const clientConfig = useMemo(() => getClientConfig(), []);
  664. const showAccessCode = enabledAccessControl && !clientConfig?.isApp;
  665. const accessCodeComponent = showAccessCode && (
  666. <ListItem
  667. title={Locale.Settings.Access.AccessCode.Title}
  668. subTitle={Locale.Settings.Access.AccessCode.SubTitle}
  669. >
  670. <PasswordInput
  671. value={accessStore.accessCode}
  672. type="text"
  673. placeholder={Locale.Settings.Access.AccessCode.Placeholder}
  674. onChange={(e) => {
  675. accessStore.update(
  676. (access) => (access.accessCode = e.currentTarget.value),
  677. );
  678. }}
  679. />
  680. </ListItem>
  681. );
  682. const useCustomConfigComponent = // Conditionally render the following ListItem based on clientConfig.isApp
  683. !clientConfig?.isApp && ( // only show if isApp is false
  684. <ListItem
  685. title={Locale.Settings.Access.CustomEndpoint.Title}
  686. subTitle={Locale.Settings.Access.CustomEndpoint.SubTitle}
  687. >
  688. <input
  689. aria-label={Locale.Settings.Access.CustomEndpoint.Title}
  690. type="checkbox"
  691. checked={accessStore.useCustomConfig}
  692. onChange={(e) =>
  693. accessStore.update(
  694. (access) => (access.useCustomConfig = e.currentTarget.checked),
  695. )
  696. }
  697. ></input>
  698. </ListItem>
  699. );
  700. const openAIConfigComponent = accessStore.provider ===
  701. ServiceProvider.OpenAI && (
  702. <>
  703. <ListItem
  704. title={Locale.Settings.Access.OpenAI.Endpoint.Title}
  705. subTitle={Locale.Settings.Access.OpenAI.Endpoint.SubTitle}
  706. >
  707. <input
  708. aria-label={Locale.Settings.Access.OpenAI.Endpoint.Title}
  709. type="text"
  710. value={accessStore.openaiUrl}
  711. placeholder={OPENAI_BASE_URL}
  712. onChange={(e) =>
  713. accessStore.update(
  714. (access) => (access.openaiUrl = e.currentTarget.value),
  715. )
  716. }
  717. ></input>
  718. </ListItem>
  719. <ListItem
  720. title={Locale.Settings.Access.OpenAI.ApiKey.Title}
  721. subTitle={Locale.Settings.Access.OpenAI.ApiKey.SubTitle}
  722. >
  723. <PasswordInput
  724. aria={Locale.Settings.ShowPassword}
  725. aria-label={Locale.Settings.Access.OpenAI.ApiKey.Title}
  726. value={accessStore.openaiApiKey}
  727. type="text"
  728. placeholder={Locale.Settings.Access.OpenAI.ApiKey.Placeholder}
  729. onChange={(e) => {
  730. accessStore.update(
  731. (access) => (access.openaiApiKey = e.currentTarget.value),
  732. );
  733. }}
  734. />
  735. </ListItem>
  736. </>
  737. );
  738. const azureConfigComponent = accessStore.provider ===
  739. ServiceProvider.Azure && (
  740. <>
  741. <ListItem
  742. title={Locale.Settings.Access.Azure.Endpoint.Title}
  743. subTitle={
  744. Locale.Settings.Access.Azure.Endpoint.SubTitle + Azure.ExampleEndpoint
  745. }
  746. >
  747. <input
  748. aria-label={Locale.Settings.Access.Azure.Endpoint.Title}
  749. type="text"
  750. value={accessStore.azureUrl}
  751. placeholder={Azure.ExampleEndpoint}
  752. onChange={(e) =>
  753. accessStore.update(
  754. (access) => (access.azureUrl = e.currentTarget.value),
  755. )
  756. }
  757. ></input>
  758. </ListItem>
  759. <ListItem
  760. title={Locale.Settings.Access.Azure.ApiKey.Title}
  761. subTitle={Locale.Settings.Access.Azure.ApiKey.SubTitle}
  762. >
  763. <PasswordInput
  764. aria-label={Locale.Settings.Access.Azure.ApiKey.Title}
  765. value={accessStore.azureApiKey}
  766. type="text"
  767. placeholder={Locale.Settings.Access.Azure.ApiKey.Placeholder}
  768. onChange={(e) => {
  769. accessStore.update(
  770. (access) => (access.azureApiKey = e.currentTarget.value),
  771. );
  772. }}
  773. />
  774. </ListItem>
  775. <ListItem
  776. title={Locale.Settings.Access.Azure.ApiVerion.Title}
  777. subTitle={Locale.Settings.Access.Azure.ApiVerion.SubTitle}
  778. >
  779. <input
  780. aria-label={Locale.Settings.Access.Azure.ApiVerion.Title}
  781. type="text"
  782. value={accessStore.azureApiVersion}
  783. placeholder="2023-08-01-preview"
  784. onChange={(e) =>
  785. accessStore.update(
  786. (access) => (access.azureApiVersion = e.currentTarget.value),
  787. )
  788. }
  789. ></input>
  790. </ListItem>
  791. </>
  792. );
  793. const googleConfigComponent = accessStore.provider ===
  794. ServiceProvider.Google && (
  795. <>
  796. <ListItem
  797. title={Locale.Settings.Access.Google.Endpoint.Title}
  798. subTitle={
  799. Locale.Settings.Access.Google.Endpoint.SubTitle +
  800. Google.ExampleEndpoint
  801. }
  802. >
  803. <input
  804. aria-label={Locale.Settings.Access.Google.Endpoint.Title}
  805. type="text"
  806. value={accessStore.googleUrl}
  807. placeholder={Google.ExampleEndpoint}
  808. onChange={(e) =>
  809. accessStore.update(
  810. (access) => (access.googleUrl = e.currentTarget.value),
  811. )
  812. }
  813. ></input>
  814. </ListItem>
  815. <ListItem
  816. title={Locale.Settings.Access.Google.ApiKey.Title}
  817. subTitle={Locale.Settings.Access.Google.ApiKey.SubTitle}
  818. >
  819. <PasswordInput
  820. aria-label={Locale.Settings.Access.Google.ApiKey.Title}
  821. value={accessStore.googleApiKey}
  822. type="text"
  823. placeholder={Locale.Settings.Access.Google.ApiKey.Placeholder}
  824. onChange={(e) => {
  825. accessStore.update(
  826. (access) => (access.googleApiKey = e.currentTarget.value),
  827. );
  828. }}
  829. />
  830. </ListItem>
  831. <ListItem
  832. title={Locale.Settings.Access.Google.ApiVersion.Title}
  833. subTitle={Locale.Settings.Access.Google.ApiVersion.SubTitle}
  834. >
  835. <input
  836. aria-label={Locale.Settings.Access.Google.ApiVersion.Title}
  837. type="text"
  838. value={accessStore.googleApiVersion}
  839. placeholder="2023-08-01-preview"
  840. onChange={(e) =>
  841. accessStore.update(
  842. (access) => (access.googleApiVersion = e.currentTarget.value),
  843. )
  844. }
  845. ></input>
  846. </ListItem>
  847. <ListItem
  848. title={Locale.Settings.Access.Google.GoogleSafetySettings.Title}
  849. subTitle={Locale.Settings.Access.Google.GoogleSafetySettings.SubTitle}
  850. >
  851. <Select
  852. aria-label={Locale.Settings.Access.Google.GoogleSafetySettings.Title}
  853. value={accessStore.googleSafetySettings}
  854. onChange={(e) => {
  855. accessStore.update(
  856. (access) =>
  857. (access.googleSafetySettings = e.target
  858. .value as GoogleSafetySettingsThreshold),
  859. );
  860. }}
  861. >
  862. {Object.entries(GoogleSafetySettingsThreshold).map(([k, v]) => (
  863. <option value={v} key={k}>
  864. {k}
  865. </option>
  866. ))}
  867. </Select>
  868. </ListItem>
  869. </>
  870. );
  871. const anthropicConfigComponent = accessStore.provider ===
  872. ServiceProvider.Anthropic && (
  873. <>
  874. <ListItem
  875. title={Locale.Settings.Access.Anthropic.Endpoint.Title}
  876. subTitle={
  877. Locale.Settings.Access.Anthropic.Endpoint.SubTitle +
  878. Anthropic.ExampleEndpoint
  879. }
  880. >
  881. <input
  882. aria-label={Locale.Settings.Access.Anthropic.Endpoint.Title}
  883. type="text"
  884. value={accessStore.anthropicUrl}
  885. placeholder={Anthropic.ExampleEndpoint}
  886. onChange={(e) =>
  887. accessStore.update(
  888. (access) => (access.anthropicUrl = e.currentTarget.value),
  889. )
  890. }
  891. ></input>
  892. </ListItem>
  893. <ListItem
  894. title={Locale.Settings.Access.Anthropic.ApiKey.Title}
  895. subTitle={Locale.Settings.Access.Anthropic.ApiKey.SubTitle}
  896. >
  897. <PasswordInput
  898. aria-label={Locale.Settings.Access.Anthropic.ApiKey.Title}
  899. value={accessStore.anthropicApiKey}
  900. type="text"
  901. placeholder={Locale.Settings.Access.Anthropic.ApiKey.Placeholder}
  902. onChange={(e) => {
  903. accessStore.update(
  904. (access) => (access.anthropicApiKey = e.currentTarget.value),
  905. );
  906. }}
  907. />
  908. </ListItem>
  909. <ListItem
  910. title={Locale.Settings.Access.Anthropic.ApiVerion.Title}
  911. subTitle={Locale.Settings.Access.Anthropic.ApiVerion.SubTitle}
  912. >
  913. <input
  914. aria-label={Locale.Settings.Access.Anthropic.ApiVerion.Title}
  915. type="text"
  916. value={accessStore.anthropicApiVersion}
  917. placeholder={Anthropic.Vision}
  918. onChange={(e) =>
  919. accessStore.update(
  920. (access) => (access.anthropicApiVersion = e.currentTarget.value),
  921. )
  922. }
  923. ></input>
  924. </ListItem>
  925. </>
  926. );
  927. const baiduConfigComponent = accessStore.provider ===
  928. ServiceProvider.Baidu && (
  929. <>
  930. <ListItem
  931. title={Locale.Settings.Access.Baidu.Endpoint.Title}
  932. subTitle={Locale.Settings.Access.Baidu.Endpoint.SubTitle}
  933. >
  934. <input
  935. aria-label={Locale.Settings.Access.Baidu.Endpoint.Title}
  936. type="text"
  937. value={accessStore.baiduUrl}
  938. placeholder={Baidu.ExampleEndpoint}
  939. onChange={(e) =>
  940. accessStore.update(
  941. (access) => (access.baiduUrl = e.currentTarget.value),
  942. )
  943. }
  944. ></input>
  945. </ListItem>
  946. <ListItem
  947. title={Locale.Settings.Access.Baidu.ApiKey.Title}
  948. subTitle={Locale.Settings.Access.Baidu.ApiKey.SubTitle}
  949. >
  950. <PasswordInput
  951. aria-label={Locale.Settings.Access.Baidu.ApiKey.Title}
  952. value={accessStore.baiduApiKey}
  953. type="text"
  954. placeholder={Locale.Settings.Access.Baidu.ApiKey.Placeholder}
  955. onChange={(e) => {
  956. accessStore.update(
  957. (access) => (access.baiduApiKey = e.currentTarget.value),
  958. );
  959. }}
  960. />
  961. </ListItem>
  962. <ListItem
  963. title={Locale.Settings.Access.Baidu.SecretKey.Title}
  964. subTitle={Locale.Settings.Access.Baidu.SecretKey.SubTitle}
  965. >
  966. <PasswordInput
  967. aria-label={Locale.Settings.Access.Baidu.SecretKey.Title}
  968. value={accessStore.baiduSecretKey}
  969. type="text"
  970. placeholder={Locale.Settings.Access.Baidu.SecretKey.Placeholder}
  971. onChange={(e) => {
  972. accessStore.update(
  973. (access) => (access.baiduSecretKey = e.currentTarget.value),
  974. );
  975. }}
  976. />
  977. </ListItem>
  978. </>
  979. );
  980. const tencentConfigComponent = accessStore.provider ===
  981. ServiceProvider.Tencent && (
  982. <>
  983. <ListItem
  984. title={Locale.Settings.Access.Tencent.Endpoint.Title}
  985. subTitle={Locale.Settings.Access.Tencent.Endpoint.SubTitle}
  986. >
  987. <input
  988. aria-label={Locale.Settings.Access.Tencent.Endpoint.Title}
  989. type="text"
  990. value={accessStore.tencentUrl}
  991. placeholder={Tencent.ExampleEndpoint}
  992. onChange={(e) =>
  993. accessStore.update(
  994. (access) => (access.tencentUrl = e.currentTarget.value),
  995. )
  996. }
  997. ></input>
  998. </ListItem>
  999. <ListItem
  1000. title={Locale.Settings.Access.Tencent.ApiKey.Title}
  1001. subTitle={Locale.Settings.Access.Tencent.ApiKey.SubTitle}
  1002. >
  1003. <PasswordInput
  1004. aria-label={Locale.Settings.Access.Tencent.ApiKey.Title}
  1005. value={accessStore.tencentSecretId}
  1006. type="text"
  1007. placeholder={Locale.Settings.Access.Tencent.ApiKey.Placeholder}
  1008. onChange={(e) => {
  1009. accessStore.update(
  1010. (access) => (access.tencentSecretId = e.currentTarget.value),
  1011. );
  1012. }}
  1013. />
  1014. </ListItem>
  1015. <ListItem
  1016. title={Locale.Settings.Access.Tencent.SecretKey.Title}
  1017. subTitle={Locale.Settings.Access.Tencent.SecretKey.SubTitle}
  1018. >
  1019. <PasswordInput
  1020. aria-label={Locale.Settings.Access.Tencent.SecretKey.Title}
  1021. value={accessStore.tencentSecretKey}
  1022. type="text"
  1023. placeholder={Locale.Settings.Access.Tencent.SecretKey.Placeholder}
  1024. onChange={(e) => {
  1025. accessStore.update(
  1026. (access) => (access.tencentSecretKey = e.currentTarget.value),
  1027. );
  1028. }}
  1029. />
  1030. </ListItem>
  1031. </>
  1032. );
  1033. const byteDanceConfigComponent = accessStore.provider ===
  1034. ServiceProvider.ByteDance && (
  1035. <>
  1036. <ListItem
  1037. title={Locale.Settings.Access.ByteDance.Endpoint.Title}
  1038. subTitle={
  1039. Locale.Settings.Access.ByteDance.Endpoint.SubTitle +
  1040. ByteDance.ExampleEndpoint
  1041. }
  1042. >
  1043. <input
  1044. aria-label={Locale.Settings.Access.ByteDance.Endpoint.Title}
  1045. type="text"
  1046. value={accessStore.bytedanceUrl}
  1047. placeholder={ByteDance.ExampleEndpoint}
  1048. onChange={(e) =>
  1049. accessStore.update(
  1050. (access) => (access.bytedanceUrl = e.currentTarget.value),
  1051. )
  1052. }
  1053. ></input>
  1054. </ListItem>
  1055. <ListItem
  1056. title={Locale.Settings.Access.ByteDance.ApiKey.Title}
  1057. subTitle={Locale.Settings.Access.ByteDance.ApiKey.SubTitle}
  1058. >
  1059. <PasswordInput
  1060. aria-label={Locale.Settings.Access.ByteDance.ApiKey.Title}
  1061. value={accessStore.bytedanceApiKey}
  1062. type="text"
  1063. placeholder={Locale.Settings.Access.ByteDance.ApiKey.Placeholder}
  1064. onChange={(e) => {
  1065. accessStore.update(
  1066. (access) => (access.bytedanceApiKey = e.currentTarget.value),
  1067. );
  1068. }}
  1069. />
  1070. </ListItem>
  1071. </>
  1072. );
  1073. const alibabaConfigComponent = accessStore.provider ===
  1074. ServiceProvider.Alibaba && (
  1075. <>
  1076. <ListItem
  1077. title={Locale.Settings.Access.Alibaba.Endpoint.Title}
  1078. subTitle={
  1079. Locale.Settings.Access.Alibaba.Endpoint.SubTitle +
  1080. Alibaba.ExampleEndpoint
  1081. }
  1082. >
  1083. <input
  1084. aria-label={Locale.Settings.Access.Alibaba.Endpoint.Title}
  1085. type="text"
  1086. value={accessStore.alibabaUrl}
  1087. placeholder={Alibaba.ExampleEndpoint}
  1088. onChange={(e) =>
  1089. accessStore.update(
  1090. (access) => (access.alibabaUrl = e.currentTarget.value),
  1091. )
  1092. }
  1093. ></input>
  1094. </ListItem>
  1095. <ListItem
  1096. title={Locale.Settings.Access.Alibaba.ApiKey.Title}
  1097. subTitle={Locale.Settings.Access.Alibaba.ApiKey.SubTitle}
  1098. >
  1099. <PasswordInput
  1100. aria-label={Locale.Settings.Access.Alibaba.ApiKey.Title}
  1101. value={accessStore.alibabaApiKey}
  1102. type="text"
  1103. placeholder={Locale.Settings.Access.Alibaba.ApiKey.Placeholder}
  1104. onChange={(e) => {
  1105. accessStore.update(
  1106. (access) => (access.alibabaApiKey = e.currentTarget.value),
  1107. );
  1108. }}
  1109. />
  1110. </ListItem>
  1111. </>
  1112. );
  1113. const moonshotConfigComponent = accessStore.provider ===
  1114. ServiceProvider.Moonshot && (
  1115. <>
  1116. <ListItem
  1117. title={Locale.Settings.Access.Moonshot.Endpoint.Title}
  1118. subTitle={
  1119. Locale.Settings.Access.Moonshot.Endpoint.SubTitle +
  1120. Moonshot.ExampleEndpoint
  1121. }
  1122. >
  1123. <input
  1124. aria-label={Locale.Settings.Access.Moonshot.Endpoint.Title}
  1125. type="text"
  1126. value={accessStore.moonshotUrl}
  1127. placeholder={Moonshot.ExampleEndpoint}
  1128. onChange={(e) =>
  1129. accessStore.update(
  1130. (access) => (access.moonshotUrl = e.currentTarget.value),
  1131. )
  1132. }
  1133. ></input>
  1134. </ListItem>
  1135. <ListItem
  1136. title={Locale.Settings.Access.Moonshot.ApiKey.Title}
  1137. subTitle={Locale.Settings.Access.Moonshot.ApiKey.SubTitle}
  1138. >
  1139. <PasswordInput
  1140. aria-label={Locale.Settings.Access.Moonshot.ApiKey.Title}
  1141. value={accessStore.moonshotApiKey}
  1142. type="text"
  1143. placeholder={Locale.Settings.Access.Moonshot.ApiKey.Placeholder}
  1144. onChange={(e) => {
  1145. accessStore.update(
  1146. (access) => (access.moonshotApiKey = e.currentTarget.value),
  1147. );
  1148. }}
  1149. />
  1150. </ListItem>
  1151. </>
  1152. );
  1153. const stabilityConfigComponent = accessStore.provider ===
  1154. ServiceProvider.Stability && (
  1155. <>
  1156. <ListItem
  1157. title={Locale.Settings.Access.Stability.Endpoint.Title}
  1158. subTitle={
  1159. Locale.Settings.Access.Stability.Endpoint.SubTitle +
  1160. Stability.ExampleEndpoint
  1161. }
  1162. >
  1163. <input
  1164. aria-label={Locale.Settings.Access.Stability.Endpoint.Title}
  1165. type="text"
  1166. value={accessStore.stabilityUrl}
  1167. placeholder={Stability.ExampleEndpoint}
  1168. onChange={(e) =>
  1169. accessStore.update(
  1170. (access) => (access.stabilityUrl = e.currentTarget.value),
  1171. )
  1172. }
  1173. ></input>
  1174. </ListItem>
  1175. <ListItem
  1176. title={Locale.Settings.Access.Stability.ApiKey.Title}
  1177. subTitle={Locale.Settings.Access.Stability.ApiKey.SubTitle}
  1178. >
  1179. <PasswordInput
  1180. aria-label={Locale.Settings.Access.Stability.ApiKey.Title}
  1181. value={accessStore.stabilityApiKey}
  1182. type="text"
  1183. placeholder={Locale.Settings.Access.Stability.ApiKey.Placeholder}
  1184. onChange={(e) => {
  1185. accessStore.update(
  1186. (access) => (access.stabilityApiKey = e.currentTarget.value),
  1187. );
  1188. }}
  1189. />
  1190. </ListItem>
  1191. </>
  1192. );
  1193. const lflytekConfigComponent = accessStore.provider ===
  1194. ServiceProvider.Iflytek && (
  1195. <>
  1196. <ListItem
  1197. title={Locale.Settings.Access.Iflytek.Endpoint.Title}
  1198. subTitle={
  1199. Locale.Settings.Access.Iflytek.Endpoint.SubTitle +
  1200. Iflytek.ExampleEndpoint
  1201. }
  1202. >
  1203. <input
  1204. aria-label={Locale.Settings.Access.Iflytek.Endpoint.Title}
  1205. type="text"
  1206. value={accessStore.iflytekUrl}
  1207. placeholder={Iflytek.ExampleEndpoint}
  1208. onChange={(e) =>
  1209. accessStore.update(
  1210. (access) => (access.iflytekUrl = e.currentTarget.value),
  1211. )
  1212. }
  1213. ></input>
  1214. </ListItem>
  1215. <ListItem
  1216. title={Locale.Settings.Access.Iflytek.ApiKey.Title}
  1217. subTitle={Locale.Settings.Access.Iflytek.ApiKey.SubTitle}
  1218. >
  1219. <PasswordInput
  1220. aria-label={Locale.Settings.Access.Iflytek.ApiKey.Title}
  1221. value={accessStore.iflytekApiKey}
  1222. type="text"
  1223. placeholder={Locale.Settings.Access.Iflytek.ApiKey.Placeholder}
  1224. onChange={(e) => {
  1225. accessStore.update(
  1226. (access) => (access.iflytekApiKey = e.currentTarget.value),
  1227. );
  1228. }}
  1229. />
  1230. </ListItem>
  1231. <ListItem
  1232. title={Locale.Settings.Access.Iflytek.ApiSecret.Title}
  1233. subTitle={Locale.Settings.Access.Iflytek.ApiSecret.SubTitle}
  1234. >
  1235. <PasswordInput
  1236. aria-label={Locale.Settings.Access.Iflytek.ApiSecret.Title}
  1237. value={accessStore.iflytekApiSecret}
  1238. type="text"
  1239. placeholder={Locale.Settings.Access.Iflytek.ApiSecret.Placeholder}
  1240. onChange={(e) => {
  1241. accessStore.update(
  1242. (access) => (access.iflytekApiSecret = e.currentTarget.value),
  1243. );
  1244. }}
  1245. />
  1246. </ListItem>
  1247. </>
  1248. );
  1249. return (
  1250. <ErrorBoundary>
  1251. <div className="window-header" data-tauri-drag-region>
  1252. <div className="window-header-title">
  1253. <div className="window-header-main-title">
  1254. {Locale.Settings.Title}
  1255. </div>
  1256. <div className="window-header-sub-title">
  1257. {Locale.Settings.SubTitle}
  1258. </div>
  1259. </div>
  1260. <div className="window-actions">
  1261. <div className="window-action-button"></div>
  1262. <div className="window-action-button"></div>
  1263. <div className="window-action-button">
  1264. <IconButton
  1265. aria={Locale.UI.Close}
  1266. icon={<CloseIcon />}
  1267. onClick={() => navigate(Path.Home)}
  1268. bordered
  1269. />
  1270. </div>
  1271. </div>
  1272. </div>
  1273. <div className={styles["settings"]}>
  1274. <List>
  1275. <ListItem title={Locale.Settings.Avatar}>
  1276. <Popover
  1277. onClose={() => setShowEmojiPicker(false)}
  1278. content={
  1279. <AvatarPicker
  1280. onEmojiClick={(avatar: string) => {
  1281. updateConfig((config) => (config.avatar = avatar));
  1282. setShowEmojiPicker(false);
  1283. }}
  1284. />
  1285. }
  1286. open={showEmojiPicker}
  1287. >
  1288. <div
  1289. aria-label={Locale.Settings.Avatar}
  1290. tabIndex={0}
  1291. className={styles.avatar}
  1292. onClick={() => {
  1293. setShowEmojiPicker(!showEmojiPicker);
  1294. }}
  1295. >
  1296. <Avatar avatar={config.avatar} />
  1297. </div>
  1298. </Popover>
  1299. </ListItem>
  1300. <ListItem
  1301. title={Locale.Settings.Update.Version(currentVersion ?? "unknown")}
  1302. subTitle={
  1303. checkingUpdate
  1304. ? Locale.Settings.Update.IsChecking
  1305. : hasNewVersion
  1306. ? Locale.Settings.Update.FoundUpdate(remoteId ?? "ERROR")
  1307. : Locale.Settings.Update.IsLatest
  1308. }
  1309. >
  1310. {checkingUpdate ? (
  1311. <LoadingIcon />
  1312. ) : hasNewVersion ? (
  1313. <Link href={updateUrl} target="_blank" className="link">
  1314. {Locale.Settings.Update.GoToUpdate}
  1315. </Link>
  1316. ) : (
  1317. <IconButton
  1318. icon={<ResetIcon></ResetIcon>}
  1319. text={Locale.Settings.Update.CheckUpdate}
  1320. onClick={() => checkUpdate(true)}
  1321. />
  1322. )}
  1323. </ListItem>
  1324. <ListItem title={Locale.Settings.SendKey}>
  1325. <Select
  1326. aria-label={Locale.Settings.SendKey}
  1327. value={config.submitKey}
  1328. onChange={(e) => {
  1329. updateConfig(
  1330. (config) =>
  1331. (config.submitKey = e.target.value as any as SubmitKey),
  1332. );
  1333. }}
  1334. >
  1335. {Object.values(SubmitKey).map((v) => (
  1336. <option value={v} key={v}>
  1337. {v}
  1338. </option>
  1339. ))}
  1340. </Select>
  1341. </ListItem>
  1342. <ListItem title={Locale.Settings.Theme}>
  1343. <Select
  1344. aria-label={Locale.Settings.Theme}
  1345. value={config.theme}
  1346. onChange={(e) => {
  1347. updateConfig(
  1348. (config) => (config.theme = e.target.value as any as Theme),
  1349. );
  1350. }}
  1351. >
  1352. {Object.values(Theme).map((v) => (
  1353. <option value={v} key={v}>
  1354. {v}
  1355. </option>
  1356. ))}
  1357. </Select>
  1358. </ListItem>
  1359. <ListItem title={Locale.Settings.Lang.Name}>
  1360. <Select
  1361. aria-label={Locale.Settings.Lang.Name}
  1362. value={getLang()}
  1363. onChange={(e) => {
  1364. changeLang(e.target.value as any);
  1365. }}
  1366. >
  1367. {AllLangs.map((lang) => (
  1368. <option value={lang} key={lang}>
  1369. {ALL_LANG_OPTIONS[lang]}
  1370. </option>
  1371. ))}
  1372. </Select>
  1373. </ListItem>
  1374. <ListItem
  1375. title={Locale.Settings.FontSize.Title}
  1376. subTitle={Locale.Settings.FontSize.SubTitle}
  1377. >
  1378. <InputRange
  1379. aria={Locale.Settings.FontSize.Title}
  1380. title={`${config.fontSize ?? 14}px`}
  1381. value={config.fontSize}
  1382. min="12"
  1383. max="40"
  1384. step="1"
  1385. onChange={(e) =>
  1386. updateConfig(
  1387. (config) =>
  1388. (config.fontSize = Number.parseInt(e.currentTarget.value)),
  1389. )
  1390. }
  1391. ></InputRange>
  1392. </ListItem>
  1393. <ListItem
  1394. title={Locale.Settings.FontFamily.Title}
  1395. subTitle={Locale.Settings.FontFamily.SubTitle}
  1396. >
  1397. <input
  1398. aria-label={Locale.Settings.FontFamily.Title}
  1399. type="text"
  1400. value={config.fontFamily}
  1401. placeholder={Locale.Settings.FontFamily.Placeholder}
  1402. onChange={(e) =>
  1403. updateConfig(
  1404. (config) => (config.fontFamily = e.currentTarget.value),
  1405. )
  1406. }
  1407. ></input>
  1408. </ListItem>
  1409. <ListItem
  1410. title={Locale.Settings.AutoGenerateTitle.Title}
  1411. subTitle={Locale.Settings.AutoGenerateTitle.SubTitle}
  1412. >
  1413. <input
  1414. aria-label={Locale.Settings.AutoGenerateTitle.Title}
  1415. type="checkbox"
  1416. checked={config.enableAutoGenerateTitle}
  1417. onChange={(e) =>
  1418. updateConfig(
  1419. (config) =>
  1420. (config.enableAutoGenerateTitle = e.currentTarget.checked),
  1421. )
  1422. }
  1423. ></input>
  1424. </ListItem>
  1425. <ListItem
  1426. title={Locale.Settings.SendPreviewBubble.Title}
  1427. subTitle={Locale.Settings.SendPreviewBubble.SubTitle}
  1428. >
  1429. <input
  1430. aria-label={Locale.Settings.SendPreviewBubble.Title}
  1431. type="checkbox"
  1432. checked={config.sendPreviewBubble}
  1433. onChange={(e) =>
  1434. updateConfig(
  1435. (config) =>
  1436. (config.sendPreviewBubble = e.currentTarget.checked),
  1437. )
  1438. }
  1439. ></input>
  1440. </ListItem>
  1441. </List>
  1442. <SyncItems />
  1443. <List>
  1444. <ListItem
  1445. title={Locale.Settings.Mask.Splash.Title}
  1446. subTitle={Locale.Settings.Mask.Splash.SubTitle}
  1447. >
  1448. <input
  1449. aria-label={Locale.Settings.Mask.Splash.Title}
  1450. type="checkbox"
  1451. checked={!config.dontShowMaskSplashScreen}
  1452. onChange={(e) =>
  1453. updateConfig(
  1454. (config) =>
  1455. (config.dontShowMaskSplashScreen =
  1456. !e.currentTarget.checked),
  1457. )
  1458. }
  1459. ></input>
  1460. </ListItem>
  1461. <ListItem
  1462. title={Locale.Settings.Mask.Builtin.Title}
  1463. subTitle={Locale.Settings.Mask.Builtin.SubTitle}
  1464. >
  1465. <input
  1466. aria-label={Locale.Settings.Mask.Builtin.Title}
  1467. type="checkbox"
  1468. checked={config.hideBuiltinMasks}
  1469. onChange={(e) =>
  1470. updateConfig(
  1471. (config) =>
  1472. (config.hideBuiltinMasks = e.currentTarget.checked),
  1473. )
  1474. }
  1475. ></input>
  1476. </ListItem>
  1477. </List>
  1478. <List>
  1479. <ListItem
  1480. title={Locale.Settings.Prompt.Disable.Title}
  1481. subTitle={Locale.Settings.Prompt.Disable.SubTitle}
  1482. >
  1483. <input
  1484. aria-label={Locale.Settings.Prompt.Disable.Title}
  1485. type="checkbox"
  1486. checked={config.disablePromptHint}
  1487. onChange={(e) =>
  1488. updateConfig(
  1489. (config) =>
  1490. (config.disablePromptHint = e.currentTarget.checked),
  1491. )
  1492. }
  1493. ></input>
  1494. </ListItem>
  1495. <ListItem
  1496. title={Locale.Settings.Prompt.List}
  1497. subTitle={Locale.Settings.Prompt.ListCount(
  1498. builtinCount,
  1499. customCount,
  1500. )}
  1501. >
  1502. <IconButton
  1503. aria={Locale.Settings.Prompt.List + Locale.Settings.Prompt.Edit}
  1504. icon={<EditIcon />}
  1505. text={Locale.Settings.Prompt.Edit}
  1506. onClick={() => setShowPromptModal(true)}
  1507. />
  1508. </ListItem>
  1509. </List>
  1510. <List id={SlotID.CustomModel}>
  1511. {accessCodeComponent}
  1512. {!accessStore.hideUserApiKey && (
  1513. <>
  1514. {useCustomConfigComponent}
  1515. {accessStore.useCustomConfig && (
  1516. <>
  1517. <ListItem
  1518. title={Locale.Settings.Access.Provider.Title}
  1519. subTitle={Locale.Settings.Access.Provider.SubTitle}
  1520. >
  1521. <Select
  1522. aria-label={Locale.Settings.Access.Provider.Title}
  1523. value={accessStore.provider}
  1524. onChange={(e) => {
  1525. accessStore.update(
  1526. (access) =>
  1527. (access.provider = e.target
  1528. .value as ServiceProvider),
  1529. );
  1530. }}
  1531. >
  1532. {Object.entries(ServiceProvider).map(([k, v]) => (
  1533. <option value={v} key={k}>
  1534. {k}
  1535. </option>
  1536. ))}
  1537. </Select>
  1538. </ListItem>
  1539. {openAIConfigComponent}
  1540. {azureConfigComponent}
  1541. {googleConfigComponent}
  1542. {anthropicConfigComponent}
  1543. {baiduConfigComponent}
  1544. {byteDanceConfigComponent}
  1545. {alibabaConfigComponent}
  1546. {tencentConfigComponent}
  1547. {moonshotConfigComponent}
  1548. {stabilityConfigComponent}
  1549. {lflytekConfigComponent}
  1550. </>
  1551. )}
  1552. </>
  1553. )}
  1554. {!shouldHideBalanceQuery && !clientConfig?.isApp ? (
  1555. <ListItem
  1556. title={Locale.Settings.Usage.Title}
  1557. subTitle={
  1558. showUsage
  1559. ? loadingUsage
  1560. ? Locale.Settings.Usage.IsChecking
  1561. : Locale.Settings.Usage.SubTitle(
  1562. usage?.used ?? "[?]",
  1563. usage?.subscription ?? "[?]",
  1564. )
  1565. : Locale.Settings.Usage.NoAccess
  1566. }
  1567. >
  1568. {!showUsage || loadingUsage ? (
  1569. <div />
  1570. ) : (
  1571. <IconButton
  1572. icon={<ResetIcon></ResetIcon>}
  1573. text={Locale.Settings.Usage.Check}
  1574. onClick={() => checkUsage(true)}
  1575. />
  1576. )}
  1577. </ListItem>
  1578. ) : null}
  1579. <ListItem
  1580. title={Locale.Settings.Access.CustomModel.Title}
  1581. subTitle={Locale.Settings.Access.CustomModel.SubTitle}
  1582. >
  1583. <input
  1584. aria-label={Locale.Settings.Access.CustomModel.Title}
  1585. type="text"
  1586. value={config.customModels}
  1587. placeholder="model1,model2,model3"
  1588. onChange={(e) =>
  1589. config.update(
  1590. (config) => (config.customModels = e.currentTarget.value),
  1591. )
  1592. }
  1593. ></input>
  1594. </ListItem>
  1595. </List>
  1596. <List>
  1597. <ModelConfigList
  1598. modelConfig={config.modelConfig}
  1599. updateConfig={(updater) => {
  1600. const modelConfig = { ...config.modelConfig };
  1601. updater(modelConfig);
  1602. config.update((config) => (config.modelConfig = modelConfig));
  1603. }}
  1604. />
  1605. </List>
  1606. {shouldShowPromptModal && (
  1607. <UserPromptModal onClose={() => setShowPromptModal(false)} />
  1608. )}
  1609. <DangerItems />
  1610. </div>
  1611. </ErrorBoundary>
  1612. );
  1613. }