fix(ai): make custom output token budget configurable
This commit is contained in:
1 parent
56f85a2c77
commit
1c170396d3
28 files changed
+249
-48
No files matched your search
@@ -669,6 +669,12 @@ describe("settingsStore AI API key normalization", () => {
|
||||
it("trims API keys when normalizing loaded configurations", () => {
|
||||
expect(normalizeAiConfig({ provider: "openai", apiKey: " secret " }).apiKey).toBe("secret");
|
||||
});
|
||||
it("preserves and bounds a configured maximum output token budget", () => {
|
||||
expect(normalizeAiConfig({ provider: "deepseek", maxOutputTokens: 32768 }).maxOutputTokens).toBe(32768);
|
||||
expect(normalizeAiConfig({ provider: "deepseek", maxOutputTokens: 1_500_000 }).maxOutputTokens).toBe(1_000_000);
|
||||
expect(normalizeAiConfig({ provider: "deepseek", maxOutputTokens: 128 }).maxOutputTokens).toBeUndefined();
|
||||
expect(normalizeAiConfig({ provider: "deepseek", maxOutputTokens: Number.NaN }).maxOutputTokens).toBeUndefined();
|
||||
});
|
||||
|
||||
it("provides Kimi defaults and recognizes legacy Kimi configurations", () => {
|
||||
expect(AI_PROVIDER_PRESETS.kimi).toMatchObject({
|
||||
|
||||
@@ -458,6 +458,8 @@ const defaultConfigs: Record<AiProvider, Omit<AiConfig, "apiKey">> = Object.from
|
||||
) as Record<AiProvider, Omit<AiConfig, "apiKey">>;
|
||||
|
||||
const AI_REASONING_LEVELS: AiReasoningLevel[] = ["default", "minimal", "low", "medium", "high", "xhigh", "max"];
|
||||
export const AI_OUTPUT_TOKENS_MIN = 256;
|
||||
export const AI_OUTPUT_TOKENS_MAX = 1_000_000;
|
||||
const AI_ENV_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
||||
|
||||
function normalizeAiReasoningLevel(value: unknown): AiReasoningLevel {
|
||||
@@ -488,6 +490,8 @@ export function normalizeAiHeaders(value: unknown): Record<string, string> {
|
||||
|
||||
export function normalizeAiConfig(config: Partial<AiConfig> | null | undefined): AiConfig {
|
||||
const provider = config?.provider && config.provider in AI_PROVIDER_PRESETS ? config.provider : inferAiProviderFromConfig(config);
|
||||
const rawMaxOutputTokens = config?.maxOutputTokens;
|
||||
const maxOutputTokens = typeof rawMaxOutputTokens === "number" && Number.isFinite(rawMaxOutputTokens) && rawMaxOutputTokens >= AI_OUTPUT_TOKENS_MIN ? Math.min(AI_OUTPUT_TOKENS_MAX, Math.round(rawMaxOutputTokens)) : undefined;
|
||||
return {
|
||||
...defaultConfigs[provider],
|
||||
...config,
|
||||
@@ -500,6 +504,7 @@ export function normalizeAiConfig(config: Partial<AiConfig> | null | undefined):
|
||||
proxyUrl: config?.proxyUrl ?? "",
|
||||
enableThinking: config?.enableThinking ?? true,
|
||||
reasoningLevel: normalizeAiReasoningLevel(config?.reasoningLevel),
|
||||
maxOutputTokens,
|
||||
contextWindow: config?.contextWindow ?? undefined,
|
||||
codexCliPath: config?.codexCliPath?.trim() || undefined,
|
||||
codexCliEnv: normalizeAiEnv(config?.codexCliEnv),
|
||||
|
||||
Reference in new issue
Block a user