|
@@ -37,7 +37,6 @@ import {
|
|
|
SubmitKey,
|
|
SubmitKey,
|
|
|
useChatStore,
|
|
useChatStore,
|
|
|
Theme,
|
|
Theme,
|
|
|
- useUpdateStore,
|
|
|
|
|
useAccessStore,
|
|
useAccessStore,
|
|
|
useAppConfig,
|
|
useAppConfig,
|
|
|
} from "../store";
|
|
} from "../store";
|
|
@@ -51,23 +50,16 @@ import Locale, {
|
|
|
import { copyToClipboard } from "../utils";
|
|
import { copyToClipboard } from "../utils";
|
|
|
import Link from "next/link";
|
|
import Link from "next/link";
|
|
|
import {
|
|
import {
|
|
|
- Anthropic,
|
|
|
|
|
Azure,
|
|
Azure,
|
|
|
Baidu,
|
|
Baidu,
|
|
|
Tencent,
|
|
Tencent,
|
|
|
ByteDance,
|
|
ByteDance,
|
|
|
Alibaba,
|
|
Alibaba,
|
|
|
- Moonshot,
|
|
|
|
|
- Google,
|
|
|
|
|
- GoogleSafetySettingsThreshold,
|
|
|
|
|
OPENAI_BASE_URL,
|
|
OPENAI_BASE_URL,
|
|
|
Path,
|
|
Path,
|
|
|
- RELEASE_URL,
|
|
|
|
|
STORAGE_KEY,
|
|
STORAGE_KEY,
|
|
|
ServiceProvider,
|
|
ServiceProvider,
|
|
|
SlotID,
|
|
SlotID,
|
|
|
- UPDATE_URL,
|
|
|
|
|
- Stability,
|
|
|
|
|
Iflytek,
|
|
Iflytek,
|
|
|
} from "../constant";
|
|
} from "../constant";
|
|
|
import { Prompt, SearchService, usePromptStore } from "../store/prompt";
|
|
import { Prompt, SearchService, usePromptStore } from "../store/prompt";
|
|
@@ -627,22 +619,7 @@ export function Settings() {
|
|
|
const config = useAppConfig();
|
|
const config = useAppConfig();
|
|
|
const updateConfig = config.update;
|
|
const updateConfig = config.update;
|
|
|
|
|
|
|
|
- const updateStore = useUpdateStore();
|
|
|
|
|
- const [checkingUpdate, setCheckingUpdate] = useState(false);
|
|
|
|
|
- const currentVersion = updateStore.formatVersion(updateStore.version);
|
|
|
|
|
- const remoteId = updateStore.formatVersion(updateStore.remoteVersion);
|
|
|
|
|
- const hasNewVersion = currentVersion !== remoteId;
|
|
|
|
|
- const updateUrl = getClientConfig()?.isApp ? RELEASE_URL : UPDATE_URL;
|
|
|
|
|
-
|
|
|
|
|
- function checkUpdate(force = false) {
|
|
|
|
|
- setCheckingUpdate(true);
|
|
|
|
|
- updateStore.getLatestVersion(force).then(() => {
|
|
|
|
|
- setCheckingUpdate(false);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- console.log("[Update] local version ", updateStore.version);
|
|
|
|
|
- console.log("[Update] remote version ", updateStore.remoteVersion);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
const accessStore = useAccessStore();
|
|
const accessStore = useAccessStore();
|
|
|
const shouldHideBalanceQuery = useMemo(() => {
|
|
const shouldHideBalanceQuery = useMemo(() => {
|
|
@@ -659,21 +636,7 @@ export function Settings() {
|
|
|
accessStore.provider,
|
|
accessStore.provider,
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
- const usage = {
|
|
|
|
|
- used: updateStore.used,
|
|
|
|
|
- subscription: updateStore.subscription,
|
|
|
|
|
- };
|
|
|
|
|
- const [loadingUsage, setLoadingUsage] = useState(false);
|
|
|
|
|
- function checkUsage(force = false) {
|
|
|
|
|
- if (shouldHideBalanceQuery) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- setLoadingUsage(true);
|
|
|
|
|
- updateStore.updateUsage(force).finally(() => {
|
|
|
|
|
- setLoadingUsage(false);
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
const enabledAccessControl = useMemo(
|
|
const enabledAccessControl = useMemo(
|
|
|
() => accessStore.enabledAccessControl(),
|
|
() => accessStore.enabledAccessControl(),
|
|
@@ -687,13 +650,7 @@ export function Settings() {
|
|
|
const customCount = promptStore.getUserPrompts().length ?? 0;
|
|
const customCount = promptStore.getUserPrompts().length ?? 0;
|
|
|
const [shouldShowPromptModal, setShowPromptModal] = useState(false);
|
|
const [shouldShowPromptModal, setShowPromptModal] = useState(false);
|
|
|
|
|
|
|
|
- const showUsage = accessStore.isAuthorized();
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- // checks per minutes
|
|
|
|
|
- checkUpdate();
|
|
|
|
|
- showUsage && checkUsage();
|
|
|
|
|
- // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
- }, []);
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
const keydownEvent = (e: KeyboardEvent) => {
|
|
const keydownEvent = (e: KeyboardEvent) => {
|
|
@@ -849,141 +806,9 @@ export function Settings() {
|
|
|
</>
|
|
</>
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- const googleConfigComponent = accessStore.provider ===
|
|
|
|
|
- ServiceProvider.Google && (
|
|
|
|
|
- <>
|
|
|
|
|
- <ListItem
|
|
|
|
|
- title={Locale.Settings.Access.Google.Endpoint.Title}
|
|
|
|
|
- subTitle={
|
|
|
|
|
- Locale.Settings.Access.Google.Endpoint.SubTitle +
|
|
|
|
|
- Google.ExampleEndpoint
|
|
|
|
|
- }
|
|
|
|
|
- >
|
|
|
|
|
- <input
|
|
|
|
|
- aria-label={Locale.Settings.Access.Google.Endpoint.Title}
|
|
|
|
|
- type="text"
|
|
|
|
|
- value={accessStore.googleUrl}
|
|
|
|
|
- placeholder={Google.ExampleEndpoint}
|
|
|
|
|
- onChange={(e) =>
|
|
|
|
|
- accessStore.update(
|
|
|
|
|
- (access) => (access.googleUrl = e.currentTarget.value),
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- ></input>
|
|
|
|
|
- </ListItem>
|
|
|
|
|
- <ListItem
|
|
|
|
|
- title={Locale.Settings.Access.Google.ApiKey.Title}
|
|
|
|
|
- subTitle={Locale.Settings.Access.Google.ApiKey.SubTitle}
|
|
|
|
|
- >
|
|
|
|
|
- <PasswordInput
|
|
|
|
|
- aria-label={Locale.Settings.Access.Google.ApiKey.Title}
|
|
|
|
|
- value={accessStore.googleApiKey}
|
|
|
|
|
- type="text"
|
|
|
|
|
- placeholder={Locale.Settings.Access.Google.ApiKey.Placeholder}
|
|
|
|
|
- onChange={(e) => {
|
|
|
|
|
- accessStore.update(
|
|
|
|
|
- (access) => (access.googleApiKey = e.currentTarget.value),
|
|
|
|
|
- );
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- </ListItem>
|
|
|
|
|
- <ListItem
|
|
|
|
|
- title={Locale.Settings.Access.Google.ApiVersion.Title}
|
|
|
|
|
- subTitle={Locale.Settings.Access.Google.ApiVersion.SubTitle}
|
|
|
|
|
- >
|
|
|
|
|
- <input
|
|
|
|
|
- aria-label={Locale.Settings.Access.Google.ApiVersion.Title}
|
|
|
|
|
- type="text"
|
|
|
|
|
- value={accessStore.googleApiVersion}
|
|
|
|
|
- placeholder="2023-08-01-preview"
|
|
|
|
|
- onChange={(e) =>
|
|
|
|
|
- accessStore.update(
|
|
|
|
|
- (access) => (access.googleApiVersion = e.currentTarget.value),
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- ></input>
|
|
|
|
|
- </ListItem>
|
|
|
|
|
- <ListItem
|
|
|
|
|
- title={Locale.Settings.Access.Google.GoogleSafetySettings.Title}
|
|
|
|
|
- subTitle={Locale.Settings.Access.Google.GoogleSafetySettings.SubTitle}
|
|
|
|
|
- >
|
|
|
|
|
- <Select
|
|
|
|
|
- aria-label={Locale.Settings.Access.Google.GoogleSafetySettings.Title}
|
|
|
|
|
- value={accessStore.googleSafetySettings}
|
|
|
|
|
- onChange={(e) => {
|
|
|
|
|
- accessStore.update(
|
|
|
|
|
- (access) =>
|
|
|
|
|
- (access.googleSafetySettings = e.target
|
|
|
|
|
- .value as GoogleSafetySettingsThreshold),
|
|
|
|
|
- );
|
|
|
|
|
- }}
|
|
|
|
|
- >
|
|
|
|
|
- {Object.entries(GoogleSafetySettingsThreshold).map(([k, v]) => (
|
|
|
|
|
- <option value={v} key={k}>
|
|
|
|
|
- {k}
|
|
|
|
|
- </option>
|
|
|
|
|
- ))}
|
|
|
|
|
- </Select>
|
|
|
|
|
- </ListItem>
|
|
|
|
|
- </>
|
|
|
|
|
- );
|
|
|
|
|
|
|
|
|
|
- const anthropicConfigComponent = accessStore.provider ===
|
|
|
|
|
- ServiceProvider.Anthropic && (
|
|
|
|
|
- <>
|
|
|
|
|
- <ListItem
|
|
|
|
|
- title={Locale.Settings.Access.Anthropic.Endpoint.Title}
|
|
|
|
|
- subTitle={
|
|
|
|
|
- Locale.Settings.Access.Anthropic.Endpoint.SubTitle +
|
|
|
|
|
- Anthropic.ExampleEndpoint
|
|
|
|
|
- }
|
|
|
|
|
- >
|
|
|
|
|
- <input
|
|
|
|
|
- aria-label={Locale.Settings.Access.Anthropic.Endpoint.Title}
|
|
|
|
|
- type="text"
|
|
|
|
|
- value={accessStore.anthropicUrl}
|
|
|
|
|
- placeholder={Anthropic.ExampleEndpoint}
|
|
|
|
|
- onChange={(e) =>
|
|
|
|
|
- accessStore.update(
|
|
|
|
|
- (access) => (access.anthropicUrl = e.currentTarget.value),
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- ></input>
|
|
|
|
|
- </ListItem>
|
|
|
|
|
- <ListItem
|
|
|
|
|
- title={Locale.Settings.Access.Anthropic.ApiKey.Title}
|
|
|
|
|
- subTitle={Locale.Settings.Access.Anthropic.ApiKey.SubTitle}
|
|
|
|
|
- >
|
|
|
|
|
- <PasswordInput
|
|
|
|
|
- aria-label={Locale.Settings.Access.Anthropic.ApiKey.Title}
|
|
|
|
|
- value={accessStore.anthropicApiKey}
|
|
|
|
|
- type="text"
|
|
|
|
|
- placeholder={Locale.Settings.Access.Anthropic.ApiKey.Placeholder}
|
|
|
|
|
- onChange={(e) => {
|
|
|
|
|
- accessStore.update(
|
|
|
|
|
- (access) => (access.anthropicApiKey = e.currentTarget.value),
|
|
|
|
|
- );
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- </ListItem>
|
|
|
|
|
- <ListItem
|
|
|
|
|
- title={Locale.Settings.Access.Anthropic.ApiVerion.Title}
|
|
|
|
|
- subTitle={Locale.Settings.Access.Anthropic.ApiVerion.SubTitle}
|
|
|
|
|
- >
|
|
|
|
|
- <input
|
|
|
|
|
- aria-label={Locale.Settings.Access.Anthropic.ApiVerion.Title}
|
|
|
|
|
- type="text"
|
|
|
|
|
- value={accessStore.anthropicApiVersion}
|
|
|
|
|
- placeholder={Anthropic.Vision}
|
|
|
|
|
- onChange={(e) =>
|
|
|
|
|
- accessStore.update(
|
|
|
|
|
- (access) => (access.anthropicApiVersion = e.currentTarget.value),
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- ></input>
|
|
|
|
|
- </ListItem>
|
|
|
|
|
- </>
|
|
|
|
|
- );
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const anthropicConfigComponent = null;
|
|
|
|
|
|
|
|
const baiduConfigComponent = accessStore.provider ===
|
|
const baiduConfigComponent = accessStore.provider ===
|
|
|
ServiceProvider.Baidu && (
|
|
ServiceProvider.Baidu && (
|
|
@@ -1175,87 +1000,9 @@ export function Settings() {
|
|
|
</>
|
|
</>
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- const moonshotConfigComponent = accessStore.provider ===
|
|
|
|
|
- ServiceProvider.Moonshot && (
|
|
|
|
|
- <>
|
|
|
|
|
- <ListItem
|
|
|
|
|
- title={Locale.Settings.Access.Moonshot.Endpoint.Title}
|
|
|
|
|
- subTitle={
|
|
|
|
|
- Locale.Settings.Access.Moonshot.Endpoint.SubTitle +
|
|
|
|
|
- Moonshot.ExampleEndpoint
|
|
|
|
|
- }
|
|
|
|
|
- >
|
|
|
|
|
- <input
|
|
|
|
|
- aria-label={Locale.Settings.Access.Moonshot.Endpoint.Title}
|
|
|
|
|
- type="text"
|
|
|
|
|
- value={accessStore.moonshotUrl}
|
|
|
|
|
- placeholder={Moonshot.ExampleEndpoint}
|
|
|
|
|
- onChange={(e) =>
|
|
|
|
|
- accessStore.update(
|
|
|
|
|
- (access) => (access.moonshotUrl = e.currentTarget.value),
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- ></input>
|
|
|
|
|
- </ListItem>
|
|
|
|
|
- <ListItem
|
|
|
|
|
- title={Locale.Settings.Access.Moonshot.ApiKey.Title}
|
|
|
|
|
- subTitle={Locale.Settings.Access.Moonshot.ApiKey.SubTitle}
|
|
|
|
|
- >
|
|
|
|
|
- <PasswordInput
|
|
|
|
|
- aria-label={Locale.Settings.Access.Moonshot.ApiKey.Title}
|
|
|
|
|
- value={accessStore.moonshotApiKey}
|
|
|
|
|
- type="text"
|
|
|
|
|
- placeholder={Locale.Settings.Access.Moonshot.ApiKey.Placeholder}
|
|
|
|
|
- onChange={(e) => {
|
|
|
|
|
- accessStore.update(
|
|
|
|
|
- (access) => (access.moonshotApiKey = e.currentTarget.value),
|
|
|
|
|
- );
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- </ListItem>
|
|
|
|
|
- </>
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ const moonshotConfigComponent = null;
|
|
|
|
|
|
|
|
- const stabilityConfigComponent = accessStore.provider ===
|
|
|
|
|
- ServiceProvider.Stability && (
|
|
|
|
|
- <>
|
|
|
|
|
- <ListItem
|
|
|
|
|
- title={Locale.Settings.Access.Stability.Endpoint.Title}
|
|
|
|
|
- subTitle={
|
|
|
|
|
- Locale.Settings.Access.Stability.Endpoint.SubTitle +
|
|
|
|
|
- Stability.ExampleEndpoint
|
|
|
|
|
- }
|
|
|
|
|
- >
|
|
|
|
|
- <input
|
|
|
|
|
- aria-label={Locale.Settings.Access.Stability.Endpoint.Title}
|
|
|
|
|
- type="text"
|
|
|
|
|
- value={accessStore.stabilityUrl}
|
|
|
|
|
- placeholder={Stability.ExampleEndpoint}
|
|
|
|
|
- onChange={(e) =>
|
|
|
|
|
- accessStore.update(
|
|
|
|
|
- (access) => (access.stabilityUrl = e.currentTarget.value),
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
- ></input>
|
|
|
|
|
- </ListItem>
|
|
|
|
|
- <ListItem
|
|
|
|
|
- title={Locale.Settings.Access.Stability.ApiKey.Title}
|
|
|
|
|
- subTitle={Locale.Settings.Access.Stability.ApiKey.SubTitle}
|
|
|
|
|
- >
|
|
|
|
|
- <PasswordInput
|
|
|
|
|
- aria-label={Locale.Settings.Access.Stability.ApiKey.Title}
|
|
|
|
|
- value={accessStore.stabilityApiKey}
|
|
|
|
|
- type="text"
|
|
|
|
|
- placeholder={Locale.Settings.Access.Stability.ApiKey.Placeholder}
|
|
|
|
|
- onChange={(e) => {
|
|
|
|
|
- accessStore.update(
|
|
|
|
|
- (access) => (access.stabilityApiKey = e.currentTarget.value),
|
|
|
|
|
- );
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- </ListItem>
|
|
|
|
|
- </>
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ const stabilityConfigComponent = null;
|
|
|
const lflytekConfigComponent = accessStore.provider ===
|
|
const lflytekConfigComponent = accessStore.provider ===
|
|
|
ServiceProvider.Iflytek && (
|
|
ServiceProvider.Iflytek && (
|
|
|
<>
|
|
<>
|
|
@@ -1366,30 +1113,7 @@ export function Settings() {
|
|
|
</Popover>
|
|
</Popover>
|
|
|
</ListItem>
|
|
</ListItem>
|
|
|
|
|
|
|
|
- <ListItem
|
|
|
|
|
- title={Locale.Settings.Update.Version(currentVersion ?? "unknown")}
|
|
|
|
|
- subTitle={
|
|
|
|
|
- checkingUpdate
|
|
|
|
|
- ? Locale.Settings.Update.IsChecking
|
|
|
|
|
- : hasNewVersion
|
|
|
|
|
- ? Locale.Settings.Update.FoundUpdate(remoteId ?? "ERROR")
|
|
|
|
|
- : Locale.Settings.Update.IsLatest
|
|
|
|
|
- }
|
|
|
|
|
- >
|
|
|
|
|
- {checkingUpdate ? (
|
|
|
|
|
- <LoadingIcon />
|
|
|
|
|
- ) : hasNewVersion ? (
|
|
|
|
|
- <Link href={updateUrl} target="_blank" className="link">
|
|
|
|
|
- {Locale.Settings.Update.GoToUpdate}
|
|
|
|
|
- </Link>
|
|
|
|
|
- ) : (
|
|
|
|
|
- <IconButton
|
|
|
|
|
- icon={<ResetIcon></ResetIcon>}
|
|
|
|
|
- text={Locale.Settings.Update.CheckUpdate}
|
|
|
|
|
- onClick={() => checkUpdate(true)}
|
|
|
|
|
- />
|
|
|
|
|
- )}
|
|
|
|
|
- </ListItem>
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
<ListItem title={Locale.Settings.SendKey}>
|
|
<ListItem title={Locale.Settings.SendKey}>
|
|
|
<Select
|
|
<Select
|
|
@@ -1623,45 +1347,17 @@ export function Settings() {
|
|
|
|
|
|
|
|
{openAIConfigComponent}
|
|
{openAIConfigComponent}
|
|
|
{azureConfigComponent}
|
|
{azureConfigComponent}
|
|
|
- {googleConfigComponent}
|
|
|
|
|
- {anthropicConfigComponent}
|
|
|
|
|
{baiduConfigComponent}
|
|
{baiduConfigComponent}
|
|
|
{byteDanceConfigComponent}
|
|
{byteDanceConfigComponent}
|
|
|
{alibabaConfigComponent}
|
|
{alibabaConfigComponent}
|
|
|
{tencentConfigComponent}
|
|
{tencentConfigComponent}
|
|
|
- {moonshotConfigComponent}
|
|
|
|
|
- {stabilityConfigComponent}
|
|
|
|
|
{lflytekConfigComponent}
|
|
{lflytekConfigComponent}
|
|
|
</>
|
|
</>
|
|
|
)}
|
|
)}
|
|
|
</>
|
|
</>
|
|
|
)}
|
|
)}
|
|
|
|
|
|
|
|
- {!shouldHideBalanceQuery && !clientConfig?.isApp ? (
|
|
|
|
|
- <ListItem
|
|
|
|
|
- title={Locale.Settings.Usage.Title}
|
|
|
|
|
- subTitle={
|
|
|
|
|
- showUsage
|
|
|
|
|
- ? loadingUsage
|
|
|
|
|
- ? Locale.Settings.Usage.IsChecking
|
|
|
|
|
- : Locale.Settings.Usage.SubTitle(
|
|
|
|
|
- usage?.used ?? "[?]",
|
|
|
|
|
- usage?.subscription ?? "[?]",
|
|
|
|
|
- )
|
|
|
|
|
- : Locale.Settings.Usage.NoAccess
|
|
|
|
|
- }
|
|
|
|
|
- >
|
|
|
|
|
- {!showUsage || loadingUsage ? (
|
|
|
|
|
- <div />
|
|
|
|
|
- ) : (
|
|
|
|
|
- <IconButton
|
|
|
|
|
- icon={<ResetIcon></ResetIcon>}
|
|
|
|
|
- text={Locale.Settings.Usage.Check}
|
|
|
|
|
- onClick={() => checkUsage(true)}
|
|
|
|
|
- />
|
|
|
|
|
- )}
|
|
|
|
|
- </ListItem>
|
|
|
|
|
- ) : null}
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
<ListItem
|
|
<ListItem
|
|
|
title={Locale.Settings.Access.CustomModel.Title}
|
|
title={Locale.Settings.Access.CustomModel.Title}
|