Something went wrong. Try again.
Local build agent for Nodrix — compiles sketches with your own Arduino toolchain so the browser can flash them. Dials out over WebSocket; n…
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344import { homedir } from 'node:os';import { join } from 'node:path';import { readFileSync } from 'node:fs';
export type Config = { instance: string; token: string; sketchbook: string | null;};
const CONFIG_PATH = join(homedir(), '.nodrix', 'agent.json');
// Env wins so a one-off run doesn't need a config file, and CI can set it.export function loadConfig(): Config { let file: Partial<Config> = {}; try { file = JSON.parse(readFileSync(CONFIG_PATH, 'utf8')) as Partial<Config>; } catch { /* no config file — env only */ }
const instance = process.env['NODRIX_INSTANCE'] ?? file.instance ?? ''; const token = process.env['NODRIX_TOKEN'] ?? file.token ?? ''; if (!instance || !token) { throw new Error( `Set NODRIX_INSTANCE and NODRIX_TOKEN, or write them to ${CONFIG_PATH}.` ); } return { instance: instance.replace(/\/+$/, ''), token, sketchbook: process.env['NODRIX_SKETCHBOOK'] ?? file.sketchbook ?? null, };}
export function socketUrl(instance: string): string { const url = new URL(instance); url.protocol = url.protocol === 'http:' ? 'ws:' : 'wss:'; url.pathname = '/v1/agent/ws'; return url.toString();}
export function artifactUrl(instance: string, buildId: string): string { return `${instance}/v1/agent/artifact/${buildId}`;}