fix(ai): make custom output token budget configurable

This commit is contained in:
Freud authored and GitHub committed 2026-09-03 21:07:37 +08:00
1 parent 56f85a2c77
commit 1c170396d3
28 files changed
+249 -48

No files matched your search

+38
View File
@@ -158,6 +158,44 @@ describe("AI SQL dialect prompt", () => {
expect(prompt).toContain("Ask mode");
});
it("uses the configured output budget for non-thinking requests", () => {
const request = buildAgentRequest({
config: {
provider: "deepseek",
apiKey: "test",
apiUrl: "https://example.invalid",
model: "deepseek-v4-flash",
enableThinking: false,
maxOutputTokens: 1024,
},
action: "general",
mode: "ask",
instruction: "generate a long migration",
context: context(),
});
expect(request.maxTokens).toBe(1024);
});
it("uses the configured output budget above the thinking minimum", () => {
const request = buildAgentRequest({
config: {
provider: "deepseek",
apiKey: "test",
apiUrl: "https://example.invalid",
model: "deepseek-v4-flash",
enableThinking: true,
maxOutputTokens: 32768,
},
action: "general",
mode: "ask",
instruction: "generate a long migration",
context: context(),
});
expect(request.maxTokens).toBe(32768);
});
it("MongoDB agent mode uses shell commands instead of SQL", () => {
const prompt = buildSystemPrompt("general", context({ databaseType: "mongodb", connectionName: "MongoDB", database: "benchmark" }), "agent");
+2 -1
View File
@@ -179,7 +179,8 @@ export function buildAgentRequest(input: AiRequestInput, history?: api.AiMessage
];
const params = actionParams(input.action);
const maxTokens = input.config.enableThinking ? Math.max(params.maxTokens, 8192) : params.maxTokens;
const baseMaxTokens = input.config.maxOutputTokens ?? params.maxTokens;
const maxTokens = input.config.enableThinking ? Math.max(baseMaxTokens, 8192) : baseMaxTokens;
return { messages, systemPrompt, taskContract, maxTokens };
}