Files
ccs/src/cliproxy/management-api-types.ts
T
c8a099509a feat(cliproxy): add hybrid catalog sync with CLIProxyAPI (#485)
* chore(release): 7.38.0 [skip ci]

## [7.38.0](https://github.com/kaitranntt/ccs/compare/v7.37.1...v7.38.0) (2026-02-07)

### Features

* **release:** v7.38.0 - Extended Context, Qwen Models, Bug Fixes ([#480](https://github.com/kaitranntt/ccs/issues/480)) ([b454834](https://github.com/kaitranntt/ccs/commit/b4548341750804339c87c48259dd8741425d2acf)), closes [#472](https://github.com/kaitranntt/ccs/issues/472) [#474](https://github.com/kaitranntt/ccs/issues/474) [#103](https://github.com/kaitranntt/ccs/issues/103) [#478](https://github.com/kaitranntt/ccs/issues/478) [#482](https://github.com/kaitranntt/ccs/issues/482)

* feat(cliproxy): add hybrid catalog sync with CLIProxyAPI

Add `ccs cliproxy catalog` command family for syncing model catalogs
from CLIProxyAPI's model-definitions endpoint. Cached locally with
24h TTL, merges remote models with static catalog preserving
broken/deprecated flags. Dashboard API endpoint at /api/cliproxy/catalog.

Closes #477

---------

Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
2026-02-06 23:16:54 -05:00

157 lines
3.9 KiB
TypeScript

/**
* Management API Types for CLIProxyAPI
*
* Type definitions matching CLIProxyAPI Go structs for Management API CRUD operations.
* Used for syncing CCS API profiles to remote CLIProxy instance.
*/
/**
* Model alias within a ClaudeKey entry.
* Maps Claude model names to provider-specific models.
*/
export interface ClaudeModel {
/** Claude model name to match (e.g., "claude-3-5-sonnet") */
name: string;
/** Target model to use instead (e.g., "glm-4.7-airx-thinking") */
alias: string;
}
/**
* ClaudeKey configuration for CLIProxy.
* Maps to config.ClaudeKey in CLIProxyAPI Go code.
*/
export interface ClaudeKey {
/** API key for the provider */
'api-key': string;
/** Prefix for model name matching (e.g., "glm-" matches "glm-*" requests) */
prefix?: string;
/** Base URL for the provider API */
'base-url'?: string;
/** Optional proxy URL for requests */
'proxy-url'?: string;
/** Additional headers to include in requests */
headers?: Record<string, string>;
/** Models to exclude from this key */
'excluded-models'?: string[];
/** Model name to alias mappings */
models?: ClaudeModel[];
}
/**
* Configuration for the Management API client.
*/
export interface ManagementClientConfig {
/** Remote proxy host (IP or hostname) */
host: string;
/** Remote proxy port (default: 8317 for HTTP, 443 for HTTPS) */
port?: number;
/** Protocol to use (http or https) */
protocol: 'http' | 'https';
/** Management key for authentication (sent as Bearer token) */
managementKey: string;
/** Request timeout in milliseconds (default: 5000) */
timeout?: number;
/** Allow self-signed certificates for HTTPS (default: false) */
allowSelfSigned?: boolean;
}
/**
* Health check result from Management API.
*/
export interface ManagementHealthStatus {
/** Whether the Management API is reachable */
healthy: boolean;
/** Version of CLIProxyAPI (from X-CPA-VERSION header) */
version?: string;
/** Commit hash (from X-CPA-COMMIT header) */
commit?: string;
/** Latency in milliseconds */
latencyMs?: number;
/** Error message if not healthy */
error?: string;
/** Error code for programmatic handling */
errorCode?: ManagementApiErrorCode;
}
/**
* Error codes for Management API operations.
*/
export type ManagementApiErrorCode =
| 'CONNECTION_REFUSED'
| 'TIMEOUT'
| 'AUTH_FAILED'
| 'DNS_FAILED'
| 'NETWORK_UNREACHABLE'
| 'NOT_FOUND'
| 'BAD_REQUEST'
| 'SERVER_ERROR'
| 'UNKNOWN';
/**
* Response from GET /v0/management/claude-api-key
*/
export interface GetClaudeKeysResponse {
'claude-api-key': ClaudeKey[];
}
/**
* Patch request body for updating a single ClaudeKey.
*/
export interface ClaudeKeyPatch {
/** Index of the key to update (0-based) */
index?: number;
/** Match by api-key value */
match?: string;
/** Fields to update */
value: Partial<ClaudeKey>;
}
/**
* Sync status for tracking sync operations.
*/
export interface SyncStatus {
/** Last sync timestamp (ISO 8601) */
lastSyncAt?: string;
/** Number of profiles synced */
profileCount: number;
/** Whether sync was successful */
success: boolean;
/** Error message if failed */
error?: string;
/** Remote CLIProxy URL */
remoteUrl?: string;
}
/**
* Remote model thinking support from CLIProxyAPI model-definitions endpoint
*/
export interface RemoteThinkingSupport {
min?: number;
max?: number;
zero_allowed?: boolean;
dynamic_allowed?: boolean;
levels?: string[];
}
/**
* Remote model info from CLIProxyAPI model-definitions endpoint
*/
export interface RemoteModelInfo {
id: string;
display_name?: string;
description?: string;
context_length?: number;
max_completion_tokens?: number;
thinking?: RemoteThinkingSupport;
owned_by?: string;
type?: string;
}
/**
* Response from GET /v0/management/model-definitions/:channel
*/
export interface GetModelDefinitionsResponse {
channel: string;
models: RemoteModelInfo[];
}