openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 855 B
JavaScript
import{s as normalizeNullableString}from"./string-coerce-CpTFcSwY.mjs";import{n as runExec}from"./exec-c5tqm8tb.mjs";import os from"node:os";
//!src/infra/machine-name.ts
let cachedPromise=null;async function tryScutil(e){try{const{stdout:t}=await runExec(`/usr/sbin/scutil`,[`--get`,e],{logOutput:false,timeoutMs:1e3});return normalizeNullableString(t)}catch{return null}}function fallbackHostName(){return(normalizeNullableString(os.hostname())??``).replace(/\.local$/i,``)||`openclaw`}async function getMachineDisplayName(){if(cachedPromise)return cachedPromise;cachedPromise=(async()=>{if(process.env.VITEST||false)return fallbackHostName();if(process.platform===`darwin`)return await tryScutil(`ComputerName`)??await tryScutil(`LocalHostName`)??fallbackHostName();return fallbackHostName()})();return cachedPromise}export{getMachineDisplayName as t};