@monitoro/herd
Version:
Automate your browser, build AI web tools and MCP servers with Monitoro Herd
29 lines (28 loc) • 993 B
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.log('🔑 No authentication found. Please run `herd login` to authenticate with Herd.');
return;
}
process.env.HERD_API_KEY = fs.readFileSync(herdrcPath, 'utf8').trim();
}
function getHerdClient() {
if (!process.env.HERD_API_KEY) {
throw new Error('🔑 Authentication required. Please run `herd login` to authenticate with Herd.');
}
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 };