mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-04 04:17:38 +00:00
fix(profile): handle km compatibility for legacy kimi api users
This commit is contained in:
@@ -5,6 +5,7 @@ import * as path from 'path';
|
||||
import { Settings } from '../types';
|
||||
import { ValidationResult } from '../types/utils';
|
||||
import { getCcsDir } from './config-manager';
|
||||
import { getProfileLookupCandidates } from './profile-compat';
|
||||
|
||||
/**
|
||||
* Extended validation result for delegation profiles
|
||||
@@ -24,19 +25,24 @@ interface DelegationValidationResult extends ValidationResult {
|
||||
export class DelegationValidator {
|
||||
/**
|
||||
* Validate a delegation profile
|
||||
* @param profileName - Name of profile to validate (e.g., 'glm', 'kimi')
|
||||
* @param profileName - Name of profile to validate (e.g., 'glm', 'km')
|
||||
* @returns Validation result { valid: boolean, error?: string, settingsPath?: string }
|
||||
*/
|
||||
static validate(profileName: string): DelegationValidationResult {
|
||||
const settingsPath = path.join(getCcsDir(), `${profileName}.settings.json`);
|
||||
const ccsDir = getCcsDir();
|
||||
const candidateSettingsPath = getProfileLookupCandidates(profileName)
|
||||
.map((candidate) => path.join(ccsDir, `${candidate}.settings.json`))
|
||||
.find((candidatePath) => fs.existsSync(candidatePath));
|
||||
const primarySettingsPath = path.join(ccsDir, `${profileName}.settings.json`);
|
||||
const settingsPath = candidateSettingsPath || primarySettingsPath;
|
||||
|
||||
// Check if profile directory exists
|
||||
if (!fs.existsSync(settingsPath)) {
|
||||
if (!candidateSettingsPath) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Profile not found: ${profileName}`,
|
||||
suggestion:
|
||||
`Profile settings missing at: ${settingsPath}\n\n` +
|
||||
`Profile settings missing at: ${primarySettingsPath}\n\n` +
|
||||
`To set up ${profileName} profile:\n` +
|
||||
` 1. Copy base settings: cp config/base-${profileName}.settings.json ~/.ccs/${profileName}.settings.json\n` +
|
||||
` 2. Edit settings: Edit ~/.ccs/${profileName}.settings.json\n` +
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Profile compatibility helpers for renamed commands/profiles.
|
||||
*
|
||||
* Current compatibility mappings:
|
||||
* - `km` is the canonical Kimi API profile command
|
||||
* - `kimi` remains as legacy API profile name in existing user configs
|
||||
*/
|
||||
|
||||
const PROFILE_COMPAT_ALIASES: Readonly<Record<string, readonly string[]>> = Object.freeze({
|
||||
km: ['kimi'],
|
||||
});
|
||||
|
||||
/**
|
||||
* Build lookup candidates for a profile.
|
||||
* Order: exact input -> lowercase form (if different) -> legacy aliases.
|
||||
*/
|
||||
export function getProfileLookupCandidates(profileName: string): string[] {
|
||||
const raw = profileName.trim();
|
||||
const normalized = raw.toLowerCase();
|
||||
const aliases = PROFILE_COMPAT_ALIASES[normalized] || [];
|
||||
const ordered = [raw, normalized, ...aliases];
|
||||
|
||||
return [...new Set(ordered.filter(Boolean))];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a resolved profile name came from a legacy alias.
|
||||
*/
|
||||
export function isLegacyProfileAlias(requestedName: string, resolvedName: string): boolean {
|
||||
const requestedNormalized = requestedName.trim().toLowerCase();
|
||||
const resolvedNormalized = resolvedName.trim().toLowerCase();
|
||||
|
||||
if (requestedNormalized === resolvedNormalized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const aliases = PROFILE_COMPAT_ALIASES[requestedNormalized] || [];
|
||||
return aliases.includes(resolvedNormalized);
|
||||
}
|
||||
Reference in New Issue
Block a user