listen.ts (644B)
1 import log from "./log.ts"; 2 3 export default async (): Promise<void> => { 4 const opencodeBaseUrl = process.env.OPENCODE_BASE_URL; 5 6 if (!opencodeBaseUrl) { 7 log("ERROR", "No opencode base url"); 8 9 process.exit(1); 10 } 11 12 log("INFO", "Probing opencode", { opencodeBaseUrl }); 13 14 try { 15 const response = await fetch(`${opencodeBaseUrl}/global/health`); 16 17 const body = await response.json(); 18 19 if (!body.healthy) { 20 log("ERROR", "Opencode not healthy"); 21 22 process.exit(1); 23 } 24 } catch (error) { 25 log("ERROR", "Could not probe opencode", { error }); 26 27 process.exit(1); 28 } 29 30 log("INFO", "Server listening"); 31 };