mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 12:44:18 +08:00
refactor(presets): pin context window values instead of form fields
Drop the Max Context Tokens / Auto Compact Window template inputs from the Codex and Kimi For Coding presets and hardcode the values in the preset env (372000 / 262144). The rare user who wants different numbers can edit them directly in the JSON editor. Both keys stay on purpose: the compact window resolves as min(model window, value), so matching the window is behavior-neutral today, but the explicit env pins compaction locally against remote-config experiments dialing it down.
This commit is contained in:
@@ -492,22 +492,10 @@ export const providerPresets: ProviderPreset[] = [
|
||||
ANTHROPIC_DEFAULT_HAIKU_MODEL: "kimi-for-coding",
|
||||
ANTHROPIC_DEFAULT_SONNET_MODEL: "kimi-for-coding",
|
||||
ANTHROPIC_DEFAULT_OPUS_MODEL: "kimi-for-coding",
|
||||
CLAUDE_CODE_MAX_CONTEXT_TOKENS: "${CLAUDE_CODE_MAX_CONTEXT_TOKENS}",
|
||||
CLAUDE_CODE_AUTO_COMPACT_WINDOW: "${CLAUDE_CODE_AUTO_COMPACT_WINDOW}",
|
||||
},
|
||||
},
|
||||
templateValues: {
|
||||
CLAUDE_CODE_MAX_CONTEXT_TOKENS: {
|
||||
label: "Max Context Tokens",
|
||||
placeholder: "262144",
|
||||
defaultValue: "262144",
|
||||
editorValue: "262144",
|
||||
},
|
||||
CLAUDE_CODE_AUTO_COMPACT_WINDOW: {
|
||||
label: "Auto Compact Window",
|
||||
placeholder: "262144",
|
||||
defaultValue: "262144",
|
||||
editorValue: "262144",
|
||||
// 双键钉 256K:压缩窗口=min(模型窗口,值),与窗口同值时行为等价于不设,
|
||||
// 但显式钉住可屏蔽远程实验下发的更小压缩点;调整直接改 JSON,不出表单字段
|
||||
CLAUDE_CODE_MAX_CONTEXT_TOKENS: "262144",
|
||||
CLAUDE_CODE_AUTO_COMPACT_WINDOW: "262144",
|
||||
},
|
||||
},
|
||||
category: "cn_official",
|
||||
@@ -1247,25 +1235,12 @@ export const providerPresets: ProviderPreset[] = [
|
||||
// Claude Code falls back to a 200K context window for unrecognized
|
||||
// non-Claude model ids. The ChatGPT Codex backend catalogs gpt-5.6
|
||||
// at a 372K window with a ~353K effective budget (openai/codex#31860),
|
||||
// not the 1.05M API window. Declare 372K for both knobs: Claude Code's
|
||||
// built-in output reserve and compact buffer already keep the compact
|
||||
// trigger below the effective budget.
|
||||
CLAUDE_CODE_MAX_CONTEXT_TOKENS: "${CLAUDE_CODE_MAX_CONTEXT_TOKENS}",
|
||||
CLAUDE_CODE_AUTO_COMPACT_WINDOW: "${CLAUDE_CODE_AUTO_COMPACT_WINDOW}",
|
||||
},
|
||||
},
|
||||
templateValues: {
|
||||
CLAUDE_CODE_MAX_CONTEXT_TOKENS: {
|
||||
label: "Max Context Tokens",
|
||||
placeholder: "372000",
|
||||
defaultValue: "372000",
|
||||
editorValue: "372000",
|
||||
},
|
||||
CLAUDE_CODE_AUTO_COMPACT_WINDOW: {
|
||||
label: "Auto Compact Window",
|
||||
placeholder: "372000",
|
||||
defaultValue: "372000",
|
||||
editorValue: "372000",
|
||||
// not the 1.05M API window. Pin both knobs: the compact window equals
|
||||
// min(model window, value), so matching the window is behavior-neutral
|
||||
// today but shields the compact trigger from remote-config experiments.
|
||||
// Tweak these directly in the JSON editor; no form fields on purpose.
|
||||
CLAUDE_CODE_MAX_CONTEXT_TOKENS: "372000",
|
||||
CLAUDE_CODE_AUTO_COMPACT_WINDOW: "372000",
|
||||
},
|
||||
},
|
||||
category: "third_party",
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { providerPresets } from "@/config/claudeProviderPresets";
|
||||
import { applyTemplateValues } from "@/utils/providerConfigUtils";
|
||||
|
||||
describe("Kimi For Coding Provider Preset", () => {
|
||||
const kimiForCoding = providerPresets.find(
|
||||
@@ -23,38 +22,12 @@ describe("Kimi For Coding Provider Preset", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("should use matching context and auto-compact placeholders", () => {
|
||||
// 预设直接钉值,不再暴露表单输入框;要调整的用户直接改 JSON 编辑框
|
||||
it("should pin the 256K context envs without exposing form fields", () => {
|
||||
const env = (kimiForCoding!.settingsConfig as any).env;
|
||||
expect(env).toHaveProperty(
|
||||
"CLAUDE_CODE_MAX_CONTEXT_TOKENS",
|
||||
"${CLAUDE_CODE_MAX_CONTEXT_TOKENS}",
|
||||
);
|
||||
expect(env).toHaveProperty(
|
||||
"CLAUDE_CODE_AUTO_COMPACT_WINDOW",
|
||||
"${CLAUDE_CODE_AUTO_COMPACT_WINDOW}",
|
||||
);
|
||||
});
|
||||
|
||||
it("should expose matching 256K context and auto-compact values", () => {
|
||||
const values = kimiForCoding!.templateValues as any;
|
||||
expect(values?.CLAUDE_CODE_MAX_CONTEXT_TOKENS).toMatchObject({
|
||||
defaultValue: "262144",
|
||||
editorValue: "262144",
|
||||
});
|
||||
expect(values?.CLAUDE_CODE_AUTO_COMPACT_WINDOW).toMatchObject({
|
||||
defaultValue: "262144",
|
||||
editorValue: "262144",
|
||||
label: "Auto Compact Window",
|
||||
});
|
||||
});
|
||||
|
||||
it("should resolve both Kimi context placeholders", () => {
|
||||
const config = applyTemplateValues(
|
||||
kimiForCoding!.settingsConfig,
|
||||
kimiForCoding!.templateValues,
|
||||
) as any;
|
||||
expect(config.env.CLAUDE_CODE_MAX_CONTEXT_TOKENS).toBe("262144");
|
||||
expect(config.env.CLAUDE_CODE_AUTO_COMPACT_WINDOW).toBe("262144");
|
||||
expect(env.CLAUDE_CODE_MAX_CONTEXT_TOKENS).toBe("262144");
|
||||
expect(env.CLAUDE_CODE_AUTO_COMPACT_WINDOW).toBe("262144");
|
||||
expect(kimiForCoding!.templateValues).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -65,37 +38,12 @@ describe("Codex Provider Preset", () => {
|
||||
expect(codex).toBeDefined();
|
||||
});
|
||||
|
||||
it("should override Claude Code's 200K fallback for GPT models", () => {
|
||||
// 预设直接钉 Codex 目录的 372K 窗口(openai/codex#31860),不暴露表单输入框
|
||||
it("should pin the Codex-catalog 372K window without exposing form fields", () => {
|
||||
const env = (codex!.settingsConfig as any).env;
|
||||
expect(env).toHaveProperty(
|
||||
"CLAUDE_CODE_MAX_CONTEXT_TOKENS",
|
||||
"${CLAUDE_CODE_MAX_CONTEXT_TOKENS}",
|
||||
);
|
||||
expect(env).toHaveProperty(
|
||||
"CLAUDE_CODE_AUTO_COMPACT_WINDOW",
|
||||
"${CLAUDE_CODE_AUTO_COMPACT_WINDOW}",
|
||||
);
|
||||
});
|
||||
|
||||
it("should expose the Codex-catalog 372K window for both context knobs", () => {
|
||||
const values = codex!.templateValues as any;
|
||||
expect(values?.CLAUDE_CODE_MAX_CONTEXT_TOKENS).toMatchObject({
|
||||
defaultValue: "372000",
|
||||
editorValue: "372000",
|
||||
});
|
||||
expect(values?.CLAUDE_CODE_AUTO_COMPACT_WINDOW).toMatchObject({
|
||||
defaultValue: "372000",
|
||||
editorValue: "372000",
|
||||
});
|
||||
});
|
||||
|
||||
it("should resolve both context placeholders into Claude Code env values", () => {
|
||||
const config = applyTemplateValues(
|
||||
codex!.settingsConfig,
|
||||
codex!.templateValues,
|
||||
) as any;
|
||||
expect(config.env.CLAUDE_CODE_MAX_CONTEXT_TOKENS).toBe("372000");
|
||||
expect(config.env.CLAUDE_CODE_AUTO_COMPACT_WINDOW).toBe("372000");
|
||||
expect(env.CLAUDE_CODE_MAX_CONTEXT_TOKENS).toBe("372000");
|
||||
expect(env.CLAUDE_CODE_AUTO_COMPACT_WINDOW).toBe("372000");
|
||||
expect(codex!.templateValues).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user