import*as p from"workerpool";import{withPathPrefix as l}from"@redocly/theme/core/utils";import{TimeoutExceededError as f}from"../../../api-routes/errors/timeout-exceeded.js";import{logger as m}from"../../../tools/notifiers/logger.js";import{serializeRequest as S}from"../../../api-routes/helpers/serialize-request.js";import{API_ROUTES_WORKER_KEY as g}from"../../../workers/api-routes-worker-pool.js";import{mcpWorkers as h}from"../../../workers/mcp-worker-pool.js";const w=10;async function D(o,a,e){const t=a.get("auth"),i=await e.resolveRouteStaticData(o)||{},s=l(o.slug);try{const{status:r,headers:n,body:c,loggerStickyState:u}=await h.exec(g,[{serverOutDir:e.serverOutDir,slug:s,requestHandlerId:o.requestHandlerId,maxResponseSizeMB:w,ctxData:{user:{teams:t.teams,email:t.claims.email,claims:t.claims,idpAccessToken:t.idpAccessToken,idpId:t.claims.idpId,isAuthenticated:t.isAuthenticated},config:e.config},staticData:{...i,props:{...i.props,routeSlug:s,outdir:e.outdir}},req:await S(a.req.raw),loggerStickyState:m.getStickyState()}]);m.setStickyState(u);const d=c.data?Buffer.from(c.data):null;return new Response(d,{status:r,headers:n})}catch(r){throw r instanceof p.Promise.TimeoutError?new f("Timeout exceeded"):r}}export{D as runMcpWorker};
