import { spawn } from 'node:child_process'; import path from 'node:path'; import { verifyInstall } from './settings.mjs'; import { refuse } from './common.mjs'; // In-process seams let the no-binary gate verify failure handling and signal forwarding. // The unit entry point supplies no seams and always uses PIN verification. export function startVerifiedProxy(config, { verify = verifyInstall, spawnImpl = spawn, env = process.env, onError = () => {}, onExit = () => {} } = {}) { if (!config.proxy) refuse('proxy-not-configured'); const install = verify(config.dataRoot); let child; try { child = spawnImpl(install.binary, ['-config', path.join(config.dataRoot, 'proxy/config.yaml'), '-local-model'], { cwd: path.join(config.dataRoot, 'proxy'), stdio: 'inherit', env: { HOME: env.HOME, PATH: '/usr/bin:/bin', MANAGEMENT_STATIC_PATH: path.dirname(install.panel) }, }); } catch { refuse('proxy-start-failed'); } child.once('error', () => onError('proxy-start-failed')); child.once('exit', (code, signal) => onExit(signal ? 1 : (code ?? 1))); return child; }