import { homedir } from 'os'; import { PrismaClient } from '@prisma/client'; import { HostConfig } from './types'; const prisma = new PrismaClient(); export async function getHostConfigs(): Promise { try { const dbConfigs = await prisma.hostConfig.findMany(); return dbConfigs.map(h => ({ name: h.name, ip: h.ip, sshUser: h.sshUser || 'bear', sshKeyPath: h.sshKeyPath?.replace(/^~/, homedir()), sshPort: h.sshPort || 22, hostType: h.hostType, })); } catch (error) { console.error('Error fetching host configs from DB:', error); return []; } } export async function hasConfig(): Promise { try { const count = await prisma.hostConfig.count(); return count > 0; } catch (error) { return false; } }