settings.tsx 57 KB

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