Reachable GETs baseURL/v1/models with ctx as deadline; any HTTP response (even 401/404) counts as reachable, only transport errors/timeouts don't. Backs the TUI connectivity probe for keyless (local) profiles. v1/models is the route-registered OpenAI heartbeat every keyless backend serves (Ollama,
(ctx context.Context, baseURL string)
| 28 | // Drain the body before close so the TCP connection returns to the pool; |
| 29 | // closing undrained leaks it in keep-alive setups. |
| 30 | func Reachable(ctx context.Context, baseURL string) error { |
| 31 | req, err := http.NewRequestWithContext(ctx, "GET", baseURL+"/v1/models", nil) |
| 32 | if err != nil { |
| 33 | return err |
| 34 | } |
| 35 | resp, err := http.DefaultClient.Do(req) |
| 36 | if err != nil { |
| 37 | return err |
| 38 | } |
| 39 | _, _ = io.Copy(io.Discard, resp.Body) |
| 40 | _ = resp.Body.Close() |
| 41 | return nil |
| 42 | } |
| 43 | |
| 44 | // Headers the proxy sets on every 200. Remaining is the pass fraction |
| 45 | // [0.0,1.0]; CtxWindow is the live context window, authoritative over config.yaml. |
no outgoing calls