Merge pull request #1 from SolarifyDev/add-ome-metis-token

Add omeToken
This commit is contained in:
Ted 2025-02-18 15:31:43 +08:00 committed by GitHub
commit 514359ac14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 36 additions and 13 deletions

View File

@ -10,6 +10,7 @@ import {
ModelType,
useAccessStore,
useChatStore,
useAppConfig,
} from "../store";
import { ChatGPTApi, DalleRequestPayload } from "./platforms/openai";
import { GeminiProApi } from "./platforms/google";
@ -233,6 +234,7 @@ export function validString(x: string): boolean {
}
export function getHeaders(ignoreHeaders: boolean = false) {
const appConfig = useAppConfig.getState();
const accessStore = useAccessStore.getState();
const chatStore = useChatStore.getState();
let headers: Record<string, string> = {};
@ -348,6 +350,8 @@ export function getHeaders(ignoreHeaders: boolean = false) {
);
}
headers["OME-METIS-Authorization"] = appConfig.omeToken || "";
return headers;
}

View File

@ -30,6 +30,7 @@ import { type ClientApi, getClientApi } from "../client/api";
import { useAccessStore } from "../store";
import clsx from "clsx";
import { initializeMcpSystem, isMcpEnabled } from "../mcp/actions";
import { isEmpty } from "lodash-es";
export function Loading(props: { noLogo?: boolean }) {
return (
@ -239,6 +240,8 @@ export function Home() {
useLoadData();
useHtmlLang();
const appConfig = useAppConfig();
useEffect(() => {
console.log("[Config] got config from build time", getClientConfig());
useAccessStore.getState().fetch();
@ -258,6 +261,25 @@ export function Home() {
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()) {
return <Loading />;
}

View File

@ -4,7 +4,6 @@ import styles from "./home.module.scss";
import { IconButton } from "./button";
import SettingsIcon from "../icons/settings.svg";
import GithubIcon from "../icons/github.svg";
import ChatGptIcon from "../icons/chatgpt.svg";
import AddIcon from "../icons/add.svg";
import DeleteIcon from "../icons/delete.svg";
@ -23,7 +22,6 @@ import {
MIN_SIDEBAR_WIDTH,
NARROW_SIDEBAR_WIDTH,
Path,
REPO_URL,
} from "../constant";
import { Link, useNavigate } from "react-router-dom";
@ -336,15 +334,6 @@ export function SideBar(props: { className?: string }) {
/>
</Link>
</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={

View File

@ -46,7 +46,8 @@ export const DEFAULT_CONFIG = {
fontSize: 14,
fontFamily: "",
theme: Theme.Auto as Theme,
tightBorder: !!config?.isApp,
// tightBorder: !!config?.isApp,
tightBorder: true,
sendPreviewBubble: true,
enableAutoGenerateTitle: true,
sidebarWidth: DEFAULT_SIDEBAR_WIDTH,
@ -104,6 +105,7 @@ export const DEFAULT_CONFIG = {
temperature: 0.9,
voice: "alloy" as Voice,
},
omeToken: "",
};
export type ChatConfig = typeof DEFAULT_CONFIG;
@ -165,7 +167,13 @@ export const useAppConfig = createPersistStore(
{ ...DEFAULT_CONFIG },
(set, get) => ({
reset() {
set(() => ({ ...DEFAULT_CONFIG }));
const { omeToken } = get();
set(() => ({ ...DEFAULT_CONFIG, omeToken }));
},
setOmeToken(omeToken: string) {
set(() => ({ omeToken }));
},
mergeModels(newModels: LLMModel[]) {