mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-17 06:17:09 +00:00
fix(codex): preserve sonnet high alias on variant model updates
This commit is contained in:
@@ -253,7 +253,7 @@ export function updateVariant(name: string, updates: UpdateVariantOptions): Vari
|
||||
existing.port
|
||||
);
|
||||
} else if (updates.model !== undefined) {
|
||||
updateSettingsModel(settingsPath, updates.model);
|
||||
updateSettingsModel(settingsPath, updates.model, existing.provider);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,8 +44,7 @@ function buildSettingsEnv(
|
||||
port: number = CLIPROXY_DEFAULT_PORT
|
||||
): SettingsEnv {
|
||||
const baseEnv = getClaudeEnvVars(provider as CLIProxyProvider, port);
|
||||
const codexSonnetModel =
|
||||
provider === 'codex' && !model.match(/-(xhigh|high|medium)$/) ? `${model}-high` : model;
|
||||
const codexSonnetModel = normalizeCodexSonnetModel(provider, model);
|
||||
|
||||
return {
|
||||
ANTHROPIC_BASE_URL: baseEnv.ANTHROPIC_BASE_URL || '',
|
||||
@@ -57,6 +56,14 @@ function buildSettingsEnv(
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeCodexSonnetModel(
|
||||
provider: CLIProxyProfileName | undefined,
|
||||
model: string
|
||||
): string {
|
||||
if (provider !== 'codex') return model;
|
||||
return /-(xhigh|high|medium)$/.test(model) ? model : `${model}-high`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure directory exists
|
||||
*/
|
||||
@@ -268,7 +275,11 @@ export function deleteSettingsFile(settingsPath: string): boolean {
|
||||
/**
|
||||
* Update model in an existing settings file
|
||||
*/
|
||||
export function updateSettingsModel(settingsPath: string, model: string): void {
|
||||
export function updateSettingsModel(
|
||||
settingsPath: string,
|
||||
model: string,
|
||||
provider?: CLIProxyProfileName
|
||||
): void {
|
||||
const fileName = path.basename(settingsPath);
|
||||
if (fileName.startsWith('composite-')) {
|
||||
console.log(
|
||||
@@ -288,9 +299,10 @@ export function updateSettingsModel(settingsPath: string, model: string): void {
|
||||
|
||||
if (model) {
|
||||
settings.env = settings.env || ({} as SettingsEnv);
|
||||
const codexSonnetModel = normalizeCodexSonnetModel(provider, model);
|
||||
settings.env.ANTHROPIC_MODEL = model;
|
||||
settings.env.ANTHROPIC_DEFAULT_OPUS_MODEL = model;
|
||||
settings.env.ANTHROPIC_DEFAULT_SONNET_MODEL = model;
|
||||
settings.env.ANTHROPIC_DEFAULT_SONNET_MODEL = codexSonnetModel;
|
||||
} else {
|
||||
// Clear model settings to use defaults
|
||||
delete (settings.env as unknown as Record<string, string>).ANTHROPIC_MODEL;
|
||||
|
||||
@@ -107,4 +107,28 @@ cliproxy:
|
||||
const config = loadOrCreateUnifiedConfig();
|
||||
expect(config.cliproxy?.variants?.demo?.provider).toBe('codex');
|
||||
});
|
||||
|
||||
it('preserves codex sonnet alias on model-only updates', () => {
|
||||
const toCodex = updateVariant('demo', {
|
||||
provider: 'codex',
|
||||
model: 'gpt-5.3-codex',
|
||||
});
|
||||
expect(toCodex.success).toBe(true);
|
||||
|
||||
const settingsPath = path.join(tmpDir, 'gemini-demo.settings.json');
|
||||
let settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8')) as {
|
||||
env: Record<string, string>;
|
||||
};
|
||||
expect(settings.env.ANTHROPIC_DEFAULT_SONNET_MODEL).toBe('gpt-5.3-codex-high');
|
||||
|
||||
const modelOnly = updateVariant('demo', { model: 'gpt-5.3-codex' });
|
||||
expect(modelOnly.success).toBe(true);
|
||||
|
||||
settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8')) as {
|
||||
env: Record<string, string>;
|
||||
};
|
||||
expect(settings.env.ANTHROPIC_MODEL).toBe('gpt-5.3-codex');
|
||||
expect(settings.env.ANTHROPIC_DEFAULT_OPUS_MODEL).toBe('gpt-5.3-codex');
|
||||
expect(settings.env.ANTHROPIC_DEFAULT_SONNET_MODEL).toBe('gpt-5.3-codex-high');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user