mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-11 12:09:03 +00:00
fix(codex): preserve sonnet high alias on variant model updates
This commit is contained in:
1 parent
164d195367
commit
3410c52f7e
3 files changed
+41
-5
No files matched your search
@@ -253,7 +253,7 @@ export function updateVariant(name: string, updates: UpdateVariantOptions): Vari
|
|||||||
existing.port
|
existing.port
|
||||||
);
|
);
|
||||||
} else if (updates.model !== undefined) {
|
} 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
|
port: number = CLIPROXY_DEFAULT_PORT
|
||||||
): SettingsEnv {
|
): SettingsEnv {
|
||||||
const baseEnv = getClaudeEnvVars(provider as CLIProxyProvider, port);
|
const baseEnv = getClaudeEnvVars(provider as CLIProxyProvider, port);
|
||||||
const codexSonnetModel =
|
const codexSonnetModel = normalizeCodexSonnetModel(provider, model);
|
||||||
provider === 'codex' && !model.match(/-(xhigh|high|medium)$/) ? `${model}-high` : model;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ANTHROPIC_BASE_URL: baseEnv.ANTHROPIC_BASE_URL || '',
|
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
|
* Ensure directory exists
|
||||||
*/
|
*/
|
||||||
@@ -268,7 +275,11 @@ export function deleteSettingsFile(settingsPath: string): boolean {
|
|||||||
/**
|
/**
|
||||||
* Update model in an existing settings file
|
* 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);
|
const fileName = path.basename(settingsPath);
|
||||||
if (fileName.startsWith('composite-')) {
|
if (fileName.startsWith('composite-')) {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -288,9 +299,10 @@ export function updateSettingsModel(settingsPath: string, model: string): void {
|
|||||||
|
|
||||||
if (model) {
|
if (model) {
|
||||||
settings.env = settings.env || ({} as SettingsEnv);
|
settings.env = settings.env || ({} as SettingsEnv);
|
||||||
|
const codexSonnetModel = normalizeCodexSonnetModel(provider, model);
|
||||||
settings.env.ANTHROPIC_MODEL = model;
|
settings.env.ANTHROPIC_MODEL = model;
|
||||||
settings.env.ANTHROPIC_DEFAULT_OPUS_MODEL = model;
|
settings.env.ANTHROPIC_DEFAULT_OPUS_MODEL = model;
|
||||||
settings.env.ANTHROPIC_DEFAULT_SONNET_MODEL = model;
|
settings.env.ANTHROPIC_DEFAULT_SONNET_MODEL = codexSonnetModel;
|
||||||
} else {
|
} else {
|
||||||
// Clear model settings to use defaults
|
// Clear model settings to use defaults
|
||||||
delete (settings.env as unknown as Record<string, string>).ANTHROPIC_MODEL;
|
delete (settings.env as unknown as Record<string, string>).ANTHROPIC_MODEL;
|
||||||
|
|||||||
@@ -107,4 +107,28 @@ cliproxy:
|
|||||||
const config = loadOrCreateUnifiedConfig();
|
const config = loadOrCreateUnifiedConfig();
|
||||||
expect(config.cliproxy?.variants?.demo?.provider).toBe('codex');
|
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