grix-connector
Version:
Connect local AI coding agents (Claude, Codex, Gemini, Qwen, DeepSeek, Cursor, OpenCode, Pi, OpenHuman, Reasonix) to the Grix scheduling platform. Also serves as an OpenClaw plugin for Grix channel transport.
2 lines (1 loc) • 1.23 kB
JavaScript
import{request as b}from"node:http";import{request as p}from"node:https";import{log as f}from"../log/logger.js";const i=5e3,m="/";async function h(o,t=i){return new Promise((n,a)=>{const r=Date.now(),e=new URL(o),l={hostname:e.hostname,port:e.port||(e.protocol==="https:"?443:80),path:m,method:"HEAD",timeout:t,headers:{"User-Agent":"grix-connector/installer",Accept:"*/*"}},s=e.protocol==="https:"?p(l):b(l);s.on("response",c=>{const u=Date.now()-r;c.resume(),n(u)}),s.on("error",c=>{a(c)}),s.on("timeout",()=>{s.destroy(),a(new Error(`TTFB probe timed out after ${t}ms`))}),s.end()})}async function T(o,t=i){const n=await Promise.all(o.map(async r=>{try{const e=await h(r.url,t);return{url:r.url,label:r.label,ttfbMs:e,reachable:!0}}catch(e){const l=e instanceof Error?e.message:String(e);return{url:r.url,label:r.label,ttfbMs:null,reachable:!1,error:l}}}));n.sort((r,e)=>r.reachable&&e.reachable?(r.ttfbMs??1/0)-(e.ttfbMs??1/0):r.reachable?-1:e.reachable?1:0);const a=n.map(r=>`${r.label}: ${r.reachable?`${r.ttfbMs}ms`:`unreachable (${r.error?.slice(0,50)})`}`).join(", ");return f.info("installer",`Speed probe: ${a}`),n}function E(o){return o.find(t=>t.reachable)??null}export{E as pickFastest,h as probeTtfb,T as probeUrls};