@monitoro/herd
Version:
Automate your browser, build AI web tools and MCP servers with Monitoro Herd
31 lines (30 loc) • 1.04 kB
JavaScript
// load config from .herdrc
import fs from 'fs';
import path from 'path';
import { homedir } from 'os';
import { HerdClient } from '../src/lib/HerdClient.js';
let clientCache = {};
function initConfig() {
const herdrcPath = path.join(homedir(), '.herdrc');
if (!fs.existsSync(herdrcPath)) {
// console.error('Error: No .herdrc file found, please login first.');
// process.exit(1);
console.log('No .herdrc file found, please login.');
return;
}
process.env.HERD_API_KEY = fs.readFileSync(herdrcPath, 'utf8').trim();
}
function getHerdClient() {
if (!process.env.HERD_API_KEY) {
throw new Error('Error: No HERD_API_KEY found, please run `herd login` first.');
}
if (clientCache[process.env.HERD_API_KEY]) {
return clientCache[process.env.HERD_API_KEY];
}
const client = new HerdClient({
token: process.env.HERD_API_KEY,
});
clientCache = { [process.env.HERD_API_KEY]: client };
return client;
}
export { initConfig, getHerdClient };