mirror of
https://github.com/tiennm99/ccs.git
synced 2026-08-08 10:21: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,
|
SYNCABLE_PROVIDERS,
|
||||||
getResolvedCatalog,
|
getResolvedCatalog,
|
||||||
refreshCatalogFromProxy,
|
refreshCatalogFromProxy,
|
||||||
|
getAllResolvedCatalogs,
|
||||||
} from '../../cliproxy/catalog-cache';
|
} from '../../cliproxy/catalog-cache';
|
||||||
import { getCatalogRoutingSnapshot } from '../../cliproxy/catalog-routing';
|
import { getCatalogRoutingSnapshot } from '../../cliproxy/catalog-routing';
|
||||||
import { ensureManagedModelPrefixes } from '../../cliproxy/managed-model-prefixes';
|
import { ensureManagedModelPrefixes } from '../../cliproxy/managed-model-prefixes';
|
||||||
@@ -173,6 +174,20 @@ export async function handleCatalogRefresh(verbose: boolean): Promise<void> {
|
|||||||
console.log('');
|
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 */
|
/** Reset catalog cache */
|
||||||
export async function handleCatalogReset(): Promise<void> {
|
export async function handleCatalogReset(): Promise<void> {
|
||||||
await initUI();
|
await initUI();
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import {
|
|||||||
handleCatalogStatus,
|
handleCatalogStatus,
|
||||||
handleCatalogRefresh,
|
handleCatalogRefresh,
|
||||||
handleCatalogReset,
|
handleCatalogReset,
|
||||||
|
handleCatalogJson,
|
||||||
} from './catalog-subcommand';
|
} from './catalog-subcommand';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,6 +147,10 @@ export async function handleCliproxyCommand(args: string[]): Promise<void> {
|
|||||||
|
|
||||||
// Catalog commands
|
// Catalog commands
|
||||||
if (command === 'catalog') {
|
if (command === 'catalog') {
|
||||||
|
if (hasAnyFlag(remainingArgs, ['--json'])) {
|
||||||
|
handleCatalogJson();
|
||||||
|
return;
|
||||||
|
}
|
||||||
const subcommand = remainingArgs[1];
|
const subcommand = remainingArgs[1];
|
||||||
if (subcommand === 'refresh') {
|
if (subcommand === 'refresh') {
|
||||||
await handleCatalogRefresh(verbose);
|
await handleCatalogRefresh(verbose);
|
||||||
|
|||||||
Reference in New Issue
Block a user