@google/gemini-cli-core 0.1.18 → 0.1.19-nightly.250813.9d023be1

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.
Files changed (239) hide show
  1. package/README.md +199 -132
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.js +2 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/src/code_assist/converter.d.ts +3 -2
  6. package/dist/src/code_assist/converter.js +2 -2
  7. package/dist/src/code_assist/converter.js.map +1 -1
  8. package/dist/src/code_assist/converter.test.js +48 -1
  9. package/dist/src/code_assist/converter.test.js.map +1 -1
  10. package/dist/src/code_assist/oauth2.js +1 -1
  11. package/dist/src/code_assist/oauth2.js.map +1 -1
  12. package/dist/src/code_assist/server.test.js +4 -1
  13. package/dist/src/code_assist/server.test.js.map +1 -1
  14. package/dist/src/code_assist/setup.js +4 -4
  15. package/dist/src/code_assist/setup.js.map +1 -1
  16. package/dist/src/config/config.d.ts +19 -3
  17. package/dist/src/config/config.js +29 -10
  18. package/dist/src/config/config.js.map +1 -1
  19. package/dist/src/config/config.test.js +34 -0
  20. package/dist/src/config/config.test.js.map +1 -1
  21. package/dist/src/core/client.d.ts +5 -4
  22. package/dist/src/core/client.js +163 -117
  23. package/dist/src/core/client.js.map +1 -1
  24. package/dist/src/core/client.test.js +282 -37
  25. package/dist/src/core/client.test.js.map +1 -1
  26. package/dist/src/core/contentGenerator.js +3 -2
  27. package/dist/src/core/contentGenerator.js.map +1 -1
  28. package/dist/src/core/contentGenerator.test.js +3 -2
  29. package/dist/src/core/contentGenerator.test.js.map +1 -1
  30. package/dist/src/core/coreToolScheduler.d.ts +21 -8
  31. package/dist/src/core/coreToolScheduler.js +170 -61
  32. package/dist/src/core/coreToolScheduler.js.map +1 -1
  33. package/dist/src/core/coreToolScheduler.test.js +181 -37
  34. package/dist/src/core/coreToolScheduler.test.js.map +1 -1
  35. package/dist/src/core/geminiChat.d.ts +7 -6
  36. package/dist/src/core/geminiChat.js +43 -43
  37. package/dist/src/core/geminiChat.js.map +1 -1
  38. package/dist/src/core/logger.d.ts +1 -0
  39. package/dist/src/core/logger.js +18 -0
  40. package/dist/src/core/logger.js.map +1 -1
  41. package/dist/src/core/logger.test.js +29 -0
  42. package/dist/src/core/logger.test.js.map +1 -1
  43. package/dist/src/core/loggingContentGenerator.d.ts +29 -0
  44. package/dist/src/core/loggingContentGenerator.js +97 -0
  45. package/dist/src/core/loggingContentGenerator.js.map +1 -0
  46. package/dist/src/core/nonInteractiveToolExecutor.js +20 -1
  47. package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
  48. package/dist/src/core/nonInteractiveToolExecutor.test.js +7 -31
  49. package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
  50. package/dist/src/core/subagent.d.ts +230 -0
  51. package/dist/src/core/subagent.js +447 -0
  52. package/dist/src/core/subagent.js.map +1 -0
  53. package/dist/src/core/subagent.test.d.ts +6 -0
  54. package/dist/src/core/subagent.test.js +515 -0
  55. package/dist/src/core/subagent.test.js.map +1 -0
  56. package/dist/src/core/turn.js +1 -0
  57. package/dist/src/core/turn.js.map +1 -1
  58. package/dist/src/core/turn.test.js +4 -0
  59. package/dist/src/core/turn.test.js.map +1 -1
  60. package/dist/src/ide/detect-ide.d.ts +10 -2
  61. package/dist/src/ide/detect-ide.js +48 -5
  62. package/dist/src/ide/detect-ide.js.map +1 -1
  63. package/dist/src/ide/ide-client.d.ts +20 -1
  64. package/dist/src/ide/ide-client.js +145 -19
  65. package/dist/src/ide/ide-client.js.map +1 -1
  66. package/dist/src/ide/ide-installer.js +1 -26
  67. package/dist/src/ide/ide-installer.js.map +1 -1
  68. package/dist/src/ide/ide-installer.test.js +0 -4
  69. package/dist/src/ide/ide-installer.test.js.map +1 -1
  70. package/dist/src/ide/ideContext.d.ts +95 -0
  71. package/dist/src/ide/ideContext.js +45 -0
  72. package/dist/src/ide/ideContext.js.map +1 -1
  73. package/dist/src/index.d.ts +1 -1
  74. package/dist/src/index.js +1 -1
  75. package/dist/src/index.js.map +1 -1
  76. package/dist/src/mcp/google-auth-provider.js +9 -0
  77. package/dist/src/mcp/google-auth-provider.js.map +1 -1
  78. package/dist/src/mcp/google-auth-provider.test.js +45 -10
  79. package/dist/src/mcp/google-auth-provider.test.js.map +1 -1
  80. package/dist/src/mocks/msw.d.ts +6 -0
  81. package/dist/src/mocks/msw.js +8 -0
  82. package/dist/src/mocks/msw.js.map +1 -0
  83. package/dist/src/services/loopDetectionService.js +14 -11
  84. package/dist/src/services/loopDetectionService.js.map +1 -1
  85. package/dist/src/services/loopDetectionService.test.js +191 -0
  86. package/dist/src/services/loopDetectionService.test.js.map +1 -1
  87. package/dist/src/services/shellExecutionService.js +29 -9
  88. package/dist/src/services/shellExecutionService.js.map +1 -1
  89. package/dist/src/services/shellExecutionService.test.js +8 -0
  90. package/dist/src/services/shellExecutionService.test.js.map +1 -1
  91. package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +48 -6
  92. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +211 -116
  93. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
  94. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.d.ts +6 -0
  95. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +219 -0
  96. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -0
  97. package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +5 -1
  98. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +8 -0
  99. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
  100. package/dist/src/telemetry/loggers.test.circular.js +7 -2
  101. package/dist/src/telemetry/loggers.test.circular.js.map +1 -1
  102. package/dist/src/telemetry/loggers.test.js +7 -2
  103. package/dist/src/telemetry/loggers.test.js.map +1 -1
  104. package/dist/src/telemetry/metrics.d.ts +3 -2
  105. package/dist/src/telemetry/metrics.js +7 -1
  106. package/dist/src/telemetry/metrics.js.map +1 -1
  107. package/dist/src/telemetry/metrics.test.js +50 -0
  108. package/dist/src/telemetry/metrics.test.js.map +1 -1
  109. package/dist/src/telemetry/tool-call-decision.d.ts +13 -0
  110. package/dist/src/telemetry/tool-call-decision.js +29 -0
  111. package/dist/src/telemetry/tool-call-decision.js.map +1 -0
  112. package/dist/src/telemetry/types.d.ts +4 -7
  113. package/dist/src/telemetry/types.js +17 -21
  114. package/dist/src/telemetry/types.js.map +1 -1
  115. package/dist/src/telemetry/uiTelemetry.d.ts +4 -1
  116. package/dist/src/telemetry/uiTelemetry.js +3 -1
  117. package/dist/src/telemetry/uiTelemetry.js.map +1 -1
  118. package/dist/src/telemetry/uiTelemetry.test.js +13 -2
  119. package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
  120. package/dist/src/test-utils/config.d.ts +16 -0
  121. package/dist/src/test-utils/config.js +32 -0
  122. package/dist/src/test-utils/config.js.map +1 -0
  123. package/dist/src/test-utils/tools.d.ts +23 -0
  124. package/dist/src/test-utils/tools.js +41 -0
  125. package/dist/src/test-utils/tools.js.map +1 -0
  126. package/dist/src/tools/diffOptions.d.ts +2 -0
  127. package/dist/src/tools/diffOptions.js +28 -0
  128. package/dist/src/tools/diffOptions.js.map +1 -1
  129. package/dist/src/tools/diffOptions.test.d.ts +6 -0
  130. package/dist/src/tools/diffOptions.test.js +119 -0
  131. package/dist/src/tools/diffOptions.test.js.map +1 -0
  132. package/dist/src/tools/edit.d.ts +9 -33
  133. package/dist/src/tools/edit.js +142 -132
  134. package/dist/src/tools/edit.js.map +1 -1
  135. package/dist/src/tools/edit.test.js +115 -51
  136. package/dist/src/tools/edit.test.js.map +1 -1
  137. package/dist/src/tools/glob.d.ts +3 -10
  138. package/dist/src/tools/glob.js +85 -89
  139. package/dist/src/tools/glob.js.map +1 -1
  140. package/dist/src/tools/glob.test.js +22 -12
  141. package/dist/src/tools/glob.test.js.map +1 -1
  142. package/dist/src/tools/grep.d.ts +3 -35
  143. package/dist/src/tools/grep.js +111 -83
  144. package/dist/src/tools/grep.js.map +1 -1
  145. package/dist/src/tools/grep.test.js +40 -23
  146. package/dist/src/tools/grep.test.js.map +1 -1
  147. package/dist/src/tools/ls.js +8 -9
  148. package/dist/src/tools/ls.js.map +1 -1
  149. package/dist/src/tools/mcp-client.d.ts +14 -3
  150. package/dist/src/tools/mcp-client.js +82 -6
  151. package/dist/src/tools/mcp-client.js.map +1 -1
  152. package/dist/src/tools/mcp-client.test.js +340 -5
  153. package/dist/src/tools/mcp-client.test.js.map +1 -1
  154. package/dist/src/tools/mcp-tool.d.ts +3 -8
  155. package/dist/src/tools/mcp-tool.js +5 -18
  156. package/dist/src/tools/mcp-tool.js.map +1 -1
  157. package/dist/src/tools/memoryTool.d.ts +2 -2
  158. package/dist/src/tools/memoryTool.js +5 -5
  159. package/dist/src/tools/memoryTool.js.map +1 -1
  160. package/dist/src/tools/memoryTool.test.js +10 -1
  161. package/dist/src/tools/memoryTool.test.js.map +1 -1
  162. package/dist/src/tools/modifiable-tool.d.ts +8 -5
  163. package/dist/src/tools/modifiable-tool.js +4 -1
  164. package/dist/src/tools/modifiable-tool.js.map +1 -1
  165. package/dist/src/tools/modifiable-tool.test.js +3 -3
  166. package/dist/src/tools/modifiable-tool.test.js.map +1 -1
  167. package/dist/src/tools/read-file.d.ts +4 -6
  168. package/dist/src/tools/read-file.js +92 -45
  169. package/dist/src/tools/read-file.js.map +1 -1
  170. package/dist/src/tools/read-file.test.js +192 -130
  171. package/dist/src/tools/read-file.test.js.map +1 -1
  172. package/dist/src/tools/read-many-files.js +25 -20
  173. package/dist/src/tools/read-many-files.js.map +1 -1
  174. package/dist/src/tools/read-many-files.test.js +22 -11
  175. package/dist/src/tools/read-many-files.test.js.map +1 -1
  176. package/dist/src/tools/shell.js +11 -7
  177. package/dist/src/tools/shell.js.map +1 -1
  178. package/dist/src/tools/shell.test.js +21 -0
  179. package/dist/src/tools/shell.test.js.map +1 -1
  180. package/dist/src/tools/tool-error.d.ts +4 -0
  181. package/dist/src/tools/tool-error.js +4 -0
  182. package/dist/src/tools/tool-error.js.map +1 -1
  183. package/dist/src/tools/tool-registry.d.ts +12 -20
  184. package/dist/src/tools/tool-registry.js +23 -76
  185. package/dist/src/tools/tool-registry.js.map +1 -1
  186. package/dist/src/tools/tool-registry.test.js +19 -192
  187. package/dist/src/tools/tool-registry.test.js.map +1 -1
  188. package/dist/src/tools/tools.d.ts +144 -43
  189. package/dist/src/tools/tools.js +181 -11
  190. package/dist/src/tools/tools.js.map +1 -1
  191. package/dist/src/tools/tools.test.d.ts +6 -0
  192. package/dist/src/tools/tools.test.js +117 -0
  193. package/dist/src/tools/tools.test.js.map +1 -0
  194. package/dist/src/tools/web-fetch.js +3 -4
  195. package/dist/src/tools/web-fetch.js.map +1 -1
  196. package/dist/src/tools/web-search.js +1 -1
  197. package/dist/src/tools/web-search.js.map +1 -1
  198. package/dist/src/tools/write-file.d.ts +6 -2
  199. package/dist/src/tools/write-file.js +84 -20
  200. package/dist/src/tools/write-file.js.map +1 -1
  201. package/dist/src/tools/write-file.test.js +112 -8
  202. package/dist/src/tools/write-file.test.js.map +1 -1
  203. package/dist/src/utils/bfsFileSearch.test.js +28 -56
  204. package/dist/src/utils/bfsFileSearch.test.js.map +1 -1
  205. package/dist/src/utils/editCorrector.js +8 -9
  206. package/dist/src/utils/editCorrector.js.map +1 -1
  207. package/dist/src/utils/environmentContext.d.ts +21 -0
  208. package/dist/src/utils/environmentContext.js +90 -0
  209. package/dist/src/utils/environmentContext.js.map +1 -0
  210. package/dist/src/utils/environmentContext.test.d.ts +6 -0
  211. package/dist/src/utils/environmentContext.test.js +139 -0
  212. package/dist/src/utils/environmentContext.test.js.map +1 -0
  213. package/dist/src/utils/fileUtils.d.ts +7 -0
  214. package/dist/src/utils/fileUtils.js +15 -12
  215. package/dist/src/utils/fileUtils.js.map +1 -1
  216. package/dist/src/utils/fileUtils.test.js +6 -5
  217. package/dist/src/utils/fileUtils.test.js.map +1 -1
  218. package/dist/src/utils/filesearch/crawlCache.d.ts +1 -1
  219. package/dist/src/utils/filesearch/crawlCache.js +4 -1
  220. package/dist/src/utils/filesearch/crawlCache.js.map +1 -1
  221. package/dist/src/utils/filesearch/crawlCache.test.js +10 -0
  222. package/dist/src/utils/filesearch/crawlCache.test.js.map +1 -1
  223. package/dist/src/utils/filesearch/fileSearch.d.ts +2 -0
  224. package/dist/src/utils/filesearch/fileSearch.js +32 -7
  225. package/dist/src/utils/filesearch/fileSearch.js.map +1 -1
  226. package/dist/src/utils/filesearch/fileSearch.test.js +139 -0
  227. package/dist/src/utils/filesearch/fileSearch.test.js.map +1 -1
  228. package/dist/src/utils/memoryDiscovery.js +4 -1
  229. package/dist/src/utils/memoryDiscovery.js.map +1 -1
  230. package/dist/src/utils/nextSpeakerChecker.js +5 -6
  231. package/dist/src/utils/nextSpeakerChecker.js.map +1 -1
  232. package/dist/src/utils/nextSpeakerChecker.test.js +2 -2
  233. package/dist/src/utils/nextSpeakerChecker.test.js.map +1 -1
  234. package/dist/src/utils/schemaValidator.d.ts +1 -8
  235. package/dist/src/utils/schemaValidator.js +1 -32
  236. package/dist/src/utils/schemaValidator.js.map +1 -1
  237. package/dist/tsconfig.tsbuildinfo +1 -1
  238. package/package.json +3 -1
  239. package/dist/google-gemini-cli-core-0.1.17.tgz +0 -0
