mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-03 14:22:13 +08:00
feat: re-implement configuration at client-side
This commit is contained in:
@@ -8,6 +8,7 @@ import { Geist } from "next/font/google";
|
||||
import Script from "next/script";
|
||||
|
||||
import { ThemeProviderWrapper } from "~/components/deer-flow/theme-provider-wrapper";
|
||||
import { loadConfig } from "~/core/api/config";
|
||||
import { env } from "~/env";
|
||||
|
||||
import { Toaster } from "../components/deer-flow/toaster";
|
||||
@@ -24,12 +25,14 @@ const geist = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
});
|
||||
|
||||
export default function RootLayout({
|
||||
export default async function RootLayout({
|
||||
children,
|
||||
}: Readonly<{ children: React.ReactNode }>) {
|
||||
const conf = await loadConfig();
|
||||
return (
|
||||
<html lang="en" className={`${geist.variable}`} suppressHydrationWarning>
|
||||
<head>
|
||||
<script>{`window.__deerflowConfig = ${JSON.stringify(conf)}`}</script>
|
||||
{/* Define isSpace function globally to fix markdown-it issues with Next.js + Turbopack
|
||||
https://github.com/markdown-it/markdown-it/issues/1082#issuecomment-2749656365 */}
|
||||
<Script id="markdown-it-fix" strategy="beforeInteractive">
|
||||
|
||||
25
web/src/core/api/config.ts
Normal file
25
web/src/core/api/config.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { type DeerFlowConfig } from "../config/types";
|
||||
|
||||
import { resolveServiceURL } from "./resolve-service-url";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
__deerflowConfig: DeerFlowConfig;
|
||||
}
|
||||
}
|
||||
|
||||
export async function loadConfig() {
|
||||
const res = await fetch(resolveServiceURL("./config"));
|
||||
const config = await res.json();
|
||||
return config;
|
||||
}
|
||||
|
||||
export function getConfig(): DeerFlowConfig {
|
||||
if (
|
||||
typeof window === "undefined" ||
|
||||
typeof window.__deerflowConfig === "undefined"
|
||||
) {
|
||||
throw new Error("Config not loaded");
|
||||
}
|
||||
return window.__deerflowConfig;
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import { env } from "~/env";
|
||||
import { useReplay } from "../replay";
|
||||
|
||||
import { fetchReplayTitle } from "./chat";
|
||||
import { getRAGConfig } from "./rag";
|
||||
import { getConfig } from "./config";
|
||||
|
||||
export function useReplayMetadata() {
|
||||
const { isReplay } = useReplay();
|
||||
@@ -52,15 +52,8 @@ export function useRAGProvider() {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
getRAGConfig()
|
||||
.then(setProvider)
|
||||
.catch((e) => {
|
||||
setProvider(null);
|
||||
console.error("Failed to get RAG provider", e);
|
||||
})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
setProvider(getConfig().rag.provider);
|
||||
setLoading(false);
|
||||
}, []);
|
||||
|
||||
return { provider, loading };
|
||||
|
||||
@@ -10,15 +10,7 @@ export function queryRAGResources(query: string) {
|
||||
.then((res) => {
|
||||
return res.resources as Array<Resource>;
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch(() => {
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
export function getRAGConfig() {
|
||||
return fetch(resolveServiceURL(`rag/config`), {
|
||||
method: "GET",
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => res.provider);
|
||||
}
|
||||
|
||||
1
web/src/core/config/index.ts
Normal file
1
web/src/core/config/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./types";
|
||||
13
web/src/core/config/types.ts
Normal file
13
web/src/core/config/types.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export interface ModelConfig {
|
||||
basic: string[];
|
||||
reasoning: string[];
|
||||
}
|
||||
|
||||
export interface RagConfig {
|
||||
provider: string;
|
||||
}
|
||||
|
||||
export interface DeerFlowConfig {
|
||||
rag: RagConfig;
|
||||
models: ModelConfig;
|
||||
}
|
||||
Reference in New Issue
Block a user