| 165 | } |
| 166 | |
| 167 | async function listRouters( |
| 168 | bearer: string, |
| 169 | ): Promise<{ ok: true; routers: RouterEntry[] } | { ok: false; status: number }> { |
| 170 | const res = await fetch(`${DO_GENAI_API}/models/routers`, { |
| 171 | headers: { |
| 172 | Authorization: `Bearer ${bearer}`, |
| 173 | Accept: "application/json", |
| 174 | "User-Agent": `opencode/${InstallationVersion}`, |
| 175 | }, |
| 176 | signal: AbortSignal.timeout(10_000), |
| 177 | }).catch(() => undefined) |
| 178 | if (!res) return { ok: false, status: 0 } |
| 179 | if (!res.ok) return { ok: false, status: res.status } |
| 180 | const body = (await res.json().catch(() => undefined)) as { model_routers?: RouterEntry[] } | undefined |
| 181 | return { ok: true, routers: body?.model_routers ?? [] } |
| 182 | } |
| 183 | |
| 184 | function routerModel(router: RouterEntry, providerID: string): Model { |
| 185 | const id = `router:${router.name}` |