@@ -3,83 +3,172 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { FunctionDeclaration, PartListUnion, Schema } from '@google/genai';
6
+ import { FunctionDeclaration, PartListUnion } from '@google/genai';
7
7
  import { ToolErrorType } from './tool-error.js';
8
+ import { DiffUpdateResult } from '../ide/ideContext.js';
8
9
  /**
9
- * Interface representing the base Tool functionality
10
+ * Represents a validated and ready-to-execute tool call.
11
+ * An instance of this is created by a `ToolBuilder`.
10
12
  */
11
- export interface Tool<TParams = unknown, TResult extends ToolResult = ToolResult> {
13
+ export interface ToolInvocation<TParams extends object, TResult extends ToolResult> {
12
14
  /**
13
- * The internal name of the tool (used for API calls)
15
+ * The validated parameters for this specific invocation.
16
+ */
17
+ params: TParams;
18
+ /**
19
+ * Gets a pre-execution description of the tool operation.
20
+ * @returns A markdown string describing what the tool will do.
21
+ */
22
+ getDescription(): string;
23
+ /**
24
+ * Determines what file system paths the tool will affect.
25
+ * @returns A list of such paths.
26
+ */
27
+ toolLocations(): ToolLocation[];
28
+ /**
29
+ * Determines if the tool should prompt for confirmation before execution.
30
+ * @returns Confirmation details or false if no confirmation is needed.
31
+ */
32
+ shouldConfirmExecute(abortSignal: AbortSignal): Promise<ToolCallConfirmationDetails | false>;
33
+ /**
34
+ * Executes the tool with the validated parameters.
35
+ * @param signal AbortSignal for tool cancellation.
36
+ * @param updateOutput Optional callback to stream output.
37
+ * @returns Result of the tool execution.
38
+ */
39
+ execute(signal: AbortSignal, updateOutput?: (output: string) => void): Promise<TResult>;
40
+ }
41
+ /**
42
+ * A convenience base class for ToolInvocation.
43
+ */
44
+ export declare abstract class BaseToolInvocation<TParams extends object, TResult extends ToolResult> implements ToolInvocation<TParams, TResult> {
45
+ readonly params: TParams;
46
+ constructor(params: TParams);
47
+ abstract getDescription(): string;
48
+ toolLocations(): ToolLocation[];
49
+ shouldConfirmExecute(_abortSignal: AbortSignal): Promise<ToolCallConfirmationDetails | false>;
50
+ abstract execute(signal: AbortSignal, updateOutput?: (output: string) => void): Promise<TResult>;
51
+ }
52
+ /**
53
+ * A type alias for a tool invocation where the specific parameter and result types are not known.
54
+ */
55
+ export type AnyToolInvocation = ToolInvocation<object, ToolResult>;
56
+ /**
57
+ * An adapter that wraps the legacy `Tool` interface to make it compatible
58
+ * with the new `ToolInvocation` pattern.
59
+ */
60
+ export declare class LegacyToolInvocation<TParams extends object, TResult extends ToolResult> implements ToolInvocation<TParams, TResult> {
61
+ private readonly legacyTool;
62
+ readonly params: TParams;
63
+ constructor(legacyTool: BaseTool<TParams, TResult>, params: TParams);
64
+ getDescription(): string;
65
+ toolLocations(): ToolLocation[];
66
+ shouldConfirmExecute(abortSignal: AbortSignal): Promise<ToolCallConfirmationDetails | false>;
67
+ execute(signal: AbortSignal, updateOutput?: (output: string) => void): Promise<TResult>;
68
+ }
69
+ /**
70
+ * Interface for a tool builder that validates parameters and creates invocations.
71
+ */
72
+ export interface ToolBuilder<TParams extends object, TResult extends ToolResult> {
73
+ /**
74
+ * The internal name of the tool (used for API calls).
14
75
  */
15
76
  name: string;
16
77
  /**
17
- * The user-friendly display name of the tool
78
+ * The user-friendly display name of the tool.
18
79
  */
19
80
  displayName: string;
20
81
  /**
21
- * Description of what the tool does
82
+ * Description of what the tool does.
22
83
  */
23
84
  description: string;
24
85
  /**
25
- * The icon to display when interacting via ACP
86
+ * The icon to display when interacting via ACP.
26
87
  */
27
88
  icon: Icon;
28
89
  /**
29
- * Function declaration schema from @google/genai
90
+ * Function declaration schema from @google/genai.
30
91
  */
31
92
  schema: FunctionDeclaration;
32
93
  /**
33
- * Whether the tool's output should be rendered as markdown
94
+ * Whether the tool's output should be rendered as markdown.
34
95
  */
35
96
  isOutputMarkdown: boolean;
36
97
  /**
37
- * Whether the tool supports live (streaming) output
98
+ * Whether the tool supports live (streaming) output.
38
99
  */
39
100
  canUpdateOutput: boolean;
40
101
  /**
41
- * Validates the parameters for the tool
42
- * Should be called from both `shouldConfirmExecute` and `execute`
43
- * `shouldConfirmExecute` should return false immediately if invalid
44
- * @param params Parameters to validate
45
- * @returns An error message string if invalid, null otherwise
46
- */
47
- validateToolParams(params: TParams): string | null;
48
- /**
49
- * Gets a pre-execution description of the tool operation
50
- * @param params Parameters for the tool execution
51
- * @returns A markdown string describing what the tool will do
52
- * Optional for backward compatibility
102
+ * Validates raw parameters and builds a ready-to-execute invocation.
103
+ * @param params The raw, untrusted parameters from the model.
104
+ * @returns A valid `ToolInvocation` if successful. Throws an error if validation fails.
53
105
  */
54
- getDescription(params: TParams): string;
106
+ build(params: TParams): ToolInvocation<TParams, TResult>;
107
+ }
108
+ /**
109
+ * New base class for tools that separates validation from execution.
110
+ * New tools should extend this class.
111
+ */
112
+ export declare abstract class DeclarativeTool<TParams extends object, TResult extends ToolResult> implements ToolBuilder<TParams, TResult> {
113
+ readonly name: string;
114
+ readonly displayName: string;
115
+ readonly description: string;
116
+ readonly icon: Icon;
117
+ readonly parameterSchema: unknown;
118
+ readonly isOutputMarkdown: boolean;
119
+ readonly canUpdateOutput: boolean;
120
+ constructor(name: string, displayName: string, description: string, icon: Icon, parameterSchema: unknown, isOutputMarkdown?: boolean, canUpdateOutput?: boolean);
121
+ get schema(): FunctionDeclaration;
55
122
  /**
56
- * Determines what file system paths the tool will affect
57
- * @param params Parameters for the tool execution
58
- * @returns A list of such paths
123
+ * Validates the raw tool parameters.
124
+ * Subclasses should override this to add custom validation logic
125
+ * beyond the JSON schema check.
126
+ * @param params The raw parameters from the model.
127
+ * @returns An error message string if invalid, null otherwise.
59
128
  */
60
- toolLocations(params: TParams): ToolLocation[];
129
+ protected validateToolParams(_params: TParams): string | null;
61
130
  /**
62
- * Determines if the tool should prompt for confirmation before execution
63
- * @param params Parameters for the tool execution
64
- * @returns Whether execute should be confirmed.
131
+ * The core of the new pattern. It validates parameters and, if successful,
132
+ * returns a `ToolInvocation` object that encapsulates the logic for the
133
+ * specific, validated call.
134
+ * @param params The raw, untrusted parameters from the model.
135
+ * @returns A `ToolInvocation` instance.
65
136
  */
66
- shouldConfirmExecute(params: TParams, abortSignal: AbortSignal): Promise<ToolCallConfirmationDetails | false>;
137
+ abstract build(params: TParams): ToolInvocation<TParams, TResult>;
67
138
  /**
68
- * Executes the tool with the given parameters
69
- * @param params Parameters for the tool execution
70
- * @returns Result of the tool execution
139
+ * A convenience method that builds and executes the tool in one step.
140
+ * Throws an error if validation fails.
141
+ * @param params The raw, untrusted parameters from the model.
142
+ * @param signal AbortSignal for tool cancellation.
143
+ * @param updateOutput Optional callback to stream output.
144
+ * @returns The result of the tool execution.
71
145
  */
72
- execute(params: TParams, signal: AbortSignal, updateOutput?: (output: string) => void): Promise<TResult>;
146
+ buildAndExecute(params: TParams, signal: AbortSignal, updateOutput?: (output: string) => void): Promise<TResult>;
73
147
  }
148
+ /**
149
+ * New base class for declarative tools that separates validation from execution.
150
+ * New tools should extend this class, which provides a `build` method that
151
+ * validates parameters before deferring to a `createInvocation` method for
152
+ * the final `ToolInvocation` object instantiation.
153
+ */
154
+ export declare abstract class BaseDeclarativeTool<TParams extends object, TResult extends ToolResult> extends DeclarativeTool<TParams, TResult> {
155
+ build(params: TParams): ToolInvocation<TParams, TResult>;
156
+ protected abstract createInvocation(params: TParams): ToolInvocation<TParams, TResult>;
157
+ }
158
+ /**
159
+ * A type alias for a declarative tool where the specific parameter and result types are not known.
160
+ */
161
+ export type AnyDeclarativeTool = DeclarativeTool<object, ToolResult>;
74
162
  /**
75
163
  * Base implementation for tools with common functionality
164
+ * @deprecated Use `DeclarativeTool` for new tools.
76
165
  */
77
- export declare abstract class BaseTool<TParams = unknown, TResult extends ToolResult = ToolResult> implements Tool<TParams, TResult> {
166
+ export declare abstract class BaseTool<TParams extends object, TResult extends ToolResult = ToolResult> extends DeclarativeTool<TParams, TResult> {
78
167
  readonly name: string;
79
168
  readonly displayName: string;
80
169
  readonly description: string;
81
170
  readonly icon: Icon;
82
- readonly parameterSchema: Schema;
171
+ readonly parameterSchema: unknown;
83
172
  readonly isOutputMarkdown: boolean;
84
173
  readonly canUpdateOutput: boolean;
85
174
  /**
@@ -89,13 +178,10 @@ export declare abstract class BaseTool<TParams = unknown, TResult extends ToolRe
89
178
  * @param description Description of what the tool does
90
179
  * @param isOutputMarkdown Whether the tool's output should be rendered as markdown
91
180
  * @param canUpdateOutput Whether the tool supports live (streaming) output
92
- * @param parameterSchema Open API 3.0 Schema defining the parameters
93
- */
94
- constructor(name: string, displayName: string, description: string, icon: Icon, parameterSchema: Schema, isOutputMarkdown?: boolean, canUpdateOutput?: boolean);
95
- /**
96
- * Function declaration schema computed from name, description, and parameterSchema
181
+ * @param parameterSchema JSON Schema defining the parameters
97
182
  */
98
- get schema(): FunctionDeclaration;
183
+ constructor(name: string, displayName: string, description: string, icon: Icon, parameterSchema: unknown, isOutputMarkdown?: boolean, canUpdateOutput?: boolean);
184
+ build(params: TParams): ToolInvocation<TParams, TResult>;
99
185
  /**
100
186
  * Validates the parameters for the tool
101
187
  * This is a placeholder implementation and should be overridden
@@ -160,22 +246,37 @@ export interface ToolResult {
160
246
  type?: ToolErrorType;
161
247
  };
162
248
  }
249
+ /**
250
+ * Detects cycles in a JSON schemas due to `$ref`s.
251
+ * @param schema The root of the JSON schema.
252
+ * @returns `true` if a cycle is detected, `false` otherwise.
253
+ */
254
+ export declare function hasCycleInSchema(schema: object): boolean;
163
255
  export type ToolResultDisplay = string | FileDiff;
164
256
  export interface FileDiff {
165
257
  fileDiff: string;
166
258
  fileName: string;
167
259
  originalContent: string | null;
168
260
  newContent: string;
261
+ diffStat?: DiffStat;
262
+ }
263
+ export interface DiffStat {
264
+ ai_removed_lines: number;
265
+ ai_added_lines: number;
266
+ user_added_lines: number;
267
+ user_removed_lines: number;
169
268
  }
170
269
  export interface ToolEditConfirmationDetails {
171
270
  type: 'edit';
172
271
  title: string;
173
272
  onConfirm: (outcome: ToolConfirmationOutcome, payload?: ToolConfirmationPayload) => Promise<void>;
174
273
  fileName: string;
274
+ filePath: string;
175
275
  fileDiff: string;
176
276
  originalContent: string | null;
177
277
  newContent: string;
178
278
  isModifying?: boolean;
279
+ ideConfirmation?: Promise<DiffUpdateResult>;
179
280
  }
180
281
  export interface ToolConfirmationPayload {
181
282
  newContent: string;
@@ -3,10 +3,117 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ /**
7
+ * A convenience base class for ToolInvocation.
8
+ */
9
+ export class BaseToolInvocation {
10
+ params;
11
+ constructor(params) {
12
+ this.params = params;
13
+ }
14
+ toolLocations() {
15
+ return [];
16
+ }
17
+ shouldConfirmExecute(_abortSignal) {
18
+ return Promise.resolve(false);
19
+ }
20
+ }
21
+ /**
22
+ * An adapter that wraps the legacy `Tool` interface to make it compatible
23
+ * with the new `ToolInvocation` pattern.
24
+ */
25
+ export class LegacyToolInvocation {
26
+ legacyTool;
27
+ params;
28
+ constructor(legacyTool, params) {
29
+ this.legacyTool = legacyTool;
30
+ this.params = params;
31
+ }
32
+ getDescription() {
33
+ return this.legacyTool.getDescription(this.params);
34
+ }
35
+ toolLocations() {
36
+ return this.legacyTool.toolLocations(this.params);
37
+ }
38
+ shouldConfirmExecute(abortSignal) {
39
+ return this.legacyTool.shouldConfirmExecute(this.params, abortSignal);
40
+ }
41
+ execute(signal, updateOutput) {
42
+ return this.legacyTool.execute(this.params, signal, updateOutput);
43
+ }
44
+ }
45
+ /**
46
+ * New base class for tools that separates validation from execution.
47
+ * New tools should extend this class.
48
+ */
49
+ export class DeclarativeTool {
50
+ name;
51
+ displayName;
52
+ description;
53
+ icon;
54
+ parameterSchema;
55
+ isOutputMarkdown;
56
+ canUpdateOutput;
57
+ constructor(name, displayName, description, icon, parameterSchema, isOutputMarkdown = true, canUpdateOutput = false) {
58
+ this.name = name;
59
+ this.displayName = displayName;
60
+ this.description = description;
61
+ this.icon = icon;
62
+ this.parameterSchema = parameterSchema;
63
+ this.isOutputMarkdown = isOutputMarkdown;
64
+ this.canUpdateOutput = canUpdateOutput;
65
+ }
66
+ get schema() {
67
+ return {
68
+ name: this.name,
69
+ description: this.description,
70
+ parametersJsonSchema: this.parameterSchema,
71
+ };
72
+ }
73
+ /**
74
+ * Validates the raw tool parameters.
75
+ * Subclasses should override this to add custom validation logic
76
+ * beyond the JSON schema check.
77
+ * @param params The raw parameters from the model.
78
+ * @returns An error message string if invalid, null otherwise.
79
+ */
80
+ validateToolParams(_params) {
81
+ // Base implementation can be extended by subclasses.
82
+ return null;
83
+ }
84
+ /**
85
+ * A convenience method that builds and executes the tool in one step.
86
+ * Throws an error if validation fails.
87
+ * @param params The raw, untrusted parameters from the model.
88
+ * @param signal AbortSignal for tool cancellation.
89
+ * @param updateOutput Optional callback to stream output.
90
+ * @returns The result of the tool execution.
91
+ */
92
+ async buildAndExecute(params, signal, updateOutput) {
93
+ const invocation = this.build(params);
94
+ return invocation.execute(signal, updateOutput);
95
+ }
96
+ }
97
+ /**
98
+ * New base class for declarative tools that separates validation from execution.
99
+ * New tools should extend this class, which provides a `build` method that
100
+ * validates parameters before deferring to a `createInvocation` method for
101
+ * the final `ToolInvocation` object instantiation.
102
+ */
103
+ export class BaseDeclarativeTool extends DeclarativeTool {
104
+ build(params) {
105
+ const validationError = this.validateToolParams(params);
106
+ if (validationError) {
107
+ throw new Error(validationError);
108
+ }
109
+ return this.createInvocation(params);
110
+ }
111
+ }
6
112
  /**
7
113
  * Base implementation for tools with common functionality
114
+ * @deprecated Use `DeclarativeTool` for new tools.
8
115
  */
9
- export class BaseTool {
116
+ export class BaseTool extends DeclarativeTool {
10
117
  name;
11
118
  displayName;
12
119
  description;
@@ -21,9 +128,10 @@ export class BaseTool {
21
128
  * @param description Description of what the tool does
22
129
  * @param isOutputMarkdown Whether the tool's output should be rendered as markdown
23
130
  * @param canUpdateOutput Whether the tool supports live (streaming) output
24
- * @param parameterSchema Open API 3.0 Schema defining the parameters
131
+ * @param parameterSchema JSON Schema defining the parameters
25
132
  */
26
133
  constructor(name, displayName, description, icon, parameterSchema, isOutputMarkdown = true, canUpdateOutput = false) {
134
+ super(name, displayName, description, icon, parameterSchema, isOutputMarkdown, canUpdateOutput);
27
135
  this.name = name;
28
136
  this.displayName = displayName;
29
137
  this.description = description;
@@ -32,15 +140,12 @@ export class BaseTool {
32
140
  this.isOutputMarkdown = isOutputMarkdown;
33
141
  this.canUpdateOutput = canUpdateOutput;
34
142
  }
35
- /**
36
- * Function declaration schema computed from name, description, and parameterSchema
37
- */
38
- get schema() {
39
- return {
40
- name: this.name,
41
- description: this.description,
42
- parameters: this.parameterSchema,
43
- };
143
+ build(params) {
144
+ const validationError = this.validateToolParams(params);
145
+ if (validationError) {
146
+ throw new Error(validationError);
147
+ }
148
+ return new LegacyToolInvocation(this, params);
44
149
  }
45
150
  /**
46
151
  * Validates the parameters for the tool
@@ -88,6 +193,71 @@ export class BaseTool {
88
193
  return [];
89
194
  }
90
195
  }
196
+ /**
197
+ * Detects cycles in a JSON schemas due to `$ref`s.
198
+ * @param schema The root of the JSON schema.
199
+ * @returns `true` if a cycle is detected, `false` otherwise.
200
+ */
201
+ export function hasCycleInSchema(schema) {
202
+ function resolveRef(ref) {
203
+ if (!ref.startsWith('#/')) {
204
+ return null;
205
+ }
206
+ const path = ref.substring(2).split('/');
207
+ let current = schema;
208
+ for (const segment of path) {
209
+ if (typeof current !== 'object' ||
210
+ current === null ||
211
+ !Object.prototype.hasOwnProperty.call(current, segment)) {
212
+ return null;
213
+ }
214
+ current = current[segment];
215
+ }
216
+ return current;
217
+ }
218
+ function traverse(node, visitedRefs, pathRefs) {
219
+ if (typeof node !== 'object' || node === null) {
220
+ return false;
221
+ }
222
+ if (Array.isArray(node)) {
223
+ for (const item of node) {
224
+ if (traverse(item, visitedRefs, pathRefs)) {
225
+ return true;
226
+ }
227
+ }
228
+ return false;
229
+ }
230
+ if ('$ref' in node && typeof node.$ref === 'string') {
231
+ const ref = node.$ref;
232
+ if (ref === '#/' || pathRefs.has(ref)) {
233
+ // A ref to just '#/' is always a cycle.
234
+ return true; // Cycle detected!
235
+ }
236
+ if (visitedRefs.has(ref)) {
237
+ return false; // Bail early, we have checked this ref before.
238
+ }
239
+ const resolvedNode = resolveRef(ref);
240
+ if (resolvedNode) {
241
+ // Add it to both visited and the current path
242
+ visitedRefs.add(ref);
243
+ pathRefs.add(ref);
244
+ const hasCycle = traverse(resolvedNode, visitedRefs, pathRefs);
245
+ pathRefs.delete(ref); // Backtrack, leaving it in visited
246
+ return hasCycle;
247
+ }
248
+ }
249
+ // Crawl all the properties of node
250
+ for (const key in node) {
251
+ if (Object.prototype.hasOwnProperty.call(node, key)) {
252
+ if (traverse(node[key], visitedRefs, pathRefs)) {
253
+ return true;
254
+ }
255
+ }
256
+ }
257
+ return false;
258
+ }
259
+ return traverse(schema, new Set(), new Set());
260
+ }
91
261
  export var ToolConfirmationOutcome;
92
262
  (function (ToolConfirmationOutcome) {
93
263
  ToolConfirmationOutcome["ProceedOnce"] = "proceed_once";
@@ -1 +1 @@
1
- {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/tools/tools.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA6FH;;GAEG;AACH,MAAM,OAAgB,QAAQ;IAejB;IACA;IACA;IACA;IACA;IACA;IACA;IAhBX;;;;;;;;OAQG;IACH,YACW,IAAY,EACZ,WAAmB,EACnB,WAAmB,EACnB,IAAU,EACV,eAAuB,EACvB,mBAA4B,IAAI,EAChC,kBAA2B,KAAK;QANhC,SAAI,GAAJ,IAAI,CAAQ;QACZ,gBAAW,GAAX,WAAW,CAAQ;QACnB,gBAAW,GAAX,WAAW,CAAQ;QACnB,SAAI,GAAJ,IAAI,CAAM;QACV,oBAAe,GAAf,eAAe,CAAQ;QACvB,qBAAgB,GAAhB,gBAAgB,CAAgB;QAChC,oBAAe,GAAf,eAAe,CAAiB;IACxC,CAAC;IAEJ;;OAEG;IACH,IAAI,MAAM;QACR,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,UAAU,EAAE,IAAI,CAAC,eAAe;SACjC,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACH,6DAA6D;IAC7D,kBAAkB,CAAC,MAAe;QAChC,6DAA6D;QAC7D,sEAAsE;QACtE,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,cAAc,CAAC,MAAe;QAC5B,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACH,oBAAoB;IAClB,6DAA6D;IAC7D,MAAe;IACf,6DAA6D;IAC7D,WAAwB;QAExB,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,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AQ,CACL,IAAgC,CAAC,GAAG,CAAC,EACtC,WAAW,EACX,QAAQ,CACT,EACD,CAAC;oBACD,OAAO,IAAI,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,QAAQ,CAAC,MAAM,EAAE,IAAI,GAAG,EAAU,EAAE,IAAI,GAAG,EAAU,CAAC,CAAC;AAChE,CAAC;AAwED,MAAM,CAAN,IAAY,uBAOX;AAPD,WAAY,uBAAuB;IACjC,uDAA4B,CAAA;IAC5B,2DAAgC,CAAA;IAChC,wEAA6C,CAAA;IAC7C,oEAAyC,CAAA;IACzC,kEAAuC,CAAA;IACvC,4CAAiB,CAAA;AACnB,CAAC,EAPW,uBAAuB,KAAvB,uBAAuB,QAOlC;AAED,MAAM,CAAN,IAAY,IASX;AATD,WAAY,IAAI;IACd,iCAAyB,CAAA;IACzB,yBAAiB,CAAA;IACjB,uBAAe,CAAA;IACf,yBAAiB,CAAA;IACjB,+BAAuB,CAAA;IACvB,yBAAiB,CAAA;IACjB,uBAAe,CAAA;IACf,6BAAqB,CAAA;AACvB,CAAC,EATW,IAAI,KAAJ,IAAI,QASf"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export {};
@@ -0,0 +1,117 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { describe, it, expect } from 'vitest';
7
+ import { hasCycleInSchema } from './tools.js'; // Added getStringifiedResultForDisplay
8
+ describe('hasCycleInSchema', () => {
9
+ it('should detect a simple direct cycle', () => {
10
+ const schema = {
11
+ properties: {
12
+ data: {
13
+ $ref: '#/properties/data',
14
+ },
15
+ },
16
+ };
17
+ expect(hasCycleInSchema(schema)).toBe(true);
18
+ });
19
+ it('should detect a cycle from object properties referencing parent properties', () => {
20
+ const schema = {
21
+ type: 'object',
22
+ properties: {
23
+ data: {
24
+ type: 'object',
25
+ properties: {
26
+ child: { $ref: '#/properties/data' },
27
+ },
28
+ },
29
+ },
30
+ };
31
+ expect(hasCycleInSchema(schema)).toBe(true);
32
+ });
33
+ it('should detect a cycle from array items referencing parent properties', () => {
34
+ const schema = {
35
+ type: 'object',
36
+ properties: {
37
+ data: {
38
+ type: 'array',
39
+ items: {
40
+ type: 'object',
41
+ properties: {
42
+ child: { $ref: '#/properties/data/items' },
43
+ },
44
+ },
45
+ },
46
+ },
47
+ };
48
+ expect(hasCycleInSchema(schema)).toBe(true);
49
+ });
50
+ it('should detect a cycle between sibling properties', () => {
51
+ const schema = {
52
+ type: 'object',
53
+ properties: {
54
+ a: {
55
+ type: 'object',
56
+ properties: {
57
+ child: { $ref: '#/properties/b' },
58
+ },
59
+ },
60
+ b: {
61
+ type: 'object',
62
+ properties: {
63
+ child: { $ref: '#/properties/a' },
64
+ },
65
+ },
66
+ },
67
+ };
68
+ expect(hasCycleInSchema(schema)).toBe(true);
69
+ });
70
+ it('should not detect a cycle in a valid schema', () => {
71
+ const schema = {
72
+ type: 'object',
73
+ properties: {
74
+ name: { type: 'string' },
75
+ address: { $ref: '#/definitions/address' },
76
+ },
77
+ definitions: {
78
+ address: {
79
+ type: 'object',
80
+ properties: {
81
+ street: { type: 'string' },
82
+ city: { type: 'string' },
83
+ },
84
+ },
85
+ },
86
+ };
87
+ expect(hasCycleInSchema(schema)).toBe(false);
88
+ });
89
+ it('should handle non-cyclic sibling refs', () => {
90
+ const schema = {
91
+ properties: {
92
+ a: { $ref: '#/definitions/stringDef' },
93
+ b: { $ref: '#/definitions/stringDef' },
94
+ },
95
+ definitions: {
96
+ stringDef: { type: 'string' },
97
+ },
98
+ };
99
+ expect(hasCycleInSchema(schema)).toBe(false);
100
+ });
101
+ it('should handle nested but not cyclic refs', () => {
102
+ const schema = {
103
+ properties: {
104
+ a: { $ref: '#/definitions/defA' },
105
+ },
106
+ definitions: {
107
+ defA: { properties: { b: { $ref: '#/definitions/defB' } } },
108
+ defB: { type: 'string' },
109
+ },
110
+ };
111
+ expect(hasCycleInSchema(schema)).toBe(false);
112
+ });
113
+ it('should return false for an empty schema', () => {
114
+ expect(hasCycleInSchema({})).toBe(false);
115
+ });
116
+ });
117
+ //# sourceMappingURL=tools.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.test.js","sourceRoot":"","sources":["../../../src/tools/tools.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC,CAAC,uCAAuC;AAEtF,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,MAAM,GAAG;YACb,UAAU,EAAE;gBACV,IAAI,EAAE;oBACJ,IAAI,EAAE,mBAAmB;iBAC1B;aACF;SACF,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4EAA4E,EAAE,GAAG,EAAE;QACpF,MAAM,MAAM,GAAG;YACb,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE;wBACV,KAAK,EAAE,EAAE,IAAI,EAAE,mBAAmB,EAAE;qBACrC;iBACF;aACF;SACF,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sEAAsE,EAAE,GAAG,EAAE;QAC9E,MAAM,MAAM,GAAG;YACb,IAAI,EAAE,QAAQ;YAC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import { Type } from '@google/genai';
9
8
  import { getErrorMessage } from '../utils/errors.js';
10
9
  import { ApprovalMode } from '../config/config.js';
11
10
  import { getResponseText } from '../utils/generateContentResponseUtilities.js';
@@ -30,11 +29,11 @@ export class WebFetchTool extends BaseTool {
30
29
  properties: {
31
30
  prompt: {
32
31
  description: 'A comprehensive prompt that includes the URL(s) (up to 20) to fetch and specific instructions on how to process their content (e.g., "Summarize https://example.com/article and extract key points from https://another.com/data"). Must contain as least one URL starting with http:// or https://.',
33
- type: Type.STRING,
32
+ type: 'string',
34
33
  },
35
34
  },
36
35
  required: ['prompt'],
37
- type: Type.OBJECT,
36
+ type: 'object',
38
37
  });
39
38
  this.config = config;
40
39
  const proxy = config.getProxy();
@@ -96,7 +95,7 @@ ${textContent}
96
95
  }
97
96
  }
98
97
  validateParams(params) {
99
- const errors = SchemaValidator.validate(this.schema.parameters, params);
98
+ const errors = SchemaValidator.validate(this.schema.parametersJsonSchema, params);
100
99
  if (errors) {
101
100
  return errors;
102
101
  }