forked from mosaicstack/stack
feat(cli): add --model/--provider flags and /model /provider TUI commands (#144)
Co-authored-by: Jason Woltje <[email protected]> Co-committed-by: Jason Woltje <[email protected]>
This commit is contained in:
@@ -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 [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user