import{REDOCLY_TEAMS_RBAC as l}from"@redocly/config";import{DEFAULT_SEARCH_ENGINE as s}from"../../constants/plugins/search.js";import{isDevelopMode as m}from"../../utils/envs/is-develop-mode.js";import{logger as p}from"../../tools/notifiers/logger.js";import{prepareSearchDocuments as g}from"./documents/search-documents.js";import{SearchEngine as E}from"./engines/search-engine.js";import{prepareAiSearchDocuments as d}from"./ai-indexer/prepare-ai-search-documents.js";import{isAiSearchEnabled as S}from"./utils.js";import{telemetryTraceStep as u}from"../../../cli/telemetry/helpers/trace-step.js";async function F(){let e=!0;return{async afterRoutesCreated(a,i){(process.env.SEARCH_DEV_REINIT||e)&&await b(a,i),e=!1},id:"search"}}async function b(e,a){await u("build.plugin.search",async i=>{const r=e.getConfig();if(i?.setAttribute("config",JSON.stringify(r.search||{})),r.search?.hide){p.info("Search is disabled in the config, skipping");return}const c=r.search?.engine||s,o=m()?process.env.SEARCH_DEV_DEBUG?c:s:c,{l10n:f}=e.getGlobalData(),h=S(r),t=r.rbac?.features?.aiSearch,n=new E(o,f);await n.initIndexSchema(e.getSearchFacets()),e.setSearchEngine(n),e.setGlobalData({searchFeatures:{advanced:{enabled:o!==s&&!r.search?.filters?.hide},ai:{enabled:h,[l]:t&&Object.keys(t).length?t:void 0}}}),await g(a.fs,e,n),await d(e,a,{aiSearchEnabled:h,llmstxtEnabled:r.seo?.llmstxt?.hide!==!0})})}export{F as searchPlugin};
