@google/gemini-cli-core 0.1.21 → 0.2.0-preview.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -28
- package/dist/src/code_assist/converter.d.ts +1 -0
- package/dist/src/code_assist/converter.js +1 -0
- package/dist/src/code_assist/converter.js.map +1 -1
- package/dist/src/code_assist/oauth2.d.ts +2 -0
- package/dist/src/code_assist/oauth2.js +44 -22
- package/dist/src/code_assist/oauth2.js.map +1 -1
- package/dist/src/code_assist/oauth2.test.js +99 -8
- package/dist/src/code_assist/oauth2.test.js.map +1 -1
- package/dist/src/code_assist/server.js +1 -1
- package/dist/src/code_assist/server.js.map +1 -1
- package/dist/src/code_assist/setup.js +1 -1
- package/dist/src/code_assist/setup.js.map +1 -1
- package/dist/src/code_assist/setup.test.js +14 -8
- package/dist/src/code_assist/setup.test.js.map +1 -1
- package/dist/src/config/config.d.ts +21 -2
- package/dist/src/config/config.js +36 -10
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/config.test.js +22 -0
- package/dist/src/config/config.test.js.map +1 -1
- package/dist/src/core/client.d.ts +4 -11
- package/dist/src/core/client.js +51 -30
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/client.test.js +296 -1
- package/dist/src/core/client.test.js.map +1 -1
- package/dist/src/core/contentGenerator.js +19 -9
- package/dist/src/core/contentGenerator.js.map +1 -1
- package/dist/src/core/contentGenerator.test.js +39 -15
- package/dist/src/core/contentGenerator.test.js.map +1 -1
- package/dist/src/core/coreToolScheduler.d.ts +2 -1
- package/dist/src/core/coreToolScheduler.js +26 -4
- package/dist/src/core/coreToolScheduler.js.map +1 -1
- package/dist/src/core/coreToolScheduler.test.js +230 -69
- package/dist/src/core/coreToolScheduler.test.js.map +1 -1
- package/dist/src/core/geminiChat.js +1 -1
- package/dist/src/core/geminiChat.js.map +1 -1
- package/dist/src/core/logger.d.ts +22 -1
- package/dist/src/core/logger.js +103 -17
- package/dist/src/core/logger.js.map +1 -1
- package/dist/src/core/logger.test.js +86 -20
- package/dist/src/core/logger.test.js.map +1 -1
- package/dist/src/core/loggingContentGenerator.d.ts +1 -5
- package/dist/src/core/loggingContentGenerator.js +4 -6
- package/dist/src/core/loggingContentGenerator.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.d.ts +2 -2
- package/dist/src/core/nonInteractiveToolExecutor.js +11 -3
- package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.test.js +95 -46
- package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
- package/dist/src/core/prompts.js +4 -4
- package/dist/src/core/prompts.js.map +1 -1
- package/dist/src/core/subagent.js +5 -5
- package/dist/src/core/subagent.js.map +1 -1
- package/dist/src/core/subagent.test.js +3 -3
- package/dist/src/core/subagent.test.js.map +1 -1
- package/dist/src/generated/git-commit.d.ts +7 -0
- package/dist/src/generated/git-commit.js +10 -0
- package/dist/src/generated/git-commit.js.map +1 -0
- package/dist/src/ide/constants.d.ts +6 -0
- package/dist/src/ide/constants.js +7 -0
- package/dist/src/ide/constants.js.map +1 -0
- package/dist/src/ide/detect-ide.js +8 -8
- package/dist/src/ide/detect-ide.js.map +1 -1
- package/dist/src/ide/ide-client.d.ts +9 -1
- package/dist/src/ide/ide-client.js +92 -22
- package/dist/src/ide/ide-client.js.map +1 -1
- package/dist/src/ide/ide-client.test.d.ts +6 -0
- package/dist/src/ide/ide-client.test.js +43 -0
- package/dist/src/ide/ide-client.test.js.map +1 -0
- package/dist/src/ide/ide-installer.js +22 -8
- package/dist/src/ide/ide-installer.js.map +1 -1
- package/dist/src/ide/ide-installer.test.js +6 -4
- package/dist/src/ide/ide-installer.test.js.map +1 -1
- package/dist/src/ide/ideContext.d.ts +6 -6
- package/dist/src/ide/process-utils.d.ts +19 -0
- package/dist/src/ide/process-utils.js +140 -0
- package/dist/src/ide/process-utils.js.map +1 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/oauth-provider.js +176 -58
- package/dist/src/mcp/oauth-provider.js.map +1 -1
- package/dist/src/mcp/oauth-provider.test.js +132 -62
- package/dist/src/mcp/oauth-provider.test.js.map +1 -1
- package/dist/src/mcp/oauth-utils.d.ts +3 -1
- package/dist/src/mcp/oauth-utils.js +50 -12
- package/dist/src/mcp/oauth-utils.js.map +1 -1
- package/dist/src/mcp/oauth-utils.test.js +17 -2
- package/dist/src/mcp/oauth-utils.test.js.map +1 -1
- package/dist/src/services/chatRecordingService.d.ts +150 -0
- package/dist/src/services/chatRecordingService.js +318 -0
- package/dist/src/services/chatRecordingService.js.map +1 -0
- package/dist/src/services/chatRecordingService.test.d.ts +6 -0
- package/dist/src/services/chatRecordingService.test.js +288 -0
- package/dist/src/services/chatRecordingService.test.js.map +1 -0
- package/dist/src/services/fileSystemService.d.ts +31 -0
- package/dist/src/services/fileSystemService.js +18 -0
- package/dist/src/services/fileSystemService.js.map +1 -0
- package/dist/src/services/fileSystemService.test.d.ts +6 -0
- package/dist/src/services/fileSystemService.test.js +41 -0
- package/dist/src/services/fileSystemService.test.js.map +1 -0
- package/dist/src/services/loopDetectionService.js +5 -5
- package/dist/src/services/loopDetectionService.js.map +1 -1
- package/dist/src/services/shellExecutionService.d.ts +8 -10
- package/dist/src/services/shellExecutionService.js +289 -133
- package/dist/src/services/shellExecutionService.js.map +1 -1
- package/dist/src/services/shellExecutionService.test.js +274 -30
- package/dist/src/services/shellExecutionService.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +31 -6
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +101 -121
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.d.ts +11 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +97 -36
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +6 -2
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +12 -11
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
- package/dist/src/telemetry/constants.d.ts +1 -0
- package/dist/src/telemetry/constants.js +1 -0
- package/dist/src/telemetry/constants.js.map +1 -1
- package/dist/src/telemetry/index.d.ts +2 -2
- package/dist/src/telemetry/index.js +2 -2
- package/dist/src/telemetry/index.js.map +1 -1
- package/dist/src/telemetry/integration.test.circular.js +1 -0
- package/dist/src/telemetry/integration.test.circular.js.map +1 -1
- package/dist/src/telemetry/loggers.d.ts +2 -1
- package/dist/src/telemetry/loggers.js +24 -6
- package/dist/src/telemetry/loggers.js.map +1 -1
- package/dist/src/telemetry/loggers.test.js +37 -7
- package/dist/src/telemetry/loggers.test.js.map +1 -1
- package/dist/src/telemetry/metrics.d.ts +5 -1
- package/dist/src/telemetry/metrics.js +23 -9
- package/dist/src/telemetry/metrics.js.map +1 -1
- package/dist/src/telemetry/metrics.test.js +31 -1
- package/dist/src/telemetry/metrics.test.js.map +1 -1
- package/dist/src/telemetry/sdk.js +67 -39
- package/dist/src/telemetry/sdk.js.map +1 -1
- package/dist/src/telemetry/sdk.test.d.ts +6 -0
- package/dist/src/telemetry/sdk.test.js +82 -0
- package/dist/src/telemetry/sdk.test.js.map +1 -0
- package/dist/src/telemetry/types.d.ts +9 -1
- package/dist/src/telemetry/types.js +14 -0
- package/dist/src/telemetry/types.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.d.ts +4 -0
- package/dist/src/telemetry/uiTelemetry.js +14 -1
- package/dist/src/telemetry/uiTelemetry.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.test.js +45 -9
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
- package/dist/src/test-utils/tools.d.ts +29 -8
- package/dist/src/test-utils/tools.js +79 -15
- package/dist/src/test-utils/tools.js.map +1 -1
- package/dist/src/tools/edit.d.ts +1 -1
- package/dist/src/tools/edit.js +15 -9
- package/dist/src/tools/edit.js.map +1 -1
- package/dist/src/tools/edit.test.js +11 -1
- package/dist/src/tools/edit.test.js.map +1 -1
- package/dist/src/tools/glob.d.ts +1 -1
- package/dist/src/tools/glob.js +8 -8
- package/dist/src/tools/glob.js.map +1 -1
- package/dist/src/tools/glob.test.js +20 -0
- package/dist/src/tools/glob.test.js.map +1 -1
- package/dist/src/tools/grep.d.ts +1 -1
- package/dist/src/tools/grep.js +1 -6
- package/dist/src/tools/grep.js.map +1 -1
- package/dist/src/tools/ls.d.ts +1 -1
- package/dist/src/tools/ls.js +1 -6
- package/dist/src/tools/ls.js.map +1 -1
- package/dist/src/tools/mcp-client-manager.d.ts +38 -0
- package/dist/src/tools/mcp-client-manager.js +74 -0
- package/dist/src/tools/mcp-client-manager.js.map +1 -0
- package/dist/src/tools/mcp-client-manager.test.d.ts +6 -0
- package/dist/src/tools/mcp-client-manager.test.js +39 -0
- package/dist/src/tools/mcp-client-manager.test.js.map +1 -0
- package/dist/src/tools/mcp-client.d.ts +43 -0
- package/dist/src/tools/mcp-client.js +157 -11
- package/dist/src/tools/mcp-client.js.map +1 -1
- package/dist/src/tools/mcp-client.test.js +59 -273
- package/dist/src/tools/mcp-client.test.js.map +1 -1
- package/dist/src/tools/mcp-tool.js +21 -3
- package/dist/src/tools/mcp-tool.js.map +1 -1
- package/dist/src/tools/mcp-tool.test.js +74 -17
- package/dist/src/tools/mcp-tool.test.js.map +1 -1
- package/dist/src/tools/memoryTool.d.ts +1 -1
- package/dist/src/tools/memoryTool.js +1 -6
- package/dist/src/tools/memoryTool.js.map +1 -1
- package/dist/src/tools/read-file.d.ts +1 -1
- package/dist/src/tools/read-file.js +5 -7
- package/dist/src/tools/read-file.js.map +1 -1
- package/dist/src/tools/read-file.test.js +8 -0
- package/dist/src/tools/read-file.test.js.map +1 -1
- package/dist/src/tools/read-many-files.d.ts +0 -1
- package/dist/src/tools/read-many-files.js +16 -11
- package/dist/src/tools/read-many-files.js.map +1 -1
- package/dist/src/tools/read-many-files.test.js +34 -0
- package/dist/src/tools/read-many-files.test.js.map +1 -1
- package/dist/src/tools/shell.d.ts +1 -1
- package/dist/src/tools/shell.js +35 -32
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/shell.test.js +23 -19
- package/dist/src/tools/shell.test.js.map +1 -1
- package/dist/src/tools/tool-error.d.ts +1 -0
- package/dist/src/tools/tool-error.js +1 -0
- package/dist/src/tools/tool-error.js.map +1 -1
- package/dist/src/tools/tool-registry.d.ts +8 -3
- package/dist/src/tools/tool-registry.js +58 -34
- package/dist/src/tools/tool-registry.js.map +1 -1
- package/dist/src/tools/tool-registry.test.js +9 -21
- package/dist/src/tools/tool-registry.test.js.map +1 -1
- package/dist/src/tools/tools.d.ts +17 -74
- package/dist/src/tools/tools.js +60 -104
- package/dist/src/tools/tools.js.map +1 -1
- package/dist/src/tools/tools.test.js +91 -2
- package/dist/src/tools/tools.test.js.map +1 -1
- package/dist/src/tools/web-fetch.d.ts +1 -1
- package/dist/src/tools/web-fetch.js +1 -6
- package/dist/src/tools/web-fetch.js.map +1 -1
- package/dist/src/tools/web-search.d.ts +4 -5
- package/dist/src/tools/web-search.js +47 -51
- package/dist/src/tools/web-search.js.map +1 -1
- package/dist/src/tools/web-search.test.d.ts +6 -0
- package/dist/src/tools/web-search.test.js +139 -0
- package/dist/src/tools/web-search.test.js.map +1 -0
- package/dist/src/tools/write-file.d.ts +15 -11
- package/dist/src/tools/write-file.js +133 -145
- package/dist/src/tools/write-file.js.map +1 -1
- package/dist/src/tools/write-file.test.js +82 -126
- package/dist/src/tools/write-file.test.js.map +1 -1
- package/dist/src/utils/browser.js +4 -3
- package/dist/src/utils/browser.js.map +1 -1
- package/dist/src/utils/editCorrector.js +13 -13
- package/dist/src/utils/editCorrector.js.map +1 -1
- package/dist/src/utils/editor.js +1 -1
- package/dist/src/utils/editor.js.map +1 -1
- package/dist/src/utils/editor.test.js +10 -10
- package/dist/src/utils/editor.test.js.map +1 -1
- package/dist/src/utils/environmentContext.js +2 -2
- package/dist/src/utils/environmentContext.js.map +1 -1
- package/dist/src/utils/environmentContext.test.js +3 -2
- package/dist/src/utils/environmentContext.test.js.map +1 -1
- package/dist/src/utils/fileUtils.d.ts +2 -1
- package/dist/src/utils/fileUtils.js +3 -3
- package/dist/src/utils/fileUtils.js.map +1 -1
- package/dist/src/utils/fileUtils.test.js +18 -17
- package/dist/src/utils/fileUtils.test.js.map +1 -1
- package/dist/src/utils/filesearch/crawler.d.ts +15 -0
- package/dist/src/utils/filesearch/crawler.js +50 -0
- package/dist/src/utils/filesearch/crawler.js.map +1 -0
- package/dist/src/utils/filesearch/crawler.test.d.ts +6 -0
- package/dist/src/utils/filesearch/crawler.test.js +468 -0
- package/dist/src/utils/filesearch/crawler.test.js.map +1 -0
- package/dist/src/utils/filesearch/fileSearch.d.ts +9 -53
- package/dist/src/utils/filesearch/fileSearch.js +62 -117
- package/dist/src/utils/filesearch/fileSearch.js.map +1 -1
- package/dist/src/utils/filesearch/fileSearch.test.js +95 -197
- package/dist/src/utils/filesearch/fileSearch.test.js.map +1 -1
- package/dist/src/utils/filesearch/ignore.d.ts +7 -0
- package/dist/src/utils/filesearch/ignore.js +25 -0
- package/dist/src/utils/filesearch/ignore.js.map +1 -1
- package/dist/src/utils/filesearch/ignore.test.js +89 -2
- package/dist/src/utils/filesearch/ignore.test.js.map +1 -1
- package/dist/src/utils/getPty.d.ts +19 -0
- package/dist/src/utils/getPty.js +23 -0
- package/dist/src/utils/getPty.js.map +1 -0
- package/dist/src/utils/memoryDiscovery.js +3 -3
- package/dist/src/utils/memoryDiscovery.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.test.js +3 -2
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.js +2 -6
- package/dist/src/utils/memoryImportProcessor.js.map +1 -1
- package/dist/src/utils/paths.d.ts +7 -0
- package/dist/src/utils/paths.js +15 -0
- package/dist/src/utils/paths.js.map +1 -1
- package/dist/src/utils/paths.test.js +74 -2
- package/dist/src/utils/paths.test.js.map +1 -1
- package/dist/src/utils/secure-browser-launcher.js +4 -3
- package/dist/src/utils/secure-browser-launcher.js.map +1 -1
- package/dist/src/utils/shell-utils.d.ts +39 -0
- package/dist/src/utils/shell-utils.js +72 -2
- package/dist/src/utils/shell-utils.js.map +1 -1
- package/dist/src/utils/shell-utils.test.js +132 -4
- package/dist/src/utils/shell-utils.test.js.map +1 -1
- package/dist/src/utils/systemEncoding.js +1 -1
- package/dist/src/utils/systemEncoding.js.map +1 -1
- package/dist/src/utils/systemEncoding.test.js +23 -23
- package/dist/src/utils/systemEncoding.test.js.map +1 -1
- package/dist/src/utils/user_account.js +58 -48
- package/dist/src/utils/user_account.js.map +1 -1
- package/dist/src/utils/user_account.test.js +76 -9
- package/dist/src/utils/user_account.test.js.map +1 -1
- package/dist/src/utils/workspaceContext.d.ts +22 -7
- package/dist/src/utils/workspaceContext.js +81 -55
- package/dist/src/utils/workspaceContext.js.map +1 -1
- package/dist/src/utils/workspaceContext.test.js +221 -137
- package/dist/src/utils/workspaceContext.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +20 -7
|
@@ -3,66 +3,29 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import { Type } from '@google/genai';
|
|
8
|
-
import { SchemaValidator } from '../utils/schemaValidator.js';
|
|
6
|
+
import { BaseDeclarativeTool, BaseToolInvocation, Kind, } from './tools.js';
|
|
9
7
|
import { getErrorMessage } from '../utils/errors.js';
|
|
10
8
|
import { getResponseText } from '../utils/generateContentResponseUtilities.js';
|
|
11
|
-
|
|
12
|
-
* A tool to perform web searches using Google Search via the Gemini API.
|
|
13
|
-
*/
|
|
14
|
-
export class WebSearchTool extends BaseTool {
|
|
9
|
+
class WebSearchToolInvocation extends BaseToolInvocation {
|
|
15
10
|
config;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
super(WebSearchTool.Name, 'GoogleSearch', 'Performs a web search using Google Search (via the Gemini API) and returns the results. This tool is useful for finding information on the internet based on a query.', Kind.Search, {
|
|
19
|
-
type: Type.OBJECT,
|
|
20
|
-
properties: {
|
|
21
|
-
query: {
|
|
22
|
-
type: Type.STRING,
|
|
23
|
-
description: 'The search query to find information on the web.',
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
required: ['query'],
|
|
27
|
-
});
|
|
11
|
+
constructor(config, params) {
|
|
12
|
+
super(params);
|
|
28
13
|
this.config = config;
|
|
29
14
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* @param params The parameters to validate
|
|
33
|
-
* @returns An error message string if validation fails, null if valid
|
|
34
|
-
*/
|
|
35
|
-
validateParams(params) {
|
|
36
|
-
const errors = SchemaValidator.validate(this.schema.parametersJsonSchema, params);
|
|
37
|
-
if (errors) {
|
|
38
|
-
return errors;
|
|
39
|
-
}
|
|
40
|
-
if (!params.query || params.query.trim() === '') {
|
|
41
|
-
return "The 'query' parameter cannot be empty.";
|
|
42
|
-
}
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
getDescription(params) {
|
|
46
|
-
return `Searching the web for: "${params.query}"`;
|
|
15
|
+
getDescription() {
|
|
16
|
+
return `Searching the web for: "${this.params.query}"`;
|
|
47
17
|
}
|
|
48
|
-
async execute(
|
|
49
|
-
const validationError = this.validateToolParams(params);
|
|
50
|
-
if (validationError) {
|
|
51
|
-
return {
|
|
52
|
-
llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`,
|
|
53
|
-
returnDisplay: validationError,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
18
|
+
async execute(signal) {
|
|
56
19
|
const geminiClient = this.config.getGeminiClient();
|
|
57
20
|
try {
|
|
58
|
-
const response = await geminiClient.generateContent([{ role: 'user', parts: [{ text: params.query }] }], { tools: [{ googleSearch: {} }] }, signal);
|
|
21
|
+
const response = await geminiClient.generateContent([{ role: 'user', parts: [{ text: this.params.query }] }], { tools: [{ googleSearch: {} }] }, signal);
|
|
59
22
|
const responseText = getResponseText(response);
|
|
60
23
|
const groundingMetadata = response.candidates?.[0]?.groundingMetadata;
|
|
61
24
|
const sources = groundingMetadata?.groundingChunks;
|
|
62
25
|
const groundingSupports = groundingMetadata?.groundingSupports;
|
|
63
26
|
if (!responseText || !responseText.trim()) {
|
|
64
27
|
return {
|
|
65
|
-
llmContent: `No search results or information found for query: "${params.query}"`,
|
|
28
|
+
llmContent: `No search results or information found for query: "${this.params.query}"`,
|
|
66
29
|
returnDisplay: 'No information found.',
|
|
67
30
|
};
|
|
68
31
|
}
|
|
@@ -91,24 +54,23 @@ export class WebSearchTool extends BaseTool {
|
|
|
91
54
|
insertions.sort((a, b) => b.index - a.index);
|
|
92
55
|
const responseChars = modifiedResponseText.split(''); // Use new variable
|
|
93
56
|
insertions.forEach((insertion) => {
|
|
94
|
-
// Fixed arrow function syntax
|
|
95
57
|
responseChars.splice(insertion.index, 0, insertion.marker);
|
|
96
58
|
});
|
|
97
59
|
modifiedResponseText = responseChars.join(''); // Assign back to modifiedResponseText
|
|
98
60
|
}
|
|
99
61
|
if (sourceListFormatted.length > 0) {
|
|
100
62
|
modifiedResponseText +=
|
|
101
|
-
'\n\nSources:\n' + sourceListFormatted.join('\n');
|
|
63
|
+
'\n\nSources:\n' + sourceListFormatted.join('\n');
|
|
102
64
|
}
|
|
103
65
|
}
|
|
104
66
|
return {
|
|
105
|
-
llmContent: `Web search results for "${params.query}":\n\n${modifiedResponseText}`,
|
|
106
|
-
returnDisplay: `Search results for "${params.query}" returned.`,
|
|
67
|
+
llmContent: `Web search results for "${this.params.query}":\n\n${modifiedResponseText}`,
|
|
68
|
+
returnDisplay: `Search results for "${this.params.query}" returned.`,
|
|
107
69
|
sources,
|
|
108
70
|
};
|
|
109
71
|
}
|
|
110
72
|
catch (error) {
|
|
111
|
-
const errorMessage = `Error during web search for query "${params.query}": ${getErrorMessage(error)}`;
|
|
73
|
+
const errorMessage = `Error during web search for query "${this.params.query}": ${getErrorMessage(error)}`;
|
|
112
74
|
console.error(errorMessage, error);
|
|
113
75
|
return {
|
|
114
76
|
llmContent: `Error: ${errorMessage}`,
|
|
@@ -117,4 +79,38 @@ export class WebSearchTool extends BaseTool {
|
|
|
117
79
|
}
|
|
118
80
|
}
|
|
119
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* A tool to perform web searches using Google Search via the Gemini API.
|
|
84
|
+
*/
|
|
85
|
+
export class WebSearchTool extends BaseDeclarativeTool {
|
|
86
|
+
config;
|
|
87
|
+
static Name = 'google_web_search';
|
|
88
|
+
constructor(config) {
|
|
89
|
+
super(WebSearchTool.Name, 'GoogleSearch', 'Performs a web search using Google Search (via the Gemini API) and returns the results. This tool is useful for finding information on the internet based on a query.', Kind.Search, {
|
|
90
|
+
type: 'object',
|
|
91
|
+
properties: {
|
|
92
|
+
query: {
|
|
93
|
+
type: 'string',
|
|
94
|
+
description: 'The search query to find information on the web.',
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
required: ['query'],
|
|
98
|
+
});
|
|
99
|
+
this.config = config;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Validates the parameters for the WebSearchTool.
|
|
103
|
+
* @param params The parameters to validate
|
|
104
|
+
* @returns An error message string if validation fails, null if valid
|
|
105
|
+
*/
|
|
106
|
+
validateToolParamValues(params) {
|
|
107
|
+
if (!params.query || params.query.trim() === '') {
|
|
108
|
+
return "The 'query' parameter cannot be empty.";
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
createInvocation(params) {
|
|
113
|
+
return new WebSearchToolInvocation(this.config, params);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
120
116
|
//# sourceMappingURL=web-search.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-search.js","sourceRoot":"","sources":["../../../src/tools/web-search.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,
|
|
1
|
+
{"version":3,"file":"web-search.js","sourceRoot":"","sources":["../../../src/tools/web-search.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,IAAI,GAGL,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AA4C/E,MAAM,uBAAwB,SAAQ,kBAGrC;IAEoB;IADnB,YACmB,MAAc,EAC/B,MAA2B;QAE3B,KAAK,CAAC,MAAM,CAAC,CAAC;QAHG,WAAM,GAAN,MAAM,CAAQ;IAIjC,CAAC;IAEQ,cAAc;QACrB,OAAO,2BAA2B,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC;IACzD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAAmB;QAC/B,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;QAEnD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,eAAe,CACjD,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,EACxD,EAAE,KAAK,EAAE,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,EAAE,EACjC,MAAM,CACP,CAAC;YAEF,MAAM,YAAY,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;YAC/C,MAAM,iBAAiB,GAAG,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC;YACtE,MAAM,OAAO,GAAG,iBAAiB,EAAE,eAEtB,CAAC;YACd,MAAM,iBAAiB,GAAG,iBAAiB,EAAE,iB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aAAc,SAAQ,mBAGlC;IAG8B;IAF7B,MAAM,CAAU,IAAI,GAAW,mBAAmB,CAAC;IAEnD,YAA6B,MAAc;QACzC,KAAK,CACH,aAAa,CAAC,IAAI,EAClB,cAAc,EACd,uKAAuK,EACvK,IAAI,CAAC,MAAM,EACX;YACE,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,kDAAkD;iBAChE;aACF;YACD,QAAQ,EAAE,CAAC,OAAO,CAAC;SACpB,CACF,CAAC;QAhByB,WAAM,GAAN,MAAM,CAAQ;IAiB3C,CAAC;IAED;;;;OAIG;IACgB,uBAAuB,CACxC,MAA2B;QAE3B,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAChD,OAAO,wCAAwC,CAAC;QAClD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAES,gBAAgB,CACxB,MAA2B;QAE3B,OAAO,IAAI,uBAAuB,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
7
|
+
import { WebSearchTool } from './web-search.js';
|
|
8
|
+
import { GeminiClient } from '../core/client.js';
|
|
9
|
+
// Mock GeminiClient and Config constructor
|
|
10
|
+
vi.mock('../core/client.js');
|
|
11
|
+
vi.mock('../config/config.js');
|
|
12
|
+
describe('WebSearchTool', () => {
|
|
13
|
+
const abortSignal = new AbortController().signal;
|
|
14
|
+
let mockGeminiClient;
|
|
15
|
+
let tool;
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
const mockConfigInstance = {
|
|
18
|
+
getGeminiClient: () => mockGeminiClient,
|
|
19
|
+
getProxy: () => undefined,
|
|
20
|
+
};
|
|
21
|
+
mockGeminiClient = new GeminiClient(mockConfigInstance);
|
|
22
|
+
tool = new WebSearchTool(mockConfigInstance);
|
|
23
|
+
});
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
vi.restoreAllMocks();
|
|
26
|
+
});
|
|
27
|
+
describe('build', () => {
|
|
28
|
+
it('should return an invocation for a valid query', () => {
|
|
29
|
+
const params = { query: 'test query' };
|
|
30
|
+
const invocation = tool.build(params);
|
|
31
|
+
expect(invocation).toBeDefined();
|
|
32
|
+
expect(invocation.params).toEqual(params);
|
|
33
|
+
});
|
|
34
|
+
it('should throw an error for an empty query', () => {
|
|
35
|
+
const params = { query: '' };
|
|
36
|
+
expect(() => tool.build(params)).toThrow("The 'query' parameter cannot be empty.");
|
|
37
|
+
});
|
|
38
|
+
it('should throw an error for a query with only whitespace', () => {
|
|
39
|
+
const params = { query: ' ' };
|
|
40
|
+
expect(() => tool.build(params)).toThrow("The 'query' parameter cannot be empty.");
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('getDescription', () => {
|
|
44
|
+
it('should return a description of the search', () => {
|
|
45
|
+
const params = { query: 'test query' };
|
|
46
|
+
const invocation = tool.build(params);
|
|
47
|
+
expect(invocation.getDescription()).toBe('Searching the web for: "test query"');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe('execute', () => {
|
|
51
|
+
it('should return search results for a successful query', async () => {
|
|
52
|
+
const params = { query: 'successful query' };
|
|
53
|
+
mockGeminiClient.generateContent.mockResolvedValue({
|
|
54
|
+
candidates: [
|
|
55
|
+
{
|
|
56
|
+
content: {
|
|
57
|
+
role: 'model',
|
|
58
|
+
parts: [{ text: 'Here are your results.' }],
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
const invocation = tool.build(params);
|
|
64
|
+
const result = await invocation.execute(abortSignal);
|
|
65
|
+
expect(result.llmContent).toBe('Web search results for "successful query":\n\nHere are your results.');
|
|
66
|
+
expect(result.returnDisplay).toBe('Search results for "successful query" returned.');
|
|
67
|
+
expect(result.sources).toBeUndefined();
|
|
68
|
+
});
|
|
69
|
+
it('should handle no search results found', async () => {
|
|
70
|
+
const params = { query: 'no results query' };
|
|
71
|
+
mockGeminiClient.generateContent.mockResolvedValue({
|
|
72
|
+
candidates: [
|
|
73
|
+
{
|
|
74
|
+
content: {
|
|
75
|
+
role: 'model',
|
|
76
|
+
parts: [{ text: '' }],
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
});
|
|
81
|
+
const invocation = tool.build(params);
|
|
82
|
+
const result = await invocation.execute(abortSignal);
|
|
83
|
+
expect(result.llmContent).toBe('No search results or information found for query: "no results query"');
|
|
84
|
+
expect(result.returnDisplay).toBe('No information found.');
|
|
85
|
+
});
|
|
86
|
+
it('should handle API errors gracefully', async () => {
|
|
87
|
+
const params = { query: 'error query' };
|
|
88
|
+
const testError = new Error('API Failure');
|
|
89
|
+
mockGeminiClient.generateContent.mockRejectedValue(testError);
|
|
90
|
+
const invocation = tool.build(params);
|
|
91
|
+
const result = await invocation.execute(abortSignal);
|
|
92
|
+
expect(result.llmContent).toContain('Error:');
|
|
93
|
+
expect(result.llmContent).toContain('API Failure');
|
|
94
|
+
expect(result.returnDisplay).toBe('Error performing web search.');
|
|
95
|
+
});
|
|
96
|
+
it('should correctly format results with sources and citations', async () => {
|
|
97
|
+
const params = { query: 'grounding query' };
|
|
98
|
+
mockGeminiClient.generateContent.mockResolvedValue({
|
|
99
|
+
candidates: [
|
|
100
|
+
{
|
|
101
|
+
content: {
|
|
102
|
+
role: 'model',
|
|
103
|
+
parts: [{ text: 'This is a test response.' }],
|
|
104
|
+
},
|
|
105
|
+
groundingMetadata: {
|
|
106
|
+
groundingChunks: [
|
|
107
|
+
{ web: { uri: 'https://example.com', title: 'Example Site' } },
|
|
108
|
+
{ web: { uri: 'https://google.com', title: 'Google' } },
|
|
109
|
+
],
|
|
110
|
+
groundingSupports: [
|
|
111
|
+
{
|
|
112
|
+
segment: { startIndex: 5, endIndex: 14 },
|
|
113
|
+
groundingChunkIndices: [0],
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
segment: { startIndex: 15, endIndex: 24 },
|
|
117
|
+
groundingChunkIndices: [0, 1],
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
});
|
|
124
|
+
const invocation = tool.build(params);
|
|
125
|
+
const result = await invocation.execute(abortSignal);
|
|
126
|
+
const expectedLlmContent = `Web search results for "grounding query":
|
|
127
|
+
|
|
128
|
+
This is a test[1] response.[1][2]
|
|
129
|
+
|
|
130
|
+
Sources:
|
|
131
|
+
[1] Example Site (https://example.com)
|
|
132
|
+
[2] Google (https://google.com)`;
|
|
133
|
+
expect(result.llmContent).toBe(expectedLlmContent);
|
|
134
|
+
expect(result.returnDisplay).toBe('Search results for "grounding query" returned.');
|
|
135
|
+
expect(result.sources).toHaveLength(2);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
//# sourceMappingURL=web-search.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-search.test.js","sourceRoot":"","sources":["../../../src/tools/web-search.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAQ,MAAM,QAAQ,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AAErE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,2CAA2C;AAC3C,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;AAC7B,EAAE,CAAC,IAAI,CAA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AAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YACnD,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,IAAI,CAC/B,gDAAgD,CACjD,CAAC;YACF,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { Config } from '../config/config.js';
|
|
7
|
-
import {
|
|
7
|
+
import { BaseDeclarativeTool, ToolInvocation, ToolResult } from './tools.js';
|
|
8
8
|
import { ModifiableDeclarativeTool, ModifyContext } from './modifiable-tool.js';
|
|
9
9
|
/**
|
|
10
10
|
* Parameters for the WriteFile tool
|
|
@@ -27,21 +27,25 @@ export interface WriteFileToolParams {
|
|
|
27
27
|
*/
|
|
28
28
|
ai_proposed_content?: string;
|
|
29
29
|
}
|
|
30
|
+
interface GetCorrectedFileContentResult {
|
|
31
|
+
originalContent: string;
|
|
32
|
+
correctedContent: string;
|
|
33
|
+
fileExists: boolean;
|
|
34
|
+
error?: {
|
|
35
|
+
message: string;
|
|
36
|
+
code?: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export declare function getCorrectedFileContent(config: Config, filePath: string, proposedContent: string, abortSignal: AbortSignal): Promise<GetCorrectedFileContentResult>;
|
|
30
40
|
/**
|
|
31
41
|
* Implementation of the WriteFile tool logic
|
|
32
42
|
*/
|
|
33
|
-
export declare class WriteFileTool extends
|
|
43
|
+
export declare class WriteFileTool extends BaseDeclarativeTool<WriteFileToolParams, ToolResult> implements ModifiableDeclarativeTool<WriteFileToolParams> {
|
|
34
44
|
private readonly config;
|
|
35
45
|
static readonly Name: string;
|
|
36
46
|
constructor(config: Config);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
getDescription(params: WriteFileToolParams): string;
|
|
40
|
-
/**
|
|
41
|
-
* Handles the confirmation prompt for the WriteFile tool.
|
|
42
|
-
*/
|
|
43
|
-
shouldConfirmExecute(params: WriteFileToolParams, abortSignal: AbortSignal): Promise<ToolCallConfirmationDetails | false>;
|
|
44
|
-
execute(params: WriteFileToolParams, abortSignal: AbortSignal): Promise<ToolResult>;
|
|
45
|
-
private _getCorrectedFileContent;
|
|
47
|
+
protected validateToolParamValues(params: WriteFileToolParams): string | null;
|
|
48
|
+
protected createInvocation(params: WriteFileToolParams): ToolInvocation<WriteFileToolParams, ToolResult>;
|
|
46
49
|
getModifyContext(abortSignal: AbortSignal): ModifyContext<WriteFileToolParams>;
|
|
47
50
|
}
|
|
51
|
+
export {};
|