import u from"node:fs";import y from"node:path";import{checkEndpointAndDeleteXMcp as x}from"../../utils/xmcp-utils.js";import{MAX_DOCUMENTS_PER_CATEGORY as O}from"../../constants.js";function E(s){const{paths:c={}}=s,a=[];for(const[l,n]of Object.entries(c)){const f=!x(n,"docs");for(const[m,t]of Object.entries(n))f||!x(t,"docs")||a.push({path:l,method:m.toUpperCase(),summary:t.summary,description:t.description,security:t.security})}return a}function k(s,c){return Object.entries(s).map(([l,n])=>{if(!n||n.length===0)return"";const f=n.slice(0,O).map(m=>{const{document:t,highlight:p}=m,g=p?.title||(Array.isArray(t.title)?t.title[0]:t.title);let r=`Document: ${t.title}`;r+=`### [${g}](${t.url})

`;let i;if(t.url)try{let e=t.url.startsWith("/")?t.url.slice(1):t.url;const o=e.indexOf("#");o!==-1&&(e=e.substring(0,o));const d=y.extname(e);d&&(e=e.slice(0,-d.length));let A=e+".md";const h=y.join(c,A);u.existsSync(h)&&(i=u.readFileSync(h,"utf8"))}catch{}return i||(i=p?.text||(Array.isArray(t.text)?t.text[0]:t.text)),r+=i,t.facets&&(r+=`

**Categories:**
`,Object.entries(t.facets).forEach(([e,o])=>{r+=`- ${e}: ${o}
`})),r});return`## ${l}

${f}`}).join(`

`).trim()}export{E as getEndpointsFromPaths,k as processDocuments};
