import e from"node:os";import{promisify as t}from"node:util";import{execFile as n}from"node:child_process";const r=t(n);let i=null;async function a(e){try{let{stdout:t}=await r(`/usr/sbin/scutil`,[`--get`,e],{timeout:1e3,windowsHide:!0}),n=String(t??``).trim();return n.length>0?n:null}catch{return null}}function o(){return e.hostname().replace(/\.local$/i,``).trim()||`openclaw`}async function s(){return i||(i=(async()=>{if(process.env.VITEST)return o();if(process.platform===`darwin`){let e=await a(`ComputerName`);if(e)return e;let t=await a(`LocalHostName`);if(t)return t}return o()})(),i)}async function c(e,t,n){let r=typeof t==`number`&&Number.isFinite(t)?Math.max(1,Math.floor(t)):void 0;if(!r)return await e(void 0);let i=new AbortController,a=Error(`${n??`request`} timed out`),o=setTimeout(()=>i.abort(a),r);o.unref?.();let s,c=i.signal.aborted?Promise.reject(i.signal.reason??a):new Promise((e,t)=>{s=()=>t(i.signal.reason??a),i.signal.addEventListener(`abort`,s,{once:!0})});try{return await Promise.race([e(i.signal),c])}finally{clearTimeout(o),s&&i.signal.removeEventListener(`abort`,s)}}export{s as n,c as t};
