diff --git a/app/client/api.ts b/app/client/api.ts index 64ac82b2a..f57be79f1 100644 --- a/app/client/api.ts +++ b/app/client/api.ts @@ -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 = {}; @@ -348,6 +350,8 @@ export function getHeaders(ignoreHeaders: boolean = false) { ); } + headers["OME-METIS-Authorization"] = appConfig.omeToken || ""; + return headers; } diff --git a/app/components/home.tsx b/app/components/home.tsx index 98f759a48..16e33c763 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -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 ; } diff --git a/app/components/sidebar.tsx b/app/components/sidebar.tsx index 56bc5bb43..6cc25bf19 100644 --- a/app/components/sidebar.tsx +++ b/app/components/sidebar.tsx @@ -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 }) { /> -
- - } - shadow - /> - -
} secondaryAction={ diff --git a/app/store/config.ts b/app/store/config.ts index 45e21b026..f360293d1 100644 --- a/app/store/config.ts +++ b/app/store/config.ts @@ -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[]) {