mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-30 01:20:22 +09:00
Merge pull request #1 from SolarifyDev/add-ome-metis-token
Add omeToken
This commit is contained in:
commit
514359ac14
@ -10,6 +10,7 @@ import {
|
|||||||
ModelType,
|
ModelType,
|
||||||
useAccessStore,
|
useAccessStore,
|
||||||
useChatStore,
|
useChatStore,
|
||||||
|
useAppConfig,
|
||||||
} from "../store";
|
} from "../store";
|
||||||
import { ChatGPTApi, DalleRequestPayload } from "./platforms/openai";
|
import { ChatGPTApi, DalleRequestPayload } from "./platforms/openai";
|
||||||
import { GeminiProApi } from "./platforms/google";
|
import { GeminiProApi } from "./platforms/google";
|
||||||
@ -233,6 +234,7 @@ export function validString(x: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getHeaders(ignoreHeaders: boolean = false) {
|
export function getHeaders(ignoreHeaders: boolean = false) {
|
||||||
|
const appConfig = useAppConfig.getState();
|
||||||
const accessStore = useAccessStore.getState();
|
const accessStore = useAccessStore.getState();
|
||||||
const chatStore = useChatStore.getState();
|
const chatStore = useChatStore.getState();
|
||||||
let headers: Record<string, string> = {};
|
let headers: Record<string, string> = {};
|
||||||
@ -348,6 +350,8 @@ export function getHeaders(ignoreHeaders: boolean = false) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
headers["OME-METIS-Authorization"] = appConfig.omeToken || "";
|
||||||
|
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ import { type ClientApi, getClientApi } from "../client/api";
|
|||||||
import { useAccessStore } from "../store";
|
import { useAccessStore } from "../store";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { initializeMcpSystem, isMcpEnabled } from "../mcp/actions";
|
import { initializeMcpSystem, isMcpEnabled } from "../mcp/actions";
|
||||||
|
import { isEmpty } from "lodash-es";
|
||||||
|
|
||||||
export function Loading(props: { noLogo?: boolean }) {
|
export function Loading(props: { noLogo?: boolean }) {
|
||||||
return (
|
return (
|
||||||
@ -239,6 +240,8 @@ export function Home() {
|
|||||||
useLoadData();
|
useLoadData();
|
||||||
useHtmlLang();
|
useHtmlLang();
|
||||||
|
|
||||||
|
const appConfig = useAppConfig();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("[Config] got config from build time", getClientConfig());
|
console.log("[Config] got config from build time", getClientConfig());
|
||||||
useAccessStore.getState().fetch();
|
useAccessStore.getState().fetch();
|
||||||
@ -258,6 +261,25 @@ export function Home() {
|
|||||||
initMcp();
|
initMcp();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.parent.postMessage("omemetis is ready", "*");
|
||||||
|
|
||||||
|
const handleMessage = (event: any) => {
|
||||||
|
if (!event.origin.includes("omeoffice")) {
|
||||||
|
return; // 如果不是信任的源,忽略消息
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isEmpty(event?.data?.omeToken))
|
||||||
|
appConfig.setOmeToken(event.data.omeToken);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("message", handleMessage);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("message", handleMessage);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (!useHasHydrated()) {
|
if (!useHasHydrated()) {
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import styles from "./home.module.scss";
|
|||||||
|
|
||||||
import { IconButton } from "./button";
|
import { IconButton } from "./button";
|
||||||
import SettingsIcon from "../icons/settings.svg";
|
import SettingsIcon from "../icons/settings.svg";
|
||||||
import GithubIcon from "../icons/github.svg";
|
|
||||||
import ChatGptIcon from "../icons/chatgpt.svg";
|
import ChatGptIcon from "../icons/chatgpt.svg";
|
||||||
import AddIcon from "../icons/add.svg";
|
import AddIcon from "../icons/add.svg";
|
||||||
import DeleteIcon from "../icons/delete.svg";
|
import DeleteIcon from "../icons/delete.svg";
|
||||||
@ -23,7 +22,6 @@ import {
|
|||||||
MIN_SIDEBAR_WIDTH,
|
MIN_SIDEBAR_WIDTH,
|
||||||
NARROW_SIDEBAR_WIDTH,
|
NARROW_SIDEBAR_WIDTH,
|
||||||
Path,
|
Path,
|
||||||
REPO_URL,
|
|
||||||
} from "../constant";
|
} from "../constant";
|
||||||
|
|
||||||
import { Link, useNavigate } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
@ -336,15 +334,6 @@ export function SideBar(props: { className?: string }) {
|
|||||||
/>
|
/>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles["sidebar-action"]}>
|
|
||||||
<a href={REPO_URL} target="_blank" rel="noopener noreferrer">
|
|
||||||
<IconButton
|
|
||||||
aria={Locale.Export.MessageFromChatGPT}
|
|
||||||
icon={<GithubIcon />}
|
|
||||||
shadow
|
|
||||||
/>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
secondaryAction={
|
secondaryAction={
|
||||||
|
@ -46,7 +46,8 @@ export const DEFAULT_CONFIG = {
|
|||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
fontFamily: "",
|
fontFamily: "",
|
||||||
theme: Theme.Auto as Theme,
|
theme: Theme.Auto as Theme,
|
||||||
tightBorder: !!config?.isApp,
|
// tightBorder: !!config?.isApp,
|
||||||
|
tightBorder: true,
|
||||||
sendPreviewBubble: true,
|
sendPreviewBubble: true,
|
||||||
enableAutoGenerateTitle: true,
|
enableAutoGenerateTitle: true,
|
||||||
sidebarWidth: DEFAULT_SIDEBAR_WIDTH,
|
sidebarWidth: DEFAULT_SIDEBAR_WIDTH,
|
||||||
@ -104,6 +105,7 @@ export const DEFAULT_CONFIG = {
|
|||||||
temperature: 0.9,
|
temperature: 0.9,
|
||||||
voice: "alloy" as Voice,
|
voice: "alloy" as Voice,
|
||||||
},
|
},
|
||||||
|
omeToken: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ChatConfig = typeof DEFAULT_CONFIG;
|
export type ChatConfig = typeof DEFAULT_CONFIG;
|
||||||
@ -165,7 +167,13 @@ export const useAppConfig = createPersistStore(
|
|||||||
{ ...DEFAULT_CONFIG },
|
{ ...DEFAULT_CONFIG },
|
||||||
(set, get) => ({
|
(set, get) => ({
|
||||||
reset() {
|
reset() {
|
||||||
set(() => ({ ...DEFAULT_CONFIG }));
|
const { omeToken } = get();
|
||||||
|
|
||||||
|
set(() => ({ ...DEFAULT_CONFIG, omeToken }));
|
||||||
|
},
|
||||||
|
|
||||||
|
setOmeToken(omeToken: string) {
|
||||||
|
set(() => ({ omeToken }));
|
||||||
},
|
},
|
||||||
|
|
||||||
mergeModels(newModels: LLMModel[]) {
|
mergeModels(newModels: LLMModel[]) {
|
||||||
|
Loading…
Reference in New Issue
Block a user