const d="manifest.json",h={config:0,skill:1,cron:2,dockerfile:3,other:4};function g(t,e,n){return{key:t,name:e,type:"folder",children:[],resourceType:n}}function k(t){return[...t].sort((e,n)=>e.type!==n.type?e.type==="folder"?-1:1:e.name.localeCompare(n.name)).map(e=>e.type==="folder"&&e.children?{...e,children:k(e.children)}:e)}function y(t,e,n){const o=e.split("/").filter(Boolean);let i=t,c="";for(const l of o){c=c?`${c}/${l}`:l;const f=`${n}/${c}/`;let r=i.children?.find(s=>s.type==="folder"&&s.key===f);r||(r=g(f,l,n),i.children.push(r)),i=r}return i}function F(t,e,n=[]){const o=[],i=new Set;o.push({key:d,name:d,type:"file"});const c=new Map,l=r=>{let s=c.get(r);return s||(s=g(`${r}/`,`${r}/`,r),c.set(r,s)),s};for(const r of n){const s=r.replace(/^\/+|\/+$/g,"");if(!s)continue;const[a,...u]=s.split("/");if(a){if(u.length===0){l(a),i.add(a);continue}y(l(a),u.join("/"),a)}}for(const r of Object.values(t)){const s=r.type||"other",a=l(s),u=r.name.split("/").filter(Boolean),p=u.pop();if(!p)continue;(u.length>0?y(a,u.join("/"),s):a).children.push({key:`${s}/${r.name}`,name:p,type:"file",resourceType:s})}const f=[...c.keys()].sort((r,s)=>(h[r]??99)-(h[s]??99));for(const r of f){const s=c.get(r);((s.children?.length??0)>0||i.has(r))&&o.push({...s,children:k(s.children)})}return o}function A(t){if(t==="Dockerfile"||t.endsWith("/Dockerfile"))return"dockerfile";const e=t.lastIndexOf(".");if(e===-1)return"plaintext";switch(t.slice(e).toLowerCase()){case".json":return"json";case".md":return"markdown";case".js":return"javascript";case".ts":return"typescript";case".yaml":case".yml":return"yaml";case".xml":return"xml";case".html":return"html";case".css":return"css";case".sh":return"shell";default:return"plaintext"}}function j(t){return t.replace(/\\/g,"/").split("/").map(e=>e.trim()).filter(Boolean).join("/")}function w(t,e,n,o="other"){const i=j(e);if(t!==n){const r=`${t}/`;return{resourceType:t,relativePath:i.startsWith(r)?i.slice(r.length):i}}const c=i.split("/").filter(Boolean);if(c.length===1)return{resourceType:o,relativePath:c[0]};const[l,...f]=c;return{resourceType:l||"",relativePath:f.join("/")}}function $(t){const e=j(t).split("/").filter(Boolean),n=[];for(let o=1;o<e.length;o+=1)n.push(e.slice(0,o).join("/"));return n}function m(t){return typeof t=="string"?t.trim():""}function D(t){try{const e=JSON.parse(t);if(!e||typeof e!="object"||Array.isArray(e))return"";const n=m(e.description);if(n)return n;const o=e.worker;if(o&&typeof o=="object"&&!Array.isArray(o))return m(o.description)}catch{}return""}function b(t,e){const n=e.trim();try{const o=JSON.parse(t);if(!o||typeof o!="object"||Array.isArray(o))return t;const i={...o};n?i.description=n:delete i.description;const c=i.worker;if(c&&typeof c=="object"&&!Array.isArray(c)){const l={...c};n?l.description=n:delete l.description,i.worker=l}return JSON.stringify(i,null,2)}catch{return t}}export{A as a,F as b,$ as c,D as g,j as n,w as r,b as s};
