46 lines
1.8 KiB
TypeScript
46 lines
1.8 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"),
|
|
GITHUB_OAUTH_TOKEN: readRuntimeEnv("VITE_GITHUB_OAUTH_TOKEN"),
|
|
};
|