@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,923 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
7
|
+
import { CoreToolScheduler, convertToFunctionResponse, } from './coreToolScheduler.js';
|
|
8
|
+
import { BaseDeclarativeTool, BaseToolInvocation, ToolConfirmationOutcome, Kind, ApprovalMode, } from '../index.js';
|
|
9
|
+
import { MockModifiableTool, MockTool } from '../test-utils/tools.js';
|
|
10
|
+
class TestApprovalTool extends BaseDeclarativeTool {
|
|
11
|
+
config;
|
|
12
|
+
static Name = 'testApprovalTool';
|
|
13
|
+
constructor(config) {
|
|
14
|
+
super(TestApprovalTool.Name, 'TestApprovalTool', 'A tool for testing approval logic', Kind.Edit, {
|
|
15
|
+
properties: { id: { type: 'string' } },
|
|
16
|
+
required: ['id'],
|
|
17
|
+
type: 'object',
|
|
18
|
+
});
|
|
19
|
+
this.config = config;
|
|
20
|
+
}
|
|
21
|
+
createInvocation(params) {
|
|
22
|
+
return new TestApprovalInvocation(this.config, params);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
class TestApprovalInvocation extends BaseToolInvocation {
|
|
26
|
+
config;
|
|
27
|
+
constructor(config, params) {
|
|
28
|
+
super(params);
|
|
29
|
+
this.config = config;
|
|
30
|
+
}
|
|
31
|
+
getDescription() {
|
|
32
|
+
return `Test tool ${this.params.id}`;
|
|
33
|
+
}
|
|
34
|
+
async shouldConfirmExecute() {
|
|
35
|
+
// Need confirmation unless approval mode is AUTO_EDIT
|
|
36
|
+
if (this.config.getApprovalMode() === ApprovalMode.AUTO_EDIT) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
type: 'edit',
|
|
41
|
+
title: `Confirm Test Tool ${this.params.id}`,
|
|
42
|
+
fileName: `test-${this.params.id}.txt`,
|
|
43
|
+
filePath: `/test-${this.params.id}.txt`,
|
|
44
|
+
fileDiff: 'Test diff content',
|
|
45
|
+
originalContent: '',
|
|
46
|
+
newContent: 'Test content',
|
|
47
|
+
onConfirm: async (outcome) => {
|
|
48
|
+
if (outcome === ToolConfirmationOutcome.ProceedAlways) {
|
|
49
|
+
this.config.setApprovalMode(ApprovalMode.AUTO_EDIT);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async execute() {
|
|
55
|
+
return {
|
|
56
|
+
llmContent: `Executed test tool ${this.params.id}`,
|
|
57
|
+
returnDisplay: `Executed test tool ${this.params.id}`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function waitForStatus(onToolCallsUpdate, status, timeout = 5000) {
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
const startTime = Date.now();
|
|
64
|
+
const check = () => {
|
|
65
|
+
if (Date.now() - startTime > timeout) {
|
|
66
|
+
const seenStatuses = onToolCallsUpdate.mock.calls
|
|
67
|
+
.flatMap((call) => call[0])
|
|
68
|
+
.map((toolCall) => toolCall.status);
|
|
69
|
+
reject(new Error(`Timed out waiting for status "${status}". Seen statuses: ${seenStatuses.join(', ')}`));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const foundCall = onToolCallsUpdate.mock.calls
|
|
73
|
+
.flatMap((call) => call[0])
|
|
74
|
+
.find((toolCall) => toolCall.status === status);
|
|
75
|
+
if (foundCall) {
|
|
76
|
+
resolve(foundCall);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
setTimeout(check, 10); // Check again in 10ms
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
check();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
describe('CoreToolScheduler', () => {
|
|
86
|
+
it('should cancel a tool call if the signal is aborted before confirmation', async () => {
|
|
87
|
+
const mockTool = new MockTool();
|
|
88
|
+
mockTool.shouldConfirm = true;
|
|
89
|
+
const declarativeTool = mockTool;
|
|
90
|
+
const mockToolRegistry = {
|
|
91
|
+
getTool: () => declarativeTool,
|
|
92
|
+
getFunctionDeclarations: () => [],
|
|
93
|
+
tools: new Map(),
|
|
94
|
+
discovery: {},
|
|
95
|
+
registerTool: () => { },
|
|
96
|
+
getToolByName: () => declarativeTool,
|
|
97
|
+
getToolByDisplayName: () => declarativeTool,
|
|
98
|
+
getTools: () => [],
|
|
99
|
+
discoverTools: async () => { },
|
|
100
|
+
getAllTools: () => [],
|
|
101
|
+
getToolsByServer: () => [],
|
|
102
|
+
};
|
|
103
|
+
const onAllToolCallsComplete = vi.fn();
|
|
104
|
+
const onToolCallsUpdate = vi.fn();
|
|
105
|
+
const mockConfig = {
|
|
106
|
+
getSessionId: () => 'test-session-id',
|
|
107
|
+
getUsageStatisticsEnabled: () => true,
|
|
108
|
+
getDebugMode: () => false,
|
|
109
|
+
getApprovalMode: () => ApprovalMode.DEFAULT,
|
|
110
|
+
getAllowedTools: () => [],
|
|
111
|
+
getContentGeneratorConfig: () => ({
|
|
112
|
+
model: 'test-model',
|
|
113
|
+
authType: 'oauth-personal',
|
|
114
|
+
}),
|
|
115
|
+
getToolRegistry: () => mockToolRegistry,
|
|
116
|
+
};
|
|
117
|
+
const scheduler = new CoreToolScheduler({
|
|
118
|
+
config: mockConfig,
|
|
119
|
+
onAllToolCallsComplete,
|
|
120
|
+
onToolCallsUpdate,
|
|
121
|
+
getPreferredEditor: () => 'vscode',
|
|
122
|
+
onEditorClose: vi.fn(),
|
|
123
|
+
});
|
|
124
|
+
const abortController = new AbortController();
|
|
125
|
+
const request = {
|
|
126
|
+
callId: '1',
|
|
127
|
+
name: 'mockTool',
|
|
128
|
+
args: {},
|
|
129
|
+
isClientInitiated: false,
|
|
130
|
+
prompt_id: 'prompt-id-1',
|
|
131
|
+
};
|
|
132
|
+
abortController.abort();
|
|
133
|
+
await scheduler.schedule([request], abortController.signal);
|
|
134
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
135
|
+
const completedCalls = onAllToolCallsComplete.mock
|
|
136
|
+
.calls[0][0];
|
|
137
|
+
expect(completedCalls[0].status).toBe('cancelled');
|
|
138
|
+
});
|
|
139
|
+
describe('getToolSuggestion', () => {
|
|
140
|
+
it('should suggest the top N closest tool names for a typo', () => {
|
|
141
|
+
// Create mocked tool registry
|
|
142
|
+
const mockConfig = {
|
|
143
|
+
getToolRegistry: () => mockToolRegistry,
|
|
144
|
+
};
|
|
145
|
+
const mockToolRegistry = {
|
|
146
|
+
getAllToolNames: () => ['list_files', 'read_file', 'write_file'],
|
|
147
|
+
};
|
|
148
|
+
// Create scheduler
|
|
149
|
+
const scheduler = new CoreToolScheduler({
|
|
150
|
+
config: mockConfig,
|
|
151
|
+
getPreferredEditor: () => 'vscode',
|
|
152
|
+
onEditorClose: vi.fn(),
|
|
153
|
+
});
|
|
154
|
+
// Test that the right tool is selected, with only 1 result, for typos
|
|
155
|
+
// @ts-expect-error accessing private method
|
|
156
|
+
const misspelledTool = scheduler.getToolSuggestion('list_fils', 1);
|
|
157
|
+
expect(misspelledTool).toBe(' Did you mean "list_files"?');
|
|
158
|
+
// Test that the right tool is selected, with only 1 result, for prefixes
|
|
159
|
+
// @ts-expect-error accessing private method
|
|
160
|
+
const prefixedTool = scheduler.getToolSuggestion('github.list_files', 1);
|
|
161
|
+
expect(prefixedTool).toBe(' Did you mean "list_files"?');
|
|
162
|
+
// Test that the right tool is first
|
|
163
|
+
// @ts-expect-error accessing private method
|
|
164
|
+
const suggestionMultiple = scheduler.getToolSuggestion('list_fils');
|
|
165
|
+
expect(suggestionMultiple).toBe(' Did you mean one of: "list_files", "read_file", "write_file"?');
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
describe('CoreToolScheduler with payload', () => {
|
|
170
|
+
it('should update args and diff and execute tool when payload is provided', async () => {
|
|
171
|
+
const mockTool = new MockModifiableTool();
|
|
172
|
+
const declarativeTool = mockTool;
|
|
173
|
+
const mockToolRegistry = {
|
|
174
|
+
getTool: () => declarativeTool,
|
|
175
|
+
getFunctionDeclarations: () => [],
|
|
176
|
+
tools: new Map(),
|
|
177
|
+
discovery: {},
|
|
178
|
+
registerTool: () => { },
|
|
179
|
+
getToolByName: () => declarativeTool,
|
|
180
|
+
getToolByDisplayName: () => declarativeTool,
|
|
181
|
+
getTools: () => [],
|
|
182
|
+
discoverTools: async () => { },
|
|
183
|
+
getAllTools: () => [],
|
|
184
|
+
getToolsByServer: () => [],
|
|
185
|
+
};
|
|
186
|
+
const onAllToolCallsComplete = vi.fn();
|
|
187
|
+
const onToolCallsUpdate = vi.fn();
|
|
188
|
+
const mockConfig = {
|
|
189
|
+
getSessionId: () => 'test-session-id',
|
|
190
|
+
getUsageStatisticsEnabled: () => true,
|
|
191
|
+
getDebugMode: () => false,
|
|
192
|
+
getApprovalMode: () => ApprovalMode.DEFAULT,
|
|
193
|
+
getAllowedTools: () => [],
|
|
194
|
+
getContentGeneratorConfig: () => ({
|
|
195
|
+
model: 'test-model',
|
|
196
|
+
authType: 'oauth-personal',
|
|
197
|
+
}),
|
|
198
|
+
getToolRegistry: () => mockToolRegistry,
|
|
199
|
+
};
|
|
200
|
+
const scheduler = new CoreToolScheduler({
|
|
201
|
+
config: mockConfig,
|
|
202
|
+
onAllToolCallsComplete,
|
|
203
|
+
onToolCallsUpdate,
|
|
204
|
+
getPreferredEditor: () => 'vscode',
|
|
205
|
+
onEditorClose: vi.fn(),
|
|
206
|
+
});
|
|
207
|
+
const abortController = new AbortController();
|
|
208
|
+
const request = {
|
|
209
|
+
callId: '1',
|
|
210
|
+
name: 'mockModifiableTool',
|
|
211
|
+
args: {},
|
|
212
|
+
isClientInitiated: false,
|
|
213
|
+
prompt_id: 'prompt-id-2',
|
|
214
|
+
};
|
|
215
|
+
await scheduler.schedule([request], abortController.signal);
|
|
216
|
+
const awaitingCall = (await waitForStatus(onToolCallsUpdate, 'awaiting_approval'));
|
|
217
|
+
const confirmationDetails = awaitingCall.confirmationDetails;
|
|
218
|
+
if (confirmationDetails) {
|
|
219
|
+
const payload = { newContent: 'final version' };
|
|
220
|
+
await confirmationDetails.onConfirm(ToolConfirmationOutcome.ProceedOnce, payload);
|
|
221
|
+
}
|
|
222
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
223
|
+
const completedCalls = onAllToolCallsComplete.mock
|
|
224
|
+
.calls[0][0];
|
|
225
|
+
expect(completedCalls[0].status).toBe('success');
|
|
226
|
+
expect(mockTool.executeFn).toHaveBeenCalledWith({
|
|
227
|
+
newContent: 'final version',
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
describe('convertToFunctionResponse', () => {
|
|
232
|
+
const toolName = 'testTool';
|
|
233
|
+
const callId = 'call1';
|
|
234
|
+
it('should handle simple string llmContent', () => {
|
|
235
|
+
const llmContent = 'Simple text output';
|
|
236
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
237
|
+
expect(result).toEqual([
|
|
238
|
+
{
|
|
239
|
+
functionResponse: {
|
|
240
|
+
name: toolName,
|
|
241
|
+
id: callId,
|
|
242
|
+
response: { output: 'Simple text output' },
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
]);
|
|
246
|
+
});
|
|
247
|
+
it('should handle llmContent as a single Part with text', () => {
|
|
248
|
+
const llmContent = { text: 'Text from Part object' };
|
|
249
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
250
|
+
expect(result).toEqual([
|
|
251
|
+
{
|
|
252
|
+
functionResponse: {
|
|
253
|
+
name: toolName,
|
|
254
|
+
id: callId,
|
|
255
|
+
response: { output: 'Text from Part object' },
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
]);
|
|
259
|
+
});
|
|
260
|
+
it('should handle llmContent as a PartListUnion array with a single text Part', () => {
|
|
261
|
+
const llmContent = [{ text: 'Text from array' }];
|
|
262
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
263
|
+
expect(result).toEqual([
|
|
264
|
+
{
|
|
265
|
+
functionResponse: {
|
|
266
|
+
name: toolName,
|
|
267
|
+
id: callId,
|
|
268
|
+
response: { output: 'Text from array' },
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
]);
|
|
272
|
+
});
|
|
273
|
+
it('should handle llmContent with inlineData', () => {
|
|
274
|
+
const llmContent = {
|
|
275
|
+
inlineData: { mimeType: 'image/png', data: 'base64...' },
|
|
276
|
+
};
|
|
277
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
278
|
+
expect(result).toEqual([
|
|
279
|
+
{
|
|
280
|
+
functionResponse: {
|
|
281
|
+
name: toolName,
|
|
282
|
+
id: callId,
|
|
283
|
+
response: {
|
|
284
|
+
output: 'Binary content of type image/png was processed.',
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
llmContent,
|
|
289
|
+
]);
|
|
290
|
+
});
|
|
291
|
+
it('should handle llmContent with fileData', () => {
|
|
292
|
+
const llmContent = {
|
|
293
|
+
fileData: { mimeType: 'application/pdf', fileUri: 'gs://...' },
|
|
294
|
+
};
|
|
295
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
296
|
+
expect(result).toEqual([
|
|
297
|
+
{
|
|
298
|
+
functionResponse: {
|
|
299
|
+
name: toolName,
|
|
300
|
+
id: callId,
|
|
301
|
+
response: {
|
|
302
|
+
output: 'Binary content of type application/pdf was processed.',
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
llmContent,
|
|
307
|
+
]);
|
|
308
|
+
});
|
|
309
|
+
it('should handle llmContent as an array of multiple Parts (text and inlineData)', () => {
|
|
310
|
+
const llmContent = [
|
|
311
|
+
{ text: 'Some textual description' },
|
|
312
|
+
{ inlineData: { mimeType: 'image/jpeg', data: 'base64data...' } },
|
|
313
|
+
{ text: 'Another text part' },
|
|
314
|
+
];
|
|
315
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
316
|
+
expect(result).toEqual([
|
|
317
|
+
{
|
|
318
|
+
functionResponse: {
|
|
319
|
+
name: toolName,
|
|
320
|
+
id: callId,
|
|
321
|
+
response: { output: 'Tool execution succeeded.' },
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
...llmContent,
|
|
325
|
+
]);
|
|
326
|
+
});
|
|
327
|
+
it('should handle llmContent as an array with a single inlineData Part', () => {
|
|
328
|
+
const llmContent = [
|
|
329
|
+
{ inlineData: { mimeType: 'image/gif', data: 'gifdata...' } },
|
|
330
|
+
];
|
|
331
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
332
|
+
expect(result).toEqual([
|
|
333
|
+
{
|
|
334
|
+
functionResponse: {
|
|
335
|
+
name: toolName,
|
|
336
|
+
id: callId,
|
|
337
|
+
response: {
|
|
338
|
+
output: 'Binary content of type image/gif was processed.',
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
...llmContent,
|
|
343
|
+
]);
|
|
344
|
+
});
|
|
345
|
+
it('should handle llmContent as a generic Part (not text, inlineData, or fileData)', () => {
|
|
346
|
+
const llmContent = { functionCall: { name: 'test', args: {} } };
|
|
347
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
348
|
+
expect(result).toEqual([
|
|
349
|
+
{
|
|
350
|
+
functionResponse: {
|
|
351
|
+
name: toolName,
|
|
352
|
+
id: callId,
|
|
353
|
+
response: { output: 'Tool execution succeeded.' },
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
]);
|
|
357
|
+
});
|
|
358
|
+
it('should handle empty string llmContent', () => {
|
|
359
|
+
const llmContent = '';
|
|
360
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
361
|
+
expect(result).toEqual([
|
|
362
|
+
{
|
|
363
|
+
functionResponse: {
|
|
364
|
+
name: toolName,
|
|
365
|
+
id: callId,
|
|
366
|
+
response: { output: '' },
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
]);
|
|
370
|
+
});
|
|
371
|
+
it('should handle llmContent as an empty array', () => {
|
|
372
|
+
const llmContent = [];
|
|
373
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
374
|
+
expect(result).toEqual([
|
|
375
|
+
{
|
|
376
|
+
functionResponse: {
|
|
377
|
+
name: toolName,
|
|
378
|
+
id: callId,
|
|
379
|
+
response: { output: 'Tool execution succeeded.' },
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
]);
|
|
383
|
+
});
|
|
384
|
+
it('should handle llmContent as a Part with undefined inlineData/fileData/text', () => {
|
|
385
|
+
const llmContent = {}; // An empty part object
|
|
386
|
+
const result = convertToFunctionResponse(toolName, callId, llmContent);
|
|
387
|
+
expect(result).toEqual([
|
|
388
|
+
{
|
|
389
|
+
functionResponse: {
|
|
390
|
+
name: toolName,
|
|
391
|
+
id: callId,
|
|
392
|
+
response: { output: 'Tool execution succeeded.' },
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
]);
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
class MockEditToolInvocation extends BaseToolInvocation {
|
|
399
|
+
constructor(params) {
|
|
400
|
+
super(params);
|
|
401
|
+
}
|
|
402
|
+
getDescription() {
|
|
403
|
+
return 'A mock edit tool invocation';
|
|
404
|
+
}
|
|
405
|
+
async shouldConfirmExecute(_abortSignal) {
|
|
406
|
+
return {
|
|
407
|
+
type: 'edit',
|
|
408
|
+
title: 'Confirm Edit',
|
|
409
|
+
fileName: 'test.txt',
|
|
410
|
+
filePath: 'test.txt',
|
|
411
|
+
fileDiff: '--- test.txt\n+++ test.txt\n@@ -1,1 +1,1 @@\n-old content\n+new content',
|
|
412
|
+
originalContent: 'old content',
|
|
413
|
+
newContent: 'new content',
|
|
414
|
+
onConfirm: async () => { },
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
async execute(_abortSignal) {
|
|
418
|
+
return {
|
|
419
|
+
llmContent: 'Edited successfully',
|
|
420
|
+
returnDisplay: 'Edited successfully',
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
class MockEditTool extends BaseDeclarativeTool {
|
|
425
|
+
constructor() {
|
|
426
|
+
super('mockEditTool', 'mockEditTool', 'A mock edit tool', Kind.Edit, {});
|
|
427
|
+
}
|
|
428
|
+
createInvocation(params) {
|
|
429
|
+
return new MockEditToolInvocation(params);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
describe('CoreToolScheduler edit cancellation', () => {
|
|
433
|
+
it('should preserve diff when an edit is cancelled', async () => {
|
|
434
|
+
const mockEditTool = new MockEditTool();
|
|
435
|
+
const mockToolRegistry = {
|
|
436
|
+
getTool: () => mockEditTool,
|
|
437
|
+
getFunctionDeclarations: () => [],
|
|
438
|
+
tools: new Map(),
|
|
439
|
+
discovery: {},
|
|
440
|
+
registerTool: () => { },
|
|
441
|
+
getToolByName: () => mockEditTool,
|
|
442
|
+
getToolByDisplayName: () => mockEditTool,
|
|
443
|
+
getTools: () => [],
|
|
444
|
+
discoverTools: async () => { },
|
|
445
|
+
getAllTools: () => [],
|
|
446
|
+
getToolsByServer: () => [],
|
|
447
|
+
};
|
|
448
|
+
const onAllToolCallsComplete = vi.fn();
|
|
449
|
+
const onToolCallsUpdate = vi.fn();
|
|
450
|
+
const mockConfig = {
|
|
451
|
+
getSessionId: () => 'test-session-id',
|
|
452
|
+
getUsageStatisticsEnabled: () => true,
|
|
453
|
+
getDebugMode: () => false,
|
|
454
|
+
getApprovalMode: () => ApprovalMode.DEFAULT,
|
|
455
|
+
getAllowedTools: () => [],
|
|
456
|
+
getContentGeneratorConfig: () => ({
|
|
457
|
+
model: 'test-model',
|
|
458
|
+
authType: 'oauth-personal',
|
|
459
|
+
}),
|
|
460
|
+
getToolRegistry: () => mockToolRegistry,
|
|
461
|
+
};
|
|
462
|
+
const scheduler = new CoreToolScheduler({
|
|
463
|
+
config: mockConfig,
|
|
464
|
+
onAllToolCallsComplete,
|
|
465
|
+
onToolCallsUpdate,
|
|
466
|
+
getPreferredEditor: () => 'vscode',
|
|
467
|
+
onEditorClose: vi.fn(),
|
|
468
|
+
});
|
|
469
|
+
const abortController = new AbortController();
|
|
470
|
+
const request = {
|
|
471
|
+
callId: '1',
|
|
472
|
+
name: 'mockEditTool',
|
|
473
|
+
args: {},
|
|
474
|
+
isClientInitiated: false,
|
|
475
|
+
prompt_id: 'prompt-id-1',
|
|
476
|
+
};
|
|
477
|
+
await scheduler.schedule([request], abortController.signal);
|
|
478
|
+
const awaitingCall = (await waitForStatus(onToolCallsUpdate, 'awaiting_approval'));
|
|
479
|
+
// Cancel the edit
|
|
480
|
+
const confirmationDetails = awaitingCall.confirmationDetails;
|
|
481
|
+
if (confirmationDetails) {
|
|
482
|
+
await confirmationDetails.onConfirm(ToolConfirmationOutcome.Cancel);
|
|
483
|
+
}
|
|
484
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
485
|
+
const completedCalls = onAllToolCallsComplete.mock
|
|
486
|
+
.calls[0][0];
|
|
487
|
+
expect(completedCalls[0].status).toBe('cancelled');
|
|
488
|
+
// Check that the diff is preserved
|
|
489
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
490
|
+
const cancelledCall = completedCalls[0];
|
|
491
|
+
expect(cancelledCall.response.resultDisplay).toBeDefined();
|
|
492
|
+
expect(cancelledCall.response.resultDisplay.fileDiff).toBe('--- test.txt\n+++ test.txt\n@@ -1,1 +1,1 @@\n-old content\n+new content');
|
|
493
|
+
expect(cancelledCall.response.resultDisplay.fileName).toBe('test.txt');
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
describe('CoreToolScheduler YOLO mode', () => {
|
|
497
|
+
it('should execute tool requiring confirmation directly without waiting', async () => {
|
|
498
|
+
// Arrange
|
|
499
|
+
const mockTool = new MockTool();
|
|
500
|
+
mockTool.executeFn.mockReturnValue({
|
|
501
|
+
llmContent: 'Tool executed',
|
|
502
|
+
returnDisplay: 'Tool executed',
|
|
503
|
+
});
|
|
504
|
+
// This tool would normally require confirmation.
|
|
505
|
+
mockTool.shouldConfirm = true;
|
|
506
|
+
const declarativeTool = mockTool;
|
|
507
|
+
const mockToolRegistry = {
|
|
508
|
+
getTool: () => declarativeTool,
|
|
509
|
+
getToolByName: () => declarativeTool,
|
|
510
|
+
// Other properties are not needed for this test but are included for type consistency.
|
|
511
|
+
getFunctionDeclarations: () => [],
|
|
512
|
+
tools: new Map(),
|
|
513
|
+
discovery: {},
|
|
514
|
+
registerTool: () => { },
|
|
515
|
+
getToolByDisplayName: () => declarativeTool,
|
|
516
|
+
getTools: () => [],
|
|
517
|
+
discoverTools: async () => { },
|
|
518
|
+
getAllTools: () => [],
|
|
519
|
+
getToolsByServer: () => [],
|
|
520
|
+
};
|
|
521
|
+
const onAllToolCallsComplete = vi.fn();
|
|
522
|
+
const onToolCallsUpdate = vi.fn();
|
|
523
|
+
// Configure the scheduler for YOLO mode.
|
|
524
|
+
const mockConfig = {
|
|
525
|
+
getSessionId: () => 'test-session-id',
|
|
526
|
+
getUsageStatisticsEnabled: () => true,
|
|
527
|
+
getDebugMode: () => false,
|
|
528
|
+
getApprovalMode: () => ApprovalMode.YOLO,
|
|
529
|
+
getAllowedTools: () => [],
|
|
530
|
+
getContentGeneratorConfig: () => ({
|
|
531
|
+
model: 'test-model',
|
|
532
|
+
authType: 'oauth-personal',
|
|
533
|
+
}),
|
|
534
|
+
getToolRegistry: () => mockToolRegistry,
|
|
535
|
+
};
|
|
536
|
+
const scheduler = new CoreToolScheduler({
|
|
537
|
+
config: mockConfig,
|
|
538
|
+
onAllToolCallsComplete,
|
|
539
|
+
onToolCallsUpdate,
|
|
540
|
+
getPreferredEditor: () => 'vscode',
|
|
541
|
+
onEditorClose: vi.fn(),
|
|
542
|
+
});
|
|
543
|
+
const abortController = new AbortController();
|
|
544
|
+
const request = {
|
|
545
|
+
callId: '1',
|
|
546
|
+
name: 'mockTool',
|
|
547
|
+
args: { param: 'value' },
|
|
548
|
+
isClientInitiated: false,
|
|
549
|
+
prompt_id: 'prompt-id-yolo',
|
|
550
|
+
};
|
|
551
|
+
// Act
|
|
552
|
+
await scheduler.schedule([request], abortController.signal);
|
|
553
|
+
// Assert
|
|
554
|
+
// 1. The tool's execute method was called directly.
|
|
555
|
+
expect(mockTool.executeFn).toHaveBeenCalledWith({ param: 'value' });
|
|
556
|
+
// 2. The tool call status never entered 'awaiting_approval'.
|
|
557
|
+
const statusUpdates = onToolCallsUpdate.mock.calls
|
|
558
|
+
.map((call) => call[0][0]?.status)
|
|
559
|
+
.filter(Boolean);
|
|
560
|
+
expect(statusUpdates).not.toContain('awaiting_approval');
|
|
561
|
+
expect(statusUpdates).toEqual([
|
|
562
|
+
'validating',
|
|
563
|
+
'scheduled',
|
|
564
|
+
'executing',
|
|
565
|
+
'success',
|
|
566
|
+
]);
|
|
567
|
+
// 3. The final callback indicates the tool call was successful.
|
|
568
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
569
|
+
const completedCalls = onAllToolCallsComplete.mock
|
|
570
|
+
.calls[0][0];
|
|
571
|
+
expect(completedCalls).toHaveLength(1);
|
|
572
|
+
const completedCall = completedCalls[0];
|
|
573
|
+
expect(completedCall.status).toBe('success');
|
|
574
|
+
if (completedCall.status === 'success') {
|
|
575
|
+
expect(completedCall.response.resultDisplay).toBe('Tool executed');
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
describe('CoreToolScheduler request queueing', () => {
|
|
580
|
+
it('should queue a request if another is running', async () => {
|
|
581
|
+
let resolveFirstCall;
|
|
582
|
+
const firstCallPromise = new Promise((resolve) => {
|
|
583
|
+
resolveFirstCall = resolve;
|
|
584
|
+
});
|
|
585
|
+
const mockTool = new MockTool();
|
|
586
|
+
mockTool.executeFn.mockImplementation(() => firstCallPromise);
|
|
587
|
+
const declarativeTool = mockTool;
|
|
588
|
+
const mockToolRegistry = {
|
|
589
|
+
getTool: () => declarativeTool,
|
|
590
|
+
getToolByName: () => declarativeTool,
|
|
591
|
+
getFunctionDeclarations: () => [],
|
|
592
|
+
tools: new Map(),
|
|
593
|
+
discovery: {},
|
|
594
|
+
registerTool: () => { },
|
|
595
|
+
getToolByDisplayName: () => declarativeTool,
|
|
596
|
+
getTools: () => [],
|
|
597
|
+
discoverTools: async () => { },
|
|
598
|
+
getAllTools: () => [],
|
|
599
|
+
getToolsByServer: () => [],
|
|
600
|
+
};
|
|
601
|
+
const onAllToolCallsComplete = vi.fn();
|
|
602
|
+
const onToolCallsUpdate = vi.fn();
|
|
603
|
+
const mockConfig = {
|
|
604
|
+
getSessionId: () => 'test-session-id',
|
|
605
|
+
getUsageStatisticsEnabled: () => true,
|
|
606
|
+
getDebugMode: () => false,
|
|
607
|
+
getApprovalMode: () => ApprovalMode.YOLO, // Use YOLO to avoid confirmation prompts
|
|
608
|
+
getAllowedTools: () => [],
|
|
609
|
+
getContentGeneratorConfig: () => ({
|
|
610
|
+
model: 'test-model',
|
|
611
|
+
authType: 'oauth-personal',
|
|
612
|
+
}),
|
|
613
|
+
getToolRegistry: () => mockToolRegistry,
|
|
614
|
+
};
|
|
615
|
+
const scheduler = new CoreToolScheduler({
|
|
616
|
+
config: mockConfig,
|
|
617
|
+
onAllToolCallsComplete,
|
|
618
|
+
onToolCallsUpdate,
|
|
619
|
+
getPreferredEditor: () => 'vscode',
|
|
620
|
+
onEditorClose: vi.fn(),
|
|
621
|
+
});
|
|
622
|
+
const abortController = new AbortController();
|
|
623
|
+
const request1 = {
|
|
624
|
+
callId: '1',
|
|
625
|
+
name: 'mockTool',
|
|
626
|
+
args: { a: 1 },
|
|
627
|
+
isClientInitiated: false,
|
|
628
|
+
prompt_id: 'prompt-1',
|
|
629
|
+
};
|
|
630
|
+
const request2 = {
|
|
631
|
+
callId: '2',
|
|
632
|
+
name: 'mockTool',
|
|
633
|
+
args: { b: 2 },
|
|
634
|
+
isClientInitiated: false,
|
|
635
|
+
prompt_id: 'prompt-2',
|
|
636
|
+
};
|
|
637
|
+
// Schedule the first call, which will pause execution.
|
|
638
|
+
scheduler.schedule([request1], abortController.signal);
|
|
639
|
+
// Wait for the first call to be in the 'executing' state.
|
|
640
|
+
await waitForStatus(onToolCallsUpdate, 'executing');
|
|
641
|
+
// Schedule the second call while the first is "running".
|
|
642
|
+
const schedulePromise2 = scheduler.schedule([request2], abortController.signal);
|
|
643
|
+
// Ensure the second tool call hasn't been executed yet.
|
|
644
|
+
expect(mockTool.executeFn).toHaveBeenCalledTimes(1);
|
|
645
|
+
expect(mockTool.executeFn).toHaveBeenCalledWith({ a: 1 });
|
|
646
|
+
// Complete the first tool call.
|
|
647
|
+
resolveFirstCall({
|
|
648
|
+
llmContent: 'First call complete',
|
|
649
|
+
returnDisplay: 'First call complete',
|
|
650
|
+
});
|
|
651
|
+
// Wait for the second schedule promise to resolve.
|
|
652
|
+
await schedulePromise2;
|
|
653
|
+
// Let the second call finish.
|
|
654
|
+
const secondCallResult = {
|
|
655
|
+
llmContent: 'Second call complete',
|
|
656
|
+
returnDisplay: 'Second call complete',
|
|
657
|
+
};
|
|
658
|
+
// Since the mock is shared, we need to resolve the current promise.
|
|
659
|
+
// In a real scenario, a new promise would be created for the second call.
|
|
660
|
+
resolveFirstCall(secondCallResult);
|
|
661
|
+
await vi.waitFor(() => {
|
|
662
|
+
// Now the second tool call should have been executed.
|
|
663
|
+
expect(mockTool.executeFn).toHaveBeenCalledTimes(2);
|
|
664
|
+
});
|
|
665
|
+
expect(mockTool.executeFn).toHaveBeenCalledWith({ b: 2 });
|
|
666
|
+
// Wait for the second completion.
|
|
667
|
+
await vi.waitFor(() => {
|
|
668
|
+
expect(onAllToolCallsComplete).toHaveBeenCalledTimes(2);
|
|
669
|
+
});
|
|
670
|
+
// Verify the completion callbacks were called correctly.
|
|
671
|
+
expect(onAllToolCallsComplete.mock.calls[0][0][0].status).toBe('success');
|
|
672
|
+
expect(onAllToolCallsComplete.mock.calls[1][0][0].status).toBe('success');
|
|
673
|
+
});
|
|
674
|
+
it('should auto-approve a tool call if it is on the allowedTools list', async () => {
|
|
675
|
+
// Arrange
|
|
676
|
+
const mockTool = new MockTool('mockTool');
|
|
677
|
+
mockTool.executeFn.mockReturnValue({
|
|
678
|
+
llmContent: 'Tool executed',
|
|
679
|
+
returnDisplay: 'Tool executed',
|
|
680
|
+
});
|
|
681
|
+
// This tool would normally require confirmation.
|
|
682
|
+
mockTool.shouldConfirm = true;
|
|
683
|
+
const declarativeTool = mockTool;
|
|
684
|
+
const toolRegistry = {
|
|
685
|
+
getTool: () => declarativeTool,
|
|
686
|
+
getToolByName: () => declarativeTool,
|
|
687
|
+
getFunctionDeclarations: () => [],
|
|
688
|
+
tools: new Map(),
|
|
689
|
+
discovery: {},
|
|
690
|
+
registerTool: () => { },
|
|
691
|
+
getToolByDisplayName: () => declarativeTool,
|
|
692
|
+
getTools: () => [],
|
|
693
|
+
discoverTools: async () => { },
|
|
694
|
+
getAllTools: () => [],
|
|
695
|
+
getToolsByServer: () => [],
|
|
696
|
+
};
|
|
697
|
+
const onAllToolCallsComplete = vi.fn();
|
|
698
|
+
const onToolCallsUpdate = vi.fn();
|
|
699
|
+
// Configure the scheduler to auto-approve the specific tool call.
|
|
700
|
+
const mockConfig = {
|
|
701
|
+
getSessionId: () => 'test-session-id',
|
|
702
|
+
getUsageStatisticsEnabled: () => true,
|
|
703
|
+
getDebugMode: () => false,
|
|
704
|
+
getApprovalMode: () => ApprovalMode.DEFAULT, // Not YOLO mode
|
|
705
|
+
getAllowedTools: () => ['mockTool'], // Auto-approve this tool
|
|
706
|
+
getToolRegistry: () => toolRegistry,
|
|
707
|
+
getContentGeneratorConfig: () => ({
|
|
708
|
+
model: 'test-model',
|
|
709
|
+
authType: 'oauth-personal',
|
|
710
|
+
}),
|
|
711
|
+
};
|
|
712
|
+
const scheduler = new CoreToolScheduler({
|
|
713
|
+
config: mockConfig,
|
|
714
|
+
onAllToolCallsComplete,
|
|
715
|
+
onToolCallsUpdate,
|
|
716
|
+
getPreferredEditor: () => 'vscode',
|
|
717
|
+
onEditorClose: vi.fn(),
|
|
718
|
+
});
|
|
719
|
+
const abortController = new AbortController();
|
|
720
|
+
const request = {
|
|
721
|
+
callId: '1',
|
|
722
|
+
name: 'mockTool',
|
|
723
|
+
args: { param: 'value' },
|
|
724
|
+
isClientInitiated: false,
|
|
725
|
+
prompt_id: 'prompt-auto-approved',
|
|
726
|
+
};
|
|
727
|
+
// Act
|
|
728
|
+
await scheduler.schedule([request], abortController.signal);
|
|
729
|
+
// Assert
|
|
730
|
+
// 1. The tool's execute method was called directly.
|
|
731
|
+
expect(mockTool.executeFn).toHaveBeenCalledWith({ param: 'value' });
|
|
732
|
+
// 2. The tool call status never entered 'awaiting_approval'.
|
|
733
|
+
const statusUpdates = onToolCallsUpdate.mock.calls
|
|
734
|
+
.map((call) => call[0][0]?.status)
|
|
735
|
+
.filter(Boolean);
|
|
736
|
+
expect(statusUpdates).not.toContain('awaiting_approval');
|
|
737
|
+
expect(statusUpdates).toEqual([
|
|
738
|
+
'validating',
|
|
739
|
+
'scheduled',
|
|
740
|
+
'executing',
|
|
741
|
+
'success',
|
|
742
|
+
]);
|
|
743
|
+
// 3. The final callback indicates the tool call was successful.
|
|
744
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
745
|
+
const completedCalls = onAllToolCallsComplete.mock
|
|
746
|
+
.calls[0][0];
|
|
747
|
+
expect(completedCalls).toHaveLength(1);
|
|
748
|
+
const completedCall = completedCalls[0];
|
|
749
|
+
expect(completedCall.status).toBe('success');
|
|
750
|
+
if (completedCall.status === 'success') {
|
|
751
|
+
expect(completedCall.response.resultDisplay).toBe('Tool executed');
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
it('should handle two synchronous calls to schedule', async () => {
|
|
755
|
+
const mockTool = new MockTool();
|
|
756
|
+
const declarativeTool = mockTool;
|
|
757
|
+
const mockToolRegistry = {
|
|
758
|
+
getTool: () => declarativeTool,
|
|
759
|
+
getToolByName: () => declarativeTool,
|
|
760
|
+
getFunctionDeclarations: () => [],
|
|
761
|
+
tools: new Map(),
|
|
762
|
+
discovery: {},
|
|
763
|
+
registerTool: () => { },
|
|
764
|
+
getToolByDisplayName: () => declarativeTool,
|
|
765
|
+
getTools: () => [],
|
|
766
|
+
discoverTools: async () => { },
|
|
767
|
+
getAllTools: () => [],
|
|
768
|
+
getToolsByServer: () => [],
|
|
769
|
+
};
|
|
770
|
+
const onAllToolCallsComplete = vi.fn();
|
|
771
|
+
const onToolCallsUpdate = vi.fn();
|
|
772
|
+
const mockConfig = {
|
|
773
|
+
getSessionId: () => 'test-session-id',
|
|
774
|
+
getUsageStatisticsEnabled: () => true,
|
|
775
|
+
getDebugMode: () => false,
|
|
776
|
+
getApprovalMode: () => ApprovalMode.YOLO,
|
|
777
|
+
getAllowedTools: () => [],
|
|
778
|
+
getContentGeneratorConfig: () => ({
|
|
779
|
+
model: 'test-model',
|
|
780
|
+
authType: 'oauth-personal',
|
|
781
|
+
}),
|
|
782
|
+
getToolRegistry: () => mockToolRegistry,
|
|
783
|
+
};
|
|
784
|
+
const scheduler = new CoreToolScheduler({
|
|
785
|
+
config: mockConfig,
|
|
786
|
+
onAllToolCallsComplete,
|
|
787
|
+
onToolCallsUpdate,
|
|
788
|
+
getPreferredEditor: () => 'vscode',
|
|
789
|
+
onEditorClose: vi.fn(),
|
|
790
|
+
});
|
|
791
|
+
const abortController = new AbortController();
|
|
792
|
+
const request1 = {
|
|
793
|
+
callId: '1',
|
|
794
|
+
name: 'mockTool',
|
|
795
|
+
args: { a: 1 },
|
|
796
|
+
isClientInitiated: false,
|
|
797
|
+
prompt_id: 'prompt-1',
|
|
798
|
+
};
|
|
799
|
+
const request2 = {
|
|
800
|
+
callId: '2',
|
|
801
|
+
name: 'mockTool',
|
|
802
|
+
args: { b: 2 },
|
|
803
|
+
isClientInitiated: false,
|
|
804
|
+
prompt_id: 'prompt-2',
|
|
805
|
+
};
|
|
806
|
+
// Schedule two calls synchronously.
|
|
807
|
+
const schedulePromise1 = scheduler.schedule([request1], abortController.signal);
|
|
808
|
+
const schedulePromise2 = scheduler.schedule([request2], abortController.signal);
|
|
809
|
+
// Wait for both promises to resolve.
|
|
810
|
+
await Promise.all([schedulePromise1, schedulePromise2]);
|
|
811
|
+
// Ensure the tool was called twice with the correct arguments.
|
|
812
|
+
expect(mockTool.executeFn).toHaveBeenCalledTimes(2);
|
|
813
|
+
expect(mockTool.executeFn).toHaveBeenCalledWith({ a: 1 });
|
|
814
|
+
expect(mockTool.executeFn).toHaveBeenCalledWith({ b: 2 });
|
|
815
|
+
// Ensure completion callbacks were called twice.
|
|
816
|
+
expect(onAllToolCallsComplete).toHaveBeenCalledTimes(2);
|
|
817
|
+
});
|
|
818
|
+
it('should auto-approve remaining tool calls when first tool call is approved with ProceedAlways', async () => {
|
|
819
|
+
let approvalMode = ApprovalMode.DEFAULT;
|
|
820
|
+
const mockConfig = {
|
|
821
|
+
getSessionId: () => 'test-session-id',
|
|
822
|
+
getUsageStatisticsEnabled: () => true,
|
|
823
|
+
getDebugMode: () => false,
|
|
824
|
+
getApprovalMode: () => approvalMode,
|
|
825
|
+
getAllowedTools: () => [],
|
|
826
|
+
setApprovalMode: (mode) => {
|
|
827
|
+
approvalMode = mode;
|
|
828
|
+
},
|
|
829
|
+
};
|
|
830
|
+
const testTool = new TestApprovalTool(mockConfig);
|
|
831
|
+
const toolRegistry = {
|
|
832
|
+
getTool: () => testTool,
|
|
833
|
+
getFunctionDeclarations: () => [],
|
|
834
|
+
getFunctionDeclarationsFiltered: () => [],
|
|
835
|
+
registerTool: () => { },
|
|
836
|
+
discoverAllTools: async () => { },
|
|
837
|
+
discoverMcpTools: async () => { },
|
|
838
|
+
discoverToolsForServer: async () => { },
|
|
839
|
+
removeMcpToolsByServer: () => { },
|
|
840
|
+
getAllTools: () => [],
|
|
841
|
+
getToolsByServer: () => [],
|
|
842
|
+
tools: new Map(),
|
|
843
|
+
config: mockConfig,
|
|
844
|
+
mcpClientManager: undefined,
|
|
845
|
+
getToolByName: () => testTool,
|
|
846
|
+
getToolByDisplayName: () => testTool,
|
|
847
|
+
getTools: () => [],
|
|
848
|
+
discoverTools: async () => { },
|
|
849
|
+
discovery: {},
|
|
850
|
+
};
|
|
851
|
+
mockConfig.getToolRegistry = () => toolRegistry;
|
|
852
|
+
const onAllToolCallsComplete = vi.fn();
|
|
853
|
+
const onToolCallsUpdate = vi.fn();
|
|
854
|
+
const pendingConfirmations = [];
|
|
855
|
+
const scheduler = new CoreToolScheduler({
|
|
856
|
+
config: mockConfig,
|
|
857
|
+
onAllToolCallsComplete,
|
|
858
|
+
onToolCallsUpdate: (toolCalls) => {
|
|
859
|
+
onToolCallsUpdate(toolCalls);
|
|
860
|
+
// Capture confirmation handlers for awaiting_approval tools
|
|
861
|
+
toolCalls.forEach((call) => {
|
|
862
|
+
if (call.status === 'awaiting_approval') {
|
|
863
|
+
const waitingCall = call;
|
|
864
|
+
if (waitingCall.confirmationDetails?.onConfirm) {
|
|
865
|
+
const originalHandler = pendingConfirmations.find((h) => h === waitingCall.confirmationDetails.onConfirm);
|
|
866
|
+
if (!originalHandler) {
|
|
867
|
+
pendingConfirmations.push(waitingCall.confirmationDetails.onConfirm);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
},
|
|
873
|
+
getPreferredEditor: () => 'vscode',
|
|
874
|
+
onEditorClose: vi.fn(),
|
|
875
|
+
});
|
|
876
|
+
const abortController = new AbortController();
|
|
877
|
+
// Schedule multiple tools that need confirmation
|
|
878
|
+
const requests = [
|
|
879
|
+
{
|
|
880
|
+
callId: '1',
|
|
881
|
+
name: 'testApprovalTool',
|
|
882
|
+
args: { id: 'first' },
|
|
883
|
+
isClientInitiated: false,
|
|
884
|
+
prompt_id: 'prompt-1',
|
|
885
|
+
},
|
|
886
|
+
{
|
|
887
|
+
callId: '2',
|
|
888
|
+
name: 'testApprovalTool',
|
|
889
|
+
args: { id: 'second' },
|
|
890
|
+
isClientInitiated: false,
|
|
891
|
+
prompt_id: 'prompt-2',
|
|
892
|
+
},
|
|
893
|
+
{
|
|
894
|
+
callId: '3',
|
|
895
|
+
name: 'testApprovalTool',
|
|
896
|
+
args: { id: 'third' },
|
|
897
|
+
isClientInitiated: false,
|
|
898
|
+
prompt_id: 'prompt-3',
|
|
899
|
+
},
|
|
900
|
+
];
|
|
901
|
+
await scheduler.schedule(requests, abortController.signal);
|
|
902
|
+
// Wait for all tools to be awaiting approval
|
|
903
|
+
await vi.waitFor(() => {
|
|
904
|
+
const calls = onToolCallsUpdate.mock.calls.at(-1)?.[0];
|
|
905
|
+
expect(calls?.length).toBe(3);
|
|
906
|
+
expect(calls?.every((call) => call.status === 'awaiting_approval')).toBe(true);
|
|
907
|
+
});
|
|
908
|
+
expect(pendingConfirmations.length).toBe(3);
|
|
909
|
+
// Approve the first tool with ProceedAlways
|
|
910
|
+
const firstConfirmation = pendingConfirmations[0];
|
|
911
|
+
firstConfirmation(ToolConfirmationOutcome.ProceedAlways);
|
|
912
|
+
// Wait for all tools to be completed
|
|
913
|
+
await vi.waitFor(() => {
|
|
914
|
+
expect(onAllToolCallsComplete).toHaveBeenCalled();
|
|
915
|
+
const completedCalls = onAllToolCallsComplete.mock.calls.at(-1)?.[0];
|
|
916
|
+
expect(completedCalls?.length).toBe(3);
|
|
917
|
+
expect(completedCalls?.every((call) => call.status === 'success')).toBe(true);
|
|
918
|
+
});
|
|
919
|
+
// Verify approval mode was changed
|
|
920
|
+
expect(approvalMode).toBe(ApprovalMode.AUTO_EDIT);
|
|
921
|
+
});
|
|
922
|
+
});
|
|
923
|
+
//# sourceMappingURL=coreToolScheduler.test.js.map
|