feat(core): Migrate generateContent to model configs. (#12834)

This commit is contained in:
joshualitt
2025-11-11 08:10:50 -08:00
committed by GitHub
parent cbbf565121
commit a4415f15d3
15 changed files with 169 additions and 95 deletions
+2 -1
View File
@@ -366,10 +366,11 @@ describe('ShellTool', () => {
const result = await promise;
expect(summarizer.summarizeToolOutput).toHaveBeenCalledWith(
mockConfig,
{ model: 'summarizer-shell' },
expect.any(String),
mockConfig.getGeminiClient(),
mockAbortSignal,
1000,
);
expect(result.llmContent).toBe('summarized output');
expect(result.returnDisplay).toBe('long output');
+2 -1
View File
@@ -308,10 +308,11 @@ export class ShellToolInvocation extends BaseToolInvocation<
: {};
if (summarizeConfig && summarizeConfig[SHELL_TOOL_NAME]) {
const summary = await summarizeToolOutput(
this.config,
{ model: 'summarizer-shell' },
llmContent,
this.config.getGeminiClient(),
signal,
summarizeConfig[SHELL_TOOL_NAME].tokenBudget,
);
return {
llmContent: summary,
+10 -4
View File
@@ -142,6 +142,12 @@ describe('WebFetchTool', () => {
setApprovalMode: vi.fn(),
getProxy: vi.fn(),
getGeminiClient: mockGetGeminiClient,
modelConfigService: {
getResolvedConfig: vi.fn().mockImplementation(({ model }) => ({
model,
generateContentConfig: {},
})),
},
isInteractive: () => false,
} as unknown as Config;
});
@@ -270,7 +276,7 @@ describe('WebFetchTool', () => {
} as Response);
// Mock fallback LLM call to return the content passed to it
mockGenerateContent.mockImplementationOnce(async (req) => ({
mockGenerateContent.mockImplementationOnce(async (_, req) => ({
candidates: [{ content: { parts: [{ text: req[0].parts[0].text }] } }],
}));
@@ -298,7 +304,7 @@ describe('WebFetchTool', () => {
} as Response);
// Mock fallback LLM call to return the content passed to it
mockGenerateContent.mockImplementationOnce(async (req) => ({
mockGenerateContent.mockImplementationOnce(async (_, req) => ({
candidates: [{ content: { parts: [{ text: req[0].parts[0].text }] } }],
}));
@@ -320,7 +326,7 @@ describe('WebFetchTool', () => {
} as Response);
// Mock fallback LLM call to return the content passed to it
mockGenerateContent.mockImplementationOnce(async (req) => ({
mockGenerateContent.mockImplementationOnce(async (_, req) => ({
candidates: [{ content: { parts: [{ text: req[0].parts[0].text }] } }],
}));
@@ -342,7 +348,7 @@ describe('WebFetchTool', () => {
} as Response);
// Mock fallback LLM call to return the content passed to it
mockGenerateContent.mockImplementationOnce(async (req) => ({
mockGenerateContent.mockImplementationOnce(async (_, req) => ({
candidates: [{ content: { parts: [{ text: req[0].parts[0].text }] } }],
}));
+2 -6
View File
@@ -19,9 +19,7 @@ import type { MessageBus } from '../confirmation-bus/message-bus.js';
import { ToolErrorType } from './tool-error.js';
import { getErrorMessage } from '../utils/errors.js';
import type { Config } from '../config/config.js';
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/config.js';
import { ApprovalMode } from '../policy/types.js';
import { getResponseText } from '../utils/partUtils.js';
import { fetchWithTimeout, isPrivateIp } from '../utils/fetch.js';
import { convert } from 'html-to-text';
@@ -171,10 +169,9 @@ ${textContent}
---
`;
const result = await geminiClient.generateContent(
{ model: 'web-fetch-fallback' },
[{ role: 'user', parts: [{ text: fallbackPrompt }] }],
{},
signal,
DEFAULT_GEMINI_FLASH_MODEL,
);
const resultText = getResponseText(result) || '';
return {
@@ -255,10 +252,9 @@ ${textContent}
try {
const response = await geminiClient.generateContent(
{ model: 'web-fetch' },
[{ role: 'user', parts: [{ text: userPrompt }] }],
{ tools: [{ urlContext: {} }] },
signal, // Pass signal
DEFAULT_GEMINI_FLASH_MODEL,
);
debugLogger.debug(
@@ -25,6 +25,12 @@ describe('WebSearchTool', () => {
const mockConfigInstance = {
getGeminiClient: () => mockGeminiClient,
getProxy: () => undefined,
generationConfigService: {
getResolvedConfig: vi.fn().mockImplementation(({ model }) => ({
model,
sdkConfig: {},
})),
},
} as unknown as Config;
mockGeminiClient = new GeminiClient(mockConfigInstance);
tool = new WebSearchTool(mockConfigInstance);
+1 -3
View File
@@ -14,7 +14,6 @@ import { ToolErrorType } from './tool-error.js';
import { getErrorMessage } from '../utils/errors.js';
import { type Config } from '../config/config.js';
import { getResponseText } from '../utils/partUtils.js';
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
interface GroundingChunkWeb {
uri?: string;
@@ -81,10 +80,9 @@ class WebSearchToolInvocation extends BaseToolInvocation<
try {
const response = await geminiClient.generateContent(
{ model: 'web-search' },
[{ role: 'user', parts: [{ text: this.params.query }] }],
{ tools: [{ googleSearch: {} }] },
signal,
DEFAULT_GEMINI_FLASH_MODEL,
);
const responseText = getResponseText(response);