@google/gemini-cli-core 0.1.20 → 0.1.22
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 +27 -29
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- 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 +1 -0
- package/dist/src/code_assist/oauth2.js +37 -20
- package/dist/src/code_assist/oauth2.js.map +1 -1
- package/dist/src/code_assist/oauth2.test.js +51 -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 +47 -16
- package/dist/src/code_assist/setup.js.map +1 -1
- package/dist/src/code_assist/setup.test.js +114 -8
- package/dist/src/code_assist/setup.test.js.map +1 -1
- package/dist/src/config/config.d.ts +8 -3
- package/dist/src/config/config.js +25 -12
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/config.test.js +83 -1
- package/dist/src/config/config.test.js.map +1 -1
- package/dist/src/core/client.d.ts +7 -12
- package/dist/src/core/client.js +67 -30
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/client.test.js +354 -0
- package/dist/src/core/client.test.js.map +1 -1
- package/dist/src/core/contentGenerator.js +19 -11
- 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.js +6 -2
- package/dist/src/core/coreToolScheduler.js.map +1 -1
- package/dist/src/core/coreToolScheduler.test.js +46 -65
- package/dist/src/core/coreToolScheduler.test.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/nonInteractiveToolExecutor.js +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.test.js +79 -36
- 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/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.d.ts +2 -0
- package/dist/src/ide/detect-ide.js +22 -6
- package/dist/src/ide/detect-ide.js.map +1 -1
- package/dist/src/ide/detect-ide.test.d.ts +6 -0
- package/dist/src/ide/detect-ide.test.js +65 -0
- package/dist/src/ide/detect-ide.test.js.map +1 -0
- package/dist/src/ide/ide-client.d.ts +5 -1
- package/dist/src/ide/ide-client.js +57 -21
- 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 +5 -4
- package/dist/src/ide/ide-installer.js.map +1 -1
- package/dist/src/ide/process-utils.d.ts +14 -0
- package/dist/src/ide/process-utils.js +57 -0
- package/dist/src/ide/process-utils.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/oauth-provider.d.ts +0 -1
- package/dist/src/mcp/oauth-provider.js +176 -59
- 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/loopDetectionService.js +5 -5
- package/dist/src/services/loopDetectionService.js.map +1 -1
- package/dist/src/services/shellExecutionService.test.js +13 -3
- package/dist/src/services/shellExecutionService.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +23 -4
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +84 -33
- 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 +143 -29
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +8 -2
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +17 -9
- 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 +3 -1
- package/dist/src/telemetry/loggers.js +37 -4
- package/dist/src/telemetry/loggers.js.map +1 -1
- package/dist/src/telemetry/loggers.test.js +27 -2
- package/dist/src/telemetry/loggers.test.js.map +1 -1
- package/dist/src/telemetry/metrics.d.ts +4 -0
- package/dist/src/telemetry/metrics.js +21 -8
- 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 +64 -36
- 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 +40 -14
- package/dist/src/telemetry/types.js +46 -23
- package/dist/src/telemetry/types.js.map +1 -1
- package/dist/src/test-utils/tools.d.ts +21 -6
- package/dist/src/test-utils/tools.js +78 -13
- package/dist/src/test-utils/tools.js.map +1 -1
- package/dist/src/tools/edit.js +2 -2
- package/dist/src/tools/edit.js.map +1 -1
- package/dist/src/tools/glob.js +2 -2
- package/dist/src/tools/glob.js.map +1 -1
- package/dist/src/tools/grep.js +2 -2
- package/dist/src/tools/grep.js.map +1 -1
- package/dist/src/tools/ls.d.ts +3 -22
- package/dist/src/tools/ls.js +81 -77
- package/dist/src/tools/ls.js.map +1 -1
- package/dist/src/tools/ls.test.js +62 -34
- package/dist/src/tools/ls.test.js.map +1 -1
- package/dist/src/tools/mcp-client.js +40 -10
- package/dist/src/tools/mcp-client.js.map +1 -1
- package/dist/src/tools/mcp-client.test.js +31 -1
- package/dist/src/tools/mcp-client.test.js.map +1 -1
- package/dist/src/tools/mcp-tool.d.ts +3 -5
- package/dist/src/tools/mcp-tool.js +62 -21
- package/dist/src/tools/mcp-tool.js.map +1 -1
- package/dist/src/tools/mcp-tool.test.js +110 -51
- package/dist/src/tools/mcp-tool.test.js.map +1 -1
- package/dist/src/tools/memoryTool.d.ts +9 -13
- package/dist/src/tools/memoryTool.js +124 -117
- package/dist/src/tools/memoryTool.js.map +1 -1
- package/dist/src/tools/memoryTool.test.js +28 -17
- package/dist/src/tools/memoryTool.test.js.map +1 -1
- package/dist/src/tools/read-file.js +2 -2
- package/dist/src/tools/read-file.js.map +1 -1
- package/dist/src/tools/read-many-files.d.ts +4 -5
- package/dist/src/tools/read-many-files.js +112 -100
- package/dist/src/tools/read-many-files.js.map +1 -1
- package/dist/src/tools/read-many-files.test.js +60 -37
- package/dist/src/tools/read-many-files.test.js.map +1 -1
- package/dist/src/tools/shell.d.ts +4 -6
- package/dist/src/tools/shell.js +116 -105
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/shell.test.js +52 -46
- 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 +56 -30
- package/dist/src/tools/tool-registry.js.map +1 -1
- package/dist/src/tools/tools.d.ts +28 -86
- package/dist/src/tools/tools.js +67 -122
- 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 +4 -7
- package/dist/src/tools/web-fetch.js +62 -62
- package/dist/src/tools/web-fetch.js.map +1 -1
- package/dist/src/tools/web-fetch.test.js +8 -4
- package/dist/src/tools/web-fetch.test.js.map +1 -1
- package/dist/src/tools/web-search.d.ts +4 -5
- package/dist/src/tools/web-search.js +51 -50
- 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 -10
- package/dist/src/tools/write-file.js +133 -141
- package/dist/src/tools/write-file.js.map +1 -1
- package/dist/src/tools/write-file.test.js +57 -88
- 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/errorParsing.d.ts +8 -0
- package/dist/src/utils/errorParsing.js +93 -0
- package/dist/src/utils/errorParsing.js.map +1 -0
- package/dist/src/utils/errorParsing.test.d.ts +6 -0
- package/dist/src/utils/errorParsing.test.js +172 -0
- package/dist/src/utils/errorParsing.test.js.map +1 -0
- 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 +63 -118
- 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/filesearch/result-cache.d.ts +1 -2
- package/dist/src/utils/filesearch/result-cache.js +1 -3
- package/dist/src/utils/filesearch/result-cache.js.map +1 -1
- package/dist/src/utils/filesearch/result-cache.test.js +3 -4
- package/dist/src/utils/filesearch/result-cache.test.js.map +1 -1
- 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 +3 -7
- package/dist/src/utils/memoryImportProcessor.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.test.js +17 -20
- package/dist/src/utils/memoryImportProcessor.test.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/quotaErrorDetection.d.ts +1 -5
- package/dist/src/utils/quotaErrorDetection.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/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 +5 -2
- package/dist/src/core/modelCheck.d.ts +0 -14
- package/dist/src/core/modelCheck.js +0 -62
- package/dist/src/core/modelCheck.js.map +0 -1
|
@@ -53,19 +53,6 @@ export declare abstract class BaseToolInvocation<TParams extends object, TResult
|
|
|
53
53
|
* A type alias for a tool invocation where the specific parameter and result types are not known.
|
|
54
54
|
*/
|
|
55
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
56
|
/**
|
|
70
57
|
* Interface for a tool builder that validates parameters and creates invocations.
|
|
71
58
|
*/
|
|
@@ -83,9 +70,9 @@ export interface ToolBuilder<TParams extends object, TResult extends ToolResult>
|
|
|
83
70
|
*/
|
|
84
71
|
description: string;
|
|
85
72
|
/**
|
|
86
|
-
* The
|
|
73
|
+
* The kind of tool for categorization and permissions
|
|
87
74
|
*/
|
|
88
|
-
|
|
75
|
+
kind: Kind;
|
|
89
76
|
/**
|
|
90
77
|
* Function declaration schema from @google/genai.
|
|
91
78
|
*/
|
|
@@ -113,11 +100,11 @@ export declare abstract class DeclarativeTool<TParams extends object, TResult ex
|
|
|
113
100
|
readonly name: string;
|
|
114
101
|
readonly displayName: string;
|
|
115
102
|
readonly description: string;
|
|
116
|
-
readonly
|
|
103
|
+
readonly kind: Kind;
|
|
117
104
|
readonly parameterSchema: unknown;
|
|
118
105
|
readonly isOutputMarkdown: boolean;
|
|
119
106
|
readonly canUpdateOutput: boolean;
|
|
120
|
-
constructor(name: string, displayName: string, description: string,
|
|
107
|
+
constructor(name: string, displayName: string, description: string, kind: Kind, parameterSchema: unknown, isOutputMarkdown?: boolean, canUpdateOutput?: boolean);
|
|
121
108
|
get schema(): FunctionDeclaration;
|
|
122
109
|
/**
|
|
123
110
|
* Validates the raw tool parameters.
|
|
@@ -144,6 +131,20 @@ export declare abstract class DeclarativeTool<TParams extends object, TResult ex
|
|
|
144
131
|
* @returns The result of the tool execution.
|
|
145
132
|
*/
|
|
146
133
|
buildAndExecute(params: TParams, signal: AbortSignal, updateOutput?: (output: string) => void): Promise<TResult>;
|
|
134
|
+
/**
|
|
135
|
+
* Similar to `build` but never throws.
|
|
136
|
+
* @param params The raw, untrusted parameters from the model.
|
|
137
|
+
* @returns A `ToolInvocation` instance.
|
|
138
|
+
*/
|
|
139
|
+
private silentBuild;
|
|
140
|
+
/**
|
|
141
|
+
* A convenience method that builds and executes the tool in one step.
|
|
142
|
+
* Never throws.
|
|
143
|
+
* @param params The raw, untrusted parameters from the model.
|
|
144
|
+
* @params abortSignal a signal to abort.
|
|
145
|
+
* @returns The result of the tool execution.
|
|
146
|
+
*/
|
|
147
|
+
validateBuildAndExecute(params: TParams, abortSignal: AbortSignal): Promise<ToolResult>;
|
|
147
148
|
}
|
|
148
149
|
/**
|
|
149
150
|
* New base class for declarative tools that separates validation from execution.
|
|
@@ -159,66 +160,6 @@ export declare abstract class BaseDeclarativeTool<TParams extends object, TResul
|
|
|
159
160
|
* A type alias for a declarative tool where the specific parameter and result types are not known.
|
|
160
161
|
*/
|
|
161
162
|
export type AnyDeclarativeTool = DeclarativeTool<object, ToolResult>;
|
|
162
|
-
/**
|
|
163
|
-
* Base implementation for tools with common functionality
|
|
164
|
-
* @deprecated Use `DeclarativeTool` for new tools.
|
|
165
|
-
*/
|
|
166
|
-
export declare abstract class BaseTool<TParams extends object, TResult extends ToolResult = ToolResult> extends DeclarativeTool<TParams, TResult> {
|
|
167
|
-
readonly name: string;
|
|
168
|
-
readonly displayName: string;
|
|
169
|
-
readonly description: string;
|
|
170
|
-
readonly icon: Icon;
|
|
171
|
-
readonly parameterSchema: unknown;
|
|
172
|
-
readonly isOutputMarkdown: boolean;
|
|
173
|
-
readonly canUpdateOutput: boolean;
|
|
174
|
-
/**
|
|
175
|
-
* Creates a new instance of BaseTool
|
|
176
|
-
* @param name Internal name of the tool (used for API calls)
|
|
177
|
-
* @param displayName User-friendly display name of the tool
|
|
178
|
-
* @param description Description of what the tool does
|
|
179
|
-
* @param isOutputMarkdown Whether the tool's output should be rendered as markdown
|
|
180
|
-
* @param canUpdateOutput Whether the tool supports live (streaming) output
|
|
181
|
-
* @param parameterSchema JSON Schema defining the parameters
|
|
182
|
-
*/
|
|
183
|
-
constructor(name: string, displayName: string, description: string, icon: Icon, parameterSchema: unknown, isOutputMarkdown?: boolean, canUpdateOutput?: boolean);
|
|
184
|
-
build(params: TParams): ToolInvocation<TParams, TResult>;
|
|
185
|
-
/**
|
|
186
|
-
* Validates the parameters for the tool
|
|
187
|
-
* This is a placeholder implementation and should be overridden
|
|
188
|
-
* Should be called from both `shouldConfirmExecute` and `execute`
|
|
189
|
-
* `shouldConfirmExecute` should return false immediately if invalid
|
|
190
|
-
* @param params Parameters to validate
|
|
191
|
-
* @returns An error message string if invalid, null otherwise
|
|
192
|
-
*/
|
|
193
|
-
validateToolParams(params: TParams): string | null;
|
|
194
|
-
/**
|
|
195
|
-
* Gets a pre-execution description of the tool operation
|
|
196
|
-
* Default implementation that should be overridden by derived classes
|
|
197
|
-
* @param params Parameters for the tool execution
|
|
198
|
-
* @returns A markdown string describing what the tool will do
|
|
199
|
-
*/
|
|
200
|
-
getDescription(params: TParams): string;
|
|
201
|
-
/**
|
|
202
|
-
* Determines if the tool should prompt for confirmation before execution
|
|
203
|
-
* @param params Parameters for the tool execution
|
|
204
|
-
* @returns Whether or not execute should be confirmed by the user.
|
|
205
|
-
*/
|
|
206
|
-
shouldConfirmExecute(params: TParams, abortSignal: AbortSignal): Promise<ToolCallConfirmationDetails | false>;
|
|
207
|
-
/**
|
|
208
|
-
* Determines what file system paths the tool will affect
|
|
209
|
-
* @param params Parameters for the tool execution
|
|
210
|
-
* @returns A list of such paths
|
|
211
|
-
*/
|
|
212
|
-
toolLocations(params: TParams): ToolLocation[];
|
|
213
|
-
/**
|
|
214
|
-
* Abstract method to execute the tool with the given parameters
|
|
215
|
-
* Must be implemented by derived classes
|
|
216
|
-
* @param params Parameters for the tool execution
|
|
217
|
-
* @param signal AbortSignal for tool cancellation
|
|
218
|
-
* @returns Result of the tool execution
|
|
219
|
-
*/
|
|
220
|
-
abstract execute(params: TParams, signal: AbortSignal, updateOutput?: (output: string) => void): Promise<TResult>;
|
|
221
|
-
}
|
|
222
163
|
export interface ToolResult {
|
|
223
164
|
/**
|
|
224
165
|
* A short, one-line summary of the tool's action and result.
|
|
@@ -312,15 +253,16 @@ export declare enum ToolConfirmationOutcome {
|
|
|
312
253
|
ModifyWithEditor = "modify_with_editor",
|
|
313
254
|
Cancel = "cancel"
|
|
314
255
|
}
|
|
315
|
-
export declare enum
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
256
|
+
export declare enum Kind {
|
|
257
|
+
Read = "read",
|
|
258
|
+
Edit = "edit",
|
|
259
|
+
Delete = "delete",
|
|
260
|
+
Move = "move",
|
|
261
|
+
Search = "search",
|
|
262
|
+
Execute = "execute",
|
|
263
|
+
Think = "think",
|
|
264
|
+
Fetch = "fetch",
|
|
265
|
+
Other = "other"
|
|
324
266
|
}
|
|
325
267
|
export interface ToolLocation {
|
|
326
268
|
path: string;
|
package/dist/src/tools/tools.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { ToolErrorType } from './tool-error.js';
|
|
6
7
|
/**
|
|
7
8
|
* A convenience base class for ToolInvocation.
|
|
8
9
|
*/
|
|
@@ -18,30 +19,6 @@ export class BaseToolInvocation {
|
|
|
18
19
|
return Promise.resolve(false);
|
|
19
20
|
}
|
|
20
21
|
}
|
|
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
22
|
/**
|
|
46
23
|
* New base class for tools that separates validation from execution.
|
|
47
24
|
* New tools should extend this class.
|
|
@@ -50,15 +27,15 @@ export class DeclarativeTool {
|
|
|
50
27
|
name;
|
|
51
28
|
displayName;
|
|
52
29
|
description;
|
|
53
|
-
|
|
30
|
+
kind;
|
|
54
31
|
parameterSchema;
|
|
55
32
|
isOutputMarkdown;
|
|
56
33
|
canUpdateOutput;
|
|
57
|
-
constructor(name, displayName, description,
|
|
34
|
+
constructor(name, displayName, description, kind, parameterSchema, isOutputMarkdown = true, canUpdateOutput = false) {
|
|
58
35
|
this.name = name;
|
|
59
36
|
this.displayName = displayName;
|
|
60
37
|
this.description = description;
|
|
61
|
-
this.
|
|
38
|
+
this.kind = kind;
|
|
62
39
|
this.parameterSchema = parameterSchema;
|
|
63
40
|
this.isOutputMarkdown = isOutputMarkdown;
|
|
64
41
|
this.canUpdateOutput = canUpdateOutput;
|
|
@@ -93,6 +70,57 @@ export class DeclarativeTool {
|
|
|
93
70
|
const invocation = this.build(params);
|
|
94
71
|
return invocation.execute(signal, updateOutput);
|
|
95
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Similar to `build` but never throws.
|
|
75
|
+
* @param params The raw, untrusted parameters from the model.
|
|
76
|
+
* @returns A `ToolInvocation` instance.
|
|
77
|
+
*/
|
|
78
|
+
silentBuild(params) {
|
|
79
|
+
try {
|
|
80
|
+
return this.build(params);
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
if (e instanceof Error) {
|
|
84
|
+
return e;
|
|
85
|
+
}
|
|
86
|
+
return new Error(String(e));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A convenience method that builds and executes the tool in one step.
|
|
91
|
+
* Never throws.
|
|
92
|
+
* @param params The raw, untrusted parameters from the model.
|
|
93
|
+
* @params abortSignal a signal to abort.
|
|
94
|
+
* @returns The result of the tool execution.
|
|
95
|
+
*/
|
|
96
|
+
async validateBuildAndExecute(params, abortSignal) {
|
|
97
|
+
const invocationOrError = this.silentBuild(params);
|
|
98
|
+
if (invocationOrError instanceof Error) {
|
|
99
|
+
const errorMessage = invocationOrError.message;
|
|
100
|
+
return {
|
|
101
|
+
llmContent: `Error: Invalid parameters provided. Reason: ${errorMessage}`,
|
|
102
|
+
returnDisplay: errorMessage,
|
|
103
|
+
error: {
|
|
104
|
+
message: errorMessage,
|
|
105
|
+
type: ToolErrorType.INVALID_TOOL_PARAMS,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
return await invocationOrError.execute(abortSignal);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
114
|
+
return {
|
|
115
|
+
llmContent: `Error: Tool call execution failed. Reason: ${errorMessage}`,
|
|
116
|
+
returnDisplay: errorMessage,
|
|
117
|
+
error: {
|
|
118
|
+
message: errorMessage,
|
|
119
|
+
type: ToolErrorType.EXECUTION_FAILED,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
96
124
|
}
|
|
97
125
|
/**
|
|
98
126
|
* New base class for declarative tools that separates validation from execution.
|
|
@@ -109,90 +137,6 @@ export class BaseDeclarativeTool extends DeclarativeTool {
|
|
|
109
137
|
return this.createInvocation(params);
|
|
110
138
|
}
|
|
111
139
|
}
|
|
112
|
-
/**
|
|
113
|
-
* Base implementation for tools with common functionality
|
|
114
|
-
* @deprecated Use `DeclarativeTool` for new tools.
|
|
115
|
-
*/
|
|
116
|
-
export class BaseTool extends DeclarativeTool {
|
|
117
|
-
name;
|
|
118
|
-
displayName;
|
|
119
|
-
description;
|
|
120
|
-
icon;
|
|
121
|
-
parameterSchema;
|
|
122
|
-
isOutputMarkdown;
|
|
123
|
-
canUpdateOutput;
|
|
124
|
-
/**
|
|
125
|
-
* Creates a new instance of BaseTool
|
|
126
|
-
* @param name Internal name of the tool (used for API calls)
|
|
127
|
-
* @param displayName User-friendly display name of the tool
|
|
128
|
-
* @param description Description of what the tool does
|
|
129
|
-
* @param isOutputMarkdown Whether the tool's output should be rendered as markdown
|
|
130
|
-
* @param canUpdateOutput Whether the tool supports live (streaming) output
|
|
131
|
-
* @param parameterSchema JSON Schema defining the parameters
|
|
132
|
-
*/
|
|
133
|
-
constructor(name, displayName, description, icon, parameterSchema, isOutputMarkdown = true, canUpdateOutput = false) {
|
|
134
|
-
super(name, displayName, description, icon, parameterSchema, isOutputMarkdown, canUpdateOutput);
|
|
135
|
-
this.name = name;
|
|
136
|
-
this.displayName = displayName;
|
|
137
|
-
this.description = description;
|
|
138
|
-
this.icon = icon;
|
|
139
|
-
this.parameterSchema = parameterSchema;
|
|
140
|
-
this.isOutputMarkdown = isOutputMarkdown;
|
|
141
|
-
this.canUpdateOutput = canUpdateOutput;
|
|
142
|
-
}
|
|
143
|
-
build(params) {
|
|
144
|
-
const validationError = this.validateToolParams(params);
|
|
145
|
-
if (validationError) {
|
|
146
|
-
throw new Error(validationError);
|
|
147
|
-
}
|
|
148
|
-
return new LegacyToolInvocation(this, params);
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Validates the parameters for the tool
|
|
152
|
-
* This is a placeholder implementation and should be overridden
|
|
153
|
-
* Should be called from both `shouldConfirmExecute` and `execute`
|
|
154
|
-
* `shouldConfirmExecute` should return false immediately if invalid
|
|
155
|
-
* @param params Parameters to validate
|
|
156
|
-
* @returns An error message string if invalid, null otherwise
|
|
157
|
-
*/
|
|
158
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
159
|
-
validateToolParams(params) {
|
|
160
|
-
// Implementation would typically use a JSON Schema validator
|
|
161
|
-
// This is a placeholder that should be implemented by derived classes
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Gets a pre-execution description of the tool operation
|
|
166
|
-
* Default implementation that should be overridden by derived classes
|
|
167
|
-
* @param params Parameters for the tool execution
|
|
168
|
-
* @returns A markdown string describing what the tool will do
|
|
169
|
-
*/
|
|
170
|
-
getDescription(params) {
|
|
171
|
-
return JSON.stringify(params);
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Determines if the tool should prompt for confirmation before execution
|
|
175
|
-
* @param params Parameters for the tool execution
|
|
176
|
-
* @returns Whether or not execute should be confirmed by the user.
|
|
177
|
-
*/
|
|
178
|
-
shouldConfirmExecute(
|
|
179
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
180
|
-
params,
|
|
181
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
182
|
-
abortSignal) {
|
|
183
|
-
return Promise.resolve(false);
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Determines what file system paths the tool will affect
|
|
187
|
-
* @param params Parameters for the tool execution
|
|
188
|
-
* @returns A list of such paths
|
|
189
|
-
*/
|
|
190
|
-
toolLocations(
|
|
191
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
192
|
-
params) {
|
|
193
|
-
return [];
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
140
|
/**
|
|
197
141
|
* Detects cycles in a JSON schemas due to `$ref`s.
|
|
198
142
|
* @param schema The root of the JSON schema.
|
|
@@ -267,15 +211,16 @@ export var ToolConfirmationOutcome;
|
|
|
267
211
|
ToolConfirmationOutcome["ModifyWithEditor"] = "modify_with_editor";
|
|
268
212
|
ToolConfirmationOutcome["Cancel"] = "cancel";
|
|
269
213
|
})(ToolConfirmationOutcome || (ToolConfirmationOutcome = {}));
|
|
270
|
-
export var
|
|
271
|
-
(function (
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
214
|
+
export var Kind;
|
|
215
|
+
(function (Kind) {
|
|
216
|
+
Kind["Read"] = "read";
|
|
217
|
+
Kind["Edit"] = "edit";
|
|
218
|
+
Kind["Delete"] = "delete";
|
|
219
|
+
Kind["Move"] = "move";
|
|
220
|
+
Kind["Search"] = "search";
|
|
221
|
+
Kind["Execute"] = "execute";
|
|
222
|
+
Kind["Think"] = "think";
|
|
223
|
+
Kind["Fetch"] = "fetch";
|
|
224
|
+
Kind["Other"] = "other";
|
|
225
|
+
})(Kind || (Kind = {}));
|
|
281
226
|
//# sourceMappingURL=tools.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/tools/tools.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/tools/tools.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAgDhD;;GAEG;AACH,MAAM,OAAgB,kBAAkB;IAKjB;IAArB,YAAqB,MAAe;QAAf,WAAM,GAAN,MAAM,CAAS;IAAG,CAAC;IAIxC,aAAa;QACX,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,oBAAoB,CAClB,YAAyB;QAEzB,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CAMF;AAyDD;;;GAGG;AACH,MAAM,OAAgB,eAAe;IAMxB;IACA;I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AN,IAAY,IAUX;AAVD,WAAY,IAAI;IACd,qBAAa,CAAA;IACb,qBAAa,CAAA;IACb,yBAAiB,CAAA;IACjB,qBAAa,CAAA;IACb,yBAAiB,CAAA;IACjB,2BAAmB,CAAA;IACnB,uBAAe,CAAA;IACf,uBAAe,CAAA;IACf,uBAAe,CAAA;AACjB,CAAC,EAVW,IAAI,KAAJ,IAAI,QAUf"}
|
|
@@ -3,8 +3,97 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { describe, it, expect } from 'vitest';
|
|
7
|
-
import { hasCycleInSchema } from './tools.js';
|
|
6
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
7
|
+
import { DeclarativeTool, hasCycleInSchema, Kind, } from './tools.js';
|
|
8
|
+
import { ToolErrorType } from './tool-error.js';
|
|
9
|
+
class TestToolInvocation {
|
|
10
|
+
params;
|
|
11
|
+
executeFn;
|
|
12
|
+
constructor(params, executeFn) {
|
|
13
|
+
this.params = params;
|
|
14
|
+
this.executeFn = executeFn;
|
|
15
|
+
}
|
|
16
|
+
getDescription() {
|
|
17
|
+
return 'A test invocation';
|
|
18
|
+
}
|
|
19
|
+
toolLocations() {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
shouldConfirmExecute() {
|
|
23
|
+
return Promise.resolve(false);
|
|
24
|
+
}
|
|
25
|
+
execute() {
|
|
26
|
+
return this.executeFn();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
class TestTool extends DeclarativeTool {
|
|
30
|
+
buildFn;
|
|
31
|
+
constructor(buildFn) {
|
|
32
|
+
super('test-tool', 'Test Tool', 'A tool for testing', Kind.Other, {});
|
|
33
|
+
this.buildFn = buildFn;
|
|
34
|
+
}
|
|
35
|
+
build(params) {
|
|
36
|
+
return this.buildFn(params);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
describe('DeclarativeTool', () => {
|
|
40
|
+
describe('validateBuildAndExecute', () => {
|
|
41
|
+
const abortSignal = new AbortController().signal;
|
|
42
|
+
it('should return INVALID_TOOL_PARAMS error if build fails', async () => {
|
|
43
|
+
const buildError = new Error('Invalid build parameters');
|
|
44
|
+
const buildFn = vi.fn().mockImplementation(() => {
|
|
45
|
+
throw buildError;
|
|
46
|
+
});
|
|
47
|
+
const tool = new TestTool(buildFn);
|
|
48
|
+
const params = { foo: 'bar' };
|
|
49
|
+
const result = await tool.validateBuildAndExecute(params, abortSignal);
|
|
50
|
+
expect(buildFn).toHaveBeenCalledWith(params);
|
|
51
|
+
expect(result).toEqual({
|
|
52
|
+
llmContent: `Error: Invalid parameters provided. Reason: ${buildError.message}`,
|
|
53
|
+
returnDisplay: buildError.message,
|
|
54
|
+
error: {
|
|
55
|
+
message: buildError.message,
|
|
56
|
+
type: ToolErrorType.INVALID_TOOL_PARAMS,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
it('should return EXECUTION_FAILED error if execute fails', async () => {
|
|
61
|
+
const executeError = new Error('Execution failed');
|
|
62
|
+
const executeFn = vi.fn().mockRejectedValue(executeError);
|
|
63
|
+
const invocation = new TestToolInvocation({}, executeFn);
|
|
64
|
+
const buildFn = vi.fn().mockReturnValue(invocation);
|
|
65
|
+
const tool = new TestTool(buildFn);
|
|
66
|
+
const params = { foo: 'bar' };
|
|
67
|
+
const result = await tool.validateBuildAndExecute(params, abortSignal);
|
|
68
|
+
expect(buildFn).toHaveBeenCalledWith(params);
|
|
69
|
+
expect(executeFn).toHaveBeenCalled();
|
|
70
|
+
expect(result).toEqual({
|
|
71
|
+
llmContent: `Error: Tool call execution failed. Reason: ${executeError.message}`,
|
|
72
|
+
returnDisplay: executeError.message,
|
|
73
|
+
error: {
|
|
74
|
+
message: executeError.message,
|
|
75
|
+
type: ToolErrorType.EXECUTION_FAILED,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
it('should return the result of execute on success', async () => {
|
|
80
|
+
const successResult = {
|
|
81
|
+
llmContent: 'Success!',
|
|
82
|
+
returnDisplay: 'Success!',
|
|
83
|
+
summary: 'Tool executed successfully',
|
|
84
|
+
};
|
|
85
|
+
const executeFn = vi.fn().mockResolvedValue(successResult);
|
|
86
|
+
const invocation = new TestToolInvocation({}, executeFn);
|
|
87
|
+
const buildFn = vi.fn().mockReturnValue(invocation);
|
|
88
|
+
const tool = new TestTool(buildFn);
|
|
89
|
+
const params = { foo: 'bar' };
|
|
90
|
+
const result = await tool.validateBuildAndExecute(params, abortSignal);
|
|
91
|
+
expect(buildFn).toHaveBeenCalledWith(params);
|
|
92
|
+
expect(executeFn).toHaveBeenCalled();
|
|
93
|
+
expect(result).toEqual(successResult);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
8
97
|
describe('hasCycleInSchema', () => {
|
|
9
98
|
it('should detect a simple direct cycle', () => {
|
|
10
99
|
const schema = {
|
|
@@ -1 +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;
|
|
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,EAAE,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,IAAI,GAGL,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,kBAAkB;IAEX;IACQ;IAFnB,YACW,MAAc,EACN,SAAoC;QAD5C,WAAM,GAAN,MAAM,CAAQ;QACN,cAAS,GAAT,SAAS,CAA2B;IAC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D,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;aACzB;SACF,CAAC;QACF,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACjD,MAAM,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { BaseDeclarativeTool, ToolInvocation, ToolResult } from './tools.js';
|
|
7
7
|
import { Config } from '../config/config.js';
|
|
8
8
|
/**
|
|
9
9
|
* Parameters for the WebFetch tool
|
|
@@ -17,13 +17,10 @@ export interface WebFetchToolParams {
|
|
|
17
17
|
/**
|
|
18
18
|
* Implementation of the WebFetch tool logic
|
|
19
19
|
*/
|
|
20
|
-
export declare class WebFetchTool extends
|
|
20
|
+
export declare class WebFetchTool extends BaseDeclarativeTool<WebFetchToolParams, ToolResult> {
|
|
21
21
|
private readonly config;
|
|
22
22
|
static readonly Name: string;
|
|
23
23
|
constructor(config: Config);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
getDescription(params: WebFetchToolParams): string;
|
|
27
|
-
shouldConfirmExecute(params: WebFetchToolParams): Promise<ToolCallConfirmationDetails | false>;
|
|
28
|
-
execute(params: WebFetchToolParams, signal: AbortSignal): Promise<ToolResult>;
|
|
24
|
+
protected validateToolParams(params: WebFetchToolParams): string | null;
|
|
25
|
+
protected createInvocation(params: WebFetchToolParams): ToolInvocation<WebFetchToolParams, ToolResult>;
|
|
29
26
|
}
|