58 lines
2.3 KiB
TypeScript
58 lines
2.3 KiB
TypeScript
type EnvValue = string | undefined;
|
|
|
|
declare global {
|
|
interface Window {
|
|
__CM_RUNTIME_CONFIG__?: Record<string, string | undefined>;
|
|
}
|
|
}
|
|
|
|
export function readRuntimeEnv(key: string): EnvValue {
|
|
const runtimeValue =
|
|
typeof window !== "undefined" ? window.__CM_RUNTIME_CONFIG__?.[key] : undefined;
|
|
if (typeof runtimeValue === "string" && runtimeValue.trim()) {
|
|
return runtimeValue.trim();
|
|
}
|
|
const value = import.meta.env[key];
|
|
return typeof value === "string" && value.trim() ? value : undefined;
|
|
}
|
|
|
|
export function readRuntimeFlag(key: string): boolean {
|
|
return readRuntimeEnv(key) === "true";
|
|
}
|
|
|
|
/**
|
|
* Read an integer setting supplied by ``runtime-config.js``.
|
|
*
|
|
* Runtime configuration is editable after the frontend is built, so validate
|
|
* numeric values here instead of letting an invalid deployment value bypass a
|
|
* UI constraint that the backend cannot accept.
|
|
*/
|
|
export const env = {
|
|
NEXT_PUBLIC_BACKEND_BASE_URL: readRuntimeEnv("VITE_BACKEND_BASE_URL"),
|
|
NEXT_PUBLIC_LANGGRAPH_BASE_URL: readRuntimeEnv("VITE_LANGGRAPH_BASE_URL"),
|
|
// Canvas page uses its own LangGraph base URL so it can be independently
|
|
// routed (e.g. a separate canvas-agent server). Falls back to the main URL.
|
|
NEXT_PUBLIC_CANVAS_LANGGRAPH_BASE_URL: readRuntimeEnv("VITE_CANVAS_LANGGRAPH_BASE_URL"),
|
|
NEXT_PUBLIC_NOTE_API_BASE_URL: readRuntimeEnv("VITE_NOTE_API_BASE_URL"),
|
|
NEXT_PUBLIC_NOTEBOOK_API_BASE_URL: readRuntimeEnv("VITE_AIPI_BACKENP_URL"),
|
|
NEXT_PUBLIC_STATIC_WEBSITE_ONLY: readRuntimeEnv("VITE_STATIC_WEBSITE_ONLY"),
|
|
/**
|
|
* Deployment-level compact navigation mode. This is intentionally a runtime
|
|
* flag so operations can switch the shell without rebuilding the frontend.
|
|
*/
|
|
FORCE_COLLAPSED_SIDEBAR: readRuntimeFlag("VITE_FORCE_COLLAPSED_SIDEBAR"),
|
|
/**
|
|
* Development-only default entry switch for the isolated Vite-native
|
|
* official-style workspace. It never starts or embeds a Next.js app.
|
|
*/
|
|
USE_OFFICIAL_DEERFLOW_ENTRY: readRuntimeFlag(
|
|
"VITE_USE_OFFICIAL_DEERFLOW_ENTRY",
|
|
),
|
|
/**
|
|
* Compact-menu variant for this website. Pair with the admin 简介模式
|
|
* type (A / B) so two deployments can show different left-nav items.
|
|
*/
|
|
COMPACT_MENU_TYPE: readRuntimeEnv("VITE_COMPACT_MENU_TYPE"),
|
|
GITHUB_OAUTH_TOKEN: readRuntimeEnv("VITE_GITHUB_OAUTH_TOKEN"),
|
|
};
|