MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / probeProvider

Function probeProvider

src/setup/provider-test.ts:19–35  ·  view source on GitHub ↗
(opts: { baseUrl: string; keyEnv?: string; timeoutMs?: number })

Source from the content-addressed store, hash-verified

17/** Probe a provider's `/models`. Reads the API key from `keyEnv` (the env var name, not the
18 * secret). Returns a friendly result; never throws. */
19export async function probeProvider(opts: { baseUrl: string; keyEnv?: string; timeoutMs?: number }): Promise<ProbeResult> {
20 if (!opts.baseUrl) return { ok: false, detail: 'no base URL' };
21 const key = opts.keyEnv ? process.env[opts.keyEnv] : undefined;
22 if (opts.keyEnv && !key) return { ok: false, detail: `${opts.keyEnv} is not set — add it to ~/.qodex/.env` };
23 try {
24 const res = await fetch(buildModelsUrl(opts.baseUrl), {
25 headers: key ? { authorization: `Bearer ${key}` } : {},
26 signal: AbortSignal.timeout(opts.timeoutMs ?? 6000),
27 });
28 if (!res.ok) return { ok: false, detail: `HTTP ${res.status}${res.status === 401 ? ' — bad/expired key' : ''}` };
29 const j: any = await res.json().catch(() => null);
30 const n = Array.isArray(j?.data) ? j.data.length : (Array.isArray(j?.models) ? j.models.length : undefined);
31 return { ok: true, detail: n != null ? `reachable — ${n} model(s)` : 'reachable' };
32 } catch (e: any) {
33 return { ok: false, detail: e?.name === 'TimeoutError' ? 'timed out — endpoint unreachable' : (e?.message ?? 'unreachable') };
34 }
35}

Callers 2

dispatchActionFunction · 0.85

Calls 1

buildModelsUrlFunction · 0.85

Tested by

no test coverage detected