Spaces:
Sleeping
Sleeping
| import { randomUUID } from 'crypto'; | |
| import { APP_CONFIG } from '../config/constants'; | |
| /** | |
| * Generates a unique ID with a prefix | |
| * Uses crypto.randomUUID() for guaranteed uniqueness | |
| * Server-side only (Node.js crypto module) | |
| */ | |
| export function generateId(prefix: keyof typeof APP_CONFIG.idPrefixes): string { | |
| const prefixStr = APP_CONFIG.idPrefixes[prefix]; | |
| const uuid = randomUUID(); | |
| return `${prefixStr}-${uuid.slice(0, 8)}`; | |
| } | |
| /** | |
| * Validates environment variables at startup | |
| * Server-side only (process.env) | |
| */ | |
| export function validateEnv(): { missing: string[]; warnings: string[] } { | |
| const missing: string[] = []; | |
| const warnings: string[] = []; | |
| if (!process.env.OPENROUTER_API_KEY && (!process.env.GEMINI_API_KEY || process.env.GEMINI_API_KEY === 'MY_GEMINI_API_KEY')) { | |
| warnings.push('No AI provider configured (OPENROUTER_API_KEY or GEMINI_API_KEY) β chat will use offline fallback'); | |
| } | |
| if (!process.env.BETTER_AUTH_SECRET) { | |
| missing.push('BETTER_AUTH_SECRET'); | |
| } | |
| if (!process.env.APP_URL) { | |
| warnings.push('APP_URL not configured β using http://localhost:3000'); | |
| } | |
| if (!process.env.GITHUB_CLIENT_ID || !process.env.GITHUB_CLIENT_SECRET) { | |
| warnings.push('GitHub OAuth credentials not configured β GitHub login will fail'); | |
| } | |
| if (!process.env.GOOGLE_CLIENT_ID || !process.env.GOOGLE_CLIENT_SECRET) { | |
| warnings.push('Google OAuth credentials not configured β Google login will fail'); | |
| } | |
| return { missing, warnings }; | |
| } |