settings.tsx 56 KB

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