@google/gemini-cli-core 0.0.3-preview.4
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/LICENSE +202 -0
- package/README.md +310 -0
- package/dist/.last_build +0 -0
- package/dist/google-gemini-cli-core-0.3.0-preview.3.tgz +0 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/src/__mocks__/fs/promises.d.ts +11 -0
- package/dist/src/__mocks__/fs/promises.js +17 -0
- package/dist/src/__mocks__/fs/promises.js.map +1 -0
- package/dist/src/code_assist/codeAssist.d.ts +10 -0
- package/dist/src/code_assist/codeAssist.js +19 -0
- package/dist/src/code_assist/codeAssist.js.map +1 -0
- package/dist/src/code_assist/converter.d.ts +72 -0
- package/dist/src/code_assist/converter.js +159 -0
- package/dist/src/code_assist/converter.js.map +1 -0
- package/dist/src/code_assist/converter.test.d.ts +6 -0
- package/dist/src/code_assist/converter.test.js +362 -0
- package/dist/src/code_assist/converter.test.js.map +1 -0
- package/dist/src/code_assist/oauth2.d.ts +22 -0
- package/dist/src/code_assist/oauth2.js +353 -0
- package/dist/src/code_assist/oauth2.js.map +1 -0
- package/dist/src/code_assist/oauth2.test.d.ts +6 -0
- package/dist/src/code_assist/oauth2.test.js +427 -0
- package/dist/src/code_assist/oauth2.test.js.map +1 -0
- package/dist/src/code_assist/server.d.ts +37 -0
- package/dist/src/code_assist/server.js +125 -0
- package/dist/src/code_assist/server.js.map +1 -0
- package/dist/src/code_assist/server.test.d.ts +6 -0
- package/dist/src/code_assist/server.test.js +134 -0
- package/dist/src/code_assist/server.test.js.map +1 -0
- package/dist/src/code_assist/setup.d.ts +20 -0
- package/dist/src/code_assist/setup.js +101 -0
- package/dist/src/code_assist/setup.js.map +1 -0
- package/dist/src/code_assist/setup.test.d.ts +6 -0
- package/dist/src/code_assist/setup.test.js +171 -0
- package/dist/src/code_assist/setup.test.js.map +1 -0
- package/dist/src/code_assist/types.d.ts +148 -0
- package/dist/src/code_assist/types.js +46 -0
- package/dist/src/code_assist/types.js.map +1 -0
- package/dist/src/config/config.d.ts +318 -0
- package/dist/src/config/config.js +633 -0
- package/dist/src/config/config.js.map +1 -0
- package/dist/src/config/config.test.d.ts +6 -0
- package/dist/src/config/config.test.js +585 -0
- package/dist/src/config/config.test.js.map +1 -0
- package/dist/src/config/flashFallback.test.d.ts +6 -0
- package/dist/src/config/flashFallback.test.js +87 -0
- package/dist/src/config/flashFallback.test.js.map +1 -0
- package/dist/src/config/models.d.ts +9 -0
- package/dist/src/config/models.js +10 -0
- package/dist/src/config/models.js.map +1 -0
- package/dist/src/config/storage.d.ts +32 -0
- package/dist/src/config/storage.js +90 -0
- package/dist/src/config/storage.js.map +1 -0
- package/dist/src/config/storage.test.d.ts +6 -0
- package/dist/src/config/storage.test.js +43 -0
- package/dist/src/config/storage.test.js.map +1 -0
- package/dist/src/core/client.d.ts +65 -0
- package/dist/src/core/client.js +689 -0
- package/dist/src/core/client.js.map +1 -0
- package/dist/src/core/client.test.d.ts +6 -0
- package/dist/src/core/client.test.js +1857 -0
- package/dist/src/core/client.test.js.map +1 -0
- package/dist/src/core/contentGenerator.d.ts +33 -0
- package/dist/src/core/contentGenerator.js +80 -0
- package/dist/src/core/contentGenerator.js.map +1 -0
- package/dist/src/core/contentGenerator.test.d.ts +6 -0
- package/dist/src/core/contentGenerator.test.js +124 -0
- package/dist/src/core/contentGenerator.test.js.map +1 -0
- package/dist/src/core/coreToolScheduler.d.ts +126 -0
- package/dist/src/core/coreToolScheduler.js +605 -0
- package/dist/src/core/coreToolScheduler.js.map +1 -0
- package/dist/src/core/coreToolScheduler.test.d.ts +6 -0
- package/dist/src/core/coreToolScheduler.test.js +923 -0
- package/dist/src/core/coreToolScheduler.test.js.map +1 -0
- package/dist/src/core/geminiChat.d.ts +122 -0
- package/dist/src/core/geminiChat.js +547 -0
- package/dist/src/core/geminiChat.js.map +1 -0
- package/dist/src/core/geminiChat.test.d.ts +6 -0
- package/dist/src/core/geminiChat.test.js +875 -0
- package/dist/src/core/geminiChat.test.js.map +1 -0
- package/dist/src/core/geminiRequest.d.ts +13 -0
- package/dist/src/core/geminiRequest.js +11 -0
- package/dist/src/core/geminiRequest.js.map +1 -0
- package/dist/src/core/logger.d.ts +60 -0
- package/dist/src/core/logger.js +360 -0
- package/dist/src/core/logger.js.map +1 -0
- package/dist/src/core/logger.test.d.ts +6 -0
- package/dist/src/core/logger.test.js +534 -0
- package/dist/src/core/logger.test.js.map +1 -0
- package/dist/src/core/loggingContentGenerator.d.ts +25 -0
- package/dist/src/core/loggingContentGenerator.js +97 -0
- package/dist/src/core/loggingContentGenerator.js.map +1 -0
- package/dist/src/core/nonInteractiveToolExecutor.d.ts +10 -0
- package/dist/src/core/nonInteractiveToolExecutor.js +24 -0
- package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -0
- package/dist/src/core/nonInteractiveToolExecutor.test.d.ts +6 -0
- package/dist/src/core/nonInteractiveToolExecutor.test.js +236 -0
- package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -0
- package/dist/src/core/prompts.d.ts +12 -0
- package/dist/src/core/prompts.js +359 -0
- package/dist/src/core/prompts.js.map +1 -0
- package/dist/src/core/prompts.test.d.ts +6 -0
- package/dist/src/core/prompts.test.js +214 -0
- package/dist/src/core/prompts.test.js.map +1 -0
- package/dist/src/core/subagent.d.ts +236 -0
- package/dist/src/core/subagent.js +485 -0
- package/dist/src/core/subagent.js.map +1 -0
- package/dist/src/core/subagent.test.d.ts +6 -0
- package/dist/src/core/subagent.test.js +520 -0
- package/dist/src/core/subagent.test.js.map +1 -0
- package/dist/src/core/tokenLimits.d.ts +10 -0
- package/dist/src/core/tokenLimits.js +28 -0
- package/dist/src/core/tokenLimits.js.map +1 -0
- package/dist/src/core/turn.d.ts +125 -0
- package/dist/src/core/turn.js +154 -0
- package/dist/src/core/turn.js.map +1 -0
- package/dist/src/core/turn.test.d.ts +6 -0
- package/dist/src/core/turn.test.js +388 -0
- package/dist/src/core/turn.test.js.map +1 -0
- 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 +25 -0
- package/dist/src/ide/detect-ide.js +104 -0
- package/dist/src/ide/detect-ide.js.map +1 -0
- package/dist/src/ide/detect-ide.test.d.ts +6 -0
- package/dist/src/ide/detect-ide.test.js +109 -0
- package/dist/src/ide/detect-ide.test.js.map +1 -0
- package/dist/src/ide/ide-client.d.ts +67 -0
- package/dist/src/ide/ide-client.js +418 -0
- package/dist/src/ide/ide-client.js.map +1 -0
- package/dist/src/ide/ide-client.test.d.ts +6 -0
- package/dist/src/ide/ide-client.test.js +155 -0
- package/dist/src/ide/ide-client.test.js.map +1 -0
- package/dist/src/ide/ide-installer.d.ts +14 -0
- package/dist/src/ide/ide-installer.js +107 -0
- package/dist/src/ide/ide-installer.js.map +1 -0
- package/dist/src/ide/ide-installer.test.d.ts +6 -0
- package/dist/src/ide/ide-installer.test.js +113 -0
- package/dist/src/ide/ide-installer.test.js.map +1 -0
- package/dist/src/ide/ideContext.d.ts +374 -0
- package/dist/src/ide/ideContext.js +147 -0
- package/dist/src/ide/ideContext.js.map +1 -0
- package/dist/src/ide/ideContext.test.d.ts +6 -0
- package/dist/src/ide/ideContext.test.js +265 -0
- package/dist/src/ide/ideContext.test.js.map +1 -0
- package/dist/src/ide/process-utils.d.ts +22 -0
- package/dist/src/ide/process-utils.js +153 -0
- package/dist/src/ide/process-utils.js.map +1 -0
- package/dist/src/ide/process-utils.test.d.ts +6 -0
- package/dist/src/ide/process-utils.test.js +72 -0
- package/dist/src/ide/process-utils.test.js.map +1 -0
- package/dist/src/index.d.ts +81 -0
- package/dist/src/index.js +90 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/index.test.d.ts +6 -0
- package/dist/src/index.test.js +12 -0
- package/dist/src/index.test.js.map +1 -0
- package/dist/src/mcp/google-auth-provider.d.ts +23 -0
- package/dist/src/mcp/google-auth-provider.js +72 -0
- package/dist/src/mcp/google-auth-provider.js.map +1 -0
- package/dist/src/mcp/google-auth-provider.test.d.ts +6 -0
- package/dist/src/mcp/google-auth-provider.test.js +89 -0
- package/dist/src/mcp/google-auth-provider.test.js.map +1 -0
- package/dist/src/mcp/oauth-provider.d.ts +146 -0
- package/dist/src/mcp/oauth-provider.js +601 -0
- package/dist/src/mcp/oauth-provider.js.map +1 -0
- package/dist/src/mcp/oauth-provider.test.d.ts +6 -0
- package/dist/src/mcp/oauth-provider.test.js +672 -0
- package/dist/src/mcp/oauth-provider.test.js.map +1 -0
- package/dist/src/mcp/oauth-token-storage.d.ts +61 -0
- package/dist/src/mcp/oauth-token-storage.js +148 -0
- package/dist/src/mcp/oauth-token-storage.js.map +1 -0
- package/dist/src/mcp/oauth-token-storage.test.d.ts +6 -0
- package/dist/src/mcp/oauth-token-storage.test.js +206 -0
- package/dist/src/mcp/oauth-token-storage.test.js.map +1 -0
- package/dist/src/mcp/oauth-utils.d.ts +119 -0
- package/dist/src/mcp/oauth-utils.js +235 -0
- package/dist/src/mcp/oauth-utils.js.map +1 -0
- package/dist/src/mcp/oauth-utils.test.d.ts +6 -0
- package/dist/src/mcp/oauth-utils.test.js +199 -0
- package/dist/src/mcp/oauth-utils.test.js.map +1 -0
- package/dist/src/mcp/token-storage/base-token-storage.d.ts +19 -0
- package/dist/src/mcp/token-storage/base-token-storage.js +36 -0
- package/dist/src/mcp/token-storage/base-token-storage.js.map +1 -0
- package/dist/src/mcp/token-storage/base-token-storage.test.d.ts +6 -0
- package/dist/src/mcp/token-storage/base-token-storage.test.js +160 -0
- package/dist/src/mcp/token-storage/base-token-storage.test.js.map +1 -0
- package/dist/src/mcp/token-storage/types.d.ts +34 -0
- package/dist/src/mcp/token-storage/types.js +7 -0
- package/dist/src/mcp/token-storage/types.js.map +1 -0
- package/dist/src/mocks/msw.d.ts +6 -0
- package/dist/src/mocks/msw.js +8 -0
- package/dist/src/mocks/msw.js.map +1 -0
- package/dist/src/prompts/mcp-prompts.d.ts +8 -0
- package/dist/src/prompts/mcp-prompts.js +13 -0
- package/dist/src/prompts/mcp-prompts.js.map +1 -0
- package/dist/src/prompts/prompt-registry.d.ts +34 -0
- package/dist/src/prompts/prompt-registry.js +63 -0
- package/dist/src/prompts/prompt-registry.js.map +1 -0
- package/dist/src/services/chatRecordingService.d.ts +150 -0
- package/dist/src/services/chatRecordingService.js +321 -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 +290 -0
- package/dist/src/services/chatRecordingService.test.js.map +1 -0
- package/dist/src/services/fileDiscoveryService.d.ts +35 -0
- package/dist/src/services/fileDiscoveryService.js +91 -0
- package/dist/src/services/fileDiscoveryService.js.map +1 -0
- package/dist/src/services/fileDiscoveryService.test.d.ts +6 -0
- package/dist/src/services/fileDiscoveryService.test.js +143 -0
- package/dist/src/services/fileDiscoveryService.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/gitService.d.ts +23 -0
- package/dist/src/services/gitService.js +110 -0
- package/dist/src/services/gitService.js.map +1 -0
- package/dist/src/services/gitService.test.d.ts +6 -0
- package/dist/src/services/gitService.test.js +212 -0
- package/dist/src/services/gitService.test.js.map +1 -0
- package/dist/src/services/loopDetectionService.d.ts +98 -0
- package/dist/src/services/loopDetectionService.js +363 -0
- package/dist/src/services/loopDetectionService.js.map +1 -0
- package/dist/src/services/loopDetectionService.test.d.ts +6 -0
- package/dist/src/services/loopDetectionService.test.js +558 -0
- package/dist/src/services/loopDetectionService.test.js.map +1 -0
- package/dist/src/services/shellExecutionService.d.ts +68 -0
- package/dist/src/services/shellExecutionService.js +332 -0
- package/dist/src/services/shellExecutionService.js.map +1 -0
- package/dist/src/services/shellExecutionService.test.d.ts +6 -0
- package/dist/src/services/shellExecutionService.test.js +517 -0
- package/dist/src/services/shellExecutionService.test.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +121 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +773 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.d.ts +17 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +407 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +90 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +229 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -0
- package/dist/src/telemetry/constants.d.ts +32 -0
- package/dist/src/telemetry/constants.js +33 -0
- package/dist/src/telemetry/constants.js.map +1 -0
- package/dist/src/telemetry/file-exporters.d.ts +29 -0
- package/dist/src/telemetry/file-exporters.js +62 -0
- package/dist/src/telemetry/file-exporters.js.map +1 -0
- package/dist/src/telemetry/index.d.ts +21 -0
- package/dist/src/telemetry/index.js +21 -0
- package/dist/src/telemetry/index.js.map +1 -0
- package/dist/src/telemetry/integration.test.circular.d.ts +6 -0
- package/dist/src/telemetry/integration.test.circular.js +54 -0
- package/dist/src/telemetry/integration.test.circular.js.map +1 -0
- package/dist/src/telemetry/loggers.d.ts +26 -0
- package/dist/src/telemetry/loggers.js +404 -0
- package/dist/src/telemetry/loggers.js.map +1 -0
- package/dist/src/telemetry/loggers.test.circular.d.ts +6 -0
- package/dist/src/telemetry/loggers.test.circular.js +107 -0
- package/dist/src/telemetry/loggers.test.circular.js.map +1 -0
- package/dist/src/telemetry/loggers.test.d.ts +6 -0
- package/dist/src/telemetry/loggers.test.js +658 -0
- package/dist/src/telemetry/loggers.test.js.map +1 -0
- package/dist/src/telemetry/metrics.d.ts +36 -0
- package/dist/src/telemetry/metrics.js +208 -0
- package/dist/src/telemetry/metrics.js.map +1 -0
- package/dist/src/telemetry/metrics.test.d.ts +6 -0
- package/dist/src/telemetry/metrics.test.js +242 -0
- package/dist/src/telemetry/metrics.test.js.map +1 -0
- package/dist/src/telemetry/sdk.d.ts +9 -0
- package/dist/src/telemetry/sdk.js +163 -0
- package/dist/src/telemetry/sdk.js.map +1 -0
- 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/telemetry-utils.d.ts +6 -0
- package/dist/src/telemetry/telemetry-utils.js +14 -0
- package/dist/src/telemetry/telemetry-utils.js.map +1 -0
- package/dist/src/telemetry/telemetry-utils.test.d.ts +6 -0
- package/dist/src/telemetry/telemetry-utils.test.js +40 -0
- package/dist/src/telemetry/telemetry-utils.test.js.map +1 -0
- package/dist/src/telemetry/telemetry.test.d.ts +6 -0
- package/dist/src/telemetry/telemetry.test.js +50 -0
- package/dist/src/telemetry/telemetry.test.js.map +1 -0
- package/dist/src/telemetry/tool-call-decision.d.ts +13 -0
- package/dist/src/telemetry/tool-call-decision.js +29 -0
- package/dist/src/telemetry/tool-call-decision.js.map +1 -0
- package/dist/src/telemetry/types.d.ts +220 -0
- package/dist/src/telemetry/types.js +383 -0
- package/dist/src/telemetry/types.js.map +1 -0
- package/dist/src/telemetry/uiTelemetry.d.ts +75 -0
- package/dist/src/telemetry/uiTelemetry.js +153 -0
- package/dist/src/telemetry/uiTelemetry.js.map +1 -0
- package/dist/src/telemetry/uiTelemetry.test.d.ts +6 -0
- package/dist/src/telemetry/uiTelemetry.test.js +558 -0
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -0
- package/dist/src/test-utils/config.d.ts +17 -0
- package/dist/src/test-utils/config.js +32 -0
- package/dist/src/test-utils/config.js.map +1 -0
- package/dist/src/test-utils/mockWorkspaceContext.d.ts +13 -0
- package/dist/src/test-utils/mockWorkspaceContext.js +24 -0
- package/dist/src/test-utils/mockWorkspaceContext.js.map +1 -0
- package/dist/src/test-utils/tools.d.ts +45 -0
- package/dist/src/test-utils/tools.js +105 -0
- package/dist/src/test-utils/tools.js.map +1 -0
- package/dist/src/tools/diffOptions.d.ts +9 -0
- package/dist/src/tools/diffOptions.js +38 -0
- package/dist/src/tools/diffOptions.js.map +1 -0
- package/dist/src/tools/diffOptions.test.d.ts +6 -0
- package/dist/src/tools/diffOptions.test.js +119 -0
- package/dist/src/tools/diffOptions.test.js.map +1 -0
- package/dist/src/tools/edit.d.ts +56 -0
- package/dist/src/tools/edit.js +423 -0
- package/dist/src/tools/edit.js.map +1 -0
- package/dist/src/tools/edit.test.d.ts +6 -0
- package/dist/src/tools/edit.test.js +713 -0
- package/dist/src/tools/edit.test.js.map +1 -0
- package/dist/src/tools/glob.d.ts +52 -0
- package/dist/src/tools/glob.js +236 -0
- package/dist/src/tools/glob.js.map +1 -0
- package/dist/src/tools/glob.test.d.ts +6 -0
- package/dist/src/tools/glob.test.js +375 -0
- package/dist/src/tools/glob.test.js.map +1 -0
- package/dist/src/tools/grep.d.ts +47 -0
- package/dist/src/tools/grep.js +517 -0
- package/dist/src/tools/grep.js.map +1 -0
- package/dist/src/tools/grep.test.d.ts +6 -0
- package/dist/src/tools/grep.test.js +295 -0
- package/dist/src/tools/grep.test.js.map +1 -0
- package/dist/src/tools/ls.d.ts +68 -0
- package/dist/src/tools/ls.js +227 -0
- package/dist/src/tools/ls.js.map +1 -0
- package/dist/src/tools/ls.test.d.ts +6 -0
- package/dist/src/tools/ls.test.js +389 -0
- package/dist/src/tools/ls.test.js.map +1 -0
- 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 +199 -0
- package/dist/src/tools/mcp-client.js +995 -0
- package/dist/src/tools/mcp-client.js.map +1 -0
- package/dist/src/tools/mcp-client.test.d.ts +6 -0
- package/dist/src/tools/mcp-client.test.js +454 -0
- package/dist/src/tools/mcp-client.test.js.map +1 -0
- package/dist/src/tools/mcp-tool.d.ts +23 -0
- package/dist/src/tools/mcp-tool.js +240 -0
- package/dist/src/tools/mcp-tool.js.map +1 -0
- package/dist/src/tools/mcp-tool.test.d.ts +6 -0
- package/dist/src/tools/mcp-tool.test.js +576 -0
- package/dist/src/tools/mcp-tool.test.js.map +1 -0
- package/dist/src/tools/memoryTool.d.ts +40 -0
- package/dist/src/tools/memoryTool.js +296 -0
- package/dist/src/tools/memoryTool.js.map +1 -0
- package/dist/src/tools/memoryTool.test.d.ts +6 -0
- package/dist/src/tools/memoryTool.test.js +298 -0
- package/dist/src/tools/memoryTool.test.js.map +1 -0
- package/dist/src/tools/modifiable-tool.d.ts +32 -0
- package/dist/src/tools/modifiable-tool.js +88 -0
- package/dist/src/tools/modifiable-tool.js.map +1 -0
- package/dist/src/tools/modifiable-tool.test.d.ts +6 -0
- package/dist/src/tools/modifiable-tool.test.js +193 -0
- package/dist/src/tools/modifiable-tool.test.js.map +1 -0
- package/dist/src/tools/read-file.d.ts +35 -0
- package/dist/src/tools/read-file.js +127 -0
- package/dist/src/tools/read-file.js.map +1 -0
- package/dist/src/tools/read-file.test.d.ts +6 -0
- package/dist/src/tools/read-file.test.js +311 -0
- package/dist/src/tools/read-file.test.js.map +1 -0
- package/dist/src/tools/read-many-files.d.ts +60 -0
- package/dist/src/tools/read-many-files.js +414 -0
- package/dist/src/tools/read-many-files.js.map +1 -0
- package/dist/src/tools/read-many-files.test.d.ts +6 -0
- package/dist/src/tools/read-many-files.test.js +565 -0
- package/dist/src/tools/read-many-files.test.js.map +1 -0
- package/dist/src/tools/ripGrep.d.ts +47 -0
- package/dist/src/tools/ripGrep.js +368 -0
- package/dist/src/tools/ripGrep.js.map +1 -0
- package/dist/src/tools/ripGrep.test.d.ts +6 -0
- package/dist/src/tools/ripGrep.test.js +874 -0
- package/dist/src/tools/ripGrep.test.js.map +1 -0
- package/dist/src/tools/shell.d.ts +22 -0
- package/dist/src/tools/shell.js +320 -0
- package/dist/src/tools/shell.js.map +1 -0
- package/dist/src/tools/shell.test.d.ts +6 -0
- package/dist/src/tools/shell.test.js +336 -0
- package/dist/src/tools/shell.test.js.map +1 -0
- package/dist/src/tools/tool-error.d.ts +43 -0
- package/dist/src/tools/tool-error.js +58 -0
- package/dist/src/tools/tool-error.js.map +1 -0
- package/dist/src/tools/tool-registry.d.ts +86 -0
- package/dist/src/tools/tool-registry.js +369 -0
- package/dist/src/tools/tool-registry.js.map +1 -0
- package/dist/src/tools/tool-registry.test.d.ts +6 -0
- package/dist/src/tools/tool-registry.test.js +332 -0
- package/dist/src/tools/tool-registry.test.js.map +1 -0
- package/dist/src/tools/tools.d.ts +274 -0
- package/dist/src/tools/tools.js +250 -0
- package/dist/src/tools/tools.js.map +1 -0
- package/dist/src/tools/tools.test.d.ts +6 -0
- package/dist/src/tools/tools.test.js +205 -0
- package/dist/src/tools/tools.test.js.map +1 -0
- package/dist/src/tools/web-fetch.d.ts +27 -0
- package/dist/src/tools/web-fetch.js +243 -0
- package/dist/src/tools/web-fetch.js.map +1 -0
- package/dist/src/tools/web-fetch.test.d.ts +6 -0
- package/dist/src/tools/web-fetch.test.js +114 -0
- package/dist/src/tools/web-fetch.test.js.map +1 -0
- package/dist/src/tools/web-search.d.ts +49 -0
- package/dist/src/tools/web-search.js +137 -0
- package/dist/src/tools/web-search.js.map +1 -0
- package/dist/src/tools/web-search.test.d.ts +6 -0
- package/dist/src/tools/web-search.test.js +207 -0
- package/dist/src/tools/web-search.test.js.map +1 -0
- package/dist/src/tools/write-file.d.ts +52 -0
- package/dist/src/tools/write-file.js +314 -0
- package/dist/src/tools/write-file.js.map +1 -0
- package/dist/src/tools/write-file.test.d.ts +6 -0
- package/dist/src/tools/write-file.test.js +531 -0
- package/dist/src/tools/write-file.test.js.map +1 -0
- package/dist/src/utils/LruCache.d.ts +13 -0
- package/dist/src/utils/LruCache.js +38 -0
- package/dist/src/utils/LruCache.js.map +1 -0
- package/dist/src/utils/bfsFileSearch.d.ts +24 -0
- package/dist/src/utils/bfsFileSearch.js +89 -0
- package/dist/src/utils/bfsFileSearch.js.map +1 -0
- package/dist/src/utils/bfsFileSearch.test.d.ts +6 -0
- package/dist/src/utils/bfsFileSearch.test.js +163 -0
- package/dist/src/utils/bfsFileSearch.test.js.map +1 -0
- package/dist/src/utils/browser.d.ts +13 -0
- package/dist/src/utils/browser.js +50 -0
- package/dist/src/utils/browser.js.map +1 -0
- package/dist/src/utils/editCorrector.d.ts +53 -0
- package/dist/src/utils/editCorrector.js +545 -0
- package/dist/src/utils/editCorrector.js.map +1 -0
- package/dist/src/utils/editCorrector.test.d.ts +6 -0
- package/dist/src/utils/editCorrector.test.js +564 -0
- package/dist/src/utils/editCorrector.test.js.map +1 -0
- package/dist/src/utils/editor.d.ts +28 -0
- package/dist/src/utils/editor.js +186 -0
- package/dist/src/utils/editor.js.map +1 -0
- package/dist/src/utils/editor.test.d.ts +6 -0
- package/dist/src/utils/editor.test.js +445 -0
- package/dist/src/utils/editor.test.js.map +1 -0
- package/dist/src/utils/environmentContext.d.ts +21 -0
- package/dist/src/utils/environmentContext.js +90 -0
- package/dist/src/utils/environmentContext.js.map +1 -0
- package/dist/src/utils/environmentContext.test.d.ts +6 -0
- package/dist/src/utils/environmentContext.test.js +140 -0
- package/dist/src/utils/environmentContext.test.js.map +1 -0
- 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/errorReporting.d.ts +14 -0
- package/dist/src/utils/errorReporting.js +88 -0
- package/dist/src/utils/errorReporting.js.map +1 -0
- package/dist/src/utils/errorReporting.test.d.ts +6 -0
- package/dist/src/utils/errorReporting.test.js +130 -0
- package/dist/src/utils/errorReporting.test.js.map +1 -0
- package/dist/src/utils/errors.d.ts +33 -0
- package/dist/src/utils/errors.js +86 -0
- package/dist/src/utils/errors.js.map +1 -0
- package/dist/src/utils/fetch.d.ts +11 -0
- package/dist/src/utils/fetch.js +51 -0
- package/dist/src/utils/fetch.js.map +1 -0
- package/dist/src/utils/fileUtils.d.ts +52 -0
- package/dist/src/utils/fileUtils.js +283 -0
- package/dist/src/utils/fileUtils.js.map +1 -0
- package/dist/src/utils/fileUtils.test.d.ts +6 -0
- package/dist/src/utils/fileUtils.test.js +364 -0
- package/dist/src/utils/fileUtils.test.js.map +1 -0
- package/dist/src/utils/filesearch/crawlCache.d.ts +25 -0
- package/dist/src/utils/filesearch/crawlCache.js +57 -0
- package/dist/src/utils/filesearch/crawlCache.js.map +1 -0
- package/dist/src/utils/filesearch/crawlCache.test.d.ts +6 -0
- package/dist/src/utils/filesearch/crawlCache.test.js +103 -0
- package/dist/src/utils/filesearch/crawlCache.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 +38 -0
- package/dist/src/utils/filesearch/fileSearch.js +191 -0
- package/dist/src/utils/filesearch/fileSearch.js.map +1 -0
- package/dist/src/utils/filesearch/fileSearch.test.d.ts +6 -0
- package/dist/src/utils/filesearch/fileSearch.test.js +642 -0
- package/dist/src/utils/filesearch/fileSearch.test.js.map +1 -0
- package/dist/src/utils/filesearch/ignore.d.ts +42 -0
- package/dist/src/utils/filesearch/ignore.js +106 -0
- package/dist/src/utils/filesearch/ignore.js.map +1 -0
- package/dist/src/utils/filesearch/ignore.test.d.ts +6 -0
- package/dist/src/utils/filesearch/ignore.test.js +144 -0
- package/dist/src/utils/filesearch/ignore.test.js.map +1 -0
- package/dist/src/utils/filesearch/result-cache.d.ts +33 -0
- package/dist/src/utils/filesearch/result-cache.js +59 -0
- package/dist/src/utils/filesearch/result-cache.js.map +1 -0
- package/dist/src/utils/filesearch/result-cache.test.d.ts +6 -0
- package/dist/src/utils/filesearch/result-cache.test.js +46 -0
- package/dist/src/utils/filesearch/result-cache.test.js.map +1 -0
- package/dist/src/utils/flashFallback.integration.test.d.ts +6 -0
- package/dist/src/utils/flashFallback.integration.test.js +118 -0
- package/dist/src/utils/flashFallback.integration.test.js.map +1 -0
- package/dist/src/utils/formatters.d.ts +6 -0
- package/dist/src/utils/formatters.js +16 -0
- package/dist/src/utils/formatters.js.map +1 -0
- package/dist/src/utils/generateContentResponseUtilities.d.ts +13 -0
- package/dist/src/utils/generateContentResponseUtilities.js +80 -0
- package/dist/src/utils/generateContentResponseUtilities.js.map +1 -0
- package/dist/src/utils/generateContentResponseUtilities.test.d.ts +6 -0
- package/dist/src/utils/generateContentResponseUtilities.test.js +235 -0
- package/dist/src/utils/generateContentResponseUtilities.test.js.map +1 -0
- package/dist/src/utils/getFolderStructure.d.ts +31 -0
- package/dist/src/utils/getFolderStructure.js +246 -0
- package/dist/src/utils/getFolderStructure.js.map +1 -0
- package/dist/src/utils/getFolderStructure.test.d.ts +6 -0
- package/dist/src/utils/getFolderStructure.test.js +282 -0
- package/dist/src/utils/getFolderStructure.test.js.map +1 -0
- 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/gitIgnoreParser.d.ts +20 -0
- package/dist/src/utils/gitIgnoreParser.js +61 -0
- package/dist/src/utils/gitIgnoreParser.js.map +1 -0
- package/dist/src/utils/gitIgnoreParser.test.d.ts +6 -0
- package/dist/src/utils/gitIgnoreParser.test.js +154 -0
- package/dist/src/utils/gitIgnoreParser.test.js.map +1 -0
- package/dist/src/utils/gitUtils.d.ts +17 -0
- package/dist/src/utils/gitUtils.js +61 -0
- package/dist/src/utils/gitUtils.js.map +1 -0
- package/dist/src/utils/ignorePatterns.d.ts +103 -0
- package/dist/src/utils/ignorePatterns.js +220 -0
- package/dist/src/utils/ignorePatterns.js.map +1 -0
- package/dist/src/utils/ignorePatterns.test.d.ts +6 -0
- package/dist/src/utils/ignorePatterns.test.js +250 -0
- package/dist/src/utils/ignorePatterns.test.js.map +1 -0
- package/dist/src/utils/installationManager.d.ts +16 -0
- package/dist/src/utils/installationManager.js +50 -0
- package/dist/src/utils/installationManager.js.map +1 -0
- package/dist/src/utils/installationManager.test.d.ts +6 -0
- package/dist/src/utils/installationManager.test.js +83 -0
- package/dist/src/utils/installationManager.test.js.map +1 -0
- package/dist/src/utils/language-detection.d.ts +6 -0
- package/dist/src/utils/language-detection.js +101 -0
- package/dist/src/utils/language-detection.js.map +1 -0
- package/dist/src/utils/memoryDiscovery.d.ts +15 -0
- package/dist/src/utils/memoryDiscovery.js +253 -0
- package/dist/src/utils/memoryDiscovery.js.map +1 -0
- package/dist/src/utils/memoryDiscovery.test.d.ts +6 -0
- package/dist/src/utils/memoryDiscovery.test.js +219 -0
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -0
- package/dist/src/utils/memoryImportProcessor.d.ts +42 -0
- package/dist/src/utils/memoryImportProcessor.js +296 -0
- package/dist/src/utils/memoryImportProcessor.js.map +1 -0
- package/dist/src/utils/memoryImportProcessor.test.d.ts +6 -0
- package/dist/src/utils/memoryImportProcessor.test.js +573 -0
- package/dist/src/utils/memoryImportProcessor.test.js.map +1 -0
- package/dist/src/utils/messageInspectors.d.ts +8 -0
- package/dist/src/utils/messageInspectors.js +16 -0
- package/dist/src/utils/messageInspectors.js.map +1 -0
- package/dist/src/utils/nextSpeakerChecker.d.ts +12 -0
- package/dist/src/utils/nextSpeakerChecker.js +91 -0
- package/dist/src/utils/nextSpeakerChecker.js.map +1 -0
- package/dist/src/utils/nextSpeakerChecker.test.d.ts +6 -0
- package/dist/src/utils/nextSpeakerChecker.test.js +168 -0
- package/dist/src/utils/nextSpeakerChecker.test.js.map +1 -0
- package/dist/src/utils/partUtils.d.ts +35 -0
- package/dist/src/utils/partUtils.js +133 -0
- package/dist/src/utils/partUtils.js.map +1 -0
- package/dist/src/utils/partUtils.test.d.ts +6 -0
- package/dist/src/utils/partUtils.test.js +241 -0
- package/dist/src/utils/partUtils.test.js.map +1 -0
- package/dist/src/utils/pathReader.d.ts +17 -0
- package/dist/src/utils/pathReader.js +92 -0
- package/dist/src/utils/pathReader.js.map +1 -0
- package/dist/src/utils/pathReader.test.d.ts +6 -0
- package/dist/src/utils/pathReader.test.js +363 -0
- package/dist/src/utils/pathReader.test.js.map +1 -0
- package/dist/src/utils/paths.d.ts +58 -0
- package/dist/src/utils/paths.js +159 -0
- package/dist/src/utils/paths.js.map +1 -0
- package/dist/src/utils/paths.test.d.ts +6 -0
- package/dist/src/utils/paths.test.js +225 -0
- package/dist/src/utils/paths.test.js.map +1 -0
- package/dist/src/utils/quotaErrorDetection.d.ts +18 -0
- package/dist/src/utils/quotaErrorDetection.js +65 -0
- package/dist/src/utils/quotaErrorDetection.js.map +1 -0
- package/dist/src/utils/retry.d.ts +30 -0
- package/dist/src/utils/retry.js +276 -0
- package/dist/src/utils/retry.js.map +1 -0
- package/dist/src/utils/retry.test.d.ts +6 -0
- package/dist/src/utils/retry.test.js +325 -0
- package/dist/src/utils/retry.test.js.map +1 -0
- package/dist/src/utils/safeJsonStringify.d.ts +13 -0
- package/dist/src/utils/safeJsonStringify.js +25 -0
- package/dist/src/utils/safeJsonStringify.js.map +1 -0
- package/dist/src/utils/safeJsonStringify.test.d.ts +6 -0
- package/dist/src/utils/safeJsonStringify.test.js +61 -0
- package/dist/src/utils/safeJsonStringify.test.js.map +1 -0
- package/dist/src/utils/schemaValidator.d.ts +15 -0
- package/dist/src/utils/schemaValidator.js +38 -0
- package/dist/src/utils/schemaValidator.js.map +1 -0
- package/dist/src/utils/secure-browser-launcher.d.ts +23 -0
- package/dist/src/utils/secure-browser-launcher.js +165 -0
- package/dist/src/utils/secure-browser-launcher.js.map +1 -0
- package/dist/src/utils/secure-browser-launcher.test.d.ts +6 -0
- package/dist/src/utils/secure-browser-launcher.test.js +149 -0
- package/dist/src/utils/secure-browser-launcher.test.js.map +1 -0
- package/dist/src/utils/session.d.ts +6 -0
- package/dist/src/utils/session.js +8 -0
- package/dist/src/utils/session.js.map +1 -0
- package/dist/src/utils/shell-utils.d.ts +117 -0
- package/dist/src/utils/shell-utils.js +370 -0
- package/dist/src/utils/shell-utils.js.map +1 -0
- package/dist/src/utils/shell-utils.test.d.ts +6 -0
- package/dist/src/utils/shell-utils.test.js +332 -0
- package/dist/src/utils/shell-utils.test.js.map +1 -0
- package/dist/src/utils/summarizer.d.ts +25 -0
- package/dist/src/utils/summarizer.js +51 -0
- package/dist/src/utils/summarizer.js.map +1 -0
- package/dist/src/utils/summarizer.test.d.ts +6 -0
- package/dist/src/utils/summarizer.test.js +131 -0
- package/dist/src/utils/summarizer.test.js.map +1 -0
- package/dist/src/utils/systemEncoding.d.ts +40 -0
- package/dist/src/utils/systemEncoding.js +149 -0
- package/dist/src/utils/systemEncoding.js.map +1 -0
- package/dist/src/utils/systemEncoding.test.d.ts +6 -0
- package/dist/src/utils/systemEncoding.test.js +368 -0
- package/dist/src/utils/systemEncoding.test.js.map +1 -0
- package/dist/src/utils/testUtils.d.ts +29 -0
- package/dist/src/utils/testUtils.js +70 -0
- package/dist/src/utils/testUtils.js.map +1 -0
- package/dist/src/utils/textUtils.d.ts +13 -0
- package/dist/src/utils/textUtils.js +28 -0
- package/dist/src/utils/textUtils.js.map +1 -0
- package/dist/src/utils/tool-utils.d.ts +19 -0
- package/dist/src/utils/tool-utils.js +58 -0
- package/dist/src/utils/tool-utils.js.map +1 -0
- package/dist/src/utils/tool-utils.test.d.ts +6 -0
- package/dist/src/utils/tool-utils.test.js +61 -0
- package/dist/src/utils/tool-utils.test.js.map +1 -0
- package/dist/src/utils/userAccountManager.d.ts +20 -0
- package/dist/src/utils/userAccountManager.js +114 -0
- package/dist/src/utils/userAccountManager.js.map +1 -0
- package/dist/src/utils/userAccountManager.test.d.ts +6 -0
- package/dist/src/utils/userAccountManager.test.js +223 -0
- package/dist/src/utils/userAccountManager.test.js.map +1 -0
- package/dist/src/utils/workspaceContext.d.ts +66 -0
- package/dist/src/utils/workspaceContext.js +171 -0
- package/dist/src/utils/workspaceContext.js.map +1 -0
- package/dist/src/utils/workspaceContext.test.d.ts +6 -0
- package/dist/src/utils/workspaceContext.test.js +318 -0
- package/dist/src/utils/workspaceContext.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { BaseDeclarativeTool, BaseToolInvocation, Kind, ToolConfirmationOutcome, } from './tools.js';
|
|
7
|
+
import { ToolErrorType } from './tool-error.js';
|
|
8
|
+
import { getErrorMessage } from '../utils/errors.js';
|
|
9
|
+
import { ApprovalMode } from '../config/config.js';
|
|
10
|
+
import { getResponseText } from '../utils/partUtils.js';
|
|
11
|
+
import { fetchWithTimeout, isPrivateIp } from '../utils/fetch.js';
|
|
12
|
+
import { convert } from 'html-to-text';
|
|
13
|
+
import { ProxyAgent, setGlobalDispatcher } from 'undici';
|
|
14
|
+
const URL_FETCH_TIMEOUT_MS = 10000;
|
|
15
|
+
const MAX_CONTENT_LENGTH = 100000;
|
|
16
|
+
// Helper function to extract URLs from a string
|
|
17
|
+
function extractUrls(text) {
|
|
18
|
+
const urlRegex = /(https?:\/\/[^\s]+)/g;
|
|
19
|
+
return text.match(urlRegex) || [];
|
|
20
|
+
}
|
|
21
|
+
class WebFetchToolInvocation extends BaseToolInvocation {
|
|
22
|
+
config;
|
|
23
|
+
constructor(config, params) {
|
|
24
|
+
super(params);
|
|
25
|
+
this.config = config;
|
|
26
|
+
}
|
|
27
|
+
async executeFallback(signal) {
|
|
28
|
+
const urls = extractUrls(this.params.prompt);
|
|
29
|
+
// For now, we only support one URL for fallback
|
|
30
|
+
let url = urls[0];
|
|
31
|
+
// Convert GitHub blob URL to raw URL
|
|
32
|
+
if (url.includes('github.com') && url.includes('/blob/')) {
|
|
33
|
+
url = url
|
|
34
|
+
.replace('github.com', 'raw.githubusercontent.com')
|
|
35
|
+
.replace('/blob/', '/');
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const response = await fetchWithTimeout(url, URL_FETCH_TIMEOUT_MS);
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
throw new Error(`Request failed with status code ${response.status} ${response.statusText}`);
|
|
41
|
+
}
|
|
42
|
+
const html = await response.text();
|
|
43
|
+
const textContent = convert(html, {
|
|
44
|
+
wordwrap: false,
|
|
45
|
+
selectors: [
|
|
46
|
+
{ selector: 'a', options: { ignoreHref: true } },
|
|
47
|
+
{ selector: 'img', format: 'skip' },
|
|
48
|
+
],
|
|
49
|
+
}).substring(0, MAX_CONTENT_LENGTH);
|
|
50
|
+
const geminiClient = this.config.getGeminiClient();
|
|
51
|
+
const fallbackPrompt = `The user requested the following: "${this.params.prompt}".
|
|
52
|
+
|
|
53
|
+
I was unable to access the URL directly. Instead, I have fetched the raw content of the page. Please use the following content to answer the request. Do not attempt to access the URL again.
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
${textContent}
|
|
57
|
+
---
|
|
58
|
+
`;
|
|
59
|
+
const result = await geminiClient.generateContent([{ role: 'user', parts: [{ text: fallbackPrompt }] }], {}, signal);
|
|
60
|
+
const resultText = getResponseText(result) || '';
|
|
61
|
+
return {
|
|
62
|
+
llmContent: resultText,
|
|
63
|
+
returnDisplay: `Content for ${url} processed using fallback fetch.`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
const error = e;
|
|
68
|
+
const errorMessage = `Error during fallback fetch for ${url}: ${error.message}`;
|
|
69
|
+
return {
|
|
70
|
+
llmContent: `Error: ${errorMessage}`,
|
|
71
|
+
returnDisplay: `Error: ${errorMessage}`,
|
|
72
|
+
error: {
|
|
73
|
+
message: errorMessage,
|
|
74
|
+
type: ToolErrorType.WEB_FETCH_FALLBACK_FAILED,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
getDescription() {
|
|
80
|
+
const displayPrompt = this.params.prompt.length > 100
|
|
81
|
+
? this.params.prompt.substring(0, 97) + '...'
|
|
82
|
+
: this.params.prompt;
|
|
83
|
+
return `Processing URLs and instructions from prompt: "${displayPrompt}"`;
|
|
84
|
+
}
|
|
85
|
+
async shouldConfirmExecute() {
|
|
86
|
+
if (this.config.getApprovalMode() === ApprovalMode.AUTO_EDIT) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
// Perform GitHub URL conversion here to differentiate between user-provided
|
|
90
|
+
// URL and the actual URL to be fetched.
|
|
91
|
+
const urls = extractUrls(this.params.prompt).map((url) => {
|
|
92
|
+
if (url.includes('github.com') && url.includes('/blob/')) {
|
|
93
|
+
return url
|
|
94
|
+
.replace('github.com', 'raw.githubusercontent.com')
|
|
95
|
+
.replace('/blob/', '/');
|
|
96
|
+
}
|
|
97
|
+
return url;
|
|
98
|
+
});
|
|
99
|
+
const confirmationDetails = {
|
|
100
|
+
type: 'info',
|
|
101
|
+
title: `Confirm Web Fetch`,
|
|
102
|
+
prompt: this.params.prompt,
|
|
103
|
+
urls,
|
|
104
|
+
onConfirm: async (outcome) => {
|
|
105
|
+
if (outcome === ToolConfirmationOutcome.ProceedAlways) {
|
|
106
|
+
this.config.setApprovalMode(ApprovalMode.AUTO_EDIT);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
return confirmationDetails;
|
|
111
|
+
}
|
|
112
|
+
async execute(signal) {
|
|
113
|
+
const userPrompt = this.params.prompt;
|
|
114
|
+
const urls = extractUrls(userPrompt);
|
|
115
|
+
const url = urls[0];
|
|
116
|
+
const isPrivate = isPrivateIp(url);
|
|
117
|
+
if (isPrivate) {
|
|
118
|
+
return this.executeFallback(signal);
|
|
119
|
+
}
|
|
120
|
+
const geminiClient = this.config.getGeminiClient();
|
|
121
|
+
try {
|
|
122
|
+
const response = await geminiClient.generateContent([{ role: 'user', parts: [{ text: userPrompt }] }], { tools: [{ urlContext: {} }] }, signal);
|
|
123
|
+
console.debug(`[WebFetchTool] Full response for prompt "${userPrompt.substring(0, 50)}...":`, JSON.stringify(response, null, 2));
|
|
124
|
+
let responseText = getResponseText(response) || '';
|
|
125
|
+
const urlContextMeta = response.candidates?.[0]?.urlContextMetadata;
|
|
126
|
+
const groundingMetadata = response.candidates?.[0]?.groundingMetadata;
|
|
127
|
+
const sources = groundingMetadata?.groundingChunks;
|
|
128
|
+
const groundingSupports = groundingMetadata?.groundingSupports;
|
|
129
|
+
// Error Handling
|
|
130
|
+
let processingError = false;
|
|
131
|
+
if (urlContextMeta?.urlMetadata &&
|
|
132
|
+
urlContextMeta.urlMetadata.length > 0) {
|
|
133
|
+
const allStatuses = urlContextMeta.urlMetadata.map((m) => m.urlRetrievalStatus);
|
|
134
|
+
if (allStatuses.every((s) => s !== 'URL_RETRIEVAL_STATUS_SUCCESS')) {
|
|
135
|
+
processingError = true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else if (!responseText.trim() && !sources?.length) {
|
|
139
|
+
// No URL metadata and no content/sources
|
|
140
|
+
processingError = true;
|
|
141
|
+
}
|
|
142
|
+
if (!processingError &&
|
|
143
|
+
!responseText.trim() &&
|
|
144
|
+
(!sources || sources.length === 0)) {
|
|
145
|
+
// Successfully retrieved some URL (or no specific error from urlContextMeta), but no usable text or grounding data.
|
|
146
|
+
processingError = true;
|
|
147
|
+
}
|
|
148
|
+
if (processingError) {
|
|
149
|
+
return this.executeFallback(signal);
|
|
150
|
+
}
|
|
151
|
+
const sourceListFormatted = [];
|
|
152
|
+
if (sources && sources.length > 0) {
|
|
153
|
+
sources.forEach((source, index) => {
|
|
154
|
+
const title = source.web?.title || 'Untitled';
|
|
155
|
+
const uri = source.web?.uri || 'Unknown URI'; // Fallback if URI is missing
|
|
156
|
+
sourceListFormatted.push(`[${index + 1}] ${title} (${uri})`);
|
|
157
|
+
});
|
|
158
|
+
if (groundingSupports && groundingSupports.length > 0) {
|
|
159
|
+
const insertions = [];
|
|
160
|
+
groundingSupports.forEach((support) => {
|
|
161
|
+
if (support.segment && support.groundingChunkIndices) {
|
|
162
|
+
const citationMarker = support.groundingChunkIndices
|
|
163
|
+
.map((chunkIndex) => `[${chunkIndex + 1}]`)
|
|
164
|
+
.join('');
|
|
165
|
+
insertions.push({
|
|
166
|
+
index: support.segment.endIndex,
|
|
167
|
+
marker: citationMarker,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
insertions.sort((a, b) => b.index - a.index);
|
|
172
|
+
const responseChars = responseText.split('');
|
|
173
|
+
insertions.forEach((insertion) => {
|
|
174
|
+
responseChars.splice(insertion.index, 0, insertion.marker);
|
|
175
|
+
});
|
|
176
|
+
responseText = responseChars.join('');
|
|
177
|
+
}
|
|
178
|
+
if (sourceListFormatted.length > 0) {
|
|
179
|
+
responseText += `
|
|
180
|
+
|
|
181
|
+
Sources:
|
|
182
|
+
${sourceListFormatted.join('\n')}`;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const llmContent = responseText;
|
|
186
|
+
console.debug(`[WebFetchTool] Formatted tool response for prompt "${userPrompt}:\n\n":`, llmContent);
|
|
187
|
+
return {
|
|
188
|
+
llmContent,
|
|
189
|
+
returnDisplay: `Content processed from prompt.`,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
const errorMessage = `Error processing web content for prompt "${userPrompt.substring(0, 50)}...": ${getErrorMessage(error)}`;
|
|
194
|
+
console.error(errorMessage, error);
|
|
195
|
+
return {
|
|
196
|
+
llmContent: `Error: ${errorMessage}`,
|
|
197
|
+
returnDisplay: `Error: ${errorMessage}`,
|
|
198
|
+
error: {
|
|
199
|
+
message: errorMessage,
|
|
200
|
+
type: ToolErrorType.WEB_FETCH_PROCESSING_ERROR,
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Implementation of the WebFetch tool logic
|
|
208
|
+
*/
|
|
209
|
+
export class WebFetchTool extends BaseDeclarativeTool {
|
|
210
|
+
config;
|
|
211
|
+
static Name = 'web_fetch';
|
|
212
|
+
constructor(config) {
|
|
213
|
+
super(WebFetchTool.Name, 'WebFetch', "Processes content from URL(s), including local and private network addresses (e.g., localhost), embedded in a prompt. Include up to 20 URLs and instructions (e.g., summarize, extract specific data) directly in the 'prompt' parameter.", Kind.Fetch, {
|
|
214
|
+
properties: {
|
|
215
|
+
prompt: {
|
|
216
|
+
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://.',
|
|
217
|
+
type: 'string',
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
required: ['prompt'],
|
|
221
|
+
type: 'object',
|
|
222
|
+
});
|
|
223
|
+
this.config = config;
|
|
224
|
+
const proxy = config.getProxy();
|
|
225
|
+
if (proxy) {
|
|
226
|
+
setGlobalDispatcher(new ProxyAgent(proxy));
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
validateToolParamValues(params) {
|
|
230
|
+
if (!params.prompt || params.prompt.trim() === '') {
|
|
231
|
+
return "The 'prompt' parameter cannot be empty and must contain URL(s) and instructions.";
|
|
232
|
+
}
|
|
233
|
+
if (!params.prompt.includes('http://') &&
|
|
234
|
+
!params.prompt.includes('https://')) {
|
|
235
|
+
return "The 'prompt' must contain at least one valid URL (starting with http:// or https://).";
|
|
236
|
+
}
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
createInvocation(params) {
|
|
240
|
+
return new WebFetchToolInvocation(this.config, params);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=web-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-fetch.js","sourceRoot":"","sources":["../../../src/tools/web-fetch.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,IAAI,EACJ,uBAAuB,GACxB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAEzD,MAAM,oBAAoB,GAAG,KAAK,CAAC;AACnC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,gDAAgD;AAChD,SAAS,WAAW,CAAC,IAAY;IAC/B,MAAM,QAAQ,GAAG,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C,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EACnC,CAAC;YACD,OAAO,uFAAuF,CAAC;QACjG,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAES,gBAAgB,CACxB,MAA0B;QAE1B,OAAO,IAAI,sBAAsB,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
7
|
+
import { WebFetchTool } from './web-fetch.js';
|
|
8
|
+
import { ApprovalMode } from '../config/config.js';
|
|
9
|
+
import { ToolConfirmationOutcome } from './tools.js';
|
|
10
|
+
import { ToolErrorType } from './tool-error.js';
|
|
11
|
+
import * as fetchUtils from '../utils/fetch.js';
|
|
12
|
+
const mockGenerateContent = vi.fn();
|
|
13
|
+
const mockGetGeminiClient = vi.fn(() => ({
|
|
14
|
+
generateContent: mockGenerateContent,
|
|
15
|
+
}));
|
|
16
|
+
vi.mock('../utils/fetch.js', async (importOriginal) => {
|
|
17
|
+
const actual = await importOriginal();
|
|
18
|
+
return {
|
|
19
|
+
...actual,
|
|
20
|
+
fetchWithTimeout: vi.fn(),
|
|
21
|
+
isPrivateIp: vi.fn(),
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
describe('WebFetchTool', () => {
|
|
25
|
+
let mockConfig;
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
vi.resetAllMocks();
|
|
28
|
+
mockConfig = {
|
|
29
|
+
getApprovalMode: vi.fn(),
|
|
30
|
+
setApprovalMode: vi.fn(),
|
|
31
|
+
getProxy: vi.fn(),
|
|
32
|
+
getGeminiClient: mockGetGeminiClient,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
describe('execute', () => {
|
|
36
|
+
it('should return WEB_FETCH_NO_URL_IN_PROMPT when no URL is in the prompt for fallback', async () => {
|
|
37
|
+
vi.spyOn(fetchUtils, 'isPrivateIp').mockReturnValue(true);
|
|
38
|
+
const tool = new WebFetchTool(mockConfig);
|
|
39
|
+
const params = { prompt: 'no url here' };
|
|
40
|
+
expect(() => tool.build(params)).toThrow("The 'prompt' must contain at least one valid URL (starting with http:// or https://).");
|
|
41
|
+
});
|
|
42
|
+
it('should return WEB_FETCH_FALLBACK_FAILED on fallback fetch failure', async () => {
|
|
43
|
+
vi.spyOn(fetchUtils, 'isPrivateIp').mockReturnValue(true);
|
|
44
|
+
vi.spyOn(fetchUtils, 'fetchWithTimeout').mockRejectedValue(new Error('fetch failed'));
|
|
45
|
+
const tool = new WebFetchTool(mockConfig);
|
|
46
|
+
const params = { prompt: 'fetch https://private.ip' };
|
|
47
|
+
const invocation = tool.build(params);
|
|
48
|
+
const result = await invocation.execute(new AbortController().signal);
|
|
49
|
+
expect(result.error?.type).toBe(ToolErrorType.WEB_FETCH_FALLBACK_FAILED);
|
|
50
|
+
});
|
|
51
|
+
it('should return WEB_FETCH_PROCESSING_ERROR on general processing failure', async () => {
|
|
52
|
+
vi.spyOn(fetchUtils, 'isPrivateIp').mockReturnValue(false);
|
|
53
|
+
mockGenerateContent.mockRejectedValue(new Error('API error'));
|
|
54
|
+
const tool = new WebFetchTool(mockConfig);
|
|
55
|
+
const params = { prompt: 'fetch https://public.ip' };
|
|
56
|
+
const invocation = tool.build(params);
|
|
57
|
+
const result = await invocation.execute(new AbortController().signal);
|
|
58
|
+
expect(result.error?.type).toBe(ToolErrorType.WEB_FETCH_PROCESSING_ERROR);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
describe('shouldConfirmExecute', () => {
|
|
62
|
+
it('should return confirmation details with the correct prompt and urls', async () => {
|
|
63
|
+
const tool = new WebFetchTool(mockConfig);
|
|
64
|
+
const params = { prompt: 'fetch https://example.com' };
|
|
65
|
+
const invocation = tool.build(params);
|
|
66
|
+
const confirmationDetails = await invocation.shouldConfirmExecute(new AbortController().signal);
|
|
67
|
+
expect(confirmationDetails).toEqual({
|
|
68
|
+
type: 'info',
|
|
69
|
+
title: 'Confirm Web Fetch',
|
|
70
|
+
prompt: 'fetch https://example.com',
|
|
71
|
+
urls: ['https://example.com'],
|
|
72
|
+
onConfirm: expect.any(Function),
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
it('should convert github urls to raw format', async () => {
|
|
76
|
+
const tool = new WebFetchTool(mockConfig);
|
|
77
|
+
const params = {
|
|
78
|
+
prompt: 'fetch https://github.com/google/gemini-react/blob/main/README.md',
|
|
79
|
+
};
|
|
80
|
+
const invocation = tool.build(params);
|
|
81
|
+
const confirmationDetails = await invocation.shouldConfirmExecute(new AbortController().signal);
|
|
82
|
+
expect(confirmationDetails).toEqual({
|
|
83
|
+
type: 'info',
|
|
84
|
+
title: 'Confirm Web Fetch',
|
|
85
|
+
prompt: 'fetch https://github.com/google/gemini-react/blob/main/README.md',
|
|
86
|
+
urls: [
|
|
87
|
+
'https://raw.githubusercontent.com/google/gemini-react/main/README.md',
|
|
88
|
+
],
|
|
89
|
+
onConfirm: expect.any(Function),
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
it('should return false if approval mode is AUTO_EDIT', async () => {
|
|
93
|
+
vi.spyOn(mockConfig, 'getApprovalMode').mockReturnValue(ApprovalMode.AUTO_EDIT);
|
|
94
|
+
const tool = new WebFetchTool(mockConfig);
|
|
95
|
+
const params = { prompt: 'fetch https://example.com' };
|
|
96
|
+
const invocation = tool.build(params);
|
|
97
|
+
const confirmationDetails = await invocation.shouldConfirmExecute(new AbortController().signal);
|
|
98
|
+
expect(confirmationDetails).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
it('should call setApprovalMode when onConfirm is called with ProceedAlways', async () => {
|
|
101
|
+
const tool = new WebFetchTool(mockConfig);
|
|
102
|
+
const params = { prompt: 'fetch https://example.com' };
|
|
103
|
+
const invocation = tool.build(params);
|
|
104
|
+
const confirmationDetails = await invocation.shouldConfirmExecute(new AbortController().signal);
|
|
105
|
+
if (confirmationDetails &&
|
|
106
|
+
typeof confirmationDetails === 'object' &&
|
|
107
|
+
'onConfirm' in confirmationDetails) {
|
|
108
|
+
await confirmationDetails.onConfirm(ToolConfirmationOutcome.ProceedAlways);
|
|
109
|
+
}
|
|
110
|
+
expect(mockConfig.setApprovalMode).toHaveBeenCalledWith(ApprovalMode.AUTO_EDIT);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
//# sourceMappingURL=web-fetch.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-fetch.test.js","sourceRoot":"","sources":["../../../src/tools/web-fetch.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAC;AAEhD,MAAM,mBAAmB,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;AACpC,MAAM,mBAAmB,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IACvC,eAAe,EAAE,mBAAmB;CACrC,CAAC,CAAC,CAAC;AAEJ,EAAE,CAAC,IAAI,CAAC,mBAAmB,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE;IACpD,MAAM,MAAM,GAAG,MAAM,cAAc,EAAqB,CAAC;IACzD,OAAO;QACL,GAAG,MAAM;QACT,gBAAgB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import type { ToolInvocation, ToolResult } from './tools.js';
|
|
8
|
+
import { BaseDeclarativeTool } from './tools.js';
|
|
9
|
+
import type { Config } from '../config/config.js';
|
|
10
|
+
interface GroundingChunkWeb {
|
|
11
|
+
uri?: string;
|
|
12
|
+
title?: string;
|
|
13
|
+
}
|
|
14
|
+
interface GroundingChunkItem {
|
|
15
|
+
web?: GroundingChunkWeb;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parameters for the WebSearchTool.
|
|
19
|
+
*/
|
|
20
|
+
export interface WebSearchToolParams {
|
|
21
|
+
/**
|
|
22
|
+
* The search query.
|
|
23
|
+
*/
|
|
24
|
+
query: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Extends ToolResult to include sources for web search.
|
|
28
|
+
*/
|
|
29
|
+
export interface WebSearchToolResult extends ToolResult {
|
|
30
|
+
sources?: GroundingMetadata extends {
|
|
31
|
+
groundingChunks: GroundingChunkItem[];
|
|
32
|
+
} ? GroundingMetadata['groundingChunks'] : GroundingChunkItem[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A tool to perform web searches using Google Search via the Gemini API.
|
|
36
|
+
*/
|
|
37
|
+
export declare class WebSearchTool extends BaseDeclarativeTool<WebSearchToolParams, WebSearchToolResult> {
|
|
38
|
+
private readonly config;
|
|
39
|
+
static readonly Name: string;
|
|
40
|
+
constructor(config: Config);
|
|
41
|
+
/**
|
|
42
|
+
* Validates the parameters for the WebSearchTool.
|
|
43
|
+
* @param params The parameters to validate
|
|
44
|
+
* @returns An error message string if validation fails, null if valid
|
|
45
|
+
*/
|
|
46
|
+
protected validateToolParamValues(params: WebSearchToolParams): string | null;
|
|
47
|
+
protected createInvocation(params: WebSearchToolParams): ToolInvocation<WebSearchToolParams, WebSearchToolResult>;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { BaseDeclarativeTool, BaseToolInvocation, Kind } from './tools.js';
|
|
7
|
+
import { ToolErrorType } from './tool-error.js';
|
|
8
|
+
import { getErrorMessage } from '../utils/errors.js';
|
|
9
|
+
import { getResponseText } from '../utils/partUtils.js';
|
|
10
|
+
class WebSearchToolInvocation extends BaseToolInvocation {
|
|
11
|
+
config;
|
|
12
|
+
constructor(config, params) {
|
|
13
|
+
super(params);
|
|
14
|
+
this.config = config;
|
|
15
|
+
}
|
|
16
|
+
getDescription() {
|
|
17
|
+
return `Searching the web for: "${this.params.query}"`;
|
|
18
|
+
}
|
|
19
|
+
async execute(signal) {
|
|
20
|
+
const geminiClient = this.config.getGeminiClient();
|
|
21
|
+
try {
|
|
22
|
+
const response = await geminiClient.generateContent([{ role: 'user', parts: [{ text: this.params.query }] }], { tools: [{ googleSearch: {} }] }, signal);
|
|
23
|
+
const responseText = getResponseText(response);
|
|
24
|
+
const groundingMetadata = response.candidates?.[0]?.groundingMetadata;
|
|
25
|
+
const sources = groundingMetadata?.groundingChunks;
|
|
26
|
+
const groundingSupports = groundingMetadata?.groundingSupports;
|
|
27
|
+
if (!responseText || !responseText.trim()) {
|
|
28
|
+
return {
|
|
29
|
+
llmContent: `No search results or information found for query: "${this.params.query}"`,
|
|
30
|
+
returnDisplay: 'No information found.',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
let modifiedResponseText = responseText;
|
|
34
|
+
const sourceListFormatted = [];
|
|
35
|
+
if (sources && sources.length > 0) {
|
|
36
|
+
sources.forEach((source, index) => {
|
|
37
|
+
const title = source.web?.title || 'Untitled';
|
|
38
|
+
const uri = source.web?.uri || 'No URI';
|
|
39
|
+
sourceListFormatted.push(`[${index + 1}] ${title} (${uri})`);
|
|
40
|
+
});
|
|
41
|
+
if (groundingSupports && groundingSupports.length > 0) {
|
|
42
|
+
const insertions = [];
|
|
43
|
+
groundingSupports.forEach((support) => {
|
|
44
|
+
if (support.segment && support.groundingChunkIndices) {
|
|
45
|
+
const citationMarker = support.groundingChunkIndices
|
|
46
|
+
.map((chunkIndex) => `[${chunkIndex + 1}]`)
|
|
47
|
+
.join('');
|
|
48
|
+
insertions.push({
|
|
49
|
+
index: support.segment.endIndex,
|
|
50
|
+
marker: citationMarker,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
// Sort insertions by index in descending order to avoid shifting subsequent indices
|
|
55
|
+
insertions.sort((a, b) => b.index - a.index);
|
|
56
|
+
// Use TextEncoder/TextDecoder since segment indices are UTF-8 byte positions
|
|
57
|
+
const encoder = new TextEncoder();
|
|
58
|
+
const responseBytes = encoder.encode(modifiedResponseText);
|
|
59
|
+
const parts = [];
|
|
60
|
+
let lastIndex = responseBytes.length;
|
|
61
|
+
for (const ins of insertions) {
|
|
62
|
+
const pos = Math.min(ins.index, lastIndex);
|
|
63
|
+
parts.unshift(responseBytes.subarray(pos, lastIndex));
|
|
64
|
+
parts.unshift(encoder.encode(ins.marker));
|
|
65
|
+
lastIndex = pos;
|
|
66
|
+
}
|
|
67
|
+
parts.unshift(responseBytes.subarray(0, lastIndex));
|
|
68
|
+
// Concatenate all parts into a single buffer
|
|
69
|
+
const totalLength = parts.reduce((sum, part) => sum + part.length, 0);
|
|
70
|
+
const finalBytes = new Uint8Array(totalLength);
|
|
71
|
+
let offset = 0;
|
|
72
|
+
for (const part of parts) {
|
|
73
|
+
finalBytes.set(part, offset);
|
|
74
|
+
offset += part.length;
|
|
75
|
+
}
|
|
76
|
+
modifiedResponseText = new TextDecoder().decode(finalBytes);
|
|
77
|
+
}
|
|
78
|
+
if (sourceListFormatted.length > 0) {
|
|
79
|
+
modifiedResponseText +=
|
|
80
|
+
'\n\nSources:\n' + sourceListFormatted.join('\n');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
llmContent: `Web search results for "${this.params.query}":\n\n${modifiedResponseText}`,
|
|
85
|
+
returnDisplay: `Search results for "${this.params.query}" returned.`,
|
|
86
|
+
sources,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
const errorMessage = `Error during web search for query "${this.params.query}": ${getErrorMessage(error)}`;
|
|
91
|
+
console.error(errorMessage, error);
|
|
92
|
+
return {
|
|
93
|
+
llmContent: `Error: ${errorMessage}`,
|
|
94
|
+
returnDisplay: `Error performing web search.`,
|
|
95
|
+
error: {
|
|
96
|
+
message: errorMessage,
|
|
97
|
+
type: ToolErrorType.WEB_SEARCH_FAILED,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* A tool to perform web searches using Google Search via the Gemini API.
|
|
105
|
+
*/
|
|
106
|
+
export class WebSearchTool extends BaseDeclarativeTool {
|
|
107
|
+
config;
|
|
108
|
+
static Name = 'google_web_search';
|
|
109
|
+
constructor(config) {
|
|
110
|
+
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, {
|
|
111
|
+
type: 'object',
|
|
112
|
+
properties: {
|
|
113
|
+
query: {
|
|
114
|
+
type: 'string',
|
|
115
|
+
description: 'The search query to find information on the web.',
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
required: ['query'],
|
|
119
|
+
});
|
|
120
|
+
this.config = config;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Validates the parameters for the WebSearchTool.
|
|
124
|
+
* @param params The parameters to validate
|
|
125
|
+
* @returns An error message string if validation fails, null if valid
|
|
126
|
+
*/
|
|
127
|
+
validateToolParamValues(params) {
|
|
128
|
+
if (!params.query || params.query.trim() === '') {
|
|
129
|
+
return "The 'query' parameter cannot be empty.";
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
createInvocation(params) {
|
|
134
|
+
return new WebSearchToolInvocation(this.config, params);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=web-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-search.js","sourceRoot":"","sources":["../../../src/tools/web-search.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AA4CxD,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,EA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