mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 08:17:11 +00:00
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:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user