Spaces:
Runtime error
Runtime error
| export type RuntimeInfo = { | |
| target: "huggingface-space" | "local"; | |
| provider: string; | |
| stage: string; | |
| label: string; | |
| proEnabled: boolean; | |
| spaceId: string | null; | |
| hardware: string | null; | |
| storage: string | null; | |
| sleepTimeMinutes: number | null; | |
| devMode: boolean; | |
| }; | |
| function readEnv(...keys: string[]): string | null { | |
| for (const key of keys) { | |
| const value = process.env[key]; | |
| if (value && value.trim().length > 0) { | |
| return value.trim(); | |
| } | |
| } | |
| return null; | |
| } | |
| function parseOptionalInt(value: string | null): number | null { | |
| if (!value) { | |
| return null; | |
| } | |
| const parsed = Number.parseInt(value, 10); | |
| return Number.isFinite(parsed) ? parsed : null; | |
| } | |
| export function resolveRuntimeInfo(): RuntimeInfo { | |
| const targetEnv = readEnv("RUNTIME_TARGET", "NEXT_PUBLIC_RUNTIME_TARGET"); | |
| const spaceId = readEnv("SPACE_ID", "HF_SPACE_REPO_ID", "NEXT_PUBLIC_HF_SPACE_ID"); | |
| const stage = readEnv("SPACE_STAGE", "NEXT_PUBLIC_SPACE_STAGE") ?? "LOCAL"; | |
| const hardware = readEnv("SPACE_HARDWARE", "NEXT_PUBLIC_HF_HARDWARE"); | |
| const storage = readEnv("SPACE_STORAGE", "NEXT_PUBLIC_HF_STORAGE"); | |
| const sleepTime = parseOptionalInt( | |
| readEnv("SPACE_SLEEP_TIME", "NEXT_PUBLIC_HF_SLEEP_TIME"), | |
| ); | |
| const provider = | |
| readEnv("SPACE_PROVIDER", "NEXT_PUBLIC_SPACE_PROVIDER") ?? | |
| (spaceId || targetEnv === "huggingface" | |
| ? "Hugging Face Spaces" | |
| : "Local workspace"); | |
| const target = | |
| targetEnv === "huggingface" || spaceId ? "huggingface-space" : "local"; | |
| return { | |
| target, | |
| provider, | |
| stage, | |
| label: target === "huggingface-space" ? "Space ativo" : "Execucao local", | |
| proEnabled: readEnv("HF_PRO_ENABLED", "NEXT_PUBLIC_HF_PRO_ENABLED") === "true", | |
| spaceId, | |
| hardware, | |
| storage, | |
| sleepTimeMinutes: sleepTime, | |
| devMode: readEnv("HF_DEV_MODE", "NEXT_PUBLIC_HF_DEV_MODE") === "true", | |
| }; | |
| } | |