import{s as e}from"./home-dir-C44RaPME-B5iLWwCq.mjs";import{n as t,t as n}from"./bundled-dir-U738ay4K-BxbzrJOo.mjs";import r from"node:fs";import i from"node:path";const a=i.join(`dist`,`channel-catalog.json`);function o(){return[t({cwd:process.cwd()}),t({moduleUrl:import.meta.url})].filter((e,t,n)=>!!e&&n.indexOf(e)===t)}function s(e=process.env){let t=n(e);if(!t)return[];try{return r.readdirSync(t,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>i.join(t,e.name,`package.json`)).filter(e=>r.existsSync(e))}catch{return[]}}function c(){let e=[];for(let t of s())try{let n=JSON.parse(r.readFileSync(t,`utf8`));e.push(n)}catch{continue}return e}function l(){for(let e of o()){let t=i.join(e,a);if(r.existsSync(t))try{let e=JSON.parse(r.readFileSync(t,`utf8`));return Array.isArray(e.entries)?e.entries:[]}catch{continue}}return[]}function u(t){let n=t.openclaw?.channel,r=e(n?.id);return!r||!n?null:{id:r,channel:n,aliases:Array.isArray(n.aliases)?n.aliases.map(t=>e(t)).filter(e=>!!e):[],order:typeof n.order==`number`&&Number.isFinite(n.order)?n.order:2**53-1}}function d(){let e=c().map(e=>u(e)).filter(e=>!!e);return e.length>0?e:l().map(e=>u(e)).filter(e=>!!e)}function f(){return d().map(t=>({id:e(t.id)??t.id,aliases:t.aliases,order:t.order})).toSorted((e,t)=>e.order-t.order||e.id.localeCompare(t.id,`en`,{sensitivity:`base`}))}const p=Object.freeze(f()),m=new Set(p.map(e=>e.id)),h=Object.freeze(p.map(e=>e.id)),g=h,_=Object.freeze(Object.fromEntries(p.flatMap(e=>e.aliases.map(t=>[t,e.id]))));function v(t){let n=e(t);if(!n)return null;let r=_[n]??n;return m.has(r)?r:null}export{v as i,h as n,d as r,g as t};