mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-13 14:15:56 +00:00
Merge pull request #1634 from KennethWKZ/feat/support-claude-sonnet-1m
fix: preserve saved Claude extended-context preference
This commit is contained in:
2 files changed
+57
-13
No files matched your search
@@ -168,6 +168,26 @@ describe('applyExtendedContextConfig', () => {
|
||||
expect(env.ANTHROPIC_MODEL).toBe('gemini-2.5-pro(high)[1m]');
|
||||
});
|
||||
|
||||
it('preserves a saved [1m] preference for supported Claude models in auto mode', () => {
|
||||
const env: NodeJS.ProcessEnv = {
|
||||
ANTHROPIC_MODEL: 'claude-sonnet-4-5-20250929[1m]',
|
||||
};
|
||||
|
||||
applyExtendedContextConfig(env, 'claude', undefined);
|
||||
|
||||
expect(env.ANTHROPIC_MODEL).toBe('claude-sonnet-4-5-20250929[1m]');
|
||||
});
|
||||
|
||||
it('strips a stale [1m] preference from unsupported native Gemini models', () => {
|
||||
const env: NodeJS.ProcessEnv = {
|
||||
ANTHROPIC_MODEL: 'gemini-2.5-flash[1m]',
|
||||
};
|
||||
|
||||
applyExtendedContextConfig(env, 'gemini', undefined);
|
||||
|
||||
expect(env.ANTHROPIC_MODEL).toBe('gemini-2.5-flash');
|
||||
});
|
||||
|
||||
it('handles empty env vars gracefully', () => {
|
||||
const env: NodeJS.ProcessEnv = {};
|
||||
applyExtendedContextConfig(env, 'gemini', undefined);
|
||||
|
||||
@@ -13,9 +13,12 @@ import type { CLIProxyProvider } from '../types';
|
||||
import { supportsExtendedContext } from '../model-catalog';
|
||||
import { warn } from '../../utils/ui';
|
||||
import {
|
||||
ANTHROPIC_MODEL_ENV_KEYS,
|
||||
applyExtendedContextPreferenceToAnthropicModels,
|
||||
applyExtendedContextSuffix as applyExtendedContextSuffixShared,
|
||||
hasExtendedContextSuffix,
|
||||
isNativeGeminiModel,
|
||||
stripExtendedContextSuffix,
|
||||
stripModelConfigurationSuffixes,
|
||||
} from '../../shared/extended-context-utils';
|
||||
|
||||
@@ -73,20 +76,41 @@ export function applyExtendedContextConfig(
|
||||
provider: CLIProxyProvider,
|
||||
extendedContextOverride?: boolean
|
||||
): void {
|
||||
if (extendedContextOverride === false) {
|
||||
Object.assign(envVars, applyExtendedContextPreferenceToAnthropicModels(envVars, false));
|
||||
if (extendedContextOverride === true || extendedContextOverride === false) {
|
||||
Object.assign(
|
||||
envVars,
|
||||
applyExtendedContextPreferenceToAnthropicModels(envVars, extendedContextOverride, {
|
||||
supportsExtendedContext: (modelId) =>
|
||||
shouldApplyExtendedContext(
|
||||
provider,
|
||||
stripModelConfigurationSuffixes(modelId),
|
||||
extendedContextOverride
|
||||
),
|
||||
})
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Object.assign(
|
||||
envVars,
|
||||
applyExtendedContextPreferenceToAnthropicModels(envVars, true, {
|
||||
supportsExtendedContext: (modelId) =>
|
||||
shouldApplyExtendedContext(
|
||||
provider,
|
||||
stripModelConfigurationSuffixes(modelId),
|
||||
extendedContextOverride
|
||||
),
|
||||
})
|
||||
);
|
||||
// Auto mode (no explicit --1m/--no-1m this launch): don't force-strip a
|
||||
// previously saved [1m] preference just because the model is Claude — only
|
||||
// strip when the model no longer supports extended context. Native Gemini
|
||||
// models still get auto-toggled based on catalog support.
|
||||
for (const key of ANTHROPIC_MODEL_ENV_KEYS) {
|
||||
const value = envVars[key];
|
||||
if (typeof value !== 'string' || value.trim().length === 0) {
|
||||
continue;
|
||||
}
|
||||
const modelId = stripModelConfigurationSuffixes(value);
|
||||
|
||||
if (isNativeGeminiModel(modelId)) {
|
||||
envVars[key] = supportsExtendedContext(provider, modelId)
|
||||
? applyExtendedContextSuffixShared(value)
|
||||
: stripExtendedContextSuffix(value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hasExtendedContextSuffix(value) && !supportsExtendedContext(provider, modelId)) {
|
||||
envVars[key] = stripExtendedContextSuffix(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user