(url: string, password?: string | null)
| 182 | } |
| 183 | |
| 184 | export async function checkHealth(url: string, password?: string | null): Promise<boolean> { |
| 185 | let healthUrl: URL |
| 186 | try { |
| 187 | healthUrl = new URL("/global/health", url) |
| 188 | } catch { |
| 189 | return false |
| 190 | } |
| 191 | |
| 192 | const headers = new Headers() |
| 193 | if (password) { |
| 194 | const auth = Buffer.from(`opencode:${password}`).toString("base64") |
| 195 | headers.set("authorization", `Basic ${auth}`) |
| 196 | } |
| 197 | |
| 198 | try { |
| 199 | const res = await fetch(healthUrl, { |
| 200 | method: "GET", |
| 201 | headers, |
| 202 | signal: AbortSignal.timeout(3000), |
| 203 | }) |
| 204 | return res.ok |
| 205 | } catch { |
| 206 | return false |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | function createSidecarEnv(): Record<string, string> { |
| 211 | const env = Object.fromEntries( |
no test coverage detected