feat(cli): add --model/--provider flags and /model /provider TUI commands (#144)
All checks were successful
ci/woodpecker/push/ci Pipeline was successful

Co-authored-by: Jason Woltje <jason@diversecanvas.com>
Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #144.
This commit is contained in:
2026-03-15 18:41:36 +00:00
committed by jason.woltje
parent 3bb401641e
commit 6a4c020179
3 changed files with 336 additions and 48 deletions

View File

@@ -0,0 +1,62 @@
/**
* Minimal gateway REST API client for the TUI.
*/
export interface ModelInfo {
id: string;
provider: string;
name: string;
}
export interface ProviderInfo {
id: string;
name: string;
available: boolean;
models: ModelInfo[];
}
/**
* Fetch the list of available models from the gateway.
* Returns an empty array on network or auth errors so the TUI can still function.
*/
export async function fetchAvailableModels(
gatewayUrl: string,
sessionCookie?: string,
): Promise<ModelInfo[]> {
try {
const res = await fetch(`${gatewayUrl}/api/providers/models`, {
headers: {
...(sessionCookie ? { Cookie: sessionCookie } : {}),
Origin: gatewayUrl,
},
});
if (!res.ok) return [];
const data = (await res.json()) as ModelInfo[];
return Array.isArray(data) ? data : [];
} catch {
return [];
}
}
/**
* Fetch the list of providers (with their models) from the gateway.
* Returns an empty array on network or auth errors.
*/
export async function fetchProviders(
gatewayUrl: string,
sessionCookie?: string,
): Promise<ProviderInfo[]> {
try {
const res = await fetch(`${gatewayUrl}/api/providers`, {
headers: {
...(sessionCookie ? { Cookie: sessionCookie } : {}),
Origin: gatewayUrl,
},
});
if (!res.ok) return [];
const data = (await res.json()) as ProviderInfo[];
return Array.isArray(data) ? data : [];
} catch {
return [];
}
}