eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.35 kB
JavaScript
import{CONNECTION_CATALOG}from"#setup/scaffold/index.js";async function probeMcpConnection(e){try{let t=await fetch(e.url,{method:`POST`,signal:e.signal,headers:{Accept:`application/json, text/event-stream`,"Content-Type":`application/json`,"MCP-Protocol-Version":`2025-03-26`},body:JSON.stringify({jsonrpc:`2.0`,id:`eve-connection-probe`,method:`initialize`,params:{protocolVersion:`2025-03-26`,capabilities:{},clientInfo:{name:`eve`,version:`connection-probe`}}})});return t.ok||t.status===401||t.status===403?void 0:`${e.url} is not reachable (HTTP ${t.status}).`}catch(t){if(e.signal.aborted)throw t;let n=t instanceof Error?t.message:`connection failed`;return`${e.url} is not reachable (${n}).`}}function createMcpConnectionStatusTracker(t){let n=t.probe??probeMcpConnection,r=t.intervalMs??6e4,i={},a=!1,o=0,s,c=setInterval(()=>refresh(),r);c.unref();let refresh=()=>{if(a)return;s?.abort(),s=new AbortController;let r=s,c=++o;Promise.all(CONNECTION_CATALOG.flatMap(e=>{let t=e.mcp?.url;return t===void 0?[]:[n({url:t,signal:r.signal}).then(t=>[e.slug,t])]})).then(e=>{a||c!==o||(i=Object.fromEntries(e.flatMap(([e,t])=>t===void 0?[]:[[e,t]])),t.onChange(i))}).catch(()=>{r.signal.aborted})};return{current:()=>i,refresh,dispose:()=>{a||(a=!0,o+=1,s?.abort(),s=void 0,clearInterval(c))}}}export{createMcpConnectionStatusTracker,probeMcpConnection};