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(e){let t=e.probe??probeMcpConnection,n=e.intervalMs??6e4,r={},i=!1,a=0,o,s=setInterval(()=>refresh(),n);s.unref();let refresh=()=>{if(i)return;o?.abort(),o=new AbortController;let n=o,s=++a;Promise.all(CONNECTION_CATALOG.flatMap(e=>{let r=e.mcp?.url;return r===void 0?[]:[t({url:r,signal:n.signal}).then(t=>[e.slug,t])]})).then(t=>{i||s!==a||(r=Object.fromEntries(t.flatMap(([e,t])=>t===void 0?[]:[[e,t]])),e.onChange(r))}).catch(()=>{n.signal.aborted})};return{current:()=>r,refresh,dispose:()=>{i||(i=!0,a+=1,o?.abort(),o=void 0,clearInterval(s))}}}export{createMcpConnectionStatusTracker,probeMcpConnection};