import{withPathPrefix as p}from"@redocly/theme/core/utils";import{SEMANTIC_SEARCH_API_URL as r}from"../../constants/common.js";function l(u){return async e=>{if(!r)return e.newResponse(null,404);const n=e.get("auth"),o={"Content-Type":"application/json"};n.idpAccessToken&&(o.Cookie=`accessToken=${n.idpAccessToken}`);const a=await e.req.json();try{const t=await fetch(r,{method:"POST",body:JSON.stringify(a),headers:o});if(t.ok){const c=(await t.json()).documents.map(s=>({...s,url:p(s.url)}));return e.json(c)}const i=await t.text();return e.newResponse(i,t.status,{"Content-Type":"application/json"})}catch(t){return e.json({error:"Failed to fetch semantic search results",details:String(t)},500)}}}export{l as semanticSearchHandler};
