feat(cliproxy): add --json flag to catalog command

Add machine-readable JSON output for `ccs cliproxy catalog --json`
to enable programmatic access to available models per provider.

Output format: { "provider": [{ "id": "...", "name": "..." }, ...] }

Closes CCS-1

Built [OnSteroids](https://onsteroids.ai)
This commit is contained in:
Sergey Galuza
2026-04-11 17:52:25 +02:00
parent 6038843d9d
commit 92d76cad89
2 changed files with 20 additions and 0 deletions
@@ -5,6 +5,7 @@ import {
SYNCABLE_PROVIDERS,
getResolvedCatalog,
refreshCatalogFromProxy,
getAllResolvedCatalogs,
} from '../../cliproxy/catalog-cache';
import { getCatalogRoutingSnapshot } from '../../cliproxy/catalog-routing';
import { ensureManagedModelPrefixes } from '../../cliproxy/managed-model-prefixes';
@@ -173,6 +174,20 @@ export async function handleCatalogRefresh(verbose: boolean): Promise<void> {
console.log('');
}
/**
* Output catalog as JSON for programmatic consumption.
* Used by OnSteroids and other tools to get available models per provider.
* Format: { provider: [{ id, name }], ... }
*/
export function handleCatalogJson(): void {
const catalogs = getAllResolvedCatalogs();
const result: Record<string, Array<{ id: string; name: string }>> = {};
for (const [provider, catalog] of Object.entries(catalogs)) {
result[provider] = catalog.models.map((m) => ({ id: m.id, name: m.name }));
}
console.log(JSON.stringify(result));
}
/** Reset catalog cache */
export async function handleCatalogReset(): Promise<void> {
await initUI();
+5
View File
@@ -40,6 +40,7 @@ import {
handleCatalogStatus,
handleCatalogRefresh,
handleCatalogReset,
handleCatalogJson,
} from './catalog-subcommand';
/**
@@ -146,6 +147,10 @@ export async function handleCliproxyCommand(args: string[]): Promise<void> {
// Catalog commands
if (command === 'catalog') {
if (hasAnyFlag(remainingArgs, ['--json'])) {
handleCatalogJson();
return;
}
const subcommand = remainingArgs[1];
if (subcommand === 'refresh') {
await handleCatalogRefresh(verbose);