refactor(cliproxy): remove model alias functionality

- delete model-alias-config.ts and cliproxy-alias-handler.ts

- simplify sync to use ANTHROPIC_MODEL directly

- remove alias routes, hooks, and UI components
This commit is contained in:
kaitranntt committed 2026-01-28 11:57:22 -05:00
1 parent afa3bdafce
commit 32dbd5e174
12 files changed
+92 -775

No files matched your search

-13
View File
@@ -15,19 +15,6 @@ export {
isProfileSyncable,
} from './profile-mapper';
// Model alias config
export type { ModelAlias, ModelAliasConfig } from './model-alias-config';
export {
getModelAliasesPath,
loadModelAliases,
saveModelAliases,
getProfileAliases,
addProfileAlias,
removeProfileAlias,
listAllAliases,
DEFAULT_MODEL_ALIASES,
} from './model-alias-config';
// Local config sync
export { syncToLocalConfig, getLocalSyncStatus } from './local-config-sync';
+2 -1
View File
@@ -122,10 +122,11 @@ function transformToConfigFormat(key: ClaudeKey): Record<string, unknown> {
// Add empty proxy-url (required by CLIProxyAPI)
entry['proxy-url'] = '';
// Use model name directly (no alias mapping)
if (key.models && key.models.length > 0) {
entry.models = key.models.map((m) => ({
name: m.name,
alias: m.alias || '',
alias: '',
}));
}
-176
View File
@@ -1,176 +0,0 @@
/**
* Model Alias Configuration
*
* Manages model alias mappings for CLIProxy sync.
* Aliases map Claude model names to provider-specific models.
*/
import * as fs from 'fs';
import * as path from 'path';
import { getCcsDir } from '../../utils/config-manager';
/** Model alias mapping */
export interface ModelAlias {
/** Claude model name (e.g., "claude-3-5-sonnet") */
from: string;
/** Target model (e.g., "glm-4.7-airx-thinking") */
to: string;
}
/** Model alias configuration file structure */
export interface ModelAliasConfig {
/** Version for future schema changes */
version: number;
/** Aliases for each profile name */
aliases: Record<string, ModelAlias[]>;
}
/** Default model aliases (common mappings) */
export const DEFAULT_MODEL_ALIASES: Record<string, ModelAlias[]> = {
glm: [
{ from: 'claude-sonnet-4-20250514', to: 'glm-4.7-thinking' },
{ from: 'claude-3-5-sonnet-20241022', to: 'glm-4.7' },
{ from: 'claude-3-5-haiku-20241022', to: 'glm-4.7-flash' },
],
kimi: [
{ from: 'claude-sonnet-4-20250514', to: 'moonshot-v1-auto' },
{ from: 'claude-3-5-sonnet-20241022', to: 'moonshot-v1-128k' },
{ from: 'claude-3-5-haiku-20241022', to: 'moonshot-v1-32k' },
],
qwen: [
{ from: 'claude-sonnet-4-20250514', to: 'qwen-coder-plus' },
{ from: 'claude-3-5-sonnet-20241022', to: 'qwen-plus' },
{ from: 'claude-3-5-haiku-20241022', to: 'qwen-turbo' },
],
};
/**
* Get path to model aliases config file.
*/
export function getModelAliasesPath(): string {
return path.join(getCcsDir(), 'cliproxy', 'model-aliases.json');
}
/**
* Load model alias configuration.
* Returns defaults if file doesn't exist.
*/
export function loadModelAliases(): ModelAliasConfig {
const aliasPath = getModelAliasesPath();
try {
if (fs.existsSync(aliasPath)) {
const content = fs.readFileSync(aliasPath, 'utf8');
const config = JSON.parse(content) as ModelAliasConfig;
return config;
}
} catch {
// Fall through to defaults
}
// Return defaults
return {
version: 1,
aliases: { ...DEFAULT_MODEL_ALIASES },
};
}
/**
* Save model alias configuration.
* @returns Success status with optional error message
*/
export function saveModelAliases(config: ModelAliasConfig): { success: boolean; error?: string } {
try {
const aliasPath = getModelAliasesPath();
const dir = path.dirname(aliasPath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
fs.writeFileSync(aliasPath, JSON.stringify(config, null, 2), 'utf8');
return { success: true };
} catch (error) {
return {
success: false,
error: error instanceof Error ? error.message : String(error),
};
}
}
/**
* Get aliases for a specific profile.
*/
export function getProfileAliases(profileName: string): ModelAlias[] {
const config = loadModelAliases();
return config.aliases[profileName] ?? [];
}
/**
* Add an alias for a profile.
*/
export function addProfileAlias(profileName: string, from: string, to: string): void {
// Validate inputs
if (!from || from.trim() === '') {
throw new Error('Model alias "from" cannot be empty');
}
if (!to || to.trim() === '') {
throw new Error('Model alias "to" cannot be empty');
}
const config = loadModelAliases();
if (!config.aliases[profileName]) {
config.aliases[profileName] = [];
}
// Check if alias already exists (update if so)
const existingIdx = config.aliases[profileName].findIndex((a) => a.from === from);
if (existingIdx >= 0) {
config.aliases[profileName][existingIdx].to = to;
} else {
config.aliases[profileName].push({ from, to });
}
const result = saveModelAliases(config);
if (!result.success) {
throw new Error(`Failed to save model aliases: ${result.error}`);
}
}
/**
* Remove an alias for a profile.
*/
export function removeProfileAlias(profileName: string, from: string): boolean {
const config = loadModelAliases();
if (!config.aliases[profileName]) {
return false;
}
const initialLen = config.aliases[profileName].length;
config.aliases[profileName] = config.aliases[profileName].filter((a) => a.from !== from);
if (config.aliases[profileName].length === initialLen) {
return false;
}
// Remove empty profile entry
if (config.aliases[profileName].length === 0) {
delete config.aliases[profileName];
}
const result = saveModelAliases(config);
if (!result.success) {
throw new Error(`Failed to save model aliases: ${result.error}`);
}
return true;
}
/**
* List all aliases.
*/
export function listAllAliases(): Record<string, ModelAlias[]> {
const config = loadModelAliases();
return config.aliases;
}
+13 -27
View File
@@ -2,15 +2,13 @@
* Profile Mapper for CLIProxy Sync
*
* Transforms CCS settings-based profiles into CLIProxy ClaudeKey format.
* Handles model alias mapping and settings normalization.
*/
import * as fs from 'fs';
import * as path from 'path';
import { getCcsDir } from '../../utils/config-manager';
import { listApiProfiles, isApiProfileConfigured } from '../../api/services/profile-reader';
import type { ClaudeKey, ClaudeModel } from '../management-api-types';
import { getProfileAliases, type ModelAlias } from './model-alias-config';
import type { ClaudeKey } from '../management-api-types';
/**
* Profile info with settings for sync.
@@ -80,16 +78,6 @@ export function loadSyncableProfiles(): SyncableProfile[] {
return syncable;
}
/**
* Map model aliases to ClaudeModel format.
*/
function mapAliasesToClaudeModels(aliases: ModelAlias[]): ClaudeModel[] {
return aliases.map((alias) => ({
name: alias.from,
alias: alias.to,
}));
}
/**
* Sanitize profile name for YAML safety.
* Replaces non-alphanumeric chars (except - and _) with hyphens.
@@ -109,6 +97,7 @@ export function mapProfileToClaudeKey(profile: SyncableProfile): ClaudeKey | nul
if (!apiKey) return null;
const baseUrl = env.ANTHROPIC_BASE_URL;
const modelName = env.ANTHROPIC_MODEL;
// Generate prefix from profile name (e.g., "glm" -> "glm-")
const sanitizedName = sanitizeProfileName(profile.name);
@@ -117,10 +106,6 @@ export function mapProfileToClaudeKey(profile: SyncableProfile): ClaudeKey | nul
}
const prefix = `${sanitizedName}-`;
// Load model aliases for this profile
const aliases = getProfileAliases(profile.name);
const models = aliases.length > 0 ? mapAliasesToClaudeModels(aliases) : undefined;
const claudeKey: ClaudeKey = {
'api-key': apiKey,
prefix,
@@ -130,8 +115,14 @@ export function mapProfileToClaudeKey(profile: SyncableProfile): ClaudeKey | nul
claudeKey['base-url'] = baseUrl;
}
if (models && models.length > 0) {
claudeKey.models = models;
// Use model name directly from profile (no alias mapping)
if (modelName) {
claudeKey.models = [
{
name: modelName,
alias: '',
},
];
}
return claudeKey;
@@ -164,10 +155,8 @@ export interface SyncPreviewItem {
name: string;
/** Base URL (masked) */
baseUrl?: string;
/** Whether profile has model aliases */
hasAliases: boolean;
/** Number of model aliases */
aliasCount: number;
/** Model name */
modelName?: string;
}
export function generateSyncPreview(): SyncPreviewItem[] {
@@ -175,13 +164,10 @@ export function generateSyncPreview(): SyncPreviewItem[] {
const preview: SyncPreviewItem[] = [];
for (const profile of profiles) {
const aliases = getProfileAliases(profile.name);
preview.push({
name: profile.name,
baseUrl: profile.env?.ANTHROPIC_BASE_URL,
hasAliases: aliases.length > 0,
aliasCount: aliases.length,
modelName: profile.env?.ANTHROPIC_MODEL,
});
}